libnfc  1.4.2
uart.h
Go to the documentation of this file.
1 /*-
2  * Public platform independent Near Field Communication (NFC) library
3  *
4  * Copyright (C) 2009, 2010, Roel Verdult, Romuald Conty
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>
18  *
19  */
20 
26 #ifndef __NFC_BUS_UART_H__
27 # define __NFC_BUS_UART_H__
28 
29 # include <stdio.h>
30 # include <string.h>
31 # include <stdlib.h>
32 
33 
34 # include <nfc/nfc-types.h>
35 
36 // Handle platform specific includes
37 # ifndef _WIN32
38 # include <termios.h>
39 # include <sys/ioctl.h>
40 # include <unistd.h>
41 # include <fcntl.h>
42 # include <sys/types.h>
43 # include <sys/stat.h>
44 # include <limits.h>
45 # include <sys/time.h>
46 # include <unistd.h>
47 # define delay_ms( X ) usleep( X * 1000 )
48 # else
49 # include "contrib/windows.h"
50 # define delay_ms( X ) Sleep( X )
51 # endif
52 
53 // Path to the serial port is OS-dependant.
54 // Try to guess what we should use.
55 # if defined (_WIN32)
56 # define DEFAULT_SERIAL_PORTS { "COM1", "COM2", "COM3", "COM4", NULL }
57 # elif defined(__APPLE__)
58  // XXX: find UART connection string for PN53X device on Mac OS X when multiples devices are used
59 # define DEFAULT_SERIAL_PORTS { "/dev/tty.SLAB_USBtoUART", NULL }
60 # elif defined (__FreeBSD__) || defined (__OpenBSD__)
61  // XXX: Not tested
62 # define DEFAULT_SERIAL_PORTS { "/dev/cuau0", "/dev/cuau1", "/dev/cuau2", "/dev/cuau3", NULL }
63 # elif defined (__linux__)
64 # define DEFAULT_SERIAL_PORTS { "/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB2", "/dev/ttyUSB3", "/dev/ttyS0", "/dev/ttyS1", "/dev/ttyS2", "/dev/ttyS3", NULL }
65 # else
66 # error "Can't determine serial string for your system"
67 # endif
68 
69 // Define shortcut to types to make code more readable
70 typedef void *serial_port;
71 # define INVALID_SERIAL_PORT (void*)(~1)
72 # define CLAIMED_SERIAL_PORT (void*)(~2)
73 
74 serial_port uart_open (const char *pcPortName);
75 void uart_close (const serial_port sp);
76 
77 void uart_set_speed (serial_port sp, const uint32_t uiPortSpeed);
78 uint32_t uart_get_speed (const serial_port sp);
79 
80 int uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRx);
81 int uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx);
82 
83 #endif // __NFC_BUS_UART_H__