wdg.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /********************************* (C) РОТЕК ***********************************
  2. * @module wdg
  3. * @file wdg.c
  4. * @version 1.0.0
  5. * @date XX.XX.XXXX
  6. * $brief External watchdog (pin PE11)
  7. *******************************************************************************
  8. * @history Version Author Comment
  9. * XX.XX.XXXX 1.0.0 Telenkov D.A. First release.
  10. *******************************************************************************
  11. */
  12. #include "stm32f4xx.h"
  13. #include "wdg.h"
  14. /**
  15. * @brief
  16. * @retval
  17. */
  18. void WDG_Init(void)
  19. {
  20. GPIO_InitTypeDef GPIO_InitStructure;
  21. NVIC_InitTypeDef NVIC_InitStructure;
  22. TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  23. #ifdef HARDWARE_BT6710
  24. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  25. #else
  26. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
  27. #endif
  28. RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM13, ENABLE);
  29. GPIO_InitStructure.GPIO_Pin = WDT_PIN;
  30. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  31. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  32. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  33. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  34. #ifdef HARDWARE_BT6710
  35. GPIO_Init(GPIOD, &GPIO_InitStructure);
  36. #else
  37. GPIO_Init(GPIOE, &GPIO_InitStructure);
  38. #endif
  39. NVIC_InitStructure.NVIC_IRQChannel = TIM8_UP_TIM13_IRQn;
  40. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x6;
  41. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0;
  42. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  43. NVIC_Init(&NVIC_InitStructure);
  44. NVIC_SetPriority(TIM8_UP_TIM13_IRQn, 2);
  45. /* APB1 Timer clock is 60Mhz, configure timer clock to 10khz (1 update event per 100 us) */
  46. TIM_TimeBaseStructure.TIM_Prescaler = 6000 - 1;
  47. /* Configure timer period to 100ms */
  48. TIM_TimeBaseStructure.TIM_Period = 1000;
  49. TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  50. TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  51. TIM_TimeBaseInit(TIM13, &TIM_TimeBaseStructure);
  52. TIM_Cmd(TIM13, ENABLE);
  53. TIM_ITConfig(TIM13, TIM_IT_Update, ENABLE);
  54. }
  55. /**
  56. * @brief Дергаем пином (сброс внешнего WDT)
  57. * @retval
  58. */
  59. void TIM8_UP_TIM13_IRQHandler(void)
  60. {
  61. TIM_ClearITPendingBit(TIM13, TIM_IT_Update);
  62. #ifdef HARDWARE_BT6710
  63. GPIOD->ODR ^= WDT_PIN;
  64. #else
  65. GPIOE->ODR ^= WDT_PIN;
  66. #endif
  67. }
  68. /**
  69. * @brief Дергаем пином (сброс внешнего WDT)
  70. */
  71. void WDT_Reset(void)
  72. {
  73. #ifdef HARDWARE_BT6710
  74. GPIOD->ODR ^= WDT_PIN;
  75. #else
  76. GPIOE->ODR ^= WDT_PIN;
  77. #endif
  78. }
  79. /********************************* (C) РОТЕК **********************************/