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

KTD-S0057-I
Page 54 Linux® Programming Examples (DebianTM)
KTAM3874/pITX Software Guide
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
/****** Do not forget to enable UART2 and/or UART4 in U-Boot Setup ******/
static const char *device = "/dev/ttyO4";
/* Connector J2105 pin 11 to 14 */
/*static const char *device = "/dev/ttyO2";*/
/* Connector J2105 pin 29 to 32 */
static int fd;
static int transmit_uart_test_string (void)
{
__u8 tx[] = {
0x11,
/*
DC1
*/
0x05,
/* Data len */
0x48, 0x65, 0x6C, 0x6C, 0x6F,
/* Data = 'Hello' */
0x0A
/*
Checksum
*/
};
if (write (fd, tx, ARRAY_SIZE(tx)) != ARRAY_SIZE(tx))
return
-1;
return
0;
}
int init_uart_interface (void)
{
struct
termios
new_values;
fd = open (device, O_RDWR);
if (fd < 0)
return
-1;
memset (&new_values, 0, sizeof (new_values));
new_values.c_cflag = CS8 | CLOCAL;
if (cfsetospeed (&new_values, B115200))
return
-1;
return tcsetattr (fd, TCSANOW, &new_values);
}
int main (void)
{
printf ("\nUART Test for eDIP128-6\n");
if (init_uart_interface ())
{
close
(fd);
printf ("UART init error!\n\n");
return
-1;
}
if (transmit_uart_test_string ())
{
close
(fd);
printf ("UART transmission fails!\n\n");
return
-1;
}