2016-04-21 14:47:09 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-18 17:01:01 -08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-04-21 14:47:09 -07:00
|
|
|
*/
|
|
|
|
|
2016-06-21 12:18:50 -07:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Nios II C-domain interrupt management code for use with Internal
|
|
|
|
* Interrupt Controller (IIC)
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2016-12-23 08:35:34 -05:00
|
|
|
#include <kernel.h>
|
2016-11-08 10:36:50 -05:00
|
|
|
#include <kernel_structs.h>
|
2016-04-21 14:47:09 -07:00
|
|
|
#include <arch/cpu.h>
|
|
|
|
#include <irq.h>
|
2016-06-21 12:18:50 -07:00
|
|
|
#include <sw_isr_table.h>
|
2017-05-11 13:29:15 -07:00
|
|
|
#include <ksched.h>
|
2018-02-08 12:34:35 -08:00
|
|
|
#include <kswap.h>
|
2020-02-06 09:14:51 -05:00
|
|
|
#include <tracing/tracing.h>
|
2019-08-07 09:06:23 +02:00
|
|
|
#include <logging/log.h>
|
|
|
|
LOG_MODULE_DECLARE(os);
|
2016-06-21 12:18:50 -07:00
|
|
|
|
2019-07-11 14:18:28 -07:00
|
|
|
FUNC_NORETURN void z_irq_spurious(void *unused)
|
2016-06-21 12:18:50 -07:00
|
|
|
{
|
|
|
|
ARG_UNUSED(unused);
|
2019-08-07 09:06:23 +02:00
|
|
|
LOG_ERR("Spurious interrupt detected! ipending: %x",
|
|
|
|
z_nios2_creg_read(NIOS2_CR_IPENDING));
|
2019-07-15 15:22:29 -07:00
|
|
|
z_nios2_fatal_error(K_ERR_SPURIOUS_IRQ, NULL);
|
2016-06-21 12:18:50 -07:00
|
|
|
}
|
2016-04-21 14:47:09 -07:00
|
|
|
|
|
|
|
|
2019-11-07 12:43:29 -08:00
|
|
|
void arch_irq_enable(unsigned int irq)
|
2016-04-21 14:47:09 -07:00
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t ienable;
|
2018-08-14 17:57:08 -07:00
|
|
|
unsigned int key;
|
2016-06-07 11:44:08 -07:00
|
|
|
|
|
|
|
key = irq_lock();
|
|
|
|
|
2019-03-14 09:20:46 -06:00
|
|
|
ienable = z_nios2_creg_read(NIOS2_CR_IENABLE);
|
2019-02-26 10:03:24 -08:00
|
|
|
ienable |= BIT(irq);
|
2019-03-14 09:20:46 -06:00
|
|
|
z_nios2_creg_write(NIOS2_CR_IENABLE, ienable);
|
2016-06-07 11:44:08 -07:00
|
|
|
|
|
|
|
irq_unlock(key);
|
2016-04-21 14:47:09 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-06-21 12:18:50 -07:00
|
|
|
|
2019-11-07 12:43:29 -08:00
|
|
|
void arch_irq_disable(unsigned int irq)
|
2016-04-21 14:47:09 -07:00
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t ienable;
|
2018-08-14 17:57:08 -07:00
|
|
|
unsigned int key;
|
2016-06-07 11:44:08 -07:00
|
|
|
|
|
|
|
key = irq_lock();
|
|
|
|
|
2019-03-14 09:20:46 -06:00
|
|
|
ienable = z_nios2_creg_read(NIOS2_CR_IENABLE);
|
2019-02-26 10:03:24 -08:00
|
|
|
ienable &= ~BIT(irq);
|
2019-03-14 09:20:46 -06:00
|
|
|
z_nios2_creg_write(NIOS2_CR_IENABLE, ienable);
|
2016-06-07 11:44:08 -07:00
|
|
|
|
|
|
|
irq_unlock(key);
|
2016-04-21 14:47:09 -07:00
|
|
|
};
|
|
|
|
|
2020-02-19 11:33:21 -08:00
|
|
|
int arch_irq_is_enabled(unsigned int irq)
|
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t ienable;
|
2020-02-19 11:33:21 -08:00
|
|
|
|
|
|
|
ienable = z_nios2_creg_read(NIOS2_CR_IENABLE);
|
|
|
|
return ienable & BIT(irq);
|
|
|
|
}
|
2016-04-21 14:47:09 -07:00
|
|
|
|
2016-06-21 12:18:50 -07:00
|
|
|
/**
|
|
|
|
* @brief Interrupt demux function
|
|
|
|
*
|
|
|
|
* Given a bitfield of pending interrupts, execute the appropriate handler
|
|
|
|
*
|
|
|
|
* @param ipending Bitfield of interrupts
|
|
|
|
*/
|
2020-05-27 11:26:57 -05:00
|
|
|
void _enter_irq(uint32_t ipending)
|
2016-06-21 12:18:50 -07:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
2018-07-23 13:57:06 +05:30
|
|
|
#ifdef CONFIG_EXECUTION_BENCHMARKING
|
|
|
|
extern void read_timer_start_of_isr(void);
|
|
|
|
read_timer_start_of_isr();
|
|
|
|
#endif
|
|
|
|
|
2020-03-16 10:18:03 -07:00
|
|
|
_kernel.cpus[0].nested++;
|
2016-10-25 11:47:52 -07:00
|
|
|
|
2016-06-23 13:49:50 -07:00
|
|
|
#ifdef CONFIG_IRQ_OFFLOAD
|
2019-03-14 09:20:46 -06:00
|
|
|
z_irq_do_offload();
|
2016-06-23 13:49:50 -07:00
|
|
|
#endif
|
|
|
|
|
2016-06-21 12:18:50 -07:00
|
|
|
while (ipending) {
|
2017-01-25 14:32:53 -08:00
|
|
|
struct _isr_table_entry *ite;
|
2016-06-21 12:18:50 -07:00
|
|
|
|
2020-01-28 16:44:59 +08:00
|
|
|
#ifdef CONFIG_TRACING_ISR
|
2019-09-19 09:25:19 +02:00
|
|
|
sys_trace_isr_enter();
|
2020-01-28 16:44:59 +08:00
|
|
|
#endif
|
2016-06-29 16:29:15 -07:00
|
|
|
|
2016-06-21 12:18:50 -07:00
|
|
|
index = find_lsb_set(ipending) - 1;
|
2019-02-26 10:03:24 -08:00
|
|
|
ipending &= ~BIT(index);
|
2016-06-21 12:18:50 -07:00
|
|
|
|
|
|
|
ite = &_sw_isr_table[index];
|
2018-07-23 13:57:06 +05:30
|
|
|
|
|
|
|
#ifdef CONFIG_EXECUTION_BENCHMARKING
|
|
|
|
extern void read_timer_end_of_isr(void);
|
|
|
|
read_timer_end_of_isr();
|
|
|
|
#endif
|
2016-06-21 12:18:50 -07:00
|
|
|
ite->isr(ite->arg);
|
2020-01-28 16:44:59 +08:00
|
|
|
#ifdef CONFIG_TRACING_ISR
|
2018-04-06 07:48:53 -04:00
|
|
|
sys_trace_isr_exit();
|
2020-01-28 16:44:59 +08:00
|
|
|
#endif
|
2016-06-21 12:18:50 -07:00
|
|
|
}
|
2016-10-25 11:47:52 -07:00
|
|
|
|
2020-03-16 10:18:03 -07:00
|
|
|
_kernel.cpus[0].nested--;
|
2017-05-11 13:29:15 -07:00
|
|
|
#ifdef CONFIG_STACK_SENTINEL
|
2019-03-08 14:19:05 -07:00
|
|
|
z_check_stack_sentinel();
|
2017-05-11 13:29:15 -07:00
|
|
|
#endif
|
2016-06-21 12:18:50 -07:00
|
|
|
}
|
|
|
|
|
2018-10-31 17:00:00 -07:00
|
|
|
#ifdef CONFIG_DYNAMIC_INTERRUPTS
|
2019-11-07 12:43:29 -08:00
|
|
|
int arch_irq_connect_dynamic(unsigned int irq, unsigned int priority,
|
|
|
|
void (*routine)(void *parameter), void *parameter,
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t flags)
|
2018-10-31 17:00:00 -07:00
|
|
|
{
|
|
|
|
ARG_UNUSED(flags);
|
|
|
|
ARG_UNUSED(priority);
|
|
|
|
|
|
|
|
z_isr_install(irq, routine, parameter);
|
|
|
|
return irq;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_DYNAMIC_INTERRUPTS */
|