Subversion Repositories HomeAutomation

Rev

Rev 73 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 73 Rev 127
Line 5... Line 5...
5
 * @target  ATmega8
5
 * @target  ATmega8
6
 *
6
 *
7
 * @author  Martin Thomas
7
 * @author  Martin Thomas
8
 * @author  Jimmy Myhrman
8
 * @author  Jimmy Myhrman
9
 *
9
 *
10
 * @date    2006-10-29
10
 * @date    2006-11-19
11
 */
11
 */
12
 
12
 
13
/*-----------------------------------------------------------------------------
13
/*-----------------------------------------------------------------------------
14
 * Includes
14
 * Includes
15
 *---------------------------------------------------------------------------*/
15
 *---------------------------------------------------------------------------*/
Line 40... Line 40...
40
 *---------------------------------------------------------------------------*/
40
 *---------------------------------------------------------------------------*/
41
/**
41
/**
42
 * Initializes the timebase. The hardware timer interrupt source will be
42
 * Initializes the timebase. The hardware timer interrupt source will be
43
 * enabled, but global interrupts need to be enabled by the application.
43
 * enabled, but global interrupts need to be enabled by the application.
44
 */
44
 */
45
void TimebaseInit() {
45
void Timebase_Init() {
46
    TCCR0 = (1<<CS01) | (1<<CS00); // prescaler: 64
46
    TCCR0 = (1<<CS01) | (1<<CS00); // prescaler: 64
47
    TCNT0 = TIMEBASE_RELOAD; // set initial reload-value
47
    TCNT0 = TIMEBASE_RELOAD; // set initial reload-value
48
    TIFR  |= (1<<TOV0);  // clear overflow int.
48
    TIFR  |= (1<<TOV0);  // clear overflow int.
49
    TIMSK |= (1<<TOIE0); // enable overflow-interrupt
49
    TIMSK |= (1<<TOIE0); // enable overflow-interrupt
50
}
50
}
Line 53... Line 53...
53
 * Reads the current time.
53
 * Reads the current time.
54
 *
54
 *
55
 * @return
55
 * @return
56
 *      The current time in milliseconds (32bit value).
56
 *      The current time in milliseconds (32bit value).
57
 */
57
 */
58
uint32_t TimebaseCurrentTime(void) {
58
uint32_t Timebase_CurrentTime(void) {
59
    uint8_t sreg;
59
    uint8_t sreg;
60
    uint16_t res;
60
    uint16_t res;
61
    sreg=SREG;
61
    sreg=SREG;
62
    cli();
62
    cli();
63
    res = gMilliSecTick;
63
    res = gMilliSecTick;
Line 71... Line 71...
71
 * @param t0
71
 * @param t0
72
 *      The timestamp.
72
 *      The timestamp.
73
 * @return
73
 * @return
74
 *      Number of milliseconds that have passed since t0.
74
 *      Number of milliseconds that have passed since t0.
75
 */
75
 */
76
uint32_t TimebasePassedTimeMS(uint32_t t0) {
76
uint32_t Timebase_PassedTimeMillis(uint32_t t0) {
77
    uint8_t sreg;
77
    uint8_t sreg;
78
    uint16_t res;
78
    uint16_t res;
79
    sreg=SREG;
79
    sreg=SREG;
80
    cli();
80
    cli();
81
    res = (uint16_t)(gMilliSecTick-t0);
81
    res = (uint16_t)(gMilliSecTick-t0);