Erste version der Software für der Prototyp

Committer:
borlanic
Date:
Thu Mar 29 07:02:09 2018 +0000
Revision:
0:380207fcb5c1
Encoder, IMU --> OK; Controller --> in bearbeitung

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:380207fcb5c1 1 /* mbed Microcontroller Library
borlanic 0:380207fcb5c1 2 * Copyright (c) 2006-2012 ARM Limited
borlanic 0:380207fcb5c1 3 *
borlanic 0:380207fcb5c1 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
borlanic 0:380207fcb5c1 5 * of this software and associated documentation files (the "Software"), to deal
borlanic 0:380207fcb5c1 6 * in the Software without restriction, including without limitation the rights
borlanic 0:380207fcb5c1 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
borlanic 0:380207fcb5c1 8 * copies of the Software, and to permit persons to whom the Software is
borlanic 0:380207fcb5c1 9 * furnished to do so, subject to the following conditions:
borlanic 0:380207fcb5c1 10 *
borlanic 0:380207fcb5c1 11 * The above copyright notice and this permission notice shall be included in
borlanic 0:380207fcb5c1 12 * all copies or substantial portions of the Software.
borlanic 0:380207fcb5c1 13 *
borlanic 0:380207fcb5c1 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
borlanic 0:380207fcb5c1 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
borlanic 0:380207fcb5c1 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
borlanic 0:380207fcb5c1 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
borlanic 0:380207fcb5c1 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
borlanic 0:380207fcb5c1 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
borlanic 0:380207fcb5c1 20 * SOFTWARE.
borlanic 0:380207fcb5c1 21 */
borlanic 0:380207fcb5c1 22 #ifndef RTOS_TIMER_H
borlanic 0:380207fcb5c1 23 #define RTOS_TIMER_H
borlanic 0:380207fcb5c1 24
borlanic 0:380207fcb5c1 25 #include <stdint.h>
borlanic 0:380207fcb5c1 26 #include "cmsis_os2.h"
borlanic 0:380207fcb5c1 27 #include "mbed_rtos_storage.h"
borlanic 0:380207fcb5c1 28 #include "platform/Callback.h"
borlanic 0:380207fcb5c1 29 #include "platform/NonCopyable.h"
borlanic 0:380207fcb5c1 30 #include "platform/mbed_toolchain.h"
borlanic 0:380207fcb5c1 31 #include "mbed_rtos1_types.h"
borlanic 0:380207fcb5c1 32
borlanic 0:380207fcb5c1 33 namespace rtos {
borlanic 0:380207fcb5c1 34 /** \addtogroup rtos */
borlanic 0:380207fcb5c1 35 /** @{*/
borlanic 0:380207fcb5c1 36 /**
borlanic 0:380207fcb5c1 37 * \defgroup rtos_RtosTimer RtosTimer class
borlanic 0:380207fcb5c1 38 * @{
borlanic 0:380207fcb5c1 39 */
borlanic 0:380207fcb5c1 40
borlanic 0:380207fcb5c1 41 /** The RtosTimer class allow creating and and controlling of timer functions in the system.
borlanic 0:380207fcb5c1 42 A timer function is called when a time period expires whereby both on-shot and
borlanic 0:380207fcb5c1 43 periodic timers are possible. A timer can be started, restarted, or stopped.
borlanic 0:380207fcb5c1 44
borlanic 0:380207fcb5c1 45 Timers are handled in the thread osTimerThread.
borlanic 0:380207fcb5c1 46 Callback functions run under control of this thread and may use CMSIS-RTOS API calls.
borlanic 0:380207fcb5c1 47
borlanic 0:380207fcb5c1 48 @deprecated
borlanic 0:380207fcb5c1 49 The RtosTimer has been superseded by the EventQueue. The RtosTimer and EventQueue duplicate
borlanic 0:380207fcb5c1 50 the functionality of timing events outside of interrupt context, however the EventQueue
borlanic 0:380207fcb5c1 51 has additional features to handle deferring other events to multiple contexts.
borlanic 0:380207fcb5c1 52
borlanic 0:380207fcb5c1 53 For an example, the following code shows a simple use of the RtosTimer:
borlanic 0:380207fcb5c1 54 @code
borlanic 0:380207fcb5c1 55 DigitalOut led(LED1);
borlanic 0:380207fcb5c1 56 void blink() {
borlanic 0:380207fcb5c1 57 led = !led;
borlanic 0:380207fcb5c1 58 }
borlanic 0:380207fcb5c1 59
borlanic 0:380207fcb5c1 60 RtosTimer timer(&blink);
borlanic 0:380207fcb5c1 61 int main() {
borlanic 0:380207fcb5c1 62 timer.start(1000); // call blink every 1s
borlanic 0:380207fcb5c1 63 wait_ms(5000);
borlanic 0:380207fcb5c1 64 timer.stop(); // stop after 5s
borlanic 0:380207fcb5c1 65 }
borlanic 0:380207fcb5c1 66 @endcode
borlanic 0:380207fcb5c1 67
borlanic 0:380207fcb5c1 68 This is the above example rewritten to use the EventQueue:
borlanic 0:380207fcb5c1 69 @code
borlanic 0:380207fcb5c1 70 DigitalOut led(LED1);
borlanic 0:380207fcb5c1 71 void blink() {
borlanic 0:380207fcb5c1 72 led = !led;
borlanic 0:380207fcb5c1 73 }
borlanic 0:380207fcb5c1 74
borlanic 0:380207fcb5c1 75 EventQueue queue(4*EVENTS_EVENT_SIZE);
borlanic 0:380207fcb5c1 76 int main() {
borlanic 0:380207fcb5c1 77 int blink_id = queue.call_every(1000, &blink); // call blink every 1s
borlanic 0:380207fcb5c1 78 queue.dispatch(5000);
borlanic 0:380207fcb5c1 79 queue.cancel(blink_id); // stop after 5s
borlanic 0:380207fcb5c1 80 }
borlanic 0:380207fcb5c1 81 @endcode
borlanic 0:380207fcb5c1 82
borlanic 0:380207fcb5c1 83 @note
borlanic 0:380207fcb5c1 84 Memory considerations: The timer control structures will be created on current thread's stack, both for the mbed OS
borlanic 0:380207fcb5c1 85 and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).
borlanic 0:380207fcb5c1 86 */
borlanic 0:380207fcb5c1 87 class RtosTimer : private mbed::NonCopyable<RtosTimer> {
borlanic 0:380207fcb5c1 88 public:
borlanic 0:380207fcb5c1 89 /** Create timer.
borlanic 0:380207fcb5c1 90 @param func function to be executed by this timer.
borlanic 0:380207fcb5c1 91 @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic)
borlanic 0:380207fcb5c1 92 @param argument argument to the timer call back function. (default: NULL)
borlanic 0:380207fcb5c1 93 @deprecated Replaced with RtosTimer(Callback<void()>, os_timer_type)
borlanic 0:380207fcb5c1 94 @deprecated
borlanic 0:380207fcb5c1 95 The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details
borlanic 0:380207fcb5c1 96
borlanic 0:380207fcb5c1 97 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 98 */
borlanic 0:380207fcb5c1 99 MBED_DEPRECATED_SINCE("mbed-os-5.1",
borlanic 0:380207fcb5c1 100 "Replaced with RtosTimer(Callback<void()>, os_timer_type)")
borlanic 0:380207fcb5c1 101 MBED_DEPRECATED_SINCE("mbed-os-5.2",
borlanic 0:380207fcb5c1 102 "The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details")
borlanic 0:380207fcb5c1 103 RtosTimer(void (*func)(void const *argument), os_timer_type type=osTimerPeriodic, void *argument=NULL) {
borlanic 0:380207fcb5c1 104 constructor(mbed::callback((void (*)(void *))func, argument), type);
borlanic 0:380207fcb5c1 105 }
borlanic 0:380207fcb5c1 106
borlanic 0:380207fcb5c1 107 /** Create timer.
borlanic 0:380207fcb5c1 108 @param func function to be executed by this timer.
borlanic 0:380207fcb5c1 109 @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic)
borlanic 0:380207fcb5c1 110 @deprecated
borlanic 0:380207fcb5c1 111 The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details
borlanic 0:380207fcb5c1 112
borlanic 0:380207fcb5c1 113 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 114 */
borlanic 0:380207fcb5c1 115 MBED_DEPRECATED_SINCE("mbed-os-5.2",
borlanic 0:380207fcb5c1 116 "The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details")
borlanic 0:380207fcb5c1 117 RtosTimer(mbed::Callback<void()> func, os_timer_type type=osTimerPeriodic) {
borlanic 0:380207fcb5c1 118 constructor(func, type);
borlanic 0:380207fcb5c1 119 }
borlanic 0:380207fcb5c1 120
borlanic 0:380207fcb5c1 121 /** Create timer.
borlanic 0:380207fcb5c1 122 @param obj pointer to the object to call the member function on.
borlanic 0:380207fcb5c1 123 @param method member function to be executed by this timer.
borlanic 0:380207fcb5c1 124 @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic)
borlanic 0:380207fcb5c1 125 @deprecated
borlanic 0:380207fcb5c1 126 The RtosTimer constructor does not support cv-qualifiers. Replaced by
borlanic 0:380207fcb5c1 127 RtosTimer(callback(obj, method), os_timer_type).
borlanic 0:380207fcb5c1 128 @deprecated
borlanic 0:380207fcb5c1 129 The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details
borlanic 0:380207fcb5c1 130
borlanic 0:380207fcb5c1 131 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 132 */
borlanic 0:380207fcb5c1 133 template <typename T, typename M>
borlanic 0:380207fcb5c1 134 MBED_DEPRECATED_SINCE("mbed-os-5.1",
borlanic 0:380207fcb5c1 135 "The RtosTimer constructor does not support cv-qualifiers. Replaced by "
borlanic 0:380207fcb5c1 136 "RtosTimer(callback(obj, method), os_timer_type).")
borlanic 0:380207fcb5c1 137 MBED_DEPRECATED_SINCE("mbed-os-5.2",
borlanic 0:380207fcb5c1 138 "The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details")
borlanic 0:380207fcb5c1 139 RtosTimer(T *obj, M method, os_timer_type type=osTimerPeriodic) {
borlanic 0:380207fcb5c1 140 constructor(mbed::callback(obj, method), type);
borlanic 0:380207fcb5c1 141 }
borlanic 0:380207fcb5c1 142
borlanic 0:380207fcb5c1 143 /** Stop the timer.
borlanic 0:380207fcb5c1 144 @return status code that indicates the execution status of the function:
borlanic 0:380207fcb5c1 145 @a osOK the timer has been stopped.
borlanic 0:380207fcb5c1 146 @a osErrorISR @a stop cannot be called from interrupt service routines.
borlanic 0:380207fcb5c1 147 @a osErrorParameter internal error.
borlanic 0:380207fcb5c1 148 @a osErrorResource the timer is not running.
borlanic 0:380207fcb5c1 149
borlanic 0:380207fcb5c1 150 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 151 */
borlanic 0:380207fcb5c1 152 osStatus stop(void);
borlanic 0:380207fcb5c1 153
borlanic 0:380207fcb5c1 154 /** Start or restart the timer.
borlanic 0:380207fcb5c1 155 @param millisec non-zero value of the timer.
borlanic 0:380207fcb5c1 156 @return status code that indicates the execution status of the function:
borlanic 0:380207fcb5c1 157 @a osOK the timer has been started or restarted.
borlanic 0:380207fcb5c1 158 @a osErrorISR @a start cannot be called from interrupt service routines.
borlanic 0:380207fcb5c1 159 @a osErrorParameter internal error or incorrect parameter value.
borlanic 0:380207fcb5c1 160 @a osErrorResource internal error (the timer is in an invalid timer state).
borlanic 0:380207fcb5c1 161
borlanic 0:380207fcb5c1 162 @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 163 */
borlanic 0:380207fcb5c1 164 osStatus start(uint32_t millisec);
borlanic 0:380207fcb5c1 165
borlanic 0:380207fcb5c1 166 /** RtosTimer destructor
borlanic 0:380207fcb5c1 167 *
borlanic 0:380207fcb5c1 168 * @note You cannot call this function from ISR context.
borlanic 0:380207fcb5c1 169 */
borlanic 0:380207fcb5c1 170 ~RtosTimer();
borlanic 0:380207fcb5c1 171
borlanic 0:380207fcb5c1 172 private:
borlanic 0:380207fcb5c1 173 // Required to share definitions without
borlanic 0:380207fcb5c1 174 // delegated constructors
borlanic 0:380207fcb5c1 175 void constructor(mbed::Callback<void()> func, os_timer_type type);
borlanic 0:380207fcb5c1 176
borlanic 0:380207fcb5c1 177 osTimerId_t _id;
borlanic 0:380207fcb5c1 178 mbed_rtos_storage_timer_t _obj_mem;
borlanic 0:380207fcb5c1 179 mbed::Callback<void()> _function;
borlanic 0:380207fcb5c1 180 };
borlanic 0:380207fcb5c1 181 /** @}*/
borlanic 0:380207fcb5c1 182 /** @}*/
borlanic 0:380207fcb5c1 183
borlanic 0:380207fcb5c1 184 }
borlanic 0:380207fcb5c1 185
borlanic 0:380207fcb5c1 186 #endif
borlanic 0:380207fcb5c1 187
borlanic 0:380207fcb5c1 188