]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/uart_i.h
backporting uart_i and cli
[avr-crypto-lib.git] / test_src / uart_i.h
1 /* uart_i.h */
2 /*
3     This file is part of the AVR-uart_ni.
4     Copyright (C) 2009  Daniel Otte (daniel.otte@rub.de)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 /**
20  * \file     uart_i.h
21  * \email    daniel.otte@rub.de
22  * \author   Daniel Otte 
23  * \date     2009-07-24
24  * \license  GPLv3 or later
25  * \ingroup  uart_i
26  * \brief    declaration for non-interrupt uart
27  */
28
29 #ifndef UART_I_H_
30 #define UART_I_H_
31
32 #include "config.h"
33 #include "circularbytebuffer.h"
34 #include <stdint.h>
35
36 typedef struct{
37         circularbytebuffer_t rxb;
38         circularbytebuffer_t txb;       
39 #if UART0_HOOK
40         void(*hook)(uint8_t);
41         volatile uint8_t hook_running;
42 #endif
43 #if UART0_SWFLOWCTRL
44         volatile uint8_t txon;
45         volatile uint8_t rxon;
46 #endif
47 } uart0_ctx_t;
48
49
50 typedef struct{
51         circularbytebuffer_t rxb;
52         circularbytebuffer_t txb;       
53 #if UART1_HOOK
54         void(*hook)(uint8_t);
55         volatile uint8_t hook_running;
56 #endif
57 #if UART1_SWFLOWCTRL
58         volatile uint8_t txon;
59         volatile uint8_t rxon;
60 #endif
61 } uart1_ctx_t;
62
63 #if UART0_I
64
65 /** \fn uart0_init(void)
66  * \brief initialize uart0.
67  * This function initializes the first uart according to the parameter specifyed
68  * in config.h .
69  */
70 void uart0_init(void);
71
72 /** \fn uart0_putc(uint16_t)
73  * \brief send data through uart0.
74  * This function sends data through the first uart 
75  * (the data size is debfined in config.h).
76  * \param c data to send
77  */
78 void uart0_putc(uint16_t c);
79
80 /** \fn uart0_getc(void)
81  * \brief read data from uart0.
82  * This function reads data from the first uart 
83  * (the data size is debfined in config.h).
84  * \return data recived by uart0
85  */
86 uint16_t uart0_getc(void);
87
88 /** \fn uart0_dataavail(void)
89  * \brief checks if data is available.
90  * 
91  * This function checks the state of the input buffer of uart0 and
92  * returns if data is available or not.
93  * \return zero if no data is available else a value different from zero is returned
94  */
95 uint8_t uart0_dataavail(void);
96
97 #if     UART0_HOOK
98 void uart0_sethook(void(*fpt)(uint8_t));
99 #endif
100
101
102 #endif /* UART0_I */
103
104 #if UART1_I
105 /** \fn uart1_init(void)
106  * \brief initialize uart1.
107  * This function initializes the second uart according to the parameter specifyed
108  * in config.h .
109  */
110 void uart1_init(void);
111
112 /** \fn uart1_putc(uint16_t)
113  * \brief send data through uart1.
114  * This function sends data through the second uart 
115  * (the data size is debfined in config.h).
116  * \param c data to send
117  */
118 void uart1_putc(uint16_t c);
119
120 /** \fn uart1_getc(void)
121  * \brief read data from uart1.
122  * This function reads data from the second uart 
123  * (the data size is debfined in config.h).
124  * \return data recived by uart1
125  */
126 uint16_t uart1_getc(void);
127
128 /** \fn uart1_dataavail(void)
129  * \brief checks if data is available.
130  * This function checks the state of the input buffer of uart1 and
131  * returns if data is available or not.
132  * \return zero if no data is available else a value different from zero is returned
133  */
134 uint8_t uart1_dataavail(void);
135
136 void uart0_sethook(void(*fpt)(uint8_t));
137 #endif
138
139 #endif /* UART_I_H_ */