Open Sint  3.4-2
uart.h
Go to the documentation of this file.
1 /* This file is part of OpenSint
2  * Copyright (C) 2005-2012 Enrico Rossi
3  *
4  * OpenSint 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  * OpenSint 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 UART0_BAUD 9600
27 
28 #define UART0_RXBUF_SIZE 64
29 
30 #define UART0_TXBUF_SIZE 64
31 
33 #define UART0_RXBUF_MASK ( UART0_RXBUF_SIZE - 1 )
34 
35 #define UART0_TXBUF_MASK ( UART0_TXBUF_SIZE - 1 )
36 
37 /* Check if something is wrong. */
38 #if ( UART0_RXBUF_SIZE & UART0_RXBUF_MASK )
39 #error RX0 buffer size is not a power of 2
40 #endif
41 
42 #if ( UART0_TXBUF_SIZE & UART0_TXBUF_MASK )
43 #error TX0 buffer size is not a power of 2
44 #endif
45 
46 #ifndef TRUE
47 #define TRUE 1
48 #define FALSE 0
49 #endif
50 
52 struct uartStruct {
53  char *rx_buffer;
54  char *tx_buffer;
55  volatile uint8_t rx_flag, tx_flag, rxIdx, txIdx;
56 };
57 
59 volatile struct uartStruct *uartPtr;
60 
61 struct uartStruct *uart_init(const uint8_t port);
62 void uart_shutdown(const uint8_t port);
63 void uart_get_msg(const uint8_t port, char *s);
64 void uart_putchar(const uint8_t port, const char c);
65 void uart_printstr(const uint8_t port, const char *s);
66 
67 #endif
Definition: uart.h:52
void uart_putchar(const uint8_t port, const char c)
Definition: uart.c:170
void uart_get_msg(const uint8_t port, char *s)
Definition: uart.c:156
void uart_shutdown(const uint8_t port)
shutdown the usart port.
Definition: uart.c:133
volatile struct uartStruct * uartPtr
Definition: uart.h:59
void uart_printstr(const uint8_t port, const char *s)
Definition: uart.c:186