app_1_3.c 22 KB

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