watchdog_clear_n_reset.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2021 IOsetting <iosetting(at)outlook.com>
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /***
  15. * Demo: Watchdog Clear And Reset
  16. */
  17. #include "fw_hal.h"
  18. static uint8_t c0 = 0, c1 = 0;
  19. INTERRUPT(Timer0_Routine, EXTI_VectTimer0)
  20. {
  21. c0++;
  22. if (c0 == 100)
  23. {
  24. c0 = 0;
  25. c1++;
  26. if (c1 < 5)
  27. {
  28. UART1_TxString("Round ");
  29. UART1_TxHex(c1);
  30. UART1_TxString(", reset watchdog counter\r\n");
  31. WDT_ResetCounter();
  32. }
  33. else
  34. {
  35. UART1_TxString("Round ");
  36. UART1_TxHex(c1);
  37. UART1_TxString(", no operation\r\n");
  38. }
  39. }
  40. }
  41. int main(void)
  42. {
  43. uint8_t count = 9;
  44. SYS_SetClock();
  45. UART1_Config8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
  46. UART1_TxString("Watchdog test restarted\r\n");
  47. // Timer0: 12T mode, frequency 100Hz
  48. TIM_Timer0_Config(HAL_State_OFF, TIM_TimerMode_16BitAuto, 100);
  49. EXTI_Timer0_SetIntState(HAL_State_ON);
  50. EXTI_Timer0_SetIntPriority(EXTI_IntPriority_High);
  51. EXTI_Global_SetIntState(HAL_State_ON);
  52. TIM_Timer0_SetRunState(HAL_State_ON);
  53. UART1_TxString("Timer 0 started\r\n");
  54. /**
  55. * Set countdown time to around 3 seconds(FOSC = 36.864MHz)
  56. */
  57. WDT_SetCounterPrescaler(0x07);
  58. WDT_StartWatchDog();
  59. while(1);
  60. }