desp koval / mbed-rtos

Dependents:   Mecatro_Filtre

Committer:
mecatro_prod
Date:
Mon Mar 15 14:18:11 2021 +0000
Revision:
0:4a2c9c1f5b9e
Pas de changement

Who changed what in which revision?

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