Open Garden  0.10.1-21
uart.h
Go to the documentation of this file.
1 /* This file is part of OpenGarden
2  * Copyright (C) 2011 Enrico Rossi
3  *
4  * OpenGarden is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * OpenGarden is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
22 #ifndef _UART_H_
23 #define _UART_H_
24 
26 #define UART_BAUD_0 9600
27 
28 #define UART_BAUD_1 9600
29 
30 #define UART_RXBUF_SIZE 64
31 
32 #define UART_TXBUF_SIZE 64
33 
34 #define UART_RXBUF_MASK ( UART_RXBUF_SIZE - 1 )
35 
36 #define UART_TXBUF_MASK ( UART_TXBUF_SIZE - 1 )
37 
38 #if ( UART_RXBUF_SIZE & UART_RXBUF_MASK )
39 #error RX buffer size is not a power of 2
40 #endif
41 
42 #if ( UART_TXBUF_SIZE & UART_TXBUF_MASK )
43 #error TX buffer size is not a power of 2
44 #endif
45 
47 struct uartStruct {
49  char *rx_buffer;
51  char *tx_buffer;
53  volatile uint8_t rx_flag;
55  volatile uint8_t tx_flag;
57  volatile uint8_t rxIdx;
59  volatile uint8_t txIdx;
60 };
61 
62 void uart_init(const uint8_t port);
63 void uart_shutdown(const uint8_t port);
64 char uart_getchar(const uint8_t port, const uint8_t locked);
65 void uart_putchar(const uint8_t port, const char c);
66 void uart_printstr(const uint8_t port, const char *s);
67 
68 #endif
Definition: uart.h:47
void uart_init(const uint8_t port)
Definition: uart.c:22
char uart_getchar(const uint8_t port, const uint8_t locked)
Definition: uart.c:70
void uart_putchar(const uint8_t port, const char c)
Definition: uart.c:98
volatile uint8_t rx_flag
Definition: uart.h:53
char * rx_buffer
Definition: uart.h:49
char * tx_buffer
Definition: uart.h:51
volatile uint8_t tx_flag
Definition: uart.h:55
void uart_shutdown(const uint8_t port)
Definition: uart.c:54
volatile uint8_t rxIdx
Definition: uart.h:57
void uart_printstr(const uint8_t port, const char *s)
Definition: uart.c:111
volatile uint8_t txIdx
Definition: uart.h:59