Test Fork
Dependencies: LoRaWAN-lib SX1272Lib lib_gps lib_mma8451q lib_mpl3115a2 mbed
Fork of LoRaWAN-NAMote72-Application-Demo by
timer.cpp
00001 /* 00002 / _____) _ | | 00003 ( (____ _____ ____ _| |_ _____ ____| |__ 00004 \____ \| ___ | (_ _) ___ |/ ___) _ \ 00005 _____) ) ____| | | || |_| ____( (___| | | | 00006 (______/|_____)_|_|_| \__)_____)\____)_| |_| 00007 (C)2013 Semtech 00008 00009 Description: Timer objects and scheduling management 00010 00011 License: Revised BSD License, see LICENSE.TXT file include in the project 00012 00013 Maintainer: Miguel Luis and Gregory Cristian 00014 */ 00015 #include "board.h" 00016 00017 Timer TimeCounter; 00018 Ticker LoadTimeCounter; 00019 00020 volatile uint32_t CurrentTime = 0; 00021 00022 void TimerResetTimeCounter( void ) 00023 { 00024 CurrentTime = CurrentTime + TimeCounter.read_us( ); 00025 TimeCounter.reset( ); 00026 TimeCounter.start( ); 00027 } 00028 00029 void TimerTimeCounterInit( void ) 00030 { 00031 TimeCounter.start( ); 00032 LoadTimeCounter.attach( &TimerResetTimeCounter, 10 ); 00033 } 00034 00035 TimerTime_t TimerGetCurrentTime( void ) 00036 { 00037 CurrentTime += TimeCounter.read_us( ); 00038 TimeCounter.reset( ); 00039 TimeCounter.start( ); 00040 return ( ( TimerTime_t )CurrentTime ); 00041 } 00042 00043 TimerTime_t TimerGetElapsedTime( TimerTime_t savedTime ) 00044 { 00045 CurrentTime += TimeCounter.read_us( ); 00046 TimeCounter.reset( ); 00047 TimeCounter.start( ); 00048 return ( TimerTime_t )( CurrentTime - savedTime ); 00049 } 00050 00051 TimerTime_t TimerGetFutureTime( TimerTime_t eventInFuture ) 00052 { 00053 CurrentTime += TimeCounter.read_us( ); 00054 TimeCounter.reset( ); 00055 TimeCounter.start( ); 00056 return ( TimerTime_t )( CurrentTime + eventInFuture ); 00057 } 00058 00059 void TimerInit( TimerEvent_t *obj, void ( *callback )( void ) ) 00060 { 00061 obj->value = 0; 00062 obj->Callback = callback; 00063 } 00064 00065 void TimerStart( TimerEvent_t *obj ) 00066 { 00067 obj->Timer.attach_us( obj->Callback, obj->value ); 00068 } 00069 00070 void TimerStop( TimerEvent_t *obj ) 00071 { 00072 obj->Timer.detach( ); 00073 } 00074 00075 void TimerSetValue( TimerEvent_t *obj, uint32_t value ) 00076 { 00077 obj->value = value; 00078 }
Generated on Mon Jul 25 2022 17:07:03 by
![doxygen](doxygen.png)