|
31 | 31 | #endif
|
32 | 32 |
|
33 | 33 | #include <helper/align.h>
|
| 34 | +#include <helper/list.h> |
34 | 35 | #include <helper/nvp.h>
|
35 | 36 | #include <helper/time_support.h>
|
36 | 37 | #include <jtag/jtag.h>
|
|
52 | 53 | /* default halt wait timeout (ms) */
|
53 | 54 | #define DEFAULT_HALT_TIMEOUT 5000
|
54 | 55 |
|
| 56 | +struct target_event_action { |
| 57 | + enum target_event event; |
| 58 | + Jim_Interp *interp; |
| 59 | + Jim_Obj *body; |
| 60 | + struct list_head list; |
| 61 | +}; |
| 62 | + |
55 | 63 | static int target_read_buffer_default(struct target *target, target_addr_t address,
|
56 | 64 | uint32_t count, uint8_t *buffer);
|
57 | 65 | static int target_write_buffer_default(struct target *target, target_addr_t address,
|
@@ -2194,12 +2202,11 @@ static void target_destroy(struct target *target)
|
2194 | 2202 |
|
2195 | 2203 | jtag_unregister_event_callback(jtag_enable_callback, target);
|
2196 | 2204 |
|
2197 |
| - struct target_event_action *teap = target->event_action; |
2198 |
| - while (teap) { |
2199 |
| - struct target_event_action *next = teap->next; |
| 2205 | + struct target_event_action *teap, *temp; |
| 2206 | + list_for_each_entry_safe(teap, temp, &target->events_action, list) { |
| 2207 | + list_del(&teap->list); |
2200 | 2208 | Jim_DecrRefCount(teap->interp, teap->body);
|
2201 | 2209 | free(teap);
|
2202 |
| - teap = next; |
2203 | 2210 | }
|
2204 | 2211 |
|
2205 | 2212 | target_free_all_working_areas(target);
|
@@ -4663,7 +4670,7 @@ void target_handle_event(struct target *target, enum target_event e)
|
4663 | 4670 | struct target_event_action *teap;
|
4664 | 4671 | int retval;
|
4665 | 4672 |
|
4666 |
| - for (teap = target->event_action; teap; teap = teap->next) { |
| 4673 | + list_for_each_entry(teap, &target->events_action, list) { |
4667 | 4674 | if (teap->event == e) {
|
4668 | 4675 | LOG_DEBUG("target: %s (%s) event: %d (%s) action: %s",
|
4669 | 4676 | target_name(target),
|
@@ -4826,7 +4833,7 @@ bool target_has_event_action(const struct target *target, enum target_event even
|
4826 | 4833 | {
|
4827 | 4834 | struct target_event_action *teap;
|
4828 | 4835 |
|
4829 |
| - for (teap = target->event_action; teap; teap = teap->next) { |
| 4836 | + list_for_each_entry(teap, &target->events_action, list) { |
4830 | 4837 | if (teap->event == event)
|
4831 | 4838 | return true;
|
4832 | 4839 | }
|
@@ -4946,13 +4953,14 @@ static int target_configure(struct jim_getopt_info *goi, struct target *target)
|
4946 | 4953 | {
|
4947 | 4954 | struct target_event_action *teap;
|
4948 | 4955 |
|
4949 |
| - teap = target->event_action; |
4950 | 4956 | /* replace existing? */
|
4951 |
| - while (teap) { |
| 4957 | + list_for_each_entry(teap, &target->events_action, list) |
4952 | 4958 | if (teap->event == (enum target_event)n->value)
|
4953 | 4959 | break;
|
4954 |
| - teap = teap->next; |
4955 |
| - } |
| 4960 | + |
| 4961 | + /* not found! */ |
| 4962 | + if (&teap->list == &target->events_action) |
| 4963 | + teap = NULL; |
4956 | 4964 |
|
4957 | 4965 | if (goi->is_configure) {
|
4958 | 4966 | /* START_DEPRECATED_TPIU */
|
@@ -4986,8 +4994,7 @@ static int target_configure(struct jim_getopt_info *goi, struct target *target)
|
4986 | 4994 |
|
4987 | 4995 | if (!replace) {
|
4988 | 4996 | /* add to head of event list */
|
4989 |
| - teap->next = target->event_action; |
4990 |
| - target->event_action = teap; |
| 4997 | + list_add(&teap->list, &target->events_action); |
4991 | 4998 | }
|
4992 | 4999 | Jim_SetEmptyResult(goi->interp);
|
4993 | 5000 | } else {
|
@@ -5402,19 +5409,19 @@ COMMAND_HANDLER(handle_target_wait_state)
|
5402 | 5409 | COMMAND_HANDLER(handle_target_event_list)
|
5403 | 5410 | {
|
5404 | 5411 | struct target *target = get_current_target(CMD_CTX);
|
5405 |
| - struct target_event_action *teap = target->event_action; |
| 5412 | + struct target_event_action *teap; |
5406 | 5413 |
|
5407 | 5414 | command_print(CMD, "Event actions for target %s\n",
|
5408 | 5415 | target_name(target));
|
5409 | 5416 | command_print(CMD, "%-25s | Body", "Event");
|
5410 | 5417 | command_print(CMD, "------------------------- | "
|
5411 | 5418 | "----------------------------------------");
|
5412 |
| - while (teap) { |
| 5419 | + |
| 5420 | + list_for_each_entry(teap, &target->events_action, list) |
5413 | 5421 | command_print(CMD, "%-25s | %s",
|
5414 | 5422 | target_event_name(teap->event),
|
5415 | 5423 | Jim_GetString(teap->body, NULL));
|
5416 |
| - teap = teap->next; |
5417 |
| - } |
| 5424 | + |
5418 | 5425 | command_print(CMD, "***END***");
|
5419 | 5426 | return ERROR_OK;
|
5420 | 5427 | }
|
@@ -5767,6 +5774,8 @@ static int target_create(struct jim_getopt_info *goi)
|
5767 | 5774 |
|
5768 | 5775 | target->halt_issued = false;
|
5769 | 5776 |
|
| 5777 | + INIT_LIST_HEAD(&target->events_action); |
| 5778 | + |
5770 | 5779 | /* initialize trace information */
|
5771 | 5780 | target->trace_info = calloc(1, sizeof(struct trace));
|
5772 | 5781 | if (!target->trace_info) {
|
|
0 commit comments