Avoid blocking calls in input message handler task

Remove output queue and associated blocking calls. Instead write
directly in the mailbox ring buffer.

If inference queue is full do not block, instead bail out immeditely
and send back a message with rejected status.

Change-Id: Id08a39792791fe383f8c01bf28b07a293a49e9b0
diff --git a/applications/message_handler/main.cpp b/applications/message_handler/main.cpp
index fa5f0b0..d478ae6 100644
--- a/applications/message_handler/main.cpp
+++ b/applications/message_handler/main.cpp
@@ -70,11 +70,10 @@
 __attribute__((section("ethosu_core_out_queue"))) MessageQueue::Queue<1000> outputMessageQueue;
 
 namespace {
-// Queue used to pass inference requests to the inference runner task
-QueueHandle_t inferenceQueue;
 
-// Queue for message responses to the remote host
-QueueHandle_t outputQueue;
+SemaphoreHandle_t messageNotify;
+QueueHandle_t inferenceInputQueue;
+QueueHandle_t inferenceOutputQueue;
 
 // Mailbox driver
 #ifdef MHU_V2
@@ -138,16 +137,19 @@
     printf("Starting inference task\n");
 
     uint8_t *arena = reinterpret_cast<uint8_t *>(pvParameters);
-    InferenceHandler process(arena, arenaSize, inferenceQueue, outputQueue);
+    InferenceHandler process(arena, arenaSize, inferenceInputQueue, inferenceOutputQueue, messageNotify);
     process.run();
 }
 
-void inputMessageTask(void *pvParameters) {
-    (void)pvParameters;
-
+void messageTask(void *) {
     printf("Starting input message task\n");
 
-    IncomingMessageHandler process(*inputMessageQueue.toQueue(), mailbox, inferenceQueue, outputQueue);
+    IncomingMessageHandler process(*inputMessageQueue.toQueue(),
+                                   *outputMessageQueue.toQueue(),
+                                   mailbox,
+                                   inferenceInputQueue,
+                                   inferenceOutputQueue,
+                                   messageNotify);
 
 #ifdef MHU_IRQ
     // Register mailbox interrupt handler
@@ -158,15 +160,6 @@
     process.run();
 }
 
-void outputMessageTask(void *pvParameters) {
-    (void)pvParameters;
-
-    printf("Starting output message task\n");
-
-    MessageHandler::OutgoingMessageHandler process(*outputMessageQueue.toQueue(), mailbox, outputQueue);
-    process.run();
-}
-
 } // namespace
 
 // FreeRTOS application. NOTE: Additional tasks may require increased heap size.
@@ -179,20 +172,14 @@
     }
 
     // Create message queues for inter process communication
-    inferenceQueue = xQueueCreate(10, sizeof(ethosu_core_inference_req));
-    outputQueue    = xQueueCreate(10, sizeof(OutputMessage));
+    messageNotify        = xSemaphoreCreateBinary();
+    inferenceInputQueue  = xQueueCreate(10, sizeof(ethosu_core_inference_req));
+    inferenceOutputQueue = xQueueCreate(10, sizeof(ethosu_core_inference_rsp));
 
     // Task for handling incoming messages from the remote host
-    ret = xTaskCreate(inputMessageTask, "inputMessageTask", 1024, nullptr, 2, nullptr);
+    ret = xTaskCreate(messageTask, "messageTask", 1024, nullptr, 2, nullptr);
     if (ret != pdPASS) {
-        printf("Failed to create 'inputMessageTask'\n");
-        return ret;
-    }
-
-    // Task for handling outgoing messages resposes to the remote host
-    ret = xTaskCreate(outputMessageTask, "outputMessageTask", 512, nullptr, 2, nullptr);
-    if (ret != pdPASS) {
-        printf("Failed to create 'outputMessageTask'\n");
+        printf("Failed to create 'messageTask'\n");
         return ret;
     }