Merge branch 'master' into qdinc

Conflicts:
	avr/usbload/main.c
	avr/usbload/shell.c
This commit is contained in:
optixx
2009-09-23 15:53:02 +02:00
30 changed files with 765 additions and 274 deletions

View File

@@ -39,7 +39,7 @@ else
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 \
uart.o fifo.o sram.o crc.o debug.o dump.o timer.o watchdog.o rle.c loader.o \
pwm.o uril.o shell.o info.o shared_memory.o command.o irq.o
pwm.o util.o shell.o info.o shared_memory.o command.o irq.o
endif
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)

View File

@@ -29,8 +29,12 @@
#include "info.h"
#include "irq.h"
#include "usbdrv.h"
#include "rle.h"
#include "loader.h"
extern uint32_t req_bank_size;
extern usb_transaction_t usb_trans;
extern const char _rom[] PROGMEM;
void usb_connect()
{
@@ -73,7 +77,7 @@ void send_irq()
void set_rom_mode()
{
if (req_bank_size == 0x8000) {
if (usb_trans.req_bank_size == 0x8000) {
snes_lorom();
info_P(PSTR("Set SNES lowrom \n"));
} else {
@@ -81,3 +85,63 @@ void set_rom_mode()
info_P(PSTR("Set SNES hirom \n"));
}
}
void boot_startup_rom(uint16_t init_delay)
{
info_P(PSTR("Fetch loader rom\n"));
info_P(PSTR("Activate AVR bus\n"));
avr_bus_active();
info_P(PSTR("IRQ off\n"));
snes_irq_lo();
snes_irq_off();
snes_lorom();
rle_decode(&_rom, ROM_BUFFER_SIZE, 0x000000);
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();
snes_irq_off();
snes_hirom();
snes_wr_disable();
snes_bus_active();
info_P(PSTR("Activate SNES bus\n"));
send_reset();
_delay_ms(init_delay);
}
void banner(){
uint8_t i;
for (i=0;i<40;i++)
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);
}
void transaction_status(){
info_P(PSTR("\nAddr 0x%06lx\n"),usb_trans.req_addr);
info_P(PSTR("Bank 0x%02x\n"),usb_trans.req_bank);
info_P(PSTR("Banksize 0x%06lx\n"),usb_trans.req_bank_size);
info_P(PSTR("Bankcount 0x%02x\n"),usb_trans.req_bank_cnt);
info_P(PSTR("Status 0x%02x\n"),usb_trans.req_state);
info_P(PSTR("Percent %02i\n"),usb_trans.req_percent);
info_P(PSTR("TX buffer %02i\n"),usb_trans.tx_remaining);
info_P(PSTR("RX buffer %02i\n"),usb_trans.rx_remaining);
info_P(PSTR("Syncerr %02i\n"),usb_trans.sync_errors);
}

View File

@@ -26,5 +26,9 @@ void send_reset();
void send_irq();
void set_rom_mode();
void usb_connect();
void boot_startup_rom(uint16_t init_delay);
void banner();
void transaction_status();
#endif

View File

@@ -43,7 +43,8 @@
#define USB_CRC_CHECK 0x01
#define TRANSFER_BUFFER_SIZE 0x000
#define FORMAT_BUFFER_LEN 0x100
#define FORMAT_BUFFER_LEN 0x080
#define RECEIVE_BUF_LEN 0x030
#define HW_VERSION "2.6"
#define SW_VERSION "1.0"
@@ -51,5 +52,6 @@
#define DO_CRC_CHECK 0
#define DO_SHM_SCRATCHPAD 1
#define DO_SHM 1
#define DO_TIMER 1
#endif

View File

@@ -26,6 +26,7 @@
#include <stdlib.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <string.h>
#include "usbdrv.h"
#include "oddebug.h"
@@ -51,31 +52,17 @@
extern const char _rom[] PROGMEM;
extern FILE uart_stdout;
uint8_t debug_level = (DEBUG | DEBUG_USB | DEBUG_CRC | DEBUG_SHM );
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;
uint8_t loader_enabled = 1;
typedef struct system_t {
uint8_t bus_mode;
uint8_t rom_mode;
uint8_t req_bank;
} system_t;
usb_transaction_t usb_trans;
usbMsgLen_t usbFunctionSetup(uchar data[8])
{
@@ -85,129 +72,139 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
if (rq->bRequest == USB_BULK_UPLOAD_INIT) {
req_bank = 0;
rx_remaining = 0;
usb_trans.req_bank = 0;
usb_trans.rx_remaining = 0;
debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_INIT: %i %i\n"), rq->wValue.word,
rq->wIndex.word);
req_bank_size = (uint32_t) (1L << rq->wValue.word);
req_bank_cnt = rq->wIndex.word;
req_addr_end = (uint32_t) req_bank_size *req_bank_cnt;
req_percent = 0;
req_percent_last = 0;
sync_errors = 0;
usb_trans.req_bank_size = (uint32_t) (1L << rq->wValue.word);
usb_trans.req_bank_cnt = rq->wIndex.word;
usb_trans.req_addr_end = (uint32_t) usb_trans.req_bank_size * usb_trans.req_bank_cnt;
usb_trans.req_percent = 0;
usb_trans.req_percent_last = 0;
usb_trans.sync_errors = 0;
debug_P(DEBUG_USB,
PSTR("USB_BULK_UPLOAD_INIT: bank_size=0x%08lx bank_cnt=0x%x end_addr=0x%08lx\n"),
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_UPLOAD_START, 0);
shared_memory_write(SHARED_MEM_TX_CMD_BANK_COUNT, req_bank_cnt);
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) {
timer_start();
}
#endif
/*
* -------------------------------------------------------------------------
*/
} else if (rq->bRequest == USB_BULK_UPLOAD_ADDR) {
req_state = REQ_STATUS_BULK_UPLOAD;
req_addr = rq->wValue.word;
req_addr = req_addr << 16;
req_addr = req_addr | rq->wIndex.word;
rx_remaining = rq->wLength.word;
usb_trans.req_state = REQ_STATUS_BULK_UPLOAD;
usb_trans.req_addr = rq->wValue.word;
usb_trans.req_addr = usb_trans.req_addr << 16;
usb_trans.req_addr = usb_trans.req_addr | rq->wIndex.word;
usb_trans.rx_remaining = rq->wLength.word;
if (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
#ifdef FLT_DEBUG
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());
usb_trans.req_bank, usb_trans.req_addr, timer_stop());
#else
debug_P(DEBUG_USB,
PSTR("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%i\n"),
req_bank, req_addr, timer_stop_int());
usb_trans.req_bank, usb_trans.req_addr, timer_stop_int());
#endif
req_bank++;
timer_start();
timer_start();
#endif
usb_trans.req_bank++;
} else {
sram_bulk_write_start(usb_trans.req_addr);
}
sram_bulk_write_start(req_addr);
ret_len = USB_MAX_TRANS;
/*
* -------------------------------------------------------------------------
*/
} else if (rq->bRequest == USB_BULK_UPLOAD_NEXT) {
req_state = REQ_STATUS_BULK_UPLOAD;
req_addr = rq->wValue.word;
req_addr = req_addr << 16;
req_addr = req_addr | rq->wIndex.word;
rx_remaining = rq->wLength.word;
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_percent = (uint32_t)( 100 * req_addr ) / req_addr_end;
if (req_percent!=req_percent_last){
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_PROGESS, req_percent);
#if DO_SHM
usb_trans.req_percent = (uint32_t)( 100 * usb_trans.req_addr ) / usb_trans.req_addr_end;
if (usb_trans.req_percent!=usb_trans.req_percent_last){
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_PROGESS, usb_trans.req_percent);
}
req_percent_last = req_percent;
usb_trans.req_percent_last = usb_trans.req_percent;
shared_memory_scratchpad_region_save_helper(usb_trans.req_addr);
#endif
if (usb_trans.req_addr && (usb_trans.req_addr % usb_trans.req_bank_size) == 0) {
#if DO_TIMER
shared_memory_scratchpad_region_save_helper(req_addr);
if (req_addr && (req_addr % req_bank_size) == 0) {
#ifdef FLT_DEBUG
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());
usb_trans.req_bank, usb_trans.req_addr, timer_stop());
#else
debug_P(DEBUG_USB,
PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%i\n"),
req_bank, req_addr, timer_stop_int());
usb_trans.req_bank, usb_trans.req_addr, timer_stop_int());
#endif
timer_start();
#endif
usb_trans.req_bank++;
#if DO_SHM
shared_memory_write(SHARED_MEM_TX_CMD_BANK_CURRENT, usb_trans.req_bank);
#endif
req_bank++;
timer_start();
shared_memory_write(SHARED_MEM_TX_CMD_BANK_CURRENT, req_bank);
}
ret_len = USB_MAX_TRANS;
/*
* -------------------------------------------------------------------------
*/
} 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_P(DEBUG_USB,
PSTR("USB_BULK_UPLOAD_END: ERROR state is not REQ_STATUS_BULK_UPLOAD\n"));
return 0;
}
debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_END:\n"));
req_state = REQ_STATUS_IDLE;
usb_trans.req_state = REQ_STATUS_IDLE;
sram_bulk_write_end();
#if DO_SHM
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_END, 0);
#endif
ret_len = 0;
/*
* -------------------------------------------------------------------------
*/
} else if (rq->bRequest == USB_CRC) {
req_addr = rq->wValue.word;
req_addr = req_addr << 16;
req_addr = req_addr | rq->wIndex.word;
debug_P(DEBUG_USB, PSTR("USB_CRC: addr=0x%08lx \n"), req_addr);
crc_check_bulk_memory(0x000000, req_addr, req_bank_size);
usb_trans.req_addr = rq->wValue.word;
usb_trans.req_addr = usb_trans.req_addr << 16;
usb_trans.req_addr = usb_trans.req_addr | rq->wIndex.word;
debug_P(DEBUG_USB, PSTR("USB_CRC: addr=0x%08lx \n"), usb_trans.req_addr);
crc_check_bulk_memory(0x000000, usb_trans.req_addr, usb_trans.req_bank_size);
ret_len = 0;
/*
* -------------------------------------------------------------------------
*/
} else if (rq->bRequest == USB_MODE_SNES) {
req_state = REQ_STATUS_SNES;
usb_trans.req_state = REQ_STATUS_SNES;
debug_P(DEBUG_USB, PSTR("USB_MODE_SNES:\n"));
ret_len = 0;
pwm_stop();
/*
* -------------------------------------------------------------------------
*/
} else if (rq->bRequest == USB_MODE_AVR) {
req_state = REQ_STATUS_AVR;
usb_trans.req_state = REQ_STATUS_AVR;
debug_P(DEBUG_USB, PSTR("USB_MODE_AVR:\n"));
ret_len = 0;
/*
@@ -220,96 +217,29 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
/*
* -------------------------------------------------------------------------
*/
} else if (rq->bRequest == USB_CRC_ADDR) {
req_state = REQ_STATUS_CRC;
req_addr = rq->wValue.word;
req_addr = req_addr << 16;
req_addr = req_addr | rq->wIndex.word;
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_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);
tx_buffer[0] = crc & 0xff;
tx_buffer[1] = (crc >> 8) & 0xff;
ret_len = 2;
req_state = REQ_STATUS_IDLE;
} else if (rq->bRequest == USB_SET_LAODER) {
loader_enabled = rq->wValue.word;
usb_trans.loader_enabled = rq->wValue.word;
ret_len = 0;
}
usbMsgPtr = data_buffer;
return ret_len; /* default for not implemented requests: return no data back to host */
usbMsgPtr = usb_trans.rx_buffer;
return ret_len;
}
/*
* -------------------------------------------------------------------------
*/
void boot_startup_rom(uint16_t init_delay)
{
info_P(PSTR("Fetch loader rom\n"));
info_P(PSTR("Activate AVR bus\n"));
avr_bus_active();
info_P(PSTR("IRQ off\n"));
snes_irq_lo();
snes_irq_off();
snes_lorom();
rle_decode(&_rom, ROM_BUFFER_SIZE, 0x000000);
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();
snes_irq_off();
snes_hirom();
snes_wr_disable();
snes_bus_active();
info_P(PSTR("Activate SNES bus\n"));
send_reset();
_delay_ms(init_delay);
}
void banner(){
uint8_t i;
for (i=0;i<40;i++)
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);
}
void globals_init(){
req_addr = 0;
req_addr_end = 0;
req_state = REQ_STATUS_IDLE;
rx_remaining = 0;
tx_remaining = 0;
sync_errors = 0;
memset(&usb_trans,0,sizeof(usb_transaction_t));
usb_trans.req_addr = 0;
usb_trans.req_addr_end = 0;
usb_trans.req_state = REQ_STATUS_IDLE;
usb_trans.rx_remaining = 0;
usb_trans.tx_remaining = 0;
usb_trans.sync_errors = 0;
usb_trans.loader_enabled = 1;
}
int main(void)
@@ -341,13 +271,15 @@ int main(void)
snes_wr_disable();
sei();
info_P(PSTR("USB poll\n"));
while (req_state != REQ_STATUS_SNES) {
while (usb_trans.req_state != REQ_STATUS_SNES) {
usbPoll();
shell_run();
}
#if DO_SHM
shared_memory_write(SHARED_MEM_TX_CMD_TERMINATE, 0);
#endif
#if DO_SHM_SCRATCHPAD
shared_memory_scratchpad_region_tx_restore();
@@ -356,7 +288,7 @@ int main(void)
#if DO_CRC_CHECK
info_P(PSTR("-->CRC Check\n"));
crc_check_bulk_memory(0x000000, req_bank_size * req_bank_cnt, req_bank_size);
crc_check_bulk_memory(0x000000, usb_trans.req_bank_size * usb_trans.req_bank_cnt, usb_trans.req_bank_size);
#endif
info_P(PSTR("-->Switch TO SNES\n"));
@@ -368,24 +300,20 @@ int main(void)
irq_stop();
send_reset();
info_P(PSTR("Poll USB\n"));
while ((req_state != REQ_STATUS_AVR)) {
while ((usb_trans.req_state != REQ_STATUS_AVR)) {
usbPoll();
shell_run();
}
info_P(PSTR("-->Switch TO AVR\n"));
shared_memory_init();
irq_init();
if(loader_enabled)
if(usb_trans.loader_enabled)
boot_startup_rom(500);
else
{
avr_bus_active();
send_reset();
}
}
return 0;
}

View File

@@ -30,17 +30,17 @@
#define PWM_SINE_MAX 64
#define PWM_OVERFLOW_MAX 1024
uint8_t pwm_sine_table[] = {
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; // Einstellungen für die einzelnen PWM-Kanäle
volatile uint16_t pwm_overflow; // Einstellungen für die einzelnen PWM-Kanäle
volatile uint8_t pwm_idx; // Einstellungen für die einzelnen PWM-Kanäle
volatile uint16_t pwm_overflow_max; // Einstellungen für die einzelnen PWM-Kanäle
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;
@@ -67,6 +67,19 @@ 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;
}

View File

@@ -40,4 +40,21 @@
#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__ */

View File

@@ -37,7 +37,7 @@
#define SHARED_MEM_TX_CMD_TERMINATE 0x06
#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_PAYLOAD 0x000002
@@ -48,7 +48,7 @@
#define SHARED_MEM_RX_CMD_FILESEL 0x01
#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_LEN 0x001002
#define SHARED_MEM_RX_LOC_PAYLOAD 0x001003

View File

@@ -35,10 +35,17 @@
#include "uart.h"
#include "dump.h"
#include "irq.h"
#include "config.h"
#include "crc.h"
#include "command.h"
#include "shared_memory.h"
#define RECEIVE_BUF_LEN 40
uint8_t recv_buf[RECEIVE_BUF_LEN];
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;
@@ -54,11 +61,11 @@ uint8_t *get_token(void)
token_ptr = p;
do {
token_ptr++;
if (*token_ptr == ' ') {
if (*token_ptr == ' ' || *token_ptr == '\n' || *token_ptr == '\r') {
*token_ptr++ = '\0';
break;
}
} while (*token_ptr != '\0');
} while (*token_ptr != ' ' && *token_ptr != '\n' && *token_ptr != '\r');
return p;
}
@@ -79,8 +86,6 @@ uint8_t get_dec(uint32_t *decval)
uint8_t parse_hex(const uint8_t *s, uint32_t *hexval)
{
uint32_t x = util_sscanhex(s);
if (x > 0xffffff)
return 0;
*hexval = (uint32_t) x;
return 1;
}
@@ -107,7 +112,7 @@ uint8_t get_hex_arg3(uint32_t *hexval1, uint32_t *hexval2, uint32_t *hexval3)
static uint8_t get_int32(uint32_t *val)
{
if (!get_hex(val)){
printf("Invalid argument!\n");
info_P(PSTR("Invalid argument!\n"));
return 0;
} else {
return 1;
@@ -118,7 +123,7 @@ static uint8_t get_int32(uint32_t *val)
{
uint32_t ret;
if (!get_hex(&ret) ||ret > 0xff){
printf("Invalid argument!\n");
info_P(PSTR("Invalid argument!\n"));
return 0;
}else{
*val = (uint8_t)ret;
@@ -135,14 +140,13 @@ static uint8_t get_int32(uint32_t *val)
if (result >= 0)
return result;
}
printf("Invalid argument (should be 0 or 1)!\n");
info_P(PSTR("Invalid argument (should be 0 or 1)!\n"));
return -1;
}
void prompt(void){
uart_putc('\r');
uart_putc('\n');
uart_putc(':');
uart_putc('>');
}
@@ -176,8 +180,55 @@ ISR(USART0_RX_vect) // Interrupt for UART Byte received
UCSR0B |= (1<<RXCIE0);// Interrupts enable for RxD
}
enum cmds { CMD_DUMP,
CMD_CRC,
CMD_EXIT,
CMD_RESET,
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_HELP
};
uint8_t command_buf[RECEIVE_BUF_LEN];
uint8_t cmdlist[][CMD_HELP] PROGMEM = {
{"DUMP"},
{"CRC"},
{"EXIT"},
{"RESET"},
{"IRQ"},
{"AVR"},
{"SNES"},
{"LOROM"},
{"HIROM"},
{"WR"},
{"SHMWR"},
{"SHMSAVE"},
{"SHMRESTORE"},
{"LOADER"},
{"RECONNECT"},
{"STATUS"},
{"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)
{
@@ -185,6 +236,7 @@ void shell_run(void)
uint32_t arg1;
uint32_t arg2;
uint32_t arg3;
uint16_t crc;
if (!cr)
return;
@@ -195,36 +247,90 @@ void shell_run(void)
t = get_token();
if (t == NULL)
return;
shell_help();
util_strupper(t);
if (strcmp((char*)t, "DUMP") == 0) {
if (strcmp_P((const char*)t,(PGM_P)cmdlist[CMD_DUMP]) == 0) {
if (get_hex_arg2(&arg1,&arg2))
dump_memory(arg1,arg2);
else
printf("DUMP <start addr> <end addr> %i %i\n",arg1,arg2);
}
else if (strcmp((char*)t, "RESET") == 0) {
leave_application();
}
prompt();
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) {
send_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();
}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();
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_LOROM]) == 0) {
info_P(PSTR("Set LOROM\n"));
snes_lorom();
snes_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();
}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_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_HELP]) == 0) {
shell_help();
}
prompt();
/*
reset
reset snes
dias
switch to avr mode
swicth to snes mode
send irq
crc
set irq vector
set reset vector
set rom mode
dump cart header
*/
}

View File

@@ -232,8 +232,8 @@ void sram_bulk_write_start(uint32_t addr)
inline void sram_bulk_write_next(void)
{
AVR_WR_PORT &= ~(1 << AVR_WR_PIN);
addr_current++;
AVR_WR_PORT |= (1 << AVR_WR_PIN);
counter_up();
}
@@ -241,6 +241,7 @@ inline void sram_bulk_write( uint8_t data)
{
AVR_WR_PORT &= ~(1 << AVR_WR_PIN);
AVR_DATA_PORT = data;
AVR_WR_PORT |= (1 << AVR_WR_PIN);
}
void sram_bulk_write_end(void)

View File

@@ -39,32 +39,24 @@
#include "crc.h"
#include "usb_bulk.h"
extern uint8_t read_buffer[TRANSFER_BUFFER_SIZE];
extern uint32_t req_addr;
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;
extern usb_transaction_t usb_trans;
uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
{
uint8_t *ptr;
uint8_t i;
if (len > rx_remaining) {
if (len > usb_trans.rx_remaining) {
info_P(PSTR("ERROR:usbFunctionWrite more data than expected remain: %i len: %i\n"),
rx_remaining, len);
len = rx_remaining;
usb_trans.rx_remaining, len);
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_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;
i = len;
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 i;
if (len > tx_remaining)
len = tx_remaining;
tx_remaining -= len;
debug_P(DEBUG_USB_TRANS, PSTR("usbFunctionRead len=%i tx_remaining=%i \n"), len, tx_remaining);
if (len > usb_trans.tx_remaining)
len = usb_trans.tx_remaining;
usb_trans.tx_remaining -= len;
debug_P(DEBUG_USB_TRANS, PSTR("usbFunctionRead len=%i tx_remaining=%i \n"), len, usb_trans.tx_remaining);
for (i = 0; i < len; i++) {
*data = tx_buffer[len];
*data = usb_trans.tx_buffer[len];
data++;
}
return len;

View File

@@ -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
* 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
* interval. The value is in milliseconds and must not be less than 10 ms for
* low speed devices.

View File

@@ -101,7 +101,7 @@ uint32_t util_sscandec(const uint8_t *s)
uint32_t util_sscanhex(const uint8_t *s)
{
uint32_t result;
int32_t result;
if (*s == '\0')
return -1;
result = 0;