mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
feat(esp_trace): add usb-serial-jtag as a transport channel
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_clk_tree.h"
|
||||
#include "esp_cpu.h"
|
||||
#include "esp_private/esp_clk.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
@@ -152,3 +154,104 @@ esp_err_t esp_trace_lock_give(esp_trace_lock_t *lock)
|
||||
portEXIT_CRITICAL(&lock->mux);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////// RING BUFFER //////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
static inline uint32_t rb_mask(const esp_trace_rb_t *rb)
|
||||
{
|
||||
return rb->max_size - 1;
|
||||
}
|
||||
|
||||
static inline void rb_advance_tail(esp_trace_rb_t *rb, uint32_t n)
|
||||
{
|
||||
rb->tail = (rb->tail + n) & rb_mask(rb);
|
||||
rb->count -= n;
|
||||
}
|
||||
|
||||
static inline void rb_advance_head(esp_trace_rb_t *rb, uint32_t n)
|
||||
{
|
||||
rb->head = (rb->head + n) & rb_mask(rb);
|
||||
rb->count += n;
|
||||
}
|
||||
|
||||
esp_err_t esp_trace_rb_init(esp_trace_rb_t *rb, uint32_t size)
|
||||
{
|
||||
rb->buffer = heap_caps_malloc(size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||
if (!rb->buffer) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
rb->max_size = size;
|
||||
rb->count = 0;
|
||||
rb->head = 0;
|
||||
rb->tail = 0;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_trace_rb_put(esp_trace_rb_t *rb, const uint8_t *data, uint32_t len)
|
||||
{
|
||||
/* Drop oldest data if needed to make room */
|
||||
uint32_t free_len = rb->max_size - rb->count;
|
||||
if (len > free_len) {
|
||||
rb_advance_tail(rb, len - free_len);
|
||||
}
|
||||
|
||||
uint32_t head = rb->head;
|
||||
uint32_t space_to_end = rb->max_size - head;
|
||||
|
||||
if (len <= space_to_end) {
|
||||
memcpy(&rb->buffer[head], data, len);
|
||||
} else {
|
||||
memcpy(&rb->buffer[head], data, space_to_end);
|
||||
memcpy(&rb->buffer[0], &data[space_to_end], len - space_to_end);
|
||||
}
|
||||
|
||||
rb_advance_head(rb, len);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
uint32_t esp_trace_rb_get(esp_trace_rb_t *rb, uint8_t *data, uint32_t len)
|
||||
{
|
||||
uint32_t available = rb->count;
|
||||
if (available == 0 || len == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t to_read = MIN(len, available);
|
||||
uint32_t tail = rb->tail;
|
||||
uint32_t cont = rb->max_size - tail;
|
||||
|
||||
if (to_read <= cont) {
|
||||
memcpy(data, &rb->buffer[tail], to_read);
|
||||
} else {
|
||||
memcpy(data, &rb->buffer[tail], cont);
|
||||
memcpy(&data[cont], &rb->buffer[0], to_read - cont);
|
||||
}
|
||||
|
||||
rb_advance_tail(rb, to_read);
|
||||
|
||||
return to_read;
|
||||
}
|
||||
|
||||
uint32_t esp_trace_rb_peek_contiguous(const esp_trace_rb_t *rb, const uint8_t **data)
|
||||
{
|
||||
uint32_t used = rb->count;
|
||||
if (used == 0) {
|
||||
*data = NULL;
|
||||
return 0;
|
||||
}
|
||||
*data = &rb->buffer[rb->tail];
|
||||
uint32_t contiguous = rb->max_size - rb->tail;
|
||||
return MIN(used, contiguous);
|
||||
}
|
||||
|
||||
void esp_trace_rb_consume(esp_trace_rb_t *rb, uint32_t len)
|
||||
{
|
||||
rb_advance_tail(rb, len);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user