Application LORAWAN : Device STM32L073 +SX1272MB2xAS board
Dependencies: mbed LoRaWAN-lib SX1272Lib
Fork of LoRaWAN-demo-72 by
system/timer.cpp@5:62862ef9480b, 2016-07-05 (annotated)
- Committer:
- mluis
- Date:
- Tue Jul 05 15:00:47 2016 +0000
- Revision:
- 5:62862ef9480b
- Parent:
- 3:3152aa75c58d
- Child:
- 7:5077515c163b
Synchronized example application with GitHub LoRaMac-node examples; Updated mbed, LoRaWAN-lib and SX1272Lib libraries
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mluis | 0:45496a70a8a5 | 1 | /* |
mluis | 0:45496a70a8a5 | 2 | / _____) _ | | |
mluis | 0:45496a70a8a5 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
mluis | 0:45496a70a8a5 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
mluis | 0:45496a70a8a5 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
mluis | 0:45496a70a8a5 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
mluis | 0:45496a70a8a5 | 7 | (C)2013 Semtech |
mluis | 0:45496a70a8a5 | 8 | |
mluis | 0:45496a70a8a5 | 9 | Description: Timer objects and scheduling management |
mluis | 0:45496a70a8a5 | 10 | |
mluis | 0:45496a70a8a5 | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
mluis | 0:45496a70a8a5 | 12 | |
mluis | 0:45496a70a8a5 | 13 | Maintainer: Miguel Luis and Gregory Cristian |
mluis | 0:45496a70a8a5 | 14 | */ |
mluis | 0:45496a70a8a5 | 15 | #include "board.h" |
mluis | 0:45496a70a8a5 | 16 | |
mluis | 0:45496a70a8a5 | 17 | Timer TimeCounter; |
mluis | 0:45496a70a8a5 | 18 | Ticker LoadTimeCounter; |
mluis | 0:45496a70a8a5 | 19 | |
mluis | 5:62862ef9480b | 20 | volatile uint64_t CurrentTime = 0; |
mluis | 0:45496a70a8a5 | 21 | |
mluis | 0:45496a70a8a5 | 22 | void TimerResetTimeCounter( void ) |
mluis | 0:45496a70a8a5 | 23 | { |
mluis | 0:45496a70a8a5 | 24 | CurrentTime = CurrentTime + TimeCounter.read_us( ); |
mluis | 0:45496a70a8a5 | 25 | TimeCounter.reset( ); |
mluis | 0:45496a70a8a5 | 26 | TimeCounter.start( ); |
mluis | 0:45496a70a8a5 | 27 | } |
mluis | 0:45496a70a8a5 | 28 | |
mluis | 0:45496a70a8a5 | 29 | void TimerTimeCounterInit( void ) |
mluis | 0:45496a70a8a5 | 30 | { |
mluis | 0:45496a70a8a5 | 31 | TimeCounter.start( ); |
mluis | 0:45496a70a8a5 | 32 | LoadTimeCounter.attach( &TimerResetTimeCounter, 10 ); |
mluis | 0:45496a70a8a5 | 33 | } |
mluis | 0:45496a70a8a5 | 34 | |
mluis | 0:45496a70a8a5 | 35 | TimerTime_t TimerGetCurrentTime( void ) |
mluis | 0:45496a70a8a5 | 36 | { |
mluis | 0:45496a70a8a5 | 37 | CurrentTime += TimeCounter.read_us( ); |
mluis | 0:45496a70a8a5 | 38 | TimeCounter.reset( ); |
mluis | 0:45496a70a8a5 | 39 | TimeCounter.start( ); |
mluis | 0:45496a70a8a5 | 40 | return ( ( TimerTime_t )CurrentTime ); |
mluis | 0:45496a70a8a5 | 41 | } |
mluis | 0:45496a70a8a5 | 42 | |
mluis | 3:3152aa75c58d | 43 | TimerTime_t TimerGetElapsedTime( TimerTime_t savedTime ) |
mluis | 3:3152aa75c58d | 44 | { |
mluis | 3:3152aa75c58d | 45 | CurrentTime += TimeCounter.read_us( ); |
mluis | 3:3152aa75c58d | 46 | TimeCounter.reset( ); |
mluis | 3:3152aa75c58d | 47 | TimeCounter.start( ); |
mluis | 3:3152aa75c58d | 48 | return ( TimerTime_t )( CurrentTime - savedTime ); |
mluis | 3:3152aa75c58d | 49 | } |
mluis | 3:3152aa75c58d | 50 | |
mluis | 3:3152aa75c58d | 51 | TimerTime_t TimerGetFutureTime( TimerTime_t eventInFuture ) |
mluis | 3:3152aa75c58d | 52 | { |
mluis | 3:3152aa75c58d | 53 | CurrentTime += TimeCounter.read_us( ); |
mluis | 3:3152aa75c58d | 54 | TimeCounter.reset( ); |
mluis | 3:3152aa75c58d | 55 | TimeCounter.start( ); |
mluis | 3:3152aa75c58d | 56 | return ( TimerTime_t )( CurrentTime + eventInFuture ); |
mluis | 3:3152aa75c58d | 57 | } |
mluis | 3:3152aa75c58d | 58 | |
mluis | 0:45496a70a8a5 | 59 | void TimerInit( TimerEvent_t *obj, void ( *callback )( void ) ) |
mluis | 0:45496a70a8a5 | 60 | { |
mluis | 0:45496a70a8a5 | 61 | obj->value = 0; |
mluis | 0:45496a70a8a5 | 62 | obj->Callback = callback; |
mluis | 0:45496a70a8a5 | 63 | } |
mluis | 0:45496a70a8a5 | 64 | |
mluis | 0:45496a70a8a5 | 65 | void TimerStart( TimerEvent_t *obj ) |
mluis | 0:45496a70a8a5 | 66 | { |
mluis | 0:45496a70a8a5 | 67 | obj->Timer.attach_us( obj->Callback, obj->value ); |
mluis | 0:45496a70a8a5 | 68 | } |
mluis | 0:45496a70a8a5 | 69 | |
mluis | 0:45496a70a8a5 | 70 | void TimerStop( TimerEvent_t *obj ) |
mluis | 0:45496a70a8a5 | 71 | { |
mluis | 0:45496a70a8a5 | 72 | obj->Timer.detach( ); |
mluis | 0:45496a70a8a5 | 73 | } |
mluis | 0:45496a70a8a5 | 74 | |
mluis | 0:45496a70a8a5 | 75 | void TimerSetValue( TimerEvent_t *obj, uint32_t value ) |
mluis | 0:45496a70a8a5 | 76 | { |
mluis | 0:45496a70a8a5 | 77 | obj->value = value; |
mluis | 0:45496a70a8a5 | 78 | } |