This is an automated email from the ASF dual-hosted git repository.
xiaoxiang 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 9481456fde risc-v/esp32c3: Implement up_perf_xxx API
9481456fde is described below
commit 9481456fde85856e81ca8feb2e0471cae39ca22a
Author: Huang Qi <[email protected]>
AuthorDate: Mon Jun 20 11:16:14 2022 +0800
risc-v/esp32c3: Implement up_perf_xxx API
Signed-off-by: Huang Qi <[email protected]>
---
arch/risc-v/src/esp32c3/Make.defs | 2 +-
.../risc-v/src/esp32c3/esp32c3_perf.c | 72 ++++++++++++----------
.../esp32c3/esp32c3-devkit/src/esp32c3_boot.c | 6 ++
3 files changed, 45 insertions(+), 35 deletions(-)
diff --git a/arch/risc-v/src/esp32c3/Make.defs
b/arch/risc-v/src/esp32c3/Make.defs
index f26aae8e90..469cb1ebb4 100644
--- a/arch/risc-v/src/esp32c3/Make.defs
+++ b/arch/risc-v/src/esp32c3/Make.defs
@@ -39,7 +39,7 @@ CHIP_CSRCS += esp32c3_irq.c
CHIP_CSRCS += esp32c3_clockconfig.c esp32c3_gpio.c
CHIP_CSRCS += esp32c3_lowputc.c esp32c3_serial.c
CHIP_CSRCS += esp32c3_systemreset.c esp32c3_resetcause.c
-CHIP_CSRCS += esp32c3_uid.c
+CHIP_CSRCS += esp32c3_uid.c esp32c3_perf.c
ifeq ($(CONFIG_ESP32C3_REGION_PROTECTION),y)
CHIP_CSRCS += esp32c3_region.c
diff --git a/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_boot.c
b/arch/risc-v/src/esp32c3/esp32c3_perf.c
similarity index 60%
copy from boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_boot.c
copy to arch/risc-v/src/esp32c3/esp32c3_perf.c
index d008b76b11..6775f8776b 100644
--- a/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_boot.c
+++ b/arch/risc-v/src/esp32c3/esp32c3_perf.c
@@ -1,9 +1,9 @@
/****************************************************************************
- * boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_boot.c
+ * arch/risc-v/src/esp32c3/esp32c3_perf.c
*
* 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
+ * this args 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
@@ -23,58 +23,62 @@
****************************************************************************/
#include <nuttx/config.h>
+#include <nuttx/clock.h>
+
+#include <stdint.h>
+#include <time.h>
+
+#include "esp32c3_attr.h"
+#include "riscv_internal.h"
+#include "hardware/esp32c3_system.h"
+#include "esp32c3_clockconfig.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
+#define NSEC_PER_CYCLE (1000 / CONFIG_ESP32C3_CPU_FREQ_MHZ)
+#define CYCLE_PER_SEC (USEC_PER_SEC * CONFIG_ESP32C3_CPU_FREQ_MHZ)
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
- * Name: esp32c3_board_initialize
- *
- * Description:
- * All ESP32-C3 architectures must provide the following entry point.
- * This entry point is called early in the initialization -- after all
- * memory has been configured and mapped but before any devices have been
- * initialized.
- *
+ * Name: up_perf_init
****************************************************************************/
-void esp32c3_board_initialize(void)
+void up_perf_init(void *arg)
{
- /* Configure on-board LEDs if LED support has been selected. */
+ WRITE_CSR(CSR_PCER_MACHINE, 0x1);
+ WRITE_CSR(CSR_PCMR_MACHINE, 0x1);
+}
+
+/****************************************************************************
+ * Name: up_perf_gettime
+ ****************************************************************************/
-#ifdef CONFIG_ARCH_LEDS
- board_autoled_initialize();
-#endif
+uint32_t IRAM_ATTR up_perf_gettime(void)
+{
+ return READ_CSR(CSR_PCCR_MACHINE);
}
/****************************************************************************
- * Name: board_late_initialize
- *
- * Description:
- * If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional
- * initialization call will be performed in the boot-up sequence to a
- * function called board_late_initialize(). board_late_initialize() will
- * be called immediately after up_initialize() is called and just before
- * the initial application is started. This additional initialization
- * phase may be used, for example, to initialize board-specific device
- * drivers.
- *
+ * Name: up_perf_getfreq
****************************************************************************/
-#ifdef CONFIG_BOARD_LATE_INITIALIZE
-void board_late_initialize(void)
+uint32_t up_perf_getfreq(void)
{
- /* Perform board-specific initialization */
+ return CYCLE_PER_SEC;
+}
- esp32c3_bringup();
+/****************************************************************************
+ * Name: up_perf_convert
+ ****************************************************************************/
+
+void up_perf_convert(uint32_t elapsed, struct timespec *ts)
+{
+ ts->tv_sec = elapsed / CYCLE_PER_SEC;
+ elapsed -= (uint64_t)ts->tv_sec * CYCLE_PER_SEC;
+ ts->tv_nsec = elapsed * NSEC_PER_CYCLE;
}
-#endif
diff --git a/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_boot.c
b/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_boot.c
index d008b76b11..76630e9853 100644
--- a/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_boot.c
+++ b/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_boot.c
@@ -24,6 +24,8 @@
#include <nuttx/config.h>
+#include "riscv_internal.h"
+
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -49,6 +51,10 @@
void esp32c3_board_initialize(void)
{
+#ifdef CONFIG_SCHED_CRITMONITOR
+ up_perf_init(NULL);
+#endif
+
/* Configure on-board LEDs if LED support has been selected. */
#ifdef CONFIG_ARCH_LEDS