Merge branch 'progmem'
Conflicts: avr/usbload/rle.c
This commit is contained in:
commit
68b882acfb
@ -34,7 +34,7 @@ extern uint32_t req_bank_size;
|
||||
|
||||
void send_reset()
|
||||
{
|
||||
info("Reset SNES\n");
|
||||
info_P(PSTR("Reset SNES\n"));
|
||||
cli();
|
||||
snes_reset_on();
|
||||
snes_reset_lo();
|
||||
@ -57,9 +57,9 @@ void set_rom_mode()
|
||||
{
|
||||
if (req_bank_size == 0x8000) {
|
||||
snes_lorom();
|
||||
info("Set SNES lowrom \n");
|
||||
info_P(PSTR("Set SNES lowrom \n"));
|
||||
} else {
|
||||
snes_hirom();
|
||||
info("Set SNES hirom \n");
|
||||
info_P(PSTR("Set SNES hirom \n"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@
|
||||
#define USB_CRC_CHECK 0x01
|
||||
|
||||
#define TRANSFER_BUFFER_SIZE 0x200
|
||||
|
||||
#define FORMAT_BUFFER_LEN 0x0FF
|
||||
#define HW_VERSION "2.6"
|
||||
#define SW_VERSION "1.0"
|
||||
|
||||
|
||||
@ -71,12 +71,12 @@ uint16_t crc_check_bulk_memory(uint32_t bottom_addr, uint32_t top_addr, uint32_t
|
||||
uint32_t addr = 0;
|
||||
uint8_t req_bank = 0;
|
||||
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);
|
||||
|
||||
for (addr = bottom_addr; addr < top_addr; addr++) {
|
||||
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++;
|
||||
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();
|
||||
}
|
||||
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);
|
||||
sram_bulk_read_end();
|
||||
return crc;
|
||||
|
||||
@ -20,11 +20,11 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
#include "debug.h"
|
||||
#include "uart.h"
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
extern FILE uart_stdout;
|
||||
|
||||
@ -46,4 +46,23 @@ void debug(int level, char* format, ...) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NO_INFO
|
||||
uint8_t buffer_debug[FORMAT_BUFFER_LEN];
|
||||
#endif
|
||||
|
||||
#if defined(NO_DEBUG) && defined(__GNUC__)
|
||||
#else
|
||||
void debug_P(int level, PGM_P format, ...) {
|
||||
#ifdef NO_DEBUG
|
||||
|
||||
#else
|
||||
va_list args;
|
||||
if (!(debug_level & level))
|
||||
return;
|
||||
strlcpy_P(buffer_debug,format,FORMAT_BUFFER_LEN);
|
||||
va_start(args, format);
|
||||
vprintf(buffer_debug, args);
|
||||
va_end(args);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@ -26,7 +26,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
#if defined(NO_DEBUG) && defined(__GNUC__)
|
||||
/* gcc's cpp has extensions; it allows for macros with a variable number of
|
||||
@ -39,5 +39,17 @@ void debug(int level, char *format, ...);
|
||||
#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 */
|
||||
|
||||
|
||||
@ -47,21 +47,21 @@ void dump_packet(uint32_t addr, uint32_t len, uint8_t * packet)
|
||||
continue;
|
||||
}
|
||||
if (clear) {
|
||||
info("*\n");
|
||||
info_P(PSTR("*\n"));
|
||||
clear = 0;
|
||||
}
|
||||
info("%08lx:", addr + i);
|
||||
info_P(PSTR("%08lx:"), addr + i);
|
||||
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++) {
|
||||
if (packet[i + j] >= 33 && packet[i + j] <= 126)
|
||||
info("%c", packet[i + j]);
|
||||
info_P(PSTR("%c"), packet[i + j]);
|
||||
else
|
||||
info(".");
|
||||
info_P(PSTR("."));
|
||||
}
|
||||
info("|\n");
|
||||
info_P(PSTR("|\n"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,11 +72,11 @@ void dump_memory(uint32_t bottom_addr, uint32_t top_addr)
|
||||
sram_bulk_read_start(bottom_addr);
|
||||
for ( addr = bottom_addr; addr < top_addr; addr++) {
|
||||
if (addr%0x10 == 0)
|
||||
info("\n%08lx:", addr);
|
||||
info_P(PSTR("\n%08lx:"), addr);
|
||||
byte = sram_bulk_read();
|
||||
sram_bulk_read_next();
|
||||
info(" %02x", byte);
|
||||
info_P(PSTR(" %02x"), byte);
|
||||
}
|
||||
info("\n");
|
||||
info_P(PSTR("\n"));
|
||||
sram_bulk_read_end();
|
||||
}
|
||||
|
||||
@ -20,9 +20,12 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
#include "info.h"
|
||||
#include "uart.h"
|
||||
#include "config.h"
|
||||
|
||||
|
||||
|
||||
|
||||
@ -47,3 +50,25 @@ void info(char* format, ...) {
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef NO_INFO
|
||||
uint8_t buffer_info[FORMAT_BUFFER_LEN];
|
||||
#endif
|
||||
|
||||
#if defined(NO_INFO) && defined(__GNUC__)
|
||||
|
||||
#define info(format, args...) ((void)0)
|
||||
|
||||
#else
|
||||
void info_P(PGM_P format, ...) {
|
||||
#ifdef NO_INFO
|
||||
|
||||
#else
|
||||
strlcpy_P(buffer_info,format,FORMAT_BUFFER_LEN);
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vprintf(buffer_info, args);
|
||||
va_end(args);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
#if defined(NO_INFO) && defined(__GNUC__)
|
||||
/* gcc's cpp has extensions; it allows for macros with a variable number of
|
||||
@ -39,4 +39,15 @@ void info(char *format, ...);
|
||||
#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
|
||||
|
||||
@ -64,8 +64,8 @@ void leave_application(void)
|
||||
ISR (SIG_PIN_CHANGE3)
|
||||
{
|
||||
if (snes_reset_test()){
|
||||
info("Catch SNES reset button\n");
|
||||
info("Set watchdog...\n");
|
||||
info_P(PSTR("Catch SNES reset button\n"));
|
||||
info_P(PSTR("Set watchdog...\n"));
|
||||
leave_application();
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
|
||||
req_bank = 0;
|
||||
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);
|
||||
req_bank_size = (uint32_t) (1L << rq->wValue.word);
|
||||
req_bank_cnt = rq->wIndex.word;
|
||||
@ -93,8 +93,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
req_percent = 0;
|
||||
req_percent_last = 0;
|
||||
sync_errors = 0;
|
||||
debug(DEBUG_USB,
|
||||
"USB_BULK_UPLOAD_INIT: bank_size=0x%08lx bank_cnt=0x%x end_addr=0x%08lx\n",
|
||||
debug_P(DEBUG_USB,
|
||||
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);
|
||||
|
||||
shared_memory_write(SHARED_MEM_TX_CMD_BANK_COUNT, req_bank_cnt);
|
||||
@ -115,12 +115,12 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
|
||||
if (req_addr && req_addr % req_bank_size == 0) {
|
||||
#ifdef FLT_DEBUG
|
||||
debug(DEBUG_USB,
|
||||
"USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%.4f\n",
|
||||
debug_P(DEBUG_USB,
|
||||
PSTR("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
|
||||
req_bank, req_addr, timer_stop());
|
||||
#else
|
||||
debug(DEBUG_USB,
|
||||
"USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%i\n",
|
||||
debug_P(DEBUG_USB,
|
||||
PSTR("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%i\n"),
|
||||
req_bank, req_addr, timer_stop_int());
|
||||
#endif
|
||||
req_bank++;
|
||||
@ -146,8 +146,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
|
||||
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);
|
||||
//debug_P(DEBUG_USB,
|
||||
// PSTR("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);
|
||||
}
|
||||
@ -155,8 +155,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
|
||||
#if 0
|
||||
if (req_addr && (req_addr % 0x1000) == 0) {
|
||||
debug(DEBUG_USB,
|
||||
"USB_BULK_UPLOAD_NEXT: bank=0x%02x addr=0x%08lx crc=%04x\n",
|
||||
debug_P(DEBUG_USB,
|
||||
PSTR("USB_BULK_UPLOAD_NEXT: bank=0x%02x addr=0x%08lx crc=%04x\n",
|
||||
req_bank, req_addr, crc_check_bulk_memory(req_addr - 0x1000,
|
||||
req_addr,
|
||||
req_bank_size));
|
||||
@ -167,8 +167,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
|
||||
#if SHM_SCRATCHPAD
|
||||
if (!shared_memory_scratchpad_region_save_helper(req_addr)){
|
||||
debug(DEBUG_USB,
|
||||
"USB_BULK_UPLOAD_NEXT: scratchpad_region_save_helper was dirty\n");
|
||||
debug_P(DEBUG_USB,
|
||||
PSTR("USB_BULK_UPLOAD_NEXT: scratchpad_region_save_helper was dirty\n"));
|
||||
sram_bulk_write_start(req_addr);
|
||||
}
|
||||
#endif
|
||||
@ -176,12 +176,12 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
|
||||
if (req_addr && (req_addr % req_bank_size) == 0) {
|
||||
#ifdef FLT_DEBUG
|
||||
debug(DEBUG_USB,
|
||||
"USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%.4f\n",
|
||||
debug_P(DEBUG_USB,
|
||||
PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
|
||||
req_bank, req_addr, timer_stop());
|
||||
#else
|
||||
debug(DEBUG_USB,
|
||||
"USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%i\n",
|
||||
debug_P(DEBUG_USB,
|
||||
PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%i\n"),
|
||||
req_bank, req_addr, timer_stop_int());
|
||||
#endif
|
||||
req_bank++;
|
||||
@ -196,11 +196,11 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
*/
|
||||
} else if (rq->bRequest == USB_BULK_UPLOAD_END) {
|
||||
if (req_state != REQ_STATUS_BULK_UPLOAD) {
|
||||
debug(DEBUG_USB,
|
||||
"USB_BULK_UPLOAD_END: ERROR state is not REQ_STATUS_BULK_UPLOAD\n");
|
||||
debug_P(DEBUG_USB,
|
||||
PSTR("USB_BULK_UPLOAD_END: ERROR state is not REQ_STATUS_BULK_UPLOAD\n"));
|
||||
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;
|
||||
sram_bulk_write_end();
|
||||
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_END, 0);
|
||||
@ -213,7 +213,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
req_addr = rq->wValue.word;
|
||||
req_addr = req_addr << 16;
|
||||
req_addr = 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"), req_addr);
|
||||
crc_check_bulk_memory(0x000000, req_addr, req_bank_size);
|
||||
ret_len = 0;
|
||||
/*
|
||||
@ -221,20 +221,20 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
*/
|
||||
} else if (rq->bRequest == USB_MODE_SNES) {
|
||||
req_state = REQ_STATUS_SNES;
|
||||
debug(DEBUG_USB, "USB_MODE_SNES:\n");
|
||||
debug_P(DEBUG_USB, PSTR("USB_MODE_SNES:\n"));
|
||||
ret_len = 0;
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
} else if (rq->bRequest == USB_MODE_AVR) {
|
||||
req_state = REQ_STATUS_AVR;
|
||||
debug(DEBUG_USB, "USB_MODE_AVR:\n");
|
||||
debug_P(DEBUG_USB, PSTR("USB_MODE_AVR:\n"));
|
||||
ret_len = 0;
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
} 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();
|
||||
ret_len = 0;
|
||||
/*
|
||||
@ -246,12 +246,12 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
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,
|
||||
debug_P(DEBUG_USB, PSTR("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,
|
||||
debug_P(DEBUG_USB, PSTR("USB_CRC_ADDR: addr=0x%lx size=%li\n"), req_addr,
|
||||
req_size);
|
||||
|
||||
crc = crc_check_memory_range(req_addr, req_size, read_buffer);
|
||||
@ -274,10 +274,10 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
void usb_connect()
|
||||
{
|
||||
uint8_t i = 0;
|
||||
info("USB init\n");
|
||||
info_P(PSTR("USB init\n"));
|
||||
usbDeviceDisconnect(); /* enforce re-enumeration, do this while */
|
||||
cli();
|
||||
info("USB disconnect\n");
|
||||
info_P(PSTR("USB disconnect\n"));
|
||||
i = 10;
|
||||
while (--i) { /* fake USB disconnect for > 250 ms */
|
||||
led_on();
|
||||
@ -287,28 +287,28 @@ void usb_connect()
|
||||
}
|
||||
led_on();
|
||||
usbDeviceConnect();
|
||||
info("USB connect\n");
|
||||
info_P(PSTR("USB connect\n"));
|
||||
}
|
||||
|
||||
|
||||
void boot_startup_rom()
|
||||
{
|
||||
info("Boot startup rom\n");
|
||||
info("Activate AVR bus\n");
|
||||
info_P(PSTR("Boot startup rom\n"));
|
||||
info_P(PSTR("Activate AVR bus\n"));
|
||||
avr_bus_active();
|
||||
info("IRQ off\n");
|
||||
info_P(PSTR("IRQ off\n"));
|
||||
snes_irq_lo();
|
||||
snes_irq_off();
|
||||
snes_lorom();
|
||||
rle_decode(&_rom, ROM_BUFFER_SIZE, 0x000000);
|
||||
info("\n");
|
||||
info_P(PSTR("\n"));
|
||||
#if 1
|
||||
dump_memory(0x10000 - 0x100, 0x10000);
|
||||
#endif
|
||||
snes_hirom();
|
||||
snes_wr_disable();
|
||||
snes_bus_active();
|
||||
info("Activate SNES bus\n");
|
||||
info_P(PSTR("Activate SNES bus\n"));
|
||||
send_reset();
|
||||
_delay_ms(50);
|
||||
send_reset();
|
||||
@ -318,17 +318,17 @@ void boot_startup_rom()
|
||||
void banner(){
|
||||
uint8_t i;
|
||||
for (i=0;i<40;i++)
|
||||
info("\n");
|
||||
info(" ________ .__ __ ________ ____ ________\n");
|
||||
info(" \\_____ \\ __ __|__| ____ | | __\\______ \\ _______ _/_ |/ _____/\n");
|
||||
info(" / / \\ \\| | \\ |/ ___\\| |/ / | | \\_/ __ \\ \\/ /| / __ \\ \n");
|
||||
info(" / \\_/. \\ | / \\ \\___| < | ` \\ ___/\\ / | \\ |__\\ \\ \n");
|
||||
info(" \\_____\\ \\_/____/|__|\\___ >__|_ \\/_______ /\\___ >\\_/ |___|\\_____ / \n");
|
||||
info(" \\__> \\/ \\/ \\/ \\/ \\/ \n");
|
||||
info("\n");
|
||||
info(" www.optixx.org\n");
|
||||
info("\n");
|
||||
info("System Hw: %s Sw: %s\n",HW_VERSION,SW_VERSION);
|
||||
info_P(PSTR("\n"));
|
||||
info_P(PSTR(" ________ .__ __ ________ ____ ________\n"));
|
||||
info_P(PSTR(" \\_____ \\ __ __|__| ____ | | __\\______ \\ _______ _/_ |/ _____/\n"));
|
||||
info_P(PSTR(" / / \\ \\| | \\ |/ ___\\| |/ / | | \\_/ __ \\ \\/ /| / __ \\ \n"));
|
||||
info_P(PSTR(" / \\_/. \\ | / \\ \\___| < | ` \\ ___/\\ / | \\ |__\\ \\ \n"));
|
||||
info_P(PSTR(" \\_____\\ \\_/____/|__|\\___ >__|_ \\/_______ /\\___ >\\_/ |___|\\_____ / \n"));
|
||||
info_P(PSTR(" \\__> \\/ \\/ \\/ \\/ \\/ \n"));
|
||||
info_P(PSTR("\n"));
|
||||
info_P(PSTR(" www.optixx.org\n"));
|
||||
info_P(PSTR("\n"));
|
||||
info_P(PSTR("System Hw: %s Sw: %s\n"),HW_VERSION,SW_VERSION);
|
||||
|
||||
}
|
||||
|
||||
@ -357,12 +357,12 @@ int main(void)
|
||||
usb_connect();
|
||||
while (1) {
|
||||
avr_bus_active();
|
||||
info("Activate AVR bus\n");
|
||||
info_P(PSTR("Activate AVR bus\n"));
|
||||
snes_lorom();
|
||||
info("Disable SNES WR\n");
|
||||
info_P(PSTR("Disable SNES WR\n"));
|
||||
snes_wr_disable();
|
||||
sei();
|
||||
info("USB poll\n");
|
||||
info_P(PSTR("USB poll\n"));
|
||||
while (req_state != REQ_STATUS_SNES) {
|
||||
usbPoll();
|
||||
}
|
||||
@ -372,15 +372,15 @@ int main(void)
|
||||
shared_memory_scratchpad_region_tx_restore();
|
||||
shared_memory_scratchpad_region_rx_restore();
|
||||
#endif
|
||||
info("USB poll done\n");
|
||||
info_P(PSTR("USB poll done\n"));
|
||||
set_rom_mode();
|
||||
snes_wr_disable();
|
||||
info("Disable SNES WR\n");
|
||||
info_P(PSTR("Disable SNES WR\n"));
|
||||
snes_bus_active();
|
||||
info("Activate SNES bus\n");
|
||||
info_P(PSTR("Activate SNES bus\n"));
|
||||
irq_stop();
|
||||
send_reset();
|
||||
info("Poll USB\n");
|
||||
info_P(PSTR("Poll USB\n"));
|
||||
while ((req_state != REQ_STATUS_AVR)) {
|
||||
usbPoll();
|
||||
|
||||
@ -391,7 +391,7 @@ int main(void)
|
||||
while (--i) {
|
||||
_delay_ms(100);
|
||||
}
|
||||
info("Send IRQ %i\n", ++irq_count);
|
||||
info_P(PSTR("Send IRQ %i\n"), ++irq_count);
|
||||
send_irq();
|
||||
#endif
|
||||
|
||||
@ -402,7 +402,7 @@ int main(void)
|
||||
i = 5;
|
||||
while (--i) {
|
||||
_delay_ms(500);
|
||||
info("Wait to switch to snes mode %i\n", i);
|
||||
info_P(PSTR("Wait to switch to snes mode %i\n"), i);
|
||||
}
|
||||
|
||||
if (req_bank_size == 0x8000) {
|
||||
@ -411,10 +411,10 @@ int main(void)
|
||||
snes_hirom();
|
||||
}
|
||||
snes_wr_disable();
|
||||
info("Disable SNES WR\n");
|
||||
info_P(PSTR("Disable SNES WR\n"));
|
||||
snes_bus_active();
|
||||
info("Activate SNES bus\n");
|
||||
info("Read 0x3000=%c\n", c);
|
||||
info_P(PSTR("Activate SNES bus\n"));
|
||||
info_P(PSTR("Read 0x3000=%c\n"), c);
|
||||
#endif
|
||||
}
|
||||
irq_init();
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
uint8_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
|
||||
{
|
||||
uint8_t in_byte, in_repeat, last_byte;
|
||||
info("RLE decode len=%li addr=0x%08lx\n", in_len, out_addr);
|
||||
info_P(PSTR("RLE decode len=%li addr=0x%08lx\n"), in_len, out_addr);
|
||||
last_byte = 0;
|
||||
|
||||
sram_bulk_write_start(out_addr);
|
||||
@ -61,7 +61,7 @@ uint8_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
|
||||
if (in_byte == RUNCHAR) {
|
||||
INBYTE(in_repeat);
|
||||
if (in_repeat != 0) {
|
||||
info("Orphaned RLE code at start\n");
|
||||
info_P(PSTR("Orphaned RLE code at start\n"));
|
||||
return 1;
|
||||
}
|
||||
OUTBYTE(RUNCHAR);
|
||||
@ -72,7 +72,7 @@ uint8_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
|
||||
while (in_len > 0) {
|
||||
INBYTE(in_byte);
|
||||
if (in_len % 1024 == 0)
|
||||
info(".");
|
||||
info_P(PSTR("."));
|
||||
if (in_byte == RUNCHAR) {
|
||||
INBYTE(in_repeat);
|
||||
if (in_repeat == 0) {
|
||||
|
||||
@ -51,12 +51,12 @@ uint8_t scratchpad_locked_tx = 1;
|
||||
uint8_t shared_memory_scratchpad_region_save_helper(uint32_t addr){
|
||||
|
||||
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);
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_save_helper: open tx addr=0x%06lx\n"),addr);
|
||||
shared_memory_scratchpad_region_tx_save();
|
||||
return 0;
|
||||
}
|
||||
if(addr > (SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE) && scratchpad_locked_rx){
|
||||
debug(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();
|
||||
return 0;
|
||||
}
|
||||
@ -70,10 +70,10 @@ void shared_memory_scratchpad_region_tx_save()
|
||||
uint16_t crc;
|
||||
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_TX_LOC_STATE,
|
||||
(uint32_t)(SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE), 0x8000);
|
||||
debug(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
|
||||
|
||||
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,
|
||||
(uint32_t)SHARED_MEM_TX_LOC_SIZE);
|
||||
scratchpad_locked_tx = 0;
|
||||
@ -92,10 +92,10 @@ void shared_memory_scratchpad_region_rx_save()
|
||||
uint16_t crc;
|
||||
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_RX_LOC_STATE,
|
||||
(uint32_t)(SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE), 0x8000);
|
||||
debug(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
|
||||
|
||||
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,
|
||||
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
|
||||
scratchpad_locked_rx = 0;
|
||||
@ -111,7 +111,7 @@ void shared_memory_scratchpad_region_tx_restore()
|
||||
if (scratchpad_locked_tx)
|
||||
return;
|
||||
|
||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_tx_restore: lock\n");
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: lock\n"));
|
||||
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;
|
||||
@ -124,7 +124,7 @@ void shared_memory_scratchpad_region_tx_restore()
|
||||
uint16_t crc;
|
||||
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_TX_LOC_STATE,
|
||||
(uint32_t)(SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE), 0x8000);
|
||||
debug(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
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ void shared_memory_scratchpad_region_rx_restore()
|
||||
{
|
||||
if (scratchpad_locked_rx)
|
||||
return;
|
||||
debug(DEBUG_SHM,"shared_memory_scratchpad_region_tx_save: lock\n");
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: lock\n"));
|
||||
sram_bulk_copy_from_buffer((uint32_t)SHARED_MEM_RX_LOC_STATE,scratchpad_region_rx,
|
||||
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
|
||||
scratchpad_locked_rx = 1;
|
||||
@ -147,7 +147,7 @@ void shared_memory_scratchpad_region_rx_restore()
|
||||
uint16_t crc;
|
||||
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_RX_LOC_STATE,
|
||||
(uint32_t)(SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE), 0x8000);
|
||||
debug(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
|
||||
}
|
||||
|
||||
@ -185,9 +185,9 @@ void shared_memory_write(uint8_t cmd, uint8_t value)
|
||||
{
|
||||
|
||||
if (scratchpad_locked_tx)
|
||||
debug(DEBUG_SHM,"shared_memory_write: locked_tx\n");
|
||||
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",
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_write: 0x%04x=0x%02x 0x%04x=0x%02x \n"),
|
||||
SHARED_MEM_TX_LOC_CMD, cmd, SHARED_MEM_TX_LOC_PAYLOAD, value);
|
||||
|
||||
sram_bulk_addr_save();
|
||||
@ -243,7 +243,7 @@ int shared_memory_read(uint8_t *cmd, uint8_t *len,uint8_t *buffer)
|
||||
uint8_t state;
|
||||
|
||||
if (scratchpad_locked_rx)
|
||||
debug(DEBUG_SHM,"shared_memory_write: locked_tx\n");
|
||||
debug_P(DEBUG_SHM, PSTR("shared_memory_write: locked_tx\n"));
|
||||
|
||||
|
||||
state = sram_read(SHARED_MEM_RX_LOC_STATE);
|
||||
@ -254,7 +254,7 @@ int shared_memory_read(uint8_t *cmd, uint8_t *len,uint8_t *buffer)
|
||||
|
||||
*cmd = sram_read(SHARED_MEM_RX_LOC_CMD);
|
||||
*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);
|
||||
|
||||
sram_bulk_copy_into_buffer(SHARED_MEM_RX_LOC_PAYLOAD,buffer, *len);
|
||||
|
||||
@ -94,19 +94,19 @@ void system_init(void)
|
||||
void sreg_set(uint32_t addr)
|
||||
{
|
||||
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--) {
|
||||
if ((addr & ( 1L << i))){
|
||||
debug(DEBUG_SREG,"1");
|
||||
debug_P(DEBUG_SREG, PSTR("1"));
|
||||
AVR_ADDR_SER_PORT |= ( 1 << AVR_ADDR_SER_PIN);
|
||||
} else {
|
||||
AVR_ADDR_SER_PORT &= ~( 1 << AVR_ADDR_SER_PIN);
|
||||
debug(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);
|
||||
}
|
||||
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);
|
||||
|
||||
@ -127,7 +127,7 @@ inline void sram_bulk_addr_restore()
|
||||
|
||||
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;
|
||||
|
||||
@ -173,7 +173,7 @@ inline uint8_t sram_bulk_read(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_CS_PORT |= (1 << AVR_CS_PIN);
|
||||
@ -183,7 +183,7 @@ void sram_bulk_read_end(void)
|
||||
uint8_t sram_read(uint32_t addr)
|
||||
{
|
||||
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();
|
||||
|
||||
@ -215,7 +215,7 @@ uint8_t sram_read(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);
|
||||
|
||||
avr_data_out();
|
||||
|
||||
@ -243,7 +243,7 @@ inline void sram_bulk_write( uint8_t data)
|
||||
|
||||
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_CS_PORT |= (1 << AVR_CS_PIN);
|
||||
avr_data_in();
|
||||
@ -252,7 +252,7 @@ void sram_bulk_write_end(void)
|
||||
|
||||
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();
|
||||
|
||||
@ -286,7 +286,7 @@ void sram_bulk_copy_from_buffer(uint32_t addr, uint8_t * src, uint32_t len)
|
||||
|
||||
uint32_t i;
|
||||
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);
|
||||
sram_bulk_write_start(addr);
|
||||
for (i = addr; i < (addr + len); i++){
|
||||
@ -301,7 +301,7 @@ void sram_bulk_copy_into_buffer(uint32_t addr, uint8_t * dst, uint32_t len)
|
||||
|
||||
uint32_t i;
|
||||
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);
|
||||
sram_bulk_read_start(addr);
|
||||
for (i = addr; i < (addr + len); i++) {
|
||||
@ -314,11 +314,11 @@ void sram_bulk_copy_into_buffer(uint32_t addr, uint8_t * dst, uint32_t len)
|
||||
|
||||
void sram_bulk_set(uint32_t addr, uint32_t len,uint8_t value){
|
||||
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);
|
||||
for (i = addr; i < (addr + len); i++) {
|
||||
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_next();
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ void test_read_write()
|
||||
}
|
||||
addr = 0x000000;
|
||||
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 +69,7 @@ void test_bulk_read_write()
|
||||
addr = 0x000000;
|
||||
sram_bulk_read_start(addr);
|
||||
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();
|
||||
addr++;
|
||||
}
|
||||
@ -85,7 +85,7 @@ void test_non_zero_memory(uint32_t bottom_addr, uint32_t top_addr)
|
||||
for (addr = bottom_addr; addr < top_addr; addr++) {
|
||||
c = sram_bulk_read();
|
||||
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_end();
|
||||
@ -95,12 +95,12 @@ void test_non_zero_memory(uint32_t bottom_addr, uint32_t top_addr)
|
||||
|
||||
void test_crc()
|
||||
{
|
||||
info("test_crc: clear\n");
|
||||
info_P(PSTR("test_crc: clear\n"));
|
||||
avr_bus_active();
|
||||
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);
|
||||
info("test_crc: check\n");
|
||||
info_P(PSTR("test_crc: check\n"));
|
||||
test_non_zero_memory(0x000000, 0x10000);
|
||||
}
|
||||
|
||||
|
||||
@ -56,14 +56,14 @@ uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
|
||||
uint8_t i;
|
||||
|
||||
if (len > 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);
|
||||
len = rx_remaining;
|
||||
}
|
||||
if (req_state == REQ_STATUS_BULK_UPLOAD) {
|
||||
|
||||
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);
|
||||
ptr = data;
|
||||
i = len;
|
||||
@ -81,7 +81,7 @@ uint8_t usbFunctionRead(uint8_t * data, uint8_t len)
|
||||
if (len > tx_remaining)
|
||||
len = tx_remaining;
|
||||
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, tx_remaining);
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
*data = tx_buffer[len];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user