[PATCH 03/41] bsps/irq: Move handler iterate to separate file

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Jul 12 12:49:25 UTC 2021


Update #3269.
---
 bsps/include/bsp/irq-generic.h               | 57 ++++++++++++
 bsps/shared/irq-default-sources.am           |  1 +
 bsps/shared/irq-sources.am                   |  1 +
 bsps/shared/irq/irq-generic.c                | 86 +-----------------
 bsps/shared/irq/irq-handler-iterate.c        | 96 ++++++++++++++++++++
 c/src/lib/libbsp/m68k/genmcf548x/Makefile.am |  1 +
 c/src/lib/libbsp/powerpc/ss555/Makefile.am   |  1 +
 spec/build/bsps/m68k/genmcf548x/obj.yml      |  1 +
 spec/build/bsps/objirq.yml                   |  1 +
 spec/build/bsps/powerpc/ss555/bspss555.yml   |  1 +
 10 files changed, 164 insertions(+), 82 deletions(-)
 create mode 100644 bsps/shared/irq/irq-handler-iterate.c

diff --git a/bsps/include/bsp/irq-generic.h b/bsps/include/bsp/irq-generic.h
index 8f7683c517..72c1d51332 100644
--- a/bsps/include/bsp/irq-generic.h
+++ b/bsps/include/bsp/irq-generic.h
@@ -322,6 +322,63 @@ void bsp_interrupt_lock(void);
 /* For internal use only */
 void bsp_interrupt_unlock(void);
 
+/**
+ * @brief This table contains a bit map which indicates if an entry is unique
+ *   or shared.
+ *
+ * If the bit associated with a vector is set, then the entry is unique,
+ * otherwise it may be shared.  If the bit with index
+ * #BSP_INTERRUPT_HANDLER_TABLE_SIZE is set, then the interrupt support is
+ * initialized, otherwise it is not initialized.
+ */
+extern uint8_t bsp_interrupt_handler_unique_table[];
+
+/**
+ * @brief Checks if the handler entry associated with the hander index is
+ *   unique.
+ *
+ * @param index is the handler index to check.
+ *
+ * @return Returns true, if handler entry associated with the hander index is
+ *   unique, otherwise false.
+ */
+static inline bool bsp_interrupt_is_handler_unique( rtems_vector_number index )
+{
+  rtems_vector_number table_index;
+  uint8_t             bit;
+
+  table_index = index / 8;
+  bit = (uint8_t) ( 1U << ( index % 8 ) );
+
+  return ( bsp_interrupt_handler_unique_table[ table_index ] & bit ) != 0;
+}
+
+/**
+ * @brief Checks if the interrupt support is initialized.
+ *
+ * @return Returns true, if the interrupt support is initialized, otherwise
+ *   false.
+ */
+static inline bool bsp_interrupt_is_initialized( void )
+{
+  return bsp_interrupt_is_handler_unique( BSP_INTERRUPT_HANDLER_TABLE_SIZE );
+}
+
+/**
+ * @brief This handler routine is used for empty entries.
+ */
+void bsp_interrupt_handler_empty( void *arg );
+
+/**
+ * @brief Checks if a handler entry is empty.
+ */
+static inline bool bsp_interrupt_is_empty_handler_entry(
+  const bsp_interrupt_handler_entry *entry
+)
+{
+  return entry->handler == bsp_interrupt_handler_empty;
+}
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/bsps/shared/irq-default-sources.am b/bsps/shared/irq-default-sources.am
index 6b4696dd26..9f0e4686f7 100644
--- a/bsps/shared/irq-default-sources.am
+++ b/bsps/shared/irq-default-sources.am
@@ -2,6 +2,7 @@ librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-affinity.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-default.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-default-handler.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-generic.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-handler-iterate.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-info.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-lock.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-server.c
diff --git a/bsps/shared/irq-sources.am b/bsps/shared/irq-sources.am
index 65c380a2da..776958dd8f 100644
--- a/bsps/shared/irq-sources.am
+++ b/bsps/shared/irq-sources.am
@@ -1,5 +1,6 @@
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-affinity.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-generic.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-handler-iterate.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-info.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-legacy.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-lock.c
diff --git a/bsps/shared/irq/irq-generic.c b/bsps/shared/irq/irq-generic.c
index bea6612136..81da647228 100644
--- a/bsps/shared/irq/irq-generic.c
+++ b/bsps/shared/irq/irq-generic.c
@@ -50,14 +50,14 @@ bsp_interrupt_handler_entry bsp_interrupt_handler_table
   [BSP_INTERRUPT_HANDLER_TABLE_SIZE];
 
 /* The last entry indicates if everything is initialized */
-static uint8_t bsp_interrupt_handler_unique_table
-  [(BSP_INTERRUPT_HANDLER_TABLE_SIZE + 7 + 1) / 8];
+uint8_t bsp_interrupt_handler_unique_table
+  [ ( BSP_INTERRUPT_HANDLER_TABLE_SIZE + 7 + 1 ) / 8 ];
 
-static void bsp_interrupt_handler_empty(void *arg)
+void bsp_interrupt_handler_empty( void *arg )
 {
   rtems_vector_number vector = (rtems_vector_number) (uintptr_t) arg;
 
-  bsp_interrupt_handler_default(vector);
+  bsp_interrupt_handler_default( vector );
 }
 
 #ifdef RTEMS_SMP
@@ -67,13 +67,6 @@ static void bsp_interrupt_handler_empty(void *arg)
   }
 #endif
 
-static inline bool bsp_interrupt_is_handler_unique(rtems_vector_number index)
-{
-  rtems_vector_number i = index / 8;
-  rtems_vector_number s = index % 8;
-  return (bsp_interrupt_handler_unique_table [i] >> s) & 0x1;
-}
-
 static inline void bsp_interrupt_set_handler_unique(
   rtems_vector_number index,
   bool unique
@@ -88,23 +81,11 @@ static inline void bsp_interrupt_set_handler_unique(
   }
 }
 
-static inline bool bsp_interrupt_is_initialized(void)
-{
-  return bsp_interrupt_is_handler_unique(BSP_INTERRUPT_HANDLER_TABLE_SIZE);
-}
-
 static inline void bsp_interrupt_set_initialized(void)
 {
   bsp_interrupt_set_handler_unique(BSP_INTERRUPT_HANDLER_TABLE_SIZE, true);
 }
 
-static inline bool bsp_interrupt_is_empty_handler_entry(
-  const bsp_interrupt_handler_entry *e
-)
-{
-  return e->handler == bsp_interrupt_handler_empty;
-}
-
 static inline void bsp_interrupt_clear_handler_entry(
   bsp_interrupt_handler_entry *e,
   rtems_vector_number vector
@@ -450,56 +431,6 @@ static rtems_status_code bsp_interrupt_handler_remove(
   return RTEMS_SUCCESSFUL;
 }
 
-/**
- * @brief Iterates over all installed interrupt handler of a vector.
- *
- * @ingroup bsp_interrupt
- *
- * @return In addition to the standard status codes this function returns
- * RTEMS_INTERNAL_ERROR if the BSP interrupt support is not initialized.
- *
- * @see rtems_interrupt_handler_iterate().
- */
-static rtems_status_code bsp_interrupt_handler_iterate(
-  rtems_vector_number vector,
-  rtems_interrupt_per_handler_routine routine,
-  void *arg
-)
-{
-  bsp_interrupt_handler_entry *current = NULL;
-  rtems_option options = 0;
-  rtems_vector_number index = 0;
-
-  /* Check parameters and system state */
-  if (!bsp_interrupt_is_initialized()) {
-    return RTEMS_INTERNAL_ERROR;
-  } else if (!bsp_interrupt_is_valid_vector(vector)) {
-    return RTEMS_INVALID_ID;
-  } else if (rtems_interrupt_is_in_progress()) {
-    return RTEMS_CALLED_FROM_ISR;
-  }
-
-  /* Lock */
-  bsp_interrupt_lock();
-
-  /* Interate */
-  index = bsp_interrupt_handler_index(vector);
-  current = &bsp_interrupt_handler_table [index];
-  if (!bsp_interrupt_is_empty_handler_entry(current)) {
-    do {
-      options = bsp_interrupt_is_handler_unique(index) ?
-        RTEMS_INTERRUPT_UNIQUE : RTEMS_INTERRUPT_SHARED;
-      routine(arg, current->info, options, current->handler, current->arg);
-      current = current->next;
-    } while (current != NULL);
-  }
-
-  /* Unlock */
-  bsp_interrupt_unlock();
-
-  return RTEMS_SUCCESSFUL;
-}
-
 rtems_status_code rtems_interrupt_handler_install(
   rtems_vector_number vector,
   const char *info,
@@ -520,15 +451,6 @@ rtems_status_code rtems_interrupt_handler_remove(
   return bsp_interrupt_handler_remove(vector, handler, arg);
 }
 
-rtems_status_code rtems_interrupt_handler_iterate(
-  rtems_vector_number vector,
-  rtems_interrupt_per_handler_routine routine,
-  void *arg
-)
-{
-  return bsp_interrupt_handler_iterate(vector, routine, arg);
-}
-
 bool bsp_interrupt_handler_is_empty(rtems_vector_number vector)
 {
   rtems_vector_number index = 0;
diff --git a/bsps/shared/irq/irq-handler-iterate.c b/bsps/shared/irq/irq-handler-iterate.c
new file mode 100644
index 0000000000..8adbdb4679
--- /dev/null
+++ b/bsps/shared/irq/irq-handler-iterate.c
@@ -0,0 +1,96 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup bsp_interrupt
+ *
+ * @brief This source file contains the implementation of
+ *   rtems_interrupt_handler_iterate().
+ */
+
+/*
+ * Copyright (C) 2017 embedded brains GmbH (http://www.embedded-brains.de)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <bsp/irq-generic.h>
+
+/**
+ * @brief Iterates over all installed interrupt handler of a vector.
+ *
+ * @ingroup bsp_interrupt
+ *
+ * @return In addition to the standard status codes this function returns
+ * RTEMS_INTERNAL_ERROR if the BSP interrupt support is not initialized.
+ *
+ * @see rtems_interrupt_handler_iterate().
+ */
+static rtems_status_code bsp_interrupt_handler_iterate(
+  rtems_vector_number vector,
+  rtems_interrupt_per_handler_routine routine,
+  void *arg
+)
+{
+  bsp_interrupt_handler_entry *current = NULL;
+  rtems_option options = 0;
+  rtems_vector_number index = 0;
+
+  /* Check parameters and system state */
+  if (!bsp_interrupt_is_initialized()) {
+    return RTEMS_INTERNAL_ERROR;
+  } else if (!bsp_interrupt_is_valid_vector(vector)) {
+    return RTEMS_INVALID_ID;
+  } else if (rtems_interrupt_is_in_progress()) {
+    return RTEMS_CALLED_FROM_ISR;
+  }
+
+  /* Lock */
+  bsp_interrupt_lock();
+
+  /* Interate */
+  index = bsp_interrupt_handler_index(vector);
+  current = &bsp_interrupt_handler_table [index];
+  if (!bsp_interrupt_is_empty_handler_entry(current)) {
+    do {
+      options = bsp_interrupt_is_handler_unique(index) ?
+        RTEMS_INTERRUPT_UNIQUE : RTEMS_INTERRUPT_SHARED;
+      routine(arg, current->info, options, current->handler, current->arg);
+      current = current->next;
+    } while (current != NULL);
+  }
+
+  /* Unlock */
+  bsp_interrupt_unlock();
+
+  return RTEMS_SUCCESSFUL;
+}
+
+rtems_status_code rtems_interrupt_handler_iterate(
+  rtems_vector_number vector,
+  rtems_interrupt_per_handler_routine routine,
+  void *arg
+)
+{
+  return bsp_interrupt_handler_iterate(vector, routine, arg);
+}
diff --git a/c/src/lib/libbsp/m68k/genmcf548x/Makefile.am b/c/src/lib/libbsp/m68k/genmcf548x/Makefile.am
index 0ae30ca93a..88a1ab0e5b 100644
--- a/c/src/lib/libbsp/m68k/genmcf548x/Makefile.am
+++ b/c/src/lib/libbsp/m68k/genmcf548x/Makefile.am
@@ -40,6 +40,7 @@ librtemsbsp_a_SOURCES += ../../../../../../bsps/m68k/genmcf548x/btimer/btimer.c
 # IRQ
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-affinity.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-default-handler.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-handler-iterate.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-info.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-legacy.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-lock.c
diff --git a/c/src/lib/libbsp/powerpc/ss555/Makefile.am b/c/src/lib/libbsp/powerpc/ss555/Makefile.am
index 43fed4fcbd..e1a79a6293 100644
--- a/c/src/lib/libbsp/powerpc/ss555/Makefile.am
+++ b/c/src/lib/libbsp/powerpc/ss555/Makefile.am
@@ -50,6 +50,7 @@ librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-affinity.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-default.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-default-handler.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-generic.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-handler-iterate.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-info.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-lock.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/irq/irq-server.c
diff --git a/spec/build/bsps/m68k/genmcf548x/obj.yml b/spec/build/bsps/m68k/genmcf548x/obj.yml
index a318da5e93..252b350f70 100644
--- a/spec/build/bsps/m68k/genmcf548x/obj.yml
+++ b/spec/build/bsps/m68k/genmcf548x/obj.yml
@@ -40,6 +40,7 @@ source:
 - bsps/shared/dev/getentropy/getentropy-cpucounter.c
 - bsps/shared/irq/irq-affinity.c
 - bsps/shared/irq/irq-default-handler.c
+- bsps/shared/irq/irq-handler-iterate.c
 - bsps/shared/irq/irq-info.c
 - bsps/shared/irq/irq-legacy.c
 - bsps/shared/irq/irq-lock.c
diff --git a/spec/build/bsps/objirq.yml b/spec/build/bsps/objirq.yml
index cb4eeb8fd4..616a3ea83f 100644
--- a/spec/build/bsps/objirq.yml
+++ b/spec/build/bsps/objirq.yml
@@ -12,6 +12,7 @@ links: []
 source:
 - bsps/shared/irq/irq-affinity.c
 - bsps/shared/irq/irq-generic.c
+- bsps/shared/irq/irq-handler-iterate.c
 - bsps/shared/irq/irq-info.c
 - bsps/shared/irq/irq-legacy.c
 - bsps/shared/irq/irq-lock.c
diff --git a/spec/build/bsps/powerpc/ss555/bspss555.yml b/spec/build/bsps/powerpc/ss555/bspss555.yml
index 89c0ff7774..e011ceb9b5 100644
--- a/spec/build/bsps/powerpc/ss555/bspss555.yml
+++ b/spec/build/bsps/powerpc/ss555/bspss555.yml
@@ -71,6 +71,7 @@ source:
 - bsps/shared/irq/irq-default-handler.c
 - bsps/shared/irq/irq-default.c
 - bsps/shared/irq/irq-generic.c
+- bsps/shared/irq/irq-handler-iterate.c
 - bsps/shared/irq/irq-info.c
 - bsps/shared/irq/irq-lock.c
 - bsps/shared/irq/irq-server.c
-- 
2.26.2



More information about the devel mailing list