mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/ipc_blocking_v4.4' into 'release/v4.4'
esp_ipc: Fix a case when ipc_task() can wake up blocking task early (v4.4) See merge request espressif/esp-idf!18415
This commit is contained in:
commit
93bf6be8bd
@ -65,14 +65,17 @@ static void IRAM_ATTR ipc_task(void* arg)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (s_func[cpuid]) {
|
if (s_func[cpuid]) {
|
||||||
|
// we need to cache s_func, s_func_arg and s_ipc_wait variables locally because they can be changed by a subsequent IPC call.
|
||||||
esp_ipc_func_t func = s_func[cpuid];
|
esp_ipc_func_t func = s_func[cpuid];
|
||||||
|
s_func[cpuid] = NULL;
|
||||||
void* arg = s_func_arg[cpuid];
|
void* arg = s_func_arg[cpuid];
|
||||||
|
esp_ipc_wait_t ipc_wait = s_ipc_wait[cpuid];
|
||||||
|
|
||||||
if (s_ipc_wait[cpuid] == IPC_WAIT_FOR_START) {
|
if (ipc_wait == IPC_WAIT_FOR_START) {
|
||||||
xSemaphoreGive(s_ipc_ack[cpuid]);
|
xSemaphoreGive(s_ipc_ack[cpuid]);
|
||||||
}
|
}
|
||||||
(*func)(arg);
|
(*func)(arg);
|
||||||
if (s_ipc_wait[cpuid] == IPC_WAIT_FOR_END) {
|
if (ipc_wait == IPC_WAIT_FOR_END) {
|
||||||
xSemaphoreGive(s_ipc_ack[cpuid]);
|
xSemaphoreGive(s_ipc_ack[cpuid]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,7 +145,6 @@ static esp_err_t esp_ipc_call_and_wait(uint32_t cpu_id, esp_ipc_func_t func, voi
|
|||||||
s_ipc_wait[cpu_id] = wait_for;
|
s_ipc_wait[cpu_id] = wait_for;
|
||||||
xSemaphoreGive(s_ipc_sem[cpu_id]);
|
xSemaphoreGive(s_ipc_sem[cpu_id]);
|
||||||
xSemaphoreTake(s_ipc_ack[cpu_id], portMAX_DELAY);
|
xSemaphoreTake(s_ipc_ack[cpu_id], portMAX_DELAY);
|
||||||
s_func[cpu_id] = NULL;
|
|
||||||
#ifdef CONFIG_ESP_IPC_USES_CALLERS_PRIORITY
|
#ifdef CONFIG_ESP_IPC_USES_CALLERS_PRIORITY
|
||||||
xSemaphoreGive(s_ipc_mutex[cpu_id]);
|
xSemaphoreGive(s_ipc_mutex[cpu_id]);
|
||||||
#else
|
#else
|
||||||
|
@ -125,4 +125,30 @@ TEST_CASE("Test multiple ipc_calls", "[ipc]")
|
|||||||
}
|
}
|
||||||
#endif /* CONFIG_ESP_IPC_USE_CALLERS_PRIORITY */
|
#endif /* CONFIG_ESP_IPC_USE_CALLERS_PRIORITY */
|
||||||
|
|
||||||
|
static void test_func_ipc_cb2(void *arg)
|
||||||
|
{
|
||||||
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||||
|
int *val = (int *)arg;
|
||||||
|
*val = *val + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_func_ipc_cb3(void *arg)
|
||||||
|
{
|
||||||
|
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||||
|
int *val = (int *)arg;
|
||||||
|
*val = *val + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Test ipc_task can not wake up blocking task early", "[ipc]")
|
||||||
|
{
|
||||||
|
int val1 = 20;
|
||||||
|
esp_ipc_call(1, test_func_ipc_cb2, &val1);
|
||||||
|
TEST_ASSERT_EQUAL(20, val1);
|
||||||
|
|
||||||
|
int val2 = 30;
|
||||||
|
esp_ipc_call_blocking(1, test_func_ipc_cb3, &val2);
|
||||||
|
TEST_ASSERT_EQUAL(21, val1);
|
||||||
|
TEST_ASSERT_EQUAL(31, val2);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* !CONFIG_FREERTOS_UNICORE */
|
#endif /* !CONFIG_FREERTOS_UNICORE */
|
||||||
|
Loading…
Reference in New Issue
Block a user