RTC auf true
rtos/TARGET_CORTEX/SysTimer.h@2:7aab896b1a3b, 2019-03-13 (annotated)
- Committer:
- kevman
- Date:
- Wed Mar 13 11:03:24 2019 +0000
- Revision:
- 2:7aab896b1a3b
- Parent:
- 0:38ceb79fef03
2019-03-13
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kevman | 0:38ceb79fef03 | 1 | /* mbed Microcontroller Library |
kevman | 0:38ceb79fef03 | 2 | * Copyright (c) 2006-2012 ARM Limited |
kevman | 0:38ceb79fef03 | 3 | * |
kevman | 0:38ceb79fef03 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
kevman | 0:38ceb79fef03 | 5 | * of this software and associated documentation files (the "Software"), to deal |
kevman | 0:38ceb79fef03 | 6 | * in the Software without restriction, including without limitation the rights |
kevman | 0:38ceb79fef03 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
kevman | 0:38ceb79fef03 | 8 | * copies of the Software, and to permit persons to whom the Software is |
kevman | 0:38ceb79fef03 | 9 | * furnished to do so, subject to the following conditions: |
kevman | 0:38ceb79fef03 | 10 | * |
kevman | 0:38ceb79fef03 | 11 | * The above copyright notice and this permission notice shall be included in |
kevman | 0:38ceb79fef03 | 12 | * all copies or substantial portions of the Software. |
kevman | 0:38ceb79fef03 | 13 | * |
kevman | 0:38ceb79fef03 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
kevman | 0:38ceb79fef03 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
kevman | 0:38ceb79fef03 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
kevman | 0:38ceb79fef03 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
kevman | 0:38ceb79fef03 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kevman | 0:38ceb79fef03 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
kevman | 0:38ceb79fef03 | 20 | * SOFTWARE. |
kevman | 0:38ceb79fef03 | 21 | */ |
kevman | 0:38ceb79fef03 | 22 | #ifndef MBED_SYS_TIMER_H |
kevman | 0:38ceb79fef03 | 23 | #define MBED_SYS_TIMER_H |
kevman | 0:38ceb79fef03 | 24 | |
kevman | 0:38ceb79fef03 | 25 | #if defined(DEVICE_LPTICKER) || defined(DOXYGEN_ONLY) |
kevman | 0:38ceb79fef03 | 26 | |
kevman | 0:38ceb79fef03 | 27 | #include "platform/NonCopyable.h" |
kevman | 0:38ceb79fef03 | 28 | #include "drivers/TimerEvent.h" |
kevman | 0:38ceb79fef03 | 29 | |
kevman | 0:38ceb79fef03 | 30 | namespace rtos { |
kevman | 0:38ceb79fef03 | 31 | namespace internal { |
kevman | 0:38ceb79fef03 | 32 | |
kevman | 0:38ceb79fef03 | 33 | /** |
kevman | 0:38ceb79fef03 | 34 | * @cond RTOS_INTERNAL |
kevman | 0:38ceb79fef03 | 35 | * |
kevman | 0:38ceb79fef03 | 36 | * @addtogroup rtos |
kevman | 0:38ceb79fef03 | 37 | * @{ |
kevman | 0:38ceb79fef03 | 38 | * |
kevman | 0:38ceb79fef03 | 39 | * @defgroup rtos_SysTimer SysTimer class |
kevman | 0:38ceb79fef03 | 40 | * @{ |
kevman | 0:38ceb79fef03 | 41 | */ |
kevman | 0:38ceb79fef03 | 42 | |
kevman | 0:38ceb79fef03 | 43 | /** |
kevman | 0:38ceb79fef03 | 44 | * The SysTimer class is used exclusively by RTX idle loop in TICKLESS mode. |
kevman | 0:38ceb79fef03 | 45 | * |
kevman | 0:38ceb79fef03 | 46 | * @note SysTimer is not the part of Mbed RTOS API. |
kevman | 0:38ceb79fef03 | 47 | */ |
kevman | 0:38ceb79fef03 | 48 | class SysTimer: private mbed::TimerEvent, private mbed::NonCopyable<SysTimer> { |
kevman | 0:38ceb79fef03 | 49 | public: |
kevman | 0:38ceb79fef03 | 50 | |
kevman | 0:38ceb79fef03 | 51 | SysTimer(); |
kevman | 0:38ceb79fef03 | 52 | SysTimer(const ticker_data_t *data); |
kevman | 0:38ceb79fef03 | 53 | virtual ~SysTimer(); |
kevman | 0:38ceb79fef03 | 54 | |
kevman | 0:38ceb79fef03 | 55 | /** |
kevman | 0:38ceb79fef03 | 56 | * Enable an IRQ/SysTick with the correct priority. |
kevman | 0:38ceb79fef03 | 57 | */ |
kevman | 0:38ceb79fef03 | 58 | static void setup_irq(); |
kevman | 0:38ceb79fef03 | 59 | |
kevman | 0:38ceb79fef03 | 60 | /** |
kevman | 0:38ceb79fef03 | 61 | * Set wakeup time and schedule a wakeup event after delta ticks |
kevman | 0:38ceb79fef03 | 62 | * |
kevman | 0:38ceb79fef03 | 63 | * After suspend has been called the function suspend_time_passed |
kevman | 0:38ceb79fef03 | 64 | * can be used to determine if the suspend time has passed. |
kevman | 0:38ceb79fef03 | 65 | * |
kevman | 0:38ceb79fef03 | 66 | * @param delta Ticks to remain suspended |
kevman | 0:38ceb79fef03 | 67 | */ |
kevman | 0:38ceb79fef03 | 68 | void suspend(uint32_t delta); |
kevman | 0:38ceb79fef03 | 69 | |
kevman | 0:38ceb79fef03 | 70 | /** |
kevman | 0:38ceb79fef03 | 71 | * Check if the suspend time has passed |
kevman | 0:38ceb79fef03 | 72 | * |
kevman | 0:38ceb79fef03 | 73 | * @return true if the specified number of ticks has passed otherwise false |
kevman | 0:38ceb79fef03 | 74 | */ |
kevman | 0:38ceb79fef03 | 75 | bool suspend_time_passed(); |
kevman | 0:38ceb79fef03 | 76 | |
kevman | 0:38ceb79fef03 | 77 | /** |
kevman | 0:38ceb79fef03 | 78 | * Exit suspend mode and return elapsed ticks |
kevman | 0:38ceb79fef03 | 79 | * |
kevman | 0:38ceb79fef03 | 80 | * Due to a scheduling issue, the number of ticks returned is decremented |
kevman | 0:38ceb79fef03 | 81 | * by 1 so that a handler can be called and update to the current value. |
kevman | 0:38ceb79fef03 | 82 | * This allows scheduling restart successfully after the OS is resumed. |
kevman | 0:38ceb79fef03 | 83 | * |
kevman | 0:38ceb79fef03 | 84 | * @return the number of elapsed ticks minus 1 |
kevman | 0:38ceb79fef03 | 85 | */ |
kevman | 0:38ceb79fef03 | 86 | uint32_t resume(); |
kevman | 0:38ceb79fef03 | 87 | |
kevman | 0:38ceb79fef03 | 88 | /** |
kevman | 0:38ceb79fef03 | 89 | * Schedule an os tick to fire |
kevman | 0:38ceb79fef03 | 90 | * |
kevman | 0:38ceb79fef03 | 91 | * @param delta Tick to fire at relative to current tick |
kevman | 0:38ceb79fef03 | 92 | * |
kevman | 0:38ceb79fef03 | 93 | * @warning If a tick is already scheduled it needs to be cancelled first! |
kevman | 0:38ceb79fef03 | 94 | */ |
kevman | 0:38ceb79fef03 | 95 | void schedule_tick(uint32_t delta = 1); |
kevman | 0:38ceb79fef03 | 96 | |
kevman | 0:38ceb79fef03 | 97 | /** |
kevman | 0:38ceb79fef03 | 98 | * Prevent any scheduled ticks from triggering |
kevman | 0:38ceb79fef03 | 99 | */ |
kevman | 0:38ceb79fef03 | 100 | void cancel_tick(); |
kevman | 0:38ceb79fef03 | 101 | |
kevman | 0:38ceb79fef03 | 102 | /** Get the current tick count |
kevman | 0:38ceb79fef03 | 103 | * |
kevman | 0:38ceb79fef03 | 104 | * @return The number of ticks since timer creation. For the os_timer this |
kevman | 0:38ceb79fef03 | 105 | * should match RTX's tick count (the number of ticks since boot). |
kevman | 0:38ceb79fef03 | 106 | */ |
kevman | 0:38ceb79fef03 | 107 | uint32_t get_tick(); |
kevman | 0:38ceb79fef03 | 108 | |
kevman | 0:38ceb79fef03 | 109 | /** |
kevman | 0:38ceb79fef03 | 110 | * Get the time |
kevman | 0:38ceb79fef03 | 111 | * |
kevman | 0:38ceb79fef03 | 112 | * @return Current time in microseconds |
kevman | 0:38ceb79fef03 | 113 | */ |
kevman | 0:38ceb79fef03 | 114 | us_timestamp_t get_time(); |
kevman | 0:38ceb79fef03 | 115 | |
kevman | 0:38ceb79fef03 | 116 | protected: |
kevman | 0:38ceb79fef03 | 117 | virtual void handler(); |
kevman | 0:38ceb79fef03 | 118 | void _increment_tick(); |
kevman | 0:38ceb79fef03 | 119 | static void _set_irq_pending(); |
kevman | 0:38ceb79fef03 | 120 | us_timestamp_t _start_time; |
kevman | 0:38ceb79fef03 | 121 | uint64_t _tick; |
kevman | 0:38ceb79fef03 | 122 | bool _suspend_time_passed; |
kevman | 0:38ceb79fef03 | 123 | bool _suspended; |
kevman | 0:38ceb79fef03 | 124 | }; |
kevman | 0:38ceb79fef03 | 125 | |
kevman | 0:38ceb79fef03 | 126 | /** |
kevman | 0:38ceb79fef03 | 127 | * @} |
kevman | 0:38ceb79fef03 | 128 | * @} |
kevman | 0:38ceb79fef03 | 129 | * @endcond |
kevman | 0:38ceb79fef03 | 130 | */ |
kevman | 0:38ceb79fef03 | 131 | |
kevman | 0:38ceb79fef03 | 132 | } |
kevman | 0:38ceb79fef03 | 133 | } |
kevman | 0:38ceb79fef03 | 134 | |
kevman | 0:38ceb79fef03 | 135 | #endif |
kevman | 0:38ceb79fef03 | 136 | |
kevman | 0:38ceb79fef03 | 137 | #endif |