You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "pkarashchenko (via GitHub)" <gi...@apache.org> on 2023/04/05 10:46:59 UTC

[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #8953: risc-v/espressif: Add support for Tickless mode

pkarashchenko commented on code in PR #8953:
URL: https://github.com/apache/nuttx/pull/8953#discussion_r1158344031


##########
arch/risc-v/src/espressif/esp_tickless.c:
##########
@@ -0,0 +1,432 @@
+/****************************************************************************
+ * arch/risc-v/src/espressif/esp_tickless.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
+ * 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 <assert.h>
+#include <stdint.h>
+#include <time.h>
+
+#include <arch/board/board.h>
+#include <arch/irq.h>
+#include <nuttx/arch.h>
+#include <nuttx/clock.h>
+
+#include "chip.h"
+#include "esp_irq.h"
+
+#include "esp_attr.h"
+#include "hal/systimer_hal.h"
+#include "hal/systimer_ll.h"
+#include "periph_ctrl.h"
+#include "systimer.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#if SOC_SYSTIMER_INT_LEVEL
+#  define SYSTIMER_TRIGGER_TYPE ESP_IRQ_TRIGGER_LEVEL
+#else
+#  define SYSTIMER_TRIGGER_TYPE ESP_IRQ_TRIGGER_EDGE
+#endif /* SOC_SYSTIMER_INT_LEVEL */
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Systimer HAL layer object */
+
+static systimer_hal_context_t systimer_hal;
+
+/* Whether an interval timer is being started */
+
+static bool g_timer_started;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp_tickless_isr
+ *
+ * Description:
+ *   Handler to be executed by the Systimer ISR.
+ *
+ * Input Parameters:
+ *   irq           - IRQ associated to that interrupt.
+ *   context       - Interrupt register state save info.
+ *   arg           - A pointer to the argument provided when the interrupt
+ *                   was registered.
+ *
+ * Returned Value:
+ *   Zero on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+static int esp_tickless_isr(int irq, void *context, void *arg)
+{
+  g_timer_started = false;
+
+  systimer_ll_clear_alarm_int(systimer_hal.dev,
+                              SYSTIMER_ALARM_OS_TICK_CORE0);
+
+  nxsched_timer_expiration();
+
+  return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_get_idletime
+ *
+ * Description:
+ *   This function returns the idle time.
+ *
+ * Input Parameters:
+ *   None.
+ *
+ * Returned Value:
+ *   The time in system ticks remaining for idle.
+ *   Zero means system is busy.
+ *
+ ****************************************************************************/
+
+uint32_t up_get_idletime(void)
+{
+  uint32_t us;
+  uint64_t alarm_value;
+  uint64_t counter;
+  irqstate_t flags;
+
+  flags = enter_critical_section();

Review Comment:
   should this be a critical section or a spinlock?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org