user_upgrade.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "user_upgrade.h"
  2. #include "peripheral.h"
  3. #include "ota.h"
  4. #include "led.h"
  5. static tmosTaskID user_upgrade_task_id = INVALID_TASK_ID;
  6. static bool ota_timeout_check = false;
  7. static uint16_t ota_timeout_delay_count = 60;
  8. static void user_upgrade_time_pro(void)
  9. {
  10. if(ota_timeout_check == true)
  11. {
  12. if(ota_timeout_delay_count > 0)
  13. {
  14. ota_timeout_delay_count--;
  15. if(ota_timeout_delay_count == 1)
  16. {
  17. Set_User_Upgrade_Queue(USER_UPGRADE_QUEUE_ENTER_APP);
  18. }
  19. }
  20. }
  21. }
  22. void Set_User_Upgrade_Queue(USER_UPGRADE_QUEUE_TYPE type)
  23. {
  24. bStatus_t stat = tmos_start_task(user_upgrade_task_id, (1 << type), MS1_TO_SYSTEM_TIME(10));
  25. }
  26. //task的event处理回调函数,需要在注册task时候,传进去
  27. static uint16_t user_upgrade_task_process_event(uint8_t task_id, uint16_t events)
  28. {
  29. //event 处理
  30. if(events & (1 << USER_UPGRADE_QUEUE_TIME))
  31. {
  32. user_upgrade_time_pro();
  33. return (events ^ (1 << USER_UPGRADE_QUEUE_TIME)); //异或的方式清除该事件运行标志,并返回未运行的事件标志
  34. }
  35. //event 处理
  36. if(events & (1 << USER_UPGRADE_QUEUE_ENTER_APP))
  37. {
  38. /* Close all the current use interrupt, or it is convenient to directly close */
  39. __disable_irq();
  40. PRINT("ota timeout jump App \n");
  41. Delay_Ms(10);
  42. app_start();
  43. return (events ^ (1 << USER_UPGRADE_QUEUE_ENTER_APP)); //异或的方式清除该事件运行标志,并返回未运行的事件标志
  44. }
  45. return 0;
  46. }
  47. void ota_timeout_task_start(bool stat)
  48. {
  49. ota_timeout_check = stat;
  50. ota_timeout_delay_count = 30;
  51. }
  52. void user_upgrade_start(void)
  53. {
  54. user_upgrade_task_id = TMOS_ProcessEventRegister(user_upgrade_task_process_event);
  55. bStatus_t stat = tmos_start_reload_task(user_upgrade_task_id, (1 << USER_UPGRADE_QUEUE_TIME), MS1_TO_SYSTEM_TIME(1000));
  56. }