Hal_Wdg.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include "Hal_Wdg.h"
  2. volatile uint8 notificationCount = 0;
  3. void WdgInit(void)
  4. {
  5. /* Initialize the Wdg driver */
  6. Wdg_43_Instance0_Init(&Wdg_Config_0_VS_0);
  7. /* Set the Wdg Trigger Condition in order to periodically service the Wdg */
  8. Wdg_43_Instance0_SetTriggerCondition(5000);
  9. /*Change the Wdg mode of operation */
  10. Wdg_43_Instance0_SetMode(WDGIF_FAST_MODE);
  11. /* Set the Wdg Trigger Condition in order to periodically service the Wdg */
  12. Wdg_43_Instance0_SetTriggerCondition(15000);
  13. }
  14. void WdgDeInit(void)
  15. {
  16. Wdg_43_Instance0_SetMode(WDGIF_OFF_MODE);
  17. }
  18. void Wdg_CallBackNotification1(void)
  19. {
  20. notificationCount = 1U;
  21. }
  22. static void HAL_1msPeriod(void)
  23. {
  24. uint16 cntTmp = 0u;
  25. /* Just for check time overflow or not? */
  26. cntTmp = hal_1ms_TimerCounter + 1u;
  27. if (0u != cntTmp)
  28. {
  29. hal_1ms_TimerCounter++;
  30. }
  31. cntTmp = hal_100ms_TimerCounter + 1u;
  32. if (0u != cntTmp)
  33. {
  34. hal_100ms_TimerCounter++;
  35. }
  36. }
  37. void vTimer1msCallback(TimerHandle_t pxTimer)
  38. {
  39. uint32 ulTimerID;
  40. // Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_ON);
  41. ulTimerID = (uint32)pvTimerGetTimerID(pxTimer);
  42. if(ulTimerID==0)
  43. {
  44. HAL_1msPeriod();
  45. }
  46. // Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  47. }
  48. boolean HAL_Is1msTickTimeout(void)
  49. {
  50. boolean result = FALSE;
  51. if (hal_1ms_TimerCounter)
  52. {
  53. result = TRUE;
  54. hal_1ms_TimerCounter--;
  55. }
  56. return result;
  57. }
  58. boolean HAL_Is100msTickTimeout(void)
  59. {
  60. boolean result = FALSE;
  61. if (hal_100ms_TimerCounter >= 100u)
  62. {
  63. result = TRUE;
  64. hal_100ms_TimerCounter -= 100u;
  65. }
  66. return result;
  67. }
  68. /* Get timer tick cnt for random seed. */
  69. uint32 HAL_GetTimerTickCnt(void)
  70. {
  71. /* This two variables not init before used, because it used for generate random */
  72. uint32 hardwareTimerTickCnt;
  73. uint32 timerTickCnt;
  74. #if 0
  75. /* For S32K1xx get timer counter(LPTIMER), get timer count will trigger the period incorrect. */
  76. hardwareTimerTickCnt = LPTMR_DRV_GetCounterValueByCount(INST_LPTMR1);
  77. #endif
  78. #pragma GCC diagnostic ignored "-Wuninitialized"
  79. timerTickCnt = ((hardwareTimerTickCnt & 0xFFFFu)) | (timerTickCnt << 16u);
  80. return timerTickCnt;
  81. }
  82. void WATCHDOG_HAL_Feed(void)
  83. {
  84. Wdg_43_Instance0_SetTriggerCondition(500);
  85. }
  86. //typedef void (*AppAddr)(void);
  87. void DoResetECUWithWdg(void)
  88. {
  89. IsFeedWdg = FALSE;
  90. Wdg_43_Instance0_SetTriggerCondition(0);
  91. // while(1)
  92. // {
  93. // AppAddr resetHandle = (AppAddr)(0x00);
  94. // (resetHandle)();
  95. // ;
  96. // }
  97. }