2013-01-08 21:05:02 +08:00
|
|
|
/*
|
|
|
|
* File : interrupt.c
|
|
|
|
* This file is part of RT-Thread RTOS
|
|
|
|
* COPYRIGHT (C) 2009, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* The license and distribution terms for this file may be
|
|
|
|
* found in the file LICENSE in this distribution or at
|
|
|
|
* http://www.rt-thread.org/license/LICENSE
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2009-01-05 Bernard first version
|
|
|
|
*/
|
|
|
|
|
2013-04-01 10:58:36 +08:00
|
|
|
#include <rthw.h>
|
2013-01-08 21:05:02 +08:00
|
|
|
#include <asm/ppc4xx.h>
|
|
|
|
#include <asm/processor.h>
|
|
|
|
|
|
|
|
/* interrupt nest */
|
|
|
|
extern volatile rt_uint8_t rt_interrupt_nest;
|
|
|
|
|
|
|
|
/* exception and interrupt handler table */
|
|
|
|
#define MAX_HANDLERS 32
|
2013-04-01 10:58:36 +08:00
|
|
|
struct rt_irq_desc isr_table[MAX_HANDLERS];
|
2013-01-08 21:05:02 +08:00
|
|
|
|
|
|
|
rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
|
|
|
|
rt_uint32_t rt_thread_switch_interrput_flag;
|
|
|
|
|
2013-04-01 10:58:36 +08:00
|
|
|
rt_isr_handler_t rt_hw_interrupt_handler(rt_uint32_t vector, void* param)
|
2013-01-08 21:05:02 +08:00
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
|
|
|
|
return RT_NULL;
|
2013-01-08 21:05:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void uic_irq_ack(unsigned int vec)
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
mtdcr(uic0sr, UIC_MASK(vec));
|
2013-01-08 21:05:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void uic_int_handler (unsigned int vec)
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
rt_interrupt_enter();
|
2013-01-08 21:05:02 +08:00
|
|
|
|
|
|
|
/* Allow external interrupts to the CPU. */
|
2013-04-01 10:58:36 +08:00
|
|
|
if (isr_table [vec].handler != 0)
|
2013-01-08 21:05:02 +08:00
|
|
|
{
|
2013-04-01 10:58:36 +08:00
|
|
|
(*isr_table[vec].handler)(vec, isr_table[vec].param);
|
2013-01-08 21:05:02 +08:00
|
|
|
}
|
|
|
|
uic_irq_ack(vec);
|
2021-03-27 17:51:56 +08:00
|
|
|
|
2013-01-08 21:05:02 +08:00
|
|
|
rt_interrupt_leave();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handler for UIC interrupt */
|
|
|
|
void uic_interrupt(rt_uint32_t uic_base, int vec_base)
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
int vec;
|
|
|
|
rt_uint32_t uic_msr;
|
|
|
|
rt_uint32_t msr_shift;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read masked interrupt status register to determine interrupt source
|
|
|
|
*/
|
|
|
|
uic_msr = get_dcr(uic_base + UIC_MSR);
|
|
|
|
msr_shift = uic_msr;
|
|
|
|
vec = vec_base;
|
|
|
|
|
|
|
|
while (msr_shift != 0)
|
|
|
|
{
|
|
|
|
if (msr_shift & 0x80000000)
|
|
|
|
uic_int_handler(vec);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shift msr to next position and increment vector
|
|
|
|
*/
|
|
|
|
msr_shift <<= 1;
|
|
|
|
vec++;
|
|
|
|
}
|
2013-01-08 21:05:02 +08:00
|
|
|
}
|
|
|
|
|
2021-03-27 17:51:56 +08:00
|
|
|
rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler,
|
2018-12-05 20:38:49 +08:00
|
|
|
void* param, const char* name)
|
2013-01-08 21:05:02 +08:00
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
int intVal;
|
2013-04-01 10:58:36 +08:00
|
|
|
rt_isr_handler_t old_handler;
|
2013-01-08 21:05:02 +08:00
|
|
|
|
2021-03-27 17:51:56 +08:00
|
|
|
if (((int)vector < 0) || ((int) vector >= MAX_HANDLERS))
|
|
|
|
{
|
2013-04-01 10:58:36 +08:00
|
|
|
return RT_NULL; /* out of range */
|
2021-03-27 17:51:56 +08:00
|
|
|
}
|
|
|
|
|
2013-01-08 21:05:02 +08:00
|
|
|
/* install the handler in the system interrupt table */
|
|
|
|
intVal = rt_hw_interrupt_disable (); /* lock interrupts to prevent races */
|
|
|
|
|
2013-04-01 10:58:36 +08:00
|
|
|
old_handler = isr_table[vector].handler;
|
|
|
|
isr_table[vector].handler = new_handler;
|
|
|
|
isr_table[vector].param = param;
|
2021-03-27 17:51:56 +08:00
|
|
|
|
2013-01-08 21:05:02 +08:00
|
|
|
rt_hw_interrupt_enable (intVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rt_hw_interrupt_mask(int vector)
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
mtdcr(uic0er, mfdcr(uic0er) & ~UIC_MASK(vector));
|
2013-01-08 21:05:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void rt_hw_interrupt_unmask(int vector)
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
mtdcr(uic0er, mfdcr(uic0er) | UIC_MASK(vector));
|
2013-01-08 21:05:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void rt_hw_interrupt_init()
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
int vector;
|
2013-01-08 21:05:02 +08:00
|
|
|
rt_uint32_t pit_value;
|
|
|
|
|
|
|
|
pit_value = RT_TICK_PER_SECOND * (100000000 / RT_CPU_FREQ);
|
|
|
|
|
|
|
|
/* enable pit */
|
2021-03-27 17:51:56 +08:00
|
|
|
mtspr(SPRN_PIT, pit_value);
|
|
|
|
mtspr(SPRN_TCR, 0x4400000);
|
2013-01-08 21:05:02 +08:00
|
|
|
|
2021-03-27 17:51:56 +08:00
|
|
|
/* set default interrupt handler */
|
2013-01-08 21:05:02 +08:00
|
|
|
for (vector = 0; vector < MAX_HANDLERS; vector++)
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
isr_table [vector].handler = (rt_isr_handler_t)rt_hw_interrupt_handler;
|
2013-04-01 10:58:36 +08:00
|
|
|
isr_table [vector].param = RT_NULL;
|
2013-01-08 21:05:02 +08:00
|
|
|
}
|
|
|
|
|
2021-03-27 17:51:56 +08:00
|
|
|
/* initialize interrupt nest, and context in thread sp */
|
|
|
|
rt_interrupt_nest = 0;
|
|
|
|
rt_interrupt_from_thread = 0;
|
|
|
|
rt_interrupt_to_thread = 0;
|
|
|
|
rt_thread_switch_interrput_flag = 0;
|
2013-01-08 21:05:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*@}*/
|