/** * @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 ) { rtems_status_code sc = RTEMS_SUCCESSFUL; 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 */ sc = bsp_interrupt_lock(); if (sc != RTEMS_SUCCESSFUL) { return sc; } /* 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 */ sc = bsp_interrupt_unlock(); if (sc != RTEMS_SUCCESSFUL) { return sc; } return RTEMS_SUCCESSFUL; }
bool bsp_interrupt_handler_is_empty(rtems_vector_number vector) { rtems_vector_number index = 0; bsp_interrupt_handler_entry *head = NULL; bool empty; /* For use in interrupts so no lock. */ /* Get handler table index */ index = bsp_interrupt_handler_index(vector); /* Get head entry of the handler list for the vector */ head = &bsp_interrupt_handler_table [index]; empty = bsp_interrupt_is_empty_handler_entry(head); return empty; }
static inline bool bsp_interrupt_allocate_handler_index( rtems_vector_number vector, rtems_vector_number *index ) { #ifdef BSP_INTERRUPT_USE_INDEX_TABLE rtems_vector_number i = 0; /* The first entry will remain empty */ for (i = 1; i < BSP_INTERRUPT_HANDLER_TABLE_SIZE; ++i) { const bsp_interrupt_handler_entry *e = &bsp_interrupt_handler_table [i]; if (bsp_interrupt_is_empty_handler_entry(e)) { *index = i; return true; } } return false; #else *index = vector; return true; #endif }
/** * @brief Installs an interrupt handler. * * @ingroup bsp_interrupt * * @return In addition to the standard status codes this function returns: * - If the BSP interrupt support is not initialized RTEMS_INTERNAL_ERROR will * be returned. * - If not enough memory for a new handler is available RTEMS_NO_MEMORY will * be returned * * @see rtems_interrupt_handler_install() */ static rtems_status_code bsp_interrupt_handler_install( rtems_vector_number vector, const char *info, rtems_option options, rtems_interrupt_handler handler, void *arg ) { rtems_status_code sc = RTEMS_SUCCESSFUL; rtems_interrupt_level level; rtems_vector_number index = 0; bsp_interrupt_handler_entry *head = NULL; bsp_interrupt_handler_entry *tail = NULL; bsp_interrupt_handler_entry *current = NULL; bsp_interrupt_handler_entry *match = NULL; bool enable_vector = false; /* 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; } /* Lock */ sc = bsp_interrupt_lock(); if (sc != RTEMS_SUCCESSFUL) { return sc; } /* Get handler table index */ index = bsp_interrupt_handler_index(vector); /* Get head entry of the handler list for current vector */ head = &bsp_interrupt_handler_table [index]; if (bsp_interrupt_is_empty_handler_entry(head)) { /* * No real handler installed yet. So allocate a new index in * the handler table and fill the entry with life. */ if (bsp_interrupt_allocate_handler_index(vector, &index)) { rtems_interrupt_disable(level); bsp_interrupt_handler_table [index].handler = handler; bsp_interrupt_handler_table [index].arg = arg; #ifdef BSP_INTERRUPT_USE_INDEX_TABLE bsp_interrupt_handler_index_table [vector] = index; #endif rtems_interrupt_enable(level); bsp_interrupt_handler_table [index].info = info; } else { /* Handler table is full */ bsp_interrupt_unlock(); return RTEMS_NO_MEMORY; } /* This is the first handler so enable the vector later */ enable_vector = true; } else { /* Ensure that a unique handler remains unique */ if ( RTEMS_INTERRUPT_IS_UNIQUE(options) || bsp_interrupt_is_handler_unique(index) ) { /* * Tried to install a unique handler on a not empty * list or there is already a unique handler installed. */ bsp_interrupt_unlock(); return RTEMS_RESOURCE_IN_USE; } /* * Search for the list tail and check if the handler is already * installed. */ current = head; do { if (current->handler == handler && current->arg == arg) { match = current; } tail = current; current = current->next; } while (current != NULL); /* Ensure the handler is not already installed */ if (match != NULL) { /* The handler is already installed */ bsp_interrupt_unlock(); return RTEMS_TOO_MANY; } /* Allocate a new entry */ current = bsp_interrupt_allocate_handler_entry(); if (current == NULL) { /* Not enough memory */ bsp_interrupt_unlock(); return RTEMS_NO_MEMORY; } /* Set entry */ current->handler = handler; current->arg = arg; current->info = info; current->next = NULL; /* Link to list tail */ rtems_interrupt_disable(level); tail->next = current; rtems_interrupt_enable(level); } /* Make the handler unique if necessary */ bsp_interrupt_set_handler_unique(index, RTEMS_INTERRUPT_IS_UNIQUE(options)); /* Enable the vector if necessary */ if (enable_vector) { sc = bsp_interrupt_vector_enable(vector); if (sc != RTEMS_SUCCESSFUL) { bsp_interrupt_unlock(); return sc; } } /* Unlock */ sc = bsp_interrupt_unlock(); if (sc != RTEMS_SUCCESSFUL) { return sc; } return RTEMS_SUCCESSFUL; }