A collection of Analog Devices drivers for the mbed platform
For additional information check out the mbed page of the Analog Devices wiki: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
libraries/libserialport/libserialport.h@27:3c32495708f4, 2016-05-24 (annotated)
- Committer:
- Paul Cercueil
- Date:
- Tue May 24 18:24:35 2016 +0200
- Revision:
- 27:3c32495708f4
Add libserialport library for mbed OS
Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Paul Cercueil |
27:3c32495708f4 | 1 | /* libserialport.h. Generated from libserialport.h.in by configure. */ |
Paul Cercueil |
27:3c32495708f4 | 2 | /* |
Paul Cercueil |
27:3c32495708f4 | 3 | * This file is part of the libserialport project. |
Paul Cercueil |
27:3c32495708f4 | 4 | * |
Paul Cercueil |
27:3c32495708f4 | 5 | * Copyright (C) 2013, 2015 Martin Ling <martin-libserialport@earth.li> |
Paul Cercueil |
27:3c32495708f4 | 6 | * Copyright (C) 2014 Uwe Hermann <uwe@hermann-uwe.de> |
Paul Cercueil |
27:3c32495708f4 | 7 | * Copyright (C) 2014 Aurelien Jacobs <aurel@gnuage.org> |
Paul Cercueil |
27:3c32495708f4 | 8 | * |
Paul Cercueil |
27:3c32495708f4 | 9 | * This program is free software: you can redistribute it and/or modify |
Paul Cercueil |
27:3c32495708f4 | 10 | * it under the terms of the GNU Lesser General Public License as |
Paul Cercueil |
27:3c32495708f4 | 11 | * published by the Free Software Foundation, either version 3 of the |
Paul Cercueil |
27:3c32495708f4 | 12 | * License, or (at your option) any later version. |
Paul Cercueil |
27:3c32495708f4 | 13 | * |
Paul Cercueil |
27:3c32495708f4 | 14 | * This program is distributed in the hope that it will be useful, |
Paul Cercueil |
27:3c32495708f4 | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Paul Cercueil |
27:3c32495708f4 | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Paul Cercueil |
27:3c32495708f4 | 17 | * GNU General Public License for more details. |
Paul Cercueil |
27:3c32495708f4 | 18 | * |
Paul Cercueil |
27:3c32495708f4 | 19 | * You should have received a copy of the GNU Lesser General Public License |
Paul Cercueil |
27:3c32495708f4 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Paul Cercueil |
27:3c32495708f4 | 21 | */ |
Paul Cercueil |
27:3c32495708f4 | 22 | |
Paul Cercueil |
27:3c32495708f4 | 23 | /** |
Paul Cercueil |
27:3c32495708f4 | 24 | * @mainpage libserialport API |
Paul Cercueil |
27:3c32495708f4 | 25 | * |
Paul Cercueil |
27:3c32495708f4 | 26 | * Introduction |
Paul Cercueil |
27:3c32495708f4 | 27 | * ============ |
Paul Cercueil |
27:3c32495708f4 | 28 | * |
Paul Cercueil |
27:3c32495708f4 | 29 | * libserialport is a minimal library written in C that is intended to take |
Paul Cercueil |
27:3c32495708f4 | 30 | * care of the OS-specific details when writing software that uses serial ports. |
Paul Cercueil |
27:3c32495708f4 | 31 | * |
Paul Cercueil |
27:3c32495708f4 | 32 | * By writing your serial code to use libserialport, you enable it to work |
Paul Cercueil |
27:3c32495708f4 | 33 | * transparently on any platform supported by the library. |
Paul Cercueil |
27:3c32495708f4 | 34 | * |
Paul Cercueil |
27:3c32495708f4 | 35 | * libserialport is an open source project released under the LGPL3+ license. |
Paul Cercueil |
27:3c32495708f4 | 36 | * |
Paul Cercueil |
27:3c32495708f4 | 37 | * The library is maintained by the [sigrok](http://sigrok.org/) project. See |
Paul Cercueil |
27:3c32495708f4 | 38 | * the [libserialport homepage](http://sigrok.org/wiki/Libserialport) for the |
Paul Cercueil |
27:3c32495708f4 | 39 | * latest information. |
Paul Cercueil |
27:3c32495708f4 | 40 | * |
Paul Cercueil |
27:3c32495708f4 | 41 | * Source code is maintained in git at |
Paul Cercueil |
27:3c32495708f4 | 42 | * [git://sigrok.org/libserialport](http://sigrok.org/gitweb/?p=libserialport.git). |
Paul Cercueil |
27:3c32495708f4 | 43 | * |
Paul Cercueil |
27:3c32495708f4 | 44 | * Bugs are tracked at http://sigrok.org/bugzilla/. |
Paul Cercueil |
27:3c32495708f4 | 45 | * |
Paul Cercueil |
27:3c32495708f4 | 46 | * The library was conceived and designed by Martin Ling, is maintained by |
Paul Cercueil |
27:3c32495708f4 | 47 | * Uwe Hermann, and has received contributions from several other developers. |
Paul Cercueil |
27:3c32495708f4 | 48 | * See the git history for full credits. |
Paul Cercueil |
27:3c32495708f4 | 49 | * |
Paul Cercueil |
27:3c32495708f4 | 50 | * API information |
Paul Cercueil |
27:3c32495708f4 | 51 | * =============== |
Paul Cercueil |
27:3c32495708f4 | 52 | * |
Paul Cercueil |
27:3c32495708f4 | 53 | * The API has been designed from scratch. It does not exactly resemble the |
Paul Cercueil |
27:3c32495708f4 | 54 | * serial API of any particular operating system. Instead it aims to provide |
Paul Cercueil |
27:3c32495708f4 | 55 | * a set of functions that can reliably be implemented across all operating |
Paul Cercueil |
27:3c32495708f4 | 56 | * systems. These form a sufficient basis for higher level behaviour to |
Paul Cercueil |
27:3c32495708f4 | 57 | * be implemented in a platform independent manner. |
Paul Cercueil |
27:3c32495708f4 | 58 | * |
Paul Cercueil |
27:3c32495708f4 | 59 | * If you are porting code written for a particular OS, you may find you need |
Paul Cercueil |
27:3c32495708f4 | 60 | * to restructure things somewhat, or do without some specialised features. |
Paul Cercueil |
27:3c32495708f4 | 61 | * For particular notes on porting existing code, see @ref Porting. |
Paul Cercueil |
27:3c32495708f4 | 62 | * |
Paul Cercueil |
27:3c32495708f4 | 63 | * The following subsections will help explain the principles of the API. |
Paul Cercueil |
27:3c32495708f4 | 64 | * |
Paul Cercueil |
27:3c32495708f4 | 65 | * Headers |
Paul Cercueil |
27:3c32495708f4 | 66 | * ------- |
Paul Cercueil |
27:3c32495708f4 | 67 | * |
Paul Cercueil |
27:3c32495708f4 | 68 | * To use libserialport functions in your code, you should include the |
Paul Cercueil |
27:3c32495708f4 | 69 | * libserialport.h header, i.e. "#include <libserialport.h>". |
Paul Cercueil |
27:3c32495708f4 | 70 | * |
Paul Cercueil |
27:3c32495708f4 | 71 | * Namespace |
Paul Cercueil |
27:3c32495708f4 | 72 | * --------- |
Paul Cercueil |
27:3c32495708f4 | 73 | * |
Paul Cercueil |
27:3c32495708f4 | 74 | * All identifiers defined by the public libserialport headers use the prefix |
Paul Cercueil |
27:3c32495708f4 | 75 | * sp_ (for functions and data types) or SP_ (for macros and constants). |
Paul Cercueil |
27:3c32495708f4 | 76 | * |
Paul Cercueil |
27:3c32495708f4 | 77 | * Functions |
Paul Cercueil |
27:3c32495708f4 | 78 | * --------- |
Paul Cercueil |
27:3c32495708f4 | 79 | * |
Paul Cercueil |
27:3c32495708f4 | 80 | * The functions provided by the library are documented in detail in |
Paul Cercueil |
27:3c32495708f4 | 81 | * the following sections: |
Paul Cercueil |
27:3c32495708f4 | 82 | * |
Paul Cercueil |
27:3c32495708f4 | 83 | * - @ref Enumeration (obtaining a list of serial ports on the system) |
Paul Cercueil |
27:3c32495708f4 | 84 | * - @ref Ports (opening, closing and getting information about ports) |
Paul Cercueil |
27:3c32495708f4 | 85 | * - @ref Configuration (baud rate, parity, etc.) |
Paul Cercueil |
27:3c32495708f4 | 86 | * - @ref Signals (modem control lines, breaks, etc.) |
Paul Cercueil |
27:3c32495708f4 | 87 | * - @ref Data (reading and writing data, and buffer management) |
Paul Cercueil |
27:3c32495708f4 | 88 | * - @ref Waiting (waiting for ports to be ready, integrating with event loops) |
Paul Cercueil |
27:3c32495708f4 | 89 | * - @ref Errors (getting error and debugging information) |
Paul Cercueil |
27:3c32495708f4 | 90 | * |
Paul Cercueil |
27:3c32495708f4 | 91 | * Data structures |
Paul Cercueil |
27:3c32495708f4 | 92 | * --------------- |
Paul Cercueil |
27:3c32495708f4 | 93 | * |
Paul Cercueil |
27:3c32495708f4 | 94 | * The library defines three data structures: |
Paul Cercueil |
27:3c32495708f4 | 95 | * |
Paul Cercueil |
27:3c32495708f4 | 96 | * - @ref sp_port, which represents a serial port. |
Paul Cercueil |
27:3c32495708f4 | 97 | * See @ref Enumeration. |
Paul Cercueil |
27:3c32495708f4 | 98 | * - @ref sp_port_config, which represents a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 99 | * See @ref Configuration. |
Paul Cercueil |
27:3c32495708f4 | 100 | * - @ref sp_event_set, which represents a set of events. |
Paul Cercueil |
27:3c32495708f4 | 101 | * See @ref Waiting. |
Paul Cercueil |
27:3c32495708f4 | 102 | * |
Paul Cercueil |
27:3c32495708f4 | 103 | * All these structures are allocated and freed by library functions. It is |
Paul Cercueil |
27:3c32495708f4 | 104 | * the caller's responsibility to ensure that the correct calls are made to |
Paul Cercueil |
27:3c32495708f4 | 105 | * free allocated structures after use. |
Paul Cercueil |
27:3c32495708f4 | 106 | * |
Paul Cercueil |
27:3c32495708f4 | 107 | * Return codes and error handling |
Paul Cercueil |
27:3c32495708f4 | 108 | * ------------------------------- |
Paul Cercueil |
27:3c32495708f4 | 109 | * |
Paul Cercueil |
27:3c32495708f4 | 110 | * Most functions have return type @ref sp_return and can return only four |
Paul Cercueil |
27:3c32495708f4 | 111 | * possible error values: |
Paul Cercueil |
27:3c32495708f4 | 112 | * |
Paul Cercueil |
27:3c32495708f4 | 113 | * - @ref SP_ERR_ARG means that a function was called with invalid |
Paul Cercueil |
27:3c32495708f4 | 114 | * arguments. This implies a bug in the caller. The arguments passed would |
Paul Cercueil |
27:3c32495708f4 | 115 | * be invalid regardless of the underlying OS or serial device involved. |
Paul Cercueil |
27:3c32495708f4 | 116 | * |
Paul Cercueil |
27:3c32495708f4 | 117 | * - @ref SP_ERR_FAIL means that the OS reported a failure. The error code or |
Paul Cercueil |
27:3c32495708f4 | 118 | * message provided by the OS can be obtained by calling sp_last_error_code() |
Paul Cercueil |
27:3c32495708f4 | 119 | * or sp_last_error_message(). |
Paul Cercueil |
27:3c32495708f4 | 120 | * |
Paul Cercueil |
27:3c32495708f4 | 121 | * - @ref SP_ERR_SUPP indicates that there is no support for the requested |
Paul Cercueil |
27:3c32495708f4 | 122 | * operation in the current OS, driver or device. No error message is |
Paul Cercueil |
27:3c32495708f4 | 123 | * available from the OS in this case. There is either no way to request |
Paul Cercueil |
27:3c32495708f4 | 124 | * the operation in the first place, or libserialport does not know how to |
Paul Cercueil |
27:3c32495708f4 | 125 | * do so in the current version. |
Paul Cercueil |
27:3c32495708f4 | 126 | * |
Paul Cercueil |
27:3c32495708f4 | 127 | * - @ref SP_ERR_MEM indicates that a memory allocation failed. |
Paul Cercueil |
27:3c32495708f4 | 128 | * |
Paul Cercueil |
27:3c32495708f4 | 129 | * All of these error values are negative. |
Paul Cercueil |
27:3c32495708f4 | 130 | * |
Paul Cercueil |
27:3c32495708f4 | 131 | * Calls that succeed return @ref SP_OK, which is equal to zero. Some functions |
Paul Cercueil |
27:3c32495708f4 | 132 | * declared @ref sp_return can also return a positive value for a successful |
Paul Cercueil |
27:3c32495708f4 | 133 | * numeric result, e.g. sp_blocking_read() or sp_blocking_write(). |
Paul Cercueil |
27:3c32495708f4 | 134 | * |
Paul Cercueil |
27:3c32495708f4 | 135 | * An error message is only available via sp_last_error_message() in the case |
Paul Cercueil |
27:3c32495708f4 | 136 | * where SP_ERR_FAIL was returned by the previous function call. The error |
Paul Cercueil |
27:3c32495708f4 | 137 | * message returned is that provided by the OS, using the current language |
Paul Cercueil |
27:3c32495708f4 | 138 | * settings. It is an error to call sp_last_error_code() or |
Paul Cercueil |
27:3c32495708f4 | 139 | * sp_last_error_message() except after a previous function call returned |
Paul Cercueil |
27:3c32495708f4 | 140 | * SP_ERR_FAIL. The library does not define its own error codes or messages |
Paul Cercueil |
27:3c32495708f4 | 141 | * to accompany other return codes. |
Paul Cercueil |
27:3c32495708f4 | 142 | * |
Paul Cercueil |
27:3c32495708f4 | 143 | * Thread safety |
Paul Cercueil |
27:3c32495708f4 | 144 | * ------------- |
Paul Cercueil |
27:3c32495708f4 | 145 | * |
Paul Cercueil |
27:3c32495708f4 | 146 | * Certain combinations of calls can be made concurrently, as follows. |
Paul Cercueil |
27:3c32495708f4 | 147 | * |
Paul Cercueil |
27:3c32495708f4 | 148 | * - Calls using different ports may always be made concurrently, i.e. |
Paul Cercueil |
27:3c32495708f4 | 149 | * it is safe for separate threads to handle their own ports. |
Paul Cercueil |
27:3c32495708f4 | 150 | * |
Paul Cercueil |
27:3c32495708f4 | 151 | * - Calls using the same port may be made concurrently when one call |
Paul Cercueil |
27:3c32495708f4 | 152 | * is a read operation and one call is a write operation, i.e. it is safe |
Paul Cercueil |
27:3c32495708f4 | 153 | * to use separate "reader" and "writer" threads for the same port. See |
Paul Cercueil |
27:3c32495708f4 | 154 | * below for which operations meet these definitions. |
Paul Cercueil |
27:3c32495708f4 | 155 | * |
Paul Cercueil |
27:3c32495708f4 | 156 | * Read operations: |
Paul Cercueil |
27:3c32495708f4 | 157 | * |
Paul Cercueil |
27:3c32495708f4 | 158 | * - sp_blocking_read() |
Paul Cercueil |
27:3c32495708f4 | 159 | * - sp_blocking_read_next() |
Paul Cercueil |
27:3c32495708f4 | 160 | * - sp_nonblocking_read() |
Paul Cercueil |
27:3c32495708f4 | 161 | * - sp_input_waiting() |
Paul Cercueil |
27:3c32495708f4 | 162 | * - sp_flush() with @ref SP_BUF_INPUT only. |
Paul Cercueil |
27:3c32495708f4 | 163 | * - sp_wait() with @ref SP_EVENT_RX_READY only. |
Paul Cercueil |
27:3c32495708f4 | 164 | * |
Paul Cercueil |
27:3c32495708f4 | 165 | * Write operations: |
Paul Cercueil |
27:3c32495708f4 | 166 | * |
Paul Cercueil |
27:3c32495708f4 | 167 | * - sp_blocking_write() |
Paul Cercueil |
27:3c32495708f4 | 168 | * - sp_nonblocking_write() |
Paul Cercueil |
27:3c32495708f4 | 169 | * - sp_output_waiting() |
Paul Cercueil |
27:3c32495708f4 | 170 | * - sp_drain() |
Paul Cercueil |
27:3c32495708f4 | 171 | * - sp_flush() with @ref SP_BUF_OUTPUT only. |
Paul Cercueil |
27:3c32495708f4 | 172 | * - sp_wait() with @ref SP_EVENT_TX_READY only. |
Paul Cercueil |
27:3c32495708f4 | 173 | * |
Paul Cercueil |
27:3c32495708f4 | 174 | * If two calls, on the same port, do not fit into one of these categories |
Paul Cercueil |
27:3c32495708f4 | 175 | * each, then they may not be made concurrently. |
Paul Cercueil |
27:3c32495708f4 | 176 | * |
Paul Cercueil |
27:3c32495708f4 | 177 | * Debugging |
Paul Cercueil |
27:3c32495708f4 | 178 | * --------- |
Paul Cercueil |
27:3c32495708f4 | 179 | * |
Paul Cercueil |
27:3c32495708f4 | 180 | * The library can output extensive tracing and debugging information. The |
Paul Cercueil |
27:3c32495708f4 | 181 | * simplest way to use this is to set the environment variable |
Paul Cercueil |
27:3c32495708f4 | 182 | * LIBSERIALPORT_DEBUG to any value; messages will then be output to the |
Paul Cercueil |
27:3c32495708f4 | 183 | * standard error stream. |
Paul Cercueil |
27:3c32495708f4 | 184 | * |
Paul Cercueil |
27:3c32495708f4 | 185 | * This behaviour is implemented by a default debug message handling |
Paul Cercueil |
27:3c32495708f4 | 186 | * callback. An alternative callback can be set using sp_set_debug_handler(), |
Paul Cercueil |
27:3c32495708f4 | 187 | * in order to e.g. redirect the output elsewhere or filter it. |
Paul Cercueil |
27:3c32495708f4 | 188 | * |
Paul Cercueil |
27:3c32495708f4 | 189 | * No guarantees are made about the content of the debug output; it is chosen |
Paul Cercueil |
27:3c32495708f4 | 190 | * to suit the needs of the developers and may change between releases. |
Paul Cercueil |
27:3c32495708f4 | 191 | * |
Paul Cercueil |
27:3c32495708f4 | 192 | * @anchor Porting |
Paul Cercueil |
27:3c32495708f4 | 193 | * Porting |
Paul Cercueil |
27:3c32495708f4 | 194 | * ------- |
Paul Cercueil |
27:3c32495708f4 | 195 | * |
Paul Cercueil |
27:3c32495708f4 | 196 | * The following guidelines may help when porting existing OS-specific code |
Paul Cercueil |
27:3c32495708f4 | 197 | * to use libserialport. |
Paul Cercueil |
27:3c32495708f4 | 198 | * |
Paul Cercueil |
27:3c32495708f4 | 199 | * ### Porting from Unix-like systems ### |
Paul Cercueil |
27:3c32495708f4 | 200 | * |
Paul Cercueil |
27:3c32495708f4 | 201 | * There are two main differences to note when porting code written for Unix. |
Paul Cercueil |
27:3c32495708f4 | 202 | * |
Paul Cercueil |
27:3c32495708f4 | 203 | * The first is that Unix traditionally provides a wide range of functionality |
Paul Cercueil |
27:3c32495708f4 | 204 | * for dealing with serial devices at the OS level; this is exposed through the |
Paul Cercueil |
27:3c32495708f4 | 205 | * termios API and dates to the days when serial terminals were common. If your |
Paul Cercueil |
27:3c32495708f4 | 206 | * code relies on many of these facilities you will need to adapt it, because |
Paul Cercueil |
27:3c32495708f4 | 207 | * libserialport provides only a raw binary channel with no special handling. |
Paul Cercueil |
27:3c32495708f4 | 208 | * |
Paul Cercueil |
27:3c32495708f4 | 209 | * The second relates to blocking versus non-blocking I/O behaviour. In |
Paul Cercueil |
27:3c32495708f4 | 210 | * Unix-like systems this is normally specified by setting the O_NONBLOCK |
Paul Cercueil |
27:3c32495708f4 | 211 | * flag on the file descriptor, affecting the semantics of subsequent read() |
Paul Cercueil |
27:3c32495708f4 | 212 | * and write() calls. |
Paul Cercueil |
27:3c32495708f4 | 213 | * |
Paul Cercueil |
27:3c32495708f4 | 214 | * In libserialport, blocking and nonblocking operations are both available at |
Paul Cercueil |
27:3c32495708f4 | 215 | * any time. If your existing code ѕets O_NONBLOCK, you should use |
Paul Cercueil |
27:3c32495708f4 | 216 | * sp_nonblocking_read() and sp_nonblocking_write() to get the same behaviour |
Paul Cercueil |
27:3c32495708f4 | 217 | * as your existing read() and write() calls. If it does not, you should use |
Paul Cercueil |
27:3c32495708f4 | 218 | * sp_blocking_read() and sp_blocking_write() instead. You may also find |
Paul Cercueil |
27:3c32495708f4 | 219 | * sp_blocking_read_next() useful, which reproduces the semantics of a blocking |
Paul Cercueil |
27:3c32495708f4 | 220 | * read() with VTIME = 0 and VMIN = 1 set in termios. |
Paul Cercueil |
27:3c32495708f4 | 221 | * |
Paul Cercueil |
27:3c32495708f4 | 222 | * Finally, you should take care if your program uses custom signal handlers. |
Paul Cercueil |
27:3c32495708f4 | 223 | * The blocking calls provided by libserialport will restart system calls that |
Paul Cercueil |
27:3c32495708f4 | 224 | * return with EINTR, so you will need to make your own arrangements if you |
Paul Cercueil |
27:3c32495708f4 | 225 | * need to interrupt blocking operations when your signal handlers are called. |
Paul Cercueil |
27:3c32495708f4 | 226 | * This is not an issue if you only use the default handlers. |
Paul Cercueil |
27:3c32495708f4 | 227 | * |
Paul Cercueil |
27:3c32495708f4 | 228 | * ### Porting from Windows ### |
Paul Cercueil |
27:3c32495708f4 | 229 | * |
Paul Cercueil |
27:3c32495708f4 | 230 | * The main consideration when porting from Windows is that there is no |
Paul Cercueil |
27:3c32495708f4 | 231 | * direct equivalent for overlapped I/O operations. |
Paul Cercueil |
27:3c32495708f4 | 232 | * |
Paul Cercueil |
27:3c32495708f4 | 233 | * If your program does not use overlapped I/O, you can simply use |
Paul Cercueil |
27:3c32495708f4 | 234 | * sp_blocking_read() and sp_blocking_write() as direct equivalents for |
Paul Cercueil |
27:3c32495708f4 | 235 | * ReadFile() and WriteFile(). You may also find sp_blocking_read_next() |
Paul Cercueil |
27:3c32495708f4 | 236 | * useful, which reproduces the special semantics of ReadFile() with |
Paul Cercueil |
27:3c32495708f4 | 237 | * ReadIntervalTimeout and ReadTotalTimeoutMultiplier set to MAXDWORD |
Paul Cercueil |
27:3c32495708f4 | 238 | * and 0 < ReadTotalTimeoutConstant < MAXDWORD. |
Paul Cercueil |
27:3c32495708f4 | 239 | * |
Paul Cercueil |
27:3c32495708f4 | 240 | * If your program makes use of overlapped I/O to continue work while a serial |
Paul Cercueil |
27:3c32495708f4 | 241 | * operation is in progress, then you can achieve the same results using |
Paul Cercueil |
27:3c32495708f4 | 242 | * sp_nonblocking_read() and sp_nonblocking_write(). |
Paul Cercueil |
27:3c32495708f4 | 243 | * |
Paul Cercueil |
27:3c32495708f4 | 244 | * Generally, overlapped I/O is combined with either waiting for completion |
Paul Cercueil |
27:3c32495708f4 | 245 | * once there is no more background work to do (using WaitForSingleObject() or |
Paul Cercueil |
27:3c32495708f4 | 246 | * WaitForMultipleObjects()), or periodically checking for completion with |
Paul Cercueil |
27:3c32495708f4 | 247 | * GetOverlappedResult(). If the aim is to start a new operation for further |
Paul Cercueil |
27:3c32495708f4 | 248 | * data once the previous one has completed, you can instead simply call the |
Paul Cercueil |
27:3c32495708f4 | 249 | * nonblocking functions again with the next data. If you need to wait for |
Paul Cercueil |
27:3c32495708f4 | 250 | * completion, use sp_wait() to determine when the port is ready to send or |
Paul Cercueil |
27:3c32495708f4 | 251 | * receive further data. |
Paul Cercueil |
27:3c32495708f4 | 252 | */ |
Paul Cercueil |
27:3c32495708f4 | 253 | |
Paul Cercueil |
27:3c32495708f4 | 254 | #ifndef LIBSERIALPORT_LIBSERIALPORT_H |
Paul Cercueil |
27:3c32495708f4 | 255 | #define LIBSERIALPORT_LIBSERIALPORT_H |
Paul Cercueil |
27:3c32495708f4 | 256 | |
Paul Cercueil |
27:3c32495708f4 | 257 | #ifdef __cplusplus |
Paul Cercueil |
27:3c32495708f4 | 258 | extern "C" { |
Paul Cercueil |
27:3c32495708f4 | 259 | #endif |
Paul Cercueil |
27:3c32495708f4 | 260 | |
Paul Cercueil |
27:3c32495708f4 | 261 | #include <stddef.h> |
Paul Cercueil |
27:3c32495708f4 | 262 | |
Paul Cercueil |
27:3c32495708f4 | 263 | /** Return values. */ |
Paul Cercueil |
27:3c32495708f4 | 264 | enum sp_return { |
Paul Cercueil |
27:3c32495708f4 | 265 | /** Operation completed successfully. */ |
Paul Cercueil |
27:3c32495708f4 | 266 | SP_OK = 0, |
Paul Cercueil |
27:3c32495708f4 | 267 | /** Invalid arguments were passed to the function. */ |
Paul Cercueil |
27:3c32495708f4 | 268 | SP_ERR_ARG = -1, |
Paul Cercueil |
27:3c32495708f4 | 269 | /** A system error occurred while executing the operation. */ |
Paul Cercueil |
27:3c32495708f4 | 270 | SP_ERR_FAIL = -2, |
Paul Cercueil |
27:3c32495708f4 | 271 | /** A memory allocation failed while executing the operation. */ |
Paul Cercueil |
27:3c32495708f4 | 272 | SP_ERR_MEM = -3, |
Paul Cercueil |
27:3c32495708f4 | 273 | /** The requested operation is not supported by this system or device. */ |
Paul Cercueil |
27:3c32495708f4 | 274 | SP_ERR_SUPP = -4 |
Paul Cercueil |
27:3c32495708f4 | 275 | }; |
Paul Cercueil |
27:3c32495708f4 | 276 | |
Paul Cercueil |
27:3c32495708f4 | 277 | /** Port access modes. */ |
Paul Cercueil |
27:3c32495708f4 | 278 | enum sp_mode { |
Paul Cercueil |
27:3c32495708f4 | 279 | /** Open port for read access. */ |
Paul Cercueil |
27:3c32495708f4 | 280 | SP_MODE_READ = 1, |
Paul Cercueil |
27:3c32495708f4 | 281 | /** Open port for write access. */ |
Paul Cercueil |
27:3c32495708f4 | 282 | SP_MODE_WRITE = 2, |
Paul Cercueil |
27:3c32495708f4 | 283 | /** Open port for read and write access. @since 0.1.1 */ |
Paul Cercueil |
27:3c32495708f4 | 284 | SP_MODE_READ_WRITE = 3 |
Paul Cercueil |
27:3c32495708f4 | 285 | }; |
Paul Cercueil |
27:3c32495708f4 | 286 | |
Paul Cercueil |
27:3c32495708f4 | 287 | /** Port events. */ |
Paul Cercueil |
27:3c32495708f4 | 288 | enum sp_event { |
Paul Cercueil |
27:3c32495708f4 | 289 | /** Data received and ready to read. */ |
Paul Cercueil |
27:3c32495708f4 | 290 | SP_EVENT_RX_READY = 1, |
Paul Cercueil |
27:3c32495708f4 | 291 | /** Ready to transmit new data. */ |
Paul Cercueil |
27:3c32495708f4 | 292 | SP_EVENT_TX_READY = 2, |
Paul Cercueil |
27:3c32495708f4 | 293 | /** Error occurred. */ |
Paul Cercueil |
27:3c32495708f4 | 294 | SP_EVENT_ERROR = 4 |
Paul Cercueil |
27:3c32495708f4 | 295 | }; |
Paul Cercueil |
27:3c32495708f4 | 296 | |
Paul Cercueil |
27:3c32495708f4 | 297 | /** Buffer selection. */ |
Paul Cercueil |
27:3c32495708f4 | 298 | enum sp_buffer { |
Paul Cercueil |
27:3c32495708f4 | 299 | /** Input buffer. */ |
Paul Cercueil |
27:3c32495708f4 | 300 | SP_BUF_INPUT = 1, |
Paul Cercueil |
27:3c32495708f4 | 301 | /** Output buffer. */ |
Paul Cercueil |
27:3c32495708f4 | 302 | SP_BUF_OUTPUT = 2, |
Paul Cercueil |
27:3c32495708f4 | 303 | /** Both buffers. */ |
Paul Cercueil |
27:3c32495708f4 | 304 | SP_BUF_BOTH = 3 |
Paul Cercueil |
27:3c32495708f4 | 305 | }; |
Paul Cercueil |
27:3c32495708f4 | 306 | |
Paul Cercueil |
27:3c32495708f4 | 307 | /** Parity settings. */ |
Paul Cercueil |
27:3c32495708f4 | 308 | enum sp_parity { |
Paul Cercueil |
27:3c32495708f4 | 309 | /** Special value to indicate setting should be left alone. */ |
Paul Cercueil |
27:3c32495708f4 | 310 | SP_PARITY_INVALID = -1, |
Paul Cercueil |
27:3c32495708f4 | 311 | /** No parity. */ |
Paul Cercueil |
27:3c32495708f4 | 312 | SP_PARITY_NONE = 0, |
Paul Cercueil |
27:3c32495708f4 | 313 | /** Odd parity. */ |
Paul Cercueil |
27:3c32495708f4 | 314 | SP_PARITY_ODD = 1, |
Paul Cercueil |
27:3c32495708f4 | 315 | /** Even parity. */ |
Paul Cercueil |
27:3c32495708f4 | 316 | SP_PARITY_EVEN = 2, |
Paul Cercueil |
27:3c32495708f4 | 317 | /** Mark parity. */ |
Paul Cercueil |
27:3c32495708f4 | 318 | SP_PARITY_MARK = 3, |
Paul Cercueil |
27:3c32495708f4 | 319 | /** Space parity. */ |
Paul Cercueil |
27:3c32495708f4 | 320 | SP_PARITY_SPACE = 4 |
Paul Cercueil |
27:3c32495708f4 | 321 | }; |
Paul Cercueil |
27:3c32495708f4 | 322 | |
Paul Cercueil |
27:3c32495708f4 | 323 | /** RTS pin behaviour. */ |
Paul Cercueil |
27:3c32495708f4 | 324 | enum sp_rts { |
Paul Cercueil |
27:3c32495708f4 | 325 | /** Special value to indicate setting should be left alone. */ |
Paul Cercueil |
27:3c32495708f4 | 326 | SP_RTS_INVALID = -1, |
Paul Cercueil |
27:3c32495708f4 | 327 | /** RTS off. */ |
Paul Cercueil |
27:3c32495708f4 | 328 | SP_RTS_OFF = 0, |
Paul Cercueil |
27:3c32495708f4 | 329 | /** RTS on. */ |
Paul Cercueil |
27:3c32495708f4 | 330 | SP_RTS_ON = 1, |
Paul Cercueil |
27:3c32495708f4 | 331 | /** RTS used for flow control. */ |
Paul Cercueil |
27:3c32495708f4 | 332 | SP_RTS_FLOW_CONTROL = 2 |
Paul Cercueil |
27:3c32495708f4 | 333 | }; |
Paul Cercueil |
27:3c32495708f4 | 334 | |
Paul Cercueil |
27:3c32495708f4 | 335 | /** CTS pin behaviour. */ |
Paul Cercueil |
27:3c32495708f4 | 336 | enum sp_cts { |
Paul Cercueil |
27:3c32495708f4 | 337 | /** Special value to indicate setting should be left alone. */ |
Paul Cercueil |
27:3c32495708f4 | 338 | SP_CTS_INVALID = -1, |
Paul Cercueil |
27:3c32495708f4 | 339 | /** CTS ignored. */ |
Paul Cercueil |
27:3c32495708f4 | 340 | SP_CTS_IGNORE = 0, |
Paul Cercueil |
27:3c32495708f4 | 341 | /** CTS used for flow control. */ |
Paul Cercueil |
27:3c32495708f4 | 342 | SP_CTS_FLOW_CONTROL = 1 |
Paul Cercueil |
27:3c32495708f4 | 343 | }; |
Paul Cercueil |
27:3c32495708f4 | 344 | |
Paul Cercueil |
27:3c32495708f4 | 345 | /** DTR pin behaviour. */ |
Paul Cercueil |
27:3c32495708f4 | 346 | enum sp_dtr { |
Paul Cercueil |
27:3c32495708f4 | 347 | /** Special value to indicate setting should be left alone. */ |
Paul Cercueil |
27:3c32495708f4 | 348 | SP_DTR_INVALID = -1, |
Paul Cercueil |
27:3c32495708f4 | 349 | /** DTR off. */ |
Paul Cercueil |
27:3c32495708f4 | 350 | SP_DTR_OFF = 0, |
Paul Cercueil |
27:3c32495708f4 | 351 | /** DTR on. */ |
Paul Cercueil |
27:3c32495708f4 | 352 | SP_DTR_ON = 1, |
Paul Cercueil |
27:3c32495708f4 | 353 | /** DTR used for flow control. */ |
Paul Cercueil |
27:3c32495708f4 | 354 | SP_DTR_FLOW_CONTROL = 2 |
Paul Cercueil |
27:3c32495708f4 | 355 | }; |
Paul Cercueil |
27:3c32495708f4 | 356 | |
Paul Cercueil |
27:3c32495708f4 | 357 | /** DSR pin behaviour. */ |
Paul Cercueil |
27:3c32495708f4 | 358 | enum sp_dsr { |
Paul Cercueil |
27:3c32495708f4 | 359 | /** Special value to indicate setting should be left alone. */ |
Paul Cercueil |
27:3c32495708f4 | 360 | SP_DSR_INVALID = -1, |
Paul Cercueil |
27:3c32495708f4 | 361 | /** DSR ignored. */ |
Paul Cercueil |
27:3c32495708f4 | 362 | SP_DSR_IGNORE = 0, |
Paul Cercueil |
27:3c32495708f4 | 363 | /** DSR used for flow control. */ |
Paul Cercueil |
27:3c32495708f4 | 364 | SP_DSR_FLOW_CONTROL = 1 |
Paul Cercueil |
27:3c32495708f4 | 365 | }; |
Paul Cercueil |
27:3c32495708f4 | 366 | |
Paul Cercueil |
27:3c32495708f4 | 367 | /** XON/XOFF flow control behaviour. */ |
Paul Cercueil |
27:3c32495708f4 | 368 | enum sp_xonxoff { |
Paul Cercueil |
27:3c32495708f4 | 369 | /** Special value to indicate setting should be left alone. */ |
Paul Cercueil |
27:3c32495708f4 | 370 | SP_XONXOFF_INVALID = -1, |
Paul Cercueil |
27:3c32495708f4 | 371 | /** XON/XOFF disabled. */ |
Paul Cercueil |
27:3c32495708f4 | 372 | SP_XONXOFF_DISABLED = 0, |
Paul Cercueil |
27:3c32495708f4 | 373 | /** XON/XOFF enabled for input only. */ |
Paul Cercueil |
27:3c32495708f4 | 374 | SP_XONXOFF_IN = 1, |
Paul Cercueil |
27:3c32495708f4 | 375 | /** XON/XOFF enabled for output only. */ |
Paul Cercueil |
27:3c32495708f4 | 376 | SP_XONXOFF_OUT = 2, |
Paul Cercueil |
27:3c32495708f4 | 377 | /** XON/XOFF enabled for input and output. */ |
Paul Cercueil |
27:3c32495708f4 | 378 | SP_XONXOFF_INOUT = 3 |
Paul Cercueil |
27:3c32495708f4 | 379 | }; |
Paul Cercueil |
27:3c32495708f4 | 380 | |
Paul Cercueil |
27:3c32495708f4 | 381 | /** Standard flow control combinations. */ |
Paul Cercueil |
27:3c32495708f4 | 382 | enum sp_flowcontrol { |
Paul Cercueil |
27:3c32495708f4 | 383 | /** No flow control. */ |
Paul Cercueil |
27:3c32495708f4 | 384 | SP_FLOWCONTROL_NONE = 0, |
Paul Cercueil |
27:3c32495708f4 | 385 | /** Software flow control using XON/XOFF characters. */ |
Paul Cercueil |
27:3c32495708f4 | 386 | SP_FLOWCONTROL_XONXOFF = 1, |
Paul Cercueil |
27:3c32495708f4 | 387 | /** Hardware flow control using RTS/CTS signals. */ |
Paul Cercueil |
27:3c32495708f4 | 388 | SP_FLOWCONTROL_RTSCTS = 2, |
Paul Cercueil |
27:3c32495708f4 | 389 | /** Hardware flow control using DTR/DSR signals. */ |
Paul Cercueil |
27:3c32495708f4 | 390 | SP_FLOWCONTROL_DTRDSR = 3 |
Paul Cercueil |
27:3c32495708f4 | 391 | }; |
Paul Cercueil |
27:3c32495708f4 | 392 | |
Paul Cercueil |
27:3c32495708f4 | 393 | /** Input signals. */ |
Paul Cercueil |
27:3c32495708f4 | 394 | enum sp_signal { |
Paul Cercueil |
27:3c32495708f4 | 395 | /** Clear to send. */ |
Paul Cercueil |
27:3c32495708f4 | 396 | SP_SIG_CTS = 1, |
Paul Cercueil |
27:3c32495708f4 | 397 | /** Data set ready. */ |
Paul Cercueil |
27:3c32495708f4 | 398 | SP_SIG_DSR = 2, |
Paul Cercueil |
27:3c32495708f4 | 399 | /** Data carrier detect. */ |
Paul Cercueil |
27:3c32495708f4 | 400 | SP_SIG_DCD = 4, |
Paul Cercueil |
27:3c32495708f4 | 401 | /** Ring indicator. */ |
Paul Cercueil |
27:3c32495708f4 | 402 | SP_SIG_RI = 8 |
Paul Cercueil |
27:3c32495708f4 | 403 | }; |
Paul Cercueil |
27:3c32495708f4 | 404 | |
Paul Cercueil |
27:3c32495708f4 | 405 | /** |
Paul Cercueil |
27:3c32495708f4 | 406 | * Transport types. |
Paul Cercueil |
27:3c32495708f4 | 407 | * |
Paul Cercueil |
27:3c32495708f4 | 408 | * @since 0.1.1 |
Paul Cercueil |
27:3c32495708f4 | 409 | */ |
Paul Cercueil |
27:3c32495708f4 | 410 | enum sp_transport { |
Paul Cercueil |
27:3c32495708f4 | 411 | /** Native platform serial port. @since 0.1.1 */ |
Paul Cercueil |
27:3c32495708f4 | 412 | SP_TRANSPORT_NATIVE, |
Paul Cercueil |
27:3c32495708f4 | 413 | /** USB serial port adapter. @since 0.1.1 */ |
Paul Cercueil |
27:3c32495708f4 | 414 | SP_TRANSPORT_USB, |
Paul Cercueil |
27:3c32495708f4 | 415 | /** Bluetooth serial port adapter. @since 0.1.1 */ |
Paul Cercueil |
27:3c32495708f4 | 416 | SP_TRANSPORT_BLUETOOTH |
Paul Cercueil |
27:3c32495708f4 | 417 | }; |
Paul Cercueil |
27:3c32495708f4 | 418 | |
Paul Cercueil |
27:3c32495708f4 | 419 | /** |
Paul Cercueil |
27:3c32495708f4 | 420 | * @struct sp_port |
Paul Cercueil |
27:3c32495708f4 | 421 | * An opaque structure representing a serial port. |
Paul Cercueil |
27:3c32495708f4 | 422 | */ |
Paul Cercueil |
27:3c32495708f4 | 423 | struct sp_port; |
Paul Cercueil |
27:3c32495708f4 | 424 | |
Paul Cercueil |
27:3c32495708f4 | 425 | /** |
Paul Cercueil |
27:3c32495708f4 | 426 | * @struct sp_port_config |
Paul Cercueil |
27:3c32495708f4 | 427 | * An opaque structure representing the configuration for a serial port. |
Paul Cercueil |
27:3c32495708f4 | 428 | */ |
Paul Cercueil |
27:3c32495708f4 | 429 | struct sp_port_config; |
Paul Cercueil |
27:3c32495708f4 | 430 | |
Paul Cercueil |
27:3c32495708f4 | 431 | /** |
Paul Cercueil |
27:3c32495708f4 | 432 | * @struct sp_event_set |
Paul Cercueil |
27:3c32495708f4 | 433 | * A set of handles to wait on for events. |
Paul Cercueil |
27:3c32495708f4 | 434 | */ |
Paul Cercueil |
27:3c32495708f4 | 435 | struct sp_event_set { |
Paul Cercueil |
27:3c32495708f4 | 436 | /** Array of OS-specific handles. */ |
Paul Cercueil |
27:3c32495708f4 | 437 | void *handles; |
Paul Cercueil |
27:3c32495708f4 | 438 | /** Array of bitmasks indicating which events apply for each handle. */ |
Paul Cercueil |
27:3c32495708f4 | 439 | enum sp_event *masks; |
Paul Cercueil |
27:3c32495708f4 | 440 | /** Number of handles. */ |
Paul Cercueil |
27:3c32495708f4 | 441 | unsigned int count; |
Paul Cercueil |
27:3c32495708f4 | 442 | }; |
Paul Cercueil |
27:3c32495708f4 | 443 | |
Paul Cercueil |
27:3c32495708f4 | 444 | /** |
Paul Cercueil |
27:3c32495708f4 | 445 | * @defgroup Enumeration Port enumeration |
Paul Cercueil |
27:3c32495708f4 | 446 | * |
Paul Cercueil |
27:3c32495708f4 | 447 | * Enumerating the serial ports of a system. |
Paul Cercueil |
27:3c32495708f4 | 448 | * |
Paul Cercueil |
27:3c32495708f4 | 449 | * @{ |
Paul Cercueil |
27:3c32495708f4 | 450 | */ |
Paul Cercueil |
27:3c32495708f4 | 451 | |
Paul Cercueil |
27:3c32495708f4 | 452 | /** |
Paul Cercueil |
27:3c32495708f4 | 453 | * Obtain a pointer to a new sp_port structure representing the named port. |
Paul Cercueil |
27:3c32495708f4 | 454 | * |
Paul Cercueil |
27:3c32495708f4 | 455 | * The user should allocate a variable of type "struct sp_port *" and pass a |
Paul Cercueil |
27:3c32495708f4 | 456 | * pointer to this to receive the result. |
Paul Cercueil |
27:3c32495708f4 | 457 | * |
Paul Cercueil |
27:3c32495708f4 | 458 | * The result should be freed after use by calling sp_free_port(). |
Paul Cercueil |
27:3c32495708f4 | 459 | * |
Paul Cercueil |
27:3c32495708f4 | 460 | * @param[in] portname The OS-specific name of a serial port. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 461 | * @param[out] port_ptr If any error is returned, the variable pointed to by |
Paul Cercueil |
27:3c32495708f4 | 462 | * port_ptr will be set to NULL. Otherwise, it will be set |
Paul Cercueil |
27:3c32495708f4 | 463 | * to point to the newly allocated port. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 464 | * |
Paul Cercueil |
27:3c32495708f4 | 465 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 466 | * |
Paul Cercueil |
27:3c32495708f4 | 467 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 468 | */ |
Paul Cercueil |
27:3c32495708f4 | 469 | enum sp_return sp_get_port_by_name(const char *portname, struct sp_port **port_ptr); |
Paul Cercueil |
27:3c32495708f4 | 470 | |
Paul Cercueil |
27:3c32495708f4 | 471 | /** |
Paul Cercueil |
27:3c32495708f4 | 472 | * Free a port structure obtained from sp_get_port_by_name() or sp_copy_port(). |
Paul Cercueil |
27:3c32495708f4 | 473 | * |
Paul Cercueil |
27:3c32495708f4 | 474 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 475 | * |
Paul Cercueil |
27:3c32495708f4 | 476 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 477 | */ |
Paul Cercueil |
27:3c32495708f4 | 478 | void sp_free_port(struct sp_port *port); |
Paul Cercueil |
27:3c32495708f4 | 479 | |
Paul Cercueil |
27:3c32495708f4 | 480 | /** |
Paul Cercueil |
27:3c32495708f4 | 481 | * List the serial ports available on the system. |
Paul Cercueil |
27:3c32495708f4 | 482 | * |
Paul Cercueil |
27:3c32495708f4 | 483 | * The result obtained is an array of pointers to sp_port structures, |
Paul Cercueil |
27:3c32495708f4 | 484 | * terminated by a NULL. The user should allocate a variable of type |
Paul Cercueil |
27:3c32495708f4 | 485 | * "struct sp_port **" and pass a pointer to this to receive the result. |
Paul Cercueil |
27:3c32495708f4 | 486 | * |
Paul Cercueil |
27:3c32495708f4 | 487 | * The result should be freed after use by calling sp_free_port_list(). |
Paul Cercueil |
27:3c32495708f4 | 488 | * If a port from the list is to be used after freeing the list, it must be |
Paul Cercueil |
27:3c32495708f4 | 489 | * copied first using sp_copy_port(). |
Paul Cercueil |
27:3c32495708f4 | 490 | * |
Paul Cercueil |
27:3c32495708f4 | 491 | * @param[out] list_ptr If any error is returned, the variable pointed to by |
Paul Cercueil |
27:3c32495708f4 | 492 | * list_ptr will be set to NULL. Otherwise, it will be set |
Paul Cercueil |
27:3c32495708f4 | 493 | * to point to the newly allocated array. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 494 | * |
Paul Cercueil |
27:3c32495708f4 | 495 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 496 | * |
Paul Cercueil |
27:3c32495708f4 | 497 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 498 | */ |
Paul Cercueil |
27:3c32495708f4 | 499 | enum sp_return sp_list_ports(struct sp_port ***list_ptr); |
Paul Cercueil |
27:3c32495708f4 | 500 | |
Paul Cercueil |
27:3c32495708f4 | 501 | /** |
Paul Cercueil |
27:3c32495708f4 | 502 | * Make a new copy of an sp_port structure. |
Paul Cercueil |
27:3c32495708f4 | 503 | * |
Paul Cercueil |
27:3c32495708f4 | 504 | * The user should allocate a variable of type "struct sp_port *" and pass a |
Paul Cercueil |
27:3c32495708f4 | 505 | * pointer to this to receive the result. |
Paul Cercueil |
27:3c32495708f4 | 506 | * |
Paul Cercueil |
27:3c32495708f4 | 507 | * The copy should be freed after use by calling sp_free_port(). |
Paul Cercueil |
27:3c32495708f4 | 508 | * |
Paul Cercueil |
27:3c32495708f4 | 509 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 510 | * @param[out] copy_ptr If any error is returned, the variable pointed to by |
Paul Cercueil |
27:3c32495708f4 | 511 | * copy_ptr will be set to NULL. Otherwise, it will be set |
Paul Cercueil |
27:3c32495708f4 | 512 | * to point to the newly allocated copy. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 513 | * |
Paul Cercueil |
27:3c32495708f4 | 514 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 515 | * |
Paul Cercueil |
27:3c32495708f4 | 516 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 517 | */ |
Paul Cercueil |
27:3c32495708f4 | 518 | enum sp_return sp_copy_port(const struct sp_port *port, struct sp_port **copy_ptr); |
Paul Cercueil |
27:3c32495708f4 | 519 | |
Paul Cercueil |
27:3c32495708f4 | 520 | /** |
Paul Cercueil |
27:3c32495708f4 | 521 | * Free a port list obtained from sp_list_ports(). |
Paul Cercueil |
27:3c32495708f4 | 522 | * |
Paul Cercueil |
27:3c32495708f4 | 523 | * This will also free all the sp_port structures referred to from the list; |
Paul Cercueil |
27:3c32495708f4 | 524 | * any that are to be retained must be copied first using sp_copy_port(). |
Paul Cercueil |
27:3c32495708f4 | 525 | * |
Paul Cercueil |
27:3c32495708f4 | 526 | * @param[in] ports Pointer to a list of port structures. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 527 | * |
Paul Cercueil |
27:3c32495708f4 | 528 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 529 | */ |
Paul Cercueil |
27:3c32495708f4 | 530 | void sp_free_port_list(struct sp_port **ports); |
Paul Cercueil |
27:3c32495708f4 | 531 | |
Paul Cercueil |
27:3c32495708f4 | 532 | /** |
Paul Cercueil |
27:3c32495708f4 | 533 | * @} |
Paul Cercueil |
27:3c32495708f4 | 534 | * @defgroup Ports Port handling |
Paul Cercueil |
27:3c32495708f4 | 535 | * |
Paul Cercueil |
27:3c32495708f4 | 536 | * Opening, closing and querying ports. |
Paul Cercueil |
27:3c32495708f4 | 537 | * |
Paul Cercueil |
27:3c32495708f4 | 538 | * @{ |
Paul Cercueil |
27:3c32495708f4 | 539 | */ |
Paul Cercueil |
27:3c32495708f4 | 540 | |
Paul Cercueil |
27:3c32495708f4 | 541 | /** |
Paul Cercueil |
27:3c32495708f4 | 542 | * Open the specified serial port. |
Paul Cercueil |
27:3c32495708f4 | 543 | * |
Paul Cercueil |
27:3c32495708f4 | 544 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 545 | * @param[in] flags Flags to use when opening the serial port. |
Paul Cercueil |
27:3c32495708f4 | 546 | * |
Paul Cercueil |
27:3c32495708f4 | 547 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 548 | * |
Paul Cercueil |
27:3c32495708f4 | 549 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 550 | */ |
Paul Cercueil |
27:3c32495708f4 | 551 | enum sp_return sp_open(struct sp_port *port, enum sp_mode flags); |
Paul Cercueil |
27:3c32495708f4 | 552 | |
Paul Cercueil |
27:3c32495708f4 | 553 | /** |
Paul Cercueil |
27:3c32495708f4 | 554 | * Close the specified serial port. |
Paul Cercueil |
27:3c32495708f4 | 555 | * |
Paul Cercueil |
27:3c32495708f4 | 556 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 557 | * |
Paul Cercueil |
27:3c32495708f4 | 558 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 559 | * |
Paul Cercueil |
27:3c32495708f4 | 560 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 561 | */ |
Paul Cercueil |
27:3c32495708f4 | 562 | enum sp_return sp_close(struct sp_port *port); |
Paul Cercueil |
27:3c32495708f4 | 563 | |
Paul Cercueil |
27:3c32495708f4 | 564 | /** |
Paul Cercueil |
27:3c32495708f4 | 565 | * Get the name of a port. |
Paul Cercueil |
27:3c32495708f4 | 566 | * |
Paul Cercueil |
27:3c32495708f4 | 567 | * The name returned is whatever is normally used to refer to a port on the |
Paul Cercueil |
27:3c32495708f4 | 568 | * current operating system; e.g. for Windows it will usually be a "COMn" |
Paul Cercueil |
27:3c32495708f4 | 569 | * device name, and for Unix it will be a device path beginning with "/dev/". |
Paul Cercueil |
27:3c32495708f4 | 570 | * |
Paul Cercueil |
27:3c32495708f4 | 571 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 572 | * |
Paul Cercueil |
27:3c32495708f4 | 573 | * @return The port name, or NULL if an invalid port is passed. The name |
Paul Cercueil |
27:3c32495708f4 | 574 | * string is part of the port structure and may not be used after |
Paul Cercueil |
27:3c32495708f4 | 575 | * the port structure has been freed. |
Paul Cercueil |
27:3c32495708f4 | 576 | * |
Paul Cercueil |
27:3c32495708f4 | 577 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 578 | */ |
Paul Cercueil |
27:3c32495708f4 | 579 | char *sp_get_port_name(const struct sp_port *port); |
Paul Cercueil |
27:3c32495708f4 | 580 | |
Paul Cercueil |
27:3c32495708f4 | 581 | /** |
Paul Cercueil |
27:3c32495708f4 | 582 | * Get a description for a port, to present to end user. |
Paul Cercueil |
27:3c32495708f4 | 583 | * |
Paul Cercueil |
27:3c32495708f4 | 584 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 585 | * |
Paul Cercueil |
27:3c32495708f4 | 586 | * @return The port description, or NULL if an invalid port is passed. |
Paul Cercueil |
27:3c32495708f4 | 587 | * The description string is part of the port structure and may not |
Paul Cercueil |
27:3c32495708f4 | 588 | * be used after the port structure has been freed. |
Paul Cercueil |
27:3c32495708f4 | 589 | * |
Paul Cercueil |
27:3c32495708f4 | 590 | * @since 0.1.1 |
Paul Cercueil |
27:3c32495708f4 | 591 | */ |
Paul Cercueil |
27:3c32495708f4 | 592 | char *sp_get_port_description(const struct sp_port *port); |
Paul Cercueil |
27:3c32495708f4 | 593 | |
Paul Cercueil |
27:3c32495708f4 | 594 | /** |
Paul Cercueil |
27:3c32495708f4 | 595 | * Get the transport type used by a port. |
Paul Cercueil |
27:3c32495708f4 | 596 | * |
Paul Cercueil |
27:3c32495708f4 | 597 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 598 | * |
Paul Cercueil |
27:3c32495708f4 | 599 | * @return The port transport type. |
Paul Cercueil |
27:3c32495708f4 | 600 | * |
Paul Cercueil |
27:3c32495708f4 | 601 | * @since 0.1.1 |
Paul Cercueil |
27:3c32495708f4 | 602 | */ |
Paul Cercueil |
27:3c32495708f4 | 603 | enum sp_transport sp_get_port_transport(const struct sp_port *port); |
Paul Cercueil |
27:3c32495708f4 | 604 | |
Paul Cercueil |
27:3c32495708f4 | 605 | /** |
Paul Cercueil |
27:3c32495708f4 | 606 | * Get the USB bus number and address on bus of a USB serial adapter port. |
Paul Cercueil |
27:3c32495708f4 | 607 | * |
Paul Cercueil |
27:3c32495708f4 | 608 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 609 | * @param[out] usb_bus Pointer to a variable to store the USB bus. |
Paul Cercueil |
27:3c32495708f4 | 610 | * Can be NULL (in that case it will be ignored). |
Paul Cercueil |
27:3c32495708f4 | 611 | * @param[out] usb_address Pointer to a variable to store the USB address. |
Paul Cercueil |
27:3c32495708f4 | 612 | * Can be NULL (in that case it will be ignored). |
Paul Cercueil |
27:3c32495708f4 | 613 | * |
Paul Cercueil |
27:3c32495708f4 | 614 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 615 | * |
Paul Cercueil |
27:3c32495708f4 | 616 | * @since 0.1.1 |
Paul Cercueil |
27:3c32495708f4 | 617 | */ |
Paul Cercueil |
27:3c32495708f4 | 618 | enum sp_return sp_get_port_usb_bus_address(const struct sp_port *port, |
Paul Cercueil |
27:3c32495708f4 | 619 | int *usb_bus, int *usb_address); |
Paul Cercueil |
27:3c32495708f4 | 620 | |
Paul Cercueil |
27:3c32495708f4 | 621 | /** |
Paul Cercueil |
27:3c32495708f4 | 622 | * Get the USB Vendor ID and Product ID of a USB serial adapter port. |
Paul Cercueil |
27:3c32495708f4 | 623 | * |
Paul Cercueil |
27:3c32495708f4 | 624 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 625 | * @param[out] usb_vid Pointer to a variable to store the USB VID. |
Paul Cercueil |
27:3c32495708f4 | 626 | * Can be NULL (in that case it will be ignored). |
Paul Cercueil |
27:3c32495708f4 | 627 | * @param[out] usb_pid Pointer to a variable to store the USB PID. |
Paul Cercueil |
27:3c32495708f4 | 628 | * Can be NULL (in that case it will be ignored). |
Paul Cercueil |
27:3c32495708f4 | 629 | * |
Paul Cercueil |
27:3c32495708f4 | 630 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 631 | * |
Paul Cercueil |
27:3c32495708f4 | 632 | * @since 0.1.1 |
Paul Cercueil |
27:3c32495708f4 | 633 | */ |
Paul Cercueil |
27:3c32495708f4 | 634 | enum sp_return sp_get_port_usb_vid_pid(const struct sp_port *port, int *usb_vid, int *usb_pid); |
Paul Cercueil |
27:3c32495708f4 | 635 | |
Paul Cercueil |
27:3c32495708f4 | 636 | /** |
Paul Cercueil |
27:3c32495708f4 | 637 | * Get the USB manufacturer string of a USB serial adapter port. |
Paul Cercueil |
27:3c32495708f4 | 638 | * |
Paul Cercueil |
27:3c32495708f4 | 639 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 640 | * |
Paul Cercueil |
27:3c32495708f4 | 641 | * @return The port manufacturer string, or NULL if an invalid port is passed. |
Paul Cercueil |
27:3c32495708f4 | 642 | * The manufacturer string is part of the port structure and may not |
Paul Cercueil |
27:3c32495708f4 | 643 | * be used after the port structure has been freed. |
Paul Cercueil |
27:3c32495708f4 | 644 | * |
Paul Cercueil |
27:3c32495708f4 | 645 | * @since 0.1.1 |
Paul Cercueil |
27:3c32495708f4 | 646 | */ |
Paul Cercueil |
27:3c32495708f4 | 647 | char *sp_get_port_usb_manufacturer(const struct sp_port *port); |
Paul Cercueil |
27:3c32495708f4 | 648 | |
Paul Cercueil |
27:3c32495708f4 | 649 | /** |
Paul Cercueil |
27:3c32495708f4 | 650 | * Get the USB product string of a USB serial adapter port. |
Paul Cercueil |
27:3c32495708f4 | 651 | * |
Paul Cercueil |
27:3c32495708f4 | 652 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 653 | * |
Paul Cercueil |
27:3c32495708f4 | 654 | * @return The port product string, or NULL if an invalid port is passed. |
Paul Cercueil |
27:3c32495708f4 | 655 | * The product string is part of the port structure and may not be |
Paul Cercueil |
27:3c32495708f4 | 656 | * used after the port structure has been freed. |
Paul Cercueil |
27:3c32495708f4 | 657 | * |
Paul Cercueil |
27:3c32495708f4 | 658 | * @since 0.1.1 |
Paul Cercueil |
27:3c32495708f4 | 659 | */ |
Paul Cercueil |
27:3c32495708f4 | 660 | char *sp_get_port_usb_product(const struct sp_port *port); |
Paul Cercueil |
27:3c32495708f4 | 661 | |
Paul Cercueil |
27:3c32495708f4 | 662 | /** |
Paul Cercueil |
27:3c32495708f4 | 663 | * Get the USB serial number string of a USB serial adapter port. |
Paul Cercueil |
27:3c32495708f4 | 664 | * |
Paul Cercueil |
27:3c32495708f4 | 665 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 666 | * |
Paul Cercueil |
27:3c32495708f4 | 667 | * @return The port serial number, or NULL if an invalid port is passed. |
Paul Cercueil |
27:3c32495708f4 | 668 | * The serial number string is part of the port structure and may |
Paul Cercueil |
27:3c32495708f4 | 669 | * not be used after the port structure has been freed. |
Paul Cercueil |
27:3c32495708f4 | 670 | * |
Paul Cercueil |
27:3c32495708f4 | 671 | * @since 0.1.1 |
Paul Cercueil |
27:3c32495708f4 | 672 | */ |
Paul Cercueil |
27:3c32495708f4 | 673 | char *sp_get_port_usb_serial(const struct sp_port *port); |
Paul Cercueil |
27:3c32495708f4 | 674 | |
Paul Cercueil |
27:3c32495708f4 | 675 | /** |
Paul Cercueil |
27:3c32495708f4 | 676 | * Get the MAC address of a Bluetooth serial adapter port. |
Paul Cercueil |
27:3c32495708f4 | 677 | * |
Paul Cercueil |
27:3c32495708f4 | 678 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 679 | * |
Paul Cercueil |
27:3c32495708f4 | 680 | * @return The port MAC address, or NULL if an invalid port is passed. |
Paul Cercueil |
27:3c32495708f4 | 681 | * The MAC address string is part of the port structure and may not |
Paul Cercueil |
27:3c32495708f4 | 682 | * be used after the port structure has been freed. |
Paul Cercueil |
27:3c32495708f4 | 683 | * |
Paul Cercueil |
27:3c32495708f4 | 684 | * @since 0.1.1 |
Paul Cercueil |
27:3c32495708f4 | 685 | */ |
Paul Cercueil |
27:3c32495708f4 | 686 | char *sp_get_port_bluetooth_address(const struct sp_port *port); |
Paul Cercueil |
27:3c32495708f4 | 687 | |
Paul Cercueil |
27:3c32495708f4 | 688 | /** |
Paul Cercueil |
27:3c32495708f4 | 689 | * Get the operating system handle for a port. |
Paul Cercueil |
27:3c32495708f4 | 690 | * |
Paul Cercueil |
27:3c32495708f4 | 691 | * The type of the handle depends on the operating system. On Unix based |
Paul Cercueil |
27:3c32495708f4 | 692 | * systems, the handle is a file descriptor of type "int". On Windows, the |
Paul Cercueil |
27:3c32495708f4 | 693 | * handle is of type "HANDLE". The user should allocate a variable of the |
Paul Cercueil |
27:3c32495708f4 | 694 | * appropriate type and pass a pointer to this to receive the result. |
Paul Cercueil |
27:3c32495708f4 | 695 | * |
Paul Cercueil |
27:3c32495708f4 | 696 | * To obtain a valid handle, the port must first be opened by calling |
Paul Cercueil |
27:3c32495708f4 | 697 | * sp_open() using the same port structure. |
Paul Cercueil |
27:3c32495708f4 | 698 | * |
Paul Cercueil |
27:3c32495708f4 | 699 | * After the port is closed or the port structure freed, the handle may |
Paul Cercueil |
27:3c32495708f4 | 700 | * no longer be valid. |
Paul Cercueil |
27:3c32495708f4 | 701 | * |
Paul Cercueil |
27:3c32495708f4 | 702 | * @warning This feature is provided so that programs may make use of |
Paul Cercueil |
27:3c32495708f4 | 703 | * OS-specific functionality where desired. Doing so obviously |
Paul Cercueil |
27:3c32495708f4 | 704 | * comes at a cost in portability. It also cannot be guaranteed |
Paul Cercueil |
27:3c32495708f4 | 705 | * that direct usage of the OS handle will not conflict with the |
Paul Cercueil |
27:3c32495708f4 | 706 | * library's own usage of the port. Be careful. |
Paul Cercueil |
27:3c32495708f4 | 707 | * |
Paul Cercueil |
27:3c32495708f4 | 708 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 709 | * @param[out] result_ptr If any error is returned, the variable pointed to by |
Paul Cercueil |
27:3c32495708f4 | 710 | * result_ptr will have unknown contents and should not |
Paul Cercueil |
27:3c32495708f4 | 711 | * be used. Otherwise, it will be set to point to the |
Paul Cercueil |
27:3c32495708f4 | 712 | * OS handle. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 713 | * |
Paul Cercueil |
27:3c32495708f4 | 714 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 715 | * |
Paul Cercueil |
27:3c32495708f4 | 716 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 717 | */ |
Paul Cercueil |
27:3c32495708f4 | 718 | enum sp_return sp_get_port_handle(const struct sp_port *port, void *result_ptr); |
Paul Cercueil |
27:3c32495708f4 | 719 | |
Paul Cercueil |
27:3c32495708f4 | 720 | /** |
Paul Cercueil |
27:3c32495708f4 | 721 | * @} |
Paul Cercueil |
27:3c32495708f4 | 722 | * |
Paul Cercueil |
27:3c32495708f4 | 723 | * @defgroup Configuration Configuration |
Paul Cercueil |
27:3c32495708f4 | 724 | * |
Paul Cercueil |
27:3c32495708f4 | 725 | * Setting and querying serial port parameters. |
Paul Cercueil |
27:3c32495708f4 | 726 | * @{ |
Paul Cercueil |
27:3c32495708f4 | 727 | */ |
Paul Cercueil |
27:3c32495708f4 | 728 | |
Paul Cercueil |
27:3c32495708f4 | 729 | /** |
Paul Cercueil |
27:3c32495708f4 | 730 | * Allocate a port configuration structure. |
Paul Cercueil |
27:3c32495708f4 | 731 | * |
Paul Cercueil |
27:3c32495708f4 | 732 | * The user should allocate a variable of type "struct sp_port_config *" and |
Paul Cercueil |
27:3c32495708f4 | 733 | * pass a pointer to this to receive the result. The variable will be updated |
Paul Cercueil |
27:3c32495708f4 | 734 | * to point to the new configuration structure. The structure is opaque and |
Paul Cercueil |
27:3c32495708f4 | 735 | * must be accessed via the functions provided. |
Paul Cercueil |
27:3c32495708f4 | 736 | * |
Paul Cercueil |
27:3c32495708f4 | 737 | * All parameters in the structure will be initialised to special values which |
Paul Cercueil |
27:3c32495708f4 | 738 | * are ignored by sp_set_config(). |
Paul Cercueil |
27:3c32495708f4 | 739 | * |
Paul Cercueil |
27:3c32495708f4 | 740 | * The structure should be freed after use by calling sp_free_config(). |
Paul Cercueil |
27:3c32495708f4 | 741 | * |
Paul Cercueil |
27:3c32495708f4 | 742 | * @param[out] config_ptr If any error is returned, the variable pointed to by |
Paul Cercueil |
27:3c32495708f4 | 743 | * config_ptr will be set to NULL. Otherwise, it will |
Paul Cercueil |
27:3c32495708f4 | 744 | * be set to point to the allocated config structure. |
Paul Cercueil |
27:3c32495708f4 | 745 | * Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 746 | * |
Paul Cercueil |
27:3c32495708f4 | 747 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 748 | * |
Paul Cercueil |
27:3c32495708f4 | 749 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 750 | */ |
Paul Cercueil |
27:3c32495708f4 | 751 | enum sp_return sp_new_config(struct sp_port_config **config_ptr); |
Paul Cercueil |
27:3c32495708f4 | 752 | |
Paul Cercueil |
27:3c32495708f4 | 753 | /** |
Paul Cercueil |
27:3c32495708f4 | 754 | * Free a port configuration structure. |
Paul Cercueil |
27:3c32495708f4 | 755 | * |
Paul Cercueil |
27:3c32495708f4 | 756 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 757 | * |
Paul Cercueil |
27:3c32495708f4 | 758 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 759 | */ |
Paul Cercueil |
27:3c32495708f4 | 760 | void sp_free_config(struct sp_port_config *config); |
Paul Cercueil |
27:3c32495708f4 | 761 | |
Paul Cercueil |
27:3c32495708f4 | 762 | /** |
Paul Cercueil |
27:3c32495708f4 | 763 | * Get the current configuration of the specified serial port. |
Paul Cercueil |
27:3c32495708f4 | 764 | * |
Paul Cercueil |
27:3c32495708f4 | 765 | * The user should allocate a configuration structure using sp_new_config() |
Paul Cercueil |
27:3c32495708f4 | 766 | * and pass this as the config parameter. The configuration structure will |
Paul Cercueil |
27:3c32495708f4 | 767 | * be updated with the port configuration. |
Paul Cercueil |
27:3c32495708f4 | 768 | * |
Paul Cercueil |
27:3c32495708f4 | 769 | * Any parameters that are configured with settings not recognised or |
Paul Cercueil |
27:3c32495708f4 | 770 | * supported by libserialport, will be set to special values that are |
Paul Cercueil |
27:3c32495708f4 | 771 | * ignored by sp_set_config(). |
Paul Cercueil |
27:3c32495708f4 | 772 | * |
Paul Cercueil |
27:3c32495708f4 | 773 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 774 | * @param[out] config Pointer to a configuration structure that will hold |
Paul Cercueil |
27:3c32495708f4 | 775 | * the result. Upon errors the contents of the config |
Paul Cercueil |
27:3c32495708f4 | 776 | * struct will not be changed. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 777 | * |
Paul Cercueil |
27:3c32495708f4 | 778 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 779 | * |
Paul Cercueil |
27:3c32495708f4 | 780 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 781 | */ |
Paul Cercueil |
27:3c32495708f4 | 782 | enum sp_return sp_get_config(struct sp_port *port, struct sp_port_config *config); |
Paul Cercueil |
27:3c32495708f4 | 783 | |
Paul Cercueil |
27:3c32495708f4 | 784 | /** |
Paul Cercueil |
27:3c32495708f4 | 785 | * Set the configuration for the specified serial port. |
Paul Cercueil |
27:3c32495708f4 | 786 | * |
Paul Cercueil |
27:3c32495708f4 | 787 | * For each parameter in the configuration, there is a special value (usually |
Paul Cercueil |
27:3c32495708f4 | 788 | * -1, but see the documentation for each field). These values will be ignored |
Paul Cercueil |
27:3c32495708f4 | 789 | * and the corresponding setting left unchanged on the port. |
Paul Cercueil |
27:3c32495708f4 | 790 | * |
Paul Cercueil |
27:3c32495708f4 | 791 | * Upon errors, the configuration of the serial port is unknown since |
Paul Cercueil |
27:3c32495708f4 | 792 | * partial/incomplete config updates may have happened. |
Paul Cercueil |
27:3c32495708f4 | 793 | * |
Paul Cercueil |
27:3c32495708f4 | 794 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 795 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 796 | * |
Paul Cercueil |
27:3c32495708f4 | 797 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 798 | * |
Paul Cercueil |
27:3c32495708f4 | 799 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 800 | */ |
Paul Cercueil |
27:3c32495708f4 | 801 | enum sp_return sp_set_config(struct sp_port *port, const struct sp_port_config *config); |
Paul Cercueil |
27:3c32495708f4 | 802 | |
Paul Cercueil |
27:3c32495708f4 | 803 | /** |
Paul Cercueil |
27:3c32495708f4 | 804 | * Set the baud rate for the specified serial port. |
Paul Cercueil |
27:3c32495708f4 | 805 | * |
Paul Cercueil |
27:3c32495708f4 | 806 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 807 | * @param[in] baudrate Baud rate in bits per second. |
Paul Cercueil |
27:3c32495708f4 | 808 | * |
Paul Cercueil |
27:3c32495708f4 | 809 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 810 | * |
Paul Cercueil |
27:3c32495708f4 | 811 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 812 | */ |
Paul Cercueil |
27:3c32495708f4 | 813 | enum sp_return sp_set_baudrate(struct sp_port *port, int baudrate); |
Paul Cercueil |
27:3c32495708f4 | 814 | |
Paul Cercueil |
27:3c32495708f4 | 815 | /** |
Paul Cercueil |
27:3c32495708f4 | 816 | * Get the baud rate from a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 817 | * |
Paul Cercueil |
27:3c32495708f4 | 818 | * The user should allocate a variable of type int and |
Paul Cercueil |
27:3c32495708f4 | 819 | * pass a pointer to this to receive the result. |
Paul Cercueil |
27:3c32495708f4 | 820 | * |
Paul Cercueil |
27:3c32495708f4 | 821 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 822 | * @param[out] baudrate_ptr Pointer to a variable to store the result. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 823 | * |
Paul Cercueil |
27:3c32495708f4 | 824 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 825 | * |
Paul Cercueil |
27:3c32495708f4 | 826 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 827 | */ |
Paul Cercueil |
27:3c32495708f4 | 828 | enum sp_return sp_get_config_baudrate(const struct sp_port_config *config, int *baudrate_ptr); |
Paul Cercueil |
27:3c32495708f4 | 829 | |
Paul Cercueil |
27:3c32495708f4 | 830 | /** |
Paul Cercueil |
27:3c32495708f4 | 831 | * Set the baud rate in a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 832 | * |
Paul Cercueil |
27:3c32495708f4 | 833 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 834 | * @param[in] baudrate Baud rate in bits per second, or -1 to retain the current setting. |
Paul Cercueil |
27:3c32495708f4 | 835 | * |
Paul Cercueil |
27:3c32495708f4 | 836 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 837 | * |
Paul Cercueil |
27:3c32495708f4 | 838 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 839 | */ |
Paul Cercueil |
27:3c32495708f4 | 840 | enum sp_return sp_set_config_baudrate(struct sp_port_config *config, int baudrate); |
Paul Cercueil |
27:3c32495708f4 | 841 | |
Paul Cercueil |
27:3c32495708f4 | 842 | /** |
Paul Cercueil |
27:3c32495708f4 | 843 | * Set the data bits for the specified serial port. |
Paul Cercueil |
27:3c32495708f4 | 844 | * |
Paul Cercueil |
27:3c32495708f4 | 845 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 846 | * @param[in] bits Number of data bits. |
Paul Cercueil |
27:3c32495708f4 | 847 | * |
Paul Cercueil |
27:3c32495708f4 | 848 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 849 | * |
Paul Cercueil |
27:3c32495708f4 | 850 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 851 | */ |
Paul Cercueil |
27:3c32495708f4 | 852 | enum sp_return sp_set_bits(struct sp_port *port, int bits); |
Paul Cercueil |
27:3c32495708f4 | 853 | |
Paul Cercueil |
27:3c32495708f4 | 854 | /** |
Paul Cercueil |
27:3c32495708f4 | 855 | * Get the data bits from a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 856 | * |
Paul Cercueil |
27:3c32495708f4 | 857 | * The user should allocate a variable of type int and |
Paul Cercueil |
27:3c32495708f4 | 858 | * pass a pointer to this to receive the result. |
Paul Cercueil |
27:3c32495708f4 | 859 | * |
Paul Cercueil |
27:3c32495708f4 | 860 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 861 | * @param[out] bits_ptr Pointer to a variable to store the result. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 862 | * |
Paul Cercueil |
27:3c32495708f4 | 863 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 864 | * |
Paul Cercueil |
27:3c32495708f4 | 865 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 866 | */ |
Paul Cercueil |
27:3c32495708f4 | 867 | enum sp_return sp_get_config_bits(const struct sp_port_config *config, int *bits_ptr); |
Paul Cercueil |
27:3c32495708f4 | 868 | |
Paul Cercueil |
27:3c32495708f4 | 869 | /** |
Paul Cercueil |
27:3c32495708f4 | 870 | * Set the data bits in a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 871 | * |
Paul Cercueil |
27:3c32495708f4 | 872 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 873 | * @param[in] bits Number of data bits, or -1 to retain the current setting. |
Paul Cercueil |
27:3c32495708f4 | 874 | * |
Paul Cercueil |
27:3c32495708f4 | 875 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 876 | * |
Paul Cercueil |
27:3c32495708f4 | 877 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 878 | */ |
Paul Cercueil |
27:3c32495708f4 | 879 | enum sp_return sp_set_config_bits(struct sp_port_config *config, int bits); |
Paul Cercueil |
27:3c32495708f4 | 880 | |
Paul Cercueil |
27:3c32495708f4 | 881 | /** |
Paul Cercueil |
27:3c32495708f4 | 882 | * Set the parity setting for the specified serial port. |
Paul Cercueil |
27:3c32495708f4 | 883 | * |
Paul Cercueil |
27:3c32495708f4 | 884 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 885 | * @param[in] parity Parity setting. |
Paul Cercueil |
27:3c32495708f4 | 886 | * |
Paul Cercueil |
27:3c32495708f4 | 887 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 888 | * |
Paul Cercueil |
27:3c32495708f4 | 889 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 890 | */ |
Paul Cercueil |
27:3c32495708f4 | 891 | enum sp_return sp_set_parity(struct sp_port *port, enum sp_parity parity); |
Paul Cercueil |
27:3c32495708f4 | 892 | |
Paul Cercueil |
27:3c32495708f4 | 893 | /** |
Paul Cercueil |
27:3c32495708f4 | 894 | * Get the parity setting from a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 895 | * |
Paul Cercueil |
27:3c32495708f4 | 896 | * The user should allocate a variable of type enum sp_parity and |
Paul Cercueil |
27:3c32495708f4 | 897 | * pass a pointer to this to receive the result. |
Paul Cercueil |
27:3c32495708f4 | 898 | * |
Paul Cercueil |
27:3c32495708f4 | 899 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 900 | * @param[out] parity_ptr Pointer to a variable to store the result. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 901 | * |
Paul Cercueil |
27:3c32495708f4 | 902 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 903 | * |
Paul Cercueil |
27:3c32495708f4 | 904 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 905 | */ |
Paul Cercueil |
27:3c32495708f4 | 906 | enum sp_return sp_get_config_parity(const struct sp_port_config *config, enum sp_parity *parity_ptr); |
Paul Cercueil |
27:3c32495708f4 | 907 | |
Paul Cercueil |
27:3c32495708f4 | 908 | /** |
Paul Cercueil |
27:3c32495708f4 | 909 | * Set the parity setting in a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 910 | * |
Paul Cercueil |
27:3c32495708f4 | 911 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 912 | * @param[in] parity Parity setting, or -1 to retain the current setting. |
Paul Cercueil |
27:3c32495708f4 | 913 | * |
Paul Cercueil |
27:3c32495708f4 | 914 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 915 | * |
Paul Cercueil |
27:3c32495708f4 | 916 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 917 | */ |
Paul Cercueil |
27:3c32495708f4 | 918 | enum sp_return sp_set_config_parity(struct sp_port_config *config, enum sp_parity parity); |
Paul Cercueil |
27:3c32495708f4 | 919 | |
Paul Cercueil |
27:3c32495708f4 | 920 | /** |
Paul Cercueil |
27:3c32495708f4 | 921 | * Set the stop bits for the specified serial port. |
Paul Cercueil |
27:3c32495708f4 | 922 | * |
Paul Cercueil |
27:3c32495708f4 | 923 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 924 | * @param[in] stopbits Number of stop bits. |
Paul Cercueil |
27:3c32495708f4 | 925 | * |
Paul Cercueil |
27:3c32495708f4 | 926 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 927 | * |
Paul Cercueil |
27:3c32495708f4 | 928 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 929 | */ |
Paul Cercueil |
27:3c32495708f4 | 930 | enum sp_return sp_set_stopbits(struct sp_port *port, int stopbits); |
Paul Cercueil |
27:3c32495708f4 | 931 | |
Paul Cercueil |
27:3c32495708f4 | 932 | /** |
Paul Cercueil |
27:3c32495708f4 | 933 | * Get the stop bits from a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 934 | * |
Paul Cercueil |
27:3c32495708f4 | 935 | * The user should allocate a variable of type int and |
Paul Cercueil |
27:3c32495708f4 | 936 | * pass a pointer to this to receive the result. |
Paul Cercueil |
27:3c32495708f4 | 937 | * |
Paul Cercueil |
27:3c32495708f4 | 938 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 939 | * @param[out] stopbits_ptr Pointer to a variable to store the result. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 940 | * |
Paul Cercueil |
27:3c32495708f4 | 941 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 942 | * |
Paul Cercueil |
27:3c32495708f4 | 943 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 944 | */ |
Paul Cercueil |
27:3c32495708f4 | 945 | enum sp_return sp_get_config_stopbits(const struct sp_port_config *config, int *stopbits_ptr); |
Paul Cercueil |
27:3c32495708f4 | 946 | |
Paul Cercueil |
27:3c32495708f4 | 947 | /** |
Paul Cercueil |
27:3c32495708f4 | 948 | * Set the stop bits in a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 949 | * |
Paul Cercueil |
27:3c32495708f4 | 950 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 951 | * @param[in] stopbits Number of stop bits, or -1 to retain the current setting. |
Paul Cercueil |
27:3c32495708f4 | 952 | * |
Paul Cercueil |
27:3c32495708f4 | 953 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 954 | * |
Paul Cercueil |
27:3c32495708f4 | 955 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 956 | */ |
Paul Cercueil |
27:3c32495708f4 | 957 | enum sp_return sp_set_config_stopbits(struct sp_port_config *config, int stopbits); |
Paul Cercueil |
27:3c32495708f4 | 958 | |
Paul Cercueil |
27:3c32495708f4 | 959 | /** |
Paul Cercueil |
27:3c32495708f4 | 960 | * Set the RTS pin behaviour for the specified serial port. |
Paul Cercueil |
27:3c32495708f4 | 961 | * |
Paul Cercueil |
27:3c32495708f4 | 962 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 963 | * @param[in] rts RTS pin mode. |
Paul Cercueil |
27:3c32495708f4 | 964 | * |
Paul Cercueil |
27:3c32495708f4 | 965 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 966 | * |
Paul Cercueil |
27:3c32495708f4 | 967 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 968 | */ |
Paul Cercueil |
27:3c32495708f4 | 969 | enum sp_return sp_set_rts(struct sp_port *port, enum sp_rts rts); |
Paul Cercueil |
27:3c32495708f4 | 970 | |
Paul Cercueil |
27:3c32495708f4 | 971 | /** |
Paul Cercueil |
27:3c32495708f4 | 972 | * Get the RTS pin behaviour from a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 973 | * |
Paul Cercueil |
27:3c32495708f4 | 974 | * The user should allocate a variable of type enum sp_rts and |
Paul Cercueil |
27:3c32495708f4 | 975 | * pass a pointer to this to receive the result. |
Paul Cercueil |
27:3c32495708f4 | 976 | * |
Paul Cercueil |
27:3c32495708f4 | 977 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 978 | * @param[out] rts_ptr Pointer to a variable to store the result. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 979 | * |
Paul Cercueil |
27:3c32495708f4 | 980 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 981 | * |
Paul Cercueil |
27:3c32495708f4 | 982 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 983 | */ |
Paul Cercueil |
27:3c32495708f4 | 984 | enum sp_return sp_get_config_rts(const struct sp_port_config *config, enum sp_rts *rts_ptr); |
Paul Cercueil |
27:3c32495708f4 | 985 | |
Paul Cercueil |
27:3c32495708f4 | 986 | /** |
Paul Cercueil |
27:3c32495708f4 | 987 | * Set the RTS pin behaviour in a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 988 | * |
Paul Cercueil |
27:3c32495708f4 | 989 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 990 | * @param[in] rts RTS pin mode, or -1 to retain the current setting. |
Paul Cercueil |
27:3c32495708f4 | 991 | * |
Paul Cercueil |
27:3c32495708f4 | 992 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 993 | * |
Paul Cercueil |
27:3c32495708f4 | 994 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 995 | */ |
Paul Cercueil |
27:3c32495708f4 | 996 | enum sp_return sp_set_config_rts(struct sp_port_config *config, enum sp_rts rts); |
Paul Cercueil |
27:3c32495708f4 | 997 | |
Paul Cercueil |
27:3c32495708f4 | 998 | /** |
Paul Cercueil |
27:3c32495708f4 | 999 | * Set the CTS pin behaviour for the specified serial port. |
Paul Cercueil |
27:3c32495708f4 | 1000 | * |
Paul Cercueil |
27:3c32495708f4 | 1001 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1002 | * @param[in] cts CTS pin mode. |
Paul Cercueil |
27:3c32495708f4 | 1003 | * |
Paul Cercueil |
27:3c32495708f4 | 1004 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1005 | * |
Paul Cercueil |
27:3c32495708f4 | 1006 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1007 | */ |
Paul Cercueil |
27:3c32495708f4 | 1008 | enum sp_return sp_set_cts(struct sp_port *port, enum sp_cts cts); |
Paul Cercueil |
27:3c32495708f4 | 1009 | |
Paul Cercueil |
27:3c32495708f4 | 1010 | /** |
Paul Cercueil |
27:3c32495708f4 | 1011 | * Get the CTS pin behaviour from a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 1012 | * |
Paul Cercueil |
27:3c32495708f4 | 1013 | * The user should allocate a variable of type enum sp_cts and |
Paul Cercueil |
27:3c32495708f4 | 1014 | * pass a pointer to this to receive the result. |
Paul Cercueil |
27:3c32495708f4 | 1015 | * |
Paul Cercueil |
27:3c32495708f4 | 1016 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1017 | * @param[out] cts_ptr Pointer to a variable to store the result. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1018 | * |
Paul Cercueil |
27:3c32495708f4 | 1019 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1020 | * |
Paul Cercueil |
27:3c32495708f4 | 1021 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1022 | */ |
Paul Cercueil |
27:3c32495708f4 | 1023 | enum sp_return sp_get_config_cts(const struct sp_port_config *config, enum sp_cts *cts_ptr); |
Paul Cercueil |
27:3c32495708f4 | 1024 | |
Paul Cercueil |
27:3c32495708f4 | 1025 | /** |
Paul Cercueil |
27:3c32495708f4 | 1026 | * Set the CTS pin behaviour in a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 1027 | * |
Paul Cercueil |
27:3c32495708f4 | 1028 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1029 | * @param[in] cts CTS pin mode, or -1 to retain the current setting. |
Paul Cercueil |
27:3c32495708f4 | 1030 | * |
Paul Cercueil |
27:3c32495708f4 | 1031 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1032 | * |
Paul Cercueil |
27:3c32495708f4 | 1033 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1034 | */ |
Paul Cercueil |
27:3c32495708f4 | 1035 | enum sp_return sp_set_config_cts(struct sp_port_config *config, enum sp_cts cts); |
Paul Cercueil |
27:3c32495708f4 | 1036 | |
Paul Cercueil |
27:3c32495708f4 | 1037 | /** |
Paul Cercueil |
27:3c32495708f4 | 1038 | * Set the DTR pin behaviour for the specified serial port. |
Paul Cercueil |
27:3c32495708f4 | 1039 | * |
Paul Cercueil |
27:3c32495708f4 | 1040 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1041 | * @param[in] dtr DTR pin mode. |
Paul Cercueil |
27:3c32495708f4 | 1042 | * |
Paul Cercueil |
27:3c32495708f4 | 1043 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1044 | * |
Paul Cercueil |
27:3c32495708f4 | 1045 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1046 | */ |
Paul Cercueil |
27:3c32495708f4 | 1047 | enum sp_return sp_set_dtr(struct sp_port *port, enum sp_dtr dtr); |
Paul Cercueil |
27:3c32495708f4 | 1048 | |
Paul Cercueil |
27:3c32495708f4 | 1049 | /** |
Paul Cercueil |
27:3c32495708f4 | 1050 | * Get the DTR pin behaviour from a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 1051 | * |
Paul Cercueil |
27:3c32495708f4 | 1052 | * The user should allocate a variable of type enum sp_dtr and |
Paul Cercueil |
27:3c32495708f4 | 1053 | * pass a pointer to this to receive the result. |
Paul Cercueil |
27:3c32495708f4 | 1054 | * |
Paul Cercueil |
27:3c32495708f4 | 1055 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1056 | * @param[out] dtr_ptr Pointer to a variable to store the result. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1057 | * |
Paul Cercueil |
27:3c32495708f4 | 1058 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1059 | * |
Paul Cercueil |
27:3c32495708f4 | 1060 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1061 | */ |
Paul Cercueil |
27:3c32495708f4 | 1062 | enum sp_return sp_get_config_dtr(const struct sp_port_config *config, enum sp_dtr *dtr_ptr); |
Paul Cercueil |
27:3c32495708f4 | 1063 | |
Paul Cercueil |
27:3c32495708f4 | 1064 | /** |
Paul Cercueil |
27:3c32495708f4 | 1065 | * Set the DTR pin behaviour in a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 1066 | * |
Paul Cercueil |
27:3c32495708f4 | 1067 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1068 | * @param[in] dtr DTR pin mode, or -1 to retain the current setting. |
Paul Cercueil |
27:3c32495708f4 | 1069 | * |
Paul Cercueil |
27:3c32495708f4 | 1070 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1071 | * |
Paul Cercueil |
27:3c32495708f4 | 1072 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1073 | */ |
Paul Cercueil |
27:3c32495708f4 | 1074 | enum sp_return sp_set_config_dtr(struct sp_port_config *config, enum sp_dtr dtr); |
Paul Cercueil |
27:3c32495708f4 | 1075 | |
Paul Cercueil |
27:3c32495708f4 | 1076 | /** |
Paul Cercueil |
27:3c32495708f4 | 1077 | * Set the DSR pin behaviour for the specified serial port. |
Paul Cercueil |
27:3c32495708f4 | 1078 | * |
Paul Cercueil |
27:3c32495708f4 | 1079 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1080 | * @param[in] dsr DSR pin mode. |
Paul Cercueil |
27:3c32495708f4 | 1081 | * |
Paul Cercueil |
27:3c32495708f4 | 1082 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1083 | * |
Paul Cercueil |
27:3c32495708f4 | 1084 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1085 | */ |
Paul Cercueil |
27:3c32495708f4 | 1086 | enum sp_return sp_set_dsr(struct sp_port *port, enum sp_dsr dsr); |
Paul Cercueil |
27:3c32495708f4 | 1087 | |
Paul Cercueil |
27:3c32495708f4 | 1088 | /** |
Paul Cercueil |
27:3c32495708f4 | 1089 | * Get the DSR pin behaviour from a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 1090 | * |
Paul Cercueil |
27:3c32495708f4 | 1091 | * The user should allocate a variable of type enum sp_dsr and |
Paul Cercueil |
27:3c32495708f4 | 1092 | * pass a pointer to this to receive the result. |
Paul Cercueil |
27:3c32495708f4 | 1093 | * |
Paul Cercueil |
27:3c32495708f4 | 1094 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1095 | * @param[out] dsr_ptr Pointer to a variable to store the result. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1096 | * |
Paul Cercueil |
27:3c32495708f4 | 1097 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1098 | * |
Paul Cercueil |
27:3c32495708f4 | 1099 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1100 | */ |
Paul Cercueil |
27:3c32495708f4 | 1101 | enum sp_return sp_get_config_dsr(const struct sp_port_config *config, enum sp_dsr *dsr_ptr); |
Paul Cercueil |
27:3c32495708f4 | 1102 | |
Paul Cercueil |
27:3c32495708f4 | 1103 | /** |
Paul Cercueil |
27:3c32495708f4 | 1104 | * Set the DSR pin behaviour in a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 1105 | * |
Paul Cercueil |
27:3c32495708f4 | 1106 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1107 | * @param[in] dsr DSR pin mode, or -1 to retain the current setting. |
Paul Cercueil |
27:3c32495708f4 | 1108 | * |
Paul Cercueil |
27:3c32495708f4 | 1109 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1110 | * |
Paul Cercueil |
27:3c32495708f4 | 1111 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1112 | */ |
Paul Cercueil |
27:3c32495708f4 | 1113 | enum sp_return sp_set_config_dsr(struct sp_port_config *config, enum sp_dsr dsr); |
Paul Cercueil |
27:3c32495708f4 | 1114 | |
Paul Cercueil |
27:3c32495708f4 | 1115 | /** |
Paul Cercueil |
27:3c32495708f4 | 1116 | * Set the XON/XOFF configuration for the specified serial port. |
Paul Cercueil |
27:3c32495708f4 | 1117 | * |
Paul Cercueil |
27:3c32495708f4 | 1118 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1119 | * @param[in] xon_xoff XON/XOFF mode. |
Paul Cercueil |
27:3c32495708f4 | 1120 | * |
Paul Cercueil |
27:3c32495708f4 | 1121 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1122 | * |
Paul Cercueil |
27:3c32495708f4 | 1123 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1124 | */ |
Paul Cercueil |
27:3c32495708f4 | 1125 | enum sp_return sp_set_xon_xoff(struct sp_port *port, enum sp_xonxoff xon_xoff); |
Paul Cercueil |
27:3c32495708f4 | 1126 | |
Paul Cercueil |
27:3c32495708f4 | 1127 | /** |
Paul Cercueil |
27:3c32495708f4 | 1128 | * Get the XON/XOFF configuration from a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 1129 | * |
Paul Cercueil |
27:3c32495708f4 | 1130 | * The user should allocate a variable of type enum sp_xonxoff and |
Paul Cercueil |
27:3c32495708f4 | 1131 | * pass a pointer to this to receive the result. |
Paul Cercueil |
27:3c32495708f4 | 1132 | * |
Paul Cercueil |
27:3c32495708f4 | 1133 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1134 | * @param[out] xon_xoff_ptr Pointer to a variable to store the result. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1135 | * |
Paul Cercueil |
27:3c32495708f4 | 1136 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1137 | * |
Paul Cercueil |
27:3c32495708f4 | 1138 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1139 | */ |
Paul Cercueil |
27:3c32495708f4 | 1140 | enum sp_return sp_get_config_xon_xoff(const struct sp_port_config *config, enum sp_xonxoff *xon_xoff_ptr); |
Paul Cercueil |
27:3c32495708f4 | 1141 | |
Paul Cercueil |
27:3c32495708f4 | 1142 | /** |
Paul Cercueil |
27:3c32495708f4 | 1143 | * Set the XON/XOFF configuration in a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 1144 | * |
Paul Cercueil |
27:3c32495708f4 | 1145 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1146 | * @param[in] xon_xoff XON/XOFF mode, or -1 to retain the current setting. |
Paul Cercueil |
27:3c32495708f4 | 1147 | * |
Paul Cercueil |
27:3c32495708f4 | 1148 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1149 | * |
Paul Cercueil |
27:3c32495708f4 | 1150 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1151 | */ |
Paul Cercueil |
27:3c32495708f4 | 1152 | enum sp_return sp_set_config_xon_xoff(struct sp_port_config *config, enum sp_xonxoff xon_xoff); |
Paul Cercueil |
27:3c32495708f4 | 1153 | |
Paul Cercueil |
27:3c32495708f4 | 1154 | /** |
Paul Cercueil |
27:3c32495708f4 | 1155 | * Set the flow control type in a port configuration. |
Paul Cercueil |
27:3c32495708f4 | 1156 | * |
Paul Cercueil |
27:3c32495708f4 | 1157 | * This function is a wrapper that sets the RTS, CTS, DTR, DSR and |
Paul Cercueil |
27:3c32495708f4 | 1158 | * XON/XOFF settings as necessary for the specified flow control |
Paul Cercueil |
27:3c32495708f4 | 1159 | * type. For more fine-grained control of these settings, use their |
Paul Cercueil |
27:3c32495708f4 | 1160 | * individual configuration functions. |
Paul Cercueil |
27:3c32495708f4 | 1161 | * |
Paul Cercueil |
27:3c32495708f4 | 1162 | * @param[in] config Pointer to a configuration structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1163 | * @param[in] flowcontrol Flow control setting to use. |
Paul Cercueil |
27:3c32495708f4 | 1164 | * |
Paul Cercueil |
27:3c32495708f4 | 1165 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1166 | * |
Paul Cercueil |
27:3c32495708f4 | 1167 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1168 | */ |
Paul Cercueil |
27:3c32495708f4 | 1169 | enum sp_return sp_set_config_flowcontrol(struct sp_port_config *config, enum sp_flowcontrol flowcontrol); |
Paul Cercueil |
27:3c32495708f4 | 1170 | |
Paul Cercueil |
27:3c32495708f4 | 1171 | /** |
Paul Cercueil |
27:3c32495708f4 | 1172 | * Set the flow control type for the specified serial port. |
Paul Cercueil |
27:3c32495708f4 | 1173 | * |
Paul Cercueil |
27:3c32495708f4 | 1174 | * This function is a wrapper that sets the RTS, CTS, DTR, DSR and |
Paul Cercueil |
27:3c32495708f4 | 1175 | * XON/XOFF settings as necessary for the specified flow control |
Paul Cercueil |
27:3c32495708f4 | 1176 | * type. For more fine-grained control of these settings, use their |
Paul Cercueil |
27:3c32495708f4 | 1177 | * individual configuration functions. |
Paul Cercueil |
27:3c32495708f4 | 1178 | * |
Paul Cercueil |
27:3c32495708f4 | 1179 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1180 | * @param[in] flowcontrol Flow control setting to use. |
Paul Cercueil |
27:3c32495708f4 | 1181 | * |
Paul Cercueil |
27:3c32495708f4 | 1182 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1183 | * |
Paul Cercueil |
27:3c32495708f4 | 1184 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1185 | */ |
Paul Cercueil |
27:3c32495708f4 | 1186 | enum sp_return sp_set_flowcontrol(struct sp_port *port, enum sp_flowcontrol flowcontrol); |
Paul Cercueil |
27:3c32495708f4 | 1187 | |
Paul Cercueil |
27:3c32495708f4 | 1188 | /** |
Paul Cercueil |
27:3c32495708f4 | 1189 | * @} |
Paul Cercueil |
27:3c32495708f4 | 1190 | * |
Paul Cercueil |
27:3c32495708f4 | 1191 | * @defgroup Data Data handling |
Paul Cercueil |
27:3c32495708f4 | 1192 | * |
Paul Cercueil |
27:3c32495708f4 | 1193 | * Reading, writing, and flushing data. |
Paul Cercueil |
27:3c32495708f4 | 1194 | * |
Paul Cercueil |
27:3c32495708f4 | 1195 | * @{ |
Paul Cercueil |
27:3c32495708f4 | 1196 | */ |
Paul Cercueil |
27:3c32495708f4 | 1197 | |
Paul Cercueil |
27:3c32495708f4 | 1198 | /** |
Paul Cercueil |
27:3c32495708f4 | 1199 | * Read bytes from the specified serial port, blocking until complete. |
Paul Cercueil |
27:3c32495708f4 | 1200 | * |
Paul Cercueil |
27:3c32495708f4 | 1201 | * @warning If your program runs on Unix, defines its own signal handlers, and |
Paul Cercueil |
27:3c32495708f4 | 1202 | * needs to abort blocking reads when these are called, then you |
Paul Cercueil |
27:3c32495708f4 | 1203 | * should not use this function. It repeats system calls that return |
Paul Cercueil |
27:3c32495708f4 | 1204 | * with EINTR. To be able to abort a read from a signal handler, you |
Paul Cercueil |
27:3c32495708f4 | 1205 | * should implement your own blocking read using sp_nonblocking_read() |
Paul Cercueil |
27:3c32495708f4 | 1206 | * together with a blocking method that makes sense for your program. |
Paul Cercueil |
27:3c32495708f4 | 1207 | * E.g. you can obtain the file descriptor for an open port using |
Paul Cercueil |
27:3c32495708f4 | 1208 | * sp_get_port_handle() and use this to call select() or pselect(), |
Paul Cercueil |
27:3c32495708f4 | 1209 | * with appropriate arrangements to return if a signal is received. |
Paul Cercueil |
27:3c32495708f4 | 1210 | * |
Paul Cercueil |
27:3c32495708f4 | 1211 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1212 | * @param[out] buf Buffer in which to store the bytes read. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1213 | * @param[in] count Requested number of bytes to read. |
Paul Cercueil |
27:3c32495708f4 | 1214 | * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely. |
Paul Cercueil |
27:3c32495708f4 | 1215 | * |
Paul Cercueil |
27:3c32495708f4 | 1216 | * @return The number of bytes read on success, or a negative error code. If |
Paul Cercueil |
27:3c32495708f4 | 1217 | * the number of bytes returned is less than that requested, the |
Paul Cercueil |
27:3c32495708f4 | 1218 | * timeout was reached before the requested number of bytes was |
Paul Cercueil |
27:3c32495708f4 | 1219 | * available. If timeout is zero, the function will always return |
Paul Cercueil |
27:3c32495708f4 | 1220 | * either the requested number of bytes or a negative error code. |
Paul Cercueil |
27:3c32495708f4 | 1221 | * |
Paul Cercueil |
27:3c32495708f4 | 1222 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1223 | */ |
Paul Cercueil |
27:3c32495708f4 | 1224 | enum sp_return sp_blocking_read(struct sp_port *port, void *buf, size_t count, unsigned int timeout_ms); |
Paul Cercueil |
27:3c32495708f4 | 1225 | |
Paul Cercueil |
27:3c32495708f4 | 1226 | /** |
Paul Cercueil |
27:3c32495708f4 | 1227 | * Read bytes from the specified serial port, returning as soon as any data is |
Paul Cercueil |
27:3c32495708f4 | 1228 | * available. |
Paul Cercueil |
27:3c32495708f4 | 1229 | * |
Paul Cercueil |
27:3c32495708f4 | 1230 | * @warning If your program runs on Unix, defines its own signal handlers, and |
Paul Cercueil |
27:3c32495708f4 | 1231 | * needs to abort blocking reads when these are called, then you |
Paul Cercueil |
27:3c32495708f4 | 1232 | * should not use this function. It repeats system calls that return |
Paul Cercueil |
27:3c32495708f4 | 1233 | * with EINTR. To be able to abort a read from a signal handler, you |
Paul Cercueil |
27:3c32495708f4 | 1234 | * should implement your own blocking read using sp_nonblocking_read() |
Paul Cercueil |
27:3c32495708f4 | 1235 | * together with a blocking method that makes sense for your program. |
Paul Cercueil |
27:3c32495708f4 | 1236 | * E.g. you can obtain the file descriptor for an open port using |
Paul Cercueil |
27:3c32495708f4 | 1237 | * sp_get_port_handle() and use this to call select() or pselect(), |
Paul Cercueil |
27:3c32495708f4 | 1238 | * with appropriate arrangements to return if a signal is received. |
Paul Cercueil |
27:3c32495708f4 | 1239 | * |
Paul Cercueil |
27:3c32495708f4 | 1240 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1241 | * @param[out] buf Buffer in which to store the bytes read. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1242 | * @param[in] count Maximum number of bytes to read. Must not be zero. |
Paul Cercueil |
27:3c32495708f4 | 1243 | * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely. |
Paul Cercueil |
27:3c32495708f4 | 1244 | * |
Paul Cercueil |
27:3c32495708f4 | 1245 | * @return The number of bytes read on success, or a negative error code. If |
Paul Cercueil |
27:3c32495708f4 | 1246 | * the result is zero, the timeout was reached before any bytes were |
Paul Cercueil |
27:3c32495708f4 | 1247 | * available. If timeout_ms is zero, the function will always return |
Paul Cercueil |
27:3c32495708f4 | 1248 | * either at least one byte, or a negative error code. |
Paul Cercueil |
27:3c32495708f4 | 1249 | * |
Paul Cercueil |
27:3c32495708f4 | 1250 | * @since 0.1.1 |
Paul Cercueil |
27:3c32495708f4 | 1251 | */ |
Paul Cercueil |
27:3c32495708f4 | 1252 | enum sp_return sp_blocking_read_next(struct sp_port *port, void *buf, size_t count, unsigned int timeout_ms); |
Paul Cercueil |
27:3c32495708f4 | 1253 | |
Paul Cercueil |
27:3c32495708f4 | 1254 | /** |
Paul Cercueil |
27:3c32495708f4 | 1255 | * Read bytes from the specified serial port, without blocking. |
Paul Cercueil |
27:3c32495708f4 | 1256 | * |
Paul Cercueil |
27:3c32495708f4 | 1257 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1258 | * @param[out] buf Buffer in which to store the bytes read. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1259 | * @param[in] count Maximum number of bytes to read. |
Paul Cercueil |
27:3c32495708f4 | 1260 | * |
Paul Cercueil |
27:3c32495708f4 | 1261 | * @return The number of bytes read on success, or a negative error code. The |
Paul Cercueil |
27:3c32495708f4 | 1262 | * number of bytes returned may be any number from zero to the maximum |
Paul Cercueil |
27:3c32495708f4 | 1263 | * that was requested. |
Paul Cercueil |
27:3c32495708f4 | 1264 | * |
Paul Cercueil |
27:3c32495708f4 | 1265 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1266 | */ |
Paul Cercueil |
27:3c32495708f4 | 1267 | enum sp_return sp_nonblocking_read(struct sp_port *port, void *buf, size_t count); |
Paul Cercueil |
27:3c32495708f4 | 1268 | |
Paul Cercueil |
27:3c32495708f4 | 1269 | /** |
Paul Cercueil |
27:3c32495708f4 | 1270 | * Write bytes to the specified serial port, blocking until complete. |
Paul Cercueil |
27:3c32495708f4 | 1271 | * |
Paul Cercueil |
27:3c32495708f4 | 1272 | * Note that this function only ensures that the accepted bytes have been |
Paul Cercueil |
27:3c32495708f4 | 1273 | * written to the OS; they may be held in driver or hardware buffers and not |
Paul Cercueil |
27:3c32495708f4 | 1274 | * yet physically transmitted. To check whether all written bytes have actually |
Paul Cercueil |
27:3c32495708f4 | 1275 | * been transmitted, use the sp_output_waiting() function. To wait until all |
Paul Cercueil |
27:3c32495708f4 | 1276 | * written bytes have actually been transmitted, use the sp_drain() function. |
Paul Cercueil |
27:3c32495708f4 | 1277 | * |
Paul Cercueil |
27:3c32495708f4 | 1278 | * @warning If your program runs on Unix, defines its own signal handlers, and |
Paul Cercueil |
27:3c32495708f4 | 1279 | * needs to abort blocking writes when these are called, then you |
Paul Cercueil |
27:3c32495708f4 | 1280 | * should not use this function. It repeats system calls that return |
Paul Cercueil |
27:3c32495708f4 | 1281 | * with EINTR. To be able to abort a write from a signal handler, you |
Paul Cercueil |
27:3c32495708f4 | 1282 | * should implement your own blocking write using sp_nonblocking_write() |
Paul Cercueil |
27:3c32495708f4 | 1283 | * together with a blocking method that makes sense for your program. |
Paul Cercueil |
27:3c32495708f4 | 1284 | * E.g. you can obtain the file descriptor for an open port using |
Paul Cercueil |
27:3c32495708f4 | 1285 | * sp_get_port_handle() and use this to call select() or pselect(), |
Paul Cercueil |
27:3c32495708f4 | 1286 | * with appropriate arrangements to return if a signal is received. |
Paul Cercueil |
27:3c32495708f4 | 1287 | * |
Paul Cercueil |
27:3c32495708f4 | 1288 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1289 | * @param[in] buf Buffer containing the bytes to write. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1290 | * @param[in] count Requested number of bytes to write. |
Paul Cercueil |
27:3c32495708f4 | 1291 | * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely. |
Paul Cercueil |
27:3c32495708f4 | 1292 | * |
Paul Cercueil |
27:3c32495708f4 | 1293 | * @return The number of bytes written on success, or a negative error code. |
Paul Cercueil |
27:3c32495708f4 | 1294 | * If the number of bytes returned is less than that requested, the |
Paul Cercueil |
27:3c32495708f4 | 1295 | * timeout was reached before the requested number of bytes was |
Paul Cercueil |
27:3c32495708f4 | 1296 | * written. If timeout is zero, the function will always return |
Paul Cercueil |
27:3c32495708f4 | 1297 | * either the requested number of bytes or a negative error code. In |
Paul Cercueil |
27:3c32495708f4 | 1298 | * the event of an error there is no way to determine how many bytes |
Paul Cercueil |
27:3c32495708f4 | 1299 | * were sent before the error occurred. |
Paul Cercueil |
27:3c32495708f4 | 1300 | * |
Paul Cercueil |
27:3c32495708f4 | 1301 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1302 | */ |
Paul Cercueil |
27:3c32495708f4 | 1303 | enum sp_return sp_blocking_write(struct sp_port *port, const void *buf, size_t count, unsigned int timeout_ms); |
Paul Cercueil |
27:3c32495708f4 | 1304 | |
Paul Cercueil |
27:3c32495708f4 | 1305 | /** |
Paul Cercueil |
27:3c32495708f4 | 1306 | * Write bytes to the specified serial port, without blocking. |
Paul Cercueil |
27:3c32495708f4 | 1307 | * |
Paul Cercueil |
27:3c32495708f4 | 1308 | * Note that this function only ensures that the accepted bytes have been |
Paul Cercueil |
27:3c32495708f4 | 1309 | * written to the OS; they may be held in driver or hardware buffers and not |
Paul Cercueil |
27:3c32495708f4 | 1310 | * yet physically transmitted. To check whether all written bytes have actually |
Paul Cercueil |
27:3c32495708f4 | 1311 | * been transmitted, use the sp_output_waiting() function. To wait until all |
Paul Cercueil |
27:3c32495708f4 | 1312 | * written bytes have actually been transmitted, use the sp_drain() function. |
Paul Cercueil |
27:3c32495708f4 | 1313 | * |
Paul Cercueil |
27:3c32495708f4 | 1314 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1315 | * @param[in] buf Buffer containing the bytes to write. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1316 | * @param[in] count Maximum number of bytes to write. |
Paul Cercueil |
27:3c32495708f4 | 1317 | * |
Paul Cercueil |
27:3c32495708f4 | 1318 | * @return The number of bytes written on success, or a negative error code. |
Paul Cercueil |
27:3c32495708f4 | 1319 | * The number of bytes returned may be any number from zero to the |
Paul Cercueil |
27:3c32495708f4 | 1320 | * maximum that was requested. |
Paul Cercueil |
27:3c32495708f4 | 1321 | * |
Paul Cercueil |
27:3c32495708f4 | 1322 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1323 | */ |
Paul Cercueil |
27:3c32495708f4 | 1324 | enum sp_return sp_nonblocking_write(struct sp_port *port, const void *buf, size_t count); |
Paul Cercueil |
27:3c32495708f4 | 1325 | |
Paul Cercueil |
27:3c32495708f4 | 1326 | /** |
Paul Cercueil |
27:3c32495708f4 | 1327 | * Gets the number of bytes waiting in the input buffer. |
Paul Cercueil |
27:3c32495708f4 | 1328 | * |
Paul Cercueil |
27:3c32495708f4 | 1329 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1330 | * |
Paul Cercueil |
27:3c32495708f4 | 1331 | * @return Number of bytes waiting on success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1332 | * |
Paul Cercueil |
27:3c32495708f4 | 1333 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1334 | */ |
Paul Cercueil |
27:3c32495708f4 | 1335 | enum sp_return sp_input_waiting(struct sp_port *port); |
Paul Cercueil |
27:3c32495708f4 | 1336 | |
Paul Cercueil |
27:3c32495708f4 | 1337 | /** |
Paul Cercueil |
27:3c32495708f4 | 1338 | * Gets the number of bytes waiting in the output buffer. |
Paul Cercueil |
27:3c32495708f4 | 1339 | * |
Paul Cercueil |
27:3c32495708f4 | 1340 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1341 | * |
Paul Cercueil |
27:3c32495708f4 | 1342 | * @return Number of bytes waiting on success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1343 | * |
Paul Cercueil |
27:3c32495708f4 | 1344 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1345 | */ |
Paul Cercueil |
27:3c32495708f4 | 1346 | enum sp_return sp_output_waiting(struct sp_port *port); |
Paul Cercueil |
27:3c32495708f4 | 1347 | |
Paul Cercueil |
27:3c32495708f4 | 1348 | /** |
Paul Cercueil |
27:3c32495708f4 | 1349 | * Flush serial port buffers. Data in the selected buffer(s) is discarded. |
Paul Cercueil |
27:3c32495708f4 | 1350 | * |
Paul Cercueil |
27:3c32495708f4 | 1351 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1352 | * @param[in] buffers Which buffer(s) to flush. |
Paul Cercueil |
27:3c32495708f4 | 1353 | * |
Paul Cercueil |
27:3c32495708f4 | 1354 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1355 | * |
Paul Cercueil |
27:3c32495708f4 | 1356 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1357 | */ |
Paul Cercueil |
27:3c32495708f4 | 1358 | enum sp_return sp_flush(struct sp_port *port, enum sp_buffer buffers); |
Paul Cercueil |
27:3c32495708f4 | 1359 | |
Paul Cercueil |
27:3c32495708f4 | 1360 | /** |
Paul Cercueil |
27:3c32495708f4 | 1361 | * Wait for buffered data to be transmitted. |
Paul Cercueil |
27:3c32495708f4 | 1362 | * |
Paul Cercueil |
27:3c32495708f4 | 1363 | * @warning If your program runs on Unix, defines its own signal handlers, and |
Paul Cercueil |
27:3c32495708f4 | 1364 | * needs to abort draining the output buffer when when these are |
Paul Cercueil |
27:3c32495708f4 | 1365 | * called, then you should not use this function. It repeats system |
Paul Cercueil |
27:3c32495708f4 | 1366 | * calls that return with EINTR. To be able to abort a drain from a |
Paul Cercueil |
27:3c32495708f4 | 1367 | * signal handler, you would need to implement your own blocking |
Paul Cercueil |
27:3c32495708f4 | 1368 | * drain by polling the result of sp_output_waiting(). |
Paul Cercueil |
27:3c32495708f4 | 1369 | * |
Paul Cercueil |
27:3c32495708f4 | 1370 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1371 | * |
Paul Cercueil |
27:3c32495708f4 | 1372 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1373 | * |
Paul Cercueil |
27:3c32495708f4 | 1374 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1375 | */ |
Paul Cercueil |
27:3c32495708f4 | 1376 | enum sp_return sp_drain(struct sp_port *port); |
Paul Cercueil |
27:3c32495708f4 | 1377 | |
Paul Cercueil |
27:3c32495708f4 | 1378 | /** |
Paul Cercueil |
27:3c32495708f4 | 1379 | * @} |
Paul Cercueil |
27:3c32495708f4 | 1380 | * |
Paul Cercueil |
27:3c32495708f4 | 1381 | * @defgroup Waiting Waiting |
Paul Cercueil |
27:3c32495708f4 | 1382 | * |
Paul Cercueil |
27:3c32495708f4 | 1383 | * Waiting for events and timeout handling. |
Paul Cercueil |
27:3c32495708f4 | 1384 | * |
Paul Cercueil |
27:3c32495708f4 | 1385 | * @{ |
Paul Cercueil |
27:3c32495708f4 | 1386 | */ |
Paul Cercueil |
27:3c32495708f4 | 1387 | |
Paul Cercueil |
27:3c32495708f4 | 1388 | /** |
Paul Cercueil |
27:3c32495708f4 | 1389 | * Allocate storage for a set of events. |
Paul Cercueil |
27:3c32495708f4 | 1390 | * |
Paul Cercueil |
27:3c32495708f4 | 1391 | * The user should allocate a variable of type struct sp_event_set *, |
Paul Cercueil |
27:3c32495708f4 | 1392 | * then pass a pointer to this variable to receive the result. |
Paul Cercueil |
27:3c32495708f4 | 1393 | * |
Paul Cercueil |
27:3c32495708f4 | 1394 | * The result should be freed after use by calling sp_free_event_set(). |
Paul Cercueil |
27:3c32495708f4 | 1395 | * |
Paul Cercueil |
27:3c32495708f4 | 1396 | * @param[out] result_ptr If any error is returned, the variable pointed to by |
Paul Cercueil |
27:3c32495708f4 | 1397 | * result_ptr will be set to NULL. Otherwise, it will |
Paul Cercueil |
27:3c32495708f4 | 1398 | * be set to point to the event set. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1399 | * |
Paul Cercueil |
27:3c32495708f4 | 1400 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1401 | * |
Paul Cercueil |
27:3c32495708f4 | 1402 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1403 | */ |
Paul Cercueil |
27:3c32495708f4 | 1404 | enum sp_return sp_new_event_set(struct sp_event_set **result_ptr); |
Paul Cercueil |
27:3c32495708f4 | 1405 | |
Paul Cercueil |
27:3c32495708f4 | 1406 | /** |
Paul Cercueil |
27:3c32495708f4 | 1407 | * Add events to a struct sp_event_set for a given port. |
Paul Cercueil |
27:3c32495708f4 | 1408 | * |
Paul Cercueil |
27:3c32495708f4 | 1409 | * The port must first be opened by calling sp_open() using the same port |
Paul Cercueil |
27:3c32495708f4 | 1410 | * structure. |
Paul Cercueil |
27:3c32495708f4 | 1411 | * |
Paul Cercueil |
27:3c32495708f4 | 1412 | * After the port is closed or the port structure freed, the results may |
Paul Cercueil |
27:3c32495708f4 | 1413 | * no longer be valid. |
Paul Cercueil |
27:3c32495708f4 | 1414 | * |
Paul Cercueil |
27:3c32495708f4 | 1415 | * @param[in,out] event_set Event set to update. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1416 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1417 | * @param[in] mask Bitmask of events to be waited for. |
Paul Cercueil |
27:3c32495708f4 | 1418 | * |
Paul Cercueil |
27:3c32495708f4 | 1419 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1420 | * |
Paul Cercueil |
27:3c32495708f4 | 1421 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1422 | */ |
Paul Cercueil |
27:3c32495708f4 | 1423 | enum sp_return sp_add_port_events(struct sp_event_set *event_set, |
Paul Cercueil |
27:3c32495708f4 | 1424 | const struct sp_port *port, enum sp_event mask); |
Paul Cercueil |
27:3c32495708f4 | 1425 | |
Paul Cercueil |
27:3c32495708f4 | 1426 | /** |
Paul Cercueil |
27:3c32495708f4 | 1427 | * Wait for any of a set of events to occur. |
Paul Cercueil |
27:3c32495708f4 | 1428 | * |
Paul Cercueil |
27:3c32495708f4 | 1429 | * @param[in] event_set Event set to wait on. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1430 | * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely. |
Paul Cercueil |
27:3c32495708f4 | 1431 | * |
Paul Cercueil |
27:3c32495708f4 | 1432 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1433 | * |
Paul Cercueil |
27:3c32495708f4 | 1434 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1435 | */ |
Paul Cercueil |
27:3c32495708f4 | 1436 | enum sp_return sp_wait(struct sp_event_set *event_set, unsigned int timeout_ms); |
Paul Cercueil |
27:3c32495708f4 | 1437 | |
Paul Cercueil |
27:3c32495708f4 | 1438 | /** |
Paul Cercueil |
27:3c32495708f4 | 1439 | * Free a structure allocated by sp_new_event_set(). |
Paul Cercueil |
27:3c32495708f4 | 1440 | * |
Paul Cercueil |
27:3c32495708f4 | 1441 | * @param[in] event_set Event set to free. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1442 | * |
Paul Cercueil |
27:3c32495708f4 | 1443 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1444 | */ |
Paul Cercueil |
27:3c32495708f4 | 1445 | void sp_free_event_set(struct sp_event_set *event_set); |
Paul Cercueil |
27:3c32495708f4 | 1446 | |
Paul Cercueil |
27:3c32495708f4 | 1447 | /** |
Paul Cercueil |
27:3c32495708f4 | 1448 | * @} |
Paul Cercueil |
27:3c32495708f4 | 1449 | * |
Paul Cercueil |
27:3c32495708f4 | 1450 | * @defgroup Signals Signals |
Paul Cercueil |
27:3c32495708f4 | 1451 | * |
Paul Cercueil |
27:3c32495708f4 | 1452 | * Port signalling operations. |
Paul Cercueil |
27:3c32495708f4 | 1453 | * |
Paul Cercueil |
27:3c32495708f4 | 1454 | * @{ |
Paul Cercueil |
27:3c32495708f4 | 1455 | */ |
Paul Cercueil |
27:3c32495708f4 | 1456 | |
Paul Cercueil |
27:3c32495708f4 | 1457 | /** |
Paul Cercueil |
27:3c32495708f4 | 1458 | * Gets the status of the control signals for the specified port. |
Paul Cercueil |
27:3c32495708f4 | 1459 | * |
Paul Cercueil |
27:3c32495708f4 | 1460 | * The user should allocate a variable of type "enum sp_signal" and pass a |
Paul Cercueil |
27:3c32495708f4 | 1461 | * pointer to this variable to receive the result. The result is a bitmask |
Paul Cercueil |
27:3c32495708f4 | 1462 | * in which individual signals can be checked by bitwise OR with values of |
Paul Cercueil |
27:3c32495708f4 | 1463 | * the sp_signal enum. |
Paul Cercueil |
27:3c32495708f4 | 1464 | * |
Paul Cercueil |
27:3c32495708f4 | 1465 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1466 | * @param[out] signal_mask Pointer to a variable to receive the result. |
Paul Cercueil |
27:3c32495708f4 | 1467 | * Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1468 | * |
Paul Cercueil |
27:3c32495708f4 | 1469 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1470 | * |
Paul Cercueil |
27:3c32495708f4 | 1471 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1472 | */ |
Paul Cercueil |
27:3c32495708f4 | 1473 | enum sp_return sp_get_signals(struct sp_port *port, enum sp_signal *signal_mask); |
Paul Cercueil |
27:3c32495708f4 | 1474 | |
Paul Cercueil |
27:3c32495708f4 | 1475 | /** |
Paul Cercueil |
27:3c32495708f4 | 1476 | * Put the port transmit line into the break state. |
Paul Cercueil |
27:3c32495708f4 | 1477 | * |
Paul Cercueil |
27:3c32495708f4 | 1478 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1479 | * |
Paul Cercueil |
27:3c32495708f4 | 1480 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1481 | * |
Paul Cercueil |
27:3c32495708f4 | 1482 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1483 | */ |
Paul Cercueil |
27:3c32495708f4 | 1484 | enum sp_return sp_start_break(struct sp_port *port); |
Paul Cercueil |
27:3c32495708f4 | 1485 | |
Paul Cercueil |
27:3c32495708f4 | 1486 | /** |
Paul Cercueil |
27:3c32495708f4 | 1487 | * Take the port transmit line out of the break state. |
Paul Cercueil |
27:3c32495708f4 | 1488 | * |
Paul Cercueil |
27:3c32495708f4 | 1489 | * @param[in] port Pointer to a port structure. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1490 | * |
Paul Cercueil |
27:3c32495708f4 | 1491 | * @return SP_OK upon success, a negative error code otherwise. |
Paul Cercueil |
27:3c32495708f4 | 1492 | * |
Paul Cercueil |
27:3c32495708f4 | 1493 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1494 | */ |
Paul Cercueil |
27:3c32495708f4 | 1495 | enum sp_return sp_end_break(struct sp_port *port); |
Paul Cercueil |
27:3c32495708f4 | 1496 | |
Paul Cercueil |
27:3c32495708f4 | 1497 | /** |
Paul Cercueil |
27:3c32495708f4 | 1498 | * @} |
Paul Cercueil |
27:3c32495708f4 | 1499 | * |
Paul Cercueil |
27:3c32495708f4 | 1500 | * @defgroup Errors Errors |
Paul Cercueil |
27:3c32495708f4 | 1501 | * |
Paul Cercueil |
27:3c32495708f4 | 1502 | * Obtaining error information. |
Paul Cercueil |
27:3c32495708f4 | 1503 | * |
Paul Cercueil |
27:3c32495708f4 | 1504 | * @{ |
Paul Cercueil |
27:3c32495708f4 | 1505 | */ |
Paul Cercueil |
27:3c32495708f4 | 1506 | |
Paul Cercueil |
27:3c32495708f4 | 1507 | /** |
Paul Cercueil |
27:3c32495708f4 | 1508 | * Get the error code for a failed operation. |
Paul Cercueil |
27:3c32495708f4 | 1509 | * |
Paul Cercueil |
27:3c32495708f4 | 1510 | * In order to obtain the correct result, this function should be called |
Paul Cercueil |
27:3c32495708f4 | 1511 | * straight after the failure, before executing any other system operations. |
Paul Cercueil |
27:3c32495708f4 | 1512 | * The result is thread-specific, and only valid when called immediately |
Paul Cercueil |
27:3c32495708f4 | 1513 | * after a previous call returning SP_ERR_FAIL. |
Paul Cercueil |
27:3c32495708f4 | 1514 | * |
Paul Cercueil |
27:3c32495708f4 | 1515 | * @return The system's numeric code for the error that caused the last |
Paul Cercueil |
27:3c32495708f4 | 1516 | * operation to fail. |
Paul Cercueil |
27:3c32495708f4 | 1517 | * |
Paul Cercueil |
27:3c32495708f4 | 1518 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1519 | */ |
Paul Cercueil |
27:3c32495708f4 | 1520 | int sp_last_error_code(void); |
Paul Cercueil |
27:3c32495708f4 | 1521 | |
Paul Cercueil |
27:3c32495708f4 | 1522 | /** |
Paul Cercueil |
27:3c32495708f4 | 1523 | * Get the error message for a failed operation. |
Paul Cercueil |
27:3c32495708f4 | 1524 | * |
Paul Cercueil |
27:3c32495708f4 | 1525 | * In order to obtain the correct result, this function should be called |
Paul Cercueil |
27:3c32495708f4 | 1526 | * straight after the failure, before executing other system operations. |
Paul Cercueil |
27:3c32495708f4 | 1527 | * The result is thread-specific, and only valid when called immediately |
Paul Cercueil |
27:3c32495708f4 | 1528 | * after a previous call returning SP_ERR_FAIL. |
Paul Cercueil |
27:3c32495708f4 | 1529 | * |
Paul Cercueil |
27:3c32495708f4 | 1530 | * @return The system's message for the error that caused the last |
Paul Cercueil |
27:3c32495708f4 | 1531 | * operation to fail. This string may be allocated by the function, |
Paul Cercueil |
27:3c32495708f4 | 1532 | * and should be freed after use by calling sp_free_error_message(). |
Paul Cercueil |
27:3c32495708f4 | 1533 | * |
Paul Cercueil |
27:3c32495708f4 | 1534 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1535 | */ |
Paul Cercueil |
27:3c32495708f4 | 1536 | char *sp_last_error_message(void); |
Paul Cercueil |
27:3c32495708f4 | 1537 | |
Paul Cercueil |
27:3c32495708f4 | 1538 | /** |
Paul Cercueil |
27:3c32495708f4 | 1539 | * Free an error message returned by sp_last_error_message(). |
Paul Cercueil |
27:3c32495708f4 | 1540 | * |
Paul Cercueil |
27:3c32495708f4 | 1541 | * @param[in] message The error message string to free. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1542 | * |
Paul Cercueil |
27:3c32495708f4 | 1543 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1544 | */ |
Paul Cercueil |
27:3c32495708f4 | 1545 | void sp_free_error_message(char *message); |
Paul Cercueil |
27:3c32495708f4 | 1546 | |
Paul Cercueil |
27:3c32495708f4 | 1547 | /** |
Paul Cercueil |
27:3c32495708f4 | 1548 | * Set the handler function for library debugging messages. |
Paul Cercueil |
27:3c32495708f4 | 1549 | * |
Paul Cercueil |
27:3c32495708f4 | 1550 | * Debugging messages are generated by the library during each operation, |
Paul Cercueil |
27:3c32495708f4 | 1551 | * to help in diagnosing problems. The handler will be called for each |
Paul Cercueil |
27:3c32495708f4 | 1552 | * message. The handler can be set to NULL to ignore all debug messages. |
Paul Cercueil |
27:3c32495708f4 | 1553 | * |
Paul Cercueil |
27:3c32495708f4 | 1554 | * The handler function should accept a format string and variable length |
Paul Cercueil |
27:3c32495708f4 | 1555 | * argument list, in the same manner as e.g. printf(). |
Paul Cercueil |
27:3c32495708f4 | 1556 | * |
Paul Cercueil |
27:3c32495708f4 | 1557 | * The default handler is sp_default_debug_handler(). |
Paul Cercueil |
27:3c32495708f4 | 1558 | * |
Paul Cercueil |
27:3c32495708f4 | 1559 | * @param[in] handler The handler function to use. Can be NULL (in that case |
Paul Cercueil |
27:3c32495708f4 | 1560 | * all debug messages will be ignored). |
Paul Cercueil |
27:3c32495708f4 | 1561 | * |
Paul Cercueil |
27:3c32495708f4 | 1562 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1563 | */ |
Paul Cercueil |
27:3c32495708f4 | 1564 | void sp_set_debug_handler(void (*handler)(const char *format, ...)); |
Paul Cercueil |
27:3c32495708f4 | 1565 | |
Paul Cercueil |
27:3c32495708f4 | 1566 | /** |
Paul Cercueil |
27:3c32495708f4 | 1567 | * Default handler function for library debugging messages. |
Paul Cercueil |
27:3c32495708f4 | 1568 | * |
Paul Cercueil |
27:3c32495708f4 | 1569 | * This function prints debug messages to the standard error stream if the |
Paul Cercueil |
27:3c32495708f4 | 1570 | * environment variable LIBSERIALPORT_DEBUG is set. Otherwise, they are |
Paul Cercueil |
27:3c32495708f4 | 1571 | * ignored. |
Paul Cercueil |
27:3c32495708f4 | 1572 | * |
Paul Cercueil |
27:3c32495708f4 | 1573 | * @param[in] format The format string to use. Must not be NULL. |
Paul Cercueil |
27:3c32495708f4 | 1574 | * @param[in] ... The variable length argument list to use. |
Paul Cercueil |
27:3c32495708f4 | 1575 | * |
Paul Cercueil |
27:3c32495708f4 | 1576 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1577 | */ |
Paul Cercueil |
27:3c32495708f4 | 1578 | void sp_default_debug_handler(const char *format, ...); |
Paul Cercueil |
27:3c32495708f4 | 1579 | |
Paul Cercueil |
27:3c32495708f4 | 1580 | /** @} */ |
Paul Cercueil |
27:3c32495708f4 | 1581 | |
Paul Cercueil |
27:3c32495708f4 | 1582 | /** |
Paul Cercueil |
27:3c32495708f4 | 1583 | * @defgroup Versions Versions |
Paul Cercueil |
27:3c32495708f4 | 1584 | * |
Paul Cercueil |
27:3c32495708f4 | 1585 | * Version number querying functions, definitions, and macros. |
Paul Cercueil |
27:3c32495708f4 | 1586 | * |
Paul Cercueil |
27:3c32495708f4 | 1587 | * This set of API calls returns two different version numbers related |
Paul Cercueil |
27:3c32495708f4 | 1588 | * to libserialport. The "package version" is the release version number of the |
Paul Cercueil |
27:3c32495708f4 | 1589 | * libserialport tarball in the usual "major.minor.micro" format, e.g. "0.1.0". |
Paul Cercueil |
27:3c32495708f4 | 1590 | * |
Paul Cercueil |
27:3c32495708f4 | 1591 | * The "library version" is independent of that; it is the libtool version |
Paul Cercueil |
27:3c32495708f4 | 1592 | * number in the "current:revision:age" format, e.g. "2:0:0". |
Paul Cercueil |
27:3c32495708f4 | 1593 | * See http://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning for details. |
Paul Cercueil |
27:3c32495708f4 | 1594 | * |
Paul Cercueil |
27:3c32495708f4 | 1595 | * Both version numbers (and/or individual components of them) can be |
Paul Cercueil |
27:3c32495708f4 | 1596 | * retrieved via the API calls at runtime, and/or they can be checked at |
Paul Cercueil |
27:3c32495708f4 | 1597 | * compile/preprocessor time using the respective macros. |
Paul Cercueil |
27:3c32495708f4 | 1598 | * |
Paul Cercueil |
27:3c32495708f4 | 1599 | * @{ |
Paul Cercueil |
27:3c32495708f4 | 1600 | */ |
Paul Cercueil |
27:3c32495708f4 | 1601 | |
Paul Cercueil |
27:3c32495708f4 | 1602 | /* |
Paul Cercueil |
27:3c32495708f4 | 1603 | * Package version macros (can be used for conditional compilation). |
Paul Cercueil |
27:3c32495708f4 | 1604 | */ |
Paul Cercueil |
27:3c32495708f4 | 1605 | |
Paul Cercueil |
27:3c32495708f4 | 1606 | /** The libserialport package 'major' version number. */ |
Paul Cercueil |
27:3c32495708f4 | 1607 | #define SP_PACKAGE_VERSION_MAJOR 0 |
Paul Cercueil |
27:3c32495708f4 | 1608 | |
Paul Cercueil |
27:3c32495708f4 | 1609 | /** The libserialport package 'minor' version number. */ |
Paul Cercueil |
27:3c32495708f4 | 1610 | #define SP_PACKAGE_VERSION_MINOR 1 |
Paul Cercueil |
27:3c32495708f4 | 1611 | |
Paul Cercueil |
27:3c32495708f4 | 1612 | /** The libserialport package 'micro' version number. */ |
Paul Cercueil |
27:3c32495708f4 | 1613 | #define SP_PACKAGE_VERSION_MICRO 1 |
Paul Cercueil |
27:3c32495708f4 | 1614 | |
Paul Cercueil |
27:3c32495708f4 | 1615 | /** The libserialport package version ("major.minor.micro") as string. */ |
Paul Cercueil |
27:3c32495708f4 | 1616 | #define SP_PACKAGE_VERSION_STRING "0.1.1" |
Paul Cercueil |
27:3c32495708f4 | 1617 | |
Paul Cercueil |
27:3c32495708f4 | 1618 | /* |
Paul Cercueil |
27:3c32495708f4 | 1619 | * Library/libtool version macros (can be used for conditional compilation). |
Paul Cercueil |
27:3c32495708f4 | 1620 | */ |
Paul Cercueil |
27:3c32495708f4 | 1621 | |
Paul Cercueil |
27:3c32495708f4 | 1622 | /** The libserialport libtool 'current' version number. */ |
Paul Cercueil |
27:3c32495708f4 | 1623 | #define SP_LIB_VERSION_CURRENT 1 |
Paul Cercueil |
27:3c32495708f4 | 1624 | |
Paul Cercueil |
27:3c32495708f4 | 1625 | /** The libserialport libtool 'revision' version number. */ |
Paul Cercueil |
27:3c32495708f4 | 1626 | #define SP_LIB_VERSION_REVISION 0 |
Paul Cercueil |
27:3c32495708f4 | 1627 | |
Paul Cercueil |
27:3c32495708f4 | 1628 | /** The libserialport libtool 'age' version number. */ |
Paul Cercueil |
27:3c32495708f4 | 1629 | #define SP_LIB_VERSION_AGE 1 |
Paul Cercueil |
27:3c32495708f4 | 1630 | |
Paul Cercueil |
27:3c32495708f4 | 1631 | /** The libserialport libtool version ("current:revision:age") as string. */ |
Paul Cercueil |
27:3c32495708f4 | 1632 | #define SP_LIB_VERSION_STRING "1:0:1" |
Paul Cercueil |
27:3c32495708f4 | 1633 | |
Paul Cercueil |
27:3c32495708f4 | 1634 | /** |
Paul Cercueil |
27:3c32495708f4 | 1635 | * Get the major libserialport package version number. |
Paul Cercueil |
27:3c32495708f4 | 1636 | * |
Paul Cercueil |
27:3c32495708f4 | 1637 | * @return The major package version number. |
Paul Cercueil |
27:3c32495708f4 | 1638 | * |
Paul Cercueil |
27:3c32495708f4 | 1639 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1640 | */ |
Paul Cercueil |
27:3c32495708f4 | 1641 | int sp_get_major_package_version(void); |
Paul Cercueil |
27:3c32495708f4 | 1642 | |
Paul Cercueil |
27:3c32495708f4 | 1643 | /** |
Paul Cercueil |
27:3c32495708f4 | 1644 | * Get the minor libserialport package version number. |
Paul Cercueil |
27:3c32495708f4 | 1645 | * |
Paul Cercueil |
27:3c32495708f4 | 1646 | * @return The minor package version number. |
Paul Cercueil |
27:3c32495708f4 | 1647 | * |
Paul Cercueil |
27:3c32495708f4 | 1648 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1649 | */ |
Paul Cercueil |
27:3c32495708f4 | 1650 | int sp_get_minor_package_version(void); |
Paul Cercueil |
27:3c32495708f4 | 1651 | |
Paul Cercueil |
27:3c32495708f4 | 1652 | /** |
Paul Cercueil |
27:3c32495708f4 | 1653 | * Get the micro libserialport package version number. |
Paul Cercueil |
27:3c32495708f4 | 1654 | * |
Paul Cercueil |
27:3c32495708f4 | 1655 | * @return The micro package version number. |
Paul Cercueil |
27:3c32495708f4 | 1656 | * |
Paul Cercueil |
27:3c32495708f4 | 1657 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1658 | */ |
Paul Cercueil |
27:3c32495708f4 | 1659 | int sp_get_micro_package_version(void); |
Paul Cercueil |
27:3c32495708f4 | 1660 | |
Paul Cercueil |
27:3c32495708f4 | 1661 | /** |
Paul Cercueil |
27:3c32495708f4 | 1662 | * Get the libserialport package version number as a string. |
Paul Cercueil |
27:3c32495708f4 | 1663 | * |
Paul Cercueil |
27:3c32495708f4 | 1664 | * @return The package version number string. The returned string is |
Paul Cercueil |
27:3c32495708f4 | 1665 | * static and thus should NOT be free'd by the caller. |
Paul Cercueil |
27:3c32495708f4 | 1666 | * |
Paul Cercueil |
27:3c32495708f4 | 1667 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1668 | */ |
Paul Cercueil |
27:3c32495708f4 | 1669 | const char *sp_get_package_version_string(void); |
Paul Cercueil |
27:3c32495708f4 | 1670 | |
Paul Cercueil |
27:3c32495708f4 | 1671 | /** |
Paul Cercueil |
27:3c32495708f4 | 1672 | * Get the "current" part of the libserialport library version number. |
Paul Cercueil |
27:3c32495708f4 | 1673 | * |
Paul Cercueil |
27:3c32495708f4 | 1674 | * @return The "current" library version number. |
Paul Cercueil |
27:3c32495708f4 | 1675 | * |
Paul Cercueil |
27:3c32495708f4 | 1676 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1677 | */ |
Paul Cercueil |
27:3c32495708f4 | 1678 | int sp_get_current_lib_version(void); |
Paul Cercueil |
27:3c32495708f4 | 1679 | |
Paul Cercueil |
27:3c32495708f4 | 1680 | /** |
Paul Cercueil |
27:3c32495708f4 | 1681 | * Get the "revision" part of the libserialport library version number. |
Paul Cercueil |
27:3c32495708f4 | 1682 | * |
Paul Cercueil |
27:3c32495708f4 | 1683 | * @return The "revision" library version number. |
Paul Cercueil |
27:3c32495708f4 | 1684 | * |
Paul Cercueil |
27:3c32495708f4 | 1685 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1686 | */ |
Paul Cercueil |
27:3c32495708f4 | 1687 | int sp_get_revision_lib_version(void); |
Paul Cercueil |
27:3c32495708f4 | 1688 | |
Paul Cercueil |
27:3c32495708f4 | 1689 | /** |
Paul Cercueil |
27:3c32495708f4 | 1690 | * Get the "age" part of the libserialport library version number. |
Paul Cercueil |
27:3c32495708f4 | 1691 | * |
Paul Cercueil |
27:3c32495708f4 | 1692 | * @return The "age" library version number. |
Paul Cercueil |
27:3c32495708f4 | 1693 | * |
Paul Cercueil |
27:3c32495708f4 | 1694 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1695 | */ |
Paul Cercueil |
27:3c32495708f4 | 1696 | int sp_get_age_lib_version(void); |
Paul Cercueil |
27:3c32495708f4 | 1697 | |
Paul Cercueil |
27:3c32495708f4 | 1698 | /** |
Paul Cercueil |
27:3c32495708f4 | 1699 | * Get the libserialport library version number as a string. |
Paul Cercueil |
27:3c32495708f4 | 1700 | * |
Paul Cercueil |
27:3c32495708f4 | 1701 | * @return The library version number string. The returned string is |
Paul Cercueil |
27:3c32495708f4 | 1702 | * static and thus should NOT be free'd by the caller. |
Paul Cercueil |
27:3c32495708f4 | 1703 | * |
Paul Cercueil |
27:3c32495708f4 | 1704 | * @since 0.1.0 |
Paul Cercueil |
27:3c32495708f4 | 1705 | */ |
Paul Cercueil |
27:3c32495708f4 | 1706 | const char *sp_get_lib_version_string(void); |
Paul Cercueil |
27:3c32495708f4 | 1707 | |
Paul Cercueil |
27:3c32495708f4 | 1708 | /** @} */ |
Paul Cercueil |
27:3c32495708f4 | 1709 | |
Paul Cercueil |
27:3c32495708f4 | 1710 | #ifdef __cplusplus |
Paul Cercueil |
27:3c32495708f4 | 1711 | } |
Paul Cercueil |
27:3c32495708f4 | 1712 | #endif |
Paul Cercueil |
27:3c32495708f4 | 1713 | |
Paul Cercueil |
27:3c32495708f4 | 1714 | #endif |