AppTaskMain.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * AppTaskMain.c
  3. *
  4. * Created on: 2022年2月22日
  5. * Author: QiXiang_CHENJIE
  6. */
  7. #include "AppTaskMain.h"
  8. #include "hal_fls.h"
  9. static void vTimerCallback(TimerHandle_t pxTimer);
  10. void MainTask(void *pvParameters)
  11. {
  12. (void)pvParameters;
  13. TimerHandle_t monitorTimer;
  14. monitorTimer = xTimerCreate("monitor", 10, pdTRUE, (void *)0, vTimerCallback);
  15. xTimerStart(monitorTimer, 0);
  16. TimerHandle_t monitorTimer1ms;
  17. monitorTimer1ms = xTimerCreate("monitor1ms", 1, pdTRUE, (void *)0, vTimer1msCallback);
  18. xTimerStart(monitorTimer1ms, 0);
  19. sleep_mutex = xSemaphoreCreateBinary();
  20. // HAL_EEP_Read(400, (uint8 *)&BcuSaveDataInfo, sizeof(BcuSaveDataInfo));
  21. // if (*(uint8 *)(eppromAddStart + 400) == 0xff || BcuSaveDataInfo.BcuAppSaveDataInfo.CRC != crc_chk(&(BcuAppSaveDataInfo.CRC)+1,sizeof(BcuAppSaveDataInfo)-1));
  22. // {
  23. // memset(&BcuAppSaveDataInfo,0,sizeof(BcuAppSaveBody));
  24. // BcuAppSaveDataInfo.CRC = crc_chk(&(BcuAppSaveDataInfo.CRC)+1,sizeof(BcuAppSaveDataInfo)-1);
  25. // BcuAppSaveDataInfo.bcuSaveFlg = false;
  26. // HAL_EEP_Write(BCU_SAVE_ADDR, (uint8 *)&BcuAppSaveDataInfo, sizeof(BcuAppSaveDataInfo));
  27. // }
  28. while (1)
  29. {
  30. vTaskDelay(pdMS_TO_TICKS(10));
  31. if (HAL_Is100msTickTimeout())
  32. {
  33. if (IsFeedWdg == TRUE)
  34. {
  35. WATCHDOG_HAL_Feed();
  36. }
  37. }
  38. if (AppConfigInfo.appSaveFlg)
  39. {
  40. AppConfigInfo.appSaveFlg = false;
  41. HAL_EEP_Write(0, (uint8 *)&AppConfigInfo, sizeof(AppConfigInfo));
  42. globalSaveFlag = 0;
  43. }
  44. if(BcuSaveDataInfo.BcuAppSaveDataInfo.bcuSaveFlg)
  45. {
  46. BcuSaveDataInfo.BcuAppSaveDataInfo.bcuSaveFlg = false;
  47. BcuSaveDataInfo.header.crc16 = crc_chk(&(BcuSaveDataInfo.BcuAppSaveDataInfo),sizeof(BcuSaveDataInfo.BcuAppSaveDataInfo));
  48. HAL_EEP_Write(BCU_SAVE_ADDR, (uint8 *)&BcuSaveDataInfo, sizeof(BcuSaveDataInfo));
  49. }
  50. if (Fota_update_flag==1)
  51. {
  52. // 重启前保存数据
  53. AppConfigInfo.appSaveFlg = false;
  54. HAL_EEP_Write(0, (uint8 *)&AppConfigInfo, sizeof(AppConfigInfo));
  55. HAL_EEP_Write(200, (uint8 *)&AppConfigInfo, sizeof(AppConfigInfo));
  56. BcuSaveDataInfo.BcuAppSaveDataInfo.bcuSaveFlg = false;
  57. BcuSaveDataInfo.header.crc16 = crc_chk(&(BcuSaveDataInfo.BcuAppSaveDataInfo),sizeof(BcuSaveDataInfo.BcuAppSaveDataInfo));
  58. HAL_EEP_Write(BCU_SAVE_ADDR, (uint8 *)&BcuSaveDataInfo, sizeof(BcuSaveDataInfo));
  59. SystemSoftwareReset();
  60. }
  61. #ifndef SEGGER_RTT_PRINTF
  62. MCUEnterSleep();
  63. #endif
  64. }
  65. }
  66. static void vTimerCallback(TimerHandle_t pxTimer)
  67. {
  68. uint32 ulTimerID;
  69. ulTimerID = (uint32)pvTimerGetTimerID(pxTimer);
  70. if (ulTimerID == 0)
  71. {
  72. TimerCounter = TimerCounter + 10;
  73. }
  74. }