Rev 902 | Rev 1437 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 902 | Rev 932 | ||
---|---|---|---|
1 | /**************************************************************************** |
1 | /**************************************************************************** |
2 | * Copyright (C) 2009-2011 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 | ||
- | 27 | #ifdef SERIALDEBUGDRAW |
|
- | 28 | #define USART0ENABLE 1 |
|
26 | 29 | #endif |
|
- | 30 | #ifdef ANTENNATRACKTEST |
|
- | 31 | #define USART0ENABLE 1 |
|
- | 32 | #endif |
|
- | 33 | ||
- | 34 | ||
- | 35 | ||
27 | #ifdef ANTENNATRACKTEST |
36 | #ifdef USART0ENABLE |
28 | 37 | ||
29 | 38 | ||
30 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
39 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
31 | 40 | ||
32 | 41 | ||
33 | /* ########################################################################## |
42 | /* ########################################################################## |
34 | * USART0 stuff |
43 | * USART0 stuff |
35 | * ##########################################################################*/ |
44 | * ##########################################################################*/ |
36 | 45 | ||
37 | /** |
46 | /** |
38 | * init usart1 |
47 | * init usart1 |
39 | */ |
48 | */ |
40 | void usart0_init() { |
49 | void usart0_init() { |
41 | UBRR0H = ((F_CPU / (16UL * baud)) - 1) >> 8; |
50 | UBRR0H = ((F_CPU / (16UL * baud)) - 1) >> 8; |
42 | UBRR0L = (F_CPU / (16UL * baud)) - 1; |
51 | UBRR0L = (F_CPU / (16UL * baud)) - 1; |
43 | 52 | ||
44 | // Enable receiver and transmitter; enable RX interrupt |
53 | // Enable receiver and transmitter; enable RX interrupt |
45 | UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0); |
54 | UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0); |
46 | 55 | ||
47 | //asynchronous 8N1 |
56 | //asynchronous 8N1 |
48 | UCSR0C = (1 << URSEL0) | (3 << UCSZ00); |
57 | UCSR0C = (1 << URSEL0) | (3 << UCSZ00); |
- | 58 | ||
- | 59 | ||
- | 60 | DDRD |= (1 << DDD1); // set TXD pin as output |
|
- | 61 | PORTD &= ~(1 << PORTD1); // disable pullup on TXD pin |
|
49 | } |
62 | } |
50 | 63 | ||
51 | 64 | ||
52 | /** |
65 | /** |
53 | * send a single <character> through usart1 |
66 | * send a single <character> through usart1 |
54 | */ |
67 | */ |
55 | void usart0_putc(unsigned char character) { |
68 | void usart0_putc(unsigned char character) { |
56 | // wait until UDR ready |
69 | // wait until UDR ready |
57 | while (!(UCSR0A & (1 << UDRE0))); |
70 | while (!(UCSR0A & (1 << UDRE0))); |
58 | UDR0 = character; |
71 | UDR0 = character; |
59 | } |
72 | } |
60 | 73 | ||
61 | /** |
74 | /** |
62 | * send a <string> throught usart0 |
75 | * send a <string> throught usart0 |
63 | */ |
76 | */ |
64 | void usart0_puts(char *s) { |
77 | void usart0_puts(char *s) { |
65 | while (*s) { |
78 | while (*s) { |
66 | usart0_putc(*s); |
79 | usart0_putc(*s); |
67 | s++; |
80 | s++; |
68 | } |
81 | } |
69 | } |
82 | } |
70 | 83 | ||
71 | /** |
84 | /** |
72 | * send a PGM<string> throught usart1 |
85 | * send a PGM<string> throught usart1 |
73 | */ |
86 | */ |
74 | void usart0_puts_pgm(const char* string) { |
87 | void usart0_puts_pgm(const char* string) { |
75 | while (pgm_read_byte(string) != 0x00) |
88 | while (pgm_read_byte(string) != 0x00) |
76 | usart0_putc(pgm_read_byte(string++)); |
89 | usart0_putc(pgm_read_byte(string++)); |
77 | } |
90 | } |
78 | 91 | ||
79 | /** |
92 | /** |
80 | * transmit interrupt handler |
93 | * transmit interrupt handler |
81 | * unused |
94 | * unused |
82 | */ |
95 | */ |
83 | ISR(SIG_USART0_DATA) { |
96 | ISR(SIG_USART0_DATA) { |
84 | } |
97 | } |
85 | 98 | ||
86 | /* |
99 | /* |
87 | * receive data through usart1 |
100 | * receive data through usart1 |
88 | * portions taken and adapted from |
101 | * portions taken and adapted from |
89 | * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Fbranches%2FV0.72p+Code+Redesign+killagreg%2Fuart0.c |
102 | * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Fbranches%2FV0.72p+Code+Redesign+killagreg%2Fuart0.c |
90 | */ |
103 | */ |
91 | ISR(SIG_USART0_RECV) { |
104 | ISR(SIG_USART0_RECV) { |
92 | uint8_t c; |
105 | uint8_t c; |
93 | // catch the received byte |
106 | // catch the received byte |
94 | c = UDR0; |
107 | c = UDR0; |
95 | 108 | ||
96 | // echo |
109 | // echo |
97 | UDR0 = c; |
110 | UDR0 = c; |
98 | } |
111 | } |
99 | 112 | ||
100 | 113 | ||
101 | 114 | ||
102 | #endif |
115 | #endif |
103 | 116 | ||
104 | #endif // ANTENNATRACKTEST |
117 | #endif // USART0ENABLE |
105 | 118 |