mQ Branch for NA mote testing
Dependencies: LoRaWAN-lib SX1272Lib-mQ lib_gps lib_mma8451q lib_mpl3115a2 mbed
Fork of LoRaWAN-NAMote72-Application-Demo by
system/timer.cpp@2:d119a85c793c, 2016-05-18 (annotated)
- Committer:
- ubhat
- Date:
- Wed May 18 00:44:52 2016 +0000
- Revision:
- 2:d119a85c793c
- Child:
- 18:18408c3c2d0c
Updated to LoRaWAN library 4.2.0 & System files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ubhat | 2:d119a85c793c | 1 | /* |
ubhat | 2:d119a85c793c | 2 | / _____) _ | | |
ubhat | 2:d119a85c793c | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
ubhat | 2:d119a85c793c | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
ubhat | 2:d119a85c793c | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
ubhat | 2:d119a85c793c | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
ubhat | 2:d119a85c793c | 7 | (C)2013 Semtech |
ubhat | 2:d119a85c793c | 8 | |
ubhat | 2:d119a85c793c | 9 | Description: Timer objects and scheduling management |
ubhat | 2:d119a85c793c | 10 | |
ubhat | 2:d119a85c793c | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
ubhat | 2:d119a85c793c | 12 | |
ubhat | 2:d119a85c793c | 13 | Maintainer: Miguel Luis and Gregory Cristian |
ubhat | 2:d119a85c793c | 14 | */ |
ubhat | 2:d119a85c793c | 15 | #include "board.h" |
ubhat | 2:d119a85c793c | 16 | |
ubhat | 2:d119a85c793c | 17 | Timer TimeCounter; |
ubhat | 2:d119a85c793c | 18 | Ticker LoadTimeCounter; |
ubhat | 2:d119a85c793c | 19 | |
ubhat | 2:d119a85c793c | 20 | volatile uint32_t CurrentTime = 0; |
ubhat | 2:d119a85c793c | 21 | |
ubhat | 2:d119a85c793c | 22 | void TimerResetTimeCounter( void ) |
ubhat | 2:d119a85c793c | 23 | { |
ubhat | 2:d119a85c793c | 24 | CurrentTime = CurrentTime + TimeCounter.read_us( ); |
ubhat | 2:d119a85c793c | 25 | TimeCounter.reset( ); |
ubhat | 2:d119a85c793c | 26 | TimeCounter.start( ); |
ubhat | 2:d119a85c793c | 27 | } |
ubhat | 2:d119a85c793c | 28 | |
ubhat | 2:d119a85c793c | 29 | void TimerTimeCounterInit( void ) |
ubhat | 2:d119a85c793c | 30 | { |
ubhat | 2:d119a85c793c | 31 | TimeCounter.start( ); |
ubhat | 2:d119a85c793c | 32 | LoadTimeCounter.attach( &TimerResetTimeCounter, 10 ); |
ubhat | 2:d119a85c793c | 33 | } |
ubhat | 2:d119a85c793c | 34 | |
ubhat | 2:d119a85c793c | 35 | TimerTime_t TimerGetCurrentTime( void ) |
ubhat | 2:d119a85c793c | 36 | { |
ubhat | 2:d119a85c793c | 37 | CurrentTime += TimeCounter.read_us( ); |
ubhat | 2:d119a85c793c | 38 | TimeCounter.reset( ); |
ubhat | 2:d119a85c793c | 39 | TimeCounter.start( ); |
ubhat | 2:d119a85c793c | 40 | return ( ( TimerTime_t )CurrentTime ); |
ubhat | 2:d119a85c793c | 41 | } |
ubhat | 2:d119a85c793c | 42 | |
ubhat | 2:d119a85c793c | 43 | TimerTime_t TimerGetElapsedTime( TimerTime_t savedTime ) |
ubhat | 2:d119a85c793c | 44 | { |
ubhat | 2:d119a85c793c | 45 | CurrentTime += TimeCounter.read_us( ); |
ubhat | 2:d119a85c793c | 46 | TimeCounter.reset( ); |
ubhat | 2:d119a85c793c | 47 | TimeCounter.start( ); |
ubhat | 2:d119a85c793c | 48 | return ( TimerTime_t )( CurrentTime - savedTime ); |
ubhat | 2:d119a85c793c | 49 | } |
ubhat | 2:d119a85c793c | 50 | |
ubhat | 2:d119a85c793c | 51 | TimerTime_t TimerGetFutureTime( TimerTime_t eventInFuture ) |
ubhat | 2:d119a85c793c | 52 | { |
ubhat | 2:d119a85c793c | 53 | CurrentTime += TimeCounter.read_us( ); |
ubhat | 2:d119a85c793c | 54 | TimeCounter.reset( ); |
ubhat | 2:d119a85c793c | 55 | TimeCounter.start( ); |
ubhat | 2:d119a85c793c | 56 | return ( TimerTime_t )( CurrentTime + eventInFuture ); |
ubhat | 2:d119a85c793c | 57 | } |
ubhat | 2:d119a85c793c | 58 | |
ubhat | 2:d119a85c793c | 59 | void TimerInit( TimerEvent_t *obj, void ( *callback )( void ) ) |
ubhat | 2:d119a85c793c | 60 | { |
ubhat | 2:d119a85c793c | 61 | obj->value = 0; |
ubhat | 2:d119a85c793c | 62 | obj->Callback = callback; |
ubhat | 2:d119a85c793c | 63 | } |
ubhat | 2:d119a85c793c | 64 | |
ubhat | 2:d119a85c793c | 65 | void TimerStart( TimerEvent_t *obj ) |
ubhat | 2:d119a85c793c | 66 | { |
ubhat | 2:d119a85c793c | 67 | obj->Timer.attach_us( obj->Callback, obj->value ); |
ubhat | 2:d119a85c793c | 68 | } |
ubhat | 2:d119a85c793c | 69 | |
ubhat | 2:d119a85c793c | 70 | void TimerStop( TimerEvent_t *obj ) |
ubhat | 2:d119a85c793c | 71 | { |
ubhat | 2:d119a85c793c | 72 | obj->Timer.detach( ); |
ubhat | 2:d119a85c793c | 73 | } |
ubhat | 2:d119a85c793c | 74 | |
ubhat | 2:d119a85c793c | 75 | void TimerSetValue( TimerEvent_t *obj, uint32_t value ) |
ubhat | 2:d119a85c793c | 76 | { |
ubhat | 2:d119a85c793c | 77 | obj->value = value; |
ubhat | 2:d119a85c793c | 78 | } |