You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/03/26 11:39:28 UTC
[incubator-nuttx] branch master updated: armv7-m/armv8-m: move up_pref* api to common place
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new f623ac0 armv7-m/armv8-m: move up_pref* api to common place
f623ac0 is described below
commit f623ac0f13ab893ef0c209325d2ac1ff85f405ee
Author: ligd <li...@xiaomi.com>
AuthorDate: Sat Mar 26 03:01:10 2022 +0800
armv7-m/armv8-m: move up_pref* api to common place
Signed-off-by: ligd <li...@xiaomi.com>
Signed-off-by: chao.an <an...@xiaomi.com>
---
.../arm/src/armv7-m/arm_perf.c | 58 ++++++++++++----------
.../arm/src/armv8-m/arm_perf.c | 58 ++++++++++++----------
boards/arm/stm32/axoloti/src/stm32_boot.c | 11 +---
boards/arm/stm32/omnibusf4/src/Make.defs | 2 +-
boards/arm/stm32/omnibusf4/src/stm32_boot.c | 11 +---
boards/arm/stm32/stm32f4discovery/src/Make.defs | 2 +-
boards/arm/stm32/stm32f4discovery/src/stm32_boot.c | 11 +---
include/nuttx/arch.h | 2 +
8 files changed, 71 insertions(+), 84 deletions(-)
diff --git a/boards/arm/stm32/omnibusf4/src/stm32_perfcount.c b/arch/arm/src/armv7-m/arm_perf.c
similarity index 68%
rename from boards/arm/stm32/omnibusf4/src/stm32_perfcount.c
rename to arch/arm/src/armv7-m/arm_perf.c
index df393a9..b4e860f 100644
--- a/boards/arm/stm32/omnibusf4/src/stm32_perfcount.c
+++ b/arch/arm/src/armv7-m/arm_perf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * boards/arm/stm32/omnibusf4/src/stm32_perfcount.c
+ * arch/arm/src/armv7-m/arm_perf.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -22,49 +22,55 @@
* Included Files
****************************************************************************/
-#include <nuttx/config.h>
-
-#include <time.h>
-#include <fixedmath.h>
-
-#include "dwt.h"
-#include "arm_internal.h"
-
+#include <nuttx/arch.h>
#include <nuttx/clock.h>
-#include <arch/board/board.h>
+#include "arm_arch.h"
+#include "dwt.h"
+#include "itm.h"
+#include "nvic.h"
/****************************************************************************
- * Public Functions
+ * Private Data
****************************************************************************/
+static uint32_t g_cpu_freq;
+
/****************************************************************************
- * Name: up_perf_gettime
+ * Public Functions
****************************************************************************/
-uint32_t up_perf_gettime(void)
+void up_perf_init(FAR void *arg)
{
- return getreg32(DWT_CYCCNT);
-}
+ g_cpu_freq = (uint32_t)(uintptr_t)arg;
-/****************************************************************************
- * Name: up_perf_getfreq
- ****************************************************************************/
+ /* Enable ITM and DWT resources, if not left enabled by debugger. */
+
+ modifyreg32(NVIC_DEMCR, 0, NVIC_DEMCR_TRCENA);
+
+ /* Make sure the high speed cycle counter is running. It will be started
+ * automatically only if a debugger is connected.
+ */
+
+ putreg32(0xc5acce55, ITM_LAR);
+ modifyreg32(DWT_CTRL, 0, DWT_CTRL_CYCCNTENA_MASK);
+}
uint32_t up_perf_getfreq(void)
{
- return STM32_SYSCLK_FREQUENCY;
+ return g_cpu_freq;
}
-/****************************************************************************
- * Name: up_perf_convert
- ****************************************************************************/
+uint32_t up_perf_gettime(void)
+{
+ return getreg32(DWT_CYCCNT);
+}
void up_perf_convert(uint32_t elapsed, FAR struct timespec *ts)
{
- b32_t b32elapsed;
+ uint32_t left;
- b32elapsed = itob32(elapsed) / STM32_SYSCLK_FREQUENCY;
- ts->tv_sec = b32toi(b32elapsed);
- ts->tv_nsec = NSEC_PER_SEC * b32frac(b32elapsed) / b32ONE;
+ ts->tv_sec = elapsed / g_cpu_freq;
+ left = elapsed - ts->tv_sec * g_cpu_freq;
+ ts->tv_nsec = NSEC_PER_SEC * (uint64_t)left / g_cpu_freq;
}
diff --git a/boards/arm/stm32/stm32f4discovery/src/stm32_perfcount.c b/arch/arm/src/armv8-m/arm_perf.c
similarity index 68%
rename from boards/arm/stm32/stm32f4discovery/src/stm32_perfcount.c
rename to arch/arm/src/armv8-m/arm_perf.c
index 8053b20..c6d4523 100644
--- a/boards/arm/stm32/stm32f4discovery/src/stm32_perfcount.c
+++ b/arch/arm/src/armv8-m/arm_perf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * boards/arm/stm32/stm32f4discovery/src/stm32_perfcount.c
+ * arch/arm/src/armv8-m/arm_perf.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -22,49 +22,55 @@
* Included Files
****************************************************************************/
-#include <nuttx/config.h>
-
-#include <time.h>
-#include <fixedmath.h>
-
-#include "dwt.h"
-#include "arm_internal.h"
-
+#include <nuttx/arch.h>
#include <nuttx/clock.h>
-#include <arch/board/board.h>
+#include "arm_arch.h"
+#include "dwt.h"
+#include "itm.h"
+#include "nvic.h"
/****************************************************************************
- * Public Functions
+ * Private Data
****************************************************************************/
+static uint32_t g_cpu_freq;
+
/****************************************************************************
- * Name: up_perf_gettime
+ * Public Functions
****************************************************************************/
-uint32_t up_perf_gettime(void)
+void up_perf_init(FAR void *arg)
{
- return getreg32(DWT_CYCCNT);
-}
+ g_cpu_freq = (uint32_t)(uintptr_t)arg;
-/****************************************************************************
- * Name: up_perf_getfreq
- ****************************************************************************/
+ /* Enable ITM and DWT resources, if not left enabled by debugger. */
+
+ modifyreg32(NVIC_DEMCR, 0, NVIC_DEMCR_TRCENA);
+
+ /* Make sure the high speed cycle counter is running. It will be started
+ * automatically only if a debugger is connected.
+ */
+
+ putreg32(0xc5acce55, ITM_LAR);
+ modifyreg32(DWT_CTRL, 0, DWT_CTRL_CYCCNTENA_MASK);
+}
uint32_t up_perf_getfreq(void)
{
- return STM32_SYSCLK_FREQUENCY;
+ return g_cpu_freq;
}
-/****************************************************************************
- * Name: up_perf_convert
- ****************************************************************************/
+uint32_t up_perf_gettime(void)
+{
+ return getreg32(DWT_CYCCNT);
+}
void up_perf_convert(uint32_t elapsed, FAR struct timespec *ts)
{
- b32_t b32elapsed;
+ uint32_t left;
- b32elapsed = itob32(elapsed) / STM32_SYSCLK_FREQUENCY;
- ts->tv_sec = b32toi(b32elapsed);
- ts->tv_nsec = NSEC_PER_SEC * b32frac(b32elapsed) / b32ONE;
+ ts->tv_sec = elapsed / g_cpu_freq;
+ left = elapsed - ts->tv_sec * g_cpu_freq;
+ ts->tv_nsec = NSEC_PER_SEC * (uint64_t)left / g_cpu_freq;
}
diff --git a/boards/arm/stm32/axoloti/src/stm32_boot.c b/boards/arm/stm32/axoloti/src/stm32_boot.c
index 9179738..bfb8384 100644
--- a/boards/arm/stm32/axoloti/src/stm32_boot.c
+++ b/boards/arm/stm32/axoloti/src/stm32_boot.c
@@ -54,16 +54,7 @@
void stm32_boardinitialize(void)
{
#ifdef CONFIG_SCHED_CRITMONITOR
- /* Enable ITM and DWT resources, if not left enabled by debugger. */
-
- modifyreg32(NVIC_DEMCR, 0, NVIC_DEMCR_TRCENA);
-
- /* Make sure the high speed cycle counter is running. It will be started
- * automatically only if a debugger is connected.
- */
-
- putreg32(0xc5acce55, ITM_LAR);
- modifyreg32(DWT_CTRL, 0, DWT_CTRL_CYCCNTENA_MASK);
+ up_perf_init((FAR void *)STM32_SYSCLK_FREQUENCY);
#endif
#if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || \
diff --git a/boards/arm/stm32/omnibusf4/src/Make.defs b/boards/arm/stm32/omnibusf4/src/Make.defs
index f59c349..3e7e821 100644
--- a/boards/arm/stm32/omnibusf4/src/Make.defs
+++ b/boards/arm/stm32/omnibusf4/src/Make.defs
@@ -20,7 +20,7 @@
include $(TOPDIR)/Make.defs
-CSRCS = stm32_boot.c stm32_bringup.c stm32_spi.c stm32_userleds.c stm32_perfcount.c
+CSRCS = stm32_boot.c stm32_bringup.c stm32_spi.c stm32_userleds.c
ifeq ($(CONFIG_SENSORS_MPU60X0),y)
CSRCS += stm32_mpu6000.c
diff --git a/boards/arm/stm32/omnibusf4/src/stm32_boot.c b/boards/arm/stm32/omnibusf4/src/stm32_boot.c
index 57f787a..b5b203d 100644
--- a/boards/arm/stm32/omnibusf4/src/stm32_boot.c
+++ b/boards/arm/stm32/omnibusf4/src/stm32_boot.c
@@ -54,16 +54,7 @@
void stm32_boardinitialize(void)
{
#ifdef CONFIG_SCHED_CRITMONITOR
- /* Enable ITM and DWT resources, if not left enabled by debugger. */
-
- modifyreg32(NVIC_DEMCR, 0, NVIC_DEMCR_TRCENA);
-
- /* Make sure the high speed cycle counter is running. It will be started
- * automatically only if a debugger is connected.
- */
-
- putreg32(0xc5acce55, ITM_LAR);
- modifyreg32(DWT_CTRL, 0, DWT_CTRL_CYCCNTENA_MASK);
+ up_perf_init((FAR void *)STM32_SYSCLK_FREQUENCY);
#endif
#if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || defined(CONFIG_STM32_SPI3)
diff --git a/boards/arm/stm32/stm32f4discovery/src/Make.defs b/boards/arm/stm32/stm32f4discovery/src/Make.defs
index fc8ddc8..d0e06dc 100644
--- a/boards/arm/stm32/stm32f4discovery/src/Make.defs
+++ b/boards/arm/stm32/stm32f4discovery/src/Make.defs
@@ -20,7 +20,7 @@
include $(TOPDIR)/Make.defs
-CSRCS = stm32_boot.c stm32_bringup.c stm32_spi.c stm32_perfcount.c
+CSRCS = stm32_boot.c stm32_bringup.c stm32_spi.c
ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += stm32_autoleds.c
diff --git a/boards/arm/stm32/stm32f4discovery/src/stm32_boot.c b/boards/arm/stm32/stm32f4discovery/src/stm32_boot.c
index 5c9278f..0ebd3a2 100644
--- a/boards/arm/stm32/stm32f4discovery/src/stm32_boot.c
+++ b/boards/arm/stm32/stm32f4discovery/src/stm32_boot.c
@@ -54,16 +54,7 @@
void stm32_boardinitialize(void)
{
#ifdef CONFIG_SCHED_CRITMONITOR
- /* Enable ITM and DWT resources, if not left enabled by debugger. */
-
- modifyreg32(NVIC_DEMCR, 0, NVIC_DEMCR_TRCENA);
-
- /* Make sure the high speed cycle counter is running. It will be started
- * automatically only if a debugger is connected.
- */
-
- putreg32(0xc5acce55, ITM_LAR);
- modifyreg32(DWT_CTRL, 0, DWT_CTRL_CYCCNTENA_MASK);
+ up_perf_init((FAR void *)STM32_SYSCLK_FREQUENCY);
#endif
#if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || defined(CONFIG_STM32_SPI3)
diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h
index 427307e..1d0d8b8 100644
--- a/include/nuttx/arch.h
+++ b/include/nuttx/arch.h
@@ -2555,8 +2555,10 @@ void arch_sporadic_resume(FAR struct tcb_s *tcb);
*
* The second interface simple converts an elapsed time into well known
* units.
+ *
****************************************************************************/
+void up_perf_init(FAR void *arg);
uint32_t up_perf_gettime(void);
uint32_t up_perf_getfreq(void);
void up_perf_convert(uint32_t elapsed, FAR struct timespec *ts);