libnfc 1.3.9
|
00001 /*- 00002 * Public platform independent Near Field Communication (NFC) library 00003 * 00004 * Copyright (C) 2009, 2010, Roel Verdult, Romuald Conty 00005 * 00006 * This program is free software: you can redistribute it and/or modify it 00007 * under the terms of the GNU Lesser General Public License as published by the 00008 * Free Software Foundation, either version 3 of the License, or (at your 00009 * option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, but WITHOUT 00012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00014 * more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> 00018 * 00019 */ 00020 00026 #ifndef __NFC_BUS_UART_H__ 00027 # define __NFC_BUS_UART_H__ 00028 00029 # include <stdio.h> 00030 # include <string.h> 00031 # include <stdlib.h> 00032 00033 00034 # include <nfc/nfc-types.h> 00035 00036 // Handle platform specific includes 00037 # ifndef _WIN32 00038 # include <termios.h> 00039 # include <sys/ioctl.h> 00040 # include <unistd.h> 00041 # include <fcntl.h> 00042 # include <sys/types.h> 00043 # include <sys/stat.h> 00044 # include <limits.h> 00045 # include <sys/time.h> 00046 00047 // unistd.h is needed for usleep() fct. 00048 # include <unistd.h> 00049 # define delay_ms( X ) usleep( X * 1000 ) 00050 # else 00051 # include <windows.h> 00052 00053 # define snprintf _snprintf 00054 # define strdup _strdup 00055 # define delay_ms( X ) Sleep( X ) 00056 # endif 00057 00058 // Path to the serial port is OS-dependant. 00059 // Try to guess what we should use. 00060 // 00061 // XXX: Some review from users cross-compiling is welcome! 00062 # if defined (_WIN32) 00063 # define DEFAULT_SERIAL_PORTS { "COM1", "COM2", "COM3", "COM4", NULL } 00064 # elif defined(__APPLE__) 00065 // XXX: find UART connection string for PN53X device on Mac OS X when multiples devices are used 00066 # define DEFAULT_SERIAL_PORTS { "/dev/tty.SLAB_USBtoUART", NULL } 00067 # elif defined (__FreeBSD__) || defined (__OpenBSD__) 00068 // XXX: Not tested 00069 # define DEFAULT_SERIAL_PORTS { "/dev/cuau0", "/dev/cuau1", "/dev/cuau2", "/dev/cuau3", NULL } 00070 # elif defined (__linux__) 00071 # define DEFAULT_SERIAL_PORTS { "/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB2", "/dev/ttyUSB3", "/dev/tty0", "/dev/tty1", "/dev/tty2", "/dev/tty3", NULL } 00072 # else 00073 # error "Can't determine serial string for your system" 00074 # endif 00075 00076 // Define shortcut to types to make code more readable 00077 typedef void *serial_port; 00078 # define INVALID_SERIAL_PORT (void*)(~1) 00079 # define CLAIMED_SERIAL_PORT (void*)(~2) 00080 00081 serial_port uart_open (const char *pcPortName); 00082 void uart_close (const serial_port sp); 00083 00084 void uart_set_speed (serial_port sp, const uint32_t uiPortSpeed); 00085 uint32_t uart_get_speed (const serial_port sp); 00086 00087 int uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRxLen); 00088 int uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTxLen); 00089 00090 #endif // __NFC_BUS_UART_H__