Mercurial > templog
annotate network/clock.c @ 108:b523761181f5 avr-http
Add some replacement functions for testing
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 15 Sep 2012 21:43:15 +0800 |
parents | 56d09a0969b5 |
children |
rev | line source |
---|---|
107
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 #include <stdint.h> |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
2 #include <stdlib.h> |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 #include <stdio.h> |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
4 #include <avr/interrupt.h> |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
5 #include <avr/io.h> |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
6 #include <avr/sfr_defs.h> |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
7 |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
8 #include "clock.h" |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
9 |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
10 //Counted time |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
11 volatile clock_time_t clock_datetime = 0; |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
12 |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
13 //Overflow interrupt |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
14 ISR(TIMER0_COMPA_vect) |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
15 { |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
16 clock_datetime += 1; |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
17 } |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
19 //Initialise the clock |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
20 void clock_init() |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
21 { |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
22 // 10ms tick interval |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 OCR0A = ((F_CPU / 1024) / 100); |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 TCCR0A = (1 << WGM01); |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 TCCR0B = ((1 << CS02) | (1 << CS00)); |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
26 TIMSK0 = (1 << OCIE0A); |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 } |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 //Return time |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 clock_time_t clock_time() |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 { |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
32 clock_time_t time; |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
33 |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 ATOMIC_BLOCK(ATOMIC_FORCEON) |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
35 { |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
36 time = clock_datetime; |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
37 } |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
38 |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
39 return time; |
56d09a0969b5
Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
40 } |