Rev 800 | Rev 932 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
772 | - | 1 | /**************************************************************************** |
902 | - | 2 | * Copyright (C) 2009-2011 by Claas Anders "CaScAdE" Rathje * |
772 | - | 3 | * admiralcascade@gmail.com * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
||
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 2 of the License. * |
||
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, write to the * |
||
17 | * Free Software Foundation, Inc., * |
||
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||
19 | ****************************************************************************/ |
||
20 | |||
800 | - | 21 | #include "main.h" |
772 | - | 22 | #include <avr/io.h> |
23 | #include <avr/interrupt.h> |
||
24 | #include <util/delay.h> |
||
25 | #include "usart0.h" |
||
26 | |||
800 | - | 27 | #ifdef ANTENNATRACKTEST |
28 | |||
29 | |||
772 | - | 30 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
31 | |||
32 | |||
33 | /* ########################################################################## |
||
34 | * USART0 stuff |
||
35 | * ##########################################################################*/ |
||
36 | |||
37 | /** |
||
38 | * init usart1 |
||
39 | */ |
||
40 | void usart0_init() { |
||
41 | UBRR0H = ((F_CPU / (16UL * baud)) - 1) >> 8; |
||
42 | UBRR0L = (F_CPU / (16UL * baud)) - 1; |
||
43 | |||
44 | // Enable receiver and transmitter; enable RX interrupt |
||
45 | UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0); |
||
46 | |||
47 | //asynchronous 8N1 |
||
48 | UCSR0C = (1 << URSEL0) | (3 << UCSZ00); |
||
49 | } |
||
50 | |||
51 | |||
52 | /** |
||
53 | * send a single <character> through usart1 |
||
54 | */ |
||
55 | void usart0_putc(unsigned char character) { |
||
56 | // wait until UDR ready |
||
57 | while (!(UCSR0A & (1 << UDRE0))); |
||
58 | UDR0 = character; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * send a <string> throught usart0 |
||
63 | */ |
||
64 | void usart0_puts(char *s) { |
||
65 | while (*s) { |
||
66 | usart0_putc(*s); |
||
67 | s++; |
||
68 | } |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * send a PGM<string> throught usart1 |
||
73 | */ |
||
74 | void usart0_puts_pgm(const char* string) { |
||
75 | while (pgm_read_byte(string) != 0x00) |
||
76 | usart0_putc(pgm_read_byte(string++)); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * transmit interrupt handler |
||
81 | * unused |
||
82 | */ |
||
83 | ISR(SIG_USART0_DATA) { |
||
84 | } |
||
85 | |||
86 | /* |
||
87 | * receive data through usart1 |
||
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 |
||
90 | */ |
||
91 | ISR(SIG_USART0_RECV) { |
||
92 | uint8_t c; |
||
93 | // catch the received byte |
||
800 | - | 94 | c = UDR0; |
95 | |||
772 | - | 96 | // echo |
800 | - | 97 | UDR0 = c; |
98 | } |
||
772 | - | 99 | |
100 | |||
101 | |||
800 | - | 102 | #endif |
103 | |||
772 | - | 104 | #endif // ANTENNATRACKTEST |