comparison network/clock.c @ 107:56d09a0969b5 avr-http

Import uIP and the PPP implementation from https://code.google.com/p/avrusbmodem/
author Matt Johnston <matt@ucc.asn.au>
date Fri, 07 Sep 2012 23:53:53 +0800
parents
children
comparison
equal deleted inserted replaced
106:5c8404549cc0 107:56d09a0969b5
1 #include <stdint.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <avr/interrupt.h>
5 #include <avr/io.h>
6 #include <avr/sfr_defs.h>
7
8 #include "clock.h"
9
10 //Counted time
11 volatile clock_time_t clock_datetime = 0;
12
13 //Overflow interrupt
14 ISR(TIMER0_COMPA_vect)
15 {
16 clock_datetime += 1;
17 }
18
19 //Initialise the clock
20 void clock_init()
21 {
22 // 10ms tick interval
23 OCR0A = ((F_CPU / 1024) / 100);
24 TCCR0A = (1 << WGM01);
25 TCCR0B = ((1 << CS02) | (1 << CS00));
26 TIMSK0 = (1 << OCIE0A);
27 }
28
29 //Return time
30 clock_time_t clock_time()
31 {
32 clock_time_t time;
33
34 ATOMIC_BLOCK(ATOMIC_FORCEON)
35 {
36 time = clock_datetime;
37 }
38
39 return time;
40 }