2008-09-19 00:56:32 +02:00
|
|
|
/****************************************************************************
|
2014-08-08 22:31:15 +02:00
|
|
|
* sched/irq/irq_dispatch.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* 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
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* 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.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-09-19 00:56:32 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-09-19 00:56:32 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2008-09-19 00:56:32 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2009-12-14 19:39:29 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2008-09-19 00:56:32 +02:00
|
|
|
#include <debug.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/irq.h>
|
2017-03-30 15:38:37 +02:00
|
|
|
#include <nuttx/random.h>
|
2020-06-16 15:57:49 +02:00
|
|
|
#include <nuttx/sched_note.h>
|
2008-09-19 00:56:32 +02:00
|
|
|
|
2014-08-08 22:31:15 +02:00
|
|
|
#include "irq/irq.h"
|
2018-08-25 15:10:11 +02:00
|
|
|
#include "clock/clock.h"
|
2018-11-15 14:11:51 +01:00
|
|
|
#include "sched/sched.h"
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-01-13 00:41:09 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-08-25 15:10:11 +02:00
|
|
|
/* INCR_COUNT - Increment the count of interrupts taken on this IRQ number */
|
|
|
|
|
2019-01-27 17:13:28 +01:00
|
|
|
#ifndef CONFIG_SCHED_IRQMONITOR
|
2018-01-13 00:41:09 +01:00
|
|
|
# define INCR_COUNT(ndx)
|
2019-01-27 17:13:28 +01:00
|
|
|
#elif defined(CONFIG_HAVE_LONG_LONG)
|
|
|
|
# define INCR_COUNT(ndx) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
g_irqvector[ndx].count++; \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
#else
|
|
|
|
# define INCR_COUNT(ndx) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if (++g_irqvector[ndx].lscount == 0) \
|
|
|
|
{ \
|
|
|
|
g_irqvector[ndx].mscount++; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while (0)
|
2018-01-13 00:41:09 +01:00
|
|
|
#endif
|
|
|
|
|
2020-05-04 16:15:10 +02:00
|
|
|
/* CALL_VECTOR - Call the interrupt service routine attached to this
|
|
|
|
* interrupt request
|
2018-08-25 15:10:11 +02:00
|
|
|
*/
|
|
|
|
|
2019-01-27 17:13:28 +01:00
|
|
|
#ifndef CONFIG_SCHED_IRQMONITOR
|
|
|
|
# define CALL_VECTOR(ndx, vector, irq, context, arg) \
|
|
|
|
vector(irq, context, arg)
|
|
|
|
#elif defined(CONFIG_SCHED_CRITMONITOR)
|
2018-08-25 15:10:11 +02:00
|
|
|
# define CALL_VECTOR(ndx, vector, irq, context, arg) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
struct timespec delta; \
|
2018-11-26 19:18:58 +01:00
|
|
|
uint32_t start; \
|
|
|
|
uint32_t elapsed; \
|
|
|
|
start = up_critmon_gettime(); \
|
2018-08-25 15:10:11 +02:00
|
|
|
vector(irq, context, arg); \
|
2018-11-26 19:18:58 +01:00
|
|
|
elapsed = up_critmon_gettime() - start; \
|
|
|
|
up_critmon_convert(elapsed, &delta); \
|
2018-08-25 15:10:11 +02:00
|
|
|
if (delta.tv_nsec > g_irqvector[ndx].time) \
|
|
|
|
{ \
|
|
|
|
g_irqvector[ndx].time = delta.tv_nsec; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
#else
|
2018-11-26 18:29:20 +01:00
|
|
|
# define CALL_VECTOR(ndx, vector, irq, context, arg) \
|
|
|
|
do \
|
|
|
|
{ \
|
2018-11-26 19:18:58 +01:00
|
|
|
struct timespec start; \
|
|
|
|
struct timespec end; \
|
2018-11-26 18:29:20 +01:00
|
|
|
struct timespec delta; \
|
2020-05-04 16:15:10 +02:00
|
|
|
clock_systime_timespec(&start); \
|
2018-11-26 18:29:20 +01:00
|
|
|
vector(irq, context, arg); \
|
2020-05-04 16:15:10 +02:00
|
|
|
clock_systime_timespec(&end); \
|
2018-11-26 19:18:58 +01:00
|
|
|
clock_timespec_subtract(&end, &start, &delta); \
|
2018-11-26 18:29:20 +01:00
|
|
|
if (delta.tv_nsec > g_irqvector[ndx].time) \
|
|
|
|
{ \
|
|
|
|
g_irqvector[ndx].time = delta.tv_nsec; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
#endif /* CONFIG_SCHED_IRQMONITOR */
|
|
|
|
|
2008-09-19 00:56:32 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Functions
|
2008-09-19 00:56:32 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-09-19 00:56:32 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Name: irq_dispatch
|
|
|
|
*
|
|
|
|
* Description:
|
2017-03-30 15:38:37 +02:00
|
|
|
* This function must be called from the architecture-specific logic in
|
2012-07-14 21:30:31 +02:00
|
|
|
* order to dispatch an interrupt to the appropriate, registered handling
|
|
|
|
* logic.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2015-10-03 01:43:18 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-02-27 22:17:21 +01:00
|
|
|
void irq_dispatch(int irq, FAR void *context)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2018-08-24 23:01:32 +02:00
|
|
|
xcpt_t vector = irq_unexpected_isr;
|
|
|
|
FAR void *arg = NULL;
|
2018-08-29 15:13:21 +02:00
|
|
|
unsigned int ndx = irq;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-02-27 22:17:21 +01:00
|
|
|
#if NR_IRQS > 0
|
2018-08-24 23:01:32 +02:00
|
|
|
if ((unsigned)irq < NR_IRQS)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2017-03-03 15:55:16 +01:00
|
|
|
#ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE
|
2018-08-29 13:44:05 +02:00
|
|
|
ndx = g_irqmap[irq];
|
2018-08-24 23:01:32 +02:00
|
|
|
if (ndx < CONFIG_ARCH_NUSER_INTERRUPTS)
|
2017-03-03 15:55:16 +01:00
|
|
|
{
|
2018-08-24 23:01:32 +02:00
|
|
|
if (g_irqvector[ndx].handler)
|
|
|
|
{
|
|
|
|
vector = g_irqvector[ndx].handler;
|
|
|
|
arg = g_irqvector[ndx].arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
INCR_COUNT(ndx);
|
2017-03-03 15:55:16 +01:00
|
|
|
}
|
2018-08-24 23:01:32 +02:00
|
|
|
#else
|
2018-08-29 13:44:05 +02:00
|
|
|
if (g_irqvector[ndx].handler)
|
2017-03-03 15:55:16 +01:00
|
|
|
{
|
2018-08-29 13:44:05 +02:00
|
|
|
vector = g_irqvector[ndx].handler;
|
|
|
|
arg = g_irqvector[ndx].arg;
|
2017-03-03 15:55:16 +01:00
|
|
|
}
|
2018-08-24 23:01:32 +02:00
|
|
|
|
2018-08-29 13:44:05 +02:00
|
|
|
INCR_COUNT(ndx);
|
2017-03-03 15:55:16 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2007-02-27 22:17:21 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2017-03-30 15:38:37 +02:00
|
|
|
#ifdef CONFIG_CRYPTO_RANDOM_POOL_COLLECT_IRQ_RANDOMNESS
|
|
|
|
/* Add interrupt timing randomness to entropy pool */
|
|
|
|
|
|
|
|
add_irq_randomness(irq);
|
|
|
|
#endif
|
|
|
|
|
2020-06-16 15:57:49 +02:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
|
|
|
|
/* Notify that we are entering into the interrupt handler */
|
|
|
|
|
|
|
|
sched_note_irqhandler(irq, vector, true);
|
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Then dispatch to the interrupt handler */
|
|
|
|
|
2018-08-25 15:10:11 +02:00
|
|
|
CALL_VECTOR(ndx, vector, irq, context, arg);
|
2018-08-30 18:27:18 +02:00
|
|
|
UNUSED(ndx);
|
2018-11-15 14:11:51 +01:00
|
|
|
|
2020-06-16 15:57:49 +02:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
|
|
|
|
/* Notify that we are leaving from the interrupt handler */
|
|
|
|
|
|
|
|
sched_note_irqhandler(irq, vector, false);
|
|
|
|
#endif
|
|
|
|
|
2018-11-15 14:11:51 +01:00
|
|
|
/* Record the new "running" task. g_running_tasks[] is only used by
|
|
|
|
* assertion logic for reporting crashes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
g_running_tasks[this_cpu()] = this_task();
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|