interrupt.c 3.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * 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
 * 2006-03-13     Bernard      first version
13
 * 2013-03-29     aozima       Modify the interrupt interface implementations.
14 15 16
 */

#include <rtthread.h>
17
#include <rthw.h>
18 19 20 21 22 23 24
#include "s3c24x0.h"

#define MAX_HANDLERS	32

extern rt_uint32_t rt_interrupt_nest;

/* exception and interrupt handler table */
25
struct rt_irq_desc isr_table[MAX_HANDLERS];
26
rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
D
dzzxzz 已提交
27
rt_uint32_t rt_thread_switch_interrupt_flag;
28 29 30 31 32 33

/**
 * @addtogroup S3C24X0
 */
/*@{*/

34
static void rt_hw_interrupt_handle(int vector, void *param)
35 36 37 38 39 40 41
{
	rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
}

/**
 * This function will initialize hardware interrupt
 */
qiuyiuestc's avatar
qiuyiuestc 已提交
42
void rt_hw_interrupt_init(void)
43
{
44
    register rt_uint32_t idx;
45

46 47
    /* all clear source pending */
    SRCPND = 0x0;
48

49 50
    /* all clear sub source pending */
    SUBSRCPND = 0x0;
51

52 53
    /* all=IRQ mode */
    INTMOD = 0x0;
54

55 56
    /* all interrupt disabled include global bit */
    INTMSK = BIT_ALLMSK;
57

58 59
    /* all sub interrupt disable */
    INTSUBMSK = BIT_SUB_ALLMSK;
60

61 62
    /* all clear interrupt pending */
    INTPND = BIT_ALLMSK;
63

64 65 66 67 68 69
    /* init exceptions table */
    rt_memset(isr_table, 0x00, sizeof(isr_table));
    for(idx=0; idx < MAX_HANDLERS; idx++)
    {
        isr_table[idx].handler = rt_hw_interrupt_handle;
    }
70

71 72 73 74 75
    /* 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;
76 77 78 79 80 81
}

/**
 * This function will mask a interrupt.
 * @param vector the interrupt number
 */
qiuyiuestc's avatar
qiuyiuestc 已提交
82
void rt_hw_interrupt_mask(int vector)
83 84 85 86 87 88 89 90
{
	INTMSK |= 1 << vector;
}

/**
 * This function will un-mask a interrupt.
 * @param vector the interrupt number
 */
qiuyiuestc's avatar
qiuyiuestc 已提交
91
void rt_hw_interrupt_umask(int vector)
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
{
	if (vector == INTNOTUSED6)
	{
		rt_kprintf("Interrupt vec %d is not used!\n", vector);
		// while(1);
	}
	else if (vector == INTGLOBAL)
		INTMSK = 0x0;
	else
		INTMSK &= ~(1 << vector);
}

/**
 * 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
 */
110 111
rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
                                        void *param, char *name)
112
{
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
    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;
130 131 132
}

/*@}*/