From 7d1bfb51ae5a08fc2cfeda4c79ba6a25ee385086 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 4 Nov 2021 15:33:35 +0100 Subject: [PATCH] drivers: timer: cortex_m_systick: improve ISR installation A Cortex-M specific function (sys_clock_isr()) was defined as a weak function, so in practice it was always available when system clock was enabled, even if no Cortex-M systick was available. This patch introduces an auxiliary Kconfig option that, when selected, the ISR function gets installed. External SysTick drivers can also make use of this function, thus achieving the same functionality offered today but in a cleaner way. Signed-off-by: Gerard Marull-Paretas --- arch/arm/core/aarch32/cortex_m/vector_table.S | 8 +++----- drivers/timer/Kconfig.cortex_m_systick | 8 ++++++++ drivers/timer/sys_clock_init.c | 5 ----- soc/arm/nxp_imx/rt6xx/soc.c | 3 ++- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/arch/arm/core/aarch32/cortex_m/vector_table.S b/arch/arm/core/aarch32/cortex_m/vector_table.S index d73aabdcb54..dd85cb81bf6 100644 --- a/arch/arm/core/aarch32/cortex_m/vector_table.S +++ b/arch/arm/core/aarch32/cortex_m/vector_table.S @@ -80,14 +80,12 @@ SECTION_SUBSEC_FUNC(exc_vector_table,_vector_table_section,_vector_table) .word z_arm_exc_spurious #endif #if defined(CONFIG_CPU_CORTEX_M_HAS_SYSTICK) -#if defined(CONFIG_SYS_CLOCK_EXISTS) - /* Install sys_clock_isr even if CORTEX_M_SYSTICK is not set - * (e.g. to support out-of-tree SysTick-based timer drivers). - */ +#if defined(CONFIG_SYS_CLOCK_EXISTS) && \ + defined(CONFIG_CORTEX_M_SYSTICK_INSTALL_ISR) .word sys_clock_isr #else .word z_arm_exc_spurious -#endif /* CONFIG_SYS_CLOCK_EXISTS */ +#endif /* CONFIG_SYS_CLOCK_EXISTS && CONFIG_CORTEX_M_SYSTICK_INSTALL_ISR */ #else .word 0 #endif /* CONFIG_CPU_CORTEX_M_HAS_SYSTICK */ diff --git a/drivers/timer/Kconfig.cortex_m_systick b/drivers/timer/Kconfig.cortex_m_systick index f95ca3b656b..0887a2edc22 100644 --- a/drivers/timer/Kconfig.cortex_m_systick +++ b/drivers/timer/Kconfig.cortex_m_systick @@ -17,6 +17,14 @@ config CORTEX_M_SYSTICK $(dt_compat_enabled,$(DT_COMPAT_ARM_V8_1M_SYSTICK)) select TICKLESS_CAPABLE select SYSTEM_TIMER_HAS_DISABLE_SUPPORT + select CORTEX_M_SYSTICK_INSTALL_ISR help This module implements a kernel device driver for the Cortex-M processor SYSTICK timer and provides the standard "system clock driver" interfaces. + +config CORTEX_M_SYSTICK_INSTALL_ISR + bool + depends on CPU_CORTEX_M_HAS_SYSTICK + help + This option should be selected by SysTick-based drivers so that the + sys_clock_isr() function is installed. diff --git a/drivers/timer/sys_clock_init.c b/drivers/timer/sys_clock_init.c index ea60adb67a2..5de7fa28a5e 100644 --- a/drivers/timer/sys_clock_init.c +++ b/drivers/timer/sys_clock_init.c @@ -18,11 +18,6 @@ /* Weak-linked noop defaults for optional driver interfaces*/ -void __weak sys_clock_isr(void *arg) -{ - __ASSERT_NO_MSG(false); -} - void __weak sys_clock_set_timeout(int32_t ticks, bool idle) { } diff --git a/soc/arm/nxp_imx/rt6xx/soc.c b/soc/arm/nxp_imx/rt6xx/soc.c index c11e1661ed4..63fa0dabbbb 100644 --- a/soc/arm/nxp_imx/rt6xx/soc.c +++ b/soc/arm/nxp_imx/rt6xx/soc.c @@ -105,7 +105,8 @@ __imx_boot_ivt_section void (* const image_vector_table[])(void) = { z_arm_debug_monitor, /* 0x30 */ (void (*)())image_vector_table, /* 0x34, imageLoadAddress. */ z_arm_pendsv, /* 0x38 */ -#if defined(CONFIG_SYS_CLOCK_EXISTS) +#if defined(CONFIG_SYS_CLOCK_EXISTS) && \ + defined(CONFIG_CORTEX_M_SYSTICK_INSTALL_ISR) sys_clock_isr, /* 0x3C */ #else z_arm_exc_spurious,