diff --git a/rtos/TARGET_CORTEX/mbed_rtx_idle.cpp b/rtos/TARGET_CORTEX/mbed_rtx_idle.cpp index 78d03220b0..9c095396d0 100644 --- a/rtos/TARGET_CORTEX/mbed_rtx_idle.cpp +++ b/rtos/TARGET_CORTEX/mbed_rtx_idle.cpp @@ -33,131 +33,131 @@ extern "C" { #include "rtx_lib.h" -using namespace mbed; + using namespace mbed; #if (defined(MBED_TICKLESS) && defined(DEVICE_LPTICKER)) #include "rtos/TARGET_CORTEX/SysTimer.h" -static rtos::internal::SysTimer *os_timer; -static uint64_t os_timer_data[sizeof(rtos::internal::SysTimer) / 8]; + static rtos::internal::SysTimer *os_timer; + static uint64_t os_timer_data[sizeof(rtos::internal::SysTimer) / 8]; -/// Enable System Timer. -void OS_Tick_Enable(void) -{ - // Do not use SingletonPtr since this relies on the RTOS - if (NULL == os_timer) { - os_timer = new (os_timer_data) rtos::internal::SysTimer(); - os_timer->setup_irq(); - } - - // set to fire interrupt on next tick - os_timer->schedule_tick(); -} - -/// Disable System Timer. -void OS_Tick_Disable(void) -{ - os_timer->cancel_tick(); -} - -/// Acknowledge System Timer IRQ. -void OS_Tick_AcknowledgeIRQ(void) -{ - -} - -/// Get System Timer count. -uint32_t OS_Tick_GetCount(void) -{ - return os_timer->get_time() & 0xFFFFFFFF; -} - -// Get OS Tick IRQ number. -int32_t OS_Tick_GetIRQn(void) -{ - return -1; -} - -// Get OS Tick overflow status. -uint32_t OS_Tick_GetOverflow(void) -{ - return 0; -} - -// Get OS Tick interval. -uint32_t OS_Tick_GetInterval(void) -{ - return 1000; -} - -static void default_idle_hook(void) -{ - uint32_t ticks_to_sleep = osKernelSuspend(); - const bool block_deep_sleep = ticks_to_sleep <= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY; - - if (block_deep_sleep) { - sleep_manager_lock_deep_sleep(); - } else { - ticks_to_sleep -= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY; - } - os_timer->suspend(ticks_to_sleep); - - bool event_pending = false; - while (!os_timer->suspend_time_passed() && !event_pending) { - - core_util_critical_section_enter(); - if (osRtxInfo.kernel.pendSV) { - event_pending = true; - } else { - sleep(); + // Enable System Timer. + void OS_Tick_Enable(void) + { + // Do not use SingletonPtr since this relies on the RTOS + if (NULL == os_timer) { + os_timer = new (os_timer_data) rtos::internal::SysTimer(); + os_timer->setup_irq(); } - core_util_critical_section_exit(); - // Ensure interrupts get a chance to fire - __ISB(); + // set to fire interrupt on next tick + os_timer->schedule_tick(); } - if (block_deep_sleep) { - sleep_manager_unlock_deep_sleep(); + // Disable System Timer. + void OS_Tick_Disable(void) + { + os_timer->cancel_tick(); } - osKernelResume(os_timer->resume()); -} + // Acknowledge System Timer IRQ. + void OS_Tick_AcknowledgeIRQ(void) + { + + } + + // Get System Timer count. + uint32_t OS_Tick_GetCount(void) + { + return os_timer->get_time() & 0xFFFFFFFF; + } + + // Get OS Tick IRQ number. + int32_t OS_Tick_GetIRQn(void) + { + return -1; + } + + // Get OS Tick overflow status. + uint32_t OS_Tick_GetOverflow(void) + { + return 0; + } + + // Get OS Tick interval. + uint32_t OS_Tick_GetInterval(void) + { + return 1000; + } + + static void default_idle_hook(void) + { + uint32_t ticks_to_sleep = osKernelSuspend(); + const bool block_deep_sleep = ticks_to_sleep <= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY; + + if (block_deep_sleep) { + sleep_manager_lock_deep_sleep(); + } else { + ticks_to_sleep -= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY; + } + os_timer->suspend(ticks_to_sleep); + + bool event_pending = false; + while (!os_timer->suspend_time_passed() && !event_pending) { + + core_util_critical_section_enter(); + if (osRtxInfo.kernel.pendSV) { + event_pending = true; + } else { + sleep(); + } + core_util_critical_section_exit(); + + // Ensure interrupts get a chance to fire + __ISB(); + } + + if (block_deep_sleep) { + sleep_manager_unlock_deep_sleep(); + } + + osKernelResume(os_timer->resume()); + } #else -static void default_idle_hook(void) -{ - // critical section to complete sleep with locked deepsleep - core_util_critical_section_enter(); - sleep_manager_lock_deep_sleep(); - sleep(); - sleep_manager_unlock_deep_sleep(); - core_util_critical_section_exit(); -} + static void default_idle_hook(void) + { + // critical section to complete sleep with locked deepsleep + core_util_critical_section_enter(); + sleep_manager_lock_deep_sleep(); + sleep(); + sleep_manager_unlock_deep_sleep(); + core_util_critical_section_exit(); + } #endif // (defined(MBED_TICKLESS) && defined(DEVICE_LPTICKER)) -static void (*idle_hook_fptr)(void) = &default_idle_hook; + static void (*idle_hook_fptr)(void) = &default_idle_hook; -void rtos_attach_idle_hook(void (*fptr)(void)) -{ - //Attach the specified idle hook, or the default idle hook in case of a NULL pointer - if (fptr != NULL) { - idle_hook_fptr = fptr; - } else { - idle_hook_fptr = default_idle_hook; + void rtos_attach_idle_hook(void (*fptr)(void)) + { + //Attach the specified idle hook, or the default idle hook in case of a NULL pointer + if (fptr != NULL) { + idle_hook_fptr = fptr; + } else { + idle_hook_fptr = default_idle_hook; + } } -} -MBED_NORETURN void rtos_idle_loop(void) -{ - //Continuously call the idle hook function pointer - while (1) { - idle_hook_fptr(); + MBED_NORETURN void rtos_idle_loop(void) + { + //Continuously call the idle hook function pointer + while (1) { + idle_hook_fptr(); + } } -} } // extern "C"