SCPI interface to SX1272 and SX1276

Dependencies:   SX127x lib_gps lib_mma8451q lib_mpl3115a2 lib_sx9500 libscpi mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers timer.cpp Source File

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 "timer.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 void TimerInit( TimerEvent_t *obj, void ( *callback )( void ) )
00044 {
00045     obj->value = 0;
00046     obj->Callback = callback;
00047 }
00048 
00049 void TimerStart( TimerEvent_t *obj )
00050 {
00051     obj->Timer.attach_us( obj->Callback, obj->value );
00052 }
00053 
00054 void TimerStop( TimerEvent_t *obj )
00055 {
00056     obj->Timer.detach( );
00057 }
00058 
00059 void TimerSetValue( TimerEvent_t *obj, uint32_t value )
00060 {
00061     obj->value = value;
00062 }