Hal_Wdg.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 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. ulTimerID = (uint32)pvTimerGetTimerID(pxTimer);
  41. if(ulTimerID==0)
  42. {
  43. HAL_1msPeriod();
  44. }
  45. }
  46. boolean HAL_Is1msTickTimeout(void)
  47. {
  48. boolean result = FALSE;
  49. if (hal_1ms_TimerCounter)
  50. {
  51. result = TRUE;
  52. hal_1ms_TimerCounter--;
  53. }
  54. return result;
  55. }
  56. boolean HAL_Is100msTickTimeout(void)
  57. {
  58. boolean result = FALSE;
  59. if (hal_100ms_TimerCounter >= 100u)
  60. {
  61. result = TRUE;
  62. hal_100ms_TimerCounter -= 100u;
  63. }
  64. return result;
  65. }
  66. /* Get timer tick cnt for random seed. */
  67. uint32 HAL_GetTimerTickCnt(void)
  68. {
  69. /* This two variables not init before used, because it used for generate random */
  70. uint32 hardwareTimerTickCnt;
  71. uint32 timerTickCnt;
  72. #if 0
  73. /* For S32K1xx get timer counter(LPTIMER), get timer count will trigger the period incorrect. */
  74. hardwareTimerTickCnt = LPTMR_DRV_GetCounterValueByCount(INST_LPTMR1);
  75. #endif
  76. #pragma GCC diagnostic ignored "-Wuninitialized"
  77. timerTickCnt = ((hardwareTimerTickCnt & 0xFFFFu)) | (timerTickCnt << 16u);
  78. return timerTickCnt;
  79. }
  80. void WATCHDOG_HAL_Feed(void)
  81. {
  82. Wdg_43_Instance0_SetTriggerCondition(500);
  83. }
  84. //typedef void (*AppAddr)(void);
  85. void DoResetECUWithWdg(void)
  86. {
  87. IsFeedWdg = FALSE;
  88. Wdg_43_Instance0_SetTriggerCondition(0);
  89. while(1)
  90. {
  91. // AppAddr resetHandle = (AppAddr)(0x00);
  92. // (resetHandle)();
  93. ;
  94. }
  95. }