Skip to content

Commit 5489eb5

Browse files
committed
Merge branch 'packetbuf2' into uart_net
2 parents 83769e3 + d1a0fbf commit 5489eb5

File tree

151 files changed

+13150
-561
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+13150
-561
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ install:
2222
- sudo apt-get install pcregrep libpcre3
2323
- sudo apt-get install qemu-system-x86 python3
2424
- sudo apt-get install g++-multilib
25+
- sudo apt-get install gcc-avr binutils-avr avr-libc
2526
- git config --global user.email "[email protected]"
2627
- git config --global user.name "Travis CI"
2728

boards/arduino-mega2560/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
MODULE = $(BOARD)_base
2+
3+
include $(RIOTBASE)/Makefile.base
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
# define the cpu used by the arduino mega2560 board
3+
export CPU = atmega2560
4+
5+
# define tools used for building the project
6+
export PREFIX = avr-
7+
export CC = $(PREFIX)gcc
8+
export CXX = $(PREFIX)c++
9+
export AR = $(PREFIX)ar
10+
export AS = $(PREFIX)as
11+
export LINK = $(PREFIX)gcc
12+
export SIZE = $(PREFIX)size
13+
export OBJCOPY = $(PREFIX)objcopy
14+
export TERMPROG = $(RIOTBASE)/dist/tools/pyterm/pyterm
15+
export TERMFLAGS = -b 38400 -p $(PORT)
16+
17+
#define the flash-tool and default port depending on the host operating system
18+
OS = $(shell uname)
19+
ifeq ($(OS),Linux)
20+
PORT ?= /dev/ttyACM0
21+
FLASHER = avrdude
22+
#else ifeq ($(OS),Darwin)
23+
# PORT ?=
24+
# FLASHER =
25+
else
26+
$(info CAUTION: No flash tool for your host system found!)
27+
# TODO: fix for building under windows/MacOS
28+
endif
29+
export FLASHER
30+
export PORT
31+
32+
# define build specific options
33+
export CPU_USAGE = -mmcu=atmega2560
34+
export CFLAGS += -ggdb -g3 -std=gnu99 -Os -Wall -Wstrict-prototypes $(CPU_USAGE)
35+
export ASFLAGS += -ggdb -g3 $(CPU_USAGE) $(FPU_USAGE)
36+
export LINKFLAGS += -g3 -ggdb -std=gnu99 $(CPU_USAGE) $(FPU_USAGE) -static -lgcc -e reset_handler
37+
# linkerscript specified in cpu/Makefile.include
38+
#export LINKFLAGS += -T$(LINKERSCRIPT)
39+
export OFLAGS += -j .text -j .data -O ihex
40+
export FFLAGS += -p m2560 -c stk500v2 -P $(PORT) -b 115200 -F -U flash:w:bin/$(BOARD)/$(PROJECT)$(APPLICATION).hex
41+
42+
# export board specific includes to the global includes-listing
43+
export INCLUDES += -I$(RIOTBOARD)/$(BOARD)/include

boards/arduino-mega2560/board.c

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
/**
10+
* @ingroup board_arduino-mega2560
11+
* @{
12+
*
13+
* @file board.c
14+
* @brief Board specific implementations for the Arduino Mega 2560 board
15+
*
16+
* @author Hinnerk van Bruinehsen <[email protected]>
17+
*
18+
* @}
19+
*/
20+
21+
#include <stdio.h>
22+
#include <avr/io.h>
23+
24+
#include "board.h"
25+
#include "cpu.h"
26+
#include "periph/uart.h"
27+
28+
#ifndef MODULE_UART0
29+
#include "ringbuffer.h"
30+
#include "mutex.h"
31+
#endif
32+
33+
#ifdef MODULE_UART0
34+
#include "board_uart0.h"
35+
#endif
36+
37+
/**
38+
* @brief use mutex for waiting on incoming UART chars
39+
*/
40+
#ifndef MODULE_UART0
41+
static mutex_t uart_rx_mutex;
42+
static char rx_buf_mem[STDIO_RX_BUFSIZE];
43+
static ringbuffer_t rx_buf;
44+
#endif
45+
46+
void led_init(void);
47+
void SystemInit(void);
48+
static int uart_putchar(unsigned char c, FILE *stream);
49+
static char uart_getchar(FILE *stream);
50+
51+
static FILE uart_stdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
52+
static FILE uart_stdin = FDEV_SETUP_STREAM(NULL, uart_getchar, _FDEV_SETUP_READ);
53+
54+
55+
/**
56+
* @brief Receive a new character from the UART and put it into the receive
57+
* buffer
58+
*
59+
* @param[in] data the newly received byte
60+
*/
61+
62+
void rx_cb(void *arg, char data)
63+
{
64+
LED_TOGGLE;
65+
#ifndef MODULE_UART0
66+
ringbuffer_add_one(&rx_buf, data);
67+
mutex_unlock(&uart_rx_mutex);
68+
#elif MODULE_UART0
69+
70+
if (uart0_handler_pid) {
71+
uart0_handle_incoming(data);
72+
uart0_notify_thread();
73+
}
74+
75+
#endif
76+
}
77+
78+
void board_init(void)
79+
{
80+
/* initialize stdio via USART_0 */
81+
SystemInit();
82+
83+
/* initialize the CPU */
84+
cpu_init();
85+
86+
/* initialize the boards LEDs */
87+
led_init();
88+
89+
enableIRQ();
90+
}
91+
92+
93+
/**
94+
* @brief Initialize the boards on-board LED (Amber LED "L")
95+
*
96+
* The LED initialization is hard-coded in this function. As the LED is soldered
97+
* onto the board it is fixed to its CPU pins.
98+
*
99+
* The LED is connected to the following pin:
100+
* - LED: PB27
101+
*/
102+
void led_init(void)
103+
{
104+
LED_ENABLE_PORT;
105+
LED_ON;
106+
}
107+
108+
/**
109+
* @brief Initialize the System, initialize IO via UART_0
110+
*/
111+
void SystemInit(void)
112+
{
113+
/* initialize UART_0 for use as stdout */
114+
#ifndef MODULE_UART0
115+
mutex_init(&uart_rx_mutex);
116+
ringbuffer_init(&rx_buf, rx_buf_mem, STDIO_RX_BUFSIZE);
117+
#endif
118+
uart_init(STDIO, STDIO_BAUDRATE, (uart_rx_cb_t) rx_cb, NULL, NULL);
119+
120+
stdout = &uart_stdout;
121+
stdin = &uart_stdin;
122+
123+
/* Flush stdout */
124+
puts("\f");
125+
}
126+
127+
static int uart_putchar(unsigned char c, FILE *stream)
128+
{
129+
uart_write_blocking(UART_0, c);
130+
return 0;
131+
}
132+
133+
char uart_getchar(FILE *stream)
134+
{
135+
#ifndef MODULE_UART0
136+
137+
if (rx_buf.avail == 0) {
138+
mutex_lock(&uart_rx_mutex);
139+
}
140+
141+
return ringbuffer_get_one(&rx_buf);
142+
#else
143+
LED_TOGGLE;
144+
char temp;
145+
temp = (char) uart0_readc();
146+
return temp;
147+
#endif
148+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
/**
10+
* @defgroup board_arduino-mega2560 Arduino Mega 2560
11+
* @ingroup boards
12+
* @brief Board specific files for the Arduino Mega 2560 board.
13+
* @{
14+
*
15+
* @file
16+
* @brief Board specific definitions for the Arduino Mega 2560 board.
17+
*
18+
* @author Hinnerk van Bruinehsen <[email protected]>
19+
*/
20+
21+
#ifndef __BOARD_H
22+
#define __BOARD_H
23+
24+
#include "cpu.h"
25+
26+
/**
27+
* Define the nominal CPU core clock in this board
28+
*/
29+
#define F_CPU (16000000L)
30+
31+
32+
/**
33+
* Assign the hardware timer
34+
*/
35+
#define HW_TIMER TIMER_0
36+
37+
/**
38+
* @name Define UART device and baudrate for stdio
39+
* @{
40+
*/
41+
#define STDIO UART_0
42+
#define STDIO_BAUDRATE (38400U)
43+
#define STDIO_RX_BUFSIZE (64U)
44+
/** @} */
45+
46+
/**
47+
* @name LED pin definitions
48+
* @{
49+
*/
50+
#define LED_PORT PORTB
51+
#define LED_PIN (1 << 7)
52+
/** @} */
53+
54+
/**
55+
* @name Macros for controlling the on-board LEDs.
56+
* @{
57+
*/
58+
#define LED_ENABLE_PORT DDRB |= (1 << DDB7)
59+
#define LED_ON LED_PORT |= LED_PIN
60+
#define LED_OFF LED_PORT &= ~LED_PIN
61+
#define LED_TOGGLE LED_PORT ^= LED_PIN;
62+
63+
/* for compatability to other boards */
64+
#define LED_GREEN_ON LED_ON
65+
#define LED_GREEN_OFF LED_OFF
66+
#define LED_GREEN_TOGGLE LED_TOGGLE
67+
#define LED_RED_ON /* not available */
68+
#define LED_RED_OFF /* not available */
69+
#define LED_RED_TOGGLE /* not available */
70+
/** @} */
71+
72+
73+
/**
74+
* @brief Initialize board specific hardware, including clock, LEDs and std-IO
75+
*/
76+
void board_init(void);
77+
78+
79+
#endif /** __BOARD_H */
80+
/** @} */

0 commit comments

Comments
 (0)