mQ Branch for NA mote testing
Dependencies: LoRaWAN-lib SX1272Lib-mQ lib_gps lib_mma8451q lib_mpl3115a2 mbed
Fork of LoRaWAN-NAMote72-Application-Demo by
system/timer.cpp@0:69f2e28d12c1, 2016-05-17 (annotated)
- Committer:
- ubhat
- Date:
- Tue May 17 00:21:55 2016 +0000
- Revision:
- 0:69f2e28d12c1
Project for LoRa Bootcamp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ubhat | 0:69f2e28d12c1 | 1 | /* |
ubhat | 0:69f2e28d12c1 | 2 | / _____) _ | | |
ubhat | 0:69f2e28d12c1 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
ubhat | 0:69f2e28d12c1 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
ubhat | 0:69f2e28d12c1 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
ubhat | 0:69f2e28d12c1 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
ubhat | 0:69f2e28d12c1 | 7 | (C)2013 Semtech |
ubhat | 0:69f2e28d12c1 | 8 | |
ubhat | 0:69f2e28d12c1 | 9 | Description: Timer objects and scheduling management |
ubhat | 0:69f2e28d12c1 | 10 | |
ubhat | 0:69f2e28d12c1 | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
ubhat | 0:69f2e28d12c1 | 12 | |
ubhat | 0:69f2e28d12c1 | 13 | Maintainer: Miguel Luis and Gregory Cristian |
ubhat | 0:69f2e28d12c1 | 14 | */ |
ubhat | 0:69f2e28d12c1 | 15 | #include "board.h" |
ubhat | 0:69f2e28d12c1 | 16 | |
ubhat | 0:69f2e28d12c1 | 17 | Timer TimeCounter; |
ubhat | 0:69f2e28d12c1 | 18 | Ticker LoadTimeCounter; |
ubhat | 0:69f2e28d12c1 | 19 | |
ubhat | 0:69f2e28d12c1 | 20 | volatile uint32_t CurrentTime = 0; |
ubhat | 0:69f2e28d12c1 | 21 | |
ubhat | 0:69f2e28d12c1 | 22 | void TimerResetTimeCounter( void ) |
ubhat | 0:69f2e28d12c1 | 23 | { |
ubhat | 0:69f2e28d12c1 | 24 | CurrentTime = CurrentTime + TimeCounter.read_us( ); |
ubhat | 0:69f2e28d12c1 | 25 | TimeCounter.reset( ); |
ubhat | 0:69f2e28d12c1 | 26 | TimeCounter.start( ); |
ubhat | 0:69f2e28d12c1 | 27 | } |
ubhat | 0:69f2e28d12c1 | 28 | |
ubhat | 0:69f2e28d12c1 | 29 | void TimerTimeCounterInit( void ) |
ubhat | 0:69f2e28d12c1 | 30 | { |
ubhat | 0:69f2e28d12c1 | 31 | TimeCounter.start( ); |
ubhat | 0:69f2e28d12c1 | 32 | LoadTimeCounter.attach( &TimerResetTimeCounter, 10 ); |
ubhat | 0:69f2e28d12c1 | 33 | } |
ubhat | 0:69f2e28d12c1 | 34 | |
ubhat | 0:69f2e28d12c1 | 35 | TimerTime_t TimerGetCurrentTime( void ) |
ubhat | 0:69f2e28d12c1 | 36 | { |
ubhat | 0:69f2e28d12c1 | 37 | CurrentTime += TimeCounter.read_us( ); |
ubhat | 0:69f2e28d12c1 | 38 | TimeCounter.reset( ); |
ubhat | 0:69f2e28d12c1 | 39 | TimeCounter.start( ); |
ubhat | 0:69f2e28d12c1 | 40 | return ( ( TimerTime_t )CurrentTime ); |
ubhat | 0:69f2e28d12c1 | 41 | } |
ubhat | 0:69f2e28d12c1 | 42 | |
ubhat | 0:69f2e28d12c1 | 43 | void TimerInit( TimerEvent_t *obj, void ( *callback )( void ) ) |
ubhat | 0:69f2e28d12c1 | 44 | { |
ubhat | 0:69f2e28d12c1 | 45 | obj->value = 0; |
ubhat | 0:69f2e28d12c1 | 46 | obj->Callback = callback; |
ubhat | 0:69f2e28d12c1 | 47 | } |
ubhat | 0:69f2e28d12c1 | 48 | |
ubhat | 0:69f2e28d12c1 | 49 | void TimerStart( TimerEvent_t *obj ) |
ubhat | 0:69f2e28d12c1 | 50 | { |
ubhat | 0:69f2e28d12c1 | 51 | obj->Timer.attach_us( obj->Callback, obj->value ); |
ubhat | 0:69f2e28d12c1 | 52 | } |
ubhat | 0:69f2e28d12c1 | 53 | |
ubhat | 0:69f2e28d12c1 | 54 | void TimerStop( TimerEvent_t *obj ) |
ubhat | 0:69f2e28d12c1 | 55 | { |
ubhat | 0:69f2e28d12c1 | 56 | obj->Timer.detach( ); |
ubhat | 0:69f2e28d12c1 | 57 | } |
ubhat | 0:69f2e28d12c1 | 58 | |
ubhat | 0:69f2e28d12c1 | 59 | void TimerSetValue( TimerEvent_t *obj, uint32_t value ) |
ubhat | 0:69f2e28d12c1 | 60 | { |
ubhat | 0:69f2e28d12c1 | 61 | obj->value = value; |
ubhat | 0:69f2e28d12c1 | 62 | } |