summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian König <chrissi@zweiundvierzig.(none)>2010-05-16 21:26:27 +0200
committerChristian König <chrissi@zweiundvierzig.(none)>2010-05-16 21:26:27 +0200
commit63d5930e80b3949f7200f398d592c07cd87f0618 (patch)
tree19ab60aeb6263f4c2bfab3c81ef5df270f0606e0
Initial commit
-rw-r--r--.gdbinit4
-rw-r--r--COPYING674
-rw-r--r--cmd/Makefile16
-rw-r--r--cmd/cec.c249
-rw-r--r--hw/cec.brdbin0 -> 18819 bytes
-rw-r--r--hw/cec.odsbin0 -> 22372 bytes
-rw-r--r--hw/cec.pro25
-rw-r--r--hw/cec.schbin0 -> 98934 bytes
-rw-r--r--lib/Makefile20
-rw-r--r--lib/cec.h567
-rw-r--r--lib/commands.c120
-rw-r--r--lib/device.c102
-rw-r--r--lib/dumper.c435
-rw-r--r--lib/msp430.c152
-rw-r--r--msp430/.gdbinit4
-rw-r--r--msp430/Makefile36
-rw-r--r--msp430/buffer.h103
-rw-r--r--msp430/cec.h220
-rw-r--r--msp430/cec_pin.h82
-rw-r--r--msp430/cec_state.h41
-rw-r--r--msp430/cec_timing.h113
-rw-r--r--msp430/i2c.h369
-rw-r--r--msp430/main.c52
23 files changed, 3384 insertions, 0 deletions
diff --git a/.gdbinit b/.gdbinit
new file mode 100644
index 0000000..1a44018
--- /dev/null
+++ b/.gdbinit
@@ -0,0 +1,4 @@
+target remote localhost:2000
+monitor erase all
+load
+monitor reset
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..94a9ed0
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,674 @@
+ 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>.
diff --git a/cmd/Makefile b/cmd/Makefile
new file mode 100644
index 0000000..de0d4d8
--- /dev/null
+++ b/cmd/Makefile
@@ -0,0 +1,16 @@
+NAME = cec
+OBJECTS = cec.o
+HEADERS = ../lib/cec.h
+
+CFLAGS = -Wall -g -I ../lib -L ../lib
+LDFLAGS = -l cec
+
+.PHONY: all
+
+all: ${NAME}
+
+${NAME}: ${OBJECTS}
+ $(CC) ${CFLAGS} ${OBJECTS} ${LDFLAGS} -o ${NAME}
+
+clean:
+ rm -f ${NAME} ${OBJECTS}
diff --git a/cmd/cec.c b/cmd/cec.c
new file mode 100644
index 0000000..e68a944
--- /dev/null
+++ b/cmd/cec.c
@@ -0,0 +1,249 @@
+/*
+ * Copyright
+ *
+ * Copyright (C) 2009-2010 Christian König (deathsimple@vodafone.de)
+ *
+ * License
+ *
+ * This program is free software; you can redistribute and/or modify
+ * program under the terms of GNU General Public license either version 3
+ * of the License, or (at your option) any later version.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <cec.h>
+
+struct CEC_Device device;
+
+static const char* hw_device = "/dev/i2c-1";
+
+const char* usage =
+"Usage: %s [commands]\n"
+"-msp430 <device> : use device as i2c device\n"
+" -phys <?.?.?.?> : use physical addr ?.?.?.?\n"
+" -src <addr> : use specified logical source addr\n"
+" -addr <device type> : run logical addr allocation algo\n"
+" -ping <addr> : ping addr\n"
+" -standby <addr> : put device into standby mode\n"
+" -abort <addr> : send abort command and wait for response\n"
+" -audio-status <addr> : send 'give audio status' and wait for response\n"
+" -audio-mode <on/off> : set system audio mode\n"
+" -scan : scan for active devices\n"
+" -dump : dump received cec packets\n"
+" -active : send Active Source packet\n"
+" -decode <byte1> ... : decode cec packet\n"
+" -button <addr> <command> <duration> : simulate a button press\n"
+"\n\n";
+
+static void debug(enum CEC_Debug reason, struct CEC_Device* device, struct CEC_Packet* packet)
+{
+ switch(reason) {
+ case CEC_RX_Packet:
+ fprintf(stderr, "received ");
+ break;
+
+ case CEC_TX_Sucess:
+ fprintf(stderr, "succeeded ");
+ break;
+
+ case CEC_TX_Failure:
+ fprintf(stderr, "failed ");
+ break;
+ }
+ CEC_Dump_Packet(stderr, packet);
+ fprintf(stderr, "\n");
+}
+
+void print_help(const char* progname, const char* message)
+{
+ if (message != NULL) fprintf(stderr, "%s\n", message);
+ fprintf(stderr, usage, progname);
+}
+
+uint8_t parse_addr(int* i, int argc, const char* argv[])
+{
+ if (++(*i) == argc || !strncmp("-", argv[*i], 1)) {
+ print_help(argv[0], "can't parse addr");
+ exit(1);
+ }
+ return strtol(argv[*i], NULL, 0);
+}
+
+uint8_t parse_byte(int* i, int argc, const char* argv[])
+{
+ if (++(*i) == argc || !strncmp("-", argv[*i], 1)) {
+ print_help(argv[0], "can't parse byte");
+ exit(1);
+ }
+ return strtol(argv[*i], NULL, 0);
+}
+
+int parse_int(int* i, int argc, const char* argv[])
+{
+ if (++(*i) == argc || !strncmp("-", argv[*i], 1)) {
+ print_help(argv[0], "can't parse int");
+ exit(1);
+ }
+ return strtol(argv[*i], NULL, 0);
+}
+
+enum CEC_Device_Type parse_device_type(int* i, int argc, const char* argv[])
+{
+ if (++(*i) != argc) {
+ if (!strncasecmp("TV", argv[*i], 3)) {
+ return CEC_TV;
+ } else if (!strncasecmp("Recorder", argv[*i], 10)) {
+ return CEC_Recording_Device;
+
+ } else if (!strncasecmp("Tuner", argv[*i], 6)) {
+ return CEC_Tuner;
+
+ } else if (!strncasecmp("Player", argv[*i], 9)) {
+ return CEC_Playback_Device;
+
+ } else if (!strncasecmp("Audio", argv[*i], 6)) {
+ return CEC_Audio_System;
+ }
+ }
+ print_help(argv[0], "can't parse device type");
+ exit(1);
+}
+
+struct CEC_Physical_Address parse_physical(int* i, int argc, const char* argv[])
+{
+ if (++(*i) == argc || !strncmp("-", argv[*i], 1)) {
+ print_help(argv[0], "can't parse physical address");
+ exit(1);
+ }
+
+ int a,b,c,d;
+ if(sscanf(argv[*i], "%i.%i.%i.%i", &a, &b, &c, &d) != 4) {
+ print_help(argv[0], "can't parse physical address");
+ exit(1);
+ }
+
+ struct CEC_Physical_Address addr = {
+ .a = a,
+ .b = b,
+ .c = c,
+ .d = d
+ };
+ return addr;
+}
+
+int parse_onoff(int* i, int argc, const char* argv[])
+{
+ if (++(*i) != argc) {
+ if (!strncasecmp("on", argv[*i], 3)) {
+ return 1;
+ } else if (!strncasecmp("off", argv[*i], 4)) {
+ return 0;
+ }
+ }
+ print_help(argv[0], "can't parse on/off");
+ exit(1);
+}
+
+void dump()
+{
+ while(1) {
+ usleep(10000);
+ CEC_Receive(&device);
+ }
+}
+
+void init_device()
+{
+ CEC_Init_Device(&device);
+ device.hardware = MSP430_Open_Hardware(hw_device);
+ device.func_debug = debug;
+}
+
+int main(int argc, const char* argv[])
+{
+ int i;
+ char addr;
+
+ if(argc < 2) {
+ print_help(argv[0], "Missing argument: please provide a command");
+ return 1;
+ }
+
+ init_device();
+
+ for(i=1; i<argc; i++) {
+
+ if (!strncmp("-msp430", argv[i], 8)) {
+ hw_device = argv[++i];
+
+ } else if (!strncmp("-phys", argv[i], 6)) {
+ device.physical_address = parse_physical(&i, argc, argv);
+
+ } else if (!strncmp("-src", argv[i], 5)) {
+ device.logical_address = parse_addr(&i, argc, argv);
+ CEC_TX_Ping(&device, device.logical_address);
+
+ } else if (!strncmp("-ping", argv[i], 6)) {
+ CEC_TX_Ping(&device, parse_addr(&i, argc, argv));
+
+ } else if (!strncmp("-standby", argv[i], 9)) {
+ CEC_TX_Standby(&device, parse_addr(&i, argc, argv));
+
+ } else if (!strncmp("-abort", argv[i], 9)) {
+ CEC_TX_Abort(&device, parse_addr(&i, argc, argv));
+ dump();
+
+ } else if (!strncmp("-audio-status", argv[i], 14)) {
+ CEC_TX_Give_Audio_Status(&device, parse_addr(&i, argc, argv));
+ dump();
+
+ } else if (!strncmp("-audio-mode", argv[i], 12)) {
+ CEC_TX_Set_System_Audio_Mode(&device, parse_onoff(&i, argc, argv));
+
+ } else if (!strncmp("-scan", argv[i], 6)) {
+ for(addr=0x0; addr<=0xF; addr++) {
+ CEC_TX_Ping(&device, addr);
+ }
+
+ } else if (!strncmp("-dump", argv[i], 6)) {
+ dump();
+
+ } else if (!strncmp("-active", argv[i], 8)) {
+ CEC_TX_Active_Source(&device);
+
+ } else if (!strncmp("-decode", argv[i], 8)) {
+ struct CEC_Packet p;
+ uint8_t* byte = ((uint8_t*)&p)+1;
+
+ for(p.length = 0; p.length<=16; p.length++) {
+ if (++i == argc || !strncmp("-", argv[i], 1))
+ break;
+ *byte++ = strtol(argv[i], NULL, 0);
+ }
+
+ CEC_Dump_Packet(stderr, &p);
+
+ } else if (!strncmp("-button", argv[i], 8)) {
+ addr = parse_addr(&i, argc, argv);
+ uint8_t command = parse_byte(&i, argc, argv);
+ int duration = parse_int(&i, argc, argv);
+
+ CEC_TX_User_Control_Pressed(&device, addr, command);
+ usleep(duration * 1000);
+ CEC_TX_User_Control_Released(&device, addr);
+
+
+ } else if (!strncmp("-addr", argv[i], 6)) {
+ CEC_Alloc_Addr(&device, parse_device_type(&i, argc, argv));
+
+ } else {
+ print_help(argv[0], "Unknown command");
+ }
+ }
+ return 0;
+}
diff --git a/hw/cec.brd b/hw/cec.brd
new file mode 100644
index 0000000..1db9527
--- /dev/null
+++ b/hw/cec.brd
Binary files differ
diff --git a/hw/cec.ods b/hw/cec.ods
new file mode 100644
index 0000000..5c60e69
--- /dev/null
+++ b/hw/cec.ods
Binary files differ
diff --git a/hw/cec.pro b/hw/cec.pro
new file mode 100644
index 0000000..67e54d0
--- /dev/null
+++ b/hw/cec.pro
@@ -0,0 +1,25 @@
+EAGLE AutoRouter Statistics:
+
+Job : /home/chrissi/Dokumente/cec/cec.brd
+
+Start at : 00:37:19 (12.03.10)
+End at : 00:37:52 (12.03.10)
+Elapsed time : 00:00:33
+
+Signals : 24 RoutingGrid: 1.9685 mil Layers: 2
+Connections : 35 predefined: 18 ( 19 Vias )
+
+Router memory : 2972228
+
+Passname : Route Optimize1 Optimize2 Optimize3 Optimize4
+
+Time per pass : 00:00:07 00:00:06 00:00:07 00:00:06 00:00:07
+Number of Ripups : 1 0 0 0 0
+max. Level : 1 0 0 0 0
+max. Total : 1 0 0 0 0
+
+Routed : 17 17 17 17 17
+Vias : 28 26 20 18 17
+Resolution : 100.0 % 100.0 % 100.0 % 100.0 % 100.0 %
+
+Final : 100.0% beendet
diff --git a/hw/cec.sch b/hw/cec.sch
new file mode 100644
index 0000000..d4cbd32
--- /dev/null
+++ b/hw/cec.sch
Binary files differ
diff --git a/lib/Makefile b/lib/Makefile
new file mode 100644
index 0000000..792453e
--- /dev/null
+++ b/lib/Makefile
@@ -0,0 +1,20 @@
+NAME = libcec
+OBJECTS = device.o commands.o dumper.o msp430.o
+HEADERS = cec.h
+
+CFLAGS = -Wall -g
+
+.PHONY: all
+
+all: ${NAME}.a
+
+${NAME}.a: ${OBJECTS}
+ $(AR) cr ${NAME}.a ${OBJECTS}
+
+clean:
+ rm -f ${NAME}.a ${OBJECTS}
+
+device.o: device.c ${HEADERS}
+commands.o: commands.c ${HEADERS}
+dumper.o: dumper.c ${HEADERS}
+msp430.o: msp430.c ${HEADERS}
diff --git a/lib/cec.h b/lib/cec.h
new file mode 100644
index 0000000..7184ebb
--- /dev/null
+++ b/lib/cec.h
@@ -0,0 +1,567 @@
+/*
+ * Copyright
+ *
+ * Copyright (C) 2009-2010 Christian König (deathsimple@vodafone.de)
+ *
+ * License
+ *
+ * This program is free software; you can redistribute and/or modify
+ * program under the terms of GNU General Public license either version 3
+ * of the License, or (at your option) any later version.
+ *
+ */
+
+#ifndef _CEC_H_
+#define _CEC_H_
+
+#include <stdint.h>
+#include <stdio.h>
+
+#pragma pack(push,1)
+
+enum CEC_Opcode
+{
+ CEC_Feature_Abort = 0x00,
+ CEC_Image_View_On = 0x04,
+ CEC_Tuner_Step_Increment = 0x05,
+ CEC_Tuner_Step_Decrement = 0x06,
+ CEC_Tuner_Device_Status = 0x07,
+ CEC_Give_Tuner_Device_Status = 0x08,
+ CEC_Record_On = 0x09,
+ CEC_Record_Status = 0x0A,
+ CEC_Record_Off = 0x0B,
+ CEC_Text_View_On = 0x0D,
+ CEC_Record_TV_Screen = 0x0F,
+ CEC_Give_Deck_Status = 0x1A,
+ CEC_Deck_Status = 0x1B,
+ CEC_Set_Menu_Language = 0x32,
+ CEC_Clear_Analogue_Timer = 0x33,
+ CEC_Set_Analogue_Timer = 0x34,
+ CEC_Timer_Status = 0x35,
+ CEC_Standby = 0x36,
+ CEC_Play = 0x41,
+ CEC_Deck_Control = 0x42,
+ CEC_Timer_Cleared_Status = 0x43,
+ CEC_User_Control_Pressed = 0x44,
+ CEC_User_Control_Released = 0x45,
+ CEC_Give_OSD_Name = 0x46,
+ CEC_Set_OSD_Name = 0x47,
+ CEC_Set_OSD_String = 0x64,
+ CEC_Set_Timer_Program = 0x67,
+ CEC_System_Audio_Mode_Request = 0x70,
+ CEC_Give_Audio_Status = 0x71,
+ CEC_Set_System_Audio_Mode = 0x72,
+ CEC_Report_Audio_Status = 0x7A,
+ CEC_System_Audio_Mode_Status = 0x7E,
+ CEC_Give_System_Audio_Mode_Status = 0x7D,
+ CEC_Routing_Change = 0x80,
+ CEC_Routing_Information = 0x81,
+ CEC_Active_Source = 0x82,
+ CEC_Give_Physical_Address = 0x83,
+ CEC_Report_Physical_Address = 0x84,
+ CEC_Request_Active_Source = 0x85,
+ CEC_Set_Stream_Path = 0x86,
+ CEC_Device_Vendor_ID = 0x87,
+ CEC_Vendor_Command = 0x89,
+ CEC_Vendor_Remote_Button_Down = 0x8A,
+ CEC_Vendor_Remote_Button_Up = 0x8B,
+ CEC_Give_Device_Vendor_ID = 0x8C,
+ CEC_Menu_Request = 0x8D,
+ CEC_Menu_Status = 0x8E,
+ CEC_Give_Device_Power_Status = 0x8F,
+ CEC_Report_Power_Status = 0x90,
+ CEC_Get_Menu_Language = 0x91,
+ CEC_Select_Analogue_Service = 0x92,
+ CEC_Select_Digital_Service = 0x93,
+ CEC_Set_Digital_Timer = 0x97,
+ CEC_Clear_Digital_Timer = 0x99,
+ CEC_Set_Audio_Rate = 0x9A,
+ CEC_Inactive_Source = 0x9D,
+ CEC_Version = 0x9E,
+ CEC_Get_Version = 0x9F,
+ CEC_Vendor_Command_With_ID = 0xA0,
+ CEC_Clear_External_Timer = 0xA1,
+ CEC_Set_External_Timer = 0xA2,
+ CEC_Abort = 0xFF
+};
+
+enum CEC_Version
+{
+ CEC_Version_1_1 = 0x00,
+ CEC_Version_1_2 = 0x01,
+ CEC_Version_1_2a = 0x02,
+ CEC_Version_1_3 = 0x03,
+ CEC_Version_1_3a = 0x04
+};
+
+enum CEC_Device_Type
+{
+ CEC_TV = 0,
+ CEC_Recording_Device = 1,
+ CEC_Tuner = 3,
+ CEC_Playback_Device = 4,
+ CEC_Audio_System = 5
+};
+
+enum CEC_Abort_Reason
+{
+ CEC_Unrecognized_opcode = 0,
+ CEC_Not_in_correct_mode_to_respond = 1,
+ CEC_Cannot_provide_source = 2,
+ CEC_Invalid_operand = 3,
+ CEC_Refused = 4
+};
+
+enum CEC_Analogue_Broadcast_Type
+{
+ CEC_Cable = 0x00,
+ CEC_Satellite = 0x01,
+ CEC_Terrestrial = 0x02
+};
+
+enum CEC_Audio_Rate
+{
+ CEC_Rate_Control_Off = 0,
+ CEC_Wide_Standard_Rate = 1,
+ CEC_Wide_Fast_Rate = 2,
+ CEC_Wide_Slow_Rate = 3,
+ CEC_Narrow_Standard_Rate = 4,
+ CEC_Narrow_Fast_Rate = 5,
+ CEC_Narrow_Slow_Rate = 6
+};
+
+enum CEC_Record_Source_Info
+{
+ CEC_Recording_currently_selected = 0x01,
+ CEC_Recording_Digital_Service = 0x02,
+ CEC_Recording_Analogue_Service = 0x03,
+ CEC_Recording_External_input = 0x04,
+ CEC_No_recording_unable_to_record_Digital_Service = 0x05,
+ CEC_No_recording_unable_to_record_Analogue_Service = 0x06,
+ CEC_No_recording_unable_to_select_required_service = 0x07,
+ CEC_No_recording_invalid_External_plug_number = 0x09,
+ CEC_No_recording_invalid_External_Physical_Address = 0x0A,
+ CEC_No_recording_CA_system_not_supported = 0x0B,
+ CEC_No_recording_No_or_Insufficient_CA_Entitlements = 0x0C,
+ CEC_No_recording_Not_allowed_to_copy_source = 0x0D,
+ CEC_No_recording_No_further_copies_allowed = 0x0E,
+ CEC_No_recording_no_media = 0x10,
+ CEC_No_recording_playing = 0x11,
+ CEC_No_recording_already_recording = 0x12,
+ CEC_No_recording_media_protected = 0x13,
+ CEC_No_recording_no_source_signal = 0x14,
+ CEC_No_recording_media_problem = 0x15,
+ CEC_No_recording_not_enough_space_available = 0x16,
+ CEC_No_recording_Parental_Lock_On = 0x17,
+ CEC_Recording_terminated_normally = 0x1A,
+ CEC_Recording_has_already_terminated = 0x1B,
+ CEC_No_recording_other_reason = 0x1F
+};
+
+enum CEC_Recording_Sequence
+{
+ CEC_Sunday = 0x01,
+ CEC_Monday = 0x02,
+ CEC_Tuesday = 0x04,
+ CEC_Wednesday = 0x08,
+ CEC_Thursday = 0x10,
+ CEC_Friday = 0x20,
+ CEC_Saturday = 0x40,
+ CEC_Once_only = 0x00
+};
+
+enum CEC_Broadcast_System
+{
+ CEC_PAL_BG = 0,
+ CEC_SECAM_L_ = 1,
+ CEC_PAL_M = 2,
+ CEC_NTSC_M = 3,
+ CEC_PAL_I = 4,
+ CEC_SECAM_DK = 5,
+ CEC_SECAM_BG = 6,
+ CEC_SECAM_L = 7,
+ CEC_PAL_DK = 8,
+ CEC_Other_System = 31
+};
+
+enum CEC_Deck_Control_Mode
+{
+ CEC_Cntrl_Wind = 1,
+ CEC_Cntrl_Rewind = 2,
+ CEC_Cntrl_Stop = 3,
+ CEC_Cntrl_Eject = 4
+};
+
+enum CEC_Deck_Info
+{
+ CEC_Info_Play = 0x11,
+ CEC_Info_Record = 0x12,
+ CEC_Info_Play_Reverse = 0x13,
+ CEC_Info_Still = 0x14,
+ CEC_Info_Slow = 0x15,
+ CEC_Info_Slow_Reverse = 0x16,
+ CEC_Info_Fast_Forward = 0x17,
+ CEC_Info_Fast_Reverse = 0x18,
+ CEC_Info_No_Media = 0x19,
+ CEC_Info_Stop = 0x1A,
+ CEC_Info_Wind = 0x1B,
+ CEC_Info_Rewind = 0x1C,
+ CEC_Info_Index_Search_Forward = 0x1D,
+ CEC_Info_Index_Search_Reverse = 0x1E,
+ CEC_Info_Other_Status = 0x1F
+};
+
+enum CEC_Timer_Cleared_Status_Data
+{
+ CEC_Timer_not_cleared_recording = 0x00,
+ CEC_Timer_not_cleared_no_matching = 0x01,
+ CEC_Timer_not_cleared_no_info_available = 0x02,
+ CEC_Timer_cleared = 0x80
+};
+
+enum CEC_Status_Request
+{
+ CEC_Status_Request_On = 1,
+ CEC_Status_Request_Off = 2,
+ CEC_Status_Request_Once = 3
+};
+
+enum CEC_Digital_Broadcast_System
+{
+ CEC_ARIB_generic = 0x00,
+ CEC_ATSC_generic = 0x01,
+ CEC_DVB_generic = 0x02,
+ CEC_ARIB_BS = 0x08,
+ CEC_ARIB_CS = 0x09,
+ CEC_ARIB_T = 0x0A,
+ CEC_ATSC_Cable = 0x10,
+ CEC_ATSC_Satellite = 0x11,
+ CEC_ATSC_Terrestrial = 0x12,
+ CEC_DVB_C = 0x18,
+ CEC_DVB_S = 0x19,
+ CEC_DVB_S2 = 0x1A,
+ CEC_DVB_T = 0x1B
+};
+
+enum CEC_Display_Control
+{
+ CEC_Display_for_default_time = 0x00,
+ CEC_Display_until_cleared = 0x40,
+ CEC_Clear_previous_message = 0x80
+};
+
+enum CEC_UI_Commands
+{
+ CEC_UI_Select = 0x00,
+ CEC_UI_Up = 0x01,
+ CEC_UI_Down = 0x02,
+ CEC_UI_Left = 0x03,
+ CEC_UI_Right = 0x04,
+ CEC_UI_Right_Up = 0x05,
+ CEC_UI_Right_Down = 0x06,
+ CEC_UI_Left_Up = 0x07,
+ CEC_UI_Left_Down = 0x08,
+ CEC_UI_Root_Menu = 0x09,
+ CEC_UI_Setup_Menu = 0x0A,
+ CEC_UI_Contents_Menu = 0x0B,
+ CEC_UI_Favorite_Menu = 0x0C,
+ CEC_UI_Exit = 0x0D,
+ CEC_UI_0 = 0x20,
+ CEC_UI_1 = 0x21,
+ CEC_UI_2 = 0x22,
+ CEC_UI_3 = 0x23,
+ CEC_UI_4 = 0x24,
+ CEC_UI_5 = 0x25,
+ CEC_UI_6 = 0x26,
+ CEC_UI_7 = 0x27,
+ CEC_UI_8 = 0x28,
+ CEC_UI_9 = 0x29,
+ CEC_UI_Dot = 0x2A,
+ CEC_UI_Enter = 0x2B,
+ CEC_UI_Clear = 0x2C,
+ CEC_UI_Next_Favorite = 0x2F,
+ CEC_UI_Channel_Up = 0x30,
+ CEC_UI_Channel_Down = 0x31,
+ CEC_UI_Previous_Channel = 0x32,
+ CEC_UI_Sound_Select = 0x33,
+ CEC_UI_Input_Select = 0x34,
+ CEC_UI_Display_Information = 0x35,
+ CEC_UI_Help = 0x36,
+ CEC_UI_Page_Up = 0x37,
+ CEC_UI_Page_Down = 0x38,
+ CEC_UI_Power = 0x40,
+ CEC_UI_Volume_Up = 0x41,
+ CEC_UI_Volume_Down = 0x42,
+ CEC_UI_Mute = 0x43,
+ CEC_UI_Play = 0x44,
+ CEC_UI_Stop = 0x45,
+ CEC_UI_Pause = 0x46,
+ CEC_UI_Record = 0x47,
+ CEC_UI_Rewind = 0x48,
+ CEC_UI_Fast_forward = 0x49,
+ CEC_UI_Eject = 0x4A,
+ CEC_UI_Forward = 0x4B,
+ CEC_UI_Backward = 0x4C,
+ CEC_UI_Stop_Record = 0x4D,
+ CEC_UI_Pause_Record = 0x4E,
+ CEC_UI_Angle = 0x50,
+ CEC_UI_Sub_picture = 0x51,
+ CEC_UI_Video_on_Demand = 0x52,
+ CEC_UI_Electronic_Program_Guide = 0x53,
+ CEC_UI_Timer_Programming = 0x54,
+ CEC_UI_Initial_Configuration = 0x55,
+ CEC_UI_Play_Function = 0x60,
+ CEC_UI_Pause_Play_Function = 0x61,
+ CEC_UI_Record_Function = 0x62,
+ CEC_UI_Pause_Record_Function = 0x63,
+ CEC_UI_Stop_Function = 0x64,
+ CEC_UI_Mute_Function = 0x65,
+ CEC_UI_Restore_Volume_Function = 0x66,
+ CEC_UI_Tune_Function = 0x67,
+ CEC_UI_Select_Media_Function = 0x68,
+ CEC_UI_Select_AV_Input_Function = 0x69,
+ CEC_UI_Select_Audio_Input = 0x6A,
+ CEC_UI_Power_Toggle_Function = 0x6B,
+ CEC_UI_Power_Off_Function = 0x6C,
+ CEC_UI_Power_On_Function = 0x6D,
+ CEC_UI_F1 = 0x71,
+ CEC_UI_F2 = 0x72,
+ CEC_UI_F3 = 0x73,
+ CEC_UI_F4 = 0x74,
+ CEC_UI_F5 = 0x75,
+ CEC_UI_Data = 0x76,
+};
+
+enum CEC_Power_Status
+{
+ CEC_Power_Status_On = 0x00,
+ CEC_Power_Status_Standby = 0x01,
+ CEC_Transition_Standby_to_On = 0x02,
+ CEC_Transition_On_to_Standby = 0x03
+};
+
+struct CEC_Audio_Status
+{
+ uint8_t volume_status:7;
+ uint8_t mute_status:1;
+};
+
+struct CEC_Physical_Address
+{
+ uint8_t b:4;
+ uint8_t a:4;
+ uint8_t d:4;
+ uint8_t c:4;
+};
+
+struct CEC_Record_Source
+{
+};
+
+struct CEC_Time
+{
+ uint8_t hour;
+ uint8_t minute;
+};
+
+struct CEC_Digital_SI
+{
+ uint8_t digital_broadcast_system:7;
+ uint8_t service_identification_method:1;
+ union
+ {
+ struct
+ {
+ uint16_t transport_stream_id;
+ uint16_t service_id;
+ uint16_t original_network_id;
+ } arib;
+ struct
+ {
+ uint16_t transport_stream_id;
+ uint16_t program_number;
+ } atsc;
+ struct
+ {
+ uint16_t transport_stream_id;
+ uint16_t service_id;
+ uint16_t original_network_id;
+ } dvb;
+ uint16_t channel_identifier;
+ };
+};
+
+struct CEC_Analogue_SI
+{
+ uint8_t analogue_broadcast_type;
+ uint16_t analogue_frequency;
+ uint8_t broadcast_system;
+};
+
+struct CEC_External_SI
+{
+ uint8_t external_source_specifier;
+ union
+ {
+ uint8_t external_plug;
+ struct CEC_Physical_Address external_physical_address;
+ };
+};
+
+struct CEC_Tuner_Device_Info
+{
+ uint8_t tuner_display_info:7;
+ uint8_t recording_flag:1;
+ union
+ {
+ struct CEC_Analogue_SI analogue_service;
+ struct CEC_Digital_SI digital_service;
+ };
+};
+
+struct CEC_Timer
+{
+ uint8_t day_of_month;
+ uint8_t month_of_year;
+ struct CEC_Time start_time;
+ struct CEC_Time duration;
+ uint8_t recording_sequence;
+};
+
+struct CEC_Timer_Status_Data
+{
+ uint8_t info:4;
+ uint8_t programmed:1;
+ uint8_t media_info:2;
+ uint8_t timer_overlap_warning:1;
+ struct CEC_Time duration;
+};
+
+struct CEC_Packet
+{
+ uint8_t length;
+ uint8_t dst:4;
+ uint8_t src:4;
+ uint8_t opcode;
+ union
+ {
+ uint8_t raw_data[14];
+ uint8_t record_status;
+ uint8_t timer_cleared_status_data;
+ uint8_t version;
+ uint8_t deck_control_mode;
+ uint8_t deck_info;
+ uint8_t status_request;
+ uint8_t play_mode;
+ uint8_t menu_request_type;
+ uint8_t menu_status;
+ uint8_t ui_command;
+ uint8_t power_status;
+ uint8_t system_audio_mode_status;
+ uint8_t audio_rate;
+
+ char string[14];
+ char language[3];
+
+ struct
+ {
+ uint8_t vendor_id[3];
+ uint8_t vendor_specific_data[11];
+ };
+
+ struct
+ {
+ uint8_t display_control;
+ char display_string[13];
+ };
+
+ struct
+ {
+ struct CEC_Timer timer;
+ union
+ {
+ struct CEC_Digital_SI digital_timer;
+ struct CEC_Analogue_SI analogue_timer;
+ struct CEC_External_SI external_timer;
+ };
+ };
+
+ struct
+ {
+ struct CEC_Physical_Address physical_address;
+ union
+ {
+ struct CEC_Physical_Address physical_address_2;
+ uint8_t device_type;
+ };
+ };
+
+ struct
+ {
+ uint8_t feature_opcode;
+ uint8_t abort_reason;
+ };
+
+ struct
+ {
+ uint8_t audio_volume_status:7;
+ uint8_t audio_mute_status:1;
+ };
+
+ struct CEC_Record_Source record_source;
+ struct CEC_Timer_Status_Data timer_status_data;
+ struct CEC_Digital_SI digital_service;
+ struct CEC_Analogue_SI analogue_service;
+ struct CEC_Tuner_Device_Info tuner_device_info;
+ };
+};
+
+struct CEC_Device;
+
+struct CEC_Hardware
+{
+ struct CEC_Packet* (*func_receive)(struct CEC_Device* device);
+ int (*func_transmit)(struct CEC_Device* device, struct CEC_Packet* packet);
+};
+
+extern struct CEC_Hardware* MSP430_Open_Hardware(const char* device);
+extern void MSP430_Close_Hardware(struct CEC_Hardware* hardware);
+
+enum CEC_Debug
+{
+ CEC_RX_Packet,
+ CEC_TX_Sucess,
+ CEC_TX_Failure
+};
+
+struct CEC_Device
+{
+ uint8_t logical_address:4;
+ struct CEC_Physical_Address physical_address;
+ struct CEC_Hardware* hardware;
+
+ void (*func_debug)(enum CEC_Debug debug, struct CEC_Device* device, struct CEC_Packet* packet);
+ void (*func_handler[0x100])(struct CEC_Device* device, struct CEC_Packet* packet);
+};
+
+extern void CEC_Init_Device(struct CEC_Device* device);
+extern void CEC_Dump_Packet(FILE* stream, struct CEC_Packet* packet);
+
+extern void CEC_Receive(struct CEC_Device* device);
+extern int CEC_Transmit(struct CEC_Device* device, struct CEC_Packet* packet);
+
+extern int CEC_TX_Ping(struct CEC_Device* device, uint8_t addr);
+extern int CEC_TX_Standby(struct CEC_Device* device, uint8_t addr);
+extern int CEC_TX_Abort(struct CEC_Device* device, uint8_t addr);
+extern int CEC_TX_Give_Audio_Status(struct CEC_Device* device, uint8_t addr);
+extern int CEC_TX_User_Control_Pressed(struct CEC_Device* device, uint8_t addr, enum CEC_UI_Commands command);
+extern int CEC_TX_User_Control_Released(struct CEC_Device* device, uint8_t addr);
+extern int CEC_TX_Report_Physical_Address(struct CEC_Device* device, enum CEC_Device_Type device_type);
+extern int CEC_TX_Active_Source(struct CEC_Device* device);
+extern int CEC_TX_Set_System_Audio_Mode(struct CEC_Device* device, int mode);
+
+extern int CEC_Alloc_Addr(struct CEC_Device* device, enum CEC_Device_Type device_type);
+
+#pragma pack(pop)
+
+#endif
diff --git a/lib/commands.c b/lib/commands.c
new file mode 100644
index 0000000..5076f00
--- /dev/null
+++ b/lib/commands.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright
+ *
+ * Copyright (C) 2009-2010 Christian König (deathsimple@vodafone.de)
+ *
+ * License
+ *
+ * This program is free software; you can redistribute and/or modify
+ * program under the terms of GNU General Public license either version 3
+ * of the License, or (at your option) any later version.
+ *
+ */
+
+#include <stdint.h>
+
+#include "cec.h"
+
+int CEC_TX_Ping(struct CEC_Device* device, uint8_t addr)
+{
+ struct CEC_Packet packet = {
+ .length = 1,
+ .src = device->logical_address,
+ .dst = addr
+ };
+ return CEC_Transmit(device, &packet);
+}
+
+int CEC_TX_Standby(struct CEC_Device* device, uint8_t addr)
+{
+ struct CEC_Packet packet = {
+ .length = 2,
+ .src = device->logical_address,
+ .dst = addr,
+ .opcode = CEC_Standby
+ };
+ return CEC_Transmit(device, &packet);
+}
+
+int CEC_TX_Abort(struct CEC_Device* device, uint8_t addr)
+{
+ struct CEC_Packet packet = {
+ .length = 2,
+ .src = device->logical_address,
+ .dst = addr,
+ .opcode = CEC_Abort
+ };
+ return CEC_Transmit(device, &packet);
+}
+
+int CEC_TX_Give_Audio_Status(struct CEC_Device* device, uint8_t addr)
+{
+ struct CEC_Packet packet = {
+ .length = 2,
+ .src = device->logical_address,
+ .dst = addr,
+ .opcode = CEC_Give_Audio_Status
+ };
+ return CEC_Transmit(device, &packet);
+}
+
+int CEC_TX_User_Control_Pressed(struct CEC_Device* device, uint8_t addr, enum CEC_UI_Commands command)
+{
+ struct CEC_Packet packet = {
+ .length = 3,
+ .src = device->logical_address,
+ .dst = addr,
+ .opcode = CEC_User_Control_Pressed,
+ };
+ packet.ui_command = command;
+ return CEC_Transmit(device, &packet);
+}
+
+int CEC_TX_User_Control_Released(struct CEC_Device* device, uint8_t addr)
+{
+ struct CEC_Packet packet = {
+ .length = 2,
+ .src = device->logical_address,
+ .dst = addr,
+ .opcode = CEC_User_Control_Released
+ };
+ return CEC_Transmit(device, &packet);
+}
+
+int CEC_TX_Report_Physical_Address(struct CEC_Device* device, enum CEC_Device_Type device_type)
+{
+ struct CEC_Packet packet = {
+ .length = 5,
+ .src = device->logical_address,
+ .dst = 0xF,
+ .opcode = CEC_Report_Physical_Address
+ };
+ packet.physical_address = device->physical_address;
+ packet.device_type = device_type;
+ return CEC_Transmit(device, &packet);
+}
+
+int CEC_TX_Active_Source(struct CEC_Device* device)
+{
+ struct CEC_Packet packet = {
+ .length = 4,
+ .src = device->logical_address,
+ .dst = 0xF,
+ .opcode = CEC_Active_Source
+ };
+ packet.physical_address = device->physical_address;
+ return CEC_Transmit(device, &packet);
+}
+
+int CEC_TX_Set_System_Audio_Mode(struct CEC_Device* device, int mode)
+{
+ struct CEC_Packet packet = {
+ .length = 3,
+ .src = device->logical_address,
+ .dst = 0x5,
+ .opcode = CEC_Set_System_Audio_Mode
+ };
+ packet.system_audio_mode_status = mode;
+ return CEC_Transmit(device, &packet);
+
+}
diff --git a/lib/device.c b/lib/device.c
new file mode 100644
index 0000000..b0cfb5b
--- /dev/null
+++ b/lib/device.c
@@ -0,0 +1,102 @@
+/*
+ * Copyright
+ *
+ * Copyright (C) 2009-2010 Christian König (deathsimple@vodafone.de)
+ *
+ * License
+ *
+ * This program is free software; you can redistribute and/or modify
+ * program under the terms of GNU General Public license either version 3
+ * of the License, or (at your option) any later version.
+ *
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "cec.h"
+
+static uint16_t device_type_addr[] = {
+ [CEC_TV] = 0xC001,
+ [CEC_Recording_Device] = 0x8206,
+ [CEC_Tuner] = 0x84C8,
+ [CEC_Playback_Device] = 0x8910,
+ [CEC_Audio_System] = 0x8020
+};
+
+static struct CEC_Physical_Address invalid_addr = {
+ .a = 0xF,
+ .b = 0xF,
+ .c = 0xF,
+ .d = 0xF
+};
+
+void CEC_Init_Device(struct CEC_Device* device)
+{
+ if(!device) return;
+
+ device->logical_address = 0xF;
+ device->physical_address = invalid_addr;
+
+ device->func_debug = NULL;
+
+ int i;
+ for(i=0;i<0x100;i++)
+ device->func_handler[i] = NULL;
+}
+
+void CEC_Receive(struct CEC_Device* device)
+{
+ if(!device || !device->hardware) return;
+ if(!device->hardware->func_receive) return;
+
+ struct CEC_Packet* packet = device->hardware->func_receive(device);
+ if(!packet) return;
+
+ if(device->func_debug) device->func_debug(CEC_RX_Packet, device, packet);
+
+ if(packet->length < 2) return;
+
+ void (*handler)(struct CEC_Device* device, struct CEC_Packet* packet);
+ handler = device->func_handler[packet->opcode];
+ if(handler) handler(device, packet);
+}
+
+int CEC_Transmit(struct CEC_Device* device, struct CEC_Packet* packet)
+{
+ if(!device || !device->hardware) return 0;
+ if(!device->hardware->func_transmit) return 0;
+
+ int retransmit, result = 0;
+ for(retransmit=0; retransmit<5; retransmit++) {
+ if(device->hardware->func_transmit(device, packet)) {
+ result = 1;
+ break;
+ }
+ }
+ if(device->func_debug) {
+ device->func_debug(result ? CEC_TX_Sucess : CEC_TX_Failure, device, packet);
+ }
+ return result;
+}
+
+int CEC_Alloc_Addr(struct CEC_Device* device, enum CEC_Device_Type device_type)
+{
+ uint16_t allowed = device_type_addr[device_type];
+ uint8_t addr;
+
+ if(!memcmp(&device->physical_address, &invalid_addr, sizeof(struct CEC_Physical_Address))) {
+ device->logical_address = 0xF;
+ return 0;
+ }
+
+ for(addr=0; addr<0xF; addr++) {
+ if(!(allowed & (1 << addr))) continue;
+ device->logical_address = addr;
+ if(!CEC_TX_Ping(device, addr)) break;
+ }
+
+ device->logical_address = addr;
+ return CEC_TX_Report_Physical_Address(device, device_type);
+}
diff --git a/lib/dumper.c b/lib/dumper.c
new file mode 100644
index 0000000..11e7487
--- /dev/null
+++ b/lib/dumper.c
@@ -0,0 +1,435 @@
+/*
+ * Copyright
+ *
+ * Copyright (C) 2009-2010 Christian König (deathsimple@vodafone.de)
+ *
+ * License
+ *
+ * This program is free software; you can redistribute and/or modify
+ * program under the terms of GNU General Public license either version 3
+ * of the License, or (at your option) any later version.
+ *
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+
+#include "cec.h"
+
+static char* opcode_names[0x100] = {
+ [CEC_Feature_Abort] = "Feature Abort",
+ [CEC_Image_View_On] = "Image View On",
+ [CEC_Tuner_Step_Increment] = "Tuner Step Increment",
+ [CEC_Tuner_Step_Decrement] = "Tuner Step Decrement",
+ [CEC_Tuner_Device_Status] = "Tuner Device Status",
+ [CEC_Give_Tuner_Device_Status] = "Give Tuner Device Status",
+ [CEC_Record_On] = "Record On",
+ [CEC_Record_Status] = "Record Status",
+ [CEC_Record_Off] = "Record Off",
+ [CEC_Text_View_On] = "Text View On",
+ [CEC_Record_TV_Screen] = "Record TV Screen",
+ [CEC_Give_Deck_Status] = "Give Deck Status",
+ [CEC_Deck_Status] = "Deck Status",
+ [CEC_Set_Menu_Language] = "Set Menu Language",
+ [CEC_Clear_Analogue_Timer] = "Clear Analogue Timer",
+ [CEC_Set_Analogue_Timer] = "Set Analogue Timer",
+ [CEC_Timer_Status] = "Timer Status",
+ [CEC_Standby] = "Standby",
+ [CEC_Play] = "Play",
+ [CEC_Deck_Control] = "Deck Control",
+ [CEC_Timer_Cleared_Status] = "Timer Cleared Status",
+ [CEC_User_Control_Pressed] = "User Control Pressed",
+ [CEC_User_Control_Released] = "User Control Released",
+ [CEC_Give_OSD_Name] = "Give OSD Name",
+ [CEC_Set_OSD_Name] = "Set OSD Name",
+ [CEC_Set_OSD_String] = "Set OSD String",
+ [CEC_Set_Timer_Program] = "Set Timer Program",
+ [CEC_System_Audio_Mode_Request] = "System Audio Mode Request",
+ [CEC_Give_Audio_Status] = "Give Audio Status",
+ [CEC_Set_System_Audio_Mode] = "Set System Audio Mode",
+ [CEC_Report_Audio_Status] = "Report Audio Status",
+ [CEC_System_Audio_Mode_Status] = "System Audio Mode Status",
+ [CEC_Give_System_Audio_Mode_Status] = "Give System Audio Mode Status",
+ [CEC_Routing_Change] = "Routing Change",
+ [CEC_Routing_Information] = "Routing Information",
+ [CEC_Active_Source] = "Active Source",
+ [CEC_Give_Physical_Address] = "Give Physical Address",
+ [CEC_Report_Physical_Address] = "Report Physical Address",
+ [CEC_Request_Active_Source] = "Request Active Source",
+ [CEC_Set_Stream_Path] = "Set Stream Path",
+ [CEC_Device_Vendor_ID] = "Device Vendor ID",
+ [CEC_Vendor_Command] = "Vendor Command",
+ [CEC_Vendor_Remote_Button_Down] = "Vendor Remote Button Down",
+ [CEC_Vendor_Remote_Button_Up] = "Vendor Remote Button Up",
+ [CEC_Give_Device_Vendor_ID] = "Give Device Vendor ID",
+ [CEC_Menu_Request] = "Menu Request",
+ [CEC_Menu_Status] = "Menu Status",
+ [CEC_Give_Device_Power_Status] = "Give Device Power Status",
+ [CEC_Report_Power_Status] = "Report Power Status",
+ [CEC_Get_Menu_Language] = "Get Menu Language",
+ [CEC_Select_Analogue_Service] = "Select Analogue Service",
+ [CEC_Select_Digital_Service] = "Select Digital Service",
+ [CEC_Set_Digital_Timer] = "Set Digital Timer",
+ [CEC_Clear_Digital_Timer] = "Clear Digital Timer",
+ [CEC_Set_Audio_Rate] = "Set Audio Rate",
+ [CEC_Inactive_Source] = "Inactive Source",
+ [CEC_Version] = "Version",
+ [CEC_Get_Version] = "Get Version",
+ [CEC_Vendor_Command_With_ID] = "Vendor Command With ID",
+ [CEC_Clear_External_Timer] = "Clear External Timer",
+ [CEC_Set_External_Timer] = "Set External Timer",
+ [CEC_Abort] = "Abort"
+};
+
+static char* version_description[0x100] = {
+ [CEC_Version_1_1] = "1.1",
+ [CEC_Version_1_2] = "1.2",
+ [CEC_Version_1_2a] = "1.2a",
+ [CEC_Version_1_3] = "1.3",
+ [CEC_Version_1_3a] = "1.3a"
+};
+
+static char* device_type_description[0x100] = {
+ [CEC_TV] = "TV",
+ [CEC_Recording_Device] = "Recording Device",
+ [CEC_Tuner] = "Tuner",
+ [CEC_Playback_Device] = "Playback Device",
+ [CEC_Audio_System] = "Audio System"
+};
+
+static void Opcode(FILE* stream, const char* prefix, uint8_t opcode)
+{
+ char* opcode_name = opcode_names[opcode];
+ fprintf(stream, " %s: 0x%02X", prefix, opcode);
+ fprintf(stream, " (%s)", opcode_name ? opcode_name : "unknown");
+}
+
+static void Physical_Address(FILE* stream, const char* prefix, struct CEC_Physical_Address* addr)
+{
+ fprintf(stream, " %s:%X.%X.%X.%X", prefix, addr->a, addr->b, addr->c, addr->d);
+}
+
+static void Record_Source(FILE* stream, struct CEC_Record_Source* record_source)
+{
+ // TODO
+}
+
+static void Record_Status_Info(FILE* stream, uint8_t record_status)
+{
+ // TODO
+}
+
+static void Timer(FILE* stream, struct CEC_Timer* timer)
+{
+ fprintf(stream, " day:%02d month:%02d", timer->day_of_month, timer->month_of_year);
+ fprintf(stream, " start:%02d:%02d", timer->start_time.hour, timer->start_time.minute);
+ fprintf(stream, " duration:%02d:%02d", timer->duration.hour, timer->duration.minute);
+ // TODO
+}
+
+static void Analogue_SI(FILE* stream, struct CEC_Analogue_SI* service)
+{
+ // TODO
+}
+
+static void Digital_SI(FILE* stream, struct CEC_Digital_SI* service)
+{
+ // TODO
+}
+
+static void External_SI(FILE* stream, struct CEC_External_SI* service)
+{
+ // TODO
+}
+
+static void String(FILE* stream, char* string, int length)
+{
+ int i;
+ fprintf(stream, " ");
+ for(i=0; i<length; i++)
+ {
+ if(string[i]<0x20)
+ fprintf(stream, "(0x%02X)", string[i]);
+ else
+ fprintf(stream, "%c", string[i]);
+ }
+}
+
+static void Timer_Cleared_Status(FILE* stream, uint8_t timer_cleared_status_data)
+{
+ // TODO
+}
+
+static void Timer_Status(FILE* stream, struct CEC_Timer_Status_Data* timer_status_data)
+{
+ // TODO
+}
+
+static void Version(FILE* stream, uint8_t version)
+{
+ const char* description = version_description[version];
+ if(description)
+ fprintf(stream, " version:%s", description);
+ else
+ fprintf(stream, " unknown version:0x%02X", version);
+}
+
+static void Device_Type(FILE* stream, uint8_t device_type)
+{
+ const char* description = device_type_description[device_type];
+ if(description)
+ fprintf(stream, " device type:%s", description);
+ else
+ fprintf(stream, " unknown device type:0x%02X", device_type);
+}
+
+static void Language(FILE* stream, char* language)
+{
+ // TODO
+}
+
+static void Deck_Control_Mode(FILE* stream, uint8_t deck_control_mode)
+{
+ // TODO
+}
+
+static void Deck_Info(FILE* stream, uint8_t deck_info)
+{
+ // TODO
+}
+
+static void Status_Request(FILE* stream, uint8_t status_request)
+{
+ // TODO
+}
+
+static void Play_Mode(FILE* stream, uint8_t play_mode)
+{
+ // TODO
+}
+
+static void Tuner_Device_Info(FILE* stream, struct CEC_Tuner_Device_Info* tuner_device_info)
+{
+ // TODO
+}
+
+static void Vendor_ID(FILE* stream, uint8_t* vendor_id)
+{
+ fprintf(stderr, " vendor id: 0x%X%X%X", vendor_id[0], vendor_id[1], vendor_id[2]);
+}
+
+static void Hex_Dump(FILE* stream, uint8_t* data, int length)
+{
+ int i;
+ fprintf(stderr, " data:");
+ for(i=0;i<length;i++) {
+ fprintf(stderr, " 0x%X", data[i]);
+ }
+}
+
+static void Display_Control(FILE* stream, uint8_t display_control)
+{
+ // TODO
+}
+
+static void Menu_Request_Type(FILE* stream, uint8_t request_type)
+{
+ // TODO
+}
+
+static void Menu_Status(FILE* stream, uint8_t status)
+{
+ // TODO
+}
+
+static void UI_Command(FILE* stream, uint8_t command)
+{
+ // TODO
+}
+
+static void Power_Status(FILE* stream, uint8_t status)
+{
+ // TODO
+}
+
+static void Abort_Reason(FILE* stream, uint8_t reason)
+{
+ // TODO
+}
+
+static void Audio_Status(FILE* stream, int mute, int volume)
+{
+ fprintf(stream, " mute: %s volume: %d", mute ? "on" : "off", volume);
+}
+
+static void System_Audio_Mode_Status(FILE* stream, uint8_t status)
+{
+ fprintf(stream, " system audio mode: %s", status ? "on" : "off");
+}
+
+static void Audio_Rate(FILE* stream, uint8_t status)
+{
+ // TODO
+}
+
+void CEC_Dump_Packet(FILE* stream, struct CEC_Packet* packet)
+{
+ fprintf(stream, "len:%d src:0x%X dst:0x%X", packet->length, packet->src, packet->dst);
+ if(packet->length == 1) return;
+
+ Opcode(stream, "opcode", packet->opcode);
+
+ switch(packet->opcode) {
+ case CEC_Active_Source:
+ case CEC_Inactive_Source:
+ case CEC_Routing_Information:
+ case CEC_Set_Stream_Path:
+ case CEC_System_Audio_Mode_Request:
+ Physical_Address(stream, "addr", &packet->physical_address);
+ break;
+
+ case CEC_Routing_Change:
+ Physical_Address(stream, "original", &packet->physical_address);
+ Physical_Address(stream, "new", &packet->physical_address_2);
+ break;
+
+ case CEC_Record_On:
+ Record_Source(stream, &packet->record_source);
+ break;
+
+ case CEC_Record_Status:
+ Record_Status_Info(stream, packet->record_status);
+ break;
+
+ case CEC_Clear_Analogue_Timer:
+ case CEC_Set_Analogue_Timer:
+ Timer(stream, &packet->timer);
+ Analogue_SI(stream, &packet->analogue_timer);
+ break;
+
+ case CEC_Set_Digital_Timer:
+ case CEC_Clear_Digital_Timer:
+ Timer(stream, &packet->timer);
+ Digital_SI(stream, &packet->digital_timer);
+ break;
+
+ case CEC_Clear_External_Timer:
+ case CEC_Set_External_Timer:
+ Timer(stream, &packet->timer);
+ External_SI(stream, &packet->external_timer);
+ break;
+
+ case CEC_Set_Timer_Program:
+ String(stream, packet->string, packet->length-2);
+ break;
+
+ case CEC_Timer_Cleared_Status:
+ Timer_Cleared_Status(stream, packet->timer_cleared_status_data);
+ break;
+
+ case CEC_Timer_Status:
+ Timer_Status(stream, &packet->timer_status_data);
+ break;
+
+ case CEC_Version:
+ Version(stream, packet->version);
+ break;
+
+ case CEC_Report_Physical_Address:
+ Physical_Address(stream, "addr", &packet->physical_address);
+ Device_Type(stream, packet->device_type);
+ break;
+
+ case CEC_Set_Menu_Language:
+ Language(stream, packet->language);
+ break;
+
+ case CEC_Deck_Control:
+ Deck_Control_Mode(stream, packet->deck_control_mode);
+ break;
+
+ case CEC_Deck_Status:
+ Deck_Info(stream, packet->deck_info);
+ break;
+
+ case CEC_Give_Deck_Status:
+ case CEC_Give_Tuner_Device_Status:
+ Status_Request(stream, packet->status_request);
+ break;
+
+ case CEC_Play:
+ Play_Mode(stream, packet->play_mode);
+ break;
+
+ case CEC_Select_Analogue_Service:
+ Analogue_SI(stream, &packet->analogue_service);
+ break;
+
+ case CEC_Select_Digital_Service:
+ Digital_SI(stream, &packet->digital_timer);
+ break;
+
+ case CEC_Tuner_Device_Status:
+ Tuner_Device_Info(stream, &packet->tuner_device_info);
+ break;
+
+ case CEC_Device_Vendor_ID:
+ Vendor_ID(stream, packet->vendor_id);
+ break;
+
+ case CEC_Vendor_Command_With_ID:
+ Vendor_ID(stream, packet->vendor_id);
+ Hex_Dump(stream, packet->vendor_specific_data, packet->length-5);
+ break;
+
+ case CEC_Vendor_Remote_Button_Down:
+ Hex_Dump(stream, packet->raw_data, packet->length-2);
+ break;
+
+ case CEC_Set_OSD_String:
+ Display_Control(stream, packet->display_control);
+ String(stream, packet->display_string, packet->length-1);
+ break;
+
+ case CEC_Set_OSD_Name:
+ String(stream, packet->string, packet->length-2);
+ break;
+
+ case CEC_Menu_Request:
+ Menu_Request_Type(stream, packet->menu_request_type);
+ break;
+
+ case CEC_Menu_Status:
+ Menu_Status(stream, packet->menu_status);
+ break;
+
+ case CEC_User_Control_Pressed:
+ UI_Command(stream, packet->ui_command);
+ break;
+
+ case CEC_Report_Power_Status:
+ Power_Status(stream, packet->power_status);
+ break;
+
+ case CEC_Feature_Abort:
+ Opcode(stream, "feature-opcode", packet->feature_opcode);
+ Abort_Reason(stream, packet->abort_reason);
+ break;
+
+ case CEC_Report_Audio_Status:
+ Audio_Status(stream, packet->audio_mute_status, packet->audio_volume_status);
+ break;
+
+ case CEC_Set_System_Audio_Mode:
+ case CEC_System_Audio_Mode_Status:
+ System_Audio_Mode_Status(stream, packet->system_audio_mode_status);
+ break;
+
+ case CEC_Set_Audio_Rate:
+ Audio_Rate(stream, packet->audio_rate);
+ break;
+
+ default:
+ Hex_Dump(stream, packet->raw_data, packet->length-2);
+ }
+}
diff --git a/lib/msp430.c b/lib/msp430.c
new file mode 100644
index 0000000..cf70512
--- /dev/null
+++ b/lib/msp430.c
@@ -0,0 +1,152 @@
+/*
+ * Copyright
+ *
+ * Copyright (C) 2009-2010 Christian König (deathsimple@vodafone.de)
+ *
+ * License
+ *
+ * This program is free software; you can redistribute and/or modify
+ * program under the terms of GNU General Public license either version 3
+ * of the License, or (at your option) any later version.
+ *
+ */
+
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <fcntl.h>
+
+#include <linux/i2c-dev.h>
+
+#include "cec.h"
+#include "../msp430/cec_state.h"
+
+#define BUFFER_SIZE 32
+#define I2C_ADDR 0x60
+
+#define RX_DELAY 10000
+#define TX_BASE_DELAY 4500
+#define TX_BIT_DELAY 2400
+#define TX_RETRY 10
+
+struct MSP430_Hardware
+{
+ struct CEC_Hardware cec;
+ int i2c;
+
+ int index;
+ uint8_t buffer[BUFFER_SIZE];
+};
+
+static ssize_t Fill_Buffer(struct MSP430_Hardware* hw)
+{
+ hw->index = 0;
+ memset(hw->buffer, 0, BUFFER_SIZE);
+ return read(hw->i2c, hw->buffer, BUFFER_SIZE);
+}
+
+static int Buffer_Empty(struct MSP430_Hardware* hw)
+{
+ return hw->index < BUFFER_SIZE && (
+ hw->buffer[hw->index] == 0 ||
+ hw->buffer[hw->index] == 0xff);
+}
+
+static struct CEC_Packet* Receive(struct CEC_Device* device)
+{
+ struct MSP430_Hardware* hw = (struct MSP430_Hardware*)device->hardware;
+
+ if(Buffer_Empty(hw)) {
+ usleep(RX_DELAY);
+ if(Fill_Buffer(hw) < 0) return NULL;
+ }
+
+ while(!Buffer_Empty(hw) && hw->buffer[hw->index] > CEC_Bytes_Max)
+ hw->index++;
+
+ if(!Buffer_Empty(hw)) {
+ hw->buffer[hw->index] >>= 3;
+
+ void* packet = &(hw->buffer[hw->index]);
+ hw->index += hw->buffer[hw->index];
+ if(hw->index > BUFFER_SIZE) return NULL;
+ return (struct CEC_Packet*)packet;
+ }
+ return NULL;
+}
+
+static int Transmit(struct CEC_Device* device, struct CEC_Packet* packet)
+{
+ struct MSP430_Hardware* hw = (struct MSP430_Hardware*)device->hardware;
+
+ do {
+ CEC_Receive(device);
+ CEC_Receive(device);
+ } while(!Buffer_Empty(hw));
+
+ if(write(hw->i2c, ((void*)packet)+1, packet->length) != packet->length)
+ return 0;
+
+
+ int retry;
+ for(retry=0; retry<TX_RETRY; retry++)
+ {
+ usleep(TX_BASE_DELAY + packet->length * TX_BIT_DELAY * 10);
+
+ int result = Fill_Buffer(hw);
+ if(result < 0) continue;
+
+ result = -1;
+
+ int i;
+ for(i=0;i<BUFFER_SIZE;i++) {
+ if(hw->buffer[i] == CEC_Transmitted)
+ result = 1;
+ else if(hw->buffer[i] > CEC_Bytes_Max)
+ result = 0;
+ else if(hw->buffer[i] == 0)
+ break;
+
+ i += hw->buffer[i];
+ }
+ if(result != -1) return result;
+ usleep(RX_DELAY);
+ }
+
+ return 0;
+}
+
+struct CEC_Hardware* MSP430_Open_Hardware(const char* device)
+{
+ struct MSP430_Hardware* result = malloc(sizeof(struct MSP430_Hardware));
+
+ if(result == NULL)
+ return NULL;
+
+ result->cec.func_receive = Receive;
+ result->cec.func_transmit = Transmit;
+
+ result->i2c = open(device, O_RDWR);
+
+ if(result->i2c < 0)
+ goto error1;
+
+ if(ioctl(result->i2c, I2C_SLAVE, I2C_ADDR) < 0)
+ goto error2;
+
+ return &(result->cec);
+
+error2:
+ close(result->i2c);
+
+error1:
+ free(result);
+ return NULL;
+}
+
+void MSP430_Close_Hardware(struct CEC_Hardware* hardware)
+{
+ struct MSP430_Hardware* hw = (struct MSP430_Hardware*)hardware;
+ close(hw->i2c);
+ free(hw);
+}
diff --git a/msp430/.gdbinit b/msp430/.gdbinit
new file mode 100644
index 0000000..1a44018
--- /dev/null
+++ b/msp430/.gdbinit
@@ -0,0 +1,4 @@
+target remote localhost:2000
+monitor erase all
+load
+monitor reset
diff --git a/msp430/Makefile b/msp430/Makefile
new file mode 100644
index 0000000..49b9d61
--- /dev/null
+++ b/msp430/Makefile
@@ -0,0 +1,36 @@
+# makfile configuration
+NAME = cec
+OBJECTS = main.o
+HEADERS = buffer.h cec.h cec_pin.h cec_state.h cec_timing.h i2c.h
+CPU = msp430x2012
+
+CFLAGS = -mmcu=${CPU} -Os -Wall -g
+
+#switch the compiler (for the internal make rules)
+CC = msp430-gcc
+
+.PHONY: all debug
+
+#all should be the first target. it's built when make is run without args
+all: ${NAME}.elf ${NAME}.a43 ${NAME}.lst
+
+debug: ${NAME}.elf
+ msp430-gdb ${NAME}.elf
+
+#additional rules for files
+${NAME}.elf: ${OBJECTS}
+ ${CC} -mmcu=${CPU} -o $@ ${OBJECTS}
+ msp430-size $@
+
+${NAME}.a43: ${NAME}.elf
+ msp430-objcopy -O ihex $^ $@
+
+${NAME}.lst: ${NAME}.elf
+ msp430-objdump -dSt $^ >$@
+
+clean:
+ rm -f ${NAME}.elf ${NAME}.a43 ${NAME}.lst ${OBJECTS}
+
+main.o: main.c ${HEADERS}
+i2c.o: i2c.c ${HEADERS}
+cec.o: cec.c ${HEADERS}
diff --git a/msp430/buffer.h b/msp430/buffer.h
new file mode 100644
index 0000000..a5142ed
--- /dev/null
+++ b/msp430/buffer.h
@@ -0,0 +1,103 @@
+/*
+ * Copyright
+ *
+ * Copyright (C) 2009-2010 Christian König (deathsimple@vodafone.de)
+ *
+ * License
+ *
+ * This program is free software; you can redistribute and/or modify
+ * program under the terms of GNU General Public license either version 3
+ * of the License, or (at your option) any later version.
+ *
+ */
+
+#ifndef _BUFFER_H_
+#define _BUFFER_H_
+
+#define BUFFER_SIZE 32
+#define BUFFER_MASK 0x1F
+
+typedef int bool;
+#define true 1
+#define false 0
+
+struct buffer {
+ uint8_t start;
+ uint8_t end;
+ uint8_t write;
+
+ uint8_t data[BUFFER_SIZE];
+};
+
+extern struct buffer rx_buf;
+extern struct buffer tx_buf;
+
+static bool buf_empty(struct buffer* buf)
+{
+ return buf->start == buf->end;
+}
+
+static uint8_t* buf_ptr(struct buffer* buf, uint8_t index)
+{
+ return &(buf->data[(index >> 3) & BUFFER_MASK]);
+}
+
+static bool buf_get_bit(struct buffer* buf)
+{
+ uint8_t* ptr = buf_ptr(buf, buf->start++);
+ bool result = *ptr & 0x80;
+ *ptr <<= 1;
+ return result;
+}
+
+static uint8_t buf_get_peak(struct buffer* buf)
+{
+ return *buf_ptr(buf, buf->start);
+}
+
+static uint8_t buf_get_byte(struct buffer* buf)
+{
+ uint8_t result = buf_get_peak(buf);
+ buf->start += 8;
+ return result;
+}
+
+static inline void buf_put_begin(struct buffer* buf)
+{
+ buf->write = 0;
+}
+
+static void buf_put_bit(struct buffer* buf, bool bit)
+{
+ uint8_t* ptr = buf_ptr(buf, buf->end + buf->write + 8);
+ *ptr <<= 1;
+ if(bit) *ptr |= 1;
+ buf->write++;
+}
+
+static inline int buf_put_addr(struct buffer* buf)
+{
+ return buf->write;
+}
+
+static uint8_t buf_put_head(struct buffer* buf)
+{
+ return *buf_ptr(buf, buf->end + 8);
+}
+
+static void buf_put_byte(struct buffer* buf, uint8_t byte)
+{
+ *buf_ptr(buf, buf->end) = byte;
+
+ buf->end += 8;
+}
+
+static void buf_put_done(struct buffer* buf)
+{
+ buf->write &= BUFFER_MASK << 3;
+ buf_put_byte(buf, buf->write);
+
+ buf->end += buf->write;
+}
+
+#endif
diff --git a/msp430/cec.h b/msp430/cec.h
new file mode 100644
index 0000000..318b67f
--- /dev/null
+++ b/msp430/cec.h
@@ -0,0 +1,220 @@
+/*
+ * Copyright
+ *
+ * Copyright (C) 2009-2010 Christian König (deathsimple@vodafone.de)
+ *
+ * License
+ *
+ * This program is free software; you can redistribute and/or modify
+ * program under the terms of GNU General Public license either version 3
+ * of the License, or (at your option) any later version.
+ *
+ */
+
+#ifndef _CEC_H_
+#define _CEC_H_
+
+#include "buffer.h"
+#include "cec_state.h"
+#include "cec_pin.h"
+#include "cec_timing.h"
+
+#define CEC_BroadcastAddr 0xF
+uint8_t CEC_UnicastAddr;
+
+uint8_t CEC_Count;
+bool CEC_IsTxBroadcast;
+
+enum CEC_State CEC_State;
+
+static inline bool CEC_IsRxAddrValid()
+{
+ uint8_t addr = buf_put_head(&rx_buf) & 0xF;
+ return addr == CEC_UnicastAddr ||
+ addr == CEC_BroadcastAddr;
+}
+
+static inline int CEC_IsRxBroadcast()
+{
+ uint8_t addr = buf_put_head(&rx_buf) & 0xF;
+ return addr == CEC_BroadcastAddr;
+}
+
+static inline void CEC_Init()
+{
+ CEC_State = CEC_Idle;
+
+ CEC_SEL &= CEC_MASK;
+
+ InputHight();
+
+ /* clear pending interrupt and enable it */
+ IntFallingEdge();
+ IntClearPending();
+
+ CEC_IE |= CEC_BIT;
+
+ // Reset timerA
+ TACTL |= TACLR;
+}
+
+static void CEC_SendMessage()
+{
+ if(CEC_State == CEC_Idle) {
+ CEC_Count = buf_get_byte(&tx_buf);
+ uint8_t addr = buf_get_peak(&tx_buf);
+ CEC_IsTxBroadcast = (addr & 0xF) == CEC_BroadcastAddr;
+
+ addr >>= 4;
+ if(addr != CEC_BroadcastAddr) {
+ CEC_UnicastAddr = addr;
+ }
+ Timer1(ARBITATION);
+ TimerStart();
+ }
+}
+
+static void CEC_Restart()
+{
+ // reset state maschine
+ CEC_State = CEC_Idle;
+
+ // stop timer
+ TimerStop();
+
+ if(!buf_empty(&tx_buf)) CEC_SendMessage();
+}
+
+static void CEC_LowDuration(unsigned int count)
+{
+ OutputLow();
+ IntClearPending();
+ Timer0(count);
+}
+
+interrupt(CEC_INT_VECTOR) IntServiceRoutineCEC()
+{
+ if(IntSelectedEdge()) {
+ TimerReset();
+ TimerStart();
+
+ int bit = CEC_IsRxBroadcast();
+ switch(CEC_State) {
+ case CEC_RX_ACK:
+ //TODO
+ //bit ^= !CEC_count && CurrentByte(rx_end) == rx_start;
+
+ case CEC_RX_Done:
+ CEC_LowDuration(bit ? DATA_H_AVG : DATA_L_AVG);
+
+ default:
+ Timer1(TIMEOUT);
+ }
+
+ } else {
+ enum DecodeResult result = TimerDecode();
+ if(result == BIT_Start) {
+ CEC_State = CEC_RX_Data;
+ buf_put_begin(&rx_buf);
+
+ } else if(result == BIT_OOR) {
+ buf_put_byte(&rx_buf, CEC_OOR);
+ CEC_Restart();
+
+ } else switch(CEC_State++) {
+ case CEC_Idle:
+ CEC_State = CEC_Idle;
+ TimerStop();
+ break;
+
+ case CEC_RX_Data:
+ buf_put_bit(&rx_buf, result);
+
+ int addr = buf_put_addr(&rx_buf);
+ if(addr == 8 && !CEC_IsRxAddrValid()) {
+ CEC_Restart();
+
+ } else if((addr & 7) != 0) {
+ CEC_State = CEC_RX_Data;
+ }
+ break;
+
+ case CEC_RX_EOM:
+ if(result) CEC_State = CEC_RX_Done;
+ break;
+
+ case CEC_RX_ACK:
+ CEC_State = CEC_RX_Data;
+ break;
+
+ case CEC_RX_Done:
+ buf_put_done(&rx_buf);
+ CEC_Restart();
+ break;
+
+ case CEC_TX_ACK:
+ if(result != CEC_IsTxBroadcast) {
+ buf_put_byte(&rx_buf, CEC_NACK);
+ CEC_Restart();
+
+ } else if(CEC_Count == 0) {
+ buf_put_byte(&rx_buf, CEC_Transmitted);
+ CEC_Restart();
+
+ } else {
+ CEC_State = CEC_TX_Data;
+ }
+ break;
+
+ default:
+ buf_put_byte(&rx_buf, CEC_ARL);
+ CEC_Restart();
+ break;
+ }
+ }
+
+ IntClearPending();
+ IntToggleEdge();
+}
+
+interrupt(TIMERA0_VECTOR) IntServiceRoutineTimerA0()
+{
+ InputHight();
+}
+
+interrupt(TIMERA1_VECTOR) IntServiceRoutineTimerA1()
+{
+ TimerReset();
+ switch(CEC_State) {
+ case CEC_Idle:
+ CEC_State = CEC_TX_Data;
+ CEC_LowDuration(START_AVG);
+ Timer1(START_LEN);
+ return;
+
+ case CEC_TX_Data:
+ CEC_Count--;
+ CEC_LowDuration(buf_get_bit(&tx_buf) ? DATA_H_AVG : DATA_L_AVG);
+ if((CEC_Count & 0x7) == 0) CEC_State = CEC_TX_EOM;
+ break;
+
+ case CEC_TX_EOM:
+ CEC_LowDuration(CEC_Count == 0 ? DATA_H_AVG : DATA_L_AVG);
+ CEC_State = CEC_TX_ACK;
+ break;
+
+ case CEC_TX_ACK:
+ CEC_LowDuration(DATA_H_AVG);
+ IntRisingEdge();
+ break;
+
+ default:
+ buf_put_byte(&rx_buf, CEC_Timeout);
+ CEC_Restart();
+ return;
+ }
+
+ Timer1(DATA_LEN);
+}
+
+#endif
diff --git a/msp430/cec_pin.h b/msp430/cec_pin.h
new file mode 100644
index 0000000..f0dbae5
--- /dev/null
+++ b/msp430/cec_pin.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright
+ *
+ * Copyright (C) 2009-2010 Christian König (deathsimple@vodafone.de)
+ *
+ * License
+ *
+ * This program is free software; you can redistribute and/or modify
+ * program under the terms of GNU General Public license either version 3
+ * of the License, or (at your option) any later version.
+ *
+ */
+
+#ifndef _CEC_PIN_H_
+#define _CEC_PIN_H_
+
+#define CEC_PIN 6
+#define CEC_BIT (1 << CEC_PIN)
+#define CEC_MASK (~CEC_BIT)
+
+#define CEC_IN P2IN
+#define CEC_OUT P2OUT
+#define CEC_DIR P2DIR
+#define CEC_REN P2REN
+#define CEC_IFG P2IFG
+#define CEC_IES P2IES
+#define CEC_IE P2IE
+#define CEC_SEL P2SEL
+#define CEC_REN P2REN
+
+#define CEC_INT_VECTOR PORT2_VECTOR
+
+static inline void InputHight()
+{
+ /* input direction */
+ CEC_DIR &= CEC_MASK;
+
+ /* pull up */
+ CEC_OUT |= CEC_BIT;
+
+ /* enable resistor */
+ CEC_REN |= CEC_BIT;
+}
+
+static inline void OutputLow()
+{
+ /* output direction */
+ CEC_DIR |= CEC_BIT;
+
+ /* pull down */
+ CEC_OUT &= CEC_MASK;
+
+ /* disable resistor */
+ CEC_REN &= CEC_MASK;
+}
+
+static inline void IntClearPending()
+{
+ CEC_IFG &= CEC_MASK;
+}
+
+static inline void IntFallingEdge()
+{
+ CEC_IES |= CEC_BIT;
+}
+
+static inline void IntRisingEdge()
+{
+ CEC_IES &= CEC_MASK;
+}
+
+static inline void IntToggleEdge()
+{
+ CEC_IES ^= CEC_BIT;
+}
+
+static inline uint8_t IntSelectedEdge()
+{
+ return CEC_IES & CEC_BIT;
+}
+
+#endif
diff --git a/msp430/cec_state.h b/msp430/cec_state.h
new file mode 100644
index 0000000..0a11554
--- /dev/null
+++ b/msp430/cec_state.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright
+ *
+ * Copyright (C) 2009-2010 Christian König (deathsimple@vodafone.de)
+ *
+ * License
+ *
+ * This program is free software; you can redistribute and/or modify
+ * program under the terms of GNU General Public license either version 3
+ * of the License, or (at your option) any later version.
+ *
+ */
+
+#ifndef _CEC_STATE_H_
+#define _CEC_STATE_H_
+
+enum CEC_State {
+ CEC_Idle,
+
+ CEC_RX_Data,
+ CEC_RX_EOM,
+ CEC_RX_ACK,
+ CEC_RX_Done,
+
+ CEC_TX_Data,
+ CEC_TX_EOM,
+ CEC_TX_ACK
+
+};
+
+enum CEC_Result {
+ CEC_Transmitted = 0xF0,
+ CEC_Timeout = 0xE0,
+ CEC_OOR = 0xD0,
+ CEC_NACK = 0xC0,
+ CEC_ARL = 0xB0,
+ CEC_Bytes_Max = 0x80
+
+};
+
+#endif
diff --git a/msp430/cec_timing.h b/msp430/cec_timing.h
new file mode 100644
index 0000000..9e1ecd9
--- /dev/null
+++ b/msp430/cec_timing.h
@@ -0,0 +1,113 @@
+/*
+ * Copyright
+ *
+ * Copyright (C) 2009-2010 Christian König (deathsimple@vodafone.de)
+ *
+ * License
+ *
+ * This program is free software; you can redistribute and/or modify
+ * program under the terms of GNU General Public license either version 3
+ * of the License, or (at your option) any later version.
+ *
+ */
+
+#ifndef _CEC_TIMING_H_
+#define _CEC_TIMING_H_
+
+//#define DECODE_USE_HARD_VALUES
+
+//SMCLK=1.5MHz so everything is based on SMCLK/8=187.5kHz
+#define MILLISECONDS(x) ((int)((x)*187.5f))
+
+/* values extracted from the HDMI standard */
+#define START_MIN MILLISECONDS(3.5f)
+#define START_AVG MILLISECONDS(3.7f)
+#define START_MAX MILLISECONDS(3.9f)
+
+#define START_LEN MILLISECONDS(4.5f)
+
+#define DATA_H_MIN MILLISECONDS(0.4f)
+#define DATA_H_AVG MILLISECONDS(0.6f)
+#define DATA_H_MAX MILLISECONDS(0.85f)
+
+#define DATA_L_MIN MILLISECONDS(1.25f)
+#define DATA_L_AVG MILLISECONDS(1.5f)
+#define DATA_L_MAX MILLISECONDS(1.7f)
+
+#define DATA_LEN MILLISECONDS(2.4f)
+
+#define ARBITATION (DATA_LEN * 7)
+
+/* not standard values, but usefull */
+#define DATA_TRIGGER ((DATA_H_AVG + DATA_L_AVG) / 2)
+#define TIMEOUT MILLISECONDS(5.0f)
+
+static inline void TimerStart()
+{
+ TA0CTL = TASSEL_2 | ID_3 | MC_CONT;
+}
+
+static inline void TimerReset()
+{
+ TA0R = 0;
+}
+
+static inline void TimerStop()
+{
+ TA0CTL = TASSEL_2 | ID_3 | MC_STOP;
+ TA0CCTL0 = 0;
+ TA0CCTL1 = 0;
+}
+
+static inline void Timer0(uint16_t count)
+{
+ TA0CCR0 = count;
+ TA0CCTL0 = CCIE;
+}
+
+static inline void Timer1(uint16_t count)
+{
+ TA0CCR1 = count;
+ TA0CCTL1 = CCIE;
+}
+
+static enum DecodeResult
+{
+ BIT_L = 0,
+ BIT_H = 1,
+ BIT_Start = 2,
+ BIT_OOR = 3
+
+} inline TimerDecode()
+{
+ uint16_t count = TA0R;
+#ifdef DECODE_USE_HARD_VALUES
+ if(DATA_L_MIN <= count && count <= DATA_L_MAX) {
+ return BIT_L;
+
+ } else if(DATA_H_MIN <= count && count <= DATA_H_MAX) {
+ return BIT_H;
+
+ } else if(START_MIN <= count && count <= START_MAX) {
+ return BIT_Start;
+
+ } else {
+ return BIT_OOR;
+ }
+#else
+ if(count < DATA_TRIGGER) {
+ return BIT_H;
+
+ } else if(count < START_MIN) {
+ return BIT_L;
+
+ } else if(count <= START_MAX) {
+ return BIT_Start;
+
+ } else {
+ return BIT_OOR;
+ }
+#endif
+}
+
+#endif
diff --git a/msp430/i2c.h b/msp430/i2c.h
new file mode 100644
index 0000000..511c082
--- /dev/null
+++ b/msp430/i2c.h
@@ -0,0 +1,369 @@
+/*
+ * Copyright
+ *
+ * Copyright (C) 2009-2010 Christian König (deathsimple@vodafone.de)
+ *
+ * License
+ *
+ * This program is free software; you can redistribute and/or modify
+ * program under the terms of GNU General Public license either version 3
+ * of the License, or (at your option) any later version.
+ *
+ */
+
+#ifndef _I2C_H_
+#define _I2C_H_
+
+#include <io.h>
+#include <signal.h>
+
+#include "buffer.h"
+#include "cec.h"
+
+#define I2C_Addr ((uint8_t)0xC0)
+
+#define I2C_SDA (1 << 6)
+#define I2C_SCL (1 << 7)
+#define I2C_BOTH (I2C_SDA | I2C_SCL)
+
+static enum {
+ I2C_Idle,
+ I2C_RX_Addr,
+
+ I2C_TX_Ack_RX,
+ I2C_RX_Data,
+
+ I2C_TX_Ack_TX,
+ I2C_TX_Data,
+ I2C_RX_Ack,
+
+} I2C_State;
+
+static inline void I2C_InputHight()
+{
+ /* input direction */
+ P1DIR &= ~I2C_SDA;
+
+ /* pull up */
+ P1OUT |= I2C_SDA;
+
+ /* enable resistor */
+ P1REN |= I2C_SDA;
+}
+
+static inline void I2C_OutputLow()
+{
+ /* output direction */
+ P1DIR |= I2C_SDA;
+
+ /* pull down */
+ P1OUT &= ~I2C_SDA;
+
+ /* disable resistor */
+ P1REN &= ~I2C_SDA;
+}
+
+static inline void I2C_Init()
+{
+ P1IES |= I2C_BOTH;
+ P1IFG &= ~I2C_BOTH;
+ P1IE |= I2C_BOTH;
+}
+
+static inline bool I2C_Start(uint8_t ies, uint8_t ifg)
+{
+ return (ies == I2C_BOTH) && (ifg == I2C_SDA);
+}
+
+static inline bool I2C_Write(uint8_t ies, uint8_t ifg)
+{
+ return (ies & I2C_SCL) && (ifg == I2C_SCL);
+}
+
+static inline bool I2C_Read(uint8_t ies, uint8_t ifg)
+{
+ return !(ies & I2C_SCL) && (ifg == I2C_SCL);
+}
+
+static inline bool I2C_Stop(uint8_t ies, uint8_t ifg)
+{
+ return (ies == I2C_SCL) && (ifg == I2C_SDA);
+}
+
+interrupt(PORT1_VECTOR) IntServiceRoutinePort1()
+{
+ uint8_t ifg = P1IFG & I2C_BOTH;
+ uint8_t ies = P1IES & I2C_BOTH;
+
+ P1IFG ^= ifg;
+ P1IES ^= ifg;
+
+ if(I2C_Start(ies, ifg)) {
+ I2C_State = I2C_RX_Addr;
+ buf_put_begin(&tx_buf);
+
+ } else if(I2C_Write(ies, ifg)) {
+ switch(I2C_State) {
+ case I2C_TX_Data:
+ if(buf_empty(&rx_buf) || buf_get_bit(&rx_buf)) {
+ I2C_InputHight();
+ break;
+ }
+
+ case I2C_TX_Ack_RX:
+ case I2C_TX_Ack_TX:
+ I2C_OutputLow();
+ break;
+
+ default:
+ I2C_InputHight();
+ break;
+ }
+
+ } else if(I2C_Read(ies, ifg)) {
+ switch(I2C_State) {
+ case I2C_Idle:
+ break;
+
+ case I2C_RX_Addr:
+ buf_put_bit(&tx_buf, P1IN & I2C_SDA);
+
+ if(buf_put_addr(&tx_buf) == 8) {
+ uint8_t addr = buf_put_head(&tx_buf);
+
+ // Address match? if yes send [N]Ack depending on buffer state
+ if(addr == I2C_Addr) {
+ buf_put_begin(&tx_buf);
+ I2C_State = I2C_TX_Ack_RX;
+
+ } else if((addr == (I2C_Addr | 1)) && !buf_empty(&rx_buf)) {
+ I2C_State = I2C_TX_Ack_TX;
+
+ } else {
+ // No address match -> ignored
+ I2C_State = I2C_Idle;
+ }
+ }
+ break;
+
+ case I2C_TX_Ack_RX:
+ I2C_State = I2C_RX_Data;
+ break;
+
+ case I2C_RX_Ack:
+ if(P1IN & I2C_SDA) {
+ I2C_State = I2C_Idle;
+ }
+
+ case I2C_TX_Ack_TX:
+ I2C_State = I2C_TX_Data;
+ break;
+
+ case I2C_TX_Data:
+ if((rx_buf.start & 7) == 0) {
+ I2C_State = I2C_RX_Ack;
+ }
+ break;
+
+ case I2C_RX_Data:
+ buf_put_bit(&tx_buf, P1IN & I2C_SDA);
+ if(!(buf_put_addr(&tx_buf) & 7)) {
+ I2C_State = I2C_TX_Ack_RX;
+ }
+ break;
+ }
+
+ } else if(I2C_Stop(ies, ifg)) {
+ if(I2C_State == I2C_RX_Data) {
+ buf_put_done(&tx_buf);
+ CEC_SendMessage();
+ }
+ I2C_State = I2C_Idle;
+
+ }
+}
+
+/*#define I2C_Direction 0x01
+#define I2C_Write 0x00
+#define I2C_Read 0x01
+
+uint8_t I2C_Offset;
+
+static uint8_t TxIndex()
+{
+ return (tx_end + I2C_Offset + 1) & BUFFER_MASK;
+}
+
+enum {
+ I2C_Idle = 0x00,
+ I2C_RX_Addr = 0x01,
+
+ I2C_TX_Ack = 0x02,
+ I2C_TX_Data = 0x03,
+
+ I2C_RX_Ack = 0x04,
+ I2C_RX_Data = 0x05
+
+} I2C_State;
+
+static inline void I2C_Init()
+{
+ // Internal Pullups enable
+ P1OUT |= 0xC0;
+ P1REN |= 0xC0;
+
+ P1DIR &= 0xC0;
+ P1IE |= 0x80;
+ P1IES &= ~0x80;
+ P1IFG &= ~0x80;
+
+ // Port & USI mode setup
+ USICTL0 = USIPE6 | USIPE7 | USISWRST;
+
+ // Set to I2C mode
+ USICTL1 = USII2C;
+
+ // Setup clock pol
+ USICKCTL = USICKPL;
+
+ // Disable automatic clear control
+ USICNT |= USIIFGCC;
+
+ // Enable USI
+ USICTL0 &= ~USISWRST;
+
+ // Clear Flags
+ USICTL1 &= ~(USISTP | USIIFG | USISTTIFG);
+
+ // Enable I2C
+ USICTL1 |= USIIE | USISTTIE;
+
+ I2C_State = I2C_Idle;
+}
+
+static inline void Receive(uint8_t count)
+{
+ // set bit counter
+ USICNT |= count;
+
+ // SDA = input
+ USICTL0 &= ~USIOE;
+}
+
+static void TransmitData()
+{
+ I2C_State = I2C_TX_Data;
+
+ if(rx_start != rx_end) {
+ USISRL = rx_buffer[rx_start];
+ rx_start++;
+ rx_start &= BUFFER_MASK;
+ } else {
+ USISRL = 0x00;
+ }
+
+ // SDA = output
+ USICTL0 |= USIOE;
+
+ // Bit counter = 8
+ USICNT |= 0x08;
+}
+
+static void TransmitAck(uint8_t value)
+{
+ if(value) {
+ I2C_State = I2C_Idle;
+ USISRL = 0xFF;
+
+ } else {
+ I2C_State = I2C_TX_Ack;
+ USISRL = 0x00;
+ }
+
+ // SDA = output
+ USICTL0 |= USIOE;
+
+ // Bit counter = 1
+ USICNT |= 0x01;
+}
+
+interrupt(USI_VECTOR) IntServiceRoutineI2C()
+{
+ if (USICTL1 & USISTTIFG) { // Start?
+ I2C_State = I2C_RX_Addr;
+
+ // Bit counter = 8, RX address
+ USICNT = (USICNT & 0xE0) | 0x08;
+
+ } else switch(I2C_State++) {
+ case I2C_Idle:
+ I2C_State = I2C_Idle;
+ USICTL0 &= ~USIOE;
+ break;
+
+ case I2C_RX_Addr:
+ I2C_Offset = 0;
+
+ // Address match? if yes send [N]Ack depending on buffer state
+ if (USISRL == (I2C_Addr | I2C_Write)) {
+ TransmitAck(TxIndex() == tx_start);
+
+ } else if (USISRL == (I2C_Addr | I2C_Read)) {
+ TransmitAck(rx_start == rx_end);
+ I2C_State = I2C_RX_Ack;
+
+ } else {
+ // No address match -> ignored
+ I2C_State = I2C_Idle;
+ }
+ break;
+
+ case I2C_TX_Ack:
+ I2C_State = I2C_RX_Data;
+ Receive(8);
+ break;
+
+ case I2C_TX_Data:
+ Receive(1);
+ break;
+
+ case I2C_RX_Ack:
+ if(USISRL & 1) {
+ I2C_State = I2C_Idle;
+
+ } else {
+ TransmitData();
+
+ }
+ break;
+
+ case I2C_RX_Data:
+ tx_buffer[TxIndex()] = USISRL;
+ I2C_Offset++;
+
+ TransmitAck(TxIndex() == tx_start);
+ break;
+ }
+
+ // Clear Flags
+ USICTL1 &= ~(USIIFG | USISTTIFG);
+}
+
+interrupt(PORT1_VECTOR) IntServiceRoutinePort1()
+{
+ P1IFG &= ~0x80;
+
+ if(USICTL1 & USISTP) {
+ USICTL0 &= ~USIOE;
+ USICTL1 &= ~USISTP;
+ I2C_State = I2C_Idle;
+ if(I2C_Offset != 0) {
+ tx_buffer[tx_end] = I2C_Offset;
+ tx_end += I2C_Offset + 1;
+ tx_end &= BUFFER_MASK;
+ CEC_SendMessage();
+ }
+ }
+}*/
+
+#endif
diff --git a/msp430/main.c b/msp430/main.c
new file mode 100644
index 0000000..86f1a4f
--- /dev/null
+++ b/msp430/main.c
@@ -0,0 +1,52 @@
+/*
+ * Copyright
+ *
+ * Copyright (C) 2009-2010 Christian König (deathsimple@vodafone.de)
+ *
+ * License
+ *
+ * This program is free software; you can redistribute and/or modify
+ * program under the terms of GNU General Public license either version 3
+ * of the License, or (at your option) any later version.
+ *
+ */
+
+#include <io.h>
+#include <signal.h>
+
+#define DEBUG
+
+#include "i2c.h"
+#include "cec.h"
+
+struct buffer rx_buf;
+struct buffer tx_buf;
+
+static inline void OutputSMCLK()
+{
+#ifdef DEBUG
+ P1SEL |= 1 << 4;
+ P1DIR |= 1 << 4;
+#endif
+}
+
+int main()
+{
+ // disable watchdog timer and RESET pin
+ WDTCTL = WDTPW | WDTHOLD | WDTNMI;
+
+ // DCO=12MHz and SMCLK=1.5MHz
+ DCOCTL = CALDCO_12MHZ;
+ BCSCTL1 = CALBC1_12MHZ;
+ BCSCTL2 = DIVS_3;
+
+ OutputSMCLK();
+
+ I2C_Init();
+ CEC_Init();
+
+ while(1) {
+ WRITE_SR(LPM0_bits|GIE);
+ }
+ return 0;
+}