1
6
7
15
16
18
19
20
21
22
23
24
31
32
36
37
38
39
40
41
42
43
44
46
47
48
49
50
51
52
53
54
55
56
57
58
59
64
65
66
67
68
69
70
71
72
73
74
75
76
77
85
86
/* ... */
#include <string.h>
#include <stdbool.h>
#include "unity.h"
#include "unity_test_utils.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
#include "sdkconfig.h"8 includes
#if !CONFIG_FREERTOS_UNICORE
#include "esp_ipc.h"
#include "esp_freertos_hooks.h"/* ... */
#endif
#if !CONFIG_FREERTOS_UNICORE
static StaticSemaphore_t s_test_sem_buffer;
static SemaphoreHandle_t s_test_sem = NULL;
static bool idle_hook_func(void)
{
if (s_test_sem) {
xSemaphoreGive(s_test_sem);
}{...}
return true;
}{ ... }
static void task_delete_func(void *arg)
{
vTaskDelete(arg);
}{ ... }
#define SEMAPHORE_COUNT_MAX 2
#define SEMAPHORE_COUNT_INITIAL 0
/* ... */
#endif
void unity_utils_task_delete(TaskHandle_t thandle)
{
/* ... */
TEST_ASSERT_NOT_NULL_MESSAGE(thandle, "unity_utils_task_delete: handle is NULL");
TEST_ASSERT_NOT_EQUAL_MESSAGE(thandle, xTaskGetCurrentTaskHandle(), "unity_utils_task_delete: handle is of currently executing task");
#if CONFIG_FREERTOS_UNICORE
vTaskDelete(thandle);
#else
const BaseType_t tsk_affinity = xTaskGetCoreID(thandle);
const BaseType_t core_id = xPortGetCoreID();
printf("Task_affinity: 0x%x, current_core: %d\n", tsk_affinity, core_id);
if (tsk_affinity == tskNO_AFFINITY) {
if (s_test_sem == NULL) {
s_test_sem = xSemaphoreCreateCountingStatic(SEMAPHORE_COUNT_MAX, SEMAPHORE_COUNT_INITIAL, &s_test_sem_buffer);
}{...} else {
while (xSemaphoreTake(s_test_sem, 0) == pdTRUE) { }
}{...}
esp_err_t ret = esp_register_freertos_idle_hook_for_cpu(idle_hook_func, !core_id);
TEST_ASSERT_EQUAL_MESSAGE(ret, ESP_OK, "unity_utils_task_delete: failed to register idle hook");
vTaskDelete(thandle);
xSemaphoreTake(s_test_sem, portMAX_DELAY);
xSemaphoreTake(s_test_sem, portMAX_DELAY);
esp_deregister_freertos_idle_hook_for_cpu(idle_hook_func, !core_id);
}{...} else if (tsk_affinity != core_id) {
/* ... */
esp_ipc_call_blocking(tsk_affinity, task_delete_func, thandle);
}{...} else {
vTaskDelete(thandle);
}{...}
/* ... */#endif
}{ ... }