From e8c135e2bb927e47b76930b0aa75d156046566a3 Mon Sep 17 00:00:00 2001 From: daishengdong Date: Mon, 27 Apr 2020 15:12:08 +0800 Subject: [PATCH] timer & tickless bugfix 1. fix a bug of timer_update when TOS_CFG_TIMER_AS_PROC > 0u 2. support disable tickless in runtime 3. fix a header file dependency bug, which cause k_tick_t typedef-ed to uint32_t 4. fix tick_count drift in tickless_proc --- kernel/core/include/tos_config_check.h | 16 ---------------- kernel/core/include/tos_k.h | 4 ++-- kernel/core/tos_global.c | 3 +-- kernel/core/tos_timer.c | 2 +- kernel/pm/include/tos_pm.h | 3 ++- kernel/pm/tos_tickless.c | 14 ++++++++++++++ 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/kernel/core/include/tos_config_check.h b/kernel/core/include/tos_config_check.h index 1b5cf22a..087e6ccf 100644 --- a/kernel/core/include/tos_config_check.h +++ b/kernel/core/include/tos_config_check.h @@ -40,18 +40,6 @@ #error "INVALID config, TOS_CFG_TASK_PRIO_MAX must be >= 8" #endif -#if (TOS_CFG_TASK_DYNAMIC_CREATE_EN > 0u) && (TOS_CFG_MMHEAP_EN == 0u) -#error "INVALID config, must enable TOS_CFG_MMHEAP_EN to support dynamic task create" -#endif - -#if (TOS_CFG_PRIORITY_MESSAGE_QUEUE_EN > 0u) && (TOS_CFG_MMHEAP_EN == 0u) -#error "INVALID config, must enable TOS_CFG_MMHEAP_EN to support tos_prio_msg_q" -#endif - -#if (TOS_CFG_PRIORITY_MAIL_QUEUE_EN > 0u) && (TOS_CFG_MMHEAP_EN == 0u) -#error "INVALID config, must enable TOS_CFG_MMHEAP_EN to support tos_prio_mail_q" -#endif - #if ((TOS_CFG_TIMER_EN > 0u) && !defined(TOS_CFG_TIMER_AS_PROC)) #error "UNDECLARED config, TOS_CFG_TIMER_AS_PROC" #endif @@ -62,10 +50,6 @@ #endif #endif -#if (TOS_CFG_VFS_EN > 0u) && (TOS_CFG_MMHEAP_EN == 0u) -#error "INVALID config, must enable TOS_CFG_MMHEAP_EN to use tos_vfs" -#endif - #ifndef TOS_CFG_CPU_HRTIMER_EN #error "UNDECLARED config, TOS_CFG_CPU_HRTIMER_EN should be declared in 'port_config.h'" #elif (TOS_CFG_CPU_HRTIMER_EN > 0u) && !defined(TOS_CFG_CPU_HRTIMER_SIZE) diff --git a/kernel/core/include/tos_k.h b/kernel/core/include/tos_k.h index 91f44552..1de7f751 100644 --- a/kernel/core/include/tos_k.h +++ b/kernel/core/include/tos_k.h @@ -20,15 +20,15 @@ #include #include -#include #include #include #include #include +#include #include +#include #include #include -#include #include #include #include diff --git a/kernel/core/tos_global.c b/kernel/core/tos_global.c index 5c8527c2..e80eb15d 100644 --- a/kernel/core/tos_global.c +++ b/kernel/core/tos_global.c @@ -78,8 +78,7 @@ pm_device_ctl_t k_pm_device_ctl = { 0u }; /* default idle power manager mode is SLEEP */ idle_pwrmgr_mode_t k_idle_pwr_mgr_mode = IDLE_POWER_MANAGER_MODE_SLEEP; -/* default low power mode is SLEEP */ -k_cpu_lpwr_mode_t k_cpu_lpwr_mode = TOS_LOW_POWER_MODE_SLEEP; +k_cpu_lpwr_mode_t k_cpu_lpwr_mode = TOS_LOW_POWER_MODE_NONE; #endif #if TOS_CFG_TICKLESS_EN > 0u diff --git a/kernel/core/tos_timer.c b/kernel/core/tos_timer.c index 45bde557..4e71f9ca 100644 --- a/kernel/core/tos_timer.c +++ b/kernel/core/tos_timer.c @@ -278,7 +278,7 @@ __KNL__ void timer_update(void) { k_timer_t *tmr, *tmp; - if (k_timer_ctl.next_expires < k_tick_count) { + if (k_timer_ctl.next_expires > k_tick_count) { // not yet return; } diff --git a/kernel/pm/include/tos_pm.h b/kernel/pm/include/tos_pm.h index 8ac712eb..c4ae722f 100644 --- a/kernel/pm/include/tos_pm.h +++ b/kernel/pm/include/tos_pm.h @@ -53,7 +53,8 @@ typedef enum idle_power_manager_mode_en { |-------------------------------------------------------------------------------------------------------------------| */ typedef enum k_cpu_low_power_mode_en { - TOS_LOW_POWER_MODE_SLEEP = 0, /* wakeup source: systick/tim/rtc */ + TOS_LOW_POWER_MODE_NONE = 0, /* if set to NONE, disable low power mode */ + TOS_LOW_POWER_MODE_SLEEP, /* wakeup source: systick/tim/rtc */ TOS_LOW_POWER_MODE_STOP, /* wakeup source: rtc wakeup/alarm */ TOS_LOW_POWER_MODE_STANDBY, /* wakeup source: rtc alarm */ __LOW_POWER_MODE_DUMMY, diff --git a/kernel/pm/tos_tickless.c b/kernel/pm/tos_tickless.c index 50000ed1..a675418a 100644 --- a/kernel/pm/tos_tickless.c +++ b/kernel/pm/tos_tickless.c @@ -132,21 +132,35 @@ __STATIC__ void tickless_leave(k_time_t time_sleep_ms) tick_sleep = k_cpu_tick_per_second * time_sleep_ms / K_TIME_MILLISEC_PER_SEC; tickless_tick_fix(tick_sleep); + + knl_sched(); } __KNL__ void tickless_proc(void) { + TOS_CPU_CPSR_ALLOC(); k_time_t time_sleep; k_cpu_lpwr_mode_t lpwr_mode; lpwr_mode = pm_cpu_lpwr_mode_get(); + if (lpwr_mode == TOS_LOW_POWER_MODE_NONE) { + return; + } + + if (!tickless_wkup_alarm_is_installed(lpwr_mode)) { + return; + } + + TOS_CPU_INT_DISABLE(); time_sleep = tickless_cpu_sleep_time_get(lpwr_mode); /* in millisecond */ if (unlikely(time_sleep == (k_time_t)0)) { + TOS_CPU_INT_ENABLE(); return; } tickless_enter(); + TOS_CPU_INT_ENABLE(); tickless_wkup_alarm_setup(lpwr_mode, time_sleep); pm_cpu_lpwr_mode_enter(lpwr_mode); tickless_wkup_alarm_dismiss(lpwr_mode);