rtx idle: fix coding style

pull/8711/head
Martin Kojtal 2018-11-12 09:30:51 +00:00
parent 9a0651c7fb
commit 830f7464cc
1 changed files with 103 additions and 103 deletions

View File

@ -33,131 +33,131 @@
extern "C" { extern "C" {
#include "rtx_lib.h" #include "rtx_lib.h"
using namespace mbed; using namespace mbed;
#if (defined(MBED_TICKLESS) && defined(DEVICE_LPTICKER)) #if (defined(MBED_TICKLESS) && defined(DEVICE_LPTICKER))
#include "rtos/TARGET_CORTEX/SysTimer.h" #include "rtos/TARGET_CORTEX/SysTimer.h"
static rtos::internal::SysTimer *os_timer; static rtos::internal::SysTimer *os_timer;
static uint64_t os_timer_data[sizeof(rtos::internal::SysTimer) / 8]; static uint64_t os_timer_data[sizeof(rtos::internal::SysTimer) / 8];
/// Enable System Timer. // Enable System Timer.
void OS_Tick_Enable(void) void OS_Tick_Enable(void)
{ {
// Do not use SingletonPtr since this relies on the RTOS // Do not use SingletonPtr since this relies on the RTOS
if (NULL == os_timer) { if (NULL == os_timer) {
os_timer = new (os_timer_data) rtos::internal::SysTimer(); os_timer = new (os_timer_data) rtos::internal::SysTimer();
os_timer->setup_irq(); 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();
} }
core_util_critical_section_exit();
// Ensure interrupts get a chance to fire // set to fire interrupt on next tick
__ISB(); os_timer->schedule_tick();
} }
if (block_deep_sleep) { // Disable System Timer.
sleep_manager_unlock_deep_sleep(); 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 #else
static void default_idle_hook(void) static void default_idle_hook(void)
{ {
// critical section to complete sleep with locked deepsleep // critical section to complete sleep with locked deepsleep
core_util_critical_section_enter(); core_util_critical_section_enter();
sleep_manager_lock_deep_sleep(); sleep_manager_lock_deep_sleep();
sleep(); sleep();
sleep_manager_unlock_deep_sleep(); sleep_manager_unlock_deep_sleep();
core_util_critical_section_exit(); core_util_critical_section_exit();
} }
#endif // (defined(MBED_TICKLESS) && defined(DEVICE_LPTICKER)) #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)) void rtos_attach_idle_hook(void (*fptr)(void))
{ {
//Attach the specified idle hook, or the default idle hook in case of a NULL pointer //Attach the specified idle hook, or the default idle hook in case of a NULL pointer
if (fptr != NULL) { if (fptr != NULL) {
idle_hook_fptr = fptr; idle_hook_fptr = fptr;
} else { } else {
idle_hook_fptr = default_idle_hook; idle_hook_fptr = default_idle_hook;
}
} }
}
MBED_NORETURN void rtos_idle_loop(void) MBED_NORETURN void rtos_idle_loop(void)
{ {
//Continuously call the idle hook function pointer //Continuously call the idle hook function pointer
while (1) { while (1) {
idle_hook_fptr(); idle_hook_fptr();
}
} }
}
} // extern "C" } // extern "C"