aboutsummaryrefslogtreecommitdiff
path: root/kernel/time/mcu/atmega2560/timer.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/time/mcu/atmega2560/timer.c')
-rw-r--r--kernel/time/mcu/atmega2560/timer.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/kernel/time/mcu/atmega2560/timer.c b/kernel/time/mcu/atmega2560/timer.c
index e3ab6eb..eece7a0 100644
--- a/kernel/time/mcu/atmega2560/timer.c
+++ b/kernel/time/mcu/atmega2560/timer.c
@@ -11,7 +11,7 @@ void timer_init() {
TCCR3B = (1 << WGM32); // turn on CTC mode:
TCCR3B |= (1 << CS32) | (0 << CS31) | (1 << CS30); // set to 1024 prescaler
- unsigned int hz_counter = F_CPU / (2 * 1024 * HZ) - 1;
+ unsigned long int hz_counter = ((unsigned long int) F_CPU) / (2 * 1024 * ((unsigned long int) HZ)) - 1;
OCR3A = hz_counter;
sei();
}
@@ -24,10 +24,24 @@ void timer_stop() {
TIMSK3 &= ~(1 << OCIE3A);
}
+#include <avr/io.h>
+void led13(int on) {
+ if (on) {
+ DDRB |= (1 << 7);
+ PORTB |= (1 << 7);
+ } else {
+ DDRB &= ~(1 << 7);
+ PORTB &= ~(1 << 7);
+ }
+}
+
ISR(TIMER3_COMPA_vect, ISR_NAKED) {
SAVE_CONTEXT();
+ static int on = 0;
+ on = !on;
+ led13(on);
sched_tick();
- sei();
RESTORE_CONTEXT();
+ sei();
asm volatile ("reti");
}