Commit ec15c42a authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

arduino-nano: Add counter driver. Conflicts with timer_s=1 / loop=1

parent b2554d7b
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
#include <avr/io.h>
#include <avr/interrupt.h>

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

	public:
		uint8_t overflowed;

		Counter() : overflowed(0) {}

		inline void start() {
			overflowed = 0;
			TCNT1 = 0;
			TCCR1A = 0;
			TCCR1B = _BV(CS10);
			TIMSK1 = _BV(TOIE1);
		}

		inline uint16_t stop() {
			TCCR1B = 0;
			return TCNT1;
		}
};

extern Counter counter;
+4 −0
Original line number Diff line number Diff line
@@ -40,6 +40,10 @@ ifneq ($(findstring timer,${arch_drivers}), )
	CXX_TARGETS += src/arch/arduino-nano/driver/timer.cc
endif

ifneq ($(findstring counter,${arch_drivers}), )
	CXX_TARGETS += src/arch/arduino-nano/driver/counter.cc
endif

ifeq (${cpu_freq}, 16000000)
	uart_baud = 57600
else ifeq (${cpu_freq}, 8000000)
+4 −0
Original line number Diff line number Diff line
@@ -40,6 +40,10 @@ ifneq ($(findstring timer,${arch_drivers}), )
	CXX_TARGETS += src/arch/arduino-nano/driver/timer.cc
endif

ifneq ($(findstring counter,${arch_drivers}), )
	CXX_TARGETS += src/arch/arduino-nano/driver/counter.cc
endif

ifeq (${cpu_freq}, 16000000)
	uart_baud = 57600
else ifeq (${cpu_freq}, 8000000)
+10 −0
Original line number Diff line number Diff line
#include "driver/counter.h"

Counter counter;

ISR(TIMER1_OVF_vect)
{
	if (counter.overflowed < 255) {
		counter.overflowed++;
	}
}