1
0
Fork 0
This repository has been archived on 2019-12-23. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
arduinisten/projekte/protothreads/timer/clock-arch.c

43 lines
632 B
C

// from avr-uip
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/sfr_defs.h>
#include "clock-arch.h"
//Counted time
clock_time_t clock_datetime = 0;
//Overflow itnerrupt
ISR(TIMER0_OVF_vect)
{
clock_datetime += 1;
TIFR0 |= (1<<TOV0);
}
//Initialise the clock
void clock_init(){
//Activate overflow interrupt for timer0
TIMSK0 |= (1<<TOIE0);
//Use prescaler 1024
TCCR0B |= ((1<<CS12)|(1<<CS10));
//Activate interrupts
sei();
}
//Return time
clock_time_t clock_time(){
clock_time_t time;
cli();
time = clock_datetime;
sei();
return time;
}