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

KTD-S0057-I
Page 267 Linux® Programming Examples (DebianTM)
KTAM3874/pITX Software Guide
gpio 11 open in
Enable (export) GPIO11 as input
gpio 11 open out
Enable (export) GPIO11 as output
gpio 11 close
Disable (unexport) GPIO11
gpio 11 data
Read GPIO11 data line (should be opened as input)
gpio 11 data 0
Set GPIO11 data line to low level (should be opened as output)
gpio 11 data 1
Set GPIO11 data line to high level (should be opened as output)
exit
Terminate client and server program
Remark: the GPIO assignment (0 to 39) uses the table on page 61.
If you perform a more detailled analysis you can notice that the programs apply two separate FIFOs, one for
sending and one for receiving, and not a bidirectional FIFO. For speed optimization it is possible to reduce
the poll time (client application) and/or use binary data instead of ASCII chars.
To run the server application as a normal program does not offer the best solution. The following source-
code realizes a Daemon for background operation. It is a good habit to rename the server program to
'serverd'. The listing only shows the main routine and two additional subroutines (extensions in green
color):
#include
#include
#include
mode_t get_mask (int cmd_set)
{
static
mode_t
oldmask;
if
(cmd_set)
oldmask = umask (0);
return
oldmask;
}
void signal_handler (int sig)
{
switch
(sig)
{
case SIGHUP: break;
/* ignore this signal or do something */
case
SIGTERM:
unlink
(root_rd);
unlink
(root_wr);
umask
(get_mask
(0));
exit
(EXIT_SUCCESS);
}
}