This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 6b6a840735f31a93111950066661211386375ca6 Author: buxiasen <[email protected]> AuthorDate: Tue Dec 16 15:54:54 2025 +0800 arch/arm_m: merge systick Move SYSTICK from v7/8m into arm_m For compatible, keep ARMV7M_SYSTICK and ARMV8M_SYSTICK, reduce the change of defconfig and Kconfig Signed-off-by: buxiasen <[email protected]> --- arch/arm/Kconfig | 3 + arch/arm/src/arm_m/CMakeLists.txt | 4 + arch/arm/src/arm_m/Kconfig | 32 +++ arch/arm/src/arm_m/Make.defs | 4 + arch/arm/src/{armv7-m => arm_m}/arm_systick.c | 15 +- arch/arm/src/{armv8-m => arm_m}/systick.h | 10 +- arch/arm/src/armv7-m/CMakeLists.txt | 4 - arch/arm/src/armv7-m/Kconfig | 19 +- arch/arm/src/armv7-m/Make.defs | 4 - arch/arm/src/armv7-m/systick.h | 74 ------ arch/arm/src/armv8-m/CMakeLists.txt | 4 - arch/arm/src/armv8-m/Kconfig | 1 + arch/arm/src/armv8-m/Make.defs | 4 - arch/arm/src/armv8-m/arm_systick.c | 340 -------------------------- 14 files changed, 58 insertions(+), 460 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 43b02fd3935..8f1971bff05 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1871,6 +1871,9 @@ endchoice # Choose ARM unwinder endif +if ARCH_ARM_M +source "arch/arm/src/arm_m/Kconfig" +endif if ARCH_ARMV6M source "arch/arm/src/armv6-m/Kconfig" endif diff --git a/arch/arm/src/arm_m/CMakeLists.txt b/arch/arm/src/arm_m/CMakeLists.txt index 4eb045d7e99..32d22f0dd88 100644 --- a/arch/arm/src/arm_m/CMakeLists.txt +++ b/arch/arm/src/arm_m/CMakeLists.txt @@ -20,6 +20,10 @@ list(APPEND SRCS arm_exception.S arm_saveusercontext.S arm_tcbinfo.c) +if(CONFIG_ARM_SYSTICK) + list(APPEND SRCS arm_systick.c) +endif() + if(CONFIG_ENABLE_ALL_SIGNALS) list(APPEND SRCS arm_sigdeliver.c arm_schedulesigaction.c) endif() diff --git a/arch/arm/src/arm_m/Kconfig b/arch/arm/src/arm_m/Kconfig new file mode 100644 index 00000000000..c531551602c --- /dev/null +++ b/arch/arm/src/arm_m/Kconfig @@ -0,0 +1,32 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +comment "ARM_M Configuration Options" + +config ARM_SYSTICK + bool "SysTick timer driver" + depends on TIMER + default n + ---help--- + Enable SysTick timer driver. + +config ARM_SYSTICK_IRQ_WQUEUE + bool "attach irq by irq_attach_wqueue" + default n + depends on ARM_SYSTICK + +if ARM_SYSTICK_IRQ_WQUEUE + +config ARM_SYSTICK_IRQ_WQUEUE_PRIORITY + int "SYSTICK IRQ WQUEUE PRIORITY" + default 255 + range 0 255 + +config ARM_SYSTICK_IRQ_THREAD_STACK_SIZE + int "SYSTICK IRQ THREAD STACK SIZE" + default DEFAULT_TASK_STACKSIZE + +endif # ARM_SYSTICK_IRQ_WQUEUE + diff --git a/arch/arm/src/arm_m/Make.defs b/arch/arm/src/arm_m/Make.defs index b5882ea1276..d1f66101f56 100644 --- a/arch/arm/src/arm_m/Make.defs +++ b/arch/arm/src/arm_m/Make.defs @@ -22,6 +22,10 @@ CMN_ASRCS += arm_exception.S arm_saveusercontext.S +ifeq ($(CONFIG_ARM_SYSTICK),y) + CMN_CSRCS += arm_systick.c +endif + ifeq ($(CONFIG_LIB_SYSCALL),y) CMN_ASRCS += arm_dispatch_syscall.S endif diff --git a/arch/arm/src/armv7-m/arm_systick.c b/arch/arm/src/arm_m/arm_systick.c similarity index 97% rename from arch/arm/src/armv7-m/arm_systick.c rename to arch/arm/src/arm_m/arm_systick.c index 28c676e1598..d6a3c3469f3 100644 --- a/arch/arm/src/armv7-m/arm_systick.c +++ b/arch/arm/src/arm_m/arm_systick.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/arm/src/armv7-m/arm_systick.c + * arch/arm/src/arm_m/arm_systick.c * * SPDX-License-Identifier: Apache-2.0 * @@ -36,7 +36,7 @@ #include "systick.h" #include "arm_internal.h" -#ifdef CONFIG_ARMV7M_SYSTICK +#ifdef CONFIG_ARM_SYSTICK /**************************************************************************** * Pre-processor definitions @@ -160,8 +160,8 @@ static int systick_getstatus(struct timer_lowerhalf_s *lower_, status->flags |= systick_is_running() ? TCFLAGS_ACTIVE : 0; status->timeout = usec_from_count( RELOAD2TIMEOUT(getreg32(NVIC_SYSTICK_RELOAD)), lower->freq); - status->timeleft = usec_from_count( - getreg32(NVIC_SYSTICK_CURRENT), lower->freq); + status->timeleft = usec_from_count(getreg32(NVIC_SYSTICK_CURRENT), + lower->freq); if (systick_irq_pending(lower)) { @@ -286,7 +286,7 @@ static int systick_interrupt(int irq, void *context, void *arg) return 0; } -#ifdef CONFIG_ARMV7M_SYSTICK_IRQ_WQUEUE +#ifdef CONFIG_ARM_SYSTICK_IRQ_WQUEUE static int systick_isr_handle(int irq, void *regs, void *arg) { return IRQ_WAKE_THREAD; @@ -309,6 +309,7 @@ struct timer_lowerhalf_s *systick_initialize(bool coreclk, { uint32_t calib = getreg32(NVIC_SYSTICK_CALIB); uint32_t tenms = calib & NVIC_SYSTICK_CALIB_TENMS_MASK; + lower->freq = 100 * (tenms + 1); } else @@ -328,7 +329,7 @@ struct timer_lowerhalf_s *systick_initialize(bool coreclk, putreg32(NVIC_SYSTICK_CTRL_TICKINT, NVIC_SYSTICK_CTRL); } -#ifdef CONFIG_ARMV7M_SYSTICK_IRQ_WQUEUE +#ifdef CONFIG_ARM_SYSTICK_IRQ_WQUEUE irq_attach_wqueue(NVIC_IRQ_SYSTICK, systick_isr_handle, systick_interrupt, lower, CONFIG_ARMV7M_SYSTICK_IRQ_WQUEUE_PRIORITY); @@ -350,4 +351,4 @@ struct timer_lowerhalf_s *systick_initialize(bool coreclk, return (struct timer_lowerhalf_s *)lower; } -#endif /* CONFIG_ARMV7M_SYSTICK */ +#endif /* CONFIG_ARM_SYSTICK */ diff --git a/arch/arm/src/armv8-m/systick.h b/arch/arm/src/arm_m/systick.h similarity index 93% rename from arch/arm/src/armv8-m/systick.h rename to arch/arm/src/arm_m/systick.h index 296fcc8bae6..a3de2ddf7c0 100644 --- a/arch/arm/src/armv8-m/systick.h +++ b/arch/arm/src/arm_m/systick.h @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/arm/src/armv8-m/systick.h + * arch/arm/src/arm_m/systick.h * * SPDX-License-Identifier: Apache-2.0 * @@ -20,8 +20,8 @@ * ****************************************************************************/ -#ifndef __ARCH_ARM_SRC_ARMV8_M_SYSTICK_H -#define __ARCH_ARM_SRC_ARMV8_M_SYSTICK_H +#ifndef __ARCH_ARM_SRC_ARM_M_SYSTICK_H +#define __ARCH_ARM_SRC_ARM_M_SYSTICK_H /**************************************************************************** * Included Files @@ -60,7 +60,7 @@ extern "C" * ****************************************************************************/ -#ifdef CONFIG_ARMV8M_SYSTICK +#ifdef CONFIG_ARM_SYSTICK struct timer_lowerhalf_s *systick_initialize(bool coreclk, unsigned int freq, int minor); #else @@ -71,4 +71,4 @@ struct timer_lowerhalf_s *systick_initialize(bool coreclk, unsigned int freq, } #endif -#endif /* __ARCH_ARM_SRC_ARMV8_M_SYSTICK_H */ +#endif /* __ARCH_ARM_SRC_ARM_M_SYSTICK_H */ diff --git a/arch/arm/src/armv7-m/CMakeLists.txt b/arch/arm/src/armv7-m/CMakeLists.txt index c203033b642..4a9e85bcb24 100644 --- a/arch/arm/src/armv7-m/CMakeLists.txt +++ b/arch/arm/src/armv7-m/CMakeLists.txt @@ -38,10 +38,6 @@ set(SRCS arm_usagefault.c arm_dbgmonitor.c) -if(CONFIG_ARMV7M_SYSTICK) - list(APPEND SRCS arm_systick.c) -endif() - if(CONFIG_ARMV7M_ITMSYSLOG) list(APPEND SRCS arm_itm_syslog.c) endif() diff --git a/arch/arm/src/armv7-m/Kconfig b/arch/arm/src/armv7-m/Kconfig index f882a6e06dc..79a4ce64773 100644 --- a/arch/arm/src/armv7-m/Kconfig +++ b/arch/arm/src/armv7-m/Kconfig @@ -152,23 +152,6 @@ endif # ARMV7M_ITMSYSLOG config ARMV7M_SYSTICK bool "SysTick timer driver" depends on TIMER + select ARM_SYSTICK ---help--- Enable SysTick timer driver. - -config ARMV7M_SYSTICK_IRQ_WQUEUE - bool "attach irq by irq_attach_wqueue" - default n - depends on ARMV7M_SYSTICK - -if ARMV7M_SYSTICK_IRQ_WQUEUE - -config ARMV7M_SYSTICK_IRQ_WQUEUE_PRIORITY - int "SYSTICK IRQ WQUEUE PRIORITY" - default 255 - range 0 255 - -config ARMV7M_SYSTICK_IRQ_THREAD_STACK_SIZE - int "SYSTICK IRQ THREAD STACK SIZE" - default DEFAULT_TASK_STACKSIZE - -endif # ARMV7M_SYSTICK_IRQ_WQUEUE diff --git a/arch/arm/src/armv7-m/Make.defs b/arch/arm/src/armv7-m/Make.defs index 39d9939ef54..c7082973225 100644 --- a/arch/arm/src/armv7-m/Make.defs +++ b/arch/arm/src/armv7-m/Make.defs @@ -31,10 +31,6 @@ CMN_CSRCS += arm_memfault.c arm_perf.c CMN_CSRCS += arm_svcall.c arm_systemreset.c CMN_CSRCS += arm_trigger_irq.c arm_usagefault.c arm_dbgmonitor.c -ifeq ($(CONFIG_ARMV7M_SYSTICK),y) - CMN_CSRCS += arm_systick.c -endif - ifeq ($(CONFIG_ARMV7M_ITMSYSLOG),y) CMN_CSRCS += arm_itm_syslog.c endif diff --git a/arch/arm/src/armv7-m/systick.h b/arch/arm/src/armv7-m/systick.h deleted file mode 100644 index 016c019cdca..00000000000 --- a/arch/arm/src/armv7-m/systick.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** - * arch/arm/src/armv7-m/systick.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __ARCH_ARM_SRC_ARMV7_M_SYSTICK_H -#define __ARCH_ARM_SRC_ARMV7_M_SYSTICK_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <nuttx/timers/timer.h> - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -/**************************************************************************** - * Name: systick_initialize - * - * Description: - * This function initialize SYSTICK hardware module which is part of NVIC - * and return an instance of a "lower half" timer interface. - * - * Input parameters: - * coreclk - false if SYSTICK working clock come from the external - * reference clock, otherwise true. - * freq - The clock frequency in Hz. If freq is zero, calculate the value - * from NVIC_SYSTICK_CALIB register. - * minor - The timer driver minor number, skip the registration if minor - * < 0. - * - * Returned Value: - * On success, a non-NULL timer_lowerhalf_s is returned to the caller. - * In the event of any failure, a NULL value is returned. - * - ****************************************************************************/ - -#ifdef CONFIG_ARMV7M_SYSTICK -struct timer_lowerhalf_s *systick_initialize(bool coreclk, unsigned int freq, - int minor); -#else -# define systick_initialize(coreclk, freq, minor) NULL -#endif /* CONFIG_ARMV7M_SYSTICK */ - -#ifdef __cplusplus -} -#endif - -#endif /* __ARCH_ARM_SRC_ARMV7_M_SYSTICK_H */ diff --git a/arch/arm/src/armv8-m/CMakeLists.txt b/arch/arm/src/armv8-m/CMakeLists.txt index 76296b90daa..5ce85a8aff5 100644 --- a/arch/arm/src/armv8-m/CMakeLists.txt +++ b/arch/arm/src/armv8-m/CMakeLists.txt @@ -39,10 +39,6 @@ set(SRCS arm_trigger_irq.c arm_usagefault.c) -if(CONFIG_ARMV8M_SYSTICK) - list(APPEND SRCS arm_systick.c) -endif() - if(CONFIG_ARMV8M_ITMSYSLOG) list(APPEND SRCS arm_itm_syslog.c) endif() diff --git a/arch/arm/src/armv8-m/Kconfig b/arch/arm/src/armv8-m/Kconfig index 783ceaa1d71..c4036ccd2d1 100644 --- a/arch/arm/src/armv8-m/Kconfig +++ b/arch/arm/src/armv8-m/Kconfig @@ -153,6 +153,7 @@ endif # ARMV8M_ITMSYSLOG config ARMV8M_SYSTICK bool "SysTick timer driver" depends on TIMER + select ARM_SYSTICK ---help--- Enable SysTick timer driver. diff --git a/arch/arm/src/armv8-m/Make.defs b/arch/arm/src/armv8-m/Make.defs index 25e8571f54b..4754f14bda4 100644 --- a/arch/arm/src/armv8-m/Make.defs +++ b/arch/arm/src/armv8-m/Make.defs @@ -33,10 +33,6 @@ CMN_CSRCS += arm_svcall.c CMN_CSRCS += arm_systemreset.c CMN_CSRCS += arm_trigger_irq.c arm_usagefault.c arm_dbgmonitor.c -ifeq ($(CONFIG_ARMV8M_SYSTICK),y) - CMN_CSRCS += arm_systick.c -endif - ifeq ($(CONFIG_ARMV8M_ITMSYSLOG),y) CMN_CSRCS += arm_itm_syslog.c endif diff --git a/arch/arm/src/armv8-m/arm_systick.c b/arch/arm/src/armv8-m/arm_systick.c deleted file mode 100644 index ca448e5b12a..00000000000 --- a/arch/arm/src/armv8-m/arm_systick.c +++ /dev/null @@ -1,340 +0,0 @@ -/**************************************************************************** - * arch/arm/src/armv8-m/arm_systick.c - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <nuttx/arch.h> -#include <nuttx/irq.h> - -#include <sys/param.h> -#include <stdio.h> - -#include "nvic.h" -#include "systick.h" -#include "arm_internal.h" - -#ifdef CONFIG_ARMV8M_SYSTICK - -/**************************************************************************** - * Pre-processor definitions - ****************************************************************************/ - -/* According to what arm specified, we should set the - * RELOAD value to N-1 for a desired systick interval of - * N processor clock cycles. - * Therefore, when reading the RELOAD value, it is important - * to add one clock cycle back. - */ -#define RELOAD2TIMEOUT(reload) ((reload) + 1) -#define TIMEOUT2RELOAD(timeout) ((timeout) - 1) - -#define CLAMP_RELOAD(reload) \ -CLAMP(reload, NVIC_MIN_SYSTICK_CNT, NVIC_MAX_SYSTICK_CNT) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* This structure provides the private representation of the "lower-half" - * driver state structure. This structure must be cast-compatible with the - * timer_lowerhalf_s structure. - */ - -struct systick_lowerhalf_s -{ - const struct timer_ops_s *ops; /* Lower half operations */ - uint32_t freq; /* Timer working clock frequency(Hz) */ - tccb_t callback; /* Current user interrupt callback */ - void *arg; /* Argument passed to upper half callback */ - uint32_t *next_interval; -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int systick_start(struct timer_lowerhalf_s *lower_); -static int systick_stop(struct timer_lowerhalf_s *lower_); -static int systick_getstatus(struct timer_lowerhalf_s *lower_, - struct timer_status_s *status); -static int systick_settimeout(struct timer_lowerhalf_s *lower_, - uint32_t timeout); -static void systick_setcallback(struct timer_lowerhalf_s *lower_, - tccb_t callback, void *arg); -static int systick_maxtimeout(struct timer_lowerhalf_s *lower_, - uint32_t *maxtimeout); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const struct timer_ops_s g_systick_ops = -{ - .start = systick_start, - .stop = systick_stop, - .getstatus = systick_getstatus, - .settimeout = systick_settimeout, - .setcallback = systick_setcallback, - .maxtimeout = systick_maxtimeout, -}; - -static struct systick_lowerhalf_s g_systick_lower = -{ - .ops = &g_systick_ops, -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static inline uint64_t usec_from_count(uint32_t count, uint32_t freq) -{ - return (uint64_t)count * USEC_PER_SEC / freq; -} - -static inline uint64_t usec_to_count(uint32_t usec, uint32_t freq) -{ - return (uint64_t)usec * freq / USEC_PER_SEC; -} - -static bool systick_is_running(void) -{ - return !!(getreg32(NVIC_SYSTICK_CTRL) & NVIC_SYSTICK_CTRL_ENABLE); -} - -static bool systick_irq_pending(struct systick_lowerhalf_s *lower) -{ - if (lower->next_interval) - { - return false; /* Interrupt is in process */ - } - else - { - return !!(getreg32(NVIC_INTCTRL) & NVIC_INTCTRL_PENDSTSET); - } -} - -static int systick_start(struct timer_lowerhalf_s *lower_) -{ - putreg32(0, NVIC_SYSTICK_CURRENT); - modifyreg32(NVIC_SYSTICK_CTRL, 0, NVIC_SYSTICK_CTRL_ENABLE); - return 0; -} - -static int systick_stop(struct timer_lowerhalf_s *lower_) -{ - modifyreg32(NVIC_SYSTICK_CTRL, NVIC_SYSTICK_CTRL_ENABLE, 0); - return 0; -} - -static int systick_getstatus(struct timer_lowerhalf_s *lower_, - struct timer_status_s *status) -{ - struct systick_lowerhalf_s *lower = (struct systick_lowerhalf_s *)lower_; - irqstate_t flags = up_irq_save(); - - status->flags = lower->callback ? TCFLAGS_HANDLER : 0; - status->flags |= systick_is_running() ? TCFLAGS_ACTIVE : 0; - status->timeout = usec_from_count( - RELOAD2TIMEOUT(getreg32(NVIC_SYSTICK_RELOAD)), lower->freq); - status->timeleft = usec_from_count(getreg32(NVIC_SYSTICK_CURRENT), - lower->freq); - - if (systick_irq_pending(lower)) - { - /* Interrupt is pending and the timer wrap happen? */ - - if (status->timeleft) - { - /* Make timeout-timeleft equal the real elapsed time */ - - status->timeout += status->timeout - status->timeleft; - status->timeleft = 0; - } - } - else if (status->timeleft == 0) - { - status->timeleft = status->timeout; - } - - up_irq_restore(flags); - return 0; -} - -static int systick_settimeout(struct timer_lowerhalf_s *lower_, - uint32_t timeout) -{ - struct systick_lowerhalf_s *lower = (struct systick_lowerhalf_s *)lower_; - irqstate_t flags = up_irq_save(); - - if (lower->next_interval) - { - /* If the timer callback is in the process, - * delay the update to timer interrupt handler. - */ - - *lower->next_interval = timeout; - } - else - { - uint32_t reload; - - reload = TIMEOUT2RELOAD(usec_to_count(timeout, lower->freq)); - - putreg32(CLAMP_RELOAD(reload), NVIC_SYSTICK_RELOAD); - if (systick_is_running()) - { - if (reload != getreg32(NVIC_SYSTICK_CURRENT)) - { - putreg32(0, NVIC_SYSTICK_CURRENT); - } - } - } - - up_irq_restore(flags); - return 0; -} - -static void systick_setcallback(struct timer_lowerhalf_s *lower_, - tccb_t callback, void *arg) -{ - struct systick_lowerhalf_s *lower = (struct systick_lowerhalf_s *)lower_; - irqstate_t flags = up_irq_save(); - - lower->callback = callback; - lower->arg = arg; - - up_irq_restore(flags); -} - -static int systick_maxtimeout(struct timer_lowerhalf_s *lower_, - uint32_t *maxtimeout) -{ - uint64_t maxtimeout64 = usec_from_count( - NVIC_SYSTICK_RELOAD_MASK, g_systick_lower.freq); - - if (maxtimeout64 > UINT32_MAX) - { - *maxtimeout = UINT32_MAX; - } - else - { - *maxtimeout = maxtimeout64; - } - - return 0; -} - -static int systick_interrupt(int irq, void *context, void *arg) -{ - struct systick_lowerhalf_s *lower = arg; - - if (lower->callback && systick_is_running()) - { - uint32_t reload = getreg32(NVIC_SYSTICK_RELOAD); - - /* Convert count to us then to tick for callback parameter */ - - uint32_t interval = USEC2TICK(usec_from_count( - RELOAD2TIMEOUT(reload), lower->freq)); - uint32_t next_interval = interval; - - lower->next_interval = &next_interval; - if (lower->callback(&next_interval, lower->arg)) - { - if (next_interval && next_interval != interval) - { - /* Recover tick to us then to count for register writing */ - - reload = TIMEOUT2RELOAD( - usec_to_count(TICK2USEC(next_interval), lower->freq)); - putreg32(CLAMP_RELOAD(reload), NVIC_SYSTICK_RELOAD); - putreg32(0, NVIC_SYSTICK_CURRENT); - } - } - else - { - modifyreg32(NVIC_SYSTICK_CTRL, NVIC_SYSTICK_CTRL_ENABLE, 0); - } - - lower->next_interval = NULL; - } - - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -struct timer_lowerhalf_s *systick_initialize(bool coreclk, - unsigned int freq, int minor) -{ - struct systick_lowerhalf_s *lower = - (struct systick_lowerhalf_s *)&g_systick_lower; - - /* Calculate the working clock frequency if need */ - - if (freq == 0) - { - uint32_t calib = getreg32(NVIC_SYSTICK_CALIB); - uint32_t tenms = calib & NVIC_SYSTICK_CALIB_TENMS_MASK; - lower->freq = 100 * (tenms + 1); - } - else - { - lower->freq = freq; - } - - /* Disable SYSTICK, but enable interrupt */ - - if (coreclk) - { - putreg32(NVIC_SYSTICK_CTRL_CLKSOURCE | NVIC_SYSTICK_CTRL_TICKINT, - NVIC_SYSTICK_CTRL); - } - else - { - putreg32(NVIC_SYSTICK_CTRL_TICKINT, NVIC_SYSTICK_CTRL); - } - - irq_attach(NVIC_IRQ_SYSTICK, systick_interrupt, lower); - up_enable_irq(NVIC_IRQ_SYSTICK); - - /* Register the timer driver if need */ - - if (minor >= 0) - { - char devname[32]; - - snprintf(devname, sizeof(devname), "/dev/timer%d", minor); - timer_register(devname, (struct timer_lowerhalf_s *)lower); - } - - return (struct timer_lowerhalf_s *)lower; -} - -#endif /* CONFIG_ARMV8M_SYSTICK */
