Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 29 | jimmy | 1 | /****************************************************************************** |
| 2 | * Copyright (C) 2005 Martin THOMAS, Kaiserslautern, Germany |
||
| 3 | * <eversmith@heizung-thomas.de> |
||
| 4 | * http://www.siwawi.arubi.uni-kl.de/avr_projects |
||
| 5 | ***************************************************************************** |
||
| 6 | * |
||
| 7 | * File : timebase.c |
||
| 8 | * Version : 0.9 |
||
| 9 | * |
||
| 10 | * Summary : AVR Timebase using Hardware-Timer 0 |
||
| 11 | * |
||
| 12 | *****************************************************************************/ |
||
| 13 | |||
| 14 | #include <inttypes.h> |
||
| 15 | #include <avr/io.h> |
||
| 16 | #include <avr/signal.h> |
||
| 17 | #include <avr/interrupt.h> |
||
| 18 | |||
| 19 | #include "timebase.h" |
||
| 20 | |||
| 21 | SIGNAL(SIG_OVERFLOW0) |
||
| 22 | { |
||
| 23 | gMilliSecTick++; |
||
| 24 | TCNT0 = TIMEBASE_RELOAD; |
||
| 25 | } |
||
| 26 | |||
| 27 | void timebase_init(void) |
||
| 28 | { |
||
| 29 | TCCR0 = (1<<CS01) | (1<<CS00); // prescaler: 64 |
||
| 30 | TCNT0 = TIMEBASE_RELOAD; // set initial reload-value |
||
| 31 | TIFR |= (1<<TOV0); // clear overflow int. |
||
| 32 | TIMSK |= (1<<TOIE0); // enable overflow-interrupt |
||
| 33 | } |
||
| 34 | |||
| 35 | uint16_t timebase_actTime(void) |
||
| 36 | { |
||
| 37 | uint8_t sreg; |
||
| 38 | uint16_t res; |
||
| 39 | |||
| 40 | sreg=SREG; |
||
| 41 | cli(); |
||
| 42 | |||
| 43 | res = gMilliSecTick; |
||
| 44 | |||
| 45 | SREG=sreg; |
||
| 46 | |||
| 47 | return res; |
||
| 48 | } |
||
| 49 | |||
| 50 | uint16_t timebase_passedTimeMS(uint16_t t0) |
||
| 51 | { |
||
| 52 | uint8_t sreg; |
||
| 53 | uint16_t res; |
||
| 54 | |||
| 55 | sreg=SREG; |
||
| 56 | cli(); |
||
| 57 | |||
| 58 | res = (uint16_t)(gMilliSecTick-t0); |
||
| 59 | |||
| 60 | SREG=sreg; |
||
| 61 | |||
| 62 | return res; |
||
| 63 | } |
||
| 64 | |||
| 65 |