forked from Qortal/Brooklyn
gnuk is now part of source tree
This commit is contained in:
parent
13f0645c94
commit
09eb29b349
67
gnuk/AUTHORS
67
gnuk/AUTHORS
@ -1,67 +0,0 @@
|
|||||||
Aurelien Jarno:
|
|
||||||
Modified:
|
|
||||||
src/Makefile
|
|
||||||
src/configure
|
|
||||||
src/main.c
|
|
||||||
src/stack-def.h
|
|
||||||
|
|
||||||
Anthony Romano:
|
|
||||||
Modified:
|
|
||||||
src/call-rsa.c
|
|
||||||
src/main.c
|
|
||||||
src/mod.c
|
|
||||||
|
|
||||||
Jeremy Drake:
|
|
||||||
Modified:
|
|
||||||
regnual/regnual.c
|
|
||||||
|
|
||||||
Kaz Kojima:
|
|
||||||
Added STM32 Primer2 support.
|
|
||||||
|
|
||||||
NIIBE Yutaka:
|
|
||||||
Founder of the project.
|
|
||||||
Wrote tools for STLink/V2:
|
|
||||||
tool/stlinkv2.py
|
|
||||||
Wrote tools for DfuSe:
|
|
||||||
tool/dfuse.py
|
|
||||||
tool/dump_mem.py
|
|
||||||
tool/intel_hex.py
|
|
||||||
Wrote a tool for Gnuk:
|
|
||||||
tool/gnuk_put_binary.py
|
|
||||||
tool/gnuk_put_binary_libusb.py
|
|
||||||
tool/gnuk_remove_keys.py
|
|
||||||
tool/gnuk_upgrade.py
|
|
||||||
Wrote a tool for USB Hub:
|
|
||||||
tool/hub_ctrl.py
|
|
||||||
Wrote a tool for testing card reader with pinpad:
|
|
||||||
tool/pinpadtest.py
|
|
||||||
Wrote reGNUal implementation:
|
|
||||||
regnual/regnual.c
|
|
||||||
regnual/sys.c
|
|
||||||
Wrote Gnuk implementation:
|
|
||||||
gnuk.svg
|
|
||||||
src/configure
|
|
||||||
src/ac.c
|
|
||||||
src/call-rsa.c
|
|
||||||
src/debug.c
|
|
||||||
src/flash.c
|
|
||||||
src/gnuk.h
|
|
||||||
src/main.c
|
|
||||||
src/neug.c
|
|
||||||
src/openpgp-do.c
|
|
||||||
src/openpgp.c
|
|
||||||
src/openpgp.h
|
|
||||||
src/pin-cir.c
|
|
||||||
src/pin-dial.c
|
|
||||||
src/pin-dnd.c
|
|
||||||
src/random.c
|
|
||||||
src/sys.c
|
|
||||||
src/usb-icc.c
|
|
||||||
src/usb-msc.c
|
|
||||||
src/usb-msc.h
|
|
||||||
src/usb_ctrl.c
|
|
||||||
src/usb_desc.c
|
|
||||||
src/usb_lld.c
|
|
||||||
src/usb_lld.h
|
|
||||||
*
|
|
||||||
and others.
|
|
2218
gnuk/ChangeLog
2218
gnuk/ChangeLog
File diff suppressed because it is too large
Load Diff
2477
gnuk/ChangeLog-1_0
2477
gnuk/ChangeLog-1_0
File diff suppressed because it is too large
Load Diff
BIN
gnuk/FSIJ-s.png
BIN
gnuk/FSIJ-s.png
Binary file not shown.
Before Width: | Height: | Size: 8.7 KiB |
@ -1,2 +0,0 @@
|
|||||||
# Email # 6-byte serial number, separated by ':'
|
|
||||||
gniibe@fsij.org f5:17:00:00:00:01
|
|
@ -1,5 +0,0 @@
|
|||||||
# VID:PID bcdDev Product_STRING Vendor_STRING
|
|
||||||
0000:0000 0200 Gnuk Emulation Free Software Initiative of Japan
|
|
||||||
234b:0000 0200 Gnuk Token Free Software Initiative of Japan
|
|
||||||
20a0:4211 0200 Nitrokey Start Nitrokey
|
|
||||||
##########<TAB> ##<TAB> ##########<TAB> #################
|
|
674
gnuk/LICENSE
674
gnuk/LICENSE
@ -1,674 +0,0 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
|
||||||
software and other kinds of works.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
|
||||||
share and change all versions of a program--to make sure it remains free
|
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
|
||||||
GNU General Public License for most of our software; it applies also to
|
|
||||||
any other work released this way by its authors. You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
|
||||||
or can get the source code. And you must show them these terms so they
|
|
||||||
know their rights.
|
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
|
||||||
that there is no warranty for this free software. For both users' and
|
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
|
||||||
changed, so that their problems will not be attributed erroneously to
|
|
||||||
authors of previous versions.
|
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
|
||||||
modified versions of the software inside them, although the manufacturer
|
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
|
||||||
protecting users' freedom to change the software. The systematic
|
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
|
||||||
products. If such problems arise substantially in other domains, we
|
|
||||||
stand ready to extend this provision to those domains in future versions
|
|
||||||
of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
|
||||||
avoid the special danger that patents applied to a free program could
|
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
|
||||||
patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
0. Definitions.
|
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
|
||||||
"recipients" may be individuals or organizations.
|
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
|
||||||
earlier work or a work "based on" the earlier work.
|
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
|
||||||
to the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
1. Source Code.
|
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
|
||||||
for making modifications to it. "Object code" means any non-source
|
|
||||||
form of a work.
|
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
|
||||||
can regenerate automatically from other parts of the Corresponding
|
|
||||||
Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
|
||||||
same work.
|
|
||||||
|
|
||||||
2. Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
|
||||||
convey, without conditions so long as your license otherwise remains
|
|
||||||
in force. You may convey covered works to others for the sole purpose
|
|
||||||
of having them make modifications exclusively for you, or provide you
|
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
|
||||||
modification of the work as a means of enforcing, against the work's
|
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the special requirements of the GNU Affero General Public License,
|
|
||||||
section 13, concerning interaction through a network will apply to the
|
|
||||||
combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Program specifies that a certain numbered version of the GNU General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
|
||||||
notice like this when it starts in an interactive mode:
|
|
||||||
|
|
||||||
<program> Copyright (C) <year> <name of author>
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, your program's commands
|
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
|
||||||
<http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
|
||||||
may consider it more useful to permit linking proprietary applications with
|
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License. But first, please read
|
|
||||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
|
787
gnuk/NEWS
787
gnuk/NEWS
@ -1,787 +0,0 @@
|
|||||||
Gnuk NEWS - User visible changes
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.2.6
|
|
||||||
|
|
||||||
Released 2017-10-11, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Port to GNU/Linux emulation
|
|
||||||
We can "run" Gnuk Token on GNU/Linux by emulation through USBIP.
|
|
||||||
|
|
||||||
** Upgrade of Chopstx
|
|
||||||
We use Chopstx 1.5.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.2.5
|
|
||||||
|
|
||||||
Released 2017-08-11, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** "factory-reset" fix
|
|
||||||
Gnuk's behavior was implemented by referring the gpg implementation.
|
|
||||||
It found that gpg implementation was not good from the viewpoint of
|
|
||||||
the OpenPGP card specification. GnuPG was fixed to match the OpenPGP
|
|
||||||
card specification already. Thus, Gnuk is now fixed.
|
|
||||||
|
|
||||||
** Upgrade of Chopstx
|
|
||||||
We use Chopstx 1.4.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.2.4
|
|
||||||
|
|
||||||
Released 2017-05-12, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Flash ROM security fix
|
|
||||||
The partial content of flash ROM might be exposed when scanning of
|
|
||||||
data object had a problem. Added boundary check and changed layout of
|
|
||||||
flash ROM.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.2.3
|
|
||||||
|
|
||||||
Released 2017-02-02, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** ECC key generation on the device
|
|
||||||
Bug fixed.
|
|
||||||
|
|
||||||
** Upgrade of Chopstx
|
|
||||||
We use Chopstx 1.3.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.2.2
|
|
||||||
|
|
||||||
Released 2016-10-15, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Change of SELECT FILE behavior
|
|
||||||
Gnuk used to reply AID upon SELECT FILE command. Now, to be compatible
|
|
||||||
to original OpenPGP card, it returns nothing but status code of 9000.
|
|
||||||
|
|
||||||
** Added feature of Factory Reset as compile time option
|
|
||||||
Original OpenPGP card has the feature, and Gnuk is now configurable to
|
|
||||||
support the feature.
|
|
||||||
|
|
||||||
** Upgrade of Chopstx
|
|
||||||
We use Chopstx 1.2.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.2.1
|
|
||||||
|
|
||||||
Released 2016-07-11, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Upgrade of Chopstx
|
|
||||||
We use Chopstx 1.1.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.2.0
|
|
||||||
|
|
||||||
Released 2016-05-20, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Upgrade of Chopstx
|
|
||||||
We use Chopstx 0.11.
|
|
||||||
|
|
||||||
** Support authentication status reset by VERIFY command.
|
|
||||||
This feature is described in the OpenPGPcard specification V2.2 and
|
|
||||||
V3.1, which allow user to reset authentication status.
|
|
||||||
|
|
||||||
** S2K algorithm tweak to defeat "copycat" service of MCU.
|
|
||||||
Even if the existence of some services copying MCU, your private key
|
|
||||||
will not be controled by others, in some cases.
|
|
||||||
|
|
||||||
** Bug fix for secp256k1 and NIST P-256.
|
|
||||||
Bugs in basic computation were fixed.
|
|
||||||
|
|
||||||
** Bug fix for bignum routines.
|
|
||||||
Bignum routine update from upstream (failure doesn't occur for our RSA
|
|
||||||
computation, though). Another fix for mpi_exp_mod.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.1.9
|
|
||||||
|
|
||||||
Released 2015-09-18, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Bug fix for Ed25519 and Curve25519
|
|
||||||
When registering key, wrong operations were not detected correctly.
|
|
||||||
This is fixed.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.1.8
|
|
||||||
|
|
||||||
Released 2015-09-17, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Upgrade of Chopstx
|
|
||||||
We use Chopstx 0.10, which supports Nitrokey-Start.
|
|
||||||
|
|
||||||
** Card serial number
|
|
||||||
The way to determine a serial number of Gnuk Token for card has been
|
|
||||||
changed. It uses the 96-bit unique bits of MCU, but the portion for
|
|
||||||
use is changed.
|
|
||||||
|
|
||||||
** USB Reset handling
|
|
||||||
USB reset lets Gnuk Token restart. It would not be perfect, when it's
|
|
||||||
during computation of some function, but most parts are protected by
|
|
||||||
Chopstx's feature of cancellation.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.1.7
|
|
||||||
|
|
||||||
Released 2015-08-05, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Upgrade of Chopstx
|
|
||||||
We use Chopstx 0.08, which supports STM32 Nucleo and ST Dongle.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.1.6
|
|
||||||
|
|
||||||
Released 2015-07-21, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** USB SerialNumber String
|
|
||||||
The way to determine a serial number of Gnuk Token has been changed.
|
|
||||||
It uses the 96-bit unique bits of MCU, but the portion for use is
|
|
||||||
changed.
|
|
||||||
|
|
||||||
** Upgrade of Chopstx
|
|
||||||
We use Chopstx 0.07, which supports STM32 Primer2 and CQ STARM, too.
|
|
||||||
|
|
||||||
** Experimental Curve25519 support.
|
|
||||||
|
|
||||||
Gnuk can support Curve25519 (for decryption). Note that this is
|
|
||||||
pretty much experimental, and subjects to change. The low level code
|
|
||||||
is somehow stable, but there are no consensus in higer level.
|
|
||||||
Especially, OID in the key attribute would be changed in future.
|
|
||||||
|
|
||||||
** No --enable-keygen option
|
|
||||||
It is now standard feature included always. Note that it doesn't mean
|
|
||||||
this feature is stable now. It is becoming stable, hopefully.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.1.5
|
|
||||||
|
|
||||||
Released 2015-06-03, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** upgrade_by_passwd.py is not so noisy any more.
|
|
||||||
Since it's getting stable, no debug output any more.
|
|
||||||
|
|
||||||
** Maple mini support.
|
|
||||||
Although its random number generation is not tested, Maple mini
|
|
||||||
support is added.
|
|
||||||
|
|
||||||
** Windows interoperability fix.
|
|
||||||
1.1.x (0 to 4) didn't work with Windows because of INTERRUPT transfer.
|
|
||||||
It's fixed and it works now.
|
|
||||||
|
|
||||||
** OpenPGPcard specification v3.0 compatibility.
|
|
||||||
OpenPGPcard specification v3.0 now include NIST curves (and other
|
|
||||||
curves) and ECDSA and ECDH operations are defined. Gnuk follows
|
|
||||||
this specification.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.1.4
|
|
||||||
|
|
||||||
Released 2014-12-15, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Experimental RSA-4096 support.
|
|
||||||
Although it takes too long (more than 8.7 second), RSA-4096
|
|
||||||
is now implemented.
|
|
||||||
|
|
||||||
** ECDH support.
|
|
||||||
ECDH is now supported. You need development branch (master)
|
|
||||||
of GnuPG to use this feature.
|
|
||||||
|
|
||||||
** ECDSA and EdDSA is not that experimental.
|
|
||||||
You don't need to edit DEFS variable in src/Makefile.
|
|
||||||
|
|
||||||
** STM8S_DISCOVERY is not supported any more.
|
|
||||||
It's flash ROM size (64KiB) is a bit small to have all features of
|
|
||||||
Gnuk now. If you manually edit code to limit the size of executable,
|
|
||||||
it still could run Gnuk, though.
|
|
||||||
|
|
||||||
** configure's default target is now FST-01.
|
|
||||||
Receiving reports from those who complain default target, I
|
|
||||||
reconsidered. Those who has Olimex STM32 H103 usually has JTAG
|
|
||||||
debugger, while FST-01 users don't. So, to be safe, the default
|
|
||||||
target is now FST-01, instead of Olimex STM32 H103.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.1.3
|
|
||||||
|
|
||||||
Released 2014-04-16, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Experimental EdDSA support.
|
|
||||||
After configure, you can edit the DEFS variable in src/Makefile, so
|
|
||||||
that Gnuk can support EdDSA with Ed25519 (for authentication). Note
|
|
||||||
that this is pretty much experimental, and subjects to change.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.1.2
|
|
||||||
|
|
||||||
Released 2014-03-07, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Experimental ECC support for secp256k1.
|
|
||||||
After configure, you can edit the DEFS variable in src/Makefile, so
|
|
||||||
that Gnuk can support ECDSA with NIST P256 (for authentication), and
|
|
||||||
ECDSA with secp256k1 (for signature). Note that this is pretty much
|
|
||||||
experimental, and subjects to change.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.1.1
|
|
||||||
|
|
||||||
Released 2013-12-25, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Tools and test suite now work with PyUSB 1.0, too.
|
|
||||||
It only worked with PyUSB 0.4.3, but it works with PyUSB 1.0 too.
|
|
||||||
|
|
||||||
** Improved RSA routine
|
|
||||||
Working memory for RSA computation is taken from stack instead of
|
|
||||||
malloc (mostly).
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.1.0
|
|
||||||
|
|
||||||
Released 2013-12-20, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Overriding key import / generation (Incompatible Change)
|
|
||||||
Gnuk supports overriding key import or key generation even if keys are
|
|
||||||
already installed. Note that it will result password reset of user.
|
|
||||||
|
|
||||||
** RSA key generation improvement
|
|
||||||
Prime number generation is done by Fouque-Tibouchi method.
|
|
||||||
|
|
||||||
** Security fix for RSA computation
|
|
||||||
PolarSSL had a vulnerability against timing attack. For detail,
|
|
||||||
please see:
|
|
||||||
|
|
||||||
http://www.gniibe.org/memo/development/gnuk/polarssl/polarssl-rsa-blinding
|
|
||||||
|
|
||||||
** Improved RSA routine
|
|
||||||
RSA computation has been improved using MPI square routine. Note that
|
|
||||||
you should not adopt this modification for general purpose computer,
|
|
||||||
as this change is weak against the Yarom/Falkner flush+reload cache
|
|
||||||
side-channel attack.
|
|
||||||
|
|
||||||
** Upgrade of NeuG
|
|
||||||
The true random number generator was upgraded to the one of NeuG 1.0.
|
|
||||||
|
|
||||||
** Replacement of kernel (thread library)
|
|
||||||
Instead of ChibiOS/RT, we now use Chopstx.
|
|
||||||
|
|
||||||
** Removal of obsolete features
|
|
||||||
The feature named pin-dial, which is pin input with hardware
|
|
||||||
enhancement (with rotary encoder) is removed.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.0.4
|
|
||||||
|
|
||||||
Released 2013-03-15, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Relocatable reGNUal, really
|
|
||||||
In 1.0.3, reGNUal was not fully relocatable. It worked loaded on higher
|
|
||||||
address, but didn't work for lower address. This was fixed.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.0.3
|
|
||||||
|
|
||||||
Released 2013-03-14, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Relocatable reGNUal
|
|
||||||
The upgrade helper, reGNUal, is now relocatable (other than the first
|
|
||||||
vector table). It runs well when loaded at different address. This
|
|
||||||
makes the upgrade procedure more stable.
|
|
||||||
|
|
||||||
** Compilation by newer GNU Toolchain
|
|
||||||
Now, Gnuk can be compiled with newer GNU Toolchain, specifically GCC
|
|
||||||
4.7.x and GNU Binutils 2.22. Old versions of Gnuk had problem for
|
|
||||||
ChibiOS_2.0.8/os/ports/GCC/ARMCMx/cmsis/core_cm3.c, which was fixed.
|
|
||||||
|
|
||||||
** Data object 0x0073
|
|
||||||
Data object 0x0073 is now available.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.0.2
|
|
||||||
|
|
||||||
Released 2013-02-15, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Product string is now "Gnuk Token" (was: "FSIJ USB Token")
|
|
||||||
Since the USB ID Repository suggests not including vendor name
|
|
||||||
in product string, we changed the product string.
|
|
||||||
|
|
||||||
** New tool (experimental): test/upgrade_by_passwd.py
|
|
||||||
This is the tool to install new firmware to Gnuk Token, provided
|
|
||||||
that it's just shipped from factory (and nothing changed). It
|
|
||||||
authenticate as admin by factory setting, register a public key
|
|
||||||
for firmware upgrade, and then, does firmware upgrade.
|
|
||||||
|
|
||||||
** tool/gnuk_upgrade.py supports '-k' option
|
|
||||||
It now supports RSA key on the host PC (not the one on the Token).
|
|
||||||
|
|
||||||
** New tool: tool/get_raw_public_key.py
|
|
||||||
This is a script to dump raw data of RSA public key, which is useful
|
|
||||||
to register to Gnuk Token as a firmware upgrade key.
|
|
||||||
|
|
||||||
** New tool: tool/gnuk_remove_keys_libusb.py
|
|
||||||
This tool is libusb version of gnuk_remove_keys.py. Besides, a bug in
|
|
||||||
gnuk_remove_keys.py was fixed.
|
|
||||||
|
|
||||||
** CCID protocol fix
|
|
||||||
When time extension is requested by Gnuk Token to host PC, argument
|
|
||||||
field was 0, which was wrong (but it works for most PC/SC
|
|
||||||
implementations and GnuPG internal driver). Now it's 1, which means
|
|
||||||
1*BWT.
|
|
||||||
|
|
||||||
** OpenPGP card protocol enhancement
|
|
||||||
Now, VERIFY command accepts empty data and returns remaining trial
|
|
||||||
counts, or 0x9000 (OK) when it's already authenticated. This is
|
|
||||||
useful for application to synchronize card's authentication status.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.0.1
|
|
||||||
|
|
||||||
Released 2012-08-03, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** USB SerialNumber String
|
|
||||||
In 1.0, it has a bug for USB SerialNumber String. It has been fixed
|
|
||||||
in 1.0.1.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 1.0
|
|
||||||
|
|
||||||
Released 2012-07-21, by NIIBE Yutaka
|
|
||||||
|
|
||||||
This is bug fixes only release.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.21
|
|
||||||
|
|
||||||
Released 2012-07-06, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Test suite
|
|
||||||
A functinality test suite is added under test/ directory.
|
|
||||||
|
|
||||||
** New tool: stlinkv2.py
|
|
||||||
This tool is SWD flash ROM writer with ST-Link/V2.
|
|
||||||
|
|
||||||
** New tool: usb_strings.py
|
|
||||||
This tool is to dump USB strings, which include revision detail and config
|
|
||||||
options.
|
|
||||||
|
|
||||||
** Protection improvement (even when internal data is disclosed)
|
|
||||||
Even if PW1 and PW3 is same, content of encrypted DEK is different
|
|
||||||
now.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.20
|
|
||||||
|
|
||||||
Released 2012-06-19, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Key generation feature added
|
|
||||||
Finally, key generation is supported. Note that it may be very slow.
|
|
||||||
It may take a few minutes (or more) to generate two or three keys,
|
|
||||||
when you are unlucky.
|
|
||||||
|
|
||||||
** DnD pinentry support is deprecated
|
|
||||||
Once, DnD pinentry was considered a great feature, but it found that
|
|
||||||
it is difficult to remember moves of folders.
|
|
||||||
|
|
||||||
** gnuk_upgrade.py assumes using another token for authentication
|
|
||||||
Use of another token for authentication is assumed now. This is
|
|
||||||
incompatible change. Note that when you upgrade a token of version
|
|
||||||
0.19 to 0.20 (or later), you need gnuk_upgrade.py of version 0.19.
|
|
||||||
|
|
||||||
** KDF (Key Derivation Function) is now SHA-256
|
|
||||||
Keystring is now computed by SHA-256 (it was SHA1 before).
|
|
||||||
|
|
||||||
** Protection improvements (even when internal data is disclosed)
|
|
||||||
Three improvements. (1) Even if PW1 and Reset-code is same, content
|
|
||||||
of encrypted DEK is different now. (2) DEK is now encrypted and
|
|
||||||
decrypted by keystring in ECB mode (it was just a kind of xor by
|
|
||||||
single block CFB mode). (3) Key data plus checksum are encrypted in
|
|
||||||
CFB mode with initial vector (it will be able to switch OCB mode
|
|
||||||
easily).
|
|
||||||
|
|
||||||
** LED display output change
|
|
||||||
LED display output by Gnuk is now more reactive. It shows status code
|
|
||||||
when it gets GET_STATUS message of CCID. When you communicate Gnuk by
|
|
||||||
internal CCID driver of GnuPG (instead of PC/SC), and enable
|
|
||||||
'debug-disable-ticker' option in .gnupg/scdaemon.conf, it is more
|
|
||||||
silent now.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.19
|
|
||||||
|
|
||||||
Released 2012-06-06, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Firmware upgrade feature
|
|
||||||
Firmware upgrade is now possible after the public key authentication
|
|
||||||
using EXTERNAL AUTHENTICATE command of ISO 7816. Firmware upgrade is
|
|
||||||
done together with reGNUal, the firmware upgrade program.
|
|
||||||
|
|
||||||
** System service blocks at the beginning of flash ROM.
|
|
||||||
Once flash ROM is protected, first 4-KiB cannot be modified. Gnuk
|
|
||||||
use this area for "system service". Note that this area will not
|
|
||||||
be able to be modified by firmware upgrade (or by any method).
|
|
||||||
|
|
||||||
** New tool: gnuk_upgrade.py
|
|
||||||
The tool gnuk_upgrade.py is to do public key authentication using
|
|
||||||
gpg-agent and send reGNUal to Gnuk. Then, we put new Gnuk binary
|
|
||||||
into the device with reGNUal.
|
|
||||||
|
|
||||||
** USB strings for revision detail, configure options, and system service.
|
|
||||||
USB strings now have more information. There are revision detail
|
|
||||||
string, configure options string, system service version string, as
|
|
||||||
well as vendor string and product string. These strings could be
|
|
||||||
examined to check Gnuk Token.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.18
|
|
||||||
|
|
||||||
Released 2012-05-15, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** New mandatory option '--vidpid' for configure
|
|
||||||
You must specify USB vendor ID and product ID for Gnuk.
|
|
||||||
The file GNUK_USB_DEVICE_ID lists valid USB device IDs.
|
|
||||||
|
|
||||||
** New tool: gnuk_remove_keys.py
|
|
||||||
The tool gnuk_remove_keys.py is to remove all keys in Gnuk Token
|
|
||||||
and reset PW1 and RC (if any).
|
|
||||||
|
|
||||||
** New USB stack
|
|
||||||
Gnuk used to use USB stack of USB-FS-Device_Lib by ST. Now, it has
|
|
||||||
original implementation. Hopefully, size and quality are improved.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.17
|
|
||||||
|
|
||||||
Released 2012-02-02, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** USB CCID/ICCD protocol implementation change
|
|
||||||
Gnuk now only supports short APDU level exchange, not supporting
|
|
||||||
extended APDU level exchange. Thus, Gnuk could be compatible to older
|
|
||||||
host side software implementation.
|
|
||||||
|
|
||||||
** ISO 7816 SELECT command behavior is somewhat strict now
|
|
||||||
Old implementations do not check DF name for SELECT command.
|
|
||||||
This causes some trouble when Gnuk Token is identified as if it were
|
|
||||||
different card/token. Now, DF name of OpenPGP card is checked.
|
|
||||||
|
|
||||||
** USB CCID/ICCD low-level bug is fixed
|
|
||||||
When the size of command APDU data is just 49, the lower level packet
|
|
||||||
size is 64. This is maximum size of BULK-OUT transfer packet, and
|
|
||||||
caused trouble in the past implementations. Example is setting url
|
|
||||||
(0x5f50) as: http://www.gniibe.org/adpu-string-size-is-just-49
|
|
||||||
This is because the past implementations expect ZLP (zero length
|
|
||||||
packet). Now, it has been fixed. You can use any size of string.
|
|
||||||
|
|
||||||
** CERT.3 Data Object (0x7f21) is now optional
|
|
||||||
As there's no valid use case for this data object and it does not
|
|
||||||
work as current version of GnuPG, this is now optional feature.
|
|
||||||
You can enable this data object by specifying --enable-certdo at
|
|
||||||
configure time.
|
|
||||||
|
|
||||||
** With DnD pinentry, user can cancel pin input
|
|
||||||
Now, user can cancel pin input by unmounting device before finishing
|
|
||||||
DnD.
|
|
||||||
|
|
||||||
** New tool: pinpadtest.py
|
|
||||||
The tool pinpadtest.py is PC/SC test tool for pinentry of pinpad with
|
|
||||||
OpenPGP card v2.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.16
|
|
||||||
|
|
||||||
Released 2011-12-14, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** DnD pinentry support is added and it's default to pinentry support
|
|
||||||
DnD pinentry support doesn't require any hardware extension, but
|
|
||||||
emulates mass storage class device of USB. User inputs pass phrase
|
|
||||||
by "drag and drop"-ing folders using file manager or something.
|
|
||||||
|
|
||||||
** Bug fix for VERIFY for CHV2
|
|
||||||
With no keys, VERIFY command for CHV2 used to fail even if pass phrase
|
|
||||||
is correct. It was intentional, because CHV2 verification would be
|
|
||||||
useless with no keys. But there is a corner case for PRIVATE-DOs,
|
|
||||||
which may requires CHV2 verification. Even though Gnuk doesn't
|
|
||||||
support any PRIVATE-DOs, it is good to be fixed.
|
|
||||||
|
|
||||||
** Changed bcdUSB = 1.1
|
|
||||||
Gnuk device conforms to USB 2.0 full speed device, but when it was
|
|
||||||
2.0, some OS informs users, "you can connect the device to 2.0
|
|
||||||
compliant hub so that it can have better bandwidth", which is not
|
|
||||||
the case for full speed device.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.15
|
|
||||||
|
|
||||||
Released 2011-11-24, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** New targets: FST_01 and FST_01_00
|
|
||||||
Flying Stone Technology's open hardware, Flying Stone Tiny 01 is
|
|
||||||
supported.
|
|
||||||
|
|
||||||
** Flash writing tool for "DfuSe" is improved
|
|
||||||
Now, it supports holes and unaligned blocks in hex file.
|
|
||||||
|
|
||||||
** Experimental PIN-pad support (by TV controller) change
|
|
||||||
Now, Gnuk has codetables for conversion from CIR code to ASCII code.
|
|
||||||
Note that only four controllers (of Dell, Sharp, Sony, and Toshiba)
|
|
||||||
are supported and tested.
|
|
||||||
|
|
||||||
** It is possible for users to keep using OPENPGP_CARD_INITIAL_PW1
|
|
||||||
With a bug fix of verify_user_0, it's now possible. Although it's not
|
|
||||||
recommended.
|
|
||||||
|
|
||||||
** Important bug fix and a workaround
|
|
||||||
In version 0.14, __main_stack_size__ (for interrupt handler) was too
|
|
||||||
small for some cases. This is fixed in 0.15.
|
|
||||||
|
|
||||||
In src/Makefile.in, added -mfix-cortex-m3-ldrd for correctly linking C
|
|
||||||
library for thumb2. This is needed for newer summon-arm-toolchain.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.14
|
|
||||||
|
|
||||||
Released 2011-10-07, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Random number generator change
|
|
||||||
NeuG, Gniibe's True RNG implementation for STM32F103, has been
|
|
||||||
integrated to Gnuk. It is not needed to put random number bytes
|
|
||||||
(generated by host) to Token any more.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.13
|
|
||||||
|
|
||||||
Released 2011-06-15, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Improved RSA routine.
|
|
||||||
About 20% speed improvement.
|
|
||||||
|
|
||||||
** New tool: hub_ctrl.
|
|
||||||
It is a Python implementation ported from original C implementation.
|
|
||||||
It is useful for development of USB target if you have a good hub.
|
|
||||||
You can power off/on the port to reset Gnuk Token.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.12
|
|
||||||
|
|
||||||
Released 2011-05-13, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Admin-less mode is supported.
|
|
||||||
The OpenPGP card specification assumes existence of a security officer
|
|
||||||
(admin), who has privilege to manage the card. On the other hand,
|
|
||||||
many use cases of Gnuk are admin == user.
|
|
||||||
|
|
||||||
Thus, Gnuk now supports "admin-less" mode. In this mode, user can get
|
|
||||||
privilege with the password of PW1.
|
|
||||||
|
|
||||||
At the initialization of the card, Gnuk becomes compatible mode by
|
|
||||||
setting PW3. Without setting PW3, it becomes "admin-less" mode
|
|
||||||
by setting PW1.
|
|
||||||
|
|
||||||
** Important two bug fixes.
|
|
||||||
Gnuk (<= 0.11) has a bug which makes possible for attacker to change
|
|
||||||
user password to unknown state without knowing original password (when
|
|
||||||
no keys are loaded yet). No, attacker could not steal your identity
|
|
||||||
(cannot sign or decrypt), but it would be possible to disturb you.
|
|
||||||
|
|
||||||
Gnuk (<= 0.11) has a bug which makes possible for attacker to guess
|
|
||||||
admin password easily. When admin password is not set (the default
|
|
||||||
value of factory setting), failure of VERIFY doesn't increment error
|
|
||||||
counter in older versions. Observing no increment of error counter,
|
|
||||||
attacker could know that admin password is the one of factory setting.
|
|
||||||
|
|
||||||
** tool/gnuk_put_binary.py now uses pyscard.
|
|
||||||
Instead of PyUSB, it uses Python binding of PC/SC. PyUSB version is
|
|
||||||
still available as tool/gnuk_put_binary_libusb.py.
|
|
||||||
|
|
||||||
** Logo for Gnuk is updated.
|
|
||||||
|
|
||||||
** Gnuk Sticker SVG is available.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.11
|
|
||||||
|
|
||||||
Released 2011-04-15, by NIIBE Yutaka
|
|
||||||
|
|
||||||
This is bug fixes only release.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.10
|
|
||||||
|
|
||||||
Released 2011-02-10, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** The executable can be installed to multiple devices.
|
|
||||||
So far, users of Gnuk should have not shared single executable among
|
|
||||||
multiple devices because the executable includes random bits (or
|
|
||||||
fixed serial number). Now, random_bits and fixed serial number are
|
|
||||||
configured *after* compilation, we can install single executable image
|
|
||||||
to multiple devices. Note that we need to configure random_bits for
|
|
||||||
each device.
|
|
||||||
|
|
||||||
** Removed configure option: --with-fixed-serial
|
|
||||||
It is not compile time option any more. After installation, we can
|
|
||||||
modify serial number in AID by tool/gnuk_put_binary.py. Modification
|
|
||||||
is possible only once. If you don't modify, Gnuk uses unique chip ID
|
|
||||||
of STM32 processor for AID.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.9
|
|
||||||
|
|
||||||
Released 2011-02-01, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Card Holder Certificate is supported (still this is experimental).
|
|
||||||
Gnuk can support card holder certificate now. Note that GnuPG is not
|
|
||||||
ready yet. The tool/gnuk_update_binary.py is for writing card holder
|
|
||||||
certificate to Gnuk Token.
|
|
||||||
|
|
||||||
** Better interoperability to OpenSC.
|
|
||||||
Gnuk is not yet supported by OpenSC, but it could be. With the
|
|
||||||
changes in Gnuk, it could be relatively easily possible to support
|
|
||||||
Gnuk Token by OpenSC with a few changes to libopensc/card-openpgp.c,
|
|
||||||
and libopensc/pkcs15-openpgp.c.
|
|
||||||
|
|
||||||
** New board support "STBee"
|
|
||||||
STBee is a board by Strawberry Linux Co., Ltd., and it has
|
|
||||||
STM32F103VET6 on the board. The chip is High Density CPU with 512KB
|
|
||||||
flash memory and many I/O. If you want to connect sensor, display,
|
|
||||||
etc., this board would be a good candidate.
|
|
||||||
|
|
||||||
** Experimental PIN-pad modification(unblock) support is added.
|
|
||||||
PIN-pad modification(unblock) is supported.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.8
|
|
||||||
|
|
||||||
Released 2011-01-19, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Experimental PIN-pad modification support is added.
|
|
||||||
PIN input using rotally encoder and push switch is tested with STBee
|
|
||||||
Mini. By this hardware, PIN-pad modification is supported.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.7
|
|
||||||
|
|
||||||
Released 2011-01-15, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Bug fix only.
|
|
||||||
In version 0.6, a severe bug was introduced in usb-icc.c when adding a
|
|
||||||
work around for libccid 1.3.11. The fix is one-liner, but it is worth
|
|
||||||
to release newer version.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.6
|
|
||||||
|
|
||||||
Released 2011-01-14, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Experimental PIN-pad support is added.
|
|
||||||
Local PIN-pad input is suppored for boards which have input hardware.
|
|
||||||
PIN input using consumer IR receive module is tested with STBee Mini
|
|
||||||
and STM8S Discovery.
|
|
||||||
|
|
||||||
** USB device serial number is virtually unique now.
|
|
||||||
STM32F103 has 96-bit unique chip identifier. We take advantage of
|
|
||||||
this, Gnuk Token has virtually unique USB serial number.
|
|
||||||
|
|
||||||
** Card serial number is determined at run time by chip identifier.
|
|
||||||
Until version 0.5, card serial number was compile time option. If we
|
|
||||||
used same binary for different devices, card serial number was same.
|
|
||||||
Now, we use STM32F103's 96-bit unique chip identifier for card serial
|
|
||||||
number (when you don't use --with-fixed-serial option).
|
|
||||||
|
|
||||||
** More improved USB-CCID/ICCD implementation.
|
|
||||||
The changes in 0.5 was not that good for libccid 1.3.11, which has
|
|
||||||
small buffer (only 262-byte APDU). Workaround for libccid 1.3.11 is
|
|
||||||
implemented.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.5
|
|
||||||
|
|
||||||
Released 2010-12-13, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** LED blink
|
|
||||||
LED blink now shows status output of the card. It shows the status of
|
|
||||||
CHV3, CHV2, and CHV1 when GPG is accessing the card.
|
|
||||||
|
|
||||||
** New board support "STM8S Discovery"
|
|
||||||
ST-Link part (with STM32F103C8T6) of STM8S Discovery board is now supported.
|
|
||||||
|
|
||||||
** Digital signing for SHA224/SHA256/SHA384/SHA512 digestInfo is now possible.
|
|
||||||
|
|
||||||
** Fixes for password management
|
|
||||||
Now, you can allow the token to do digital signing multiple times with
|
|
||||||
single authentication. You can use "forcesig" subcommand in card-edit
|
|
||||||
of GnuPG to enable the feature.
|
|
||||||
|
|
||||||
** Key management changes
|
|
||||||
If you remove all keys, it is possible to import keys again.
|
|
||||||
|
|
||||||
** More improved USB-CCID/ICCD implementation.
|
|
||||||
Gnuk works better with GPG's in-stock protocol stack. You can do
|
|
||||||
digital signing (not decryption, key import, or get_public_key in
|
|
||||||
GPG2). For decryption, key import and get_public_key, changes are
|
|
||||||
needed for GPG (scd/ccid-driver.c) to support the case of extended
|
|
||||||
APDU. In short, you can sign with Gnuk by GPG.
|
|
||||||
|
|
||||||
** Windows support.
|
|
||||||
Gnuk Token could run with GPG4WIN on MS Windows. GPG4WIN runs with
|
|
||||||
"usbccid" driver and "winscard" driver.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.4
|
|
||||||
|
|
||||||
Released 2010-11-09, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** New board support "STBee Mini".
|
|
||||||
|
|
||||||
** Flash writing tool for "DfuSe" is included now.
|
|
||||||
|
|
||||||
** Since Flash GC is now implemented, it can be used longer.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.3
|
|
||||||
|
|
||||||
Released 2010-10-23, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Now we have 'configure' script to select target.
|
|
||||||
|
|
||||||
** Support system with DFU (Device Firmware Upgrade) downloader.
|
|
||||||
|
|
||||||
** New board support "CQ STARM".
|
|
||||||
|
|
||||||
** Improved USB-ICCD implementation. Works fine with GPG's protocol stack.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.2
|
|
||||||
|
|
||||||
Released 2010-09-13, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** With DEBUG=1, timeout is more than 3 seconds.
|
|
||||||
|
|
||||||
** Flash ROM entries for random numbers are cleared after use.
|
|
||||||
|
|
||||||
** Board support "STM32 Primer 2" now works.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.1
|
|
||||||
|
|
||||||
Released 2010-09-10, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Enabled force_chv1 (in the pw_status_bytes), so that the decipher works.
|
|
||||||
|
|
||||||
** Support both of key for digital signing and key for decryption.
|
|
||||||
|
|
||||||
** Decipher is supported.
|
|
||||||
|
|
||||||
** New board support "STM32 Primer 2" is added by Kaz Kojima.
|
|
||||||
|
|
||||||
** LED behavior is meaningful now. "ON" during execution.
|
|
||||||
|
|
||||||
** Fixed bcdCCID revision number.
|
|
||||||
|
|
||||||
** Logo.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Gnuk 0.0
|
|
||||||
|
|
||||||
Released 2010-09-06, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** This is initial release. Only it supports digital signing.
|
|
||||||
|
|
||||||
Local Variables:
|
|
||||||
mode: outline
|
|
||||||
End:
|
|
638
gnuk/README
638
gnuk/README
@ -1,638 +0,0 @@
|
|||||||
Gnuk - An Implementation of USB Cryptographic Token for GnuPG
|
|
||||||
|
|
||||||
Version 1.2.6
|
|
||||||
2017-10-11
|
|
||||||
Niibe Yutaka
|
|
||||||
Free Software Initiative of Japan
|
|
||||||
|
|
||||||
Release Notes
|
|
||||||
=============
|
|
||||||
|
|
||||||
This is the release of Gnuk, version 1.2.6, which has major
|
|
||||||
incompatible changes to Gnuk 1.0.x. Specifically, it now supports
|
|
||||||
overriding key import, but importing keys (or generating keys) results
|
|
||||||
password reset. Also, you need to import private keys before changing
|
|
||||||
your password. Please update your documentation for Gnuk Token, so
|
|
||||||
that the instruction of importing keys won't cause any confusion.
|
|
||||||
|
|
||||||
It has supports of EdDSA, ECDSA (with NIST P256 and secp256k1), and
|
|
||||||
ECDH (with X25519, NIST P256 and secp256k1), but this ECC feature is
|
|
||||||
somehow experimental, and it requires modern GnuPG 2.2 with libgcrypt
|
|
||||||
1.7.0 or later.
|
|
||||||
|
|
||||||
It also supports RSA-4096, but users should know that it takes more
|
|
||||||
than 8 seconds to sign/decrypt. Key generation of RSA-4096 just fails,
|
|
||||||
because the device doesn't have enough memory.
|
|
||||||
|
|
||||||
With this release, you can test how Gnuk Token works on GNU/Linux,
|
|
||||||
without real hardware, by USBIP emulation (--target=GNU_LINUX).
|
|
||||||
Please note that this emulation is intended only for testing. When
|
|
||||||
Gnuk does crypto computation on host, it is vulnerable by side channel
|
|
||||||
attacks.
|
|
||||||
|
|
||||||
|
|
||||||
What's Gnuk?
|
|
||||||
============
|
|
||||||
|
|
||||||
Gnuk is an implementation of USB cryptographic token for GNU Privacy
|
|
||||||
Guard. Gnuk supports OpenPGP card protocol version 3, and it runs on
|
|
||||||
STM32F103 processor.
|
|
||||||
|
|
||||||
I wish that Gnuk will be a developer's soother who uses GnuPG. I have
|
|
||||||
been nervous of storing secret key(s) on usual secondary storage.
|
|
||||||
There is a solution with OpenPGP card, but it is not the choice for
|
|
||||||
me, as card reader is not common device. With Gnuk, this issue will
|
|
||||||
be solved by a USB token.
|
|
||||||
|
|
||||||
Please look at the graphics of "gnuk.svg" for the software name. My
|
|
||||||
son used to be with his NUK(R), always, everywhere. Now, I am with a
|
|
||||||
USB Cryptographic Token by "Gnuk", always, everywhere.
|
|
||||||
|
|
||||||
|
|
||||||
FAQ
|
|
||||||
===
|
|
||||||
|
|
||||||
Q0: How Gnuk USB Token is superior than other solutions (OpenPGP
|
|
||||||
card 2.0, YubiKey, etc.) ?
|
|
||||||
https://www.g10code.de/p-card.html
|
|
||||||
https://www.yubico.com/
|
|
||||||
A0: Good points of Gnuk are:
|
|
||||||
* If you have skill of electronics and like DIY, you can build
|
|
||||||
Gnuk Token cheaper (see Q8-A8).
|
|
||||||
* You can study Gnuk to modify and to enhance. For example, you
|
|
||||||
can implement your own authentication method with some sensor
|
|
||||||
such as an acceleration sensor.
|
|
||||||
* It is "of Free Software"; Gnuk is distributed under GPLv3+,
|
|
||||||
"by Free Software"; Gnuk development requires only Free Software
|
|
||||||
(GNU Toolchain, Python, etc.),
|
|
||||||
"for Free Software"; Gnuk supports GnuPG.
|
|
||||||
|
|
||||||
Q1: What kind of key algorithm is supported?
|
|
||||||
A1: Gnuk version 1.0 only supports RSA-2048.
|
|
||||||
Gnuk version 1.2.x supports 255-bit EdDSA, as well as RSA-4096.
|
|
||||||
(Note that it takes long time to sign with RSA-4096.)
|
|
||||||
|
|
||||||
Q2: How long does it take for digital signing?
|
|
||||||
A2: It takes a second and a half or so for RSA-2048.
|
|
||||||
It takes more than 8 secondd for RSA-4096.
|
|
||||||
|
|
||||||
Q3: What's your recommendation for target board?
|
|
||||||
A3: Orthodox choice is Olimex STM32-H103.
|
|
||||||
FST-01 (Flying Stone Tiny 01) is available for sale, and it is a
|
|
||||||
kind of the best choice, hopefully.
|
|
||||||
If you have a skill of electronics, STM32 Nucleo F103 is the best
|
|
||||||
choice for experiment.
|
|
||||||
|
|
||||||
Q4: What's version of GnuPG are you using?
|
|
||||||
A4: In Debian GNU/Linux system, I use GnuPG modern 2.1.18 in
|
|
||||||
unstable.
|
|
||||||
|
|
||||||
Q5: What's version of pcscd and libccid are you using?
|
|
||||||
A5: I don't use them, pcscd and libccid are optional, you can use Gnuk
|
|
||||||
Token without them.
|
|
||||||
I tested pcscd 1.5.5-4 and libccid 1.3.11-2 which were in Debian
|
|
||||||
squeeze.
|
|
||||||
|
|
||||||
Q6: What kinds of hardware is required for development?
|
|
||||||
A6: You need a target board plus a JTAG/SWD debugger. If you just
|
|
||||||
want to test Gnuk for target boards with DfuSe, JTAG debugger is
|
|
||||||
not the requirement. Note that for real use, you need JTAG/SWD
|
|
||||||
debugger to enable flash ROM protection.
|
|
||||||
|
|
||||||
Q7: How much does it cost?
|
|
||||||
A7: Olimex STM32-H103 plus ARM-USB-TINY-H cost 70 Euro or so.
|
|
||||||
|
|
||||||
Q8: How much does it cost for DIY version?
|
|
||||||
A8: STM32 Nucleo F103 costs about $10 USD.
|
|
||||||
|
|
||||||
Q9: I got an error like "gpg: selecting openpgp failed: ec=6.108", what's up?
|
|
||||||
A9: Older GnuPG's SCDaemon has problems for handling insertion/removal of
|
|
||||||
card/reader. When your newly inserted token is not found by
|
|
||||||
GnuPG, try killing scdaemon and let it to be invoked again. I do:
|
|
||||||
|
|
||||||
$ gpg-connect-agent "SCD KILLSCD" "SCD BYE" /bye
|
|
||||||
|
|
||||||
and confirm scdaemon doesn't exist, then,
|
|
||||||
|
|
||||||
$ gpg-connect-agent learn /bye
|
|
||||||
|
|
||||||
Qa: With GNOME 2, I can't use Gnuk Token for SSH. How can we use it for SSH?
|
|
||||||
Aa: You need to deactivate seahorse-agent and gnome-keyring, but use
|
|
||||||
gpg-agant for the role of ssh-agent. For gnome-keyring please do:
|
|
||||||
|
|
||||||
$ gconftool-2 --type bool --set /apps/gnome-keyring/daemon-components/ssh false
|
|
||||||
|
|
||||||
Qb: With GNOME 3.0, I can't use Gnuk Token at all. Why?
|
|
||||||
Ab: That's because gnome-keyring-daemon interferes GnuPG. Type:
|
|
||||||
|
|
||||||
$ gnome-session-properties
|
|
||||||
|
|
||||||
and at the tab of "Startup Programs", disable check buttons for
|
|
||||||
"GPG Password Agent" and "SSH Key Agent".
|
|
||||||
|
|
||||||
Qc: With GNOME 3.x (x >= 8?), I can't use Gnuk Token at all. Why?
|
|
||||||
Ac: That's because gnome-keyring-daemon interferes GnuPG. Please
|
|
||||||
disable the invocation of gnome-keyring-daemon. In Debian
|
|
||||||
wheezy, it's in the files /etc/xdg/autostart/gnome-keyring-ssh.desktop
|
|
||||||
and /etc/xdg/autostart/gnome-keyring-gpg.desktop.
|
|
||||||
We have a line something like:
|
|
||||||
|
|
||||||
OnlyShowIn=GNOME;Unity;MATE;
|
|
||||||
|
|
||||||
Please edit this line to:
|
|
||||||
|
|
||||||
OnlyShowIn=
|
|
||||||
|
|
||||||
Qd: Do you know a good SWD debugger to connect FST-01 or something?
|
|
||||||
Ad: ST-Link/V2 is cheap one. We have a tool/stlinkv2.py as flash ROM
|
|
||||||
writer program. STM32 Nucleo F103 comes with the valiant of
|
|
||||||
ST-Link/V2. However, the firmware of ST-Link/V2 is proprietary.
|
|
||||||
Now, I develop BBG-SWD, SWD debugger by BeagleBone Green.
|
|
||||||
|
|
||||||
|
|
||||||
Tested features
|
|
||||||
===============
|
|
||||||
|
|
||||||
Gnuk is tested by test suite. Please see the test directory.
|
|
||||||
|
|
||||||
* Personalization of the card
|
|
||||||
* Changing Login name, URL, Name, Sex, Language, etc.
|
|
||||||
* Password handling (PW1, RC, PW3)
|
|
||||||
* Key import for three types:
|
|
||||||
* key for digital signing
|
|
||||||
* key for decryption
|
|
||||||
* key for authentication
|
|
||||||
* PSO: Digital Signature
|
|
||||||
* PSO: Decipher
|
|
||||||
* INTERNAL AUTHENTICATE
|
|
||||||
* Changing value of password status bytes (0x00C4): forcesig
|
|
||||||
* Verify with pin pad
|
|
||||||
* Modify with pin pad
|
|
||||||
* Card holder certificate (read)
|
|
||||||
* Removal of keys
|
|
||||||
* Key generation on device side for RSA-2048
|
|
||||||
* Overriding key import
|
|
||||||
|
|
||||||
Original features of Gnuk, tested manually lightly:
|
|
||||||
|
|
||||||
* OpenPGP card serial number setup
|
|
||||||
* Card holder certificate (write by UPDATE BINARY)
|
|
||||||
* Upgrading with "EXTERNAL AUTHENTICATE" by reGNUal
|
|
||||||
|
|
||||||
It is known not-working well:
|
|
||||||
|
|
||||||
* It is known that the specific combination of libccid 1.4.1
|
|
||||||
(or newer) with libusb 1.0.8 (or older) had a minor problem.
|
|
||||||
It is rare but it is possible for USB communication to be
|
|
||||||
failed, because of a bug in libusb implementation. Use
|
|
||||||
libusbx 1.0.9 or newer, or don't use PC/SC, but use internal
|
|
||||||
CCID driver of GnuPG.
|
|
||||||
|
|
||||||
|
|
||||||
Targets
|
|
||||||
=======
|
|
||||||
|
|
||||||
We use Olimex STM32-H103 board and Flying Stone Tiny 01 (FST-01).
|
|
||||||
|
|
||||||
With DfuSe support, STBee is also our targets. But this target with
|
|
||||||
DfuSe is for experiment only, because it is impossible for DfuSe to
|
|
||||||
disable read from flash. For real use, please consider killing DfuSe
|
|
||||||
and enabling read protection using JTAG debugger.
|
|
||||||
|
|
||||||
For experimental PIN-pad support, I connect a consumer IR receive
|
|
||||||
module to FST-01, and use controller for TV. PIN verification is
|
|
||||||
supported by this configuration. Yes, it is not secure at all, since
|
|
||||||
it is very easy to monitor IR output of the controllers. It is just
|
|
||||||
an experiment. Note that hardware needed for this experiment is only
|
|
||||||
a consumer IR receive module which is as cheap as 50 JPY.
|
|
||||||
|
|
||||||
Note that you need pinpad support for GnuPG to use PIN-pad enabled
|
|
||||||
Gnuk. The pinpad support for GnuPG is only available in version 2.
|
|
||||||
|
|
||||||
|
|
||||||
Build system and Host system
|
|
||||||
============================
|
|
||||||
|
|
||||||
Makefile is written for GNU make. You need Bash 4.x for configure.
|
|
||||||
|
|
||||||
If your bash is not installed as /bin/bash, you need to run configure
|
|
||||||
script prepending 'bash' before './configure'.
|
|
||||||
|
|
||||||
Some tools are written in Python. If your Python is not installed as
|
|
||||||
/usr/bin/python, please prepend 'python' for your command invocation.
|
|
||||||
Python 2.7 and PyUSB 0.4.3 is assumed.
|
|
||||||
|
|
||||||
|
|
||||||
Souce code
|
|
||||||
==========
|
|
||||||
|
|
||||||
Gnuk source code is under src/ directory.
|
|
||||||
|
|
||||||
Note that SHA-2 hash function implementation, src/sha256.c, is based
|
|
||||||
on the original implementation by Dr. Brian Gladman. See:
|
|
||||||
|
|
||||||
http://brg.a2hosted.com//oldsite/cryptography_technology/sha/index.php
|
|
||||||
(was at:
|
|
||||||
http://gladman.plushost.co.uk/oldsite/cryptography_technology/sha/index.php)
|
|
||||||
|
|
||||||
|
|
||||||
License
|
|
||||||
=======
|
|
||||||
|
|
||||||
It is distributed under GNU General Public Licence version 3 or later
|
|
||||||
(GPLv3+). Please see src/COPYING.
|
|
||||||
|
|
||||||
Please note that it is distributed with external source code too.
|
|
||||||
Please read relevant licenses for external source code as well.
|
|
||||||
|
|
||||||
The author(s) of Gnuk expect users of Gnuk will be able to access the
|
|
||||||
source code of Gnuk, so that users can study the code and can modify
|
|
||||||
if needed. This doesn't mean person who has a Gnuk Token should be
|
|
||||||
able to access everything on the Token, regardless of its protections.
|
|
||||||
Private keys, and other information should be protected properly.
|
|
||||||
|
|
||||||
|
|
||||||
External source code
|
|
||||||
====================
|
|
||||||
|
|
||||||
Gnuk is distributed with external source code.
|
|
||||||
|
|
||||||
* chopstx/ -- Chopstx 1.5
|
|
||||||
|
|
||||||
We use Chopstx as the kernel for Gnuk.
|
|
||||||
|
|
||||||
Chopstx is distributed under GPLv3+ (with a special exception).
|
|
||||||
|
|
||||||
|
|
||||||
* polarssl/ -- based on PolarSSL 1.2.10 (now mbedTLS)
|
|
||||||
|
|
||||||
Souce code taken from: http://polarssl.org/
|
|
||||||
|
|
||||||
We use PolarSSL for RSA computation, and AES encryption/decryption.
|
|
||||||
|
|
||||||
PolarSSL is distributed under GPLv2+. We use PolarSSL under GPLv3
|
|
||||||
as our options.
|
|
||||||
|
|
||||||
The file include/polarssl/bn_mul.h is heavily modified for ARM
|
|
||||||
Cortex-M3.
|
|
||||||
|
|
||||||
The function rsa_private in polarssl/library/rsa.c is modified so
|
|
||||||
that it doesn't check T against N. The function rsa_pkcs1_sign is
|
|
||||||
modified to avoid warnings in case of !POLARSSL_PKCS1_V21.
|
|
||||||
|
|
||||||
The functions rsa_pkcs1_verify and rsa_rsassa_pkcs1_v15_verify in
|
|
||||||
include/polarssl/rsa.h and polarssl/library/rsa.c are modified
|
|
||||||
(fixed) for last argument SIG, as the memory at SIG aren't modified
|
|
||||||
by those routines.
|
|
||||||
|
|
||||||
The constant POLARSSL_MPI_MAX_SIZE in include/polarssl/bignum.h is
|
|
||||||
modified for 2048-bit keys only Gnuk.
|
|
||||||
|
|
||||||
The function mpi_mul_hlp in library/bignum.c is modified for more
|
|
||||||
optimization for ARM Cortex-M3. Functions mpi_montred, mpi_sub_hlp,
|
|
||||||
mpi_sub_abs, mpi_mul_mpi, mpi_montmul, and mpi_exp_mod are modified
|
|
||||||
to avoid side channel attacks. Note that we don't use RSA-blinding
|
|
||||||
technique for Gnuk. Function mpi_gen_prime and mpi_is_prime are
|
|
||||||
modified to use Fouque-Tibouchi method. Function mpi_exp_mod is
|
|
||||||
modified to use new function mpi_montsqr for speed up.
|
|
||||||
|
|
||||||
The file library/aes.c is modified so that some constants can
|
|
||||||
go to .sys section.
|
|
||||||
|
|
||||||
The file include/polarssl/config.h are modified not to define
|
|
||||||
POLARSSL_HAVE_LONGLONG to avoid linking libgcc, to define
|
|
||||||
POLARSSL_AES_ROM_TABLES to have AES tables, not to define
|
|
||||||
POLARSSL_CIPHER_MODE_CTR, POLARSSL_FS_IO, POLARSSL_PKCS1_V21,
|
|
||||||
POLARSSL_SELF_TEST, and POLARSSL_PADLOCK_C, and only define
|
|
||||||
POLARSSL_GENPRIME when defined KEYGEN_SUPPORT.
|
|
||||||
|
|
||||||
And polarssl/library/bignum.c is modified to work on 64-bit machine.
|
|
||||||
|
|
||||||
Aurelien Jarno also modified:
|
|
||||||
|
|
||||||
polarssl/include/polarssl/bn_mul.h
|
|
||||||
polarssl/library/bignum.c
|
|
||||||
|
|
||||||
See ChangeLog (and/or history of git) for detail.
|
|
||||||
|
|
||||||
|
|
||||||
USB vendor ID and product ID (USB device ID)
|
|
||||||
============================================
|
|
||||||
|
|
||||||
When you have a vendor ID and assign a product ID for Gnuk, edit the
|
|
||||||
file GNUK_USB_DEVICE_ID and add an entry for yours. In this case,
|
|
||||||
please contact Niibe, so that it is listed to the file in the official
|
|
||||||
release of the source code.
|
|
||||||
|
|
||||||
When you are modifing Gnuk and installing the binary to device, you
|
|
||||||
should replace the vendor string and serial number to yours (in the
|
|
||||||
file GNUK_USB_DEVICE_ID and SERIALNO of the script of src/configure),
|
|
||||||
so that users can see it's not by original vendor, and it is modified
|
|
||||||
version.
|
|
||||||
|
|
||||||
FSIJ allows you to use USB device ID of FSIJ (234b:0000) for devices
|
|
||||||
with Gnuk under one of following conditions:
|
|
||||||
|
|
||||||
* For everyone for experimental purpose:
|
|
||||||
|
|
||||||
- You must not distribute a binary with FSIJ's USB device ID, but
|
|
||||||
must use the binary by yourself only for your experiment. Note
|
|
||||||
that "Distributing binary" includes distributing a device which
|
|
||||||
holds the binary.
|
|
||||||
|
|
||||||
* For general individuals:
|
|
||||||
|
|
||||||
- You must use your Gnuk device with a card serial number which is
|
|
||||||
*not* by FSIJ. Easy one would be a card serial number generated
|
|
||||||
by chip unique ID.
|
|
||||||
|
|
||||||
* For individuals with explicit permission from FSIJ.
|
|
||||||
|
|
||||||
- You should have an assigned card serial number by FSIJ,
|
|
||||||
please use that number for your device.
|
|
||||||
(There a file 'GNUK_SERIAL_NUMBER' in the official release.)
|
|
||||||
|
|
||||||
FSIJ could give companies or business entities "second source
|
|
||||||
manufacturer" license to use USB device ID of FSIJ for devices with
|
|
||||||
unmodified version of Gnuk, provided they support Free Software and
|
|
||||||
respect users' freedom for computing. Please ask FSIJ for the
|
|
||||||
license.
|
|
||||||
|
|
||||||
Otherwise, companies which want to distribute Gnuk devices, please use
|
|
||||||
your own USB vendor ID and product ID. Please replace vendor string
|
|
||||||
and possibly product string to yours, when you modify Gnuk.
|
|
||||||
|
|
||||||
|
|
||||||
Host Requirements
|
|
||||||
=================
|
|
||||||
|
|
||||||
For GNU/Linux, PC/SC service is an option, you can use GnuPG's
|
|
||||||
internal CCID driver instead. If you chose using PC/SC service,
|
|
||||||
libccid version >= 1.3.11 is recommended for GNU/Linux.
|
|
||||||
|
|
||||||
|
|
||||||
How to compile
|
|
||||||
==============
|
|
||||||
|
|
||||||
You need GNU toolchain and newlib for 'arm-none-eabi' target.
|
|
||||||
|
|
||||||
On Debian we can install the packages of gcc-arm-none-eabi,
|
|
||||||
gdb-arm-none-eabi and its friends. I'm using:
|
|
||||||
|
|
||||||
binutils-arm-none-eabi 2.28-4+9+b3
|
|
||||||
gcc-arm-none-eabi 15:5.4.1+svn241155-1
|
|
||||||
gdb-arm-none-eabi 7.12-6+9+b2
|
|
||||||
libnewlib-arm-none-eabi 2.4.0.20160527-2
|
|
||||||
|
|
||||||
Or else, see https://launchpad.net/gcc-arm-embedded for preparation of
|
|
||||||
GNU Toolchain for 'arm-none-eabi' target.
|
|
||||||
|
|
||||||
Change directory to `src':
|
|
||||||
|
|
||||||
$ cd gnuk-VERSION/src
|
|
||||||
|
|
||||||
Then, run `configure':
|
|
||||||
|
|
||||||
$ ./configure --vidpid=<VID:PID>
|
|
||||||
|
|
||||||
Here, you need to specify USB vendor ID and product ID. For FSIJ's,
|
|
||||||
it's: --vidpid=234b:0000 . Please read section 'USB vendor ID and
|
|
||||||
product ID' above.
|
|
||||||
|
|
||||||
|
|
||||||
Then, type:
|
|
||||||
|
|
||||||
$ make
|
|
||||||
|
|
||||||
Then, we will have "gnuk.elf" under src/build directory.
|
|
||||||
|
|
||||||
|
|
||||||
How to install
|
|
||||||
==============
|
|
||||||
|
|
||||||
Olimex STM32-H103 board
|
|
||||||
-----------------------
|
|
||||||
|
|
||||||
If you are using Olimex JTAG-Tiny, type following to invoke OpenOCD
|
|
||||||
and write "gnuk.elf" to Flash ROM:
|
|
||||||
|
|
||||||
$ openocd -f interface/ftdi/olimex-jtag-tiny.cfg \
|
|
||||||
-f board/olimex_stm32_h103.cfg \
|
|
||||||
-c "program build/gnuk.elf verify reset exit"
|
|
||||||
|
|
||||||
Command invocation is assumed in src/ directory.
|
|
||||||
|
|
||||||
|
|
||||||
Flying Stone Tiny 01
|
|
||||||
--------------------
|
|
||||||
|
|
||||||
If you are using Flying Stone Tiny 01, you need a SWD writer.
|
|
||||||
|
|
||||||
OpenOCD 0.9.0 now supports ST-Link/V2. We can use it like:
|
|
||||||
|
|
||||||
$ openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg \
|
|
||||||
-c "program build/gnuk.elf verify reset exit"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
STBee
|
|
||||||
-----
|
|
||||||
|
|
||||||
Reset the board with "USER" switch pushed. Type following to write
|
|
||||||
to flash:
|
|
||||||
|
|
||||||
# cd ../tool
|
|
||||||
# ./dfuse.py ../src/build/gnuk.hex
|
|
||||||
|
|
||||||
Then, reset the board.
|
|
||||||
|
|
||||||
|
|
||||||
How to protect flash ROM
|
|
||||||
========================
|
|
||||||
|
|
||||||
To protect, invoke OpenOCD like (for FST-01):
|
|
||||||
|
|
||||||
$ openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg \
|
|
||||||
-c init -c "reset halt" -c "stm32f1x lock 0" -c reset -c exit
|
|
||||||
|
|
||||||
After power-off / power-on sequence, the contents of flash ROM cannot
|
|
||||||
be accessible from JTAG debugger.
|
|
||||||
|
|
||||||
Unprotecting is:
|
|
||||||
|
|
||||||
$ openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg \
|
|
||||||
-c init -c "reset halt" -c "stm32f1x unlock 0" -c reset -c exit
|
|
||||||
|
|
||||||
Upon unprotection, flash is erased.
|
|
||||||
|
|
||||||
Note that it would be still possible for some implementation of DfuSe
|
|
||||||
to access the contents, even if it's protected. If you really want to
|
|
||||||
protect, killing DfuSe and accessing by JTAG debugger is recommended.
|
|
||||||
|
|
||||||
|
|
||||||
(Optional) Configure serial number and X.509 certificate
|
|
||||||
========================================================
|
|
||||||
|
|
||||||
This is completely optional.
|
|
||||||
|
|
||||||
For this procedure, you need python and pyscard (python-pyscard
|
|
||||||
package in Debian) or PyUSB 0.4.3 (python-usb package in Debian).
|
|
||||||
|
|
||||||
(1) [pyscard] Stop scdaemon
|
|
||||||
[PyUSB] Stop the pcsc daemon.
|
|
||||||
|
|
||||||
If scdaemon is running, please kill it, or you will get "Smartcard
|
|
||||||
Exception" by "Sharing violation".
|
|
||||||
|
|
||||||
$ gpg-connect-agent "SCD KILLSCD" "SCD BYE" /bye
|
|
||||||
|
|
||||||
In case of PyUSB tool, you need to stop pcscd.
|
|
||||||
|
|
||||||
# /etc/init.d/pcscd stop
|
|
||||||
|
|
||||||
|
|
||||||
(2) [Optional] Write fixed serial number
|
|
||||||
|
|
||||||
If you use fixed serial number in the file 'GNUK_SERIAL_NUMBER', you can do:
|
|
||||||
|
|
||||||
$ EMAIL=<YOUR-EMAIL-ADDRESS> ../tool/gnuk_put_binary_usb.py -s ../GNUK_SERIAL_NUMBER
|
|
||||||
Writing serial number
|
|
||||||
...
|
|
||||||
|
|
||||||
(3) [Optional] Write card holder certificate
|
|
||||||
|
|
||||||
If you have card holder certificate binary file, you can do:
|
|
||||||
|
|
||||||
$ ../tool/gnuk_put_binary_usb.py ../../<YOUR-CERTIFICATE>.bin
|
|
||||||
../../<YOUR-CERTIFICATE>.bin: <LENGTH-OF-YOUR-CERTIFICATE>
|
|
||||||
Updating card holder certificate
|
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
How to run
|
|
||||||
==========
|
|
||||||
|
|
||||||
Debug enabled
|
|
||||||
-------------
|
|
||||||
|
|
||||||
If you compiled with --enable-debug option, Gnuk has two interfaces
|
|
||||||
(one is CCID/ICCD device and another is virtual COM port). Open
|
|
||||||
virtual COM port by:
|
|
||||||
|
|
||||||
$ cu -l /dev/ttyACM0
|
|
||||||
|
|
||||||
and you will see debug output of Gnuk.
|
|
||||||
|
|
||||||
|
|
||||||
Testing Gnuk
|
|
||||||
------------
|
|
||||||
|
|
||||||
Type following command to see Gnuk runs:
|
|
||||||
|
|
||||||
$ gpg --card-status
|
|
||||||
|
|
||||||
|
|
||||||
Besides, there is a functionality test under test/ directory. See
|
|
||||||
test/README.
|
|
||||||
|
|
||||||
|
|
||||||
Personalize the Token, import keys, and change the password
|
|
||||||
-----------------------------------------------------------
|
|
||||||
|
|
||||||
You can personalize the token, putting your information like: Name,
|
|
||||||
Login name, Sex, Languages, URL. To do so, GnuPG command is:
|
|
||||||
|
|
||||||
$ gpg --card-edit
|
|
||||||
|
|
||||||
Note that the factory setting of user password is "123456" and admin
|
|
||||||
password is "12345678" as the specification.
|
|
||||||
|
|
||||||
It is recommended to create your keys on your computer, and import
|
|
||||||
them to Gnuk Token. After you create your keys (they must be 2048-bit
|
|
||||||
RSA), you can import them.
|
|
||||||
|
|
||||||
Gnuk supports key generation, but this feature is young and should be
|
|
||||||
considered experimental.
|
|
||||||
|
|
||||||
For detail, please see documentation under doc/. You can see the HTML
|
|
||||||
version at: https://www.fsij.org/doc-gnuk/
|
|
||||||
|
|
||||||
|
|
||||||
How to debug
|
|
||||||
============
|
|
||||||
|
|
||||||
We can use GDB.
|
|
||||||
|
|
||||||
$ arm-none-eabi-gdb gnuk.elf
|
|
||||||
|
|
||||||
|
|
||||||
Inside GDB, we can connect OpenOCD by:
|
|
||||||
|
|
||||||
(gdb) target remote localhost:3333
|
|
||||||
|
|
||||||
or
|
|
||||||
|
|
||||||
(gdb) target extended-remote localhost:3333
|
|
||||||
|
|
||||||
|
|
||||||
You can see the output of PCSCD:
|
|
||||||
|
|
||||||
# /etc/init.d/pcscd stop
|
|
||||||
# LIBCCID_ifdLogLevel=7 /usr/sbin/pcscd --debug --foreground
|
|
||||||
|
|
||||||
|
|
||||||
You can observe the traffic of USB using "usbmon". See the file:
|
|
||||||
linux/Documentation/usb/usbmon.txt
|
|
||||||
|
|
||||||
|
|
||||||
Firmware update
|
|
||||||
===============
|
|
||||||
|
|
||||||
See doc/note/firmware-update.
|
|
||||||
|
|
||||||
|
|
||||||
Git Repositories
|
|
||||||
================
|
|
||||||
|
|
||||||
Please use: https://anonscm.debian.org/cgit/gnuk/gnuk/
|
|
||||||
|
|
||||||
You can get it by:
|
|
||||||
|
|
||||||
$ git clone git://anonscm.debian.org/gnuk/gnuk/gnuk.git
|
|
||||||
|
|
||||||
It's also available at: www.gniibe.org
|
|
||||||
You can browse at: https://git.gniibe.org/gitweb?p=gnuk/gnuk.git;a=summary
|
|
||||||
|
|
||||||
I put Chopstx as a submodule of Git. Please do this:
|
|
||||||
|
|
||||||
$ git submodule update --init
|
|
||||||
|
|
||||||
|
|
||||||
Information on the Web
|
|
||||||
======================
|
|
||||||
|
|
||||||
For more information, please visit: https://www.fsij.org/gnuk/
|
|
||||||
|
|
||||||
Please see the FST-01 support pages:
|
|
||||||
|
|
||||||
https://www.gniibe.org/category/fst-01.html
|
|
||||||
|
|
||||||
Please consider to join Gnuk-users mailing list:
|
|
||||||
|
|
||||||
https://lists.alioth.debian.org/mailman/listinfo/gnuk-users
|
|
||||||
|
|
||||||
The mailing list will be moved to lists.debian.org.
|
|
||||||
|
|
||||||
|
|
||||||
Your Contributions
|
|
||||||
==================
|
|
||||||
|
|
||||||
FSIJ welcomes your contributions. Please assign your copyright
|
|
||||||
to FSIJ (if possible), as I do.
|
|
||||||
|
|
||||||
|
|
||||||
Foot note
|
|
||||||
==========
|
|
||||||
|
|
||||||
* NUK(R) is a registered trademark owend by MAPA GmbH, Germany.
|
|
||||||
--
|
|
@ -1,6 +0,0 @@
|
|||||||
# An unofficial clone of FST Gnuk Cryptographic Token device for GnuPG
|
|
||||||
|
|
||||||
* See `README` for the original README instruction.
|
|
||||||
* Note well that the `master` branch is modified by @jj1bdx.
|
|
||||||
* For the original master branch of NeuG, see `gniibe-master` branch.
|
|
||||||
|
|
43
gnuk/THANKS
43
gnuk/THANKS
@ -1,43 +0,0 @@
|
|||||||
-*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
We would like to express our gratitudes to Werner Koch for GnuPG, and
|
|
||||||
Giovanni Di Sirio for ChibiOS/RT.
|
|
||||||
|
|
||||||
Gnuk was originally written by NIIBE Yutaka. People contributed by
|
|
||||||
encouraging the development, testing the implementation, suggesting
|
|
||||||
improvements, or fixing bugs. Here is a list of those people.
|
|
||||||
|
|
||||||
Aurelien Jarno aurelien@aurel32.net
|
|
||||||
Achim Pietig achim@pietig.com
|
|
||||||
Aidan Thornton
|
|
||||||
Anibal Monsalve Salazar anibal@debian.org
|
|
||||||
Andre Zepezauer andre.zepezauer@student.uni-halle.de
|
|
||||||
Anthony Romano anthony.romano@coreos.com
|
|
||||||
Bertrand Jacquin bertrand@jacquin.bzh
|
|
||||||
Clint Adams clint@softwarefreedom.org
|
|
||||||
Daniel Kahn Gillmor dkg@fifthhorseman.net
|
|
||||||
Elliott Mitchell
|
|
||||||
Hironobu SUZUKI hironobu@h2np.net
|
|
||||||
Jan Suhr jan@suhr.info
|
|
||||||
Jeremy Drake jeremydrake+gnuk@eacceleration.com
|
|
||||||
Jonathan McDowell noodles@earth.li
|
|
||||||
Kaz Kojima kkojima@rr.iij4u.or.jp
|
|
||||||
Kenji Rikitake
|
|
||||||
Ludovic Rousseau ludovic.rousseau@free.fr
|
|
||||||
Luis Felipe R. Murillo luisfelipe@ucla.edu
|
|
||||||
Mateusz Zalega mateusz@nitrokey.com
|
|
||||||
MATSUU Takuto matsuu@gentoo.org
|
|
||||||
Micah Anderson micah@debian.org
|
|
||||||
NAGAMI Takeshi nagami-takeshi@aist.go.jp
|
|
||||||
Nguyễn Hồng Quân quannguyen@mbm.vn
|
|
||||||
Nico Rikken nico@nicorikken.eu
|
|
||||||
NOKUBI Takatsugu knok@daionet.gr.jp
|
|
||||||
Paul Fertser
|
|
||||||
Paul Bakker polarssl_maintainer@polarssl.org
|
|
||||||
Santiago Ruano Rincón santiago@debian.org
|
|
||||||
Shane Coughlan scoughlan@openinventionnetwork.com
|
|
||||||
Stanislas Bach sbach@0g.re
|
|
||||||
Szczepan Zalega szczepan@nitrokey.com
|
|
||||||
Vasily Evseenko
|
|
||||||
Werner Koch wk@gnupg.org
|
|
||||||
Yuji Imai ug@xcast.jp
|
|
@ -1 +0,0 @@
|
|||||||
release/1.2.6
|
|
3
gnuk/chopstx/.gitignore
vendored
3
gnuk/chopstx/.gitignore
vendored
@ -1,3 +0,0 @@
|
|||||||
*/build
|
|
||||||
*/.dep
|
|
||||||
doc/chopstx.info
|
|
@ -1,15 +0,0 @@
|
|||||||
image: debian:stable
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- apt-get update && apt-get -y install texi2html
|
|
||||||
|
|
||||||
pages:
|
|
||||||
stage: deploy
|
|
||||||
script:
|
|
||||||
- mkdir -p html && (cd html && texi2html ../doc/chopstx.texi)
|
|
||||||
- mv html/ public
|
|
||||||
artifacts:
|
|
||||||
paths:
|
|
||||||
- public
|
|
||||||
only:
|
|
||||||
- master
|
|
@ -1,76 +0,0 @@
|
|||||||
Aidan Thornton:
|
|
||||||
Added Maple Mini support.
|
|
||||||
board/board-maple-mini.h
|
|
||||||
|
|
||||||
Jeremy Drake:
|
|
||||||
Modified STM32F103 support.
|
|
||||||
mcu/sys-stm32f103.c
|
|
||||||
|
|
||||||
Kaz Kojima:
|
|
||||||
Added STM32 Primer2 support.
|
|
||||||
board/board-stm32-primer2.h
|
|
||||||
example-primer2
|
|
||||||
|
|
||||||
Kenji Rikitake:
|
|
||||||
Added ST Dongle support.
|
|
||||||
board/board-st-dongle.h
|
|
||||||
Added ST Nucleo F103 support.
|
|
||||||
board/board-st-nucleo-f103.h
|
|
||||||
|
|
||||||
Kiwamu Okabe:
|
|
||||||
Wrote an OpenOCD scirpt:
|
|
||||||
example-fsm-55/stlink-v2.cfg
|
|
||||||
|
|
||||||
Mateusz Zalega:
|
|
||||||
Added Nitrokey-Start support.
|
|
||||||
board/board-nitrokey-start.h
|
|
||||||
|
|
||||||
NIIBE Yutaka:
|
|
||||||
Wrote the library:
|
|
||||||
chopstx.c, chopstx.h,
|
|
||||||
chopstx-cortex-m.c, chopstx-cortex-m.h,
|
|
||||||
chopstx-gnu-linux.c, chopstx-gnu-linux.h,
|
|
||||||
entry.c,
|
|
||||||
eventflag.c, eventflag.h
|
|
||||||
Wrote the drivers mcu/*:
|
|
||||||
chx-gnu-linux.c, chx-mkl27z.c, chx-stm32f0.c, chx-stm32f103.c,
|
|
||||||
clk_gpio_init-mkl27z.c, clk_gpio_init-stm32.c,
|
|
||||||
cortex-m.h, mkl27z.h, stm32.h, stm32f103.h,
|
|
||||||
sys-gnu-linux.c,sys-gnu-linux.h,
|
|
||||||
sys-mkl27z.c, sys-mkl27z.h,
|
|
||||||
sys-stm32f0.c, sys-stm32f0.h
|
|
||||||
sys-stm32f103.c, sys-stm32f103.h,
|
|
||||||
usb-stm32f103.c, usb-mkl27z.c
|
|
||||||
Wrote the drivers:
|
|
||||||
controb/adc-mkl27z.c
|
|
||||||
Drew the logo:
|
|
||||||
chopstx.svg, chopstx.png
|
|
||||||
Wrote examples:
|
|
||||||
example-led, example-cdc, example-fsm-55, example-fs-bb48,
|
|
||||||
example-usb-serial, example-cdc-gnu-linux
|
|
||||||
Wrote board/*:
|
|
||||||
board-fst-01sz.h,
|
|
||||||
board-fst-01g.h, board-fst-01.h, board-fst-01-00.h,
|
|
||||||
board-olimex-stm32-h103.h, board-stm8s-discovery.h
|
|
||||||
board-cq-starm.h, board-stbee-mini.h, board-stbee.h,
|
|
||||||
|
|
||||||
board-stm32f0-discovery.h, board-fsm-55.h,
|
|
||||||
|
|
||||||
board-fs-bb48.h
|
|
||||||
|
|
||||||
For Free Software Initiative of Japan, wrote:
|
|
||||||
contrib/adc-stm32f103.c,
|
|
||||||
contrib/adc-gnu-linux.c
|
|
||||||
|
|
||||||
Under contract of g10 Code GmbH, wrote:
|
|
||||||
mcu/usb-usbip.c
|
|
||||||
contrib/usart-stm32f103.c
|
|
||||||
contrib/ackbtn-stm32f103.c
|
|
||||||
|
|
||||||
Paul Fertser:
|
|
||||||
Added Blue Pill support.
|
|
||||||
board/board-blue-pill.h
|
|
||||||
|
|
||||||
Szczepan Zalega:
|
|
||||||
Modified Nitrokey-Start support.
|
|
||||||
board/board-nitrokey-start.h
|
|
@ -1,674 +0,0 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
|
||||||
software and other kinds of works.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
|
||||||
share and change all versions of a program--to make sure it remains free
|
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
|
||||||
GNU General Public License for most of our software; it applies also to
|
|
||||||
any other work released this way by its authors. You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
|
||||||
or can get the source code. And you must show them these terms so they
|
|
||||||
know their rights.
|
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
|
||||||
that there is no warranty for this free software. For both users' and
|
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
|
||||||
changed, so that their problems will not be attributed erroneously to
|
|
||||||
authors of previous versions.
|
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
|
||||||
modified versions of the software inside them, although the manufacturer
|
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
|
||||||
protecting users' freedom to change the software. The systematic
|
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
|
||||||
products. If such problems arise substantially in other domains, we
|
|
||||||
stand ready to extend this provision to those domains in future versions
|
|
||||||
of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
|
||||||
avoid the special danger that patents applied to a free program could
|
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
|
||||||
patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
0. Definitions.
|
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
|
||||||
"recipients" may be individuals or organizations.
|
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
|
||||||
earlier work or a work "based on" the earlier work.
|
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
|
||||||
to the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
1. Source Code.
|
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
|
||||||
for making modifications to it. "Object code" means any non-source
|
|
||||||
form of a work.
|
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
|
||||||
can regenerate automatically from other parts of the Corresponding
|
|
||||||
Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
|
||||||
same work.
|
|
||||||
|
|
||||||
2. Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
|
||||||
convey, without conditions so long as your license otherwise remains
|
|
||||||
in force. You may convey covered works to others for the sole purpose
|
|
||||||
of having them make modifications exclusively for you, or provide you
|
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
|
||||||
modification of the work as a means of enforcing, against the work's
|
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the special requirements of the GNU Affero General Public License,
|
|
||||||
section 13, concerning interaction through a network will apply to the
|
|
||||||
combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Program specifies that a certain numbered version of the GNU General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
|
||||||
notice like this when it starts in an interactive mode:
|
|
||||||
|
|
||||||
<program> Copyright (C) <year> <name of author>
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, your program's commands
|
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
|
||||||
<http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
|
||||||
may consider it more useful to permit linking proprietary applications with
|
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License. But first, please read
|
|
||||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
|
File diff suppressed because it is too large
Load Diff
@ -1,14 +0,0 @@
|
|||||||
For released versions of Chopstx, it is OK to distribute a binary
|
|
||||||
without the copy of the GNU GPL, as the license notice of Chopstx
|
|
||||||
include following exception to GNU GPL.
|
|
||||||
|
|
||||||
--------------------
|
|
||||||
As additional permission under GNU GPL version 3 section 7, you may
|
|
||||||
distribute non-source form of the Program without the copy of the GNU
|
|
||||||
GPL normally required by section 4, provided you inform the receipents
|
|
||||||
of GNU GPL by a written offer.
|
|
||||||
--------------------
|
|
||||||
|
|
||||||
Note that "written offer" is still needed when you distribute binary
|
|
||||||
only.
|
|
||||||
--
|
|
@ -1,455 +0,0 @@
|
|||||||
NEWS - Noteworthy changes
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 1.14
|
|
||||||
|
|
||||||
Released 2019-03-02
|
|
||||||
|
|
||||||
** Enhancement of driver: USART for STM32
|
|
||||||
Now, it supports smartcard communication.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 1.13
|
|
||||||
|
|
||||||
Released 2018-12-19
|
|
||||||
|
|
||||||
** API fix (redefinition): chopstx_poll
|
|
||||||
In old implementations, when chopstx_poll returns by non-timeout
|
|
||||||
event, *USEC_P is not updated. Now, it is updated.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 1.12
|
|
||||||
|
|
||||||
Released 2018-11-12
|
|
||||||
|
|
||||||
** Enhance API of eventflag
|
|
||||||
New function eventflag_set_mask is added, so that we can only handle
|
|
||||||
specified events. See Gnuk 1.2.12 for an example (while USB Tx is
|
|
||||||
busy, the USB thread only accepts EV_TX_FINISHED event, leaving
|
|
||||||
other events).
|
|
||||||
|
|
||||||
** Acknowledge button support for FST-01 and FST-01G
|
|
||||||
While FST-01 and FST-01G don't have any button in the original design,
|
|
||||||
it may be PA2 when user put a hall sensor or a switch.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 1.11
|
|
||||||
|
|
||||||
Released 2018-10-02
|
|
||||||
|
|
||||||
** Support calling chopstx_poll with intr->ready==1
|
|
||||||
In version <= 1.10, it assumed that all events should be handled after
|
|
||||||
chopstx_poll, before calling chopstx_poll again. With having
|
|
||||||
chopstx_intr_done, it's OK now that chopstx_poll can be called again
|
|
||||||
not examining/handling all poll descriptors, but only parts of them.
|
|
||||||
|
|
||||||
** Acknowledge button change
|
|
||||||
In 1.10, the action was able to be "memorized" by the edge detector.
|
|
||||||
Now, the edge detector is disabled by ackbtn_disable, and it is
|
|
||||||
enabled by ackbtn_enable. So, the status is cleared correctly.
|
|
||||||
|
|
||||||
** New board support: FST-01SZ
|
|
||||||
It's still under development. Programming-wise, it will be kept same.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 1.10
|
|
||||||
|
|
||||||
Released 2018-09-29
|
|
||||||
|
|
||||||
** Function chopstx_intr_wait is not deprecated, now
|
|
||||||
Once, it was said that it's deprecated, but it's active again
|
|
||||||
to match the new function of chopstx_intr_done.
|
|
||||||
|
|
||||||
** API change: chopstx_poll, chopstx_intr_wait, chopstx_intr_done
|
|
||||||
To avoid spurious interrupt, we introduce new function
|
|
||||||
chopstx_intr_done, which should be called after interrupt handling.
|
|
||||||
|
|
||||||
** New driver: Acknowledge button for FST-01SZ
|
|
||||||
The use case is waiting user's acknowledge. We use EXTI interrupt
|
|
||||||
feature of STM32.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 1.9
|
|
||||||
|
|
||||||
Released 2018-05-09
|
|
||||||
|
|
||||||
** GD32F103 support
|
|
||||||
GD32F103 is an alternative implementation of STM32F103 by Giga Device,
|
|
||||||
which can run at 96MHz.
|
|
||||||
|
|
||||||
** Minor USB driver fix for STM32F103/GD32F103
|
|
||||||
BTABLE setting should be done at initialization, not at USB RESET.
|
|
||||||
|
|
||||||
** Minor SYS driver fix for GD32F103
|
|
||||||
flash_protect should check FLASH_CR_OPTWRE.
|
|
||||||
|
|
||||||
** Minor ADC driver change for GD32F103
|
|
||||||
ADC on GD32F103 is another implementation and its behavior is somewhat
|
|
||||||
different. It requires waits after enabling. So, we use continuous
|
|
||||||
sampling, instead of start and stop for each sample. Still, we
|
|
||||||
observe enough noise (> 4.7 bit/byte) for each ADC sampling.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 1.8
|
|
||||||
|
|
||||||
Released 2018-01-19
|
|
||||||
|
|
||||||
** Minor driver API fix
|
|
||||||
In version 1.6, part of mcu/stm32f103.h was moved into mcu/cortex-m.h
|
|
||||||
and mcu/stm32.h. Now, mcu/stm32f103.h automatically includes
|
|
||||||
mcu/cortex-m.h and mcu/stm32.h, so that it doesn't break existing
|
|
||||||
applications.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 1.7
|
|
||||||
|
|
||||||
Released 2017-12-19
|
|
||||||
|
|
||||||
** Fix: timer wakeup
|
|
||||||
Timer expiration had a bug. When it is waken up, the wake up doesn't
|
|
||||||
handle as a timer expiration when there are multiple threads on same
|
|
||||||
timing of expire. It confuses as if it were forced wakeup.
|
|
||||||
|
|
||||||
** New driver: USART for STM32
|
|
||||||
USART driver for STM32 is added.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 1.6
|
|
||||||
|
|
||||||
Released 2017-11-24
|
|
||||||
|
|
||||||
** Fix cancellation
|
|
||||||
In Chopstx 1.4 and 1.5, cancellation doesn't work for real MCU. This
|
|
||||||
is due to the change of chx_sched interface, introduced for GNU/Linux
|
|
||||||
emulation. This bug is fixed.
|
|
||||||
|
|
||||||
** New feature: sleep mode
|
|
||||||
New function chopstx_conf_idle is added to support sleep. Note that
|
|
||||||
use of sleep by this feature requires careful preparation. For
|
|
||||||
example, enabling sleep, a board with no RESET pin cannot be debugged
|
|
||||||
by JTAG/SWD. Setting of DBGMCU_CR (0xE0042004) is required beforehand
|
|
||||||
(hardware default is zero).
|
|
||||||
|
|
||||||
** API change: chopstx_poll
|
|
||||||
This is a kind of clarification. The third argument is now an array
|
|
||||||
of constant pointers. We don't touch the array itself, just use it.
|
|
||||||
This allows having the array in read-only memory and can contribute
|
|
||||||
less use of RAM.
|
|
||||||
|
|
||||||
** USB API changes
|
|
||||||
INTR_REQ_USB is now defined by usb_lld.h. Enumeration type of
|
|
||||||
DEVICE_STATE now has USB_DEVICE_STATE_ prefix.
|
|
||||||
|
|
||||||
** USB driver change
|
|
||||||
USB suspend and wakeup events are supported for STM32F103.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 1.5
|
|
||||||
|
|
||||||
Released 2017-10-10
|
|
||||||
|
|
||||||
** Stack size definition by stack-def.h
|
|
||||||
Stack size of each thread was used to be defined in ldscript.
|
|
||||||
While emulation on GNU/Linux doesn't use ldscript, it is better
|
|
||||||
to put those definitions in independent header file. Please see
|
|
||||||
example-cdc/stack-def.h and example-cdc/sample.ld.
|
|
||||||
|
|
||||||
** More support for emulation on GNU/Linux
|
|
||||||
We have SYS driver for emulation on GNU/Linux. It has flash ROM
|
|
||||||
emulation.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 1.4
|
|
||||||
|
|
||||||
Released 2017-08-11
|
|
||||||
|
|
||||||
** New port: Emulation on GNU/Linux
|
|
||||||
Now, user can run Chopstx application on GNU/Linux. Its USB driver is
|
|
||||||
by USBIP. Its ADC driver is dummy with random(3).
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 1.3
|
|
||||||
|
|
||||||
Released 2017-02-02
|
|
||||||
|
|
||||||
** New board support: Blue Pill
|
|
||||||
It is contributed by Paul Fertser.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 1.2
|
|
||||||
|
|
||||||
Released 2016-10-13
|
|
||||||
|
|
||||||
** Fix: chopstx_join
|
|
||||||
chopstx_join is now cancellation point.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 1.1
|
|
||||||
|
|
||||||
Released 2016-07-01
|
|
||||||
|
|
||||||
** API change: chopstx_poll
|
|
||||||
In version 1.0, chopstx_poll has variable arguments. It found that
|
|
||||||
it's challenging for ffi or lower level C implementation, if C
|
|
||||||
compiler is new for the specific MCU target. Another example is that
|
|
||||||
a program touches FPU registers for varargs, even if no argument is
|
|
||||||
float. So, we decided to avoid use of varargs in Chopstx.
|
|
||||||
|
|
||||||
** API change: chopstx_setpriority
|
|
||||||
In version 1.0, chopstx_setpriority does not return value. It is
|
|
||||||
changed to return old value of the priority.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 1.0
|
|
||||||
|
|
||||||
Released 2016-06-16
|
|
||||||
|
|
||||||
** New USB API
|
|
||||||
Now, USB driver is included in Chopstx. So, it should be good one.
|
|
||||||
It used to be the code which was derived from interrupt driven API
|
|
||||||
with callbacks. It's changed to event driven API, so that a user can
|
|
||||||
do as wish, beyond the restriction of callbacks.
|
|
||||||
|
|
||||||
** New board support: FST-01G
|
|
||||||
FST-01G is a new revision of original FST-01 with fixed pull-up of
|
|
||||||
D+ line.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 0.12
|
|
||||||
|
|
||||||
Released 2016-05-31
|
|
||||||
|
|
||||||
** Provide drivers of SYS, USB and ADC
|
|
||||||
Those were only offered as examples, but now, Chopstx provides drivers
|
|
||||||
of SYS, USB, and ADC. Please note that the ADC driver is not for
|
|
||||||
general use (it's specific to NeuG to get noise). To use them, enable
|
|
||||||
variables in Makefile, like following.
|
|
||||||
------------
|
|
||||||
CHIP=stm32f103
|
|
||||||
USE_ADC = yes
|
|
||||||
USE_USB = yes
|
|
||||||
USE_SYS = yes
|
|
||||||
DEFS = -DUSE_SYS3
|
|
||||||
------------
|
|
||||||
|
|
||||||
** Removal of chopstx_usec_wait_var chopstx_wakeup_usec_wait
|
|
||||||
This API was used when we need to wait something with timeout.
|
|
||||||
Now, we have better API with chopstx_poll. Please use chopstx_poll
|
|
||||||
and chopstx_cond_signal.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 0.11
|
|
||||||
|
|
||||||
Released 2016-05-19
|
|
||||||
|
|
||||||
** New feature: polling
|
|
||||||
New function chopstx_poll is added to watch multiple condition
|
|
||||||
variables, threads' exit, or IRQ, simultaneously with timeout.
|
|
||||||
|
|
||||||
** Change API of eventflag
|
|
||||||
The initialization function eventflag_init only has an argument of EV.
|
|
||||||
An eventflag can be waited with timeout or can be waited with no
|
|
||||||
timeout, as caller like. It is not determined at initialization time
|
|
||||||
now. Besides, the eventflag can be waited by any threads. Functions
|
|
||||||
to poll eventflag together with other events (cond, join, and IRQ) are
|
|
||||||
provided.
|
|
||||||
|
|
||||||
** Removal of the function chopstx_release_irq
|
|
||||||
IRQ is enabled only when a thread is blocked in polling. When it (the
|
|
||||||
thread in polling) is canceled, IRQ is disabled.
|
|
||||||
|
|
||||||
** Removal of the function chopstx_main_init
|
|
||||||
It is removed because it's too special. Please use
|
|
||||||
chopstx_setpriority instead.
|
|
||||||
|
|
||||||
** New function: chopstx_setpriority
|
|
||||||
This function is not recommended in general. It is only added to
|
|
||||||
support the usage when main thread wants to change the schedule
|
|
||||||
priority after creating other threads.
|
|
||||||
|
|
||||||
** Function chopstx_intr_wait is deprecated
|
|
||||||
Use of chopstx_poll is recommended.
|
|
||||||
|
|
||||||
** FS-BB48: Kinetis L MCU
|
|
||||||
Support for FS-BB48 board with Kinetis L MCU is added.
|
|
||||||
|
|
||||||
** No HardFault at context switch on Cortex-M0
|
|
||||||
By its design, Chopstx does context switch holding the scheduler lock.
|
|
||||||
This is implemented with the feature of BASEPRI on Cortex-M3. Because
|
|
||||||
Cortex-M0 doesn't have support of BASEPRI, the context switch (before
|
|
||||||
version 0.11) always caused HardFault exception. Since Cortex-M0
|
|
||||||
doesn't have complex exception mechism of ICI/IT (which is supported
|
|
||||||
on Cortex-M3), it is actually possible to implement the context switch
|
|
||||||
in user mode. This is done.
|
|
||||||
|
|
||||||
** New sys.c (3.0)
|
|
||||||
Don't touch NVIC in usb_lld_sys_init.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 0.10
|
|
||||||
|
|
||||||
Released 2015-09-15
|
|
||||||
|
|
||||||
** Thread cancellation bug fix
|
|
||||||
Thread cancellation didn't work well with 0.09 because
|
|
||||||
of initial configuration mistake. It's fixed.
|
|
||||||
|
|
||||||
** Interrupt handler bug fix
|
|
||||||
Interrupt handler wasn't unregistered on exit well.
|
|
||||||
It's fixed.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 0.09
|
|
||||||
|
|
||||||
Released 2015-09-10
|
|
||||||
|
|
||||||
** New board support: Nitrokey-Start
|
|
||||||
It is contributed by Mateusz Zalega.
|
|
||||||
|
|
||||||
** Thread cancellation
|
|
||||||
Add new API: chopstx_setcancelstate.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 0.08
|
|
||||||
|
|
||||||
Released 2015-07-31
|
|
||||||
|
|
||||||
** New board support: ST Nucleo F103
|
|
||||||
It is contributed by Kenji Rikitake.
|
|
||||||
|
|
||||||
** New board support: ST Dongle
|
|
||||||
It is contributed by Kenji Rikitake.
|
|
||||||
It's the ST-Link/V2-1 part of ST Nucleo F103.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 0.07
|
|
||||||
|
|
||||||
Released 2015-07-15
|
|
||||||
|
|
||||||
** New Board macro definitions
|
|
||||||
Each board-*.h should have BOARD_ID and BOARD_NAME now.
|
|
||||||
FLASH_PAGE_SIZE and NEUG_ADC_SETTING2_* are deprecated.
|
|
||||||
|
|
||||||
** New sys.c (2.1)
|
|
||||||
Flash memory size is probed at runtime now. System
|
|
||||||
service flash pages now include sys_board_id and sys_board_name.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 0.06
|
|
||||||
|
|
||||||
Released 2015-07-08
|
|
||||||
|
|
||||||
** New file: clk_gpio_init.c
|
|
||||||
To avoid duplication of code, clock and GPIO initialization code
|
|
||||||
is now in this file.
|
|
||||||
|
|
||||||
** New board support: STM32 Primer2
|
|
||||||
It is contributed by Kaz Kojima.
|
|
||||||
|
|
||||||
** New board support: CQ STARM
|
|
||||||
The old board which was "published" by CQ Publishing in 2008 is added.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 0.05
|
|
||||||
|
|
||||||
Released 2015-04-20, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** New function: chopstx_main_init
|
|
||||||
chopstx_main_init is the function to change the schedule priority of
|
|
||||||
main thread. This is useful to enter main loop after initialization
|
|
||||||
of other threads.
|
|
||||||
|
|
||||||
** The use of CHX_PRIO_MAIN
|
|
||||||
CHX_PRIO_MAIN is deprecated. Instead, please use the function
|
|
||||||
chopstx_main_init.
|
|
||||||
|
|
||||||
** Cortex-M0 support
|
|
||||||
Cortex-M0 support has been added.
|
|
||||||
|
|
||||||
** New board support: Maple mini
|
|
||||||
It is contributed by Aidan Thornton.
|
|
||||||
|
|
||||||
** New board support: FSM-55 and STM32F0 Discovery
|
|
||||||
Those boards with STM32F0 (Cortex-M0) are now supported.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 0.04
|
|
||||||
|
|
||||||
Released 2014-12-10, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** new board.h macros and sys.c in example
|
|
||||||
In board.h, RCC_APB2ENR_IOP_EN was renamed to RCC_ENR_IOP_EN and
|
|
||||||
RCC_APB2RSTR_IOP_RST was renamed to RCC_RSTR_IOP_RST. Example sys.c
|
|
||||||
was changed accordingly.
|
|
||||||
|
|
||||||
** Bug fix of chopstx_wakeup_usec_wait
|
|
||||||
chopstx_usec_wait_var/chopstx_usec_wait won't be woken up
|
|
||||||
by chopstx_wakeup_usec_wait. This is now fixed in 0.04.
|
|
||||||
|
|
||||||
** Board support STBee and STBee Mini
|
|
||||||
The board STBee and STBee Mini are now supported.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 0.03
|
|
||||||
|
|
||||||
Released 2013-11-08, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Bug fix of preemption
|
|
||||||
In the implementation of preemption, there was a bug which might cause
|
|
||||||
not to schedule proper thread. This is because the routine preepmt
|
|
||||||
itself might be interrupted. This is now fixed in 0.03.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 0.02
|
|
||||||
|
|
||||||
Released 2013-11-08, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Bug fix of priority
|
|
||||||
There was a severe bug about the configuraion of priority setting of
|
|
||||||
exceptions. As we don't use any inter-lock between interrupts hander
|
|
||||||
and timer expiration handler, these priorities should be equal. If
|
|
||||||
not, timer expiration handler might interrupt the execution of
|
|
||||||
interrupts handers.
|
|
||||||
|
|
||||||
|
|
||||||
* Major changes in Chopstx 0.01
|
|
||||||
|
|
||||||
Released 2013-11-03, by NIIBE Yutaka
|
|
||||||
|
|
||||||
** Interrupt handling change
|
|
||||||
There was a bug in 0.00, which caused spurious interrupts. Every
|
|
||||||
interrupt event caused two events. Specifically, after valid
|
|
||||||
interrupt event (for the caller of chopstx_intr_wait), another
|
|
||||||
spurious event was always occurred. This was fixed.
|
|
||||||
|
|
||||||
In the design of Chopstx, interrupt handling is done by a thread.
|
|
||||||
Lower level interrupt handler just accepts interrupt, disabling the
|
|
||||||
interrupt, and switchs the control to the thread. It is the thread to
|
|
||||||
check the cause of interrupt, to process it, and to clear the cause.
|
|
||||||
Next call to chopstx_intr_wait will enable the interrupt again.
|
|
||||||
|
|
||||||
The bug was related to pending interrupt flag. Pending interrupt flag
|
|
||||||
for a specific interrupt is set, on return from handler mode if the
|
|
||||||
cause is still active. With traditional interrupt handling, lower
|
|
||||||
level interrupt handler processes it and clears the cause. Thus,
|
|
||||||
pending interrupt flag is not set on return.
|
|
||||||
|
|
||||||
In Chopstx, pending interrupt flag was always set, because the control
|
|
||||||
goes from lower level interrupt handler (in handler mode) to a
|
|
||||||
interrupt handling thread which processes the interrupt. In 0.01, new
|
|
||||||
internal routine chx_clr_intr is introduced, and pending interrupt
|
|
||||||
flag is cleared within chopstx_intr_wait after waked up.
|
|
||||||
|
|
||||||
For detail of interrupt operation, see the section B.3.4, Nested
|
|
||||||
Vectored Interrupt Controller (NVIC), in the ARM v7-M Architecture
|
|
||||||
Reference Manual. The subsection, B3.4.1, Theory of operation,
|
|
||||||
explains how it works.
|
|
||||||
|
|
||||||
** gpio_init change
|
|
||||||
Now, gpi_init support AFIO mapping and another GPIO (GPIO_OTHER)
|
|
||||||
settings.
|
|
||||||
|
|
||||||
|
|
||||||
# Local Variables:
|
|
||||||
# mode: outline
|
|
||||||
# End:
|
|
@ -1,70 +0,0 @@
|
|||||||
Chopstx - Threads and only Threads
|
|
||||||
Version 1.14
|
|
||||||
2018-03-02
|
|
||||||
Niibe Yutaka
|
|
||||||
Flying Stone Technology
|
|
||||||
|
|
||||||
What's Chopstx?
|
|
||||||
===============
|
|
||||||
|
|
||||||
Chopstx is an RT thread library for STM32F103 and GD32F103 (ARM
|
|
||||||
Cortex-M3), STM32F030 (ARM Cortex-M0), MKL27Z (ARM Cortex-M0plus), and
|
|
||||||
emulation on GNU/Linux.
|
|
||||||
|
|
||||||
While most RTOSes come with many features, drivers, and protocol
|
|
||||||
stacks, Chopstx just offers a simple RT thread library.
|
|
||||||
|
|
||||||
With Chopstx, interrupt handling is also done by a thread. This
|
|
||||||
enables coherent code for ease of maintenance.
|
|
||||||
|
|
||||||
While threads are important, we don't need more threads than
|
|
||||||
necessary. Chopstx provides a feature of poll, so that we can
|
|
||||||
minimize use of threads.
|
|
||||||
|
|
||||||
|
|
||||||
Note that this library is _not_ related to the hand game:
|
|
||||||
|
|
||||||
https://en.wikipedia.org/wiki/Chopsticks_(hand_game)
|
|
||||||
|
|
||||||
Thanks to Yao Wei and Enrico Zini for giving me an opportunity
|
|
||||||
visiting the wiki page above, when my children were playing the game.
|
|
||||||
|
|
||||||
|
|
||||||
License
|
|
||||||
=======
|
|
||||||
|
|
||||||
It is distributed under GNU General Public Licence version 3 or later
|
|
||||||
(GPLv3+), with additional permission. Please see COPYING and
|
|
||||||
EXCEPTION.
|
|
||||||
|
|
||||||
|
|
||||||
Example code
|
|
||||||
============
|
|
||||||
|
|
||||||
We have some examples in this distribution; Useful ones are LED
|
|
||||||
blinker and USB CDC-ACM device. For STM32F103, you can build it USB
|
|
||||||
CDC-ACM demo by:
|
|
||||||
|
|
||||||
$ cd example-cdc
|
|
||||||
$ ln -sf ../board/board-olimex-stm32-h103.h board.h
|
|
||||||
$ make
|
|
||||||
|
|
||||||
If you want to try GD32F103, Add -DMHZ=96 to DEFS in Makefile.
|
|
||||||
|
|
||||||
For a specific board named FSM-55, an example of LED matrix dynamic
|
|
||||||
driver is provided. See the directory: example-fsm-55.
|
|
||||||
|
|
||||||
For STM32 Primer2, see the directory: example-primer2.
|
|
||||||
|
|
||||||
|
|
||||||
Future Works
|
|
||||||
============
|
|
||||||
|
|
||||||
Convenience function to determine the bottom of thread stack,
|
|
||||||
configuration of thread size by compiler's output would be next things
|
|
||||||
to be done.
|
|
||||||
|
|
||||||
Experimental SMP port for Cortex-A7 is under development. For SMP,
|
|
||||||
more careful considerations for shared access to objects of struct
|
|
||||||
chx_pq is needed. So, modifications required will not be small.
|
|
||||||
--
|
|
@ -1 +0,0 @@
|
|||||||
release/1.14
|
|
@ -1,8 +0,0 @@
|
|||||||
int adc_init (void);
|
|
||||||
void adc_start (void);
|
|
||||||
void adc_stop (void);
|
|
||||||
|
|
||||||
extern uint32_t adc_buf[64];
|
|
||||||
|
|
||||||
void adc_start_conversion (int offset, int count);
|
|
||||||
int adc_wait_completion (void);
|
|
@ -1,42 +0,0 @@
|
|||||||
#define BOARD_NAME "Blue Pill GD32F103"
|
|
||||||
/* http://wiki.stm32duino.com/index.php?title=Blue_Pill */
|
|
||||||
/* echo -n "Blue Pill GD32F103" | shasum -a 256 | sed -e 's/^.*\(........\) -$/\1/' */
|
|
||||||
#define BOARD_ID 0xed415594
|
|
||||||
|
|
||||||
#define MCU_STM32F1_GD32F1 1
|
|
||||||
#define STM32_USBPRE STM32_USBPRE_DIV2
|
|
||||||
#define STM32_ADCPRE STM32_ADCPRE_DIV8
|
|
||||||
|
|
||||||
#define MCU_STM32F1 1
|
|
||||||
#define STM32F10X_MD /* Medium-density device */
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 12
|
|
||||||
#define STM32_HSECLK 8000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOC_BASE
|
|
||||||
#define GPIO_LED_CLEAR_TO_EMIT 13
|
|
||||||
#define GPIO_USB_BASE GPIOA_BASE
|
|
||||||
#undef GPIO_OTHER_BASE
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM)
|
|
||||||
* PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP)
|
|
||||||
*
|
|
||||||
* Port C setup.
|
|
||||||
* PC13 - Push pull output 50MHz (LED 1:ON 0:OFF)
|
|
||||||
* ------------------------ Default
|
|
||||||
* PAx - input with pull-up
|
|
||||||
* PCx - input with pull-up
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_USB_ODR 0xFFFFE7FF
|
|
||||||
#define VAL_GPIO_USB_CRL 0x88888888 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_USB_CRH 0x88811888 /* PA15...PA8 */
|
|
||||||
|
|
||||||
#define VAL_GPIO_LED_ODR 0xFFFFFFFF
|
|
||||||
#define VAL_GPIO_LED_CRL 0x88888888 /* PC7...PC0 */
|
|
||||||
#define VAL_GPIO_LED_CRH 0x88388888 /* PC15...PC8 */
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN (RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPCEN)
|
|
||||||
#define RCC_RSTR_IOP_RST (RCC_APB2RSTR_IOPARST | RCC_APB2RSTR_IOPCRST)
|
|
@ -1,38 +0,0 @@
|
|||||||
#define BOARD_NAME "Blue Pill"
|
|
||||||
/* http://wiki.stm32duino.com/index.php?title=Blue_Pill */
|
|
||||||
/* echo -n "Blue Pill" | shasum -a 256 | sed -e 's/^.*\(........\) -$/\1/' */
|
|
||||||
#define BOARD_ID 0xa1099d43
|
|
||||||
|
|
||||||
#define MCU_STM32F1 1
|
|
||||||
#define STM32F10X_MD /* Medium-density device */
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 9
|
|
||||||
#define STM32_HSECLK 8000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOC_BASE
|
|
||||||
#define GPIO_LED_CLEAR_TO_EMIT 13
|
|
||||||
#define GPIO_USB_BASE GPIOA_BASE
|
|
||||||
#undef GPIO_OTHER_BASE
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM)
|
|
||||||
* PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP)
|
|
||||||
*
|
|
||||||
* Port C setup.
|
|
||||||
* PC13 - Push pull output 50MHz (LED 1:ON 0:OFF)
|
|
||||||
* ------------------------ Default
|
|
||||||
* PAx - input with pull-up
|
|
||||||
* PCx - input with pull-up
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_USB_ODR 0xFFFFE7FF
|
|
||||||
#define VAL_GPIO_USB_CRL 0x88888888 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_USB_CRH 0x88811888 /* PA15...PA8 */
|
|
||||||
|
|
||||||
#define VAL_GPIO_LED_ODR 0xFFFFFFFF
|
|
||||||
#define VAL_GPIO_LED_CRL 0x88888888 /* PC7...PC0 */
|
|
||||||
#define VAL_GPIO_LED_CRH 0x88388888 /* PC15...PC8 */
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN (RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPCEN)
|
|
||||||
#define RCC_RSTR_IOP_RST (RCC_APB2RSTR_IOPARST | RCC_APB2RSTR_IOPCRST)
|
|
@ -1,47 +0,0 @@
|
|||||||
#define BOARD_NAME "CQ STARM"
|
|
||||||
#define BOARD_ID 0xc5480875
|
|
||||||
|
|
||||||
#define MCU_STM32F1 1
|
|
||||||
#define STM32F10X_MD /* Medium-density device */
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 9
|
|
||||||
#define STM32_HSECLK 8000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOC_BASE
|
|
||||||
#define GPIO_LED_SET_TO_EMIT 6
|
|
||||||
#undef GPIO_USB_BASE /* No external DISCONNECT/RENUM circuit. */
|
|
||||||
#define GPIO_OTHER_BASE GPIOA_BASE
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA0 - input with pull-up. AN0
|
|
||||||
* PA1 - input with pull-up. AN1
|
|
||||||
* PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM)
|
|
||||||
* PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP)
|
|
||||||
* ------------------------ Default
|
|
||||||
* PAx - input with pull-up
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_OTHER_ODR 0xFFFFE7FF
|
|
||||||
#define VAL_GPIO_OTHER_CRL 0x88888888 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_OTHER_CRH 0x88811888 /* PA15...PA8 */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port C setup.
|
|
||||||
* PC0 - Push Pull output 50MHz.
|
|
||||||
* PC1 - Push Pull output 50MHz.
|
|
||||||
* Everything input with pull-up except:
|
|
||||||
* PC4 - Normal input (ADC_IN14 : VoutY of LIS344ALH).
|
|
||||||
* PC5 - Normal input (ADC_IN15 : VoutZ of LIS344ALH).
|
|
||||||
* PC6 - Push Pull output (LED).
|
|
||||||
* (PC9 - SDCard CD)
|
|
||||||
* (PC12 - SDCard CS)
|
|
||||||
* PC14 - Normal input (XTAL).
|
|
||||||
* PC15 - Normal input (XTAL).
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_LED_CRL 0x83448833 /* PC7...PC0 */
|
|
||||||
#define VAL_GPIO_LED_CRH 0x44888888 /* PC15...PC8 */
|
|
||||||
#define VAL_GPIO_LED_ODR 0xFFFFFFFF
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN (RCC_APB2ENR_IOPAEN|RCC_APB2ENR_IOPCEN)
|
|
||||||
#define RCC_RSTR_IOP_RST (RCC_APB2RSTR_IOPARST|RCC_APB2RSTR_IOPCRST)
|
|
@ -1,5 +0,0 @@
|
|||||||
#define BOARD_NAME "FS-BB48"
|
|
||||||
#define BOARD_ID 0xd1f5119c
|
|
||||||
/* echo -n "FST-01" | sha256sum | sed -e 's/^.*\(........\) -$/\1/' */
|
|
||||||
|
|
||||||
#define MCU_KINETIS_L 1
|
|
@ -1,42 +0,0 @@
|
|||||||
#define BOARD_NAME "FSM-55"
|
|
||||||
#define BOARD_ID 0x83433c76
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Running at 48MHz with HSI as clock source.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#define MCU_STM32F0 1
|
|
||||||
/* __ARM_ARCH_6M__ */
|
|
||||||
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 12
|
|
||||||
#define STM32_HSICLK 8000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOA_BASE
|
|
||||||
#define GPIO_LED_SET_TO_EMIT 5
|
|
||||||
#define GPIO_OTHER_BASE GPIOF_BASE /* USER BUTTON */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA5 - ON (LED 1:ON 0:OFF)
|
|
||||||
* PA4 - Pull DOWN
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_LED_MODER 0x00145555 /* Output Pin0-7, Pin9 and Pin10 */
|
|
||||||
#define VAL_GPIO_LED_OTYPER 0x0000001f /* Open-drain for Pin0-4, Push-Pull*/
|
|
||||||
#define VAL_GPIO_LED_OSPEEDR 0x003cffff /* High speed */
|
|
||||||
#define VAL_GPIO_LED_PUPDR 0x00000000 /* No pull-up/pull-down */
|
|
||||||
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN (RCC_AHBENR_IOPAEN | RCC_AHBENR_IOPFEN)
|
|
||||||
#define RCC_RSTR_IOP_RST (RCC_AHBRSTR_IOPARST | RCC_AHBRSTR_IOPFRST)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port F setup.
|
|
||||||
* PF0 - USER Button
|
|
||||||
* PF1 - SPEAKER
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_OTHER_MODER 0x00000004 /* Input Pin0, Output Pin1 */
|
|
||||||
#define VAL_GPIO_OTHER_OTYPER 0x00000000 /* Push-Pull Pin1 */
|
|
||||||
#define VAL_GPIO_OTHER_OSPEEDR 0x00000000
|
|
||||||
#define VAL_GPIO_OTHER_PUPDR 0x00000009 /* Pull-up Pin0, Pull-down Pin1 */
|
|
@ -1,33 +0,0 @@
|
|||||||
#define BOARD_NAME "FST-01-00"
|
|
||||||
#define BOARD_ID 0x613870a9
|
|
||||||
|
|
||||||
#define MCU_STM32F1 1
|
|
||||||
#define STM32F10X_MD /* Medium-density device */
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 9
|
|
||||||
#define STM32_HSECLK 8000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOA_BASE
|
|
||||||
#define GPIO_LED_SET_TO_EMIT 8
|
|
||||||
#define GPIO_USB_BASE GPIOA_BASE
|
|
||||||
#define GPIO_USB_SET_TO_ENABLE 10
|
|
||||||
#undef GPIO_OTHER_BASE
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA0 - input with pull-up. AN0
|
|
||||||
* PA1 - input with pull-up. AN1
|
|
||||||
* PA8 - Push pull output 50MHz (LED 1:ON 0:OFF)
|
|
||||||
* PA10 - Push pull output 50MHz (USB 1:ON 0:OFF)
|
|
||||||
* PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM)
|
|
||||||
* PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP)
|
|
||||||
* ------------------------ Default
|
|
||||||
* PAx - input with pull-up
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_LED_ODR 0xFFFFE7FF
|
|
||||||
#define VAL_GPIO_LED_CRL 0x88888888 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_LED_CRH 0x88811383 /* PA15...PA8 */
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN RCC_APB2ENR_IOPAEN
|
|
||||||
#define RCC_RSTR_IOP_RST RCC_APB2RSTR_IOPARST
|
|
@ -1,87 +0,0 @@
|
|||||||
#define BOARD_NAME "FST-01"
|
|
||||||
#define BOARD_ID 0x696886af
|
|
||||||
/* echo -n "FST-01" | sha256sum | sed -e 's/^.*\(........\) -$/\1/' */
|
|
||||||
|
|
||||||
#define MCU_STM32F1 1
|
|
||||||
#define STM32F10X_MD /* Medium-density device */
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 6
|
|
||||||
#define STM32_HSECLK 12000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOB_BASE
|
|
||||||
#define GPIO_LED_SET_TO_EMIT 0
|
|
||||||
#define GPIO_USB_BASE GPIOA_BASE
|
|
||||||
#define GPIO_USB_SET_TO_ENABLE 10
|
|
||||||
#undef GPIO_OTHER_BASE
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA0 - input with pull-up (TIM2_CH1): AN0 for NeuG
|
|
||||||
* PA1 - input with pull-down (TIM2_CH2)
|
|
||||||
* PA2 - input with pull-up (TIM2_CH3) connected to CIR module
|
|
||||||
* PA3 - input with pull-up: external pin available to user
|
|
||||||
* PA4 - Push pull output (SPI1_NSS)
|
|
||||||
* PA5 - Alternate Push pull output (SPI1_SCK)
|
|
||||||
* PA6 - Alternate Push pull output (SPI1_MISO)
|
|
||||||
* PA7 - Alternate Push pull output (SPI1_MOSI)
|
|
||||||
* PA10 - Push pull output (USB 1:ON 0:OFF)
|
|
||||||
* PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM)
|
|
||||||
* PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP)
|
|
||||||
* ------------------------ Default
|
|
||||||
* PA8 - input with pull-up.
|
|
||||||
* PA9 - input with pull-up.
|
|
||||||
* PA13 - input with pull-up.
|
|
||||||
* PA14 - input with pull-up.
|
|
||||||
* PA15 - input with pull-up.
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_USB_ODR 0xFFFFE7FD
|
|
||||||
#define VAL_GPIO_USB_CRL 0xBBB38888 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_USB_CRH 0x88811388 /* PA15...PA8 */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port B setup.
|
|
||||||
* PB0 - Push pull output (LED 1:ON 0:OFF)
|
|
||||||
* PB1 - input with pull-up: AN9 for NeuG
|
|
||||||
* ------------------------ Default
|
|
||||||
* PBx - input with pull-up.
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_LED_ODR 0xFFFFFFFF
|
|
||||||
#define VAL_GPIO_LED_CRL 0x88888883 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_LED_CRH 0x88888888 /* PA15...PA8 */
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN (RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN)
|
|
||||||
#define RCC_RSTR_IOP_RST (RCC_APB2RSTR_IOPARST | RCC_APB2RSTR_IOPBRST)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Board specific information other than clock and GPIO initial
|
|
||||||
* setting should not be in board-*.h, but each driver should include
|
|
||||||
* information by itself.
|
|
||||||
*
|
|
||||||
* Please see NeuG's ADC driver how board specific handling is done.
|
|
||||||
*
|
|
||||||
* Given the situation of Chopstx's boards support, which is not that
|
|
||||||
* huge, this works well. If scalability and flexibility will matter,
|
|
||||||
* we will need something like device tree in which boot process can
|
|
||||||
* pass information to application program.
|
|
||||||
*
|
|
||||||
* Following constants are here, because experimental CIR driver is
|
|
||||||
* written before this design decision of Chopstx.
|
|
||||||
*
|
|
||||||
* Those will be removed soon, once such an driver will be improved
|
|
||||||
* in new style.
|
|
||||||
*/
|
|
||||||
#if defined(PINPAD_CIR_SUPPORT)
|
|
||||||
/* For pin-cir settings of Gnuk */
|
|
||||||
#define TIMx TIM2
|
|
||||||
#define INTR_REQ_TIM TIM2_IRQ
|
|
||||||
#define AFIO_EXTICR_INDEX 0
|
|
||||||
#define AFIO_EXTICR1_EXTIx_Py AFIO_EXTICR1_EXTI2_PA
|
|
||||||
#define EXTI_PR EXTI_PR_PR2
|
|
||||||
#define EXTI_IMR EXTI_IMR_MR2
|
|
||||||
#define EXTI_FTSR_TR EXTI_FTSR_TR2
|
|
||||||
#define INTR_REQ_EXTI EXTI2_IRQ
|
|
||||||
#define ENABLE_RCC_APB1
|
|
||||||
#define RCC_APBnENR_TIMxEN RCC_APB1ENR_TIM2EN
|
|
||||||
#define RCC_APBnRSTR_TIMxRST RCC_APB1RSTR_TIM2RST
|
|
||||||
#endif
|
|
@ -1,86 +0,0 @@
|
|||||||
#define BOARD_NAME "FST-01G"
|
|
||||||
#define BOARD_ID 0x8801277f
|
|
||||||
/* echo -n "FST-01G" | sha256sum | sed -e 's/^.*\(........\) -$/\1/' */
|
|
||||||
|
|
||||||
#define MCU_STM32F1 1
|
|
||||||
#define STM32F10X_MD /* Medium-density device */
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 6
|
|
||||||
#define STM32_HSECLK 12000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOB_BASE
|
|
||||||
#define GPIO_LED_SET_TO_EMIT 0
|
|
||||||
#define GPIO_USB_BASE GPIOA_BASE
|
|
||||||
#undef GPIO_OTHER_BASE
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA0 - input with pull-up (TIM2_CH1): AN0 for NeuG
|
|
||||||
* PA1 - input with pull-down (TIM2_CH2)
|
|
||||||
* PA2 - input with pull-up (TIM2_CH3) connected to CIR module
|
|
||||||
* PA3 - input with pull-up: external pin available to user
|
|
||||||
* PA4 - Push pull output (SPI1_NSS)
|
|
||||||
* PA5 - Alternate Push pull output (SPI1_SCK)
|
|
||||||
* PA6 - Alternate Push pull output (SPI1_MISO)
|
|
||||||
* PA7 - Alternate Push pull output (SPI1_MOSI)
|
|
||||||
* PA10 - Push pull output 1 default
|
|
||||||
* (so that binary for FST-01G also works on FST-01)
|
|
||||||
* PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM)
|
|
||||||
* PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP)
|
|
||||||
* ------------------------ Default
|
|
||||||
* PA8 - input with pull-up.
|
|
||||||
* PA9 - input with pull-up.
|
|
||||||
* PA13 - input with pull-up.
|
|
||||||
* PA14 - input with pull-up.
|
|
||||||
* PA15 - input with pull-up.
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_USB_ODR 0xFFFFE7FD
|
|
||||||
#define VAL_GPIO_USB_CRL 0xBBB38888 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_USB_CRH 0x88811388 /* PA15...PA8 */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port B setup.
|
|
||||||
* PB0 - Push pull output (LED 1:ON 0:OFF)
|
|
||||||
* PB1 - input with pull-up: AN9 for NeuG
|
|
||||||
* ------------------------ Default
|
|
||||||
* PBx - input with pull-up.
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_LED_ODR 0xFFFFFFFF
|
|
||||||
#define VAL_GPIO_LED_CRL 0x88888883 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_LED_CRH 0x88888888 /* PA15...PA8 */
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN (RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN)
|
|
||||||
#define RCC_RSTR_IOP_RST (RCC_APB2RSTR_IOPARST | RCC_APB2RSTR_IOPBRST)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Board specific information other than clock and GPIO initial
|
|
||||||
* setting should not be in board-*.h, but each driver should include
|
|
||||||
* information by itself.
|
|
||||||
*
|
|
||||||
* Please see NeuG's ADC driver how board specific handling is done.
|
|
||||||
*
|
|
||||||
* Given the situation of Chopstx's boards support, which is not that
|
|
||||||
* huge, this works well. If scalability and flexibility will matter,
|
|
||||||
* we will need something like device tree in which boot process can
|
|
||||||
* pass information to application program.
|
|
||||||
*
|
|
||||||
* Following constants are here, because experimental CIR driver is
|
|
||||||
* written before this design decision of Chopstx.
|
|
||||||
*
|
|
||||||
* Those will be removed soon, once such an driver will be improved
|
|
||||||
* in new style.
|
|
||||||
*/
|
|
||||||
#if defined(PINPAD_CIR_SUPPORT)
|
|
||||||
#define TIMx TIM2
|
|
||||||
#define INTR_REQ_TIM TIM2_IRQ
|
|
||||||
#define AFIO_EXTICR_INDEX 0
|
|
||||||
#define AFIO_EXTICR1_EXTIx_Py AFIO_EXTICR1_EXTI2_PA
|
|
||||||
#define EXTI_PR EXTI_PR_PR2
|
|
||||||
#define EXTI_IMR EXTI_IMR_MR2
|
|
||||||
#define EXTI_FTSR_TR EXTI_FTSR_TR2
|
|
||||||
#define INTR_REQ_EXTI EXTI2_IRQ
|
|
||||||
#define ENABLE_RCC_APB1
|
|
||||||
#define RCC_APBnENR_TIMxEN RCC_APB1ENR_TIM2EN
|
|
||||||
#define RCC_APBnRSTR_TIMxRST RCC_APB1RSTR_TIM2RST
|
|
||||||
#endif
|
|
@ -1,43 +0,0 @@
|
|||||||
#define BOARD_NAME "FST-01SZ"
|
|
||||||
#define BOARD_ID 0x7e6fb084
|
|
||||||
/* echo -n "FST-01SZ" | sha256sum | sed -e 's/^.*\(........\) -$/\1/' */
|
|
||||||
|
|
||||||
#define MCU_STM32F1_GD32F1 1
|
|
||||||
#define STM32_USBPRE STM32_USBPRE_DIV2
|
|
||||||
#define STM32_ADCPRE STM32_ADCPRE_DIV8
|
|
||||||
|
|
||||||
#define MCU_STM32F1 1
|
|
||||||
#define STM32F10X_MD /* Medium-density device */
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 8
|
|
||||||
#define STM32_HSECLK 12000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOA_BASE
|
|
||||||
#define GPIO_LED_SET_TO_EMIT 8
|
|
||||||
#define GPIO_USB_BASE GPIOA_BASE
|
|
||||||
#undef GPIO_OTHER_BASE
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA0 - input with pull-up: AN0 for NeuG
|
|
||||||
* PA1 - input with pull-up: AN1 for NeuG
|
|
||||||
* PA3 - input with pull-up: Hall effect sensor output
|
|
||||||
* PA8 - Push pull output 10MHz 0 default (LED 1:ON 0:OFF)
|
|
||||||
* PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM)
|
|
||||||
* PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP)
|
|
||||||
* ------------------------ Default
|
|
||||||
* PAx - input with pull-up.
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_LED_ODR 0xFFFFE6FF
|
|
||||||
#define VAL_GPIO_LED_CRL 0x88888888 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_LED_CRH 0x88811881 /* PA15...PA8 */
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN RCC_APB2ENR_IOPAEN
|
|
||||||
#define RCC_RSTR_IOP_RST RCC_APB2RSTR_IOPARST
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Board specific information other than clock and GPIO initial
|
|
||||||
* setting should not be in board-*.h, but each driver should include
|
|
||||||
* such specific information by itself.
|
|
||||||
*/
|
|
@ -1,4 +0,0 @@
|
|||||||
#define BOARD_NAME "GNU/Linux"
|
|
||||||
/* Emulation on GNU/Linux */
|
|
||||||
/* echo -n "GNU/Linux" | shasum -a 256 | sed -e 's/^.*\(........\) -$/\1/' */
|
|
||||||
#define BOARD_ID 0x7ec86145
|
|
@ -1,42 +0,0 @@
|
|||||||
#define BOARD_NAME "Maple Mini"
|
|
||||||
#define BOARD_ID 0x7a445272
|
|
||||||
|
|
||||||
#define MCU_STM32F1 1
|
|
||||||
#define STM32F10X_MD /* Medium-density device */
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 9
|
|
||||||
#define STM32_HSECLK 8000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOB_BASE
|
|
||||||
#define GPIO_LED_SET_TO_EMIT 1
|
|
||||||
#define GPIO_USB_BASE GPIOB_BASE
|
|
||||||
#define GPIO_USB_CLEAR_TO_ENABLE 9
|
|
||||||
#define GPIO_OTHER_BASE GPIOA_BASE
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA0 - input with pull-up. AN0
|
|
||||||
* PA1 - input with pull-up. AN1
|
|
||||||
* PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM)
|
|
||||||
* PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP)
|
|
||||||
* ------------------------ Default
|
|
||||||
* PAx - input with pull-up
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_OTHER_ODR 0xFFFFE7FF
|
|
||||||
#define VAL_GPIO_OTHER_CRL 0x88888888 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_OTHER_CRH 0x88811888 /* PA15...PA8 */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port B setup.
|
|
||||||
* PB1 - Push pull output 50MHz (LED 1:ON 0:OFF)
|
|
||||||
* PB9 - Push pull output 50MHz (USB 1:ON 0:OFF)
|
|
||||||
* ------------------------ Default
|
|
||||||
* PBx - input with pull-up
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_LED_ODR 0xFFFFFFFF
|
|
||||||
#define VAL_GPIO_LED_CRL 0x88888838 /* PB7...PB0 */
|
|
||||||
#define VAL_GPIO_LED_CRH 0x88888838 /* PB15...PB8 */
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN (RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN)
|
|
||||||
#define RCC_RSTR_IOP_RST (RCC_APB2RSTR_IOPARST | RCC_APB2RSTR_IOPBRST)
|
|
@ -1,60 +0,0 @@
|
|||||||
#define BOARD_NAME "NITROKEY-START"
|
|
||||||
#define BOARD_ID 0xad1e7ebd
|
|
||||||
|
|
||||||
#define MCU_STM32F1 1
|
|
||||||
#define STM32F10X_MD /* Medium-density device */
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 6
|
|
||||||
#define STM32_HSECLK 12000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOB_BASE
|
|
||||||
#define GPIO_LED_SET_TO_EMIT 0
|
|
||||||
#define GPIO_USB_BASE GPIOA_BASE
|
|
||||||
#define GPIO_USB_SET_TO_ENABLE 15
|
|
||||||
#undef GPIO_OTHER_BASE
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA0 - input with pull-up: AN0 for NeuG
|
|
||||||
* PA1 - input with pull-up: AN1 for NeuG
|
|
||||||
* PA2 - floating input
|
|
||||||
* PA3 - floating input
|
|
||||||
* PA4 - floating input
|
|
||||||
* PA5 - floating input
|
|
||||||
* PA6 - floating input
|
|
||||||
* PA7 - Push pull output (Red LED1 1:ON 0:OFF)
|
|
||||||
* PA8 - floating input (smartcard, SCDSA)
|
|
||||||
* PA9 - floating input
|
|
||||||
* PA10 - floating input
|
|
||||||
* PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM)
|
|
||||||
* PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP)
|
|
||||||
* PA15 - Push pull output (USB_EN 1:ON 0:OFF)
|
|
||||||
* ------------------------ Default
|
|
||||||
* PA8 - input with pull-up.
|
|
||||||
* PA9 - floating input.
|
|
||||||
* PA10 - floating input.
|
|
||||||
* PA13 - input with pull-up.
|
|
||||||
* PA14 - input with pull-up.
|
|
||||||
* PA15 - Push pull output (USB 1:ON 0:OFF)
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_USB_ODR 0xFFFFE77F
|
|
||||||
#define VAL_GPIO_USB_CRL 0x34444488 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_USB_CRH 0x38811444 /* PA15...PA8 */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port B setup.
|
|
||||||
* PB0 - Push pull output (Green LED2 1:ON 0:OFF)
|
|
||||||
* ------------------------ Default
|
|
||||||
* PBx - input with pull-up.
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_LED_ODR 0xFFFFFFFF
|
|
||||||
#define VAL_GPIO_LED_CRL 0x88888883 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_LED_CRH 0x88888888 /* PA15...PA8 */
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN \
|
|
||||||
(RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_AFIOEN)
|
|
||||||
#define RCC_RSTR_IOP_RST \
|
|
||||||
(RCC_APB2RSTR_IOPARST | RCC_APB2RSTR_IOPBRST | RCC_APB2RSTR_AFIORST)
|
|
||||||
|
|
||||||
#define AFIO_MAPR_SOMETHING AFIO_MAPR_SWJ_CFG_JTAGDISABLE
|
|
@ -1,33 +0,0 @@
|
|||||||
#define BOARD_NAME "Olimex STM32-H103"
|
|
||||||
#define BOARD_ID 0xf92bb594
|
|
||||||
|
|
||||||
#define MCU_STM32F1 1
|
|
||||||
#define STM32F10X_MD /* Medium-density device */
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 9
|
|
||||||
#define STM32_HSECLK 8000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOC_BASE
|
|
||||||
#define GPIO_LED_CLEAR_TO_EMIT 12
|
|
||||||
#define GPIO_USB_BASE GPIOC_BASE
|
|
||||||
#define GPIO_USB_CLEAR_TO_ENABLE 11
|
|
||||||
#undef GPIO_OTHER_BASE
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port C setup.
|
|
||||||
* PC0 - input with pull-up. AN10 for NeuG
|
|
||||||
* PC1 - input with pull-up. AN11 for NeuG
|
|
||||||
* PC6 - input without pull-up/down
|
|
||||||
* PC7 - input without pull-up/down
|
|
||||||
* PC11 - Open-drain output 50MHz (USB disconnect).
|
|
||||||
* PC12 - Push Pull output 50MHz (LED).
|
|
||||||
* ------------------------ Default
|
|
||||||
* PCx - input with pull-up
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_LED_ODR 0xFFFFFFFF
|
|
||||||
#define VAL_GPIO_LED_CRL 0x44888888 /* PC7...PC0 */
|
|
||||||
#define VAL_GPIO_LED_CRH 0x88837888 /* PC15...PC8 */
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN RCC_APB2ENR_IOPCEN
|
|
||||||
#define RCC_RSTR_IOP_RST RCC_APB2RSTR_IOPCRST
|
|
@ -1,34 +0,0 @@
|
|||||||
#define BOARD_NAME "ST Dongle"
|
|
||||||
/* echo -n "ST Dongle" | shasum -a 256 | sed -e 's/^.*\(........\) -$/\1/' */
|
|
||||||
#define BOARD_ID 0x2cd4e471
|
|
||||||
|
|
||||||
#define MCU_STM32F1 1
|
|
||||||
#define STM32F10X_MD /* Medium-density device */
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 9
|
|
||||||
#define STM32_HSECLK 8000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOA_BASE
|
|
||||||
#define GPIO_LED_SET_TO_EMIT 9
|
|
||||||
#define GPIO_USB_BASE GPIOA_BASE
|
|
||||||
#define GPIO_USB_SET_TO_ENABLE 15
|
|
||||||
#undef GPIO_OTHER_BASE
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA0 - input with pull-up. AN0
|
|
||||||
* PA1 - input with pull-up. AN1
|
|
||||||
* PA9 - Push pull output 50MHz (LED 1:ON 0:OFF)
|
|
||||||
* PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM)
|
|
||||||
* PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP)
|
|
||||||
* PA15 - Push pull output 50MHz (USB 1:ON 0:OFF)
|
|
||||||
* ------------------------ Default
|
|
||||||
* PAx - input with pull-up
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_LED_ODR 0xFFFFE7FF
|
|
||||||
#define VAL_GPIO_LED_CRL 0x88888888 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_LED_CRH 0x38811838 /* PA15...PA8 */
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN RCC_APB2ENR_IOPAEN
|
|
||||||
#define RCC_RSTR_IOP_RST RCC_APB2RSTR_IOPARST
|
|
@ -1,74 +0,0 @@
|
|||||||
#define BOARD_NAME "ST Nucleo F103"
|
|
||||||
#define BOARD_ID 0x9b87c16d
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Please add X3 and USB cable to ST Nucleo F103.
|
|
||||||
*
|
|
||||||
* Solder X3 XTAL of 8MHz (and put C33 and C34 of 22pF).
|
|
||||||
* Solder the bridges for R35 and R37, since it's 0 ohm.
|
|
||||||
*
|
|
||||||
* (Optional) Remove SB54 and SB55.
|
|
||||||
*
|
|
||||||
* At CN10, connect USB cable
|
|
||||||
* Vbus RED --> 10 NC ----------> CN7 (6 E5V)
|
|
||||||
* D+ GREEN --> 12 PA11 ---[1K5]--> CN6 (4 3V3)
|
|
||||||
* D- WHITE --> 14 PA12
|
|
||||||
* GND BLACK --> 20 GND
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define MCU_STM32F1 1
|
|
||||||
#define STM32F10X_MD /* Medium-density device */
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 9
|
|
||||||
#define STM32_HSECLK 8000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOA_BASE
|
|
||||||
#define GPIO_LED_SET_TO_EMIT 5
|
|
||||||
#undef GPIO_USB_BASE /* No external DISCONNECT/RENUM circuit. */
|
|
||||||
#define GPIO_OTHER_BASE GPIOB_BASE
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA0 - Input with pull-up USART2-CTS
|
|
||||||
* PA1 - Alternate function push pull output 2MHz USART2-RTS
|
|
||||||
* PA2 - Alternate function push pull output 2MHz USART2-TX
|
|
||||||
* PA3 - Input with pull-up USART2-RX
|
|
||||||
* PA4 - Alternate function push pull output 2MHz USART2-CK
|
|
||||||
* PA5 - Push pull output 2MHz (LED 1:ON 0:OFF)
|
|
||||||
* PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM)
|
|
||||||
* PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP)
|
|
||||||
* ------------------------ Default
|
|
||||||
* PAx - input with pull-up
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_LED_ODR 0xFFFFE7FF
|
|
||||||
#define VAL_GPIO_LED_CRL 0x882A8AA8 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_LED_CRH 0x88811888 /* PA15...PA8 */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port B setup.
|
|
||||||
* PB0 - input with pull-up: AN8 for NeuG
|
|
||||||
* PB1 - input with pull-up: AN9 for NeuG
|
|
||||||
* ---
|
|
||||||
* ---
|
|
||||||
* PB4 - Input with pull-up: Card insertion detect: 0 when detected
|
|
||||||
* ---
|
|
||||||
* PB6 - Output push pull 2MHz: Vcc for card: default 0
|
|
||||||
* ---
|
|
||||||
* PB8 - Output push pull 2MHz: Vpp for card: default 0
|
|
||||||
* PB9 - Output push pull 2MHz: RST for card: default 0
|
|
||||||
* PB10 - Alternate function open-drain output 50MHz USART3-TX
|
|
||||||
* PB11 - Input with pull-up USART3-RX
|
|
||||||
* PB12 - Alternate function push pull output 50MHz USART3-CK
|
|
||||||
* PB13 - Input with pull-up USART3-CTS
|
|
||||||
* PB14 - Alternate function push pull output 50MHz USART3-RTS
|
|
||||||
* ---
|
|
||||||
* ------------------------ Default
|
|
||||||
* PBx - input with pull-up.
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_OTHER_ODR 0xFFFFFCBF
|
|
||||||
#define VAL_GPIO_OTHER_CRL 0x82888888 /* PB7...PB0 */
|
|
||||||
#define VAL_GPIO_OTHER_CRH 0x8B8B8F22 /* PB15...PB8 */
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN (RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN)
|
|
||||||
#define RCC_RSTR_IOP_RST (RCC_APB2RSTR_IOPARST | RCC_APB2RSTR_IOPBRST)
|
|
@ -1,114 +0,0 @@
|
|||||||
#define BOARD_NAME "STBee Mini"
|
|
||||||
#define BOARD_ID 0x1f341961
|
|
||||||
|
|
||||||
#define MCU_STM32F1 1
|
|
||||||
#define STM32F10X_MD /* Medium-density device */
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 6
|
|
||||||
#define STM32_HSECLK 12000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOA_BASE
|
|
||||||
#define GPIO_LED_CLEAR_TO_EMIT 13
|
|
||||||
#define GPIO_USB_BASE GPIOA_BASE
|
|
||||||
#define GPIO_USB_SET_TO_ENABLE 14
|
|
||||||
|
|
||||||
#if defined(PINPAD_CIR_SUPPORT) || defined(PINPAD_DIAL_SUPPORT)
|
|
||||||
#define HAVE_7SEGLED 1
|
|
||||||
/*
|
|
||||||
* Timer assignment for CIR
|
|
||||||
*/
|
|
||||||
#define TIMx TIM3
|
|
||||||
#define INTR_REQ_TIM TIM3_IRQ
|
|
||||||
#define AFIO_EXTICR_INDEX 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(PINPAD_CIR_SUPPORT)
|
|
||||||
#define AFIO_EXTICR1_EXTIx_Py AFIO_EXTICR1_EXTI0_PB
|
|
||||||
#define EXTI_PR EXTI_PR_PR0
|
|
||||||
#define EXTI_IMR EXTI_IMR_MR0
|
|
||||||
#define EXTI_FTSR_TR EXTI_FTSR_TR0
|
|
||||||
#define INTR_REQ_EXTI EXTI0_IRQ
|
|
||||||
#define RCC_APBnENR_TIMxEN RCC_APB1ENR_TIM3EN
|
|
||||||
#define RCC_APBnRSTR_TIMxRST RCC_APB1RSTR_TIM3RST
|
|
||||||
#elif defined(PINPAD_DIAL_SUPPORT)
|
|
||||||
#define AFIO_EXTICR1_EXTIx_Py AFIO_EXTICR1_EXTI2_PB
|
|
||||||
#define EXTI_PR EXTI_PR_PR2
|
|
||||||
#define EXTI_IMR EXTI_IMR_MR2
|
|
||||||
#define EXTI_FTSR_TR EXTI_FTSR_TR2
|
|
||||||
#define INTR_REQ_EXTI EXTI2_IRQ
|
|
||||||
#define RCC_APBnENR_TIMxEN RCC_APB1ENR_TIM4EN
|
|
||||||
#define RCC_APBnRSTR_TIMxRST RCC_APB1RSTR_TIM4RST
|
|
||||||
#endif
|
|
||||||
#define ENABLE_RCC_APB1
|
|
||||||
|
|
||||||
#if defined(PINPAD_CIR_SUPPORT) || defined(PINPAD_DIAL_SUPPORT)
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA1 - Digital input with PullUp. AN1 for NeuG
|
|
||||||
* PA2 - Digital input with PullUp. AN2 for NeuG
|
|
||||||
* PA6 - (TIM3_CH1) input with pull-up
|
|
||||||
* PA7 - (TIM3_CH2) input with pull-down
|
|
||||||
* PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM)
|
|
||||||
* PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP)
|
|
||||||
* PA13 - Open Drain output (LED1 0:ON 1:OFF)
|
|
||||||
* PA14 - Push pull output (USB ENABLE 0:DISABLE 1:ENABLE)
|
|
||||||
* PA15 - Open Drain output (LED2 0:ON 1:OFF)
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_LED_ODR 0xFFFFE77F
|
|
||||||
#define VAL_GPIO_LED_CRL 0x88888888 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_LED_CRH 0x63611888 /* PA15...PA8 */
|
|
||||||
|
|
||||||
#define GPIO_OTHER_BASE GPIOB_BASE
|
|
||||||
/*
|
|
||||||
* Port B setup.
|
|
||||||
* PB0 - Push pull output (LED 1:ON 0:OFF)
|
|
||||||
* ------------------------ Default
|
|
||||||
* PBx - input with pull-up.
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_OTHER_ODR 0xFFFFFFFF
|
|
||||||
#define VAL_GPIO_OTHER_CRL 0x88888888 /* PB7...PB0 */
|
|
||||||
#define VAL_GPIO_OTHER_CRH 0x66666666 /* PB15...PB8 */
|
|
||||||
|
|
||||||
/* Port B setup. */
|
|
||||||
#define GPIOB_CIR 0
|
|
||||||
#define GPIOB_BUTTON 2
|
|
||||||
#define GPIOB_ROT_A 6
|
|
||||||
#define GPIOB_ROT_B 7
|
|
||||||
|
|
||||||
#define GPIOB_7SEG_DP 15
|
|
||||||
#define GPIOB_7SEG_A 14
|
|
||||||
#define GPIOB_7SEG_B 13
|
|
||||||
#define GPIOB_7SEG_C 12
|
|
||||||
#define GPIOB_7SEG_D 11
|
|
||||||
#define GPIOB_7SEG_E 10
|
|
||||||
#define GPIOB_7SEG_F 9
|
|
||||||
#define GPIOB_7SEG_G 8
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN \
|
|
||||||
(RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_AFIOEN)
|
|
||||||
#define RCC_RSTR_IOP_RST \
|
|
||||||
(RCC_APB2RSTR_IOPARST | RCC_APB2RSTR_IOPBRST | RCC_APB2RSTR_AFIORST)
|
|
||||||
#else
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA1 - Digital input with PullUp. AN1 for NeuG
|
|
||||||
* PA2 - Digital input with PullUp. AN2 for NeuG
|
|
||||||
* PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM)
|
|
||||||
* PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP)
|
|
||||||
* PA13 - Open Drain output (LED1 0:ON 1:OFF)
|
|
||||||
* PA14 - Push pull output (USB ENABLE 0:DISABLE 1:ENABLE)
|
|
||||||
* PA15 - Open Drain output (LED2 0:ON 1:OFF)
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_LED_ODR 0xFFFFE7FF
|
|
||||||
#define VAL_GPIO_LED_CRL 0x88888888 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_LED_CRH 0x63611888 /* PA15...PA8 */
|
|
||||||
|
|
||||||
#undef GPIO_OTHER_BASE
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN (RCC_APB2ENR_IOPAEN | RCC_APB2ENR_AFIOEN)
|
|
||||||
#define RCC_RSTR_IOP_RST (RCC_APB2RSTR_IOPARST | RCC_APB2RSTR_AFIORST)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#define AFIO_MAPR_SOMETHING AFIO_MAPR_SWJ_CFG_DISABLE
|
|
@ -1,37 +0,0 @@
|
|||||||
#define BOARD_NAME "STBee"
|
|
||||||
#define BOARD_ID 0x945c37e8
|
|
||||||
|
|
||||||
#define MCU_STM32F1 1
|
|
||||||
/* High-density device */
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 6
|
|
||||||
#define STM32_HSECLK 12000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOD_BASE
|
|
||||||
#define GPIO_LED_CLEAR_TO_EMIT 4
|
|
||||||
#define GPIO_USB_BASE GPIOD_BASE
|
|
||||||
#define GPIO_USB_CLEAR_TO_ENABLE 3
|
|
||||||
#define GPIO_OTHER_BASE GPIOA_BASE
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA0 - Normal input.
|
|
||||||
* PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM)
|
|
||||||
* PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP)
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_OTHER_ODR 0xFFFFE7FF
|
|
||||||
#define VAL_GPIO_OTHER_CRL 0x88888884 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_OTHER_CRH 0x88811888 /* PA15...PA8 */
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN (RCC_APB2ENR_IOPAEN|RCC_APB2ENR_IOPDEN)
|
|
||||||
#define RCC_RSTR_IOP_RST (RCC_APB2RSTR_IOPARST|RCC_APB2RSTR_IOPDRST)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port D setup.
|
|
||||||
* PD3 - Push pull output (USB_DISC 1:USB-DISABLE 0:USB-ENABLE) 2MHz
|
|
||||||
* PD4 - Open Drain output 2MHz (LED1).
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_LED_ODR 0xFFFFFFFF
|
|
||||||
#define VAL_GPIO_LED_CRL 0x88862888 /* PD7...PD0 */
|
|
||||||
#define VAL_GPIO_LED_CRH 0x88888888 /* PD15...PD8 */
|
|
@ -1,59 +0,0 @@
|
|||||||
#define BOARD_NAME "STM32 Primer2"
|
|
||||||
#define BOARD_ID 0x21e5798d
|
|
||||||
|
|
||||||
#define MCU_STM32F1 1
|
|
||||||
/* High-density device */
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 6
|
|
||||||
#define STM32_HSECLK 12000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOE_BASE
|
|
||||||
#define GPIO_LED_SET_TO_EMIT 0
|
|
||||||
#define GPIO_USB_BASE GPIOD_BASE
|
|
||||||
#define GPIO_USB_CLEAR_TO_ENABLE 3
|
|
||||||
#define GPIO_OTHER_BASE GPIOA_BASE
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA0 - input with pull-up. AN0
|
|
||||||
* PA1 - input with pull-up. AN1
|
|
||||||
* PA8 - Input with pull-down (PBUTTON).
|
|
||||||
* PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM)
|
|
||||||
* PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP)
|
|
||||||
* ------------------------ Default
|
|
||||||
* PAx - input with pull-up
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_OTHER_ODR 0xFFFFE6FF
|
|
||||||
#define VAL_GPIO_OTHER_CRL 0x88888888 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_OTHER_CRH 0x88811888 /* PA15...PA8 */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port D setup.
|
|
||||||
* PD3 - Push pull output 50MHz (USB 1:ON 0:OFF)
|
|
||||||
* ------------------------ Default
|
|
||||||
* PDx - input with pull-up
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_USB_ODR 0xFFFFFFFF
|
|
||||||
#define VAL_GPIO_USB_CRL 0x88883888 /* PD7...PD0 */
|
|
||||||
#define VAL_GPIO_USB_CRH 0x88888888 /* PD15...PD8 */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port E setup.
|
|
||||||
* PE0 - Push pull output (LED 1:ON 0:OFF)
|
|
||||||
* PE1 - Push pull output (LED 1:ON 0:OFF)
|
|
||||||
* PE3 - Input with pull-down (JOYSTICK L).
|
|
||||||
* PE4 - Input with pull-down (JOYSTICK R).
|
|
||||||
* PE5 - Input with pull-down (JOYSTICK U).
|
|
||||||
* PE6 - Input with pull-down (JOYSTICK D).
|
|
||||||
* ------------------------ Default
|
|
||||||
* PEx - input with pull-up
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_LED_ODR 0xFFFFFF87
|
|
||||||
#define VAL_GPIO_LED_CRL 0x88888833 /* PE7...PE0 */
|
|
||||||
#define VAL_GPIO_LED_CRH 0x88888888 /* PE15...PE8 */
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN \
|
|
||||||
(RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPDEN | RCC_APB2ENR_IOPEEN)
|
|
||||||
#define RCC_RSTR_IOP_RST \
|
|
||||||
(RCC_APB2RSTR_IOPARST | RCC_APB2RSTR_IOPDRST | RCC_APB2RSTR_IOPERST)
|
|
@ -1,48 +0,0 @@
|
|||||||
#define BOARD_NAME "STM32F0 Discovery"
|
|
||||||
#define BOARD_ID 0xde4b4bc1
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Running at 48MHz with HSI as clock source.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#define MCU_STM32F0 1
|
|
||||||
/* __ARM_ARCH_6M__ */
|
|
||||||
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 12
|
|
||||||
#define STM32_HSICLK 8000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOC_BASE
|
|
||||||
#define GPIO_LED_SET_TO_EMIT 8
|
|
||||||
#define GPIO_OTHER_BASE GPIOA_BASE /* USER BUTTON */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port C setup.
|
|
||||||
* PC9 - LED3 (LED 1:ON 0:OFF)
|
|
||||||
* PC8 - LED4 (LED 1:ON 0:OFF)
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_LED_MODER 0x00050000 /* Output Pin9 and Pin8 */
|
|
||||||
#define VAL_GPIO_LED_OTYPER 0x00000000 /* Push-Pull */
|
|
||||||
#define VAL_GPIO_LED_OSPEEDR 0x000f0000 /* High speed: Pin9 and Pin8 */
|
|
||||||
#define VAL_GPIO_LED_PUPDR 0x00000000 /* No pull-up/pull-down */
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#define RCC_ENR_IOP_EN (RCC_AHBENR_IOPAEN | RCC_AHBENR_IOPCEN)
|
|
||||||
#define RCC_RSTR_IOP_RST (RCC_AHBRSTR_IOPARST | RCC_AHBRSTR_IOPCRST)
|
|
||||||
#else
|
|
||||||
#define RCC_ENR_IOP_EN RCC_AHBENR_IOPCEN
|
|
||||||
#define RCC_RSTR_IOP_RST RCC_AHBRSTR_IOPCRST
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* ??? NeuG settings for ADC2 is default (PA0: Analog IN0, PA1: Analog IN1). */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA0 - USER Button
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_OTHER_MODER 0x00000000 /* Input Pin0 */
|
|
||||||
#define VAL_GPIO_OTHER_OTYPER 0x00000000 /* Push-Pull */
|
|
||||||
#define VAL_GPIO_OTHER_OSPEEDR 0x00000000
|
|
||||||
#define VAL_GPIO_OTHER_PUPDR 0x00000000 /* No pull-up/pull-down */
|
|
@ -1,61 +0,0 @@
|
|||||||
#define BOARD_NAME "STM8S Discovery"
|
|
||||||
#define BOARD_ID 0x2f0976bb
|
|
||||||
|
|
||||||
#define MCU_STM32F1 1
|
|
||||||
#define STM32F10X_MD /* Medium-density device */
|
|
||||||
|
|
||||||
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
|
|
||||||
#define STM32_PLLMUL_VALUE 9
|
|
||||||
#define STM32_HSECLK 8000000
|
|
||||||
|
|
||||||
#define GPIO_LED_BASE GPIOA_BASE
|
|
||||||
#define GPIO_LED_SET_TO_EMIT 8
|
|
||||||
#undef GPIO_USB_BASE /* No external DISCONNECT/RENUM circuit. */
|
|
||||||
#define GPIO_OTHER_BASE GPIOB_BASE
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port A setup.
|
|
||||||
* PA0 - input with pull-up. AN0
|
|
||||||
* PA1 - input with pull-up. AN1
|
|
||||||
* PA8 - Push pull output 10MHz (LED 1:ON 0:OFF)
|
|
||||||
* PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM)
|
|
||||||
* PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP)
|
|
||||||
* ------------------------ Default
|
|
||||||
* PAx - input with pull-up
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_LED_ODR 0xFFFFE7FF
|
|
||||||
#define VAL_GPIO_LED_CRL 0x88888888 /* PA7...PA0 */
|
|
||||||
#define VAL_GPIO_LED_CRH 0x88811881 /* PA15...PA8 */
|
|
||||||
|
|
||||||
#define RCC_ENR_IOP_EN \
|
|
||||||
(RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_AFIOEN)
|
|
||||||
#define RCC_RSTR_IOP_RST \
|
|
||||||
(RCC_APB2RSTR_IOPARST | RCC_APB2RSTR_IOPBRST | RCC_APB2RSTR_AFIORST)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Port B setup.
|
|
||||||
* PB4 - (TIM3_CH1) input with pull-up
|
|
||||||
* PB5 - (TIM3_CH2) input with pull-up, connected to CIR module
|
|
||||||
* Everything input with pull-up except:
|
|
||||||
* PB0 - (TIM3_CH3) input with pull-down
|
|
||||||
*/
|
|
||||||
#define VAL_GPIO_OTHER_ODR 0xFFFFFFFE
|
|
||||||
#define VAL_GPIO_OTHER_CRL 0x88888888 /* PB7...PB0 */
|
|
||||||
#define VAL_GPIO_OTHER_CRH 0x88888888 /* PB15...PB8 */
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(PINPAD_CIR_SUPPORT)
|
|
||||||
#define TIMx TIM3
|
|
||||||
#define INTR_REQ_TIM TIM3_IRQ
|
|
||||||
#define AFIO_EXTICR_INDEX 1
|
|
||||||
#define AFIO_EXTICR1_EXTIx_Py AFIO_EXTICR2_EXTI5_PB
|
|
||||||
#define EXTI_PR EXTI_PR_PR5
|
|
||||||
#define EXTI_IMR EXTI_IMR_MR5
|
|
||||||
#define EXTI_FTSR_TR EXTI_FTSR_TR5
|
|
||||||
#define INTR_REQ_EXTI EXTI9_5_IRQ
|
|
||||||
#define ENABLE_RCC_APB1
|
|
||||||
#define RCC_APBnENR_TIMxEN RCC_APB1ENR_TIM3EN
|
|
||||||
#define RCC_APBnRSTR_TIMxRST RCC_APB1RSTR_TIM3RST
|
|
||||||
#define AFIO_MAPR_SOMETHING AFIO_MAPR_TIM3_REMAP_PARTIALREMAP
|
|
||||||
/* Remap (PB4, PB5) -> (TIM3_CH1, TIM3_CH2) */
|
|
||||||
#endif
|
|
@ -1,699 +0,0 @@
|
|||||||
/*
|
|
||||||
* chopstx-cortex-m.c - Threads and only threads: Arch specific code
|
|
||||||
* for Cortex-M0/M3
|
|
||||||
*
|
|
||||||
* Copyright (C) 2013, 2014, 2015, 2016, 2017, 2018
|
|
||||||
* Flying Stone Technology
|
|
||||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
|
||||||
*
|
|
||||||
* This file is a part of Chopstx, a thread library for embedded.
|
|
||||||
*
|
|
||||||
* Chopstx is free software: you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Chopstx is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* As additional permission under GNU GPL version 3 section 7, you may
|
|
||||||
* distribute non-source form of the Program without the copy of the
|
|
||||||
* GNU GPL normally required by section 4, provided you inform the
|
|
||||||
* receipents of GNU GPL by a written offer.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Data Memory Barrier. */
|
|
||||||
static void
|
|
||||||
chx_dmb (void)
|
|
||||||
{
|
|
||||||
asm volatile ("dmb" : : : "memory");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Saved registers on the stack. */
|
|
||||||
struct chx_stack_regs {
|
|
||||||
uint32_t reg[8]; /* r0, r1, r2, r3, r12, lr, pc, xpsr */
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Constants for ARM.
|
|
||||||
*/
|
|
||||||
#define REG_SP 8
|
|
||||||
|
|
||||||
#define REG_R0 0
|
|
||||||
#define REG_LR 5
|
|
||||||
#define REG_PC 6
|
|
||||||
#define REG_XPSR 7
|
|
||||||
|
|
||||||
#define INITIAL_XPSR 0x01000000 /* T=1 */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Exception priority: lower has higher precedence.
|
|
||||||
*
|
|
||||||
* Cortex-M3
|
|
||||||
* =====================================
|
|
||||||
* Prio 0x30: svc
|
|
||||||
* ---------------------
|
|
||||||
* Prio 0x40: thread temporarily inhibiting schedule for critical region
|
|
||||||
* ...
|
|
||||||
* Prio 0xb0: systick, external interrupt
|
|
||||||
* Prio 0xc0: pendsv
|
|
||||||
* =====================================
|
|
||||||
*
|
|
||||||
* Cortex-M0
|
|
||||||
* =====================================
|
|
||||||
* Prio 0x00: thread temporarily inhibiting schedule for critical region
|
|
||||||
* ...
|
|
||||||
* Prio 0x40: systick, external interrupt
|
|
||||||
* Prio 0x80: pendsv
|
|
||||||
* Prio 0x80: svc
|
|
||||||
* =====================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define CPU_EXCEPTION_PRIORITY_CLEAR 0
|
|
||||||
|
|
||||||
#if defined(__ARM_ARCH_6M__)
|
|
||||||
#define CPU_EXCEPTION_PRIORITY_INHIBIT_SCHED 0x00
|
|
||||||
/* ... */
|
|
||||||
#define CPU_EXCEPTION_PRIORITY_SYSTICK CPU_EXCEPTION_PRIORITY_INTERRUPT
|
|
||||||
#define CPU_EXCEPTION_PRIORITY_INTERRUPT 0x40
|
|
||||||
#define CPU_EXCEPTION_PRIORITY_PENDSV 0x80
|
|
||||||
#define CPU_EXCEPTION_PRIORITY_SVC 0x80 /* No use in this arch */
|
|
||||||
#elif defined(__ARM_ARCH_7M__)
|
|
||||||
#define CPU_EXCEPTION_PRIORITY_SVC 0x30
|
|
||||||
|
|
||||||
#define CPU_EXCEPTION_PRIORITY_INHIBIT_SCHED 0x40
|
|
||||||
/* ... */
|
|
||||||
#define CPU_EXCEPTION_PRIORITY_SYSTICK CPU_EXCEPTION_PRIORITY_INTERRUPT
|
|
||||||
#define CPU_EXCEPTION_PRIORITY_INTERRUPT 0xb0
|
|
||||||
#define CPU_EXCEPTION_PRIORITY_PENDSV 0xc0
|
|
||||||
#else
|
|
||||||
#error "no support for this arch"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Lower layer architecture specific functions.
|
|
||||||
*
|
|
||||||
* system tick and interrupt
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* System tick
|
|
||||||
*/
|
|
||||||
/* SysTick registers. */
|
|
||||||
static volatile uint32_t *const SYST_CSR = (uint32_t *)0xE000E010;
|
|
||||||
static volatile uint32_t *const SYST_RVR = (uint32_t *)0xE000E014;
|
|
||||||
static volatile uint32_t *const SYST_CVR = (uint32_t *)0xE000E018;
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_systick_reset (void)
|
|
||||||
{
|
|
||||||
*SYST_RVR = 0;
|
|
||||||
*SYST_CVR = 0;
|
|
||||||
*SYST_CSR = 7;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_systick_reload (uint32_t ticks)
|
|
||||||
{
|
|
||||||
*SYST_RVR = ticks;
|
|
||||||
*SYST_CVR = 0; /* write (any) to clear the counter to reload. */
|
|
||||||
*SYST_RVR = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t
|
|
||||||
chx_systick_get (void)
|
|
||||||
{
|
|
||||||
return *SYST_CVR;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t usec_to_ticks (uint32_t usec)
|
|
||||||
{
|
|
||||||
return usec * MHZ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Interrupt Handling
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* NVIC: Nested Vectored Interrupt Controller. */
|
|
||||||
struct NVIC {
|
|
||||||
volatile uint32_t ISER[8];
|
|
||||||
uint32_t unused1[24];
|
|
||||||
volatile uint32_t ICER[8];
|
|
||||||
uint32_t unused2[24];
|
|
||||||
volatile uint32_t ISPR[8];
|
|
||||||
uint32_t unused3[24];
|
|
||||||
volatile uint32_t ICPR[8];
|
|
||||||
uint32_t unused4[24];
|
|
||||||
volatile uint32_t IABR[8];
|
|
||||||
uint32_t unused5[56];
|
|
||||||
volatile uint32_t IPR[60];
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct NVIC *const NVIC = (struct NVIC *)0xE000E100;
|
|
||||||
#define NVIC_ISER(n) (NVIC->ISER[n >> 5])
|
|
||||||
#define NVIC_ICER(n) (NVIC->ICER[n >> 5])
|
|
||||||
#define NVIC_ICPR(n) (NVIC->ICPR[n >> 5])
|
|
||||||
#define NVIC_IPR(n) (NVIC->IPR[n >> 2])
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_enable_intr (uint8_t irq_num)
|
|
||||||
{
|
|
||||||
NVIC_ISER (irq_num) = 1 << (irq_num & 0x1f);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_clr_intr (uint8_t irq_num)
|
|
||||||
{ /* Clear pending interrupt. */
|
|
||||||
NVIC_ICPR (irq_num) = 1 << (irq_num & 0x1f);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_disable_intr (uint8_t irq_num)
|
|
||||||
{
|
|
||||||
NVIC_ICER (irq_num) = 1 << (irq_num & 0x1f);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_set_intr_prio (uint8_t n)
|
|
||||||
{
|
|
||||||
unsigned int sh = (n & 3) << 3;
|
|
||||||
|
|
||||||
NVIC_IPR (n) = (NVIC_IPR(n) & ~(0xFF << sh))
|
|
||||||
| (CPU_EXCEPTION_PRIORITY_INTERRUPT << sh);
|
|
||||||
}
|
|
||||||
|
|
||||||
static volatile uint32_t *const ICSR = (uint32_t *)0xE000ED04;
|
|
||||||
|
|
||||||
/* Priority control. */
|
|
||||||
static uint32_t *const AIRCR = (uint32_t *)0xE000ED0C;
|
|
||||||
static uint32_t *const SHPR2 = (uint32_t *)0xE000ED1C;
|
|
||||||
static uint32_t *const SHPR3 = (uint32_t *)0xE000ED20;
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_prio_init (void)
|
|
||||||
{
|
|
||||||
*AIRCR = 0x05FA0000 | ( 5 << 8); /* PRIGROUP = 5, 2-bit:2-bit. */
|
|
||||||
*SHPR2 = (CPU_EXCEPTION_PRIORITY_SVC << 24);
|
|
||||||
*SHPR3 = ((CPU_EXCEPTION_PRIORITY_SYSTICK << 24)
|
|
||||||
| (CPU_EXCEPTION_PRIORITY_PENDSV << 16));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_cpu_sched_lock (void)
|
|
||||||
{
|
|
||||||
if (running->prio < CHOPSTX_PRIO_INHIBIT_PREEMPTION)
|
|
||||||
{
|
|
||||||
#if defined(__ARM_ARCH_6M__)
|
|
||||||
asm volatile ("cpsid i" : : : "memory");
|
|
||||||
#else
|
|
||||||
register uint32_t tmp = CPU_EXCEPTION_PRIORITY_INHIBIT_SCHED;
|
|
||||||
asm volatile ("msr BASEPRI, %0" : : "r" (tmp) : "memory");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_cpu_sched_unlock (void)
|
|
||||||
{
|
|
||||||
if (running->prio < CHOPSTX_PRIO_INHIBIT_PREEMPTION)
|
|
||||||
{
|
|
||||||
#if defined(__ARM_ARCH_6M__)
|
|
||||||
asm volatile ("cpsie i" : : : "memory");
|
|
||||||
#else
|
|
||||||
register uint32_t tmp = CPU_EXCEPTION_PRIORITY_CLEAR;
|
|
||||||
asm volatile ("msr BASEPRI, %0" : : "r" (tmp) : "memory");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
chx_handle_intr (void)
|
|
||||||
{
|
|
||||||
struct chx_pq *p;
|
|
||||||
register uint32_t irq_num;
|
|
||||||
|
|
||||||
asm volatile ("mrs %0, IPSR\n\t"
|
|
||||||
"sub %0, #16" /* Exception # - 16 = interrupt number. */
|
|
||||||
: "=r" (irq_num) : /* no input */ : "memory");
|
|
||||||
|
|
||||||
chx_disable_intr (irq_num);
|
|
||||||
chx_spin_lock (&q_intr.lock);
|
|
||||||
for (p = q_intr.q.next; p != (struct chx_pq *)&q_intr.q; p = p->next)
|
|
||||||
if (p->v == irq_num)
|
|
||||||
{ /* should be one at most. */
|
|
||||||
struct chx_px *px = (struct chx_px *)p;
|
|
||||||
|
|
||||||
ll_dequeue (p);
|
|
||||||
chx_wakeup (p);
|
|
||||||
chx_request_preemption (px->master->prio);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
chx_spin_unlock (&q_intr.lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_init_arch (struct chx_thread *tp)
|
|
||||||
{
|
|
||||||
memset (&tp->tc, 0, sizeof (tp->tc));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_request_preemption (uint16_t prio)
|
|
||||||
{
|
|
||||||
if (running == NULL || (uint16_t)running->prio < prio)
|
|
||||||
{
|
|
||||||
*ICSR = (1 << 28);
|
|
||||||
asm volatile ("" : : : "memory");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* chx_sched: switch to another thread.
|
|
||||||
*
|
|
||||||
* There are two cases:
|
|
||||||
* YIELD=0 (SLEEP): Current RUNNING thread is already connected to
|
|
||||||
* something (mutex, cond, intr, etc.)
|
|
||||||
* YIELD=1 (YIELD): Current RUNNING thread is active,
|
|
||||||
* it is needed to be enqueued to READY queue.
|
|
||||||
*
|
|
||||||
* For Cortex-M0, this should be AAPCS-compliant function entry, so we
|
|
||||||
* put "noinline" attribute.
|
|
||||||
*
|
|
||||||
* AAPCS: ARM Architecture Procedure Call Standard
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* >= 1 on wakeup by others, value means ticks remained for sleep.
|
|
||||||
* 0 on normal wakeup (timer expiration, lock acquirement).
|
|
||||||
* -1 on cancellation.
|
|
||||||
*/
|
|
||||||
static uintptr_t __attribute__ ((naked, noinline))
|
|
||||||
chx_sched (uint32_t yield)
|
|
||||||
{
|
|
||||||
register struct chx_thread *tp asm ("r0");
|
|
||||||
|
|
||||||
#if defined(__ARM_ARCH_7M__)
|
|
||||||
asm volatile (
|
|
||||||
"svc #0"
|
|
||||||
: "=r" (tp) : "0" (yield): "memory");
|
|
||||||
#else
|
|
||||||
register uint32_t arg_yield asm ("r1");
|
|
||||||
|
|
||||||
/* Build stack data as if it were an exception entry. */
|
|
||||||
/*
|
|
||||||
* r0: TP scratch
|
|
||||||
* r1: 0 scratch
|
|
||||||
* r2: 0 scratch
|
|
||||||
* r3: 0 scratch
|
|
||||||
* r12: 0 scratch
|
|
||||||
* lr as-is
|
|
||||||
* pc: return address (= .L_CONTEXT_SWITCH_FINISH)
|
|
||||||
* psr: INITIAL_XPSR scratch
|
|
||||||
*/
|
|
||||||
asm ("mov r1, lr\n\t"
|
|
||||||
"ldr r2, =.L_CONTEXT_SWITCH_FINISH\n\t"
|
|
||||||
"mov r3, #128\n\t"
|
|
||||||
"lsl r3, #17\n\t"
|
|
||||||
"push {r1, r2, r3}\n\t"
|
|
||||||
"mov r1, #0\n\t"
|
|
||||||
"mov r2, r1\n\t"
|
|
||||||
"mov r3, r1\n\t"
|
|
||||||
"push {r1, r2, r3}\n\t"
|
|
||||||
"mov r1, r0\n\t"
|
|
||||||
"ldr r2, =running\n\t"
|
|
||||||
"ldr r0, [r2]\n\t"
|
|
||||||
"push {r0, r3}"
|
|
||||||
: "=r" (tp), "=r" (arg_yield)
|
|
||||||
: "0" (yield)
|
|
||||||
: "r2", "r3", "memory");
|
|
||||||
|
|
||||||
/* Save registers onto CHX_THREAD struct. */
|
|
||||||
asm ("add r0, #20\n\t"
|
|
||||||
"stm r0!, {r4, r5, r6, r7}\n\t"
|
|
||||||
"mov r2, r8\n\t"
|
|
||||||
"mov r3, r9\n\t"
|
|
||||||
"mov r4, r10\n\t"
|
|
||||||
"mov r5, r11\n\t"
|
|
||||||
"mov r6, sp\n\t"
|
|
||||||
"stm r0!, {r2, r3, r4, r5, r6}\n\t"
|
|
||||||
"sub r0, #56"
|
|
||||||
: /* no output */
|
|
||||||
: "r" (tp)
|
|
||||||
: "r2", "r3", "r4", "r5", "r6", "r7", "memory");
|
|
||||||
|
|
||||||
if (arg_yield)
|
|
||||||
{
|
|
||||||
if (tp->flag_sched_rr)
|
|
||||||
chx_timer_dequeue (tp);
|
|
||||||
chx_ready_enqueue (tp);
|
|
||||||
}
|
|
||||||
|
|
||||||
tp = chx_ready_pop ();
|
|
||||||
if (tp && tp->flag_sched_rr)
|
|
||||||
{
|
|
||||||
chx_spin_lock (&q_timer.lock);
|
|
||||||
tp = chx_timer_insert (tp, PREEMPTION_USEC);
|
|
||||||
chx_spin_unlock (&q_timer.lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
asm volatile (/* Now, r0 points to the thread to be switched. */
|
|
||||||
/* Put it to *running. */
|
|
||||||
"ldr r1, =running\n\t"
|
|
||||||
/* Update running. */
|
|
||||||
"str r0, [r1]\n\t"
|
|
||||||
"cmp r0, #0\n\t"
|
|
||||||
"bne 0f\n\t"
|
|
||||||
|
|
||||||
/* Spawn an IDLE thread. */
|
|
||||||
"ldr r1, =__main_stack_end__\n\t"
|
|
||||||
"mov sp, r1\n\t"
|
|
||||||
"ldr r0, =chx_idle\n\t" /* PC = idle */
|
|
||||||
/**/
|
|
||||||
/* Unmask interrupts. */
|
|
||||||
"cpsie i\n\t"
|
|
||||||
"bx r0\n"
|
|
||||||
|
|
||||||
/* Normal context switch */
|
|
||||||
"0:\n\t"
|
|
||||||
"add r0, #20\n\t"
|
|
||||||
"ldm r0!, {r4, r5, r6, r7}\n\t"
|
|
||||||
"ldm r0!, {r1, r2, r3}\n\t"
|
|
||||||
"mov r8, r1\n\t"
|
|
||||||
"mov r9, r2\n\t"
|
|
||||||
"mov r10, r3\n\t"
|
|
||||||
"ldm r0!, {r1, r2}\n\t"
|
|
||||||
"mov r11, r1\n\t"
|
|
||||||
"mov sp, r2\n\t"
|
|
||||||
"sub r0, #45\n\t"
|
|
||||||
"ldrb r1, [r0]\n\t" /* ->PRIO field. */
|
|
||||||
"cmp r1, #247\n\t"
|
|
||||||
"bhi 1f\n\t" /* Leave interrupt disabled if >= 248 */
|
|
||||||
/**/
|
|
||||||
/* Unmask interrupts. */
|
|
||||||
"cpsie i\n"
|
|
||||||
/**/
|
|
||||||
"1:\n\t"
|
|
||||||
/*
|
|
||||||
0: r0
|
|
||||||
4: r1
|
|
||||||
8: r2
|
|
||||||
12: r3
|
|
||||||
16: r12
|
|
||||||
20: lr
|
|
||||||
24: pc
|
|
||||||
28: psr
|
|
||||||
32: possibly exists for alignment
|
|
||||||
[28 or 32] <-- pc
|
|
||||||
*/
|
|
||||||
"ldr r0, [sp, #28]\n\t"
|
|
||||||
"lsl r1, r0, #23\n\t"
|
|
||||||
"bcc 2f\n\t"
|
|
||||||
/**/
|
|
||||||
"ldr r2, [sp, #24]\n\t"
|
|
||||||
"mov r1, #1\n\t"
|
|
||||||
"orr r2, r1\n\t" /* Ensure Thumb-mode */
|
|
||||||
"str r2, [sp, #32]\n\t"
|
|
||||||
"msr APSR_nzcvq, r0\n\t"
|
|
||||||
/**/
|
|
||||||
"ldr r0, [sp, #20]\n\t"
|
|
||||||
"mov lr, r0\n\t"
|
|
||||||
"ldr r0, [sp, #16]\n\t"
|
|
||||||
"mov r12, r0\n\t"
|
|
||||||
"pop {r0, r1, r2, r3}\n\t"
|
|
||||||
"add sp, #16\n\t"
|
|
||||||
"pop {pc}\n"
|
|
||||||
"2:\n\t"
|
|
||||||
"ldr r2, [sp, #24]\n\t"
|
|
||||||
"mov r1, #1\n\t"
|
|
||||||
"orr r2, r1\n\t" /* Ensure Thumb-mode */
|
|
||||||
"str r2, [sp, #28]\n\t"
|
|
||||||
"msr APSR_nzcvq, r0\n\t"
|
|
||||||
/**/
|
|
||||||
"ldr r0, [sp, #20]\n\t"
|
|
||||||
"mov lr, r0\n\t"
|
|
||||||
"ldr r0, [sp, #16]\n\t"
|
|
||||||
"mov r12, r0\n\t"
|
|
||||||
"pop {r0, r1, r2, r3}\n\t"
|
|
||||||
"add sp, #12\n\t"
|
|
||||||
"pop {pc}\n\t"
|
|
||||||
".L_CONTEXT_SWITCH_FINISH:"
|
|
||||||
: "=r" (tp) /* Return value in R0 */
|
|
||||||
: "0" (tp)
|
|
||||||
: "memory");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
asm volatile ("bx lr"
|
|
||||||
: "=r" (tp)
|
|
||||||
: "0" (tp->v)
|
|
||||||
: "memory");
|
|
||||||
return (uintptr_t)tp;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern void cause_link_time_error_unexpected_size_of_struct_chx_thread (void);
|
|
||||||
|
|
||||||
static struct chx_thread *
|
|
||||||
chopstx_create_arch (uintptr_t stack_addr, size_t stack_size,
|
|
||||||
voidfunc thread_entry, void *arg)
|
|
||||||
{
|
|
||||||
struct chx_thread *tp;
|
|
||||||
void *stack;
|
|
||||||
struct chx_stack_regs *p;
|
|
||||||
|
|
||||||
if (CHOPSTX_THREAD_SIZE != sizeof(struct chx_thread))
|
|
||||||
cause_link_time_error_unexpected_size_of_struct_chx_thread ();
|
|
||||||
|
|
||||||
if (stack_size < sizeof (struct chx_thread) + 8 * sizeof (uint32_t))
|
|
||||||
chx_fatal (CHOPSTX_ERR_THREAD_CREATE);
|
|
||||||
|
|
||||||
stack = (void *)(stack_addr + stack_size - sizeof (struct chx_thread)
|
|
||||||
- sizeof (struct chx_stack_regs));
|
|
||||||
memset (stack, 0, sizeof (struct chx_stack_regs));
|
|
||||||
tp = (struct chx_thread *)(stack + sizeof (struct chx_stack_regs));
|
|
||||||
p = (struct chx_stack_regs *)stack;
|
|
||||||
p->reg[REG_R0] = (uint32_t)arg;
|
|
||||||
p->reg[REG_LR] = (uint32_t)chopstx_exit;
|
|
||||||
p->reg[REG_PC] = (uint32_t)thread_entry;
|
|
||||||
p->reg[REG_XPSR] = INITIAL_XPSR;
|
|
||||||
|
|
||||||
memset (&tp->tc, 0, sizeof (tp->tc));
|
|
||||||
tp->tc.reg[REG_SP] = (uint32_t)stack;
|
|
||||||
|
|
||||||
return tp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Lower layer architecture specific exception handling entries.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
void __attribute__ ((naked))
|
|
||||||
preempt (void)
|
|
||||||
{
|
|
||||||
register struct chx_thread *tp asm ("r0");
|
|
||||||
register struct chx_thread *cur asm ("r1");
|
|
||||||
|
|
||||||
asm volatile (
|
|
||||||
#if defined(__ARM_ARCH_6M__)
|
|
||||||
"cpsid i\n\t"
|
|
||||||
#else
|
|
||||||
"msr BASEPRI, r0\n\t"
|
|
||||||
#endif
|
|
||||||
"ldr r2, =running\n\t"
|
|
||||||
"ldr r0, [r2]\n\t"
|
|
||||||
"mov r1, r0"
|
|
||||||
: "=r" (tp), "=r" (cur)
|
|
||||||
: "0" (CPU_EXCEPTION_PRIORITY_INHIBIT_SCHED)
|
|
||||||
: "r2");
|
|
||||||
|
|
||||||
if (!cur)
|
|
||||||
/* It's idle thread. It's ok to clobber registers. */
|
|
||||||
;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Save registers onto CHX_THREAD struct. */
|
|
||||||
asm volatile (
|
|
||||||
"add %0, #20\n\t"
|
|
||||||
"stm %0!, {r4, r5, r6, r7}\n\t"
|
|
||||||
"mov r2, r8\n\t"
|
|
||||||
"mov r3, r9\n\t"
|
|
||||||
"mov r4, r10\n\t"
|
|
||||||
"mov r5, r11\n\t"
|
|
||||||
"mrs r6, PSP\n\t" /* r13(=SP) in user space. */
|
|
||||||
"stm %0!, {r2, r3, r4, r5, r6}"
|
|
||||||
: "=r" (cur)
|
|
||||||
: "0" (cur)
|
|
||||||
/*
|
|
||||||
* Memory clobber constraint here is not accurate, but this
|
|
||||||
* works. R7 keeps its value, but having "r7" here prevents
|
|
||||||
* use of R7 before this asm statement.
|
|
||||||
*/
|
|
||||||
: "r2", "r3", "r4", "r5", "r6", "r7", "memory");
|
|
||||||
|
|
||||||
if (tp)
|
|
||||||
{
|
|
||||||
if (tp->flag_sched_rr)
|
|
||||||
{
|
|
||||||
if (tp->state == THREAD_RUNNING)
|
|
||||||
{
|
|
||||||
chx_timer_dequeue (tp);
|
|
||||||
chx_ready_enqueue (tp);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* It may be THREAD_READY after chx_timer_expired.
|
|
||||||
* Then, do nothing.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
else
|
|
||||||
chx_ready_push (tp);
|
|
||||||
running = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Registers on stack (PSP): r0, r1, r2, r3, r12, lr, pc, xpsr */
|
|
||||||
|
|
||||||
tp = chx_ready_pop ();
|
|
||||||
if (tp && tp->flag_sched_rr)
|
|
||||||
{
|
|
||||||
chx_spin_lock (&q_timer.lock);
|
|
||||||
tp = chx_timer_insert (tp, PREEMPTION_USEC);
|
|
||||||
chx_spin_unlock (&q_timer.lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
asm volatile (
|
|
||||||
".L_CONTEXT_SWITCH:\n\t"
|
|
||||||
/* Now, r0 points to the thread to be switched. */
|
|
||||||
/* Put it to *running. */
|
|
||||||
"ldr r1, =running\n\t"
|
|
||||||
/* Update running. */
|
|
||||||
"str r0, [r1]\n\t"
|
|
||||||
#if defined(__ARM_ARCH_6M__)
|
|
||||||
"cmp r0, #0\n\t"
|
|
||||||
"beq 1f\n\t"
|
|
||||||
#else
|
|
||||||
"cbz r0, 1f\n\t"
|
|
||||||
#endif
|
|
||||||
/**/
|
|
||||||
"add r0, #20\n\t"
|
|
||||||
"ldm r0!, {r4, r5, r6, r7}\n\t"
|
|
||||||
#if defined(__ARM_ARCH_6M__)
|
|
||||||
"ldm r0!, {r1, r2, r3}\n\t"
|
|
||||||
"mov r8, r1\n\t"
|
|
||||||
"mov r9, r2\n\t"
|
|
||||||
"mov r10, r3\n\t"
|
|
||||||
"ldm r0!, {r1, r2}\n\t"
|
|
||||||
"mov r11, r1\n\t"
|
|
||||||
"msr PSP, r2\n\t"
|
|
||||||
#else
|
|
||||||
"ldr r8, [r0], #4\n\t"
|
|
||||||
"ldr r9, [r0], #4\n\t"
|
|
||||||
"ldr r10, [r0], #4\n\t"
|
|
||||||
"ldr r11, [r0], #4\n\t"
|
|
||||||
"ldr r1, [r0], #4\n\t"
|
|
||||||
"msr PSP, r1\n\t"
|
|
||||||
#endif
|
|
||||||
"sub r0, #45\n\t"
|
|
||||||
"ldrb r1, [r0]\n\t" /* ->PRIO field. */
|
|
||||||
"mov r0, #0\n\t"
|
|
||||||
"cmp r1, #247\n\t"
|
|
||||||
"bhi 0f\n\t" /* Leave interrupt disabled if >= 248 */
|
|
||||||
/**/
|
|
||||||
/* Unmask interrupts. */
|
|
||||||
#if defined(__ARM_ARCH_6M__)
|
|
||||||
"cpsie i\n"
|
|
||||||
#else
|
|
||||||
"msr BASEPRI, r0\n"
|
|
||||||
#endif
|
|
||||||
/**/
|
|
||||||
"0:\n\t"
|
|
||||||
"sub r0, #3\n\t" /* EXC_RETURN to a thread with PSP */
|
|
||||||
"bx r0\n"
|
|
||||||
"1:\n\t"
|
|
||||||
/* Spawn an IDLE thread. */
|
|
||||||
"ldr r0, =__main_stack_end__-32\n\t"
|
|
||||||
"msr PSP, r0\n\t"
|
|
||||||
"mov r1, #0\n\t"
|
|
||||||
"mov r2, #0\n\t"
|
|
||||||
"mov r3, #0\n\t"
|
|
||||||
"stm r0!, {r1, r2, r3}\n\t"
|
|
||||||
"stm r0!, {r1, r2, r3}\n\t"
|
|
||||||
"ldr r1, =chx_idle\n\t" /* PC = idle */
|
|
||||||
"mov r2, #0x010\n\t"
|
|
||||||
"lsl r2, r2, #20\n\t" /* xPSR = T-flag set (Thumb) */
|
|
||||||
"stm r0!, {r1, r2}\n\t"
|
|
||||||
/**/
|
|
||||||
/* Unmask interrupts. */
|
|
||||||
"mov r0, #0\n\t"
|
|
||||||
#if defined(__ARM_ARCH_6M__)
|
|
||||||
"cpsie i\n\t"
|
|
||||||
#else
|
|
||||||
"msr BASEPRI, r0\n"
|
|
||||||
#endif
|
|
||||||
/**/
|
|
||||||
"sub r0, #3\n\t" /* EXC_RETURN to a thread with PSP */
|
|
||||||
"bx r0"
|
|
||||||
: /* no output */ : "r" (tp) : "memory");
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(__ARM_ARCH_7M__)
|
|
||||||
/*
|
|
||||||
* System call: switch to another thread.
|
|
||||||
* There are two cases:
|
|
||||||
* ORIG_R0=0 (SLEEP): Current RUNNING thread is already connected to
|
|
||||||
* something (mutex, cond, intr, etc.)
|
|
||||||
* ORIG_R0=1 (YIELD): Current RUNNING thread is active,
|
|
||||||
* it is needed to be enqueued to READY queue.
|
|
||||||
*/
|
|
||||||
void __attribute__ ((naked))
|
|
||||||
svc (void)
|
|
||||||
{
|
|
||||||
register struct chx_thread *tp asm ("r0");
|
|
||||||
register uint32_t orig_r0 asm ("r1");
|
|
||||||
|
|
||||||
asm ("ldr r1, =running\n\t"
|
|
||||||
"ldr r0, [r1]\n\t"
|
|
||||||
"add r1, r0, #20\n\t"
|
|
||||||
/* Save registers onto CHX_THREAD struct. */
|
|
||||||
"stm r1!, {r4, r5, r6, r7}\n\t"
|
|
||||||
"mov r2, r8\n\t"
|
|
||||||
"mov r3, r9\n\t"
|
|
||||||
"mov r4, r10\n\t"
|
|
||||||
"mov r5, r11\n\t"
|
|
||||||
"mrs r6, PSP\n\t" /* r13(=SP) in user space. */
|
|
||||||
"stm r1!, {r2, r3, r4, r5, r6}\n\t"
|
|
||||||
"ldr r1, [r6]\n\t"
|
|
||||||
"str r0, [r6]"
|
|
||||||
: "=r" (tp), "=r" (orig_r0)
|
|
||||||
: /* no input */
|
|
||||||
: "r2", "r3", "r4", "r5", "r6", "memory");
|
|
||||||
|
|
||||||
if (orig_r0) /* yield */
|
|
||||||
{
|
|
||||||
if (tp->flag_sched_rr)
|
|
||||||
chx_timer_dequeue (tp);
|
|
||||||
chx_ready_enqueue (tp);
|
|
||||||
running = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
tp = chx_ready_pop ();
|
|
||||||
if (tp && tp->flag_sched_rr)
|
|
||||||
{
|
|
||||||
chx_spin_lock (&q_timer.lock);
|
|
||||||
chx_timer_insert (tp, PREEMPTION_USEC);
|
|
||||||
chx_spin_unlock (&q_timer.lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
asm volatile (
|
|
||||||
"b .L_CONTEXT_SWITCH"
|
|
||||||
: /* no output */ : "r" (tp) : "memory");
|
|
||||||
}
|
|
||||||
#endif
|
|
@ -1,12 +0,0 @@
|
|||||||
/*
|
|
||||||
* The thread context: specific to ARM Cortex-M0/M3.
|
|
||||||
*
|
|
||||||
* In this structure, it's only partial information; Other part of the
|
|
||||||
* context is on the stack.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
struct tcontext {
|
|
||||||
uint32_t reg[9]; /* r4, r5, r6, r7, r8, r9, r10, r11, r13(sp) */
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct tcontext tcontext_t;
|
|
@ -1,351 +0,0 @@
|
|||||||
/*
|
|
||||||
* chopstx-gnu-linux.c - Threads and only threads: Arch specific code
|
|
||||||
* for GNU/Linux emulation
|
|
||||||
*
|
|
||||||
* Copyright (C) 2017, 2018 Flying Stone Technology
|
|
||||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
|
||||||
*
|
|
||||||
* This file is a part of Chopstx, a thread library for embedded.
|
|
||||||
*
|
|
||||||
* Chopstx is free software: you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Chopstx is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* As additional permission under GNU GPL version 3 section 7, you may
|
|
||||||
* distribute non-source form of the Program without the copy of the
|
|
||||||
* GNU GPL normally required by section 4, provided you inform the
|
|
||||||
* receipents of GNU GPL by a written offer.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <ucontext.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
/* Data Memory Barrier. */
|
|
||||||
static void
|
|
||||||
chx_dmb (void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static sigset_t ss_cur;
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_systick_reset (void)
|
|
||||||
{
|
|
||||||
const struct itimerval it = { {0, 0}, {0, 0} };
|
|
||||||
|
|
||||||
setitimer (ITIMER_REAL, &it, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_systick_reload (uint32_t ticks)
|
|
||||||
{
|
|
||||||
struct itimerval it;
|
|
||||||
|
|
||||||
it.it_value.tv_sec = 0;
|
|
||||||
it.it_value.tv_usec = (ticks / MHZ);
|
|
||||||
it.it_interval.tv_sec = 0;
|
|
||||||
it.it_interval.tv_usec = 0;
|
|
||||||
|
|
||||||
setitimer (ITIMER_REAL, &it, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t
|
|
||||||
chx_systick_get (void)
|
|
||||||
{
|
|
||||||
struct itimerval it;
|
|
||||||
getitimer (ITIMER_REAL, &it);
|
|
||||||
return it.it_value.tv_usec * 72;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t
|
|
||||||
usec_to_ticks (uint32_t usec)
|
|
||||||
{
|
|
||||||
return usec * MHZ;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_enable_intr (uint8_t irq_num)
|
|
||||||
{
|
|
||||||
sigdelset (&ss_cur, irq_num);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_clr_intr (uint8_t irq_num)
|
|
||||||
{ /* Clear pending interrupt. */
|
|
||||||
(void)irq_num;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_disable_intr (uint8_t irq_num)
|
|
||||||
{
|
|
||||||
sigaddset (&ss_cur, irq_num);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_set_intr_prio (uint8_t n)
|
|
||||||
{
|
|
||||||
(void)n;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_prio_init (void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_cpu_sched_lock (void)
|
|
||||||
{
|
|
||||||
sigset_t ss;
|
|
||||||
|
|
||||||
sigfillset (&ss);
|
|
||||||
pthread_sigmask (SIG_BLOCK, &ss, &ss_cur);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_cpu_sched_unlock (void)
|
|
||||||
{
|
|
||||||
pthread_sigmask (SIG_SETMASK, &ss_cur, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
idle (void)
|
|
||||||
{
|
|
||||||
for (;;)
|
|
||||||
pause ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
chx_handle_intr (uint32_t irq_num)
|
|
||||||
{
|
|
||||||
struct chx_pq *p;
|
|
||||||
|
|
||||||
chx_disable_intr (irq_num);
|
|
||||||
chx_spin_lock (&q_intr.lock);
|
|
||||||
for (p = q_intr.q.next; p != (struct chx_pq *)&q_intr.q; p = p->next)
|
|
||||||
if (p->v == irq_num)
|
|
||||||
{ /* should be one at most. */
|
|
||||||
struct chx_px *px = (struct chx_px *)p;
|
|
||||||
|
|
||||||
ll_dequeue (p);
|
|
||||||
chx_wakeup (p);
|
|
||||||
chx_spin_unlock (&q_intr.lock);
|
|
||||||
chx_request_preemption (px->master->prio);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
chx_spin_unlock (&q_intr.lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static ucontext_t idle_tc;
|
|
||||||
static char idle_stack[4096];
|
|
||||||
|
|
||||||
struct chx_thread main_thread;
|
|
||||||
|
|
||||||
void
|
|
||||||
chx_sigmask (ucontext_t *uc)
|
|
||||||
{
|
|
||||||
/* Modify oldmask to SS_CUR, so that the signal mask will
|
|
||||||
* be set to SS_CUR.
|
|
||||||
*
|
|
||||||
* In user-level, sigset_t is big, but only the first word
|
|
||||||
* is used by the kernel.
|
|
||||||
*/
|
|
||||||
memcpy (&uc->uc_sigmask, &ss_cur, sizeof (uint64_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
sigalrm_handler (int sig, siginfo_t *siginfo, void *arg)
|
|
||||||
{
|
|
||||||
extern void chx_timer_expired (void);
|
|
||||||
ucontext_t *uc = arg;
|
|
||||||
(void)sig;
|
|
||||||
(void)siginfo;
|
|
||||||
chx_timer_expired ();
|
|
||||||
chx_sigmask (uc);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_init_arch (struct chx_thread *tp)
|
|
||||||
{
|
|
||||||
struct sigaction sa;
|
|
||||||
|
|
||||||
sigemptyset (&ss_cur);
|
|
||||||
|
|
||||||
sa.sa_sigaction = sigalrm_handler;
|
|
||||||
sigfillset (&sa.sa_mask);
|
|
||||||
sa.sa_flags = SA_SIGINFO|SA_RESTART;
|
|
||||||
sigaction (SIGALRM, &sa, NULL);
|
|
||||||
|
|
||||||
getcontext (&idle_tc);
|
|
||||||
idle_tc.uc_stack.ss_sp = idle_stack;
|
|
||||||
idle_tc.uc_stack.ss_size = sizeof (idle_stack);
|
|
||||||
idle_tc.uc_link = NULL;
|
|
||||||
makecontext (&idle_tc, idle, 0);
|
|
||||||
|
|
||||||
getcontext (&tp->tc);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
chx_request_preemption (uint16_t prio)
|
|
||||||
{
|
|
||||||
struct chx_thread *tp, *tp_prev;
|
|
||||||
ucontext_t *tcp;
|
|
||||||
|
|
||||||
if (running && (uint16_t)running->prio >= prio)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Change the context to another thread with higher priority. */
|
|
||||||
tp = tp_prev = running;
|
|
||||||
if (tp)
|
|
||||||
{
|
|
||||||
if (tp->flag_sched_rr)
|
|
||||||
{
|
|
||||||
if (tp->state == THREAD_RUNNING)
|
|
||||||
{
|
|
||||||
chx_timer_dequeue (tp);
|
|
||||||
chx_ready_enqueue (tp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
chx_ready_push (tp);
|
|
||||||
running = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
tp = running = chx_ready_pop ();
|
|
||||||
if (tp)
|
|
||||||
{
|
|
||||||
tcp = &tp->tc;
|
|
||||||
if (tp->flag_sched_rr)
|
|
||||||
{
|
|
||||||
chx_spin_lock (&q_timer.lock);
|
|
||||||
tp = chx_timer_insert (tp, PREEMPTION_USEC);
|
|
||||||
chx_spin_unlock (&q_timer.lock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
tcp = &idle_tc;
|
|
||||||
|
|
||||||
if (tp_prev)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* The swapcontext implementation may reset sigmask in the
|
|
||||||
* middle of its execution, unfortunately. It is best if
|
|
||||||
* sigmask restore is done at the end of the routine, but we
|
|
||||||
* can't assume that.
|
|
||||||
*
|
|
||||||
* Thus, there might be a race condition with regards to the
|
|
||||||
* user context TCP, if signal mask is cleared and signal comes
|
|
||||||
* in. To avoid this situation, we block signals.
|
|
||||||
*
|
|
||||||
* We don't need to fill the mask here. It keeps the condition
|
|
||||||
* of blocking signals before&after swapcontext call. It is
|
|
||||||
* done by the signal mask for sigaction, the initial creation
|
|
||||||
* of the thread, and the condition of chx_sched function which
|
|
||||||
* mandates holding cpu_sched_lock.
|
|
||||||
*/
|
|
||||||
swapcontext (&tp_prev->tc, tcp);
|
|
||||||
}
|
|
||||||
else if (tp)
|
|
||||||
{
|
|
||||||
setcontext (tcp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* chx_sched: switch to another thread.
|
|
||||||
*
|
|
||||||
* There are two cases:
|
|
||||||
* YIELD=0 (SLEEP): Current RUNNING thread is already connected to
|
|
||||||
* something (mutex, cond, intr, etc.)
|
|
||||||
* YIELD=1 (YIELD): Current RUNNING thread is active,
|
|
||||||
* it is needed to be enqueued to READY queue.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* 1 on wakeup by others.
|
|
||||||
* 0 on normal wakeup.
|
|
||||||
* -1 on cancellation.
|
|
||||||
*/
|
|
||||||
static uintptr_t
|
|
||||||
chx_sched (uint32_t yield)
|
|
||||||
{
|
|
||||||
struct chx_thread *tp, *tp_prev;
|
|
||||||
uintptr_t v;
|
|
||||||
ucontext_t *tcp;
|
|
||||||
|
|
||||||
tp = tp_prev = running;
|
|
||||||
if (yield)
|
|
||||||
{
|
|
||||||
if (tp->flag_sched_rr)
|
|
||||||
chx_timer_dequeue (tp);
|
|
||||||
chx_ready_enqueue (tp);
|
|
||||||
}
|
|
||||||
|
|
||||||
running = tp = chx_ready_pop ();
|
|
||||||
if (tp)
|
|
||||||
{
|
|
||||||
v = tp->v;
|
|
||||||
if (tp->flag_sched_rr)
|
|
||||||
{
|
|
||||||
chx_spin_lock (&q_timer.lock);
|
|
||||||
tp = chx_timer_insert (tp, PREEMPTION_USEC);
|
|
||||||
chx_spin_unlock (&q_timer.lock);
|
|
||||||
}
|
|
||||||
tcp = &tp->tc;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
v = 0;
|
|
||||||
tcp = &idle_tc;
|
|
||||||
}
|
|
||||||
|
|
||||||
swapcontext (&tp_prev->tc, tcp);
|
|
||||||
chx_cpu_sched_unlock ();
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __attribute__((__noreturn__))
|
|
||||||
chx_thread_start (voidfunc thread_entry, void *arg)
|
|
||||||
{
|
|
||||||
chx_cpu_sched_unlock ();
|
|
||||||
thread_entry (arg);
|
|
||||||
chopstx_exit (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct chx_thread *
|
|
||||||
chopstx_create_arch (uintptr_t stack_addr, size_t stack_size,
|
|
||||||
voidfunc thread_entry, void *arg)
|
|
||||||
{
|
|
||||||
struct chx_thread *tp;
|
|
||||||
tp = malloc (sizeof (struct chx_thread));
|
|
||||||
if (!tp)
|
|
||||||
chx_fatal (CHOPSTX_ERR_THREAD_CREATE);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Calling getcontext with sched_lock held, the context is with
|
|
||||||
* signal blocked. The sigmask will be cleared in chx_thread_start.
|
|
||||||
*/
|
|
||||||
chx_cpu_sched_lock ();
|
|
||||||
getcontext (&tp->tc);
|
|
||||||
tp->tc.uc_stack.ss_sp = (void *)stack_addr;
|
|
||||||
tp->tc.uc_stack.ss_size = stack_size;
|
|
||||||
tp->tc.uc_link = NULL;
|
|
||||||
|
|
||||||
makecontext (&tp->tc, (void (*)(void))chx_thread_start,
|
|
||||||
4, thread_entry, arg);
|
|
||||||
chx_cpu_sched_unlock ();
|
|
||||||
return tp;
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
#include <ucontext.h>
|
|
||||||
/*
|
|
||||||
* The thread context: specific to GNU/Linux.
|
|
||||||
*
|
|
||||||
* We use the type ucontext_t, which includes all registers;
|
|
||||||
* Note that signal mask is also included in ucontext_t.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef ucontext_t tcontext_t;
|
|
File diff suppressed because it is too large
Load Diff
@ -1,167 +0,0 @@
|
|||||||
/*
|
|
||||||
* chopstx.h - Threads and only threads.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2013, 2016, 2017, 2018 Flying Stone Technology
|
|
||||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
|
||||||
*
|
|
||||||
* This file is a part of Chopstx, a thread library for embedded.
|
|
||||||
*
|
|
||||||
* Chopstx is free software: you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Chopstx is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* As additional permission under GNU GPL version 3 section 7, you may
|
|
||||||
* distribute non-source form of the Program without the copy of the
|
|
||||||
* GNU GPL normally required by section 4, provided you inform the
|
|
||||||
* receipents of GNU GPL by a written offer.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct chx_qh {
|
|
||||||
struct chx_pq *next, *prev;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef uintptr_t chopstx_t;
|
|
||||||
typedef uint8_t chopstx_prio_t;
|
|
||||||
|
|
||||||
extern chopstx_t chopstx_main;
|
|
||||||
|
|
||||||
|
|
||||||
/* NOTE: This signature is different to PTHREAD's one. */
|
|
||||||
chopstx_t
|
|
||||||
chopstx_create (uint32_t flags_and_prio,
|
|
||||||
uintptr_t stack_addr, size_t stack_size,
|
|
||||||
void *(thread_entry) (void *), void *);
|
|
||||||
#define CHOPSTX_PRIO_BITS 8
|
|
||||||
#define CHOPSTX_DETACHED 0x10000
|
|
||||||
#define CHOPSTX_SCHED_RR 0x20000
|
|
||||||
|
|
||||||
#define CHOPSTX_PRIO_INHIBIT_PREEMPTION 248
|
|
||||||
|
|
||||||
void chopstx_usec_wait (uint32_t usec);
|
|
||||||
|
|
||||||
struct chx_spinlock {
|
|
||||||
/* nothing for uniprocessor. */
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct chx_mtx {
|
|
||||||
struct chx_qh q;
|
|
||||||
struct chx_spinlock lock;
|
|
||||||
struct chx_thread *owner;
|
|
||||||
struct chx_mtx *list;
|
|
||||||
} chopstx_mutex_t;
|
|
||||||
|
|
||||||
/* NOTE: This signature is different to PTHREAD's one. */
|
|
||||||
void chopstx_mutex_init (chopstx_mutex_t *mutex);
|
|
||||||
|
|
||||||
void chopstx_mutex_lock (chopstx_mutex_t *mutex);
|
|
||||||
|
|
||||||
void chopstx_mutex_unlock (chopstx_mutex_t *mutex);
|
|
||||||
|
|
||||||
typedef struct chx_cond {
|
|
||||||
struct chx_qh q;
|
|
||||||
struct chx_spinlock lock;
|
|
||||||
} chopstx_cond_t;
|
|
||||||
|
|
||||||
/* NOTE: This signature is different to PTHREAD's one. */
|
|
||||||
void chopstx_cond_init (chopstx_cond_t *cond);
|
|
||||||
|
|
||||||
void chopstx_cond_wait (chopstx_cond_t *cond, chopstx_mutex_t *mutex);
|
|
||||||
void chopstx_cond_signal (chopstx_cond_t *cond);
|
|
||||||
void chopstx_cond_broadcast (chopstx_cond_t *cond);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Library provides default implementation as weak reference.
|
|
||||||
* User can replace it.
|
|
||||||
*/
|
|
||||||
void chx_fatal (uint32_t err_code) __attribute__((__noreturn__));
|
|
||||||
|
|
||||||
int chopstx_join (chopstx_t, void **);
|
|
||||||
void chopstx_exit (void *retval) __attribute__((__noreturn__));
|
|
||||||
|
|
||||||
|
|
||||||
enum {
|
|
||||||
CHOPSTX_ERR_NONE = 0,
|
|
||||||
CHOPSTX_ERR_THREAD_CREATE,
|
|
||||||
CHOPSTX_ERR_JOIN,
|
|
||||||
};
|
|
||||||
|
|
||||||
#define CHOPSTX_CANCELED ((void *) -1)
|
|
||||||
|
|
||||||
void chopstx_cancel (chopstx_t thd);
|
|
||||||
void chopstx_testcancel (void);
|
|
||||||
|
|
||||||
/* NOTE: This signature is different to PTHREAD's one. */
|
|
||||||
int chopstx_setcancelstate (int);
|
|
||||||
|
|
||||||
typedef struct chx_cleanup {
|
|
||||||
struct chx_cleanup *next;
|
|
||||||
void (*routine) (void *);
|
|
||||||
void *arg;
|
|
||||||
} chopstx_cleanup_t;
|
|
||||||
|
|
||||||
/* NOTE: This signature is different to PTHREAD's one. */
|
|
||||||
void chopstx_cleanup_push (chopstx_cleanup_t *clp);
|
|
||||||
void chopstx_cleanup_pop (int execute);
|
|
||||||
|
|
||||||
chopstx_prio_t chopstx_setpriority (chopstx_prio_t);
|
|
||||||
|
|
||||||
enum {
|
|
||||||
CHOPSTX_POLL_COND = 0,
|
|
||||||
CHOPSTX_POLL_INTR,
|
|
||||||
CHOPSTX_POLL_JOIN,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct chx_poll_head {
|
|
||||||
uint16_t type;
|
|
||||||
uint16_t ready;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct chx_poll_cond {
|
|
||||||
uint16_t type;
|
|
||||||
uint16_t ready;
|
|
||||||
/**/
|
|
||||||
chopstx_cond_t *cond;
|
|
||||||
chopstx_mutex_t *mutex;
|
|
||||||
int (*check) (void *);
|
|
||||||
void *arg;
|
|
||||||
};
|
|
||||||
typedef struct chx_poll_cond chopstx_poll_cond_t;
|
|
||||||
|
|
||||||
struct chx_poll_join {
|
|
||||||
uint16_t type;
|
|
||||||
uint16_t ready;
|
|
||||||
/**/
|
|
||||||
chopstx_t thd;
|
|
||||||
};
|
|
||||||
typedef struct chx_poll_join chopstx_poll_join_t;
|
|
||||||
|
|
||||||
struct chx_intr {
|
|
||||||
uint16_t type;
|
|
||||||
uint16_t ready;
|
|
||||||
/**/
|
|
||||||
uint8_t irq_num;
|
|
||||||
};
|
|
||||||
typedef struct chx_intr chopstx_intr_t;
|
|
||||||
|
|
||||||
void chopstx_claim_irq (chopstx_intr_t *intr, uint8_t irq_num);
|
|
||||||
|
|
||||||
void chopstx_intr_wait (chopstx_intr_t *intr);
|
|
||||||
void chopstx_intr_done (chopstx_intr_t *intr);
|
|
||||||
|
|
||||||
|
|
||||||
int chopstx_poll (uint32_t *usec_p, int n,
|
|
||||||
struct chx_poll_head *const pd_array[]);
|
|
||||||
|
|
||||||
int chopstx_conf_idle (int enable_sleep);
|
|
||||||
|
|
||||||
#define CHOPSTX_THREAD_SIZE 64
|
|
Binary file not shown.
Before Width: | Height: | Size: 16 KiB |
@ -1,156 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
||||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
|
||||||
|
|
||||||
<svg
|
|
||||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
|
||||||
xmlns:cc="http://creativecommons.org/ns#"
|
|
||||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
|
||||||
xmlns:svg="http://www.w3.org/2000/svg"
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
|
||||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
|
||||||
width="210mm"
|
|
||||||
height="297mm"
|
|
||||||
id="svg2"
|
|
||||||
version="1.1"
|
|
||||||
inkscape:version="0.48.3.1 r9886"
|
|
||||||
sodipodi:docname="chopstx.svg"
|
|
||||||
inkscape:export-filename="chopstx.png"
|
|
||||||
inkscape:export-xdpi="36"
|
|
||||||
inkscape:export-ydpi="36">
|
|
||||||
<defs
|
|
||||||
id="defs4">
|
|
||||||
<marker
|
|
||||||
inkscape:stockid="Arrow1Lend"
|
|
||||||
orient="auto"
|
|
||||||
refY="0.0"
|
|
||||||
refX="0.0"
|
|
||||||
id="Arrow1Lend"
|
|
||||||
style="overflow:visible;">
|
|
||||||
<path
|
|
||||||
id="path3762"
|
|
||||||
d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
|
|
||||||
style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0pt;"
|
|
||||||
transform="scale(0.8) rotate(180) translate(12.5,0)" />
|
|
||||||
</marker>
|
|
||||||
</defs>
|
|
||||||
<sodipodi:namedview
|
|
||||||
id="base"
|
|
||||||
pagecolor="#ffffff"
|
|
||||||
bordercolor="#666666"
|
|
||||||
borderopacity="1.0"
|
|
||||||
inkscape:pageopacity="0.0"
|
|
||||||
inkscape:pageshadow="2"
|
|
||||||
inkscape:zoom="0.5"
|
|
||||||
inkscape:cx="459.21448"
|
|
||||||
inkscape:cy="471.91176"
|
|
||||||
inkscape:document-units="px"
|
|
||||||
inkscape:current-layer="layer1"
|
|
||||||
showgrid="false"
|
|
||||||
showborder="true"
|
|
||||||
inkscape:window-width="906"
|
|
||||||
inkscape:window-height="719"
|
|
||||||
inkscape:window-x="1"
|
|
||||||
inkscape:window-y="24"
|
|
||||||
inkscape:window-maximized="0" />
|
|
||||||
<metadata
|
|
||||||
id="metadata7">
|
|
||||||
<rdf:RDF>
|
|
||||||
<cc:Work
|
|
||||||
rdf:about="">
|
|
||||||
<dc:format>image/svg+xml</dc:format>
|
|
||||||
<dc:type
|
|
||||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
|
||||||
<dc:title></dc:title>
|
|
||||||
</cc:Work>
|
|
||||||
</rdf:RDF>
|
|
||||||
</metadata>
|
|
||||||
<g
|
|
||||||
inkscape:label="Layer 1"
|
|
||||||
inkscape:groupmode="layer"
|
|
||||||
id="layer1">
|
|
||||||
<g
|
|
||||||
id="g4305"
|
|
||||||
style="fill:#164122;fill-opacity:1;stroke:none;stroke-opacity:1;stroke-width:0.10000000000000001;stroke-miterlimit:4;stroke-dasharray:none">
|
|
||||||
<g
|
|
||||||
transform="translate(-190,-14)"
|
|
||||||
id="g4236"
|
|
||||||
style="fill:#164122;fill-opacity:1;stroke:none;stroke-opacity:1;stroke-width:0.10000000000000001;stroke-miterlimit:4;stroke-dasharray:none">
|
|
||||||
<g
|
|
||||||
id="g4199"
|
|
||||||
transform="translate(186,0)"
|
|
||||||
style="fill:#164122;fill-opacity:1;stroke:none;stroke-opacity:1;stroke-width:0.10000000000000001;stroke-miterlimit:4;stroke-dasharray:none">
|
|
||||||
<path
|
|
||||||
style="fill-rule:evenodd;stroke:none;stroke-width:0.10000000000000001;fill:#164122;fill-opacity:1;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
|
||||||
d="M 245.5395,924.99188 237.95004,940.17081 274,915.50504 l -43.63943,1.89737 z"
|
|
||||||
id="path4205"
|
|
||||||
inkscape:connector-curvature="0"
|
|
||||||
sodipodi:nodetypes="ccccc" />
|
|
||||||
</g>
|
|
||||||
<path
|
|
||||||
style="font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:normal;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;baseline-shift:baseline;color:#000000;fill:#164122;fill-opacity:1;stroke:none;stroke-width:0.10000000000000001;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:Sans;-inkscape-font-specification:Sans;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
|
||||||
d="m 451.30156,863.09375 c -12.29154,0.67964 -24.56513,6.31983 -32.55093,15.74368 -6.74505,8.98414 -14.74647,19.18713 -13.27855,31.13292 0.81861,7.53179 4.96334,15.52377 12.3578,18.2841 6.5527,1.56145 12.36737,-2.87335 18.24105,-4.87414 2.46026,0.0325 7.79766,-5.57819 2.80659,-2.62717 -5.86212,3.04634 -12.09693,7.41598 -19.02815,6.20781 -6.67881,-2.45807 -10.67091,-9.57389 -11.94134,-16.2776 -1.65616,-6.85973 1.2677,-13.63117 5.02324,-19.23708 7.11677,-11.84162 18.63914,-21.98251 32.76069,-23.75581 14.13711,-2.23575 29.01952,1.81411 40.58636,10.08551 7.52021,5.28929 14.01916,12.81867 15.41858,22.18896 2.35212,12.95802 -5.71873,25.02827 -15.27391,32.93766 -9.57979,7.75126 -20.98736,12.8445 -32.4632,17.09918 -5.28833,-0.64073 -7.07207,5.94812 -4.23041,9.49281 0.54847,2.21012 1.09694,4.42025 1.64541,6.63037 18.79336,-6.7629 38.15989,-16.2698 49.24661,-33.6521 6.02058,-10.72278 10.41044,-23.35707 8.15467,-35.76217 -1.2356,-5.99366 -5.54747,-10.6846 -8.85242,-15.6466 -7.03785,-9.20338 -18.12594,-14.19792 -29.30714,-16.17859 -6.35088,-1.24159 -12.83528,-2.02773 -19.31495,-1.79174 z"
|
|
||||||
id="path4214"
|
|
||||||
inkscape:connector-curvature="0" />
|
|
||||||
</g>
|
|
||||||
<g
|
|
||||||
id="g4236-1"
|
|
||||||
transform="translate(-297.33681,-120.22628)"
|
|
||||||
style="fill:#164122;fill-opacity:1;stroke:none;stroke-opacity:1;stroke-width:0.10000000000000001;stroke-miterlimit:4;stroke-dasharray:none">
|
|
||||||
<g
|
|
||||||
id="g4199-2"
|
|
||||||
transform="translate(186,0)"
|
|
||||||
style="fill:#164122;fill-opacity:1;stroke:none;stroke-opacity:1;stroke-width:0.10000000000000001;stroke-miterlimit:4;stroke-dasharray:none">
|
|
||||||
<path
|
|
||||||
style="fill-rule:evenodd;stroke:none;stroke-width:0.10000000000000001;fill:#164122;fill-opacity:1;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
|
||||||
d="M 245.5395,924.99188 237.95004,940.17081 274,915.50504 l -43.63943,1.89737 z"
|
|
||||||
id="path4205-7"
|
|
||||||
inkscape:connector-curvature="0"
|
|
||||||
sodipodi:nodetypes="ccccc" />
|
|
||||||
</g>
|
|
||||||
<path
|
|
||||||
style="font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:normal;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;baseline-shift:baseline;color:#000000;fill:#164122;fill-opacity:1;stroke:none;stroke-width:0.10000000000000001;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:Sans;-inkscape-font-specification:Sans;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
|
||||||
d="m 451.30156,863.09375 c -12.29154,0.67964 -24.56513,6.31983 -32.55093,15.74368 -6.74505,8.98414 -14.74647,19.18713 -13.27855,31.13292 0.81861,7.53179 4.96334,15.52377 12.3578,18.2841 6.5527,1.56145 12.36737,-2.87335 18.24105,-4.87414 2.46026,0.0325 7.79766,-5.57819 2.80659,-2.62717 -5.86212,3.04634 -12.09693,7.41598 -19.02815,6.20781 -6.67881,-2.45807 -10.67091,-9.57389 -11.94134,-16.2776 -1.65616,-6.85973 1.2677,-13.63117 5.02324,-19.23708 7.11677,-11.84162 18.63914,-21.98251 32.76069,-23.75581 14.13711,-2.23575 29.01952,1.81411 40.58636,10.08551 7.52021,5.28929 14.01916,12.81867 15.41858,22.18896 2.35212,12.95802 -5.71873,25.02827 -15.27391,32.93766 -9.57979,7.75126 -20.98736,12.8445 -32.4632,17.09918 -5.28833,-0.64073 -7.07207,5.94812 -4.23041,9.49281 0.54847,2.21012 1.09694,4.42025 1.64541,6.63037 18.79336,-6.7629 38.15989,-16.2698 49.24661,-33.6521 6.02058,-10.72278 10.41044,-23.35707 8.15467,-35.76217 -1.2356,-5.99366 -5.54747,-10.6846 -8.85242,-15.6466 -7.03785,-9.20338 -18.12594,-14.19792 -29.30714,-16.17859 -6.35088,-1.24159 -12.83528,-2.02773 -19.31495,-1.79174 z"
|
|
||||||
id="path4214-1"
|
|
||||||
inkscape:connector-curvature="0" />
|
|
||||||
</g>
|
|
||||||
<g
|
|
||||||
id="g4236-8"
|
|
||||||
transform="translate(-321.33681,5.77372)"
|
|
||||||
style="fill:#164122;fill-opacity:1;stroke:none;stroke-opacity:1;stroke-width:0.10000000000000001;stroke-miterlimit:4;stroke-dasharray:none">
|
|
||||||
<g
|
|
||||||
id="g4199-5"
|
|
||||||
transform="translate(186,0)"
|
|
||||||
style="fill:#164122;fill-opacity:1;stroke:none;stroke-opacity:1;stroke-width:0.10000000000000001;stroke-miterlimit:4;stroke-dasharray:none">
|
|
||||||
<path
|
|
||||||
style="fill-rule:evenodd;stroke:none;stroke-width:0.10000000000000001;fill:#164122;fill-opacity:1;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
|
||||||
d="M 245.5395,924.99188 237.95004,940.17081 274,915.50504 l -43.63943,1.89737 z"
|
|
||||||
id="path4205-1"
|
|
||||||
inkscape:connector-curvature="0"
|
|
||||||
sodipodi:nodetypes="ccccc" />
|
|
||||||
</g>
|
|
||||||
<path
|
|
||||||
style="font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:normal;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;baseline-shift:baseline;color:#000000;fill:#164122;fill-opacity:1;stroke:none;stroke-width:0.10000000000000001;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:Sans;-inkscape-font-specification:Sans;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
|
||||||
d="m 451.30156,863.09375 c -12.29154,0.67964 -24.56513,6.31983 -32.55093,15.74368 -6.74505,8.98414 -14.74647,19.18713 -13.27855,31.13292 0.81861,7.53179 4.96334,15.52377 12.3578,18.2841 6.5527,1.56145 12.36737,-2.87335 18.24105,-4.87414 2.46026,0.0325 7.79766,-5.57819 2.80659,-2.62717 -5.86212,3.04634 -12.09693,7.41598 -19.02815,6.20781 -6.67881,-2.45807 -10.67091,-9.57389 -11.94134,-16.2776 -1.65616,-6.85973 1.2677,-13.63117 5.02324,-19.23708 7.11677,-11.84162 18.63914,-21.98251 32.76069,-23.75581 14.13711,-2.23575 29.01952,1.81411 40.58636,10.08551 7.52021,5.28929 14.01916,12.81867 15.41858,22.18896 2.35212,12.95802 -5.71873,25.02827 -15.27391,32.93766 -9.57979,7.75126 -20.98736,12.8445 -32.4632,17.09918 -5.28833,-0.64073 -7.07207,5.94812 -4.23041,9.49281 0.54847,2.21012 1.09694,4.42025 1.64541,6.63037 18.79336,-6.7629 38.15989,-16.2698 49.24661,-33.6521 6.02058,-10.72278 10.41044,-23.35707 8.15467,-35.76217 -1.2356,-5.99366 -5.54747,-10.6846 -8.85242,-15.6466 -7.03785,-9.20338 -18.12594,-14.19792 -29.30714,-16.17859 -6.35088,-1.24159 -12.83528,-2.02773 -19.31495,-1.79174 z"
|
|
||||||
id="path4214-3"
|
|
||||||
inkscape:connector-curvature="0" />
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
<g
|
|
||||||
id="g4301"
|
|
||||||
transform="translate(8,-22)">
|
|
||||||
<path
|
|
||||||
sodipodi:nodetypes="cccccc"
|
|
||||||
inkscape:connector-curvature="0"
|
|
||||||
id="path4281"
|
|
||||||
d="m 544,310.36218 -309,554 3,3 327,-545 -1,-14 z"
|
|
||||||
style="fill:#cd0000;fill-opacity:1;stroke:#000088;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
|
|
||||||
<path
|
|
||||||
sodipodi:nodetypes="cccccc"
|
|
||||||
inkscape:connector-curvature="0"
|
|
||||||
id="path4281-5"
|
|
||||||
d="m 478.99332,286.67888 -275.00872,571.63555 3.17555,2.81352 293.51899,-563.73807 -1.84294,-13.91415 z"
|
|
||||||
style="fill:#cd0000;fill-opacity:1;stroke:#000088;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
Before Width: | Height: | Size: 11 KiB |
@ -1,115 +0,0 @@
|
|||||||
/*
|
|
||||||
* ackbtn-stm32f103.c - Acknowledge button support for STM32F103
|
|
||||||
*
|
|
||||||
* Copyright (C) 2018 g10 Code GmbH
|
|
||||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
|
||||||
*
|
|
||||||
* This file is a part of Chopstx, a thread library for embedded.
|
|
||||||
*
|
|
||||||
* Chopstx is free software: you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Chopstx is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* As additional permission under GNU GPL version 3 section 7, you may
|
|
||||||
* distribute non-source form of the Program without the copy of the
|
|
||||||
* GNU GPL normally required by section 4, provided you inform the
|
|
||||||
* receipents of GNU GPL by a written offer.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <chopstx.h>
|
|
||||||
#include <mcu/stm32f103.h>
|
|
||||||
|
|
||||||
#include "board.h"
|
|
||||||
#include "sys.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* All EXTI registers (EXTI_IMR, EXTI_EMR, EXTI_PR , EXTI_RTSR, and
|
|
||||||
* EXTI_FTSR) have same structure, where each bit of X is used for
|
|
||||||
* line X, from 0 up to 19.
|
|
||||||
*
|
|
||||||
* We use 31-bit of PIN_CONFIG to represent if it's for rising edge or
|
|
||||||
* falling edge.
|
|
||||||
*/
|
|
||||||
static uint32_t pin_config;
|
|
||||||
#define PINCFG_EDGE 0x80000000
|
|
||||||
#define PINCFG_EDGE_RISING PINCFG_EDGE
|
|
||||||
|
|
||||||
void
|
|
||||||
ackbtn_init (chopstx_intr_t *intr)
|
|
||||||
{
|
|
||||||
uint8_t irq_num;
|
|
||||||
uint32_t afio_exticr_index;
|
|
||||||
uint32_t afio_exticr_extiX_pY;
|
|
||||||
|
|
||||||
switch (SYS_BOARD_ID)
|
|
||||||
{
|
|
||||||
case BOARD_ID_FST_01:
|
|
||||||
case BOARD_ID_FST_01G:
|
|
||||||
/* PA2 can be connected to a hall sensor or a switch */
|
|
||||||
afio_exticr_index = 0;
|
|
||||||
afio_exticr_extiX_pY = AFIO_EXTICR1_EXTI2_PA;
|
|
||||||
irq_num = EXTI2_IRQ;
|
|
||||||
pin_config = 0x0004; /* EXTI_PR_PR2 == EXTI_IMR_MR2 == EXTI_RTSR_TR2 */
|
|
||||||
pin_config |= PINCFG_EDGE_RISING;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BOARD_ID_FST_01SZ:
|
|
||||||
default:
|
|
||||||
/* PA3 is connected to a hall sensor DRV5032FA */
|
|
||||||
afio_exticr_index = 0;
|
|
||||||
afio_exticr_extiX_pY = AFIO_EXTICR1_EXTI3_PA;
|
|
||||||
irq_num = EXTI3_IRQ;
|
|
||||||
pin_config = 0x0008; /* EXTI_PR_PR3 == EXTI_IMR_MR3 == EXTI_RTSR_TR3 */
|
|
||||||
pin_config |= PINCFG_EDGE_RISING;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Configure EXTI line */
|
|
||||||
if (afio_exticr_extiX_pY)
|
|
||||||
AFIO->EXTICR[afio_exticr_index] |= afio_exticr_extiX_pY;
|
|
||||||
|
|
||||||
/* Interrupt is masked, now */
|
|
||||||
EXTI->IMR &= ~(pin_config & ~PINCFG_EDGE);
|
|
||||||
|
|
||||||
chopstx_claim_irq (intr, irq_num);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ackbtn_enable (void)
|
|
||||||
{
|
|
||||||
/* Clear pending interrupt */
|
|
||||||
EXTI->PR |= (pin_config & ~PINCFG_EDGE);
|
|
||||||
/* Enable interrupt, clearing the mask */
|
|
||||||
EXTI->IMR |= (pin_config & ~PINCFG_EDGE);
|
|
||||||
|
|
||||||
/* Configure which edge is detected */
|
|
||||||
if ((pin_config & PINCFG_EDGE))
|
|
||||||
EXTI->RTSR |= (pin_config & ~PINCFG_EDGE);
|
|
||||||
else
|
|
||||||
EXTI->FTSR |= (pin_config & ~PINCFG_EDGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ackbtn_disable (void)
|
|
||||||
{
|
|
||||||
/* Disable interrupt having the mask */
|
|
||||||
EXTI->IMR &= ~(pin_config & ~PINCFG_EDGE);
|
|
||||||
/* Clear pending interrupt */
|
|
||||||
EXTI->PR |= (pin_config & ~PINCFG_EDGE);
|
|
||||||
|
|
||||||
/* Disable edge detection */
|
|
||||||
EXTI->RTSR &= ~(pin_config & ~PINCFG_EDGE);
|
|
||||||
EXTI->FTSR &= ~(pin_config & ~PINCFG_EDGE);
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
void ackbtn_init (chopstx_intr_t *intr);
|
|
||||||
void ackbtn_enable (void);
|
|
||||||
void ackbtn_disable (void);
|
|
@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* adc-gnu-linux.c - ADC driver for GNU/Linux emulation.
|
|
||||||
* This ADC driver just fills pseudo random values.
|
|
||||||
* It's completely useless other than for NeuG.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2017 Free Software Initiative of Japan
|
|
||||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
|
||||||
*
|
|
||||||
* This file is a part of Chopstx, a thread library for embedded.
|
|
||||||
*
|
|
||||||
* Chopstx is free software: you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Chopstx is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* As additional permission under GNU GPL version 3 section 7, you may
|
|
||||||
* distribute non-source form of the Program without the copy of the
|
|
||||||
* GNU GPL normally required by section 4, provided you inform the
|
|
||||||
* receipents of GNU GPL by a written offer.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <chopstx.h>
|
|
||||||
#include "adc.h"
|
|
||||||
|
|
||||||
#define ADC_RANDOM_SEED 0x01034649 /* "Hello, father!" in Japanese */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Do calibration for ADC.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
adc_init (void)
|
|
||||||
{
|
|
||||||
srandom (ADC_RANDOM_SEED);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
adc_start (void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t adc_buf[64];
|
|
||||||
|
|
||||||
void
|
|
||||||
adc_start_conversion (int offset, int count)
|
|
||||||
{
|
|
||||||
while (count--)
|
|
||||||
adc_buf[offset++] = random ();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
adc_stop (void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Return 0 on success.
|
|
||||||
* Return 1 on error.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
adc_wait_completion (void)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,322 +0,0 @@
|
|||||||
/*
|
|
||||||
* adc-mkl27z.c - ADC driver for MKL27Z
|
|
||||||
* In this ADC driver, there are NeuG specific parts.
|
|
||||||
* It only records lower 8-bit of 16-bit data.
|
|
||||||
* You need to modify to use this as generic ADC driver.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2016 Flying Stone Technology
|
|
||||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
|
||||||
*
|
|
||||||
* This file is a part of Chopstx, a thread library for embedded.
|
|
||||||
*
|
|
||||||
* Chopstx is free software: you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Chopstx is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* As additional permission under GNU GPL version 3 section 7, you may
|
|
||||||
* distribute non-source form of the Program without the copy of the
|
|
||||||
* GNU GPL normally required by section 4, provided you inform the
|
|
||||||
* receipents of GNU GPL by a written offer.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <chopstx.h>
|
|
||||||
#include <mcu/mkl27z.h>
|
|
||||||
|
|
||||||
struct DMAMUX {
|
|
||||||
volatile uint32_t CHCFG0;
|
|
||||||
volatile uint32_t CHCFG1;
|
|
||||||
volatile uint32_t CHCFG2;
|
|
||||||
volatile uint32_t CHCFG3;
|
|
||||||
};
|
|
||||||
static struct DMAMUX *const DMAMUX = (struct DMAMUX *)0x40021000;
|
|
||||||
|
|
||||||
#define INTR_REQ_DMA0 0
|
|
||||||
|
|
||||||
struct DMA {
|
|
||||||
volatile uint32_t SAR;
|
|
||||||
volatile uint32_t DAR;
|
|
||||||
volatile uint32_t DSR_BCR;
|
|
||||||
volatile uint32_t DCR;
|
|
||||||
};
|
|
||||||
static struct DMA *const DMA0 = (struct DMA *)0x40008100;
|
|
||||||
static struct DMA *const DMA1 = (struct DMA *)0x40008110;
|
|
||||||
|
|
||||||
|
|
||||||
/* We don't use ADC interrupt. Just for reference. */
|
|
||||||
#define INTR_REQ_ADC 15
|
|
||||||
|
|
||||||
struct ADC {
|
|
||||||
volatile uint32_t SC1[2];/* Status and Control Registers 1 */
|
|
||||||
volatile uint32_t CFG1; /* Configuration Register 1 */
|
|
||||||
volatile uint32_t CFG2; /* Configuration Register 2 */
|
|
||||||
volatile uint32_t R[2]; /* Data Result Register */
|
|
||||||
|
|
||||||
/* Compare Value Registers 1, 2 */
|
|
||||||
volatile uint32_t CV1;
|
|
||||||
volatile uint32_t CV2;
|
|
||||||
|
|
||||||
volatile uint32_t SC2; /* Status and Control Register 2 */
|
|
||||||
volatile uint32_t SC3; /* Status and Control Register 3 */
|
|
||||||
|
|
||||||
volatile uint32_t OFS; /* Offset Correction Register */
|
|
||||||
volatile uint32_t PG; /* Plus-Side Gain Register */
|
|
||||||
volatile uint32_t MG; /* Minus-Side Gain Register */
|
|
||||||
|
|
||||||
/* Plus-Side General Calibration Value Registers */
|
|
||||||
volatile uint32_t CLPD;
|
|
||||||
volatile uint32_t CLPS;
|
|
||||||
volatile uint32_t CLP4;
|
|
||||||
volatile uint32_t CLP3;
|
|
||||||
volatile uint32_t CLP2;
|
|
||||||
volatile uint32_t CLP1;
|
|
||||||
volatile uint32_t CLP0;
|
|
||||||
uint32_t rsvd0;
|
|
||||||
/* Minus-Side General Calibration Value Registers */
|
|
||||||
volatile uint32_t CLMD;
|
|
||||||
volatile uint32_t CLMS;
|
|
||||||
volatile uint32_t CLM4;
|
|
||||||
volatile uint32_t CLM3;
|
|
||||||
volatile uint32_t CLM2;
|
|
||||||
volatile uint32_t CLM1;
|
|
||||||
volatile uint32_t CLM0;
|
|
||||||
};
|
|
||||||
static struct ADC *const ADC0 = (struct ADC *)0x4003B000;
|
|
||||||
|
|
||||||
/* SC1 */
|
|
||||||
#define ADC_SC1_DIFF (1 << 5)
|
|
||||||
#define ADC_SC1_AIEN (1 << 6)
|
|
||||||
#define ADC_SC1_COCO (1 << 7)
|
|
||||||
#define ADC_SC1_TEMPSENSOR 26
|
|
||||||
#define ADC_SC1_BANDGAP 27
|
|
||||||
#define ADC_SC1_ADCSTOP 31
|
|
||||||
|
|
||||||
/* CFG1 */
|
|
||||||
#define ADC_CLOCK_SOURCE_ASYNCH (3 << 0)
|
|
||||||
#define ADC_MODE_16BIT (3 << 2)
|
|
||||||
#define ADC_ADLSMP_SHORT (0 << 4)
|
|
||||||
#define ADC_ADLSMP_LONG (1 << 4)
|
|
||||||
#define ADC_ADIV_1 (0 << 5)
|
|
||||||
#define ADC_ADIV_8 (3 << 5)
|
|
||||||
#define ADC_ADLPC_NORMAL (0 << 7)
|
|
||||||
#define ADC_ADLPC_LOWPOWER (1 << 7)
|
|
||||||
/**/
|
|
||||||
#define ADC_CLOCK_SOURCE ADC_CLOCK_SOURCE_ASYNCH
|
|
||||||
#define ADC_MODE ADC_MODE_16BIT
|
|
||||||
#define ADC_ADLSMP ADC_ADLSMP_SHORT
|
|
||||||
#define ADC_ADIV ADC_ADIV_1
|
|
||||||
#define ADC_ADLPC ADC_ADLPC_LOWPOWER
|
|
||||||
|
|
||||||
/* CFG2 */
|
|
||||||
#define ADC_ADLSTS_DEFAULT 0 /* 24 cycles if CFG1.ADLSMP=1, 4 if not. */
|
|
||||||
#define ADC_ADHSC_NORMAL (0 << 2)
|
|
||||||
#define ADC_ADHSC_HIGHSPEED (1 << 2)
|
|
||||||
#define ADC_ADACK_DISABLE (0 << 3)
|
|
||||||
#define ADC_ADACK_ENABLE (1 << 3)
|
|
||||||
#define ADC_MUXSEL_A (0 << 4)
|
|
||||||
#define ADC_MUXSEL_B (1 << 4)
|
|
||||||
/**/
|
|
||||||
#define ADC_ADLSTS ADC_ADLSTS_DEFAULT
|
|
||||||
#define ADC_ADHSC ADC_ADHSC_NORMAL
|
|
||||||
#define ADC_ADACKEN ADC_ADACK_ENABLE
|
|
||||||
#define ADC_MUXSEL ADC_MUXSEL_A
|
|
||||||
|
|
||||||
/* SC2 */
|
|
||||||
#define ADC_SC2_REFSEL_DEFAULT 1 /* Internal Voltage Reference??? */
|
|
||||||
#define ADC_SC2_DMAEN (1 << 2)
|
|
||||||
#define ADC_SC2_ACREN (1 << 3)
|
|
||||||
#define ADC_SC2_ACFGT (1 << 4)
|
|
||||||
#define ADC_SC2_ACFE (1 << 5)
|
|
||||||
#define ADC_SC2_ADTRG (1 << 6) /* For hardware trigger */
|
|
||||||
|
|
||||||
/* SC3 */
|
|
||||||
#define ADC_SC3_AVGS11 0x03
|
|
||||||
#define ADC_SC3_AVGE (1 << 2)
|
|
||||||
#define ADC_SC3_ADCO (1 << 3)
|
|
||||||
#define ADC_SC3_CALF (1 << 6)
|
|
||||||
#define ADC_SC3_CAL (1 << 7)
|
|
||||||
|
|
||||||
#define ADC_DMA_SLOT_NUM 40
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Buffer to save ADC data.
|
|
||||||
*/
|
|
||||||
uint32_t adc_buf[64];
|
|
||||||
|
|
||||||
static const uint32_t adc0_sc1_setting = ADC_SC1_TEMPSENSOR;
|
|
||||||
|
|
||||||
static chopstx_intr_t adc_intr;
|
|
||||||
|
|
||||||
struct adc_internal {
|
|
||||||
uint32_t buf[64];
|
|
||||||
uint8_t *p;
|
|
||||||
int phase : 8;
|
|
||||||
int count : 8;
|
|
||||||
};
|
|
||||||
struct adc_internal adc;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Initialize ADC module, do calibration.
|
|
||||||
*
|
|
||||||
* This is called by MAIN, only once, hopefully before creating any
|
|
||||||
* other threads (to be accurate).
|
|
||||||
*
|
|
||||||
* We configure ADC0 to kick DMA0, configure DMA0 to kick DMA1.
|
|
||||||
* DMA0 records output of ADC0 to the ADC.BUF.
|
|
||||||
* DMA1 kicks ADC0 again to get another value.
|
|
||||||
*
|
|
||||||
* ADC0 --[finish conversion]--> DMA0 --[Link channel 1]--> DMA1
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
adc_init (void)
|
|
||||||
{
|
|
||||||
uint32_t v;
|
|
||||||
|
|
||||||
/* Enable ADC0 and DMAMUX clock. */
|
|
||||||
SIM->SCGC6 |= (1 << 27) | (1 << 1);
|
|
||||||
/* Enable DMA clock. */
|
|
||||||
SIM->SCGC7 |= (1 << 8);
|
|
||||||
|
|
||||||
/* ADC0 setting for calibration. */
|
|
||||||
ADC0->CFG1 = ADC_CLOCK_SOURCE | ADC_MODE | ADC_ADLSMP | ADC_ADIV | ADC_ADLPC;
|
|
||||||
ADC0->CFG2 = ADC_ADLSTS | ADC_ADHSC | ADC_ADACKEN | ADC_MUXSEL;
|
|
||||||
ADC0->SC2 = ADC_SC2_REFSEL_DEFAULT;
|
|
||||||
ADC0->SC3 = ADC_SC3_CAL | ADC_SC3_CALF | ADC_SC3_AVGE | ADC_SC3_AVGS11;
|
|
||||||
|
|
||||||
/* Wait ADC completion */
|
|
||||||
while ((ADC0->SC1[0] & ADC_SC1_COCO) == 0)
|
|
||||||
if ((ADC0->SC3 & ADC_SC3_CALF) != 0)
|
|
||||||
/* Calibration failure */
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if ((ADC0->SC3 & ADC_SC3_CALF) != 0)
|
|
||||||
/* Calibration failure */
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/* Configure PG by the calibration values. */
|
|
||||||
v = ADC0->CLP0 + ADC0->CLP1 + ADC0->CLP2 + ADC0->CLP3 + ADC0->CLP4 + ADC0->CLPS;
|
|
||||||
ADC0->PG = 0x8000 | (v >> 1);
|
|
||||||
|
|
||||||
/* Configure MG by the calibration values. */
|
|
||||||
v = ADC0->CLM0 + ADC0->CLM1 + ADC0->CLM2 + ADC0->CLM3 + ADC0->CLM4 + ADC0->CLMS;
|
|
||||||
ADC0->MG = 0x8000 | (v >> 1);
|
|
||||||
|
|
||||||
ADC0->SC1[0] = ADC_SC1_ADCSTOP;
|
|
||||||
|
|
||||||
/* DMAMUX setting. */
|
|
||||||
DMAMUX->CHCFG0 = (1 << 7) | ADC_DMA_SLOT_NUM;
|
|
||||||
|
|
||||||
/* DMA0 initial setting. */
|
|
||||||
DMA0->SAR = (uint32_t)&ADC0->R[0];
|
|
||||||
|
|
||||||
/* DMA1 initial setting. */
|
|
||||||
DMA1->SAR = (uint32_t)&adc0_sc1_setting;
|
|
||||||
DMA1->DAR = (uint32_t)&ADC0->SC1[0];
|
|
||||||
|
|
||||||
chopstx_claim_irq (&adc_intr, INTR_REQ_DMA0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Start using ADC.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
adc_start (void)
|
|
||||||
{
|
|
||||||
ADC0->CFG1 = ADC_CLOCK_SOURCE | ADC_MODE | ADC_ADLSMP | ADC_ADIV | ADC_ADLPC;
|
|
||||||
ADC0->CFG2 = ADC_ADLSTS | ADC_ADHSC | ADC_ADACKEN | ADC_MUXSEL;
|
|
||||||
ADC0->SC2 = ADC_SC2_REFSEL_DEFAULT | ADC_SC2_DMAEN;
|
|
||||||
ADC0->SC3 = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Kick getting data for COUNT times.
|
|
||||||
* Data will be saved in ADC_BUF starting at OFFSET.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
adc_start_conversion_internal (int count)
|
|
||||||
{
|
|
||||||
/* DMA0 setting. */
|
|
||||||
DMA0->DAR = (uint32_t)&adc.buf[0];
|
|
||||||
DMA0->DSR_BCR = 4 * count;
|
|
||||||
DMA0->DCR = (1 << 31) | (1 << 30) | (1 << 29) | (0 << 20) | (1 << 19)
|
|
||||||
| (0 << 17) | (1 << 7) | (2 << 4) | (1 << 2);
|
|
||||||
|
|
||||||
/* Kick DMA1. */
|
|
||||||
DMA1->DSR_BCR = 4 * count;
|
|
||||||
DMA1->DCR = (1 << 30) | (1 << 29) | (0 << 19) | (0 << 17) | (1 << 16) | (1 << 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Kick getting data for COUNT times.
|
|
||||||
* Data will be saved in ADC_BUF starting at OFFSET.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
adc_start_conversion (int offset, int count)
|
|
||||||
{
|
|
||||||
adc.p = (uint8_t *)&adc_buf[offset];
|
|
||||||
adc.phase = 0;
|
|
||||||
adc.count = count;
|
|
||||||
adc_start_conversion_internal (count);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
adc_stop_conversion (void)
|
|
||||||
{
|
|
||||||
ADC0->SC1[0] = ADC_SC1_ADCSTOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Stop using ADC.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
adc_stop (void)
|
|
||||||
{
|
|
||||||
SIM->SCGC6 &= ~(1 << 27);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Return 0 on success.
|
|
||||||
* Return 1 on error.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
adc_wait_completion (void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
/* Wait DMA completion */
|
|
||||||
chopstx_intr_wait (&adc_intr);
|
|
||||||
|
|
||||||
DMA0->DSR_BCR = (1 << 24);
|
|
||||||
DMA1->DSR_BCR = (1 << 24);
|
|
||||||
|
|
||||||
adc_stop_conversion ();
|
|
||||||
|
|
||||||
chopstx_intr_done (&adc_intr);
|
|
||||||
|
|
||||||
for (i = 0; i < adc.count; i++)
|
|
||||||
*adc.p++ = (uint8_t)adc.buf[i];
|
|
||||||
|
|
||||||
if (++adc.phase >= 4)
|
|
||||||
break;
|
|
||||||
|
|
||||||
adc_start_conversion_internal (adc.count);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,347 +0,0 @@
|
|||||||
/*
|
|
||||||
* adc_stm32f103.c - ADC driver for STM32F103
|
|
||||||
* In this ADC driver, there are NeuG specific parts.
|
|
||||||
* You need to modify to use this as generic ADC driver.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2011, 2012, 2013, 2015, 2016, 2017, 2018
|
|
||||||
* Free Software Initiative of Japan
|
|
||||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
|
||||||
*
|
|
||||||
* This file is a part of Chopstx, a thread library for embedded.
|
|
||||||
*
|
|
||||||
* Chopstx is free software: you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Chopstx is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* As additional permission under GNU GPL version 3 section 7, you may
|
|
||||||
* distribute non-source form of the Program without the copy of the
|
|
||||||
* GNU GPL normally required by section 4, provided you inform the
|
|
||||||
* receipents of GNU GPL by a written offer.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <chopstx.h>
|
|
||||||
#include <mcu/stm32f103.h>
|
|
||||||
#include "adc.h"
|
|
||||||
#include "board.h"
|
|
||||||
#include "sys.h"
|
|
||||||
|
|
||||||
#define STM32_ADC_ADC1_DMA_PRIORITY 2
|
|
||||||
|
|
||||||
#define ADC_SMPR1_SMP_VREF(n) ((n) << 21)
|
|
||||||
#define ADC_SMPR1_SMP_SENSOR(n) ((n) << 18)
|
|
||||||
|
|
||||||
#define ADC_SMPR1_SMP_AN10(n) ((n) << 0)
|
|
||||||
#define ADC_SMPR1_SMP_AN11(n) ((n) << 3)
|
|
||||||
|
|
||||||
#define ADC_SMPR2_SMP_AN0(n) ((n) << 0)
|
|
||||||
#define ADC_SMPR2_SMP_AN1(n) ((n) << 3)
|
|
||||||
#define ADC_SMPR2_SMP_AN2(n) ((n) << 6)
|
|
||||||
#define ADC_SMPR2_SMP_AN8(n) ((n) << 24)
|
|
||||||
#define ADC_SMPR2_SMP_AN9(n) ((n) << 27)
|
|
||||||
|
|
||||||
#define ADC_SQR1_NUM_CH(n) (((n) - 1) << 20)
|
|
||||||
|
|
||||||
#define ADC_SQR3_SQ1_N(n) ((n) << 0)
|
|
||||||
#define ADC_SQR3_SQ2_N(n) ((n) << 5)
|
|
||||||
#define ADC_SQR3_SQ3_N(n) ((n) << 10)
|
|
||||||
#define ADC_SQR3_SQ4_N(n) ((n) << 15)
|
|
||||||
|
|
||||||
#define ADC_SAMPLE_1P5 0
|
|
||||||
|
|
||||||
#define ADC_CHANNEL_IN0 0
|
|
||||||
#define ADC_CHANNEL_IN1 1
|
|
||||||
#define ADC_CHANNEL_IN2 2
|
|
||||||
#define ADC_CHANNEL_IN8 8
|
|
||||||
#define ADC_CHANNEL_IN9 9
|
|
||||||
#define ADC_CHANNEL_IN10 10
|
|
||||||
#define ADC_CHANNEL_IN11 11
|
|
||||||
#define ADC_CHANNEL_SENSOR 16
|
|
||||||
#define ADC_CHANNEL_VREFINT 17
|
|
||||||
|
|
||||||
#define DELIBARATELY_DO_IT_WRONG_VREF_SAMPLE_TIME
|
|
||||||
#ifndef MCU_STM32F1_GD32F1
|
|
||||||
#define DELIBARATELY_DO_IT_WRONG_START_STOP
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DELIBARATELY_DO_IT_WRONG_VREF_SAMPLE_TIME
|
|
||||||
#define ADC_SAMPLE_VREF ADC_SAMPLE_1P5
|
|
||||||
#define ADC_SAMPLE_SENSOR ADC_SAMPLE_1P5
|
|
||||||
#else
|
|
||||||
#define ADC_SAMPLE_VREF ADC_SAMPLE_239P5
|
|
||||||
#define ADC_SAMPLE_SENSOR ADC_SAMPLE_239P5
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define NEUG_DMA_CHANNEL STM32_DMA1_STREAM1
|
|
||||||
#define NEUG_DMA_MODE \
|
|
||||||
( STM32_DMA_CR_PL (STM32_ADC_ADC1_DMA_PRIORITY) \
|
|
||||||
| STM32_DMA_CR_MSIZE_WORD | STM32_DMA_CR_PSIZE_WORD \
|
|
||||||
| STM32_DMA_CR_MINC | STM32_DMA_CR_TCIE \
|
|
||||||
| STM32_DMA_CR_TEIE )
|
|
||||||
|
|
||||||
#define NEUG_ADC_SETTING1_SMPR1 ADC_SMPR1_SMP_VREF(ADC_SAMPLE_VREF) \
|
|
||||||
| ADC_SMPR1_SMP_SENSOR(ADC_SAMPLE_SENSOR)
|
|
||||||
#define NEUG_ADC_SETTING1_SMPR2 0
|
|
||||||
#define NEUG_ADC_SETTING1_SQR3 ADC_SQR3_SQ1_N(ADC_CHANNEL_VREFINT) \
|
|
||||||
| ADC_SQR3_SQ2_N(ADC_CHANNEL_SENSOR) \
|
|
||||||
| ADC_SQR3_SQ3_N(ADC_CHANNEL_SENSOR) \
|
|
||||||
| ADC_SQR3_SQ4_N(ADC_CHANNEL_VREFINT)
|
|
||||||
#define NEUG_ADC_SETTING1_NUM_CHANNELS 4
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ADC finish interrupt
|
|
||||||
*/
|
|
||||||
#define INTR_REQ_DMA1_Channel1 11
|
|
||||||
|
|
||||||
static chopstx_intr_t adc_intr;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Do calibration for both of ADCs.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
adc_init (void)
|
|
||||||
{
|
|
||||||
RCC->APB2ENR |= (RCC_APB2ENR_ADC1EN | RCC_APB2ENR_ADC2EN);
|
|
||||||
RCC->APB2RSTR = (RCC_APB2RSTR_ADC1RST | RCC_APB2RSTR_ADC2RST);
|
|
||||||
RCC->APB2RSTR = 0;
|
|
||||||
|
|
||||||
ADC1->CR1 = 0;
|
|
||||||
ADC1->CR2 = ADC_CR2_ADON;
|
|
||||||
chopstx_usec_wait (1000);
|
|
||||||
|
|
||||||
ADC1->CR2 = ADC_CR2_ADON | ADC_CR2_RSTCAL;
|
|
||||||
while ((ADC1->CR2 & ADC_CR2_RSTCAL) != 0)
|
|
||||||
;
|
|
||||||
ADC1->CR2 = ADC_CR2_ADON | ADC_CR2_CAL;
|
|
||||||
while ((ADC1->CR2 & ADC_CR2_CAL) != 0)
|
|
||||||
;
|
|
||||||
ADC1->CR2 = 0;
|
|
||||||
|
|
||||||
ADC2->CR1 = 0;
|
|
||||||
ADC2->CR2 = ADC_CR2_ADON;
|
|
||||||
chopstx_usec_wait (1000);
|
|
||||||
|
|
||||||
ADC2->CR2 = ADC_CR2_ADON | ADC_CR2_RSTCAL;
|
|
||||||
while ((ADC2->CR2 & ADC_CR2_RSTCAL) != 0)
|
|
||||||
;
|
|
||||||
ADC2->CR2 = ADC_CR2_ADON | ADC_CR2_CAL;
|
|
||||||
while ((ADC2->CR2 & ADC_CR2_CAL) != 0)
|
|
||||||
;
|
|
||||||
ADC2->CR2 = 0;
|
|
||||||
RCC->APB2ENR &= ~(RCC_APB2ENR_ADC1EN | RCC_APB2ENR_ADC2EN);
|
|
||||||
|
|
||||||
chopstx_claim_irq (&adc_intr, INTR_REQ_DMA1_Channel1);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
get_adc_config (uint32_t config[4])
|
|
||||||
{
|
|
||||||
config[2] = ADC_SQR1_NUM_CH(2);
|
|
||||||
switch (SYS_BOARD_ID)
|
|
||||||
{
|
|
||||||
case BOARD_ID_FST_01G:
|
|
||||||
case BOARD_ID_FST_01:
|
|
||||||
config[0] = 0;
|
|
||||||
config[1] = ADC_SMPR2_SMP_AN0(ADC_SAMPLE_1P5)
|
|
||||||
| ADC_SMPR2_SMP_AN9(ADC_SAMPLE_1P5);
|
|
||||||
config[3] = ADC_SQR3_SQ1_N(ADC_CHANNEL_IN0)
|
|
||||||
| ADC_SQR3_SQ2_N(ADC_CHANNEL_IN9);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BOARD_ID_OLIMEX_STM32_H103:
|
|
||||||
case BOARD_ID_STBEE:
|
|
||||||
config[0] = ADC_SMPR1_SMP_AN10(ADC_SAMPLE_1P5)
|
|
||||||
| ADC_SMPR1_SMP_AN11(ADC_SAMPLE_1P5);
|
|
||||||
config[1] = 0;
|
|
||||||
config[3] = ADC_SQR3_SQ1_N(ADC_CHANNEL_IN10)
|
|
||||||
| ADC_SQR3_SQ2_N(ADC_CHANNEL_IN11);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BOARD_ID_STBEE_MINI:
|
|
||||||
config[0] = 0;
|
|
||||||
config[1] = ADC_SMPR2_SMP_AN1(ADC_SAMPLE_1P5)
|
|
||||||
| ADC_SMPR2_SMP_AN2(ADC_SAMPLE_1P5);
|
|
||||||
config[3] = ADC_SQR3_SQ1_N(ADC_CHANNEL_IN1)
|
|
||||||
| ADC_SQR3_SQ2_N(ADC_CHANNEL_IN2);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BOARD_ID_ST_NUCLEO_F103:
|
|
||||||
config[0] = 0;
|
|
||||||
config[1] = ADC_SMPR2_SMP_AN8(ADC_SAMPLE_1P5)
|
|
||||||
| ADC_SMPR2_SMP_AN9(ADC_SAMPLE_1P5);
|
|
||||||
config[3] = ADC_SQR3_SQ1_N(ADC_CHANNEL_IN8)
|
|
||||||
| ADC_SQR3_SQ2_N(ADC_CHANNEL_IN9);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BOARD_ID_CQ_STARM:
|
|
||||||
case BOARD_ID_FST_01_00:
|
|
||||||
case BOARD_ID_MAPLE_MINI:
|
|
||||||
case BOARD_ID_STM32_PRIMER2:
|
|
||||||
case BOARD_ID_STM8S_DISCOVERY:
|
|
||||||
case BOARD_ID_ST_DONGLE:
|
|
||||||
case BOARD_ID_NITROKEY_START:
|
|
||||||
case BOARD_ID_FST_01SZ:
|
|
||||||
default:
|
|
||||||
config[0] = 0;
|
|
||||||
config[1] = ADC_SMPR2_SMP_AN0(ADC_SAMPLE_1P5)
|
|
||||||
| ADC_SMPR2_SMP_AN1(ADC_SAMPLE_1P5);
|
|
||||||
config[3] = ADC_SQR3_SQ1_N(ADC_CHANNEL_IN0)
|
|
||||||
| ADC_SQR3_SQ2_N(ADC_CHANNEL_IN1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
adc_start (void)
|
|
||||||
{
|
|
||||||
uint32_t config[4];
|
|
||||||
|
|
||||||
get_adc_config (config);
|
|
||||||
|
|
||||||
/* Use DMA channel 1. */
|
|
||||||
RCC->AHBENR |= RCC_AHBENR_DMA1EN;
|
|
||||||
DMA1_Channel1->CCR = STM32_DMA_CCR_RESET_VALUE;
|
|
||||||
DMA1->IFCR = 0xffffffff;
|
|
||||||
|
|
||||||
RCC->APB2ENR |= (RCC_APB2ENR_ADC1EN | RCC_APB2ENR_ADC2EN);
|
|
||||||
|
|
||||||
ADC1->SMPR1 = NEUG_ADC_SETTING1_SMPR1;
|
|
||||||
ADC1->SMPR2 = NEUG_ADC_SETTING1_SMPR2;
|
|
||||||
ADC1->SQR1 = ADC_SQR1_NUM_CH(NEUG_ADC_SETTING1_NUM_CHANNELS);
|
|
||||||
ADC1->SQR2 = 0;
|
|
||||||
ADC1->SQR3 = NEUG_ADC_SETTING1_SQR3;
|
|
||||||
ADC1->CR1 = (ADC_CR1_DUALMOD_2 | ADC_CR1_DUALMOD_1 | ADC_CR1_DUALMOD_0
|
|
||||||
| ADC_CR1_SCAN);
|
|
||||||
ADC1->CR2 = (ADC_CR2_TSVREFE | ADC_CR2_EXTTRIG | ADC_CR2_SWSTART
|
|
||||||
| ADC_CR2_EXTSEL | ADC_CR2_DMA | ADC_CR2_CONT | ADC_CR2_ADON);
|
|
||||||
chopstx_usec_wait (1000);
|
|
||||||
|
|
||||||
ADC2->SMPR1 = config[0];
|
|
||||||
ADC2->SMPR2 = config[1];
|
|
||||||
ADC2->SQR1 = config[2];
|
|
||||||
ADC2->SQR2 = 0;
|
|
||||||
ADC2->SQR3 = config[3];
|
|
||||||
ADC2->CR1 = (ADC_CR1_DUALMOD_2 | ADC_CR1_DUALMOD_1 | ADC_CR1_DUALMOD_0
|
|
||||||
| ADC_CR1_SCAN);
|
|
||||||
ADC2->CR2 = ADC_CR2_EXTTRIG | ADC_CR2_CONT | ADC_CR2_ADON;
|
|
||||||
chopstx_usec_wait (1000);
|
|
||||||
|
|
||||||
#ifdef DELIBARATELY_DO_IT_WRONG_START_STOP
|
|
||||||
/*
|
|
||||||
* We could just let ADC run continuously always and only enable DMA
|
|
||||||
* to receive stable data from ADC. But our purpose is not to get
|
|
||||||
* correct data but noise. In fact, we can get more noise when we
|
|
||||||
* start/stop ADC each time.
|
|
||||||
*/
|
|
||||||
ADC2->CR2 = 0;
|
|
||||||
ADC1->CR2 = 0;
|
|
||||||
#else
|
|
||||||
/* Start conversion. */
|
|
||||||
ADC2->CR2 = ADC_CR2_EXTTRIG | ADC_CR2_CONT | ADC_CR2_ADON;
|
|
||||||
ADC1->CR2 = (ADC_CR2_TSVREFE | ADC_CR2_EXTTRIG | ADC_CR2_SWSTART
|
|
||||||
| ADC_CR2_EXTSEL | ADC_CR2_DMA | ADC_CR2_CONT | ADC_CR2_ADON);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t adc_buf[64];
|
|
||||||
|
|
||||||
void
|
|
||||||
adc_start_conversion (int offset, int count)
|
|
||||||
{
|
|
||||||
DMA1_Channel1->CPAR = (uint32_t)&ADC1->DR; /* SetPeripheral */
|
|
||||||
DMA1_Channel1->CMAR = (uint32_t)&adc_buf[offset]; /* SetMemory0 */
|
|
||||||
DMA1_Channel1->CNDTR = count; /* Counter */
|
|
||||||
DMA1_Channel1->CCR = NEUG_DMA_MODE | DMA_CCR1_EN; /* Mode */
|
|
||||||
|
|
||||||
#ifdef DELIBARATELY_DO_IT_WRONG_START_STOP
|
|
||||||
/* Power on */
|
|
||||||
ADC2->CR2 = ADC_CR2_EXTTRIG | ADC_CR2_CONT | ADC_CR2_ADON;
|
|
||||||
ADC1->CR2 = (ADC_CR2_TSVREFE | ADC_CR2_EXTTRIG | ADC_CR2_SWSTART
|
|
||||||
| ADC_CR2_EXTSEL | ADC_CR2_DMA | ADC_CR2_CONT | ADC_CR2_ADON);
|
|
||||||
/*
|
|
||||||
* Start conversion. tSTAB is 1uS, but we don't follow the spec, to
|
|
||||||
* get more noise.
|
|
||||||
*/
|
|
||||||
ADC2->CR2 = ADC_CR2_EXTTRIG | ADC_CR2_CONT | ADC_CR2_ADON;
|
|
||||||
ADC1->CR2 = (ADC_CR2_TSVREFE | ADC_CR2_EXTTRIG | ADC_CR2_SWSTART
|
|
||||||
| ADC_CR2_EXTSEL | ADC_CR2_DMA | ADC_CR2_CONT | ADC_CR2_ADON);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void adc_stop_conversion (void)
|
|
||||||
{
|
|
||||||
DMA1_Channel1->CCR &= ~DMA_CCR1_EN;
|
|
||||||
|
|
||||||
#ifdef DELIBARATELY_DO_IT_WRONG_START_STOP
|
|
||||||
ADC2->CR2 = 0;
|
|
||||||
ADC1->CR2 = 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
adc_stop (void)
|
|
||||||
{
|
|
||||||
ADC1->CR1 = 0;
|
|
||||||
ADC1->CR2 = 0;
|
|
||||||
|
|
||||||
ADC2->CR1 = 0;
|
|
||||||
ADC2->CR2 = 0;
|
|
||||||
|
|
||||||
RCC->AHBENR &= ~RCC_AHBENR_DMA1EN;
|
|
||||||
RCC->APB2ENR &= ~(RCC_APB2ENR_ADC1EN | RCC_APB2ENR_ADC2EN);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static uint32_t adc_err;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Return 0 on success.
|
|
||||||
* Return 1 on error.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
adc_wait_completion (void)
|
|
||||||
{
|
|
||||||
uint32_t flags;
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
chopstx_intr_wait (&adc_intr);
|
|
||||||
flags = DMA1->ISR & STM32_DMA_ISR_MASK; /* Channel 1 interrupt cause. */
|
|
||||||
/*
|
|
||||||
* Clear interrupt cause of channel 1.
|
|
||||||
*
|
|
||||||
* Note that CGIFx=0, as CGIFx=1 clears all of GIF, HTIF, TCIF
|
|
||||||
* and TEIF.
|
|
||||||
*/
|
|
||||||
DMA1->IFCR = (flags & ~1);
|
|
||||||
chopstx_intr_done (&adc_intr);
|
|
||||||
|
|
||||||
if ((flags & STM32_DMA_ISR_TEIF) != 0) /* DMA errors */
|
|
||||||
{
|
|
||||||
/* Should never happened. If any, it's coding error. */
|
|
||||||
/* Access an unmapped address space or alignment violation. */
|
|
||||||
adc_err++;
|
|
||||||
adc_stop_conversion ();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else if ((flags & STM32_DMA_ISR_TCIF) != 0) /* Transfer complete */
|
|
||||||
{
|
|
||||||
adc_stop_conversion ();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,656 +0,0 @@
|
|||||||
/*
|
|
||||||
* usart-stm32.c - USART driver for STM32F103 (USART2 and USART3)
|
|
||||||
*
|
|
||||||
* Copyright (C) 2017, 2019 g10 Code GmbH
|
|
||||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
|
||||||
*
|
|
||||||
* This file is a part of Chopstx, a thread library for embedded.
|
|
||||||
*
|
|
||||||
* Chopstx is free software: you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Chopstx is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* As additional permission under GNU GPL version 3 section 7, you may
|
|
||||||
* distribute non-source form of the Program without the copy of the
|
|
||||||
* GNU GPL normally required by section 4, provided you inform the
|
|
||||||
* receipents of GNU GPL by a written offer.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <chopstx.h>
|
|
||||||
#include <mcu/stm32.h>
|
|
||||||
#include <contrib/usart.h>
|
|
||||||
|
|
||||||
struct USART {
|
|
||||||
volatile uint32_t SR;
|
|
||||||
volatile uint32_t DR;
|
|
||||||
volatile uint32_t BRR;
|
|
||||||
volatile uint32_t CR1;
|
|
||||||
volatile uint32_t CR2;
|
|
||||||
volatile uint32_t CR3;
|
|
||||||
volatile uint32_t GTPR;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define USART2_BASE (APB1PERIPH_BASE + 0x4400)
|
|
||||||
#define USART3_BASE (APB1PERIPH_BASE + 0x4800)
|
|
||||||
static struct USART *const USART2 = (struct USART *)USART2_BASE;
|
|
||||||
static struct USART *const USART3 = (struct USART *)USART3_BASE;
|
|
||||||
|
|
||||||
#define USART_SR_CTS (1 << 9)
|
|
||||||
#define USART_SR_LBD (1 << 8)
|
|
||||||
#define USART_SR_TXE (1 << 7)
|
|
||||||
#define USART_SR_TC (1 << 6)
|
|
||||||
#define USART_SR_RXNE (1 << 5)
|
|
||||||
#define USART_SR_IDLE (1 << 4)
|
|
||||||
#define USART_SR_ORE (1 << 3)
|
|
||||||
#define USART_SR_NE (1 << 2)
|
|
||||||
#define USART_SR_FE (1 << 1)
|
|
||||||
#define USART_SR_PE (1 << 0)
|
|
||||||
|
|
||||||
|
|
||||||
#define USART_CR1_UE (1 << 13)
|
|
||||||
#define USART_CR1_M (1 << 12)
|
|
||||||
#define USART_CR1_WAKE (1 << 11)
|
|
||||||
#define USART_CR1_PCE (1 << 10)
|
|
||||||
#define USART_CR1_PS (1 << 9)
|
|
||||||
#define USART_CR1_PEIE (1 << 8)
|
|
||||||
#define USART_CR1_TXEIE (1 << 7)
|
|
||||||
#define USART_CR1_TCIE (1 << 6)
|
|
||||||
#define USART_CR1_RXNEIE (1 << 5)
|
|
||||||
#define USART_CR1_IDLEIE (1 << 4)
|
|
||||||
#define USART_CR1_TE (1 << 3)
|
|
||||||
#define USART_CR1_RE (1 << 2)
|
|
||||||
#define USART_CR1_RWU (1 << 1)
|
|
||||||
#define USART_CR1_SBK (1 << 0)
|
|
||||||
|
|
||||||
|
|
||||||
static struct USART *
|
|
||||||
get_usart_dev (uint8_t dev_no)
|
|
||||||
{
|
|
||||||
if (dev_no == 2)
|
|
||||||
return USART2;
|
|
||||||
else if (dev_no == 3)
|
|
||||||
return USART3;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We assume 36MHz f_PCLK */
|
|
||||||
struct brr_setting {
|
|
||||||
uint8_t baud_spec;
|
|
||||||
uint16_t brr_value;
|
|
||||||
};
|
|
||||||
#define NUM_BAUD (int)(sizeof (brr_table) / sizeof (struct brr_setting))
|
|
||||||
|
|
||||||
static const struct brr_setting brr_table[] = {
|
|
||||||
{ B600, (3750 << 4)},
|
|
||||||
{ B1200, (1875 << 4)},
|
|
||||||
{ B2400, ( 937 << 4)|8},
|
|
||||||
{ B9600, ( 234 << 4)|6},
|
|
||||||
{ B19200, ( 117 << 4)|3},
|
|
||||||
{ B57600, ( 39 << 4)|1},
|
|
||||||
{ B115200, ( 19 << 4)|8},
|
|
||||||
{ B230400, ( 9 << 4)|12},
|
|
||||||
{ B460800, ( 4 << 4)|14},
|
|
||||||
{ B921600, ( 2 << 4)|7},
|
|
||||||
{ BSCARD, ( 232 << 4)|8},
|
|
||||||
};
|
|
||||||
|
|
||||||
static void *usart_main (void *arg);
|
|
||||||
|
|
||||||
static struct usart_stat usart2_stat;
|
|
||||||
static struct usart_stat usart3_stat;
|
|
||||||
|
|
||||||
void
|
|
||||||
usart_config_clken (uint8_t dev_no, int on)
|
|
||||||
{
|
|
||||||
struct USART *USARTx = get_usart_dev (dev_no);
|
|
||||||
|
|
||||||
if (on)
|
|
||||||
USARTx->CR2 |= (1 << 11);
|
|
||||||
else
|
|
||||||
USARTx->CR2 &= ~(1 << 11);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
usart_config (uint8_t dev_no, uint32_t config_bits)
|
|
||||||
{
|
|
||||||
struct USART *USARTx = get_usart_dev (dev_no);
|
|
||||||
uint8_t baud_spec = (config_bits & MASK_BAUD);
|
|
||||||
int i;
|
|
||||||
uint32_t cr1_config = (USART_CR1_UE | USART_CR1_RXNEIE
|
|
||||||
| USART_CR1_TE | USART_CR1_RE);
|
|
||||||
/* TXEIE will be enabled when putting char */
|
|
||||||
/* No CTSIE, PEIE, TCIE, IDLEIE, LBDIE */
|
|
||||||
if (USARTx == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/* Disable USART before configure. */
|
|
||||||
USARTx->CR1 &= ~USART_CR1_UE;
|
|
||||||
|
|
||||||
if (((config_bits & MASK_CS) == CS7 && (config_bits & PARENB))
|
|
||||||
|| ((config_bits & MASK_CS) == CS8 && (config_bits & PARENB) == 0))
|
|
||||||
cr1_config &= ~USART_CR1_M;
|
|
||||||
else if ((config_bits & MASK_CS) == CS8)
|
|
||||||
cr1_config |= USART_CR1_M;
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if ((config_bits & PARENB) == 0)
|
|
||||||
cr1_config &= ~(USART_CR1_PCE | USART_CR1_PEIE);
|
|
||||||
else
|
|
||||||
cr1_config |= (USART_CR1_PCE | USART_CR1_PEIE);
|
|
||||||
|
|
||||||
if ((config_bits & PARODD) == 0)
|
|
||||||
cr1_config &= ~USART_CR1_PS;
|
|
||||||
else
|
|
||||||
cr1_config |= USART_CR1_PS;
|
|
||||||
|
|
||||||
if ((config_bits & MASK_STOP) == STOP0B5)
|
|
||||||
USARTx->CR2 = (0x1 << 12);
|
|
||||||
else if ((config_bits & MASK_STOP) == STOP1B)
|
|
||||||
USARTx->CR2 = (0x0 << 12);
|
|
||||||
else if ((config_bits & MASK_STOP) == STOP1B5)
|
|
||||||
USARTx->CR2 = (0x3 << 12);
|
|
||||||
else /* if ((config_bits & MASK_STOP) == STOP2B) */
|
|
||||||
USARTx->CR2 = (0x2 << 12);
|
|
||||||
|
|
||||||
for (i = 0; i < NUM_BAUD; i++)
|
|
||||||
if (brr_table[i].baud_spec == baud_spec)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (i >= NUM_BAUD)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
USARTx->BRR = brr_table[i].brr_value;
|
|
||||||
|
|
||||||
if ((config_bits & MASK_FLOW))
|
|
||||||
USARTx->CR3 = (1 << 9) | (1 << 8);
|
|
||||||
else
|
|
||||||
USARTx->CR3 = 0;
|
|
||||||
|
|
||||||
USARTx->CR1 = cr1_config;
|
|
||||||
|
|
||||||
/* SCEN (smartcard enable) should be set _after_ CR1. */
|
|
||||||
if ((config_bits & MASK_MODE))
|
|
||||||
{
|
|
||||||
if ((config_bits & MASK_MODE) == MODE_SMARTCARD)
|
|
||||||
{
|
|
||||||
USARTx->GTPR = (16 << 8) | 5;
|
|
||||||
USARTx->CR3 |= ((1 << 5) | (1 << 4));
|
|
||||||
}
|
|
||||||
else if ((config_bits & MASK_MODE) == MODE_IRDA)
|
|
||||||
USARTx->CR3 |= (1 << 1);
|
|
||||||
else if ((config_bits & MASK_MODE) == MODE_IRDA_LP)
|
|
||||||
USARTx->CR3 |= (1 << 2) | (1 << 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int (*ss_notify_callback) (uint8_t dev_no, uint16_t notify_bits);
|
|
||||||
|
|
||||||
void
|
|
||||||
usart_init (uint16_t prio, uintptr_t stack_addr, size_t stack_size,
|
|
||||||
int (*cb) (uint8_t dev_no, uint16_t notify_bits))
|
|
||||||
{
|
|
||||||
ss_notify_callback = cb;
|
|
||||||
usart2_stat.dev_no = 2;
|
|
||||||
usart3_stat.dev_no = 3;
|
|
||||||
|
|
||||||
/* Enable USART2 and USART3 clocks, and strobe reset. */
|
|
||||||
RCC->APB1ENR |= ((1 << 18) | (1 << 17));
|
|
||||||
RCC->APB1RSTR = ((1 << 18) | (1 << 17));
|
|
||||||
RCC->APB1RSTR = 0;
|
|
||||||
|
|
||||||
chopstx_create (prio, stack_addr, stack_size, usart_main, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Ring buffer
|
|
||||||
*/
|
|
||||||
#define MAX_RB_BUF 1024
|
|
||||||
|
|
||||||
struct rb {
|
|
||||||
uint8_t *buf;
|
|
||||||
chopstx_mutex_t m;
|
|
||||||
chopstx_cond_t data_available;
|
|
||||||
chopstx_cond_t space_available;
|
|
||||||
uint32_t head :10;
|
|
||||||
uint32_t tail :10;
|
|
||||||
uint32_t size :10;
|
|
||||||
uint32_t full : 1;
|
|
||||||
uint32_t empty : 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Note: size = 1024 can still work, regardless of the limit of 10-bit.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
rb_init (struct rb *rb, uint8_t *p, uint16_t size)
|
|
||||||
{
|
|
||||||
rb->buf = p;
|
|
||||||
rb->size = size;
|
|
||||||
chopstx_mutex_init (&rb->m);
|
|
||||||
chopstx_cond_init (&rb->data_available);
|
|
||||||
chopstx_cond_init (&rb->space_available);
|
|
||||||
rb->head = rb->tail = 0;
|
|
||||||
rb->full = 0;
|
|
||||||
rb->empty = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
rb_add (struct rb *rb, uint8_t v)
|
|
||||||
{
|
|
||||||
rb->buf[rb->tail++] = v;
|
|
||||||
if (rb->tail == rb->size)
|
|
||||||
rb->tail = 0;
|
|
||||||
if (rb->tail == rb->head)
|
|
||||||
rb->full = 1;
|
|
||||||
rb->empty = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint8_t
|
|
||||||
rb_del (struct rb *rb)
|
|
||||||
{
|
|
||||||
uint32_t v = rb->buf[rb->head++];
|
|
||||||
|
|
||||||
if (rb->head == rb->size)
|
|
||||||
rb->head = 0;
|
|
||||||
if (rb->head == rb->tail)
|
|
||||||
rb->empty = 1;
|
|
||||||
rb->full = 0;
|
|
||||||
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Application: consumer
|
|
||||||
* Hardware: generator
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
rb_ll_put (struct rb *rb, uint8_t v)
|
|
||||||
{
|
|
||||||
int r;
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&rb->m);
|
|
||||||
if (rb->full)
|
|
||||||
r = -1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
r = 0;
|
|
||||||
rb_add (rb, v);
|
|
||||||
chopstx_cond_signal (&rb->data_available);
|
|
||||||
}
|
|
||||||
chopstx_mutex_unlock (&rb->m);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Application: generator
|
|
||||||
* Hardware: consumer
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
rb_ll_get (struct rb *rb)
|
|
||||||
{
|
|
||||||
int r;
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&rb->m);
|
|
||||||
if (rb->empty)
|
|
||||||
r = -1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
r = rb_del (rb);
|
|
||||||
chopstx_cond_signal (&rb->space_available);
|
|
||||||
}
|
|
||||||
chopstx_mutex_unlock (&rb->m);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
rb_ll_flush (struct rb *rb)
|
|
||||||
{
|
|
||||||
chopstx_mutex_lock (&rb->m);
|
|
||||||
while (!rb->empty)
|
|
||||||
rb_del (rb);
|
|
||||||
chopstx_cond_signal (&rb->space_available);
|
|
||||||
chopstx_mutex_unlock (&rb->m);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Application: consumer
|
|
||||||
* Hardware: generator
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
rb_read (struct rb *rb, uint8_t *buf, uint16_t buflen)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&rb->m);
|
|
||||||
while (rb->empty)
|
|
||||||
chopstx_cond_wait (&rb->data_available, &rb->m);
|
|
||||||
|
|
||||||
while (i < buflen)
|
|
||||||
{
|
|
||||||
buf[i++] = rb_del (rb);
|
|
||||||
if (rb->empty)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
chopstx_cond_signal (&rb->space_available);
|
|
||||||
chopstx_mutex_unlock (&rb->m);
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Application: generator
|
|
||||||
* Hardware: consumer
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
rb_write (struct rb *rb, uint8_t *buf, uint16_t buflen)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&rb->m);
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
while (rb->full)
|
|
||||||
chopstx_cond_wait (&rb->space_available, &rb->m);
|
|
||||||
|
|
||||||
while (i < buflen)
|
|
||||||
{
|
|
||||||
rb_add (rb, buf[i++]);
|
|
||||||
if (rb->full)
|
|
||||||
{
|
|
||||||
chopstx_cond_signal (&rb->data_available);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (i < buflen);
|
|
||||||
|
|
||||||
if (i)
|
|
||||||
chopstx_cond_signal (&rb->data_available);
|
|
||||||
chopstx_mutex_unlock (&rb->m);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
rb_empty_check (void *arg)
|
|
||||||
{
|
|
||||||
struct rb *rb = arg;
|
|
||||||
return rb->empty == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
rb_get_prepare_poll (struct rb *rb, chopstx_poll_cond_t *poll_desc)
|
|
||||||
{
|
|
||||||
poll_desc->type = CHOPSTX_POLL_COND;
|
|
||||||
poll_desc->ready = 0;
|
|
||||||
poll_desc->cond = &rb->data_available;
|
|
||||||
poll_desc->mutex = &rb->m;
|
|
||||||
poll_desc->check = rb_empty_check;
|
|
||||||
poll_desc->arg = rb;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define INTR_REQ_USART2 38
|
|
||||||
#define INTR_REQ_USART3 39
|
|
||||||
|
|
||||||
static uint8_t buf_usart2_rb_a2h[256];
|
|
||||||
static uint8_t buf_usart2_rb_h2a[512];
|
|
||||||
static uint8_t buf_usart3_rb_a2h[256];
|
|
||||||
static uint8_t buf_usart3_rb_h2a[512];
|
|
||||||
|
|
||||||
static struct chx_intr usart2_intr;
|
|
||||||
static struct chx_intr usart3_intr;
|
|
||||||
|
|
||||||
static struct rb usart2_rb_a2h;
|
|
||||||
static struct rb usart2_rb_h2a;
|
|
||||||
static struct rb usart3_rb_a2h;
|
|
||||||
static struct rb usart3_rb_h2a;
|
|
||||||
|
|
||||||
static chopstx_poll_cond_t usart2_app_write_event;
|
|
||||||
static chopstx_poll_cond_t usart3_app_write_event;
|
|
||||||
|
|
||||||
static struct chx_poll_head *usart_poll[4];
|
|
||||||
|
|
||||||
/* Global variables so that it can be easier to debug. */
|
|
||||||
static int usart2_tx_ready;
|
|
||||||
static int usart3_tx_ready;
|
|
||||||
|
|
||||||
#define UART_STATE_BITMAP_RX_CARRIER (1 << 0)
|
|
||||||
#define UART_STATE_BITMAP_TX_CARRIER (1 << 1)
|
|
||||||
#define UART_STATE_BITMAP_BREAK (1 << 2)
|
|
||||||
#define UART_STATE_BITMAP_RINGSIGNAL (1 << 3)
|
|
||||||
#define UART_STATE_BITMAP_FRAMING (1 << 4)
|
|
||||||
#define UART_STATE_BITMAP_PARITY (1 << 5)
|
|
||||||
#define UART_STATE_BITMAP_OVERRUN (1 << 6)
|
|
||||||
|
|
||||||
static int
|
|
||||||
handle_intr (struct USART *USARTx, struct rb *rb2a, struct usart_stat *stat)
|
|
||||||
{
|
|
||||||
int tx_ready = 0;
|
|
||||||
uint32_t r = USARTx->SR;
|
|
||||||
int notify_bits = 0;
|
|
||||||
|
|
||||||
if ((r & USART_SR_TXE))
|
|
||||||
{
|
|
||||||
tx_ready = 1;
|
|
||||||
USARTx->CR1 &= ~USART_CR1_TXEIE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((r & USART_SR_RXNE))
|
|
||||||
{
|
|
||||||
uint32_t data = USARTx->DR;
|
|
||||||
|
|
||||||
/* DR register should be accessed even if data is not used.
|
|
||||||
* Its read-access has side effect of clearing error flags.
|
|
||||||
*/
|
|
||||||
asm volatile ("" : : "r" (data) : "memory");
|
|
||||||
|
|
||||||
if ((r & USART_SR_NE))
|
|
||||||
stat->err_rx_noise++;
|
|
||||||
else if ((r & USART_SR_FE))
|
|
||||||
{
|
|
||||||
/* NOTE: Noway to distinguish framing error and break */
|
|
||||||
|
|
||||||
stat->rx_break++;
|
|
||||||
notify_bits |= UART_STATE_BITMAP_BREAK;
|
|
||||||
}
|
|
||||||
else if ((r & USART_SR_PE))
|
|
||||||
{
|
|
||||||
stat->err_rx_parity++;
|
|
||||||
notify_bits |= UART_STATE_BITMAP_PARITY;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ((r & USART_SR_ORE))
|
|
||||||
{
|
|
||||||
stat->err_rx_overrun++;
|
|
||||||
notify_bits |= UART_STATE_BITMAP_OVERRUN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* XXX: if CS is 7-bit, mask it, or else parity bit in upper layer */
|
|
||||||
if (rb_ll_put (rb2a, (data & 0xff)) < 0)
|
|
||||||
stat->err_rx_overflow++;
|
|
||||||
else
|
|
||||||
stat->rx++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ((r & USART_SR_ORE))
|
|
||||||
{ /* Clear ORE */
|
|
||||||
uint32_t data = USARTx->DR;
|
|
||||||
asm volatile ("" : : "r" (data) : "memory");
|
|
||||||
stat->err_rx_overrun++;
|
|
||||||
notify_bits |= UART_STATE_BITMAP_OVERRUN;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (notify_bits)
|
|
||||||
{
|
|
||||||
if ((*ss_notify_callback) (stat->dev_no, notify_bits))
|
|
||||||
stat->err_notify_overflow++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tx_ready;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
handle_tx_ready (struct USART *USARTx, struct rb *rb2h,
|
|
||||||
struct usart_stat *stat)
|
|
||||||
{
|
|
||||||
int tx_ready = 1;
|
|
||||||
int c = rb_ll_get (rb2h);
|
|
||||||
|
|
||||||
if (c >= 0)
|
|
||||||
{
|
|
||||||
uint32_t r;
|
|
||||||
|
|
||||||
USARTx->DR = (c & 0xff);
|
|
||||||
stat->tx++;
|
|
||||||
r = USARTx->SR;
|
|
||||||
if ((r & USART_SR_TXE) == 0)
|
|
||||||
{
|
|
||||||
tx_ready = 0;
|
|
||||||
USARTx->CR1 |= USART_CR1_TXEIE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return tx_ready;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *
|
|
||||||
usart_main (void *arg)
|
|
||||||
{
|
|
||||||
(void)arg;
|
|
||||||
|
|
||||||
usart2_tx_ready = 1;
|
|
||||||
usart3_tx_ready = 1;
|
|
||||||
|
|
||||||
chopstx_claim_irq (&usart2_intr, INTR_REQ_USART2);
|
|
||||||
chopstx_claim_irq (&usart3_intr, INTR_REQ_USART3);
|
|
||||||
|
|
||||||
rb_init (&usart2_rb_a2h, buf_usart2_rb_a2h, sizeof buf_usart2_rb_a2h);
|
|
||||||
rb_init (&usart2_rb_h2a, buf_usart2_rb_h2a, sizeof buf_usart2_rb_h2a);
|
|
||||||
rb_init (&usart3_rb_a2h, buf_usart3_rb_a2h, sizeof buf_usart3_rb_a2h);
|
|
||||||
rb_init (&usart3_rb_h2a, buf_usart3_rb_h2a, sizeof buf_usart3_rb_h2a);
|
|
||||||
|
|
||||||
rb_get_prepare_poll (&usart2_rb_a2h, &usart2_app_write_event);
|
|
||||||
rb_get_prepare_poll (&usart3_rb_a2h, &usart3_app_write_event);
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
int n = 0;
|
|
||||||
|
|
||||||
usart_poll[n++] = (struct chx_poll_head *)&usart2_intr;
|
|
||||||
usart_poll[n++] = (struct chx_poll_head *)&usart3_intr;
|
|
||||||
if (usart2_tx_ready)
|
|
||||||
usart_poll[n++] = (struct chx_poll_head *)&usart2_app_write_event;
|
|
||||||
else
|
|
||||||
usart2_app_write_event.ready = 0;
|
|
||||||
if (usart3_tx_ready)
|
|
||||||
usart_poll[n++] = (struct chx_poll_head *)&usart3_app_write_event;
|
|
||||||
else
|
|
||||||
usart3_app_write_event.ready = 0;
|
|
||||||
|
|
||||||
chopstx_poll (NULL, n, usart_poll);
|
|
||||||
|
|
||||||
if (usart2_intr.ready)
|
|
||||||
{
|
|
||||||
usart2_tx_ready = handle_intr (USART2, &usart2_rb_h2a, &usart2_stat);
|
|
||||||
chopstx_intr_done (&usart2_intr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (usart3_intr.ready)
|
|
||||||
{
|
|
||||||
usart3_tx_ready = handle_intr (USART3, &usart3_rb_h2a, &usart3_stat);
|
|
||||||
chopstx_intr_done (&usart3_intr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (usart2_tx_ready && usart2_app_write_event.ready)
|
|
||||||
usart2_tx_ready = handle_tx_ready (USART2,
|
|
||||||
&usart2_rb_a2h, &usart2_stat);
|
|
||||||
|
|
||||||
if (usart3_tx_ready && usart3_app_write_event.ready)
|
|
||||||
usart3_tx_ready = handle_tx_ready (USART3,
|
|
||||||
&usart3_rb_a2h, &usart3_stat);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
usart_read (uint8_t dev_no, char *buf, uint16_t buflen)
|
|
||||||
{
|
|
||||||
struct rb *rb;
|
|
||||||
|
|
||||||
if (dev_no == 2)
|
|
||||||
rb = &usart2_rb_h2a;
|
|
||||||
else if (dev_no == 3)
|
|
||||||
rb = &usart3_rb_h2a;
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (buf == NULL && buflen == 0)
|
|
||||||
{
|
|
||||||
rb_ll_flush (rb);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return rb_read (rb, (uint8_t *)buf, buflen);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
usart_write (uint8_t dev_no, char *buf, uint16_t buflen)
|
|
||||||
{
|
|
||||||
struct rb *rb;
|
|
||||||
|
|
||||||
if (dev_no == 2)
|
|
||||||
rb = &usart2_rb_a2h;
|
|
||||||
else if (dev_no == 3)
|
|
||||||
rb = &usart3_rb_a2h;
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (buf == NULL && buflen == 0)
|
|
||||||
rb_ll_flush (rb);
|
|
||||||
else
|
|
||||||
rb_write (rb, (uint8_t *)buf, buflen);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const struct usart_stat *
|
|
||||||
usart_stat (uint8_t dev_no)
|
|
||||||
{
|
|
||||||
if (dev_no == 2)
|
|
||||||
return &usart2_stat;
|
|
||||||
else if (dev_no == 3)
|
|
||||||
return &usart3_stat;
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
usart_send_break (uint8_t dev_no)
|
|
||||||
{
|
|
||||||
struct USART *USARTx = get_usart_dev (dev_no);
|
|
||||||
if (USARTx == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if ((USARTx->CR1 & 0x01))
|
|
||||||
return 1; /* Busy sending break, which was requested before. */
|
|
||||||
|
|
||||||
USARTx->CR1 |= 0x01;
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
#define B0 0 /* POSIX to hang up */
|
|
||||||
|
|
||||||
/* POSIX supports B75 to B300 */
|
|
||||||
#define B600 16
|
|
||||||
#define B1200 17
|
|
||||||
#define B2400 19
|
|
||||||
#define B9600 21
|
|
||||||
#define B19200 22
|
|
||||||
#define B57600 24
|
|
||||||
#define B115200 25
|
|
||||||
#define B230400 26
|
|
||||||
#define B460800 27
|
|
||||||
#define B921600 28
|
|
||||||
#define BSCARD 63
|
|
||||||
#define MASK_BAUD 0x3f
|
|
||||||
|
|
||||||
/* POSIX supports 5, 6. USB suppots 16 */
|
|
||||||
#define CS7 (2 << 6)
|
|
||||||
#define CS8 (3 << 6)
|
|
||||||
#define MASK_CS (0x7 << 6)
|
|
||||||
|
|
||||||
#define STOP0B5 (0 << 9) /* USART Hardware only */
|
|
||||||
#define STOP1B (1 << 9) /* USB, POSIX */
|
|
||||||
#define STOP1B5 (2 << 9) /* USB */
|
|
||||||
#define STOP2B (3 << 9) /* USB, POSIX */
|
|
||||||
#define MASK_STOP (0x3 << 9)
|
|
||||||
|
|
||||||
#define PARENB (1 << 11)
|
|
||||||
#define PARODD (2 << 11)
|
|
||||||
#define MASK_PAR (0x7 << 11)
|
|
||||||
/* USB 0: none, 1: odd, 2: even, 3: mark, 4: space */
|
|
||||||
|
|
||||||
#define CRTSCTS (1 << 14)
|
|
||||||
#define MASK_FLOW (0x1 << 14)
|
|
||||||
|
|
||||||
/*
|
|
||||||
BAUD_BITS 6
|
|
||||||
CS_BITS 3
|
|
||||||
STOP_BITS 2
|
|
||||||
PAR_BITS 3
|
|
||||||
*/
|
|
||||||
/* USB: SET_CONTROL_LINE_STATE
|
|
||||||
DTR RTS */
|
|
||||||
/* USB: SERIAL_STATE
|
|
||||||
DSR DCD RI */
|
|
||||||
|
|
||||||
/* non-POSIX, non-USB-CDC configs */
|
|
||||||
#define MODE_SMARTCARD (1 << 30)
|
|
||||||
#define MODE_IRDA (2UL << 30)
|
|
||||||
#define MODE_IRDA_LP (3UL << 30)
|
|
||||||
#define MASK_MODE (0x3UL << 30)
|
|
||||||
/* 0: standard, 1: smartcard, 2: IrDA, 3: IrDA-LP */
|
|
||||||
|
|
||||||
struct usart_stat {
|
|
||||||
uint8_t dev_no;
|
|
||||||
|
|
||||||
uint32_t tx;
|
|
||||||
uint32_t rx;
|
|
||||||
uint32_t rx_break;
|
|
||||||
uint32_t err_notify_overflow;
|
|
||||||
uint32_t err_rx_overflow; /* software side */
|
|
||||||
uint32_t err_rx_overrun; /* hardware side */
|
|
||||||
uint32_t err_rx_noise;
|
|
||||||
uint32_t err_rx_parity;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void usart_init (uint16_t prio, uintptr_t stack_addr, size_t stack_size,
|
|
||||||
int (*ss_notify_callback) (uint8_t dev_no, uint16_t notify_bits));
|
|
||||||
int usart_config (uint8_t dev_no, uint32_t config_bits);
|
|
||||||
int usart_read (uint8_t dev_no, char *buf, uint16_t buflen);
|
|
||||||
int usart_write (uint8_t dev_no, char *buf, uint16_t buflen);
|
|
||||||
const struct usart_stat *usart_stat (uint8_t dev_no);
|
|
||||||
int usart_send_break (uint8_t dev_no);
|
|
||||||
void usart_config_clken (uint8_t dev_no, int on);
|
|
@ -1,13 +0,0 @@
|
|||||||
The GDOC script is taken from:
|
|
||||||
|
|
||||||
http://git.savannah.gnu.org/cgit/libidn.git/plain/doc/gdoc
|
|
||||||
|
|
||||||
and then modified %highlights_texinfo to use @var for parameters.
|
|
||||||
|
|
||||||
The file 'chopstx-api.texi' is generated by:
|
|
||||||
|
|
||||||
$ ./gdoc -texinfo ../chopstx.c >chopstx-api.texi
|
|
||||||
|
|
||||||
Then, we generate chopstx.info by:
|
|
||||||
|
|
||||||
$ makeinfo -o chopstx.info chopstx.texi
|
|
@ -1,231 +0,0 @@
|
|||||||
@subheading chx_fatal
|
|
||||||
@anchor{chx_fatal}
|
|
||||||
@deftypefun {void} {chx_fatal} (uint32_t @var{err_code})
|
|
||||||
@var{err_code}: Error code
|
|
||||||
|
|
||||||
When it detects a coding error, this function will be called to
|
|
||||||
stop further execution of code. It never returns.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_create
|
|
||||||
@anchor{chopstx_create}
|
|
||||||
@deftypefun {chopstx_t} {chopstx_create} (uint32_t @var{flags_and_prio}, uintptr_t @var{stack_addr}, size_t @var{stack_size}, voidfunc @var{thread_entry}, void * @var{arg})
|
|
||||||
@var{flags_and_prio}: Flags and priority
|
|
||||||
|
|
||||||
@var{stack_addr}: Stack address
|
|
||||||
|
|
||||||
@var{stack_size}: Size of stack
|
|
||||||
|
|
||||||
@var{thread_entry}: Entry function of new thread
|
|
||||||
|
|
||||||
@var{arg}: Argument to the thread entry function
|
|
||||||
|
|
||||||
Create a thread. Returns thread ID.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_usec_wait
|
|
||||||
@anchor{chopstx_usec_wait}
|
|
||||||
@deftypefun {void} {chopstx_usec_wait} (uint32_t @var{usec})
|
|
||||||
@var{usec}: number of micro seconds
|
|
||||||
|
|
||||||
Sleep for @var{usec}.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_mutex_init
|
|
||||||
@anchor{chopstx_mutex_init}
|
|
||||||
@deftypefun {void} {chopstx_mutex_init} (chopstx_mutex_t * @var{mutex})
|
|
||||||
@var{mutex}: Mutex
|
|
||||||
|
|
||||||
Initialize @var{mutex}.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_mutex_lock
|
|
||||||
@anchor{chopstx_mutex_lock}
|
|
||||||
@deftypefun {void} {chopstx_mutex_lock} (chopstx_mutex_t * @var{mutex})
|
|
||||||
@var{mutex}: Mutex
|
|
||||||
|
|
||||||
Lock @var{mutex}.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_mutex_unlock
|
|
||||||
@anchor{chopstx_mutex_unlock}
|
|
||||||
@deftypefun {void} {chopstx_mutex_unlock} (chopstx_mutex_t * @var{mutex})
|
|
||||||
@var{mutex}: Mutex
|
|
||||||
|
|
||||||
Unlock @var{mutex}.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_cond_init
|
|
||||||
@anchor{chopstx_cond_init}
|
|
||||||
@deftypefun {void} {chopstx_cond_init} (chopstx_cond_t * @var{cond})
|
|
||||||
@var{cond}: Condition variable
|
|
||||||
|
|
||||||
Initialize @var{cond}.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_cond_wait
|
|
||||||
@anchor{chopstx_cond_wait}
|
|
||||||
@deftypefun {void} {chopstx_cond_wait} (chopstx_cond_t * @var{cond}, chopstx_mutex_t * @var{mutex})
|
|
||||||
@var{cond}: Condition variable
|
|
||||||
|
|
||||||
@var{mutex}: Associated mutex
|
|
||||||
|
|
||||||
Wait for @var{cond} with @var{mutex}.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_cond_signal
|
|
||||||
@anchor{chopstx_cond_signal}
|
|
||||||
@deftypefun {void} {chopstx_cond_signal} (chopstx_cond_t * @var{cond})
|
|
||||||
@var{cond}: Condition variable
|
|
||||||
|
|
||||||
Wake up a thread waiting on @var{cond}.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_cond_broadcast
|
|
||||||
@anchor{chopstx_cond_broadcast}
|
|
||||||
@deftypefun {void} {chopstx_cond_broadcast} (chopstx_cond_t * @var{cond})
|
|
||||||
@var{cond}: Condition Variable
|
|
||||||
|
|
||||||
Wake up all threads waiting on @var{cond}.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_claim_irq
|
|
||||||
@anchor{chopstx_claim_irq}
|
|
||||||
@deftypefun {void} {chopstx_claim_irq} (chopstx_intr_t * @var{intr}, uint8_t @var{irq_num})
|
|
||||||
@var{intr}: Pointer to INTR structure
|
|
||||||
|
|
||||||
@var{irq_num}: IRQ Number (hardware specific)
|
|
||||||
|
|
||||||
Claim interrupt @var{intr} with @var{irq_num}
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_intr_wait
|
|
||||||
@anchor{chopstx_intr_wait}
|
|
||||||
@deftypefun {void} {chopstx_intr_wait} (chopstx_intr_t * @var{intr})
|
|
||||||
@var{intr}: Pointer to INTR structure
|
|
||||||
|
|
||||||
Wait for the interrupt @var{intr} to be occured.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_intr_done
|
|
||||||
@anchor{chopstx_intr_done}
|
|
||||||
@deftypefun {void} {chopstx_intr_done} (chopstx_intr_t * @var{intr})
|
|
||||||
@var{intr}: Pointer to INTR structure
|
|
||||||
|
|
||||||
Finish for the interrupt @var{intr} occurred.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_cleanup_push
|
|
||||||
@anchor{chopstx_cleanup_push}
|
|
||||||
@deftypefun {void} {chopstx_cleanup_push} (struct chx_cleanup * @var{clp})
|
|
||||||
@var{clp}: Pointer to clean-up structure
|
|
||||||
|
|
||||||
Register a clean-up structure.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_cleanup_pop
|
|
||||||
@anchor{chopstx_cleanup_pop}
|
|
||||||
@deftypefun {void} {chopstx_cleanup_pop} (int @var{execute})
|
|
||||||
@var{execute}: Execute the clen-up function on release
|
|
||||||
|
|
||||||
Unregister a clean-up structure. When @var{execute} is non-zero, the
|
|
||||||
clean-up will be executed.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_exit
|
|
||||||
@anchor{chopstx_exit}
|
|
||||||
@deftypefun {void} {chopstx_exit} (void * @var{retval})
|
|
||||||
@var{retval}: Return value (to be caught by a joining thread)
|
|
||||||
|
|
||||||
Calling this function terminates the execution of running thread,
|
|
||||||
after calling clean up functions. If the calling thread still
|
|
||||||
holds mutexes, they will be released. This function never
|
|
||||||
returns.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_join
|
|
||||||
@anchor{chopstx_join}
|
|
||||||
@deftypefun {int} {chopstx_join} (chopstx_t @var{thd}, void ** @var{ret})
|
|
||||||
@var{thd}: Thread to wait
|
|
||||||
|
|
||||||
@var{ret}: Pointer to void * to store return value
|
|
||||||
|
|
||||||
Waits for the thread of @var{thd} to terminate.
|
|
||||||
Returns 0 on success, 1 when waiting is interrupted.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_cancel
|
|
||||||
@anchor{chopstx_cancel}
|
|
||||||
@deftypefun {void} {chopstx_cancel} (chopstx_t @var{thd})
|
|
||||||
@var{thd}: Thread to be canceled
|
|
||||||
|
|
||||||
This function requests a cancellation of a thread @var{thd}.
|
|
||||||
No return value.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_testcancel
|
|
||||||
@anchor{chopstx_testcancel}
|
|
||||||
@deftypefun {void} {chopstx_testcancel} ( @var{void})
|
|
||||||
|
|
||||||
Calling chopstx_testcancel creates a cancellation point.
|
|
||||||
No return value. If the thread is canceled, this function
|
|
||||||
does not return.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_setcancelstate
|
|
||||||
@anchor{chopstx_setcancelstate}
|
|
||||||
@deftypefun {int} {chopstx_setcancelstate} (int @var{cancel_disable})
|
|
||||||
@var{cancel_disable}: 0 to enable cancelation, otherwise disabled.
|
|
||||||
|
|
||||||
Calling chopstx_setcancelstate sets cancelability state.
|
|
||||||
|
|
||||||
Returns old state which is 0 when it was enabled.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_poll
|
|
||||||
@anchor{chopstx_poll}
|
|
||||||
@deftypefun {int} {chopstx_poll} (uint32_t * @var{usec_p}, int @var{n}, struct chx_poll_head *const [] @var{pd_array})
|
|
||||||
@var{usec_p}: Pointer to usec for timeout. Forever if NULL.
|
|
||||||
|
|
||||||
@var{n}: Number of poll descriptors
|
|
||||||
|
|
||||||
@var{pd_array}: Pointer to an array of poll descriptor pointer which
|
|
||||||
should be one of:
|
|
||||||
chopstx_poll_cond_t, chopstx_poll_join_t, or chopstx_intr_t.
|
|
||||||
|
|
||||||
Returns number of active descriptors.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chopstx_setpriority
|
|
||||||
@anchor{chopstx_setpriority}
|
|
||||||
@deftypefun {chopstx_prio_t} {chopstx_setpriority} (chopstx_prio_t @var{prio_new})
|
|
||||||
Change the schedule priority with @var{prio}.
|
|
||||||
Returns the old priority.
|
|
||||||
|
|
||||||
In general, it is not recommended to use this function because
|
|
||||||
dynamically changing schedule priorities complicates the system.
|
|
||||||
Only a possible valid usage of this function is in the main thread
|
|
||||||
which starts its execution with priority of CHX_PRIO_MAIN_INIT, and
|
|
||||||
let it change its priority after initialization of other threads.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
||||||
@subheading chx_sleep_mode
|
|
||||||
@anchor{chx_sleep_mode}
|
|
||||||
@deftypefun {extern void} {chx_sleep_mode} (int @var{enable_sleep})
|
|
||||||
@var{enable_sleep}: Enable sleep on idle or not
|
|
||||||
|
|
||||||
If @var{enable_sleep} is > 0, allow sleep for the idle thread.
|
|
||||||
|
|
||||||
Behavior of @var{enable_sleep} >= 1 depends on MCU.
|
|
||||||
|
|
||||||
For STM32F0, 1 for Sleep (CPU clock OFF only), 2 for Stop (Wakeup
|
|
||||||
by EXTI, voltage regulator on), 3 for Stop (Wakeup by EXTI, voltage
|
|
||||||
regulator low-power), 4 for Standby (Wakeup by RESET, voltage
|
|
||||||
regulator off).
|
|
||||||
|
|
||||||
For STM32F103, 1 for normal sleep, and 2 for sleep with lower 8MHz
|
|
||||||
clock.
|
|
||||||
|
|
||||||
Return previous value of @var{enable_sleep}.
|
|
||||||
@end deftypefun
|
|
||||||
|
|
@ -1,196 +0,0 @@
|
|||||||
\input texinfo @c -*-texinfo-*-
|
|
||||||
@c %**start of header
|
|
||||||
@setfilename chopstx.info
|
|
||||||
@set VERSION 1.14
|
|
||||||
@settitle Chopstx Reference Manual
|
|
||||||
@c Unify some of the indices.
|
|
||||||
@syncodeindex tp fn
|
|
||||||
@syncodeindex pg fn
|
|
||||||
@c %**end of header
|
|
||||||
@copying
|
|
||||||
This manual is for Chopstx (version @value{VERSION}).
|
|
||||||
|
|
||||||
@noindent
|
|
||||||
Copyright @copyright{} 2013, 2015, 2016, 2017, 2018 Flying Stone Technology @*
|
|
||||||
|
|
||||||
@quotation
|
|
||||||
Permission is granted to copy, distribute and/or modify this document
|
|
||||||
under the terms of the GNU General Public License as published by the
|
|
||||||
Free Software Foundation; either version 3 of the License, or (at your
|
|
||||||
option) any later version. The text of the license can be found in the
|
|
||||||
section entitled ``Copying''.
|
|
||||||
@end quotation
|
|
||||||
@end copying
|
|
||||||
|
|
||||||
|
|
||||||
@c ********************************************
|
|
||||||
|
|
||||||
@dircategory Development
|
|
||||||
@direntry
|
|
||||||
* chopstx: (chopstx). Chopstx, the thread library for embedded system.
|
|
||||||
@end direntry
|
|
||||||
|
|
||||||
@c
|
|
||||||
@c Titlepage
|
|
||||||
@c
|
|
||||||
@setchapternewpage odd
|
|
||||||
@titlepage
|
|
||||||
@title Chopstx Reference Manual
|
|
||||||
@subtitle Version @value{VERSION}
|
|
||||||
@author NIIBE Yutaka (@email{gniibe@@fsij.org})
|
|
||||||
|
|
||||||
@page
|
|
||||||
@vskip 0pt plus 1filll
|
|
||||||
@insertcopying
|
|
||||||
@end titlepage
|
|
||||||
|
|
||||||
@ifnothtml
|
|
||||||
@summarycontents
|
|
||||||
@contents
|
|
||||||
@page
|
|
||||||
@end ifnothtml
|
|
||||||
|
|
||||||
@ifnottex
|
|
||||||
@node Top
|
|
||||||
@top Chopstx, The Thread Library
|
|
||||||
@insertcopying
|
|
||||||
@end ifnottex
|
|
||||||
|
|
||||||
|
|
||||||
@menu
|
|
||||||
* Introduction:: What is Chopstx.
|
|
||||||
* Threads and only Threads:: Threads and only Threads.
|
|
||||||
* Poll or Pole:: Poll or Pole.
|
|
||||||
* Note (Use of sleep mode):: Use it carefully.
|
|
||||||
* Compile-time macro:: Macro to be defined.
|
|
||||||
* API:: API.
|
|
||||||
|
|
||||||
Appendix
|
|
||||||
|
|
||||||
* Copying:: The GNU General Public License says how you
|
|
||||||
can copy and share the program.
|
|
||||||
|
|
||||||
Indexes
|
|
||||||
|
|
||||||
* Concept Index:: Index of concepts and programs.
|
|
||||||
* Function and Data Index:: Index of functions, variables and data types.
|
|
||||||
|
|
||||||
@end menu
|
|
||||||
|
|
||||||
@ifhtml
|
|
||||||
@page
|
|
||||||
@summarycontents
|
|
||||||
@contents
|
|
||||||
@end ifhtml
|
|
||||||
|
|
||||||
@c ********************************************
|
|
||||||
@node Introduction
|
|
||||||
@chapter Introduction
|
|
||||||
|
|
||||||
Chopstx is an RT thread library for ARM Cortex-M0, Cortex-M0plus,
|
|
||||||
Cortex-M3 and GNU/Linux emulation. Specifically, it is used for
|
|
||||||
STM32F030, MKL27Z, STM32F103, GD32F103 and as a command on GNU/Linux.
|
|
||||||
|
|
||||||
While most RTOSes come with many features, drivers, and stacks,
|
|
||||||
Chopstx just offers an RT thread library.
|
|
||||||
|
|
||||||
With Chopstx, interrupt handling is also done by a thread. This
|
|
||||||
enables coherent code for ease of maintenance.
|
|
||||||
|
|
||||||
While threads are important, we don't need more threads than
|
|
||||||
necessary. Chopstx provides a feature of poll, so that we can
|
|
||||||
minimize use of threads.
|
|
||||||
|
|
||||||
|
|
||||||
@node Threads and only Threads
|
|
||||||
@chapter Threads and only Threads
|
|
||||||
|
|
||||||
Chopstx doesn't use the feature of (prioritized) nested vector
|
|
||||||
interrupt mechanism at all. All interrupts are equally handled by a
|
|
||||||
single entry of chx_handle_intr which just wakes up corresponding
|
|
||||||
thread. This is the feature of Chopstx.
|
|
||||||
|
|
||||||
Nested vector interrupt machanism would be useful for interrupt-driven
|
|
||||||
programming style for specific application targets, or, some other
|
|
||||||
programing style like the one with spl of Unix. Some engineers
|
|
||||||
(especially, hardware side) still seem to believe that it is a good
|
|
||||||
feature to have. But from the view point of programming and
|
|
||||||
maintenance of software, this is one of the most difficult part with
|
|
||||||
little benefit, if any.
|
|
||||||
|
|
||||||
With traditional interrupt handling, a demarcation of what should be
|
|
||||||
done by interrupt handler, bottom half, and thead is crucial for
|
|
||||||
applications' performance. And because the demarcation should be done
|
|
||||||
at an early stage of an application development, it has a tendency,
|
|
||||||
many parts are getting demanding higher priority. Amount of code for
|
|
||||||
higher priority interrupt hander is getting bigger and bigger, while
|
|
||||||
losing performance.
|
|
||||||
|
|
||||||
On the other hand, ``Threads (and only Threads)'' programming style
|
|
||||||
gives us best flexibility and it can make an application more
|
|
||||||
predictable, deterministic and easy to maintain.
|
|
||||||
|
|
||||||
There are some applications, like square wave generator, which are not
|
|
||||||
suited to this programming style; Another programming style can
|
|
||||||
support more performance (frequency). In general, such an example is
|
|
||||||
best suited by hardware (not software).
|
|
||||||
|
|
||||||
|
|
||||||
@node Poll or Pole
|
|
||||||
@chapter Poll or Pole
|
|
||||||
Chopstx provides the @code{chopstx_poll} function to wait on multiple events.
|
|
||||||
|
|
||||||
Using @code{chopstx_poll}, we can write an application by event-driven
|
|
||||||
programming style, with minimum number of threads, avoiding
|
|
||||||
complicated dependency between threads.
|
|
||||||
|
|
||||||
|
|
||||||
@node Note (Use of sleep mode)
|
|
||||||
@chapter Note (Use of sleep mode)
|
|
||||||
|
|
||||||
Calling the chopstx_conf_idle function (> 0) to allow the idle thread
|
|
||||||
going to sleep. MCU will be in sleep mode when no threads are
|
|
||||||
running. By setting relevant bits of system registers, MCU will be
|
|
||||||
able to be into stop or stand-by mode, which is MCU dependent.
|
|
||||||
|
|
||||||
If you use this sleep feature, please consider and implement your
|
|
||||||
program carefully. Enabling sleep, it may result a bricked board; A
|
|
||||||
board with no RESET pin cannot be debugged by JTAG/SWD.
|
|
||||||
|
|
||||||
|
|
||||||
@node Compile-time macro
|
|
||||||
@chapter Compile-time macro
|
|
||||||
|
|
||||||
Compiling Chopstx, a macro MHZ should be supplied.
|
|
||||||
|
|
||||||
For example, when using the makefile rule of chopstx/rules.mk, please
|
|
||||||
define the make variable DEFS with -DMHZ=72 before inclusion of the rule file.
|
|
||||||
|
|
||||||
@subheading MHZ
|
|
||||||
@anchor{MHZ}
|
|
||||||
@defmac {MHZ}
|
|
||||||
Running CPU clock in MHz. Used for chopstx_usec_wait.
|
|
||||||
@end defmac
|
|
||||||
|
|
||||||
|
|
||||||
@node API
|
|
||||||
@chapter API
|
|
||||||
|
|
||||||
@include chopstx-api.texi
|
|
||||||
|
|
||||||
|
|
||||||
@c ********************************************
|
|
||||||
|
|
||||||
@include gpl.texi
|
|
||||||
|
|
||||||
@node Concept Index
|
|
||||||
@unnumbered Concept Index
|
|
||||||
|
|
||||||
@printindex cp
|
|
||||||
|
|
||||||
@node Function and Data Index
|
|
||||||
@unnumbered Function and Data Index
|
|
||||||
|
|
||||||
@printindex fn
|
|
||||||
|
|
||||||
@bye
|
|
@ -1,912 +0,0 @@
|
|||||||
eval '(exit $?0)' && eval 'exec perl -S "$0" ${1+"$@"}'
|
|
||||||
& eval 'exec perl -S "$0" $argv:q'
|
|
||||||
if 0;
|
|
||||||
# Generate documentation from source code.
|
|
||||||
|
|
||||||
## Copyright (c) 2002-2013 Simon Josefsson
|
|
||||||
## added -texinfo, -listfunc, -pkg-name
|
|
||||||
## man page revamp
|
|
||||||
## various improvements
|
|
||||||
## Copyright (c) 2001, 2002 Nikos Mavrogiannopoulos
|
|
||||||
## added -tex
|
|
||||||
## Copyright (c) 1998 Michael Zucchi
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# This will read a C source code file and scan for embedded comments
|
|
||||||
# in the style of gnome comments (+minor extensions - see below).
|
|
||||||
|
|
||||||
# usage:
|
|
||||||
# gdoc [ -docbook | -html | -text | -man | -tex | -texinfo | -listfunc ]
|
|
||||||
# [ -sourceversion verno ] [ -include file | -includefuncprefix ]
|
|
||||||
# [ -bugsto address ] [ -pkg-name packagename ]
|
|
||||||
# [ -seeinfo infonode ] [ -copyright notice ] [ -verbatimcopying ]
|
|
||||||
# [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile
|
|
||||||
#
|
|
||||||
# Set output format using one of -docbook, -html, -text, -man, -tex,
|
|
||||||
# -texinfo, or -listfunc. Default is man.
|
|
||||||
#
|
|
||||||
# -sourceversion
|
|
||||||
# Version number for source code, e.g. '1.0.4'. Used in 'man' headers.
|
|
||||||
# Defaults to using current date.
|
|
||||||
#
|
|
||||||
# -include FILE
|
|
||||||
# For man pages, mention #include <FILE.h> in the synopsis.
|
|
||||||
#
|
|
||||||
# -includefuncprefix
|
|
||||||
# For man pages, mention a #include <FILE.h> in the synopsis.
|
|
||||||
# The FILE derived from the function prefix. For example, a
|
|
||||||
# function gss_init_sec_context will generate an include
|
|
||||||
# statement of #include <gss.h>.
|
|
||||||
#
|
|
||||||
# -bugsto address
|
|
||||||
# For man pages, include a section about reporting bugs and mention
|
|
||||||
# the given e-mail address, e.g 'bug-libidn@gnu.org'.
|
|
||||||
#
|
|
||||||
# -pkg-name packagename
|
|
||||||
# For man pages when -bugsto is used, also include help URLs to the
|
|
||||||
# the project's home page. For example, "GNU Libidn".
|
|
||||||
#
|
|
||||||
# -seeinfo infonode
|
|
||||||
# For man pages, include a section that point to an info manual
|
|
||||||
# for more information.
|
|
||||||
#
|
|
||||||
# -copyright notice
|
|
||||||
# For man pages, include a copyright section with the given
|
|
||||||
# notice after a preamble. Use, e.g., '2002, 2003 Simon Josefsson'.
|
|
||||||
#
|
|
||||||
# -verbatimcopying
|
|
||||||
# For man pages, and when the -copyright parameter is used,
|
|
||||||
# add a licensing statement that say verbatim copying is permitted.
|
|
||||||
#
|
|
||||||
# -function funcname
|
|
||||||
# If set, then only generate documentation for the given function(s). All
|
|
||||||
# other functions are ignored.
|
|
||||||
#
|
|
||||||
# c files - list of 'c' files to process
|
|
||||||
#
|
|
||||||
# All output goes to stdout, with errors to stderr.
|
|
||||||
|
|
||||||
#
|
|
||||||
# format of comments.
|
|
||||||
# In the following table, (...)? signifies optional structure.
|
|
||||||
# (...)* signifies 0 or more structure elements
|
|
||||||
# /**
|
|
||||||
# * function_name(:)? (- short description)?
|
|
||||||
# (* @parameterx: (description of parameter x)?)*
|
|
||||||
# (* a blank line)?
|
|
||||||
# * (Description:)? (Description of function)?
|
|
||||||
# * (Section header: (section description)? )*
|
|
||||||
# (*)?*/
|
|
||||||
#
|
|
||||||
# So .. the trivial example would be:
|
|
||||||
#
|
|
||||||
# /**
|
|
||||||
# * my_function
|
|
||||||
# **/
|
|
||||||
#
|
|
||||||
# If the Description: header tag is ommitted, then there must be a blank line
|
|
||||||
# after the last parameter specification.
|
|
||||||
# e.g.
|
|
||||||
# /**
|
|
||||||
# * my_function - does my stuff
|
|
||||||
# * @my_arg: its mine damnit
|
|
||||||
# *
|
|
||||||
# * Does my stuff explained.
|
|
||||||
# */
|
|
||||||
#
|
|
||||||
# or, could also use:
|
|
||||||
# /**
|
|
||||||
# * my_function - does my stuff
|
|
||||||
# * @my_arg: its mine damnit
|
|
||||||
# * Description: Does my stuff explained.
|
|
||||||
# */
|
|
||||||
# etc.
|
|
||||||
#
|
|
||||||
# All descriptions can be multiline, apart from the short function description.
|
|
||||||
#
|
|
||||||
# All descriptive text is further processed, scanning for the following special
|
|
||||||
# patterns, which are highlighted appropriately.
|
|
||||||
#
|
|
||||||
# 'funcname()' - function
|
|
||||||
# '$ENVVAR' - environmental variable OBSOLETE (?)
|
|
||||||
# '#struct_name' - name of a structure
|
|
||||||
# '@parameter' - name of a parameter
|
|
||||||
# '%CONST' - name of a constant.
|
|
||||||
|
|
||||||
#
|
|
||||||
# Extensions for LaTeX:
|
|
||||||
#
|
|
||||||
# 1. the symbol '->' will be replaced with a rightarrow
|
|
||||||
# 2. x^y with ${x}^{y}$.
|
|
||||||
# 3. xxx\: with xxx:
|
|
||||||
|
|
||||||
use POSIX qw(strftime);
|
|
||||||
|
|
||||||
# match expressions used to find embedded type information
|
|
||||||
$type_constant = "\\\%(\\w+)";
|
|
||||||
$type_func = "(\\w+\\(\\))";
|
|
||||||
$type_param = "\\\@(\\w+)";
|
|
||||||
$type_struct = "\\\#(\\w+)";
|
|
||||||
$type_env = "(\\\$\\w+)";
|
|
||||||
|
|
||||||
|
|
||||||
# Output conversion substitutions.
|
|
||||||
# One for each output format
|
|
||||||
|
|
||||||
# these work fairly well
|
|
||||||
%highlights_html = ( $type_constant, "<i>\$1</i>",
|
|
||||||
$type_func, "<b>\$1</b>",
|
|
||||||
$type_struct, "<i>\$1</i>",
|
|
||||||
$type_param, "<tt><b>\$1</b></tt>" );
|
|
||||||
$blankline_html = "<p>";
|
|
||||||
|
|
||||||
%highlights_texinfo = ( $type_constant, "\\\@code{\$1}",
|
|
||||||
$type_func, "\\\@code{\$1}",
|
|
||||||
$type_struct, "\\\@code{\$1}",
|
|
||||||
$type_param, "\\\@var{\$1}" );
|
|
||||||
$blankline_texinfo = "";
|
|
||||||
|
|
||||||
%highlights_tex = ( $type_constant, "{\\\\it \$1}",
|
|
||||||
$type_func, "{\\\\bf \$1}",
|
|
||||||
$type_struct, "{\\\\it \$1}",
|
|
||||||
$type_param, "{\\\\bf \$1}" );
|
|
||||||
$blankline_tex = "\\\\";
|
|
||||||
|
|
||||||
# sgml, docbook format
|
|
||||||
%highlights_sgml = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
|
|
||||||
$type_func, "<function>\$1</function>",
|
|
||||||
$type_struct, "<structname>\$1</structname>",
|
|
||||||
$type_env, "<envar>\$1</envar>",
|
|
||||||
$type_param, "<parameter>\$1</parameter>" );
|
|
||||||
$blankline_sgml = "</para><para>\n";
|
|
||||||
|
|
||||||
# these are pretty rough
|
|
||||||
%highlights_man = ( $type_constant, "\\\\fB\$1\\\\fP",
|
|
||||||
$type_func, "\\\\fB\$1\\\\fP",
|
|
||||||
$type_struct, "\\\\fB\$1\\\\fP",
|
|
||||||
$type_param, "\\\\fI\$1\\\\fP" );
|
|
||||||
$blankline_man = "";
|
|
||||||
|
|
||||||
# text-mode
|
|
||||||
%highlights_text = ( $type_constant, "\$1",
|
|
||||||
$type_func, "\$1",
|
|
||||||
$type_struct, "\$1",
|
|
||||||
$type_param, "\$1" );
|
|
||||||
$blankline_text = "";
|
|
||||||
|
|
||||||
|
|
||||||
sub usage {
|
|
||||||
print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man | -tex | -texinfo -listfunc ]\n";
|
|
||||||
print " [ -sourceversion verno ] [ -include file | -includefuncprefix ]\n";
|
|
||||||
print " [ -bugsto address ] [ -seeinfo infonode ] [ -copyright notice]\n";
|
|
||||||
print " [ -verbatimcopying ] [ -pkg-name packagename ]\n";
|
|
||||||
print " [ -function funcname [ -function funcname ...] ]\n";
|
|
||||||
print " c source file(s) > outputfile\n";
|
|
||||||
exit 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
# read arguments
|
|
||||||
if ($#ARGV==-1) {
|
|
||||||
usage();
|
|
||||||
}
|
|
||||||
|
|
||||||
$verbose = 0;
|
|
||||||
$output_mode = "man";
|
|
||||||
%highlights = %highlights_man;
|
|
||||||
$blankline = $blankline_man;
|
|
||||||
$modulename = "API Documentation";
|
|
||||||
$sourceversion = strftime "%Y-%m-%d", localtime;
|
|
||||||
$function_only = 0;
|
|
||||||
while ($ARGV[0] =~ m/^-(.*)/) {
|
|
||||||
$cmd = shift @ARGV;
|
|
||||||
if ($cmd eq "-html") {
|
|
||||||
$output_mode = "html";
|
|
||||||
%highlights = %highlights_html;
|
|
||||||
$blankline = $blankline_html;
|
|
||||||
} elsif ($cmd eq "-man") {
|
|
||||||
$output_mode = "man";
|
|
||||||
%highlights = %highlights_man;
|
|
||||||
$blankline = $blankline_man;
|
|
||||||
} elsif ($cmd eq "-tex") {
|
|
||||||
$output_mode = "tex";
|
|
||||||
%highlights = %highlights_tex;
|
|
||||||
$blankline = $blankline_tex;
|
|
||||||
} elsif ($cmd eq "-texinfo") {
|
|
||||||
$output_mode = "texinfo";
|
|
||||||
%highlights = %highlights_texinfo;
|
|
||||||
$blankline = $blankline_texinfo;
|
|
||||||
} elsif ($cmd eq "-text") {
|
|
||||||
$output_mode = "text";
|
|
||||||
%highlights = %highlights_text;
|
|
||||||
$blankline = $blankline_text;
|
|
||||||
} elsif ($cmd eq "-docbook") {
|
|
||||||
$output_mode = "sgml";
|
|
||||||
%highlights = %highlights_sgml;
|
|
||||||
$blankline = $blankline_sgml;
|
|
||||||
} elsif ($cmd eq "-listfunc") {
|
|
||||||
$output_mode = "listfunc";
|
|
||||||
} elsif ($cmd eq "-module") { # not needed for sgml, inherits from calling document
|
|
||||||
$modulename = shift @ARGV;
|
|
||||||
} elsif ($cmd eq "-sourceversion") {
|
|
||||||
$sourceversion = shift @ARGV;
|
|
||||||
} elsif ($cmd eq "-include") {
|
|
||||||
$include = shift @ARGV;
|
|
||||||
} elsif ($cmd eq "-includefuncprefix") {
|
|
||||||
$includefuncprefix = 1;
|
|
||||||
} elsif ($cmd eq "-bugsto") {
|
|
||||||
$bugsto = shift @ARGV;
|
|
||||||
} elsif ($cmd eq "-pkg-name") {
|
|
||||||
$pkgname = shift @ARGV;
|
|
||||||
} elsif ($cmd eq "-copyright") {
|
|
||||||
$copyright = shift @ARGV;
|
|
||||||
} elsif ($cmd eq "-verbatimcopying") {
|
|
||||||
$verbatimcopying = 1;
|
|
||||||
} elsif ($cmd eq "-seeinfo") {
|
|
||||||
$seeinfo = shift @ARGV;
|
|
||||||
} elsif ($cmd eq "-function") { # to only output specific functions
|
|
||||||
$function_only = 1;
|
|
||||||
$function = shift @ARGV;
|
|
||||||
$function_table{$function} = 1;
|
|
||||||
} elsif ($cmd eq "-v") {
|
|
||||||
$verbose = 1;
|
|
||||||
} elsif (($cmd eq "-h") || ($cmd eq "--help")) {
|
|
||||||
usage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
##
|
|
||||||
# dumps section contents to arrays/hashes intended for that purpose.
|
|
||||||
#
|
|
||||||
sub dump_section {
|
|
||||||
my $name = shift @_;
|
|
||||||
my $contents = join "\n", @_;
|
|
||||||
|
|
||||||
if ($name =~ m/$type_constant/) {
|
|
||||||
$name = $1;
|
|
||||||
# print STDERR "constant section '$1' = '$contents'\n";
|
|
||||||
$constants{$name} = $contents;
|
|
||||||
} elsif ($name =~ m/$type_param/) {
|
|
||||||
# print STDERR "parameter def '$1' = '$contents'\n";
|
|
||||||
$name = $1;
|
|
||||||
$parameters{$name} = $contents;
|
|
||||||
} else {
|
|
||||||
# print STDERR "other section '$name' = '$contents'\n";
|
|
||||||
$sections{$name} = $contents;
|
|
||||||
push @sectionlist, $name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
##
|
|
||||||
# output function
|
|
||||||
#
|
|
||||||
# parameters, a hash.
|
|
||||||
# function => "function name"
|
|
||||||
# parameterlist => @list of parameters
|
|
||||||
# parameters => %parameter descriptions
|
|
||||||
# sectionlist => @list of sections
|
|
||||||
# sections => %descriont descriptions
|
|
||||||
#
|
|
||||||
|
|
||||||
sub repstr {
|
|
||||||
$pattern = shift;
|
|
||||||
$repl = shift;
|
|
||||||
$match1 = shift;
|
|
||||||
$match2 = shift;
|
|
||||||
$match3 = shift;
|
|
||||||
$match4 = shift;
|
|
||||||
|
|
||||||
$output = $repl;
|
|
||||||
$output =~ s,\$1,$match1,g;
|
|
||||||
$output =~ s,\$2,$match2,g;
|
|
||||||
$output =~ s,\$3,$match3,g;
|
|
||||||
$output =~ s,\$4,$match4,g;
|
|
||||||
|
|
||||||
eval "\$return = qq/$output/";
|
|
||||||
|
|
||||||
# print "pattern $pattern matched 1=$match1 2=$match2 3=$match3 4=$match4 replace $repl yielded $output interpolated $return\n";
|
|
||||||
|
|
||||||
$return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub just_highlight {
|
|
||||||
my $contents = join "\n", @_;
|
|
||||||
my $line;
|
|
||||||
my $ret = "";
|
|
||||||
|
|
||||||
foreach $pattern (keys %highlights) {
|
|
||||||
# print "scanning pattern $pattern ($highlights{$pattern})\n";
|
|
||||||
$contents =~ s:$pattern:repstr($pattern, $highlights{$pattern}, $1, $2, $3, $4):gse;
|
|
||||||
}
|
|
||||||
foreach $line (split "\n", $contents) {
|
|
||||||
if ($line eq ""){
|
|
||||||
$ret = $ret . $lineprefix . $blankline;
|
|
||||||
} else {
|
|
||||||
$ret = $ret . $lineprefix . $line;
|
|
||||||
}
|
|
||||||
$ret = $ret . "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub output_highlight {
|
|
||||||
print (just_highlight (@_));
|
|
||||||
}
|
|
||||||
|
|
||||||
# output in texinfo
|
|
||||||
sub output_texinfo {
|
|
||||||
my %args = %{$_[0]};
|
|
||||||
my ($parameter, $section);
|
|
||||||
my $count;
|
|
||||||
|
|
||||||
print "\@subheading ".$args{'function'}."\n";
|
|
||||||
print "\@anchor{".$args{'function'}."}\n";
|
|
||||||
print "\@deftypefun {" . $args{'functiontype'} . "} ";
|
|
||||||
print "{".$args{'function'}."} ";
|
|
||||||
print "(";
|
|
||||||
$count = 0;
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
print $args{'parametertypes'}{$parameter}." \@var{".$parameter."}";
|
|
||||||
if ($count != $#{$args{'parameterlist'}}) {
|
|
||||||
$count++;
|
|
||||||
print ", ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print ")\n";
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
if ($args{'parameters'}{$parameter}) {
|
|
||||||
print "\@var{".$parameter."}: ";
|
|
||||||
output_highlight($args{'parameters'}{$parameter});
|
|
||||||
print "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach $section (@{$args{'sectionlist'}}) {
|
|
||||||
print "\n\@strong{$section:} " if $section ne $section_default;
|
|
||||||
$args{'sections'}{$section} =~ s:([{}]):\@\1:gs;
|
|
||||||
output_highlight($args{'sections'}{$section});
|
|
||||||
}
|
|
||||||
print "\@end deftypefun\n\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
# output in html
|
|
||||||
sub output_html {
|
|
||||||
my %args = %{$_[0]};
|
|
||||||
my ($parameter, $section);
|
|
||||||
my $count;
|
|
||||||
print "\n\n<a name=\"". $args{'function'} . "\"> </a><h2>Function</h2>\n";
|
|
||||||
|
|
||||||
print "<i>".$args{'functiontype'}."</i>\n";
|
|
||||||
print "<b>".$args{'function'}."</b>\n";
|
|
||||||
print "(";
|
|
||||||
$count = 0;
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
print "<i>".$args{'parametertypes'}{$parameter}."</i> <b>".$parameter."</b>\n";
|
|
||||||
if ($count != $#{$args{'parameterlist'}}) {
|
|
||||||
$count++;
|
|
||||||
print ", ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print ")\n";
|
|
||||||
|
|
||||||
print "<h3>Arguments</h3>\n";
|
|
||||||
print "<dl>\n";
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
print "<dt><i>".$args{'parametertypes'}{$parameter}."</i> <b>".$parameter."</b>\n";
|
|
||||||
print "<dd>";
|
|
||||||
output_highlight($args{'parameters'}{$parameter});
|
|
||||||
}
|
|
||||||
print "</dl>\n";
|
|
||||||
foreach $section (@{$args{'sectionlist'}}) {
|
|
||||||
print "<h3>$section</h3>\n";
|
|
||||||
print "<ul>\n";
|
|
||||||
output_highlight($args{'sections'}{$section});
|
|
||||||
print "</ul>\n";
|
|
||||||
}
|
|
||||||
print "<hr>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
# output in tex
|
|
||||||
sub output_tex {
|
|
||||||
my %args = %{$_[0]};
|
|
||||||
my ($parameter, $section);
|
|
||||||
my $count;
|
|
||||||
my $func = $args{'function'};
|
|
||||||
my $param;
|
|
||||||
my $param2;
|
|
||||||
my $sec;
|
|
||||||
my $check;
|
|
||||||
my $type;
|
|
||||||
|
|
||||||
$func =~ s/_/\\_/g;
|
|
||||||
|
|
||||||
print "\n\n\\subsection{". $func . "}\n\\label{" . $args{'function'} . "}\n";
|
|
||||||
|
|
||||||
$type = $args{'functiontype'};
|
|
||||||
$type =~ s/_/\\_/g;
|
|
||||||
|
|
||||||
print "{\\it ".$type."}\n";
|
|
||||||
print "{\\bf ".$func."}\n";
|
|
||||||
print "(";
|
|
||||||
$count = 0;
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
$param = $args{'parametertypes'}{$parameter};
|
|
||||||
$param2 = $parameter;
|
|
||||||
$param =~ s/_/\\_/g;
|
|
||||||
$param2 =~ s/_/\\_/g;
|
|
||||||
|
|
||||||
print "{\\it ".$param."} {\\bf ".$param2."}";
|
|
||||||
if ($count != $#{$args{'parameterlist'}}) {
|
|
||||||
$count++;
|
|
||||||
print ", ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print ")\n";
|
|
||||||
|
|
||||||
print "\n{\\large{Arguments}}\n";
|
|
||||||
|
|
||||||
print "\\begin{itemize}\n";
|
|
||||||
$check=0;
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
$param1 = $args{'parametertypes'}{$parameter};
|
|
||||||
$param1 =~ s/_/\\_/g;
|
|
||||||
$param2 = $parameter;
|
|
||||||
$param2 =~ s/_/\\_/g;
|
|
||||||
|
|
||||||
$check = 1;
|
|
||||||
print "\\item {\\it ".$param1."} {\\bf ".$param2."}: \n";
|
|
||||||
# print "\n";
|
|
||||||
|
|
||||||
$param3 = $args{'parameters'}{$parameter};
|
|
||||||
$param3 =~ s/#([a-zA-Z\_]+)/{\\it \1}/g;
|
|
||||||
|
|
||||||
$out = just_highlight($param3);
|
|
||||||
$out =~ s/_/\\_/g;
|
|
||||||
print $out;
|
|
||||||
}
|
|
||||||
if ($check==0) {
|
|
||||||
print "\\item void\n";
|
|
||||||
}
|
|
||||||
print "\\end{itemize}\n";
|
|
||||||
|
|
||||||
foreach $section (@{$args{'sectionlist'}}) {
|
|
||||||
$sec = $section;
|
|
||||||
$sec =~ s/_/\\_/g;
|
|
||||||
$sec =~ s/#([a-zA-Z\_]+)/{\\it \1}/g;
|
|
||||||
|
|
||||||
print "\n{\\large{$sec}}\\\\\n";
|
|
||||||
print "\\begin{rmfamily}\n";
|
|
||||||
|
|
||||||
$sec = $args{'sections'}{$section};
|
|
||||||
$sec =~ s/\\:/:/g;
|
|
||||||
$sec =~ s/#([a-zA-Z\_]+)/{\\it \1}/g;
|
|
||||||
$sec =~ s/->/\$\\rightarrow\$/g;
|
|
||||||
$sec =~ s/([0-9]+)\^([0-9]+)/\$\{\1\}\^\{\2\}\$/g;
|
|
||||||
|
|
||||||
$out = just_highlight($sec);
|
|
||||||
$out =~ s/_/\\_/g;
|
|
||||||
|
|
||||||
print $out;
|
|
||||||
print "\\end{rmfamily}\n";
|
|
||||||
}
|
|
||||||
print "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# output in sgml DocBook
|
|
||||||
sub output_sgml {
|
|
||||||
my %args = %{$_[0]};
|
|
||||||
my ($parameter, $section);
|
|
||||||
my $count;
|
|
||||||
my $id;
|
|
||||||
|
|
||||||
$id = $args{'module'}."-".$args{'function'};
|
|
||||||
$id =~ s/[^A-Za-z0-9]/-/g;
|
|
||||||
|
|
||||||
print "<refentry>\n";
|
|
||||||
print "<refmeta>\n";
|
|
||||||
print "<refentrytitle><phrase id=\"$id\">".$args{'function'}."</phrase></refentrytitle>\n";
|
|
||||||
print "</refmeta>\n";
|
|
||||||
print "<refnamediv>\n";
|
|
||||||
print " <refname>".$args{'function'}."</refname>\n";
|
|
||||||
print " <refpurpose>\n";
|
|
||||||
print " ".$args{'purpose'}."\n";
|
|
||||||
print " </refpurpose>\n";
|
|
||||||
print "</refnamediv>\n";
|
|
||||||
|
|
||||||
print "<refsynopsisdiv>\n";
|
|
||||||
print " <title>Synopsis</title>\n";
|
|
||||||
print " <funcsynopsis>\n";
|
|
||||||
print " <funcdef>".$args{'functiontype'}." ";
|
|
||||||
print "<function>".$args{'function'}." ";
|
|
||||||
print "</function></funcdef>\n";
|
|
||||||
|
|
||||||
# print "<refsect1>\n";
|
|
||||||
# print " <title>Synopsis</title>\n";
|
|
||||||
# print " <funcsynopsis>\n";
|
|
||||||
# print " <funcdef>".$args{'functiontype'}." ";
|
|
||||||
# print "<function>".$args{'function'}." ";
|
|
||||||
# print "</function></funcdef>\n";
|
|
||||||
|
|
||||||
$count = 0;
|
|
||||||
if ($#{$args{'parameterlist'}} >= 0) {
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
print " <paramdef>".$args{'parametertypes'}{$parameter};
|
|
||||||
print " <parameter>$parameter</parameter></paramdef>\n";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
print " <void>\n";
|
|
||||||
}
|
|
||||||
print " </funcsynopsis>\n";
|
|
||||||
print "</refsynopsisdiv>\n";
|
|
||||||
# print "</refsect1>\n";
|
|
||||||
|
|
||||||
# print parameters
|
|
||||||
print "<refsect1>\n <title>Arguments</title>\n";
|
|
||||||
# print "<para>\nArguments\n";
|
|
||||||
if ($#{$args{'parameterlist'}} >= 0) {
|
|
||||||
print " <variablelist>\n";
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
|
|
||||||
print " <listitem>\n <para>\n";
|
|
||||||
$lineprefix=" ";
|
|
||||||
output_highlight($args{'parameters'}{$parameter});
|
|
||||||
print " </para>\n </listitem>\n </varlistentry>\n";
|
|
||||||
}
|
|
||||||
print " </variablelist>\n";
|
|
||||||
} else {
|
|
||||||
print " <para>\n None\n </para>\n";
|
|
||||||
}
|
|
||||||
print "</refsect1>\n";
|
|
||||||
|
|
||||||
# print out each section
|
|
||||||
$lineprefix=" ";
|
|
||||||
foreach $section (@{$args{'sectionlist'}}) {
|
|
||||||
print "<refsect1>\n <title>$section</title>\n <para>\n";
|
|
||||||
# print "<para>\n$section\n";
|
|
||||||
if ($section =~ m/EXAMPLE/i) {
|
|
||||||
print "<example><para>\n";
|
|
||||||
}
|
|
||||||
output_highlight($args{'sections'}{$section});
|
|
||||||
# print "</para>";
|
|
||||||
if ($section =~ m/EXAMPLE/i) {
|
|
||||||
print "</para></example>\n";
|
|
||||||
}
|
|
||||||
print " </para>\n</refsect1>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
print "\n\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
##
|
|
||||||
# output in man
|
|
||||||
sub output_man {
|
|
||||||
my %args = %{$_[0]};
|
|
||||||
my ($parameter, $section);
|
|
||||||
my $count;
|
|
||||||
|
|
||||||
print ".\\\" DO NOT MODIFY THIS FILE! It was generated by gdoc.\n";
|
|
||||||
print ".TH \"$args{'function'}\" 3 \"$args{'sourceversion'}\" \"". $args{'module'} . "\" \"". $args{'module'} . "\"\n";
|
|
||||||
|
|
||||||
print ".SH NAME\n";
|
|
||||||
|
|
||||||
print $args{'function'};
|
|
||||||
if ($args{'purpose'}) {
|
|
||||||
print " \\- " . $args{'purpose'} . "\n";
|
|
||||||
} else {
|
|
||||||
print " \\- API function\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
print ".SH SYNOPSIS\n";
|
|
||||||
print ".B #include <". $args{'include'} . ">\n"
|
|
||||||
if $args{'include'};
|
|
||||||
print ".B #include <". lc((split /_/, $args{'function'})[0]) . ".h>\n"
|
|
||||||
if $args{'includefuncprefix'};
|
|
||||||
print ".sp\n";
|
|
||||||
print ".BI \"".$args{'functiontype'}." ".$args{'function'}."(";
|
|
||||||
$count = 0;
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
print $args{'parametertypes'}{$parameter}." \" ".$parameter." \"";
|
|
||||||
if ($count != $#{$args{'parameterlist'}}) {
|
|
||||||
$count++;
|
|
||||||
print ", ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print ");\"\n";
|
|
||||||
|
|
||||||
print ".SH ARGUMENTS\n";
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
print ".IP \"".$args{'parametertypes'}{$parameter}." ".$parameter."\" 12\n";
|
|
||||||
$param = $args{'parameters'}{$parameter};
|
|
||||||
$param =~ s/-/\\-/g;
|
|
||||||
output_highlight($param);
|
|
||||||
}
|
|
||||||
foreach $section (@{$args{'sectionlist'}}) {
|
|
||||||
print ".SH \"" . uc($section) . "\"\n";
|
|
||||||
$sec = $args{'sections'}{$section};
|
|
||||||
$sec =~ s/-/\\-/g;
|
|
||||||
output_highlight($sec);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($args{'bugsto'}) {
|
|
||||||
print ".SH \"REPORTING BUGS\"\n";
|
|
||||||
print "Report bugs to <". $args{'bugsto'} . ">.\n";
|
|
||||||
if ($args{'pkgname'}) {
|
|
||||||
print $args{'pkgname'} . " home page: " .
|
|
||||||
"http://www.gnu.org/software/" . $args{'module'} . "/\n";
|
|
||||||
}
|
|
||||||
print "General help using GNU software: http://www.gnu.org/gethelp/\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($args{'copyright'}) {
|
|
||||||
print ".SH COPYRIGHT\n";
|
|
||||||
print "Copyright \\(co ". $args{'copyright'} . ".\n";
|
|
||||||
if ($args{'verbatimcopying'}) {
|
|
||||||
print ".br\n";
|
|
||||||
print "Copying and distribution of this file, with or without modification,\n";
|
|
||||||
print "are permitted in any medium without royalty provided the copyright\n";
|
|
||||||
print "notice and this notice are preserved.\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($args{'seeinfo'}) {
|
|
||||||
print ".SH \"SEE ALSO\"\n";
|
|
||||||
print "The full documentation for\n";
|
|
||||||
print ".B " . $args{'module'} . "\n";
|
|
||||||
print "is maintained as a Texinfo manual. If the\n";
|
|
||||||
print ".B info\n";
|
|
||||||
print "and\n";
|
|
||||||
print ".B " . $args{'module'} . "\n";
|
|
||||||
print "programs are properly installed at your site, the command\n";
|
|
||||||
print ".IP\n";
|
|
||||||
print ".B info " . $args{'seeinfo'} . "\n";
|
|
||||||
print ".PP\n";
|
|
||||||
print "should give you access to the complete manual.\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub output_listfunc {
|
|
||||||
my %args = %{$_[0]};
|
|
||||||
print $args{'function'} . "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
##
|
|
||||||
# output in text
|
|
||||||
sub output_text {
|
|
||||||
my %args = %{$_[0]};
|
|
||||||
my ($parameter, $section);
|
|
||||||
|
|
||||||
print "Function = ".$args{'function'}."\n";
|
|
||||||
print " return type: ".$args{'functiontype'}."\n\n";
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
print " ".$args{'parametertypes'}{$parameter}." ".$parameter."\n";
|
|
||||||
print " -> ".$args{'parameters'}{$parameter}."\n";
|
|
||||||
}
|
|
||||||
foreach $section (@{$args{'sectionlist'}}) {
|
|
||||||
print " $section:\n";
|
|
||||||
print " -> ";
|
|
||||||
output_highlight($args{'sections'}{$section});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
##
|
|
||||||
# generic output function - calls the right one based
|
|
||||||
# on current output mode.
|
|
||||||
sub output_function {
|
|
||||||
# output_html(@_);
|
|
||||||
eval "output_".$output_mode."(\@_);";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
##
|
|
||||||
# takes a function prototype and spits out all the details
|
|
||||||
# stored in the global arrays/hsahes.
|
|
||||||
sub dump_function {
|
|
||||||
my $prototype = shift @_;
|
|
||||||
|
|
||||||
if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
|
|
||||||
$prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
|
|
||||||
$prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
|
|
||||||
$prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
|
|
||||||
$prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/) {
|
|
||||||
$return_type = $1;
|
|
||||||
$function_name = $2;
|
|
||||||
$args = $3;
|
|
||||||
|
|
||||||
# print STDERR "ARGS = '$args'\n";
|
|
||||||
|
|
||||||
foreach $arg (split ',', $args) {
|
|
||||||
# strip leading/trailing spaces
|
|
||||||
$arg =~ s/^\s*//;
|
|
||||||
$arg =~ s/\s*$//;
|
|
||||||
# print STDERR "SCAN ARG: '$arg'\n";
|
|
||||||
@args = split('\s', $arg);
|
|
||||||
|
|
||||||
# print STDERR " -> @args\n";
|
|
||||||
$param = pop @args;
|
|
||||||
# print STDERR " -> @args\n";
|
|
||||||
if ($param =~ m/^(\*+)(.*)/) {
|
|
||||||
$param = $2;
|
|
||||||
push @args, $1;
|
|
||||||
}
|
|
||||||
if ($param =~ m/^(.*)(\[\])$/) {
|
|
||||||
$param = $1;
|
|
||||||
push @args, $2;
|
|
||||||
}
|
|
||||||
# print STDERR " :> @args\n";
|
|
||||||
$type = join " ", @args;
|
|
||||||
|
|
||||||
if ($parameters{$param} eq "" && $param != "void") {
|
|
||||||
$parameters{$param} = "-- undescribed --";
|
|
||||||
print STDERR "warning: $lineno: Function parameter '$param' not described in '$function_name'\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
push @parameterlist, $param;
|
|
||||||
$parametertypes{$param} = $type;
|
|
||||||
|
|
||||||
# print STDERR "param = '$param', type = '$type'\n";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
print STDERR "warning: $lineno: Cannot understand prototype: '$prototype'\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($function_only==0 || defined($function_table{$function_name})) {
|
|
||||||
output_function({'function' => $function_name,
|
|
||||||
'module' => $modulename,
|
|
||||||
'sourceversion' => $sourceversion,
|
|
||||||
'include' => $include,
|
|
||||||
'includefuncprefix' => $includefuncprefix,
|
|
||||||
'bugsto' => $bugsto,
|
|
||||||
'pkgname' => $pkgname,
|
|
||||||
'copyright' => $copyright,
|
|
||||||
'verbatimcopying' => $verbatimcopying,
|
|
||||||
'seeinfo' => $seeinfo,
|
|
||||||
'functiontype' => $return_type,
|
|
||||||
'parameterlist' => \@parameterlist,
|
|
||||||
'parameters' => \%parameters,
|
|
||||||
'parametertypes' => \%parametertypes,
|
|
||||||
'sectionlist' => \@sectionlist,
|
|
||||||
'sections' => \%sections,
|
|
||||||
'purpose' => $function_purpose
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# main
|
|
||||||
# states
|
|
||||||
# 0 - normal code
|
|
||||||
# 1 - looking for function name
|
|
||||||
# 2 - scanning field start.
|
|
||||||
# 3 - scanning prototype.
|
|
||||||
$state = 0;
|
|
||||||
$section = "";
|
|
||||||
|
|
||||||
$doc_special = "\@\%\$\#";
|
|
||||||
|
|
||||||
$doc_start = "^/\\*\\*\$";
|
|
||||||
$doc_end = "\\*/";
|
|
||||||
$doc_com = "\\s*\\*\\s*";
|
|
||||||
$doc_func = $doc_com."(\\w+):?";
|
|
||||||
$doc_sect = $doc_com."([".$doc_special."[:upper:]][\\w ]+):\\s*(.*)";
|
|
||||||
$doc_content = $doc_com."(.*)";
|
|
||||||
|
|
||||||
%constants = ();
|
|
||||||
%parameters = ();
|
|
||||||
@parameterlist = ();
|
|
||||||
%sections = ();
|
|
||||||
@sectionlist = ();
|
|
||||||
|
|
||||||
$contents = "";
|
|
||||||
$section_default = "Description"; # default section
|
|
||||||
$section = $section_default;
|
|
||||||
|
|
||||||
$lineno = 0;
|
|
||||||
foreach $file (@ARGV) {
|
|
||||||
if (!open(IN,"<$file")) {
|
|
||||||
print STDERR "Error: Cannot open file $file\n";
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
while (<IN>) {
|
|
||||||
$lineno++;
|
|
||||||
|
|
||||||
if ($state == 0) {
|
|
||||||
if (/$doc_start/o) {
|
|
||||||
$state = 1; # next line is always the function name
|
|
||||||
}
|
|
||||||
} elsif ($state == 1) { # this line is the function name (always)
|
|
||||||
if (/$doc_func/o) {
|
|
||||||
$function = $1;
|
|
||||||
$state = 2;
|
|
||||||
if (/-\s*(.*)/) {
|
|
||||||
$function_purpose = $1;
|
|
||||||
} else {
|
|
||||||
$function_purpose = "";
|
|
||||||
}
|
|
||||||
if ($verbose) {
|
|
||||||
print STDERR "Info($lineno): Scanning doc for $function\n";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
print STDERR "warning: $lineno: Cannot understand $_ on line $lineno",
|
|
||||||
" - I thought it was a doc line\n";
|
|
||||||
$state = 0;
|
|
||||||
}
|
|
||||||
} elsif ($state == 2) { # look for head: lines, and include content
|
|
||||||
if (/$doc_sect/o) {
|
|
||||||
$newsection = $1;
|
|
||||||
$newcontents = $2;
|
|
||||||
|
|
||||||
if ($contents ne "") {
|
|
||||||
dump_section($section, $contents);
|
|
||||||
$section = $section_default;
|
|
||||||
}
|
|
||||||
|
|
||||||
$contents = $newcontents;
|
|
||||||
if ($contents ne "") {
|
|
||||||
$contents .= "\n";
|
|
||||||
}
|
|
||||||
$section = $newsection;
|
|
||||||
} elsif (/$doc_end/) {
|
|
||||||
|
|
||||||
if ($contents ne "") {
|
|
||||||
dump_section($section, $contents);
|
|
||||||
$section = $section_default;
|
|
||||||
$contents = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
# print STDERR "end of doc comment, looking for prototype\n";
|
|
||||||
$prototype = "";
|
|
||||||
$state = 3;
|
|
||||||
} elsif (/$doc_content/) {
|
|
||||||
# miguel-style comment kludge, look for blank lines after
|
|
||||||
# @parameter line to signify start of description
|
|
||||||
if ($1 eq "" && $section =~ m/^@/) {
|
|
||||||
dump_section($section, $contents);
|
|
||||||
$section = $section_default;
|
|
||||||
$contents = "";
|
|
||||||
} else {
|
|
||||||
$contents .= $1."\n";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
# i dont know - bad line? ignore.
|
|
||||||
print STDERR "warning: $lineno: Bad line: $_";
|
|
||||||
}
|
|
||||||
} elsif ($state == 3) { # scanning for function { (end of prototype)
|
|
||||||
if (m#\s*/\*\s+MACDOC\s*#io) {
|
|
||||||
# do nothing
|
|
||||||
}
|
|
||||||
elsif (/([^\{]*)/) {
|
|
||||||
$prototype .= $1;
|
|
||||||
}
|
|
||||||
if (/\{/) {
|
|
||||||
$prototype =~ s@/\*.*?\*/@@gos; # strip comments.
|
|
||||||
$prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
|
|
||||||
$prototype =~ s@^ +@@gos; # strip leading spaces
|
|
||||||
dump_function($prototype);
|
|
||||||
|
|
||||||
$function = "";
|
|
||||||
%constants = ();
|
|
||||||
%parameters = ();
|
|
||||||
%parametertypes = ();
|
|
||||||
@parameterlist = ();
|
|
||||||
%sections = ();
|
|
||||||
@sectionlist = ();
|
|
||||||
$prototype = "";
|
|
||||||
|
|
||||||
$state = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,912 +0,0 @@
|
|||||||
eval '(exit $?0)' && eval 'exec perl -S "$0" ${1+"$@"}'
|
|
||||||
& eval 'exec perl -S "$0" $argv:q'
|
|
||||||
if 0;
|
|
||||||
# Generate documentation from source code.
|
|
||||||
|
|
||||||
## Copyright (c) 2002-2013 Simon Josefsson
|
|
||||||
## added -texinfo, -listfunc, -pkg-name
|
|
||||||
## man page revamp
|
|
||||||
## various improvements
|
|
||||||
## Copyright (c) 2001, 2002 Nikos Mavrogiannopoulos
|
|
||||||
## added -tex
|
|
||||||
## Copyright (c) 1998 Michael Zucchi
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# This will read a C source code file and scan for embedded comments
|
|
||||||
# in the style of gnome comments (+minor extensions - see below).
|
|
||||||
|
|
||||||
# usage:
|
|
||||||
# gdoc [ -docbook | -html | -text | -man | -tex | -texinfo | -listfunc ]
|
|
||||||
# [ -sourceversion verno ] [ -include file | -includefuncprefix ]
|
|
||||||
# [ -bugsto address ] [ -pkg-name packagename ]
|
|
||||||
# [ -seeinfo infonode ] [ -copyright notice ] [ -verbatimcopying ]
|
|
||||||
# [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile
|
|
||||||
#
|
|
||||||
# Set output format using one of -docbook, -html, -text, -man, -tex,
|
|
||||||
# -texinfo, or -listfunc. Default is man.
|
|
||||||
#
|
|
||||||
# -sourceversion
|
|
||||||
# Version number for source code, e.g. '1.0.4'. Used in 'man' headers.
|
|
||||||
# Defaults to using current date.
|
|
||||||
#
|
|
||||||
# -include FILE
|
|
||||||
# For man pages, mention #include <FILE.h> in the synopsis.
|
|
||||||
#
|
|
||||||
# -includefuncprefix
|
|
||||||
# For man pages, mention a #include <FILE.h> in the synopsis.
|
|
||||||
# The FILE derived from the function prefix. For example, a
|
|
||||||
# function gss_init_sec_context will generate an include
|
|
||||||
# statement of #include <gss.h>.
|
|
||||||
#
|
|
||||||
# -bugsto address
|
|
||||||
# For man pages, include a section about reporting bugs and mention
|
|
||||||
# the given e-mail address, e.g 'bug-libidn@gnu.org'.
|
|
||||||
#
|
|
||||||
# -pkg-name packagename
|
|
||||||
# For man pages when -bugsto is used, also include help URLs to the
|
|
||||||
# the project's home page. For example, "GNU Libidn".
|
|
||||||
#
|
|
||||||
# -seeinfo infonode
|
|
||||||
# For man pages, include a section that point to an info manual
|
|
||||||
# for more information.
|
|
||||||
#
|
|
||||||
# -copyright notice
|
|
||||||
# For man pages, include a copyright section with the given
|
|
||||||
# notice after a preamble. Use, e.g., '2002, 2003 Simon Josefsson'.
|
|
||||||
#
|
|
||||||
# -verbatimcopying
|
|
||||||
# For man pages, and when the -copyright parameter is used,
|
|
||||||
# add a licensing statement that say verbatim copying is permitted.
|
|
||||||
#
|
|
||||||
# -function funcname
|
|
||||||
# If set, then only generate documentation for the given function(s). All
|
|
||||||
# other functions are ignored.
|
|
||||||
#
|
|
||||||
# c files - list of 'c' files to process
|
|
||||||
#
|
|
||||||
# All output goes to stdout, with errors to stderr.
|
|
||||||
|
|
||||||
#
|
|
||||||
# format of comments.
|
|
||||||
# In the following table, (...)? signifies optional structure.
|
|
||||||
# (...)* signifies 0 or more structure elements
|
|
||||||
# /**
|
|
||||||
# * function_name(:)? (- short description)?
|
|
||||||
# (* @parameterx: (description of parameter x)?)*
|
|
||||||
# (* a blank line)?
|
|
||||||
# * (Description:)? (Description of function)?
|
|
||||||
# * (Section header: (section description)? )*
|
|
||||||
# (*)?*/
|
|
||||||
#
|
|
||||||
# So .. the trivial example would be:
|
|
||||||
#
|
|
||||||
# /**
|
|
||||||
# * my_function
|
|
||||||
# **/
|
|
||||||
#
|
|
||||||
# If the Description: header tag is ommitted, then there must be a blank line
|
|
||||||
# after the last parameter specification.
|
|
||||||
# e.g.
|
|
||||||
# /**
|
|
||||||
# * my_function - does my stuff
|
|
||||||
# * @my_arg: its mine damnit
|
|
||||||
# *
|
|
||||||
# * Does my stuff explained.
|
|
||||||
# */
|
|
||||||
#
|
|
||||||
# or, could also use:
|
|
||||||
# /**
|
|
||||||
# * my_function - does my stuff
|
|
||||||
# * @my_arg: its mine damnit
|
|
||||||
# * Description: Does my stuff explained.
|
|
||||||
# */
|
|
||||||
# etc.
|
|
||||||
#
|
|
||||||
# All descriptions can be multiline, apart from the short function description.
|
|
||||||
#
|
|
||||||
# All descriptive text is further processed, scanning for the following special
|
|
||||||
# patterns, which are highlighted appropriately.
|
|
||||||
#
|
|
||||||
# 'funcname()' - function
|
|
||||||
# '$ENVVAR' - environmental variable OBSOLETE (?)
|
|
||||||
# '#struct_name' - name of a structure
|
|
||||||
# '@parameter' - name of a parameter
|
|
||||||
# '%CONST' - name of a constant.
|
|
||||||
|
|
||||||
#
|
|
||||||
# Extensions for LaTeX:
|
|
||||||
#
|
|
||||||
# 1. the symbol '->' will be replaced with a rightarrow
|
|
||||||
# 2. x^y with ${x}^{y}$.
|
|
||||||
# 3. xxx\: with xxx:
|
|
||||||
|
|
||||||
use POSIX qw(strftime);
|
|
||||||
|
|
||||||
# match expressions used to find embedded type information
|
|
||||||
$type_constant = "\\\%(\\w+)";
|
|
||||||
$type_func = "(\\w+\\(\\))";
|
|
||||||
$type_param = "\\\@(\\w+)";
|
|
||||||
$type_struct = "\\\#(\\w+)";
|
|
||||||
$type_env = "(\\\$\\w+)";
|
|
||||||
|
|
||||||
|
|
||||||
# Output conversion substitutions.
|
|
||||||
# One for each output format
|
|
||||||
|
|
||||||
# these work fairly well
|
|
||||||
%highlights_html = ( $type_constant, "<i>\$1</i>",
|
|
||||||
$type_func, "<b>\$1</b>",
|
|
||||||
$type_struct, "<i>\$1</i>",
|
|
||||||
$type_param, "<tt><b>\$1</b></tt>" );
|
|
||||||
$blankline_html = "<p>";
|
|
||||||
|
|
||||||
%highlights_texinfo = ( $type_constant, "\\\@code{\$1}",
|
|
||||||
$type_func, "\\\@code{\$1}",
|
|
||||||
$type_struct, "\\\@code{\$1}",
|
|
||||||
$type_param, "\\\@code{\$1}" );
|
|
||||||
$blankline_texinfo = "";
|
|
||||||
|
|
||||||
%highlights_tex = ( $type_constant, "{\\\\it \$1}",
|
|
||||||
$type_func, "{\\\\bf \$1}",
|
|
||||||
$type_struct, "{\\\\it \$1}",
|
|
||||||
$type_param, "{\\\\bf \$1}" );
|
|
||||||
$blankline_tex = "\\\\";
|
|
||||||
|
|
||||||
# sgml, docbook format
|
|
||||||
%highlights_sgml = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
|
|
||||||
$type_func, "<function>\$1</function>",
|
|
||||||
$type_struct, "<structname>\$1</structname>",
|
|
||||||
$type_env, "<envar>\$1</envar>",
|
|
||||||
$type_param, "<parameter>\$1</parameter>" );
|
|
||||||
$blankline_sgml = "</para><para>\n";
|
|
||||||
|
|
||||||
# these are pretty rough
|
|
||||||
%highlights_man = ( $type_constant, "\\\\fB\$1\\\\fP",
|
|
||||||
$type_func, "\\\\fB\$1\\\\fP",
|
|
||||||
$type_struct, "\\\\fB\$1\\\\fP",
|
|
||||||
$type_param, "\\\\fI\$1\\\\fP" );
|
|
||||||
$blankline_man = "";
|
|
||||||
|
|
||||||
# text-mode
|
|
||||||
%highlights_text = ( $type_constant, "\$1",
|
|
||||||
$type_func, "\$1",
|
|
||||||
$type_struct, "\$1",
|
|
||||||
$type_param, "\$1" );
|
|
||||||
$blankline_text = "";
|
|
||||||
|
|
||||||
|
|
||||||
sub usage {
|
|
||||||
print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man | -tex | -texinfo -listfunc ]\n";
|
|
||||||
print " [ -sourceversion verno ] [ -include file | -includefuncprefix ]\n";
|
|
||||||
print " [ -bugsto address ] [ -seeinfo infonode ] [ -copyright notice]\n";
|
|
||||||
print " [ -verbatimcopying ] [ -pkg-name packagename ]\n";
|
|
||||||
print " [ -function funcname [ -function funcname ...] ]\n";
|
|
||||||
print " c source file(s) > outputfile\n";
|
|
||||||
exit 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
# read arguments
|
|
||||||
if ($#ARGV==-1) {
|
|
||||||
usage();
|
|
||||||
}
|
|
||||||
|
|
||||||
$verbose = 0;
|
|
||||||
$output_mode = "man";
|
|
||||||
%highlights = %highlights_man;
|
|
||||||
$blankline = $blankline_man;
|
|
||||||
$modulename = "API Documentation";
|
|
||||||
$sourceversion = strftime "%Y-%m-%d", localtime;
|
|
||||||
$function_only = 0;
|
|
||||||
while ($ARGV[0] =~ m/^-(.*)/) {
|
|
||||||
$cmd = shift @ARGV;
|
|
||||||
if ($cmd eq "-html") {
|
|
||||||
$output_mode = "html";
|
|
||||||
%highlights = %highlights_html;
|
|
||||||
$blankline = $blankline_html;
|
|
||||||
} elsif ($cmd eq "-man") {
|
|
||||||
$output_mode = "man";
|
|
||||||
%highlights = %highlights_man;
|
|
||||||
$blankline = $blankline_man;
|
|
||||||
} elsif ($cmd eq "-tex") {
|
|
||||||
$output_mode = "tex";
|
|
||||||
%highlights = %highlights_tex;
|
|
||||||
$blankline = $blankline_tex;
|
|
||||||
} elsif ($cmd eq "-texinfo") {
|
|
||||||
$output_mode = "texinfo";
|
|
||||||
%highlights = %highlights_texinfo;
|
|
||||||
$blankline = $blankline_texinfo;
|
|
||||||
} elsif ($cmd eq "-text") {
|
|
||||||
$output_mode = "text";
|
|
||||||
%highlights = %highlights_text;
|
|
||||||
$blankline = $blankline_text;
|
|
||||||
} elsif ($cmd eq "-docbook") {
|
|
||||||
$output_mode = "sgml";
|
|
||||||
%highlights = %highlights_sgml;
|
|
||||||
$blankline = $blankline_sgml;
|
|
||||||
} elsif ($cmd eq "-listfunc") {
|
|
||||||
$output_mode = "listfunc";
|
|
||||||
} elsif ($cmd eq "-module") { # not needed for sgml, inherits from calling document
|
|
||||||
$modulename = shift @ARGV;
|
|
||||||
} elsif ($cmd eq "-sourceversion") {
|
|
||||||
$sourceversion = shift @ARGV;
|
|
||||||
} elsif ($cmd eq "-include") {
|
|
||||||
$include = shift @ARGV;
|
|
||||||
} elsif ($cmd eq "-includefuncprefix") {
|
|
||||||
$includefuncprefix = 1;
|
|
||||||
} elsif ($cmd eq "-bugsto") {
|
|
||||||
$bugsto = shift @ARGV;
|
|
||||||
} elsif ($cmd eq "-pkg-name") {
|
|
||||||
$pkgname = shift @ARGV;
|
|
||||||
} elsif ($cmd eq "-copyright") {
|
|
||||||
$copyright = shift @ARGV;
|
|
||||||
} elsif ($cmd eq "-verbatimcopying") {
|
|
||||||
$verbatimcopying = 1;
|
|
||||||
} elsif ($cmd eq "-seeinfo") {
|
|
||||||
$seeinfo = shift @ARGV;
|
|
||||||
} elsif ($cmd eq "-function") { # to only output specific functions
|
|
||||||
$function_only = 1;
|
|
||||||
$function = shift @ARGV;
|
|
||||||
$function_table{$function} = 1;
|
|
||||||
} elsif ($cmd eq "-v") {
|
|
||||||
$verbose = 1;
|
|
||||||
} elsif (($cmd eq "-h") || ($cmd eq "--help")) {
|
|
||||||
usage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
##
|
|
||||||
# dumps section contents to arrays/hashes intended for that purpose.
|
|
||||||
#
|
|
||||||
sub dump_section {
|
|
||||||
my $name = shift @_;
|
|
||||||
my $contents = join "\n", @_;
|
|
||||||
|
|
||||||
if ($name =~ m/$type_constant/) {
|
|
||||||
$name = $1;
|
|
||||||
# print STDERR "constant section '$1' = '$contents'\n";
|
|
||||||
$constants{$name} = $contents;
|
|
||||||
} elsif ($name =~ m/$type_param/) {
|
|
||||||
# print STDERR "parameter def '$1' = '$contents'\n";
|
|
||||||
$name = $1;
|
|
||||||
$parameters{$name} = $contents;
|
|
||||||
} else {
|
|
||||||
# print STDERR "other section '$name' = '$contents'\n";
|
|
||||||
$sections{$name} = $contents;
|
|
||||||
push @sectionlist, $name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
##
|
|
||||||
# output function
|
|
||||||
#
|
|
||||||
# parameters, a hash.
|
|
||||||
# function => "function name"
|
|
||||||
# parameterlist => @list of parameters
|
|
||||||
# parameters => %parameter descriptions
|
|
||||||
# sectionlist => @list of sections
|
|
||||||
# sections => %descriont descriptions
|
|
||||||
#
|
|
||||||
|
|
||||||
sub repstr {
|
|
||||||
$pattern = shift;
|
|
||||||
$repl = shift;
|
|
||||||
$match1 = shift;
|
|
||||||
$match2 = shift;
|
|
||||||
$match3 = shift;
|
|
||||||
$match4 = shift;
|
|
||||||
|
|
||||||
$output = $repl;
|
|
||||||
$output =~ s,\$1,$match1,g;
|
|
||||||
$output =~ s,\$2,$match2,g;
|
|
||||||
$output =~ s,\$3,$match3,g;
|
|
||||||
$output =~ s,\$4,$match4,g;
|
|
||||||
|
|
||||||
eval "\$return = qq/$output/";
|
|
||||||
|
|
||||||
# print "pattern $pattern matched 1=$match1 2=$match2 3=$match3 4=$match4 replace $repl yielded $output interpolated $return\n";
|
|
||||||
|
|
||||||
$return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub just_highlight {
|
|
||||||
my $contents = join "\n", @_;
|
|
||||||
my $line;
|
|
||||||
my $ret = "";
|
|
||||||
|
|
||||||
foreach $pattern (keys %highlights) {
|
|
||||||
# print "scanning pattern $pattern ($highlights{$pattern})\n";
|
|
||||||
$contents =~ s:$pattern:repstr($pattern, $highlights{$pattern}, $1, $2, $3, $4):gse;
|
|
||||||
}
|
|
||||||
foreach $line (split "\n", $contents) {
|
|
||||||
if ($line eq ""){
|
|
||||||
$ret = $ret . $lineprefix . $blankline;
|
|
||||||
} else {
|
|
||||||
$ret = $ret . $lineprefix . $line;
|
|
||||||
}
|
|
||||||
$ret = $ret . "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub output_highlight {
|
|
||||||
print (just_highlight (@_));
|
|
||||||
}
|
|
||||||
|
|
||||||
# output in texinfo
|
|
||||||
sub output_texinfo {
|
|
||||||
my %args = %{$_[0]};
|
|
||||||
my ($parameter, $section);
|
|
||||||
my $count;
|
|
||||||
|
|
||||||
print "\@subheading ".$args{'function'}."\n";
|
|
||||||
print "\@anchor{".$args{'function'}."}\n";
|
|
||||||
print "\@deftypefun {" . $args{'functiontype'} . "} ";
|
|
||||||
print "{".$args{'function'}."} ";
|
|
||||||
print "(";
|
|
||||||
$count = 0;
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
print $args{'parametertypes'}{$parameter}." \@var{".$parameter."}";
|
|
||||||
if ($count != $#{$args{'parameterlist'}}) {
|
|
||||||
$count++;
|
|
||||||
print ", ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print ")\n";
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
if ($args{'parameters'}{$parameter}) {
|
|
||||||
print "\@var{".$parameter."}: ";
|
|
||||||
output_highlight($args{'parameters'}{$parameter});
|
|
||||||
print "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach $section (@{$args{'sectionlist'}}) {
|
|
||||||
print "\n\@strong{$section:} " if $section ne $section_default;
|
|
||||||
$args{'sections'}{$section} =~ s:([{}]):\@\1:gs;
|
|
||||||
output_highlight($args{'sections'}{$section});
|
|
||||||
}
|
|
||||||
print "\@end deftypefun\n\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
# output in html
|
|
||||||
sub output_html {
|
|
||||||
my %args = %{$_[0]};
|
|
||||||
my ($parameter, $section);
|
|
||||||
my $count;
|
|
||||||
print "\n\n<a name=\"". $args{'function'} . "\"> </a><h2>Function</h2>\n";
|
|
||||||
|
|
||||||
print "<i>".$args{'functiontype'}."</i>\n";
|
|
||||||
print "<b>".$args{'function'}."</b>\n";
|
|
||||||
print "(";
|
|
||||||
$count = 0;
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
print "<i>".$args{'parametertypes'}{$parameter}."</i> <b>".$parameter."</b>\n";
|
|
||||||
if ($count != $#{$args{'parameterlist'}}) {
|
|
||||||
$count++;
|
|
||||||
print ", ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print ")\n";
|
|
||||||
|
|
||||||
print "<h3>Arguments</h3>\n";
|
|
||||||
print "<dl>\n";
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
print "<dt><i>".$args{'parametertypes'}{$parameter}."</i> <b>".$parameter."</b>\n";
|
|
||||||
print "<dd>";
|
|
||||||
output_highlight($args{'parameters'}{$parameter});
|
|
||||||
}
|
|
||||||
print "</dl>\n";
|
|
||||||
foreach $section (@{$args{'sectionlist'}}) {
|
|
||||||
print "<h3>$section</h3>\n";
|
|
||||||
print "<ul>\n";
|
|
||||||
output_highlight($args{'sections'}{$section});
|
|
||||||
print "</ul>\n";
|
|
||||||
}
|
|
||||||
print "<hr>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
# output in tex
|
|
||||||
sub output_tex {
|
|
||||||
my %args = %{$_[0]};
|
|
||||||
my ($parameter, $section);
|
|
||||||
my $count;
|
|
||||||
my $func = $args{'function'};
|
|
||||||
my $param;
|
|
||||||
my $param2;
|
|
||||||
my $sec;
|
|
||||||
my $check;
|
|
||||||
my $type;
|
|
||||||
|
|
||||||
$func =~ s/_/\\_/g;
|
|
||||||
|
|
||||||
print "\n\n\\subsection{". $func . "}\n\\label{" . $args{'function'} . "}\n";
|
|
||||||
|
|
||||||
$type = $args{'functiontype'};
|
|
||||||
$type =~ s/_/\\_/g;
|
|
||||||
|
|
||||||
print "{\\it ".$type."}\n";
|
|
||||||
print "{\\bf ".$func."}\n";
|
|
||||||
print "(";
|
|
||||||
$count = 0;
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
$param = $args{'parametertypes'}{$parameter};
|
|
||||||
$param2 = $parameter;
|
|
||||||
$param =~ s/_/\\_/g;
|
|
||||||
$param2 =~ s/_/\\_/g;
|
|
||||||
|
|
||||||
print "{\\it ".$param."} {\\bf ".$param2."}";
|
|
||||||
if ($count != $#{$args{'parameterlist'}}) {
|
|
||||||
$count++;
|
|
||||||
print ", ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print ")\n";
|
|
||||||
|
|
||||||
print "\n{\\large{Arguments}}\n";
|
|
||||||
|
|
||||||
print "\\begin{itemize}\n";
|
|
||||||
$check=0;
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
$param1 = $args{'parametertypes'}{$parameter};
|
|
||||||
$param1 =~ s/_/\\_/g;
|
|
||||||
$param2 = $parameter;
|
|
||||||
$param2 =~ s/_/\\_/g;
|
|
||||||
|
|
||||||
$check = 1;
|
|
||||||
print "\\item {\\it ".$param1."} {\\bf ".$param2."}: \n";
|
|
||||||
# print "\n";
|
|
||||||
|
|
||||||
$param3 = $args{'parameters'}{$parameter};
|
|
||||||
$param3 =~ s/#([a-zA-Z\_]+)/{\\it \1}/g;
|
|
||||||
|
|
||||||
$out = just_highlight($param3);
|
|
||||||
$out =~ s/_/\\_/g;
|
|
||||||
print $out;
|
|
||||||
}
|
|
||||||
if ($check==0) {
|
|
||||||
print "\\item void\n";
|
|
||||||
}
|
|
||||||
print "\\end{itemize}\n";
|
|
||||||
|
|
||||||
foreach $section (@{$args{'sectionlist'}}) {
|
|
||||||
$sec = $section;
|
|
||||||
$sec =~ s/_/\\_/g;
|
|
||||||
$sec =~ s/#([a-zA-Z\_]+)/{\\it \1}/g;
|
|
||||||
|
|
||||||
print "\n{\\large{$sec}}\\\\\n";
|
|
||||||
print "\\begin{rmfamily}\n";
|
|
||||||
|
|
||||||
$sec = $args{'sections'}{$section};
|
|
||||||
$sec =~ s/\\:/:/g;
|
|
||||||
$sec =~ s/#([a-zA-Z\_]+)/{\\it \1}/g;
|
|
||||||
$sec =~ s/->/\$\\rightarrow\$/g;
|
|
||||||
$sec =~ s/([0-9]+)\^([0-9]+)/\$\{\1\}\^\{\2\}\$/g;
|
|
||||||
|
|
||||||
$out = just_highlight($sec);
|
|
||||||
$out =~ s/_/\\_/g;
|
|
||||||
|
|
||||||
print $out;
|
|
||||||
print "\\end{rmfamily}\n";
|
|
||||||
}
|
|
||||||
print "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# output in sgml DocBook
|
|
||||||
sub output_sgml {
|
|
||||||
my %args = %{$_[0]};
|
|
||||||
my ($parameter, $section);
|
|
||||||
my $count;
|
|
||||||
my $id;
|
|
||||||
|
|
||||||
$id = $args{'module'}."-".$args{'function'};
|
|
||||||
$id =~ s/[^A-Za-z0-9]/-/g;
|
|
||||||
|
|
||||||
print "<refentry>\n";
|
|
||||||
print "<refmeta>\n";
|
|
||||||
print "<refentrytitle><phrase id=\"$id\">".$args{'function'}."</phrase></refentrytitle>\n";
|
|
||||||
print "</refmeta>\n";
|
|
||||||
print "<refnamediv>\n";
|
|
||||||
print " <refname>".$args{'function'}."</refname>\n";
|
|
||||||
print " <refpurpose>\n";
|
|
||||||
print " ".$args{'purpose'}."\n";
|
|
||||||
print " </refpurpose>\n";
|
|
||||||
print "</refnamediv>\n";
|
|
||||||
|
|
||||||
print "<refsynopsisdiv>\n";
|
|
||||||
print " <title>Synopsis</title>\n";
|
|
||||||
print " <funcsynopsis>\n";
|
|
||||||
print " <funcdef>".$args{'functiontype'}." ";
|
|
||||||
print "<function>".$args{'function'}." ";
|
|
||||||
print "</function></funcdef>\n";
|
|
||||||
|
|
||||||
# print "<refsect1>\n";
|
|
||||||
# print " <title>Synopsis</title>\n";
|
|
||||||
# print " <funcsynopsis>\n";
|
|
||||||
# print " <funcdef>".$args{'functiontype'}." ";
|
|
||||||
# print "<function>".$args{'function'}." ";
|
|
||||||
# print "</function></funcdef>\n";
|
|
||||||
|
|
||||||
$count = 0;
|
|
||||||
if ($#{$args{'parameterlist'}} >= 0) {
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
print " <paramdef>".$args{'parametertypes'}{$parameter};
|
|
||||||
print " <parameter>$parameter</parameter></paramdef>\n";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
print " <void>\n";
|
|
||||||
}
|
|
||||||
print " </funcsynopsis>\n";
|
|
||||||
print "</refsynopsisdiv>\n";
|
|
||||||
# print "</refsect1>\n";
|
|
||||||
|
|
||||||
# print parameters
|
|
||||||
print "<refsect1>\n <title>Arguments</title>\n";
|
|
||||||
# print "<para>\nArguments\n";
|
|
||||||
if ($#{$args{'parameterlist'}} >= 0) {
|
|
||||||
print " <variablelist>\n";
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
|
|
||||||
print " <listitem>\n <para>\n";
|
|
||||||
$lineprefix=" ";
|
|
||||||
output_highlight($args{'parameters'}{$parameter});
|
|
||||||
print " </para>\n </listitem>\n </varlistentry>\n";
|
|
||||||
}
|
|
||||||
print " </variablelist>\n";
|
|
||||||
} else {
|
|
||||||
print " <para>\n None\n </para>\n";
|
|
||||||
}
|
|
||||||
print "</refsect1>\n";
|
|
||||||
|
|
||||||
# print out each section
|
|
||||||
$lineprefix=" ";
|
|
||||||
foreach $section (@{$args{'sectionlist'}}) {
|
|
||||||
print "<refsect1>\n <title>$section</title>\n <para>\n";
|
|
||||||
# print "<para>\n$section\n";
|
|
||||||
if ($section =~ m/EXAMPLE/i) {
|
|
||||||
print "<example><para>\n";
|
|
||||||
}
|
|
||||||
output_highlight($args{'sections'}{$section});
|
|
||||||
# print "</para>";
|
|
||||||
if ($section =~ m/EXAMPLE/i) {
|
|
||||||
print "</para></example>\n";
|
|
||||||
}
|
|
||||||
print " </para>\n</refsect1>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
print "\n\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
##
|
|
||||||
# output in man
|
|
||||||
sub output_man {
|
|
||||||
my %args = %{$_[0]};
|
|
||||||
my ($parameter, $section);
|
|
||||||
my $count;
|
|
||||||
|
|
||||||
print ".\\\" DO NOT MODIFY THIS FILE! It was generated by gdoc.\n";
|
|
||||||
print ".TH \"$args{'function'}\" 3 \"$args{'sourceversion'}\" \"". $args{'module'} . "\" \"". $args{'module'} . "\"\n";
|
|
||||||
|
|
||||||
print ".SH NAME\n";
|
|
||||||
|
|
||||||
print $args{'function'};
|
|
||||||
if ($args{'purpose'}) {
|
|
||||||
print " \\- " . $args{'purpose'} . "\n";
|
|
||||||
} else {
|
|
||||||
print " \\- API function\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
print ".SH SYNOPSIS\n";
|
|
||||||
print ".B #include <". $args{'include'} . ">\n"
|
|
||||||
if $args{'include'};
|
|
||||||
print ".B #include <". lc((split /_/, $args{'function'})[0]) . ".h>\n"
|
|
||||||
if $args{'includefuncprefix'};
|
|
||||||
print ".sp\n";
|
|
||||||
print ".BI \"".$args{'functiontype'}." ".$args{'function'}."(";
|
|
||||||
$count = 0;
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
print $args{'parametertypes'}{$parameter}." \" ".$parameter." \"";
|
|
||||||
if ($count != $#{$args{'parameterlist'}}) {
|
|
||||||
$count++;
|
|
||||||
print ", ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print ");\"\n";
|
|
||||||
|
|
||||||
print ".SH ARGUMENTS\n";
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
print ".IP \"".$args{'parametertypes'}{$parameter}." ".$parameter."\" 12\n";
|
|
||||||
$param = $args{'parameters'}{$parameter};
|
|
||||||
$param =~ s/-/\\-/g;
|
|
||||||
output_highlight($param);
|
|
||||||
}
|
|
||||||
foreach $section (@{$args{'sectionlist'}}) {
|
|
||||||
print ".SH \"" . uc($section) . "\"\n";
|
|
||||||
$sec = $args{'sections'}{$section};
|
|
||||||
$sec =~ s/-/\\-/g;
|
|
||||||
output_highlight($sec);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($args{'bugsto'}) {
|
|
||||||
print ".SH \"REPORTING BUGS\"\n";
|
|
||||||
print "Report bugs to <". $args{'bugsto'} . ">.\n";
|
|
||||||
if ($args{'pkgname'}) {
|
|
||||||
print $args{'pkgname'} . " home page: " .
|
|
||||||
"http://www.gnu.org/software/" . $args{'module'} . "/\n";
|
|
||||||
}
|
|
||||||
print "General help using GNU software: http://www.gnu.org/gethelp/\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($args{'copyright'}) {
|
|
||||||
print ".SH COPYRIGHT\n";
|
|
||||||
print "Copyright \\(co ". $args{'copyright'} . ".\n";
|
|
||||||
if ($args{'verbatimcopying'}) {
|
|
||||||
print ".br\n";
|
|
||||||
print "Copying and distribution of this file, with or without modification,\n";
|
|
||||||
print "are permitted in any medium without royalty provided the copyright\n";
|
|
||||||
print "notice and this notice are preserved.\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($args{'seeinfo'}) {
|
|
||||||
print ".SH \"SEE ALSO\"\n";
|
|
||||||
print "The full documentation for\n";
|
|
||||||
print ".B " . $args{'module'} . "\n";
|
|
||||||
print "is maintained as a Texinfo manual. If the\n";
|
|
||||||
print ".B info\n";
|
|
||||||
print "and\n";
|
|
||||||
print ".B " . $args{'module'} . "\n";
|
|
||||||
print "programs are properly installed at your site, the command\n";
|
|
||||||
print ".IP\n";
|
|
||||||
print ".B info " . $args{'seeinfo'} . "\n";
|
|
||||||
print ".PP\n";
|
|
||||||
print "should give you access to the complete manual.\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub output_listfunc {
|
|
||||||
my %args = %{$_[0]};
|
|
||||||
print $args{'function'} . "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
##
|
|
||||||
# output in text
|
|
||||||
sub output_text {
|
|
||||||
my %args = %{$_[0]};
|
|
||||||
my ($parameter, $section);
|
|
||||||
|
|
||||||
print "Function = ".$args{'function'}."\n";
|
|
||||||
print " return type: ".$args{'functiontype'}."\n\n";
|
|
||||||
foreach $parameter (@{$args{'parameterlist'}}) {
|
|
||||||
print " ".$args{'parametertypes'}{$parameter}." ".$parameter."\n";
|
|
||||||
print " -> ".$args{'parameters'}{$parameter}."\n";
|
|
||||||
}
|
|
||||||
foreach $section (@{$args{'sectionlist'}}) {
|
|
||||||
print " $section:\n";
|
|
||||||
print " -> ";
|
|
||||||
output_highlight($args{'sections'}{$section});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
##
|
|
||||||
# generic output function - calls the right one based
|
|
||||||
# on current output mode.
|
|
||||||
sub output_function {
|
|
||||||
# output_html(@_);
|
|
||||||
eval "output_".$output_mode."(\@_);";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
##
|
|
||||||
# takes a function prototype and spits out all the details
|
|
||||||
# stored in the global arrays/hsahes.
|
|
||||||
sub dump_function {
|
|
||||||
my $prototype = shift @_;
|
|
||||||
|
|
||||||
if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
|
|
||||||
$prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
|
|
||||||
$prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
|
|
||||||
$prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
|
|
||||||
$prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/) {
|
|
||||||
$return_type = $1;
|
|
||||||
$function_name = $2;
|
|
||||||
$args = $3;
|
|
||||||
|
|
||||||
# print STDERR "ARGS = '$args'\n";
|
|
||||||
|
|
||||||
foreach $arg (split ',', $args) {
|
|
||||||
# strip leading/trailing spaces
|
|
||||||
$arg =~ s/^\s*//;
|
|
||||||
$arg =~ s/\s*$//;
|
|
||||||
# print STDERR "SCAN ARG: '$arg'\n";
|
|
||||||
@args = split('\s', $arg);
|
|
||||||
|
|
||||||
# print STDERR " -> @args\n";
|
|
||||||
$param = pop @args;
|
|
||||||
# print STDERR " -> @args\n";
|
|
||||||
if ($param =~ m/^(\*+)(.*)/) {
|
|
||||||
$param = $2;
|
|
||||||
push @args, $1;
|
|
||||||
}
|
|
||||||
if ($param =~ m/^(.*)(\[\])$/) {
|
|
||||||
$param = $1;
|
|
||||||
push @args, $2;
|
|
||||||
}
|
|
||||||
# print STDERR " :> @args\n";
|
|
||||||
$type = join " ", @args;
|
|
||||||
|
|
||||||
if ($parameters{$param} eq "" && $param != "void") {
|
|
||||||
$parameters{$param} = "-- undescribed --";
|
|
||||||
print STDERR "warning: $lineno: Function parameter '$param' not described in '$function_name'\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
push @parameterlist, $param;
|
|
||||||
$parametertypes{$param} = $type;
|
|
||||||
|
|
||||||
# print STDERR "param = '$param', type = '$type'\n";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
print STDERR "warning: $lineno: Cannot understand prototype: '$prototype'\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($function_only==0 || defined($function_table{$function_name})) {
|
|
||||||
output_function({'function' => $function_name,
|
|
||||||
'module' => $modulename,
|
|
||||||
'sourceversion' => $sourceversion,
|
|
||||||
'include' => $include,
|
|
||||||
'includefuncprefix' => $includefuncprefix,
|
|
||||||
'bugsto' => $bugsto,
|
|
||||||
'pkgname' => $pkgname,
|
|
||||||
'copyright' => $copyright,
|
|
||||||
'verbatimcopying' => $verbatimcopying,
|
|
||||||
'seeinfo' => $seeinfo,
|
|
||||||
'functiontype' => $return_type,
|
|
||||||
'parameterlist' => \@parameterlist,
|
|
||||||
'parameters' => \%parameters,
|
|
||||||
'parametertypes' => \%parametertypes,
|
|
||||||
'sectionlist' => \@sectionlist,
|
|
||||||
'sections' => \%sections,
|
|
||||||
'purpose' => $function_purpose
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# main
|
|
||||||
# states
|
|
||||||
# 0 - normal code
|
|
||||||
# 1 - looking for function name
|
|
||||||
# 2 - scanning field start.
|
|
||||||
# 3 - scanning prototype.
|
|
||||||
$state = 0;
|
|
||||||
$section = "";
|
|
||||||
|
|
||||||
$doc_special = "\@\%\$\#";
|
|
||||||
|
|
||||||
$doc_start = "^/\\*\\*\$";
|
|
||||||
$doc_end = "\\*/";
|
|
||||||
$doc_com = "\\s*\\*\\s*";
|
|
||||||
$doc_func = $doc_com."(\\w+):?";
|
|
||||||
$doc_sect = $doc_com."([".$doc_special."[:upper:]][\\w ]+):\\s*(.*)";
|
|
||||||
$doc_content = $doc_com."(.*)";
|
|
||||||
|
|
||||||
%constants = ();
|
|
||||||
%parameters = ();
|
|
||||||
@parameterlist = ();
|
|
||||||
%sections = ();
|
|
||||||
@sectionlist = ();
|
|
||||||
|
|
||||||
$contents = "";
|
|
||||||
$section_default = "Description"; # default section
|
|
||||||
$section = $section_default;
|
|
||||||
|
|
||||||
$lineno = 0;
|
|
||||||
foreach $file (@ARGV) {
|
|
||||||
if (!open(IN,"<$file")) {
|
|
||||||
print STDERR "Error: Cannot open file $file\n";
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
while (<IN>) {
|
|
||||||
$lineno++;
|
|
||||||
|
|
||||||
if ($state == 0) {
|
|
||||||
if (/$doc_start/o) {
|
|
||||||
$state = 1; # next line is always the function name
|
|
||||||
}
|
|
||||||
} elsif ($state == 1) { # this line is the function name (always)
|
|
||||||
if (/$doc_func/o) {
|
|
||||||
$function = $1;
|
|
||||||
$state = 2;
|
|
||||||
if (/-\s*(.*)/) {
|
|
||||||
$function_purpose = $1;
|
|
||||||
} else {
|
|
||||||
$function_purpose = "";
|
|
||||||
}
|
|
||||||
if ($verbose) {
|
|
||||||
print STDERR "Info($lineno): Scanning doc for $function\n";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
print STDERR "warning: $lineno: Cannot understand $_ on line $lineno",
|
|
||||||
" - I thought it was a doc line\n";
|
|
||||||
$state = 0;
|
|
||||||
}
|
|
||||||
} elsif ($state == 2) { # look for head: lines, and include content
|
|
||||||
if (/$doc_sect/o) {
|
|
||||||
$newsection = $1;
|
|
||||||
$newcontents = $2;
|
|
||||||
|
|
||||||
if ($contents ne "") {
|
|
||||||
dump_section($section, $contents);
|
|
||||||
$section = $section_default;
|
|
||||||
}
|
|
||||||
|
|
||||||
$contents = $newcontents;
|
|
||||||
if ($contents ne "") {
|
|
||||||
$contents .= "\n";
|
|
||||||
}
|
|
||||||
$section = $newsection;
|
|
||||||
} elsif (/$doc_end/) {
|
|
||||||
|
|
||||||
if ($contents ne "") {
|
|
||||||
dump_section($section, $contents);
|
|
||||||
$section = $section_default;
|
|
||||||
$contents = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
# print STDERR "end of doc comment, looking for prototype\n";
|
|
||||||
$prototype = "";
|
|
||||||
$state = 3;
|
|
||||||
} elsif (/$doc_content/) {
|
|
||||||
# miguel-style comment kludge, look for blank lines after
|
|
||||||
# @parameter line to signify start of description
|
|
||||||
if ($1 eq "" && $section =~ m/^@/) {
|
|
||||||
dump_section($section, $contents);
|
|
||||||
$section = $section_default;
|
|
||||||
$contents = "";
|
|
||||||
} else {
|
|
||||||
$contents .= $1."\n";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
# i dont know - bad line? ignore.
|
|
||||||
print STDERR "warning: $lineno: Bad line: $_";
|
|
||||||
}
|
|
||||||
} elsif ($state == 3) { # scanning for function { (end of prototype)
|
|
||||||
if (m#\s*/\*\s+MACDOC\s*#io) {
|
|
||||||
# do nothing
|
|
||||||
}
|
|
||||||
elsif (/([^\{]*)/) {
|
|
||||||
$prototype .= $1;
|
|
||||||
}
|
|
||||||
if (/\{/) {
|
|
||||||
$prototype =~ s@/\*.*?\*/@@gos; # strip comments.
|
|
||||||
$prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
|
|
||||||
$prototype =~ s@^ +@@gos; # strip leading spaces
|
|
||||||
dump_function($prototype);
|
|
||||||
|
|
||||||
$function = "";
|
|
||||||
%constants = ();
|
|
||||||
%parameters = ();
|
|
||||||
%parametertypes = ();
|
|
||||||
@parameterlist = ();
|
|
||||||
%sections = ();
|
|
||||||
@sectionlist = ();
|
|
||||||
$prototype = "";
|
|
||||||
|
|
||||||
$state = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,732 +0,0 @@
|
|||||||
@node Copying
|
|
||||||
|
|
||||||
@unnumbered GNU General Public License
|
|
||||||
@center Version 3, 29 June 2007
|
|
||||||
|
|
||||||
@c This file is intended to be included in another file.
|
|
||||||
|
|
||||||
@display
|
|
||||||
Copyright @copyright{} 2007 Free Software Foundation, Inc. @url{http://fsf.org/}
|
|
||||||
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies of this
|
|
||||||
license document, but changing it is not allowed.
|
|
||||||
@end display
|
|
||||||
|
|
||||||
@unnumberedsec Preamble
|
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
|
||||||
software and other kinds of works.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
the GNU General Public License is intended to guarantee your freedom
|
|
||||||
to share and change all versions of a program--to make sure it remains
|
|
||||||
free software for all its users. We, the Free Software Foundation,
|
|
||||||
use the GNU General Public License for most of our software; it
|
|
||||||
applies also to any other work released this way by its authors. You
|
|
||||||
can apply it to your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
|
||||||
these rights or asking you to surrender the rights. Therefore, you
|
|
||||||
have certain responsibilities if you distribute copies of the
|
|
||||||
software, or if you modify it: responsibilities to respect the freedom
|
|
||||||
of others.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
|
||||||
freedoms that you received. You must make sure that they, too,
|
|
||||||
receive or can get the source code. And you must show them these
|
|
||||||
terms so they know their rights.
|
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
|
||||||
that there is no warranty for this free software. For both users' and
|
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
|
||||||
changed, so that their problems will not be attributed erroneously to
|
|
||||||
authors of previous versions.
|
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
|
||||||
modified versions of the software inside them, although the
|
|
||||||
manufacturer can do so. This is fundamentally incompatible with the
|
|
||||||
aim of protecting users' freedom to change the software. The
|
|
||||||
systematic pattern of such abuse occurs in the area of products for
|
|
||||||
individuals to use, which is precisely where it is most unacceptable.
|
|
||||||
Therefore, we have designed this version of the GPL to prohibit the
|
|
||||||
practice for those products. If such problems arise substantially in
|
|
||||||
other domains, we stand ready to extend this provision to those
|
|
||||||
domains in future versions of the GPL, as needed to protect the
|
|
||||||
freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish
|
|
||||||
to avoid the special danger that patents applied to a free program
|
|
||||||
could make it effectively proprietary. To prevent this, the GPL
|
|
||||||
assures that patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
@iftex
|
|
||||||
@unnumberedsec TERMS AND CONDITIONS
|
|
||||||
@end iftex
|
|
||||||
@ifinfo
|
|
||||||
@center TERMS AND CONDITIONS
|
|
||||||
@end ifinfo
|
|
||||||
|
|
||||||
@enumerate 0
|
|
||||||
@item Definitions.
|
|
||||||
|
|
||||||
``This License'' refers to version 3 of the GNU General Public License.
|
|
||||||
|
|
||||||
``Copyright'' also means copyright-like laws that apply to other kinds
|
|
||||||
of works, such as semiconductor masks.
|
|
||||||
|
|
||||||
``The Program'' refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as ``you''. ``Licensees'' and
|
|
||||||
``recipients'' may be individuals or organizations.
|
|
||||||
|
|
||||||
To ``modify'' a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of
|
|
||||||
an exact copy. The resulting work is called a ``modified version'' of
|
|
||||||
the earlier work or a work ``based on'' the earlier work.
|
|
||||||
|
|
||||||
A ``covered work'' means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To ``propagate'' a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To ``convey'' a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user
|
|
||||||
through a computer network, with no transfer of a copy, is not
|
|
||||||
conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays ``Appropriate Legal Notices'' to
|
|
||||||
the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
@item Source Code.
|
|
||||||
|
|
||||||
The ``source code'' for a work means the preferred form of the work for
|
|
||||||
making modifications to it. ``Object code'' means any non-source form
|
|
||||||
of a work.
|
|
||||||
|
|
||||||
A ``Standard Interface'' means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The ``System Libraries'' of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
``Major Component'', in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The ``Corresponding Source'' for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users can
|
|
||||||
regenerate automatically from other parts of the Corresponding Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that same
|
|
||||||
work.
|
|
||||||
|
|
||||||
@item Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not convey,
|
|
||||||
without conditions so long as your license otherwise remains in force.
|
|
||||||
You may convey covered works to others for the sole purpose of having
|
|
||||||
them make modifications exclusively for you, or provide you with
|
|
||||||
facilities for running those works, provided that you comply with the
|
|
||||||
terms of this License in conveying all material for which you do not
|
|
||||||
control copyright. Those thus making or running the covered works for
|
|
||||||
you must do so exclusively on your behalf, under your direction and
|
|
||||||
control, on terms that prohibit them from making any copies of your
|
|
||||||
copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under the
|
|
||||||
conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
@item Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such
|
|
||||||
circumvention is effected by exercising rights under this License with
|
|
||||||
respect to the covered work, and you disclaim any intention to limit
|
|
||||||
operation or modification of the work as a means of enforcing, against
|
|
||||||
the work's users, your or third parties' legal rights to forbid
|
|
||||||
circumvention of technological measures.
|
|
||||||
|
|
||||||
@item Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
@item Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these
|
|
||||||
conditions:
|
|
||||||
|
|
||||||
@enumerate a
|
|
||||||
@item
|
|
||||||
The work must carry prominent notices stating that you modified it,
|
|
||||||
and giving a relevant date.
|
|
||||||
|
|
||||||
@item
|
|
||||||
The work must carry prominent notices stating that it is released
|
|
||||||
under this License and any conditions added under section 7. This
|
|
||||||
requirement modifies the requirement in section 4 to ``keep intact all
|
|
||||||
notices''.
|
|
||||||
|
|
||||||
@item
|
|
||||||
You must license the entire work, as a whole, under this License to
|
|
||||||
anyone who comes into possession of a copy. This License will
|
|
||||||
therefore apply, along with any applicable section 7 additional terms,
|
|
||||||
to the whole of the work, and all its parts, regardless of how they
|
|
||||||
are packaged. This License gives no permission to license the work in
|
|
||||||
any other way, but it does not invalidate such permission if you have
|
|
||||||
separately received it.
|
|
||||||
|
|
||||||
@item
|
|
||||||
If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your work
|
|
||||||
need not make them do so.
|
|
||||||
@end enumerate
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
``aggregate'' if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
@item Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms of
|
|
||||||
sections 4 and 5, provided that you also convey the machine-readable
|
|
||||||
Corresponding Source under the terms of this License, in one of these
|
|
||||||
ways:
|
|
||||||
|
|
||||||
@enumerate a
|
|
||||||
@item
|
|
||||||
Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium customarily
|
|
||||||
used for software interchange.
|
|
||||||
|
|
||||||
@item
|
|
||||||
Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a written
|
|
||||||
offer, valid for at least three years and valid for as long as you
|
|
||||||
offer spare parts or customer support for that product model, to give
|
|
||||||
anyone who possesses the object code either (1) a copy of the
|
|
||||||
Corresponding Source for all the software in the product that is
|
|
||||||
covered by this License, on a durable physical medium customarily used
|
|
||||||
for software interchange, for a price no more than your reasonable
|
|
||||||
cost of physically performing this conveying of source, or (2) access
|
|
||||||
to copy the Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
@item
|
|
||||||
Convey individual copies of the object code with a copy of the written
|
|
||||||
offer to provide the Corresponding Source. This alternative is
|
|
||||||
allowed only occasionally and noncommercially, and only if you
|
|
||||||
received the object code with such an offer, in accord with subsection
|
|
||||||
6b.
|
|
||||||
|
|
||||||
@item
|
|
||||||
Convey the object code by offering access from a designated place
|
|
||||||
(gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to copy
|
|
||||||
the object code is a network server, the Corresponding Source may be
|
|
||||||
on a different server (operated by you or a third party) that supports
|
|
||||||
equivalent copying facilities, provided you maintain clear directions
|
|
||||||
next to the object code saying where to find the Corresponding Source.
|
|
||||||
Regardless of what server hosts the Corresponding Source, you remain
|
|
||||||
obligated to ensure that it is available for as long as needed to
|
|
||||||
satisfy these requirements.
|
|
||||||
|
|
||||||
@item
|
|
||||||
Convey the object code using peer-to-peer transmission, provided you
|
|
||||||
inform other peers where the object code and Corresponding Source of
|
|
||||||
the work are being offered to the general public at no charge under
|
|
||||||
subsection 6d.
|
|
||||||
|
|
||||||
@end enumerate
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A ``User Product'' is either (1) a ``consumer product'', which means any
|
|
||||||
tangible personal property which is normally used for personal,
|
|
||||||
family, or household purposes, or (2) anything designed or sold for
|
|
||||||
incorporation into a dwelling. In determining whether a product is a
|
|
||||||
consumer product, doubtful cases shall be resolved in favor of
|
|
||||||
coverage. For a particular product received by a particular user,
|
|
||||||
``normally used'' refers to a typical or common use of that class of
|
|
||||||
product, regardless of the status of the particular user or of the way
|
|
||||||
in which the particular user actually uses, or expects or is expected
|
|
||||||
to use, the product. A product is a consumer product regardless of
|
|
||||||
whether the product has substantial commercial, industrial or
|
|
||||||
non-consumer uses, unless such uses represent the only significant
|
|
||||||
mode of use of the product.
|
|
||||||
|
|
||||||
``Installation Information'' for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to
|
|
||||||
install and execute modified versions of a covered work in that User
|
|
||||||
Product from a modified version of its Corresponding Source. The
|
|
||||||
information must suffice to ensure that the continued functioning of
|
|
||||||
the modified object code is in no case prevented or interfered with
|
|
||||||
solely because modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or
|
|
||||||
updates for a work that has been modified or installed by the
|
|
||||||
recipient, or for the User Product in which it has been modified or
|
|
||||||
installed. Access to a network may be denied when the modification
|
|
||||||
itself materially and adversely affects the operation of the network
|
|
||||||
or violates the rules and protocols for communication across the
|
|
||||||
network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
@item Additional Terms.
|
|
||||||
|
|
||||||
``Additional permissions'' are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders
|
|
||||||
of that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
@enumerate a
|
|
||||||
@item
|
|
||||||
Disclaiming warranty or limiting liability differently from the terms
|
|
||||||
of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
@item
|
|
||||||
Requiring preservation of specified reasonable legal notices or author
|
|
||||||
attributions in that material or in the Appropriate Legal Notices
|
|
||||||
displayed by works containing it; or
|
|
||||||
|
|
||||||
@item
|
|
||||||
Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
@item
|
|
||||||
Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
@item
|
|
||||||
Declining to grant rights under trademark law for use of some trade
|
|
||||||
names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
@item
|
|
||||||
Requiring indemnification of licensors and authors of that material by
|
|
||||||
anyone who conveys the material (or modified versions of it) with
|
|
||||||
contractual assumptions of liability to the recipient, for any
|
|
||||||
liability that these contractual assumptions directly impose on those
|
|
||||||
licensors and authors.
|
|
||||||
@end enumerate
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered ``further
|
|
||||||
restrictions'' within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions; the
|
|
||||||
above requirements apply either way.
|
|
||||||
|
|
||||||
@item Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your license
|
|
||||||
from a particular copyright holder is reinstated (a) provisionally,
|
|
||||||
unless and until the copyright holder explicitly and finally
|
|
||||||
terminates your license, and (b) permanently, if the copyright holder
|
|
||||||
fails to notify you of the violation by some reasonable means prior to
|
|
||||||
60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
@item Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or run
|
|
||||||
a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
@item Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An ``entity transaction'' is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
@item Patents.
|
|
||||||
|
|
||||||
A ``contributor'' is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's ``contributor version''.
|
|
||||||
|
|
||||||
A contributor's ``essential patent claims'' are all patent claims owned
|
|
||||||
or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, ``control'' includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a ``patent license'' is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To ``grant'' such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. ``Knowingly relying'' means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is ``discriminatory'' if it does not include within the
|
|
||||||
scope of its coverage, prohibits the exercise of, or is conditioned on
|
|
||||||
the non-exercise of one or more of the rights that are specifically
|
|
||||||
granted under this License. You may not convey a covered work if you
|
|
||||||
are a party to an arrangement with a third party that is in the
|
|
||||||
business of distributing software, under which you make payment to the
|
|
||||||
third party based on the extent of your activity of conveying the
|
|
||||||
work, and under which the third party grants, to any of the parties
|
|
||||||
who would receive the covered work from you, a discriminatory patent
|
|
||||||
license (a) in connection with copies of the covered work conveyed by
|
|
||||||
you (or copies made from those copies), or (b) primarily for and in
|
|
||||||
connection with specific products or compilations that contain the
|
|
||||||
covered work, unless you entered into that arrangement, or that patent
|
|
||||||
license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
@item No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey
|
|
||||||
a covered work so as to satisfy simultaneously your obligations under
|
|
||||||
this License and any other pertinent obligations, then as a
|
|
||||||
consequence you may not convey it at all. For example, if you agree
|
|
||||||
to terms that obligate you to collect a royalty for further conveying
|
|
||||||
from those to whom you convey the Program, the only way you could
|
|
||||||
satisfy both those terms and this License would be to refrain entirely
|
|
||||||
from conveying the Program.
|
|
||||||
|
|
||||||
@item Use with the GNU Affero General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the special requirements of the GNU Affero General Public License,
|
|
||||||
section 13, concerning interaction through a network will apply to the
|
|
||||||
combination as such.
|
|
||||||
|
|
||||||
@item Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions
|
|
||||||
of the GNU General Public License from time to time. Such new
|
|
||||||
versions will be similar in spirit to the present version, but may
|
|
||||||
differ in detail to address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the Program
|
|
||||||
specifies that a certain numbered version of the GNU General Public
|
|
||||||
License ``or any later version'' applies to it, you have the option of
|
|
||||||
following the terms and conditions either of that numbered version or
|
|
||||||
of any later version published by the Free Software Foundation. If
|
|
||||||
the Program does not specify a version number of the GNU General
|
|
||||||
Public License, you may choose any version ever published by the Free
|
|
||||||
Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future versions
|
|
||||||
of the GNU General Public License can be used, that proxy's public
|
|
||||||
statement of acceptance of a version permanently authorizes you to
|
|
||||||
choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
@item Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM ``AS IS'' WITHOUT
|
|
||||||
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
|
|
||||||
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
|
|
||||||
DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
|
|
||||||
CORRECTION.
|
|
||||||
|
|
||||||
@item Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR
|
|
||||||
CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
|
||||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
|
|
||||||
ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
|
|
||||||
NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
|
|
||||||
LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
|
|
||||||
TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER
|
|
||||||
PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
||||||
|
|
||||||
@item Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
@end enumerate
|
|
||||||
|
|
||||||
@iftex
|
|
||||||
@heading END OF TERMS AND CONDITIONS
|
|
||||||
@end iftex
|
|
||||||
@ifinfo
|
|
||||||
@center END OF TERMS AND CONDITIONS
|
|
||||||
@end ifinfo
|
|
||||||
|
|
||||||
@unnumberedsec How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these
|
|
||||||
terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the ``copyright'' line and a pointer to where the full notice is
|
|
||||||
found.
|
|
||||||
|
|
||||||
@example
|
|
||||||
@var{one line to give the program's name and a brief idea of what it does.}
|
|
||||||
Copyright (C) @var{year} @var{name of author}
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or (at
|
|
||||||
your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, but
|
|
||||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see @url{http://www.gnu.org/licenses/}.
|
|
||||||
@end example
|
|
||||||
|
|
||||||
@noindent
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
@noindent
|
|
||||||
If the program does terminal interaction, make it output a short
|
|
||||||
notice like this when it starts in an interactive mode:
|
|
||||||
|
|
||||||
@smallexample
|
|
||||||
@var{program} Copyright (C) @var{year} @var{name of author}
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details
|
|
||||||
type @samp{show w}. This is free software, and you are
|
|
||||||
welcome to redistribute it under certain conditions;
|
|
||||||
type @samp{show c} for details.
|
|
||||||
@end smallexample
|
|
||||||
|
|
||||||
The hypothetical commands @samp{show w} and @samp{show c} should show
|
|
||||||
the appropriate parts of the General Public License. Of course, your
|
|
||||||
program's commands might be different; for a GUI interface, you would
|
|
||||||
use an ``about box''.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a ``copyright disclaimer'' for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
|
||||||
@url{http://www.gnu.org/licenses/}.
|
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your
|
|
||||||
program into proprietary programs. If your program is a subroutine
|
|
||||||
library, you may consider it more useful to permit linking proprietary
|
|
||||||
applications with the library. If this is what you want to do, use
|
|
||||||
the GNU Lesser General Public License instead of this License. But
|
|
||||||
first, please read @url{http://www.gnu.org/philosophy/why-not-lgpl.html}.
|
|
@ -1,244 +0,0 @@
|
|||||||
/*
|
|
||||||
* entry.c - Entry routine when reset and interrupt vectors.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2013, 2014, 2015, 2016, 2017
|
|
||||||
* Flying Stone Technology
|
|
||||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
|
||||||
*
|
|
||||||
* This file is a part of Chopstx, a thread library for embedded.
|
|
||||||
*
|
|
||||||
* Chopstx is free software: you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Chopstx is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* As additional permission under GNU GPL version 3 section 7, you may
|
|
||||||
* distribute non-source form of the Program without the copy of the
|
|
||||||
* GNU GPL normally required by section 4, provided you inform the
|
|
||||||
* receipents of GNU GPL by a written offer.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <chopstx.h>
|
|
||||||
|
|
||||||
#include "board.h"
|
|
||||||
|
|
||||||
#ifdef GNU_LINUX_EMULATION
|
|
||||||
int emulated_main (int, const char **);
|
|
||||||
void chx_init (struct chx_thread *);
|
|
||||||
void chx_systick_init (void);
|
|
||||||
extern struct chx_thread main_thread;
|
|
||||||
|
|
||||||
int
|
|
||||||
main (int argc, const char *argv[])
|
|
||||||
{
|
|
||||||
chx_init (&main_thread);
|
|
||||||
chx_systick_init ();
|
|
||||||
emulated_main (argc, argv);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#if defined(USE_SYS3) || defined(USE_SYS_CLOCK_GPIO_SETTING)
|
|
||||||
#define REQUIRE_CLOCK_GPIO_SETTING_IN_SYS
|
|
||||||
#include "sys.h"
|
|
||||||
/*
|
|
||||||
* Avoid medium density specific code and prepare for high density
|
|
||||||
* device, too.
|
|
||||||
*/
|
|
||||||
#undef STM32F10X_MD
|
|
||||||
#else
|
|
||||||
#if defined (MCU_KINETIS_L)
|
|
||||||
#include "mcu/clk_gpio_init-mkl27z.c"
|
|
||||||
#else
|
|
||||||
#include "mcu/clk_gpio_init-stm32.c"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef MAKE_ENTRY_PUBLIC
|
|
||||||
#define STATIC_ENTRY
|
|
||||||
#else
|
|
||||||
#define STATIC_ENTRY static
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern uint8_t __main_stack_end__;
|
|
||||||
#if defined(__ARM_ARCH_7M__)
|
|
||||||
extern void svc (void);
|
|
||||||
#endif
|
|
||||||
extern void preempt (void);
|
|
||||||
extern void chx_timer_expired (void);
|
|
||||||
extern void chx_handle_intr (void);
|
|
||||||
|
|
||||||
static void nmi (void)
|
|
||||||
{
|
|
||||||
for (;;);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void hard_fault (void)
|
|
||||||
{
|
|
||||||
for (;;);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mem_manage (void)
|
|
||||||
{
|
|
||||||
for (;;);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bus_fault (void)
|
|
||||||
{
|
|
||||||
for (;;);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void usage_fault (void)
|
|
||||||
{
|
|
||||||
for (;;);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void none (void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#define C_S_SUB(arg0, arg1, arg2) arg0 #arg1 arg2
|
|
||||||
#define COMPOSE_STATEMENT(arg0,arg1,arg2) C_S_SUB (arg0, arg1, arg2)
|
|
||||||
|
|
||||||
#if defined(__ARM_ARCH_6M__)
|
|
||||||
__attribute__ ((used,section(".bss.startup.0")))
|
|
||||||
uint32_t vectors_in_ram[48];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This routine only changes PSP and not MSP.
|
|
||||||
*/
|
|
||||||
STATIC_ENTRY __attribute__ ((naked,section(".text.startup.0")))
|
|
||||||
void
|
|
||||||
entry (void)
|
|
||||||
{
|
|
||||||
asm volatile ("bl clock_init\n\t"
|
|
||||||
/* Clear BSS section. */
|
|
||||||
"mov r0, #0\n\t"
|
|
||||||
"ldr r1, =_bss_start\n\t"
|
|
||||||
"ldr r2, =_bss_end\n"
|
|
||||||
"0:\n\t"
|
|
||||||
"cmp r1, r2\n\t"
|
|
||||||
"beq 1f\n\t"
|
|
||||||
#if defined(__ARM_ARCH_6M__)
|
|
||||||
"str r0, [r1]\n\t"
|
|
||||||
"add r1, #4\n\t"
|
|
||||||
#else
|
|
||||||
"str r0, [r1], #4\n\t"
|
|
||||||
#endif
|
|
||||||
"b 0b\n"
|
|
||||||
"1:\n\t"
|
|
||||||
/* Copy data section. */
|
|
||||||
"ldr r1, =_data\n\t"
|
|
||||||
"ldr r2, =_edata\n\t"
|
|
||||||
"ldr r3, =_textdata\n"
|
|
||||||
"2:\n\t"
|
|
||||||
"cmp r1, r2\n\t"
|
|
||||||
"beq 3f\n\t"
|
|
||||||
#if defined(__ARM_ARCH_6M__)
|
|
||||||
"ldr r0, [r3]\n\t"
|
|
||||||
"str r0, [r1]\n\t"
|
|
||||||
"add r3, #4\n\t"
|
|
||||||
"add r1, #4\n\t"
|
|
||||||
#else
|
|
||||||
"ldr r0, [r3], #4\n\t"
|
|
||||||
"str r0, [r1], #4\n\t"
|
|
||||||
#endif
|
|
||||||
"b 2b\n"
|
|
||||||
"3:\n\t"
|
|
||||||
/* Switch to PSP. */
|
|
||||||
"ldr r0, =__process0_stack_end__\n\t"
|
|
||||||
COMPOSE_STATEMENT ("sub r0, #", CHOPSTX_THREAD_SIZE, "\n\t")
|
|
||||||
"msr PSP, r0\n\t" /* Process (main routine) stack. */
|
|
||||||
"mov r1, #2\n\t"
|
|
||||||
"msr CONTROL, r1\n\t"
|
|
||||||
"isb\n\t"
|
|
||||||
"bl chx_init\n\t"
|
|
||||||
"bl chx_systick_init\n\t"
|
|
||||||
"bl gpio_init\n\t"
|
|
||||||
/* Enable interrupts. */
|
|
||||||
#if defined(__ARM_ARCH_7M__)
|
|
||||||
"mov r0, #0\n\t"
|
|
||||||
"msr BASEPRI, r0\n\t"
|
|
||||||
#endif
|
|
||||||
"cpsie i\n\t"
|
|
||||||
/* Call main. */
|
|
||||||
"mov r1, r0\n\t"
|
|
||||||
"bl main\n"
|
|
||||||
"4:\n\t"
|
|
||||||
"b 4b"
|
|
||||||
: /* no output */ : /* no input */ : "memory");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
typedef void (*handler)(void);
|
|
||||||
|
|
||||||
handler vector_table[] __attribute__ ((section(".startup.vectors"))) = {
|
|
||||||
(handler)(&__main_stack_end__ - 32),
|
|
||||||
entry,
|
|
||||||
nmi, /* nmi */
|
|
||||||
hard_fault, /* hard fault */
|
|
||||||
/* 0x10 */
|
|
||||||
mem_manage, /* mem manage */
|
|
||||||
bus_fault, /* bus fault */
|
|
||||||
usage_fault, /* usage fault */
|
|
||||||
none,
|
|
||||||
/* 0x20 */
|
|
||||||
none, none, none, /* reserved */
|
|
||||||
#if defined(__ARM_ARCH_6M__)
|
|
||||||
none, /* SVCall */
|
|
||||||
#elif defined(__ARM_ARCH_7M__)
|
|
||||||
svc, /* SVCall */
|
|
||||||
#endif
|
|
||||||
none, /* Debug */
|
|
||||||
none, /* reserved */
|
|
||||||
preempt, /* PendSV */
|
|
||||||
chx_timer_expired, /* SysTick */
|
|
||||||
/* 0x40 */
|
|
||||||
chx_handle_intr /* WWDG */, chx_handle_intr /* PVD */,
|
|
||||||
chx_handle_intr /* TAMPER */, chx_handle_intr /* RTC */,
|
|
||||||
chx_handle_intr /* FLASH */, chx_handle_intr /* RCC */,
|
|
||||||
chx_handle_intr /* EXTI0 */, chx_handle_intr /* EXTI1 */,
|
|
||||||
/* 0x60 */
|
|
||||||
chx_handle_intr /* EXTI2 */, chx_handle_intr /* EXTI3 */,
|
|
||||||
chx_handle_intr /* EXTI4 */, chx_handle_intr /* DMA1 CH1 */,
|
|
||||||
chx_handle_intr /* DMA1 CH2 */, chx_handle_intr /* DMA1 CH3 */,
|
|
||||||
chx_handle_intr /* DMA1 CH4 */, chx_handle_intr /* DMA1 CH5 */,
|
|
||||||
/* 0x80 */
|
|
||||||
chx_handle_intr /* DMA1 CH6 */, chx_handle_intr /* DMA1 CH7 */,
|
|
||||||
chx_handle_intr /* ADC1_2 */, chx_handle_intr /* USB HP */,
|
|
||||||
/* 0x90 */
|
|
||||||
chx_handle_intr /* USB LP */, chx_handle_intr /* CAN RX1 */,
|
|
||||||
chx_handle_intr /* CAN SCE */, chx_handle_intr /* EXT9_5 */,
|
|
||||||
/* 0xa0 */
|
|
||||||
/* ... and more. TIMx, I2C, SPI, USART... */
|
|
||||||
chx_handle_intr, chx_handle_intr, chx_handle_intr, chx_handle_intr,
|
|
||||||
chx_handle_intr, chx_handle_intr, chx_handle_intr, chx_handle_intr,
|
|
||||||
/* 0xc0 */
|
|
||||||
#if !defined(__ARM_ARCH_6M__)
|
|
||||||
/* STM32F0 doesn't have more. */
|
|
||||||
chx_handle_intr, chx_handle_intr, chx_handle_intr, chx_handle_intr,
|
|
||||||
chx_handle_intr, chx_handle_intr, chx_handle_intr, chx_handle_intr,
|
|
||||||
/* 0xe0 */
|
|
||||||
chx_handle_intr /* EXT15_10 */, chx_handle_intr /* RTCAlarm */,
|
|
||||||
chx_handle_intr /* USBWakeup */, chx_handle_intr,
|
|
||||||
#endif
|
|
||||||
#if !defined(STM32F10X_MD)
|
|
||||||
/* High-density chips have more; ... DMA2_Channel4_5 */
|
|
||||||
chx_handle_intr, chx_handle_intr, chx_handle_intr, chx_handle_intr,
|
|
||||||
chx_handle_intr, chx_handle_intr, chx_handle_intr, chx_handle_intr,
|
|
||||||
chx_handle_intr, chx_handle_intr, chx_handle_intr, chx_handle_intr,
|
|
||||||
chx_handle_intr, chx_handle_intr, chx_handle_intr, chx_handle_intr,
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
#endif
|
|
@ -1,145 +0,0 @@
|
|||||||
/*
|
|
||||||
* eventflag.c - Eventflag
|
|
||||||
*
|
|
||||||
* Copyright (C) 2013, 2016, 2018 Flying Stone Technology
|
|
||||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
|
||||||
*
|
|
||||||
* This file is a part of Chopstx, a thread library for embedded.
|
|
||||||
*
|
|
||||||
* Chopstx is free software: you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Chopstx is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* As additional permission under GNU GPL version 3 section 7, you may
|
|
||||||
* distribute non-source form of the Program without the copy of the
|
|
||||||
* GNU GPL normally required by section 4, provided you inform the
|
|
||||||
* receipents of GNU GPL by a written offer.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <chopstx.h>
|
|
||||||
#include <eventflag.h>
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
eventflag_init (struct eventflag *ev)
|
|
||||||
{
|
|
||||||
ev->flags = 0;
|
|
||||||
ev->mask = ~0;
|
|
||||||
chopstx_cond_init (&ev->cond);
|
|
||||||
chopstx_mutex_init (&ev->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
eventflag_set_mask (struct eventflag *ev, eventmask_t m)
|
|
||||||
{
|
|
||||||
chopstx_mutex_lock (&ev->mutex);
|
|
||||||
ev->mask = m;
|
|
||||||
if ((ev->flags & ev->mask))
|
|
||||||
chopstx_cond_signal (&ev->cond);
|
|
||||||
chopstx_mutex_unlock (&ev->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
eventflag_check (void *arg)
|
|
||||||
{
|
|
||||||
struct eventflag *ev = arg;
|
|
||||||
|
|
||||||
return (ev->flags & ev->mask) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
eventflag_prepare_poll (struct eventflag *ev, chopstx_poll_cond_t *poll_desc)
|
|
||||||
{
|
|
||||||
poll_desc->type = CHOPSTX_POLL_COND;
|
|
||||||
poll_desc->ready = 0;
|
|
||||||
poll_desc->cond = &ev->cond;
|
|
||||||
poll_desc->mutex = &ev->mutex;
|
|
||||||
poll_desc->check = eventflag_check;
|
|
||||||
poll_desc->arg = ev;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* When multiple events are marked, event with lower bit has precedence.
|
|
||||||
Because __builtin_ffs returns the least significant 1-bit. */
|
|
||||||
|
|
||||||
eventmask_t
|
|
||||||
eventflag_get (struct eventflag *ev)
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
eventmask_t m;
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&ev->mutex);
|
|
||||||
n = __builtin_ffs ((ev->flags & ev->mask));
|
|
||||||
if (n)
|
|
||||||
{
|
|
||||||
m = (1 << (n - 1));
|
|
||||||
ev->flags &= ~m;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m = 0;
|
|
||||||
chopstx_mutex_unlock (&ev->mutex);
|
|
||||||
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
eventmask_t
|
|
||||||
eventflag_wait (struct eventflag *ev)
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
eventmask_t m;
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&ev->mutex);
|
|
||||||
while (!(ev->flags & ev->mask))
|
|
||||||
chopstx_cond_wait (&ev->cond, &ev->mutex);
|
|
||||||
|
|
||||||
n = __builtin_ffs ((ev->flags & ev->mask));
|
|
||||||
if (n) /* Always n > 0 when waked up, but make sure no bad things. */
|
|
||||||
{
|
|
||||||
m = (1 << (n - 1));
|
|
||||||
ev->flags &= ~m;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m = 0;
|
|
||||||
chopstx_mutex_unlock (&ev->mutex);
|
|
||||||
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
eventmask_t
|
|
||||||
eventflag_wait_timeout (struct eventflag *ev, uint32_t usec)
|
|
||||||
{
|
|
||||||
chopstx_poll_cond_t poll_desc;
|
|
||||||
struct chx_poll_head *pd_array[1] = { (struct chx_poll_head *)&poll_desc };
|
|
||||||
|
|
||||||
eventflag_prepare_poll (ev, &poll_desc);
|
|
||||||
chopstx_poll (&usec, 1, pd_array);
|
|
||||||
return eventflag_get (ev);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
eventflag_signal (struct eventflag *ev, eventmask_t m)
|
|
||||||
{
|
|
||||||
chopstx_mutex_lock (&ev->mutex);
|
|
||||||
ev->flags |= m;
|
|
||||||
if ((ev->flags & ev->mask))
|
|
||||||
chopstx_cond_signal (&ev->cond);
|
|
||||||
chopstx_mutex_unlock (&ev->mutex);
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
typedef uint32_t eventmask_t;
|
|
||||||
|
|
||||||
struct eventflag {
|
|
||||||
eventmask_t flags;
|
|
||||||
eventmask_t mask;
|
|
||||||
chopstx_mutex_t mutex;
|
|
||||||
chopstx_cond_t cond;
|
|
||||||
};
|
|
||||||
|
|
||||||
void eventflag_init (struct eventflag *ev);
|
|
||||||
void eventflag_set_mask (struct eventflag *ev, eventmask_t m);
|
|
||||||
eventmask_t eventflag_wait (struct eventflag *ev);
|
|
||||||
eventmask_t eventflag_wait_timeout (struct eventflag *ev, uint32_t usec);
|
|
||||||
void eventflag_signal (struct eventflag *ev, eventmask_t m);
|
|
||||||
|
|
||||||
/* For polling */
|
|
||||||
void eventflag_prepare_poll (struct eventflag *ev, chopstx_poll_cond_t *p);
|
|
||||||
eventmask_t eventflag_get (struct eventflag *ev);
|
|
@ -1,43 +0,0 @@
|
|||||||
# Makefile for example application of Chopstx
|
|
||||||
|
|
||||||
PROJECT = sample
|
|
||||||
|
|
||||||
### This is for GNU/Linux
|
|
||||||
|
|
||||||
CHOPSTX = ..
|
|
||||||
LDSCRIPT=
|
|
||||||
CSRC = sample.c usb-cdc.c command.c
|
|
||||||
|
|
||||||
CHIP=gnu-linux
|
|
||||||
USE_SYS = yes
|
|
||||||
USE_USB = yes
|
|
||||||
USE_ADC = yes
|
|
||||||
EMULATION=yes
|
|
||||||
|
|
||||||
###################################
|
|
||||||
CROSS =
|
|
||||||
CC = $(CROSS)gcc
|
|
||||||
LD = $(CROSS)gcc
|
|
||||||
OBJCOPY = $(CROSS)objcopy
|
|
||||||
|
|
||||||
MCU = none
|
|
||||||
CWARN = -Wall -Wextra -Wstrict-prototypes
|
|
||||||
DEFS = -DGNU_LINUX_EMULATION -DUSE_SYS_BOARD_ID
|
|
||||||
OPT = -g # -O3 -Os
|
|
||||||
LIBS = -lpthread
|
|
||||||
|
|
||||||
####################
|
|
||||||
include ../rules.mk
|
|
||||||
|
|
||||||
board.h:
|
|
||||||
@echo Please make a symbolic link \'board.h\' to a file in ../board;
|
|
||||||
@exit 1
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
|
|
||||||
build/flash.data: Makefile
|
|
||||||
@echo 'Generating 8192-byte flash.data'
|
|
||||||
@/bin/echo -n -e '\xff\xff\xff\xff\xff\xff\xff\xff' >$@
|
|
||||||
@for i in $(shell seq 1023); do /bin/echo -n -e '\xff\xff\xff\xff\xff\xff\xff\xff' >>$@; done
|
|
||||||
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
|||||||
(0) Build and generate initial flash data
|
|
||||||
|
|
||||||
$ make
|
|
||||||
$ make build/flash.data
|
|
||||||
|
|
||||||
|
|
||||||
(1) preparation as root
|
|
||||||
|
|
||||||
Don't run ModemManager
|
|
||||||
|
|
||||||
# systemctl stop ModemManager
|
|
||||||
|
|
||||||
Install USBIP host module
|
|
||||||
# modprobe vhci_hcd
|
|
||||||
|
|
||||||
|
|
||||||
(2) Run sample program of USBIP server
|
|
||||||
|
|
||||||
$ ./sample
|
|
||||||
|
|
||||||
|
|
||||||
(3) Use the USB device as root
|
|
||||||
|
|
||||||
Attach the Chopstx application program (USBIP device) to USBIP host.
|
|
||||||
|
|
||||||
# usbip attach -r 127.0.0.1 -b 1-1
|
|
||||||
|
|
||||||
|
|
||||||
(4) Connect CDC-ACM device
|
|
||||||
|
|
||||||
$ cu -l /dev/ttyACM0
|
|
||||||
|
|
||||||
Then, you see the message from Chopstx. As you type lines, it echos.
|
|
||||||
|
|
||||||
Type RET, ~ then . , you can terminate the session.
|
|
||||||
|
|
||||||
|
|
||||||
(5) Detach the USBIP device as root
|
|
||||||
|
|
||||||
# usbip detach -p 0
|
|
||||||
|
|
@ -1,579 +0,0 @@
|
|||||||
#include <string.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <chopstx.h>
|
|
||||||
#include "tty.h"
|
|
||||||
#include "config.h"
|
|
||||||
#ifdef ADC_SUPPORT
|
|
||||||
#include "adc.h"
|
|
||||||
static int adc_initialized = 0;
|
|
||||||
#endif
|
|
||||||
#include "board.h"
|
|
||||||
#include "sys.h"
|
|
||||||
|
|
||||||
struct command_table
|
|
||||||
{
|
|
||||||
const char *name;
|
|
||||||
void (*handler) (struct tty *tty, const char *line);
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Put a line (or lines) to TTY.
|
|
||||||
* LINE should be terminated with newline.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
put_line (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
tty_send (tty, line, strlen (line));
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *help_string =
|
|
||||||
"mdb ADDR [COUNT]; memory display byte\r\n"
|
|
||||||
"mwh ADDR VALUE [COUNT]; memory write halfword\r\n"
|
|
||||||
"fes ADDR [COUNT]; flash erase sector\r\n"
|
|
||||||
"fwh ADDR VALUE [COUNT]; flash write halfword\r\n"
|
|
||||||
#ifdef CRC32_SUPPORT
|
|
||||||
"crc32 string; CRC32 calc string\r\n"
|
|
||||||
#endif
|
|
||||||
#ifdef ADC_SUPPORT
|
|
||||||
"adc; get 256-byte from ADC\r\n"
|
|
||||||
#endif
|
|
||||||
"sysinfo; system information\r\n"
|
|
||||||
"help\r\n";
|
|
||||||
|
|
||||||
static char hexchar (uint8_t x)
|
|
||||||
{
|
|
||||||
x &= 0x0f;
|
|
||||||
if (x <= 0x09)
|
|
||||||
return '0' + x;
|
|
||||||
else if (x <= 0x0f)
|
|
||||||
return 'a' + x - 10;
|
|
||||||
else
|
|
||||||
return '?';
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef TOUCH_SUPPORT
|
|
||||||
static char *
|
|
||||||
compose_decimal (char *s, int value)
|
|
||||||
{
|
|
||||||
uint32_t v;
|
|
||||||
int col = 1000000000;
|
|
||||||
int d;
|
|
||||||
int digit_output = 0;
|
|
||||||
|
|
||||||
if (value < 0)
|
|
||||||
{
|
|
||||||
*s++ = '-';
|
|
||||||
v = 1 + ~((uint32_t)value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
v = (uint32_t)value;
|
|
||||||
|
|
||||||
while (col >= 10)
|
|
||||||
{
|
|
||||||
if (v >= (uint32_t)col)
|
|
||||||
{
|
|
||||||
d = v / col;
|
|
||||||
v = v - d * col;
|
|
||||||
*s++ = d + '0';
|
|
||||||
digit_output = 1;
|
|
||||||
}
|
|
||||||
else if (digit_output)
|
|
||||||
*s++ = '0';
|
|
||||||
|
|
||||||
col = col / 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
*s++ = v + '0';
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
char *
|
|
||||||
compose_hex_ptr (char *s, uintptr_t v)
|
|
||||||
{
|
|
||||||
s[0] = hexchar (v >> 60);
|
|
||||||
s[1] = hexchar (v >> 56);
|
|
||||||
s[2] = hexchar (v >> 52);
|
|
||||||
s[3] = hexchar (v >> 48);
|
|
||||||
s[4] = hexchar (v >> 44);
|
|
||||||
s[5] = hexchar (v >> 40);
|
|
||||||
s[6] = hexchar (v >> 36);
|
|
||||||
s[7] = hexchar (v >> 32);
|
|
||||||
s[8] = hexchar (v >> 28);
|
|
||||||
s[9] = hexchar (v >> 24);
|
|
||||||
s[10] = hexchar (v >> 20);
|
|
||||||
s[11] = hexchar (v >> 16);
|
|
||||||
s[12] = hexchar (v >> 12);
|
|
||||||
s[13] = hexchar (v >> 8);
|
|
||||||
s[14] = hexchar (v >> 4);
|
|
||||||
s[15] = hexchar (v);
|
|
||||||
return s+16;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
|
||||||
compose_hex (char *s, uint32_t v)
|
|
||||||
{
|
|
||||||
s[0] = hexchar (v >> 28);
|
|
||||||
s[1] = hexchar (v >> 24);
|
|
||||||
s[2] = hexchar (v >> 20);
|
|
||||||
s[3] = hexchar (v >> 16);
|
|
||||||
s[4] = hexchar (v >> 12);
|
|
||||||
s[5] = hexchar (v >> 8);
|
|
||||||
s[6] = hexchar (v >> 4);
|
|
||||||
s[7] = hexchar (v);
|
|
||||||
return s+8;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
|
||||||
compose_hex_byte (char *s, uint8_t v)
|
|
||||||
{
|
|
||||||
s[0] = hexchar (v >> 4);
|
|
||||||
s[1] = hexchar (v);
|
|
||||||
return s+2;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *
|
|
||||||
get_hex (struct tty *tty, const char *s, uintptr_t *v_p)
|
|
||||||
{
|
|
||||||
uintptr_t v = 0;
|
|
||||||
char c;
|
|
||||||
|
|
||||||
if (s[0] == '0' && s[1] == 'x')
|
|
||||||
s = s + 2;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
c = *s++;
|
|
||||||
|
|
||||||
if (c == 0)
|
|
||||||
{
|
|
||||||
s--;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == ' ')
|
|
||||||
break;
|
|
||||||
|
|
||||||
v = (v << 4);
|
|
||||||
if (c >= '0' && c <= '9')
|
|
||||||
v += (c - '0');
|
|
||||||
else if (c >= 'a' && c <= 'f')
|
|
||||||
v += (c - 'a') + 10;
|
|
||||||
else if (c >= 'A' && c <= 'F')
|
|
||||||
v += (c - 'A') + 10;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
put_line (tty, "hex error\r\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*v_p = v;
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef TOUCH_SUPPORT
|
|
||||||
#define TOUCH_VALUE_HIGH 100
|
|
||||||
#define TOUCH_VALUE_LOW 50
|
|
||||||
static void
|
|
||||||
cmd_button (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
extern uint16_t touch_get (void);
|
|
||||||
uint16_t v0 = 0;
|
|
||||||
int touched = 0;
|
|
||||||
|
|
||||||
(void)line;
|
|
||||||
put_line (tty, "Please touch the bear.\r\n");
|
|
||||||
|
|
||||||
while (i < 16)
|
|
||||||
{
|
|
||||||
uint16_t v = touch_get ();
|
|
||||||
v0 = (v0 * 2 + v)/3;
|
|
||||||
|
|
||||||
if (touched == 0 && v0 > TOUCH_VALUE_HIGH)
|
|
||||||
{
|
|
||||||
tty_send (tty, "!", 1);
|
|
||||||
touched = 1;
|
|
||||||
}
|
|
||||||
else if (touched == 1 && v0 < TOUCH_VALUE_LOW)
|
|
||||||
{
|
|
||||||
tty_send (tty, ".", 1);
|
|
||||||
touched = 0;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
chopstx_usec_wait (10*1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
tty_send (tty, "\r\n", 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_touch (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
extern uint16_t touch_get (void);
|
|
||||||
|
|
||||||
(void)line;
|
|
||||||
put_line (tty, "Please touch the bear.\r\n");
|
|
||||||
|
|
||||||
for (i = 0; i < 20; i++)
|
|
||||||
{
|
|
||||||
uint16_t v;
|
|
||||||
char output[8];
|
|
||||||
char *s;
|
|
||||||
|
|
||||||
chopstx_usec_wait (1000*1000);
|
|
||||||
v = touch_get ();
|
|
||||||
s = compose_decimal (output, v);
|
|
||||||
*s++ = '\r';
|
|
||||||
*s++ = '\n';
|
|
||||||
tty_send (tty, output, s - output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_mdb (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
uintptr_t addr = 0;
|
|
||||||
int count = 0;
|
|
||||||
char c;
|
|
||||||
const char *s = line;
|
|
||||||
|
|
||||||
s = get_hex (tty, s, &addr);
|
|
||||||
addr &= ~3;
|
|
||||||
if (s == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (*s == 0)
|
|
||||||
count = 1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
c = *s++;
|
|
||||||
|
|
||||||
if (c == 0 || c == ' ')
|
|
||||||
break;
|
|
||||||
|
|
||||||
count = count * 10;
|
|
||||||
if (c >= '0' && c <= '9')
|
|
||||||
count += c - '0';
|
|
||||||
else
|
|
||||||
{
|
|
||||||
put_line (tty, "mdb error\r\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < count)
|
|
||||||
{
|
|
||||||
uint8_t v;
|
|
||||||
char output[68];
|
|
||||||
char *s;
|
|
||||||
|
|
||||||
s = compose_hex_ptr (output, addr);
|
|
||||||
*s++ = ':';
|
|
||||||
*s++ = ' ';
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
v = *(uint8_t *)addr;
|
|
||||||
s = compose_hex_byte (s, v);
|
|
||||||
i++;
|
|
||||||
addr += 1;
|
|
||||||
if (i >= count || (i % 16) == 0)
|
|
||||||
break;
|
|
||||||
*s++ = ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
*s++ = '\r';
|
|
||||||
*s++ = '\n';
|
|
||||||
tty_send (tty, output, s - output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_mwh (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
(void)tty;
|
|
||||||
(void)line;
|
|
||||||
put_line (tty, "mwh not yet supported\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_fes (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
uintptr_t addr = 0;
|
|
||||||
int count = 0;
|
|
||||||
char c;
|
|
||||||
const char *s = line;
|
|
||||||
|
|
||||||
s = get_hex (tty, s, &addr);
|
|
||||||
if (s == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (*s == 0)
|
|
||||||
count = 1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
c = *s++;
|
|
||||||
|
|
||||||
if (c == 0 || c == ' ')
|
|
||||||
break;
|
|
||||||
|
|
||||||
count = count * 10;
|
|
||||||
if (c >= '0' && c <= '9')
|
|
||||||
count += c - '0';
|
|
||||||
else
|
|
||||||
{
|
|
||||||
put_line (tty, "fww error\r\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
flash_erase_page (addr);
|
|
||||||
addr += 1024;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_fwh (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
uintptr_t addr = 0;
|
|
||||||
uintptr_t d;
|
|
||||||
uint16_t value = 0;
|
|
||||||
int count = 0;
|
|
||||||
char c;
|
|
||||||
const char *s = line;
|
|
||||||
|
|
||||||
s = get_hex (tty, s, &addr);
|
|
||||||
if (s == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (*s == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
s = get_hex (tty, s, &d);
|
|
||||||
value = (uint16_t)d;
|
|
||||||
if (s == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (*s == 0)
|
|
||||||
count = 1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
c = *s++;
|
|
||||||
|
|
||||||
if (c == 0 || c == ' ')
|
|
||||||
break;
|
|
||||||
|
|
||||||
count = count * 10;
|
|
||||||
if (c >= '0' && c <= '9')
|
|
||||||
count += c - '0';
|
|
||||||
else
|
|
||||||
{
|
|
||||||
put_line (tty, "fww error\r\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
flash_program_halfword (addr, value);
|
|
||||||
addr += 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef CRC32_SUPPORT
|
|
||||||
static unsigned int crc_value;
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_crc32 (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
uint32_t v;
|
|
||||||
char string[10];
|
|
||||||
char *s;
|
|
||||||
|
|
||||||
crc32_init (&crc_value);
|
|
||||||
while (*line)
|
|
||||||
crc32_u8 (&crc_value, *line++);
|
|
||||||
v = crc_value ^ 0xffffffff;
|
|
||||||
|
|
||||||
s = compose_hex (string, v);
|
|
||||||
*s++ = '\r';
|
|
||||||
*s++ = '\n';
|
|
||||||
tty_send (tty, string, sizeof (string));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ADC_SUPPORT
|
|
||||||
static void
|
|
||||||
cmd_adc (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char output[73];
|
|
||||||
char *s;
|
|
||||||
|
|
||||||
(void)line;
|
|
||||||
|
|
||||||
if (!adc_initialized)
|
|
||||||
{
|
|
||||||
if (adc_init ())
|
|
||||||
{
|
|
||||||
put_line (tty, "adc_init error\r\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
adc_start ();
|
|
||||||
adc_initialized = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
adc_start_conversion (0, 64);
|
|
||||||
adc_wait_completion ();
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
s = output;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
s = compose_hex (s, adc_buf[i]);
|
|
||||||
i++;
|
|
||||||
if ((i % 8))
|
|
||||||
*s++ = ' ';
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*s++ = '\r';
|
|
||||||
*s++ = '\n';
|
|
||||||
tty_send (tty, output, s - output);
|
|
||||||
s = output;
|
|
||||||
if (i >= 64)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_sysinfo (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
char output[73];
|
|
||||||
char *s;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
(void)line;
|
|
||||||
memcpy (output, "SYS version: ", 13);
|
|
||||||
s = output + 13;
|
|
||||||
*s++ = sys_version[2];
|
|
||||||
*s++ = sys_version[4];
|
|
||||||
*s++ = sys_version[6];
|
|
||||||
*s++ = '\r';
|
|
||||||
*s++ = '\n';
|
|
||||||
tty_send (tty, output, s - output);
|
|
||||||
|
|
||||||
memcpy (output, "Board ID: ", 10);
|
|
||||||
s = output + 10;
|
|
||||||
s = compose_hex (s, sys_board_id);
|
|
||||||
*s++ = '\r';
|
|
||||||
*s++ = '\n';
|
|
||||||
tty_send (tty, output, s - output);
|
|
||||||
|
|
||||||
memcpy (output, "Board name: ", 12);
|
|
||||||
s = output + 12;
|
|
||||||
for (i = 0; i < (int)sizeof (output) - 2; i ++)
|
|
||||||
if ((*s = sys_board_name[i]) == 0)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
s++;
|
|
||||||
|
|
||||||
*s++ = '\r';
|
|
||||||
*s++ = '\n';
|
|
||||||
tty_send (tty, output, s - output);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_help (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
(void)line;
|
|
||||||
put_line (tty, help_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct command_table command_table[] = {
|
|
||||||
#ifdef TOUCH_SUPPORT
|
|
||||||
{ "button", cmd_button },
|
|
||||||
{ "touch", cmd_touch },
|
|
||||||
#endif
|
|
||||||
{ "mdb", cmd_mdb },
|
|
||||||
{ "mwh", cmd_mwh },
|
|
||||||
{ "fes", cmd_fes },
|
|
||||||
{ "fwh", cmd_fwh },
|
|
||||||
#ifdef CRC32_SUPPORT
|
|
||||||
{ "crc32", cmd_crc32 },
|
|
||||||
#endif
|
|
||||||
#ifdef ADC_SUPPORT
|
|
||||||
{ "adc", cmd_adc },
|
|
||||||
#endif
|
|
||||||
{ "sysinfo", cmd_sysinfo },
|
|
||||||
{ "help", cmd_help },
|
|
||||||
};
|
|
||||||
|
|
||||||
#define N_CMDS (int)(sizeof (command_table) / sizeof (struct command_table))
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Dispatch a command parsing LINE.
|
|
||||||
* Line is NULL terminated with no newline.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
cmd_dispatch (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
const char *p;
|
|
||||||
unsigned int n = 0;
|
|
||||||
|
|
||||||
p = line;
|
|
||||||
while (*p)
|
|
||||||
{
|
|
||||||
if (*p++ == ' ')
|
|
||||||
break;
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < N_CMDS; i++)
|
|
||||||
if (n == strlen (command_table[i].name)
|
|
||||||
&& strncmp ((const char *)line, command_table[i].name, n) == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (i != N_CMDS)
|
|
||||||
(*command_table[i].handler) (tty, p);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
char crlf[] = { '\r', '\n' };
|
|
||||||
|
|
||||||
put_line (tty, "No such command: ");
|
|
||||||
tty_send (tty, line, n);
|
|
||||||
tty_send (tty, crlf, sizeof (crlf));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,2 +0,0 @@
|
|||||||
void cmd_dispatch (struct tty *tty, const char *line);
|
|
||||||
char * compose_hex_ptr (char *s, uintptr_t v);
|
|
@ -1,2 +0,0 @@
|
|||||||
#undef CRC32_SUPPORT
|
|
||||||
#define ADC_SUPPORT
|
|
@ -1,197 +0,0 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ucontext.h>
|
|
||||||
|
|
||||||
#include <chopstx.h>
|
|
||||||
|
|
||||||
#include "sys.h"
|
|
||||||
|
|
||||||
#include "usb_lld.h"
|
|
||||||
#include "tty.h"
|
|
||||||
#include "command.h"
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
static chopstx_mutex_t mtx;
|
|
||||||
static chopstx_cond_t cnd0;
|
|
||||||
static chopstx_cond_t cnd1;
|
|
||||||
|
|
||||||
static uint8_t u, v;
|
|
||||||
static uint8_t m; /* 0..100 */
|
|
||||||
|
|
||||||
static void *
|
|
||||||
pwm (void *arg)
|
|
||||||
{
|
|
||||||
(void)arg;
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&mtx);
|
|
||||||
chopstx_cond_wait (&cnd0, &mtx);
|
|
||||||
chopstx_mutex_unlock (&mtx);
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
set_led (u&v);
|
|
||||||
chopstx_usec_wait (m);
|
|
||||||
set_led (0);
|
|
||||||
chopstx_usec_wait (100-m);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *
|
|
||||||
blk (void *arg)
|
|
||||||
{
|
|
||||||
(void)arg;
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&mtx);
|
|
||||||
chopstx_cond_wait (&cnd1, &mtx);
|
|
||||||
chopstx_mutex_unlock (&mtx);
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
v = 0;
|
|
||||||
chopstx_usec_wait (200*1000);
|
|
||||||
v = 1;
|
|
||||||
chopstx_usec_wait (200*1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define PRIO_PWM 3
|
|
||||||
#define PRIO_BLK 2
|
|
||||||
|
|
||||||
static char __process1_stack_base__[4096];
|
|
||||||
static char __process2_stack_base__[4096];
|
|
||||||
|
|
||||||
#define STACK_ADDR_PWM ((uintptr_t)__process1_stack_base__)
|
|
||||||
#define STACK_SIZE_PWM (sizeof __process1_stack_base__)
|
|
||||||
|
|
||||||
#define STACK_ADDR_BLK ((uintptr_t)__process2_stack_base__)
|
|
||||||
#define STACK_SIZE_BLK (sizeof __process2_stack_base__)
|
|
||||||
|
|
||||||
|
|
||||||
static char hexchar (uint8_t x)
|
|
||||||
{
|
|
||||||
x &= 0x0f;
|
|
||||||
if (x <= 0x09)
|
|
||||||
return '0' + x;
|
|
||||||
else if (x <= 0x0f)
|
|
||||||
return 'a' + x - 10;
|
|
||||||
else
|
|
||||||
return '?';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef GNU_LINUX_EMULATION
|
|
||||||
#define main emulated_main
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int
|
|
||||||
main (int argc, const char *argv[])
|
|
||||||
{
|
|
||||||
struct tty *tty;
|
|
||||||
uint8_t count;
|
|
||||||
uintptr_t addr;
|
|
||||||
|
|
||||||
if (argc >= 2 && !strncmp (argv[1], "--debug=", 8))
|
|
||||||
debug = strtol (&argv[1][8], NULL, 10);
|
|
||||||
|
|
||||||
chopstx_mutex_init (&mtx);
|
|
||||||
chopstx_cond_init (&cnd0);
|
|
||||||
chopstx_cond_init (&cnd1);
|
|
||||||
|
|
||||||
m = 10;
|
|
||||||
|
|
||||||
chopstx_create (PRIO_PWM, STACK_ADDR_PWM, STACK_SIZE_PWM, pwm, NULL);
|
|
||||||
chopstx_create (PRIO_BLK, STACK_ADDR_BLK, STACK_SIZE_BLK, blk, NULL);
|
|
||||||
|
|
||||||
chopstx_usec_wait (200*1000);
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&mtx);
|
|
||||||
chopstx_cond_signal (&cnd0);
|
|
||||||
chopstx_cond_signal (&cnd1);
|
|
||||||
chopstx_mutex_unlock (&mtx);
|
|
||||||
|
|
||||||
addr = flash_init ("flash.data");
|
|
||||||
flash_unlock ();
|
|
||||||
|
|
||||||
u = 1;
|
|
||||||
|
|
||||||
tty = tty_open ();
|
|
||||||
tty_wait_configured (tty);
|
|
||||||
|
|
||||||
count = 0;
|
|
||||||
m = 50;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
char s[LINEBUFSIZE];
|
|
||||||
|
|
||||||
connection_loop:
|
|
||||||
u = 1;
|
|
||||||
tty_wait_connection (tty);
|
|
||||||
|
|
||||||
chopstx_usec_wait (50*1000);
|
|
||||||
|
|
||||||
puts("send ZLP");
|
|
||||||
/* Send ZLP at the beginning. */
|
|
||||||
tty_send (tty, s, 0);
|
|
||||||
|
|
||||||
memcpy (s, "xx: Hello, World with Chopstx!\r\n", 32);
|
|
||||||
s[0] = hexchar (count >> 4);
|
|
||||||
s[1] = hexchar (count & 0x0f);
|
|
||||||
|
|
||||||
puts("send hello");
|
|
||||||
if (tty_send (tty, s, 32) < 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
s[0] = hexchar (count >> 4);
|
|
||||||
s[1] = hexchar (count & 0x0f);
|
|
||||||
s[2] = ':';
|
|
||||||
s[3] = ' ';
|
|
||||||
compose_hex_ptr (s+4, addr);
|
|
||||||
s[20] = '\r';
|
|
||||||
s[21] = '\n';
|
|
||||||
|
|
||||||
count++;
|
|
||||||
|
|
||||||
if (tty_send (tty, s, 22) < 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
uint32_t usec;
|
|
||||||
|
|
||||||
/* Prompt */
|
|
||||||
if (tty_send (tty, "> ", 2) < 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
usec = 3000000; /* 3.0 seconds */
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
int size = tty_recv (tty, s, &usec);
|
|
||||||
u ^= 1;
|
|
||||||
|
|
||||||
if (size < 0)
|
|
||||||
goto connection_loop;
|
|
||||||
|
|
||||||
if (size == 1)
|
|
||||||
/* Do nothing but prompt again. */
|
|
||||||
break;
|
|
||||||
else if (size)
|
|
||||||
{
|
|
||||||
/* Newline into NUL */
|
|
||||||
s[size - 1] = 0;
|
|
||||||
cmd_dispatch (tty, (char *)s);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
#define LINEBUFSIZE 128
|
|
||||||
|
|
||||||
struct tty;
|
|
||||||
|
|
||||||
struct tty *tty_open (void);
|
|
||||||
void tty_wait_configured (struct tty *tty);
|
|
||||||
void tty_wait_connection (struct tty *tty);
|
|
||||||
int tty_send (struct tty *tty, const char *buf, int count);
|
|
||||||
int tty_recv (struct tty *tty, char *buf, uint32_t *timeout);
|
|
@ -1,952 +0,0 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <chopstx.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "usb_lld.h"
|
|
||||||
#include "tty.h"
|
|
||||||
|
|
||||||
static chopstx_intr_t usb_intr;
|
|
||||||
|
|
||||||
struct line_coding
|
|
||||||
{
|
|
||||||
uint32_t bitrate;
|
|
||||||
uint8_t format;
|
|
||||||
uint8_t paritytype;
|
|
||||||
uint8_t datatype;
|
|
||||||
} __attribute__((packed));
|
|
||||||
|
|
||||||
static const struct line_coding line_coding0 = {
|
|
||||||
115200, /* baud rate: 115200 */
|
|
||||||
0x00, /* stop bits: 1 */
|
|
||||||
0x00, /* parity: none */
|
|
||||||
0x08 /* bits: 8 */
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Currently, we only support a single TTY.
|
|
||||||
*
|
|
||||||
* It is possible to extend to support multiple TTYs, for multiple
|
|
||||||
* interfaces.
|
|
||||||
*
|
|
||||||
* In that case, add argument to TTY_OPEN function and
|
|
||||||
* modify TTY_GET function to get the TTY structure. Functions which
|
|
||||||
* directy accesses TTY0 (usb_device_reset and usb_set_configuration)
|
|
||||||
* should be modified, too.
|
|
||||||
*
|
|
||||||
* Modification of TTY_MAIN thread will be also needed to echo back
|
|
||||||
* input for each TTY, and the thread should run if one of TTY is
|
|
||||||
* opened.
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct tty {
|
|
||||||
chopstx_mutex_t mtx;
|
|
||||||
chopstx_cond_t cnd;
|
|
||||||
uint8_t inputline[LINEBUFSIZE]; /* Line editing is supported */
|
|
||||||
uint8_t send_buf[LINEBUFSIZE]; /* Sending ring buffer for echo back */
|
|
||||||
uint8_t send_buf0[64];
|
|
||||||
uint8_t recv_buf0[64];
|
|
||||||
uint32_t inputline_len : 8;
|
|
||||||
uint32_t send_head : 8;
|
|
||||||
uint32_t send_tail : 8;
|
|
||||||
uint32_t flag_connected : 1;
|
|
||||||
uint32_t flag_send_ready : 1;
|
|
||||||
uint32_t flag_input_avail : 1;
|
|
||||||
uint32_t : 2;
|
|
||||||
uint32_t device_state : 3; /* USB device status */
|
|
||||||
struct line_coding line_coding;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct tty tty0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Locate TTY structure from interface number or endpoint number.
|
|
||||||
* Currently, it always returns tty0, because we only have the one.
|
|
||||||
*/
|
|
||||||
static struct tty *
|
|
||||||
tty_get (int interface, uint8_t ep_num)
|
|
||||||
{
|
|
||||||
struct tty *t = &tty0;
|
|
||||||
|
|
||||||
if (interface >= 0)
|
|
||||||
{
|
|
||||||
if (interface == 0)
|
|
||||||
t = &tty0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (ep_num == ENDP1 || ep_num == ENDP2 || ep_num == ENDP3)
|
|
||||||
t = &tty0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define USB_CDC_REQ_SET_LINE_CODING 0x20
|
|
||||||
#define USB_CDC_REQ_GET_LINE_CODING 0x21
|
|
||||||
#define USB_CDC_REQ_SET_CONTROL_LINE_STATE 0x22
|
|
||||||
#define USB_CDC_REQ_SEND_BREAK 0x23
|
|
||||||
|
|
||||||
/* USB Device Descriptor */
|
|
||||||
static const uint8_t vcom_device_desc[18] = {
|
|
||||||
18, /* bLength */
|
|
||||||
DEVICE_DESCRIPTOR, /* bDescriptorType */
|
|
||||||
0x10, 0x01, /* bcdUSB = 1.1 */
|
|
||||||
0x02, /* bDeviceClass (CDC). */
|
|
||||||
0x00, /* bDeviceSubClass. */
|
|
||||||
0x00, /* bDeviceProtocol. */
|
|
||||||
0x40, /* bMaxPacketSize. */
|
|
||||||
0xFF, 0xFF, /* idVendor */
|
|
||||||
0x01, 0x00, /* idProduct */
|
|
||||||
0x00, 0x01, /* bcdDevice */
|
|
||||||
1, /* iManufacturer. */
|
|
||||||
2, /* iProduct. */
|
|
||||||
3, /* iSerialNumber. */
|
|
||||||
1 /* bNumConfigurations. */
|
|
||||||
};
|
|
||||||
|
|
||||||
#define VCOM_FEATURE_BUS_POWERED 0x80
|
|
||||||
|
|
||||||
/* Configuration Descriptor tree for a CDC.*/
|
|
||||||
static const uint8_t vcom_config_desc[67] = {
|
|
||||||
9,
|
|
||||||
CONFIG_DESCRIPTOR, /* bDescriptorType: Configuration */
|
|
||||||
/* Configuration Descriptor.*/
|
|
||||||
67, 0x00, /* wTotalLength. */
|
|
||||||
0x02, /* bNumInterfaces. */
|
|
||||||
0x01, /* bConfigurationValue. */
|
|
||||||
0, /* iConfiguration. */
|
|
||||||
VCOM_FEATURE_BUS_POWERED, /* bmAttributes. */
|
|
||||||
50, /* bMaxPower (100mA). */
|
|
||||||
/* Interface Descriptor.*/
|
|
||||||
9,
|
|
||||||
INTERFACE_DESCRIPTOR,
|
|
||||||
0x00, /* bInterfaceNumber. */
|
|
||||||
0x00, /* bAlternateSetting. */
|
|
||||||
0x01, /* bNumEndpoints. */
|
|
||||||
0x02, /* bInterfaceClass (Communications Interface Class,
|
|
||||||
CDC section 4.2). */
|
|
||||||
0x02, /* bInterfaceSubClass (Abstract Control Model, CDC
|
|
||||||
section 4.3). */
|
|
||||||
0x01, /* bInterfaceProtocol (AT commands, CDC section
|
|
||||||
4.4). */
|
|
||||||
0, /* iInterface. */
|
|
||||||
/* Header Functional Descriptor (CDC section 5.2.3).*/
|
|
||||||
5, /* bLength. */
|
|
||||||
0x24, /* bDescriptorType (CS_INTERFACE). */
|
|
||||||
0x00, /* bDescriptorSubtype (Header Functional Descriptor). */
|
|
||||||
0x10, 0x01, /* bcdCDC. */
|
|
||||||
/* Call Management Functional Descriptor. */
|
|
||||||
5, /* bFunctionLength. */
|
|
||||||
0x24, /* bDescriptorType (CS_INTERFACE). */
|
|
||||||
0x01, /* bDescriptorSubtype (Call Management Functional
|
|
||||||
Descriptor). */
|
|
||||||
0x03, /* bmCapabilities (D0+D1). */
|
|
||||||
0x01, /* bDataInterface. */
|
|
||||||
/* ACM Functional Descriptor.*/
|
|
||||||
4, /* bFunctionLength. */
|
|
||||||
0x24, /* bDescriptorType (CS_INTERFACE). */
|
|
||||||
0x02, /* bDescriptorSubtype (Abstract Control Management
|
|
||||||
Descriptor). */
|
|
||||||
0x02, /* bmCapabilities. */
|
|
||||||
/* Union Functional Descriptor.*/
|
|
||||||
5, /* bFunctionLength. */
|
|
||||||
0x24, /* bDescriptorType (CS_INTERFACE). */
|
|
||||||
0x06, /* bDescriptorSubtype (Union Functional
|
|
||||||
Descriptor). */
|
|
||||||
0x00, /* bMasterInterface (Communication Class
|
|
||||||
Interface). */
|
|
||||||
0x01, /* bSlaveInterface0 (Data Class Interface). */
|
|
||||||
/* Endpoint 2 Descriptor.*/
|
|
||||||
7,
|
|
||||||
ENDPOINT_DESCRIPTOR,
|
|
||||||
ENDP2|0x80, /* bEndpointAddress. */
|
|
||||||
0x03, /* bmAttributes (Interrupt). */
|
|
||||||
0x08, 0x00, /* wMaxPacketSize. */
|
|
||||||
0xFF, /* bInterval. */
|
|
||||||
/* Interface Descriptor.*/
|
|
||||||
9,
|
|
||||||
INTERFACE_DESCRIPTOR, /* bDescriptorType: */
|
|
||||||
0x01, /* bInterfaceNumber. */
|
|
||||||
0x00, /* bAlternateSetting. */
|
|
||||||
0x02, /* bNumEndpoints. */
|
|
||||||
0x0A, /* bInterfaceClass (Data Class Interface, CDC section 4.5). */
|
|
||||||
0x00, /* bInterfaceSubClass (CDC section 4.6). */
|
|
||||||
0x00, /* bInterfaceProtocol (CDC section 4.7). */
|
|
||||||
0x00, /* iInterface. */
|
|
||||||
/* Endpoint 3 Descriptor.*/
|
|
||||||
7,
|
|
||||||
ENDPOINT_DESCRIPTOR, /* bDescriptorType: Endpoint */
|
|
||||||
ENDP3, /* bEndpointAddress. */
|
|
||||||
0x02, /* bmAttributes (Bulk). */
|
|
||||||
0x40, 0x00, /* wMaxPacketSize. */
|
|
||||||
0x00, /* bInterval. */
|
|
||||||
/* Endpoint 1 Descriptor.*/
|
|
||||||
7,
|
|
||||||
ENDPOINT_DESCRIPTOR, /* bDescriptorType: Endpoint */
|
|
||||||
ENDP1|0x80, /* bEndpointAddress. */
|
|
||||||
0x02, /* bmAttributes (Bulk). */
|
|
||||||
0x40, 0x00, /* wMaxPacketSize. */
|
|
||||||
0x00 /* bInterval. */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* U.S. English language identifier.
|
|
||||||
*/
|
|
||||||
static const uint8_t vcom_string0[4] = {
|
|
||||||
4, /* bLength */
|
|
||||||
STRING_DESCRIPTOR,
|
|
||||||
0x09, 0x04 /* LangID = 0x0409: US-English */
|
|
||||||
};
|
|
||||||
|
|
||||||
static const uint8_t vcom_string1[] = {
|
|
||||||
23*2+2, /* bLength */
|
|
||||||
STRING_DESCRIPTOR, /* bDescriptorType */
|
|
||||||
/* Manufacturer: "Flying Stone Technology" */
|
|
||||||
'F', 0, 'l', 0, 'y', 0, 'i', 0, 'n', 0, 'g', 0, ' ', 0, 'S', 0,
|
|
||||||
't', 0, 'o', 0, 'n', 0, 'e', 0, ' ', 0, 'T', 0, 'e', 0, 'c', 0,
|
|
||||||
'h', 0, 'n', 0, 'o', 0, 'l', 0, 'o', 0, 'g', 0, 'y', 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
static const uint8_t vcom_string2[] = {
|
|
||||||
14*2+2, /* bLength */
|
|
||||||
STRING_DESCRIPTOR, /* bDescriptorType */
|
|
||||||
/* Product name: "Chopstx Sample" */
|
|
||||||
'C', 0, 'h', 0, 'o', 0, 'p', 0, 's', 0, 't', 0, 'x', 0, ' ', 0,
|
|
||||||
'S', 0, 'a', 0, 'm', 0, 'p', 0, 'l', 0, 'e', 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Serial Number string.
|
|
||||||
*/
|
|
||||||
static const uint8_t vcom_string3[28] = {
|
|
||||||
28, /* bLength */
|
|
||||||
STRING_DESCRIPTOR, /* bDescriptorType */
|
|
||||||
'0', 0, '.', 0, '0', 0, '0', 0, /* Version number */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#define NUM_INTERFACES 2
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
usb_device_reset (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
usb_lld_reset (dev, VCOM_FEATURE_BUS_POWERED);
|
|
||||||
|
|
||||||
/* Initialize Endpoint 0 */
|
|
||||||
usb_lld_setup_endp (dev, ENDP0, 1, 1);
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&tty0.mtx);
|
|
||||||
tty0.inputline_len = 0;
|
|
||||||
tty0.send_head = tty0.send_tail = 0;
|
|
||||||
tty0.flag_connected = 0;
|
|
||||||
tty0.flag_send_ready = 1;
|
|
||||||
tty0.flag_input_avail = 0;
|
|
||||||
tty0.device_state = USB_DEVICE_STATE_ATTACHED;
|
|
||||||
memcpy (&tty0.line_coding, &line_coding0, sizeof (struct line_coding));
|
|
||||||
chopstx_mutex_unlock (&tty0.mtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define CDC_CTRL_DTR 0x0001
|
|
||||||
|
|
||||||
static void
|
|
||||||
usb_ctrl_write_finish (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
struct device_req *arg = &dev->dev_req;
|
|
||||||
uint8_t type_rcp = arg->type & (REQUEST_TYPE|RECIPIENT);
|
|
||||||
|
|
||||||
if (type_rcp == (CLASS_REQUEST | INTERFACE_RECIPIENT) && arg->index == 0
|
|
||||||
&& USB_SETUP_SET (arg->type)
|
|
||||||
&& arg->request == USB_CDC_REQ_SET_CONTROL_LINE_STATE)
|
|
||||||
{
|
|
||||||
struct tty *t = tty_get (arg->index, 0);
|
|
||||||
|
|
||||||
/* Open/close the connection. */
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
t->flag_connected = ((arg->value & CDC_CTRL_DTR) != 0);
|
|
||||||
chopstx_cond_signal (&t->cnd);
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The transaction was already finished. So, it is no use to call
|
|
||||||
* usb_lld_ctrl_error when the condition does not match.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
vcom_port_data_setup (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
struct device_req *arg = &dev->dev_req;
|
|
||||||
|
|
||||||
if (USB_SETUP_GET (arg->type))
|
|
||||||
{
|
|
||||||
struct tty *t = tty_get (arg->index, 0);
|
|
||||||
|
|
||||||
if (arg->request == USB_CDC_REQ_GET_LINE_CODING)
|
|
||||||
return usb_lld_ctrl_send (dev, &t->line_coding,
|
|
||||||
sizeof (struct line_coding));
|
|
||||||
}
|
|
||||||
else /* USB_SETUP_SET (req) */
|
|
||||||
{
|
|
||||||
if (arg->request == USB_CDC_REQ_SET_LINE_CODING
|
|
||||||
&& arg->len == sizeof (struct line_coding))
|
|
||||||
{
|
|
||||||
struct tty *t = tty_get (arg->index, 0);
|
|
||||||
|
|
||||||
return usb_lld_ctrl_recv (dev, &t->line_coding,
|
|
||||||
sizeof (struct line_coding));
|
|
||||||
}
|
|
||||||
else if (arg->request == USB_CDC_REQ_SET_CONTROL_LINE_STATE)
|
|
||||||
return usb_lld_ctrl_ack (dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
usb_setup (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
struct device_req *arg = &dev->dev_req;
|
|
||||||
uint8_t type_rcp = arg->type & (REQUEST_TYPE|RECIPIENT);
|
|
||||||
|
|
||||||
if (type_rcp == (CLASS_REQUEST | INTERFACE_RECIPIENT) && arg->index == 0)
|
|
||||||
return vcom_port_data_setup (dev);
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
usb_get_descriptor (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
struct device_req *arg = &dev->dev_req;
|
|
||||||
uint8_t rcp = arg->type & RECIPIENT;
|
|
||||||
uint8_t desc_type = (arg->value >> 8);
|
|
||||||
uint8_t desc_index = (arg->value & 0xff);
|
|
||||||
|
|
||||||
if (rcp != DEVICE_RECIPIENT)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (desc_type == DEVICE_DESCRIPTOR)
|
|
||||||
return usb_lld_ctrl_send (dev,
|
|
||||||
vcom_device_desc, sizeof (vcom_device_desc));
|
|
||||||
else if (desc_type == CONFIG_DESCRIPTOR)
|
|
||||||
return usb_lld_ctrl_send (dev,
|
|
||||||
vcom_config_desc, sizeof (vcom_config_desc));
|
|
||||||
else if (desc_type == STRING_DESCRIPTOR)
|
|
||||||
{
|
|
||||||
const uint8_t *str;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
switch (desc_index)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
str = vcom_string0;
|
|
||||||
size = sizeof (vcom_string0);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
str = vcom_string1;
|
|
||||||
size = sizeof (vcom_string1);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
str = vcom_string2;
|
|
||||||
size = sizeof (vcom_string2);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
str = vcom_string3;
|
|
||||||
size = sizeof (vcom_string3);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return usb_lld_ctrl_send (dev, str, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
vcom_setup_endpoints_for_interface (struct usb_dev *dev,
|
|
||||||
uint16_t interface, int stop)
|
|
||||||
{
|
|
||||||
if (interface == 0)
|
|
||||||
{
|
|
||||||
if (!stop)
|
|
||||||
usb_lld_setup_endp (dev, ENDP2, 0, 1);
|
|
||||||
else
|
|
||||||
usb_lld_stall_tx (ENDP2);
|
|
||||||
}
|
|
||||||
else if (interface == 1)
|
|
||||||
{
|
|
||||||
if (!stop)
|
|
||||||
{
|
|
||||||
usb_lld_setup_endp (dev, ENDP1, 0, 1);
|
|
||||||
usb_lld_setup_endp (dev, ENDP3, 1, 0);
|
|
||||||
/* Start with no data receiving (ENDP3 not enabled)*/
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
usb_lld_stall_tx (ENDP1);
|
|
||||||
usb_lld_stall_rx (ENDP3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
usb_set_configuration (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
uint8_t current_conf;
|
|
||||||
|
|
||||||
current_conf = usb_lld_current_configuration (dev);
|
|
||||||
if (current_conf == 0)
|
|
||||||
{
|
|
||||||
if (dev->dev_req.value != 1)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
usb_lld_set_configuration (dev, 1);
|
|
||||||
for (i = 0; i < NUM_INTERFACES; i++)
|
|
||||||
vcom_setup_endpoints_for_interface (dev, i, 0);
|
|
||||||
chopstx_mutex_lock (&tty0.mtx);
|
|
||||||
tty0.device_state = USB_DEVICE_STATE_CONFIGURED;
|
|
||||||
chopstx_cond_signal (&tty0.cnd);
|
|
||||||
chopstx_mutex_unlock (&tty0.mtx);
|
|
||||||
}
|
|
||||||
else if (current_conf != dev->dev_req.value)
|
|
||||||
{
|
|
||||||
if (dev->dev_req.value != 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
usb_lld_set_configuration (dev, 0);
|
|
||||||
for (i = 0; i < NUM_INTERFACES; i++)
|
|
||||||
vcom_setup_endpoints_for_interface (dev, i, 1);
|
|
||||||
chopstx_mutex_lock (&tty0.mtx);
|
|
||||||
tty0.device_state = USB_DEVICE_STATE_ADDRESSED;
|
|
||||||
chopstx_cond_signal (&tty0.cnd);
|
|
||||||
chopstx_mutex_unlock (&tty0.mtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return usb_lld_ctrl_ack (dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
usb_set_interface (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
uint16_t interface = dev->dev_req.index;
|
|
||||||
uint16_t alt = dev->dev_req.value;
|
|
||||||
|
|
||||||
if (interface >= NUM_INTERFACES)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (alt != 0)
|
|
||||||
return -1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vcom_setup_endpoints_for_interface (dev, interface, 0);
|
|
||||||
return usb_lld_ctrl_ack (dev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
usb_get_interface (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
const uint8_t zero = 0;
|
|
||||||
uint16_t interface = dev->dev_req.index;
|
|
||||||
|
|
||||||
if (interface >= NUM_INTERFACES)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/* We don't have alternate interface, so, always return 0. */
|
|
||||||
return usb_lld_ctrl_send (dev, &zero, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
usb_get_status_interface (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
const uint16_t status_info = 0;
|
|
||||||
uint16_t interface = dev->dev_req.index;
|
|
||||||
|
|
||||||
if (interface >= NUM_INTERFACES)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return usb_lld_ctrl_send (dev, &status_info, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Put a character into the ring buffer to be send back.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
put_char_to_ringbuffer (struct tty *t, int c)
|
|
||||||
{
|
|
||||||
uint32_t next = (t->send_tail + 1) % LINEBUFSIZE;
|
|
||||||
|
|
||||||
if (t->send_head == next)
|
|
||||||
/* full */
|
|
||||||
/* All that we can do is ignore this char. */
|
|
||||||
return;
|
|
||||||
|
|
||||||
t->send_buf[t->send_tail] = c;
|
|
||||||
t->send_tail = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get characters from ring buffer into S.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
get_chars_from_ringbuffer (struct tty *t, uint8_t *s, int len)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
if (t->send_head == t->send_tail)
|
|
||||||
/* Empty */
|
|
||||||
return i;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
s[i++] = t->send_buf[t->send_head];
|
|
||||||
t->send_head = (t->send_head + 1) % LINEBUFSIZE;
|
|
||||||
}
|
|
||||||
while (t->send_head != t->send_tail && i < len);
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
tty_echo_char (struct tty *t, int c)
|
|
||||||
{
|
|
||||||
put_char_to_ringbuffer (t, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
usb_tx_done (uint8_t ep_num, uint16_t len)
|
|
||||||
{
|
|
||||||
struct tty *t = tty_get (-1, ep_num);
|
|
||||||
|
|
||||||
(void)len;
|
|
||||||
if (ep_num == ENDP1)
|
|
||||||
{
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
if (t->flag_send_ready == 0)
|
|
||||||
{
|
|
||||||
t->flag_send_ready = 1;
|
|
||||||
chopstx_cond_signal (&t->cnd);
|
|
||||||
}
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
}
|
|
||||||
else if (ep_num == ENDP2)
|
|
||||||
{
|
|
||||||
/* Nothing */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
tty_input_char (struct tty *t, int c)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
int r = 0;
|
|
||||||
|
|
||||||
/* Process DEL, C-U, C-R, and RET as editing command. */
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case 0x0d: /* Control-M */
|
|
||||||
t->inputline[t->inputline_len++] = '\n';
|
|
||||||
tty_echo_char (t, 0x0d);
|
|
||||||
tty_echo_char (t, 0x0a);
|
|
||||||
t->flag_input_avail = 1;
|
|
||||||
r = 1;
|
|
||||||
chopstx_cond_signal (&t->cnd);
|
|
||||||
break;
|
|
||||||
case 0x12: /* Control-R */
|
|
||||||
tty_echo_char (t, '^');
|
|
||||||
tty_echo_char (t, 'R');
|
|
||||||
tty_echo_char (t, 0x0d);
|
|
||||||
tty_echo_char (t, 0x0a);
|
|
||||||
for (i = 0; i < t->inputline_len; i++)
|
|
||||||
tty_echo_char (t, t->inputline[i]);
|
|
||||||
break;
|
|
||||||
case 0x15: /* Control-U */
|
|
||||||
for (i = 0; i < t->inputline_len; i++)
|
|
||||||
{
|
|
||||||
tty_echo_char (t, 0x08);
|
|
||||||
tty_echo_char (t, 0x20);
|
|
||||||
tty_echo_char (t, 0x08);
|
|
||||||
}
|
|
||||||
t->inputline_len = 0;
|
|
||||||
break;
|
|
||||||
case 0x7f: /* DEL */
|
|
||||||
if (t->inputline_len > 0)
|
|
||||||
{
|
|
||||||
tty_echo_char (t, 0x08);
|
|
||||||
tty_echo_char (t, 0x20);
|
|
||||||
tty_echo_char (t, 0x08);
|
|
||||||
t->inputline_len--;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (t->inputline_len < sizeof (t->inputline) - 1)
|
|
||||||
{
|
|
||||||
tty_echo_char (t, c);
|
|
||||||
t->inputline[t->inputline_len++] = c;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
/* Beep */
|
|
||||||
tty_echo_char (t, 0x0a);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
usb_rx_ready (uint8_t ep_num, uint16_t len)
|
|
||||||
{
|
|
||||||
struct tty *t = tty_get (-1, ep_num);
|
|
||||||
if (ep_num == ENDP3)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
|
||||||
if (tty_input_char (t, t->recv_buf0[i]))
|
|
||||||
break;
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
if (t->flag_input_avail == 0)
|
|
||||||
usb_lld_rx_enable_buf (ENDP3, t->recv_buf0, 64);
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *tty_main (void *arg);
|
|
||||||
|
|
||||||
#define PRIO_TTY 4
|
|
||||||
|
|
||||||
static char __process3_stack_base__[4096];
|
|
||||||
#define STACK_ADDR_TTY ((uintptr_t)__process3_stack_base__)
|
|
||||||
#define STACK_SIZE_TTY (sizeof __process3_stack_base__)
|
|
||||||
|
|
||||||
struct tty *
|
|
||||||
tty_open (void)
|
|
||||||
{
|
|
||||||
chopstx_mutex_init (&tty0.mtx);
|
|
||||||
chopstx_cond_init (&tty0.cnd);
|
|
||||||
tty0.inputline_len = 0;
|
|
||||||
tty0.send_head = tty0.send_tail = 0;
|
|
||||||
tty0.flag_connected = 0;
|
|
||||||
tty0.flag_send_ready = 1;
|
|
||||||
tty0.flag_input_avail = 0;
|
|
||||||
tty0.device_state = USB_DEVICE_STATE_UNCONNECTED;
|
|
||||||
memcpy (&tty0.line_coding, &line_coding0, sizeof (struct line_coding));
|
|
||||||
|
|
||||||
chopstx_create (PRIO_TTY, STACK_ADDR_TTY, STACK_SIZE_TTY, tty_main, &tty0);
|
|
||||||
return &tty0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void *
|
|
||||||
tty_main (void *arg)
|
|
||||||
{
|
|
||||||
struct tty *t = arg;
|
|
||||||
struct usb_dev dev;
|
|
||||||
int e;
|
|
||||||
|
|
||||||
#if defined(OLDER_SYS_H)
|
|
||||||
/*
|
|
||||||
* Historically (before sys < 3.0), NVIC priority setting for USB
|
|
||||||
* interrupt was done in usb_lld_sys_init. Thus this code.
|
|
||||||
*
|
|
||||||
* When USB interrupt occurs between usb_lld_init (which assumes
|
|
||||||
* ISR) and chopstx_claim_irq (which clears pending interrupt),
|
|
||||||
* invocation of usb_lld_event_handler won't occur.
|
|
||||||
*
|
|
||||||
* Calling usb_lld_event_handler is no harm even if there were no
|
|
||||||
* interrupts, thus, we call it unconditionally here, just in case
|
|
||||||
* if there is a request.
|
|
||||||
*
|
|
||||||
* We can't call usb_lld_init after chopstx_claim_irq, as
|
|
||||||
* usb_lld_init does its own setting for NVIC. Calling
|
|
||||||
* chopstx_claim_irq after usb_lld_init overrides that.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
|
||||||
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
|
||||||
goto event_handle;
|
|
||||||
#else
|
|
||||||
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
|
||||||
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
chopstx_intr_wait (&usb_intr);
|
|
||||||
if (usb_intr.ready)
|
|
||||||
{
|
|
||||||
uint8_t ep_num;
|
|
||||||
#if defined(OLDER_SYS_H)
|
|
||||||
event_handle:
|
|
||||||
#endif
|
|
||||||
/*
|
|
||||||
* When interrupt is detected, call usb_lld_event_handler.
|
|
||||||
* The event may be one of following:
|
|
||||||
* (1) Transfer to endpoint (bulk or interrupt)
|
|
||||||
* In this case EP_NUM is encoded in the variable E.
|
|
||||||
* (2) "NONE" event: some trasfer was done, but all was
|
|
||||||
* done by lower layer, no other work is needed in
|
|
||||||
* upper layer.
|
|
||||||
* (3) Device events: Reset or Suspend
|
|
||||||
* (4) Device requests to the endpoint zero.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
e = usb_lld_event_handler (&dev);
|
|
||||||
chopstx_intr_done (&usb_intr);
|
|
||||||
ep_num = USB_EVENT_ENDP (e);
|
|
||||||
|
|
||||||
if (ep_num != 0)
|
|
||||||
{
|
|
||||||
if (USB_EVENT_TXRX (e))
|
|
||||||
usb_tx_done (ep_num, USB_EVENT_LEN (e));
|
|
||||||
else
|
|
||||||
usb_rx_ready (ep_num, USB_EVENT_LEN (e));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
switch (USB_EVENT_ID (e))
|
|
||||||
{
|
|
||||||
case USB_EVENT_DEVICE_RESET:
|
|
||||||
usb_device_reset (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_DEVICE_ADDRESSED:
|
|
||||||
/* The addres is assigned to the device. We don't
|
|
||||||
* need to do anything for this actually, but in this
|
|
||||||
* application, we maintain the USB status of the
|
|
||||||
* device. Usually, just "continue" as EVENT_OK is
|
|
||||||
* OK.
|
|
||||||
*/
|
|
||||||
chopstx_mutex_lock (&tty0.mtx);
|
|
||||||
tty0.device_state = USB_DEVICE_STATE_ADDRESSED;
|
|
||||||
chopstx_cond_signal (&tty0.cnd);
|
|
||||||
chopstx_mutex_unlock (&tty0.mtx);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_GET_DESCRIPTOR:
|
|
||||||
if (usb_get_descriptor (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_SET_CONFIGURATION:
|
|
||||||
if (usb_set_configuration (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_SET_INTERFACE:
|
|
||||||
if (usb_set_interface (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_CTRL_REQUEST:
|
|
||||||
/* Device specific device request. */
|
|
||||||
if (usb_setup (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_GET_STATUS_INTERFACE:
|
|
||||||
if (usb_get_status_interface (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_GET_INTERFACE:
|
|
||||||
if (usb_get_interface (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_SET_FEATURE_DEVICE:
|
|
||||||
case USB_EVENT_SET_FEATURE_ENDPOINT:
|
|
||||||
case USB_EVENT_CLEAR_FEATURE_DEVICE:
|
|
||||||
case USB_EVENT_CLEAR_FEATURE_ENDPOINT:
|
|
||||||
usb_lld_ctrl_ack (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_CTRL_WRITE_FINISH:
|
|
||||||
/* Control WRITE transfer finished. */
|
|
||||||
usb_ctrl_write_finish (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_OK:
|
|
||||||
case USB_EVENT_DEVICE_SUSPEND:
|
|
||||||
default:
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
if (t->device_state == USB_DEVICE_STATE_CONFIGURED && t->flag_connected
|
|
||||||
&& t->flag_send_ready)
|
|
||||||
{
|
|
||||||
uint8_t line[32];
|
|
||||||
int len = get_chars_from_ringbuffer (t, line, sizeof (len));
|
|
||||||
|
|
||||||
if (len)
|
|
||||||
{
|
|
||||||
memcpy (t->send_buf0, line, len);
|
|
||||||
usb_lld_tx_enable_buf (ENDP1, t->send_buf0, len);
|
|
||||||
t->flag_send_ready = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
tty_wait_configured (struct tty *t)
|
|
||||||
{
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
while (t->device_state != USB_DEVICE_STATE_CONFIGURED)
|
|
||||||
chopstx_cond_wait (&t->cnd, &t->mtx);
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
tty_wait_connection (struct tty *t)
|
|
||||||
{
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
while (t->flag_connected == 0)
|
|
||||||
chopstx_cond_wait (&t->cnd, &t->mtx);
|
|
||||||
t->flag_send_ready = 1;
|
|
||||||
t->flag_input_avail = 0;
|
|
||||||
t->send_head = t->send_tail = 0;
|
|
||||||
t->inputline_len = 0;
|
|
||||||
usb_lld_rx_enable_buf (ENDP3, t->recv_buf0, 64); /* Accept input for line */
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
check_tx (struct tty *t)
|
|
||||||
{
|
|
||||||
if (t->flag_send_ready)
|
|
||||||
/* TX done */
|
|
||||||
return 1;
|
|
||||||
if (t->flag_connected == 0)
|
|
||||||
/* Disconnected */
|
|
||||||
return -1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
tty_send (struct tty *t, const char *buf, int len)
|
|
||||||
{
|
|
||||||
int r;
|
|
||||||
const char *p;
|
|
||||||
int count;
|
|
||||||
|
|
||||||
p = buf;
|
|
||||||
count = len >= 64 ? 64 : len;
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
while ((r = check_tx (t)) == 0)
|
|
||||||
chopstx_cond_wait (&t->cnd, &t->mtx);
|
|
||||||
if (r > 0)
|
|
||||||
{
|
|
||||||
usb_lld_tx_enable_buf (ENDP1, p, count);
|
|
||||||
t->flag_send_ready = 0;
|
|
||||||
}
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
|
|
||||||
len -= count;
|
|
||||||
p += count;
|
|
||||||
if (len == 0 && count != 64)
|
|
||||||
/*
|
|
||||||
* The size of the last packet should be != 0
|
|
||||||
* If 64, send ZLP (zelo length packet)
|
|
||||||
*/
|
|
||||||
break;
|
|
||||||
count = len >= 64 ? 64 : len;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait until all sent. */
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
while ((r = check_tx (t)) == 0)
|
|
||||||
chopstx_cond_wait (&t->cnd, &t->mtx);
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
check_rx (void *arg)
|
|
||||||
{
|
|
||||||
struct tty *t = arg;
|
|
||||||
|
|
||||||
if (t->flag_input_avail)
|
|
||||||
/* RX */
|
|
||||||
return 1;
|
|
||||||
if (t->flag_connected == 0)
|
|
||||||
/* Disconnected */
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns -1 on connection close
|
|
||||||
* 0 on timeout.
|
|
||||||
* >0 length of the inputline (including final \n)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
tty_recv (struct tty *t, char *buf, uint32_t *timeout)
|
|
||||||
{
|
|
||||||
int r;
|
|
||||||
chopstx_poll_cond_t poll_desc;
|
|
||||||
|
|
||||||
poll_desc.type = CHOPSTX_POLL_COND;
|
|
||||||
poll_desc.ready = 0;
|
|
||||||
poll_desc.cond = &t->cnd;
|
|
||||||
poll_desc.mutex = &t->mtx;
|
|
||||||
poll_desc.check = check_rx;
|
|
||||||
poll_desc.arg = t;
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
struct chx_poll_head *pd_array[1] = {
|
|
||||||
(struct chx_poll_head *)&poll_desc
|
|
||||||
};
|
|
||||||
chopstx_poll (timeout, 1, pd_array);
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
r = check_rx (t);
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
if (r || (timeout != NULL && *timeout == 0))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
if (t->flag_connected == 0)
|
|
||||||
r = -1;
|
|
||||||
else if (t->flag_input_avail)
|
|
||||||
{
|
|
||||||
r = t->inputline_len;
|
|
||||||
memcpy (buf, t->inputline, r);
|
|
||||||
t->flag_input_avail = 0;
|
|
||||||
usb_lld_rx_enable_buf (ENDP3, t->recv_buf0, 64);
|
|
||||||
t->inputline_len = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
r = 0;
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
# Makefile for example application of Chopstx
|
|
||||||
|
|
||||||
PROJECT = sample
|
|
||||||
|
|
||||||
CHOPSTX = ..
|
|
||||||
LDSCRIPT= sample.ld
|
|
||||||
CSRC = sample.c usb-cdc.c
|
|
||||||
|
|
||||||
CHIP=stm32f103
|
|
||||||
|
|
||||||
USE_SYS = yes
|
|
||||||
USE_USB = yes
|
|
||||||
ENABLE_OUTPUT_HEX=yes
|
|
||||||
|
|
||||||
###################################
|
|
||||||
CROSS = arm-none-eabi-
|
|
||||||
CC = $(CROSS)gcc
|
|
||||||
LD = $(CROSS)gcc
|
|
||||||
OBJCOPY = $(CROSS)objcopy
|
|
||||||
|
|
||||||
MCU = cortex-m3
|
|
||||||
CWARN = -Wall -Wextra -Wstrict-prototypes
|
|
||||||
DEFS = -DUSE_SYS3 -DFREE_STANDING -DMHZ=72
|
|
||||||
OPT = -O3 -Os -g
|
|
||||||
LIBS =
|
|
||||||
|
|
||||||
####################
|
|
||||||
include ../rules.mk
|
|
||||||
|
|
||||||
board.h:
|
|
||||||
@echo Please make a symbolic link \'board.h\' to a file in ../board;
|
|
||||||
@exit 1
|
|
||||||
|
|
||||||
sys.c: board.h
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
rm -f board.h
|
|
@ -1,167 +0,0 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <chopstx.h>
|
|
||||||
|
|
||||||
#include "usb_lld.h"
|
|
||||||
#include "tty.h"
|
|
||||||
|
|
||||||
/* For set_led */
|
|
||||||
#include "board.h"
|
|
||||||
#include "sys.h"
|
|
||||||
|
|
||||||
static chopstx_mutex_t mtx;
|
|
||||||
static chopstx_cond_t cnd0;
|
|
||||||
static chopstx_cond_t cnd1;
|
|
||||||
|
|
||||||
static uint8_t u, v;
|
|
||||||
static uint8_t m; /* 0..100 */
|
|
||||||
|
|
||||||
static void *
|
|
||||||
pwm (void *arg)
|
|
||||||
{
|
|
||||||
(void)arg;
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&mtx);
|
|
||||||
chopstx_cond_wait (&cnd0, &mtx);
|
|
||||||
chopstx_mutex_unlock (&mtx);
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
set_led (u&v);
|
|
||||||
chopstx_usec_wait (m);
|
|
||||||
set_led (0);
|
|
||||||
chopstx_usec_wait (100-m);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *
|
|
||||||
blk (void *arg)
|
|
||||||
{
|
|
||||||
(void)arg;
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&mtx);
|
|
||||||
chopstx_cond_wait (&cnd1, &mtx);
|
|
||||||
chopstx_mutex_unlock (&mtx);
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
v = 0;
|
|
||||||
chopstx_usec_wait (200*1000);
|
|
||||||
v = 1;
|
|
||||||
chopstx_usec_wait (200*1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define PRIO_PWM 3
|
|
||||||
#define PRIO_BLK 2
|
|
||||||
|
|
||||||
#define STACK_MAIN
|
|
||||||
#define STACK_PROCESS_1
|
|
||||||
#define STACK_PROCESS_2
|
|
||||||
#include "stack-def.h"
|
|
||||||
#define STACK_ADDR_PWM ((uint32_t)process1_base)
|
|
||||||
#define STACK_SIZE_PWM (sizeof process1_base)
|
|
||||||
#define STACK_ADDR_BLK ((uint32_t)process2_base)
|
|
||||||
#define STACK_SIZE_BLK (sizeof process2_base)
|
|
||||||
|
|
||||||
|
|
||||||
static char hexchar (uint8_t x)
|
|
||||||
{
|
|
||||||
x &= 0x0f;
|
|
||||||
if (x <= 0x09)
|
|
||||||
return '0' + x;
|
|
||||||
else if (x <= 0x0f)
|
|
||||||
return 'a' + x - 10;
|
|
||||||
else
|
|
||||||
return '?';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
main (int argc, const char *argv[])
|
|
||||||
{
|
|
||||||
struct tty *tty;
|
|
||||||
uint8_t count;
|
|
||||||
|
|
||||||
(void)argc;
|
|
||||||
(void)argv;
|
|
||||||
|
|
||||||
chopstx_mutex_init (&mtx);
|
|
||||||
chopstx_cond_init (&cnd0);
|
|
||||||
chopstx_cond_init (&cnd1);
|
|
||||||
|
|
||||||
m = 10;
|
|
||||||
|
|
||||||
chopstx_create (PRIO_PWM, STACK_ADDR_PWM, STACK_SIZE_PWM, pwm, NULL);
|
|
||||||
chopstx_create (PRIO_BLK, STACK_ADDR_BLK, STACK_SIZE_BLK, blk, NULL);
|
|
||||||
|
|
||||||
chopstx_usec_wait (200*1000);
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&mtx);
|
|
||||||
chopstx_cond_signal (&cnd0);
|
|
||||||
chopstx_cond_signal (&cnd1);
|
|
||||||
chopstx_mutex_unlock (&mtx);
|
|
||||||
|
|
||||||
u = 1;
|
|
||||||
|
|
||||||
tty = tty_open ();
|
|
||||||
tty_wait_configured (tty);
|
|
||||||
|
|
||||||
count = 0;
|
|
||||||
m = 50;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
char s[LINEBUFSIZE];
|
|
||||||
|
|
||||||
u = 1;
|
|
||||||
tty_wait_connection (tty);
|
|
||||||
|
|
||||||
chopstx_usec_wait (50*1000);
|
|
||||||
|
|
||||||
/* Send ZLP at the beginning. */
|
|
||||||
tty_send (tty, s, 0);
|
|
||||||
|
|
||||||
memcpy (s, "xx: Hello, World with Chopstx!\r\n", 32);
|
|
||||||
s[0] = hexchar (count >> 4);
|
|
||||||
s[1] = hexchar (count & 0x0f);
|
|
||||||
count++;
|
|
||||||
|
|
||||||
if (tty_send (tty, s, 32) < 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
int size;
|
|
||||||
uint32_t usec;
|
|
||||||
|
|
||||||
usec = 3000000; /* 3.0 seconds */
|
|
||||||
size = tty_recv (tty, s + 4, &usec);
|
|
||||||
if (size < 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (size)
|
|
||||||
{
|
|
||||||
size--;
|
|
||||||
|
|
||||||
s[0] = hexchar (size >> 4);
|
|
||||||
s[1] = hexchar (size & 0x0f);
|
|
||||||
s[2] = ':';
|
|
||||||
s[3] = ' ';
|
|
||||||
s[size + 4] = '\r';
|
|
||||||
s[size + 5] = '\n';
|
|
||||||
if (tty_send (tty, s, size + 6) < 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
u ^= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,124 +0,0 @@
|
|||||||
/*
|
|
||||||
* ST32F103 memory setup.
|
|
||||||
*/
|
|
||||||
|
|
||||||
MEMORY
|
|
||||||
{
|
|
||||||
flash0 : org = 0x08000000, len = 4k
|
|
||||||
flash : org = 0x08000000+0x1000, len = 60k
|
|
||||||
ram : org = 0x20000000, len = 20k
|
|
||||||
}
|
|
||||||
|
|
||||||
__ram_start__ = ORIGIN(ram);
|
|
||||||
__ram_size__ = 20k;
|
|
||||||
__ram_end__ = __ram_start__ + __ram_size__;
|
|
||||||
|
|
||||||
SECTIONS
|
|
||||||
{
|
|
||||||
. = 0;
|
|
||||||
|
|
||||||
.sys : ALIGN(4) SUBALIGN(4)
|
|
||||||
{
|
|
||||||
_sys = .;
|
|
||||||
KEEP(*(.vectors))
|
|
||||||
. = ALIGN(16);
|
|
||||||
KEEP(*(.sys.version))
|
|
||||||
KEEP(*(.sys.board_id))
|
|
||||||
KEEP(*(.sys.board_name))
|
|
||||||
build/sys-*.o(.text)
|
|
||||||
build/sys-*.o(.text.*)
|
|
||||||
build/sys-*.o(.rodata)
|
|
||||||
build/sys-*.o(.rodata.*)
|
|
||||||
. = ALIGN(1024);
|
|
||||||
*(.sys.0)
|
|
||||||
*(.sys.1)
|
|
||||||
*(.sys.2)
|
|
||||||
} > flash0
|
|
||||||
|
|
||||||
_text = .;
|
|
||||||
|
|
||||||
.startup : ALIGN(128) SUBALIGN(128)
|
|
||||||
{
|
|
||||||
KEEP(*(.startup.vectors))
|
|
||||||
. = ALIGN (16);
|
|
||||||
} > flash =0xffffffff
|
|
||||||
|
|
||||||
.text : ALIGN(16) SUBALIGN(16)
|
|
||||||
{
|
|
||||||
*(.text.startup.*)
|
|
||||||
*(.text)
|
|
||||||
*(.text.*)
|
|
||||||
*(.rodata)
|
|
||||||
*(.rodata.*)
|
|
||||||
*(.glue_7t)
|
|
||||||
*(.glue_7)
|
|
||||||
*(.gcc*)
|
|
||||||
. = ALIGN(8);
|
|
||||||
} > flash
|
|
||||||
|
|
||||||
.ARM.extab : {*(.ARM.extab* .gnu.linkonce.armextab.*)} > flash
|
|
||||||
|
|
||||||
.ARM.exidx : {
|
|
||||||
PROVIDE(__exidx_start = .);
|
|
||||||
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
|
||||||
PROVIDE(__exidx_end = .);
|
|
||||||
} > flash
|
|
||||||
|
|
||||||
.eh_frame_hdr : {*(.eh_frame_hdr)} > flash
|
|
||||||
|
|
||||||
.eh_frame : ONLY_IF_RO {*(.eh_frame)} > flash
|
|
||||||
|
|
||||||
.textalign : ONLY_IF_RO { . = ALIGN(8); } > flash
|
|
||||||
|
|
||||||
_etext = .;
|
|
||||||
_textdata = _etext;
|
|
||||||
|
|
||||||
.process_stack (NOLOAD) :
|
|
||||||
{
|
|
||||||
. = ALIGN(8);
|
|
||||||
*(.process_stack.3)
|
|
||||||
*(.process_stack.2)
|
|
||||||
*(.process_stack.1)
|
|
||||||
*(.process_stack.0)
|
|
||||||
. = ALIGN(8);
|
|
||||||
} > ram
|
|
||||||
|
|
||||||
.main_stack (NOLOAD) :
|
|
||||||
{
|
|
||||||
. = ALIGN(8);
|
|
||||||
*(.main_stack)
|
|
||||||
. = ALIGN(8);
|
|
||||||
} > ram
|
|
||||||
|
|
||||||
.data :
|
|
||||||
{
|
|
||||||
. = ALIGN(4);
|
|
||||||
PROVIDE(_data = .);
|
|
||||||
*(.data)
|
|
||||||
. = ALIGN(4);
|
|
||||||
*(.data.*)
|
|
||||||
. = ALIGN(4);
|
|
||||||
*(.ramtext)
|
|
||||||
. = ALIGN(4);
|
|
||||||
PROVIDE(_edata = .);
|
|
||||||
} > ram AT > flash
|
|
||||||
|
|
||||||
.bss :
|
|
||||||
{
|
|
||||||
. = ALIGN(4);
|
|
||||||
PROVIDE(_bss_start = .);
|
|
||||||
*(.bss)
|
|
||||||
. = ALIGN(4);
|
|
||||||
*(.bss.*)
|
|
||||||
. = ALIGN(4);
|
|
||||||
*(COMMON)
|
|
||||||
. = ALIGN(4);
|
|
||||||
PROVIDE(_bss_end = .);
|
|
||||||
} > ram
|
|
||||||
|
|
||||||
PROVIDE(end = .);
|
|
||||||
_end = .;
|
|
||||||
}
|
|
||||||
|
|
||||||
__heap_base__ = _end;
|
|
||||||
__heap_end__ = __ram_end__;
|
|
@ -1,24 +0,0 @@
|
|||||||
#if defined(STACK_MAIN)
|
|
||||||
/* Idle+Exception handlers */
|
|
||||||
char __main_stack_end__[0] __attribute__ ((section(".main_stack")));
|
|
||||||
char main_base[0x0100] __attribute__ ((section(".main_stack")));
|
|
||||||
|
|
||||||
/* Main program */
|
|
||||||
char __process0_stack_end__[0] __attribute__ ((section(".process_stack.0")));
|
|
||||||
char process0_base[0x0400] __attribute__ ((section(".process_stack.0")));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* First thread program */
|
|
||||||
#if defined(STACK_PROCESS_1)
|
|
||||||
char process1_base[0x0200] __attribute__ ((section(".process_stack.1")));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Second thread program */
|
|
||||||
#if defined(STACK_PROCESS_2)
|
|
||||||
char process2_base[0x0200] __attribute__ ((section(".process_stack.2")));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Third thread program */
|
|
||||||
#if defined(STACK_PROCESS_3)
|
|
||||||
char process3_base[0x0200] __attribute__ ((section(".process_stack.3")));
|
|
||||||
#endif
|
|
@ -1,9 +0,0 @@
|
|||||||
#define LINEBUFSIZE 128
|
|
||||||
|
|
||||||
struct tty;
|
|
||||||
|
|
||||||
struct tty *tty_open (void);
|
|
||||||
void tty_wait_configured (struct tty *tty);
|
|
||||||
void tty_wait_connection (struct tty *tty);
|
|
||||||
int tty_send (struct tty *tty, const char *buf, int count);
|
|
||||||
int tty_recv (struct tty *tty, char *buf, uint32_t *timeout);
|
|
@ -1,959 +0,0 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <chopstx.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "usb_lld.h"
|
|
||||||
#include "tty.h"
|
|
||||||
|
|
||||||
static chopstx_intr_t usb_intr;
|
|
||||||
|
|
||||||
struct line_coding
|
|
||||||
{
|
|
||||||
uint32_t bitrate;
|
|
||||||
uint8_t format;
|
|
||||||
uint8_t paritytype;
|
|
||||||
uint8_t datatype;
|
|
||||||
} __attribute__((packed));
|
|
||||||
|
|
||||||
static const struct line_coding line_coding0 = {
|
|
||||||
115200, /* baud rate: 115200 */
|
|
||||||
0x00, /* stop bits: 1 */
|
|
||||||
0x00, /* parity: none */
|
|
||||||
0x08 /* bits: 8 */
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Currently, we only support a single TTY.
|
|
||||||
*
|
|
||||||
* It is possible to extend to support multiple TTYs, for multiple
|
|
||||||
* interfaces.
|
|
||||||
*
|
|
||||||
* In that case, add argument to TTY_OPEN function and
|
|
||||||
* modify TTY_GET function to get the TTY structure. Functions which
|
|
||||||
* directy accesses TTY0 (usb_device_reset and usb_set_configuration)
|
|
||||||
* should be modified, too.
|
|
||||||
*
|
|
||||||
* Modification of TTY_MAIN thread will be also needed to echo back
|
|
||||||
* input for each TTY, and the thread should run if one of TTY is
|
|
||||||
* opened.
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct tty {
|
|
||||||
chopstx_mutex_t mtx;
|
|
||||||
chopstx_cond_t cnd;
|
|
||||||
uint8_t inputline[LINEBUFSIZE]; /* Line editing is supported */
|
|
||||||
uint8_t send_buf[LINEBUFSIZE]; /* Sending ring buffer for echo back */
|
|
||||||
uint32_t inputline_len : 8;
|
|
||||||
uint32_t send_head : 8;
|
|
||||||
uint32_t send_tail : 8;
|
|
||||||
uint32_t flag_connected : 1;
|
|
||||||
uint32_t flag_send_ready : 1;
|
|
||||||
uint32_t flag_input_avail : 1;
|
|
||||||
uint32_t : 2;
|
|
||||||
uint32_t device_state : 3; /* USB device status */
|
|
||||||
struct line_coding line_coding;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct tty tty0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Locate TTY structure from interface number or endpoint number.
|
|
||||||
* Currently, it always returns tty0, because we only have the one.
|
|
||||||
*/
|
|
||||||
static struct tty *
|
|
||||||
tty_get (int interface, uint8_t ep_num)
|
|
||||||
{
|
|
||||||
struct tty *t = &tty0;
|
|
||||||
|
|
||||||
if (interface >= 0)
|
|
||||||
{
|
|
||||||
if (interface == 0)
|
|
||||||
t = &tty0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (ep_num == ENDP1 || ep_num == ENDP2 || ep_num == ENDP3)
|
|
||||||
t = &tty0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define ENDP0_RXADDR (0x40)
|
|
||||||
#define ENDP0_TXADDR (0x80)
|
|
||||||
#define ENDP1_TXADDR (0xc0)
|
|
||||||
#define ENDP2_TXADDR (0x100)
|
|
||||||
#define ENDP3_RXADDR (0x140)
|
|
||||||
|
|
||||||
#define USB_CDC_REQ_SET_LINE_CODING 0x20
|
|
||||||
#define USB_CDC_REQ_GET_LINE_CODING 0x21
|
|
||||||
#define USB_CDC_REQ_SET_CONTROL_LINE_STATE 0x22
|
|
||||||
#define USB_CDC_REQ_SEND_BREAK 0x23
|
|
||||||
|
|
||||||
/* USB Device Descriptor */
|
|
||||||
static const uint8_t vcom_device_desc[18] = {
|
|
||||||
18, /* bLength */
|
|
||||||
DEVICE_DESCRIPTOR, /* bDescriptorType */
|
|
||||||
0x10, 0x01, /* bcdUSB = 1.1 */
|
|
||||||
0x02, /* bDeviceClass (CDC). */
|
|
||||||
0x00, /* bDeviceSubClass. */
|
|
||||||
0x00, /* bDeviceProtocol. */
|
|
||||||
0x40, /* bMaxPacketSize. */
|
|
||||||
0xFF, 0xFF, /* idVendor */
|
|
||||||
0x01, 0x00, /* idProduct */
|
|
||||||
0x00, 0x01, /* bcdDevice */
|
|
||||||
1, /* iManufacturer. */
|
|
||||||
2, /* iProduct. */
|
|
||||||
3, /* iSerialNumber. */
|
|
||||||
1 /* bNumConfigurations. */
|
|
||||||
};
|
|
||||||
|
|
||||||
#define VCOM_FEATURE_BUS_POWERED 0x80
|
|
||||||
|
|
||||||
/* Configuration Descriptor tree for a CDC.*/
|
|
||||||
static const uint8_t vcom_config_desc[67] = {
|
|
||||||
9,
|
|
||||||
CONFIG_DESCRIPTOR, /* bDescriptorType: Configuration */
|
|
||||||
/* Configuration Descriptor.*/
|
|
||||||
67, 0x00, /* wTotalLength. */
|
|
||||||
0x02, /* bNumInterfaces. */
|
|
||||||
0x01, /* bConfigurationValue. */
|
|
||||||
0, /* iConfiguration. */
|
|
||||||
VCOM_FEATURE_BUS_POWERED, /* bmAttributes. */
|
|
||||||
50, /* bMaxPower (100mA). */
|
|
||||||
/* Interface Descriptor.*/
|
|
||||||
9,
|
|
||||||
INTERFACE_DESCRIPTOR,
|
|
||||||
0x00, /* bInterfaceNumber. */
|
|
||||||
0x00, /* bAlternateSetting. */
|
|
||||||
0x01, /* bNumEndpoints. */
|
|
||||||
0x02, /* bInterfaceClass (Communications Interface Class,
|
|
||||||
CDC section 4.2). */
|
|
||||||
0x02, /* bInterfaceSubClass (Abstract Control Model, CDC
|
|
||||||
section 4.3). */
|
|
||||||
0x01, /* bInterfaceProtocol (AT commands, CDC section
|
|
||||||
4.4). */
|
|
||||||
0, /* iInterface. */
|
|
||||||
/* Header Functional Descriptor (CDC section 5.2.3).*/
|
|
||||||
5, /* bLength. */
|
|
||||||
0x24, /* bDescriptorType (CS_INTERFACE). */
|
|
||||||
0x00, /* bDescriptorSubtype (Header Functional Descriptor). */
|
|
||||||
0x10, 0x01, /* bcdCDC. */
|
|
||||||
/* Call Management Functional Descriptor. */
|
|
||||||
5, /* bFunctionLength. */
|
|
||||||
0x24, /* bDescriptorType (CS_INTERFACE). */
|
|
||||||
0x01, /* bDescriptorSubtype (Call Management Functional
|
|
||||||
Descriptor). */
|
|
||||||
0x03, /* bmCapabilities (D0+D1). */
|
|
||||||
0x01, /* bDataInterface. */
|
|
||||||
/* ACM Functional Descriptor.*/
|
|
||||||
4, /* bFunctionLength. */
|
|
||||||
0x24, /* bDescriptorType (CS_INTERFACE). */
|
|
||||||
0x02, /* bDescriptorSubtype (Abstract Control Management
|
|
||||||
Descriptor). */
|
|
||||||
0x02, /* bmCapabilities. */
|
|
||||||
/* Union Functional Descriptor.*/
|
|
||||||
5, /* bFunctionLength. */
|
|
||||||
0x24, /* bDescriptorType (CS_INTERFACE). */
|
|
||||||
0x06, /* bDescriptorSubtype (Union Functional
|
|
||||||
Descriptor). */
|
|
||||||
0x00, /* bMasterInterface (Communication Class
|
|
||||||
Interface). */
|
|
||||||
0x01, /* bSlaveInterface0 (Data Class Interface). */
|
|
||||||
/* Endpoint 2 Descriptor.*/
|
|
||||||
7,
|
|
||||||
ENDPOINT_DESCRIPTOR,
|
|
||||||
ENDP2|0x80, /* bEndpointAddress. */
|
|
||||||
0x03, /* bmAttributes (Interrupt). */
|
|
||||||
0x08, 0x00, /* wMaxPacketSize. */
|
|
||||||
0xFF, /* bInterval. */
|
|
||||||
/* Interface Descriptor.*/
|
|
||||||
9,
|
|
||||||
INTERFACE_DESCRIPTOR, /* bDescriptorType: */
|
|
||||||
0x01, /* bInterfaceNumber. */
|
|
||||||
0x00, /* bAlternateSetting. */
|
|
||||||
0x02, /* bNumEndpoints. */
|
|
||||||
0x0A, /* bInterfaceClass (Data Class Interface, CDC section 4.5). */
|
|
||||||
0x00, /* bInterfaceSubClass (CDC section 4.6). */
|
|
||||||
0x00, /* bInterfaceProtocol (CDC section 4.7). */
|
|
||||||
0x00, /* iInterface. */
|
|
||||||
/* Endpoint 3 Descriptor.*/
|
|
||||||
7,
|
|
||||||
ENDPOINT_DESCRIPTOR, /* bDescriptorType: Endpoint */
|
|
||||||
ENDP3, /* bEndpointAddress. */
|
|
||||||
0x02, /* bmAttributes (Bulk). */
|
|
||||||
0x40, 0x00, /* wMaxPacketSize. */
|
|
||||||
0x00, /* bInterval. */
|
|
||||||
/* Endpoint 1 Descriptor.*/
|
|
||||||
7,
|
|
||||||
ENDPOINT_DESCRIPTOR, /* bDescriptorType: Endpoint */
|
|
||||||
ENDP1|0x80, /* bEndpointAddress. */
|
|
||||||
0x02, /* bmAttributes (Bulk). */
|
|
||||||
0x40, 0x00, /* wMaxPacketSize. */
|
|
||||||
0x00 /* bInterval. */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* U.S. English language identifier.
|
|
||||||
*/
|
|
||||||
static const uint8_t vcom_string0[4] = {
|
|
||||||
4, /* bLength */
|
|
||||||
STRING_DESCRIPTOR,
|
|
||||||
0x09, 0x04 /* LangID = 0x0409: US-English */
|
|
||||||
};
|
|
||||||
|
|
||||||
static const uint8_t vcom_string1[] = {
|
|
||||||
23*2+2, /* bLength */
|
|
||||||
STRING_DESCRIPTOR, /* bDescriptorType */
|
|
||||||
/* Manufacturer: "Flying Stone Technology" */
|
|
||||||
'F', 0, 'l', 0, 'y', 0, 'i', 0, 'n', 0, 'g', 0, ' ', 0, 'S', 0,
|
|
||||||
't', 0, 'o', 0, 'n', 0, 'e', 0, ' ', 0, 'T', 0, 'e', 0, 'c', 0,
|
|
||||||
'h', 0, 'n', 0, 'o', 0, 'l', 0, 'o', 0, 'g', 0, 'y', 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
static const uint8_t vcom_string2[] = {
|
|
||||||
14*2+2, /* bLength */
|
|
||||||
STRING_DESCRIPTOR, /* bDescriptorType */
|
|
||||||
/* Product name: "Chopstx Sample" */
|
|
||||||
'C', 0, 'h', 0, 'o', 0, 'p', 0, 's', 0, 't', 0, 'x', 0, ' ', 0,
|
|
||||||
'S', 0, 'a', 0, 'm', 0, 'p', 0, 'l', 0, 'e', 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Serial Number string.
|
|
||||||
*/
|
|
||||||
static const uint8_t vcom_string3[28] = {
|
|
||||||
28, /* bLength */
|
|
||||||
STRING_DESCRIPTOR, /* bDescriptorType */
|
|
||||||
'0', 0, '.', 0, '0', 0, '0', 0, /* Version number */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#define NUM_INTERFACES 2
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
usb_device_reset (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
usb_lld_reset (dev, VCOM_FEATURE_BUS_POWERED);
|
|
||||||
|
|
||||||
/* Initialize Endpoint 0 */
|
|
||||||
usb_lld_setup_endpoint (ENDP0, EP_CONTROL, 0, ENDP0_RXADDR, ENDP0_TXADDR, 64);
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&tty0.mtx);
|
|
||||||
tty0.inputline_len = 0;
|
|
||||||
tty0.send_head = tty0.send_tail = 0;
|
|
||||||
tty0.flag_connected = 0;
|
|
||||||
tty0.flag_send_ready = 1;
|
|
||||||
tty0.flag_input_avail = 0;
|
|
||||||
tty0.device_state = USB_DEVICE_STATE_ATTACHED;
|
|
||||||
memcpy (&tty0.line_coding, &line_coding0, sizeof (struct line_coding));
|
|
||||||
chopstx_mutex_unlock (&tty0.mtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define CDC_CTRL_DTR 0x0001
|
|
||||||
|
|
||||||
static void
|
|
||||||
usb_ctrl_write_finish (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
struct device_req *arg = &dev->dev_req;
|
|
||||||
uint8_t type_rcp = arg->type & (REQUEST_TYPE|RECIPIENT);
|
|
||||||
|
|
||||||
if (type_rcp == (CLASS_REQUEST | INTERFACE_RECIPIENT) && arg->index == 0
|
|
||||||
&& USB_SETUP_SET (arg->type)
|
|
||||||
&& arg->request == USB_CDC_REQ_SET_CONTROL_LINE_STATE)
|
|
||||||
{
|
|
||||||
struct tty *t = tty_get (arg->index, 0);
|
|
||||||
|
|
||||||
/* Open/close the connection. */
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
t->flag_connected = ((arg->value & CDC_CTRL_DTR) != 0);
|
|
||||||
chopstx_cond_signal (&t->cnd);
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The transaction was already finished. So, it is no use to call
|
|
||||||
* usb_lld_ctrl_error when the condition does not match.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
vcom_port_data_setup (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
struct device_req *arg = &dev->dev_req;
|
|
||||||
|
|
||||||
if (USB_SETUP_GET (arg->type))
|
|
||||||
{
|
|
||||||
struct tty *t = tty_get (arg->index, 0);
|
|
||||||
|
|
||||||
if (arg->request == USB_CDC_REQ_GET_LINE_CODING)
|
|
||||||
return usb_lld_ctrl_send (dev, &t->line_coding,
|
|
||||||
sizeof (struct line_coding));
|
|
||||||
}
|
|
||||||
else /* USB_SETUP_SET (req) */
|
|
||||||
{
|
|
||||||
if (arg->request == USB_CDC_REQ_SET_LINE_CODING
|
|
||||||
&& arg->len == sizeof (struct line_coding))
|
|
||||||
{
|
|
||||||
struct tty *t = tty_get (arg->index, 0);
|
|
||||||
|
|
||||||
return usb_lld_ctrl_recv (dev, &t->line_coding,
|
|
||||||
sizeof (struct line_coding));
|
|
||||||
}
|
|
||||||
else if (arg->request == USB_CDC_REQ_SET_CONTROL_LINE_STATE)
|
|
||||||
return usb_lld_ctrl_ack (dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
usb_setup (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
struct device_req *arg = &dev->dev_req;
|
|
||||||
uint8_t type_rcp = arg->type & (REQUEST_TYPE|RECIPIENT);
|
|
||||||
|
|
||||||
if (type_rcp == (CLASS_REQUEST | INTERFACE_RECIPIENT) && arg->index == 0)
|
|
||||||
return vcom_port_data_setup (dev);
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
usb_get_descriptor (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
struct device_req *arg = &dev->dev_req;
|
|
||||||
uint8_t rcp = arg->type & RECIPIENT;
|
|
||||||
uint8_t desc_type = (arg->value >> 8);
|
|
||||||
uint8_t desc_index = (arg->value & 0xff);
|
|
||||||
|
|
||||||
if (rcp != DEVICE_RECIPIENT)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (desc_type == DEVICE_DESCRIPTOR)
|
|
||||||
return usb_lld_ctrl_send (dev,
|
|
||||||
vcom_device_desc, sizeof (vcom_device_desc));
|
|
||||||
else if (desc_type == CONFIG_DESCRIPTOR)
|
|
||||||
return usb_lld_ctrl_send (dev,
|
|
||||||
vcom_config_desc, sizeof (vcom_config_desc));
|
|
||||||
else if (desc_type == STRING_DESCRIPTOR)
|
|
||||||
{
|
|
||||||
const uint8_t *str;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
switch (desc_index)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
str = vcom_string0;
|
|
||||||
size = sizeof (vcom_string0);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
str = vcom_string1;
|
|
||||||
size = sizeof (vcom_string1);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
str = vcom_string2;
|
|
||||||
size = sizeof (vcom_string2);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
str = vcom_string3;
|
|
||||||
size = sizeof (vcom_string3);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return usb_lld_ctrl_send (dev, str, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
vcom_setup_endpoints_for_interface (uint16_t interface, int stop)
|
|
||||||
{
|
|
||||||
if (interface == 0)
|
|
||||||
{
|
|
||||||
if (!stop)
|
|
||||||
usb_lld_setup_endpoint (ENDP2, EP_INTERRUPT, 0, 0, ENDP2_TXADDR, 0);
|
|
||||||
else
|
|
||||||
usb_lld_stall_tx (ENDP2);
|
|
||||||
}
|
|
||||||
else if (interface == 1)
|
|
||||||
{
|
|
||||||
if (!stop)
|
|
||||||
{
|
|
||||||
usb_lld_setup_endpoint (ENDP1, EP_BULK, 0, 0, ENDP1_TXADDR, 0);
|
|
||||||
usb_lld_setup_endpoint (ENDP3, EP_BULK, 0, ENDP3_RXADDR, 0, 64);
|
|
||||||
/* Start with no data receiving (ENDP3 not enabled)*/
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
usb_lld_stall_tx (ENDP1);
|
|
||||||
usb_lld_stall_rx (ENDP3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
usb_set_configuration (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
uint8_t current_conf;
|
|
||||||
|
|
||||||
current_conf = usb_lld_current_configuration (dev);
|
|
||||||
if (current_conf == 0)
|
|
||||||
{
|
|
||||||
if (dev->dev_req.value != 1)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
usb_lld_set_configuration (dev, 1);
|
|
||||||
for (i = 0; i < NUM_INTERFACES; i++)
|
|
||||||
vcom_setup_endpoints_for_interface (i, 0);
|
|
||||||
chopstx_mutex_lock (&tty0.mtx);
|
|
||||||
tty0.device_state = USB_DEVICE_STATE_CONFIGURED;
|
|
||||||
chopstx_cond_signal (&tty0.cnd);
|
|
||||||
chopstx_mutex_unlock (&tty0.mtx);
|
|
||||||
}
|
|
||||||
else if (current_conf != dev->dev_req.value)
|
|
||||||
{
|
|
||||||
if (dev->dev_req.value != 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
usb_lld_set_configuration (dev, 0);
|
|
||||||
for (i = 0; i < NUM_INTERFACES; i++)
|
|
||||||
vcom_setup_endpoints_for_interface (i, 1);
|
|
||||||
chopstx_mutex_lock (&tty0.mtx);
|
|
||||||
tty0.device_state = USB_DEVICE_STATE_ADDRESSED;
|
|
||||||
chopstx_cond_signal (&tty0.cnd);
|
|
||||||
chopstx_mutex_unlock (&tty0.mtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
usb_lld_ctrl_ack (dev);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
usb_set_interface (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
uint16_t interface = dev->dev_req.index;
|
|
||||||
uint16_t alt = dev->dev_req.value;
|
|
||||||
|
|
||||||
if (interface >= NUM_INTERFACES)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (alt != 0)
|
|
||||||
return -1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vcom_setup_endpoints_for_interface (interface, 0);
|
|
||||||
usb_lld_ctrl_ack (dev);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
usb_get_interface (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
const uint8_t zero = 0;
|
|
||||||
uint16_t interface = dev->dev_req.index;
|
|
||||||
|
|
||||||
if (interface >= NUM_INTERFACES)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/* We don't have alternate interface, so, always return 0. */
|
|
||||||
return usb_lld_ctrl_send (dev, &zero, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
usb_get_status_interface (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
const uint16_t status_info = 0;
|
|
||||||
uint16_t interface = dev->dev_req.index;
|
|
||||||
|
|
||||||
if (interface >= NUM_INTERFACES)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return usb_lld_ctrl_send (dev, &status_info, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Put a character into the ring buffer to be send back.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
put_char_to_ringbuffer (struct tty *t, int c)
|
|
||||||
{
|
|
||||||
uint32_t next = (t->send_tail + 1) % LINEBUFSIZE;
|
|
||||||
|
|
||||||
if (t->send_head == next)
|
|
||||||
/* full */
|
|
||||||
/* All that we can do is ignore this char. */
|
|
||||||
return;
|
|
||||||
|
|
||||||
t->send_buf[t->send_tail] = c;
|
|
||||||
t->send_tail = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get characters from ring buffer into S.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
get_chars_from_ringbuffer (struct tty *t, uint8_t *s, int len)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
if (t->send_head == t->send_tail)
|
|
||||||
/* Empty */
|
|
||||||
return i;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
s[i++] = t->send_buf[t->send_head];
|
|
||||||
t->send_head = (t->send_head + 1) % LINEBUFSIZE;
|
|
||||||
}
|
|
||||||
while (t->send_head != t->send_tail && i < len);
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
tty_echo_char (struct tty *t, int c)
|
|
||||||
{
|
|
||||||
put_char_to_ringbuffer (t, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
usb_tx_done (uint8_t ep_num, uint16_t len)
|
|
||||||
{
|
|
||||||
struct tty *t = tty_get (-1, ep_num);
|
|
||||||
|
|
||||||
(void)len;
|
|
||||||
|
|
||||||
if (ep_num == ENDP1)
|
|
||||||
{
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
if (t->flag_send_ready == 0)
|
|
||||||
{
|
|
||||||
t->flag_send_ready = 1;
|
|
||||||
chopstx_cond_signal (&t->cnd);
|
|
||||||
}
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
}
|
|
||||||
else if (ep_num == ENDP2)
|
|
||||||
{
|
|
||||||
/* Nothing */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
tty_input_char (struct tty *t, int c)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
int r = 0;
|
|
||||||
|
|
||||||
/* Process DEL, C-U, C-R, and RET as editing command. */
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case 0x0d: /* Control-M */
|
|
||||||
t->inputline[t->inputline_len++] = '\n';
|
|
||||||
tty_echo_char (t, 0x0d);
|
|
||||||
tty_echo_char (t, 0x0a);
|
|
||||||
t->flag_input_avail = 1;
|
|
||||||
r = 1;
|
|
||||||
chopstx_cond_signal (&t->cnd);
|
|
||||||
break;
|
|
||||||
case 0x12: /* Control-R */
|
|
||||||
tty_echo_char (t, '^');
|
|
||||||
tty_echo_char (t, 'R');
|
|
||||||
tty_echo_char (t, 0x0d);
|
|
||||||
tty_echo_char (t, 0x0a);
|
|
||||||
for (i = 0; i < t->inputline_len; i++)
|
|
||||||
tty_echo_char (t, t->inputline[i]);
|
|
||||||
break;
|
|
||||||
case 0x15: /* Control-U */
|
|
||||||
for (i = 0; i < t->inputline_len; i++)
|
|
||||||
{
|
|
||||||
tty_echo_char (t, 0x08);
|
|
||||||
tty_echo_char (t, 0x20);
|
|
||||||
tty_echo_char (t, 0x08);
|
|
||||||
}
|
|
||||||
t->inputline_len = 0;
|
|
||||||
break;
|
|
||||||
case 0x7f: /* DEL */
|
|
||||||
if (t->inputline_len > 0)
|
|
||||||
{
|
|
||||||
tty_echo_char (t, 0x08);
|
|
||||||
tty_echo_char (t, 0x20);
|
|
||||||
tty_echo_char (t, 0x08);
|
|
||||||
t->inputline_len--;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (t->inputline_len < sizeof (t->inputline) - 1)
|
|
||||||
{
|
|
||||||
tty_echo_char (t, c);
|
|
||||||
t->inputline[t->inputline_len++] = c;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
/* Beep */
|
|
||||||
tty_echo_char (t, 0x0a);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
usb_rx_ready (uint8_t ep_num, uint16_t len)
|
|
||||||
{
|
|
||||||
uint8_t recv_buf[64];
|
|
||||||
struct tty *t = tty_get (-1, ep_num);
|
|
||||||
|
|
||||||
if (ep_num == ENDP3)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
usb_lld_rxcpy (recv_buf, ep_num, 0, len);
|
|
||||||
for (i = 0; i < len; i++)
|
|
||||||
if (tty_input_char (t, recv_buf[i]))
|
|
||||||
break;
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
if (t->flag_input_avail == 0)
|
|
||||||
usb_lld_rx_enable (ENDP3);
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *tty_main (void *arg);
|
|
||||||
|
|
||||||
#define PRIO_TTY 4
|
|
||||||
|
|
||||||
#define STACK_PROCESS_3
|
|
||||||
#include "stack-def.h"
|
|
||||||
#define STACK_ADDR_TTY ((uint32_t)process3_base)
|
|
||||||
#define STACK_SIZE_TTY (sizeof process3_base)
|
|
||||||
|
|
||||||
struct tty *
|
|
||||||
tty_open (void)
|
|
||||||
{
|
|
||||||
chopstx_mutex_init (&tty0.mtx);
|
|
||||||
chopstx_cond_init (&tty0.cnd);
|
|
||||||
tty0.inputline_len = 0;
|
|
||||||
tty0.send_head = tty0.send_tail = 0;
|
|
||||||
tty0.flag_connected = 0;
|
|
||||||
tty0.flag_send_ready = 1;
|
|
||||||
tty0.flag_input_avail = 0;
|
|
||||||
tty0.device_state = USB_DEVICE_STATE_UNCONNECTED;
|
|
||||||
memcpy (&tty0.line_coding, &line_coding0, sizeof (struct line_coding));
|
|
||||||
|
|
||||||
chopstx_create (PRIO_TTY, STACK_ADDR_TTY, STACK_SIZE_TTY, tty_main, &tty0);
|
|
||||||
return &tty0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void *
|
|
||||||
tty_main (void *arg)
|
|
||||||
{
|
|
||||||
struct tty *t = arg;
|
|
||||||
struct usb_dev dev;
|
|
||||||
int e;
|
|
||||||
|
|
||||||
#if defined(OLDER_SYS_H)
|
|
||||||
/*
|
|
||||||
* Historically (before sys < 3.0), NVIC priority setting for USB
|
|
||||||
* interrupt was done in usb_lld_sys_init. Thus this code.
|
|
||||||
*
|
|
||||||
* When USB interrupt occurs between usb_lld_init (which assumes
|
|
||||||
* ISR) and chopstx_claim_irq (which clears pending interrupt),
|
|
||||||
* invocation of usb_lld_event_handler won't occur.
|
|
||||||
*
|
|
||||||
* Calling usb_lld_event_handler is no harm even if there were no
|
|
||||||
* interrupts, thus, we call it unconditionally here, just in case
|
|
||||||
* if there is a request.
|
|
||||||
*
|
|
||||||
* We can't call usb_lld_init after chopstx_claim_irq, as
|
|
||||||
* usb_lld_init does its own setting for NVIC. Calling
|
|
||||||
* chopstx_claim_irq after usb_lld_init overrides that.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
|
||||||
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
|
||||||
goto event_handle;
|
|
||||||
#else
|
|
||||||
chopstx_claim_irq (&usb_intr, INTR_REQ_USB);
|
|
||||||
usb_lld_init (&dev, VCOM_FEATURE_BUS_POWERED);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
chopstx_intr_wait (&usb_intr);
|
|
||||||
if (usb_intr.ready)
|
|
||||||
{
|
|
||||||
uint8_t ep_num;
|
|
||||||
#if defined(OLDER_SYS_H)
|
|
||||||
event_handle:
|
|
||||||
#endif
|
|
||||||
/*
|
|
||||||
* When interrupt is detected, call usb_lld_event_handler.
|
|
||||||
* The event may be one of following:
|
|
||||||
* (1) Transfer to endpoint (bulk or interrupt)
|
|
||||||
* In this case EP_NUM is encoded in the variable E.
|
|
||||||
* (2) "NONE" event: some trasfer was done, but all was
|
|
||||||
* done by lower layer, no other work is needed in
|
|
||||||
* upper layer.
|
|
||||||
* (3) Device events: Reset or Suspend
|
|
||||||
* (4) Device requests to the endpoint zero.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
e = usb_lld_event_handler (&dev);
|
|
||||||
chopstx_intr_done (&usb_intr);
|
|
||||||
ep_num = USB_EVENT_ENDP (e);
|
|
||||||
|
|
||||||
if (ep_num != 0)
|
|
||||||
{
|
|
||||||
if (USB_EVENT_TXRX (e))
|
|
||||||
usb_tx_done (ep_num, USB_EVENT_LEN (e));
|
|
||||||
else
|
|
||||||
usb_rx_ready (ep_num, USB_EVENT_LEN (e));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
switch (USB_EVENT_ID (e))
|
|
||||||
{
|
|
||||||
case USB_EVENT_DEVICE_RESET:
|
|
||||||
usb_device_reset (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_DEVICE_ADDRESSED:
|
|
||||||
/* The addres is assigned to the device. We don't
|
|
||||||
* need to do anything for this actually, but in this
|
|
||||||
* application, we maintain the USB status of the
|
|
||||||
* device. Usually, just "continue" as EVENT_OK is
|
|
||||||
* OK.
|
|
||||||
*/
|
|
||||||
chopstx_mutex_lock (&tty0.mtx);
|
|
||||||
tty0.device_state = USB_DEVICE_STATE_ADDRESSED;
|
|
||||||
chopstx_cond_signal (&tty0.cnd);
|
|
||||||
chopstx_mutex_unlock (&tty0.mtx);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_GET_DESCRIPTOR:
|
|
||||||
if (usb_get_descriptor (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_SET_CONFIGURATION:
|
|
||||||
if (usb_set_configuration (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_SET_INTERFACE:
|
|
||||||
if (usb_set_interface (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_CTRL_REQUEST:
|
|
||||||
/* Device specific device request. */
|
|
||||||
if (usb_setup (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_GET_STATUS_INTERFACE:
|
|
||||||
if (usb_get_status_interface (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_GET_INTERFACE:
|
|
||||||
if (usb_get_interface (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_SET_FEATURE_DEVICE:
|
|
||||||
case USB_EVENT_SET_FEATURE_ENDPOINT:
|
|
||||||
case USB_EVENT_CLEAR_FEATURE_DEVICE:
|
|
||||||
case USB_EVENT_CLEAR_FEATURE_ENDPOINT:
|
|
||||||
usb_lld_ctrl_ack (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_CTRL_WRITE_FINISH:
|
|
||||||
/* Control WRITE transfer finished. */
|
|
||||||
usb_ctrl_write_finish (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_OK:
|
|
||||||
case USB_EVENT_DEVICE_SUSPEND:
|
|
||||||
default:
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
if (t->device_state == USB_DEVICE_STATE_CONFIGURED && t->flag_connected
|
|
||||||
&& t->flag_send_ready)
|
|
||||||
{
|
|
||||||
uint8_t line[32];
|
|
||||||
int len = get_chars_from_ringbuffer (t, line, sizeof (len));
|
|
||||||
|
|
||||||
if (len)
|
|
||||||
{
|
|
||||||
usb_lld_txcpy (line, ENDP1, 0, len);
|
|
||||||
usb_lld_tx_enable (ENDP1, len);
|
|
||||||
t->flag_send_ready = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
tty_wait_configured (struct tty *t)
|
|
||||||
{
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
while (t->device_state != USB_DEVICE_STATE_CONFIGURED)
|
|
||||||
chopstx_cond_wait (&t->cnd, &t->mtx);
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
tty_wait_connection (struct tty *t)
|
|
||||||
{
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
while (t->flag_connected == 0)
|
|
||||||
chopstx_cond_wait (&t->cnd, &t->mtx);
|
|
||||||
t->flag_send_ready = 1;
|
|
||||||
t->flag_input_avail = 0;
|
|
||||||
t->send_head = t->send_tail = 0;
|
|
||||||
t->inputline_len = 0;
|
|
||||||
usb_lld_rx_enable (ENDP3); /* Accept input for line */
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
check_tx (struct tty *t)
|
|
||||||
{
|
|
||||||
if (t->flag_send_ready)
|
|
||||||
/* TX done */
|
|
||||||
return 1;
|
|
||||||
if (t->flag_connected == 0)
|
|
||||||
/* Disconnected */
|
|
||||||
return -1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
tty_send (struct tty *t, const char *buf, int len)
|
|
||||||
{
|
|
||||||
int r;
|
|
||||||
const char *p;
|
|
||||||
int count;
|
|
||||||
|
|
||||||
p = buf;
|
|
||||||
count = len >= 64 ? 64 : len;
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
while ((r = check_tx (t)) == 0)
|
|
||||||
chopstx_cond_wait (&t->cnd, &t->mtx);
|
|
||||||
if (r > 0)
|
|
||||||
{
|
|
||||||
usb_lld_txcpy (p, ENDP1, 0, count);
|
|
||||||
usb_lld_tx_enable (ENDP1, count);
|
|
||||||
t->flag_send_ready = 0;
|
|
||||||
}
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
|
|
||||||
len -= count;
|
|
||||||
p += count;
|
|
||||||
if (len == 0 && count != 64)
|
|
||||||
/*
|
|
||||||
* The size of the last packet should be != 0
|
|
||||||
* If 64, send ZLP (zelo length packet)
|
|
||||||
*/
|
|
||||||
break;
|
|
||||||
count = len >= 64 ? 64 : len;
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
check_rx (void *arg)
|
|
||||||
{
|
|
||||||
struct tty *t = arg;
|
|
||||||
|
|
||||||
if (t->flag_input_avail)
|
|
||||||
/* RX */
|
|
||||||
return 1;
|
|
||||||
if (t->flag_connected == 0)
|
|
||||||
/* Disconnected */
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns -1 on connection close
|
|
||||||
* 0 on timeout.
|
|
||||||
* >0 length of the inputline (including final \n)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
tty_recv (struct tty *t, char *buf, uint32_t *timeout)
|
|
||||||
{
|
|
||||||
int r;
|
|
||||||
chopstx_poll_cond_t poll_desc;
|
|
||||||
|
|
||||||
poll_desc.type = CHOPSTX_POLL_COND;
|
|
||||||
poll_desc.ready = 0;
|
|
||||||
poll_desc.cond = &t->cnd;
|
|
||||||
poll_desc.mutex = &t->mtx;
|
|
||||||
poll_desc.check = check_rx;
|
|
||||||
poll_desc.arg = t;
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
struct chx_poll_head *pd_array[1] = {
|
|
||||||
(struct chx_poll_head *)&poll_desc
|
|
||||||
};
|
|
||||||
chopstx_poll (timeout, 1, pd_array);
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
r = check_rx (t);
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
if (r || (timeout != NULL && *timeout == 0))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&t->mtx);
|
|
||||||
if (t->flag_connected == 0)
|
|
||||||
r = -1;
|
|
||||||
else if (t->flag_input_avail)
|
|
||||||
{
|
|
||||||
r = t->inputline_len;
|
|
||||||
memcpy (buf, t->inputline, r);
|
|
||||||
t->flag_input_avail = 0;
|
|
||||||
usb_lld_rx_enable (ENDP3);
|
|
||||||
t->inputline_len = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
r = 0;
|
|
||||||
chopstx_mutex_unlock (&t->mtx);
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
(0) configure and make
|
|
||||||
|
|
||||||
This example assumes that you have fraucheky source code
|
|
||||||
along with chopstx.
|
|
||||||
|
|
||||||
--- chopstx --- chostx --- example-fraucheky
|
|
||||||
|
|
|
||||||
\- fraucheky
|
|
||||||
|
|
||||||
|
|
||||||
If you use vendor id and product id of 234b:0004 under
|
|
||||||
the condition of FSIJ, you can configure this program as:
|
|
||||||
|
|
||||||
$ ./configure --vidpid=234b:0004
|
|
||||||
|
|
||||||
then, invoke make.
|
|
||||||
|
|
||||||
$ make
|
|
||||||
|
|
||||||
|
|
||||||
(1) preparation as root
|
|
||||||
|
|
||||||
Install USBIP host module
|
|
||||||
# modprobe vhci_hcd
|
|
||||||
|
|
||||||
|
|
||||||
(2) Run sample program of USBIP server
|
|
||||||
|
|
||||||
$ ./sample-msc
|
|
||||||
|
|
||||||
|
|
||||||
(3) Use the USB device as root
|
|
||||||
|
|
||||||
Attach the Chopstx application program (USBIP device) to USBIP host.
|
|
||||||
|
|
||||||
# usbip attach -r 127.0.0.1 -b 1-1
|
|
||||||
|
|
||||||
|
|
||||||
(4) Use the USB Mass Storage Class device
|
|
||||||
|
|
||||||
You can mount the storage.
|
|
||||||
|
|
||||||
Unmounting the storage, the program will exit.
|
|
@ -1,62 +0,0 @@
|
|||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
||||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
||||||
<head><title>How to use this device</title>
|
|
||||||
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<h1>How to use this device</h1>
|
|
||||||
<h2>Introduction</h2>
|
|
||||||
<p>This is an example program for GNU/Linux to see how
|
|
||||||
Chopstx works with USB emulation by USBIP.</p>
|
|
||||||
<p>Now, you are accessing this file.
|
|
||||||
It means that the device is running as USB memory
|
|
||||||
(USB Mass Storage Class device).</p>
|
|
||||||
|
|
||||||
<h2>README, GNU GPL and Corresponding Source code</h2>
|
|
||||||
<p>In this program, it contains copyrighted software that is licensed under
|
|
||||||
the GPLv3. Please see README for the explanation of the software and see
|
|
||||||
GNU GPLv3 for terms and conditions.</p>
|
|
||||||
<p>You may obtain the complete Corresponding Source code from git repositories.
|
|
||||||
This program uses Chopstx for RTOS, and Fraucheky for
|
|
||||||
GPL container. Those code are availabe in the Chopstx repository.</p>
|
|
||||||
<p>You can also download tarballs from the repository.</p>
|
|
||||||
<ul>
|
|
||||||
<li><a href="README">README</a></li>
|
|
||||||
<li><a href="COPYING">GNU GPLv3</a></li>
|
|
||||||
<li><a href="https://anonscm.debian.org/cgit/gnuk/chopstx/">Chopstx Repository</a></li>
|
|
||||||
<li><a href="https://git.gniibe.org/gitweb/?p=chopstx/chopstx.git;a=snapshot;h=@REVISION_CHOPSTX@;sf=tgz">Chopstx tarball</a></li>
|
|
||||||
<li><a href="https://git.gniibe.org/gitweb/?p=chopstx/fraucheky.git;a=snapshot;h=@REVISION_FRAUCHEKY@;sf=tgz">Fraucheky tarball</a></li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<h3>Source code by physical media</h3>
|
|
||||||
<p>For those who want source code by physical media, Flying Stone Technology sells a microSD card (with SD card adapter) which contains all repositories at git.gniibe.org.</p>
|
|
||||||
<p>The price is JPY1000 for a single media including tax and shipment in Japan. Please use YUUBIN-FURIKAE account of Flying Stone Technology below. Note that the account name is in Japanese (which means: Flying Stone Technology).</p>
|
|
||||||
<p>On the form of YUUBIN-FURIKAE, you specify your address and you can write some message. The media will be sent to your address written in the form.</p>
|
|
||||||
<ul>
|
|
||||||
<li>Account No: 00110-2-346446</li>
|
|
||||||
<li>Account name: Tobiishi Gijutsu</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<p>If it is difficult for you to use YUUBIN-FURIKAE, please write to the following address.</p>
|
|
||||||
<ul>
|
|
||||||
<li>Niibe Yutaka</li>
|
|
||||||
<li>Flying Stone Technology</li>
|
|
||||||
<li>1-5-14 Iwagami, Maebashi</li>
|
|
||||||
<li>Gunma, 371-0031 JAPAN</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<p>This source code offer will be valid for three years after the shipment of this device or at least until 2021-03-31.</p>
|
|
||||||
|
|
||||||
<h2>Links</h2>
|
|
||||||
<ul>
|
|
||||||
<li><a href="https://www.gniibe.org/category/fst-01.html">
|
|
||||||
FST-01 support pages</a></li>
|
|
||||||
<li><a href="https://lists.alioth.debian.org/mailman/listinfo/gnuk-users">
|
|
||||||
Mailing list: Gnuk Users</a></li>
|
|
||||||
<li><a href="https://www.gnu.org/gnu/manifesto.ja.html">
|
|
||||||
GNU Manifesto (Japanese Translation)</a></li>
|
|
||||||
</ul>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,45 +0,0 @@
|
|||||||
# Makefile for NeuG
|
|
||||||
|
|
||||||
# Define project name here
|
|
||||||
PROJECT = sample-msc
|
|
||||||
|
|
||||||
CHOPSTX = ..
|
|
||||||
FRAUCHEKY = ../../fraucheky
|
|
||||||
LDSCRIPT=
|
|
||||||
|
|
||||||
CSRC = main.c
|
|
||||||
CHIP=gnu-linux
|
|
||||||
USE_SYS = yes
|
|
||||||
USE_USB = yes
|
|
||||||
EMULATION=yes
|
|
||||||
# USE_ADC = yes
|
|
||||||
|
|
||||||
include $(FRAUCHEKY)/src.mk
|
|
||||||
|
|
||||||
###################################
|
|
||||||
CROSS =
|
|
||||||
CC = $(CROSS)gcc
|
|
||||||
LD = $(CROSS)gcc
|
|
||||||
OBJCOPY = $(CROSS)objcopy
|
|
||||||
|
|
||||||
MCU = none
|
|
||||||
CWARN = -Wall -Wextra -Wstrict-prototypes
|
|
||||||
DEFS = -DGNU_LINUX_EMULATION
|
|
||||||
OPT = -O3 -g
|
|
||||||
LIBS = -lpthread
|
|
||||||
|
|
||||||
BFDNAME_OBJ=elf64-x86-64
|
|
||||||
BFDARCH=i386:x86-64
|
|
||||||
|
|
||||||
#######################
|
|
||||||
include $(CHOPSTX)/rules.mk
|
|
||||||
|
|
||||||
include $(FRAUCHEKY)/build.mk
|
|
||||||
###################################
|
|
||||||
|
|
||||||
board.h:
|
|
||||||
@echo Please run configure to have a symbolic link \'board.h\'
|
|
||||||
@exit 1
|
|
||||||
|
|
||||||
distclean:: clean
|
|
||||||
-rm -f config.h
|
|
@ -1,2 +0,0 @@
|
|||||||
@FRAUCHEKY_DEFINE@
|
|
||||||
@FRAUCHEKY_MSC_DEFINE@
|
|
137
gnuk/chopstx/example-fraucheky/configure
vendored
137
gnuk/chopstx/example-fraucheky/configure
vendored
@ -1,137 +0,0 @@
|
|||||||
#! /bin/bash
|
|
||||||
|
|
||||||
# This is bash which supports ANSI-C Quoting
|
|
||||||
nl=$'\n'
|
|
||||||
|
|
||||||
# Default settings
|
|
||||||
help=no
|
|
||||||
vidpid=none
|
|
||||||
verbose=no
|
|
||||||
debug=no
|
|
||||||
with_fraucheky=yes
|
|
||||||
with_index=./INDEX.HTM
|
|
||||||
|
|
||||||
if test -d ../.git; then
|
|
||||||
REVISION=`git describe --dirty="-modified"`
|
|
||||||
REVISION_CHOPSTX=`cd .. && git describe --dirty="-modified"`
|
|
||||||
REVISION_FRAUCHEKY=`cd ../../fraucheky &&git describe --dirty="-modified"`
|
|
||||||
else
|
|
||||||
REVISION=`cat ../VERSION`
|
|
||||||
REVISION_CHOPSTX=`cat ../VERSION`
|
|
||||||
REVISION_FRAUCHEKY=`cat ../../fraucheky/VERSION`
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Process each option
|
|
||||||
for option; do
|
|
||||||
case $option in
|
|
||||||
*=*) optarg=`expr "X$option" : '[^=]*=\(.*\)'` ;;
|
|
||||||
*) optarg=yes ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
case $option in
|
|
||||||
-h | --help)
|
|
||||||
help=yes ;;
|
|
||||||
-v | --verbose)
|
|
||||||
verbose=yes ;;
|
|
||||||
--vidpid=*)
|
|
||||||
vidpid=$optarg ;;
|
|
||||||
*)
|
|
||||||
echo "Unrecognized option \`$option'" >&2
|
|
||||||
echo "Try \`$0 --help' for more information." >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
if test "$help" = "yes"; then
|
|
||||||
cat <<EOF
|
|
||||||
Usage: $0 [OPTION]...
|
|
||||||
|
|
||||||
Defaults for the options are specified in brackets.
|
|
||||||
|
|
||||||
Configuration:
|
|
||||||
-h, --help display this help and exit [no]
|
|
||||||
--vidpid=VID:PID specify vendor/product ID [<NONE>]
|
|
||||||
--with-index=INDEX specify INDEX file [none]
|
|
||||||
EOF
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test "$vidpid" = "none"; then
|
|
||||||
echo "Please specify Vendor ID and Product ID by --vidpid option." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
VIDPID="$vidpid"
|
|
||||||
VERSION="0100"
|
|
||||||
PRODUCT="Fraucheky"
|
|
||||||
VENDOR="Free Software Initiative of Japan"
|
|
||||||
SERIALNO="FSIJ-`cat ../VERSION | sed -e 's%^[^/]*/%%'`-"
|
|
||||||
|
|
||||||
|
|
||||||
../../fraucheky/configure "$vidpid" $with_index $REVISION $REVISION_CHOPSTX $REVISION_FRAUCHEKY
|
|
||||||
|
|
||||||
ENABLE_FRAUCHEKY=""
|
|
||||||
FRAUCHEKY_DEFINE="#define FRAUCHEKY_SUPPORT 1"
|
|
||||||
FRAUCHEKY_MSC_DEFINE="#define MSC_INTERFACE_NO 2"
|
|
||||||
if ! test -f ../../fraucheky/build.mk; then
|
|
||||||
echo "'fraucheky' not found" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
output_vid_pid_version () {
|
|
||||||
echo $VIDPID | sed -n -e "s%^\([0-9a-f][0-9a-f]\)\([0-9a-f][0-9a-f]\):\([0-9a-f][0-9a-f]\)\([0-9a-f][0-9a-f]\)$% 0x\2, 0x\1, /* idVendor */\\${nl} 0x\4, 0x\3, /* idProduct */%p"
|
|
||||||
echo $VERSION | sed -n -e "s%^\([0-9a-f][0-9a-f]\)\([0-9a-f][0-9a-f]\)$% 0x\2, 0x\1, /* bcdDevice */%p"
|
|
||||||
}
|
|
||||||
|
|
||||||
output_vendor_product_serial_strings () {
|
|
||||||
prefix=$1
|
|
||||||
|
|
||||||
echo "static const uint8_t ${prefix}string_vendor[] = {"
|
|
||||||
echo " ${#VENDOR}*2+2, /* bLength */"
|
|
||||||
echo " STRING_DESCRIPTOR, /* bDescriptorType */"
|
|
||||||
echo " /* Manufacturer: \"$VENDOR\" */"
|
|
||||||
echo $VENDOR | sed -e "s/\(........\)/\1\\${nl}/g" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "/^ ./s/ $//p"
|
|
||||||
echo '};'
|
|
||||||
echo
|
|
||||||
echo "static const uint8_t ${prefix}string_product[] = {"
|
|
||||||
echo " ${#PRODUCT}*2+2, /* bLength */"
|
|
||||||
echo " STRING_DESCRIPTOR, /* bDescriptorType */"
|
|
||||||
echo " /* Product name: \"$PRODUCT\" */"
|
|
||||||
echo $PRODUCT | sed -e "s/\(........\)/\1\\${nl}/g" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "/^ ./s/ $//p"
|
|
||||||
echo '};'
|
|
||||||
|
|
||||||
if test -n "$prefix"; then
|
|
||||||
echo
|
|
||||||
echo "static uint8_t ${prefix}string_serial[] = {"
|
|
||||||
echo " ${#SERIALNO}*2+2+16, /* bLength */"
|
|
||||||
echo " STRING_DESCRIPTOR, /* bDescriptorType */"
|
|
||||||
echo " /* Serial number: \"$SERIALNO\" */"
|
|
||||||
echo $SERIALNO | sed -e "s/\(........\)/\1\\${nl}/g" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "/^ ./s/ $//p"
|
|
||||||
echo " 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,"
|
|
||||||
echo " 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,"
|
|
||||||
echo '};'
|
|
||||||
echo
|
|
||||||
echo "static const uint8_t ${prefix}revision_detail[] = {"
|
|
||||||
echo " ${#REVISION}*2+2, /* bLength */"
|
|
||||||
echo " STRING_DESCRIPTOR, /* bDescriptorType */"
|
|
||||||
echo " /* revision detail: \"$REVISION\" */"
|
|
||||||
echo $REVISION | sed -e "s/\(........\)/\1\\${nl}/g" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "/^ ./s/ $//p"
|
|
||||||
echo '};'
|
|
||||||
echo
|
|
||||||
echo "static const uint8_t ${prefix}config_options[] = {"
|
|
||||||
echo " ${#CONFIG}*2+2, /* bLength */"
|
|
||||||
echo " STRING_DESCRIPTOR, /* bDescriptorType */"
|
|
||||||
echo " /* configure options: \"$CONFIG\" */"
|
|
||||||
echo $CONFIG | sed -e "s/\(........\)/\1\\${nl}/g" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "/^ ./s/ $//p"
|
|
||||||
echo '};'
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
output_vid_pid_version > fraucheky-vid-pid-ver.c.inc
|
|
||||||
output_vendor_product_serial_strings >fraucheky-usb-strings.c.inc
|
|
||||||
|
|
||||||
sed -e "s/@FRAUCHEKY_DEFINE@/$FRAUCHEKY_DEFINE/" \
|
|
||||||
-e "s/@FRAUCHEKY_MSC_DEFINE@/$FRAUCHEKY_MSC_DEFINE/" \
|
|
||||||
< config.h.in > config.h
|
|
||||||
exit 0
|
|
@ -1,318 +0,0 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <chopstx.h>
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "usb_lld.h"
|
|
||||||
|
|
||||||
#define NUM_INTERFACES 1
|
|
||||||
#define FEATURE_BUS_POWERED 0x80
|
|
||||||
|
|
||||||
static chopstx_mutex_t usb_mtx;
|
|
||||||
static chopstx_cond_t usb_cnd;
|
|
||||||
static uint32_t bDeviceState = USB_DEVICE_STATE_UNCONNECTED;
|
|
||||||
|
|
||||||
extern void EP6_IN_Callback (uint16_t len);
|
|
||||||
extern void EP6_OUT_Callback (uint16_t len);
|
|
||||||
|
|
||||||
#define MSC_MASS_STORAGE_RESET_COMMAND 0xFF
|
|
||||||
extern int fraucheky_enabled (void);
|
|
||||||
extern void fraucheky_init (void);
|
|
||||||
extern void fraucheky_main (void);
|
|
||||||
|
|
||||||
extern void fraucheky_setup_endpoints_for_interface (struct usb_dev *dev, int stop);
|
|
||||||
extern int fraucheky_setup (struct usb_dev *dev);
|
|
||||||
extern int fraucheky_get_descriptor (struct usb_dev *dev);
|
|
||||||
|
|
||||||
static void
|
|
||||||
setup_endpoints_for_interface (struct usb_dev *dev, uint16_t interface, int stop)
|
|
||||||
{
|
|
||||||
if (interface == 0)
|
|
||||||
fraucheky_setup_endpoints_for_interface (dev, stop);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
usb_device_reset (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
usb_lld_reset (dev, FEATURE_BUS_POWERED);
|
|
||||||
|
|
||||||
/* Initialize Endpoint 0. */
|
|
||||||
usb_lld_setup_endp (dev, ENDP0, 1, 1);
|
|
||||||
|
|
||||||
/* Notify upper layer. */
|
|
||||||
chopstx_mutex_lock (&usb_mtx);
|
|
||||||
bDeviceState = USB_DEVICE_STATE_ATTACHED;
|
|
||||||
chopstx_cond_signal (&usb_cnd);
|
|
||||||
chopstx_mutex_unlock (&usb_mtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
usb_ctrl_write_finish (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
struct device_req *arg = &dev->dev_req;
|
|
||||||
uint8_t type_rcp = arg->type & (REQUEST_TYPE|RECIPIENT);
|
|
||||||
|
|
||||||
if (type_rcp == (CLASS_REQUEST | INTERFACE_RECIPIENT) && arg->index == 0
|
|
||||||
&& USB_SETUP_SET (arg->type))
|
|
||||||
{
|
|
||||||
if (arg->request == MSC_MASS_STORAGE_RESET_COMMAND)
|
|
||||||
fraucheky_setup_endpoints_for_interface (dev, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
usb_setup (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
struct device_req *arg = &dev->dev_req;
|
|
||||||
uint8_t type_rcp = arg->type & (REQUEST_TYPE|RECIPIENT);
|
|
||||||
|
|
||||||
if (type_rcp == (CLASS_REQUEST | INTERFACE_RECIPIENT)
|
|
||||||
&& arg->index == 0)
|
|
||||||
return fraucheky_setup (dev);
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
usb_set_configuration (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
uint8_t current_conf;
|
|
||||||
|
|
||||||
current_conf = usb_lld_current_configuration (dev);
|
|
||||||
if (current_conf == 0)
|
|
||||||
{
|
|
||||||
if (dev->dev_req.value != 1)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
usb_lld_set_configuration (dev, 1);
|
|
||||||
for (i = 0; i < NUM_INTERFACES; i++)
|
|
||||||
setup_endpoints_for_interface (dev, i, 0);
|
|
||||||
chopstx_mutex_lock (&usb_mtx);
|
|
||||||
bDeviceState = USB_DEVICE_STATE_CONFIGURED;
|
|
||||||
chopstx_mutex_unlock (&usb_mtx);
|
|
||||||
}
|
|
||||||
else if (current_conf != dev->dev_req.value)
|
|
||||||
{
|
|
||||||
if (dev->dev_req.value != 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
usb_lld_set_configuration (dev, 0);
|
|
||||||
for (i = 0; i < NUM_INTERFACES; i++)
|
|
||||||
setup_endpoints_for_interface (dev, i, 1);
|
|
||||||
chopstx_mutex_lock (&usb_mtx);
|
|
||||||
bDeviceState = USB_DEVICE_STATE_ADDRESSED;
|
|
||||||
chopstx_cond_signal (&usb_cnd);
|
|
||||||
chopstx_mutex_unlock (&usb_mtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Do nothing when current_conf == value */
|
|
||||||
return usb_lld_ctrl_ack (dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
usb_set_interface (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
uint16_t interface = dev->dev_req.index;
|
|
||||||
uint16_t alt = dev->dev_req.value;
|
|
||||||
|
|
||||||
if (interface >= NUM_INTERFACES)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (alt != 0)
|
|
||||||
return -1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setup_endpoints_for_interface (dev, interface, 0);
|
|
||||||
return usb_lld_ctrl_ack (dev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
usb_get_interface (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
const uint8_t zero = 0;
|
|
||||||
uint16_t interface = dev->dev_req.index;
|
|
||||||
|
|
||||||
if (interface >= NUM_INTERFACES)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return usb_lld_ctrl_send (dev, &zero, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
usb_get_status_interface (struct usb_dev *dev)
|
|
||||||
{
|
|
||||||
const uint16_t status_info = 0;
|
|
||||||
uint16_t interface = dev->dev_req.index;
|
|
||||||
|
|
||||||
if (interface >= NUM_INTERFACES)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return usb_lld_ctrl_send (dev, &status_info, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void usb_tx_done (uint8_t ep_num, uint16_t len);
|
|
||||||
static void usb_rx_ready (uint8_t ep_num, uint16_t len);
|
|
||||||
|
|
||||||
|
|
||||||
#define PRIO_USB 3
|
|
||||||
|
|
||||||
static void *
|
|
||||||
usb_main (void *arg)
|
|
||||||
{
|
|
||||||
chopstx_intr_t interrupt;
|
|
||||||
struct usb_dev dev;
|
|
||||||
int e;
|
|
||||||
|
|
||||||
(void)arg;
|
|
||||||
chopstx_claim_irq (&interrupt, INTR_REQ_USB);
|
|
||||||
usb_lld_init (&dev, FEATURE_BUS_POWERED);
|
|
||||||
goto event_handle; /* For old SYS < 3.0 */
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
chopstx_intr_wait (&interrupt);
|
|
||||||
|
|
||||||
if (interrupt.ready)
|
|
||||||
{
|
|
||||||
uint8_t ep_num;
|
|
||||||
|
|
||||||
event_handle:
|
|
||||||
e = usb_lld_event_handler (&dev);
|
|
||||||
chopstx_intr_done (&interrupt);
|
|
||||||
ep_num = USB_EVENT_ENDP (e);
|
|
||||||
|
|
||||||
if (ep_num != 0)
|
|
||||||
{
|
|
||||||
if (USB_EVENT_TXRX (e))
|
|
||||||
usb_tx_done (ep_num, USB_EVENT_LEN (e));
|
|
||||||
else
|
|
||||||
usb_rx_ready (ep_num, USB_EVENT_LEN (e));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
switch (USB_EVENT_ID (e))
|
|
||||||
{
|
|
||||||
case USB_EVENT_DEVICE_RESET:
|
|
||||||
usb_device_reset (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_DEVICE_ADDRESSED:
|
|
||||||
chopstx_mutex_lock (&usb_mtx);
|
|
||||||
bDeviceState = USB_DEVICE_STATE_ADDRESSED;
|
|
||||||
chopstx_cond_signal (&usb_cnd);
|
|
||||||
chopstx_mutex_unlock (&usb_mtx);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_GET_DESCRIPTOR:
|
|
||||||
if (fraucheky_get_descriptor (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_SET_CONFIGURATION:
|
|
||||||
if (usb_set_configuration (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_SET_INTERFACE:
|
|
||||||
if (usb_set_interface (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_CTRL_REQUEST:
|
|
||||||
/* Device specific device request. */
|
|
||||||
if (usb_setup (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_GET_STATUS_INTERFACE:
|
|
||||||
if (usb_get_status_interface (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_GET_INTERFACE:
|
|
||||||
if (usb_get_interface (&dev) < 0)
|
|
||||||
usb_lld_ctrl_error (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_SET_FEATURE_DEVICE:
|
|
||||||
case USB_EVENT_SET_FEATURE_ENDPOINT:
|
|
||||||
case USB_EVENT_CLEAR_FEATURE_DEVICE:
|
|
||||||
case USB_EVENT_CLEAR_FEATURE_ENDPOINT:
|
|
||||||
usb_lld_ctrl_ack (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_CTRL_WRITE_FINISH:
|
|
||||||
/* Control WRITE transfer finished. */
|
|
||||||
usb_ctrl_write_finish (&dev);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case USB_EVENT_OK:
|
|
||||||
case USB_EVENT_DEVICE_SUSPEND:
|
|
||||||
default:
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
usb_tx_done (uint8_t ep_num, uint16_t len)
|
|
||||||
{
|
|
||||||
if (ep_num == ENDP6)
|
|
||||||
EP6_IN_Callback (len);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
usb_rx_ready (uint8_t ep_num, uint16_t len)
|
|
||||||
{
|
|
||||||
if (ep_num == ENDP6)
|
|
||||||
EP6_OUT_Callback (len);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char __process3_stack_base__[4096];
|
|
||||||
|
|
||||||
#define STACK_ADDR_USB ((uintptr_t)__process3_stack_base__)
|
|
||||||
#define STACK_SIZE_USB (sizeof __process3_stack_base__)
|
|
||||||
|
|
||||||
#ifdef GNU_LINUX_EMULATION
|
|
||||||
#define main emulated_main
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Entry point.
|
|
||||||
*
|
|
||||||
* NOTE: the main function is already a thread in the system on entry.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
main (int argc, char **argv)
|
|
||||||
{
|
|
||||||
chopstx_t usb_thd;
|
|
||||||
|
|
||||||
(void)argc;
|
|
||||||
(void)argv;
|
|
||||||
|
|
||||||
chopstx_mutex_init (&usb_mtx);
|
|
||||||
chopstx_cond_init (&usb_cnd);
|
|
||||||
|
|
||||||
bDeviceState = USB_DEVICE_STATE_UNCONNECTED;
|
|
||||||
usb_thd = chopstx_create (PRIO_USB, STACK_ADDR_USB, STACK_SIZE_USB,
|
|
||||||
usb_main, NULL);
|
|
||||||
fraucheky_init ();
|
|
||||||
while (bDeviceState != USB_DEVICE_STATE_CONFIGURED)
|
|
||||||
chopstx_usec_wait (250*1000);
|
|
||||||
fraucheky_main ();
|
|
||||||
chopstx_cancel (usb_thd);
|
|
||||||
chopstx_join (usb_thd, NULL);
|
|
||||||
usb_lld_shutdown ();
|
|
||||||
bDeviceState = USB_DEVICE_STATE_UNCONNECTED;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
# Makefile for example application of Chopstx
|
|
||||||
|
|
||||||
PROJECT = sample
|
|
||||||
|
|
||||||
### Currently, it's for FS-BB48.
|
|
||||||
|
|
||||||
CHOPSTX = ..
|
|
||||||
LDSCRIPT= sample.ld
|
|
||||||
CSRC = sample.c usb-cdc.c command.c touch.c
|
|
||||||
CHIP=mkl27z
|
|
||||||
|
|
||||||
USE_SYS = yes
|
|
||||||
USE_USB = yes
|
|
||||||
USE_ADC = yes
|
|
||||||
|
|
||||||
###################################
|
|
||||||
CROSS = arm-none-eabi-
|
|
||||||
CC = $(CROSS)gcc
|
|
||||||
LD = $(CROSS)gcc
|
|
||||||
OBJCOPY = $(CROSS)objcopy
|
|
||||||
|
|
||||||
MCU = cortex-m0plus
|
|
||||||
CWARN = -Wall -Wextra -Wstrict-prototypes
|
|
||||||
DEFS = -DFREE_STANDING -DMHZ=48 -DUSE_SYS3
|
|
||||||
OPT = -O3 -Os -g
|
|
||||||
LIBS =
|
|
||||||
|
|
||||||
####################
|
|
||||||
include ../rules.mk
|
|
||||||
|
|
||||||
board.h:
|
|
||||||
@echo Please make a symbolic link \'board.h\' to a file in ../board;
|
|
||||||
@exit 1
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
rm -f board.h
|
|
@ -1,542 +0,0 @@
|
|||||||
#include <string.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <chopstx.h>
|
|
||||||
#include "tty.h"
|
|
||||||
#include "config.h"
|
|
||||||
#ifdef ADC_SUPPORT
|
|
||||||
#include "adc.h"
|
|
||||||
static int adc_initialized = 0;
|
|
||||||
#endif
|
|
||||||
#include "board.h"
|
|
||||||
#include "sys.h"
|
|
||||||
|
|
||||||
struct command_table
|
|
||||||
{
|
|
||||||
const char *name;
|
|
||||||
void (*handler) (struct tty *tty, const char *line);
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Put a line (or lines) to TTY.
|
|
||||||
* LINE should be terminated with newline.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
put_line (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
tty_send (tty, line, strlen (line));
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *help_string =
|
|
||||||
"mdw ADDR [COUNT]; memory display word\r\n"
|
|
||||||
"mww ADDR VALUE [COUNT]; memory write word\r\n"
|
|
||||||
"fes ADDR [COUNT]; flash erase sector\r\n"
|
|
||||||
"fww ADDR VALUE [COUNT]; flash write word\r\n"
|
|
||||||
#ifdef CRC32_SUPPORT
|
|
||||||
"crc32 string; CRC32 calc string\r\n"
|
|
||||||
#endif
|
|
||||||
#ifdef ADC_SUPPORT
|
|
||||||
"adc; get 256-byte from ADC\r\n"
|
|
||||||
#endif
|
|
||||||
"sysinfo; system information\r\n"
|
|
||||||
"help\r\n";
|
|
||||||
|
|
||||||
static char hexchar (uint8_t x)
|
|
||||||
{
|
|
||||||
x &= 0x0f;
|
|
||||||
if (x <= 0x09)
|
|
||||||
return '0' + x;
|
|
||||||
else if (x <= 0x0f)
|
|
||||||
return 'a' + x - 10;
|
|
||||||
else
|
|
||||||
return '?';
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
|
||||||
compose_decimal (char *s, int value)
|
|
||||||
{
|
|
||||||
uint32_t v;
|
|
||||||
int col = 1000000000;
|
|
||||||
int d;
|
|
||||||
int digit_output = 0;
|
|
||||||
|
|
||||||
if (value < 0)
|
|
||||||
{
|
|
||||||
*s++ = '-';
|
|
||||||
v = 1 + ~((uint32_t)value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
v = (uint32_t)value;
|
|
||||||
|
|
||||||
while (col >= 10)
|
|
||||||
{
|
|
||||||
if (v >= (uint32_t)col)
|
|
||||||
{
|
|
||||||
d = v / col;
|
|
||||||
v = v - d * col;
|
|
||||||
*s++ = d + '0';
|
|
||||||
digit_output = 1;
|
|
||||||
}
|
|
||||||
else if (digit_output)
|
|
||||||
*s++ = '0';
|
|
||||||
|
|
||||||
col = col / 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
*s++ = v + '0';
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static char *
|
|
||||||
compose_hex (char *s, uint32_t v)
|
|
||||||
{
|
|
||||||
s[0] = hexchar (v >> 28);
|
|
||||||
s[1] = hexchar (v >> 24);
|
|
||||||
s[2] = hexchar (v >> 20);
|
|
||||||
s[3] = hexchar (v >> 16);
|
|
||||||
s[4] = hexchar (v >> 12);
|
|
||||||
s[5] = hexchar (v >> 8);
|
|
||||||
s[6] = hexchar (v >> 4);
|
|
||||||
s[7] = hexchar (v);
|
|
||||||
return s+8;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *
|
|
||||||
get_hex (struct tty *tty, const char *s, uint32_t *v_p)
|
|
||||||
{
|
|
||||||
uint32_t v = 0;
|
|
||||||
char c;
|
|
||||||
|
|
||||||
if (s[0] == '0' && s[1] == 'x')
|
|
||||||
s = s + 2;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
c = *s++;
|
|
||||||
|
|
||||||
if (c == 0)
|
|
||||||
{
|
|
||||||
s--;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == ' ')
|
|
||||||
break;
|
|
||||||
|
|
||||||
v = (v << 4);
|
|
||||||
if (c >= '0' && c <= '9')
|
|
||||||
v += (c - '0');
|
|
||||||
else if (c >= 'a' && c <= 'f')
|
|
||||||
v += (c - 'a') + 10;
|
|
||||||
else if (c >= 'A' && c <= 'F')
|
|
||||||
v += (c - 'A') + 10;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
put_line (tty, "hex error\r\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*v_p = v;
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define TOUCH_VALUE_HIGH 100
|
|
||||||
#define TOUCH_VALUE_LOW 50
|
|
||||||
static void
|
|
||||||
cmd_button (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
extern uint16_t touch_get (void);
|
|
||||||
uint16_t v0 = 0;
|
|
||||||
int touched = 0;
|
|
||||||
|
|
||||||
(void)line;
|
|
||||||
put_line (tty, "Please touch the bear.\r\n");
|
|
||||||
|
|
||||||
while (i < 16)
|
|
||||||
{
|
|
||||||
uint16_t v = touch_get ();
|
|
||||||
v0 = (v0 * 2 + v)/3;
|
|
||||||
|
|
||||||
if (touched == 0 && v0 > TOUCH_VALUE_HIGH)
|
|
||||||
{
|
|
||||||
tty_send (tty, "!", 1);
|
|
||||||
touched = 1;
|
|
||||||
}
|
|
||||||
else if (touched == 1 && v0 < TOUCH_VALUE_LOW)
|
|
||||||
{
|
|
||||||
tty_send (tty, ".", 1);
|
|
||||||
touched = 0;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
chopstx_usec_wait (10*1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
tty_send (tty, "\r\n", 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_touch (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
extern uint16_t touch_get (void);
|
|
||||||
|
|
||||||
(void)line;
|
|
||||||
put_line (tty, "Please touch the bear.\r\n");
|
|
||||||
|
|
||||||
for (i = 0; i < 20; i++)
|
|
||||||
{
|
|
||||||
uint16_t v;
|
|
||||||
char output[8];
|
|
||||||
char *s;
|
|
||||||
|
|
||||||
chopstx_usec_wait (1000*1000);
|
|
||||||
v = touch_get ();
|
|
||||||
s = compose_decimal (output, v);
|
|
||||||
*s++ = '\r';
|
|
||||||
*s++ = '\n';
|
|
||||||
tty_send (tty, output, s - output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_mdw (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
uint32_t addr = 0;
|
|
||||||
int count = 0;
|
|
||||||
char c;
|
|
||||||
const char *s = line;
|
|
||||||
|
|
||||||
s = get_hex (tty, s, &addr);
|
|
||||||
addr &= ~3;
|
|
||||||
if (s == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (*s == 0)
|
|
||||||
count = 1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
c = *s++;
|
|
||||||
|
|
||||||
if (c == 0 || c == ' ')
|
|
||||||
break;
|
|
||||||
|
|
||||||
count = count * 10;
|
|
||||||
if (c >= '0' && c <= '9')
|
|
||||||
count += c - '0';
|
|
||||||
else
|
|
||||||
{
|
|
||||||
put_line (tty, "mdw error\r\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < count)
|
|
||||||
{
|
|
||||||
uint32_t v;
|
|
||||||
char output[48];
|
|
||||||
char *s;
|
|
||||||
|
|
||||||
s = compose_hex (output, addr);
|
|
||||||
*s++ = ':';
|
|
||||||
*s++ = ' ';
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
v = *(uint32_t *)addr;
|
|
||||||
s = compose_hex (s, v);
|
|
||||||
i++;
|
|
||||||
addr += 4;
|
|
||||||
if (i >= count || (i % 4) == 0)
|
|
||||||
break;
|
|
||||||
*s++ = ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
*s++ = '\r';
|
|
||||||
*s++ = '\n';
|
|
||||||
tty_send (tty, output, s - output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_mww (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
(void)tty;
|
|
||||||
(void)line;
|
|
||||||
put_line (tty, "mww not yet supported\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_fes (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
uint32_t addr = 0;
|
|
||||||
int count = 0;
|
|
||||||
char c;
|
|
||||||
const char *s = line;
|
|
||||||
|
|
||||||
s = get_hex (tty, s, &addr);
|
|
||||||
if (s == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (*s == 0)
|
|
||||||
count = 1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
c = *s++;
|
|
||||||
|
|
||||||
if (c == 0 || c == ' ')
|
|
||||||
break;
|
|
||||||
|
|
||||||
count = count * 10;
|
|
||||||
if (c >= '0' && c <= '9')
|
|
||||||
count += c - '0';
|
|
||||||
else
|
|
||||||
{
|
|
||||||
put_line (tty, "fww error\r\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
flash_erase_page (addr);
|
|
||||||
addr += 1024;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_fww (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
uint32_t addr = 0;
|
|
||||||
uint32_t value = 0;
|
|
||||||
int count = 0;
|
|
||||||
char c;
|
|
||||||
const char *s = line;
|
|
||||||
|
|
||||||
s = get_hex (tty, s, &addr);
|
|
||||||
if (s == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (*s == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
s = get_hex (tty, s, &value);
|
|
||||||
if (s == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (*s == 0)
|
|
||||||
count = 1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
c = *s++;
|
|
||||||
|
|
||||||
if (c == 0 || c == ' ')
|
|
||||||
break;
|
|
||||||
|
|
||||||
count = count * 10;
|
|
||||||
if (c >= '0' && c <= '9')
|
|
||||||
count += c - '0';
|
|
||||||
else
|
|
||||||
{
|
|
||||||
put_line (tty, "fww error\r\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
flash_program_word (addr, value);
|
|
||||||
addr += 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef CRC32_SUPPORT
|
|
||||||
static unsigned int crc_value;
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_crc32 (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
uint32_t v;
|
|
||||||
char string[10];
|
|
||||||
char *s;
|
|
||||||
|
|
||||||
crc32_init (&crc_value);
|
|
||||||
while (*line)
|
|
||||||
crc32_u8 (&crc_value, *line++);
|
|
||||||
v = crc_value ^ 0xffffffff;
|
|
||||||
|
|
||||||
s = compose_hex (string, v);
|
|
||||||
*s++ = '\r';
|
|
||||||
*s++ = '\n';
|
|
||||||
tty_send (tty, string, sizeof (string));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ADC_SUPPORT
|
|
||||||
static void
|
|
||||||
cmd_adc (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char output[73];
|
|
||||||
char *s;
|
|
||||||
|
|
||||||
(void)line;
|
|
||||||
|
|
||||||
if (!adc_initialized)
|
|
||||||
{
|
|
||||||
if (adc_init ())
|
|
||||||
{
|
|
||||||
put_line (tty, "adc_init error\r\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
adc_start ();
|
|
||||||
adc_initialized = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
adc_start_conversion (0, 64);
|
|
||||||
adc_wait_completion ();
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
s = output;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
s = compose_hex (s, adc_buf[i]);
|
|
||||||
i++;
|
|
||||||
if ((i % 8))
|
|
||||||
*s++ = ' ';
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*s++ = '\r';
|
|
||||||
*s++ = '\n';
|
|
||||||
tty_send (tty, output, s - output);
|
|
||||||
s = output;
|
|
||||||
if (i >= 64)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_sysinfo (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
char output[73];
|
|
||||||
char *s;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
(void)line;
|
|
||||||
memcpy (output, "SYS version: ", 13);
|
|
||||||
s = output + 13;
|
|
||||||
*s++ = sys_version[2];
|
|
||||||
*s++ = sys_version[4];
|
|
||||||
*s++ = sys_version[6];
|
|
||||||
*s++ = '\r';
|
|
||||||
*s++ = '\n';
|
|
||||||
tty_send (tty, output, s - output);
|
|
||||||
|
|
||||||
memcpy (output, "Board ID: ", 10);
|
|
||||||
s = output + 10;
|
|
||||||
s = compose_hex (s, sys_board_id);
|
|
||||||
*s++ = '\r';
|
|
||||||
*s++ = '\n';
|
|
||||||
tty_send (tty, output, s - output);
|
|
||||||
|
|
||||||
memcpy (output, "Board name: ", 12);
|
|
||||||
s = output + 12;
|
|
||||||
for (i = 0; i < (int)sizeof (output) - 2; i ++)
|
|
||||||
if ((*s = sys_board_name[i]) == 0)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
s++;
|
|
||||||
|
|
||||||
*s++ = '\r';
|
|
||||||
*s++ = '\n';
|
|
||||||
tty_send (tty, output, s - output);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
cmd_help (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
(void)line;
|
|
||||||
put_line (tty, help_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct command_table command_table[] = {
|
|
||||||
{ "button", cmd_button },
|
|
||||||
{ "touch", cmd_touch },
|
|
||||||
{ "mdw", cmd_mdw },
|
|
||||||
{ "mww", cmd_mww },
|
|
||||||
{ "fes", cmd_fes },
|
|
||||||
{ "fww", cmd_fww },
|
|
||||||
#ifdef CRC32_SUPPORT
|
|
||||||
{ "crc32", cmd_crc32 },
|
|
||||||
#endif
|
|
||||||
#ifdef ADC_SUPPORT
|
|
||||||
{ "adc", cmd_adc },
|
|
||||||
#endif
|
|
||||||
{ "sysinfo", cmd_sysinfo },
|
|
||||||
{ "help", cmd_help },
|
|
||||||
};
|
|
||||||
|
|
||||||
#define N_CMDS (int)(sizeof (command_table) / sizeof (struct command_table))
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Dispatch a command parsing LINE.
|
|
||||||
* Line is NULL terminated with no newline.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
cmd_dispatch (struct tty *tty, const char *line)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
const char *p;
|
|
||||||
unsigned int n = 0;
|
|
||||||
|
|
||||||
p = line;
|
|
||||||
while (*p)
|
|
||||||
{
|
|
||||||
if (*p++ == ' ')
|
|
||||||
break;
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < N_CMDS; i++)
|
|
||||||
if (n == strlen (command_table[i].name)
|
|
||||||
&& strncmp ((const char *)line, command_table[i].name, n) == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (i != N_CMDS)
|
|
||||||
(*command_table[i].handler) (tty, p);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
char crlf[] = { '\r', '\n' };
|
|
||||||
|
|
||||||
put_line (tty, "No such command: ");
|
|
||||||
tty_send (tty, line, n);
|
|
||||||
tty_send (tty, crlf, sizeof (crlf));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
void cmd_dispatch (struct tty *tty, const char *line);
|
|
@ -1,2 +0,0 @@
|
|||||||
#define CRC32_SUPPORT
|
|
||||||
#define ADC_SUPPORT
|
|
@ -1,22 +0,0 @@
|
|||||||
const unsigned int *const crc32_table= (const unsigned int *)0x00000480;
|
|
||||||
|
|
||||||
void
|
|
||||||
crc32_init (unsigned int *p)
|
|
||||||
{
|
|
||||||
*p = 0xffffffff;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
crc32_u8 (unsigned int *p, unsigned char v)
|
|
||||||
{
|
|
||||||
*p = crc32_table[(*p & 0xff) ^ v] ^ (*p >> 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
crc32_u32 (unsigned int *p, unsigned int u)
|
|
||||||
{
|
|
||||||
crc32_u8 (p, u & 0xff);
|
|
||||||
crc32_u8 (p, (u >> 8)& 0xff);
|
|
||||||
crc32_u8 (p, (u >> 16)& 0xff);
|
|
||||||
crc32_u8 (p, (u >> 24)& 0xff);
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
#
|
|
||||||
# Polynomial for CRC32:
|
|
||||||
# x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1
|
|
||||||
#
|
|
||||||
# When it is represented in binary, it's:
|
|
||||||
# 0x04C11DB7
|
|
||||||
# =
|
|
||||||
# 0000 0100 1100 0001 0001 1101 1011 0111
|
|
||||||
#
|
|
||||||
# When we put in reverse bit-order, it's
|
|
||||||
# 0xedb88320
|
|
||||||
|
|
||||||
for i in range(0,256):
|
|
||||||
c = i
|
|
||||||
for j in range(0,8):
|
|
||||||
if (c&1):
|
|
||||||
c = 0xEDB88320 ^ (c >> 1)
|
|
||||||
else:
|
|
||||||
c = c >> 1
|
|
||||||
print("0x%08x," % c),
|
|
||||||
if (i % 6) == 5:
|
|
||||||
print("")
|
|
@ -1,189 +0,0 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <chopstx.h>
|
|
||||||
|
|
||||||
#include "usb_lld.h"
|
|
||||||
#include "tty.h"
|
|
||||||
#include "board.h"
|
|
||||||
#include "command.h"
|
|
||||||
#include <sys.h>
|
|
||||||
|
|
||||||
static chopstx_mutex_t mtx;
|
|
||||||
static chopstx_cond_t cnd0;
|
|
||||||
static chopstx_cond_t cnd1;
|
|
||||||
|
|
||||||
uint8_t u;
|
|
||||||
static uint8_t v;
|
|
||||||
static uint8_t m; /* 0..100 */
|
|
||||||
|
|
||||||
static void
|
|
||||||
wait_for (uint32_t usec)
|
|
||||||
{
|
|
||||||
#if defined(BUSY_LOOP)
|
|
||||||
uint32_t count = usec * 6;
|
|
||||||
uint32_t i;
|
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
|
||||||
asm volatile ("" : : "r" (i) : "memory");
|
|
||||||
#else
|
|
||||||
chopstx_usec_wait (usec);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *
|
|
||||||
pwm (void *arg)
|
|
||||||
{
|
|
||||||
(void)arg;
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&mtx);
|
|
||||||
chopstx_cond_wait (&cnd0, &mtx);
|
|
||||||
chopstx_mutex_unlock (&mtx);
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
set_led (u&v);
|
|
||||||
wait_for (m);
|
|
||||||
set_led (0);
|
|
||||||
wait_for (100-m);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *
|
|
||||||
blk (void *arg)
|
|
||||||
{
|
|
||||||
(void)arg;
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&mtx);
|
|
||||||
chopstx_cond_wait (&cnd1, &mtx);
|
|
||||||
chopstx_mutex_unlock (&mtx);
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
v = 0;
|
|
||||||
wait_for (200*1000);
|
|
||||||
v = 1;
|
|
||||||
wait_for (200*1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define PRIO_PWM 3
|
|
||||||
#define PRIO_BLK 2
|
|
||||||
|
|
||||||
extern uint8_t __process1_stack_base__[], __process1_stack_size__[];
|
|
||||||
extern uint8_t __process2_stack_base__[], __process2_stack_size__[];
|
|
||||||
|
|
||||||
#define STACK_ADDR_PWM ((uint32_t)__process1_stack_base__)
|
|
||||||
#define STACK_SIZE_PWM ((uint32_t)__process1_stack_size__)
|
|
||||||
|
|
||||||
#define STACK_ADDR_BLK ((uint32_t)__process2_stack_base__)
|
|
||||||
#define STACK_SIZE_BLK ((uint32_t)__process2_stack_size__)
|
|
||||||
|
|
||||||
|
|
||||||
static char hexchar (uint8_t x)
|
|
||||||
{
|
|
||||||
x &= 0x0f;
|
|
||||||
if (x <= 0x09)
|
|
||||||
return '0' + x;
|
|
||||||
else if (x <= 0x0f)
|
|
||||||
return 'a' + x - 10;
|
|
||||||
else
|
|
||||||
return '?';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
extern void touch_init (void);
|
|
||||||
|
|
||||||
int
|
|
||||||
main (int argc, const char *argv[])
|
|
||||||
{
|
|
||||||
struct tty *tty;
|
|
||||||
uint8_t count;
|
|
||||||
|
|
||||||
(void)argc;
|
|
||||||
(void)argv;
|
|
||||||
|
|
||||||
chopstx_mutex_init (&mtx);
|
|
||||||
chopstx_cond_init (&cnd0);
|
|
||||||
chopstx_cond_init (&cnd1);
|
|
||||||
|
|
||||||
m = 10;
|
|
||||||
|
|
||||||
chopstx_create (PRIO_PWM, STACK_ADDR_PWM, STACK_SIZE_PWM, pwm, NULL);
|
|
||||||
chopstx_create (PRIO_BLK, STACK_ADDR_BLK, STACK_SIZE_BLK, blk, NULL);
|
|
||||||
|
|
||||||
chopstx_usec_wait (200*1000);
|
|
||||||
|
|
||||||
chopstx_mutex_lock (&mtx);
|
|
||||||
chopstx_cond_signal (&cnd0);
|
|
||||||
chopstx_cond_signal (&cnd1);
|
|
||||||
chopstx_mutex_unlock (&mtx);
|
|
||||||
|
|
||||||
u = 1;
|
|
||||||
|
|
||||||
touch_init ();
|
|
||||||
|
|
||||||
tty = tty_open ();
|
|
||||||
tty_wait_configured (tty);
|
|
||||||
|
|
||||||
count = 0;
|
|
||||||
m = 50;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
char s[LINEBUFSIZE];
|
|
||||||
|
|
||||||
connection_loop:
|
|
||||||
u = 1;
|
|
||||||
tty_wait_connection (tty);
|
|
||||||
|
|
||||||
chopstx_usec_wait (50*1000);
|
|
||||||
|
|
||||||
/* Send ZLP at the beginning. */
|
|
||||||
tty_send (tty, s, 0);
|
|
||||||
|
|
||||||
memcpy (s, "xx: Hello, World with Chopstx!\r\n", 32);
|
|
||||||
s[0] = hexchar (count >> 4);
|
|
||||||
s[1] = hexchar (count & 0x0f);
|
|
||||||
count++;
|
|
||||||
|
|
||||||
if (tty_send (tty, s, 32) < 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
uint32_t usec;
|
|
||||||
|
|
||||||
/* Prompt */
|
|
||||||
if (tty_send (tty, "> ", 2) < 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
usec = 3000000; /* 3.0 seconds */
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
int size = tty_recv (tty, s, &usec);
|
|
||||||
u ^= 1;
|
|
||||||
|
|
||||||
if (size < 0)
|
|
||||||
goto connection_loop;
|
|
||||||
|
|
||||||
if (size == 1)
|
|
||||||
/* Do nothing but prompt again. */
|
|
||||||
break;
|
|
||||||
else if (size)
|
|
||||||
{
|
|
||||||
/* Newline into NUL */
|
|
||||||
s[size - 1] = 0;
|
|
||||||
cmd_dispatch (tty, (char *)s);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,150 +0,0 @@
|
|||||||
/*
|
|
||||||
* MK27Z memory setup.
|
|
||||||
*/
|
|
||||||
__main_stack_size__ = 0x0100; /* Idle+Exception handlers */
|
|
||||||
__process0_stack_size__ = 0x0300; /* Main program */
|
|
||||||
__process1_stack_size__ = 0x0200; /* first thread program */
|
|
||||||
__process2_stack_size__ = 0x0100; /* second thread program */
|
|
||||||
__process3_stack_size__ = 0x0200; /* third thread program */
|
|
||||||
|
|
||||||
MEMORY
|
|
||||||
{
|
|
||||||
flash : org = 0x00000000, len = 256k
|
|
||||||
ram : org = 0x1fffe000, len = 32k
|
|
||||||
}
|
|
||||||
|
|
||||||
__ram_start__ = ORIGIN(ram);
|
|
||||||
__ram_size__ = 32k;
|
|
||||||
__ram_end__ = __ram_start__ + __ram_size__;
|
|
||||||
|
|
||||||
SECTIONS
|
|
||||||
{
|
|
||||||
. = 0;
|
|
||||||
|
|
||||||
_text = .;
|
|
||||||
|
|
||||||
.text : ALIGN(16) SUBALIGN(8)
|
|
||||||
{
|
|
||||||
KEEP(*(.first_page.first_words))
|
|
||||||
KEEP(*(.sys.version))
|
|
||||||
KEEP(*(.sys.board_info))
|
|
||||||
KEEP(*(.sys.vectors))
|
|
||||||
build/sys-*.o(.text)
|
|
||||||
build/sys-*.o(.text.*)
|
|
||||||
build/sys-*.o(.rodata)
|
|
||||||
build/sys-*.o(.rodata.*)
|
|
||||||
. = ALIGN(1024);
|
|
||||||
KEEP(*(.flash_config))
|
|
||||||
KEEP(*(.fixed_function.reset))
|
|
||||||
KEEP(*(.fixed_function.flash_do_internal))
|
|
||||||
KEEP(*(.fixed_function.flash_do))
|
|
||||||
KEEP(*(.fixed_function.flash_erase_page))
|
|
||||||
KEEP(*(.fixed_function.flash_program_word))
|
|
||||||
KEEP(*(.fixed_function.crc32_init))
|
|
||||||
KEEP(*(.fixed_function.crc32_u8))
|
|
||||||
KEEP(*(.fixed_function.crc32_u32))
|
|
||||||
/*
|
|
||||||
* Because of alignment requirement
|
|
||||||
* of startup.vectors, align to 256.
|
|
||||||
*/
|
|
||||||
. = ALIGN(256);
|
|
||||||
KEEP(*(.crc32_table))
|
|
||||||
KEEP(*(.startup.vectors))
|
|
||||||
. = ALIGN(16);
|
|
||||||
*(.text.startup.*)
|
|
||||||
*(.text)
|
|
||||||
*(.text.*)
|
|
||||||
*(.rodata)
|
|
||||||
*(.rodata.*)
|
|
||||||
*(.glue_7t)
|
|
||||||
*(.glue_7)
|
|
||||||
*(.gcc*)
|
|
||||||
. = ALIGN(8);
|
|
||||||
} > flash =0xffffffff
|
|
||||||
|
|
||||||
/DISCARD/ :
|
|
||||||
{
|
|
||||||
*(.bss.startup.0)
|
|
||||||
}
|
|
||||||
|
|
||||||
.ARM.extab : {*(.ARM.extab* .gnu.linkonce.armextab.*)} > flash
|
|
||||||
|
|
||||||
.ARM.exidx : {
|
|
||||||
PROVIDE(__exidx_start = .);
|
|
||||||
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
|
||||||
PROVIDE(__exidx_end = .);
|
|
||||||
} > flash =0xffffffff
|
|
||||||
|
|
||||||
.eh_frame_hdr : {*(.eh_frame_hdr)} > flash
|
|
||||||
|
|
||||||
.eh_frame : ONLY_IF_RO {*(.eh_frame)} > flash
|
|
||||||
|
|
||||||
.textalign : ONLY_IF_RO { . = ALIGN(8); } > flash
|
|
||||||
|
|
||||||
_etext = .;
|
|
||||||
_textdata = _etext;
|
|
||||||
|
|
||||||
.process_stack :
|
|
||||||
{
|
|
||||||
. = ALIGN(8);
|
|
||||||
__process3_stack_base__ = .;
|
|
||||||
. += __process3_stack_size__;
|
|
||||||
. = ALIGN(8);
|
|
||||||
__process3_stack_end__ = .;
|
|
||||||
__process2_stack_base__ = .;
|
|
||||||
. += __process2_stack_size__;
|
|
||||||
. = ALIGN(8);
|
|
||||||
__process2_stack_end__ = .;
|
|
||||||
__process1_stack_base__ = .;
|
|
||||||
. += __process1_stack_size__;
|
|
||||||
. = ALIGN(8);
|
|
||||||
__process1_stack_end__ = .;
|
|
||||||
__process0_stack_base__ = .;
|
|
||||||
. += __process0_stack_size__;
|
|
||||||
. = ALIGN(8);
|
|
||||||
__process0_stack_end__ = .;
|
|
||||||
} > ram
|
|
||||||
|
|
||||||
.main_stack :
|
|
||||||
{
|
|
||||||
. = ALIGN(8);
|
|
||||||
__main_stack_base__ = .;
|
|
||||||
. += __main_stack_size__;
|
|
||||||
. = ALIGN(8);
|
|
||||||
__main_stack_end__ = .;
|
|
||||||
} > ram
|
|
||||||
|
|
||||||
.data :
|
|
||||||
{
|
|
||||||
. = ALIGN(4);
|
|
||||||
PROVIDE(_data = .);
|
|
||||||
*(.data)
|
|
||||||
. = ALIGN(4);
|
|
||||||
*(.data.*)
|
|
||||||
. = ALIGN(4);
|
|
||||||
*(.ramtext)
|
|
||||||
. = ALIGN(4);
|
|
||||||
PROVIDE(_edata = .);
|
|
||||||
} > ram AT > flash =0xffffffff
|
|
||||||
|
|
||||||
.bss :
|
|
||||||
{
|
|
||||||
. = ALIGN(4);
|
|
||||||
PROVIDE(_bss_start = .);
|
|
||||||
*(.bss)
|
|
||||||
. = ALIGN(4);
|
|
||||||
*(.bss.*)
|
|
||||||
. = ALIGN(4);
|
|
||||||
*(COMMON)
|
|
||||||
. = ALIGN(512);
|
|
||||||
__usb_bdt__ = .;
|
|
||||||
. += 512;
|
|
||||||
PROVIDE(_bss_end = .);
|
|
||||||
} > ram
|
|
||||||
|
|
||||||
PROVIDE(end = .);
|
|
||||||
_end = .;
|
|
||||||
}
|
|
||||||
|
|
||||||
__heap_base__ = _end;
|
|
||||||
__heap_end__ = __ram_end__;
|
|
@ -1,99 +0,0 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <chopstx.h>
|
|
||||||
#include <mcu/mkl27z.h>
|
|
||||||
|
|
||||||
struct TPM {
|
|
||||||
volatile uint32_t SC;
|
|
||||||
volatile uint32_t CNT;
|
|
||||||
volatile uint32_t MOD;
|
|
||||||
volatile uint32_t C0SC;
|
|
||||||
volatile uint32_t C0V;
|
|
||||||
volatile uint32_t C1SC;
|
|
||||||
volatile uint32_t C1V;
|
|
||||||
uint32_t rsvd0[13];
|
|
||||||
volatile uint32_t STATUS;
|
|
||||||
uint32_t rsvd1[7];
|
|
||||||
volatile uint32_t POL;
|
|
||||||
uint32_t rsvd2[4];
|
|
||||||
volatile uint32_t CONF;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct TPM *const TPM1 = (struct TPM *)0x40039000;
|
|
||||||
|
|
||||||
static chopstx_intr_t tpm1_intr;
|
|
||||||
#define INTR_REQ_TPM1 18
|
|
||||||
|
|
||||||
static void
|
|
||||||
gpio_assert_low (void)
|
|
||||||
{
|
|
||||||
/* Assert LOW. */
|
|
||||||
PORTB->PCR1 = (1<<8) /* GPIO */
|
|
||||||
| (0<<6) /* DriveStrengthEnable=0 */
|
|
||||||
| (0<<4) /* PassiveFilterEnable=0 */
|
|
||||||
| (1<<2) /* SlewRateEnable = slow */
|
|
||||||
| (0<<1) /* pull enable = 0 */
|
|
||||||
| (0<<0) /* pull up select= 0 */
|
|
||||||
;
|
|
||||||
|
|
||||||
GPIOB->PCOR = (1 << 1); /* PTB1: Clear: Output 0 */
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t
|
|
||||||
touch_get (void)
|
|
||||||
{
|
|
||||||
chopstx_prio_t prio_old;
|
|
||||||
uint16_t v;
|
|
||||||
|
|
||||||
prio_old = chopstx_setpriority (CHOPSTX_PRIO_INHIBIT_PREEMPTION);
|
|
||||||
/*
|
|
||||||
* Start the timer's counter.
|
|
||||||
* TOF clear, TOIE=1, CPWMS=0, CMOD=1, PS=011.
|
|
||||||
*/
|
|
||||||
TPM1->SC = 0xcb;
|
|
||||||
|
|
||||||
/* Let the register to pull it up. */
|
|
||||||
PORTB->PCR1 = (3<<8) /* TPM1_CH1 */
|
|
||||||
| (0<<6) /* DriveStrengthEnable=0 */
|
|
||||||
| (0<<4) /* PassiveFilterEnable=0 */
|
|
||||||
| (1<<2) /* SlewRateEnable = slow */
|
|
||||||
| (0<<1) /* pull enable = 0 */
|
|
||||||
| (0<<0) /* pullup select= 0 */
|
|
||||||
;
|
|
||||||
|
|
||||||
chopstx_setpriority (prio_old);
|
|
||||||
|
|
||||||
chopstx_intr_wait (&tpm1_intr);
|
|
||||||
gpio_assert_low ();
|
|
||||||
|
|
||||||
v = TPM1->C1V;
|
|
||||||
|
|
||||||
/* Clear overflow and CH1 capture. */
|
|
||||||
TPM1->STATUS = 0x102;
|
|
||||||
/* Stop the timer. */
|
|
||||||
TPM1->SC = 0;
|
|
||||||
TPM1->CNT = 0xffff; /* Writing causes reset of the counter. */
|
|
||||||
|
|
||||||
chopstx_intr_done (&tpm1_intr);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
touch_init (void)
|
|
||||||
{
|
|
||||||
chopstx_claim_irq (&tpm1_intr, INTR_REQ_TPM1);
|
|
||||||
|
|
||||||
/* Input capture mode: MSB = 0, MSA = 0 */
|
|
||||||
/* Rising edge: ELSB=0 ELSA=1 */
|
|
||||||
TPM1->C1SC = 0x84;
|
|
||||||
TPM1->POL=0;
|
|
||||||
|
|
||||||
/* No trigger. */
|
|
||||||
/* Stop on overflow: CSOO=1 */
|
|
||||||
/* Run the timer in the debug mode */
|
|
||||||
TPM1->CONF = 0x000200c0;
|
|
||||||
|
|
||||||
TPM1->CNT = 0xffff; /* Writing causes reset of the counter. */
|
|
||||||
gpio_assert_low ();
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
#define LINEBUFSIZE 128
|
|
||||||
|
|
||||||
struct tty;
|
|
||||||
|
|
||||||
struct tty *tty_open (void);
|
|
||||||
void tty_wait_configured (struct tty *tty);
|
|
||||||
void tty_wait_connection (struct tty *tty);
|
|
||||||
int tty_send (struct tty *tty, const char *buf, int count);
|
|
||||||
int tty_recv (struct tty *tty, char *buf, uint32_t *timeout);
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user