RTC auf true
rtos/TARGET_CORTEX/mbed_rtx_idle.cpp@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 | |
kevman | 0:38ceb79fef03 | 23 | #include "rtos/rtos_idle.h" |
kevman | 0:38ceb79fef03 | 24 | #include "platform/mbed_power_mgmt.h" |
kevman | 0:38ceb79fef03 | 25 | #include "TimerEvent.h" |
kevman | 0:38ceb79fef03 | 26 | #include "lp_ticker_api.h" |
kevman | 0:38ceb79fef03 | 27 | #include "mbed_critical.h" |
kevman | 0:38ceb79fef03 | 28 | #include "mbed_assert.h" |
kevman | 0:38ceb79fef03 | 29 | #include <new> |
kevman | 0:38ceb79fef03 | 30 | #include "rtx_os.h" |
kevman | 0:38ceb79fef03 | 31 | extern "C" { |
kevman | 0:38ceb79fef03 | 32 | #include "rtx_lib.h" |
kevman | 0:38ceb79fef03 | 33 | } |
kevman | 0:38ceb79fef03 | 34 | |
kevman | 0:38ceb79fef03 | 35 | using namespace mbed; |
kevman | 0:38ceb79fef03 | 36 | |
kevman | 0:38ceb79fef03 | 37 | #if (defined(MBED_TICKLESS) && defined(DEVICE_LPTICKER)) |
kevman | 0:38ceb79fef03 | 38 | |
kevman | 0:38ceb79fef03 | 39 | #include "rtos/TARGET_CORTEX/SysTimer.h" |
kevman | 0:38ceb79fef03 | 40 | |
kevman | 0:38ceb79fef03 | 41 | static rtos::internal::SysTimer *os_timer; |
kevman | 0:38ceb79fef03 | 42 | static uint64_t os_timer_data[sizeof(rtos::internal::SysTimer) / 8]; |
kevman | 0:38ceb79fef03 | 43 | |
kevman | 0:38ceb79fef03 | 44 | /// Enable System Timer. |
kevman | 0:38ceb79fef03 | 45 | void OS_Tick_Enable (void) |
kevman | 0:38ceb79fef03 | 46 | { |
kevman | 0:38ceb79fef03 | 47 | // Do not use SingletonPtr since this relies on the RTOS |
kevman | 0:38ceb79fef03 | 48 | if (NULL == os_timer) { |
kevman | 0:38ceb79fef03 | 49 | os_timer = new (os_timer_data) rtos::internal::SysTimer(); |
kevman | 0:38ceb79fef03 | 50 | os_timer->setup_irq(); |
kevman | 0:38ceb79fef03 | 51 | } |
kevman | 0:38ceb79fef03 | 52 | |
kevman | 0:38ceb79fef03 | 53 | // set to fire interrupt on next tick |
kevman | 0:38ceb79fef03 | 54 | os_timer->schedule_tick(); |
kevman | 0:38ceb79fef03 | 55 | } |
kevman | 0:38ceb79fef03 | 56 | |
kevman | 0:38ceb79fef03 | 57 | /// Disable System Timer. |
kevman | 0:38ceb79fef03 | 58 | void OS_Tick_Disable (void) |
kevman | 0:38ceb79fef03 | 59 | { |
kevman | 0:38ceb79fef03 | 60 | os_timer->cancel_tick(); |
kevman | 0:38ceb79fef03 | 61 | } |
kevman | 0:38ceb79fef03 | 62 | |
kevman | 0:38ceb79fef03 | 63 | /// Acknowledge System Timer IRQ. |
kevman | 0:38ceb79fef03 | 64 | void OS_Tick_AcknowledgeIRQ (void) |
kevman | 0:38ceb79fef03 | 65 | { |
kevman | 0:38ceb79fef03 | 66 | |
kevman | 0:38ceb79fef03 | 67 | } |
kevman | 0:38ceb79fef03 | 68 | |
kevman | 0:38ceb79fef03 | 69 | /// Get System Timer count. |
kevman | 0:38ceb79fef03 | 70 | uint32_t OS_Tick_GetCount (void) |
kevman | 0:38ceb79fef03 | 71 | { |
kevman | 0:38ceb79fef03 | 72 | return os_timer->get_time() & 0xFFFFFFFF; |
kevman | 0:38ceb79fef03 | 73 | } |
kevman | 0:38ceb79fef03 | 74 | |
kevman | 0:38ceb79fef03 | 75 | // Get OS Tick IRQ number. |
kevman | 0:38ceb79fef03 | 76 | int32_t OS_Tick_GetIRQn (void) { |
kevman | 0:38ceb79fef03 | 77 | return -1; |
kevman | 0:38ceb79fef03 | 78 | } |
kevman | 0:38ceb79fef03 | 79 | |
kevman | 0:38ceb79fef03 | 80 | // Get OS Tick overflow status. |
kevman | 0:38ceb79fef03 | 81 | uint32_t OS_Tick_GetOverflow (void) { |
kevman | 0:38ceb79fef03 | 82 | return 0; |
kevman | 0:38ceb79fef03 | 83 | } |
kevman | 0:38ceb79fef03 | 84 | |
kevman | 0:38ceb79fef03 | 85 | // Get OS Tick interval. |
kevman | 0:38ceb79fef03 | 86 | uint32_t OS_Tick_GetInterval (void) { |
kevman | 0:38ceb79fef03 | 87 | return 1000; |
kevman | 0:38ceb79fef03 | 88 | } |
kevman | 0:38ceb79fef03 | 89 | |
kevman | 0:38ceb79fef03 | 90 | static void default_idle_hook(void) |
kevman | 0:38ceb79fef03 | 91 | { |
kevman | 0:38ceb79fef03 | 92 | uint32_t ticks_to_sleep = osKernelSuspend(); |
kevman | 0:38ceb79fef03 | 93 | os_timer->suspend(ticks_to_sleep); |
kevman | 0:38ceb79fef03 | 94 | |
kevman | 0:38ceb79fef03 | 95 | bool event_pending = false; |
kevman | 0:38ceb79fef03 | 96 | while (!os_timer->suspend_time_passed() && !event_pending) { |
kevman | 0:38ceb79fef03 | 97 | |
kevman | 0:38ceb79fef03 | 98 | core_util_critical_section_enter(); |
kevman | 0:38ceb79fef03 | 99 | if (osRtxInfo.kernel.pendSV) { |
kevman | 0:38ceb79fef03 | 100 | event_pending = true; |
kevman | 0:38ceb79fef03 | 101 | } else { |
kevman | 0:38ceb79fef03 | 102 | sleep(); |
kevman | 0:38ceb79fef03 | 103 | } |
kevman | 0:38ceb79fef03 | 104 | core_util_critical_section_exit(); |
kevman | 0:38ceb79fef03 | 105 | |
kevman | 0:38ceb79fef03 | 106 | // Ensure interrupts get a chance to fire |
kevman | 0:38ceb79fef03 | 107 | __ISB(); |
kevman | 0:38ceb79fef03 | 108 | } |
kevman | 0:38ceb79fef03 | 109 | osKernelResume(os_timer->resume()); |
kevman | 0:38ceb79fef03 | 110 | } |
kevman | 0:38ceb79fef03 | 111 | |
kevman | 0:38ceb79fef03 | 112 | |
kevman | 0:38ceb79fef03 | 113 | #else |
kevman | 0:38ceb79fef03 | 114 | |
kevman | 0:38ceb79fef03 | 115 | static void default_idle_hook(void) |
kevman | 0:38ceb79fef03 | 116 | { |
kevman | 0:38ceb79fef03 | 117 | // critical section to complete sleep with locked deepsleep |
kevman | 0:38ceb79fef03 | 118 | core_util_critical_section_enter(); |
kevman | 0:38ceb79fef03 | 119 | sleep_manager_lock_deep_sleep(); |
kevman | 0:38ceb79fef03 | 120 | sleep(); |
kevman | 0:38ceb79fef03 | 121 | sleep_manager_unlock_deep_sleep(); |
kevman | 0:38ceb79fef03 | 122 | core_util_critical_section_exit(); |
kevman | 0:38ceb79fef03 | 123 | } |
kevman | 0:38ceb79fef03 | 124 | |
kevman | 0:38ceb79fef03 | 125 | #endif // (defined(MBED_TICKLESS) && defined(DEVICE_LPTICKER)) |
kevman | 0:38ceb79fef03 | 126 | |
kevman | 0:38ceb79fef03 | 127 | static void (*idle_hook_fptr)(void) = &default_idle_hook; |
kevman | 0:38ceb79fef03 | 128 | |
kevman | 0:38ceb79fef03 | 129 | void rtos_attach_idle_hook(void (*fptr)(void)) |
kevman | 0:38ceb79fef03 | 130 | { |
kevman | 0:38ceb79fef03 | 131 | //Attach the specified idle hook, or the default idle hook in case of a NULL pointer |
kevman | 0:38ceb79fef03 | 132 | if (fptr != NULL) { |
kevman | 0:38ceb79fef03 | 133 | idle_hook_fptr = fptr; |
kevman | 0:38ceb79fef03 | 134 | } else { |
kevman | 0:38ceb79fef03 | 135 | idle_hook_fptr = default_idle_hook; |
kevman | 0:38ceb79fef03 | 136 | } |
kevman | 0:38ceb79fef03 | 137 | } |
kevman | 0:38ceb79fef03 | 138 | |
kevman | 0:38ceb79fef03 | 139 | extern "C" void rtos_idle_loop(void) |
kevman | 0:38ceb79fef03 | 140 | { |
kevman | 0:38ceb79fef03 | 141 | //Continuously call the idle hook function pointer |
kevman | 0:38ceb79fef03 | 142 | while (1) { |
kevman | 0:38ceb79fef03 | 143 | idle_hook_fptr(); |
kevman | 0:38ceb79fef03 | 144 | } |
kevman | 0:38ceb79fef03 | 145 | } |