diff --git a/SConstruct b/SConstruct index 86243dfbd..9685f08ec 100644 --- a/SConstruct +++ b/SConstruct @@ -54,7 +54,7 @@ parser = PropertyParser(GetOption('properties'), target, verbose) # create a build-environment for the specific target build = parser.getGlobalProperties() -if build.target == 'avr': +if build.target == 'atmega' or build.target == 'atxmega': env = Environment( ARCHITECTURE = 'avr', AVRDUDE = build.avr.avrdude, diff --git a/misc/python/scons/build_properties.py b/misc/python/scons/build_properties.py index f1006254a..8384168fe 100644 --- a/misc/python/scons/build_properties.py +++ b/misc/python/scons/build_properties.py @@ -32,8 +32,10 @@ def __init__(self, properties, target=None): target = properties.get('target', 'pc') self.target = target - if self.target == 'avr': - self.avr = self.AvrProperties(properties.get('avr', {})) + if self.target == 'atmega': + self.avr = self.AvrProperties(properties.get('atmega', {})) + elif self.target == 'atxmega': + self.avr = self.AvrProperties(properties.get('atxmega', {})) def getLocalProperties(self, path, target, tag): try: diff --git a/properties.yaml b/properties.yaml index a379c9e77..f9ee03f62 100644 --- a/properties.yaml +++ b/properties.yaml @@ -1,15 +1,19 @@ -#target: avr +#target: atmega +#target: atxmega target: pc -avr: -# device: atmega2560 +atmega: + device: atmega2560 + clock: 14745600 + avrdude: + programmer: stk500 + port: /dev/ttyUSB0 + +atxmega: device: atxmega128a1 clock: 32000000 -# clock: 14745600 avrdude: -# programmer: stk500 -# port: /dev/ttyUSB0 programmer: avrispmkII port: usb @@ -37,5 +41,3 @@ library: tests: include: no -unittest: - diff --git a/src/xpcc/hal/avr/properties.yaml b/src/xpcc/hal/avr/properties.yaml deleted file mode 100644 index 3a3a9994b..000000000 --- a/src/xpcc/hal/avr/properties.yaml +++ /dev/null @@ -1,3 +0,0 @@ - -target: avr - diff --git a/src/xpcc/hal/avr/uart/uart0_put.cpp b/src/xpcc/hal/avr/uart/uart0_put.cpp deleted file mode 100644 index ab589b2d7..000000000 --- a/src/xpcc/hal/avr/uart/uart0_put.cpp +++ /dev/null @@ -1,50 +0,0 @@ - -#include -#include - -#include "../../../hal/atomic/queue.hpp" -#include "../../../hal/atomic/lock.hpp" - -#include "uart_defines.h" -#include "uart_defaults.h" - -#include "../uart0.hpp" - -#ifndef __AVR_ATxmega128A1__ - -static xpcc::atomic::Queue txBuffer; - -// ---------------------------------------------------------------------------- -// called when the UART is ready to transmit the next byte -// -ISR(UART0_TRANSMIT_INTERRUPT) -{ - if (txBuffer.isEmpty()) - { - // transmission finished, disable UDRE interrupt - UART0_CONTROL &= ~(1 << UART0_UDRIE); - } - else { - // get one byte from buffer and write it to UART (starts transmission) - UART0_DATA = txBuffer.get(); - txBuffer.pop(); - } -} - -// ---------------------------------------------------------------------------- -void -xpcc::Uart0::put(char c) -{ - while (!txBuffer.push(c)) { - // wait for a free slot in the buffer - } - - atomic::Lock lock; - - // enable UDRE interrupt - UART0_CONTROL |= (1 << UART0_UDRIE); -} - -#else - #warning TODO! -#endif diff --git a/src/xpcc/hal/avr/uart/uart1.cpp b/src/xpcc/hal/avr/uart/uart1.cpp deleted file mode 100644 index d5c5c9fc8..000000000 --- a/src/xpcc/hal/avr/uart/uart1.cpp +++ /dev/null @@ -1,75 +0,0 @@ - -#include -#include - -#include "../../../hal/atomic/queue.hpp" - -#include "uart_defines.h" -#include "uart_defaults.h" - -#include "../uart1.hpp" - -#ifdef ATMEGA_USART1 - -static xpcc::atomic::Queue rxBuffer; - -// ---------------------------------------------------------------------------- -// called when the UART has received a character -// -ISR(UART1_RECEIVE_INTERRUPT) -{ - uint8_t data = UART1_DATA; - - // read UART status register and UART data register - //uint8_t usr = UART1_STATUS; - -/* uint8_t last_rx_error; - last_rx_error = usr & ((1 << FE1) | (1 << DOR1));*/ - - // TODO Fehlerbehandlung - rxBuffer.push(data); -} - -// ---------------------------------------------------------------------------- -void -xpcc::Uart1::setBaudrateRegister(uint16_t ubrr) -{ - // Set baud rate - if (ubrr & 0x8000) { - UART1_STATUS = (1 << U2X1); //Enable 2x speed - ubrr &= ~0x8000; - } - else { - UART1_STATUS = 0; - } - UBRR1H = (uint8_t) (ubrr >> 8); - UBRR1L = (uint8_t) ubrr; - - // Enable USART receiver and transmitter and receive complete interrupt - UART1_CONTROL = (1 << RXCIE1) | (1 << RXEN1) | (1 << TXEN1); - - // Set frame format: asynchronous, 8data, no parity, 1stop bit - #ifdef URSEL1 - UCSR1C = (1 << URSEL1) | (3 << UCSZ10); - #else - UCSR1C = (3 << UCSZ10); - #endif -} - -// ---------------------------------------------------------------------------- -bool -xpcc::Uart1::get(char& c) -{ - if (rxBuffer.isEmpty()) { - return false; - } - else { - c = rxBuffer.get(); - rxBuffer.pop(); - - return true; - } -} - -#endif // ATMEGA_USART1 - diff --git a/src/xpcc/hal/avr/uart/uart1_put.cpp b/src/xpcc/hal/avr/uart/uart1_put.cpp deleted file mode 100644 index 084e57a7c..000000000 --- a/src/xpcc/hal/avr/uart/uart1_put.cpp +++ /dev/null @@ -1,48 +0,0 @@ - -#include -#include - -#include "../../../hal/atomic/queue.hpp" -#include "../../../hal/atomic/lock.hpp" - -#include "uart_defines.h" -#include "uart_defaults.h" - -#include "../uart1.hpp" - -#ifdef ATMEGA_USART1 - -static xpcc::atomic::Queue txBuffer; - -// ---------------------------------------------------------------------------- -// called when the UART is ready to transmit the next byte -// -ISR(UART1_TRANSMIT_INTERRUPT) -{ - if (txBuffer.isEmpty()) - { - // transmission finished, disable UDRE interrupt - UART1_CONTROL &= ~(1 << UART1_UDRIE); - } - else { - // get one byte from buffer and write it to UART (starts transmission) - UART1_DATA = txBuffer.get(); - txBuffer.pop(); - } -} - -// ---------------------------------------------------------------------------- -void -xpcc::Uart1::put(char c) -{ - while (!txBuffer.push(c)) { - // wait for a free slot in the buffer - } - - atomic::Lock lock; - - // enable UDRE interrupt - UART1_CONTROL |= (1 << UART1_UDRIE); -} - -#endif // ATMEGA_USART1 diff --git a/src/xpcc/hal/avr/uart/uart2.cpp b/src/xpcc/hal/avr/uart/uart2.cpp deleted file mode 100644 index 959e2b4f2..000000000 --- a/src/xpcc/hal/avr/uart/uart2.cpp +++ /dev/null @@ -1,75 +0,0 @@ - -#include -#include - -#include "../../../hal/atomic/queue.hpp" - -#include "uart_defines.h" -#include "uart_defaults.h" - -#include "../uart2.hpp" - -#ifdef ATMEGA_USART2 - -static xpcc::atomic::Queue rxBuffer; - -// ---------------------------------------------------------------------------- -// called when the UART has received a character -// -ISR(UART2_RECEIVE_INTERRUPT) -{ - uint8_t data = UART2_DATA; - - // read UART status register and UART data register - //uint8_t usr = UART2_STATUS; - -/* uint8_t last_rx_error; - last_rx_error = usr & ((1 << FE2) | (1 << DOR2));*/ - - // TODO Fehlerbehandlung - rxBuffer.push(data); -} - -// ---------------------------------------------------------------------------- -void -xpcc::Uart2::setBaudrateRegister(uint16_t ubrr) -{ - // Set baud rate - if (ubrr & 0x8000) { - UART2_STATUS = (1 << U2X2); //Enable 2x speed - ubrr &= ~0x8000; - } - else { - UART2_STATUS = 0; - } - UBRR2H = (uint8_t) (ubrr >> 8); - UBRR2L = (uint8_t) ubrr; - - // Enable USART receiver and transmitter and receive complete interrupt - UART2_CONTROL = (1 << RXCIE2) | (1 << RXEN2) | (1 << TXEN2); - - // Set frame format: asynchronous, 8data, no parity, 1stop bit - #ifdef URSEL1 - UCSR2C = (1 << URSEL2) | (3 << UCSZ20); - #else - UCSR2C = (3 << UCSZ20); - #endif -} - -// ---------------------------------------------------------------------------- -bool -xpcc::Uart2::get(char& c) -{ - if (rxBuffer.isEmpty()) { - return false; - } - else { - c = rxBuffer.get(); - rxBuffer.pop(); - - return true; - } -} - -#endif // ATMEGA_USART2 - diff --git a/src/xpcc/hal/avr/uart/uart2_put.cpp b/src/xpcc/hal/avr/uart/uart2_put.cpp deleted file mode 100644 index c1af78f04..000000000 --- a/src/xpcc/hal/avr/uart/uart2_put.cpp +++ /dev/null @@ -1,49 +0,0 @@ - -#include -#include - -#include "../../../hal/atomic/queue.hpp" -#include "../../../hal/atomic/lock.hpp" - -#include "uart_defines.h" -#include "uart_defaults.h" - -#include "../uart2.hpp" - -#ifdef ATMEGA_USART2 - -static xpcc::atomic::Queue txBuffer; - -// ---------------------------------------------------------------------------- -// called when the UART is ready to transmit the next byte -// -ISR(UART2_TRANSMIT_INTERRUPT) -{ - if (txBuffer.isEmpty()) - { - // transmission finished, disable UDRE interrupt - UART2_CONTROL &= ~(1 << UART2_UDRIE); - } - else { - // get one byte from buffer and write it to UART (starts transmission) - UART2_DATA = txBuffer.get(); - txBuffer.pop(); - } -} - -// ---------------------------------------------------------------------------- -void -xpcc::Uart2::put(char c) -{ - while (!txBuffer.push(c)) { - // wait for a free slot in the buffer - } - - atomic::Lock lock; - - // enable UDRE interrupt - UART2_CONTROL |= (1 << UART2_UDRIE); -} - -#endif // ATMEGA_USART2 - diff --git a/src/xpcc/hal/avr/uart/uart3.cpp b/src/xpcc/hal/avr/uart/uart3.cpp deleted file mode 100644 index fdc0704ff..000000000 --- a/src/xpcc/hal/avr/uart/uart3.cpp +++ /dev/null @@ -1,75 +0,0 @@ - -#include -#include - -#include "../../../hal/atomic/queue.hpp" - -#include "uart_defines.h" -#include "uart_defaults.h" - -#include "../uart3.hpp" - -#ifdef ATMEGA_USART3 - -static xpcc::atomic::Queue rxBuffer; - -// ---------------------------------------------------------------------------- -// called when the UART has received a character -// -ISR(UART3_RECEIVE_INTERRUPT) -{ - uint8_t data = UART3_DATA; - - // read UART status register and UART data register - //uint8_t usr = UART3_STATUS; - -/* uint8_t last_rx_error; - last_rx_error = usr & ((1 << FE1) | (1 << DOR1));*/ - - // TODO Fehlerbehandlung - rxBuffer.push(data); -} - -// ---------------------------------------------------------------------------- -void -xpcc::Uart3::setBaudrateRegister(uint16_t ubrr) -{ - // Set baud rate - if (ubrr & 0x8000) { - UART3_STATUS = (1 << U2X3); //Enable 2x speed - ubrr &= ~0x8000; - } - else { - UART3_STATUS = 0; - } - UBRR3H = (uint8_t) (ubrr >> 8); - UBRR3L = (uint8_t) ubrr; - - // Enable USART receiver and transmitter and receive complete interrupt - UART3_CONTROL = (1 << RXCIE3) | (1 << RXEN3) | (1 << TXEN3); - - // Set frame format: asynchronous, 8data, no parity, 1stop bit - #ifdef URSEL1 - UCSR1C = (1 << URSEL3) | (3 << UCSZ30); - #else - UCSR1C = (3 << UCSZ30); - #endif -} - -// ---------------------------------------------------------------------------- -bool -xpcc::Uart3::get(char& c) -{ - if (rxBuffer.isEmpty()) { - return false; - } - else { - c = rxBuffer.get(); - rxBuffer.pop(); - - return true; - } -} - -#endif // ATMEGA_USART3 - diff --git a/src/xpcc/hal/avr/uart/uart3_put.cpp b/src/xpcc/hal/avr/uart/uart3_put.cpp deleted file mode 100644 index b6756e55e..000000000 --- a/src/xpcc/hal/avr/uart/uart3_put.cpp +++ /dev/null @@ -1,48 +0,0 @@ - -#include -#include - -#include "../../../hal/atomic/queue.hpp" -#include "../../../hal/atomic/lock.hpp" - -#include "uart_defines.h" -#include "uart_defaults.h" - -#include "../uart3.hpp" - -#ifdef ATMEGA_USART3 - -static xpcc::atomic::Queue txBuffer; - -// ---------------------------------------------------------------------------- -// called when the UART is ready to transmit the next byte -// -ISR(UART3_TRANSMIT_INTERRUPT) -{ - if (txBuffer.isEmpty()) - { - // transmission finished, disable UDRE interrupt - UART3_CONTROL &= ~(1 << UART3_UDRIE); - } - else { - // get one byte from buffer and write it to UART (starts transmission) - UART3_DATA = txBuffer.get(); - txBuffer.pop(); - } -} - -// ---------------------------------------------------------------------------- -void -xpcc::Uart3::put(char c) -{ - while (!txBuffer.push(c)) { - // wait for a free slot in the buffer - } - - atomic::Lock lock; - - // enable UDRE interrupt - UART3_CONTROL |= (1 << UART3_UDRIE); -} - -#endif // ATMEGA_USART3 diff --git a/src/xpcc/hal/avr/pin.hpp b/src/xpcc/hal/peripheral/atmega/pin.hpp similarity index 100% rename from src/xpcc/hal/avr/pin.hpp rename to src/xpcc/hal/peripheral/atmega/pin.hpp diff --git a/src/xpcc/hal/peripheral/atmega/properties.yaml b/src/xpcc/hal/peripheral/atmega/properties.yaml new file mode 100644 index 000000000..8792fb69e --- /dev/null +++ b/src/xpcc/hal/peripheral/atmega/properties.yaml @@ -0,0 +1,3 @@ + +target: atmega + diff --git a/src/xpcc/hal/avr/spi/spi.cpp b/src/xpcc/hal/peripheral/atmega/spi/spi.cpp similarity index 100% rename from src/xpcc/hal/avr/spi/spi.cpp rename to src/xpcc/hal/peripheral/atmega/spi/spi.cpp diff --git a/src/xpcc/hal/avr/spi/spi.hpp b/src/xpcc/hal/peripheral/atmega/spi/spi.hpp similarity index 100% rename from src/xpcc/hal/avr/spi/spi.hpp rename to src/xpcc/hal/peripheral/atmega/spi/spi.hpp diff --git a/src/xpcc/hal/peripheral/atmega/uart/generate.py b/src/xpcc/hal/peripheral/atmega/uart/generate.py new file mode 100755 index 000000000..9e74c4d31 --- /dev/null +++ b/src/xpcc/hal/peripheral/atmega/uart/generate.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# +# $Id$ + +import os +import time +import jinja2 + +generation = """/* + * WARNING: This file is generated automatically, do not edit! + * Please modify the corresponding *.tmpl file instead and re-run the + * script 'generate.py'. + * + * Generated %s + */ +// ---------------------------------------------------------------------------- +""" % time.strftime("%d %b %Y, %H:%M:%S", time.localtime()) + +env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.getcwd())) + +globals = { + 'generation_block': generation +} + +for number in range(0,4): + template = env.get_template('uartn.hpp.tmpl', globals=globals) + output = template.render(id=number) + open('uart%i.hpp' % number, 'w').write(output) + + template = env.get_template('uartn.cpp.tmpl', globals=globals) + output = template.render(id=number) + open('uart%i.cpp' % number, 'w').write(output) + + template = env.get_template('uartn_put.cpp.tmpl', globals=globals) + output = template.render(id=number) + open('uart%i_put.cpp' % number, 'w').write(output) diff --git a/src/xpcc/hal/avr/uart.hpp b/src/xpcc/hal/peripheral/atmega/uart/uart.hpp similarity index 100% rename from src/xpcc/hal/avr/uart.hpp rename to src/xpcc/hal/peripheral/atmega/uart/uart.hpp diff --git a/src/xpcc/hal/avr/uart/uart0.cpp b/src/xpcc/hal/peripheral/atmega/uart/uart0.cpp similarity index 53% rename from src/xpcc/hal/avr/uart/uart0.cpp rename to src/xpcc/hal/peripheral/atmega/uart/uart0.cpp index 745fb6b14..2744875a6 100644 --- a/src/xpcc/hal/avr/uart/uart0.cpp +++ b/src/xpcc/hal/peripheral/atmega/uart/uart0.cpp @@ -1,21 +1,58 @@ +// coding: utf-8 +// ---------------------------------------------------------------------------- +/* Copyright (c) 2009, Roboterclub Aachen e.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Roboterclub Aachen e.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id$ + */ +// ---------------------------------------------------------------------------- +/* + * WARNING: This file is generated automatically, do not edit! + * Please modify the corresponding *.tmpl file instead and re-run the + * script 'generate.py'. + * + * Generated 08 Nov 2009, 18:08:18 + */ +// ---------------------------------------------------------------------------- #include #include -#include "../../../hal/atomic/queue.hpp" +#include #include "uart_defines.h" #include "uart_defaults.h" -#include "../uart0.hpp" - -#ifndef __AVR_ATxmega128A1__ +#include "uart0.hpp" static xpcc::atomic::Queue rxBuffer; // ---------------------------------------------------------------------------- // called when the UART has received a character -// + ISR(UART0_RECEIVE_INTERRUPT) { uint8_t data = UART0_DATA; @@ -24,9 +61,7 @@ ISR(UART0_RECEIVE_INTERRUPT) //uint8_t usr = UART0_STATUS; // uint8_t last_rx_error; -//#if defined(AT90_UART) -// last_rx_error = usr & ((1 << FE) | (1 << DOR)); -//#elif defined(ATMEGA_USART) +//#if defined(ATMEGA_USART) // last_rx_error = usr & ((1 << FE) | (1 << DOR)); //#elif defined(ATMEGA_USART0) // last_rx_error = usr & ((1 << FE0) | (1 << DOR0)); @@ -42,14 +77,22 @@ ISR(UART0_RECEIVE_INTERRUPT) void xpcc::Uart0::setBaudrateRegister(uint16_t ubrr) { -#if defined(AT90_UART) - +#if defined(ATMEGA_UART) + // set baud rate - UBRR = (uint8_t) ubrr; + if (ubrr & 0x8000) { + UART0_STATUS = (1 << U2X); //Enable 2x speed + ubrr &= ~0x8000; + } + else { + UART0_STATUS = 0; + } + UBRRHI = (uint8_t) (ubrr >> 8); + UBRR = (uint8_t) ubrr; - // enable UART receiver and transmmitter and receive complete interrupt + // Enable UART receiver and transmitter and receive complete interrupt UART0_CONTROL = (1 << RXCIE) | (1 << RXEN) | (1 << TXEN); - + #elif defined(ATMEGA_USART) // Set baudrate @@ -96,22 +139,6 @@ xpcc::Uart0::setBaudrateRegister(uint16_t ubrr) UCSR0C = (3 << UCSZ00); #endif -#elif defined(ATMEGA_UART) - - // set baud rate - if (ubrr & 0x8000) { - UART0_STATUS = (1 << U2X); //Enable 2x speed - ubrr &= ~0x8000; - } - else { - UART0_STATUS = 0; - } - UBRRHI = (uint8_t) (ubrr >> 8); - UBRR = (uint8_t) ubrr; - - // Enable UART receiver and transmitter and receive complete interrupt - UART0_CONTROL = (1 << RXCIE) | (1 << RXEN) | (1 << TXEN); - #endif } @@ -129,7 +156,3 @@ xpcc::Uart0::get(char& c) return true; } } - -#else - #warning TODO! -#endif diff --git a/src/xpcc/hal/avr/uart0.hpp b/src/xpcc/hal/peripheral/atmega/uart/uart0.hpp similarity index 88% rename from src/xpcc/hal/avr/uart0.hpp rename to src/xpcc/hal/peripheral/atmega/uart/uart0.hpp index 8100ec743..07b471dc7 100644 --- a/src/xpcc/hal/avr/uart0.hpp +++ b/src/xpcc/hal/peripheral/atmega/uart/uart0.hpp @@ -5,6 +5,7 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: + * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright @@ -25,7 +26,15 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: uart0.hpp 69 2009-10-10 17:51:10Z dergraaf $ + * $Id$ + */ +// ---------------------------------------------------------------------------- +/* + * WARNING: This file is generated automatically, do not edit! + * Please modify the corresponding *.tmpl file instead and re-run the + * script 'generate.py'. + * + * Generated 08 Nov 2009, 18:08:18 */ // ---------------------------------------------------------------------------- diff --git a/src/xpcc/hal/peripheral/atmega/uart/uart0_put.cpp b/src/xpcc/hal/peripheral/atmega/uart/uart0_put.cpp new file mode 100644 index 000000000..432e99459 --- /dev/null +++ b/src/xpcc/hal/peripheral/atmega/uart/uart0_put.cpp @@ -0,0 +1,83 @@ +// coding: utf-8 +// ---------------------------------------------------------------------------- +/* Copyright (c) 2009, Roboterclub Aachen e.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Roboterclub Aachen e.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id$ + */ +// ---------------------------------------------------------------------------- +/* + * WARNING: This file is generated automatically, do not edit! + * Please modify the corresponding *.tmpl file instead and re-run the + * script 'generate.py'. + * + * Generated 08 Nov 2009, 18:08:18 + */ +// ---------------------------------------------------------------------------- + +#include +#include + +#include +#include + +#include "uart_defines.h" +#include "uart_defaults.h" + +#include "uart0.hpp" + +static xpcc::atomic::Queue txBuffer; + +// ---------------------------------------------------------------------------- +// called when the UART is ready to transmit the next byte + +ISR(UART0_TRANSMIT_INTERRUPT) +{ + if (txBuffer.isEmpty()) + { + // transmission finished, disable UDRE interrupt + UART0_CONTROL &= ~(1 << UART0_UDRIE); + } + else { + // get one byte from buffer and write it to UART (starts transmission) + UART0_DATA = txBuffer.get(); + txBuffer.pop(); + } +} + +// ---------------------------------------------------------------------------- +void +xpcc::Uart0::put(char c) +{ + while (!txBuffer.push(c)) { + // wait for a free slot in the buffer + } + + atomic::Lock lock; + + // enable UDRE interrupt + UART0_CONTROL |= (1 << UART0_UDRIE); +} diff --git a/src/xpcc/hal/peripheral/atmega/uart/uart1.cpp b/src/xpcc/hal/peripheral/atmega/uart/uart1.cpp new file mode 100644 index 000000000..f36f86d6d --- /dev/null +++ b/src/xpcc/hal/peripheral/atmega/uart/uart1.cpp @@ -0,0 +1,116 @@ +// coding: utf-8 +// ---------------------------------------------------------------------------- +/* Copyright (c) 2009, Roboterclub Aachen e.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Roboterclub Aachen e.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id$ + */ +// ---------------------------------------------------------------------------- +/* + * WARNING: This file is generated automatically, do not edit! + * Please modify the corresponding *.tmpl file instead and re-run the + * script 'generate.py'. + * + * Generated 08 Nov 2009, 18:08:18 + */ +// ---------------------------------------------------------------------------- + +#include +#include + +#include + +#include "uart_defines.h" +#include "uart_defaults.h" + +#include "uart1.hpp" + +static xpcc::atomic::Queue rxBuffer; + +// ---------------------------------------------------------------------------- +// called when the UART has received a character + +ISR(UART1_RECEIVE_INTERRUPT) +{ + uint8_t data = UART1_DATA; + + // read UART status register and UART data register + //uint8_t usr = UART1_STATUS; + +// uint8_t last_rx_error; +//#if defined(ATMEGA_USART) +// last_rx_error = usr & ((1 << FE) | (1 << DOR)); +//#elif defined(ATMEGA_USART1) +// last_rx_error = usr & ((1 << FE1) | (1 << DOR1)); +//#elif defined (ATMEGA_UART) +// last_rx_error = usr & ((1 << FE) | (1 << DOR)); +//#endif + + // TODO Fehlerbehandlung + rxBuffer.push(data); +} + +// ---------------------------------------------------------------------------- +void +xpcc::Uart1::setBaudrateRegister(uint16_t ubrr) +{ + + // Set baud rate + if (ubrr & 0x8000) { + UART0_STATUS = (1 << U2X0); //Enable 2x speed + ubrr &= ~0x8000; + } + else { + UART0_STATUS = 0; + } + UBRR0H = (uint8_t) (ubrr >> 8); + UBRR0L = (uint8_t) ubrr; + + // Enable USART receiver and transmitter and receive complete interrupt + UART0_CONTROL = (1 << RXCIE0) | (1 << RXEN0) | (1 << TXEN0); + + // Set frame format: asynchronous, 8data, no parity, 1stop bit + #ifdef URSEL0 + UCSR0C = (1 << URSEL0) | (3 << UCSZ00); + #else + UCSR0C = (3 << UCSZ00); + #endif +} + +// ---------------------------------------------------------------------------- +bool +xpcc::Uart1::get(char& c) +{ + if (rxBuffer.isEmpty()) { + return false; + } + else { + c = rxBuffer.get(); + rxBuffer.pop(); + + return true; + } +} diff --git a/src/xpcc/hal/avr/uart1.hpp b/src/xpcc/hal/peripheral/atmega/uart/uart1.hpp similarity index 88% rename from src/xpcc/hal/avr/uart1.hpp rename to src/xpcc/hal/peripheral/atmega/uart/uart1.hpp index acb04f1cc..99e0bf3fd 100644 --- a/src/xpcc/hal/avr/uart1.hpp +++ b/src/xpcc/hal/peripheral/atmega/uart/uart1.hpp @@ -5,6 +5,7 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: + * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright @@ -25,7 +26,15 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: uart1.hpp 69 2009-10-10 17:51:10Z dergraaf $ + * $Id$ + */ +// ---------------------------------------------------------------------------- +/* + * WARNING: This file is generated automatically, do not edit! + * Please modify the corresponding *.tmpl file instead and re-run the + * script 'generate.py'. + * + * Generated 08 Nov 2009, 18:08:18 */ // ---------------------------------------------------------------------------- diff --git a/src/xpcc/hal/peripheral/atmega/uart/uart1_put.cpp b/src/xpcc/hal/peripheral/atmega/uart/uart1_put.cpp new file mode 100644 index 000000000..4417ac4f9 --- /dev/null +++ b/src/xpcc/hal/peripheral/atmega/uart/uart1_put.cpp @@ -0,0 +1,83 @@ +// coding: utf-8 +// ---------------------------------------------------------------------------- +/* Copyright (c) 2009, Roboterclub Aachen e.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Roboterclub Aachen e.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id$ + */ +// ---------------------------------------------------------------------------- +/* + * WARNING: This file is generated automatically, do not edit! + * Please modify the corresponding *.tmpl file instead and re-run the + * script 'generate.py'. + * + * Generated 08 Nov 2009, 18:08:18 + */ +// ---------------------------------------------------------------------------- + +#include +#include + +#include +#include + +#include "uart_defines.h" +#include "uart_defaults.h" + +#include "uart1.hpp" + +static xpcc::atomic::Queue txBuffer; + +// ---------------------------------------------------------------------------- +// called when the UART is ready to transmit the next byte + +ISR(UART1_TRANSMIT_INTERRUPT) +{ + if (txBuffer.isEmpty()) + { + // transmission finished, disable UDRE interrupt + UART1_CONTROL &= ~(1 << UART1_UDRIE); + } + else { + // get one byte from buffer and write it to UART (starts transmission) + UART1_DATA = txBuffer.get(); + txBuffer.pop(); + } +} + +// ---------------------------------------------------------------------------- +void +xpcc::Uart1::put(char c) +{ + while (!txBuffer.push(c)) { + // wait for a free slot in the buffer + } + + atomic::Lock lock; + + // enable UDRE interrupt + UART1_CONTROL |= (1 << UART1_UDRIE); +} diff --git a/src/xpcc/hal/peripheral/atmega/uart/uart2.cpp b/src/xpcc/hal/peripheral/atmega/uart/uart2.cpp new file mode 100644 index 000000000..5bbcf1860 --- /dev/null +++ b/src/xpcc/hal/peripheral/atmega/uart/uart2.cpp @@ -0,0 +1,116 @@ +// coding: utf-8 +// ---------------------------------------------------------------------------- +/* Copyright (c) 2009, Roboterclub Aachen e.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Roboterclub Aachen e.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id$ + */ +// ---------------------------------------------------------------------------- +/* + * WARNING: This file is generated automatically, do not edit! + * Please modify the corresponding *.tmpl file instead and re-run the + * script 'generate.py'. + * + * Generated 08 Nov 2009, 18:08:18 + */ +// ---------------------------------------------------------------------------- + +#include +#include + +#include + +#include "uart_defines.h" +#include "uart_defaults.h" + +#include "uart2.hpp" + +static xpcc::atomic::Queue rxBuffer; + +// ---------------------------------------------------------------------------- +// called when the UART has received a character + +ISR(UART2_RECEIVE_INTERRUPT) +{ + uint8_t data = UART2_DATA; + + // read UART status register and UART data register + //uint8_t usr = UART2_STATUS; + +// uint8_t last_rx_error; +//#if defined(ATMEGA_USART) +// last_rx_error = usr & ((1 << FE) | (1 << DOR)); +//#elif defined(ATMEGA_USART2) +// last_rx_error = usr & ((1 << FE2) | (1 << DOR2)); +//#elif defined (ATMEGA_UART) +// last_rx_error = usr & ((1 << FE) | (1 << DOR)); +//#endif + + // TODO Fehlerbehandlung + rxBuffer.push(data); +} + +// ---------------------------------------------------------------------------- +void +xpcc::Uart2::setBaudrateRegister(uint16_t ubrr) +{ + + // Set baud rate + if (ubrr & 0x8000) { + UART0_STATUS = (1 << U2X0); //Enable 2x speed + ubrr &= ~0x8000; + } + else { + UART0_STATUS = 0; + } + UBRR0H = (uint8_t) (ubrr >> 8); + UBRR0L = (uint8_t) ubrr; + + // Enable USART receiver and transmitter and receive complete interrupt + UART0_CONTROL = (1 << RXCIE0) | (1 << RXEN0) | (1 << TXEN0); + + // Set frame format: asynchronous, 8data, no parity, 1stop bit + #ifdef URSEL0 + UCSR0C = (1 << URSEL0) | (3 << UCSZ00); + #else + UCSR0C = (3 << UCSZ00); + #endif +} + +// ---------------------------------------------------------------------------- +bool +xpcc::Uart2::get(char& c) +{ + if (rxBuffer.isEmpty()) { + return false; + } + else { + c = rxBuffer.get(); + rxBuffer.pop(); + + return true; + } +} diff --git a/src/xpcc/hal/avr/uart2.hpp b/src/xpcc/hal/peripheral/atmega/uart/uart2.hpp similarity index 88% rename from src/xpcc/hal/avr/uart2.hpp rename to src/xpcc/hal/peripheral/atmega/uart/uart2.hpp index 2e8ec0637..0c2d16448 100644 --- a/src/xpcc/hal/avr/uart2.hpp +++ b/src/xpcc/hal/peripheral/atmega/uart/uart2.hpp @@ -5,6 +5,7 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: + * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright @@ -25,7 +26,15 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: uart2.hpp 69 2009-10-10 17:51:10Z dergraaf $ + * $Id$ + */ +// ---------------------------------------------------------------------------- +/* + * WARNING: This file is generated automatically, do not edit! + * Please modify the corresponding *.tmpl file instead and re-run the + * script 'generate.py'. + * + * Generated 08 Nov 2009, 18:08:18 */ // ---------------------------------------------------------------------------- diff --git a/src/xpcc/hal/peripheral/atmega/uart/uart2_put.cpp b/src/xpcc/hal/peripheral/atmega/uart/uart2_put.cpp new file mode 100644 index 000000000..286d41f5a --- /dev/null +++ b/src/xpcc/hal/peripheral/atmega/uart/uart2_put.cpp @@ -0,0 +1,83 @@ +// coding: utf-8 +// ---------------------------------------------------------------------------- +/* Copyright (c) 2009, Roboterclub Aachen e.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Roboterclub Aachen e.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id$ + */ +// ---------------------------------------------------------------------------- +/* + * WARNING: This file is generated automatically, do not edit! + * Please modify the corresponding *.tmpl file instead and re-run the + * script 'generate.py'. + * + * Generated 08 Nov 2009, 18:08:18 + */ +// ---------------------------------------------------------------------------- + +#include +#include + +#include +#include + +#include "uart_defines.h" +#include "uart_defaults.h" + +#include "uart2.hpp" + +static xpcc::atomic::Queue txBuffer; + +// ---------------------------------------------------------------------------- +// called when the UART is ready to transmit the next byte + +ISR(UART2_TRANSMIT_INTERRUPT) +{ + if (txBuffer.isEmpty()) + { + // transmission finished, disable UDRE interrupt + UART2_CONTROL &= ~(1 << UART2_UDRIE); + } + else { + // get one byte from buffer and write it to UART (starts transmission) + UART2_DATA = txBuffer.get(); + txBuffer.pop(); + } +} + +// ---------------------------------------------------------------------------- +void +xpcc::Uart2::put(char c) +{ + while (!txBuffer.push(c)) { + // wait for a free slot in the buffer + } + + atomic::Lock lock; + + // enable UDRE interrupt + UART2_CONTROL |= (1 << UART2_UDRIE); +} diff --git a/src/xpcc/hal/peripheral/atmega/uart/uart3.cpp b/src/xpcc/hal/peripheral/atmega/uart/uart3.cpp new file mode 100644 index 000000000..280a6a1ed --- /dev/null +++ b/src/xpcc/hal/peripheral/atmega/uart/uart3.cpp @@ -0,0 +1,116 @@ +// coding: utf-8 +// ---------------------------------------------------------------------------- +/* Copyright (c) 2009, Roboterclub Aachen e.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Roboterclub Aachen e.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id$ + */ +// ---------------------------------------------------------------------------- +/* + * WARNING: This file is generated automatically, do not edit! + * Please modify the corresponding *.tmpl file instead and re-run the + * script 'generate.py'. + * + * Generated 08 Nov 2009, 18:08:18 + */ +// ---------------------------------------------------------------------------- + +#include +#include + +#include + +#include "uart_defines.h" +#include "uart_defaults.h" + +#include "uart3.hpp" + +static xpcc::atomic::Queue rxBuffer; + +// ---------------------------------------------------------------------------- +// called when the UART has received a character + +ISR(UART3_RECEIVE_INTERRUPT) +{ + uint8_t data = UART3_DATA; + + // read UART status register and UART data register + //uint8_t usr = UART3_STATUS; + +// uint8_t last_rx_error; +//#if defined(ATMEGA_USART) +// last_rx_error = usr & ((1 << FE) | (1 << DOR)); +//#elif defined(ATMEGA_USART3) +// last_rx_error = usr & ((1 << FE3) | (1 << DOR3)); +//#elif defined (ATMEGA_UART) +// last_rx_error = usr & ((1 << FE) | (1 << DOR)); +//#endif + + // TODO Fehlerbehandlung + rxBuffer.push(data); +} + +// ---------------------------------------------------------------------------- +void +xpcc::Uart3::setBaudrateRegister(uint16_t ubrr) +{ + + // Set baud rate + if (ubrr & 0x8000) { + UART0_STATUS = (1 << U2X0); //Enable 2x speed + ubrr &= ~0x8000; + } + else { + UART0_STATUS = 0; + } + UBRR0H = (uint8_t) (ubrr >> 8); + UBRR0L = (uint8_t) ubrr; + + // Enable USART receiver and transmitter and receive complete interrupt + UART0_CONTROL = (1 << RXCIE0) | (1 << RXEN0) | (1 << TXEN0); + + // Set frame format: asynchronous, 8data, no parity, 1stop bit + #ifdef URSEL0 + UCSR0C = (1 << URSEL0) | (3 << UCSZ00); + #else + UCSR0C = (3 << UCSZ00); + #endif +} + +// ---------------------------------------------------------------------------- +bool +xpcc::Uart3::get(char& c) +{ + if (rxBuffer.isEmpty()) { + return false; + } + else { + c = rxBuffer.get(); + rxBuffer.pop(); + + return true; + } +} diff --git a/src/xpcc/hal/avr/uart3.hpp b/src/xpcc/hal/peripheral/atmega/uart/uart3.hpp similarity index 88% rename from src/xpcc/hal/avr/uart3.hpp rename to src/xpcc/hal/peripheral/atmega/uart/uart3.hpp index cd66a382d..ea46143c4 100644 --- a/src/xpcc/hal/avr/uart3.hpp +++ b/src/xpcc/hal/peripheral/atmega/uart/uart3.hpp @@ -5,6 +5,7 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: + * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright @@ -25,7 +26,15 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: uart3.hpp 69 2009-10-10 17:51:10Z dergraaf $ + * $Id$ + */ +// ---------------------------------------------------------------------------- +/* + * WARNING: This file is generated automatically, do not edit! + * Please modify the corresponding *.tmpl file instead and re-run the + * script 'generate.py'. + * + * Generated 08 Nov 2009, 18:08:18 */ // ---------------------------------------------------------------------------- diff --git a/src/xpcc/hal/peripheral/atmega/uart/uart3_put.cpp b/src/xpcc/hal/peripheral/atmega/uart/uart3_put.cpp new file mode 100644 index 000000000..cbb84e25c --- /dev/null +++ b/src/xpcc/hal/peripheral/atmega/uart/uart3_put.cpp @@ -0,0 +1,83 @@ +// coding: utf-8 +// ---------------------------------------------------------------------------- +/* Copyright (c) 2009, Roboterclub Aachen e.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Roboterclub Aachen e.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id$ + */ +// ---------------------------------------------------------------------------- +/* + * WARNING: This file is generated automatically, do not edit! + * Please modify the corresponding *.tmpl file instead and re-run the + * script 'generate.py'. + * + * Generated 08 Nov 2009, 18:08:18 + */ +// ---------------------------------------------------------------------------- + +#include +#include + +#include +#include + +#include "uart_defines.h" +#include "uart_defaults.h" + +#include "uart3.hpp" + +static xpcc::atomic::Queue txBuffer; + +// ---------------------------------------------------------------------------- +// called when the UART is ready to transmit the next byte + +ISR(UART3_TRANSMIT_INTERRUPT) +{ + if (txBuffer.isEmpty()) + { + // transmission finished, disable UDRE interrupt + UART3_CONTROL &= ~(1 << UART3_UDRIE); + } + else { + // get one byte from buffer and write it to UART (starts transmission) + UART3_DATA = txBuffer.get(); + txBuffer.pop(); + } +} + +// ---------------------------------------------------------------------------- +void +xpcc::Uart3::put(char c) +{ + while (!txBuffer.push(c)) { + // wait for a free slot in the buffer + } + + atomic::Lock lock; + + // enable UDRE interrupt + UART3_CONTROL |= (1 << UART3_UDRIE); +} diff --git a/src/xpcc/hal/avr/uart/uart_defaults.h b/src/xpcc/hal/peripheral/atmega/uart/uart_defaults.h similarity index 100% rename from src/xpcc/hal/avr/uart/uart_defaults.h rename to src/xpcc/hal/peripheral/atmega/uart/uart_defaults.h diff --git a/src/xpcc/hal/avr/uart/uart_defines.h b/src/xpcc/hal/peripheral/atmega/uart/uart_defines.h similarity index 85% rename from src/xpcc/hal/avr/uart/uart_defines.h rename to src/xpcc/hal/peripheral/atmega/uart/uart_defines.h index 9bcf83900..b57e214a4 100644 --- a/src/xpcc/hal/avr/uart/uart_defines.h +++ b/src/xpcc/hal/peripheral/atmega/uart/uart_defines.h @@ -7,30 +7,7 @@ #ifndef UART_DEFS_H #define UART_DEFS_H -#if defined(__AVR_AT90S2313__) ||\ - defined(__AVR_AT90S4414__) || defined(__AVR_AT90S4434__) ||\ - defined(__AVR_AT90S8515__) || defined(__AVR_AT90S8535__) ||\ - defined(__AVR_ATmega103__) - // old AVR classic or ATmega103 with one UART - #define AT90_UART - #define UART0_RECEIVE_INTERRUPT SIG_UART_RECV - #define UART0_TRANSMIT_INTERRUPT SIG_UART_DATA - #define UART0_STATUS USR - #define UART0_CONTROL UCR - #define UART0_DATA UDR - #define UART0_UDRIE UDRIE - -#elif defined(__AVR_AT90S2333__) || defined(__AVR_AT90S4433__) - // old AVR classic with one UART - #define AT90_UART - #define UART0_RECEIVE_INTERRUPT SIG_UART_RECV - #define UART0_TRANSMIT_INTERRUPT SIG_UART_DATA - #define UART0_STATUS UCSRA - #define UART0_CONTROL UCSRB - #define UART0_DATA UDR - #define UART0_UDRIE UDRIE - -#elif defined(__AVR_ATmega8__) || defined(__AVR_ATmega16__) ||\ +#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega16__) ||\ defined(__AVR_ATmega32__) || defined(__AVR_ATmega8515__) ||\ defined(__AVR_ATmega8535__) || defined(__AVR_ATmega323__) // ATmega with one USART diff --git a/src/xpcc/hal/peripheral/atmega/uart/uartn.cpp.tmpl b/src/xpcc/hal/peripheral/atmega/uart/uartn.cpp.tmpl new file mode 100644 index 000000000..8596a201b --- /dev/null +++ b/src/xpcc/hal/peripheral/atmega/uart/uartn.cpp.tmpl @@ -0,0 +1,154 @@ +// coding: utf-8 +// ---------------------------------------------------------------------------- +/* Copyright (c) 2009, Roboterclub Aachen e.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Roboterclub Aachen e.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id$ + */ +// ---------------------------------------------------------------------------- +{{ generation_block }} + +#include +#include + +#include + +#include "uart_defines.h" +#include "uart_defaults.h" + +#include "uart{{ id }}.hpp" + +static xpcc::atomic::Queue rxBuffer; + +// ---------------------------------------------------------------------------- +// called when the UART has received a character + +ISR(UART{{ id }}_RECEIVE_INTERRUPT) +{ + uint8_t data = UART{{ id }}_DATA; + + // read UART status register and UART data register + //uint8_t usr = UART{{ id }}_STATUS; + +// uint8_t last_rx_error; +//#if defined(ATMEGA_USART) +// last_rx_error = usr & ((1 << FE) | (1 << DOR)); +//#elif defined(ATMEGA_USART{{ id }}) +// last_rx_error = usr & ((1 << FE{{ id }}) | (1 << DOR{{ id }})); +//#elif defined (ATMEGA_UART) +// last_rx_error = usr & ((1 << FE) | (1 << DOR)); +//#endif + + // TODO Fehlerbehandlung + rxBuffer.push(data); +} + +// ---------------------------------------------------------------------------- +void +xpcc::Uart{{ id }}::setBaudrateRegister(uint16_t ubrr) +{ +{% if id == 0 -%} +#if defined(ATMEGA_UART) + + // set baud rate + if (ubrr & 0x8000) { + UART0_STATUS = (1 << U2X); //Enable 2x speed + ubrr &= ~0x8000; + } + else { + UART0_STATUS = 0; + } + UBRRHI = (uint8_t) (ubrr >> 8); + UBRR = (uint8_t) ubrr; + + // Enable UART receiver and transmitter and receive complete interrupt + UART0_CONTROL = (1 << RXCIE) | (1 << RXEN) | (1 << TXEN); + +#elif defined(ATMEGA_USART) + + // Set baudrate + if (ubrr & 0x8000) { + UART0_STATUS = (1 << U2X); // Enable 2x speed + ubrr &= ~0x8000; + } + else { + UART0_STATUS = 0; + } + UBRRH = (uint8_t) (ubrr >> 8); + UBRRL = (uint8_t) ubrr; + + // Enable USART receiver and transmitter and receive complete interrupt + UART0_CONTROL = (1 << RXCIE) | (1<> 8); + UBRR0L = (uint8_t) ubrr; + + // Enable USART receiver and transmitter and receive complete interrupt + UART0_CONTROL = (1 << RXCIE0) | (1 << RXEN0) | (1 << TXEN0); + + // Set frame format: asynchronous, 8data, no parity, 1stop bit + #ifdef URSEL0 + UCSR0C = (1 << URSEL0) | (3 << UCSZ00); + #else + UCSR0C = (3 << UCSZ00); + #endif +{% if id == 0 %} +#endif +{% endif -%} +} + +// ---------------------------------------------------------------------------- +bool +xpcc::Uart{{ id }}::get(char& c) +{ + if (rxBuffer.isEmpty()) { + return false; + } + else { + c = rxBuffer.get(); + rxBuffer.pop(); + + return true; + } +} + diff --git a/src/xpcc/hal/peripheral/atmega/uart/uartn.hpp.tmpl b/src/xpcc/hal/peripheral/atmega/uart/uartn.hpp.tmpl new file mode 100644 index 000000000..6c32f59e4 --- /dev/null +++ b/src/xpcc/hal/peripheral/atmega/uart/uartn.hpp.tmpl @@ -0,0 +1,72 @@ +// coding: utf-8 +// ---------------------------------------------------------------------------- +/* Copyright (c) 2009, Roboterclub Aachen e.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Roboterclub Aachen e.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id$ + */ +// ---------------------------------------------------------------------------- +{{ generation_block }} + +#ifndef XPCC__UART{{ id }}_HPP +#define XPCC__UART{{ id }}_HPP + +#include "uart.hpp" + +namespace xpcc +{ + class Uart{{ id }} : public Uart + { + public: + static Uart{{ id }}& + instance() { + static Uart{{ id }} uart; + return uart; + } + + virtual void + put(char c); + + using Uart::put; + + virtual bool + get(char& c); + + protected: + virtual void + setBaudrateRegister(uint16_t ubrr); + + Uart{{ id }}() {}; + + Uart{{ id }}(const Uart{{ id }}&); + + Uart{{ id }}& + operator =(const Uart{{ id }} &); + }; +} + +#endif // XPCC__UART{{ id }}_HPP + diff --git a/src/xpcc/hal/peripheral/atmega/uart/uartn_put.cpp.tmpl b/src/xpcc/hal/peripheral/atmega/uart/uartn_put.cpp.tmpl new file mode 100644 index 000000000..f277676e4 --- /dev/null +++ b/src/xpcc/hal/peripheral/atmega/uart/uartn_put.cpp.tmpl @@ -0,0 +1,77 @@ +// coding: utf-8 +// ---------------------------------------------------------------------------- +/* Copyright (c) 2009, Roboterclub Aachen e.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Roboterclub Aachen e.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id$ + */ +// ---------------------------------------------------------------------------- +{{ generation_block }} + +#include +#include + +#include +#include + +#include "uart_defines.h" +#include "uart_defaults.h" + +#include "uart{{ id }}.hpp" + +static xpcc::atomic::Queue txBuffer; + +// ---------------------------------------------------------------------------- +// called when the UART is ready to transmit the next byte + +ISR(UART{{ id }}_TRANSMIT_INTERRUPT) +{ + if (txBuffer.isEmpty()) + { + // transmission finished, disable UDRE interrupt + UART{{ id }}_CONTROL &= ~(1 << UART{{ id }}_UDRIE); + } + else { + // get one byte from buffer and write it to UART (starts transmission) + UART{{ id }}_DATA = txBuffer.get(); + txBuffer.pop(); + } +} + +// ---------------------------------------------------------------------------- +void +xpcc::Uart{{ id }}::put(char c) +{ + while (!txBuffer.push(c)) { + // wait for a free slot in the buffer + } + + atomic::Lock lock; + + // enable UDRE interrupt + UART{{ id }}_CONTROL |= (1 << UART{{ id }}_UDRIE); +} + diff --git a/src/xpcc/hal/peripheral/atxmega/properties.yaml b/src/xpcc/hal/peripheral/atxmega/properties.yaml new file mode 100644 index 000000000..757afbc5f --- /dev/null +++ b/src/xpcc/hal/peripheral/atxmega/properties.yaml @@ -0,0 +1,3 @@ + +target: atxmega + diff --git a/src/xpcc/hal/peripheral/avr/avr.dox b/src/xpcc/hal/peripheral/avr/avr.dox new file mode 100644 index 000000000..c01260b94 --- /dev/null +++ b/src/xpcc/hal/peripheral/avr/avr.dox @@ -0,0 +1,11 @@ +// coding: utf-8 +// +// $Id$ + +/*! +@ingroup hal +@defgroup avr AVR specifiy functions + + + +*/ diff --git a/src/xpcc/hal/avr/cxxabi/cxxabi.cpp b/src/xpcc/hal/peripheral/avr/cpputils/cxxabi.cpp similarity index 77% rename from src/xpcc/hal/avr/cxxabi/cxxabi.cpp rename to src/xpcc/hal/peripheral/avr/cpputils/cxxabi.cpp index 9b0d95afb..f1231d914 100644 --- a/src/xpcc/hal/avr/cxxabi/cxxabi.cpp +++ b/src/xpcc/hal/peripheral/avr/cpputils/cxxabi.cpp @@ -1,11 +1,12 @@ -/** - * \brief Pure-virtual workaround. - * - * The avr-libc does not support a default implementation for handling - * possible pure-virtual calls. This is a short and empty workaround for this. - */ -extern "C" { +extern "C" +{ + /** + * @brief Pure-virtual workaround. + * + * The avr-libc does not support a default implementation for handling + * possible pure-virtual calls. This is a short and empty workaround for this. + */ void __cxa_pure_virtual() { diff --git a/src/xpcc/hal/avr/cxxabi/newdelete.cpp b/src/xpcc/hal/peripheral/avr/cpputils/newdelete.cpp similarity index 91% rename from src/xpcc/hal/avr/cxxabi/newdelete.cpp rename to src/xpcc/hal/peripheral/avr/cpputils/newdelete.cpp index d26938032..3293c07fd 100644 --- a/src/xpcc/hal/avr/cxxabi/newdelete.cpp +++ b/src/xpcc/hal/peripheral/avr/cpputils/newdelete.cpp @@ -29,24 +29,25 @@ */ // ---------------------------------------------------------------------------- -#include "../memory/memory_allocation.hpp" +#include "../ram/allocator.hpp" void * operator new(size_t size) { - return avr::allocateMemory(size); + return xpcc::avr::allocateMemory(size); } void * operator new[](size_t size) { - return avr::allocateMemory(size); + return xpcc::avr::allocateMemory(size); } void operator delete(void* ptr) { - avr::freeMemory(ptr); + xpcc::avr::freeMemory(ptr); } void operator delete[](void* ptr) { - avr::freeMemory(ptr); + xpcc::avr::freeMemory(ptr); } + diff --git a/src/xpcc/hal/peripheral/avr/math/math.hpp b/src/xpcc/hal/peripheral/avr/math/math.hpp new file mode 100644 index 000000000..11b2b675e --- /dev/null +++ b/src/xpcc/hal/peripheral/avr/math/math.hpp @@ -0,0 +1,103 @@ +// coding: utf-8 +// ---------------------------------------------------------------------------- +/* Copyright (c) 2009, Roboterclub Aachen e.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Roboterclub Aachen e.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: math.hpp 75 2009-10-14 22:48:12Z dergraaf $ + */ +// ---------------------------------------------------------------------------- + +#ifndef XPCC_AVR__MATH_HPP +#define XPCC_AVR__MATH_HPP + +#include + +namespace xpcc +{ + namespace avr + { + /** + * @ingroup avr + * @brief Fast and short 32 bits sqrt routine + * + * Quadratwurzel basierend auf einer Implementierung von Ruud v Gessel, + * die zusammen mit avr-gcc verwendet werden kann. Je nach Algorithmus + * wird das Ergebnis zum Nächsten gerundet oder abgerundet. Abrunden + * ist dann angesagt, wenn die Wurzel aus einer großen Eingabe wie + * 0xffffffff zu ziehen ist, da bei Aufrunden hier das Ergebnis + * zu 0 überläuft. + * + * Die Ausführungszeit ist maximal 310 Ticks (inclusive CALL+RET) + * + * @see http://www.mikrocontroller.net/articles/AVR_Arithmetik#avr-gcc_Implementierung_.2832_Bit.29 + * @see http://members.chello.nl/j.beentjes3/Ruud/sqrt32avr.htm + */ + extern "C" uint16_t + sqrt32_round(uint32_t); + + /** + * @ingroup avr + */ + extern "C" uint16_t + sqrt32_floor(uint32_t); + + /** + * @ingroup avr + * @brief unsigned 16bit x 16bit = 32bit multiplication + * + * @see AVR201 + */ + inline uint32_t + mul32(uint16_t a, uint16_t b); + + /** + * @ingroup avr + * @brief signed 16bit x 16bit = 32bit multiplication + * + * @see AVR201 + */ + inline int32_t + mul32(int16_t a, int16_t b); + + /** + * @ingroup avr + * @brief Signed multiply accumulate of two 16bits numbers with + * a 32bits result + * + * @verbatim + * result += a * b; + * @endverbatim + * + * @see AVR201 + */ + inline int32_t + mac32(int32_t result, int16_t a, int16_t b); + } +} + +#include "math_impl.hpp" + +#endif // XPCC_AVR__MATH_HPP diff --git a/src/xpcc/hal/avr/math/math.hpp b/src/xpcc/hal/peripheral/avr/math/math_impl.hpp similarity index 75% rename from src/xpcc/hal/avr/math/math.hpp rename to src/xpcc/hal/peripheral/avr/math/math_impl.hpp index d64cc1d92..9803f32a5 100644 --- a/src/xpcc/hal/avr/math/math.hpp +++ b/src/xpcc/hal/peripheral/avr/math/math_impl.hpp @@ -26,48 +26,16 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: math.hpp 75 2009-10-14 22:48:12Z dergraaf $ + * $Id$ */ // ---------------------------------------------------------------------------- -#ifndef AVR__MATH_HPP -#define AVR__MATH_HPP +#ifndef XPCC_AVR__MATH_HPP + #error "Don't include this file directly, use 'math.hpp' instead!" +#endif -#include - -namespace avr -{ - -/** - * \brief Fast and short 32 bits sqrt routine - * - * Quadratwurzel basierend auf einer Implementierung von Ruud v Gessel, - * die zusammen mit avr-gcc verwendet werden kann. Je nach Algorithmus wird - * das Ergebnis zum Nächsten gerundet oder abgerundet. Abrunden ist dann - * angesagt, wenn die Wurzel aus einer großen Eingabe wie 0xffffffff zu - * ziehen ist, da bei Aufrunden hier das Ergebnis zu 0 überläuft. - * - * Die Ausführungszeit ist maximal 310 Ticks (inclusive CALL+RET) - * - * \see http://www.mikrocontroller.net/articles/AVR_Arithmetik#avr-gcc_Implementierung_.2832_Bit.29 - * \see http://members.chello.nl/j.beentjes3/Ruud/sqrt32avr.htm - */ -extern "C" uint16_t -sqrt32_round(uint32_t); - -/** - * - */ -extern "C" uint16_t -sqrt32_floor(uint32_t); - -/** - * \brief unsigned 16bit x 16bit = 32bit multiplication - * - * \see AVR201 - */ inline uint32_t -mul32(uint16_t a, uint16_t b) +xpcc::avr::mul32(uint16_t a, uint16_t b) { uint32_t result; asm( @@ -92,13 +60,8 @@ mul32(uint16_t a, uint16_t b) return result; } -/** - * \brief signed 16bit x 16bit = 32bit multiplication - * - * \see AVR201 - */ inline int32_t -mul32(int16_t a, int16_t b) +xpcc::avr::mul32(int16_t a, int16_t b) { int32_t result; int8_t help_reg; @@ -134,18 +97,8 @@ mul32(int16_t a, int16_t b) return result; } -/** - * \brief Signed multiply accumulate of two 16bits numbers with - * a 32bits result - * - * \verbatim - * result += a * b; - * \endverbatim - * - * \see AVR201 - */ inline int32_t -mac32(int32_t result, int16_t a, int16_t b) +xpcc::avr::mac32(int32_t result, int16_t a, int16_t b) { int8_t help_reg; @@ -183,7 +136,3 @@ mac32(int32_t result, int16_t a, int16_t b) return result; } - -} - -#endif // AVR__MATH_HPP diff --git a/src/xpcc/hal/avr/math/sqrt32_floor.S b/src/xpcc/hal/peripheral/avr/math/sqrt32_floor.S similarity index 100% rename from src/xpcc/hal/avr/math/sqrt32_floor.S rename to src/xpcc/hal/peripheral/avr/math/sqrt32_floor.S diff --git a/src/xpcc/hal/avr/math/sqrt32_round.S b/src/xpcc/hal/peripheral/avr/math/sqrt32_round.S similarity index 100% rename from src/xpcc/hal/avr/math/sqrt32_round.S rename to src/xpcc/hal/peripheral/avr/math/sqrt32_round.S diff --git a/src/xpcc/hal/peripheral/avr/properties.yaml b/src/xpcc/hal/peripheral/avr/properties.yaml new file mode 100644 index 000000000..3d7cdf051 --- /dev/null +++ b/src/xpcc/hal/peripheral/avr/properties.yaml @@ -0,0 +1,5 @@ + +target: + - atmega + - atxmega + diff --git a/src/xpcc/hal/avr/memory/memory_allocation.cpp b/src/xpcc/hal/peripheral/avr/ram/allocator.cpp similarity index 97% rename from src/xpcc/hal/avr/memory/memory_allocation.cpp rename to src/xpcc/hal/peripheral/avr/ram/allocator.cpp index 440a8e85a..c2a171d23 100644 --- a/src/xpcc/hal/avr/memory/memory_allocation.cpp +++ b/src/xpcc/hal/peripheral/avr/ram/allocator.cpp @@ -29,7 +29,7 @@ */ // ---------------------------------------------------------------------------- -#include "memory_allocation.hpp" +#include "allocator.hpp" #include #include @@ -92,7 +92,7 @@ void initializeMemory(void) * TODO description */ void * -avr::allocateMemory(size_t requestedSize) +xpcc::avr::allocateMemory(size_t requestedSize) { if (requestedSize == 0 || requestedSize > MAX_BLOCK_PARTS * BLOCK_SIZE) @@ -171,7 +171,7 @@ avr::allocateMemory(size_t requestedSize) // ---------------------------------------------------------------------------- void -avr::freeMemory(void *ptr) +xpcc::avr::freeMemory(void *ptr) { if (ptr == 0) { return; @@ -254,13 +254,13 @@ printMemoryLayout(void) void * allocate(size_t size) { - return avr::allocateMemory(size); + return xpcc::avr::allocateMemory(size); } void release(void *p) { - avr::freeMemory(p); + xpcc::avr::freeMemory(p); } int diff --git a/src/xpcc/hal/avr/memory/memory_allocation.hpp b/src/xpcc/hal/peripheral/avr/ram/allocator.hpp similarity index 85% rename from src/xpcc/hal/avr/memory/memory_allocation.hpp rename to src/xpcc/hal/peripheral/avr/ram/allocator.hpp index 39b34643a..867cfd672 100644 --- a/src/xpcc/hal/avr/memory/memory_allocation.hpp +++ b/src/xpcc/hal/peripheral/avr/ram/allocator.hpp @@ -29,22 +29,25 @@ */ // ---------------------------------------------------------------------------- -#ifndef AVR__MEMORY_ALLOCATION_HPP -#define AVR__MEMORY_ALLOCATION_HPP +#ifndef XPCC_AVR__ALLOCATOR_HPP +#define XPCC_AVR__ALLOCATOR_HPP #include -#include +#include // for size_t -namespace avr +namespace xpcc { - void * - allocateMemory(size_t requestedSize); - - void - freeMemory(void *ptr); - - // TODO functions to retrieve status informations about used memory + namespace avr + { + void * + allocateMemory(size_t requestedSize); + + void + freeMemory(void *ptr); + + // TODO functions to retrieve status informations about used memory + } } -#endif // AVR__MEMORY_ALLOCATION_HPP +#endif // XPCC_AVR__ALLOCATOR_HPP diff --git a/src/xpcc/math/cartesian_coordinate_impl.hpp b/src/xpcc/math/cartesian_coordinate_impl.hpp index ee364a158..ae69e0645 100644 --- a/src/xpcc/math/cartesian_coordinate_impl.hpp +++ b/src/xpcc/math/cartesian_coordinate_impl.hpp @@ -34,6 +34,10 @@ #error "Don't include this file directly use 'math/cartesian_coordinate.hpp' instead!" #endif +#if defined(__AVR__) && defined(__AVR_HAVE_MUL__) +#include +#endif + namespace xpcc { // ------------------------------------------------------------------------ @@ -95,8 +99,6 @@ namespace xpcc } #if defined(__AVR__) && defined(__AVR_HAVE_MUL__) -#include - template<> int16_t CartesianCoordinate::getLength() const diff --git a/tests/hal/avr/uart_test.cpp b/tests/hal/avr/uart_test.cpp index 7dedd3783..2a2e4f06d 100644 --- a/tests/hal/avr/uart_test.cpp +++ b/tests/hal/avr/uart_test.cpp @@ -14,7 +14,6 @@ int main(void) sei(); - //uart.setBaudrate(UART_BAUD_SELECT(9600UL, F_CPU)); uart.setBaudrate(9600); uart.put('a'); uart.put('\n');