1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177 |
- /*******************************
- *
- * 骑享程序测试
- *
- * ****************************/
- #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 <cis_def.h>
- #include "debug_log.h"
- #include "slpman_ec616.h"
- #include "plat_config.h"
- //空间及变量定义
- #define PROC_MAIN_TASK_STACK_SIZE (1024)
- #define PROC_UART_TASK_STACK_SIZE (1024)
- #define PROC_CAN_TASK_STACK_SIZE (1024)
- #define PROC_TCP_TASK_STACK_SIZE (1024)
- #define APP_EVENT_QUEUE_SIZE (10)
- uint8_t deepslpTimerID = DEEPSLP_TIMER_ID7;
- uint8_t MainSlpHandler = 0xff;
- uint8_t UartSlpHandler = 0xfe;
- uint8_t CanSlpHandler = 0xfd;
- uint8_t TcpSlpHandler = 0xfd;
- #define Uart_Send_LEN (8)
- #define Uart_Rece_LEN (40)
- #define RTE_UART_RX_IO_MODE RTE_UART1_RX_IO_MODE
- extern ARM_DRIVER_USART Driver_USART1;
- static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
- volatile bool isRecvTimeout = false;
- volatile bool isRecvComplete = false;
- static volatile UINT32 Event;
- static QueueHandle_t psEventQueueHandle;
- static UINT8 gImsi[16] = {0};
- static INT32 sockfd = -1;
- static UINT32 gCellID = 0;
- uint8_t Batt_Cell_Num = 14;//默认数值14、17
- uint8_t Batt_Cell_Num_2 ;//默认数值
- uint8_t Batt_Temp_Num = 5;//默认数值5、7
- int16_t Uart_Rece_BattI=0x0000;
- uint8_t Can_Rece_buffer[8];
- volatile bool Can_Enable = false;
- uint16_t data_index = 0x0000;
- uint8_t battbuffer[100];//电池数据都存在此数组中————电压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 34+x*2+N 35 +X*2+N 36+X*2 +N 37+X*2+N
- * 电池状态 是否加热 最高单体H 最高单体L 最低单体H 最低单体L
- * */
- //状态机定义
- typedef enum
- {
- PROCESS_STATE_IDLE = 0,
- PROCESS_STATE_WORK,
- PROCESS_STATE_SLEEP
- }process_Main;
- static process_Main gProcess_Main_Task = PROCESS_STATE_IDLE;
- #define PROC_MAIN_STATE_SWITCH(a) (gProcess_Main_Task = a)
- typedef enum
- {
- PROCESS_UART_STATE_IDLE = 0,
- PROCESS_UART_STATE_CHECK,
- PROCESS_UART_STATE_WORK,
- PROCESS_UART_STATE_SLEEP
- }process_Uart;
- static process_Uart gProcess_Uart_Task = PROCESS_UART_STATE_IDLE;
- #define PROC_UART_STATE_SWITCH(a) (gProcess_Uart_Task = a)
- typedef enum
- {
- PROCESS_CAN_STATE_IDLE = 0,
- PROCESS_CAN_STATE_RECV,
- PROCESS_CAN_STATE_SEND,
- PROCESS_CAN_STATE_SLEEP
- }process_CAN;
- static process_CAN gProcess_Can_Task = PROCESS_CAN_STATE_IDLE;
- #define PROC_CAN_STATE_SWITCH(a) (gProcess_Can_Task = a)
- typedef enum
- {
- PROCESS_TCP_STATE_IDLE = 0,
- PROCESS_TCP_STATE_LINK,
- PROCESS_TCP_STATE_WORK,
- PROCESS_TCP_STATE_SLEEP
- }process_TCP;
- static process_TCP gProcess_Tcp_Task = PROCESS_TCP_STATE_IDLE;
- #define PROC_TCP_STATE_SWITCH(a) (gProcess_Tcp_Task = a)
- //堆栈申请
- static StaticTask_t gProcess_Main_Task_t;
- static UINT8 gProcess_Main_TaskStack[PROC_UART_TASK_STACK_SIZE];
- static StaticTask_t gProcess_Uart_Task_t;
- static UINT8 gProcess_Uart_TaskStack[PROC_UART_TASK_STACK_SIZE];
- static StaticTask_t gProcess_Can_Task_t;
- static UINT8 gProcess_Can_TaskStack[PROC_CAN_TASK_STACK_SIZE];
- static StaticTask_t gProcess_Tcp_Task_t;
- static UINT8 gProcess_Tcp_TaskStack[PROC_TCP_TASK_STACK_SIZE];
- //睡眠进出函数
- static void appBeforeHib(void *pdata, slpManLpState state)
- {
- uint32_t *p_param = (uint32_t *)pdata;
- #ifdef USING_PRINTF
- printf("Before Hibernate:%d \n",state);
- #endif
- slpManAONIOLatchEn(AonIOLatch_Enable);
- }
- static void appAfterHib(void *pdata, slpManLpState state)
- {
- #ifdef USING_PRINTF
- printf("Try Hibernate Failed:%d \n",state);
- #endif
- }
- static void appBeforeSlp1(void *pdata, slpManLpState state)
- {
- #ifdef USING_PRINTF
- printf("Before Sleep1:%d \n",state);
- #endif
- slpManAONIOLatchEn(AonIOLatch_Enable);
- }
- static void appAfterSlp1(void *pdata, slpManLpState state)
- {
- #ifdef USING_PRINTF
- printf("After Sleep1:%d \n",state);
- #endif
- }
- static void appBeforeSlp2(void *pdata, slpManLpState state)
- {
- #ifdef USING_PRINTF
- printf("before sleep2:%d \n",state);
- #endif
- slpManAONIOLatchEn(AonIOLatch_Enable);
- }
- static void appAfterSlp2(void *pdata, slpManLpState state)
- {
- #ifdef USING_PRINTF
- printf("sleep2 failed:%d \n",state);
- #endif
- }
- // 主任务线程
- static void Main_Task(void* arg)
- {
- UINT16 Can_index = 0;
- UINT16 Uart_index = 0;
- UINT16 Tcp_index = 0;
- uint32_t sleep_index = 0;
- int32_t inParam = 0xAABBCCDD;
- PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
- NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
- NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
- NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
- FaultDisplay(LED_TURN_OFF);
- NVIC_EnableIRQ(PadWakeup1_IRQn);
- slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
- slpManApplyPlatVoteHandle("MainSlp",&MainSlpHandler);
- slpManPlatVoteDisableSleep(MainSlpHandler, SLP_SLP2_STATE);
- slpManRegisterUsrdefinedBackupCb(appBeforeHib,&inParam,SLPMAN_HIBERNATE_STATE);
- slpManRegisterUsrdefinedRestoreCb(appAfterHib,NULL,SLPMAN_HIBERNATE_STATE);
- slpManRegisterUsrdefinedBackupCb(appBeforeSlp1,NULL,SLPMAN_SLEEP1_STATE);
- slpManRegisterUsrdefinedRestoreCb(appAfterSlp1,NULL,SLPMAN_SLEEP1_STATE);
- slpManRegisterUsrdefinedBackupCb(appBeforeSlp2,NULL,SLPMAN_SLEEP2_STATE);
- slpManRegisterUsrdefinedRestoreCb(appAfterSlp2,NULL,SLPMAN_SLEEP2_STATE);
- slpManSlpState_t slpstate = slpManGetLastSlpState();
- #ifdef USING_PRINTF
- printf("slpstate:%d \n",slpstate);
- #endif
- if((slpstate == SLP_SLP2_STATE) || (slpstate == SLP_HIB_STATE))
- {
- PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
- }
- else
- {
- PROC_MAIN_STATE_SWITCH(PROCESS_STATE_WORK);
- }
- //线程初始化完成
- while (true)
- {
- switch(gProcess_Main_Task)
- {
- case PROCESS_STATE_IDLE:
- {
- // 暂时不区分唤醒
- PROC_MAIN_STATE_SWITCH(PROCESS_STATE_WORK);
- break;
- }
- case PROCESS_STATE_WORK:
- {
- osDelay(10/portTICK_PERIOD_MS);
- Can_index++;
- Uart_index++;
- Tcp_index++;
- if (Uart_index >100)//Uart 1s 调用一次
- {
- PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_WORK);
- Uart_index = 0;
- }
- if (Can_index >=100)//Can 1s 调用一次
- {
- PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_RECV);
- Can_index = 0;
- }
- if (Tcp_index >=100)//Tcp 1s 调用一次
- {
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_LINK);
- Tcp_index = 0;
- }
- if((!Can_Enable)&&(Uart_Rece_BattI==0x0000))
- {
- sleep_index++;
- }
- else
- {
- sleep_index = 0;
- }
- if (sleep_index >=6000)
- {
- PROC_MAIN_STATE_SWITCH(PROCESS_STATE_SLEEP);
- sleep_index = 0;
- }
- break;
- }
- case PROCESS_STATE_SLEEP:
- {
- while((gProcess_Uart_Task!=PROCESS_UART_STATE_SLEEP)||(gProcess_Can_Task!=PROCESS_CAN_STATE_SLEEP)||(gProcess_Tcp_Task!=PROCESS_TCP_STATE_SLEEP))
- {
- PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_SLEEP);
- PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_SLEEP);
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_SLEEP);
- }
- slpManSlpState_t State;
- uint8_t cnt;
- if(slpManCheckVoteState(MainSlpHandler, &State, &cnt)==RET_TRUE)
- {
- #ifdef USING_PRINTF
- printf("[%d]We Can Check Vote State, state=%d, cnt=%d\r\n",__LINE__,State,cnt);
- #endif
- }
- slpManPlatVoteEnableSleep(MainSlpHandler, SLP_SLP2_STATE);
- if(slpManCheckVoteState(MainSlpHandler, &State, &cnt)==RET_TRUE)
- {
- #ifdef USING_PRINTF
- printf("[%d]We Can Check Vote State Again, state=%d, cnt=%d\r\n",__LINE__,State,cnt);
- #endif
- }
- #ifdef USING_PRINTF
- printf("[%d]Waiting sleep\r\n",__LINE__);
- #endif
- #ifdef USING_PRINTF
- printf("Main_Sleep\n");
- #endif
- FaultDisplay(LED_TURN_ON);
- slpManDeepSlpTimerStart(deepslpTimerID,300000);
- while(1)
- {
- osDelay(30000/portTICK_PERIOD_MS);
- }
- break;
- }
- }
- }
-
- }
- //Uart校验程序
- 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;
- }
- //Uart回调程序
- void USART_callback(uint32_t event)
- {
- if(event & ARM_USART_EVENT_RX_TIMEOUT)
- {
- isRecvTimeout = true;
- }
- if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
- {
- isRecvComplete = true;
- }
- }
- //Uart发送接收函数
- uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t* Uart_Rece_buffer,uint8_t Data_Len)
- {
- uint16_t CRC_Rece_buffer;
- uint16_t CRC_chk_buffer;
- uint8_t Uart_Send_buffer[8];
- 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 = 0x00000000;
- USARTdrv->Send(Uart_Send_buffer,8);
- // #ifdef USING_PRINTF
- // printf("Uart_Send_buffer: ");
- // for(int i=0;i<8;i++)
- // {
- // printf("%x ",Uart_Send_buffer[i]);
- // }
- // printf("\n");
- // #endif
- USARTdrv->Receive(Uart_Rece_buffer,Data_Len);
- while((isRecvTimeout == false) && (isRecvComplete == false))
- {
- timeout++;
- if (timeout>=7000000)
- {
- timeout =0;
- isRecvTimeout = true;
- break;
- }
- }
- if (isRecvComplete == true)
- {
- #ifdef USING_PRINTF
- #endif
- isRecvComplete = false;
- CRC_Rece_buffer =*(Uart_Rece_buffer+Data_Len-1)<<8|*(Uart_Rece_buffer+Data_Len-2);
- CRC_chk_buffer = crc_chk(Uart_Rece_buffer,Data_Len-2);
- if (CRC_Rece_buffer == CRC_chk_buffer)//满足校验
- {
- return Uart_Rece_buffer;//此处指针移位出现重启问题
- }
- else //接收数据的校验不过屏蔽
- {
- #ifdef USING_PRINTF
- printf("Uart_Rece_buffer: ");
- for(int i=0;i<Data_Len;i++)
- {
- printf("%x ",*(Uart_Rece_buffer+i));
- }
- printf("crcchk:%x,%x\n ",CRC_chk_buffer,CRC_Rece_buffer);
- #endif
- memset(Uart_Rece_buffer,0xff,Data_Len);
- return Uart_Rece_buffer;
- }
- }
- else
- {
- memset(Uart_Rece_buffer,0x00,Data_Len);
- isRecvTimeout = false;
- osDelay(100);
- return Uart_Rece_buffer;
- }
- }
- //Uart线程
- static void Uart_Task(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;
- volatile uint8_t Data_Len;
- Uart_Receive_Type Uart_Receive_Msg;
- memset(&battbuffer[0],0x00,100);
- PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
- slpManApplyPlatVoteHandle("UARTSLP",&UartSlpHandler);
- slpManPlatVoteDisableSleep(UartSlpHandler, SLP_SLP2_STATE);
- Uart_Receive_Msg.Bms_Address = 0x01;
- Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
- uint8_t *Uart_Rece_buffer = NULL;
- volatile bool Uart_task = false;
- Batt_Cell_Num_2 = Batt_Cell_Num<<1;
- while (true)
- {
- switch (gProcess_Uart_Task)
- {
- case PROCESS_UART_STATE_IDLE:
- {
- NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
- Rece_index = 0;
- break;
- }
- case PROCESS_UART_STATE_CHECK:
- {
- Uart_Rece_buffer = (uint8_t *)malloc(Uart_Rece_LEN);
- 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;
- Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
- memset(Uart_Rece_buffer,0x00,Data_Len);
- Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
- Uart_Rece_BattI = *(Uart_Rece_buffer+3+0)<<8 |*(Uart_Rece_buffer+3+1);
- #ifdef USING_PRINTF
- printf("Check_Current!\n");
- #endif
- PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
- free(Uart_Rece_buffer);
- break;
- }
- case PROCESS_UART_STATE_WORK:
- {
- NetSocDisplay(LED_SOC_1,LED_TURN_ON);
- Uart_task = false;
- Uart_Rece_buffer = (uint8_t *)malloc(Uart_Rece_LEN);
- while(!Uart_task)
- {
- switch (Rece_index)
- {
- case 0://current
- {
- 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;
- Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
- memset(Uart_Rece_buffer,0x00,Data_Len);
- Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
- Uart_Rece_BattI = *(Uart_Rece_buffer+3+0)<<8 |*(Uart_Rece_buffer+3+1);
- break;
- }
- case 1://cell votage
- {
- 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;
- Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
- memset(Uart_Rece_buffer,0x00,Data_Len);
- Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
- battbuffer[30] = Batt_Cell_Num;
- memcpy(&battbuffer[31],Uart_Rece_buffer+3,Batt_Cell_Num_2);
- break;
- }
- case 2://temprature
- {
- 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;
- Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
- memset(Uart_Rece_buffer,0x00,Data_Len);
- Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
- 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_Rece_buffer+3+2*i+1);
- }
- break;
- }
- case 3://batt votage
- {
- 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;
- Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
- memset(Uart_Rece_buffer,0x00,Data_Len);
- Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
- battbuffer[19] = *(Uart_Rece_buffer+3+0);//Link U
- battbuffer[20] = *(Uart_Rece_buffer+3+1);
- battbuffer[21] = *(Uart_Rece_buffer+3+0);//Pack U
- battbuffer[22] = *(Uart_Rece_buffer+3+1);
- break;
- }
- case 4://soc,soh
- {
- 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;
- Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
- memset(Uart_Rece_buffer,0x00,Data_Len);
- Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
- battbuffer[23] = *(Uart_Rece_buffer+3+0)>>1;//mos状态
- battbuffer[24] = *(Uart_Rece_buffer+3+5);//SOC
- battbuffer[25] = *(Uart_Rece_buffer+3+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;
- Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
- memset(Uart_Rece_buffer,0x00,Data_Len);
- Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
- memcpy(&battbuffer[26],Uart_Rece_buffer+3,4);
- break;
- }
- case 6:
- {
- Uart_Receive_Msg.Reg_Begin_H = 0x00;
- Uart_Receive_Msg.Reg_Begin_L = 0x19+Batt_Cell_Num+Batt_Temp_Num;
- Uart_Receive_Msg.Reg_Num_H = 0x00;
- Uart_Receive_Msg.Reg_Num_L = 0x02;
- Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
- memset(Uart_Rece_buffer,0x00,Data_Len);
- Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
- memcpy(&battbuffer[34+Batt_Cell_Num_2+Batt_Temp_Num],Uart_Rece_buffer+3,4);
- break;
- }
- default:
- {
- PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
- Uart_task = true;
- break;
- }
- }
- Rece_index++;
- }
- free(Uart_Rece_buffer);
- break;
- }
- case PROCESS_UART_STATE_SLEEP:
- {
- slpManPlatVoteEnableSleep(UartSlpHandler, SLP_SLP2_STATE);
- while(1)
- {
- osDelay(30000/portTICK_PERIOD_MS);
- }
- }
- }
- }
- }
- //Can-线程任务
- static void Can_Task(void* arg)
- {
- uint32_t Can_ID;
- Can_InitType param;
- Can_TxMsgType Can_TxMsg;
- param.baudrate = CAN_500Kbps;
- param.mode = REQOP_NORMAL;
- //过滤ID配置
- 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;
- uint16_t Batt_Cell_addU = 0x0000;
- slpManApplyPlatVoteHandle("CanSlp",&CanSlpHandler);
- slpManPlatVoteDisableSleep(CanSlpHandler, SLP_SLP2_STATE);
- volatile bool Can_Flag=false;
- PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_IDLE);
- while(1)
- {
- switch(gProcess_Can_Task)
- {
- case PROCESS_CAN_STATE_IDLE:
- {
- Can_Rece_buffer[0]=0xff;
- send_index = 0;
- break;
- }
- case PROCESS_CAN_STATE_RECV:
- {
- //can采用先接收后发送的策略
- HAL_Can_Receive(Can_Rece_buffer);
- if (Can_Rece_buffer[0]!=0xff)//满足can发送使能
- {
- PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_SEND);
- Can_Enable = true;
- }
- else
- {
- Can_Enable = false;
- }
- break;
- }
- case PROCESS_CAN_STATE_SEND:
- {
- Can_Flag=false;
- while(!Can_Flag)
- {
- #ifdef USING_PRINTF
- printf("Can_Send!\n");
- #endif
- 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 = 0x011;
- 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 = 0x020;
- 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 < Batt_Temp_Num; i++)
- {
- Can_TxMsg.Data[i] = 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;
- }
- case 5:
- {
- Batt_Cell_addU = 0x0000;
- for (int i = 0; i < Batt_Cell_Num; i++)
- {
- Batt_Cell_addU = Batt_Cell_addU + (battbuffer[31+i*2]<<8|battbuffer[31+i*2+1]);
- }
- Can_ID = 0x201;
- Can_TxMsg.Data[0] = battbuffer[19];
- Can_TxMsg.Data[1] = battbuffer[20];
- Can_TxMsg.Data[2] = battbuffer[21];
- Can_TxMsg.Data[3] = battbuffer[22];//外电压
- Can_TxMsg.Data[4] = Batt_Cell_addU>>8;
- Can_TxMsg.Data[5] = Batt_Cell_addU;//累加电压
- Can_TxMsg.Data[6] = Uart_Rece_BattI>>8;
- Can_TxMsg.Data[7] = Uart_Rece_BattI;
- Can_TxMsg.stdIDH = Can_ID>>3;
- Can_TxMsg.stdIDL = Can_ID<<5;
- Can_TxMsg.DLC = 8;
- HAL_Can_Transmit(Can_TxMsg);
- break;
- }
- case 6:
- {
- Can_ID = 0x211;
- Can_TxMsg.Data[0] = battbuffer[34+Batt_Cell_Num_2+Batt_Temp_Num];
- Can_TxMsg.Data[1] = battbuffer[35+Batt_Cell_Num_2+Batt_Temp_Num];
- Can_TxMsg.Data[2] = battbuffer[36+Batt_Cell_Num_2+Batt_Temp_Num];
- Can_TxMsg.Data[3] = battbuffer[37+Batt_Cell_Num_2+Batt_Temp_Num];
- Can_TxMsg.Data[4] = 0x00;
- Can_TxMsg.Data[5] = 0x00;
- Can_TxMsg.Data[6] = battbuffer[24];
- Can_TxMsg.Data[7] = Batt_Temp_Num<<4|0;
- Can_TxMsg.stdIDH = Can_ID>>3;
- Can_TxMsg.stdIDL = Can_ID<<5;
- Can_TxMsg.DLC = 8;
- HAL_Can_Transmit(Can_TxMsg);
- break;
- }
- case 7:
- {
- Can_ID = 0x221;
- Can_TxMsg.Data[0] = battbuffer[25];//SOH
- Can_TxMsg.Data[1] = 0x00;
- Can_TxMsg.Data[2] = 0x00;
- Can_TxMsg.Data[3] = 0x00;
- 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;
- }
- default:
- {
- Can_Flag=true;
- PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_IDLE);
- break;
- }
- }
- send_index ++;
- }
- break;
- }
- case PROCESS_CAN_STATE_SLEEP:
- {
- slpManPlatVoteEnableSleep(CanSlpHandler, SLP_SLP2_STATE);
- while(1)
- {
- osDelay(30000/portTICK_PERIOD_MS);
- }
- }
- }
- }
- }
- static void sendQueueMsg(UINT32 msgId, UINT32 xTickstoWait)
- {
- eventCallbackMessage_t *queueMsg = NULL;
- queueMsg = malloc(sizeof(eventCallbackMessage_t));
- queueMsg->messageId = msgId;
- if (psEventQueueHandle)
- {
- if (pdTRUE != xQueueSend(psEventQueueHandle, &queueMsg, xTickstoWait))
- {
- ECOMM_TRACE(UNILOG_PLA_APP, sendQueueMsg_1, P_ERROR, 0, "xQueueSend error");
- }
- }
- }
- static INT32 socketRegisterPSUrcCallback(urcID_t eventID, void *param, UINT32 paramLen)
- {
- CmiSimImsiStr *imsi = NULL;
- CmiPsCeregInd *cereg = NULL;
- UINT8 rssi = 0, index = 0;
- NmAtiNetifInfo *netif = NULL;
- switch(eventID)
- {
- case NB_URC_ID_SIM_READY:
- {
- imsi = (CmiSimImsiStr *)param;
- memcpy(gImsi, imsi->contents, imsi->length);
- #ifdef USING_PRINTF
- printf("SIM ready(imsi=%s)\n",(UINT8 *)imsi->contents);
- #endif
- break;
- }
- case NB_URC_ID_MM_SIGQ:
- {
- rssi = *(UINT8 *)param;
- #ifdef USING_PRINTF
- printf("RSSI signal=%d\n",rssi);
- #endif
- ECOMM_TRACE(UNILOG_PLA_APP, socketRegisterPSUrcCallback_1, P_INFO, 1, "RSSI signal=%d", rssi);
- break;
- }
- case NB_URC_ID_PS_BEARER_ACTED:
- {
- #ifdef USING_PRINTF
- printf("Default bearer activated\n");
- #endif
- break;
- }
- case NB_URC_ID_PS_BEARER_DEACTED:
- {
- #ifdef USING_PRINTF
- printf("Default bearer Deactivated\n");
- #endif
- break;
- }
- case NB_URC_ID_PS_CEREG_CHANGED:
- {
- cereg = (CmiPsCeregInd *)param;
- gCellID = cereg->celId;
- #ifdef USING_PRINTF
- printf("URCCallBack:CEREG changed act:%d celId:%d locPresent:%d tac:%d\n", cereg->act, cereg->celId, cereg->locPresent, cereg->tac);
- #endif
- break;
- }
- case NB_URC_ID_PS_NETINFO:
- {
- netif = (NmAtiNetifInfo *)param;
- if (netif->netStatus == NM_NETIF_ACTIVATED)
- sendQueueMsg(QMSG_ID_NW_IP_READY, 0);
- break;
- }
- }
- return 0;
- }
- uint8_t bcc_chk(uint8_t* data, uint8_t length)//发送bcc校验函数
- {
- uint8_t bcc_chk_return = 0x00;
- uint8_t count = 0;
- while (count<length)
- {
- bcc_chk_return^=data[count];
- count++;
- }
- return bcc_chk_return;
- }
- //电池数据组装函数
- void Tcp_Batt_Data_Assemble(void)
- {
- int16_t Batt_current;
- uint8_t csq=0;
- int8_t snr=0;
- int8_t rsnr=0;
- Batt_current = Uart_Rece_BattI;
- OsaUtcTimeTValue timestracture;
- appGetSystemTimeUtcSync(×tracture);
- battbuffer[0] = timestracture.UTCtimer1>>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;
- 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];//秒
- appGetSignalInfoSync(&csq,&snr,&rsnr);//获取信号质量
- battbuffer[13] = csq;// 网络信号
- battbuffer[14] = 0x00;//故障等级
- battbuffer[15] = 0x00;//故障代码高
- battbuffer[16] = 0x00;//故障代码低
- //电流适应性更改,从int转换到uint,加10000的偏移量,100mA的单位
- if (Batt_current>0x8000)
- {
- Batt_current = Batt_current|0x7fff;
- Batt_current = 0x2710 - Batt_current;
- Batt_current = Batt_current;
- }
- else
- {
- Batt_current = Batt_current+0x2710;
- Batt_current = Batt_current;
- }
- 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++;
- }
- //Tcp线程
- static void Tcp_Task(void* arg)
- {
- CHAR SN[] = "GYTEST00000000003";//SN应写到osfile里面
- CHAR serverip[] = "47.97.127.222";
- CHAR serverport[] = "8712";
- struct addrinfo hints, *server_res;
- int TcpsendID = -1;
- int TcpconnectID = -1;
- memset( &hints, 0, sizeof( hints ) );
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = IPPROTO_TCP;
- psEventQueueHandle = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(eventCallbackMessage_t*));
- int NB_send_len=59+Batt_Cell_Num_2+Batt_Temp_Num;//设定tcp发送的最大数值,以电池数据为上线
- slpManApplyPlatVoteHandle("TcpSlp",&TcpSlpHandler);
- slpManPlatVoteDisableSleep(TcpSlpHandler, SLP_SLP2_STATE);
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_IDLE);
- uint8_t Tcp_Index = 0;
- uint8_t* TcpSendBuffer=NULL;
- volatile bool Tcp_Flag=false;
- eventCallbackMessage_t *queueItem = NULL;
- while(true)
- {
- switch(gProcess_Tcp_Task)
- {
- case PROCESS_TCP_STATE_IDLE:
- {
- osDelay(100);
- break;
- }
- case PROCESS_TCP_STATE_LINK:
- {
- if(TcpconnectID<0)
- {
- if (xQueueReceive(psEventQueueHandle, &queueItem, portMAX_DELAY))
- {
- switch(queueItem->messageId)
- {
- case QMSG_ID_NW_IP_READY:
- {
- if (getaddrinfo( serverip, serverport , &hints, &server_res ) != 0 )
- {
- #ifdef USING_PRINTF
- printf("TCP connect unresolved dns\n");
- #endif
- }
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
- TcpconnectID = connect(sockfd, (struct sockaddr *) server_res->ai_addr, server_res->ai_addrlen);
- if(TcpconnectID<0)
- {
- #ifdef USING_PRINTF
- printf("Connect failed!%d\n",TcpconnectID);
- #endif
- close(sockfd);
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_IDLE);
- break;
- }
- else
- {
- sendQueueMsg(QMSG_ID_SOCK_SENDPKG, 0);
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_WORK);
- }
- break;
- }
- }
- free(queueItem);
- }
- }
- else
- {
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_WORK);
- }
- break;
- }
- case PROCESS_TCP_STATE_WORK:
- {
- Tcp_Flag = false;
- TcpSendBuffer = (uint8_t *)malloc(NB_send_len);
- while (!Tcp_Flag)
- {
- switch(Tcp_Index)
- {
- case 0://发送登录信息
- {
- Tcp_Index=1;
- break;
- }
- case 1://发送电池数据
- {
- memset(TcpSendBuffer,0x00,NB_send_len);
- *(TcpSendBuffer+0) = 0x23;
- *(TcpSendBuffer+1) = 0x23;
- *(TcpSendBuffer+2) = 0x02;
- *(TcpSendBuffer+3) = 0xfe;
- memcpy(TcpSendBuffer+4,SN,17);
- *(TcpSendBuffer+21) = 0x01;//01表示不加密
- Tcp_Batt_Data_Assemble();//数据组装函数
- *(TcpSendBuffer+22) = data_index>>8;//数据长度
- *(TcpSendBuffer+23) = data_index;//数据长度
- memcpy(TcpSendBuffer+24,battbuffer,data_index);
- *(TcpSendBuffer+NB_send_len-1) = bcc_chk(TcpSendBuffer,NB_send_len-1);
- #ifdef USING_PRINTF
- printf("battbuffer:");
- for (int i = 0; i < data_index; i++)
- {
- printf("%x ",battbuffer[i]);
- }
- printf("\n ");
- #endif
- TcpsendID = send(sockfd, TcpSendBuffer, NB_send_len, 0 );
- //发送失败暂时不写
- #ifdef USING_PRINTF
- printf("ConnectID:%d,TcpSend:%d,data length:%d,Data: ",sockfd,TcpsendID,NB_send_len);
- for (int i = 0; i < NB_send_len; i++)
- {
- printf("%x ",*(TcpSendBuffer+i));
- }
- printf("\n ");
- #endif
- Tcp_Index=2;
- break;
- }
- case 2:
- {
- Tcp_Index=3;
- break;
- }
- default:
- {
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_IDLE);
- Tcp_Index = 0;
- Tcp_Flag = true;
- }
- }
- }
- free(TcpSendBuffer);
- break;
- }
- case PROCESS_TCP_STATE_SLEEP:
- {
- slpManPlatVoteEnableSleep(TcpSlpHandler, SLP_SLP2_STATE);
- closesocket(sockfd);
- deregisterPSEventCallback(socketRegisterPSUrcCallback);//注销NB网络事件函数
- while(1)
- {
- osDelay(30000/portTICK_PERIOD_MS);
- }
- }
- }
- }
- }
- //主任务线程初始化
- void Main_Task_Init()
- {
- #ifndef USING_PRINTF
- if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
- {
- HAL_UART_RecvFlowControl(false);
- }
- #endif
- osThreadAttr_t task_attr;
- memset(&task_attr,0,sizeof(task_attr));
- memset(gProcess_Main_TaskStack, 0xA5, PROC_MAIN_TASK_STACK_SIZE);
- task_attr.name = "Main_Task";
- task_attr.stack_mem = gProcess_Main_TaskStack;
- task_attr.stack_size = PROC_MAIN_TASK_STACK_SIZE;
- task_attr.priority = osPriorityNormal;
- task_attr.cb_mem = &gProcess_Main_Task_t;
- task_attr.cb_size = sizeof(StaticTask_t);
- osThreadNew(Main_Task, NULL, &task_attr);
- }
- //Uart读取线程初始化
- void Uart_Task_Init()
- {
- osThreadAttr_t task_attr;
- memset(&task_attr,0,sizeof(task_attr));
- memset(gProcess_Uart_TaskStack, 0xA5, PROC_UART_TASK_STACK_SIZE);
- task_attr.name = "Uart_Task";
- task_attr.stack_mem = gProcess_Uart_TaskStack;
- task_attr.stack_size = PROC_UART_TASK_STACK_SIZE;
- task_attr.priority = osPriorityNormal;
- task_attr.cb_mem = &gProcess_Uart_Task_t;
- task_attr.cb_size = sizeof(StaticTask_t);
- osThreadNew(Uart_Task, NULL, &task_attr);
- }
- //Can线程初始化
- void Can_Task_Init()
- {
- osThreadAttr_t task_attr;
- memset(&task_attr,0,sizeof(task_attr));
- memset(gProcess_Can_TaskStack, 0xA5, PROC_CAN_TASK_STACK_SIZE);
- task_attr.name = "Can_Task";
- task_attr.stack_mem = gProcess_Can_TaskStack;
- task_attr.stack_size = PROC_CAN_TASK_STACK_SIZE;
- task_attr.priority = osPriorityNormal;
- task_attr.cb_mem = &gProcess_Can_Task_t;
- task_attr.cb_size = sizeof(StaticTask_t);
- osThreadNew(Can_Task, NULL, &task_attr);
- }
- //Tcp线程初始化
- void Tcp_Task_Init()
- {
- osThreadAttr_t task_attr;
- registerPSEventCallback(NB_GROUP_ALL_MASK, socketRegisterPSUrcCallback);
- memset(&task_attr,0,sizeof(task_attr));
- memset(gProcess_Tcp_TaskStack, 0xA5, PROC_TCP_TASK_STACK_SIZE);
- task_attr.name = "Tcp_Task";
- task_attr.stack_mem = gProcess_Tcp_TaskStack;
- task_attr.stack_size = PROC_TCP_TASK_STACK_SIZE;
- task_attr.priority = osPriorityNormal;
- task_attr.cb_mem = &gProcess_Tcp_Task_t;
- task_attr.cb_size = sizeof(StaticTask_t);
- osThreadNew(Tcp_Task, NULL, &task_attr);
- }
- void appInit(void *arg)
- {
- Main_Task_Init();
- Uart_Task_Init();
- Can_Task_Init();
- Tcp_Task_Init();
- }
- //主函数入口
- void main_entry(void) {
- BSP_CommonInit();
- osKernelInitialize();
- registerAppEntry(appInit, NULL);
- if (osKernelGetState() == osKernelReady)
- {
- osKernelStart();
- }
- while(1);
- }
|