LoRaWAN demo 76 bootcamp

Dependencies:   mbed DigitDisplay Chainable_RGB_LED LoRaWAN-lib SX1276Lib

Committer:
mluis
Date:
Mon Apr 24 13:40:32 2017 +0000
Revision:
5:d87bb1eabccd
Parent:
3:de1dcfbe175a
WARNING: Radio API timings changed from micro-seconds to milliseconds; ; Synchronized with https://github.com/Lora-net/LoRaMac-node git revision e506c246652fa44c3f24cecb89d0707b49ece739; Updated all libraries to the latest versions

Who changed what in which revision?

UserRevisionLine numberNew 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 5:d87bb1eabccd 20 volatile uint32_t CurrentTime = 0;
mluis 0:cb80564f40e1 21
mluis 0:cb80564f40e1 22 void TimerResetTimeCounter( void )
mluis 0:cb80564f40e1 23 {
mluis 5:d87bb1eabccd 24 CurrentTime = CurrentTime + TimeCounter.read_us( ) / 1e3;
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 5:d87bb1eabccd 32 LoadTimeCounter.attach( mbed::callback( &TimerResetTimeCounter ), 10 );
mluis 0:cb80564f40e1 33 }
mluis 0:cb80564f40e1 34
mluis 0:cb80564f40e1 35 TimerTime_t TimerGetCurrentTime( void )
mluis 0:cb80564f40e1 36 {
mluis 5:d87bb1eabccd 37 CurrentTime += TimeCounter.read_us( ) / 1e3;
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 5:d87bb1eabccd 45 CurrentTime += TimeCounter.read_us( ) / 1e3;
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 5:d87bb1eabccd 53 CurrentTime += TimeCounter.read_us( ) / 1e3;
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 5:d87bb1eabccd 67 obj->Timer.attach_us( mbed::callback( obj->Callback ), obj->value * 1e3 );
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 }