Subversion Repositories HomeAutomation

Rev

Rev 29 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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