gcov: add gcov callback into the ipc task

This commit is contained in:
Erhan Kurubas
2021-06-29 13:12:01 +03:00
committed by bot
parent f6f7ab2e7f
commit ca88b269ed
4 changed files with 64 additions and 16 deletions

View File

@@ -31,7 +31,7 @@ static TaskHandle_t s_ipc_task_handle[portNUM_PROCESSORS];
static SemaphoreHandle_t s_ipc_mutex[portNUM_PROCESSORS]; // 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 ipc tasks
static SemaphoreHandle_t s_ipc_ack[portNUM_PROCESSORS]; // Semaphore used to acknowledge that task was woken up,
// or function has finished running
// or function has finished running
static volatile esp_ipc_func_t s_func[portNUM_PROCESSORS]; // Function which should be called by high priority task
static void * volatile s_func_arg[portNUM_PROCESSORS]; // Argument to pass into s_func
typedef enum {
@@ -43,6 +43,11 @@ static volatile esp_ipc_wait_t s_ipc_wait[portNUM_PROCESSORS];// This variable t
// s_ipc_ack semaphore: before s_func is called, or
// after it returns
#if CONFIG_APPTRACE_GCOV_ENABLE
static volatile esp_ipc_func_t s_gcov_func = NULL; // Gcov dump starter function which should be called by high priority task
static void * volatile s_gcov_func_arg; // Argument to pass into s_gcov_func
#endif
static void IRAM_ATTR ipc_task(void* arg)
{
const int cpuid = (int) arg;
@@ -56,16 +61,26 @@ static void IRAM_ATTR ipc_task(void* arg)
abort();
}
esp_ipc_func_t func = s_func[cpuid];
void* arg = s_func_arg[cpuid];
#if CONFIG_APPTRACE_GCOV_ENABLE
if (s_gcov_func) {
(*s_gcov_func)(s_gcov_func_arg);
s_gcov_func = NULL;
}
#endif
if (s_func[cpuid]) {
esp_ipc_func_t func = s_func[cpuid];
void* arg = s_func_arg[cpuid];
if (s_ipc_wait[cpuid] == IPC_WAIT_FOR_START) {
xSemaphoreGive(s_ipc_ack[cpuid]);
}
(*func)(arg);
if (s_ipc_wait[cpuid] == IPC_WAIT_FOR_END) {
xSemaphoreGive(s_ipc_ack[cpuid]);
if (s_ipc_wait[cpuid] == IPC_WAIT_FOR_START) {
xSemaphoreGive(s_ipc_ack[cpuid]);
}
(*func)(arg);
if (s_ipc_wait[cpuid] == IPC_WAIT_FOR_END) {
xSemaphoreGive(s_ipc_ack[cpuid]);
}
s_func[cpuid] = NULL;
}
}
// TODO: currently this is unreachable code. Introduce esp_ipc_uninit
// function which will signal to both tasks that they can shut down.
@@ -93,6 +108,7 @@ static void esp_ipc_init(void)
esp_ipc_isr_init();
#endif
char task_name[15];
for (int i = 0; i < portNUM_PROCESSORS; ++i) {
snprintf(task_name, sizeof(task_name), "ipc%d", i);
s_ipc_mutex[i] = xSemaphoreCreateMutex();
@@ -151,4 +167,19 @@ esp_err_t esp_ipc_call_blocking(uint32_t cpu_id, esp_ipc_func_t func, void* arg)
return esp_ipc_call_and_wait(cpu_id, func, arg, IPC_WAIT_FOR_END);
}
#endif // not CONFIG_FREERTOS_UNICORE
// currently this is only called from gcov component
#if CONFIG_APPTRACE_GCOV_ENABLE
esp_err_t esp_ipc_start_gcov_from_isr(uint32_t cpu_id, esp_ipc_func_t func, void* arg)
{
if (xTaskGetSchedulerState() != taskSCHEDULER_RUNNING) {
return ESP_ERR_INVALID_STATE;
}
s_gcov_func = func;
s_gcov_func_arg = arg;
xSemaphoreGiveFromISR(s_ipc_sem[cpu_id], NULL);
return ESP_OK;
}
#endif
#endif // not CONFIG_FREERTOS_UNICORE