bsps/irq: Move handler iterate to separate file

Update #3269.
This commit is contained in:
Sebastian Huber
2021-06-25 11:06:39 +02:00
parent 1b3b5b8428
commit 04c2c0804b
10 changed files with 164 additions and 82 deletions

View File

@@ -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 */

View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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