Skip to content

Instantly share code, notes, and snippets.

@Embedded-linux
Created September 4, 2013 14:13
Show Gist options
  • Select an option

  • Save Embedded-linux/6437514 to your computer and use it in GitHub Desktop.

Select an option

Save Embedded-linux/6437514 to your computer and use it in GitHub Desktop.
WDT for LPC2148
Reference user manual :
http://www.keil.com/dd/docs/datashts/philips/user_manual_lpc2119_2129_2194_2292_2294.pdf
/* WDT [Watch Dog Timer] driver for LPC2129 */
#include <LPC210x.H> /* LPC210x definitions */
extern void init_serial (void); /* Initialize Serial Interface */
extern int sendchar (int ch); /* Write character to Serial Port */
extern int getkey (void); /* Read character from Serial Port */
void feed_watchdog (void) { /* Reload the watchdog timer */
WDFEED = 0xAA;
WDFEED = 0x55;
}
void sendhex (int hex) { /* Write Hex Digit to Serial Port */
if (hex > 9) sendchar('A' + (hex - 10));
else sendchar('0' + hex);
}
void sendstr (char *p) { /* Write string */
while (*p) {
sendchar (*p++);
}
}
/* just waste time here for demonstration */
void do_job (void) {
int i;
for (i = 0; i < 5; i++);
}
int main (void) {
unsigned int i;
init_serial(); /* Initialize Serial Interface */
if( WDMOD & 0x04 ) { /* Check for watchdog time out */
sendstr("Watchdog Reset Occurred\n");
WDMOD &= ~0x04; /* Clear time out flag */
}
WDTC = 0x2000; /* Set watchdog time out value */
WDMOD = 0x03; /* Enable watchdog timer and reset */
for(i = 0; i < 2; i++) {
do_job (); /* the actual job of the CPU */
feed_watchdog(); /* restart watchdog timer */
}
while (1) { /* Loop forever */
do_job (); /* the actual job of the CPU */
/* no watchdog restart,
watchdog reset will occur! */
}
}
WDTC:
Watchdog Timer Constant register. This register
determines the time-out value.
WDMOD:
Watchdog Mode register. This register contains the
basic mode and status of the Watchdog Timer.
WDFEED:
Watchdog Feed sequence register. Writing 0xAA
followed by 0x55 to this register reloads the
Watchdog timer to its preset value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment