summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libcpu/powerpc/mpc5xx/ictrl
diff options
context:
space:
mode:
Diffstat (limited to 'c/src/lib/libcpu/powerpc/mpc5xx/ictrl')
-rw-r--r--c/src/lib/libcpu/powerpc/mpc5xx/ictrl/ictrl.c68
-rw-r--r--c/src/lib/libcpu/powerpc/mpc5xx/ictrl/ictrl.h75
2 files changed, 143 insertions, 0 deletions
diff --git a/c/src/lib/libcpu/powerpc/mpc5xx/ictrl/ictrl.c b/c/src/lib/libcpu/powerpc/mpc5xx/ictrl/ictrl.c
new file mode 100644
index 0000000000..9590e5ba1a
--- /dev/null
+++ b/c/src/lib/libcpu/powerpc/mpc5xx/ictrl/ictrl.c
@@ -0,0 +1,68 @@
+/*
+ * mpc505/509 external interrupt controller management.
+ */
+
+#include "ictrl.h"
+
+#include <rtems.h>
+#include <rtems/score/ppc.h>
+
+/*
+ * Internal routines.
+ */
+
+static unsigned long volatile *const IRQAND =
+ (unsigned long volatile *const)0x8007EFA4;
+
+static void nullHandler()
+{
+}
+
+/* Interrupt dispatch table. */
+static ExtIsrHandler extIrqHandlers[NUM_IRQS] =
+{
+ nullHandler,
+ nullHandler,
+ nullHandler,
+ nullHandler,
+ nullHandler,
+ nullHandler,
+ nullHandler
+};
+
+
+/* RTEMS external interrupt handler. Calls installed external interrupt
+ handlers for every pending external interrupt in turn. */
+static rtems_isr extIsr_( rtems_vector_number i )
+{
+#define BIT_NUMBER(val, bit) \
+ asm volatile ( "cntlzw %0, %1; srawi %0, %0, 1": "=r" (bit) : "r" (val) );
+
+ int bit;
+ (void)i;
+
+ BIT_NUMBER(*IRQAND & IMASK_ALL, bit);
+ while ( bit < NUM_IRQS ) {
+ extIrqHandlers[bit]();
+ BIT_NUMBER(*IRQAND & IMASK_ALL, bit);
+ }
+}
+
+/*
+ * Public routines
+ */
+
+void extIrqSetHandler(ExtInt interrupt,ExtIsrHandler handler)
+{
+ extIrqHandlers[interrupt] = handler;
+}
+
+void extIsrInit( void )
+{
+ int i = 0;
+
+ extIrqDisable(IMASK_ALL);
+ for( i = 0; i < NUM_IRQS; i++)
+ extIrqHandlers[i] = nullHandler;
+ set_vector(extIsr_,PPC_IRQ_EXTERNAL,1);
+}
diff --git a/c/src/lib/libcpu/powerpc/mpc5xx/ictrl/ictrl.h b/c/src/lib/libcpu/powerpc/mpc5xx/ictrl/ictrl.h
new file mode 100644
index 0000000000..303ece825d
--- /dev/null
+++ b/c/src/lib/libcpu/powerpc/mpc5xx/ictrl/ictrl.h
@@ -0,0 +1,75 @@
+#ifndef _ICTRL_H
+#define _ICTRL_H
+
+/*
+ * mpc505/509 external interrupt controller management.
+ *
+ * FIXME: should be somehow merged into general RTEMS interrupt
+ * management code.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define _SIU_IRQENABLE ((unsigned long volatile *const)0x8007EFA8)
+#define _SIU_IRQPEND ((unsigned long volatile *const)0x8007EFA0)
+
+/* Interrupt masks. */
+enum {
+ IMASK_EXT0 = 0x80000000,
+ IMASK_EXT1 = 0x20000000,
+ IMASK_EXT2 = 0x08000000,
+ IMASK_EXT3 = 0x02000000,
+ IMASK_EXT4 = 0x00800000,
+ IMASK_EXT5 = 0x00200000,
+ IMASK_EXT6 = 0x00080000,
+ IMASK_ALL = IMASK_EXT0 | IMASK_EXT1 | IMASK_EXT2 | IMASK_EXT3 |
+ IMASK_EXT4 | IMASK_EXT5 | IMASK_EXT6
+};
+
+/* Interrupt numbers. */
+typedef enum {
+ IRQ_EXT0,
+ IRQ_EXT1,
+ IRQ_EXT2,
+ IRQ_EXT3,
+ IRQ_EXT4,
+ IRQ_EXT5,
+ IRQ_EXT6,
+ NUM_IRQS
+} ExtInt;
+
+/* Type of external interrupt handlers */
+typedef void (*ExtIsrHandler) (void);
+
+/* Initialization. Must be called once after RTEMS interrupts sybsystem
+ is initiailized. 'predriver_hook' is one of such places. */
+extern void extIsrInit( void );
+
+/* Set interrupt handler 'handler' for external interrupt number
+ 'interrupt'. */
+extern void extIrqSetHandler(ExtInt interrupt, ExtIsrHandler handler);
+
+/* Check is external interrupt 'irq' (IMASK_XXXX) is pended. */
+#define extIrqIsSet(irq) \
+ (*_SIU_IRQPEND & (irq))
+
+/* Enable external interrupt 'irq' (IMASK_XXXX) processing. */
+#define extIrqEnable(irq) \
+ (*_SIU_IRQENABLE |= (irq))
+
+/* Disable external interrupt 'irq' (IMASK_XXXX) processing. */
+#define extIrqDisable(irq) \
+ (*_SIU_IRQENABLE &= ~(irq))
+
+/* Check if external interrupt 'irq' (IMASK_XXXX) processing is
+ enabled. */
+#define extIrqGetEnable \
+ (*_SIU_IRQENABLE)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ICTRL_H */