/**************************************************************************** * * Copy right: 2020-, Copyrigths of QIXIANG TECH Ltd. * File name: app.c * Description: QX app source file * History: Rev1.0 2020-10-16 * Athuor: chenjie * ****************************************************************************/ //include #include "bsp.h" #include "bsp_custom.h" #include "osasys.h" #include "ostask.h" #include "queue.h" #include "ps_event_callback.h" #include "app.h" #include "cmisim.h" #include "cmimm.h" #include "cmips.h" #include "sockets.h" #include "psifevent.h" #include "ps_lib_api.h" #include "lwip/netdb.h" #include #include "debug_log.h" #include "slpman_ec616.h" #include "plat_config.h" //define // app task static stack and control block #define PROC_TASK_STACK_SIZE (1024) //uart def #define Uart_Send_LEN (8) #define Uart_Rece_LEN (40)//串口读取的最大数量,40个字节,能满足一次性读取17个单体 #define RTE_UART_RX_IO_MODE RTE_UART1_RX_IO_MODE //statement variable extern ARM_DRIVER_USART Driver_USART1; static ARM_DRIVER_USART *USARTdrv = &Driver_USART1; /** \brief receive timeout flag */ volatile bool isRecvTimeout = false; /** \brief receive complete flag */ volatile bool isRecvComplete = false; uint8_t process0SlpHandler = 0xff; uint8_t process1SlpHandler = 0xff; uint8_t process2SlpHandler = 0xff; uint8_t process3SlpHandler = 0xff; uint8_t Can_Rece_buffer[8]; uint16_t Batt_Cell_Num = 14;//默认数值 uint16_t Batt_Cell_Num_2 ;//默认数值 uint16_t Batt_Temp_Num = 5;//默认数值 int16_t Uart_Rece_BattI; uint8_t battbuffer[73];//电池数据都存在此数组中————电压14,温度5 /** * 存放规则如下: * 位置: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 * 数据: 年 月 日 时 分 秒 信息体标志 年 月 日 时 分 秒 网络信号 故障等级 故障代码高 故障代码低 * * 17 18 19 20 21 22 23 24 25 26 27 28 29 30 30+1 .... 30+X*2 31+X*2 31+1...31+X*2+N * 电流H 电流L Link电压H Link电压L Pack电压H Pack电压L 开关状态 SOC SOH 均衡状态 单体个数X 单体v1...单体vX 温度个数N 温度1..温度N * 32+X*2+N 33+X*2+N * 电池状态 是否加热 * */ uint16_t data_index = 0x0000; typedef enum { PROCESS_STATE_IDLE = 0, PROCESS_STATE_WORK, PROCESS_STATE_SLEEP }processSM; typedef enum { PROCESS_Uart_STATE_IDLE = 0, PROCESS_Uart_STATE_WORK, PROCESS_Uart_STATE_CHECK, PROCESS_Uart_STATE_SLEEP }process_Uart; typedef enum { PROCESS_NB_STATE_IDLE = 0, PROCESS_NB_STATE_WORK, PROCESS_NB_STATE_CONNECT, PROCESS_NB_STATE_SLEEP }process_NB; static StaticTask_t gProcessTask0; static UINT8 gProcessTaskStack0[PROC_TASK_STACK_SIZE]; static StaticTask_t gProcessTask1; static UINT8 gProcessTaskStack1[PROC_TASK_STACK_SIZE]; static StaticTask_t gProcessTask2; static UINT8 gProcessTaskStack2[PROC_TASK_STACK_SIZE]; static StaticTask_t gProcessTask3; static UINT8 gProcessTaskStack3[PROC_TASK_STACK_SIZE]; processSM gProc0State = PROCESS_STATE_IDLE; process_Uart gProc1State = PROCESS_Uart_STATE_IDLE; processSM gProc2State = PROCESS_STATE_IDLE; process_NB gProc3State = PROCESS_NB_STATE_IDLE; #define PROC_Task_STATE_SWITCH(a) (gProc0State = a) //任务调度切换 #define PROC_Uart_STATE_SWITCH(a) (gProc1State = a) //uart 状态切换 #define PROC_Can_STATE_SWITCH(a) (gProc2State = a) //can 状态切换 #define PROC_NB_STATE_SWITCH(a) (gProc3State = a) //NB状态切换 //------------------------------------------------------------------------------------------------------------------------------------------------------- unsigned int crc_chk(uint8_t* data, uint8_t length) { int j; uint16_t reg_crc=0xFFFF; while(length--) { reg_crc ^= *data++; for(j=0;j<8;j++) { if(reg_crc & 0x01) { reg_crc=(reg_crc>>1) ^ 0xA001; } else { reg_crc=reg_crc >>1; } } } return reg_crc; } uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t *Uart_Rece_buffer) { uint16_t CRC_Rece_buffer; uint16_t CRC_chk_buffer; uint8_t Uart_Send_buffer[8]; uint8_t Rece_Data_Len; Uart_Send_buffer[0] = Uart_Receive_Msg.Bms_Address; Uart_Send_buffer[1] = Uart_Receive_Msg.Bms_Read_Funcode; Uart_Send_buffer[2] = Uart_Receive_Msg.Reg_Begin_H; Uart_Send_buffer[3] = Uart_Receive_Msg.Reg_Begin_L; Uart_Send_buffer[4] = Uart_Receive_Msg.Reg_Num_H; Uart_Send_buffer[5] = Uart_Receive_Msg.Reg_Num_L; CRC_chk_buffer = crc_chk(Uart_Send_buffer,6); Uart_Send_buffer[6] = CRC_chk_buffer; Uart_Send_buffer[7] = CRC_chk_buffer>>8; uint32_t timeout=0; USARTdrv->Send(Uart_Send_buffer,8); Rece_Data_Len = Uart_Receive_Msg.Reg_Num_L<<1;//读取几个寄存器的值,数据长度乘以二 USARTdrv->Receive(Uart_Rece_buffer,Rece_Data_Len+5); while((isRecvTimeout == false) && (isRecvComplete == false))// 未收到数据不叫时间超时,收到数据但是不全叫时间超时 { timeout++; if (timeout>7000000) { timeout =0; isRecvTimeout = true; break; } } if (isRecvComplete == true) { Rece_Data_Len = *(Uart_Rece_buffer+2); isRecvComplete = false; CRC_Rece_buffer =*(Uart_Rece_buffer+Rece_Data_Len+4)<<8|*(Uart_Rece_buffer+Rece_Data_Len+3); CRC_chk_buffer = crc_chk(Uart_Rece_buffer,Rece_Data_Len+3); #ifdef USING_PRINTF printf("Uart_Send_buffer: "); for(int i=0;i<8;i++) { printf("%x ",Uart_Send_buffer[i]); } printf("\n"); printf("Uart_Rece_buffer: "); for(int i=0;i=200) { NetSocDisplay(LED_SOC_0,LED_TURN_OFF); sleep_index=0; PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP); } break; } case PROCESS_STATE_WORK: { osDelay(10);//10ms Can_index++; Uart_index++; NB_index++; if (Uart_index >10)//Uart 100ms 调用一次 { PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_WORK); Uart_index = 0; } if (Can_index >=100)//Can 1000ms 调用一次 { PROC_Can_STATE_SWITCH(PROCESS_STATE_WORK); Can_index = 0; } if (NB_index >=100)//NB 1s 调用一次 { PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_CONNECT); NB_index = 0; } if((Uart_Rece_BattI==0x0000)&&(Can_Rece_buffer[0]==0xff)) { sleep_index++; } else { sleep_index = 0; } if (sleep_index >=6000) { PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP); sleep_index = 0; } break; } case PROCESS_STATE_SLEEP: { PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_SLEEP); PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_SLEEP); PROC_Can_STATE_SWITCH(PROCESS_STATE_SLEEP); slpManPlatVoteEnableSleep(process0SlpHandler,SLP_SLP2_STATE); slpManPlatVoteDisableSleep(process0SlpHandler, SLP_HIB_STATE); #ifdef USING_PRINTF printf("ready to sleep \n"); #endif slpManDeepSlpTimerStart(DEEPSLP_TIMER_ID7,180000); // create a 60s timer, DeepSleep Timer is always oneshoot while(1) // now app can enter hib, but ps and phy maybe not, so wait here { osDelay(3000); } } } } } static void process1AppTask(void* arg) { USARTdrv->Initialize(USART_callback); USARTdrv->PowerControl(ARM_POWER_FULL); USARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS | ARM_USART_DATA_BITS_8 | ARM_USART_PARITY_NONE | ARM_USART_STOP_BITS_1 | ARM_USART_FLOW_CONTROL_NONE, 9600); int Rece_index = 0; uint8_t *Uart_Reve_Point = NULL; Uart_Receive_Type Uart_Receive_Msg; PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE); slpManApplyPlatVoteHandle("process1slp",&process1SlpHandler); Uart_Receive_Msg.Bms_Address = 0x01; Uart_Receive_Msg.Bms_Read_Funcode = 0x03; uint8_t *Uart_Rece_buffer; Batt_Cell_Num_2 = Batt_Cell_Num<<1; while(1) { switch(gProc1State) { case PROCESS_Uart_STATE_IDLE: { NetSocDisplay(LED_SOC_1,LED_TURN_OFF); Rece_index = 0; break; } case PROCESS_Uart_STATE_CHECK://检查电流数值 { Uart_Receive_Msg.Reg_Begin_H = 0x00; Uart_Receive_Msg.Reg_Begin_L= 0x02+Batt_Cell_Num; Uart_Receive_Msg.Reg_Num_H = 0x00; Uart_Receive_Msg.Reg_Num_L = 0x01; Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer); Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 |*(Uart_Reve_Point+1); #ifdef USING_PRINTF printf("Check_Current! %x\n ",Uart_Rece_BattI); #endif PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE); break; } case PROCESS_Uart_STATE_WORK: { NetSocDisplay(LED_SOC_1,LED_TURN_ON); Uart_Rece_buffer = (uint8_t *)malloc(Uart_Rece_LEN); memset(Uart_Rece_buffer,0xff,Uart_Rece_LEN); switch(Rece_index) { case 0://读取电流 { Uart_Receive_Msg.Reg_Begin_H = 0x00; Uart_Receive_Msg.Reg_Begin_L= 0x02+Batt_Cell_Num; Uart_Receive_Msg.Reg_Num_H = 0x00; Uart_Receive_Msg.Reg_Num_L = 0x01; Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer); Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 |*(Uart_Reve_Point+1); break; } case 1://读取单体电压 { Uart_Receive_Msg.Reg_Begin_H = 0x00; Uart_Receive_Msg.Reg_Begin_L = 0x02; Uart_Receive_Msg.Reg_Num_H = Batt_Cell_Num>>8; Uart_Receive_Msg.Reg_Num_L = Batt_Cell_Num; Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer); #ifdef USING_PRINTF printf("BattCellV: "); for (size_t i = 0; i < Batt_Cell_Num_2; i++) { printf("%x ",*(Uart_Reve_Point+i)); } printf("\n"); #endif battbuffer[30] = Batt_Cell_Num; memcpy(&battbuffer[31],Uart_Reve_Point,Batt_Cell_Num_2); break; } case 2://读取温度 { Uart_Receive_Msg.Reg_Begin_H = 0x00; Uart_Receive_Msg.Reg_Begin_L = 0x06+Batt_Cell_Num; Uart_Receive_Msg.Reg_Num_H = Batt_Temp_Num>>8; Uart_Receive_Msg.Reg_Num_L = Batt_Temp_Num; Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer); battbuffer[31+Batt_Cell_Num_2] = Batt_Temp_Num; for (int i = 0; i < Batt_Temp_Num; i++) { battbuffer[32+Batt_Cell_Num_2+i] = *(Uart_Reve_Point+2*i+1); } #ifdef USING_PRINTF printf("BattCellT: "); for (size_t i = 0; i < Batt_Temp_Num; i++) { printf("%x ",*(Uart_Reve_Point+i)); } printf("\n"); #endif break; } case 3://读取总电压,目前保护板只有一个电压 { Uart_Receive_Msg.Reg_Begin_H = 0x00; Uart_Receive_Msg.Reg_Begin_L = 0x18+Batt_Cell_Num+Batt_Temp_Num; Uart_Receive_Msg.Reg_Num_H = 0x00; Uart_Receive_Msg.Reg_Num_L = 0x01; Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer); battbuffer[19] = *(Uart_Reve_Point+0);//Link U battbuffer[20] = *(Uart_Reve_Point+1); battbuffer[21] = *(Uart_Reve_Point+0);//Pack U battbuffer[22] = *(Uart_Reve_Point+1); break; } case 4://读取状态及SOC { Uart_Receive_Msg.Reg_Begin_H = 0x00; Uart_Receive_Msg.Reg_Begin_L = 0x09+Batt_Cell_Num+Batt_Temp_Num; Uart_Receive_Msg.Reg_Num_H = 0x00; Uart_Receive_Msg.Reg_Num_L = 0x04; Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer); battbuffer[23] = *(Uart_Reve_Point+0)>>1;//mos状态 battbuffer[24] = *(Uart_Reve_Point+5);//SOC battbuffer[25] = *(Uart_Reve_Point+7);//SOH break; } case 5://读取均衡状态 { Uart_Receive_Msg.Reg_Begin_H = 0x00; Uart_Receive_Msg.Reg_Begin_L = 0x06+Batt_Cell_Num+Batt_Temp_Num; Uart_Receive_Msg.Reg_Num_H = 0x00; Uart_Receive_Msg.Reg_Num_L = 0x02; Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer); memcpy(&battbuffer[26],Uart_Reve_Point,4); break; } default: { PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE); break; } } Rece_index++; free(Uart_Rece_buffer); break; } case PROCESS_Uart_STATE_SLEEP: { while(1) { osDelay(3000); } //此处休眠 } } } } static void process2AppTask(void* arg) { PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE); slpManApplyPlatVoteHandle("process2slp",&process2SlpHandler); uint32_t Can_ID; NVIC_EnableIRQ(PadWakeup1_IRQn); Can_InitType param; Can_TxMsgType Can_TxMsg; param.baudrate = CAN_500Kbps; param.mode = REQOP_NORMAL; param.TxStdIDH = 0x00; param.TxStdIDL = 0x00; param.RxStdIDH[0] = 0x00; param.RxStdIDL[0] = 0x00; /*stdid 0000 0000 001x*/ param.RxStdIDH[1] = 0x00; param.RxStdIDL[1] = 0x20; /*stdid 0000 0000 010x */ param.RxStdIDH[2] = 0x00; param.RxStdIDL[2] = 0x40; /*stdid 0000 0000 011x*/ param.RxStdIDH[3] = 0x00; param.RxStdIDL[3] =0x60; /*stdid 0000 0000 100x */ param.RxStdIDH[4] = 0x00; param.RxStdIDL[4] = 0x80; /*stdid 0000 0000 101x*/ param.RxStdIDH[5] = 0x00; param.RxStdIDL[5] =0xa0; param.packType = STD_PACK; HAL_Can_Init(param); int send_index = 0; while(1) { switch(gProc2State) { case PROCESS_STATE_IDLE: { HAL_Can_Receive(Can_Rece_buffer); send_index = 0; break; } case PROCESS_STATE_WORK: { switch(send_index) { case 0: { Can_ID = 0x001; for (int i = 0; i < 8; i++) { Can_TxMsg.Data[i] = battbuffer[i+31+send_index*8]; } Can_TxMsg.stdIDH = Can_ID>>3; Can_TxMsg.stdIDL = Can_ID<<5; Can_TxMsg.DLC = 8; HAL_Can_Transmit(Can_TxMsg); break; } case 1: { Can_ID = 0x013; for (int i = 0; i < 8; i++) { Can_TxMsg.Data[i] = battbuffer[i+31+send_index*8]; } Can_TxMsg.stdIDH = Can_ID>>3; Can_TxMsg.stdIDL = Can_ID<<5; Can_TxMsg.DLC = 8; HAL_Can_Transmit(Can_TxMsg); break; } case 2: { Can_ID = 0x021; for (int i = 0; i < 8; i++) { Can_TxMsg.Data[i] = battbuffer[i+31+send_index*8]; } Can_TxMsg.stdIDH = Can_ID>>3; Can_TxMsg.stdIDL = Can_ID<<5; Can_TxMsg.DLC = 8; HAL_Can_Transmit(Can_TxMsg); break; } case 3: { Can_ID = 0x031; for (int i = 0; i < 4; i++) { Can_TxMsg.Data[i] = battbuffer[i+31+send_index*8]; } Can_TxMsg.Data[4] = 0x00; Can_TxMsg.Data[5] = 0x00; Can_TxMsg.Data[6] = 0x00; Can_TxMsg.Data[7] = 0x00; Can_TxMsg.stdIDH = Can_ID>>3; Can_TxMsg.stdIDL = Can_ID<<5; Can_TxMsg.DLC = 8; HAL_Can_Transmit(Can_TxMsg); break; } case 4: { Can_ID = 0x101; for (int i = 0; i < 4; i++) { Can_TxMsg.Data[2*i] = 0x00; Can_TxMsg.Data[2*i+1] = battbuffer[i+32+Batt_Cell_Num_2]; } Can_TxMsg.stdIDH = Can_ID>>3; Can_TxMsg.stdIDL = Can_ID<<5; Can_TxMsg.DLC = 8; HAL_Can_Transmit(Can_TxMsg); break; } default: { PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE); Can_Rece_buffer[0]=0xff; break; } } // #ifdef USING_PRINTF // printf("CANID:%#x Msg: ",Can_ID); // for (size_t i = 0; i < 8; i++) // { // printf("%x ",Can_TxMsg.Data[i]); // } // printf("\n"); // #endif #ifdef USING_PRINTF printf("CANsend :%x\n ",Can_ID); #endif send_index ++; break; } case PROCESS_STATE_SLEEP: { while(1) { osDelay(3000); } } } } } uint8_t bcc_chk(uint8_t* data, uint8_t length) { uint8_t bcc_chk_return = 0x00; uint8_t count = 0; while (count>16; battbuffer[0] = battbuffer[0] - 0x07D0; battbuffer[1] = timestracture.UTCtimer1>>8; battbuffer[2] = timestracture.UTCtimer1; battbuffer[3] = timestracture.UTCtimer2>>24; battbuffer[4] = timestracture.UTCtimer2>>16; battbuffer[5] = timestracture.UTCtimer2>>8; switch (datatype) { case 0x80: { battbuffer[6] = 0x80;//信息体标志,此处为电池信息 battbuffer[7] = battbuffer[0];//年 battbuffer[8] = battbuffer[1];//月 battbuffer[9] = battbuffer[2];//日 battbuffer[10] = battbuffer[3];//时 0时区时间 battbuffer[11] = battbuffer[4];//分 battbuffer[12] = battbuffer[5];//秒 battbuffer[13] = 0x1A;// 网络信号 battbuffer[14] = 0x00;//故障等级 battbuffer[15] = 0x00;//故障代码高 battbuffer[16] = 0x00;//故障代码低 //电流适应性更改,从int转换到uint,加1000的偏移量,100mA的单位 if (Batt_current>0x8000) { Batt_current = Batt_current|0x7fff; Batt_current = 0x2710 - Batt_current; Batt_current = Batt_current/10; } else { Batt_current = Batt_current+0x2710; Batt_current = Batt_current/10; } battbuffer[17] = Batt_current>>8; battbuffer[18] = Batt_current; data_index = 32+Batt_Cell_Num_2+Batt_Temp_Num; battbuffer[data_index] = 0x00;//电池状态 data_index++; battbuffer[data_index] = 0x00;//是否加热 data_index++; break; } default: break; } return; } static void process3AppTask(void* arg) { CHAR SN[] = "GYTEST00000000002"; CHAR serverip[] = "47.97.127.222"; UINT16 serverport = 8712; int TcpConnectID = -1; int TcpSendID = -1; int NB_send_len=59+Batt_Cell_Num_2+Batt_Temp_Num;//设定网络发送最大数值 slpManApplyPlatVoteHandle("process3slp",&process3SlpHandler); PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_IDLE); while(1) { switch(gProc3State) { case PROCESS_NB_STATE_IDLE: { break; } case PROCESS_NB_STATE_CONNECT: { while(TcpConnectID<0) { TcpConnectID = tcpipConnectionCreate(1,PNULL,PNULL,serverip,serverport,TcpCallBack); } PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_WORK); break; } case PROCESS_NB_STATE_WORK: { uint8_t* TcpSendBuffer; TcpSendBuffer = (uint8_t *)malloc(NB_send_len);//申请发送的数据内存 if (!TcpSendBuffer) { #ifdef USING_PRINTF printf("[%d]malloc error! \r\n",__LINE__); #endif } memset(TcpSendBuffer,0x00,92); *(TcpSendBuffer+0) = 0x23; *(TcpSendBuffer+1) = 0x23; *(TcpSendBuffer+2) = 0x02; *(TcpSendBuffer+3) = 0xfe; memcpy(TcpSendBuffer+4,SN,17); *(TcpSendBuffer+21) = 0x01;//不加密 Tcp_Data_Assemble(0x80); *(TcpSendBuffer+22) = data_index>>8;//数据长度 *(TcpSendBuffer+23) = data_index;//数据长度 memcpy(TcpSendBuffer+24,battbuffer,data_index); #ifdef USING_PRINTF printf("battbuffer:"); for (int i = 0; i < data_index; i++) { printf("%x ",battbuffer[i]); } printf("\n "); #endif *(TcpSendBuffer+NB_send_len-1) = bcc_chk(TcpSendBuffer,NB_send_len-1); // #ifdef USING_PRINTF // printf("[%d]sizeof:%d \r\n",__LINE__,sizeof(TcpSendBuffer)-1); // #endif // #ifdef USING_PRINTF // printf("[%d]Tcpchk:%#X \r\n",__LINE__,*(TcpSendBuffer+91)); // #endif #ifdef USING_PRINTF printf("TcpSend:"); for (int i = 0; i < NB_send_len; i++) { printf("%x ",*(TcpSendBuffer+i)); } printf("\n "); #endif TcpSendID = tcpipConnectionSend(TcpConnectID,TcpSendBuffer,NB_send_len,PNULL,PNULL,PNULL); free(TcpSendBuffer); PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_IDLE); break; } case PROCESS_NB_STATE_SLEEP: { while(1) { osDelay(3000); } } } } } /** \fn process0Init(void) \brief process0Init function. \return */ void process0Init(void) { osThreadAttr_t task_attr; #ifndef USING_PRINTF if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0) { HAL_UART_RecvFlowControl(false); } #endif memset(&task_attr,0,sizeof(task_attr)); memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE); task_attr.name = "Process0AppTask"; task_attr.stack_mem = gProcessTaskStack0; task_attr.stack_size = PROC_TASK_STACK_SIZE; task_attr.priority = osPriorityNormal;//osPriorityBelowNormal; task_attr.cb_mem = &gProcessTask0;//task control block task_attr.cb_size = sizeof(StaticTask_t);//size of task control block osThreadNew(process0AppTask, NULL, &task_attr); } /** \fn process1Init(void) \brief process1Init function. \return */ void process1Init(void) { osThreadAttr_t task_attr; #ifndef USING_PRINTF if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0) { HAL_UART_RecvFlowControl(false); } #endif memset(&task_attr,0,sizeof(task_attr)); memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE); task_attr.name = "Process1AppTask"; task_attr.stack_mem = gProcessTaskStack1; task_attr.stack_size = PROC_TASK_STACK_SIZE; task_attr.priority = osPriorityNormal;//osPriorityBelowNormal; task_attr.cb_mem = &gProcessTask1;//task control block task_attr.cb_size = sizeof(StaticTask_t);//size of task control block osThreadNew(process1AppTask, NULL, &task_attr); } /** \fn process2Init(void) \brief process2Init function. \return */ void process2Init(void) { osThreadAttr_t task_attr; memset(&task_attr,0,sizeof(task_attr)); memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE); task_attr.name = "Process2AppTask"; task_attr.stack_mem = gProcessTaskStack2; task_attr.stack_size = PROC_TASK_STACK_SIZE; task_attr.priority = osPriorityNormal;//osPriorityBelowNormal; task_attr.cb_mem = &gProcessTask2;//task control block task_attr.cb_size = sizeof(StaticTask_t);//size of task control block osThreadNew(process2AppTask, NULL, &task_attr); } void process3Init(void) { osThreadAttr_t task_attr; memset(&task_attr,0,sizeof(task_attr)); memset(gProcessTaskStack3, 0xA5,PROC_TASK_STACK_SIZE); task_attr.name = "Process3AppTask"; task_attr.stack_mem = gProcessTaskStack3; task_attr.stack_size = PROC_TASK_STACK_SIZE; task_attr.priority = osPriorityNormal;//osPriorityBelowNormal; task_attr.cb_mem = &gProcessTask3;//task control block task_attr.cb_size = sizeof(StaticTask_t);//size of task control block osThreadNew(process3AppTask, NULL, &task_attr); } /** \fn appInit(void) \brief appInit function. \return */ void appInit(void *arg) { process0Init();//任务调度和检测程序 process1Init();//Uart程序 process2Init();//Can程序 process3Init();//NB程序 } /** \fn int main_entry(void) \brief main entry function. \return */ void main_entry(void) { BSP_CommonInit(); osKernelInitialize(); registerAppEntry(appInit, NULL); if (osKernelGetState() == osKernelReady) { osKernelStart(); } while(1); }