Hal_Wdg.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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(5000);
  13. }
  14. void Wdg_CallBackNotification1(void)
  15. {
  16. notificationCount = 1U;
  17. }
  18. static void HAL_1msPeriod(void)
  19. {
  20. uint16 cntTmp = 0u;
  21. /* Just for check time overflow or not? */
  22. cntTmp = hal_1ms_TimerCounter + 1u;
  23. if (0u != cntTmp)
  24. {
  25. hal_1ms_TimerCounter++;
  26. }
  27. cntTmp = hal_100ms_TimerCounter + 1u;
  28. if (0u != cntTmp)
  29. {
  30. hal_100ms_TimerCounter++;
  31. }
  32. }
  33. void vTimer1msCallback(TimerHandle_t pxTimer)
  34. {
  35. uint32 ulTimerID;
  36. // Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_ON);
  37. ulTimerID = (uint32)pvTimerGetTimerID(pxTimer);
  38. if(ulTimerID==0)
  39. {
  40. HAL_1msPeriod();
  41. }
  42. // Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  43. }
  44. boolean HAL_Is1msTickTimeout(void)
  45. {
  46. boolean result = FALSE;
  47. if (hal_1ms_TimerCounter)
  48. {
  49. result = TRUE;
  50. hal_1ms_TimerCounter--;
  51. }
  52. return result;
  53. }
  54. boolean HAL_Is100msTickTimeout(void)
  55. {
  56. boolean result = FALSE;
  57. if (hal_100ms_TimerCounter >= 100u)
  58. {
  59. result = TRUE;
  60. hal_100ms_TimerCounter -= 100u;
  61. }
  62. return result;
  63. }
  64. /* Get timer tick cnt for random seed. */
  65. uint32 HAL_GetTimerTickCnt(void)
  66. {
  67. /* This two variables not init before used, because it used for generate random */
  68. uint32 hardwareTimerTickCnt;
  69. uint32 timerTickCnt;
  70. #if 0
  71. /* For S32K1xx get timer counter(LPTIMER), get timer count will trigger the period incorrect. */
  72. hardwareTimerTickCnt = LPTMR_DRV_GetCounterValueByCount(INST_LPTMR1);
  73. #endif
  74. #pragma GCC diagnostic ignored "-Wuninitialized"
  75. timerTickCnt = ((hardwareTimerTickCnt & 0xFFFFu)) | (timerTickCnt << 16u);
  76. return timerTickCnt;
  77. }
  78. void WATCHDOG_HAL_Feed(void)
  79. {
  80. Wdg_43_Instance0_SetTriggerCondition(500);
  81. }
  82. typedef void (*AppAddr)(void);
  83. void DoResetECU(void)
  84. {
  85. IsFeedWdg = FALSE;
  86. Wdg_43_Instance0_SetTriggerCondition(0);
  87. while(1)
  88. {
  89. // AppAddr resetHandle = (AppAddr)(0x00);
  90. // (resetHandle)();
  91. ;
  92. }
  93. }