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