[PATCH 8/8] Added an interrupt handler to generic_or1k BSP

jakob.viketoft at gmail.com jakob.viketoft at gmail.com
Sat Feb 20 23:02:13 UTC 2016


From: Jakob Viketoft <jakob.viketoft at aacmicrotec.com>

Update #2603
---
 c/src/lib/libbsp/or1k/generic_or1k/irq/irq.c | 61 ++++++++++++++++++++++++----
 1 file changed, 54 insertions(+), 7 deletions(-)

diff --git a/c/src/lib/libbsp/or1k/generic_or1k/irq/irq.c b/c/src/lib/libbsp/or1k/generic_or1k/irq/irq.c
index c3c4d6d..ef69f54 100644
--- a/c/src/lib/libbsp/or1k/generic_or1k/irq/irq.c
+++ b/c/src/lib/libbsp/or1k/generic_or1k/irq/irq.c
@@ -8,6 +8,8 @@
 
 /*
  * Copyright (c) 2014 Hesham ALMatary
+ * Copyright (c) 2015 ÅAC Microtec AB <www.aacmicrotec.com>
+ *                    Jakob Viketoft <jakob.viketoft at aacmicrotec.com>
  *
  * The license and distribution terms for this file may be
  * found in the file LICENSE in this distribution or at
@@ -16,27 +18,72 @@
 
 #include <bsp/irq.h>
 #include <bsp/irq-generic.h>
+#include <assert.h>
 
-/* Almost all of the jobs that the following functions should
- * do are implemented in cpukit
- */
+static int or1k_external_interrupt_handler(rtems_vector_number vector)
+{
+  uint32_t picsr;
+  uint32_t int_num;
+
+  /* Get picsr */
+  picsr = _OR1K_mfspr(CPU_OR1K_SPR_PICSR);
+
+  /* Make sure we have a pending interrupt */
+  assert(picsr != 0);
+
+  /* Go through all set interrupts in a round-robin style */
+  while (picsr) {
+    /* Find pending interrupt with lowest number */
+    int_num = _OR1K_Find_first_one(picsr);
+
+    /* Adjust vector number with a start from 0 */
+    int_num--;
+
+    /* Call the interrupt handler */
+    bsp_interrupt_handler_dispatch((rtems_vector_number) int_num);
+
+    /* Clear the interrupt */
+    picsr &= ~(1 << int_num);
+    _OR1K_mtspr(CPU_OR1K_SPR_PICSR, picsr);
+  }
+
+  return 0;
+}
 
 void bsp_interrupt_handler_default(rtems_vector_number vector)
 {
-    printk("spurious interrupt: %u\n", vector);
+  printk("Unhandled interrupt, number: %u\n", vector);
 }
 
 rtems_status_code bsp_interrupt_facility_initialize()
 {
-  return 0;
+  /* Install exception handler for external interrupt exception */
+  _CPU_ISR_install_vector(OR1K_EXCEPTION_IRQ, or1k_external_interrupt_handler, NULL);
+
+  /* Clear all pending interrupts */
+  _OR1K_mtspr(CPU_OR1K_SPR_PICSR, 0);
+
+  return RTEMS_SUCCESSFUL;
 }
 
 rtems_status_code bsp_interrupt_vector_enable(rtems_vector_number vector)
 {
-  return 0;
+  uint32_t picmr;
+
+  picmr = _OR1K_mfspr(CPU_OR1K_SPR_PICMR);
+  picmr |= (1 << vector);
+  _OR1K_mtspr(CPU_OR1K_SPR_PICMR, picmr);
+
+  return RTEMS_SUCCESSFUL;
 }
 
 rtems_status_code bsp_interrupt_vector_disable(rtems_vector_number vector)
 {
-  return 0;
+  uint32_t picmr;
+
+  picmr = _OR1K_mfspr(CPU_OR1K_SPR_PICMR);
+  picmr &= ~(1 << vector);
+  _OR1K_mtspr(CPU_OR1K_SPR_PICMR, picmr);
+
+  return RTEMS_SUCCESSFUL;
 }
-- 
2.1.4



More information about the devel mailing list