| Remote Access Control |

# timer.c File Reference

## Detailed Description

Source file for timer public and support functions.

This file contains the function implementation for the timer functions. Refer to the timer.h file for more details.

- File: timer.c
- Compiler: IAR EWAVR 4.11B
- Supported devices: ATtiny45/85
- AppNote: AVR411 - Secure Rolling Code Algorithm for Wireless Link

Author:
  Atmel Corporation: http://www.atmel.com
  Support email: avr@atmel.com

Name

Revision
  1193

Date
  2006-10-31 14:21:08 +0100 (ti, 31 okt 2006)

Copyright (c) 2006, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file timer.c.

`#include "timer.h"`
`#include "common.h"`
`#include "config.h"`

Include dependency graph for timer.c:

Go to the source code of this file.

## Defines
#define | SHORT_TIMEOUT_VALUE 100
#define | TIMER_PRESCALER_VALUE ((1<<CS12) | (0<<CS11) | (1<<CS10))
## Functions
__interrupt void | longTimeoutHandler (void)
__interrupt void | shortTimeoutHandler (void)
void | startLongTimeout (void)
void | startShortTimeout (void)
void | stopTimer (void)
## Variables
volatile bool | longTimeout
static byte | longTimeoutHighCounter
volatile bool | shortTimeout

## Define Documentation

#define SHORT_TIMEOUT_VALUE 100

Short timeout delay = 100 = approx. 12.8 ms timeout @ 8 MHz.

Definition at line 57 of file timer.c.

Referenced by startShortTimeout().

#define TIMER_PRESCALER_VALUE ((1<<CS12) | (0<<CS11) | (1<<CS10))

Timeout prescaler = CPUCLK/1024 = approx. 0.128 ms @ 8MHz.

Definition at line 55 of file timer.c.

Referenced by startLongTimeout(), and startShortTimeout().

## Function Documentation

__interrupt void longTimeoutHandler | ( | void |  | ) |

ISR called when one 8.39 second period expires when waiting for a long timeout.

Definition at line 83 of file timer.c.

References LONG_TIMEOUT_LO_VALUE, longTimeout, and longTimeoutHighCounter.

    00084 {
    00085         // Count down.
    00086         if( longTimeoutHighCounter > 0 ) {
    00087                 if( --longTimeoutHighCounter == 0 ) {
    00088                         OCR1B = TCNT1 + LONG_TIMEOUT_LO_VALUE;
    00089                 }
    00090         } else {
    00091                 // Set timeout flag.
    00092                 longTimeout = true;
    00093                 // Disable this interrupt.
    00094                 TIMSK1 &= ~(1<<OCIE1B);
    00095         }
    00096 }

__interrupt void shortTimeoutHandler | ( | void |  | ) |

ISR called when short timeout expires.

Definition at line 71 of file timer.c.

References shortTimeout.

    00072 {
    00073         // Set timeout flag.
    00074         shortTimeout = true;
    00075         // Disable this interrupt.
    00076         TIMSK1 &= ~(1<<OCIE1A);
    00077 }

void startLongTimeout | ( | void |  | ) |

Clear flag and restart long timeout delay.

Definition at line 117 of file timer.c.

References LONG_TIMEOUT_HI_VALUE, longTimeout, longTimeoutHighCounter, and TIMER_PRESCALER_VALUE.

Referenced by learnMode().

    00118 {
    00119         // Clear timeout flag.
    00120         longTimeout = false;
    00121         // Initialize countdown value.
    00122         longTimeoutHighCounter = LONG_TIMEOUT_HI_VALUE;
    00123         // Initialize compare value to one less than
    00124         // current counter value, so that we do not get
    00125         // an interrupt immediately.
    00126         OCR1B = TCNT1 - 1;
    00127         // Clear pending interrupt flag.
    00128         TIFR1 |= (1<<OCF1B);
    00129         // Enable interrupt.
    00130         TIMSK1 |= (1<<OCIE1B);
    00131         // Start timer/counter if not started yet.
    00132         TCCR1B = TIMER_PRESCALER_VALUE;
    00133 }

void startShortTimeout | ( | void |  | ) |

Clear flag and restart short timeout delay.

Definition at line 100 of file timer.c.

References SHORT_TIMEOUT_VALUE, shortTimeout, and TIMER_PRESCALER_VALUE.

Referenced by rxClockLineHandler().

    00101 {
    00102         // Clear timeout flag.
    00103         shortTimeout = false;
    00104         // Initialize compare value relative
    00105         // to current timer value.
    00106         OCR1A = TCNT1 + SHORT_TIMEOUT_VALUE;
    00107         // Clear pending interrupt flag.
    00108         TIFR1 |= (1<<OCF1A);
    00109         // Enable interrupt.
    00110         TIMSK1 |= (1<<OCIE1A);
    00111         // Start timer/counter if not started yet.
    00112         TCCR1B = TIMER_PRESCALER_VALUE;
    00113 }

void stopTimer | ( | void |  | ) |

Stop both timers and clear flags.

Definition at line 137 of file timer.c.

References longTimeout, and shortTimeout.

Referenced by learnMode(), and main().

    00138 {
    00139         TCCR1B = 0x00;
    00140         shortTimeout = false;
    00141         longTimeout = false;
    00142 }

## Variable Documentation

volatile bool longTimeout

Timeout flag set if long timeout occurs.

Definition at line 62 of file timer.c.

Referenced by learnMode(), longTimeoutHandler(), startLongTimeout(), and stopTimer().

byte longTimeoutHighCounter`[static]`

Countdown for high part of long delay.

Definition at line 65 of file timer.c.

Referenced by longTimeoutHandler(), and startLongTimeout().

volatile bool shortTimeout

Timeout flag set if short timeout occurs.

Definition at line 61 of file timer.c.

Referenced by receiverTimedOut(), shortTimeoutHandler(), startShortTimeout(), and stopTimer().

@DOC_TITLE@