Advantech Watchdog timer query.
From: Ryan Clayburn
Date:  Fri Oct 21 2005 - 02:48:26 EST
Hi Everyone,
I work for a government agency so please forgive me for not having the
latest version of the kernel. My question concerns an Advantech card PCI
6870 Single Board Computer and its watchdog timer. I am running Redhat 9
linux 2.4.20-8 and it comes with module that supports the hardware
advantechwdt.o. I have been able install and communicate with the card.
Get and set the timeout or margin and get the support information of the
card. Everything seems to work except when i deliberately delay the ping
to the card to let it reboot the system as a watchdog should it does not
reboot. Is there something i am missing. Do i need a update to the
driver? I am attaching the code. It is fairly simple and a lot of it is
just reading and writing information read from the driver about the
card. I would appreciate any help.
Cheers
Ryan Clayburn
Can i please be CC'ed the answers/comments posted to the list in
response to my posting
************************************************************************
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/watchdog.h>
#include <time.h>
#include <sys/time.h>
int main(int argc, const char *argv[]) 
{
	int fd;
	struct watchdog_info *wdog_info;
	time_t timenow;
	char supportOptions[500];
	char dtime[50];
	int i, err;
	int timein, timeout;
	    
	fd = open("/dev/watchdog",O_WRONLY);
	
	if (fd==-1) 
	{
		perror("watchdog");
		return 1;
	}
	//printf("argc = %d\n", argc);
	err = ioctl(fd, WDIOC_GETSUPPORT, wdog_info);
	if (err < 0)
		printf("error is %d\n", err);
	if (wdog_info->options & WDIOF_KEEPALIVEPING)
		strcpy(supportOptions, "WDIOF_KEEPALIVEPING");
	if (wdog_info->options & WDIOF_MAGICCLOSE)
	{
		if (strlen(supportOptions) == 0)
		{
			strcpy(supportOptions, "WDIOF_MAGICCLOSE");
		}
		else
		{
			strcat(supportOptions, " | WDIOF_MAGICCLOSE");
		}
	}
	if (wdog_info->options & WDIOF_SETTIMEOUT)
	{
		if (strlen(supportOptions) == 0)
		{
			strcpy(supportOptions, "WDIOF_SETTIMEOUT");
		}
		else
		{
			strcat(supportOptions, " | WDIOF_SETTIMEOUT");
		}
	}
	if (wdog_info->options & WDIOF_POWEROVER)
	{
		if (strlen(supportOptions) == 0)
		{
			strcpy(supportOptions, "WDIOF_POWEROVER");
		}
		else
		{
			strcat(supportOptions, " | WDIOF_POWEROVER");
		}
	}
	if (wdog_info->options & WDIOF_CARDRESET)
	{
		if (strlen(supportOptions) == 0)
		{
			strcpy(supportOptions, "WDIOF_CARDRESET");
		}
		else
		{
			strcat(supportOptions, " | WDIOF_CARDRESET");
		}
	}
	if (wdog_info->options & WDIOF_POWERUNDER)
	{
		if (strlen(supportOptions) == 0)
		{
			strcpy(supportOptions, "WDIOF_POWERUNDER");
		}
		else
		{
			strcat(supportOptions, " | WDIOF_POWERUNDER");
		}
	}
	if (wdog_info->options & WDIOF_EXTERN2)
	{
		if (strlen(supportOptions) == 0)
		{
			strcpy(supportOptions, "WDIOF_EXTERN2");
		}
		else
		{
			strcat(supportOptions, " | WDIOF_EXTERN2");
		}
	}
	if (wdog_info->options & WDIOF_EXTERN1)
	{
		if (strlen(supportOptions) == 0)
		{
			strcpy(supportOptions, "WDIOF_EXTERN1");
		}
		else
		{
			strcat(supportOptions, " | WDIOF_EXTERN1");
		}
	}
	if (wdog_info->options & WDIOF_FANFAULT)
	{
		if (strlen(supportOptions) == 0)
		{
			strcpy(supportOptions, "WDIOF_FANFAULT");
		}
		else
		{
			strcat(supportOptions, " | WDIOF_FANFAULT");
		}
	}
	if (wdog_info->options & WDIOF_OVERHEAT)
	{
		if (strlen(supportOptions) == 0)
		{
			strcpy(supportOptions, "WDIOF_OVERHEAT");
		}
		else
		{
			strcat(supportOptions, " | WDIOF_OVERHEAT");
		}
	}
	
	printf("\nWATCHDOG TIMER DAEMON\n");
	printf("---------------------\n\n");
	printf("Wdioc Get Support Information\n");
	printf("-------------------------------------\n");
	printf("Options: %s\nFirmware Version: %d\n", supportOptions,
wdog_info->firmware_version);
	printf("Identity: ", wdog_info->identity);
	for (i = 0; i < 32; i++)
	{
		printf("%c", wdog_info->identity[i]);
	}
	printf("\n-------------------------------------\n\n");
	ioctl(fd, WDIOC_GETTIMEOUT, &timein);
	printf("The current timeout is %d seconds\n", timein);
	timeout = 30;
	ioctl(fd, WDIOC_SETTIMEOUT, &timeout);
	printf("The timeout was set to %d seconds\n", timeout);
	time(&timenow);
	strcpy(dtime, ctime(&timenow));
	printf("%s", dtime);
	while(1)
	{
		//write(fd, "\0", 1);
		ioctl(fd, WDIOC_KEEPALIVE, 0);
		if (err < 0)
			printf("error is %d\n", err);
		sleep(timeout*2+10);
		time(&timenow);
		strcpy(dtime, ctime(&timenow));
		printf("%s", dtime);
	}
	close(fd);
	printf("bye bye...\n");
	return 0;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/