User_Task.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /*********************************************************************
  2. *
  3. * 文件名: User_task.c
  4. * 功能描述:定时器任务
  5. * 作者: 陈俊超
  6. * 时间:2020-11-20
  7. *
  8. ********************************************************************/
  9. #include "User_task.h"
  10. #include "app_fifo.h"
  11. #include "main.h"
  12. /********************** 变量区 **************************************/
  13. APP_TIMER_DEF(m_MoveCheck_timer);
  14. APP_TIMER_DEF(m_CheckEsbCmd_timer);
  15. APP_TIMER_DEF(m_MilliSecond_timer);
  16. APP_TIMER_DEF(m_TranForStep_timer);
  17. static app_fifo_t m_MainEvent_fifo;
  18. volatile uint8_t SystemTimer_Minutes =0;//分钟计数器
  19. TranforStep_type m_tranforStep={0,0,0,0,false,false,{0}};
  20. ShoesInforMation_type m_shoes_info={0,0,{0}};
  21. Motion_Detect_type m_motion_detect={0,0,Motion_Release,Stop_Mode};
  22. motor_control_type m_motor_control={false,0};
  23. extern volatile bool HardWareTime_10ms_Flag;
  24. extern void process_motion(IMU_DAT_t* p);
  25. IMU_DAT_t m_IMU_DAT_t;
  26. /********************** 函数区 **************************************/
  27. /**********************************************************
  28. * 函数名字:AcquireTempPowerSend
  29. * 函数作用:获取电池电量并且通过ESB发送
  30. * 函数参数: SendTime: 发送次数
  31. * SendInternal_ms: 发送时间间隔
  32. * 函数返回值:无
  33. ***********************************************************/
  34. static void AcquireTempPowerSend(uint8_t SendTime,uint8_t SendInternal_ms)
  35. {
  36. uint8_t buf[100];
  37. uint8_t length=0;
  38. uint8_t Esb_sendTime=0;
  39. m_shoes_info.power=GetBatteryCurrentPersent();
  40. m_shoes_info.inner_temperature=Acquire_nrf_temp();
  41. m_shoes_info.pressure[2]=(m_IMU_DAT_t.h.press&0xff00)>>8;
  42. m_shoes_info.pressure[3]=m_IMU_DAT_t.h.press&0x00ff;
  43. buf[length++]=UPDATE_BASEINFO;
  44. buf[length++]=m_shoes_info.power;
  45. buf[length++]=m_shoes_info.inner_temperature;
  46. buf[length++]=m_shoes_info.pressure[0];
  47. buf[length++]=m_shoes_info.pressure[1];
  48. buf[length++]=m_shoes_info.pressure[2];
  49. buf[length++]=m_shoes_info.pressure[3];
  50. #if DEBUG_EN
  51. //SEGGER_RTT_printf(0,"output power= %d%% ,temperature= %d ,pressure= 0x%x 0x%x 0x%x 0x%x\n",m_shoes_info.power,m_shoes_info.inner_temperature,m_shoes_info.pressure[0],m_shoes_info.pressure[1],m_shoes_info.pressure[2],m_shoes_info.pressure[3]);
  52. #endif
  53. for(Esb_sendTime=0;Esb_sendTime<SendTime;Esb_sendTime++){
  54. send_protocol(DEX_NUM,CMD_UPDATE,buf,length);
  55. if(SendInternal_ms !=0)nrf_delay_ms(SendInternal_ms);
  56. }
  57. }
  58. /**********************************************************
  59. * 函数名字:Led_Pross
  60. * 函数作用:错误灯提示
  61. * 函数参数:void
  62. * 函数返回值:无
  63. ***********************************************************/
  64. static void SensorFailLed_Pross(void)
  65. {
  66. static uint32_t CurrentTime =0,led_R_time =0;
  67. static bool Led_G_flag =false;
  68. if(TIME_GetTicks()-CurrentTime>=1000){
  69. CurrentTime = TIME_GetTicks();
  70. if(0 == m_IMU_DAT_t.h.press){
  71. nrf_gpio_pin_toggle(LED_G);
  72. Led_G_flag =true;
  73. }
  74. else if(Led_G_flag){
  75. nrf_gpio_pin_write(LED_G,1);
  76. Led_G_flag =false;
  77. }
  78. }
  79. if(TIME_GetTicks()-led_R_time>=1200){
  80. led_R_time = TIME_GetTicks();
  81. if(0 == m_IMU_DAT_t.h.acc[2] && (Game_Mode == m_motion_detect.state))
  82. {
  83. nrf_gpio_pin_toggle(LED_R);
  84. }
  85. else nrf_gpio_pin_write(LED_R,1);
  86. }
  87. }
  88. /**********************************************************
  89. * 函数名字:FeedDog_Pross
  90. * 函数作用:喂狗定时任务
  91. * 函数参数:void
  92. * 函数返回值:无
  93. ***********************************************************/
  94. static void FeedDog_Pross(void)
  95. {
  96. static uint32_t CurrentTime =0;
  97. if(TIME_GetTicks()-CurrentTime>=FEED_WATCHDOG_INTERVAL){
  98. CurrentTime = TIME_GetTicks();
  99. User_Feed_watchDog();
  100. }
  101. }
  102. /**********************************************************
  103. * 函数名字:GetBatteryVoltage_Pross
  104. * 函数作用:获取电池电压的定时任务
  105. * 函数参数:void
  106. * 函数返回值:无
  107. ***********************************************************/
  108. static void GetBatteryVoltage_Pross(void)
  109. {
  110. static uint32_t GetBattery_time =0;
  111. if(TIME_GetTicks()-GetBattery_time>=GET_BATTERY_INTERVAL){
  112. GetBattery_time = TIME_GetTicks();
  113. User_SAADC_DisOrEnable(Enable);
  114. GetBatteryVoltage_adc();
  115. User_SAADC_DisOrEnable(DisEnable);
  116. }
  117. }
  118. /**********************************************************
  119. * 函数名字:OneHourSaveStep_To_Flash
  120. * 函数作用:
  121. * 函数参数:无
  122. * 函数返回值:无
  123. ***********************************************************/
  124. static uint8_t SaveStepflag =0;
  125. static void SaveStepToFlash_pross(void)
  126. {
  127. static uint32_t one_time =0;
  128. static uint8_t SaveTime =0;
  129. switch(SaveStepflag){
  130. case 1:
  131. if(Update_StepToflash())SaveStepflag =0;
  132. else {
  133. SaveStepflag =2;
  134. SaveTime =0;
  135. one_time = TIME_GetTicks();
  136. }
  137. break;
  138. case 2:
  139. if(TIME_GetTicks()-one_time >= 200){
  140. one_time = TIME_GetTicks();
  141. if(Update_StepToflash() || SaveTime > 3){
  142. SaveStepflag =0;
  143. }
  144. else SaveTime++;
  145. }
  146. break;
  147. }
  148. }
  149. /**********************************************************
  150. * 函数名字:一分钟定时任务
  151. * 函数作用:获取电池电压的定时任务
  152. * 函数参数:void
  153. * 函数返回值:无
  154. ***********************************************************/
  155. static void OneMinutes_pross(void)
  156. {
  157. static uint32_t one_time =0;
  158. if(TIME_GetTicks()-one_time>=60000){
  159. one_time = TIME_GetTicks();
  160. SystemTimer_Minutes++;
  161. if(SystemTimer_Minutes >= UpdateFlashTimer_INTERVAL){//1小时
  162. SystemTimer_Minutes =0;
  163. TranforMainEvent_Fifo(UpdateStep_Event);
  164. OneHour_Step();
  165. }
  166. }
  167. }
  168. /**
  169. @brief 电量灯指示
  170. @param callinterval_ms:函数调用间隔,单位为ms
  171. */
  172. static void powerled_indicate(uint32_t callinterval_ms)
  173. {
  174. IMU_DAT_t mIMU;
  175. uint16_t power_val = 0;
  176. int16_t acc_z = 0;
  177. static uint8_t powerled_lightcount = 0,resetflag = 0;
  178. static bool ReverseLedFlag = false;
  179. MPU9250_ReadData(mIMU.h.gyr,mIMU.h.acc,mIMU.h.mag,&mIMU.h.temperature);
  180. acc_z = mIMU.h.acc[2];
  181. #if DEBUG_EN
  182. SEGGER_RTT_printf(0,"h_az=%d\n",acc_z);
  183. #endif
  184. //倾斜范围 -3000 ~ 400
  185. if(acc_z >= -3000 && acc_z<=900 &&resetflag){ //-2252 ~ -2058 倾斜
  186. powerled_lightcount = 9000 / callinterval_ms; //亮灯时间:9s
  187. ReverseLedFlag = true;
  188. }
  189. //平躺范围 >= 1800
  190. if(acc_z >= 1800){ //1990-2005 平躺
  191. resetflag = 1;
  192. }
  193. //灯亮
  194. if(powerled_lightcount > 0){
  195. powerled_lightcount--;
  196. power_val = GetBatteryCurrentPersent();
  197. #if DEBUG_EN
  198. SEGGER_RTT_printf(0,"currentPower:%d\n",power_val);
  199. #endif
  200. if(power_val >= 20){ //20%的电量
  201. nrf_gpio_pin_write(LED_G,0);
  202. }
  203. else{
  204. //橙灯亮
  205. nrf_gpio_pin_write(LED_R,0);
  206. nrf_gpio_pin_write(LED_G,0);
  207. }
  208. resetflag = 0;
  209. }
  210. else{
  211. if(!ReverseLedFlag)return;
  212. nrf_gpio_pin_write(LED_R,1);
  213. nrf_gpio_pin_write(LED_G,1);
  214. nrf_gpio_pin_write(LED_B,1);
  215. ReverseLedFlag = false;
  216. }
  217. #if DEBUG_EN
  218. SEGGER_RTT_printf(0,"powerled_lightcount=%d\r,resetflag=%d\n",powerled_lightcount, resetflag);
  219. #endif
  220. }
  221. /**********************************************************
  222. * 函数名字:Battery_led_process
  223. * 函数作用:电池状态灯显示
  224. * 函数参数:无
  225. * 函数返回值:无
  226. ***********************************************************/
  227. void Battery_led_process(void)
  228. {
  229. static uint32_t tim=0;
  230. if(TIME_GetTicks()-tim>=3000){ tim = TIME_GetTicks();
  231. powerled_indicate(3000);
  232. }
  233. }
  234. /**********************************************************
  235. * 函数名字:Battery_led_process
  236. * 函数作用:电池状态灯显示
  237. * 函数参数:无
  238. * 函数返回值:无
  239. ***********************************************************/
  240. void Charge_led_process(void)
  241. {
  242. static uint32_t tim=0;
  243. static uint8_t charge_Flag = 0;
  244. if(TIME_GetTicks()-tim>=1000){
  245. tim = TIME_GetTicks();
  246. #if DEBUG_EN
  247. SEGGER_RTT_printf(0,"led state:%d\n",nrf_gpio_pin_read(8));
  248. #endif
  249. // if(1 == charge_Flag){
  250. // if(1 == nrf_gpio_pin_read(8)){//充满电拔出
  251. // charge_Flag =0;
  252. // nrf_gpio_pin_write(LED_R,1);
  253. // nrf_gpio_pin_write(LED_G,1);
  254. // nrf_gpio_cfg_input(8,NRF_GPIO_PIN_PULLUP);
  255. // }
  256. // }
  257. // else{
  258. if(0 == nrf_gpio_pin_read(8)){
  259. if(GetBatteryCurrentPersent() >=100)
  260. {
  261. nrf_gpio_pin_write(LED_R,1);
  262. nrf_gpio_pin_write(LED_G,0);
  263. //if(charge_Flag !=1)nrf_gpio_cfg_input(8,NRF_GPIO_PIN_NOPULL);
  264. charge_Flag =1;
  265. }
  266. else {
  267. nrf_gpio_pin_write(LED_R,0);
  268. nrf_gpio_pin_write(LED_G,0);
  269. charge_Flag =2;
  270. }
  271. }
  272. else if(charge_Flag != 0){
  273. charge_Flag =0;
  274. nrf_gpio_pin_write(LED_R,1);
  275. nrf_gpio_pin_write(LED_G,1);
  276. nrf_gpio_cfg_input(8,NRF_GPIO_PIN_PULLUP);
  277. }
  278. // }
  279. }
  280. }
  281. /**********************************************************
  282. * 函数名字:TranforMainEvent_Fifo
  283. * 函数作用:传输事件到队列当中
  284. * 函数参数:m_event:需要传输的事件
  285. * 函数返回值:无
  286. ***********************************************************/
  287. void TranforMainEvent_Fifo(MainEvent m_event)
  288. {
  289. uint8_t data=0;
  290. uint32_t length=1,ret_code=0;
  291. data = m_event;
  292. ret_code = app_fifo_write(&m_MainEvent_fifo,&data,&length);
  293. #if DEBUG_EN
  294. if(ret_code != NRF_SUCCESS)SEGGER_RTT_printf(0,"fifo error:%d\n",ret_code);
  295. #endif
  296. }
  297. /**********************************************************
  298. * 函数名字:User_Task_loop
  299. * 函数作用: 循环检测主任务
  300. * 函数参数: 无
  301. * 函数返回值:无
  302. ***********************************************************/
  303. extern volatile bool SetpSendFLag;
  304. void User_Task_loop(void)
  305. {
  306. uint8_t msg_Event;
  307. uint32_t err_code;
  308. static bool Current_Movestate =false;//鞋子当前状态,静止,移动
  309. uint8_t systemtime_temp[8]={0};
  310. #if 0
  311. static uint32_t tim=0;
  312. static uint32_t fps=0;
  313. static uint32_t fps_max=0;
  314. fps = TIME_GetTicks()-fps;
  315. if(fps_max<fps) fps_max = fps;
  316. fps = TIME_GetTicks();
  317. if(TIME_GetTicks()-tim>=1000){
  318. tim = TIME_GetTicks();
  319. #if DEBUG_EN
  320. SEGGER_RTT_printf(0,"main timer=%d\rms\n",fps_max);
  321. #endif
  322. fps_max = 0;
  323. }
  324. #endif
  325. if(HardWareTime_10ms_Flag){
  326. OY_SetValue_False(HardWareTime_10ms_Flag);
  327. //process_motion(&m_IMU_DAT_t);
  328. (void) nrf_esb_flush_tx();
  329. (void) nrf_esb_start_rx();
  330. }
  331. if(SetpSendFLag && m_tranforStep.StartFlag){
  332. User_Esb_Set(Enable);
  333. SendStep_Packet_ToEsb();
  334. nrf_delay_ms(1);
  335. SetpSendFLag =false;
  336. }
  337. FeedDog_Pross();
  338. GetBatteryVoltage_Pross();
  339. OneMinutes_pross();
  340. SaveStepToFlash_pross();
  341. Charge_led_process();
  342. if(m_motion_detect.state != Game_Mode)Battery_led_process();
  343. else SensorFailLed_Pross();
  344. if(app_fifo_get(&m_MainEvent_fifo, &msg_Event) == NRF_SUCCESS)
  345. {
  346. switch(msg_Event)
  347. {
  348. case Move_Event:
  349. if(Current_Movestate)return;
  350. OY_SetValue_True(Current_Movestate);
  351. err_code = app_timer_stop(m_CheckEsbCmd_timer);
  352. APP_ERROR_CHECK(err_code);
  353. err_code = app_timer_start(m_CheckEsbCmd_timer, APP_TIMER_TICKS(300), NULL);
  354. APP_ERROR_CHECK(err_code);
  355. break;
  356. case No_MoveOverTime_Event:
  357. if(!Current_Movestate)return;
  358. OY_SetValue_False(Current_Movestate);
  359. err_code = app_timer_stop(m_CheckEsbCmd_timer);
  360. APP_ERROR_CHECK(err_code);
  361. err_code = app_timer_start(m_CheckEsbCmd_timer, APP_TIMER_TICKS(CheckEsbCmd_INTERVAL), NULL);
  362. APP_ERROR_CHECK(err_code);
  363. break;
  364. case Quit_GameMode_Event:
  365. User_HardwareTime_Set(DisEnable);
  366. User_Esb_Set(Enable);
  367. send_protocol_game(OutGameMode_cmd,2,1);
  368. nrf_gpio_pin_write(LED_RUN,1);
  369. if(Stop_Mode == m_motion_detect.state)return;
  370. #if (MPU_SENSOR == MPU_SENSOR_6050)
  371. MPU6050_sheep();
  372. #else
  373. MPU9250_LowPowerAccelModeInit();
  374. #endif
  375. m_motion_detect.state = Stop_Mode;
  376. User_Esb_Set(DisEnable);
  377. nrf_gpio_pin_write(MT_EN,0);
  378. break;
  379. case Into_GameMode_Event:
  380. User_Esb_Set(Enable);
  381. send_protocol_game(InGameMode_cmd,2,1);
  382. if(Game_Mode == m_motion_detect.state)return;
  383. OY_ClearValue_Zero(m_motion_detect.QuitGameHoldTime);
  384. #if (MPU_SENSOR == MPU_SENSOR_6050)
  385. MPU6050_Init_reg();
  386. #else
  387. MPU9250_init();
  388. #endif
  389. m_motion_detect.state = Game_Mode;
  390. User_HardwareTime_Set(Enable);
  391. break;
  392. case CheckEsbRxData_Event:
  393. User_Esb_Set(Enable);
  394. AcquireTempPowerSend(3,1);
  395. if(!m_tranforStep.StartFlag){
  396. nrf_delay_ms(2);
  397. User_Esb_Set(DisEnable);
  398. }
  399. break;
  400. case UpdateStep_Event:
  401. SaveStepflag = 1;
  402. break;
  403. case Resquest_Step_Event:
  404. if(m_tranforStep.StartFlag){
  405. User_Esb_Set(Enable);
  406. Rsponse_ReqStepCmd(m_tranforStep.Packetlength);
  407. return;
  408. }
  409. memcpy(systemtime_temp, &m_tranforStep.systemtime[0],8);
  410. memset(&m_tranforStep,0,sizeof(TranforStep_type));
  411. memcpy(&m_tranforStep.systemtime[0],systemtime_temp,8);
  412. m_tranforStep.CurrentPacket =0x01;
  413. Calculate_Send_Packet();
  414. User_Esb_Set(Enable);
  415. Rsponse_ReqStepCmd(m_tranforStep.Packetlength);
  416. if(m_tranforStep.Packetlength >=1){//有数据的时候启动定时器发送
  417. OY_SetValue_True(m_tranforStep.StartFlag);
  418. app_timer_stop(m_TranForStep_timer);
  419. err_code = app_timer_start(m_TranForStep_timer, APP_TIMER_TICKS(TranforStep_INTERVAL), NULL);
  420. APP_ERROR_CHECK(err_code);
  421. }
  422. else OY_SetValue_False(m_tranforStep.StartFlag);
  423. break;
  424. case SendStep_Packet_Event:
  425. User_Esb_Set(Enable);
  426. SendStep_Packet_ToEsb();
  427. //User_Esb_Set(DisEnable);
  428. break;
  429. case Stop_SendStep_Packet_Event:
  430. app_timer_stop(m_TranForStep_timer);
  431. APP_ERROR_CHECK(err_code);
  432. OY_SetValue_False(m_tranforStep.StartFlag);
  433. User_Esb_Set(DisEnable);
  434. #if DEBUG_EN
  435. SEGGER_RTT_printf(0,"Stop Send Step\n");
  436. #endif
  437. break;
  438. case EsbError_Event:
  439. #if DEBUG_EN
  440. SEGGER_RTT_printf(0,"Esb send Error Event\n");
  441. #endif
  442. if(m_motion_detect.state == Game_Mode){
  443. m_motion_detect.state = Stop_Mode;
  444. User_Esb_Set(DisEnable);
  445. User_Esb_Set(Enable);
  446. m_motion_detect.state = Game_Mode;
  447. }
  448. else{
  449. User_Esb_Set(DisEnable);
  450. User_Esb_Set(Enable);
  451. }
  452. break;
  453. default:
  454. break;
  455. }
  456. }
  457. }
  458. /**********************************************************
  459. * 函数名字:MoveCheck_handler
  460. * 函数作用:鞋子运动检测,检测气压传感器判断鞋子是否在运动
  461. * 函数参数:p_context:上下文
  462. * 函数返回值:无
  463. ***********************************************************/
  464. static void MoveCheck_handler(void * p_context)
  465. {
  466. m_IMU_DAT_t.h.press = (uint16_t)(ReadPressure()>>8);
  467. ReadPressure_Pre(); //MSE5611下一次读取做准备
  468. if(m_IMU_DAT_t.h.press >MSE5611_PRESS_MAX){
  469. OY_ClearValue_Zero(m_motion_detect.ReleaseHoldTime);
  470. if(Motion_Release == m_motion_detect.Motion_state) {
  471. m_motion_detect.Motion_state =Motion_Press;
  472. if(!m_tranforStep.StartFlag)Add_Step();//步数+1,步数传输过程当中不允许更改步数
  473. }
  474. TranforMainEvent_Fifo(Move_Event);
  475. }
  476. else if(m_IMU_DAT_t.h.press < MSE5611_PRESS_MIN){
  477. m_motion_detect.ReleaseHoldTime++;
  478. if(Game_Mode == m_motion_detect.state){//游戏模式无压力退出
  479. m_motion_detect.QuitGameHoldTime++;
  480. if(m_motion_detect.QuitGameHoldTime > QuitGameMode_Hold_MAX_TIME){
  481. OY_ClearValue_Zero( m_motion_detect.QuitGameHoldTime);
  482. TranforMainEvent_Fifo(Quit_GameMode_Event);
  483. }
  484. }
  485. if(Motion_Press == m_motion_detect.Motion_state)m_motion_detect.Motion_state =Motion_Release;
  486. }
  487. if(m_motion_detect.ReleaseHoldTime > (SHOES_REALSE_MAX_TIME/MoveCheck_INTERVAL)){
  488. TranforMainEvent_Fifo(No_MoveOverTime_Event);
  489. OY_ClearValue_Zero(m_motion_detect.ReleaseHoldTime);
  490. }
  491. }
  492. /**********************************************************
  493. * 函数名字:TIME_GetTicks
  494. * 函数作用:系统滴答计时器
  495. * 函数参数:无
  496. * 函数返回值:无
  497. ***********************************************************/
  498. volatile static uint32_t time_100ms = 0;
  499. uint32_t TIME_GetTicks(void)
  500. {
  501. return time_100ms;
  502. }
  503. /**********************************************************
  504. * 函数名字:MilliSecond_handler
  505. * 函数作用:20ms定时器中断回调
  506. * 函数参数:p_context:上下文
  507. * 函数返回值:无
  508. ***********************************************************/
  509. static void MilliSecond_handler(void * p_context)
  510. {
  511. time_100ms+=100;//电机控制
  512. }
  513. /**********************************************************
  514. * 函数名字:CheckEsbCmd_handler
  515. * 函数作用:主动发送设备信息,并且短暂进入ESB接收状态
  516. * 函数参数:p_context:上下文
  517. * 函数返回值:无
  518. ***********************************************************/
  519. static void CheckEsbCmd_handler(void * p_context)
  520. {
  521. static uint8_t temp =0;
  522. if(Game_Mode == m_motion_detect.state)
  523. {
  524. temp++;
  525. if(temp >=30){
  526. temp = 0;
  527. TranforMainEvent_Fifo(CheckEsbRxData_Event);
  528. }
  529. }
  530. else TranforMainEvent_Fifo(CheckEsbRxData_Event);
  531. }
  532. /**********************************************************
  533. * 函数名字:TranforStep_handler
  534. * 函数作用:传输脚步数据
  535. * 函数参数:p_context:上下文
  536. * 函数返回值:无
  537. ***********************************************************/
  538. static void TranforStep_handler(void * p_context)
  539. {
  540. if(m_tranforStep.NumberTransfers >= TranforStep_MAX_NUMBER){
  541. OY_SetValue_True(m_tranforStep.StopFlag);
  542. }
  543. if(m_tranforStep.StopFlag){//发送超时
  544. TranforMainEvent_Fifo(Stop_SendStep_Packet_Event);
  545. }
  546. else {
  547. TranforMainEvent_Fifo(SendStep_Packet_Event);
  548. m_tranforStep.NumberTransfers++;
  549. }
  550. }
  551. /**********************************************************
  552. * 函数名字:UserTask_init
  553. * 函数作用:用户任务初始化
  554. * 函数参数: 无
  555. * 函数返回值:无
  556. ***********************************************************/
  557. void User_Task_init(void)
  558. {
  559. static uint8_t MainEvent_buff[MAIN_EVENT_BUFF_SIZE];
  560. ret_code_t err_code;
  561. //创建主任务管理队列
  562. err_code = app_fifo_init(&m_MainEvent_fifo, MainEvent_buff, sizeof(MainEvent_buff));
  563. APP_ERROR_CHECK(err_code);
  564. //创建并启动运动检测任务
  565. err_code = app_timer_create(&m_MoveCheck_timer,
  566. APP_TIMER_MODE_REPEATED,
  567. MoveCheck_handler);
  568. APP_ERROR_CHECK(err_code);
  569. err_code = app_timer_start(m_MoveCheck_timer, APP_TIMER_TICKS(MoveCheck_INTERVAL), NULL);
  570. APP_ERROR_CHECK(err_code);
  571. //创建并启动ESB数据检测任务
  572. err_code = app_timer_create(&m_CheckEsbCmd_timer,
  573. APP_TIMER_MODE_REPEATED,
  574. CheckEsbCmd_handler);
  575. APP_ERROR_CHECK(err_code);
  576. err_code = app_timer_start(m_CheckEsbCmd_timer, APP_TIMER_TICKS(CheckEsbCmd_INTERVAL), NULL);
  577. APP_ERROR_CHECK(err_code);
  578. //创建并启动1ms软件定时器
  579. err_code = app_timer_create(&m_MilliSecond_timer,
  580. APP_TIMER_MODE_REPEATED,
  581. MilliSecond_handler);
  582. APP_ERROR_CHECK(err_code);
  583. err_code = app_timer_start(m_MilliSecond_timer, APP_TIMER_TICKS(100), NULL);
  584. APP_ERROR_CHECK(err_code);
  585. //创建脚步传输定时器
  586. err_code = app_timer_create(&m_TranForStep_timer,
  587. APP_TIMER_MODE_REPEATED,
  588. TranforStep_handler);
  589. APP_ERROR_CHECK(err_code);
  590. m_IMU_DAT_t.h.press =0xFFFF;
  591. }