5.2.1 - Updated I2C files
Dependents: mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510
rtos/RtosTimer.h@1:f30bdcd2b33b, 2017-02-27 (annotated)
- Committer:
- jacobjohnson
- Date:
- Mon Feb 27 17:45:05 2017 +0000
- Revision:
- 1:f30bdcd2b33b
- Parent:
- 0:098463de4c5d
changed the inputscale from 1 to 7 in analogin_api.c. This will need to be changed later, and accessed from the main level, but for now this allows the adc to read a value from 0 to 3.7V, instead of just up to 1V.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
group-onsemi | 0:098463de4c5d | 1 | /* mbed Microcontroller Library |
group-onsemi | 0:098463de4c5d | 2 | * Copyright (c) 2006-2012 ARM Limited |
group-onsemi | 0:098463de4c5d | 3 | * |
group-onsemi | 0:098463de4c5d | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
group-onsemi | 0:098463de4c5d | 5 | * of this software and associated documentation files (the "Software"), to deal |
group-onsemi | 0:098463de4c5d | 6 | * in the Software without restriction, including without limitation the rights |
group-onsemi | 0:098463de4c5d | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
group-onsemi | 0:098463de4c5d | 8 | * copies of the Software, and to permit persons to whom the Software is |
group-onsemi | 0:098463de4c5d | 9 | * furnished to do so, subject to the following conditions: |
group-onsemi | 0:098463de4c5d | 10 | * |
group-onsemi | 0:098463de4c5d | 11 | * The above copyright notice and this permission notice shall be included in |
group-onsemi | 0:098463de4c5d | 12 | * all copies or substantial portions of the Software. |
group-onsemi | 0:098463de4c5d | 13 | * |
group-onsemi | 0:098463de4c5d | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
group-onsemi | 0:098463de4c5d | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
group-onsemi | 0:098463de4c5d | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
group-onsemi | 0:098463de4c5d | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
group-onsemi | 0:098463de4c5d | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
group-onsemi | 0:098463de4c5d | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
group-onsemi | 0:098463de4c5d | 20 | * SOFTWARE. |
group-onsemi | 0:098463de4c5d | 21 | */ |
group-onsemi | 0:098463de4c5d | 22 | #ifndef RTOS_TIMER_H |
group-onsemi | 0:098463de4c5d | 23 | #define RTOS_TIMER_H |
group-onsemi | 0:098463de4c5d | 24 | |
group-onsemi | 0:098463de4c5d | 25 | #include <stdint.h> |
group-onsemi | 0:098463de4c5d | 26 | #include "cmsis_os.h" |
group-onsemi | 0:098463de4c5d | 27 | #include "platform/Callback.h" |
group-onsemi | 0:098463de4c5d | 28 | #include "platform/toolchain.h" |
group-onsemi | 0:098463de4c5d | 29 | |
group-onsemi | 0:098463de4c5d | 30 | namespace rtos { |
group-onsemi | 0:098463de4c5d | 31 | /** \addtogroup rtos */ |
group-onsemi | 0:098463de4c5d | 32 | /** @{*/ |
group-onsemi | 0:098463de4c5d | 33 | |
group-onsemi | 0:098463de4c5d | 34 | /** The RtosTimer class allow creating and and controlling of timer functions in the system. |
group-onsemi | 0:098463de4c5d | 35 | A timer function is called when a time period expires whereby both on-shot and |
group-onsemi | 0:098463de4c5d | 36 | periodic timers are possible. A timer can be started, restarted, or stopped. |
group-onsemi | 0:098463de4c5d | 37 | |
group-onsemi | 0:098463de4c5d | 38 | Timers are handled in the thread osTimerThread. |
group-onsemi | 0:098463de4c5d | 39 | Callback functions run under control of this thread and may use CMSIS-RTOS API calls. |
group-onsemi | 0:098463de4c5d | 40 | |
group-onsemi | 0:098463de4c5d | 41 | @deprecated |
group-onsemi | 0:098463de4c5d | 42 | The RtosTimer has been superseded by the EventQueue. The RtosTimer and EventQueue duplicate |
group-onsemi | 0:098463de4c5d | 43 | the functionality of timing events outside of interrupt context, however the EventQueue |
group-onsemi | 0:098463de4c5d | 44 | has additional features to handle deferring other events to multiple contexts. |
group-onsemi | 0:098463de4c5d | 45 | |
group-onsemi | 0:098463de4c5d | 46 | For an example, the following code shows a simple use of the RtosTimer: |
group-onsemi | 0:098463de4c5d | 47 | @code |
group-onsemi | 0:098463de4c5d | 48 | DigitalOut led(LED1); |
group-onsemi | 0:098463de4c5d | 49 | void blink() { |
group-onsemi | 0:098463de4c5d | 50 | led = !led; |
group-onsemi | 0:098463de4c5d | 51 | } |
group-onsemi | 0:098463de4c5d | 52 | |
group-onsemi | 0:098463de4c5d | 53 | RtosTimer timer(&blink); |
group-onsemi | 0:098463de4c5d | 54 | int main() { |
group-onsemi | 0:098463de4c5d | 55 | timer.start(1000); // call blink every 1s |
group-onsemi | 0:098463de4c5d | 56 | wait_ms(5000); |
group-onsemi | 0:098463de4c5d | 57 | timer.stop(); // stop after 5s |
group-onsemi | 0:098463de4c5d | 58 | } |
group-onsemi | 0:098463de4c5d | 59 | @endcode |
group-onsemi | 0:098463de4c5d | 60 | |
group-onsemi | 0:098463de4c5d | 61 | This is the above example rewritten to use the EventQueue: |
group-onsemi | 0:098463de4c5d | 62 | @code |
group-onsemi | 0:098463de4c5d | 63 | DigitalOut led(LED1); |
group-onsemi | 0:098463de4c5d | 64 | void blink() { |
group-onsemi | 0:098463de4c5d | 65 | led = !led; |
group-onsemi | 0:098463de4c5d | 66 | } |
group-onsemi | 0:098463de4c5d | 67 | |
group-onsemi | 0:098463de4c5d | 68 | EventQueue queue(4*EVENTS_EVENT_SIZE); |
group-onsemi | 0:098463de4c5d | 69 | int main() { |
group-onsemi | 0:098463de4c5d | 70 | int blink_id = queue.call_every(1000, &blink); // call blink every 1s |
group-onsemi | 0:098463de4c5d | 71 | queue.dispatch(5000); |
group-onsemi | 0:098463de4c5d | 72 | queue.cancel(blink_id); // stop after 5s |
group-onsemi | 0:098463de4c5d | 73 | } |
group-onsemi | 0:098463de4c5d | 74 | @endcode |
group-onsemi | 0:098463de4c5d | 75 | */ |
group-onsemi | 0:098463de4c5d | 76 | class RtosTimer { |
group-onsemi | 0:098463de4c5d | 77 | public: |
group-onsemi | 0:098463de4c5d | 78 | /** Create timer. |
group-onsemi | 0:098463de4c5d | 79 | @param func function to be executed by this timer. |
group-onsemi | 0:098463de4c5d | 80 | @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic) |
group-onsemi | 0:098463de4c5d | 81 | @param argument argument to the timer call back function. (default: NULL) |
group-onsemi | 0:098463de4c5d | 82 | @deprecated Replaced with RtosTimer(Callback<void()>, os_timer_type) |
group-onsemi | 0:098463de4c5d | 83 | @deprecated |
group-onsemi | 0:098463de4c5d | 84 | The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details |
group-onsemi | 0:098463de4c5d | 85 | */ |
group-onsemi | 0:098463de4c5d | 86 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
group-onsemi | 0:098463de4c5d | 87 | "Replaced with RtosTimer(Callback<void()>, os_timer_type)") |
group-onsemi | 0:098463de4c5d | 88 | MBED_DEPRECATED_SINCE("mbed-os-5.2", |
group-onsemi | 0:098463de4c5d | 89 | "The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details") |
group-onsemi | 0:098463de4c5d | 90 | RtosTimer(void (*func)(void const *argument), os_timer_type type=osTimerPeriodic, void *argument=NULL) { |
group-onsemi | 0:098463de4c5d | 91 | constructor(mbed::callback((void (*)(void *))func, argument), type); |
group-onsemi | 0:098463de4c5d | 92 | } |
group-onsemi | 0:098463de4c5d | 93 | |
group-onsemi | 0:098463de4c5d | 94 | /** Create timer. |
group-onsemi | 0:098463de4c5d | 95 | @param func function to be executed by this timer. |
group-onsemi | 0:098463de4c5d | 96 | @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic) |
group-onsemi | 0:098463de4c5d | 97 | @deprecated |
group-onsemi | 0:098463de4c5d | 98 | The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details |
group-onsemi | 0:098463de4c5d | 99 | */ |
group-onsemi | 0:098463de4c5d | 100 | MBED_DEPRECATED_SINCE("mbed-os-5.2", |
group-onsemi | 0:098463de4c5d | 101 | "The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details") |
group-onsemi | 0:098463de4c5d | 102 | RtosTimer(mbed::Callback<void()> func, os_timer_type type=osTimerPeriodic) { |
group-onsemi | 0:098463de4c5d | 103 | constructor(func, type); |
group-onsemi | 0:098463de4c5d | 104 | } |
group-onsemi | 0:098463de4c5d | 105 | |
group-onsemi | 0:098463de4c5d | 106 | /** Create timer. |
group-onsemi | 0:098463de4c5d | 107 | @param obj pointer to the object to call the member function on. |
group-onsemi | 0:098463de4c5d | 108 | @param method member function to be executed by this timer. |
group-onsemi | 0:098463de4c5d | 109 | @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic) |
group-onsemi | 0:098463de4c5d | 110 | @deprecated |
group-onsemi | 0:098463de4c5d | 111 | The RtosTimer constructor does not support cv-qualifiers. Replaced by |
group-onsemi | 0:098463de4c5d | 112 | RtosTimer(callback(obj, method), os_timer_type). |
group-onsemi | 0:098463de4c5d | 113 | @deprecated |
group-onsemi | 0:098463de4c5d | 114 | The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details |
group-onsemi | 0:098463de4c5d | 115 | */ |
group-onsemi | 0:098463de4c5d | 116 | template <typename T, typename M> |
group-onsemi | 0:098463de4c5d | 117 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
group-onsemi | 0:098463de4c5d | 118 | "The RtosTimer constructor does not support cv-qualifiers. Replaced by " |
group-onsemi | 0:098463de4c5d | 119 | "RtosTimer(callback(obj, method), os_timer_type).") |
group-onsemi | 0:098463de4c5d | 120 | MBED_DEPRECATED_SINCE("mbed-os-5.2", |
group-onsemi | 0:098463de4c5d | 121 | "The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details") |
group-onsemi | 0:098463de4c5d | 122 | RtosTimer(T *obj, M method, os_timer_type type=osTimerPeriodic) { |
group-onsemi | 0:098463de4c5d | 123 | constructor(mbed::callback(obj, method), type); |
group-onsemi | 0:098463de4c5d | 124 | } |
group-onsemi | 0:098463de4c5d | 125 | |
group-onsemi | 0:098463de4c5d | 126 | /** Stop the timer. |
group-onsemi | 0:098463de4c5d | 127 | @return status code that indicates the execution status of the function. |
group-onsemi | 0:098463de4c5d | 128 | */ |
group-onsemi | 0:098463de4c5d | 129 | osStatus stop(void); |
group-onsemi | 0:098463de4c5d | 130 | |
group-onsemi | 0:098463de4c5d | 131 | /** Start the timer. |
group-onsemi | 0:098463de4c5d | 132 | @param millisec time delay value of the timer. |
group-onsemi | 0:098463de4c5d | 133 | @return status code that indicates the execution status of the function. |
group-onsemi | 0:098463de4c5d | 134 | */ |
group-onsemi | 0:098463de4c5d | 135 | osStatus start(uint32_t millisec); |
group-onsemi | 0:098463de4c5d | 136 | |
group-onsemi | 0:098463de4c5d | 137 | ~RtosTimer(); |
group-onsemi | 0:098463de4c5d | 138 | |
group-onsemi | 0:098463de4c5d | 139 | private: |
group-onsemi | 0:098463de4c5d | 140 | // Required to share definitions without |
group-onsemi | 0:098463de4c5d | 141 | // delegated constructors |
group-onsemi | 0:098463de4c5d | 142 | void constructor(mbed::Callback<void()> func, os_timer_type type); |
group-onsemi | 0:098463de4c5d | 143 | |
group-onsemi | 0:098463de4c5d | 144 | mbed::Callback<void()> _function; |
group-onsemi | 0:098463de4c5d | 145 | osTimerId _timer_id; |
group-onsemi | 0:098463de4c5d | 146 | osTimerDef_t _timer; |
group-onsemi | 0:098463de4c5d | 147 | #ifdef CMSIS_OS_RTX |
group-onsemi | 0:098463de4c5d | 148 | uint32_t _timer_data[6]; |
group-onsemi | 0:098463de4c5d | 149 | #endif |
group-onsemi | 0:098463de4c5d | 150 | }; |
group-onsemi | 0:098463de4c5d | 151 | |
group-onsemi | 0:098463de4c5d | 152 | } |
group-onsemi | 0:098463de4c5d | 153 | |
group-onsemi | 0:098463de4c5d | 154 | #endif |
group-onsemi | 0:098463de4c5d | 155 | |
group-onsemi | 0:098463de4c5d | 156 | /** @}*/ |