iwdg.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "iwdg.h"
  2. INT32U g_dog = 0;
  3. OS_EVENT *iwdg_mutex = NULL;
  4. //初始化独立看门狗
  5. // prer:分频数:0~7(只有低3位有效!)
  6. // rlr:自动重装载值,0~0XFFF.
  7. //分频因子=4*2^prer.但最大值只能是256!
  8. // rlr:重装载寄存器值:低11位有效.
  9. //时间计算(大概):Tout=((4*2^prer)*rlr)/32 (ms).
  10. void iwdg_init(void)
  11. {
  12. IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); //使能对IWDG->PR IWDG->RLR的写
  13. IWDG_SetPrescaler(IWDG_Prescaler_128); //设置IWDG分频系数
  14. IWDG_SetReload(0XFFF); //设置IWDG装载值
  15. IWDG_ReloadCounter(); // reload
  16. IWDG_Enable(); //使能看门狗
  17. }
  18. void iwdg_feed(INT32U dog)
  19. {
  20. INT8U err = 0;
  21. INT32U all_dog = CURRENT_DOG | SOC_DOG | ADC_DOG | INCAN_RX_DOG | INCAN_TX_DOG | INCAN_INFO_DOG | CAN2_TX_DOG | CAN2_RX_DOG | FAULT_DIG_DOG | UART1_DOG | UART3_DOG | BALANCE_DOG | MISC_DOG | PROCESS_DOG;
  22. OSMutexPend(iwdg_mutex, 0, &err);
  23. g_dog |= dog;
  24. OSMutexPost(iwdg_mutex);
  25. if (g_dog == all_dog)
  26. {
  27. /* 重载IWDG计数 */
  28. IWDG_ReloadCounter();
  29. OSMutexPend(iwdg_mutex, 0, &err);
  30. g_dog = 0;
  31. OSMutexPost(iwdg_mutex);
  32. }
  33. }
  34. void iwdg_disable(void)
  35. {
  36. }