7. Watchdog Timer
49
Chaining the ISRs
Save the original NMI ISR vector so that it can be invoked from the new watchdog NMI ISR.
Alter the interrupt vector table so that the NMI ISR vector is overwritten with a vector to the
watchdog ISR. C code to do this in DOS might look like the following:
#define NMI_INTERRUPT_VECTOR_NUMBER 2
void interrupt far (*OldNmiIsr)();
void HookWatchdogIsr(void){
//
// To be absolutely certain the interrupt table is not accessed by an
// NMI (this is quite unlikely), the application could disable NMI in
// the chip set before installing the new vector.
//
.
.
.
//
// Install the new ISR.
//
oldNmiIsr = getvect(IsrVector); // Save the old vector.
setvect(NMI_INTERRUPT_VECTOR_NUMBER, WatchdogIsr); // Install the new.
}
Enabling the Watchdog NMI
To activate the NMI feature, enable it in the watchdog register (
Port 79h
). The code to do this
might look like the following:
#define WD_NMI_EN_BIT_SET 0x10
void EnableWatchdogNmi(void){
unsigned char WdValue;
// Holds watchdog register values.
//
WdValue = inb(WD_CSR_IO_ADDRESS);
// Read the current contents of the
// watchdog register.
WdValue |= WD_NMI_EN_BIT_SET;
// Assert the enable bit in the
// local copy.
outb(WD_CSR_IO_ADDRESS,WdValue);
// Assert the enable in the watchdog
// register.
}
Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com