📄 watchdog.c
字号:
//================================================
// Watch-dog timer Interrupt Request Test
// Watchdog.c 2413X
//================================================
#include <stdio.h>
#include <stdlib.h>
#include "2413addr.h"
#include "System.h"
#include "Exception.h"
#include "Console.h"
#include "def.h"
#include "watchdog.h"
void WDT_DIV_Test(void);
void WDT_PVAL_Test(void);
void __irq Wdt_Int(void);
void __irq Wdt_pval_Int(void);
volatile int isWdtInt;
void * wdt_func[][2]=
{
(void *)WDT_DIV_Test, "Watchdog Divider Test ",
(void *)WDT_PVAL_Test, "Watchdog Prescaler Val Test",
(void *)signalviewingTest, "signalviewingTest ",
0,0
};
void Ch17_Watchdog(void)
{
int i=0;
while(1)
{
i=0;
printf("\n\n");
while(1)
{ //display menu
printf("%2d:%s",i,wdt_func[i][1]);
i++;
if((int)(wdt_func[i][0])==0)
{
printf("\n");
break;
}
printf("\n");
}
printf("\nPress Enter key to exit : ");
i = GetIntNum();
if(i==-1) break; // return.
if(i>=0 && (i<((sizeof(wdt_func)-1)/8)) ) // select and execute...
( (void (*)(void)) (wdt_func[i][0]) )();
}
}
void WDT_DIV_Test(void)
{
int i;
printf("Select Clock Division Factor 0:[1/16] 1:[1/32] 2:[1/64] 3:[1/128 (D)] ");
i=GetIntNum();
rINTMSK &= ~(BIT_WDT); //Watch dog Interrupt service is available
pISR_WDT= (unsigned )Wdt_Int;
isWdtInt = 0;
rWTCON = 0; // wdt reset & interrupt disable
switch(i) {
case 0:
printf("Clock Divsion 1/16\n");
rWTCON = ((PCLK/1000000-1)<<8) | (0<<3) | (1<<2); //Prescaler=0x2a(42),Clock division 128,Interrupt enable
rWTDAT = 62500 ;
rWTCNT = 62500 ;
break;
case 1:
rWTCON = ((PCLK/1000000-1)<<8) | (1<<3) | (1<<2); //Prescaler=0x2a(42),Clock division 128,Interrupt enable
rWTDAT = 31250 ;
rWTCNT = 31250 ;
printf("Clock Divsion 1/32\n");
break;
case 2:
rWTCON = ((PCLK/1000000-1)<<8) | (2<<3) | (1<<2); //Prescaler=0x2a(42),Clock division 128,Interrupt enable
rWTDAT = 15625 ;
rWTCNT = 15625 ;
printf("Clock Divsion 1/64\n");
break;
case 3:
rWTCON = ((PCLK/1000000-1)<<8) | (3<<3) | (1<<2); //Prescaler=0x2a(42),Clock division 128,Interrupt enable
rWTDAT = 7813 ;
rWTCNT = 7813 ;
printf("Clock Divsion 1/128\n");
break;
default :
printf("Clock Divsion 1/128\n");
rWTCON = ((PCLK/1000000-1)<<8) | (3<<3) | (1<<2); //Prescaler=0x2a(42),Clock division 128,Interrupt enable
rWTDAT = 7813 ;
rWTCNT = 7813 ;
}
rWTCON = rWTCON | (1<<5); //Watch-dog timer enable
printf("[ WDT Reset Test]\n");
printf("WDT Reset after wdt interrupt happened 5 times. \n");
while(isWdtInt != 5); // variable
// WDT reset enable
rWTCON |= (1<<5)|(1);
rINTMSK |= BIT_WDT; //WDT Interrupt Mask
}
void __irq Wdt_Int(void)
{
printf("%d ",++isWdtInt);
ClearPending(BIT_WDT);
}
//-------------------------------------------------------------------------------------------------------------
void __irq Wdt_pval_Int(void)
{
if(((isWdtInt++)%10)==0) printf(".");
ClearPending(BIT_WDT);
}
void __irq Wdt_toggoe_Int(void) {
if ( isWdtInt ++ % 2 )
rGPEDAT |= (1<<12);
else
rGPEDAT &= ~(1<<12);
ClearPending(BIT_WDT);
}
void WDT_PVAL_Test(void)
{
U32 CNT;
U32 input;
printf("%d\n",PCLK);
rINTMSK &= ~(BIT_WDT); //Watch dog Interrupt service is available
isWdtInt = 0;
rWTCON = 0; // wdt reset & interrupt disable
printf("Prescaler value [0]:0, [1(D)]:255 =>");
input=GetIntNum();
if(input>1) input=1;
if (input==0) {
pISR_WDT= (unsigned )Wdt_pval_Int;
rWTCON = (0<<8) | (3<<3) | (1<<2); //Prescaler=0,Clock division 128,Interrupt enable
rWTDAT = 39062 ;
rWTCNT = 39062 ;
printf("printf . per 1 second\n");
rWTCON = rWTCON | (1<<5); //Watch-dog timer enable
getchar();
}
else {
pISR_WDT= (unsigned )Wdt_Int;
rWTCON = (255<<8) | (0<<3) | (1<<2); //Prescaler=255,Clock division 16,Interrupt enable
rWTDAT = 12207 ;
rWTCNT = 12207 ;
printf("printf . per 1 second\n");
rWTCON = rWTCON | (1<<5); //Watch-dog timer enable
getchar();
}
rWTCON = rWTCON & ~(1<<5); //Watch-dog timer disable
rINTMSK |= BIT_WDT; //WDT Interrupt Mask
}
void signalviewingTest(void) {
int i,k;
int maxcount = 0xff;
int mux;
int muxval[] = { 16,32,64,128};
isWdtInt = 0;
mux = 0;
// initialize random function
srand(rBCDSEC);
// GPIO Setting.
rGPGCON=rGPGCON|(3<<22);
rGPEDN = 0x1000; //Pull-up disable
rGPECON = 0x01000000; //GPE12
pISR_WDT= (unsigned )Wdt_toggoe_Int;
rINTMSK &= ~(BIT_WDT);
for(k=0;k<20;k++) {
for( i = 0 ; i < maxcount; i++ ) {
rWTCON = 0;
rWTDAT = rand() & 0xffff;
rWTCNT = rWTDAT;
printf ( "setting : prescaler:%d,mux:%d,cnt:%d, clock:%5.2f Hz, time:%5f msec\n",i,mux, rWTDAT , (float)PCLK/(i+1)/muxval[mux]/rWTCNT/2, (float)1000/((float)PCLK/(i+1)/muxval[mux]/rWTCNT) );
rWTCON = (i<<8) | (1<<5) | (mux<<3) | (1<<2); //Prescaler=i,Clock division is mux,Interrupt enable
while(isWdtInt<100);
isWdtInt=0;
}
mux=(mux+1) % 4;
}
printf ( "Done\n");
rWTCON = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -