mbed os with nrf51 internal bandgap enabled to read battery level
Dependents: BLE_file_test BLE_Blink ExternalEncoder
rtos/RtosTimer.h@0:f269e3021894, 2016-10-23 (annotated)
- Committer:
- elessair
- Date:
- Sun Oct 23 15:10:02 2016 +0000
- Revision:
- 0:f269e3021894
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | /* mbed Microcontroller Library |
elessair | 0:f269e3021894 | 2 | * Copyright (c) 2006-2012 ARM Limited |
elessair | 0:f269e3021894 | 3 | * |
elessair | 0:f269e3021894 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
elessair | 0:f269e3021894 | 5 | * of this software and associated documentation files (the "Software"), to deal |
elessair | 0:f269e3021894 | 6 | * in the Software without restriction, including without limitation the rights |
elessair | 0:f269e3021894 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
elessair | 0:f269e3021894 | 8 | * copies of the Software, and to permit persons to whom the Software is |
elessair | 0:f269e3021894 | 9 | * furnished to do so, subject to the following conditions: |
elessair | 0:f269e3021894 | 10 | * |
elessair | 0:f269e3021894 | 11 | * The above copyright notice and this permission notice shall be included in |
elessair | 0:f269e3021894 | 12 | * all copies or substantial portions of the Software. |
elessair | 0:f269e3021894 | 13 | * |
elessair | 0:f269e3021894 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
elessair | 0:f269e3021894 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
elessair | 0:f269e3021894 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
elessair | 0:f269e3021894 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
elessair | 0:f269e3021894 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
elessair | 0:f269e3021894 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
elessair | 0:f269e3021894 | 20 | * SOFTWARE. |
elessair | 0:f269e3021894 | 21 | */ |
elessair | 0:f269e3021894 | 22 | #ifndef RTOS_TIMER_H |
elessair | 0:f269e3021894 | 23 | #define RTOS_TIMER_H |
elessair | 0:f269e3021894 | 24 | |
elessair | 0:f269e3021894 | 25 | #include <stdint.h> |
elessair | 0:f269e3021894 | 26 | #include "cmsis_os.h" |
elessair | 0:f269e3021894 | 27 | #include "platform/Callback.h" |
elessair | 0:f269e3021894 | 28 | #include "platform/toolchain.h" |
elessair | 0:f269e3021894 | 29 | |
elessair | 0:f269e3021894 | 30 | namespace rtos { |
elessair | 0:f269e3021894 | 31 | /** \addtogroup rtos */ |
elessair | 0:f269e3021894 | 32 | /** @{*/ |
elessair | 0:f269e3021894 | 33 | |
elessair | 0:f269e3021894 | 34 | /** The RtosTimer class allow creating and and controlling of timer functions in the system. |
elessair | 0:f269e3021894 | 35 | A timer function is called when a time period expires whereby both on-shot and |
elessair | 0:f269e3021894 | 36 | periodic timers are possible. A timer can be started, restarted, or stopped. |
elessair | 0:f269e3021894 | 37 | |
elessair | 0:f269e3021894 | 38 | Timers are handled in the thread osTimerThread. |
elessair | 0:f269e3021894 | 39 | Callback functions run under control of this thread and may use CMSIS-RTOS API calls. |
elessair | 0:f269e3021894 | 40 | */ |
elessair | 0:f269e3021894 | 41 | class RtosTimer { |
elessair | 0:f269e3021894 | 42 | public: |
elessair | 0:f269e3021894 | 43 | /** Create timer. |
elessair | 0:f269e3021894 | 44 | @param func function to be executed by this timer. |
elessair | 0:f269e3021894 | 45 | @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic) |
elessair | 0:f269e3021894 | 46 | @param argument argument to the timer call back function. (default: NULL) |
elessair | 0:f269e3021894 | 47 | @deprecated Replaced with RtosTimer(Callback<void()>, os_timer_type) |
elessair | 0:f269e3021894 | 48 | */ |
elessair | 0:f269e3021894 | 49 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
elessair | 0:f269e3021894 | 50 | "Replaced with RtosTimer(Callback<void()>, os_timer_type)") |
elessair | 0:f269e3021894 | 51 | RtosTimer(void (*func)(void const *argument), os_timer_type type=osTimerPeriodic, void *argument=NULL) { |
elessair | 0:f269e3021894 | 52 | constructor(mbed::callback((void (*)(void *))func, argument), type); |
elessair | 0:f269e3021894 | 53 | } |
elessair | 0:f269e3021894 | 54 | |
elessair | 0:f269e3021894 | 55 | /** Create timer. |
elessair | 0:f269e3021894 | 56 | @param func function to be executed by this timer. |
elessair | 0:f269e3021894 | 57 | @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic) |
elessair | 0:f269e3021894 | 58 | */ |
elessair | 0:f269e3021894 | 59 | RtosTimer(mbed::Callback<void()> func, os_timer_type type=osTimerPeriodic) { |
elessair | 0:f269e3021894 | 60 | constructor(func, type); |
elessair | 0:f269e3021894 | 61 | } |
elessair | 0:f269e3021894 | 62 | |
elessair | 0:f269e3021894 | 63 | /** Create timer. |
elessair | 0:f269e3021894 | 64 | @param obj pointer to the object to call the member function on. |
elessair | 0:f269e3021894 | 65 | @param method member function to be executed by this timer. |
elessair | 0:f269e3021894 | 66 | @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic) |
elessair | 0:f269e3021894 | 67 | @deprecated |
elessair | 0:f269e3021894 | 68 | The RtosTimer constructor does not support cv-qualifiers. Replaced by |
elessair | 0:f269e3021894 | 69 | RtosTimer(callback(obj, method), os_timer_type). |
elessair | 0:f269e3021894 | 70 | */ |
elessair | 0:f269e3021894 | 71 | template <typename T, typename M> |
elessair | 0:f269e3021894 | 72 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
elessair | 0:f269e3021894 | 73 | "The RtosTimer constructor does not support cv-qualifiers. Replaced by " |
elessair | 0:f269e3021894 | 74 | "RtosTimer(callback(obj, method), os_timer_type).") |
elessair | 0:f269e3021894 | 75 | RtosTimer(T *obj, M method, os_timer_type type=osTimerPeriodic) { |
elessair | 0:f269e3021894 | 76 | constructor(mbed::callback(obj, method), type); |
elessair | 0:f269e3021894 | 77 | } |
elessair | 0:f269e3021894 | 78 | |
elessair | 0:f269e3021894 | 79 | /** Stop the timer. |
elessair | 0:f269e3021894 | 80 | @return status code that indicates the execution status of the function. |
elessair | 0:f269e3021894 | 81 | */ |
elessair | 0:f269e3021894 | 82 | osStatus stop(void); |
elessair | 0:f269e3021894 | 83 | |
elessair | 0:f269e3021894 | 84 | /** Start the timer. |
elessair | 0:f269e3021894 | 85 | @param millisec time delay value of the timer. |
elessair | 0:f269e3021894 | 86 | @return status code that indicates the execution status of the function. |
elessair | 0:f269e3021894 | 87 | */ |
elessair | 0:f269e3021894 | 88 | osStatus start(uint32_t millisec); |
elessair | 0:f269e3021894 | 89 | |
elessair | 0:f269e3021894 | 90 | ~RtosTimer(); |
elessair | 0:f269e3021894 | 91 | |
elessair | 0:f269e3021894 | 92 | private: |
elessair | 0:f269e3021894 | 93 | // Required to share definitions without |
elessair | 0:f269e3021894 | 94 | // delegated constructors |
elessair | 0:f269e3021894 | 95 | void constructor(mbed::Callback<void()> func, os_timer_type type); |
elessair | 0:f269e3021894 | 96 | |
elessair | 0:f269e3021894 | 97 | mbed::Callback<void()> _function; |
elessair | 0:f269e3021894 | 98 | osTimerId _timer_id; |
elessair | 0:f269e3021894 | 99 | osTimerDef_t _timer; |
elessair | 0:f269e3021894 | 100 | #if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM) |
elessair | 0:f269e3021894 | 101 | uint32_t _timer_data[5]; |
elessair | 0:f269e3021894 | 102 | #else |
elessair | 0:f269e3021894 | 103 | uint32_t _timer_data[6]; |
elessair | 0:f269e3021894 | 104 | #endif |
elessair | 0:f269e3021894 | 105 | }; |
elessair | 0:f269e3021894 | 106 | |
elessair | 0:f269e3021894 | 107 | } |
elessair | 0:f269e3021894 | 108 | |
elessair | 0:f269e3021894 | 109 | #endif |
elessair | 0:f269e3021894 | 110 | |
elessair | 0:f269e3021894 | 111 | /** @}*/ |