bsp_wdog.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "Platform.h"
  2. /* ---------------------------------------------------------------------------------------------------
  3. //看门狗计数器对应的初值
  4. (0x0)0000:0x FFFF
  5. (0x1)0001:0x 1FFFF
  6. (0x2)0010:0x 3FFFF
  7. (0x3)0011:0x 7FFFF
  8. (0x4)0100:0x FFFFF
  9. (0x5)0101:0x 1FFFFF
  10. (0x6)0110:0x 3FFFFF
  11. (0x7)0111:0x 7FFFFF
  12. (0x8)1000:0x FFFFFF----约2S
  13. (0x9)1001:0x 1FFFFFF----约5S
  14. (0xA)1010:0x 3FFFFFF----约10S
  15. (0xB)1011:0x 7FFFFFF----约20S
  16. (0xC)1100:0x FFFFFFF
  17. (0xD)1101:0x1FFFFFFF
  18. (0xE)1110:0x3FFFFFFF
  19. (0xF)1111:0x7FFFFFFF
  20. ----------------------------------------------------------------------------------------------------*/
  21. /* ---------------------------------------------------------------------------------------------------
  22. - 函数名称: xc_wdog_init
  23. - 函数功能: 初始化看门狗
  24. - 函数形参:看门狗计数器重装值
  25. - 创建日期: 2019-04-22
  26. - 创 建 人:陈俊伟
  27. ----------------------------------------------------------------------------------------------------*/
  28. void xc_wdog_init(uint32_t counter_value)
  29. {
  30. __write_hw_reg32(CPR_CTLAPBCLKEN_GRCTL,0x10001); //WDT_PCLK 时钟使能
  31. __write_hw_reg32(CPR_RSTCTL_CTLAPB_SW,0x40000); //WDT 模块软复位
  32. __write_hw_reg32(CPR_RSTCTL_CTLAPB_SW,0x40004);
  33. __write_hw_reg32(CPR_RSTCTL_WDTRST_MASK,0x20);//屏蔽 WDT 引起的 M0 的软复位,不屏蔽 WDT 引起的系统的软复位
  34. __write_hw_reg32(WDT_CR,0x7);// WDT 使能 ,M0 复位信号,维持4个 pclk 时钟周期,工作模式 0,直接产生复位信号送给 CPR
  35. __write_hw_reg32(WDT_TORR,counter_value);
  36. __write_hw_reg32(WDT_CRR,0x76); //重启计数器
  37. }
  38. /* ---------------------------------------------------------------------------------------------------
  39. - 函数名称: xc_wdog_feed
  40. - 函数功能: 喂看门狗
  41. - 函数形参:无
  42. - 创建日期: 2019-04-22
  43. - 创 建 人:陈俊伟
  44. ----------------------------------------------------------------------------------------------------*/
  45. void xc_wdog_feed(void)
  46. {
  47. __write_hw_reg32(WDT_CRR,0x76); //重启计数器
  48. }