Ktam3874/pitx software guide – Kontron KTAM3874-pITX User Manual

Page 265

Advertising
background image

KTD-S0057-I

Page 261 Linux® Programming Examples (DebianTM)


KTAM3874/pITX Software Guide


#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <linux/limits.h>
#include <linux/watchdog.h>
#include "fifo.h"

int parse_wdio (char cmd_line[])
{

static int fd_wd = 0;

const char delim[] = " ,;:-";

char

*param1,

*param2;

cmd_line [strlen (cmd_line) - 1] = '\0';

/* remove CR */

strsep (&cmd_line, delim);

/* suppress the command */

param1 = strsep (&cmd_line, delim);

param2 = strsep (&cmd_line, delim);

if (param1 == (char *) NULL)

return

-1;

if (!strcasecmp (param1, WD_ON) && param2 != (char *) NULL && !fd_wd)

{

int

time;

time = atoi (param2);

if ((time < 1) || (time > 600))

return

-1;

if ((fd_wd = open (wdt, O_WRONLY)) < 0)

return

-1;

if (ioctl (fd_wd, WDIOC_SETTIMEOUT, &time))

{

close

(fd_wd);

fd_wd = 0;

return

-1;

}

return

0;

}

if (!strcasecmp (param1, WD_OFF) && fd_wd)

{

if (write (fd_wd, "V", 1) != 1)

{

close (fd_wd);

/* matter of opinion */

fd_wd = 0;

/* the same */

return

-1;

}

close

(fd_wd);

fd_wd = 0;

return

0;

}

Advertising
This manual is related to the following products: