]> granicus.if.org Git - esp-idf/commitdiff
ipc: fix `esp_ipc_call_blocking` to return after callback execution is completed
authorMahavir Jain <mahavir@espressif.com>
Thu, 6 Sep 2018 05:52:41 +0000 (11:22 +0530)
committerMahavir Jain <mahavir@espressif.com>
Fri, 7 Sep 2018 08:49:35 +0000 (14:19 +0530)
Signed-off-by: Mahavir Jain <mahavir@espressif.com>
components/esp32/ipc.c
components/esp32/test/test_ipc.c [new file with mode: 0644]

index 6319a621d7a1c01fc3216fee5e866da11fac3c72..d10e8e819ed3c28ae13becff4d1bbe8fd29effa8 100644 (file)
@@ -25,9 +25,8 @@
 #include "freertos/semphr.h"
 
 
-static TaskHandle_t s_ipc_tasks[portNUM_PROCESSORS];         // Two high priority tasks, one for each CPU
 static SemaphoreHandle_t s_ipc_mutex;                        // This mutex is used as a global lock for esp_ipc_* APIs
-static SemaphoreHandle_t s_ipc_sem[portNUM_PROCESSORS];      // Two semaphores used to wake each of s_ipc_tasks
+static SemaphoreHandle_t s_ipc_sem[portNUM_PROCESSORS];      // Two semaphores used to wake each of ipc tasks
 static SemaphoreHandle_t s_ipc_ack;                          // Semaphore used to acknowledge that task was woken up,
                                                              //   or function has finished running
 static volatile esp_ipc_func_t s_func;                       // Function which should be called by high priority task
@@ -79,10 +78,10 @@ void esp_ipc_init()
     s_ipc_ack = xSemaphoreCreateBinary();
     char task_name[15];
     for (int i = 0; i < portNUM_PROCESSORS; ++i) {
-        sprintf(task_name,"ipc%d",i);
+        snprintf(task_name, sizeof(task_name), "ipc%d", i);
         s_ipc_sem[i] = xSemaphoreCreateBinary();
         portBASE_TYPE res = xTaskCreatePinnedToCore(ipc_task, task_name, CONFIG_IPC_TASK_STACK_SIZE, (void*) i,
-                                                    configMAX_PRIORITIES - 1, &s_ipc_tasks[i], i);
+                                                    configMAX_PRIORITIES - 1, NULL, i);
         assert(res == pdTRUE);
     }
 }
@@ -100,7 +99,7 @@ static esp_err_t esp_ipc_call_and_wait(uint32_t cpu_id, esp_ipc_func_t func, voi
 
     s_func = func;
     s_func_arg = arg;
-    s_ipc_wait = IPC_WAIT_FOR_START;
+    s_ipc_wait = wait_for;
     xSemaphoreGive(s_ipc_sem[cpu_id]);
     xSemaphoreTake(s_ipc_ack, portMAX_DELAY);
     xSemaphoreGive(s_ipc_mutex);
diff --git a/components/esp32/test/test_ipc.c b/components/esp32/test/test_ipc.c
new file mode 100644 (file)
index 0000000..c58e8f7
--- /dev/null
@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+#include "unity.h"
+#include "esp_ipc.h"
+
+static void test_func_ipc_cb(void *arg)
+{
+    vTaskDelay(50);
+    int *val = (int *)arg;
+    *val = 0xa5a5;
+}
+
+TEST_CASE("Test blocking IPC function call", "[ipc]")
+{
+    int val = 0x5a5a;
+#ifdef CONFIG_FREERTOS_UNICORE
+    esp_ipc_call_blocking(xPortGetCoreID(), test_func_ipc_cb, &val);
+#else
+    esp_ipc_call_blocking(!xPortGetCoreID(), test_func_ipc_cb, &val);
+#endif
+    TEST_ASSERT_EQUAL_HEX(val, 0xa5a5);
+}