testing lora and ble on nrf51

Dependencies:   BLE_API LoRaWAN-lib SX1276Lib mbed nRF51822

Committer:
olav
Date:
Mon May 09 08:06:21 2016 +0000
Revision:
0:4c1fcbfcc7bf
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
olav 0:4c1fcbfcc7bf 1 /*
olav 0:4c1fcbfcc7bf 2 / _____) _ | |
olav 0:4c1fcbfcc7bf 3 ( (____ _____ ____ _| |_ _____ ____| |__
olav 0:4c1fcbfcc7bf 4 \____ \| ___ | (_ _) ___ |/ ___) _ \
olav 0:4c1fcbfcc7bf 5 _____) ) ____| | | || |_| ____( (___| | | |
olav 0:4c1fcbfcc7bf 6 (______/|_____)_|_|_| \__)_____)\____)_| |_|
olav 0:4c1fcbfcc7bf 7 (C)2013 Semtech
olav 0:4c1fcbfcc7bf 8
olav 0:4c1fcbfcc7bf 9 Description: Timer objects and scheduling management
olav 0:4c1fcbfcc7bf 10
olav 0:4c1fcbfcc7bf 11 License: Revised BSD License, see LICENSE.TXT file include in the project
olav 0:4c1fcbfcc7bf 12
olav 0:4c1fcbfcc7bf 13 Maintainer: Miguel Luis and Gregory Cristian
olav 0:4c1fcbfcc7bf 14 */
olav 0:4c1fcbfcc7bf 15 #include "board.h"
olav 0:4c1fcbfcc7bf 16
olav 0:4c1fcbfcc7bf 17 Timer TimeCounter;
olav 0:4c1fcbfcc7bf 18 Ticker LoadTimeCounter;
olav 0:4c1fcbfcc7bf 19
olav 0:4c1fcbfcc7bf 20 volatile uint32_t CurrentTime = 0;
olav 0:4c1fcbfcc7bf 21
olav 0:4c1fcbfcc7bf 22 void TimerResetTimeCounter( void )
olav 0:4c1fcbfcc7bf 23 {
olav 0:4c1fcbfcc7bf 24 CurrentTime = CurrentTime + TimeCounter.read_us( );
olav 0:4c1fcbfcc7bf 25 TimeCounter.reset( );
olav 0:4c1fcbfcc7bf 26 TimeCounter.start( );
olav 0:4c1fcbfcc7bf 27 }
olav 0:4c1fcbfcc7bf 28
olav 0:4c1fcbfcc7bf 29 void TimerTimeCounterInit( void )
olav 0:4c1fcbfcc7bf 30 {
olav 0:4c1fcbfcc7bf 31 TimeCounter.start( );
olav 0:4c1fcbfcc7bf 32 LoadTimeCounter.attach( &TimerResetTimeCounter, 10 );
olav 0:4c1fcbfcc7bf 33 }
olav 0:4c1fcbfcc7bf 34
olav 0:4c1fcbfcc7bf 35 TimerTime_t TimerGetCurrentTime( void )
olav 0:4c1fcbfcc7bf 36 {
olav 0:4c1fcbfcc7bf 37 CurrentTime += TimeCounter.read_us( );
olav 0:4c1fcbfcc7bf 38 TimeCounter.reset( );
olav 0:4c1fcbfcc7bf 39 TimeCounter.start( );
olav 0:4c1fcbfcc7bf 40 return ( ( TimerTime_t )CurrentTime );
olav 0:4c1fcbfcc7bf 41 }
olav 0:4c1fcbfcc7bf 42
olav 0:4c1fcbfcc7bf 43 void TimerInit( TimerEvent_t *obj, void ( *callback )( void ) )
olav 0:4c1fcbfcc7bf 44 {
olav 0:4c1fcbfcc7bf 45 obj->value = 0;
olav 0:4c1fcbfcc7bf 46 obj->Callback = callback;
olav 0:4c1fcbfcc7bf 47 }
olav 0:4c1fcbfcc7bf 48
olav 0:4c1fcbfcc7bf 49 void TimerStart( TimerEvent_t *obj )
olav 0:4c1fcbfcc7bf 50 {
olav 0:4c1fcbfcc7bf 51 obj->Timer.attach_us( obj->Callback, obj->value );
olav 0:4c1fcbfcc7bf 52 }
olav 0:4c1fcbfcc7bf 53
olav 0:4c1fcbfcc7bf 54 void TimerStop( TimerEvent_t *obj )
olav 0:4c1fcbfcc7bf 55 {
olav 0:4c1fcbfcc7bf 56 obj->Timer.detach( );
olav 0:4c1fcbfcc7bf 57 }
olav 0:4c1fcbfcc7bf 58
olav 0:4c1fcbfcc7bf 59 void TimerSetValue( TimerEvent_t *obj, uint32_t value )
olav 0:4c1fcbfcc7bf 60 {
olav 0:4c1fcbfcc7bf 61 obj->value = value;
olav 0:4c1fcbfcc7bf 62 }