]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/uart_ni-asm.S
forgotten uart files
[avr-crypto-lib.git] / test_src / uart_ni-asm.S
1 /* uart_ni.c */
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 #include "config.h"
20 #include <avr/io.h>
21 #include "avr-asm-macros.S"
22 #include "uart_defs.h"
23 /******************************************************************************/
24
25 #if UART0_NI
26
27 #ifndef UART0_PARATY
28 # warning "UART0: using default paraty: 'none'"
29 # define UART0_PARATY UART_PARATY_NONE
30 #endif
31
32 #ifndef UART0_STOPBITS
33 # warning "UART0: using default ammount of stop bits: '1'"
34 # define UART0_STOPBITS UART_STOPBITS_1
35 #endif
36
37 #ifndef UART0_DATABITS
38 # warning "UART0: using default ammount of data bits: '8'"
39 # define UART0_DATABITS UART_DATABITS_8
40 #endif
41
42
43 #ifdef UDR
44 # define OLD_UART
45 # ifdef UDR0
46 #  error "can not decide which registernames to use, UDR and UDR0 are defined"
47 # endif
48 #endif
49
50 #ifdef OLD_UART
51 # define UCSR0A UCSRA
52 # define UCSR0B UCSRB
53 # define UCSR0C UCSRC
54 # define UBRR0H UBRRH
55 # define UBRR0L UBRRL
56 # define UDR0   UDR
57 # define TXEN0  TXEN
58 # define RXEN0  RXEN
59 # define UDRE0  UDRE
60 # define RXC0   RXC
61 # define TXB80  TXB8
62 # define RXB80  RXB8
63 #endif
64
65 #define BAUD (UART0_BAUD_RATE)
66 #include "setbaud_asm.inc"
67
68 /******************************************************************************/
69
70 .global uart0_init
71 uart0_init:
72         ldi r24, UBRRH_VALUE
73         STORE_IO UBRR0H, r24
74         ldi r24, UBRRL_VALUE
75         STORE_IO UBRR0L, r24
76 #if _SFR_IO_REG_P(UCSR0A)
77   #if USE_2X
78         sbi _SFR_IO_ADDR(UCSR0A), 1
79   #else
80         cbi _SFR_IO_ADDR(UCSR0A), 1
81   #endif
82 #else 
83         lds r24, _SFR_MEM_ADDR(UCSR0A)
84   #if USE_2X
85         ori r24, 0x02
86   #else
87         andi r24, ~0x02
88   #endif
89         sts _SFR_MEM_ADDR(UCSR0A), r24
90 #endif
91         ldi r24, (UART0_PARATY<<4)|(UART0_STOPBITS<<3)|((UART0_DATABITS&3)<<1)
92         STORE_IO UCSR0C, r24
93         ldi r24, _BV(TXEN0)|_BV(RXEN0)|((UART0_DATABITS>>2)<<2)  
94         STORE_IO UCSR0B, r24
95         ret
96
97 /******************************************************************************/
98         
99 .global uart0_putc
100 uart0_putc:
101 #if _SFR_IO_REG_P(UCSR0A)
102         sbis _SFR_IO_ADDR(UCSR0A), UDRE0
103         rjmp uart0_putc
104 #else
105         lds r25, _SFR_MEM_ADDR(UCSR0A)
106         sbrs r25, UDRE0
107         rjmp uart0_putc
108 #endif
109 #if UART0_DATABITS == UART_DATABITS_9
110 #  if _SFR_IO_REG_P(UCSR0B)
111     sbi UCSR0B, TXB80
112         sbrs r25, 0
113         cbi UCSR0B, TXB80
114 #  else
115         lds r23, _SFR_MEM_ADDR(UCSR0B)
116         bst r25, 0
117         bld r23, TXB80
118         sts _SFR_MEM_ADDR(UCSR0B), r23
119 #  endif
120 #endif
121         STORE_IO UDR0, r24
122         ret
123         
124 /******************************************************************************/
125         
126 .global uart0_getc
127 uart0_getc:
128 #if _SFR_IO_REG_P(UCSR0A)
129         sbis _SFR_IO_ADDR(UCSR0A), RXC0
130         rjmp uart0_putc
131 #else
132         lds r25, _SFR_MEM_ADDR(UCSR0A)
133         sbrs r25, RXC0
134         rjmp uart0_getc
135 #endif
136
137 #if UART0_DATABITS == UART_DATABITS_9
138         LOAD_IO r25, UCSR0B
139         lsr r25
140         andi r25, 1
141 #else
142         clr r25
143 #endif  
144         LOAD_IO r24, UDR0
145         ret
146         
147 /******************************************************************************/
148         
149 .global uart0_dataavail
150 uart0_dataavail:
151         LOAD_IO r24, UCSR0A
152         andi r24, _BV(RXC0)
153         clr r25
154         ret
155
156 #endif /* UART0_NI */
157
158 /******************************************************************************/
159 /******************************************************************************/
160 /******************************************************************************/
161
162 #if UART1_NI
163
164 #ifndef UDRE1
165 # error "registernames for second UART not defined"
166 #endif
167
168 #ifndef UART1_PARATY
169 # warning "UART1: using default paraty: 'none'"
170 # define UART1_PARATY UART_PARATY_NONE
171 #endif
172
173 #ifndef UART1_STOPBITS
174 # warning "UART1: using default ammount of stop bits: '1'"
175 # define UART1_STOPBITS UART_STOPBITS_1
176 #endif
177
178 #ifndef UART1_DATABITS
179 # warning "UART1: using default ammount of data bits: '8'"
180 # define UART1_DATABITS UART_DATABITS_8
181 #endif
182
183 #ifdef BAUD
184 #  undef BAUD
185 #endif
186
187 #define BAUD (UART1_BAUD_RATE)
188
189 #include "setbaud_asm.inc"
190
191 /******************************************************************************/
192
193 .global uart1_init
194 uart1_init:
195         ldi r24, UBRRH_VALUE
196         STORE_IO UBRR1H, r24
197         ldi r24, UBRRL_VALUE
198         STORE_IO UBRR1L, r24
199 #if _SFR_IO_REG_P(UCSR1A)
200   #if USE_2X
201         sbi _SFR_IO_ADDR(UCSR1A), 1
202   #else
203         cbi _SFR_IO_ADDR(UCSR1A), 1
204   #endif
205 #else 
206         lds r24, _SFR_MEM_ADDR(UCSR1A)
207   #if USE_2X
208         ori r24, 0x02
209   #else
210         andi r24, ~0x02
211   #endif
212         sts _SFR_MEM_ADDR(UCSR1A), r24
213 #endif
214         ldi r24, (UART1_PARATY<<4)|(UART1_STOPBITS<<3)|((UART1_DATABITS&3)<<1)
215         STORE_IO UCSR1C, r24
216         ldi r24, _BV(TXEN1)|_BV(RXEN1)|((UART1_DATABITS>>2)<<2)  
217         STORE_IO UCSR1B, r24
218         ret
219         
220 /******************************************************************************/
221
222 .global uart1_putc
223 uart1_putc:
224 #if _SFR_IO_REG_P(UCSR1A)
225         sbis _SFR_IO_ADDR(UCSR1A), UDRE1
226         rjmp uart1_putc
227 #else
228         lds r23, _SFR_MEM_ADDR(UCSR1A)
229         sbrs r23, UDRE1
230         rjmp uart1_putc
231 #endif
232 #if UART1_DATABITS == UART_DATABITS_9
233 #  if _SFR_IO_REG_P(UCSR1B)
234     sbi UCSR1B, TXB81
235         sbrs r25, 0
236         cbi UCSR1B, TXB81
237 #  else
238         lds r23, _SFR_MEM_ADDR(UCSR1B)
239         bst r25, 0
240         bld r23, TXB81
241         sts _SFR_MEM_ADDR(UCSR1B), r23
242 #  endif
243 #endif
244         STOREIO UDR1, r24
245         ret
246         
247 /******************************************************************************/
248         
249 .global uart1_getc
250 uart1_getc:
251 #if _SFR_IO_REG_P(UCSR1A)
252         sbis _SFR_IO_ADDR(UCSR1A), RXC1
253         rjmp uart1_putc
254 #else
255         lds r25, _SFR_MEM_ADDR(UCSR1A)
256         sbrs r25, RXC1
257         rjmp uart1_getc
258 #endif
259 #if UART1_DATABITS == UART_DATABITS_9
260         LOAD_IO r25, UCSR1B
261         lsr r25
262         andi r25, 1
263 #else
264         clr r25
265 #endif  
266         LOAD_IO r24, UDR1
267         ret
268         
269 /******************************************************************************/
270
271 .global uart1_dataavail
272 uart1_dataavail:
273         LOAD_IO r24, UCSR1A
274         andi r24, _BV(RXC1)
275         clr r25
276         ret
277
278 #endif /* UART1_NI */