rt-thread-official/libcpu/arm/am335x/interrupt.c

224 lines
5.1 KiB
C
Raw Normal View History

2013-09-20 21:20:51 +08:00
/*
2021-03-27 17:51:56 +08:00
* Copyright (c) 2006-2021, RT-Thread Development Team
2013-09-20 21:20:51 +08:00
*
* SPDX-License-Identifier: Apache-2.0
2013-09-20 21:20:51 +08:00
*
* Change Logs:
* Date Author Notes
* 2013-07-06 Bernard first version
2015-11-11 23:44:05 +08:00
* 2015-11-06 zchong support iar compiler
2013-09-20 21:20:51 +08:00
*/
#include <rthw.h>
#include <rtthread.h>
#include "am33xx.h"
#include "interrupt.h"
#define AINTC_BASE AM33XX_AINTC_REGS
2021-03-27 17:51:56 +08:00
#define MAX_HANDLERS 128
2013-09-20 21:20:51 +08:00
extern volatile rt_uint8_t rt_interrupt_nest;
/* exception and interrupt handler table */
struct rt_irq_desc isr_table[MAX_HANDLERS];
rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
rt_uint32_t rt_thread_switch_interrupt_flag;
/**
* @addtogroup AM33xx
*/
/*@{*/
void rt_dump_aintc(void)
{
int k;
rt_kprintf("active irq %d", INTC_SIR_IRQ(AINTC_BASE));
rt_kprintf("\n--- hw mask ---\n");
for (k = 0; k < 4; k++)
{
rt_kprintf("0x%08x, ", INTC_MIR(AINTC_BASE, k));
}
rt_kprintf("\n--- hw itr ---\n");
for (k = 0; k < 4; k++)
{
rt_kprintf("0x%08x, ", INTC_ITR(AINTC_BASE, k));
}
rt_kprintf("\n");
}
const unsigned int AM335X_VECTOR_BASE = 0x4030FC00;
extern void rt_cpu_vector_set_base(unsigned int addr);
2015-11-11 23:44:05 +08:00
#ifdef __ICCARM__
extern int __vector;
#else
2013-09-20 21:20:51 +08:00
extern int system_vectors;
2015-11-11 23:44:05 +08:00
#endif
2013-09-20 21:20:51 +08:00
static void rt_hw_vector_init(void)
{
unsigned int *dest = (unsigned int *)AM335X_VECTOR_BASE;
2021-03-27 17:51:56 +08:00
2015-11-11 23:44:05 +08:00
#ifdef __ICCARM__
unsigned int *src = (unsigned int *)&__vector;
#else
2013-09-20 21:20:51 +08:00
unsigned int *src = (unsigned int *)&system_vectors;
2015-11-11 23:44:05 +08:00
#endif
2021-03-27 17:51:56 +08:00
2013-09-20 21:20:51 +08:00
rt_memcpy(dest, src, 16 * 4);
rt_cpu_vector_set_base(AM335X_VECTOR_BASE);
}
/**
* This function will initialize hardware interrupt
*/
void rt_hw_interrupt_init(void)
{
/* Reset the ARM interrupt controller */
INTC_SYSCONFIG(AINTC_BASE) = INTC_SYSCONFIG_SOFTRESET;
/* Wait for the reset to complete */
while((INTC_SYSSTATUS(AINTC_BASE)
& INTC_SYSSTATUS_RESETDONE) != INTC_SYSSTATUS_RESETDONE);
/* Enable any interrupt generation by setting priority threshold */
INTC_THRESHOLD(AINTC_BASE) = INTC_THRESHOLD_PRIORITYTHRESHOLD;
2013-09-20 21:20:51 +08:00
/* initialize vector table */
rt_hw_vector_init();
/* init exceptions table */
rt_memset(isr_table, 0x00, sizeof(isr_table));
/* init interrupt nest, and context in thread sp */
rt_interrupt_nest = 0;
rt_interrupt_from_thread = 0;
rt_interrupt_to_thread = 0;
rt_thread_switch_interrupt_flag = 0;
}
/**
* This function will mask a interrupt.
* @param vector the interrupt number
*/
void rt_hw_interrupt_mask(int vector)
{
INTC_MIR_SET(AINTC_BASE, vector >> 0x05) = 0x1 << (vector & 0x1f);
}
/**
* This function will un-mask a interrupt.
* @param vector the interrupt number
*/
void rt_hw_interrupt_umask(int vector)
{
INTC_MIR_CLEAR(AINTC_BASE, vector >> 0x05) = 0x1 << (vector & 0x1f);
}
/**
* This function will control the interrupt attribute.
* @param vector the interrupt number
*/
void rt_hw_interrupt_control(int vector, int priority, int route)
{
int fiq;
if (route == 0)
fiq = 0;
else
fiq = 1;
INTC_ILR(AINTC_BASE, vector) = ((priority << 0x02) & 0x1FC) | fiq ;
}
int rt_hw_interrupt_get_active(int fiq_irq)
{
int ir;
if (fiq_irq == INT_FIQ)
{
ir = INTC_SIR_FIQ(AINTC_BASE) & 0x7f;
}
else
{
ir = INTC_SIR_IRQ(AINTC_BASE) & 0x7f;
}
return ir;
}
void rt_hw_interrupt_ack(int fiq_irq)
{
if (fiq_irq == INT_FIQ)
{
/* new FIQ generation */
INTC_CONTROL(AINTC_BASE) |= 0x02;
}
else
{
/* new IRQ generation */
INTC_CONTROL(AINTC_BASE) |= 0x01;
}
}
/**
* This function will install a interrupt service routine to a interrupt.
* @param vector the interrupt number
* @param new_handler the interrupt service routine to be installed
* @param old_handler the old interrupt service routine
*/
rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
void *param, const char *name)
2013-09-20 21:20:51 +08:00
{
rt_isr_handler_t old_handler = RT_NULL;
if(vector < MAX_HANDLERS)
{
old_handler = isr_table[vector].handler;
if (handler != RT_NULL)
{
#ifdef RT_USING_INTERRUPT_INFO
rt_strncpy(isr_table[vector].name, name, RT_NAME_MAX);
#endif /* RT_USING_INTERRUPT_INFO */
isr_table[vector].handler = handler;
isr_table[vector].param = param;
}
}
return old_handler;
}
/**
* This function will trigger an interrupt.
* @param vector the interrupt number
*/
void rt_hw_interrupt_trigger(int vector)
{
INTC_ISR_SET(AINTC_BASE, vector>>5) = 1 << (vector & 0x1f);
}
void rt_hw_interrupt_clear(int vector)
{
INTC_ISR_CLEAR(AINTC_BASE, vector>>5) = 1 << (vector & 0x1f);
}
void rt_dump_isr_table(void)
{
int idx;
for(idx = 0; idx < MAX_HANDLERS; idx++)
{
#ifdef RT_USING_INTERRUPT_INFO
rt_kprintf("nr:%4d, name: %*.s, handler: 0x%p, param: 0x%08x\r\n",
idx, RT_NAME_MAX, isr_table[idx].name,
isr_table[idx].handler, isr_table[idx].param);
#else
rt_kprintf("nr:%4d, handler: 0x%p, param: 0x%08x\r\n",
idx, isr_table[idx].handler, isr_table[idx].param);
#endif
}
}
/*@}*/
2015-11-11 23:44:05 +08:00