Subversion Repositories Projects

Rev

Rev 772 | Rev 902 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/****************************************************************************
 *   Copyright (C) 2009-2010 by Claas Anders "CaScAdE" Rathje               *
 *   admiralcascade@gmail.com                                               *
 *   Project-URL: http://www.mylifesucks.de/oss/c-osd/                      *
 *                                                                          *
 *   This program is free software; you can redistribute it and/or modify   *
 *   it under the terms of the GNU General Public License as published by   *
 *   the Free Software Foundation; either version 2 of the License.         *
 *                                                                          *
 *   This program is distributed in the hope that it will be useful,        *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *   GNU General Public License for more details.                           *
 *                                                                          *
 *   You should have received a copy of the GNU General Public License      *
 *   along with this program; if not, write to the                          *
 *   Free Software Foundation, Inc.,                                        *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
 ****************************************************************************/


#include "main.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "usart0.h"

#ifdef ANTENNATRACKTEST


#if !(ALLCHARSDEBUG|(WRITECHARS != -1))


/* ##########################################################################
 * USART0 stuff
 * ##########################################################################*/


/**
 * init usart1
 */

void usart0_init() {
    UBRR0H = ((F_CPU / (16UL * baud)) - 1) >> 8;
    UBRR0L = (F_CPU / (16UL * baud)) - 1;

    // Enable receiver and transmitter; enable RX interrupt
    UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);

    //asynchronous 8N1
    UCSR0C = (1 << URSEL0) | (3 << UCSZ00);
}


/**
 * send a single <character> through usart1
 */

void usart0_putc(unsigned char character) {
    // wait until UDR ready
    while (!(UCSR0A & (1 << UDRE0)));
    UDR0 = character;
}

/**
 * send a <string> throught usart0
 */

void usart0_puts(char *s) {
    while (*s) {
        usart0_putc(*s);
        s++;
    }
}

/**
 * send a PGM<string> throught usart1
 */

void usart0_puts_pgm(const char* string) {
    while (pgm_read_byte(string) != 0x00)
        usart0_putc(pgm_read_byte(string++));
}

/**
 * transmit interrupt handler
 * unused
 */

ISR(SIG_USART0_DATA) {
}

/*
 * receive data through usart1
 * portions taken and adapted from
 * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Fbranches%2FV0.72p+Code+Redesign+killagreg%2Fuart0.c
 */

ISR(SIG_USART0_RECV) {
    uint8_t c;
    // catch the received byte
    c = UDR0;

        // echo
        UDR0 = c;
}



#endif

#endif // ANTENNATRACKTEST