|
From: openocd-gerrit <ope...@us...> - 2023-01-15 15:08:08
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via a9b48a6f481344c592e7e05ca06564cdadfe0721 (commit)
via 128736d23f0e92a245d51c10e889ed3e6da4c2b1 (commit)
from 9dac3b247b43d8b91821560b7c99fbd33d736419 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit a9b48a6f481344c592e7e05ca06564cdadfe0721
Author: Tomas Vanek <va...@fb...>
Date: Sat Nov 19 07:08:32 2022 +0100
jtag/drivers/cmsis_dap: use dap parameter instead of cmsis_dap_handle
Replace the direct dereference of cmsis_dap_handle by dereference
of the dap function parameter wherever possible.
Signed-off-by: Tomas Vanek <va...@fb...>
Change-Id: I32601dbe0270267642720a8524706aa76d187c3b
Reviewed-on: https://review.openocd.org/c/openocd/+/7361
Tested-by: jenkins
Reviewed-by: Antonio Borneo <bor...@gm...>
diff --git a/src/jtag/drivers/cmsis_dap.c b/src/jtag/drivers/cmsis_dap.c
index c2f01f33d..49181ad90 100644
--- a/src/jtag/drivers/cmsis_dap.c
+++ b/src/jtag/drivers/cmsis_dap.c
@@ -290,14 +290,15 @@ static void cmsis_dap_close(struct cmsis_dap *dap)
dap->backend = NULL;
}
- free(cmsis_dap_handle->packet_buffer);
- free(cmsis_dap_handle);
- cmsis_dap_handle = NULL;
+ free(dap->packet_buffer);
for (int i = 0; i < MAX_PENDING_REQUESTS; i++) {
free(dap->pending_fifo[i].transfers);
dap->pending_fifo[i].transfers = NULL;
}
+
+ free(cmsis_dap_handle);
+ cmsis_dap_handle = NULL;
}
static void cmsis_dap_flush_read(struct cmsis_dap *dap)
@@ -328,7 +329,7 @@ static int cmsis_dap_xfer(struct cmsis_dap *dap, int txlen)
dap->pending_fifo_get_idx = 0;
}
- uint8_t current_cmd = cmsis_dap_handle->command[0];
+ uint8_t current_cmd = dap->command[0];
int retval = dap->backend->write(dap, txlen, LIBUSB_TIMEOUT_MS);
if (retval < 0)
return retval;
@@ -338,7 +339,7 @@ static int cmsis_dap_xfer(struct cmsis_dap *dap, int txlen)
if (retval < 0)
return retval;
- uint8_t *resp = cmsis_dap_handle->response;
+ uint8_t *resp = dap->response;
if (resp[0] == DAP_ERROR) {
LOG_ERROR("CMSIS-DAP command 0x%" PRIx8 " not implemented", current_cmd);
return ERROR_NOT_IMPLEMENTED;
@@ -743,7 +744,7 @@ static int cmsis_dap_cmd_dap_swo_data(
static void cmsis_dap_swd_write_from_queue(struct cmsis_dap *dap)
{
- uint8_t *command = cmsis_dap_handle->command;
+ uint8_t *command = dap->command;
struct pending_request_block *block = &dap->pending_fifo[dap->pending_fifo_put_idx];
LOG_DEBUG_IO("Executing %d queued transactions from FIFO index %u",
commit 128736d23f0e92a245d51c10e889ed3e6da4c2b1
Author: Tomas Vanek <va...@fb...>
Date: Sat Nov 19 06:57:56 2022 +0100
jtag/drivers/cmsis_dap: move pending request FIFO
Move all pending request FIFO related variables to
the struct cmsis_dap
Pure refactoring, no functional changes.
Signed-off-by: Tomas Vanek <va...@fb...>
Change-Id: I2cea9c1e265ac102ec0f314767b8b9afdcda9ee9
Reviewed-on: https://review.openocd.org/c/openocd/+/7360
Tested-by: jenkins
Reviewed-by: Antonio Borneo <bor...@gm...>
diff --git a/src/jtag/drivers/cmsis_dap.c b/src/jtag/drivers/cmsis_dap.c
index 44a7dd8cb..c2f01f33d 100644
--- a/src/jtag/drivers/cmsis_dap.c
+++ b/src/jtag/drivers/cmsis_dap.c
@@ -209,17 +209,6 @@ static const char * const info_caps_str[INFO_CAPS__NUM_CAPS] = {
"UART via USB COM port supported",
};
-struct pending_transfer_result {
- uint8_t cmd;
- uint32_t data;
- void *buffer;
-};
-
-struct pending_request_block {
- struct pending_transfer_result *transfers;
- int transfer_count;
-};
-
struct pending_scan_result {
/** Offset in bytes in the CMD_DAP_JTAG_SEQ response buffer. */
unsigned first;
@@ -231,16 +220,8 @@ struct pending_scan_result {
unsigned buffer_offset;
};
-/* Up to MIN(packet_count, MAX_PENDING_REQUESTS) requests may be issued
- * until the first response arrives */
-#define MAX_PENDING_REQUESTS 3
-
-/* Pending requests are organized as a FIFO - circular buffer */
/* Each block in FIFO can contain up to pending_queue_len transfers */
static int pending_queue_len;
-static struct pending_request_block pending_fifo[MAX_PENDING_REQUESTS];
-static int pending_fifo_put_idx, pending_fifo_get_idx;
-static int pending_fifo_block_count;
/* pointers to buffers that will receive jtag scan results on the next flush */
#define MAX_PENDING_SCAN_RESULTS 256
@@ -314,8 +295,8 @@ static void cmsis_dap_close(struct cmsis_dap *dap)
cmsis_dap_handle = NULL;
for (int i = 0; i < MAX_PENDING_REQUESTS; i++) {
- free(pending_fifo[i].transfers);
- pending_fifo[i].transfers = NULL;
+ free(dap->pending_fifo[i].transfers);
+ dap->pending_fifo[i].transfers = NULL;
}
}
@@ -337,14 +318,14 @@ static void cmsis_dap_flush_read(struct cmsis_dap *dap)
/* Send a message and receive the reply */
static int cmsis_dap_xfer(struct cmsis_dap *dap, int txlen)
{
- if (pending_fifo_block_count) {
- LOG_ERROR("pending %d blocks, flushing", pending_fifo_block_count);
- while (pending_fifo_block_count) {
+ if (dap->pending_fifo_block_count) {
+ LOG_ERROR("pending %u blocks, flushing", dap->pending_fifo_block_count);
+ while (dap->pending_fifo_block_count) {
dap->backend->read(dap, 10);
- pending_fifo_block_count--;
+ dap->pending_fifo_block_count--;
}
- pending_fifo_put_idx = 0;
- pending_fifo_get_idx = 0;
+ dap->pending_fifo_put_idx = 0;
+ dap->pending_fifo_get_idx = 0;
}
uint8_t current_cmd = cmsis_dap_handle->command[0];
@@ -763,9 +744,10 @@ static int cmsis_dap_cmd_dap_swo_data(
static void cmsis_dap_swd_write_from_queue(struct cmsis_dap *dap)
{
uint8_t *command = cmsis_dap_handle->command;
- struct pending_request_block *block = &pending_fifo[pending_fifo_put_idx];
+ struct pending_request_block *block = &dap->pending_fifo[dap->pending_fifo_put_idx];
- LOG_DEBUG_IO("Executing %d queued transactions from FIFO index %d", block->transfer_count, pending_fifo_put_idx);
+ LOG_DEBUG_IO("Executing %d queued transactions from FIFO index %u",
+ block->transfer_count, dap->pending_fifo_put_idx);
if (queued_retval != ERROR_OK) {
LOG_DEBUG("Skipping due to previous errors: %d", queued_retval);
@@ -824,10 +806,10 @@ static void cmsis_dap_swd_write_from_queue(struct cmsis_dap *dap)
queued_retval = ERROR_OK;
}
- pending_fifo_put_idx = (pending_fifo_put_idx + 1) % dap->packet_count;
- pending_fifo_block_count++;
- if (pending_fifo_block_count > dap->packet_count)
- LOG_ERROR("too much pending writes %d", pending_fifo_block_count);
+ dap->pending_fifo_put_idx = (dap->pending_fifo_put_idx + 1) % dap->packet_count;
+ dap->pending_fifo_block_count++;
+ if (dap->pending_fifo_block_count > dap->packet_count)
+ LOG_ERROR("too much pending writes %u", dap->pending_fifo_block_count);
return;
@@ -837,9 +819,9 @@ skip:
static void cmsis_dap_swd_read_process(struct cmsis_dap *dap, int timeout_ms)
{
- struct pending_request_block *block = &pending_fifo[pending_fifo_get_idx];
+ struct pending_request_block *block = &dap->pending_fifo[dap->pending_fifo_get_idx];
- if (pending_fifo_block_count == 0)
+ if (dap->pending_fifo_block_count == 0)
LOG_ERROR("no pending write");
/* get reply */
@@ -880,8 +862,8 @@ static void cmsis_dap_swd_read_process(struct cmsis_dap *dap, int timeout_ms)
LOG_ERROR("CMSIS-DAP transfer count mismatch: expected %d, got %d",
block->transfer_count, transfer_count);
- LOG_DEBUG_IO("Received results of %d queued transactions FIFO index %d",
- transfer_count, pending_fifo_get_idx);
+ LOG_DEBUG_IO("Received results of %d queued transactions FIFO index %u timeout %i",
+ transfer_count, dap->pending_fifo_get_idx, timeout_ms);
size_t idx = 3;
for (int i = 0; i < transfer_count; i++) {
struct pending_transfer_result *transfer = &(block->transfers[i]);
@@ -907,22 +889,22 @@ static void cmsis_dap_swd_read_process(struct cmsis_dap *dap, int timeout_ms)
skip:
block->transfer_count = 0;
- pending_fifo_get_idx = (pending_fifo_get_idx + 1) % dap->packet_count;
- pending_fifo_block_count--;
+ dap->pending_fifo_get_idx = (dap->pending_fifo_get_idx + 1) % dap->packet_count;
+ dap->pending_fifo_block_count--;
}
static int cmsis_dap_swd_run_queue(void)
{
- if (pending_fifo_block_count)
+ if (cmsis_dap_handle->pending_fifo_block_count)
cmsis_dap_swd_read_process(cmsis_dap_handle, 0);
cmsis_dap_swd_write_from_queue(cmsis_dap_handle);
- while (pending_fifo_block_count)
+ while (cmsis_dap_handle->pending_fifo_block_count)
cmsis_dap_swd_read_process(cmsis_dap_handle, LIBUSB_TIMEOUT_MS);
- pending_fifo_put_idx = 0;
- pending_fifo_get_idx = 0;
+ cmsis_dap_handle->pending_fifo_put_idx = 0;
+ cmsis_dap_handle->pending_fifo_get_idx = 0;
int retval = queued_retval;
queued_retval = ERROR_OK;
@@ -934,15 +916,15 @@ static void cmsis_dap_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data)
{
bool targetsel_cmd = swd_cmd(false, false, DP_TARGETSEL) == cmd;
- if (pending_fifo[pending_fifo_put_idx].transfer_count == pending_queue_len
- || targetsel_cmd) {
- if (pending_fifo_block_count)
+ if (cmsis_dap_handle->pending_fifo[cmsis_dap_handle->pending_fifo_put_idx].transfer_count == pending_queue_len
+ || targetsel_cmd) {
+ if (cmsis_dap_handle->pending_fifo_block_count)
cmsis_dap_swd_read_process(cmsis_dap_handle, 0);
/* Not enough room in the queue. Run the queue. */
cmsis_dap_swd_write_from_queue(cmsis_dap_handle);
- if (pending_fifo_block_count >= cmsis_dap_handle->packet_count)
+ if (cmsis_dap_handle->pending_fifo_block_count >= cmsis_dap_handle->packet_count)
cmsis_dap_swd_read_process(cmsis_dap_handle, LIBUSB_TIMEOUT_MS);
}
@@ -954,7 +936,7 @@ static void cmsis_dap_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data)
return;
}
- struct pending_request_block *block = &pending_fifo[pending_fifo_put_idx];
+ struct pending_request_block *block = &cmsis_dap_handle->pending_fifo[cmsis_dap_handle->pending_fifo_put_idx];
struct pending_transfer_result *transfer = &(block->transfers[block->transfer_count]);
transfer->data = data;
transfer->cmd = cmd;
@@ -1231,17 +1213,18 @@ static int cmsis_dap_init(void)
goto init_err;
if (data[0] == 1) { /* byte */
- int pkt_cnt = data[1];
+ unsigned int pkt_cnt = data[1];
if (pkt_cnt > 1)
cmsis_dap_handle->packet_count = MIN(MAX_PENDING_REQUESTS, pkt_cnt);
- LOG_DEBUG("CMSIS-DAP: Packet Count = %d", pkt_cnt);
+ LOG_DEBUG("CMSIS-DAP: Packet Count = %u", pkt_cnt);
}
- LOG_DEBUG("Allocating FIFO for %d pending packets", cmsis_dap_handle->packet_count);
- for (int i = 0; i < cmsis_dap_handle->packet_count; i++) {
- pending_fifo[i].transfers = malloc(pending_queue_len * sizeof(struct pending_transfer_result));
- if (!pending_fifo[i].transfers) {
+ LOG_DEBUG("Allocating FIFO for %u pending packets", cmsis_dap_handle->packet_count);
+ for (unsigned int i = 0; i < cmsis_dap_handle->packet_count; i++) {
+ cmsis_dap_handle->pending_fifo[i].transfers = malloc(pending_queue_len
+ * sizeof(struct pending_transfer_result));
+ if (!cmsis_dap_handle->pending_fifo[i].transfers) {
LOG_ERROR("Unable to allocate memory for CMSIS-DAP queue");
retval = ERROR_FAIL;
goto init_err;
diff --git a/src/jtag/drivers/cmsis_dap.h b/src/jtag/drivers/cmsis_dap.h
index cf929b069..7eaa1f216 100644
--- a/src/jtag/drivers/cmsis_dap.h
+++ b/src/jtag/drivers/cmsis_dap.h
@@ -7,17 +7,37 @@
struct cmsis_dap_backend;
struct cmsis_dap_backend_data;
-struct command_registration;
+
+struct pending_transfer_result {
+ uint8_t cmd;
+ uint32_t data;
+ void *buffer;
+};
+
+/* Up to MIN(packet_count, MAX_PENDING_REQUESTS) requests may be issued
+ * until the first response arrives */
+#define MAX_PENDING_REQUESTS 4
+
+struct pending_request_block {
+ struct pending_transfer_result *transfers;
+ int transfer_count;
+};
struct cmsis_dap {
struct cmsis_dap_backend_data *bdata;
const struct cmsis_dap_backend *backend;
uint16_t packet_size;
- int packet_count;
uint8_t *packet_buffer;
uint16_t packet_buffer_size;
uint8_t *command;
uint8_t *response;
+
+ /* Pending requests are organized as a FIFO - circular buffer */
+ struct pending_request_block pending_fifo[MAX_PENDING_REQUESTS];
+ unsigned int packet_count;
+ unsigned int pending_fifo_put_idx, pending_fifo_get_idx;
+ unsigned int pending_fifo_block_count;
+
uint16_t caps;
uint8_t mode;
uint32_t swo_buf_sz;
-----------------------------------------------------------------------
Summary of changes:
src/jtag/drivers/cmsis_dap.c | 104 ++++++++++++++++++-------------------------
src/jtag/drivers/cmsis_dap.h | 24 +++++++++-
2 files changed, 66 insertions(+), 62 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|