You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

120 lines
3.4 KiB

  1. /*
  2. * Copyright (C) 2016-2017 by Marc Schink
  3. * openocd-dev@marcschink.de
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef OPENOCD_RTT_RTT_H
  19. #define OPENOCD_RTT_RTT_H
  20. #include <stdint.h>
  21. #include <stdbool.h>
  22. #include <helper/command.h>
  23. #include <target/target.h>
  24. #define RTT_MAX_CB_ID_LENGTH 16
  25. #define RTT_MIN_BUFFER_SIZE 2
  26. #define RTT_CB_LENGTH (RTT_MAX_CB_ID_LENGTH + 4 + 4)
  27. #define RTT_BUFFER_LENGTH 24
  28. struct rtt_control {
  29. target_addr_t address;
  30. char id[RTT_MAX_CB_ID_LENGTH + 1];
  31. uint32_t num_up_buffers;
  32. uint32_t num_down_buffers;
  33. };
  34. struct rtt_buffer {
  35. target_addr_t address;
  36. target_addr_t name_addr;
  37. target_addr_t buffer_addr;
  38. uint32_t size;
  39. uint32_t write_offset;
  40. uint32_t read_offset;
  41. uint32_t flags;
  42. };
  43. struct rtt_buffer_info {
  44. char *name;
  45. size_t name_length;
  46. uint32_t size;
  47. uint32_t flags;
  48. };
  49. typedef int (*rtt_sink_read)(unsigned int channel, const uint8_t *buffer,
  50. size_t length, void *user_data);
  51. struct rtt_sink_list {
  52. rtt_sink_read read;
  53. void *user_data;
  54. struct rtt_sink_list *next;
  55. };
  56. enum rtt_channel_type {
  57. RTT_CHANNEL_TYPE_UP,
  58. RTT_CHANNEL_TYPE_DOWN
  59. };
  60. typedef int (*rtt_source_find_ctrl_block)(target_addr_t *address,
  61. size_t length, const char *id, size_t id_length, bool *found,
  62. struct target *target, void *user_data);
  63. typedef int (*rtt_source_read_ctrl_block)(target_addr_t address,
  64. struct rtt_control *ctrl_block, struct target *target,
  65. void *user_data);
  66. typedef int (*rtt_source_read_buffer_info)(const struct rtt_control *ctrl,
  67. unsigned int channel, enum rtt_channel_type type,
  68. struct rtt_buffer_info *info, struct target *target, void *user_data);
  69. typedef int (*rtt_source_start)(const struct rtt_control *ctrl,
  70. struct target *target, void *user_data);
  71. typedef int (*rtt_source_stop)(struct target *target, void *user_data);
  72. typedef int (*rtt_source_read)(const struct rtt_control *ctrl,
  73. struct rtt_sink_list **sinks, size_t num_channels,
  74. struct target *target, void *user_data);
  75. typedef int (*rtt_source_write)(struct rtt_control *ctrl,
  76. unsigned int channel, const uint8_t *buffer, size_t *length,
  77. struct target *target, void *user_data);
  78. struct rtt_source {
  79. rtt_source_find_ctrl_block find_cb;
  80. rtt_source_read_ctrl_block read_cb;
  81. rtt_source_read_buffer_info read_buffer_info;
  82. rtt_source_start start;
  83. rtt_source_stop stop;
  84. rtt_source_read read;
  85. rtt_source_write write;
  86. };
  87. int rtt_init(void);
  88. int rtt_exit(void);
  89. int rtt_register_source(const struct rtt_source source, struct target *target);
  90. int rtt_start(void);
  91. int rtt_stop(void);
  92. int rtt_register_sink(unsigned int channel, rtt_sink_read read,
  93. void *user_data);
  94. int rtt_unregister_sink(unsigned int channel, rtt_sink_read read,
  95. void *user_data);
  96. int rtt_write_channel(unsigned int channel, const uint8_t *buffer,
  97. size_t *length);
  98. int rtt_register_commands(struct command_context *ctx);
  99. #endif /* OPENOCD_RTT_RTT_H */