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>
33 * \brief Simple serial I/O driver
36 * \author Bernardo Innocenti <bernie@develer.com>
37 * \author Francesco Sacchi <batt@develer.com>
42 *#* Revision 1.2 2006/07/19 12:56:26 bernie
43 *#* Convert to new Doxygen style.
45 *#* Revision 1.1 2005/04/12 01:37:50 bernie
46 *#* Import into DevLib.
48 *#* Revision 1.5 2004/10/20 13:37:49 batt
49 *#* Change testing of simple serial instead of ARCH_BOOT in sc driver.
51 *#* Revision 1.4 2004/10/15 12:22:04 batt
52 *#* Readd ';' in setstatus macro.
54 *#* Revision 1.3 2004/10/15 12:13:57 batt
55 *#* Correct \brief header.
57 *#* Revision 1.2 2004/10/15 11:54:21 batt
60 *#* Revision 1.1 2004/10/13 16:35:36 batt
61 *#* New (simple) serial driver.
68 /* For checking which serial driver is linked */
71 #include <appconfig.h>
72 #include <cfg/compiler.h>
77 typedef uint8_t serstatus_t;
80 #define SERRF_RXFIFOOVERRUN BV(0) /**< Rx FIFO buffer overrun */
81 #define SERRF_RXTIMEOUT BV(5) /**< Receive timeout */
82 #define SERRF_TXTIMEOUT BV(6) /**< Transmit timeout */
85 #define SERRF_RXSROVERRUN BV(3) /**< Rx shift register overrun */
86 #define SERRF_FRAMEERROR BV(4) /**< Stop bit missing */
87 #define SERRF_PARITYERROR BV(7) /**< Parity error */
89 #error unknown architecture
94 * \name Serial hw numbers
100 #if CPU_AVR_ATMEGA64 || CPU_AVR_ATMEGA128
104 #elif CPU_AVR_ATMEGA103 || CPU_AVR_ATMEGA8
108 #error unknown architecture
110 SER_CNT /**< Number of serial ports */
115 /** \name Parity settings for ser_setparity() */
117 #define SER_PARITY_NONE 0
118 #define SER_PARITY_EVEN 2
119 #define SER_PARITY_ODD 3
123 /** Serial handle structure */
126 /* Function prototypes */
127 extern int _ser_putchar(int c);
128 extern int _ser_getchar(void);
129 extern int _ser_getchar_nowait(void);
131 extern int ser_write(struct Serial *port, const void *buf, size_t len);
132 extern int ser_read(struct Serial *port, void *buf, size_t size);
134 extern int ser_printf(struct Serial *port, const char *format, ...) FORMAT(__printf__, 2, 3);
136 extern int ser_gets(struct Serial *port, char *buf, int size);
137 extern int ser_gets_echo(struct Serial *port, char *buf, int size, bool echo);
139 extern int _ser_print(const char *s);
141 extern void _ser_setbaudrate(unsigned long rate);
142 extern void _ser_setparity(int parity);
143 extern void _ser_settimeouts(void);
144 extern void _ser_setstatus(void);
146 extern void ser_resync(struct Serial *port, time_t delay);
147 extern void ser_drain(struct Serial *port);
149 extern void _ser_purge(void);
150 extern struct Serial *_ser_open(void);
151 extern void _ser_close(void);
154 * \name Functions implemented as macros
158 #define ser_putchar(c, port) _ser_putchar(c)
159 #define ser_getchar(port) _ser_getchar()
160 #define ser_getchar_nowait(port) _ser_getchar_nowait()
161 #define ser_print(port, s) _ser_print(s)
162 #define ser_setbaudrate(port, y) _ser_setbaudrate(y)
163 #define ser_setparity(port, par) _ser_setparity(par)
164 #define ser_settimeouts(port, y, z) _ser_settimeouts()
165 #define ser_purge(port) _ser_purge()
166 #define ser_open(port) _ser_open()
167 #define ser_getstatus(h) 0
168 #define ser_setstatus(h, x) do {(void)(x);} while(0)
171 #endif /* SER_SIMPLE_H */