interrupt.c 1.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 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
/*
 * File      : trap.c
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2006, 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://openlab.rt-thread.com/license/LICENSE
 *
 * Change Logs:
 * Date           Author       Notes
 * 2008-12-11     XuXinming    first version
 */

#include <rtthread.h>
#include "LPC24xx.h"

#define MAX_HANDLERS	32

extern rt_uint32_t rt_interrupt_nest;

/* exception and interrupt handler table */
rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
rt_uint32_t rt_thread_switch_interrput_flag;


/**
 * @addtogroup LPC2478
 */
/*@{*/

void rt_hw_interrupt_handle(int vector)
{
	rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
}

void rt_hw_interrupt_init()
{
	register int i;

	rt_uint32_t *vect_addr, *vect_cntl;
    
	/* initialize VIC*/
	VICIntEnClr = 0xffffffff;
	VICVectAddr = 0;
	VICIntSelect = 0;

    for ( i = 0; i < 32; i++ )
    {
		vect_addr = (rt_uint32_t *)(VIC_BASE_ADDR + 0x100 + i*4);
		vect_cntl = (rt_uint32_t *)(VIC_BASE_ADDR + 0x200 + i*4);
		*vect_addr = 0x0;	
		*vect_cntl = 0xF;
    }
	
	/* 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_interrput_flag = 0;
}

void rt_hw_interrupt_mask(int vector)
{
	VICIntEnClr = (1 << vector);
}

void rt_hw_interrupt_umask(int vector)
{
	VICIntEnable = (1 << vector);
}

void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler)
{
	rt_uint32_t *vect_addr;
	
	if(vector < MAX_HANDLERS)
	{
		/* find first un-assigned VIC address for the handler */
80 81
		vect_addr = (rt_uint32_t *)(VIC_BASE_ADDR + 0x100 + vector*4);

B
bernard.xiong 已提交
82 83
		/* get old handler */
		if (old_handler != RT_NULL) *old_handler = (rt_isr_handler_t)*vect_addr; 
84

85 86 87 88 89
		*vect_addr = (rt_uint32_t)new_handler;	/* set interrupt vector */
	}
}

/*@}*/