indent cleanup
This commit is contained in:
parent
0f0c6eb409
commit
c09d1a1918
@ -66,18 +66,18 @@ void boot_startup_rom(uint16_t init_delay)
|
|||||||
info_P(PSTR("Fetch loader rom\n"));
|
info_P(PSTR("Fetch loader rom\n"));
|
||||||
|
|
||||||
system_set_bus_avr();
|
system_set_bus_avr();
|
||||||
//snes_irq_lo();
|
// snes_irq_lo();
|
||||||
//system_snes_irq_off();
|
// system_snes_irq_off();
|
||||||
system_set_rom_lorom();
|
system_set_rom_lorom();
|
||||||
|
|
||||||
//info_P(PSTR("Activate AVR bus\n"));
|
// info_P(PSTR("Activate AVR bus\n"));
|
||||||
//avr_bus_active();
|
// avr_bus_active();
|
||||||
//info_P(PSTR("IRQ off\n"));
|
// info_P(PSTR("IRQ off\n"));
|
||||||
//snes_irq_lo();
|
// snes_irq_lo();
|
||||||
//snes_irq_off();
|
// snes_irq_off();
|
||||||
//snes_lorom();
|
// snes_lorom();
|
||||||
|
|
||||||
for (i=0; i<ROM_BUFFER_CNT; i++){
|
for (i = 0; i < ROM_BUFFER_CNT; i++) {
|
||||||
addr += rle_decode(_rom[i], _rom_size[i], addr);
|
addr += rle_decode(_rom[i], _rom_size[i], addr);
|
||||||
}
|
}
|
||||||
info_P(PSTR("\n"));
|
info_P(PSTR("\n"));
|
||||||
@ -85,19 +85,19 @@ void boot_startup_rom(uint16_t init_delay)
|
|||||||
#if DO_CRC_CHECK_LOADER
|
#if DO_CRC_CHECK_LOADER
|
||||||
dump_memory(0x010000 - 0x100, 0x010000);
|
dump_memory(0x010000 - 0x100, 0x010000);
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
crc = crc_check_bulk_memory((uint32_t)0x000000,0x010000, 0x010000);
|
crc = crc_check_bulk_memory((uint32_t) 0x000000, 0x010000, 0x010000);
|
||||||
info(PSTR("crc=%x\n"),crc);
|
info(PSTR("crc=%x\n"), crc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//snes_irq_lo();
|
// snes_irq_lo();
|
||||||
//snes_irq_off();
|
// snes_irq_off();
|
||||||
//snes_hirom();
|
// snes_hirom();
|
||||||
//snes_wr_disable();
|
// snes_wr_disable();
|
||||||
|
|
||||||
//system_set_bus_snes();
|
// system_set_bus_snes();
|
||||||
//system_set_rom_hirom();
|
// system_set_rom_hirom();
|
||||||
//system_set_wr_disable();
|
// system_set_wr_disable();
|
||||||
//system_snes_irq_off();
|
// system_snes_irq_off();
|
||||||
|
|
||||||
snes_irq_lo();
|
snes_irq_lo();
|
||||||
system_snes_irq_off();
|
system_snes_irq_off();
|
||||||
@ -108,39 +108,46 @@ void boot_startup_rom(uint16_t init_delay)
|
|||||||
|
|
||||||
system_send_snes_reset();
|
system_send_snes_reset();
|
||||||
info_P(PSTR("Move Loader to wram"));
|
info_P(PSTR("Move Loader to wram"));
|
||||||
for (i=0;i<30;i++){
|
for (i = 0; i < 30; i++) {
|
||||||
_delay_ms(20);
|
_delay_ms(20);
|
||||||
info_P(PSTR("."));
|
info_P(PSTR("."));
|
||||||
}
|
}
|
||||||
info_P(PSTR("\n"));
|
info_P(PSTR("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void banner(){
|
void banner()
|
||||||
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
for (i=0;i<40;i++)
|
for (i = 0; i < 40; i++)
|
||||||
info_P(PSTR("\n"));
|
info_P(PSTR("\n"));
|
||||||
info_P(PSTR(" ________ .__ __ ________ ____ ________\n"));
|
info_P(PSTR
|
||||||
info_P(PSTR(" \\_____ \\ __ __|__| ____ | | __\\______ \\ _______ _/_ |/ _____/\n"));
|
(" ________ .__ __ ________ ____ ________\n"));
|
||||||
info_P(PSTR(" / / \\ \\| | \\ |/ ___\\| |/ / | | \\_/ __ \\ \\/ /| / __ \\ \n"));
|
info_P(PSTR
|
||||||
info_P(PSTR(" / \\_/. \\ | / \\ \\___| < | ` \\ ___/\\ / | \\ |__\\ \\ \n"));
|
(" \\_____ \\ __ __|__| ____ | | __\\______ \\ _______ _/_ |/ _____/\n"));
|
||||||
info_P(PSTR(" \\_____\\ \\_/____/|__|\\___ >__|_ \\/_______ /\\___ >\\_/ |___|\\_____ / \n"));
|
info_P(PSTR
|
||||||
info_P(PSTR(" \\__> \\/ \\/ \\/ \\/ \\/ \n"));
|
(" / / \\ \\| | \\ |/ ___\\| |/ / | | \\_/ __ \\ \\/ /| / __ \\ \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(" www.optixx.org\n"));
|
||||||
info_P(PSTR("\n"));
|
info_P(PSTR("\n"));
|
||||||
info_P(PSTR("System Hw: %s Sw: %s\n"),HW_VERSION,SW_VERSION);
|
info_P(PSTR("System Hw: %s Sw: %s\n"), HW_VERSION, SW_VERSION);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void transaction_status(){
|
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("\nAddr 0x%06lx\n"), usb_trans.req_addr);
|
||||||
info_P(PSTR("Banksize 0x%06lx\n"),usb_trans.req_bank_size);
|
info_P(PSTR("Bank 0x%02x\n"), usb_trans.req_bank);
|
||||||
info_P(PSTR("Bankcount 0x%02x\n"),usb_trans.req_bank_cnt);
|
info_P(PSTR("Banksize 0x%06lx\n"), usb_trans.req_bank_size);
|
||||||
info_P(PSTR("Status 0x%02x\n"),usb_trans.req_state);
|
info_P(PSTR("Bankcount 0x%02x\n"), usb_trans.req_bank_cnt);
|
||||||
info_P(PSTR("Percent %02i\n"),usb_trans.req_percent);
|
info_P(PSTR("Status 0x%02x\n"), usb_trans.req_state);
|
||||||
info_P(PSTR("TX buffer %02i\n"),usb_trans.tx_remaining);
|
info_P(PSTR("Percent %02i\n"), usb_trans.req_percent);
|
||||||
info_P(PSTR("RX buffer %02i\n"),usb_trans.rx_remaining);
|
info_P(PSTR("TX buffer %02i\n"), usb_trans.tx_remaining);
|
||||||
info_P(PSTR("Syncerr %02i\n"),usb_trans.sync_errors);
|
info_P(PSTR("RX buffer %02i\n"), usb_trans.rx_remaining);
|
||||||
|
info_P(PSTR("Syncerr %02i\n"), usb_trans.sync_errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -65,19 +65,24 @@ uint16_t do_crc_update(uint16_t crc, uint8_t * data, uint16_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint16_t crc_check_bulk_memory(uint32_t bottom_addr, uint32_t top_addr, uint32_t bank_size)
|
uint16_t crc_check_bulk_memory(uint32_t bottom_addr, uint32_t top_addr,
|
||||||
|
uint32_t bank_size)
|
||||||
{
|
{
|
||||||
uint16_t crc = 0;
|
uint16_t crc = 0;
|
||||||
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_P(DEBUG_CRC, PSTR("crc_check_bulk_memory: bottom_addr=0x%08lx top_addr=0x%08lx\n"),
|
debug_P(DEBUG_CRC,
|
||||||
bottom_addr,top_addr);
|
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++) {
|
for (addr = bottom_addr; addr < top_addr; addr++) {
|
||||||
if (addr && ((addr % bank_size) == 0)) {
|
if (addr && ((addr % bank_size) == 0)) {
|
||||||
debug_P(DEBUG_CRC, PSTR("crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n"),
|
debug_P(DEBUG_CRC,
|
||||||
req_bank,addr,crc);
|
PSTR
|
||||||
|
("crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n"),
|
||||||
|
req_bank, addr, crc);
|
||||||
req_bank++;
|
req_bank++;
|
||||||
crc = 0;
|
crc = 0;
|
||||||
}
|
}
|
||||||
@ -85,8 +90,10 @@ 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_P(DEBUG_CRC, PSTR("crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n"),
|
debug_P(DEBUG_CRC,
|
||||||
req_bank,addr,crc);
|
PSTR
|
||||||
|
("crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n"),
|
||||||
|
req_bank, addr, crc);
|
||||||
sram_bulk_read_end();
|
sram_bulk_read_end();
|
||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
@ -94,11 +101,13 @@ uint16_t crc_check_bulk_memory(uint32_t bottom_addr, uint32_t top_addr, uint32_t
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint16_t crc_check_memory_range(uint32_t start_addr, uint32_t size,uint8_t *buffer)
|
uint16_t crc_check_memory_range(uint32_t start_addr, uint32_t size,
|
||||||
|
uint8_t * buffer)
|
||||||
{
|
{
|
||||||
uint16_t crc = 0;
|
uint16_t crc = 0;
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
for (addr = start_addr; addr < start_addr + size; addr += TRANSFER_BUFFER_SIZE) {
|
for (addr = start_addr; addr < start_addr + size;
|
||||||
|
addr += TRANSFER_BUFFER_SIZE) {
|
||||||
sram_bulk_copy_into_buffer(addr, buffer, TRANSFER_BUFFER_SIZE);
|
sram_bulk_copy_into_buffer(addr, buffer, TRANSFER_BUFFER_SIZE);
|
||||||
crc = do_crc_update(crc, buffer, TRANSFER_BUFFER_SIZE);
|
crc = do_crc_update(crc, buffer, TRANSFER_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,9 +27,11 @@
|
|||||||
|
|
||||||
|
|
||||||
uint16_t crc_xmodem_update(uint16_t crc, uint8_t data);
|
uint16_t crc_xmodem_update(uint16_t crc, uint8_t data);
|
||||||
uint16_t do_crc(uint8_t * data,uint16_t size);
|
uint16_t do_crc(uint8_t * data, uint16_t size);
|
||||||
uint16_t do_crc_update(uint16_t crc,uint8_t * data,uint16_t size);
|
uint16_t do_crc_update(uint16_t crc, uint8_t * data, uint16_t size);
|
||||||
uint16_t crc_check_memory_range(uint32_t start_addr, uint32_t size,uint8_t *buffer);
|
uint16_t crc_check_memory_range(uint32_t start_addr, uint32_t size,
|
||||||
uint16_t crc_check_bulk_memory(uint32_t bottom_addr, uint32_t bank_size,uint32_t top_addr);
|
uint8_t * buffer);
|
||||||
|
uint16_t crc_check_bulk_memory(uint32_t bottom_addr, uint32_t bank_size,
|
||||||
|
uint32_t top_addr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -28,11 +28,12 @@
|
|||||||
|
|
||||||
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... */
|
||||||
|
|
||||||
#if defined(NO_DEBUG) && defined(__GNUC__)
|
#if defined(NO_DEBUG) && defined(__GNUC__)
|
||||||
#else
|
#else
|
||||||
void debug(int level, char* format, ...) {
|
void debug(int level, char *format, ...)
|
||||||
|
{
|
||||||
#ifdef NO_DEBUG
|
#ifdef NO_DEBUG
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@ -47,23 +48,23 @@ void debug(int level, char* format, ...) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NO_INFO
|
#ifndef NO_INFO
|
||||||
uint8_t buffer_debug[FORMAT_BUFFER_LEN];
|
uint8_t buffer_debug[FORMAT_BUFFER_LEN];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(NO_DEBUG) && defined(__GNUC__)
|
#if defined(NO_DEBUG) && defined(__GNUC__)
|
||||||
#else
|
#else
|
||||||
void debug_P(int level, PGM_P 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);
|
strlcpy_P((char *) buffer_debug, format, FORMAT_BUFFER_LEN);
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
vprintf((char*)buffer_debug, args);
|
vprintf((char *) buffer_debug, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -29,27 +29,30 @@
|
|||||||
#include <avr/pgmspace.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
|
/*
|
||||||
arguments. We use this extension here to preprocess pmesg away. */
|
* gcc's cpp has extensions; it allows for macros with a variable number of arguments. We use this extension here to preprocess pmesg away.
|
||||||
|
*/
|
||||||
#define debug(level, format, args...) ((void)0)
|
#define debug(level, format, args...) ((void)0)
|
||||||
#else
|
#else
|
||||||
void debug(int level, char *format, ...);
|
void debug(int level, char *format, ...);
|
||||||
/* print a message, if it is considered significant enough.
|
/*
|
||||||
Adapted from [K&R2], p. 174 */
|
* print a message, if it is considered significant enough. Adapted from [K&R2], p. 174
|
||||||
|
*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#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
|
/*
|
||||||
arguments. We use this extension here to preprocess pmesg away. */
|
* 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)
|
#define debug_P(level, format, args...) ((void)0)
|
||||||
#else
|
#else
|
||||||
void debug_P(int level, PGM_P format, ...);
|
void debug_P(int level, PGM_P format, ...);
|
||||||
/* print a message, if it is considered significant enough.
|
/*
|
||||||
Adapted from [K&R2], p. 174 */
|
* print a message, if it is considered significant enough. Adapted from [K&R2], p. 174
|
||||||
|
*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif /* DEBUG_H */
|
#endif /* DEBUG_H */
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ extern FILE uart_stdout;
|
|||||||
|
|
||||||
void dump_packet(uint32_t addr, uint32_t len, uint8_t * packet)
|
void dump_packet(uint32_t addr, uint32_t len, uint8_t * packet)
|
||||||
{
|
{
|
||||||
uint16_t i,j;
|
uint16_t i, j;
|
||||||
uint16_t sum = 0;
|
uint16_t sum = 0;
|
||||||
uint8_t clear = 0;
|
uint8_t clear = 0;
|
||||||
|
|
||||||
@ -71,8 +71,8 @@ void dump_memory(uint32_t bottom_addr, uint32_t top_addr)
|
|||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
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_P(PSTR("\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();
|
||||||
|
|||||||
@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
void dump_memory(uint32_t bottom_addr, uint32_t top_addr);
|
void dump_memory(uint32_t bottom_addr, uint32_t top_addr);
|
||||||
|
|
||||||
void dump_packet(uint32_t addr,uint32_t len,uint8_t *packet);
|
void dump_packet(uint32_t addr, uint32_t len, uint8_t * packet);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,8 @@ extern FILE uart_stdout;
|
|||||||
#define info(format, args...) ((void)0)
|
#define info(format, args...) ((void)0)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
void info(char* format, ...) {
|
void info(char *format, ...)
|
||||||
|
{
|
||||||
#ifdef NO_INFO
|
#ifdef NO_INFO
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@ -51,7 +52,7 @@ void info(char* format, ...) {
|
|||||||
|
|
||||||
|
|
||||||
#ifndef NO_INFO
|
#ifndef NO_INFO
|
||||||
uint8_t buffer_info[FORMAT_BUFFER_LEN];
|
uint8_t buffer_info[FORMAT_BUFFER_LEN];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(NO_INFO) && defined(__GNUC__)
|
#if defined(NO_INFO) && defined(__GNUC__)
|
||||||
@ -59,16 +60,16 @@ void info(char* format, ...) {
|
|||||||
#define info(format, args...) ((void)0)
|
#define info(format, args...) ((void)0)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
void info_P(PGM_P format, ...) {
|
void info_P(PGM_P format, ...)
|
||||||
|
{
|
||||||
#ifdef NO_INFO
|
#ifdef NO_INFO
|
||||||
|
|
||||||
#else
|
#else
|
||||||
strlcpy_P((char*)buffer_info,format,FORMAT_BUFFER_LEN);
|
strlcpy_P((char *) buffer_info, format, FORMAT_BUFFER_LEN);
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
vprintf((char*)buffer_info, args);
|
vprintf((char *) buffer_info, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -29,24 +29,28 @@
|
|||||||
#include <avr/pgmspace.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
|
/*
|
||||||
arguments. We use this extension here to preprocess pmesg away. */
|
* gcc's cpp has extensions; it allows for macros with a variable number of arguments. We use this extension here to preprocess pmesg away.
|
||||||
|
*/
|
||||||
#define info(format, args...) ((void)0)
|
#define info(format, args...) ((void)0)
|
||||||
#else
|
#else
|
||||||
void info(char *format, ...);
|
void info(char *format, ...);
|
||||||
/* print a message, if it is considered significant enough.
|
/*
|
||||||
Adapted from [K&R2], p. 174 */
|
* print a message, if it is considered significant enough. Adapted from [K&R2], p. 174
|
||||||
|
*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#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
|
/*
|
||||||
arguments. We use this extension here to preprocess pmesg away. */
|
* 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)
|
#define info_P(format, args...) ((void)0)
|
||||||
#else
|
#else
|
||||||
void info_P(PGM_P format, ...);
|
void info_P(PGM_P format, ...);
|
||||||
/* print a message, if it is considered significant enough.
|
/*
|
||||||
Adapted from [K&R2], p. 174 */
|
* print a message, if it is considered significant enough. Adapted from [K&R2], p. 174
|
||||||
|
*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -29,8 +29,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "usbdrv.h"
|
#include "usbdrv.h"
|
||||||
#include "oddebug.h" /* This is also an example for using debug
|
#include "oddebug.h" /* This is also an example for using debug macros */
|
||||||
* macros */
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
#include "sram.h"
|
#include "sram.h"
|
||||||
@ -40,17 +39,19 @@ extern system_t system;
|
|||||||
|
|
||||||
void (*jump_to_app) (void) = 0x0000;
|
void (*jump_to_app) (void) = 0x0000;
|
||||||
|
|
||||||
void irq_init(){
|
void irq_init()
|
||||||
|
{
|
||||||
cli();
|
cli();
|
||||||
PCMSK3 |=(1<<PCINT27);
|
PCMSK3 |= (1 << PCINT27);
|
||||||
PCICR |= (1<<PCIE3);
|
PCICR |= (1 << PCIE3);
|
||||||
sei();
|
sei();
|
||||||
system.reset_irq = RESET_IRQ_ON;
|
system.reset_irq = RESET_IRQ_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
void irq_stop(){
|
void irq_stop()
|
||||||
|
{
|
||||||
cli();
|
cli();
|
||||||
PCMSK3 &=~(1<<PCINT27);
|
PCMSK3 &= ~(1 << PCINT27);
|
||||||
sei();
|
sei();
|
||||||
system.reset_irq = RESET_IRQ_OFF;
|
system.reset_irq = RESET_IRQ_OFF;
|
||||||
}
|
}
|
||||||
@ -65,12 +66,11 @@ void leave_application(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ISR (SIG_PIN_CHANGE3)
|
ISR(SIG_PIN_CHANGE3)
|
||||||
{
|
{
|
||||||
if (snes_reset_test()){
|
if (snes_reset_test()) {
|
||||||
info_P(PSTR("Catch SNES reset button\n"));
|
info_P(PSTR("Catch SNES reset button\n"));
|
||||||
info_P(PSTR("Set watchdog...\n"));
|
info_P(PSTR("Set watchdog...\n"));
|
||||||
leave_application();
|
leave_application();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
5842
avr/usbload/loader.c
5842
avr/usbload/loader.c
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
File: qd16boot01.smc
|
* File: qd16boot01.smc Time: Fri, 30 Oct 2009 16:49:11
|
||||||
Time: Fri, 30 Oct 2009 16:49:11
|
*/
|
||||||
*/
|
|
||||||
#ifndef __FIFO_H__
|
#ifndef __FIFO_H__
|
||||||
#define __FIFO_H__
|
#define __FIFO_H__
|
||||||
|
|
||||||
|
|||||||
@ -70,20 +70,24 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
|
|
||||||
usb_trans.req_bank = 0;
|
usb_trans.req_bank = 0;
|
||||||
usb_trans.rx_remaining = 0;
|
usb_trans.rx_remaining = 0;
|
||||||
debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_INIT: %i %i\n"), rq->wValue.word,
|
debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_INIT: %i %i\n"),
|
||||||
rq->wIndex.word);
|
rq->wValue.word, rq->wIndex.word);
|
||||||
usb_trans.req_bank_size = (uint32_t) (1L << rq->wValue.word);
|
usb_trans.req_bank_size = (uint32_t) (1L << rq->wValue.word);
|
||||||
usb_trans.req_bank_cnt = rq->wIndex.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_addr_end =
|
||||||
|
(uint32_t) usb_trans.req_bank_size * usb_trans.req_bank_cnt;
|
||||||
usb_trans.req_percent = 0;
|
usb_trans.req_percent = 0;
|
||||||
usb_trans.req_percent_last = 0;
|
usb_trans.req_percent_last = 0;
|
||||||
usb_trans.sync_errors = 0;
|
usb_trans.sync_errors = 0;
|
||||||
debug_P(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
PSTR("USB_BULK_UPLOAD_INIT: bank_size=0x%08lx bank_cnt=0x%x end_addr=0x%08lx\n"),
|
PSTR
|
||||||
usb_trans.req_bank_size, usb_trans.req_bank_cnt, usb_trans.req_addr_end);
|
("USB_BULK_UPLOAD_INIT: bank_size=0x%08lx bank_cnt=0x%x end_addr=0x%08lx\n"),
|
||||||
|
usb_trans.req_bank_size, usb_trans.req_bank_cnt,
|
||||||
|
usb_trans.req_addr_end);
|
||||||
|
|
||||||
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_START, 0);
|
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_START, 0);
|
||||||
shared_memory_write(SHARED_MEM_TX_CMD_BANK_COUNT, usb_trans.req_bank_cnt);
|
shared_memory_write(SHARED_MEM_TX_CMD_BANK_COUNT,
|
||||||
|
usb_trans.req_bank_cnt);
|
||||||
#if DO_TIMER
|
#if DO_TIMER
|
||||||
if (usb_trans.req_addr == 0x000000) {
|
if (usb_trans.req_addr == 0x000000) {
|
||||||
#ifndef NO_DEBUG
|
#ifndef NO_DEBUG
|
||||||
@ -104,19 +108,22 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (usb_trans.req_addr && usb_trans.req_addr % usb_trans.req_bank_size == 0) {
|
if (usb_trans.req_addr
|
||||||
|
&& usb_trans.req_addr % usb_trans.req_bank_size == 0) {
|
||||||
#if DO_TIMER
|
#if DO_TIMER
|
||||||
#ifndef NO_DEBUG
|
#ifndef NO_DEBUG
|
||||||
#ifdef FLT_DEBUG
|
#ifdef FLT_DEBUG
|
||||||
debug_P(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
PSTR("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
|
PSTR
|
||||||
usb_trans.req_bank, usb_trans.req_addr, timer_stop());
|
("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
|
||||||
|
usb_trans.req_bank, usb_trans.req_addr, timer_stop());
|
||||||
#else
|
#else
|
||||||
debug_P(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
PSTR("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%i\n"),
|
PSTR
|
||||||
usb_trans.req_bank, usb_trans.req_addr, timer_stop_int());
|
("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%i\n"),
|
||||||
|
usb_trans.req_bank, usb_trans.req_addr, timer_stop_int());
|
||||||
#endif
|
#endif
|
||||||
timer_start();
|
timer_start();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
usb_trans.req_bank++;
|
usb_trans.req_bank++;
|
||||||
@ -137,31 +144,37 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
usb_trans.rx_remaining = rq->wLength.word;
|
usb_trans.rx_remaining = rq->wLength.word;
|
||||||
|
|
||||||
#if DO_SHM
|
#if DO_SHM
|
||||||
usb_trans.req_percent = (uint32_t)( 100 * usb_trans.req_addr ) / usb_trans.req_addr_end;
|
usb_trans.req_percent =
|
||||||
if (usb_trans.req_percent!=usb_trans.req_percent_last){
|
(uint32_t) (100 * usb_trans.req_addr) / usb_trans.req_addr_end;
|
||||||
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_PROGESS, usb_trans.req_percent);
|
if (usb_trans.req_percent != usb_trans.req_percent_last) {
|
||||||
|
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_PROGESS,
|
||||||
|
usb_trans.req_percent);
|
||||||
}
|
}
|
||||||
usb_trans.req_percent_last = usb_trans.req_percent;
|
usb_trans.req_percent_last = usb_trans.req_percent;
|
||||||
shared_memory_scratchpad_region_save_helper(usb_trans.req_addr);
|
shared_memory_scratchpad_region_save_helper(usb_trans.req_addr);
|
||||||
#endif
|
#endif
|
||||||
if (usb_trans.req_addr && (usb_trans.req_addr % usb_trans.req_bank_size) == 0) {
|
if (usb_trans.req_addr
|
||||||
|
&& (usb_trans.req_addr % usb_trans.req_bank_size) == 0) {
|
||||||
#if DO_TIMER
|
#if DO_TIMER
|
||||||
#ifndef NO_DEBUG
|
#ifndef NO_DEBUG
|
||||||
#ifdef FLT_DEBUG
|
#ifdef FLT_DEBUG
|
||||||
debug_P(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
|
PSTR
|
||||||
usb_trans.req_bank, usb_trans.req_addr, timer_stop());
|
("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
|
||||||
|
usb_trans.req_bank, usb_trans.req_addr, timer_stop());
|
||||||
#else
|
#else
|
||||||
debug_P(DEBUG_USB,
|
debug_P(DEBUG_USB,
|
||||||
PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%i\n"),
|
PSTR
|
||||||
usb_trans.req_bank, usb_trans.req_addr, timer_stop_int());
|
("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%i\n"),
|
||||||
|
usb_trans.req_bank, usb_trans.req_addr, timer_stop_int());
|
||||||
#endif
|
#endif
|
||||||
timer_start();
|
timer_start();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
usb_trans.req_bank++;
|
usb_trans.req_bank++;
|
||||||
#if DO_SHM
|
#if DO_SHM
|
||||||
shared_memory_write(SHARED_MEM_TX_CMD_BANK_CURRENT, usb_trans.req_bank);
|
shared_memory_write(SHARED_MEM_TX_CMD_BANK_CURRENT,
|
||||||
|
usb_trans.req_bank);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
ret_len = USB_MAX_TRANS;
|
ret_len = USB_MAX_TRANS;
|
||||||
@ -184,8 +197,10 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
usb_trans.req_addr = rq->wValue.word;
|
usb_trans.req_addr = rq->wValue.word;
|
||||||
usb_trans.req_addr = usb_trans.req_addr << 16;
|
usb_trans.req_addr = usb_trans.req_addr << 16;
|
||||||
usb_trans.req_addr = usb_trans.req_addr | rq->wIndex.word;
|
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);
|
debug_P(DEBUG_USB, PSTR("USB_CRC: addr=0x%08lx \n"),
|
||||||
crc_check_bulk_memory(0x000000, usb_trans.req_addr, usb_trans.req_bank_size);
|
usb_trans.req_addr);
|
||||||
|
crc_check_bulk_memory(0x000000, usb_trans.req_addr,
|
||||||
|
usb_trans.req_bank_size);
|
||||||
ret_len = 0;
|
ret_len = 0;
|
||||||
/*
|
/*
|
||||||
* -------------------------------------------------------------------------
|
* -------------------------------------------------------------------------
|
||||||
@ -226,8 +241,9 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
void globals_init(){
|
void globals_init()
|
||||||
memset(&usb_trans,0,sizeof(usb_transaction_t));
|
{
|
||||||
|
memset(&usb_trans, 0, sizeof(usb_transaction_t));
|
||||||
|
|
||||||
usb_trans.req_addr = 0;
|
usb_trans.req_addr = 0;
|
||||||
usb_trans.req_addr_end = 0;
|
usb_trans.req_addr_end = 0;
|
||||||
@ -280,7 +296,9 @@ int main(void)
|
|||||||
|
|
||||||
#if DO_CRC_CHECK
|
#if DO_CRC_CHECK
|
||||||
info_P(PSTR("-->CRC Check\n"));
|
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);
|
crc_check_bulk_memory(0x000000,
|
||||||
|
usb_trans.req_bank_size * usb_trans.req_bank_cnt,
|
||||||
|
usb_trans.req_bank_size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
system_set_rom_mode(&usb_trans);
|
system_set_rom_mode(&usb_trans);
|
||||||
@ -299,7 +317,7 @@ int main(void)
|
|||||||
info_P(PSTR("-->Switch TO AVR\n"));
|
info_P(PSTR("-->Switch TO AVR\n"));
|
||||||
shared_memory_init();
|
shared_memory_init();
|
||||||
irq_init();
|
irq_init();
|
||||||
if(usb_trans.loader_enabled) {
|
if (usb_trans.loader_enabled) {
|
||||||
boot_startup_rom(50);
|
boot_startup_rom(50);
|
||||||
} else {
|
} else {
|
||||||
system_set_bus_avr();
|
system_set_bus_avr();
|
||||||
|
|||||||
@ -31,11 +31,15 @@
|
|||||||
#define PWM_SINE_MAX 64
|
#define PWM_SINE_MAX 64
|
||||||
#define PWM_OVERFLOW_MAX 1024
|
#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,
|
0x7f, 0x8b, 0x97, 0xa4, 0xaf, 0xbb, 0xc5, 0xcf, 0xd9, 0xe1, 0xe8, 0xef,
|
||||||
0xfd,0xfd,0xfb,0xf8,0xf3,0xee,0xe7,0xe0,0xd7,0xce,0xc4,0xb9,0xae,0xa2,0x96,0x89,
|
0xf4, 0xf8, 0xfb, 0xfd,
|
||||||
0x7e,0x71,0x65,0x59,0x4d,0x42,0x37,0x2d,0x24,0x1c,0x15,0x0f,0x09,0x05,0x03,0x01,
|
0xfd, 0xfd, 0xfb, 0xf8, 0xf3, 0xee, 0xe7, 0xe0, 0xd7, 0xce, 0xc4, 0xb9,
|
||||||
0x01,0x01,0x03,0x07,0x0b,0x11,0x17,0x1f,0x28,0x31,0x3b,0x46,0x52,0x5e,0x6a,0x76
|
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 uint8_t pwm_setting;
|
||||||
@ -43,20 +47,21 @@ volatile uint16_t pwm_overflow;
|
|||||||
volatile uint8_t pwm_idx;
|
volatile uint8_t pwm_idx;
|
||||||
volatile uint16_t pwm_overflow_max;
|
volatile uint16_t pwm_overflow_max;
|
||||||
|
|
||||||
ISR(TIMER2_COMPA_vect) {
|
ISR(TIMER2_COMPA_vect)
|
||||||
static uint8_t pwm_cnt=0;
|
{
|
||||||
OCR2A += (uint16_t)T_PWM;
|
static uint8_t pwm_cnt = 0;
|
||||||
|
OCR2A += (uint16_t) T_PWM;
|
||||||
|
|
||||||
if (pwm_setting> pwm_cnt)
|
if (pwm_setting > pwm_cnt)
|
||||||
led_pwm_on();
|
led_pwm_on();
|
||||||
else
|
else
|
||||||
led_pwm_off();
|
led_pwm_off();
|
||||||
|
|
||||||
if (pwm_cnt==(uint8_t)(PWM_STEPS-1))
|
if (pwm_cnt == (uint8_t) (PWM_STEPS - 1))
|
||||||
pwm_cnt=0;
|
pwm_cnt = 0;
|
||||||
else
|
else
|
||||||
pwm_cnt++;
|
pwm_cnt++;
|
||||||
if (pwm_overflow_max == pwm_overflow++ ){
|
if (pwm_overflow_max == pwm_overflow++) {
|
||||||
pwm_setting = pwm_sine_table[pwm_idx++];
|
pwm_setting = pwm_sine_table[pwm_idx++];
|
||||||
pwm_overflow = 0;
|
pwm_overflow = 0;
|
||||||
if (PWM_SINE_MAX == pwm_idx)
|
if (PWM_SINE_MAX == pwm_idx)
|
||||||
@ -64,38 +69,45 @@ volatile uint16_t pwm_overflow_max;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pwm_speed(uint16_t val) {
|
void pwm_speed(uint16_t val)
|
||||||
|
{
|
||||||
pwm_overflow_max = val;
|
pwm_overflow_max = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pwm_speed_slow(uint16_t val) {
|
void pwm_speed_slow(uint16_t val)
|
||||||
pwm_overflow_max = PWM_OVERFLOW_MAX * 2 ;
|
{
|
||||||
|
pwm_overflow_max = PWM_OVERFLOW_MAX * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pwm_speed_fast(uint16_t val) {
|
void pwm_speed_fast(uint16_t val)
|
||||||
|
{
|
||||||
pwm_overflow_max = PWM_OVERFLOW_MAX / 2;
|
pwm_overflow_max = PWM_OVERFLOW_MAX / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pwm_speed_normal(uint16_t val) {
|
void pwm_speed_normal(uint16_t val)
|
||||||
|
{
|
||||||
pwm_overflow_max = PWM_OVERFLOW_MAX;
|
pwm_overflow_max = PWM_OVERFLOW_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void pwm_set(uint8_t val) {
|
void pwm_set(uint8_t val)
|
||||||
|
{
|
||||||
pwm_setting = val;
|
pwm_setting = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pwm_stop(void) {
|
void pwm_stop(void)
|
||||||
while(pwm_setting!=0xfd);
|
{
|
||||||
|
while (pwm_setting != 0xfd);
|
||||||
TIMSK2 = 0;
|
TIMSK2 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pwm_init(void) {
|
void pwm_init(void)
|
||||||
|
{
|
||||||
pwm_overflow_max = PWM_OVERFLOW_MAX;
|
pwm_overflow_max = PWM_OVERFLOW_MAX;
|
||||||
pwm_setting = 0x7f;
|
pwm_setting = 0x7f;
|
||||||
pwm_overflow = 0;
|
pwm_overflow = 0;
|
||||||
//cli();
|
// cli();
|
||||||
TCCR2B = 1;
|
TCCR2B = 1;
|
||||||
TIMSK2 |= (1<<OCIE2A);
|
TIMSK2 |= (1 << OCIE2A);
|
||||||
sei();
|
sei();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,16 +21,16 @@
|
|||||||
#ifndef __PWM_H__
|
#ifndef __PWM_H__
|
||||||
#define __PWM_H__
|
#define __PWM_H__
|
||||||
|
|
||||||
#define F_PWM 100 // PWM-Frequenz in Hz
|
#define F_PWM 100 // PWM-Frequenz in Hz
|
||||||
#define PWM_STEPS 256 // PWM-Schritte pro Zyklus(1..256)
|
#define PWM_STEPS 256 // PWM-Schritte pro Zyklus(1..256)
|
||||||
|
|
||||||
#define T_PWM (F_CPU/(F_PWM*PWM_STEPS)) // Systemtakte pro PWM-Takt
|
#define T_PWM (F_CPU/(F_PWM*PWM_STEPS)) // Systemtakte pro PWM-Takt
|
||||||
|
|
||||||
#if (T_PWM<(93+5))
|
#if (T_PWM<(93+5))
|
||||||
#error T_PWM zu klein, F_CPU muss vergrösst werden oder F_PWM oder PWM_STEPS verkleinert werden
|
#error T_PWM zu klein, F_CPU muss vergrösst werden oder F_PWM oder PWM_STEPS verkleinert werden
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void pwm_init(void);
|
void pwm_init(void);
|
||||||
void pwm_stop(void);
|
void pwm_stop(void);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -50,11 +50,11 @@ typedef struct usb_transaction_t {
|
|||||||
uint8_t req_percent_last;
|
uint8_t req_percent_last;
|
||||||
uint8_t req_state;
|
uint8_t req_state;
|
||||||
uint8_t rx_remaining;
|
uint8_t rx_remaining;
|
||||||
uint8_t tx_remaining ;
|
uint8_t tx_remaining;
|
||||||
uint16_t sync_errors;
|
uint16_t sync_errors;
|
||||||
uint8_t tx_buffer[32];
|
uint8_t tx_buffer[32];
|
||||||
uint8_t rx_buffer[8];
|
uint8_t rx_buffer[8];
|
||||||
uint8_t loader_enabled;
|
uint8_t loader_enabled;
|
||||||
} usb_transaction_t;
|
} usb_transaction_t;
|
||||||
|
|
||||||
#endif /* __REQUESTS_H_INCLUDED__ */
|
#endif /* __REQUESTS_H_INCLUDED__ */
|
||||||
|
|||||||
@ -48,25 +48,35 @@ uint8_t scratchpad_locked_rx = 1;
|
|||||||
uint8_t scratchpad_locked_tx = 1;
|
uint8_t scratchpad_locked_tx = 1;
|
||||||
|
|
||||||
|
|
||||||
void shared_memory_init(void){
|
void shared_memory_init(void)
|
||||||
|
{
|
||||||
scratchpad_locked_rx = 1;
|
scratchpad_locked_rx = 1;
|
||||||
scratchpad_locked_tx = 1;
|
scratchpad_locked_tx = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint8_t shared_memory_scratchpad_region_save_helper(uint32_t addr){
|
uint8_t shared_memory_scratchpad_region_save_helper(uint32_t addr)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if DO_SHM_SCRATCHPAD
|
#if DO_SHM_SCRATCHPAD
|
||||||
if(addr > (SHARED_MEM_TX_LOC_STATE + (SHARED_MEM_TX_LOC_SIZE )) && scratchpad_locked_tx){
|
if (addr > (SHARED_MEM_TX_LOC_STATE + (SHARED_MEM_TX_LOC_SIZE))
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_save_helper: open tx addr=0x%06lx\n"),addr);
|
&& 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))
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_save_helper: open rx addr=0x%06lx\n"),addr);
|
&& scratchpad_locked_rx) {
|
||||||
|
debug_P(DEBUG_SHM,
|
||||||
|
PSTR
|
||||||
|
("shared_memory_scratchpad_region_save_helper: open rx addr=0x%06lx\n"),
|
||||||
|
addr);
|
||||||
shared_memory_scratchpad_region_rx_save();
|
shared_memory_scratchpad_region_rx_save();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -81,25 +91,32 @@ void shared_memory_scratchpad_region_tx_save()
|
|||||||
|
|
||||||
#if SHARED_SCRATCHPAD_CRC
|
#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 +
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"),crc);
|
SHARED_MEM_TX_LOC_SIZE), 0x8000);
|
||||||
|
debug_P(DEBUG_SHM,
|
||||||
|
PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"), crc);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: unlock\n"));
|
debug_P(DEBUG_SHM,
|
||||||
sram_bulk_copy_into_buffer((uint32_t)SHARED_MEM_TX_LOC_STATE,scratchpad_region_tx,
|
PSTR("shared_memory_scratchpad_region_tx_save: unlock\n"));
|
||||||
(uint32_t)SHARED_MEM_TX_LOC_SIZE);
|
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;
|
scratchpad_locked_tx = 0;
|
||||||
|
|
||||||
#if SHARED_SCRATCHPAD_CRC
|
#if SHARED_SCRATCHPAD_CRC
|
||||||
do_crc_update(0, scratchpad_region_tx,SHARED_MEM_TX_LOC_SIZE);
|
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);
|
debug_P(DEBUG_SHM,
|
||||||
|
PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"), crc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if SHARED_SCRATCHPAD_DUMP
|
#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,
|
||||||
dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
|
scratchpad_region_tx);
|
||||||
|
dump_memory(SHARED_MEM_TX_LOC_STATE,
|
||||||
|
SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
|
||||||
#endif
|
#endif
|
||||||
sram_bulk_addr_restore();
|
sram_bulk_addr_restore();
|
||||||
|
|
||||||
@ -111,24 +128,31 @@ void shared_memory_scratchpad_region_rx_save()
|
|||||||
sram_bulk_addr_save();
|
sram_bulk_addr_save();
|
||||||
#if SHARED_SCRATCHPAD_CRC
|
#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 +
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_save: crc=%x\n"),crc);
|
SHARED_MEM_RX_LOC_SIZE), 0x8000);
|
||||||
|
debug_P(DEBUG_SHM,
|
||||||
|
PSTR("shared_memory_scratchpad_region_rx_save: crc=%x\n"), crc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_save: unlock\n"));
|
debug_P(DEBUG_SHM,
|
||||||
sram_bulk_copy_into_buffer((uint32_t)SHARED_MEM_RX_LOC_STATE,scratchpad_region_rx,
|
PSTR("shared_memory_scratchpad_region_rx_save: unlock\n"));
|
||||||
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
|
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;
|
scratchpad_locked_rx = 0;
|
||||||
|
|
||||||
#if SHARED_SCRATCHPAD_CRC
|
#if SHARED_SCRATCHPAD_CRC
|
||||||
do_crc_update(0, scratchpad_region_rx,SHARED_MEM_RX_LOC_SIZE);
|
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);
|
debug_P(DEBUG_SHM,
|
||||||
|
PSTR("shared_memory_scratchpad_region_rx_save: crc=%x\n"), crc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if SHARED_SCRATCHPAD_DUMP
|
#if SHARED_SCRATCHPAD_DUMP
|
||||||
dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_SIZE, scratchpad_region_rx);
|
dump_packet(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);
|
scratchpad_region_rx);
|
||||||
|
dump_memory(SHARED_MEM_RX_LOC_STATE,
|
||||||
|
SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE);
|
||||||
#endif
|
#endif
|
||||||
sram_bulk_addr_restore();
|
sram_bulk_addr_restore();
|
||||||
|
|
||||||
@ -138,29 +162,39 @@ 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_P(DEBUG_SHM,
|
||||||
|
PSTR("shared_memory_scratchpad_region_tx_restore: lock\n"));
|
||||||
|
|
||||||
#if SHARED_SCRATCHPAD_DUMP
|
#if SHARED_SCRATCHPAD_DUMP
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: memory\n"));
|
debug_P(DEBUG_SHM,
|
||||||
dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
|
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
|
#endif
|
||||||
|
|
||||||
sram_bulk_copy_from_buffer((uint32_t)SHARED_MEM_TX_LOC_STATE,scratchpad_region_tx,
|
sram_bulk_copy_from_buffer((uint32_t) SHARED_MEM_TX_LOC_STATE,
|
||||||
(uint32_t)SHARED_MEM_TX_LOC_SIZE);
|
scratchpad_region_tx,
|
||||||
|
(uint32_t) SHARED_MEM_TX_LOC_SIZE);
|
||||||
scratchpad_locked_tx = 1;
|
scratchpad_locked_tx = 1;
|
||||||
|
|
||||||
#if SHARED_SCRATCHPAD_DUMP
|
#if SHARED_SCRATCHPAD_DUMP
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: buffer\n"));
|
debug_P(DEBUG_SHM,
|
||||||
dump_packet(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_SIZE, scratchpad_region_tx);
|
PSTR("shared_memory_scratchpad_region_tx_restore: buffer\n"));
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: memory\n"));
|
dump_packet(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);
|
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
|
#endif
|
||||||
|
|
||||||
#if SHARED_SCRATCHPAD_CRC
|
#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 +
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: crc=%x\n"),crc);
|
SHARED_MEM_TX_LOC_SIZE), 0x8000);
|
||||||
|
debug_P(DEBUG_SHM,
|
||||||
|
PSTR("shared_memory_scratchpad_region_tx_restore: crc=%x\n"), crc);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,29 +205,39 @@ void shared_memory_scratchpad_region_rx_restore()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: lock\n"));
|
debug_P(DEBUG_SHM,
|
||||||
|
PSTR("shared_memory_scratchpad_region_rx_restore: lock\n"));
|
||||||
|
|
||||||
#if SHARED_SCRATCHPAD_DUMP
|
#if SHARED_SCRATCHPAD_DUMP
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: memory\n"));
|
debug_P(DEBUG_SHM,
|
||||||
dump_memory(SHARED_MEM_RX_LOC_STATE - 0x10, SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE);
|
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
|
||||||
|
|
||||||
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,
|
||||||
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
|
scratchpad_region_rx,
|
||||||
|
(uint32_t) SHARED_MEM_RX_LOC_SIZE);
|
||||||
scratchpad_locked_rx = 1;
|
scratchpad_locked_rx = 1;
|
||||||
|
|
||||||
#if SHARED_SCRATCHPAD_DUMP
|
#if SHARED_SCRATCHPAD_DUMP
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: buffer\n"));
|
debug_P(DEBUG_SHM,
|
||||||
dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_SIZE, scratchpad_region_rx);
|
PSTR("shared_memory_scratchpad_region_rx_restore: buffer\n"));
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: memory\n"));
|
dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_SIZE,
|
||||||
dump_memory(SHARED_MEM_RX_LOC_STATE - 0x10, 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 SHARED_SCRATCHPAD_CRC
|
#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 +
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: crc=%x\n"),crc);
|
SHARED_MEM_RX_LOC_SIZE), 0x8000);
|
||||||
|
debug_P(DEBUG_SHM,
|
||||||
|
PSTR("shared_memory_scratchpad_region_rx_restore: crc=%x\n"), crc);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,13 +275,14 @@ void shared_memory_write(uint8_t cmd, uint8_t value)
|
|||||||
{
|
{
|
||||||
#if DO_SHM
|
#if DO_SHM
|
||||||
#if DO_SHM_SCRATCHPAD
|
#if DO_SHM_SCRATCHPAD
|
||||||
if (scratchpad_locked_tx){
|
if (scratchpad_locked_tx) {
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_write: locked_tx\n"));
|
debug_P(DEBUG_SHM, PSTR("shared_memory_write: locked_tx\n"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_write: 0x%04x=0x%02x 0x%04x=0x%02x \n"),
|
debug_P(DEBUG_SHM,
|
||||||
SHARED_MEM_TX_LOC_CMD, cmd, SHARED_MEM_TX_LOC_PAYLOAD, value);
|
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();
|
sram_bulk_addr_save();
|
||||||
|
|
||||||
@ -296,12 +341,12 @@ 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 DO_SHM
|
||||||
#if DO_SHM_SCRATCHPAD
|
#if DO_SHM_SCRATCHPAD
|
||||||
if (scratchpad_locked_rx){
|
if (scratchpad_locked_rx) {
|
||||||
debug_P(DEBUG_SHM, PSTR("shared_memory_write: locked_tx\n"));
|
debug_P(DEBUG_SHM, PSTR("shared_memory_write: locked_tx\n"));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -309,17 +354,18 @@ int shared_memory_read(uint8_t *cmd, uint8_t *len,uint8_t *buffer)
|
|||||||
sram_bulk_addr_save();
|
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();
|
sram_bulk_addr_restore();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*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_P(DEBUG_SHM, PSTR("shared_memory_read: 0x%04x=0x%02x 0x%04x=0x%02x \n"),
|
debug_P(DEBUG_SHM,
|
||||||
SHARED_MEM_RX_LOC_CMD, *cmd, SHARED_MEM_RX_LOC_LEN, *len);
|
PSTR("shared_memory_read: 0x%04x=0x%02x 0x%04x=0x%02x \n"),
|
||||||
|
SHARED_MEM_RX_LOC_CMD, *cmd, SHARED_MEM_RX_LOC_LEN, *len);
|
||||||
|
|
||||||
sram_bulk_copy_into_buffer(SHARED_MEM_RX_LOC_PAYLOAD,buffer, *len);
|
sram_bulk_copy_into_buffer(SHARED_MEM_RX_LOC_PAYLOAD, buffer, *len);
|
||||||
sram_write(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_AVR_RTS);
|
sram_write(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_AVR_RTS);
|
||||||
|
|
||||||
snes_hirom();
|
snes_hirom();
|
||||||
|
|||||||
@ -56,7 +56,9 @@
|
|||||||
#define SHARED_IRQ_LOC_LO 0x00fffe
|
#define SHARED_IRQ_LOC_LO 0x00fffe
|
||||||
#define SHARED_IRQ_LOC_HI 0x00ffff
|
#define SHARED_IRQ_LOC_HI 0x00ffff
|
||||||
|
|
||||||
/* Use COP IRQ LOC for hooked IRQ handler */
|
/*
|
||||||
|
* Use COP IRQ LOC for hooked IRQ handler
|
||||||
|
*/
|
||||||
#define SHARED_IRQ_HANDLER_LO 0x0ffe4
|
#define SHARED_IRQ_HANDLER_LO 0x0ffe4
|
||||||
#define SHARED_IRQ_HANDLER_HI 0x0ffe5
|
#define SHARED_IRQ_HANDLER_HI 0x0ffe5
|
||||||
|
|
||||||
@ -71,6 +73,6 @@ void shared_memory_scratchpad_region_tx_restore();
|
|||||||
void shared_memory_scratchpad_region_rx_save();
|
void shared_memory_scratchpad_region_rx_save();
|
||||||
void shared_memory_scratchpad_region_rx_restore();
|
void shared_memory_scratchpad_region_rx_restore();
|
||||||
void shared_memory_write(uint8_t cmd, uint8_t value);
|
void shared_memory_write(uint8_t cmd, uint8_t value);
|
||||||
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);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -52,10 +52,10 @@ const char STR_SA[] PROGMEM = "SA-1";
|
|||||||
|
|
||||||
|
|
||||||
uint8_t command_buf[RECEIVE_BUF_LEN];
|
uint8_t command_buf[RECEIVE_BUF_LEN];
|
||||||
uint8_t recv_buf[RECEIVE_BUF_LEN];
|
uint8_t recv_buf[RECEIVE_BUF_LEN];
|
||||||
|
|
||||||
volatile uint8_t recv_counter = 0;
|
volatile uint8_t recv_counter = 0;
|
||||||
volatile uint8_t cr = 0;
|
volatile uint8_t cr = 0;
|
||||||
|
|
||||||
uint8_t *token_ptr;
|
uint8_t *token_ptr;
|
||||||
|
|
||||||
@ -63,188 +63,193 @@ uint8_t *token_ptr;
|
|||||||
|
|
||||||
uint8_t *get_token(void)
|
uint8_t *get_token(void)
|
||||||
{
|
{
|
||||||
uint8_t *p = token_ptr;
|
uint8_t *p = token_ptr;
|
||||||
while (*p == ' ')
|
while (*p == ' ')
|
||||||
p++;
|
p++;
|
||||||
if (*p == '\0')
|
if (*p == '\0')
|
||||||
return NULL;
|
return NULL;
|
||||||
token_ptr = p;
|
token_ptr = p;
|
||||||
do {
|
do {
|
||||||
token_ptr++;
|
token_ptr++;
|
||||||
if (*token_ptr == ' ' || *token_ptr == '\n' || *token_ptr == '\r') {
|
if (*token_ptr == ' ' || *token_ptr == '\n' || *token_ptr == '\r') {
|
||||||
*token_ptr++ = '\0';
|
*token_ptr++ = '\0';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (*token_ptr != ' ' && *token_ptr != '\n' && *token_ptr != '\r');
|
} while (*token_ptr != ' ' && *token_ptr != '\n' && *token_ptr != '\r');
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t get_dec(uint32_t *decval)
|
uint8_t get_dec(uint32_t * decval)
|
||||||
{
|
{
|
||||||
const uint8_t *t;
|
const uint8_t *t;
|
||||||
t = get_token();
|
t = get_token();
|
||||||
if (t != NULL) {
|
if (t != NULL) {
|
||||||
int x = util_sscandec(t);
|
int x = util_sscandec(t);
|
||||||
if (x < 0)
|
if (x < 0)
|
||||||
return 0;
|
return 0;
|
||||||
*decval = x;
|
*decval = x;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
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)
|
uint8_t parse_hex(const uint8_t * s, uint32_t * hexval)
|
||||||
{
|
{
|
||||||
return get_hex(hexval1) && get_hex(hexval2) && get_hex(hexval3);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
static uint8_t get_int32(uint32_t *val)
|
static uint8_t get_int32(uint32_t * val)
|
||||||
{
|
{
|
||||||
if (!get_hex(val)){
|
if (!get_hex(val)) {
|
||||||
info_P(PSTR("Invalid argument!\n"));
|
info_P(PSTR("Invalid argument!\n"));
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t get_int8(uint8_t *val)
|
static uint8_t get_int8(uint8_t * val)
|
||||||
{
|
{
|
||||||
uint32_t ret;
|
uint32_t ret;
|
||||||
if (!get_hex(&ret) ||ret > 0xff){
|
if (!get_hex(&ret) || ret > 0xff) {
|
||||||
info_P(PSTR("Invalid argument!\n"));
|
info_P(PSTR("Invalid argument!\n"));
|
||||||
return 0;
|
return 0;
|
||||||
}else{
|
} else {
|
||||||
*val = (uint8_t)ret;
|
*val = (uint8_t) ret;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
static int get_bool(void)
|
static int get_bool(void)
|
||||||
{
|
{
|
||||||
const uint8_t *t;
|
const uint8_t *t;
|
||||||
t = get_token();
|
t = get_token();
|
||||||
if (t != NULL) {
|
if (t != NULL) {
|
||||||
int result = util_sscanbool(t);
|
int result = util_sscanbool(t);
|
||||||
if (result >= 0)
|
if (result >= 0)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
info_P(PSTR("Invalid argument (should be 0 or 1)!\n"));
|
info_P(PSTR("Invalid argument (should be 0 or 1)!\n"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
void prompt(void){
|
void prompt(void)
|
||||||
|
{
|
||||||
|
|
||||||
uart_putc('\r');
|
uart_putc('\r');
|
||||||
uart_putc('\n');
|
uart_putc('\n');
|
||||||
uart_putc('>');
|
uart_putc('>');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ISR(USART0_RX_vect)
|
ISR(USART0_RX_vect)
|
||||||
{
|
{
|
||||||
UCSR0B &= (255 - (1<<RXCIE0));// Interrupts disable for RxD
|
UCSR0B &= (255 - (1 << RXCIE0)); // Interrupts disable for RxD
|
||||||
sei();
|
sei();
|
||||||
if(recv_counter == (sizeof(recv_buf)-1)) {
|
if (recv_counter == (sizeof(recv_buf) - 1)) {
|
||||||
cr=1;
|
cr = 1;
|
||||||
recv_buf[recv_counter]='\0';
|
recv_buf[recv_counter] = '\0';
|
||||||
recv_counter=0;
|
recv_counter = 0;
|
||||||
prompt();
|
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++;
|
|
||||||
}
|
}
|
||||||
}
|
recv_buf[recv_counter] = UDR0;
|
||||||
UCSR0B |= (1<<RXCIE0);
|
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 {
|
enum cmds {
|
||||||
CMD_DUMP,
|
CMD_DUMP,
|
||||||
CMD_DUMPVEC,
|
CMD_DUMPVEC,
|
||||||
CMD_DUMPHEADER,
|
CMD_DUMPHEADER,
|
||||||
CMD_CRC,
|
CMD_CRC,
|
||||||
CMD_EXIT,
|
CMD_EXIT,
|
||||||
CMD_RESET,
|
CMD_RESET,
|
||||||
CMD_RESETSNIFF,
|
CMD_RESETSNIFF,
|
||||||
CMD_IRQ,
|
CMD_IRQ,
|
||||||
CMD_AVR,
|
CMD_AVR,
|
||||||
CMD_SNES,
|
CMD_SNES,
|
||||||
CMD_LOROM,
|
CMD_LOROM,
|
||||||
CMD_HIROM,
|
CMD_HIROM,
|
||||||
CMD_WR,
|
CMD_WR,
|
||||||
CMD_SHMWR,
|
CMD_SHMWR,
|
||||||
CMD_SHMSAVE,
|
CMD_SHMSAVE,
|
||||||
CMD_SHMRESTORE,
|
CMD_SHMRESTORE,
|
||||||
CMD_LOADER,
|
CMD_LOADER,
|
||||||
CMD_RECONNECT,
|
CMD_RECONNECT,
|
||||||
CMD_STATUS,
|
CMD_STATUS,
|
||||||
CMD_SYS,
|
CMD_SYS,
|
||||||
CMD_HELP
|
CMD_HELP
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t cmdlist[][CMD_HELP] PROGMEM = {
|
uint8_t cmdlist[][CMD_HELP] PROGMEM = {
|
||||||
{"DUMP"},
|
{"DUMP"},
|
||||||
{"DUMPVEC"},
|
{"DUMPVEC"},
|
||||||
{"DUMPHEADER"},
|
{"DUMPHEADER"},
|
||||||
{"CRC"},
|
{"CRC"},
|
||||||
{"EXIT"},
|
{"EXIT"},
|
||||||
{"RESET"},
|
{"RESET"},
|
||||||
{"RESETSNIFF"},
|
{"RESETSNIFF"},
|
||||||
{"IRQ"},
|
{"IRQ"},
|
||||||
{"AVR"},
|
{"AVR"},
|
||||||
{"SNES"},
|
{"SNES"},
|
||||||
{"LOROM"},
|
{"LOROM"},
|
||||||
{"HIROM"},
|
{"HIROM"},
|
||||||
{"WR"},
|
{"WR"},
|
||||||
{"SHMWR"},
|
{"SHMWR"},
|
||||||
{"SHMSAVE"},
|
{"SHMSAVE"},
|
||||||
{"SHMRESTORE"},
|
{"SHMRESTORE"},
|
||||||
{"LOADER"},
|
{"LOADER"},
|
||||||
{"RECONNECT"},
|
{"RECONNECT"},
|
||||||
{"STATUS"},
|
{"STATUS"},
|
||||||
{"SYS"},
|
{"SYS"},
|
||||||
{"HELP"},
|
{"HELP"},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void shell_help(void){
|
void shell_help(void)
|
||||||
uint8_t i;
|
{
|
||||||
|
uint8_t i;
|
||||||
info_P(PSTR("\n"));
|
info_P(PSTR("\n"));
|
||||||
for (i=CMD_DUMP; i<CMD_HELP; i++){
|
for (i = CMD_DUMP; i < CMD_HELP; i++) {
|
||||||
info_P((PGM_P)cmdlist[i]);
|
info_P((PGM_P) cmdlist[i]);
|
||||||
info_P(PSTR("\n"));
|
info_P(PSTR("\n"));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -253,129 +258,131 @@ void shell_help(void){
|
|||||||
|
|
||||||
void shell_run(void)
|
void shell_run(void)
|
||||||
{
|
{
|
||||||
uint8_t *t;
|
uint8_t *t;
|
||||||
uint32_t arg1;
|
uint32_t arg1;
|
||||||
uint32_t arg2;
|
uint32_t arg2;
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
uint8_t c;
|
uint8_t c;
|
||||||
|
|
||||||
if (!cr)
|
if (!cr)
|
||||||
return;
|
return;
|
||||||
cr=0;
|
cr = 0;
|
||||||
strcpy((char*)command_buf, (char*)recv_buf);
|
strcpy((char *) command_buf, (char *) recv_buf);
|
||||||
|
|
||||||
token_ptr = command_buf;
|
token_ptr = command_buf;
|
||||||
t = get_token();
|
t = get_token();
|
||||||
|
|
||||||
if (t == NULL)
|
if (t == NULL)
|
||||||
shell_help();
|
shell_help();
|
||||||
|
|
||||||
util_strupper(t);
|
util_strupper(t);
|
||||||
|
|
||||||
if (strcmp_P((const char*)t,(PGM_P)cmdlist[CMD_DUMP]) == 0) {
|
if (strcmp_P((const char *) t, (PGM_P) cmdlist[CMD_DUMP]) == 0) {
|
||||||
if (get_hex_arg2(&arg1,&arg2))
|
if (get_hex_arg2(&arg1, &arg2))
|
||||||
dump_memory(arg1,arg2);
|
dump_memory(arg1, arg2);
|
||||||
else
|
else
|
||||||
info_P(PSTR("DUMP <start addr> <end addr>\n"));
|
info_P(PSTR("DUMP <start addr> <end addr>\n"));
|
||||||
|
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_CRC]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_CRC]) == 0) {
|
||||||
if (get_hex_arg2(&arg1,&arg2)){
|
if (get_hex_arg2(&arg1, &arg2)) {
|
||||||
crc = crc_check_bulk_memory(arg1,arg2,0x8000);
|
crc = crc_check_bulk_memory(arg1, arg2, 0x8000);
|
||||||
info_P(PSTR("0x%06lx - 0x%06lx crc=0x%04x\n"),arg1,arg2,crc);
|
info_P(PSTR("0x%06lx - 0x%06lx crc=0x%04x\n"), arg1, arg2, crc);
|
||||||
} else
|
} else
|
||||||
info_P(PSTR("CRC <start addr> <end addr>\n"));
|
info_P(PSTR("CRC <start addr> <end addr>\n"));
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_EXIT]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_EXIT]) == 0) {
|
||||||
leave_application();
|
leave_application();
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_RESET]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_RESET]) == 0) {
|
||||||
system_send_snes_reset();
|
system_send_snes_reset();
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_IRQ]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_IRQ]) == 0) {
|
||||||
info_P(PSTR("Send IRQ\n"));
|
info_P(PSTR("Send IRQ\n"));
|
||||||
snes_irq_on();
|
snes_irq_on();
|
||||||
snes_irq_lo();
|
snes_irq_lo();
|
||||||
_delay_us(20);
|
_delay_us(20);
|
||||||
snes_irq_hi();
|
snes_irq_hi();
|
||||||
snes_irq_off();
|
snes_irq_off();
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_AVR]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_AVR]) == 0) {
|
||||||
system_set_bus_avr();
|
system_set_bus_avr();
|
||||||
snes_irq_lo();
|
snes_irq_lo();
|
||||||
system_snes_irq_off();
|
system_snes_irq_off();
|
||||||
|
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SNES]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_SNES]) == 0) {
|
||||||
snes_irq_lo();
|
snes_irq_lo();
|
||||||
system_snes_irq_off();
|
system_snes_irq_off();
|
||||||
system_set_wr_disable();
|
system_set_wr_disable();
|
||||||
system_set_bus_snes();
|
system_set_bus_snes();
|
||||||
|
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_LOROM]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_LOROM]) == 0) {
|
||||||
system_set_rom_lorom();
|
system_set_rom_lorom();
|
||||||
system_set_wr_disable();
|
system_set_wr_disable();
|
||||||
|
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_HIROM]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_HIROM]) == 0) {
|
||||||
system_set_rom_hirom();
|
system_set_rom_hirom();
|
||||||
system_set_wr_disable();
|
system_set_wr_disable();
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_WR]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_WR]) == 0) {
|
||||||
arg1 = get_bool();
|
arg1 = get_bool();
|
||||||
if(arg1==1){
|
if (arg1 == 1) {
|
||||||
info_P(PSTR("Set WR enable"));
|
info_P(PSTR("Set WR enable"));
|
||||||
snes_wr_enable();
|
snes_wr_enable();
|
||||||
}else if (arg1==0){
|
} else if (arg1 == 0) {
|
||||||
info_P(PSTR("Set WR disable"));
|
info_P(PSTR("Set WR disable"));
|
||||||
snes_wr_disable();
|
snes_wr_disable();
|
||||||
}
|
}
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_RESETSNIFF]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_RESETSNIFF]) == 0) {
|
||||||
arg1 = get_bool();
|
arg1 = get_bool();
|
||||||
if(arg1==1){
|
if (arg1 == 1) {
|
||||||
info_P(PSTR("Start Reset sniffer"));
|
info_P(PSTR("Start Reset sniffer"));
|
||||||
irq_init();
|
irq_init();
|
||||||
}else if (arg1==0){
|
} else if (arg1 == 0) {
|
||||||
info_P(PSTR("Stop Reset sniffer"));
|
info_P(PSTR("Stop Reset sniffer"));
|
||||||
irq_stop();
|
irq_stop();
|
||||||
}
|
}
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_DUMPVEC]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_DUMPVEC]) == 0) {
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
if (system.rom_mode==LOROM)
|
if (system.rom_mode == LOROM)
|
||||||
offset = 0x8000;
|
offset = 0x8000;
|
||||||
else
|
else
|
||||||
offset = 0x0000;
|
offset = 0x0000;
|
||||||
|
|
||||||
info_P(PSTR("ABORT 0x%04x 0x%04x\n"), (0xFFE8 - offset),sram_read16_be(0xFFE8 - offset));
|
info_P(PSTR("ABORT 0x%04x 0x%04x\n"), (0xFFE8 - offset),
|
||||||
info_P(PSTR("BRK 0x%04x 0x%04x\n"), (0xFFE6 - offset),sram_read16_be(0xFFE6 - offset));
|
sram_read16_be(0xFFE8 - offset));
|
||||||
info_P(PSTR("COP 0x%04x 0x%04x\n"), (0xFFE4 - offset),sram_read16_be(0xFFE4 - offset));
|
info_P(PSTR("BRK 0x%04x 0x%04x\n"), (0xFFE6 - offset),
|
||||||
info_P(PSTR("IRQ 0x%04x 0x%04x\n"), (0xFFEE - offset),sram_read16_be(0xFFEE - offset));
|
sram_read16_be(0xFFE6 - offset));
|
||||||
info_P(PSTR("NMI 0x%04x 0x%04x\n"), (0xFFEA - offset),sram_read16_be(0xFFEA - offset));
|
info_P(PSTR("COP 0x%04x 0x%04x\n"), (0xFFE4 - offset),
|
||||||
info_P(PSTR("RES 0x%04x 0x%04x\n"), (0xFFFC - offset),sram_read16_be(0xFFFC - 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) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_DUMPHEADER]) == 0) {
|
||||||
|
|
||||||
if (system.rom_mode==LOROM)
|
if (system.rom_mode == LOROM)
|
||||||
offset = 0x8000;
|
offset = 0x8000;
|
||||||
else
|
else
|
||||||
offset = 0x0000;
|
offset = 0x0000;
|
||||||
/*
|
/*
|
||||||
# $ffc0..$ffd4 => Name of the ROM, typically in ASCII, using spaces to pad the name to 21 bytes.
|
* # $ffc0..$ffd4 => Name of the ROM, typically in ASCII, using spaces to pad the name to 21 bytes. # $ffd5 => ROM layout,
|
||||||
# $ffd5 => ROM layout, typically $20 for LoROM, or $21 for HiROM. Add $10 for FastROM.
|
* typically $20 for LoROM, or $21 for HiROM. Add $10 for FastROM. # $ffd6 => Cartridge type, typically $00 for ROM only, or $02
|
||||||
# $ffd6 => Cartridge type, typically $00 for ROM only, or $02 for ROM with save-RAM.
|
* for ROM with save-RAM. # $ffd7 => ROM size byte. # $ffd8 => RAM size byte. # $ffd9 => Country code, which selects the video in
|
||||||
# $ffd7 => ROM size byte.
|
* the emulator. Values $00, $01, $0d use NTSC. Values in range $02..$0c use PAL. Other values are invalid. # $ffda => Licensee
|
||||||
# $ffd8 => RAM size byte.
|
* code. If this value is $33, then the ROM has an extended header with ID at $ffb2..$ffb5. # $ffdb => Version number, typically
|
||||||
# $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.
|
* $00. # $ffdc..$ffdd => Checksum complement, which is the bitwise-xor of the checksum and $ffff. # $ffde..$ffdf => SNES checksum,
|
||||||
# $ffda => Licensee code. If this value is $33, then the ROM has an extended header with ID at $ffb2..$ffb5.
|
* an unsigned 16-bit checksum of bytes. # $ffe0..$ffe3 => Unknown.
|
||||||
# $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));
|
info_P(PSTR("NAME 0x%04x "), (0xffc0 - offset));
|
||||||
for(arg1=(0xffc0 - offset); arg1<(0xffc0 - offset + 21);arg1++){
|
for (arg1 = (0xffc0 - offset); arg1 < (0xffc0 - offset + 21); arg1++) {
|
||||||
c = sram_read(arg1);
|
c = sram_read(arg1);
|
||||||
if (c>0x1f && c<0x7f)
|
if (c > 0x1f && c < 0x7f)
|
||||||
printf("%c",c);
|
printf("%c", c);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
c = sram_read(0xffd5 - offset);
|
c = sram_read(0xffd5 - offset);
|
||||||
info_P(PSTR("LAYOUT 0x%04x "), (0xffd5 - offset));
|
info_P(PSTR("LAYOUT 0x%04x "), (0xffd5 - offset));
|
||||||
|
|
||||||
switch(c){
|
switch (c) {
|
||||||
case 0x20:
|
case 0x20:
|
||||||
info_P(PSTR("LoROM, not fast\n"));
|
info_P(PSTR("LoROM, not fast\n"));
|
||||||
break;
|
break;
|
||||||
@ -389,13 +396,13 @@ void shell_run(void)
|
|||||||
info_P(PSTR("HiRom, fast\n"));
|
info_P(PSTR("HiRom, fast\n"));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
info_P(PSTR("Unkown 0x%02x\n"),c);
|
info_P(PSTR("Unkown 0x%02x\n"), c);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
c = sram_read(0xffd6 - offset);
|
c = sram_read(0xffd6 - offset);
|
||||||
info_P(PSTR("TYPE 0x%04xc"), (0xffd6 - offset),c);
|
info_P(PSTR("TYPE 0x%04xc"), (0xffd6 - offset), c);
|
||||||
switch(c){
|
switch (c) {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
info_P(PSTR("Rom\n"));
|
info_P(PSTR("Rom\n"));
|
||||||
break;
|
break;
|
||||||
@ -424,51 +431,56 @@ void shell_run(void)
|
|||||||
info_P(PSTR("SA-1"));
|
info_P(PSTR("SA-1"));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
info_P(PSTR("Unkown 0x%02x\n"),c);
|
info_P(PSTR("Unkown 0x%02x\n"), c);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
arg1 = ( 2 << ( sram_read(0xffd7 - offset) - 1 ));
|
arg1 = (2 << (sram_read(0xffd7 - offset) - 1));
|
||||||
info_P(PSTR("ROM 0x%04x %li MBit ( %li KiB)\n"), (0xffd7 - offset), (arg1 / 128), arg1);
|
info_P(PSTR("ROM 0x%04x %li MBit ( %li KiB)\n"),
|
||||||
arg1 = ( 2 << ( sram_read(0xffd8 - offset) - 1 ));
|
(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("RAM 0x%04x %li KiB\n"), (0xffd8 - offset), arg1);
|
||||||
|
|
||||||
info_P(PSTR("CCODE 0x%04x "), (0xffd9 - offset));
|
info_P(PSTR("CCODE 0x%04x "), (0xffd9 - offset));
|
||||||
c = sram_read(0xffd9 - offset);
|
c = sram_read(0xffd9 - offset);
|
||||||
if (c==0x00 || c==0x01 || 0x0d )
|
if (c == 0x00 || c == 0x01 || 0x0d)
|
||||||
info_P(PSTR("NTSC\n"));
|
info_P(PSTR("NTSC\n"));
|
||||||
else if (c>=0x02 || c<=0x0c )
|
else if (c >= 0x02 || c <= 0x0c)
|
||||||
info_P(PSTR("PAL\n"));
|
info_P(PSTR("PAL\n"));
|
||||||
else
|
else
|
||||||
info_P(PSTR("Unkown 0x%02x\n"),c);
|
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("LIC 0x%04x 0x%02x\n"), (0xffda - offset),
|
||||||
info_P(PSTR("VER 0x%04x 0x%02x\n"), (0xffdb - offset),sram_read(0xffdb - offset));
|
sram_read(0xffda - offset));
|
||||||
info_P(PSTR("SUM1 0x%04x 0x%04x\n"), (0xffdc - offset),sram_read16_be(0xffdc - offset));
|
info_P(PSTR("VER 0x%04x 0x%02x\n"), (0xffdb - offset),
|
||||||
info_P(PSTR("SUM2 0x%04x 0x%04x\n"), (0xffde - offset),sram_read16_be(0xffde - 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) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_SHMWR]) == 0) {
|
||||||
if (get_hex_arg2(&arg1,&arg2))
|
if (get_hex_arg2(&arg1, &arg2))
|
||||||
shared_memory_write((uint8_t)arg1, (uint8_t)arg1);
|
shared_memory_write((uint8_t) arg1, (uint8_t) arg1);
|
||||||
else
|
else
|
||||||
info_P(PSTR("SHMWR <command> <value>\n"));
|
info_P(PSTR("SHMWR <command> <value>\n"));
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SHMSAVE]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_SHMSAVE]) == 0) {
|
||||||
shared_memory_scratchpad_region_tx_save();
|
shared_memory_scratchpad_region_tx_save();
|
||||||
shared_memory_scratchpad_region_rx_save();
|
shared_memory_scratchpad_region_rx_save();
|
||||||
info_P(PSTR("Save scratchpad\n"));
|
info_P(PSTR("Save scratchpad\n"));
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SHMRESTORE]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_SHMRESTORE]) == 0) {
|
||||||
shared_memory_scratchpad_region_tx_restore();
|
shared_memory_scratchpad_region_tx_restore();
|
||||||
shared_memory_scratchpad_region_rx_restore();
|
shared_memory_scratchpad_region_rx_restore();
|
||||||
info_P(PSTR("Restore scratchpad\n"));
|
info_P(PSTR("Restore scratchpad\n"));
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_LOADER]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_LOADER]) == 0) {
|
||||||
boot_startup_rom(500);
|
boot_startup_rom(500);
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_RECONNECT]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_RECONNECT]) == 0) {
|
||||||
usb_connect();
|
usb_connect();
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_STATUS]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_STATUS]) == 0) {
|
||||||
transaction_status();
|
transaction_status();
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SYS]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_SYS]) == 0) {
|
||||||
system_status();
|
system_status();
|
||||||
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_HELP]) == 0) {
|
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_HELP]) == 0) {
|
||||||
shell_help();
|
shell_help();
|
||||||
}
|
}
|
||||||
prompt();
|
prompt();
|
||||||
|
|||||||
@ -21,6 +21,6 @@
|
|||||||
#ifndef __SHELL_H__
|
#ifndef __SHELL_H__
|
||||||
#define __SHELL_H__
|
#define __SHELL_H__
|
||||||
|
|
||||||
void shell_run(void);
|
void shell_run(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -38,53 +38,53 @@ void sram_init(void)
|
|||||||
{
|
{
|
||||||
/*-------------------------------------------------*/
|
/*-------------------------------------------------*/
|
||||||
|
|
||||||
DDRA = 0x00;
|
DDRA = 0x00;
|
||||||
PORTA = 0x00;
|
PORTA = 0x00;
|
||||||
|
|
||||||
/*-------------------------------------------------*/
|
/*-------------------------------------------------*/
|
||||||
|
|
||||||
DDRC |= ( (1 << AVR_ADDR_LATCH_PIN)
|
DDRC |= ((1 << AVR_ADDR_LATCH_PIN)
|
||||||
| (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_UP_PIN));
|
| (1 << AVR_ADDR_UP_PIN));
|
||||||
|
|
||||||
DDRC &= ~ ((1 << SNES_WR_PIN)
|
DDRC &= ~((1 << SNES_WR_PIN)
|
||||||
| (1 << AVR_BTLDR_EN_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_UP_PIN)
|
PORTC |= ((1 << AVR_ADDR_UP_PIN)
|
||||||
| (1 << AVR_ADDR_LOAD_PIN));
|
| (1 << AVR_ADDR_LOAD_PIN));
|
||||||
|
|
||||||
//| (1 << SNES_WR_PIN));
|
// | (1 << SNES_WR_PIN));
|
||||||
/*-------------------------------------------------*/
|
/*-------------------------------------------------*/
|
||||||
|
|
||||||
DDRB |= ( (1 << AVR_RD_PIN)
|
DDRB |= ((1 << AVR_RD_PIN)
|
||||||
| (1 << AVR_WR_PIN)
|
| (1 << AVR_WR_PIN)
|
||||||
| (1 << AVR_CS_PIN)
|
| (1 << AVR_CS_PIN)
|
||||||
| (1 << SNES_IRQ_PIN));
|
| (1 << SNES_IRQ_PIN));
|
||||||
|
|
||||||
|
|
||||||
PORTB |= ( (1 << AVR_RD_PIN)
|
PORTB |= ((1 << AVR_RD_PIN)
|
||||||
| (1 << AVR_WR_PIN)
|
| (1 << AVR_WR_PIN)
|
||||||
| (1 << AVR_CS_PIN)
|
| (1 << AVR_CS_PIN)
|
||||||
| (1 << SNES_IRQ_PIN));
|
| (1 << SNES_IRQ_PIN));
|
||||||
|
|
||||||
/*-------------------------------------------------*/
|
/*-------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
DDRD |= ( (1 << AVR_SNES_SW_PIN)
|
DDRD |= ((1 << AVR_SNES_SW_PIN)
|
||||||
| (1 << HI_LOROM_SW_PIN)
|
| (1 << HI_LOROM_SW_PIN)
|
||||||
| (1 << SNES_WR_EN_PIN));
|
| (1 << SNES_WR_EN_PIN));
|
||||||
|
|
||||||
PORTD |= (1 << HI_LOROM_SW_PIN);
|
PORTD |= (1 << HI_LOROM_SW_PIN);
|
||||||
|
|
||||||
PORTD &= ~((1 << AVR_SNES_SW_PIN)
|
PORTD &= ~((1 << AVR_SNES_SW_PIN)
|
||||||
| (1 << SNES_WR_EN_PIN));
|
| (1 << SNES_WR_EN_PIN));
|
||||||
|
|
||||||
/*-------------------------------------------------*/
|
/*-------------------------------------------------*/
|
||||||
|
|
||||||
@ -94,13 +94,13 @@ void sram_init(void)
|
|||||||
void sreg_set(uint32_t addr)
|
void sreg_set(uint32_t addr)
|
||||||
{
|
{
|
||||||
uint8_t i = 24;
|
uint8_t i = 24;
|
||||||
debug_P(DEBUG_SREG, PSTR("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_P(DEBUG_SREG, PSTR("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_P(DEBUG_SREG, PSTR("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);
|
||||||
@ -114,15 +114,17 @@ void sreg_set(uint32_t addr)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
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()
|
||||||
{
|
{
|
||||||
debug_P(DEBUG_SRAM, PSTR("sram_bulk_addr_restore: addr=0x%08lx\n\r"), addr_stash);
|
debug_P(DEBUG_SRAM, PSTR("sram_bulk_addr_restore: addr=0x%08lx\n\r"),
|
||||||
|
addr_stash);
|
||||||
sram_bulk_write_start(addr_stash);
|
sram_bulk_write_start(addr_stash);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +151,7 @@ void sram_bulk_read_start(uint32_t addr)
|
|||||||
asm volatile ("nop");
|
asm volatile ("nop");
|
||||||
asm volatile ("nop");
|
asm volatile ("nop");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void sram_bulk_read_next(void)
|
inline void sram_bulk_read_next(void)
|
||||||
{
|
{
|
||||||
@ -215,10 +217,11 @@ uint8_t sram_read(uint32_t addr)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t sram_read16_be(uint32_t addr){
|
uint16_t sram_read16_be(uint32_t addr)
|
||||||
|
{
|
||||||
uint8_t hi = sram_read(addr);
|
uint8_t hi = sram_read(addr);
|
||||||
uint8_t lo = sram_read(addr+1);
|
uint8_t lo = sram_read(addr + 1);
|
||||||
return (hi << 8 | lo );
|
return (hi << 8 | lo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sram_bulk_write_start(uint32_t addr)
|
void sram_bulk_write_start(uint32_t addr)
|
||||||
@ -242,7 +245,7 @@ inline void sram_bulk_write_next(void)
|
|||||||
counter_up();
|
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_WR_PORT &= ~(1 << AVR_WR_PIN);
|
||||||
AVR_DATA_PORT = data;
|
AVR_DATA_PORT = data;
|
||||||
@ -260,7 +263,8 @@ 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_P(DEBUG_SRAM_RAW, PSTR("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();
|
||||||
|
|
||||||
@ -294,13 +298,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_P(DEBUG_SRAM, PSTR("sram_bulk_copy_from_buffer: addr=0x%08lx src=0x%p len=%li\n\r"),
|
debug_P(DEBUG_SRAM,
|
||||||
addr, src, len);
|
PSTR
|
||||||
|
("sram_bulk_copy_from_buffer: addr=0x%08lx src=0x%p len=%li\n\r"),
|
||||||
|
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);
|
||||||
//hack
|
// hack
|
||||||
if ((i+1) < (addr + len))
|
if ((i + 1) < (addr + len))
|
||||||
sram_bulk_write_next();
|
sram_bulk_write_next();
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
@ -311,9 +317,11 @@ 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_P(DEBUG_SRAM, PSTR("sram_bulk_copy_into_buffer: addr=0x%08lx dst=0x%p len=%li\n\r"),
|
debug_P(DEBUG_SRAM,
|
||||||
addr, dst, len);
|
PSTR
|
||||||
|
("sram_bulk_copy_into_buffer: addr=0x%08lx dst=0x%p len=%li\n\r"),
|
||||||
|
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++) {
|
||||||
dst[i] = sram_bulk_read();
|
dst[i] = sram_bulk_read();
|
||||||
@ -322,9 +330,11 @@ void sram_bulk_copy_into_buffer(uint32_t addr, uint8_t * dst, uint32_t len)
|
|||||||
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_P(DEBUG_SRAM, PSTR("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)
|
||||||
@ -334,4 +344,3 @@ void sram_bulk_set(uint32_t addr, uint32_t len,uint8_t value){
|
|||||||
}
|
}
|
||||||
sram_bulk_write_end();
|
sram_bulk_write_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ---------------------------- PORT A ---------------------------- */
|
/*
|
||||||
|
* ---------------------------- PORT A ----------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
#define AVR_DATA_PORT PORTA
|
#define AVR_DATA_PORT PORTA
|
||||||
#define AVR_DATA_DIR DDRA
|
#define AVR_DATA_DIR DDRA
|
||||||
@ -41,7 +43,9 @@
|
|||||||
#define avr_data_out() (AVR_DATA_DIR = 0xff)
|
#define avr_data_out() (AVR_DATA_DIR = 0xff)
|
||||||
|
|
||||||
|
|
||||||
/* ---------------------------- PORT B ---------------------------- */
|
/*
|
||||||
|
* ---------------------------- PORT B ----------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
#define AVR_PORT PORTB
|
#define AVR_PORT PORTB
|
||||||
#define AVR_DIR DDRB
|
#define AVR_DIR DDRB
|
||||||
@ -78,7 +82,9 @@
|
|||||||
#define snes_irq_lo() (SNES_IRQ_PORT &= ~(1 << SNES_IRQ_PIN))
|
#define snes_irq_lo() (SNES_IRQ_PORT &= ~(1 << SNES_IRQ_PIN))
|
||||||
|
|
||||||
|
|
||||||
/* ---------------------------- PORT C ---------------------------- */
|
/*
|
||||||
|
* ---------------------------- PORT C ----------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
#define AVR_ADDR_PORT PORTC
|
#define AVR_ADDR_PORT PORTC
|
||||||
#define AVR_ADDR_DIR DDRC
|
#define AVR_ADDR_DIR DDRC
|
||||||
@ -140,7 +146,9 @@
|
|||||||
#define led_pwm_on() (LED_DIR &=~ (1 << LED_PIN))
|
#define led_pwm_on() (LED_DIR &=~ (1 << LED_PIN))
|
||||||
#define led_pwm_off() (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
|
||||||
#define AVR_SNES_DIR DDRD
|
#define AVR_SNES_DIR DDRD
|
||||||
@ -216,7 +224,7 @@ void sram_bulk_write(uint8_t data);
|
|||||||
void sram_bulk_copy_from_buffer(uint32_t addr, uint8_t * src, uint32_t len);
|
void sram_bulk_copy_from_buffer(uint32_t addr, uint8_t * src, uint32_t len);
|
||||||
void sram_bulk_copy_into_buffer(uint32_t addr, uint8_t * dst, uint32_t len);
|
void sram_bulk_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);
|
void sram_bulk_set(uint32_t addr, uint32_t len, uint8_t value);
|
||||||
|
|
||||||
inline void sram_bulk_addr_save();
|
inline void sram_bulk_addr_save();
|
||||||
inline void sram_bulk_addr_restore();
|
inline void sram_bulk_addr_restore();
|
||||||
|
|||||||
@ -106,13 +106,15 @@ void system_set_bus_avr()
|
|||||||
system.bus_mode = MODE_AVR;
|
system.bus_mode = MODE_AVR;
|
||||||
}
|
}
|
||||||
|
|
||||||
void system_set_wr_disable(){
|
void system_set_wr_disable()
|
||||||
|
{
|
||||||
snes_wr_disable();
|
snes_wr_disable();
|
||||||
system.wr_line = WR_DISABLE;
|
system.wr_line = WR_DISABLE;
|
||||||
info_P(PSTR("Disable SNES WR\n"));
|
info_P(PSTR("Disable SNES WR\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void system_set_wr_enable(){
|
void system_set_wr_enable()
|
||||||
|
{
|
||||||
snes_wr_enable();
|
snes_wr_enable();
|
||||||
system.wr_line = WR_ENABLE;
|
system.wr_line = WR_ENABLE;
|
||||||
info_P(PSTR("Enable SNES WR\n"));
|
info_P(PSTR("Enable SNES WR\n"));
|
||||||
@ -125,7 +127,7 @@ void system_set_bus_snes()
|
|||||||
info_P(PSTR("Activate SNES bus\n"));
|
info_P(PSTR("Activate SNES bus\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void system_set_rom_mode(usb_transaction_t *usb_trans)
|
void system_set_rom_mode(usb_transaction_t * usb_trans)
|
||||||
{
|
{
|
||||||
if (usb_trans->req_bank_size == 0x8000) {
|
if (usb_trans->req_bank_size == 0x8000) {
|
||||||
snes_lorom();
|
snes_lorom();
|
||||||
@ -153,34 +155,39 @@ void system_set_rom_hirom()
|
|||||||
info_P(PSTR("Set SNES hirom \n"));
|
info_P(PSTR("Set SNES hirom \n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
char* system_status_helper(uint8_t val){
|
char *system_status_helper(uint8_t val)
|
||||||
if (val)
|
{
|
||||||
return "ON";
|
if (val)
|
||||||
|
return "ON";
|
||||||
else
|
else
|
||||||
return "OFF";
|
return "OFF";
|
||||||
}
|
}
|
||||||
|
|
||||||
char* system_status_bus(uint8_t val){
|
char *system_status_bus(uint8_t val)
|
||||||
if (val)
|
{
|
||||||
return "SNES";
|
if (val)
|
||||||
|
return "SNES";
|
||||||
else
|
else
|
||||||
return "AVR";
|
return "AVR";
|
||||||
}
|
}
|
||||||
|
|
||||||
char* system_status_rom(uint8_t val){
|
char *system_status_rom(uint8_t val)
|
||||||
if (val)
|
{
|
||||||
return "HIROM";
|
if (val)
|
||||||
|
return "HIROM";
|
||||||
else
|
else
|
||||||
return "LOROM";
|
return "LOROM";
|
||||||
}
|
}
|
||||||
|
|
||||||
void system_status(){
|
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("\nBus Mode %s\n"), system_status_bus(system.bus_mode));
|
||||||
info_P(PSTR("Reset Line %s\n"),system_status_helper(system.reset_line));
|
info_P(PSTR("Rom Mode %s\n"), system_status_rom(system.rom_mode));
|
||||||
info_P(PSTR("IRQ Line %s\n"),system_status_helper(system.irq_line));
|
info_P(PSTR("Reset Line %s\n"),
|
||||||
info_P(PSTR("WR Line %s\n"),system_status_helper(system.wr_line));
|
system_status_helper(system.reset_line));
|
||||||
info_P(PSTR("Reset IRQ %s\n"),system_status_helper(system.reset_irq));
|
info_P(PSTR("IRQ Line %s\n"), system_status_helper(system.irq_line));
|
||||||
info_P(PSTR("SNES Reset 0x%02x\n"),system.snes_reset_count);
|
info_P(PSTR("WR Line %s\n"), system_status_helper(system.wr_line));
|
||||||
info_P(PSTR("AVR Reset 0x%02x\n"),system.avr_reset_count);
|
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);
|
||||||
}
|
}
|
||||||
@ -28,12 +28,12 @@
|
|||||||
|
|
||||||
|
|
||||||
typedef struct system_t {
|
typedef struct system_t {
|
||||||
enum bus_mode_e { MODE_AVR, MODE_SNES } bus_mode;
|
enum bus_mode_e { MODE_AVR, MODE_SNES } bus_mode;
|
||||||
enum rom_mode_e { LOROM, HIROM } rom_mode;
|
enum rom_mode_e { LOROM, HIROM } rom_mode;
|
||||||
enum reset_line_e { RESET_OFF, RESET_ON } reset_line;
|
enum reset_line_e { RESET_OFF, RESET_ON } reset_line;
|
||||||
enum irq_line_e { IRQ_ON, IRQ_OFF } irq_line;
|
enum irq_line_e { IRQ_ON, IRQ_OFF } irq_line;
|
||||||
enum wr_line_e { WR_DISABLE, WR_ENABLE } wr_line;
|
enum wr_line_e { WR_DISABLE, WR_ENABLE } wr_line;
|
||||||
enum reset_irq_e { RESET_IRQ_OFF, RESET_IRQ_ON } reset_irq;
|
enum reset_irq_e { RESET_IRQ_OFF, RESET_IRQ_ON } reset_irq;
|
||||||
|
|
||||||
uint8_t snes_reset_count;
|
uint8_t snes_reset_count;
|
||||||
uint8_t avr_reset_count;
|
uint8_t avr_reset_count;
|
||||||
@ -45,7 +45,7 @@ void system_send_snes_reset(void);
|
|||||||
void system_send_snes_irq(void);
|
void system_send_snes_irq(void);
|
||||||
void system_set_bus_avr(void);
|
void system_set_bus_avr(void);
|
||||||
void system_set_bus_snes(void);
|
void system_set_bus_snes(void);
|
||||||
void system_set_rom_mode(usb_transaction_t *usb_trans);
|
void system_set_rom_mode(usb_transaction_t * usb_trans);
|
||||||
void system_set_rom_hirom(void);
|
void system_set_rom_hirom(void);
|
||||||
void system_set_rom_lorom(void);
|
void system_set_rom_lorom(void);
|
||||||
void system_snes_irq_off(void);
|
void system_snes_irq_off(void);
|
||||||
|
|||||||
@ -93,29 +93,36 @@ void test_non_zero_memory(uint32_t bottom_addr, uint32_t top_addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void test_memory_pattern(uint32_t bottom_addr, uint32_t top_addr, uint32_t bank_size)
|
void test_memory_pattern(uint32_t bottom_addr, uint32_t top_addr,
|
||||||
|
uint32_t bank_size)
|
||||||
{
|
{
|
||||||
uint32_t addr = 0;
|
uint32_t addr = 0;
|
||||||
uint8_t pattern = 0x55;
|
uint8_t pattern = 0x55;
|
||||||
info_P(PSTR("test_memory_pattern: bottom_addr=0x%08lx top_addr=0x%08lx\n"), bottom_addr, top_addr);
|
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);
|
sram_bulk_write_start(bottom_addr);
|
||||||
for (addr = bottom_addr; addr < top_addr; addr++) {
|
for (addr = bottom_addr; addr < top_addr; addr++) {
|
||||||
if (addr % bank_size == 0){
|
if (addr % bank_size == 0) {
|
||||||
pattern++;
|
pattern++;
|
||||||
info_P(PSTR("test_memory_pattern: write addr=0x%08lx pattern=0x%08lx\n"), addr, pattern);
|
info_P(PSTR
|
||||||
|
("test_memory_pattern: write addr=0x%08lx pattern=0x%08lx\n"),
|
||||||
|
addr, pattern);
|
||||||
}
|
}
|
||||||
sram_bulk_write(pattern);
|
sram_bulk_write(pattern);
|
||||||
}
|
}
|
||||||
sram_bulk_write_end();
|
sram_bulk_write_end();
|
||||||
|
|
||||||
|
|
||||||
for (addr = bottom_addr; addr < top_addr; addr+=bank_size) {
|
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);
|
info_P(PSTR
|
||||||
dump_memory(addr, addr + bank_size );
|
("test_memory_pattern: dump bottom_addr=0x%08lx top_addr=0x%08lx\n"),
|
||||||
info_P(PSTR("----------------------------------------------------------------\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);
|
crc_check_bulk_memory((uint32_t) bottom_addr, top_addr, bank_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_crc()
|
void test_crc()
|
||||||
@ -128,4 +135,3 @@ void test_crc()
|
|||||||
info_P(PSTR("test_crc: check\n"));
|
info_P(PSTR("test_crc: check\n"));
|
||||||
test_non_zero_memory(0x000000, 0x10000);
|
test_non_zero_memory(0x000000, 0x10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -35,14 +35,14 @@
|
|||||||
extern uint8_t snes_reset_line;
|
extern uint8_t snes_reset_line;
|
||||||
|
|
||||||
#ifndef OCR1A
|
#ifndef OCR1A
|
||||||
#define OCR1A OCR1 // 2313 support
|
#define OCR1A OCR1 // 2313 support
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WGM12
|
#ifndef WGM12
|
||||||
#define WGM12 CTC1 // 2313 support
|
#define WGM12 CTC1 // 2313 support
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//#define XTAL 11059201L // nominal value
|
// #define XTAL 11059201L // nominal value
|
||||||
#define XTAL 20000000UL
|
#define XTAL 20000000UL
|
||||||
|
|
||||||
#define DEBOUNCE 500L // debounce clock (256Hz = 4msec)
|
#define DEBOUNCE 500L // debounce clock (256Hz = 4msec)
|
||||||
@ -51,44 +51,41 @@ extern uint8_t snes_reset_line;
|
|||||||
#define uint unsigned int
|
#define uint unsigned int
|
||||||
|
|
||||||
uint16_t prescaler;
|
uint16_t prescaler;
|
||||||
uint16_t volatile second; // count seconds
|
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
|
||||||
#endif
|
#endif
|
||||||
if( --prescaler == 0 ){
|
if (--prescaler == 0) {
|
||||||
prescaler = (uint16_t)DEBOUNCE;
|
prescaler = (uint16_t) DEBOUNCE;
|
||||||
second++; // exact one second over
|
second++; // exact one second over
|
||||||
#if XTAL % DEBOUNCE // handle remainder
|
#if XTAL % DEBOUNCE // handle remainder
|
||||||
OCR1A = XTAL / DEBOUNCE + XTAL % DEBOUNCE - 1; // compare once per second
|
OCR1A = XTAL / DEBOUNCE + XTAL % DEBOUNCE - 1; // compare once per second
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void timer_start( void )
|
void timer_start(void)
|
||||||
{
|
{
|
||||||
TCCR1B = (1<<WGM12) | (1<<CS10); // divide by 1
|
TCCR1B = (1 << WGM12) | (1 << CS10); // divide by 1
|
||||||
// clear on compare
|
// clear on compare
|
||||||
OCR1A = XTAL / DEBOUNCE - 1UL; // Output Compare Register
|
OCR1A = XTAL / DEBOUNCE - 1UL; // Output Compare Register
|
||||||
TCNT1 = 0; // Timmer startet mit 0
|
TCNT1 = 0; // Timmer startet mit 0
|
||||||
second = 0;
|
second = 0;
|
||||||
prescaler = (uint16_t)DEBOUNCE; //software teiler
|
prescaler = (uint16_t) DEBOUNCE; // software teiler
|
||||||
TIMSK1 = 1<<OCIE1A; // beim Vergleichswertes Compare Match
|
TIMSK1 = 1 << OCIE1A; // beim Vergleichswertes Compare Match
|
||||||
// Interrupt (SIG_OUTPUT_COMPARE1A)
|
// Interrupt (SIG_OUTPUT_COMPARE1A)
|
||||||
sei();
|
sei();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t timer_stop_int(void)
|
uint16_t timer_stop_int(void)
|
||||||
{
|
{
|
||||||
uint16_t t = ((DEBOUNCE - prescaler) / DEBOUNCE ) + second;
|
uint16_t t = ((DEBOUNCE - prescaler) / DEBOUNCE) + second;
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -18,12 +18,12 @@
|
|||||||
* =====================================================================================
|
* =====================================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TIMER_H__
|
#ifndef __TIMER_H__
|
||||||
#define __TIMER_H__
|
#define __TIMER_H__
|
||||||
|
|
||||||
|
|
||||||
int16_t timer_start( void );
|
int16_t timer_start(void);
|
||||||
double timer_stop( void );
|
double timer_stop(void);
|
||||||
int16_t timer_stop_int( void );
|
int16_t timer_stop_int(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -38,31 +38,22 @@ volatile char rxbuff;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int uart_stream(char c, FILE *stream);
|
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)
|
||||||
{
|
{
|
||||||
UCSR0A = _BV(U2X0); /* improves baud rate error @ F_CPU = 1 MHz */
|
UCSR0A = _BV(U2X0); /* improves baud rate error @ F_CPU = 1 MHz */
|
||||||
UCSR0B = _BV(TXEN0) | _BV(RXEN0) | _BV(RXCIE0); /* tx/rx enable, rx complete
|
UCSR0B = _BV(TXEN0) | _BV(RXEN0) | _BV(RXCIE0); /* tx/rx enable, rx complete * intr */
|
||||||
* intr */
|
|
||||||
UBRR0L = (F_CPU / (8 * 115200UL)) - 1;
|
UBRR0L = (F_CPU / (8 * 115200UL)) - 1;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ISR(USART0_RX_vect)
|
* ISR(USART0_RX_vect) { uint8_t c; c = UDR0; if (bit_is_clear(UCSR0A, FE0)) { rxbuff = c; intflags.rx_int = 1; } }
|
||||||
{
|
*/
|
||||||
uint8_t c;
|
|
||||||
c = UDR0;
|
|
||||||
if (bit_is_clear(UCSR0A, FE0)) {
|
|
||||||
rxbuff = c;
|
|
||||||
intflags.rx_int = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void uart_putc(uint8_t c)
|
void uart_putc(uint8_t c)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -34,6 +34,3 @@ void uart_puts(const char *s);
|
|||||||
void uart_puts_P(PGM_P s);
|
void uart_puts_P(PGM_P s);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -27,8 +27,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "usbdrv.h"
|
#include "usbdrv.h"
|
||||||
#include "oddebug.h" /* This is also an example for using debug
|
#include "oddebug.h" /* This is also an example for using debug macros */
|
||||||
* macros */
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "requests.h" /* The custom request numbers we use */
|
#include "requests.h" /* The custom request numbers we use */
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
@ -45,21 +44,24 @@ extern usb_transaction_t usb_trans;
|
|||||||
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 > usb_trans.rx_remaining) {
|
if (len > usb_trans.rx_remaining) {
|
||||||
info_P(PSTR("ERROR:usbFunctionWrite more data than expected remain: %i len: %i\n"),
|
info_P(PSTR
|
||||||
usb_trans.rx_remaining, len);
|
("ERROR:usbFunctionWrite more data than expected remain: %i len: %i\n"),
|
||||||
len = usb_trans.rx_remaining;
|
usb_trans.rx_remaining, len);
|
||||||
|
len = usb_trans.rx_remaining;
|
||||||
}
|
}
|
||||||
if (usb_trans.req_state == REQ_STATUS_BULK_UPLOAD) {
|
if (usb_trans.req_state == REQ_STATUS_BULK_UPLOAD) {
|
||||||
|
|
||||||
usb_trans.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"),
|
debug_P(DEBUG_USB_TRANS,
|
||||||
usb_trans.req_addr, len, usb_trans.rx_remaining);
|
PSTR
|
||||||
|
("usbFunctionWrite REQ_STATUS_BULK_UPLOAD addr: 0x%08lx len: %i rx_remaining=%i\n"),
|
||||||
|
usb_trans.req_addr, len, usb_trans.rx_remaining);
|
||||||
ptr = data;
|
ptr = data;
|
||||||
i = len;
|
i = len;
|
||||||
while(i--){
|
while (i--) {
|
||||||
sram_bulk_write(*ptr++);
|
sram_bulk_write(*ptr++);
|
||||||
sram_bulk_write_next();
|
sram_bulk_write_next();
|
||||||
}
|
}
|
||||||
@ -70,13 +72,14 @@ 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 > usb_trans.tx_remaining)
|
if (len > usb_trans.tx_remaining)
|
||||||
len = usb_trans.tx_remaining;
|
len = usb_trans.tx_remaining;
|
||||||
usb_trans.tx_remaining -= len;
|
usb_trans.tx_remaining -= len;
|
||||||
debug_P(DEBUG_USB_TRANS, PSTR("usbFunctionRead len=%i tx_remaining=%i \n"), len, usb_trans.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 = usb_trans.tx_buffer[len];
|
*data = usb_trans.tx_buffer[len];
|
||||||
data++;
|
data++;
|
||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
|
|||||||
@ -20,325 +20,287 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Name: usbconfig.h
|
/*
|
||||||
* Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
|
* Name: usbconfig.h Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers Author: Christian Starkjohann Creation Date:
|
||||||
* Author: Christian Starkjohann
|
* 2005-04-01 Tabsize: 4 Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH License: GNU GPL v2 (see License.txt), GNU GPL v3 or
|
||||||
* Creation Date: 2005-04-01
|
* proprietary (CommercialLicense.txt) This Revision: $Id: usbconfig-prototype.h 740 2009-04-13 18:23:31Z cs $
|
||||||
* Tabsize: 4
|
|
||||||
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
|
|
||||||
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
|
||||||
* This Revision: $Id: usbconfig-prototype.h 740 2009-04-13 18:23:31Z cs $
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __usbconfig_h_included__
|
#ifndef __usbconfig_h_included__
|
||||||
#define __usbconfig_h_included__
|
#define __usbconfig_h_included__
|
||||||
|
|
||||||
/*
|
/*
|
||||||
General Description:
|
* General Description: This file is an example configuration (with inline documentation) for the USB driver. It configures V-USB for USB
|
||||||
This file is an example configuration (with inline documentation) for the USB
|
* D+ connected to Port D bit 2 (which is also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may wire the lines to
|
||||||
driver. It configures V-USB for USB D+ connected to Port D bit 2 (which is
|
* any other port, as long as D+ is also wired to INT0 (or any other hardware interrupt, as long as it is the highest level interrupt, see
|
||||||
also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may
|
* section at the end of this file).
|
||||||
wire the lines to any other port, as long as D+ is also wired to INT0 (or any
|
*/
|
||||||
other hardware interrupt, as long as it is the highest level interrupt, see
|
|
||||||
section at the end of this file).
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* ---------------------------- Hardware Config ---------------------------- */
|
/*
|
||||||
|
* ---------------------------- Hardware Config ----------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
#define USB_CFG_IOPORTNAME D
|
#define USB_CFG_IOPORTNAME D
|
||||||
/* This is the port where the USB bus is connected. When you configure it to
|
/*
|
||||||
* "B", the registers PORTB, PINB and DDRB will be used.
|
* This is the port where the USB bus is connected. When you configure it to "B", the registers PORTB, PINB and DDRB will be used.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_DMINUS_BIT 4
|
#define USB_CFG_DMINUS_BIT 4
|
||||||
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
|
/*
|
||||||
* This may be any bit in the port.
|
* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected. This may be any bit in the port.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_DPLUS_BIT 2
|
#define USB_CFG_DPLUS_BIT 2
|
||||||
/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
|
/*
|
||||||
* This may be any bit in the port. Please note that D+ must also be connected
|
* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected. This may be any bit in the port. Please note that D+ must
|
||||||
* to interrupt pin INT0! [You can also use other interrupts, see section
|
* also be connected to interrupt pin INT0! [You can also use other interrupts, see section "Optional MCU Description" below, or you can
|
||||||
* "Optional MCU Description" below, or you can connect D- to the interrupt, as
|
* connect D- to the interrupt, as it is required if you use the USB_COUNT_SOF feature. If you use D- for the interrupt, the USB interrupt
|
||||||
* it is required if you use the USB_COUNT_SOF feature. If you use D- for the
|
* will also be triggered at Start-Of-Frame markers every millisecond.]
|
||||||
* interrupt, the USB interrupt will also be triggered at Start-Of-Frame
|
|
||||||
* markers every millisecond.]
|
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_CLOCK_KHZ (F_CPU/1000)
|
#define USB_CFG_CLOCK_KHZ (F_CPU/1000)
|
||||||
/* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000,
|
/*
|
||||||
* 16500 and 20000. The 12.8 MHz and 16.5 MHz versions of the code require no
|
* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000, 16500 and 20000. The 12.8 MHz and 16.5 MHz versions of the
|
||||||
* crystal, they tolerate +/- 1% deviation from the nominal frequency. All
|
* code require no crystal, they tolerate +/- 1% deviation from the nominal frequency. All other rates require a precision of 2000 ppm and
|
||||||
* other rates require a precision of 2000 ppm and thus a crystal!
|
* thus a crystal! Default if not specified: 12 MHz
|
||||||
* Default if not specified: 12 MHz
|
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_CHECK_CRC 0
|
#define USB_CFG_CHECK_CRC 0
|
||||||
/* Define this to 1 if you want that the driver checks integrity of incoming
|
/*
|
||||||
* data packets (CRC checks). CRC checks cost quite a bit of code size and are
|
* Define this to 1 if you want that the driver checks integrity of incoming data packets (CRC checks). CRC checks cost quite a bit of code
|
||||||
* currently only available for 18 MHz crystal clock. You must choose
|
* size and are currently only available for 18 MHz crystal clock. You must choose USB_CFG_CLOCK_KHZ = 18000 if you enable this option.
|
||||||
* USB_CFG_CLOCK_KHZ = 18000 if you enable this option.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* ----------------------- Optional Hardware Config ------------------------ */
|
/*
|
||||||
|
* ----------------------- Optional Hardware Config ------------------------
|
||||||
//#define USB_CFG_PULLUP_IOPORTNAME D
|
|
||||||
/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
|
|
||||||
* V+, you can connect and disconnect the device from firmware by calling
|
|
||||||
* the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
|
|
||||||
* This constant defines the port on which the pullup resistor is connected.
|
|
||||||
*/
|
|
||||||
//#define USB_CFG_PULLUP_BIT 6
|
|
||||||
/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
|
|
||||||
* above) where the 1.5k pullup resistor is connected. See description
|
|
||||||
* above for details.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* --------------------------- Functional Range ---------------------------- */
|
// #define USB_CFG_PULLUP_IOPORTNAME D
|
||||||
|
/*
|
||||||
|
* If you connect the 1.5k pullup resistor from D- to a port pin instead of V+, you can connect and disconnect the device from firmware by
|
||||||
|
* calling the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h). This constant defines the port on which the pullup
|
||||||
|
* resistor is connected.
|
||||||
|
*/
|
||||||
|
// #define USB_CFG_PULLUP_BIT 6
|
||||||
|
/*
|
||||||
|
* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined above) where the 1.5k pullup resistor is connected. See
|
||||||
|
* description above for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* --------------------------- Functional Range ----------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
#define USB_CFG_HAVE_INTRIN_ENDPOINT 0
|
#define USB_CFG_HAVE_INTRIN_ENDPOINT 0
|
||||||
/* Define this to 1 if you want to compile a version with two endpoints: The
|
/*
|
||||||
* default control endpoint 0 and an interrupt-in endpoint (any other endpoint
|
* Define this to 1 if you want to compile a version with two endpoints: The default control endpoint 0 and an interrupt-in endpoint (any
|
||||||
* number).
|
* other endpoint number).
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_HAVE_INTRIN_ENDPOINT3 0
|
#define USB_CFG_HAVE_INTRIN_ENDPOINT3 0
|
||||||
/* Define this to 1 if you want to compile a version with three endpoints: The
|
/*
|
||||||
* default control endpoint 0, an interrupt-in endpoint 3 (or the number
|
* Define this to 1 if you want to compile a version with three endpoints: The default control endpoint 0, an interrupt-in endpoint 3 (or
|
||||||
* configured below) and a catch-all default interrupt-in endpoint as above.
|
* the number configured below) and a catch-all default interrupt-in endpoint as above. You must also define USB_CFG_HAVE_INTRIN_ENDPOINT
|
||||||
* You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature.
|
* to 1 for this feature.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_EP3_NUMBER 3
|
#define USB_CFG_EP3_NUMBER 3
|
||||||
/* If the so-called endpoint 3 is used, it can now be configured to any other
|
/*
|
||||||
* endpoint number (except 0) with this macro. Default if undefined is 3.
|
* If the so-called endpoint 3 is used, it can now be configured to any other endpoint number (except 0) with this macro. Default if
|
||||||
|
* undefined is 3.
|
||||||
*/
|
*/
|
||||||
/* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */
|
/*
|
||||||
/* The above macro defines the startup condition for data toggling on the
|
* #define USB_INITIAL_DATATOKEN USBPID_DATA1
|
||||||
* interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1.
|
*/
|
||||||
* Since the token is toggled BEFORE sending any data, the first packet is
|
/*
|
||||||
* sent with the oposite value of this configuration!
|
* The above macro defines the startup condition for data toggling on the interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1. Since
|
||||||
|
* the token is toggled BEFORE sending any data, the first packet is sent with the oposite value of this configuration!
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_IMPLEMENT_HALT 0
|
#define USB_CFG_IMPLEMENT_HALT 0
|
||||||
/* Define this to 1 if you also want to implement the ENDPOINT_HALT feature
|
/*
|
||||||
* for endpoint 1 (interrupt endpoint). Although you may not need this feature,
|
* Define this to 1 if you also want to implement the ENDPOINT_HALT feature for endpoint 1 (interrupt endpoint). Although you may not need
|
||||||
* it is required by the standard. We have made it a config option because it
|
* this feature, it is required by the standard. We have made it a config option because it bloats the code considerably.
|
||||||
* bloats the code considerably.
|
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_SUPPRESS_INTR_CODE 1
|
#define USB_CFG_SUPPRESS_INTR_CODE 1
|
||||||
/* Define this to 1 if you want to declare interrupt-in endpoints, but don't
|
/*
|
||||||
* want to send any data over them. If this macro is defined to 1, functions
|
* Define this to 1 if you want to declare interrupt-in endpoints, but don't want to send any data over them. If this macro is defined to
|
||||||
* usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if
|
* 1, functions usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if you need the interrupt-in endpoints in order to
|
||||||
* you need the interrupt-in endpoints in order to comply to an interface
|
* comply to an interface (e.g. HID), but never want to send any data. This option saves a couple of bytes in flash memory and the transmit
|
||||||
* (e.g. HID), but never want to send any data. This option saves a couple
|
* buffers in RAM.
|
||||||
* of bytes in flash memory and the transmit buffers in RAM.
|
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_INTR_POLL_INTERVAL 20
|
#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
|
* 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
|
||||||
* low speed devices.
|
* than 10 ms for low speed devices.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_IS_SELF_POWERED 0
|
#define USB_CFG_IS_SELF_POWERED 0
|
||||||
/* Define this to 1 if the device has its own power supply. Set it to 0 if the
|
/*
|
||||||
* device is powered from the USB bus.
|
* Define this to 1 if the device has its own power supply. Set it to 0 if the device is powered from the USB bus.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_MAX_BUS_POWER 300
|
#define USB_CFG_MAX_BUS_POWER 300
|
||||||
/* Set this variable to the maximum USB bus power consumption of your device.
|
/*
|
||||||
* The value is in milliamperes. [It will be divided by two since USB
|
* Set this variable to the maximum USB bus power consumption of your device. The value is in milliamperes. [It will be divided by two
|
||||||
* communicates power requirements in units of 2 mA.]
|
* since USB communicates power requirements in units of 2 mA.]
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_IMPLEMENT_FN_WRITE 1
|
#define USB_CFG_IMPLEMENT_FN_WRITE 1
|
||||||
/* Set this to 1 if you want usbFunctionWrite() to be called for control-out
|
/*
|
||||||
* transfers. Set it to 0 if you don't need it and want to save a couple of
|
* Set this to 1 if you want usbFunctionWrite() to be called for control-out transfers. Set it to 0 if you don't need it and want to save a
|
||||||
* bytes.
|
* couple of bytes.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_IMPLEMENT_FN_READ 0
|
#define USB_CFG_IMPLEMENT_FN_READ 0
|
||||||
/* Set this to 1 if you need to send control replies which are generated
|
/*
|
||||||
* "on the fly" when usbFunctionRead() is called. If you only want to send
|
* Set this to 1 if you need to send control replies which are generated "on the fly" when usbFunctionRead() is called. If you only want to
|
||||||
* data from a static buffer, set it to 0 and return the data from
|
* send data from a static buffer, set it to 0 and return the data from usbFunctionSetup(). This saves a couple of bytes.
|
||||||
* usbFunctionSetup(). This saves a couple of bytes.
|
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_IMPLEMENT_FN_WRITEOUT 0
|
#define USB_CFG_IMPLEMENT_FN_WRITEOUT 0
|
||||||
/* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints.
|
/*
|
||||||
* You must implement the function usbFunctionWriteOut() which receives all
|
* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints. You must implement the function usbFunctionWriteOut() which
|
||||||
* interrupt/bulk data sent to any endpoint other than 0. The endpoint number
|
* receives all interrupt/bulk data sent to any endpoint other than 0. The endpoint number can be found in 'usbRxToken'.
|
||||||
* can be found in 'usbRxToken'.
|
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_HAVE_FLOWCONTROL 0
|
#define USB_CFG_HAVE_FLOWCONTROL 0
|
||||||
/* Define this to 1 if you want flowcontrol over USB data. See the definition
|
/*
|
||||||
* of the macros usbDisableAllRequests() and usbEnableAllRequests() in
|
* Define this to 1 if you want flowcontrol over USB data. See the definition of the macros usbDisableAllRequests() and
|
||||||
* usbdrv.h.
|
* usbEnableAllRequests() in usbdrv.h.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_LONG_TRANSFERS 0
|
#define USB_CFG_LONG_TRANSFERS 0
|
||||||
/* Define this to 1 if you want to send/receive blocks of more than 254 bytes
|
/*
|
||||||
* in a single control-in or control-out transfer. Note that the capability
|
* Define this to 1 if you want to send/receive blocks of more than 254 bytes in a single control-in or control-out transfer. Note that the
|
||||||
* for long transfers increases the driver size.
|
* capability for long transfers increases the driver size.
|
||||||
*/
|
*/
|
||||||
/* #define USB_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) blinkLED(); */
|
/*
|
||||||
/* This macro is a hook if you want to do unconventional things. If it is
|
* #define USB_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) blinkLED();
|
||||||
* defined, it's inserted at the beginning of received message processing.
|
|
||||||
* If you eat the received message and don't want default processing to
|
|
||||||
* proceed, do a return after doing your things. One possible application
|
|
||||||
* (besides debugging) is to flash a status LED on each packet.
|
|
||||||
*/
|
*/
|
||||||
/* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();} */
|
/*
|
||||||
/* This macro is a hook if you need to know when an USB RESET occurs. It has
|
* This macro is a hook if you want to do unconventional things. If it is defined, it's inserted at the beginning of received message
|
||||||
* one parameter which distinguishes between the start of RESET state and its
|
* processing. If you eat the received message and don't want default processing to proceed, do a return after doing your things. One
|
||||||
* end.
|
* possible application (besides debugging) is to flash a status LED on each packet.
|
||||||
*/
|
*/
|
||||||
/* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned(); */
|
/*
|
||||||
/* This macro (if defined) is executed when a USB SET_ADDRESS request was
|
* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();}
|
||||||
* received.
|
*/
|
||||||
|
/*
|
||||||
|
* This macro is a hook if you need to know when an USB RESET occurs. It has one parameter which distinguishes between the start of RESET
|
||||||
|
* state and its end.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned();
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This macro (if defined) is executed when a USB SET_ADDRESS request was received.
|
||||||
*/
|
*/
|
||||||
#define USB_COUNT_SOF 0
|
#define USB_COUNT_SOF 0
|
||||||
/* define this macro to 1 if you need the global variable "usbSofCount" which
|
/*
|
||||||
* counts SOF packets. This feature requires that the hardware interrupt is
|
* define this macro to 1 if you need the global variable "usbSofCount" which counts SOF packets. This feature requires that the hardware
|
||||||
* connected to D- instead of D+.
|
* interrupt is connected to D- instead of D+.
|
||||||
*/
|
*/
|
||||||
/* #ifdef __ASSEMBLER__
|
/*
|
||||||
* macro myAssemblerMacro
|
* #ifdef __ASSEMBLER__ macro myAssemblerMacro in YL, TCNT0 sts timer0Snapshot, YL endm #endif #define USB_SOF_HOOK myAssemblerMacro This
|
||||||
* in YL, TCNT0
|
* macro (if defined) is executed in the assembler module when a Start Of Frame condition is detected. It is recommended to define it to
|
||||||
* sts timer0Snapshot, YL
|
* the name of an assembler macro which is defined here as well so that more than one assembler instruction can be used. The macro may use
|
||||||
* endm
|
* the register YL and modify SREG. If it lasts longer than a couple of cycles, USB messages immediately after an SOF pulse may be lost and
|
||||||
* #endif
|
* must be retried by the host. What can you do with this hook? Since the SOF signal occurs exactly every 1 ms (unless the host is in sleep
|
||||||
* #define USB_SOF_HOOK myAssemblerMacro
|
* mode), you can use it to tune OSCCAL in designs running on the internal RC oscillator. Please note that Start Of Frame detection works
|
||||||
* This macro (if defined) is executed in the assembler module when a
|
* only if D- is wired to the interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES!
|
||||||
* Start Of Frame condition is detected. It is recommended to define it to
|
|
||||||
* the name of an assembler macro which is defined here as well so that more
|
|
||||||
* than one assembler instruction can be used. The macro may use the register
|
|
||||||
* YL and modify SREG. If it lasts longer than a couple of cycles, USB messages
|
|
||||||
* immediately after an SOF pulse may be lost and must be retried by the host.
|
|
||||||
* What can you do with this hook? Since the SOF signal occurs exactly every
|
|
||||||
* 1 ms (unless the host is in sleep mode), you can use it to tune OSCCAL in
|
|
||||||
* designs running on the internal RC oscillator.
|
|
||||||
* Please note that Start Of Frame detection works only if D- is wired to the
|
|
||||||
* interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES!
|
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_CHECK_DATA_TOGGLING 0
|
#define USB_CFG_CHECK_DATA_TOGGLING 0
|
||||||
/* define this macro to 1 if you want to filter out duplicate data packets
|
/*
|
||||||
* sent by the host. Duplicates occur only as a consequence of communication
|
* define this macro to 1 if you want to filter out duplicate data packets sent by the host. Duplicates occur only as a consequence of
|
||||||
* errors, when the host does not receive an ACK. Please note that you need to
|
* communication errors, when the host does not receive an ACK. Please note that you need to implement the filtering yourself in
|
||||||
* implement the filtering yourself in usbFunctionWriteOut() and
|
* usbFunctionWriteOut() and usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable for each control- and
|
||||||
* usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable
|
* out-endpoint to check for duplicate packets.
|
||||||
* for each control- and out-endpoint to check for duplicate packets.
|
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0
|
#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0
|
||||||
/* define this macro to 1 if you want the function usbMeasureFrameLength()
|
/*
|
||||||
* compiled in. This function can be used to calibrate the AVR's RC oscillator.
|
* define this macro to 1 if you want the function usbMeasureFrameLength() compiled in. This function can be used to calibrate the AVR's RC
|
||||||
|
* oscillator.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* -------------------------- Device Description --------------------------- */
|
/*
|
||||||
|
* -------------------------- Device Description ---------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
#define USB_CFG_VENDOR_ID 0xc0, 0x16
|
#define USB_CFG_VENDOR_ID 0xc0, 0x16
|
||||||
/* USB vendor ID for the device, low byte first. If you have registered your
|
/*
|
||||||
* own Vendor ID, define it here. Otherwise you use one of obdev's free shared
|
* USB vendor ID for the device, low byte first. If you have registered your own Vendor ID, define it here. Otherwise you use one of
|
||||||
* VID/PID pairs. Be sure to read USBID-License.txt for rules!
|
* obdev's free shared VID/PID pairs. Be sure to read USBID-License.txt for rules!
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_DEVICE_ID 0xdd, 0x05
|
#define USB_CFG_DEVICE_ID 0xdd, 0x05
|
||||||
/* This is the ID of the product, low byte first. It is interpreted in the
|
/*
|
||||||
* scope of the vendor ID. If you have registered your own VID with usb.org
|
* This is the ID of the product, low byte first. It is interpreted in the scope of the vendor ID. If you have registered your own VID with
|
||||||
* or if you have licensed a PID from somebody else, define it here. Otherwise
|
* usb.org or if you have licensed a PID from somebody else, define it here. Otherwise you use obdev's free shared VID/PID pair. Be sure to
|
||||||
* you use obdev's free shared VID/PID pair. Be sure to read the rules in
|
* read the rules in USBID-License.txt!
|
||||||
* USBID-License.txt!
|
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_DEVICE_VERSION 0x00, 0x01
|
#define USB_CFG_DEVICE_VERSION 0x00, 0x01
|
||||||
/* Version number of the device: Minor number first, then major number.
|
/*
|
||||||
|
* Version number of the device: Minor number first, then major number.
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_VENDOR_NAME 'o', 'p', 't', 'i', 'x', 'x', '.', 'o', 'r', 'g'
|
#define USB_CFG_VENDOR_NAME 'o', 'p', 't', 'i', 'x', 'x', '.', 'o', 'r', 'g'
|
||||||
#define USB_CFG_VENDOR_NAME_LEN 10
|
#define USB_CFG_VENDOR_NAME_LEN 10
|
||||||
/* These two values define the vendor name returned by the USB device. The name
|
/*
|
||||||
* must be given as a list of characters under single quotes. The characters
|
* These two values define the vendor name returned by the USB device. The name must be given as a list of characters under single quotes.
|
||||||
* are interpreted as Unicode (UTF-16) entities.
|
* The characters are interpreted as Unicode (UTF-16) entities. If you don't want a vendor name string, undefine these macros. ALWAYS
|
||||||
* If you don't want a vendor name string, undefine these macros.
|
* define a vendor name containing your Internet domain name if you use obdev's free shared VID/PID pair. See the file USBID-License.txt
|
||||||
* ALWAYS define a vendor name containing your Internet domain name if you use
|
* for details.
|
||||||
* obdev's free shared VID/PID pair. See the file USBID-License.txt for
|
|
||||||
* details.
|
|
||||||
*/
|
*/
|
||||||
#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
|
/*
|
||||||
* the macros. See the file USBID-License.txt before you assign a name if you
|
* Same as above for the device name. If you don't want a device name, undefine the macros. See the file USBID-License.txt before you
|
||||||
* use a shared VID/PID.
|
* assign a name if you use a shared VID/PID.
|
||||||
*/
|
*/
|
||||||
/*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */
|
/*
|
||||||
/*#define USB_CFG_SERIAL_NUMBER_LEN 0 */
|
* #define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e'
|
||||||
/* Same as above for the serial number. If you don't want a serial number,
|
|
||||||
* undefine the macros.
|
|
||||||
* It may be useful to provide the serial number through other means than at
|
|
||||||
* compile time. See the section about descriptor properties below for how
|
|
||||||
* to fine tune control over USB descriptors such as the string descriptor
|
|
||||||
* for the serial number.
|
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_DEVICE_CLASS 0xff /* set to 0 if deferred to interface */
|
/*
|
||||||
|
* #define USB_CFG_SERIAL_NUMBER_LEN 0
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Same as above for the serial number. If you don't want a serial number, undefine the macros. It may be useful to provide the serial
|
||||||
|
* number through other means than at compile time. See the section about descriptor properties below for how to fine tune control over USB
|
||||||
|
* descriptors such as the string descriptor for the serial number.
|
||||||
|
*/
|
||||||
|
#define USB_CFG_DEVICE_CLASS 0xff /* set to 0 if deferred to interface */
|
||||||
#define USB_CFG_DEVICE_SUBCLASS 0
|
#define USB_CFG_DEVICE_SUBCLASS 0
|
||||||
/* See USB specification if you want to conform to an existing device class.
|
/*
|
||||||
* Class 0xff is "vendor specific".
|
* See USB specification if you want to conform to an existing device class. Class 0xff is "vendor specific".
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_INTERFACE_CLASS 0 /* define class here if not at device level */
|
#define USB_CFG_INTERFACE_CLASS 0 /* define class here if not at device level */
|
||||||
#define USB_CFG_INTERFACE_SUBCLASS 0
|
#define USB_CFG_INTERFACE_SUBCLASS 0
|
||||||
#define USB_CFG_INTERFACE_PROTOCOL 0
|
#define USB_CFG_INTERFACE_PROTOCOL 0
|
||||||
/* See USB specification if you want to conform to an existing device class or
|
/*
|
||||||
* protocol. The following classes must be set at interface level:
|
* See USB specification if you want to conform to an existing device class or protocol. The following classes must be set at interface
|
||||||
* HID class is 3, no subclass and protocol required (but may be useful!)
|
* level: HID class is 3, no subclass and protocol required (but may be useful!) CDC class is 2, use subclass 2 and protocol 1 for ACM
|
||||||
* CDC class is 2, use subclass 2 and protocol 1 for ACM
|
|
||||||
*/
|
*/
|
||||||
#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 0
|
#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 0
|
||||||
|
|
||||||
/* Define this to the length of the HID report descriptor, if you implement
|
/*
|
||||||
* an HID device. Otherwise don't define it or define it to 0.
|
* Define this to the length of the HID report descriptor, if you implement an HID device. Otherwise don't define it or define it to 0. If
|
||||||
* If you use this define, you must add a PROGMEM character array named
|
* you use this define, you must add a PROGMEM character array named "usbHidReportDescriptor" to your code which contains the report
|
||||||
* "usbHidReportDescriptor" to your code which contains the report descriptor.
|
* descriptor. Don't forget to keep the array and this define in sync!
|
||||||
* Don't forget to keep the array and this define in sync!
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* #define USB_PUBLIC static */
|
/*
|
||||||
/* Use the define above if you #include usbdrv.c instead of linking against it.
|
* #define USB_PUBLIC static
|
||||||
* This technique saves a couple of bytes in flash memory.
|
*/
|
||||||
|
/*
|
||||||
|
* Use the define above if you #include usbdrv.c instead of linking against it. This technique saves a couple of bytes in flash memory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* ------------------- Fine Control over USB Descriptors ------------------- */
|
/*
|
||||||
/* If you don't want to use the driver's default USB descriptors, you can
|
* ------------------- Fine Control over USB Descriptors -------------------
|
||||||
* provide our own. These can be provided as (1) fixed length static data in
|
*/
|
||||||
* flash memory, (2) fixed length static data in RAM or (3) dynamically at
|
/*
|
||||||
* runtime in the function usbFunctionDescriptor(). See usbdrv.h for more
|
* If you don't want to use the driver's default USB descriptors, you can provide our own. These can be provided as (1) fixed length static
|
||||||
* information about this function.
|
* data in flash memory, (2) fixed length static data in RAM or (3) dynamically at runtime in the function usbFunctionDescriptor(). See
|
||||||
* Descriptor handling is configured through the descriptor's properties. If
|
* usbdrv.h for more information about this function. Descriptor handling is configured through the descriptor's properties. If no
|
||||||
* no properties are defined or if they are 0, the default descriptor is used.
|
* properties are defined or if they are 0, the default descriptor is used. Possible properties are: + USB_PROP_IS_DYNAMIC: The data for
|
||||||
* Possible properties are:
|
* the descriptor should be fetched at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is used, the data is in FLASH by
|
||||||
* + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched
|
* default. Add property USB_PROP_IS_RAM if you want RAM pointers. + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or
|
||||||
* at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is
|
* found in static memory is in RAM, not in flash memory. + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash), the
|
||||||
* used, the data is in FLASH by default. Add property USB_PROP_IS_RAM if
|
* driver must know the descriptor's length. The descriptor itself is found at the address of a well known identifier (see below). List of
|
||||||
* you want RAM pointers.
|
* static descriptor names (must be declared PROGMEM if in flash): char usbDescriptorDevice[]; char usbDescriptorConfiguration[]; char
|
||||||
* + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found
|
* usbDescriptorHidReport[]; char usbDescriptorString0[]; int usbDescriptorStringVendor[]; int usbDescriptorStringDevice[]; int
|
||||||
* in static memory is in RAM, not in flash memory.
|
* usbDescriptorStringSerialNumber[]; Other descriptors can't be provided statically, they must be provided dynamically at runtime.
|
||||||
* + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash),
|
* Descriptor properties are or-ed or added together, e.g.: #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18)) The
|
||||||
* the driver must know the descriptor's length. The descriptor itself is
|
* following descriptors are defined: USB_CFG_DESCR_PROPS_DEVICE USB_CFG_DESCR_PROPS_CONFIGURATION USB_CFG_DESCR_PROPS_STRINGS
|
||||||
* found at the address of a well known identifier (see below).
|
* USB_CFG_DESCR_PROPS_STRING_0 USB_CFG_DESCR_PROPS_STRING_VENDOR USB_CFG_DESCR_PROPS_STRING_PRODUCT
|
||||||
* List of static descriptor names (must be declared PROGMEM if in flash):
|
* USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER USB_CFG_DESCR_PROPS_HID USB_CFG_DESCR_PROPS_HID_REPORT USB_CFG_DESCR_PROPS_UNKNOWN (for all
|
||||||
* char usbDescriptorDevice[];
|
* descriptors not handled by the driver) Note about string descriptors: String descriptors are not just strings, they are Unicode strings
|
||||||
* char usbDescriptorConfiguration[];
|
* prefixed with a 2 byte header. Example: int serialNumberDescriptor[] = { USB_STRING_DESCRIPTOR_HEADER(6), 'S', 'e', 'r', 'i', 'a', 'l'
|
||||||
* char usbDescriptorHidReport[];
|
|
||||||
* char usbDescriptorString0[];
|
|
||||||
* int usbDescriptorStringVendor[];
|
|
||||||
* int usbDescriptorStringDevice[];
|
|
||||||
* int usbDescriptorStringSerialNumber[];
|
|
||||||
* Other descriptors can't be provided statically, they must be provided
|
|
||||||
* dynamically at runtime.
|
|
||||||
*
|
|
||||||
* Descriptor properties are or-ed or added together, e.g.:
|
|
||||||
* #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18))
|
|
||||||
*
|
|
||||||
* The following descriptors are defined:
|
|
||||||
* USB_CFG_DESCR_PROPS_DEVICE
|
|
||||||
* USB_CFG_DESCR_PROPS_CONFIGURATION
|
|
||||||
* USB_CFG_DESCR_PROPS_STRINGS
|
|
||||||
* USB_CFG_DESCR_PROPS_STRING_0
|
|
||||||
* USB_CFG_DESCR_PROPS_STRING_VENDOR
|
|
||||||
* USB_CFG_DESCR_PROPS_STRING_PRODUCT
|
|
||||||
* USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER
|
|
||||||
* USB_CFG_DESCR_PROPS_HID
|
|
||||||
* USB_CFG_DESCR_PROPS_HID_REPORT
|
|
||||||
* USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver)
|
|
||||||
*
|
|
||||||
* Note about string descriptors: String descriptors are not just strings, they
|
|
||||||
* are Unicode strings prefixed with a 2 byte header. Example:
|
|
||||||
* int serialNumberDescriptor[] = {
|
|
||||||
* USB_STRING_DESCRIPTOR_HEADER(6),
|
|
||||||
* 'S', 'e', 'r', 'i', 'a', 'l'
|
|
||||||
* };
|
* };
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -353,21 +315,38 @@ section at the end of this file).
|
|||||||
#define USB_CFG_DESCR_PROPS_HID_REPORT 0
|
#define USB_CFG_DESCR_PROPS_HID_REPORT 0
|
||||||
#define USB_CFG_DESCR_PROPS_UNKNOWN 0
|
#define USB_CFG_DESCR_PROPS_UNKNOWN 0
|
||||||
|
|
||||||
/* ----------------------- Optional MCU Description ------------------------ */
|
/*
|
||||||
|
* ----------------------- Optional MCU Description ------------------------
|
||||||
/* The following configurations have working defaults in usbdrv.h. You
|
|
||||||
* usually don't need to set them explicitly. Only if you want to run
|
|
||||||
* the driver on a device which is not yet supported or with a compiler
|
|
||||||
* which is not fully supported (such as IAR C) or if you use a differnt
|
|
||||||
* interrupt than INT0, you may have to define some of these.
|
|
||||||
*/
|
*/
|
||||||
/* #define USB_INTR_CFG MCUCR */
|
|
||||||
/* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */
|
|
||||||
/* #define USB_INTR_CFG_CLR 0 */
|
|
||||||
/* #define USB_INTR_ENABLE GIMSK */
|
|
||||||
/* #define USB_INTR_ENABLE_BIT INT0 */
|
|
||||||
/* #define USB_INTR_PENDING GIFR */
|
|
||||||
/* #define USB_INTR_PENDING_BIT INTF0 */
|
|
||||||
/* #define USB_INTR_VECTOR SIG_INTERRUPT0 */
|
|
||||||
|
|
||||||
#endif /* __usbconfig_h_included__ */
|
/*
|
||||||
|
* The following configurations have working defaults in usbdrv.h. You usually don't need to set them explicitly. Only if you want to run
|
||||||
|
* the driver on a device which is not yet supported or with a compiler which is not fully supported (such as IAR C) or if you use a
|
||||||
|
* differnt interrupt than INT0, you may have to define some of these.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* #define USB_INTR_CFG MCUCR
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01))
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* #define USB_INTR_CFG_CLR 0
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* #define USB_INTR_ENABLE GIMSK
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* #define USB_INTR_ENABLE_BIT INT0
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* #define USB_INTR_PENDING GIFR
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* #define USB_INTR_PENDING_BIT INTF0
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* #define USB_INTR_VECTOR SIG_INTERRUPT0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* __usbconfig_h_included__ */
|
||||||
|
|||||||
@ -22,111 +22,124 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
uint8_t *util_strupper(uint8_t *s)
|
uint8_t *util_strupper(uint8_t * s)
|
||||||
{
|
{
|
||||||
uint8_t *p;
|
uint8_t *p;
|
||||||
for (p = s; *p != '\0'; p++)
|
for (p = s; *p != '\0'; p++)
|
||||||
if (*p >= 'a' && *p <= 'z')
|
if (*p >= 'a' && *p <= 'z')
|
||||||
*p += 'A' - 'a';
|
*p += 'A' - 'a';
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *util_strlower(uint8_t *s)
|
uint8_t *util_strlower(uint8_t * s)
|
||||||
{
|
{
|
||||||
uint8_t *p;
|
uint8_t *p;
|
||||||
for (p = s; *p != '\0'; p++)
|
for (p = s; *p != '\0'; p++)
|
||||||
if (*p >= 'A' && *p <= 'Z')
|
if (*p >= 'A' && *p <= 'Z')
|
||||||
*p += 'a' - 'A';
|
*p += 'a' - 'A';
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void util_chomp(uint8_t *s)
|
void util_chomp(uint8_t * s)
|
||||||
{
|
{
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
|
|
||||||
len = strlen((char*)s);
|
len = strlen((char *) s);
|
||||||
if (len >= 2 && s[len - 1] == '\n' && s[len - 2] == '\r')
|
if (len >= 2 && s[len - 1] == '\n' && s[len - 2] == '\r')
|
||||||
s[len - 2] = '\0';
|
s[len - 2] = '\0';
|
||||||
else if (len >= 1 && (s[len - 1] == '\n' || s[len - 1] == '\r'))
|
else if (len >= 1 && (s[len - 1] == '\n' || s[len - 1] == '\r'))
|
||||||
s[len - 1] = '\0';
|
s[len - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
void util_trim(uint8_t *s)
|
void util_trim(uint8_t * s)
|
||||||
{
|
{
|
||||||
uint8_t *p = s;
|
uint8_t *p = s;
|
||||||
uint8_t *q;
|
uint8_t *q;
|
||||||
/* skip leading whitespace */
|
/*
|
||||||
while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n')
|
* skip leading whitespace
|
||||||
p++;
|
*/
|
||||||
/* now p points at the first non-whitespace uint8_tacter */
|
while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n')
|
||||||
|
p++;
|
||||||
|
/*
|
||||||
|
* now p points at the first non-whitespace uint8_tacter
|
||||||
|
*/
|
||||||
|
|
||||||
if (*p == '\0') {
|
if (*p == '\0') {
|
||||||
/* only whitespace */
|
/*
|
||||||
*s = '\0';
|
* only whitespace
|
||||||
return;
|
*/
|
||||||
}
|
*s = '\0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
q = s + strlen((char*)s);
|
q = s + strlen((char *) s);
|
||||||
/* skip trailing whitespace */
|
/*
|
||||||
/* we have found p < q such that *p is non-whitespace,
|
* skip trailing whitespace
|
||||||
so this loop terminates with q >= p */
|
*/
|
||||||
do
|
/*
|
||||||
q--;
|
* we have found p < q such that *p is non-whitespace, so this loop terminates with q >= p
|
||||||
while (*q == ' ' || *q == '\t' || *q == '\r' || *q == '\n');
|
*/
|
||||||
|
do
|
||||||
|
q--;
|
||||||
|
while (*q == ' ' || *q == '\t' || *q == '\r' || *q == '\n');
|
||||||
|
|
||||||
/* now q points at the last non-whitespace uint8_tacter */
|
/*
|
||||||
/* cut off trailing whitespace */
|
* now q points at the last non-whitespace uint8_tacter
|
||||||
*++q = '\0';
|
*/
|
||||||
|
/*
|
||||||
|
* cut off trailing whitespace
|
||||||
|
*/
|
||||||
|
*++q = '\0';
|
||||||
|
|
||||||
/* move to string */
|
/*
|
||||||
memmove(s, p, q + 1 - p);
|
* move to string
|
||||||
|
*/
|
||||||
|
memmove(s, p, q + 1 - p);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t util_sscandec(const uint8_t *s)
|
uint32_t util_sscandec(const uint8_t * s)
|
||||||
{
|
{
|
||||||
uint32_t result;
|
uint32_t result;
|
||||||
if (*s == '\0')
|
if (*s == '\0')
|
||||||
return -1;
|
return -1;
|
||||||
result = 0;
|
result = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (*s >= '0' && *s <= '9')
|
if (*s >= '0' && *s <= '9')
|
||||||
result = 10 * result + *s - '0';
|
result = 10 * result + *s - '0';
|
||||||
else if (*s == '\0')
|
else if (*s == '\0')
|
||||||
return result;
|
return result;
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t util_sscanhex(const uint8_t *s)
|
uint32_t util_sscanhex(const uint8_t * s)
|
||||||
{
|
{
|
||||||
int32_t result;
|
int32_t result;
|
||||||
if (*s == '\0')
|
if (*s == '\0')
|
||||||
return -1;
|
return -1;
|
||||||
result = 0;
|
result = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (*s >= '0' && *s <= '9')
|
if (*s >= '0' && *s <= '9')
|
||||||
result = 16 * result + *s - '0';
|
result = 16 * result + *s - '0';
|
||||||
else if (*s >= 'A' && *s <= 'F')
|
else if (*s >= 'A' && *s <= 'F')
|
||||||
result = 16 * result + *s - 'A' + 10;
|
result = 16 * result + *s - 'A' + 10;
|
||||||
else if (*s >= 'a' && *s <= 'f')
|
else if (*s >= 'a' && *s <= 'f')
|
||||||
result = 16 * result + *s - 'a' + 10;
|
result = 16 * result + *s - 'a' + 10;
|
||||||
else if (*s == '\0')
|
else if (*s == '\0')
|
||||||
return result;
|
return result;
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t util_sscanbool(const uint8_t *s)
|
uint8_t util_sscanbool(const uint8_t * s)
|
||||||
{
|
{
|
||||||
if (*s == '0' && s[1] == '\0')
|
if (*s == '0' && s[1] == '\0')
|
||||||
return 0;
|
return 0;
|
||||||
if (*s == '1' && s[1] == '\0')
|
if (*s == '1' && s[1] == '\0')
|
||||||
return 1;
|
return 1;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -21,12 +21,12 @@
|
|||||||
#ifndef __UTIL_H__
|
#ifndef __UTIL_H__
|
||||||
#define __UTIL_H__
|
#define __UTIL_H__
|
||||||
|
|
||||||
uint8_t *util_strupper(uint8_t *s);
|
uint8_t *util_strupper(uint8_t * s);
|
||||||
uint8_t *util_strlower(uint8_t *s);
|
uint8_t *util_strlower(uint8_t * s);
|
||||||
void util_chomp(uint8_t *s);
|
void util_chomp(uint8_t * s);
|
||||||
void util_trim(uint8_t *s);
|
void util_trim(uint8_t * s);
|
||||||
uint32_t util_sscandec(const uint8_t *s);
|
uint32_t util_sscandec(const uint8_t * s);
|
||||||
uint32_t util_sscanhex(const uint8_t *s);
|
uint32_t util_sscanhex(const uint8_t * s);
|
||||||
uint8_t util_sscanbool(const uint8_t *s);
|
uint8_t util_sscanbool(const uint8_t * s);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -28,4 +28,3 @@ void wdt_init(void)
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,7 @@
|
|||||||
#define __WATCHDOG_H__
|
#define __WATCHDOG_H__
|
||||||
|
|
||||||
|
|
||||||
void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3")));
|
void wdt_init(void) __attribute__ ((naked)) __attribute__ ((section(".init3")));
|
||||||
|
|
||||||
#define soft_reset() \
|
#define soft_reset() \
|
||||||
do \
|
do \
|
||||||
@ -39,4 +39,3 @@ do \
|
|||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user