remove more useless declarations
[openocd.git] / src / pld / pld.c
1 /***************************************************************************
2 * Copyright (C) 2006 by Dominic Rath *
3 * Dominic.Rath@gmx.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, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include "pld.h"
25 #include "log.h"
26 #include "time_support.h"
27
28
29 /* pld drivers
30 */
31 extern pld_driver_t virtex2_pld;
32
33 static pld_driver_t *pld_drivers[] =
34 {
35 &virtex2_pld,
36 NULL,
37 };
38
39 static pld_device_t *pld_devices;
40 static command_t *pld_cmd;
41
42 pld_device_t *get_pld_device_by_num(int num)
43 {
44 pld_device_t *p;
45 int i = 0;
46
47 for (p = pld_devices; p; p = p->next)
48 {
49 if (i++ == num)
50 {
51 return p;
52 }
53 }
54
55 return NULL;
56 }
57
58 /* pld device <driver> [driver_options ...]
59 */
60 static int handle_pld_device_command(struct command_context_s *cmd_ctx,
61 char *cmd, char **args, int argc)
62 {
63 int i;
64 int found = 0;
65
66 if (argc < 1)
67 {
68 LOG_WARNING("incomplete 'pld device' command");
69 return ERROR_OK;
70 }
71
72 for (i = 0; pld_drivers[i]; i++)
73 {
74 if (strcmp(args[0], pld_drivers[i]->name) == 0)
75 {
76 pld_device_t *p, *c;
77
78 /* register pld specific commands */
79 if (pld_drivers[i]->register_commands(cmd_ctx) != ERROR_OK)
80 {
81 LOG_ERROR("couldn't register '%s' commands", args[0]);
82 exit(-1);
83 }
84
85 c = malloc(sizeof(pld_device_t));
86 c->driver = pld_drivers[i];
87 c->next = NULL;
88
89 if (pld_drivers[i]->pld_device_command(cmd_ctx, cmd, args, argc, c) != ERROR_OK)
90 {
91 LOG_ERROR("'%s' driver rejected pld device", args[0]);
92 free(c);
93 return ERROR_OK;
94 }
95
96 /* put pld device in linked list */
97 if (pld_devices)
98 {
99 /* find last pld device */
100 for (p = pld_devices; p && p->next; p = p->next);
101 if (p)
102 p->next = c;
103 }
104 else
105 {
106 pld_devices = c;
107 }
108
109 found = 1;
110 }
111 }
112
113 /* no matching pld driver found */
114 if (!found)
115 {
116 LOG_ERROR("pld driver '%s' not found", args[0]);
117 exit(-1);
118 }
119
120 return ERROR_OK;
121 }
122
123 static int handle_pld_devices_command(struct command_context_s *cmd_ctx,
124 char *cmd, char **args, int argc)
125 {
126 pld_device_t *p;
127 int i = 0;
128
129 if (!pld_devices)
130 {
131 command_print(cmd_ctx, "no pld devices configured");
132 return ERROR_OK;
133 }
134
135 for (p = pld_devices; p; p = p->next)
136 {
137 command_print(cmd_ctx, "#%i: %s", i++, p->driver->name);
138 }
139
140 return ERROR_OK;
141 }
142
143 static int handle_pld_load_command(struct command_context_s *cmd_ctx,
144 char *cmd, char **args, int argc)
145 {
146 int retval;
147 struct timeval start, end, duration;
148 pld_device_t *p;
149
150 gettimeofday(&start, NULL);
151
152 if (argc < 2)
153 {
154 command_print(cmd_ctx, "usage: pld load <device#> <file>");
155 return ERROR_OK;
156 }
157
158 unsigned dev_id;
159 COMMAND_PARSE_NUMBER(uint, args[0], dev_id);
160 p = get_pld_device_by_num(dev_id);
161 if (!p)
162 {
163 command_print(cmd_ctx, "pld device '#%s' is out of bounds", args[0]);
164 return ERROR_OK;
165 }
166
167 if ((retval = p->driver->load(p, args[1])) != ERROR_OK)
168 {
169 command_print(cmd_ctx, "failed loading file %s to pld device %u",
170 args[1], dev_id);
171 switch (retval)
172 {
173 }
174 return retval;
175 }
176 else
177 {
178 gettimeofday(&end, NULL);
179 timeval_subtract(&duration, &end, &start);
180
181 command_print(cmd_ctx, "loaded file %s to pld device %u in %jis %jius",
182 args[1], dev_id,
183 (intmax_t)duration.tv_sec, (intmax_t)duration.tv_usec);
184 }
185
186 return ERROR_OK;
187 }
188
189 int pld_init(struct command_context_s *cmd_ctx)
190 {
191 if (!pld_devices)
192 return ERROR_OK;
193
194 register_command(cmd_ctx, pld_cmd, "devices",
195 handle_pld_devices_command, COMMAND_EXEC,
196 "list configured pld devices");
197 register_command(cmd_ctx, pld_cmd, "load",
198 handle_pld_load_command, COMMAND_EXEC,
199 "load configuration <file> into programmable logic device");
200
201 return ERROR_OK;
202 }
203
204 int pld_register_commands(struct command_context_s *cmd_ctx)
205 {
206 pld_cmd = register_command(cmd_ctx, NULL, "pld", NULL, COMMAND_ANY, "programmable logic device commands");
207
208 register_command(cmd_ctx, pld_cmd, "device", handle_pld_device_command, COMMAND_CONFIG, NULL);
209
210 return ERROR_OK;
211 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)