Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90350158
Systime.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Oct 31, 20:21
Size
1008 B
Mime Type
text/x-c
Expires
Sat, Nov 2, 20:21 (2 d)
Engine
blob
Format
Raw Data
Handle
22057795
Attached To
R7582 FORmicidae Tracker - Communication Protocol Implementations - libarke
Systime.c
View Options
#include "arke-avr.h"
#include <avr/io.h>
#include <avr/interrupt.h>
volatile
ArkeSystime_t
systime
;
#if defined(__AVR_ATmega16m1__)
#define START_TIMER0_1ms() do{ \
TCCR0A = _BV(WGM01); \
TCCR0B = _BV(CS01) | _BV(CS00); \
}while(0)
#define OCIE0A_ENABLE() TIMSK0 = _BV(OCIE0A)
#define OCIE0A_DISABLE() TIMSK0 = _BV(OCIE0A)
#define LIBARKE_TIMER0_COMPA_VECT TIMER0_COMPA_vect
#elif defined(__AVR_AT90CAN128__)
#define START_TIMER0_1ms() do{ \
TCCR0A = _BV(WGM01) | _BV(CS01) | _BV(CS00); \
}while(0)
#define OCIE0A_ENABLE() TIMSK0 = _BV(OCIE0A)
#define OCIE0A_DISABLE() TIMSK0 = _BV(OCIE0A)
#define LIBARKE_TIMER0_COMPA_VECT TIMER0_COMP_vect
#else
#error "Unssuported AVR device"
#endif
void
ArkeInitSystime
()
{
systime
=
0
;
//frequency 16MHz/ ( N * (1+OCRnA))
OCR0A
=
249
;
OCIE0A_ENABLE
();
START_TIMER0_1ms
();
sei
();
}
ISR
(
LIBARKE_TIMER0_COMPA_VECT
)
{
++
systime
;
}
ArkeSystime_t
ArkeGetSystime
()
{
OCIE0A_DISABLE
();
ArkeSystime_t
res
=
systime
;
OCIE0A_ENABLE
();
return
res
;
}
Event Timeline
Log In to Comment