Compare commits
12 Commits
b0e59996cd
...
1216082a4f
Author | SHA1 | Date |
---|---|---|
Olaf Rempel | 1216082a4f | |
Olaf Rempel | d1e3e5be08 | |
Olaf Rempel | 63b2291931 | |
Olaf Rempel | 118eaa091b | |
Olaf Rempel | 49ffbdb579 | |
Olaf Rempel | 6a75a0aec3 | |
Olaf Rempel | 121d52abe6 | |
Olaf Rempel | 1fa54cd456 | |
Olaf Rempel | f26732ccfa | |
Olaf Rempel | 88cc3ad2dc | |
Olaf Rempel | c3f43e7fb3 | |
Olaf Rempel | cb3707d2c0 |
|
@ -1,7 +1 @@
|
|||
*.o
|
||||
*.elf
|
||||
*.bin
|
||||
*.hex
|
||||
*.lst
|
||||
*.lss
|
||||
*.map
|
||||
build
|
|
@ -0,0 +1,262 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 Lesser 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.
|
||||
|
||||
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.)
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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
|
19
Makefile
19
Makefile
|
@ -6,6 +6,7 @@ SIZE := avr-size
|
|||
|
||||
TARGET = ispprog
|
||||
SOURCE = $(wildcard *.c)
|
||||
BUILD_DIR = build
|
||||
|
||||
#CONFIG = ispprog
|
||||
CONFIG = ispprog2
|
||||
|
@ -34,29 +35,33 @@ endif
|
|||
# ---------------------------------------------------------------------------
|
||||
|
||||
CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections
|
||||
CFLAGS += -Wa,-adhlns=$(*F).lst -DCONFIG_$(CONFIG)=1
|
||||
CFLAGS += -Wa,-adhlns=$(BUILD_DIR)/$(*D)/$(*F).lst -MMD -MP -MF $(BUILD_DIR)/$(*D)/$(*F).d
|
||||
CFLAGS += -DCONFIG_$(CONFIG)=1
|
||||
LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
$(TARGET): $(TARGET).elf
|
||||
$(TARGET): $(BUILD_DIR)/$(TARGET).elf
|
||||
@$(SIZE) -B -x --mcu=$(MCU) $<
|
||||
|
||||
$(TARGET).elf: $(SOURCE:.c=.o)
|
||||
$(BUILD_DIR)/$(TARGET).elf: $(patsubst %,$(BUILD_DIR)/%,$(SOURCE:.c=.o))
|
||||
@echo " Linking file: $@"
|
||||
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
|
||||
@$(OBJDUMP) -h -S $@ > $(@:.elf=.lss)
|
||||
@$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex)
|
||||
@$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin)
|
||||
|
||||
%.o: %.c $(MAKEFILE_LIST)
|
||||
$(BUILD_DIR)/%.o: %.c $(MAKEFILE_LIST)
|
||||
@echo " Building file: $<"
|
||||
@$(shell test -d $(BUILD_DIR)/$(*D) || mkdir -p $(BUILD_DIR)/$(*D))
|
||||
@$(CC) $(CFLAGS) -o $@ -c $<
|
||||
|
||||
clean:
|
||||
rm -rf $(SOURCE:.c=.o) $(SOURCE:.c=.lst) $(addprefix $(TARGET), .elf .map .lss .hex .bin)
|
||||
include $(shell find $(BUILD_DIR) -name \*.d 2> /dev/null)
|
||||
|
||||
install: $(TARGET).elf
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)
|
||||
|
||||
install: $(BUILD_DIR)/$(TARGET).elf
|
||||
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
|
||||
|
||||
fuses:
|
||||
|
|
|
@ -0,0 +1,183 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2006 - 2020 by Olaf Rempel *
|
||||
* razzor AT kopf MINUS tisch DOT de *
|
||||
* *
|
||||
* 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; version 2 of the License, *
|
||||
* *
|
||||
* 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. *
|
||||
***************************************************************************/
|
||||
#include <avr/pgmspace.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "avrdevice.h"
|
||||
|
||||
/* *********************************************************************** */
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
|
||||
|
||||
/* *********************************************************************** */
|
||||
|
||||
static const avr_device_t devices[] PROGMEM = {
|
||||
{ "at90s1200", { 0x1E, 0x90, 0x01 }, 0x13, 0x00, POLL_00 | POLL_FF },
|
||||
{ "tiny12", { 0x1E, 0x90, 0x05 }, 0x55, 0x00, POLL_UNTESTED },
|
||||
{ "tiny15", { 0x1E, 0x90, 0x06 }, 0x56, 0x00, POLL_UNTESTED },
|
||||
{ "tiny13", { 0x1E, 0x90, 0x07 }, 0xFF, 0x00, POLL_UNTESTED },
|
||||
|
||||
{ "at90s2313", { 0x1E, 0x91, 0x01 }, 0x20, 0x00, POLL_7F | POLL_80 | POLL_FF },
|
||||
{ "at90s2323", { 0x1E, 0x91, 0x02 }, 0x48, 0x00, POLL_UNTESTED },
|
||||
{ "at90s2343", { 0x1E, 0x91, 0x03 }, 0x4C, 0x00, POLL_UNTESTED },
|
||||
{ "at90s2333", { 0x1E, 0x91, 0x05 }, 0x34, 0x00, POLL_UNTESTED },
|
||||
{ "tiny25", { 0x1E, 0x91, 0x08 }, 0x20, 0x0F, POLL_FF }, /* at90s2313 devcode */
|
||||
{ "tiny26", { 0x1E, 0x91, 0x09 }, 0x5E, 0x0F, POLL_FF },
|
||||
{ "tiny2313", { 0x1E, 0x91, 0x0A }, 0x5E, 0x0F, POLL_FF }, /* tiny26 devcode */
|
||||
{ "tiny24", { 0x1E, 0x91, 0x0B }, 0x20, 0x0F, POLL_FF }, /* at90s2313 devcode */
|
||||
{ "tiny261a", { 0x1E, 0x91, 0x0C }, 0xFF, 0x0F, POLL_FF | POLL_UNTESTED },
|
||||
|
||||
{ "at90s4414", { 0x1E, 0x92, 0x01 }, 0x28, 0x00, POLL_UNTESTED },
|
||||
{ "at90s4434", { 0x1E, 0x92, 0x02 }, 0x6C, 0x00, POLL_UNTESTED },
|
||||
{ "at90s4433", { 0x1E, 0x92, 0x03 }, 0x30, 0x00, POLL_UNTESTED },
|
||||
{ "mega48", { 0x1E, 0x92, 0x05 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED},
|
||||
{ "tiny45", { 0x1E, 0x92, 0x06 }, 0x20, 0x1F, POLL_FF }, /* at90s2313 devcode */
|
||||
{ "tiny44", { 0x1E, 0x92, 0x07 }, 0x20, 0x1F, POLL_FF }, /* at90s2313 devcode */
|
||||
{ "mega461a", { 0x1E, 0x92, 0x08 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
|
||||
{ "mega48pa", { 0x1E, 0x92, 0x0A }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
|
||||
{ "tiny4313", { 0x1E, 0x92, 0x0D }, 0x5E, 0x1F, POLL_FF | POLL_UNTESTED }, /* tiny26 devcode */
|
||||
|
||||
{ "at90s8515", { 0x1E, 0x93, 0x01 }, 0x38, 0x00, POLL_7F | POLL_80 | POLL_FF },
|
||||
{ "at90s8535", { 0x1E, 0x93, 0x03 }, 0x68, 0x00, POLL_UNTESTED },
|
||||
{ "mega83", { 0x1E, 0x93, 0x05 }, 0x65, 0x00, POLL_UNTESTED },
|
||||
{ "mega8515", { 0x1E, 0x93, 0x06 }, 0x3A, 0x1F, POLL_FF | POLL_UNTESTED },
|
||||
{ "mega8", { 0x1E, 0x93, 0x07 }, 0x76, 0x1F, POLL_FF },
|
||||
{ "mega8535", { 0x1E, 0x93, 0x08 }, 0x69, 0x1F, POLL_FF | POLL_UNTESTED },
|
||||
{ "mega88", { 0x1E, 0x93, 0x0A }, 0xFF, 0x1F, POLL_FF },
|
||||
{ "tiny85", { 0x1E, 0x93, 0x0B }, 0x20, 0x1F, POLL_FF }, /* at90s2313 devcode */
|
||||
{ "tiny84", { 0x1E, 0x93, 0x0C }, 0x20, 0x1F, POLL_FF }, /* at90s2313 devcode */
|
||||
{ "tiny861a", { 0x1E, 0x93, 0x0D }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
|
||||
{ "mega88pa", { 0x1E, 0x93, 0x0F }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
|
||||
{ "tiny88", { 0x1E, 0x93, 0x11 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
|
||||
{ "at90pwm3", { 0x1E, 0x93, 0x81 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED }, /* same: at90pwm2 */
|
||||
{ "at90usb82", { 0x1E, 0x93, 0x82 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
|
||||
{ "at90pwm3b", { 0x1E, 0x93, 0x83 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED }, /* same: at90pwm2b */
|
||||
{ "mega8u2", { 0x1E, 0x93, 0x89 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
|
||||
|
||||
{ "mega161", { 0x1E, 0x94, 0x01 }, 0x60, 0x00, POLL_UNTESTED },
|
||||
{ "mega163", { 0x1E, 0x94, 0x02 }, 0x64, 0x00, POLL_UNTESTED },
|
||||
{ "mega16", { 0x1E, 0x94, 0x03 }, 0x74, 0x3F, POLL_FF },
|
||||
{ "mega162", { 0x1E, 0x94, 0x04 }, 0x63, 0x3F, POLL_FF | POLL_UNTESTED },
|
||||
{ "mega169", { 0x1E, 0x94, 0x05 }, 0x78, 0x3F, POLL_FF | POLL_UNTESTED },
|
||||
{ "mega168", { 0x1E, 0x94, 0x06 }, 0xFF, 0x3F, POLL_FF },
|
||||
{ "mega164pa", { 0x1E, 0x94, 0x0A }, 0x74, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
|
||||
{ "mega168pa", { 0x1E, 0x94, 0x0B }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
|
||||
{ "mega164a", { 0x1E, 0x94, 0x0F }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
|
||||
{ "at90usb162", { 0x1E, 0x94, 0x82 }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
|
||||
{ "mega16u4", { 0x1E, 0x94, 0x88 }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
|
||||
{ "mega16u2", { 0x1E, 0x94, 0x89 }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
|
||||
|
||||
{ "mega32", { 0x1E, 0x95, 0x02 }, 0x72, 0x3F, POLL_FF },
|
||||
{ "mega329", { 0x1E, 0x95, 0x03 }, 0x75, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
|
||||
{ "mega3290", { 0x1E, 0x95, 0x04 }, 0x75, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
|
||||
{ "mega325", { 0x1E, 0x95, 0x05 }, 0x74, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
|
||||
{ "mega3250", { 0x1E, 0x95, 0x06 }, 0x74, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
|
||||
{ "mega324p", { 0x1E, 0x95, 0x08 }, 0x74, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
|
||||
{ "mega329p", { 0x1E, 0x95, 0x0B }, 0x75, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
|
||||
{ "mega3290p", { 0x1E, 0x95, 0x0C }, 0x75, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
|
||||
{ "mega328p", { 0x1E, 0x95, 0x0F }, 0xFF, 0x3F, POLL_FF },
|
||||
{ "mega324pa", { 0x1E, 0x95, 0x11 }, 0x74, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
|
||||
{ "mega324a", { 0x1E, 0x95, 0x15 }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
|
||||
{ "at90can32", { 0x1E, 0x95, 0x81 }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
|
||||
{ "mega32u4", { 0x1E, 0x95, 0x87 }, 0xFF, 0x3F, POLL_FF },
|
||||
{ "mega32u2", { 0x1E, 0x95, 0x8A }, 0xFF, 0x3F, POLL_FF },
|
||||
|
||||
{ "mega64", { 0x1E, 0x96, 0x02 }, 0x45, 0x7F, POLL_FF },
|
||||
{ "mega649", { 0x1E, 0x96, 0x03 }, 0x75, 0x7F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
|
||||
{ "mega6490", { 0x1E, 0x96, 0x04 }, 0x75, 0x7F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
|
||||
{ "mega645", { 0x1E, 0x96, 0x05 }, 0x74, 0x7F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
|
||||
{ "mega6450", { 0x1E, 0x96, 0x06 }, 0x74, 0x7F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
|
||||
{ "mega640", { 0x1E, 0x96, 0x08 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
|
||||
{ "mega644a", { 0x1E, 0x96, 0x09 }, 0x74, 0x7F, POLL_FF }, /* mega16 devcode */
|
||||
{ "mega644p", { 0x1E, 0x96, 0x0A }, 0x74, 0x7F, POLL_FF }, /* mega16 devcode */
|
||||
{ "at90can64", { 0x1E, 0x96, 0x81 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
|
||||
{ "at90usb646", { 0x1E, 0x96, 0x82 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED }, /* same: at90usb647 */
|
||||
|
||||
{ "mega103", { 0x1E, 0x97, 0x01 }, 0x41, 0x7F, POLL_7F | POLL_80 | POLL_FF },
|
||||
{ "mega128", { 0x1E, 0x97, 0x02 }, 0x43, 0x7F, POLL_FF },
|
||||
{ "mega1280", { 0x1E, 0x97, 0x03 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
|
||||
{ "mega1281", { 0x1E, 0x97, 0x04 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
|
||||
{ "mega1284p", { 0x1E, 0x97, 0x05 }, 0x74, 0x7F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode) */
|
||||
{ "mega1284", { 0x1E, 0x97, 0x06 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
|
||||
{ "at90can128", { 0x1E, 0x97, 0x81 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
|
||||
{ "at90usb1286",{ 0x1E, 0x97, 0x82 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED }, /* same: at90usb1287 */
|
||||
|
||||
{ "mega2560", { 0x1E, 0x98, 0x01 }, 0xFF, 0x00, POLL_UNTESTED },
|
||||
{ "mega2561", { 0x1E, 0x98, 0x02 }, 0xFF, 0x00, POLL_UNTESTED },
|
||||
|
||||
{ "mega128rfa1",{ 0x1E, 0xA7, 0x01 }, 0xFF, 0x00, POLL_UNTESTED },
|
||||
};
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* avrdevice_iterate_devcodes
|
||||
* *********************************************************************** */
|
||||
void avrdevice_iterate_devcodes(avrdevice_callback_t callback)
|
||||
{
|
||||
uint8_t limit = 0x00;
|
||||
|
||||
while (1)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t search = 0xFF;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(devices); i++)
|
||||
{
|
||||
uint8_t devcode = pgm_read_byte(&devices[i].devcode);
|
||||
|
||||
if ((devcode > limit) && (devcode < search))
|
||||
{
|
||||
search = devcode;
|
||||
}
|
||||
}
|
||||
|
||||
if (search == 0xFF)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
callback(search);
|
||||
limit = search;
|
||||
}
|
||||
} /* avrdevice_iterate_devcodes */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* avrdevice_get_by_signature
|
||||
* *********************************************************************** */
|
||||
void avrdevice_get_by_signature(avr_device_t * p_device,
|
||||
const uint8_t * p_signature)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(devices); i++)
|
||||
{
|
||||
if (memcmp_P(p_signature, devices[i].sig, sizeof(p_device->sig)) == 0)
|
||||
{
|
||||
memcpy_P(p_device, &devices[i], sizeof(avr_device_t));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* unknown devices are untested */
|
||||
if (p_device->name[0] == '\0')
|
||||
{
|
||||
p_device->flags |= POLL_UNTESTED;
|
||||
}
|
||||
} /* avrdevice_get_by_signature */
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef AVRDEVICE_H_
|
||||
#define AVRDEVICE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* *********************************************************************** */
|
||||
|
||||
#define POLL_00 0x01 /* value 0x00 can not be polled from flash/eeprom */
|
||||
#define POLL_7F 0x02 /* value 0x7F can not be polled from flash/eeprom */
|
||||
#define POLL_80 0x04 /* value 0x80 can not be polled from flash/eeprom */
|
||||
#define POLL_FF 0x08 /* value 0xFF can not be polled from flash/eeprom */
|
||||
#define POLL_UNTESTED 0x80 /* device not tested */
|
||||
|
||||
typedef struct avr_device_s
|
||||
{
|
||||
char name[12];
|
||||
uint8_t sig[3]; /* device signature */
|
||||
uint8_t devcode; /* avr910 device code */
|
||||
uint16_t pagemask; /* pagemask (pagesize in words!) */
|
||||
uint16_t flags; /* quirks for this device */
|
||||
} avr_device_t;
|
||||
|
||||
typedef void (* avrdevice_callback_t)(uint8_t value);
|
||||
|
||||
/* *********************************************************************** */
|
||||
|
||||
void avrdevice_iterate_devcodes (avrdevice_callback_t callback);
|
||||
|
||||
void avrdevice_get_by_signature (avr_device_t * p_device,
|
||||
const uint8_t * p_signature);
|
||||
|
||||
/* *********************************************************************** */
|
||||
|
||||
#endif /* AVRDEVICE_H_ */
|
|
@ -0,0 +1,206 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2006 - 2020 by Olaf Rempel *
|
||||
* razzor AT kopf MINUS tisch DOT de *
|
||||
* *
|
||||
* 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; version 2 of the License, *
|
||||
* *
|
||||
* 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. *
|
||||
***************************************************************************/
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "display.h"
|
||||
#include "target.h"
|
||||
|
||||
#if (USE_DISPLAY)
|
||||
static display_mode_t m_mode = DISPLAY_MODE_OFF;
|
||||
static char m_buffer[24];
|
||||
static uint8_t m_buffer_length = 0;
|
||||
static uint8_t m_buffer_pos = 0;
|
||||
|
||||
/* ***********************************************************************
|
||||
* display_putc
|
||||
* *********************************************************************** */
|
||||
static void display_putc(uint8_t pos, char ch)
|
||||
{
|
||||
if (ch >= 'a' && ch <= 'z')
|
||||
{
|
||||
ch &= ~0x20;
|
||||
}
|
||||
|
||||
PORTD = ((ch & 0x7E) << 1);
|
||||
PORTC = ((ch & 0x01) << 3) | (3 - (pos & 0x03));
|
||||
PORTC |= (1<<DISP_WR);
|
||||
} /* display_putc */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* display_put4
|
||||
* *********************************************************************** */
|
||||
static void display_put4(const char * p_str)
|
||||
{
|
||||
display_putc(0, *p_str++);
|
||||
display_putc(1, *p_str++);
|
||||
display_putc(2, *p_str++);
|
||||
display_putc(3, *p_str++);
|
||||
} /* display_put4 */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* _hexnibble
|
||||
* *********************************************************************** */
|
||||
static char _hexnibble(char value)
|
||||
{
|
||||
value &= 0x0F;
|
||||
return (value < 0x0A) ? ('0' + value)
|
||||
: ('A' + value - 0x0A);
|
||||
} /* _hexnibble */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* display_show_string
|
||||
* *********************************************************************** */
|
||||
void display_show_string(const char * p_string, uint8_t append)
|
||||
{
|
||||
char * p_dst = m_buffer;
|
||||
uint8_t pos = 0;
|
||||
|
||||
if (append)
|
||||
{
|
||||
p_dst += m_buffer_length;
|
||||
pos = m_buffer_length;
|
||||
}
|
||||
|
||||
while ((pos < sizeof(m_buffer) -1) &&
|
||||
(*p_string != '\0'))
|
||||
{
|
||||
*p_dst++ = *p_string++;
|
||||
pos++;
|
||||
}
|
||||
|
||||
*p_dst++ = ' ';
|
||||
|
||||
m_buffer_length = pos;
|
||||
m_buffer_pos = 0;
|
||||
} /* display_show_string */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* display_show_hex
|
||||
* *********************************************************************** */
|
||||
void display_show_hex(uint8_t value, uint8_t append)
|
||||
{
|
||||
char * p_dst = m_buffer;
|
||||
uint8_t pos = 0;
|
||||
|
||||
if (append)
|
||||
{
|
||||
p_dst += m_buffer_length;
|
||||
pos = m_buffer_length;
|
||||
}
|
||||
|
||||
if (pos < (sizeof(m_buffer) -3))
|
||||
{
|
||||
*p_dst++ = _hexnibble(value >> 4);
|
||||
*p_dst++ = _hexnibble(value);
|
||||
*p_dst++ = ' ';
|
||||
}
|
||||
|
||||
m_buffer_length = pos +2;
|
||||
m_buffer_pos = 0;
|
||||
} /* display_show_hex */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* display_set_mode
|
||||
* *********************************************************************** */
|
||||
void display_set_mode(display_mode_t mode)
|
||||
{
|
||||
m_mode = mode;
|
||||
} /* display_set_mode */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* display_update
|
||||
* *********************************************************************** */
|
||||
void display_update(void)
|
||||
{
|
||||
static uint8_t update_timer;
|
||||
|
||||
update_timer++;
|
||||
|
||||
switch (m_mode)
|
||||
{
|
||||
default:
|
||||
case DISPLAY_MODE_OFF:
|
||||
display_put4(" ");
|
||||
break;
|
||||
|
||||
case DISPLAY_MODE_RUN_ANIM:
|
||||
display_put4("RUN-");
|
||||
m_mode = DISPLAY_MODE_RUN_ANIM_LOOP;
|
||||
/* fallthrough */
|
||||
|
||||
case DISPLAY_MODE_RUN_ANIM_LOOP:
|
||||
switch (update_timer & 0x18)
|
||||
{
|
||||
case 0x00:
|
||||
display_putc(3, '-');
|
||||
break;
|
||||
|
||||
case 0x08:
|
||||
display_putc(3, '\\');
|
||||
break;
|
||||
|
||||
case 0x10:
|
||||
display_putc(3, '1');
|
||||
break;
|
||||
|
||||
case 0x18:
|
||||
display_putc(3, '/');
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case DISPLAY_MODE_STATIC:
|
||||
display_put4(m_buffer);
|
||||
break;
|
||||
|
||||
case DISPLAY_MODE_SCROLL:
|
||||
case DISPLAY_MODE_SCROLL_ONCE:
|
||||
if ((m_buffer_length != 0x00) &&
|
||||
(!(update_timer & 0x1F))
|
||||
)
|
||||
{
|
||||
display_put4(m_buffer + m_buffer_pos);
|
||||
|
||||
if (m_buffer_pos <= (m_buffer_length -3))
|
||||
{
|
||||
m_buffer_pos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_buffer_pos = 0x00;
|
||||
|
||||
if (m_mode == DISPLAY_MODE_SCROLL_ONCE)
|
||||
{
|
||||
m_mode = DISPLAY_MODE_RUN_ANIM;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
} /* display_update */
|
||||
#endif /* (USE_DISPLAY) */
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef DISPLAY_H_
|
||||
#define DISPLAY_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* *********************************************************************** */
|
||||
|
||||
typedef enum display_mode_e {
|
||||
DISPLAY_MODE_OFF, /* disable display */
|
||||
DISPLAY_MODE_RUN_ANIM, /* show RUN animation */
|
||||
DISPLAY_MODE_RUN_ANIM_LOOP, /* change last char of RUN animation */
|
||||
DISPLAY_MODE_STATIC, /* show first 4 chars */
|
||||
DISPLAY_MODE_SCROLL, /* scroll through buffer */
|
||||
DISPLAY_MODE_SCROLL_ONCE, /* scroll once, then switch to RUN_ANIM */
|
||||
} display_mode_t;
|
||||
|
||||
/* *********************************************************************** */
|
||||
|
||||
void display_show_string (const char * p_string, uint8_t append);
|
||||
void display_show_hex (uint8_t value, uint8_t append);
|
||||
void display_set_mode (display_mode_t mode);
|
||||
void display_update (void);
|
||||
|
||||
/* *********************************************************************** */
|
||||
|
||||
#endif /* DISPLAY_H_ */
|
|
@ -0,0 +1,233 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2006 - 2020 by Olaf Rempel *
|
||||
* razzor AT kopf MINUS tisch DOT de *
|
||||
* *
|
||||
* 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; version 2 of the License, *
|
||||
* *
|
||||
* 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. *
|
||||
***************************************************************************/
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "avrdevice.h"
|
||||
#include "spi_isp.h"
|
||||
#include "target.h"
|
||||
|
||||
#include <util/delay.h>
|
||||
|
||||
/* F_CPU /4 (1.8432MHz) */
|
||||
#define SPI_MODE4 ((1<<SPE) | (1<<MSTR))
|
||||
/* F_CPU /16 (460.8kHz) */
|
||||
#define SPI_MODE3 ((1<<SPE) | (1<<MSTR) | (1<<SPR0))
|
||||
/* F_CPU /64 (115.2kHz) */
|
||||
#define SPI_MODE2 ((1<<SPE) | (1<<MSTR) | (1<<SPR1))
|
||||
/* F_CPU /128 (57.6kHz) */
|
||||
#define SPI_MODE1 ((1<<SPE) | (1<<MSTR) | (1<<SPR1) | (1<<SPR0))
|
||||
|
||||
static const uint8_t m_spi_modes[4] = { SPI_MODE1, SPI_MODE2, SPI_MODE3, SPI_MODE4 };
|
||||
|
||||
static uint8_t m_last_cmd;
|
||||
static uint8_t m_last_val;
|
||||
static uint16_t m_last_addr;
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* spi_rxtx
|
||||
* - transmit one byte to target, and return received one
|
||||
* *********************************************************************** */
|
||||
static uint8_t spi_rxtx(uint8_t val)
|
||||
{
|
||||
SPDR = val;
|
||||
loop_until_bit_is_set(SPSR, SPIF);
|
||||
return SPDR;
|
||||
} /* spi_rxtx */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* spi_set_clk
|
||||
* *********************************************************************** */
|
||||
void spi_set_clk(uint8_t mode)
|
||||
{
|
||||
static uint8_t spi_speed;
|
||||
|
||||
if (mode == SPI_SET_CLK_MAX)
|
||||
{
|
||||
spi_speed = (sizeof(m_spi_modes) -1);
|
||||
}
|
||||
else if ((mode == SPI_SET_CLK_DEC) &&
|
||||
(spi_speed > 0)
|
||||
)
|
||||
{
|
||||
spi_speed--;
|
||||
}
|
||||
|
||||
/* enable SPI master mode */
|
||||
SPCR = m_spi_modes[spi_speed];
|
||||
} /* spi_set_clk */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* spi_init
|
||||
* *********************************************************************** */
|
||||
void spi_init(uint8_t enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
ISP_ACTIVE();
|
||||
spi_set_clk(SPI_SET_CLK_MAX);
|
||||
}
|
||||
else
|
||||
{
|
||||
ISP_INACTIVE();
|
||||
SPCR = 0x00;
|
||||
}
|
||||
} /* spi_init */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* isp_enter_progmode
|
||||
* *********************************************************************** */
|
||||
uint8_t isp_enter_progmode(void)
|
||||
{
|
||||
uint8_t sync;
|
||||
spi_rxtx(CMD_PROG_ENABLE_1);
|
||||
spi_rxtx(CMD_PROG_ENABLE_2);
|
||||
sync = spi_rxtx(0x00);
|
||||
spi_rxtx(0x00);
|
||||
|
||||
return (sync == CMD_PROG_ENABLE_2);
|
||||
} /* isp_enter_progmode */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* isp_mem_write
|
||||
* - write a byte to target flash/eeprom
|
||||
* *********************************************************************** */
|
||||
void isp_mem_write(uint8_t cmd, uint16_t addr, uint8_t val)
|
||||
{
|
||||
spi_rxtx(cmd);
|
||||
spi_rxtx(addr >> 8);
|
||||
spi_rxtx(addr & 0xFF);
|
||||
spi_rxtx(val);
|
||||
|
||||
/* remember values for polling */
|
||||
m_last_cmd = cmd;
|
||||
m_last_addr = addr;
|
||||
m_last_val = val;
|
||||
} /* isp_mem_write */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* isp_mem_read
|
||||
* - read a byte from target flash/eeprom
|
||||
* *********************************************************************** */
|
||||
uint8_t isp_mem_read(uint8_t cmd, uint16_t addr)
|
||||
{
|
||||
spi_rxtx(cmd);
|
||||
spi_rxtx(addr >> 8);
|
||||
spi_rxtx(addr & 0xFF);
|
||||
return spi_rxtx(0x00);
|
||||
} /* isp_mem_read */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* isp_mem_poll
|
||||
* - wait until byte/page is written to target memory
|
||||
* *********************************************************************** */
|
||||
void isp_mem_poll(const avr_device_t * p_device)
|
||||
{
|
||||
uint8_t cmd, val, poll = 0xFF;
|
||||
|
||||
if (((m_last_val == 0x00) && (p_device->flags & POLL_00)) ||
|
||||
((m_last_val == 0x7F) && (p_device->flags & POLL_7F)) ||
|
||||
((m_last_val == 0x80) && (p_device->flags & POLL_80)) ||
|
||||
((m_last_val == 0xFF) && (p_device->flags & POLL_FF))
|
||||
) {
|
||||
/* wait default time */
|
||||
_delay_ms(15);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_last_cmd == CMD_WRITE_EEPROM) {
|
||||
cmd = CMD_READ_EEPROM;
|
||||
|
||||
} else {
|
||||
/* CMD_WRITE_FLASH -> CMD_READ_FLASH */
|
||||
cmd = (m_last_cmd & 0x08) | 0x20;
|
||||
}
|
||||
|
||||
/* poll until we get correct value */
|
||||
do {
|
||||
val = isp_mem_read(cmd, m_last_addr);
|
||||
} while ((val != m_last_val) && poll--);
|
||||
} /* isp_mem_poll */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* isp_mem_pagewrite
|
||||
* *********************************************************************** */
|
||||
void isp_mem_pagewrite(void)
|
||||
{
|
||||
spi_rxtx(CMD_WRITE_FLASH_PAGE);
|
||||
spi_rxtx(m_last_addr >> 8);
|
||||
spi_rxtx(m_last_addr & 0xFF);
|
||||
spi_rxtx(0x00);
|
||||
} /* isp_mem_pagewrite */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* isp_read_signature
|
||||
* *********************************************************************** */
|
||||
void isp_read_signature(uint8_t * p_signature)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
p_signature[i] = isp_mem_read(CMD_READ_SIG_1, (CMD_READ_SIG_2 << 8) | i);
|
||||
}
|
||||
} /* isp_read_signature */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* isp_cmd3
|
||||
* *********************************************************************** */
|
||||
uint8_t isp_cmd3(uint8_t cmd1, uint8_t cmd2,
|
||||
uint8_t cmd3)
|
||||
{
|
||||
uint8_t result;
|
||||
|
||||
spi_rxtx(cmd1);
|
||||
spi_rxtx(cmd2);
|
||||
result = spi_rxtx(cmd3);
|
||||
|
||||
_delay_ms(10);
|
||||
return result;
|
||||
} /* isp_cmd3 */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* isp_cmd4
|
||||
* *********************************************************************** */
|
||||
uint8_t isp_cmd4(uint8_t cmd1, uint8_t cmd2,
|
||||
uint8_t cmd3, uint8_t cmd4)
|
||||
{
|
||||
uint8_t result;
|
||||
|
||||
spi_rxtx(cmd1);
|
||||
spi_rxtx(cmd2);
|
||||
spi_rxtx(cmd3);
|
||||
result = spi_rxtx(cmd4);
|
||||
|
||||
_delay_ms(10);
|
||||
return result;
|
||||
} /* isp_cmd3 */
|
|
@ -0,0 +1,71 @@
|
|||
#ifndef SPI_ISP_H_
|
||||
#define SPI_ISP_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "avrdevice.h"
|
||||
|
||||
/* *********************************************************************** */
|
||||
|
||||
#define SPI_SET_CLK_MAX 0
|
||||
#define SPI_SET_CLK_DEC 1
|
||||
|
||||
#define CMD_PROG_ENABLE_1 0xAC
|
||||
#define CMD_PROG_ENABLE_2 0x53
|
||||
#define CMD_CHIP_ERASE_1 0xAC
|
||||
#define CMD_CHIP_ERASE_2 0x80
|
||||
#define CMD_POLL_BUSY_1 0xF0 /* not used */
|
||||
#define CMD_POLL_BUSY_2 0x00 /* not used */
|
||||
|
||||
#define CMD_LOAD_EADDR_1 0x4D /* not used */
|
||||
#define CMD_LOAD_EADDR_2 0x00 /* not used */
|
||||
#define CMD_LOAD_FLASH_HI 0x48
|
||||
#define CMD_LOAD_FLASH_LO 0x40
|
||||
#define CMD_LOAD_EEPROM_PAGE 0xC1 /* not used */
|
||||
|
||||
#define CMD_READ_FLASH_LO 0x20
|
||||
#define CMD_READ_FLASH_HI 0x28
|
||||
#define CMD_READ_EEPROM 0xA0
|
||||
#define CMD_READ_LOCK_1 0x58
|
||||
#define CMD_READ_LOCK_2 0x00
|
||||
#define CMD_READ_SIG_1 0x30
|
||||
#define CMD_READ_SIG_2 0x00
|
||||
#define CMD_READ_FUSE_1 0x50
|
||||
#define CMD_READ_FUSE_2 0x00
|
||||
#define CMD_READ_FUSE_H_1 0x58
|
||||
#define CMD_READ_FUSE_H_2 0x08
|
||||
#define CMD_READ_FUSE_E_1 0x50
|
||||
#define CMD_READ_FUSE_E_2 0x08
|
||||
#define CMD_READ_CAL 0x38 /* not used */
|
||||
|
||||
#define CMD_WRITE_FLASH_PAGE 0x4C
|
||||
#define CMD_WRITE_EEPROM 0xC0
|
||||
#define CMD_WRITE_EEPROM_PAGE 0xC2 /* not used */
|
||||
#define CMD_WRITE_LOCK_1 0xAC
|
||||
#define CMD_WRITE_LOCK_2 0xE0
|
||||
#define CMD_WRITE_FUSE_1 0xAC
|
||||
#define CMD_WRITE_FUSE_2 0xA0
|
||||
#define CMD_WRITE_FUSE_H_1 0xAC /* not used */
|
||||
#define CMD_WRITE_FUSE_H_2 0xA8 /* not used */
|
||||
#define CMD_WRITE_FUSE_E_1 0xAC /* not used */
|
||||
#define CMD_WRITE_FUSE_E_2 0xA4 /* not used */
|
||||
|
||||
/* *********************************************************************** */
|
||||
|
||||
void spi_set_clk (uint8_t mode);
|
||||
void spi_init (uint8_t enable);
|
||||
|
||||
uint8_t isp_enter_progmode (void);
|
||||
void isp_mem_write (uint8_t cmd, uint16_t addr, uint8_t val);
|
||||
uint8_t isp_mem_read (uint8_t cmd, uint16_t addr);
|
||||
void isp_mem_poll (const avr_device_t * p_device);
|
||||
void isp_mem_pagewrite (void);
|
||||
void isp_read_signature (uint8_t * p_signature);
|
||||
uint8_t isp_cmd3 (uint8_t cmd1, uint8_t cmd2,
|
||||
uint8_t cmd3);
|
||||
uint8_t isp_cmd4 (uint8_t cmd1, uint8_t cmd2,
|
||||
uint8_t cmd3, uint8_t cmd4);
|
||||
|
||||
/* *********************************************************************** */
|
||||
|
||||
#endif /* SPI_ISP_H_ */
|
|
@ -0,0 +1,120 @@
|
|||
#ifndef TARGET_H_
|
||||
#define TARGET_H_
|
||||
|
||||
/* *********************************************************************** */
|
||||
#if defined(CONFIG_ispprog)
|
||||
/*
|
||||
* using ATmega16 @7.3728MHz:
|
||||
* Fuse H: 0xDA (512 words bootloader, jtag disabled)
|
||||
* Fuse L: 0xFF (ext. Crystal)
|
||||
*/
|
||||
#define F_CPU 7372800ULL
|
||||
#define BAUDRATE 115200
|
||||
|
||||
#define ISP_RESET PORTB1 /* to target */
|
||||
#define ISP_LED PORTB3 /* low active */
|
||||
#define ISP_MOSI PORTB5 /* to target */
|
||||
#define ISP_MISO PORTB6 /* to target */
|
||||
#define ISP_SCK PORTB7 /* to target */
|
||||
#define RESET_IN PORTD3 /* high active */
|
||||
|
||||
#define RESET_INACTIVE(){ PORTB |= (1<<ISP_RESET); }
|
||||
#define RESET_ACTIVE() { PORTB &= ~(1<<ISP_RESET); }
|
||||
|
||||
#define ISP_INACTIVE() { /* ISP_SCK and ISP_MOSI are inputs */ \
|
||||
DDRB &= ~((1<<ISP_SCK) | (1<<ISP_MOSI)); \
|
||||
};
|
||||
|
||||
#define ISP_ACTIVE() { /* ISP_SCK and ISP_MOSI are outputs */ \
|
||||
DDRB |= ((1<<ISP_SCK) | (1<<ISP_MOSI)); \
|
||||
};
|
||||
|
||||
#define ISP_LED_ON() { PORTB &= ~(1<<ISP_LED); };
|
||||
#define ISP_LED_OFF() { PORTB |= (1<<ISP_LED); };
|
||||
#define ISP_CHECK() (PIND & (1<<RESET_IN))
|
||||
|
||||
#define USE_DISPLAY 0
|
||||
|
||||
#define TIMER_DIVISOR 1024
|
||||
#define TIMER_INIT() { /* timer0, FCPU/1024, overflow interrupt */ \
|
||||
TCCR0 = (1<<CS02) | (1<<CS00); \
|
||||
TIMSK = (1<<TOIE0); \
|
||||
}
|
||||
|
||||
#define GPIO_INIT() { /* ISP_RESET and ISP_LED are outputs, pullup SlaveSelect */ \
|
||||
PORTB = (1<<ISP_RESET) | (1<<ISP_LED) | (1<<PORTB4); \
|
||||
DDRB = (1<<ISP_RESET) | (1<<ISP_LED); \
|
||||
};
|
||||
|
||||
/* *********************************************************************** */
|
||||
#elif defined(CONFIG_ispprog2)
|
||||
/*
|
||||
* using ATmega328P @8MHz:
|
||||
* Fuse E: 0xFA (2.7V BOD)
|
||||
* Fuse H: 0xDC (512 words bootloader)
|
||||
* Fuse L: 0xE2 (internal osc)
|
||||
*/
|
||||
#define F_CPU 8000000ULL
|
||||
#define BAUDRATE 115200
|
||||
|
||||
/* trim internal oscillator to get "good" baudrate */
|
||||
#define OSCCAL_VALUE 0x80
|
||||
|
||||
#define ISP_RESET PORTB2 /* to target */
|
||||
#define ISP_LED PORTB0 /* high active */
|
||||
#define ISP_MOSI PORTB3 /* to target */
|
||||
#define ISP_MISO PORTB4 /* to target */
|
||||
#define ISP_SCK PORTB5 /* to target */
|
||||
#define RESET_IN PORTB1 /* low active */
|
||||
|
||||
#define RESET_INACTIVE(){ PORTB |= (1<<ISP_RESET); }
|
||||
#define RESET_ACTIVE() { PORTB &= ~(1<<ISP_RESET); }
|
||||
|
||||
#define ISP_INACTIVE() { /* ISP_SCK and ISP_MOSI are inputs */ \
|
||||
DDRB &= ~((1<<ISP_SCK) | (1<<ISP_MOSI)); \
|
||||
};
|
||||
|
||||
#define ISP_ACTIVE() { /* ISP_SCK and ISP_MOSI and ISP_RESET are outputs */ \
|
||||
DDRB |= ((1<<ISP_SCK) | (1<<ISP_MOSI)); \
|
||||
};
|
||||
|
||||
#define ISP_LED_ON() { PORTB |= (1<<ISP_LED); };
|
||||
#define ISP_LED_OFF() { PORTB &= ~(1<<ISP_LED); };
|
||||
#define ISP_CHECK() !(PINB & (1<<RESET_IN))
|
||||
|
||||
/* DL1414 display */
|
||||
#define USE_DISPLAY 1
|
||||
#define DISP_WR PORTC2 /* low active */
|
||||
#define DISP_A0 PORTC0
|
||||
#define DISP_A1 PORTC1
|
||||
#define DISP_D0 PORTC3
|
||||
#define DISP_D1 PORTD2
|
||||
#define DISP_D2 PORTD3
|
||||
#define DISP_D3 PORTD4
|
||||
#define DISP_D4 PORTD5
|
||||
#define DISP_D5 PORTD6
|
||||
#define DISP_D6 PORTD7
|
||||
|
||||
#define TIMER_DIVISOR 1024
|
||||
#define TIMER_INIT() { /* timer0, FCPU/1024, overflow interrupt */ \
|
||||
TCCR0B = (1<<CS02) | (1<<CS00); \
|
||||
TIMSK0 = (1<<TOIE0); \
|
||||
}
|
||||
|
||||
#define GPIO_INIT() { /* ISP_RESET and ISP_LED are outputs, pullup RESET_IN and SlaveSelect */ \
|
||||
PORTB = (1<<ISP_RESET) | (1<<RESET_IN) | (1<<PORTB2); \
|
||||
DDRB = (1<<ISP_RESET) | (1<<ISP_LED); \
|
||||
\
|
||||
/* all DISP_* pins are outputs, DISP_WR is high */ \
|
||||
DDRC = (1<<DISP_WR) | (1<<DISP_A0) | (1<<DISP_A1) | (1<<DISP_D0); \
|
||||
PORTC = (1<<DISP_WR); \
|
||||
DDRD = 0xFC; \
|
||||
};
|
||||
|
||||
/* *********************************************************************** */
|
||||
#else
|
||||
#error "unknown CONFIG"
|
||||
#endif
|
||||
/* *********************************************************************** */
|
||||
|
||||
#endif /* TARGET_H_ */
|
|
@ -0,0 +1,107 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2006 - 2020 by Olaf Rempel *
|
||||
* razzor AT kopf MINUS tisch DOT de *
|
||||
* *
|
||||
* 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; version 2 of the License, *
|
||||
* *
|
||||
* 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. *
|
||||
***************************************************************************/
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "target.h"
|
||||
#include "uart.h"
|
||||
|
||||
#define UART_CALC_BAUDRATE(baudRate) (((uint32_t)F_CPU) / (((uint32_t)baudRate)*16) -1)
|
||||
|
||||
/* ***********************************************************************
|
||||
* uart_send
|
||||
* *********************************************************************** */
|
||||
void uart_send(uint8_t data)
|
||||
{
|
||||
#if defined(__AVR_ATmega16__)
|
||||
loop_until_bit_is_set(UCSRA, UDRE);
|
||||
UDR = data;
|
||||
#elif defined(__AVR_ATmega328P__)
|
||||
loop_until_bit_is_set(UCSR0A, UDRE0);
|
||||
UDR0 = data;
|
||||
#endif
|
||||
} /* uart_send */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* uart_recv
|
||||
* *********************************************************************** */
|
||||
uint8_t uart_recv(void)
|
||||
{
|
||||
#if defined(__AVR_ATmega16__)
|
||||
loop_until_bit_is_set(UCSRA, RXC);
|
||||
return UDR;
|
||||
#elif defined(__AVR_ATmega328P__)
|
||||
loop_until_bit_is_set(UCSR0A, RXC0);
|
||||
return UDR0;
|
||||
#endif
|
||||
} /* uart_recv */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* uart_rx_ready
|
||||
* *********************************************************************** */
|
||||
uint8_t uart_rx_ready(void)
|
||||
{
|
||||
#if defined(__AVR_ATmega16__)
|
||||
return ((UCSRA & (1<<RXC)) == (1<<RXC));
|
||||
#elif defined(__AVR_ATmega328P__)
|
||||
return ((UCSR0A & (1<<RXC0)) == (1<<RXC0));
|
||||
#endif
|
||||
} /* uart_rx_ready */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* uart_recv_buf
|
||||
* *********************************************************************** */
|
||||
void uart_recv_buf(uint8_t * p_data, uint16_t data_length)
|
||||
{
|
||||
while (data_length--)
|
||||
{
|
||||
*p_data++ = uart_recv();
|
||||
}
|
||||
} /* uart_recv_buf */
|
||||
|
||||
|
||||
/* ***********************************************************************
|
||||
* uart_init
|
||||
* *********************************************************************** */
|
||||
void uart_init(void)
|
||||
{
|
||||
#if defined(OSCCAL_VALUE)
|
||||
OSCCAL = OSCCAL_VALUE;
|
||||
#endif /* defined(OSCCAL_VALUE) */
|
||||
|
||||
#if defined(__AVR_ATmega16__)
|
||||
/* Set baud rate */
|
||||
UBRRH = (UART_CALC_BAUDRATE(BAUDRATE)>>8) & 0xFF;
|
||||
UBRRL = (UART_CALC_BAUDRATE(BAUDRATE) & 0xFF);
|
||||
|
||||
/* enable usart with 8n1 */
|
||||
UCSRB = (1<<TXEN) | (1<<RXEN);
|
||||
UCSRC = (1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0);
|
||||
#elif defined(__AVR_ATmega328P__)
|
||||
/* Set baud rate */
|
||||
UBRR0H = (UART_CALC_BAUDRATE(BAUDRATE)>>8) & 0xFF;
|
||||
UBRR0L = (UART_CALC_BAUDRATE(BAUDRATE) & 0xFF);
|
||||
|
||||
/* enable usart with 8n1 */
|
||||
UCSR0B = (1<<TXEN0) | (1<<RXEN0);
|
||||
UCSR0C = (1<<UCSZ01) | (1<<UCSZ00);
|
||||
#endif
|
||||
} /* uart_init */
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef UART_H_
|
||||
#define UART_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* *********************************************************************** */
|
||||
|
||||
void uart_send (uint8_t data);
|
||||
uint8_t uart_recv (void);
|
||||
uint8_t uart_rx_ready (void);
|
||||
|
||||
void uart_recv_buf (uint8_t * p_data, uint16_t data_length);
|
||||
|
||||
void uart_init (void);
|
||||
|
||||
/* *********************************************************************** */
|
||||
|
||||
#endif /* UART_H_ */
|
Loading…
Reference in New Issue