Compare commits
355 Commits
mem_compac
...
deflate
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3cc6f41e2 | ||
|
|
5a439f56bb | ||
|
|
7a8ae11ce1 | ||
|
|
e177b17ad8 | ||
|
|
54acc416b0 | ||
|
|
185b833929 | ||
|
|
97137ed993 | ||
|
|
e13b124e93 | ||
|
|
76254835ca | ||
|
|
1adabc080f | ||
|
|
6eead3e37d | ||
|
|
05bb485495 | ||
|
|
3c39e11784 | ||
|
|
2ad1d63ca6 | ||
|
|
53376edc09 | ||
|
|
ef82981d42 | ||
|
|
697742d59f | ||
|
|
6935aa9693 | ||
|
|
67e02fb38e | ||
|
|
a9a366895a | ||
|
|
596a26323a | ||
|
|
13c71760c8 | ||
|
|
f027b93a1a | ||
|
|
5b6e62a428 | ||
|
|
ea3113142e | ||
|
|
08a1c0b3e0 | ||
|
|
2e59b07d7d | ||
|
|
ec555efafd | ||
|
|
cfceee4db3 | ||
|
|
1d0eae3aec | ||
|
|
650b182ab4 | ||
|
|
b092b3e182 | ||
|
|
ab3f7704f0 | ||
|
|
859dcadbac | ||
|
|
c897497e24 | ||
|
|
ba64d2a683 | ||
|
|
65a852ebb4 | ||
|
|
2e99c42510 | ||
|
|
d777415549 | ||
|
|
3f91df1af6 | ||
|
|
1bbc73c363 | ||
|
|
a019317b6e | ||
|
|
243658c0d3 | ||
|
|
080598cb97 | ||
|
|
51087abaa2 | ||
|
|
7671a35127 | ||
|
|
1a7fb2487e | ||
|
|
a341e10efc | ||
|
|
b7cc7ea935 | ||
|
|
55aa99c4d3 | ||
|
|
2e432cd7a7 | ||
|
|
d3a48efb0b | ||
|
|
7c9aca48c9 | ||
|
|
440c24ad78 | ||
|
|
0d7fc524f2 | ||
|
|
b2e13a54eb | ||
|
|
850d1790cb | ||
|
|
9b3dcc844f | ||
|
|
5767b13385 | ||
|
|
ec68a9a1a1 | ||
|
|
54ac4204ed | ||
|
|
8a8b21615c | ||
|
|
49df405d14 | ||
|
|
7f0a9f9285 | ||
|
|
e7e5cfd126 | ||
|
|
6c702b9a68 | ||
|
|
2bdc53bd21 | ||
|
|
415b79751d | ||
|
|
b9425b1da5 | ||
|
|
9c4c880b0b | ||
|
|
c6b9c57e6d | ||
|
|
0295c8c385 | ||
|
|
2e01e2bfb3 | ||
|
|
07a0296886 | ||
|
|
0d473fd0dd | ||
|
|
5451aeb39b | ||
|
|
fa27d73167 | ||
|
|
4b0bec820e | ||
|
|
105575bc37 | ||
|
|
8beb0bbb4f | ||
|
|
6db781d12d | ||
|
|
a86d9d26bd | ||
|
|
d86f0ad5a9 | ||
|
|
d9b729754c | ||
|
|
f5cdf71fb1 | ||
|
|
d008551968 | ||
|
|
0d2c2c274b | ||
|
|
a28a7e928a | ||
|
|
8650109879 | ||
|
|
c30ca4ca54 | ||
|
|
2d601dac17 | ||
|
|
f8599fb60a | ||
|
|
db616a1637 | ||
|
|
935c1d6f7f | ||
|
|
325a09eff2 | ||
|
|
dab671a5da | ||
|
|
485a7831db | ||
|
|
99cee555c1 | ||
|
|
dc67d91c4f | ||
|
|
90d4a0d019 | ||
|
|
9be841521f | ||
|
|
e3067c7256 | ||
|
|
3a1f58ce18 | ||
|
|
a6e8d7e033 | ||
|
|
1fb3cfdfd9 | ||
|
|
04b2b9a02a | ||
|
|
58b422771a | ||
|
|
6256cab7ef | ||
|
|
c60d2f92fa | ||
|
|
aeb3638e1f | ||
|
|
0b81db48e3 | ||
|
|
5e31bc1946 | ||
|
|
9e1fec1ec6 | ||
|
|
87b5936c02 | ||
|
|
9efca9e242 | ||
|
|
f9e1a7a151 | ||
|
|
68b882acfb | ||
|
|
3928f5548e | ||
|
|
b8a45b6a38 | ||
|
|
bc08b4a71a | ||
|
|
9469398c04 | ||
|
|
bb1367c243 | ||
|
|
710aa2d53a | ||
|
|
9908f32103 | ||
|
|
2a143d3d9f | ||
|
|
72678f3ed5 | ||
|
|
3381998d0f | ||
|
|
98c470dbc0 | ||
|
|
cd948a94d1 | ||
|
|
346216ceb8 | ||
|
|
4bd3876adc | ||
|
|
c6e27c7c1f | ||
|
|
44df97f81a | ||
|
|
b1db3f6ae0 | ||
|
|
f273b986c1 | ||
|
|
bb209bb464 | ||
|
|
507957f7cc | ||
|
|
a741a2ff3a | ||
|
|
ba7f2dd94b | ||
|
|
4fa167a61d | ||
|
|
b375b0d510 | ||
|
|
ced4b73075 | ||
|
|
0887e64266 | ||
|
|
34ed695dee | ||
|
|
d8eb1eb4a4 | ||
|
|
d67158f523 | ||
|
|
ce327a382e | ||
|
|
ba27b79bb3 | ||
|
|
fb86f7ba7b | ||
|
|
0981d9fd3c | ||
|
|
982c56e426 | ||
|
|
d8f6f8f748 | ||
|
|
096227ca98 | ||
|
|
d8b23614d7 | ||
|
|
d1415c6283 | ||
|
|
ee9b377698 | ||
|
|
98ac61c91d | ||
|
|
752a16fd07 | ||
|
|
b47af2c376 | ||
|
|
07086b2a3c | ||
|
|
bfc795d35b | ||
|
|
dbff180a91 | ||
|
|
df167b285e | ||
|
|
cd7ac81a2d | ||
|
|
f7dc5b3bd8 | ||
|
|
1f68465dc6 | ||
|
|
5e5df7e275 | ||
|
|
ba2ac254a7 | ||
|
|
1282e93334 | ||
|
|
decb810bcc | ||
|
|
b6d5d1b571 | ||
|
|
406c884cfe | ||
|
|
6ef9989320 | ||
|
|
97962b8e89 | ||
|
|
cf95b95723 | ||
|
|
af45ed720b | ||
|
|
92762d7f51 | ||
|
|
3e3fbe5bc4 | ||
|
|
570323f017 | ||
|
|
d1447db7b0 | ||
|
|
1b45c2f325 | ||
|
|
1539ff6111 | ||
|
|
c5e72c48eb | ||
|
|
82a6edad50 | ||
|
|
553ef0059a | ||
|
|
01e41d36dd | ||
|
|
3a85bb2ee5 | ||
|
|
29fb976051 | ||
|
|
3e988eafe2 | ||
|
|
7f84c8d97a | ||
|
|
1c8c3dc244 | ||
|
|
170ef9f5c6 | ||
|
|
6cab377087 | ||
|
|
8670300642 | ||
|
|
68d4ffc7f1 | ||
|
|
31989233b4 | ||
|
|
b2bf789b85 | ||
|
|
e45b08a5fb | ||
|
|
9e1a9fffc5 | ||
|
|
8bee3f786f | ||
|
|
31687b3094 | ||
|
|
cc2c7ab4dc | ||
|
|
a7270acdf1 | ||
|
|
56713860ac | ||
|
|
fbd05f2863 | ||
|
|
3a794947f0 | ||
|
|
ed16c23002 | ||
|
|
446c3932ae | ||
|
|
8e2889212a | ||
|
|
5a2bba0d33 | ||
|
|
8f0096eb5e | ||
|
|
18c4b45824 | ||
|
|
0f9ebb146e | ||
|
|
d7b82e2503 | ||
|
|
ef14c4dcd8 | ||
|
|
d609954c8b | ||
|
|
05db3108a2 | ||
|
|
a518ff1e1e | ||
|
|
e67e726743 | ||
|
|
ff6e13d8f0 | ||
|
|
935b2a3557 | ||
|
|
2e84cf22d1 | ||
|
|
bcd3d802f0 | ||
|
|
fd1e5d890a | ||
|
|
5cb972e7f6 | ||
|
|
21298fc63f | ||
|
|
f1b89eee83 | ||
|
|
10d435d2f9 | ||
|
|
690bfd6502 | ||
|
|
c55a66f90d | ||
|
|
fef90c7f6e | ||
|
|
8d571d0c55 | ||
|
|
c110d1132a | ||
|
|
30399e2d1c | ||
|
|
78b77a1352 | ||
|
|
b67de0308c | ||
|
|
9d707f612a | ||
|
|
0a62ac52be | ||
|
|
7ef03b498f | ||
|
|
656192fc14 | ||
|
|
77d9418cee | ||
|
|
2ebd2b75aa | ||
|
|
f9724a3209 | ||
|
|
50886c58bd | ||
|
|
6419623018 | ||
|
|
fc785d3ec8 | ||
|
|
cc54fb9f61 | ||
|
|
daae8ef051 | ||
|
|
811b82616e | ||
|
|
8e6c67db08 | ||
|
|
accdf39f18 | ||
|
|
0b12206f1d | ||
|
|
e4e4beac3a | ||
|
|
36d6899692 | ||
|
|
1f6c710e9e | ||
|
|
b7b35800cc | ||
|
|
a9640af2bf | ||
|
|
b6956c8fbd | ||
|
|
d727e978be | ||
|
|
128c27d441 | ||
|
|
08e6710321 | ||
|
|
bc25723df0 | ||
|
|
ce712477fe | ||
|
|
4a0461987b | ||
|
|
8b10ccc7de | ||
|
|
c24d6ceb81 | ||
|
|
1b2b7ecbed | ||
|
|
465ea1fbfe | ||
|
|
b8bd7acfa3 | ||
|
|
6a8e8e4692 | ||
|
|
6b8a6babb7 | ||
|
|
d65a17184f | ||
|
|
b443d3df2f | ||
|
|
4f8e258710 | ||
|
|
c4631f2991 | ||
|
|
f3cc60e77b | ||
|
|
989b738c49 | ||
|
|
0fc0500cc6 | ||
|
|
086f77b551 | ||
|
|
925c54a9c6 | ||
|
|
b2c644b6e7 | ||
|
|
9991dfa249 | ||
|
|
396729e2e2 | ||
|
|
622841e70a | ||
|
|
1100333487 | ||
|
|
4ea1912318 | ||
|
|
c30e626a3f | ||
|
|
66a592eeff | ||
|
|
a4751edf97 | ||
|
|
7bdc299e61 | ||
|
|
8299d3d581 | ||
|
|
483c89c337 | ||
|
|
f832f0f72b | ||
|
|
8e1e5ea072 | ||
|
|
309e1062b9 | ||
|
|
cb0ea4f8c8 | ||
|
|
c1203c3519 | ||
|
|
4a61063406 | ||
|
|
641903c166 | ||
|
|
f5eb151288 | ||
|
|
74e238bdca | ||
|
|
19cc80e70d | ||
|
|
0b9ed151fa | ||
|
|
c1d066ae3c | ||
|
|
78a799d718 | ||
|
|
1ead73684d | ||
|
|
92c4e4d686 | ||
|
|
69182c85b0 | ||
|
|
53e0a0999e | ||
|
|
0a50554f4a | ||
|
|
3ecc61adf4 | ||
|
|
dfcf4016b1 | ||
|
|
515ed6dd27 | ||
|
|
4419128348 | ||
|
|
551ecb1915 | ||
|
|
ae0f35d746 | ||
|
|
4ec2da3a5c | ||
|
|
6b89029105 | ||
|
|
a64e9ebd7d | ||
|
|
6bab776497 | ||
|
|
7b98ebb480 | ||
|
|
2fd08d0df7 | ||
|
|
d69d2bf398 | ||
|
|
a9df4311b4 | ||
|
|
b6c8135749 | ||
|
|
23a5b777ec | ||
|
|
660767c464 | ||
|
|
0fd42d7b1d | ||
|
|
a6aade11c4 | ||
|
|
ce5d1de968 | ||
|
|
c8afff5630 | ||
|
|
efe6ba19c4 | ||
|
|
8929a96e6e | ||
|
|
5dd4904f9c | ||
|
|
aa649c89ee | ||
|
|
ef69ab4ab3 | ||
|
|
1075795ef4 | ||
|
|
c66828729f | ||
|
|
46a566ce14 | ||
|
|
ca2f62ee62 | ||
|
|
48b15ca792 | ||
|
|
7a878eab39 | ||
|
|
091b82a7ef | ||
|
|
1c30d3db56 | ||
|
|
9cf6eae076 | ||
|
|
67a25941a7 | ||
|
|
aedc6dab5b | ||
|
|
c40b9c32b6 | ||
|
|
59aad4c7a8 | ||
|
|
af48032798 | ||
|
|
d481bd5061 | ||
|
|
96c273fe89 | ||
|
|
25c1f38aed | ||
|
|
0693dbc933 | ||
|
|
500e6326c1 |
@@ -1,4 +0,0 @@
|
|||||||
--- !ditz.rubyforge.org,2008-03-06/config
|
|
||||||
name: David
|
|
||||||
email: david@optixx.org
|
|
||||||
issue_dir: bugs
|
|
||||||
15
.gitignore
vendored
15
.gitignore
vendored
@@ -21,3 +21,18 @@
|
|||||||
*.swc
|
*.swc
|
||||||
*.rom
|
*.rom
|
||||||
*.usage
|
*.usage
|
||||||
|
*.moc
|
||||||
|
*.obj
|
||||||
|
*.TMP
|
||||||
|
*.vfat
|
||||||
|
*.wla*
|
||||||
|
*.rcc
|
||||||
|
*.log
|
||||||
|
bootloader
|
||||||
|
snesuploader
|
||||||
|
tmtags
|
||||||
|
bsnes
|
||||||
|
web
|
||||||
|
ucon64.exe
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "scripts/webpy"]
|
||||||
|
path = scripts/webpy
|
||||||
|
url = git://github.com/webpy/webpy.git
|
||||||
9
README
9
README
@@ -1 +1,8 @@
|
|||||||
o Test
|
________ .__ __ ________ ____ ________
|
||||||
|
\_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
/ / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
/ \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
\_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
\__> \/ \/ \/ \/ \/
|
||||||
|
|
||||||
|
www.optixx.org
|
||||||
78
avr/bootloader/Makefile
Normal file
78
avr/bootloader/Makefile
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
|
||||||
|
# microcontroller and project specific settings
|
||||||
|
TARGET = bootloader
|
||||||
|
F_CPU = 20000000UL
|
||||||
|
MCU = atmega644
|
||||||
|
|
||||||
|
SRC = bootloader.c
|
||||||
|
ASRC = usbdrv/usbdrvasm.S interrupts.S
|
||||||
|
OBJECTS += $(patsubst %.c,%.o,${SRC})
|
||||||
|
OBJECTS += $(patsubst %.S,%.o,${ASRC})
|
||||||
|
HEADERS += $(shell echo *.h)
|
||||||
|
# CFLAGS += -Werror
|
||||||
|
|
||||||
|
LDFLAGS += -L/usr/local/avr/avr/lib
|
||||||
|
CFLAGS += -Iusbdrv -I.
|
||||||
|
CFLAGS += -DHARDWARE_REV=$(HARDWARE_REV)
|
||||||
|
CDEFS += -DF_CPU
|
||||||
|
ASFLAGS += -x assembler-with-cpp
|
||||||
|
ASFLAGS += -Iusbdrv -I.
|
||||||
|
|
||||||
|
# use own linkerscript, for special interrupt table handling
|
||||||
|
LDFLAGS += -T ./ldscripts/avr5.x
|
||||||
|
|
||||||
|
# no safe mode checks
|
||||||
|
AVRDUDE_FLAGS += -u
|
||||||
|
|
||||||
|
# set name for dependency-file
|
||||||
|
MAKEFILE = Makefile
|
||||||
|
|
||||||
|
# bootloader section start
|
||||||
|
# (see datasheet)
|
||||||
|
ifeq ($(MCU),atmega168)
|
||||||
|
# atmega168 with 1024 words bootloader:
|
||||||
|
# bootloader section starts at 0x1c00 (word-address) == 0x3800 (byte-address)
|
||||||
|
BOOT_SECTION_START = 0x3800
|
||||||
|
else ifeq ($(MCU),atmega88)
|
||||||
|
# atmega88 with 1024 words bootloader:
|
||||||
|
# bootloader section starts at 0xc00 (word-address) == 0x1800 (byte-address)
|
||||||
|
BOOT_SECTION_START = 0x1800
|
||||||
|
else ifeq ($(MCU),atmega644)
|
||||||
|
# atmega644 with 2048 words bootloader:
|
||||||
|
# bootloader section starts at 0x7800 (word-address) == 0xF000 (byte-address)
|
||||||
|
BOOT_SECTION_START = 0xf000
|
||||||
|
endif
|
||||||
|
|
||||||
|
LDFLAGS += -Wl,--section-start=.text=$(BOOT_SECTION_START) -Wl,-u,vfprintf
|
||||||
|
CFLAGS += -DBOOT_SECTION_START=$(BOOT_SECTION_START)
|
||||||
|
|
||||||
|
|
||||||
|
include avr.mk
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
|
||||||
|
all: $(TARGET).hex $(TARGET).lss
|
||||||
|
@echo "==============================="
|
||||||
|
@echo "$(TARGET) compiled for: $(MCU)"
|
||||||
|
@echo -n "size is: "
|
||||||
|
@$(SIZE) -A $(TARGET).hex | grep "\.sec1" | tr -s " " | cut -d" " -f2
|
||||||
|
@echo "==============================="
|
||||||
|
|
||||||
|
$(TARGET): $(OBJECTS) $(TARGET).o
|
||||||
|
|
||||||
|
%.o: $(HEADERS)
|
||||||
|
|
||||||
|
.PHONY: clean clean-$(TARGET)
|
||||||
|
|
||||||
|
clean: clean-$(TARGET)
|
||||||
|
|
||||||
|
clean-$(TARGET):
|
||||||
|
$(RM) $(TARGET) $(OBJECTS)
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: depend test
|
||||||
|
|
||||||
|
depend:
|
||||||
|
$(CC) $(CFLAGS) -M $(CDEFS) $(CINCS) $(SRC) >> $(MAKEFILE).dep
|
||||||
|
|
||||||
|
-include $(MAKEFILE).dep
|
||||||
86
avr/bootloader/avr.mk
Normal file
86
avr/bootloader/avr.mk
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
# Programmer used for In System Programming
|
||||||
|
ISP_PROG = usbasp
|
||||||
|
# device the ISP programmer is connected to
|
||||||
|
ISP_DEV =
|
||||||
|
# Programmer used for serial programming (using the bootloader)
|
||||||
|
SERIAL_PROG = avr109
|
||||||
|
# device the serial programmer is connected to
|
||||||
|
SERIAL_DEV = /dev/ttyS0
|
||||||
|
|
||||||
|
# programs
|
||||||
|
CC = avr-gcc
|
||||||
|
OBJCOPY = avr-objcopy
|
||||||
|
OBJDUMP = avr-objdump
|
||||||
|
AS = avr-as
|
||||||
|
CP = cp
|
||||||
|
RM = rm -f
|
||||||
|
AVRDUDE = avrdude
|
||||||
|
SIZE = avr-size
|
||||||
|
|
||||||
|
-include $(CURDIR)/config.mk
|
||||||
|
|
||||||
|
# flags for avrdude
|
||||||
|
ifeq ($(MCU),atmega8)
|
||||||
|
AVRDUDE_MCU=m8
|
||||||
|
endif
|
||||||
|
ifeq ($(MCU),atmega48)
|
||||||
|
AVRDUDE_MCU=m48
|
||||||
|
endif
|
||||||
|
ifeq ($(MCU),atmega88)
|
||||||
|
AVRDUDE_MCU=m88
|
||||||
|
endif
|
||||||
|
ifeq ($(MCU),atmega168)
|
||||||
|
AVRDUDE_MCU=m168
|
||||||
|
endif
|
||||||
|
ifeq ($(MCU),atmega644)
|
||||||
|
AVRDUDE_MCU=m644
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
AVRDUDE_FLAGS += -p $(AVRDUDE_MCU)
|
||||||
|
|
||||||
|
# flags for the compiler
|
||||||
|
CFLAGS += -g -Os -finline-limit=800 -mmcu=$(MCU) -DF_CPU=$(F_CPU) -std=gnu99
|
||||||
|
ASFLAGS += -g -mmcu=$(MCU) -DF_CPU=$(F_CPU)
|
||||||
|
|
||||||
|
# flags for the linker
|
||||||
|
LDFLAGS += -mmcu=$(MCU)
|
||||||
|
|
||||||
|
ifneq ($(DEBUG),)
|
||||||
|
CFLAGS += -Wall -W -Wchar-subscripts -Wmissing-prototypes
|
||||||
|
CFLAGS += -Wmissing-declarations -Wredundant-decls
|
||||||
|
CFLAGS += -Wstrict-prototypes -Wshadow -Wbad-function-cast
|
||||||
|
CFLAGS += -Winline -Wpointer-arith -Wsign-compare
|
||||||
|
#CFLAGS += -Wunreachable-code -Wdisabled-optimization -Werror
|
||||||
|
CFLAGS += -Wunreachable-code -Wdisabled-optimization
|
||||||
|
CFLAGS += -Wcast-align -Wwrite-strings -Wnested-externs -Wundef
|
||||||
|
CFLAGS += -Wa,-adhlns=$(basename $@).lst
|
||||||
|
CFLAGS += -DDEBUG
|
||||||
|
endif
|
||||||
|
|
||||||
|
all:
|
||||||
|
|
||||||
|
$(OBJECTS):
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) *.hex *.eep.hex *.o *.lst *.lss
|
||||||
|
|
||||||
|
.PHONY: all clean interactive-isp interactive-serial launch-bootloader
|
||||||
|
|
||||||
|
flash: bootloader.hex
|
||||||
|
$(AVRDUDE) $(AVRDUDE_FLAGS) -c $(ISP_PROG) -U flash:w:$<
|
||||||
|
|
||||||
|
flash-eeprom-%: %.eep.hex
|
||||||
|
$(AVRDUDE) $(AVRDUDE_FLAGS) -c $(ISP_PROG) -P $(ISP_DEV) -U eeprom:w:$<
|
||||||
|
|
||||||
|
%.hex: %
|
||||||
|
$(OBJCOPY) -O ihex -R .eeprom $< $@
|
||||||
|
|
||||||
|
%.eep.hex: %
|
||||||
|
$(OBJCOPY) --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex -j .eeprom $< $@
|
||||||
|
|
||||||
|
%.lss: %
|
||||||
|
$(OBJDUMP) -h -S $< > $@
|
||||||
|
|
||||||
|
%-size: %.hex
|
||||||
|
$(SIZE) $<
|
||||||
558
avr/bootloader/bootloader.c
Normal file
558
avr/bootloader/bootloader.c
Normal file
@@ -0,0 +1,558 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* simple USBasp compatible bootloader by
|
||||||
|
* Alexander Neumann <alexander@lochraster.org>
|
||||||
|
* inspired by USBasploader by Christian Starkjohann,
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include <avr/boot.h>
|
||||||
|
#include <avr/eeprom.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "usbdrv/usbdrv.c"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* USBasp requests, taken from the original USBasp sourcecode
|
||||||
|
*/
|
||||||
|
#define USBASP_FUNC_CONNECT 1
|
||||||
|
#define USBASP_FUNC_DISCONNECT 2
|
||||||
|
#define USBASP_FUNC_TRANSMIT 3
|
||||||
|
#define USBASP_FUNC_READFLASH 4
|
||||||
|
#define USBASP_FUNC_ENABLEPROG 5
|
||||||
|
#define USBASP_FUNC_WRITEFLASH 6
|
||||||
|
#define USBASP_FUNC_READEEPROM 7
|
||||||
|
#define USBASP_FUNC_WRITEEEPROM 8
|
||||||
|
#define USBASP_FUNC_SETLONGADDRESS 9
|
||||||
|
|
||||||
|
/*
|
||||||
|
* additional functions
|
||||||
|
*/
|
||||||
|
#define FUNC_ECHO 0x17
|
||||||
|
|
||||||
|
/*
|
||||||
|
* atmel isp commands
|
||||||
|
*/
|
||||||
|
#define ISP_CHIP_ERASE1 0xAC
|
||||||
|
#define ISP_CHIP_ERASE2 0x80
|
||||||
|
#define ISP_READ_SIGNATURE 0x30
|
||||||
|
#define ISP_READ_EEPROM 0xa0
|
||||||
|
#define ISP_WRITE_EEPROM 0xc0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define LED_PORT PORTC
|
||||||
|
#define LED_DIR DDRC
|
||||||
|
#define LED_PIN PC7
|
||||||
|
|
||||||
|
#define DLED_ON {((LED_PORT &=~ (1 << LED_PIN)),\
|
||||||
|
(LED_DIR &=~ (1 << LED_PIN))); }
|
||||||
|
#define DLED_OFF {((LED_PORT &=~ (1 << LED_PIN)),\
|
||||||
|
(LED_DIR |= (1 << LED_PIN))); }
|
||||||
|
#define DLED_TGL {((LED_PORT &=~ (1 << LED_PIN)),\
|
||||||
|
(LED_DIR ^= (1 << LED_PIN)));}
|
||||||
|
|
||||||
|
|
||||||
|
#define AVR_BTLDR_EN_PORT PORTC
|
||||||
|
#define AVR_BTLDR_EN_DIR DDRC
|
||||||
|
#define AVR_BTLDR_EN_PIN PC1
|
||||||
|
#define AVR_BTLDR_EN_IN PINC
|
||||||
|
|
||||||
|
#undef AVR_BTLDR_SWITCH
|
||||||
|
/*
|
||||||
|
* some predefined signatures, taken from the original USBasp sourcecode
|
||||||
|
*/
|
||||||
|
static const uint8_t signature[4] = {
|
||||||
|
#ifdef SIGNATURE_BYTES
|
||||||
|
SIGNATURE_BYTES
|
||||||
|
#elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega8HVA__)
|
||||||
|
0x1e, 0x93, 0x07, 0
|
||||||
|
#elif defined (__AVR_ATmega48__) || defined (__AVR_ATmega48P__)
|
||||||
|
0x1e, 0x92, 0x05, 0
|
||||||
|
#elif defined (__AVR_ATmega88__) || defined (__AVR_ATmega88P__)
|
||||||
|
0x1e, 0x93, 0x0a, 0
|
||||||
|
#elif defined (__AVR_ATmega168__) || defined (__AVR_ATmega168P__)
|
||||||
|
0x1e, 0x94, 0x06, 0
|
||||||
|
#elif defined (__AVR_ATmega328P__)
|
||||||
|
0x1e, 0x95, 0x0f, 0
|
||||||
|
#elif defined (__AVR_ATmega644__)
|
||||||
|
0x1e, 0x96, 0x09, 0
|
||||||
|
#else
|
||||||
|
# error "Device signature is not known, please edit config.h!"
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef BOOT_SECTION_START
|
||||||
|
# error "BOOT_SECTION_START undefined!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined (__AVR_ATmega644__)
|
||||||
|
/*
|
||||||
|
* Due arvdude limitations we can't erase the whole progmem without running into an usb timeount on cleint side. So we we limit the
|
||||||
|
* erase section by 0x1000
|
||||||
|
*/
|
||||||
|
#define ERASE_SECTION 0xe000
|
||||||
|
#else
|
||||||
|
#define ERASE_SECTION BOOT_SECTION_START
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DEBUG_UART
|
||||||
|
static __attribute__ ((__noinline__))
|
||||||
|
void uart_putc(uint8_t data)
|
||||||
|
{
|
||||||
|
while (!(UCSR0A & _BV(UDRE0)));
|
||||||
|
UDR0 = data;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define uart_putc(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG_UART
|
||||||
|
static __attribute__ ((__noinline__))
|
||||||
|
void uart_puts(uint8_t * data)
|
||||||
|
{
|
||||||
|
while (*data) {
|
||||||
|
uart_putc(*data);
|
||||||
|
data++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define uart_puts(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* supply custom usbDeviceConnect() and usbDeviceDisconnect() macros which turn the interrupt on and off at the right times, and prevent
|
||||||
|
* the execution of an interrupt while the pullup resistor is switched off
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef USB_CFG_PULLUP_IOPORTNAME
|
||||||
|
#undef usbDeviceConnect
|
||||||
|
#define usbDeviceConnect() do { \
|
||||||
|
USB_PULLUP_DDR |= (1<<USB_CFG_PULLUP_BIT); \
|
||||||
|
USB_PULLUP_OUT |= (1<<USB_CFG_PULLUP_BIT); \
|
||||||
|
USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT); \
|
||||||
|
} while(0);
|
||||||
|
#undef usbDeviceDisconnect
|
||||||
|
#define usbDeviceDisconnect() do { \
|
||||||
|
USB_INTR_ENABLE &= ~(1 << USB_INTR_ENABLE_BIT); \
|
||||||
|
USB_PULLUP_DDR &= ~(1<<USB_CFG_PULLUP_BIT); \
|
||||||
|
USB_PULLUP_OUT &= ~(1<<USB_CFG_PULLUP_BIT); \
|
||||||
|
} while(0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prototypes
|
||||||
|
*/
|
||||||
|
void __attribute__ ((__noreturn__, __noinline__,
|
||||||
|
__naked__)) leave_bootloader(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* we just support flash sizes <= 64kb, for code size reasons if you need to program bigger devices, have a look at USBasploader:
|
||||||
|
* http://www.obdev.at/products/avrusb/usbasploader.html
|
||||||
|
*/
|
||||||
|
#if FLASHEND > 0xffff
|
||||||
|
# error "usbload only supports up to 64kb of flash!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* we are just checking the lower byte of flash_address, so make sure SPM_PAGESIZE is <= 256
|
||||||
|
*/
|
||||||
|
#if SPM_PAGESIZE > 256
|
||||||
|
# error "SPM_PAGESIZE is too big (just checking lower byte)"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* start flash (byte address) read/write at this address
|
||||||
|
*/
|
||||||
|
usbWord_t flash_address;
|
||||||
|
uint8_t bytes_remaining;
|
||||||
|
uint8_t request;
|
||||||
|
uint8_t request_exit;
|
||||||
|
|
||||||
|
uint8_t timeout;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||||
|
{
|
||||||
|
usbRequest_t *req = (void *) data;
|
||||||
|
uint8_t len = 0;
|
||||||
|
static uint8_t buf[4];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* set global data pointer to local buffer
|
||||||
|
*/
|
||||||
|
usbMsgPtr = buf;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* on enableprog just return one zero, which means success
|
||||||
|
*/
|
||||||
|
if (req->bRequest == USBASP_FUNC_ENABLEPROG) {
|
||||||
|
buf[0] = 0;
|
||||||
|
len = 1;
|
||||||
|
timeout = 255;
|
||||||
|
} else if (req->bRequest == USBASP_FUNC_CONNECT) {
|
||||||
|
/*
|
||||||
|
* turn on led
|
||||||
|
*/
|
||||||
|
DLED_ON;
|
||||||
|
} else if (req->bRequest == USBASP_FUNC_DISCONNECT) {
|
||||||
|
/*
|
||||||
|
* turn off led
|
||||||
|
*/
|
||||||
|
DLED_OFF;
|
||||||
|
request_exit = 1;
|
||||||
|
/*
|
||||||
|
* catch query for the devicecode, chip erase and eeprom byte requests
|
||||||
|
*/
|
||||||
|
} else if (req->bRequest == USBASP_FUNC_TRANSMIT) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* reset buffer with zeroes
|
||||||
|
*/
|
||||||
|
memset(buf, '\0', sizeof(buf));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* read the address for eeprom operations
|
||||||
|
*/
|
||||||
|
usbWord_t address;
|
||||||
|
address.bytes[0] = data[4]; /* low byte is data[4] */
|
||||||
|
address.bytes[1] = data[3]; /* high byte is data[3] */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if this is a request to read the device signature, answer with the appropiate signature byte
|
||||||
|
*/
|
||||||
|
if (data[2] == ISP_READ_SIGNATURE) {
|
||||||
|
/*
|
||||||
|
* the complete isp data is reported back to avrdude, but we just need byte 4 bits 0 and 1 of byte 3 determine the signature
|
||||||
|
* byte address
|
||||||
|
*/
|
||||||
|
buf[3] = signature[data[4] & 0x03];
|
||||||
|
|
||||||
|
#ifdef ENABLE_CATCH_EEPROM_ISP
|
||||||
|
/*
|
||||||
|
* catch eeprom read
|
||||||
|
*/
|
||||||
|
} else if (data[2] == ISP_READ_EEPROM) {
|
||||||
|
|
||||||
|
buf[3] = eeprom_read_byte((uint8_t *) address.word);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* catch eeprom write
|
||||||
|
*/
|
||||||
|
} else if (data[2] == ISP_WRITE_EEPROM) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* address is in data[4], data[3], and databyte is in data[5]
|
||||||
|
*/
|
||||||
|
eeprom_write_byte((uint8_t *) address.word, data[5]);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* catch a chip erase
|
||||||
|
*/
|
||||||
|
} else if (data[2] == ISP_CHIP_ERASE1 && data[3] == ISP_CHIP_ERASE2) {
|
||||||
|
uart_puts("\n\rErase Flash");
|
||||||
|
for (flash_address.word = 0;
|
||||||
|
flash_address.word < ERASE_SECTION;
|
||||||
|
flash_address.word += SPM_PAGESIZE) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* wait and erase page
|
||||||
|
*/
|
||||||
|
boot_spm_busy_wait();
|
||||||
|
if (flash_address.word && flash_address.word % 1024 == 0)
|
||||||
|
uart_putc('.');
|
||||||
|
cli();
|
||||||
|
boot_page_erase(flash_address.word);
|
||||||
|
sei();
|
||||||
|
}
|
||||||
|
uart_puts("\n\rWrite Flash");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* in case no data has been filled in by the if's above, just return zeroes
|
||||||
|
*/
|
||||||
|
len = 4;
|
||||||
|
|
||||||
|
#ifdef ENABLE_ECHO_FUNC
|
||||||
|
/*
|
||||||
|
* implement a simple echo function, for testing the usb connectivity
|
||||||
|
*/
|
||||||
|
} else if (req->bRequest == FUNC_ECHO) {
|
||||||
|
buf[0] = req->wValue.bytes[0];
|
||||||
|
buf[1] = req->wValue.bytes[1];
|
||||||
|
len = 2;
|
||||||
|
#endif
|
||||||
|
} else if (req->bRequest >= USBASP_FUNC_READFLASH) {
|
||||||
|
/*
|
||||||
|
* && req->bRequest <= USBASP_FUNC_SETLONGADDRESS
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* extract address and length
|
||||||
|
*/
|
||||||
|
flash_address.word = req->wValue.word;
|
||||||
|
bytes_remaining = req->wLength.bytes[0];
|
||||||
|
request = req->bRequest;
|
||||||
|
/*
|
||||||
|
* hand control over to usbFunctionRead()/usbFunctionWrite()
|
||||||
|
*/
|
||||||
|
len = 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
uchar usbFunctionWrite(uchar * data, uchar len)
|
||||||
|
{
|
||||||
|
if (len > bytes_remaining)
|
||||||
|
len = bytes_remaining;
|
||||||
|
bytes_remaining -= len;
|
||||||
|
if (request == USBASP_FUNC_WRITEEEPROM) {
|
||||||
|
for (uint8_t i = 0; i < len; i++)
|
||||||
|
eeprom_write_byte((uint8_t *) flash_address.word++, *data++);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* data is handled wordwise, adjust len
|
||||||
|
*/
|
||||||
|
len /= 2;
|
||||||
|
len -= 1;
|
||||||
|
for (uint8_t i = 0; i <= len; i++) {
|
||||||
|
uint16_t *w = (uint16_t *) data;
|
||||||
|
cli();
|
||||||
|
boot_page_fill(flash_address.word, *w);
|
||||||
|
sei();
|
||||||
|
|
||||||
|
usbWord_t next_address;
|
||||||
|
next_address.word = flash_address.word;
|
||||||
|
next_address.word += 2;
|
||||||
|
data += 2;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* write page if page boundary is crossed or this is the last page
|
||||||
|
*/
|
||||||
|
if (next_address.bytes[0] % SPM_PAGESIZE == 0 ||
|
||||||
|
(bytes_remaining == 0 && i == len)) {
|
||||||
|
cli();
|
||||||
|
boot_page_write(flash_address.word);
|
||||||
|
sei();
|
||||||
|
boot_spm_busy_wait();
|
||||||
|
cli();
|
||||||
|
boot_rww_enable();
|
||||||
|
sei();
|
||||||
|
}
|
||||||
|
|
||||||
|
flash_address.word = next_address.word;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* flash led on activity
|
||||||
|
*/
|
||||||
|
DLED_TGL;
|
||||||
|
|
||||||
|
return (bytes_remaining == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
uchar usbFunctionRead(uchar * data, uchar len)
|
||||||
|
{
|
||||||
|
if (len > bytes_remaining)
|
||||||
|
len = bytes_remaining;
|
||||||
|
bytes_remaining -= len;
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < len; i++) {
|
||||||
|
if (request == USBASP_FUNC_READEEPROM)
|
||||||
|
*data = eeprom_read_byte((void *) flash_address.word);
|
||||||
|
else
|
||||||
|
*data = pgm_read_byte_near((void *) flash_address.word);
|
||||||
|
data++;
|
||||||
|
flash_address.word++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* flash led on activity
|
||||||
|
*/
|
||||||
|
DLED_TGL;
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
void (*jump_to_app) (void) = 0x0000;
|
||||||
|
void leave_bootloader(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
cli();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* disconnect usb
|
||||||
|
*/
|
||||||
|
usbDeviceDisconnect();
|
||||||
|
#if 0
|
||||||
|
for (uint8_t i = 0; i < 50; i++)
|
||||||
|
_delay_ms(10); /* 0 means 0x10000, 38*1/f*0x10000 =~ 498ms */
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
* enable watchdog to soft-reset the uC for clean startup of new application
|
||||||
|
*/
|
||||||
|
wdt_enable(WDTO_15MS);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* let watchdog kick in and reset uC
|
||||||
|
*/
|
||||||
|
while (1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void banner(){
|
||||||
|
uart_puts("\n\r");
|
||||||
|
uart_puts("\n\r");
|
||||||
|
uart_puts("\n\r");
|
||||||
|
uart_puts("Quickdev16 Bootloader v0.2\n\r");
|
||||||
|
uart_puts("www.optixx.org\n\r");
|
||||||
|
}
|
||||||
|
|
||||||
|
int __attribute__ ((noreturn, OS_main)) main(void)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* start bootloader
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef DEBUG_UART
|
||||||
|
/*
|
||||||
|
* init uart (115200 baud, at 20mhz)
|
||||||
|
*/
|
||||||
|
UBRR0L = 10;
|
||||||
|
UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
|
||||||
|
UCSR0B = _BV(TXEN0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uint8_t reset = MCUSR;
|
||||||
|
uint16_t delay = 0;
|
||||||
|
timeout = TIMEOUT;
|
||||||
|
|
||||||
|
DDRC &= ~(1 << AVR_BTLDR_EN_PIN);
|
||||||
|
PORTC &= ~(1 << AVR_BTLDR_EN_PIN);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if watchdog reset, disable watchdog and jump to app
|
||||||
|
*/
|
||||||
|
if (reset & _BV(WDRF)) {
|
||||||
|
uart_puts("Found watchdog reset\n\r");
|
||||||
|
MCUSR = 0;
|
||||||
|
wdt_disable();
|
||||||
|
uart_puts("Jump to 0x0000\n\r");
|
||||||
|
jump_to_app();
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef AVR_BTLDR_SWITCH ENABLE
|
||||||
|
if ((AVR_BTLDR_EN_IN & ( 1 << AVR_BTLDR_EN_PIN)) == 0){
|
||||||
|
banner();
|
||||||
|
uart_puts("Bootloader flashing is disabled\n\r");
|
||||||
|
MCUSR = 0;
|
||||||
|
leave_bootloader();
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if power-on reset, quit bootloader via watchdog reset
|
||||||
|
*/
|
||||||
|
if (reset & _BV(PORF)) {
|
||||||
|
banner();
|
||||||
|
uart_puts("Found power on reset\n\r");
|
||||||
|
MCUSR = 0;
|
||||||
|
leave_bootloader();
|
||||||
|
}
|
||||||
|
banner();
|
||||||
|
uart_puts("Enter programming mode\n\r");
|
||||||
|
/*
|
||||||
|
* else: enter programming mode
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* clear external reset flags
|
||||||
|
*/
|
||||||
|
MCUSR = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* init exit request state
|
||||||
|
*/
|
||||||
|
request_exit = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* move interrupts to boot section
|
||||||
|
*/
|
||||||
|
|
||||||
|
MCUCR = (1 << IVCE);
|
||||||
|
MCUCR = (1 << IVSEL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* enable interrupts
|
||||||
|
*/
|
||||||
|
sei();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* initialize usb pins
|
||||||
|
*/
|
||||||
|
usbInit();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* disconnect for ~500ms, so that the host re-enumerates this device
|
||||||
|
*/
|
||||||
|
usbDeviceDisconnect();
|
||||||
|
for (uint8_t i = 0; i < 50; i++)
|
||||||
|
_delay_ms(10); /* 0 means 0x10000, 38*1/f*0x10000 =~ 498ms */
|
||||||
|
usbDeviceConnect();
|
||||||
|
uart_puts("Wait for firmware");
|
||||||
|
while (1) {
|
||||||
|
usbPoll();
|
||||||
|
|
||||||
|
delay++;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* do some led blinking, so that it is visible that the bootloader is still running
|
||||||
|
*/
|
||||||
|
if (delay == 0) {
|
||||||
|
uart_putc('.');
|
||||||
|
DLED_TGL;
|
||||||
|
if (timeout < 255)
|
||||||
|
timeout--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request_exit || timeout == 0) {
|
||||||
|
uart_puts("\n\rExit\n\r");
|
||||||
|
_delay_ms(10);
|
||||||
|
leave_bootloader();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
22
avr/bootloader/config.h
Normal file
22
avr/bootloader/config.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
/* configuratino file for usbload */
|
||||||
|
|
||||||
|
/* after this timeout, the main application ist started, if no usb
|
||||||
|
* connection is detected */
|
||||||
|
#define TIMEOUT 50
|
||||||
|
|
||||||
|
/* uncomment this if you need to define some other signature bytes */
|
||||||
|
//#define SIGNATURE_BYTES 0x23, 0x24, 0x25, 0
|
||||||
|
|
||||||
|
/* uncomment this if you want to catch the eeprom isp bytewise read/write
|
||||||
|
* commands. costs ~34 byte */
|
||||||
|
//#define ENABLE_CATCH_EEPROM_ISP
|
||||||
|
|
||||||
|
/* uncomment this if you want a usb echo function (for communication testing) */
|
||||||
|
//#define ENABLE_ECHO_FUNC
|
||||||
|
|
||||||
|
/* uncomment this for debug information via uart */
|
||||||
|
#define DEBUG_UART
|
||||||
|
|
||||||
|
|
||||||
|
#define DEBUG 1
|
||||||
|
#define DEBUG_USB 2
|
||||||
21
avr/bootloader/fuses.txt
Normal file
21
avr/bootloader/fuses.txt
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
additional fuse bit settings for using this bootloader:
|
||||||
|
=======================================================
|
||||||
|
|
||||||
|
atmega88/168:
|
||||||
|
|
||||||
|
extended fuse byte:
|
||||||
|
1024 words bootloader size: BOOTSZ0 = 0
|
||||||
|
BOOTSZ1 = 0
|
||||||
|
|
||||||
|
reset vector, jump to bootloader on reset: BOOTRST = 0
|
||||||
|
|
||||||
|
-> default: 0b001 = 0x01
|
||||||
|
new: 0b000 = 0x00
|
||||||
|
|
||||||
|
lock byte:
|
||||||
|
SPM is not allowed to write to the Boot Loader section BLB12 = 1
|
||||||
|
BLB11 = 0
|
||||||
|
|
||||||
|
-> default: 0b111111 = 0x3f
|
||||||
|
new: 0b101111 = 0x2f
|
||||||
|
|
||||||
9
avr/bootloader/interrupts.S
Normal file
9
avr/bootloader/interrupts.S
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
.extern __init, __vector_1
|
||||||
|
.global __vector_default, exit
|
||||||
|
.section .vectors.bootloader
|
||||||
|
|
||||||
|
/* micro-jumptable, we are using just reset and int0 vectors */
|
||||||
|
exit:
|
||||||
|
__vector_default:
|
||||||
|
jmp __init
|
||||||
|
jmp __vector_1
|
||||||
174
avr/bootloader/ldscripts/avr5.x
Normal file
174
avr/bootloader/ldscripts/avr5.x
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
/* Default linker script, for normal executables */
|
||||||
|
OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")
|
||||||
|
OUTPUT_ARCH(avr:5)
|
||||||
|
MEMORY
|
||||||
|
{
|
||||||
|
text (rx) : ORIGIN = 0, LENGTH = 128K
|
||||||
|
data (rw!x) : ORIGIN = 0x800060, LENGTH = 0xffa0
|
||||||
|
eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K
|
||||||
|
}
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
/* Read-only sections, merged into text segment: */
|
||||||
|
.hash : { *(.hash) }
|
||||||
|
.dynsym : { *(.dynsym) }
|
||||||
|
.dynstr : { *(.dynstr) }
|
||||||
|
.gnu.version : { *(.gnu.version) }
|
||||||
|
.gnu.version_d : { *(.gnu.version_d) }
|
||||||
|
.gnu.version_r : { *(.gnu.version_r) }
|
||||||
|
.rel.init : { *(.rel.init) }
|
||||||
|
.rela.init : { *(.rela.init) }
|
||||||
|
.rel.text :
|
||||||
|
{
|
||||||
|
*(.rel.text)
|
||||||
|
*(.rel.text.*)
|
||||||
|
*(.rel.gnu.linkonce.t*)
|
||||||
|
}
|
||||||
|
.rela.text :
|
||||||
|
{
|
||||||
|
*(.rela.text)
|
||||||
|
*(.rela.text.*)
|
||||||
|
*(.rela.gnu.linkonce.t*)
|
||||||
|
}
|
||||||
|
.rel.fini : { *(.rel.fini) }
|
||||||
|
.rela.fini : { *(.rela.fini) }
|
||||||
|
.rel.rodata :
|
||||||
|
{
|
||||||
|
*(.rel.rodata)
|
||||||
|
*(.rel.rodata.*)
|
||||||
|
*(.rel.gnu.linkonce.r*)
|
||||||
|
}
|
||||||
|
.rela.rodata :
|
||||||
|
{
|
||||||
|
*(.rela.rodata)
|
||||||
|
*(.rela.rodata.*)
|
||||||
|
*(.rela.gnu.linkonce.r*)
|
||||||
|
}
|
||||||
|
.rel.data :
|
||||||
|
{
|
||||||
|
*(.rel.data)
|
||||||
|
*(.rel.data.*)
|
||||||
|
*(.rel.gnu.linkonce.d*)
|
||||||
|
}
|
||||||
|
.rela.data :
|
||||||
|
{
|
||||||
|
*(.rela.data)
|
||||||
|
*(.rela.data.*)
|
||||||
|
*(.rela.gnu.linkonce.d*)
|
||||||
|
}
|
||||||
|
.rel.ctors : { *(.rel.ctors) }
|
||||||
|
.rela.ctors : { *(.rela.ctors) }
|
||||||
|
.rel.dtors : { *(.rel.dtors) }
|
||||||
|
.rela.dtors : { *(.rela.dtors) }
|
||||||
|
.rel.got : { *(.rel.got) }
|
||||||
|
.rela.got : { *(.rela.got) }
|
||||||
|
.rel.bss : { *(.rel.bss) }
|
||||||
|
.rela.bss : { *(.rela.bss) }
|
||||||
|
.rel.plt : { *(.rel.plt) }
|
||||||
|
.rela.plt : { *(.rela.plt) }
|
||||||
|
|
||||||
|
/DISCARD/ : { *(.vectors) }
|
||||||
|
/DISCARD/ : { *(.fini9)
|
||||||
|
*(.fini6)
|
||||||
|
*(.fini0)
|
||||||
|
}
|
||||||
|
/* Internal text space or external memory */
|
||||||
|
.text :
|
||||||
|
{
|
||||||
|
*(.vectors.bootloader)
|
||||||
|
__ctors_start = . ;
|
||||||
|
*(.ctors)
|
||||||
|
__ctors_end = . ;
|
||||||
|
__dtors_start = . ;
|
||||||
|
*(.dtors)
|
||||||
|
__dtors_end = . ;
|
||||||
|
*(.progmem.gcc*)
|
||||||
|
*(.progmem*)
|
||||||
|
. = ALIGN(2);
|
||||||
|
*(.init0) /* Start here after reset. */
|
||||||
|
*(.init1)
|
||||||
|
*(.init2) /* Clear __zero_reg__, set up stack pointer. */
|
||||||
|
*(.init3)
|
||||||
|
*(.init4) /* Initialize data and BSS. */
|
||||||
|
*(.init5)
|
||||||
|
*(.init6) /* C++ constructors. */
|
||||||
|
*(.init7)
|
||||||
|
*(.init8)
|
||||||
|
*(.init9) /* Call main(). */
|
||||||
|
*(.text)
|
||||||
|
. = ALIGN(2);
|
||||||
|
*(.text.*)
|
||||||
|
. = ALIGN(2);
|
||||||
|
*(.fini9) /* _exit() starts here. */
|
||||||
|
*(.fini8)
|
||||||
|
*(.fini7)
|
||||||
|
*(.fini6) /* C++ destructors. */
|
||||||
|
*(.fini5)
|
||||||
|
*(.fini4)
|
||||||
|
*(.fini3)
|
||||||
|
*(.fini2)
|
||||||
|
*(.fini1)
|
||||||
|
*(.fini0) /* Infinite loop after program termination. */
|
||||||
|
_etext = . ;
|
||||||
|
} > text
|
||||||
|
.data : AT (ADDR (.text) + SIZEOF (.text))
|
||||||
|
{
|
||||||
|
PROVIDE (__data_start = .) ;
|
||||||
|
*(.data)
|
||||||
|
*(.gnu.linkonce.d*)
|
||||||
|
. = ALIGN(2);
|
||||||
|
_edata = . ;
|
||||||
|
PROVIDE (__data_end = .) ;
|
||||||
|
} > data
|
||||||
|
.bss SIZEOF(.data) + ADDR(.data) :
|
||||||
|
{
|
||||||
|
PROVIDE (__bss_start = .) ;
|
||||||
|
*(.bss)
|
||||||
|
*(COMMON)
|
||||||
|
PROVIDE (__bss_end = .) ;
|
||||||
|
} > data
|
||||||
|
__data_load_start = LOADADDR(.data);
|
||||||
|
__data_load_end = __data_load_start + SIZEOF(.data);
|
||||||
|
/* Global data not cleared after reset. */
|
||||||
|
.noinit SIZEOF(.bss) + ADDR(.bss) :
|
||||||
|
{
|
||||||
|
PROVIDE (__noinit_start = .) ;
|
||||||
|
*(.noinit*)
|
||||||
|
PROVIDE (__noinit_end = .) ;
|
||||||
|
_end = . ;
|
||||||
|
PROVIDE (__heap_start = .) ;
|
||||||
|
} > data
|
||||||
|
.eeprom :
|
||||||
|
{
|
||||||
|
*(.eeprom*)
|
||||||
|
__eeprom_end = . ;
|
||||||
|
} > eeprom
|
||||||
|
/* Stabs debugging sections. */
|
||||||
|
.stab 0 : { *(.stab) }
|
||||||
|
.stabstr 0 : { *(.stabstr) }
|
||||||
|
.stab.excl 0 : { *(.stab.excl) }
|
||||||
|
.stab.exclstr 0 : { *(.stab.exclstr) }
|
||||||
|
.stab.index 0 : { *(.stab.index) }
|
||||||
|
.stab.indexstr 0 : { *(.stab.indexstr) }
|
||||||
|
.comment 0 : { *(.comment) }
|
||||||
|
/* DWARF debug sections.
|
||||||
|
Symbols in the DWARF debugging sections are relative to the beginning
|
||||||
|
of the section so we begin them at 0. */
|
||||||
|
/* DWARF 1 */
|
||||||
|
.debug 0 : { *(.debug) }
|
||||||
|
.line 0 : { *(.line) }
|
||||||
|
/* GNU DWARF 1 extensions */
|
||||||
|
.debug_srcinfo 0 : { *(.debug_srcinfo) }
|
||||||
|
.debug_sfnames 0 : { *(.debug_sfnames) }
|
||||||
|
/* DWARF 1.1 and DWARF 2 */
|
||||||
|
.debug_aranges 0 : { *(.debug_aranges) }
|
||||||
|
.debug_pubnames 0 : { *(.debug_pubnames) }
|
||||||
|
/* DWARF 2 */
|
||||||
|
.debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
|
||||||
|
.debug_abbrev 0 : { *(.debug_abbrev) }
|
||||||
|
.debug_line 0 : { *(.debug_line) }
|
||||||
|
.debug_frame 0 : { *(.debug_frame) }
|
||||||
|
.debug_str 0 : { *(.debug_str) }
|
||||||
|
.debug_loc 0 : { *(.debug_loc) }
|
||||||
|
.debug_macinfo 0 : { *(.debug_macinfo) }
|
||||||
|
}
|
||||||
@@ -1,26 +1,18 @@
|
|||||||
/* Name: usbconfig.h
|
|
||||||
* Project: AVR USB driver
|
|
||||||
* Author: Christian Starkjohann
|
|
||||||
* Creation Date: 2005-04-01
|
|
||||||
* Tabsize: 4
|
|
||||||
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
|
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
|
||||||
* This Revision: $Id: usbconfig-prototype.h 734 2009-03-23 11:10:07Z cs $
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __usbconfig_h_included__
|
#ifndef __usbconfig_h_included__
|
||||||
#define __usbconfig_h_included__
|
#define __usbconfig_h_included__
|
||||||
|
|
||||||
/*
|
/*
|
||||||
General Description:
|
General Description:
|
||||||
This file is an example configuration (with inline documentation) for the USB
|
This file contains parts of the USB driver which can be configured and can or
|
||||||
driver. It configures AVR-USB for USB D+ connected to Port D bit 2 (which is
|
must be adapted to your hardware.
|
||||||
also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may
|
|
||||||
wire the lines to any other port, as long as D+ is also wired to INT0 (or any
|
Please note that the usbdrv contains a usbconfig-prototype.h file now. We
|
||||||
other hardware interrupt, as long as it is the highest level interrupt, see
|
recommend that you use that file as a template because it will always list
|
||||||
section at the end of this file).
|
the newest features and options.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
/* ---------------------------- Hardware Config ---------------------------- */
|
/* ---------------------------- Hardware Config ---------------------------- */
|
||||||
|
|
||||||
#define USB_CFG_IOPORTNAME D
|
#define USB_CFG_IOPORTNAME D
|
||||||
@@ -41,28 +33,22 @@ section at the end of this file).
|
|||||||
* markers every millisecond.]
|
* markers every millisecond.]
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_CLOCK_KHZ (F_CPU/1000)
|
#define USB_CFG_CLOCK_KHZ (F_CPU/1000)
|
||||||
/* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000,
|
/* Clock rate of the AVR in MHz. Legal values are 12000, 15000, 16000, 16500
|
||||||
* 16500 and 20000. The 12.8 MHz and 16.5 MHz versions of the code require no
|
* and 20000. The 16.5 MHz version of the code requires no crystal, it
|
||||||
* crystal, they tolerate +/- 1% deviation from the nominal frequency. All
|
* tolerates +/- 1% deviation from the nominal frequency. All other rates
|
||||||
* other rates require a precision of 2000 ppm and thus a crystal!
|
* require a precision of 2000 ppm and thus a crystal!
|
||||||
* Default if not specified: 12 MHz
|
* Default if not specified: 12 MHz
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_CHECK_CRC 0
|
|
||||||
/* Define this to 1 if you want that the driver checks integrity of incoming
|
|
||||||
* data packets (CRC checks). CRC checks cost quite a bit of code size and are
|
|
||||||
* currently only available for 18 MHz crystal clock. You must choose
|
|
||||||
* USB_CFG_CLOCK_KHZ = 18000 if you enable this option.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* ----------------------- Optional Hardware Config ------------------------ */
|
/* ----------------------- Optional Hardware Config ------------------------ */
|
||||||
|
|
||||||
/* #define USB_CFG_PULLUP_IOPORTNAME D */
|
//#define USB_CFG_PULLUP_IOPORTNAME B
|
||||||
/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
|
/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
|
||||||
* V+, you can connect and disconnect the device from firmware by calling
|
* V+, you can connect and disconnect the device from firmware by calling
|
||||||
* the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
|
* the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
|
||||||
* This constant defines the port on which the pullup resistor is connected.
|
* This constant defines the port on which the pullup resistor is connected.
|
||||||
*/
|
*/
|
||||||
/* #define USB_CFG_PULLUP_BIT 4 */
|
//#define USB_CFG_PULLUP_BIT 0
|
||||||
/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
|
/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
|
||||||
* above) where the 1.5k pullup resistor is connected. See description
|
* above) where the 1.5k pullup resistor is connected. See description
|
||||||
* above for details.
|
* above for details.
|
||||||
@@ -70,7 +56,7 @@ section at the end of this file).
|
|||||||
|
|
||||||
/* --------------------------- Functional Range ---------------------------- */
|
/* --------------------------- Functional Range ---------------------------- */
|
||||||
|
|
||||||
#define USB_CFG_HAVE_INTRIN_ENDPOINT 1
|
#define USB_CFG_HAVE_INTRIN_ENDPOINT 0
|
||||||
/* Define this to 1 if you want to compile a version with two endpoints: The
|
/* Define this to 1 if you want to compile a version with two endpoints: The
|
||||||
* default control endpoint 0 and an interrupt-in endpoint (any other endpoint
|
* default control endpoint 0 and an interrupt-in endpoint (any other endpoint
|
||||||
* number).
|
* number).
|
||||||
@@ -97,15 +83,7 @@ section at the end of this file).
|
|||||||
* it is required by the standard. We have made it a config option because it
|
* it is required by the standard. We have made it a config option because it
|
||||||
* bloats the code considerably.
|
* bloats the code considerably.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_SUPPRESS_INTR_CODE 0
|
#define USB_CFG_INTR_POLL_INTERVAL 200
|
||||||
/* Define this to 1 if you want to declare interrupt-in endpoints, but don't
|
|
||||||
* want to send any data over them. If this macro is defined to 1, functions
|
|
||||||
* usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if
|
|
||||||
* you need the interrupt-in endpoints in order to comply to an interface
|
|
||||||
* (e.g. HID), but never want to send any data. This option saves a couple
|
|
||||||
* of bytes in flash memory and the transmit buffers in RAM.
|
|
||||||
*/
|
|
||||||
#define USB_CFG_INTR_POLL_INTERVAL 100
|
|
||||||
/* If you compile a version with endpoint 1 (interrupt-in), this is the poll
|
/* If you compile a version with endpoint 1 (interrupt-in), this is the poll
|
||||||
* interval. The value is in milliseconds and must not be less than 10 ms for
|
* interval. The value is in milliseconds and must not be less than 10 ms for
|
||||||
* low speed devices.
|
* low speed devices.
|
||||||
@@ -114,7 +92,7 @@ section at the end of this file).
|
|||||||
/* Define this to 1 if the device has its own power supply. Set it to 0 if the
|
/* Define this to 1 if the device has its own power supply. Set it to 0 if the
|
||||||
* device is powered from the USB bus.
|
* device is powered from the USB bus.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_MAX_BUS_POWER 20
|
#define USB_CFG_MAX_BUS_POWER 100
|
||||||
/* Set this variable to the maximum USB bus power consumption of your device.
|
/* Set this variable to the maximum USB bus power consumption of your device.
|
||||||
* The value is in milliamperes. [It will be divided by two since USB
|
* The value is in milliamperes. [It will be divided by two since USB
|
||||||
* communicates power requirements in units of 2 mA.]
|
* communicates power requirements in units of 2 mA.]
|
||||||
@@ -167,33 +145,6 @@ section at the end of this file).
|
|||||||
* counts SOF packets. This feature requires that the hardware interrupt is
|
* counts SOF packets. This feature requires that the hardware interrupt is
|
||||||
* connected to D- instead of D+.
|
* connected to D- instead of D+.
|
||||||
*/
|
*/
|
||||||
/* #ifdef __ASSEMBLER__
|
|
||||||
* macro myAssemblerMacro
|
|
||||||
* in YL, TCNT0
|
|
||||||
* sts timer0Snapshot, YL
|
|
||||||
* endm
|
|
||||||
* #endif
|
|
||||||
* #define USB_SOF_HOOK myAssemblerMacro
|
|
||||||
* This macro (if defined) is executed in the assembler module when a
|
|
||||||
* Start Of Frame condition is detected. It is recommended to define it to
|
|
||||||
* the name of an assembler macro which is defined here as well so that more
|
|
||||||
* than one assembler instruction can be used. The macro may use the register
|
|
||||||
* YL and modify SREG. If it lasts longer than a couple of cycles, USB messages
|
|
||||||
* immediately after an SOF pulse may be lost and must be retried by the host.
|
|
||||||
* What can you do with this hook? Since the SOF signal occurs exactly every
|
|
||||||
* 1 ms (unless the host is in sleep mode), you can use it to tune OSCCAL in
|
|
||||||
* designs running on the internal RC oscillator.
|
|
||||||
* Please note that Start Of Frame detection works only if D- is wired to the
|
|
||||||
* interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES!
|
|
||||||
*/
|
|
||||||
#define USB_CFG_CHECK_DATA_TOGGLING 0
|
|
||||||
/* define this macro to 1 if you want to filter out duplicate data packets
|
|
||||||
* sent by the host. Duplicates occur only as a consequence of communication
|
|
||||||
* errors, when the host does not receive an ACK. Please note that you need to
|
|
||||||
* implement the filtering yourself in usbFunctionWriteOut() and
|
|
||||||
* usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable
|
|
||||||
* for each control- and out-endpoint to check for duplicate packets.
|
|
||||||
*/
|
|
||||||
#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0
|
#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0
|
||||||
/* define this macro to 1 if you want the function usbMeasureFrameLength()
|
/* define this macro to 1 if you want the function usbMeasureFrameLength()
|
||||||
* compiled in. This function can be used to calibrate the AVR's RC oscillator.
|
* compiled in. This function can be used to calibrate the AVR's RC oscillator.
|
||||||
@@ -201,12 +152,12 @@ section at the end of this file).
|
|||||||
|
|
||||||
/* -------------------------- Device Description --------------------------- */
|
/* -------------------------- Device Description --------------------------- */
|
||||||
|
|
||||||
#define USB_CFG_VENDOR_ID 0xc0, 0x16
|
#define USB_CFG_VENDOR_ID 0xc0, 0x16 /* 5824 in dec, stands for VOTI */
|
||||||
/* USB vendor ID for the device, low byte first. If you have registered your
|
/* USB vendor ID for the device, low byte first. If you have registered your
|
||||||
* own Vendor ID, define it here. Otherwise you use one of obdev's free shared
|
* own Vendor ID, define it here. Otherwise you use obdev's free shared
|
||||||
* VID/PID pairs. Be sure to read USBID-License.txt for rules!
|
* VID/PID pair. Be sure to read USBID-License.txt for rules!
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_DEVICE_ID 0xdf, 0x05 /* obdev's shared PID for HIDs */
|
#define USB_CFG_DEVICE_ID 0xdc, 0x05 /* 1500 in dec, obdev's free PID */
|
||||||
/* This is the ID of the product, low byte first. It is interpreted in the
|
/* This is the ID of the product, low byte first. It is interpreted in the
|
||||||
* scope of the vendor ID. If you have registered your own VID with usb.org
|
* scope of the vendor ID. If you have registered your own VID with usb.org
|
||||||
* or if you have licensed a PID from somebody else, define it here. Otherwise
|
* or if you have licensed a PID from somebody else, define it here. Otherwise
|
||||||
@@ -216,8 +167,8 @@ section at the end of this file).
|
|||||||
#define USB_CFG_DEVICE_VERSION 0x00, 0x01
|
#define USB_CFG_DEVICE_VERSION 0x00, 0x01
|
||||||
/* Version number of the device: Minor number first, then major number.
|
/* Version number of the device: Minor number first, then major number.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_VENDOR_NAME 'o', 'b', 'd', 'e', 'v', '.', 'a', 't'
|
#define USB_CFG_VENDOR_NAME 'w', 'w', 'w', '.', 'f', 'i', 's', 'c', 'h', 'l', '.', 'd', 'e'
|
||||||
#define USB_CFG_VENDOR_NAME_LEN 8
|
#define USB_CFG_VENDOR_NAME_LEN 13
|
||||||
/* These two values define the vendor name returned by the USB device. The name
|
/* These two values define the vendor name returned by the USB device. The name
|
||||||
* must be given as a list of characters under single quotes. The characters
|
* must be given as a list of characters under single quotes. The characters
|
||||||
* are interpreted as Unicode (UTF-16) entities.
|
* are interpreted as Unicode (UTF-16) entities.
|
||||||
@@ -226,11 +177,10 @@ section at the end of this file).
|
|||||||
* obdev's free shared VID/PID pair. See the file USBID-License.txt for
|
* obdev's free shared VID/PID pair. See the file USBID-License.txt for
|
||||||
* details.
|
* details.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_DEVICE_NAME 'D', 'a', 't', 'a', 'S', 't', 'o', 'r', 'e'
|
#define USB_CFG_DEVICE_NAME 'U', 'S', 'B', 'a', 's', 'p'
|
||||||
#define USB_CFG_DEVICE_NAME_LEN 9
|
#define USB_CFG_DEVICE_NAME_LEN 6
|
||||||
/* Same as above for the device name. If you don't want a device name, undefine
|
/* Same as above for the device name. If you don't want a device name, undefine
|
||||||
* the macros. See the file USBID-License.txt before you assign a name if you
|
* the macros. See the file USBID-License.txt before you assign a name.
|
||||||
* use a shared VID/PID.
|
|
||||||
*/
|
*/
|
||||||
/*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */
|
/*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */
|
||||||
/*#define USB_CFG_SERIAL_NUMBER_LEN 0 */
|
/*#define USB_CFG_SERIAL_NUMBER_LEN 0 */
|
||||||
@@ -241,12 +191,12 @@ section at the end of this file).
|
|||||||
* to fine tune control over USB descriptors such as the string descriptor
|
* to fine tune control over USB descriptors such as the string descriptor
|
||||||
* for the serial number.
|
* for the serial number.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_DEVICE_CLASS 0
|
#define USB_CFG_DEVICE_CLASS 0xff /* set to 0 if deferred to interface */
|
||||||
#define USB_CFG_DEVICE_SUBCLASS 0
|
#define USB_CFG_DEVICE_SUBCLASS 0
|
||||||
/* See USB specification if you want to conform to an existing device class.
|
/* See USB specification if you want to conform to an existing device class.
|
||||||
* Class 0xff is "vendor specific".
|
* Class 0xff is "vendor specific".
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_INTERFACE_CLASS 3
|
#define USB_CFG_INTERFACE_CLASS 0 /* define class here if not at device level */
|
||||||
#define USB_CFG_INTERFACE_SUBCLASS 0
|
#define USB_CFG_INTERFACE_SUBCLASS 0
|
||||||
#define USB_CFG_INTERFACE_PROTOCOL 0
|
#define USB_CFG_INTERFACE_PROTOCOL 0
|
||||||
/* See USB specification if you want to conform to an existing device class or
|
/* See USB specification if you want to conform to an existing device class or
|
||||||
@@ -254,7 +204,7 @@ section at the end of this file).
|
|||||||
* HID class is 3, no subclass and protocol required (but may be useful!)
|
* HID class is 3, no subclass and protocol required (but may be useful!)
|
||||||
* CDC class is 2, use subclass 2 and protocol 1 for ACM
|
* CDC class is 2, use subclass 2 and protocol 1 for ACM
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 22
|
/* #define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 42 */
|
||||||
/* Define this to the length of the HID report descriptor, if you implement
|
/* Define this to the length of the HID report descriptor, if you implement
|
||||||
* an HID device. Otherwise don't define it or define it to 0.
|
* an HID device. Otherwise don't define it or define it to 0.
|
||||||
* If you use this define, you must add a PROGMEM character array named
|
* If you use this define, you must add a PROGMEM character array named
|
||||||
@@ -262,7 +212,7 @@ section at the end of this file).
|
|||||||
* Don't forget to keep the array and this define in sync!
|
* Don't forget to keep the array and this define in sync!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* #define USB_PUBLIC static */
|
#define USB_PUBLIC static
|
||||||
/* Use the define above if you #include usbdrv.c instead of linking against it.
|
/* Use the define above if you #include usbdrv.c instead of linking against it.
|
||||||
* This technique saves a couple of bytes in flash memory.
|
* This technique saves a couple of bytes in flash memory.
|
||||||
*/
|
*/
|
||||||
@@ -277,9 +227,7 @@ section at the end of this file).
|
|||||||
* no properties are defined or if they are 0, the default descriptor is used.
|
* no properties are defined or if they are 0, the default descriptor is used.
|
||||||
* Possible properties are:
|
* Possible properties are:
|
||||||
* + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched
|
* + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched
|
||||||
* at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is
|
* at runtime via usbFunctionDescriptor().
|
||||||
* used, the data is in FLASH by default. Add property USB_PROP_IS_RAM if
|
|
||||||
* you want RAM pointers.
|
|
||||||
* + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found
|
* + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found
|
||||||
* in static memory is in RAM, not in flash memory.
|
* in static memory is in RAM, not in flash memory.
|
||||||
* + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash),
|
* + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash),
|
||||||
@@ -311,12 +259,6 @@ section at the end of this file).
|
|||||||
* USB_CFG_DESCR_PROPS_HID_REPORT
|
* USB_CFG_DESCR_PROPS_HID_REPORT
|
||||||
* USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver)
|
* USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver)
|
||||||
*
|
*
|
||||||
* Note about string descriptors: String descriptors are not just strings, they
|
|
||||||
* are Unicode strings prefixed with a 2 byte header. Example:
|
|
||||||
* int serialNumberDescriptor[] = {
|
|
||||||
* USB_STRING_DESCRIPTOR_HEADER(6),
|
|
||||||
* 'S', 'e', 'r', 'i', 'a', 'l'
|
|
||||||
* };
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define USB_CFG_DESCR_PROPS_DEVICE 0
|
#define USB_CFG_DESCR_PROPS_DEVICE 0
|
||||||
@@ -345,6 +287,5 @@ section at the end of this file).
|
|||||||
/* #define USB_INTR_ENABLE_BIT INT0 */
|
/* #define USB_INTR_ENABLE_BIT INT0 */
|
||||||
/* #define USB_INTR_PENDING GIFR */
|
/* #define USB_INTR_PENDING GIFR */
|
||||||
/* #define USB_INTR_PENDING_BIT INTF0 */
|
/* #define USB_INTR_PENDING_BIT INTF0 */
|
||||||
/* #define USB_INTR_VECTOR SIG_INTERRUPT0 */
|
|
||||||
|
|
||||||
#endif /* __usbconfig_h_included__ */
|
#endif /* __usbconfig_h_included__ */
|
||||||
@@ -231,40 +231,3 @@ Scroll down to the bottom to see the most recent changes.
|
|||||||
- Added 20 MHz module contributed by Jeroen Benschop.
|
- Added 20 MHz module contributed by Jeroen Benschop.
|
||||||
|
|
||||||
* Release 2008-05-13
|
* Release 2008-05-13
|
||||||
|
|
||||||
- Fixed bug in libs-host/hiddata.c function usbhidGetReport(): length
|
|
||||||
was not incremented, pointer to length was incremented instead.
|
|
||||||
- Added code to command line tool(s) which claims an interface. This code
|
|
||||||
is disabled by default, but may be necessary on newer Linux kernels.
|
|
||||||
- Added usbconfig.h option "USB_CFG_CHECK_DATA_TOGGLING".
|
|
||||||
- New header "usbportability.h" prepares ports to other development
|
|
||||||
environments.
|
|
||||||
- Long transfers (above 254 bytes) did not work when usbFunctionRead() was
|
|
||||||
used to supply the data. Fixed this bug. [Thanks to Alexander Neumann!]
|
|
||||||
- In hiddata.c (example code for sending/receiving data over HID), use
|
|
||||||
USB_RECIP_DEVICE instead of USB_RECIP_INTERFACE for control transfers so
|
|
||||||
that we need not claim the interface.
|
|
||||||
- in usbPoll() loop 20 times polling for RESET state instead of 10 times.
|
|
||||||
This accounts for the higher clock rates we now support.
|
|
||||||
- Added a module for 12.8 MHz RC oscillator with PLL in receiver loop.
|
|
||||||
- Added hook to SOF code so that oscillator can be tuned to USB frame clock.
|
|
||||||
- Added timeout to waitForJ loop. Helps preventing unexpected hangs.
|
|
||||||
- Added example code for oscillator tuning to libs-device (thanks to
|
|
||||||
Henrik Haftmann for the idea to this routine).
|
|
||||||
- Implemented option USB_CFG_SUPPRESS_INTR_CODE.
|
|
||||||
|
|
||||||
* Release 2008-10-22
|
|
||||||
|
|
||||||
- Fixed libs-device/osctune.h: OSCCAL is memory address on ATMega88 and
|
|
||||||
similar, not offset of 0x20 needs to be added.
|
|
||||||
- Allow distribution under GPLv3 for those who have to link against other
|
|
||||||
code distributed under GPLv3.
|
|
||||||
|
|
||||||
* Release 2008-11-26
|
|
||||||
|
|
||||||
- Removed libusb-win32 dependency for hid-data example in Makefile.windows.
|
|
||||||
It was never required and confused many people.
|
|
||||||
- Added extern uchar usbRxToken to usbdrv.h.
|
|
||||||
- Integrated a module with CRC checks at 18 MHz by Lukas Schrittwieser.
|
|
||||||
|
|
||||||
* Release 2009-03-23
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
AVR-USB Driver Software License Agreement
|
AVR-USB Driver Software License Agreement
|
||||||
Version 2008-10-07
|
Version 2008-04-15
|
||||||
|
|
||||||
THIS LICENSE AGREEMENT GRANTS YOU CERTAIN RIGHTS IN A SOFTWARE. YOU CAN
|
THIS LICENSE AGREEMENT GRANTS YOU CERTAIN RIGHTS IN A SOFTWARE. YOU CAN
|
||||||
ENTER INTO THIS AGREEMENT AND ACQUIRE THE RIGHTS OUTLINED BELOW BY PAYING
|
ENTER INTO THIS AGREEMENT AND ACQUIRE THE RIGHTS OUTLINED BELOW BY PAYING
|
||||||
@@ -26,11 +26,11 @@ and host side software examples and libraries.
|
|||||||
code of AVR-USB.
|
code of AVR-USB.
|
||||||
|
|
||||||
2.2 Distribution and Use. OBJECTIVE DEVELOPMENT grants you the
|
2.2 Distribution and Use. OBJECTIVE DEVELOPMENT grants you the
|
||||||
non-exclusive right to use, copy and distribute AVR-USB with your hardware
|
non-exclusive right to use and distribute AVR-USB with your hardware
|
||||||
product(s), restricted by the limitations in section 3 below.
|
product(s), restricted by the limitations in section 3 below.
|
||||||
|
|
||||||
2.3 Modifications. OBJECTIVE DEVELOPMENT grants you the right to modify
|
2.3 Modifications. OBJECTIVE DEVELOPMENT grants you the right to modify
|
||||||
the source code and your copy of AVR-USB according to your needs.
|
your copy of AVR-USB according to your needs.
|
||||||
|
|
||||||
2.4 USB IDs. OBJECTIVE DEVELOPMENT grants you the exclusive rights to use
|
2.4 USB IDs. OBJECTIVE DEVELOPMENT grants you the exclusive rights to use
|
||||||
USB Product ID(s) sent to you in e-mail after receiving your payment in
|
USB Product ID(s) sent to you in e-mail after receiving your payment in
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
OBJECTIVE DEVELOPMENT GmbH's AVR-USB driver software is distributed under the
|
OBJECTIVE DEVELOPMENT GmbH's AVR-USB driver software is distributed under the
|
||||||
terms and conditions of the GNU GPL version 2 or the GNU GPL version 3. It is
|
terms and conditions of the GNU GPL version 2, see the text below. In addition
|
||||||
your choice whether you apply the terms of version 2 or version 3. The full
|
to the requirements in the GPL, we STRONGLY ENCOURAGE you to do the following:
|
||||||
text of GPLv2 is included below. In addition to the requirements in the GPL,
|
|
||||||
we STRONGLY ENCOURAGE you to do the following:
|
|
||||||
|
|
||||||
(1) Publish your entire project on a web site and drop us a note with the URL.
|
(1) Publish your entire project on a web site and drop us a note with the URL.
|
||||||
Use the form at http://www.obdev.at/avrusb/feedback.html for your submission.
|
Use the form at http://www.obdev.at/avrusb/feedback.html for your submission.
|
||||||
@@ -33,7 +33,7 @@ The driver consists of the following files:
|
|||||||
defined to a value greater than 0. Link this module
|
defined to a value greater than 0. Link this module
|
||||||
to your code!
|
to your code!
|
||||||
oddebug.h .............. Interface definitions of the debug module.
|
oddebug.h .............. Interface definitions of the debug module.
|
||||||
usbportability.h ....... Header with compiler-dependent stuff.
|
iarcompat.h ............ Compatibility definitions for IAR C-compiler.
|
||||||
usbdrvasm.asm .......... Compatibility stub for IAR-C-compiler. Use this
|
usbdrvasm.asm .......... Compatibility stub for IAR-C-compiler. Use this
|
||||||
module instead of usbdrvasm.S when you assembler
|
module instead of usbdrvasm.S when you assembler
|
||||||
with IAR's tools.
|
with IAR's tools.
|
||||||
@@ -47,10 +47,9 @@ The driver consists of the following files:
|
|||||||
|
|
||||||
CPU CORE CLOCK FREQUENCY
|
CPU CORE CLOCK FREQUENCY
|
||||||
========================
|
========================
|
||||||
We supply assembler modules for clock frequencies of 12 MHz, 12.8 MHz, 15 MHz,
|
We supply assembler modules for clock frequencies of 12 MHz, 15 MHz, 16 MHz and
|
||||||
16 MHz, 16.5 MHz 18 MHz and 20 MHz. Other clock rates are not supported. The
|
16.5 MHz. Other clock rates are not supported. The actual clock rate must be
|
||||||
actual clock rate must be configured in usbdrv.h unless you use the default
|
configured in usbdrv.h unless you use the default 12 MHz.
|
||||||
12 MHz.
|
|
||||||
|
|
||||||
12 MHz Clock
|
12 MHz Clock
|
||||||
This is the traditional clock rate of AVR-USB because it's the lowest clock
|
This is the traditional clock rate of AVR-USB because it's the lowest clock
|
||||||
@@ -68,29 +67,19 @@ if you need the slightly higher clock rate for performance reasons. Since
|
|||||||
16 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code
|
16 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code
|
||||||
is somewhat tricky and has to insert a leap cycle every third byte.
|
is somewhat tricky and has to insert a leap cycle every third byte.
|
||||||
|
|
||||||
12.8 MHz and 16.5 MHz Clock
|
16.5 MHz Clock
|
||||||
The assembler modules for these clock rates differ from the other modules
|
The assembler module for this clock rate differs from the other modules because
|
||||||
because they have been built for an RC oscillator with only 1% precision. The
|
it has been built for an RC oscillator with only 1% precision. The receiver
|
||||||
receiver code inserts leap cycles to compensate for clock deviations. 1% is
|
code inserts leap cycles to compensate for clock deviations. 1% is also the
|
||||||
also the precision which can be achieved by calibrating the internal RC
|
precision which can be achieved by calibrating the internal RC oscillator of
|
||||||
oscillator of the AVR. Please note that only AVRs with internal 64 MHz PLL
|
the AVR. Please note that only AVRs with internal 64 MHz PLL oscillator can be
|
||||||
oscillator can reach 16.5 MHz with the RC oscillator. This includes the very
|
used since the 8 MHz RC oscillator cannot be trimmed up to 16.5 MHz. This
|
||||||
popular ATTiny25, ATTiny45, ATTiny85 series as well as the ATTiny26. Almost
|
includes the very popular ATTiny25, ATTiny45, ATTiny85 series as well as the
|
||||||
all AVRs can reach 12.8 MHz, although this is outside the specified range.
|
ATTiny26.
|
||||||
|
|
||||||
See the EasyLogger example at http://www.obdev.at/avrusb/easylogger.html for
|
See the EasyLogger example at http://www.obdev.at/avrusb/easylogger.html for
|
||||||
code which calibrates the RC oscillator based on the USB frame clock.
|
code which calibrates the RC oscillator based on the USB frame clock.
|
||||||
|
|
||||||
18 MHz Clock
|
|
||||||
This module is closer to the USB specification because it performs an on the
|
|
||||||
fly CRC check for incoming packets. Packets with invalid checksum are
|
|
||||||
discarded as required by the spec. If you also implement checks for data
|
|
||||||
PID toggling on application level (see option USB_CFG_CHECK_DATA_TOGGLING
|
|
||||||
in usbconfig.h for more info), this ensures data integrity. Due to the CRC
|
|
||||||
tables and alignment requirements, this code is bigger than modules for other
|
|
||||||
clock rates. To activate this module, you must define USB_CFG_CHECK_CRC to 1
|
|
||||||
and USB_CFG_CLOCK_KHZ to 18000 in usbconfig.h.
|
|
||||||
|
|
||||||
20 MHz Clock
|
20 MHz Clock
|
||||||
This module is for people who won't do it with less than the maximum. Since
|
This module is for people who won't do it with less than the maximum. Since
|
||||||
20 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code
|
20 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code
|
||||||
@@ -126,11 +115,10 @@ usbdrv.c because this module has been deliberately optimized for gcc.
|
|||||||
USING AVR-USB FOR FREE
|
USING AVR-USB FOR FREE
|
||||||
======================
|
======================
|
||||||
The AVR firmware driver is published under the GNU General Public License
|
The AVR firmware driver is published under the GNU General Public License
|
||||||
Version 2 (GPL2) and the GNU General Public License Version 3 (GPL3). It is
|
Version 2 (GPL2). See the file "License.txt" for details.
|
||||||
your choice whether you apply the terms of version 2 or version 3.
|
|
||||||
|
|
||||||
If you decide for the free GPL2 or GPL3, we STRONGLY ENCOURAGE you to do the
|
If you decide for the free GPL2, we STRONGLY ENCOURAGE you to do the following
|
||||||
following things IN ADDITION to the obligations from the GPL:
|
things IN ADDITION to the obligations from the GPL2:
|
||||||
|
|
||||||
(1) Publish your entire project on a web site and drop us a note with the URL.
|
(1) Publish your entire project on a web site and drop us a note with the URL.
|
||||||
Use the form at http://www.obdev.at/avrusb/feedback.html for your submission.
|
Use the form at http://www.obdev.at/avrusb/feedback.html for your submission.
|
||||||
@@ -151,7 +139,7 @@ to your modifications for our commercial license offerings.
|
|||||||
|
|
||||||
COMMERCIAL LICENSES FOR AVR-USB
|
COMMERCIAL LICENSES FOR AVR-USB
|
||||||
===============================
|
===============================
|
||||||
If you don't want to publish your source code under the terms of the GPL,
|
If you don't want to publish your source code under the terms of the GPL2,
|
||||||
you can simply pay money for AVR-USB. As an additional benefit you get
|
you can simply pay money for AVR-USB. As an additional benefit you get
|
||||||
USB PIDs for free, licensed exclusively to you. See the file
|
USB PIDs for free, licensed exclusively to you. See the file
|
||||||
"CommercialLicense.txt" for details.
|
"CommercialLicense.txt" for details.
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
* Creation Date: 2007-11-05
|
* Creation Date: 2007-11-05
|
||||||
* Tabsize: 4
|
* Tabsize: 4
|
||||||
* Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
|
* Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
|
||||||
* Revision: $Id$
|
* Revision: $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -103,11 +103,8 @@ sofError:
|
|||||||
reti
|
reti
|
||||||
|
|
||||||
handleData:
|
handleData:
|
||||||
#if USB_CFG_CHECK_CRC
|
lds token, usbCurrentTok;[18]
|
||||||
CRC_CLEANUP_AND_CHECK ; jumps to ignorePacket if CRC error
|
tst token ;[20]
|
||||||
#endif
|
|
||||||
lds shift, usbCurrentTok;[18]
|
|
||||||
tst shift ;[20]
|
|
||||||
breq doReturn ;[21]
|
breq doReturn ;[21]
|
||||||
lds x2, usbRxLen ;[22]
|
lds x2, usbRxLen ;[22]
|
||||||
tst x2 ;[24]
|
tst x2 ;[24]
|
||||||
@@ -116,11 +113,8 @@ handleData:
|
|||||||
; recognized if usbPoll() was called less frequently than once every 4 ms.
|
; recognized if usbPoll() was called less frequently than once every 4 ms.
|
||||||
cpi cnt, 4 ;[26] zero sized data packets are status phase only -- ignore and ack
|
cpi cnt, 4 ;[26] zero sized data packets are status phase only -- ignore and ack
|
||||||
brmi sendAckAndReti ;[27] keep rx buffer clean -- we must not NAK next SETUP
|
brmi sendAckAndReti ;[27] keep rx buffer clean -- we must not NAK next SETUP
|
||||||
#if USB_CFG_CHECK_DATA_TOGGLING
|
|
||||||
sts usbCurrentDataToken, token ; store for checking by C code
|
|
||||||
#endif
|
|
||||||
sts usbRxLen, cnt ;[28] store received data, swap buffers
|
sts usbRxLen, cnt ;[28] store received data, swap buffers
|
||||||
sts usbRxToken, shift ;[30]
|
sts usbRxToken, token ;[30]
|
||||||
lds x2, usbInputBufOffset;[32] swap buffers
|
lds x2, usbInputBufOffset;[32] swap buffers
|
||||||
ldi cnt, USB_BUFSIZE ;[34]
|
ldi cnt, USB_BUFSIZE ;[34]
|
||||||
sub cnt, x2 ;[35]
|
sub cnt, x2 ;[35]
|
||||||
@@ -137,11 +131,7 @@ handleIn:
|
|||||||
ldi x1, USBPID_NAK ;[34] prepare value for usbTxLen
|
ldi x1, USBPID_NAK ;[34] prepare value for usbTxLen
|
||||||
#if USB_CFG_HAVE_INTRIN_ENDPOINT
|
#if USB_CFG_HAVE_INTRIN_ENDPOINT
|
||||||
andi x3, 0xf ;[35] x3 contains endpoint
|
andi x3, 0xf ;[35] x3 contains endpoint
|
||||||
#if USB_CFG_SUPPRESS_INTR_CODE
|
|
||||||
brne sendNakAndReti ;[36]
|
|
||||||
#else
|
|
||||||
brne handleIn1 ;[36]
|
brne handleIn1 ;[36]
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
lds cnt, usbTxLen ;[37]
|
lds cnt, usbTxLen ;[37]
|
||||||
sbrc cnt, 4 ;[39] all handshake tokens have bit 4 set
|
sbrc cnt, 4 ;[39] all handshake tokens have bit 4 set
|
||||||
@@ -160,7 +150,7 @@ handleIn:
|
|||||||
; RAM this way and avoid potential problems with endless retries. The rest of
|
; RAM this way and avoid potential problems with endless retries. The rest of
|
||||||
; the driver assumes error-free transfers anyway.
|
; the driver assumes error-free transfers anyway.
|
||||||
|
|
||||||
#if !USB_CFG_SUPPRESS_INTR_CODE && USB_CFG_HAVE_INTRIN_ENDPOINT /* placed here due to relative jump range */
|
#if USB_CFG_HAVE_INTRIN_ENDPOINT /* placed here due to relative jump range */
|
||||||
handleIn1: ;[38]
|
handleIn1: ;[38]
|
||||||
#if USB_CFG_HAVE_INTRIN_ENDPOINT3
|
#if USB_CFG_HAVE_INTRIN_ENDPOINT3
|
||||||
; 2006-06-10 as suggested by O.Tamura: support second INTR IN / BULK IN endpoint
|
; 2006-06-10 as suggested by O.Tamura: support second INTR IN / BULK IN endpoint
|
||||||
@@ -174,8 +164,9 @@ handleIn1: ;[38]
|
|||||||
ldi YL, lo8(usbTxBuf1) ;[46]
|
ldi YL, lo8(usbTxBuf1) ;[46]
|
||||||
ldi YH, hi8(usbTxBuf1) ;[47]
|
ldi YH, hi8(usbTxBuf1) ;[47]
|
||||||
rjmp usbSendAndReti ;[48] 50 + 12 = 62 until SOP
|
rjmp usbSendAndReti ;[48] 50 + 12 = 62 until SOP
|
||||||
|
#endif
|
||||||
|
|
||||||
#if USB_CFG_HAVE_INTRIN_ENDPOINT3
|
#if USB_CFG_HAVE_INTRIN_ENDPOINT && USB_CFG_HAVE_INTRIN_ENDPOINT3
|
||||||
handleIn3:
|
handleIn3:
|
||||||
lds cnt, usbTxLen3 ;[41]
|
lds cnt, usbTxLen3 ;[41]
|
||||||
sbrc cnt, 4 ;[43]
|
sbrc cnt, 4 ;[43]
|
||||||
@@ -185,4 +176,3 @@ handleIn3:
|
|||||||
ldi YH, hi8(usbTxBuf3) ;[48]
|
ldi YH, hi8(usbTxBuf3) ;[48]
|
||||||
rjmp usbSendAndReti ;[49] 51 + 12 = 63 until SOP
|
rjmp usbSendAndReti ;[49] 51 + 12 = 63 until SOP
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
65
avr/bootloader/usbdrv/iarcompat.h
Normal file
65
avr/bootloader/usbdrv/iarcompat.h
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/* Name: iarcompat.h
|
||||||
|
* Project: AVR USB driver
|
||||||
|
* Author: Christian Starkjohann
|
||||||
|
* Creation Date: 2006-03-01
|
||||||
|
* Tabsize: 4
|
||||||
|
* Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
|
* License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
|
||||||
|
* This Revision: $Id: iarcompat.h 533 2008-02-28 15:35:25Z cs $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
General Description:
|
||||||
|
This header is included when we compile with the IAR C-compiler and assembler.
|
||||||
|
It defines macros for cross compatibility between gcc and IAR-cc.
|
||||||
|
|
||||||
|
Thanks to Oleg Semyonov for his help with the IAR tools port!
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __iarcompat_h_INCLUDED__
|
||||||
|
#define __iarcompat_h_INCLUDED__
|
||||||
|
|
||||||
|
#if defined __IAR_SYSTEMS_ICC__ || defined __IAR_SYSTEMS_ASM__
|
||||||
|
|
||||||
|
/* Enable bit definitions */
|
||||||
|
#ifndef ENABLE_BIT_DEFINITIONS
|
||||||
|
# define ENABLE_BIT_DEFINITIONS 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Include IAR headers */
|
||||||
|
#include <ioavr.h>
|
||||||
|
#ifndef __IAR_SYSTEMS_ASM__
|
||||||
|
# include <inavr.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define __attribute__(arg)
|
||||||
|
|
||||||
|
#ifdef __IAR_SYSTEMS_ASM__
|
||||||
|
# define __ASSEMBLER__
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __HAS_ELPM__
|
||||||
|
# define PROGMEM __farflash
|
||||||
|
#else
|
||||||
|
# define PROGMEM __flash
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define PRG_RDB(addr) (*(PROGMEM char *)(addr))
|
||||||
|
|
||||||
|
/* The following definitions are not needed by the driver, but may be of some
|
||||||
|
* help if you port a gcc based project to IAR.
|
||||||
|
*/
|
||||||
|
#define cli() __disable_interrupt()
|
||||||
|
#define sei() __enable_interrupt()
|
||||||
|
#define wdt_reset() __watchdog_reset()
|
||||||
|
|
||||||
|
/* Depending on the device you use, you may get problems with the way usbdrv.h
|
||||||
|
* handles the differences between devices. Since IAR does not use #defines
|
||||||
|
* for MCU registers, we can't check for the existence of a particular
|
||||||
|
* register with an #ifdef. If the autodetection mechanism fails, include
|
||||||
|
* definitions for the required USB_INTR_* macros in your usbconfig.h. See
|
||||||
|
* usbconfig-prototype.h and usbdrv.h for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* defined __IAR_SYSTEMS_ICC__ || defined __IAR_SYSTEMS_ASM__ */
|
||||||
|
#endif /* __iarcompat_h_INCLUDED__ */
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
* Creation Date: 2005-01-16
|
* Creation Date: 2005-01-16
|
||||||
* Tabsize: 4
|
* Tabsize: 4
|
||||||
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
|
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
|
||||||
* This Revision: $Id: oddebug.c 692 2008-11-07 15:07:40Z cs $
|
* This Revision: $Id: oddebug.c 275 2007-03-20 09:58:28Z cs $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "oddebug.h"
|
#include "oddebug.h"
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
* Creation Date: 2005-01-16
|
* Creation Date: 2005-01-16
|
||||||
* Tabsize: 4
|
* Tabsize: 4
|
||||||
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
|
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
|
||||||
* This Revision: $Id: oddebug.h 692 2008-11-07 15:07:40Z cs $
|
* This Revision: $Id: oddebug.h 275 2007-03-20 09:58:28Z cs $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __oddebug_h_included__
|
#ifndef __oddebug_h_included__
|
||||||
@@ -29,7 +29,10 @@ the output and a memory block to dump in hex ('data' and 'len').
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* make sure we have the UART defines: */
|
/* make sure we have the UART defines: */
|
||||||
#include "usbportability.h"
|
#include "iarcompat.h"
|
||||||
|
#ifndef __IAR_SYSTEMS_ICC__
|
||||||
|
# include <avr/io.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef uchar
|
#ifndef uchar
|
||||||
# define uchar unsigned char
|
# define uchar unsigned char
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
* Creation Date: 2005-04-01
|
* Creation Date: 2005-04-01
|
||||||
* Tabsize: 4
|
* Tabsize: 4
|
||||||
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
|
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
|
||||||
* This Revision: $Id: usbconfig.h 719 2009-03-16 18:51:56Z cs $
|
* This Revision: $Id: usbconfig-prototype.h 600 2008-05-13 10:34:56Z cs $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __usbconfig_h_included__
|
#ifndef __usbconfig_h_included__
|
||||||
@@ -19,6 +19,9 @@ also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may
|
|||||||
wire the lines to any other port, as long as D+ is also wired to INT0 (or any
|
wire the lines to any other port, as long as D+ is also wired to INT0 (or any
|
||||||
other hardware interrupt, as long as it is the highest level interrupt, see
|
other hardware interrupt, as long as it is the highest level interrupt, see
|
||||||
section at the end of this file).
|
section at the end of this file).
|
||||||
|
+ To create your own usbconfig.h file, copy this file to your project's
|
||||||
|
+ firmware source directory) and rename it to "usbconfig.h".
|
||||||
|
+ Then edit it accordingly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* ---------------------------- Hardware Config ---------------------------- */
|
/* ---------------------------- Hardware Config ---------------------------- */
|
||||||
@@ -41,19 +44,12 @@ section at the end of this file).
|
|||||||
* markers every millisecond.]
|
* markers every millisecond.]
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_CLOCK_KHZ (F_CPU/1000)
|
#define USB_CFG_CLOCK_KHZ (F_CPU/1000)
|
||||||
/* Clock rate of the AVR in MHz. Legal values are 12000, 15000, 16000 or 16500.
|
/* Clock rate of the AVR in MHz. Legal values are 12000, 15000, 16000, 16500
|
||||||
* The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1%
|
* and 20000. The 16.5 MHz version of the code requires no crystal, it
|
||||||
* deviation from the nominal frequency. All other rates require a precision
|
* tolerates +/- 1% deviation from the nominal frequency. All other rates
|
||||||
* of 2000 ppm and thus a crystal!
|
* require a precision of 2000 ppm and thus a crystal!
|
||||||
* Default if not specified: 12 MHz
|
* Default if not specified: 12 MHz
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_CHECK_CRC (USB_CFG_CLOCK_KHZ == 18000)
|
|
||||||
/* Define this to 1 if you want that the driver checks data integrity of data
|
|
||||||
* packets (CRC checks). CRC checks cost quite a bit of code size and are
|
|
||||||
* currently only available for 18 MHz crystal clock. You must choose
|
|
||||||
* USB_CFG_CLOCK_KHZ = 18000 if you enable this option.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------- Optional Hardware Config ------------------------ */
|
/* ----------------------- Optional Hardware Config ------------------------ */
|
||||||
|
|
||||||
@@ -71,21 +67,17 @@ section at the end of this file).
|
|||||||
|
|
||||||
/* --------------------------- Functional Range ---------------------------- */
|
/* --------------------------- Functional Range ---------------------------- */
|
||||||
|
|
||||||
#ifndef USB_CFG_HAVE_INTRIN_ENDPOINT3
|
#define USB_CFG_HAVE_INTRIN_ENDPOINT 0
|
||||||
|
/* Define this to 1 if you want to compile a version with two endpoints: The
|
||||||
|
* default control endpoint 0 and an interrupt-in endpoint (any other endpoint
|
||||||
|
* number).
|
||||||
|
*/
|
||||||
#define USB_CFG_HAVE_INTRIN_ENDPOINT3 0
|
#define USB_CFG_HAVE_INTRIN_ENDPOINT3 0
|
||||||
#endif
|
|
||||||
/* Define this to 1 if you want to compile a version with three endpoints: The
|
/* Define this to 1 if you want to compile a version with three endpoints: The
|
||||||
* default control endpoint 0, an interrupt-in endpoint 3 (or the number
|
* default control endpoint 0, an interrupt-in endpoint 3 (or the number
|
||||||
* configured below) and a catch-all default interrupt-in endpoint as above.
|
* configured below) and a catch-all default interrupt-in endpoint as above.
|
||||||
* You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature.
|
* You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature.
|
||||||
*/
|
*/
|
||||||
#ifndef USB_CFG_HAVE_INTRIN_ENDPOINT
|
|
||||||
#define USB_CFG_HAVE_INTRIN_ENDPOINT USB_CFG_HAVE_INTRIN_ENDPOINT3
|
|
||||||
#endif
|
|
||||||
/* Define this to 1 if you want to compile a version with two endpoints: The
|
|
||||||
* default control endpoint 0 and an interrupt-in endpoint (any other endpoint
|
|
||||||
* number).
|
|
||||||
*/
|
|
||||||
#define USB_CFG_EP3_NUMBER 3
|
#define USB_CFG_EP3_NUMBER 3
|
||||||
/* If the so-called endpoint 3 is used, it can now be configured to any other
|
/* If the so-called endpoint 3 is used, it can now be configured to any other
|
||||||
* endpoint number (except 0) with this macro. Default if undefined is 3.
|
* endpoint number (except 0) with this macro. Default if undefined is 3.
|
||||||
@@ -96,7 +88,7 @@ section at the end of this file).
|
|||||||
* Since the token is toggled BEFORE sending any data, the first packet is
|
* Since the token is toggled BEFORE sending any data, the first packet is
|
||||||
* sent with the oposite value of this configuration!
|
* sent with the oposite value of this configuration!
|
||||||
*/
|
*/
|
||||||
//#define USB_CFG_IMPLEMENT_HALT 0
|
#define USB_CFG_IMPLEMENT_HALT 0
|
||||||
/* Define this to 1 if you also want to implement the ENDPOINT_HALT feature
|
/* Define this to 1 if you also want to implement the ENDPOINT_HALT feature
|
||||||
* for endpoint 1 (interrupt endpoint). Although you may not need this feature,
|
* for endpoint 1 (interrupt endpoint). Although you may not need this feature,
|
||||||
* it is required by the standard. We have made it a config option because it
|
* it is required by the standard. We have made it a config option because it
|
||||||
@@ -111,23 +103,23 @@ section at the end of this file).
|
|||||||
/* Define this to 1 if the device has its own power supply. Set it to 0 if the
|
/* Define this to 1 if the device has its own power supply. Set it to 0 if the
|
||||||
* device is powered from the USB bus.
|
* device is powered from the USB bus.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_MAX_BUS_POWER 40
|
#define USB_CFG_MAX_BUS_POWER 100
|
||||||
/* Set this variable to the maximum USB bus power consumption of your device.
|
/* Set this variable to the maximum USB bus power consumption of your device.
|
||||||
* The value is in milliamperes. [It will be divided by two since USB
|
* The value is in milliamperes. [It will be divided by two since USB
|
||||||
* communicates power requirements in units of 2 mA.]
|
* communicates power requirements in units of 2 mA.]
|
||||||
*/
|
*/
|
||||||
//#define USB_CFG_IMPLEMENT_FN_WRITE 0
|
#define USB_CFG_IMPLEMENT_FN_WRITE 0
|
||||||
/* Set this to 1 if you want usbFunctionWrite() to be called for control-out
|
/* Set this to 1 if you want usbFunctionWrite() to be called for control-out
|
||||||
* transfers. Set it to 0 if you don't need it and want to save a couple of
|
* transfers. Set it to 0 if you don't need it and want to save a couple of
|
||||||
* bytes.
|
* bytes.
|
||||||
*/
|
*/
|
||||||
//#define USB_CFG_IMPLEMENT_FN_READ 0
|
#define USB_CFG_IMPLEMENT_FN_READ 0
|
||||||
/* Set this to 1 if you need to send control replies which are generated
|
/* Set this to 1 if you need to send control replies which are generated
|
||||||
* "on the fly" when usbFunctionRead() is called. If you only want to send
|
* "on the fly" when usbFunctionRead() is called. If you only want to send
|
||||||
* data from a static buffer, set it to 0 and return the data from
|
* data from a static buffer, set it to 0 and return the data from
|
||||||
* usbFunctionSetup(). This saves a couple of bytes.
|
* usbFunctionSetup(). This saves a couple of bytes.
|
||||||
*/
|
*/
|
||||||
//#define USB_CFG_IMPLEMENT_FN_WRITEOUT 0
|
#define USB_CFG_IMPLEMENT_FN_WRITEOUT 0
|
||||||
/* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints.
|
/* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints.
|
||||||
* You must implement the function usbFunctionWriteOut() which receives all
|
* You must implement the function usbFunctionWriteOut() which receives all
|
||||||
* interrupt/bulk data sent to any endpoint other than 0. The endpoint number
|
* interrupt/bulk data sent to any endpoint other than 0. The endpoint number
|
||||||
@@ -138,7 +130,7 @@ section at the end of this file).
|
|||||||
* of the macros usbDisableAllRequests() and usbEnableAllRequests() in
|
* of the macros usbDisableAllRequests() and usbEnableAllRequests() in
|
||||||
* usbdrv.h.
|
* usbdrv.h.
|
||||||
*/
|
*/
|
||||||
//#define USB_CFG_LONG_TRANSFERS 0
|
#define USB_CFG_LONG_TRANSFERS 0
|
||||||
/* Define this to 1 if you want to send/receive blocks of more than 254 bytes
|
/* Define this to 1 if you want to send/receive blocks of more than 254 bytes
|
||||||
* in a single control-in or control-out transfer. Note that the capability
|
* in a single control-in or control-out transfer. Note that the capability
|
||||||
* for long transfers increases the driver size.
|
* for long transfers increases the driver size.
|
||||||
@@ -159,12 +151,12 @@ section at the end of this file).
|
|||||||
/* This macro (if defined) is executed when a USB SET_ADDRESS request was
|
/* This macro (if defined) is executed when a USB SET_ADDRESS request was
|
||||||
* received.
|
* received.
|
||||||
*/
|
*/
|
||||||
//#define USB_COUNT_SOF 0
|
#define USB_COUNT_SOF 0
|
||||||
/* define this macro to 1 if you need the global variable "usbSofCount" which
|
/* define this macro to 1 if you need the global variable "usbSofCount" which
|
||||||
* counts SOF packets. This feature requires that the hardware interrupt is
|
* counts SOF packets. This feature requires that the hardware interrupt is
|
||||||
* connected to D- instead of D+.
|
* connected to D- instead of D+.
|
||||||
*/
|
*/
|
||||||
//#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0
|
#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0
|
||||||
/* define this macro to 1 if you want the function usbMeasureFrameLength()
|
/* define this macro to 1 if you want the function usbMeasureFrameLength()
|
||||||
* compiled in. This function can be used to calibrate the AVR's RC oscillator.
|
* compiled in. This function can be used to calibrate the AVR's RC oscillator.
|
||||||
*/
|
*/
|
||||||
@@ -175,13 +167,17 @@ section at the end of this file).
|
|||||||
/* USB vendor ID for the device, low byte first. If you have registered your
|
/* USB vendor ID for the device, low byte first. If you have registered your
|
||||||
* own Vendor ID, define it here. Otherwise you use one of obdev's free shared
|
* own Vendor ID, define it here. Otherwise you use one of obdev's free shared
|
||||||
* VID/PID pairs. Be sure to read USBID-License.txt for rules!
|
* VID/PID pairs. Be sure to read USBID-License.txt for rules!
|
||||||
|
* + This template uses obdev's shared VID/PID pair: 0x16c0/0x5dc.
|
||||||
|
* + Use this VID/PID pair ONLY if you understand the implications!
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_DEVICE_ID 0x08, 0x3e /* 1000 dec, "free for lab use" */
|
#define USB_CFG_DEVICE_ID 0xdc, 0x05
|
||||||
/* This is the ID of the product, low byte first. It is interpreted in the
|
/* This is the ID of the product, low byte first. It is interpreted in the
|
||||||
* scope of the vendor ID. If you have registered your own VID with usb.org
|
* scope of the vendor ID. If you have registered your own VID with usb.org
|
||||||
* or if you have licensed a PID from somebody else, define it here. Otherwise
|
* or if you have licensed a PID from somebody else, define it here. Otherwise
|
||||||
* you use obdev's free shared VID/PID pair. Be sure to read the rules in
|
* you use obdev's free shared VID/PID pair. Be sure to read the rules in
|
||||||
* USBID-License.txt!
|
* USBID-License.txt!
|
||||||
|
* + This template uses obdev's shared VID/PID pair: 0x16c0/0x5dc.
|
||||||
|
* + Use this VID/PID pair ONLY if you understand the implications!
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_DEVICE_VERSION 0x00, 0x01
|
#define USB_CFG_DEVICE_VERSION 0x00, 0x01
|
||||||
/* Version number of the device: Minor number first, then major number.
|
/* Version number of the device: Minor number first, then major number.
|
||||||
@@ -196,8 +192,8 @@ section at the end of this file).
|
|||||||
* obdev's free shared VID/PID pair. See the file USBID-License.txt for
|
* obdev's free shared VID/PID pair. See the file USBID-License.txt for
|
||||||
* details.
|
* details.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_DEVICE_NAME 'T', 'e', 's', 't'
|
#define USB_CFG_DEVICE_NAME 'T', 'e', 'm', 'p', 'l', 'a', 't', 'e'
|
||||||
#define USB_CFG_DEVICE_NAME_LEN 4
|
#define USB_CFG_DEVICE_NAME_LEN 8
|
||||||
/* Same as above for the device name. If you don't want a device name, undefine
|
/* Same as above for the device name. If you don't want a device name, undefine
|
||||||
* the macros. See the file USBID-License.txt before you assign a name if you
|
* the macros. See the file USBID-License.txt before you assign a name if you
|
||||||
* use a shared VID/PID.
|
* use a shared VID/PID.
|
||||||
@@ -281,13 +277,8 @@ section at the end of this file).
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if USE_DYNAMIC_DESCRIPTOR
|
|
||||||
#define USB_CFG_DESCR_PROPS_DEVICE USB_PROP_IS_DYNAMIC
|
|
||||||
#define USB_CFG_DESCR_PROPS_CONFIGURATION USB_PROP_IS_DYNAMIC
|
|
||||||
#else
|
|
||||||
#define USB_CFG_DESCR_PROPS_DEVICE 0
|
#define USB_CFG_DESCR_PROPS_DEVICE 0
|
||||||
#define USB_CFG_DESCR_PROPS_CONFIGURATION 0
|
#define USB_CFG_DESCR_PROPS_CONFIGURATION 0
|
||||||
#endif
|
|
||||||
#define USB_CFG_DESCR_PROPS_STRINGS 0
|
#define USB_CFG_DESCR_PROPS_STRINGS 0
|
||||||
#define USB_CFG_DESCR_PROPS_STRING_0 0
|
#define USB_CFG_DESCR_PROPS_STRING_0 0
|
||||||
#define USB_CFG_DESCR_PROPS_STRING_VENDOR 0
|
#define USB_CFG_DESCR_PROPS_STRING_VENDOR 0
|
||||||
@@ -4,11 +4,15 @@
|
|||||||
* Creation Date: 2004-12-29
|
* Creation Date: 2004-12-29
|
||||||
* Tabsize: 4
|
* Tabsize: 4
|
||||||
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
|
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
|
||||||
* This Revision: $Id: usbdrv.c 721 2009-03-16 19:03:19Z cs $
|
* This Revision: $Id: usbdrv.c 591 2008-05-03 20:21:19Z cs $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "usbportability.h"
|
#include "iarcompat.h"
|
||||||
|
#ifndef __IAR_SYSTEMS_ICC__
|
||||||
|
# include <avr/io.h>
|
||||||
|
# include <avr/pgmspace.h>
|
||||||
|
#endif
|
||||||
#include "usbdrv.h"
|
#include "usbdrv.h"
|
||||||
#include "oddebug.h"
|
#include "oddebug.h"
|
||||||
|
|
||||||
@@ -34,15 +38,12 @@ uchar usbTxBuf[USB_BUFSIZE];/* data to transmit with next IN, free if usbT
|
|||||||
#if USB_COUNT_SOF
|
#if USB_COUNT_SOF
|
||||||
volatile uchar usbSofCount; /* incremented by assembler module every SOF */
|
volatile uchar usbSofCount; /* incremented by assembler module every SOF */
|
||||||
#endif
|
#endif
|
||||||
#if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE
|
#if USB_CFG_HAVE_INTRIN_ENDPOINT
|
||||||
usbTxStatus_t usbTxStatus1;
|
usbTxStatus_t usbTxStatus1;
|
||||||
# if USB_CFG_HAVE_INTRIN_ENDPOINT3
|
# if USB_CFG_HAVE_INTRIN_ENDPOINT3
|
||||||
usbTxStatus_t usbTxStatus3;
|
usbTxStatus_t usbTxStatus3;
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#if USB_CFG_CHECK_DATA_TOGGLING
|
|
||||||
uchar usbCurrentDataToken;/* when we check data toggling to ignore duplicate packets */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* USB status registers / not shared with asm code */
|
/* USB status registers / not shared with asm code */
|
||||||
uchar *usbMsgPtr; /* data to transmit next -- ROM or RAM address */
|
uchar *usbMsgPtr; /* data to transmit next -- ROM or RAM address */
|
||||||
@@ -55,7 +56,7 @@ static uchar usbMsgFlags; /* flag values see below */
|
|||||||
/*
|
/*
|
||||||
optimizing hints:
|
optimizing hints:
|
||||||
- do not post/pre inc/dec integer values in operations
|
- do not post/pre inc/dec integer values in operations
|
||||||
- assign value of USB_READ_FLASH() to register variables and don't use side effects in arg
|
- assign value of PRG_RDB() to register variables and don't use side effects in arg
|
||||||
- use narrow scope for variables which should be in X/Y/Z register
|
- use narrow scope for variables which should be in X/Y/Z register
|
||||||
- assign char sized expressions to variables to force 8 bit arithmetics
|
- assign char sized expressions to variables to force 8 bit arithmetics
|
||||||
*/
|
*/
|
||||||
@@ -194,9 +195,18 @@ PROGMEM char usbDescriptorConfiguration[] = { /* USB configuration descriptor
|
|||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/* We don't use prog_int or prog_int16_t for compatibility with various libc
|
||||||
|
* versions. Here's an other compatibility hack:
|
||||||
|
*/
|
||||||
|
#ifndef PRG_RDB
|
||||||
|
#define PRG_RDB(addr) pgm_read_byte(addr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static inline void usbResetDataToggling(void)
|
static inline void usbResetDataToggling(void)
|
||||||
{
|
{
|
||||||
#if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE
|
#if USB_CFG_HAVE_INTRIN_ENDPOINT
|
||||||
USB_SET_DATATOKEN1(USB_INITIAL_DATATOKEN); /* reset data toggling for interrupt endpoint */
|
USB_SET_DATATOKEN1(USB_INITIAL_DATATOKEN); /* reset data toggling for interrupt endpoint */
|
||||||
# if USB_CFG_HAVE_INTRIN_ENDPOINT3
|
# if USB_CFG_HAVE_INTRIN_ENDPOINT3
|
||||||
USB_SET_DATATOKEN3(USB_INITIAL_DATATOKEN); /* reset data toggling for interrupt endpoint */
|
USB_SET_DATATOKEN3(USB_INITIAL_DATATOKEN); /* reset data toggling for interrupt endpoint */
|
||||||
@@ -216,7 +226,6 @@ static inline void usbResetStall(void)
|
|||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#if !USB_CFG_SUPPRESS_INTR_CODE
|
|
||||||
#if USB_CFG_HAVE_INTRIN_ENDPOINT
|
#if USB_CFG_HAVE_INTRIN_ENDPOINT
|
||||||
static void usbGenericSetInterrupt(uchar *data, uchar len, usbTxStatus_t *txStatus)
|
static void usbGenericSetInterrupt(uchar *data, uchar len, usbTxStatus_t *txStatus)
|
||||||
{
|
{
|
||||||
@@ -254,7 +263,6 @@ USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len)
|
|||||||
usbGenericSetInterrupt(data, len, &usbTxStatus3);
|
usbGenericSetInterrupt(data, len, &usbTxStatus3);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif /* USB_CFG_SUPPRESS_INTR_CODE */
|
|
||||||
|
|
||||||
/* ------------------ utilities for code following below ------------------- */
|
/* ------------------ utilities for code following below ------------------- */
|
||||||
|
|
||||||
@@ -400,7 +408,7 @@ uchar index = rq->wIndex.bytes[0];
|
|||||||
usbResetStall();
|
usbResetStall();
|
||||||
SWITCH_CASE(USBRQ_GET_INTERFACE) /* 10 */
|
SWITCH_CASE(USBRQ_GET_INTERFACE) /* 10 */
|
||||||
len = 1;
|
len = 1;
|
||||||
#if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE
|
#if USB_CFG_HAVE_INTRIN_ENDPOINT
|
||||||
SWITCH_CASE(USBRQ_SET_INTERFACE) /* 11 */
|
SWITCH_CASE(USBRQ_SET_INTERFACE) /* 11 */
|
||||||
usbResetDataToggling();
|
usbResetDataToggling();
|
||||||
usbResetStall();
|
usbResetStall();
|
||||||
@@ -428,7 +436,7 @@ usbRequest_t *rq = (void *)data;
|
|||||||
* 0xe1 11100001 (USBPID_OUT: data phase of setup transfer)
|
* 0xe1 11100001 (USBPID_OUT: data phase of setup transfer)
|
||||||
* 0...0x0f for OUT on endpoint X
|
* 0...0x0f for OUT on endpoint X
|
||||||
*/
|
*/
|
||||||
DBG2(0x10 + (usbRxToken & 0xf), data, len + 2); /* SETUP=1d, SETUP-DATA=11, OUTx=1x */
|
DBG2(0x10 + (usbRxToken & 0xf), data, len); /* SETUP=1d, SETUP-DATA=11, OUTx=1x */
|
||||||
USB_RX_USER_HOOK(data, len)
|
USB_RX_USER_HOOK(data, len)
|
||||||
#if USB_CFG_IMPLEMENT_FN_WRITEOUT
|
#if USB_CFG_IMPLEMENT_FN_WRITEOUT
|
||||||
if(usbRxToken < 0x10){ /* OUT to endpoint != 0: endpoint number in usbRxToken */
|
if(usbRxToken < 0x10){ /* OUT to endpoint != 0: endpoint number in usbRxToken */
|
||||||
@@ -451,13 +459,9 @@ usbRequest_t *rq = (void *)data;
|
|||||||
}
|
}
|
||||||
#if USB_CFG_IMPLEMENT_FN_READ || USB_CFG_IMPLEMENT_FN_WRITE
|
#if USB_CFG_IMPLEMENT_FN_READ || USB_CFG_IMPLEMENT_FN_WRITE
|
||||||
if(replyLen == USB_NO_MSG){ /* use user-supplied read/write function */
|
if(replyLen == USB_NO_MSG){ /* use user-supplied read/write function */
|
||||||
/* do some conditioning on replyLen, but on IN transfers only */
|
/* do some conditioning on replyLen */
|
||||||
if((rq->bmRequestType & USBRQ_DIR_MASK) != USBRQ_DIR_HOST_TO_DEVICE){
|
if((rq->bmRequestType & USBRQ_DIR_MASK) != USBRQ_DIR_HOST_TO_DEVICE){
|
||||||
if(sizeof(replyLen) < sizeof(rq->wLength.word)){ /* help compiler with optimizing */
|
replyLen = rq->wLength.bytes[0]; /* IN transfers only */
|
||||||
replyLen = rq->wLength.bytes[0];
|
|
||||||
}else{
|
|
||||||
replyLen = rq->wLength.word;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
usbMsgFlags = USB_FLG_USE_USER_RW;
|
usbMsgFlags = USB_FLG_USE_USER_RW;
|
||||||
}else /* The 'else' prevents that we limit a replyLen of USB_NO_MSG to the maximum transfer len. */
|
}else /* The 'else' prevents that we limit a replyLen of USB_NO_MSG to the maximum transfer len. */
|
||||||
@@ -501,7 +505,7 @@ static uchar usbDeviceRead(uchar *data, uchar len)
|
|||||||
uchar i = len, *r = usbMsgPtr;
|
uchar i = len, *r = usbMsgPtr;
|
||||||
if(usbMsgFlags & USB_FLG_MSGPTR_IS_ROM){ /* ROM data */
|
if(usbMsgFlags & USB_FLG_MSGPTR_IS_ROM){ /* ROM data */
|
||||||
do{
|
do{
|
||||||
uchar c = USB_READ_FLASH(r); /* assign to char size variable to enforce byte ops */
|
uchar c = PRG_RDB(r); /* assign to char size variable to enforce byte ops */
|
||||||
*data++ = c;
|
*data++ = c;
|
||||||
r++;
|
r++;
|
||||||
}while(--i);
|
}while(--i);
|
||||||
@@ -588,17 +592,17 @@ uchar i;
|
|||||||
usbBuildTxBlock();
|
usbBuildTxBlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(i = 20; i > 0; i--){
|
for(i = 10; i > 0; i--){
|
||||||
uchar usbLineStatus = USBIN & USBMASK;
|
uchar usbLineStatus = USBIN & USBMASK;
|
||||||
if(usbLineStatus != 0) /* SE0 has ended */
|
if(usbLineStatus != 0) /* SE0 has ended */
|
||||||
goto isNotReset;
|
break;
|
||||||
}
|
}
|
||||||
/* RESET condition, called multiple times during reset */
|
if(i == 0){ /* RESET condition, called multiple times during reset */
|
||||||
usbNewDeviceAddr = 0;
|
usbNewDeviceAddr = 0;
|
||||||
usbDeviceAddr = 0;
|
usbDeviceAddr = 0;
|
||||||
usbResetStall();
|
usbResetStall();
|
||||||
DBG1(0xff, 0, 0);
|
DBG1(0xff, 0, 0);
|
||||||
isNotReset:
|
}
|
||||||
usbHandleResetHook(i);
|
usbHandleResetHook(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,7 +618,7 @@ USB_PUBLIC void usbInit(void)
|
|||||||
#endif
|
#endif
|
||||||
USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT);
|
USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT);
|
||||||
usbResetDataToggling();
|
usbResetDataToggling();
|
||||||
#if USB_CFG_HAVE_INTRIN_ENDPOINT && !USB_CFG_SUPPRESS_INTR_CODE
|
#if USB_CFG_HAVE_INTRIN_ENDPOINT
|
||||||
usbTxLen1 = USBPID_NAK;
|
usbTxLen1 = USBPID_NAK;
|
||||||
#if USB_CFG_HAVE_INTRIN_ENDPOINT3
|
#if USB_CFG_HAVE_INTRIN_ENDPOINT3
|
||||||
usbTxLen3 = USBPID_NAK;
|
usbTxLen3 = USBPID_NAK;
|
||||||
@@ -4,14 +4,14 @@
|
|||||||
* Creation Date: 2004-12-29
|
* Creation Date: 2004-12-29
|
||||||
* Tabsize: 4
|
* Tabsize: 4
|
||||||
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
|
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
|
||||||
* This Revision: $Id: usbdrv.h 738 2009-03-23 11:13:24Z cs $
|
* This Revision: $Id: usbdrv.h 607 2008-05-13 15:57:28Z cs $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __usbdrv_h_included__
|
#ifndef __usbdrv_h_included__
|
||||||
#define __usbdrv_h_included__
|
#define __usbdrv_h_included__
|
||||||
#include "usbconfig.h"
|
#include "usbconfig.h"
|
||||||
#include "usbportability.h"
|
#include "iarcompat.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Hardware Prerequisites:
|
Hardware Prerequisites:
|
||||||
@@ -34,8 +34,8 @@ usbDeviceConnect() and usbDeviceDisconnect() further down in this file.
|
|||||||
|
|
||||||
Please adapt the values in usbconfig.h according to your hardware!
|
Please adapt the values in usbconfig.h according to your hardware!
|
||||||
|
|
||||||
The device MUST be clocked at exactly 12 MHz, 15 MHz, 16 MHz or 20 MHz
|
The device MUST be clocked at exactly 12 MHz, 15 MHz or 16 MHz
|
||||||
or at 12.8 MHz resp. 16.5 MHz +/- 1%. See usbconfig-prototype.h for details.
|
or at 16.5 MHz +/- 1%. See usbconfig-prototype.h for details.
|
||||||
|
|
||||||
|
|
||||||
Limitations:
|
Limitations:
|
||||||
@@ -122,7 +122,7 @@ USB messages, even if they address another (low-speed) device on the same bus.
|
|||||||
/* --------------------------- Module Interface ---------------------------- */
|
/* --------------------------- Module Interface ---------------------------- */
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#define USBDRV_VERSION 20090323
|
#define USBDRV_VERSION 20080513
|
||||||
/* This define uniquely identifies a driver version. It is a decimal number
|
/* This define uniquely identifies a driver version. It is a decimal number
|
||||||
* constructed from the driver's release date in the form YYYYMMDD. If the
|
* constructed from the driver's release date in the form YYYYMMDD. If the
|
||||||
* driver's behavior or interface changes, you can use this constant to
|
* driver's behavior or interface changes, you can use this constant to
|
||||||
@@ -273,8 +273,6 @@ USB_PUBLIC uchar usbFunctionRead(uchar *data, uchar len);
|
|||||||
* to 1 in usbconfig.h and return 0xff in usbFunctionSetup()..
|
* to 1 in usbconfig.h and return 0xff in usbFunctionSetup()..
|
||||||
*/
|
*/
|
||||||
#endif /* USB_CFG_IMPLEMENT_FN_READ */
|
#endif /* USB_CFG_IMPLEMENT_FN_READ */
|
||||||
|
|
||||||
extern uchar usbRxToken; /* may be used in usbFunctionWriteOut() below */
|
|
||||||
#if USB_CFG_IMPLEMENT_FN_WRITEOUT
|
#if USB_CFG_IMPLEMENT_FN_WRITEOUT
|
||||||
USB_PUBLIC void usbFunctionWriteOut(uchar *data, uchar len);
|
USB_PUBLIC void usbFunctionWriteOut(uchar *data, uchar len);
|
||||||
/* This function is called by the driver when data is received on an interrupt-
|
/* This function is called by the driver when data is received on an interrupt-
|
||||||
@@ -341,12 +339,6 @@ extern volatile uchar usbSofCount;
|
|||||||
* the macro USB_COUNT_SOF is defined to a value != 0.
|
* the macro USB_COUNT_SOF is defined to a value != 0.
|
||||||
*/
|
*/
|
||||||
#endif
|
#endif
|
||||||
#if USB_CFG_CHECK_DATA_TOGGLING
|
|
||||||
extern uchar usbCurrentDataToken;
|
|
||||||
/* This variable can be checked in usbFunctionWrite() and usbFunctionWriteOut()
|
|
||||||
* to ignore duplicate packets.
|
|
||||||
*/
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define USB_STRING_DESCRIPTOR_HEADER(stringLength) ((2*(stringLength)+2) | (3<<8))
|
#define USB_STRING_DESCRIPTOR_HEADER(stringLength) ((2*(stringLength)+2) | (3<<8))
|
||||||
/* This macro builds a descriptor header for a string descriptor given the
|
/* This macro builds a descriptor header for a string descriptor given the
|
||||||
@@ -390,9 +382,7 @@ extern volatile schar usbRxLen;
|
|||||||
*/
|
*/
|
||||||
#define USB_PROP_IS_DYNAMIC (1 << 14)
|
#define USB_PROP_IS_DYNAMIC (1 << 14)
|
||||||
/* If this property is set for a descriptor, usbFunctionDescriptor() will be
|
/* If this property is set for a descriptor, usbFunctionDescriptor() will be
|
||||||
* used to obtain the particular descriptor. Data directly returned via
|
* used to obtain the particular descriptor.
|
||||||
* usbMsgPtr are FLASH data by default, combine (OR) with USB_PROP_IS_RAM to
|
|
||||||
* return RAM data.
|
|
||||||
*/
|
*/
|
||||||
#define USB_PROP_IS_RAM (1 << 15)
|
#define USB_PROP_IS_RAM (1 << 15)
|
||||||
/* If this property is set for a descriptor, the data is read from RAM
|
/* If this property is set for a descriptor, the data is read from RAM
|
||||||
@@ -556,10 +546,6 @@ int usbDescriptorStringSerialNumber[];
|
|||||||
#define USB_CFG_EP3_NUMBER 3
|
#define USB_CFG_EP3_NUMBER 3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef USB_CFG_HAVE_INTRIN_ENDPOINT3
|
|
||||||
#define USB_CFG_HAVE_INTRIN_ENDPOINT3 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define USB_BUFSIZE 11 /* PID, 8 bytes data, 2 bytes CRC */
|
#define USB_BUFSIZE 11 /* PID, 8 bytes data, 2 bytes CRC */
|
||||||
|
|
||||||
/* ----- Try to find registers and bits responsible for ext interrupt 0 ----- */
|
/* ----- Try to find registers and bits responsible for ext interrupt 0 ----- */
|
||||||
@@ -572,14 +558,7 @@ int usbDescriptorStringSerialNumber[];
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#ifndef USB_INTR_CFG_SET /* allow user to override our default */
|
#ifndef USB_INTR_CFG_SET /* allow user to override our default */
|
||||||
# if defined(USB_COUNT_SOF) || defined(USB_SOF_HOOK)
|
|
||||||
# define USB_INTR_CFG_SET (1 << ISC01) /* cfg for falling edge */
|
|
||||||
/* If any SOF logic is used, the interrupt must be wired to D- where
|
|
||||||
* we better trigger on falling edge
|
|
||||||
*/
|
|
||||||
# else
|
|
||||||
# define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) /* cfg for rising edge */
|
# define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) /* cfg for rising edge */
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
#ifndef USB_INTR_CFG_CLR /* allow user to override our default */
|
#ifndef USB_INTR_CFG_CLR /* allow user to override our default */
|
||||||
# define USB_INTR_CFG_CLR 0 /* no bits to clear */
|
# define USB_INTR_CFG_CLR 0 /* no bits to clear */
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
* Creation Date: 2007-06-13
|
* Creation Date: 2007-06-13
|
||||||
* Tabsize: 4
|
* Tabsize: 4
|
||||||
* Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
|
* Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
|
||||||
* Revision: $Id: usbdrvasm.S 722 2009-03-16 19:03:57Z cs $
|
* Revision: $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -15,8 +15,15 @@ general code (preprocessor acrobatics and CRC computation) and then includes
|
|||||||
the file appropriate for the given clock rate.
|
the file appropriate for the given clock rate.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define __SFR_OFFSET 0 /* used by avr-libc's register definitions */
|
#include "iarcompat.h"
|
||||||
#include "usbportability.h"
|
#ifndef __IAR_SYSTEMS_ASM__
|
||||||
|
/* configs for io.h */
|
||||||
|
# define __SFR_OFFSET 0
|
||||||
|
# define _VECTOR(N) __vector_ ## N /* io.h does not define this for asm */
|
||||||
|
# include <avr/io.h> /* for CPU I/O register definitions and vectors */
|
||||||
|
# define macro .macro /* GNU Assembler macro definition */
|
||||||
|
# define endm .endm /* End of GNU Assembler macro definition */
|
||||||
|
#endif /* __IAR_SYSTEMS_ASM__ */
|
||||||
#include "usbdrv.h" /* for common defs */
|
#include "usbdrv.h" /* for common defs */
|
||||||
|
|
||||||
/* register names */
|
/* register names */
|
||||||
@@ -26,14 +33,24 @@ the file appropriate for the given clock rate.
|
|||||||
#define cnt r19
|
#define cnt r19
|
||||||
#define x3 r20
|
#define x3 r20
|
||||||
#define x4 r21
|
#define x4 r21
|
||||||
#define x5 r22
|
#define bitcnt r22
|
||||||
#define bitcnt x5
|
|
||||||
#define phase x4
|
#define phase x4
|
||||||
#define leap x4
|
#define leap x4
|
||||||
|
|
||||||
/* Some assembler dependent definitions and declarations: */
|
/* Some assembler dependent definitions and declarations: */
|
||||||
|
|
||||||
#ifdef __IAR_SYSTEMS_ASM__
|
#ifdef __IAR_SYSTEMS_ASM__
|
||||||
|
|
||||||
|
# define nop2 rjmp $+2 /* jump to next instruction */
|
||||||
|
# define XL r26
|
||||||
|
# define XH r27
|
||||||
|
# define YL r28
|
||||||
|
# define YH r29
|
||||||
|
# define ZL r30
|
||||||
|
# define ZH r31
|
||||||
|
# define lo8(x) LOW(x)
|
||||||
|
# define hi8(x) (((x)>>8) & 0xff) /* not HIGH to allow XLINK to make a proper range check */
|
||||||
|
|
||||||
extern usbRxBuf, usbDeviceAddr, usbNewDeviceAddr, usbInputBufOffset
|
extern usbRxBuf, usbDeviceAddr, usbNewDeviceAddr, usbInputBufOffset
|
||||||
extern usbCurrentTok, usbRxLen, usbRxToken, usbTxLen
|
extern usbCurrentTok, usbRxLen, usbRxToken, usbTxLen
|
||||||
extern usbTxBuf, usbTxStatus1, usbTxStatus3
|
extern usbTxBuf, usbTxStatus1, usbTxStatus3
|
||||||
@@ -56,6 +73,8 @@ the file appropriate for the given clock rate.
|
|||||||
|
|
||||||
#else /* __IAR_SYSTEMS_ASM__ */
|
#else /* __IAR_SYSTEMS_ASM__ */
|
||||||
|
|
||||||
|
# define nop2 rjmp .+0 /* jump to next instruction */
|
||||||
|
|
||||||
# ifndef USB_INTR_VECTOR /* default to hardware interrupt INT0 */
|
# ifndef USB_INTR_VECTOR /* default to hardware interrupt INT0 */
|
||||||
# define USB_INTR_VECTOR SIG_INTERRUPT0
|
# define USB_INTR_VECTOR SIG_INTERRUPT0
|
||||||
# endif
|
# endif
|
||||||
@@ -280,26 +299,16 @@ usbMFTimeout:
|
|||||||
# define USB_CFG_CLOCK_KHZ 12000
|
# define USB_CFG_CLOCK_KHZ 12000
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if USB_CFG_CHECK_CRC /* separate dispatcher for CRC type modules */
|
#if USB_CFG_CLOCK_KHZ == 12000
|
||||||
# if USB_CFG_CLOCK_KHZ == 18000
|
|
||||||
# include "usbdrvasm18-crc.inc"
|
|
||||||
# else
|
|
||||||
# error "USB_CFG_CLOCK_KHZ is not one of the supported crc-rates!"
|
|
||||||
# endif
|
|
||||||
#else /* USB_CFG_CHECK_CRC */
|
|
||||||
# if USB_CFG_CLOCK_KHZ == 12000
|
|
||||||
# include "usbdrvasm12.inc"
|
# include "usbdrvasm12.inc"
|
||||||
# elif USB_CFG_CLOCK_KHZ == 12800
|
#elif USB_CFG_CLOCK_KHZ == 15000
|
||||||
# include "usbdrvasm128.inc"
|
|
||||||
# elif USB_CFG_CLOCK_KHZ == 15000
|
|
||||||
# include "usbdrvasm15.inc"
|
# include "usbdrvasm15.inc"
|
||||||
# elif USB_CFG_CLOCK_KHZ == 16000
|
#elif USB_CFG_CLOCK_KHZ == 16000
|
||||||
# include "usbdrvasm16.inc"
|
# include "usbdrvasm16.inc"
|
||||||
# elif USB_CFG_CLOCK_KHZ == 16500
|
#elif USB_CFG_CLOCK_KHZ == 16500
|
||||||
# include "usbdrvasm165.inc"
|
# include "usbdrvasm165.inc"
|
||||||
# elif USB_CFG_CLOCK_KHZ == 20000
|
#elif USB_CFG_CLOCK_KHZ == 20000
|
||||||
# include "usbdrvasm20.inc"
|
# include "usbdrvasm20.inc"
|
||||||
# else
|
#else
|
||||||
# error "USB_CFG_CLOCK_KHZ is not one of the supported non-crc-rates!"
|
# error "USB_CFG_CLOCK_KHZ is not one of the supported rates!"
|
||||||
# endif
|
#endif
|
||||||
#endif /* USB_CFG_CHECK_CRC */
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
* Creation Date: 2006-03-01
|
* Creation Date: 2006-03-01
|
||||||
* Tabsize: 4
|
* Tabsize: 4
|
||||||
* Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH
|
* Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
|
||||||
* This Revision: $Id$
|
* This Revision: $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
* Creation Date: 2004-12-29
|
* Creation Date: 2004-12-29
|
||||||
* Tabsize: 4
|
* Tabsize: 4
|
||||||
* Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
|
* Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
|
||||||
* This Revision: $Id: usbdrvasm12.inc 692 2008-11-07 15:07:40Z cs $
|
* This Revision: $Id: usbdrvasm12.inc 483 2008-02-05 15:05:32Z cs $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Do not link this file! Link usbdrvasm.S instead, which includes the
|
/* Do not link this file! Link usbdrvasm.S instead, which includes the
|
||||||
@@ -48,13 +48,10 @@ USB_INTR_VECTOR:
|
|||||||
;----------------------------------------------------------------------------
|
;----------------------------------------------------------------------------
|
||||||
;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K]
|
;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K]
|
||||||
;sync up with J to K edge during sync pattern -- use fastest possible loops
|
;sync up with J to K edge during sync pattern -- use fastest possible loops
|
||||||
;The first part waits at most 1 bit long since we must be in sync pattern.
|
;first part has no timeout because it waits for IDLE or SE1 (== disconnected)
|
||||||
;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to
|
|
||||||
;waitForJ, ensure that this prerequisite is met.
|
|
||||||
waitForJ:
|
waitForJ:
|
||||||
inc YL
|
sbis USBIN, USBMINUS ;1 [40] wait for D- == 1
|
||||||
sbis USBIN, USBMINUS
|
rjmp waitForJ ;2
|
||||||
brne waitForJ ; just make sure we have ANY timeout
|
|
||||||
waitForK:
|
waitForK:
|
||||||
;The following code results in a sampling window of 1/4 bit which meets the spec.
|
;The following code results in a sampling window of 1/4 bit which meets the spec.
|
||||||
sbis USBIN, USBMINUS
|
sbis USBIN, USBMINUS
|
||||||
@@ -72,9 +69,6 @@ waitForK:
|
|||||||
inc YL
|
inc YL
|
||||||
sts usbSofCount, YL
|
sts usbSofCount, YL
|
||||||
#endif /* USB_COUNT_SOF */
|
#endif /* USB_COUNT_SOF */
|
||||||
#ifdef USB_SOF_HOOK
|
|
||||||
USB_SOF_HOOK
|
|
||||||
#endif
|
|
||||||
rjmp sofError
|
rjmp sofError
|
||||||
foundK:
|
foundK:
|
||||||
;{3, 5} after falling D- edge, average delay: 4 cycles [we want 4 for center sampling]
|
;{3, 5} after falling D- edge, average delay: 4 cycles [we want 4 for center sampling]
|
||||||
@@ -256,12 +250,12 @@ macro POP_STANDARD ; 12 cycles
|
|||||||
pop x1
|
pop x1
|
||||||
pop shift
|
pop shift
|
||||||
pop YH
|
pop YH
|
||||||
endm
|
endm
|
||||||
macro POP_RETI ; 5 cycles
|
macro POP_RETI ; 5 cycles
|
||||||
pop YL
|
pop YL
|
||||||
out SREG, YL
|
out SREG, YL
|
||||||
pop YL
|
pop YL
|
||||||
endm
|
endm
|
||||||
|
|
||||||
#include "asmcommon.inc"
|
#include "asmcommon.inc"
|
||||||
|
|
||||||
@@ -269,16 +263,25 @@ macro POP_RETI ; 5 cycles
|
|||||||
; Transmitting data
|
; Transmitting data
|
||||||
;----------------------------------------------------------------------------
|
;----------------------------------------------------------------------------
|
||||||
|
|
||||||
txByteLoop:
|
bitstuff0: ;1 (for branch taken)
|
||||||
txBitloop:
|
eor x1, x4 ;1
|
||||||
stuffN1Delay: ; [03]
|
ldi x2, 0 ;1
|
||||||
ror shift ;[-5] [11] [59]
|
out USBOUT, x1 ;1 <-- out
|
||||||
brcc doExorN1 ;[-4] [60]
|
rjmp didStuff0 ;2 branch back 2 cycles earlier
|
||||||
subi x4, 1 ;[-3]
|
bitstuff1: ;1 (for branch taken)
|
||||||
brne commonN1 ;[-2]
|
eor x1, x4 ;1
|
||||||
lsl shift ;[-1] compensate ror after rjmp stuffDelay
|
rjmp didStuff1 ;2 we know that C is clear, jump back to do OUT and ror 0 into x2
|
||||||
nop ;[00] stuffing consists of just waiting 8 cycles
|
bitstuff2: ;1 (for branch taken)
|
||||||
rjmp stuffN1Delay ;[01] after ror, C bit is reliably clear
|
eor x1, x4 ;1
|
||||||
|
rjmp didStuff2 ;2 jump back 4 cycles earlier and do out and ror 0 into x2
|
||||||
|
bitstuff3: ;1 (for branch taken)
|
||||||
|
eor x1, x4 ;1
|
||||||
|
rjmp didStuff3 ;2 jump back earlier and ror 0 into x2
|
||||||
|
bitstuff4: ;1 (for branch taken)
|
||||||
|
eor x1, x4 ;1
|
||||||
|
ldi x2, 0 ;1
|
||||||
|
out USBOUT, x1 ;1 <-- out
|
||||||
|
rjmp didStuff4 ;2 jump back 2 cycles earlier
|
||||||
|
|
||||||
sendNakAndReti: ;0 [-19] 19 cycles until SOP
|
sendNakAndReti: ;0 [-19] 19 cycles until SOP
|
||||||
ldi x3, USBPID_NAK ;1 [-18]
|
ldi x3, USBPID_NAK ;1 [-18]
|
||||||
@@ -303,91 +306,122 @@ usbSendX3: ;0 [-16]
|
|||||||
;usbSend:
|
;usbSend:
|
||||||
;pointer to data in 'Y'
|
;pointer to data in 'Y'
|
||||||
;number of bytes in 'cnt' -- including sync byte
|
;number of bytes in 'cnt' -- including sync byte
|
||||||
;uses: x1...x2, x4, shift, cnt, Y [x1 = mirror USBOUT, x2 = USBMASK, x4 = bitstuff cnt]
|
;uses: x1...x4, shift, cnt, Y
|
||||||
;Numbers in brackets are time since first bit of sync pattern is sent (start of instruction)
|
;Numbers in brackets are time since first bit of sync pattern is sent
|
||||||
usbSendAndReti:
|
usbSendAndReti: ;0 [-13] timing: 13 cycles until SOP
|
||||||
in x2, USBDDR ;[-12] 12 cycles until SOP
|
in x2, USBDDR ;1 [-12]
|
||||||
ori x2, USBMASK ;[-11]
|
ori x2, USBMASK ;1 [-11]
|
||||||
sbi USBOUT, USBMINUS ;[-10] prepare idle state; D+ and D- must have been 0 (no pullups)
|
sbi USBOUT, USBMINUS;2 [-9] prepare idle state; D+ and D- must have been 0 (no pullups)
|
||||||
out USBDDR, x2 ;[-8] <--- acquire bus
|
in x1, USBOUT ;1 [-8] port mirror for tx loop
|
||||||
in x1, USBOUT ;[-7] port mirror for tx loop
|
out USBDDR, x2 ;1 [-7] <- acquire bus
|
||||||
ldi shift, 0x40 ;[-6] sync byte is first byte sent (we enter loop after ror)
|
; need not init x2 (bitstuff history) because sync starts with 0
|
||||||
ldi x2, USBMASK ;[-5]
|
push x4 ;2 [-5]
|
||||||
push x4 ;[-4]
|
ldi x4, USBMASK ;1 [-4] exor mask
|
||||||
doExorN1:
|
ldi shift, 0x80 ;1 [-3] sync byte is first byte sent
|
||||||
eor x1, x2 ;[-2] [06] [62]
|
txLoop: ; [62]
|
||||||
ldi x4, 6 ;[-1] [07] [63]
|
sbrs shift, 0 ;1 [-2] [62]
|
||||||
commonN1:
|
eor x1, x4 ;1 [-1] [63]
|
||||||
stuffN2Delay:
|
out USBOUT, x1 ;1 [0] <-- out bit 0
|
||||||
out USBOUT, x1 ;[00] [08] [64] <--- set bit
|
ror shift ;1 [1]
|
||||||
ror shift ;[01]
|
ror x2 ;1 [2]
|
||||||
brcc doExorN2 ;[02]
|
didStuff0:
|
||||||
subi x4, 1 ;[03]
|
cpi x2, 0xfc ;1 [3]
|
||||||
brne commonN2 ;[04]
|
brsh bitstuff0 ;1 [4]
|
||||||
lsl shift ;[05] compensate ror after rjmp stuffDelay
|
sbrs shift, 0 ;1 [5]
|
||||||
rjmp stuffN2Delay ;[06] after ror, C bit is reliably clear
|
eor x1, x4 ;1 [6]
|
||||||
doExorN2:
|
ror shift ;1 [7]
|
||||||
eor x1, x2 ;[04] [12]
|
didStuff1:
|
||||||
ldi x4, 6 ;[05] [13]
|
out USBOUT, x1 ;1 [8] <-- out bit 1
|
||||||
commonN2:
|
ror x2 ;1 [9]
|
||||||
nop ;[06] [14]
|
cpi x2, 0xfc ;1 [10]
|
||||||
subi cnt, 171 ;[07] [15] trick: (3 * 171) & 0xff = 1
|
brsh bitstuff1 ;1 [11]
|
||||||
out USBOUT, x1 ;[08] [16] <--- set bit
|
sbrs shift, 0 ;1 [12]
|
||||||
brcs txBitloop ;[09] [25] [41]
|
eor x1, x4 ;1 [13]
|
||||||
|
ror shift ;1 [14]
|
||||||
stuff6Delay:
|
didStuff2:
|
||||||
ror shift ;[42] [50]
|
ror x2 ;1 [15]
|
||||||
brcc doExor6 ;[43]
|
out USBOUT, x1 ;1 [16] <-- out bit 2
|
||||||
subi x4, 1 ;[44]
|
cpi x2, 0xfc ;1 [17]
|
||||||
brne common6 ;[45]
|
brsh bitstuff2 ;1 [18]
|
||||||
lsl shift ;[46] compensate ror after rjmp stuffDelay
|
sbrs shift, 0 ;1 [19]
|
||||||
nop ;[47] stuffing consists of just waiting 8 cycles
|
eor x1, x4 ;1 [20]
|
||||||
rjmp stuff6Delay ;[48] after ror, C bit is reliably clear
|
ror shift ;1 [21]
|
||||||
doExor6:
|
didStuff3:
|
||||||
eor x1, x2 ;[45] [53]
|
ror x2 ;1 [22]
|
||||||
ldi x4, 6 ;[46]
|
cpi x2, 0xfc ;1 [23]
|
||||||
common6:
|
out USBOUT, x1 ;1 [24] <-- out bit 3
|
||||||
stuff7Delay:
|
brsh bitstuff3 ;1 [25]
|
||||||
ror shift ;[47] [55]
|
nop2 ;2 [27]
|
||||||
out USBOUT, x1 ;[48] <--- set bit
|
ld x3, y+ ;2 [29]
|
||||||
brcc doExor7 ;[49]
|
sbrs shift, 0 ;1 [30]
|
||||||
subi x4, 1 ;[50]
|
eor x1, x4 ;1 [31]
|
||||||
brne common7 ;[51]
|
out USBOUT, x1 ;1 [32] <-- out bit 4
|
||||||
lsl shift ;[52] compensate ror after rjmp stuffDelay
|
ror shift ;1 [33]
|
||||||
rjmp stuff7Delay ;[53] after ror, C bit is reliably clear
|
ror x2 ;1 [34]
|
||||||
doExor7:
|
didStuff4:
|
||||||
eor x1, x2 ;[51] [59]
|
cpi x2, 0xfc ;1 [35]
|
||||||
ldi x4, 6 ;[52]
|
brsh bitstuff4 ;1 [36]
|
||||||
common7:
|
sbrs shift, 0 ;1 [37]
|
||||||
ld shift, y+ ;[53]
|
eor x1, x4 ;1 [38]
|
||||||
tst cnt ;[55]
|
ror shift ;1 [39]
|
||||||
out USBOUT, x1 ;[56] <--- set bit
|
didStuff5:
|
||||||
brne txByteLoop ;[57]
|
out USBOUT, x1 ;1 [40] <-- out bit 5
|
||||||
|
ror x2 ;1 [41]
|
||||||
|
cpi x2, 0xfc ;1 [42]
|
||||||
|
brsh bitstuff5 ;1 [43]
|
||||||
|
sbrs shift, 0 ;1 [44]
|
||||||
|
eor x1, x4 ;1 [45]
|
||||||
|
ror shift ;1 [46]
|
||||||
|
didStuff6:
|
||||||
|
ror x2 ;1 [47]
|
||||||
|
out USBOUT, x1 ;1 [48] <-- out bit 6
|
||||||
|
cpi x2, 0xfc ;1 [49]
|
||||||
|
brsh bitstuff6 ;1 [50]
|
||||||
|
sbrs shift, 0 ;1 [51]
|
||||||
|
eor x1, x4 ;1 [52]
|
||||||
|
ror shift ;1 [53]
|
||||||
|
didStuff7:
|
||||||
|
ror x2 ;1 [54]
|
||||||
|
cpi x2, 0xfc ;1 [55]
|
||||||
|
out USBOUT, x1 ;1 [56] <-- out bit 7
|
||||||
|
brsh bitstuff7 ;1 [57]
|
||||||
|
mov shift, x3 ;1 [58]
|
||||||
|
dec cnt ;1 [59]
|
||||||
|
brne txLoop ;1/2 [60/61]
|
||||||
;make SE0:
|
;make SE0:
|
||||||
cbr x1, USBMASK ;[58] prepare SE0 [spec says EOP may be 15 to 18 cycles]
|
cbr x1, USBMASK ;1 [61] prepare SE0 [spec says EOP may be 15 to 18 cycles]
|
||||||
lds x2, usbNewDeviceAddr;[59]
|
pop x4 ;2 [63]
|
||||||
lsl x2 ;[61] we compare with left shifted address
|
;brackets are cycles from start of SE0 now
|
||||||
subi YL, 2 + 20 ;[62] Only assign address on data packets, not ACK/NAK in x3
|
out USBOUT, x1 ;1 [0] <-- out SE0 -- from now 2 bits = 16 cycles until bus idle
|
||||||
sbci YH, 0 ;[63]
|
|
||||||
out USBOUT, x1 ;[00] <-- out SE0 -- from now 2 bits = 16 cycles until bus idle
|
|
||||||
;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm:
|
;2006-03-06: moved transfer of new address to usbDeviceAddr from C-Code to asm:
|
||||||
;set address only after data packet was sent, not after handshake
|
;set address only after data packet was sent, not after handshake
|
||||||
breq skipAddrAssign ;[01]
|
lds x2, usbNewDeviceAddr;2 [2]
|
||||||
sts usbDeviceAddr, x2 ; if not skipped: SE0 is one cycle longer
|
lsl x2; ;1 [3] we compare with left shifted address
|
||||||
|
subi YL, 20 + 2 ;1 [4] Only assign address on data packets, not ACK/NAK in x3
|
||||||
|
sbci YH, 0 ;1 [5]
|
||||||
|
breq skipAddrAssign ;2 [7]
|
||||||
|
sts usbDeviceAddr, x2; if not skipped: SE0 is one cycle longer
|
||||||
skipAddrAssign:
|
skipAddrAssign:
|
||||||
;end of usbDeviceAddress transfer
|
;end of usbDeviceAddress transfer
|
||||||
ldi x2, 1<<USB_INTR_PENDING_BIT;[03] int0 occurred during TX -- clear pending flag
|
ldi x2, 1<<USB_INTR_PENDING_BIT;1 [8] int0 occurred during TX -- clear pending flag
|
||||||
USB_STORE_PENDING(x2) ;[04]
|
USB_STORE_PENDING(x2) ;1 [9]
|
||||||
ori x1, USBIDLE ;[05]
|
ori x1, USBIDLE ;1 [10]
|
||||||
in x2, USBDDR ;[06]
|
in x2, USBDDR ;1 [11]
|
||||||
cbr x2, USBMASK ;[07] set both pins to input
|
cbr x2, USBMASK ;1 [12] set both pins to input
|
||||||
mov x3, x1 ;[08]
|
mov x3, x1 ;1 [13]
|
||||||
cbr x3, USBMASK ;[09] configure no pullup on both pins
|
cbr x3, USBMASK ;1 [14] configure no pullup on both pins
|
||||||
pop x4 ;[10]
|
out USBOUT, x1 ;1 [15] <-- out J (idle) -- end of SE0 (EOP signal)
|
||||||
nop2 ;[12]
|
out USBDDR, x2 ;1 [16] <-- release bus now
|
||||||
nop2 ;[14]
|
out USBOUT, x3 ;1 [17] <-- ensure no pull-up resistors are active
|
||||||
out USBOUT, x1 ;[16] <-- out J (idle) -- end of SE0 (EOP signal)
|
|
||||||
out USBDDR, x2 ;[17] <-- release bus now
|
|
||||||
out USBOUT, x3 ;[18] <-- ensure no pull-up resistors are active
|
|
||||||
rjmp doReturn
|
rjmp doReturn
|
||||||
|
|
||||||
|
bitstuff5: ;1 (for branch taken)
|
||||||
|
eor x1, x4 ;1
|
||||||
|
rjmp didStuff5 ;2 same trick as in bitstuff1...
|
||||||
|
bitstuff6: ;1 (for branch taken)
|
||||||
|
eor x1, x4 ;1
|
||||||
|
rjmp didStuff6 ;2 same trick as above...
|
||||||
|
bitstuff7: ;1 (for branch taken)
|
||||||
|
eor x1, x4 ;1
|
||||||
|
rjmp didStuff7 ;2 same trick as above...
|
||||||
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
/* Name: usbdrvasm128.inc
|
/* Name: usbdrvasm128.inc
|
||||||
* Project: AVR USB driver
|
* Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
|
||||||
* Author: Christian Starkjohann
|
* Author: Christian Starkjohann
|
||||||
* Creation Date: 2008-10-11
|
* Creation Date: 2008-10-11
|
||||||
* Tabsize: 4
|
* Tabsize: 4
|
||||||
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
|
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
||||||
* This Revision: $Id: usbdrvasm128.inc 692 2008-11-07 15:07:40Z cs $
|
* This Revision: $Id: usbdrvasm128.inc 740 2009-04-13 18:23:31Z cs $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Do not link this file! Link usbdrvasm.S instead, which includes the
|
/* Do not link this file! Link usbdrvasm.S instead, which includes the
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
* Creation Date: 2007-08-06
|
* Creation Date: 2007-08-06
|
||||||
* Tabsize: 4
|
* Tabsize: 4
|
||||||
* Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
|
* Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
|
||||||
* Revision: $Id: usbdrvasm15.inc 692 2008-11-07 15:07:40Z cs $
|
* Revision: $Id: usbdrvasm15.inc 607 2008-05-13 15:57:28Z cs $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Do not link this file! Link usbdrvasm.S instead, which includes the
|
/* Do not link this file! Link usbdrvasm.S instead, which includes the
|
||||||
@@ -43,13 +43,11 @@ USB_INTR_VECTOR:
|
|||||||
;
|
;
|
||||||
; sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K]
|
; sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K]
|
||||||
; sync up with J to K edge during sync pattern -- use fastest possible loops
|
; sync up with J to K edge during sync pattern -- use fastest possible loops
|
||||||
;The first part waits at most 1 bit long since we must be in sync pattern.
|
; first part has no timeout because it waits for IDLE or SE1 (== disconnected)
|
||||||
;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to
|
;-------------------------------------------------------------------------------
|
||||||
;waitForJ, ensure that this prerequisite is met.
|
waitForJ: ;-
|
||||||
waitForJ:
|
sbis USBIN, USBMINUS ;1 <-- sample: wait for D- == 1
|
||||||
inc YL
|
rjmp waitForJ ;2
|
||||||
sbis USBIN, USBMINUS
|
|
||||||
brne waitForJ ; just make sure we have ANY timeout
|
|
||||||
;-------------------------------------------------------------------------------
|
;-------------------------------------------------------------------------------
|
||||||
; The following code results in a sampling window of < 1/4 bit
|
; The following code results in a sampling window of < 1/4 bit
|
||||||
; which meets the spec.
|
; which meets the spec.
|
||||||
@@ -72,9 +70,6 @@ waitForK: ;-
|
|||||||
inc YL
|
inc YL
|
||||||
sts usbSofCount, YL
|
sts usbSofCount, YL
|
||||||
#endif /* USB_COUNT_SOF */
|
#endif /* USB_COUNT_SOF */
|
||||||
#ifdef USB_SOF_HOOK
|
|
||||||
USB_SOF_HOOK
|
|
||||||
#endif
|
|
||||||
rjmp sofError
|
rjmp sofError
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
; {3, 5} after falling D- edge, average delay: 4 cycles [we want 5 for
|
; {3, 5} after falling D- edge, average delay: 4 cycles [we want 5 for
|
||||||
@@ -294,12 +289,12 @@ macro POP_STANDARD ; 16 cycles
|
|||||||
pop x1
|
pop x1
|
||||||
pop shift
|
pop shift
|
||||||
pop YH
|
pop YH
|
||||||
endm
|
endm
|
||||||
macro POP_RETI ; 5 cycles
|
macro POP_RETI ; 5 cycles
|
||||||
pop YL
|
pop YL
|
||||||
out SREG, YL
|
out SREG, YL
|
||||||
pop YL
|
pop YL
|
||||||
endm
|
endm
|
||||||
|
|
||||||
#include "asmcommon.inc"
|
#include "asmcommon.inc"
|
||||||
|
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
* Creation Date: 2007-06-15
|
* Creation Date: 2007-06-15
|
||||||
* Tabsize: 4
|
* Tabsize: 4
|
||||||
* Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
|
* Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
|
||||||
* Revision: $Id: usbdrvasm16.inc 692 2008-11-07 15:07:40Z cs $
|
* Revision: $Id: usbdrvasm16.inc 607 2008-05-13 15:57:28Z cs $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Do not link this file! Link usbdrvasm.S instead, which includes the
|
/* Do not link this file! Link usbdrvasm.S instead, which includes the
|
||||||
@@ -41,13 +41,10 @@ USB_INTR_VECTOR:
|
|||||||
;----------------------------------------------------------------------------
|
;----------------------------------------------------------------------------
|
||||||
;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K]
|
;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K]
|
||||||
;sync up with J to K edge during sync pattern -- use fastest possible loops
|
;sync up with J to K edge during sync pattern -- use fastest possible loops
|
||||||
;The first part waits at most 1 bit long since we must be in sync pattern.
|
;first part has no timeout because it waits for IDLE or SE1 (== disconnected)
|
||||||
;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to
|
|
||||||
;waitForJ, ensure that this prerequisite is met.
|
|
||||||
waitForJ:
|
waitForJ:
|
||||||
inc YL
|
sbis USBIN, USBMINUS ;[-18] wait for D- == 1
|
||||||
sbis USBIN, USBMINUS
|
rjmp waitForJ
|
||||||
brne waitForJ ; just make sure we have ANY timeout
|
|
||||||
waitForK:
|
waitForK:
|
||||||
;The following code results in a sampling window of < 1/4 bit which meets the spec.
|
;The following code results in a sampling window of < 1/4 bit which meets the spec.
|
||||||
sbis USBIN, USBMINUS ;[-15]
|
sbis USBIN, USBMINUS ;[-15]
|
||||||
@@ -67,9 +64,6 @@ waitForK:
|
|||||||
inc YL
|
inc YL
|
||||||
sts usbSofCount, YL
|
sts usbSofCount, YL
|
||||||
#endif /* USB_COUNT_SOF */
|
#endif /* USB_COUNT_SOF */
|
||||||
#ifdef USB_SOF_HOOK
|
|
||||||
USB_SOF_HOOK
|
|
||||||
#endif
|
|
||||||
rjmp sofError
|
rjmp sofError
|
||||||
foundK: ;[-12]
|
foundK: ;[-12]
|
||||||
;{3, 5} after falling D- edge, average delay: 4 cycles [we want 5 for center sampling]
|
;{3, 5} after falling D- edge, average delay: 4 cycles [we want 5 for center sampling]
|
||||||
@@ -214,13 +208,13 @@ macro POP_STANDARD ; 14 cycles
|
|||||||
pop x1
|
pop x1
|
||||||
pop shift
|
pop shift
|
||||||
pop bitcnt
|
pop bitcnt
|
||||||
endm
|
endm
|
||||||
macro POP_RETI ; 7 cycles
|
macro POP_RETI ; 7 cycles
|
||||||
pop YH
|
pop YH
|
||||||
pop YL
|
pop YL
|
||||||
out SREG, YL
|
out SREG, YL
|
||||||
pop YL
|
pop YL
|
||||||
endm
|
endm
|
||||||
|
|
||||||
#include "asmcommon.inc"
|
#include "asmcommon.inc"
|
||||||
|
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
* Creation Date: 2007-04-22
|
* Creation Date: 2007-04-22
|
||||||
* Tabsize: 4
|
* Tabsize: 4
|
||||||
* Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
|
* Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
|
||||||
* Revision: $Id: usbdrvasm165.inc 692 2008-11-07 15:07:40Z cs $
|
* Revision: $Id: usbdrvasm165.inc 607 2008-05-13 15:57:28Z cs $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Do not link this file! Link usbdrvasm.S instead, which includes the
|
/* Do not link this file! Link usbdrvasm.S instead, which includes the
|
||||||
@@ -46,13 +46,10 @@ USB_INTR_VECTOR:
|
|||||||
;----------------------------------------------------------------------------
|
;----------------------------------------------------------------------------
|
||||||
;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K]
|
;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K]
|
||||||
;sync up with J to K edge during sync pattern -- use fastest possible loops
|
;sync up with J to K edge during sync pattern -- use fastest possible loops
|
||||||
;The first part waits at most 1 bit long since we must be in sync pattern.
|
;first part has no timeout because it waits for IDLE or SE1 (== disconnected)
|
||||||
;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to
|
|
||||||
;waitForJ, ensure that this prerequisite is met.
|
|
||||||
waitForJ:
|
waitForJ:
|
||||||
inc YL
|
sbis USBIN, USBMINUS ;[-18] wait for D- == 1
|
||||||
sbis USBIN, USBMINUS
|
rjmp waitForJ
|
||||||
brne waitForJ ; just make sure we have ANY timeout
|
|
||||||
waitForK:
|
waitForK:
|
||||||
;The following code results in a sampling window of < 1/4 bit which meets the spec.
|
;The following code results in a sampling window of < 1/4 bit which meets the spec.
|
||||||
sbis USBIN, USBMINUS ;[-15]
|
sbis USBIN, USBMINUS ;[-15]
|
||||||
@@ -72,9 +69,6 @@ waitForK:
|
|||||||
inc YL
|
inc YL
|
||||||
sts usbSofCount, YL
|
sts usbSofCount, YL
|
||||||
#endif /* USB_COUNT_SOF */
|
#endif /* USB_COUNT_SOF */
|
||||||
#ifdef USB_SOF_HOOK
|
|
||||||
USB_SOF_HOOK
|
|
||||||
#endif
|
|
||||||
rjmp sofError
|
rjmp sofError
|
||||||
foundK: ;[-12]
|
foundK: ;[-12]
|
||||||
;{3, 5} after falling D- edge, average delay: 4 cycles [we want 5 for center sampling]
|
;{3, 5} after falling D- edge, average delay: 4 cycles [we want 5 for center sampling]
|
||||||
@@ -340,12 +334,12 @@ macro POP_STANDARD ; 16 cycles
|
|||||||
pop shift
|
pop shift
|
||||||
pop YH
|
pop YH
|
||||||
pop r0
|
pop r0
|
||||||
endm
|
endm
|
||||||
macro POP_RETI ; 5 cycles
|
macro POP_RETI ; 5 cycles
|
||||||
pop YL
|
pop YL
|
||||||
out SREG, YL
|
out SREG, YL
|
||||||
pop YL
|
pop YL
|
||||||
endm
|
endm
|
||||||
|
|
||||||
#include "asmcommon.inc"
|
#include "asmcommon.inc"
|
||||||
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
/* Name: usbdrvasm18.inc
|
/* Name: usbdrvasm18.inc
|
||||||
* Project: AVR USB driver
|
* Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
|
||||||
* Author: Lukas Schrittwieser (based on 20 MHz usbdrvasm20.inc by Jeroen Benschop)
|
* Author: Lukas Schrittwieser (based on 20 MHz usbdrvasm20.inc by Jeroen Benschop)
|
||||||
* Creation Date: 2009-01-20
|
* Creation Date: 2009-01-20
|
||||||
* Tabsize: 4
|
* Tabsize: 4
|
||||||
* Copyright: (c) 2008 by Lukas Schrittwieser and OBJECTIVE DEVELOPMENT Software GmbH
|
* Copyright: (c) 2008 by Lukas Schrittwieser and OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
||||||
* Revision: $Id: usbdrvasm18-crc.inc 734 2009-03-23 11:10:07Z cs $
|
* Revision: $Id: usbdrvasm18-crc.inc 740 2009-04-13 18:23:31Z cs $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Do not link this file! Link usbdrvasm.S instead, which includes the
|
/* Do not link this file! Link usbdrvasm.S instead, which includes the
|
||||||
@@ -5,8 +5,8 @@
|
|||||||
* Creation Date: 2008-03-05
|
* Creation Date: 2008-03-05
|
||||||
* Tabsize: 4
|
* Tabsize: 4
|
||||||
* Copyright: (c) 2008 by Jeroen Benschop and OBJECTIVE DEVELOPMENT Software GmbH
|
* Copyright: (c) 2008 by Jeroen Benschop and OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
|
||||||
* Revision: $Id: usbdrvasm20.inc 692 2008-11-07 15:07:40Z cs $
|
* Revision: $Id: usbdrvasm20.inc 607 2008-05-13 15:57:28Z cs $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Do not link this file! Link usbdrvasm.S instead, which includes the
|
/* Do not link this file! Link usbdrvasm.S instead, which includes the
|
||||||
@@ -57,13 +57,10 @@ USB_INTR_VECTOR:
|
|||||||
;----------------------------------------------------------------------------
|
;----------------------------------------------------------------------------
|
||||||
;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K]
|
;sync byte (D-) pattern LSb to MSb: 01010100 [1 = idle = J, 0 = K]
|
||||||
;sync up with J to K edge during sync pattern -- use fastest possible loops
|
;sync up with J to K edge during sync pattern -- use fastest possible loops
|
||||||
;The first part waits at most 1 bit long since we must be in sync pattern.
|
;first part has no timeout because it waits for IDLE or SE1 (== disconnected)
|
||||||
;YL is guarenteed to be < 0x80 because I flag is clear. When we jump to
|
|
||||||
;waitForJ, ensure that this prerequisite is met.
|
|
||||||
waitForJ:
|
waitForJ:
|
||||||
inc YL
|
sbis USBIN, USBMINUS ;[-21] wait for D- == 1
|
||||||
sbis USBIN, USBMINUS
|
rjmp waitForJ
|
||||||
brne waitForJ ; just make sure we have ANY timeout
|
|
||||||
waitForK:
|
waitForK:
|
||||||
;The following code results in a sampling window of < 1/4 bit which meets the spec.
|
;The following code results in a sampling window of < 1/4 bit which meets the spec.
|
||||||
sbis USBIN, USBMINUS ;[-19]
|
sbis USBIN, USBMINUS ;[-19]
|
||||||
@@ -89,9 +86,6 @@ waitForK:
|
|||||||
inc YL
|
inc YL
|
||||||
sts usbSofCount, YL
|
sts usbSofCount, YL
|
||||||
#endif /* USB_COUNT_SOF */
|
#endif /* USB_COUNT_SOF */
|
||||||
#ifdef USB_SOF_HOOK
|
|
||||||
USB_SOF_HOOK
|
|
||||||
#endif
|
|
||||||
rjmp sofError
|
rjmp sofError
|
||||||
foundK: ;[-16]
|
foundK: ;[-16]
|
||||||
;{3, 5} after falling D- edge, average delay: 4 cycles
|
;{3, 5} after falling D- edge, average delay: 4 cycles
|
||||||
@@ -238,13 +232,13 @@ macro POP_STANDARD ; 14 cycles
|
|||||||
pop x1
|
pop x1
|
||||||
pop shift
|
pop shift
|
||||||
pop bitcnt
|
pop bitcnt
|
||||||
endm
|
endm
|
||||||
macro POP_RETI ; 7 cycles
|
macro POP_RETI ; 7 cycles
|
||||||
pop YH
|
pop YH
|
||||||
pop YL
|
pop YL
|
||||||
out SREG, YL
|
out SREG, YL
|
||||||
pop YL
|
pop YL
|
||||||
endm
|
endm
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
/* Name: usbportability.h
|
/* Name: usbportability.h
|
||||||
* Project: AVR USB driver
|
* Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
|
||||||
* Author: Christian Starkjohann
|
* Author: Christian Starkjohann
|
||||||
* Creation Date: 2008-06-17
|
* Creation Date: 2008-06-17
|
||||||
* Tabsize: 4
|
* Tabsize: 4
|
||||||
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
|
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
||||||
* This Revision: $Id: usbportability.h 692 2008-11-07 15:07:40Z cs $
|
* This Revision: $Id: usbportability.h 740 2009-04-13 18:23:31Z cs $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
117
avr/usbload/Makefile
Normal file
117
avr/usbload/Makefile
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
# =====================================================================================
|
||||||
|
#
|
||||||
|
# ________ .__ __ ________ ____ ________
|
||||||
|
# \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
# / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
# / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
# \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
# \__> \/ \/ \/ \/ \/
|
||||||
|
# www.optixx.org
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Version: 1.0
|
||||||
|
# Created: 07/21/2009 03:32:16 PM
|
||||||
|
# Author: david@optixx.org
|
||||||
|
# Based on: custom-class, a basic USB example
|
||||||
|
# Author: Christian Starkjohann
|
||||||
|
# =====================================================================================
|
||||||
|
|
||||||
|
DEBUG = 1
|
||||||
|
TTY = /dev/tty.PL2303-00002126
|
||||||
|
DEVICE = atmega644
|
||||||
|
F_CPU = 20000000
|
||||||
|
TARGET = main
|
||||||
|
AVRDUDE = avrdude -c usbasp -p $(DEVICE)
|
||||||
|
SIZE = avr-size
|
||||||
|
BOOT_ROM01 = ../../roms/qd16boot01.smc
|
||||||
|
BOOT_ROM02 = ../../roms/qd16boot02.smc
|
||||||
|
CONVERT_RLE = ../../scripts/conv_rle.py
|
||||||
|
CONVERT_ZIP = ../../scripts/conv_zip.py
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ifeq ($(DEBUG),1)
|
||||||
|
LDFLAGS =-Wl,-u,vfprintf
|
||||||
|
CFLAGS =-Iusbdrv -I. -DDEBUG_LEVEL=0
|
||||||
|
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o \
|
||||||
|
main.o usb_bulk.o uart.o fifo.o sram.o crc.o debug.o \
|
||||||
|
dump.o timer.o watchdog.o rle.c loader.o info.o shared_memory.o \
|
||||||
|
system.o pwm.o util.o shell.o irq.o command.o testing.o inflate.o neginf/neginf.o
|
||||||
|
else
|
||||||
|
LDFLAGS =-Wl,-u
|
||||||
|
CFLAGS =-Iusbdrv -I. -DDEBUG_LEVEL=0 -DNO_DEBUG -DNO_INFO
|
||||||
|
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o usb_bulk.o \
|
||||||
|
sram.o crc.o debug.o dump.o rle.c loader.o \
|
||||||
|
system.o util.o info.o shared_memory.o command.o irq.o \
|
||||||
|
pwm.o inflate.o neginf/neginf.o
|
||||||
|
endif
|
||||||
|
|
||||||
|
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# Fuse values for particular devices
|
||||||
|
##############################################################################
|
||||||
|
# http://www.engbedded.com/fusecalc/
|
||||||
|
FUSE_L = 0xf7
|
||||||
|
FUSE_H = 0xda
|
||||||
|
|
||||||
|
all: hex
|
||||||
|
|
||||||
|
help:
|
||||||
|
@echo "This Makefile has no default rule. Use one of the following:"
|
||||||
|
@echo "make hex ....... to build main.hex"
|
||||||
|
@echo "make program ... to flash fuses and firmware"
|
||||||
|
@echo "make fuse ...... to flash the fuses"
|
||||||
|
@echo "make flash ..... to flash the firmware (use this on metaboard)"
|
||||||
|
@echo "make clean ..... to delete objects and hex file"
|
||||||
|
|
||||||
|
hex: main.hex
|
||||||
|
@echo "$(TARGET) compiled for: $(DEVICE)"
|
||||||
|
@./checksize $(TARGET).elf
|
||||||
|
|
||||||
|
program: flash fuse
|
||||||
|
|
||||||
|
# rule for programming fuse bits:
|
||||||
|
fuse:
|
||||||
|
@[ "$(FUSE_H)" != "" -a "$(FUSE_L)" != "" ] || \
|
||||||
|
{ echo "*** Edit Makefile and choose values for FUSE_L and FUSE_H!"; exit 1; }
|
||||||
|
$(AVRDUDE) -U hfuse:w:$(FUSE_H):m -U lfuse:w:$(FUSE_L):m
|
||||||
|
|
||||||
|
flash: main.hex
|
||||||
|
$(AVRDUDE) -U flash:w:main.hex:i
|
||||||
|
|
||||||
|
loader01:
|
||||||
|
python $(CONVERT_RLE) $(BOOT_ROM01)
|
||||||
|
|
||||||
|
loader02:
|
||||||
|
python $(CONVERT_ZIP) $(BOOT_ROM02)
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(COMPILE) -c $< -o $@
|
||||||
|
|
||||||
|
.S.o:
|
||||||
|
$(COMPILE) -x assembler-with-cpp -c $< -o $@
|
||||||
|
|
||||||
|
.c.s:
|
||||||
|
$(COMPILE) -S $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
usbdrv:
|
||||||
|
cp -r ../../../usbdrv .
|
||||||
|
|
||||||
|
main.elf: usbdrv $(OBJECTS) # usbdrv dependency only needed because we copy it
|
||||||
|
$(COMPILE) -o main.elf $(OBJECTS) $(LDFLAGS)
|
||||||
|
|
||||||
|
main.hex: main.elf
|
||||||
|
rm -f main.hex main.eep.hex
|
||||||
|
avr-objcopy -j .text -j .data -O ihex main.elf main.hex
|
||||||
|
avr-size main.hex
|
||||||
|
|
||||||
|
disasm: main.elf
|
||||||
|
avr-objdump -d main.elf
|
||||||
|
|
||||||
|
cpp:
|
||||||
|
$(COMPILE) -E main.c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s neginf/*.o
|
||||||
19
avr/usbload/Makefile.test
Normal file
19
avr/usbload/Makefile.test
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
MD5=md5
|
||||||
|
|
||||||
|
all:
|
||||||
|
gcc -c loader_test.c
|
||||||
|
gcc -c inflate.c
|
||||||
|
gcc -c neginf/neginf.c
|
||||||
|
gcc -c inflate_test.c
|
||||||
|
gcc -c ringbuffer.c
|
||||||
|
gcc -o inflate_test inflate.o neginf.o inflate_test.o loader_test.o ringbuffer.o
|
||||||
|
loader:
|
||||||
|
python ../../scripts/conv_zip_test.py ../../roms/qd16boot02_half.smc
|
||||||
|
|
||||||
|
test:
|
||||||
|
./inflate_test
|
||||||
|
@$(MD5) out.smc
|
||||||
|
@$(MD5) out_ref.smc
|
||||||
|
@$(MD5) ../../roms/qd16boot02_half.smc
|
||||||
|
|
||||||
35
avr/usbload/checksize
Executable file
35
avr/usbload/checksize
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Name: checksize
|
||||||
|
# Project: PowerSwitch/AVR-USB
|
||||||
|
# Author: Christian Starkjohann
|
||||||
|
# Creation Date: 2004-12-29
|
||||||
|
# Tabsize: 4
|
||||||
|
# Copyright: (c) 2005 OBJECTIVE DEVELOPMENT Software GmbH.
|
||||||
|
# Revision: $:Id: checksize 83 2006-01-05 22:20:53Z cs $
|
||||||
|
|
||||||
|
error=0
|
||||||
|
codelimit=61440 # default value
|
||||||
|
datalimit=4064 # default value; leave 32 bytes for stack
|
||||||
|
|
||||||
|
if [ $# -gt 1 ]; then
|
||||||
|
codelimit="$2"
|
||||||
|
fi
|
||||||
|
if [ $# -gt 2 ]; then
|
||||||
|
datalimit="$3"
|
||||||
|
fi
|
||||||
|
|
||||||
|
set -- `avr-size -d "$1" | awk '/[0-9]/ {print $1 + $2, $2 + $3, $2}'`
|
||||||
|
if [ $1 -gt $codelimit ]; then
|
||||||
|
echo "*** code size $1 exceeds limit of $codelimit"
|
||||||
|
error=1
|
||||||
|
else
|
||||||
|
echo "ROM: $1 bytes (data=$3)"
|
||||||
|
fi
|
||||||
|
if [ $2 -gt $datalimit ]; then
|
||||||
|
echo "*** data size $2 exceeds limit of $datalimit"
|
||||||
|
error=1
|
||||||
|
else
|
||||||
|
echo "RAM: $2 bytes"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit $error
|
||||||
120
avr/usbload/command.c
Normal file
120
avr/usbload/command.c
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "requests.h"
|
||||||
|
#include "sram.h"
|
||||||
|
#include "info.h"
|
||||||
|
#include "irq.h"
|
||||||
|
#include "usbdrv.h"
|
||||||
|
#include "rle.h"
|
||||||
|
#include "loader.h"
|
||||||
|
#include "system.h"
|
||||||
|
|
||||||
|
#include "neginf/neginf.h"
|
||||||
|
#include "inflate.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern usb_transaction_t usb_trans;
|
||||||
|
extern system_t system;
|
||||||
|
|
||||||
|
extern const char *_rom[];
|
||||||
|
extern const char _rom01[];
|
||||||
|
extern const int _rom_size[];
|
||||||
|
|
||||||
|
void usb_connect()
|
||||||
|
{
|
||||||
|
uint8_t i = 0;
|
||||||
|
info_P(PSTR("USB init\n"));
|
||||||
|
usbDeviceDisconnect(); /* enforce re-enumeration, do this while */
|
||||||
|
cli();
|
||||||
|
info_P(PSTR("USB disconnect\n"));
|
||||||
|
i = 10;
|
||||||
|
while (--i) { /* fake USB disconnect for > 250 ms */
|
||||||
|
_delay_ms(50);
|
||||||
|
}
|
||||||
|
led_on();
|
||||||
|
usbDeviceConnect();
|
||||||
|
info_P(PSTR("USB connect\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void boot_startup_rom(uint16_t init_delay)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
uint8_t c;
|
||||||
|
uint16_t j;
|
||||||
|
uint32_t addr = 0x000000;
|
||||||
|
PGM_VOID_P p_addr;
|
||||||
|
|
||||||
|
info_P(PSTR("Fetch loader rom\n"));
|
||||||
|
|
||||||
|
system_set_bus_avr();
|
||||||
|
snes_irq_lo();
|
||||||
|
system_snes_irq_off();
|
||||||
|
system_set_rom_lorom();
|
||||||
|
|
||||||
|
|
||||||
|
inflate_init();
|
||||||
|
for (i=0; i<ROM_BUFFER_CNT; i++){
|
||||||
|
p_addr = _rom[i];
|
||||||
|
printf("idx: %i %lx\n",i,p_addr);
|
||||||
|
for (j=0; j<_rom_size[i]; j++){
|
||||||
|
//rle_decode(_rom[i], _rom_size[i], addr);
|
||||||
|
c = pgm_read_byte((PGM_VOID_P)p_addr++);
|
||||||
|
printf("%02x ",c);
|
||||||
|
neginf_process_byte(c);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
info_P(PSTR("\n"));
|
||||||
|
|
||||||
|
#if DO_CRC_CHECK_LOADER
|
||||||
|
dump_memory(0x010000 - 0x100, 0x010000);
|
||||||
|
uint16_t crc;
|
||||||
|
crc = crc_check_bulk_memory((uint32_t)0x000000,0x010000, 0x010000);
|
||||||
|
info(PSTR("crc=%x\n"),crc);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
snes_irq_lo();
|
||||||
|
system_snes_irq_off();
|
||||||
|
system_set_rom_hirom();
|
||||||
|
system_set_wr_disable();
|
||||||
|
system_set_bus_snes();
|
||||||
|
|
||||||
|
|
||||||
|
system_send_snes_reset();
|
||||||
|
_delay_ms(init_delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
void banner(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void transaction_status(){
|
||||||
|
}
|
||||||
|
|
||||||
31
avr/usbload/command.h
Normal file
31
avr/usbload/command.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __COMMAND_H__
|
||||||
|
#define __COMMAND_H__
|
||||||
|
|
||||||
|
void usb_connect();
|
||||||
|
void boot_startup_rom(uint16_t init_delay);
|
||||||
|
void banner();
|
||||||
|
void transaction_status();
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# Name: Makefile
|
# Name: Makefile
|
||||||
# Project: hid-custom-rq example
|
# Project: custom-class example
|
||||||
# Author: Christian Starkjohann
|
# Author: Christian Starkjohann
|
||||||
# Creation Date: 2008-04-06
|
# Creation Date: 2008-04-06
|
||||||
# Tabsize: 4
|
# Tabsize: 4
|
||||||
@@ -22,7 +22,7 @@ EXE_SUFFIX =
|
|||||||
#USBLIBS = -L/usr/local/lib -lusb
|
#USBLIBS = -L/usr/local/lib -lusb
|
||||||
#EXE_SUFFIX = .exe
|
#EXE_SUFFIX = .exe
|
||||||
|
|
||||||
NAME = set-led
|
NAME = snesuploader
|
||||||
|
|
||||||
OBJECTS = opendevice.o $(NAME).o
|
OBJECTS = opendevice.o $(NAME).o
|
||||||
|
|
||||||
296
avr/usbload/commandline/opendevice.c
Normal file
296
avr/usbload/commandline/opendevice.c
Normal file
@@ -0,0 +1,296 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
* Based on: custom-class, a basic USB example
|
||||||
|
* Author: Christian Starkjohann
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "opendevice.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define MATCH_SUCCESS 1
|
||||||
|
#define MATCH_FAILED 0
|
||||||
|
#define MATCH_ABORT -1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* private interface: match text and p, return MATCH_SUCCESS, MATCH_FAILED, or
|
||||||
|
* MATCH_ABORT.
|
||||||
|
*/
|
||||||
|
static int _shellStyleMatch(char *text, char *p)
|
||||||
|
{
|
||||||
|
int last,
|
||||||
|
matched,
|
||||||
|
reverse;
|
||||||
|
|
||||||
|
for (; *p; text++, p++) {
|
||||||
|
if (*text == 0 && *p != '*')
|
||||||
|
return MATCH_ABORT;
|
||||||
|
switch (*p) {
|
||||||
|
case '\\':
|
||||||
|
/*
|
||||||
|
* Literal match with following character.
|
||||||
|
*/
|
||||||
|
p++;
|
||||||
|
/*
|
||||||
|
* FALLTHROUGH
|
||||||
|
*/
|
||||||
|
default:
|
||||||
|
if (*text != *p)
|
||||||
|
return MATCH_FAILED;
|
||||||
|
continue;
|
||||||
|
case '?':
|
||||||
|
/*
|
||||||
|
* Match anything.
|
||||||
|
*/
|
||||||
|
continue;
|
||||||
|
case '*':
|
||||||
|
while (*++p == '*')
|
||||||
|
/*
|
||||||
|
* Consecutive stars act just like one.
|
||||||
|
*/
|
||||||
|
continue;
|
||||||
|
if (*p == 0)
|
||||||
|
/*
|
||||||
|
* Trailing star matches everything.
|
||||||
|
*/
|
||||||
|
return MATCH_SUCCESS;
|
||||||
|
while (*text)
|
||||||
|
if ((matched = _shellStyleMatch(text++, p)) != MATCH_FAILED)
|
||||||
|
return matched;
|
||||||
|
return MATCH_ABORT;
|
||||||
|
case '[':
|
||||||
|
reverse = p[1] == '^';
|
||||||
|
if (reverse) /* Inverted character class. */
|
||||||
|
p++;
|
||||||
|
matched = MATCH_FAILED;
|
||||||
|
if (p[1] == ']' || p[1] == '-')
|
||||||
|
if (*++p == *text)
|
||||||
|
matched = MATCH_SUCCESS;
|
||||||
|
for (last = *p; *++p && *p != ']'; last = *p)
|
||||||
|
if (*p == '-' && p[1] != ']' ? *text <= *++p
|
||||||
|
&& *text >= last : *text == *p)
|
||||||
|
matched = MATCH_SUCCESS;
|
||||||
|
if (matched == reverse)
|
||||||
|
return MATCH_FAILED;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return *text == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* public interface for shell style matching: returns 0 if fails, 1 if matches
|
||||||
|
*/
|
||||||
|
static int shellStyleMatch(char *text, char *pattern)
|
||||||
|
{
|
||||||
|
if (pattern == NULL) /* NULL pattern is synonymous to "*" */
|
||||||
|
return 1;
|
||||||
|
return _shellStyleMatch(text, pattern) == MATCH_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
int usbGetStringAscii(usb_dev_handle * dev, int index, char *buf, int buflen)
|
||||||
|
{
|
||||||
|
char buffer[256];
|
||||||
|
int rval,
|
||||||
|
i;
|
||||||
|
|
||||||
|
if ((rval = usb_get_string_simple(dev, index, buf, buflen)) >= 0) /* use
|
||||||
|
* libusb
|
||||||
|
* version
|
||||||
|
* if
|
||||||
|
* it
|
||||||
|
* works
|
||||||
|
*/
|
||||||
|
return rval;
|
||||||
|
if ((rval =
|
||||||
|
usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR,
|
||||||
|
(USB_DT_STRING << 8) + index, 0x0409, buffer,
|
||||||
|
sizeof(buffer), 5000)) < 0)
|
||||||
|
return rval;
|
||||||
|
if (buffer[1] != USB_DT_STRING) {
|
||||||
|
*buf = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if ((unsigned char) buffer[0] < rval)
|
||||||
|
rval = (unsigned char) buffer[0];
|
||||||
|
rval /= 2;
|
||||||
|
/*
|
||||||
|
* lossy conversion to ISO Latin1:
|
||||||
|
*/
|
||||||
|
for (i = 1; i < rval; i++) {
|
||||||
|
if (i > buflen) /* destination buffer overflow */
|
||||||
|
break;
|
||||||
|
buf[i - 1] = buffer[2 * i];
|
||||||
|
if (buffer[2 * i + 1] != 0) /* outside of ISO Latin1 range */
|
||||||
|
buf[i - 1] = '?';
|
||||||
|
}
|
||||||
|
buf[i - 1] = 0;
|
||||||
|
return i - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
int usbOpenDevice(usb_dev_handle ** device, int vendorID,
|
||||||
|
char *vendorNamePattern, int productID,
|
||||||
|
char *productNamePattern, char *serialNamePattern,
|
||||||
|
FILE * printMatchingDevicesFp, FILE * warningsFp)
|
||||||
|
{
|
||||||
|
struct usb_bus *bus;
|
||||||
|
struct usb_device *dev;
|
||||||
|
usb_dev_handle *handle = NULL;
|
||||||
|
int errorCode = USBOPEN_ERR_NOTFOUND;
|
||||||
|
|
||||||
|
usb_find_busses();
|
||||||
|
usb_find_devices();
|
||||||
|
for (bus = usb_get_busses(); bus; bus = bus->next) {
|
||||||
|
for (dev = bus->devices; dev; dev = dev->next) { /* iterate over
|
||||||
|
* all devices
|
||||||
|
* on all
|
||||||
|
* busses */
|
||||||
|
if ((vendorID == 0 || dev->descriptor.idVendor == vendorID)
|
||||||
|
&& (productID == 0 || dev->descriptor.idProduct == productID)) {
|
||||||
|
char vendor[256],
|
||||||
|
product[256],
|
||||||
|
serial[256];
|
||||||
|
int len;
|
||||||
|
handle = usb_open(dev); /* we need to open the device in order
|
||||||
|
* to query strings */
|
||||||
|
if (!handle) {
|
||||||
|
errorCode = USBOPEN_ERR_ACCESS;
|
||||||
|
if (warningsFp != NULL)
|
||||||
|
fprintf(warningsFp,
|
||||||
|
"Warning: cannot open VID=0x%04x PID=0x%04x: %s\n",
|
||||||
|
dev->descriptor.idVendor,
|
||||||
|
dev->descriptor.idProduct, usb_strerror());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* now check whether the names match:
|
||||||
|
*/
|
||||||
|
len = vendor[0] = 0;
|
||||||
|
if (dev->descriptor.iManufacturer > 0) {
|
||||||
|
len =
|
||||||
|
usbGetStringAscii(handle, dev->descriptor.iManufacturer,
|
||||||
|
vendor, sizeof(vendor));
|
||||||
|
}
|
||||||
|
if (len < 0) {
|
||||||
|
errorCode = USBOPEN_ERR_ACCESS;
|
||||||
|
if (warningsFp != NULL)
|
||||||
|
fprintf(warningsFp,
|
||||||
|
"Warning: cannot query manufacturer for VID=0x%04x PID=0x%04x: %s\n",
|
||||||
|
dev->descriptor.idVendor,
|
||||||
|
dev->descriptor.idProduct, usb_strerror());
|
||||||
|
} else {
|
||||||
|
errorCode = USBOPEN_ERR_NOTFOUND;
|
||||||
|
/*
|
||||||
|
* printf("seen device from vendor ->%s<-\n", vendor);
|
||||||
|
*/
|
||||||
|
if (shellStyleMatch(vendor, vendorNamePattern)) {
|
||||||
|
len = product[0] = 0;
|
||||||
|
if (dev->descriptor.iProduct > 0) {
|
||||||
|
len =
|
||||||
|
usbGetStringAscii(handle,
|
||||||
|
dev->descriptor.iProduct,
|
||||||
|
product, sizeof(product));
|
||||||
|
}
|
||||||
|
if (len < 0) {
|
||||||
|
errorCode = USBOPEN_ERR_ACCESS;
|
||||||
|
if (warningsFp != NULL)
|
||||||
|
fprintf(warningsFp,
|
||||||
|
"Warning: cannot query product for VID=0x%04x PID=0x%04x: %s\n",
|
||||||
|
dev->descriptor.idVendor,
|
||||||
|
dev->descriptor.idProduct,
|
||||||
|
usb_strerror());
|
||||||
|
} else {
|
||||||
|
errorCode = USBOPEN_ERR_NOTFOUND;
|
||||||
|
/*
|
||||||
|
* printf("seen product ->%s<-\n", product);
|
||||||
|
*/
|
||||||
|
if (shellStyleMatch(product, productNamePattern)) {
|
||||||
|
len = serial[0] = 0;
|
||||||
|
if (dev->descriptor.iSerialNumber > 0) {
|
||||||
|
len =
|
||||||
|
usbGetStringAscii(handle,
|
||||||
|
dev->descriptor.
|
||||||
|
iSerialNumber, serial,
|
||||||
|
sizeof(serial));
|
||||||
|
}
|
||||||
|
if (len < 0) {
|
||||||
|
errorCode = USBOPEN_ERR_ACCESS;
|
||||||
|
if (warningsFp != NULL)
|
||||||
|
fprintf(warningsFp,
|
||||||
|
"Warning: cannot query serial for VID=0x%04x PID=0x%04x: %s\n",
|
||||||
|
dev->descriptor.idVendor,
|
||||||
|
dev->descriptor.idProduct,
|
||||||
|
usb_strerror());
|
||||||
|
}
|
||||||
|
if (shellStyleMatch(serial, serialNamePattern)) {
|
||||||
|
if (printMatchingDevicesFp != NULL) {
|
||||||
|
if (serial[0] == 0) {
|
||||||
|
fprintf(printMatchingDevicesFp,
|
||||||
|
"VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\"\n",
|
||||||
|
dev->descriptor.idVendor,
|
||||||
|
dev->descriptor.idProduct,
|
||||||
|
vendor, product);
|
||||||
|
} else {
|
||||||
|
fprintf(printMatchingDevicesFp,
|
||||||
|
"VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\" serial=\"%s\"\n",
|
||||||
|
dev->descriptor.idVendor,
|
||||||
|
dev->descriptor.idProduct,
|
||||||
|
vendor, product, serial);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
usb_close(handle);
|
||||||
|
handle = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (handle) /* we have found a deice */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (handle != NULL) {
|
||||||
|
errorCode = 0;
|
||||||
|
*device = handle;
|
||||||
|
}
|
||||||
|
if (printMatchingDevicesFp != NULL) /* never return an error for listing
|
||||||
|
* only */
|
||||||
|
errorCode = 0;
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
@@ -1,24 +1,24 @@
|
|||||||
/* Name: opendevice.h
|
/*
|
||||||
* Project: AVR-USB host-side library
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
* Based on: custom-class, a basic USB example
|
||||||
* Author: Christian Starkjohann
|
* Author: Christian Starkjohann
|
||||||
* Creation Date: 2008-04-10
|
* =====================================================================================
|
||||||
* Tabsize: 4
|
|
||||||
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
|
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
|
||||||
* This Revision: $Id: opendevice.h 692 2008-11-07 15:07:40Z cs $
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
General Description:
|
|
||||||
This module offers additional functionality for host side drivers based on
|
|
||||||
libusb or libusb-win32. It includes a function to find and open a device
|
|
||||||
based on numeric IDs and textual description. It also includes a function to
|
|
||||||
obtain textual descriptions from a device.
|
|
||||||
|
|
||||||
To use this functionality, simply copy opendevice.c and opendevice.h into your
|
|
||||||
project and add them to your Makefile. You may modify and redistribute these
|
|
||||||
files according to the GNU General Public License (GPL) version 2 or 3.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __OPENDEVICE_H_INCLUDED__
|
#ifndef __OPENDEVICE_H_INCLUDED__
|
||||||
#define __OPENDEVICE_H_INCLUDED__
|
#define __OPENDEVICE_H_INCLUDED__
|
||||||
313
avr/usbload/commandline/snesuploader.c
Normal file
313
avr/usbload/commandline/snesuploader.c
Normal file
@@ -0,0 +1,313 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
* Based on: custom-class, a basic USB example
|
||||||
|
* Author: Christian Starkjohann
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
#define BANK_SIZE_SHIFT 15
|
||||||
|
#define BANK_SIZE (1<<BANK_SIZE_SHIFT)
|
||||||
|
#define READ_BUFFER_SIZE (1<<BANK_SIZE_SHIFT)
|
||||||
|
#define SEND_BUFFER_SIZE 128
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <usb.h> /* this is libusb */
|
||||||
|
|
||||||
|
#include "opendevice.h" /* common code moved to separate module */
|
||||||
|
|
||||||
|
#include "../requests.h" /* custom request numbers */
|
||||||
|
#include "../usbconfig.h" /* device's VID/PID and names */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void dump_packet(uint32_t addr, uint32_t len, uint8_t * packet)
|
||||||
|
{
|
||||||
|
uint16_t i,
|
||||||
|
j;
|
||||||
|
uint16_t sum = 0;
|
||||||
|
uint8_t clear = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < len; i += 16) {
|
||||||
|
|
||||||
|
sum = 0;
|
||||||
|
for (j = 0; j < 16; j++) {
|
||||||
|
sum += packet[i + j];
|
||||||
|
}
|
||||||
|
if (!sum) {
|
||||||
|
clear = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (clear) {
|
||||||
|
printf("*\n");
|
||||||
|
clear = 0;
|
||||||
|
}
|
||||||
|
printf("%08x:", addr + i);
|
||||||
|
for (j = 0; j < 16; j++) {
|
||||||
|
printf(" %02x", packet[i + j]);
|
||||||
|
}
|
||||||
|
printf(" |");
|
||||||
|
for (j = 0; j < 16; j++) {
|
||||||
|
if (packet[i + j] >= 33 && packet[i + j] <= 126)
|
||||||
|
printf("%c", packet[i + j]);
|
||||||
|
else
|
||||||
|
printf(".");
|
||||||
|
}
|
||||||
|
printf("|\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t crc_xmodem_update(uint16_t crc, uint8_t data)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
crc = crc ^ ((uint16_t) data << 8);
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
if (crc & 0x8000)
|
||||||
|
crc = (crc << 1) ^ 0x1021;
|
||||||
|
else
|
||||||
|
crc <<= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t do_crc(uint8_t * data, uint16_t size)
|
||||||
|
{
|
||||||
|
uint16_t crc = 0;
|
||||||
|
uint16_t i;
|
||||||
|
for (i = 0; i < size; i++) {
|
||||||
|
crc = crc_xmodem_update(crc, data[i]);
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t do_crc_update(uint16_t crc, uint8_t * data, uint16_t size)
|
||||||
|
{
|
||||||
|
uint16_t i;
|
||||||
|
for (i = 0; i < size; i++)
|
||||||
|
crc = crc_xmodem_update(crc, data[i]);
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void usage(char *name)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "usage:\n");
|
||||||
|
fprintf(stderr, " %s upload filename.. upload\n", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
usb_dev_handle *handle = NULL;
|
||||||
|
const unsigned char rawVid[2] = { USB_CFG_VENDOR_ID }, rawPid[2] = {
|
||||||
|
USB_CFG_DEVICE_ID};
|
||||||
|
char vendor[] = { USB_CFG_VENDOR_NAME, 0 }, product[] = {
|
||||||
|
USB_CFG_DEVICE_NAME, 0};
|
||||||
|
int cnt, vid, pid;
|
||||||
|
uint8_t *read_buffer;
|
||||||
|
uint8_t *crc_buffer;
|
||||||
|
uint8_t *ptr;
|
||||||
|
|
||||||
|
uint32_t addr = 0;
|
||||||
|
uint16_t addr_lo = 0;
|
||||||
|
uint16_t addr_hi = 0;
|
||||||
|
uint32_t step = 0;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
uint8_t bank = 0;
|
||||||
|
uint8_t bank_cnt = 0;
|
||||||
|
uint32_t file_size = 0;
|
||||||
|
uint32_t file_offset = 0;
|
||||||
|
|
||||||
|
FILE *fp;
|
||||||
|
usb_init();
|
||||||
|
if (argc < 2) { /* we need at least one argument */
|
||||||
|
usage(argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* compute VID/PID from usbconfig.h so that there is a central source
|
||||||
|
* of information
|
||||||
|
*/
|
||||||
|
vid = rawVid[1] * 256 + rawVid[0];
|
||||||
|
pid = rawPid[1] * 256 + rawPid[0];
|
||||||
|
/*
|
||||||
|
* The following function is in opendevice.c:
|
||||||
|
*/
|
||||||
|
if (usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) !=
|
||||||
|
0) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n",
|
||||||
|
product, vid, pid);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
printf("Open USB device \"%s\" with vid=0x%x pid=0x%x\n", product, vid,
|
||||||
|
pid);
|
||||||
|
if (strcasecmp(argv[1], "upload") == 0) {
|
||||||
|
if (argc < 3) { /* we need at least one argument */
|
||||||
|
usage(argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
fp = fopen(argv[2], "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
fprintf(stderr, "Cannot open file %s ", argv[2]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek (fp, 0, SEEK_END);
|
||||||
|
file_size = ftell (fp);
|
||||||
|
file_offset = 512;
|
||||||
|
if (strstr(argv[2],".smc") || strstr(argv[2],".swc")){
|
||||||
|
printf("Skip 512 Byte header\n");
|
||||||
|
file_size -= 512;
|
||||||
|
|
||||||
|
fseek (fp, 512, SEEK_SET);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
fseek (fp, 0, SEEK_SET);
|
||||||
|
}
|
||||||
|
|
||||||
|
bank_cnt = file_size / BANK_SIZE;
|
||||||
|
printf("Transfer '%s' %i Bytes, %i Banks\n",argv[2],file_size,bank_cnt);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
read_buffer = (unsigned char *) malloc(READ_BUFFER_SIZE);
|
||||||
|
crc_buffer = (unsigned char *) malloc(0x1000);
|
||||||
|
memset(crc_buffer, 0, 0x1000);
|
||||||
|
addr = 0x000000;
|
||||||
|
|
||||||
|
cnt = usb_control_msg(handle,
|
||||||
|
USB_TYPE_VENDOR | USB_RECIP_DEVICE |
|
||||||
|
USB_ENDPOINT_OUT, USB_MODE_AVR, 0, 0, NULL,
|
||||||
|
0, 5000);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cnt = usb_control_msg(handle,
|
||||||
|
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT,
|
||||||
|
USB_BULK_UPLOAD_INIT, BANK_SIZE_SHIFT , bank_cnt, NULL, 0, 5000);
|
||||||
|
|
||||||
|
if (cnt < 0) {
|
||||||
|
fprintf(stderr, "USB error: %s\n", usb_strerror());
|
||||||
|
usb_close(handle);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
ptr = crc_buffer;
|
||||||
|
while ((cnt = fread(read_buffer, READ_BUFFER_SIZE, 1, fp)) > 0) {
|
||||||
|
ptr = crc_buffer;
|
||||||
|
for (step = 0; step < READ_BUFFER_SIZE; step += SEND_BUFFER_SIZE) {
|
||||||
|
|
||||||
|
|
||||||
|
addr_lo = addr & 0xffff;
|
||||||
|
addr_hi = (addr >> 16) & 0x00ff;
|
||||||
|
if (addr == 0x000000){
|
||||||
|
|
||||||
|
cnt = usb_control_msg(handle,
|
||||||
|
USB_TYPE_VENDOR | USB_RECIP_DEVICE |
|
||||||
|
USB_ENDPOINT_OUT, USB_BULK_UPLOAD_ADDR, addr_hi,
|
||||||
|
addr_lo, (char *) read_buffer + step,
|
||||||
|
SEND_BUFFER_SIZE, 5000);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
cnt = usb_control_msg(handle,
|
||||||
|
USB_TYPE_VENDOR | USB_RECIP_DEVICE |
|
||||||
|
USB_ENDPOINT_OUT, USB_BULK_UPLOAD_NEXT, addr_hi,
|
||||||
|
addr_lo, (char *) read_buffer + step,
|
||||||
|
SEND_BUFFER_SIZE, 5000);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (cnt < 0) {
|
||||||
|
fprintf(stderr, "USB error: %s\n", usb_strerror());
|
||||||
|
usb_close(handle);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(ptr, read_buffer + step, SEND_BUFFER_SIZE);
|
||||||
|
addr += SEND_BUFFER_SIZE;
|
||||||
|
ptr += SEND_BUFFER_SIZE;
|
||||||
|
if ( addr % BANK_SIZE == 0){
|
||||||
|
crc = do_crc(crc_buffer, 0x1000);
|
||||||
|
printf ("bank=0x%02x addr=0x%08x addr=0x%08x crc=0x%04x\n", bank, addr - 0x1000, addr, crc);
|
||||||
|
ptr = crc_buffer;
|
||||||
|
if ( addr % BANK_SIZE == 0) {
|
||||||
|
bank++;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bank = 0;
|
||||||
|
cnt = usb_control_msg(handle,
|
||||||
|
USB_TYPE_VENDOR | USB_RECIP_DEVICE |
|
||||||
|
USB_ENDPOINT_OUT, USB_BULK_UPLOAD_END, 0, 0, NULL,
|
||||||
|
0, 5000);
|
||||||
|
|
||||||
|
|
||||||
|
fseek(fp, file_offset, SEEK_SET);
|
||||||
|
while ((cnt = fread(read_buffer, READ_BUFFER_SIZE, 1, fp)) > 0) {
|
||||||
|
printf ("bank=0x%02x crc=0x%04x\n", bank++,
|
||||||
|
do_crc(read_buffer, READ_BUFFER_SIZE));
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
cnt = usb_control_msg(handle,
|
||||||
|
USB_TYPE_VENDOR | USB_RECIP_DEVICE |
|
||||||
|
USB_ENDPOINT_OUT, USB_MODE_SNES, 0, 0, NULL,
|
||||||
|
0, 5000);
|
||||||
|
|
||||||
|
|
||||||
|
if (cnt < 1) {
|
||||||
|
if (cnt < 0) {
|
||||||
|
fprintf(stderr, "USB error: %s\n", usb_strerror());
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "only %d bytes received.\n", cnt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (strcasecmp(argv[1], "crc") == 0) {
|
||||||
|
/*
|
||||||
|
* if(argc < 2){ usage(argv[0]); exit(1); }
|
||||||
|
*/
|
||||||
|
addr = 0x000000;
|
||||||
|
addr_lo = addr & 0xffff;
|
||||||
|
addr_hi = (addr >> 16) & 0xff;
|
||||||
|
printf("Request CRC for Addr: 0x%06x\n", addr);
|
||||||
|
|
||||||
|
cnt = usb_control_msg(handle,
|
||||||
|
USB_TYPE_VENDOR | USB_RECIP_DEVICE |
|
||||||
|
USB_ENDPOINT_OUT, USB_CRC_ADDR, addr_hi, addr_lo,
|
||||||
|
NULL, (1 << 15) / 4, 5000);
|
||||||
|
|
||||||
|
if (cnt < 1) {
|
||||||
|
if (cnt < 0) {
|
||||||
|
fprintf(stderr, "USB error: %s\n", usb_strerror());
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "only %d bytes received.\n", cnt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
usage(argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
usb_close(handle);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
809
avr/usbload/commandline/snesuploader.ll
Normal file
809
avr/usbload/commandline/snesuploader.ll
Normal file
@@ -0,0 +1,809 @@
|
|||||||
|
; ModuleID = '/Users/david/Devel/arch/avr/code/snesram/poc/avr_usbload/commandline/snesuploader.c'
|
||||||
|
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
|
||||||
|
target triple = "i386-apple-darwin9"
|
||||||
|
%struct.__sFILE = type <{ i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %struct.__sbuf, %struct.__sFILEX*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64 }>
|
||||||
|
%struct.__sFILEX = type opaque
|
||||||
|
%struct.__sbuf = type <{ i8*, i32 }>
|
||||||
|
%struct.usb_dev_handle = type opaque
|
||||||
|
@"\01LC" = internal constant [3 x i8] c"*\0A\00" ; <[3 x i8]*> [#uses=1]
|
||||||
|
@"\01LC1" = internal constant [6 x i8] c"%08x:\00" ; <[6 x i8]*> [#uses=1]
|
||||||
|
@"\01LC2" = internal constant [6 x i8] c" %02x\00" ; <[6 x i8]*> [#uses=1]
|
||||||
|
@"\01LC3" = internal constant [3 x i8] c" |\00" ; <[3 x i8]*> [#uses=1]
|
||||||
|
@"\01LC4" = internal constant [3 x i8] c"%c\00" ; <[3 x i8]*> [#uses=1]
|
||||||
|
@"\01LC5" = internal constant [2 x i8] c".\00" ; <[2 x i8]*> [#uses=1]
|
||||||
|
@"\01LC6" = internal constant [3 x i8] c"|\0A\00" ; <[3 x i8]*> [#uses=1]
|
||||||
|
@__stderrp = external global %struct.__sFILE* ; <%struct.__sFILE**> [#uses=8]
|
||||||
|
@"\01LC7" = internal constant [55 x i8] c"Could not find USB device \22%s\22 with vid=0x%x pid=0x%x\0A\00" ; <[55 x i8]*> [#uses=1]
|
||||||
|
@"\01LC8" = internal constant [45 x i8] c"Open USB device \22%s\22 with vid=0x%x pid=0x%x\0A\00" ; <[45 x i8]*> [#uses=1]
|
||||||
|
@"\01LC9" = internal constant [7 x i8] c"upload\00" ; <[7 x i8]*> [#uses=1]
|
||||||
|
@"\01LC10" = internal constant [2 x i8] c"r\00" ; <[2 x i8]*> [#uses=1]
|
||||||
|
@"\01LC11" = internal constant [21 x i8] c"Cannot open file %s \00" ; <[21 x i8]*> [#uses=1]
|
||||||
|
@"\01LC12" = internal constant [70 x i8] c"Addr: 0x%06x Bank: 0x%02x HiAddr: 0x%02x LoAddr: 0x%04x Crc: 0x%04x\0A\00" ; <[70 x i8]*> [#uses=1]
|
||||||
|
@"\01LC13" = internal constant [15 x i8] c"USB error: %s\0A\00" ; <[15 x i8]*> [#uses=1]
|
||||||
|
@"\01LC14" = internal constant [25 x i8] c"only %d bytes received.\0A\00" ; <[25 x i8]*> [#uses=1]
|
||||||
|
@"\01LC15" = internal constant [4 x i8] c"crc\00" ; <[4 x i8]*> [#uses=1]
|
||||||
|
@"\01LC16" = internal constant [30 x i8] c"Request CRC for Addr: 0x%06x\0A\00" ; <[30 x i8]*> [#uses=1]
|
||||||
|
@"\01LC17" = internal constant [8 x i8] c"usage:\0A\00" ; <[8 x i8]*> [#uses=1]
|
||||||
|
@"\01LC18" = internal constant [31 x i8] c" %s upload filename.. upload\0A\00" ; <[31 x i8]*> [#uses=1]
|
||||||
|
|
||||||
|
define void @dump_packet(i32 %addr, i32 %len, i8* %packet) nounwind {
|
||||||
|
entry:
|
||||||
|
%addr.addr = alloca i32 ; <i32*> [#uses=2]
|
||||||
|
%len.addr = alloca i32 ; <i32*> [#uses=2]
|
||||||
|
%packet.addr = alloca i8* ; <i8**> [#uses=6]
|
||||||
|
%i = alloca i16, align 2 ; <i16*> [#uses=10]
|
||||||
|
%j = alloca i16, align 2 ; <i16*> [#uses=17]
|
||||||
|
%sum = alloca i16, align 2 ; <i16*> [#uses=5]
|
||||||
|
%clear = alloca i8, align 1 ; <i8*> [#uses=4]
|
||||||
|
store i32 %addr, i32* %addr.addr
|
||||||
|
store i32 %len, i32* %len.addr
|
||||||
|
store i8* %packet, i8** %packet.addr
|
||||||
|
store i16 0, i16* %sum
|
||||||
|
store i8 0, i8* %clear
|
||||||
|
store i16 0, i16* %i
|
||||||
|
br label %for.cond
|
||||||
|
|
||||||
|
for.cond: ; preds = %for.inc98, %entry
|
||||||
|
%tmp = load i16* %i ; <i16> [#uses=1]
|
||||||
|
%conv = zext i16 %tmp to i32 ; <i32> [#uses=1]
|
||||||
|
%tmp1 = load i32* %len.addr ; <i32> [#uses=1]
|
||||||
|
%cmp = icmp ult i32 %conv, %tmp1 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp, label %for.body, label %for.end103
|
||||||
|
|
||||||
|
for.body: ; preds = %for.cond
|
||||||
|
store i16 0, i16* %sum
|
||||||
|
store i16 0, i16* %j
|
||||||
|
br label %for.cond3
|
||||||
|
|
||||||
|
for.cond3: ; preds = %for.inc, %for.body
|
||||||
|
%tmp4 = load i16* %j ; <i16> [#uses=1]
|
||||||
|
%conv5 = zext i16 %tmp4 to i32 ; <i32> [#uses=1]
|
||||||
|
%cmp6 = icmp slt i32 %conv5, 16 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp6, label %for.body8, label %for.end
|
||||||
|
|
||||||
|
for.body8: ; preds = %for.cond3
|
||||||
|
%tmp9 = load i16* %sum ; <i16> [#uses=1]
|
||||||
|
%conv10 = zext i16 %tmp9 to i32 ; <i32> [#uses=1]
|
||||||
|
%tmp11 = load i16* %i ; <i16> [#uses=1]
|
||||||
|
%conv12 = zext i16 %tmp11 to i32 ; <i32> [#uses=1]
|
||||||
|
%tmp13 = load i16* %j ; <i16> [#uses=1]
|
||||||
|
%conv14 = zext i16 %tmp13 to i32 ; <i32> [#uses=1]
|
||||||
|
%add = add i32 %conv12, %conv14 ; <i32> [#uses=1]
|
||||||
|
%tmp15 = load i8** %packet.addr ; <i8*> [#uses=1]
|
||||||
|
%arrayidx = getelementptr i8* %tmp15, i32 %add ; <i8*> [#uses=1]
|
||||||
|
%tmp16 = load i8* %arrayidx ; <i8> [#uses=1]
|
||||||
|
%conv17 = zext i8 %tmp16 to i32 ; <i32> [#uses=1]
|
||||||
|
%add18 = add i32 %conv10, %conv17 ; <i32> [#uses=1]
|
||||||
|
%conv19 = trunc i32 %add18 to i16 ; <i16> [#uses=1]
|
||||||
|
store i16 %conv19, i16* %sum
|
||||||
|
br label %for.inc
|
||||||
|
|
||||||
|
for.inc: ; preds = %for.body8
|
||||||
|
%tmp20 = load i16* %j ; <i16> [#uses=1]
|
||||||
|
%inc = add i16 %tmp20, 1 ; <i16> [#uses=1]
|
||||||
|
store i16 %inc, i16* %j
|
||||||
|
br label %for.cond3
|
||||||
|
|
||||||
|
for.end: ; preds = %for.cond3
|
||||||
|
%tmp21 = load i16* %sum ; <i16> [#uses=1]
|
||||||
|
%tobool = icmp ne i16 %tmp21, 0 ; <i1> [#uses=1]
|
||||||
|
br i1 %tobool, label %if.end, label %if.then
|
||||||
|
|
||||||
|
if.then: ; preds = %for.end
|
||||||
|
store i8 1, i8* %clear
|
||||||
|
br label %for.inc98
|
||||||
|
|
||||||
|
if.end: ; preds = %for.end
|
||||||
|
%tmp22 = load i8* %clear ; <i8> [#uses=1]
|
||||||
|
%tobool23 = icmp ne i8 %tmp22, 0 ; <i1> [#uses=1]
|
||||||
|
br i1 %tobool23, label %if.then24, label %if.end25
|
||||||
|
|
||||||
|
if.then24: ; preds = %if.end
|
||||||
|
%call = call i32 (i8*, ...)* @printf(i8* getelementptr ([3 x i8]* @"\01LC", i32 0, i32 0)) ; <i32> [#uses=0]
|
||||||
|
store i8 0, i8* %clear
|
||||||
|
br label %if.end25
|
||||||
|
|
||||||
|
if.end25: ; preds = %if.then24, %if.end
|
||||||
|
%tmp26 = load i32* %addr.addr ; <i32> [#uses=1]
|
||||||
|
%tmp27 = load i16* %i ; <i16> [#uses=1]
|
||||||
|
%conv28 = zext i16 %tmp27 to i32 ; <i32> [#uses=1]
|
||||||
|
%add29 = add i32 %tmp26, %conv28 ; <i32> [#uses=1]
|
||||||
|
%call30 = call i32 (i8*, ...)* @printf(i8* getelementptr ([6 x i8]* @"\01LC1", i32 0, i32 0), i32 %add29) ; <i32> [#uses=0]
|
||||||
|
store i16 0, i16* %j
|
||||||
|
br label %for.cond31
|
||||||
|
|
||||||
|
for.cond31: ; preds = %for.inc47, %if.end25
|
||||||
|
%tmp32 = load i16* %j ; <i16> [#uses=1]
|
||||||
|
%conv33 = zext i16 %tmp32 to i32 ; <i32> [#uses=1]
|
||||||
|
%cmp34 = icmp slt i32 %conv33, 16 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp34, label %for.body36, label %for.end50
|
||||||
|
|
||||||
|
for.body36: ; preds = %for.cond31
|
||||||
|
%tmp37 = load i16* %i ; <i16> [#uses=1]
|
||||||
|
%conv38 = zext i16 %tmp37 to i32 ; <i32> [#uses=1]
|
||||||
|
%tmp39 = load i16* %j ; <i16> [#uses=1]
|
||||||
|
%conv40 = zext i16 %tmp39 to i32 ; <i32> [#uses=1]
|
||||||
|
%add41 = add i32 %conv38, %conv40 ; <i32> [#uses=1]
|
||||||
|
%tmp42 = load i8** %packet.addr ; <i8*> [#uses=1]
|
||||||
|
%arrayidx43 = getelementptr i8* %tmp42, i32 %add41 ; <i8*> [#uses=1]
|
||||||
|
%tmp44 = load i8* %arrayidx43 ; <i8> [#uses=1]
|
||||||
|
%conv45 = zext i8 %tmp44 to i32 ; <i32> [#uses=1]
|
||||||
|
%call46 = call i32 (i8*, ...)* @printf(i8* getelementptr ([6 x i8]* @"\01LC2", i32 0, i32 0), i32 %conv45) ; <i32> [#uses=0]
|
||||||
|
br label %for.inc47
|
||||||
|
|
||||||
|
for.inc47: ; preds = %for.body36
|
||||||
|
%tmp48 = load i16* %j ; <i16> [#uses=1]
|
||||||
|
%inc49 = add i16 %tmp48, 1 ; <i16> [#uses=1]
|
||||||
|
store i16 %inc49, i16* %j
|
||||||
|
br label %for.cond31
|
||||||
|
|
||||||
|
for.end50: ; preds = %for.cond31
|
||||||
|
%call51 = call i32 (i8*, ...)* @printf(i8* getelementptr ([3 x i8]* @"\01LC3", i32 0, i32 0)) ; <i32> [#uses=0]
|
||||||
|
store i16 0, i16* %j
|
||||||
|
br label %for.cond52
|
||||||
|
|
||||||
|
for.cond52: ; preds = %for.inc93, %for.end50
|
||||||
|
%tmp53 = load i16* %j ; <i16> [#uses=1]
|
||||||
|
%conv54 = zext i16 %tmp53 to i32 ; <i32> [#uses=1]
|
||||||
|
%cmp55 = icmp slt i32 %conv54, 16 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp55, label %for.body57, label %for.end96
|
||||||
|
|
||||||
|
for.body57: ; preds = %for.cond52
|
||||||
|
%tmp58 = load i16* %i ; <i16> [#uses=1]
|
||||||
|
%conv59 = zext i16 %tmp58 to i32 ; <i32> [#uses=1]
|
||||||
|
%tmp60 = load i16* %j ; <i16> [#uses=1]
|
||||||
|
%conv61 = zext i16 %tmp60 to i32 ; <i32> [#uses=1]
|
||||||
|
%add62 = add i32 %conv59, %conv61 ; <i32> [#uses=1]
|
||||||
|
%tmp63 = load i8** %packet.addr ; <i8*> [#uses=1]
|
||||||
|
%arrayidx64 = getelementptr i8* %tmp63, i32 %add62 ; <i8*> [#uses=1]
|
||||||
|
%tmp65 = load i8* %arrayidx64 ; <i8> [#uses=1]
|
||||||
|
%conv66 = zext i8 %tmp65 to i32 ; <i32> [#uses=1]
|
||||||
|
%cmp67 = icmp sge i32 %conv66, 33 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp67, label %land.lhs.true, label %if.else
|
||||||
|
|
||||||
|
land.lhs.true: ; preds = %for.body57
|
||||||
|
%tmp69 = load i16* %i ; <i16> [#uses=1]
|
||||||
|
%conv70 = zext i16 %tmp69 to i32 ; <i32> [#uses=1]
|
||||||
|
%tmp71 = load i16* %j ; <i16> [#uses=1]
|
||||||
|
%conv72 = zext i16 %tmp71 to i32 ; <i32> [#uses=1]
|
||||||
|
%add73 = add i32 %conv70, %conv72 ; <i32> [#uses=1]
|
||||||
|
%tmp74 = load i8** %packet.addr ; <i8*> [#uses=1]
|
||||||
|
%arrayidx75 = getelementptr i8* %tmp74, i32 %add73 ; <i8*> [#uses=1]
|
||||||
|
%tmp76 = load i8* %arrayidx75 ; <i8> [#uses=1]
|
||||||
|
%conv77 = zext i8 %tmp76 to i32 ; <i32> [#uses=1]
|
||||||
|
%cmp78 = icmp sle i32 %conv77, 126 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp78, label %if.then80, label %if.else
|
||||||
|
|
||||||
|
if.then80: ; preds = %land.lhs.true
|
||||||
|
%tmp81 = load i16* %i ; <i16> [#uses=1]
|
||||||
|
%conv82 = zext i16 %tmp81 to i32 ; <i32> [#uses=1]
|
||||||
|
%tmp83 = load i16* %j ; <i16> [#uses=1]
|
||||||
|
%conv84 = zext i16 %tmp83 to i32 ; <i32> [#uses=1]
|
||||||
|
%add85 = add i32 %conv82, %conv84 ; <i32> [#uses=1]
|
||||||
|
%tmp86 = load i8** %packet.addr ; <i8*> [#uses=1]
|
||||||
|
%arrayidx87 = getelementptr i8* %tmp86, i32 %add85 ; <i8*> [#uses=1]
|
||||||
|
%tmp88 = load i8* %arrayidx87 ; <i8> [#uses=1]
|
||||||
|
%conv89 = zext i8 %tmp88 to i32 ; <i32> [#uses=1]
|
||||||
|
%call90 = call i32 (i8*, ...)* @printf(i8* getelementptr ([3 x i8]* @"\01LC4", i32 0, i32 0), i32 %conv89) ; <i32> [#uses=0]
|
||||||
|
br label %if.end92
|
||||||
|
|
||||||
|
if.else: ; preds = %land.lhs.true, %for.body57
|
||||||
|
%call91 = call i32 (i8*, ...)* @printf(i8* getelementptr ([2 x i8]* @"\01LC5", i32 0, i32 0)) ; <i32> [#uses=0]
|
||||||
|
br label %if.end92
|
||||||
|
|
||||||
|
if.end92: ; preds = %if.else, %if.then80
|
||||||
|
br label %for.inc93
|
||||||
|
|
||||||
|
for.inc93: ; preds = %if.end92
|
||||||
|
%tmp94 = load i16* %j ; <i16> [#uses=1]
|
||||||
|
%inc95 = add i16 %tmp94, 1 ; <i16> [#uses=1]
|
||||||
|
store i16 %inc95, i16* %j
|
||||||
|
br label %for.cond52
|
||||||
|
|
||||||
|
for.end96: ; preds = %for.cond52
|
||||||
|
%call97 = call i32 (i8*, ...)* @printf(i8* getelementptr ([3 x i8]* @"\01LC6", i32 0, i32 0)) ; <i32> [#uses=0]
|
||||||
|
br label %for.inc98
|
||||||
|
|
||||||
|
for.inc98: ; preds = %for.end96, %if.then
|
||||||
|
%tmp99 = load i16* %i ; <i16> [#uses=1]
|
||||||
|
%conv100 = zext i16 %tmp99 to i32 ; <i32> [#uses=1]
|
||||||
|
%add101 = add i32 %conv100, 16 ; <i32> [#uses=1]
|
||||||
|
%conv102 = trunc i32 %add101 to i16 ; <i16> [#uses=1]
|
||||||
|
store i16 %conv102, i16* %i
|
||||||
|
br label %for.cond
|
||||||
|
|
||||||
|
for.end103: ; preds = %for.cond
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare i32 @printf(i8*, ...)
|
||||||
|
|
||||||
|
define zeroext i16 @crc_xmodem_update(i16 zeroext %crc, i8 zeroext %data) nounwind {
|
||||||
|
entry:
|
||||||
|
%retval = alloca i16 ; <i16*> [#uses=2]
|
||||||
|
%crc.addr = alloca i16 ; <i16*> [#uses=9]
|
||||||
|
%data.addr = alloca i8 ; <i8*> [#uses=2]
|
||||||
|
%i = alloca i32, align 4 ; <i32*> [#uses=4]
|
||||||
|
store i16 %crc, i16* %crc.addr
|
||||||
|
store i8 %data, i8* %data.addr
|
||||||
|
%tmp = load i16* %crc.addr ; <i16> [#uses=1]
|
||||||
|
%conv = zext i16 %tmp to i32 ; <i32> [#uses=1]
|
||||||
|
%tmp1 = load i8* %data.addr ; <i8> [#uses=1]
|
||||||
|
%conv2 = zext i8 %tmp1 to i32 ; <i32> [#uses=1]
|
||||||
|
%conv3 = trunc i32 %conv2 to i16 ; <i16> [#uses=1]
|
||||||
|
%conv4 = zext i16 %conv3 to i32 ; <i32> [#uses=1]
|
||||||
|
%shl = shl i32 %conv4, 8 ; <i32> [#uses=1]
|
||||||
|
%xor = xor i32 %conv, %shl ; <i32> [#uses=1]
|
||||||
|
%conv5 = trunc i32 %xor to i16 ; <i16> [#uses=1]
|
||||||
|
store i16 %conv5, i16* %crc.addr
|
||||||
|
store i32 0, i32* %i
|
||||||
|
br label %for.cond
|
||||||
|
|
||||||
|
for.cond: ; preds = %for.inc, %entry
|
||||||
|
%tmp6 = load i32* %i ; <i32> [#uses=1]
|
||||||
|
%cmp = icmp slt i32 %tmp6, 8 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp, label %for.body, label %for.end
|
||||||
|
|
||||||
|
for.body: ; preds = %for.cond
|
||||||
|
%tmp8 = load i16* %crc.addr ; <i16> [#uses=1]
|
||||||
|
%conv9 = zext i16 %tmp8 to i32 ; <i32> [#uses=1]
|
||||||
|
%and = and i32 %conv9, 32768 ; <i32> [#uses=1]
|
||||||
|
%tobool = icmp ne i32 %and, 0 ; <i1> [#uses=1]
|
||||||
|
br i1 %tobool, label %if.then, label %if.else
|
||||||
|
|
||||||
|
if.then: ; preds = %for.body
|
||||||
|
%tmp10 = load i16* %crc.addr ; <i16> [#uses=1]
|
||||||
|
%conv11 = zext i16 %tmp10 to i32 ; <i32> [#uses=1]
|
||||||
|
%shl12 = shl i32 %conv11, 1 ; <i32> [#uses=1]
|
||||||
|
%xor13 = xor i32 %shl12, 4129 ; <i32> [#uses=1]
|
||||||
|
%conv14 = trunc i32 %xor13 to i16 ; <i16> [#uses=1]
|
||||||
|
store i16 %conv14, i16* %crc.addr
|
||||||
|
br label %if.end
|
||||||
|
|
||||||
|
if.else: ; preds = %for.body
|
||||||
|
%tmp15 = load i16* %crc.addr ; <i16> [#uses=1]
|
||||||
|
%conv16 = zext i16 %tmp15 to i32 ; <i32> [#uses=1]
|
||||||
|
%shl17 = shl i32 %conv16, 1 ; <i32> [#uses=1]
|
||||||
|
%conv18 = trunc i32 %shl17 to i16 ; <i16> [#uses=1]
|
||||||
|
store i16 %conv18, i16* %crc.addr
|
||||||
|
br label %if.end
|
||||||
|
|
||||||
|
if.end: ; preds = %if.else, %if.then
|
||||||
|
br label %for.inc
|
||||||
|
|
||||||
|
for.inc: ; preds = %if.end
|
||||||
|
%tmp19 = load i32* %i ; <i32> [#uses=1]
|
||||||
|
%inc = add i32 %tmp19, 1 ; <i32> [#uses=1]
|
||||||
|
store i32 %inc, i32* %i
|
||||||
|
br label %for.cond
|
||||||
|
|
||||||
|
for.end: ; preds = %for.cond
|
||||||
|
%tmp20 = load i16* %crc.addr ; <i16> [#uses=1]
|
||||||
|
store i16 %tmp20, i16* %retval
|
||||||
|
%0 = load i16* %retval ; <i16> [#uses=1]
|
||||||
|
ret i16 %0
|
||||||
|
}
|
||||||
|
|
||||||
|
define zeroext i16 @do_crc(i8* %data, i16 zeroext %size) nounwind {
|
||||||
|
entry:
|
||||||
|
%retval = alloca i16 ; <i16*> [#uses=2]
|
||||||
|
%data.addr = alloca i8* ; <i8**> [#uses=2]
|
||||||
|
%size.addr = alloca i16 ; <i16*> [#uses=2]
|
||||||
|
%crc = alloca i16, align 2 ; <i16*> [#uses=4]
|
||||||
|
%i = alloca i16, align 2 ; <i16*> [#uses=5]
|
||||||
|
store i8* %data, i8** %data.addr
|
||||||
|
store i16 %size, i16* %size.addr
|
||||||
|
store i16 0, i16* %crc
|
||||||
|
store i16 0, i16* %i
|
||||||
|
br label %for.cond
|
||||||
|
|
||||||
|
for.cond: ; preds = %for.inc, %entry
|
||||||
|
%tmp = load i16* %i ; <i16> [#uses=1]
|
||||||
|
%conv = zext i16 %tmp to i32 ; <i32> [#uses=1]
|
||||||
|
%tmp1 = load i16* %size.addr ; <i16> [#uses=1]
|
||||||
|
%conv2 = zext i16 %tmp1 to i32 ; <i32> [#uses=1]
|
||||||
|
%cmp = icmp slt i32 %conv, %conv2 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp, label %for.body, label %for.end
|
||||||
|
|
||||||
|
for.body: ; preds = %for.cond
|
||||||
|
%tmp4 = load i16* %crc ; <i16> [#uses=1]
|
||||||
|
%tmp5 = load i16* %i ; <i16> [#uses=1]
|
||||||
|
%tmp6 = load i8** %data.addr ; <i8*> [#uses=1]
|
||||||
|
%idxprom = zext i16 %tmp5 to i32 ; <i32> [#uses=1]
|
||||||
|
%arrayidx = getelementptr i8* %tmp6, i32 %idxprom ; <i8*> [#uses=1]
|
||||||
|
%tmp7 = load i8* %arrayidx ; <i8> [#uses=1]
|
||||||
|
%call = call zeroext i16 @crc_xmodem_update(i16 zeroext %tmp4, i8 zeroext %tmp7) ; <i16> [#uses=1]
|
||||||
|
store i16 %call, i16* %crc
|
||||||
|
br label %for.inc
|
||||||
|
|
||||||
|
for.inc: ; preds = %for.body
|
||||||
|
%tmp8 = load i16* %i ; <i16> [#uses=1]
|
||||||
|
%inc = add i16 %tmp8, 1 ; <i16> [#uses=1]
|
||||||
|
store i16 %inc, i16* %i
|
||||||
|
br label %for.cond
|
||||||
|
|
||||||
|
for.end: ; preds = %for.cond
|
||||||
|
%tmp9 = load i16* %crc ; <i16> [#uses=1]
|
||||||
|
store i16 %tmp9, i16* %retval
|
||||||
|
%0 = load i16* %retval ; <i16> [#uses=1]
|
||||||
|
ret i16 %0
|
||||||
|
}
|
||||||
|
|
||||||
|
define zeroext i16 @do_crc_update(i16 zeroext %crc, i8* %data, i16 zeroext %size) nounwind {
|
||||||
|
entry:
|
||||||
|
%retval = alloca i16 ; <i16*> [#uses=2]
|
||||||
|
%crc.addr = alloca i16 ; <i16*> [#uses=4]
|
||||||
|
%data.addr = alloca i8* ; <i8**> [#uses=2]
|
||||||
|
%size.addr = alloca i16 ; <i16*> [#uses=2]
|
||||||
|
%i = alloca i16, align 2 ; <i16*> [#uses=5]
|
||||||
|
store i16 %crc, i16* %crc.addr
|
||||||
|
store i8* %data, i8** %data.addr
|
||||||
|
store i16 %size, i16* %size.addr
|
||||||
|
store i16 0, i16* %i
|
||||||
|
br label %for.cond
|
||||||
|
|
||||||
|
for.cond: ; preds = %for.inc, %entry
|
||||||
|
%tmp = load i16* %i ; <i16> [#uses=1]
|
||||||
|
%conv = zext i16 %tmp to i32 ; <i32> [#uses=1]
|
||||||
|
%tmp1 = load i16* %size.addr ; <i16> [#uses=1]
|
||||||
|
%conv2 = zext i16 %tmp1 to i32 ; <i32> [#uses=1]
|
||||||
|
%cmp = icmp slt i32 %conv, %conv2 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp, label %for.body, label %for.end
|
||||||
|
|
||||||
|
for.body: ; preds = %for.cond
|
||||||
|
%tmp4 = load i16* %crc.addr ; <i16> [#uses=1]
|
||||||
|
%tmp5 = load i16* %i ; <i16> [#uses=1]
|
||||||
|
%tmp6 = load i8** %data.addr ; <i8*> [#uses=1]
|
||||||
|
%idxprom = zext i16 %tmp5 to i32 ; <i32> [#uses=1]
|
||||||
|
%arrayidx = getelementptr i8* %tmp6, i32 %idxprom ; <i8*> [#uses=1]
|
||||||
|
%tmp7 = load i8* %arrayidx ; <i8> [#uses=1]
|
||||||
|
%call = call zeroext i16 @crc_xmodem_update(i16 zeroext %tmp4, i8 zeroext %tmp7) ; <i16> [#uses=1]
|
||||||
|
store i16 %call, i16* %crc.addr
|
||||||
|
br label %for.inc
|
||||||
|
|
||||||
|
for.inc: ; preds = %for.body
|
||||||
|
%tmp8 = load i16* %i ; <i16> [#uses=1]
|
||||||
|
%inc = add i16 %tmp8, 1 ; <i16> [#uses=1]
|
||||||
|
store i16 %inc, i16* %i
|
||||||
|
br label %for.cond
|
||||||
|
|
||||||
|
for.end: ; preds = %for.cond
|
||||||
|
%tmp9 = load i16* %crc.addr ; <i16> [#uses=1]
|
||||||
|
store i16 %tmp9, i16* %retval
|
||||||
|
%0 = load i16* %retval ; <i16> [#uses=1]
|
||||||
|
ret i16 %0
|
||||||
|
}
|
||||||
|
|
||||||
|
define i32 @main(i32 %argc, i8** %argv) nounwind {
|
||||||
|
entry:
|
||||||
|
%retval = alloca i32 ; <i32*> [#uses=2]
|
||||||
|
%argc.addr = alloca i32 ; <i32*> [#uses=3]
|
||||||
|
%argv.addr = alloca i8** ; <i8***> [#uses=8]
|
||||||
|
%handle = alloca %struct.usb_dev_handle*, align 4 ; <%struct.usb_dev_handle**> [#uses=7]
|
||||||
|
%rawVid = alloca [2 x i8], align 1 ; <[2 x i8]*> [#uses=4]
|
||||||
|
%rawPid = alloca [2 x i8], align 1 ; <[2 x i8]*> [#uses=4]
|
||||||
|
%vendor = alloca [11 x i8], align 1 ; <[11 x i8]*> [#uses=12]
|
||||||
|
%product = alloca [8 x i8], align 1 ; <[8 x i8]*> [#uses=11]
|
||||||
|
%cnt = alloca i32, align 4 ; <i32*> [#uses=9]
|
||||||
|
%vid = alloca i32, align 4 ; <i32*> [#uses=4]
|
||||||
|
%pid = alloca i32, align 4 ; <i32*> [#uses=4]
|
||||||
|
%cnt_crc = alloca i32, align 4 ; <i32*> [#uses=6]
|
||||||
|
%read_buffer = alloca i8*, align 4 ; <i8**> [#uses=4]
|
||||||
|
%crc_buffer = alloca i8*, align 4 ; <i8**> [#uses=5]
|
||||||
|
%addr = alloca i32, align 4 ; <i32*> [#uses=11]
|
||||||
|
%addr_lo = alloca i16, align 2 ; <i16*> [#uses=7]
|
||||||
|
%addr_hi = alloca i16, align 2 ; <i16*> [#uses=7]
|
||||||
|
%step = alloca i16, align 2 ; <i16*> [#uses=6]
|
||||||
|
%crc = alloca i16, align 2 ; <i16*> [#uses=3]
|
||||||
|
%bank = alloca i8, align 1 ; <i8*> [#uses=4]
|
||||||
|
%fp = alloca %struct.__sFILE*, align 4 ; <%struct.__sFILE**> [#uses=3]
|
||||||
|
store i32 %argc, i32* %argc.addr
|
||||||
|
store i8** %argv, i8*** %argv.addr
|
||||||
|
store %struct.usb_dev_handle* null, %struct.usb_dev_handle** %handle
|
||||||
|
%.array = getelementptr [2 x i8]* %rawVid, i32 0, i32 0 ; <i8*> [#uses=1]
|
||||||
|
store i8 -64, i8* %.array
|
||||||
|
%.array1 = getelementptr [2 x i8]* %rawVid, i32 0, i32 1 ; <i8*> [#uses=1]
|
||||||
|
store i8 22, i8* %.array1
|
||||||
|
%.array2 = getelementptr [2 x i8]* %rawPid, i32 0, i32 0 ; <i8*> [#uses=1]
|
||||||
|
store i8 -36, i8* %.array2
|
||||||
|
%.array3 = getelementptr [2 x i8]* %rawPid, i32 0, i32 1 ; <i8*> [#uses=1]
|
||||||
|
store i8 5, i8* %.array3
|
||||||
|
%.array4 = getelementptr [11 x i8]* %vendor, i32 0, i32 0 ; <i8*> [#uses=1]
|
||||||
|
store i8 111, i8* %.array4
|
||||||
|
%.array5 = getelementptr [11 x i8]* %vendor, i32 0, i32 1 ; <i8*> [#uses=1]
|
||||||
|
store i8 112, i8* %.array5
|
||||||
|
%.array6 = getelementptr [11 x i8]* %vendor, i32 0, i32 2 ; <i8*> [#uses=1]
|
||||||
|
store i8 116, i8* %.array6
|
||||||
|
%.array7 = getelementptr [11 x i8]* %vendor, i32 0, i32 3 ; <i8*> [#uses=1]
|
||||||
|
store i8 105, i8* %.array7
|
||||||
|
%.array8 = getelementptr [11 x i8]* %vendor, i32 0, i32 4 ; <i8*> [#uses=1]
|
||||||
|
store i8 120, i8* %.array8
|
||||||
|
%.array9 = getelementptr [11 x i8]* %vendor, i32 0, i32 5 ; <i8*> [#uses=1]
|
||||||
|
store i8 120, i8* %.array9
|
||||||
|
%.array10 = getelementptr [11 x i8]* %vendor, i32 0, i32 6 ; <i8*> [#uses=1]
|
||||||
|
store i8 46, i8* %.array10
|
||||||
|
%.array11 = getelementptr [11 x i8]* %vendor, i32 0, i32 7 ; <i8*> [#uses=1]
|
||||||
|
store i8 111, i8* %.array11
|
||||||
|
%.array12 = getelementptr [11 x i8]* %vendor, i32 0, i32 8 ; <i8*> [#uses=1]
|
||||||
|
store i8 114, i8* %.array12
|
||||||
|
%.array13 = getelementptr [11 x i8]* %vendor, i32 0, i32 9 ; <i8*> [#uses=1]
|
||||||
|
store i8 103, i8* %.array13
|
||||||
|
%.array14 = getelementptr [11 x i8]* %vendor, i32 0, i32 10 ; <i8*> [#uses=1]
|
||||||
|
store i8 0, i8* %.array14
|
||||||
|
%.array15 = getelementptr [8 x i8]* %product, i32 0, i32 0 ; <i8*> [#uses=1]
|
||||||
|
store i8 83, i8* %.array15
|
||||||
|
%.array16 = getelementptr [8 x i8]* %product, i32 0, i32 1 ; <i8*> [#uses=1]
|
||||||
|
store i8 78, i8* %.array16
|
||||||
|
%.array17 = getelementptr [8 x i8]* %product, i32 0, i32 2 ; <i8*> [#uses=1]
|
||||||
|
store i8 69, i8* %.array17
|
||||||
|
%.array18 = getelementptr [8 x i8]* %product, i32 0, i32 3 ; <i8*> [#uses=1]
|
||||||
|
store i8 83, i8* %.array18
|
||||||
|
%.array19 = getelementptr [8 x i8]* %product, i32 0, i32 4 ; <i8*> [#uses=1]
|
||||||
|
store i8 82, i8* %.array19
|
||||||
|
%.array20 = getelementptr [8 x i8]* %product, i32 0, i32 5 ; <i8*> [#uses=1]
|
||||||
|
store i8 65, i8* %.array20
|
||||||
|
%.array21 = getelementptr [8 x i8]* %product, i32 0, i32 6 ; <i8*> [#uses=1]
|
||||||
|
store i8 77, i8* %.array21
|
||||||
|
%.array22 = getelementptr [8 x i8]* %product, i32 0, i32 7 ; <i8*> [#uses=1]
|
||||||
|
store i8 0, i8* %.array22
|
||||||
|
store i32 0, i32* %cnt_crc
|
||||||
|
store i32 0, i32* %addr
|
||||||
|
store i16 0, i16* %addr_lo
|
||||||
|
store i16 0, i16* %addr_hi
|
||||||
|
store i16 0, i16* %step
|
||||||
|
store i16 0, i16* %crc
|
||||||
|
store i8 0, i8* %bank
|
||||||
|
call void @usb_init()
|
||||||
|
%tmp = load i32* %argc.addr ; <i32> [#uses=1]
|
||||||
|
%cmp = icmp slt i32 %tmp, 2 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp, label %if.then, label %if.end
|
||||||
|
|
||||||
|
if.then: ; preds = %entry
|
||||||
|
%tmp23 = load i8*** %argv.addr ; <i8**> [#uses=1]
|
||||||
|
%arrayidx = getelementptr i8** %tmp23, i32 0 ; <i8**> [#uses=1]
|
||||||
|
%tmp24 = load i8** %arrayidx ; <i8*> [#uses=1]
|
||||||
|
call void @usage(i8* %tmp24)
|
||||||
|
call void @exit(i32 1) noreturn
|
||||||
|
unreachable
|
||||||
|
; No predecessors!
|
||||||
|
br label %if.end
|
||||||
|
|
||||||
|
if.end: ; preds = %0, %entry
|
||||||
|
%arraydecay = getelementptr [2 x i8]* %rawVid, i32 0, i32 0 ; <i8*> [#uses=1]
|
||||||
|
%arrayidx25 = getelementptr i8* %arraydecay, i32 1 ; <i8*> [#uses=1]
|
||||||
|
%tmp26 = load i8* %arrayidx25 ; <i8> [#uses=1]
|
||||||
|
%conv = zext i8 %tmp26 to i32 ; <i32> [#uses=1]
|
||||||
|
%mul = mul i32 %conv, 256 ; <i32> [#uses=1]
|
||||||
|
%arraydecay27 = getelementptr [2 x i8]* %rawVid, i32 0, i32 0 ; <i8*> [#uses=1]
|
||||||
|
%arrayidx28 = getelementptr i8* %arraydecay27, i32 0 ; <i8*> [#uses=1]
|
||||||
|
%tmp29 = load i8* %arrayidx28 ; <i8> [#uses=1]
|
||||||
|
%conv30 = zext i8 %tmp29 to i32 ; <i32> [#uses=1]
|
||||||
|
%add = add i32 %mul, %conv30 ; <i32> [#uses=1]
|
||||||
|
store i32 %add, i32* %vid
|
||||||
|
%arraydecay31 = getelementptr [2 x i8]* %rawPid, i32 0, i32 0 ; <i8*> [#uses=1]
|
||||||
|
%arrayidx32 = getelementptr i8* %arraydecay31, i32 1 ; <i8*> [#uses=1]
|
||||||
|
%tmp33 = load i8* %arrayidx32 ; <i8> [#uses=1]
|
||||||
|
%conv34 = zext i8 %tmp33 to i32 ; <i32> [#uses=1]
|
||||||
|
%mul35 = mul i32 %conv34, 256 ; <i32> [#uses=1]
|
||||||
|
%arraydecay36 = getelementptr [2 x i8]* %rawPid, i32 0, i32 0 ; <i8*> [#uses=1]
|
||||||
|
%arrayidx37 = getelementptr i8* %arraydecay36, i32 0 ; <i8*> [#uses=1]
|
||||||
|
%tmp38 = load i8* %arrayidx37 ; <i8> [#uses=1]
|
||||||
|
%conv39 = zext i8 %tmp38 to i32 ; <i32> [#uses=1]
|
||||||
|
%add40 = add i32 %mul35, %conv39 ; <i32> [#uses=1]
|
||||||
|
store i32 %add40, i32* %pid
|
||||||
|
%tmp41 = load i32* %vid ; <i32> [#uses=1]
|
||||||
|
%arraydecay42 = getelementptr [11 x i8]* %vendor, i32 0, i32 0 ; <i8*> [#uses=1]
|
||||||
|
%tmp43 = load i32* %pid ; <i32> [#uses=1]
|
||||||
|
%arraydecay44 = getelementptr [8 x i8]* %product, i32 0, i32 0 ; <i8*> [#uses=1]
|
||||||
|
%call = call i32 @usbOpenDevice(%struct.usb_dev_handle** %handle, i32 %tmp41, i8* %arraydecay42, i32 %tmp43, i8* %arraydecay44, i8* null, %struct.__sFILE* null, %struct.__sFILE* null) ; <i32> [#uses=1]
|
||||||
|
%cmp45 = icmp ne i32 %call, 0 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp45, label %if.then47, label %if.end53
|
||||||
|
|
||||||
|
if.then47: ; preds = %if.end
|
||||||
|
%tmp48 = load %struct.__sFILE** @__stderrp ; <%struct.__sFILE*> [#uses=1]
|
||||||
|
%arraydecay49 = getelementptr [8 x i8]* %product, i32 0, i32 0 ; <i8*> [#uses=1]
|
||||||
|
%tmp50 = load i32* %vid ; <i32> [#uses=1]
|
||||||
|
%tmp51 = load i32* %pid ; <i32> [#uses=1]
|
||||||
|
%call52 = call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %tmp48, i8* getelementptr ([55 x i8]* @"\01LC7", i32 0, i32 0), i8* %arraydecay49, i32 %tmp50, i32 %tmp51) ; <i32> [#uses=0]
|
||||||
|
call void @exit(i32 1) noreturn
|
||||||
|
unreachable
|
||||||
|
; No predecessors!
|
||||||
|
br label %if.end53
|
||||||
|
|
||||||
|
if.end53: ; preds = %1, %if.end
|
||||||
|
%arraydecay54 = getelementptr [8 x i8]* %product, i32 0, i32 0 ; <i8*> [#uses=1]
|
||||||
|
%tmp55 = load i32* %vid ; <i32> [#uses=1]
|
||||||
|
%tmp56 = load i32* %pid ; <i32> [#uses=1]
|
||||||
|
%call57 = call i32 (i8*, ...)* @printf(i8* getelementptr ([45 x i8]* @"\01LC8", i32 0, i32 0), i8* %arraydecay54, i32 %tmp55, i32 %tmp56) ; <i32> [#uses=0]
|
||||||
|
%tmp58 = load i8*** %argv.addr ; <i8**> [#uses=1]
|
||||||
|
%arrayidx59 = getelementptr i8** %tmp58, i32 1 ; <i8**> [#uses=1]
|
||||||
|
%tmp60 = load i8** %arrayidx59 ; <i8*> [#uses=1]
|
||||||
|
%call61 = call i32 @strcasecmp(i8* %tmp60, i8* getelementptr ([7 x i8]* @"\01LC9", i32 0, i32 0)) ; <i32> [#uses=1]
|
||||||
|
%cmp62 = icmp eq i32 %call61, 0 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp62, label %if.then64, label %if.else171
|
||||||
|
|
||||||
|
if.then64: ; preds = %if.end53
|
||||||
|
%tmp65 = load i32* %argc.addr ; <i32> [#uses=1]
|
||||||
|
%cmp66 = icmp slt i32 %tmp65, 3 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp66, label %if.then68, label %if.end72
|
||||||
|
|
||||||
|
if.then68: ; preds = %if.then64
|
||||||
|
%tmp69 = load i8*** %argv.addr ; <i8**> [#uses=1]
|
||||||
|
%arrayidx70 = getelementptr i8** %tmp69, i32 0 ; <i8**> [#uses=1]
|
||||||
|
%tmp71 = load i8** %arrayidx70 ; <i8*> [#uses=1]
|
||||||
|
call void @usage(i8* %tmp71)
|
||||||
|
call void @exit(i32 1) noreturn
|
||||||
|
unreachable
|
||||||
|
; No predecessors!
|
||||||
|
br label %if.end72
|
||||||
|
|
||||||
|
if.end72: ; preds = %2, %if.then64
|
||||||
|
%tmp73 = load i8*** %argv.addr ; <i8**> [#uses=1]
|
||||||
|
%arrayidx74 = getelementptr i8** %tmp73, i32 2 ; <i8**> [#uses=1]
|
||||||
|
%tmp75 = load i8** %arrayidx74 ; <i8*> [#uses=1]
|
||||||
|
%call76 = call %struct.__sFILE* @fopen(i8* %tmp75, i8* getelementptr ([2 x i8]* @"\01LC10", i32 0, i32 0)) ; <%struct.__sFILE*> [#uses=1]
|
||||||
|
store %struct.__sFILE* %call76, %struct.__sFILE** %fp
|
||||||
|
%tmp77 = load %struct.__sFILE** %fp ; <%struct.__sFILE*> [#uses=1]
|
||||||
|
%cmp78 = icmp eq %struct.__sFILE* %tmp77, null ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp78, label %if.then80, label %if.end86
|
||||||
|
|
||||||
|
if.then80: ; preds = %if.end72
|
||||||
|
%tmp81 = load %struct.__sFILE** @__stderrp ; <%struct.__sFILE*> [#uses=1]
|
||||||
|
%tmp82 = load i8*** %argv.addr ; <i8**> [#uses=1]
|
||||||
|
%arrayidx83 = getelementptr i8** %tmp82, i32 2 ; <i8**> [#uses=1]
|
||||||
|
%tmp84 = load i8** %arrayidx83 ; <i8*> [#uses=1]
|
||||||
|
%call85 = call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %tmp81, i8* getelementptr ([21 x i8]* @"\01LC11", i32 0, i32 0), i8* %tmp84) ; <i32> [#uses=0]
|
||||||
|
call void @exit(i32 1) noreturn
|
||||||
|
unreachable
|
||||||
|
; No predecessors!
|
||||||
|
br label %if.end86
|
||||||
|
|
||||||
|
if.end86: ; preds = %3, %if.end72
|
||||||
|
%call87 = call i8* @malloc(i32 1024) ; <i8*> [#uses=1]
|
||||||
|
store i8* %call87, i8** %read_buffer
|
||||||
|
%call88 = call i8* @malloc(i32 32768) ; <i8*> [#uses=1]
|
||||||
|
store i8* %call88, i8** %crc_buffer
|
||||||
|
%tmp89 = load i8** %crc_buffer ; <i8*> [#uses=1]
|
||||||
|
%call90 = call i8* @memset(i8* %tmp89, i32 0, i32 32768) ; <i8*> [#uses=0]
|
||||||
|
store i32 0, i32* %addr
|
||||||
|
%tmp91 = load %struct.usb_dev_handle** %handle ; <%struct.usb_dev_handle*> [#uses=1]
|
||||||
|
%call92 = call i32 @usb_control_msg(%struct.usb_dev_handle* %tmp91, i32 64, i32 0, i32 0, i32 0, i8* null, i32 0, i32 5000) ; <i32> [#uses=0]
|
||||||
|
br label %while.cond
|
||||||
|
|
||||||
|
while.cond: ; preds = %if.end148, %if.end86
|
||||||
|
%tmp93 = load i8** %read_buffer ; <i8*> [#uses=1]
|
||||||
|
%tmp94 = load %struct.__sFILE** %fp ; <%struct.__sFILE*> [#uses=1]
|
||||||
|
%call95 = call i32 @fread(i8* %tmp93, i32 1024, i32 1, %struct.__sFILE* %tmp94) ; <i32> [#uses=2]
|
||||||
|
store i32 %call95, i32* %cnt
|
||||||
|
%cmp96 = icmp sgt i32 %call95, 0 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp96, label %while.body, label %while.end
|
||||||
|
|
||||||
|
while.body: ; preds = %while.cond
|
||||||
|
store i16 0, i16* %step
|
||||||
|
br label %for.cond
|
||||||
|
|
||||||
|
for.cond: ; preds = %for.inc, %while.body
|
||||||
|
%tmp98 = load i16* %step ; <i16> [#uses=1]
|
||||||
|
%conv99 = zext i16 %tmp98 to i32 ; <i32> [#uses=1]
|
||||||
|
%cmp100 = icmp slt i32 %conv99, 1024 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp100, label %for.body, label %for.end
|
||||||
|
|
||||||
|
for.body: ; preds = %for.cond
|
||||||
|
%tmp102 = load i32* %addr ; <i32> [#uses=1]
|
||||||
|
%and = and i32 %tmp102, 65535 ; <i32> [#uses=1]
|
||||||
|
%conv103 = trunc i32 %and to i16 ; <i16> [#uses=1]
|
||||||
|
store i16 %conv103, i16* %addr_lo
|
||||||
|
%tmp104 = load i32* %addr ; <i32> [#uses=1]
|
||||||
|
%shr = lshr i32 %tmp104, 16 ; <i32> [#uses=1]
|
||||||
|
%and105 = and i32 %shr, 255 ; <i32> [#uses=1]
|
||||||
|
%conv106 = trunc i32 %and105 to i16 ; <i16> [#uses=1]
|
||||||
|
store i16 %conv106, i16* %addr_hi
|
||||||
|
%tmp107 = load %struct.usb_dev_handle** %handle ; <%struct.usb_dev_handle*> [#uses=1]
|
||||||
|
%tmp108 = load i16* %addr_hi ; <i16> [#uses=1]
|
||||||
|
%conv109 = zext i16 %tmp108 to i32 ; <i32> [#uses=1]
|
||||||
|
%tmp110 = load i16* %addr_lo ; <i16> [#uses=1]
|
||||||
|
%conv111 = zext i16 %tmp110 to i32 ; <i32> [#uses=1]
|
||||||
|
%tmp112 = load i8** %read_buffer ; <i8*> [#uses=1]
|
||||||
|
%tmp113 = load i16* %step ; <i16> [#uses=1]
|
||||||
|
%conv114 = zext i16 %tmp113 to i32 ; <i32> [#uses=1]
|
||||||
|
%add.ptr = getelementptr i8* %tmp112, i32 %conv114 ; <i8*> [#uses=1]
|
||||||
|
%call115 = call i32 @usb_control_msg(%struct.usb_dev_handle* %tmp107, i32 64, i32 1, i32 %conv109, i32 %conv111, i8* %add.ptr, i32 128, i32 5000) ; <i32> [#uses=0]
|
||||||
|
%tmp116 = load i32* %addr ; <i32> [#uses=1]
|
||||||
|
%add117 = add i32 %tmp116, 128 ; <i32> [#uses=1]
|
||||||
|
store i32 %add117, i32* %addr
|
||||||
|
br label %for.inc
|
||||||
|
|
||||||
|
for.inc: ; preds = %for.body
|
||||||
|
%tmp118 = load i16* %step ; <i16> [#uses=1]
|
||||||
|
%conv119 = zext i16 %tmp118 to i32 ; <i32> [#uses=1]
|
||||||
|
%add120 = add i32 %conv119, 128 ; <i32> [#uses=1]
|
||||||
|
%conv121 = trunc i32 %add120 to i16 ; <i16> [#uses=1]
|
||||||
|
store i16 %conv121, i16* %step
|
||||||
|
br label %for.cond
|
||||||
|
|
||||||
|
for.end: ; preds = %for.cond
|
||||||
|
%tmp122 = load i8** %crc_buffer ; <i8*> [#uses=1]
|
||||||
|
%tmp123 = load i32* %cnt_crc ; <i32> [#uses=1]
|
||||||
|
%add.ptr124 = getelementptr i8* %tmp122, i32 %tmp123 ; <i8*> [#uses=1]
|
||||||
|
%tmp125 = load i8** %read_buffer ; <i8*> [#uses=1]
|
||||||
|
%call126 = call i8* @memcpy(i8* %add.ptr124, i8* %tmp125, i32 1024) ; <i8*> [#uses=0]
|
||||||
|
%tmp127 = load i32* %cnt_crc ; <i32> [#uses=1]
|
||||||
|
%add128 = add i32 %tmp127, 1024 ; <i32> [#uses=1]
|
||||||
|
store i32 %add128, i32* %cnt_crc
|
||||||
|
%tmp129 = load i32* %cnt_crc ; <i32> [#uses=1]
|
||||||
|
%cmp130 = icmp sge i32 %tmp129, 32768 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp130, label %if.then132, label %if.end148
|
||||||
|
|
||||||
|
if.then132: ; preds = %for.end
|
||||||
|
%tmp133 = load i8** %crc_buffer ; <i8*> [#uses=1]
|
||||||
|
%call134 = call zeroext i16 @do_crc(i8* %tmp133, i16 zeroext -32768) ; <i16> [#uses=1]
|
||||||
|
store i16 %call134, i16* %crc
|
||||||
|
%tmp135 = load i32* %addr ; <i32> [#uses=1]
|
||||||
|
%tmp136 = load i8* %bank ; <i8> [#uses=1]
|
||||||
|
%conv137 = zext i8 %tmp136 to i32 ; <i32> [#uses=1]
|
||||||
|
%tmp138 = load i16* %addr_hi ; <i16> [#uses=1]
|
||||||
|
%conv139 = zext i16 %tmp138 to i32 ; <i32> [#uses=1]
|
||||||
|
%tmp140 = load i16* %addr_lo ; <i16> [#uses=1]
|
||||||
|
%conv141 = zext i16 %tmp140 to i32 ; <i32> [#uses=1]
|
||||||
|
%tmp142 = load i16* %crc ; <i16> [#uses=1]
|
||||||
|
%conv143 = zext i16 %tmp142 to i32 ; <i32> [#uses=1]
|
||||||
|
%call144 = call i32 (i8*, ...)* @printf(i8* getelementptr ([70 x i8]* @"\01LC12", i32 0, i32 0), i32 %tmp135, i32 %conv137, i32 %conv139, i32 %conv141, i32 %conv143) ; <i32> [#uses=0]
|
||||||
|
%tmp145 = load i8** %crc_buffer ; <i8*> [#uses=1]
|
||||||
|
%call146 = call i8* @memset(i8* %tmp145, i32 0, i32 32768) ; <i8*> [#uses=0]
|
||||||
|
%tmp147 = load i8* %bank ; <i8> [#uses=1]
|
||||||
|
%inc = add i8 %tmp147, 1 ; <i8> [#uses=1]
|
||||||
|
store i8 %inc, i8* %bank
|
||||||
|
store i32 0, i32* %cnt_crc
|
||||||
|
br label %if.end148
|
||||||
|
|
||||||
|
if.end148: ; preds = %if.then132, %for.end
|
||||||
|
br label %while.cond
|
||||||
|
|
||||||
|
while.end: ; preds = %while.cond
|
||||||
|
%tmp149 = load %struct.usb_dev_handle** %handle ; <%struct.usb_dev_handle*> [#uses=1]
|
||||||
|
%tmp150 = load i16* %addr_hi ; <i16> [#uses=1]
|
||||||
|
%conv151 = zext i16 %tmp150 to i32 ; <i32> [#uses=1]
|
||||||
|
%tmp152 = load i16* %addr_lo ; <i16> [#uses=1]
|
||||||
|
%conv153 = zext i16 %tmp152 to i32 ; <i32> [#uses=1]
|
||||||
|
%call154 = call i32 @usb_control_msg(%struct.usb_dev_handle* %tmp149, i32 64, i32 4, i32 %conv151, i32 %conv153, i8* null, i32 0, i32 5000) ; <i32> [#uses=1]
|
||||||
|
store i32 %call154, i32* %cnt
|
||||||
|
%tmp155 = load i32* %cnt ; <i32> [#uses=1]
|
||||||
|
%cmp156 = icmp slt i32 %tmp155, 1 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp156, label %if.then158, label %if.end170
|
||||||
|
|
||||||
|
if.then158: ; preds = %while.end
|
||||||
|
%tmp159 = load i32* %cnt ; <i32> [#uses=1]
|
||||||
|
%cmp160 = icmp slt i32 %tmp159, 0 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp160, label %if.then162, label %if.else
|
||||||
|
|
||||||
|
if.then162: ; preds = %if.then158
|
||||||
|
%tmp163 = load %struct.__sFILE** @__stderrp ; <%struct.__sFILE*> [#uses=1]
|
||||||
|
%call164 = call i8* @usb_strerror() ; <i8*> [#uses=1]
|
||||||
|
%call165 = call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %tmp163, i8* getelementptr ([15 x i8]* @"\01LC13", i32 0, i32 0), i8* %call164) ; <i32> [#uses=0]
|
||||||
|
br label %if.end169
|
||||||
|
|
||||||
|
if.else: ; preds = %if.then158
|
||||||
|
%tmp166 = load %struct.__sFILE** @__stderrp ; <%struct.__sFILE*> [#uses=1]
|
||||||
|
%tmp167 = load i32* %cnt ; <i32> [#uses=1]
|
||||||
|
%call168 = call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %tmp166, i8* getelementptr ([25 x i8]* @"\01LC14", i32 0, i32 0), i32 %tmp167) ; <i32> [#uses=0]
|
||||||
|
br label %if.end169
|
||||||
|
|
||||||
|
if.end169: ; preds = %if.else, %if.then162
|
||||||
|
br label %if.end170
|
||||||
|
|
||||||
|
if.end170: ; preds = %if.end169, %while.end
|
||||||
|
br label %if.end216
|
||||||
|
|
||||||
|
if.else171: ; preds = %if.end53
|
||||||
|
%tmp172 = load i8*** %argv.addr ; <i8**> [#uses=1]
|
||||||
|
%arrayidx173 = getelementptr i8** %tmp172, i32 1 ; <i8**> [#uses=1]
|
||||||
|
%tmp174 = load i8** %arrayidx173 ; <i8*> [#uses=1]
|
||||||
|
%call175 = call i32 @strcasecmp(i8* %tmp174, i8* getelementptr ([4 x i8]* @"\01LC15", i32 0, i32 0)) ; <i32> [#uses=1]
|
||||||
|
%cmp176 = icmp eq i32 %call175, 0 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp176, label %if.then178, label %if.else211
|
||||||
|
|
||||||
|
if.then178: ; preds = %if.else171
|
||||||
|
store i32 0, i32* %addr
|
||||||
|
%tmp179 = load i32* %addr ; <i32> [#uses=1]
|
||||||
|
%and180 = and i32 %tmp179, 65535 ; <i32> [#uses=1]
|
||||||
|
%conv181 = trunc i32 %and180 to i16 ; <i16> [#uses=1]
|
||||||
|
store i16 %conv181, i16* %addr_lo
|
||||||
|
%tmp182 = load i32* %addr ; <i32> [#uses=1]
|
||||||
|
%shr183 = lshr i32 %tmp182, 16 ; <i32> [#uses=1]
|
||||||
|
%and184 = and i32 %shr183, 255 ; <i32> [#uses=1]
|
||||||
|
%conv185 = trunc i32 %and184 to i16 ; <i16> [#uses=1]
|
||||||
|
store i16 %conv185, i16* %addr_hi
|
||||||
|
%tmp186 = load i32* %addr ; <i32> [#uses=1]
|
||||||
|
%call187 = call i32 (i8*, ...)* @printf(i8* getelementptr ([30 x i8]* @"\01LC16", i32 0, i32 0), i32 %tmp186) ; <i32> [#uses=0]
|
||||||
|
%tmp188 = load %struct.usb_dev_handle** %handle ; <%struct.usb_dev_handle*> [#uses=1]
|
||||||
|
%tmp189 = load i16* %addr_hi ; <i16> [#uses=1]
|
||||||
|
%conv190 = zext i16 %tmp189 to i32 ; <i32> [#uses=1]
|
||||||
|
%tmp191 = load i16* %addr_lo ; <i16> [#uses=1]
|
||||||
|
%conv192 = zext i16 %tmp191 to i32 ; <i32> [#uses=1]
|
||||||
|
%call193 = call i32 @usb_control_msg(%struct.usb_dev_handle* %tmp188, i32 64, i32 5, i32 %conv190, i32 %conv192, i8* null, i32 8192, i32 5000) ; <i32> [#uses=1]
|
||||||
|
store i32 %call193, i32* %cnt
|
||||||
|
%tmp194 = load i32* %cnt ; <i32> [#uses=1]
|
||||||
|
%cmp195 = icmp slt i32 %tmp194, 1 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp195, label %if.then197, label %if.end210
|
||||||
|
|
||||||
|
if.then197: ; preds = %if.then178
|
||||||
|
%tmp198 = load i32* %cnt ; <i32> [#uses=1]
|
||||||
|
%cmp199 = icmp slt i32 %tmp198, 0 ; <i1> [#uses=1]
|
||||||
|
br i1 %cmp199, label %if.then201, label %if.else205
|
||||||
|
|
||||||
|
if.then201: ; preds = %if.then197
|
||||||
|
%tmp202 = load %struct.__sFILE** @__stderrp ; <%struct.__sFILE*> [#uses=1]
|
||||||
|
%call203 = call i8* @usb_strerror() ; <i8*> [#uses=1]
|
||||||
|
%call204 = call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %tmp202, i8* getelementptr ([15 x i8]* @"\01LC13", i32 0, i32 0), i8* %call203) ; <i32> [#uses=0]
|
||||||
|
br label %if.end209
|
||||||
|
|
||||||
|
if.else205: ; preds = %if.then197
|
||||||
|
%tmp206 = load %struct.__sFILE** @__stderrp ; <%struct.__sFILE*> [#uses=1]
|
||||||
|
%tmp207 = load i32* %cnt ; <i32> [#uses=1]
|
||||||
|
%call208 = call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %tmp206, i8* getelementptr ([25 x i8]* @"\01LC14", i32 0, i32 0), i32 %tmp207) ; <i32> [#uses=0]
|
||||||
|
br label %if.end209
|
||||||
|
|
||||||
|
if.end209: ; preds = %if.else205, %if.then201
|
||||||
|
br label %if.end210
|
||||||
|
|
||||||
|
if.end210: ; preds = %if.end209, %if.then178
|
||||||
|
br label %if.end215
|
||||||
|
|
||||||
|
if.else211: ; preds = %if.else171
|
||||||
|
%tmp212 = load i8*** %argv.addr ; <i8**> [#uses=1]
|
||||||
|
%arrayidx213 = getelementptr i8** %tmp212, i32 0 ; <i8**> [#uses=1]
|
||||||
|
%tmp214 = load i8** %arrayidx213 ; <i8*> [#uses=1]
|
||||||
|
call void @usage(i8* %tmp214)
|
||||||
|
call void @exit(i32 1) noreturn
|
||||||
|
unreachable
|
||||||
|
; No predecessors!
|
||||||
|
br label %if.end215
|
||||||
|
|
||||||
|
if.end215: ; preds = %4, %if.end210
|
||||||
|
br label %if.end216
|
||||||
|
|
||||||
|
if.end216: ; preds = %if.end215, %if.end170
|
||||||
|
%tmp217 = load %struct.usb_dev_handle** %handle ; <%struct.usb_dev_handle*> [#uses=1]
|
||||||
|
%call218 = call i32 @usb_close(%struct.usb_dev_handle* %tmp217) ; <i32> [#uses=0]
|
||||||
|
store i32 0, i32* %retval
|
||||||
|
%5 = load i32* %retval ; <i32> [#uses=1]
|
||||||
|
ret i32 %5
|
||||||
|
}
|
||||||
|
|
||||||
|
declare void @usb_init()
|
||||||
|
|
||||||
|
define internal void @usage(i8* %name) nounwind {
|
||||||
|
entry:
|
||||||
|
%name.addr = alloca i8* ; <i8**> [#uses=2]
|
||||||
|
store i8* %name, i8** %name.addr
|
||||||
|
%tmp = load %struct.__sFILE** @__stderrp ; <%struct.__sFILE*> [#uses=1]
|
||||||
|
%call = call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %tmp, i8* getelementptr ([8 x i8]* @"\01LC17", i32 0, i32 0)) ; <i32> [#uses=0]
|
||||||
|
%tmp1 = load %struct.__sFILE** @__stderrp ; <%struct.__sFILE*> [#uses=1]
|
||||||
|
%tmp2 = load i8** %name.addr ; <i8*> [#uses=1]
|
||||||
|
%call3 = call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %tmp1, i8* getelementptr ([31 x i8]* @"\01LC18", i32 0, i32 0), i8* %tmp2) ; <i32> [#uses=0]
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare void @exit(i32) noreturn
|
||||||
|
|
||||||
|
declare i32 @usbOpenDevice(%struct.usb_dev_handle**, i32, i8*, i32, i8*, i8*, %struct.__sFILE*, %struct.__sFILE*)
|
||||||
|
|
||||||
|
declare i32 @fprintf(%struct.__sFILE*, i8*, ...)
|
||||||
|
|
||||||
|
declare i32 @strcasecmp(i8*, i8*)
|
||||||
|
|
||||||
|
declare %struct.__sFILE* @fopen(i8*, i8*)
|
||||||
|
|
||||||
|
declare i8* @malloc(i32)
|
||||||
|
|
||||||
|
declare i8* @memset(i8*, i32, i32)
|
||||||
|
|
||||||
|
declare i32 @usb_control_msg(%struct.usb_dev_handle*, i32, i32, i32, i32, i8*, i32, i32)
|
||||||
|
|
||||||
|
declare i32 @fread(i8*, i32, i32, %struct.__sFILE*)
|
||||||
|
|
||||||
|
declare i8* @memcpy(i8*, i8*, i32)
|
||||||
|
|
||||||
|
declare i8* @usb_strerror()
|
||||||
|
|
||||||
|
declare i32 @usb_close(%struct.usb_dev_handle*)
|
||||||
57
avr/usbload/config.h
Normal file
57
avr/usbload/config.h
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __CONFIH_H__
|
||||||
|
#define __CONFIH_H__
|
||||||
|
|
||||||
|
|
||||||
|
#define DEBUG 1
|
||||||
|
#define DEBUG_USB 2
|
||||||
|
#define DEBUG_USB_TRANS 4
|
||||||
|
#define DEBUG_SRAM 8
|
||||||
|
#define DEBUG_SRAM_RAW 16
|
||||||
|
#define DEBUG_SREG 32
|
||||||
|
#define DEBUG_CRC 64
|
||||||
|
#define DEBUG_SHM 128
|
||||||
|
|
||||||
|
#define REQ_STATUS_IDLE 0x01
|
||||||
|
#define REQ_STATUS_UPLOAD 0x02
|
||||||
|
#define REQ_STATUS_BULK_UPLOAD 0x03
|
||||||
|
#define REQ_STATUS_BULK_NEXT 0x04
|
||||||
|
#define REQ_STATUS_CRC 0x05
|
||||||
|
#define REQ_STATUS_SNES 0x06
|
||||||
|
#define REQ_STATUS_AVR 0x07
|
||||||
|
|
||||||
|
#define USB_MAX_TRANS 0xff
|
||||||
|
#define USB_CRC_CHECK 0x01
|
||||||
|
|
||||||
|
#define TRANSFER_BUFFER_SIZE 0x000
|
||||||
|
#define FORMAT_BUFFER_LEN 0x080
|
||||||
|
#define RECEIVE_BUF_LEN 0x030
|
||||||
|
#define HW_VERSION "2.6"
|
||||||
|
#define SW_VERSION "1.0"
|
||||||
|
|
||||||
|
#define DO_CRC_CHECK_LOADER 0
|
||||||
|
#define DO_CRC_CHECK 0
|
||||||
|
#define DO_SHM_SCRATCHPAD 0
|
||||||
|
#define DO_SHM 0
|
||||||
|
#define DO_TIMER 0
|
||||||
|
|
||||||
|
#endif
|
||||||
106
avr/usbload/crc.c
Normal file
106
avr/usbload/crc.c
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "crc.h"
|
||||||
|
#include "uart.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "sram.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "info.h"
|
||||||
|
|
||||||
|
extern FILE uart_stdout;
|
||||||
|
|
||||||
|
uint16_t crc_xmodem_update(uint16_t crc, uint8_t data)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
crc = crc ^ ((uint16_t) data << 8);
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
if (crc & 0x8000)
|
||||||
|
crc = (crc << 1) ^ 0x1021;
|
||||||
|
else
|
||||||
|
crc <<= 1;
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t do_crc(uint8_t * data, uint16_t size)
|
||||||
|
{
|
||||||
|
uint16_t crc = 0;
|
||||||
|
uint16_t i;
|
||||||
|
for (i = 0; i < size; i++) {
|
||||||
|
crc = crc_xmodem_update(crc, data[i]);
|
||||||
|
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t do_crc_update(uint16_t crc, uint8_t * data, uint16_t size)
|
||||||
|
{
|
||||||
|
uint16_t i;
|
||||||
|
for (i = 0; i < size; i++)
|
||||||
|
crc = crc_xmodem_update(crc, data[i]);
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t crc_check_bulk_memory(uint32_t bottom_addr, uint32_t top_addr, uint32_t bank_size)
|
||||||
|
{
|
||||||
|
uint16_t crc = 0;
|
||||||
|
uint32_t addr = 0;
|
||||||
|
uint8_t req_bank = 0;
|
||||||
|
sram_bulk_read_start(bottom_addr);
|
||||||
|
debug_P(DEBUG_CRC, PSTR("crc_check_bulk_memory: bottom_addr=0x%08lx top_addr=0x%08lx\n"),
|
||||||
|
bottom_addr,top_addr);
|
||||||
|
|
||||||
|
for (addr = bottom_addr; addr < top_addr; addr++) {
|
||||||
|
if (addr && ((addr % bank_size) == 0)) {
|
||||||
|
debug_P(DEBUG_CRC, PSTR("crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n"),
|
||||||
|
req_bank,addr,crc);
|
||||||
|
req_bank++;
|
||||||
|
crc = 0;
|
||||||
|
}
|
||||||
|
crc = crc_xmodem_update(crc, sram_bulk_read());
|
||||||
|
sram_bulk_read_next();
|
||||||
|
}
|
||||||
|
if (addr % 0x8000 == 0)
|
||||||
|
debug_P(DEBUG_CRC, PSTR("crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n"),
|
||||||
|
req_bank,addr,crc);
|
||||||
|
sram_bulk_read_end();
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t crc_check_memory_range(uint32_t start_addr, uint32_t size,uint8_t *buffer)
|
||||||
|
{
|
||||||
|
uint16_t crc = 0;
|
||||||
|
uint32_t addr;
|
||||||
|
for (addr = start_addr; addr < start_addr + size; addr += TRANSFER_BUFFER_SIZE) {
|
||||||
|
sram_bulk_copy_into_buffer(addr, buffer, TRANSFER_BUFFER_SIZE);
|
||||||
|
crc = do_crc_update(crc, buffer, TRANSFER_BUFFER_SIZE);
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
35
avr/usbload/crc.h
Normal file
35
avr/usbload/crc.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __CRC_H__
|
||||||
|
#define __CRC_H__
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t crc_xmodem_update(uint16_t crc, uint8_t data);
|
||||||
|
uint16_t do_crc(uint8_t * data,uint16_t size);
|
||||||
|
uint16_t do_crc_update(uint16_t crc,uint8_t * data,uint16_t size);
|
||||||
|
uint16_t crc_check_memory_range(uint32_t start_addr, uint32_t size,uint8_t *buffer);
|
||||||
|
uint16_t crc_check_bulk_memory(uint32_t bottom_addr, uint32_t bank_size,uint32_t top_addr);
|
||||||
|
|
||||||
|
#endif
|
||||||
54
avr/usbload/debug.c
Normal file
54
avr/usbload/debug.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
#include "uart.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
extern FILE uart_stdout;
|
||||||
|
|
||||||
|
extern int debug_level; /* the higher, the more messages... */
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef NO_INFO
|
||||||
|
uint8_t buffer_debug[FORMAT_BUFFER_LEN];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(NO_DEBUG) && defined(__GNUC__)
|
||||||
|
#else
|
||||||
|
void debug_P(int level, PGM_P format, ...) {
|
||||||
|
#ifdef NO_DEBUG
|
||||||
|
|
||||||
|
#else
|
||||||
|
va_list args;
|
||||||
|
if (!(debug_level & level))
|
||||||
|
return;
|
||||||
|
strlcpy_P((char*)buffer_debug,format,FORMAT_BUFFER_LEN);
|
||||||
|
va_start(args, format);
|
||||||
|
vprintf((char*)buffer_debug, args);
|
||||||
|
va_end(args);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
55
avr/usbload/debug.h
Normal file
55
avr/usbload/debug.h
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __DEBUG_H__
|
||||||
|
#define __DEBUG_H__
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
#if defined(NO_DEBUG) && defined(__GNUC__)
|
||||||
|
/* gcc's cpp has extensions; it allows for macros with a variable number of
|
||||||
|
arguments. We use this extension here to preprocess pmesg away. */
|
||||||
|
#define debug(level, format, args...) ((void)0)
|
||||||
|
#else
|
||||||
|
void debug(int level, char *format, ...);
|
||||||
|
/* print a message, if it is considered significant enough.
|
||||||
|
Adapted from [K&R2], p. 174 */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(NO_DEBUG) && defined(__GNUC__)
|
||||||
|
/* gcc's cpp has extensions; it allows for macros with a variable number of
|
||||||
|
arguments. We use this extension here to preprocess pmesg away. */
|
||||||
|
#define debug_P(level, format, args...) ((void)0)
|
||||||
|
#else
|
||||||
|
void debug_P(int level, PGM_P format, ...);
|
||||||
|
/* print a message, if it is considered significant enough.
|
||||||
|
Adapted from [K&R2], p. 174 */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* DEBUG_H */
|
||||||
|
|
||||||
83
avr/usbload/dump.c
Normal file
83
avr/usbload/dump.c
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
#include "info.h"
|
||||||
|
#include "uart.h"
|
||||||
|
#include "sram.h"
|
||||||
|
#include "dump.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern FILE uart_stdout;
|
||||||
|
|
||||||
|
void dump_packet(uint32_t addr, uint32_t len, uint8_t * packet)
|
||||||
|
{
|
||||||
|
uint16_t i,j;
|
||||||
|
uint16_t sum = 0;
|
||||||
|
uint8_t clear = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < len; i += 16) {
|
||||||
|
|
||||||
|
sum = 0;
|
||||||
|
for (j = 0; j < 16; j++) {
|
||||||
|
sum += packet[i + j];
|
||||||
|
}
|
||||||
|
if (!sum) {
|
||||||
|
clear = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (clear) {
|
||||||
|
info_P(PSTR("*\n"));
|
||||||
|
clear = 0;
|
||||||
|
}
|
||||||
|
info_P(PSTR("%08lx:"), addr + i);
|
||||||
|
for (j = 0; j < 16; j++) {
|
||||||
|
info_P(PSTR(" %02x"), packet[i + j]);
|
||||||
|
}
|
||||||
|
info_P(PSTR(" |"));
|
||||||
|
for (j = 0; j < 16; j++) {
|
||||||
|
if (packet[i + j] >= 33 && packet[i + j] <= 126)
|
||||||
|
info_P(PSTR("%c"), packet[i + j]);
|
||||||
|
else
|
||||||
|
info_P(PSTR("."));
|
||||||
|
}
|
||||||
|
info_P(PSTR("|\n"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_memory(uint32_t bottom_addr, uint32_t top_addr)
|
||||||
|
{
|
||||||
|
uint32_t addr;
|
||||||
|
uint8_t byte;
|
||||||
|
sram_bulk_read_start(bottom_addr);
|
||||||
|
for ( addr = bottom_addr; addr < top_addr; addr++) {
|
||||||
|
if (addr%0x10 == 0)
|
||||||
|
info_P(PSTR("\n%08lx:"), addr);
|
||||||
|
byte = sram_bulk_read();
|
||||||
|
sram_bulk_read_next();
|
||||||
|
info_P(PSTR(" %02x"), byte);
|
||||||
|
}
|
||||||
|
info_P(PSTR("\n"));
|
||||||
|
sram_bulk_read_end();
|
||||||
|
}
|
||||||
34
avr/usbload/dump.h
Normal file
34
avr/usbload/dump.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __DUMP_H__
|
||||||
|
#define __DUMP_H__
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
void dump_memory(uint32_t bottom_addr, uint32_t top_addr);
|
||||||
|
|
||||||
|
void dump_packet(uint32_t addr,uint32_t len,uint8_t *packet);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
50
avr/usbload/fifo.c
Normal file
50
avr/usbload/fifo.c
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "fifo.h"
|
||||||
|
|
||||||
|
void fifo_init(fifo_t * f, uint8_t * buffer, const uint8_t size)
|
||||||
|
{
|
||||||
|
f->count = 0;
|
||||||
|
f->pread = f->pwrite = buffer;
|
||||||
|
f->read2end = f->write2end = f->size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t fifo_put(fifo_t * f, const uint8_t data)
|
||||||
|
{
|
||||||
|
return _inline_fifo_put(f, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t fifo_get_wait(fifo_t * f)
|
||||||
|
{
|
||||||
|
while (!f->count);
|
||||||
|
|
||||||
|
return _inline_fifo_get(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
int fifo_get_nowait(fifo_t * f)
|
||||||
|
{
|
||||||
|
if (!f->count)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return (int) _inline_fifo_get(f);
|
||||||
|
}
|
||||||
88
avr/usbload/fifo.h
Normal file
88
avr/usbload/fifo.h
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
#ifndef __FIFO_H__
|
||||||
|
#define __FIFO_H__
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t volatile count; // # Zeichen im Puffer
|
||||||
|
uint8_t size; // Puffer-Größe
|
||||||
|
uint8_t *pread; // Lesezeiger
|
||||||
|
uint8_t *pwrite; // Schreibzeiger
|
||||||
|
uint8_t read2end, write2end; // # Zeichen bis zum Überlauf Lese-/Schreibzeiger
|
||||||
|
} fifo_t;
|
||||||
|
|
||||||
|
extern void fifo_init(fifo_t *, uint8_t * buf, const uint8_t size);
|
||||||
|
extern uint8_t fifo_put(fifo_t *, const uint8_t data);
|
||||||
|
extern uint8_t fifo_get_wait(fifo_t *);
|
||||||
|
extern int fifo_get_nowait(fifo_t *);
|
||||||
|
|
||||||
|
static inline uint8_t _inline_fifo_put(fifo_t * f, const uint8_t data)
|
||||||
|
{
|
||||||
|
if (f->count >= f->size)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
uint8_t *pwrite = f->pwrite;
|
||||||
|
|
||||||
|
*(pwrite++) = data;
|
||||||
|
|
||||||
|
uint8_t write2end = f->write2end;
|
||||||
|
|
||||||
|
if (--write2end == 0) {
|
||||||
|
write2end = f->size;
|
||||||
|
pwrite -= write2end;
|
||||||
|
}
|
||||||
|
|
||||||
|
f->write2end = write2end;
|
||||||
|
f->pwrite = pwrite;
|
||||||
|
|
||||||
|
uint8_t sreg = SREG;
|
||||||
|
cli();
|
||||||
|
f->count++;
|
||||||
|
SREG = sreg;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint8_t _inline_fifo_get(fifo_t * f)
|
||||||
|
{
|
||||||
|
uint8_t *pread = f->pread;
|
||||||
|
uint8_t data = *(pread++);
|
||||||
|
uint8_t read2end = f->read2end;
|
||||||
|
|
||||||
|
if (--read2end == 0) {
|
||||||
|
read2end = f->size;
|
||||||
|
pread -= read2end;
|
||||||
|
}
|
||||||
|
|
||||||
|
f->pread = pread;
|
||||||
|
f->read2end = read2end;
|
||||||
|
|
||||||
|
uint8_t sreg = SREG;
|
||||||
|
cli();
|
||||||
|
f->count--;
|
||||||
|
SREG = sreg;
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* _FIFO_H_ */
|
||||||
85
avr/usbload/inflate.c
Normal file
85
avr/usbload/inflate.c
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 09/22/2009
|
||||||
|
* Author: jannis@harderweb.de
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "neginf/neginf.h"
|
||||||
|
#include "inflate.h"
|
||||||
|
#include "assert.h"
|
||||||
|
#include "ringbuffer.h"
|
||||||
|
|
||||||
|
char inflate_done = 0;
|
||||||
|
char *mem_ref;
|
||||||
|
|
||||||
|
int addr_ref = 0;
|
||||||
|
|
||||||
|
int cnt_hit = 0;
|
||||||
|
int cnt = 0;
|
||||||
|
|
||||||
|
|
||||||
|
void inflate_init()
|
||||||
|
{
|
||||||
|
neginf_init(0);
|
||||||
|
mem_ref = (char*)malloc(2<<15);
|
||||||
|
addr_ref = 0;
|
||||||
|
rb_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
void inflate_flush()
|
||||||
|
{
|
||||||
|
|
||||||
|
rb_flush();
|
||||||
|
FILE *file;
|
||||||
|
printf("write out_ref.smc\n");
|
||||||
|
file = fopen("out_ref.smc","w");
|
||||||
|
fwrite(mem_ref,2<<15,1,file);
|
||||||
|
fclose(file);
|
||||||
|
printf("cnt=%i cnt_hit=%i\n",cnt,cnt_hit);
|
||||||
|
}
|
||||||
|
|
||||||
|
void neginf_cb_completed()
|
||||||
|
{
|
||||||
|
inflate_done = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void neginf_cb_seq_byte(nbyte byte)
|
||||||
|
{
|
||||||
|
mem_ref[addr_ref++] = byte;
|
||||||
|
rb_put(byte);
|
||||||
|
}
|
||||||
|
|
||||||
|
void neginf_cb_copy(nsize from, nsize to, nint length)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
cnt++;
|
||||||
|
if ((to - from) < ( 1024 * 2 ) ){
|
||||||
|
cnt_hit++;
|
||||||
|
}
|
||||||
|
printf("neginf_cb_copy from=0x%06x to=0x%06x dist=%i len=%i\n",(int)from, (int)to, (int)(to - from), (int)length);
|
||||||
|
for (i=0; i<length;i++){
|
||||||
|
mem_ref[to+i] = mem_ref[from+i];
|
||||||
|
}
|
||||||
|
addr_ref = to + length;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
28
avr/usbload/inflate.h
Normal file
28
avr/usbload/inflate.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 09/22/2009
|
||||||
|
* Author: jannis@harderweb.de
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __INFLATE_H__
|
||||||
|
#define __INFLATE_H__
|
||||||
|
|
||||||
|
extern char inflate_done;
|
||||||
|
|
||||||
|
#endif
|
||||||
44
avr/usbload/inflate_test.c
Normal file
44
avr/usbload/inflate_test.c
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "neginf/neginf.h"
|
||||||
|
#include "inflate.h"
|
||||||
|
#include "loader_test.h"
|
||||||
|
|
||||||
|
extern const char _rom[];
|
||||||
|
extern char inflate_done;
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
|
||||||
|
int j;
|
||||||
|
char c;
|
||||||
|
inflate_init();
|
||||||
|
for (j=0; j< ROM_ZIP_SIZE; j++){
|
||||||
|
neginf_process_byte(_rom[j]);
|
||||||
|
}
|
||||||
|
while(!inflate_done)
|
||||||
|
neginf_process_byte(0x00);
|
||||||
|
inflate_flush();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
56
avr/usbload/info.c
Normal file
56
avr/usbload/info.c
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
#include "info.h"
|
||||||
|
#include "uart.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern FILE uart_stdout;
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef NO_INFO
|
||||||
|
uint8_t buffer_info[FORMAT_BUFFER_LEN];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(NO_INFO) && defined(__GNUC__)
|
||||||
|
|
||||||
|
#define info(format, args...) ((void)0)
|
||||||
|
|
||||||
|
#else
|
||||||
|
void info_P(PGM_P format, ...) {
|
||||||
|
#ifdef NO_INFO
|
||||||
|
|
||||||
|
#else
|
||||||
|
strlcpy_P((char*)buffer_info,format,FORMAT_BUFFER_LEN);
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
vprintf((char*)buffer_info, args);
|
||||||
|
va_end(args);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
53
avr/usbload/info.h
Normal file
53
avr/usbload/info.h
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __INFO_H__
|
||||||
|
#define __INFO_H__
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
#if defined(NO_INFO) && defined(__GNUC__)
|
||||||
|
/* gcc's cpp has extensions; it allows for macros with a variable number of
|
||||||
|
arguments. We use this extension here to preprocess pmesg away. */
|
||||||
|
#define info(format, args...) ((void)0)
|
||||||
|
#else
|
||||||
|
void info(char *format, ...);
|
||||||
|
/* print a message, if it is considered significant enough.
|
||||||
|
Adapted from [K&R2], p. 174 */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(NO_INFO) && defined(__GNUC__)
|
||||||
|
/* gcc's cpp has extensions; it allows for macros with a variable number of
|
||||||
|
arguments. We use this extension here to preprocess pmesg away. */
|
||||||
|
#define info_P(format, args...) ((void)0)
|
||||||
|
#else
|
||||||
|
void info_P(PGM_P format, ...);
|
||||||
|
/* print a message, if it is considered significant enough.
|
||||||
|
Adapted from [K&R2], p. 174 */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
76
avr/usbload/irq.c
Normal file
76
avr/usbload/irq.c
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h> /* for sei() */
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "usbdrv.h"
|
||||||
|
#include "oddebug.h" /* This is also an example for using debug
|
||||||
|
* macros */
|
||||||
|
#include "debug.h"
|
||||||
|
#include "info.h"
|
||||||
|
#include "sram.h"
|
||||||
|
#include "system.h"
|
||||||
|
|
||||||
|
extern system_t system;
|
||||||
|
|
||||||
|
void (*jump_to_app) (void) = 0x0000;
|
||||||
|
|
||||||
|
void irq_init(){
|
||||||
|
cli();
|
||||||
|
PCMSK3 |=(1<<PCINT27);
|
||||||
|
PCICR |= (1<<PCIE3);
|
||||||
|
sei();
|
||||||
|
system.reset_irq = RESET_IRQ_ON;
|
||||||
|
}
|
||||||
|
|
||||||
|
void irq_stop(){
|
||||||
|
cli();
|
||||||
|
PCMSK3 &=~(1<<PCINT27);
|
||||||
|
sei();
|
||||||
|
system.reset_irq = RESET_IRQ_OFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
void leave_application(void)
|
||||||
|
{
|
||||||
|
cli();
|
||||||
|
usbDeviceDisconnect();
|
||||||
|
system.avr_reset_count++;
|
||||||
|
wdt_enable(WDTO_15MS);
|
||||||
|
while (1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ISR (SIG_PIN_CHANGE3)
|
||||||
|
{
|
||||||
|
if (snes_reset_test()){
|
||||||
|
info_P(PSTR("Catch SNES reset button\n"));
|
||||||
|
info_P(PSTR("Set watchdog...\n"));
|
||||||
|
leave_application();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
28
avr/usbload/irq.h
Normal file
28
avr/usbload/irq.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __IRQ_H__
|
||||||
|
#define __IRQ_H__
|
||||||
|
|
||||||
|
void irq_init();
|
||||||
|
void irq_stop();
|
||||||
|
void leave_application(void);
|
||||||
|
#endif
|
||||||
2118
avr/usbload/loader.c
Normal file
2118
avr/usbload/loader.c
Normal file
File diff suppressed because it is too large
Load Diff
14
avr/usbload/loader.h
Normal file
14
avr/usbload/loader.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
File: qd16boot02.smc
|
||||||
|
Time: Sat, 24 Oct 2009 19:05:36
|
||||||
|
*/
|
||||||
|
#ifndef __FIFO_H__
|
||||||
|
#define __FIFO_H__
|
||||||
|
|
||||||
|
#define ROM_ZIP_SIZE 33654
|
||||||
|
#define ROM_BUFFER_CNT 2
|
||||||
|
|
||||||
|
#define ROM_BUFFER_SIZE01 32767
|
||||||
|
#define ROM_BUFFER_SIZE02 887
|
||||||
|
|
||||||
|
#endif
|
||||||
2229
avr/usbload/loader_test.c
Normal file
2229
avr/usbload/loader_test.c
Normal file
File diff suppressed because it is too large
Load Diff
7
avr/usbload/loader_test.h
Normal file
7
avr/usbload/loader_test.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
#ifndef __FIFO_H__
|
||||||
|
#define __FIFO_H__
|
||||||
|
|
||||||
|
#define ROM_ZIP_SIZE 35543
|
||||||
|
|
||||||
|
#endif
|
||||||
324
avr/usbload/main.c
Normal file
324
avr/usbload/main.c
Normal file
@@ -0,0 +1,324 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include <avr/eeprom.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "usbdrv.h"
|
||||||
|
#include "oddebug.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "requests.h"
|
||||||
|
#include "uart.h"
|
||||||
|
#include "sram.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "info.h"
|
||||||
|
#include "dump.h"
|
||||||
|
#include "crc.h"
|
||||||
|
#include "usb_bulk.h"
|
||||||
|
#include "timer.h"
|
||||||
|
#include "watchdog.h"
|
||||||
|
#include "rle.h"
|
||||||
|
#include "loader.h"
|
||||||
|
#include "command.h"
|
||||||
|
#include "shared_memory.h"
|
||||||
|
#include "irq.h"
|
||||||
|
#include "pwm.h"
|
||||||
|
#include "testing.h"
|
||||||
|
#include "shell.h"
|
||||||
|
#include "system.h"
|
||||||
|
|
||||||
|
#ifndef NO_DEBUG
|
||||||
|
extern FILE uart_stdout;
|
||||||
|
#endif
|
||||||
|
extern system_t system;
|
||||||
|
|
||||||
|
uint8_t debug_level = (DEBUG | DEBUG_CRC);
|
||||||
|
|
||||||
|
|
||||||
|
usb_transaction_t usb_trans;
|
||||||
|
|
||||||
|
usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||||
|
{
|
||||||
|
|
||||||
|
usbRequest_t *rq = (void *) data;
|
||||||
|
uint8_t ret_len = 0;
|
||||||
|
|
||||||
|
if (rq->bRequest == USB_BULK_UPLOAD_INIT) {
|
||||||
|
|
||||||
|
usb_trans.req_bank = 0;
|
||||||
|
usb_trans.rx_remaining = 0;
|
||||||
|
debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_INIT: %i %i\n"), rq->wValue.word,
|
||||||
|
rq->wIndex.word);
|
||||||
|
usb_trans.req_bank_size = (uint32_t) (1L << rq->wValue.word);
|
||||||
|
usb_trans.req_bank_cnt = rq->wIndex.word;
|
||||||
|
usb_trans.req_addr_end = (uint32_t) usb_trans.req_bank_size * usb_trans.req_bank_cnt;
|
||||||
|
usb_trans.req_percent = 0;
|
||||||
|
usb_trans.req_percent_last = 0;
|
||||||
|
usb_trans.sync_errors = 0;
|
||||||
|
debug_P(DEBUG_USB,
|
||||||
|
PSTR("USB_BULK_UPLOAD_INIT: bank_size=0x%08lx bank_cnt=0x%x end_addr=0x%08lx\n"),
|
||||||
|
usb_trans.req_bank_size, usb_trans.req_bank_cnt, usb_trans.req_addr_end);
|
||||||
|
|
||||||
|
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_START, 0);
|
||||||
|
shared_memory_write(SHARED_MEM_TX_CMD_BANK_COUNT, usb_trans.req_bank_cnt);
|
||||||
|
#if DO_TIMER
|
||||||
|
if (usb_trans.req_addr == 0x000000) {
|
||||||
|
#ifndef NO_DEBUG
|
||||||
|
timer_start();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
} else if (rq->bRequest == USB_BULK_UPLOAD_ADDR) {
|
||||||
|
|
||||||
|
usb_trans.req_state = REQ_STATUS_BULK_UPLOAD;
|
||||||
|
usb_trans.req_addr = rq->wValue.word;
|
||||||
|
usb_trans.req_addr = usb_trans.req_addr << 16;
|
||||||
|
usb_trans.req_addr = usb_trans.req_addr | rq->wIndex.word;
|
||||||
|
usb_trans.rx_remaining = rq->wLength.word;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (usb_trans.req_addr && usb_trans.req_addr % usb_trans.req_bank_size == 0) {
|
||||||
|
#if DO_TIMER
|
||||||
|
#ifndef NO_DEBUG
|
||||||
|
#ifdef FLT_DEBUG
|
||||||
|
debug_P(DEBUG_USB,
|
||||||
|
PSTR("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
|
||||||
|
usb_trans.req_bank, usb_trans.req_addr, timer_stop());
|
||||||
|
#else
|
||||||
|
debug_P(DEBUG_USB,
|
||||||
|
PSTR("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%i\n"),
|
||||||
|
usb_trans.req_bank, usb_trans.req_addr, timer_stop_int());
|
||||||
|
#endif
|
||||||
|
timer_start();
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
usb_trans.req_bank++;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
sram_bulk_write_start(usb_trans.req_addr);
|
||||||
|
}
|
||||||
|
ret_len = USB_MAX_TRANS;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
} else if (rq->bRequest == USB_BULK_UPLOAD_NEXT) {
|
||||||
|
usb_trans.req_state = REQ_STATUS_BULK_UPLOAD;
|
||||||
|
usb_trans.req_addr = rq->wValue.word;
|
||||||
|
usb_trans.req_addr = usb_trans.req_addr << 16;
|
||||||
|
usb_trans.req_addr = usb_trans.req_addr | rq->wIndex.word;
|
||||||
|
usb_trans.rx_remaining = rq->wLength.word;
|
||||||
|
|
||||||
|
#if DO_SHM
|
||||||
|
usb_trans.req_percent = (uint32_t)( 100 * usb_trans.req_addr ) / usb_trans.req_addr_end;
|
||||||
|
if (usb_trans.req_percent!=usb_trans.req_percent_last){
|
||||||
|
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_PROGESS, usb_trans.req_percent);
|
||||||
|
}
|
||||||
|
usb_trans.req_percent_last = usb_trans.req_percent;
|
||||||
|
shared_memory_scratchpad_region_save_helper(usb_trans.req_addr);
|
||||||
|
#endif
|
||||||
|
if (usb_trans.req_addr && (usb_trans.req_addr % usb_trans.req_bank_size) == 0) {
|
||||||
|
#if DO_TIMER
|
||||||
|
#ifndef NO_DEBUG
|
||||||
|
#ifdef FLT_DEBUG
|
||||||
|
debug_P(DEBUG_USB,
|
||||||
|
PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
|
||||||
|
usb_trans.req_bank, usb_trans.req_addr, timer_stop());
|
||||||
|
#else
|
||||||
|
debug_P(DEBUG_USB,
|
||||||
|
PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%i\n"),
|
||||||
|
usb_trans.req_bank, usb_trans.req_addr, timer_stop_int());
|
||||||
|
#endif
|
||||||
|
timer_start();
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
usb_trans.req_bank++;
|
||||||
|
#if DO_SHM
|
||||||
|
shared_memory_write(SHARED_MEM_TX_CMD_BANK_CURRENT, usb_trans.req_bank);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
ret_len = USB_MAX_TRANS;
|
||||||
|
/*
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
} else if (rq->bRequest == USB_BULK_UPLOAD_END) {
|
||||||
|
if (usb_trans.req_state != REQ_STATUS_BULK_UPLOAD) {
|
||||||
|
debug_P(DEBUG_USB,
|
||||||
|
PSTR("USB_BULK_UPLOAD_END: ERROR state is not REQ_STATUS_BULK_UPLOAD\n"));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_END:\n"));
|
||||||
|
usb_trans.req_state = REQ_STATUS_IDLE;
|
||||||
|
sram_bulk_write_end();
|
||||||
|
#if DO_SHM
|
||||||
|
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_END, 0);
|
||||||
|
#endif
|
||||||
|
ret_len = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
} else if (rq->bRequest == USB_CRC) {
|
||||||
|
usb_trans.req_addr = rq->wValue.word;
|
||||||
|
usb_trans.req_addr = usb_trans.req_addr << 16;
|
||||||
|
usb_trans.req_addr = usb_trans.req_addr | rq->wIndex.word;
|
||||||
|
debug_P(DEBUG_USB, PSTR("USB_CRC: addr=0x%08lx \n"), usb_trans.req_addr);
|
||||||
|
crc_check_bulk_memory(0x000000, usb_trans.req_addr, usb_trans.req_bank_size);
|
||||||
|
ret_len = 0;
|
||||||
|
/*
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
} else if (rq->bRequest == USB_MODE_AVR) {
|
||||||
|
usb_trans.req_state = REQ_STATUS_AVR;
|
||||||
|
debug_P(DEBUG_USB, PSTR("USB_MODE_AVR:\n"));
|
||||||
|
ret_len = 0;
|
||||||
|
/*
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
} else if (rq->bRequest == USB_AVR_RESET) {
|
||||||
|
debug_P(DEBUG_USB, PSTR("USB_AVR_RESET:\n"));
|
||||||
|
soft_reset();
|
||||||
|
ret_len = 0;
|
||||||
|
/*
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
} else if (rq->bRequest == USB_SET_LAODER) {
|
||||||
|
usb_trans.loader_enabled = rq->wValue.word;
|
||||||
|
ret_len = 0;
|
||||||
|
}
|
||||||
|
usbMsgPtr = usb_trans.rx_buffer;
|
||||||
|
return ret_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
void globals_init(){
|
||||||
|
memset(&usb_trans,0,sizeof(usb_transaction_t));
|
||||||
|
|
||||||
|
usb_trans.req_addr = 0;
|
||||||
|
usb_trans.req_addr_end = 0;
|
||||||
|
usb_trans.req_state = REQ_STATUS_IDLE;
|
||||||
|
usb_trans.rx_remaining = 0;
|
||||||
|
usb_trans.tx_remaining = 0;
|
||||||
|
usb_trans.sync_errors = 0;
|
||||||
|
usb_trans.loader_enabled = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifndef NO_DEBUG
|
||||||
|
uart_init();
|
||||||
|
stdout = &uart_stdout;
|
||||||
|
banner();
|
||||||
|
#endif
|
||||||
|
shared_memory_init();
|
||||||
|
system_init();
|
||||||
|
sram_init();
|
||||||
|
//pwm_init();
|
||||||
|
irq_init();
|
||||||
|
boot_startup_rom(50);
|
||||||
|
globals_init();
|
||||||
|
//pwm_stop();
|
||||||
|
usbInit();
|
||||||
|
usb_connect();
|
||||||
|
sei();
|
||||||
|
while (1) {
|
||||||
|
|
||||||
|
system_set_bus_avr();
|
||||||
|
system_set_wr_disable();
|
||||||
|
info_P(PSTR("USB poll\n"));
|
||||||
|
while (usb_trans.req_state != REQ_STATUS_SNES) {
|
||||||
|
usbPoll();
|
||||||
|
#ifdef DO_SHELL
|
||||||
|
#ifndef NO_DEBUG
|
||||||
|
shell_run();
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DO_SHM
|
||||||
|
shared_memory_write(SHARED_MEM_TX_CMD_TERMINATE, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DO_SHM_SCRATCHPAD
|
||||||
|
shared_memory_scratchpad_region_tx_restore();
|
||||||
|
shared_memory_scratchpad_region_rx_restore();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DO_CRC_CHECK
|
||||||
|
info_P(PSTR("-->CRC Check\n"));
|
||||||
|
crc_check_bulk_memory(0x000000, usb_trans.req_bank_size * usb_trans.req_bank_cnt, usb_trans.req_bank_size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
system_set_rom_mode(&usb_trans);
|
||||||
|
system_set_wr_disable();
|
||||||
|
system_set_bus_snes();
|
||||||
|
system_send_snes_reset();
|
||||||
|
irq_stop();
|
||||||
|
/*
|
||||||
|
info_P(PSTR("-->Switch TO SNES\n"));
|
||||||
|
set_rom_mode();
|
||||||
|
snes_wr_disable();
|
||||||
|
info_P(PSTR("Disable SNES WR\n"));
|
||||||
|
snes_bus_active();
|
||||||
|
info_P(PSTR("Activate SNES bus\n"));
|
||||||
|
irq_stop();
|
||||||
|
send_reset();
|
||||||
|
*/
|
||||||
|
info_P(PSTR("Poll USB\n"));
|
||||||
|
while ((usb_trans.req_state != REQ_STATUS_AVR)) {
|
||||||
|
usbPoll();
|
||||||
|
#ifdef DO_SHELL
|
||||||
|
#ifndef NO_DEBUG
|
||||||
|
shell_run();
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
//info_P(PSTR("-->Switch TO AVR\n"));
|
||||||
|
shared_memory_init();
|
||||||
|
if(usb_trans.loader_enabled) {
|
||||||
|
boot_startup_rom(500);
|
||||||
|
} else {
|
||||||
|
system_set_bus_avr();
|
||||||
|
system_send_snes_reset();
|
||||||
|
//avr_bus_active();
|
||||||
|
//send_reset();
|
||||||
|
|
||||||
|
}
|
||||||
|
irq_init();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
30
avr/usbload/memmory.txt
Normal file
30
avr/usbload/memmory.txt
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
Loader Version 1
|
||||||
|
|
||||||
|
DEBUG:
|
||||||
|
Bootloader: 4096
|
||||||
|
CODE: 24984
|
||||||
|
RAM: 742
|
||||||
|
LOADER: 31091
|
||||||
|
|
||||||
|
NO_DEBUG:
|
||||||
|
Bootloader: 4096
|
||||||
|
CODE: 7532
|
||||||
|
RAM: 344
|
||||||
|
LOADER: 31091
|
||||||
|
|
||||||
|
|
||||||
|
Loader Version 2
|
||||||
|
|
||||||
|
DEBUG:
|
||||||
|
Bootloader: 4096
|
||||||
|
CODE: 24984
|
||||||
|
RAM: 742
|
||||||
|
LOADER: 58046
|
||||||
|
|
||||||
|
NO_DEBUG:
|
||||||
|
Bootloader: 4096
|
||||||
|
CODE: 7532
|
||||||
|
RAM: 344
|
||||||
|
LOADER: 58046
|
||||||
|
|
||||||
466
avr/usbload/neginf/neginf.c
Normal file
466
avr/usbload/neginf/neginf.c
Normal file
@@ -0,0 +1,466 @@
|
|||||||
|
/*
|
||||||
|
* neginf.c
|
||||||
|
* neginf -- embedded inflate lib
|
||||||
|
*
|
||||||
|
* inflate routines
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "neginf.h"
|
||||||
|
#include "neginf_priv.h"
|
||||||
|
|
||||||
|
typedef void(*mode_fun)() ;
|
||||||
|
|
||||||
|
static neginf_state state;
|
||||||
|
static const mode_fun mode_tab[mode_count] = {
|
||||||
|
&await_block,
|
||||||
|
&raw_block_begin,
|
||||||
|
&raw_block_begin2,
|
||||||
|
&raw_block,
|
||||||
|
&fixed_block_begin,
|
||||||
|
&huff_block,
|
||||||
|
&huff_len_addbits,
|
||||||
|
&huff_dist,
|
||||||
|
&huff_dist_addbits,
|
||||||
|
&dynamic_block_begin,
|
||||||
|
&dynamic_read_lc,
|
||||||
|
&dynamic_read_lit_len,
|
||||||
|
&dynamic_read_dist
|
||||||
|
};
|
||||||
|
|
||||||
|
void neginf_init(nsize start_pos)
|
||||||
|
{
|
||||||
|
state.queue_size = 0;
|
||||||
|
state.mode = mode_await_block;
|
||||||
|
state.last_block = 0;
|
||||||
|
#ifdef NEGINF_POS_TRACKING
|
||||||
|
state.output_pos = start_pos;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void neginf_process_byte(nbyte byte)
|
||||||
|
{
|
||||||
|
assert(state.queue_size <= 16);
|
||||||
|
state.input_queue |= (byte << state.queue_size);
|
||||||
|
state.queue_size += 8;
|
||||||
|
|
||||||
|
while(state.queue_size >= 16)
|
||||||
|
{
|
||||||
|
//printf("qsize=%i mode=%i\n",state.queue_size,state.mode);
|
||||||
|
mode_tab[state.mode]();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef NEGINF_POS_TRACKING
|
||||||
|
nsize neginf_output_position()
|
||||||
|
{
|
||||||
|
return state.output_pos;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
nint lookahead()
|
||||||
|
{
|
||||||
|
//printf("lookahead\n");
|
||||||
|
return state.input_queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void consume(ntiny amount)
|
||||||
|
{
|
||||||
|
//printf("consume %i %i\n",state.queue_size,amount);
|
||||||
|
assert(state.queue_size > amount);
|
||||||
|
state.input_queue >>= amount;
|
||||||
|
state.queue_size -= amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
void await_block()
|
||||||
|
{
|
||||||
|
//printf("wait block\n");
|
||||||
|
if(state.last_block)
|
||||||
|
{
|
||||||
|
neginf_cb_completed();
|
||||||
|
consume(16);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nint la = lookahead();
|
||||||
|
state.last_block = la & 1;
|
||||||
|
consume(3);
|
||||||
|
switch(la & 6)
|
||||||
|
{
|
||||||
|
case 0: // 00 uncompressed
|
||||||
|
consume((state.queue_size) & 7); // align to byte
|
||||||
|
state.mode = mode_raw_block_begin;
|
||||||
|
break;
|
||||||
|
case 2: // 01 fixed huffman
|
||||||
|
state.mode = mode_fixed_block_begin;
|
||||||
|
break;
|
||||||
|
case 4: // 10 dynamic huffman
|
||||||
|
state.mode = mode_dynamic_block_begin;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void raw_block_begin()
|
||||||
|
{
|
||||||
|
//printf("raw block begin\n");
|
||||||
|
state.raw_size = lookahead() & 0xFFFF; // size of raw block
|
||||||
|
consume(16);
|
||||||
|
state.mode = mode_raw_block_begin2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void raw_block_begin2()
|
||||||
|
{
|
||||||
|
//printf("raw block begin2\n");
|
||||||
|
consume(16); // we ignore the inverted size
|
||||||
|
state.mode = mode_raw_block;
|
||||||
|
}
|
||||||
|
|
||||||
|
void raw_block()
|
||||||
|
{
|
||||||
|
//printf("raw block\n");
|
||||||
|
if(state.raw_size == 0)
|
||||||
|
{
|
||||||
|
state.mode = mode_await_block;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state.raw_size--;
|
||||||
|
neginf_cb_seq_byte(lookahead() & 0xFF);
|
||||||
|
#ifdef NEGINF_POS_TRACKING
|
||||||
|
state.output_pos++;
|
||||||
|
#endif
|
||||||
|
consume(8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void fixed_block_begin()
|
||||||
|
{
|
||||||
|
//printf("fixed block begin\n");
|
||||||
|
|
||||||
|
nint i = 0;
|
||||||
|
for(; i < 144; i++)
|
||||||
|
state.lit_len_lengths[i] = 8;
|
||||||
|
for(; i < 256; i++)
|
||||||
|
state.lit_len_lengths[i] = 9;
|
||||||
|
for(; i < 280; i++)
|
||||||
|
state.lit_len_lengths[i] = 7;
|
||||||
|
for(; i < 288; i++)
|
||||||
|
state.lit_len_lengths[i] = 8;
|
||||||
|
|
||||||
|
ntiny j;
|
||||||
|
for(j = 0; i < 32; i++)
|
||||||
|
state.dist_lengths[i] = 5;
|
||||||
|
|
||||||
|
compute_begins();
|
||||||
|
state.mode = mode_huff_block;
|
||||||
|
}
|
||||||
|
|
||||||
|
void huff_block()
|
||||||
|
{
|
||||||
|
//printf("huff block\n");
|
||||||
|
nint code = lit_len_read();
|
||||||
|
if(code == 256)
|
||||||
|
{
|
||||||
|
state.mode = mode_await_block;
|
||||||
|
}
|
||||||
|
else if(code < 256)
|
||||||
|
{
|
||||||
|
neginf_cb_seq_byte(code);
|
||||||
|
#ifdef NEGINF_POS_TRACKING
|
||||||
|
state.output_pos++;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state.code = code;
|
||||||
|
state.mode = mode_huff_len_addbits;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void huff_len_addbits()
|
||||||
|
{
|
||||||
|
//printf("huff len addbits\n");
|
||||||
|
nint len;
|
||||||
|
nint code = state.code;
|
||||||
|
nint la = lookahead();
|
||||||
|
if(code < 265)
|
||||||
|
len = code - 257 + 3;
|
||||||
|
else if(code < 269)
|
||||||
|
{
|
||||||
|
len = (code - 265) * 2 + 11 + (la & 1);
|
||||||
|
consume(1);
|
||||||
|
}
|
||||||
|
else if(code < 273)
|
||||||
|
{
|
||||||
|
len = (code - 269) * 4 + 19 + (la & 3);
|
||||||
|
consume(2);
|
||||||
|
}
|
||||||
|
else if(code < 277)
|
||||||
|
{
|
||||||
|
len = (code - 273) * 8 + 35 + (la & 7);
|
||||||
|
consume(3);
|
||||||
|
}
|
||||||
|
else if(code < 281)
|
||||||
|
{
|
||||||
|
len = (code - 277) * 16 + 67 + (la & 15);
|
||||||
|
consume(4);
|
||||||
|
}
|
||||||
|
else if(code < 285)
|
||||||
|
{
|
||||||
|
len = (code - 281) * 32 + 131 + (la & 31);
|
||||||
|
consume(5);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
len = 258;
|
||||||
|
}
|
||||||
|
state.match_len = len;
|
||||||
|
state.mode = mode_huff_dist;
|
||||||
|
}
|
||||||
|
|
||||||
|
void huff_dist()
|
||||||
|
{
|
||||||
|
//printf("huff dist\n");
|
||||||
|
state.tcode = dist_read();
|
||||||
|
state.mode = mode_huff_dist_addbits;
|
||||||
|
}
|
||||||
|
|
||||||
|
void huff_dist_addbits()
|
||||||
|
{
|
||||||
|
//printf("huff addbits\n");
|
||||||
|
nint dist;
|
||||||
|
ntiny code = state.tcode;
|
||||||
|
|
||||||
|
if(code < 4)
|
||||||
|
{
|
||||||
|
dist = code+1;
|
||||||
|
}
|
||||||
|
else if(code > 29)
|
||||||
|
{
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nint la = lookahead();
|
||||||
|
ntiny len = (code - 2) / 2;
|
||||||
|
dist = ((2 + (code & 1)) << len) + 1 + (((1 << len) - 1) & la);
|
||||||
|
consume(len);
|
||||||
|
}
|
||||||
|
neginf_cb_rel_copy(dist, state.match_len);
|
||||||
|
#ifdef NEGINF_POS_TRACKING
|
||||||
|
state.output_pos += state.match_len;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
state.mode = mode_huff_block;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dynamic_block_begin()
|
||||||
|
{
|
||||||
|
nint j;
|
||||||
|
ntiny i;
|
||||||
|
//printf("dynamic block begin\n");
|
||||||
|
for(j = 0; j < 288; j++)
|
||||||
|
state.lit_len_lengths[j] = 0;
|
||||||
|
for(i = 0; i < 32; i++)
|
||||||
|
state.dist_lengths[i] = 0;
|
||||||
|
for(i = 0; i < 19; i++)
|
||||||
|
state.hc_lengths[i] = 0;
|
||||||
|
|
||||||
|
nint la = lookahead();
|
||||||
|
state.hlit = (la & 31) + 257;
|
||||||
|
state.hdist = ((la >> 5) & 31) + 1;
|
||||||
|
state.hclen = ((la >> 10) & 15) + 4;
|
||||||
|
state.torder = 0;
|
||||||
|
consume(5+5+4);
|
||||||
|
state.mode = mode_dynamic_read_lc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dynamic_read_lc()
|
||||||
|
{
|
||||||
|
//printf("dynamic read lc\n");
|
||||||
|
if(state.hclen == 0)
|
||||||
|
{
|
||||||
|
compute_begin(state.hc_lengths, state.hc_begins, 19);
|
||||||
|
state.mode = mode_dynamic_read_lit_len;
|
||||||
|
state.order = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
static const ntiny order[19] = {
|
||||||
|
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
|
||||||
|
};
|
||||||
|
ntiny i = lookahead() & 7;
|
||||||
|
state.hc_lengths[order[state.torder]] = i;
|
||||||
|
consume(3);
|
||||||
|
|
||||||
|
state.torder++;
|
||||||
|
state.hclen--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dynamic_read_lit_len()
|
||||||
|
{
|
||||||
|
//printf("dynamic read lit len\n");
|
||||||
|
if(state.hlit == 0)
|
||||||
|
{
|
||||||
|
state.mode = mode_dynamic_read_dist;
|
||||||
|
state.order = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state.hlit -= lc_read(state.lit_len_lengths);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dynamic_read_dist()
|
||||||
|
{
|
||||||
|
//printf("dynamic read dist\n");
|
||||||
|
if(state.hdist == 0)
|
||||||
|
{
|
||||||
|
compute_begins();
|
||||||
|
state.mode = mode_huff_block;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state.hdist -= lc_read(state.dist_lengths);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ntiny lc_read(ntiny * lenghts)
|
||||||
|
{
|
||||||
|
//printf("read lc\n");
|
||||||
|
ntiny code = huff_read(state.hc_lengths, state.hc_begins, 19);
|
||||||
|
// this reads 7 bits max so we still have 9 bits left in the buffer
|
||||||
|
if(code < 16)
|
||||||
|
{
|
||||||
|
lenghts[state.order] = code;
|
||||||
|
state.order++;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if(code == 16)
|
||||||
|
{
|
||||||
|
ntiny i;
|
||||||
|
ntiny copy = (lookahead() & 3) + 3;
|
||||||
|
consume(2);
|
||||||
|
for(i = 0; i < copy; i++)
|
||||||
|
lenghts[state.order + i] = lenghts[state.order - 1];
|
||||||
|
state.order += copy;
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ntiny fill;
|
||||||
|
ntiny i;
|
||||||
|
|
||||||
|
if(code == 17)
|
||||||
|
{
|
||||||
|
fill = (lookahead() & 7) + 3;
|
||||||
|
consume(3);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fill = (lookahead() & 127) + 11;
|
||||||
|
consume(7);
|
||||||
|
}
|
||||||
|
for(i = 0; i < fill; i++)
|
||||||
|
{
|
||||||
|
lenghts[state.order] = 0;
|
||||||
|
state.order++;
|
||||||
|
}
|
||||||
|
return fill;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void compute_begins()
|
||||||
|
{
|
||||||
|
//printf("compute begins\n");
|
||||||
|
compute_begin(state.lit_len_lengths, state.lit_len_begins, 288);
|
||||||
|
compute_begin(state.dist_lengths, state.dist_begins, 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void compute_begin(ntiny * lengths, nint * begins, nint size)
|
||||||
|
{
|
||||||
|
ntiny j;
|
||||||
|
nint i;
|
||||||
|
//printf("compute begin\n");
|
||||||
|
for(j = 0; j < 14; j++)
|
||||||
|
begins[j] = 0;
|
||||||
|
for(i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
nint len = lengths[i];
|
||||||
|
if(len != 0 && len != 15)
|
||||||
|
begins[len-1] += 1 << (15 - len);
|
||||||
|
}
|
||||||
|
nint acc = 0;
|
||||||
|
for(j = 0; j < 14; j++)
|
||||||
|
{
|
||||||
|
nint val = begins[j];
|
||||||
|
acc += val;
|
||||||
|
begins[j] = acc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nint lit_len_read()
|
||||||
|
{
|
||||||
|
//printf("lit len read\n");
|
||||||
|
|
||||||
|
return huff_read(state.lit_len_lengths, state.lit_len_begins, 288);
|
||||||
|
}
|
||||||
|
|
||||||
|
nint dist_read()
|
||||||
|
{
|
||||||
|
//printf("dist read\n");
|
||||||
|
return huff_read(state.dist_lengths, state.dist_begins, 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
nint huff_read(ntiny * lenghts, nint * begins, nint size)
|
||||||
|
{
|
||||||
|
//printf("huff read\n");
|
||||||
|
nint code = 0;
|
||||||
|
ntiny i;
|
||||||
|
for(i = 1; i < 16; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
code |= (lookahead() & 1) << (15-i);
|
||||||
|
consume(1);
|
||||||
|
if(i == 15 || code < begins[i-1])
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
code -= begins[i-2];
|
||||||
|
code >>= (15-i);
|
||||||
|
nint j;
|
||||||
|
for(j = 0; j < size; j++)
|
||||||
|
{
|
||||||
|
if(lenghts[j] == i)
|
||||||
|
{
|
||||||
|
if(code == 0)
|
||||||
|
return j;
|
||||||
|
code--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//assert(0);
|
||||||
|
return 0; // silent warning
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef NEGINF_USE_SEQ_WRITES
|
||||||
|
void neginf_cb_seq_byte(nbyte byte)
|
||||||
|
{
|
||||||
|
neginf_cb_byte(state.output_pos, byte);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NEGINF_USE_REL_COPY
|
||||||
|
void neginf_cb_rel_copy(nint distance, nint length)
|
||||||
|
{
|
||||||
|
neginf_cb_copy(state.output_pos - distance, state.output_pos, length);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
43
avr/usbload/neginf/neginf.h
Normal file
43
avr/usbload/neginf/neginf.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* neginf.h
|
||||||
|
* neginf -- embedded inflate lib
|
||||||
|
*
|
||||||
|
* public header file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NEGINF_H
|
||||||
|
#define NEGINF_H
|
||||||
|
|
||||||
|
#include "neginf_conf.h"
|
||||||
|
|
||||||
|
#if defined(NEGINF_USE_SEQ_WRITES) && defined(NEGINF_USE_REL_COPY)
|
||||||
|
#else
|
||||||
|
#ifndef NEGINF_POS_TRACKING
|
||||||
|
#define NEGINF_POS_TRACKING
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void neginf_init(nsize start_pos);
|
||||||
|
void neginf_process_byte(nbyte byte);
|
||||||
|
|
||||||
|
#ifdef NEGINF_POS_TRACKING
|
||||||
|
nsize neginf_output_position();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// callbacks
|
||||||
|
|
||||||
|
#ifdef NEGINF_USE_SEQ_WRITES
|
||||||
|
void neginf_cb_seq_byte(nbyte byte);
|
||||||
|
#else
|
||||||
|
void neginf_cb_byte(nsize pos, nbyte byte);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef NEGINF_USE_REL_COPY
|
||||||
|
void neginf_cb_rel_copy(nint distance, nint length);
|
||||||
|
#else
|
||||||
|
void neginf_cb_copy(nsize from, nsize to, nint length);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void neginf_cb_completed();
|
||||||
|
|
||||||
|
#endif
|
||||||
48
avr/usbload/neginf/neginf_conf.h
Normal file
48
avr/usbload/neginf/neginf_conf.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* neginf_conf.h
|
||||||
|
* neginf -- embedded inflate lib
|
||||||
|
*
|
||||||
|
* configuration header file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NEGINF_CONF_H
|
||||||
|
#define NEGINF_CONF_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define NEGINF_USE_SEQ_WRITES
|
||||||
|
//#define NEGINF_USE_REL_COPY
|
||||||
|
//#define NEGINF_POS_TRACKING
|
||||||
|
|
||||||
|
//#define NEGINF_8BIT
|
||||||
|
#define NEGINF_PACKED_STATE
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef NEGINF_8BIT
|
||||||
|
|
||||||
|
typedef char nbool;
|
||||||
|
typedef uint8_t nbyte;
|
||||||
|
typedef uint8_t ntiny;
|
||||||
|
typedef uint16_t nint;
|
||||||
|
typedef uint32_t nbuf;
|
||||||
|
|
||||||
|
typedef uint32_t nsize;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
typedef int nbool; // boolean
|
||||||
|
typedef uint8_t nbyte; // has to be exaclty 8 bit, unsigned
|
||||||
|
typedef unsigned int ntiny; // has to be at least 8 bit, unsigned
|
||||||
|
typedef unsigned int nint; // has to be at least 16 bit, unsigned
|
||||||
|
typedef unsigned int nbuf; // has to be at least 24 bit, unsigned
|
||||||
|
|
||||||
|
|
||||||
|
typedef size_t nsize; // has be at least 24 bit, unsigned
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
102
avr/usbload/neginf/neginf_priv.h
Normal file
102
avr/usbload/neginf/neginf_priv.h
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* neginf_priv.h
|
||||||
|
* neginf -- embedded inflate lib
|
||||||
|
*
|
||||||
|
* internal header file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NEGINF_PRIV_H
|
||||||
|
#define NEGINF_PRIV_H
|
||||||
|
|
||||||
|
typedef struct neginf_state_s neginf_state;
|
||||||
|
struct neginf_state_s {
|
||||||
|
ntiny queue_size; // 0 .. 24
|
||||||
|
ntiny mode;
|
||||||
|
nbool last_block;
|
||||||
|
#ifdef NEGINF_POS_TRACKING
|
||||||
|
nsize output_pos;
|
||||||
|
#endif
|
||||||
|
// can be left uninitialized
|
||||||
|
nbuf input_queue; // three input bytes
|
||||||
|
|
||||||
|
ntiny raw_size;
|
||||||
|
ntiny tcode;
|
||||||
|
nint code;
|
||||||
|
nint match_len;
|
||||||
|
|
||||||
|
nint order;
|
||||||
|
ntiny torder;
|
||||||
|
nint hlit;
|
||||||
|
ntiny hdist;
|
||||||
|
ntiny hclen;
|
||||||
|
|
||||||
|
ntiny lit_len_lengths[288];
|
||||||
|
nint lit_len_begins[14];
|
||||||
|
|
||||||
|
ntiny dist_lengths[32];
|
||||||
|
nint dist_begins[14];
|
||||||
|
|
||||||
|
ntiny hc_lengths[19];
|
||||||
|
nint hc_begins[14];
|
||||||
|
// what could be saved by limiting this to 7
|
||||||
|
// will be lost due to the extra code i guess
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
#ifdef NEGINF_PACKED_STATE
|
||||||
|
__attribute__((__packed__))
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
|
enum neginf_mode {
|
||||||
|
mode_await_block = 0,
|
||||||
|
mode_raw_block_begin,
|
||||||
|
mode_raw_block_begin2,
|
||||||
|
mode_raw_block,
|
||||||
|
mode_fixed_block_begin,
|
||||||
|
mode_huff_block,
|
||||||
|
mode_huff_len_addbits,
|
||||||
|
mode_huff_dist,
|
||||||
|
mode_huff_dist_addbits,
|
||||||
|
mode_dynamic_block_begin,
|
||||||
|
mode_dynamic_read_lc,
|
||||||
|
mode_dynamic_read_lit_len,
|
||||||
|
mode_dynamic_read_dist,
|
||||||
|
mode_count
|
||||||
|
};
|
||||||
|
|
||||||
|
static void await_block();
|
||||||
|
static void raw_block_begin();
|
||||||
|
static void raw_block_begin2();
|
||||||
|
static void raw_block();
|
||||||
|
static void fixed_block_begin();
|
||||||
|
static void huff_block();
|
||||||
|
static void huff_len_addbits();
|
||||||
|
static void huff_dist();
|
||||||
|
static void huff_dist_addbits();
|
||||||
|
static void dynamic_block_begin();
|
||||||
|
static void dynamic_read_lc();
|
||||||
|
static void dynamic_read_lit_len();
|
||||||
|
static void dynamic_read_dist();
|
||||||
|
|
||||||
|
static void compute_begins();
|
||||||
|
static void compute_begin(ntiny * lengths, nint * begins, nint size);
|
||||||
|
static nint lit_len_read();
|
||||||
|
static nint dist_read();
|
||||||
|
static nint huff_read(ntiny * lengths, nint * begins, nint size);
|
||||||
|
static ntiny lc_read(ntiny * lengths);
|
||||||
|
|
||||||
|
static nint lookahead();
|
||||||
|
static void consume(ntiny amount);
|
||||||
|
|
||||||
|
#ifndef NEGINF_USE_SEQ_WRITES
|
||||||
|
static void neginf_cb_seq_byte(nbyte byte);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NEGINF_USE_REL_COPY
|
||||||
|
void neginf_cb_rel_copy(nint distance, nint length);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
104
avr/usbload/pwm.c
Normal file
104
avr/usbload/pwm.c
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
|
#include "pwm.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "info.h"
|
||||||
|
#include "sram.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define PWM_SINE_MAX 64
|
||||||
|
#define PWM_OVERFLOW_MAX 1024
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
uint8_t pwm_sine_table[] = {
|
||||||
|
0x7f,0x8b,0x97,0xa4,0xaf,0xbb,0xc5,0xcf,0xd9,0xe1,0xe8,0xef,0xf4,0xf8,0xfb,0xfd,
|
||||||
|
0xfd,0xfd,0xfb,0xf8,0xf3,0xee,0xe7,0xe0,0xd7,0xce,0xc4,0xb9,0xae,0xa2,0x96,0x89,
|
||||||
|
0x7e,0x71,0x65,0x59,0x4d,0x42,0x37,0x2d,0x24,0x1c,0x15,0x0f,0x09,0x05,0x03,0x01,
|
||||||
|
0x01,0x01,0x03,0x07,0x0b,0x11,0x17,0x1f,0x28,0x31,0x3b,0x46,0x52,0x5e,0x6a,0x76
|
||||||
|
};
|
||||||
|
|
||||||
|
volatile uint8_t pwm_setting;
|
||||||
|
volatile uint16_t pwm_overflow;
|
||||||
|
volatile uint8_t pwm_idx;
|
||||||
|
volatile uint16_t pwm_overflow_max;
|
||||||
|
|
||||||
|
ISR(TIMER2_COMPA_vect) {
|
||||||
|
static uint8_t pwm_cnt=0;
|
||||||
|
OCR2A += (uint16_t)T_PWM;
|
||||||
|
|
||||||
|
if (pwm_setting> pwm_cnt)
|
||||||
|
led_pwm_on();
|
||||||
|
else
|
||||||
|
led_pwm_off();
|
||||||
|
|
||||||
|
if (pwm_cnt==(uint8_t)(PWM_STEPS-1))
|
||||||
|
pwm_cnt=0;
|
||||||
|
else
|
||||||
|
pwm_cnt++;
|
||||||
|
if (pwm_overflow_max == pwm_overflow++ ){
|
||||||
|
pwm_setting = pwm_sine_table[pwm_idx++];
|
||||||
|
pwm_overflow = 0;
|
||||||
|
if (PWM_SINE_MAX == pwm_idx)
|
||||||
|
pwm_idx = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pwm_speed(uint16_t val) {
|
||||||
|
pwm_overflow_max = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pwm_speed_slow(uint16_t val) {
|
||||||
|
pwm_overflow_max = PWM_OVERFLOW_MAX * 2 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pwm_speed_fast(uint16_t val) {
|
||||||
|
pwm_overflow_max = PWM_OVERFLOW_MAX / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pwm_speed_normal(uint16_t val) {
|
||||||
|
pwm_overflow_max = PWM_OVERFLOW_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void pwm_set(uint8_t val) {
|
||||||
|
pwm_setting = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pwm_stop(void) {
|
||||||
|
while(pwm_setting!=0xfd);
|
||||||
|
TIMSK2 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pwm_init(void) {
|
||||||
|
pwm_overflow_max = PWM_OVERFLOW_MAX;
|
||||||
|
pwm_setting = 0x7f;
|
||||||
|
pwm_overflow = 0;
|
||||||
|
//cli();
|
||||||
|
TCCR2B = 1;
|
||||||
|
TIMSK2 |= (1<<OCIE2A);
|
||||||
|
sei();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
37
avr/usbload/pwm.h
Normal file
37
avr/usbload/pwm.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __PWM_H__
|
||||||
|
#define __PWM_H__
|
||||||
|
|
||||||
|
#define F_PWM 100 // PWM-Frequenz in Hz
|
||||||
|
#define PWM_STEPS 256 // PWM-Schritte pro Zyklus(1..256)
|
||||||
|
|
||||||
|
#define T_PWM (F_CPU/(F_PWM*PWM_STEPS)) // Systemtakte pro PWM-Takt
|
||||||
|
|
||||||
|
#if (T_PWM<(93+5))
|
||||||
|
#error T_PWM zu klein, F_CPU muss vergrösst werden oder F_PWM oder PWM_STEPS verkleinert werden
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void pwm_init(void);
|
||||||
|
void pwm_stop(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
60
avr/usbload/requests.h
Normal file
60
avr/usbload/requests.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __REQUESTS_H__
|
||||||
|
#define __REQUESTS_H__
|
||||||
|
|
||||||
|
#define USB_UPLOAD_INIT 0
|
||||||
|
#define USB_UPLOAD_ADDR 1
|
||||||
|
|
||||||
|
#define USB_DOWNLOAD_INIT 2
|
||||||
|
#define USB_DOWNLOAD_ADDR 3
|
||||||
|
|
||||||
|
#define USB_CRC 4
|
||||||
|
#define USB_CRC_ADDR 5
|
||||||
|
|
||||||
|
#define USB_BULK_UPLOAD_INIT 6
|
||||||
|
#define USB_BULK_UPLOAD_ADDR 7
|
||||||
|
#define USB_BULK_UPLOAD_NEXT 8
|
||||||
|
#define USB_BULK_UPLOAD_END 9
|
||||||
|
#define USB_MODE_SNES 10
|
||||||
|
#define USB_MODE_AVR 11
|
||||||
|
#define USB_AVR_RESET 12
|
||||||
|
#define USB_SET_LAODER 13
|
||||||
|
|
||||||
|
typedef struct usb_transaction_t {
|
||||||
|
uint32_t req_addr;
|
||||||
|
uint32_t req_addr_end;
|
||||||
|
uint8_t req_bank;
|
||||||
|
uint32_t req_bank_size;
|
||||||
|
uint16_t req_bank_cnt;
|
||||||
|
uint8_t req_percent;
|
||||||
|
uint8_t req_percent_last;
|
||||||
|
uint8_t req_state;
|
||||||
|
uint8_t rx_remaining;
|
||||||
|
uint8_t tx_remaining ;
|
||||||
|
uint16_t sync_errors;
|
||||||
|
uint8_t tx_buffer[32];
|
||||||
|
uint8_t rx_buffer[8];
|
||||||
|
uint8_t loader_enabled;
|
||||||
|
} usb_transaction_t;
|
||||||
|
|
||||||
|
#endif /* __REQUESTS_H_INCLUDED__ */
|
||||||
126
avr/usbload/ringbuffer.c
Normal file
126
avr/usbload/ringbuffer.c
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
// AT90USB/ringbuffer.c
|
||||||
|
// Simple Ring-Buffer (FIFO) for Elements of type char
|
||||||
|
// S. Salewski, 19-MAR-2007
|
||||||
|
|
||||||
|
/*
|
||||||
|
t-> o
|
||||||
|
o <-w
|
||||||
|
x
|
||||||
|
x <-r
|
||||||
|
b-> x
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include "ringbuffer.h"
|
||||||
|
#define memory_size 65536
|
||||||
|
#define t &buf[ringbuffer_size - 1]
|
||||||
|
#define b &buf[0]
|
||||||
|
|
||||||
|
char buf[ringbuffer_size];
|
||||||
|
int rb_count;
|
||||||
|
char *memory;
|
||||||
|
int pos_mem;
|
||||||
|
int pos_head;
|
||||||
|
|
||||||
|
|
||||||
|
//char *t = &buf[ringbuffer_size - 1];
|
||||||
|
//char *b = &buf[0];
|
||||||
|
|
||||||
|
char *r; // position from where we can read (if rb_count > 0)
|
||||||
|
char *w; // next free position (if rb_count < ringbuffer_size))
|
||||||
|
char *o; // output pointer
|
||||||
|
|
||||||
|
void rb_init()
|
||||||
|
{
|
||||||
|
r = b;
|
||||||
|
w = b;
|
||||||
|
o = b;
|
||||||
|
rb_count = 0;
|
||||||
|
memory = (char*)malloc(memory_size);
|
||||||
|
pos_mem = 0;
|
||||||
|
pos_head = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void rb_dump()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
printf("b=0x%02x t=0x%02x w=0x%02x o=0x%02x\n",*b,*t,*w,*o);
|
||||||
|
for (i=0; i<ringbuffer_size; i++)
|
||||||
|
printf("%02i 0x%02x\n",i, buf[i]);
|
||||||
|
|
||||||
|
}
|
||||||
|
void rb_flush(){
|
||||||
|
FILE *file;
|
||||||
|
while(!rb_isempty()){
|
||||||
|
memory[pos_mem++] = rb_get();
|
||||||
|
}
|
||||||
|
printf("write out.smc\n");
|
||||||
|
file = fopen("out.smc","w");
|
||||||
|
fwrite(memory,memory_size,1,file);
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
char rb_get(void)
|
||||||
|
{
|
||||||
|
rb_count--;
|
||||||
|
if (r > t)
|
||||||
|
r = b;
|
||||||
|
return *r++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char rb_read(int pos)
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
printf("rb_read: pos_mem=%06i pos_head=%06i pos=%06i\n",
|
||||||
|
pos_mem, pos_head,pos);
|
||||||
|
|
||||||
|
if ( pos_head - pos > ringbuffer_size){
|
||||||
|
printf("rb_read: memory[%i]=0x%02x \n",
|
||||||
|
pos,
|
||||||
|
memory[pos]);
|
||||||
|
return memory[pos];
|
||||||
|
}
|
||||||
|
if (w - index >= b)
|
||||||
|
p = w - index;
|
||||||
|
else
|
||||||
|
p = b + (b - ( w - index ));
|
||||||
|
return *p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rb_copy(int from,int to,int len){
|
||||||
|
int i;
|
||||||
|
char c;
|
||||||
|
for (i = from; i< to; i++){
|
||||||
|
c = rb_read(i);
|
||||||
|
rb_put(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void rb_put(char el)
|
||||||
|
{
|
||||||
|
pos_head++;
|
||||||
|
rb_count++;
|
||||||
|
|
||||||
|
if ( rb_count > ringbuffer_size){
|
||||||
|
rb_dump();
|
||||||
|
memory[pos_mem++]=*o++;
|
||||||
|
if (o > t){
|
||||||
|
o = b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("rb_count=%i pos_head=0x%06x add_mem=0x%06x\n",rb_count, pos_head,pos_mem);
|
||||||
|
|
||||||
|
if (w > t){
|
||||||
|
w = b;
|
||||||
|
}
|
||||||
|
*w++ = el;
|
||||||
|
}
|
||||||
19
avr/usbload/ringbuffer.h
Normal file
19
avr/usbload/ringbuffer.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
#ifndef _RING_BUFFER_H_
|
||||||
|
#define _RING_BUFFER_H_
|
||||||
|
|
||||||
|
|
||||||
|
#define ringbuffer_size 8
|
||||||
|
|
||||||
|
extern int rb_count;
|
||||||
|
|
||||||
|
#define rb_free() (ringbuffer_size - rb_count)
|
||||||
|
#define rb_isfull() (rb_count == ringbuffer_size)
|
||||||
|
#define rb_isempty() (rb_count == 0)
|
||||||
|
|
||||||
|
void rb_init(void);
|
||||||
|
void rb_put(char el);
|
||||||
|
char rb_get(void);
|
||||||
|
void rb_flush(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
106
avr/usbload/rle.c
Normal file
106
avr/usbload/rle.c
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <avr/pgmspace.h> /* required by usbdrv.h */
|
||||||
|
#include <util/delay.h> /* for _delay_ms() */
|
||||||
|
#include <avr/interrupt.h> /* for sei() */
|
||||||
|
|
||||||
|
#include "sram.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "info.h"
|
||||||
|
|
||||||
|
#define RUNCHAR 0x90
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
uint32_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
|
||||||
|
{
|
||||||
|
uint8_t in_byte, in_repeat, last_byte;
|
||||||
|
info_P(PSTR("RLE decode len=%li addr=0x%08lx\n"), in_len, out_addr);
|
||||||
|
last_byte = 0;
|
||||||
|
|
||||||
|
sram_bulk_write_start(out_addr);
|
||||||
|
#define INBYTE(b) \
|
||||||
|
do { \
|
||||||
|
if ( --in_len < 0 ) { \
|
||||||
|
return 1; \
|
||||||
|
} \
|
||||||
|
cli();\
|
||||||
|
b = pgm_read_byte((PGM_VOID_P)in_addr++); \
|
||||||
|
sei();\
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
#define OUTBYTE(b) \
|
||||||
|
do { \
|
||||||
|
sram_bulk_write(b);\
|
||||||
|
sram_bulk_write_next();\
|
||||||
|
out_addr++;\
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
INBYTE(in_byte);
|
||||||
|
|
||||||
|
if (in_byte == RUNCHAR) {
|
||||||
|
INBYTE(in_repeat);
|
||||||
|
if (in_repeat != 0) {
|
||||||
|
info_P(PSTR("Orphaned RLE code at start\n"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
OUTBYTE(RUNCHAR);
|
||||||
|
} else {
|
||||||
|
OUTBYTE(in_byte);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (in_len > 0) {
|
||||||
|
INBYTE(in_byte);
|
||||||
|
if (in_len % 1024 == 0)
|
||||||
|
info_P(PSTR("."));
|
||||||
|
if (in_byte == RUNCHAR) {
|
||||||
|
INBYTE(in_repeat);
|
||||||
|
if (in_repeat == 0) {
|
||||||
|
/*
|
||||||
|
* Just an escaped RUNCHAR value
|
||||||
|
*/
|
||||||
|
OUTBYTE(RUNCHAR);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Pick up value and output a sequence of it
|
||||||
|
*/
|
||||||
|
in_byte = last_byte; // ;out_data[-1];
|
||||||
|
while (--in_repeat > 0)
|
||||||
|
OUTBYTE(in_byte);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Normal byte
|
||||||
|
*/
|
||||||
|
OUTBYTE(in_byte);
|
||||||
|
}
|
||||||
|
last_byte = in_byte;
|
||||||
|
}
|
||||||
|
sram_bulk_write_end();
|
||||||
|
info_P(PSTR("\nDone addr=0x%08lx\n"), out_addr);
|
||||||
|
return out_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
28
avr/usbload/rle.h
Normal file
28
avr/usbload/rle.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RLE_H__
|
||||||
|
#define __RLE_H__
|
||||||
|
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
uint32_t rle_decode(PGM_VOID_P in_addr, uint32_t in_len, uint32_t out_addr);
|
||||||
|
|
||||||
|
#endif
|
||||||
345
avr/usbload/shared_memory.c
Normal file
345
avr/usbload/shared_memory.c
Normal file
@@ -0,0 +1,345 @@
|
|||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
#include "shared_memory.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "sram.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "dump.h"
|
||||||
|
#include "info.h"
|
||||||
|
#include "crc.h"
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t irq_addr_lo;
|
||||||
|
uint8_t irq_addr_hi;
|
||||||
|
|
||||||
|
uint8_t scratchpad_state;
|
||||||
|
uint8_t scratchpad_cmd;
|
||||||
|
uint8_t scratchpad_payload;
|
||||||
|
|
||||||
|
uint8_t scratchpad_region_rx[SHARED_MEM_RX_LOC_SIZE];
|
||||||
|
uint8_t scratchpad_region_tx[SHARED_MEM_TX_LOC_SIZE];
|
||||||
|
|
||||||
|
uint8_t scratchpad_locked_rx = 1;
|
||||||
|
uint8_t scratchpad_locked_tx = 1;
|
||||||
|
|
||||||
|
|
||||||
|
void shared_memory_init(void){
|
||||||
|
scratchpad_locked_rx = 1;
|
||||||
|
scratchpad_locked_tx = 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t shared_memory_scratchpad_region_save_helper(uint32_t addr){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if DO_SHM_SCRATCHPAD
|
||||||
|
if(addr > (SHARED_MEM_TX_LOC_STATE + (SHARED_MEM_TX_LOC_SIZE )) && scratchpad_locked_tx){
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_save_helper: open tx addr=0x%06lx\n"),addr);
|
||||||
|
shared_memory_scratchpad_region_tx_save();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(addr > (SHARED_MEM_RX_LOC_STATE + ( SHARED_MEM_RX_LOC_SIZE )) && scratchpad_locked_rx){
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_save_helper: open rx addr=0x%06lx\n"),addr);
|
||||||
|
shared_memory_scratchpad_region_rx_save();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void shared_memory_scratchpad_region_tx_save()
|
||||||
|
{
|
||||||
|
sram_bulk_addr_save();
|
||||||
|
|
||||||
|
#if SHARED_SCRATCHPAD_CRC
|
||||||
|
uint16_t crc;
|
||||||
|
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_TX_LOC_STATE,
|
||||||
|
(uint32_t)(SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE), 0x8000);
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"),crc);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: unlock\n"));
|
||||||
|
sram_bulk_copy_into_buffer((uint32_t)SHARED_MEM_TX_LOC_STATE,scratchpad_region_tx,
|
||||||
|
(uint32_t)SHARED_MEM_TX_LOC_SIZE);
|
||||||
|
scratchpad_locked_tx = 0;
|
||||||
|
|
||||||
|
#if SHARED_SCRATCHPAD_CRC
|
||||||
|
do_crc_update(0, scratchpad_region_tx,SHARED_MEM_TX_LOC_SIZE);
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"),crc);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SHARED_SCRATCHPAD_DUMP
|
||||||
|
dump_packet(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_SIZE, scratchpad_region_tx);
|
||||||
|
dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
|
||||||
|
#endif
|
||||||
|
sram_bulk_addr_restore();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void shared_memory_scratchpad_region_rx_save()
|
||||||
|
{
|
||||||
|
|
||||||
|
sram_bulk_addr_save();
|
||||||
|
#if SHARED_SCRATCHPAD_CRC
|
||||||
|
uint16_t crc;
|
||||||
|
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_RX_LOC_STATE,
|
||||||
|
(uint32_t)(SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE), 0x8000);
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_save: crc=%x\n"),crc);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_save: unlock\n"));
|
||||||
|
sram_bulk_copy_into_buffer((uint32_t)SHARED_MEM_RX_LOC_STATE,scratchpad_region_rx,
|
||||||
|
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
|
||||||
|
scratchpad_locked_rx = 0;
|
||||||
|
|
||||||
|
#if SHARED_SCRATCHPAD_CRC
|
||||||
|
do_crc_update(0, scratchpad_region_rx,SHARED_MEM_RX_LOC_SIZE);
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_save: crc=%x\n"),crc);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SHARED_SCRATCHPAD_DUMP
|
||||||
|
dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_SIZE, scratchpad_region_rx);
|
||||||
|
dump_memory(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE);
|
||||||
|
#endif
|
||||||
|
sram_bulk_addr_restore();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void shared_memory_scratchpad_region_tx_restore()
|
||||||
|
{
|
||||||
|
if (scratchpad_locked_tx)
|
||||||
|
return;
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: lock\n"));
|
||||||
|
|
||||||
|
#if SHARED_SCRATCHPAD_DUMP
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: memory\n"));
|
||||||
|
dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sram_bulk_copy_from_buffer((uint32_t)SHARED_MEM_TX_LOC_STATE,scratchpad_region_tx,
|
||||||
|
(uint32_t)SHARED_MEM_TX_LOC_SIZE);
|
||||||
|
scratchpad_locked_tx = 1;
|
||||||
|
|
||||||
|
#if SHARED_SCRATCHPAD_DUMP
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: buffer\n"));
|
||||||
|
dump_packet(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_SIZE, scratchpad_region_tx);
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: memory\n"));
|
||||||
|
dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SHARED_SCRATCHPAD_CRC
|
||||||
|
uint16_t crc;
|
||||||
|
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_TX_LOC_STATE,
|
||||||
|
(uint32_t)(SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE), 0x8000);
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: crc=%x\n"),crc);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void shared_memory_scratchpad_region_rx_restore()
|
||||||
|
{
|
||||||
|
if (scratchpad_locked_rx)
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: lock\n"));
|
||||||
|
|
||||||
|
#if SHARED_SCRATCHPAD_DUMP
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: memory\n"));
|
||||||
|
dump_memory(SHARED_MEM_RX_LOC_STATE - 0x10, SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sram_bulk_copy_from_buffer((uint32_t)SHARED_MEM_RX_LOC_STATE,scratchpad_region_rx,
|
||||||
|
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
|
||||||
|
scratchpad_locked_rx = 1;
|
||||||
|
|
||||||
|
#if SHARED_SCRATCHPAD_DUMP
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: buffer\n"));
|
||||||
|
dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_SIZE, scratchpad_region_rx);
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: memory\n"));
|
||||||
|
dump_memory(SHARED_MEM_RX_LOC_STATE - 0x10, SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SHARED_SCRATCHPAD_CRC
|
||||||
|
uint16_t crc;
|
||||||
|
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_RX_LOC_STATE,
|
||||||
|
(uint32_t)(SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE), 0x8000);
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: crc=%x\n"),crc);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void shared_memory_scratchpad_tx_save()
|
||||||
|
{
|
||||||
|
scratchpad_state = sram_read(SHARED_MEM_TX_LOC_STATE);
|
||||||
|
scratchpad_cmd = sram_read(SHARED_MEM_TX_LOC_CMD);
|
||||||
|
scratchpad_payload = sram_read(SHARED_MEM_TX_LOC_PAYLOAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
void shared_memory_scratchpad_tx_restore()
|
||||||
|
{
|
||||||
|
sram_write(SHARED_MEM_TX_LOC_STATE, scratchpad_state);
|
||||||
|
sram_write(SHARED_MEM_TX_LOC_CMD, scratchpad_cmd);
|
||||||
|
sram_write(SHARED_MEM_TX_LOC_PAYLOAD, scratchpad_payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void shared_memory_irq_hook()
|
||||||
|
{
|
||||||
|
irq_addr_lo = sram_read(SHARED_IRQ_LOC_LO);
|
||||||
|
irq_addr_hi = sram_read(SHARED_IRQ_LOC_HI);
|
||||||
|
sram_write(SHARED_IRQ_HANDLER_LO, 0);
|
||||||
|
sram_write(SHARED_IRQ_HANDLER_HI, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void shared_memory_irq_restore()
|
||||||
|
{
|
||||||
|
sram_write(SHARED_IRQ_LOC_LO, irq_addr_lo);
|
||||||
|
sram_write(SHARED_IRQ_LOC_HI, irq_addr_hi);
|
||||||
|
}
|
||||||
|
|
||||||
|
void shared_memory_write(uint8_t cmd, uint8_t value)
|
||||||
|
{
|
||||||
|
#if DO_SHM
|
||||||
|
#if DO_SHM_SCRATCHPAD
|
||||||
|
if (scratchpad_locked_tx){
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_write: locked_tx\n"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_write: 0x%04x=0x%02x 0x%04x=0x%02x \n"),
|
||||||
|
SHARED_MEM_TX_LOC_CMD, cmd, SHARED_MEM_TX_LOC_PAYLOAD, value);
|
||||||
|
|
||||||
|
sram_bulk_addr_save();
|
||||||
|
|
||||||
|
#if (DO_SHM_SCRATCHPAD==0)
|
||||||
|
shared_memory_scratchpad_tx_save();
|
||||||
|
#endif
|
||||||
|
#if SHARED_MEM_SWITCH_IRQ
|
||||||
|
shared_memory_irq_hook();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sram_write(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_SNES_ACK);
|
||||||
|
sram_write(SHARED_MEM_TX_LOC_CMD, cmd);
|
||||||
|
sram_write(SHARED_MEM_TX_LOC_PAYLOAD, value);
|
||||||
|
|
||||||
|
snes_hirom();
|
||||||
|
snes_wr_disable();
|
||||||
|
snes_bus_active();
|
||||||
|
|
||||||
|
#if SHARED_MEM_SWITCH_IRQ
|
||||||
|
snes_irq_on();
|
||||||
|
snes_irq_lo();
|
||||||
|
_delay_us(20);
|
||||||
|
snes_irq_hi();
|
||||||
|
snes_irq_off();
|
||||||
|
#else
|
||||||
|
_delay_ms(SHARED_MEM_SWITCH_DELAY);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
avr_bus_active();
|
||||||
|
snes_irq_lo();
|
||||||
|
snes_irq_off();
|
||||||
|
snes_lorom();
|
||||||
|
snes_wr_disable();
|
||||||
|
|
||||||
|
#if (DO_SHM_SCRATCHPAD==0)
|
||||||
|
shared_memory_scratchpad_tx_restore();
|
||||||
|
#endif
|
||||||
|
#if SHARED_MEM_SWITCH_IRQ
|
||||||
|
shared_memory_irq_restore();
|
||||||
|
#endif
|
||||||
|
sram_bulk_addr_restore();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void shared_memory_yield()
|
||||||
|
{
|
||||||
|
|
||||||
|
snes_hirom();
|
||||||
|
snes_wr_disable();
|
||||||
|
snes_bus_active();
|
||||||
|
_delay_ms(SHARED_MEM_SWITCH_DELAY);
|
||||||
|
avr_bus_active();
|
||||||
|
snes_lorom();
|
||||||
|
snes_wr_disable();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int shared_memory_read(uint8_t *cmd, uint8_t *len,uint8_t *buffer)
|
||||||
|
{
|
||||||
|
uint8_t state;
|
||||||
|
#if DO_SHM
|
||||||
|
#if DO_SHM_SCRATCHPAD
|
||||||
|
if (scratchpad_locked_rx){
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_write: locked_tx\n"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
sram_bulk_addr_save();
|
||||||
|
|
||||||
|
state = sram_read(SHARED_MEM_RX_LOC_STATE);
|
||||||
|
if (state != SHARED_MEM_RX_AVR_ACK){
|
||||||
|
sram_bulk_addr_restore();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*cmd = sram_read(SHARED_MEM_RX_LOC_CMD);
|
||||||
|
*len = sram_read(SHARED_MEM_RX_LOC_LEN);
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_read: 0x%04x=0x%02x 0x%04x=0x%02x \n"),
|
||||||
|
SHARED_MEM_RX_LOC_CMD, *cmd, SHARED_MEM_RX_LOC_LEN, *len);
|
||||||
|
|
||||||
|
sram_bulk_copy_into_buffer(SHARED_MEM_RX_LOC_PAYLOAD,buffer, *len);
|
||||||
|
sram_write(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_AVR_RTS);
|
||||||
|
|
||||||
|
snes_hirom();
|
||||||
|
snes_wr_disable();
|
||||||
|
snes_bus_active();
|
||||||
|
|
||||||
|
#if SHARED_MEM_SWITCH_IRQ
|
||||||
|
snes_irq_on();
|
||||||
|
snes_irq_lo();
|
||||||
|
_delay_us(20);
|
||||||
|
snes_irq_hi();
|
||||||
|
snes_irq_off();
|
||||||
|
#else
|
||||||
|
_delay_ms(SHARED_MEM_SWITCH_DELAY);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
avr_bus_active();
|
||||||
|
snes_lorom();
|
||||||
|
snes_wr_disable();
|
||||||
|
sram_bulk_addr_restore();
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
76
avr/usbload/shared_memory.h
Normal file
76
avr/usbload/shared_memory.h
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SHARED_MEMORY_H__
|
||||||
|
#define __SHARED_MEMORY_H__
|
||||||
|
|
||||||
|
|
||||||
|
#define SHARED_MEM_SWITCH_IRQ 0
|
||||||
|
#define SHARED_MEM_SWITCH_DELAY 20
|
||||||
|
|
||||||
|
#define SHARED_MEM_TX_SNES_ACK 0xa5
|
||||||
|
#define SHARED_MEM_TX_SNES_RTS 0x5a
|
||||||
|
|
||||||
|
#define SHARED_MEM_TX_CMD_BANK_COUNT 0x00
|
||||||
|
#define SHARED_MEM_TX_CMD_BANK_CURRENT 0x01
|
||||||
|
|
||||||
|
#define SHARED_MEM_TX_CMD_UPLOAD_START 0x03
|
||||||
|
#define SHARED_MEM_TX_CMD_UPLOAD_END 0x04
|
||||||
|
#define SHARED_MEM_TX_CMD_UPLOAD_PROGESS 0x05
|
||||||
|
#define SHARED_MEM_TX_CMD_TERMINATE 0x06
|
||||||
|
|
||||||
|
#define SHARED_MEM_TX_LOC_STATE 0x000000
|
||||||
|
#define SHARED_MEM_TX_LOC_SIZE 0x000040
|
||||||
|
#define SHARED_MEM_TX_LOC_CMD 0x000001
|
||||||
|
#define SHARED_MEM_TX_LOC_PAYLOAD 0x000002
|
||||||
|
|
||||||
|
#define SHARED_MEM_RX_AVR_ACK 0xa5
|
||||||
|
#define SHARED_MEM_RX_AVR_RTS 0x5a
|
||||||
|
|
||||||
|
#define SHARED_MEM_RX_CMD_PRINFT 0x00
|
||||||
|
#define SHARED_MEM_RX_CMD_FILESEL 0x01
|
||||||
|
|
||||||
|
#define SHARED_MEM_RX_LOC_STATE 0x001000
|
||||||
|
#define SHARED_MEM_RX_LOC_SIZE 0x000040
|
||||||
|
#define SHARED_MEM_RX_LOC_CMD 0x001001
|
||||||
|
#define SHARED_MEM_RX_LOC_LEN 0x001002
|
||||||
|
#define SHARED_MEM_RX_LOC_PAYLOAD 0x001003
|
||||||
|
|
||||||
|
#define SHARED_IRQ_LOC_LO 0x00fffe
|
||||||
|
#define SHARED_IRQ_LOC_HI 0x00ffff
|
||||||
|
|
||||||
|
/* Use COP IRQ LOC for hooked IRQ handler */
|
||||||
|
#define SHARED_IRQ_HANDLER_LO 0x0ffe4
|
||||||
|
#define SHARED_IRQ_HANDLER_HI 0x0ffe5
|
||||||
|
|
||||||
|
#define SHARED_SCRATCHPAD_DUMP 0
|
||||||
|
#define SHARED_SCRATCHPAD_CRC 0
|
||||||
|
|
||||||
|
|
||||||
|
void shared_memory_init(void);
|
||||||
|
uint8_t shared_memory_scratchpad_region_save_helper(uint32_t addr);
|
||||||
|
void shared_memory_scratchpad_region_tx_save();
|
||||||
|
void shared_memory_scratchpad_region_tx_restore();
|
||||||
|
void shared_memory_scratchpad_region_rx_save();
|
||||||
|
void shared_memory_scratchpad_region_rx_restore();
|
||||||
|
void shared_memory_write(uint8_t cmd, uint8_t value);
|
||||||
|
int shared_memory_read(uint8_t *cmd, uint8_t *len,uint8_t *buffer);
|
||||||
|
|
||||||
|
#endif
|
||||||
487
avr/usbload/shell.c
Normal file
487
avr/usbload/shell.c
Normal file
@@ -0,0 +1,487 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include <avr/eeprom.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "pwm.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "info.h"
|
||||||
|
#include "sram.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "uart.h"
|
||||||
|
#include "dump.h"
|
||||||
|
#include "irq.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "crc.h"
|
||||||
|
#include "command.h"
|
||||||
|
#include "shared_memory.h"
|
||||||
|
#include "system.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern system_t system;
|
||||||
|
|
||||||
|
uint8_t command_buf[RECEIVE_BUF_LEN];
|
||||||
|
uint8_t recv_buf[RECEIVE_BUF_LEN];
|
||||||
|
|
||||||
|
volatile uint8_t recv_counter = 0;
|
||||||
|
volatile uint8_t cr = 0;
|
||||||
|
|
||||||
|
uint8_t *token_ptr;
|
||||||
|
|
||||||
|
#ifdef DO_SHELL
|
||||||
|
|
||||||
|
uint8_t *get_token(void)
|
||||||
|
{
|
||||||
|
uint8_t *p = token_ptr;
|
||||||
|
while (*p == ' ')
|
||||||
|
p++;
|
||||||
|
if (*p == '\0')
|
||||||
|
return NULL;
|
||||||
|
token_ptr = p;
|
||||||
|
do {
|
||||||
|
token_ptr++;
|
||||||
|
if (*token_ptr == ' ' || *token_ptr == '\n' || *token_ptr == '\r') {
|
||||||
|
*token_ptr++ = '\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (*token_ptr != ' ' && *token_ptr != '\n' && *token_ptr != '\r');
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t get_dec(uint32_t *decval)
|
||||||
|
{
|
||||||
|
const uint8_t *t;
|
||||||
|
t = get_token();
|
||||||
|
if (t != NULL) {
|
||||||
|
int x = util_sscandec(t);
|
||||||
|
if (x < 0)
|
||||||
|
return 0;
|
||||||
|
*decval = x;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t parse_hex(const uint8_t *s, uint32_t *hexval)
|
||||||
|
{
|
||||||
|
uint32_t x = util_sscanhex(s);
|
||||||
|
*hexval = (uint32_t) x;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t get_hex(uint32_t *hexval)
|
||||||
|
{
|
||||||
|
const uint8_t *t;
|
||||||
|
t = get_token();
|
||||||
|
if (t != NULL)
|
||||||
|
return parse_hex(t, hexval);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t get_hex_arg2(uint32_t *hexval1, uint32_t *hexval2)
|
||||||
|
{
|
||||||
|
return get_hex(hexval1) && get_hex(hexval2);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t get_hex_arg3(uint32_t *hexval1, uint32_t *hexval2, uint32_t *hexval3)
|
||||||
|
{
|
||||||
|
return get_hex(hexval1) && get_hex(hexval2) && get_hex(hexval3);
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t get_int32(uint32_t *val)
|
||||||
|
{
|
||||||
|
if (!get_hex(val)){
|
||||||
|
info_P(PSTR("Invalid argument!\n"));
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t get_int8(uint8_t *val)
|
||||||
|
{
|
||||||
|
uint32_t ret;
|
||||||
|
if (!get_hex(&ret) ||ret > 0xff){
|
||||||
|
info_P(PSTR("Invalid argument!\n"));
|
||||||
|
return 0;
|
||||||
|
}else{
|
||||||
|
*val = (uint8_t)ret;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int get_bool(void)
|
||||||
|
{
|
||||||
|
const uint8_t *t;
|
||||||
|
t = get_token();
|
||||||
|
if (t != NULL) {
|
||||||
|
int result = util_sscanbool(t);
|
||||||
|
if (result >= 0)
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
info_P(PSTR("Invalid argument (should be 0 or 1)!\n"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
void prompt(void){
|
||||||
|
|
||||||
|
uart_putc('\r');
|
||||||
|
uart_putc('\n');
|
||||||
|
uart_putc('>');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ISR(USART0_RX_vect)
|
||||||
|
{
|
||||||
|
UCSR0B &= (255 - (1<<RXCIE0));// Interrupts disable for RxD
|
||||||
|
sei();
|
||||||
|
if(recv_counter == (sizeof(recv_buf)-1)) {
|
||||||
|
cr=1;
|
||||||
|
recv_buf[recv_counter]='\0';
|
||||||
|
recv_counter=0;
|
||||||
|
prompt();
|
||||||
|
}
|
||||||
|
recv_buf[recv_counter] = UDR0;
|
||||||
|
uart_putc(recv_buf[recv_counter]);
|
||||||
|
if (recv_buf[recv_counter] == 0x0d) {
|
||||||
|
/* recv_buf[recv_counter] = 0; */
|
||||||
|
cr = 1;
|
||||||
|
recv_buf[++recv_counter]='\0';
|
||||||
|
recv_counter = 0;
|
||||||
|
prompt();
|
||||||
|
} else {
|
||||||
|
// we accept backspace or delete
|
||||||
|
if ((recv_buf[recv_counter] == 0x08 || recv_buf[recv_counter] == 0x7f) && recv_counter > 0) {
|
||||||
|
recv_counter--;
|
||||||
|
} else {
|
||||||
|
recv_counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UCSR0B |= (1<<RXCIE0);
|
||||||
|
}
|
||||||
|
|
||||||
|
enum cmds {
|
||||||
|
CMD_DUMP,
|
||||||
|
CMD_DUMPVEC,
|
||||||
|
CMD_DUMPHEADER,
|
||||||
|
CMD_CRC,
|
||||||
|
CMD_EXIT,
|
||||||
|
CMD_RESET,
|
||||||
|
CMD_RESETSNIFF,
|
||||||
|
CMD_IRQ,
|
||||||
|
CMD_AVR,
|
||||||
|
CMD_SNES,
|
||||||
|
CMD_LOROM,
|
||||||
|
CMD_HIROM,
|
||||||
|
CMD_WR,
|
||||||
|
CMD_SHMWR,
|
||||||
|
CMD_SHMSAVE,
|
||||||
|
CMD_SHMRESTORE,
|
||||||
|
CMD_LOADER,
|
||||||
|
CMD_RECONNECT,
|
||||||
|
CMD_STATUS,
|
||||||
|
CMD_SYS,
|
||||||
|
CMD_HELP
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t cmdlist[][CMD_HELP] PROGMEM = {
|
||||||
|
{"DUMP"},
|
||||||
|
{"DUMPVEC"},
|
||||||
|
{"DUMPHEADER"},
|
||||||
|
{"CRC"},
|
||||||
|
{"EXIT"},
|
||||||
|
{"RESET"},
|
||||||
|
{"RESETSNIFF"},
|
||||||
|
{"IRQ"},
|
||||||
|
{"AVR"},
|
||||||
|
{"SNES"},
|
||||||
|
{"LOROM"},
|
||||||
|
{"HIROM"},
|
||||||
|
{"WR"},
|
||||||
|
{"SHMWR"},
|
||||||
|
{"SHMSAVE"},
|
||||||
|
{"SHMRESTORE"},
|
||||||
|
{"LOADER"},
|
||||||
|
{"RECONNECT"},
|
||||||
|
{"STATUS"},
|
||||||
|
{"SYS"},
|
||||||
|
{"HELP"},
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void shell_help(void){
|
||||||
|
uint8_t i;
|
||||||
|
info_P(PSTR("\n"));
|
||||||
|
for (i=CMD_DUMP; i<CMD_HELP; i++){
|
||||||
|
info_P((PGM_P)cmdlist[i]);
|
||||||
|
info_P(PSTR("\n"));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void shell_run(void)
|
||||||
|
{
|
||||||
|
uint8_t *t;
|
||||||
|
uint32_t arg1;
|
||||||
|
uint32_t arg2;
|
||||||
|
uint32_t arg3;
|
||||||
|
uint16_t crc;
|
||||||
|
uint16_t offset;
|
||||||
|
uint16_t i;
|
||||||
|
uint8_t c;
|
||||||
|
|
||||||
|
if (!cr)
|
||||||
|
return;
|
||||||
|
cr=0;
|
||||||
|
strcpy((char*)command_buf, (char*)recv_buf);
|
||||||
|
|
||||||
|
token_ptr = command_buf;
|
||||||
|
t = get_token();
|
||||||
|
|
||||||
|
if (t == NULL)
|
||||||
|
shell_help();
|
||||||
|
|
||||||
|
util_strupper(t);
|
||||||
|
|
||||||
|
if (strcmp_P((const char*)t,(PGM_P)cmdlist[CMD_DUMP]) == 0) {
|
||||||
|
if (get_hex_arg2(&arg1,&arg2))
|
||||||
|
dump_memory(arg1,arg2);
|
||||||
|
else
|
||||||
|
info_P(PSTR("DUMP <start addr> <end addr>\n"));
|
||||||
|
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_CRC]) == 0) {
|
||||||
|
if (get_hex_arg2(&arg1,&arg2)){
|
||||||
|
crc = crc_check_bulk_memory(arg1,arg2,0x8000);
|
||||||
|
info_P(PSTR("0x%06lx - 0x%06lx crc=0x%04x\n"),arg1,arg2,crc);
|
||||||
|
} else
|
||||||
|
info_P(PSTR("CRC <start addr> <end addr>\n"));
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_EXIT]) == 0) {
|
||||||
|
leave_application();
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_RESET]) == 0) {
|
||||||
|
system_send_snes_reset();
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_IRQ]) == 0) {
|
||||||
|
info_P(PSTR("Send IRQ\n"));
|
||||||
|
snes_irq_on();
|
||||||
|
snes_irq_lo();
|
||||||
|
_delay_us(20);
|
||||||
|
snes_irq_hi();
|
||||||
|
snes_irq_off();
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_AVR]) == 0) {
|
||||||
|
//info_P(PSTR("Activate AVR bus\n"));
|
||||||
|
//avr_bus_active();
|
||||||
|
//snes_irq_lo();
|
||||||
|
//snes_irq_off();
|
||||||
|
system_set_bus_avr();
|
||||||
|
snes_irq_lo();
|
||||||
|
system_snes_irq_off();
|
||||||
|
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SNES]) == 0) {
|
||||||
|
//info_P(PSTR("Activate SNES bus\n"));
|
||||||
|
//snes_irq_lo();
|
||||||
|
//snes_irq_off();
|
||||||
|
//snes_wr_disable();
|
||||||
|
//snes_bus_active();
|
||||||
|
snes_irq_lo();
|
||||||
|
system_snes_irq_off();
|
||||||
|
system_set_wr_disable();
|
||||||
|
system_set_bus_snes();
|
||||||
|
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_LOROM]) == 0) {
|
||||||
|
//info_P(PSTR("Set LOROM\n"));
|
||||||
|
//snes_lorom();
|
||||||
|
//snes_wr_disable();
|
||||||
|
system_set_rom_lorom();
|
||||||
|
system_set_wr_disable();
|
||||||
|
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_HIROM]) == 0) {
|
||||||
|
//info_P(PSTR("Set HIROM\n"));
|
||||||
|
//snes_hirom();
|
||||||
|
//snes_wr_disable();
|
||||||
|
system_set_rom_hirom();
|
||||||
|
system_set_wr_disable();
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_WR]) == 0) {
|
||||||
|
arg1 = get_bool();
|
||||||
|
if(arg1==1){
|
||||||
|
info_P(PSTR("Set WR enable"));
|
||||||
|
snes_wr_enable();
|
||||||
|
}else if (arg1==0){
|
||||||
|
info_P(PSTR("Set WR disable"));
|
||||||
|
snes_wr_disable();
|
||||||
|
}
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_RESETSNIFF]) == 0) {
|
||||||
|
arg1 = get_bool();
|
||||||
|
if(arg1==1){
|
||||||
|
info_P(PSTR("Start Reset sniffer"));
|
||||||
|
irq_init();
|
||||||
|
}else if (arg1==0){
|
||||||
|
info_P(PSTR("Stop Reset sniffer"));
|
||||||
|
irq_stop();
|
||||||
|
}
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_DUMPVEC]) == 0) {
|
||||||
|
uint16_t offset;
|
||||||
|
if (system.rom_mode==LOROM)
|
||||||
|
offset = 0x8000;
|
||||||
|
else
|
||||||
|
offset = 0x0000;
|
||||||
|
|
||||||
|
info_P(PSTR("ABORT 0x%04x 0x%04x\n"), (0xFFE8 - offset),sram_read16_be(0xFFE8 - offset));
|
||||||
|
info_P(PSTR("BRK 0x%04x 0x%04x\n"), (0xFFE6 - offset),sram_read16_be(0xFFE6 - offset));
|
||||||
|
info_P(PSTR("COP 0x%04x 0x%04x\n"), (0xFFE4 - offset),sram_read16_be(0xFFE4 - offset));
|
||||||
|
info_P(PSTR("IRQ 0x%04x 0x%04x\n"), (0xFFEE - offset),sram_read16_be(0xFFEE - offset));
|
||||||
|
info_P(PSTR("NMI 0x%04x 0x%04x\n"), (0xFFEA - offset),sram_read16_be(0xFFEA - offset));
|
||||||
|
info_P(PSTR("RES 0x%04x 0x%04x\n"), (0xFFFC - offset),sram_read16_be(0xFFFC - offset));
|
||||||
|
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_DUMPHEADER]) == 0) {
|
||||||
|
|
||||||
|
if (system.rom_mode==LOROM)
|
||||||
|
offset = 0x8000;
|
||||||
|
else
|
||||||
|
offset = 0x0000;
|
||||||
|
/*
|
||||||
|
# $ffc0..$ffd4 => Name of the ROM, typically in ASCII, using spaces to pad the name to 21 bytes.
|
||||||
|
# $ffd5 => ROM layout, typically $20 for LoROM, or $21 for HiROM. Add $10 for FastROM.
|
||||||
|
# $ffd6 => Cartridge type, typically $00 for ROM only, or $02 for ROM with save-RAM.
|
||||||
|
# $ffd7 => ROM size byte.
|
||||||
|
# $ffd8 => RAM size byte.
|
||||||
|
# $ffd9 => Country code, which selects the video in the emulator. Values $00, $01, $0d use NTSC. Values in range $02..$0c use PAL. Other values are invalid.
|
||||||
|
# $ffda => Licensee code. If this value is $33, then the ROM has an extended header with ID at $ffb2..$ffb5.
|
||||||
|
# $ffdb => Version number, typically $00.
|
||||||
|
# $ffdc..$ffdd => Checksum complement, which is the bitwise-xor of the checksum and $ffff.
|
||||||
|
# $ffde..$ffdf => SNES checksum, an unsigned 16-bit checksum of bytes.
|
||||||
|
# $ffe0..$ffe3 => Unknown.
|
||||||
|
*/
|
||||||
|
info_P(PSTR("NAME 0x%04x "), (0xffc0 - offset));
|
||||||
|
for(arg1=(0xffc0 - offset); arg1<(0xffc0 - offset + 21);arg1++){
|
||||||
|
c = sram_read(arg1);
|
||||||
|
if (c>0x1f && c<0x7f)
|
||||||
|
printf("%c",c);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
c = sram_read(0xffd5 - offset);
|
||||||
|
info_P(PSTR("LAYOUT 0x%04x "), (0xffd5 - offset));
|
||||||
|
|
||||||
|
switch(c){
|
||||||
|
case 0x20:
|
||||||
|
info_P(PSTR("LoROM, not fast\n"));
|
||||||
|
break;
|
||||||
|
case 0x21:
|
||||||
|
info_P(PSTR("HiRom, not fast\n"));
|
||||||
|
break;
|
||||||
|
case 0x30:
|
||||||
|
info_P(PSTR("LoROM, fast\n"));
|
||||||
|
break;
|
||||||
|
case 0x31:
|
||||||
|
info_P(PSTR("HiRom, fast\n"));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
info_P(PSTR("Unkown 0x%02x\n"),c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
c = sram_read(0xffd6 - offset);
|
||||||
|
info_P(PSTR("TYPE 0x%04x "), (0xffd6 - offset),c);
|
||||||
|
switch(c){
|
||||||
|
case 0x00:
|
||||||
|
info_P(PSTR("Rom\n"));
|
||||||
|
break;
|
||||||
|
case 0x01:
|
||||||
|
info_P(PSTR("Rom + Sram\n"));
|
||||||
|
break;
|
||||||
|
case 0x02:
|
||||||
|
info_P(PSTR("Rom + Sram + Battery\n"));
|
||||||
|
break;
|
||||||
|
case 0x13:
|
||||||
|
info_P(PSTR("SuperFX\n"));
|
||||||
|
break;
|
||||||
|
case 0x14:
|
||||||
|
info_P(PSTR("SuperFX\n"));
|
||||||
|
break;
|
||||||
|
case 0x15:
|
||||||
|
info_P(PSTR("SuperFX + Sram\n"));
|
||||||
|
break;
|
||||||
|
case 0x1a:
|
||||||
|
info_P(PSTR("SuperFX + Sram\n"));
|
||||||
|
break;
|
||||||
|
case 0x34:
|
||||||
|
info_P(PSTR("SA-1"));
|
||||||
|
break;
|
||||||
|
case 0x35:
|
||||||
|
info_P(PSTR("SA-1"));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
info_P(PSTR("Unkown 0x%02x\n"),c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
arg1 = ( 2 << ( sram_read(0xffd7 - offset) - 1 ));
|
||||||
|
info_P(PSTR("ROM 0x%04x %li MBit ( %li KiB)\n"), (0xffd7 - offset), (arg1 / 128), arg1);
|
||||||
|
arg1 = ( 2 << ( sram_read(0xffd8 - offset) - 1 ));
|
||||||
|
info_P(PSTR("RAM 0x%04x %li KiB\n"), (0xffd8 - offset), arg1);
|
||||||
|
|
||||||
|
info_P(PSTR("CCODE 0x%04x "), (0xffd9 - offset));
|
||||||
|
c = sram_read(0xffd9 - offset);
|
||||||
|
if (c==0x00 || c==0x01 || 0x0d )
|
||||||
|
info_P(PSTR("NTSC\n"));
|
||||||
|
else if (c>=0x02 || c<=0x0c )
|
||||||
|
info_P(PSTR("PAL\n"));
|
||||||
|
else
|
||||||
|
info_P(PSTR("Unkown 0x%02x\n"),c);
|
||||||
|
|
||||||
|
info_P(PSTR("LIC 0x%04x 0x%02x\n"), (0xffda - offset),sram_read(0xffda - offset));
|
||||||
|
info_P(PSTR("VER 0x%04x 0x%02x\n"), (0xffdb - offset),sram_read(0xffdb - offset));
|
||||||
|
info_P(PSTR("SUM1 0x%04x 0x%04x\n"), (0xffdc - offset),sram_read16_be(0xffdc - offset));
|
||||||
|
info_P(PSTR("SUM2 0x%04x 0x%04x\n"), (0xffde - offset),sram_read16_be(0xffde - offset));
|
||||||
|
|
||||||
|
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SHMWR]) == 0) {
|
||||||
|
if (get_hex_arg2(&arg1,&arg2))
|
||||||
|
shared_memory_write((uint8_t)arg1, (uint8_t)arg1);
|
||||||
|
else
|
||||||
|
info_P(PSTR("SHMWR <command> <value>\n"));
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SHMSAVE]) == 0) {
|
||||||
|
shared_memory_scratchpad_region_tx_save();
|
||||||
|
shared_memory_scratchpad_region_rx_save();
|
||||||
|
info_P(PSTR("Save scratchpad\n"));
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SHMRESTORE]) == 0) {
|
||||||
|
shared_memory_scratchpad_region_tx_restore();
|
||||||
|
shared_memory_scratchpad_region_rx_restore();
|
||||||
|
info_P(PSTR("Restore scratchpad\n"));
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_LOADER]) == 0) {
|
||||||
|
boot_startup_rom(500);
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_RECONNECT]) == 0) {
|
||||||
|
usb_connect();
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_STATUS]) == 0) {
|
||||||
|
transaction_status();
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SYS]) == 0) {
|
||||||
|
system_status();
|
||||||
|
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_HELP]) == 0) {
|
||||||
|
shell_help();
|
||||||
|
}
|
||||||
|
prompt();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
26
avr/usbload/shell.h
Normal file
26
avr/usbload/shell.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SHELL_H__
|
||||||
|
#define __SHELL_H__
|
||||||
|
|
||||||
|
void shell_run(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
338
avr/usbload/sram.c
Normal file
338
avr/usbload/sram.c
Normal file
@@ -0,0 +1,338 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <util/delay.h> /* for _delay_ms() */
|
||||||
|
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "sram.h"
|
||||||
|
#include "uart.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "info.h"
|
||||||
|
|
||||||
|
uint32_t addr_current = 0;
|
||||||
|
uint32_t addr_stash = 0;
|
||||||
|
|
||||||
|
void sram_init(void)
|
||||||
|
{
|
||||||
|
/*-------------------------------------------------*/
|
||||||
|
|
||||||
|
DDRA = 0x00;
|
||||||
|
PORTA = 0x00;
|
||||||
|
|
||||||
|
/*-------------------------------------------------*/
|
||||||
|
|
||||||
|
DDRC |= ( (1 << AVR_ADDR_LATCH_PIN)
|
||||||
|
| (1 << AVR_ADDR_SCK_PIN)
|
||||||
|
| (1 << AVR_ADDR_SER_PIN)
|
||||||
|
| (1 << AVR_ADDR_LOAD_PIN)
|
||||||
|
| (1 << AVR_ADDR_UP_PIN));
|
||||||
|
|
||||||
|
DDRC &= ~ ((1 << SNES_WR_PIN)
|
||||||
|
| (1 << AVR_BTLDR_EN_PIN));
|
||||||
|
|
||||||
|
PORTC &= ~((1 << AVR_ADDR_LATCH_PIN)
|
||||||
|
| (1 << AVR_ADDR_SCK_PIN)
|
||||||
|
| (1 << SNES_WR_PIN));
|
||||||
|
|
||||||
|
|
||||||
|
PORTC |= ( (1 << AVR_ADDR_UP_PIN)
|
||||||
|
| (1 << AVR_ADDR_LOAD_PIN));
|
||||||
|
|
||||||
|
//| (1 << SNES_WR_PIN));
|
||||||
|
/*-------------------------------------------------*/
|
||||||
|
|
||||||
|
DDRB |= ( (1 << AVR_RD_PIN)
|
||||||
|
| (1 << AVR_WR_PIN)
|
||||||
|
| (1 << AVR_CS_PIN)
|
||||||
|
| (1 << SNES_IRQ_PIN));
|
||||||
|
|
||||||
|
|
||||||
|
PORTB |= ( (1 << AVR_RD_PIN)
|
||||||
|
| (1 << AVR_WR_PIN)
|
||||||
|
| (1 << AVR_CS_PIN)
|
||||||
|
| (1 << SNES_IRQ_PIN));
|
||||||
|
|
||||||
|
/*-------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
DDRD |= ( (1 << AVR_SNES_SW_PIN)
|
||||||
|
| (1 << HI_LOROM_SW_PIN)
|
||||||
|
| (1 << SNES_WR_EN_PIN));
|
||||||
|
|
||||||
|
PORTD |= (1 << HI_LOROM_SW_PIN);
|
||||||
|
|
||||||
|
PORTD &= ~((1 << AVR_SNES_SW_PIN)
|
||||||
|
| (1 << SNES_WR_EN_PIN));
|
||||||
|
|
||||||
|
/*-------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void sreg_set(uint32_t addr)
|
||||||
|
{
|
||||||
|
uint8_t i = 24;
|
||||||
|
debug_P(DEBUG_SREG, PSTR("sreg_set: addr=0x%08lx"),addr);
|
||||||
|
while(i--) {
|
||||||
|
if ((addr & ( 1L << i))){
|
||||||
|
debug_P(DEBUG_SREG, PSTR("1"));
|
||||||
|
AVR_ADDR_SER_PORT |= ( 1 << AVR_ADDR_SER_PIN);
|
||||||
|
} else {
|
||||||
|
AVR_ADDR_SER_PORT &= ~( 1 << AVR_ADDR_SER_PIN);
|
||||||
|
debug_P(DEBUG_SREG, PSTR("0"));
|
||||||
|
}
|
||||||
|
AVR_ADDR_SCK_PORT |= (1 << AVR_ADDR_SCK_PIN);
|
||||||
|
AVR_ADDR_SCK_PORT &= ~(1 << AVR_ADDR_SCK_PIN);
|
||||||
|
}
|
||||||
|
debug_P(DEBUG_SREG, PSTR("\n"));
|
||||||
|
AVR_ADDR_LATCH_PORT |= (1 << AVR_ADDR_LATCH_PIN);
|
||||||
|
AVR_ADDR_LATCH_PORT &= ~(1 << AVR_ADDR_LATCH_PIN);
|
||||||
|
|
||||||
|
counter_load();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void sram_bulk_addr_save()
|
||||||
|
{
|
||||||
|
addr_stash = addr_current;
|
||||||
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_addr_save: addr=0x%08lx\n\r"), addr_stash);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void sram_bulk_addr_restore()
|
||||||
|
{
|
||||||
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_addr_restore: addr=0x%08lx\n\r"), addr_stash);
|
||||||
|
sram_bulk_write_start(addr_stash);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void sram_bulk_read_start(uint32_t addr)
|
||||||
|
{
|
||||||
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_read_start: addr=0x%08lx\n\r"), addr);
|
||||||
|
|
||||||
|
addr_current = addr;
|
||||||
|
|
||||||
|
avr_data_in();
|
||||||
|
|
||||||
|
AVR_CS_PORT &= ~(1 << AVR_CS_PIN);
|
||||||
|
AVR_WR_PORT |= (1 << AVR_WR_PIN);
|
||||||
|
AVR_RD_PORT |= (1 << AVR_RD_PIN);
|
||||||
|
|
||||||
|
sreg_set(addr);
|
||||||
|
|
||||||
|
AVR_RD_PORT &= ~(1 << AVR_RD_PIN);
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void sram_bulk_read_next(void)
|
||||||
|
{
|
||||||
|
addr_current++;
|
||||||
|
AVR_RD_PORT |= (1 << AVR_RD_PIN);
|
||||||
|
counter_up();
|
||||||
|
AVR_RD_PORT &= ~(1 << AVR_RD_PIN);
|
||||||
|
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline uint8_t sram_bulk_read(void)
|
||||||
|
{
|
||||||
|
return AVR_DATA_PIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sram_bulk_read_end(void)
|
||||||
|
{
|
||||||
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_read_end:\n"));
|
||||||
|
|
||||||
|
AVR_RD_PORT |= (1 << AVR_RD_PIN);
|
||||||
|
AVR_CS_PORT |= (1 << AVR_CS_PIN);
|
||||||
|
avr_data_in();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t sram_read(uint32_t addr)
|
||||||
|
{
|
||||||
|
uint8_t byte;
|
||||||
|
debug_P(DEBUG_SRAM_RAW, PSTR("sram_read: addr=0x%08lx\n\r"), addr);
|
||||||
|
|
||||||
|
avr_data_in();
|
||||||
|
|
||||||
|
AVR_CS_PORT &= ~(1 << AVR_CS_PIN);
|
||||||
|
|
||||||
|
AVR_WR_PORT |= (1 << AVR_WR_PIN);
|
||||||
|
AVR_RD_PORT |= (1 << AVR_RD_PIN);
|
||||||
|
|
||||||
|
sreg_set(addr);
|
||||||
|
|
||||||
|
AVR_RD_PORT &= ~(1 << AVR_RD_PIN);
|
||||||
|
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
|
||||||
|
byte = AVR_DATA_PIN;
|
||||||
|
|
||||||
|
AVR_RD_PORT |= (1 << AVR_RD_PIN);
|
||||||
|
AVR_CS_PORT |= (1 << AVR_CS_PIN);
|
||||||
|
|
||||||
|
avr_data_in();
|
||||||
|
return byte;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t sram_read16_be(uint32_t addr){
|
||||||
|
uint8_t hi = sram_read(addr);
|
||||||
|
uint8_t lo = sram_read(addr+1);
|
||||||
|
return (hi << 8 | lo );
|
||||||
|
}
|
||||||
|
|
||||||
|
void sram_bulk_write_start(uint32_t addr)
|
||||||
|
{
|
||||||
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_write_start: addr=0x%08lx\n\r"), addr);
|
||||||
|
addr_current = addr;
|
||||||
|
|
||||||
|
avr_data_out();
|
||||||
|
|
||||||
|
AVR_CS_PORT &= ~(1 << AVR_CS_PIN);
|
||||||
|
AVR_WR_PORT |= (1 << AVR_WR_PIN);
|
||||||
|
AVR_RD_PORT |= (1 << AVR_RD_PIN);
|
||||||
|
|
||||||
|
sreg_set(addr);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void sram_bulk_write_next(void)
|
||||||
|
{
|
||||||
|
AVR_WR_PORT &= ~(1 << AVR_WR_PIN);
|
||||||
|
addr_current++;
|
||||||
|
counter_up();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void sram_bulk_write( uint8_t data)
|
||||||
|
{
|
||||||
|
AVR_WR_PORT &= ~(1 << AVR_WR_PIN);
|
||||||
|
AVR_DATA_PORT = data;
|
||||||
|
AVR_WR_PORT |= (1 << AVR_WR_PIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sram_bulk_write_end(void)
|
||||||
|
{
|
||||||
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_write_end:"));
|
||||||
|
AVR_WR_PORT |= (1 << AVR_WR_PIN);
|
||||||
|
AVR_CS_PORT |= (1 << AVR_CS_PIN);
|
||||||
|
avr_data_in();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void sram_write(uint32_t addr, uint8_t data)
|
||||||
|
{
|
||||||
|
debug_P(DEBUG_SRAM_RAW, PSTR("sram_write: addr=0x%08lx data=%x\n\r"), addr, data);
|
||||||
|
|
||||||
|
avr_data_out();
|
||||||
|
|
||||||
|
AVR_CS_PORT &= ~(1 << AVR_CS_PIN);
|
||||||
|
AVR_WR_PORT |= (1 << AVR_WR_PIN);
|
||||||
|
AVR_RD_PORT |= (1 << AVR_RD_PIN);
|
||||||
|
|
||||||
|
sreg_set(addr);
|
||||||
|
|
||||||
|
AVR_WR_PORT &= ~(1 << AVR_WR_PIN);
|
||||||
|
|
||||||
|
|
||||||
|
AVR_DATA_PORT = data;
|
||||||
|
|
||||||
|
|
||||||
|
AVR_WR_PORT |= (1 << AVR_WR_PIN);
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
asm volatile ("nop");
|
||||||
|
AVR_CS_PORT |= (1 << AVR_CS_PIN);
|
||||||
|
|
||||||
|
avr_data_in();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void sram_bulk_copy_from_buffer(uint32_t addr, uint8_t * src, uint32_t len)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint32_t i;
|
||||||
|
uint8_t *ptr = src;
|
||||||
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_copy_from_buffer: addr=0x%08lx src=0x%p len=%li\n\r"),
|
||||||
|
addr, src, len);
|
||||||
|
sram_bulk_write_start(addr);
|
||||||
|
for (i = addr; i < (addr + len); i++){
|
||||||
|
sram_bulk_write(*ptr);
|
||||||
|
//hack
|
||||||
|
if ((i+1) < (addr + len))
|
||||||
|
sram_bulk_write_next();
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
sram_bulk_write_end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void sram_bulk_copy_into_buffer(uint32_t addr, uint8_t * dst, uint32_t len)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint32_t i;
|
||||||
|
uint8_t *ptr = dst;
|
||||||
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_copy_into_buffer: addr=0x%08lx dst=0x%p len=%li\n\r"),
|
||||||
|
addr, dst, len);
|
||||||
|
sram_bulk_read_start(addr);
|
||||||
|
for (i = addr; i < (addr + len); i++) {
|
||||||
|
dst[i] = sram_bulk_read();
|
||||||
|
sram_bulk_read_next();
|
||||||
|
}
|
||||||
|
sram_bulk_read_end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void sram_bulk_set(uint32_t addr, uint32_t len,uint8_t value){
|
||||||
|
uint32_t i;
|
||||||
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_set: addr=0x%08lx len=%li\n\r"), addr,len);
|
||||||
|
sram_bulk_write_start(addr);
|
||||||
|
for (i = addr; i < (addr + len); i++) {
|
||||||
|
if (0 == i % 0xfff)
|
||||||
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_set: addr=0x%08lx\n\r"), i);
|
||||||
|
sram_bulk_write(value);
|
||||||
|
sram_bulk_write_next();
|
||||||
|
}
|
||||||
|
sram_bulk_write_end();
|
||||||
|
}
|
||||||
|
|
||||||
226
avr/usbload/sram.h
Normal file
226
avr/usbload/sram.h
Normal file
@@ -0,0 +1,226 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __SRAM_H__
|
||||||
|
#define __SRAM_H__
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ---------------------------- PORT A ---------------------------- */
|
||||||
|
|
||||||
|
#define AVR_DATA_PORT PORTA
|
||||||
|
#define AVR_DATA_DIR DDRA
|
||||||
|
#define AVR_DATA_PIN PINA
|
||||||
|
|
||||||
|
#define avr_data_in() ((AVR_DATA_DIR = 0x00),\
|
||||||
|
(AVR_DATA_PORT = 0x00))
|
||||||
|
|
||||||
|
#define avr_data_out() (AVR_DATA_DIR = 0xff)
|
||||||
|
|
||||||
|
|
||||||
|
/* ---------------------------- PORT B ---------------------------- */
|
||||||
|
|
||||||
|
#define AVR_PORT PORTB
|
||||||
|
#define AVR_DIR DDRB
|
||||||
|
#define AVR_RD_PORT PORTB
|
||||||
|
#define AVR_RD_DIR DDRB
|
||||||
|
#define AVR_RD_PIN PB2
|
||||||
|
|
||||||
|
#define avr_rd_hi() (AVR_RD_PORT |= (1 << AVR_RD_PIN))
|
||||||
|
#define avr_rd_lo() (AVR_RD_PORT &= ~(1 << AVR_RD_PIN))
|
||||||
|
|
||||||
|
#define AVR_WR_PORT PORTB
|
||||||
|
#define AVR_WR_DIR DDRB
|
||||||
|
#define AVR_WR_PIN PB1
|
||||||
|
|
||||||
|
#define avr_wr_hi() (AVR_WR_PORT |= (1 << AVR_WR_PIN))
|
||||||
|
#define avr_wr_lo() (AVR_WR_PORT &= ~(1 << AVR_WR_PIN))
|
||||||
|
|
||||||
|
#define AVR_CS_PORT PORTB
|
||||||
|
#define AVR_CS_DIR DDRB
|
||||||
|
#define AVR_CS_PIN PB0
|
||||||
|
|
||||||
|
#define avr_cs_hi() (AVR_CS_PORT |= (1 << AVR_CS_PIN))
|
||||||
|
#define avr_cs_lo() (AVR_CS_PORT &= ~(1 << AVR_CS_PIN))
|
||||||
|
|
||||||
|
#define SNES_IRQ_PORT PORTB
|
||||||
|
#define SNES_IRQ_DIR DDRB
|
||||||
|
#define SNES_IRQ_PIN PB3
|
||||||
|
|
||||||
|
|
||||||
|
#define snes_irq_on() (SNES_IRQ_DIR |= (1 << SNES_IRQ_PIN))
|
||||||
|
#define snes_irq_hi() (SNES_IRQ_PORT |= (1 << SNES_IRQ_PIN))
|
||||||
|
|
||||||
|
#define snes_irq_off() (SNES_IRQ_DIR &= ~(1 << SNES_IRQ_PIN))
|
||||||
|
#define snes_irq_lo() (SNES_IRQ_PORT &= ~(1 << SNES_IRQ_PIN))
|
||||||
|
|
||||||
|
|
||||||
|
/* ---------------------------- PORT C ---------------------------- */
|
||||||
|
|
||||||
|
#define AVR_ADDR_PORT PORTC
|
||||||
|
#define AVR_ADDR_DIR DDRC
|
||||||
|
#define AVR_ADDR_LATCH_PORT PORTC
|
||||||
|
#define AVR_ADDR_LATCH_DIR DDRC
|
||||||
|
#define AVR_ADDR_LATCH_PIN PC6
|
||||||
|
|
||||||
|
#define avr_addr_latch_hi() (AVR_ADDR_LATCH_PORT |= (1 << AVR_ADDR_LATCH_PIN))
|
||||||
|
#define avr_addr_latch_lo() (AVR_ADDR_LATCH_PORT &= ~(1 << AVR_ADDR_LATCH_PIN))
|
||||||
|
|
||||||
|
#define AVR_ADDR_SCK_PORT PORTC
|
||||||
|
#define AVR_ADDR_SCK_DIR DDRC
|
||||||
|
#define AVR_ADDR_SCK_PIN PC5
|
||||||
|
|
||||||
|
#define avr_addr_sck_hi() (AVR_ADDR_SCK_PORT |= (1 << AVR_ADDR_SCK_PIN))
|
||||||
|
#define avr_addr_sck_lo() (AVR_ADDR_SCK_PORT &= ~(1 << AVR_ADDR_SCK_PIN))
|
||||||
|
|
||||||
|
#define AVR_ADDR_SER_PORT PORTC
|
||||||
|
#define AVR_ADDR_SER_DIR DDRC
|
||||||
|
#define AVR_ADDR_SER_PIN PC4
|
||||||
|
|
||||||
|
#define avr_addr_ser_hi() (AVR_ADDR_SER_PORT |= (1 << AVR_ADDR_SER_PIN))
|
||||||
|
#define avr_addr_ser_lo() (AVR_ADDR_SER_PORT &= ~(1 << AVR_ADDR_SER_PIN))
|
||||||
|
|
||||||
|
#define AVR_ADDR_LOAD_PORT PORTC
|
||||||
|
#define AVR_ADDR_LOAD_DIR DDRC
|
||||||
|
#define AVR_ADDR_LOAD_PIN PC2
|
||||||
|
|
||||||
|
#define counter_load() ((AVR_ADDR_LOAD_PORT &= ~(1 << AVR_ADDR_LOAD_PIN)),\
|
||||||
|
(AVR_ADDR_LOAD_PORT |= (1 << AVR_ADDR_LOAD_PIN)))
|
||||||
|
|
||||||
|
#define AVR_BTLDR_EN_PORT PORTC
|
||||||
|
#define AVR_BTLDR_EN_DIR DDRC
|
||||||
|
#define AVR_BTLDR_EN_PIN PC1
|
||||||
|
|
||||||
|
#define btldr_down() ((AVR_BTLDR_EN_PORT &= ~(1 << AVR_BTLDR_EN_PIN)),\
|
||||||
|
(AVR_BTLDR_EN_PORT |= (1 << AVR_BTLDR_EN_PIN)))
|
||||||
|
|
||||||
|
#define AVR_ADDR_UP_PORT PORTC
|
||||||
|
#define AVR_ADDR_UP_DIR DDRC
|
||||||
|
#define AVR_ADDR_UP_PIN PC0
|
||||||
|
|
||||||
|
#define counter_up() ((AVR_ADDR_UP_PORT &= ~(1 << AVR_ADDR_UP_PIN)),\
|
||||||
|
(AVR_ADDR_UP_PORT |= (1 << AVR_ADDR_UP_PIN)))
|
||||||
|
|
||||||
|
#define SNES_WR_PORT PORTC
|
||||||
|
#define SNES_WR_DIR DDRC
|
||||||
|
#define SNES_WR_PIN PC3
|
||||||
|
|
||||||
|
#define LED_PORT PORTC
|
||||||
|
#define LED_DIR DDRC
|
||||||
|
#define LED_PIN PC7
|
||||||
|
|
||||||
|
#define led_on() ((LED_PORT &=~ (1 << LED_PIN)),\
|
||||||
|
(LED_DIR &=~ (1 << LED_PIN)))
|
||||||
|
#define led_off() ((LED_PORT &=~ (1 << LED_PIN)),\
|
||||||
|
(LED_DIR |= (1 << LED_PIN)))
|
||||||
|
|
||||||
|
#define led_pwm_on() (LED_DIR &=~ (1 << LED_PIN))
|
||||||
|
#define led_pwm_off() (LED_DIR |= (1 << LED_PIN))
|
||||||
|
|
||||||
|
/* ---------------------------- PORT D ---------------------------- */
|
||||||
|
|
||||||
|
#define AVR_SNES_PORT PORTD
|
||||||
|
#define AVR_SNES_DIR DDRD
|
||||||
|
#define AVR_SNES_SW_PORT PORTD
|
||||||
|
#define AVR_SNES_SW_DIR DDRD
|
||||||
|
#define AVR_SNES_SW_PIN PD5
|
||||||
|
|
||||||
|
#define avr_bus_active() ((AVR_SNES_SW_PORT &= ~(1 << AVR_SNES_SW_PIN)),\
|
||||||
|
(HI_LOROM_SW_PORT |= (1 << HI_LOROM_SW_PIN)),\
|
||||||
|
(AVR_CS_DIR |= (1 << AVR_CS_PIN)))
|
||||||
|
|
||||||
|
#define snes_bus_active() ((AVR_SNES_SW_PORT |= (1 << AVR_SNES_SW_PIN)),\
|
||||||
|
(AVR_CS_DIR &= ~(1 << AVR_CS_PIN)),\
|
||||||
|
(AVR_CS_PORT |= (1 << AVR_CS_PIN)))
|
||||||
|
|
||||||
|
#define HI_LOROM_SW_PORT PORTD
|
||||||
|
#define HI_LOROM_SW_DIR DDRD
|
||||||
|
#define HI_LOROM_SW_PIN PD6
|
||||||
|
|
||||||
|
#define snes_hirom() (HI_LOROM_SW_PORT &= ~(1 << HI_LOROM_SW_PIN))
|
||||||
|
#define snes_lorom() (HI_LOROM_SW_PORT |= (1 << HI_LOROM_SW_PIN))
|
||||||
|
|
||||||
|
#define SNES_WR_EN_PORT PORTD
|
||||||
|
#define SNES_WR_EN_DIR DDRD
|
||||||
|
#define SNES_WR_EN_PIN PD7
|
||||||
|
|
||||||
|
#define snes_wr_disable() (SNES_WR_EN_PORT &= ~(1 << SNES_WR_EN_PIN))
|
||||||
|
|
||||||
|
#define snes_wr_enable() (SNES_WR_EN_PORT |= (1 << SNES_WR_EN_PIN))
|
||||||
|
|
||||||
|
#define SNES_RESET_PORT PORTD
|
||||||
|
#define SNES_RESET_DIR DDRD
|
||||||
|
#define SNES_RESET_PIN PD3
|
||||||
|
#define SNES_RESET_INP PIND
|
||||||
|
|
||||||
|
#define snes_reset_on() (SNES_RESET_DIR |= (1 << SNES_RESET_PIN))
|
||||||
|
#define snes_reset_hi() (SNES_RESET_PORT |= (1 << SNES_RESET_PIN))
|
||||||
|
|
||||||
|
#define snes_reset_off() (SNES_RESET_DIR &= ~(1 << SNES_RESET_PIN))
|
||||||
|
#define snes_reset_lo() (SNES_RESET_PORT &= ~(1 << SNES_RESET_PIN))
|
||||||
|
|
||||||
|
#define snes_reset_test() ((SNES_RESET_INP & (1 << SNES_RESET_PIN)) == 0)
|
||||||
|
|
||||||
|
#define MMC_PORT PORTB
|
||||||
|
#define MMC_DIR DDRB
|
||||||
|
|
||||||
|
#define MMC_MISO_PIN PB6
|
||||||
|
#define MMC_MOSI_PIN PB5
|
||||||
|
#define MMC_SCK_PIN PB7
|
||||||
|
#define MMC_CS_PIN PB4
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void sram_init(void);
|
||||||
|
void sreg_set(uint32_t addr);
|
||||||
|
|
||||||
|
uint8_t sram_read(uint32_t addr);
|
||||||
|
void sram_write(uint32_t addr, uint8_t data);
|
||||||
|
|
||||||
|
void sram_bulk_read_start(uint32_t addr);
|
||||||
|
inline void sram_bulk_read_next(void);
|
||||||
|
inline void sram_bulk_read_end(void);
|
||||||
|
uint8_t sram_bulk_read(void);
|
||||||
|
uint16_t sram_read16_be(uint32_t addr);
|
||||||
|
|
||||||
|
void sram_bulk_write_start(uint32_t addr);
|
||||||
|
inline void sram_bulk_write_next(void);
|
||||||
|
inline void sram_bulk_write_end(void);
|
||||||
|
void sram_bulk_write(uint8_t data);
|
||||||
|
|
||||||
|
void sram_bulk_copy_from_buffer(uint32_t addr, uint8_t * src, uint32_t len);
|
||||||
|
void sram_bulk_copy_into_buffer(uint32_t addr, uint8_t * dst, uint32_t len);
|
||||||
|
|
||||||
|
void sram_bulk_set(uint32_t addr, uint32_t len,uint8_t value);
|
||||||
|
|
||||||
|
inline void sram_bulk_addr_save();
|
||||||
|
inline void sram_bulk_addr_restore();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
186
avr/usbload/system.c
Normal file
186
avr/usbload/system.c
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <util/delay.h> /* for _delay_ms() */
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "sram.h"
|
||||||
|
#include "system.h"
|
||||||
|
#include "uart.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "info.h"
|
||||||
|
#include "requests.h"
|
||||||
|
#include "irq.h"
|
||||||
|
|
||||||
|
system_t system;
|
||||||
|
|
||||||
|
void system_init(void)
|
||||||
|
{
|
||||||
|
snes_reset_hi();
|
||||||
|
snes_reset_off();
|
||||||
|
system.reset_line = RESET_OFF;
|
||||||
|
|
||||||
|
snes_irq_hi();
|
||||||
|
snes_irq_off();
|
||||||
|
system.irq_line = IRQ_OFF;
|
||||||
|
|
||||||
|
|
||||||
|
snes_wr_disable();
|
||||||
|
system.wr_line = WR_DISABLE;
|
||||||
|
|
||||||
|
avr_bus_active();
|
||||||
|
system.bus_mode = MODE_AVR;
|
||||||
|
|
||||||
|
snes_lorom();
|
||||||
|
system.rom_mode = LOROM;
|
||||||
|
|
||||||
|
system.snes_reset_count = 0;
|
||||||
|
system.avr_reset_count = 0;
|
||||||
|
|
||||||
|
system.reset_irq = RESET_IRQ_OFF;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void system_send_snes_reset()
|
||||||
|
{
|
||||||
|
info_P(PSTR("Reset SNES\n"));
|
||||||
|
cli();
|
||||||
|
snes_reset_on();
|
||||||
|
snes_reset_lo();
|
||||||
|
_delay_ms(2);
|
||||||
|
snes_reset_hi();
|
||||||
|
snes_reset_off();
|
||||||
|
sei();
|
||||||
|
system.snes_reset_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void system_send_snes_irq()
|
||||||
|
{
|
||||||
|
snes_irq_on();
|
||||||
|
snes_irq_lo();
|
||||||
|
_delay_us(20);
|
||||||
|
snes_irq_hi();
|
||||||
|
snes_irq_off();
|
||||||
|
}
|
||||||
|
|
||||||
|
void system_snes_irq_off()
|
||||||
|
{
|
||||||
|
snes_irq_off();
|
||||||
|
system.irq_line = IRQ_OFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
void system_snes_irq_on()
|
||||||
|
{
|
||||||
|
snes_irq_on();
|
||||||
|
system.irq_line = IRQ_ON;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void system_set_bus_avr()
|
||||||
|
{
|
||||||
|
avr_bus_active();
|
||||||
|
info_P(PSTR("Activate AVR bus\n"));
|
||||||
|
system.bus_mode = MODE_AVR;
|
||||||
|
}
|
||||||
|
|
||||||
|
void system_set_wr_disable(){
|
||||||
|
snes_wr_disable();
|
||||||
|
system.wr_line = WR_DISABLE;
|
||||||
|
info_P(PSTR("Disable SNES WR\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void system_set_wr_enable(){
|
||||||
|
snes_wr_enable();
|
||||||
|
system.wr_line = WR_ENABLE;
|
||||||
|
info_P(PSTR("Enable SNES WR\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void system_set_bus_snes()
|
||||||
|
{
|
||||||
|
snes_bus_active();
|
||||||
|
system.bus_mode = MODE_SNES;
|
||||||
|
info_P(PSTR("Activate SNES bus\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void system_set_rom_mode(usb_transaction_t *usb_trans)
|
||||||
|
{
|
||||||
|
if (usb_trans->req_bank_size == 0x8000) {
|
||||||
|
snes_lorom();
|
||||||
|
system.rom_mode = LOROM;
|
||||||
|
info_P(PSTR("Set SNES lorom \n"));
|
||||||
|
} else {
|
||||||
|
snes_hirom();
|
||||||
|
system.rom_mode = HIROM;
|
||||||
|
info_P(PSTR("Set SNES hirom \n"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void system_set_rom_lorom()
|
||||||
|
{
|
||||||
|
snes_lorom();
|
||||||
|
system.rom_mode = LOROM;
|
||||||
|
info_P(PSTR("Set SNES lorom \n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void system_set_rom_hirom()
|
||||||
|
{
|
||||||
|
snes_hirom();
|
||||||
|
system.rom_mode = HIROM;
|
||||||
|
info_P(PSTR("Set SNES hirom \n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
char* system_status_helper(uint8_t val){
|
||||||
|
if (val)
|
||||||
|
return "ON";
|
||||||
|
else
|
||||||
|
return "OFF";
|
||||||
|
}
|
||||||
|
|
||||||
|
char* system_status_bus(uint8_t val){
|
||||||
|
if (val)
|
||||||
|
return "SNES";
|
||||||
|
else
|
||||||
|
return "AVR";
|
||||||
|
}
|
||||||
|
|
||||||
|
char* system_status_rom(uint8_t val){
|
||||||
|
if (val)
|
||||||
|
return "HIROM";
|
||||||
|
else
|
||||||
|
return "LOROM";
|
||||||
|
}
|
||||||
|
|
||||||
|
void system_status(){
|
||||||
|
info_P(PSTR("\nBus Mode %s\n"),system_status_bus(system.bus_mode));
|
||||||
|
info_P(PSTR("Rom Mode %s\n"),system_status_rom(system.rom_mode));
|
||||||
|
info_P(PSTR("Reset Line %s\n"),system_status_helper(system.reset_line));
|
||||||
|
info_P(PSTR("IRQ Line %s\n"),system_status_helper(system.irq_line));
|
||||||
|
info_P(PSTR("WR Line %s\n"),system_status_helper(system.wr_line));
|
||||||
|
info_P(PSTR("Reset IRQ %s\n"),system_status_helper(system.reset_irq));
|
||||||
|
info_P(PSTR("SNES Reset 0x%02x\n"),system.snes_reset_count);
|
||||||
|
info_P(PSTR("AVR Reset 0x%02x\n"),system.avr_reset_count);
|
||||||
|
}
|
||||||
57
avr/usbload/system.h
Normal file
57
avr/usbload/system.h
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __SYSTEM_H__
|
||||||
|
#define __SYSTEM_H__
|
||||||
|
|
||||||
|
#include "requests.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct system_t {
|
||||||
|
enum bus_mode_e { MODE_AVR, MODE_SNES } bus_mode;
|
||||||
|
enum rom_mode_e { LOROM, HIROM } rom_mode;
|
||||||
|
enum reset_line_e { RESET_OFF, RESET_ON } reset_line;
|
||||||
|
enum irq_line_e { IRQ_ON, IRQ_OFF } irq_line;
|
||||||
|
enum wr_line_e { WR_DISABLE, WR_ENABLE } wr_line;
|
||||||
|
enum reset_irq_e { RESET_IRQ_OFF, RESET_IRQ_ON } reset_irq;
|
||||||
|
|
||||||
|
uint8_t snes_reset_count;
|
||||||
|
uint8_t avr_reset_count;
|
||||||
|
} system_t;
|
||||||
|
|
||||||
|
void system_init(void);
|
||||||
|
void system_init(void);
|
||||||
|
void system_send_snes_reset(void);
|
||||||
|
void system_send_snes_irq(void);
|
||||||
|
void system_set_bus_avr(void);
|
||||||
|
void system_set_bus_snes(void);
|
||||||
|
void system_set_rom_mode(usb_transaction_t *usb_trans);
|
||||||
|
void system_set_rom_hirom(void);
|
||||||
|
void system_set_rom_lorom(void);
|
||||||
|
void system_snes_irq_off(void);
|
||||||
|
void system_set_wr_disable(void);
|
||||||
|
void system_set_wr_enable(void);
|
||||||
|
|
||||||
|
void system_status();
|
||||||
|
|
||||||
|
#endif
|
||||||
1184
avr/usbload/tags
Normal file
1184
avr/usbload/tags
Normal file
File diff suppressed because it is too large
Load Diff
131
avr/usbload/testing.c
Normal file
131
avr/usbload/testing.c
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
#include "shared_memory.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "sram.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "crc.h"
|
||||||
|
#include "info.h"
|
||||||
|
#include "dump.h"
|
||||||
|
|
||||||
|
void test_read_write()
|
||||||
|
{
|
||||||
|
|
||||||
|
uint8_t i;
|
||||||
|
uint32_t addr;
|
||||||
|
avr_bus_active();
|
||||||
|
addr = 0x000000;
|
||||||
|
i = 1;
|
||||||
|
while (addr++ <= 0x0000ff) {
|
||||||
|
sram_write(addr, i++);
|
||||||
|
}
|
||||||
|
addr = 0x000000;
|
||||||
|
while (addr++ <= 0x0000ff) {
|
||||||
|
info_P(PSTR("read addr=0x%08lx %x\n"), addr, sram_read(addr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void test_bulk_read_write()
|
||||||
|
{
|
||||||
|
|
||||||
|
uint8_t i;
|
||||||
|
uint32_t addr;
|
||||||
|
avr_bus_active();
|
||||||
|
addr = 0x000000;
|
||||||
|
i = 0;
|
||||||
|
sram_bulk_write_start(addr);
|
||||||
|
while (addr++ <= 0x8000) {
|
||||||
|
sram_bulk_write(i++);
|
||||||
|
sram_bulk_write_next();
|
||||||
|
}
|
||||||
|
sram_bulk_write_end();
|
||||||
|
|
||||||
|
addr = 0x000000;
|
||||||
|
sram_bulk_read_start(addr);
|
||||||
|
while (addr <= 0x8000) {
|
||||||
|
info_P(PSTR("addr=0x%08lx %x\n"), addr, sram_bulk_read());
|
||||||
|
sram_bulk_read_next();
|
||||||
|
addr++;
|
||||||
|
}
|
||||||
|
sram_bulk_read_end();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_non_zero_memory(uint32_t bottom_addr, uint32_t top_addr)
|
||||||
|
{
|
||||||
|
uint32_t addr = 0;
|
||||||
|
uint8_t c;
|
||||||
|
sram_bulk_read_start(bottom_addr);
|
||||||
|
for (addr = bottom_addr; addr < top_addr; addr++) {
|
||||||
|
c = sram_bulk_read();
|
||||||
|
if (c != 0xff)
|
||||||
|
info_P(PSTR("addr=0x%08lx c=0x%x\n"), addr, c);
|
||||||
|
sram_bulk_read_next();
|
||||||
|
}
|
||||||
|
sram_bulk_read_end();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_memory_pattern(uint32_t bottom_addr, uint32_t top_addr, uint32_t bank_size)
|
||||||
|
{
|
||||||
|
uint32_t addr = 0;
|
||||||
|
uint8_t pattern = 0x55;
|
||||||
|
info_P(PSTR("test_memory_pattern: bottom_addr=0x%08lx top_addr=0x%08lx\n"), bottom_addr, top_addr);
|
||||||
|
sram_bulk_write_start(bottom_addr);
|
||||||
|
for (addr = bottom_addr; addr < top_addr; addr++) {
|
||||||
|
if (addr % bank_size == 0){
|
||||||
|
pattern++;
|
||||||
|
info_P(PSTR("test_memory_pattern: write addr=0x%08lx pattern=0x%08lx\n"), addr, pattern);
|
||||||
|
}
|
||||||
|
sram_bulk_write(pattern);
|
||||||
|
}
|
||||||
|
sram_bulk_write_end();
|
||||||
|
|
||||||
|
|
||||||
|
for (addr = bottom_addr; addr < top_addr; addr+=bank_size) {
|
||||||
|
info_P(PSTR("test_memory_pattern: dump bottom_addr=0x%08lx top_addr=0x%08lx\n"), addr, addr + bank_size);
|
||||||
|
dump_memory(addr, addr + bank_size );
|
||||||
|
info_P(PSTR("----------------------------------------------------------------\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
crc_check_bulk_memory((uint32_t)bottom_addr,top_addr, bank_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_crc()
|
||||||
|
{
|
||||||
|
info_P(PSTR("test_crc: clear\n"));
|
||||||
|
avr_bus_active();
|
||||||
|
sram_bulk_set(0x000000, 0x10000, 0xff);
|
||||||
|
info_P(PSTR("test_crc: crc\n"));
|
||||||
|
crc_check_bulk_memory(0x000000, 0x10000, 0x8000);
|
||||||
|
info_P(PSTR("test_crc: check\n"));
|
||||||
|
test_non_zero_memory(0x000000, 0x10000);
|
||||||
|
}
|
||||||
|
|
||||||
31
avr/usbload/testing.h
Normal file
31
avr/usbload/testing.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __TESTING_H__
|
||||||
|
#define __TESTING_H__
|
||||||
|
|
||||||
|
|
||||||
|
void test_read_write();
|
||||||
|
void test_bulk_read_write();
|
||||||
|
void test_non_zero_memory(uint32_t bottom_addr, uint32_t top_addr);
|
||||||
|
void test_crc();
|
||||||
|
|
||||||
|
#endif
|
||||||
94
avr/usbload/timer.c
Normal file
94
avr/usbload/timer.c
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h> /* for sei() */
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
#include "info.h"
|
||||||
|
#include "sram.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern uint8_t snes_reset_line;
|
||||||
|
|
||||||
|
#ifndef OCR1A
|
||||||
|
#define OCR1A OCR1 // 2313 support
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WGM12
|
||||||
|
#define WGM12 CTC1 // 2313 support
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//#define XTAL 11059201L // nominal value
|
||||||
|
#define XTAL 20000000UL
|
||||||
|
|
||||||
|
#define DEBOUNCE 500L // debounce clock (256Hz = 4msec)
|
||||||
|
|
||||||
|
#define uint8_t unsigned char
|
||||||
|
#define uint unsigned int
|
||||||
|
|
||||||
|
uint16_t prescaler;
|
||||||
|
uint16_t volatile second; // count seconds
|
||||||
|
|
||||||
|
|
||||||
|
ISR (SIG_OUTPUT_COMPARE1A)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
#if XTAL % DEBOUNCE // bei rest
|
||||||
|
OCR1A = 20000000UL / DEBOUNCE - 1; // compare DEBOUNCE - 1 times
|
||||||
|
#endif
|
||||||
|
if( --prescaler == 0 ){
|
||||||
|
prescaler = (uint16_t)DEBOUNCE;
|
||||||
|
second++; // exact one second over
|
||||||
|
#if XTAL % DEBOUNCE // handle remainder
|
||||||
|
OCR1A = XTAL / DEBOUNCE + XTAL % DEBOUNCE - 1; // compare once per second
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void timer_start( void )
|
||||||
|
{
|
||||||
|
TCCR1B = (1<<WGM12) | (1<<CS10); // divide by 1
|
||||||
|
// clear on compare
|
||||||
|
OCR1A = XTAL / DEBOUNCE - 1UL; // Output Compare Register
|
||||||
|
TCNT1 = 0; // Timmer startet mit 0
|
||||||
|
second = 0;
|
||||||
|
prescaler = (uint16_t)DEBOUNCE; //software teiler
|
||||||
|
TIMSK1 = 1<<OCIE1A; // beim Vergleichswertes Compare Match
|
||||||
|
// Interrupt (SIG_OUTPUT_COMPARE1A)
|
||||||
|
sei();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t timer_stop_int(void)
|
||||||
|
{
|
||||||
|
uint16_t t = ((DEBOUNCE - prescaler) / DEBOUNCE ) + second;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
29
avr/usbload/timer.h
Normal file
29
avr/usbload/timer.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __TIMER_H__
|
||||||
|
#define __TIMER_H__
|
||||||
|
|
||||||
|
|
||||||
|
int16_t timer_start( void );
|
||||||
|
double timer_stop( void );
|
||||||
|
int16_t timer_stop_int( void );
|
||||||
|
|
||||||
|
#endif
|
||||||
100
avr/usbload/uart.c
Normal file
100
avr/usbload/uart.c
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "uart.h"
|
||||||
|
#include "fifo.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
volatile struct {
|
||||||
|
uint8_t tmr_int:1;
|
||||||
|
uint8_t adc_int:1;
|
||||||
|
uint8_t rx_int:1;
|
||||||
|
} intflags;
|
||||||
|
|
||||||
|
|
||||||
|
volatile char rxbuff;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int uart_stream(char c, FILE *stream);
|
||||||
|
|
||||||
|
FILE uart_stdout = FDEV_SETUP_STREAM(uart_stream, NULL, _FDEV_SETUP_WRITE);
|
||||||
|
|
||||||
|
void uart_init(void)
|
||||||
|
{
|
||||||
|
UCSR0A = _BV(U2X0); /* improves baud rate error @ F_CPU = 1 MHz */
|
||||||
|
UCSR0B = _BV(TXEN0) | _BV(RXEN0) | _BV(RXCIE0); /* tx/rx enable, rx complete
|
||||||
|
* intr */
|
||||||
|
UBRR0L = (F_CPU / (8 * 115200UL)) - 1;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
ISR(USART0_RX_vect)
|
||||||
|
{
|
||||||
|
uint8_t c;
|
||||||
|
c = UDR0;
|
||||||
|
if (bit_is_clear(UCSR0A, FE0)) {
|
||||||
|
rxbuff = c;
|
||||||
|
intflags.rx_int = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
void uart_putc(uint8_t c)
|
||||||
|
{
|
||||||
|
loop_until_bit_is_set(UCSR0A, UDRE0);
|
||||||
|
UDR0 = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void uart_puts(const char *s)
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
uart_putc(*s);
|
||||||
|
}
|
||||||
|
while (*s++);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uart_puts_P(PGM_P s)
|
||||||
|
{
|
||||||
|
while (1) {
|
||||||
|
unsigned char c = pgm_read_byte(s);
|
||||||
|
s++;
|
||||||
|
if ('\0' == c)
|
||||||
|
break;
|
||||||
|
uart_putc(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int uart_stream(char c, FILE * stream)
|
||||||
|
{
|
||||||
|
if (c == '\n')
|
||||||
|
uart_putc('\r');
|
||||||
|
loop_until_bit_is_set(UCSR0A, UDRE0);
|
||||||
|
UDR0 = c;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
39
avr/usbload/uart.h
Normal file
39
avr/usbload/uart.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __UART_H__
|
||||||
|
#define __UART_H__
|
||||||
|
|
||||||
|
#define CR "\r\n"
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void uart_init(void);
|
||||||
|
void uart_putc(const uint8_t);
|
||||||
|
void uart_puts(const char *s);
|
||||||
|
void uart_puts_P(PGM_P s);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
83
avr/usbload/usb_bulk.c
Normal file
83
avr/usbload/usb_bulk.c
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/pgmspace.h> /* required by usbdrv.h */
|
||||||
|
#include <avr/interrupt.h> /* for sei() */
|
||||||
|
#include <util/delay.h> /* for _delay_ms() */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "usbdrv.h"
|
||||||
|
#include "oddebug.h" /* This is also an example for using debug
|
||||||
|
* macros */
|
||||||
|
#include "config.h"
|
||||||
|
#include "requests.h" /* The custom request numbers we use */
|
||||||
|
#include "uart.h"
|
||||||
|
#include "sram.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "info.h"
|
||||||
|
|
||||||
|
#include "crc.h"
|
||||||
|
#include "usb_bulk.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern usb_transaction_t usb_trans;
|
||||||
|
|
||||||
|
uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
|
||||||
|
{
|
||||||
|
uint8_t *ptr;
|
||||||
|
uint8_t i;
|
||||||
|
|
||||||
|
if (len > usb_trans.rx_remaining) {
|
||||||
|
info_P(PSTR("ERROR:usbFunctionWrite more data than expected remain: %i len: %i\n"),
|
||||||
|
usb_trans.rx_remaining, len);
|
||||||
|
len = usb_trans.rx_remaining;
|
||||||
|
}
|
||||||
|
if (usb_trans.req_state == REQ_STATUS_BULK_UPLOAD) {
|
||||||
|
|
||||||
|
usb_trans.rx_remaining -= len;
|
||||||
|
debug_P(DEBUG_USB_TRANS, PSTR("usbFunctionWrite REQ_STATUS_BULK_UPLOAD addr: 0x%08lx len: %i rx_remaining=%i\n"),
|
||||||
|
usb_trans.req_addr, len, usb_trans.rx_remaining);
|
||||||
|
ptr = data;
|
||||||
|
i = len;
|
||||||
|
while(i--){
|
||||||
|
sram_bulk_write(*ptr++);
|
||||||
|
sram_bulk_write_next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t usbFunctionRead(uint8_t * data, uint8_t len)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
if (len > usb_trans.tx_remaining)
|
||||||
|
len = usb_trans.tx_remaining;
|
||||||
|
usb_trans.tx_remaining -= len;
|
||||||
|
debug_P(DEBUG_USB_TRANS, PSTR("usbFunctionRead len=%i tx_remaining=%i \n"), len, usb_trans.tx_remaining);
|
||||||
|
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
*data = usb_trans.tx_buffer[len];
|
||||||
|
data++;
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
29
avr/usbload/usb_bulk.h
Normal file
29
avr/usbload/usb_bulk.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __USB_BULK_H__
|
||||||
|
#define __USB_BULK_H__
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t usbFunctionWrite(uint8_t * data, uint8_t len);
|
||||||
|
uint8_t usbFunctionRead(uint8_t * data, uint8_t len);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,11 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Name: usbconfig.h
|
/* Name: usbconfig.h
|
||||||
* Project: AVR USB driver
|
* Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
|
||||||
* Author: Christian Starkjohann
|
* Author: Christian Starkjohann
|
||||||
* Creation Date: 2005-04-01
|
* Creation Date: 2005-04-01
|
||||||
* Tabsize: 4
|
* Tabsize: 4
|
||||||
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
|
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
||||||
* This Revision: $Id: usbconfig-prototype.h 734 2009-03-23 11:10:07Z cs $
|
* This Revision: $Id: usbconfig-prototype.h 740 2009-04-13 18:23:31Z cs $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __usbconfig_h_included__
|
#ifndef __usbconfig_h_included__
|
||||||
@@ -14,14 +36,11 @@
|
|||||||
/*
|
/*
|
||||||
General Description:
|
General Description:
|
||||||
This file is an example configuration (with inline documentation) for the USB
|
This file is an example configuration (with inline documentation) for the USB
|
||||||
driver. It configures AVR-USB for USB D+ connected to Port D bit 2 (which is
|
driver. It configures V-USB for USB D+ connected to Port D bit 2 (which is
|
||||||
also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may
|
also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may
|
||||||
wire the lines to any other port, as long as D+ is also wired to INT0 (or any
|
wire the lines to any other port, as long as D+ is also wired to INT0 (or any
|
||||||
other hardware interrupt, as long as it is the highest level interrupt, see
|
other hardware interrupt, as long as it is the highest level interrupt, see
|
||||||
section at the end of this file).
|
section at the end of this file).
|
||||||
+ To create your own usbconfig.h file, copy this file to your project's
|
|
||||||
+ firmware source directory) and rename it to "usbconfig.h".
|
|
||||||
+ Then edit it accordingly.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* ---------------------------- Hardware Config ---------------------------- */
|
/* ---------------------------- Hardware Config ---------------------------- */
|
||||||
@@ -59,13 +78,13 @@ section at the end of this file).
|
|||||||
|
|
||||||
/* ----------------------- Optional Hardware Config ------------------------ */
|
/* ----------------------- Optional Hardware Config ------------------------ */
|
||||||
|
|
||||||
/* #define USB_CFG_PULLUP_IOPORTNAME D */
|
//#define USB_CFG_PULLUP_IOPORTNAME D
|
||||||
/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
|
/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
|
||||||
* V+, you can connect and disconnect the device from firmware by calling
|
* V+, you can connect and disconnect the device from firmware by calling
|
||||||
* the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
|
* the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
|
||||||
* This constant defines the port on which the pullup resistor is connected.
|
* This constant defines the port on which the pullup resistor is connected.
|
||||||
*/
|
*/
|
||||||
/* #define USB_CFG_PULLUP_BIT 4 */
|
//#define USB_CFG_PULLUP_BIT 6
|
||||||
/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
|
/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
|
||||||
* above) where the 1.5k pullup resistor is connected. See description
|
* above) where the 1.5k pullup resistor is connected. See description
|
||||||
* above for details.
|
* above for details.
|
||||||
@@ -100,7 +119,7 @@ section at the end of this file).
|
|||||||
* it is required by the standard. We have made it a config option because it
|
* it is required by the standard. We have made it a config option because it
|
||||||
* bloats the code considerably.
|
* bloats the code considerably.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_SUPPRESS_INTR_CODE 0
|
#define USB_CFG_SUPPRESS_INTR_CODE 1
|
||||||
/* Define this to 1 if you want to declare interrupt-in endpoints, but don't
|
/* Define this to 1 if you want to declare interrupt-in endpoints, but don't
|
||||||
* want to send any data over them. If this macro is defined to 1, functions
|
* want to send any data over them. If this macro is defined to 1, functions
|
||||||
* usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if
|
* usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if
|
||||||
@@ -108,7 +127,7 @@ section at the end of this file).
|
|||||||
* (e.g. HID), but never want to send any data. This option saves a couple
|
* (e.g. HID), but never want to send any data. This option saves a couple
|
||||||
* of bytes in flash memory and the transmit buffers in RAM.
|
* of bytes in flash memory and the transmit buffers in RAM.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_INTR_POLL_INTERVAL 10
|
#define USB_CFG_INTR_POLL_INTERVAL 20
|
||||||
/* If you compile a version with endpoint 1 (interrupt-in), this is the poll
|
/* If you compile a version with endpoint 1 (interrupt-in), this is the poll
|
||||||
* interval. The value is in milliseconds and must not be less than 10 ms for
|
* interval. The value is in milliseconds and must not be less than 10 ms for
|
||||||
* low speed devices.
|
* low speed devices.
|
||||||
@@ -117,12 +136,12 @@ section at the end of this file).
|
|||||||
/* Define this to 1 if the device has its own power supply. Set it to 0 if the
|
/* Define this to 1 if the device has its own power supply. Set it to 0 if the
|
||||||
* device is powered from the USB bus.
|
* device is powered from the USB bus.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_MAX_BUS_POWER 100
|
#define USB_CFG_MAX_BUS_POWER 300
|
||||||
/* Set this variable to the maximum USB bus power consumption of your device.
|
/* Set this variable to the maximum USB bus power consumption of your device.
|
||||||
* The value is in milliamperes. [It will be divided by two since USB
|
* The value is in milliamperes. [It will be divided by two since USB
|
||||||
* communicates power requirements in units of 2 mA.]
|
* communicates power requirements in units of 2 mA.]
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_IMPLEMENT_FN_WRITE 0
|
#define USB_CFG_IMPLEMENT_FN_WRITE 1
|
||||||
/* Set this to 1 if you want usbFunctionWrite() to be called for control-out
|
/* Set this to 1 if you want usbFunctionWrite() to be called for control-out
|
||||||
* transfers. Set it to 0 if you don't need it and want to save a couple of
|
* transfers. Set it to 0 if you don't need it and want to save a couple of
|
||||||
* bytes.
|
* bytes.
|
||||||
@@ -208,23 +227,19 @@ section at the end of this file).
|
|||||||
/* USB vendor ID for the device, low byte first. If you have registered your
|
/* USB vendor ID for the device, low byte first. If you have registered your
|
||||||
* own Vendor ID, define it here. Otherwise you use one of obdev's free shared
|
* own Vendor ID, define it here. Otherwise you use one of obdev's free shared
|
||||||
* VID/PID pairs. Be sure to read USBID-License.txt for rules!
|
* VID/PID pairs. Be sure to read USBID-License.txt for rules!
|
||||||
* + This template uses obdev's shared VID/PID pair: 0x16c0/0x5dc.
|
|
||||||
* + Use this VID/PID pair ONLY if you understand the implications!
|
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_DEVICE_ID 0xdc, 0x05
|
#define USB_CFG_DEVICE_ID 0xdd, 0x05
|
||||||
/* This is the ID of the product, low byte first. It is interpreted in the
|
/* This is the ID of the product, low byte first. It is interpreted in the
|
||||||
* scope of the vendor ID. If you have registered your own VID with usb.org
|
* scope of the vendor ID. If you have registered your own VID with usb.org
|
||||||
* or if you have licensed a PID from somebody else, define it here. Otherwise
|
* or if you have licensed a PID from somebody else, define it here. Otherwise
|
||||||
* you use obdev's free shared VID/PID pair. Be sure to read the rules in
|
* you use obdev's free shared VID/PID pair. Be sure to read the rules in
|
||||||
* USBID-License.txt!
|
* USBID-License.txt!
|
||||||
* + This template uses obdev's shared VID/PID pair: 0x16c0/0x5dc.
|
|
||||||
* + Use this VID/PID pair ONLY if you understand the implications!
|
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_DEVICE_VERSION 0x00, 0x01
|
#define USB_CFG_DEVICE_VERSION 0x00, 0x01
|
||||||
/* Version number of the device: Minor number first, then major number.
|
/* Version number of the device: Minor number first, then major number.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_VENDOR_NAME 'o', 'b', 'd', 'e', 'v', '.', 'a', 't'
|
#define USB_CFG_VENDOR_NAME 'o', 'p', 't', 'i', 'x', 'x', '.', 'o', 'r', 'g'
|
||||||
#define USB_CFG_VENDOR_NAME_LEN 8
|
#define USB_CFG_VENDOR_NAME_LEN 10
|
||||||
/* These two values define the vendor name returned by the USB device. The name
|
/* These two values define the vendor name returned by the USB device. The name
|
||||||
* must be given as a list of characters under single quotes. The characters
|
* must be given as a list of characters under single quotes. The characters
|
||||||
* are interpreted as Unicode (UTF-16) entities.
|
* are interpreted as Unicode (UTF-16) entities.
|
||||||
@@ -233,8 +248,8 @@ section at the end of this file).
|
|||||||
* obdev's free shared VID/PID pair. See the file USBID-License.txt for
|
* obdev's free shared VID/PID pair. See the file USBID-License.txt for
|
||||||
* details.
|
* details.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_DEVICE_NAME 'T', 'e', 'm', 'p', 'l', 'a', 't', 'e'
|
#define USB_CFG_DEVICE_NAME 'Q', 'U', 'I', 'C', 'K', 'D', 'E', 'V', '1', '6'
|
||||||
#define USB_CFG_DEVICE_NAME_LEN 8
|
#define USB_CFG_DEVICE_NAME_LEN 10
|
||||||
/* Same as above for the device name. If you don't want a device name, undefine
|
/* Same as above for the device name. If you don't want a device name, undefine
|
||||||
* the macros. See the file USBID-License.txt before you assign a name if you
|
* the macros. See the file USBID-License.txt before you assign a name if you
|
||||||
* use a shared VID/PID.
|
* use a shared VID/PID.
|
||||||
@@ -261,7 +276,8 @@ section at the end of this file).
|
|||||||
* HID class is 3, no subclass and protocol required (but may be useful!)
|
* HID class is 3, no subclass and protocol required (but may be useful!)
|
||||||
* CDC class is 2, use subclass 2 and protocol 1 for ACM
|
* CDC class is 2, use subclass 2 and protocol 1 for ACM
|
||||||
*/
|
*/
|
||||||
/* #define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 42 */
|
#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 0
|
||||||
|
|
||||||
/* Define this to the length of the HID report descriptor, if you implement
|
/* Define this to the length of the HID report descriptor, if you implement
|
||||||
* an HID device. Otherwise don't define it or define it to 0.
|
* an HID device. Otherwise don't define it or define it to 0.
|
||||||
* If you use this define, you must add a PROGMEM character array named
|
* If you use this define, you must add a PROGMEM character array named
|
||||||
@@ -268,3 +268,10 @@ Scroll down to the bottom to see the most recent changes.
|
|||||||
- Integrated a module with CRC checks at 18 MHz by Lukas Schrittwieser.
|
- Integrated a module with CRC checks at 18 MHz by Lukas Schrittwieser.
|
||||||
|
|
||||||
* Release 2009-03-23
|
* Release 2009-03-23
|
||||||
|
|
||||||
|
- Hid-mouse example used settings from hid-data example, fixed that.
|
||||||
|
- Renamed project to V-USB due to a trademark issue with Atmel(r).
|
||||||
|
- Changed CommercialLicense.txt and USBID-License.txt to make the
|
||||||
|
background of USB ID registration clearer.
|
||||||
|
|
||||||
|
* Release 2009-04-15
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
AVR-USB Driver Software License Agreement
|
V-USB Driver Software License Agreement
|
||||||
Version 2008-10-07
|
Version 2009-04-14
|
||||||
|
|
||||||
THIS LICENSE AGREEMENT GRANTS YOU CERTAIN RIGHTS IN A SOFTWARE. YOU CAN
|
THIS LICENSE AGREEMENT GRANTS YOU CERTAIN RIGHTS IN A SOFTWARE. YOU CAN
|
||||||
ENTER INTO THIS AGREEMENT AND ACQUIRE THE RIGHTS OUTLINED BELOW BY PAYING
|
ENTER INTO THIS AGREEMENT AND ACQUIRE THE RIGHTS OUTLINED BELOW BY PAYING
|
||||||
@@ -13,8 +13,8 @@ Grosse Schiffgasse 1A/7, 1020 Wien, AUSTRIA.
|
|||||||
|
|
||||||
1.2 "You" shall mean the Licensee.
|
1.2 "You" shall mean the Licensee.
|
||||||
|
|
||||||
1.3 "AVR-USB" shall mean all files included in the package distributed under
|
1.3 "V-USB" shall mean all files included in the package distributed under
|
||||||
the name "avrusb" by OBJECTIVE DEVELOPMENT (http://www.obdev.at/avrusb/)
|
the name "vusb" by OBJECTIVE DEVELOPMENT (http://www.obdev.at/vusb/)
|
||||||
unless otherwise noted. This includes the firmware-only USB device
|
unless otherwise noted. This includes the firmware-only USB device
|
||||||
implementation for Atmel AVR microcontrollers, some simple device examples
|
implementation for Atmel AVR microcontrollers, some simple device examples
|
||||||
and host side software examples and libraries.
|
and host side software examples and libraries.
|
||||||
@@ -23,21 +23,22 @@ and host side software examples and libraries.
|
|||||||
2 LICENSE GRANTS
|
2 LICENSE GRANTS
|
||||||
|
|
||||||
2.1 Source Code. OBJECTIVE DEVELOPMENT shall furnish you with the source
|
2.1 Source Code. OBJECTIVE DEVELOPMENT shall furnish you with the source
|
||||||
code of AVR-USB.
|
code of V-USB.
|
||||||
|
|
||||||
2.2 Distribution and Use. OBJECTIVE DEVELOPMENT grants you the
|
2.2 Distribution and Use. OBJECTIVE DEVELOPMENT grants you the
|
||||||
non-exclusive right to use, copy and distribute AVR-USB with your hardware
|
non-exclusive right to use, copy and distribute V-USB with your hardware
|
||||||
product(s), restricted by the limitations in section 3 below.
|
product(s), restricted by the limitations in section 3 below.
|
||||||
|
|
||||||
2.3 Modifications. OBJECTIVE DEVELOPMENT grants you the right to modify
|
2.3 Modifications. OBJECTIVE DEVELOPMENT grants you the right to modify
|
||||||
the source code and your copy of AVR-USB according to your needs.
|
the source code and your copy of V-USB according to your needs.
|
||||||
|
|
||||||
2.4 USB IDs. OBJECTIVE DEVELOPMENT grants you the exclusive rights to use
|
2.4 USB IDs. OBJECTIVE DEVELOPMENT furnishes you with one or two USB Product
|
||||||
USB Product ID(s) sent to you in e-mail after receiving your payment in
|
ID(s), sent to you in e-mail. These Product IDs are reserved exclusively for
|
||||||
conjunction with USB Vendor ID 5824. OBJECTIVE DEVELOPMENT has acquired an
|
you. They have been obtained from Wouter van Ooijen (www.voti.nl), who has
|
||||||
exclusive license for this pair of USB identifiers from Wouter van Ooijen
|
reserved the Vendor ID 5824 (decimal) at the USB Implementers Forum, Inc.
|
||||||
(www.voti.nl), who has licensed the VID from the USB Implementers Forum,
|
(www.usb.org). This mechanism ensures that there are no Product ID conflicts,
|
||||||
Inc. (www.usb.org).
|
but you cannot become USB certified (enter into the USB-IF Trademark License
|
||||||
|
Agreement) as you would need your own Vendor ID for that.
|
||||||
|
|
||||||
|
|
||||||
3 LICENSE RESTRICTIONS
|
3 LICENSE RESTRICTIONS
|
||||||
@@ -46,21 +47,21 @@ Inc. (www.usb.org).
|
|||||||
applicable. Which one is determined by the amount you pay to OBJECTIVE
|
applicable. Which one is determined by the amount you pay to OBJECTIVE
|
||||||
DEVELOPMENT, see section 4 ("Payment") below.
|
DEVELOPMENT, see section 4 ("Payment") below.
|
||||||
|
|
||||||
Hobby License: You may use AVR-USB according to section 2 above in no more
|
Hobby License: You may use V-USB according to section 2 above in no more
|
||||||
than 5 hardware units. These units must not be sold for profit.
|
than 5 hardware units. These units must not be sold for profit.
|
||||||
|
|
||||||
Entry Level License: You may use AVR-USB according to section 2 above in no
|
Entry Level License: You may use V-USB according to section 2 above in no
|
||||||
more than 150 hardware units.
|
more than 150 hardware units.
|
||||||
|
|
||||||
Professional License: You may use AVR-USB according to section 2 above in
|
Professional License: You may use V-USB according to section 2 above in
|
||||||
any number of hardware units, except for large scale production ("unlimited
|
any number of hardware units, except for large scale production ("unlimited
|
||||||
fair use"). Quantities below 10,000 units are not considered large scale
|
fair use"). Quantities below 10,000 units are not considered large scale
|
||||||
production. If your reach quantities which are obviously large scale
|
production. If your reach quantities which are obviously large scale
|
||||||
production, you must pay a license fee of 0.10 EUR per unit for all units
|
production, you must pay a license fee of 0.10 EUR per unit for all units
|
||||||
above 10,000.
|
above 10,000.
|
||||||
|
|
||||||
3.2 Rental. You may not rent, lease, or lend AVR-USB or otherwise encumber
|
3.2 Rental. You may not rent, lease, or lend V-USB or otherwise encumber
|
||||||
any copy of AVR-USB, or any of the rights granted herein.
|
any copy of V-USB, or any of the rights granted herein.
|
||||||
|
|
||||||
3.3 Transfer. You may not transfer your rights under this Agreement to
|
3.3 Transfer. You may not transfer your rights under this Agreement to
|
||||||
another party without OBJECTIVE DEVELOPMENT's prior written consent. If
|
another party without OBJECTIVE DEVELOPMENT's prior written consent. If
|
||||||
@@ -78,7 +79,7 @@ non-exclusive.
|
|||||||
by third parties. In particular, you are not allowed to use the USB logo or
|
by third parties. In particular, you are not allowed to use the USB logo or
|
||||||
other trademarks owned by the USB Implementers Forum, Inc. without their
|
other trademarks owned by the USB Implementers Forum, Inc. without their
|
||||||
consent. Since such consent depends on USB certification, it should be
|
consent. Since such consent depends on USB certification, it should be
|
||||||
noted that AVR-USB will not pass certification because it does not
|
noted that V-USB will not pass certification because it does not
|
||||||
implement checksum verification and the microcontroller ports do not meet
|
implement checksum verification and the microcontroller ports do not meet
|
||||||
the electrical specifications.
|
the electrical specifications.
|
||||||
|
|
||||||
@@ -88,15 +89,15 @@ the electrical specifications.
|
|||||||
The payment amount depends on the variation of this agreement (according to
|
The payment amount depends on the variation of this agreement (according to
|
||||||
section 3.1) into which you want to enter. Concrete prices are listed on
|
section 3.1) into which you want to enter. Concrete prices are listed on
|
||||||
OBJECTIVE DEVELOPMENT's web site, usually at
|
OBJECTIVE DEVELOPMENT's web site, usually at
|
||||||
http://www.obdev.at/avrusb/license.html. You agree to pay the amount listed
|
http://www.obdev.at/vusb/license.html. You agree to pay the amount listed
|
||||||
there to OBJECTIVE DEVELOPMENT or OBJECTIVE DEVELOPMENT's payment processor
|
there to OBJECTIVE DEVELOPMENT or OBJECTIVE DEVELOPMENT's payment processor
|
||||||
or reseller.
|
or reseller.
|
||||||
|
|
||||||
|
|
||||||
5 COPYRIGHT AND OWNERSHIP
|
5 COPYRIGHT AND OWNERSHIP
|
||||||
|
|
||||||
AVR-USB is protected by copyright laws and international copyright
|
V-USB is protected by copyright laws and international copyright
|
||||||
treaties, as well as other intellectual property laws and treaties. AVR-USB
|
treaties, as well as other intellectual property laws and treaties. V-USB
|
||||||
is licensed, not sold.
|
is licensed, not sold.
|
||||||
|
|
||||||
|
|
||||||
@@ -112,12 +113,12 @@ and limitation of liability shall survive termination of this agreement.
|
|||||||
|
|
||||||
7 DISCLAIMER OF WARRANTY AND LIABILITY
|
7 DISCLAIMER OF WARRANTY AND LIABILITY
|
||||||
|
|
||||||
LIMITED WARRANTY. AVR-USB IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
LIMITED WARRANTY. V-USB IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
||||||
KIND. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, OBJECTIVE
|
KIND. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, OBJECTIVE
|
||||||
DEVELOPMENT AND ITS SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES, EITHER
|
DEVELOPMENT AND ITS SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES, EITHER
|
||||||
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND
|
||||||
NON-INFRINGEMENT, WITH REGARD TO AVR-USB, AND THE PROVISION OF OR FAILURE
|
NON-INFRINGEMENT, WITH REGARD TO V-USB, AND THE PROVISION OF OR FAILURE
|
||||||
TO PROVIDE SUPPORT SERVICES. THIS LIMITED WARRANTY GIVES YOU SPECIFIC LEGAL
|
TO PROVIDE SUPPORT SERVICES. THIS LIMITED WARRANTY GIVES YOU SPECIFIC LEGAL
|
||||||
RIGHTS. YOU MAY HAVE OTHERS, WHICH VARY FROM STATE/JURISDICTION TO
|
RIGHTS. YOU MAY HAVE OTHERS, WHICH VARY FROM STATE/JURISDICTION TO
|
||||||
STATE/JURISDICTION.
|
STATE/JURISDICTION.
|
||||||
@@ -127,11 +128,11 @@ IN NO EVENT SHALL OBJECTIVE DEVELOPMENT OR ITS SUPPLIERS BE LIABLE FOR ANY
|
|||||||
SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER
|
SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER
|
||||||
(INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
|
(INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
|
||||||
BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY
|
BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY
|
||||||
LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE AVR-USB OR THE
|
LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE V-USB OR THE
|
||||||
PROVISION OF OR FAILURE TO PROVIDE SUPPORT SERVICES, EVEN IF OBJECTIVE
|
PROVISION OF OR FAILURE TO PROVIDE SUPPORT SERVICES, EVEN IF OBJECTIVE
|
||||||
DEVELOPMENT HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN ANY
|
DEVELOPMENT HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN ANY
|
||||||
CASE, OBJECTIVE DEVELOPMENT'S ENTIRE LIABILITY UNDER ANY PROVISION OF THIS
|
CASE, OBJECTIVE DEVELOPMENT'S ENTIRE LIABILITY UNDER ANY PROVISION OF THIS
|
||||||
AGREEMENT SHALL BE LIMITED TO THE AMOUNT ACTUALLY PAID BY YOU FOR AVR-USB.
|
AGREEMENT SHALL BE LIMITED TO THE AMOUNT ACTUALLY PAID BY YOU FOR V-USB.
|
||||||
|
|
||||||
|
|
||||||
8 MISCELLANEOUS TERMS
|
8 MISCELLANEOUS TERMS
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
OBJECTIVE DEVELOPMENT GmbH's AVR-USB driver software is distributed under the
|
OBJECTIVE DEVELOPMENT GmbH's V-USB driver software is distributed under the
|
||||||
terms and conditions of the GNU GPL version 2 or the GNU GPL version 3. It is
|
terms and conditions of the GNU GPL version 2 or the GNU GPL version 3. It is
|
||||||
your choice whether you apply the terms of version 2 or version 3. The full
|
your choice whether you apply the terms of version 2 or version 3. The full
|
||||||
text of GPLv2 is included below. In addition to the requirements in the GPL,
|
text of GPLv2 is included below. In addition to the requirements in the GPL,
|
||||||
we STRONGLY ENCOURAGE you to do the following:
|
we STRONGLY ENCOURAGE you to do the following:
|
||||||
|
|
||||||
(1) Publish your entire project on a web site and drop us a note with the URL.
|
(1) Publish your entire project on a web site and drop us a note with the URL.
|
||||||
Use the form at http://www.obdev.at/avrusb/feedback.html for your submission.
|
Use the form at http://www.obdev.at/vusb/feedback.html for your submission.
|
||||||
|
|
||||||
(2) Adhere to minimum publication standards. Please include AT LEAST:
|
(2) Adhere to minimum publication standards. Please include AT LEAST:
|
||||||
- a circuit diagram in PDF, PNG or GIF format
|
- a circuit diagram in PDF, PNG or GIF format
|
||||||
- full source code for the host software
|
- full source code for the host software
|
||||||
- a Readme.txt file in ASCII format which describes the purpose of the
|
- a Readme.txt file in ASCII format which describes the purpose of the
|
||||||
project and what can be found in which directories and which files
|
project and what can be found in which directories and which files
|
||||||
- a reference to http://www.obdev.at/avrusb/
|
- a reference to http://www.obdev.at/vusb/
|
||||||
|
|
||||||
(3) If you improve the driver firmware itself, please give us a free license
|
(3) If you improve the driver firmware itself, please give us a free license
|
||||||
to your modifications for our commercial license offerings.
|
to your modifications for our commercial license offerings.
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
This is the Readme file to Objective Development's firmware-only USB driver
|
This is the Readme file to Objective Development's firmware-only USB driver
|
||||||
for Atmel AVR microcontrollers. For more information please visit
|
for Atmel AVR microcontrollers. For more information please visit
|
||||||
http://www.obdev.at/avrusb/
|
http://www.obdev.at/vusb/
|
||||||
|
|
||||||
This directory contains the USB firmware only. Copy it as-is to your own
|
This directory contains the USB firmware only. Copy it as-is to your own
|
||||||
project and add all .c and .S files to your project (these files are marked
|
project and add all .c and .S files to your project (these files are marked
|
||||||
@@ -53,7 +53,7 @@ actual clock rate must be configured in usbdrv.h unless you use the default
|
|||||||
12 MHz.
|
12 MHz.
|
||||||
|
|
||||||
12 MHz Clock
|
12 MHz Clock
|
||||||
This is the traditional clock rate of AVR-USB because it's the lowest clock
|
This is the traditional clock rate of V-USB because it's the lowest clock
|
||||||
rate where the timing constraints of the USB spec can be met.
|
rate where the timing constraints of the USB spec can be met.
|
||||||
|
|
||||||
15 MHz Clock
|
15 MHz Clock
|
||||||
@@ -78,7 +78,7 @@ oscillator can reach 16.5 MHz with the RC oscillator. This includes the very
|
|||||||
popular ATTiny25, ATTiny45, ATTiny85 series as well as the ATTiny26. Almost
|
popular ATTiny25, ATTiny45, ATTiny85 series as well as the ATTiny26. Almost
|
||||||
all AVRs can reach 12.8 MHz, although this is outside the specified range.
|
all AVRs can reach 12.8 MHz, although this is outside the specified range.
|
||||||
|
|
||||||
See the EasyLogger example at http://www.obdev.at/avrusb/easylogger.html for
|
See the EasyLogger example at http://www.obdev.at/vusb/easylogger.html for
|
||||||
code which calibrates the RC oscillator based on the USB frame clock.
|
code which calibrates the RC oscillator based on the USB frame clock.
|
||||||
|
|
||||||
18 MHz Clock
|
18 MHz Clock
|
||||||
@@ -108,14 +108,14 @@ and hobbyists, we provide some VID/PID pairs for free. See the file
|
|||||||
USBID-License.txt for details.
|
USBID-License.txt for details.
|
||||||
|
|
||||||
Objective Development also has some license offerings which include product
|
Objective Development also has some license offerings which include product
|
||||||
IDs. See http://www.obdev.at/avrusb/ for details.
|
IDs. See http://www.obdev.at/vusb/ for details.
|
||||||
|
|
||||||
|
|
||||||
DEVELOPMENT SYSTEM
|
DEVELOPMENT SYSTEM
|
||||||
==================
|
==================
|
||||||
This driver has been developed and optimized for the GNU compiler version 3
|
This driver has been developed and optimized for the GNU compiler version 3
|
||||||
(gcc 3). It does work well with gcc 4, but with bigger code size. We recommend
|
(gcc 3). It does work well with gcc 4, but with bigger code size. We recommend
|
||||||
that you use the GNU compiler suite because it is freely available. AVR-USB
|
that you use the GNU compiler suite because it is freely available. V-USB
|
||||||
has also been ported to the IAR compiler and assembler. It has been tested
|
has also been ported to the IAR compiler and assembler. It has been tested
|
||||||
with IAR 4.10B/W32 and 4.12A/W32 on an ATmega8 with the "small" and "tiny"
|
with IAR 4.10B/W32 and 4.12A/W32 on an ATmega8 with the "small" and "tiny"
|
||||||
memory model. Not every release is tested with IAR CC and the driver may
|
memory model. Not every release is tested with IAR CC and the driver may
|
||||||
@@ -123,8 +123,8 @@ therefore fail to compile with IAR. Please note that gcc is more efficient for
|
|||||||
usbdrv.c because this module has been deliberately optimized for gcc.
|
usbdrv.c because this module has been deliberately optimized for gcc.
|
||||||
|
|
||||||
|
|
||||||
USING AVR-USB FOR FREE
|
USING V-USB FOR FREE
|
||||||
======================
|
====================
|
||||||
The AVR firmware driver is published under the GNU General Public License
|
The AVR firmware driver is published under the GNU General Public License
|
||||||
Version 2 (GPL2) and the GNU General Public License Version 3 (GPL3). It is
|
Version 2 (GPL2) and the GNU General Public License Version 3 (GPL3). It is
|
||||||
your choice whether you apply the terms of version 2 or version 3.
|
your choice whether you apply the terms of version 2 or version 3.
|
||||||
@@ -133,26 +133,26 @@ If you decide for the free GPL2 or GPL3, we STRONGLY ENCOURAGE you to do the
|
|||||||
following things IN ADDITION to the obligations from the GPL:
|
following things IN ADDITION to the obligations from the GPL:
|
||||||
|
|
||||||
(1) Publish your entire project on a web site and drop us a note with the URL.
|
(1) Publish your entire project on a web site and drop us a note with the URL.
|
||||||
Use the form at http://www.obdev.at/avrusb/feedback.html for your submission.
|
Use the form at http://www.obdev.at/vusb/feedback.html for your submission.
|
||||||
If you don't have a web site, you can publish the project in obdev's
|
If you don't have a web site, you can publish the project in obdev's
|
||||||
documentation wiki at
|
documentation wiki at
|
||||||
http://www.obdev.at/goto.php?t=avrusb-wiki&p=hosted-projects.
|
http://www.obdev.at/goto.php?t=vusb-wiki&p=hosted-projects.
|
||||||
|
|
||||||
(2) Adhere to minimum publication standards. Please include AT LEAST:
|
(2) Adhere to minimum publication standards. Please include AT LEAST:
|
||||||
- a circuit diagram in PDF, PNG or GIF format
|
- a circuit diagram in PDF, PNG or GIF format
|
||||||
- full source code for the host software
|
- full source code for the host software
|
||||||
- a Readme.txt file in ASCII format which describes the purpose of the
|
- a Readme.txt file in ASCII format which describes the purpose of the
|
||||||
project and what can be found in which directories and which files
|
project and what can be found in which directories and which files
|
||||||
- a reference to http://www.obdev.at/avrusb/
|
- a reference to http://www.obdev.at/vusb/
|
||||||
|
|
||||||
(3) If you improve the driver firmware itself, please give us a free license
|
(3) If you improve the driver firmware itself, please give us a free license
|
||||||
to your modifications for our commercial license offerings.
|
to your modifications for our commercial license offerings.
|
||||||
|
|
||||||
|
|
||||||
COMMERCIAL LICENSES FOR AVR-USB
|
COMMERCIAL LICENSES FOR V-USB
|
||||||
===============================
|
=============================
|
||||||
If you don't want to publish your source code under the terms of the GPL,
|
If you don't want to publish your source code under the terms of the GPL,
|
||||||
you can simply pay money for AVR-USB. As an additional benefit you get
|
you can simply pay money for V-USB. As an additional benefit you get
|
||||||
USB PIDs for free, licensed exclusively to you. See the file
|
USB PIDs for free, reserved exclusively to you. See the file
|
||||||
"CommercialLicense.txt" for details.
|
"CommercialLicense.txt" for details.
|
||||||
|
|
||||||
@@ -1,10 +1,17 @@
|
|||||||
Royalty-Free Non-Exclusive License USB Product-ID
|
Royalty-Free Non-Exclusive Use of USB Product-IDs
|
||||||
=================================================
|
=================================================
|
||||||
|
|
||||||
Version 2008-04-07
|
Version 2009-04-13
|
||||||
|
|
||||||
|
Strictly speaking, this is not a license. You can't give a license to use
|
||||||
|
a simple number (such as e.g. 1500) for any purpose. This is a set of rules
|
||||||
|
which should make it possible to build USB devices without the requirement
|
||||||
|
for individual USB IDs. If you break one of the rules, you will run into
|
||||||
|
technical problems sooner or later, but you don't risk legal trouble.
|
||||||
|
|
||||||
|
|
||||||
OBJECTIVE DEVELOPMENT Software GmbH hereby grants you the non-exclusive
|
OBJECTIVE DEVELOPMENT Software GmbH hereby grants you the non-exclusive
|
||||||
right to use three USB.org vendor-ID (VID) / product-ID (PID) pairs with
|
right to use four USB.org vendor-ID (VID) / product-ID (PID) pairs with
|
||||||
products based on Objective Development's firmware-only USB driver for
|
products based on Objective Development's firmware-only USB driver for
|
||||||
Atmel AVR microcontrollers:
|
Atmel AVR microcontrollers:
|
||||||
|
|
||||||
@@ -27,10 +34,11 @@ used by many companies and individuals for different products. To avoid
|
|||||||
conflicts, your device and host driver software MUST adhere to the rules
|
conflicts, your device and host driver software MUST adhere to the rules
|
||||||
outlined below.
|
outlined below.
|
||||||
|
|
||||||
OBJECTIVE DEVELOPMENT Software GmbH has licensed these VID/PID pairs from
|
OBJECTIVE DEVELOPMENT Software GmbH has obtained these VID/PID pairs from
|
||||||
Wouter van Ooijen (see www.voti.nl), who has licensed the VID from the USB
|
Wouter van Ooijen (see www.voti.nl) for exclusive disposition. Wouter van
|
||||||
Implementers Forum, Inc. (see www.usb.org). The VID is registered for the
|
Ooijen has obtained the VID from the USB Implementers Forum, Inc.
|
||||||
company name "Van Ooijen Technische Informatica".
|
(see www.usb.org). The VID is registered for the company name
|
||||||
|
"Van Ooijen Technische Informatica".
|
||||||
|
|
||||||
|
|
||||||
RULES AND RESTRICTIONS
|
RULES AND RESTRICTIONS
|
||||||
@@ -44,7 +52,7 @@ MUST be available at least in USB language 0x0409 (English/US).
|
|||||||
domain name (e.g. "mycompany.com") registered and owned by you, or an
|
domain name (e.g. "mycompany.com") registered and owned by you, or an
|
||||||
e-mail address under your control (e.g. "myname@gmx.net"). You can embed
|
e-mail address under your control (e.g. "myname@gmx.net"). You can embed
|
||||||
the domain name or e-mail address in any string you like, e.g. "Objective
|
the domain name or e-mail address in any string you like, e.g. "Objective
|
||||||
Development http://www.obdev.at/avrusb/".
|
Development http://www.obdev.at/vusb/".
|
||||||
|
|
||||||
(3) You are responsible for retaining ownership of the domain or e-mail
|
(3) You are responsible for retaining ownership of the domain or e-mail
|
||||||
address for as long as any of your products are in use.
|
address for as long as any of your products are in use.
|
||||||
@@ -142,5 +150,5 @@ violates the USB specification. If you do it, you do it at your own risk.
|
|||||||
|
|
||||||
To avoid possible incompatibilities, we highly recommend that you get your
|
To avoid possible incompatibilities, we highly recommend that you get your
|
||||||
own VID/PID pair if you intend to sell your product. Objective
|
own VID/PID pair if you intend to sell your product. Objective
|
||||||
Development's commercial licenses for AVR-USB include a PID for
|
Development's commercial licenses for V-USB include a PID for
|
||||||
unrestricted exclusive use.
|
unrestricted exclusive use.
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user