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/arch/risc-v/src/esp32c3/esp32c3_perf.c b/arch/risc-v/src/esp32c3/esp32c3_perf.c new file mode 100644 index 0000000000..6775f8776b --- /dev/null +++ b/arch/risc-v/src/esp32c3/esp32c3_perf.c @@ -0,0 +1,84 @@ +/**************************************************************************** + * 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 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 + * + * 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 +#include + +#include +#include + +#include "esp32c3_attr.h" +#include "riscv_internal.h" +#include "hardware/esp32c3_system.h" +#include "esp32c3_clockconfig.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#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: up_perf_init + ****************************************************************************/ + +void up_perf_init(void *arg) +{ + WRITE_CSR(CSR_PCER_MACHINE, 0x1); + WRITE_CSR(CSR_PCMR_MACHINE, 0x1); +} + +/**************************************************************************** + * Name: up_perf_gettime + ****************************************************************************/ + +uint32_t IRAM_ATTR up_perf_gettime(void) +{ + return READ_CSR(CSR_PCCR_MACHINE); +} + +/**************************************************************************** + * Name: up_perf_getfreq + ****************************************************************************/ + +uint32_t up_perf_getfreq(void) +{ + return CYCLE_PER_SEC; +} + +/**************************************************************************** + * 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; +} 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 +#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