1 /***************************************************************************
2 * Copyright (C) 2011 by Mathias Kuester *
3 * Mathias Kuester <kesmtp@freenet.de> *
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. *
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. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
25 /* project specific includes */
26 #include <jtag/interface.h>
27 #include <transport/transport.h>
28 #include <helper/time_support.h>
30 static int jim_newtap_expected_id(Jim_Nvp *n, Jim_GetOptInfo *goi,
31 struct jtag_tap *pTap)
34 int e = Jim_GetOpt_Wide(goi, &w);
36 Jim_SetResultFormatted(goi->interp, "option: %s bad parameter",
41 unsigned expected_len = sizeof(uint32_t) * pTap->expected_ids_cnt;
42 uint32_t *new_expected_ids = malloc(expected_len + sizeof(uint32_t));
43 if (new_expected_ids == NULL) {
44 Jim_SetResultFormatted(goi->interp, "no memory");
48 memcpy(new_expected_ids, pTap->expected_ids, expected_len);
50 new_expected_ids[pTap->expected_ids_cnt] = w;
52 free(pTap->expected_ids);
53 pTap->expected_ids = new_expected_ids;
54 pTap->expected_ids_cnt++;
59 #define NTAP_OPT_EXPECTED_ID 0
61 static int jim_stlink_newtap_cmd(Jim_GetOptInfo *goi)
63 struct jtag_tap *pTap;
68 const Jim_Nvp opts[] = {
69 {.name = "-expected-id", .value = NTAP_OPT_EXPECTED_ID},
70 {.name = NULL, .value = -1},
73 pTap = calloc(1, sizeof(struct jtag_tap));
75 Jim_SetResultFormatted(goi->interp, "no memory");
80 * we expect CHIP + TAP + OPTIONS
83 Jim_SetResultFormatted(goi->interp,
84 "Missing CHIP TAP OPTIONS ....");
88 Jim_GetOpt_String(goi, &cp, NULL);
89 pTap->chip = strdup(cp);
91 Jim_GetOpt_String(goi, &cp, NULL);
92 pTap->tapname = strdup(cp);
94 /* name + dot + name + null */
95 x = strlen(pTap->chip) + 1 + strlen(pTap->tapname) + 1;
97 sprintf(cp, "%s.%s", pTap->chip, pTap->tapname);
98 pTap->dotted_name = cp;
100 LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
101 pTap->chip, pTap->tapname, pTap->dotted_name, goi->argc);
104 e = Jim_GetOpt_Nvp(goi, opts, &n);
106 Jim_GetOpt_NvpUnknown(goi, opts, 0);
107 free((void *)pTap->dotted_name);
111 LOG_DEBUG("Processing option: %s", n->name);
113 case NTAP_OPT_EXPECTED_ID:
114 e = jim_newtap_expected_id(n, goi, pTap);
116 free((void *)pTap->dotted_name);
121 } /* switch (n->value) */
122 } /* while (goi->argc) */
124 /* default is enabled-after-reset */
125 pTap->enabled = !pTap->disabled_after_reset;
131 int jim_stlink_newtap(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
134 Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1);
135 return jim_stlink_newtap_cmd(&goi);