2014-07-15 12:10:14 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
|
2015-07-16 09:31:12 +02:00
|
|
|
* 2015 Kaspar Schleiser <kaspar@schleiser.de>
|
2014-07-15 12:10:14 +02:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-02-12 13:34:50 +01:00
|
|
|
* @ingroup boards_arduino-mega2560
|
2014-07-15 12:10:14 +02:00
|
|
|
* @{
|
|
|
|
*
|
2015-05-22 07:34:41 +02:00
|
|
|
* @file
|
2014-07-15 12:10:14 +02:00
|
|
|
* @brief Board specific implementations for the Arduino Mega 2560 board
|
|
|
|
*
|
|
|
|
* @author Hinnerk van Bruinehsen <h.v.bruinehsen@fu-berlin.de>
|
2015-07-16 09:31:12 +02:00
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
2014-07-15 12:10:14 +02:00
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <avr/io.h>
|
|
|
|
|
|
|
|
#include "board.h"
|
|
|
|
#include "cpu.h"
|
2015-06-09 13:09:28 +02:00
|
|
|
#include "uart_stdio.h"
|
2014-07-15 12:10:14 +02:00
|
|
|
|
|
|
|
void led_init(void);
|
|
|
|
void SystemInit(void);
|
2015-08-11 10:21:25 +02:00
|
|
|
static int uart_putchar(char c, FILE *stream);
|
|
|
|
static int uart_getchar(FILE *stream);
|
2014-07-15 12:10:14 +02:00
|
|
|
|
|
|
|
static FILE uart_stdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
|
|
|
|
static FILE uart_stdin = FDEV_SETUP_STREAM(NULL, uart_getchar, _FDEV_SETUP_READ);
|
|
|
|
|
|
|
|
void board_init(void)
|
|
|
|
{
|
|
|
|
/* initialize stdio via USART_0 */
|
|
|
|
SystemInit();
|
|
|
|
|
|
|
|
/* initialize the CPU */
|
|
|
|
cpu_init();
|
|
|
|
|
|
|
|
/* initialize the boards LEDs */
|
|
|
|
led_init();
|
|
|
|
|
|
|
|
enableIRQ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize the boards on-board LED (Amber LED "L")
|
|
|
|
*
|
|
|
|
* The LED initialization is hard-coded in this function. As the LED is soldered
|
|
|
|
* onto the board it is fixed to its CPU pins.
|
|
|
|
*
|
|
|
|
* The LED is connected to the following pin:
|
|
|
|
* - LED: PB27
|
|
|
|
*/
|
|
|
|
void led_init(void)
|
|
|
|
{
|
|
|
|
LED_ENABLE_PORT;
|
|
|
|
LED_ON;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize the System, initialize IO via UART_0
|
|
|
|
*/
|
|
|
|
void SystemInit(void)
|
|
|
|
{
|
|
|
|
/* initialize UART_0 for use as stdout */
|
2015-06-09 13:09:28 +02:00
|
|
|
uart_stdio_init();
|
2014-07-15 12:10:14 +02:00
|
|
|
|
|
|
|
stdout = &uart_stdout;
|
|
|
|
stdin = &uart_stdin;
|
|
|
|
|
|
|
|
/* Flush stdout */
|
|
|
|
puts("\f");
|
|
|
|
}
|
|
|
|
|
2015-08-11 10:21:25 +02:00
|
|
|
static int uart_putchar(char c, FILE *stream)
|
2014-07-15 12:10:14 +02:00
|
|
|
{
|
2015-11-28 14:12:55 +01:00
|
|
|
(void) stream;
|
2015-06-09 13:09:28 +02:00
|
|
|
uart_stdio_write(&c, 1);
|
2014-07-15 12:10:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-11 10:21:25 +02:00
|
|
|
int uart_getchar(FILE *stream)
|
2014-07-15 12:10:14 +02:00
|
|
|
{
|
2015-11-28 14:12:55 +01:00
|
|
|
(void) stream;
|
2015-06-09 13:09:28 +02:00
|
|
|
char c;
|
|
|
|
uart_stdio_read(&c, 1);
|
|
|
|
return (int)c;
|
2014-07-15 12:10:14 +02:00
|
|
|
}
|