Daoyu_Sofiane Yao_Belouka / mbed-rtos

Dependents:   Mecatro_Gyro_Programme_Codeur_HC06

Committer:
daoyu_sofiane
Date:
Fri Apr 16 09:25:33 2021 +0000
Revision:
0:a8ed743bc1e1
Projet Gyropode

Who changed what in which revision?

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