firstTest

Dependencies:   mbed lib_sx9500 SX127x lib_mpl3115a2 lib_mma8451q lib_gps libscpi

Committer:
bongkwan
Date:
Tue Apr 14 02:55:34 2020 +0000
Revision:
1:96123698b488
Parent:
0:1aa6d4a96bf1
first change

Who changed what in which revision?

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