4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2003,2004 Develer S.r.l. (http://www.develer.com/)
30 * Copyright 2000 Bernardo Innocenti <bernie@codewiz.org>
34 * \brief High level serial I/O API
37 * \author Bernardo Innocenti <bernie@develer.com>
43 #include <kern/kfile.h>
44 #include <mware/fifobuf.h>
45 #include <cfg/compiler.h>
48 #include <cfg/macros.h> /* BV() */
50 typedef uint16_t serstatus_t;
53 #define SERRF_RXFIFOOVERRUN BV(0) /**< Rx FIFO buffer overrun */
54 #define SERRF_RXTIMEOUT BV(1) /**< Receive timeout */
55 #define SERRF_TXTIMEOUT BV(2) /**< Transmit timeout */
58 #define SERRF_RXSROVERRUN 0 /**< Unsupported in emulated serial port. */
59 #define SERRF_FRAMEERROR 0 /**< Unsupported in emulated serial port. */
60 #define SERRF_PARITYERROR 0 /**< Unsupported in emulated serial port. */
61 #define SERRF_NOISEERROR 0 /**< Unsupported in emulated serial port. */
68 SER_CNT /**< Number of serial ports */
72 #include CPU_HEADER(ser)
75 #include "cfg/cfg_ser.h"
80 * \name Masks to group TX/RX errors.
84 ( SERRF_RXFIFOOVERRUN \
90 #define SERRF_TX (SERRF_TXTIMEOUT)
94 * \name LSB or MSB first data order for SPI driver.
97 #define SER_MSB_FIRST 0
98 #define SER_LSB_FIRST 1
102 * \name Parity settings for ser_setparity().
104 * \note Values are AVR-specific for performance reasons.
105 * Other processors should either decode them or
106 * redefine these macros.
109 #define SER_PARITY_NONE 0
110 #define SER_PARITY_EVEN 2
111 #define SER_PARITY_ODD 3
115 struct SerialHardware;
117 /** Human-readable serial error descriptions */
118 extern const char * const serial_errors[8];
120 /** Serial handle structure */
121 typedef struct Serial
123 /** Physical port number */
131 * \name Transmit and receive FIFOs.
133 * Declared volatile because handled asinchronously by interrupts.
141 #if CONFIG_SER_RXTIMEOUT != -1
144 #if CONFIG_SER_TXTIMEOUT != -1
148 /** Holds the flags defined above. Will be 0 when no errors have occurred. */
149 volatile serstatus_t status;
151 /** Low-level interface to hardware. */
152 struct SerialHardware* hw;
155 typedef struct KFileSerial
164 #define KFT_SERIAL MAKE_ID('S', 'E', 'R', 'L')
167 INLINE KFileSerial * KFILESERIAL(KFile *fd)
169 ASSERT(fd->_type == KFT_SERIAL);
170 return (KFileSerial *)fd;
173 /* Function prototypes */
174 //extern int ser_getchar_nowait(struct Serial *port);
176 void ser_setbaudrate(struct KFileSerial *fd, unsigned long rate);
177 void ser_setparity(struct KFileSerial *fd, int parity);
178 void ser_settimeouts(struct KFileSerial *fd, mtime_t rxtimeout, mtime_t txtimeout);
179 void ser_resync(struct KFileSerial *fd, mtime_t delay);
180 int ser_getchar_nowait(struct KFileSerial *fd);
182 void ser_purgeRx(struct KFileSerial *fd);
183 void ser_purgeTx(struct KFileSerial *fd);
184 void ser_purge(struct KFileSerial *fd);
185 void ser_init(struct KFileSerial *fds, unsigned int unit);
186 void spimaster_init(KFileSerial *fds, unsigned int unit);
190 * \name Additional functions implemented as macros
194 #define ser_getstatus(h) ((h)->status)
195 #define ser_setstatus(h, x) ((h)->status = (x))
198 #endif /* DRV_SER_H */