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

KTD-S0057-I
Page 83 Linux® Programming Examples (DebianTM)
KTAM3874/pITX Software Guide
10.10 RS485 Interface Example
The application programming of the RS485 interface can be a little tricky (up to Kernel version 1.03).
Normally the RTS status line should switch between transmit and receive mode but after initialization of the
serial interface the status line does not work correctly. If you use the
devmem2
utility directly after the
boot process with
sudo ./devmem2 481AA010 d 2
resp.
sudo ./devmem2 481AA010 d 0
you can toggle the RTS status line without a problem but the same approach fails after initialization by an
application program (auto-RTS and auto-CTS not enabled, clearing the complete EFR = Enhanced Feature
Register also has no effect). If you want to control the RTS pin by calling ioctl() with TIOCMGET/TIOCMSET
parameters the result belies over the true state. The only way out of this situation is to redefine the RTS pin
as a GPIO pin. The program below uses the
sysfs
interface to modify the pin multiplexing and initialize the
GPIO part.
/* RS485 test program
* 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
#include
#include
#include
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#define FALSE
0
#define TRUE
1
#define DEF_BAUDRATE
115200
#define PIN138_GPIO
"E0080"
#define PIN138_RTS
"E0020"
#define GP2_3
67
#define DIR_OUT
"out"
#define MIN_RCV_CHARS
8
static const char *device
= "/dev/ttyO5";
static const char *pin_138
= "/sys/kernel/debug/omap_mux/vin0_hsync0";
static const char *dev_export
= "/sys/class/gpio/export";
static const char *dev_unexport =
"/sys/class/gpio/unexport";
static const char *dev_dir
= "/sys/class/gpio/gpio%d/direction";
static const char *dev_val
= "/sys/class/gpio/gpio%d/value";
static int fd;
int update_device (const char *dev, char *str, int seek_ctrl)
{
int
fd_tmp;
fd_tmp = open (dev, O_WRONLY);
if (fd_tmp < 0)
return
-1;