sketchbook
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
uart.h
Go to the documentation of this file.
1 #ifndef UART_H
2 #define UART_H
3 #include "features.h"
4 
5 /*
6  * Copyright © 2010-2015, Matthias Urlichs <matthias@urlichs.de>
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License (included; see the file LICENSE)
17  * for more details.
18  */
19 
20 /* This code is based on work by: */
21 
22 /************************************************************************
23 Title: Interrupt UART library with receive/transmit circular buffers
24 Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury
25 File: not valid see "Extension"
26  ($Id: uart.h,v 1.7.2.1 2003/12/27 20:39:14 peter Exp $)
27 Software: AVR-GCC 3.3/3.4
28 Hardware: any AVR with built-in UART, tested on AT90S8515 at 4 Mhz and
29  ATmega16 at 1.8, 3.6, 4 and 8 MHz
30 Usage: see Doxygen manual
31 Extension: uart_puti, uart_puthex_nibble, uart_puthex_byte
32  by M.Thomas 9/2004
33 ************************************************************************/
34 
56 
57 #if (__GNUC__ * 100 + __GNUC_MINOR__) < 303
58 #error "This library requires AVR-GCC 3.3 or later, update to newer AVR-GCC compiler !"
59 #endif
60 
61 
62 /*
63 ** constants and macros
64 */
65 
70 //#define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu)/((baudRate)*16l)-1)
71 #define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu + baudRate * 8L) / (baudRate * 16L) - 1)
72 
73 
74 #ifndef P
75 #define P(s) ({static const char c[] __attribute__ ((progmem)) = s;c;})
76 #endif
77 
78 
79 /*
80 ** high byte error return code of uart_getc()
81 */
82 #define UART_FRAME_ERROR 0x0800 /* Framing Error by UART */
83 #define UART_OVERRUN_ERROR 0x0400 /* Overrun condition by UART */
84 #define UART_BUFFER_OVERFLOW 0x0200 /* receive ringbuffer overflow */
85 #define UART_NO_DATA 0x0100 /* no receive data available */
86 
87 #ifdef HAVE_UART
88 
89 /*
90 ** function prototypes
91 */
92 
98 extern void uart_init(unsigned int baudrate);
99 
100 
126 extern unsigned int uart_getc(void);
127 
128 
134 extern void uart_putc(unsigned char data);
135 
136 
147 extern void uart_puts(const char *s );
148 
149 
161 extern void uart_puts_p(const char *s );
162 
166 #define uart_puts_P(__s) uart_puts_p(P(__s))
167 
179 extern void uart_puti( int i );
180 extern void uart_putl( long i );
181 
193 extern void uart_puthex_nibble(const unsigned char b);
194 
208 extern void uart_puthex_byte(const unsigned char b);
209 extern void uart_puthex_byte_(const unsigned char b);
210 
222 extern void uart_puthex_word(const uint16_t b);
223 
233 #if !defined(HAVE_UART_IRQ) && !defined(HAVE_UART_SYNC)
234 extern void uart_poll(void);
235 #else
236 #define uart_poll() do {} while(0)
237 #endif
238 
240 #else // !HAVE_UART
241 
242 #define uart_init(baud) do {} while(0)
243 #define uart_getc() UART_NO_DATA
244 #define uart_putc(data) do {} while(0)
245 #define uart_puts(s) do {} while(0)
246 #define uart_puts_p(s) do {} while(0)
247 #define uart_puts_P(s) do {} while(0)
248 #define uart_puti(i) do {} while(0)
249 #define uart_putl(i) do {} while(0)
250 #define uart_puthex_nibble(b) do {} while(0)
251 #define uart_puthex_byte(b) do {} while(0)
252 #define uart_puthex_byte_(b) do {} while(0)
253 #define uart_puthex_word(b) do {} while(0)
254 #define uart_poll() do {} while(0)
255 
257 #endif // !HAVE_UART
258 #endif // UART_H
259 
#define uart_getc()
Definition: uart.h:243
#define uart_puthex_byte_(b)
Definition: uart.h:252
#define uart_puts_p(s)
Definition: uart.h:246
#define uart_puts(s)
Definition: uart.h:245
#define uart_puthex_byte(b)
Definition: uart.h:251
#define uart_puthex_nibble(b)
Definition: uart.h:250
#define uart_init(baud)
Definition: uart.h:242
#define uart_puthex_word(b)
Definition: uart.h:253
int32_t int16_t b
Definition: IMU.cpp:172
tuple s
Definition: ser-mon-AS7265X.py:36
tuple data
Definition: ser-mon-AS7265X.py:40
#define uart_poll()
Definition: uart.h:254
#define uart_puti(i)
Definition: uart.h:248
#define uart_putc(data)
Definition: uart.h:244
#define uart_putl(i)
Definition: uart.h:249
int i
Definition: ser-log.py:25