- idx = 2;
- uint8_t ack = buffer[idx] & 0x07;
- if (ack != SWD_ACK_OK || (buffer[idx] & 0x08)) {
- LOG_DEBUG("SWD ack not OK: %d %s", buffer[idx-1],
+ 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);
+
+ return;
+
+skip:
+ block->transfer_count = 0;
+}
+
+static void cmsis_dap_swd_read_process(struct cmsis_dap *dap, int timeout_ms)
+{
+ uint8_t *buffer = dap->packet_buffer;
+ struct pending_request_block *block = &pending_fifo[pending_fifo_get_idx];
+
+ if (pending_fifo_block_count == 0)
+ LOG_ERROR("no pending write");
+
+ /* get reply */
+ int retval = hid_read_timeout(dap->dev_handle, dap->packet_buffer, dap->packet_size, timeout_ms);
+ if (retval == 0 && timeout_ms < USB_TIMEOUT)
+ return;
+
+ if (retval == -1 || retval == 0) {
+ LOG_DEBUG("error reading data: %ls", hid_error(dap->dev_handle));
+ queued_retval = ERROR_FAIL;
+ goto skip;
+ }
+
+ if (buffer[2] & 0x08) {
+ LOG_DEBUG("CMSIS-DAP Protocol Error @ %d (wrong parity)", buffer[1]);
+ queued_retval = ERROR_FAIL;
+ goto skip;
+ }
+ uint8_t ack = buffer[2] & 0x07;
+ if (ack != SWD_ACK_OK) {
+ LOG_DEBUG("SWD ack not OK @ %d %s", buffer[1],