2023-10-08 08:10:23 +00:00
|
|
|
#include "MCUTaskInPara.h"
|
|
|
|
|
#include "McuBspAdc.h"
|
|
|
|
|
#include "McuBspGpio.h"
|
|
|
|
|
#include "bme68x.h"
|
|
|
|
|
#include "bme68x_defs.h"
|
|
|
|
|
#include "McuBspI2c.h"
|
|
|
|
|
#include "McuTaskBlueTooth.h"
|
|
|
|
|
#include "ZthyToolDataTypeSwitch.h"
|
|
|
|
|
#include "BeiDouHtyDrv.h"
|
|
|
|
|
#include "McuTaskFlash.h"
|
|
|
|
|
#include "McuSelfDestructionDrv.h"
|
|
|
|
|
#include "McuBspTimer.h"
|
2024-07-31 00:52:45 +00:00
|
|
|
#include "Usr_4GCatDtuDrv.h"
|
|
|
|
|
#include "McuTaskLowPower.h"
|
2023-10-08 08:10:23 +00:00
|
|
|
|
|
|
|
|
#include <string.h>
|
2023-10-09 01:01:31 +00:00
|
|
|
#include <stdio.h>
|
2023-10-08 08:10:23 +00:00
|
|
|
|
|
|
|
|
#define MCU_TASK_POWER_V_ADC MCU_ADC1
|
|
|
|
|
|
|
|
|
|
#define MCU_TASK_BME680_IIC_ADDR 0xEC // 已经进行了一位偏移
|
|
|
|
|
#define MCU_TASK_BME680_IIC_TYPE MCU_BSP_I2C_REG // 哪一种IIC通信(主从或者带寄存器)
|
|
|
|
|
#define MCU_TASK_BME680_IIC_ID MCU_BSP_I2C2_ID // 使用那一路IIC进行通信
|
|
|
|
|
|
|
|
|
|
/* 控制引脚配置 */
|
|
|
|
|
#define MCU_TASK_ADC_ONOFF_GPIO_PORT GPIOF
|
|
|
|
|
#define MCU_TASK_ADC_ONOFF_GPIO_PIN GPIO_PIN_15
|
|
|
|
|
#define MCU_TASK_ADC_ONOFF_GPIO_MODE GPIO_MODE_OUTPUT_PP
|
|
|
|
|
#define MCU_TASK_ADC_ONOFF_GPIO_SPEED GPIO_SPEED_FREQ_HIGH
|
|
|
|
|
#define MCU_TASK_ADC_ONOFF_GPIO_PULL GPIO_PULLDOWN
|
|
|
|
|
|
|
|
|
|
static int McuTaskAdcInit(void);
|
|
|
|
|
/* ADC上电 */
|
|
|
|
|
static void McuTaskAdcUpPower(void);
|
|
|
|
|
static void McuTaskAdcDownPower(void);
|
|
|
|
|
/* 关于自毁信号的处理函数 */
|
|
|
|
|
static void McuTaskSelfStructionHandle(void);
|
|
|
|
|
|
|
|
|
|
/* 蓝牙发送标志位 */
|
|
|
|
|
static int gMcuTaskInParaBlueToothSendFlag = 0;
|
|
|
|
|
static unsigned short gMcuTaskInParaBlueToothSerial = 0;
|
|
|
|
|
static unsigned char gMcuTaskInParaBlueToothSendBuf[18] = {0};
|
|
|
|
|
|
2024-07-31 00:52:45 +00:00
|
|
|
static unsigned short gMcuTaskInPara4gSerial = 0;
|
|
|
|
|
|
2023-10-08 08:10:23 +00:00
|
|
|
/* 北斗发送标志位 */
|
|
|
|
|
static int gMcuTaskInParaBeiDouSendFlag = 0;
|
2023-10-09 01:01:31 +00:00
|
|
|
static unsigned char gMcuTaskInParaBeiDouSerial = 0;
|
2023-10-08 08:10:23 +00:00
|
|
|
/* 电压AD监测 */
|
|
|
|
|
static float gMcuTaskInParaPower = 0.0f;
|
|
|
|
|
static uint32_t gMcuTaskInParaPower32 = 0;
|
|
|
|
|
|
|
|
|
|
/* BME680 */
|
|
|
|
|
static uint8_t gNfields = 0; // 数据内容是否为最新内容
|
|
|
|
|
static struct bme68x_data gData = {0}; // BME680的采集数据
|
|
|
|
|
static struct bme68x_dev gMcuTaskBme680Dev = {0}; // 新建一个设备
|
|
|
|
|
static uint8_t gMcuTaskBme680DevId = MCU_TASK_BME680_IIC_ADDR; // 设备地址
|
|
|
|
|
|
|
|
|
|
static uint32_t gMcuTaskBme680Temp = 0; // 温度的4字节底层存储形式
|
|
|
|
|
static uint32_t gMcuTaskBme680Humi = 0; // 湿度的4字节底层存储形式
|
|
|
|
|
static uint32_t gMcuTaskBme680Press = 0; // 压力的4字节底层存储形式
|
|
|
|
|
|
|
|
|
|
/* 自毁模式 */
|
|
|
|
|
static int gMcuTaskSelfDestructionMode = 0;
|
2024-07-31 00:52:45 +00:00
|
|
|
static int gMcuTaskSelfDestructioTimer1Id = -1;
|
2023-10-08 08:10:23 +00:00
|
|
|
static MCU_BSP_TIMER_TASK gMcuTaskSelfDestructioTimer1;
|
2024-07-31 00:52:45 +00:00
|
|
|
static int gMcuTaskSelfDestructioTimer2Id = -1;
|
2023-10-08 08:10:23 +00:00
|
|
|
static MCU_BSP_TIMER_TASK gMcuTaskSelfDestructioTimer2;
|
|
|
|
|
|
|
|
|
|
static int8_t McuTaskBme680Init(void);
|
|
|
|
|
static int8_t McuTaskBme680Measure(void);
|
|
|
|
|
static BME68X_INTF_RET_TYPE McuTaskBme680Read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length,
|
|
|
|
|
void *intf_ptr);
|
|
|
|
|
static BME68X_INTF_RET_TYPE McuTaskBme680Write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length,
|
|
|
|
|
void *intf_ptr);
|
|
|
|
|
static void McuTaskBme680DelayUs(uint32_t period, void *intf_ptr);
|
|
|
|
|
/* 关于自毁定时器反馈 */
|
|
|
|
|
static void McuTaskSelfStructionTimer1Handle(void);
|
|
|
|
|
static void McuTaskSelfStructionTimer2Handle(void);
|
|
|
|
|
|
|
|
|
|
/* 内部参数初始化 */
|
|
|
|
|
int McuTaskInParaInit(void)
|
|
|
|
|
{
|
|
|
|
|
/* 初始化BME680 */
|
|
|
|
|
McuTaskBme680Init();
|
|
|
|
|
/* 初始化ADC采样 */
|
|
|
|
|
McuTaskAdcInit();
|
|
|
|
|
/* 初始化自毁信号 */
|
|
|
|
|
McuSelfDestructionDrvInit(McuTaskSelfStructionHandle);
|
|
|
|
|
gMcuTaskSelfDestructionMode = McuTaskFlashGetSelfDestruction(); // 获取保存的自毁模式状态
|
|
|
|
|
if (gMcuTaskSelfDestructionMode < 0) {
|
|
|
|
|
gMcuTaskSelfDestructionMode = 0;
|
|
|
|
|
}
|
|
|
|
|
McuSelfDestructionDrvSetMode(gMcuTaskSelfDestructionMode);
|
|
|
|
|
gMcuTaskSelfDestructioTimer1.TaskPeriod = 30;
|
|
|
|
|
gMcuTaskSelfDestructioTimer1.Callback = McuTaskSelfStructionTimer1Handle;
|
|
|
|
|
gMcuTaskSelfDestructioTimer2.TaskPeriod = 10;
|
|
|
|
|
gMcuTaskSelfDestructioTimer2.Callback = McuTaskSelfStructionTimer2Handle;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int McuTaskInParaTask(void)
|
|
|
|
|
{
|
|
|
|
|
if (gMcuTaskInParaBlueToothSendFlag == 1 || gMcuTaskInParaBeiDouSendFlag == 1) {
|
|
|
|
|
McuTaskFlashWriteOpt("InPara Join\r\n", strlen("InPara Join\r\n"));
|
|
|
|
|
/* 获取数据 */
|
|
|
|
|
McuTaskAdcUpPower();
|
|
|
|
|
HAL_Delay(2000);
|
|
|
|
|
McuBspAdcGetData(MCU_TASK_POWER_V_ADC, &gMcuTaskInParaPower);
|
|
|
|
|
McuTaskAdcDownPower();
|
|
|
|
|
McuTaskBme680Measure();
|
|
|
|
|
if (gMcuTaskInParaBlueToothSendFlag == 1) {
|
|
|
|
|
ZthyToolFloatToUint32(gData.temperature, &gMcuTaskBme680Temp);
|
|
|
|
|
ZthyToolFloatToUint32(gData.humidity, &gMcuTaskBme680Humi);
|
|
|
|
|
ZthyToolFloatToUint32(gData.pressure, &gMcuTaskBme680Press);
|
|
|
|
|
ZthyToolFloatToUint32(gMcuTaskInParaPower, &gMcuTaskInParaPower32);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[0] = 1;
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[1] = (uint8_t)((gMcuTaskBme680Temp & 0xff000000) >> 24);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[2] = (uint8_t)((gMcuTaskBme680Temp & 0x00ff0000) >> 16);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[3] = (uint8_t)((gMcuTaskBme680Temp & 0x0000ff00) >> 8);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[4] = (uint8_t)(gMcuTaskBme680Temp & 0x000000ff);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[5] = (uint8_t)((gMcuTaskBme680Humi & 0xff000000) >> 24);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[6] = (uint8_t)((gMcuTaskBme680Humi & 0x00ff0000) >> 16);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[7] = (uint8_t)((gMcuTaskBme680Humi & 0x0000ff00) >> 8);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[8] = (uint8_t)(gMcuTaskBme680Humi & 0x000000ff);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[9] = (uint8_t)((gMcuTaskBme680Press & 0xff000000) >> 24);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[10] = (uint8_t)((gMcuTaskBme680Press & 0x00ff0000) >> 16);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[11] = (uint8_t)((gMcuTaskBme680Press & 0x0000ff00) >> 8);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[12] = (uint8_t)(gMcuTaskBme680Press & 0x000000ff);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[13] = (uint8_t)((gMcuTaskInParaPower32 & 0xff000000) >> 24);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[14] = (uint8_t)((gMcuTaskInParaPower32 & 0x00ff0000) >> 16);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[15] = (uint8_t)((gMcuTaskInParaPower32 & 0x0000ff00) >> 8);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[16] = (uint8_t)(gMcuTaskInParaPower32 & 0x000000ff);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[17] = (uint8_t)gMcuTaskSelfDestructionMode;
|
|
|
|
|
McuTaskFlashWriteOpt("InPara BlueTh Send Data\r\n", strlen("InPara BlueTh Send Data\r\n"));
|
|
|
|
|
TaskBlueToothSendMessage(MCU_TASK_INPARA_SEND_MESSAGE_ID, &gMcuTaskInParaBlueToothSerial, gMcuTaskInParaBlueToothSendBuf, sizeof(gMcuTaskInParaBlueToothSendBuf));
|
|
|
|
|
gMcuTaskInParaBlueToothSerial++;
|
|
|
|
|
gMcuTaskInParaBlueToothSendFlag = 0;
|
|
|
|
|
}
|
|
|
|
|
if (gMcuTaskInParaBeiDouSendFlag == 1) {
|
|
|
|
|
gMcuTaskInParaBeiDouSendFlag = 0;
|
2024-07-31 00:52:45 +00:00
|
|
|
if (1 != McuDrv4GCatDtuPowerSta()) {
|
|
|
|
|
unsigned char crc = 0;
|
|
|
|
|
int i = 0;
|
|
|
|
|
unsigned char BeiDouSend[70] = {0};
|
|
|
|
|
gMcuTaskInParaBeiDouSendFlag = 0;
|
|
|
|
|
|
|
|
|
|
crc = 0;
|
|
|
|
|
sprintf((char *)BeiDouSend, "InPara 01 %03d %0.2f %0.2f %0.2f %0.2f", gMcuTaskInParaBeiDouSerial, gData.temperature, gData.humidity, gData.pressure, gMcuTaskInParaPower);
|
|
|
|
|
for (i = 0; i < strlen((char *)BeiDouSend); i++) {
|
|
|
|
|
crc ^= BeiDouSend[i];
|
|
|
|
|
}
|
|
|
|
|
sprintf((char *)&BeiDouSend[strlen((char *)BeiDouSend)], "%x", crc);
|
|
|
|
|
McuDrvBeiDouHtySendPacket(BeiDouSend, strlen((char *)BeiDouSend));
|
|
|
|
|
|
|
|
|
|
gMcuTaskInParaBeiDouSerial++;
|
|
|
|
|
gMcuTaskInParaBeiDouSerial = gMcuTaskInParaBeiDouSerial % 1000;
|
|
|
|
|
McuTaskFlashWriteOpt("InPara BeiDou Send Data\r\n", strlen("InPara BeiDou Send Data\r\n"));
|
|
|
|
|
} else {
|
|
|
|
|
ZthyToolFloatToUint32(gData.temperature, &gMcuTaskBme680Temp);
|
|
|
|
|
ZthyToolFloatToUint32(gData.humidity, &gMcuTaskBme680Humi);
|
|
|
|
|
ZthyToolFloatToUint32(gData.pressure, &gMcuTaskBme680Press);
|
|
|
|
|
ZthyToolFloatToUint32(gMcuTaskInParaPower, &gMcuTaskInParaPower32);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[0] = 1;
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[1] = (uint8_t)((gMcuTaskBme680Temp & 0xff000000) >> 24);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[2] = (uint8_t)((gMcuTaskBme680Temp & 0x00ff0000) >> 16);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[3] = (uint8_t)((gMcuTaskBme680Temp & 0x0000ff00) >> 8);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[4] = (uint8_t)(gMcuTaskBme680Temp & 0x000000ff);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[5] = (uint8_t)((gMcuTaskBme680Humi & 0xff000000) >> 24);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[6] = (uint8_t)((gMcuTaskBme680Humi & 0x00ff0000) >> 16);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[7] = (uint8_t)((gMcuTaskBme680Humi & 0x0000ff00) >> 8);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[8] = (uint8_t)(gMcuTaskBme680Humi & 0x000000ff);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[9] = (uint8_t)((gMcuTaskBme680Press & 0xff000000) >> 24);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[10] = (uint8_t)((gMcuTaskBme680Press & 0x00ff0000) >> 16);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[11] = (uint8_t)((gMcuTaskBme680Press & 0x0000ff00) >> 8);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[12] = (uint8_t)(gMcuTaskBme680Press & 0x000000ff);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[13] = (uint8_t)((gMcuTaskInParaPower32 & 0xff000000) >> 24);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[14] = (uint8_t)((gMcuTaskInParaPower32 & 0x00ff0000) >> 16);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[15] = (uint8_t)((gMcuTaskInParaPower32 & 0x0000ff00) >> 8);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[16] = (uint8_t)(gMcuTaskInParaPower32 & 0x000000ff);
|
|
|
|
|
gMcuTaskInParaBlueToothSendBuf[17] = (uint8_t)gMcuTaskSelfDestructionMode;
|
|
|
|
|
McuTaskFlashWriteOpt("InPara 4G Send Data\r\n", strlen("InPara 4G Send Data\r\n"));
|
|
|
|
|
McuDrv4GSendMessage(MCU_TASK_INPARA_SEND_MESSAGE_ID, &gMcuTaskInPara4gSerial, gMcuTaskInParaBlueToothSendBuf, sizeof(gMcuTaskInParaBlueToothSendBuf));
|
|
|
|
|
gMcuTaskInPara4gSerial++;
|
2023-10-09 01:01:31 +00:00
|
|
|
}
|
2023-10-08 08:10:23 +00:00
|
|
|
}
|
|
|
|
|
McuTaskFlashWriteInPara(gData.temperature, gData.humidity, gData.pressure, gMcuTaskInParaPower, gMcuTaskSelfDestructionMode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 蓝牙请求数据 */
|
|
|
|
|
void McuTaskInParaBlueToothAsk(void)
|
|
|
|
|
{
|
|
|
|
|
gMcuTaskInParaBlueToothSendFlag = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 北斗请求数据 */
|
|
|
|
|
void McuTaskInParaBeiDouAsk(void)
|
|
|
|
|
{
|
|
|
|
|
gMcuTaskInParaBeiDouSendFlag = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 获取数据请求状态 */
|
|
|
|
|
int McuTaskInParaAskStatus(void)
|
|
|
|
|
{
|
|
|
|
|
return ((gMcuTaskInParaBlueToothSendFlag * 2) | gMcuTaskInParaBeiDouSendFlag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 设置自毁状态 */
|
|
|
|
|
void McuTaskSetSelfStructionMode(uint8_t mode)
|
|
|
|
|
{
|
|
|
|
|
if (gMcuTaskSelfDestructionMode != mode) {
|
|
|
|
|
gMcuTaskSelfDestructionMode = mode;
|
|
|
|
|
/* 保存自毁模式状态 */
|
|
|
|
|
McuTaskFlashSetSelfDestruction(gMcuTaskSelfDestructionMode);
|
|
|
|
|
/* 设置自毁模式状态 */
|
|
|
|
|
McuSelfDestructionDrvSetMode(gMcuTaskSelfDestructionMode);
|
|
|
|
|
if (gMcuTaskSelfDestructionMode == 0) {
|
|
|
|
|
if (gMcuTaskSelfDestructioTimer1Id >= 0) {
|
2024-07-31 00:52:45 +00:00
|
|
|
McuBspTimerDelTask(gMcuTaskSelfDestructioTimer1Id);
|
|
|
|
|
gMcuTaskSelfDestructioTimer1Id = -1;
|
2023-10-08 08:10:23 +00:00
|
|
|
}
|
|
|
|
|
if (gMcuTaskSelfDestructioTimer2Id >= 0) {
|
2024-07-31 00:52:45 +00:00
|
|
|
McuBspTimerDelTask(gMcuTaskSelfDestructioTimer2Id);
|
|
|
|
|
gMcuTaskSelfDestructioTimer2Id = -1;
|
2023-10-08 08:10:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-31 00:52:45 +00:00
|
|
|
/* 获取当前自毁的功能定时器状态 */
|
|
|
|
|
int McuTaskSetSelfStructionTimerState(void)
|
|
|
|
|
{
|
|
|
|
|
if (gMcuTaskSelfDestructioTimer1Id < 0 && gMcuTaskSelfDestructioTimer2Id < 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-08 08:10:23 +00:00
|
|
|
/* 关于自毁信号的处理函数 */
|
|
|
|
|
static void McuTaskSelfStructionHandle(void)
|
|
|
|
|
{
|
2024-07-31 00:52:45 +00:00
|
|
|
McuTaskLowPowerUpclk();
|
2023-10-08 08:10:23 +00:00
|
|
|
/* 判断触发中断的引脚是不是被拉起 */
|
|
|
|
|
if (1 == McuSelfDestructionDrvGetSta()) {
|
|
|
|
|
if (gMcuTaskSelfDestructioTimer1Id < 0) {
|
|
|
|
|
gMcuTaskSelfDestructioTimer1Id = McuBspTimerAddTask(&gMcuTaskSelfDestructioTimer1);
|
|
|
|
|
}
|
|
|
|
|
if (gMcuTaskSelfDestructioTimer2Id >= 0) {
|
|
|
|
|
McuBspTimerTaskRefresh(gMcuTaskSelfDestructioTimer2Id);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (gMcuTaskSelfDestructioTimer1Id >= 0) {
|
|
|
|
|
McuBspTimerTaskRefresh(gMcuTaskSelfDestructioTimer1Id);
|
|
|
|
|
}
|
|
|
|
|
if (gMcuTaskSelfDestructioTimer2Id < 0) {
|
|
|
|
|
gMcuTaskSelfDestructioTimer2Id = McuBspTimerAddTask(&gMcuTaskSelfDestructioTimer2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 关于自毁倒计时定时器反馈 */
|
|
|
|
|
static void McuTaskSelfStructionTimer1Handle(void)
|
|
|
|
|
{
|
|
|
|
|
/* 输出自毁信号 */
|
2024-07-31 00:52:45 +00:00
|
|
|
gMcuTaskSelfDestructioTimer1Id = -1;
|
2023-10-08 08:10:23 +00:00
|
|
|
McuSelfDestructionDrvOnOff(1); // 打开自毁信号
|
|
|
|
|
if (gMcuTaskSelfDestructioTimer2Id < 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
McuBspTimerDelTask(gMcuTaskSelfDestructioTimer2Id);
|
|
|
|
|
gMcuTaskSelfDestructioTimer2Id = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 关于关闭自毁倒计时定时器反馈 */
|
|
|
|
|
static void McuTaskSelfStructionTimer2Handle(void)
|
|
|
|
|
{
|
|
|
|
|
/* 删除自毁倒计时定时器 */
|
2024-07-31 00:52:45 +00:00
|
|
|
gMcuTaskSelfDestructioTimer2Id = -1;
|
|
|
|
|
McuSelfDestructionDrvOnOff(0);
|
2023-10-08 08:10:23 +00:00
|
|
|
if (gMcuTaskSelfDestructioTimer1Id < 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
McuBspTimerDelTask(gMcuTaskSelfDestructioTimer1Id);
|
|
|
|
|
gMcuTaskSelfDestructioTimer1Id = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* BME680初始化 */
|
|
|
|
|
static int8_t McuTaskBme680Init(void)
|
|
|
|
|
{
|
|
|
|
|
int8_t rslt;
|
|
|
|
|
struct bme68x_conf conf;
|
|
|
|
|
struct bme68x_heatr_conf heatr_conf;
|
|
|
|
|
McuBspI2cInit(MCU_TASK_BME680_IIC_ID);
|
|
|
|
|
gMcuTaskBme680Dev.amb_temp = 25;
|
|
|
|
|
gMcuTaskBme680Dev.read = McuTaskBme680Read;
|
|
|
|
|
gMcuTaskBme680Dev.write = McuTaskBme680Write;
|
|
|
|
|
gMcuTaskBme680Dev.intf = BME68X_I2C_INTF;
|
|
|
|
|
gMcuTaskBme680Dev.delay_us = McuTaskBme680DelayUs;
|
|
|
|
|
gMcuTaskBme680Dev.intf_ptr = &gMcuTaskBme680DevId;
|
|
|
|
|
rslt = bme68x_init(&gMcuTaskBme680Dev);
|
|
|
|
|
if (rslt == BME68X_OK) {
|
|
|
|
|
/* Set the temperature, pressure and humidity & filter settings */
|
|
|
|
|
conf.filter = BME68X_FILTER_SIZE_3;
|
|
|
|
|
conf.odr = BME68X_ODR_NONE;
|
|
|
|
|
conf.os_hum = BME68X_OS_4X;
|
|
|
|
|
conf.os_pres = BME68X_OS_4X;
|
|
|
|
|
conf.os_temp = BME68X_OS_4X;
|
|
|
|
|
/* Set the remaining gas sensor settings and link the heating profile */
|
|
|
|
|
heatr_conf.enable = BME68X_DISABLE;
|
|
|
|
|
heatr_conf.heatr_dur = 0;
|
|
|
|
|
heatr_conf.heatr_temp = 0;
|
|
|
|
|
rslt = bme68x_set_heatr_conf(BME68X_FORCED_MODE, &heatr_conf, &gMcuTaskBme680Dev);
|
|
|
|
|
if (rslt == BME68X_OK) {
|
|
|
|
|
rslt = bme68x_set_conf(&conf, &gMcuTaskBme680Dev);
|
|
|
|
|
if (rslt == BME68X_OK) {
|
|
|
|
|
return rslt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int8_t McuTaskBme680Measure(void)
|
|
|
|
|
{
|
|
|
|
|
int8_t rslt;
|
|
|
|
|
gNfields = 0;
|
|
|
|
|
/* 只有在FORCED_MODE下才能进行数据采集 */
|
|
|
|
|
rslt = bme68x_set_op_mode(BME68X_FORCED_MODE, &gMcuTaskBme680Dev);
|
|
|
|
|
if (rslt != BME68X_OK) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
rslt = bme68x_get_data(BME68X_FORCED_MODE, &gData, &gNfields, &gMcuTaskBme680Dev);
|
|
|
|
|
if (rslt != BME68X_OK) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
rslt = bme68x_set_op_mode(BME68X_SLEEP_MODE, &gMcuTaskBme680Dev);
|
|
|
|
|
if (rslt != BME68X_OK) {
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static BME68X_INTF_RET_TYPE McuTaskBme680Read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length,
|
|
|
|
|
void *intf_ptr)
|
|
|
|
|
{
|
|
|
|
|
return (BME68X_INTF_RET_TYPE)McuBspI2cRecvData(MCU_TASK_BME680_IIC_TYPE, MCU_TASK_BME680_IIC_ID,
|
|
|
|
|
*(uint8_t *)intf_ptr, reg_addr, I2C_MEMADD_SIZE_8BIT, reg_data, length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static BME68X_INTF_RET_TYPE McuTaskBme680Write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length,
|
|
|
|
|
void *intf_ptr)
|
|
|
|
|
{
|
|
|
|
|
return (BME68X_INTF_RET_TYPE)McuBspI2cSendData(MCU_TASK_BME680_IIC_TYPE, MCU_TASK_BME680_IIC_ID,
|
|
|
|
|
*(uint8_t *)intf_ptr, reg_addr, I2C_MEMADD_SIZE_8BIT, (uint8_t *)reg_data, length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void McuTaskBme680DelayUs(uint32_t period, void *intf_ptr)
|
|
|
|
|
{
|
|
|
|
|
if (intf_ptr != NULL) {
|
|
|
|
|
intf_ptr = NULL;
|
|
|
|
|
}
|
|
|
|
|
uint32_t i = 35; // 35 = 72 / 2 -1;
|
|
|
|
|
while (period) {
|
|
|
|
|
while (i) {
|
|
|
|
|
i--;
|
|
|
|
|
}
|
|
|
|
|
period--;
|
|
|
|
|
i = 35;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************************ADC*******************************/
|
|
|
|
|
static int McuTaskAdcInit(void)
|
|
|
|
|
{
|
|
|
|
|
McuBspGpioInit(MCU_TASK_ADC_ONOFF_GPIO_PORT, MCU_TASK_ADC_ONOFF_GPIO_PIN,
|
|
|
|
|
MCU_TASK_ADC_ONOFF_GPIO_MODE, MCU_TASK_ADC_ONOFF_GPIO_SPEED,
|
|
|
|
|
MCU_TASK_ADC_ONOFF_GPIO_PULL, 0, NULL);
|
|
|
|
|
McuBspAdcInit();
|
|
|
|
|
McuTaskAdcDownPower();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ADC上电 */
|
|
|
|
|
static void McuTaskAdcUpPower(void)
|
|
|
|
|
{
|
|
|
|
|
McuBspGpioSetLevel(MCU_TASK_ADC_ONOFF_GPIO_PORT, MCU_TASK_ADC_ONOFF_GPIO_PIN, MCU_BSP_GPIO_OUT_HIGH);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ADC下电 */
|
|
|
|
|
static void McuTaskAdcDownPower(void)
|
|
|
|
|
{
|
|
|
|
|
McuBspGpioSetLevel(MCU_TASK_ADC_ONOFF_GPIO_PORT, MCU_TASK_ADC_ONOFF_GPIO_PIN, MCU_BSP_GPIO_OUT_LOW);
|
|
|
|
|
}
|