Alan Ffrench / Mbed 2 deprecated Experiment_2_5

Dependencies:   mbed

Committer:
alanffrench
Date:
Wed Jul 29 18:51:38 2020 +0000
Revision:
0:52468b19aa21
Threads

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alanffrench 0:52468b19aa21 1 /* mbed Microcontroller Library
alanffrench 0:52468b19aa21 2 * Copyright (c) 2006-2012 ARM Limited
alanffrench 0:52468b19aa21 3 *
alanffrench 0:52468b19aa21 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
alanffrench 0:52468b19aa21 5 * of this software and associated documentation files (the "Software"), to deal
alanffrench 0:52468b19aa21 6 * in the Software without restriction, including without limitation the rights
alanffrench 0:52468b19aa21 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
alanffrench 0:52468b19aa21 8 * copies of the Software, and to permit persons to whom the Software is
alanffrench 0:52468b19aa21 9 * furnished to do so, subject to the following conditions:
alanffrench 0:52468b19aa21 10 *
alanffrench 0:52468b19aa21 11 * The above copyright notice and this permission notice shall be included in
alanffrench 0:52468b19aa21 12 * all copies or substantial portions of the Software.
alanffrench 0:52468b19aa21 13 *
alanffrench 0:52468b19aa21 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
alanffrench 0:52468b19aa21 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
alanffrench 0:52468b19aa21 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
alanffrench 0:52468b19aa21 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
alanffrench 0:52468b19aa21 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
alanffrench 0:52468b19aa21 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
alanffrench 0:52468b19aa21 20 * SOFTWARE.
alanffrench 0:52468b19aa21 21 */
alanffrench 0:52468b19aa21 22 #ifndef RTOS_TIMER_H
alanffrench 0:52468b19aa21 23 #define RTOS_TIMER_H
alanffrench 0:52468b19aa21 24
alanffrench 0:52468b19aa21 25 #include <stdint.h>
alanffrench 0:52468b19aa21 26 #include "cmsis_os.h"
alanffrench 0:52468b19aa21 27
alanffrench 0:52468b19aa21 28 namespace rtos {
alanffrench 0:52468b19aa21 29
alanffrench 0:52468b19aa21 30 /** The RtosTimer class allow creating and and controlling of timer functions in the system.
alanffrench 0:52468b19aa21 31 A timer function is called when a time period expires whereby both on-shot and
alanffrench 0:52468b19aa21 32 periodic timers are possible. A timer can be started, restarted, or stopped.
alanffrench 0:52468b19aa21 33
alanffrench 0:52468b19aa21 34 Timers are handled in the thread osTimerThread.
alanffrench 0:52468b19aa21 35 Callback functions run under control of this thread and may use CMSIS-RTOS API calls.
alanffrench 0:52468b19aa21 36 */
alanffrench 0:52468b19aa21 37 class RtosTimer {
alanffrench 0:52468b19aa21 38 public:
alanffrench 0:52468b19aa21 39 /** Create and Start timer.
alanffrench 0:52468b19aa21 40 @param task name of the timer call back function.
alanffrench 0:52468b19aa21 41 @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic)
alanffrench 0:52468b19aa21 42 @param argument argument to the timer call back function. (default: NULL)
alanffrench 0:52468b19aa21 43 */
alanffrench 0:52468b19aa21 44 RtosTimer(void (*task)(void const *argument),
alanffrench 0:52468b19aa21 45 os_timer_type type=osTimerPeriodic,
alanffrench 0:52468b19aa21 46 void *argument=NULL);
alanffrench 0:52468b19aa21 47
alanffrench 0:52468b19aa21 48 /** Stop the timer.
alanffrench 0:52468b19aa21 49 @return status code that indicates the execution status of the function.
alanffrench 0:52468b19aa21 50 */
alanffrench 0:52468b19aa21 51 osStatus stop(void);
alanffrench 0:52468b19aa21 52
alanffrench 0:52468b19aa21 53 /** start a timer.
alanffrench 0:52468b19aa21 54 @param millisec time delay value of the timer.
alanffrench 0:52468b19aa21 55 @return status code that indicates the execution status of the function.
alanffrench 0:52468b19aa21 56 */
alanffrench 0:52468b19aa21 57 osStatus start(uint32_t millisec);
alanffrench 0:52468b19aa21 58
alanffrench 0:52468b19aa21 59 ~RtosTimer();
alanffrench 0:52468b19aa21 60
alanffrench 0:52468b19aa21 61 private:
alanffrench 0:52468b19aa21 62 osTimerId _timer_id;
alanffrench 0:52468b19aa21 63 osTimerDef_t _timer;
alanffrench 0:52468b19aa21 64 #ifdef CMSIS_OS_RTX
alanffrench 0:52468b19aa21 65 uint32_t _timer_data[5];
alanffrench 0:52468b19aa21 66 #endif
alanffrench 0:52468b19aa21 67 };
alanffrench 0:52468b19aa21 68
alanffrench 0:52468b19aa21 69 }
alanffrench 0:52468b19aa21 70
alanffrench 0:52468b19aa21 71 #endif