OneWay  3.0-3-ge9d4fa4
uart.h
1 /* This file is part of OneWay
2  * Copyright (C) 2011 Enrico Rossi
3  *
4  * OneWay 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  * OneWay 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 
18 #ifndef _UART_H_
19 #define _UART_H_
20 
21 /* UART baud rate */
22 #define UART_BAUD_0 9600
23 #define UART_BAUD_1 1200
24 #define UART_RXBUF_SIZE 64
25 #define UART_TXBUF_SIZE 64
26 #define UART_RXBUF_MASK ( UART_RXBUF_SIZE - 1 )
27 #define UART_TXBUF_MASK ( UART_TXBUF_SIZE - 1 )
28 #if ( UART_RXBUF_SIZE & UART_RXBUF_MASK )
29 #error RX buffer size is not a power of 2
30 #endif
31 #if ( UART_TXBUF_SIZE & UART_TXBUF_MASK )
32 #error TX buffer size is not a power of 2
33 #endif
34 
36 struct uartStruct {
38  char *rx_buffer;
40  char *tx_buffer;
42  volatile uint8_t rx_flag;
44  volatile uint8_t tx_flag;
46  volatile uint8_t rxIdx;
48  volatile uint8_t txIdx;
49 };
50 
51 void uart_tx(const uint8_t port, const uint8_t enable);
52 void uart_rx(const uint8_t port, const uint8_t enable);
53 void uart_init(const uint8_t port);
54 void uart_shutdown(const uint8_t port);
55 char uart_getchar(const uint8_t port, const uint8_t locked);
56 void uart_putchar(const uint8_t port, const char c);
57 void uart_printstr(const uint8_t port, const char *s);
58 void uart_flush(const uint8_t port);
59 
60 #endif
void uart_rx(const uint8_t port, const uint8_t enable)
enable/disable the receive part of a serial port.
Definition: uart.c:46
Definition: uart.h:36
void uart_printstr(const uint8_t port, const char *s)
Definition: uart.c:170
void uart_shutdown(const uint8_t port)
Definition: uart.c:94
volatile uint8_t rx_flag
Definition: uart.h:42
char * rx_buffer
Definition: uart.h:38
char * tx_buffer
Definition: uart.h:40
void uart_putchar(const uint8_t port, const char c)
send a single char down to the serial port.
Definition: uart.c:148
volatile uint8_t tx_flag
Definition: uart.h:44
void uart_init(const uint8_t port)
initialize the serial port and speed.
Definition: uart.c:64
volatile uint8_t rxIdx
Definition: uart.h:46
void uart_flush(const uint8_t port)
flush the port
Definition: uart.c:177
void uart_tx(const uint8_t port, const uint8_t enable)
enable/disable the trasmit part of a serial port.
Definition: uart.c:28
char uart_getchar(const uint8_t port, const uint8_t locked)
get a char from the serial port.
Definition: uart.c:116
volatile uint8_t txIdx
Definition: uart.h:48