LoRaWAN demo 76 bootcamp

Dependencies:   mbed DigitDisplay Chainable_RGB_LED LoRaWAN-lib SX1276Lib

Committer:
mluis
Date:
Fri May 13 15:52:23 2016 +0000
Revision:
1:21e3eef8200f
Parent:
0:cb80564f40e1
Child:
3:de1dcfbe175a
Updated mbed, LoRaWAN-lib and SX1276Lib libraries.

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 0:cb80564f40e1 20 volatile uint32_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 }