Subversion Repositories Projects

Rev

Rev 2225 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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