watchdog.c
上传用户:mhstny
上传日期:2022-08-05
资源大小:793k
文件大小:2k
源码类别:

微处理器开发

开发平台:

Unix_Linux

  1. #include "2410addr.h"
  2. #include "2410lib.h"
  3. void watchdog_test(void);
  4. void __irq watchdog_int(void);
  5. //复位次数
  6. int f_ucSencondNo=0;
  7. /*************************************************
  8. Function name: Main
  9. Parameter    : void
  10. Description  : 主功能函数
  11. Return  : void
  12. Argument     : void
  13. Autor & date :
  14. **************************************************/
  15. int Main(void)
  16. {
  17. ChangeClockDivider(1,1);
  18.     ChangeMPllValue(0xa1,0x3,0x1);   
  19.     Port_Init();
  20.     Uart_Select(0);
  21.     Uart_Init(0,115200);
  22. Uart_Printf("watchdog test is beginningn");
  23. watchdog_test();
  24. while(1);
  25. }
  26. /**********************************
  27. watchdog_init
  28. watchdog interrupt service routine
  29. ************************************/ 
  30. void watchdog_test(void)
  31. {
  32.   //initialize interrupt registers
  33.   ClearPending(BIT_WDT);
  34.  
  35.   //建立WatchDog中断
  36.   pISR_WDT=(unsigned)watchdog_int;
  37.   //Prescaler value=100、clock division factor=128
  38.   //t_watchdog=1/[PCLK/(Prescaler value+1)/Division_factor]=0.00025856
  39.   //disable watchdog
  40.   rWTCON=((100<<8)|(3<<3)); 
  41.   
  42.   //看门狗时钟周期T=WTCNT*t_watchdog=4S
  43.   //看门狗喂狗
  44.   rWTDAT=15000;
  45.   rWTCNT=15000;
  46.   rWTCON|=((1<<5)|(1<<2));//enable Watchdog timer ang watchdog interrupt
  47.   
  48.   //rWTCON|=((1<<5)|(1<<2)|1);//watchdog 复位,时间间隔为4S。
  49.   rWTCON|=(1<<5)|(1<<2);//每4S watchdog 一次中断。
  50.    
  51.   //设置watchdog为IRQ中断模式
  52.   rINTMOD&=0xFFFFFDFF;
  53.   //开中断
  54.   EnableIrq(BIT_WDT);
  55.   
  56.   while(f_ucSencondNo<11);
  57.  }
  58. /****  watchdog_int  ****/
  59. void __irq watchdog_int(void)
  60. {
  61.   //清除中断
  62.   ClearPending(BIT_WDT);
  63.   f_ucSencondNo++;
  64.   
  65.   if(f_ucSencondNo<11)
  66.   Uart_Printf("%ds",f_ucSencondNo);
  67.   else
  68.   {
  69.     //mask watchdog timer interrupt
  70.     DisableIrq(BIT_WDT);
  71.     Uart_Printf("watch dog is okn");
  72.   }
  73. }