将所有BSP下的文件初始化,放在了user_sys.c中
This commit is contained in:
parent
9a7c78302f
commit
1b2a11301d
|
@ -9,6 +9,7 @@ encoding//bsp/inc/at_device_ml307.h=UTF-8
|
|||
encoding//bsp/inc/bsp_bt.h=UTF-8
|
||||
encoding//bsp/inc/bsp_hr.h=GBK
|
||||
encoding//bsp/inc/bsp_led.h=UTF-8
|
||||
encoding//bsp/inc/bsp_rng.h=GBK
|
||||
encoding//bsp/src/at_device_ml307.c=UTF-8
|
||||
encoding//bsp/src/bsp_bt.c=UTF-8
|
||||
encoding//bsp/src/bsp_button.c=GBK
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* @Author: mbw
|
||||
* @Date: 2024-10-23 17:14:16
|
||||
* @LastEditors: mbw && 1600520629@qq.com
|
||||
* @LastEditTime: 2025-01-04 16:01:41
|
||||
* @LastEditTime: 2025-01-04 17:13:09
|
||||
* @FilePath: \ble_bjq_ch303rct6_ml307\applications\main.c
|
||||
* @Descrt_thread_
|
||||
*
|
||||
|
@ -155,11 +155,54 @@ int main(void)
|
|||
rt_err_t result = RT_EINVAL;
|
||||
rt_uint32_t received_event;
|
||||
|
||||
BSP_ADC_Init();
|
||||
BSP_VIN_Detection_Init();
|
||||
|
||||
if (Get_VIN_VoltageInt1000x() > 10000)
|
||||
{
|
||||
BSP_SYS_Init();
|
||||
rt_kprintf("JT-DT-YD4N02A Software version: %02X\r\n", (uint8_t)Flash_Get_SysCfg(kSwVerId));
|
||||
// 读取历史记录总数
|
||||
Flash_GetTotalRecord(&TotalRecords);
|
||||
g_Calibration_status = Flash_Get_Calibration_State();
|
||||
rt_thread_mdelay(10);
|
||||
if (g_Calibration_status == kSysGasCalibStatus)
|
||||
{
|
||||
SYS_EventInit();
|
||||
work_duration = Flash_Get_WorkDuration();
|
||||
rt_timer_init(&work_cnt_timer,
|
||||
"work_cnt_timer",
|
||||
Work_Cnt_Timer_Callback,
|
||||
RT_NULL,
|
||||
WORK_TIMER_CNT,
|
||||
RT_TIMER_FLAG_PERIODIC);
|
||||
rt_timer_start(&work_cnt_timer);
|
||||
rt_timer_init(&preheat_timer,
|
||||
"preheat_timer",
|
||||
Preheat_Timer_Callback,
|
||||
RT_NULL,
|
||||
TIMEOUT_MS,
|
||||
RT_TIMER_FLAG_SOFT_TIMER | RT_TIMER_FLAG_ONE_SHOT);
|
||||
// 检测上电/掉电复位标志
|
||||
if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) // TODO:这块超级电容会造成掉电重启,并且标志是上电复位,只能通过其超级电容造成复位时事件创建失败进行判断,不治本
|
||||
{
|
||||
Send_Laser_Alarm_Event(kPowerOnEvent);
|
||||
TotalRecords.power_on++;
|
||||
RCC_ClearFlag();
|
||||
}
|
||||
else
|
||||
{
|
||||
Send_Laser_Alarm_Event(kPreheatingEvent); // 这一句的作用是设备不是掉电重启的情况,直接进入预热模式
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_D("欠压复位\r\n");
|
||||
RCC_ClearFlag();
|
||||
NVIC_SystemReset(); // 直接重启系统
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (g_Calibration_status == kNotCalibrated) // 没标定
|
||||
|
@ -201,42 +244,6 @@ int main(void)
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SYS_EventInit();
|
||||
work_duration = Flash_Get_WorkDuration();
|
||||
rt_timer_init(&work_cnt_timer,
|
||||
"work_cnt_timer",
|
||||
Work_Cnt_Timer_Callback,
|
||||
RT_NULL,
|
||||
WORK_TIMER_CNT,
|
||||
RT_TIMER_FLAG_SOFT_TIMER | RT_TIMER_FLAG_PERIODIC);
|
||||
rt_timer_start(&work_cnt_timer);
|
||||
rt_timer_init(&preheat_timer,
|
||||
"preheat_timer",
|
||||
Preheat_Timer_Callback,
|
||||
RT_NULL,
|
||||
TIMEOUT_MS,
|
||||
RT_TIMER_FLAG_SOFT_TIMER | RT_TIMER_FLAG_ONE_SHOT);
|
||||
if (Get_VIN_VoltageInt1000x() > 10000)
|
||||
{
|
||||
// 检测上电/掉电复位标志
|
||||
if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) // TODO:这块超级电容会造成掉电重启,并且标志是上电复位,只能通过其超级电容造成复位时事件创建失败进行判断,不治本
|
||||
{
|
||||
Send_Laser_Alarm_Event(kPowerOnEvent);
|
||||
TotalRecords.power_on++;
|
||||
RCC_ClearFlag();
|
||||
}
|
||||
else
|
||||
{
|
||||
Send_Laser_Alarm_Event(kPreheatingEvent); // 这一句的作用是设备不是掉电重启的情况,直接进入预热模式
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_D("欠压复位\r\n");
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
result = rt_event_recv(&alarm_event,
|
||||
Get_Sys_Event_Flag(kPowerOnEvent) | // 上电
|
||||
|
@ -349,7 +356,6 @@ int main(void)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#if (IOT_MODULE_SWITCH == 1)
|
||||
Ml307_Send_Event(kMl307AlarmEvent);
|
||||
#endif
|
||||
|
@ -486,7 +492,6 @@ int main(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TEST_ENABLE
|
||||
static void SYS_Set_RtcProductTime(int argc, char **argv)
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* @Author: mbw
|
||||
* @Date: 2024-10-10 15:50:39
|
||||
* @LastEditors: mbw && 1600520629@qq.com
|
||||
* @LastEditTime: 2024-11-29 11:27:21
|
||||
* @FilePath: \JT-DT-YD4N02A_RTT_MRS\applications\user_sys.c
|
||||
* @LastEditTime: 2025-01-04 17:16:04
|
||||
* @FilePath: \ble_bjq_ch303rct6_ml307\applications\user_sys.c
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
|
||||
|
@ -13,7 +13,24 @@
|
|||
#include "ctype.h"
|
||||
#include "rtthread.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#include "bsp_adc.h"
|
||||
#include "bsp_beep.h"
|
||||
#include "bsp_bt.h"
|
||||
#include"bsp_button.h"
|
||||
#include "bsp_emv.h"
|
||||
#include "bsp_flash.h"
|
||||
#include "bsp_hr.h"
|
||||
#include "bsp_led.h"
|
||||
#include "bsp_ml307.h"
|
||||
#include "bsp_mq.h"
|
||||
#include "bsp_rtc.h"
|
||||
#include "bsp_vin_detection.h"
|
||||
#include "bsp_wdg.h"
|
||||
#include "bsp_rng.h"
|
||||
|
||||
|
||||
|
||||
|
||||
volatile rt_uint16_t work_duration = 1; // 工作时长
|
||||
volatile rt_uint8_t device_life_check = 0;
|
||||
|
@ -227,3 +244,23 @@ rt_uint8_t XOR_CheckSum(const rt_uint8_t *data, rt_size_t len)
|
|||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
int BSP_SYS_Init(void)
|
||||
{
|
||||
BSP_Flash_Init();
|
||||
BSP_RTC_Init();
|
||||
BSP_Rng_Init();
|
||||
BSP_WDG_Init();
|
||||
BSP_LED_Init();
|
||||
BSP_BEEP_Init();
|
||||
BSP_EMV_Init();
|
||||
BSP_BUTTON_Init();
|
||||
BSP_MQ_Init();
|
||||
BSP_HR_Init();
|
||||
BSP_Bt_Init();
|
||||
ml307_device_class_register();
|
||||
ml307_device_register();
|
||||
BSP_Ml307_Thread_Init();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ int Extract_Value(const char *str, const char *key);
|
|||
int _Self_Check_Mode(void);
|
||||
rt_uint8_t XOR_CheckSum(const rt_uint8_t *data, rt_size_t len);
|
||||
|
||||
|
||||
int BSP_SYS_Init(void);
|
||||
|
||||
|
||||
#endif //!__USER_SYS_H__
|
||||
|
|
|
@ -83,7 +83,7 @@ typedef struct __attribute__((packed))
|
|||
extern ml307_sys_info ml307;
|
||||
extern rt_uint8_t ml307_init_complate_flag;
|
||||
extern struct rt_completion ml307_init_complate;
|
||||
|
||||
int ml307_device_class_register(void);
|
||||
int at_send_data(struct at_device *device, const char *data, rt_size_t size);
|
||||
rt_err_t Ml307_Reset(struct at_device *device);
|
||||
int Time_Calibration(struct at_device *device);
|
||||
|
|
|
@ -71,6 +71,6 @@ extern struct rt_semaphore bt_reg_sem; //注册阀门信号量
|
|||
extern struct rt_semaphore bt_rem_sem; //移除阀门信号量
|
||||
extern struct rt_semaphore bt_rep_sem; //更换阀门信号量
|
||||
|
||||
|
||||
int BSP_Bt_Init(void);
|
||||
int Bt_Valve_Handler(ValveCmdType type, rt_uint8_t id, rt_uint8_t *data);
|
||||
#endif // BSP_BT_H__
|
||||
|
|
|
@ -59,5 +59,6 @@ while (0);
|
|||
|
||||
// extern volatile rt_uint16_t emv_state_flag;
|
||||
// int BSP_Set_Emv_Status(rt_bool_t status);
|
||||
int BSP_EMV_Init(void);
|
||||
|
||||
#endif // !__BSP_EMV__
|
||||
|
|
|
@ -108,4 +108,5 @@ extern agile_led_t *led_y;
|
|||
LED_START(r); \
|
||||
} while (0U)
|
||||
|
||||
int BSP_LED_Init(void);
|
||||
#endif //!__BSP_LED_H__
|
||||
|
|
|
@ -235,3 +235,5 @@ extern rt_uint8_t power_on_send_flag;
|
|||
|
||||
extern rt_sem_t ml307_disconnect_sem;
|
||||
void Ml307_Send_Event(Ml307Event event_type);
|
||||
int ml307_device_register(void);
|
||||
int BSP_Ml307_Thread_Init(void);
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef __BSP_RNG_H__
|
||||
#define __BSP_RNG_H__
|
||||
|
||||
#include "rtthread.h"
|
||||
|
||||
|
||||
|
||||
int BSP_Rng_Init(void);
|
||||
int Get_RandomNumber(void);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1427,7 +1427,7 @@ const struct at_device_ops ml307_device_ops =
|
|||
ml307_control,
|
||||
};
|
||||
|
||||
static int ml307_device_class_register(void)
|
||||
int ml307_device_class_register(void)
|
||||
{
|
||||
struct at_device_class *class = RT_NULL;
|
||||
|
||||
|
@ -1442,7 +1442,7 @@ static int ml307_device_class_register(void)
|
|||
|
||||
return at_device_class_register(class, AT_DEVICE_CLASS_ML307);
|
||||
}
|
||||
INIT_DEVICE_EXPORT(ml307_device_class_register);
|
||||
// INIT_DEVICE_EXPORT(ml307_device_class_register);
|
||||
#endif //! IOT_MODULE_SWITCH
|
||||
|
||||
#endif /* AT_DEVICE_USING_ML307 */
|
||||
|
|
|
@ -146,7 +146,7 @@ int BSP_ADC_Init(void)
|
|||
return 0;
|
||||
}
|
||||
#ifdef RT_USING_COMPONENTS_INIT
|
||||
INIT_DEVICE_EXPORT(BSP_ADC_Init);
|
||||
// INIT_DEVICE_EXPORT(BSP_ADC_Init);
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,7 +29,7 @@ int BSP_BEEP_Init(void)
|
|||
LOG_D("BSP_BEEP_Init");
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_DEVICE_EXPORT(BSP_BEEP_Init);
|
||||
// INIT_DEVICE_EXPORT(BSP_BEEP_Init);
|
||||
|
||||
#ifdef TEST_ENABLE
|
||||
static void TEST_BEEP(int argc, char **argv)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* @Author: mbw
|
||||
* @Date: 2024-12-03 10:31:45
|
||||
* @LastEditors: mbw && 1600520629@qq.com
|
||||
* @LastEditTime: 2025-01-04 15:42:19
|
||||
* @LastEditTime: 2025-01-04 16:49:26
|
||||
* @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\bsp_bt.c
|
||||
* @Description:
|
||||
*
|
||||
|
@ -515,7 +515,7 @@ int BSP_Bt_Init(void)
|
|||
|
||||
return ret;
|
||||
}
|
||||
INIT_COMPONENT_EXPORT(BSP_Bt_Init);
|
||||
// INIT_COMPONENT_EXPORT(BSP_Bt_Init);
|
||||
|
||||
#ifdef TEST_ENABLE
|
||||
static void TEST_BT_Send_Data(int argc, char **argv)
|
||||
|
|
|
@ -187,5 +187,5 @@ int BSP_BUTTON_Init(void)
|
|||
return -RT_ERROR;
|
||||
}
|
||||
#ifdef FINSH_USING_MSH
|
||||
INIT_DEVICE_EXPORT(BSP_BUTTON_Init);
|
||||
// INIT_DEVICE_EXPORT(BSP_BUTTON_Init);
|
||||
#endif
|
||||
|
|
|
@ -147,7 +147,7 @@ int BSP_EMV_Init(void)
|
|||
// rt_timer_start(&emv_timer); // 启动定时器
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_DEVICE_EXPORT(BSP_EMV_Init);
|
||||
// INIT_DEVICE_EXPORT(BSP_EMV_Init);
|
||||
|
||||
static void TEST_Jxs(int argc, char **argv)
|
||||
{
|
||||
|
|
|
@ -930,7 +930,7 @@ int BSP_Flash_Init(void)
|
|||
return 0;
|
||||
}
|
||||
#ifdef RT_USING_COMPONENTS_INIT
|
||||
INIT_PREV_EXPORT(BSP_Flash_Init);
|
||||
// INIT_PREV_EXPORT(BSP_Flash_Init);
|
||||
#endif
|
||||
|
||||
#ifdef TEST_ENABLE
|
||||
|
|
|
@ -636,7 +636,7 @@ int BSP_HR_Init(void)
|
|||
|
||||
return ret;
|
||||
}
|
||||
INIT_PREV_EXPORT(BSP_HR_Init);
|
||||
// INIT_PREV_EXPORT(BSP_HR_Init);
|
||||
|
||||
void USART2_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void USART2_IRQHandler(void)
|
||||
|
|
|
@ -90,7 +90,7 @@ int BSP_LED_Init(void)
|
|||
LOG_D("BSP_LED_Init");
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_DEVICE_EXPORT(BSP_LED_Init);
|
||||
// INIT_DEVICE_EXPORT(BSP_LED_Init);
|
||||
|
||||
#ifdef TEST_ENABLE
|
||||
static void TEST_LED(int argc, char **argv)
|
||||
|
|
|
@ -1779,9 +1779,9 @@ int BSP_Ml307_Thread_Init(void)
|
|||
|
||||
return ret;
|
||||
}
|
||||
INIT_APP_EXPORT(BSP_Ml307_Thread_Init);
|
||||
// INIT_APP_EXPORT(BSP_Ml307_Thread_Init);
|
||||
|
||||
static int ml307_device_register(void)
|
||||
int ml307_device_register(void)
|
||||
{
|
||||
struct at_device_ml307 *ml307 = &_dev;
|
||||
|
||||
|
@ -1791,6 +1791,6 @@ static int ml307_device_register(void)
|
|||
AT_DEVICE_CLASS_ML307,
|
||||
(void *)ml307);
|
||||
}
|
||||
INIT_DEVICE_EXPORT(ml307_device_register);
|
||||
// INIT_DEVICE_EXPORT(ml307_device_register);
|
||||
|
||||
#endif // IOT_MODULE_SWITCH
|
||||
|
|
|
@ -193,7 +193,7 @@ int BSP_MQ_Init(void)
|
|||
return 0;
|
||||
}
|
||||
#ifdef RT_USING_COMPONENTS_INIT
|
||||
INIT_DEVICE_EXPORT(BSP_MQ_Init);
|
||||
// INIT_DEVICE_EXPORT(BSP_MQ_Init);
|
||||
#endif
|
||||
|
||||
#ifdef TEST_ENABLE
|
||||
|
@ -201,5 +201,5 @@ static void TEST_MQ_EndOfLife(void)
|
|||
{
|
||||
Sensor_device.end_of_life = 1;
|
||||
}
|
||||
MSH_CMD_EXPORT(TEST_MQ_EndOfLife, TEST_MQ_EndOfLife);
|
||||
// MSH_CMD_EXPORT(TEST_MQ_EndOfLife, TEST_MQ_EndOfLife);
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#include "bsp_rng.h"
|
||||
#include "ch32v30x_rng.h"
|
||||
#include "rtdef.h"
|
||||
|
||||
#define LOG_LVL LOG_LVL_DBG
|
||||
#include <ulog.h>
|
||||
|
||||
int BSP_Rng_Init(void)
|
||||
{
|
||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_RNG, ENABLE);
|
||||
RNG_Cmd(ENABLE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
// INIT_PREV_EXPORT(BSP_Rng_Init);
|
||||
|
||||
int Get_RandomNumber(void)
|
||||
{
|
||||
u32 random = 0;
|
||||
while(RNG_GetFlagStatus(RNG_FLAG_DRDY) == RESET);
|
||||
random = RNG_GetRandomNumber();
|
||||
|
||||
LOG_D("random = %d\r\n", random % 31);
|
||||
|
||||
// 生成0到1000之间的随机数
|
||||
return random % 1000;
|
||||
}
|
|
@ -378,7 +378,7 @@ int BSP_RTC_Init(void)
|
|||
|
||||
return 0;
|
||||
}
|
||||
INIT_PREV_EXPORT(BSP_RTC_Init);
|
||||
// INIT_PREV_EXPORT(BSP_RTC_Init);
|
||||
|
||||
#if 1
|
||||
void RTC_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
|
|
|
@ -122,7 +122,7 @@ int BSP_VIN_Detection_Init(void)
|
|||
return RT_EOK;
|
||||
}
|
||||
#ifdef RT_USING_COMPONENTS_INIT
|
||||
INIT_APP_EXPORT(BSP_VIN_Detection_Init);
|
||||
// INIT_APP_EXPORT(BSP_VIN_Detection_Init);
|
||||
#endif
|
||||
|
||||
void ADC1_2_IRQHandler(void) __attribute__((interrupt()));
|
||||
|
|
|
@ -165,7 +165,7 @@ int BSP_WDG_Init(void)
|
|||
return 0;
|
||||
}
|
||||
#ifdef RT_USING_COMPONENTS_INIT
|
||||
INIT_APP_EXPORT(BSP_WDG_Init);
|
||||
// INIT_APP_EXPORT(BSP_WDG_Init);
|
||||
#endif
|
||||
|
||||
#if USED_WWDG
|
||||
|
|
Loading…
Reference in New Issue