![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
This code uses Semtech's open source LoRaWAN stack ported to mbed environment.
Dependencies: mbed LoRaWAN-lib SX1272Lib
system/timer.cpp@0:6155544d38b1, 2016-06-09 (annotated)
- Committer:
- Mehrad
- Date:
- Thu Jun 09 23:58:16 2016 +0000
- Revision:
- 0:6155544d38b1
The initial commit.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mehrad | 0:6155544d38b1 | 1 | /* |
Mehrad | 0:6155544d38b1 | 2 | / _____) _ | | |
Mehrad | 0:6155544d38b1 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
Mehrad | 0:6155544d38b1 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
Mehrad | 0:6155544d38b1 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
Mehrad | 0:6155544d38b1 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
Mehrad | 0:6155544d38b1 | 7 | (C)2013 Semtech |
Mehrad | 0:6155544d38b1 | 8 | |
Mehrad | 0:6155544d38b1 | 9 | Description: Timer objects and scheduling management |
Mehrad | 0:6155544d38b1 | 10 | |
Mehrad | 0:6155544d38b1 | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
Mehrad | 0:6155544d38b1 | 12 | |
Mehrad | 0:6155544d38b1 | 13 | Maintainer: Miguel Luis and Gregory Cristian |
Mehrad | 0:6155544d38b1 | 14 | */ |
Mehrad | 0:6155544d38b1 | 15 | #include "board.h" |
Mehrad | 0:6155544d38b1 | 16 | |
Mehrad | 0:6155544d38b1 | 17 | Timer TimeCounter; |
Mehrad | 0:6155544d38b1 | 18 | Ticker LoadTimeCounter; |
Mehrad | 0:6155544d38b1 | 19 | |
Mehrad | 0:6155544d38b1 | 20 | volatile uint32_t CurrentTime = 0; |
Mehrad | 0:6155544d38b1 | 21 | |
Mehrad | 0:6155544d38b1 | 22 | void TimerResetTimeCounter( void ) |
Mehrad | 0:6155544d38b1 | 23 | { |
Mehrad | 0:6155544d38b1 | 24 | CurrentTime = CurrentTime + TimeCounter.read_us( ); |
Mehrad | 0:6155544d38b1 | 25 | TimeCounter.reset( ); |
Mehrad | 0:6155544d38b1 | 26 | TimeCounter.start( ); |
Mehrad | 0:6155544d38b1 | 27 | } |
Mehrad | 0:6155544d38b1 | 28 | |
Mehrad | 0:6155544d38b1 | 29 | void TimerTimeCounterInit( void ) |
Mehrad | 0:6155544d38b1 | 30 | { |
Mehrad | 0:6155544d38b1 | 31 | TimeCounter.start( ); |
Mehrad | 0:6155544d38b1 | 32 | LoadTimeCounter.attach( &TimerResetTimeCounter, 10 ); |
Mehrad | 0:6155544d38b1 | 33 | } |
Mehrad | 0:6155544d38b1 | 34 | |
Mehrad | 0:6155544d38b1 | 35 | TimerTime_t TimerGetCurrentTime( void ) |
Mehrad | 0:6155544d38b1 | 36 | { |
Mehrad | 0:6155544d38b1 | 37 | CurrentTime += TimeCounter.read_us( ); |
Mehrad | 0:6155544d38b1 | 38 | TimeCounter.reset( ); |
Mehrad | 0:6155544d38b1 | 39 | TimeCounter.start( ); |
Mehrad | 0:6155544d38b1 | 40 | return ( ( TimerTime_t )CurrentTime ); |
Mehrad | 0:6155544d38b1 | 41 | } |
Mehrad | 0:6155544d38b1 | 42 | |
Mehrad | 0:6155544d38b1 | 43 | TimerTime_t TimerGetElapsedTime( TimerTime_t savedTime ) |
Mehrad | 0:6155544d38b1 | 44 | { |
Mehrad | 0:6155544d38b1 | 45 | CurrentTime += TimeCounter.read_us( ); |
Mehrad | 0:6155544d38b1 | 46 | TimeCounter.reset( ); |
Mehrad | 0:6155544d38b1 | 47 | TimeCounter.start( ); |
Mehrad | 0:6155544d38b1 | 48 | return ( TimerTime_t )( CurrentTime - savedTime ); |
Mehrad | 0:6155544d38b1 | 49 | } |
Mehrad | 0:6155544d38b1 | 50 | |
Mehrad | 0:6155544d38b1 | 51 | TimerTime_t TimerGetFutureTime( TimerTime_t eventInFuture ) |
Mehrad | 0:6155544d38b1 | 52 | { |
Mehrad | 0:6155544d38b1 | 53 | CurrentTime += TimeCounter.read_us( ); |
Mehrad | 0:6155544d38b1 | 54 | TimeCounter.reset( ); |
Mehrad | 0:6155544d38b1 | 55 | TimeCounter.start( ); |
Mehrad | 0:6155544d38b1 | 56 | return ( TimerTime_t )( CurrentTime + eventInFuture ); |
Mehrad | 0:6155544d38b1 | 57 | } |
Mehrad | 0:6155544d38b1 | 58 | |
Mehrad | 0:6155544d38b1 | 59 | void TimerInit( TimerEvent_t *obj, void ( *callback )( void ) ) |
Mehrad | 0:6155544d38b1 | 60 | { |
Mehrad | 0:6155544d38b1 | 61 | obj->value = 0; |
Mehrad | 0:6155544d38b1 | 62 | obj->Callback = callback; |
Mehrad | 0:6155544d38b1 | 63 | } |
Mehrad | 0:6155544d38b1 | 64 | |
Mehrad | 0:6155544d38b1 | 65 | void TimerStart( TimerEvent_t *obj ) |
Mehrad | 0:6155544d38b1 | 66 | { |
Mehrad | 0:6155544d38b1 | 67 | obj->Timer.attach_us( obj->Callback, obj->value ); |
Mehrad | 0:6155544d38b1 | 68 | } |
Mehrad | 0:6155544d38b1 | 69 | |
Mehrad | 0:6155544d38b1 | 70 | void TimerStop( TimerEvent_t *obj ) |
Mehrad | 0:6155544d38b1 | 71 | { |
Mehrad | 0:6155544d38b1 | 72 | obj->Timer.detach( ); |
Mehrad | 0:6155544d38b1 | 73 | } |
Mehrad | 0:6155544d38b1 | 74 | |
Mehrad | 0:6155544d38b1 | 75 | void TimerSetValue( TimerEvent_t *obj, uint32_t value ) |
Mehrad | 0:6155544d38b1 | 76 | { |
Mehrad | 0:6155544d38b1 | 77 | obj->value = value; |
Mehrad | 0:6155544d38b1 | 78 | } |