watchdog.c
资源名称:arm_exam.rar [点击查看]
上传用户:mhstny
上传日期:2022-08-05
资源大小:793k
文件大小:2k
源码类别:
微处理器开发
开发平台:
Unix_Linux
- #include "2410addr.h"
- #include "2410lib.h"
- void watchdog_test(void);
- void __irq watchdog_int(void);
- //复位次数
- int f_ucSencondNo=0;
- /*************************************************
- Function name: Main
- Parameter : void
- Description : 主功能函数
- Return : void
- Argument : void
- Autor & date :
- **************************************************/
- int Main(void)
- {
- ChangeClockDivider(1,1);
- ChangeMPllValue(0xa1,0x3,0x1);
- Port_Init();
- Uart_Select(0);
- Uart_Init(0,115200);
- Uart_Printf("watchdog test is beginningn");
- watchdog_test();
- while(1);
- }
- /**********************************
- watchdog_init
- watchdog interrupt service routine
- ************************************/
- void watchdog_test(void)
- {
- //initialize interrupt registers
- ClearPending(BIT_WDT);
- //建立WatchDog中断
- pISR_WDT=(unsigned)watchdog_int;
- //Prescaler value=100、clock division factor=128
- //t_watchdog=1/[PCLK/(Prescaler value+1)/Division_factor]=0.00025856
- //disable watchdog
- rWTCON=((100<<8)|(3<<3));
- //看门狗时钟周期T=WTCNT*t_watchdog=4S
- //看门狗喂狗
- rWTDAT=15000;
- rWTCNT=15000;
- rWTCON|=((1<<5)|(1<<2));//enable Watchdog timer ang watchdog interrupt
- //rWTCON|=((1<<5)|(1<<2)|1);//watchdog 复位,时间间隔为4S。
- rWTCON|=(1<<5)|(1<<2);//每4S watchdog 一次中断。
- //设置watchdog为IRQ中断模式
- rINTMOD&=0xFFFFFDFF;
- //开中断
- EnableIrq(BIT_WDT);
- while(f_ucSencondNo<11);
- }
- /**** watchdog_int ****/
- void __irq watchdog_int(void)
- {
- //清除中断
- ClearPending(BIT_WDT);
- f_ucSencondNo++;
- if(f_ucSencondNo<11)
- Uart_Printf("%ds",f_ucSencondNo);
- else
- {
- //mask watchdog timer interrupt
- DisableIrq(BIT_WDT);
- Uart_Printf("watch dog is okn");
- }
- }