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