SX126xDevKit
Dependencies: mbed DmTftLibrary SX126xLib
Peripherals/Timers.cpp@0:e5420f1a8a1a, 2017-09-05 (annotated)
- Committer:
- GregCr
- Date:
- Tue Sep 05 08:15:37 2017 +0000
- Revision:
- 0:e5420f1a8a1a
Candidate Release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GregCr | 0:e5420f1a8a1a | 1 | /* |
GregCr | 0:e5420f1a8a1a | 2 | ______ _ |
GregCr | 0:e5420f1a8a1a | 3 | / _____) _ | | |
GregCr | 0:e5420f1a8a1a | 4 | ( (____ _____ ____ _| |_ _____ ____| |__ |
GregCr | 0:e5420f1a8a1a | 5 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
GregCr | 0:e5420f1a8a1a | 6 | _____) ) ____| | | || |_| ____( (___| | | | |
GregCr | 0:e5420f1a8a1a | 7 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
GregCr | 0:e5420f1a8a1a | 8 | (C)2016 Semtech |
GregCr | 0:e5420f1a8a1a | 9 | |
GregCr | 0:e5420f1a8a1a | 10 | Description: Timers |
GregCr | 0:e5420f1a8a1a | 11 | |
GregCr | 0:e5420f1a8a1a | 12 | Maintainer: Gregory Cristian & Gilbert Menth |
GregCr | 0:e5420f1a8a1a | 13 | */ |
GregCr | 0:e5420f1a8a1a | 14 | |
GregCr | 0:e5420f1a8a1a | 15 | #include "mbed.h" |
GregCr | 0:e5420f1a8a1a | 16 | #include "Timers.h" |
GregCr | 0:e5420f1a8a1a | 17 | |
GregCr | 0:e5420f1a8a1a | 18 | |
GregCr | 0:e5420f1a8a1a | 19 | Ticker TickTimer; |
GregCr | 0:e5420f1a8a1a | 20 | |
GregCr | 0:e5420f1a8a1a | 21 | static uint32_t SoftTimer = 0; |
GregCr | 0:e5420f1a8a1a | 22 | static void TimersIncSoftTimer( void ); |
GregCr | 0:e5420f1a8a1a | 23 | |
GregCr | 0:e5420f1a8a1a | 24 | |
GregCr | 0:e5420f1a8a1a | 25 | void TimersInit( void ) |
GregCr | 0:e5420f1a8a1a | 26 | { |
GregCr | 0:e5420f1a8a1a | 27 | TickTimer.attach_us( &TimersIncSoftTimer, 1000 ); // Ticks every millisecond |
GregCr | 0:e5420f1a8a1a | 28 | } |
GregCr | 0:e5420f1a8a1a | 29 | |
GregCr | 0:e5420f1a8a1a | 30 | static void TimersIncSoftTimer( void ) |
GregCr | 0:e5420f1a8a1a | 31 | { |
GregCr | 0:e5420f1a8a1a | 32 | SoftTimer++; |
GregCr | 0:e5420f1a8a1a | 33 | } |
GregCr | 0:e5420f1a8a1a | 34 | |
GregCr | 0:e5420f1a8a1a | 35 | void TimersSetTimer( uint32_t *sTimer, uint32_t timeLength ) |
GregCr | 0:e5420f1a8a1a | 36 | { |
GregCr | 0:e5420f1a8a1a | 37 | if( timeLength > MAX_TIMER_VALUE ) |
GregCr | 0:e5420f1a8a1a | 38 | { |
GregCr | 0:e5420f1a8a1a | 39 | timeLength = MAX_TIMER_VALUE; |
GregCr | 0:e5420f1a8a1a | 40 | } |
GregCr | 0:e5420f1a8a1a | 41 | *sTimer = SoftTimer + timeLength; |
GregCr | 0:e5420f1a8a1a | 42 | } |
GregCr | 0:e5420f1a8a1a | 43 | |
GregCr | 0:e5420f1a8a1a | 44 | uint32_t TimersTimerHasExpired ( const uint32_t * sTimer ) |
GregCr | 0:e5420f1a8a1a | 45 | { |
GregCr | 0:e5420f1a8a1a | 46 | if( ( SoftTimer - *sTimer ) > 0x7fffffff ) |
GregCr | 0:e5420f1a8a1a | 47 | { |
GregCr | 0:e5420f1a8a1a | 48 | return false; |
GregCr | 0:e5420f1a8a1a | 49 | } |
GregCr | 0:e5420f1a8a1a | 50 | return true; |
GregCr | 0:e5420f1a8a1a | 51 | } |
GregCr | 0:e5420f1a8a1a | 52 | |
GregCr | 0:e5420f1a8a1a | 53 | uint32_t TimersTimerValue ( void ) |
GregCr | 0:e5420f1a8a1a | 54 | { |
GregCr | 0:e5420f1a8a1a | 55 | return SoftTimer; |
GregCr | 0:e5420f1a8a1a | 56 | } |