4 * Copyright 2003,2004 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 2000 Bernardo Innocenti <bernie@codewiz.org>
8 * \brief Simple serial I/O driver
11 * \author Bernardo Innocenti <bernie@develer.com>
12 * \author Francesco Sacchi <batt@develer.com>
17 *#* Revision 1.1 2005/04/12 01:37:50 bernie
18 *#* Import into DevLib.
20 *#* Revision 1.5 2004/10/20 13:37:49 batt
21 *#* Change testing of simple serial instead of ARCH_BOOT in sc driver.
23 *#* Revision 1.4 2004/10/15 12:22:04 batt
24 *#* Readd ';' in setstatus macro.
26 *#* Revision 1.3 2004/10/15 12:13:57 batt
27 *#* Correct \brief header.
29 *#* Revision 1.2 2004/10/15 11:54:21 batt
32 *#* Revision 1.1 2004/10/13 16:35:36 batt
33 *#* New (simple) serial driver.
40 /* For checking which serial driver is linked */
49 typedef uint8_t serstatus_t;
52 #define SERRF_RXFIFOOVERRUN BV(0) /*!< Rx FIFO buffer overrun */
53 #define SERRF_RXTIMEOUT BV(5) /*!< Receive timeout */
54 #define SERRF_TXTIMEOUT BV(6) /*!< Transmit timeout */
57 #define SERRF_RXSROVERRUN BV(3) /*!< Rx shift register overrun */
58 #define SERRF_FRAMEERROR BV(4) /*!< Stop bit missing */
59 #define SERRF_PARITYERROR BV(7) /*!< Parity error */
61 #error unknown architecture
66 * \name Serial hw numbers
72 #if CPU_AVR_ATMEGA64 || CPU_AVR_ATMEGA128
76 #elif CPU_AVR_ATMEGA103 || CPU_AVR_ATMEGA8
80 #error unknown architecture
82 SER_CNT /*!< Number of serial ports */
87 /*! \name Parity settings for ser_setparity() */
89 #define SER_PARITY_NONE 0
90 #define SER_PARITY_EVEN 2
91 #define SER_PARITY_ODD 3
95 /*! Serial handle structure */
98 /* Function prototypes */
99 extern int _ser_putchar(int c);
100 extern int _ser_getchar(void);
101 extern int _ser_getchar_nowait(void);
103 extern int ser_write(struct Serial *port, const void *buf, size_t len);
104 extern int ser_read(struct Serial *port, void *buf, size_t size);
106 extern int ser_printf(struct Serial *port, const char *format, ...) FORMAT(__printf__, 2, 3);
108 extern int ser_gets(struct Serial *port, char *buf, int size);
109 extern int ser_gets_echo(struct Serial *port, char *buf, int size, bool echo);
111 extern int _ser_print(const char *s);
113 extern void _ser_setbaudrate(unsigned long rate);
114 extern void _ser_setparity(int parity);
115 extern void _ser_settimeouts(void);
116 extern void _ser_setstatus(void);
118 extern void ser_resync(struct Serial *port, time_t delay);
119 extern void ser_drain(struct Serial *port);
121 extern void _ser_purge(void);
122 extern struct Serial *_ser_open(void);
123 extern void _ser_close(void);
126 * \name Functions implemented as macros
130 #define ser_putchar(c, port) _ser_putchar(c)
131 #define ser_getchar(port) _ser_getchar()
132 #define ser_getchar_nowait(port) _ser_getchar_nowait()
133 #define ser_print(port, s) _ser_print(s)
134 #define ser_setbaudrate(port, y) _ser_setbaudrate(y)
135 #define ser_setparity(port, par) _ser_setparity(par)
136 #define ser_settimeouts(port, y, z) _ser_settimeouts()
137 #define ser_purge(port) _ser_purge()
138 #define ser_open(port) _ser_open()
139 #define ser_getstatus(h) 0
140 #define ser_setstatus(h, x) do {(void)(x);} while(0)
143 #endif /* SER_SIMPLE_H */