Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
#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;
...@@ -40,6 +40,10 @@ ifneq ($(findstring timer,${arch_drivers}), ) ...@@ -40,6 +40,10 @@ ifneq ($(findstring timer,${arch_drivers}), )
CXX_TARGETS += src/arch/arduino-nano/driver/timer.cc CXX_TARGETS += src/arch/arduino-nano/driver/timer.cc
endif endif
ifneq ($(findstring counter,${arch_drivers}), )
CXX_TARGETS += src/arch/arduino-nano/driver/counter.cc
endif
ifeq (${cpu_freq}, 16000000) ifeq (${cpu_freq}, 16000000)
uart_baud = 57600 uart_baud = 57600
else ifeq (${cpu_freq}, 8000000) else ifeq (${cpu_freq}, 8000000)
......
...@@ -40,6 +40,10 @@ ifneq ($(findstring timer,${arch_drivers}), ) ...@@ -40,6 +40,10 @@ ifneq ($(findstring timer,${arch_drivers}), )
CXX_TARGETS += src/arch/arduino-nano/driver/timer.cc CXX_TARGETS += src/arch/arduino-nano/driver/timer.cc
endif endif
ifneq ($(findstring counter,${arch_drivers}), )
CXX_TARGETS += src/arch/arduino-nano/driver/counter.cc
endif
ifeq (${cpu_freq}, 16000000) ifeq (${cpu_freq}, 16000000)
uart_baud = 57600 uart_baud = 57600
else ifeq (${cpu_freq}, 8000000) else ifeq (${cpu_freq}, 8000000)
......
#include "driver/counter.h"
Counter counter;
ISR(TIMER1_OVF_vect)
{
if (counter.overflowed < 255) {
counter.overflowed++;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment