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

Page 270

Advertising
background image

KTD-S0057-I

Page 266 Linux® Programming Examples (DebianTM)


KTAM3874/pITX Software Guide


#include <linux/limits.h>
#include "fifo.h"

int main (void)
{

int fifo_rd, fifo_wr, n;

struct pollfd pfd;

static char buff_rd [RD_SIZE];

static char buff_wr [WR_SIZE];

if ((fifo_rd = open (root_wr, O_RDONLY | O_NDELAY)) < 0 || (fifo_wr = open (root_rd, O_WRONLY)) < 0)

ERROR;

while

(1)

{

write (fileno (stdout), CMD_STR, strlen (CMD_STR));

memset (buff_wr, 0, WR_SIZE);

memset (buff_rd, 0, RD_SIZE);

n = read (fileno (stdin), buff_wr, WR_SIZE);

write (fifo_wr, buff_wr, n);

if (! strncasecmp (buff_wr, CMD_EXIT, CMD_SIZE))

break;

pfd.fd = fifo_rd;

pfd.events = POLLIN;

if (poll (&pfd, 1, POLL_TIME) > 0)

/* wait 5 milliseconds */

{

write (fileno (stderr), ACK_APP, strlen (ACK_APP));

while ((n = read (fifo_rd, buff_rd, RD_SIZE)) > 0)

write (fileno (stderr), buff_rd, n);

}

else

write (fileno (stderr), TIMEOUT_STR, strlen (TIMEOUT_STR));

}

close

(fifo_rd);

close

(fifo_wr);

return

0;

}


First open a terminal window, type

su

(password

root

) or

sudo -i

(password

ktam3874

), change to your

target directory with the server application and start the server program with '

./server

'. Thereafter open a

second new terminal window, go to your target directory with the client application and run this program
with '

./client

' (not as root).

Both samples are based on practical experience and aimed at simple and quick implementation of inter-
process communication, therefore only watchdog and GPIO functionality are implemented.
Command table:

wdio on 30

Activate the watchdog with timeout of 30 seconds

wdio off

Disable the watchdog

wdio trig

Trigger the watchdog

Advertising
This manual is related to the following products: