diff options
Diffstat (limited to 'applications/message_handler/main.cpp')
-rw-r--r-- | applications/message_handler/main.cpp | 103 |
1 files changed, 11 insertions, 92 deletions
diff --git a/applications/message_handler/main.cpp b/applications/message_handler/main.cpp index 0b4860a..caa778b 100644 --- a/applications/message_handler/main.cpp +++ b/applications/message_handler/main.cpp @@ -29,10 +29,12 @@ #include <stdio.h> #include "ethosu_core_interface.h" +#include "indexed_networks.hpp" #include "message_handler.hpp" #include "message_queue.hpp" -#include <mailbox.hpp> +#include "networks.hpp" +#include <mailbox.hpp> #if defined(MHU_V2) #include <mhu_v2.hpp> #elif defined(MHU_JUNO) @@ -83,94 +85,6 @@ Mailbox::MHUDummy mailbox; } // namespace /**************************************************************************** - * Override new operators to call in FreeRTOS allocator - ****************************************************************************/ - -void *operator new(size_t size) { - return pvPortMalloc(size); -} - -void *operator new[](size_t size) { - return pvPortMalloc(size); -} - -void operator delete(void *ptr) { - vPortFree(ptr); -} - -void operator delete(void *ptr, std::size_t) { - vPortFree(ptr); -} - -void operator delete[](void *ptr) { - vPortFree(ptr); -} - -void operator delete[](void *ptr, std::size_t) { - vPortFree(ptr); -} - -/**************************************************************************** - * Mutex & Semaphore - ****************************************************************************/ - -extern "C" { - -void *ethosu_mutex_create(void) { - return xSemaphoreCreateMutex(); -} - -int ethosu_mutex_lock(void *mutex) { - SemaphoreHandle_t handle = reinterpret_cast<SemaphoreHandle_t>(mutex); - if (xSemaphoreTake(handle, portMAX_DELAY) != pdTRUE) { - printf("Error: Failed to lock mutex.\n"); - return -1; - } - return 0; -} - -int ethosu_mutex_unlock(void *mutex) { - SemaphoreHandle_t handle = reinterpret_cast<SemaphoreHandle_t>(mutex); - if (xSemaphoreGive(handle) != pdTRUE) { - printf("Error: Failed to unlock mutex.\n"); - return -1; - } - return 0; -} - -void *ethosu_semaphore_create(void) { - return xSemaphoreCreateBinary(); -} - -int ethosu_semaphore_take(void *sem) { - SemaphoreHandle_t handle = reinterpret_cast<SemaphoreHandle_t>(sem); - if (xSemaphoreTake(handle, portMAX_DELAY) != pdTRUE) { - printf("Error: Failed to take semaphore.\n"); - return -1; - } - return 0; -} - -int ethosu_semaphore_give(void *sem) { - SemaphoreHandle_t handle = reinterpret_cast<SemaphoreHandle_t>(sem); - if (xPortIsInsideInterrupt()) { - if (xSemaphoreGiveFromISR(handle, NULL) != pdTRUE) { - printf("Error: Failed to give semaphore from ISR.\n"); - return -1; - } - } else { - /* A FreeRTOS binary semaphore is fundamentally a queue that can only hold one item. If the queue is full, - * xSemaphoreGive will return a pdFALSE value. Ignoring the return value in here, as a semaphore give failure - * does not affect the application correctness. */ - if (xSemaphoreGive(handle) != pdTRUE) { - // do nothing - } - } - return 0; -} -} - -/**************************************************************************** * Application ****************************************************************************/ namespace { @@ -179,13 +93,16 @@ struct TaskParams { TaskParams() : messageNotify(xSemaphoreCreateBinary()), inferenceInputQueue(std::make_shared<Queue<ethosu_core_inference_req>>()), - inferenceOutputQueue(xQueueCreate(10, sizeof(ethosu_core_inference_rsp))) {} + inferenceOutputQueue(xQueueCreate(10, sizeof(ethosu_core_inference_rsp))), + networks(std::make_shared<WithIndexedNetworks>()) {} SemaphoreHandle_t messageNotify; // Used to pass inference requests to the inference runner task std::shared_ptr<Queue<ethosu_core_inference_req>> inferenceInputQueue; // Queue for message responses to the remote host QueueHandle_t inferenceOutputQueue; + // Networks provider + std::shared_ptr<Networks> networks; }; struct InferenceTaskParams { @@ -207,7 +124,8 @@ void inferenceTask(void *pvParameters) { arenaSize, params->taskParams->inferenceInputQueue, params->taskParams->inferenceOutputQueue, - params->taskParams->messageNotify); + params->taskParams->messageNotify, + params->taskParams->networks); process.run(); } @@ -221,7 +139,8 @@ void messageTask(void *pvParameters) { mailbox, params->inferenceInputQueue, params->inferenceOutputQueue, - params->messageNotify); + params->messageNotify, + params->networks); #ifdef MHU_IRQ // Register mailbox interrupt handler |