beautypg.com

NEXCOM NISE 101 User Manual

Page 78

background image

Copyright © 2010 NEXCOM International Co., Ltd. All Rights Reserved.

65

NISE 101 User Manual

Appendix C: Watchdog Timer Setting

#define IO_INDEX_PORT 0x2E
#define IO_DATA_PORT 0x2F
#define UNLOCK_DATA1 0x87
#define UNLOCK_DATA2 0x01
#define UNLOCK_DATA3 0x55
#define UNLOCK_DATA4 0x55
#define LOCK_DATA 0x02
#define DEVICE_REGISTER 0x07
#define SECOND_MODE 0
#define MINUTE_MODE 1

void EnterConfigMode()
{
outportb(IO_INDEX_PORT, UNLOCK_DATA1);
outportb(IO_INDEX_PORT, UNLOCK_DATA2);
outportb(IO_INDEX_PORT, UNLOCK_DATA3);
outportb(IO_INDEX_PORT, UNLOCK_DATA4);
}

void ExitConfigMode()
{
outportb(IO_INDEX_PORT, LOCK_DATA);
}

void SelectDevice(unsigned char device)
{
outportb(IO_INDEX_PORT, DEVICE_REGISTER);
outportb(IO_DATA_PORT, device);
}

unsigned char ReadAData(short int reg)
{
outportb(IO_INDEX_PORT, reg);
return (inportb(IO_DATA_PORT));
}

void WriteAData(unsigned char reg, unsigned char data)
{
outportb(IO_INDEX_PORT, reg);
outportb(IO_DATA_PORT, data);
}

void SetWatchDogTime(int time_mode, unsigned char time_val)
{
unsigned char data;

EnterConfigMode();
SelectDevice(7);
//Set Register 72 bit6 = 1, KRST as WDT output pin
WriteAData(0x72, 0x40);
//Set Register 72 bit7 = 1, WDT time-out value mode as second
//Set Watchdog Count Mode (bit7=1:second, bit=0:minute)
data = ReadAData(0x72);
if (time_mode == SECOND_MODE)
data = data | 0x80;
else
data = data & 0x7F;
WriteAData(0x72, data);
//Set Register 73
//Set Watch-Dog Timer 1~ 256 steps
WriteAData(0x73, time_val);