!37 更新代码

Merge pull request !37 from 候鹏飞/master
This commit is contained in:
候鹏飞 2021-10-22 11:44:02 +00:00 committed by Gitee
commit 6d6effe542
248 changed files with 373558 additions and 286 deletions

View File

@ -28,7 +28,7 @@ const unsigned char rgbDutyLow[] = {20,4,20}; //低亮度
const unsigned char rgbDutyHig[] = {99,99,99}; //高亮度
//初始化蜂鸣器相关参数
struct BEEPCTRLATTR gBeepCtrlAttr ={
struct BEEPCTRLATTR gBeepCtrlAttr = {
.times = 0,
.duty = 0.4,
.period = 500,
@ -54,7 +54,7 @@ static void MainDemoTask(void)
//更新当前环境红外人体状态
envBodyState = GetEnvBodyState();
printf("envBodyState = %d \r\n",envBodyState);
//有人到来时蜂鸣器响RGB灯在暗环境下点亮
if(envBodyState == BODY_COME)
{

View File

@ -13,13 +13,16 @@
static_library("module_enviroment_example") {
sources = [
"THsensor.c",
"CGsensor.c",
"buzzer.c"
"src/THSensor.c",
"src/CGSensor.c",
"src/beep_demo.c"
]
include_dirs = [
"include",
"//utils/native/lite/include",
"//third_party/cmsis/CMSIS/RTOS2/Include",
"//base/iot_hardware/peripheral/interfaces/kits",
"//third_party/bounds_checking_function/include"
]
}

View File

@ -4,10 +4,10 @@
# 目录结构:
## include
buzzer.h --蜂鸣器控制头文件
beep_demo.h --蜂鸣器控制头文件
sensor.h --传感器头文件
## src
buzzer.c --蜂鸣器控制源文件
beep_demo.c --蜂鸣器控制源文件
CGsensor.c --烟感传感器源文件
THsensor.c --温湿度源文件
@ -23,39 +23,11 @@
period //每响一次的时间周期
callTime //控制函数的调用周期
## infrared_demo
1.InfraredSensorInit(): 红外传感初始化函数初始化GPIO7为IO输入
2.GetInfraredSensorVal(): 获取红外传感IO引脚当前的状态值
3.GetEnvBodyState(): 获取红外人体感应目前的环境状态
返回值(enum ENV_BODY_STATE):
BODY_NOT //无人靠近
BODY_COME //有人靠近
BODY_KEEP //有人靠近后保持
BODY_LEAVE //有人离开
## light_demo
1.LightSensorVal(unsigned short* val): 获取当前环境光照值保存到val中
2.GetLightAverageVal(unsigned char cnt): 多次获取当前环境光照并取平均值
cnt为多次获取次数
return 返回多次获取的平均值
3.GetEnvLightState(): 获取当前环境光照状态
返回值(enum ENV_LIGHT_STATE):
LIGHT_DAY //白天
LIGHT_DUSK //黄昏
LIGHT_NIGHT //黑夜
## tricolor_light_demo
1.TricolorLightInit(): 三色灯初始化函数初始化GPIO10,GPIO11,GPIO12为PWM1,PWM2,PWM3输出
2.TricolorLightStart(char redDuty, char GreenDuty, char BlueDuty): 设置PWM输出值并开启PWM输出
redDuty: 红灯PWM占空比
GreenDuty: 绿灯PWM占空比
BlueDuty: 蓝灯PWM占空比
3.TricolorLightStop(): 三色灯P输出停止函数
## sensor
1.CGSensorTask: 烟雾传感器任务
2.THSensorTaskEntry: 温湿度传感器任务
# 运行结果
当红外检测到有人接近时,蜂鸣器响两声,同时:
当环境光线充足时,三色灯熄灭;
当环境光线较昏暗时,三色灯显示低亮度;
当环境光线非常不足时,三色灯显示高亮度;
当红外检测到有人离开时,蜂鸣器响两声,且三色灯熄灭
输出烟雾传感器电压当电压高于1V蜂鸣器会响两声低于1V会停止
输出温湿度值

View File

@ -1,108 +0,0 @@
/*
* Copyright (c) 2021 Talkweb Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "iot_gpio.h"
#include "iot_pwm.h"
#include "buzzer.h"
// 是否正在播放标志 1. playing 0. free
volatile uint8_t buzz_flag = 0;
#define PWM_BEEP_PORT IOT_PWM_PORT_PWM0
static const uint16_t gTuneFreqs40M[] = {
0, //40MHz时钟源
38223, // 1 1046.5
34052, // 2 1174.7
30338, // 3 1318.5
28635, // 4 1396.4
25511, // 5 1568
22728, // 6 1760
20249, // 7 1975.5
};
static const uint8_t gScoreNotesBeep[] = {
5, 3, 3, 4, 2, 2, 1, 2, 3, 4, 5, 5, 5,
5, 3, 3, 4, 2, 2, 1, 3, 5, 5, 1,
2, 2, 2, 2, 2, 3, 4,
3, 3, 3, 3, 3, 4, 5,
5, 3, 3, 4, 2, 2, 1, 3, 5, 5, 1
};
static const uint8_t gScoreDurationsBeep[] = {
4, 4, 8, 4, 4, 8, 4, 4, 4, 4, 4, 4, 8,
4, 4, 8, 4, 4, 8, 4, 4, 4, 4, 8,
4, 4, 4, 4, 4, 4, 8,
4, 4, 4, 4, 4, 4, 8,
4, 4, 8, 4, 4, 8, 4, 4, 4, 4, 8};
static void PlayTuneTask(void *arg)
{
(void)arg;
uint32_t tune;
uint16_t freqDivisor;
uint32_t tuneInterval;
for (size_t i = 0; i < sizeof(gScoreNotesBeep) / sizeof(gScoreNotesBeep[0]); i++)
{
tune = gScoreNotesBeep[i];
freqDivisor = gTuneFreqs40M[tune];
tuneInterval = gScoreDurationsBeep[i] * (125 * 1000); // 时间
IoTPwmStart(PWM_BEEP_PORT, freqDivisor / 2, freqDivisor);
usleep(tuneInterval);
IoTPwmStop(PWM_BEEP_PORT);
}
if (buzz_flag == 1)
{
buzz_flag = 0;
}
}
void StartBuzz()
{
if (buzz_flag == 1)
{
return;
}
// 蜂鸣器端口初始化
IoTGpioInit(IOT_GPIO_IO_GPIO_9);
IoTIoSetFunc(IOT_GPIO_IO_GPIO_9, IOT_IO_FUNC_GPIO_9_PWM0_OUT);
IoTPwmInit(PWM_BEEP_PORT);
// 时钟
IoTPwmSetClock(IOT_PWM_CLK_XTAL);
osThreadAttr_t attr;
attr.name = "BuzzTask";
attr.attr_bits = 0U;
attr.cb_mem = NULL;
attr.cb_size = 0U;
attr.stack_mem = NULL;
attr.stack_size = 1024;
attr.priority = 25;
if (osThreadNew(PlayTuneTask, NULL, &attr) == NULL)
{
printf("[pwm] Falied to create BuzzTask!\n");
}
}

View File

@ -1,23 +0,0 @@
/*
* Copyright (c) 2021 Talkweb Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __BUZZE_H__
#define __BUZZE_H__
#include "ohos_types.h"
void StartBuzz();
#endif

View File

@ -13,21 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _BEEP_DEMO_H
#define _BEEP_DEMO_H
#include "iot_gpio.h"
#include "iot_pwm.h"
typedef struct {
struct BEEPCTRLATTR{
unsigned int times; //响的次数
float duty; //每次响的占空比
unsigned int period; //每响一次的时间周期
unsigned int callTime; //控制函数的调用周期
} BeepCtrlAttr;
};
void BeepInit(void);
void BeepCtrl(BeepCtrlAttr* ctrlAttr);
void BeepCtrl(struct BEEPCTRLATTR* ctrlAttr);
#endif

View File

@ -25,15 +25,15 @@
#define THSENSOR_TASK_PRIO 25
//AHT20
#define AHT20_I2C_IDX IOT_I2C_IDX_0 //I2C ID
#define AHT20_I2C_IDX IOT_I2C_IDX_0 // I2C ID
#define AHT20_RECEIVE_MAX 6 //AHT20 返回最大字节数
#define AHT20_MAX_RETRY 10 //当AHT20未初始化最大尝试重新初始化次数
#define AHT20_RECEIVE_MAX 6 // AHT20 返回最大字节数
#define AHT20_MAX_RETRY 10 // 当AHT20未初始化最大尝试重新初始化次数
#define CGSENSOR_TASK_STACK_SIZE 2048
#define CGSENSOR_TASK_PRIO 25
#define AHT20_I2C_ADDR 0x38
#define AHT20_I2C_ADDR 0x38
#define AHT20_READ_ADDR ((0x38<<1)|0x1)
#define AHT20_WRITE_ADDR ((0x38<<1)|0x0)
@ -43,10 +43,10 @@
#define AHT20_CMD_CALIBRATION_ARG0 0x08
#define AHT20_CMD_CALIBRATION_ARG1 0x00
/**
/*
* ,0xAC75
* [Bit7]01
**/
*/
#define AHT20_CMD_TRIGGER 0xAC // 触发测量命令
#define AHT20_CMD_TRIGGER_ARG0 0x33
#define AHT20_CMD_TRIGGER_ARG1 0x00
@ -54,8 +54,6 @@
// 用于在无需关闭和再次打开电源的情况下重新启动传感器系统软复位所需时间不超过20 毫秒
#define AHT20_CMD_RESET 0xBA // 软复位命令
#endif

View File

@ -23,13 +23,21 @@
#include "iot_adc.h"
#include "iot_errno.h"
#include "sensor.h"
#include "buzze.h"
#include "beep_demo.h"
//初始化蜂鸣器相关参数
struct BEEPCTRLATTR gBeepCtrlAttr = {
.times = 0,
.duty = 0.4,
.period = 500,
.callTime = 200
};
/**
* ADC
* \param [in] data
* \param [in] len
*
* @brief ADC
* @param [in] data
* @param [in] len
* @return
*/
static void OnAdcData(uint16_t *data, uint32_t len)
{
@ -37,7 +45,6 @@ static void OnAdcData(uint16_t *data, uint32_t len)
float vlt_min = 100; //最小值
for (size_t i = 0; i < len; i++)
{
float voltage = (float)data[i] * 1.8 * 4 / 4096.0; /* vlt * 1.8 * 4 / 4096.0: Convert code into voltage */
vlt_max = (voltage > vlt_max) ? voltage : vlt_max;
vlt_min = (voltage < vlt_min) ? voltage : vlt_min;
@ -47,15 +54,22 @@ static void OnAdcData(uint16_t *data, uint32_t len)
printf("MQ-2 Voltage = %.3f \r\n", vlt_val);
if (vlt_val >= 1.0f)
{ //电压变化超值1.0f
StartBuzz();
{
//电压变化超值1.0f
gBeepCtrlAttr.times = 2;
BeepCtrl(&gBeepCtrlAttr);
}
else
{
gBeepCtrlAttr.times = 0;
BeepCtrl(&gBeepCtrlAttr);
}
}
static void *CGsensorTask(const char *arg)
static void *CGSensorTask(const char *arg)
{
(void)arg;
uint16_t th_adc_buf[ADC_TEST_LENGTH] = {0};
while (1)
@ -69,42 +83,40 @@ static void *CGsensorTask(const char *arg)
if (ret != IOT_SUCCESS)
{
printf("ADC Read Fail\n");
return NULL;
return;
}
}
OnAdcData(th_adc_buf, ADC_TEST_LENGTH);
usleep(500000); // 延迟500ms
} //end while
return NULL;
// 延迟500ms
osDelay(50);
}
}
/**
* @brief
* @return
*/
static void CGsensorExampleEntry(void)
{
osThreadAttr_t attr;
uint32_t ret;
//ADC PORT
BeepInit();
// ADC初始化
IoTGpioInit(IOT_GPIO_IO_GPIO_11);
IoTIoSetFunc(IOT_GPIO_IO_GPIO_11, IOT_IO_FUNC_GPIO_11_GPIO);
IoTGpioSetDir(IOT_GPIO_IO_GPIO_11, IOT_GPIO_DIR_IN);
if (ret != IOT_SUCCESS)
{
printf("[CGsensorExampleEntry]===== ERROR ======gpio -> hi_gpio_set_dir1 ret:%d\r\n", ret);
return;
}
attr.name = "CHsensorTask";
attr.name = "CHSensorTask";
attr.attr_bits = 0U;
attr.cb_mem = NULL;
attr.cb_size = 0U;
attr.stack_mem = NULL;
attr.stack_size = THSENSOR_TASK_STACK_SIZE;
attr.priority = THSENSOR_TASK_PRIO;
attr.stack_size = CGSENSOR_TASK_STACK_SIZE;
attr.priority = CGSENSOR_TASK_PRIO;
if (osThreadNew((osThreadFunc_t)CGsensorTask, NULL, &attr) == NULL)
if (osThreadNew((osThreadFunc_t)CGSensorTask, NULL, &attr) == NULL)
{
printf("[CGsensorExampleEntry] Falied to create THsensorTask!\n");
printf("[CGsensorExampleEntry] Falied to create CGSensorTask!\n");
}
}

View File

@ -18,139 +18,144 @@
#include "ohos_init.h"
#include "cmsis_os2.h"
#include <hi_types_base.h>
#include <hi_early_debug.h>
#include <hi_stdlib.h>
#include "sensor.h"
#include "iot_errno.h"
#include "iot_gpio.h"
/**
*
* \param buffer
* \param length
* return 0:
* @brief
* @param buffer
* @param length
* @return IOT_SUCCESS: IOT_FAILURE
*/
static uint32_t Aht20I2cWrite(uint8_t *buffer, uint32_t length)
{
uint32_t status;
status = IoTI2cWrite(AHT20_I2C_IDX, AHT20_WRITE_ADDR, buffer, length);
if (status != HI_ERR_SUCCESS)
if (status != IOT_SUCCESS)
{
printf("===== Error: I2C write status = 0x%x! =====\r\n", status);
return status;
}
return HI_ERR_SUCCESS;
return IOT_SUCCESS;
}
/**
*
* \param buffer
* \param length
* return 0:
* @brief
* @param buffer
* @param length
* @return IOT_SUCCESS: IOT_FAILURE
*/
static uint32_t Aht20I2cRead(uint8_t *buffer, uint32_t length)
{
uint32_t receive_data;
receive_data = IoTI2cRead(AHT20_I2C_IDX, AHT20_WRITE_ADDR, buffer, length);
if (receive_data != HI_ERR_SUCCESS)
if (receive_data != IOT_SUCCESS)
{
printf("===== hi_i2c_read failed, 0x%x! =====\r\n", receive_data);
printf("===== hi_i2c_read failed, 0x%x! =====\r\n", receive_data);
return receive_data;
}
return HI_ERR_SUCCESS;
return IOT_SUCCESS;
}
// 发送软复位命令
static uint32_t AHT20ResetCommand(void)
static uint32_t Aht20ResetCommand(void)
{
uint8_t resetCmd[] = {AHT20_CMD_RESET};
return Aht20I2cWrite(resetCmd, sizeof(resetCmd));
}
// 发送初始化校准命令
static uint32_t AHT20CalibrateCommand(void)
static uint32_t Aht20CalibrateCommand(void)
{
uint8_t clibrateCmd[] = {AHT20_CMD_CALIBRATION, AHT20_CMD_CALIBRATION_ARG0, AHT20_CMD_CALIBRATION_ARG1};
return Aht20I2cWrite(clibrateCmd, sizeof(clibrateCmd));
}
/***
*
*
** return 0:
* @brief
* @brief
* @return IOT_SUCCESS:
*/
static hi_u32 AHT20Calibrate(void)
static unsigned int Aht20Calibrate(void)
{
uint8_t RevBuffer[AHT20_RECEIVE_MAX];
uint8_t statusCmd[] = {AHT20_CMD_STATE}; //状态字指令
uint32_t retval = 0;
retval = Aht20I2cWrite(statusCmd, sizeof(statusCmd)); //发送状态字指令
if (retval != HI_ERR_SUCCESS)
if (retval != IOT_SUCCESS)
{
return retval;
}
retval = Aht20I2cRead(RevBuffer, sizeof(RevBuffer)); //接收状态字
if (retval != HI_ERR_SUCCESS)
if (retval != IOT_SUCCESS)
{
return retval;
}
if ((RevBuffer[0] & 0x80) || !(RevBuffer[0] & 0x08)) //设备忙或未校准
// 设备忙或未校准
if ((RevBuffer[0] & 0x80) || !(RevBuffer[0] & 0x08))
{
retval = AHT20ResetCommand(); //调用软启动命令,重启设备
if (retval != HI_ERR_SUCCESS)
// 调用软启动命令,重启设备
retval = Aht20ResetCommand();
if (retval != IOT_SUCCESS)
{
return retval;
}
usleep(20 * 1000); //重启所需时间
retval = AHT20CalibrateCommand(); //校准命令
usleep(40 * 1000); //校准所需时间
// 重启所需时间
usleep(20 * 1000);
// 校准命令
retval = Aht20CalibrateCommand();
// 校准所需时间
usleep(40 * 1000);
return retval;
}
return HI_ERR_SUCCESS;
return IOT_SUCCESS;
}
/**
*
* return 0:
* @brief
* @return IOT_SUCCESS: IOT_FAILURE
*/
static uint32_t StartMeasure(void)
static uint32_t Aht20StartMeasure(void)
{
uint8_t triggerCmd[] = {AHT20_CMD_TRIGGER, AHT20_CMD_TRIGGER_ARG0, AHT20_CMD_TRIGGER_ARG1};
return Aht20I2cWrite(triggerCmd, sizeof(triggerCmd));
}
static int IsDeviceBusy(uint8_t *buffer)
{
return (buffer[0] & 0x80) >> 7;
}
/**
*
* \param[out] temp
* \param[out] humi
* * return 0:
**/
static uint32_t GetMeasureResult(float *temp, float *humi)
* @brief
* @param[out] temp
* @param[out] humi
* @return IOT_SUCCESS: IOT_FAILURE
*/
static uint32_t Aht20GetMeasureResult(float *temp, float *humi)
{
uint32_t retval = 0, i = 0;
uint8_t buffer[AHT20_RECEIVE_MAX];
if (temp == NULL || humi == NULL)
{
return HI_ERR_S_FAILURE;
return IOT_FAILURE;
}
uint8_t buffer[AHT20_RECEIVE_MAX];
memset(&buffer, 0x0, sizeof(buffer));
memset_s(&buffer, sizeof(buffer), 0x0, sizeof(buffer));
retval = Aht20I2cRead(buffer, sizeof(buffer)); // recv status command result
if (retval != HI_ERR_SUCCESS)
if (retval != IOT_SUCCESS)
{
return retval;
}
for (i = 0; (IsDeviceBusy(buffer)) && i < AHT20_MAX_RETRY; i++)
for (i = 0; ((buffer[0] & 0x80) >> 7) && i < AHT20_MAX_RETRY; i++)
{
usleep(75 * 1000);
retval = Aht20I2cRead(buffer, sizeof(buffer)); // recv status command result
if (retval != HI_ERR_SUCCESS)
if (retval != IOT_SUCCESS)
{
return retval;
}
@ -158,7 +163,7 @@ static uint32_t GetMeasureResult(float *temp, float *humi)
if (i >= AHT20_MAX_RETRY)
{
printf("AHT20 device always busy!\r\n");
return HI_ERR_S_FAILURE;
return IOT_FAILURE;
}
//转换
@ -172,14 +177,14 @@ static uint32_t GetMeasureResult(float *temp, float *humi)
tempRaw = (tempRaw << 8) | buffer[5];
*temp = tempRaw / (float)(1 << 20) * 200 - 50;
return HI_ERR_SUCCESS;
return IOT_SUCCESS;
}
/**
* 线
* \param arg
* @brief 线
* @param arg
*/
static void *THsensorTaskEntry(const char *arg)
static void *THSensorTaskEntry(const char *arg)
{
(void)arg;
uint32_t retval = 0;
@ -187,45 +192,56 @@ static void *THsensorTaskEntry(const char *arg)
float temp = 0.0, humi = 0.0;
//校准设备
retval = AHT20Calibrate();
retval = Aht20Calibrate();
printf("AHT20_Calibrate: %d\r\n", retval);
while (1)
{
//工作循环
retval = StartMeasure();
if (retval == HI_ERR_SUCCESS)
retval = Aht20StartMeasure();
if (retval == IOT_SUCCESS)
{
retval = GetMeasureResult(&temp, &humi);
if (retval == HI_ERR_SUCCESS)
retval = Aht20GetMeasureResult(&temp, &humi);
if (retval == IOT_SUCCESS)
{
printf("AHT20 GetMeasureResult: temp = %.2f, humi = %.2f\r\n", temp, humi);
}
}
usleep(1000000);
osDelay(100);
}
return NULL;
}
static void THsensorExampleEntry(void)
static void THSensorExampleEntry(void)
{
osThreadAttr_t attr;
IoTI2cInit(IOT_I2C_IDX_0, 100 * 1000); /* baudrate: 100K */
// 初始化IIC
IoTGpioInit(IOT_GPIO_IO_GPIO_13);
IoTGpioInit(IOT_GPIO_IO_GPIO_14);
attr.name = "THsensorTask";
IoTIoSetPull(IOT_GPIO_IO_GPIO_13, IOT_IO_PULL_UP);
IoTIoSetPull(IOT_GPIO_IO_GPIO_14, IOT_IO_PULL_UP);
IoTIoSetFunc(IOT_GPIO_IO_GPIO_13, IOT_IO_FUNC_GPIO_13_I2C0_SDA);
IoTIoSetFunc(IOT_GPIO_IO_GPIO_14, IOT_IO_FUNC_GPIO_14_I2C0_SCL);
// 设置IIC速率 100K
IoTI2cInit(IOT_I2C_IDX_0, 100 * 1000);
attr.name = "THSensorTask";
attr.attr_bits = 0U;
attr.cb_mem = NULL;
attr.cb_size = 0U;
attr.stack_mem = NULL;
attr.stack_size = CGSENSOR_TASK_STACK_SIZE;
attr.priority = CGSENSOR_TASK_PRIO;
attr.stack_size = THSENSOR_TASK_STACK_SIZE;
attr.priority = THSENSOR_TASK_PRIO;
if (osThreadNew((osThreadFunc_t)THsensorTaskEntry, NULL, &attr) == NULL)
if (osThreadNew((osThreadFunc_t)THSensorTaskEntry, NULL, &attr) == NULL)
{
printf("[THsensorExampleEntry] Falied to create THsensorTask!\n");
printf("[THsensorExampleEntry] Falied to create THSensorTask!\n");
}
}
APP_FEATURE_INIT(THsensorExampleEntry);
APP_FEATURE_INIT(THSensorExampleEntry);

View File

@ -32,7 +32,7 @@ static void BeepStop(void)
IoTPwmStop(IOT_PWM_PORT_PWM0);
}
void BeepCtrl(BeepCtrlAttr* ctrlAttr)
void BeepCtrl(struct BEEPCTRLATTR* ctrlAttr)
{
static unsigned char step = 0;
static unsigned int onceOpenCnt = 0, onceCloseCnt = 0;

View File

@ -13,16 +13,21 @@
* limitations under the License.
*/
#include "iot_errno.h"
#include "iot_pwm.h"
#include "hi_pwm.h"
#define CLK_160M 160000000
#define DUTY_MIN 0
#define DUTY_MAX 100
#define SHORT_MAX 0xFFFF
unsigned int IoTPwmInit(unsigned int port)
{
if (hi_pwm_set_clock(PWM_CLK_160M) != IOT_SUCCESS)
{
return IOT_FAILURE;
}
return hi_pwm_init((hi_pwm_port)port);
}
@ -38,12 +43,21 @@ unsigned int IoTPwmDeinit(unsigned int port)
unsigned int IoTPwmStart(unsigned int port, unsigned short duty, unsigned int freq)
{
if ((freq == 0) || (duty >= DUTY_MAX) || (duty == DUTY_MIN))
{
unsigned short hiDuty;
unsigned short hiFreq;
if ((freq == 0) || (duty >= DUTY_MAX) || (duty == DUTY_MIN)) {
return IOT_FAILURE;
}
return hi_pwm_start((hi_pwm_port)port, duty, freq);
if ((CLK_160M / freq) > SHORT_MAX) {
return IOT_FAILURE;
}
hiFreq = (unsigned short)(CLK_160M / freq);
hiDuty = (duty * hiFreq) / DUTY_MAX;
return hi_pwm_start((hi_pwm_port)port, hiDuty, hiFreq);
}
unsigned int IoTPwmStop(unsigned int port)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,200 @@
execute ota_builder with python...
riscv32-unknown-elf-gcc -Iplatform/os/Huawei_LiteOS/kernel/include -Iconfig -DCONFIG_TEE_HUKS_SUPPORT -DCONFIG_CHIP_PKT_32K -DHI_BOARD_ASIC -DHI_ON_FLASH -E build/link/system_config.ld.S -o build/build_tmp/scripts/system_config.ld -P
nvimg_builder(["build/build_tmp/scripts/system_config.ld"], ["build/link/system_config.ld.S"])
product_name_list: ['sta']
xml h file: /home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/h_file/nv
/home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/out_nv_bin/sta
app_subver_list: ['demo']
current subver_name:demo
root_dir: /home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool
mdm_xml: /home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/xml_file/mss_nvi_db.xml
HNV NAME:mss_nvi_db.xml
nv_tool: /home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/tools/nv/cdbm
app_subver_temp_dir:/home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/out_nv_bin/sta/nv/Hi3861_wifiiot_app/outside_demo
make app_subver_temp_dir
mdmxml:/home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/xml_file/mss_nvi_db.xml
src_xml_list: ['/home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/xml_file/mss_nvi_db.xml']
combin_xml:/home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/out_nv_bin/sta/nv/Hi3861_wifiiot_app/mss_nvi_db.xml
root_list [<Element 'HISTUDIO' at 0x7f56df593c70>]
hi_nv_modify_by_cfg
cfg_file: nv
cmd_line= ('/home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/tools/nv/cdbm', '/home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/out_nv_bin/sta/nv/Hi3861_wifiiot_app/outside_demo/nv.xml', '/home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/h_file/nv', '/home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/out_nv_bin/sta/nv/Hi3861_wifiiot_app/outside_demo/nv')
/home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/out_nv_bin/sta/nv/Hi3861_wifiiot_app/outside_demo/nv.xml
/home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/h_file/nv
/home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/out_nv_bin/sta/nv/Hi3861_wifiiot_app/outside_demo/nv
===========Init HDB Start===========
*********strDataTypeDefPath:/home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/h_file/nv/../nv/nv_modem_struct_def.txt
*********strDataTypeDefPath:/home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/h_file/nv/../nv/nv_modem_struct_def.txt
*********strDataTypeDefPath:/home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/h_file/nv/../nv/nv_factory_struct_def.txt
===========Init HDB finish===========
===========Write NV Buffer To File===========
===========Write NV Buffer Finish===========
RETURN VALUE:0
dst_hnv= /home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/out_nv_bin/sta/nv/hnv/Hi3861_wifiiot_app.hnv
Factory NV total num:10
NV_FILE_STRU :28
Factory NV total size:824
Normal NV total num:13
NV_FILE_STRU :28
Normal NV total size:766
build hnv OK:/home/openharmony/device/talkweb/niobe/sdk_liteos/tools/nvtool/out_nv_bin/sta/nv/hnv/Hi3861_wifiiot_app.hnv
ENDING
riscv32-unknown-elf-gcc -Iplatform/os/Huawei_LiteOS/kernel/include -Iconfig -DCONFIG_TEE_HUKS_SUPPORT -DCONFIG_CHIP_PKT_32K -DHI_BOARD_ASIC -DHI_ON_FLASH -DFLASH_FIRM_START=4248512 -E build/link/link.ld.S -o build/build_tmp/scripts/link.lds -P
riscv32-unknown-elf-ld -nostartfiles -nostdlib -static --gc-sections -L/home/openharmony/device/talkweb/niobe/sdk_liteos/build/scripts/../../../../../huawei/hms/hilink/ohos/l0/hi3861/lib/wifi -L/home/tools/gcc_riscv32/bin/../lib/gcc/riscv32-unknown-elf/7.3.0 -Lbuild/build_tmp/libs/app/wifiiot_app -Lbuild/build_tmp/libs/components/at -Lbuild/build_tmp/libs/platform/drivers -Lbuild/build_tmp/libs/platform/system -Lbuild/build_tmp/scripts -Lbuild/libs -Lbuild/libs/hi3861/release/no_mesh -Lbuild/scripts -Lohos/libs -Tbuild/build_tmp/scripts/link.lds -Map=output/bin/Hi3861_wifiiot_app.map -o output/bin/Hi3861_wifiiot_app.out --start-group --no-whole-archive --whole-archive -ladc -lat -lauthmanager -lblackbox -lbootstrap -lbroadcast -lc_flash -lcfg -lcjson_static -lcmsis -lcpup -ldeviceauth -ldeviceauth_hal_liteos -ldiag -ldiscovery -ldrv -ldump_static -lflash -lgcc -lgpio -lhal_file_static -lhal_iothardware -lhal_sysparam -lhal_token_static -lhal_update_static -lhal_wifiaware -lhichainsdk -lhidumper_mini -lhievent_lite -lhilog_lite -lhiview_lite -lhota -lhuks_3.0_sdk -li2c -lio -liperf -llitekernel_flash -lltoswpa -llwip -lm_flash -lmbedtls -lmodule_enviroment_example -lnative_file -lparttab -lposix -lpwm -lres_cfg -lsamgr -lsamgr_adapter -lsamgr_source -lsdio -lsec_flash -lspiffs -lsysparam -lsystem -ltoken_static -ltrans_service -ltsensor -luart -lupg -lutils_kv_store -lwifi -lwifi_flash -lwifiaware -lwifiiot_app -lwifiservice -lwpa --end-group
riscv32-unknown-elf-objcopy -O binary output/bin/Hi3861_wifiiot_app.out build/build_tmp/cache/Hi3861_wifiiot_app.bin
baseimg_builder(["build/build_tmp/cache/Hi3861_wifiiot_app_base.bin", "build/build_tmp/cache/Hi3861_wifiiot_app_kernel.bin"], ["build/build_tmp/cache/Hi3861_wifiiot_app.bin"])
cleanup(["build/build_tmp/cache/Hi3861_wifiiot_app_base.bin", "build/build_tmp/cache/Hi3861_wifiiot_app_kernel.bin"], ["build/build_tmp/cache/Hi3861_wifiiot_app.bin"])
ota_builder(["build/build_tmp/cache/Hi3861_wifiiot_app_ota_temp.bin"], ["build/build_tmp/cache/Hi3861_wifiiot_app_base.bin", "build/build_tmp/cache/Hi3861_wifiiot_app_kernel.bin"])
********************package kernel&nv upgrade file********************
upg kernel file in: build/build_tmp/cache/Hi3861_wifiiot_app_kernel.bin
upg normal nv file in: build/build_tmp/nv/Hi3861_wifiiot_app_normal.hnv
upg file out: build/build_tmp/cache/Hi3861_wifiiot_app_ota_temp.bin
[common_head_offset=0][common_head_size=96]
[common_key_offset=96][common_key_size=288]
[common_head_sign_offset=384][common_head_sign_size=256]
[section_head_offset=640][section_head_size=64]
[upg_file_sign_offset=704][upg_file_sign_size=256]
[padding_offset=638088][padding_size=8]
[upg fill user info]chip:b'Hi3861'
-------------build/build_tmp/cache/Hi3861_wifiiot_app_ota_temp.bin image info print start-------------
[image_id=0x3c78961e][struct_version=0x0]]
[section_offset=0x280][section_len=0x9ba10]
[file_type=0xf0][file_version=0x0][encrypt_flag=0x42]
[file_len=0x9bc90][key_len=0x120]
[file_attr=0x44]
[hash_alg=0x0][sign_alg=0x3f][sign_param=0x0]
[aes_key[0-1-14-15]=[0x0][0x0][0x0][0x0]]
[aes_iv [0-1-14-15]=[0x0][0x0][0x0][0x0]]
[common key][00]=[0x0]
[common key][01]=[0x0]
[common key][30]=[0x0]
[common key][31]=[0x0]
[common sign][00]=[0x62]
[common sign][01]=[0x81]
[common sign][30]=[0x1e]
[common sign][31]=[0x70]
[section sign][00]=[0xea]
[section sign][01]=[0xa6]
[section sign][30]=[0xd4]
[section sign][31]=[0xb2]
[image_id=0x3c78961e][struct_version=0x0]]
[hash_alg=0x0][sign_alg=0x3f][sign_param=0x0]
[section_count=0x2]
[section0_compress=0x0][section0_offset=0x3c0][section0_len=0x9a8c8]
[section1_compress=0x0][section1_offset=0x9ac88][section1_len=0x1000]
-------------build/build_tmp/cache/Hi3861_wifiiot_app_ota_temp.bin image info print end--------------
riscv32-unknown-elf-objdump -d output/bin/Hi3861_wifiiot_app.out > output/bin/Hi3861_wifiiot_app.asm
burn_bin_builder(["output/bin/Hi3861_wifiiot_app_burn.bin", "output/bin/Hi3861_wifiiot_app_allinone.bin"], ["build/build_tmp/cache/Hi3861_wifiiot_app_ota_temp.bin", "output/bin/Hi3861_loader_signed.bin"])
********************package hiburn file********************
hbin flash boot file in : output/bin/Hi3861_boot_signed.bin
hbin factory nv file in : build/build_tmp/nv/Hi3861_wifiiot_app_factory.hnv
hbin normal nv file in : build/build_tmp/cache/Hi3861_wifiiot_app_ota_temp.bin
hbin upg file in : build/build_tmp/nv/Hi3861_wifiiot_app_factory.hnv
hbin file out : output/bin/Hi3861_wifiiot_app_burn.bin
-------------output/bin/Hi3861_wifiiot_app_burn.bin image info print start-------------
[bin_size]=[0xa8c90]
[image_id=0x3c78961e][struct_version=0x0]]
[section_offset=0x280][section_len=0x9ba10]
[file_type=0xf0][file_version=0x0][encrypt_flag=0x42]
[file_len=0x9bc90][key_len=0x120]
[hash_alg=0x0][sign_alg=0x3f][sign_param=0x0]
[aes_key[0,1,14,15]=[0x0][0x0][0x0][0x0]]
[aes_iv[0,1,14,15]=[0x0][0x0][0x0][0x0]]
-------------output/bin/Hi3861_wifiiot_app_burn.bin image info print end--------------
['output/bin/Hi3861_loader_signed.bin', 'output/bin/Hi3861_wifiiot_app_burn.bin']
[0, 0]
[0, 2097152]
[15360, 691344]
[0, 1]
4022250975
boot_ota_builder(["output/bin/Hi3861_wifiiot_app_flash_boot_ota.bin"], ["output/bin/Hi3861_boot_signed.bin"])
********************package boot upgrade file********************
boot upg file in: output/bin/Hi3861_boot_signed.bin
boot upg file out: output/bin/Hi3861_wifiiot_app_flash_boot_ota.bin
[common_head_offset=0][common_head_size=96]
[common_key_offset=96][common_key_size=288]
[common_head_sign_offset=384][common_head_sign_size=256]
[section_head_offset=640][section_head_size=64]
[upg_file_sign_offset=704][upg_file_sign_size=256]
[padding_offset=0][padding_size=0]
[upg fill user info]chip:b'Hi3861'
-------------output/bin/Hi3861_wifiiot_app_flash_boot_ota.bin image info print start-------------
[image_id=0x3c78961e][struct_version=0x0]]
[section_offset=0x280][section_len=0x60a0]
[file_type=0xe1][file_version=0x0][encrypt_flag=0x42]
[file_len=0x6320][key_len=0x120]
[file_attr=0x44]
[hash_alg=0x0][sign_alg=0x3f][sign_param=0x0]
[aes_key[0-1-14-15]=[0x0][0x0][0x0][0x0]]
[aes_iv [0-1-14-15]=[0x0][0x0][0x0][0x0]]
[common key][00]=[0x0]
[common key][01]=[0x0]
[common key][30]=[0x0]
[common key][31]=[0x0]
[common sign][00]=[0xc9]
[common sign][01]=[0x21]
[common sign][30]=[0x2f]
[common sign][31]=[0x82]
[section sign][00]=[0x34]
[section sign][01]=[0x40]
[section sign][30]=[0x90]
[section sign][31]=[0x2]
[image_id=0x3c78961e][struct_version=0x0]]
[hash_alg=0x0][sign_alg=0x3f][sign_param=0x0]
[section_count=0x1]
[section0_compress=0x0][section0_offset=0x3c0][section0_len=0x5f60]
[section1_compress=0x0][section1_offset=0x0][section1_len=0x0]
-------------output/bin/Hi3861_wifiiot_app_flash_boot_ota.bin image info print end--------------
compress_ota_builder(["output/bin/Hi3861_wifiiot_app_ota.bin"], ["build/build_tmp/cache/Hi3861_wifiiot_app_ota_temp.bin"])
********************package compress upgrade file********************
compress upg file in: build/build_tmp/cache/Hi3861_wifiiot_app_ota_temp.bin
compress upg file out: output/bin/Hi3861_wifiiot_app_ota.bin
lzma compress tool : /home/openharmony/device/talkweb/niobe/sdk_liteos/build/scripts/../../tools/lzma_tool/lzma_tool
lzma src file : build/build_tmp/cache/Hi3861_wifiiot_app_ota_temp.bin
lzma out file : build/build_tmp/cache/Hi3861_wifiiot_app_ota_temp.lzma
LZMA 19.00 (x64) : Igor Pavlov : Public domain : 2019-02-21
Input size: 638096 (0 MiB)
 Output size: 398360 (0 MiB)
[upgbin-compressbin]0x9bc90-0x13a000
[common_head_offset=0][common_head_size=96]
[common_key_offset=96][common_key_size=288]
[common_head_sign_offset=384][common_head_sign_size=256]
[section_head_offset=640][section_head_size=64]
[upg_file_sign_offset=704][upg_file_sign_size=256]
[padding_offset=399320][padding_size=8]
[upg fill user info]chip:b'Hi3861'
-------------output/bin/Hi3861_wifiiot_app_ota.bin image info print start-------------
[image_id=0x3c78961e][struct_version=0x0]]
[section_offset=0x280][section_len=0x61560]
[file_type=0xf0][file_version=0x0][encrypt_flag=0x42]
[file_len=0x617e0][key_len=0x120]
[file_attr=0x44]
[hash_alg=0x0][sign_alg=0x3f][sign_param=0x0]
[aes_key[0-1-14-15]=[0x0][0x0][0x0][0x0]]
[aes_iv [0-1-14-15]=[0x0][0x0][0x0][0x0]]
[common key][00]=[0x0]
[common key][01]=[0x0]
[common key][30]=[0x0]
[common key][31]=[0x0]
[common sign][00]=[0x4f]
[common sign][01]=[0x8d]
[common sign][30]=[0x57]
[common sign][31]=[0x67]
[section sign][00]=[0x48]
[section sign][01]=[0xac]
[section sign][30]=[0x3e]
[section sign][31]=[0xaa]
[image_id=0x3c78961e][struct_version=0x0]]
[hash_alg=0x0][sign_alg=0x3f][sign_param=0x0]
[section_count=0x1]
[section0_compress=0x1][section0_offset=0x3c0][section0_len=0x61418]
[section1_compress=0x0][section1_offset=0x0][section1_len=0x0]
-------------output/bin/Hi3861_wifiiot_app_ota.bin image info print end--------------

< ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >
BUILD SUCCESS
< ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >


View File

@ -0,0 +1,14 @@
Building at 2021/10/22 10:54:43
----------------------------top-----------------
lib_name: uart
lib_name: adc
lib_name: tsensor
lib_name: i2c
lib_name: pwm
lib_name: cfg
lib_name: parttab
lib_name: upg
lib_name: at
lib_name: wifiiot_app
~~~~~~~~~~~~~~~~~~~~~~~~~~~~libpath: ['-L/home/openharmony/device/talkweb/niobe/sdk_liteos/build/scripts/../../../../../huawei/hms/hilink/ohos/l0/hi3861/lib/wifi', '-L/home/tools/gcc_riscv32/bin/../lib/gcc/riscv32-unknown-elf/7.3.0', '-Lbuild/build_tmp/libs/app/wifiiot_app', '-Lbuild/build_tmp/libs/components/at', '-Lbuild/build_tmp/libs/platform/drivers', '-Lbuild/build_tmp/libs/platform/system', '-Lbuild/build_tmp/scripts', '-Lbuild/libs', '-Lbuild/libs/hi3861/release/no_mesh', '-Lbuild/scripts', '-Lohos/libs']
~~~~~~~~~~~~~~~~~~~~~~~~~~~~libs: ['--no-whole-archive', '--whole-archive', '-ladc', '-lat', '-lauthmanager', '-lblackbox', '-lbootstrap', '-lbroadcast', '-lc_flash', '-lcfg', '-lcjson_static', '-lcmsis', '-lcpup', '-ldeviceauth', '-ldeviceauth_hal_liteos', '-ldiag', '-ldiscovery', '-ldrv', '-ldump_static', '-lflash', '-lgcc', '-lgpio', '-lhal_file_static', '-lhal_iothardware', '-lhal_sysparam', '-lhal_token_static', '-lhal_update_static', '-lhal_wifiaware', '-lhichainsdk', '-lhidumper_mini', '-lhievent_lite', '-lhilog_lite', '-lhiview_lite', '-lhota', '-lhuks_3.0_sdk', '-li2c', '-lio', '-liperf', '-llitekernel_flash', '-lltoswpa', '-llwip', '-lm_flash', '-lmbedtls', '-lmodule_enviroment_example', '-lnative_file', '-lparttab', '-lposix', '-lpwm', '-lres_cfg', '-lsamgr', '-lsamgr_adapter', '-lsamgr_source', '-lsdio', '-lsec_flash', '-lspiffs', '-lsysparam', '-lsystem', '-ltoken_static', '-ltrans_service', '-ltsensor', '-luart', '-lupg', '-lutils_kv_store', '-lwifi', '-lwifi_flash', '-lwifiaware', '-lwifiiot_app', '-lwifiservice', '-lwpa']

Some files were not shown because too many files have changed in this diff Show More