bsps/irq: Add bsp_interrupt_check_and_lock()

Return RTEMS_INCORRECT_STATE instead of RTEMS_INTERNAL_ERROR in case the
interrupt support is not initialized.  This is similar to
rtems_timer_server_fire_after() for example.

Update #3269.
This commit is contained in:
Sebastian Huber
2021-06-24 17:14:03 +02:00
parent 73fcbf4cff
commit 63d9e840b7
3 changed files with 86 additions and 63 deletions

View File

@@ -122,6 +122,32 @@ static inline bool bsp_interrupt_allocate_handler_index(
#endif
}
rtems_status_code bsp_interrupt_check_and_lock(
rtems_vector_number vector,
rtems_interrupt_handler handler
)
{
if ( !bsp_interrupt_is_initialized() ) {
return RTEMS_INCORRECT_STATE;
}
if ( handler == NULL ) {
return RTEMS_INVALID_ADDRESS;
}
if ( !bsp_interrupt_is_valid_vector( vector ) ) {
return RTEMS_INVALID_ID;
}
if ( rtems_interrupt_is_in_progress() ) {
return RTEMS_CALLED_FROM_ISR;
}
bsp_interrupt_lock();
return RTEMS_SUCCESSFUL;
}
void bsp_interrupt_initialize(void)
{
rtems_status_code sc = RTEMS_SUCCESSFUL;
@@ -162,25 +188,18 @@ static rtems_status_code bsp_interrupt_handler_install(
void *arg
)
{
rtems_status_code sc;
rtems_interrupt_level level;
rtems_vector_number index = 0;
rtems_interrupt_entry *head = NULL;
bool enable_vector = false;
bool replace = RTEMS_INTERRUPT_IS_REPLACE(options);
/* 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 (handler == NULL) {
return RTEMS_INVALID_ADDRESS;
} else if (rtems_interrupt_is_in_progress()) {
return RTEMS_CALLED_FROM_ISR;
}
sc = bsp_interrupt_check_and_lock( vector, handler );
/* Lock */
bsp_interrupt_lock();
if ( sc != RTEMS_SUCCESSFUL ) {
return sc;
}
/* Get handler table index */
index = bsp_interrupt_handler_index(vector);
@@ -325,6 +344,7 @@ static rtems_status_code bsp_interrupt_handler_remove(
void *arg
)
{
rtems_status_code sc;
rtems_interrupt_level level;
rtems_vector_number index = 0;
rtems_interrupt_entry *head = NULL;
@@ -332,19 +352,11 @@ static rtems_status_code bsp_interrupt_handler_remove(
rtems_interrupt_entry *previous = NULL;
rtems_interrupt_entry *match = NULL;
/* 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 (handler == NULL) {
return RTEMS_INVALID_ADDRESS;
} else if (rtems_interrupt_is_in_progress()) {
return RTEMS_CALLED_FROM_ISR;
}
sc = bsp_interrupt_check_and_lock( vector, handler );
/* Lock */
bsp_interrupt_lock();
if ( sc != RTEMS_SUCCESSFUL ) {
return sc;
}
/* Get handler table index */
index = bsp_interrupt_handler_index(vector);

View File

@@ -36,39 +36,26 @@
#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_status_code rtems_interrupt_handler_iterate(
rtems_vector_number vector,
rtems_interrupt_per_handler_routine routine,
void *arg
void *arg
)
{
rtems_interrupt_entry *current = NULL;
rtems_option options = 0;
rtems_vector_number index = 0;
rtems_status_code sc;
rtems_vector_number index;
rtems_option options;
rtems_interrupt_entry *current;
/* 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;
sc = bsp_interrupt_check_and_lock(
vector,
(rtems_interrupt_handler) routine
);
if ( sc != RTEMS_SUCCESSFUL ) {
return sc;
}
/* 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)) {
@@ -80,17 +67,7 @@ static rtems_status_code bsp_interrupt_handler_iterate(
} 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);
}