]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/setbaud_asm.inc
optimizing norx32
[avr-crypto-lib.git] / test_src / setbaud_asm.inc
1 /*
2     This file is part of the AVR-uart_ni.
3     Copyright (C) 2009 Daniel Otte (daniel.otte@rub.de)
4
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /* #include <util/setbaud.h> */
20 /* we use a modifyed version of util/setbaud where the UL suffix is removed
21  * since the preprocessor can not handle that.
22  */
23
24 #ifndef F_CPU
25 #  error "uart_i requires F_CPU to be defined"
26 #endif
27
28 #ifndef BAUD
29 #  error "uart_i requires UART0_BAUD_RATE to be defined"
30 #endif
31
32 #if !(F_CPU)
33 #  error "F_CPU must be a constant value"
34 #endif
35
36 #if !(BAUD)
37 #  error "UART0_BAUD_RATE must be a constant value"
38 #endif
39
40 #undef USE_2X
41
42 /* Baud rate tolerance is 2 % unless previously defined */
43 #ifndef BAUD_TOL
44 #  define BAUD_TOL 2
45 #endif
46
47 #define UBRR_VALUE (((F_CPU) + 8 * (BAUD)) / (16 * (BAUD)) -1)
48
49 #if 100 * (F_CPU) > \
50   (16 * ((UBRR_VALUE) + 1)) * (100 * (BAUD) + (BAUD) * (BAUD_TOL))
51 #  define USE_2X 1
52 #elif 100 * (F_CPU) < \
53   (16 * ((UBRR_VALUE) + 1)) * (100 * (BAUD) - (BAUD) * (BAUD_TOL))
54 #  define USE_2X 1
55 #else
56 #  define USE_2X 0
57 #endif
58
59 #if USE_2X
60 /* U2X required, recalculate */
61 #undef UBRR_VALUE
62 #define UBRR_VALUE (((F_CPU) + 4 * (BAUD)) / (8 * (BAUD)) -1)
63
64 #if 100 * (F_CPU) > \
65   (8 * ((UBRR_VALUE) + 1)) * (100 * (BAUD) + (BAUD) * (BAUD_TOL))
66 #  warning "Baud rate achieved is higher than allowed"
67 #endif
68
69 #if 100 * (F_CPU) < \
70   (8 * ((UBRR_VALUE) + 1)) * (100 * (BAUD) - (BAUD) * (BAUD_TOL))
71 #  warning "Baud rate achieved is lower than allowed"
72 #endif
73
74 #endif /* USE_U2X */
75
76 #ifdef UBRR_VALUE
77 #  define UBRRL_VALUE ((UBRR_VALUE) & 0xff)
78 #  define UBRRH_VALUE ((UBRR_VALUE) >> 8)
79 #endif
80