interrupt.c 6.2 KB
Newer Older
1 2 3
/*
 *  This file is part of FH8620 BSP for RT-Thread distribution.
 *
mysterywolf's avatar
mysterywolf 已提交
4 5
 *  Copyright (c) 2016 Shanghai Fullhan Microelectronics Co., Ltd.
 *  All rights reserved
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
mysterywolf's avatar
mysterywolf 已提交
21
 *  Visit http://www.fullhan.com to get contact with Fullhan.
22 23 24 25 26 27 28 29 30 31 32 33 34
 *
 * Change Logs:
 * Date           Author       Notes
 */

/*****************************************************************************
 *  Include Section
 *  add all #include here
 *****************************************************************************/

#include "interrupt.h"
#include "fh_def.h"
#include "fh_arch.h"
35
#include "libraries/inc/fh_ictl.h"
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

/*****************************************************************************
 * Define section
 * add all #define here
 *****************************************************************************/
#define MAX_HANDLERS    (NR_INTERNAL_IRQS+NR_EXTERNAL_IRQS)


/****************************************************************************
 * ADT section
 *  add definition of user defined Data Type that only be used in this file  here
 ***************************************************************************/

/******************************************************************************
 * Function prototype section
 * add prototypes for all functions called by this file,execepting those
 * declared in header file
 *****************************************************************************/



/*****************************************************************************
 * Global variables section - Exported
 * add declaration of global variables that will be exported here
 * e.g.
 *  int8_t foo;
 ****************************************************************************/
extern rt_uint32_t rt_interrupt_nest;
struct rt_irq_desc irq_desc[MAX_HANDLERS];
rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
rt_uint32_t rt_thread_switch_interrupt_flag;
/*****************************************************************************
 * Global variables section - Local
 * define global variables(will be refered only in this file) here,
 * static keyword should be used to limit scope of local variable to this file
 * e.g.
 *  static uint8_t ufoo;
 *****************************************************************************/



 /* function body */






/*****************************************************************************
 * Description:
 *      add funtion description here
 * Parameters:
 *      description for each argument, new argument starts at new line
 * Return:
 *      what does this function returned?
 *****************************************************************************/
rt_isr_handler_t rt_hw_interrupt_handle(rt_uint32_t vector, void *param)
{
    rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
    return RT_NULL;
}




/**
 * This function will initialize hardware interrupt
 */
void rt_hw_interrupt_init(void)
{
    rt_int32_t i;
    register rt_uint32_t idx;
mysterywolf's avatar
mysterywolf 已提交
108
    fh_intc *p = (fh_intc *)INTC_REG_BASE;
109 110


mysterywolf's avatar
mysterywolf 已提交
111
    ictl_close_all_isr(p);
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
    /* init exceptions table */
    for(idx=0; idx < MAX_HANDLERS; idx++)
    {

        irq_desc[idx].handler = (rt_isr_handler_t)rt_hw_interrupt_handle;
        irq_desc[idx].param = RT_NULL;
#ifdef RT_USING_INTERRUPT_INFO
        rt_snprintf(irq_desc[idx].name, RT_NAME_MAX - 1, "default");
        irq_desc[idx].counter = 0;
#endif

    }

    /* 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 irq)
{

mysterywolf's avatar
mysterywolf 已提交
140
    fh_intc *p = (fh_intc *)INTC_REG_BASE;
141
    /* Disable irq on AIC */
mysterywolf's avatar
mysterywolf 已提交
142
    ictl_mask_isr(p,irq);
143

mysterywolf's avatar
mysterywolf 已提交
144 145 146 147
//  if (irq < 32)
//      p->IRQ_EN_L &= ~(1 << irq);
//  else
//      p->IRQ_EN_H &= ~(1 << (irq - 32));
148 149 150 151 152 153
}


void rt_hw_interrupt_umask(int irq)
{

mysterywolf's avatar
mysterywolf 已提交
154
    fh_intc *p = (fh_intc *)INTC_REG_BASE;
155
    /* Enable irq on AIC */
mysterywolf's avatar
mysterywolf 已提交
156
    ictl_unmask_isr(p,irq);
157
//    if (irq < 32)
mysterywolf's avatar
mysterywolf 已提交
158 159 160
//      p->IRQ_EN_L |= 1 << irq;
//  else
//      p->IRQ_EN_H |= 1 << (irq - 32);
161 162 163 164 165 166 167 168 169 170
}

/**
 * This function will install a interrupt service routine to a interrupt.
 * @param vector the interrupt number
 * @param handler the interrupt service routine to be installed
 * @param param the interrupt service function parameter
 * @param name the interrupt name
 * @return old handler
 */
mysterywolf's avatar
mysterywolf 已提交
171
rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
172
                                    void *param, const char *name)
173 174 175 176 177 178 179 180 181 182 183 184
{
    rt_isr_handler_t old_handler = RT_NULL;

    if(vector < MAX_HANDLERS)
    {
        old_handler = irq_desc[vector].handler;
        if (handler != RT_NULL)
        {
            irq_desc[vector].handler = (rt_isr_handler_t)handler;
            irq_desc[vector].param = param;
#ifdef RT_USING_INTERRUPT_INFO
            rt_snprintf(irq_desc[vector].name, RT_NAME_MAX - 1, "%s", name);
mysterywolf's avatar
mysterywolf 已提交
185
            irq_desc[vector].counter = 0;
186 187 188 189 190 191 192 193 194 195 196 197
#endif
        }
    }

    return old_handler;
}

#ifdef RT_USING_FINSH
void list_irq(void)
{

#ifdef RT_USING_INTERRUPT_INFO
mysterywolf's avatar
mysterywolf 已提交
198
    int irq;
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
    rt_kprintf("number\tcount\tname\n");
    for (irq = 0; irq < MAX_HANDLERS; irq++)
    {
        if (rt_strncmp(irq_desc[irq].name, "default", sizeof("default")))
        {
            rt_kprintf("%02ld: %10ld  %s\n", irq, irq_desc[irq].counter, irq_desc[irq].name);
        }
    }
#else
    rt_kprintf("please open 'RT_USING_INTERRUPT_INFO'\n");

#endif
}
#include <finsh.h>
FINSH_FUNCTION_EXPORT(list_irq, list system irq);

#endif