Commit 972126fd authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Add AVR (Arduino Nano) support

parent bfcfa4cf
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
#ifndef GPIO_H
#define GPIO_H

class GPIO {
	private:
		GPIO(const GPIO &copy);

	public:
		GPIO () {}
		void setup();
		void led_on(unsigned char id);
		void led_off(unsigned char id);
		void led_toggle(unsigned char id);
};

extern GPIO gpio;

#endif
+19 −0
Original line number Diff line number Diff line
#ifndef STANDARDOUTPUT_H
#define STANDANDOUTPUT_H

#include "object/outputstream.h"

class StandardOutput : public OutputStream {
	private:
		StandardOutput(const StandardOutput &copy);

	public:
		StandardOutput () {}
		void setup();

		virtual void put(char c) override;
};

extern StandardOutput kout;

#endif
+29 −0
Original line number Diff line number Diff line
#ifndef UPTIME_H
#define UPTIME_H

#include <avr/io.h>

class Uptime {
	private:
		Uptime(const Uptime &copy);
#ifdef TIMER_S
		uint8_t seconds;
#endif

	public:
#ifdef TIMER_S
		Uptime () : seconds(0) {}
#else
		Uptime () {}
#endif
		inline uint8_t get_cycles() { return TCNT0; }
		inline uint8_t get_us() { return TCNT2/2; }
#ifdef TIMER_S
		inline uint8_t get_s() { return seconds; }
		inline void tick_s() { seconds++; }
#endif
};

extern Uptime uptime;

#endif
+40 −0
Original line number Diff line number Diff line
# vim:ft=make

MCU = atmega328p
PROGRAMMER ?= usbasp

INCLUDES += -Iinclude/arduino-nano
COMMON_FLAGS += -mmcu=${MCU} -DF_CPU=16000000UL

CC = avr-gcc
CXX = avr-g++
NM = avr-nm
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump

TARGETS += src/arch/arduino-nano/arch.cc
TARGETS += src/arch/arduino-nano/driver/gpio.cc
TARGETS += src/arch/arduino-nano/driver/stdout.cc
TARGETS += src/arch/arduino-nano/driver/uptime.cc

OBJECTS = ${TARGETS:.cc=.o}

.cc.o:
	${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc}

build/system.elf: ${OBJECTS}
	${CXX} ${COMMON_FLAGS} ${CXXFLAGS} -Wl,--gc-sections -o $@ ${OBJECTS}

build/system.hex: build/system.elf
	${OBJCOPY} -O ihex ${@:.hex=.elf} $@

program: build/system.hex
	avrdude -p ${MCU} -c arduino -P /dev/ttyUSB0 -b 57600 -U flash:w:build/system.hex

arch_clean:
	rm -f ${OBJECTS} build/system.hex

monitor:
	screen /dev/ttyUSB0 115200

.PHONY: arch_clean monitor program
+58 −0
Original line number Diff line number Diff line
#include "arch.h"
#include <avr/io.h>
#include <avr/interrupt.h>

void Arch::setup(void)
{
#ifdef TIMER_CYCLES
	TCCR0A = 0;
	TCCR0B = _BV(CS00);
#endif

#if defined(WITH_LOOP) || defined(TIMER_S)
	TCCR1A = 0;
	TCCR1B = _BV(WGM12) | _BV(CS12) | _BV(CS10); // /1024
	OCR1A = 15625;
	TIMSK1 = _BV(OCIE1A);
#endif

#ifdef TIMER_US
	// 16MHz/8 -> 2MHz timer
	TCCR2A = 0;
	TCCR2B = _BV(CS21);
#endif
	sei();
}

#if defined(WITH_LOOP) || defined(TIMER_S)

#include "driver/uptime.h"
extern void loop();

#endif

void Arch::idle_loop(void)
{
	while (1) {
		SMCR = _BV(SE);
		asm("sleep");
		SMCR = 0;
		asm("wdr");
#ifdef WITH_LOOP
		loop();
#endif
#ifdef TIMER_S
		uptime.tick_s();
#endif
	}
}

Arch arch;

#if defined(WITH_LOOP) || defined(TIMER_S)

ISR(TIMER1_COMPA_vect)
{
}

#endif
Loading