Yes

Dependents:   Asservissement_Gyro

Committer:
braichi13
Date:
Sun May 08 14:39:47 2022 +0000
Revision:
0:77205fc699b9
Programme du Gyropode

Who changed what in which revision?

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