LoRa send is causing hang-up when a gps fix is acquired
Dependencies: mbed LoRaWAN-lib_publishing_testing_UART_bug SingleFrequencyLora
Fork of simple-demo-76_revised_20171113_copy by
system/timer.cpp@5:1e9f6a365854, 2016-05-13 (annotated)
- Committer:
- mluis
- Date:
- Fri May 13 15:15:13 2016 +0000
- Revision:
- 5:1e9f6a365854
- Parent:
- 1:352f608c3337
- Child:
- 7:3173f0508a98
Updated mbed, LoRaWAN-lib and SX1276Lib libraries.
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 | 5:1e9f6a365854 | 43 | TimerTime_t TimerGetElapsedTime( TimerTime_t savedTime ) |
mluis | 5:1e9f6a365854 | 44 | { |
mluis | 5:1e9f6a365854 | 45 | CurrentTime += TimeCounter.read_us( ); |
mluis | 5:1e9f6a365854 | 46 | TimeCounter.reset( ); |
mluis | 5:1e9f6a365854 | 47 | TimeCounter.start( ); |
mluis | 5:1e9f6a365854 | 48 | return ( TimerTime_t )( CurrentTime - savedTime ); |
mluis | 5:1e9f6a365854 | 49 | } |
mluis | 5:1e9f6a365854 | 50 | |
mluis | 5:1e9f6a365854 | 51 | TimerTime_t TimerGetFutureTime( TimerTime_t eventInFuture ) |
mluis | 5:1e9f6a365854 | 52 | { |
mluis | 5:1e9f6a365854 | 53 | CurrentTime += TimeCounter.read_us( ); |
mluis | 5:1e9f6a365854 | 54 | TimeCounter.reset( ); |
mluis | 5:1e9f6a365854 | 55 | TimeCounter.start( ); |
mluis | 5:1e9f6a365854 | 56 | return ( TimerTime_t )( CurrentTime + eventInFuture ); |
mluis | 5:1e9f6a365854 | 57 | } |
mluis | 5:1e9f6a365854 | 58 | |
mluis | 1:352f608c3337 | 59 | void TimerInit( TimerEvent_t *obj, void ( *callback )( void ) ) |
mluis | 1:352f608c3337 | 60 | { |
mluis | 1:352f608c3337 | 61 | obj->value = 0; |
mluis | 1:352f608c3337 | 62 | obj->Callback = callback; |
mluis | 1:352f608c3337 | 63 | } |
mluis | 1:352f608c3337 | 64 | |
mluis | 1:352f608c3337 | 65 | void TimerStart( TimerEvent_t *obj ) |
mluis | 1:352f608c3337 | 66 | { |
mluis | 1:352f608c3337 | 67 | obj->Timer.attach_us( obj->Callback, obj->value ); |
mluis | 1:352f608c3337 | 68 | } |
mluis | 1:352f608c3337 | 69 | |
mluis | 1:352f608c3337 | 70 | void TimerStop( TimerEvent_t *obj ) |
mluis | 1:352f608c3337 | 71 | { |
mluis | 1:352f608c3337 | 72 | obj->Timer.detach( ); |
mluis | 1:352f608c3337 | 73 | } |
mluis | 1:352f608c3337 | 74 | |
mluis | 1:352f608c3337 | 75 | void TimerSetValue( TimerEvent_t *obj, uint32_t value ) |
mluis | 1:352f608c3337 | 76 | { |
mluis | 1:352f608c3337 | 77 | obj->value = value; |
mluis | 1:352f608c3337 | 78 | } |