1 /*
2 * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include "esp_log.h"
8 #include "esp_check.h"
9 #include "esp_heap_caps.h"
10 #include "esp_systick_etm.h"
11 #include "soc/soc_caps.h"
12 #include "soc/soc_etm_source.h"
13 #include "esp_private/systimer.h"
14 #include "esp_private/etm_interface.h"
15
16 #define ETM_MEM_ALLOC_CAPS MALLOC_CAP_DEFAULT
17
18 static const char *TAG = "systick-etm";
19
systick_etm_event_del(esp_etm_event_t * event)20 static esp_err_t systick_etm_event_del(esp_etm_event_t *event)
21 {
22 free(event);
23 return ESP_OK;
24 }
25
esp_systick_new_etm_alarm_event(int core_id,esp_etm_event_handle_t * out_event)26 esp_err_t esp_systick_new_etm_alarm_event(int core_id, esp_etm_event_handle_t *out_event)
27 {
28 esp_etm_event_t *event = NULL;
29 esp_err_t ret = ESP_OK;
30 ESP_GOTO_ON_FALSE(out_event && core_id < SOC_CPU_CORES_NUM, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument");
31 event = heap_caps_calloc(1, sizeof(esp_etm_event_t), ETM_MEM_ALLOC_CAPS);
32 ESP_GOTO_ON_FALSE(event, ESP_ERR_NO_MEM, err, TAG, "no memory for ETM event");
33
34 // fill the ETM event object
35 uint32_t event_id = SYSTIMER_EVT_CNT_CMP0 + SYSTIMER_ALARM_OS_TICK_CORE0 + core_id;
36 event->event_id = event_id;
37 event->trig_periph = ETM_TRIG_PERIPH_SYSTIMER;
38 event->del = systick_etm_event_del;
39 *out_event = event;
40 return ESP_OK;
41
42 err:
43 if (event) {
44 systick_etm_event_del(event);
45 }
46 return ret;
47 }
48