├── LICENSE
├── README.md
├── images
└── my_setup.jpg
├── lenval.cpp
├── lenval.h
├── micro.cpp
├── micro.h
├── ports.cpp
├── ports.h
├── tools
└── send_xsvf
└── xsvfduino.ino
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | xsvfduino
2 | =========
3 |
4 | An Arduino (currently the Blue Pill variant) as an XSVF player to program CPLD's and FPGA's based on a reference implementation by Xilinx (Keep reading for Altera). It works by receiving an XSVF file via the USB-serial interface, interpreting it as a sequence of instructions, and then bit banging the JTAG signals that are needed to program the target device.
5 |
6 | I have tested and successfully programmed the following CPLDs:
7 |
8 | - Xilinx XC2C64A
9 | - Xilinx XC9572XL
10 | - Altera MAX II EPM240T100C5 (I used dangerous prototypes svf2xsvf converter to convert Altera's svf file to the compressed xsvf file, although that program doesn't claim to support this device)
11 |
12 | INSTRUCTIONS
13 | ============
14 |
15 | 1. Know your Arduino: http://wiki.stm32duino.com/index.php?title=Blue_Pill
16 | 2. Download the project contents somewhere on your computer.
17 | 3. If you don't have it, install Roger Clark's support for Arduino available from https://github.com/rogerclarkmelbourne/Arduino_STM32
18 | 4. Open the xsvduino.ino on the Arduino IDE
19 | 5. On the tools menu, use the following settings:
20 | Board: "Generic STM32F103CB series"
21 | 6. On the same menu, choose your upload method. I find the ST-Link method to be the easiest, but look there for other options or check out this link: https://medium.com/@paramaggarwal/converting-an-stm32f103-board-to-a-black-magic-probe-c013cf2cc38c
22 | 7. Unplug the ST-Link programmer if you are using one, and then plug the Blue Pill to your computer with a USB cable. An LED
23 | starts blinking on the Blue Pill it should be seen by the OS as a new serial device. On OSX this is something like /dev/tty.usbmodem1411, and on Linux something like /dev/ttyACM0. I'm not sure how this works on Windows, but I guess a new COM port should present itself to you (hopefully).
24 | 8. Find the send_xsvf tool on the tools folder. This a Python script to upload a file to the xsvfduino.
25 | 9. Upload your XSVF file using a command like this:
26 | `./send_xsvf -p /dev/tty.your_arduino_serial_port somefile.xsvf`
27 |
28 | JTAG INTERFACE PINOUT
29 | =====================
30 |
31 | This is defined in ports.h:
32 |
33 | - **TCK** -- PB6 (output)
34 | - **TMS** -- PB7 (output)
35 | - **TDI** -- PB8 (output)
36 | - **TDO** -- PB9 (input with internal pullup)
37 |
38 | WARNING
39 | =======
40 | This is a very early WIP, almost a proof of concept. It is working for me on an STM32 Arduino clone (the Blue Pill) but it's ugly, and probably will take a lot of effort before it becomes a decent tool. I tested it to program a Xilinx XC2C64A CPLD, a Xilinx XC9572XL and even an Altera MAX II EPM240T100C5 with success. I chose the Blue Pill because I had one taking dust on my benchtop, it has enough memory to hold the code and the data, and it's darn cheap.
41 |
42 | I tried using Daniel Fekete's Generic STM32 support, but unfortunately I came accross some bug in the pinMode/digitalRead functions which caused a pin which had been set as INPUT_PULLUP to read as zero even if nothing was connected to it. Clark's package works fine.
43 |
44 | Be aware that most devices out there run on 3.3V or less (some are 1.8V) and might not be 5V-tolerant, so make sure you use adequate level shifters, if they are required for your chip. Otherwise you could see some magic smoke! The Blue Pill runs on 3.3V, the same voltage of all the CPLDs I tested, so I just hooked them up directly to the indicated GPIO pins.
45 |
46 | DISCLAIMER
47 | ==========
48 | I am not a developer and programming is not my thing. I am posting this in the hopes that it might be useful to someone out there. Use it at your own risk and don't blame me if it bricks your beloved CPLD/FPGA, if it scares your dog, or anything. It probably just won't work as you'd expect, but who knows?
49 |
50 | CREDITS
51 | =======
52 | This project was inspired by Mike Tsao's [JTAGWhispeer](https://github.com/sowbug/JTAGWhisperer) which sadly seems to have been discontinued. Mine is a crude attempt at picking up where Mike has left off.
53 |
--------------------------------------------------------------------------------
/images/my_setup.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wschutzer/xsvfduino/3206f1e78c25371288383b8b33aaccd7906544e3/images/my_setup.jpg
--------------------------------------------------------------------------------
/lenval.cpp:
--------------------------------------------------------------------------------
1 | /*******************************************************/
2 | /* file: lenval.c */
3 | /* abstract: This file contains routines for using */
4 | /* the lenVal data structure. */
5 | /*******************************************************/
6 | #include "lenval.h"
7 | #include "ports.h"
8 |
9 | /*****************************************************************************
10 | * Function: value
11 | * Description: Extract the long value from the lenval array.
12 | * Parameters: plvValue - ptr to lenval.
13 | * Returns: long - the extracted value.
14 | *****************************************************************************/
15 | long value( lenVal* plvValue )
16 | {
17 | long lValue; /* result to hold the accumulated result */
18 | short sIndex;
19 |
20 | lValue = 0;
21 | for ( sIndex = 0; sIndex < plvValue->len ; ++sIndex )
22 | {
23 | lValue <<= 8; /* shift the accumulated result */
24 | lValue |= plvValue->val[ sIndex]; /* get the last byte first */
25 | }
26 |
27 | return( lValue );
28 | }
29 |
30 | /*****************************************************************************
31 | * Function: initLenVal
32 | * Description: Initialize the lenval array with the given value.
33 | * Assumes lValue is less than 256.
34 | * Parameters: plv - ptr to lenval.
35 | * lValue - the value to set.
36 | * Returns: void.
37 | *****************************************************************************/
38 | void initLenVal( lenVal* plv,
39 | long lValue )
40 | {
41 | plv->len = 1;
42 | plv->val[0] = (unsigned char)lValue;
43 | }
44 |
45 | /*****************************************************************************
46 | * Function: EqualLenVal
47 | * Description: Compare two lenval arrays with an optional mask.
48 | * Parameters: plvTdoExpected - ptr to lenval #1.
49 | * plvTdoCaptured - ptr to lenval #2.
50 | * plvTdoMask - optional ptr to mask (=0 if no mask).
51 | * Returns: short - 0 = mismatch; 1 = equal.
52 | *****************************************************************************/
53 | short EqualLenVal( lenVal* plvTdoExpected,
54 | lenVal* plvTdoCaptured,
55 | lenVal* plvTdoMask )
56 | {
57 | short sEqual;
58 | short sIndex;
59 | unsigned char ucByteVal1;
60 | unsigned char ucByteVal2;
61 | unsigned char ucByteMask;
62 |
63 | sEqual = 1;
64 | sIndex = plvTdoExpected->len;
65 |
66 | while ( sEqual && sIndex-- )
67 | {
68 | ucByteVal1 = plvTdoExpected->val[ sIndex ];
69 | ucByteVal2 = plvTdoCaptured->val[ sIndex ];
70 | if ( plvTdoMask )
71 | {
72 | ucByteMask = plvTdoMask->val[ sIndex ];
73 | ucByteVal1 &= ucByteMask;
74 | ucByteVal2 &= ucByteMask;
75 | }
76 | if ( ucByteVal1 != ucByteVal2 )
77 | {
78 | sEqual = 0;
79 | }
80 | }
81 |
82 | return( sEqual );
83 | }
84 |
85 |
86 | /*****************************************************************************
87 | * Function: RetBit
88 | * Description: return the (byte, bit) of lv (reading from left to right).
89 | * Parameters: plv - ptr to lenval.
90 | * iByte - the byte to get the bit from.
91 | * iBit - the bit number (0=msb)
92 | * Returns: short - the bit value.
93 | *****************************************************************************/
94 | short RetBit( lenVal* plv,
95 | int iByte,
96 | int iBit )
97 | {
98 | /* assert( ( iByte >= 0 ) && ( iByte < plv->len ) ); */
99 | /* assert( ( iBit >= 0 ) && ( iBit < 8 ) ); */
100 | return( (short)( ( plv->val[ iByte ] >> ( 7 - iBit ) ) & 0x1 ) );
101 | }
102 |
103 | /*****************************************************************************
104 | * Function: SetBit
105 | * Description: set the (byte, bit) of lv equal to val
106 | * Example: SetBit("00000000",byte, 1) equals "01000000".
107 | * Parameters: plv - ptr to lenval.
108 | * iByte - the byte to get the bit from.
109 | * iBit - the bit number (0=msb).
110 | * sVal - the bit value to set.
111 | * Returns: void.
112 | *****************************************************************************/
113 | void SetBit( lenVal* plv,
114 | int iByte,
115 | int iBit,
116 | short sVal )
117 | {
118 | unsigned char ucByteVal;
119 | unsigned char ucBitMask;
120 |
121 | ucBitMask = (unsigned char)(1 << ( 7 - iBit ));
122 | ucByteVal = (unsigned char)(plv->val[ iByte ] & (~ucBitMask));
123 |
124 | if ( sVal )
125 | {
126 | ucByteVal |= ucBitMask;
127 | }
128 | plv->val[ iByte ] = ucByteVal;
129 | }
130 |
131 | /*****************************************************************************
132 | * Function: AddVal
133 | * Description: add val1 to val2 and store in resVal;
134 | * assumes val1 and val2 are of equal length.
135 | * Parameters: plvResVal - ptr to result.
136 | * plvVal1 - ptr of addendum.
137 | * plvVal2 - ptr of addendum.
138 | * Returns: void.
139 | *****************************************************************************/
140 | void addVal( lenVal* plvResVal,
141 | lenVal* plvVal1,
142 | lenVal* plvVal2 )
143 | {
144 | unsigned char ucCarry;
145 | unsigned short usSum;
146 | unsigned short usVal1;
147 | unsigned short usVal2;
148 | short sIndex;
149 |
150 | plvResVal->len = plvVal1->len; /* set up length of result */
151 |
152 | /* start at least significant bit and add bytes */
153 | ucCarry = 0;
154 | sIndex = plvVal1->len;
155 | while ( sIndex-- )
156 | {
157 | usVal1 = plvVal1->val[ sIndex ]; /* i'th byte of val1 */
158 | usVal2 = plvVal2->val[ sIndex ]; /* i'th byte of val2 */
159 |
160 | /* add the two bytes plus carry from previous addition */
161 | usSum = (unsigned short)( usVal1 + usVal2 + ucCarry );
162 |
163 | /* set up carry for next byte */
164 | ucCarry = (unsigned char)( ( usSum > 255 ) ? 1 : 0 );
165 |
166 | /* set the i'th byte of the result */
167 | plvResVal->val[ sIndex ] = (unsigned char)usSum;
168 | }
169 | }
170 |
171 | /*****************************************************************************
172 | * Function: readVal
173 | * Description: read from XSVF numBytes bytes of data into x.
174 | * Parameters: plv - ptr to lenval in which to put the bytes read.
175 | * sNumBytes - the number of bytes to read.
176 | * Returns: void.
177 | *****************************************************************************/
178 | void readVal( lenVal* plv,
179 | short sNumBytes )
180 | {
181 | unsigned char* pucVal;
182 |
183 | plv->len = sNumBytes; /* set the length of the lenVal */
184 | for ( pucVal = plv->val; sNumBytes; --sNumBytes, ++pucVal )
185 | {
186 | /* read a byte of data into the lenVal */
187 | readByte( pucVal );
188 | }
189 | }
190 |
191 |
--------------------------------------------------------------------------------
/lenval.h:
--------------------------------------------------------------------------------
1 | /*******************************************************/
2 | /* file: lenval.h */
3 | /* abstract: This file contains a description of the */
4 | /* data structure "lenval". */
5 | /*******************************************************/
6 |
7 | #ifndef lenval_dot_h
8 | #define lenval_dot_h
9 |
10 | /* the lenVal structure is a byte oriented type used to store an */
11 | /* arbitrary length binary value. As an example, the hex value */
12 | /* 0x0e3d is represented as a lenVal with len=2 (since 2 bytes */
13 | /* and val[0]=0e and val[1]=3d. val[2-MAX_LEN] are undefined */
14 |
15 | /* maximum length (in bytes) of value to read in */
16 | /* this needs to be at least 4, and longer than the */
17 | /* length of the longest SDR instruction. If there is, */
18 | /* only 1 device in the chain, MAX_LEN must be at least */
19 | /* ceil(27/8) == 4. For 6 devices in a chain, MAX_LEN */
20 | /* must be 5, for 14 devices MAX_LEN must be 6, for 20 */
21 | /* devices MAX_LEN must be 7, etc.. */
22 | /* You can safely set MAX_LEN to a smaller number if you*/
23 | /* know how many devices will be in your chain. */
24 | /* #define MAX_LEN (Actual #define is below this comment block)
25 | This #define defines the maximum length (in bytes) of predefined
26 | buffers in which the XSVF player stores the current shift data.
27 | This length must be greater than the longest shift length (in bytes)
28 | in the XSVF files that will be processed. 7000 is a very conservative
29 | number. The buffers are stored on the stack and if you have limited
30 | stack space, you may decrease the MAX_LEN value.
31 |
32 | How to find the "shift length" in bits?
33 | Look at the ASCII version of the XSVF (generated with the -a option
34 | for the SVF2XSVF translator) and search for the XSDRSIZE command
35 | with the biggest parameter. XSDRSIZE is equivalent to the SVF's
36 | SDR length plus the lengths of applicable HDR and TDR commands.
37 | Remember that the MAX_LEN is defined in bytes. Therefore, the
38 | minimum MAX_LEN = ceil( max( XSDRSIZE ) / 8 );
39 |
40 | The following MAX_LEN values have been tested and provide relatively
41 | good margin for the corresponding devices:
42 |
43 | DEVICE MAX_LEN Resulting Shift Length Max (in bits)
44 | --------- ------- ----------------------------------------------
45 | XC9500/XL/XV 32 256
46 |
47 | CoolRunner/II 256 2048 - actual max 1 device = 1035 bits
48 |
49 | FPGA 128 1024 - svf2xsvf -rlen 1024
50 |
51 | XC18V00/XCF00
52 | 1100 8800 - no blank check performed (default)
53 | - actual max 1 device = 8192 bits verify
54 | - max 1 device = 4096 bits program-only
55 |
56 | XC18V00/XCF00 when using the optional Blank Check operation
57 | 2500 20000 - required for blank check
58 | - blank check max 1 device = 16384 bits
59 | */
60 | #define MAX_LEN 256
61 |
62 |
63 | typedef struct var_len_byte
64 | {
65 | short len; /* number of chars in this value */
66 | unsigned char val[MAX_LEN+1]; /* bytes of data */
67 | } lenVal;
68 |
69 |
70 | /* return the long representation of a lenVal */
71 | extern long value(lenVal *x);
72 |
73 | /* set lenVal equal to value */
74 | extern void initLenVal(lenVal *x, long value);
75 |
76 | /* check if expected equals actual (taking the mask into account) */
77 | extern short EqualLenVal(lenVal *expected, lenVal *actual, lenVal *mask);
78 |
79 | /* add val1+val2 and put the result in resVal */
80 | extern void addVal(lenVal *resVal, lenVal *val1, lenVal *val2);
81 |
82 | /* return the (byte, bit) of lv (reading from left to right) */
83 | extern short RetBit(lenVal *lv, int byte, int bit);
84 |
85 | /* set the (byte, bit) of lv equal to val (e.g. SetBit("00000000",byte, 1)
86 | equals "01000000" */
87 | extern void SetBit(lenVal *lv, int byte, int bit, short val);
88 |
89 | /* read from XSVF numBytes bytes of data into x */
90 | extern void readVal(lenVal *x, short numBytes);
91 |
92 | #endif
93 |
94 |
--------------------------------------------------------------------------------
/micro.cpp:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * file: micro.c
3 | * abstract: This file contains the function, xsvfExecute(),
4 | * call for interpreting the XSVF commands.
5 | * Usage: Call xsvfExecute() to process XSVF data.
6 | * The XSVF data is retrieved by readByte() in ports.c
7 | * Remove the main function if you already have one.
8 | * Options: XSVF_SUPPORT_COMPRESSION
9 | * This define supports the XC9500/XL compression scheme.
10 | * This define adds support for XSDRINC and XSETSDRMASKS.
11 | * XSVF_SUPPORT_ERRORCODES
12 | * This define causes the xsvfExecute function to return
13 | * an error code for specific errors. See error codes below.
14 | * If this is not defined, the return value defaults to the
15 | * legacy values for backward compatibility:
16 | * 1 = success; 0 = failure.
17 | * Debugging: DEBUG_MODE (Legacy name)
18 | * Define DEBUG_MODE to compile with debugging features.
19 | * Both micro.c and ports.c must be compiled with the DEBUG_MODE
20 | * defined to enable the standalone main implementation in
21 | * micro.c that reads XSVF from a file.
22 | * History: v2.00 - Original XSVF implementation.
23 | * v4.04 - Added delay at end of XSIR for XC18v00 support.
24 | * Added new commands for CoolRunner support:
25 | * XSTATE, XENDIR, XENDDR
26 | * v4.05 - Cleanup micro.c but leave ports.c intact.
27 | * v4.06 - Fix xsvfGotoTapState for retry transition.
28 | * v4.07 - Update example waitTime implementations for
29 | * compatibility with Virtex-II.
30 | * v4.10 - Add new XSIR2 command that supports a 2-byte
31 | * IR-length parameter for IR shifts > 255 bits.
32 | * v4.11 - No change. Update version to match SVF2XSVF xlator.
33 | * v4.14 - Added XCOMMENT.
34 | * v5.00 - Improve XSTATE support.
35 | * Added XWAIT.
36 | * v5.01 - make sure that TCK is low during RUNTEST wait for
37 | * XC18V00/XCF00 support. Only change is in PORTS.C
38 | * waitTime() function for implementations that do NOT
39 | * pulse TCK during the waitTime.
40 | *****************************************************************************/
41 |
42 | /*============================================================================
43 | * #pragmas
44 | ============================================================================*/
45 | #ifdef _MSC_VER
46 | #pragma warning( disable : 4100 )
47 | #endif /* _MSC_VER */
48 |
49 | /*============================================================================
50 | * #include files
51 | ============================================================================*/
52 | #define DEBUG_MODE
53 | #ifdef DEBUG_MODE
54 | #include
55 | #include
56 | #include
57 | #include
58 | #endif /* DEBUG_MODE */
59 |
60 | #include "micro.h"
61 | #include "lenval.h"
62 | #include "ports.h"
63 |
64 |
65 | /*============================================================================
66 | * XSVF #define
67 | ============================================================================*/
68 |
69 | #define XSVF_VERSION "5.01"
70 |
71 | /*****************************************************************************
72 | * Define: XSVF_SUPPORT_COMPRESSION
73 | * Description: Define this to support the XC9500/XL XSVF data compression
74 | * scheme.
75 | * Code size can be reduced by NOT supporting this feature.
76 | * However, you must use the -nc (no compress) option when
77 | * translating SVF to XSVF using the SVF2XSVF translator.
78 | * Corresponding, uncompressed XSVF may be larger.
79 | *****************************************************************************/
80 | #ifndef XSVF_SUPPORT_COMPRESSION
81 | #define XSVF_SUPPORT_COMPRESSION 1
82 | #endif
83 |
84 | /*****************************************************************************
85 | * Define: XSVF_SUPPORT_ERRORCODES
86 | * Description: Define this to support the new XSVF error codes.
87 | * (The original XSVF player just returned 1 for success and
88 | * 0 for an unspecified failure.)
89 | *****************************************************************************/
90 | #ifndef XSVF_SUPPORT_ERRORCODES
91 | #define XSVF_SUPPORT_ERRORCODES 1
92 | #endif
93 |
94 | #ifdef XSVF_SUPPORT_ERRORCODES
95 | #define XSVF_ERRORCODE(errorCode) errorCode
96 | #else /* Use legacy error code */
97 | #define XSVF_ERRORCODE(errorCode) ((errorCode==XSVF_ERROR_NONE)?1:0)
98 | #endif /* XSVF_SUPPORT_ERRORCODES */
99 |
100 |
101 | /*****************************************************************************
102 | * Define: XSVF_MAIN
103 | * Description: Define this to compile with a main function for standalone
104 | * debugging.
105 | *****************************************************************************/
106 | #ifndef XSVF_MAIN
107 | #ifdef DEBUG_MODE
108 | #define XSVF_MAIN 1
109 | #endif /* DEBUG_MODE */
110 | #endif /* XSVF_MAIN */
111 |
112 |
113 | /*============================================================================
114 | * DEBUG_MODE #define
115 | ============================================================================*/
116 |
117 | #ifdef DEBUG_MODE
118 | extern void debug_printf(char *format,...);
119 |
120 | #define XSVFDBG_PRINTF(iDebugLevel,pzFormat) \
121 | { if ( xsvf_iDebugLevel >= iDebugLevel ) \
122 | debug_printf( pzFormat ); }
123 | #define XSVFDBG_PRINTF1(iDebugLevel,pzFormat,arg1) \
124 | { if ( xsvf_iDebugLevel >= iDebugLevel ) \
125 | debug_printf( pzFormat, arg1 ); }
126 | #define XSVFDBG_PRINTF2(iDebugLevel,pzFormat,arg1,arg2) \
127 | { if ( xsvf_iDebugLevel >= iDebugLevel ) \
128 | debug_printf( pzFormat, arg1, arg2 ); }
129 | #define XSVFDBG_PRINTF3(iDebugLevel,pzFormat,arg1,arg2,arg3) \
130 | { if ( xsvf_iDebugLevel >= iDebugLevel ) \
131 | debug_printf( pzFormat, arg1, arg2, arg3 ); }
132 | #define XSVFDBG_PRINTLENVAL(iDebugLevel,plenVal) \
133 | { if ( xsvf_iDebugLevel >= iDebugLevel ) \
134 | xsvfPrintLenVal(plenVal); }
135 | #else /* !DEBUG_MODE */
136 | #define XSVFDBG_PRINTF(iDebugLevel,pzFormat)
137 | #define XSVFDBG_PRINTF1(iDebugLevel,pzFormat,arg1)
138 | #define XSVFDBG_PRINTF2(iDebugLevel,pzFormat,arg1,arg2)
139 | #define XSVFDBG_PRINTF3(iDebugLevel,pzFormat,arg1,arg2,arg3)
140 | #define XSVFDBG_PRINTLENVAL(iDebugLevel,plenVal)
141 | #endif /* DEBUG_MODE */
142 |
143 |
144 | /*============================================================================
145 | * XSVF Type Declarations
146 | ============================================================================*/
147 |
148 | /*****************************************************************************
149 | * Struct: SXsvfInfo
150 | * Description: This structure contains all of the data used during the
151 | * execution of the XSVF. Some data is persistent, predefined
152 | * information (e.g. lRunTestTime). The bulk of this struct's
153 | * size is due to the lenVal structs (defined in lenval.h)
154 | * which contain buffers for the active shift data. The MAX_LEN
155 | * #define in lenval.h defines the size of these buffers.
156 | * These buffers must be large enough to store the longest
157 | * shift data in your XSVF file. For example:
158 | * MAX_LEN >= ( longest_shift_data_in_bits / 8 )
159 | * Because the lenVal struct dominates the space usage of this
160 | * struct, the rough size of this struct is:
161 | * sizeof( SXsvfInfo ) ~= MAX_LEN * 7 (number of lenVals)
162 | * xsvfInitialize() contains initialization code for the data
163 | * in this struct.
164 | * xsvfCleanup() contains cleanup code for the data in this
165 | * struct.
166 | *****************************************************************************/
167 | typedef struct tagSXsvfInfo
168 | {
169 | /* XSVF status information */
170 | unsigned char ucComplete; /* 0 = running; 1 = complete */
171 | unsigned char ucCommand; /* Current XSVF command byte */
172 | long lCommandCount; /* Number of commands processed */
173 | int iErrorCode; /* An error code. 0 = no error. */
174 |
175 | /* TAP state/sequencing information */
176 | unsigned char ucTapState; /* Current TAP state */
177 | unsigned char ucEndIR; /* ENDIR TAP state (See SVF) */
178 | unsigned char ucEndDR; /* ENDDR TAP state (See SVF) */
179 |
180 | /* RUNTEST information */
181 | unsigned char ucMaxRepeat; /* Max repeat loops (for xc9500/xl) */
182 | long lRunTestTime; /* Pre-specified RUNTEST time (usec) */
183 |
184 | /* Shift Data Info and Buffers */
185 | long lShiftLengthBits; /* Len. current shift data in bits */
186 | short sShiftLengthBytes; /* Len. current shift data in bytes */
187 |
188 | lenVal lvTdi; /* Current TDI shift data */
189 | lenVal lvTdoExpected; /* Expected TDO shift data */
190 | lenVal lvTdoCaptured; /* Captured TDO shift data */
191 | lenVal lvTdoMask; /* TDO mask: 0=dontcare; 1=compare */
192 |
193 | #ifdef XSVF_SUPPORT_COMPRESSION
194 | /* XSDRINC Data Buffers */
195 | lenVal lvAddressMask; /* Address mask for XSDRINC */
196 | lenVal lvDataMask; /* Data mask for XSDRINC */
197 | lenVal lvNextData; /* Next data for XSDRINC */
198 | #endif /* XSVF_SUPPORT_COMPRESSION */
199 | } SXsvfInfo;
200 |
201 | /* Declare pointer to functions that perform XSVF commands */
202 | typedef int (*TXsvfDoCmdFuncPtr)( SXsvfInfo* );
203 |
204 |
205 | /*============================================================================
206 | * XSVF Command Bytes
207 | ============================================================================*/
208 |
209 | /* encodings of xsvf instructions */
210 | #define XCOMPLETE 0
211 | #define XTDOMASK 1
212 | #define XSIR 2
213 | #define XSDR 3
214 | #define XRUNTEST 4
215 | /* Reserved 5 */
216 | /* Reserved 6 */
217 | #define XREPEAT 7
218 | #define XSDRSIZE 8
219 | #define XSDRTDO 9
220 | #define XSETSDRMASKS 10
221 | #define XSDRINC 11
222 | #define XSDRB 12
223 | #define XSDRC 13
224 | #define XSDRE 14
225 | #define XSDRTDOB 15
226 | #define XSDRTDOC 16
227 | #define XSDRTDOE 17
228 | #define XSTATE 18 /* 4.00 */
229 | #define XENDIR 19 /* 4.04 */
230 | #define XENDDR 20 /* 4.04 */
231 | #define XSIR2 21 /* 4.10 */
232 | #define XCOMMENT 22 /* 4.14 */
233 | #define XWAIT 23 /* 5.00 */
234 | /* Insert new commands here */
235 | /* and add corresponding xsvfDoCmd function to xsvf_pfDoCmd below. */
236 | #define XLASTCMD 24 /* Last command marker */
237 |
238 |
239 | /*============================================================================
240 | * XSVF Command Parameter Values
241 | ============================================================================*/
242 |
243 | #define XSTATE_RESET 0 /* 4.00 parameter for XSTATE */
244 | #define XSTATE_RUNTEST 1 /* 4.00 parameter for XSTATE */
245 |
246 | #define XENDXR_RUNTEST 0 /* 4.04 parameter for XENDIR/DR */
247 | #define XENDXR_PAUSE 1 /* 4.04 parameter for XENDIR/DR */
248 |
249 | /* TAP states */
250 | #define XTAPSTATE_RESET 0x00
251 | #define XTAPSTATE_RUNTEST 0x01 /* a.k.a. IDLE */
252 | #define XTAPSTATE_SELECTDR 0x02
253 | #define XTAPSTATE_CAPTUREDR 0x03
254 | #define XTAPSTATE_SHIFTDR 0x04
255 | #define XTAPSTATE_EXIT1DR 0x05
256 | #define XTAPSTATE_PAUSEDR 0x06
257 | #define XTAPSTATE_EXIT2DR 0x07
258 | #define XTAPSTATE_UPDATEDR 0x08
259 | #define XTAPSTATE_IRSTATES 0x09 /* All IR states begin here */
260 | #define XTAPSTATE_SELECTIR 0x09
261 | #define XTAPSTATE_CAPTUREIR 0x0A
262 | #define XTAPSTATE_SHIFTIR 0x0B
263 | #define XTAPSTATE_EXIT1IR 0x0C
264 | #define XTAPSTATE_PAUSEIR 0x0D
265 | #define XTAPSTATE_EXIT2IR 0x0E
266 | #define XTAPSTATE_UPDATEIR 0x0F
267 |
268 | /*============================================================================
269 | * XSVF Function Prototypes
270 | ============================================================================*/
271 |
272 | int xsvfDoIllegalCmd( SXsvfInfo* pXsvfInfo ); /* Illegal command function */
273 | int xsvfDoXCOMPLETE( SXsvfInfo* pXsvfInfo );
274 | int xsvfDoXTDOMASK( SXsvfInfo* pXsvfInfo );
275 | int xsvfDoXSIR( SXsvfInfo* pXsvfInfo );
276 | int xsvfDoXSIR2( SXsvfInfo* pXsvfInfo );
277 | int xsvfDoXSDR( SXsvfInfo* pXsvfInfo );
278 | int xsvfDoXRUNTEST( SXsvfInfo* pXsvfInfo );
279 | int xsvfDoXREPEAT( SXsvfInfo* pXsvfInfo );
280 | int xsvfDoXSDRSIZE( SXsvfInfo* pXsvfInfo );
281 | int xsvfDoXSDRTDO( SXsvfInfo* pXsvfInfo );
282 | int xsvfDoXSETSDRMASKS( SXsvfInfo* pXsvfInfo );
283 | int xsvfDoXSDRINC( SXsvfInfo* pXsvfInfo );
284 | int xsvfDoXSDRBCE( SXsvfInfo* pXsvfInfo );
285 | int xsvfDoXSDRTDOBCE( SXsvfInfo* pXsvfInfo );
286 | int xsvfDoXSTATE( SXsvfInfo* pXsvfInfo );
287 | int xsvfDoXENDXR( SXsvfInfo* pXsvfInfo );
288 | int xsvfDoXCOMMENT( SXsvfInfo* pXsvfInfo );
289 | int xsvfDoXWAIT( SXsvfInfo* pXsvfInfo );
290 | /* Insert new command functions here */
291 |
292 | /*============================================================================
293 | * XSVF Global Variables
294 | ============================================================================*/
295 |
296 | /* Array of XSVF command functions. Must follow command byte value order! */
297 | /* If your compiler cannot take this form, then convert to a switch statement*/
298 | TXsvfDoCmdFuncPtr xsvf_pfDoCmd[] =
299 | {
300 | xsvfDoXCOMPLETE, /* 0 */
301 | xsvfDoXTDOMASK, /* 1 */
302 | xsvfDoXSIR, /* 2 */
303 | xsvfDoXSDR, /* 3 */
304 | xsvfDoXRUNTEST, /* 4 */
305 | xsvfDoIllegalCmd, /* 5 */
306 | xsvfDoIllegalCmd, /* 6 */
307 | xsvfDoXREPEAT, /* 7 */
308 | xsvfDoXSDRSIZE, /* 8 */
309 | xsvfDoXSDRTDO, /* 9 */
310 | #ifdef XSVF_SUPPORT_COMPRESSION
311 | xsvfDoXSETSDRMASKS, /* 10 */
312 | xsvfDoXSDRINC, /* 11 */
313 | #else
314 | xsvfDoIllegalCmd, /* 10 */
315 | xsvfDoIllegalCmd, /* 11 */
316 | #endif /* XSVF_SUPPORT_COMPRESSION */
317 | xsvfDoXSDRBCE, /* 12 */
318 | xsvfDoXSDRBCE, /* 13 */
319 | xsvfDoXSDRBCE, /* 14 */
320 | xsvfDoXSDRTDOBCE, /* 15 */
321 | xsvfDoXSDRTDOBCE, /* 16 */
322 | xsvfDoXSDRTDOBCE, /* 17 */
323 | xsvfDoXSTATE, /* 18 */
324 | xsvfDoXENDXR, /* 19 */
325 | xsvfDoXENDXR, /* 20 */
326 | xsvfDoXSIR2, /* 21 */
327 | xsvfDoXCOMMENT, /* 22 */
328 | xsvfDoXWAIT /* 23 */
329 | /* Insert new command functions here */
330 | };
331 |
332 | #ifdef DEBUG_MODE
333 | char* xsvf_pzCommandName[] =
334 | {
335 | "XCOMPLETE",
336 | "XTDOMASK",
337 | "XSIR",
338 | "XSDR",
339 | "XRUNTEST",
340 | "Reserved5",
341 | "Reserved6",
342 | "XREPEAT",
343 | "XSDRSIZE",
344 | "XSDRTDO",
345 | "XSETSDRMASKS",
346 | "XSDRINC",
347 | "XSDRB",
348 | "XSDRC",
349 | "XSDRE",
350 | "XSDRTDOB",
351 | "XSDRTDOC",
352 | "XSDRTDOE",
353 | "XSTATE",
354 | "XENDIR",
355 | "XENDDR",
356 | "XSIR2",
357 | "XCOMMENT",
358 | "XWAIT"
359 | };
360 |
361 | char* xsvf_pzErrorName[] =
362 | {
363 | "No error",
364 | "ERROR: Unknown",
365 | "ERROR: TDO mismatch",
366 | "ERROR: TDO mismatch and exceeded max retries",
367 | "ERROR: Unsupported XSVF command",
368 | "ERROR: Illegal state specification",
369 | "ERROR: Data overflows allocated MAX_LEN buffer size"
370 | };
371 |
372 | char* xsvf_pzTapState[] =
373 | {
374 | "RESET", /* 0x00 */
375 | "RUNTEST/IDLE", /* 0x01 */
376 | "DRSELECT", /* 0x02 */
377 | "DRCAPTURE", /* 0x03 */
378 | "DRSHIFT", /* 0x04 */
379 | "DREXIT1", /* 0x05 */
380 | "DRPAUSE", /* 0x06 */
381 | "DREXIT2", /* 0x07 */
382 | "DRUPDATE", /* 0x08 */
383 | "IRSELECT", /* 0x09 */
384 | "IRCAPTURE", /* 0x0A */
385 | "IRSHIFT", /* 0x0B */
386 | "IREXIT1", /* 0x0C */
387 | "IRPAUSE", /* 0x0D */
388 | "IREXIT2", /* 0x0E */
389 | "IRUPDATE" /* 0x0F */
390 | };
391 | #endif /* DEBUG_MODE */
392 |
393 | #ifdef DEBUG_MODE
394 | // FILE* in; /* Legacy DEBUG_MODE file pointer */
395 | int xsvf_iDebugLevel = 7;
396 | #endif /* DEBUG_MODE */
397 |
398 | /*============================================================================
399 | * Utility Functions
400 | ============================================================================*/
401 |
402 | /*****************************************************************************
403 | * Function: xsvfPrintLenVal
404 | * Description: Print the lenval value in hex.
405 | * Parameters: plv - ptr to lenval.
406 | * Returns: void.
407 | *****************************************************************************/
408 | #ifdef DEBUG_MODE
409 | void xsvfPrintLenVal( lenVal *plv )
410 | {
411 | int i;
412 |
413 | if ( plv )
414 | {
415 | debug_printf( "0x" );
416 | for ( i = 0; i < plv->len; ++i )
417 | {
418 | debug_printf( "%02x", ((unsigned int)(plv->val[ i ])) );
419 | }
420 | }
421 | }
422 | #endif /* DEBUG_MODE */
423 |
424 |
425 | /*****************************************************************************
426 | * Function: xsvfInfoInit
427 | * Description: Initialize the xsvfInfo data.
428 | * Parameters: pXsvfInfo - ptr to the XSVF info structure.
429 | * Returns: int - 0 = success; otherwise error.
430 | *****************************************************************************/
431 | int xsvfInfoInit( SXsvfInfo* pXsvfInfo )
432 | {
433 |
434 | XSVFDBG_PRINTF1( 4, " sizeof( SXsvfInfo ) = %d bytes\n",
435 | sizeof( SXsvfInfo ) );
436 |
437 | pXsvfInfo->ucComplete = 0;
438 | pXsvfInfo->ucCommand = XCOMPLETE;
439 | pXsvfInfo->lCommandCount = 0;
440 | pXsvfInfo->iErrorCode = XSVF_ERROR_NONE;
441 | pXsvfInfo->ucMaxRepeat = 0;
442 | pXsvfInfo->ucTapState = XTAPSTATE_RESET;
443 | pXsvfInfo->ucEndIR = XTAPSTATE_RUNTEST;
444 | pXsvfInfo->ucEndDR = XTAPSTATE_RUNTEST;
445 | pXsvfInfo->lShiftLengthBits = 0L;
446 | pXsvfInfo->sShiftLengthBytes= 0;
447 | pXsvfInfo->lRunTestTime = 0L;
448 |
449 | return( 0 );
450 | }
451 |
452 | /*****************************************************************************
453 | * Function: xsvfInfoCleanup
454 | * Description: Cleanup the xsvfInfo data.
455 | * Parameters: pXsvfInfo - ptr to the XSVF info structure.
456 | * Returns: void.
457 | *****************************************************************************/
458 | void xsvfInfoCleanup( SXsvfInfo* pXsvfInfo )
459 | {
460 | Serial.print("QINFO: Stop sending data\n");
461 | }
462 |
463 | /*****************************************************************************
464 | * Function: xsvfGetAsNumBytes
465 | * Description: Calculate the number of bytes the given number of bits
466 | * consumes.
467 | * Parameters: lNumBits - the number of bits.
468 | * Returns: short - the number of bytes to store the number of bits.
469 | *****************************************************************************/
470 | short xsvfGetAsNumBytes( long lNumBits )
471 | {
472 | return( (short)( ( lNumBits + 7L ) / 8L ) );
473 | }
474 |
475 | /*****************************************************************************
476 | * Function: xsvfTmsTransition
477 | * Description: Apply TMS and transition TAP controller by applying one TCK
478 | * cycle.
479 | * Parameters: sTms - new TMS value.
480 | * Returns: void.
481 | *****************************************************************************/
482 | void xsvfTmsTransition( short sTms )
483 | {
484 | setPort( TMS, sTms );
485 | setPort( TCK, 0 );
486 | setPort( TCK, 1 );
487 | }
488 |
489 | /*****************************************************************************
490 | * Function: xsvfGotoTapState
491 | * Description: From the current TAP state, go to the named TAP state.
492 | * A target state of RESET ALWAYS causes TMS reset sequence.
493 | * All SVF standard stable state paths are supported.
494 | * All state transitions are supported except for the following
495 | * which cause an XSVF_ERROR_ILLEGALSTATE:
496 | * - Target==DREXIT2; Start!=DRPAUSE
497 | * - Target==IREXIT2; Start!=IRPAUSE
498 | * Parameters: pucTapState - Current TAP state; returns final TAP state.
499 | * ucTargetState - New target TAP state.
500 | * Returns: int - 0 = success; otherwise error.
501 | *****************************************************************************/
502 | int xsvfGotoTapState( unsigned char* pucTapState,
503 | unsigned char ucTargetState )
504 | {
505 | int i;
506 | int iErrorCode;
507 |
508 | iErrorCode = XSVF_ERROR_NONE;
509 | if ( ucTargetState == XTAPSTATE_RESET )
510 | {
511 | /* If RESET, always perform TMS reset sequence to reset/sync TAPs */
512 | xsvfTmsTransition( 1 );
513 | for ( i = 0; i < 5; ++i )
514 | {
515 | setPort( TCK, 0 );
516 | setPort( TCK, 1 );
517 | }
518 | *pucTapState = XTAPSTATE_RESET;
519 | XSVFDBG_PRINTF( 3, " TMS Reset Sequence -> Test-Logic-Reset\n" );
520 | XSVFDBG_PRINTF1( 3, " TAP State = %s\n",
521 | xsvf_pzTapState[ *pucTapState ] );
522 | }
523 | else if ( ( ucTargetState != *pucTapState ) &&
524 | ( ( ( ucTargetState == XTAPSTATE_EXIT2DR ) && ( *pucTapState != XTAPSTATE_PAUSEDR ) ) ||
525 | ( ( ucTargetState == XTAPSTATE_EXIT2IR ) && ( *pucTapState != XTAPSTATE_PAUSEIR ) ) ) )
526 | {
527 | /* Trap illegal TAP state path specification */
528 | iErrorCode = XSVF_ERROR_ILLEGALSTATE;
529 | }
530 | else
531 | {
532 | if ( ucTargetState == *pucTapState )
533 | {
534 | /* Already in target state. Do nothing except when in DRPAUSE
535 | or in IRPAUSE to comply with SVF standard */
536 | if ( ucTargetState == XTAPSTATE_PAUSEDR )
537 | {
538 | xsvfTmsTransition( 1 );
539 | *pucTapState = XTAPSTATE_EXIT2DR;
540 | XSVFDBG_PRINTF1( 3, " TAP State = %s\n",
541 | xsvf_pzTapState[ *pucTapState ] );
542 | }
543 | else if ( ucTargetState == XTAPSTATE_PAUSEIR )
544 | {
545 | xsvfTmsTransition( 1 );
546 | *pucTapState = XTAPSTATE_EXIT2IR;
547 | XSVFDBG_PRINTF1( 3, " TAP State = %s\n",
548 | xsvf_pzTapState[ *pucTapState ] );
549 | }
550 | }
551 |
552 | /* Perform TAP state transitions to get to the target state */
553 | while ( ucTargetState != *pucTapState )
554 | {
555 | switch ( *pucTapState )
556 | {
557 | case XTAPSTATE_RESET:
558 | xsvfTmsTransition( 0 );
559 | *pucTapState = XTAPSTATE_RUNTEST;
560 | break;
561 | case XTAPSTATE_RUNTEST:
562 | xsvfTmsTransition( 1 );
563 | *pucTapState = XTAPSTATE_SELECTDR;
564 | break;
565 | case XTAPSTATE_SELECTDR:
566 | if ( ucTargetState >= XTAPSTATE_IRSTATES )
567 | {
568 | xsvfTmsTransition( 1 );
569 | *pucTapState = XTAPSTATE_SELECTIR;
570 | }
571 | else
572 | {
573 | xsvfTmsTransition( 0 );
574 | *pucTapState = XTAPSTATE_CAPTUREDR;
575 | }
576 | break;
577 | case XTAPSTATE_CAPTUREDR:
578 | if ( ucTargetState == XTAPSTATE_SHIFTDR )
579 | {
580 | xsvfTmsTransition( 0 );
581 | *pucTapState = XTAPSTATE_SHIFTDR;
582 | }
583 | else
584 | {
585 | xsvfTmsTransition( 1 );
586 | *pucTapState = XTAPSTATE_EXIT1DR;
587 | }
588 | break;
589 | case XTAPSTATE_SHIFTDR:
590 | xsvfTmsTransition( 1 );
591 | *pucTapState = XTAPSTATE_EXIT1DR;
592 | break;
593 | case XTAPSTATE_EXIT1DR:
594 | if ( ucTargetState == XTAPSTATE_PAUSEDR )
595 | {
596 | xsvfTmsTransition( 0 );
597 | *pucTapState = XTAPSTATE_PAUSEDR;
598 | }
599 | else
600 | {
601 | xsvfTmsTransition( 1 );
602 | *pucTapState = XTAPSTATE_UPDATEDR;
603 | }
604 | break;
605 | case XTAPSTATE_PAUSEDR:
606 | xsvfTmsTransition( 1 );
607 | *pucTapState = XTAPSTATE_EXIT2DR;
608 | break;
609 | case XTAPSTATE_EXIT2DR:
610 | if ( ucTargetState == XTAPSTATE_SHIFTDR )
611 | {
612 | xsvfTmsTransition( 0 );
613 | *pucTapState = XTAPSTATE_SHIFTDR;
614 | }
615 | else
616 | {
617 | xsvfTmsTransition( 1 );
618 | *pucTapState = XTAPSTATE_UPDATEDR;
619 | }
620 | break;
621 | case XTAPSTATE_UPDATEDR:
622 | if ( ucTargetState == XTAPSTATE_RUNTEST )
623 | {
624 | xsvfTmsTransition( 0 );
625 | *pucTapState = XTAPSTATE_RUNTEST;
626 | }
627 | else
628 | {
629 | xsvfTmsTransition( 1 );
630 | *pucTapState = XTAPSTATE_SELECTDR;
631 | }
632 | break;
633 | case XTAPSTATE_SELECTIR:
634 | xsvfTmsTransition( 0 );
635 | *pucTapState = XTAPSTATE_CAPTUREIR;
636 | break;
637 | case XTAPSTATE_CAPTUREIR:
638 | if ( ucTargetState == XTAPSTATE_SHIFTIR )
639 | {
640 | xsvfTmsTransition( 0 );
641 | *pucTapState = XTAPSTATE_SHIFTIR;
642 | }
643 | else
644 | {
645 | xsvfTmsTransition( 1 );
646 | *pucTapState = XTAPSTATE_EXIT1IR;
647 | }
648 | break;
649 | case XTAPSTATE_SHIFTIR:
650 | xsvfTmsTransition( 1 );
651 | *pucTapState = XTAPSTATE_EXIT1IR;
652 | break;
653 | case XTAPSTATE_EXIT1IR:
654 | if ( ucTargetState == XTAPSTATE_PAUSEIR )
655 | {
656 | xsvfTmsTransition( 0 );
657 | *pucTapState = XTAPSTATE_PAUSEIR;
658 | }
659 | else
660 | {
661 | xsvfTmsTransition( 1 );
662 | *pucTapState = XTAPSTATE_UPDATEIR;
663 | }
664 | break;
665 | case XTAPSTATE_PAUSEIR:
666 | xsvfTmsTransition( 1 );
667 | *pucTapState = XTAPSTATE_EXIT2IR;
668 | break;
669 | case XTAPSTATE_EXIT2IR:
670 | if ( ucTargetState == XTAPSTATE_SHIFTIR )
671 | {
672 | xsvfTmsTransition( 0 );
673 | *pucTapState = XTAPSTATE_SHIFTIR;
674 | }
675 | else
676 | {
677 | xsvfTmsTransition( 1 );
678 | *pucTapState = XTAPSTATE_UPDATEIR;
679 | }
680 | break;
681 | case XTAPSTATE_UPDATEIR:
682 | if ( ucTargetState == XTAPSTATE_RUNTEST )
683 | {
684 | xsvfTmsTransition( 0 );
685 | *pucTapState = XTAPSTATE_RUNTEST;
686 | }
687 | else
688 | {
689 | xsvfTmsTransition( 1 );
690 | *pucTapState = XTAPSTATE_SELECTDR;
691 | }
692 | break;
693 | default:
694 | iErrorCode = XSVF_ERROR_ILLEGALSTATE;
695 | *pucTapState = ucTargetState; /* Exit while loop */
696 | break;
697 | }
698 | XSVFDBG_PRINTF1( 3, " TAP State = %s\n",
699 | xsvf_pzTapState[ *pucTapState ] );
700 | }
701 | }
702 |
703 | return( iErrorCode );
704 | }
705 |
706 | /*****************************************************************************
707 | * Function: xsvfShiftOnly
708 | * Description: Assumes that starting TAP state is SHIFT-DR or SHIFT-IR.
709 | * Shift the given TDI data into the JTAG scan chain.
710 | * Optionally, save the TDO data shifted out of the scan chain.
711 | * Last shift cycle is special: capture last TDO, set last TDI,
712 | * but does not pulse TCK. Caller must pulse TCK and optionally
713 | * set TMS=1 to exit shift state.
714 | * Parameters: lNumBits - number of bits to shift.
715 | * plvTdi - ptr to lenval for TDI data.
716 | * plvTdoCaptured - ptr to lenval for storing captured TDO data.
717 | * iExitShift - 1=exit at end of shift; 0=stay in Shift-DR.
718 | * Returns: void.
719 | *****************************************************************************/
720 | void xsvfShiftOnly( long lNumBits,
721 | lenVal* plvTdi,
722 | lenVal* plvTdoCaptured,
723 | int iExitShift )
724 | {
725 | unsigned char* pucTdi;
726 | unsigned char* pucTdo;
727 | unsigned char ucTdiByte;
728 | unsigned char ucTdoByte;
729 | unsigned char ucTdoBit;
730 | int i;
731 |
732 | /* assert( ( ( lNumBits + 7 ) / 8 ) == plvTdi->len ); */
733 |
734 | /* Initialize TDO storage len == TDI len */
735 | pucTdo = 0;
736 | if ( plvTdoCaptured )
737 | {
738 | plvTdoCaptured->len = plvTdi->len;
739 | pucTdo = plvTdoCaptured->val + plvTdi->len;
740 | }
741 |
742 | /* Shift LSB first. val[N-1] == LSB. val[0] == MSB. */
743 | pucTdi = plvTdi->val + plvTdi->len;
744 | while ( lNumBits )
745 | {
746 | /* Process on a byte-basis */
747 | ucTdiByte = (*(--pucTdi));
748 | ucTdoByte = 0;
749 | for ( i = 0; ( lNumBits && ( i < 8 ) ); ++i )
750 | {
751 | --lNumBits;
752 | if ( iExitShift && !lNumBits )
753 | {
754 | /* Exit Shift-DR state */
755 | setPort( TMS, 1 );
756 | }
757 |
758 | /* Set the new TDI value */
759 | setPort( TDI, (short)(ucTdiByte & 1) );
760 | ucTdiByte >>= 1;
761 |
762 | /* Set TCK low */
763 | setPort( TCK, 0 );
764 |
765 | if ( pucTdo )
766 | {
767 | /* Save the TDO value */
768 | ucTdoBit = readTDOBit();
769 | ucTdoByte |= ( ucTdoBit << i );
770 | }
771 |
772 | /* Set TCK high */
773 | setPort( TCK, 1 );
774 | }
775 |
776 | /* Save the TDO byte value */
777 | if ( pucTdo )
778 | {
779 | (*(--pucTdo)) = ucTdoByte;
780 | }
781 | }
782 | }
783 |
784 | /*****************************************************************************
785 | * Function: xsvfShift
786 | * Description: Goes to the given starting TAP state.
787 | * Calls xsvfShiftOnly to shift in the given TDI data and
788 | * optionally capture the TDO data.
789 | * Compares the TDO captured data against the TDO expected
790 | * data.
791 | * If a data mismatch occurs, then executes the exception
792 | * handling loop upto ucMaxRepeat times.
793 | * Parameters: pucTapState - Ptr to current TAP state.
794 | * ucStartState - Starting shift state: Shift-DR or Shift-IR.
795 | * lNumBits - number of bits to shift.
796 | * plvTdi - ptr to lenval for TDI data.
797 | * plvTdoCaptured - ptr to lenval for storing TDO data.
798 | * plvTdoExpected - ptr to expected TDO data.
799 | * plvTdoMask - ptr to TDO mask.
800 | * ucEndState - state in which to end the shift.
801 | * lRunTestTime - amount of time to wait after the shift.
802 | * ucMaxRepeat - Maximum number of retries on TDO mismatch.
803 | * Returns: int - 0 = success; otherwise TDO mismatch.
804 | * Notes: XC9500XL-only Optimization:
805 | * Skip the waitTime() if plvTdoMask->val[0:plvTdoMask->len-1]
806 | * is NOT all zeros and sMatch==1.
807 | *****************************************************************************/
808 | int xsvfShift( unsigned char* pucTapState,
809 | unsigned char ucStartState,
810 | long lNumBits,
811 | lenVal* plvTdi,
812 | lenVal* plvTdoCaptured,
813 | lenVal* plvTdoExpected,
814 | lenVal* plvTdoMask,
815 | unsigned char ucEndState,
816 | long lRunTestTime,
817 | unsigned char ucMaxRepeat )
818 | {
819 | int iErrorCode;
820 | int iMismatch;
821 | unsigned char ucRepeat;
822 | int iExitShift;
823 |
824 | iErrorCode = XSVF_ERROR_NONE;
825 | iMismatch = 0;
826 | ucRepeat = 0;
827 | iExitShift = ( ucStartState != ucEndState );
828 |
829 | XSVFDBG_PRINTF1( 3, " Shift Length = %ld\n", lNumBits );
830 | XSVFDBG_PRINTF( 4, " TDI = ");
831 | XSVFDBG_PRINTLENVAL( 4, plvTdi );
832 | XSVFDBG_PRINTF( 4, "\n");
833 | XSVFDBG_PRINTF( 4, " TDO Expected = ");
834 | XSVFDBG_PRINTLENVAL( 4, plvTdoExpected );
835 | XSVFDBG_PRINTF( 4, "\n");
836 |
837 | if ( !lNumBits )
838 | {
839 | /* Compatibility with XSVF2.00: XSDR 0 = no shift, but wait in RTI */
840 | if ( lRunTestTime )
841 | {
842 | /* Wait for prespecified XRUNTEST time */
843 | xsvfGotoTapState( pucTapState, XTAPSTATE_RUNTEST );
844 | XSVFDBG_PRINTF1( 3, " Wait = %ld usec\n", lRunTestTime );
845 | waitTime( lRunTestTime );
846 | }
847 | }
848 | else
849 | {
850 | do
851 | {
852 | /* Goto Shift-DR or Shift-IR */
853 | xsvfGotoTapState( pucTapState, ucStartState );
854 |
855 | /* Shift TDI and capture TDO */
856 | xsvfShiftOnly( lNumBits, plvTdi, plvTdoCaptured, iExitShift );
857 |
858 | if ( plvTdoExpected )
859 | {
860 | /* Compare TDO data to expected TDO data */
861 | iMismatch = !EqualLenVal( plvTdoExpected,
862 | plvTdoCaptured,
863 | plvTdoMask );
864 | }
865 |
866 | if ( iExitShift )
867 | {
868 | /* Update TAP state: Shift->Exit */
869 | ++(*pucTapState);
870 | XSVFDBG_PRINTF1( 3, " TAP State = %s\n",
871 | xsvf_pzTapState[ *pucTapState ] );
872 |
873 | if ( iMismatch && lRunTestTime && ( ucRepeat < ucMaxRepeat ) )
874 | {
875 | XSVFDBG_PRINTF( 4, " TDO Expected = ");
876 | XSVFDBG_PRINTLENVAL( 4, plvTdoExpected );
877 | XSVFDBG_PRINTF( 4, "\n");
878 | XSVFDBG_PRINTF( 4, " TDO Captured = ");
879 | XSVFDBG_PRINTLENVAL( 4, plvTdoCaptured );
880 | XSVFDBG_PRINTF( 4, "\n");
881 | XSVFDBG_PRINTF( 4, " TDO Mask = ");
882 | XSVFDBG_PRINTLENVAL( 4, plvTdoMask );
883 | XSVFDBG_PRINTF( 4, "\n");
884 | XSVFDBG_PRINTF1( 3, " Retry #%d\n", ( ucRepeat + 1 ) );
885 | /* Do exception handling retry - ShiftDR only */
886 | xsvfGotoTapState( pucTapState, XTAPSTATE_PAUSEDR );
887 | /* Shift 1 extra bit */
888 | xsvfGotoTapState( pucTapState, XTAPSTATE_SHIFTDR );
889 | /* Increment RUNTEST time by an additional 25% */
890 | lRunTestTime += ( lRunTestTime >> 2 );
891 | }
892 | else
893 | {
894 | /* Do normal exit from Shift-XR */
895 | xsvfGotoTapState( pucTapState, ucEndState );
896 | }
897 |
898 | if ( lRunTestTime )
899 | {
900 | /* Wait for prespecified XRUNTEST time */
901 | xsvfGotoTapState( pucTapState, XTAPSTATE_RUNTEST );
902 | XSVFDBG_PRINTF1( 3, " Wait = %ld usec\n", lRunTestTime );
903 | waitTime( lRunTestTime );
904 | }
905 | }
906 | } while ( iMismatch && ( ucRepeat++ < ucMaxRepeat ) );
907 | }
908 |
909 | if ( iMismatch )
910 | {
911 | XSVFDBG_PRINTF( 1, " TDO Expected = ");
912 | XSVFDBG_PRINTLENVAL( 1, plvTdoExpected );
913 | XSVFDBG_PRINTF( 1, "\n");
914 | XSVFDBG_PRINTF( 1, " TDO Captured = ");
915 | XSVFDBG_PRINTLENVAL( 1, plvTdoCaptured );
916 | XSVFDBG_PRINTF( 1, "\n");
917 | XSVFDBG_PRINTF( 1, " TDO Mask = ");
918 | XSVFDBG_PRINTLENVAL( 1, plvTdoMask );
919 | XSVFDBG_PRINTF( 1, "\n");
920 | if ( ucMaxRepeat && ( ucRepeat > ucMaxRepeat ) )
921 | {
922 | iErrorCode = XSVF_ERROR_MAXRETRIES;
923 | }
924 | else
925 | {
926 | iErrorCode = XSVF_ERROR_TDOMISMATCH;
927 | }
928 | }
929 |
930 | return( iErrorCode );
931 | }
932 |
933 | /*****************************************************************************
934 | * Function: xsvfBasicXSDRTDO
935 | * Description: Get the XSDRTDO parameters and execute the XSDRTDO command.
936 | * This is the common function for all XSDRTDO commands.
937 | * Parameters: pucTapState - Current TAP state.
938 | * lShiftLengthBits - number of bits to shift.
939 | * sShiftLengthBytes - number of bytes to read.
940 | * plvTdi - ptr to lenval for TDI data.
941 | * lvTdoCaptured - ptr to lenval for storing TDO data.
942 | * iEndState - state in which to end the shift.
943 | * lRunTestTime - amount of time to wait after the shift.
944 | * ucMaxRepeat - maximum xc9500/xl retries.
945 | * Returns: int - 0 = success; otherwise TDO mismatch.
946 | *****************************************************************************/
947 | int xsvfBasicXSDRTDO( unsigned char* pucTapState,
948 | long lShiftLengthBits,
949 | short sShiftLengthBytes,
950 | lenVal* plvTdi,
951 | lenVal* plvTdoCaptured,
952 | lenVal* plvTdoExpected,
953 | lenVal* plvTdoMask,
954 | unsigned char ucEndState,
955 | long lRunTestTime,
956 | unsigned char ucMaxRepeat )
957 | {
958 | readVal( plvTdi, sShiftLengthBytes );
959 | if ( plvTdoExpected )
960 | {
961 | readVal( plvTdoExpected, sShiftLengthBytes );
962 | }
963 | return( xsvfShift( pucTapState, XTAPSTATE_SHIFTDR, lShiftLengthBits,
964 | plvTdi, plvTdoCaptured, plvTdoExpected, plvTdoMask,
965 | ucEndState, lRunTestTime, ucMaxRepeat ) );
966 | }
967 |
968 | /*****************************************************************************
969 | * Function: xsvfDoSDRMasking
970 | * Description: Update the data value with the next XSDRINC data and address.
971 | * Example: dataVal=0x01ff, nextData=0xab, addressMask=0x0100,
972 | * dataMask=0x00ff, should set dataVal to 0x02ab
973 | * Parameters: plvTdi - The current TDI value.
974 | * plvNextData - the next data value.
975 | * plvAddressMask - the address mask.
976 | * plvDataMask - the data mask.
977 | * Returns: void.
978 | *****************************************************************************/
979 | #ifdef XSVF_SUPPORT_COMPRESSION
980 | void xsvfDoSDRMasking( lenVal* plvTdi,
981 | lenVal* plvNextData,
982 | lenVal* plvAddressMask,
983 | lenVal* plvDataMask )
984 | {
985 | int i;
986 | unsigned char ucTdi;
987 | unsigned char ucTdiMask;
988 | unsigned char ucDataMask;
989 | unsigned char ucNextData;
990 | unsigned char ucNextMask;
991 | short sNextData;
992 |
993 | /* add the address Mask to dataVal and return as a new dataVal */
994 | addVal( plvTdi, plvTdi, plvAddressMask );
995 |
996 | ucNextData = 0;
997 | ucNextMask = 0;
998 | sNextData = plvNextData->len;
999 | for ( i = plvDataMask->len - 1; i >= 0; --i )
1000 | {
1001 | /* Go through data mask in reverse order looking for mask (1) bits */
1002 | ucDataMask = plvDataMask->val[ i ];
1003 | if ( ucDataMask )
1004 | {
1005 | /* Retrieve the corresponding TDI byte value */
1006 | ucTdi = plvTdi->val[ i ];
1007 |
1008 | /* For each bit in the data mask byte, look for 1's */
1009 | ucTdiMask = 1;
1010 | while ( ucDataMask )
1011 | {
1012 | if ( ucDataMask & 1 )
1013 | {
1014 | if ( !ucNextMask )
1015 | {
1016 | /* Get the next data byte */
1017 | ucNextData = plvNextData->val[ --sNextData ];
1018 | ucNextMask = 1;
1019 | }
1020 |
1021 | /* Set or clear the data bit according to the next data */
1022 | if ( ucNextData & ucNextMask )
1023 | {
1024 | ucTdi |= ucTdiMask; /* Set bit */
1025 | }
1026 | else
1027 | {
1028 | ucTdi &= ( ~ucTdiMask ); /* Clear bit */
1029 | }
1030 |
1031 | /* Update the next data */
1032 | ucNextMask <<= 1;
1033 | }
1034 | ucTdiMask <<= 1;
1035 | ucDataMask >>= 1;
1036 | }
1037 |
1038 | /* Update the TDI value */
1039 | plvTdi->val[ i ] = ucTdi;
1040 | }
1041 | }
1042 | }
1043 | #endif /* XSVF_SUPPORT_COMPRESSION */
1044 |
1045 | /*============================================================================
1046 | * XSVF Command Functions (type = TXsvfDoCmdFuncPtr)
1047 | * These functions update pXsvfInfo->iErrorCode only on an error.
1048 | * Otherwise, the error code is left alone.
1049 | * The function returns the error code from the function.
1050 | ============================================================================*/
1051 |
1052 | /*****************************************************************************
1053 | * Function: xsvfDoIllegalCmd
1054 | * Description: Function place holder for illegal/unsupported commands.
1055 | * Parameters: pXsvfInfo - XSVF information pointer.
1056 | * Returns: int - 0 = success; non-zero = error.
1057 | *****************************************************************************/
1058 | int xsvfDoIllegalCmd( SXsvfInfo* pXsvfInfo )
1059 | {
1060 | XSVFDBG_PRINTF2( 0, "ERROR: Encountered unsupported command #%d (%s)\n",
1061 | ((unsigned int)(pXsvfInfo->ucCommand)),
1062 | ((pXsvfInfo->ucCommand < XLASTCMD)
1063 | ? (xsvf_pzCommandName[pXsvfInfo->ucCommand])
1064 | : "Unknown") );
1065 | pXsvfInfo->iErrorCode = XSVF_ERROR_ILLEGALCMD;
1066 | return( pXsvfInfo->iErrorCode );
1067 | }
1068 |
1069 | /*****************************************************************************
1070 | * Function: xsvfDoXCOMPLETE
1071 | * Description: XCOMPLETE (no parameters)
1072 | * Update complete status for XSVF player.
1073 | * Parameters: pXsvfInfo - XSVF information pointer.
1074 | * Returns: int - 0 = success; non-zero = error.
1075 | *****************************************************************************/
1076 | int xsvfDoXCOMPLETE( SXsvfInfo* pXsvfInfo )
1077 | {
1078 | pXsvfInfo->ucComplete = 1;
1079 | return( XSVF_ERROR_NONE );
1080 | }
1081 |
1082 | /*****************************************************************************
1083 | * Function: xsvfDoXTDOMASK
1084 | * Description: XTDOMASK
1085 | * Prespecify the TDO compare mask.
1086 | * Parameters: pXsvfInfo - XSVF information pointer.
1087 | * Returns: int - 0 = success; non-zero = error.
1088 | *****************************************************************************/
1089 | int xsvfDoXTDOMASK( SXsvfInfo* pXsvfInfo )
1090 | {
1091 | readVal( &(pXsvfInfo->lvTdoMask), pXsvfInfo->sShiftLengthBytes );
1092 | XSVFDBG_PRINTF( 4, " TDO Mask = ");
1093 | XSVFDBG_PRINTLENVAL( 4, &(pXsvfInfo->lvTdoMask) );
1094 | XSVFDBG_PRINTF( 4, "\n");
1095 | return( XSVF_ERROR_NONE );
1096 | }
1097 |
1098 | /*****************************************************************************
1099 | * Function: xsvfDoXSIR
1100 | * Description: XSIR <(byte)shiftlen>
1101 | * Get the instruction and shift the instruction into the TAP.
1102 | * If prespecified XRUNTEST!=0, goto RUNTEST and wait after
1103 | * the shift for XRUNTEST usec.
1104 | * Parameters: pXsvfInfo - XSVF information pointer.
1105 | * Returns: int - 0 = success; non-zero = error.
1106 | *****************************************************************************/
1107 | int xsvfDoXSIR( SXsvfInfo* pXsvfInfo )
1108 | {
1109 | unsigned char ucShiftIrBits;
1110 | short sShiftIrBytes;
1111 | int iErrorCode;
1112 |
1113 | /* Get the shift length and store */
1114 | readByte( &ucShiftIrBits );
1115 | sShiftIrBytes = xsvfGetAsNumBytes( ucShiftIrBits );
1116 | XSVFDBG_PRINTF1( 3, " XSIR length = %d\n",
1117 | ((unsigned int)ucShiftIrBits) );
1118 |
1119 | if ( sShiftIrBytes > MAX_LEN )
1120 | {
1121 | iErrorCode = XSVF_ERROR_DATAOVERFLOW;
1122 | }
1123 | else
1124 | {
1125 | /* Get and store instruction to shift in */
1126 | readVal( &(pXsvfInfo->lvTdi), xsvfGetAsNumBytes( ucShiftIrBits ) );
1127 |
1128 | /* Shift the data */
1129 | iErrorCode = xsvfShift( &(pXsvfInfo->ucTapState), XTAPSTATE_SHIFTIR,
1130 | ucShiftIrBits, &(pXsvfInfo->lvTdi),
1131 | /*plvTdoCaptured*/0, /*plvTdoExpected*/0,
1132 | /*plvTdoMask*/0, pXsvfInfo->ucEndIR,
1133 | pXsvfInfo->lRunTestTime, /*ucMaxRepeat*/0 );
1134 | }
1135 |
1136 | if ( iErrorCode != XSVF_ERROR_NONE )
1137 | {
1138 | pXsvfInfo->iErrorCode = iErrorCode;
1139 | }
1140 | return( iErrorCode );
1141 | }
1142 |
1143 | /*****************************************************************************
1144 | * Function: xsvfDoXSIR2
1145 | * Description: XSIR <(2-byte)shiftlen>
1146 | * Get the instruction and shift the instruction into the TAP.
1147 | * If prespecified XRUNTEST!=0, goto RUNTEST and wait after
1148 | * the shift for XRUNTEST usec.
1149 | * Parameters: pXsvfInfo - XSVF information pointer.
1150 | * Returns: int - 0 = success; non-zero = error.
1151 | *****************************************************************************/
1152 | int xsvfDoXSIR2( SXsvfInfo* pXsvfInfo )
1153 | {
1154 | long lShiftIrBits;
1155 | short sShiftIrBytes;
1156 | int iErrorCode;
1157 |
1158 | /* Get the shift length and store */
1159 | readVal( &(pXsvfInfo->lvTdi), 2 );
1160 | lShiftIrBits = value( &(pXsvfInfo->lvTdi) );
1161 | sShiftIrBytes = xsvfGetAsNumBytes( lShiftIrBits );
1162 | XSVFDBG_PRINTF1( 3, " XSIR2 length = %d\n", lShiftIrBits);
1163 |
1164 | if ( sShiftIrBytes > MAX_LEN )
1165 | {
1166 | iErrorCode = XSVF_ERROR_DATAOVERFLOW;
1167 | }
1168 | else
1169 | {
1170 | /* Get and store instruction to shift in */
1171 | readVal( &(pXsvfInfo->lvTdi), xsvfGetAsNumBytes( lShiftIrBits ) );
1172 |
1173 | /* Shift the data */
1174 | iErrorCode = xsvfShift( &(pXsvfInfo->ucTapState), XTAPSTATE_SHIFTIR,
1175 | lShiftIrBits, &(pXsvfInfo->lvTdi),
1176 | /*plvTdoCaptured*/0, /*plvTdoExpected*/0,
1177 | /*plvTdoMask*/0, pXsvfInfo->ucEndIR,
1178 | pXsvfInfo->lRunTestTime, /*ucMaxRepeat*/0 );
1179 | }
1180 |
1181 | if ( iErrorCode != XSVF_ERROR_NONE )
1182 | {
1183 | pXsvfInfo->iErrorCode = iErrorCode;
1184 | }
1185 | return( iErrorCode );
1186 | }
1187 |
1188 | /*****************************************************************************
1189 | * Function: xsvfDoXSDR
1190 | * Description: XSDR
1191 | * Shift the given TDI data into the JTAG scan chain.
1192 | * Compare the captured TDO with the expected TDO from the
1193 | * previous XSDRTDO command using the previously specified
1194 | * XTDOMASK.
1195 | * Parameters: pXsvfInfo - XSVF information pointer.
1196 | * Returns: int - 0 = success; non-zero = error.
1197 | *****************************************************************************/
1198 | int xsvfDoXSDR( SXsvfInfo* pXsvfInfo )
1199 | {
1200 | int iErrorCode;
1201 | readVal( &(pXsvfInfo->lvTdi), pXsvfInfo->sShiftLengthBytes );
1202 | /* use TDOExpected from last XSDRTDO instruction */
1203 | iErrorCode = xsvfShift( &(pXsvfInfo->ucTapState), XTAPSTATE_SHIFTDR,
1204 | pXsvfInfo->lShiftLengthBits, &(pXsvfInfo->lvTdi),
1205 | &(pXsvfInfo->lvTdoCaptured),
1206 | &(pXsvfInfo->lvTdoExpected),
1207 | &(pXsvfInfo->lvTdoMask), pXsvfInfo->ucEndDR,
1208 | pXsvfInfo->lRunTestTime, pXsvfInfo->ucMaxRepeat );
1209 | if ( iErrorCode != XSVF_ERROR_NONE )
1210 | {
1211 | pXsvfInfo->iErrorCode = iErrorCode;
1212 | }
1213 | return( iErrorCode );
1214 | }
1215 |
1216 | /*****************************************************************************
1217 | * Function: xsvfDoXRUNTEST
1218 | * Description: XRUNTEST
1219 | * Prespecify the XRUNTEST wait time for shift operations.
1220 | * Parameters: pXsvfInfo - XSVF information pointer.
1221 | * Returns: int - 0 = success; non-zero = error.
1222 | *****************************************************************************/
1223 | int xsvfDoXRUNTEST( SXsvfInfo* pXsvfInfo )
1224 | {
1225 | readVal( &(pXsvfInfo->lvTdi), 4 );
1226 | pXsvfInfo->lRunTestTime = value( &(pXsvfInfo->lvTdi) );
1227 | XSVFDBG_PRINTF1( 3, " XRUNTEST = %ld\n", pXsvfInfo->lRunTestTime );
1228 | return( XSVF_ERROR_NONE );
1229 | }
1230 |
1231 | /*****************************************************************************
1232 | * Function: xsvfDoXREPEAT
1233 | * Description: XREPEAT
1234 | * Prespecify the maximum number of XC9500/XL retries.
1235 | * Parameters: pXsvfInfo - XSVF information pointer.
1236 | * Returns: int - 0 = success; non-zero = error.
1237 | *****************************************************************************/
1238 | int xsvfDoXREPEAT( SXsvfInfo* pXsvfInfo )
1239 | {
1240 | readByte( &(pXsvfInfo->ucMaxRepeat) );
1241 | XSVFDBG_PRINTF1( 3, " XREPEAT = %d\n",
1242 | ((unsigned int)(pXsvfInfo->ucMaxRepeat)) );
1243 | return( XSVF_ERROR_NONE );
1244 | }
1245 |
1246 | /*****************************************************************************
1247 | * Function: xsvfDoXSDRSIZE
1248 | * Description: XSDRSIZE
1249 | * Prespecify the XRUNTEST wait time for shift operations.
1250 | * Parameters: pXsvfInfo - XSVF information pointer.
1251 | * Returns: int - 0 = success; non-zero = error.
1252 | *****************************************************************************/
1253 | int xsvfDoXSDRSIZE( SXsvfInfo* pXsvfInfo )
1254 | {
1255 | int iErrorCode;
1256 | iErrorCode = XSVF_ERROR_NONE;
1257 | readVal( &(pXsvfInfo->lvTdi), 4 );
1258 | pXsvfInfo->lShiftLengthBits = value( &(pXsvfInfo->lvTdi) );
1259 | pXsvfInfo->sShiftLengthBytes= xsvfGetAsNumBytes( pXsvfInfo->lShiftLengthBits );
1260 | XSVFDBG_PRINTF1( 3, " XSDRSIZE = %ld\n", pXsvfInfo->lShiftLengthBits );
1261 | if ( pXsvfInfo->sShiftLengthBytes > MAX_LEN )
1262 | {
1263 | iErrorCode = XSVF_ERROR_DATAOVERFLOW;
1264 | pXsvfInfo->iErrorCode = iErrorCode;
1265 | }
1266 | return( iErrorCode );
1267 | }
1268 |
1269 | /*****************************************************************************
1270 | * Function: xsvfDoXSDRTDO
1271 | * Description: XSDRTDO
1272 | * Get the TDI and expected TDO values. Then, shift.
1273 | * Compare the expected TDO with the captured TDO using the
1274 | * prespecified XTDOMASK.
1275 | * Parameters: pXsvfInfo - XSVF information pointer.
1276 | * Returns: int - 0 = success; non-zero = error.
1277 | *****************************************************************************/
1278 | int xsvfDoXSDRTDO( SXsvfInfo* pXsvfInfo )
1279 | {
1280 | int iErrorCode;
1281 | iErrorCode = xsvfBasicXSDRTDO( &(pXsvfInfo->ucTapState),
1282 | pXsvfInfo->lShiftLengthBits,
1283 | pXsvfInfo->sShiftLengthBytes,
1284 | &(pXsvfInfo->lvTdi),
1285 | &(pXsvfInfo->lvTdoCaptured),
1286 | &(pXsvfInfo->lvTdoExpected),
1287 | &(pXsvfInfo->lvTdoMask),
1288 | pXsvfInfo->ucEndDR,
1289 | pXsvfInfo->lRunTestTime,
1290 | pXsvfInfo->ucMaxRepeat );
1291 | if ( iErrorCode != XSVF_ERROR_NONE )
1292 | {
1293 | pXsvfInfo->iErrorCode = iErrorCode;
1294 | }
1295 | return( iErrorCode );
1296 | }
1297 |
1298 | /*****************************************************************************
1299 | * Function: xsvfDoXSETSDRMASKS
1300 | * Description: XSETSDRMASKS
1301 | *
1302 | * Get the prespecified address and data mask for the XSDRINC
1303 | * command.
1304 | * Used for xc9500/xl compressed XSVF data.
1305 | * Parameters: pXsvfInfo - XSVF information pointer.
1306 | * Returns: int - 0 = success; non-zero = error.
1307 | *****************************************************************************/
1308 | #ifdef XSVF_SUPPORT_COMPRESSION
1309 | int xsvfDoXSETSDRMASKS( SXsvfInfo* pXsvfInfo )
1310 | {
1311 | /* read the addressMask */
1312 | readVal( &(pXsvfInfo->lvAddressMask), pXsvfInfo->sShiftLengthBytes );
1313 | /* read the dataMask */
1314 | readVal( &(pXsvfInfo->lvDataMask), pXsvfInfo->sShiftLengthBytes );
1315 |
1316 | XSVFDBG_PRINTF( 4, " Address Mask = " );
1317 | XSVFDBG_PRINTLENVAL( 4, &(pXsvfInfo->lvAddressMask) );
1318 | XSVFDBG_PRINTF( 4, "\n" );
1319 | XSVFDBG_PRINTF( 4, " Data Mask = " );
1320 | XSVFDBG_PRINTLENVAL( 4, &(pXsvfInfo->lvDataMask) );
1321 | XSVFDBG_PRINTF( 4, "\n" );
1322 |
1323 | return( XSVF_ERROR_NONE );
1324 | }
1325 | #endif /* XSVF_SUPPORT_COMPRESSION */
1326 |
1327 | /*****************************************************************************
1328 | * Function: xsvfDoXSDRINC
1329 | * Description: XSDRINC
1330 | * ...
1331 | * Get the XSDRINC parameters and execute the XSDRINC command.
1332 | * XSDRINC starts by loading the first TDI shift value.
1333 | * Then, for numTimes, XSDRINC gets the next piece of data,
1334 | * replaces the bits from the starting TDI as defined by the
1335 | * XSETSDRMASKS.dataMask, adds the address mask from
1336 | * XSETSDRMASKS.addressMask, shifts the new TDI value,
1337 | * and compares the TDO to the expected TDO from the previous
1338 | * XSDRTDO command using the XTDOMASK.
1339 | * Used for xc9500/xl compressed XSVF data.
1340 | * Parameters: pXsvfInfo - XSVF information pointer.
1341 | * Returns: int - 0 = success; non-zero = error.
1342 | *****************************************************************************/
1343 | #ifdef XSVF_SUPPORT_COMPRESSION
1344 | int xsvfDoXSDRINC( SXsvfInfo* pXsvfInfo )
1345 | {
1346 | int iErrorCode;
1347 | int iDataMaskLen;
1348 | unsigned char ucDataMask;
1349 | unsigned char ucNumTimes;
1350 | unsigned char i;
1351 |
1352 | readVal( &(pXsvfInfo->lvTdi), pXsvfInfo->sShiftLengthBytes );
1353 | iErrorCode = xsvfShift( &(pXsvfInfo->ucTapState), XTAPSTATE_SHIFTDR,
1354 | pXsvfInfo->lShiftLengthBits,
1355 | &(pXsvfInfo->lvTdi), &(pXsvfInfo->lvTdoCaptured),
1356 | &(pXsvfInfo->lvTdoExpected),
1357 | &(pXsvfInfo->lvTdoMask), pXsvfInfo->ucEndDR,
1358 | pXsvfInfo->lRunTestTime, pXsvfInfo->ucMaxRepeat );
1359 | if ( !iErrorCode )
1360 | {
1361 | /* Calculate number of data mask bits */
1362 | iDataMaskLen = 0;
1363 | for ( i = 0; i < pXsvfInfo->lvDataMask.len; ++i )
1364 | {
1365 | ucDataMask = pXsvfInfo->lvDataMask.val[ i ];
1366 | while ( ucDataMask )
1367 | {
1368 | iDataMaskLen += ( ucDataMask & 1 );
1369 | ucDataMask >>= 1;
1370 | }
1371 | }
1372 |
1373 | /* Get the number of data pieces, i.e. number of times to shift */
1374 | readByte( &ucNumTimes );
1375 |
1376 | /* For numTimes, get data, fix TDI, and shift */
1377 | for ( i = 0; !iErrorCode && ( i < ucNumTimes ); ++i )
1378 | {
1379 | readVal( &(pXsvfInfo->lvNextData),
1380 | xsvfGetAsNumBytes( iDataMaskLen ) );
1381 | xsvfDoSDRMasking( &(pXsvfInfo->lvTdi),
1382 | &(pXsvfInfo->lvNextData),
1383 | &(pXsvfInfo->lvAddressMask),
1384 | &(pXsvfInfo->lvDataMask) );
1385 | iErrorCode = xsvfShift( &(pXsvfInfo->ucTapState),
1386 | XTAPSTATE_SHIFTDR,
1387 | pXsvfInfo->lShiftLengthBits,
1388 | &(pXsvfInfo->lvTdi),
1389 | &(pXsvfInfo->lvTdoCaptured),
1390 | &(pXsvfInfo->lvTdoExpected),
1391 | &(pXsvfInfo->lvTdoMask),
1392 | pXsvfInfo->ucEndDR,
1393 | pXsvfInfo->lRunTestTime,
1394 | pXsvfInfo->ucMaxRepeat );
1395 | }
1396 | }
1397 | if ( iErrorCode != XSVF_ERROR_NONE )
1398 | {
1399 | pXsvfInfo->iErrorCode = iErrorCode;
1400 | }
1401 | return( iErrorCode );
1402 | }
1403 | #endif /* XSVF_SUPPORT_COMPRESSION */
1404 |
1405 | /*****************************************************************************
1406 | * Function: xsvfDoXSDRBCE
1407 | * Description: XSDRB/XSDRC/XSDRE
1408 | * If not already in SHIFTDR, goto SHIFTDR.
1409 | * Shift the given TDI data into the JTAG scan chain.
1410 | * Ignore TDO.
1411 | * If cmd==XSDRE, then goto ENDDR. Otherwise, stay in ShiftDR.
1412 | * XSDRB, XSDRC, and XSDRE are the same implementation.
1413 | * Parameters: pXsvfInfo - XSVF information pointer.
1414 | * Returns: int - 0 = success; non-zero = error.
1415 | *****************************************************************************/
1416 | int xsvfDoXSDRBCE( SXsvfInfo* pXsvfInfo )
1417 | {
1418 | unsigned char ucEndDR;
1419 | int iErrorCode;
1420 | ucEndDR = (unsigned char)(( pXsvfInfo->ucCommand == XSDRE ) ?
1421 | pXsvfInfo->ucEndDR : XTAPSTATE_SHIFTDR);
1422 | iErrorCode = xsvfBasicXSDRTDO( &(pXsvfInfo->ucTapState),
1423 | pXsvfInfo->lShiftLengthBits,
1424 | pXsvfInfo->sShiftLengthBytes,
1425 | &(pXsvfInfo->lvTdi),
1426 | /*plvTdoCaptured*/0, /*plvTdoExpected*/0,
1427 | /*plvTdoMask*/0, ucEndDR,
1428 | /*lRunTestTime*/0, /*ucMaxRepeat*/0 );
1429 | if ( iErrorCode != XSVF_ERROR_NONE )
1430 | {
1431 | pXsvfInfo->iErrorCode = iErrorCode;
1432 | }
1433 | return( iErrorCode );
1434 | }
1435 |
1436 | /*****************************************************************************
1437 | * Function: xsvfDoXSDRTDOBCE
1438 | * Description: XSDRB/XSDRC/XSDRE
1439 | * If not already in SHIFTDR, goto SHIFTDR.
1440 | * Shift the given TDI data into the JTAG scan chain.
1441 | * Compare TDO, but do NOT use XTDOMASK.
1442 | * If cmd==XSDRTDOE, then goto ENDDR. Otherwise, stay in ShiftDR.
1443 | * XSDRTDOB, XSDRTDOC, and XSDRTDOE are the same implementation.
1444 | * Parameters: pXsvfInfo - XSVF information pointer.
1445 | * Returns: int - 0 = success; non-zero = error.
1446 | *****************************************************************************/
1447 | int xsvfDoXSDRTDOBCE( SXsvfInfo* pXsvfInfo )
1448 | {
1449 | unsigned char ucEndDR;
1450 | int iErrorCode;
1451 | ucEndDR = (unsigned char)(( pXsvfInfo->ucCommand == XSDRTDOE ) ?
1452 | pXsvfInfo->ucEndDR : XTAPSTATE_SHIFTDR);
1453 | iErrorCode = xsvfBasicXSDRTDO( &(pXsvfInfo->ucTapState),
1454 | pXsvfInfo->lShiftLengthBits,
1455 | pXsvfInfo->sShiftLengthBytes,
1456 | &(pXsvfInfo->lvTdi),
1457 | &(pXsvfInfo->lvTdoCaptured),
1458 | &(pXsvfInfo->lvTdoExpected),
1459 | /*plvTdoMask*/0, ucEndDR,
1460 | /*lRunTestTime*/0, /*ucMaxRepeat*/0 );
1461 | if ( iErrorCode != XSVF_ERROR_NONE )
1462 | {
1463 | pXsvfInfo->iErrorCode = iErrorCode;
1464 | }
1465 | return( iErrorCode );
1466 | }
1467 |
1468 | /*****************************************************************************
1469 | * Function: xsvfDoXSTATE
1470 | * Description: XSTATE
1471 | * == XTAPSTATE;
1472 | * Get the state parameter and transition the TAP to that state.
1473 | * Parameters: pXsvfInfo - XSVF information pointer.
1474 | * Returns: int - 0 = success; non-zero = error.
1475 | *****************************************************************************/
1476 | int xsvfDoXSTATE( SXsvfInfo* pXsvfInfo )
1477 | {
1478 | unsigned char ucNextState;
1479 | int iErrorCode;
1480 | readByte( &ucNextState );
1481 | iErrorCode = xsvfGotoTapState( &(pXsvfInfo->ucTapState), ucNextState );
1482 | if ( iErrorCode != XSVF_ERROR_NONE )
1483 | {
1484 | pXsvfInfo->iErrorCode = iErrorCode;
1485 | }
1486 | return( iErrorCode );
1487 | }
1488 |
1489 | /*****************************************************************************
1490 | * Function: xsvfDoXENDXR
1491 | * Description: XENDIR/XENDDR
1492 | * : 0 = RUNTEST; 1 = PAUSE.
1493 | * Get the prespecified XENDIR or XENDDR.
1494 | * Both XENDIR and XENDDR use the same implementation.
1495 | * Parameters: pXsvfInfo - XSVF information pointer.
1496 | * Returns: int - 0 = success; non-zero = error.
1497 | *****************************************************************************/
1498 | int xsvfDoXENDXR( SXsvfInfo* pXsvfInfo )
1499 | {
1500 | int iErrorCode;
1501 | unsigned char ucEndState;
1502 |
1503 | iErrorCode = XSVF_ERROR_NONE;
1504 | readByte( &ucEndState );
1505 | if ( ( ucEndState != XENDXR_RUNTEST ) && ( ucEndState != XENDXR_PAUSE ) )
1506 | {
1507 | iErrorCode = XSVF_ERROR_ILLEGALSTATE;
1508 | }
1509 | else
1510 | {
1511 |
1512 | if ( pXsvfInfo->ucCommand == XENDIR )
1513 | {
1514 | if ( ucEndState == XENDXR_RUNTEST )
1515 | {
1516 | pXsvfInfo->ucEndIR = XTAPSTATE_RUNTEST;
1517 | }
1518 | else
1519 | {
1520 | pXsvfInfo->ucEndIR = XTAPSTATE_PAUSEIR;
1521 | }
1522 | XSVFDBG_PRINTF1( 3, " ENDIR State = %s\n",
1523 | xsvf_pzTapState[ pXsvfInfo->ucEndIR ] );
1524 | }
1525 | else /* XENDDR */
1526 | {
1527 | if ( ucEndState == XENDXR_RUNTEST )
1528 | {
1529 | pXsvfInfo->ucEndDR = XTAPSTATE_RUNTEST;
1530 | }
1531 | else
1532 | {
1533 | pXsvfInfo->ucEndDR = XTAPSTATE_PAUSEDR;
1534 | }
1535 | XSVFDBG_PRINTF1( 3, " ENDDR State = %s\n",
1536 | xsvf_pzTapState[ pXsvfInfo->ucEndDR ] );
1537 | }
1538 | }
1539 |
1540 | if ( iErrorCode != XSVF_ERROR_NONE )
1541 | {
1542 | pXsvfInfo->iErrorCode = iErrorCode;
1543 | }
1544 | return( iErrorCode );
1545 | }
1546 |
1547 | /*****************************************************************************
1548 | * Function: xsvfDoXCOMMENT
1549 | * Description: XCOMMENT
1550 | * == text comment;
1551 | * Arbitrary comment embedded in the XSVF.
1552 | * Parameters: pXsvfInfo - XSVF information pointer.
1553 | * Returns: int - 0 = success; non-zero = error.
1554 | *****************************************************************************/
1555 | int xsvfDoXCOMMENT( SXsvfInfo* pXsvfInfo )
1556 | {
1557 | /* Use the comment for debugging */
1558 | /* Otherwise, read through the comment to the end '\0' and ignore */
1559 | unsigned char ucText;
1560 |
1561 | #ifdef DEBUG_MODE
1562 | if ( xsvf_iDebugLevel > 0 )
1563 | {
1564 | debug_printf( "%c", ' ' );
1565 | }
1566 | #endif
1567 |
1568 | do
1569 | {
1570 | readByte( &ucText );
1571 | #ifdef DEBUG_MODE
1572 | if ( xsvf_iDebugLevel > 0 )
1573 | {
1574 | debug_printf( "%c", ucText ? ucText : '\n' );
1575 | }
1576 | #endif
1577 | } while ( ucText );
1578 |
1579 | pXsvfInfo->iErrorCode = XSVF_ERROR_NONE;
1580 |
1581 | return( pXsvfInfo->iErrorCode );
1582 | }
1583 |
1584 | /*****************************************************************************
1585 | * Function: xsvfDoXWAIT
1586 | * Description: XWAIT
1587 | * If not already in , then go to .
1588 | * Wait in for microseconds.
1589 | * Finally, if not already in , then goto .
1590 | * Parameters: pXsvfInfo - XSVF information pointer.
1591 | * Returns: int - 0 = success; non-zero = error.
1592 | *****************************************************************************/
1593 | int xsvfDoXWAIT( SXsvfInfo* pXsvfInfo )
1594 | {
1595 | unsigned char ucWaitState;
1596 | unsigned char ucEndState;
1597 | long lWaitTime;
1598 |
1599 | /* Get Parameters */
1600 | /* */
1601 | readVal( &(pXsvfInfo->lvTdi), 1 );
1602 | ucWaitState = pXsvfInfo->lvTdi.val[0];
1603 |
1604 | /* */
1605 | readVal( &(pXsvfInfo->lvTdi), 1 );
1606 | ucEndState = pXsvfInfo->lvTdi.val[0];
1607 |
1608 | /* */
1609 | readVal( &(pXsvfInfo->lvTdi), 4 );
1610 | lWaitTime = value( &(pXsvfInfo->lvTdi) );
1611 | XSVFDBG_PRINTF2( 3, " XWAIT: state = %s; time = %ld\n",
1612 | xsvf_pzTapState[ ucWaitState ], lWaitTime );
1613 |
1614 | /* If not already in , go to */
1615 | if ( pXsvfInfo->ucTapState != ucWaitState )
1616 | {
1617 | xsvfGotoTapState( &(pXsvfInfo->ucTapState), ucWaitState );
1618 | }
1619 |
1620 | /* Wait for microseconds */
1621 | waitTime( lWaitTime );
1622 |
1623 | /* If not already in , go to */
1624 | if ( pXsvfInfo->ucTapState != ucEndState )
1625 | {
1626 | xsvfGotoTapState( &(pXsvfInfo->ucTapState), ucEndState );
1627 | }
1628 |
1629 | return( XSVF_ERROR_NONE );
1630 | }
1631 |
1632 |
1633 | /*============================================================================
1634 | * Execution Control Functions
1635 | ============================================================================*/
1636 |
1637 | /*****************************************************************************
1638 | * Function: xsvfInitialize
1639 | * Description: Initialize the xsvf player.
1640 | * Call this before running the player to initialize the data
1641 | * in the SXsvfInfo struct.
1642 | * xsvfCleanup is called to clean up the data in SXsvfInfo
1643 | * after the XSVF is played.
1644 | * Parameters: pXsvfInfo - ptr to the XSVF information.
1645 | * Returns: int - 0 = success; otherwise error.
1646 | *****************************************************************************/
1647 | int xsvfInitialize( SXsvfInfo* pXsvfInfo )
1648 | {
1649 | /* Initialize values */
1650 | pXsvfInfo->iErrorCode = xsvfInfoInit( pXsvfInfo );
1651 |
1652 | if ( !pXsvfInfo->iErrorCode )
1653 | {
1654 | /* Initialize the TAPs */
1655 | pXsvfInfo->iErrorCode = xsvfGotoTapState( &(pXsvfInfo->ucTapState),
1656 | XTAPSTATE_RESET );
1657 | }
1658 |
1659 | return( pXsvfInfo->iErrorCode );
1660 | }
1661 |
1662 | /*****************************************************************************
1663 | * Function: xsvfRun
1664 | * Description: Run the xsvf player for a single command and return.
1665 | * First, call xsvfInitialize.
1666 | * Then, repeatedly call this function until an error is detected
1667 | * or until the pXsvfInfo->ucComplete variable is non-zero.
1668 | * Finally, call xsvfCleanup to cleanup any remnants.
1669 | * Parameters: pXsvfInfo - ptr to the XSVF information.
1670 | * Returns: int - 0 = success; otherwise error.
1671 | *****************************************************************************/
1672 | int xsvfRun( SXsvfInfo* pXsvfInfo )
1673 | {
1674 | /* Process the XSVF commands */
1675 | if ( (!pXsvfInfo->iErrorCode) && (!pXsvfInfo->ucComplete) )
1676 | {
1677 | /* read 1 byte for the instruction */
1678 | readByte( &(pXsvfInfo->ucCommand) );
1679 | ++(pXsvfInfo->lCommandCount);
1680 |
1681 | if ( pXsvfInfo->ucCommand < XLASTCMD )
1682 | {
1683 | /* Execute the command. Func sets error code. */
1684 | XSVFDBG_PRINTF1( 2, " %s\n",
1685 | xsvf_pzCommandName[pXsvfInfo->ucCommand] );
1686 | /* If your compiler cannot take this form,
1687 | then convert to a switch statement */
1688 | xsvf_pfDoCmd[ pXsvfInfo->ucCommand ]( pXsvfInfo );
1689 | }
1690 | else
1691 | {
1692 | /* Illegal command value. Func sets error code. */
1693 | xsvfDoIllegalCmd( pXsvfInfo );
1694 | }
1695 | }
1696 |
1697 | return( pXsvfInfo->iErrorCode );
1698 | }
1699 |
1700 | /*****************************************************************************
1701 | * Function: xsvfCleanup
1702 | * Description: cleanup remnants of the xsvf player.
1703 | * Parameters: pXsvfInfo - ptr to the XSVF information.
1704 | * Returns: void.
1705 | *****************************************************************************/
1706 | void xsvfCleanup( SXsvfInfo* pXsvfInfo )
1707 | {
1708 | xsvfInfoCleanup( pXsvfInfo );
1709 | }
1710 |
1711 |
1712 | /*============================================================================
1713 | * xsvfExecute() - The primary entry point to the XSVF player
1714 | ============================================================================*/
1715 |
1716 | /*****************************************************************************
1717 | * Function: xsvfExecute
1718 | * Description: Process, interpret, and apply the XSVF commands.
1719 | * See port.c:readByte for source of XSVF data.
1720 | * Parameters: none.
1721 | * Returns: int - Legacy result values: 1 == success; 0 == failed.
1722 | *****************************************************************************/
1723 | int xsvfExecute()
1724 | {
1725 | static SXsvfInfo xsvfInfo;
1726 |
1727 | xsvfInitialize( &xsvfInfo );
1728 |
1729 | while ( !xsvfInfo.iErrorCode && (!xsvfInfo.ucComplete) )
1730 | {
1731 | xsvfRun( &xsvfInfo );
1732 | }
1733 |
1734 | if ( xsvfInfo.iErrorCode )
1735 | {
1736 | XSVFDBG_PRINTF1( 0, "%s\n", xsvf_pzErrorName[
1737 | ( xsvfInfo.iErrorCode < XSVF_ERROR_LAST )
1738 | ? xsvfInfo.iErrorCode : XSVF_ERROR_UNKNOWN ] );
1739 | XSVFDBG_PRINTF2( 0, "ERROR at or near XSVF command #%ld. See line #%ld in the XSVF ASCII file.\n",
1740 | xsvfInfo.lCommandCount, xsvfInfo.lCommandCount );
1741 | }
1742 | else
1743 | {
1744 | XSVFDBG_PRINTF( 0, "SUCCESS - Completed XSVF execution.\n" );
1745 | }
1746 |
1747 | xsvfCleanup( &xsvfInfo );
1748 |
1749 | return( XSVF_ERRORCODE(xsvfInfo.iErrorCode) );
1750 | }
1751 |
1752 |
1753 | /*============================================================================
1754 | * main
1755 | ============================================================================*/
1756 |
1757 | /*****************************************************************************
1758 | * Function: main
1759 | * Description: main function.
1760 | * Specified here for creating stand-alone debug executable.
1761 | * Embedded users should call xsvfExecute() directly.
1762 | * Parameters: iArgc - number of command-line arguments.
1763 | * ppzArgv - array of ptrs to strings (command-line arguments).
1764 | * Returns: int - Legacy return value: 1 = success; 0 = error.
1765 | *****************************************************************************/
1766 | #if 0
1767 | int main( int iArgc, char** ppzArgv )
1768 | {
1769 | int iErrorCode;
1770 | char* pzXsvfFileName;
1771 | int i;
1772 | clock_t startClock;
1773 | clock_t endClock;
1774 |
1775 | iErrorCode = XSVF_ERRORCODE( XSVF_ERROR_NONE );
1776 | pzXsvfFileName = 0;
1777 |
1778 | printf( "XSVF Player v%s, Xilinx, Inc.\n", XSVF_VERSION );
1779 |
1780 | for ( i = 1; i < iArgc ; ++i )
1781 | {
1782 | if ( !_stricmp( ppzArgv[ i ], "-v" ) )
1783 | {
1784 | ++i;
1785 | if ( i >= iArgc )
1786 | {
1787 | printf( "ERROR: missing parameter for -v option.\n" );
1788 | }
1789 | else
1790 | {
1791 | xsvf_iDebugLevel = atoi( ppzArgv[ i ] );
1792 | printf( "Verbose level = %d\n", xsvf_iDebugLevel );
1793 | }
1794 | }
1795 | else
1796 | {
1797 | pzXsvfFileName = ppzArgv[ i ];
1798 | printf( "XSVF file = %s\n", pzXsvfFileName );
1799 | }
1800 | }
1801 |
1802 | if ( !pzXsvfFileName )
1803 | {
1804 | printf( "USAGE: playxsvf [-v level] filename.xsvf\n" );
1805 | printf( "where: -v level = verbose, level = 0-4 (default=0)\n" );
1806 | printf( " filename.xsvf = the XSVF file to execute.\n" );
1807 | }
1808 | else
1809 | {
1810 | /* read from the XSVF file instead of a real prom */
1811 | in = fopen( pzXsvfFileName, "rb" );
1812 | if ( !in )
1813 | {
1814 | printf( "ERROR: Cannot open file %s\n", pzXsvfFileName );
1815 | iErrorCode = XSVF_ERRORCODE( XSVF_ERROR_UNKNOWN );
1816 | }
1817 | else
1818 | {
1819 | /* Initialize the I/O. SetPort initializes I/O on first call */
1820 | setPort( TMS, 1 );
1821 |
1822 | /* Execute the XSVF in the file */
1823 | startClock = clock();
1824 | iErrorCode = xsvfExecute();
1825 | endClock = clock();
1826 | fclose( in );
1827 | printf( "Execution Time = %.3f seconds\n",
1828 | (((double)(endClock - startClock))/CLOCKS_PER_SEC) );
1829 | }
1830 | }
1831 |
1832 | return( iErrorCode );
1833 | }
1834 | #endif /* XSVF_MAIN */
1835 |
1836 |
--------------------------------------------------------------------------------
/micro.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * File: micro.h
3 | * Description: This header file contains the function prototype to the
4 | * primary interface function for the XSVF player.
5 | * Usage: FIRST - PORTS.C
6 | * Customize the ports.c function implementations to establish
7 | * the correct protocol for communicating with your JTAG ports
8 | * (setPort() and readTDOBit()) and tune the waitTime() delay
9 | * function. Also, establish access to the XSVF data source
10 | * in the readByte() function.
11 | * FINALLY - Call xsvfExecute().
12 | *****************************************************************************/
13 | #ifndef XSVF_MICRO_H
14 | #define XSVF_MICRO_H
15 |
16 | /* Legacy error codes for xsvfExecute from original XSVF player v2.0 */
17 | #define XSVF_LEGACY_SUCCESS 1
18 | #define XSVF_LEGACY_ERROR 0
19 |
20 | /* 4.04 [NEW] Error codes for xsvfExecute. */
21 | /* Must #define XSVF_SUPPORT_ERRORCODES in micro.c to get these codes */
22 | #define XSVF_ERROR_NONE 0
23 | #define XSVF_ERROR_UNKNOWN 1
24 | #define XSVF_ERROR_TDOMISMATCH 2
25 | #define XSVF_ERROR_MAXRETRIES 3 /* TDO mismatch after max retries */
26 | #define XSVF_ERROR_ILLEGALCMD 4
27 | #define XSVF_ERROR_ILLEGALSTATE 5
28 | #define XSVF_ERROR_DATAOVERFLOW 6 /* Data > lenVal MAX_LEN buffer size*/
29 | /* Insert new errors here */
30 | #define XSVF_ERROR_LAST 7
31 |
32 | /*****************************************************************************
33 | * Function: xsvfExecute
34 | * Description: Process, interpret, and apply the XSVF commands.
35 | * See port.c:readByte for source of XSVF data.
36 | * Parameters: none.
37 | * Returns: int - For error codes see above.
38 | *****************************************************************************/
39 | extern int xsvfExecute();
40 |
41 | #endif /* XSVF_MICRO_H */
42 |
43 |
--------------------------------------------------------------------------------
/ports.cpp:
--------------------------------------------------------------------------------
1 | /*******************************************************/
2 | /* file: ports.c */
3 | /* abstract: This file contains the routines to */
4 | /* output values on the JTAG ports, to read */
5 | /* the TDO bit, and to read a byte of data */
6 | /* from the prom */
7 | /* Revisions: */
8 | /* 12/01/2008: Same code as before (original v5.01). */
9 | /* Updated comments to clarify instructions.*/
10 | /* Add print in setPort for xapp058_example.exe.*/
11 | /*******************************************************/
12 | #include "ports.h"
13 | /*#include "prgispx.h"*/
14 | // #include "stm32_gpio.h"
15 |
16 | static uint32_t port_ = 0; /* Port vlaues */
17 |
18 | /*BYTE *xsvf_data=0;*/
19 |
20 | #if 1
21 | inline void DLY()
22 | {
23 | asm(
24 | "nop\n\t"
25 | "nop\n\t"
26 | "nop\n\t"
27 | "nop\n\t"
28 | "nop\n\t"
29 | );
30 | }
31 | #else
32 | #define DLY()
33 | #endif
34 |
35 | void initPorts()
36 | {
37 | pinMode(TCK, OUTPUT);
38 | pinMode(TMS, OUTPUT);
39 | pinMode(TDI, OUTPUT);
40 | pinMode(TDO, INPUT_PULLUP);
41 | }
42 |
43 | /* setPort: Implement to set the named JTAG signal (p) to the new value (v).*/
44 | /* if in debugging mode, then just set the variables */
45 | void setPort(uint8_t p,uint8_t val)
46 | {
47 | /* Printing code for the xapp058_example.exe. You must set the specified
48 | JTAG signal (p) to the new value (v). See the above, old Win95 code
49 | as an implementation example. */
50 | switch(p)
51 | {
52 | case TMS:
53 | // g_iTMS = val;
54 | if (val) port_ |= 1u << TMS_PIN; else port_ &= ~(1u << TMS_PIN);
55 | break;
56 |
57 | case TDI:
58 | // g_iTDI = val;
59 | if (val) port_ |= 1u << TDI_PIN; else port_ &= ~(1u << TDI_PIN);
60 | break;
61 |
62 | case TCK:
63 | // g_iTCK = val;
64 | if (val) port_ |= 1u << TCK_PIN; else port_ &= ~(1u << TCK_PIN);
65 | #if 1
66 | // uint32_t r = GPIOB->ODR;
67 | // if (g_iTMS) r |= 1u << TMS_PIN; else r &= ~(1u << TMS_PIN);
68 | // if (g_iTDI) r |= 1u << TDI_PIN; else r &= ~(1u << TDI_PIN);
69 | // if (g_iTCK) r |= 1u << TCK_PIN; else r &= ~(1u << TCK_PIN);
70 | // GPIOB->ODR = r;
71 | //GPIOB->ODR = ( GPIOB->ODR & ~( (1u << TMS_PIN) | (1u << TDI_PIN) | (1u << TCK_PIN) ) ) | port_;
72 | GPIOB->regs->ODR = ( GPIOB->regs->ODR & ~( (1u << TMS_PIN) | (1u << TDI_PIN) | (1u << TCK_PIN) ) ) | port_;
73 |
74 | #else
75 | digitalWrite( TMS, g_iTMS );
76 | digitalWrite( TDI, g_iTDI );
77 | digitalWrite( TCK, g_iTCK );
78 | #endif
79 | DLY();
80 | break;
81 |
82 | }
83 | }
84 |
85 |
86 | /* toggle tck LH. No need to modify this code. It is output via setPort. */
87 | void pulseClock()
88 | {
89 | setPort(TCK,0); /* set the TCK port to low */
90 | setPort(TCK,1); /* set the TCK port to high */
91 | }
92 |
93 |
94 | /* readByte: Implement to source the next byte from your XSVF file location */
95 | /* read in a byte of data from the prom */
96 | void readByte(uint8_t *data)
97 | {
98 | *data = read_data();
99 | /**data=*xsvf_data++;*/
100 | }
101 |
102 | /* waitTime: Implement as follows: */
103 | /* REQUIRED: This function must consume/wait at least the specified number */
104 | /* of microsec, interpreting microsec as a number of microseconds.*/
105 | /* REQUIRED FOR SPARTAN/VIRTEX FPGAs and indirect flash programming: */
106 | /* This function must pulse TCK for at least microsec times, */
107 | /* interpreting microsec as an integer value. */
108 | /* RECOMMENDED IMPLEMENTATION: Pulse TCK at least microsec times AND */
109 | /* continue pulsing TCK until the microsec wait */
110 | /* requirement is also satisfied. */
111 | void waitTime(uint32_t microsec)
112 | {
113 | #if 0
114 | static long tckCyclesPerMicrosec = 72/10; /* must be at least 1 */
115 | long tckCycles = microsec * tckCyclesPerMicrosec;
116 | long i;
117 |
118 |
119 | /* This implementation is highly recommended!!! */
120 | /* This implementation requires you to tune the tckCyclesPerMicrosec
121 | variable (above) to match the performance of your embedded system
122 | in order to satisfy the microsec wait time requirement. */
123 | for ( i = 0; i < tckCycles; ++i )
124 | {
125 | pulseClock();
126 | }
127 | #endif
128 |
129 | #if 1
130 | uint32_t t0 = micros();
131 | while( micros()-t0 < microsec )
132 | {
133 | pulseClock();
134 | }
135 | #endif
136 |
137 | #if 0
138 | /* Alternate implementation */
139 | /* For systems with TCK rates << 1 MHz; Consider this implementation. */
140 | /* This implementation does not work with Spartan-3AN or indirect flash
141 | programming. */
142 | if ( microsec >= 50L )
143 | {
144 | /* Make sure TCK is low during wait for XC18V00/XCFxxS */
145 | /* Or, a running TCK implementation as shown above is an OK alternate */
146 | setPort( TCK, 0 );
147 |
148 | /* Use Windows Sleep(). Round up to the nearest millisec */
149 | _sleep( ( microsec + 999L ) / 1000L );
150 | }
151 | else /* Satisfy FPGA JTAG configuration, startup TCK cycles */
152 | {
153 | for ( i = 0; i < microsec; ++i )
154 | {
155 | pulseClock();
156 | }
157 | }
158 | #endif
159 |
160 | #if 0
161 | /* Alternate implementation */
162 | /* This implementation is valid for only XC9500/XL/XV, CoolRunner/II CPLDs,
163 | XC18V00 PROMs, or Platform Flash XCFxxS/XCFxxP PROMs.
164 | This implementation does not work with FPGAs JTAG configuration. */
165 | /* Make sure TCK is low during wait for XC18V00/XCFxxS PROMs */
166 | /* Or, a running TCK implementation as shown above is an OK alternate */
167 | setPort( TCK, 0 );
168 | /* Use Windows Sleep(). Round up to the nearest millisec */
169 | u_sleep( ( microsec + 999L ) / 1000L );
170 | #endif
171 | }
172 |
--------------------------------------------------------------------------------
/ports.h:
--------------------------------------------------------------------------------
1 | /*******************************************************/
2 | /* file: ports.h */
3 | /* abstract: This file contains extern declarations */
4 | /* for providing stimulus to the JTAG ports.*/
5 | /*******************************************************/
6 |
7 | #ifndef ports_dot_h
8 | #define ports_dot_h
9 |
10 | #include "Arduino.h"
11 | /* these constants are used to send the appropriate ports to setPort */
12 | /* they should be enumerated types, but some of the microcontroller */
13 | /* compilers don't like enumerated types */
14 |
15 | /*
16 | Pin assignment on the bluepill:
17 | TCK - PB6
18 | TMS - PB7
19 | TDI - PB8
20 | TDO - PB9
21 | */
22 | #define TCK PB6
23 | #define TCK_PIN 6
24 | #define TMS PB7
25 | #define TMS_PIN 7
26 | #define TDI PB8
27 | #define TDI_PIN 8
28 | #define TDO PB5
29 | #define TDO_PIN 5
30 |
31 | extern uint8_t read_data();
32 | extern void u_sleep( uint32_t m );
33 |
34 | /* Sets up the ports ready */
35 | extern void initPorts();
36 |
37 | /* set the port "p" (TCK, TMS, or TDI) to val (0 or 1) */
38 | extern void setPort(uint8_t p, uint8_t val);
39 |
40 | /* read the TDO bit and store it in val */
41 | inline int readTDOBit()
42 | {
43 | // return digitalRead(TDO);
44 | return (GPIOB->regs->IDR & (1u << TDO_PIN)) != 0;
45 | }
46 |
47 | /* make clock go down->up->down*/
48 | extern void pulseClock();
49 |
50 | /* read the next byte of data from the xsvf file */
51 | extern void readByte(uint8_t *data);
52 |
53 | extern void waitTime(uint32_t microsec);
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/tools/send_xsvf:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # The JTAG Whisperer https://github.com/sowbug/JTAGWhisperer
4 | # Copyright 2012 Mike Tsao http://www.sowbug.com/
5 | #
6 | # See LICENSE file for BSD-style licensing information.
7 | #
8 |
9 | import binascii
10 | from time import time
11 | import getopt
12 | import sys
13 |
14 | try:
15 | import serial
16 | except ImportError:
17 | print """
18 | You don't have pyserial installed. Please install it and try again.
19 | "easy_install pyserial" or "pip install pyserial" will probably work.
20 | """
21 |
22 | total_bytes_sent = 0
23 | need_lf = False
24 | def send_xsvf_chunk(s, xsvf):
25 | global total_bytes_sent, need_lf
26 | if len(xsvf) == 0:
27 | print 'Problem: tried to send empty xsvf.'
28 | return xsvf
29 | chunk = xsvf[:32]
30 | xsvf = xsvf[len(chunk):]
31 | bytes_to_write = len(chunk)
32 | s.write('D')
33 | while bytes_to_write > 0:
34 | bytes_written = s.write(chunk)
35 | total_bytes_sent += bytes_written
36 | print 'DEBUG: SENT: ', binascii.hexlify(chunk)
37 | chunk = chunk[bytes_written:]
38 | bytes_to_write -= bytes_written
39 | # print '\rSent: %8d bytes, %8d remaining' % (total_bytes_sent, len(xsvf)),
40 | need_lf = True
41 | sys.stdout.flush()
42 | return xsvf
43 |
44 | def get_xsvf_checksum(xsvf):
45 | xsvf_sum = 0
46 | for c in xsvf:
47 | xsvf_sum += ord(c)
48 | return (xsvf_sum, len(xsvf))
49 |
50 | def maybe_print_lf():
51 | global need_lf
52 | if need_lf:
53 | need_lf = False
54 | print
55 |
56 | def program(xsvf_filename, port, bps):
57 | global total_bytes_sent
58 | start_time = 0
59 |
60 | f = open(xsvf_filename, 'rb')
61 | xsvf = f.read()
62 | f.close()
63 | print 'Ready to send file of size %d bytes.' % (len(xsvf))
64 |
65 | (xsvf_sum, xsvf_len) = get_xsvf_checksum(xsvf)
66 |
67 | s = serial.Serial(port=port, baudrate=bps, rtscts=True)
68 | s.flushInput()
69 | s.write('R')
70 | s.flushOutput()
71 | is_device_ready = False
72 | while True:
73 | line = s.readline().strip()
74 | if len(line) == 0:
75 | continue
76 | print 'DEBUG: ', line
77 | command = line[0]
78 | text = line[1:].strip()
79 |
80 | if command == 'A':
81 | # if text == 'XSVF':
82 | if not is_device_ready:
83 | is_device_ready = True
84 | print 'Device is ready.'
85 | start_time = time()
86 | # continue
87 | # elif text == 'SEND':
88 | if len(xsvf) == 0: break
89 | xsvf = send_xsvf_chunk(s, xsvf)
90 | # continue
91 | # else:
92 | # print 'Unrecognized ready command:', text
93 | elif command == 'Q':
94 | maybe_print_lf()
95 | print 'Received device quit:', text
96 | break
97 | elif command == 'G':
98 | maybe_print_lf()
99 | print 'Device:', text
100 | if text[0:5] == 'ERROR':
101 | print 'Received an ERROR. Stop.'
102 | break
103 | # elif command == '!':
104 | # maybe_print_lf()
105 | # print 'IMPORTANT:', text
106 | else:
107 | maybe_print_lf()
108 | print 'Unrecognized line:', line
109 |
110 | s.close()
111 | print 'Expected checksum: %lx/%lx.' % (xsvf_sum, xsvf_len)
112 | if start_time > 0:
113 | print 'Elapsed time: %.02f seconds.' % (time() - start_time)
114 | return 0
115 |
116 | def usage():
117 | print 'send_xsvf [-b bps] -p /dev/your_arduino_serial_port xsvf_filename'
118 |
119 | def main():
120 | try:
121 | opts, args = getopt.getopt(sys.argv[1:], 'b:p:', ['bps=', 'port='])
122 | except getopt.GetoptError, err:
123 | print str(err)
124 | usage()
125 | sys.exit(2)
126 | xsvf_filename = args[0]
127 | port = None
128 | bps = 115200
129 |
130 | for o, a in opts:
131 | if o in ['-b', '--bps']:
132 | bps = int(a)
133 | elif o in ['-p', '--port']:
134 | port = a
135 | else:
136 | assert False, 'unhandled option'
137 |
138 | if port is None:
139 | usage()
140 | sys.exit(2)
141 |
142 | sys.exit(program(xsvf_filename, port, bps))
143 |
144 | if __name__ == '__main__':
145 | main()
146 |
--------------------------------------------------------------------------------
/xsvfduino.ino:
--------------------------------------------------------------------------------
1 | ///
2 | // An XSVF player for the Arduino
3 | //
4 | // Tested with the STM32 Arduino clone known as the Blue Pill
5 | //
6 | // Settings:
7 | // Board: BluePill F103CB
8 | // USB: Virtual COMM
9 | // Serial: SerialUSB
10 |
11 |
12 | #if MENU_SERIAL != SerialUSB
13 | #error "Make sure that the SerialUSB option is selected"
14 | #endif
15 |
16 | #define LED PC13
17 |
18 | uint8_t xsvf_buf[32]; // 32-bit chunks
19 | int8_t xsvf_buf_ptr = 32, xsvf_buf_len = 0;
20 |
21 | #include "ports.h"
22 | #include "micro.h"
23 | #include
24 | #include
25 | #include
26 |
27 | bool ongoing = false; // Is there an ongoing transmission?
28 | jmp_buf glb_jmp_buf;
29 |
30 | void debug_printf(char *format,...)
31 | {
32 | static bool send_g = true;
33 | char buf[256];
34 | va_list args;
35 | va_start(args, format);
36 | vsprintf(buf, format, args);
37 | va_end(args);
38 | if (send_g)
39 | {
40 | Serial.print('G'); // TODO: send this only at the beginning of a line
41 | send_g = false;
42 | }
43 | if ( strchr(buf, '\n') != NULL )
44 | send_g = true;
45 | Serial.print(buf);
46 | Serial.flush();
47 | yield();
48 | if ( !strncmp(buf, "ERROR", 5) )
49 | longjmp(glb_jmp_buf, 1);
50 | }
51 |
52 | uint8_t read_data()
53 | {
54 | if (xsvf_buf_ptr < xsvf_buf_len)
55 | return xsvf_buf[xsvf_buf_ptr++];
56 | if (ongoing)
57 | Serial.println("A"); // Todo: send extra info with the ack (debug info?)
58 | xsvf_buf_len = -1;
59 | xsvf_buf_ptr = 0;
60 | while(xsvf_buf_len < 32)
61 | {
62 | uint32_t t0 = millis(), t1 = t0;
63 | while(!Serial.available())
64 | {
65 | uint32_t t2 = millis();
66 | if (t2 - t1 > 500)
67 | {
68 | digitalWrite(LED, !digitalRead(LED)); // Toggles the LED
69 | t1 = t2;
70 | }
71 | if (t2 - t0 > 1000) // Timeout waiting for packet
72 | {
73 | if (xsvf_buf_ptr < xsvf_buf_len) // Any data on the buffer?
74 | {
75 | return xsvf_buf[xsvf_buf_ptr++]; // Yes, return it
76 | }
77 | else
78 | if (ongoing && t2 - t0 > 3000)
79 | {
80 | Serial.print("QINFO: Timeout waiting for a packet. (End of Data?)\n");
81 | Serial.flush();
82 | yield();
83 | longjmp(glb_jmp_buf, 1); // Waiting for too long, reset the engine
84 | }
85 | }
86 | yield();
87 | }
88 | uint8_t c = Serial.read();
89 | ongoing = true;
90 | if (xsvf_buf_len < 0)
91 | {
92 | if (c == 'D') // Data packet TODO: packet numbering and CRC checking
93 | xsvf_buf_len = 0; // Receive the rest of the packet
94 | if (c == 'R')
95 | Serial.println("A");
96 | }
97 | else
98 | {
99 | if (xsvf_buf_len < 32)
100 | {
101 | xsvf_buf[xsvf_buf_len++] = c;
102 | }
103 | }
104 | }
105 | return xsvf_buf[xsvf_buf_ptr++];
106 | }
107 |
108 | void u_sleep( uint32_t m )
109 | {
110 | delayMicroseconds( m );
111 | }
112 |
113 |
114 | void setup()
115 | {
116 | initPorts();
117 | pinMode(LED, OUTPUT);
118 | digitalWrite(LED, HIGH);
119 | Serial.begin(115200);
120 | Serial.println("A");
121 | }
122 |
123 | int cnt = 1;
124 | String buf;
125 |
126 | void loop()
127 | {
128 | ongoing = false;
129 | if ( !setjmp(glb_jmp_buf) )
130 | xsvfExecute();
131 | }
132 |
--------------------------------------------------------------------------------