Appendix b - watchdog sample code, Appendix b appendix b - watchdog sample code – DFI CR960-HM76 User Manual
Page 78
www.dfi .com
Appendix B Watchdog Sample Code
78
Appendix B
Appendix B - Watchdog Sample Code
#include
//--------------------------------------------------------------
#defi ne EC_EnablePort 0x66
#defi ne EC_DataPort 0x62
//--------------------------------------------------------------
void WriteEC(char,int);
void SetWDTime(int,int);
int GetWDTime(void);
//--------------------------------------------------------------
main()
{
unsigned int countdown;
unsigned int input,count_h,count_l;
printf("Input WD Time: ");
scanf("%d",&input);
printf("\n");
count_h=input>>8;
count_l=input&0x00FF;
SetWDTime(count_h,count_l);
while(1)
{
countdown = GetWDTime();
delay(100);
printf("\rTime Remaining: %d ",countdown);
}
}
//--------------------------------------------------------------
void SetWDTime(int count_H,int count_L)
{
//Set Count
WriteEC(0xB7,count_H); //High Byte
WriteEC(0xB8,count_L); //Low Byte
//Enable Watch Dog Timer
WriteEC(0xB4,0x02);
}
//--------------------------------------------------------------
int GetWDTime(void)
{
int sum,data_h,data_l;
//Select EC Read Type
outportb(EC_EnablePort,0x80);
delay(5);
//Get Remaining Count High Byte
outportb(EC_DataPort,0xF6);
delay(5);
data_h=inportb(EC_DataPort);
delay(5);
//Select EC Read Type
outportb(EC_EnablePort,0x80);
delay(5);
//Get Remaining Count Low Byte
outportb(EC_DataPort,0xF7);
delay(5);
data_l=inportb(EC_DataPort);
delay(5);
data_h<<=8;
data_h&=0xFF00;
sum=data_h|data_l;
return sum;
}
//--------------------------------------------------------------
void WriteEC(char EC_Addr, int data)
{
//Select EC Write Type
outportb(EC_EnablePort,0x81);
delay(5);
outportb(EC_DataPort,EC_Addr);
delay(5);
outportb(EC_DataPort,data);
delay(5);
}
//--------------------------------------------------------------