2015-04-11 07:44:37 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2014 Wind River Systems, Inc.
|
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Licensed 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
|
2015-04-11 07:44:37 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-04-11 07:44:37 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08: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.
|
2015-04-11 07:44:37 +08:00
|
|
|
*/
|
|
|
|
|
2015-12-04 23:09:39 +08:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief ARM CORTEX-M3 interrupt management
|
|
|
|
*
|
2015-10-21 00:42:33 +08:00
|
|
|
*
|
|
|
|
* Interrupt management: enabling/disabling and dynamic ISR
|
|
|
|
* connecting/replacing. SW_ISR_TABLE_DYNAMIC has to be enabled for
|
|
|
|
* connecting ISRs at runtime.
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-04-11 07:44:37 +08:00
|
|
|
|
|
|
|
#include <nanokernel.h>
|
2015-05-29 01:56:47 +08:00
|
|
|
#include <arch/cpu.h>
|
2015-04-11 07:44:37 +08:00
|
|
|
#include <misc/__assert.h>
|
|
|
|
#include <toolchain.h>
|
|
|
|
#include <sections.h>
|
|
|
|
#include <sw_isr_table.h>
|
2016-02-26 05:21:02 +08:00
|
|
|
#include <irq.h>
|
2015-04-11 07:44:37 +08:00
|
|
|
|
|
|
|
extern void __reserved(void);
|
|
|
|
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Enable an interrupt line
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* Clear possible pending interrupts on the line, and enable the interrupt
|
|
|
|
* line. After this call, the CPU will receive interrupts for the specified
|
|
|
|
* <irq>.
|
|
|
|
*
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return N/A
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2016-02-26 05:21:02 +08:00
|
|
|
void _arch_irq_enable(unsigned int irq)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
|
|
|
/* before enabling interrupts, ensure that interrupt is cleared */
|
|
|
|
_NvicIrqUnpend(irq);
|
|
|
|
_NvicIrqEnable(irq);
|
|
|
|
}
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Disable an interrupt line
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* Disable an interrupt line. After this call, the CPU will stop receiving
|
|
|
|
* interrupts for the specified <irq>.
|
|
|
|
*
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return N/A
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2016-02-26 05:21:02 +08:00
|
|
|
void _arch_irq_disable(unsigned int irq)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
|
|
|
_NvicIrqDisable(irq);
|
|
|
|
}
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
2015-08-13 03:15:48 +08:00
|
|
|
* @internal
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Set an interrupt's priority
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2016-02-05 05:55:57 +08:00
|
|
|
* The priority is verified if ASSERT_ON is enabled. The maximum number
|
|
|
|
* of priority levels is a little complex, as there are some hardware
|
|
|
|
* priority levels which are reserved: three for various types of exceptions,
|
|
|
|
* and possibly one additional to support zero latency interrupts.
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return N/A
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2016-02-05 05:55:57 +08:00
|
|
|
void _irq_priority_set(unsigned int irq, unsigned int prio, uint32_t flags)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
2016-02-05 05:55:57 +08:00
|
|
|
/* Hardware priority levels 0 and 1 reserved for Kernel use.
|
|
|
|
* So we add 2 to the requested priority level. If we support
|
|
|
|
* ZLI, 2 is also reserved so we add 3.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if CONFIG_ZERO_LATENCY_IRQS
|
|
|
|
#define IRQ_PRIORITY_OFFSET 3
|
|
|
|
/* If we have zero latency interrupts, that makes priority level 2
|
|
|
|
* a case with special semantics; it is not masked by irq_lock().
|
|
|
|
* Our policy is to express priority levels with special properties
|
|
|
|
* via flags
|
|
|
|
*/
|
|
|
|
if (flags | IRQ_ZERO_LATENCY) {
|
|
|
|
prio = 2;
|
|
|
|
} else {
|
|
|
|
prio += IRQ_PRIORITY_OFFSET;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define IRQ_PRIORITY_OFFSET 2
|
|
|
|
ARG_UNUSED(flags);
|
|
|
|
prio += IRQ_PRIORITY_OFFSET;
|
|
|
|
#endif
|
|
|
|
/* Last priority level reserved for PendSV exception */
|
|
|
|
__ASSERT(prio < ((1 << CONFIG_NUM_IRQ_PRIO_BITS) - 1),
|
|
|
|
"invalid priority %d! values must be less than %d\n",
|
|
|
|
prio - IRQ_PRIORITY_OFFSET,
|
|
|
|
(1 << CONFIG_NUM_IRQ_PRIO_BITS) - (IRQ_PRIORITY_OFFSET + 1));
|
2015-04-11 07:44:37 +08:00
|
|
|
_NvicIrqPrioSet(irq, _EXC_PRIO(prio));
|
|
|
|
}
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Spurious interrupt handler
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* Installed in all dynamic interrupt slots at boot time. Throws an error if
|
|
|
|
* called.
|
|
|
|
*
|
|
|
|
* See __reserved().
|
|
|
|
*
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return N/A
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-04-23 21:49:36 +08:00
|
|
|
void _irq_spurious(void *unused)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
|
|
|
ARG_UNUSED(unused);
|
|
|
|
__reserved();
|
|
|
|
}
|
|
|
|
|
2016-01-21 07:13:38 +08:00
|
|
|
#if CONFIG_SW_ISR_TABLE_DYNAMIC
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*
|
|
|
|
* @brief Replace an interrupt handler by another
|
|
|
|
*
|
|
|
|
* An interrupt's ISR can be replaced at runtime.
|
|
|
|
*
|
|
|
|
* @return N/A
|
|
|
|
*/
|
|
|
|
void _irq_handler_set(unsigned int irq,
|
|
|
|
void (*new)(void *arg),
|
|
|
|
void *arg)
|
|
|
|
{
|
|
|
|
int key = irq_lock();
|
|
|
|
|
|
|
|
_sw_isr_table[irq].isr = new;
|
|
|
|
_sw_isr_table[irq].arg = arg;
|
|
|
|
|
|
|
|
irq_unlock(key);
|
|
|
|
}
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Connect an ISR to an interrupt line
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* <isr> is connected to interrupt line <irq> (exception #<irq>+16). No prior
|
|
|
|
* ISR can have been connected on <irq> interrupt line since the system booted.
|
|
|
|
*
|
|
|
|
* This routine will hang if another ISR was connected for interrupt line <irq>
|
|
|
|
* and ASSERT_ON is enabled; if ASSERT_ON is disabled, it will fail silently.
|
|
|
|
*
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return the interrupt line number
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2016-02-26 05:21:02 +08:00
|
|
|
int _arch_irq_connect_dynamic(unsigned int irq,
|
2015-04-11 07:44:37 +08:00
|
|
|
unsigned int prio,
|
|
|
|
void (*isr)(void *arg),
|
2015-11-03 07:06:08 +08:00
|
|
|
void *arg,
|
|
|
|
uint32_t flags)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
2015-11-03 07:06:08 +08:00
|
|
|
ARG_UNUSED(flags);
|
2015-10-27 06:46:34 +08:00
|
|
|
_irq_handler_set(irq, isr, arg);
|
2016-02-05 05:55:57 +08:00
|
|
|
_irq_priority_set(irq, prio, flags);
|
2015-04-11 07:44:37 +08:00
|
|
|
return irq;
|
|
|
|
}
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
2015-08-13 03:15:48 +08:00
|
|
|
*
|
|
|
|
* @internal
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Disconnect an ISR from an interrupt line
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* Interrupt line <irq> (exception #<irq>+16) is disconnected from its ISR and
|
|
|
|
* the latter is replaced by _irq_spurious(). irq_disable() should have
|
|
|
|
* been called before invoking this routine.
|
|
|
|
*
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return N/A
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-08-13 03:15:48 +08:00
|
|
|
void _irq_disconnect(unsigned int irq)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
2015-10-27 06:46:34 +08:00
|
|
|
_irq_handler_set(irq, _irq_spurious, NULL);
|
2015-04-11 07:44:37 +08:00
|
|
|
}
|
2016-01-21 07:13:38 +08:00
|
|
|
#endif /* CONFIG_SW_ISR_TABLE_DYNAMIC */
|