diff --git a/.cproject b/.cproject index 9da49e2..c253b18 100644 --- a/.cproject +++ b/.cproject @@ -648,4 +648,4 @@ - + \ No newline at end of file diff --git a/.mrs/launch.json b/.mrs/launch.json index be75f06..1d041f2 100644 --- a/.mrs/launch.json +++ b/.mrs/launch.json @@ -5,7 +5,7 @@ "type": "mrs-debugger", "request": "launch", "name": "JT-DT-YD4N02A_RTT_MRS-4G", - "cwd": "d:\\SXDT\\Project\\CH32\\JT-DT-YD4N02A_RTT_MRS-NT26K", + "cwd": "c:\\Users\\16586\\Desktop\\JT-DT-YD4N02A_4G_RTT_MRS", "openOCDCfg": { "useLocalOpenOCD": true, "executable": "c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/openocd.exe", @@ -39,8 +39,8 @@ "additionalCommands": [] }, "loadedFiles": { - "executableFile": "d:\\SXDT\\Project\\CH32\\JT-DT-YD4N02A_RTT_MRS-NT26K\\obj\\JT-DT-YD4N02A_RTT_MRS-4G.elf", - "symbolFile": "d:\\SXDT\\Project\\CH32\\JT-DT-YD4N02A_RTT_MRS-NT26K\\obj\\JT-DT-YD4N02A_RTT_MRS-4G.elf", + "executableFile": "c:\\Users\\16586\\Desktop\\JT-DT-YD4N02A_4G_RTT_MRS\\obj\\JT-DT-YD4N02A_RTT_MRS-4G.elf", + "symbolFile": "c:\\Users\\16586\\Desktop\\JT-DT-YD4N02A_4G_RTT_MRS\\obj\\JT-DT-YD4N02A_RTT_MRS-4G.elf", "executableFileOffset": 0, "symbolFileOffset": 0 }, diff --git a/.project b/.project index e9a17f9..76bc70e 100644 --- a/.project +++ b/.project @@ -31,4 +31,4 @@ - + \ No newline at end of file diff --git a/.template b/.template index 12d75d1..7a75afa 100644 --- a/.template +++ b/.template @@ -9,10 +9,15 @@ Description=============ROM(byte): 256K, SRAM(byte): 64K, CHIP PINS: 64, GPIO PO Mcu Type=CH32V30x Address=0x08000000 Target Path=obj\JT-DT-YD4N02A_RTT_MRS-4G.hex +Exe Path= +Exe Arguments= CLKSpeed=1 -DebugInterfaceMode=-1 +DebugInterfaceMode=0 Erase All=true Program=true Verify=true Reset=true SDIPrintf=false +Disable Power Output=false +Clear CodeFlash=false +Disable Code-Protect=false \ No newline at end of file diff --git a/JT-DT-YD4N02A_RTT_MRS-4G.launch b/JT-DT-YD4N02A_RTT_MRS-4G.launch index a885e48..aa24d59 100644 --- a/JT-DT-YD4N02A_RTT_MRS-4G.launch +++ b/JT-DT-YD4N02A_RTT_MRS-4G.launch @@ -1,62 +1,62 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + \ No newline at end of file diff --git a/JT-DT-YD4N02A_RTT_MRS-4G.wvproj b/JT-DT-YD4N02A_RTT_MRS-4G.wvproj index 9bb8a45..2166da0 100644 --- a/JT-DT-YD4N02A_RTT_MRS-4G.wvproj +++ b/JT-DT-YD4N02A_RTT_MRS-4G.wvproj @@ -8,9 +8,9 @@ "series": "CH32V307", "rtos": "NoneOS", "mcu": "CH32V307RVT6", - "description": "===========ROM(byte): 256K, SRAM(byte): 64K, CHIP PINS: 64, GPIO PORTS: 51.\\nWCH CH32V3 series of mainstream MCUs covers the needs of a large variety of applications in the industrial,medical and consumer markets. High performance with first-class peripherals and low-power,low-voltage operation is paired with a high level of integration at accessible prices with a simple architecture and easy-to-use tools.", + "description": "============ROM(byte): 256K, SRAM(byte): 64K, CHIP PINS: 64, GPIO PORTS: 51.\\nWCH CH32V3 series of mainstream MCUs covers the needs of a large variety of applications in the industrial,medical and consumer markets. High performance with first-class peripherals and low-power,low-voltage operation is paired with a high level of integration at accessible prices with a simple architecture and easy-to-use tools.", "link": "WCH-Link", - "peripheral_version": "===========1.4" + "peripheral_version": "============1.4" }, "linkedFolders": [], "removedResources": [ diff --git a/applications/main.c b/applications/main.c index 57732a1..94ea7bc 100644 --- a/applications/main.c +++ b/applications/main.c @@ -192,7 +192,6 @@ int main(void) rt_uint32_t received_event; BSP_ADC_Init(); - BSP_VIN_Detection_Init(); if (Get_VIN_VoltageInt1000x() > 10000) { @@ -243,6 +242,9 @@ int main(void) RCC_ClearFlag(); NVIC_SystemReset(); // 直接重启系统 } + BSP_VIN_Detection_Init(); + // IWDG_Feed(); + while (1) { if (is_event_initialized) @@ -412,7 +414,9 @@ int main(void) { LOG_D("掉电模式"); - ADC_ITConfig(USED_ADC, ADC_IT_AWD, DISABLE); + is_event_initialized = RT_FALSE; + + // ADC_ITConfig(USED_ADC, ADC_IT_AWD, DISABLE); H308_PWR_OFF; SysControl.last_status = SysControl.status; @@ -439,6 +443,7 @@ int main(void) LOG_D("cnt2 = %d", cnt); cnt++; } + __disable_irq(); // 关闭中断 NVIC_SystemReset(); // 直接重启系统 @@ -478,6 +483,7 @@ int main(void) else { rt_thread_mdelay(1000); + // IWDG_Feed(); } } } diff --git a/applications/user_sys.c b/applications/user_sys.c index f133a1d..493b697 100644 --- a/applications/user_sys.c +++ b/applications/user_sys.c @@ -253,9 +253,9 @@ rt_uint32_t IMEI_Delay(void) int BSP_SYS_Init(void) { - + BSP_WDG_Init(); - + BSP_RTC_Init(); BSP_Rng_Init(); BSP_LED_Init(); @@ -265,6 +265,7 @@ int BSP_SYS_Init(void) BSP_BUTTON_Init(); BSP_HR_Init(); BSP_Nt26k_Thread_Init(); + return 0; } // INIT_ENV_EXPORT(BSP_SYS_Init); diff --git a/applications/user_sys.h b/applications/user_sys.h index 09f67ac..d45319b 100644 --- a/applications/user_sys.h +++ b/applications/user_sys.h @@ -14,6 +14,8 @@ #include "rtdef.h" #include "bsp_flash.h" + + #define MAX_EXPIRATION_YEARS (10U) #define MAX_EXPIRATION_DAYS (365 * MAX_EXPIRATION_YEARS + 30 * 3U) @@ -35,7 +37,7 @@ do { \ rt_kprintf("Compiled on: %s at %s\n", __DATE__, __TIME__); \ } while (0) - + typedef enum { kPowerOnEvent, diff --git a/bsp/inc/bsp_h308.h b/bsp/inc/bsp_h308.h index e0d266d..f1d770c 100644 --- a/bsp/inc/bsp_h308.h +++ b/bsp/inc/bsp_h308.h @@ -30,7 +30,7 @@ #define H308_RST_OFF rt_pin_write(H308_RST_PIN, PIN_HIGH) #define H308_THREAD_STACK_SIZE (2048) -#define H308_THREAD_PRIORITY (8) +#define H308_THREAD_PRIORITY (7) #define H308_THREAD_TIMESLICE (5) typedef enum diff --git a/bsp/inc/bsp_vin_detection.h b/bsp/inc/bsp_vin_detection.h index d7daf9e..1c7d54c 100644 --- a/bsp/inc/bsp_vin_detection.h +++ b/bsp/inc/bsp_vin_detection.h @@ -2,8 +2,8 @@ * @Author : stark1898y 1658608470@qq.com * @Date : 2024-09-13 13:11:09 * @LastEditors : stark1898y 1658608470@qq.com - * @LastEditTime : 2024-09-24 11:21:59 - * @FilePath : \JT-DT-YD4N02A_RTT_MRS-4G\bsp\inc\bsp_vin_detection.h + * @LastEditTime : 2025-01-23 16:17:44 + * @FilePath : \JT-DT-YD4N02A_4G_RTT_MRS\bsp\inc\bsp_vin_detection.h * @Description : * * Copyright (c) 2024 by yzy, All Rights Reserved. @@ -13,9 +13,9 @@ #include "board.h" -#if 0 +#if 1 #define VIN_THREAD_STACK_SIZE (1024) -#define VIN_THREAD_PRIORITY (1) +#define VIN_THREAD_PRIORITY (5) #define VIN_THREAD_TIMESLICE (5) #endif diff --git a/bsp/inc/bsp_wdg.h b/bsp/inc/bsp_wdg.h index 8aa5afd..5ea6b6f 100644 --- a/bsp/inc/bsp_wdg.h +++ b/bsp/inc/bsp_wdg.h @@ -14,7 +14,7 @@ #include "board.h" #define WDG_THREAD_STACK_SIZE (1024U) -#define WDG_THREAD_PRIORITY 30 +#define WDG_THREAD_PRIORITY 29 #define WDG_THREAD_TIMESLICE 5 // 暂时只写了IWDG的 diff --git a/bsp/src/bsp_h308.c b/bsp/src/bsp_h308.c index ef8d340..bf9f6f2 100644 --- a/bsp/src/bsp_h308.c +++ b/bsp/src/bsp_h308.c @@ -37,7 +37,7 @@ static rt_sem_t uart4_rx_ok_sem; static struct rt_timer uart4_rx_timer; uint8_t sensor_rx_flag = 0; // 接收缓冲区中,已经收到的数据包数量static rt_uint8_t alarm_flag = 0, fault_flag = 0; -static rt_uint8_t alarm_flag = 0, fault_flag = 0; +static rt_uint8_t alarm_flag = 0, fault_flag = 0; TsH308 H308 = {0}; void _UART4_RxTimeout(void *parameter) @@ -346,7 +346,7 @@ static void h308_thread_entry(void *param) else if (ret == -RT_ETIMEOUT) // 这个主要是考虑传感器未焊接好,或者脱落的情况,国标要求30s内反应 3*5 = 15s,符合国标 { h308_rx_timout_cnt++; - if (h308_rx_timout_cnt >= 5) + if (h308_rx_timout_cnt >= 6) { H308_RST_ON; rt_thread_mdelay(100); @@ -415,7 +415,7 @@ void UART4_IRQHandler(void) { sensor_rx_flag = 1; rt_timer_start(&uart4_rx_timer); - } + } } rt_interrupt_leave(); diff --git a/bsp/src/bsp_led.c b/bsp/src/bsp_led.c index 20c1bd4..e76dd06 100644 --- a/bsp/src/bsp_led.c +++ b/bsp/src/bsp_led.c @@ -37,6 +37,7 @@ static void BSP_Led_thread_entry(void *param) rt_thread_mdelay(1000); } } + int BSP_LED_Init(void) { led_r = agile_led_create(LED_R_PIN, PIN_HIGH, "100,0", 0); diff --git a/bsp/src/bsp_nt26k.c b/bsp/src/bsp_nt26k.c index 517aef9..0c3aaa8 100644 --- a/bsp/src/bsp_nt26k.c +++ b/bsp/src/bsp_nt26k.c @@ -817,12 +817,12 @@ int Nt26k_Process_Events(Nt26kEvent nt26k_recv_event, struct at_device *device, return RT_EOK; } } - if (rt_strcmp(event->event_name, "掉电事件") == RT_EOK) + if (rt_strcmp(event->event_name, "掉电事件") == RT_EOK) { rt_uint8_t cnt = 0; while ((device_power_down_flag == 0)&&(cnt < 10)) { - rt_thread_mdelay(500); + rt_thread_mdelay(500); } if (device->class->device_ops->control(device, AT_DEVICE_CTRL_POWER_OFF, RT_NULL) == RT_EOK) { @@ -830,7 +830,7 @@ int Nt26k_Process_Events(Nt26kEvent nt26k_recv_event, struct at_device *device, nt26k_power_down_flag = 1; return RT_EOK; } - } + } } } else @@ -1504,7 +1504,7 @@ static void Nt26k_Life_Thread_Entry(void *parameter) { device->class->device_ops->control(device, AT_DEVICE_RF_CLOSE, RT_NULL); result = -RT_ETIMEOUT; - + goto __exit; } at_delete_resp(resp); @@ -1521,7 +1521,7 @@ static void Nt26k_Life_Thread_Entry(void *parameter) { nt26k_disconnect_retry_flag = 1; LOG_D("重连网络失败,等待%d s后重连\n",delay_n * 5); - + rt_thread_mdelay(delay_n * 5000); delay_n++; if (delay_n >= 66)//大于3小时的重连都不行,则重启设备 @@ -1531,7 +1531,7 @@ static void Nt26k_Life_Thread_Entry(void *parameter) reboot(); } rt_sem_release(nt26k_disconnect_sem); - + } } } @@ -1549,7 +1549,7 @@ int BSP_Nt26k_Thread_Init(void) Nt26k_Event_Init(); rt_uint32_t iot_upload_time = (uint16_t)Flash_Get_SysCfg(kIotUploadCycleId); rt_uint32_t timeout = 0; - + if (iot_upload_time > 24 * 60 * 60 * RT_TICK_PER_SECOND) { timeout = 24 * 60 * 60 * RT_TICK_PER_SECOND; @@ -1559,7 +1559,7 @@ int BSP_Nt26k_Thread_Init(void) { timeout = iot_upload_time * 60 * RT_TICK_PER_SECOND; } - + LOG_I("上报服务器周期:%d分钟", iot_upload_time); nt26k_mutex = rt_mutex_create("nt26k_mutex", RT_IPC_FLAG_PRIO); if (nt26k_mutex == RT_NULL) diff --git a/bsp/src/bsp_vin_detection.c b/bsp/src/bsp_vin_detection.c index 9e97843..b3902b2 100644 --- a/bsp/src/bsp_vin_detection.c +++ b/bsp/src/bsp_vin_detection.c @@ -17,27 +17,26 @@ #include "user_sys.h" -#define LOG_TAG "bsp_vin_detection" // 该模块对应的标签。不定义时,默认:NO_TAG -#define LOG_LVL LOG_LVL_DBG // 该模块对应的日志输出级别。不定义时,默认:调试级别 +#define LOG_TAG "bsp_vin_detection" // 该模块对应的标签。不定义时,默认:NO_TAG +#define LOG_LVL LOG_LVL_DBG // 该模块对应的日志输出级别。不定义时,默认:调试级别 #include // 必须在 LOG_TAG 与 LOG_LVL 下面 -#if 0 -static rt_sem_t sem_vin; +#if 1 +// static rt_sem_t sem_vin; ALIGN(RT_ALIGN_SIZE) static char vin_thread_stack[VIN_THREAD_STACK_SIZE]; static struct rt_thread vin_thread; #endif - float Get_VIN_Voltage(void) { float vin_voltage = Get_ADC_Voltage(kVinAdc) * VIN_VOLTAGE_RATIO; -// int16_t voltage = vin_voltage * 1000; + // int16_t voltage = vin_voltage * 1000; -// LOG_D("Get_VIN_Voltage(V): %d.%d%d%d\r\n", (voltage / 1000), ((voltage % 1000) / 100), -// ((voltage % 100) / 10), (voltage % 10)); + // LOG_D("Get_VIN_Voltage(V): %d.%d%d%d\r\n", (voltage / 1000), ((voltage % 1000) / 100), + // ((voltage % 100) / 10), (voltage % 10)); return vin_voltage; } @@ -49,20 +48,31 @@ uint16_t Get_VIN_VoltageInt1000x(void) { uint16_t voltage = (Get_ADC_Average(kVinAdc) * 3.3 / 4096) * VIN_VOLTAGE_RATIO * 1000; - LOG_D("Get_VIN_VoltageInt1000x = %04d", voltage); + // LOG_D("Get_VIN_VoltageInt1000x = %04d", voltage); return voltage; } #ifdef FINSH_USING_MSH // MSH_CMD_EXPORT(Get_VIN_VoltageInt1000x, "Get_VIN_VoltageInt1000x"); #endif // !FINSH_USING_MSH -#if 0 +#if 1 static void vin_thread_entry(void *param) { while (1) { - rt_sem_take(sem_vin, RT_WAITING_FOREVER); + // rt_sem_take(sem_vin, RT_WAITING_FOREVER); // 写入掉电记录 + if (Get_VIN_VoltageInt1000x() <= 10000) + { + if (SysControl.status != kPowerDownEvent) + { + LOG_D("电压低于10V"); + Send_Laser_Alarm_Event(kPowerDownEvent); + } + } + rt_thread_mdelay(50); + + #if 0 Flash_Write_Record(kRecordPowerDown); LOG_D("Enter AnalogWatchdog Interrupt"); @@ -78,35 +88,38 @@ static void vin_thread_entry(void *param) } // 还是没断电的话就重启 NVIC_SystemReset(); + #endif } } #endif int BSP_VIN_Detection_Init(void) { - NVIC_InitTypeDef NVIC_InitStructure = {0}; + // NVIC_InitTypeDef NVIC_InitStructure = {0}; - /* Higher Threshold: 14V, Lower Threshold: 10V */ - ADC_AnalogWatchdogThresholdsConfig(USED_ADC, VIN_ADC_HIGH_THRESHOLD, VIN_ADC_LOW_THRESHOLD); - ADC_AnalogWatchdogSingleChannelConfig(USED_ADC, VIN_ADC_CHANNEL); - ADC_AnalogWatchdogCmd(USED_ADC, ADC_AnalogWatchdog_SingleRegEnable); + // rt_thread_mdelay(100); - NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); + // /* Higher Threshold: 14V, Lower Threshold: 10V */ + // ADC_AnalogWatchdogThresholdsConfig(USED_ADC, VIN_ADC_HIGH_THRESHOLD, VIN_ADC_LOW_THRESHOLD); + // ADC_AnalogWatchdogSingleChannelConfig(USED_ADC, VIN_ADC_CHANNEL); + // ADC_AnalogWatchdogCmd(USED_ADC, ADC_AnalogWatchdog_SingleRegEnable); - rt_thread_mdelay(50); + // NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn; + // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; + // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; + // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + // NVIC_Init(&NVIC_InitStructure); - ADC_ITConfig(USED_ADC, ADC_IT_AWD, ENABLE); + // rt_thread_mdelay(50); -#if 0 - sem_vin = rt_sem_create("sem_vin", 0, RT_IPC_FLAG_PRIO); - if (sem_vin == RT_NULL) - { - LOG_E("create sem_vin fail"); - } + // ADC_ITConfig(USED_ADC, ADC_IT_AWD, ENABLE); + +#if 1 + // sem_vin = rt_sem_create("sem_vin", 0, RT_IPC_FLAG_PRIO); + // if (sem_vin == RT_NULL) + // { + // LOG_E("create sem_vin fail"); + // } rt_thread_init(&vin_thread, "vin_thread", @@ -121,10 +134,11 @@ int BSP_VIN_Detection_Init(void) return RT_EOK; } -#ifdef RT_USING_COMPONENTS_INIT +// #ifdef RT_USING_COMPONENTS_INIT // INIT_APP_EXPORT(BSP_VIN_Detection_Init); -#endif +// #endif +#if 0 void ADC1_2_IRQHandler(void) __attribute__((interrupt())); void ADC1_2_IRQHandler(void) { @@ -132,19 +146,18 @@ void ADC1_2_IRQHandler(void) /* enter interrupt */ rt_interrupt_enter(); - if(ADC_GetITStatus(ADC1, ADC_IT_AWD)) - { + if (ADC_GetITStatus(ADC1, ADC_IT_AWD)) + { ADC_ClearITPendingBit(ADC1, ADC_IT_AWD); - // ADC_ITConfig(USED_ADC, ADC_IT_AWD, DISABLE); LOG_D("Enter AnalogWatchdog Interrupt"); Send_Laser_Alarm_Event(kPowerDownEvent); + + ADC_ITConfig(USED_ADC, ADC_IT_AWD, DISABLE); } /* leave interrupt */ rt_interrupt_leave(); FREE_INT_SP(); } - - - +#endif diff --git a/libraries/hal_drivers/drv_usart.c b/libraries/hal_drivers/drv_usart.c index 6498f22..d2dbe57 100644 --- a/libraries/hal_drivers/drv_usart.c +++ b/libraries/hal_drivers/drv_usart.c @@ -532,7 +532,6 @@ int rt_hw_usart_init(void) continue; } - /* register UART device */ result = rt_hw_serial_register(&uart_obj[i].serial, uart_obj[i].config->name, RT_DEVICE_FLAG_RDWR diff --git a/rt-thread/rtconfig.h b/rt-thread/rtconfig.h index 1100317..9f07380 100644 --- a/rt-thread/rtconfig.h +++ b/rt-thread/rtconfig.h @@ -1,9 +1,9 @@ /* * @Author : stark1898y 1658608470@qq.com * @Date : 2024-07-19 13:49:43 - * @LastEditors : stark1898y 1658608470@qq.com - * @LastEditTime : 2024-09-19 14:25:52 - * @FilePath : \JT-DT-YD4N02A_RTT_MRS-4G\rt-thread\rtconfig.h + * @LastEditors : stark1898y 1658608470@qq.com + * @LastEditTime : 2025-01-23 16:25:55 + * @FilePath : \JT-DT-YD4N02A_4G_RTT_MRS\rt-thread\rtconfig.h * @Description : * * Copyright (c) 2024 by yzy, All Rights Reserved. @@ -15,7 +15,7 @@ /*使用动态日志及密码功能时,需开启宏 FINSH_USING_AUTH ULOG_USING_FILTER ENABLE_LOG_ALL ULOG_OUTPUT_LVL = 7 以及设置ulog.c 1522行 输出等级为0*/ /**/ -// #define FINSH_USING_AUTH //开启终端密码登录功能 +#define FINSH_USING_AUTH //开启终端密码登录功能 // #define ULOG_USING_FILTER //开启动态修改日志等级 默认修改在ulog.c 1522行 #define ENABLE_LOG_ALL @@ -23,11 +23,16 @@ #define ULOG_OUTPUT_LVL 7 // 生产时将其设为0 #define IOT_MODULE_SWITCH 1 //开启物联网功能 +// #ifdef FINSH_USING_AUTH + // #define AT_USING_CLI + // #define AT_PRINT_RAW_CMD +// #endif + /* RT-Thread Kernel */ #define RT_NAME_MAX 16 #define RT_ALIGN_SIZE 4 - #define RT_THREAD_PRIORITY_32 + #define RT_THREAD_PRIORITY_32 #define RT_THREAD_PRIORITY_MAX 32 #define RT_TICK_PER_SECOND 1000 @@ -37,8 +42,6 @@ #define RT_USING_IDLE_HOOK - - #define RT_IDLE_HOOK_LIST_SIZE 4 #define IDLE_THREAD_STACK_SIZE 512 @@ -155,11 +158,8 @@ #define AT_USING_CLIENT #define AT_CLIENT_NUM_MAX 1 - -// #ifdef FINSH_USING_AUTH - #define AT_USING_CLI - #define AT_PRINT_RAW_CMD -// #endif + + #define AT_CMD_MAX_LEN 256 #define AT_SW_VERSION_NUM 0x10301