From 51a6fd555d2f20506b4b235b0046d0b4b57708f4 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Fri, 19 Dec 2008 15:00:09 +0000 Subject: 2008-12-19 Sebastian Huber * include/irq-info.h, src/irq-info.c, src/irq-shell.c: New files. * include/irq-generic.h, src/irq-generic.c: Improved interrupt handler dispatch function. --- c/src/lib/libbsp/shared/ChangeLog | 6 ++ c/src/lib/libbsp/shared/include/irq-generic.h | 20 ++---- c/src/lib/libbsp/shared/include/irq-info.h | 51 ++++++++++++++++ c/src/lib/libbsp/shared/src/irq-generic.c | 18 +++--- c/src/lib/libbsp/shared/src/irq-info.c | 88 +++++++++++++++++++++++++++ c/src/lib/libbsp/shared/src/irq-shell.c | 45 ++++++++++++++ 6 files changed, 205 insertions(+), 23 deletions(-) create mode 100644 c/src/lib/libbsp/shared/include/irq-info.h create mode 100644 c/src/lib/libbsp/shared/src/irq-info.c create mode 100644 c/src/lib/libbsp/shared/src/irq-shell.c (limited to 'c') diff --git a/c/src/lib/libbsp/shared/ChangeLog b/c/src/lib/libbsp/shared/ChangeLog index 98ed522e66..225a98ccbe 100644 --- a/c/src/lib/libbsp/shared/ChangeLog +++ b/c/src/lib/libbsp/shared/ChangeLog @@ -1,3 +1,9 @@ +2008-12-19 Sebastian Huber + + * include/irq-info.h, src/irq-info.c, src/irq-shell.c: New files. + * include/irq-generic.h, src/irq-generic.c: Improved interrupt handler + dispatch function. + 2008-12-15 Joel Sherrill * bootcard.c: Eliminate pointers to API configuration tables in the diff --git a/c/src/lib/libbsp/shared/include/irq-generic.h b/c/src/lib/libbsp/shared/include/irq-generic.h index 58d4f4639f..71ff88fe84 100644 --- a/c/src/lib/libbsp/shared/include/irq-generic.h +++ b/c/src/lib/libbsp/shared/include/irq-generic.h @@ -75,13 +75,6 @@ static inline rtems_vector_number bsp_interrupt_handler_index( rtems_vector_numb #endif /* BSP_INTERRUPT_USE_INDEX_TABLE */ } -void bsp_interrupt_handler_empty( rtems_vector_number vector, void *arg); - -static inline bool bsp_interrupt_is_empty_handler_entry( bsp_interrupt_handler_entry *e) -{ - return e->handler == bsp_interrupt_handler_empty; -} - /** * @defgroup bsp_interrupt BSP Interrupt Support * @@ -217,17 +210,12 @@ rtems_status_code bsp_interrupt_vector_disable( rtems_vector_number vector); static inline void bsp_interrupt_handler_dispatch( rtems_vector_number vector) { if (bsp_interrupt_is_valid_vector( vector)) { - bsp_interrupt_handler_entry *head = &bsp_interrupt_handler_table [bsp_interrupt_handler_index( vector)]; - bsp_interrupt_handler_entry *current = head; + bsp_interrupt_handler_entry *e = &bsp_interrupt_handler_table [bsp_interrupt_handler_index( vector)]; do { - current->handler( vector, current->arg); - current = current->next; - } while (current != NULL); - - if (bsp_interrupt_is_empty_handler_entry( head)) { - bsp_interrupt_handler_default( vector); - } + e->handler( vector, e->arg); + e = e->next; + } while (e != NULL); } else { bsp_interrupt_handler_default( vector); } diff --git a/c/src/lib/libbsp/shared/include/irq-info.h b/c/src/lib/libbsp/shared/include/irq-info.h new file mode 100644 index 0000000000..f2dee7ed35 --- /dev/null +++ b/c/src/lib/libbsp/shared/include/irq-info.h @@ -0,0 +1,51 @@ +/** + * @file + * + * @ingroup bsp_interrupt + * + * @brief Header file for generic BSP interrupt information. + */ + +/* + * Copyright (c) 2008 + * Embedded Brains GmbH + * Obere Lagerstr. 30 + * D-82178 Puchheim + * Germany + * rtems@embedded-brains.de + * + * The license and distribution terms for this file may be found in the file + * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE. + */ + +#ifndef LIBBSP_SHARED_IRQ_INFO_H +#define LIBBSP_SHARED_IRQ_INFO_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @defgroup bsp_interrupt BSP Interrupt Information + * + * @ingroup rtems_interrupt_extension + * + * @{ + */ + +void bsp_interrupt_report_with_plugin( void *context, rtems_printk_plugin_t print); + +void bsp_interrupt_report( void); + +extern struct rtems_shell_cmd_tt bsp_interrupt_shell_command; + +/** @} */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* LIBBSP_SHARED_IRQ_INFO_H */ diff --git a/c/src/lib/libbsp/shared/src/irq-generic.c b/c/src/lib/libbsp/shared/src/irq-generic.c index fb6370a7da..2659001c14 100644 --- a/c/src/lib/libbsp/shared/src/irq-generic.c +++ b/c/src/lib/libbsp/shared/src/irq-generic.c @@ -26,6 +26,11 @@ bsp_interrupt_handler_index_type bsp_interrupt_handler_index_table [BSP_INTERRUPT_VECTOR_NUMBER]; #endif /* BSP_INTERRUPT_USE_INDEX_TABLE */ +static void bsp_interrupt_handler_empty( rtems_vector_number vector, void *arg) +{ + bsp_interrupt_handler_default( vector); +} + bsp_interrupt_handler_entry bsp_interrupt_handler_table [BSP_INTERRUPT_HANDLER_TABLE_SIZE] = { [0 ... BSP_INTERRUPT_HANDLER_TABLE_SIZE - 1] = { .handler = bsp_interrupt_handler_empty, @@ -68,9 +73,9 @@ static inline void bsp_interrupt_set_initialized(void) bsp_interrupt_set_handler_unique( BSP_INTERRUPT_HANDLER_TABLE_SIZE, true); } -void bsp_interrupt_handler_empty( rtems_vector_number vector, void *arg) +static inline bool bsp_interrupt_is_empty_handler_entry( bsp_interrupt_handler_entry *e) { - /* Do nothing */ + return e->handler == bsp_interrupt_handler_empty; } static inline void bsp_interrupt_clear_handler_entry( bsp_interrupt_handler_entry *e) @@ -101,7 +106,7 @@ static inline bool bsp_interrupt_allocate_handler_index( rtems_vector_number vec #endif /* BSP_INTERRUPT_USE_INDEX_TABLE */ } -static bsp_interrupt_handler_entry *bsp_interrupt_allocate_handler_entry() +static bsp_interrupt_handler_entry *bsp_interrupt_allocate_handler_entry( void) { #ifdef BSP_INTERRUPT_NO_HEAP_USAGE rtems_vector_number index = 0; @@ -124,7 +129,7 @@ static void bsp_interrupt_free_handler_entry( bsp_interrupt_handler_entry *e) #endif /* BSP_INTERRUPT_NO_HEAP_USAGE */ } -static rtems_status_code bsp_interrupt_lock() +static rtems_status_code bsp_interrupt_lock( void) { rtems_status_code sc = RTEMS_SUCCESSFUL; if (_System_state_Is_up( _System_state_Get())) { @@ -167,7 +172,7 @@ static rtems_status_code bsp_interrupt_lock() } } -static rtems_status_code bsp_interrupt_unlock() +static rtems_status_code bsp_interrupt_unlock( void) { if (bsp_interrupt_mutex != RTEMS_ID_NONE) { return rtems_semaphore_release( bsp_interrupt_mutex); @@ -184,10 +189,9 @@ static rtems_status_code bsp_interrupt_unlock() * function will be called after all internals are initialized. Initialization * is complete if everything was successful. */ -rtems_status_code bsp_interrupt_initialize() +rtems_status_code bsp_interrupt_initialize( void) { rtems_status_code sc = RTEMS_SUCCESSFUL; - rtems_vector_number index = 0; /* Lock */ sc = bsp_interrupt_lock(); diff --git a/c/src/lib/libbsp/shared/src/irq-info.c b/c/src/lib/libbsp/shared/src/irq-info.c new file mode 100644 index 0000000000..6736d508b7 --- /dev/null +++ b/c/src/lib/libbsp/shared/src/irq-info.c @@ -0,0 +1,88 @@ +/** + * @file + * + * @ingroup bsp_interrupt + * + * @brief Source file for generic BSP interrupt information code. + */ + +/* + * Copyright (c) 2008 + * Embedded Brains GmbH + * Obere Lagerstr. 30 + * D-82178 Puchheim + * Germany + * rtems@embedded-brains.de + * + * The license and distribution terms for this file may be found in the file + * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE. + */ + +#include + +#include + +#include +#include +#include + +typedef struct { + void *context; + rtems_printk_plugin_t print; + rtems_vector_number vector; +} bsp_interrupt_report_entry; + +static void bsp_interrupt_report_per_handler_routine( + void *arg, + const char *info, + rtems_option options, + rtems_interrupt_handler handler, + void *handler_arg +) +{ + bsp_interrupt_report_entry *e = (bsp_interrupt_report_entry *) arg; + const char *opt = options == RTEMS_INTERRUPT_UNIQUE ? "UNIQUE" : "SHARED"; + + e->print( e->context, "%7" PRIu32 " | %-32s | %7s | %010p | %010p\n", e->vector, info, opt, handler, handler_arg); +} + +/** + * @brief Prints interrupt information via the printk plugin @a print with the + * context @a context. + */ +void bsp_interrupt_report_with_plugin( void *context, rtems_printk_plugin_t print) +{ + rtems_vector_number v = 0; + bsp_interrupt_report_entry e = { + .context = context, + .print = print, + .vector = 0 + }; + + print( + context, + "-------------------------------------------------------------------------------\n" + " INTERRUPT INFORMATION\n" + "--------+----------------------------------+---------+------------+------------\n" + " VECTOR | INFO | OPTIONS | HANDLER | ARGUMENT \n" + "--------+----------------------------------+---------+------------+------------\n" + ); + + for (v = BSP_INTERRUPT_VECTOR_MIN; v <= BSP_INTERRUPT_VECTOR_MAX; ++v) { + e.vector = v; + (void) rtems_interrupt_handler_iterate( v, bsp_interrupt_report_per_handler_routine, &e); + } + + print( + context, + "--------+----------------------------------+---------+------------+------------\n" + ); +} + +/** + * @brief Prints interrupt information via the default printk plugin. + */ +void bsp_interrupt_report( void) +{ + bsp_interrupt_report_with_plugin( NULL, printk_plugin); +} diff --git a/c/src/lib/libbsp/shared/src/irq-shell.c b/c/src/lib/libbsp/shared/src/irq-shell.c new file mode 100644 index 0000000000..341f30364a --- /dev/null +++ b/c/src/lib/libbsp/shared/src/irq-shell.c @@ -0,0 +1,45 @@ +/** + * @file + * + * @ingroup bsp_interrupt + * + * @brief Source file for generic BSP interrupt shell code. + */ + +/* + * Copyright (c) 2008 + * Embedded Brains GmbH + * Obere Lagerstr. 30 + * D-82178 Puchheim + * Germany + * rtems@embedded-brains.de + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + +#include + +#include + +#include + +static int bsp_interrupt_shell_main( int argc, char **argv) +{ + bsp_interrupt_report_with_plugin( stdout, (rtems_printk_plugin_t) fprintf); + + return 0; +} + +/** + * @brief Shell command entry for interrupt information. + */ +struct rtems_shell_cmd_tt bsp_interrupt_shell_command = { + .name = "irq", + .usage = "Prints interrupt information", + .topic = "rtems", + .command = bsp_interrupt_shell_main, + .alias = NULL, + .next = NULL +}; -- cgit v1.2.3