Amir Chaudhary
/
LoRaWAN-hello-world_new_mcu_Anish
new code ani
system/timer.cpp@1:352f608c3337, 2015-11-26 (annotated)
- Committer:
- mluis
- Date:
- Thu Nov 26 12:59:52 2015 +0000
- Revision:
- 1:352f608c3337
- Child:
- 5:1e9f6a365854
Changed application architecture to mimic GitHub LoRaMac-node repository.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mluis | 1:352f608c3337 | 1 | /* |
mluis | 1:352f608c3337 | 2 | / _____) _ | | |
mluis | 1:352f608c3337 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
mluis | 1:352f608c3337 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
mluis | 1:352f608c3337 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
mluis | 1:352f608c3337 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
mluis | 1:352f608c3337 | 7 | (C)2013 Semtech |
mluis | 1:352f608c3337 | 8 | |
mluis | 1:352f608c3337 | 9 | Description: Timer objects and scheduling management |
mluis | 1:352f608c3337 | 10 | |
mluis | 1:352f608c3337 | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
mluis | 1:352f608c3337 | 12 | |
mluis | 1:352f608c3337 | 13 | Maintainer: Miguel Luis and Gregory Cristian |
mluis | 1:352f608c3337 | 14 | */ |
mluis | 1:352f608c3337 | 15 | #include "board.h" |
mluis | 1:352f608c3337 | 16 | |
mluis | 1:352f608c3337 | 17 | Timer TimeCounter; |
mluis | 1:352f608c3337 | 18 | Ticker LoadTimeCounter; |
mluis | 1:352f608c3337 | 19 | |
mluis | 1:352f608c3337 | 20 | volatile uint32_t CurrentTime = 0; |
mluis | 1:352f608c3337 | 21 | |
mluis | 1:352f608c3337 | 22 | void TimerResetTimeCounter( void ) |
mluis | 1:352f608c3337 | 23 | { |
mluis | 1:352f608c3337 | 24 | CurrentTime = CurrentTime + TimeCounter.read_us( ); |
mluis | 1:352f608c3337 | 25 | TimeCounter.reset( ); |
mluis | 1:352f608c3337 | 26 | TimeCounter.start( ); |
mluis | 1:352f608c3337 | 27 | } |
mluis | 1:352f608c3337 | 28 | |
mluis | 1:352f608c3337 | 29 | void TimerTimeCounterInit( void ) |
mluis | 1:352f608c3337 | 30 | { |
mluis | 1:352f608c3337 | 31 | TimeCounter.start( ); |
mluis | 1:352f608c3337 | 32 | LoadTimeCounter.attach( &TimerResetTimeCounter, 10 ); |
mluis | 1:352f608c3337 | 33 | } |
mluis | 1:352f608c3337 | 34 | |
mluis | 1:352f608c3337 | 35 | TimerTime_t TimerGetCurrentTime( void ) |
mluis | 1:352f608c3337 | 36 | { |
mluis | 1:352f608c3337 | 37 | CurrentTime += TimeCounter.read_us( ); |
mluis | 1:352f608c3337 | 38 | TimeCounter.reset( ); |
mluis | 1:352f608c3337 | 39 | TimeCounter.start( ); |
mluis | 1:352f608c3337 | 40 | return ( ( TimerTime_t )CurrentTime ); |
mluis | 1:352f608c3337 | 41 | } |
mluis | 1:352f608c3337 | 42 | |
mluis | 1:352f608c3337 | 43 | void TimerInit( TimerEvent_t *obj, void ( *callback )( void ) ) |
mluis | 1:352f608c3337 | 44 | { |
mluis | 1:352f608c3337 | 45 | obj->value = 0; |
mluis | 1:352f608c3337 | 46 | obj->Callback = callback; |
mluis | 1:352f608c3337 | 47 | } |
mluis | 1:352f608c3337 | 48 | |
mluis | 1:352f608c3337 | 49 | void TimerStart( TimerEvent_t *obj ) |
mluis | 1:352f608c3337 | 50 | { |
mluis | 1:352f608c3337 | 51 | obj->Timer.attach_us( obj->Callback, obj->value ); |
mluis | 1:352f608c3337 | 52 | } |
mluis | 1:352f608c3337 | 53 | |
mluis | 1:352f608c3337 | 54 | void TimerStop( TimerEvent_t *obj ) |
mluis | 1:352f608c3337 | 55 | { |
mluis | 1:352f608c3337 | 56 | obj->Timer.detach( ); |
mluis | 1:352f608c3337 | 57 | } |
mluis | 1:352f608c3337 | 58 | |
mluis | 1:352f608c3337 | 59 | void TimerSetValue( TimerEvent_t *obj, uint32_t value ) |
mluis | 1:352f608c3337 | 60 | { |
mluis | 1:352f608c3337 | 61 | obj->value = value; |
mluis | 1:352f608c3337 | 62 | } |