update ldscript
[protos/xbee-avr.git] / uart_private.h
1 /*  \r
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)\r
3  * \r
4  *  This program is free software; you can redistribute it and/or modify\r
5  *  it under the terms of the GNU General Public License as published by\r
6  *  the Free Software Foundation; either version 2 of the License, or\r
7  *  (at your option) any later version.\r
8  *\r
9  *  This program is distributed in the hope that it will be useful,\r
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12  *  GNU General Public License for more details.\r
13  *\r
14  *  You should have received a copy of the GNU General Public License\r
15  *  along with this program; if not, write to the Free Software\r
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
17  *\r
18  *  Revision : $Id: uart_private.h,v 1.1.2.5 2009-01-03 16:24:50 zer0 Exp $\r
19  *\r
20  */\r
21 \r
22 /* Olivier MATZ, Droids-corp 2004 - 2009 */\r
23 \r
24 #ifndef _UART_PRIVATE_H_\r
25 #define _UART_PRIVATE_H_\r
26 \r
27 #include <aversive.h>\r
28 #include <aversive/list.h>\r
29 \r
30 #include <uart.h>\r
31 #include <uart_defs.h>\r
32 #include <uart_config.h>\r
33 \r
34 typedef volatile uint8_t *uart_reg_t;\r
35 \r
36 struct regs {\r
37         uart_reg_t udr;\r
38         uart_reg_t ucsra;\r
39         uart_reg_t ucsrb;\r
40         uart_reg_t ucsrc;\r
41         uart_reg_t ubrrl;\r
42         uart_reg_t ubrrh;\r
43 };\r
44 \r
45 const struct regs uart_regs[UART_HW_NUM];\r
46 \r
47 typedef void (event)(char);\r
48 typedef void (event_9bits)(int);\r
49 \r
50 extern event *rx_event[UART_HW_NUM];\r
51 extern event *tx_event[UART_HW_NUM];\r
52 \r
53 void uart_send_next_char(uint8_t num);\r
54 int8_t uart_setconf(uint8_t num, struct uart_config *u);\r
55 \r
56 static inline char uart_get_udr(uint8_t num)\r
57 {\r
58         return *uart_regs[num].udr;\r
59 }\r
60 \r
61 static inline void uart_set_udr(uint8_t num, char c)\r
62 {\r
63         *uart_regs[num].udr = c;\r
64         /* tx event function. We suppose interrupts are already\r
65          * locked, so no pb with tx_event pointer */\r
66         if (tx_event[num])\r
67                 tx_event[num](c);\r
68 }\r
69 \r
70 #ifdef CONFIG_MODULE_UART_9BITS\r
71 static inline int uart_get_udr_9bits(uint8_t num)\r
72 {\r
73         int val = *uart_regs[num].udr;\r
74         val |= (*uart_regs[num].ucsrb & ((1 << RXB8) ? 0x100 : 0));\r
75         return val;\r
76 }\r
77 \r
78 static inline void uart_set_udr_9bits(uint8_t num, int c)\r
79 {\r
80         if (c & 0x100 )\r
81                 *uart_regs[num].ucsrb |= (1 << RXB8);\r
82         else\r
83                 *uart_regs[num].ucsrb &= ~(1 << RXB8);\r
84         *uart_regs[num].udr = c;\r
85 \r
86         /* tx event function. We suppose interrupts are already\r
87          * locked, so no pb with tx_event pointer */\r
88         if (tx_event[num])\r
89                 ((event_9bits *)tx_event[num])(c);\r
90 }\r
91 #endif /* CONFIG_MODULE_UART_9BITS */\r
92 \r
93 #endif /* _UART_PRIVATE_H_ */\r