Compare commits
148 Commits
quickdev16
...
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 |
@@ -1,4 +0,0 @@
|
|||||||
--- !ditz.rubyforge.org,2008-03-06/config
|
|
||||||
name: David
|
|
||||||
email: david@optixx.org
|
|
||||||
issue_dir: bugs
|
|
||||||
9
.gitignore
vendored
9
.gitignore
vendored
@@ -27,3 +27,12 @@
|
|||||||
*.vfat
|
*.vfat
|
||||||
*.wla*
|
*.wla*
|
||||||
*.rcc
|
*.rcc
|
||||||
|
*.log
|
||||||
|
bootloader
|
||||||
|
snesuploader
|
||||||
|
tmtags
|
||||||
|
bsnes
|
||||||
|
web
|
||||||
|
ucon64.exe
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ clean:
|
|||||||
|
|
||||||
.PHONY: all clean interactive-isp interactive-serial launch-bootloader
|
.PHONY: all clean interactive-isp interactive-serial launch-bootloader
|
||||||
|
|
||||||
flash:
|
flash: bootloader.hex
|
||||||
$(AVRDUDE) $(AVRDUDE_FLAGS) -c $(ISP_PROG) -U flash:w:$<
|
$(AVRDUDE) $(AVRDUDE_FLAGS) -c $(ISP_PROG) -U flash:w:$<
|
||||||
|
|
||||||
flash-eeprom-%: %.eep.hex
|
flash-eeprom-%: %.eep.hex
|
||||||
|
|||||||
@@ -33,6 +33,10 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "usbdrv/usbdrv.c"
|
#include "usbdrv/usbdrv.c"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* USBasp requests, taken from the original USBasp sourcecode
|
* USBasp requests, taken from the original USBasp sourcecode
|
||||||
*/
|
*/
|
||||||
@@ -74,8 +78,12 @@
|
|||||||
(LED_DIR ^= (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
|
* some predefined signatures, taken from the original USBasp sourcecode
|
||||||
*/
|
*/
|
||||||
@@ -286,7 +294,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
boot_page_erase(flash_address.word);
|
boot_page_erase(flash_address.word);
|
||||||
sei();
|
sei();
|
||||||
}
|
}
|
||||||
uart_puts("\n\r");
|
uart_puts("\n\rWrite Flash");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -406,9 +414,10 @@ void leave_bootloader(void)
|
|||||||
* disconnect usb
|
* disconnect usb
|
||||||
*/
|
*/
|
||||||
usbDeviceDisconnect();
|
usbDeviceDisconnect();
|
||||||
|
#if 0
|
||||||
for (uint8_t i = 0; i < 50; i++)
|
for (uint8_t i = 0; i < 50; i++)
|
||||||
_delay_ms(10); /* 0 means 0x10000, 38*1/f*0x10000 =~ 498ms */
|
_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
|
* enable watchdog to soft-reset the uC for clean startup of new application
|
||||||
*/
|
*/
|
||||||
@@ -421,6 +430,13 @@ void leave_bootloader(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
int __attribute__ ((noreturn, OS_main)) main(void)
|
||||||
{
|
{
|
||||||
@@ -441,32 +457,40 @@ int __attribute__ ((noreturn, OS_main)) main(void)
|
|||||||
uint16_t delay = 0;
|
uint16_t delay = 0;
|
||||||
timeout = TIMEOUT;
|
timeout = TIMEOUT;
|
||||||
|
|
||||||
uart_puts("Snesram Bootloader v0.1\n\r");
|
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 power-on reset, quit bootloader via watchdog reset
|
||||||
*/
|
*/
|
||||||
if (reset & _BV(PORF)) {
|
if (reset & _BV(PORF)) {
|
||||||
|
banner();
|
||||||
uart_puts("Found power on reset\n\r");
|
uart_puts("Found power on reset\n\r");
|
||||||
MCUSR = 0;
|
MCUSR = 0;
|
||||||
leave_bootloader();
|
leave_bootloader();
|
||||||
}
|
}
|
||||||
/*
|
banner();
|
||||||
* if watchdog reset, disable watchdog and jump to app
|
|
||||||
*/
|
|
||||||
else if (reset & _BV(WDRF)) {
|
|
||||||
uart_puts("Found watchdog reset\n\r");
|
|
||||||
MCUSR = 0;
|
|
||||||
wdt_disable();
|
|
||||||
DLED_TGL;
|
|
||||||
_delay_ms(500);
|
|
||||||
DLED_TGL;
|
|
||||||
_delay_ms(500);
|
|
||||||
uart_puts("Jump to main\n\r");
|
|
||||||
jump_to_app();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uart_puts("Enter programming mode\n\r");
|
uart_puts("Enter programming mode\n\r");
|
||||||
/*
|
/*
|
||||||
* else: enter programming mode
|
* else: enter programming mode
|
||||||
|
|||||||
@@ -19,27 +19,31 @@
|
|||||||
DEBUG = 1
|
DEBUG = 1
|
||||||
TTY = /dev/tty.PL2303-00002126
|
TTY = /dev/tty.PL2303-00002126
|
||||||
DEVICE = atmega644
|
DEVICE = atmega644
|
||||||
F_CPU = 20000000 # in Hz
|
F_CPU = 20000000
|
||||||
TARGET = main
|
TARGET = main
|
||||||
AVRDUDE = avrdude -c usbasp -p $(DEVICE)
|
AVRDUDE = avrdude -c usbasp -p $(DEVICE)
|
||||||
SIZE = avr-size
|
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)
|
ifeq ($(DEBUG),1)
|
||||||
LDFLAGS = -Wl,-u,vfprintf -lprintf_flt
|
LDFLAGS =-Wl,-u,vfprintf
|
||||||
CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0
|
CFLAGS =-Iusbdrv -I. -DDEBUG_LEVEL=0
|
||||||
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o \
|
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 \
|
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 \
|
dump.o timer.o watchdog.o rle.c loader.o info.o shared_memory.o \
|
||||||
command.o testing.o
|
system.o pwm.o util.o shell.o irq.o command.o testing.o inflate.o neginf/neginf.o
|
||||||
else
|
else
|
||||||
LDFLAGS = -Wl,-u
|
LDFLAGS =-Wl,-u
|
||||||
CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 -DNO_DEBUG -DNO_INFO
|
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 \
|
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 \
|
sram.o crc.o debug.o dump.o rle.c loader.o \
|
||||||
info.o shared_memory.o command.o
|
system.o util.o info.o shared_memory.o command.o irq.o \
|
||||||
|
pwm.o inflate.o neginf/neginf.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
|
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
|
||||||
@@ -76,6 +80,11 @@ fuse:
|
|||||||
flash: main.hex
|
flash: main.hex
|
||||||
$(AVRDUDE) -U flash:w:main.hex:i
|
$(AVRDUDE) -U flash:w:main.hex:i
|
||||||
|
|
||||||
|
loader01:
|
||||||
|
python $(CONVERT_RLE) $(BOOT_ROM01)
|
||||||
|
|
||||||
|
loader02:
|
||||||
|
python $(CONVERT_ZIP) $(BOOT_ROM02)
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$(COMPILE) -c $< -o $@
|
$(COMPILE) -c $< -o $@
|
||||||
@@ -105,4 +114,4 @@ cpp:
|
|||||||
$(COMPILE) -E main.c
|
$(COMPILE) -E main.c
|
||||||
|
|
||||||
clean:
|
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
|
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
|
||||||
|
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
# Revision: $:Id: checksize 83 2006-01-05 22:20:53Z cs $
|
# Revision: $:Id: checksize 83 2006-01-05 22:20:53Z cs $
|
||||||
|
|
||||||
error=0
|
error=0
|
||||||
codelimit=65536 # default value
|
codelimit=61440 # default value
|
||||||
datalimit=4064 # default value; leave 32 bytes for stack
|
datalimit=4064 # default value; leave 32 bytes for stack
|
||||||
|
|
||||||
if [ $# -gt 1 ]; then
|
if [ $# -gt 1 ]; then
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@@ -26,36 +27,94 @@
|
|||||||
#include "requests.h"
|
#include "requests.h"
|
||||||
#include "sram.h"
|
#include "sram.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
|
#include "irq.h"
|
||||||
|
#include "usbdrv.h"
|
||||||
|
#include "rle.h"
|
||||||
|
#include "loader.h"
|
||||||
|
#include "system.h"
|
||||||
|
|
||||||
extern uint32_t req_bank_size;
|
#include "neginf/neginf.h"
|
||||||
|
#include "inflate.h"
|
||||||
|
|
||||||
|
|
||||||
void send_reset()
|
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()
|
||||||
{
|
{
|
||||||
info("Reset Snes\n");
|
uint8_t i = 0;
|
||||||
snes_reset_on();
|
info_P(PSTR("USB init\n"));
|
||||||
snes_reset_lo();
|
usbDeviceDisconnect(); /* enforce re-enumeration, do this while */
|
||||||
_delay_ms(2);
|
cli();
|
||||||
snes_reset_hi();
|
info_P(PSTR("USB disconnect\n"));
|
||||||
snes_reset_off();
|
i = 10;
|
||||||
}
|
while (--i) { /* fake USB disconnect for > 250 ms */
|
||||||
|
_delay_ms(50);
|
||||||
void send_irq()
|
|
||||||
{
|
|
||||||
snes_irq_on();
|
|
||||||
snes_irq_lo();
|
|
||||||
_delay_us(20);
|
|
||||||
snes_irq_hi();
|
|
||||||
snes_irq_off();
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_rom_mode()
|
|
||||||
{
|
|
||||||
if (req_bank_size == 0x8000) {
|
|
||||||
snes_lorom();
|
|
||||||
info("Set Snes lowrom \n");
|
|
||||||
} else {
|
|
||||||
snes_hirom();
|
|
||||||
info("Set Snes hirom \n");
|
|
||||||
}
|
}
|
||||||
|
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(){
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,10 @@
|
|||||||
#ifndef __COMMAND_H__
|
#ifndef __COMMAND_H__
|
||||||
#define __COMMAND_H__
|
#define __COMMAND_H__
|
||||||
|
|
||||||
void send_reset();
|
void usb_connect();
|
||||||
void send_irq();
|
void boot_startup_rom(uint16_t init_delay);
|
||||||
void set_rom_mode();
|
void banner();
|
||||||
|
void transaction_status();
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -42,7 +42,16 @@
|
|||||||
#define USB_MAX_TRANS 0xff
|
#define USB_MAX_TRANS 0xff
|
||||||
#define USB_CRC_CHECK 0x01
|
#define USB_CRC_CHECK 0x01
|
||||||
|
|
||||||
#define TRANSFER_BUFFER_SIZE 0x200
|
#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
|
#endif
|
||||||
|
|||||||
@@ -71,12 +71,12 @@ uint16_t crc_check_bulk_memory(uint32_t bottom_addr, uint32_t top_addr, uint32_t
|
|||||||
uint32_t addr = 0;
|
uint32_t addr = 0;
|
||||||
uint8_t req_bank = 0;
|
uint8_t req_bank = 0;
|
||||||
sram_bulk_read_start(bottom_addr);
|
sram_bulk_read_start(bottom_addr);
|
||||||
debug(DEBUG_CRC,"crc_check_bulk_memory: bottom_addr=0x%08lx top_addr=0x%08lx\n",
|
debug_P(DEBUG_CRC, PSTR("crc_check_bulk_memory: bottom_addr=0x%08lx top_addr=0x%08lx\n"),
|
||||||
bottom_addr,top_addr);
|
bottom_addr,top_addr);
|
||||||
|
|
||||||
for (addr = bottom_addr; addr < top_addr; addr++) {
|
for (addr = bottom_addr; addr < top_addr; addr++) {
|
||||||
if (addr && addr % bank_size == 0) {
|
if (addr && ((addr % bank_size) == 0)) {
|
||||||
debug(DEBUG_CRC,"crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n",
|
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,addr,crc);
|
||||||
req_bank++;
|
req_bank++;
|
||||||
crc = 0;
|
crc = 0;
|
||||||
@@ -85,7 +85,7 @@ uint16_t crc_check_bulk_memory(uint32_t bottom_addr, uint32_t top_addr, uint32_t
|
|||||||
sram_bulk_read_next();
|
sram_bulk_read_next();
|
||||||
}
|
}
|
||||||
if (addr % 0x8000 == 0)
|
if (addr % 0x8000 == 0)
|
||||||
debug(DEBUG_CRC,"crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n",
|
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,addr,crc);
|
||||||
sram_bulk_read_end();
|
sram_bulk_read_end();
|
||||||
return crc;
|
return crc;
|
||||||
|
|||||||
@@ -20,30 +20,35 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
extern FILE uart_stdout;
|
extern FILE uart_stdout;
|
||||||
|
|
||||||
extern int debug_level; /* the higher, the more messages... */
|
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__)
|
#if defined(NO_DEBUG) && defined(__GNUC__)
|
||||||
#else
|
#else
|
||||||
void debug(int level, char* format, ...) {
|
void debug_P(int level, PGM_P format, ...) {
|
||||||
#ifdef NO_DEBUG
|
#ifdef NO_DEBUG
|
||||||
|
|
||||||
#else
|
#else
|
||||||
va_list args;
|
va_list args;
|
||||||
if (!(debug_level & level))
|
if (!(debug_level & level))
|
||||||
return;
|
return;
|
||||||
|
strlcpy_P((char*)buffer_debug,format,FORMAT_BUFFER_LEN);
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
vprintf(format, args);
|
vprintf((char*)buffer_debug, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
#if defined(NO_DEBUG) && defined(__GNUC__)
|
#if defined(NO_DEBUG) && defined(__GNUC__)
|
||||||
/* gcc's cpp has extensions; it allows for macros with a variable number of
|
/* gcc's cpp has extensions; it allows for macros with a variable number of
|
||||||
@@ -39,5 +39,17 @@ void debug(int level, char *format, ...);
|
|||||||
#endif
|
#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 */
|
#endif /* DEBUG_H */
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "info.h"
|
#include "info.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "sram.h"
|
#include "sram.h"
|
||||||
|
#include "dump.h"
|
||||||
|
|
||||||
|
|
||||||
extern FILE uart_stdout;
|
extern FILE uart_stdout;
|
||||||
@@ -47,21 +48,21 @@ void dump_packet(uint32_t addr, uint32_t len, uint8_t * packet)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (clear) {
|
if (clear) {
|
||||||
info("*\n");
|
info_P(PSTR("*\n"));
|
||||||
clear = 0;
|
clear = 0;
|
||||||
}
|
}
|
||||||
info("%08lx:", addr + i);
|
info_P(PSTR("%08lx:"), addr + i);
|
||||||
for (j = 0; j < 16; j++) {
|
for (j = 0; j < 16; j++) {
|
||||||
info(" %02x", packet[i + j]);
|
info_P(PSTR(" %02x"), packet[i + j]);
|
||||||
}
|
}
|
||||||
info(" |");
|
info_P(PSTR(" |"));
|
||||||
for (j = 0; j < 16; j++) {
|
for (j = 0; j < 16; j++) {
|
||||||
if (packet[i + j] >= 33 && packet[i + j] <= 126)
|
if (packet[i + j] >= 33 && packet[i + j] <= 126)
|
||||||
info("%c", packet[i + j]);
|
info_P(PSTR("%c"), packet[i + j]);
|
||||||
else
|
else
|
||||||
info(".");
|
info_P(PSTR("."));
|
||||||
}
|
}
|
||||||
info("|\n");
|
info_P(PSTR("|\n"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,11 +73,11 @@ void dump_memory(uint32_t bottom_addr, uint32_t top_addr)
|
|||||||
sram_bulk_read_start(bottom_addr);
|
sram_bulk_read_start(bottom_addr);
|
||||||
for ( addr = bottom_addr; addr < top_addr; addr++) {
|
for ( addr = bottom_addr; addr < top_addr; addr++) {
|
||||||
if (addr%0x10 == 0)
|
if (addr%0x10 == 0)
|
||||||
info("\n%08lx:", addr);
|
info_P(PSTR("\n%08lx:"), addr);
|
||||||
byte = sram_bulk_read();
|
byte = sram_bulk_read();
|
||||||
sram_bulk_read_next();
|
sram_bulk_read_next();
|
||||||
info(" %02x", byte);
|
info_P(PSTR(" %02x"), byte);
|
||||||
}
|
}
|
||||||
info("\n");
|
info_P(PSTR("\n"));
|
||||||
sram_bulk_read_end();
|
sram_bulk_read_end();
|
||||||
}
|
}
|
||||||
|
|||||||
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;
|
||||||
|
}
|
||||||
@@ -20,30 +20,37 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern FILE uart_stdout;
|
extern FILE uart_stdout;
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef NO_INFO
|
||||||
|
uint8_t buffer_info[FORMAT_BUFFER_LEN];
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(NO_INFO) && defined(__GNUC__)
|
#if defined(NO_INFO) && defined(__GNUC__)
|
||||||
|
|
||||||
#define info(format, args...) ((void)0)
|
#define info(format, args...) ((void)0)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
void info(char* format, ...) {
|
void info_P(PGM_P format, ...) {
|
||||||
#ifdef NO_INFO
|
#ifdef NO_INFO
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
strlcpy_P((char*)buffer_info,format,FORMAT_BUFFER_LEN);
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
vprintf(format, args);
|
vprintf((char*)buffer_info, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
#if defined(NO_INFO) && defined(__GNUC__)
|
#if defined(NO_INFO) && defined(__GNUC__)
|
||||||
/* gcc's cpp has extensions; it allows for macros with a variable number of
|
/* gcc's cpp has extensions; it allows for macros with a variable number of
|
||||||
@@ -39,4 +39,15 @@ void info(char *format, ...);
|
|||||||
#endif
|
#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
|
#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
|
||||||
4061
avr/usbload/loader.c
4061
avr/usbload/loader.c
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,14 @@
|
|||||||
|
/*
|
||||||
|
File: qd16boot02.smc
|
||||||
|
Time: Sat, 24 Oct 2009 19:05:36
|
||||||
|
*/
|
||||||
#ifndef __FIFO_H__
|
#ifndef __FIFO_H__
|
||||||
#define __FIFO_H__
|
#define __FIFO_H__
|
||||||
|
|
||||||
#define ROM_BUFFER_SIZE 31091
|
#define ROM_ZIP_SIZE 33654
|
||||||
#define ROM_HUFFMAN_SIZE 0
|
#define ROM_BUFFER_CNT 2
|
||||||
#define ROM_RLE_SIZE 31091
|
|
||||||
|
#define ROM_BUFFER_SIZE01 32767
|
||||||
|
#define ROM_BUFFER_SIZE02 887
|
||||||
|
|
||||||
#endif
|
#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
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
#include <avr/eeprom.h>
|
#include <avr/eeprom.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "usbdrv.h"
|
#include "usbdrv.h"
|
||||||
#include "oddebug.h"
|
#include "oddebug.h"
|
||||||
@@ -44,35 +45,21 @@
|
|||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "shared_memory.h"
|
#include "shared_memory.h"
|
||||||
|
#include "irq.h"
|
||||||
|
#include "pwm.h"
|
||||||
#include "testing.h"
|
#include "testing.h"
|
||||||
|
#include "shell.h"
|
||||||
|
#include "system.h"
|
||||||
|
|
||||||
|
#ifndef NO_DEBUG
|
||||||
|
|
||||||
extern const char _rom[] PROGMEM;
|
|
||||||
extern FILE uart_stdout;
|
extern FILE uart_stdout;
|
||||||
|
#endif
|
||||||
|
extern system_t system;
|
||||||
|
|
||||||
uint8_t debug_level = (DEBUG | DEBUG_USB | DEBUG_CRC | DEBUG_SHM );
|
uint8_t debug_level = (DEBUG | DEBUG_CRC);
|
||||||
|
|
||||||
uint8_t read_buffer[TRANSFER_BUFFER_SIZE];
|
|
||||||
uint32_t req_addr = 0;
|
|
||||||
uint32_t req_addr_end = 0;
|
|
||||||
uint32_t req_size;
|
|
||||||
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 = REQ_STATUS_IDLE;
|
|
||||||
uint8_t rx_remaining = 0;
|
|
||||||
uint8_t tx_remaining = 0;
|
|
||||||
uint16_t sync_errors = 0;
|
|
||||||
uint8_t tx_buffer[32];
|
|
||||||
uint8_t data_buffer[4];
|
|
||||||
uint32_t addr;
|
|
||||||
uint16_t crc = 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
usb_transaction_t usb_trans;
|
||||||
|
|
||||||
usbMsgLen_t usbFunctionSetup(uchar data[8])
|
usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||||
{
|
{
|
||||||
@@ -82,53 +69,61 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
|
|
||||||
if (rq->bRequest == USB_BULK_UPLOAD_INIT) {
|
if (rq->bRequest == USB_BULK_UPLOAD_INIT) {
|
||||||
|
|
||||||
req_bank = 0;
|
usb_trans.req_bank = 0;
|
||||||
rx_remaining = 0;
|
usb_trans.rx_remaining = 0;
|
||||||
debug(DEBUG_USB, "USB_BULK_UPLOAD_INIT: %i %i\n", rq->wValue.word,
|
debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_INIT: %i %i\n"), rq->wValue.word,
|
||||||
rq->wIndex.word);
|
rq->wIndex.word);
|
||||||
req_bank_size = (uint32_t) (1L << rq->wValue.word);
|
usb_trans.req_bank_size = (uint32_t) (1L << rq->wValue.word);
|
||||||
req_bank_cnt = rq->wIndex.word;
|
usb_trans.req_bank_cnt = rq->wIndex.word;
|
||||||
req_addr_end = (uint32_t) req_bank_size *req_bank_cnt;
|
usb_trans.req_addr_end = (uint32_t) usb_trans.req_bank_size * usb_trans.req_bank_cnt;
|
||||||
req_percent = 0;
|
usb_trans.req_percent = 0;
|
||||||
req_percent_last = 0;
|
usb_trans.req_percent_last = 0;
|
||||||
sync_errors = 0;
|
usb_trans.sync_errors = 0;
|
||||||
debug(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
"USB_BULK_UPLOAD_INIT: bank_size=0x%08lx bank_cnt=0x%x end_addr=0x%08lx\n",
|
PSTR("USB_BULK_UPLOAD_INIT: bank_size=0x%08lx bank_cnt=0x%x end_addr=0x%08lx\n"),
|
||||||
req_bank_size, req_bank_cnt, req_addr_end);
|
usb_trans.req_bank_size, usb_trans.req_bank_cnt, usb_trans.req_addr_end);
|
||||||
|
|
||||||
shared_memory_write(SHARED_MEM_TX_CMD_BANK_COUNT, req_bank_cnt);
|
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_START, 0);
|
||||||
if (req_addr == 0x000000) {
|
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();
|
timer_start();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
* -------------------------------------------------------------------------
|
* -------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
} else if (rq->bRequest == USB_BULK_UPLOAD_ADDR) {
|
} else if (rq->bRequest == USB_BULK_UPLOAD_ADDR) {
|
||||||
|
|
||||||
req_state = REQ_STATUS_BULK_UPLOAD;
|
usb_trans.req_state = REQ_STATUS_BULK_UPLOAD;
|
||||||
req_addr = rq->wValue.word;
|
usb_trans.req_addr = rq->wValue.word;
|
||||||
req_addr = req_addr << 16;
|
usb_trans.req_addr = usb_trans.req_addr << 16;
|
||||||
req_addr = req_addr | rq->wIndex.word;
|
usb_trans.req_addr = usb_trans.req_addr | rq->wIndex.word;
|
||||||
rx_remaining = rq->wLength.word;
|
usb_trans.rx_remaining = rq->wLength.word;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (req_addr && req_addr % req_bank_size == 0) {
|
if (usb_trans.req_addr && usb_trans.req_addr % usb_trans.req_bank_size == 0) {
|
||||||
|
#if DO_TIMER
|
||||||
|
#ifndef NO_DEBUG
|
||||||
#ifdef FLT_DEBUG
|
#ifdef FLT_DEBUG
|
||||||
debug(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
"USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%.4f\n",
|
PSTR("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
|
||||||
req_bank, req_addr, timer_stop());
|
usb_trans.req_bank, usb_trans.req_addr, timer_stop());
|
||||||
#else
|
#else
|
||||||
debug(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
"USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%i\n",
|
PSTR("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%i\n"),
|
||||||
req_bank, req_addr, timer_stop_int());
|
usb_trans.req_bank, usb_trans.req_addr, timer_stop_int());
|
||||||
#endif
|
#endif
|
||||||
req_bank++;
|
timer_start();
|
||||||
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_PROGESS, req_bank);
|
#endif
|
||||||
sram_bulk_write_start(req_addr);
|
#endif
|
||||||
timer_start();
|
usb_trans.req_bank++;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
sram_bulk_write_start(req_addr);
|
sram_bulk_write_start(usb_trans.req_addr);
|
||||||
}
|
}
|
||||||
ret_len = USB_MAX_TRANS;
|
ret_len = USB_MAX_TRANS;
|
||||||
|
|
||||||
@@ -136,283 +131,194 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
* -------------------------------------------------------------------------
|
* -------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
} else if (rq->bRequest == USB_BULK_UPLOAD_NEXT) {
|
} 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;
|
||||||
|
|
||||||
req_state = REQ_STATUS_BULK_UPLOAD;
|
#if DO_SHM
|
||||||
req_addr = rq->wValue.word;
|
usb_trans.req_percent = (uint32_t)( 100 * usb_trans.req_addr ) / usb_trans.req_addr_end;
|
||||||
req_addr = req_addr << 16;
|
if (usb_trans.req_percent!=usb_trans.req_percent_last){
|
||||||
req_addr = req_addr | rq->wIndex.word;
|
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_PROGESS, usb_trans.req_percent);
|
||||||
rx_remaining = rq->wLength.word;
|
|
||||||
|
|
||||||
req_percent = (uint32_t)( 100 * req_addr ) / req_addr_end;
|
|
||||||
if (req_percent!=req_percent_last){
|
|
||||||
//debug(DEBUG_USB,
|
|
||||||
// "USB_BULK_UPLOAD_ADDR: precent=%i\n", req_percent);
|
|
||||||
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_PROGESS, req_percent);
|
|
||||||
sram_bulk_write_start(req_addr);
|
|
||||||
}
|
}
|
||||||
req_percent_last = req_percent;
|
usb_trans.req_percent_last = usb_trans.req_percent;
|
||||||
|
shared_memory_scratchpad_region_save_helper(usb_trans.req_addr);
|
||||||
#if 0
|
#endif
|
||||||
if (req_addr && (req_addr % 0x1000) == 0) {
|
if (usb_trans.req_addr && (usb_trans.req_addr % usb_trans.req_bank_size) == 0) {
|
||||||
debug(DEBUG_USB,
|
#if DO_TIMER
|
||||||
"USB_BULK_UPLOAD_NEXT: bank=0x%02x addr=0x%08lx crc=%04x\n",
|
#ifndef NO_DEBUG
|
||||||
req_bank, req_addr, crc_check_bulk_memory(req_addr - 0x1000,
|
|
||||||
req_addr,
|
|
||||||
req_bank_size));
|
|
||||||
|
|
||||||
}
|
|
||||||
sram_bulk_write_start(req_addr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!shared_memory_scratchpad_region_save_helper(req_addr)){
|
|
||||||
debug(DEBUG_USB,
|
|
||||||
"USB_BULK_UPLOAD_NEXT: scratchpad_region_save_helper was dirty\n");
|
|
||||||
sram_bulk_write_start(req_addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (req_addr && (req_addr % req_bank_size) == 0) {
|
|
||||||
#ifdef FLT_DEBUG
|
#ifdef FLT_DEBUG
|
||||||
debug(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
"USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%.4f\n",
|
PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
|
||||||
req_bank, req_addr, timer_stop());
|
usb_trans.req_bank, usb_trans.req_addr, timer_stop());
|
||||||
#else
|
#else
|
||||||
debug(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
"USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%i\n",
|
PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%i\n"),
|
||||||
req_bank, req_addr, timer_stop_int());
|
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
|
#endif
|
||||||
req_bank++;
|
|
||||||
timer_start();
|
|
||||||
shared_memory_write(SHARED_MEM_TX_CMD_BANK_CURRENT, req_bank);
|
|
||||||
sram_bulk_write_start(req_addr);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
ret_len = USB_MAX_TRANS;
|
ret_len = USB_MAX_TRANS;
|
||||||
/*
|
/*
|
||||||
* -------------------------------------------------------------------------
|
* -------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
} else if (rq->bRequest == USB_BULK_UPLOAD_END) {
|
} else if (rq->bRequest == USB_BULK_UPLOAD_END) {
|
||||||
if (req_state != REQ_STATUS_BULK_UPLOAD) {
|
if (usb_trans.req_state != REQ_STATUS_BULK_UPLOAD) {
|
||||||
debug(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
"USB_BULK_UPLOAD_END: ERROR state is not REQ_STATUS_BULK_UPLOAD\n");
|
PSTR("USB_BULK_UPLOAD_END: ERROR state is not REQ_STATUS_BULK_UPLOAD\n"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
debug(DEBUG_USB, "USB_BULK_UPLOAD_END:\n");
|
debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_END:\n"));
|
||||||
req_state = REQ_STATUS_IDLE;
|
usb_trans.req_state = REQ_STATUS_IDLE;
|
||||||
sram_bulk_write_end();
|
sram_bulk_write_end();
|
||||||
|
#if DO_SHM
|
||||||
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_END, 0);
|
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_END, 0);
|
||||||
|
#endif
|
||||||
ret_len = 0;
|
ret_len = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* -------------------------------------------------------------------------
|
* -------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
} else if (rq->bRequest == USB_CRC) {
|
} else if (rq->bRequest == USB_CRC) {
|
||||||
req_addr = rq->wValue.word;
|
usb_trans.req_addr = rq->wValue.word;
|
||||||
req_addr = req_addr << 16;
|
usb_trans.req_addr = usb_trans.req_addr << 16;
|
||||||
req_addr = req_addr | rq->wIndex.word;
|
usb_trans.req_addr = usb_trans.req_addr | rq->wIndex.word;
|
||||||
debug(DEBUG_USB, "USB_CRC: addr=0x%08lx \n", req_addr);
|
debug_P(DEBUG_USB, PSTR("USB_CRC: addr=0x%08lx \n"), usb_trans.req_addr);
|
||||||
crc_check_bulk_memory(0x000000, req_addr, req_bank_size);
|
crc_check_bulk_memory(0x000000, usb_trans.req_addr, usb_trans.req_bank_size);
|
||||||
ret_len = 0;
|
|
||||||
/*
|
|
||||||
* -------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
} else if (rq->bRequest == USB_MODE_SNES) {
|
|
||||||
req_state = REQ_STATUS_SNES;
|
|
||||||
debug(DEBUG_USB, "USB_MODE_SNES:\n");
|
|
||||||
ret_len = 0;
|
ret_len = 0;
|
||||||
/*
|
/*
|
||||||
* -------------------------------------------------------------------------
|
* -------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
} else if (rq->bRequest == USB_MODE_AVR) {
|
} else if (rq->bRequest == USB_MODE_AVR) {
|
||||||
req_state = REQ_STATUS_AVR;
|
usb_trans.req_state = REQ_STATUS_AVR;
|
||||||
debug(DEBUG_USB, "USB_MODE_AVR:\n");
|
debug_P(DEBUG_USB, PSTR("USB_MODE_AVR:\n"));
|
||||||
ret_len = 0;
|
ret_len = 0;
|
||||||
/*
|
/*
|
||||||
* -------------------------------------------------------------------------
|
* -------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
} else if (rq->bRequest == USB_AVR_RESET) {
|
} else if (rq->bRequest == USB_AVR_RESET) {
|
||||||
debug(DEBUG_USB, "USB_AVR_RESET:\n");
|
debug_P(DEBUG_USB, PSTR("USB_AVR_RESET:\n"));
|
||||||
soft_reset();
|
soft_reset();
|
||||||
ret_len = 0;
|
ret_len = 0;
|
||||||
/*
|
/*
|
||||||
* -------------------------------------------------------------------------
|
* -------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
} else if (rq->bRequest == USB_SET_LAODER) {
|
||||||
} else if (rq->bRequest == USB_CRC_ADDR) {
|
usb_trans.loader_enabled = rq->wValue.word;
|
||||||
req_state = REQ_STATUS_CRC;
|
ret_len = 0;
|
||||||
req_addr = rq->wValue.word;
|
|
||||||
req_addr = req_addr << 16;
|
|
||||||
req_addr = req_addr | rq->wIndex.word;
|
|
||||||
debug(DEBUG_USB, "USB_CRC_ADDR: addr=0x%lx size=%i\n", req_addr,
|
|
||||||
rq->wLength.word);
|
|
||||||
req_size = rq->wLength.word;
|
|
||||||
req_size = req_size << 2;
|
|
||||||
tx_remaining = 2;
|
|
||||||
debug(DEBUG_USB, "USB_CRC_ADDR: addr=0x%lx size=%li\n", req_addr,
|
|
||||||
req_size);
|
|
||||||
|
|
||||||
crc = crc_check_memory_range(req_addr, req_size, read_buffer);
|
|
||||||
tx_buffer[0] = crc & 0xff;
|
|
||||||
tx_buffer[1] = (crc >> 8) & 0xff;
|
|
||||||
ret_len = 2;
|
|
||||||
req_state = REQ_STATUS_IDLE;
|
|
||||||
}
|
}
|
||||||
|
usbMsgPtr = usb_trans.rx_buffer;
|
||||||
usbMsgPtr = data_buffer;
|
return ret_len;
|
||||||
return ret_len; /* default for not implemented requests: return no data back to host */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* -------------------------------------------------------------------------
|
* -------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
void usb_connect()
|
void globals_init(){
|
||||||
{
|
memset(&usb_trans,0,sizeof(usb_transaction_t));
|
||||||
uint8_t i = 0;
|
|
||||||
info("USB init\n");
|
usb_trans.req_addr = 0;
|
||||||
usbDeviceDisconnect(); /* enforce re-enumeration, do this while */
|
usb_trans.req_addr_end = 0;
|
||||||
cli();
|
usb_trans.req_state = REQ_STATUS_IDLE;
|
||||||
info("USB disconnect\n");
|
usb_trans.rx_remaining = 0;
|
||||||
i = 10;
|
usb_trans.tx_remaining = 0;
|
||||||
while (--i) { /* fake USB disconnect for > 250 ms */
|
usb_trans.sync_errors = 0;
|
||||||
led_on();
|
usb_trans.loader_enabled = 1;
|
||||||
_delay_ms(35);
|
|
||||||
led_off();
|
|
||||||
_delay_ms(65);
|
|
||||||
}
|
|
||||||
led_on();
|
|
||||||
usbDeviceConnect();
|
|
||||||
info("USB connect\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void boot_startup_rom()
|
|
||||||
{
|
|
||||||
|
|
||||||
info("Activate AVR bus\n");
|
|
||||||
avr_bus_active();
|
|
||||||
info("IRQ off\n");
|
|
||||||
snes_irq_lo();
|
|
||||||
snes_irq_off();
|
|
||||||
snes_lorom();
|
|
||||||
info("Set Snes lowrom \n");
|
|
||||||
rle_decode(&_rom, ROM_BUFFER_SIZE, 0x000000);
|
|
||||||
dump_memory(0x10000 - 0x100, 0x10000);
|
|
||||||
snes_reset_hi();
|
|
||||||
snes_reset_off();
|
|
||||||
snes_irq_lo();
|
|
||||||
snes_irq_off();
|
|
||||||
info("IRQ off\n");
|
|
||||||
snes_hirom();
|
|
||||||
snes_wr_disable();
|
|
||||||
info("Disable snes WR\n");
|
|
||||||
snes_bus_active();
|
|
||||||
info("Activate Snes bus\n");
|
|
||||||
_delay_ms(20);
|
|
||||||
send_reset();
|
|
||||||
_delay_ms(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifndef NO_DEBUG
|
||||||
uart_init();
|
uart_init();
|
||||||
stdout = &uart_stdout;
|
stdout = &uart_stdout;
|
||||||
|
banner();
|
||||||
info("Sytem start\n");
|
|
||||||
system_init();
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
test_read_write();
|
|
||||||
test_bulk_read_write();
|
|
||||||
test_crc();
|
|
||||||
while (1);
|
|
||||||
#endif
|
#endif
|
||||||
|
shared_memory_init();
|
||||||
info("Boot startup rom\n");
|
system_init();
|
||||||
boot_startup_rom();
|
sram_init();
|
||||||
|
//pwm_init();
|
||||||
|
irq_init();
|
||||||
|
boot_startup_rom(50);
|
||||||
|
globals_init();
|
||||||
|
//pwm_stop();
|
||||||
usbInit();
|
usbInit();
|
||||||
usb_connect();
|
usb_connect();
|
||||||
|
sei();
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
avr_bus_active();
|
system_set_bus_avr();
|
||||||
info("Activate AVR bus\n");
|
system_set_wr_disable();
|
||||||
info("IRQ off\n");
|
info_P(PSTR("USB poll\n"));
|
||||||
snes_irq_lo();
|
while (usb_trans.req_state != REQ_STATUS_SNES) {
|
||||||
snes_irq_off();
|
|
||||||
info("Set Snes lowrom\n");
|
|
||||||
snes_lorom();
|
|
||||||
info("Disable snes WR\n");
|
|
||||||
snes_wr_disable();
|
|
||||||
sei();
|
|
||||||
info("USB poll\n");
|
|
||||||
while (req_state != REQ_STATUS_SNES) {
|
|
||||||
usbPoll();
|
usbPoll();
|
||||||
|
#ifdef DO_SHELL
|
||||||
|
#ifndef NO_DEBUG
|
||||||
|
shell_run();
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DO_SHM
|
||||||
shared_memory_write(SHARED_MEM_TX_CMD_TERMINATE, 0);
|
shared_memory_write(SHARED_MEM_TX_CMD_TERMINATE, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
//shared_memory_scratchpad_region_tx_restore();
|
#if DO_SHM_SCRATCHPAD
|
||||||
//shared_memory_scratchpad_region_rx_restore();
|
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
|
||||||
|
|
||||||
info("USB poll done\n");
|
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();
|
set_rom_mode();
|
||||||
snes_wr_disable();
|
snes_wr_disable();
|
||||||
info("Disable snes WR\n");
|
info_P(PSTR("Disable SNES WR\n"));
|
||||||
snes_bus_active();
|
snes_bus_active();
|
||||||
info("Activate Snes bus\n");
|
info_P(PSTR("Activate SNES bus\n"));
|
||||||
_delay_ms(100);
|
irq_stop();
|
||||||
send_reset();
|
send_reset();
|
||||||
|
*/
|
||||||
info("Poll\n");
|
info_P(PSTR("Poll USB\n"));
|
||||||
while (req_state != REQ_STATUS_AVR) {
|
while ((usb_trans.req_state != REQ_STATUS_AVR)) {
|
||||||
usbPoll();
|
usbPoll();
|
||||||
|
#ifdef DO_SHELL
|
||||||
|
#ifndef NO_DEBUG
|
||||||
|
shell_run();
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DO_IRQ
|
|
||||||
uint8_t i;
|
|
||||||
uint16_t irq_count = 0;
|
|
||||||
i = 10;
|
|
||||||
while (--i) {
|
|
||||||
_delay_ms(100);
|
|
||||||
}
|
|
||||||
info("Send IRQ %i\n", ++irq_count);
|
|
||||||
send_irq();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DO_BUS_STEALING
|
|
||||||
avr_bus_active();
|
|
||||||
sram_bulk_read_start(0x003000);
|
|
||||||
c = sram_bulk_read();
|
|
||||||
i = 5;
|
|
||||||
while (--i) {
|
|
||||||
_delay_ms(500);
|
|
||||||
info("Wait to switch to snes mode %i\n", i);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req_bank_size == 0x8000) {
|
|
||||||
snes_lorom();
|
|
||||||
info("Set Snes lowrom \n");
|
|
||||||
} else {
|
|
||||||
snes_hirom();
|
|
||||||
info("Set Snes hirom \n");
|
|
||||||
}
|
|
||||||
snes_wr_disable();
|
|
||||||
info("Disable snes WR\n");
|
|
||||||
snes_bus_active();
|
|
||||||
info("Activate Snes bus\n");
|
|
||||||
info("Read 0x3000=%c\n", c);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
info("Boot startup rom\n");
|
//info_P(PSTR("-->Switch TO AVR\n"));
|
||||||
boot_startup_rom();
|
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;
|
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
|
||||||
@@ -38,5 +38,23 @@
|
|||||||
#define USB_MODE_SNES 10
|
#define USB_MODE_SNES 10
|
||||||
#define USB_MODE_AVR 11
|
#define USB_MODE_AVR 11
|
||||||
#define USB_AVR_RESET 12
|
#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__ */
|
#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
|
||||||
@@ -32,14 +32,14 @@
|
|||||||
|
|
||||||
#define RUNCHAR 0x90
|
#define RUNCHAR 0x90
|
||||||
|
|
||||||
uint8_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
|
#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;
|
uint8_t in_byte, in_repeat, last_byte;
|
||||||
uint32_t out_len, out_len_left;
|
info_P(PSTR("RLE decode len=%li addr=0x%08lx\n"), in_len, out_addr);
|
||||||
info("RLE decode len=%li addr=0x%08lx\n", in_len, out_addr);
|
|
||||||
last_byte = 0;
|
last_byte = 0;
|
||||||
|
|
||||||
out_len_left = out_len;
|
|
||||||
sram_bulk_write_start(out_addr);
|
sram_bulk_write_start(out_addr);
|
||||||
#define INBYTE(b) \
|
#define INBYTE(b) \
|
||||||
do { \
|
do { \
|
||||||
@@ -63,7 +63,7 @@ uint8_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
|
|||||||
if (in_byte == RUNCHAR) {
|
if (in_byte == RUNCHAR) {
|
||||||
INBYTE(in_repeat);
|
INBYTE(in_repeat);
|
||||||
if (in_repeat != 0) {
|
if (in_repeat != 0) {
|
||||||
info("Orphaned RLE code at start\n");
|
info_P(PSTR("Orphaned RLE code at start\n"));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
OUTBYTE(RUNCHAR);
|
OUTBYTE(RUNCHAR);
|
||||||
@@ -74,7 +74,7 @@ uint8_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
|
|||||||
while (in_len > 0) {
|
while (in_len > 0) {
|
||||||
INBYTE(in_byte);
|
INBYTE(in_byte);
|
||||||
if (in_len % 1024 == 0)
|
if (in_len % 1024 == 0)
|
||||||
info(".");
|
info_P(PSTR("."));
|
||||||
if (in_byte == RUNCHAR) {
|
if (in_byte == RUNCHAR) {
|
||||||
INBYTE(in_repeat);
|
INBYTE(in_repeat);
|
||||||
if (in_repeat == 0) {
|
if (in_repeat == 0) {
|
||||||
@@ -99,5 +99,8 @@ uint8_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
|
|||||||
last_byte = in_byte;
|
last_byte = in_byte;
|
||||||
}
|
}
|
||||||
sram_bulk_write_end();
|
sram_bulk_write_end();
|
||||||
return 0;
|
info_P(PSTR("\nDone addr=0x%08lx\n"), out_addr);
|
||||||
|
return out_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -23,6 +23,6 @@
|
|||||||
|
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
uint8_t rle_decode(PGM_VOID_P in_addr, uint32_t in_len, uint32_t out_addr);
|
uint32_t rle_decode(PGM_VOID_P in_addr, uint32_t in_len, uint32_t out_addr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -31,6 +31,8 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "dump.h"
|
#include "dump.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
|
#include "crc.h"
|
||||||
|
|
||||||
|
|
||||||
uint8_t irq_addr_lo;
|
uint8_t irq_addr_lo;
|
||||||
uint8_t irq_addr_hi;
|
uint8_t irq_addr_hi;
|
||||||
@@ -46,83 +48,119 @@ uint8_t scratchpad_locked_rx = 1;
|
|||||||
uint8_t scratchpad_locked_tx = 1;
|
uint8_t scratchpad_locked_tx = 1;
|
||||||
|
|
||||||
|
|
||||||
uint8_t shared_memory_scratchpad_region_save_helper(uint32_t addr){
|
void shared_memory_init(void){
|
||||||
|
scratchpad_locked_rx = 1;
|
||||||
|
scratchpad_locked_tx = 1;
|
||||||
|
|
||||||
if(addr > (SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE) && scratchpad_locked_tx){
|
}
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_save_helper: open tx addr=0x%06lx\n",addr);
|
|
||||||
|
|
||||||
|
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();
|
shared_memory_scratchpad_region_tx_save();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(addr > (SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE) && scratchpad_locked_rx){
|
if(addr > (SHARED_MEM_RX_LOC_STATE + ( SHARED_MEM_RX_LOC_SIZE )) && scratchpad_locked_rx){
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_save_helper: open rx addr=0x%06lx\n",addr);
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_save_helper: open rx addr=0x%06lx\n"),addr);
|
||||||
shared_memory_scratchpad_region_rx_save();
|
shared_memory_scratchpad_region_rx_save();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void shared_memory_scratchpad_region_tx_save()
|
void shared_memory_scratchpad_region_tx_save()
|
||||||
{
|
{
|
||||||
#if 1
|
sram_bulk_addr_save();
|
||||||
|
|
||||||
|
#if SHARED_SCRATCHPAD_CRC
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_TX_LOC_STATE,
|
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);
|
(uint32_t)(SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE), 0x8000);
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_tx_save: crc=%x\n",crc);
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"),crc);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_tx_save: unlock\n");
|
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,
|
sram_bulk_copy_into_buffer((uint32_t)SHARED_MEM_TX_LOC_STATE,scratchpad_region_tx,
|
||||||
(uint32_t)SHARED_MEM_TX_LOC_SIZE);
|
(uint32_t)SHARED_MEM_TX_LOC_SIZE);
|
||||||
scratchpad_locked_tx = 0;
|
scratchpad_locked_tx = 0;
|
||||||
|
|
||||||
#if 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_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);
|
dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
|
||||||
#endif
|
#endif
|
||||||
|
sram_bulk_addr_restore();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void shared_memory_scratchpad_region_rx_save()
|
void shared_memory_scratchpad_region_rx_save()
|
||||||
{
|
{
|
||||||
#if 1
|
|
||||||
|
sram_bulk_addr_save();
|
||||||
|
#if SHARED_SCRATCHPAD_CRC
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_RX_LOC_STATE,
|
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);
|
(uint32_t)(SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE), 0x8000);
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_tx_save: crc=%x\n",crc);
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_save: crc=%x\n"),crc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_rx_save: unlock\n");
|
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,
|
sram_bulk_copy_into_buffer((uint32_t)SHARED_MEM_RX_LOC_STATE,scratchpad_region_rx,
|
||||||
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
|
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
|
||||||
scratchpad_locked_rx = 0;
|
scratchpad_locked_rx = 0;
|
||||||
|
|
||||||
#if 0
|
#if SHARED_SCRATCHPAD_CRC
|
||||||
dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_SIZE, scratchpad_region_tx);
|
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);
|
dump_memory(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE);
|
||||||
#endif
|
#endif
|
||||||
|
sram_bulk_addr_restore();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void shared_memory_scratchpad_region_tx_restore()
|
void shared_memory_scratchpad_region_tx_restore()
|
||||||
{
|
{
|
||||||
if (scratchpad_locked_tx)
|
if (scratchpad_locked_tx)
|
||||||
return;
|
return;
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: lock\n"));
|
||||||
|
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_tx_restore: lock\n");
|
#if SHARED_SCRATCHPAD_DUMP
|
||||||
sram_bulk_copy_from_buffer((uint32_t)SHARED_MEM_TX_LOC_STATE,scratchpad_region_tx,
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: memory\n"));
|
||||||
(uint32_t)SHARED_MEM_TX_LOC_SIZE);
|
|
||||||
scratchpad_locked_tx = 1;
|
|
||||||
#if 0
|
|
||||||
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);
|
dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 1
|
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;
|
uint16_t crc;
|
||||||
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_TX_LOC_STATE,
|
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);
|
(uint32_t)(SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE), 0x8000);
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_tx_restore: crc=%x\n",crc);
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: crc=%x\n"),crc);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,21 +169,31 @@ void shared_memory_scratchpad_region_rx_restore()
|
|||||||
{
|
{
|
||||||
if (scratchpad_locked_rx)
|
if (scratchpad_locked_rx)
|
||||||
return;
|
return;
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_tx_save: lock\n");
|
|
||||||
|
|
||||||
|
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,
|
sram_bulk_copy_from_buffer((uint32_t)SHARED_MEM_RX_LOC_STATE,scratchpad_region_rx,
|
||||||
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
|
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
|
||||||
scratchpad_locked_rx = 1;
|
scratchpad_locked_rx = 1;
|
||||||
|
|
||||||
#if 0
|
#if SHARED_SCRATCHPAD_DUMP
|
||||||
dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_TX_LOC_SIZE, scratchpad_region_rx);
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: buffer\n"));
|
||||||
dump_memory(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE);
|
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
|
#endif
|
||||||
|
|
||||||
#if 1
|
#if SHARED_SCRATCHPAD_CRC
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_RX_LOC_STATE,
|
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);
|
(uint32_t)(SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE), 0x8000);
|
||||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_rx_restore: crc=%x\n",crc);
|
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: crc=%x\n"),crc);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,16 +229,24 @@ void shared_memory_irq_restore()
|
|||||||
|
|
||||||
void shared_memory_write(uint8_t cmd, uint8_t value)
|
void shared_memory_write(uint8_t cmd, uint8_t value)
|
||||||
{
|
{
|
||||||
|
#if DO_SHM
|
||||||
if (scratchpad_locked_tx)
|
#if DO_SHM_SCRATCHPAD
|
||||||
debug(DEBUG_SHM,"shared_memory_write: locked_tx\n");
|
if (scratchpad_locked_tx){
|
||||||
|
debug_P(DEBUG_SHM, PSTR("shared_memory_write: locked_tx\n"));
|
||||||
debug(DEBUG_SHM,"shared_memory_write: 0x%04x=0x%02x 0x%04x=0x%02x \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);
|
SHARED_MEM_TX_LOC_CMD, cmd, SHARED_MEM_TX_LOC_PAYLOAD, value);
|
||||||
|
|
||||||
sram_bulk_addr_save();
|
sram_bulk_addr_save();
|
||||||
|
|
||||||
|
#if (DO_SHM_SCRATCHPAD==0)
|
||||||
shared_memory_scratchpad_tx_save();
|
shared_memory_scratchpad_tx_save();
|
||||||
|
#endif
|
||||||
|
#if SHARED_MEM_SWITCH_IRQ
|
||||||
shared_memory_irq_hook();
|
shared_memory_irq_hook();
|
||||||
|
#endif
|
||||||
|
|
||||||
sram_write(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_SNES_ACK);
|
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_CMD, cmd);
|
||||||
@@ -216,10 +272,14 @@ void shared_memory_write(uint8_t cmd, uint8_t value)
|
|||||||
snes_lorom();
|
snes_lorom();
|
||||||
snes_wr_disable();
|
snes_wr_disable();
|
||||||
|
|
||||||
|
#if (DO_SHM_SCRATCHPAD==0)
|
||||||
shared_memory_scratchpad_tx_restore();
|
shared_memory_scratchpad_tx_restore();
|
||||||
|
#endif
|
||||||
|
#if SHARED_MEM_SWITCH_IRQ
|
||||||
shared_memory_irq_restore();
|
shared_memory_irq_restore();
|
||||||
//sram_bulk_addr_restore();
|
#endif
|
||||||
|
sram_bulk_addr_restore();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void shared_memory_yield()
|
void shared_memory_yield()
|
||||||
@@ -239,20 +299,24 @@ void shared_memory_yield()
|
|||||||
int shared_memory_read(uint8_t *cmd, uint8_t *len,uint8_t *buffer)
|
int shared_memory_read(uint8_t *cmd, uint8_t *len,uint8_t *buffer)
|
||||||
{
|
{
|
||||||
uint8_t state;
|
uint8_t state;
|
||||||
|
#if DO_SHM
|
||||||
if (scratchpad_locked_rx)
|
#if DO_SHM_SCRATCHPAD
|
||||||
debug(DEBUG_SHM,"shared_memory_write: locked_tx\n");
|
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);
|
state = sram_read(SHARED_MEM_RX_LOC_STATE);
|
||||||
if (state != SHARED_MEM_RX_AVR_ACK){
|
if (state != SHARED_MEM_RX_AVR_ACK){
|
||||||
|
sram_bulk_addr_restore();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
sram_bulk_addr_save();
|
|
||||||
|
|
||||||
*cmd = sram_read(SHARED_MEM_RX_LOC_CMD);
|
*cmd = sram_read(SHARED_MEM_RX_LOC_CMD);
|
||||||
*len = sram_read(SHARED_MEM_RX_LOC_LEN);
|
*len = sram_read(SHARED_MEM_RX_LOC_LEN);
|
||||||
debug(DEBUG_SHM,"shared_memory_read: 0x%04x=0x%02x 0x%04x=0x%02x \n",
|
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);
|
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_bulk_copy_into_buffer(SHARED_MEM_RX_LOC_PAYLOAD,buffer, *len);
|
||||||
@@ -276,5 +340,6 @@ int shared_memory_read(uint8_t *cmd, uint8_t *len,uint8_t *buffer)
|
|||||||
snes_lorom();
|
snes_lorom();
|
||||||
snes_wr_disable();
|
snes_wr_disable();
|
||||||
sram_bulk_addr_restore();
|
sram_bulk_addr_restore();
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
#define SHARED_MEM_TX_CMD_TERMINATE 0x06
|
#define SHARED_MEM_TX_CMD_TERMINATE 0x06
|
||||||
|
|
||||||
#define SHARED_MEM_TX_LOC_STATE 0x000000
|
#define SHARED_MEM_TX_LOC_STATE 0x000000
|
||||||
#define SHARED_MEM_TX_LOC_SIZE 0x000100
|
#define SHARED_MEM_TX_LOC_SIZE 0x000040
|
||||||
#define SHARED_MEM_TX_LOC_CMD 0x000001
|
#define SHARED_MEM_TX_LOC_CMD 0x000001
|
||||||
#define SHARED_MEM_TX_LOC_PAYLOAD 0x000002
|
#define SHARED_MEM_TX_LOC_PAYLOAD 0x000002
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
#define SHARED_MEM_RX_CMD_FILESEL 0x01
|
#define SHARED_MEM_RX_CMD_FILESEL 0x01
|
||||||
|
|
||||||
#define SHARED_MEM_RX_LOC_STATE 0x001000
|
#define SHARED_MEM_RX_LOC_STATE 0x001000
|
||||||
#define SHARED_MEM_RX_LOC_SIZE 0x000100
|
#define SHARED_MEM_RX_LOC_SIZE 0x000040
|
||||||
#define SHARED_MEM_RX_LOC_CMD 0x001001
|
#define SHARED_MEM_RX_LOC_CMD 0x001001
|
||||||
#define SHARED_MEM_RX_LOC_LEN 0x001002
|
#define SHARED_MEM_RX_LOC_LEN 0x001002
|
||||||
#define SHARED_MEM_RX_LOC_PAYLOAD 0x001003
|
#define SHARED_MEM_RX_LOC_PAYLOAD 0x001003
|
||||||
@@ -60,8 +60,11 @@
|
|||||||
#define SHARED_IRQ_HANDLER_LO 0x0ffe4
|
#define SHARED_IRQ_HANDLER_LO 0x0ffe4
|
||||||
#define SHARED_IRQ_HANDLER_HI 0x0ffe5
|
#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);
|
uint8_t shared_memory_scratchpad_region_save_helper(uint32_t addr);
|
||||||
void shared_memory_scratchpad_region_tx_save();
|
void shared_memory_scratchpad_region_tx_save();
|
||||||
void shared_memory_scratchpad_region_tx_restore();
|
void shared_memory_scratchpad_region_tx_restore();
|
||||||
|
|||||||
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
|
||||||
@@ -34,8 +34,7 @@
|
|||||||
uint32_t addr_current = 0;
|
uint32_t addr_current = 0;
|
||||||
uint32_t addr_stash = 0;
|
uint32_t addr_stash = 0;
|
||||||
|
|
||||||
|
void sram_init(void)
|
||||||
void system_init(void)
|
|
||||||
{
|
{
|
||||||
/*-------------------------------------------------*/
|
/*-------------------------------------------------*/
|
||||||
|
|
||||||
@@ -48,18 +47,17 @@ void system_init(void)
|
|||||||
| (1 << AVR_ADDR_SCK_PIN)
|
| (1 << AVR_ADDR_SCK_PIN)
|
||||||
| (1 << AVR_ADDR_SER_PIN)
|
| (1 << AVR_ADDR_SER_PIN)
|
||||||
| (1 << AVR_ADDR_LOAD_PIN)
|
| (1 << AVR_ADDR_LOAD_PIN)
|
||||||
| (1 << AVR_ADDR_DOWN_PIN)
|
| (1 << AVR_ADDR_UP_PIN));
|
||||||
| (1 << AVR_ADDR_UP_PIN));
|
|
||||||
|
|
||||||
DDRC &= ~ (1 << SNES_WR_PIN);
|
DDRC &= ~ ((1 << SNES_WR_PIN)
|
||||||
|
| (1 << AVR_BTLDR_EN_PIN));
|
||||||
|
|
||||||
PORTC &= ~((1 << AVR_ADDR_LATCH_PIN)
|
PORTC &= ~((1 << AVR_ADDR_LATCH_PIN)
|
||||||
| (1 << AVR_ADDR_SCK_PIN)
|
| (1 << AVR_ADDR_SCK_PIN)
|
||||||
| (1 << SNES_WR_PIN));
|
| (1 << SNES_WR_PIN));
|
||||||
|
|
||||||
|
|
||||||
PORTC |= ( (1 << AVR_ADDR_DOWN_PIN)
|
PORTC |= ( (1 << AVR_ADDR_UP_PIN)
|
||||||
| (1 << AVR_ADDR_UP_PIN)
|
|
||||||
| (1 << AVR_ADDR_LOAD_PIN));
|
| (1 << AVR_ADDR_LOAD_PIN));
|
||||||
|
|
||||||
//| (1 << SNES_WR_PIN));
|
//| (1 << SNES_WR_PIN));
|
||||||
@@ -93,23 +91,22 @@ void system_init(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void sreg_set(uint32_t addr)
|
void sreg_set(uint32_t addr)
|
||||||
{
|
{
|
||||||
uint8_t i = 24;
|
uint8_t i = 24;
|
||||||
debug(DEBUG_SREG,"sreg_set: addr=0x%08lx",addr);
|
debug_P(DEBUG_SREG, PSTR("sreg_set: addr=0x%08lx"),addr);
|
||||||
while(i--) {
|
while(i--) {
|
||||||
if ((addr & ( 1L << i))){
|
if ((addr & ( 1L << i))){
|
||||||
debug(DEBUG_SREG,"1");
|
debug_P(DEBUG_SREG, PSTR("1"));
|
||||||
AVR_ADDR_SER_PORT |= ( 1 << AVR_ADDR_SER_PIN);
|
AVR_ADDR_SER_PORT |= ( 1 << AVR_ADDR_SER_PIN);
|
||||||
} else {
|
} else {
|
||||||
AVR_ADDR_SER_PORT &= ~( 1 << AVR_ADDR_SER_PIN);
|
AVR_ADDR_SER_PORT &= ~( 1 << AVR_ADDR_SER_PIN);
|
||||||
debug(DEBUG_SREG,"0");
|
debug_P(DEBUG_SREG, PSTR("0"));
|
||||||
}
|
}
|
||||||
AVR_ADDR_SCK_PORT |= (1 << AVR_ADDR_SCK_PIN);
|
AVR_ADDR_SCK_PORT |= (1 << AVR_ADDR_SCK_PIN);
|
||||||
AVR_ADDR_SCK_PORT &= ~(1 << AVR_ADDR_SCK_PIN);
|
AVR_ADDR_SCK_PORT &= ~(1 << AVR_ADDR_SCK_PIN);
|
||||||
}
|
}
|
||||||
debug(DEBUG_SREG,"\n");
|
debug_P(DEBUG_SREG, PSTR("\n"));
|
||||||
AVR_ADDR_LATCH_PORT |= (1 << AVR_ADDR_LATCH_PIN);
|
AVR_ADDR_LATCH_PORT |= (1 << AVR_ADDR_LATCH_PIN);
|
||||||
AVR_ADDR_LATCH_PORT &= ~(1 << AVR_ADDR_LATCH_PIN);
|
AVR_ADDR_LATCH_PORT &= ~(1 << AVR_ADDR_LATCH_PIN);
|
||||||
|
|
||||||
@@ -117,20 +114,22 @@ void sreg_set(uint32_t addr)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void sram_bulk_addr_save()
|
void sram_bulk_addr_save()
|
||||||
{
|
{
|
||||||
addr_stash = addr_current;
|
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()
|
inline void sram_bulk_addr_restore()
|
||||||
{
|
{
|
||||||
sreg_set(addr_stash);
|
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)
|
void sram_bulk_read_start(uint32_t addr)
|
||||||
{
|
{
|
||||||
debug(DEBUG_SRAM,"sram_bulk_read_start: addr=0x%08lx\n\r", addr);
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_read_start: addr=0x%08lx\n\r"), addr);
|
||||||
|
|
||||||
addr_current = addr;
|
addr_current = addr;
|
||||||
|
|
||||||
@@ -176,7 +175,7 @@ inline uint8_t sram_bulk_read(void)
|
|||||||
|
|
||||||
void sram_bulk_read_end(void)
|
void sram_bulk_read_end(void)
|
||||||
{
|
{
|
||||||
debug(DEBUG_SRAM,"sram_bulk_read_end:\n");
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_read_end:\n"));
|
||||||
|
|
||||||
AVR_RD_PORT |= (1 << AVR_RD_PIN);
|
AVR_RD_PORT |= (1 << AVR_RD_PIN);
|
||||||
AVR_CS_PORT |= (1 << AVR_CS_PIN);
|
AVR_CS_PORT |= (1 << AVR_CS_PIN);
|
||||||
@@ -186,7 +185,7 @@ void sram_bulk_read_end(void)
|
|||||||
uint8_t sram_read(uint32_t addr)
|
uint8_t sram_read(uint32_t addr)
|
||||||
{
|
{
|
||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
debug(DEBUG_SRAM_RAW,"sram_read: addr=0x%08lx\n\r", addr);
|
debug_P(DEBUG_SRAM_RAW, PSTR("sram_read: addr=0x%08lx\n\r"), addr);
|
||||||
|
|
||||||
avr_data_in();
|
avr_data_in();
|
||||||
|
|
||||||
@@ -216,9 +215,16 @@ uint8_t sram_read(uint32_t addr)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
void sram_bulk_write_start(uint32_t addr)
|
||||||
{
|
{
|
||||||
debug(DEBUG_SRAM,"sram_bulk_write_start: addr=0x%08lx\n\r", addr);
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_write_start: addr=0x%08lx\n\r"), addr);
|
||||||
|
addr_current = addr;
|
||||||
|
|
||||||
avr_data_out();
|
avr_data_out();
|
||||||
|
|
||||||
@@ -228,25 +234,25 @@ void sram_bulk_write_start(uint32_t addr)
|
|||||||
|
|
||||||
sreg_set(addr);
|
sreg_set(addr);
|
||||||
|
|
||||||
AVR_WR_PORT &= ~(1 << AVR_WR_PIN);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void sram_bulk_write_next(void)
|
inline void sram_bulk_write_next(void)
|
||||||
{
|
{
|
||||||
AVR_WR_PORT |= (1 << AVR_WR_PIN);
|
|
||||||
counter_up();
|
|
||||||
AVR_WR_PORT &= ~(1 << AVR_WR_PIN);
|
AVR_WR_PORT &= ~(1 << AVR_WR_PIN);
|
||||||
|
addr_current++;
|
||||||
|
counter_up();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void sram_bulk_write( uint8_t data)
|
inline void sram_bulk_write( uint8_t data)
|
||||||
{
|
{
|
||||||
|
AVR_WR_PORT &= ~(1 << AVR_WR_PIN);
|
||||||
AVR_DATA_PORT = data;
|
AVR_DATA_PORT = data;
|
||||||
}
|
AVR_WR_PORT |= (1 << AVR_WR_PIN);
|
||||||
|
}
|
||||||
|
|
||||||
void sram_bulk_write_end(void)
|
void sram_bulk_write_end(void)
|
||||||
{
|
{
|
||||||
debug(DEBUG_SRAM,"sram_bulk_write_end:");
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_write_end:"));
|
||||||
AVR_WR_PORT |= (1 << AVR_WR_PIN);
|
AVR_WR_PORT |= (1 << AVR_WR_PIN);
|
||||||
AVR_CS_PORT |= (1 << AVR_CS_PIN);
|
AVR_CS_PORT |= (1 << AVR_CS_PIN);
|
||||||
avr_data_in();
|
avr_data_in();
|
||||||
@@ -255,7 +261,7 @@ void sram_bulk_write_end(void)
|
|||||||
|
|
||||||
void sram_write(uint32_t addr, uint8_t data)
|
void sram_write(uint32_t addr, uint8_t data)
|
||||||
{
|
{
|
||||||
debug(DEBUG_SRAM_RAW,"sram_write: addr=0x%08lx data=%x\n\r", addr, data);
|
debug_P(DEBUG_SRAM_RAW, PSTR("sram_write: addr=0x%08lx data=%x\n\r"), addr, data);
|
||||||
|
|
||||||
avr_data_out();
|
avr_data_out();
|
||||||
|
|
||||||
@@ -289,12 +295,15 @@ void sram_bulk_copy_from_buffer(uint32_t addr, uint8_t * src, uint32_t len)
|
|||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint8_t *ptr = src;
|
uint8_t *ptr = src;
|
||||||
debug(DEBUG_SRAM,"sram_bulk_copy_from_buffer: addr=0x%08lx src=0x%p len=%li\n\r",
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_copy_from_buffer: addr=0x%08lx src=0x%p len=%li\n\r"),
|
||||||
addr, src, len);
|
addr, src, len);
|
||||||
sram_bulk_write_start(addr);
|
sram_bulk_write_start(addr);
|
||||||
for (i = addr; i < (addr + len); i++){
|
for (i = addr; i < (addr + len); i++){
|
||||||
sram_bulk_write(*ptr++);
|
sram_bulk_write(*ptr);
|
||||||
sram_bulk_write_next();
|
//hack
|
||||||
|
if ((i+1) < (addr + len))
|
||||||
|
sram_bulk_write_next();
|
||||||
|
ptr++;
|
||||||
}
|
}
|
||||||
sram_bulk_write_end();
|
sram_bulk_write_end();
|
||||||
}
|
}
|
||||||
@@ -304,24 +313,23 @@ void sram_bulk_copy_into_buffer(uint32_t addr, uint8_t * dst, uint32_t len)
|
|||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint8_t *ptr = dst;
|
uint8_t *ptr = dst;
|
||||||
debug(DEBUG_SRAM,"sram_bulk_copy_into_buffer: addr=0x%08lx dst=0x%p len=%li\n\r",
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_copy_into_buffer: addr=0x%08lx dst=0x%p len=%li\n\r"),
|
||||||
addr, dst, len);
|
addr, dst, len);
|
||||||
sram_bulk_read_start(addr);
|
sram_bulk_read_start(addr);
|
||||||
for (i = addr; i < (addr + len); i++) {
|
for (i = addr; i < (addr + len); i++) {
|
||||||
*ptr = sram_bulk_read();
|
dst[i] = sram_bulk_read();
|
||||||
sram_bulk_read_next();
|
sram_bulk_read_next();
|
||||||
ptr++;
|
|
||||||
}
|
}
|
||||||
sram_bulk_read_end();
|
sram_bulk_read_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sram_bulk_set(uint32_t addr, uint32_t len,uint8_t value){
|
void sram_bulk_set(uint32_t addr, uint32_t len,uint8_t value){
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
debug(DEBUG_SRAM,"sram_bulk_set: addr=0x%08lx len=%li\n\r", addr,len);
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_set: addr=0x%08lx len=%li\n\r"), addr,len);
|
||||||
sram_bulk_write_start(addr);
|
sram_bulk_write_start(addr);
|
||||||
for (i = addr; i < (addr + len); i++) {
|
for (i = addr; i < (addr + len); i++) {
|
||||||
if (0 == i % 0xfff)
|
if (0 == i % 0xfff)
|
||||||
debug(DEBUG_SRAM,"sram_bulk_set: addr=0x%08lx\n\r", i);
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_set: addr=0x%08lx\n\r"), i);
|
||||||
sram_bulk_write(value);
|
sram_bulk_write(value);
|
||||||
sram_bulk_write_next();
|
sram_bulk_write_next();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,14 +40,6 @@
|
|||||||
|
|
||||||
#define avr_data_out() (AVR_DATA_DIR = 0xff)
|
#define avr_data_out() (AVR_DATA_DIR = 0xff)
|
||||||
|
|
||||||
#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)))
|
|
||||||
|
|
||||||
/* ---------------------------- PORT B ---------------------------- */
|
/* ---------------------------- PORT B ---------------------------- */
|
||||||
|
|
||||||
@@ -85,17 +77,6 @@
|
|||||||
#define snes_irq_off() (SNES_IRQ_DIR &= ~(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))
|
#define snes_irq_lo() (SNES_IRQ_PORT &= ~(1 << SNES_IRQ_PIN))
|
||||||
|
|
||||||
#define SNES_RESET_PORT PORTB
|
|
||||||
#define SNES_RESET_DIR DDRB
|
|
||||||
#define SNES_RESET_PIN PB4
|
|
||||||
|
|
||||||
|
|
||||||
#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))
|
|
||||||
|
|
||||||
|
|
||||||
/* ---------------------------- PORT C ---------------------------- */
|
/* ---------------------------- PORT C ---------------------------- */
|
||||||
|
|
||||||
@@ -105,22 +86,22 @@
|
|||||||
#define AVR_ADDR_LATCH_DIR DDRC
|
#define AVR_ADDR_LATCH_DIR DDRC
|
||||||
#define AVR_ADDR_LATCH_PIN PC6
|
#define AVR_ADDR_LATCH_PIN PC6
|
||||||
|
|
||||||
#define avr_addr_latch_hi() (AVR_ADDR_LATCH_PORT |= (1 << AVR_ADDR_LATCH_PIN)))
|
#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_latch_lo() (AVR_ADDR_LATCH_PORT &= ~(1 << AVR_ADDR_LATCH_PIN))
|
||||||
|
|
||||||
#define AVR_ADDR_SCK_PORT PORTC
|
#define AVR_ADDR_SCK_PORT PORTC
|
||||||
#define AVR_ADDR_SCK_DIR DDRC
|
#define AVR_ADDR_SCK_DIR DDRC
|
||||||
#define AVR_ADDR_SCK_PIN PC5
|
#define AVR_ADDR_SCK_PIN PC5
|
||||||
|
|
||||||
#define avr_addr_sck_hi() (AVR_ADDR_SCK_PORT |= (1 << AVR_ADDR_SCK_PIN)))
|
#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_sck_lo() (AVR_ADDR_SCK_PORT &= ~(1 << AVR_ADDR_SCK_PIN))
|
||||||
|
|
||||||
#define AVR_ADDR_SER_PORT PORTC
|
#define AVR_ADDR_SER_PORT PORTC
|
||||||
#define AVR_ADDR_SER_DIR DDRC
|
#define AVR_ADDR_SER_DIR DDRC
|
||||||
#define AVR_ADDR_SER_PIN PC4
|
#define AVR_ADDR_SER_PIN PC4
|
||||||
|
|
||||||
#define avr_addr_ser_hi() (AVR_ADDR_SER_PORT |= (1 << AVR_ADDR_SER_PIN)))
|
#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_ser_lo() (AVR_ADDR_SER_PORT &= ~(1 << AVR_ADDR_SER_PIN))
|
||||||
|
|
||||||
#define AVR_ADDR_LOAD_PORT PORTC
|
#define AVR_ADDR_LOAD_PORT PORTC
|
||||||
#define AVR_ADDR_LOAD_DIR DDRC
|
#define AVR_ADDR_LOAD_DIR DDRC
|
||||||
@@ -129,12 +110,12 @@
|
|||||||
#define counter_load() ((AVR_ADDR_LOAD_PORT &= ~(1 << AVR_ADDR_LOAD_PIN)),\
|
#define counter_load() ((AVR_ADDR_LOAD_PORT &= ~(1 << AVR_ADDR_LOAD_PIN)),\
|
||||||
(AVR_ADDR_LOAD_PORT |= (1 << AVR_ADDR_LOAD_PIN)))
|
(AVR_ADDR_LOAD_PORT |= (1 << AVR_ADDR_LOAD_PIN)))
|
||||||
|
|
||||||
#define AVR_ADDR_DOWN_PORT PORTC
|
#define AVR_BTLDR_EN_PORT PORTC
|
||||||
#define AVR_ADDR_DOWN_DIR DDRC
|
#define AVR_BTLDR_EN_DIR DDRC
|
||||||
#define AVR_ADDR_DOWN_PIN PC1
|
#define AVR_BTLDR_EN_PIN PC1
|
||||||
|
|
||||||
#define counter_down() ((AVR_ADDR_DOWN_PORT &= ~(1 << AVR_ADDR_DOWN_PIN)),\
|
#define btldr_down() ((AVR_BTLDR_EN_PORT &= ~(1 << AVR_BTLDR_EN_PIN)),\
|
||||||
(AVR_ADDR_DOWN_PORT |= (1 << AVR_ADDR_DOWN_PIN)))
|
(AVR_BTLDR_EN_PORT |= (1 << AVR_BTLDR_EN_PIN)))
|
||||||
|
|
||||||
#define AVR_ADDR_UP_PORT PORTC
|
#define AVR_ADDR_UP_PORT PORTC
|
||||||
#define AVR_ADDR_UP_DIR DDRC
|
#define AVR_ADDR_UP_DIR DDRC
|
||||||
@@ -147,6 +128,18 @@
|
|||||||
#define SNES_WR_DIR DDRC
|
#define SNES_WR_DIR DDRC
|
||||||
#define SNES_WR_PIN PC3
|
#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 ---------------------------- */
|
/* ---------------------------- PORT D ---------------------------- */
|
||||||
|
|
||||||
#define AVR_SNES_PORT PORTD
|
#define AVR_SNES_PORT PORTD
|
||||||
@@ -160,7 +153,8 @@
|
|||||||
(AVR_CS_DIR |= (1 << AVR_CS_PIN)))
|
(AVR_CS_DIR |= (1 << AVR_CS_PIN)))
|
||||||
|
|
||||||
#define snes_bus_active() ((AVR_SNES_SW_PORT |= (1 << AVR_SNES_SW_PIN)),\
|
#define snes_bus_active() ((AVR_SNES_SW_PORT |= (1 << AVR_SNES_SW_PIN)),\
|
||||||
(AVR_CS_DIR &= ~(1 << AVR_CS_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_PORT PORTD
|
||||||
#define HI_LOROM_SW_DIR DDRD
|
#define HI_LOROM_SW_DIR DDRD
|
||||||
@@ -177,11 +171,32 @@
|
|||||||
|
|
||||||
#define snes_wr_enable() (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 system_init(void);
|
|
||||||
|
void sram_init(void);
|
||||||
void sreg_set(uint32_t addr);
|
void sreg_set(uint32_t addr);
|
||||||
|
|
||||||
uint8_t sram_read(uint32_t addr);
|
uint8_t sram_read(uint32_t addr);
|
||||||
@@ -191,6 +206,7 @@ void sram_bulk_read_start(uint32_t addr);
|
|||||||
inline void sram_bulk_read_next(void);
|
inline void sram_bulk_read_next(void);
|
||||||
inline void sram_bulk_read_end(void);
|
inline void sram_bulk_read_end(void);
|
||||||
uint8_t sram_bulk_read(void);
|
uint8_t sram_bulk_read(void);
|
||||||
|
uint16_t sram_read16_be(uint32_t addr);
|
||||||
|
|
||||||
void sram_bulk_write_start(uint32_t addr);
|
void sram_bulk_write_start(uint32_t addr);
|
||||||
inline void sram_bulk_write_next(void);
|
inline void sram_bulk_write_next(void);
|
||||||
|
|||||||
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
|
||||||
1556
avr/usbload/tags
1556
avr/usbload/tags
File diff suppressed because it is too large
Load Diff
@@ -31,6 +31,7 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
|
#include "dump.h"
|
||||||
|
|
||||||
void test_read_write()
|
void test_read_write()
|
||||||
{
|
{
|
||||||
@@ -45,7 +46,7 @@ void test_read_write()
|
|||||||
}
|
}
|
||||||
addr = 0x000000;
|
addr = 0x000000;
|
||||||
while (addr++ <= 0x0000ff) {
|
while (addr++ <= 0x0000ff) {
|
||||||
info("read addr=0x%08lx %x\n", addr, sram_read(addr));
|
info_P(PSTR("read addr=0x%08lx %x\n"), addr, sram_read(addr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +70,7 @@ void test_bulk_read_write()
|
|||||||
addr = 0x000000;
|
addr = 0x000000;
|
||||||
sram_bulk_read_start(addr);
|
sram_bulk_read_start(addr);
|
||||||
while (addr <= 0x8000) {
|
while (addr <= 0x8000) {
|
||||||
info("addr=0x%08lx %x\n", addr, sram_bulk_read());
|
info_P(PSTR("addr=0x%08lx %x\n"), addr, sram_bulk_read());
|
||||||
sram_bulk_read_next();
|
sram_bulk_read_next();
|
||||||
addr++;
|
addr++;
|
||||||
}
|
}
|
||||||
@@ -85,22 +86,46 @@ void test_non_zero_memory(uint32_t bottom_addr, uint32_t top_addr)
|
|||||||
for (addr = bottom_addr; addr < top_addr; addr++) {
|
for (addr = bottom_addr; addr < top_addr; addr++) {
|
||||||
c = sram_bulk_read();
|
c = sram_bulk_read();
|
||||||
if (c != 0xff)
|
if (c != 0xff)
|
||||||
info("addr=0x%08lx c=0x%x\n", addr, c);
|
info_P(PSTR("addr=0x%08lx c=0x%x\n"), addr, c);
|
||||||
sram_bulk_read_next();
|
sram_bulk_read_next();
|
||||||
}
|
}
|
||||||
sram_bulk_read_end();
|
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()
|
void test_crc()
|
||||||
{
|
{
|
||||||
info("test_crc: clear\n");
|
info_P(PSTR("test_crc: clear\n"));
|
||||||
avr_bus_active();
|
avr_bus_active();
|
||||||
sram_bulk_set(0x000000, 0x10000, 0xff);
|
sram_bulk_set(0x000000, 0x10000, 0xff);
|
||||||
info("test_crc: crc\n");
|
info_P(PSTR("test_crc: crc\n"));
|
||||||
crc_check_bulk_memory(0x000000, 0x10000, 0x8000);
|
crc_check_bulk_memory(0x000000, 0x10000, 0x8000);
|
||||||
info("test_crc: check\n");
|
info_P(PSTR("test_crc: check\n"));
|
||||||
test_non_zero_memory(0x000000, 0x10000);
|
test_non_zero_memory(0x000000, 0x10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,11 @@
|
|||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
|
#include "sram.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern uint8_t snes_reset_line;
|
||||||
|
|
||||||
#ifndef OCR1A
|
#ifndef OCR1A
|
||||||
#define OCR1A OCR1 // 2313 support
|
#define OCR1A OCR1 // 2313 support
|
||||||
#endif
|
#endif
|
||||||
@@ -52,6 +56,7 @@ uint16_t volatile second; // count seconds
|
|||||||
|
|
||||||
ISR (SIG_OUTPUT_COMPARE1A)
|
ISR (SIG_OUTPUT_COMPARE1A)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
#if XTAL % DEBOUNCE // bei rest
|
#if XTAL % DEBOUNCE // bei rest
|
||||||
OCR1A = 20000000UL / DEBOUNCE - 1; // compare DEBOUNCE - 1 times
|
OCR1A = 20000000UL / DEBOUNCE - 1; // compare DEBOUNCE - 1 times
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "fifo.h"
|
#include "fifo.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
volatile struct {
|
volatile struct {
|
||||||
uint8_t tmr_int:1;
|
uint8_t tmr_int:1;
|
||||||
uint8_t adc_int:1;
|
uint8_t adc_int:1;
|
||||||
@@ -35,6 +37,9 @@ volatile struct {
|
|||||||
volatile char rxbuff;
|
volatile char rxbuff;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int uart_stream(char c, FILE *stream);
|
||||||
|
|
||||||
FILE uart_stdout = FDEV_SETUP_STREAM(uart_stream, NULL, _FDEV_SETUP_WRITE);
|
FILE uart_stdout = FDEV_SETUP_STREAM(uart_stream, NULL, _FDEV_SETUP_WRITE);
|
||||||
|
|
||||||
void uart_init(void)
|
void uart_init(void)
|
||||||
@@ -47,7 +52,7 @@ void uart_init(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
ISR(USART0_RX_vect)
|
ISR(USART0_RX_vect)
|
||||||
{
|
{
|
||||||
uint8_t c;
|
uint8_t c;
|
||||||
@@ -57,7 +62,7 @@ ISR(USART0_RX_vect)
|
|||||||
intflags.rx_int = 1;
|
intflags.rx_int = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void uart_putc(uint8_t c)
|
void uart_putc(uint8_t c)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ void uart_init(void);
|
|||||||
void uart_putc(const uint8_t);
|
void uart_putc(const uint8_t);
|
||||||
void uart_puts(const char *s);
|
void uart_puts(const char *s);
|
||||||
void uart_puts_P(PGM_P s);
|
void uart_puts_P(PGM_P s);
|
||||||
static int uart_stream(char c, FILE *stream);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -39,32 +39,24 @@
|
|||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
#include "usb_bulk.h"
|
#include "usb_bulk.h"
|
||||||
|
|
||||||
extern uint8_t read_buffer[TRANSFER_BUFFER_SIZE];
|
|
||||||
extern uint32_t req_addr;
|
extern usb_transaction_t usb_trans;
|
||||||
extern uint32_t req_size;
|
|
||||||
extern uint8_t req_bank;
|
|
||||||
extern uint32_t req_bank_size;
|
|
||||||
extern uint8_t req_state;
|
|
||||||
extern uint8_t rx_remaining;
|
|
||||||
extern uint8_t tx_remaining;
|
|
||||||
extern uint8_t tx_buffer[32];
|
|
||||||
extern uint16_t crc;
|
|
||||||
|
|
||||||
uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
|
uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
|
||||||
{
|
{
|
||||||
uint8_t *ptr;
|
uint8_t *ptr;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
if (len > rx_remaining) {
|
if (len > usb_trans.rx_remaining) {
|
||||||
info("ERROR:usbFunctionWrite more data than expected remain: %i len: %i\n",
|
info_P(PSTR("ERROR:usbFunctionWrite more data than expected remain: %i len: %i\n"),
|
||||||
rx_remaining, len);
|
usb_trans.rx_remaining, len);
|
||||||
len = rx_remaining;
|
len = usb_trans.rx_remaining;
|
||||||
}
|
}
|
||||||
if (req_state == REQ_STATUS_BULK_UPLOAD) {
|
if (usb_trans.req_state == REQ_STATUS_BULK_UPLOAD) {
|
||||||
|
|
||||||
rx_remaining -= len;
|
usb_trans.rx_remaining -= len;
|
||||||
debug(DEBUG_USB_TRANS,"usbFunctionWrite REQ_STATUS_BULK_UPLOAD addr: 0x%08lx len: %i rx_remaining=%i\n",
|
debug_P(DEBUG_USB_TRANS, PSTR("usbFunctionWrite REQ_STATUS_BULK_UPLOAD addr: 0x%08lx len: %i rx_remaining=%i\n"),
|
||||||
req_addr, len, rx_remaining);
|
usb_trans.req_addr, len, usb_trans.rx_remaining);
|
||||||
ptr = data;
|
ptr = data;
|
||||||
i = len;
|
i = len;
|
||||||
while(i--){
|
while(i--){
|
||||||
@@ -78,13 +70,13 @@ uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
|
|||||||
uint8_t usbFunctionRead(uint8_t * data, uint8_t len)
|
uint8_t usbFunctionRead(uint8_t * data, uint8_t len)
|
||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
if (len > tx_remaining)
|
if (len > usb_trans.tx_remaining)
|
||||||
len = tx_remaining;
|
len = usb_trans.tx_remaining;
|
||||||
tx_remaining -= len;
|
usb_trans.tx_remaining -= len;
|
||||||
debug(DEBUG_USB_TRANS,"usbFunctionRead len=%i tx_remaining=%i \n", len, tx_remaining);
|
debug_P(DEBUG_USB_TRANS, PSTR("usbFunctionRead len=%i tx_remaining=%i \n"), len, usb_trans.tx_remaining);
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
*data = tx_buffer[len];
|
*data = usb_trans.tx_buffer[len];
|
||||||
data++;
|
data++;
|
||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
|
|||||||
@@ -127,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 200
|
#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.
|
||||||
@@ -248,7 +248,6 @@ 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 'S', 'N', 'E', 'S', 'R', 'A', 'M'
|
|
||||||
#define USB_CFG_DEVICE_NAME 'Q', 'U', 'I', 'C', 'K', 'D', 'E', 'V', '1', '6'
|
#define USB_CFG_DEVICE_NAME 'Q', 'U', 'I', 'C', 'K', 'D', 'E', 'V', '1', '6'
|
||||||
#define USB_CFG_DEVICE_NAME_LEN 10
|
#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
|
||||||
|
|||||||
132
avr/usbload/util.c
Normal file
132
avr/usbload/util.c
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
uint8_t *util_strupper(uint8_t *s)
|
||||||
|
{
|
||||||
|
uint8_t *p;
|
||||||
|
for (p = s; *p != '\0'; p++)
|
||||||
|
if (*p >= 'a' && *p <= 'z')
|
||||||
|
*p += 'A' - 'a';
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t *util_strlower(uint8_t *s)
|
||||||
|
{
|
||||||
|
uint8_t *p;
|
||||||
|
for (p = s; *p != '\0'; p++)
|
||||||
|
if (*p >= 'A' && *p <= 'Z')
|
||||||
|
*p += 'a' - 'A';
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void util_chomp(uint8_t *s)
|
||||||
|
{
|
||||||
|
uint16_t len;
|
||||||
|
|
||||||
|
len = strlen((char*)s);
|
||||||
|
if (len >= 2 && s[len - 1] == '\n' && s[len - 2] == '\r')
|
||||||
|
s[len - 2] = '\0';
|
||||||
|
else if (len >= 1 && (s[len - 1] == '\n' || s[len - 1] == '\r'))
|
||||||
|
s[len - 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
void util_trim(uint8_t *s)
|
||||||
|
{
|
||||||
|
uint8_t *p = s;
|
||||||
|
uint8_t *q;
|
||||||
|
/* skip leading whitespace */
|
||||||
|
while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n')
|
||||||
|
p++;
|
||||||
|
/* now p points at the first non-whitespace uint8_tacter */
|
||||||
|
|
||||||
|
if (*p == '\0') {
|
||||||
|
/* only whitespace */
|
||||||
|
*s = '\0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
q = s + strlen((char*)s);
|
||||||
|
/* skip trailing whitespace */
|
||||||
|
/* we have found p < q such that *p is non-whitespace,
|
||||||
|
so this loop terminates with q >= p */
|
||||||
|
do
|
||||||
|
q--;
|
||||||
|
while (*q == ' ' || *q == '\t' || *q == '\r' || *q == '\n');
|
||||||
|
|
||||||
|
/* now q points at the last non-whitespace uint8_tacter */
|
||||||
|
/* cut off trailing whitespace */
|
||||||
|
*++q = '\0';
|
||||||
|
|
||||||
|
/* move to string */
|
||||||
|
memmove(s, p, q + 1 - p);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t util_sscandec(const uint8_t *s)
|
||||||
|
{
|
||||||
|
uint32_t result;
|
||||||
|
if (*s == '\0')
|
||||||
|
return -1;
|
||||||
|
result = 0;
|
||||||
|
for (;;) {
|
||||||
|
if (*s >= '0' && *s <= '9')
|
||||||
|
result = 10 * result + *s - '0';
|
||||||
|
else if (*s == '\0')
|
||||||
|
return result;
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t util_sscanhex(const uint8_t *s)
|
||||||
|
{
|
||||||
|
int32_t result;
|
||||||
|
if (*s == '\0')
|
||||||
|
return -1;
|
||||||
|
result = 0;
|
||||||
|
for (;;) {
|
||||||
|
if (*s >= '0' && *s <= '9')
|
||||||
|
result = 16 * result + *s - '0';
|
||||||
|
else if (*s >= 'A' && *s <= 'F')
|
||||||
|
result = 16 * result + *s - 'A' + 10;
|
||||||
|
else if (*s >= 'a' && *s <= 'f')
|
||||||
|
result = 16 * result + *s - 'a' + 10;
|
||||||
|
else if (*s == '\0')
|
||||||
|
return result;
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t util_sscanbool(const uint8_t *s)
|
||||||
|
{
|
||||||
|
if (*s == '0' && s[1] == '\0')
|
||||||
|
return 0;
|
||||||
|
if (*s == '1' && s[1] == '\0')
|
||||||
|
return 1;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
32
avr/usbload/util.h
Normal file
32
avr/usbload/util.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* ________ .__ __ ________ ____ ________
|
||||||
|
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
|
||||||
|
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
|
||||||
|
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
|
||||||
|
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
|
||||||
|
* \__> \/ \/ \/ \/ \/
|
||||||
|
*
|
||||||
|
* www.optixx.org
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Version: 1.0
|
||||||
|
* Created: 07/21/2009 03:32:16 PM
|
||||||
|
* Author: david@optixx.org
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __UTIL_H__
|
||||||
|
#define __UTIL_H__
|
||||||
|
|
||||||
|
uint8_t *util_strupper(uint8_t *s);
|
||||||
|
uint8_t *util_strlower(uint8_t *s);
|
||||||
|
void util_chomp(uint8_t *s);
|
||||||
|
void util_trim(uint8_t *s);
|
||||||
|
uint32_t util_sscandec(const uint8_t *s);
|
||||||
|
uint32_t util_sscanhex(const uint8_t *s);
|
||||||
|
uint8_t util_sscanbool(const uint8_t *s);
|
||||||
|
|
||||||
|
#endif
|
||||||
10
done.txt
Normal file
10
done.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
x 2009-10-13 Send PCB to seeed
|
||||||
|
x 2009-10-13 RS232 cable add programm header and sio lines
|
||||||
|
x 2009-10-13 Assemble No. 006 & No. 007
|
||||||
|
x 2009-10-13 Flash all cartridge with latest firmware and bootloader
|
||||||
|
x 2009-10-13 Bootloader lockbits
|
||||||
|
x 2009-10-13 Rework No. 002
|
||||||
|
x 2009-10-13 Package for Quickdev16
|
||||||
|
x 2009-10-13 Add struct for usb and communcations flags
|
||||||
|
x 2009-10-13 Mail snega2usb about OEM
|
||||||
|
x 2009-10-13 Email to seeed about the retour package
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user