interrupt.c 3.1 KB
Newer Older
B
Bernard Xiong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * 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
 */

15
#include <rthw.h>
B
Bernard Xiong 已提交
16 17 18 19 20 21 22 23
#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
24
struct rt_irq_desc isr_table[MAX_HANDLERS];
B
Bernard Xiong 已提交
25 26 27 28

rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
rt_uint32_t rt_thread_switch_interrput_flag;

29
rt_isr_handler_t rt_hw_interrupt_handler(rt_uint32_t vector, void* param)
B
Bernard Xiong 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
{
	rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
	return RT_NULL;
}

void uic_irq_ack(unsigned int vec)
{
	mtdcr(uic0sr, UIC_MASK(vec));
}

void  uic_int_handler (unsigned int vec)
{
	rt_interrupt_enter();

    /* Allow external interrupts to the CPU. */
45
    if (isr_table [vec].handler != 0)
B
Bernard Xiong 已提交
46
    {
47
       (*isr_table[vec].handler)(vec, isr_table[vec].param);
B
Bernard Xiong 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    }
    uic_irq_ack(vec);
	
    rt_interrupt_leave();
}

/* handler for UIC interrupt */
void uic_interrupt(rt_uint32_t uic_base, int vec_base)
{
	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++;
	}
}

81 82
rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, 
    void* param, char* name)
B
Bernard Xiong 已提交
83 84
{
    int	intVal;
85
    rt_isr_handler_t old_handler;
B
Bernard Xiong 已提交
86 87 88

    if (((int)vector < 0)  || ((int) vector >= MAX_HANDLERS)) 
	{
89
        return RT_NULL;   /*  out of range  */
B
Bernard Xiong 已提交
90 91 92 93 94
	}
   
    /* install the handler in the system interrupt table  */
    intVal = rt_hw_interrupt_disable (); /* lock interrupts to prevent races */

95 96 97 98
    old_handler = isr_table[vector].handler;
    isr_table[vector].handler = new_handler;
    isr_table[vector].param = param;
    
B
Bernard Xiong 已提交
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    rt_hw_interrupt_enable (intVal);
}

void rt_hw_interrupt_mask(int vector)
{
	mtdcr(uic0er, mfdcr(uic0er) & ~UIC_MASK(vector));
}

void rt_hw_interrupt_unmask(int vector)
{
	mtdcr(uic0er, mfdcr(uic0er) | UIC_MASK(vector));
}

void rt_hw_interrupt_init()
{
	int vector;
    rt_uint32_t pit_value;

    pit_value = RT_TICK_PER_SECOND * (100000000 / RT_CPU_FREQ);

    /* enable pit */
	mtspr(SPRN_PIT, pit_value);
	mtspr(SPRN_TCR, 0x4400000);

	/* set default interrupt handler */
    for (vector = 0; vector < MAX_HANDLERS; vector++)
    {
126 127
	    isr_table [vector].handler = (rt_isr_handler_t)rt_hw_interrupt_handler;
        isr_table [vector].param = RT_NULL;
B
Bernard Xiong 已提交
128 129 130 131 132 133 134 135 136 137
    }

	/* 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;
}

/*@}*/