OpenOCD
arm_tpiu_swo.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
11 /*
12  * Relevant specifications from ARM include:
13  *
14  * CoreSight(tm) Components Technical Reference Manual ARM DDI 0314H
15  * CoreSight(tm) TPIU-Lite Technical Reference Manual ARM DDI 0317A
16  * Cortex(tm)-M3 Technical Reference Manual ARM DDI 0337G
17  * Cortex(tm)-M4 Technical Reference Manual ARM DDI 0439B
18  * CoreSight(tm) SoC-400 Technical Reference Manual ARM DDI 0480F
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include <stdlib.h>
26 #include <jim.h>
27 
28 #include <helper/bits.h>
29 #include <helper/command.h>
30 #include <helper/jim-nvp.h>
31 #include <helper/list.h>
32 #include <helper/log.h>
33 #include <helper/types.h>
34 #include <jtag/interface.h>
35 #include <server/server.h>
36 #include <target/arm_adi_v5.h>
37 #include <target/target.h>
38 #include <transport/transport.h>
39 #include "arm_tpiu_swo.h"
40 
41 /* START_DEPRECATED_TPIU */
42 #include <target/cortex_m.h>
43 #define MSG "DEPRECATED \'tpiu config\' command: "
44 /* END_DEPRECATED_TPIU */
45 
46 #define TCP_SERVICE_NAME "tpiu_swo_trace"
47 
48 /* default for Cortex-M3 and Cortex-M4 specific TPIU */
49 #define TPIU_SWO_DEFAULT_BASE 0xE0040000
50 
51 #define TPIU_SSPSR_OFFSET 0x000
52 #define TPIU_CSPSR_OFFSET 0x004
53 #define TPIU_ACPR_OFFSET 0x010
54 #define TPIU_SPPR_OFFSET 0x0F0
55 #define TPIU_FFSR_OFFSET 0x300
56 #define TPIU_FFCR_OFFSET 0x304
57 #define TPIU_FSCR_OFFSET 0x308
58 #define TPIU_DEVID_OFFSET 0xfc8
59 
60 #define TPIU_ACPR_MAX_PRESCALER 0x1fff
61 #define TPIU_SPPR_PROTOCOL_SYNC (TPIU_PIN_PROTOCOL_SYNC)
62 #define TPIU_SPPR_PROTOCOL_MANCHESTER (TPIU_PIN_PROTOCOL_ASYNC_MANCHESTER)
63 #define TPIU_SPPR_PROTOCOL_UART (TPIU_PIN_PROTOCOL_ASYNC_UART)
64 #define TPIU_DEVID_NOSUPPORT_SYNC BIT(9)
65 #define TPIU_DEVID_SUPPORT_MANCHESTER BIT(10)
66 #define TPIU_DEVID_SUPPORT_UART BIT(11)
67 
73 };
74 
75 static const struct jim_nvp nvp_arm_tpiu_swo_event[] = {
76  { .value = TPIU_SWO_EVENT_PRE_ENABLE, .name = "pre-enable" },
77  { .value = TPIU_SWO_EVENT_POST_ENABLE, .name = "post-enable" },
78  { .value = TPIU_SWO_EVENT_PRE_DISABLE, .name = "pre-disable" },
79  { .value = TPIU_SWO_EVENT_POST_DISABLE, .name = "post-disable" },
80 };
81 
84  Jim_Interp *interp;
85  Jim_Obj *body;
87 };
88 
90  struct list_head lh;
91  struct adiv5_mem_ap_spot spot;
92  struct adiv5_ap *ap;
93  char *name;
95  /* record enable before init */
97  bool enabled;
98  bool en_capture;
101  uint32_t port_width;
102  FILE *file;
104  unsigned int pin_protocol;
108  unsigned int traceclkin_freq;
110  unsigned int swo_pin_freq;
114  struct list_head connections;
115  /* START_DEPRECATED_TPIU */
117  /* END_DEPRECATED_TPIU */
118 };
119 
121  struct list_head lh;
123 };
124 
127 };
128 
129 static LIST_HEAD(all_tpiu_swo);
130 
131 #define ARM_TPIU_SWO_TRACE_BUF_SIZE 4096
132 
133 static int arm_tpiu_swo_poll_trace(void *priv)
134 {
135  struct arm_tpiu_swo_object *obj = priv;
136  uint8_t buf[ARM_TPIU_SWO_TRACE_BUF_SIZE];
137  size_t size = sizeof(buf);
138  struct arm_tpiu_swo_connection *c;
139 
140  int retval = adapter_poll_trace(buf, &size);
141  if (retval != ERROR_OK || !size)
142  return retval;
143 
144  target_call_trace_callbacks(/*target*/NULL, size, buf);
145 
146  if (obj->file) {
147  if (fwrite(buf, 1, size, obj->file) == size) {
148  fflush(obj->file);
149  } else {
150  LOG_ERROR("Error writing to the SWO trace destination file");
151  return ERROR_FAIL;
152  }
153  }
154 
155  if (obj->out_filename[0] == ':')
157  if (connection_write(c->connection, buf, size) != (int)size)
158  LOG_ERROR("Error writing to connection"); /* FIXME: which connection? */
159 
160  return ERROR_OK;
161 }
162 
164 {
165  for (struct arm_tpiu_swo_event_action *ea = obj->event_action; ea; ea = ea->next) {
166  if (ea->event != event)
167  continue;
168 
169  LOG_DEBUG("TPIU/SWO: %s event: %s (%d) action : %s",
170  obj->name,
172  event,
173  Jim_GetString(ea->body, NULL));
174 
175  /* prevent event execution to change current target */
176  struct command_context *cmd_ctx = current_command_context(ea->interp);
177  struct target *saved_target = cmd_ctx->current_target;
178  int retval = Jim_EvalObj(ea->interp, ea->body);
179  cmd_ctx->current_target = saved_target;
180 
181  if (retval == JIM_RETURN)
182  retval = ea->interp->returnCode;
183  if (retval == JIM_OK || retval == ERROR_COMMAND_CLOSE_CONNECTION)
184  return ERROR_OK;
185 
186  Jim_MakeErrorMessage(ea->interp);
187  LOG_USER("Error executing event %s on TPIU/SWO %s:\n%s",
189  obj->name,
190  Jim_GetString(Jim_GetResult(ea->interp), NULL));
191  /* clean both error code and stacktrace before return */
192  Jim_Eval(ea->interp, "error \"\" \"\"");
193  return ERROR_FAIL;
194  }
195 
196  return ERROR_OK;
197 }
198 
200 {
201  if (obj->file) {
202  fclose(obj->file);
203  obj->file = NULL;
204  }
205  if (obj->out_filename[0] == ':')
207 }
208 
210 {
211  struct arm_tpiu_swo_object *obj, *tmp;
212 
213  list_for_each_entry_safe(obj, tmp, &all_tpiu_swo, lh) {
214  if (obj->enabled)
216 
218 
219  if (obj->en_capture) {
221 
222  int retval = adapter_config_trace(false, 0, 0, NULL, 0, NULL);
223  if (retval != ERROR_OK)
224  LOG_ERROR("Failed to stop adapter's trace");
225  }
226 
227  if (obj->enabled)
229 
230  struct arm_tpiu_swo_event_action *ea = obj->event_action;
231  while (ea) {
232  struct arm_tpiu_swo_event_action *next = ea->next;
233  Jim_DecrRefCount(ea->interp, ea->body);
234  free(ea);
235  ea = next;
236  }
237 
238  if (obj->ap)
239  dap_put_ap(obj->ap);
240 
241  free(obj->name);
242  free(obj->out_filename);
243  free(obj);
244  }
245 
246  return ERROR_OK;
247 }
248 
250 {
252  struct arm_tpiu_swo_object *obj = priv->obj;
253  struct arm_tpiu_swo_connection *c = malloc(sizeof(*c));
254  if (!c) {
255  LOG_ERROR("Out of memory");
256  return ERROR_FAIL;
257  }
258  c->connection = connection;
259  list_add(&c->lh, &obj->connections);
260  return ERROR_OK;
261 }
262 
264 {
265  /* read a dummy buffer to check if the connection is still active */
266  long dummy;
267  int bytes_read = connection_read(connection, &dummy, sizeof(dummy));
268 
269  if (bytes_read == 0) {
271  } else if (bytes_read == -1) {
272  LOG_ERROR("error during read: %s", strerror(errno));
274  }
275 
276  return ERROR_OK;
277 }
278 
280 {
282  struct arm_tpiu_swo_object *obj = priv->obj;
283  struct arm_tpiu_swo_connection *c, *tmp;
284 
285  list_for_each_entry_safe(c, tmp, &obj->connections, lh)
286  if (c->connection == connection) {
287  list_del(&c->lh);
288  free(c);
289  return ERROR_OK;
290  }
291  LOG_ERROR("Failed to find connection to close!");
292  return ERROR_FAIL;
293 }
294 
295 COMMAND_HANDLER(handle_arm_tpiu_swo_event_list)
296 {
297  struct arm_tpiu_swo_object *obj = CMD_DATA;
298 
299  command_print(CMD, "Event actions for TPIU/SWO %s\n", obj->name);
300  command_print(CMD, "%-25s | Body", "Event");
301  command_print(CMD, "------------------------- | "
302  "----------------------------------------");
303 
304  for (struct arm_tpiu_swo_event_action *ea = obj->event_action; ea; ea = ea->next) {
305  struct jim_nvp *opt = jim_nvp_value2name_simple(nvp_arm_tpiu_swo_event, ea->event);
306  command_print(CMD, "%-25s | %s",
307  opt->name, Jim_GetString(ea->body, NULL));
308  }
309  command_print(CMD, "***END***");
310  return ERROR_OK;
311 }
312 
321 };
322 
323 static const struct jim_nvp nvp_arm_tpiu_swo_config_opts[] = {
324  { .name = "-port-width", .value = CFG_PORT_WIDTH },
325  { .name = "-protocol", .value = CFG_PROTOCOL },
326  { .name = "-formatter", .value = CFG_FORMATTER },
327  { .name = "-traceclk", .value = CFG_TRACECLKIN },
328  { .name = "-pin-freq", .value = CFG_BITRATE },
329  { .name = "-output", .value = CFG_OUTFILE },
330  { .name = "-event", .value = CFG_EVENT },
331  /* handled by mem_ap_spot, added for jim_getopt_nvp_unknown() */
332  { .name = "-dap", .value = -1 },
333  { .name = "-ap-num", .value = -1 },
334  { .name = "-baseaddr", .value = -1 },
335  { .name = NULL, .value = -1 },
336 };
337 
338 static const struct jim_nvp nvp_arm_tpiu_swo_protocol_opts[] = {
339  { .name = "sync", .value = TPIU_SPPR_PROTOCOL_SYNC },
340  { .name = "uart", .value = TPIU_SPPR_PROTOCOL_UART },
341  { .name = "manchester", .value = TPIU_SPPR_PROTOCOL_MANCHESTER },
342  { .name = NULL, .value = -1 },
343 };
344 
345 static const struct jim_nvp nvp_arm_tpiu_swo_bool_opts[] = {
346  { .name = "on", .value = 1 },
347  { .name = "yes", .value = 1 },
348  { .name = "1", .value = 1 },
349  { .name = "true", .value = 1 },
350  { .name = "off", .value = 0 },
351  { .name = "no", .value = 0 },
352  { .name = "0", .value = 0 },
353  { .name = "false", .value = 0 },
354  { .name = NULL, .value = -1 },
355 };
356 
357 static int arm_tpiu_swo_configure(struct jim_getopt_info *goi, struct arm_tpiu_swo_object *obj)
358 {
359  assert(obj);
360 
361  if (goi->is_configure && obj->enabled) {
362  Jim_SetResultFormatted(goi->interp, "Cannot configure TPIU/SWO; %s is enabled!", obj->name);
363  return JIM_ERR;
364  }
365 
366  /* parse config or cget options ... */
367  while (goi->argc > 0) {
368  Jim_SetEmptyResult(goi->interp);
369 
370  int e = adiv5_jim_mem_ap_spot_configure(&obj->spot, goi);
371  if (e == JIM_OK)
372  continue;
373  if (e == JIM_ERR)
374  return e;
375 
376  struct jim_nvp *n;
378  if (e != JIM_OK) {
380  return e;
381  }
382 
383  switch (n->value) {
384  case CFG_PORT_WIDTH:
385  if (goi->is_configure) {
386  jim_wide port_width;
387  e = jim_getopt_wide(goi, &port_width);
388  if (e != JIM_OK)
389  return e;
390  if (port_width < 1 || port_width > 32) {
391  Jim_SetResultString(goi->interp, "Invalid port width!", -1);
392  return JIM_ERR;
393  }
394  obj->port_width = (uint32_t)port_width;
395  } else {
396  if (goi->argc)
397  goto err_no_params;
398  Jim_SetResult(goi->interp, Jim_NewIntObj(goi->interp, obj->port_width));
399  }
400  break;
401  case CFG_PROTOCOL:
402  if (goi->is_configure) {
403  struct jim_nvp *p;
405  if (e != JIM_OK)
406  return e;
407  obj->pin_protocol = p->value;
408  } else {
409  if (goi->argc)
410  goto err_no_params;
411  struct jim_nvp *p;
413  if (e != JIM_OK) {
414  Jim_SetResultString(goi->interp, "protocol error", -1);
415  return JIM_ERR;
416  }
417  Jim_SetResult(goi->interp, Jim_NewStringObj(goi->interp, p->name, -1));
418  }
419  break;
420  case CFG_FORMATTER:
421  if (goi->is_configure) {
422  struct jim_nvp *p;
424  if (e != JIM_OK)
425  return e;
426  obj->en_formatter = p->value;
427  } else {
428  if (goi->argc)
429  goto err_no_params;
430  struct jim_nvp *p;
432  if (e != JIM_OK) {
433  Jim_SetResultString(goi->interp, "formatter error", -1);
434  return JIM_ERR;
435  }
436  Jim_SetResult(goi->interp, Jim_NewStringObj(goi->interp, p->name, -1));
437  }
438  break;
439  case CFG_TRACECLKIN:
440  if (goi->is_configure) {
441  jim_wide clk;
442  e = jim_getopt_wide(goi, &clk);
443  if (e != JIM_OK)
444  return e;
445  obj->traceclkin_freq = clk;
446  } else {
447  if (goi->argc)
448  goto err_no_params;
449  Jim_SetResult(goi->interp, Jim_NewIntObj(goi->interp, obj->traceclkin_freq));
450  }
451  break;
452  case CFG_BITRATE:
453  if (goi->is_configure) {
454  jim_wide clk;
455  e = jim_getopt_wide(goi, &clk);
456  if (e != JIM_OK)
457  return e;
458  obj->swo_pin_freq = clk;
459  } else {
460  if (goi->argc)
461  goto err_no_params;
462  Jim_SetResult(goi->interp, Jim_NewIntObj(goi->interp, obj->swo_pin_freq));
463  }
464  break;
465  case CFG_OUTFILE:
466  if (goi->is_configure) {
467  const char *s;
468  e = jim_getopt_string(goi, &s, NULL);
469  if (e != JIM_OK)
470  return e;
471  if (s[0] == ':') {
472  char *end;
473  long port = strtol(s + 1, &end, 0);
474  if (port <= 0 || port > UINT16_MAX || *end != '\0') {
475  Jim_SetResultFormatted(goi->interp, "Invalid TCP port \'%s\'", s + 1);
476  return JIM_ERR;
477  }
478  }
479  char *out_filename = strdup(s);
480  if (!out_filename) {
481  LOG_ERROR("Out of memory");
482  return JIM_ERR;
483  }
484  free(obj->out_filename);
485  obj->out_filename = out_filename;
486  } else {
487  if (goi->argc)
488  goto err_no_params;
489  if (obj->out_filename)
490  Jim_SetResult(goi->interp, Jim_NewStringObj(goi->interp, obj->out_filename, -1));
491  }
492  break;
493  case CFG_EVENT:
494  if (goi->is_configure) {
495  if (goi->argc < 2) {
496  Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "-event ?event-name? ?EVENT-BODY?");
497  return JIM_ERR;
498  }
499  } else {
500  if (goi->argc != 1) {
501  Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "-event ?event-name?");
502  return JIM_ERR;
503  }
504  }
505 
506  {
507  struct jim_nvp *p;
508  Jim_Obj *o;
509  struct arm_tpiu_swo_event_action *ea = obj->event_action;
510 
512  if (e != JIM_OK) {
514  return e;
515  }
516 
517  while (ea) {
518  /* replace existing? */
519  if (ea->event == (enum arm_tpiu_swo_event)p->value)
520  break;
521  ea = ea->next;
522  }
523 
524  if (goi->is_configure) {
525  if (!ea) {
526  ea = calloc(1, sizeof(*ea));
527  if (!ea) {
528  LOG_ERROR("Out of memory");
529  return JIM_ERR;
530  }
531  ea->next = obj->event_action;
532  obj->event_action = ea;
533  }
534  if (ea->body)
535  Jim_DecrRefCount(ea->interp, ea->body);
536  ea->event = p->value;
537  ea->interp = goi->interp;
538  jim_getopt_obj(goi, &o);
539  ea->body = Jim_DuplicateObj(goi->interp, o);
540  Jim_IncrRefCount(ea->body);
541  } else {
542  if (ea)
543  Jim_SetResult(goi->interp, Jim_DuplicateObj(goi->interp, ea->body));
544  }
545  }
546  break;
547  }
548  }
549 
550  return JIM_OK;
551 
552 err_no_params:
553  Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "NO PARAMS");
554  return JIM_ERR;
555 }
556 
557 static int jim_arm_tpiu_swo_configure(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
558 {
559  struct command *c = jim_to_command(interp);
560  struct jim_getopt_info goi;
561 
562  jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
563  goi.is_configure = !strcmp(c->name, "configure");
564  if (goi.argc < 1) {
565  Jim_WrongNumArgs(goi.interp, goi.argc, goi.argv,
566  "missing: -option ...");
567  return JIM_ERR;
568  }
569  struct arm_tpiu_swo_object *obj = c->jim_handler_data;
570  return arm_tpiu_swo_configure(&goi, obj);
571 }
572 
573 static int wrap_write_u32(struct target *target, struct adiv5_ap *tpiu_ap,
574  target_addr_t address, uint32_t value)
575 {
576  if (transport_is_hla())
577  return target_write_u32(target, address, value);
578  else
579  return mem_ap_write_atomic_u32(tpiu_ap, address, value);
580 }
581 
582 static int wrap_read_u32(struct target *target, struct adiv5_ap *tpiu_ap,
583  target_addr_t address, uint32_t *value)
584 {
585  if (transport_is_hla())
586  return target_read_u32(target, address, value);
587  else
588  return mem_ap_read_atomic_u32(tpiu_ap, address, value);
589 }
590 
591 static const struct service_driver arm_tpiu_swo_service_driver = {
592  .name = "tpiu_swo_trace",
593  .new_connection_during_keep_alive_handler = NULL,
594  .new_connection_handler = arm_tpiu_swo_service_new_connection,
595  .input_handler = arm_tpiu_swo_service_input,
596  .connection_closed_handler = arm_tpiu_swo_service_connection_closed,
597  .keep_client_alive_handler = NULL,
598 };
599 
600 COMMAND_HANDLER(handle_arm_tpiu_swo_enable)
601 {
602  struct arm_tpiu_swo_object *obj = CMD_DATA;
603  uint32_t value;
604  int retval;
605 
606  if (CMD_ARGC != 0)
608 
609  if (CMD_CTX->mode == COMMAND_CONFIG) {
610  LOG_DEBUG("%s: enable deferred", obj->name);
611  obj->deferred_enable = true;
612  return ERROR_OK;
613  }
614 
615  if (obj->enabled)
616  return ERROR_OK;
617 
618  if (transport_is_hla() && obj->spot.ap_num != 0) {
620  "Invalid access port 0x%" PRIx64 ". Only AP#0 allowed with hla transport",
621  obj->spot.ap_num);
622  return ERROR_FAIL;
623  }
624 
625  if (!obj->traceclkin_freq) {
626  command_print(CMD, "Trace clock-in frequency not set");
627  return ERROR_FAIL;
628  }
629 
630  const bool output_external = !strcmp(obj->out_filename, "external");
631 
633  if (!obj->swo_pin_freq) {
634  if (output_external) {
635  command_print(CMD, "SWO pin frequency required when using external capturing");
636  return ERROR_FAIL;
637  }
638 
639  LOG_DEBUG("SWO pin frequency not set, will be autodetected by the adapter");
640  }
641  }
642 
644 
645  /* START_DEPRECATED_TPIU */
646  if (obj->recheck_ap_cur_target) {
647  if (strcmp(target_type_name(target), "cortex_m") &&
648  strcmp(target_type_name(target), "hla_target")) {
649  LOG_ERROR(MSG "Current target is not a Cortex-M nor a HLA");
650  return ERROR_FAIL;
651  }
652  if (!target_was_examined(target)) {
653  LOG_ERROR(MSG "Current target not examined yet");
654  return ERROR_FAIL;
655  }
656  struct cortex_m_common *cm = target_to_cm(target);
657  obj->recheck_ap_cur_target = false;
658  obj->spot.ap_num = cm->armv7m.debug_ap->ap_num;
659  if (obj->spot.ap_num == 0)
660  LOG_INFO(MSG "Confirmed TPIU %s is on AP 0", obj->name);
661  else
662  LOG_INFO(MSG "Target %s is on AP#0x%" PRIx64 ". Revised command is "
663  "\'tpiu create %s -dap %s -ap-num 0x%" PRIx64 "\'",
664  target_name(target), obj->spot.ap_num,
665  obj->name, adiv5_dap_name(obj->spot.dap), obj->spot.ap_num);
666  }
667  /* END_DEPRECATED_TPIU */
668 
669  if (!obj->ap) {
670  obj->ap = dap_get_ap(obj->spot.dap, obj->spot.ap_num);
671  if (!obj->ap) {
672  command_print(CMD, "Cannot get AP");
673  return ERROR_FAIL;
674  }
675  }
676 
677  /* trigger the event before any attempt to R/W in the TPIU/SWO */
679  if (retval != ERROR_OK)
680  return retval;
681 
682  retval = wrap_read_u32(target, obj->ap, obj->spot.base + TPIU_DEVID_OFFSET, &value);
683  if (retval != ERROR_OK) {
684  command_print(CMD, "Unable to read %s", obj->name);
685  return retval;
686  }
687  switch (obj->pin_protocol) {
689  value = !(value & TPIU_DEVID_NOSUPPORT_SYNC);
690  break;
692  value &= TPIU_DEVID_SUPPORT_UART;
693  break;
696  break;
697  default:
698  value = 0;
699  }
700  if (!value) {
702  command_print(CMD, "%s does not support protocol %s", obj->name, p->name);
703  return ERROR_FAIL;
704  }
705 
707  retval = wrap_read_u32(target, obj->ap, obj->spot.base + TPIU_SSPSR_OFFSET, &value);
708  if (retval != ERROR_OK) {
709  command_print(CMD, "Cannot read TPIU register SSPSR");
710  return retval;
711  }
712  if (!(value & BIT(obj->port_width - 1))) {
713  command_print(CMD, "TPIU does not support port-width of %d bits", obj->port_width);
714  return ERROR_FAIL;
715  }
716  }
717 
718  uint16_t prescaler = 1; /* dummy value */
719  unsigned int swo_pin_freq = obj->swo_pin_freq; /* could be replaced */
720 
721  if (!output_external) {
722  if (obj->out_filename[0] == ':') {
723  struct arm_tpiu_swo_priv_connection *priv = malloc(sizeof(*priv));
724  if (!priv) {
725  LOG_ERROR("Out of memory");
726  return ERROR_FAIL;
727  }
728  priv->obj = obj;
729  LOG_INFO("starting trace server for %s on %s", obj->name, &obj->out_filename[1]);
732  if (retval != ERROR_OK) {
733  command_print(CMD, "Can't configure trace TCP port %s", &obj->out_filename[1]);
734  return retval;
735  }
736  } else if (strcmp(obj->out_filename, "-")) {
737  obj->file = fopen(obj->out_filename, "ab");
738  if (!obj->file) {
739  command_print(CMD, "Can't open trace destination file \"%s\"", obj->out_filename);
740  return ERROR_FAIL;
741  }
742  }
743 
745  &swo_pin_freq, obj->traceclkin_freq, &prescaler);
746  if (retval != ERROR_OK) {
747  command_print(CMD, "Failed to start adapter's trace");
749  return retval;
750  }
751 
753  if (!swo_pin_freq) {
754  if (obj->swo_pin_freq)
755  command_print(CMD, "Adapter rejected SWO pin frequency %d Hz", obj->swo_pin_freq);
756  else
758  "Adapter does not support auto-detection of SWO pin frequency nor a default value");
759 
761  return ERROR_FAIL;
762  }
763 
764  if (obj->swo_pin_freq != swo_pin_freq)
765  LOG_INFO("SWO pin data rate adjusted by adapter to %d Hz", swo_pin_freq);
766  obj->swo_pin_freq = swo_pin_freq;
767 
770 
771  obj->en_capture = true;
773  prescaler = (obj->traceclkin_freq + obj->swo_pin_freq / 2) / obj->swo_pin_freq;
774  if (prescaler > TPIU_ACPR_MAX_PRESCALER)
775  prescaler = TPIU_ACPR_MAX_PRESCALER;
776  swo_pin_freq = obj->traceclkin_freq / prescaler;
777 
778  if (obj->swo_pin_freq != swo_pin_freq)
779  LOG_INFO("SWO pin data rate adjusted to %d Hz", swo_pin_freq);
780  obj->swo_pin_freq = swo_pin_freq;
781  }
782 
784  if (retval != ERROR_OK)
785  goto error_exit;
786 
787  retval = wrap_write_u32(target, obj->ap, obj->spot.base + TPIU_ACPR_OFFSET, prescaler - 1);
788  if (retval != ERROR_OK)
789  goto error_exit;
790 
792  if (retval != ERROR_OK)
793  goto error_exit;
794 
795  retval = wrap_read_u32(target, obj->ap, obj->spot.base + TPIU_FFCR_OFFSET, &value);
796  if (retval != ERROR_OK)
797  goto error_exit;
798  if (obj->en_formatter)
799  value |= BIT(1);
800  else
801  value &= ~BIT(1);
802  retval = wrap_write_u32(target, obj->ap, obj->spot.base + TPIU_FFCR_OFFSET, value);
803  if (retval != ERROR_OK)
804  goto error_exit;
805 
807  if (retval != ERROR_OK)
808  goto error_exit;
809 
810  /* START_DEPRECATED_TPIU */
812  /* END_DEPRECATED_TPIU */
813 
814  obj->enabled = true;
815  return ERROR_OK;
816 
817 error_exit:
818  command_print(CMD, "Error!");
819 
820  if (obj->en_capture) {
821  obj->en_capture = false;
822 
824 
826 
827  int retval1 = adapter_config_trace(false, 0, 0, NULL, 0, NULL);
828  if (retval1 != ERROR_OK)
829  command_print(CMD, "Failed to stop adapter's trace");
830  }
831  return retval;
832 }
833 
834 COMMAND_HANDLER(handle_arm_tpiu_swo_disable)
835 {
836  struct arm_tpiu_swo_object *obj = CMD_DATA;
837 
838  if (CMD_ARGC != 0)
840 
841  if (!obj->enabled)
842  return ERROR_OK;
843  obj->enabled = false;
844 
846 
847  if (obj->en_capture) {
848  obj->en_capture = false;
849 
851 
853 
854  int retval = adapter_config_trace(false, 0, 0, NULL, 0, NULL);
855  if (retval != ERROR_OK) {
856  command_print(CMD, "Failed to stop adapter's trace");
857  return retval;
858  }
859  }
860 
862 
863  /* START_DEPRECATED_TPIU */
866  /* END_DEPRECATED_TPIU */
867 
868  return ERROR_OK;
869 }
870 
872  {
873  .name = "configure",
874  .mode = COMMAND_ANY,
875  .jim_handler = jim_arm_tpiu_swo_configure,
876  .help = "configure a new TPIU/SWO for use",
877  .usage = "[attribute value ...]",
878  },
879  {
880  .name = "cget",
881  .mode = COMMAND_ANY,
882  .jim_handler = jim_arm_tpiu_swo_configure,
883  .help = "returns the specified TPIU/SWO attribute",
884  .usage = "attribute",
885  },
886  {
887  .name = "eventlist",
888  .mode = COMMAND_ANY,
889  .handler = handle_arm_tpiu_swo_event_list,
890  .help = "displays a table of events defined for this TPIU/SWO",
891  .usage = "",
892  },
893  {
894  .name = "enable",
895  .mode = COMMAND_ANY,
896  .handler = handle_arm_tpiu_swo_enable,
897  .usage = "",
898  .help = "Enables the TPIU/SWO output",
899  },
900  {
901  .name = "disable",
902  .mode = COMMAND_EXEC,
903  .handler = handle_arm_tpiu_swo_disable,
904  .usage = "",
905  .help = "Disables the TPIU/SWO output",
906  },
908 };
909 
910 static int arm_tpiu_swo_create(Jim_Interp *interp, struct arm_tpiu_swo_object *obj)
911 {
912  struct command_context *cmd_ctx;
913  Jim_Cmd *cmd;
914  int e;
915 
916  cmd_ctx = current_command_context(interp);
917  assert(cmd_ctx);
918 
919  /* does this command exist? */
920  cmd = Jim_GetCommand(interp, Jim_NewStringObj(interp, obj->name, -1), JIM_NONE);
921  if (cmd) {
922  Jim_SetResultFormatted(interp, "cannot create TPIU object because a command with name '%s' already exists",
923  obj->name);
924  return JIM_ERR;
925  }
926 
927  /* now - create the new tpiu/swo name command */
928  const struct command_registration obj_commands[] = {
929  {
930  .name = obj->name,
931  .mode = COMMAND_ANY,
932  .help = "tpiu/swo instance command group",
933  .usage = "",
935  },
937  };
938  e = register_commands_with_data(cmd_ctx, NULL, obj_commands, obj);
939  if (e != ERROR_OK)
940  return JIM_ERR;
941 
942  list_add_tail(&obj->lh, &all_tpiu_swo);
943 
944  return JIM_OK;
945 }
946 
947 static int jim_arm_tpiu_swo_create(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
948 {
949  struct jim_getopt_info goi;
950  jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
951  if (goi.argc < 1) {
952  Jim_WrongNumArgs(interp, 1, argv, "name ?option option ...?");
953  return JIM_ERR;
954  }
955 
956  struct arm_tpiu_swo_object *obj = calloc(1, sizeof(struct arm_tpiu_swo_object));
957  if (!obj) {
958  LOG_ERROR("Out of memory");
959  return JIM_ERR;
960  }
964  obj->port_width = 1;
965  obj->out_filename = strdup("external");
966  if (!obj->out_filename) {
967  LOG_ERROR("Out of memory");
968  goto err_exit;
969  }
970 
971  Jim_Obj *n;
972  jim_getopt_obj(&goi, &n);
973  obj->name = strdup(Jim_GetString(n, NULL));
974  if (!obj->name) {
975  LOG_ERROR("Out of memory");
976  goto err_exit;
977  }
978 
979  /* Do the rest as "configure" options */
980  goi.is_configure = true;
981  int e = arm_tpiu_swo_configure(&goi, obj);
982  if (e != JIM_OK)
983  goto err_exit;
984 
985  if (!obj->spot.dap || obj->spot.ap_num == DP_APSEL_INVALID) {
986  Jim_SetResultString(goi.interp, "-dap and -ap-num required when creating TPIU", -1);
987  goto err_exit;
988  }
989 
990  e = arm_tpiu_swo_create(goi.interp, obj);
991  if (e != JIM_OK)
992  goto err_exit;
993 
994  return JIM_OK;
995 
996 err_exit:
997  free(obj->name);
998  free(obj->out_filename);
999  free(obj);
1000  return JIM_ERR;
1001 }
1002 
1003 COMMAND_HANDLER(handle_arm_tpiu_swo_names)
1004 {
1005  struct arm_tpiu_swo_object *obj;
1006 
1007  if (CMD_ARGC != 0)
1009 
1010  list_for_each_entry(obj, &all_tpiu_swo, lh)
1011  command_print(CMD, "%s", obj->name);
1012 
1013  return ERROR_OK;
1014 }
1015 
1016 COMMAND_HANDLER(handle_arm_tpiu_swo_init)
1017 {
1018  struct arm_tpiu_swo_object *obj;
1019  int retval = ERROR_OK;
1020 
1021  if (CMD_ARGC != 0)
1023 
1024  list_for_each_entry(obj, &all_tpiu_swo, lh) {
1025  if (!obj->deferred_enable)
1026  continue;
1027  LOG_DEBUG("%s: running enable during init", obj->name);
1028  int retval2 = command_run_linef(CMD_CTX, "%s enable", obj->name);
1029  if (retval2 != ERROR_OK)
1030  retval = retval2;
1031  }
1032  return retval;
1033 }
1034 
1035 /* START_DEPRECATED_TPIU */
1036 /* DEPRECATED: emulation of old command 'tpiu config' */
1037 COMMAND_HANDLER(handle_tpiu_deprecated_config_command)
1038 {
1040  struct arm_tpiu_swo_object *obj = NULL;
1041  int retval;
1042 
1043  if (strcmp(target_type_name(target), "cortex_m") &&
1044  strcmp(target_type_name(target), "hla_target")) {
1045  LOG_ERROR(MSG "Current target is not a Cortex-M nor a HLA");
1046  return ERROR_FAIL;
1047  }
1048 
1049  if (!list_empty(&all_tpiu_swo)) {
1050  obj = list_first_entry(&all_tpiu_swo, typeof(*obj), lh);
1051  LOG_INFO(MSG "Using %s", obj->name);
1052  } else {
1053  struct cortex_m_common *cm = target_to_cm(target);
1055  struct adiv5_dap *dap = pc->dap;
1056  uint64_t ap_num = pc->ap_num;
1057  bool set_recheck_ap_cur_target = false;
1058 
1059  LOG_INFO(MSG "Adding a TPIU \'%s.tpiu\' in the configuration", target_name(target));
1060 
1061  if (ap_num == DP_APSEL_INVALID && transport_is_hla())
1062  ap_num = 0; /* HLA should only support AP 0 */
1063 
1064  if (ap_num == DP_APSEL_INVALID && target_was_examined(target))
1065  ap_num = cm->armv7m.debug_ap->ap_num;
1066 
1067  if (ap_num == DP_APSEL_INVALID) {
1068  LOG_INFO(MSG "Target %s uses AP autodetection. Adding TPIU on AP 0; can be revised later",
1069  target_name(target));
1070  ap_num = 0;
1071  set_recheck_ap_cur_target = true;
1072  }
1073 
1074  LOG_INFO(MSG "Running: \'tpiu create %s.tpiu -dap %s -ap-num 0x%" PRIx64 "\'",
1075  target_name(target), adiv5_dap_name(dap), ap_num);
1076 
1077  retval = command_run_linef(CMD_CTX, "tpiu create %s.tpiu -dap %s -ap-num 0x%" PRIx64,
1078  target_name(target), adiv5_dap_name(dap), ap_num);
1079  if (retval != ERROR_OK)
1080  return retval;
1081 
1082  obj = list_first_entry(&all_tpiu_swo, typeof(*obj), lh);
1083  if (set_recheck_ap_cur_target)
1084  obj->recheck_ap_cur_target = true;
1085  }
1086 
1087  unsigned int cmd_idx = 0;
1088  if (cmd_idx == CMD_ARGC)
1090 
1091  if (!strcmp(CMD_ARGV[cmd_idx], "disable")) {
1092  if (CMD_ARGC != cmd_idx + 1)
1094  LOG_INFO(MSG "Running: \'%s disable\'", obj->name);
1095  return command_run_linef(CMD_CTX, "%s disable", obj->name);
1096  }
1097 
1098  const char *output = NULL;
1099  const char *protocol;
1100  const char *formatter = NULL;
1101  const char *port_width = NULL;
1102  const char *trace_clk;
1103  const char *pin_clk = NULL;
1104  if (!strcmp(CMD_ARGV[cmd_idx], "internal")) {
1105  cmd_idx++;
1106  if (cmd_idx == CMD_ARGC)
1108  output = CMD_ARGV[cmd_idx];
1109  } else if (strcmp(CMD_ARGV[cmd_idx], "external"))
1111  cmd_idx++;
1112  if (cmd_idx == CMD_ARGC)
1114  if (!strcmp(CMD_ARGV[cmd_idx], "sync")) {
1115  protocol = CMD_ARGV[cmd_idx];
1116  cmd_idx++;
1117  if (cmd_idx == CMD_ARGC)
1119  port_width = CMD_ARGV[cmd_idx];
1120  } else {
1121  if (strcmp(CMD_ARGV[cmd_idx], "manchester") && strcmp(CMD_ARGV[cmd_idx], "uart"))
1123  protocol = CMD_ARGV[cmd_idx];
1124  cmd_idx++;
1125  if (cmd_idx == CMD_ARGC)
1127  formatter = CMD_ARGV[cmd_idx];
1128  }
1129  cmd_idx++;
1130  if (cmd_idx == CMD_ARGC)
1132  trace_clk = CMD_ARGV[cmd_idx];
1133  cmd_idx++;
1134  if (cmd_idx != CMD_ARGC) {
1135  pin_clk = CMD_ARGV[cmd_idx];
1136  cmd_idx++;
1137  }
1138  if (cmd_idx != CMD_ARGC)
1140 
1141  LOG_INFO(MSG "Running: \'%s configure -protocol %s -traceclk %s" "%s%s" "%s%s" "%s%s" "%s%s\'",
1142  obj->name, protocol, trace_clk,
1143  pin_clk ? " -pin-freq " : "", pin_clk ? pin_clk : "",
1144  output ? " -output " : "", output ? output : "",
1145  formatter ? " -formatter " : "", formatter ? formatter : "",
1146  port_width ? " -port-width " : "", port_width ? port_width : "");
1147 
1148  retval = command_run_linef(CMD_CTX,
1149  "%s configure -protocol %s -traceclk %s" "%s%s" "%s%s" "%s%s" "%s%s",
1150  obj->name, protocol, trace_clk,
1151  pin_clk ? " -pin-freq " : "", pin_clk ? pin_clk : "",
1152  output ? " -output " : "", output ? output : "",
1153  formatter ? " -formatter " : "", formatter ? formatter : "",
1154  port_width ? " -port-width " : "", port_width ? port_width : "");
1155  if (retval != ERROR_OK)
1156  return retval;
1157 
1158  LOG_INFO(MSG "Running: \'%s enable\'", obj->name);
1159  retval = command_run_linef(CMD_CTX, "%s enable", obj->name);
1160  if (retval != ERROR_OK)
1161  return retval;
1162 
1163  return ERROR_OK;
1164 }
1165 
1167  {
1168  .name = "config",
1169  .handler = handle_tpiu_deprecated_config_command,
1170  .mode = COMMAND_ANY,
1171  .help = "Configure TPIU features, DEPRECATED, use \'tpiu create\'",
1172  .usage = "(disable | "
1173  "((external | internal (<filename> | <:port> | -)) "
1174  "(sync <port width> | ((manchester | uart) <formatter enable>)) "
1175  "<TRACECLKIN freq> [<trace freq>]))",
1176  },
1178 };
1179 
1181  {
1182  .name = "tpiu",
1184  .usage = "",
1185  .help = "tpiu command group",
1186  },
1188 };
1189 /* END_DEPRECATED_TPIU */
1190 
1192  {
1193  .name = "create",
1194  .mode = COMMAND_ANY,
1195  .jim_handler = jim_arm_tpiu_swo_create,
1196  .usage = "name [-dap dap] [-ap-num num] [-baseaddr baseaddr]",
1197  .help = "Creates a new TPIU or SWO object",
1198  },
1199  {
1200  .name = "names",
1201  .mode = COMMAND_ANY,
1202  .handler = handle_arm_tpiu_swo_names,
1203  .usage = "",
1204  .help = "Lists all registered TPIU and SWO objects by name",
1205  },
1206  {
1207  .name = "init",
1208  .mode = COMMAND_EXEC,
1209  .handler = handle_arm_tpiu_swo_init,
1210  .usage = "",
1211  .help = "Initialize TPIU and SWO",
1212  },
1214 };
1215 
1216 static const struct command_registration arm_tpiu_swo_command_handlers[] = {
1217  {
1218  .name = "tpiu",
1220  .usage = "",
1221  .help = "tpiu command group",
1222  },
1223  {
1224  .name = "swo",
1226  .usage = "",
1227  .help = "swo command group",
1228  },
1230 };
1231 
1233 {
1235 }
int adiv5_mem_ap_spot_init(struct adiv5_mem_ap_spot *p)
Definition: arm_adi_v5.c:2501
int mem_ap_read_atomic_u32(struct adiv5_ap *ap, target_addr_t address, uint32_t *value)
Synchronous read of a word from memory or a system register.
Definition: arm_adi_v5.c:266
struct adiv5_ap * dap_get_ap(struct adiv5_dap *dap, uint64_t ap_num)
Definition: arm_adi_v5.c:1189
int dap_put_ap(struct adiv5_ap *ap)
Definition: arm_adi_v5.c:1209
int adiv5_jim_mem_ap_spot_configure(struct adiv5_mem_ap_spot *cfg, struct jim_getopt_info *goi)
Definition: arm_adi_v5.c:2495
int mem_ap_write_atomic_u32(struct adiv5_ap *ap, target_addr_t address, uint32_t value)
Synchronous write of a word to memory or a system register.
Definition: arm_adi_v5.c:318
This defines formats and data structures used to talk to ADIv5 entities.
#define DP_APSEL_INVALID
Definition: arm_adi_v5.h:110
const char * adiv5_dap_name(struct adiv5_dap *self)
Definition: arm_dap.c:54
static LIST_HEAD(all_tpiu_swo)
static const struct jim_nvp nvp_arm_tpiu_swo_bool_opts[]
Definition: arm_tpiu_swo.c:345
#define ARM_TPIU_SWO_TRACE_BUF_SIZE
Definition: arm_tpiu_swo.c:131
#define MSG
Definition: arm_tpiu_swo.c:43
static const struct command_registration arm_tpiu_deprecated_subcommand_handlers[]
static int jim_arm_tpiu_swo_configure(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Definition: arm_tpiu_swo.c:557
#define TPIU_SWO_DEFAULT_BASE
Definition: arm_tpiu_swo.c:49
#define TPIU_SPPR_PROTOCOL_MANCHESTER
Definition: arm_tpiu_swo.c:62
arm_tpiu_swo_event
Definition: arm_tpiu_swo.c:68
@ TPIU_SWO_EVENT_PRE_DISABLE
Definition: arm_tpiu_swo.c:71
@ TPIU_SWO_EVENT_PRE_ENABLE
Definition: arm_tpiu_swo.c:69
@ TPIU_SWO_EVENT_POST_ENABLE
Definition: arm_tpiu_swo.c:70
@ TPIU_SWO_EVENT_POST_DISABLE
Definition: arm_tpiu_swo.c:72
static const struct jim_nvp nvp_arm_tpiu_swo_config_opts[]
Definition: arm_tpiu_swo.c:323
#define TPIU_DEVID_OFFSET
Definition: arm_tpiu_swo.c:58
#define TPIU_CSPSR_OFFSET
Definition: arm_tpiu_swo.c:52
static int jim_arm_tpiu_swo_create(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Definition: arm_tpiu_swo.c:947
static const struct service_driver arm_tpiu_swo_service_driver
Definition: arm_tpiu_swo.c:591
const struct command_registration arm_tpiu_deprecated_command_handlers[]
static const struct command_registration arm_tpiu_swo_subcommand_handlers[]
static void arm_tpiu_swo_close_output(struct arm_tpiu_swo_object *obj)
Definition: arm_tpiu_swo.c:199
int arm_tpiu_swo_register_commands(struct command_context *cmd_ctx)
static const struct jim_nvp nvp_arm_tpiu_swo_protocol_opts[]
Definition: arm_tpiu_swo.c:338
static int arm_tpiu_swo_service_connection_closed(struct connection *connection)
Definition: arm_tpiu_swo.c:279
arm_tpiu_swo_cfg_param
Definition: arm_tpiu_swo.c:313
@ CFG_PROTOCOL
Definition: arm_tpiu_swo.c:315
@ CFG_TRACECLKIN
Definition: arm_tpiu_swo.c:317
@ CFG_FORMATTER
Definition: arm_tpiu_swo.c:316
@ CFG_PORT_WIDTH
Definition: arm_tpiu_swo.c:314
@ CFG_OUTFILE
Definition: arm_tpiu_swo.c:319
@ CFG_EVENT
Definition: arm_tpiu_swo.c:320
@ CFG_BITRATE
Definition: arm_tpiu_swo.c:318
#define TPIU_SPPR_OFFSET
Definition: arm_tpiu_swo.c:54
static int arm_tpiu_swo_handle_event(struct arm_tpiu_swo_object *obj, enum arm_tpiu_swo_event event)
Definition: arm_tpiu_swo.c:163
static int arm_tpiu_swo_service_input(struct connection *connection)
Definition: arm_tpiu_swo.c:263
#define TPIU_SPPR_PROTOCOL_SYNC
Definition: arm_tpiu_swo.c:61
#define TPIU_FFCR_OFFSET
Definition: arm_tpiu_swo.c:56
static const struct command_registration arm_tpiu_swo_instance_command_handlers[]
Definition: arm_tpiu_swo.c:871
static int arm_tpiu_swo_service_new_connection(struct connection *connection)
Definition: arm_tpiu_swo.c:249
#define TPIU_ACPR_MAX_PRESCALER
Definition: arm_tpiu_swo.c:60
#define TPIU_DEVID_SUPPORT_UART
Definition: arm_tpiu_swo.c:66
#define TPIU_SPPR_PROTOCOL_UART
Definition: arm_tpiu_swo.c:63
static const struct jim_nvp nvp_arm_tpiu_swo_event[]
Definition: arm_tpiu_swo.c:75
static int arm_tpiu_swo_create(Jim_Interp *interp, struct arm_tpiu_swo_object *obj)
Definition: arm_tpiu_swo.c:910
#define TCP_SERVICE_NAME
Definition: arm_tpiu_swo.c:46
#define TPIU_DEVID_SUPPORT_MANCHESTER
Definition: arm_tpiu_swo.c:65
static int wrap_write_u32(struct target *target, struct adiv5_ap *tpiu_ap, target_addr_t address, uint32_t value)
Definition: arm_tpiu_swo.c:573
static const struct command_registration arm_tpiu_swo_command_handlers[]
#define TPIU_SSPSR_OFFSET
Definition: arm_tpiu_swo.c:51
#define TPIU_DEVID_NOSUPPORT_SYNC
Definition: arm_tpiu_swo.c:64
int arm_tpiu_swo_cleanup_all(void)
Definition: arm_tpiu_swo.c:209
static int wrap_read_u32(struct target *target, struct adiv5_ap *tpiu_ap, target_addr_t address, uint32_t *value)
Definition: arm_tpiu_swo.c:582
static int arm_tpiu_swo_configure(struct jim_getopt_info *goi, struct arm_tpiu_swo_object *obj)
Definition: arm_tpiu_swo.c:357
COMMAND_HANDLER(handle_arm_tpiu_swo_event_list)
Definition: arm_tpiu_swo.c:295
#define TPIU_ACPR_OFFSET
Definition: arm_tpiu_swo.c:53
static int arm_tpiu_swo_poll_trace(void *priv)
Definition: arm_tpiu_swo.c:133
const char * name
Definition: armv4_5.c:76
struct command_context * current_command_context(Jim_Interp *interp)
Definition: command.c:157
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:443
int command_run_linef(struct command_context *context, const char *format,...)
Definition: command.c:613
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:141
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:156
static int register_commands_with_data(struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds, void *data)
Register one or more commands, as register_commands(), plus specify a pointer to command private data...
Definition: command.h:315
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:402
#define CMD_DATA
Use this macro to access the invoked command handler's data pointer, rather than accessing the variab...
Definition: command.h:176
#define ERROR_COMMAND_CLOSE_CONNECTION
Definition: command.h:401
#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 CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
Definition: command.h:146
static struct command * jim_to_command(Jim_Interp *interp)
Definition: command.h:212
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
static int register_commands(struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds)
Register one or more commands in the specified context, as children of parent (or top-level commends,...
Definition: command.h:274
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
static struct cortex_m_common * target_to_cm(struct target *target)
Definition: cortex_m.h:287
static struct esp_usb_jtag * priv
Definition: esp_usb_jtag.c:219
static uint16_t output
Definition: ftdi.c:119
bool transport_is_hla(void)
int jim_getopt_wide(struct jim_getopt_info *goi, jim_wide *puthere)
Remove argv[0] as wide.
Definition: jim-nvp.c:222
int jim_getopt_setup(struct jim_getopt_info *p, Jim_Interp *interp, int argc, Jim_Obj *const *argv)
GetOpt - how to.
Definition: jim-nvp.c:149
int jim_getopt_string(struct jim_getopt_info *goi, const char **puthere, int *len)
Remove argv[0] as string.
Definition: jim-nvp.c:188
int jim_getopt_nvp(struct jim_getopt_info *goi, const struct jim_nvp *nvp, struct jim_nvp **puthere)
Remove argv[0] as NVP.
Definition: jim-nvp.c:237
void jim_getopt_nvp_unknown(struct jim_getopt_info *goi, const struct jim_nvp *nvptable, int hadprefix)
Create an appropriate error message for an NVP.
Definition: jim-nvp.c:253
int jim_getopt_obj(struct jim_getopt_info *goi, Jim_Obj **puthere)
Remove argv[0] from the list.
Definition: jim-nvp.c:169
struct jim_nvp * jim_nvp_value2name_simple(const struct jim_nvp *p, int value)
Definition: jim-nvp.c:124
int jim_nvp_value2name(Jim_Interp *interp, const struct jim_nvp *_p, int value, struct jim_nvp **result)
Definition: jim-nvp.c:134
int adapter_config_trace(bool enabled, enum tpiu_pin_protocol pin_protocol, uint32_t port_size, unsigned int *trace_freq, unsigned int traceclkin_freq, uint16_t *prescaler)
Definition: jtag/core.c:1922
int adapter_poll_trace(uint8_t *buf, size_t *size)
Definition: jtag/core.c:1937
static void list_add(struct list_head *new, struct list_head *head)
Definition: list.h:193
#define list_first_entry(ptr, type, member)
Definition: list.h:127
static void list_add_tail(struct list_head *new, struct list_head *head)
Definition: list.h:199
static int list_empty(const struct list_head *head)
Definition: list.h:60
#define list_for_each_entry_safe(p, n, h, field)
Definition: list.h:155
#define list_for_each_entry(p, h, field)
Definition: list.h:151
static void list_del(struct list_head *entry)
Definition: list.h:87
static void INIT_LIST_HEAD(struct list_head *list)
Definition: list.h:53
#define LOG_USER(expr ...)
Definition: log.h:135
#define ERROR_FAIL
Definition: log.h:170
#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:164
static uint32_t lh(unsigned int rd, unsigned int base, uint16_t offset) __attribute__((unused))
Definition: opcodes.h:117
size_t size
Size of the control block search area.
Definition: rtt/rtt.c:30
int connection_write(struct connection *connection, const void *data, int len)
Definition: server.c:732
int connection_read(struct connection *connection, void *data, int len)
Definition: server.c:744
int remove_service(const char *name, const char *port)
Definition: server.c:355
int add_service(const struct service_driver *driver, const char *port, int max_connections, void *priv)
Definition: server.c:198
#define CONNECTION_LIMIT_UNLIMITED
Definition: server.h:34
#define ERROR_SERVER_REMOTE_CLOSED
Definition: server.h:119
#define BIT(nr)
Definition: stm32l4x.h:18
This represents an ARM Debug Interface (v5) Access Port (AP).
Definition: arm_adi_v5.h:250
uint64_t ap_num
ADIv5: Number of this AP (0~255) ADIv6: Base address of this AP (4k aligned) TODO: to be more coheren...
Definition: arm_adi_v5.h:261
This represents an ARM Debug Interface (v5) Debug Access Port (DAP).
Definition: arm_adi_v5.h:348
struct adiv5_dap * dap
Definition: arm_adi_v5.h:803
struct adiv5_dap * dap
Definition: arm_adi_v5.h:787
struct list_head lh
Definition: arm_tpiu_swo.c:121
struct connection * connection
Definition: arm_tpiu_swo.c:122
struct arm_tpiu_swo_event_action * next
Definition: arm_tpiu_swo.c:86
enum arm_tpiu_swo_event event
Definition: arm_tpiu_swo.c:83
uint32_t port_width
Handle to output trace data in INTERNAL capture mode.
Definition: arm_tpiu_swo.c:101
struct arm_tpiu_swo_event_action * event_action
Definition: arm_tpiu_swo.c:94
struct list_head lh
Definition: arm_tpiu_swo.c:90
struct adiv5_ap * ap
Definition: arm_tpiu_swo.c:92
bool en_formatter
Enable formatter.
Definition: arm_tpiu_swo.c:106
unsigned int traceclkin_freq
frequency of TRACECLKIN (usually matches HCLK)
Definition: arm_tpiu_swo.c:108
unsigned int swo_pin_freq
SWO pin frequency.
Definition: arm_tpiu_swo.c:110
struct adiv5_mem_ap_spot spot
Definition: arm_tpiu_swo.c:91
struct list_head connections
track TCP connections
Definition: arm_tpiu_swo.c:114
unsigned int pin_protocol
output mode
Definition: arm_tpiu_swo.c:104
char * out_filename
where to dump the captured output trace data
Definition: arm_tpiu_swo.c:112
struct arm_tpiu_swo_object * obj
Definition: arm_tpiu_swo.c:126
struct adiv5_ap * debug_ap
Definition: armv7m.h:230
Jim_Interp * interp
Definition: command.h:53
struct target * current_target
Definition: command.h:55
const char * name
Definition: command.h:235
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:241
void * jim_handler_data
Definition: command.h:201
char * name
Definition: command.h:198
struct service * service
Definition: server.h:41
struct armv7m_common armv7m
Definition: cortex_m.h:224
A TCL -ish GetOpt like code.
Definition: jim-nvp.h:136
Jim_Interp * interp
Definition: jim-nvp.h:137
bool is_configure
Definition: jim-nvp.h:140
Jim_Obj *const * argv
Definition: jim-nvp.h:139
Name Value Pairs, aka: NVP.
Definition: jim-nvp.h:60
const char * name
Definition: jim-nvp.h:61
int value
Definition: jim-nvp.h:62
Definition: list.h:40
const char * name
the name of the server
Definition: server.h:49
void * priv
Definition: server.h:81
Definition: target.h:116
void * private_config
Definition: target.h:165
int target_unregister_timer_callback(int(*callback)(void *priv), void *priv)
Definition: target.c:1748
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
Definition: target.c:2641
int target_register_timer_callback(int(*callback)(void *priv), unsigned int time_ms, enum target_timer_type type, void *priv)
The period is very approximate, the callback can happen much more often or much more rarely than spec...
Definition: target.c:1658
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
Definition: target.c:2550
struct target * get_current_target(struct command_context *cmd_ctx)
Definition: target.c:458
void target_handle_event(struct target *target, enum target_event e)
Definition: target.c:4667
const char * target_type_name(const struct target *target)
Get the target type name.
Definition: target.c:736
int target_call_trace_callbacks(struct target *target, size_t len, uint8_t *data)
Definition: target.c:1802
static bool target_was_examined(const struct target *target)
Definition: target.h:436
@ TARGET_TIMER_TYPE_PERIODIC
Definition: target.h:327
@ TARGET_EVENT_TRACE_CONFIG
Definition: target.h:286
static const char * target_name(const struct target *target)
Returns the instance-specific name of the specified target.
Definition: target.h:233
uint64_t target_addr_t
Definition: types.h:335
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1
uint8_t dummy[96]
Definition: vdebug.c:23