Rev 800 | Rev 932 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 800 | Rev 902 | ||
---|---|---|---|
1 | /**************************************************************************** |
1 | /**************************************************************************** |
2 | * Copyright (C) 2009-2010 by Claas Anders "CaScAdE" Rathje * |
2 | * Copyright (C) 2009-2011 by Claas Anders "CaScAdE" Rathje * |
3 | * admiralcascade@gmail.com * |
3 | * admiralcascade@gmail.com * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
5 | * * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
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 * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License. * |
8 | * the Free Software Foundation; either version 2 of the License. * |
9 | * * |
9 | * * |
10 | * This program is distributed in the hope that it will be useful, * |
10 | * This program is distributed in the hope that it will be useful, * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 | * GNU General Public License for more details. * |
13 | * GNU General Public License for more details. * |
14 | * * |
14 | * * |
15 | * You should have received a copy of the GNU General Public License * |
15 | * You should have received a copy of the GNU General Public License * |
16 | * along with this program; if not, write to the * |
16 | * along with this program; if not, write to the * |
17 | * Free Software Foundation, Inc., * |
17 | * Free Software Foundation, Inc., * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | ****************************************************************************/ |
19 | ****************************************************************************/ |
20 | 20 | ||
21 | #include "main.h" |
21 | #include "main.h" |
22 | #include <avr/io.h> |
22 | #include <avr/io.h> |
23 | #include <avr/interrupt.h> |
23 | #include <avr/interrupt.h> |
24 | #include <util/delay.h> |
24 | #include <util/delay.h> |
25 | #include "usart0.h" |
25 | #include "usart0.h" |
26 | 26 | ||
27 | #ifdef ANTENNATRACKTEST |
27 | #ifdef ANTENNATRACKTEST |
28 | 28 | ||
29 | 29 | ||
30 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
30 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
31 | 31 | ||
32 | 32 | ||
33 | /* ########################################################################## |
33 | /* ########################################################################## |
34 | * USART0 stuff |
34 | * USART0 stuff |
35 | * ##########################################################################*/ |
35 | * ##########################################################################*/ |
36 | 36 | ||
37 | /** |
37 | /** |
38 | * init usart1 |
38 | * init usart1 |
39 | */ |
39 | */ |
40 | void usart0_init() { |
40 | void usart0_init() { |
41 | UBRR0H = ((F_CPU / (16UL * baud)) - 1) >> 8; |
41 | UBRR0H = ((F_CPU / (16UL * baud)) - 1) >> 8; |
42 | UBRR0L = (F_CPU / (16UL * baud)) - 1; |
42 | UBRR0L = (F_CPU / (16UL * baud)) - 1; |
43 | 43 | ||
44 | // Enable receiver and transmitter; enable RX interrupt |
44 | // Enable receiver and transmitter; enable RX interrupt |
45 | UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0); |
45 | UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0); |
46 | 46 | ||
47 | //asynchronous 8N1 |
47 | //asynchronous 8N1 |
48 | UCSR0C = (1 << URSEL0) | (3 << UCSZ00); |
48 | UCSR0C = (1 << URSEL0) | (3 << UCSZ00); |
49 | } |
49 | } |
50 | 50 | ||
51 | 51 | ||
52 | /** |
52 | /** |
53 | * send a single <character> through usart1 |
53 | * send a single <character> through usart1 |
54 | */ |
54 | */ |
55 | void usart0_putc(unsigned char character) { |
55 | void usart0_putc(unsigned char character) { |
56 | // wait until UDR ready |
56 | // wait until UDR ready |
57 | while (!(UCSR0A & (1 << UDRE0))); |
57 | while (!(UCSR0A & (1 << UDRE0))); |
58 | UDR0 = character; |
58 | UDR0 = character; |
59 | } |
59 | } |
60 | 60 | ||
61 | /** |
61 | /** |
62 | * send a <string> throught usart0 |
62 | * send a <string> throught usart0 |
63 | */ |
63 | */ |
64 | void usart0_puts(char *s) { |
64 | void usart0_puts(char *s) { |
65 | while (*s) { |
65 | while (*s) { |
66 | usart0_putc(*s); |
66 | usart0_putc(*s); |
67 | s++; |
67 | s++; |
68 | } |
68 | } |
69 | } |
69 | } |
70 | 70 | ||
71 | /** |
71 | /** |
72 | * send a PGM<string> throught usart1 |
72 | * send a PGM<string> throught usart1 |
73 | */ |
73 | */ |
74 | void usart0_puts_pgm(const char* string) { |
74 | void usart0_puts_pgm(const char* string) { |
75 | while (pgm_read_byte(string) != 0x00) |
75 | while (pgm_read_byte(string) != 0x00) |
76 | usart0_putc(pgm_read_byte(string++)); |
76 | usart0_putc(pgm_read_byte(string++)); |
77 | } |
77 | } |
78 | 78 | ||
79 | /** |
79 | /** |
80 | * transmit interrupt handler |
80 | * transmit interrupt handler |
81 | * unused |
81 | * unused |
82 | */ |
82 | */ |
83 | ISR(SIG_USART0_DATA) { |
83 | ISR(SIG_USART0_DATA) { |
84 | } |
84 | } |
85 | 85 | ||
86 | /* |
86 | /* |
87 | * receive data through usart1 |
87 | * receive data through usart1 |
88 | * portions taken and adapted from |
88 | * portions taken and adapted from |
89 | * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Fbranches%2FV0.72p+Code+Redesign+killagreg%2Fuart0.c |
89 | * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Fbranches%2FV0.72p+Code+Redesign+killagreg%2Fuart0.c |
90 | */ |
90 | */ |
91 | ISR(SIG_USART0_RECV) { |
91 | ISR(SIG_USART0_RECV) { |
92 | uint8_t c; |
92 | uint8_t c; |
93 | // catch the received byte |
93 | // catch the received byte |
94 | c = UDR0; |
94 | c = UDR0; |
95 | 95 | ||
96 | // echo |
96 | // echo |
97 | UDR0 = c; |
97 | UDR0 = c; |
98 | } |
98 | } |
99 | 99 | ||
100 | 100 | ||
101 | 101 | ||
102 | #endif |
102 | #endif |
103 | 103 | ||
104 | #endif // ANTENNATRACKTEST |
104 | #endif // ANTENNATRACKTEST |
105 | 105 |