[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

watchdog



Hi there,

I tried to use the watchdog of the board, but it doesn't work! I'm using
following code and Developer Board Software Release 1.0.1 (caused of troubles
with updating). Watchdog is enabled (so the boot log).
Could someone imaging why it doesn't work or send me a another code ....?




#include <asm/svinto.h>
#include <stdio.h>
#include <signal.h>

#define SIGNMI	1 // signal for the watchdog

static byte   watchdog_key = 0;


void feed_watchdog(void) {
	printf("*** FEED WATCHDOG ***\r\n");
	watchdog_key = ~watchdog_key;
	// IO_FIELD shifts the val parameter to be aligned with the bitfield specified.
	// IO_STATE returns a constant corresponding to a one of the symbolic
  	// states that the bitfield can have. (Shifted to correct position)
	*R_WATCHDOG = IO_FIELD(R_WATCHDOG,key,::watchdog_key &
		0x07)|IO_STATE(R_WATCHDOG,enable,start); }


void stop_watchdog(void) {
	printf("*** STOP WATCHDOG ***\r\n");
	*R_WATCHDOG = IO_FIELD(R_WATCHDOG,key, (~::watchdog_key) &
		0x07)|IO_STATE(R_WATCHDOG,enable, stop); 
}


void watchdog_handler(int signr) {
	stop_watchdog(); /* Kill dog so it won't bother us again */
	printf("*** WATCHDOG IS STARVING ***\r\n");
	printf("called from %i\r\n", signr);
}


int main(void) {
	struct sigaction 	signmi_handler;
	// watchdog (NMI: interrupt 1) handler
	signmi_handler.sa_handler=watchdog_handler;
	sigemptyset(&signmi_handler.sa_mask);
	signmi_handler.sa_flags=0;
		
	// create Signal-Handler
	if(sigaction(SIGNMI,&signmi_handler,NULL)<0) {
		printf("watchdog handler couldn't be created\n");
		return -1;
	}
	
	printf("starts initializing watchdog\n");
	
	*R_VECT_MASK_SET = IO_STATE(R_VECT_MASK_SET, nmi, set);
	*R_IRQ_MASK0_SET = IO_STATE(R_IRQ_MASK0_SET, watchdog_nmi, set);
	// Start watchdog
	__asm__ volatile ("setf m"); // enable nmi
	*R_WATCHDOG =
		IO_FIELD(R_WATCHDOG,key,::watchdog_key)|IO_STATE(R_WATCHDOG,enable,start); 
	// Start watchdog 
	printf("ending initializing watchdog\n"); 	
	while(1);
}


thx
	NKrug