--- /dev/null
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) 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
+this service 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 make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. 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.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+\f
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+\f
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+\f
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+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
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+\f
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the 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 a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE 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.
+
+ END OF TERMS AND CONDITIONS
+\f
+ 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
+convey 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision 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, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This 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 Library General
+Public License instead of this License.
--- /dev/null
+The TAPR Open Hardware License
+Version 1.0 (May 25, 2007)
+Copyright 2007 TAPR – http://www.tapr.org/OHL
+
+PREAMBLE
+
+Open Hardware is a thing - a physical artifact, either electrical or
+mechanical - whose design information is available to, and usable by,
+the public in a way that allows anyone to make, modify, distribute, and
+use that thing. In this preface, design information is called
+"documentation" and things created from it are called "products."
+
+The TAPR Open Hardware License ("OHL") agreement provides a legal
+framework for Open Hardware projects. It may be used for any kind of
+product, be it a hammer or a computer motherboard, and is TAPR's
+contribution to the community; anyone may use the OHL for their Open
+Hardware project.
+
+Like the GNU General Public License, the OHL is designed to guarantee
+your freedom to share and to create. It forbids anyone who receives
+rights under the OHL to deny any other licensee those same rights to
+copy, modify, and distribute documentation, and to make, use and
+distribute products based on that documentation.
+
+Unlike the GPL, the OHL is not primarily a copyright license. While
+copyright protects documentation from unauthorized copying, modification,
+and distribution, it has little to do with your right to make, distribute,
+or use a product based on that documentation. For better or worse, patents
+play a significant role in those activities. Although it does not prohibit
+anyone from patenting inventions embodied in an Open Hardware design, and
+of course cannot prevent a third party from enforcing their patent rights,
+those who benefit from an OHL design may not bring lawsuits claiming that
+design infringes their patents or other intellectual property.
+
+The OHL addresses unique issues involved in the creation of tangible,
+physical things, but does not cover software, firmware, or code loaded
+into programmable devices. A copyright-oriented license such as the GPL
+better suits these creations.
+
+How can you use the OHL, or a design based upon it? While the terms and
+conditions below take precedence over this preamble, here is a summary:
+
+* You may modify the documentation and make products based upon it.
+
+* You may use products for any legal purpose without limitation.
+
+* You may distribute unmodified documentation, but you must include the
+complete package as you received it.
+
+* You may distribute products you make to third parties, if you either
+include the documentation on which the product is based, or make it
+available without charge for at least three years to anyone who requests
+it.
+
+* You may distribute modified documentation or products based on it, if
+you:
+ * License your modifications under the OHL.
+ * Include those modifications, following the requirements stated
+ below.
+ * Attempt to send the modified documentation by email to any of the
+ developers who have provided their email address. This is a good
+ faith obligation – if the email fails, you need do nothing more
+ and may go on with your distribution.
+
+* If you create a design that you want to license under the OHL, you
+should:
+ * Include this document in a file named LICENSE (with the appropriate
+ extension) that is included in the documentation package.
+ * If the file format allows, include a notice like “Licensed under
+ the TAPR Open Hardware License (www.tapr.org/OHL)” in each
+ documentation file. While not required, you should also include
+ this notice on printed circuit board artwork and the product
+ itself; if space is limited the notice can be shortened or
+ abbreviated.
+ * Include a copyright notice in each file and on printed circuit
+ board artwork.
+ * If you wish to be notified of modifications that others may make,
+ include your email address in a file named “CONTRIB.TXT” or
+ something similar.
+
+* Any time the OHL requires you to make documentation available to
+others, you must include all the materials you received from the
+upstream licensors. In addition, if you have modified the
+documentation:
+ * You must identify the modifications in a text file (preferably
+ named "CHANGES.TXT") that you include with the documentation.
+ That file must also include a statement like "These modifications
+ are licensed under the TAPR Open Hardware License."
+ * You must include any new files you created, including any
+ manufacturing files (such as Gerber files) you create in the
+ course of making products.
+ * You must include both "before" and "after" versions of all files
+ you modified.
+ * You may include files in proprietary formats, but you must also
+ include open format versions (such as Gerber, ASCII, Postscript,
+ or PDF) if your tools can create them.
+
+TERMS AND CONDITIONS
+
+1. Introduction
+1.1 This Agreement governs how you may use, copy, modify, and
+distribute Documentation, and how you may make, have made, and
+distribute Products based on that Documentation. As used in this
+Agreement, to "distribute" Documentation means to directly or indirectly
+make copies available to a third party, and to "distribute" Products
+means to directly or indirectly give, loan, sell or otherwise transfer
+them to a third party.
+
+1.2 "Documentation" includes:
+ (a) schematic diagrams;
+ (b) circuit or circuit board layouts, including Gerber and other
+ data files used for manufacture;
+ (c) mechanical drawings, including CAD, CAM, and other data files
+ used for manufacture;
+ (d) flow charts and descriptive text; and
+ (e) other explanatory material.
+Documentation may be in any tangible or intangible form of expression,
+including but not limited to computer files in open or proprietary
+formats and representations on paper, film, or other media.
+
+1.3 "Products" include:
+ (a) circuit boards, mechanical assemblies, and other physical parts
+ and components;
+ (b) assembled or partially assembled units (including components
+ and subassemblies); and
+ (c) parts and components combined into kits intended for assembly
+ by others;
+which are based in whole or in part on the Documentation.
+
+1.4 This Agreement applies to any Documentation which contains a
+notice stating it is subject to the TAPR Open Hardware License, and to
+all Products based in whole or in part on that Documentation. If
+Documentation is distributed in an archive (such as a "zip" file) which
+includes this document, all files in that archive are subject to this
+Agreement unless they are specifically excluded. Each person who
+contributes content to the Documentation is referred to in this
+Agreement as a "Licensor."
+
+1.5 By (a) using, copying, modifying, or distributing the
+Documentation, or (b) making or having Products made or distributing
+them, you accept this Agreement, agree to comply with its terms, and
+become a "Licensee." Any activity inconsistent with this Agreement will
+automatically terminate your rights under it (including the immunities
+from suit granted in Section 2), but the rights of others who have
+received Documentation, or have obtained Products, directly or
+indirectly from you will not be affected so long as they fully comply
+with it themselves.
+
+1.6 This Agreement does not apply to software, firmware, or code
+loaded into programmable devices which may be used in conjunction with
+Documentation or Products. Such software is subject to the license
+terms established by its copyright holder(s).
+
+2. Patents
+2.1 Each Licensor grants you, every other Licensee, and every
+possessor or user of Products a perpetual, worldwide, and royalty-free
+immunity from suit under any patent, patent application, or other
+intellectual property right which he or she controls, to the extent
+necessary to make, have made, possess, use, and distribute Products.
+This immunity does not extend to infringement arising from modifications
+subsequently made by others.
+
+2.2 If you make or have Products made, or distribute Documentation
+that you have modified, you grant every Licensor, every other Licensee,
+and every possessor or user of Products a perpetual, worldwide, and
+royalty-free immunity from suit under any patent, patent application, or
+other intellectual property right which you control, to the extent
+necessary to make, have made, possess, use, and distribute Products.
+This immunity does not extend to infringement arising from modifications
+subsequently made by others.
+
+2.3 To avoid doubt, providing Documentation to a third party for the
+sole purpose of having that party make Products on your behalf is not
+considered "distribution," and a third party's act of making Products
+solely on your behalf does not cause that party to grant the immunity
+described in the preceding paragraph.
+
+2.4 These grants of immunity are a material part of this Agreement,
+and form a portion of the consideration given by each party to the
+other. If any court judgment or legal agreement prevents you from
+granting the immunity required by this Section, your rights under this
+Agreement will terminate and you may no longer use, copy, modify or
+distribute the Documentation, or make, have made, or distribute
+Products.
+
+3. Modifications
+You may modify the Documentation, and those modifications will become
+part of the Documentation. They are subject to this Agreement, as are
+Products based in whole or in part on them. If you distribute the
+modified Documentation, or Products based in whole or in part upon it,
+you must email the modified Documentation in a form compliant with
+Section 4 to each Licensor who has provided an email address with the
+Documentation. Attempting to send the email completes your obligations
+under this Section and you need take no further action if any address
+fails.
+
+4. Distributing Documentation
+4.1 You may distribute unmodified copies of the Documentation in its
+entirety in any medium, provided that you retain all copyright and other
+notices (including references to this Agreement) included by each
+Licensor, and include an unaltered copy of this Agreement.
+4.2 You may distribute modified copies of the Documentation if you
+comply with all the requirements of the preceding paragraph and:
+ (a) include a prominent notice in an ASCII or other open format
+ file identifying those elements of the Documentation that you
+ changed, and stating that the modifications are licensed under
+ the terms of this Agreement;
+ (b) include all new documentation files that you create, as well as
+ both the original and modified versions of each file you change
+ (files may be in your development tool's native file format,
+ but if reasonably possible, you must also include open format,
+ such as Gerber, ASCII, Postscript, or PDF, versions);
+ (c) do not change the terms of this Agreement with respect to
+ subsequent licensees; and
+ (d) if you make or have Products made, include in the Documentation
+ all elements reasonably required to permit others to make
+ Products, including Gerber, CAD/CAM and other files used for
+ manufacture.
+
+5. Making Products
+5.1 You may use the Documentation to make or have Products made,
+provided that each Product retains any notices included by the Licensor
+(including, but not limited to, copyright notices on circuit boards).
+5.2 You may distribute Products you make or have made, provided that
+you include with each unit a copy of the Documentation in a form
+consistent with Section 4. Alternatively, you may include either (i) an
+offer valid for at least three years to provide that Documentation, at
+no charge other than the reasonable cost of media and postage, to any
+person who requests it; or (ii) a URL where that Documentation may be
+downloaded, available for at least three years after you last distribute
+the Product.
+
+6. NEW LICENSE VERSIONS
+TAPR may publish updated versions of the OHL which retain the same
+general provisions as the present version, but differ in detail to
+address new problems or concerns, and carry a distinguishing version
+number. If the Documentation specifies a version number which applies
+to it and "any later version", you may choose either that version or any
+later version published by TAPR. If the Documentation does not specify
+a version number, you may choose any version ever published by TAPR.
+TAPR owns the copyright to the OHL, but grants permission to any person
+to copy, distribute, and use it in unmodified form.
+
+7. WARRANTY AND LIABILITY LIMITATIONS
+7.1 THE DOCUMENTATION IS PROVIDED ON AN "AS-IS" BASIS WITHOUT
+WARRANTY OF ANY KIND, TO THE EXTENT PERMITTED BY APPLICABLE LAW. ALL
+WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
+TITLE, ARE HEREBY EXPRESSLY DISCLAIMED.
+7.2 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL ANY LICENSOR
+BE LIABLE TO YOU OR ANY THIRD PARTY FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, CONSEQUENTIAL, PUNITIVE, OR EXEMPLARY DAMAGES ARISING OUT OF
+THE USE OF, OR INABILITY TO USE, THE DOCUMENTATION OR PRODUCTS,
+INCLUDING BUT NOT LIMITED TO CLAIMS OF INTELLECTUAL PROPERTY
+INFRINGEMENT OR LOSS OF DATA, EVEN IF THAT PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+7.3 You agree that the foregoing limitations are reasonable due to
+the non-financial nature of the transaction represented by this
+Agreement, and acknowledge that were it not for these limitations, the
+Licensor(s) would not be willing to make the Documentation available to
+you.
+7.4 You agree to defend, indemnify, and hold each Licensor harmless
+from any claim brought by a third party alleging any defect in the
+design, manufacture, or operation of any Product which you make, have
+made, or distribute pursuant to this Agreement.
+ ####
--- /dev/null
+# Makefile for Wispcar schematics
+# Generates sch PDF
+# Derived from the BlackfinOne Makefile - thanks Ivan
+
+SCH_FILES = wispcar
+PROJECT = wispcar
+REV := $(shell svn info | grep Revision | sed 's/Revision: //')
+
+SCHPS = $(addsuffix .ps,$(SCH_FILES))
+SCHPDF = $(addsuffix .sch.ps,$(SCH_FILES))
+PWD = $(shell pwd)
+
+PCB_PRINT_OPTIONS = --ps-color --media A4
+
+all: schpdf
+
+%.ps: %.sch
+ gschem -o $@ -s gschem-print.scm $^
+
+schpdf: $(SCHPS)
+ -rm *_sch.ps
+ # sed stuff enlarges gschem font which is too small for my eyes :-)
+ cat $(SCHPS) | sed 's/scalefont/1.5 mul scalefont/' > $(PROJECT)_sch.ps
+ ps2pdf $(PROJECT)_sch.ps $(PROJECT)_sch.pdf
+
--- /dev/null
+/* used to prototype algorithm for 3 digit count down timer used in wispcar.asm */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main() {
+ int x,y,z;
+
+ x = 1;
+ y = 2;
+ z = 3;
+
+ while(1) {
+ if (z == 0) {
+ if (y == 0) {
+ if (x == 0) {
+ exit(0);
+ }
+ else {
+ x--;
+ y = 9;
+ z = 9;
+ }
+ }
+ else {
+ y--;
+ z = 9;
+ }
+ }
+ else {
+ z--;
+ }
+ printf("%d%d%d\n",x,y,z);
+ }
+
+}
+
--- /dev/null
+documentation.txt
+Created by David Rowe May 2008
+Wispcar project
+
+Files
+-----
+
+wispcar.asm........: PIC source code, compile and simulate
+ with Windows MPLAB 8.10 (free download)
+ Also explains Wispcar commands
+wispcar.sch........: gEDA gschem schematic
+Makefile...........: Creates PDF of schematic
+documentation.txt..: This file
+
+Project Plan
+------------
+
+[ ] WP100 Documentation
+ [ ] Create SVN repository
+ [ ] Draw schematic
+ [ ] Write Test Report
+ + Discuss tests performed
+ + how to repeat them
+ + results
+ [ ] Software
+ [ ] Write Design Notes
+ + explain various sections of design
+ + discuss trade offs
+
+[ ] WP200 Prototype Development
+ [ ] Breadboard Prototype
+ [X] PIC with RS232
+ [X] Current sensor
+ + high-side op-amp differential amp
+ [X] Power Switch
+ + used to switch power to AP
+ + controlled by watchdog and sleep function
+ [ ] Linear Regulator
+ [X] Watchdog software
+ [X] Sleep software
+ [ ] Construct Soldered Prototype
+ [ ] Install in Solar powered AP (Rowetel)
+
+[ ] WP300 Testing
+ [ ] Test to determine watchdog doesn't fire by mistake
+ + leave running for 1 week
+ + stable power & router
+ + ensure watchdog doesn't fire by mistake
+ [ ] Dirty power test
+ + work out a way to simulate a poor power supply
+ + for example put power supply in series with transformer
+ secondary, then modulate primary with pulses
+ + this will give big spikes on power line
+ + make sure PIC never hangs
+ [ ] Brown out test
+ + vary Vbat from 30V down to 2V 10 times
+ + make sure PIC does not hang
+
+Specs:
+-----
+
+1/ Measures Vbat and Ibat.
+
+ Vbat between 5 and 60V
+ Ibat between 0 and 5A
+
+ Measures Vbat and Ibat and reports every 1 sec to Host.
+
+2/ Watchdog
+
+ Fires if no RS232 rx for TBD1 secs from host
+ Power is shut off for 5 seconds then reapplied
+
+3/ Sleep
+
+ Send "sleepXXXX" to put power supply to sleep for XXXX seconds
+
+4/ Current consumption (estimated)
+
+ Vbat = 30V I=2mA
+ Vbat = 5V I=2mA
+
+ Note: we need to work out a way to get 60V operation, 78L05
+ regulator can't go above 35V.
+
+References
+----------
+
+1/ Zener power supply design:
+
+ http://www.kpsec.freeuk.com/powersup.htm
+
+2/ PIC10F510 datasheet from Microchip
+
+3/ 78L05 datasheet
+
+4/ IRF9540 datasheet
+
+Credits
+-------
+
+Tim Ansell (Mithro) for lending me his PIC collection and programmer
+Yahel Ben-David
+
+Notes
+-----
+
+1/ IRF9640 FET was selected largely at random. At 19A max it may be
+overkill, a cheaper FET may be more suitable.
+
+2/ The RS232 polarity may need to change when directly connected to a
+router without level conversion, see reference docs for RS232 software
+UART code in wispcar.asm. I used a MAX232 type chip for interfacing
+the RS232 tx & rx to a PC's serial port for testing.
+
+Gotcha
+------
+
+Can only use 'call' to call an address in the first 256 bytes, so put
+all funcs at the start of the program, main at the end.
+
+TODO List
+---------
+
+[ ] schematic
+ [ ] pinout of 78L05
+ [ ] pinout of power FET
+ [ ] pinout of BC548
+ [ ] connect + & - together on unsued op-amp sections
+ [ ] TAPR open harwdare license
+
+[ ] svn repository
+ + with datasheet pdfs ?
+[ ] wire correctly for power on reset
+ + test with dodgy power on curve (slow power up)
+[ ] blog post
+[ ] README in SVN
+[ ] test with WRT54
+[ ] add brown out detector to PIC reset to be double sure?
+ + see PIC data sheet
+[ ] check what happens in overvoltage on input, how can we protect?
+[ ] document test plan
+[X] make sure we can't stall in RS232 input routine
+ + need a way to get around this.....
+ + malformed RS323 could cause a hang
+ + maybe better to just look at h/l transition or something?
+ + sep pic for sleep function?
+ + solution: integrate 1 sec delay with RS232 rx
+[ ] Limitations
+ + need to send full command before 1 second delay?
+ + like send command immediately after ADC data
+ + need automatic reset from fragment
+ + like once every second
+ + or can it be spread over cycles?
+[ ] enable PIC watchdog timer
+ + how can we test?
+[ ] make sure all RS232 chars OK
+ + how to prog with calibrated clock?
+ + check baud rate
+ + is max232 OK at Vcc=5V?
+[ ] programming procedure to preserve osccal
+[X] make function to print decimal, rather than repeating all that code
+ + we can't as call stack is only two levels deep and we are at the limit
+
+[ ] automatic thrash tests (repeat each one for hours/days)
+ + maybe use expect
+ [ ] send sleep
+ + make sure we sleep
+ [ ] send 'w'
+ + make sure we dont WD time out
+ [ ] check for unlikely WD/sleep/reboot events
+ + especially under nasty conditions
+
+[ ] check how accurate the timing is
+ + is 1 sec delay accurate?
+
+[ ] work out how to run from 60V
+ + 78L05 pops at 35V
+
--- /dev/null
+(component-library "sym")
+(source-library "sym")
+
--- /dev/null
+(paper-size 11.5 8.5)
+(load (string-append gedadatarc "/gschem-lightbg")) ; light background
+(output-type "limits")
+(output-color "enabled")
+
+(text-color 9 "green4" "green4" "0 0 0" 0 0 0) ; light background
+(net-endpoint-color 2 "red" "red3" ".502 .094 .062" 128 24 16) ; light
+(graphic-color 3 "green4" "green4" "0 0 0" 0 0 0) ; light background
+(net-color 4 "blue2" "blue3" "0 0 0" 0 0 0) ; light background
+
+(output-text "ps")
+(gschem-use-rc-values) ;You need call this after you call any
+(gschem-print "dummyfilename") ;filename is specified on the command line
+(gschem-exit)
--- /dev/null
+v 20060906 1
+T 400 600 9 8 1 0 0 0 1
+IN
+T 948 600 9 8 1 0 0 0 1
+OUT
+T 900 100 9 8 1 0 0 0 1
+78L05
+B 300 300 1000 600 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1
+T 1600 1300 5 10 0 0 0 0 1
+device=78L05
+T 656 401 9 8 1 0 0 0 1
+GND
+P 300 600 0 600 1 0 1
+{
+T 100 650 5 8 1 1 0 0 1
+pinnumber=1
+T 100 650 5 8 0 0 0 0 1
+pinseq=1
+}
+P 800 0 800 300 1 0 0
+{
+T 700 100 5 8 1 1 0 0 1
+pinnumber=2
+T 700 100 5 8 0 0 0 0 1
+pinseq=2
+}
+P 1300 600 1600 600 1 0 1
+{
+T 1430 650 5 8 1 1 0 0 1
+pinnumber=3
+T 1430 650 5 8 0 0 0 0 1
+pinseq=3
+}
+T 1400 1000 8 10 1 1 0 6 1
+refdes=U?
+T 1600 1100 5 10 0 0 0 0 1
+pins=3
+T 1600 900 5 10 0 0 0 0 1
+net=GND:2
--- /dev/null
+v 20060906 1
+B 300 200 1200 1600 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1
+P 0 1600 300 1600 1 0 0
+{
+T 200 1650 5 8 1 1 0 6 1
+pinnumber=1
+T 400 1550 5 8 1 1 0 0 1
+pinlabel=VCC
+T 0 1950 5 8 0 1 0 2 1
+pintype=pwr
+}
+P 0 400 300 400 1 0 0
+{
+T 200 450 5 8 1 1 0 6 1
+pinnumber=4
+T 400 350 5 8 1 1 0 0 1
+pinlabel=GP3
+T 0 750 5 8 0 1 0 2 1
+pintype=in
+}
+P 0 800 300 800 1 0 0
+{
+T 200 850 5 8 1 1 0 6 1
+pinnumber=3
+T 400 750 5 8 1 1 0 0 1
+pinlabel=GP4
+T 0 1050 5 8 0 1 0 2 1
+pintype=tri
+}
+P 0 1200 300 1200 1 0 0
+{
+T 200 1250 5 8 1 1 0 6 1
+pinnumber=2
+T 400 1150 5 8 1 1 0 0 1
+pinlabel=GP5
+T 0 1550 5 8 0 1 0 2 1
+pintype=tri
+}
+T 2400 800 5 10 0 0 0 0 1
+device=PIC12F510
+T 1650 150 9 10 1 1 180 0 1
+PIC12F510 DIP8
+T 2400 500 5 10 0 0 0 0 1
+footprint=DIP8
+T 2400 200 5 10 0 0 0 0 1
+description=PCI Microcontroller
+T -1300 500 5 10 0 0 0 0 1
+numslots=0
+P 1800 1600 1500 1600 1 0 0
+{
+T 1600 1650 5 8 1 1 0 0 1
+pinnumber=1
+T 1450 1550 5 8 1 1 0 6 1
+pinlabel=GND
+T 2100 1700 5 8 0 1 0 8 1
+pintype=pwr
+}
+P 1800 400 1500 400 1 0 0
+{
+T 1600 450 5 8 1 1 0 0 1
+pinnumber=4
+T 1450 350 5 8 1 1 0 6 1
+pinlabel=GP2
+T 2000 450 5 8 0 1 0 8 1
+pintype=io
+}
+P 1800 800 1500 800 1 0 0
+{
+T 1600 850 5 8 1 1 0 0 1
+pinnumber=3
+T 1450 750 5 8 1 1 0 6 1
+pinlabel=GP1
+T 2000 950 5 8 0 1 0 8 1
+pintype=io
+}
+P 1800 1200 1500 1200 1 0 0
+{
+T 1600 1250 5 8 1 1 0 0 1
+pinnumber=2
+T 1450 1150 5 8 1 1 0 6 1
+pinlabel=GP0
+T 2050 1300 5 8 0 1 0 8 1
+pintype=tri
+}
+T 550 1950 8 10 1 1 0 6 1
+refdes=U?
--- /dev/null
+v 20060123 1
+P 200 0 200 200 1 0 0
+{
+T 250 50 5 6 0 1 0 0 1
+pinnumber=1
+T 250 50 5 6 0 0 0 0 1
+pinseq=1
+T 900 100 5 10 0 0 0 0 1
+pintype=pas
+}
+L 50 200 350 200 3 0 0 0 -1 -1
+T 75 250 9 8 1 0 0 0 1
++5V
+T 300 0 8 8 0 0 0 0 1
+net=+5V:1
--- /dev/null
+v 20050820 1
+P 0 200 200 200 1 0 0
+{
+T 100 250 5 8 0 1 0 0 1
+pinnumber=1
+T 100 250 5 8 0 0 0 0 1
+pinseq=1
+T 0 100 5 10 0 0 0 0 1
+pintype=pas
+}
+P 900 200 700 200 1 0 0
+{
+T 700 250 5 8 0 1 0 0 1
+pinnumber=2
+T 700 250 5 8 0 0 0 0 1
+pinseq=2
+T 0 100 5 10 0 0 0 0 1
+pintype=pas
+}
+L 400 400 400 0 3 0 0 0 -1 -1
+L 500 400 500 0 3 0 0 0 -1 -1
+L 700 200 500 200 3 0 0 0 -1 -1
+L 400 200 200 200 3 0 0 0 -1 -1
+T 300 600 5 10 0 0 0 0 1
+device=CAPACITOR
+T 200 500 8 10 1 1 0 0 1
+refdes=C?
+T 0 0 8 10 0 1 0 0 1
+pins=2
+T 0 0 8 10 0 1 0 0 1
+class=DISCRETE
--- /dev/null
+v 20031231 1
+P 0 200 200 200 1 0 0
+{
+T 100 250 5 8 0 1 0 0 1
+pinnumber=1
+T 100 250 5 8 0 0 0 0 1
+pinseq=1
+T 0 100 5 10 0 0 0 0 1
+pintype=pas
+}
+P 900 200 700 200 1 0 0
+{
+T 700 250 5 8 0 1 0 0 1
+pinnumber=2
+T 700 250 5 8 0 0 0 0 1
+pinseq=2
+T 0 100 5 10 0 0 0 0 1
+pintype=pas
+}
+L 400 400 400 0 3 0 0 0 -1 -1
+L 700 200 500 200 3 0 0 0 -1 -1
+L 400 200 200 200 3 0 0 0 -1 -1
+T 400 600 5 10 0 0 0 0 1
+device=POLARIZED_CAPACITOR
+A 1200 200 700 165 30 3 0 0 0 -1 -1
+L 289 400 289 300 3 0 0 0 -1 -1
+L 340 349 240 349 3 0 0 0 -1 -1
+T 200 500 8 10 1 1 0 0 1
+refdes=C?
+T 0 0 8 10 0 1 0 0 1
+pins=2
+T 0 0 8 10 0 1 0 0 1
+class=DISCRETE
--- /dev/null
+v 20050820 1
+B 300 200 1200 700 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1
+P 1800 400 1500 400 1 0 0
+{
+T 1600 450 5 8 1 1 0 0 1
+pinnumber=1
+T 1600 450 5 8 0 1 0 0 1
+pinseq=1
+T 1400 350 5 8 1 1 0 6 1
+pinlabel=EN
+T 1600 450 5 8 0 1 0 8 1
+pintype=pas
+}
+P 0 700 300 700 1 0 0
+{
+T 200 750 5 8 1 1 0 6 1
+pinnumber=4
+T 200 750 5 8 0 1 0 6 1
+pinseq=4
+T 400 650 5 8 1 1 0 0 1
+pinlabel=VCC
+T 200 750 5 8 0 1 0 2 1
+pintype=pwr
+}
+P 1800 700 1500 700 1 0 0
+{
+T 1600 750 5 8 1 1 0 0 1
+pinnumber=3
+T 1600 750 5 8 0 1 0 0 1
+pinseq=2
+T 1400 650 5 8 1 1 0 6 1
+pinlabel=OUT
+T 1600 750 5 8 0 1 0 8 1
+pintype=out
+}
+P 0 400 300 400 1 0 0
+{
+T 200 450 5 8 1 1 0 6 1
+pinnumber=2
+T 200 450 5 8 0 1 0 6 1
+pinseq=3
+T 400 350 5 8 1 1 0 0 1
+pinlabel=GND
+T 200 450 5 8 0 1 0 2 1
+pintype=pwr
+}
+T 1900 800 5 10 0 0 0 0 1
+device=CLOCK OSC
+T 1450 150 9 10 1 1 180 0 1
+CLOCK OSC
+T 1900 500 5 10 0 0 0 0 1
+footprint=bf_XTALOSC
+T 1900 200 5 10 0 0 0 0 1
+description=Hi-Q QMSO-4200 Series
+T 1900 0 5 10 0 0 0 0 1
+documentation=TBD
+T 300 1100 8 10 1 1 0 0 1
+refdes=U?
+T -1300 500 5 10 0 0 0 0 1
+numslots=0
--- /dev/null
+v 20050820 1
+L 600 200 500 0 3 0 0 0 -1 -1
+L 500 0 400 200 3 0 0 0 -1 -1
+L 400 200 300 0 3 0 0 0 -1 -1
+L 300 0 200 200 3 0 0 0 -1 -1
+T 300 400 5 10 0 0 0 0 1
+device=RESISTOR
+L 600 200 700 0 3 0 0 0 -1 -1
+L 700 0 750 100 3 0 0 0 -1 -1
+P 900 100 750 100 1 0 0
+{
+T 800 150 5 8 0 1 0 0 1
+pinnumber=2
+T 800 150 5 8 0 0 0 0 1
+pinseq=2
+T 900 100 5 10 0 0 0 0 1
+pintype=pas
+}
+P 0 100 152 100 1 0 0
+{
+T 100 150 5 8 0 1 0 0 1
+pinnumber=1
+T 100 150 5 8 0 0 0 0 1
+pinseq=1
+T 0 100 5 10 0 0 0 0 1
+pintype=pas
+}
+L 201 200 150 100 3 0 0 0 -1 -1
+T 200 300 8 10 1 1 0 0 1
+refdes=R?
+T 0 0 8 10 0 1 0 0 1
+pins=2
+T 0 0 8 10 0 1 0 0 1
+class=DISCRETE
--- /dev/null
+v 20060123 1
+L 300 100 300 700 3 0 0 0 -1 -1
+L 300 700 700 700 3 0 0 0 -1 -1
+T 500 800 5 10 0 0 0 0 1
+device=7400
+T 500 1000 5 10 0 0 0 0 1
+slot=1
+T 500 1200 5 10 0 0 0 0 1
+numslots=4
+T 500 1400 5 10 0 0 0 0 1
+slotdef=1:1,2,3
+T 500 1600 5 10 0 0 0 0 1
+slotdef=2:4,5,6
+T 500 1800 5 10 0 0 0 0 1
+slotdef=3:9,10,8
+T 500 2000 5 10 0 0 0 0 1
+slotdef=4:12,13,11
+L 300 100 700 100 3 0 0 0 -1 -1
+A 700 400 300 270 180 3 0 0 0 -1 -1
+V 1050 400 50 6 0 0 0 -1 -1 0 -1 -1 -1 -1 -1
+P 1100 400 1300 400 1 0 1
+{
+T 1100 450 5 8 1 1 0 0 1
+pinnumber=3
+T 1100 350 5 8 0 1 0 2 1
+pinseq=3
+T 950 400 9 8 0 1 0 6 1
+pinlabel=Y
+T 950 400 5 8 0 1 0 8 1
+pintype=out
+}
+P 300 200 0 200 1 0 1
+{
+T 200 250 5 8 1 1 0 6 1
+pinnumber=2
+T 200 150 5 8 0 1 0 8 1
+pinseq=2
+T 350 200 9 8 0 1 0 0 1
+pinlabel=B
+T 350 200 5 8 0 1 0 2 1
+pintype=in
+}
+P 300 600 0 600 1 0 1
+{
+T 200 650 5 8 1 1 0 6 1
+pinnumber=1
+T 200 550 5 8 0 1 0 8 1
+pinseq=1
+T 350 600 9 8 0 1 0 0 1
+pinlabel=A
+T 350 600 5 8 0 1 0 2 1
+pintype=in
+}
+T 300 800 8 10 1 1 0 0 1
+refdes=U?
+T 500 2150 5 10 0 0 0 0 1
+footprint=DTSSOP-14
+T 500 2350 5 10 0 0 0 0 1
+description=4 NAND gates with 2 inputs
+T 500 2550 5 10 0 0 0 0 1
+documentation=http://www-s.ti.com/sc/ds/sn74hc00.pdf
+T 0 0 8 8 0 0 0 0 1
+author=Ivan Danov
+T 0 0 8 8 0 0 0 0 1
+email=idanov@gmail.com
+T 0 0 8 8 0 0 0 0 1
+dist-license=GPL
+T 0 0 8 8 0 0 0 0 1
+use-license=unlimited
--- /dev/null
+v 20060906 1
+T 600 500 5 10 0 0 0 0 1
+device=PMOS_TRANSISTOR
+T 600 500 5 10 0 0 0 0 1
+numslots=0
+T 600 500 5 10 0 0 0 0 1
+description=generic P channel MOS transistor (enhancement type)
+L 250 600 500 600 3 0 0 0 -1 -1
+L 250 200 500 200 3 0 0 0 -1 -1
+L 300 350 400 400 3 0 0 0 -1 -1
+L 300 450 400 400 3 0 0 0 -1 -1
+P 0 200 200 200 1 0 0
+{
+T 0 300 5 10 0 1 0 0 1
+pinnumber=G
+T 0 300 9 10 1 1 0 0 1
+pinlabel=G
+T 0 300 5 10 0 0 0 0 1
+pinseq=2
+T 0 300 5 10 0 0 0 0 1
+pintype=pas
+}
+P 500 600 500 800 1 0 1
+{
+T 300 700 5 10 0 1 0 0 1
+pinnumber=D
+T 300 700 9 10 1 1 0 0 1
+pinlabel=D
+T 300 700 5 10 0 0 0 0 1
+pinseq=1
+T 300 700 5 10 0 0 0 0 1
+pintype=pas
+}
+P 500 200 500 0 1 0 1
+{
+T 300 0 5 10 0 1 0 0 1
+pinnumber=S
+T 300 0 9 10 1 1 0 0 1
+pinlabel=S
+T 300 0 5 10 0 0 0 0 1
+pinseq=3
+T 300 0 5 10 0 0 0 0 1
+pintype=pas
+}
+T 700 600 8 10 1 1 0 0 1
+refdes=Q?
+L 250 675 250 525 3 0 0 0 -1 -1
+L 250 475 250 325 3 0 0 0 -1 -1
+L 250 275 250 125 3 0 0 0 -1 -1
+L 200 600 200 200 3 0 0 0 -1 -1
+L 250 400 400 400 3 0 0 0 -1 -1
+L 400 400 400 200 3 0 0 0 -1 -1
--- /dev/null
+; wispcar.asm\r
+; David Rowe May 2008\r
+;\r
+; PIC12F510 Assembler program, MPLAB V8.10 IDE used to build.\r
+;\r
+; ********************************************************\r
+; * Wifi Station Power Controller And Reporter - WiSPCaR *\r
+; ********************************************************\r
+;\r
+;---------------------------------------------------------------------\r
+; Copyright (C) 2008 David Rowe\r
+;\r
+; This program is free software; you can redistribute it and/or modify\r
+; it under the terms of the GNU General Public License as published by\r
+; the Free Software Foundation; either version 2 of the License, or\r
+; (at your option) any later version.\r
+;\r
+; This program is distributed in the hope that it will be useful,\r
+; but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+; GNU General Public License for more details.\r
+;\r
+; You should have received a copy of the GNU General Public License\r
+; along with this program; if not, write to the Free Software\r
+; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 \r
+; USA\r
+;---------------------------------------------------------------------\r
+;\r
+; FUNCTIONS\r
+; =========\r
+;\r
+; 1/ Monitor Voltage\r
+; 2/ Monitor Current\r
+; 3/ Watchdog timer\r
+; 4/ Sleep timer\r
+;\r
+;\r
+; PINOUT\r
+; ======\r
+; ____ ____\r
+; | \/ | \r
+; Vcc --| 1 8 |-- GND\r
+; | |\r
+; Spare I/O --| 2 7 |-- Vsense (in)\r
+; | |\r
+; RS232 Tx (out) --| 3 6 |-- PowerSwitch (out)\r
+; | |\r
+; RS232 Rx (in) --| 4 5 |-- Isense (in)\r
+; |__________|\r
+;\r
+;\r
+; Pin | Function | PIC Name\r
+; -----|-------------|---------\r
+; 2 | Spare I/O | GP5 \r
+; 3 | RS232 Tx | GP4\r
+; 4 | RS232 Rx | GP3\r
+; 5 | Isense | AN2\r
+; 6 | PowerSwitch | GP1\r
+; 7 | Vsense | AN0\r
+;\r
+; \r
+; PIC PROGRAMMING OPTIONS\r
+; =======================\r
+;\r
+; 8MHz clock, MCLRE=I/O, INTOSC\r
+;\r
+;\r
+; 4800 BAUD RS232 OUTPUT\r
+; ======================\r
+;\r
+; Vsense\r
+; | Isense\r
+; | | Last char received (ASCII)\r
+; | | | Last char received (decimal)\r
+; | | | | Watchdog timeout counter\r
+; | | | | | Watchdog fire counter\r
+; | | | | | | Sleep state machine state\r
+; | | | | | | | Sleep timeout counter\r
+; | | | | | | | | \r
+; 040 031 032 012 000 0 000 w---reason for last restart\r
+; b - Wispcar (re)booted \r
+; w - watchdog timer fired \r
+; s - we went to sleep\r
+;\r
+;\r
+; COMMANDS\r
+; ========\r
+;\r
+; 1/ Send a 'w' every WD_TIMEOUT seconds to prevent Watchdog timer\r
+; firing and cutting power.\r
+;\r
+; 2/ Send the string 'sleepxyz' to cut the power for xyz seconds,\r
+; where x,y and z are digits in the range 0-9. If any part of the\r
+; string is invalid it will be ignored. Wait 5 seconds and start\r
+; again.\r
+;\r
+; 3/ Wispcar cannot rx and tx RS232 at the same time. It is best to\r
+; wait until just after the output line is received by the host, then\r
+; send your command. If the command (such as sleep) gets messed up,\r
+; just wait 5 seconds and wispcar will reset it's internal state\r
+; machine. You can then try again.\r
+;\r
+; 4/ The final field is reset to a space when a 'w' is sent to\r
+; Wispcar. This field lets the host know just _why_ it was rebooted.\r
+\r
+#include <p12f510.inc>\r
+\r
+; VARIABLES ---------------------------------------------------------------------\r
+\r
+TEMP equ 0x10\r
+SERBUF equ 0x11 ; RS232 char to transmit\r
+count equ 0x12 ; temp reg used by "BIN2BCD" and "baud" routines\r
+BIN equ 0x13 \r
+huns equ 0x14\r
+tens equ 0x15\r
+ones equ 0x16\r
+thirty equ 0x17 ; constant set to (guess what) 30\r
+SERBUFI equ 0x18 ; last RS232 character we received\r
+wd_timeout equ 0x19 ; current watchdog timer value (in secs)\r
+ ; when this hits zero we turn the power off\r
+wd_fire equ 0x1a ; count down timer when watchdog fires (in secs)\r
+restart_flag equ 0x1b ; tells host why we just restarted (WD or sleep)\r
+\r
+sleep_state equ 0x1c\r
+sleep_timeout equ 0x1d ; current value of sleep time out (in secs)\r
+ ; measures time between rx-ed chars in\r
+ ; s-l-e-e-p-x-y-z sequence.\r
+ ; If this hits zero (like s-l- (BIG GAP))\r
+ ; we assume sleep command\r
+ ; was invalid and we reset the input state machine\r
+\r
+ ; three digit sleep time (up to 999 secs)\r
+ ; these count down to zero while we are sleeping\r
+ ; when count down hits 0 power is switched back on\r
+\r
+sleeping equ 0x1e ; asserted if we are sleeping (power off)\r
+\r
+; following variables are in bank1, which makes life difficult....\r
+\r
+d1 equ 0x10\r
+d2 equ 0x11\r
+d3 equ 0x12\r
+\r
+x equ 0x13 ; sleep time (hundreds of secs)\r
+y equ 0x14 ; sleep time (tens of secs)\r
+z equ 0x15 ; sleep time (secs)\r
+\r
+; CONSTANTS ---------------------------------------------------------------------\r
+\r
+WD_TIMEOUT equ d'18' ; watchdog timeout in seconds\r
+WD_FIRE equ d'5' ; watchdog firing time in seconds\r
+ ; how long power is cut off to host\r
+\r
+SLEEP_TIMEOUT equ d'5' ; timeout between rx-ed chars in sleep input\r
+ ; sequence.\r
+\r
+; Values for restart_flag - tell host why we just cut power after we woke up\r
+\r
+BOOT_FLAG equ 'b' ; Wispcar just rebooted\r
+WD_FLAG equ 'w' ; Watchdog fired\r
+SLEEP_FLAG equ 's' ; We slept\r
+\r
+; START PROGRAM ----------------------------------------------------------------\r
+\r
+; set up osc cal (temp code just for experimenting)\r
+; TODO - FIX ME for general case\r
+\r
+ movlw 16\r
+ movwf OSCCAL\r
+\r
+; configure AN[1:0] as analog inputs\r
+\r
+ movlw b'10110001'\r
+ movwf ADCON0 \r
+\r
+; configure GP[3] as digital input (RS232 RX)\r
+; configure GP[4] as digital output (RS232 TX)\r
+; configure GP[1] as digital output (PowerSwitch)\r
+\r
+; disble the comparitor so we can use GP[1]\r
+\r
+ bcf CM1CON0,3\r
+\r
+ ; set up GPIO directions\r
+\r
+ movlw b'00001101'\r
+ tris GPIO\r
+\r
+; turn on PowerSwitch \r
+\r
+ bsf GPIO,1 \r
+\r
+; set up a convenient constant\r
+\r
+ movlw h'30'\r
+ movwf thirty\r
+\r
+; init watchdog \r
+\r
+ movlw WD_TIMEOUT\r
+ movwf wd_timeout\r
+ clrf wd_fire\r
+\r
+; init sleep\r
+\r
+ clrf sleep_state\r
+ clrf sleeping \r
+ clrf sleep_timeout \r
+ bsf FSR,5 ; x,y,z are in bank 1 (grumble)\r
+ clrf x\r
+ clrf y\r
+ clrf z\r
+ bcf FSR,5 ; x,y,z are in bank 1 (grumble)\r
+\r
+; init restart_flag\r
+\r
+ movlw BOOT_FLAG\r
+ movwf restart_flag\r
+\r
+ goto main\r
+\r
+; START FUNCTIONS ------------------------------------------------------------\r
+\r
+; BIN2BCD\r
+;\r
+; Convert 8 bit value in BIN to a 3 digit decimal value.\r
+;\r
+; in.......: BIN\r
+; out......: huns, tens, ones\r
+; Reference: http://www.piclist.com/techref/microchip/math/radix/b2a-8b3d-ab.htm\r
+;\r
+; Uses temp reg 'count'\r
+\r
+; uses ADD-3 algorithm\r
+\r
+BIN2BCD\r
+ movlw 8\r
+ movwf count\r
+ clrf huns\r
+ clrf tens\r
+ clrf ones\r
+BCDADD3\r
+ movlw 5\r
+ subwf huns, 0\r
+ btfsc STATUS, C\r
+ CALL ADD3HUNS\r
+\r
+ movlw 5\r
+ subwf tens, 0\r
+ btfsc STATUS, C\r
+ CALL ADD3TENS\r
+\r
+ movlw 5\r
+ subwf ones, 0\r
+ btfsc STATUS, C\r
+ CALL ADD3ONES\r
+\r
+ decf count, 1\r
+ bcf STATUS, C\r
+ rlf BIN, 1\r
+ rlf ones, 1\r
+ btfsc ones,4 ; \r
+ CALL CARRYONES\r
+ rlf tens, 1\r
+\r
+ btfsc tens,4 ; \r
+ CALL CARRYTENS\r
+ rlf huns,1\r
+ bcf STATUS, C\r
+\r
+ movf count, 0\r
+ btfss STATUS, Z\r
+ GOTO BCDADD3\r
+\r
+ movf huns, 0 ; add ASCII Offset\r
+ addwf thirty, 0\r
+ movwf huns\r
+\r
+ movf tens, 0 ; add ASCII Offset\r
+ addwf thirty, 0\r
+ movwf tens\r
+\r
+ movf ones, 0 ; add ASCII Offset\r
+ addwf thirty, 0\r
+ movwf ones\r
+\r
+ retlw 0\r
+\r
+ADD3HUNS\r
+ movlw 3\r
+ addwf huns,1\r
+ retlw 0\r
+\r
+ADD3TENS\r
+ movlw 3\r
+ addwf tens,1\r
+ retlw 0\r
+\r
+ADD3ONES\r
+ movlw 3\r
+ addwf ones,1\r
+ retlw 0\r
+\r
+CARRYONES\r
+ bcf ones, 4\r
+ bsf STATUS, C\r
+ retlw 0\r
+\r
+CARRYTENS\r
+ bcf tens, 4\r
+ bsf STATUS, C\r
+ retlw 0 \r
+\r
+; INCH_N is from "PIC Software UART Routines"\r
+; John Massa, Datadog Systems (C) 2005\r
+\r
+; ********************************************************************\r
+; INCH_N\r
+; THIS ROUTINE INPUTS RS232 DATA USING AN INVERTER, LIKE THE MAX232.\r
+; THIS ROUTINE USES A 8-DATA BIT PER CHARACTER PROTOCOL\r
+; GPIO,0 = RX (MARK = 1, SPACE = 0).\r
+; TO RECIEVE A CHARACTER, CALL inch_n, THE RECEIVED CHARACTER IS PLACED\r
+; IN THE REG 'W' AND IN THE REG 'SERBUF'.\r
+; THE RECEIVED CHARACTER WILL ECHO IF 'RETLW 0' IS REM-ED OUT.\r
+; VARIABLES USED: REG 'TEMP' AND REG 'SERBUF' BOTH VARIABLES ARE\r
+; SHARED WITH THE 'outch_n' ROUTINE.\r
+; ROUTINES CALLED: 'half_baud'AND 'baud' TO SET THE BAUD-RATE\r
+; ********************************************************************\r
+\r
+; Modified by David Rowe May 2008 to combine a 1 second delay with\r
+; character reception.\r
+\r
+inch_n_delay\r
+\r
+ ; clear previous rx char\r
+\r
+ movlw ' '\r
+ movwf SERBUFI\r
+\r
+ ; init delay loop for 1999996 cycles\r
+\r
+ bsf FSR,5 ; d1, d2, d3 in Bank 1 (groan)\r
+ movlw 0x11\r
+ movwf d1\r
+ movlw 0x5D\r
+ movwf d2\r
+ movlw 0x05\r
+ movwf d3\r
+\r
+wait_for_start\r
+ bcf FSR,5 ; just in case goto below fires\r
+ btfss GPIO,3 ; SKIP UNLESS WE GET A START BIT = 1 (A "MARK")\r
+ goto start_serial ; start bit - process character\r
+\r
+ ; process delay loop while we look for start bit\r
+\r
+ bsf FSR,5\r
+ decfsz d1, f\r
+ goto $+2\r
+ decfsz d2, f\r
+ goto $+2\r
+ decfsz d3, f\r
+ goto wait_for_start\r
+\r
+ ; delay finished\r
+\r
+ bcf FSR,5 \r
+ retlw 0\r
+ \r
+start_serial\r
+ bsf GPIO,5\r
+ bcf GPIO,5\r
+\r
+ movlw 8 ; START SERIAL INPUT SEQUENCE\r
+ movwf TEMP ; COLLECT 8 DATA BITS\r
+ clrf SERBUFI ; CLEAR SERIAL CHARACTER BUFFER\r
+ call half_baud ; DELAY FOR ONE HALF BAUD TIME\r
+ btfsc GPIO,3 ; FALL THRU IF START BIT STILL = 1 (A "MARK")\r
+ goto wait_for_start ; ELSE IT WAS JUST A NOISE SPIKE, KEEP LOOKING\r
+inch_n1\r
+ call baud ; DELAY ONE BAUD-BIT TIME ( = 1/BAUD-RATE)\r
+ bcf STATUS,0 ; CLEAR THE CARRY BIT\r
+ rrf SERBUFI,F ; ROTATE CRY -> MSB, ROTATE MSB RIGHT\r
+ btfsc GPIO,3 ; IS IT A "MARK" ?\r
+ bsf SERBUFI,7 ; ...SKIP IF YES, ELSE SET BIT TO LOGIC '1'\r
+ decfsz TEMP,F ; EIGHT COUNTS YET?\r
+ goto inch_n1 ; ...NO, GET ANOTHER BIT\r
+ call baud ; DELAY FOR THE STOP BIT\r
+ movf SERBUFI,W ; PUT THE RECEIVED CHARACTER IN REG 'W'\r
+\r
+ ; process received character, this can be considered an "event\r
+ ; handler" for rx-chars. We expect either a 'w' to reset the\r
+ ; watchdog or a tightly defined sequence of sleep characters.\r
+\r
+ movlw 'w' \r
+ subwf SERBUFI,0 ; is it a 'w' for watchdog reset?\r
+ btfss STATUS,Z ; skip if received char matches\r
+ goto handle_sleepin ; only process sleep input if not a 'w'\r
+\r
+ ; handle 'w' input \r
+ \r
+ ; Note if we are sleeping or WD is firing we will keep power\r
+ ; off and receiving 'w' will have no effect. Unlikely unless\r
+ ; device sending rx chars is powered indepednantly (ie during\r
+ ; testing).\r
+\r
+ movlw WD_TIMEOUT ; reset watchdog timer\r
+ movwf wd_timeout\r
+\r
+ movlw ' ' ; clear reboot flag\r
+ movwf restart_flag\r
+\r
+ clrf sleep_state ; reset sleep state machine for good measure\r
+ clrf sleep_timeout ; just in case we get s-l-w-e-e-p or something\r
+\r
+ goto wait_for_start\r
+\r
+handle_sleepin\r
+ call sleep_input\r
+ goto wait_for_start\r
+\r
+; OUTCH_N and BAUD are from "PIC Software UART Routines"\r
+; John Massa, Datadog Systems (C) 2005\r
+\r
+;*********************************************************************\r
+; OUTCH_N\r
+; THIS ROUTINE OUTPUTS RS232 DATA THROUGH AN INVERTER.\r
+; THIS ROUTINE USES AN 8-DATA BIT PER CHARACTER PROTOCOL.\r
+; TO PRINT A CHARACTER, LOAD BYTE INTO REG 'W' AND CALL outch_n.\r
+; GPIO,1 = TX (MARK = 1, SPACE = 0) ; USE INVERTER ON THE OUTPUT\r
+; VARIABLES USED: REG 'TEMP' AND SHARE REG 'SERBUF' WITH THE ROUTINE\r
+; 'inch_n'\r
+; CALLS THE ROUTINE 'baud' TO SET THE BAUD-RATE TIMING.\r
+;*********************************************************************\r
+\r
+outch_n ; THIS ROUTINE USES 8 DATA BITS\r
+ movwf SERBUF ; SERBUF CONTAINS CHARACTER TO XMT\r
+ movlw 8 ; THE CHARACTER HAS 8 BITS\r
+ movwf TEMP\r
+ bcf GPIO,4 ; SET START-BIT TO A "SPACE"\r
+ call baud ; WAIT ONE BAUD TIME\r
+outch_n1\r
+ rrf SERBUF,F ; ROTATE THE FIRST BIT INTO CARRY\r
+ btfss STATUS,0 ; TEST THE CARRY BIT\r
+ bcf GPIO,4 ; IF BIT IS 0 SET OUTPUT PIN TO A "0" (SPACE)\r
+ btfsc STATUS,0 ; TEST THE CARRY BIT AGAIN\r
+ bsf GPIO,4 ; IF BIT IS 1 SET OUTPUT PIN TO A "1" (MARK)\r
+ call baud ; ONE BAUD-BIT DELAY\r
+ decfsz TEMP,F ; IF COUNT IS ZERO THEN XMIT A STOP BIT\r
+ goto outch_n1 ; ...ELSE XMIT NEXT BIT\r
+ rrf SERBUF,F ; ROTATE CARRY, GET THE MSB BACK INTO BIT 7\r
+ bsf GPIO,4 ; SET PIN TO A 1 (A "MARK") FOR THE STOP BIT\r
+ call baud ; FIRST BAUD-BIT DELAY\r
+ call baud ; SECOND BAUD-BIT DELAY\r
+ retlw 0 ; RETURN WITH THE CHARACTER IN SERBUF\r
+ \r
+; ********************************************************************\r
+; BAUD ROUTINE @ 4 MHz\r
+; BAUD RATE: CONSTANT:\r
+; 1200 Baud D'137'\r
+; 2400 Baud D'68'\r
+; 4800 Baud D'34'\r
+; 9600 Baud D'16'\r
+; 19200 Baud D'8'\r
+; 38400 Baud and up - use 'NOP' delays\r
+; VARIABLES USED: REG 'count'\r
+; ROUTINES CALLED: NONE\r
+; ********************************************************************\r
+\r
+baud ; AT 2400 BAUD THE PERIOD IS 416.6 US\r
+ ; CLK = 4MHz\r
+ movlw D'68' ; 1 US (BAUD RATE CONSTANT)\r
+ movwf count ; 1 US\r
+baud1\r
+ decfsz count,F ; 1 US (+ 1 US MORE IF SKIP)\r
+ goto baud1 ; 2 US\r
+ ; FALL THRU...AFTER 1+1+3x68+1 = 207 US\r
+half_baud\r
+ movlw D'68' ; 1 US\r
+ movwf count ; 1 US\r
+hbaud1\r
+ decfsz count,F ; 1 US (+ 1 US MORE IF SKIP)\r
+ goto hbaud1 ; 2 US\r
+ retlw 0 ; ...AFTER 1+1+3x68+1 = 207 US (X2=414 US)\r
+\r
+; http://www.piclist.com/techref/piclist/codegen/delay.htm\r
+; Delay = 1 seconds\r
+; Clock frequency = 8 MHz\r
+\r
+; Actual delay = 1 seconds = 2000000 cycles\r
+; Error = 0 %\r
+\r
+delay\r
+ ;1999996 cycles\r
+ bsf FSR,5\r
+ movlw 0x11\r
+ movwf d1\r
+ movlw 0x5D\r
+ movwf d2\r
+ movlw 0x05\r
+ movwf d3\r
+Delay_0\r
+ decfsz d1, f\r
+ goto $+2\r
+ decfsz d2, f\r
+ goto $+2\r
+ decfsz d3, f\r
+ goto Delay_0\r
+\r
+ ;4 cycles\r
+ goto $+1\r
+ goto $+1\r
+\r
+ bcf FSR,5\r
+ retlw 0\r
+\r
+; sleep input state machine\r
+; \r
+; we expect the chars s-l-e-e-p-x-y-z where xyz are digits\r
+; if wrong char received reset\r
+; if 5 sec timout between chars reset\r
+; if xyz are not digits reset\r
+\r
+sleep_input\r
+\r
+ ; big case statement to work out what state we are in\r
+\r
+ movlw 0\r
+ subwf sleep_state,0\r
+ btfsc STATUS,Z ; Z set if in state 's'\r
+ goto sleep_state_s\r
+ movlw 1\r
+ subwf sleep_state,0\r
+ btfsc STATUS,Z ; Z set if in state 'l'\r
+ goto sleep_state_l\r
+ movlw 2\r
+ subwf sleep_state,0\r
+ btfsc STATUS,Z ; Z set if in state 'e1'\r
+ goto sleep_state_e1\r
+ movlw 3\r
+ subwf sleep_state,0\r
+ btfsc STATUS,Z ; Z set if in state 'e2'\r
+ goto sleep_state_e2\r
+ movlw 4\r
+ subwf sleep_state,0\r
+ btfsc STATUS,Z ; Z set if in state 'p'\r
+ goto sleep_state_p\r
+ movlw 5\r
+ subwf sleep_state,0\r
+ btfsc STATUS,Z ; Z set if in state 'x'\r
+ goto sleep_state_x\r
+ movlw 6\r
+ subwf sleep_state,0\r
+ btfsc STATUS,Z ; Z set if in state 'y'\r
+ goto sleep_state_y\r
+ movlw 7\r
+ subwf sleep_state,0\r
+ btfsc STATUS,Z ; Z set if in state 'z'\r
+ goto sleep_state_z\r
+\r
+ ; should never get here but just in case\r
+\r
+ goto sleep_reset\r
+\r
+ ; if we have rx-ed a 's' continue to next state\r
+sleep_state_s\r
+ movlw 's'\r
+ subwf SERBUFI,0\r
+ btfss STATUS,Z ; Z set if we received a 's'\r
+ goto sleep_reset\r
+ goto sleep_cont\r
+\r
+ ; if we have rx-ed a 'l' continue to next state\r
+sleep_state_l\r
+ movlw 'l'\r
+ subwf SERBUFI,0\r
+ btfss STATUS,Z ; Z set if we received a 'l'\r
+ goto sleep_reset\r
+ goto sleep_cont\r
+\r
+ ; if we have rx-ed a 'e' continue to next state\r
+sleep_state_e1\r
+ movlw 'e'\r
+ subwf SERBUFI,0\r
+ btfss STATUS,Z ; Z set if we received a 'e'\r
+ goto sleep_reset\r
+ goto sleep_cont\r
+\r
+ ; if we have rx-ed a 'e' continue to next state\r
+sleep_state_e2\r
+ movlw 'e'\r
+ subwf SERBUFI,0\r
+ btfss STATUS,Z ; Z set if we received a 'e'\r
+ goto sleep_reset\r
+ goto sleep_cont\r
+\r
+ ; if we have rx-ed a 'p' continue to next state\r
+sleep_state_p\r
+ movlw 'p'\r
+ subwf SERBUFI,0\r
+ btfss STATUS,Z ; Z set if we received a 'p'\r
+ goto sleep_reset\r
+ goto sleep_cont\r
+\r
+ ; if we have rx-ed a digit 0-9 continue to next state\r
+sleep_state_x\r
+\r
+ ; check if >= '0'\r
+ movlw '0'\r
+ subwf SERBUFI,0\r
+ btfss STATUS,C ; C set if valid\r
+ goto sleep_reset\r
+\r
+ ; check if x <= 9\r
+ bsf FSR,5 ; x is in bank 1\r
+ movwf x\r
+ movlw d'10'\r
+ subwf x,0\r
+ bcf FSR,5\r
+ btfsc STATUS,C ; C reset if valid\r
+ goto sleep_reset\r
+ goto sleep_cont\r
+\r
+ ; if we have rx-ed a digit 0-9 continue to next state\r
+sleep_state_y\r
+\r
+ ; check if >= '0'\r
+ movlw '0'\r
+ subwf SERBUFI,0\r
+ btfss STATUS,C ; C set if valid\r
+ goto sleep_reset\r
+\r
+ ; check if y <= 9\r
+ bsf FSR,5 ; y is in bank 1\r
+ movwf y\r
+ movlw d'10'\r
+ subwf y,0\r
+ bcf FSR,5\r
+ btfsc STATUS,C ; C reset if valid\r
+ goto sleep_reset\r
+ goto sleep_cont\r
+\r
+ ; if we have rx-ed a digit 0-9 continue to next state\r
+sleep_state_z\r
+\r
+ ; check if >= '0'\r
+ movlw '0'\r
+ subwf SERBUFI,0\r
+ btfss STATUS,C ; C set if valid\r
+ goto sleep_reset\r
+\r
+ ; check if z <= 9\r
+ bsf FSR,5 ; z is in bank 1\r
+ movwf z\r
+ movlw d'10'\r
+ subwf z,0\r
+ bcf FSR,5\r
+ btfsc STATUS,C ; C reset if valid\r
+ goto sleep_reset\r
+\r
+ ; OK we made it! Lets go to SLEEP, ZZZZZzzzzzzzzzz\r
+\r
+ clrf sleep_state\r
+ clrf sleep_timeout\r
+ movlw 1\r
+ movwf sleeping\r
+ bcf GPIO,1 ; power switch off\r
+\r
+ retlw 0\r
+\r
+ ; we bombed out in rx-ing sleep string\r
+sleep_reset\r
+ clrf sleep_state\r
+ clrf sleep_timeout\r
+ retlw 0\r
+ \r
+ ; increment to next state, and reset sleep timeout\r
+sleep_cont\r
+ incf sleep_state,1\r
+ movlw SLEEP_TIMEOUT\r
+ movwf sleep_timeout\r
+ retlw 0\r
+\r
+; START MAIN LOOP -----------------------------------------------\r
+\r
+main\r
+\r
+ ; sample AN[0] (voltage)\r
+\r
+ movlw b'10110001'\r
+ movwf ADCON0 \r
+ bsf ADCON0,1 ; start A/D conversion\r
+wait_adc_v\r
+ btfsc ADCON0,1 ; skip if A/D conversion finished\r
+ goto wait_adc_v\r
+\r
+ ; print voltage to RS232\r
+\r
+ movf ADRES, 0\r
+ movwf BIN\r
+ call BIN2BCD ; convert voltage to decimal ASCII \r
+\r
+ movf huns, 0 \r
+ call outch_n\r
+ movf tens, 0\r
+ call outch_n\r
+ movf ones, 0\r
+ call outch_n\r
+\r
+ ; print space\r
+\r
+ movlw ' '\r
+ call outch_n\r
+\r
+ ; sample AN[1] (current)\r
+\r
+ movlw b'10111001'\r
+ movwf ADCON0 \r
+ bsf ADCON0,1 ; start A/D conversion\r
+wait_adc_i\r
+ btfsc ADCON0,1 ; skip if A/D conversion finished\r
+ goto wait_adc_i\r
+\r
+ ; print current to RS232\r
+\r
+ movf ADRES, 0\r
+ movwf BIN\r
+ call BIN2BCD ; convert current to decimal & ASCII \r
+\r
+ movf huns, 0 \r
+ call outch_n\r
+ movf tens, 0\r
+ call outch_n\r
+ movf ones, 0\r
+ call outch_n\r
+\r
+ ; print rx char\r
+\r
+ movlw ' '\r
+ call outch_n\r
+ movf SERBUFI, 0\r
+ call outch_n\r
+\r
+ ; print rx char in dec\r
+\r
+ movlw ' '\r
+ call outch_n\r
+ movf SERBUFI, 0\r
+ movwf BIN\r
+ call BIN2BCD ; convert rx char to decimal & ASCII \r
+\r
+ movf huns, 0 \r
+ call outch_n\r
+ movf tens, 0\r
+ call outch_n\r
+ movf ones, 0\r
+ call outch_n\r
+\r
+ ; print wd_timeout in dec\r
+\r
+ movlw ' '\r
+ call outch_n\r
+ movf wd_timeout, 0\r
+ movwf BIN\r
+ call BIN2BCD \r
+\r
+ movf huns, 0 \r
+ call outch_n\r
+ movf tens, 0\r
+ call outch_n\r
+ movf ones, 0\r
+ call outch_n\r
+\r
+ ; print wd_fire in dec\r
+\r
+ movlw ' '\r
+ call outch_n\r
+ movf wd_fire, 0\r
+ movwf BIN\r
+ call BIN2BCD \r
+\r
+ movf huns, 0 \r
+ call outch_n\r
+ movf tens, 0\r
+ call outch_n\r
+ movf ones, 0\r
+ call outch_n\r
+\r
+ ; print sleep_state \r
+\r
+ movlw ' '\r
+ call outch_n\r
+ movlw '0' \r
+ addwf sleep_state,0\r
+ call outch_n\r
+\r
+ ; print sleep timer in dec\r
+\r
+ movlw ' '\r
+ call outch_n\r
+ movlw '0' ; print x\r
+ bsf FSR,5\r
+ addwf x,0\r
+ bcf FSR,5\r
+ call outch_n\r
+ movlw '0' ; print y\r
+ bsf FSR,5\r
+ addwf y,0\r
+ bcf FSR,5\r
+ call outch_n\r
+ movlw '0' ; print z\r
+ bsf FSR,5\r
+ addwf z,0\r
+ bcf FSR,5\r
+ call outch_n\r
+\r
+ ; print restart_flag\r
+\r
+ movlw ' '\r
+ call outch_n\r
+ movf restart_flag, 0\r
+ call outch_n\r
+\r
+ ; print CR-LF\r
+\r
+ movlw '\r'\r
+ call outch_n\r
+ movlw '\n'\r
+ call outch_n\r
+\r
+ ; RS232 RX and 1 second delay\r
+\r
+ call inch_n_delay \r
+\r
+ ; has watchdog fired (wd_timeout == 0) ?\r
+\r
+ movf wd_timeout,1\r
+ btfsc STATUS,Z ; skip if not fired\r
+ goto watchdog_firing ; Yes? Then goto watchdog firing code\r
+ \r
+ ; are we sleeping (sleeping == 1)?\r
+\r
+ movf sleeping,1\r
+ btfss STATUS,Z ; skip if not sleeping\r
+ goto snooze ; Yes? Then goto sleeping code\r
+\r
+ ; No? Then count down watchdog\r
+\r
+ movlw 1\r
+ subwf wd_timeout,1\r
+\r
+ ; Has watchdog just fired (wd_timeout == 0)?\r
+\r
+ btfss STATUS,Z ; skip if wd_countdown is zero\r
+ goto dec_sleeptimeout ; No - continue\r
+\r
+ ; Yes - start watchdog firing code\r
+\r
+ bcf GPIO,1 ; PowerSwitch Off\r
+ movlw WD_FIRE\r
+ movwf wd_fire\r
+ goto main\r
+\r
+dec_sleeptimeout\r
+ ; has sleep state machine accepted a rx char?\r
+\r
+ movf sleep_state,1\r
+ btfsc STATUS,Z \r
+ goto main ; No? Then continue processing\r
+\r
+ decfsz sleep_timeout,1\r
+ goto main\r
+\r
+ ; sleep state machine timeout, reset state machine\r
+ clrf sleep_state\r
+ goto main\r
+\r
+ ; watchdog firing code\r
+\r
+watchdog_firing\r
+\r
+ movlw 1\r
+ subwf wd_fire,1\r
+\r
+ ; watchdog firing complete? (wd_fire == 0)?\r
+\r
+ btfss STATUS,Z ; skip if wd_fire is zero\r
+ goto main ; No - continue\r
+\r
+ ; Yes - reset watchdog\r
+\r
+ bsf GPIO,1 ; PowerSwitch On\r
+ movlw WD_TIMEOUT\r
+ movwf wd_timeout\r
+\r
+ ; Indicate WD has fired since last 'w' sent by host. A rx of\r
+ ; 'w' resets this flag.\r
+ \r
+ movlw WD_FLAG\r
+ movwf restart_flag\r
+ \r
+ goto main\r
+\r
+ ; sleeping code\r
+ ; sleep for xyz seconds, need to count down in decimal\r
+snooze\r
+ ; 3 digit decimal count down timer xyz, e.g. 999, 998,...001,000\r
+ ; it's time's like these I wonder why I volunteered for this project!! :-)\r
+ ; see countdown.c for C version of this algorithm\r
+\r
+ bsf FSR,5\r
+ movf z,1\r
+ btfss STATUS,Z\r
+ goto z_not_zero\r
+ movf y,1\r
+ btfss STATUS,Z\r
+ goto y_not_zero\r
+ movf x,1\r
+ btfss STATUS,Z\r
+ goto x_not_zero\r
+ \r
+ ; x=y=z=0 so we are finished\r
+\r
+ bcf FSR,5\r
+ goto sleep_finished\r
+\r
+z_not_zero\r
+ decf z,1\r
+ goto continue_sleep\r
+\r
+y_not_zero\r
+ decf y,1\r
+ movlw 9\r
+ movwf z\r
+ goto continue_sleep\r
+\r
+x_not_zero\r
+ decf x,1\r
+ movlw 9\r
+ movwf y\r
+ movwf z\r
+ goto continue_sleep\r
+\r
+ ; sleep finished\r
+\r
+sleep_finished\r
+ bsf GPIO,1 ; PowerSwitch On\r
+ movlw WD_TIMEOUT ; reset watchdog for good measure\r
+ movwf wd_timeout\r
+ clrf wd_fire\r
+ clrf sleep_timeout ; clear sleep timeout counter\r
+ clrf sleeping ; clear sleep flag\r
+ \r
+ ; Indicate we have just woken up from a sleep. A rx of 'w'\r
+ ; resets this.\r
+ \r
+ movlw SLEEP_FLAG \r
+ movwf restart_flag\r
+ goto main\r
+ \r
+continue_sleep\r
+ bcf FSR,5\r
+ goto main\r
+ \r
+; END MAIN LOOP -----------------------------------------------\r
+\r
+ end\r
+\r
+\r
--- /dev/null
+v 20060906 1
+C 50900 31400 1 90 0 bf-capacitor-1.sym
+{
+T 50400 31900 5 10 1 1 180 0 1
+value=100nF 100V
+}
+C 50800 35800 1 0 0 bf-resistor-1.sym
+{
+T 51000 36300 5 10 1 1 0 0 1
+refdes=R1
+T 51000 36100 5 10 1 1 0 0 1
+value=100k
+}
+C 43000 23300 0 0 0 title-bordered-C.sym
+B 43500 23800 6800 800 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1
+T 43600 24000 9 10 1 0 0 0 1
+Licensed under the TAPR Open Hardware License (www.tapr.org/OHL)
+T 43600 24300 9 10 1 0 0 0 1
+COPYRIGHT DAVID ROWE 2008
+T 58000 24500 9 10 1 0 0 0 1
+Wifi Station Power Controller And Reporter - WiSPCaR
+T 62000 23600 9 10 1 0 0 0 1
+David Rowe
+T 62000 23900 9 10 1 0 0 0 1
+0.1
+T 58500 23600 9 10 1 0 0 0 1
+1
+T 59800 23600 9 10 1 0 0 0 1
+1
+T 58000 23900 9 10 1 0 0 0 1
+wispcar.sch
+C 58000 35600 1 180 1 lm324-1.sym
+{
+T 57525 35650 5 8 1 1 180 6 1
+device=LM324
+T 57500 35900 5 10 1 1 180 6 1
+refdes=U2
+T 58000 35600 5 10 0 0 180 6 1
+slot=2
+}
+C 56300 28300 1 0 0 lm324-1.sym
+{
+T 57125 28450 5 8 0 0 0 0 1
+device=LM324
+T 57000 29100 5 10 1 1 0 0 1
+refdes=U2
+T 56300 28300 5 10 0 0 0 0 1
+slot=1
+}
+C 56300 29300 1 0 0 lm324-1.sym
+{
+T 57125 29450 5 8 0 0 0 0 1
+device=LM324
+T 57000 29900 5 10 1 1 0 0 1
+refdes=U2
+T 56300 29300 5 10 0 0 0 0 1
+slot=3
+}
+C 56300 27200 1 0 0 lm324-1.sym
+{
+T 57125 27350 5 8 0 0 0 0 1
+device=LM324
+T 57000 28100 5 10 1 1 0 0 1
+refdes=U2
+T 56300 27200 5 10 0 0 0 0 1
+slot=4
+}
+C 50800 31700 1 0 0 LM78L05.sym
+{
+T 52400 33000 5 10 0 0 0 0 1
+device=78L05
+T 51300 32700 5 10 1 1 0 6 1
+refdes=U3
+}
+C 54800 30700 1 0 0 PC12F510.sym
+{
+T 57200 31500 5 10 0 0 0 0 1
+device=PIC12F510
+T 57200 31200 5 10 0 0 0 0 1
+footprint=DIP8
+T 55350 32650 5 10 1 1 0 6 1
+refdes=U1
+}
+C 52200 33800 1 0 1 npn-2.sym
+{
+T 51600 34300 5 10 0 0 0 6 1
+device=NPN_TRANSISTOR
+T 52400 34000 5 10 1 1 0 6 1
+refdes=Q2
+T 52100 33800 5 10 1 1 0 0 1
+value=BC548
+}
+B 51400 28300 1000 1000 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1
+B 51500 29300 800 600 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1
+V 51900 29600 100 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1
+B 51500 27700 100 600 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1
+B 52200 27700 100 600 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1
+B 51850 27700 100 600 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1
+T 52350 30050 9 10 1 0 0 0 1
+IRF9540
+T 52900 28450 9 10 1 0 0 0 1
+BC548
+A 53200 27900 400 0 179 3 0 0 0 -1 -1
+L 52800 27900 52800 27700 3 0 0 0 -1 -1
+L 53600 27900 53600 27700 3 0 0 0 -1 -1
+L 52800 27700 53600 27700 3 0 0 0 -1 -1
+V 53000 27900 52 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1
+V 53200 27900 50 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1
+V 53400 27900 50 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1
+T 52950 27450 9 10 1 0 0 0 1
+E
+T 53150 27450 9 10 1 0 0 0 1
+B
+T 53350 27450 9 10 1 0 0 0 1
+C
+T 51500 27450 9 10 1 0 0 0 1
+G
+T 51850 27450 9 10 1 0 0 0 1
+D
+T 52200 27450 9 10 1 0 0 0 1
+S
+A 54350 27900 400 0 179 3 0 0 0 -1 -1
+L 53950 27900 53950 27700 3 0 0 0 -1 -1
+L 54750 27900 54750 27700 3 0 0 0 -1 -1
+L 53950 27700 54750 27700 3 0 0 0 -1 -1
+V 54150 27900 52 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1
+V 54350 27900 50 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1
+V 54550 27900 50 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1
+T 54050 28450 9 10 1 0 0 0 1
+78L05
+T 53900 27450 9 10 1 0 0 0 1
+VIN
+T 54150 27200 9 10 1 0 0 0 1
+GND
+T 54500 27450 9 10 1 0 0 0 1
+VOUT
+T 51700 28750 9 10 1 0 0 0 1
+TOP
+N 50300 36700 51500 36700 4
+{
+T 50200 36800 5 10 1 1 0 0 1
+netname=VBAT_IN
+}
+N 50700 35900 50800 35900 4
+C 51600 35700 1 270 0 bf-resistor-1.sym
+{
+T 51100 35400 5 10 1 1 0 0 1
+refdes=R2
+T 51100 35200 5 10 1 1 0 0 1
+value=100k
+}
+N 51700 36200 51700 35700 4
+N 50700 32300 50700 36700 4
+N 50700 32300 50800 32300 4
+C 50600 31100 1 0 0 gnd-1.sym
+C 52600 31400 1 90 0 bf-capacitor-1.sym
+{
+T 52900 31200 5 10 1 1 180 0 1
+value=100nF 10V
+}
+N 50700 31400 52400 31400 4
+N 51600 31700 51600 31400 4
+C 51600 33500 1 0 0 gnd-1.sym
+C 52900 34200 1 0 0 bf-resistor-1.sym
+{
+T 53100 34700 5 10 1 1 0 0 1
+refdes=R4
+T 53100 34500 5 10 1 1 0 0 1
+value=10k
+}
+C 52500 35700 1 270 0 bf-resistor-1.sym
+{
+T 52000 35400 5 10 1 1 0 0 1
+refdes=R3
+T 52000 35200 5 10 1 1 0 0 1
+value=100k
+}
+C 52400 35700 1 0 0 bf-5V-plus-1.sym
+C 52600 32300 1 0 0 bf-5V-plus-1.sym
+N 52400 32300 54800 32300 4
+N 52200 34300 52900 34300 4
+N 52600 34800 52600 34300 4
+T 51200 37300 9 10 1 0 0 0 1
+POWER SWITCH
+N 52300 36700 55000 36700 4
+T 56300 37300 9 10 1 0 0 0 1
+CURRENT SENSOR
+C 55000 36600 1 0 0 bf-resistor-1.sym
+{
+T 55300 36900 5 10 1 1 0 0 1
+refdes=R5
+T 55100 36400 5 10 1 1 0 0 1
+value=0.1R 5W
+}
+C 54400 36300 1 270 0 bf-resistor-1.sym
+{
+T 53900 36000 5 10 1 1 0 0 1
+refdes=R6
+T 53900 35800 5 10 1 1 0 0 1
+value=1M
+}
+C 54400 34900 1 270 0 bf-resistor-1.sym
+{
+T 53900 34700 5 10 1 1 0 0 1
+refdes=R7
+T 53900 34500 5 10 1 1 0 0 1
+value=100k
+}
+C 56400 36300 1 270 0 bf-resistor-1.sym
+{
+T 55900 36000 5 10 1 1 0 0 1
+refdes=R8
+T 55900 35800 5 10 1 1 0 0 1
+value=1M
+}
+C 56400 34900 1 270 0 bf-resistor-1.sym
+{
+T 55900 34600 5 10 1 1 0 0 1
+refdes=R9
+T 55900 34400 5 10 1 1 0 0 1
+value=100k
+}
+C 57500 34900 1 270 0 bf-resistor-1.sym
+{
+T 57000 34600 5 10 1 1 0 0 1
+refdes=R10
+T 57000 34400 5 10 1 1 0 0 1
+value=10M
+}
+C 58000 36000 1 0 0 bf-resistor-1.sym
+{
+T 58300 36500 5 10 1 1 0 0 1
+refdes=R11
+T 58300 36300 5 10 1 1 0 0 1
+value=10M
+}
+N 54500 36700 54500 36300 4
+N 54500 35400 54500 34900 4
+C 58600 35900 1 180 0 gnd-1.sym
+N 56500 35400 56500 34900 4
+N 56500 36700 56500 36300 4
+N 55900 36700 60300 36700 4
+{
+T 59300 36800 5 10 1 1 0 0 1
+netname=VBAT_OUT
+}
+N 56500 35400 58000 35400 4
+N 58000 36100 56900 36100 4
+N 56900 36100 56900 35400 4
+N 58000 35000 54500 35000 4
+N 57600 35000 57600 34900 4
+C 58700 34800 1 180 0 bf-5V-plus-1.sym
+C 57500 33700 1 0 0 gnd-1.sym
+N 57600 34000 54500 34000 4
+N 58900 36100 59200 36100 4
+N 59200 36100 59200 35200 4
+C 56900 32200 1 90 0 gnd-1.sym
+N 54800 31500 53200 31500 4
+{
+T 53200 31600 5 10 1 1 0 0 1
+netname=RS232 TX (OUT)
+}
+N 54800 31100 53200 31100 4
+{
+T 53200 31200 5 10 1 1 0 0 1
+netname=RS232 RX (IN)
+}
+N 54800 31900 53200 31900 4
+{
+T 53200 32000 5 10 1 1 0 0 1
+netname=SPARE I/O
+}
+N 58200 31900 56600 31900 4
+N 53800 34300 54000 34300 4
+N 54000 34300 54000 33400 4
+N 54000 33400 58500 33400 4
+N 58500 31500 58500 33400 4
+N 56600 31500 58500 31500 4
+{
+T 56600 31600 5 10 1 1 0 0 1
+netname=PowerSwitch (OUT)
+}
+N 56300 29900 56300 27200 4
+C 56200 26900 1 0 0 gnd-1.sym
+N 59000 35200 60300 35200 4
+{
+T 59600 35300 5 10 1 1 0 0 1
+netname=Isense
+}
+N 60300 35200 60300 31100 4
+N 56600 31100 60300 31100 4
+{
+T 56600 31200 5 10 1 1 0 0 1
+netname=Isense (IN)
+}
+N 50700 33000 58200 33000 4
+N 58200 33000 58200 31900 4
+C 51500 36200 1 270 1 pmos-wispcar.sym
+{
+T 52000 36800 5 10 0 0 90 2 1
+device=PMOS_TRANSISTOR
+T 51700 36800 5 10 1 1 180 2 1
+refdes=Q1
+T 52100 36800 5 10 1 1 0 0 1
+value=IRF9540
+}