beautypg.com

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

Page 266

background image

KTD-S0057-I

Page 262 Linux® Programming Examples (DebianTM)


KTAM3874/pITX Software Guide


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

{

if (write (fd_wd, "\0", 1) != 1)

return -1;

/* fd_wd is not closed to give a second chance */

return

0;

}

return

-1;

}


int parse_gpio (char cmd_line[], int *val)
{

static int fd_io = 0;

static int gp_num = 0;

static int gp_dir = -1;

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

char *param1, *param2, *param3;

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);

param3 = strsep (&cmd_line, delim);

*val = -1;

if ((param1 == (char *) NULL) || (param2 == (char *) NULL))

return

-1;

if (!strcasecmp (param2, IO_OPEN) && param3 != (char *) NULL && !fd_io)

{

int fd_tmp, gpio;

char str [64];

gpio = atoi (param1);

if ((gpio < 0) || (gpio > 39))

return

-1;

if (strcasecmp (param3, IO_IN) && strcasecmp (param3, IO_OUT))

return

-1;

if ((fd_tmp = open (io_exp, O_WRONLY)) < 0)

return

-1;

sprintf (str, "%d", io_num[gpio]);

if (write (fd_tmp, str, strlen (str)) != strlen (str))

{

close

(fd_tmp);

return

-1;

}

close

(fd_tmp);

sprintf (str, io_dir, io_num[gpio]);

if ((fd_tmp = open (str, O_WRONLY)) < 0)

return

-1;

This manual is related to the following products: