7 watchdog example, Ktam3874/pitx software guide – Kontron KTAM3874-pITX User Manual

Page 73

Advertising
background image

KTD-S0057-I

Page 69 Linux® Programming Examples (DebianTM)


KTAM3874/pITX Software Guide

10.7 Watchdog Example

The watchdog option represents a nice feature for industrial applications. You can also download a watch-
dog daemon with 'sudo apt-get install watchdog' for additional features.
Further information about watchdog programming is available on

https://www.kernel.org/doc/Documen-

tation/watchdog/watchdog-api.txt

. The demonstration program needs root rights (compiled on Ubuntu

TM

distribution).

/* Watchdog test program

* Copyright (c) 2013 Kontron Technology A/S

* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*/

#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <asm/types.h>
#include <linux/watchdog.h>

#define WDT_TIMEOUT

20

/* Seconds */

#define WDT_TRIG_TIME

3

#define WDT_DELAY

10

/* Seconds */

#define WDT_MARKUP

((WDT_TIMEOUT - WDT_DELAY) + 10)

static const char *device = "/dev/watchdog";

int main (void)
{

int fd, i;

/*int

bootstat;*/

int wdt_time = WDT_TIMEOUT;

fd = open (device, O_WRONLY);

if (fd < 0)

{

printf ("\nWatchdog init error !\n\n");

return

-1;

}

/* Check if last boot is caused by watchdog - NOT WORKING PROPERLY */

/*if (ioctl (fd, WDIOC_GETBOOTSTATUS, &bootstat))

printf ("\nCannot read watchdog status !\n");

else

printf ("\nLast boot is caused by : %s\n", (bootstat != 0) ? "Watchdog" : "Power-On-Reset"); */

if (ioctl (fd, WDIOC_SETTIMEOUT, &wdt_time))

printf ("\nSetting of watchdog timeout fails !\n");

else

printf ("\nNew timeout value is : %d seconds\n", wdt_time);

Advertising
This manual is related to the following products: