Code for controlling mbed hardware (LED's, motors), as well as code for the Raspberry Pi to run a Support Vector Machine that identifies objects using the Pi camera

Dependencies:   mbed Motordriver mbed-rtos PololuLedStrip

Committer:
arogliero3
Date:
Thu Dec 05 20:34:10 2019 -0500
Revision:
0:e0dbd261724a
Adding code to mbed repo

Who changed what in which revision?

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