Bootcamp application example using LoRaWAN-lib MAC layer implementation. Provides an application example controlling a 3 color LED and a light sensor.
Dependencies: mbed Chainable_RGB_LED DigitDisplay LoRaWAN-lib SX1276Lib
For a detailed description of the LoRaWAN operations, please visit the MBED dedicated page at https://developer.mbed.org/teams/Semtech/code/LoRaWAN-demo-76/
system/timer.cpp@3:de1dcfbe175a, 2016-07-05 (annotated)
- Committer:
- mluis
- Date:
- Tue Jul 05 15:02:26 2016 +0000
- Revision:
- 3:de1dcfbe175a
- Parent:
- 1:21e3eef8200f
- Child:
- 5:d87bb1eabccd
Synchronized example application with GitHub LoRaMac-node examples; Updated mbed and LoRaWAN-lib libraries
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mluis | 0:cb80564f40e1 | 1 | /* |
mluis | 0:cb80564f40e1 | 2 | / _____) _ | | |
mluis | 0:cb80564f40e1 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
mluis | 0:cb80564f40e1 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
mluis | 0:cb80564f40e1 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
mluis | 0:cb80564f40e1 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
mluis | 0:cb80564f40e1 | 7 | (C)2013 Semtech |
mluis | 0:cb80564f40e1 | 8 | |
mluis | 0:cb80564f40e1 | 9 | Description: Timer objects and scheduling management |
mluis | 0:cb80564f40e1 | 10 | |
mluis | 0:cb80564f40e1 | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
mluis | 0:cb80564f40e1 | 12 | |
mluis | 0:cb80564f40e1 | 13 | Maintainer: Miguel Luis and Gregory Cristian |
mluis | 0:cb80564f40e1 | 14 | */ |
mluis | 0:cb80564f40e1 | 15 | #include "board.h" |
mluis | 0:cb80564f40e1 | 16 | |
mluis | 0:cb80564f40e1 | 17 | Timer TimeCounter; |
mluis | 0:cb80564f40e1 | 18 | Ticker LoadTimeCounter; |
mluis | 0:cb80564f40e1 | 19 | |
mluis | 3:de1dcfbe175a | 20 | volatile uint64_t CurrentTime = 0; |
mluis | 0:cb80564f40e1 | 21 | |
mluis | 0:cb80564f40e1 | 22 | void TimerResetTimeCounter( void ) |
mluis | 0:cb80564f40e1 | 23 | { |
mluis | 0:cb80564f40e1 | 24 | CurrentTime = CurrentTime + TimeCounter.read_us( ); |
mluis | 0:cb80564f40e1 | 25 | TimeCounter.reset( ); |
mluis | 0:cb80564f40e1 | 26 | TimeCounter.start( ); |
mluis | 0:cb80564f40e1 | 27 | } |
mluis | 0:cb80564f40e1 | 28 | |
mluis | 0:cb80564f40e1 | 29 | void TimerTimeCounterInit( void ) |
mluis | 0:cb80564f40e1 | 30 | { |
mluis | 0:cb80564f40e1 | 31 | TimeCounter.start( ); |
mluis | 0:cb80564f40e1 | 32 | LoadTimeCounter.attach( &TimerResetTimeCounter, 10 ); |
mluis | 0:cb80564f40e1 | 33 | } |
mluis | 0:cb80564f40e1 | 34 | |
mluis | 0:cb80564f40e1 | 35 | TimerTime_t TimerGetCurrentTime( void ) |
mluis | 0:cb80564f40e1 | 36 | { |
mluis | 0:cb80564f40e1 | 37 | CurrentTime += TimeCounter.read_us( ); |
mluis | 0:cb80564f40e1 | 38 | TimeCounter.reset( ); |
mluis | 0:cb80564f40e1 | 39 | TimeCounter.start( ); |
mluis | 0:cb80564f40e1 | 40 | return ( ( TimerTime_t )CurrentTime ); |
mluis | 0:cb80564f40e1 | 41 | } |
mluis | 0:cb80564f40e1 | 42 | |
mluis | 1:21e3eef8200f | 43 | TimerTime_t TimerGetElapsedTime( TimerTime_t savedTime ) |
mluis | 1:21e3eef8200f | 44 | { |
mluis | 1:21e3eef8200f | 45 | CurrentTime += TimeCounter.read_us( ); |
mluis | 1:21e3eef8200f | 46 | TimeCounter.reset( ); |
mluis | 1:21e3eef8200f | 47 | TimeCounter.start( ); |
mluis | 1:21e3eef8200f | 48 | return ( TimerTime_t )( CurrentTime - savedTime ); |
mluis | 1:21e3eef8200f | 49 | } |
mluis | 1:21e3eef8200f | 50 | |
mluis | 1:21e3eef8200f | 51 | TimerTime_t TimerGetFutureTime( TimerTime_t eventInFuture ) |
mluis | 1:21e3eef8200f | 52 | { |
mluis | 1:21e3eef8200f | 53 | CurrentTime += TimeCounter.read_us( ); |
mluis | 1:21e3eef8200f | 54 | TimeCounter.reset( ); |
mluis | 1:21e3eef8200f | 55 | TimeCounter.start( ); |
mluis | 1:21e3eef8200f | 56 | return ( TimerTime_t )( CurrentTime + eventInFuture ); |
mluis | 1:21e3eef8200f | 57 | } |
mluis | 1:21e3eef8200f | 58 | |
mluis | 0:cb80564f40e1 | 59 | void TimerInit( TimerEvent_t *obj, void ( *callback )( void ) ) |
mluis | 0:cb80564f40e1 | 60 | { |
mluis | 0:cb80564f40e1 | 61 | obj->value = 0; |
mluis | 0:cb80564f40e1 | 62 | obj->Callback = callback; |
mluis | 0:cb80564f40e1 | 63 | } |
mluis | 0:cb80564f40e1 | 64 | |
mluis | 0:cb80564f40e1 | 65 | void TimerStart( TimerEvent_t *obj ) |
mluis | 0:cb80564f40e1 | 66 | { |
mluis | 0:cb80564f40e1 | 67 | obj->Timer.attach_us( obj->Callback, obj->value ); |
mluis | 0:cb80564f40e1 | 68 | } |
mluis | 0:cb80564f40e1 | 69 | |
mluis | 0:cb80564f40e1 | 70 | void TimerStop( TimerEvent_t *obj ) |
mluis | 0:cb80564f40e1 | 71 | { |
mluis | 0:cb80564f40e1 | 72 | obj->Timer.detach( ); |
mluis | 0:cb80564f40e1 | 73 | } |
mluis | 0:cb80564f40e1 | 74 | |
mluis | 0:cb80564f40e1 | 75 | void TimerSetValue( TimerEvent_t *obj, uint32_t value ) |
mluis | 0:cb80564f40e1 | 76 | { |
mluis | 0:cb80564f40e1 | 77 | obj->value = value; |
mluis | 0:cb80564f40e1 | 78 | } |