Move also cpu/ to bertos/ :-).
[bertos.git] / bertos / cpu / avr / drv / ser_simple_avr.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
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.
10  *
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.
15  *
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
19  *
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.
28  *
29  * Copyright 2003,2004 Develer S.r.l. (http://www.develer.com/)
30  * Copyright 2000 Bernardo Innocenti <bernie@codewiz.org>
31  * -->
32  *
33  * \brief Simple serial I/O driver
34  *
35  * \version $Id$
36  * \author Bernardo Innocenti <bernie@develer.com>
37  * \author Francesco Sacchi <batt@develer.com>
38  */
39
40 /*#*
41  *#* $Log$
42  *#* Revision 1.2  2006/07/19 12:56:26  bernie
43  *#* Convert to new Doxygen style.
44  *#*
45  *#* Revision 1.1  2005/04/12 01:37:50  bernie
46  *#* Import into DevLib.
47  *#*
48  *#* Revision 1.5  2004/10/20 13:37:49  batt
49  *#* Change testing of simple serial instead of ARCH_BOOT in sc driver.
50  *#*
51  *#* Revision 1.4  2004/10/15 12:22:04  batt
52  *#* Readd ';' in setstatus macro.
53  *#*
54  *#* Revision 1.3  2004/10/15 12:13:57  batt
55  *#* Correct \brief header.
56  *#*
57  *#* Revision 1.2  2004/10/15 11:54:21  batt
58  *#* Reformat.
59  *#*
60  *#* Revision 1.1  2004/10/13 16:35:36  batt
61  *#* New (simple) serial driver.
62  *#*
63  *#*
64  */
65 #ifndef SER_SIMPLE_H
66 #define SER_SIMPLE_H
67
68 /* For checking which serial driver is linked */
69 #define SER_SIMPLE
70
71 #include <config.h>
72 #include <compiler.h>
73
74
75 #if 0
76 #if CPU_AVR
77         typedef uint8_t serstatus_t;
78
79         /* Software errors */
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 */
83
84         /* Hardware errors */
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 */
88 #else
89         #error unknown architecture
90 #endif
91 /*\}*/
92
93 /**
94  * \name Serial hw numbers
95  *
96  * \{
97  */
98 enum
99 {
100 #if CPU_AVR_ATMEGA64 || CPU_AVR_ATMEGA128
101         SER_UART0,
102         SER_UART1,
103         SER_SPI,
104 #elif CPU_AVR_ATMEGA103 || CPU_AVR_ATMEGA8
105         SER_UART0,
106         SER_SPI,
107 #else
108         #error unknown architecture
109 #endif
110         SER_CNT  /**< Number of serial ports */
111 };
112 /*\}*/
113 #endif
114
115 /** \name Parity settings for ser_setparity() */
116 /*\{*/
117 #define SER_PARITY_NONE  0
118 #define SER_PARITY_EVEN  2
119 #define SER_PARITY_ODD   3
120 /*\}*/
121
122
123 /** Serial handle structure */
124 struct Serial;
125
126 /* Function prototypes */
127 extern int _ser_putchar(int c);
128 extern int _ser_getchar(void);
129 extern int _ser_getchar_nowait(void);
130 /*
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);
133
134 extern int ser_printf(struct Serial *port, const char *format, ...) FORMAT(__printf__, 2, 3);
135
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);
138 */
139 extern int _ser_print(const char *s);
140
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);
145 /*
146 extern void ser_resync(struct Serial *port, time_t delay);
147 extern void ser_drain(struct Serial *port);
148 */
149 extern void _ser_purge(void);
150 extern struct Serial *_ser_open(void);
151 extern void _ser_close(void);
152
153 /**
154  * \name Functions implemented as macros
155  *
156  * \{
157  */
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)
169 /* \} */
170
171 #endif /* SER_SIMPLE_H */