2018-10-18 12:14:44 -04:00
|
|
|
/* Application Trace to Host Example
|
|
|
|
|
|
|
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, this
|
|
|
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
|
|
CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
*/
|
|
|
|
|
2023-12-13 17:32:53 -05:00
|
|
|
#include "sdkconfig.h"
|
2018-10-18 12:14:44 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2022-12-09 02:04:55 -05:00
|
|
|
#include <inttypes.h>
|
2018-10-18 12:14:44 -04:00
|
|
|
#include "esp_log.h"
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
2022-01-02 03:16:24 -05:00
|
|
|
#include "driver/gptimer.h"
|
2018-10-18 12:14:44 -04:00
|
|
|
|
|
|
|
static const char *TAG = "example";
|
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
#if CONFIG_APPTRACE_SV_ENABLE
|
2018-10-18 12:14:44 -04:00
|
|
|
#if !CONFIG_USE_CUSTOM_EVENT_ID
|
|
|
|
|
|
|
|
#define SYSVIEW_EXAMPLE_SEND_EVENT_ID 0
|
|
|
|
#define SYSVIEW_EXAMPLE_WAIT_EVENT_ID 1
|
|
|
|
|
|
|
|
#define SYSVIEW_EXAMPLE_SEND_EVENT_START() SEGGER_SYSVIEW_OnUserStart(SYSVIEW_EXAMPLE_SEND_EVENT_ID)
|
|
|
|
#define SYSVIEW_EXAMPLE_SEND_EVENT_END(_val_) SEGGER_SYSVIEW_OnUserStop(SYSVIEW_EXAMPLE_SEND_EVENT_ID)
|
|
|
|
#define SYSVIEW_EXAMPLE_WAIT_EVENT_START() SEGGER_SYSVIEW_OnUserStart(SYSVIEW_EXAMPLE_WAIT_EVENT_ID)
|
|
|
|
#define SYSVIEW_EXAMPLE_WAIT_EVENT_END(_val_) SEGGER_SYSVIEW_OnUserStop(SYSVIEW_EXAMPLE_WAIT_EVENT_ID)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define SYSVIEW_EXAMPLE_SEND_EVENT_START_ID 0
|
|
|
|
#define SYSVIEW_EXAMPLE_SEND_EVENT_END_ID 1
|
|
|
|
#define SYSVIEW_EXAMPLE_WAIT_EVENT_START_ID 2
|
|
|
|
#define SYSVIEW_EXAMPLE_WAIT_EVENT_END_ID 3
|
|
|
|
#define SYSVIEW_EXAMPLE_EVENT_MAX 4
|
|
|
|
|
|
|
|
#define SYSVIEW_EXAMPLE_SEND_EVENT_START() example_sysview_event_send(SYSVIEW_EXAMPLE_SEND_EVENT_START_ID, 0)
|
|
|
|
#define SYSVIEW_EXAMPLE_SEND_EVENT_END(_val_) example_sysview_event_send(SYSVIEW_EXAMPLE_SEND_EVENT_END_ID, _val_)
|
|
|
|
#define SYSVIEW_EXAMPLE_WAIT_EVENT_START() example_sysview_event_send(SYSVIEW_EXAMPLE_WAIT_EVENT_START_ID, 0)
|
|
|
|
#define SYSVIEW_EXAMPLE_WAIT_EVENT_END(_val_) example_sysview_event_send(SYSVIEW_EXAMPLE_WAIT_EVENT_END_ID, _val_)
|
|
|
|
|
|
|
|
static void example_sysview_module_send_desc(void);
|
|
|
|
|
|
|
|
static SEGGER_SYSVIEW_MODULE s_example_sysview_module = {
|
|
|
|
.sModule = "example_sysview_module",
|
|
|
|
.NumEvents = SYSVIEW_EXAMPLE_EVENT_MAX,
|
|
|
|
.pfSendModuleDesc = example_sysview_module_send_desc,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void example_sysview_module_send_desc(void)
|
|
|
|
{
|
|
|
|
SEGGER_SYSVIEW_RecordModuleDescription(&s_example_sysview_module, "Example SystemView User Module");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void example_sysview_event_send(uint32_t id, uint32_t val)
|
|
|
|
{
|
|
|
|
U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32];
|
|
|
|
|
2021-07-15 01:55:19 -04:00
|
|
|
U8 *pPayload = SEGGER_SYSVIEW_PREPARE_PACKET(aPacket);
|
2018-10-18 12:14:44 -04:00
|
|
|
pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, val); // Add the parameter to the packet
|
|
|
|
SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, s_example_sysview_module.EventOffset + id);
|
|
|
|
}
|
|
|
|
|
2022-01-02 03:16:24 -05:00
|
|
|
#endif // !CONFIG_USE_CUSTOM_EVENT_ID
|
2018-10-18 12:14:44 -04:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define SYSVIEW_EXAMPLE_SEND_EVENT_START()
|
|
|
|
#define SYSVIEW_EXAMPLE_SEND_EVENT_END(_val_)
|
|
|
|
#define SYSVIEW_EXAMPLE_WAIT_EVENT_START()
|
|
|
|
#define SYSVIEW_EXAMPLE_WAIT_EVENT_END(_val_)
|
|
|
|
|
2022-01-02 03:16:24 -05:00
|
|
|
#endif // CONFIG_APPTRACE_SV_ENABLE
|
2018-10-18 12:14:44 -04:00
|
|
|
|
2022-01-02 03:16:24 -05:00
|
|
|
typedef struct {
|
|
|
|
gptimer_handle_t gptimer;
|
|
|
|
int count;
|
|
|
|
TaskHandle_t thnd;
|
|
|
|
uint64_t period;
|
|
|
|
char task_name[32];
|
|
|
|
} example_event_data_t;
|
2018-10-18 12:14:44 -04:00
|
|
|
|
2022-01-02 03:16:24 -05:00
|
|
|
static bool example_timer_alarm_cb(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_ctx)
|
2018-10-18 12:14:44 -04:00
|
|
|
{
|
2022-01-02 03:16:24 -05:00
|
|
|
example_event_data_t *tim_arg = (example_event_data_t *)user_ctx;
|
|
|
|
bool need_yield = false;
|
2018-10-18 12:14:44 -04:00
|
|
|
|
|
|
|
if (tim_arg->thnd != NULL) {
|
|
|
|
if (tim_arg->count++ < 10) {
|
|
|
|
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
|
|
|
SYSVIEW_EXAMPLE_SEND_EVENT_START();
|
|
|
|
if (xTaskNotifyFromISR(tim_arg->thnd, tim_arg->count, eSetValueWithOverwrite, &xHigherPriorityTaskWoken) != pdPASS) {
|
|
|
|
ESP_EARLY_LOGE(TAG, "Failed to notify task %p", tim_arg->thnd);
|
|
|
|
} else {
|
|
|
|
SYSVIEW_EXAMPLE_SEND_EVENT_END(tim_arg->count);
|
|
|
|
if (xHigherPriorityTaskWoken == pdTRUE) {
|
2022-01-02 03:16:24 -05:00
|
|
|
need_yield = true;
|
2018-10-18 12:14:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-02 03:16:24 -05:00
|
|
|
return need_yield;
|
2018-10-18 12:14:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void example_task(void *p)
|
|
|
|
{
|
2022-01-02 03:16:24 -05:00
|
|
|
uint32_t event_val;
|
2018-10-18 12:14:44 -04:00
|
|
|
example_event_data_t *arg = (example_event_data_t *) p;
|
|
|
|
ESP_LOGI(TAG, "%p: run task", xTaskGetCurrentTaskHandle());
|
2022-01-02 03:16:24 -05:00
|
|
|
gptimer_alarm_config_t alarm_config = {
|
|
|
|
.reload_count = 0,
|
|
|
|
.alarm_count = arg->period,
|
|
|
|
.flags.auto_reload_on_alarm = true,
|
|
|
|
};
|
|
|
|
// This task is pinned to a specific core, to the interrupt will also be install to that core
|
|
|
|
gptimer_event_callbacks_t cbs = {
|
|
|
|
.on_alarm = example_timer_alarm_cb,
|
|
|
|
};
|
|
|
|
ESP_ERROR_CHECK(gptimer_register_event_callbacks(arg->gptimer, &cbs, arg));
|
|
|
|
ESP_ERROR_CHECK(gptimer_set_alarm_action(arg->gptimer, &alarm_config));
|
2022-04-23 06:59:38 -04:00
|
|
|
ESP_ERROR_CHECK(gptimer_enable(arg->gptimer));
|
2022-01-02 03:16:24 -05:00
|
|
|
ESP_ERROR_CHECK(gptimer_start(arg->gptimer));
|
2018-10-18 12:14:44 -04:00
|
|
|
while (1) {
|
|
|
|
SYSVIEW_EXAMPLE_WAIT_EVENT_START();
|
|
|
|
xTaskNotifyWait(0, 0, &event_val, portMAX_DELAY);
|
|
|
|
SYSVIEW_EXAMPLE_WAIT_EVENT_END(event_val);
|
2022-12-09 02:04:55 -05:00
|
|
|
ESP_LOGI(TAG, "Task[%p]: received event %"PRIu32, xTaskGetCurrentTaskHandle(), event_val);
|
2018-10-18 12:14:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-16 05:33:30 -04:00
|
|
|
void app_main(void)
|
2018-10-18 12:14:44 -04:00
|
|
|
{
|
2023-12-13 17:32:53 -05:00
|
|
|
static example_event_data_t event_data[CONFIG_FREERTOS_NUMBER_OF_CORES];
|
2018-10-18 12:14:44 -04:00
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
#if CONFIG_APPTRACE_SV_ENABLE && CONFIG_USE_CUSTOM_EVENT_ID
|
2018-10-18 12:14:44 -04:00
|
|
|
// Currently OpenOCD does not support requesting module info from target. So do the following...
|
2018-12-12 12:35:17 -05:00
|
|
|
// Wait untill SystemView module receives START command from host,
|
|
|
|
// after that data can be sent to the host using onboard API,
|
|
|
|
// so user module description does not need to be requested by OpenOCD itself.
|
2021-07-15 01:55:19 -04:00
|
|
|
while (!SEGGER_SYSVIEW_Started()) {
|
2018-12-12 12:35:17 -05:00
|
|
|
vTaskDelay(1);
|
|
|
|
}
|
2018-10-18 12:14:44 -04:00
|
|
|
SEGGER_SYSVIEW_RegisterModule(&s_example_sysview_module);
|
|
|
|
#endif
|
|
|
|
|
2023-12-13 17:32:53 -05:00
|
|
|
for (int i = 0; i < CONFIG_FREERTOS_NUMBER_OF_CORES; i++) {
|
2022-01-02 03:16:24 -05:00
|
|
|
gptimer_config_t timer_config = {
|
2022-04-13 01:12:30 -04:00
|
|
|
.clk_src = GPTIMER_CLK_SRC_DEFAULT,
|
2022-01-02 03:16:24 -05:00
|
|
|
.direction = GPTIMER_COUNT_UP,
|
|
|
|
.resolution_hz = 1000000,
|
|
|
|
};
|
|
|
|
ESP_ERROR_CHECK(gptimer_new_timer(&timer_config, &event_data[i].gptimer));
|
|
|
|
event_data[i].period = 1000000 * (i + 1);
|
|
|
|
}
|
2018-10-18 12:14:44 -04:00
|
|
|
|
2023-12-13 17:32:53 -05:00
|
|
|
for (int i = 0; i < CONFIG_FREERTOS_NUMBER_OF_CORES; i++) {
|
2022-01-02 03:16:24 -05:00
|
|
|
sprintf(event_data->task_name, "svtrace%d", i);
|
|
|
|
xTaskCreatePinnedToCore(example_task, event_data->task_name, 4096, &event_data[i], 3, &event_data[i].thnd, i);
|
|
|
|
ESP_LOGI(TAG, "Created task %p", event_data[i].thnd);
|
|
|
|
}
|
2018-10-18 12:14:44 -04:00
|
|
|
}
|