libnfc
1.4.2
|
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 # include <unistd.h> 00047 # define delay_ms( X ) usleep( X * 1000 ) 00048 # else 00049 # include "contrib/windows.h" 00050 # define delay_ms( X ) Sleep( X ) 00051 # endif 00052 00053 // Path to the serial port is OS-dependant. 00054 // Try to guess what we should use. 00055 # if defined (_WIN32) 00056 # define DEFAULT_SERIAL_PORTS { "COM1", "COM2", "COM3", "COM4", NULL } 00057 # elif defined(__APPLE__) 00058 // XXX: find UART connection string for PN53X device on Mac OS X when multiples devices are used 00059 # define DEFAULT_SERIAL_PORTS { "/dev/tty.SLAB_USBtoUART", NULL } 00060 # elif defined (__FreeBSD__) || defined (__OpenBSD__) 00061 // XXX: Not tested 00062 # define DEFAULT_SERIAL_PORTS { "/dev/cuau0", "/dev/cuau1", "/dev/cuau2", "/dev/cuau3", NULL } 00063 # elif defined (__linux__) 00064 # define DEFAULT_SERIAL_PORTS { "/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB2", "/dev/ttyUSB3", "/dev/ttyS0", "/dev/ttyS1", "/dev/ttyS2", "/dev/ttyS3", NULL } 00065 # else 00066 # error "Can't determine serial string for your system" 00067 # endif 00068 00069 // Define shortcut to types to make code more readable 00070 typedef void *serial_port; 00071 # define INVALID_SERIAL_PORT (void*)(~1) 00072 # define CLAIMED_SERIAL_PORT (void*)(~2) 00073 00074 serial_port uart_open (const char *pcPortName); 00075 void uart_close (const serial_port sp); 00076 00077 void uart_set_speed (serial_port sp, const uint32_t uiPortSpeed); 00078 uint32_t uart_get_speed (const serial_port sp); 00079 00080 int uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRx); 00081 int uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx); 00082 00083 #endif // __NFC_BUS_UART_H__