diff --git a/epicardium/api/caller.c b/epicardium/api/caller.c index 8e61b674b4179832223f1c85adafca137c2ea113..54d9c4aea555950816bf7ab3f52898c6ca73572c 100644 --- a/epicardium/api/caller.c +++ b/epicardium/api/caller.c @@ -5,8 +5,17 @@ #define MXC_ASSERT_ENABLE #include "mxc_assert.h" +static uint32_t irq_save = 0; + void *_api_call_start(api_id_t id, uintptr_t size) { + /* + * Disable all maskable interrupts here, to be turned on again at the + * end of _api_call_transact(). + */ + irq_save = __get_PRIMASK(); + __set_PRIMASK(1); + while (SEMA_GetSema(_API_SEMAPHORE) == E_BUSY) { } @@ -51,6 +60,12 @@ void *_api_call_transact(void *buffer) API_CALL_MEM->call_flag = _API_FLAG_IDLE; SEMA_FreeSema(_API_SEMAPHORE); + /* + * Re-enable interrupts (if previously enabled) after completing the API + * call. + */ + __set_PRIMASK(irq_save); + return API_CALL_MEM->buffer; }