You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "acassis (via GitHub)" <gi...@apache.org> on 2024/09/01 14:08:38 UTC
Re: [PR] irq: irq with the same priority share the same wqueue [nuttx]
acassis commented on code in PR #13256:
URL: https://github.com/apache/nuttx/pull/13256#discussion_r1740112489
##########
sched/irq/irq_attach_wqueue.c:
##########
@@ -0,0 +1,220 @@
+/****************************************************************************
+ * sched/irq/irq_attach_wqueue.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 <errno.h>
+#include <stdio.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/wqueue.h>
+#include <debug.h>
+
+#include "irq/irq.h"
+#include "sched/sched.h"
+
+/****************************************************************************
+ * Privte Types
+ ****************************************************************************/
+
+/* This is the type of the list of interrupt handlers, one for each IRQ.
+ * This type provided all of the information necessary to irq_dispatch to
+ * transfer control to interrupt handlers after the occurrence of an
+ * interrupt.
+ */
+
+struct irq_work_info_s
+{
+ xcpt_t handler; /* Address of the interrupt handler */
+ xcpt_t isrwork; /* Address of the interrupt worked handler */
+ FAR void *arg; /* The argument provided to the interrupt handler. */
+ int irq; /* Irq id */
+ struct work_s work; /* Interrupt work to the wq */
+
+ FAR struct kwork_wqueue_s *wqueue; /* Work queue. */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE
+static struct irq_work_info_s
+g_irq_work_vector[CONFIG_ARCH_NUSER_INTERRUPTS];
+#else
+static struct irq_work_info_s g_irq_work_vector[NR_IRQS];
+#endif
+
+static mutex_t g_irq_wqueue_lock = NXMUTEX_INITIALIZER;
+static FAR struct kwork_wqueue_s *g_irq_wqueue[CONFIG_IRQ_NWORKS];
+static int g_irq_wqueue_count = 0;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static inline_function struct kwork_wqueue_s *irq_get_wqueue(int priority)
+{
+ FAR struct kwork_wqueue_s *queue;
+ int wqueue_priority;
+ int i;
+
+ nxmutex_lock(&g_irq_wqueue_lock);
+ for (i = 0; i < g_irq_wqueue_count; i++)
+ {
+ wqueue_priority = work_queue_priority_wq(g_irq_wqueue[i]);
+ DEBUGASSERT(wqueue_priority >= SCHED_PRIORITY_MIN &&
+ wqueue_priority <= SCHED_PRIORITY_MAX);
+
+ if (wqueue_priority == priority)
+ {
+ nxmutex_unlock(&g_irq_wqueue_lock);
+ return g_irq_wqueue[i];
+ }
+ }
+
+ DEBUGASSERT(g_irq_wqueue_count < CONFIG_IRQ_NWORKS);
+
+ queue = work_queue_create("isrwork", priority,
+ CONFIG_IRQ_WORK_STACKSIZE, 1);
+
+ g_irq_wqueue[g_irq_wqueue_count++] = queue;
+ nxmutex_unlock(&g_irq_wqueue_lock);
+ return queue;
+}
+
+/* Default interrupt handler for worked interrupts.
+ * Useful for oneshot interrupts.
+ */
+
+static void irq_work_handler(FAR void *arg)
+{
+ FAR struct irq_work_info_s *info = (FAR struct irq_work_info_s *)arg;
+
+ info->isrwork(info->irq, NULL, info->arg);
+}
+
+static int irq_default_handler(int irq, FAR void *regs, FAR void *arg)
+{
+ FAR struct irq_work_info_s *info;
+ int ret = IRQ_WAKE_THREAD;
+ int ndx = IRQ_TO_NDX(irq);
+ xcpt_t vector;
+
+ if (ndx < 0)
+ {
+ return ndx;
+ }
+
+ info = &g_irq_work_vector[ndx];
+ vector = info->handler;
+
Review Comment:
please remove empty line
--
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