app_1_0_1.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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 PROC_TASK_STACK_SIZE (1024)
  32. //uart def
  33. #define Uart_Send_LEN (8)
  34. #define Uart_Rece_LEN (16)
  35. #define RTE_UART_RX_IO_MODE RTE_UART1_RX_IO_MODE
  36. //statement variable
  37. extern ARM_DRIVER_USART Driver_USART1;
  38. static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
  39. /** \brief usart receive buffer */
  40. uint8_t Uart_Data_buffer[8];
  41. /** \brief usart send buffer */
  42. /** \brief receive timeout flag */
  43. volatile bool isRecvTimeout = false;
  44. /** \brief receive complete flag */
  45. volatile bool isRecvComplete = false;
  46. uint8_t process0SlpHandler = 0xff;
  47. uint8_t process1SlpHandler = 0xff;
  48. uint8_t process2SlpHandler = 0xff;
  49. /** \brief 电压传输 */
  50. uint8_t Uart_Rece_BattCellU1_U4[8];
  51. uint8_t Uart_Rece_BattCellU5_U8[8];
  52. uint8_t Uart_Rece_BattCellU9_U12[8];
  53. uint8_t Uart_Rece_BattCellU13_U14[8];
  54. uint8_t Uart_Rece_BattT[8];
  55. int16_t Uart_Rece_BattI;
  56. uint8_t Uart_Rece_Batt_states[6];
  57. uint16_t Uart_Rece_BattU;
  58. uint16_t Uart_Rece_Batt_MaxcellU;
  59. uint16_t Uart_Rece_Batt_MincellU;
  60. uint8_t Can_Rece_buffer[16];
  61. typedef enum
  62. {
  63. PROCESS1_STATE_IDLE = 0,
  64. PROCESS1_STATE_WORK,
  65. PROCESS1_STATE_SLEEP
  66. }process1SM;
  67. typedef enum
  68. {
  69. PROCESS2_STATE_IDLE = 0,
  70. PROCESS2_STATE_WORK,
  71. PROCESS2_STATE_SLEEP
  72. }process2SM;
  73. static StaticTask_t gProcessTask0;
  74. static UINT8 gProcessTaskStack0[PROC_TASK_STACK_SIZE];
  75. static StaticTask_t gProcessTask1;
  76. static UINT8 gProcessTaskStack1[PROC_TASK_STACK_SIZE];
  77. static StaticTask_t gProcessTask2;
  78. static UINT8 gProcessTaskStack2[PROC_TASK_STACK_SIZE];
  79. process1SM gProc1State = PROCESS1_STATE_IDLE;
  80. process2SM gProc2State = PROCESS2_STATE_IDLE;
  81. #define PROC1_STATE_SWITCH(a) (gProc1State = a)
  82. #define PROC2_STATE_SWITCH(a) (gProc2State = a)
  83. unsigned int crc_chk(uint8_t* data, uint8_t length)
  84. {
  85. int j;
  86. uint16_t reg_crc=0xFFFF;
  87. while(length--)
  88. {
  89. reg_crc ^= *data++;
  90. for(j=0;j<8;j++)
  91. {
  92. if(reg_crc & 0x01)
  93. {
  94. reg_crc=(reg_crc>>1) ^ 0xA001;
  95. }
  96. else
  97. {
  98. reg_crc=reg_crc >>1;
  99. }
  100. }
  101. }
  102. return reg_crc;
  103. }
  104. uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg)
  105. {
  106. uint8_t Uart_Rece_buffer[Uart_Rece_LEN];
  107. uint16_t CRC_Reve_buffer;
  108. uint16_t CRC_chk_buffer;
  109. uint8_t Uart_Send_buffer[8];
  110. uint8_t Rece_Data_Len;
  111. Uart_Send_buffer[0] = Uart_Receive_Msg.Bms_Address;
  112. Uart_Send_buffer[1] = Uart_Receive_Msg.Bms_Read_Funcode;
  113. Uart_Send_buffer[2] = Uart_Receive_Msg.Reg_Begin_H;
  114. Uart_Send_buffer[3] = Uart_Receive_Msg.Reg_Begin_L;
  115. Uart_Send_buffer[4] = Uart_Receive_Msg.Reg_Num_H;
  116. Uart_Send_buffer[5] = Uart_Receive_Msg.Reg_Num_L;
  117. CRC_chk_buffer = crc_chk(Uart_Send_buffer,6);
  118. Uart_Send_buffer[6] = CRC_chk_buffer;
  119. Uart_Send_buffer[7] = CRC_chk_buffer>>8;
  120. Uart_Rece_buffer[0]=0xfe;
  121. uint32_t timeout=0;
  122. USARTdrv->Send(Uart_Send_buffer,8);
  123. USARTdrv->Receive(Uart_Rece_buffer,13);
  124. Rece_Data_Len = 11;
  125. while((isRecvTimeout == false) && (isRecvComplete == false))// 未收到数据不叫时间超时,收到数据但是不全叫时间超时
  126. {
  127. timeout++;
  128. if (timeout>7000000)
  129. {
  130. timeout =0;
  131. isRecvTimeout = true;
  132. break;
  133. }
  134. }
  135. if (isRecvComplete == true)
  136. {
  137. isRecvComplete = false;
  138. CRC_chk_buffer =Uart_Rece_buffer[12]<<8|Uart_Rece_buffer[11];
  139. CRC_Reve_buffer = crc_chk(Uart_Rece_buffer,11);
  140. if (CRC_Reve_buffer == CRC_chk_buffer)//满足校验
  141. {
  142. for (uint8_t i = 0; i < 8; i++)
  143. {
  144. Uart_Data_buffer[i]=Uart_Rece_buffer[i+3];
  145. }
  146. return Uart_Data_buffer;
  147. }
  148. else //接收数据的校验不过暂时屏蔽
  149. {
  150. for (uint8_t i = 0; i < 8; i++)
  151. {
  152. Uart_Data_buffer[i]=0xff;
  153. }
  154. return Uart_Data_buffer;
  155. }
  156. }
  157. if (isRecvTimeout == true)//没收到数据,全部为空值
  158. {
  159. Uart_Data_buffer[0] = 0x00;
  160. Uart_Data_buffer[1] = 0x00;
  161. Uart_Data_buffer[2] = 0x00;
  162. Uart_Data_buffer[3] = 0x00;
  163. Uart_Data_buffer[4] = 0x00;
  164. Uart_Data_buffer[5] = 0x00;
  165. Uart_Data_buffer[6] = 0x00;
  166. Uart_Data_buffer[7] = 0xff;
  167. isRecvTimeout = false;
  168. osDelay(1000);
  169. return Uart_Data_buffer;
  170. }
  171. }
  172. void USART_callback(uint32_t event)
  173. {
  174. if(event & ARM_USART_EVENT_RX_TIMEOUT)
  175. {
  176. isRecvTimeout = true;
  177. }
  178. if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
  179. {
  180. isRecvComplete = true;
  181. }
  182. }
  183. static void process0AppTask(void* arg)
  184. {
  185. uint32_t inParam = 0xAABBCCDD;
  186. uint32_t cnt;
  187. slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
  188. slpManApplyPlatVoteHandle("process0slp",&process0SlpHandler);
  189. slpManSlpState_t slpstate = slpManGetLastSlpState();
  190. UINT8 Can_index = 0;
  191. UINT8 Uart_index = 0;
  192. while(1)
  193. {
  194. osDelay(10);//10ms
  195. Can_index++;
  196. Uart_index++;
  197. if (Uart_index >10)//Uart 100ms 调用一次
  198. {
  199. PROC2_STATE_SWITCH(PROCESS2_STATE_WORK);
  200. Uart_index = 0;
  201. }
  202. if (Can_index >=100)//Can 100ms 调用一次
  203. {
  204. PROC1_STATE_SWITCH(PROCESS1_STATE_WORK);
  205. Can_index = 0;
  206. }
  207. }
  208. }
  209. static void process1AppTask(void* arg)
  210. {
  211. PROC1_STATE_SWITCH(PROCESS1_STATE_IDLE);
  212. uint32_t Can_ID;
  213. NVIC_EnableIRQ(PadWakeup1_IRQn);
  214. Can_InitType param;
  215. Can_TxMsgType Can_TxMsg;
  216. param.baudrate = CAN_500Kbps;
  217. param.mode = REQOP_NORMAL;
  218. param.TxStdIDH = 0x00;
  219. param.TxStdIDL = 0x00;
  220. param.RxStdIDH[0] = 0x00;
  221. param.RxStdIDL[0] = 0x00;
  222. /*stdid 0000 0000 001x*/
  223. param.RxStdIDH[1] = 0x00;
  224. param.RxStdIDL[1] = 0x20;
  225. /*stdid 0000 0000 010x */
  226. param.RxStdIDH[2] = 0x00;
  227. param.RxStdIDL[2] = 0x40;
  228. /*stdid 0000 0000 011x*/
  229. param.RxStdIDH[3] = 0x00;
  230. param.RxStdIDL[3] =0x60;
  231. /*stdid 0000 0000 100x */
  232. param.RxStdIDH[4] = 0x00;
  233. param.RxStdIDL[4] = 0x80;
  234. /*stdid 0000 0000 101x*/
  235. param.RxStdIDH[5] = 0x00;
  236. param.RxStdIDL[5] =0xa0;
  237. param.packType = STD_PACK;
  238. HAL_Can_Init(param);
  239. int send_index = 0;
  240. while(1)
  241. {
  242. switch(gProc1State)
  243. {
  244. case PROCESS1_STATE_IDLE:
  245. {
  246. HAL_Can_Receive(Can_Rece_buffer);
  247. send_index = 0;
  248. FaultDisplay(LED_TURN_OFF);
  249. break;
  250. }
  251. case PROCESS1_STATE_WORK:
  252. {
  253. switch(send_index)
  254. {
  255. case 0:
  256. {
  257. Can_ID = 0x001;
  258. for (int i = 0; i < 8; i++)
  259. {
  260. Can_TxMsg.Data[i] = Uart_Rece_BattCellU1_U4[i];
  261. }
  262. Can_TxMsg.stdIDH = Can_ID>>3;
  263. Can_TxMsg.stdIDL = Can_ID<<5;
  264. Can_TxMsg.DLC = 8;
  265. HAL_Can_Transmit(Can_TxMsg);
  266. break;
  267. }
  268. case 1:
  269. {
  270. Can_ID = 0x012;
  271. for (int i = 0; i < 8; i++)
  272. {
  273. Can_TxMsg.Data[i] = Uart_Rece_BattCellU5_U8[i];
  274. }
  275. Can_TxMsg.stdIDH = Can_ID>>3;
  276. Can_TxMsg.stdIDL = Can_ID<<5;
  277. Can_TxMsg.DLC = 8;
  278. HAL_Can_Transmit(Can_TxMsg);
  279. break;
  280. }
  281. case 2:
  282. {
  283. Can_ID = 0x021;
  284. for (int i = 0; i < 8; i++)
  285. {
  286. Can_TxMsg.Data[i] = Uart_Rece_BattCellU9_U12[i];
  287. }
  288. Can_TxMsg.stdIDH = Can_ID>>3;
  289. Can_TxMsg.stdIDL = Can_ID<<5;
  290. Can_TxMsg.DLC = 8;
  291. HAL_Can_Transmit(Can_TxMsg);
  292. break;
  293. }
  294. case 3:
  295. {
  296. Can_ID = 0x031;
  297. for (int i = 0; i < 4; i++)
  298. {
  299. Can_TxMsg.Data[i] = Uart_Rece_BattCellU13_U14[i];
  300. }
  301. Can_TxMsg.Data[4] = 0x00;
  302. Can_TxMsg.Data[5] = 0x00;
  303. Can_TxMsg.Data[6] = 0x00;
  304. Can_TxMsg.Data[7] = 0x00;
  305. Can_TxMsg.stdIDH = Can_ID>>3;
  306. Can_TxMsg.stdIDL = Can_ID<<5;
  307. Can_TxMsg.DLC = 8;
  308. HAL_Can_Transmit(Can_TxMsg);
  309. break;
  310. }
  311. case 4:
  312. {
  313. Can_ID = 0x101;
  314. for (int i = 0; i < 4; i++)
  315. {
  316. Can_TxMsg.Data[i] = Uart_Rece_BattT[i*2+1];
  317. }
  318. Can_TxMsg.stdIDH = Can_ID>>3;
  319. Can_TxMsg.stdIDL = Can_ID<<5;
  320. Can_TxMsg.DLC = 8;
  321. HAL_Can_Transmit(Can_TxMsg);
  322. break;
  323. }
  324. case 5:
  325. {
  326. Can_ID = 0x201;
  327. Can_TxMsg.Data[0] = Uart_Rece_BattU>>8;
  328. Can_TxMsg.Data[1] = Uart_Rece_BattU;
  329. Can_TxMsg.Data[2] = 0x00;
  330. Can_TxMsg.Data[3] = 0x00;//外电压
  331. Can_TxMsg.Data[4] = 0x00;
  332. Can_TxMsg.Data[5] = 0x00;//累加电压
  333. Can_TxMsg.Data[6] = Uart_Rece_BattI>>8;
  334. Can_TxMsg.Data[7] = Uart_Rece_BattI;
  335. Can_TxMsg.stdIDH = Can_ID>>3;
  336. Can_TxMsg.stdIDL = Can_ID<<5;
  337. Can_TxMsg.DLC = 8;
  338. HAL_Can_Transmit(Can_TxMsg);
  339. break;
  340. }
  341. default:
  342. {
  343. PROC1_STATE_SWITCH(PROCESS1_STATE_IDLE);
  344. }
  345. }
  346. send_index ++;
  347. FaultDisplay(LED_TURN_ON);
  348. break;
  349. }
  350. case PROCESS1_STATE_SLEEP:
  351. {
  352. break;
  353. }
  354. }
  355. }
  356. }
  357. static void process2AppTask(void* arg)
  358. {
  359. USARTdrv->Initialize(USART_callback);
  360. USARTdrv->PowerControl(ARM_POWER_FULL);
  361. USARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS |
  362. ARM_USART_DATA_BITS_8 |
  363. ARM_USART_PARITY_NONE |
  364. ARM_USART_STOP_BITS_1 |
  365. ARM_USART_FLOW_CONTROL_NONE, 9600);
  366. int Rece_index = 0;
  367. uint8_t *Uart_Reve_Point = NULL;
  368. Uart_Receive_Type Uart_Receive_Msg;
  369. PROC2_STATE_SWITCH(PROCESS2_STATE_IDLE);
  370. while(1)
  371. {
  372. switch(gProc2State)
  373. {
  374. case PROCESS2_STATE_IDLE:
  375. {
  376. Rece_index = 0;
  377. NetSocDisplay(3,LED_TURN_OFF);
  378. break;
  379. }
  380. case PROCESS2_STATE_WORK:
  381. {
  382. Uart_Receive_Msg.Bms_Address = 0x01;
  383. Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
  384. switch(Rece_index)
  385. {
  386. case 0://读取电压1-4
  387. {
  388. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  389. Uart_Receive_Msg.Reg_Begin_L = 0x02;
  390. Uart_Receive_Msg.Reg_Num_H = 0x00;
  391. Uart_Receive_Msg.Reg_Num_L = 0x04;
  392. Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
  393. for(int i =0;i<8;i++)
  394. {
  395. Uart_Rece_BattCellU1_U4[i] = *(Uart_Reve_Point+i);
  396. }
  397. break;
  398. }
  399. case 1://读取电压5-8
  400. {
  401. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  402. Uart_Receive_Msg.Reg_Begin_L= 0x06;
  403. Uart_Receive_Msg.Reg_Num_H = 0x00;
  404. Uart_Receive_Msg.Reg_Num_L = 0x04;
  405. Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
  406. for(int i =0;i<8;i++)
  407. {
  408. Uart_Rece_BattCellU5_U8[i] = *(Uart_Reve_Point+i);
  409. }
  410. break;
  411. }
  412. case 2:
  413. {
  414. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  415. Uart_Receive_Msg.Reg_Begin_L= 0x0A;
  416. Uart_Receive_Msg.Reg_Num_H = 0x00;
  417. Uart_Receive_Msg.Reg_Num_L = 0x04;
  418. Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
  419. for(int i =0;i<8;i++)
  420. {
  421. Uart_Rece_BattCellU9_U12[i] = *(Uart_Reve_Point+i);
  422. }
  423. break;
  424. }
  425. case 3:
  426. {
  427. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  428. Uart_Receive_Msg.Reg_Begin_L= 0x0E;
  429. Uart_Receive_Msg.Reg_Num_H = 0x00;
  430. Uart_Receive_Msg.Reg_Num_L = 0x04;
  431. Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
  432. for(int i =0;i<8;i++)
  433. {
  434. Uart_Rece_BattCellU13_U14[i] = *(Uart_Reve_Point+i);
  435. }
  436. break;
  437. }
  438. case 4:
  439. {
  440. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  441. Uart_Receive_Msg.Reg_Begin_L= 0x14;
  442. Uart_Receive_Msg.Reg_Num_H = 0x00;
  443. Uart_Receive_Msg.Reg_Num_L = 0x04;
  444. Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
  445. for(int i =0;i<8;i++)
  446. {
  447. Uart_Rece_BattT[i] = *(Uart_Reve_Point+i);
  448. }
  449. break;
  450. }
  451. case 5:
  452. {
  453. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  454. Uart_Receive_Msg.Reg_Begin_L= 0x10;
  455. Uart_Receive_Msg.Reg_Num_H = 0x00;
  456. Uart_Receive_Msg.Reg_Num_L = 0x04;
  457. Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
  458. Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
  459. for (int i = 0; i < 6; i++)
  460. {
  461. Uart_Rece_Batt_states[i] = *(Uart_Reve_Point+2+i);
  462. }
  463. break;
  464. }
  465. case 6:
  466. {
  467. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  468. Uart_Receive_Msg.Reg_Begin_L= 0x2B;
  469. Uart_Receive_Msg.Reg_Num_H = 0x00;
  470. Uart_Receive_Msg.Reg_Num_L = 0x04;
  471. Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
  472. Uart_Rece_BattU = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
  473. Uart_Rece_Batt_MaxcellU = *(Uart_Reve_Point+2)<<8 | *(Uart_Reve_Point+3);
  474. Uart_Rece_Batt_MincellU = *(Uart_Reve_Point+4)<<8 | *(Uart_Reve_Point+5);
  475. break;
  476. }
  477. case 7:
  478. {
  479. USARTdrv->Send(Can_Rece_buffer,16);
  480. }
  481. default:
  482. {
  483. PROC2_STATE_SWITCH(PROCESS2_STATE_IDLE);
  484. break;
  485. }
  486. }
  487. Rece_index++;
  488. NetSocDisplay(3,LED_TURN_ON);
  489. break;
  490. }
  491. case PROCESS2_STATE_SLEEP:
  492. {
  493. //此处写休眠程序
  494. break;
  495. }
  496. }
  497. }
  498. }
  499. /**
  500. \fn process0Init(void)
  501. \brief process0Init function.
  502. \return
  503. */
  504. void process0Init(void)
  505. {
  506. osThreadAttr_t task_attr;
  507. #ifndef USING_PRINTF
  508. if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
  509. {
  510. HAL_UART_RecvFlowControl(false);
  511. }
  512. #endif
  513. memset(&task_attr,0,sizeof(task_attr));
  514. memset(gProcessTaskStack0, 0xA5,PROC_TASK_STACK_SIZE);
  515. task_attr.name = "Process0AppTask";
  516. task_attr.stack_mem = gProcessTaskStack0;
  517. task_attr.stack_size = PROC_TASK_STACK_SIZE;
  518. task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
  519. task_attr.cb_mem = &gProcessTask0;//task control block
  520. task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
  521. osThreadNew(process0AppTask, NULL, &task_attr);
  522. }
  523. /**
  524. \fn process1Init(void)
  525. \brief process1Init function.
  526. \return
  527. */
  528. void process1Init(void)
  529. {
  530. osThreadAttr_t task_attr;
  531. #ifndef USING_PRINTF
  532. if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
  533. {
  534. HAL_UART_RecvFlowControl(false);
  535. }
  536. #endif
  537. memset(&task_attr,0,sizeof(task_attr));
  538. memset(gProcessTaskStack1, 0xA5,PROC_TASK_STACK_SIZE);
  539. task_attr.name = "Process1AppTask";
  540. task_attr.stack_mem = gProcessTaskStack1;
  541. task_attr.stack_size = PROC_TASK_STACK_SIZE;
  542. task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
  543. task_attr.cb_mem = &gProcessTask1;//task control block
  544. task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
  545. osThreadNew(process1AppTask, NULL, &task_attr);
  546. }
  547. /**
  548. \fn process2Init(void)
  549. \brief process2Init function.
  550. \return
  551. */
  552. void process2Init(void)
  553. {
  554. osThreadAttr_t task_attr;
  555. memset(&task_attr,0,sizeof(task_attr));
  556. memset(gProcessTaskStack2, 0xA5,PROC_TASK_STACK_SIZE);
  557. task_attr.name = "Process2AppTask";
  558. task_attr.stack_mem = gProcessTaskStack2;
  559. task_attr.stack_size = PROC_TASK_STACK_SIZE;
  560. task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
  561. task_attr.cb_mem = &gProcessTask2;//task control block
  562. task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
  563. osThreadNew(process2AppTask, NULL, &task_attr);
  564. }
  565. /**
  566. \fn appInit(void)
  567. \brief appInit function.
  568. \return
  569. */
  570. void appInit(void *arg)
  571. {
  572. process0Init();
  573. process1Init();
  574. process2Init();
  575. }
  576. /**
  577. \fn int main_entry(void)
  578. \brief main entry function.
  579. \return
  580. */
  581. void main_entry(void) {
  582. BSP_CommonInit();
  583. osKernelInitialize();
  584. registerAppEntry(appInit, NULL);
  585. if (osKernelGetState() == osKernelReady)
  586. {
  587. osKernelStart();
  588. }
  589. while(1);
  590. }