TS-7670 Watchdog

From embeddedTS Manuals
Revision as of 19:04, 19 December 2013 by Kris (talk | contribs)

The i.MX286 uses a WDT inside of the CPU. The counter for the WDT has millisecond resolution and can be set from 0 to 4,294,967,295. Any application can feed the WDT at any time (though it is recommended to only have one application handle the feeding) with any arbitrary value. Once this counter reaches 0 the WDT will trip and the whole system will restart. Upon bootup the WDT is disabled and the timeout is set to 4,294,967,295. There are no applications on the default software load that utilize the WDT, this leaves it free for use in customer applications. Some examples of feeding the WDT:

Bash:

devmem 0x80056004 32 0x10 #Enable WDT counter
devmem 0x80056050 32 10000 #feed for 10000ms, or 10s


C:

#include <assert.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

/*******************************************************************************
* Main: accept input from the command line and act accordingly.
*******************************************************************************/
int main(int argc, char **argv)
{
	int devmem = 0;
	volatile unsigned int *wdtctl = NULL;
	unsigned long int val;
         
	// Check for invalid command line arguments
	if(argc != 2) {
		printf("Usage: %s val_in_ms\n", argv[0]);
		return 1;
	}
   
	val = strtoul(argv[1], NULL, 0);

	devmem = open("/dev/mem", O_RDWR|O_SYNC);
	wdtctl = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, devmem, 0x80056000);
	
	/* Enable WDT */
	wdtctl[0x4/4] = 0x10;

	wdtctl[0x50/4] = val;
	
	return 0;
}