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 Bernie Innocenti <bernie@codewiz.org>
33 * \brief Simple serial I/O driver
35 * \author Bernie Innocenti <bernie@codewiz.org>
36 * \author Francesco Sacchi <batt@develer.com>
39 #ifndef DRV_SER_SIMPLE_AVR_H
40 #define DRV_SER_SIMPLE_AVR_H
42 #warning FIXME:This module is obsolete, yuo must refactor it.
45 /* For checking which serial driver is linked */
48 #include <appconfig.h>
49 #include <cfg/compiler.h>
54 typedef uint8_t serstatus_t;
57 #define SERRF_RXFIFOOVERRUN BV(0) /**< Rx FIFO buffer overrun */
58 #define SERRF_RXTIMEOUT BV(5) /**< Receive timeout */
59 #define SERRF_TXTIMEOUT BV(6) /**< Transmit timeout */
62 #define SERRF_RXSROVERRUN BV(3) /**< Rx shift register overrun */
63 #define SERRF_FRAMEERROR BV(4) /**< Stop bit missing */
64 #define SERRF_PARITYERROR BV(7) /**< Parity error */
66 #error unknown architecture
71 * \name Serial hw numbers
77 #if CPU_AVR_ATMEGA64 || CPU_AVR_ATMEGA128
81 #elif CPU_AVR_ATMEGA103 || CPU_AVR_ATMEGA8
85 #error unknown architecture
87 SER_CNT /**< Number of serial ports */
92 /** \name Parity settings for ser_setparity() */
94 #define SER_PARITY_NONE 0
95 #define SER_PARITY_EVEN 2
96 #define SER_PARITY_ODD 3
100 /** Serial handle structure */
103 /* Function prototypes */
104 extern int _ser_putchar(int c);
105 extern int _ser_getchar(void);
106 extern int _ser_getchar_nowait(void);
108 extern int ser_write(struct Serial *port, const void *buf, size_t len);
109 extern int ser_read(struct Serial *port, void *buf, size_t size);
111 extern int ser_printf(struct Serial *port, const char *format, ...) FORMAT(__printf__, 2, 3);
113 extern int ser_gets(struct Serial *port, char *buf, int size);
114 extern int ser_gets_echo(struct Serial *port, char *buf, int size, bool echo);
116 extern int _ser_print(const char *s);
118 extern void _ser_setbaudrate(unsigned long rate);
119 extern void _ser_setparity(int parity);
120 extern void _ser_settimeouts(void);
121 extern void _ser_setstatus(void);
123 extern void ser_resync(struct Serial *port, time_t delay);
124 extern void ser_drain(struct Serial *port);
126 extern void _ser_purge(void);
127 extern struct Serial *_ser_open(void);
128 extern void _ser_close(void);
131 * \name Functions implemented as macros
135 #define ser_putchar(c, port) _ser_putchar(c)
136 #define ser_getchar(port) _ser_getchar()
137 #define ser_getchar_nowait(port) _ser_getchar_nowait()
138 #define ser_print(port, s) _ser_print(s)
139 #define ser_setbaudrate(port, y) _ser_setbaudrate(y)
140 #define ser_setparity(port, par) _ser_setparity(par)
141 #define ser_settimeouts(port, y, z) _ser_settimeouts()
142 #define ser_purge(port) _ser_purge()
143 #define ser_open(port) _ser_open()
144 #define ser_getstatus(h) 0
145 #define ser_setstatus(h, x) do {(void)(x);} while(0)
148 #endif /* DRV_SER_SIMPLE_AVR_H */