summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2012-11-06 10:15:17 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2012-11-06 10:20:56 +0100
commita9e5e747f08f7f157ec20f3a08c159ec85f7f394 (patch)
tree062dec3792cb444f9858f3d1c0d8069d0d2b2bae
parentscore: Support static_assert and _Static_assert (diff)
downloadrtems-a9e5e747f08f7f157ec20f3a08c159ec85f7f394.tar.bz2
bsps: Use allocator mutex for generic IRQ support
Since the allocator mutex allows nesting now we can use it for the generic IRQ support (recursive obtain in a potential malloc()). This simplifies the code and reduces memory usage.
-rw-r--r--c/src/lib/libbsp/shared/src/irq-generic.c105
1 files changed, 16 insertions, 89 deletions
diff --git a/c/src/lib/libbsp/shared/src/irq-generic.c b/c/src/lib/libbsp/shared/src/irq-generic.c
index 4f18e341ba..d0d593281b 100644
--- a/c/src/lib/libbsp/shared/src/irq-generic.c
+++ b/c/src/lib/libbsp/shared/src/irq-generic.c
@@ -21,9 +21,11 @@
* http://www.rtems.com/license/LICENSE.
*/
+#include <bsp/irq-generic.h>
+
#include <stdlib.h>
-#include <bsp/irq-generic.h>
+#include <rtems/score/apimutex.h>
#ifdef BSP_INTERRUPT_USE_INDEX_TABLE
bsp_interrupt_handler_index_type bsp_interrupt_handler_index_table
@@ -37,8 +39,6 @@ bsp_interrupt_handler_entry bsp_interrupt_handler_table
static uint8_t bsp_interrupt_handler_unique_table
[(BSP_INTERRUPT_HANDLER_TABLE_SIZE + 7 + 1) / 8];
-static rtems_id bsp_interrupt_mutex = RTEMS_ID_NONE;
-
static void bsp_interrupt_handler_empty(void *arg)
{
rtems_vector_number vector = (rtems_vector_number) arg;
@@ -141,59 +141,17 @@ static void bsp_interrupt_free_handler_entry(bsp_interrupt_handler_entry *e)
#endif
}
-static rtems_status_code bsp_interrupt_lock(void)
+static void bsp_interrupt_lock(void)
{
- rtems_status_code sc = RTEMS_SUCCESSFUL;
if (_System_state_Is_up(_System_state_Get())) {
- if (bsp_interrupt_mutex == RTEMS_ID_NONE) {
- rtems_id mutex = RTEMS_ID_NONE;
- rtems_interrupt_level level;
-
- /* Create a mutex */
- sc = rtems_semaphore_create (
- rtems_build_name('I', 'N', 'T', 'R'),
- 1,
- RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
- 0,
- &mutex
- );
- if (sc != RTEMS_SUCCESSFUL) {
- return sc;
- }
-
- /* Assign the mutex */
- rtems_interrupt_disable(level);
- if (bsp_interrupt_mutex == RTEMS_ID_NONE) {
- /* Nobody else assigned the mutex in the meantime */
-
- bsp_interrupt_mutex = mutex;
- rtems_interrupt_enable(level);
- } else {
- /* Somebody else won */
-
- rtems_interrupt_enable(level);
- sc = rtems_semaphore_delete(mutex);
- if (sc != RTEMS_SUCCESSFUL) {
- return sc;
- }
- }
- }
- return rtems_semaphore_obtain(
- bsp_interrupt_mutex,
- RTEMS_WAIT,
- RTEMS_NO_TIMEOUT
- );
- } else {
- return RTEMS_SUCCESSFUL;
+ _RTEMS_Lock_allocator();
}
}
-static rtems_status_code bsp_interrupt_unlock(void)
+static void bsp_interrupt_unlock(void)
{
- if (bsp_interrupt_mutex != RTEMS_ID_NONE) {
- return rtems_semaphore_release(bsp_interrupt_mutex);
- } else {
- return RTEMS_SUCCESSFUL;
+ if (_System_state_Is_up(_System_state_Get())) {
+ _RTEMS_Unlock_allocator();
}
}
@@ -202,16 +160,7 @@ rtems_status_code bsp_interrupt_initialize(void)
rtems_status_code sc = RTEMS_SUCCESSFUL;
size_t i = 0;
- sc = bsp_interrupt_lock();
- if (sc != RTEMS_SUCCESSFUL) {
- return sc;
- }
-
- /* We need one semaphore */
- if (_System_state_Is_before_initialization(_System_state_Get())) {
- Configuration.work_space_size += sizeof(Semaphore_Control);
- ++Configuration_RTEMS_API.maximum_semaphores;
- }
+ bsp_interrupt_lock();
if (bsp_interrupt_is_initialized()) {
bsp_interrupt_unlock();
@@ -232,10 +181,7 @@ rtems_status_code bsp_interrupt_initialize(void)
bsp_interrupt_set_initialized();
- sc = bsp_interrupt_unlock();
- if (sc != RTEMS_SUCCESSFUL) {
- return sc;
- }
+ bsp_interrupt_unlock();
return RTEMS_SUCCESSFUL;
}
@@ -282,10 +228,7 @@ static rtems_status_code bsp_interrupt_handler_install(
}
/* Lock */
- sc = bsp_interrupt_lock();
- if (sc != RTEMS_SUCCESSFUL) {
- return sc;
- }
+ bsp_interrupt_lock();
/* Get handler table index */
index = bsp_interrupt_handler_index(vector);
@@ -382,10 +325,7 @@ static rtems_status_code bsp_interrupt_handler_install(
}
/* Unlock */
- sc = bsp_interrupt_unlock();
- if (sc != RTEMS_SUCCESSFUL) {
- return sc;
- }
+ bsp_interrupt_unlock();
return RTEMS_SUCCESSFUL;
}
@@ -426,10 +366,7 @@ static rtems_status_code bsp_interrupt_handler_remove(
}
/* Lock */
- sc = bsp_interrupt_lock();
- if (sc != RTEMS_SUCCESSFUL) {
- return sc;
- }
+ bsp_interrupt_lock();
/* Get handler table index */
index = bsp_interrupt_handler_index(vector);
@@ -508,10 +445,7 @@ static rtems_status_code bsp_interrupt_handler_remove(
}
/* Unlock */
- sc = bsp_interrupt_unlock();
- if (sc != RTEMS_SUCCESSFUL) {
- return sc;
- }
+ bsp_interrupt_unlock();
return RTEMS_SUCCESSFUL;
}
@@ -532,7 +466,6 @@ static rtems_status_code bsp_interrupt_handler_iterate(
void *arg
)
{
- rtems_status_code sc = RTEMS_SUCCESSFUL;
bsp_interrupt_handler_entry *current = NULL;
rtems_option options = 0;
rtems_vector_number index = 0;
@@ -547,10 +480,7 @@ static rtems_status_code bsp_interrupt_handler_iterate(
}
/* Lock */
- sc = bsp_interrupt_lock();
- if (sc != RTEMS_SUCCESSFUL) {
- return sc;
- }
+ bsp_interrupt_lock();
/* Interate */
index = bsp_interrupt_handler_index(vector);
@@ -565,10 +495,7 @@ static rtems_status_code bsp_interrupt_handler_iterate(
}
/* Unlock */
- sc = bsp_interrupt_unlock();
- if (sc != RTEMS_SUCCESSFUL) {
- return sc;
- }
+ bsp_interrupt_unlock();
return RTEMS_SUCCESSFUL;
}