OpenOCD
linuxspidev.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /* Copyright (C) 2020 by Lup Yuen Lee <luppy@appkaki.com>
4  * Copyright (C) 2024 by Richard Pasek <rpasek@google.com>
5  */
6 
12 /* Uncomment to log SPI exchanges (very verbose, slows things down a lot)
13  *
14  * A quick note on interpreting SPI exchange messages:
15  *
16  * This implementation works by performing SPI exchanges with MOSI and MISO
17  * tied together with a 1K resistor. This combined signal becomes SWDIO.
18  *
19  * Since we are performing SPI exchanges, (reading and writing at the same
20  * time) this means when the target isn't driving SWDIO, what is written by
21  * the host should also be read by the host.
22  *
23  * On SWD writes:
24  * The TX and RX data should match except for the ACK bits from the target
25  * swd write reg exchange: len=6
26  * tx_buf=C5 02 40 00 02 2C
27  * rx_buf=C5 42 40 00 02 2C
28  * ^
29  * |
30  * ACK from target
31  *
32  * On SWD reads:
33  * Only the command byte should match
34  * swd read reg exchange: len=6
35  * tx_buf=B1 00 00 00 00 00
36  * rx_buf=B1 40 20 00 00 F8
37  * ^^
38  * ||
39  * Command packet from host
40  *
41  */
42 // #define LOG_SPI_EXCHANGE
43 
44 #ifdef HAVE_CONFIG_H
45 #include "config.h"
46 #endif
47 
48 #include <stdint.h>
49 #include <unistd.h>
50 #include <stdlib.h>
51 #include <string.h>
52 #include <fcntl.h>
53 #include <sys/ioctl.h>
54 #include <linux/spi/spidev.h>
55 #include <jtag/adapter.h>
56 #include <jtag/swd.h>
57 #include <jtag/interface.h>
58 #include <jtag/commands.h>
59 
60 // Number of bits per SPI exchange
61 #define SPI_BITS 8
62 
63 // Time in uS after the last bit of transfer before deselecting the device
64 #define SPI_DESELECT_DELAY 0
65 
66 // Maximum number of SWD transactions to queue together in a SPI exchange
67 #define MAX_QUEUE_ENTRIES 64
68 
69 #define CMD_BITS 8
70 #define TURN_BITS 1
71 #define ACK_BITS 3
72 #define DATA_BITS 32
73 #define PARITY_BITS 1
74 
75 #define SWD_WR_BITS (CMD_BITS + TURN_BITS + ACK_BITS + TURN_BITS + DATA_BITS + PARITY_BITS)
76 #define SWD_RD_BITS (CMD_BITS + TURN_BITS + ACK_BITS + DATA_BITS + PARITY_BITS + TURN_BITS)
77 #define SWD_OP_BITS (MAX(SWD_WR_BITS, SWD_RD_BITS))
78 #define SWD_OP_BYTES (DIV_ROUND_UP(SWD_OP_BITS, SPI_BITS))
79 
80 #define AP_DELAY_CLOCKS 8
81 #define AP_DELAY_BYTES (DIV_ROUND_UP(AP_DELAY_CLOCKS, SPI_BITS))
82 
83 #define END_IDLE_CLOCKS 8
84 #define END_IDLE_BYTES (DIV_ROUND_UP(END_IDLE_CLOCKS, SPI_BITS))
85 
86 // File descriptor for SPI device
87 static int spi_fd = -1;
88 
89 // SPI Configuration
90 static char *spi_path;
91 static uint32_t spi_mode = SPI_MODE_3; // Note: SPI in LSB mode is not often supported. We'll flip LSB to MSB ourselves.
92 static uint32_t spi_speed;
93 
94 struct queue_info {
95  unsigned int buf_idx;
96  uint32_t *rx_ptr;
97 };
98 
99 static int queue_retval;
100 static unsigned int max_queue_entries;
101 static unsigned int queue_fill;
102 static unsigned int queue_buf_fill;
103 static unsigned int queue_buf_size;
104 static struct queue_info *queue_infos;
105 static uint8_t *queue_tx_buf;
106 static uint8_t *queue_rx_buf;
107 static uint8_t *tx_flip_buf;
108 
109 static int spidev_swd_switch_seq(enum swd_special_seq seq);
110 static void spidev_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk);
111 
112 static void spi_exchange(const uint8_t *tx_data, uint8_t *rx_data, unsigned int len)
113 {
114 #ifdef LOG_SPI_EXCHANGE
115  LOG_OUTPUT("exchange: len=%u\n", len);
116 #endif // LOG_SPI_EXCHANGE
117 
118  if (len == 0) {
119  LOG_DEBUG("exchange with no length");
120  return;
121  }
122 
123  if (!tx_data && !rx_data) {
124  LOG_DEBUG("exchange with no valid tx or rx pointers");
125  return;
126  }
127 
128  if (len > queue_buf_size) {
129  LOG_ERROR("exchange too large len=%u ", len);
130  return;
131  }
132 
133  if (tx_data) {
134  // Reverse LSB to MSB
135  for (unsigned int i = 0; i < len; i++)
136  tx_flip_buf[i] = flip_u32(tx_data[i], 8);
137 
138 #ifdef LOG_SPI_EXCHANGE
139  if (len != 0) {
140  LOG_OUTPUT(" tx_buf=");
141  for (unsigned int i = 0; i < len; i++)
142  LOG_OUTPUT("%.2" PRIx8 " ", tx_flip_buf[i]);
143  }
144  LOG_OUTPUT("\n");
145 #endif // LOG_SPI_EXCHANGE
146  }
147  // Transmit the MSB buffer to SPI device.
148  struct spi_ioc_transfer tr = {
149  /* The following must be cast to unsigned long to compile correctly on
150  * 32 and 64 bit machines (as is done in the spidev examples in Linux
151  * kernel code in tools/spi/).
152  */
153  .tx_buf = (unsigned long)(tx_data ? tx_flip_buf : NULL),
154  .rx_buf = (unsigned long)rx_data,
155  .len = len,
156  .delay_usecs = SPI_DESELECT_DELAY,
157  .speed_hz = spi_speed,
158  .bits_per_word = SPI_BITS,
159  };
160  int ret = ioctl(spi_fd, SPI_IOC_MESSAGE(1), &tr);
161 
162  if (ret < 1) {
163  LOG_ERROR("exchange failed");
164  return;
165  }
166 
167  if (rx_data) {
168 #ifdef LOG_SPI_EXCHANGE
169  if (len != 0) {
170  LOG_OUTPUT(" rx_buf=");
171  for (unsigned int i = 0; i < len; i++)
172  LOG_OUTPUT("%.2" PRIx8 " ", rx_data[i]);
173  }
174  LOG_OUTPUT("\n");
175 #endif // LOG_SPI_EXCHANGE
176 
177  // Reverse MSB to LSB
178  for (unsigned int i = 0; i < len; i++)
179  rx_data[i] = flip_u32(rx_data[i], 8);
180  }
181 }
182 
183 static int spidev_speed(int speed)
184 {
185  uint32_t tmp_speed = speed;
186 
187  int ret = ioctl(spi_fd, SPI_IOC_WR_MAX_SPEED_HZ, &tmp_speed);
188  if (ret == -1) {
189  LOG_ERROR("Failed to set SPI %d speed", speed);
190  return ERROR_FAIL;
191  }
192 
193  spi_speed = speed;
194 
195  return ERROR_OK;
196 }
197 
198 static int spidev_speed_div(int speed, int *khz)
199 {
200  *khz = speed / 1000;
201  return ERROR_OK;
202 }
203 
204 static int spidev_khz(int khz, int *jtag_speed)
205 {
206  if (khz == 0) {
207  LOG_DEBUG("RCLK not supported");
208  return ERROR_FAIL;
209  }
210 
211  *jtag_speed = khz * 1000;
212  return ERROR_OK;
213 }
214 
215 static void spidev_free_queue(void)
216 {
217  max_queue_entries = 0;
218  queue_buf_size = 0;
219 
220  free(queue_infos);
221  queue_infos = NULL;
222 
223  free(queue_tx_buf);
224  queue_tx_buf = NULL;
225 
226  free(queue_rx_buf);
227  queue_rx_buf = NULL;
228 
229  free(tx_flip_buf);
230  tx_flip_buf = NULL;
231 }
232 
233 static void spidev_clear_queue(void)
234 {
235  queue_fill = 0;
236  queue_buf_fill = 0;
237 
238  memset(queue_infos, 0, sizeof(struct queue_info) * max_queue_entries);
239  memset(queue_tx_buf, 0, queue_buf_size);
240  memset(queue_rx_buf, 0, queue_buf_size);
241  memset(tx_flip_buf, 0, queue_buf_size);
242 }
243 
244 static int spidev_alloc_queue(unsigned int new_queue_entries)
245 {
246  if (queue_fill || queue_buf_fill) {
247  LOG_ERROR("Can't realloc queue when queue is in use");
248  return ERROR_FAIL;
249  }
250 
251  unsigned int new_queue_buf_size =
252  (new_queue_entries * (SWD_OP_BYTES + AP_DELAY_BYTES)) + END_IDLE_BYTES;
253 
254  queue_infos = realloc(queue_infos, sizeof(struct queue_info) * new_queue_entries);
255  if (!queue_infos)
256  goto realloc_fail;
257 
258  queue_tx_buf = realloc(queue_tx_buf, new_queue_buf_size);
259  if (!queue_tx_buf)
260  goto realloc_fail;
261 
262  queue_rx_buf = realloc(queue_rx_buf, new_queue_buf_size);
263  if (!queue_rx_buf)
264  goto realloc_fail;
265 
266  tx_flip_buf = realloc(tx_flip_buf, new_queue_buf_size);
267  if (!tx_flip_buf)
268  goto realloc_fail;
269 
270  max_queue_entries = new_queue_entries;
271  queue_buf_size = new_queue_buf_size;
272 
274 
275  LOG_DEBUG("Set queue entries to %u (buffers %u bytes)", max_queue_entries, queue_buf_size);
276 
277  return ERROR_OK;
278 
279 realloc_fail:
281 
282  LOG_ERROR("Couldn't allocate queue. Out of memory.");
283  return ERROR_FAIL;
284 }
285 
286 static int spidev_init(void)
287 {
288  LOG_INFO("SPI SWD driver");
289 
290  if (spi_fd >= 0)
291  return ERROR_OK;
292 
293  if (!spi_path) {
294  LOG_ERROR("Path to spidev not set");
295  return ERROR_JTAG_INIT_FAILED;
296  }
297 
298  // Open SPI device.
299  spi_fd = open(spi_path, O_RDWR);
300  if (spi_fd < 0) {
301  LOG_ERROR("Failed to open SPI port at %s", spi_path);
302  return ERROR_JTAG_INIT_FAILED;
303  }
304 
305  // Set SPI mode.
306  int ret = ioctl(spi_fd, SPI_IOC_WR_MODE32, &spi_mode);
307  if (ret == -1) {
308  LOG_ERROR("Failed to set SPI mode 0x%" PRIx32, spi_mode);
309  return ERROR_JTAG_INIT_FAILED;
310  }
311 
312  // Set SPI bits per word.
313  uint32_t spi_bits = SPI_BITS;
314  ret = ioctl(spi_fd, SPI_IOC_WR_BITS_PER_WORD, &spi_bits);
315  if (ret == -1) {
316  LOG_ERROR("Failed to set SPI %" PRIu8 " bits per transfer", spi_bits);
317  return ERROR_JTAG_INIT_FAILED;
318  }
319 
320  LOG_INFO("Opened SPI device at %s in mode 0x%" PRIx32 " with %" PRIu8 " bits ",
321  spi_path, spi_mode, spi_bits);
322 
323  if (max_queue_entries == 0) {
325  if (ret != ERROR_OK)
326  return ERROR_JTAG_INIT_FAILED;
327  }
328 
329  return ERROR_OK;
330 }
331 
332 static int spidev_quit(void)
333 {
335 
336  if (spi_fd < 0)
337  return ERROR_OK;
338 
339  close(spi_fd);
340  spi_fd = -1;
341 
342  free(spi_path);
343  spi_path = NULL;
344 
345  return ERROR_OK;
346 }
347 
348 static int spidev_swd_init(void)
349 {
350  LOG_DEBUG("spidev_swd_init");
351  return ERROR_OK;
352 }
353 
354 static int spidev_swd_execute_queue(unsigned int end_idle_bytes)
355 {
356  LOG_DEBUG_IO("Executing %u queued transactions", queue_fill);
357 
358  if (queue_retval != ERROR_OK) {
359  LOG_DEBUG_IO("Skipping due to previous errors: %d", queue_retval);
360  goto skip;
361  }
362 
363  /* A transaction must be followed by another transaction or at least 8 idle
364  * cycles to ensure that data is clocked through the AP. Since the tx
365  * buffer is zeroed after each queue run, every byte added to the buffer
366  * fill will add on an additional 8 idle cycles.
367  */
368  queue_buf_fill += end_idle_bytes;
369 
371 
372  for (unsigned int queue_idx = 0; queue_idx < queue_fill; queue_idx++) {
373  unsigned int buf_idx = queue_infos[queue_idx].buf_idx;
374  uint8_t *tx_ptr = &queue_tx_buf[buf_idx];
375  uint8_t *rx_ptr = &queue_rx_buf[buf_idx];
376  uint8_t cmd = buf_get_u32(tx_ptr, 0, CMD_BITS);
377  bool read = cmd & SWD_CMD_RNW ? true : false;
378  int ack = buf_get_u32(rx_ptr, CMD_BITS + TURN_BITS, ACK_BITS);
379  uint32_t data = read ?
382 
383  // Devices do not reply to DP_TARGETSEL write cmd, ignore received ack
384  bool check_ack = swd_cmd_returns_ack(cmd);
385 
386  LOG_CUSTOM_LEVEL((check_ack && ack != SWD_ACK_OK) ? LOG_LVL_DEBUG : LOG_LVL_DEBUG_IO,
387  "%s%s %s %s reg %X = %08" PRIx32,
388  check_ack ? "" : "ack ignored ",
389  ack == SWD_ACK_OK ? "OK" :
390  ack == SWD_ACK_WAIT ? "WAIT" :
391  ack == SWD_ACK_FAULT ? "FAULT" : "JUNK",
392  cmd & SWD_CMD_APNDP ? "AP" : "DP",
393  read ? "read" : "write",
394  (cmd & SWD_CMD_A32) >> 1,
395  data);
396 
397  if (ack != SWD_ACK_OK && check_ack) {
399  goto skip;
400 
401  } else if (read) {
403 
404  if (parity != parity_u32(data)) {
405  LOG_ERROR("SWD Read data parity mismatch");
407  goto skip;
408  }
409 
410  if (queue_infos[queue_idx].rx_ptr)
411  *queue_infos[queue_idx].rx_ptr = data;
412  }
413  }
414 
415 skip:
417 
418  int retval = queue_retval;
420 
421  return retval;
422 }
423 
424 static int spidev_swd_run_queue(void)
425 {
426  /* Since we are unsure if another SWD transaction will follow the
427  * transactions we are just about to execute, we need to add on 8 idle
428  * cycles.
429  */
431 }
432 
433 static void spidev_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk)
434 {
435  unsigned int swd_op_bytes = DIV_ROUND_UP(SWD_OP_BITS + ap_delay_clk, SPI_BITS);
436 
437  if (queue_fill >= max_queue_entries ||
438  queue_buf_fill + swd_op_bytes + END_IDLE_BYTES > queue_buf_size) {
439  /* Not enough room in the queue. Run the queue. No idle bytes are
440  * needed because we are going to execute transactions right after
441  * the queue is emptied.
442  */
444  }
445 
446  if (queue_retval != ERROR_OK)
447  return;
448 
449  uint8_t *tx_ptr = &queue_tx_buf[queue_buf_fill];
450 
452 
453  buf_set_u32(tx_ptr, 0, CMD_BITS, cmd);
454 
455  if (cmd & SWD_CMD_RNW) {
456  // Queue a read transaction
458  } else {
459  // Queue a write transaction
460  buf_set_u32(tx_ptr,
462  buf_set_u32(tx_ptr,
464  }
465 
467 
468  /* Add idle cycles after AP accesses to avoid WAIT. Buffer is already
469  * zeroed so we just need to advance the pointer to add idle cycles.
470  */
471  queue_buf_fill += swd_op_bytes;
472 
473  queue_fill++;
474 }
475 
476 static void spidev_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
477 {
478  assert(cmd & SWD_CMD_RNW);
479  spidev_swd_queue_cmd(cmd, value, 0, ap_delay_clk);
480 }
481 
482 static void spidev_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
483 {
484  assert(!(cmd & SWD_CMD_RNW));
485  spidev_swd_queue_cmd(cmd, NULL, value, ap_delay_clk);
486 }
487 
489 {
490  switch (seq) {
491  case LINE_RESET:
492  LOG_DEBUG_IO("SWD line reset");
494  break;
495  case JTAG_TO_SWD:
496  LOG_DEBUG("JTAG-to-SWD");
498  break;
499  case JTAG_TO_DORMANT:
500  LOG_DEBUG("JTAG-to-DORMANT");
502  break;
503  case SWD_TO_JTAG:
504  LOG_DEBUG("SWD-to-JTAG");
506  break;
507  case SWD_TO_DORMANT:
508  LOG_DEBUG("SWD-to-DORMANT");
510  break;
511  case DORMANT_TO_SWD:
512  LOG_DEBUG("DORMANT-to-SWD");
514  break;
515  case DORMANT_TO_JTAG:
516  LOG_DEBUG("DORMANT-to-JTAG");
518  break;
519  default:
520  LOG_ERROR("Sequence %d not supported", seq);
521  return ERROR_FAIL;
522  }
523 
524  return ERROR_OK;
525 }
526 
527 COMMAND_HANDLER(spidev_handle_path_command)
528 {
529  if (CMD_ARGC != 1)
531 
532  free(spi_path);
533  spi_path = strdup(CMD_ARGV[0]);
534  if (!spi_path) {
535  LOG_ERROR("Out of memory");
536  return ERROR_FAIL;
537  }
538 
539  return ERROR_OK;
540 }
541 
542 COMMAND_HANDLER(spidev_handle_mode_command)
543 {
544  if (CMD_ARGC != 1)
546 
548  return ERROR_OK;
549 }
550 
551 COMMAND_HANDLER(spidev_handle_queue_entries_command)
552 {
553  uint32_t new_queue_entries;
554 
555  if (CMD_ARGC != 1)
557 
558  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], new_queue_entries);
559 
560  return spidev_alloc_queue(new_queue_entries);
561 }
562 
563 const struct swd_driver spidev_swd = {
565  .switch_seq = spidev_swd_switch_seq,
566  .read_reg = spidev_swd_read_reg,
567  .write_reg = spidev_swd_write_reg,
568  .run = spidev_swd_run_queue,
569 };
570 
571 static const struct command_registration spidev_subcommand_handlers[] = {
572  {
573  .name = "path",
574  .handler = &spidev_handle_path_command,
575  .mode = COMMAND_CONFIG,
576  .help = "set the path to the spidev device",
577  .usage = "path_to_spidev",
578  },
579  {
580  .name = "mode",
581  .handler = &spidev_handle_mode_command,
582  .mode = COMMAND_CONFIG,
583  .help = "set the mode of the spi port with optional bit flags (default=3)",
584  .usage = "mode",
585  },
586  {
587  .name = "queue_entries",
588  .handler = &spidev_handle_queue_entries_command,
589  .mode = COMMAND_CONFIG,
590  .help = "set the queue entry size (default=64)",
591  .usage = "queue_entries",
592  },
594 };
595 
596 static const struct command_registration spidev_command_handlers[] = {
597  {
598  .name = "spidev",
599  .mode = COMMAND_ANY,
600  .help = "perform spidev management",
602  .usage = "",
603  },
605 };
606 
607 // Only SWD transport supported
608 static const char *const spidev_transports[] = { "swd", NULL };
609 
611  .name = "linuxspidev",
612  .transports = spidev_transports,
613  .commands = spidev_command_handlers,
614 
615  .init = spidev_init,
616  .quit = spidev_quit,
617  .speed = spidev_speed,
618  .khz = spidev_khz,
619  .speed_div = spidev_speed_div,
620 
621  .swd_ops = &spidev_swd,
622 };
#define SWD_ACK_FAULT
Definition: arm_adi_v5.h:33
swd_special_seq
Definition: arm_adi_v5.h:236
@ DORMANT_TO_JTAG
Definition: arm_adi_v5.h:243
@ JTAG_TO_SWD
Definition: arm_adi_v5.h:238
@ DORMANT_TO_SWD
Definition: arm_adi_v5.h:242
@ LINE_RESET
Definition: arm_adi_v5.h:237
@ JTAG_TO_DORMANT
Definition: arm_adi_v5.h:239
@ SWD_TO_DORMANT
Definition: arm_adi_v5.h:241
@ SWD_TO_JTAG
Definition: arm_adi_v5.h:240
#define SWD_ACK_WAIT
Definition: arm_adi_v5.h:32
#define SWD_ACK_OK
Definition: arm_adi_v5.h:31
uint32_t flip_u32(uint32_t value, unsigned int num)
Inverts the ordering of bits inside a 32-bit word (e.g.
Definition: binarybuffer.c:165
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
Definition: binarybuffer.h:104
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:34
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:156
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:402
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:151
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
Definition: command.h:442
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_ANY
Definition: command.h:42
#define ERROR_JTAG_INIT_FAILED
Definition: jtag.h:552
static const struct command_registration spidev_subcommand_handlers[]
Definition: linuxspidev.c:571
static int spi_fd
Definition: linuxspidev.c:87
#define SWD_OP_BITS
Definition: linuxspidev.c:77
#define END_IDLE_BYTES
Definition: linuxspidev.c:84
static void spidev_free_queue(void)
Definition: linuxspidev.c:215
static void spidev_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk)
Definition: linuxspidev.c:433
#define TURN_BITS
Definition: linuxspidev.c:70
static uint32_t spi_mode
Definition: linuxspidev.c:91
static void spidev_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
Definition: linuxspidev.c:482
static int spidev_swd_init(void)
Definition: linuxspidev.c:348
#define ACK_BITS
Definition: linuxspidev.c:71
static int spidev_alloc_queue(unsigned int new_queue_entries)
Definition: linuxspidev.c:244
static uint8_t * queue_tx_buf
Definition: linuxspidev.c:105
static int spidev_swd_execute_queue(unsigned int end_idle_bytes)
Definition: linuxspidev.c:354
#define DATA_BITS
Definition: linuxspidev.c:72
const struct swd_driver spidev_swd
Definition: linuxspidev.c:563
#define SWD_OP_BYTES
Definition: linuxspidev.c:78
static uint8_t * queue_rx_buf
Definition: linuxspidev.c:106
static void spidev_clear_queue(void)
Definition: linuxspidev.c:233
static int spidev_quit(void)
Definition: linuxspidev.c:332
COMMAND_HANDLER(spidev_handle_path_command)
Definition: linuxspidev.c:527
static int queue_retval
Definition: linuxspidev.c:99
static const char *const spidev_transports[]
Definition: linuxspidev.c:608
struct adapter_driver linuxspidev_adapter_driver
Definition: linuxspidev.c:610
#define AP_DELAY_BYTES
Definition: linuxspidev.c:81
static struct queue_info * queue_infos
Definition: linuxspidev.c:104
#define SPI_BITS
Definition: linuxspidev.c:61
static int spidev_khz(int khz, int *jtag_speed)
Definition: linuxspidev.c:204
static char * spi_path
Definition: linuxspidev.c:90
static unsigned int max_queue_entries
Definition: linuxspidev.c:100
#define MAX_QUEUE_ENTRIES
Definition: linuxspidev.c:67
static int spidev_init(void)
Definition: linuxspidev.c:286
static uint32_t spi_speed
Definition: linuxspidev.c:92
static int spidev_speed_div(int speed, int *khz)
Definition: linuxspidev.c:198
#define SPI_DESELECT_DELAY
Definition: linuxspidev.c:64
static uint8_t * tx_flip_buf
Definition: linuxspidev.c:107
static unsigned int queue_buf_fill
Definition: linuxspidev.c:102
static const struct command_registration spidev_command_handlers[]
Definition: linuxspidev.c:596
static int spidev_swd_switch_seq(enum swd_special_seq seq)
Definition: linuxspidev.c:488
static unsigned int queue_fill
Definition: linuxspidev.c:101
static int spidev_speed(int speed)
Definition: linuxspidev.c:183
static void spi_exchange(const uint8_t *tx_data, uint8_t *rx_data, unsigned int len)
Definition: linuxspidev.c:112
#define PARITY_BITS
Definition: linuxspidev.c:73
static unsigned int queue_buf_size
Definition: linuxspidev.c:103
static void spidev_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
Definition: linuxspidev.c:476
#define CMD_BITS
Definition: linuxspidev.c:69
static int spidev_swd_run_queue(void)
Definition: linuxspidev.c:424
#define LOG_CUSTOM_LEVEL(level, expr ...)
Definition: log.h:117
#define LOG_OUTPUT(expr ...)
Definition: log.h:141
#define LOG_DEBUG_IO(expr ...)
Definition: log.h:101
#define ERROR_FAIL
Definition: log.h:173
#define LOG_ERROR(expr ...)
Definition: log.h:132
#define LOG_INFO(expr ...)
Definition: log.h:126
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:167
@ LOG_LVL_DEBUG
Definition: log.h:47
@ LOG_LVL_DEBUG_IO
Definition: log.h:48
Represents a driver for a debugging interface.
Definition: interface.h:207
const char *const name
The name of the interface driver.
Definition: interface.h:209
const char * name
Definition: command.h:235
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:241
unsigned int buf_idx
Definition: linuxspidev.c:95
uint32_t * rx_ptr
Definition: linuxspidev.c:96
int(* init)(void)
Initialize the debug link so it can perform SWD operations.
Definition: swd.h:255
static const unsigned int swd_seq_dormant_to_swd_len
Definition: swd.h:190
static const uint8_t swd_seq_dormant_to_jtag[]
Dormant-to-JTAG sequence.
Definition: swd.h:230
#define SWD_CMD_A32
Definition: swd.h:19
static const uint8_t swd_seq_dormant_to_swd[]
Dormant-to-SWD sequence.
Definition: swd.h:171
static const uint8_t swd_seq_jtag_to_dormant[]
JTAG-to-dormant sequence.
Definition: swd.h:199
static bool swd_cmd_returns_ack(uint8_t cmd)
Test if we can rely on ACK returned by SWD command.
Definition: swd.h:58
#define SWD_CMD_PARK
Definition: swd.h:22
static int swd_ack_to_error_code(uint8_t ack)
Convert SWD ACK value returned from DP to OpenOCD error code.
Definition: swd.h:72
static const unsigned int swd_seq_jtag_to_swd_len
Definition: swd.h:125
static const unsigned int swd_seq_line_reset_len
Definition: swd.h:104
static const unsigned int swd_seq_dormant_to_jtag_len
Definition: swd.h:244
#define SWD_CMD_APNDP
Definition: swd.h:17
static const unsigned int swd_seq_swd_to_dormant_len
Definition: swd.h:159
#define SWD_CMD_START
Definition: swd.h:16
#define SWD_CMD_RNW
Definition: swd.h:18
static const uint8_t swd_seq_line_reset[]
SWD Line reset.
Definition: swd.h:98
static const uint8_t swd_seq_jtag_to_swd[]
JTAG-to-SWD sequence.
Definition: swd.h:115
static const uint8_t swd_seq_swd_to_jtag[]
SWD-to-JTAG sequence.
Definition: swd.h:136
static const unsigned int swd_seq_swd_to_jtag_len
Definition: swd.h:144
static const unsigned int swd_seq_jtag_to_dormant_len
Definition: swd.h:211
static const uint8_t swd_seq_swd_to_dormant[]
SWD-to-dormant sequence.
Definition: swd.h:153
#define true
Definition: system.h:66
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
Definition: types.h:79
static int parity_u32(uint32_t x)
Calculate the (even) parity of a 32-bit datum.
Definition: types.h:265
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1
static unsigned int parity(unsigned int v)
Definition: xscale.c:623