summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/arm/vegaplus/irq
diff options
context:
space:
mode:
Diffstat (limited to 'c/src/lib/libbsp/arm/vegaplus/irq')
-rw-r--r--c/src/lib/libbsp/arm/vegaplus/irq/.cvsignore2
-rw-r--r--c/src/lib/libbsp/arm/vegaplus/irq/Makefile.am44
-rw-r--r--c/src/lib/libbsp/arm/vegaplus/irq/bsp_irq_asm.S67
-rw-r--r--c/src/lib/libbsp/arm/vegaplus/irq/bsp_irq_init.c39
-rw-r--r--c/src/lib/libbsp/arm/vegaplus/irq/irq.c137
-rw-r--r--c/src/lib/libbsp/arm/vegaplus/irq/irq.h193
6 files changed, 482 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/arm/vegaplus/irq/.cvsignore b/c/src/lib/libbsp/arm/vegaplus/irq/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/c/src/lib/libbsp/arm/vegaplus/irq/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/c/src/lib/libbsp/arm/vegaplus/irq/Makefile.am b/c/src/lib/libbsp/arm/vegaplus/irq/Makefile.am
new file mode 100644
index 0000000000..ec9fccfbf4
--- /dev/null
+++ b/c/src/lib/libbsp/arm/vegaplus/irq/Makefile.am
@@ -0,0 +1,44 @@
+##
+## $Id$
+##
+
+AUTOMAKE_OPTIONS = foreign 1.4
+
+VPATH = @srcdir@:@srcdir@/../../shared/irq
+
+PGM = $(ARCH)/irq.rel
+
+C_FILES = irq.c irq_init.c bsp_irq_init.c
+S_FILES = irq_asm.S bsp_irq_asm.S
+H_FILES = irq.h
+
+C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.o)
+S_O_FILES = $(S_FILES:%.S=$(ARCH)/%.o)
+
+irq_rel_OBJECTS = $(C_O_FILES) $(S_O_FILES)
+
+$(PROJECT_INCLUDE):
+ $(mkinstalldirs) $@
+
+$(PROJECT_INCLUDE)/%.h: %.h
+ $(INSTALL_DATA) $< $@
+
+PREINSTALL_FILES += $(PROJECT_INCLUDE) $(H_FILES:%.h=$(PROJECT_INCLUDE)/%.h)
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
+include $(top_srcdir)/../../../../../../automake/lib.am
+
+#
+# (OPTIONAL) Add local stuff here using +=
+#
+
+$(PGM): $(startup_rel_OBJECTS)
+ $(make-rel)
+
+all: $(PREINSTALL_FILES) $(ARCH) $(irq_rel_OBJECTS) $(PGM)
+
+.PRECIOUS: $(PGM)
+
+EXTRA_DIST = irq.c bsp_irq_init.c bsp_irq_asm.S
+
+include $(top_srcdir)/../../../../../../automake/local.am
diff --git a/c/src/lib/libbsp/arm/vegaplus/irq/bsp_irq_asm.S b/c/src/lib/libbsp/arm/vegaplus/irq/bsp_irq_asm.S
new file mode 100644
index 0000000000..7436c3d8fe
--- /dev/null
+++ b/c/src/lib/libbsp/arm/vegaplus/irq/bsp_irq_asm.S
@@ -0,0 +1,67 @@
+/* bsp_irq_asm.S
+ *
+ * This file contains the implementation of the IRQ handler
+ * for a specific BSP
+ *
+ * CopyRight (C) 2000 Canon Research France SA.
+ * Emmanuel Raguet, mailto:raguet@crf.canon.fr
+ *
+ * The license and distribution terms for this file may be
+ * found in found in the file LICENSE in this distribution or at
+ * http://www.OARcorp.com/rtems/license.html.
+ *
+ */
+
+#define __asm__
+#include <registers.h>
+
+/*
+ * Function to obtain, execute an IT handler and acknowledge the IT
+ */
+
+ .globl ExecuteITHandler
+
+ExecuteITHandler :
+ ldr r0, =INTPHAI3 /* read the vector number */
+ ldr r0, [r0]
+ ldr r0, [r0] /* extract the IT handler @ */
+
+ /*
+ * re-enable interrupts at processor level as the current
+ * interrupt source is now masked via VEGA logic
+ */
+ mrs r1, cpsr
+ and r1, r1, #0xFFFFFF3F
+ msr cpsr, r1
+
+ stmdb sp!,{lr}
+ ldr lr, =IRQ_return /* prepare the return from handler */
+ mov pc, r0 /* EXECUTE INT HANDLER */
+
+IRQ_return:
+ ldmia sp!,{lr}
+ ldr r2, =INTSTAT3 /* Ack the interrupt */
+ ldr r2, [r2]
+ ldr r1, =INTACK3
+ str r2, [r1]
+ /*
+ * disable interrupts_again and switch back to SVC mode
+ */
+ mrs r0, cpsr
+ orr r0, r0, #0xc3
+ msr cpsr, r0
+
+ b ReturnFromHandler /* return to ISR handler */
+
+/*
+ * Function to acknowledge the IT controller
+ */
+ .globl AckControler
+
+AckControler:
+ ldr r0, =INTEOI3
+ mov r1, #EOI
+ str r1, [r0]
+
+ b ReturnFromAck /* return to ISR handler */
+
diff --git a/c/src/lib/libbsp/arm/vegaplus/irq/bsp_irq_init.c b/c/src/lib/libbsp/arm/vegaplus/irq/bsp_irq_init.c
new file mode 100644
index 0000000000..08da02f9f5
--- /dev/null
+++ b/c/src/lib/libbsp/arm/vegaplus/irq/bsp_irq_init.c
@@ -0,0 +1,39 @@
+/* irq_init.c
+ *
+ * This file contains the implementation of rtems initialization
+ * related to interrupt handling.
+ *
+ * CopyRight (C) 2000 Canon Research Centre France SA.
+ * Emmanuel Raguet, mailto:raguet@crf.canon.fr
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.OARcorp.com/rtems/license.html.
+ *
+ * $Id$
+ */
+#include <irq.h>
+#include <bsp.h>
+#include <registers.h>
+
+
+void BSP_rtems_irq_mngt_init() {
+
+ /* Initialize the vector table address in internal RAM */
+ Regs[INTTAB] = VECTOR_TABLE;
+
+ /* Initialize the GLOBAL INT CONTROL register */
+ Regs[INTGCNTL] = 0x00;
+
+ /* Mask all the interrupts */
+ Regs[INTMASK] = 0xFFFF;
+
+ /* Unmask the 2 arm interrupts IRQ and FIQ on the INT controller */
+ Regs[INTMASKALL] = 0x0;
+
+ /* Ack pending interrupt */
+ while ( ( Regs[INTSTAT] & 0xF433 ) != 0 ) {
+ Regs[INTACK] = 0xFFFF;
+ Regs[INTEOI] = EOI;
+ }
+}
diff --git a/c/src/lib/libbsp/arm/vegaplus/irq/irq.c b/c/src/lib/libbsp/arm/vegaplus/irq/irq.c
new file mode 100644
index 0000000000..0f90bb1d47
--- /dev/null
+++ b/c/src/lib/libbsp/arm/vegaplus/irq/irq.c
@@ -0,0 +1,137 @@
+/* irq.c
+ *
+ * This file contains the implementation of the function described in irq.h
+ *
+ * CopyRight (C) 2000 Canon Research France SA.
+ * Emmanuel Raguet, mailto:raguet@crf.canon.fr
+ *
+ * The license and distribution terms for this file may be
+ * found in found in the file LICENSE in this distribution or at
+ * http://www.OARcorp.com/rtems/license.html.
+ *
+ * $Id$
+ */
+
+
+#include <bsp.h>
+#include <irq.h>
+#include <registers.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/apiext.h>
+
+
+/*
+ * This function check that the value given for the irq line
+ * is valid.
+ */
+
+static int isValidInterrupt(int irq)
+{
+ if ( (irq < 0) || (irq > BSP_MAX_INT))
+ return 0;
+ return 1;
+}
+
+/*
+ * ------------------------ RTEMS Single Irq Handler Mngt Routines ----------------
+ */
+
+int BSP_install_rtems_irq_handler (const rtems_irq_connect_data* irq)
+{
+ rtems_irq_hdl *HdlTable;
+
+ if (!isValidInterrupt(irq->name)) {
+ return 0;
+ }
+ /*
+ * Check if default handler is actually connected. If not issue an error.
+ */
+ HdlTable = VECTOR_TABLE;
+ if (*(HdlTable + irq->name) != default_int_handler) {
+ return 0;
+ }
+
+ _CPU_ISR_Disable(level);
+
+ /*
+ * store the new handler
+ */
+ *(HdlTable + irq->name) = irq->hdl;
+
+ /*
+ * initialize the control register for the concerned interrupt
+ */
+ Regs[(INTCNTL0 + irq->name)] = (long)(irq->irqTrigger) | (long)(irq->irqLevel) ;
+
+ /*
+ * ack pending interrupt
+ */
+ Regs[INTACK] |= (long)(1 << irq->name);
+
+ /*
+ * unmask at INT controler level level
+ */
+ Regs[INTMASK] &= ~(long)(1 << irq->name);
+
+ /*
+ * Enable interrupt on device
+ */
+ irq->on(irq);
+
+ _CPU_ISR_Enable(level);
+
+ return 1;
+}
+
+int BSP_remove_rtems_irq_handler (const rtems_irq_connect_data* irq)
+{
+ rtems_irq_hdl *HdlTable;
+
+ if (!isValidInterrupt(irq->name)) {
+ return 0;
+ }
+ /*
+ * Check if the handler is actually connected. If not issue an error.
+ */
+ HdlTable = VECTOR_TABLE;
+ if (*(HdlTable + irq->name) != irq->hdl) {
+ return 0;
+ }
+ _CPU_ISR_Disable(level);
+
+ /*
+ * mask at INT controller level
+ */
+ Regs[INTMASK] |= (long)(1 << irq->name);
+
+ /*
+ * Disable interrupt on device
+ */
+ irq->off(irq);
+
+ /*
+ * restore the default irq value
+ */
+ *(HdlTable + irq->name) = default_int_handler;
+
+ _CPU_ISR_Enable(level);
+
+ return 1;
+}
+
+
+
+void _ThreadProcessSignalsFromIrq (CPU_Exception_frame* ctx)
+{
+ /*
+ * Process pending signals that have not already been
+ * processed by _Thread_Displatch. This happens quite
+ * unfrequently : the ISR must have posted an action
+ * to the current running thread.
+ */
+ if ( _Thread_Do_post_task_switch_extension ||
+ _Thread_Executing->do_post_task_switch_extension ) {
+ _Thread_Executing->do_post_task_switch_extension = FALSE;
+ _API_extensions_Run_postswitch();
+ }
+}
diff --git a/c/src/lib/libbsp/arm/vegaplus/irq/irq.h b/c/src/lib/libbsp/arm/vegaplus/irq/irq.h
new file mode 100644
index 0000000000..730f45cd71
--- /dev/null
+++ b/c/src/lib/libbsp/arm/vegaplus/irq/irq.h
@@ -0,0 +1,193 @@
+/* irq.h
+ *
+ * This include file describe the data structure and the functions implemented
+ * by rtems to write interrupt handlers.
+ *
+ * Copyright (c) 2000 Canon Research Centre France SA.
+ * Emmanuel Raguet, mailto:raguet@crf.canon.fr
+ *
+ * The license and distribution terms for this file may be
+ * found in found in the file LICENSE in this distribution or at
+ * http://www.OARcorp.com/rtems/license.html.
+ *
+ */
+
+#ifndef _IRQ_H_
+#define _IRQ_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Include some preprocessor value also used by assember code
+ */
+
+#include <rtems.h>
+
+extern void default_int_handler();
+/*-------------------------------------------------------------------------+
+| Constants
++--------------------------------------------------------------------------*/
+
+typedef enum {
+ BSP_DECT_CORE = 0,
+ BSP_PCM = 1,
+ BSP_UART = 2,
+ BSP_RESERVED1 = 3,
+ BSP_TIMER_0 = 4,
+ BSP_TIMER_1 = 5,
+ BSP_RESERVED2 = 6,
+ BSP_RESERVED3 = 7,
+ BSP_LCD = 8,
+ BSP_KPAD = 9,
+ BSP_TAD = 10,
+ BSP_ADC = 11,
+ BSP_EXT_0 = 12,
+ BSP_EXT_1 = 13,
+ BSP_EXT_2 = 14,
+ BSP_EXT_3 = 15,
+ BSP_MAX_INT = 16
+} rtems_irq_symbolic_name;
+
+#define LEVEL_EDGE_MASK 0xC0
+#define LEVEL_LOW 0x00
+#define LEVEL_HIGH 0x40
+#define EDGE_FALLING 0x80
+#define EDGE_RISING 0xC0
+
+#define PRIO_MASK 0x07
+
+#define LEVEL_MASK 0x07
+
+#define MASKIRQ 0x80
+#define MASKFIQ 0x40
+
+#define END_OF_INT 0x80
+
+#define VECTOR_TABLE 0x40
+
+/*
+ * Type definition for RTEMS managed interrupts
+ */
+typedef unsigned char rtems_irq_level;
+typedef unsigned char rtems_irq_trigger;
+
+struct __rtems_irq_connect_data__; /* forward declaratiuon */
+
+typedef void (*rtems_irq_hdl) (void);
+typedef void (*rtems_irq_enable) (const struct __rtems_irq_connect_data__*);
+typedef void (*rtems_irq_disable) (const struct __rtems_irq_connect_data__*);
+typedef int (*rtems_irq_is_enabled) (const struct __rtems_irq_connect_data__*);
+
+typedef struct __rtems_irq_connect_data__ {
+ /*
+ * IRQ line
+ */
+ rtems_irq_symbolic_name name;
+ /*
+ * handler. See comment on handler properties below in function prototype.
+ */
+ rtems_irq_hdl hdl;
+ /*
+ * function for enabling interrupts at device level (ONLY!).
+ * The BSP code will automatically enable it at i8259s level.
+ * RATIONALE : anyway such code has to exist in current driver code.
+ * It is usually called immediately AFTER connecting the interrupt handler.
+ * RTEMS may well need such a function when restoring normal interrupt
+ * processing after a debug session.
+ *
+ */
+ rtems_irq_enable on;
+ /*
+ * function for disabling interrupts at device level (ONLY!).
+ * The code will disable it at i8259s level. RATIONALE : anyway
+ * such code has to exist for clean shutdown. It is usually called
+ * BEFORE disconnecting the interrupt. RTEMS may well need such
+ * a function when disabling normal interrupt processing for
+ * a debug session. May well be a NOP function.
+ */
+ rtems_irq_disable off;
+ /*
+ * function enabling to know what interrupt may currently occur
+ * if someone manipulates the i8259s interrupt mask without care...
+ */
+ rtems_irq_is_enabled isOn;
+ /*
+ * priority level at the vplus level
+ */
+ rtems_irq_level irqLevel;
+ /*
+ * Trigger way : Rising or falling edge or High or low level
+ */
+ rtems_irq_trigger irqTrigger;
+} rtems_irq_connect_data;
+
+/*-------------------------------------------------------------------------+
+| Function Prototypes.
++--------------------------------------------------------------------------*/
+/*
+ * ------------------------ RTEMS Single Irq Handler Mngt Routines ----------------
+ */
+
+/*
+ * function to initialize the interrupt for a specific BSP
+ */
+void BSP_rtems_irq_mngt_init();
+
+
+/*
+ * function to connect a particular irq handler. This hanlder will NOT be called
+ * directly as the result of the corresponding interrupt. Instead, a RTEMS
+ * irq prologue will be called that will :
+ *
+ * 1) save the C scratch registers,
+ * 2) switch to a interrupt stack if the interrupt is not nested,
+ * 3) store the current i8259s' interrupt masks
+ * 4) modify them to disable the current interrupt at 8259 level (and may
+ * be others depending on software priorities)
+ * 5) aknowledge the i8259s',
+ * 6) demask the processor,
+ * 7) call the application handler
+ *
+ * As a result the hdl function provided
+ *
+ * a) can perfectly be written is C,
+ * b) may also well directly call the part of the RTEMS API that can be used
+ * from interrupt level,
+ * c) It only responsible for handling the jobs that need to be done at
+ * the device level including (aknowledging/re-enabling the interrupt at device,
+ * level, getting the data,...)
+ *
+ * When returning from the function, the following will be performed by
+ * the RTEMS irq epilogue :
+ *
+ * 1) masks the interrupts again,
+ * 2) restore the original i8259s' interrupt masks
+ * 3) switch back on the orinal stack if needed,
+ * 4) perform rescheduling when necessary,
+ * 5) restore the C scratch registers...
+ * 6) restore initial execution flow
+ *
+ */
+
+int BSP_install_rtems_irq_handler (const rtems_irq_connect_data*);
+/*
+ * function to get the current RTEMS irq handler for ptr->name. It enables to
+ * define hanlder chain...
+ */
+int BSP_get_current_rtems_irq_handler (rtems_irq_connect_data* ptr);
+/*
+ * function to get disconnect the RTEMS irq handler for ptr->name.
+ * This function checks that the value given is the current one for safety reason.
+ * The user can use the previous function to get it.
+ */
+int BSP_remove_rtems_irq_handler (const rtems_irq_connect_data*);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _IRQ_H_ */
+/* end of include file */