#include "led.h" #include "app.h" #include "lora.h" #include "gw_ctrl.h" #include "encoder.h" /* ********************************************************************************************************* * LOCAL VARIABLES ********************************************************************************************************* */ extern volatile uint32_t TickCounter; OS_TCB LED_TASK_HandleTCB; CPU_STK LED_TASK_HandleStk[APP_TASK_START_STK_SIZE]; void LED_TASK_Handle(void * p_arg); OS_TCB UART_TASK_HandleTCB; CPU_STK UART_TASK_HandleStk[UART_TASK_START_STK_SIZE]; void UART_TASK_Handle(void * p_arg); OS_TCB PROG_TASK_HandleTCB; CPU_STK PROG_TASK_HandleStk[PROG_TASK_START_STK_SIZE]; void PROG_TASK_Handle(void * p_arg); OS_TCB OTA_TASK_HandleTCB; CPU_STK OTA_TASK_HandleStk[OTA_TASK_START_STK_SIZE]; void OTA_TASK_Handle(void * p_arg); OS_TCB LORA_TASK_HandleTCB; CPU_STK LORA_TASK_HandleStk[LORA_TASK_START_STK_SIZE]; void LORA_TASK_Handle(void * p_arg); ////OS_TCB INFO_TASK_HandleTCB; ////CPU_STK INFO_TASK_HandleStk[INFO_TASK_START_STK_SIZE]; ////void INFO_TASK_Handle(void * p_arg); OS_TCB ENCODER_TASK_HandleTCB; CPU_STK ENCODER_TASK_HandleStk[ENCODER_TASK_START_STK_SIZE]; void ENCODER_TASK_Handle(void * p_arg); /* ********************************************************************************************************* * STARTUP TASK * * Description : This is an example of a startup task. As mentioned in the book's text, you MUST * initialize the ticker only once multitasking has started. * * Arguments : p_arg is the argument passed to 'AppTaskStart()' by 'OSTaskCreate()'. * * Returns : none * * Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not * used. The compiler should not generate any code for this statement. ********************************************************************************************************* */ // void AppTaskStart (void *p_arg) { uint8_t i; OS_ERR err; CPU_Init(); // Initialize the uC/CPU services BSP_Init(); // Initialize BSP functions printf("APP begin\n"); tim4_init(); port_init(PORT_LED_ON);//判断是否加密 printf_debug(INIT_DEBUG, "\n复位信息:\n"); printf_debug(INIT_DEBUG, " reset_type = 0x%02x\n",last_reset_flag); printf_debug(INIT_DEBUG, " reset_times = %u\n",eeprom_first_info.reset_total_num); printf_debug(INIT_DEBUG, "\n软件版本:\n"); printf_debug(INIT_DEBUG, " boot_ver = 0x%08x\n",device_version_info.boot_ver); printf_debug(INIT_DEBUG, " pt_ver = 0x%08x\n",device_version_info.PT_ver); printf_debug(INIT_DEBUG, " app1_ver = 0x%08x\n",device_version_info.APP1_ver); printf_debug(INIT_DEBUG, " app2_ver = 0x%08x\n",device_version_info.APP2_ver); printf_debug(INIT_DEBUG, " app3_ver = 0x%08x\n",device_version_info.APP3_ver); printf_debug(INIT_DEBUG, "\n设备出厂信息:\n"); printf_debug(INIT_DEBUG, " PT_init = 0x%02x\n",device_info.alrd); printf_debug(INIT_DEBUG, " device_type = 0x%04x\n",device_info.device_type); printf_debug(INIT_DEBUG, " device_sn = %010u, 0x%08x\n",device_info.device_sn,device_info.device_sn); printf_debug(INIT_DEBUG, " uuid = "); for(i = 0; i < 12; i++) { printf_debug(INIT_DEBUG, "%02x ", device_fixed_info.MCU_UUID[i]); } printf_debug(INIT_DEBUG, "\r\n"); printf_debug(INIT_DEBUG, " pcb_ver = 0x%02x\n",device_info.pcb_ver); printf_debug(INIT_DEBUG, " device_pd = 0x%08x\n",device_info.production_data); printf_debug(INIT_DEBUG, " device_bn = 0x%04x\n",device_info.batch_number); printf_debug(INIT_DEBUG, " device_mfrs = 0x%04x\n",device_info.manufactures); if((device_fixed_info.Encrypt&0x80) == 0x80) printf("支持解码\n"); else printf("不支持解码\n"); if((device_fixed_info.Encrypt>>4)&0x01) printf("插入加密模块\n"); else printf("未插入加密模块\n"); /* if(device_fixed_info.Encrypt == CIPHERTEXT)//密文 { printf_debug(INIT_DEBUG, " is miwen = 1\n"); } else//明文 { printf_debug(INIT_DEBUG, " is miwen = 0\n"); } */ printf_debug(INIT_DEBUG, "\nLora参数信息:\n"); printf_debug(INIT_DEBUG, " lora_index = %d\n",lora_para_choice); APP_edittion_led_run();//APP版本指示灯运行 #if OS_CFG_STAT_TASK_EN > 0u //如果使能(默认使能)了统计任务 OSStatTaskCPUUsageInit(&err); //计算没有应用任务(只有空闲任务)运行时 CPU 的(最大) #endif //容量(决定 OS_Stat_IdleCtrMax 的值,为后面计算 CPU //使用率使用)。 OSTaskCreate((OS_TCB *)&LED_TASK_HandleTCB, (CPU_CHAR *)"LED TASK Handle", (OS_TASK_PTR )LED_TASK_Handle, (void *)0, (OS_PRIO )LED_TASK_PRIO, (CPU_STK *)&LED_TASK_HandleStk[0], (CPU_STK_SIZE)APP_TASK_START_STK_SIZE / 10, (CPU_STK_SIZE)APP_TASK_START_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSTaskCreate((OS_TCB *)&UART_TASK_HandleTCB, (CPU_CHAR *)"UART TASK Handle", (OS_TASK_PTR )UART_TASK_Handle, (void *)0, (OS_PRIO )UART_TASK_PRIO, (CPU_STK *)&UART_TASK_HandleStk[0], (CPU_STK_SIZE)UART_TASK_START_STK_SIZE / 10, (CPU_STK_SIZE)UART_TASK_START_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSTaskCreate((OS_TCB *)&LORA_TASK_HandleTCB, (CPU_CHAR *)"LORA TASK Handle", (OS_TASK_PTR )LORA_TASK_Handle, (void *)0, (OS_PRIO )LORA_TASK_PRIO, (CPU_STK *)&LORA_TASK_HandleStk[0], (CPU_STK_SIZE)LORA_TASK_START_STK_SIZE / 10, (CPU_STK_SIZE)LORA_TASK_START_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSTaskCreate((OS_TCB *)&PROG_TASK_HandleTCB, (CPU_CHAR *)"PROG TASK Handle", (OS_TASK_PTR )PROG_TASK_Handle, (void *)0, (OS_PRIO )PROG_TASK_PRIO, (CPU_STK *)&PROG_TASK_HandleStk[0], (CPU_STK_SIZE)PROG_TASK_START_STK_SIZE / 10, (CPU_STK_SIZE)PROG_TASK_START_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSTaskCreate((OS_TCB *)&OTA_TASK_HandleTCB, (CPU_CHAR *)"OTA TASK Handle", (OS_TASK_PTR )OTA_TASK_Handle, (void *)0, (OS_PRIO )OTA_TASK_PRIO, (CPU_STK *)&OTA_TASK_HandleStk[0], (CPU_STK_SIZE)OTA_TASK_START_STK_SIZE / 10, (CPU_STK_SIZE)OTA_TASK_START_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); //pcb版本1加入编码器,打开编码器任务 if(hd_id == PCB_V1) { OSTaskCreate((OS_TCB *)&ENCODER_TASK_HandleTCB, (CPU_CHAR *)"ENCODER TASK Handle", (OS_TASK_PTR )ENCODER_TASK_Handle, (void *)0, (OS_PRIO )ENCODER_TASK_PRIO, (CPU_STK *)&ENCODER_TASK_HandleStk[0], (CPU_STK_SIZE)ENCODER_TASK_START_STK_SIZE / 10, (CPU_STK_SIZE)ENCODER_TASK_START_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); } OSTaskDel(&AppTaskStartTCB, &err); } uint8_t uart3_buf[1300] = {0}; uint16_t uart3_len = 0; uint8_t delay = 0; void LED_TASK_Handle(void * p_arg)//按键和指示灯任务函数 { OS_ERR err; (void)p_arg; while (1) { led_run();//led灯运行处理 key_press();//按键处理 device_real_time_para_read();//读实时参数(温度、电压) run_irq_set();//运行时中断控制 device_module_reset();//设备模块复位判断 watchdog_feed();//喂狗 tax_ciphertext_0x8C_process(); //测试 // uart3_len = uart_rcv_uart3(uart3_buf); // if(uart3_len) // { // data_dump("uart3 rcv",uart3_buf,uart3_len); // } OSTimeDlyHMSM(0, 0, 0, 50, OS_OPT_TIME_DLY, &err); } } void UART_TASK_Handle(void * p_arg)//串口接收任务函数 { u8 i; OS_ERR err; (void)p_arg; for(i = 0;i < UART_MAX;i++) { uart_rs232_init(i, NULL); } while (1) { for(i = 0;i < 5;i++) { uart_rcv_process(i); } task_count.uart_count_cur++; OSTimeDlyHMSM(0, 0, 0, 20, OS_OPT_TIME_DLY, &err); } } //uint8_t uart_rcv_buf[128],uart_rcv_len; //uint8_t uart_send_buf[128],uart_send_len; void PROG_TASK_Handle(void * p_arg)//业务处理函数 { OS_ERR err; (void)p_arg; while(1) { business_uart_rcv_proc();//业务串口接收处理 uart_timeout_handle();//串口超时处理函数 pos_changle();//pos切换 pt_handle();//产测处理 xsp_ota_handle();//显示屏(0904)升级 // xsp_update_handle();//显示屏升级 task_count.prog_count_cur++; OSTimeDlyHMSM(0, 0, 0, 20, OS_OPT_TIME_DLY, &err); } } void OTA_TASK_Handle(void * p_arg)//升级任务处理函数 { OS_ERR err; (void)p_arg; while(1) { //升级时从设备处理 if(device_fixed_info.slave_uploade_start)//开始上报升级状态 { device_fixed_info.slave_uploade_start = 0; device_fixed_info.Work_State = DEV_WORK_STATE_UPDATING; ota_state.update_mode = OTA_WORK_STATE_UPLOAD; srand(device_info.device_sn);//随机数种子 ota_timer_upload_cad_slave_set(OPEN,SLAVE_CAD_TIME_MIN);//打开上报间隔定时 ota_timer_upload_total_slave_set(OPEN,OTA_SLAVE_UPLOADE_TIME_TICK);//打开上报总定时 } ota_slave_time_handle();//从设备升级定时处理函数 //升级时主设备处理 if(device_fixed_info.master_updata_start)//开始离线升级 { device_fixed_info.master_updata_start = 0; device_fixed_info.Work_State = DEV_WORK_STATE_UPDATING; ota_state.update_mode = OTA_WORK_STATE_MASTER; Offline_upgrade_master();//离线升级时的主设备下发升级包 } ota_master_time_handle();//离线升级主设备定时处理函数 task_count.ota_count_cur++; OSTimeDlyHMSM(0, 0, 0, 20, OS_OPT_TIME_DLY, &err); } } void LORA_TASK_Handle(void * p_arg)//Lora任务函数 { OS_ERR err; (void)p_arg; lora_queue_init(); lora_init(); while(1) { lora_task(); task_count.lora_count_cur++; OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_DLY, &err); } } void ENCODER_TASK_Handle(void * p_arg)//编码器任务函数 { OS_ERR err; (void)p_arg; encoder_init(); while(1) { encoder_record_end_handle();//交易完成处理函数 gunsignal_irq_delay_handle();//抬枪信号滤波函数 encoder_eeprom_write_handle();//编码器写eeprom // gunnum_irq_delay_handle();//抬枪次数 task_count.encoder_count_cur++; OSTimeDlyHMSM(0, 0, 0, 10, OS_OPT_TIME_DLY, &err); } }