app.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  1. /****************************************************************************
  2. *
  3. * Copy right: 2020-, Copyrigths of QIXIANG TECH Ltd.
  4. * File name: app.c
  5. * Description: QX app source file
  6. * History: Rev1.0 2020-10-16
  7. * Athuor: chenjie
  8. *
  9. ****************************************************************************/
  10. //include
  11. #include "bsp.h"
  12. #include "bsp_custom.h"
  13. #include "osasys.h"
  14. #include "ostask.h"
  15. #include "queue.h"
  16. #include "ps_event_callback.h"
  17. #include "app.h"
  18. #include "cmisim.h"
  19. #include "cmimm.h"
  20. #include "cmips.h"
  21. #include "sockets.h"
  22. #include "psifevent.h"
  23. #include "ps_lib_api.h"
  24. #include "lwip/netdb.h"
  25. #include <cis_def.h>
  26. #include "debug_log.h"
  27. #include "slpman_ec616.h"
  28. #include "plat_config.h"
  29. //define
  30. // app task static stack and control block
  31. #define PROC0_TASK_STACK_SIZE (512)
  32. #define PROC1_TASK_STACK_SIZE (1024)
  33. #define PROC2_TASK_STACK_SIZE (1024)
  34. #define PROC3_TASK_STACK_SIZE (1536)
  35. //uart def
  36. #define Uart_Send_LEN (8)
  37. #define Uart_Rece_LEN (40)//串口读取的最大数量,40个字节,能满足一次性读取17个单体
  38. #define RTE_UART_RX_IO_MODE RTE_UART1_RX_IO_MODE
  39. //statement variable
  40. extern ARM_DRIVER_USART Driver_USART1;
  41. static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
  42. /** \brief receive timeout flag */
  43. volatile bool isRecvTimeout = false;
  44. /** \brief receive complete flag */
  45. volatile bool isRecvComplete = false;
  46. uint8_t process0SlpHandler = 0x00;
  47. uint8_t process1SlpHandler = 0x01;
  48. uint8_t process2SlpHandler = 0x02;
  49. uint8_t process3SlpHandler = 0x03;
  50. uint8_t deepslpTimerID = 7;
  51. uint8_t Can_Rece_buffer[8];
  52. uint8_t Batt_Cell_Num = 14;//默认数值14、17
  53. uint8_t Batt_Cell_Num_2 ;//默认数值
  54. uint8_t Batt_Temp_Num = 5;//默认数值5、7
  55. int16_t Uart_Rece_BattI=0x0000;
  56. uint8_t battbuffer[100];//电池数据都存在此数组中————电压14,温度5
  57. /**
  58. * 存放规则如下:
  59. * 位置: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
  60. * 数据: 年 月 日 时 分 秒 信息体标志 年 月 日 时 分 秒 网络信号 故障等级 故障代码高 故障代码低
  61. *
  62. * 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
  63. * 电流H 电流L Link电压H Link电压L Pack电压H Pack电压L 开关状态 SOC SOH 均衡状态 单体个数X 单体v1...单体vX 温度个数N 温度1..温度N
  64. * 32+X*2+N 33+X*2+N 34+x*2+N 35 +X*2+N 36+X*2 +N 37+X*2+N
  65. * 电池状态 是否加热 最高单体H 最高单体L 最低单体H 最低单体L
  66. * */
  67. uint16_t data_index = 0x0000;
  68. typedef enum
  69. {
  70. PROCESS_STATE_IDLE = 0,
  71. PROCESS_STATE_WORK,
  72. PROCESS_STATE_SLEEP
  73. }processSM;
  74. typedef enum
  75. {
  76. PROCESS_Uart_STATE_IDLE = 0,
  77. PROCESS_Uart_STATE_WORK,
  78. PROCESS_Uart_STATE_CHECK,
  79. PROCESS_Uart_STATE_SLEEP
  80. }process_Uart;
  81. typedef enum
  82. {
  83. PROCESS_NB_STATE_IDLE = 0,
  84. PROCESS_NB_STATE_WORK,
  85. PROCESS_NB_STATE_CONNECT,
  86. PROCESS_NB_STATE_SLEEP
  87. }process_NB;
  88. static StaticTask_t gProcessTask0;
  89. static UINT8 gProcessTaskStack0[PROC0_TASK_STACK_SIZE];
  90. static StaticTask_t gProcessTask1;
  91. static UINT8 gProcessTaskStack1[PROC1_TASK_STACK_SIZE];
  92. static StaticTask_t gProcessTask2;
  93. static UINT8 gProcessTaskStack2[PROC2_TASK_STACK_SIZE];
  94. static StaticTask_t gProcessTask3;
  95. static UINT8 gProcessTaskStack3[PROC3_TASK_STACK_SIZE];
  96. processSM gProc0State = PROCESS_STATE_IDLE;
  97. process_Uart gProc1State = PROCESS_Uart_STATE_IDLE;
  98. processSM gProc2State = PROCESS_STATE_IDLE;
  99. process_NB gProc3State = PROCESS_NB_STATE_IDLE;
  100. #define PROC_Task_STATE_SWITCH(a) (gProc0State = a) //任务调度切换
  101. #define PROC_Uart_STATE_SWITCH(a) (gProc1State = a) //uart 状态切换
  102. #define PROC_Can_STATE_SWITCH(a) (gProc2State = a) //can 状态切换
  103. #define PROC_NB_STATE_SWITCH(a) (gProc3State = a) //NB状态切换
  104. //-------------------------------------------------------------------------------------------------------------------------------------------------------
  105. static void appBeforeHib(void *pdata, slpManLpState state)
  106. {
  107. uint32_t *p_param = (uint32_t *)pdata;
  108. #ifdef USING_PRINTF
  109. printf("Before Hibernate:%d \n",state);
  110. #endif
  111. ECOMM_TRACE(UNILOG_PLA_APP, appBeforeHib_1, P_SIG, 1, "Before Hibernate = %x",*p_param);
  112. slpManAONIOLatchEn(AonIOLatch_Enable);
  113. }
  114. static void appAfterHib(void *pdata, slpManLpState state)
  115. {
  116. #ifdef USING_PRINTF
  117. printf("Try Hibernate Failed:%d \n",state);
  118. #endif
  119. ECOMM_TRACE(UNILOG_PLA_APP, appAfterHib_1, P_SIG, 0, "Try Hibernate Failed, Interrupt Pending. Only sleep failed this function will excute");
  120. }
  121. static void appBeforeSlp1(void *pdata, slpManLpState state)
  122. {
  123. #ifdef USING_PRINTF
  124. printf("Before Sleep1:%d \n",state);
  125. #endif
  126. ECOMM_TRACE(UNILOG_PLA_APP, appBeforeSlp1_1, P_SIG, 0, "Before Sleep1");
  127. slpManAONIOLatchEn(AonIOLatch_Enable);
  128. }
  129. static void appAfterSlp1(void *pdata, slpManLpState state)
  130. {
  131. #ifdef USING_PRINTF
  132. printf("After Sleep1:%d \n",state);
  133. #endif
  134. PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
  135. ECOMM_TRACE(UNILOG_PLA_APP, appAfterSlp1_1, P_SIG, 0, "After Sleep1, no matter sleep success or not this function will excute");
  136. }
  137. static void appBeforeSlp2(void *pdata, slpManLpState state)
  138. {
  139. #ifdef USING_PRINTF
  140. printf("before sleep2:%d \n",state);
  141. #endif
  142. ECOMM_TRACE(UNILOG_PLA_APP, appBeforeSlp2_1, P_SIG, 0, "Before Sleep2");
  143. slpManAONIOLatchEn(AonIOLatch_Enable);
  144. }
  145. static void appAfterSlp2(void *pdata, slpManLpState state)
  146. {
  147. #ifdef USING_PRINTF
  148. printf("sleep2 failed:%d \n",state);
  149. #endif
  150. ECOMM_TRACE(UNILOG_PLA_APP, appAfterSlp2_1, P_SIG, 0, "Sleep2 Failed, Interrupt Pending. Only sleep failed this function will excute");
  151. }
  152. unsigned int crc_chk(uint8_t* data, uint8_t length)
  153. {
  154. int j;
  155. uint16_t reg_crc=0xFFFF;
  156. while(length--)
  157. {
  158. reg_crc ^= *data++;
  159. for(j=0;j<8;j++)
  160. {
  161. if(reg_crc & 0x01)
  162. {
  163. reg_crc=(reg_crc>>1) ^ 0xA001;
  164. }
  165. else
  166. {
  167. reg_crc=reg_crc >>1;
  168. }
  169. }
  170. }
  171. return reg_crc;
  172. }
  173. uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t *Uart_Rece_buffer)
  174. {
  175. uint16_t CRC_Rece_buffer;
  176. uint16_t CRC_chk_buffer;
  177. uint8_t Uart_Send_buffer[8];
  178. uint8_t Rece_Data_Len;
  179. Uart_Send_buffer[0] = Uart_Receive_Msg.Bms_Address;
  180. Uart_Send_buffer[1] = Uart_Receive_Msg.Bms_Read_Funcode;
  181. Uart_Send_buffer[2] = Uart_Receive_Msg.Reg_Begin_H;
  182. Uart_Send_buffer[3] = Uart_Receive_Msg.Reg_Begin_L;
  183. Uart_Send_buffer[4] = Uart_Receive_Msg.Reg_Num_H;
  184. Uart_Send_buffer[5] = Uart_Receive_Msg.Reg_Num_L;
  185. CRC_chk_buffer = crc_chk(Uart_Send_buffer,6);
  186. Uart_Send_buffer[6] = CRC_chk_buffer;
  187. Uart_Send_buffer[7] = CRC_chk_buffer>>8;
  188. uint32_t timeout=0;
  189. USARTdrv->Send(Uart_Send_buffer,8);
  190. Rece_Data_Len = Uart_Receive_Msg.Reg_Num_L<<1;//读取几个寄存器的值,数据长度乘以二
  191. USARTdrv->Receive(Uart_Rece_buffer,Rece_Data_Len+5);
  192. while((isRecvTimeout == false) && (isRecvComplete == false))// 未收到数据不叫时间超时,收到数据但是不全叫时间超时
  193. {
  194. timeout++;
  195. if (timeout>7000000)
  196. {
  197. timeout =0;
  198. isRecvTimeout = true;
  199. break;
  200. }
  201. }
  202. if (isRecvComplete == true)
  203. {
  204. Rece_Data_Len = *(Uart_Rece_buffer+2);
  205. isRecvComplete = false;
  206. CRC_Rece_buffer =*(Uart_Rece_buffer+Rece_Data_Len+4)<<8|*(Uart_Rece_buffer+Rece_Data_Len+3);
  207. CRC_chk_buffer = crc_chk(Uart_Rece_buffer,Rece_Data_Len+3);
  208. // #ifdef USING_PRINTF
  209. // // printf("Uart_Send_buffer: ");
  210. // // for(int i=0;i<8;i++)
  211. // // {
  212. // // printf("%x ",Uart_Send_buffer[i]);
  213. // // }
  214. // // printf("\n");
  215. // printf("Uart_Rece_buffer: ");
  216. // for(int i=0;i<Rece_Data_Len+5;i++)
  217. // {
  218. // printf("%x ",*(Uart_Rece_buffer+i));
  219. // }
  220. // printf("crcchk:%x,%x ",CRC_chk_buffer,CRC_Rece_buffer);
  221. // #endif
  222. if (CRC_Rece_buffer == CRC_chk_buffer)//满足校验
  223. {
  224. return Uart_Rece_buffer+3;
  225. }
  226. else //接收数据的校验不过屏蔽
  227. {
  228. memset(Uart_Rece_buffer,0xff,Rece_Data_Len+5);
  229. return Uart_Rece_buffer+3;
  230. }
  231. }
  232. if (isRecvTimeout == true)//没收到数据,全部为空值
  233. {
  234. memset(Uart_Rece_buffer,0x00,Rece_Data_Len+5);
  235. isRecvTimeout = false;
  236. osDelay(1000);
  237. return Uart_Rece_buffer;
  238. }
  239. return Uart_Rece_buffer;
  240. }
  241. void USART_callback(uint32_t event)
  242. {
  243. if(event & ARM_USART_EVENT_RX_TIMEOUT)
  244. {
  245. isRecvTimeout = true;
  246. }
  247. if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
  248. {
  249. isRecvComplete = true;
  250. }
  251. }
  252. static void process0AppTask(void* arg)//任务调度程序
  253. {
  254. UINT16 Can_index = 0;
  255. UINT16 Uart_index = 0;
  256. UINT16 NB_index = 0;
  257. uint32_t sleep_index = 0;
  258. int32_t inParam = 0xAABBCCDD;
  259. PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
  260. NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
  261. NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
  262. NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
  263. NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
  264. FaultDisplay(LED_TURN_OFF);
  265. NVIC_EnableIRQ(PadWakeup1_IRQn);
  266. slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
  267. slpManApplyPlatVoteHandle("pro0",&process0SlpHandler);
  268. slpManPlatVoteDisableSleep(process0SlpHandler, SLP_SLP2_STATE);
  269. slpManRegisterUsrdefinedBackupCb(appBeforeHib,&inParam,SLPMAN_HIBERNATE_STATE);
  270. slpManRegisterUsrdefinedRestoreCb(appAfterHib,NULL,SLPMAN_HIBERNATE_STATE);
  271. slpManRegisterUsrdefinedBackupCb(appBeforeSlp1,NULL,SLPMAN_SLEEP1_STATE);
  272. slpManRegisterUsrdefinedRestoreCb(appAfterSlp1,NULL,SLPMAN_SLEEP1_STATE);
  273. slpManRegisterUsrdefinedBackupCb(appBeforeSlp2,NULL,SLPMAN_SLEEP2_STATE);
  274. slpManRegisterUsrdefinedRestoreCb(appAfterSlp2,NULL,SLPMAN_SLEEP2_STATE);
  275. slpManSlpState_t slpstate = slpManGetLastSlpState();
  276. #ifdef USING_PRINTF
  277. printf("slpstate:%d \n",slpstate);
  278. #endif
  279. if((slpstate == SLP_SLP2_STATE) || (slpstate == SLP_HIB_STATE))
  280. {
  281. PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
  282. }
  283. else
  284. {
  285. PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
  286. }
  287. while(1)
  288. {
  289. switch(gProc0State)
  290. {
  291. case PROCESS_STATE_IDLE:
  292. {
  293. #ifdef USING_PRINTF
  294. printf("wake up 5s \n");
  295. #endif
  296. PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_CHECK);
  297. NetSocDisplay(LED_SOC_0,LED_TURN_ON);
  298. osDelay(100/portTICK_PERIOD_MS);//delay 100ms
  299. if(Uart_Rece_BattI!=0x0000)
  300. {
  301. PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
  302. }
  303. sleep_index++;
  304. if(sleep_index>=50)
  305. {
  306. NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
  307. sleep_index=0;
  308. PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
  309. }
  310. break;
  311. }
  312. case PROCESS_STATE_WORK:
  313. {
  314. osDelay(10/portTICK_PERIOD_MS);//10ms
  315. Can_index++;
  316. Uart_index++;
  317. NB_index++;
  318. if (Uart_index >10)//Uart 100ms 调用一次
  319. {
  320. PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_WORK);
  321. Uart_index = 0;
  322. }
  323. if (Can_index >=100)//Can 1000ms 调用一次
  324. {
  325. PROC_Can_STATE_SWITCH(PROCESS_STATE_WORK);
  326. Can_index = 0;
  327. }
  328. if (NB_index >=1000)//NB 10s 调用一次
  329. {
  330. PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_CONNECT);
  331. NB_index = 0;
  332. }
  333. if((Uart_Rece_BattI==0x0000)&&(Can_Rece_buffer[0]!=0x01))
  334. {
  335. sleep_index++;
  336. }
  337. else
  338. {
  339. sleep_index = 0;
  340. }
  341. if (sleep_index >=6000)
  342. {
  343. PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
  344. sleep_index = 0;
  345. #ifdef USING_PRINTF
  346. printf("sleep_index:%d,Current:%x,CAN:%x \n",sleep_index,Uart_Rece_BattI,Can_Rece_buffer[0]);
  347. #endif
  348. }
  349. break;
  350. }
  351. case PROCESS_STATE_SLEEP:
  352. {
  353. slpManSlpState_t State;
  354. uint8_t cnt;
  355. PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_SLEEP);
  356. PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_SLEEP);
  357. PROC_Can_STATE_SWITCH(PROCESS_STATE_SLEEP);
  358. osDelay(1000/portTICK_PERIOD_MS);
  359. #if 1
  360. if(slpManCheckVoteState(process0SlpHandler, &State, &cnt)==RET_TRUE)
  361. {
  362. #ifdef USING_PRINTF
  363. printf("[%d]We Can Check Vote State, state=%d, cnt=%d\r\n",__LINE__,State,cnt);
  364. #endif
  365. }
  366. //slpManPlatVoteEnableSleep(process0SlpHandler, SLP_SLP2_STATE); // cancel the prohibition of sleep2
  367. slpManPlatVoteEnableSleep(process0SlpHandler, SLP_SLP2_STATE);
  368. if(slpManCheckVoteState(process0SlpHandler, &State, &cnt)==RET_TRUE)
  369. {
  370. #ifdef USING_PRINTF
  371. printf("[%d]We Can Check Vote State Again, state=%d, cnt=%d\r\n",__LINE__,State,cnt);
  372. #endif
  373. }
  374. #ifdef USING_PRINTF
  375. printf("[%d]Waiting sleep\r\n",__LINE__);
  376. #endif
  377. #endif
  378. FaultDisplay(LED_TURN_ON);
  379. slpManDeepSlpTimerStart(deepslpTimerID,60000);
  380. while(1);
  381. }
  382. }
  383. }
  384. }
  385. static void process1AppTask(void* arg)
  386. {
  387. USARTdrv->Initialize(USART_callback);
  388. USARTdrv->PowerControl(ARM_POWER_FULL);
  389. USARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS |
  390. ARM_USART_DATA_BITS_8 |
  391. ARM_USART_PARITY_NONE |
  392. ARM_USART_STOP_BITS_1 |
  393. ARM_USART_FLOW_CONTROL_NONE, 9600);
  394. int Rece_index = 0;
  395. uint8_t *Uart_Reve_Point = NULL;
  396. Uart_Receive_Type Uart_Receive_Msg;
  397. PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
  398. slpManApplyPlatVoteHandle("pro1",&process1SlpHandler);
  399. slpManPlatVoteDisableSleep(process1SlpHandler, SLP_SLP2_STATE);
  400. Uart_Receive_Msg.Bms_Address = 0x01;
  401. Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
  402. uint8_t *Uart_Rece_buffer;
  403. Batt_Cell_Num_2 = Batt_Cell_Num<<1;
  404. Uart_Rece_buffer = (uint8_t *)malloc(Uart_Rece_LEN);
  405. while(1)
  406. {
  407. switch(gProc1State)
  408. {
  409. case PROCESS_Uart_STATE_IDLE:
  410. {
  411. NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
  412. Rece_index = 0;
  413. break;
  414. }
  415. case PROCESS_Uart_STATE_CHECK://检查电流数值
  416. {
  417. memset(Uart_Rece_buffer,0x00,8);
  418. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  419. Uart_Receive_Msg.Reg_Begin_L= 0x02+Batt_Cell_Num;
  420. Uart_Receive_Msg.Reg_Num_H = 0x00;
  421. Uart_Receive_Msg.Reg_Num_L = 0x01;
  422. Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
  423. Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 |*(Uart_Reve_Point+1);
  424. #ifdef USING_PRINTF
  425. printf("Check_Current!\n");
  426. #endif
  427. PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
  428. break;
  429. }
  430. case PROCESS_Uart_STATE_WORK:
  431. {
  432. NetSocDisplay(LED_SOC_1,LED_TURN_ON);
  433. memset(Uart_Rece_buffer,0xff,Uart_Rece_LEN);
  434. switch(Rece_index)
  435. {
  436. case 0://读取电流
  437. {
  438. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  439. Uart_Receive_Msg.Reg_Begin_L= 0x02+Batt_Cell_Num;
  440. Uart_Receive_Msg.Reg_Num_H = 0x00;
  441. Uart_Receive_Msg.Reg_Num_L = 0x01;
  442. Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
  443. Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 |*(Uart_Reve_Point+1);
  444. break;
  445. }
  446. case 1://读取单体电压
  447. {
  448. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  449. Uart_Receive_Msg.Reg_Begin_L = 0x02;
  450. Uart_Receive_Msg.Reg_Num_H = Batt_Cell_Num>>8;
  451. Uart_Receive_Msg.Reg_Num_L = Batt_Cell_Num;
  452. Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
  453. // #ifdef USING_PRINTF
  454. // printf("BattCellV: ");
  455. // for (size_t i = 0; i < Batt_Cell_Num_2; i++)
  456. // {
  457. // printf("%x ",*(Uart_Reve_Point+i));
  458. // }
  459. // printf("\n");
  460. // #endif
  461. battbuffer[30] = Batt_Cell_Num;
  462. memcpy(&battbuffer[31],Uart_Reve_Point,Batt_Cell_Num_2);
  463. break;
  464. }
  465. case 2://读取温度
  466. {
  467. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  468. Uart_Receive_Msg.Reg_Begin_L = 0x06+Batt_Cell_Num;
  469. Uart_Receive_Msg.Reg_Num_H = Batt_Temp_Num>>8;
  470. Uart_Receive_Msg.Reg_Num_L = Batt_Temp_Num;
  471. Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
  472. battbuffer[31+Batt_Cell_Num_2] = Batt_Temp_Num;
  473. for (int i = 0; i < Batt_Temp_Num; i++)
  474. {
  475. battbuffer[32+Batt_Cell_Num_2+i] = *(Uart_Reve_Point+2*i+1);
  476. }
  477. // #ifdef USING_PRINTF
  478. // printf("BattCellT: ");
  479. // for (size_t i = 0; i < Batt_Temp_Num; i++)
  480. // {
  481. // printf("%x ",*(Uart_Reve_Point+2*i+1));
  482. // }
  483. // printf("\n");
  484. // #endif
  485. break;
  486. }
  487. case 3://读取总电压,目前保护板只有一个电压
  488. {
  489. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  490. Uart_Receive_Msg.Reg_Begin_L = 0x18+Batt_Cell_Num+Batt_Temp_Num;
  491. Uart_Receive_Msg.Reg_Num_H = 0x00;
  492. Uart_Receive_Msg.Reg_Num_L = 0x01;
  493. Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
  494. battbuffer[19] = *(Uart_Reve_Point+0);//Link U
  495. battbuffer[20] = *(Uart_Reve_Point+1);
  496. battbuffer[21] = *(Uart_Reve_Point+0);//Pack U
  497. battbuffer[22] = *(Uart_Reve_Point+1);
  498. break;
  499. }
  500. case 4://读取状态及SOC
  501. {
  502. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  503. Uart_Receive_Msg.Reg_Begin_L = 0x09+Batt_Cell_Num+Batt_Temp_Num;
  504. Uart_Receive_Msg.Reg_Num_H = 0x00;
  505. Uart_Receive_Msg.Reg_Num_L = 0x04;
  506. Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
  507. battbuffer[23] = *(Uart_Reve_Point+0)>>1;//mos状态
  508. battbuffer[24] = *(Uart_Reve_Point+5);//SOC
  509. battbuffer[25] = *(Uart_Reve_Point+7);//SOH
  510. break;
  511. }
  512. case 5://读取均衡状态
  513. {
  514. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  515. Uart_Receive_Msg.Reg_Begin_L = 0x06+Batt_Cell_Num+Batt_Temp_Num;
  516. Uart_Receive_Msg.Reg_Num_H = 0x00;
  517. Uart_Receive_Msg.Reg_Num_L = 0x02;
  518. Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
  519. memcpy(&battbuffer[26],Uart_Reve_Point,4);
  520. break;
  521. }
  522. case 6:
  523. {
  524. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  525. Uart_Receive_Msg.Reg_Begin_L = 0x19+Batt_Cell_Num+Batt_Temp_Num;
  526. Uart_Receive_Msg.Reg_Num_H = 0x00;
  527. Uart_Receive_Msg.Reg_Num_L = 0x02;
  528. Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
  529. memcpy(&battbuffer[34+Batt_Cell_Num_2+Batt_Temp_Num],Uart_Reve_Point,4);
  530. break;
  531. }
  532. default:
  533. {
  534. PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
  535. break;
  536. }
  537. }
  538. Rece_index++;
  539. break;
  540. }
  541. case PROCESS_Uart_STATE_SLEEP:
  542. {
  543. free(Uart_Rece_buffer);
  544. slpManPlatVoteEnableSleep(process1SlpHandler, SLP_SLP2_STATE);
  545. while (1)
  546. {
  547. ;
  548. }
  549. break;
  550. }
  551. }
  552. }
  553. }
  554. static void process2AppTask(void* arg)
  555. {
  556. PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
  557. uint32_t Can_ID;
  558. NVIC_EnableIRQ(PadWakeup1_IRQn);
  559. Can_InitType param;
  560. Can_TxMsgType Can_TxMsg;
  561. param.baudrate = CAN_500Kbps;
  562. param.mode = REQOP_NORMAL;
  563. param.TxStdIDH = 0x00;
  564. param.TxStdIDL = 0x00;
  565. param.RxStdIDH[0] = 0x00;
  566. param.RxStdIDL[0] = 0x00;
  567. /*stdid 0000 0000 001x*/
  568. param.RxStdIDH[1] = 0x00;
  569. param.RxStdIDL[1] = 0x20;
  570. /*stdid 0000 0000 010x */
  571. param.RxStdIDH[2] = 0x00;
  572. param.RxStdIDL[2] = 0x40;
  573. /*stdid 0000 0000 011x*/
  574. param.RxStdIDH[3] = 0x00;
  575. param.RxStdIDL[3] =0x60;
  576. /*stdid 0000 0000 100x */
  577. param.RxStdIDH[4] = 0x00;
  578. param.RxStdIDL[4] = 0x80;
  579. /*stdid 0000 0000 101x*/
  580. param.RxStdIDH[5] = 0x00;
  581. param.RxStdIDL[5] =0xa0;
  582. param.packType = STD_PACK;
  583. HAL_Can_Init(param);
  584. int send_index = 0;
  585. uint16_t Batt_Cell_addU = 0x0000;
  586. Can_Rece_buffer[0]=0xff;
  587. slpManApplyPlatVoteHandle("pro2",&process2SlpHandler);
  588. slpManPlatVoteDisableSleep(process2SlpHandler, SLP_SLP2_STATE);
  589. while(1)
  590. {
  591. switch(gProc2State)
  592. {
  593. case PROCESS_STATE_IDLE:
  594. {
  595. HAL_Can_Receive(Can_Rece_buffer);
  596. osDelay(10);
  597. send_index = 0;
  598. break;
  599. }
  600. case PROCESS_STATE_WORK:
  601. {
  602. switch(send_index)
  603. {
  604. case 0:
  605. {
  606. Can_ID = 0x001;
  607. for (int i = 0; i < 8; i++)
  608. {
  609. Can_TxMsg.Data[i] = battbuffer[i+31+send_index*8];
  610. }
  611. Can_TxMsg.stdIDH = Can_ID>>3;
  612. Can_TxMsg.stdIDL = Can_ID<<5;
  613. Can_TxMsg.DLC = 8;
  614. HAL_Can_Transmit(Can_TxMsg);
  615. break;
  616. }
  617. case 1:
  618. {
  619. Can_ID = 0x011;
  620. for (int i = 0; i < 8; i++)
  621. {
  622. Can_TxMsg.Data[i] = battbuffer[i+31+send_index*8];
  623. }
  624. Can_TxMsg.stdIDH = Can_ID>>3;
  625. Can_TxMsg.stdIDL = Can_ID<<5;
  626. Can_TxMsg.DLC = 8;
  627. HAL_Can_Transmit(Can_TxMsg);
  628. break;
  629. }
  630. case 2:
  631. {
  632. Can_ID = 0x020;
  633. for (int i = 0; i < 8; i++)
  634. {
  635. Can_TxMsg.Data[i] = battbuffer[i+31+send_index*8];
  636. }
  637. Can_TxMsg.stdIDH = Can_ID>>3;
  638. Can_TxMsg.stdIDL = Can_ID<<5;
  639. Can_TxMsg.DLC = 8;
  640. HAL_Can_Transmit(Can_TxMsg);
  641. break;
  642. }
  643. case 3:
  644. {
  645. Can_ID = 0x031;
  646. for (int i = 0; i < 4; i++)
  647. {
  648. Can_TxMsg.Data[i] = battbuffer[i+31+send_index*8];
  649. }
  650. Can_TxMsg.Data[4] = 0x00;
  651. Can_TxMsg.Data[5] = 0x00;
  652. Can_TxMsg.Data[6] = 0x00;
  653. Can_TxMsg.Data[7] = 0x00;
  654. Can_TxMsg.stdIDH = Can_ID>>3;
  655. Can_TxMsg.stdIDL = Can_ID<<5;
  656. Can_TxMsg.DLC = 8;
  657. HAL_Can_Transmit(Can_TxMsg);
  658. break;
  659. }
  660. case 4:
  661. {
  662. Can_ID = 0x101;
  663. for (int i = 0; i < Batt_Temp_Num; i++)
  664. {
  665. Can_TxMsg.Data[i] = battbuffer[i+32+Batt_Cell_Num_2];
  666. }
  667. Can_TxMsg.stdIDH = Can_ID>>3;
  668. Can_TxMsg.stdIDL = Can_ID<<5;
  669. Can_TxMsg.DLC = 8;
  670. HAL_Can_Transmit(Can_TxMsg);
  671. break;
  672. }
  673. case 5:
  674. {
  675. Batt_Cell_addU = 0x0000;
  676. for (int i = 0; i < Batt_Cell_Num; i++)
  677. {
  678. Batt_Cell_addU = Batt_Cell_addU + (battbuffer[31+i*2]<<8|battbuffer[31+i*2+1]);
  679. }
  680. Can_ID = 0x201;
  681. Can_TxMsg.Data[0] = battbuffer[19];
  682. Can_TxMsg.Data[1] = battbuffer[20];
  683. Can_TxMsg.Data[2] = battbuffer[21];
  684. Can_TxMsg.Data[3] = battbuffer[22];//外电压
  685. Can_TxMsg.Data[4] = Batt_Cell_addU>>8;
  686. Can_TxMsg.Data[5] = Batt_Cell_addU;//累加电压
  687. Can_TxMsg.Data[6] = Uart_Rece_BattI>>8;
  688. Can_TxMsg.Data[7] = Uart_Rece_BattI;
  689. Can_TxMsg.stdIDH = Can_ID>>3;
  690. Can_TxMsg.stdIDL = Can_ID<<5;
  691. Can_TxMsg.DLC = 8;
  692. HAL_Can_Transmit(Can_TxMsg);
  693. break;
  694. }
  695. case 6:
  696. {
  697. Can_ID = 0x211;
  698. Can_TxMsg.Data[0] = battbuffer[34+Batt_Cell_Num_2+Batt_Temp_Num];
  699. Can_TxMsg.Data[1] = battbuffer[35+Batt_Cell_Num_2+Batt_Temp_Num];
  700. Can_TxMsg.Data[2] = battbuffer[36+Batt_Cell_Num_2+Batt_Temp_Num];
  701. Can_TxMsg.Data[3] = battbuffer[37+Batt_Cell_Num_2+Batt_Temp_Num];
  702. Can_TxMsg.Data[4] = 0x00;
  703. Can_TxMsg.Data[5] = 0x00;
  704. Can_TxMsg.Data[6] = battbuffer[24];
  705. Can_TxMsg.Data[7] = Batt_Temp_Num<<4|0;
  706. Can_TxMsg.stdIDH = Can_ID>>3;
  707. Can_TxMsg.stdIDL = Can_ID<<5;
  708. Can_TxMsg.DLC = 8;
  709. HAL_Can_Transmit(Can_TxMsg);
  710. break;
  711. }
  712. case 7:
  713. {
  714. Can_ID = 0x221;
  715. Can_TxMsg.Data[0] = battbuffer[25];//SOH
  716. Can_TxMsg.Data[1] = 0x00;
  717. Can_TxMsg.Data[2] = 0x00;
  718. Can_TxMsg.Data[3] = 0x00;
  719. Can_TxMsg.Data[4] = 0x00;
  720. Can_TxMsg.Data[5] = 0x00;
  721. Can_TxMsg.Data[6] = 0x00;
  722. Can_TxMsg.Data[7] = 0x00;
  723. Can_TxMsg.stdIDH = Can_ID>>3;
  724. Can_TxMsg.stdIDL = Can_ID<<5;
  725. Can_TxMsg.DLC = 8;
  726. HAL_Can_Transmit(Can_TxMsg);
  727. break;
  728. }
  729. default:
  730. {
  731. PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
  732. }
  733. }
  734. send_index ++;
  735. break;
  736. }
  737. case PROCESS_STATE_SLEEP:
  738. {
  739. slpManPlatVoteEnableSleep(process2SlpHandler, SLP_SLP2_STATE);
  740. while (1)
  741. {
  742. ;
  743. }
  744. break;
  745. }
  746. }
  747. }
  748. }
  749. uint8_t bcc_chk(uint8_t* data, uint8_t length)
  750. {
  751. uint8_t bcc_chk_return = 0x00;
  752. uint8_t count = 0;
  753. while (count<length)
  754. {
  755. bcc_chk_return^=data[count];
  756. count++;
  757. }
  758. return bcc_chk_return;
  759. }
  760. void TcpCallBack(void)
  761. {
  762. #ifdef USING_PRINTF
  763. printf("[%d]TcpCallBack\n",__LINE__);
  764. #endif
  765. }
  766. void Tcp_Data_Assemble(uint8_t datatype)
  767. {
  768. int16_t Batt_current;
  769. uint8_t csq=0;
  770. int8_t snr=0;
  771. int8_t rsnr=0;
  772. Batt_current = Uart_Rece_BattI;
  773. OsaUtcTimeTValue timestracture;
  774. appGetSystemTimeUtcSync(&timestracture);
  775. battbuffer[0] = timestracture.UTCtimer1>>16;
  776. battbuffer[0] = battbuffer[0] - 0x07D0;
  777. battbuffer[1] = timestracture.UTCtimer1>>8;
  778. battbuffer[2] = timestracture.UTCtimer1;
  779. battbuffer[3] = timestracture.UTCtimer2>>24;
  780. battbuffer[4] = timestracture.UTCtimer2>>16;
  781. battbuffer[5] = timestracture.UTCtimer2>>8;
  782. switch (datatype)
  783. {
  784. case 0x80:
  785. {
  786. battbuffer[6] = 0x80;//信息体标志,此处为电池信息
  787. battbuffer[7] = battbuffer[0];//年
  788. battbuffer[8] = battbuffer[1];//月
  789. battbuffer[9] = battbuffer[2];//日
  790. battbuffer[10] = battbuffer[3];//时 0时区时间
  791. battbuffer[11] = battbuffer[4];//分
  792. battbuffer[12] = battbuffer[5];//秒
  793. appGetSignalInfoSync(&csq,&snr,&rsnr);//获取信号质量
  794. battbuffer[13] = csq;// 网络信号
  795. battbuffer[14] = 0x00;//故障等级
  796. battbuffer[15] = 0x00;//故障代码高
  797. battbuffer[16] = 0x00;//故障代码低
  798. //电流适应性更改,从int转换到uint,加1000的偏移量,100mA的单位
  799. if (Batt_current>0x8000)
  800. {
  801. Batt_current = Batt_current|0x7fff;
  802. Batt_current = 0x2710 - Batt_current;
  803. Batt_current = Batt_current;
  804. }
  805. else
  806. {
  807. Batt_current = Batt_current+0x2710;
  808. Batt_current = Batt_current;
  809. }
  810. battbuffer[17] = Batt_current>>8;
  811. battbuffer[18] = Batt_current;
  812. data_index = 32+Batt_Cell_Num_2+Batt_Temp_Num;
  813. battbuffer[data_index] = 0x00;//电池状态
  814. data_index++;
  815. battbuffer[data_index] = 0x00;//是否加热
  816. data_index++;
  817. break;
  818. }
  819. default:
  820. break;
  821. }
  822. return;
  823. }
  824. void GGACallBack(UINT8 res, UINT8 * params)
  825. {
  826. #ifdef USING_PRINTF
  827. printf("GPSCallBack,len:%d,GPS:%s\n",res,params);
  828. #endif
  829. }
  830. static void process3AppTask(void* arg)
  831. {
  832. CHAR SN[] = "GYTEST00000000003";
  833. CHAR serverip[] = "47.97.127.222";
  834. UINT16 serverport = 8712;
  835. int TcpConnectID = -1;
  836. int TcpSendID = -1;
  837. int NB_send_len=59+Batt_Cell_Num_2+Batt_Temp_Num;//设定网络发送最大数值
  838. slpManApplyPlatVoteHandle("pro3",&process3SlpHandler);
  839. slpManPlatVoteDisableSleep(process3SlpHandler, SLP_SLP2_STATE);
  840. PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_IDLE);
  841. uint8_t* TcpSendBuffer;
  842. TcpSendBuffer = (uint8_t *)malloc(NB_send_len);//申请发送的数据内存
  843. while(1)
  844. {
  845. switch(gProc3State)
  846. {
  847. case PROCESS_NB_STATE_IDLE:
  848. {
  849. osDelay(100);
  850. break;
  851. }
  852. case PROCESS_NB_STATE_CONNECT:
  853. {
  854. while(TcpConnectID<0)
  855. {
  856. TcpConnectID = tcpipConnectionCreate(1,PNULL,PNULL,serverip,serverport,TcpCallBack);
  857. osDelay(100);
  858. #ifdef USING_PRINTF
  859. printf("ConnectID:%d\n ",TcpConnectID);
  860. #endif
  861. }
  862. PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_WORK);
  863. break;
  864. }
  865. case PROCESS_NB_STATE_WORK:
  866. {
  867. posGGAServiceStart(GGACallBack);
  868. memset(TcpSendBuffer,0x00,92);
  869. *(TcpSendBuffer+0) = 0x23;
  870. *(TcpSendBuffer+1) = 0x23;
  871. *(TcpSendBuffer+2) = 0x02;
  872. *(TcpSendBuffer+3) = 0xfe;
  873. memcpy(TcpSendBuffer+4,SN,17);
  874. *(TcpSendBuffer+21) = 0x01;//不加密
  875. Tcp_Data_Assemble(0x80);
  876. *(TcpSendBuffer+22) = data_index>>8;//数据长度
  877. *(TcpSendBuffer+23) = data_index;//数据长度
  878. memcpy(TcpSendBuffer+24,battbuffer,data_index);
  879. #ifdef USING_PRINTF
  880. printf("battbuffer:");
  881. for (int i = 0; i < data_index; i++)
  882. {
  883. printf("%x ",battbuffer[i]);
  884. }
  885. printf("\n ");
  886. #endif
  887. *(TcpSendBuffer+NB_send_len-1) = bcc_chk(TcpSendBuffer,NB_send_len-1);
  888. // #ifdef USING_PRINTF
  889. // printf("[%d]sizeof:%d \r\n",__LINE__,sizeof(TcpSendBuffer)-1);
  890. // #endif
  891. // #ifdef USING_PRINTF
  892. // printf("[%d]Tcpchk:%#X \r\n",__LINE__,*(TcpSendBuffer+91));
  893. // #endif
  894. TcpSendID = tcpipConnectionSend(TcpConnectID,TcpSendBuffer,NB_send_len,PNULL,PNULL,PNULL);
  895. // #ifdef USING_PRINTF
  896. // printf("ConnectID:%d,TcpSend:%d,data length:%d,Data: ",TcpConnectID,TcpSendID,NB_send_len);
  897. // for (int i = 0; i < NB_send_len; i++)
  898. // {
  899. // printf("%x ",*(TcpSendBuffer+i));
  900. // }
  901. // printf("\n ");
  902. // #endif
  903. PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_IDLE);
  904. break;
  905. }
  906. case PROCESS_NB_STATE_SLEEP:
  907. {
  908. tcpipConnectionClose(TcpConnectID);
  909. posGGAServiceStop();
  910. free(TcpSendBuffer);
  911. slpManPlatVoteEnableSleep(process3SlpHandler, SLP_SLP2_STATE); // cancel the prohibition of sleep2
  912. while(1);
  913. break;
  914. }
  915. }
  916. }
  917. }
  918. /**
  919. \fn process0Init(void)
  920. \brief process0Init function.
  921. \return
  922. */
  923. void process0Init(void)
  924. {
  925. osThreadAttr_t task_attr;
  926. #ifndef USING_PRINTF
  927. if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
  928. {
  929. HAL_UART_RecvFlowControl(false);
  930. }
  931. #endif
  932. memset(&task_attr,0,sizeof(task_attr));
  933. memset(gProcessTaskStack0, 0xA5,PROC0_TASK_STACK_SIZE);
  934. task_attr.name = "Process0AppTask";
  935. task_attr.stack_mem = gProcessTaskStack0;
  936. task_attr.stack_size = PROC0_TASK_STACK_SIZE;
  937. task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
  938. task_attr.cb_mem = &gProcessTask0;//task control block
  939. task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
  940. osThreadNew(process0AppTask, NULL, &task_attr);
  941. }
  942. /**
  943. \fn process1Init(void)
  944. \brief process1Init function.
  945. \return
  946. */
  947. void process1Init(void)
  948. {
  949. osThreadAttr_t task_attr;
  950. #ifndef USING_PRINTF
  951. if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
  952. {
  953. HAL_UART_RecvFlowControl(false);
  954. }
  955. #endif
  956. memset(&task_attr,0,sizeof(task_attr));
  957. memset(gProcessTaskStack1, 0xA5,PROC1_TASK_STACK_SIZE);
  958. task_attr.name = "Process1AppTask";
  959. task_attr.stack_mem = gProcessTaskStack1;
  960. task_attr.stack_size = PROC1_TASK_STACK_SIZE;
  961. task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
  962. task_attr.cb_mem = &gProcessTask1;//task control block
  963. task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
  964. osThreadNew(process1AppTask, NULL, &task_attr);
  965. }
  966. /**
  967. \fn process2Init(void)
  968. \brief process2Init function.
  969. \return
  970. */
  971. void process2Init(void)
  972. {
  973. osThreadAttr_t task_attr;
  974. memset(&task_attr,0,sizeof(task_attr));
  975. memset(gProcessTaskStack2, 0xA5,PROC2_TASK_STACK_SIZE);
  976. task_attr.name = "Process2AppTask";
  977. task_attr.stack_mem = gProcessTaskStack2;
  978. task_attr.stack_size = PROC2_TASK_STACK_SIZE;
  979. task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
  980. task_attr.cb_mem = &gProcessTask2;//task control block
  981. task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
  982. osThreadNew(process2AppTask, NULL, &task_attr);
  983. }
  984. void process3Init(void)
  985. {
  986. osThreadAttr_t task_attr;
  987. memset(&task_attr,0,sizeof(task_attr));
  988. memset(gProcessTaskStack3, 0xA5,PROC3_TASK_STACK_SIZE);
  989. task_attr.name = "Process3AppTask";
  990. task_attr.stack_mem = gProcessTaskStack3;
  991. task_attr.stack_size = PROC3_TASK_STACK_SIZE;
  992. task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
  993. task_attr.cb_mem = &gProcessTask3;//task control block
  994. task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
  995. osThreadNew(process3AppTask, NULL, &task_attr);
  996. }
  997. /**
  998. \fn appInit(void)
  999. \brief appInit function.
  1000. \return
  1001. */
  1002. void appInit(void *arg)
  1003. {
  1004. process0Init();//任务调度和检测程序
  1005. process1Init();//Uart程序
  1006. process2Init();//Can程序
  1007. process3Init();//NB程序
  1008. }
  1009. /**
  1010. \fn int main_entry(void)
  1011. \brief main entry function.
  1012. \return
  1013. */
  1014. void main_entry(void) {
  1015. BSP_CommonInit();
  1016. osKernelInitialize();
  1017. registerAppEntry(appInit, NULL);
  1018. if (osKernelGetState() == osKernelReady)
  1019. {
  1020. osKernelStart();
  1021. }
  1022. while(1);
  1023. }