1234567891011121314151617181920212223242526272829303132333435363738 |
- /*
- * Time-Keeping helper
- */
-
- #include <avr/io.h>
- #include <avr/interrupt.h>
-
- #include "timer.h"
-
- volatile time_t systemTime = 0;
-
- void timerInit(void) {
- #ifdef DEBUG
- TCCR2A |= (1 << WGM21); // CTC Mode
- TCCR2B |= (1 << CS22); // Prescaler: 64
- OCR2A = 250; // Count to 250
- TIMSK2 |= (1 << OCIE2A); // Enable compare match interrupt
- #else
- // Using 8bit Timer1
- TCCR1 |= (1 << CTC1); // CTC Mode
- TCCR1 |= (1 << CS12) | (1 << CS11) | (1 << CS10); // Prescaler: 64
- OCR1A = 250; // Count to 250
- TIMSK |= (1 << OCIE1A); // Enable compare match interrupt
- #endif
- }
-
- #ifdef DEBUG
- ISR(TIMER2_COMPA_vect) {
- #else
- ISR(TIMER1_COMPA_vect) {
- #endif
- systemTime++; // one millisecond has passed
- }
-
- time_t timerGet(void) {
- return systemTime;
- }
|