indent cleanup

This commit is contained in:
optixx 2010-07-19 16:35:47 +02:00
parent 0f0c6eb409
commit c09d1a1918
38 changed files with 5177 additions and 3112 deletions

View File

@ -66,18 +66,18 @@ void boot_startup_rom(uint16_t init_delay)
info_P(PSTR("Fetch loader rom\n"));
system_set_bus_avr();
//snes_irq_lo();
//system_snes_irq_off();
// snes_irq_lo();
// system_snes_irq_off();
system_set_rom_lorom();
//info_P(PSTR("Activate AVR bus\n"));
//avr_bus_active();
//info_P(PSTR("IRQ off\n"));
//snes_irq_lo();
//snes_irq_off();
//snes_lorom();
// info_P(PSTR("Activate AVR bus\n"));
// avr_bus_active();
// info_P(PSTR("IRQ off\n"));
// snes_irq_lo();
// snes_irq_off();
// 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);
}
info_P(PSTR("\n"));
@ -85,19 +85,19 @@ void boot_startup_rom(uint16_t init_delay)
#if DO_CRC_CHECK_LOADER
dump_memory(0x010000 - 0x100, 0x010000);
uint16_t crc;
crc = crc_check_bulk_memory((uint32_t)0x000000,0x010000, 0x010000);
info(PSTR("crc=%x\n"),crc);
crc = crc_check_bulk_memory((uint32_t) 0x000000, 0x010000, 0x010000);
info(PSTR("crc=%x\n"), crc);
#endif
//snes_irq_lo();
//snes_irq_off();
//snes_hirom();
//snes_wr_disable();
// snes_irq_lo();
// snes_irq_off();
// snes_hirom();
// snes_wr_disable();
//system_set_bus_snes();
//system_set_rom_hirom();
//system_set_wr_disable();
//system_snes_irq_off();
// system_set_bus_snes();
// system_set_rom_hirom();
// system_set_wr_disable();
// system_snes_irq_off();
snes_irq_lo();
system_snes_irq_off();
@ -108,39 +108,46 @@ void boot_startup_rom(uint16_t init_delay)
system_send_snes_reset();
info_P(PSTR("Move Loader to wram"));
for (i=0;i<30;i++){
for (i = 0; i < 30; i++) {
_delay_ms(20);
info_P(PSTR("."));
}
info_P(PSTR("\n"));
}
void banner(){
void banner()
{
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(" / / \\ \\| | \\ |/ ___\\| |/ / | | \\_/ __ \\ \\/ /| / __ \\ \n"));
info_P(PSTR(" / \\_/. \\ | / \\ \\___| < | ` \\ ___/\\ / | \\ |__\\ \\ \n"));
info_P(PSTR(" \\_____\\ \\_/____/|__|\\___ >__|_ \\/_______ /\\___ >\\_/ |___|\\_____ / \n"));
info_P(PSTR(" \\__> \\/ \\/ \\/ \\/ \\/ \n"));
info_P(PSTR
(" ________ .__ __ ________ ____ ________\n"));
info_P(PSTR
(" \\_____ \\ __ __|__| ____ | | __\\______ \\ _______ _/_ |/ _____/\n"));
info_P(PSTR
(" / / \\ \\| | \\ |/ ___\\| |/ / | | \\_/ __ \\ \\/ /| / __ \\ \n"));
info_P(PSTR
(" / \\_/. \\ | / \\ \\___| < | ` \\ ___/\\ / | \\ |__\\ \\ \n"));
info_P(PSTR
(" \\_____\\ \\_/____/|__|\\___ >__|_ \\/_______ /\\___ >\\_/ |___|\\_____ / \n"));
info_P(PSTR
(" \\__> \\/ \\/ \\/ \\/ \\/ \n"));
info_P(PSTR("\n"));
info_P(PSTR(" www.optixx.org\n"));
info_P(PSTR("\n"));
info_P(PSTR("System Hw: %s Sw: %s\n"),HW_VERSION,SW_VERSION);
info_P(PSTR("System Hw: %s Sw: %s\n"), HW_VERSION, SW_VERSION);
}
void transaction_status(){
info_P(PSTR("\nAddr 0x%06lx\n"),usb_trans.req_addr);
info_P(PSTR("Bank 0x%02x\n"),usb_trans.req_bank);
info_P(PSTR("Banksize 0x%06lx\n"),usb_trans.req_bank_size);
info_P(PSTR("Bankcount 0x%02x\n"),usb_trans.req_bank_cnt);
info_P(PSTR("Status 0x%02x\n"),usb_trans.req_state);
info_P(PSTR("Percent %02i\n"),usb_trans.req_percent);
info_P(PSTR("TX buffer %02i\n"),usb_trans.tx_remaining);
info_P(PSTR("RX buffer %02i\n"),usb_trans.rx_remaining);
info_P(PSTR("Syncerr %02i\n"),usb_trans.sync_errors);
void transaction_status()
{
info_P(PSTR("\nAddr 0x%06lx\n"), usb_trans.req_addr);
info_P(PSTR("Bank 0x%02x\n"), usb_trans.req_bank);
info_P(PSTR("Banksize 0x%06lx\n"), usb_trans.req_bank_size);
info_P(PSTR("Bankcount 0x%02x\n"), usb_trans.req_bank_cnt);
info_P(PSTR("Status 0x%02x\n"), usb_trans.req_state);
info_P(PSTR("Percent %02i\n"), usb_trans.req_percent);
info_P(PSTR("TX buffer %02i\n"), usb_trans.tx_remaining);
info_P(PSTR("RX buffer %02i\n"), usb_trans.rx_remaining);
info_P(PSTR("Syncerr %02i\n"), usb_trans.sync_errors);
}

View File

@ -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;
uint32_t addr = 0;
uint8_t req_bank = 0;
sram_bulk_read_start(bottom_addr);
debug_P(DEBUG_CRC, PSTR("crc_check_bulk_memory: bottom_addr=0x%08lx top_addr=0x%08lx\n"),
bottom_addr,top_addr);
debug_P(DEBUG_CRC,
PSTR
("crc_check_bulk_memory: bottom_addr=0x%08lx top_addr=0x%08lx\n"),
bottom_addr, top_addr);
for (addr = bottom_addr; addr < top_addr; addr++) {
if (addr && ((addr % bank_size) == 0)) {
debug_P(DEBUG_CRC, PSTR("crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n"),
req_bank,addr,crc);
debug_P(DEBUG_CRC,
PSTR
("crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n"),
req_bank, addr, crc);
req_bank++;
crc = 0;
}
@ -85,8 +90,10 @@ uint16_t crc_check_bulk_memory(uint32_t bottom_addr, uint32_t top_addr, uint32_t
sram_bulk_read_next();
}
if (addr % 0x8000 == 0)
debug_P(DEBUG_CRC, PSTR("crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n"),
req_bank,addr,crc);
debug_P(DEBUG_CRC,
PSTR
("crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n"),
req_bank, addr, crc);
sram_bulk_read_end();
return crc;
}
@ -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;
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);
crc = do_crc_update(crc, buffer, TRANSFER_BUFFER_SIZE);
}

View File

@ -27,9 +27,11 @@
uint16_t crc_xmodem_update(uint16_t crc, uint8_t data);
uint16_t do_crc(uint8_t * data,uint16_t size);
uint16_t do_crc_update(uint16_t crc,uint8_t * data,uint16_t size);
uint16_t crc_check_memory_range(uint32_t start_addr, uint32_t size,uint8_t *buffer);
uint16_t crc_check_bulk_memory(uint32_t bottom_addr, uint32_t bank_size,uint32_t top_addr);
uint16_t do_crc(uint8_t * data, uint16_t size);
uint16_t do_crc_update(uint16_t crc, uint8_t * data, uint16_t size);
uint16_t crc_check_memory_range(uint32_t start_addr, uint32_t size,
uint8_t * buffer);
uint16_t crc_check_bulk_memory(uint32_t bottom_addr, uint32_t bank_size,
uint32_t top_addr);
#endif

View File

@ -32,7 +32,8 @@ extern int debug_level; /* the higher, the more messages... */
#if defined(NO_DEBUG) && defined(__GNUC__)
#else
void debug(int level, char* format, ...) {
void debug(int level, char *format, ...)
{
#ifdef NO_DEBUG
#else
@ -47,23 +48,23 @@ void debug(int level, char* format, ...) {
#endif
#ifndef NO_INFO
uint8_t buffer_debug[FORMAT_BUFFER_LEN];
uint8_t buffer_debug[FORMAT_BUFFER_LEN];
#endif
#if defined(NO_DEBUG) && defined(__GNUC__)
#else
void debug_P(int level, PGM_P format, ...) {
void debug_P(int level, PGM_P format, ...)
{
#ifdef NO_DEBUG
#else
va_list args;
if (!(debug_level & level))
return;
strlcpy_P((char*)buffer_debug,format,FORMAT_BUFFER_LEN);
strlcpy_P((char *) buffer_debug, format, FORMAT_BUFFER_LEN);
va_start(args, format);
vprintf((char*)buffer_debug, args);
vprintf((char *) buffer_debug, args);
va_end(args);
#endif
}
#endif

View File

@ -29,27 +29,30 @@
#include <avr/pgmspace.h>
#if defined(NO_DEBUG) && defined(__GNUC__)
/* gcc's cpp has extensions; it allows for macros with a variable number of
arguments. We use this extension here to preprocess pmesg away. */
/*
* gcc's cpp has extensions; it allows for macros with a variable number of arguments. We use this extension here to preprocess pmesg away.
*/
#define debug(level, format, args...) ((void)0)
#else
void debug(int level, char *format, ...);
/* print a message, if it is considered significant enough.
Adapted from [K&R2], p. 174 */
/*
* print a message, if it is considered significant enough. Adapted from [K&R2], p. 174
*/
#endif
#if defined(NO_DEBUG) && defined(__GNUC__)
/* gcc's cpp has extensions; it allows for macros with a variable number of
arguments. We use this extension here to preprocess pmesg away. */
/*
* gcc's cpp has extensions; it allows for macros with a variable number of arguments. We use this extension here to preprocess pmesg away.
*/
#define debug_P(level, format, args...) ((void)0)
#else
void debug_P(int level, PGM_P format, ...);
/* print a message, if it is considered significant enough.
Adapted from [K&R2], p. 174 */
/*
* print a message, if it is considered significant enough. Adapted from [K&R2], p. 174
*/
#endif
#endif /* DEBUG_H */

View File

@ -33,7 +33,7 @@ extern FILE uart_stdout;
void dump_packet(uint32_t addr, uint32_t len, uint8_t * packet)
{
uint16_t i,j;
uint16_t i, j;
uint16_t sum = 0;
uint8_t clear = 0;
@ -71,8 +71,8 @@ void dump_memory(uint32_t bottom_addr, uint32_t top_addr)
uint32_t addr;
uint8_t byte;
sram_bulk_read_start(bottom_addr);
for ( addr = bottom_addr; addr < top_addr; addr++) {
if (addr%0x10 == 0)
for (addr = bottom_addr; addr < top_addr; addr++) {
if (addr % 0x10 == 0)
info_P(PSTR("\n%08lx:"), addr);
byte = sram_bulk_read();
sram_bulk_read_next();

View File

@ -28,7 +28,6 @@
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

View File

@ -37,7 +37,8 @@ extern FILE uart_stdout;
#define info(format, args...) ((void)0)
#else
void info(char* format, ...) {
void info(char *format, ...)
{
#ifdef NO_INFO
#else
@ -51,7 +52,7 @@ void info(char* format, ...) {
#ifndef NO_INFO
uint8_t buffer_info[FORMAT_BUFFER_LEN];
uint8_t buffer_info[FORMAT_BUFFER_LEN];
#endif
#if defined(NO_INFO) && defined(__GNUC__)
@ -59,16 +60,16 @@ void info(char* format, ...) {
#define info(format, args...) ((void)0)
#else
void info_P(PGM_P format, ...) {
void info_P(PGM_P format, ...)
{
#ifdef NO_INFO
#else
strlcpy_P((char*)buffer_info,format,FORMAT_BUFFER_LEN);
strlcpy_P((char *) buffer_info, format, FORMAT_BUFFER_LEN);
va_list args;
va_start(args, format);
vprintf((char*)buffer_info, args);
vprintf((char *) buffer_info, args);
va_end(args);
#endif
}
#endif

View File

@ -29,24 +29,28 @@
#include <avr/pgmspace.h>
#if defined(NO_INFO) && defined(__GNUC__)
/* gcc's cpp has extensions; it allows for macros with a variable number of
arguments. We use this extension here to preprocess pmesg away. */
/*
* gcc's cpp has extensions; it allows for macros with a variable number of arguments. We use this extension here to preprocess pmesg away.
*/
#define info(format, args...) ((void)0)
#else
void info(char *format, ...);
/* print a message, if it is considered significant enough.
Adapted from [K&R2], p. 174 */
/*
* print a message, if it is considered significant enough. Adapted from [K&R2], p. 174
*/
#endif
#if defined(NO_INFO) && defined(__GNUC__)
/* gcc's cpp has extensions; it allows for macros with a variable number of
arguments. We use this extension here to preprocess pmesg away. */
/*
* gcc's cpp has extensions; it allows for macros with a variable number of arguments. We use this extension here to preprocess pmesg away.
*/
#define info_P(format, args...) ((void)0)
#else
void info_P(PGM_P format, ...);
/* print a message, if it is considered significant enough.
Adapted from [K&R2], p. 174 */
/*
* print a message, if it is considered significant enough. Adapted from [K&R2], p. 174
*/
#endif

View File

@ -29,8 +29,7 @@
#include "usbdrv.h"
#include "oddebug.h" /* This is also an example for using debug
* macros */
#include "oddebug.h" /* This is also an example for using debug macros */
#include "debug.h"
#include "info.h"
#include "sram.h"
@ -40,17 +39,19 @@ extern system_t system;
void (*jump_to_app) (void) = 0x0000;
void irq_init(){
void irq_init()
{
cli();
PCMSK3 |=(1<<PCINT27);
PCICR |= (1<<PCIE3);
PCMSK3 |= (1 << PCINT27);
PCICR |= (1 << PCIE3);
sei();
system.reset_irq = RESET_IRQ_ON;
}
void irq_stop(){
void irq_stop()
{
cli();
PCMSK3 &=~(1<<PCINT27);
PCMSK3 &= ~(1 << PCINT27);
sei();
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("Set watchdog...\n"));
leave_application();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,6 @@
/*
File: qd16boot01.smc
Time: Fri, 30 Oct 2009 16:49:11
*/
* File: qd16boot01.smc Time: Fri, 30 Oct 2009 16:49:11
*/
#ifndef __FIFO_H__
#define __FIFO_H__

View File

@ -70,20 +70,24 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
usb_trans.req_bank = 0;
usb_trans.rx_remaining = 0;
debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_INIT: %i %i\n"), rq->wValue.word,
rq->wIndex.word);
debug_P(DEBUG_USB, PSTR("USB_BULK_UPLOAD_INIT: %i %i\n"),
rq->wValue.word, rq->wIndex.word);
usb_trans.req_bank_size = (uint32_t) (1L << rq->wValue.word);
usb_trans.req_bank_cnt = rq->wIndex.word;
usb_trans.req_addr_end = (uint32_t) usb_trans.req_bank_size * usb_trans.req_bank_cnt;
usb_trans.req_addr_end =
(uint32_t) usb_trans.req_bank_size * usb_trans.req_bank_cnt;
usb_trans.req_percent = 0;
usb_trans.req_percent_last = 0;
usb_trans.sync_errors = 0;
debug_P(DEBUG_USB,
PSTR("USB_BULK_UPLOAD_INIT: bank_size=0x%08lx bank_cnt=0x%x end_addr=0x%08lx\n"),
usb_trans.req_bank_size, usb_trans.req_bank_cnt, usb_trans.req_addr_end);
PSTR
("USB_BULK_UPLOAD_INIT: bank_size=0x%08lx bank_cnt=0x%x end_addr=0x%08lx\n"),
usb_trans.req_bank_size, usb_trans.req_bank_cnt,
usb_trans.req_addr_end);
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_START, 0);
shared_memory_write(SHARED_MEM_TX_CMD_BANK_COUNT, usb_trans.req_bank_cnt);
shared_memory_write(SHARED_MEM_TX_CMD_BANK_COUNT,
usb_trans.req_bank_cnt);
#if DO_TIMER
if (usb_trans.req_addr == 0x000000) {
#ifndef NO_DEBUG
@ -104,16 +108,19 @@ 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
#ifndef NO_DEBUG
#ifdef FLT_DEBUG
debug_P(DEBUG_USB,
PSTR("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
PSTR
("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
usb_trans.req_bank, usb_trans.req_addr, timer_stop());
#else
debug_P(DEBUG_USB,
PSTR("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%i\n"),
PSTR
("USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%i\n"),
usb_trans.req_bank, usb_trans.req_addr, timer_stop_int());
#endif
timer_start();
@ -137,23 +144,28 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
usb_trans.rx_remaining = rq->wLength.word;
#if DO_SHM
usb_trans.req_percent = (uint32_t)( 100 * usb_trans.req_addr ) / usb_trans.req_addr_end;
if (usb_trans.req_percent!=usb_trans.req_percent_last){
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_PROGESS, usb_trans.req_percent);
usb_trans.req_percent =
(uint32_t) (100 * usb_trans.req_addr) / usb_trans.req_addr_end;
if (usb_trans.req_percent != usb_trans.req_percent_last) {
shared_memory_write(SHARED_MEM_TX_CMD_UPLOAD_PROGESS,
usb_trans.req_percent);
}
usb_trans.req_percent_last = usb_trans.req_percent;
shared_memory_scratchpad_region_save_helper(usb_trans.req_addr);
#endif
if (usb_trans.req_addr && (usb_trans.req_addr % usb_trans.req_bank_size) == 0) {
if (usb_trans.req_addr
&& (usb_trans.req_addr % usb_trans.req_bank_size) == 0) {
#if DO_TIMER
#ifndef NO_DEBUG
#ifdef FLT_DEBUG
debug_P(DEBUG_USB,
PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
PSTR
("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%.4f\n"),
usb_trans.req_bank, usb_trans.req_addr, timer_stop());
#else
debug_P(DEBUG_USB,
PSTR("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%i\n"),
PSTR
("USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%i\n"),
usb_trans.req_bank, usb_trans.req_addr, timer_stop_int());
#endif
timer_start();
@ -161,7 +173,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
#endif
usb_trans.req_bank++;
#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
}
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 = usb_trans.req_addr << 16;
usb_trans.req_addr = usb_trans.req_addr | rq->wIndex.word;
debug_P(DEBUG_USB, PSTR("USB_CRC: addr=0x%08lx \n"), usb_trans.req_addr);
crc_check_bulk_memory(0x000000, usb_trans.req_addr, usb_trans.req_bank_size);
debug_P(DEBUG_USB, PSTR("USB_CRC: addr=0x%08lx \n"),
usb_trans.req_addr);
crc_check_bulk_memory(0x000000, usb_trans.req_addr,
usb_trans.req_bank_size);
ret_len = 0;
/*
* -------------------------------------------------------------------------
@ -226,8 +241,9 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
*/
void globals_init(){
memset(&usb_trans,0,sizeof(usb_transaction_t));
void globals_init()
{
memset(&usb_trans, 0, sizeof(usb_transaction_t));
usb_trans.req_addr = 0;
usb_trans.req_addr_end = 0;
@ -280,7 +296,9 @@ int main(void)
#if DO_CRC_CHECK
info_P(PSTR("-->CRC Check\n"));
crc_check_bulk_memory(0x000000, usb_trans.req_bank_size * usb_trans.req_bank_cnt, usb_trans.req_bank_size);
crc_check_bulk_memory(0x000000,
usb_trans.req_bank_size * usb_trans.req_bank_cnt,
usb_trans.req_bank_size);
#endif
system_set_rom_mode(&usb_trans);
@ -299,7 +317,7 @@ int main(void)
info_P(PSTR("-->Switch TO AVR\n"));
shared_memory_init();
irq_init();
if(usb_trans.loader_enabled) {
if (usb_trans.loader_enabled) {
boot_startup_rom(50);
} else {
system_set_bus_avr();

View File

@ -32,10 +32,14 @@
#define PWM_OVERFLOW_MAX 1024
uint8_t pwm_sine_table[] = {
0x7f,0x8b,0x97,0xa4,0xaf,0xbb,0xc5,0xcf,0xd9,0xe1,0xe8,0xef,0xf4,0xf8,0xfb,0xfd,
0xfd,0xfd,0xfb,0xf8,0xf3,0xee,0xe7,0xe0,0xd7,0xce,0xc4,0xb9,0xae,0xa2,0x96,0x89,
0x7e,0x71,0x65,0x59,0x4d,0x42,0x37,0x2d,0x24,0x1c,0x15,0x0f,0x09,0x05,0x03,0x01,
0x01,0x01,0x03,0x07,0x0b,0x11,0x17,0x1f,0x28,0x31,0x3b,0x46,0x52,0x5e,0x6a,0x76
0x7f, 0x8b, 0x97, 0xa4, 0xaf, 0xbb, 0xc5, 0xcf, 0xd9, 0xe1, 0xe8, 0xef,
0xf4, 0xf8, 0xfb, 0xfd,
0xfd, 0xfd, 0xfb, 0xf8, 0xf3, 0xee, 0xe7, 0xe0, 0xd7, 0xce, 0xc4, 0xb9,
0xae, 0xa2, 0x96, 0x89,
0x7e, 0x71, 0x65, 0x59, 0x4d, 0x42, 0x37, 0x2d, 0x24, 0x1c, 0x15, 0x0f,
0x09, 0x05, 0x03, 0x01,
0x01, 0x01, 0x03, 0x07, 0x0b, 0x11, 0x17, 0x1f, 0x28, 0x31, 0x3b, 0x46,
0x52, 0x5e, 0x6a, 0x76
};
volatile uint8_t pwm_setting;
@ -43,20 +47,21 @@ volatile uint16_t pwm_overflow;
volatile uint8_t pwm_idx;
volatile uint16_t pwm_overflow_max;
ISR(TIMER2_COMPA_vect) {
static uint8_t pwm_cnt=0;
OCR2A += (uint16_t)T_PWM;
ISR(TIMER2_COMPA_vect)
{
static uint8_t pwm_cnt = 0;
OCR2A += (uint16_t) T_PWM;
if (pwm_setting> pwm_cnt)
if (pwm_setting > pwm_cnt)
led_pwm_on();
else
led_pwm_off();
if (pwm_cnt==(uint8_t)(PWM_STEPS-1))
pwm_cnt=0;
if (pwm_cnt == (uint8_t) (PWM_STEPS - 1))
pwm_cnt = 0;
else
pwm_cnt++;
if (pwm_overflow_max == pwm_overflow++ ){
if (pwm_overflow_max == pwm_overflow++) {
pwm_setting = pwm_sine_table[pwm_idx++];
pwm_overflow = 0;
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;
}
void pwm_speed_slow(uint16_t val) {
pwm_overflow_max = PWM_OVERFLOW_MAX * 2 ;
void pwm_speed_slow(uint16_t val)
{
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;
}
void pwm_speed_normal(uint16_t val) {
void pwm_speed_normal(uint16_t val)
{
pwm_overflow_max = PWM_OVERFLOW_MAX;
}
void pwm_set(uint8_t val) {
void pwm_set(uint8_t val)
{
pwm_setting = val;
}
void pwm_stop(void) {
while(pwm_setting!=0xfd);
void pwm_stop(void)
{
while (pwm_setting != 0xfd);
TIMSK2 = 0;
}
void pwm_init(void) {
void pwm_init(void)
{
pwm_overflow_max = PWM_OVERFLOW_MAX;
pwm_setting = 0x7f;
pwm_overflow = 0;
//cli();
// cli();
TCCR2B = 1;
TIMSK2 |= (1<<OCIE2A);
TIMSK2 |= (1 << OCIE2A);
sei();
}

View File

@ -27,10 +27,10 @@
#define T_PWM (F_CPU/(F_PWM*PWM_STEPS)) // Systemtakte pro PWM-Takt
#if (T_PWM<(93+5))
#error T_PWM zu klein, F_CPU muss vergrösst werden oder F_PWM oder PWM_STEPS verkleinert werden
#error T_PWM zu klein, F_CPU muss vergrösst werden oder F_PWM oder PWM_STEPS verkleinert werden
#endif
void pwm_init(void);
void pwm_init(void);
void pwm_stop(void);

View File

@ -50,7 +50,7 @@ typedef struct usb_transaction_t {
uint8_t req_percent_last;
uint8_t req_state;
uint8_t rx_remaining;
uint8_t tx_remaining ;
uint8_t tx_remaining;
uint16_t sync_errors;
uint8_t tx_buffer[32];
uint8_t rx_buffer[8];

View File

@ -48,25 +48,35 @@ uint8_t scratchpad_locked_rx = 1;
uint8_t scratchpad_locked_tx = 1;
void shared_memory_init(void){
void shared_memory_init(void)
{
scratchpad_locked_rx = 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(addr > (SHARED_MEM_TX_LOC_STATE + (SHARED_MEM_TX_LOC_SIZE )) && scratchpad_locked_tx){
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_save_helper: open tx addr=0x%06lx\n"),addr);
if (addr > (SHARED_MEM_TX_LOC_STATE + (SHARED_MEM_TX_LOC_SIZE))
&& scratchpad_locked_tx) {
debug_P(DEBUG_SHM,
PSTR
("shared_memory_scratchpad_region_save_helper: open tx addr=0x%06lx\n"),
addr);
shared_memory_scratchpad_region_tx_save();
return 0;
}
if(addr > (SHARED_MEM_RX_LOC_STATE + ( SHARED_MEM_RX_LOC_SIZE )) && scratchpad_locked_rx){
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_save_helper: open rx addr=0x%06lx\n"),addr);
if (addr > (SHARED_MEM_RX_LOC_STATE + (SHARED_MEM_RX_LOC_SIZE))
&& scratchpad_locked_rx) {
debug_P(DEBUG_SHM,
PSTR
("shared_memory_scratchpad_region_save_helper: open rx addr=0x%06lx\n"),
addr);
shared_memory_scratchpad_region_rx_save();
return 0;
}
@ -81,25 +91,32 @@ void shared_memory_scratchpad_region_tx_save()
#if SHARED_SCRATCHPAD_CRC
uint16_t crc;
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_TX_LOC_STATE,
(uint32_t)(SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE), 0x8000);
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"),crc);
crc = crc_check_bulk_memory((uint32_t) SHARED_MEM_TX_LOC_STATE,
(uint32_t) (SHARED_MEM_TX_LOC_STATE +
SHARED_MEM_TX_LOC_SIZE), 0x8000);
debug_P(DEBUG_SHM,
PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"), crc);
#endif
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: unlock\n"));
sram_bulk_copy_into_buffer((uint32_t)SHARED_MEM_TX_LOC_STATE,scratchpad_region_tx,
(uint32_t)SHARED_MEM_TX_LOC_SIZE);
debug_P(DEBUG_SHM,
PSTR("shared_memory_scratchpad_region_tx_save: unlock\n"));
sram_bulk_copy_into_buffer((uint32_t) SHARED_MEM_TX_LOC_STATE,
scratchpad_region_tx,
(uint32_t) SHARED_MEM_TX_LOC_SIZE);
scratchpad_locked_tx = 0;
#if SHARED_SCRATCHPAD_CRC
do_crc_update(0, scratchpad_region_tx,SHARED_MEM_TX_LOC_SIZE);
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"),crc);
do_crc_update(0, scratchpad_region_tx, SHARED_MEM_TX_LOC_SIZE);
debug_P(DEBUG_SHM,
PSTR("shared_memory_scratchpad_region_tx_save: crc=%x\n"), crc);
#endif
#if SHARED_SCRATCHPAD_DUMP
dump_packet(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_SIZE, scratchpad_region_tx);
dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
dump_packet(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_SIZE,
scratchpad_region_tx);
dump_memory(SHARED_MEM_TX_LOC_STATE,
SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
#endif
sram_bulk_addr_restore();
@ -111,24 +128,31 @@ void shared_memory_scratchpad_region_rx_save()
sram_bulk_addr_save();
#if SHARED_SCRATCHPAD_CRC
uint16_t crc;
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_RX_LOC_STATE,
(uint32_t)(SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE), 0x8000);
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_save: crc=%x\n"),crc);
crc = crc_check_bulk_memory((uint32_t) SHARED_MEM_RX_LOC_STATE,
(uint32_t) (SHARED_MEM_RX_LOC_STATE +
SHARED_MEM_RX_LOC_SIZE), 0x8000);
debug_P(DEBUG_SHM,
PSTR("shared_memory_scratchpad_region_rx_save: crc=%x\n"), crc);
#endif
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_save: unlock\n"));
sram_bulk_copy_into_buffer((uint32_t)SHARED_MEM_RX_LOC_STATE,scratchpad_region_rx,
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
debug_P(DEBUG_SHM,
PSTR("shared_memory_scratchpad_region_rx_save: unlock\n"));
sram_bulk_copy_into_buffer((uint32_t) SHARED_MEM_RX_LOC_STATE,
scratchpad_region_rx,
(uint32_t) SHARED_MEM_RX_LOC_SIZE);
scratchpad_locked_rx = 0;
#if SHARED_SCRATCHPAD_CRC
do_crc_update(0, scratchpad_region_rx,SHARED_MEM_RX_LOC_SIZE);
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_save: crc=%x\n"),crc);
do_crc_update(0, scratchpad_region_rx, SHARED_MEM_RX_LOC_SIZE);
debug_P(DEBUG_SHM,
PSTR("shared_memory_scratchpad_region_rx_save: crc=%x\n"), crc);
#endif
#if SHARED_SCRATCHPAD_DUMP
dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_SIZE, scratchpad_region_rx);
dump_memory(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE);
dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_SIZE,
scratchpad_region_rx);
dump_memory(SHARED_MEM_RX_LOC_STATE,
SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE);
#endif
sram_bulk_addr_restore();
@ -138,29 +162,39 @@ void shared_memory_scratchpad_region_tx_restore()
{
if (scratchpad_locked_tx)
return;
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: lock\n"));
debug_P(DEBUG_SHM,
PSTR("shared_memory_scratchpad_region_tx_restore: lock\n"));
#if SHARED_SCRATCHPAD_DUMP
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: memory\n"));
dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
debug_P(DEBUG_SHM,
PSTR("shared_memory_scratchpad_region_tx_restore: memory\n"));
dump_memory(SHARED_MEM_TX_LOC_STATE,
SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
#endif
sram_bulk_copy_from_buffer((uint32_t)SHARED_MEM_TX_LOC_STATE,scratchpad_region_tx,
(uint32_t)SHARED_MEM_TX_LOC_SIZE);
sram_bulk_copy_from_buffer((uint32_t) SHARED_MEM_TX_LOC_STATE,
scratchpad_region_tx,
(uint32_t) SHARED_MEM_TX_LOC_SIZE);
scratchpad_locked_tx = 1;
#if SHARED_SCRATCHPAD_DUMP
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: buffer\n"));
dump_packet(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_SIZE, scratchpad_region_tx);
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: memory\n"));
dump_memory(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
debug_P(DEBUG_SHM,
PSTR("shared_memory_scratchpad_region_tx_restore: buffer\n"));
dump_packet(SHARED_MEM_TX_LOC_STATE, SHARED_MEM_TX_LOC_SIZE,
scratchpad_region_tx);
debug_P(DEBUG_SHM,
PSTR("shared_memory_scratchpad_region_tx_restore: memory\n"));
dump_memory(SHARED_MEM_TX_LOC_STATE,
SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE);
#endif
#if SHARED_SCRATCHPAD_CRC
uint16_t crc;
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_TX_LOC_STATE,
(uint32_t)(SHARED_MEM_TX_LOC_STATE + SHARED_MEM_TX_LOC_SIZE), 0x8000);
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_tx_restore: crc=%x\n"),crc);
crc = crc_check_bulk_memory((uint32_t) SHARED_MEM_TX_LOC_STATE,
(uint32_t) (SHARED_MEM_TX_LOC_STATE +
SHARED_MEM_TX_LOC_SIZE), 0x8000);
debug_P(DEBUG_SHM,
PSTR("shared_memory_scratchpad_region_tx_restore: crc=%x\n"), crc);
#endif
}
@ -171,29 +205,39 @@ void shared_memory_scratchpad_region_rx_restore()
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
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);
debug_P(DEBUG_SHM,
PSTR("shared_memory_scratchpad_region_rx_restore: memory\n"));
dump_memory(SHARED_MEM_RX_LOC_STATE - 0x10,
SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE);
#endif
sram_bulk_copy_from_buffer((uint32_t)SHARED_MEM_RX_LOC_STATE,scratchpad_region_rx,
(uint32_t)SHARED_MEM_RX_LOC_SIZE);
sram_bulk_copy_from_buffer((uint32_t) SHARED_MEM_RX_LOC_STATE,
scratchpad_region_rx,
(uint32_t) SHARED_MEM_RX_LOC_SIZE);
scratchpad_locked_rx = 1;
#if SHARED_SCRATCHPAD_DUMP
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: buffer\n"));
dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_SIZE, scratchpad_region_rx);
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: memory\n"));
dump_memory(SHARED_MEM_RX_LOC_STATE - 0x10, SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE);
debug_P(DEBUG_SHM,
PSTR("shared_memory_scratchpad_region_rx_restore: buffer\n"));
dump_packet(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_LOC_SIZE,
scratchpad_region_rx);
debug_P(DEBUG_SHM,
PSTR("shared_memory_scratchpad_region_rx_restore: memory\n"));
dump_memory(SHARED_MEM_RX_LOC_STATE - 0x10,
SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE);
#endif
#if SHARED_SCRATCHPAD_CRC
uint16_t crc;
crc = crc_check_bulk_memory((uint32_t)SHARED_MEM_RX_LOC_STATE,
(uint32_t)(SHARED_MEM_RX_LOC_STATE + SHARED_MEM_RX_LOC_SIZE), 0x8000);
debug_P(DEBUG_SHM, PSTR("shared_memory_scratchpad_region_rx_restore: crc=%x\n"),crc);
crc = crc_check_bulk_memory((uint32_t) SHARED_MEM_RX_LOC_STATE,
(uint32_t) (SHARED_MEM_RX_LOC_STATE +
SHARED_MEM_RX_LOC_SIZE), 0x8000);
debug_P(DEBUG_SHM,
PSTR("shared_memory_scratchpad_region_rx_restore: crc=%x\n"), crc);
#endif
}
@ -231,12 +275,13 @@ void shared_memory_write(uint8_t cmd, uint8_t value)
{
#if DO_SHM
#if DO_SHM_SCRATCHPAD
if (scratchpad_locked_tx){
if (scratchpad_locked_tx) {
debug_P(DEBUG_SHM, PSTR("shared_memory_write: locked_tx\n"));
return;
}
#endif
debug_P(DEBUG_SHM, PSTR("shared_memory_write: 0x%04x=0x%02x 0x%04x=0x%02x \n"),
debug_P(DEBUG_SHM,
PSTR("shared_memory_write: 0x%04x=0x%02x 0x%04x=0x%02x \n"),
SHARED_MEM_TX_LOC_CMD, cmd, SHARED_MEM_TX_LOC_PAYLOAD, value);
sram_bulk_addr_save();
@ -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_SCRATCHPAD
if (scratchpad_locked_rx){
if (scratchpad_locked_rx) {
debug_P(DEBUG_SHM, PSTR("shared_memory_write: locked_tx\n"));
return 1;
}
@ -309,17 +354,18 @@ int shared_memory_read(uint8_t *cmd, uint8_t *len,uint8_t *buffer)
sram_bulk_addr_save();
state = sram_read(SHARED_MEM_RX_LOC_STATE);
if (state != SHARED_MEM_RX_AVR_ACK){
if (state != SHARED_MEM_RX_AVR_ACK) {
sram_bulk_addr_restore();
return 1;
}
*cmd = sram_read(SHARED_MEM_RX_LOC_CMD);
*len = sram_read(SHARED_MEM_RX_LOC_LEN);
debug_P(DEBUG_SHM, PSTR("shared_memory_read: 0x%04x=0x%02x 0x%04x=0x%02x \n"),
debug_P(DEBUG_SHM,
PSTR("shared_memory_read: 0x%04x=0x%02x 0x%04x=0x%02x \n"),
SHARED_MEM_RX_LOC_CMD, *cmd, SHARED_MEM_RX_LOC_LEN, *len);
sram_bulk_copy_into_buffer(SHARED_MEM_RX_LOC_PAYLOAD,buffer, *len);
sram_bulk_copy_into_buffer(SHARED_MEM_RX_LOC_PAYLOAD, buffer, *len);
sram_write(SHARED_MEM_RX_LOC_STATE, SHARED_MEM_RX_AVR_RTS);
snes_hirom();

View File

@ -56,7 +56,9 @@
#define SHARED_IRQ_LOC_LO 0x00fffe
#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_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_restore();
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

View File

@ -79,7 +79,7 @@ uint8_t *get_token(void)
return p;
}
uint8_t get_dec(uint32_t *decval)
uint8_t get_dec(uint32_t * decval)
{
const uint8_t *t;
t = get_token();
@ -91,59 +91,59 @@ uint8_t get_dec(uint32_t *decval)
return 1;
}
return 0;
}
}
uint8_t parse_hex(const uint8_t *s, uint32_t *hexval)
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)
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)
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 get_hex_arg3(uint32_t * hexval1, uint32_t * hexval2, uint32_t * hexval3)
{
return get_hex(hexval1) && get_hex(hexval2) && get_hex(hexval3);
}
#if 0
static uint8_t get_int32(uint32_t *val)
{
if (!get_hex(val)){
static uint8_t get_int32(uint32_t * val)
{
if (!get_hex(val)) {
info_P(PSTR("Invalid argument!\n"));
return 0;
} else {
return 1;
}
}
}
static uint8_t get_int8(uint8_t *val)
{
static uint8_t get_int8(uint8_t * val)
{
uint32_t ret;
if (!get_hex(&ret) ||ret > 0xff){
if (!get_hex(&ret) || ret > 0xff) {
info_P(PSTR("Invalid argument!\n"));
return 0;
}else{
*val = (uint8_t)ret;
} else {
*val = (uint8_t) ret;
return 1;
}
}
}
#endif
static int get_bool(void)
{
static int get_bool(void)
{
const uint8_t *t;
t = get_token();
if (t != NULL) {
@ -153,42 +153,46 @@ static uint8_t get_int32(uint32_t *val)
}
info_P(PSTR("Invalid argument (should be 0 or 1)!\n"));
return -1;
}
void prompt(void){
}
void prompt(void)
{
uart_putc('\r');
uart_putc('\n');
uart_putc('>');
}
}
ISR(USART0_RX_vect)
{
UCSR0B &= (255 - (1<<RXCIE0));// Interrupts disable for RxD
UCSR0B &= (255 - (1 << RXCIE0)); // Interrupts disable for RxD
sei();
if(recv_counter == (sizeof(recv_buf)-1)) {
cr=1;
recv_buf[recv_counter]='\0';
recv_counter=0;
if (recv_counter == (sizeof(recv_buf) - 1)) {
cr = 1;
recv_buf[recv_counter] = '\0';
recv_counter = 0;
prompt();
}
recv_buf[recv_counter] = UDR0;
uart_putc(recv_buf[recv_counter]);
if (recv_buf[recv_counter] == 0x0d) {
/* recv_buf[recv_counter] = 0; */
/*
* recv_buf[recv_counter] = 0;
*/
cr = 1;
recv_buf[++recv_counter]='\0';
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) {
if ((recv_buf[recv_counter] == 0x08 || recv_buf[recv_counter] == 0x7f)
&& recv_counter > 0) {
recv_counter--;
} else {
recv_counter++;
}
}
UCSR0B |= (1<<RXCIE0);
UCSR0B |= (1 << RXCIE0);
}
enum cmds {
@ -237,14 +241,15 @@ uint8_t cmdlist[][CMD_HELP] PROGMEM = {
{"STATUS"},
{"SYS"},
{"HELP"},
};
};
void shell_help(void){
void shell_help(void)
{
uint8_t i;
info_P(PSTR("\n"));
for (i=CMD_DUMP; i<CMD_HELP; i++){
info_P((PGM_P)cmdlist[i]);
for (i = CMD_DUMP; i < CMD_HELP; i++) {
info_P((PGM_P) cmdlist[i]);
info_P(PSTR("\n"));
}
@ -262,8 +267,8 @@ void shell_run(void)
if (!cr)
return;
cr=0;
strcpy((char*)command_buf, (char*)recv_buf);
cr = 0;
strcpy((char *) command_buf, (char *) recv_buf);
token_ptr = command_buf;
t = get_token();
@ -273,109 +278,111 @@ void shell_run(void)
util_strupper(t);
if (strcmp_P((const char*)t,(PGM_P)cmdlist[CMD_DUMP]) == 0) {
if (get_hex_arg2(&arg1,&arg2))
dump_memory(arg1,arg2);
if (strcmp_P((const char *) t, (PGM_P) cmdlist[CMD_DUMP]) == 0) {
if (get_hex_arg2(&arg1, &arg2))
dump_memory(arg1, arg2);
else
info_P(PSTR("DUMP <start addr> <end addr>\n"));
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_CRC]) == 0) {
if (get_hex_arg2(&arg1,&arg2)){
crc = crc_check_bulk_memory(arg1,arg2,0x8000);
info_P(PSTR("0x%06lx - 0x%06lx crc=0x%04x\n"),arg1,arg2,crc);
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_CRC]) == 0) {
if (get_hex_arg2(&arg1, &arg2)) {
crc = crc_check_bulk_memory(arg1, arg2, 0x8000);
info_P(PSTR("0x%06lx - 0x%06lx crc=0x%04x\n"), arg1, arg2, crc);
} else
info_P(PSTR("CRC <start addr> <end addr>\n"));
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_EXIT]) == 0) {
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_EXIT]) == 0) {
leave_application();
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_RESET]) == 0) {
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_RESET]) == 0) {
system_send_snes_reset();
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_IRQ]) == 0) {
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_IRQ]) == 0) {
info_P(PSTR("Send IRQ\n"));
snes_irq_on();
snes_irq_lo();
_delay_us(20);
snes_irq_hi();
snes_irq_off();
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_AVR]) == 0) {
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_AVR]) == 0) {
system_set_bus_avr();
snes_irq_lo();
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();
system_snes_irq_off();
system_set_wr_disable();
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_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_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();
if(arg1==1){
if (arg1 == 1) {
info_P(PSTR("Set WR enable"));
snes_wr_enable();
}else if (arg1==0){
} else if (arg1 == 0) {
info_P(PSTR("Set WR disable"));
snes_wr_disable();
}
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_RESETSNIFF]) == 0) {
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_RESETSNIFF]) == 0) {
arg1 = get_bool();
if(arg1==1){
if (arg1 == 1) {
info_P(PSTR("Start Reset sniffer"));
irq_init();
}else if (arg1==0){
} else if (arg1 == 0) {
info_P(PSTR("Stop Reset sniffer"));
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;
if (system.rom_mode==LOROM)
if (system.rom_mode == LOROM)
offset = 0x8000;
else
offset = 0x0000;
info_P(PSTR("ABORT 0x%04x 0x%04x\n"), (0xFFE8 - offset),sram_read16_be(0xFFE8 - offset));
info_P(PSTR("BRK 0x%04x 0x%04x\n"), (0xFFE6 - offset),sram_read16_be(0xFFE6 - offset));
info_P(PSTR("COP 0x%04x 0x%04x\n"), (0xFFE4 - offset),sram_read16_be(0xFFE4 - offset));
info_P(PSTR("IRQ 0x%04x 0x%04x\n"), (0xFFEE - offset),sram_read16_be(0xFFEE - offset));
info_P(PSTR("NMI 0x%04x 0x%04x\n"), (0xFFEA - offset),sram_read16_be(0xFFEA - offset));
info_P(PSTR("RES 0x%04x 0x%04x\n"), (0xFFFC - offset),sram_read16_be(0xFFFC - offset));
info_P(PSTR("ABORT 0x%04x 0x%04x\n"), (0xFFE8 - offset),
sram_read16_be(0xFFE8 - offset));
info_P(PSTR("BRK 0x%04x 0x%04x\n"), (0xFFE6 - offset),
sram_read16_be(0xFFE6 - offset));
info_P(PSTR("COP 0x%04x 0x%04x\n"), (0xFFE4 - offset),
sram_read16_be(0xFFE4 - offset));
info_P(PSTR("IRQ 0x%04x 0x%04x\n"), (0xFFEE - offset),
sram_read16_be(0xFFEE - offset));
info_P(PSTR("NMI 0x%04x 0x%04x\n"), (0xFFEA - offset),
sram_read16_be(0xFFEA - offset));
info_P(PSTR("RES 0x%04x 0x%04x\n"), (0xFFFC - offset),
sram_read16_be(0xFFFC - offset));
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_DUMPHEADER]) == 0) {
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_DUMPHEADER]) == 0) {
if (system.rom_mode==LOROM)
if (system.rom_mode == LOROM)
offset = 0x8000;
else
offset = 0x0000;
/*
# $ffc0..$ffd4 => Name of the ROM, typically in ASCII, using spaces to pad the name to 21 bytes.
# $ffd5 => ROM layout, typically $20 for LoROM, or $21 for HiROM. Add $10 for FastROM.
# $ffd6 => Cartridge type, typically $00 for ROM only, or $02 for ROM with save-RAM.
# $ffd7 => ROM size byte.
# $ffd8 => RAM size byte.
# $ffd9 => Country code, which selects the video in the emulator. Values $00, $01, $0d use NTSC. Values in range $02..$0c use PAL. Other values are invalid.
# $ffda => Licensee code. If this value is $33, then the ROM has an extended header with ID at $ffb2..$ffb5.
# $ffdb => Version number, typically $00.
# $ffdc..$ffdd => Checksum complement, which is the bitwise-xor of the checksum and $ffff.
# $ffde..$ffdf => SNES checksum, an unsigned 16-bit checksum of bytes.
# $ffe0..$ffe3 => Unknown.
* # $ffc0..$ffd4 => Name of the ROM, typically in ASCII, using spaces to pad the name to 21 bytes. # $ffd5 => ROM layout,
* typically $20 for LoROM, or $21 for HiROM. Add $10 for FastROM. # $ffd6 => Cartridge type, typically $00 for ROM only, or $02
* for ROM with save-RAM. # $ffd7 => ROM size byte. # $ffd8 => RAM size byte. # $ffd9 => Country code, which selects the video in
* the emulator. Values $00, $01, $0d use NTSC. Values in range $02..$0c use PAL. Other values are invalid. # $ffda => Licensee
* code. If this value is $33, then the ROM has an extended header with ID at $ffb2..$ffb5. # $ffdb => Version number, typically
* $00. # $ffdc..$ffdd => Checksum complement, which is the bitwise-xor of the checksum and $ffff. # $ffde..$ffdf => SNES checksum,
* an unsigned 16-bit checksum of bytes. # $ffe0..$ffe3 => Unknown.
*/
info_P(PSTR("NAME 0x%04x "), (0xffc0 - offset));
for(arg1=(0xffc0 - offset); arg1<(0xffc0 - offset + 21);arg1++){
for (arg1 = (0xffc0 - offset); arg1 < (0xffc0 - offset + 21); arg1++) {
c = sram_read(arg1);
if (c>0x1f && c<0x7f)
printf("%c",c);
if (c > 0x1f && c < 0x7f)
printf("%c", c);
}
printf("\n");
c = sram_read(0xffd5 - offset);
info_P(PSTR("LAYOUT 0x%04x "), (0xffd5 - offset));
switch(c){
switch (c) {
case 0x20:
info_P(PSTR("LoROM, not fast\n"));
break;
@ -389,13 +396,13 @@ void shell_run(void)
info_P(PSTR("HiRom, fast\n"));
break;
default:
info_P(PSTR("Unkown 0x%02x\n"),c);
info_P(PSTR("Unkown 0x%02x\n"), c);
break;
}
c = sram_read(0xffd6 - offset);
info_P(PSTR("TYPE 0x%04xc"), (0xffd6 - offset),c);
switch(c){
info_P(PSTR("TYPE 0x%04xc"), (0xffd6 - offset), c);
switch (c) {
case 0x00:
info_P(PSTR("Rom\n"));
break;
@ -424,51 +431,56 @@ void shell_run(void)
info_P(PSTR("SA-1"));
break;
default:
info_P(PSTR("Unkown 0x%02x\n"),c);
info_P(PSTR("Unkown 0x%02x\n"), c);
break;
}
arg1 = ( 2 << ( sram_read(0xffd7 - offset) - 1 ));
info_P(PSTR("ROM 0x%04x %li MBit ( %li KiB)\n"), (0xffd7 - offset), (arg1 / 128), arg1);
arg1 = ( 2 << ( sram_read(0xffd8 - offset) - 1 ));
arg1 = (2 << (sram_read(0xffd7 - offset) - 1));
info_P(PSTR("ROM 0x%04x %li MBit ( %li KiB)\n"),
(0xffd7 - offset), (arg1 / 128), arg1);
arg1 = (2 << (sram_read(0xffd8 - offset) - 1));
info_P(PSTR("RAM 0x%04x %li KiB\n"), (0xffd8 - offset), arg1);
info_P(PSTR("CCODE 0x%04x "), (0xffd9 - offset));
c = sram_read(0xffd9 - offset);
if (c==0x00 || c==0x01 || 0x0d )
if (c == 0x00 || c == 0x01 || 0x0d)
info_P(PSTR("NTSC\n"));
else if (c>=0x02 || c<=0x0c )
else if (c >= 0x02 || c <= 0x0c)
info_P(PSTR("PAL\n"));
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("VER 0x%04x 0x%02x\n"), (0xffdb - offset),sram_read(0xffdb - offset));
info_P(PSTR("SUM1 0x%04x 0x%04x\n"), (0xffdc - offset),sram_read16_be(0xffdc - offset));
info_P(PSTR("SUM2 0x%04x 0x%04x\n"), (0xffde - offset),sram_read16_be(0xffde - offset));
info_P(PSTR("LIC 0x%04x 0x%02x\n"), (0xffda - offset),
sram_read(0xffda - offset));
info_P(PSTR("VER 0x%04x 0x%02x\n"), (0xffdb - offset),
sram_read(0xffdb - offset));
info_P(PSTR("SUM1 0x%04x 0x%04x\n"), (0xffdc - offset),
sram_read16_be(0xffdc - offset));
info_P(PSTR("SUM2 0x%04x 0x%04x\n"), (0xffde - offset),
sram_read16_be(0xffde - offset));
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SHMWR]) == 0) {
if (get_hex_arg2(&arg1,&arg2))
shared_memory_write((uint8_t)arg1, (uint8_t)arg1);
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_SHMWR]) == 0) {
if (get_hex_arg2(&arg1, &arg2))
shared_memory_write((uint8_t) arg1, (uint8_t) arg1);
else
info_P(PSTR("SHMWR <command> <value>\n"));
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SHMSAVE]) == 0) {
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_SHMSAVE]) == 0) {
shared_memory_scratchpad_region_tx_save();
shared_memory_scratchpad_region_rx_save();
info_P(PSTR("Save scratchpad\n"));
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SHMRESTORE]) == 0) {
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_SHMRESTORE]) == 0) {
shared_memory_scratchpad_region_tx_restore();
shared_memory_scratchpad_region_rx_restore();
info_P(PSTR("Restore scratchpad\n"));
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_LOADER]) == 0) {
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_LOADER]) == 0) {
boot_startup_rom(500);
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_RECONNECT]) == 0) {
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_RECONNECT]) == 0) {
usb_connect();
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_STATUS]) == 0) {
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_STATUS]) == 0) {
transaction_status();
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_SYS]) == 0) {
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_SYS]) == 0) {
system_status();
}else if (strcmp_P((char*)t, (PGM_P)cmdlist[CMD_HELP]) == 0) {
} else if (strcmp_P((char *) t, (PGM_P) cmdlist[CMD_HELP]) == 0) {
shell_help();
}
prompt();

View File

@ -21,6 +21,6 @@
#ifndef __SHELL_H__
#define __SHELL_H__
void shell_run(void);
void shell_run(void);
#endif

View File

@ -43,13 +43,13 @@ void sram_init(void)
/*-------------------------------------------------*/
DDRC |= ( (1 << AVR_ADDR_LATCH_PIN)
DDRC |= ((1 << AVR_ADDR_LATCH_PIN)
| (1 << AVR_ADDR_SCK_PIN)
| (1 << AVR_ADDR_SER_PIN)
| (1 << AVR_ADDR_LOAD_PIN)
| (1 << AVR_ADDR_UP_PIN));
DDRC &= ~ ((1 << SNES_WR_PIN)
DDRC &= ~((1 << SNES_WR_PIN)
| (1 << AVR_BTLDR_EN_PIN));
PORTC &= ~((1 << AVR_ADDR_LATCH_PIN)
@ -57,19 +57,19 @@ void sram_init(void)
| (1 << SNES_WR_PIN));
PORTC |= ( (1 << AVR_ADDR_UP_PIN)
PORTC |= ((1 << AVR_ADDR_UP_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_CS_PIN)
| (1 << SNES_IRQ_PIN));
PORTB |= ( (1 << AVR_RD_PIN)
PORTB |= ((1 << AVR_RD_PIN)
| (1 << AVR_WR_PIN)
| (1 << AVR_CS_PIN)
| (1 << SNES_IRQ_PIN));
@ -77,7 +77,7 @@ void sram_init(void)
/*-------------------------------------------------*/
DDRD |= ( (1 << AVR_SNES_SW_PIN)
DDRD |= ((1 << AVR_SNES_SW_PIN)
| (1 << HI_LOROM_SW_PIN)
| (1 << SNES_WR_EN_PIN));
@ -94,13 +94,13 @@ void sram_init(void)
void sreg_set(uint32_t addr)
{
uint8_t i = 24;
debug_P(DEBUG_SREG, PSTR("sreg_set: addr=0x%08lx"),addr);
while(i--) {
if ((addr & ( 1L << i))){
debug_P(DEBUG_SREG, PSTR("sreg_set: addr=0x%08lx"), addr);
while (i--) {
if ((addr & (1L << i))) {
debug_P(DEBUG_SREG, PSTR("1"));
AVR_ADDR_SER_PORT |= ( 1 << AVR_ADDR_SER_PIN);
AVR_ADDR_SER_PORT |= (1 << AVR_ADDR_SER_PIN);
} 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"));
}
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;
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()
{
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);
}
@ -149,7 +151,7 @@ void sram_bulk_read_start(uint32_t addr)
asm volatile ("nop");
asm volatile ("nop");
}
}
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 lo = sram_read(addr+1);
return (hi << 8 | lo );
uint8_t lo = sram_read(addr + 1);
return (hi << 8 | lo);
}
void sram_bulk_write_start(uint32_t addr)
@ -242,7 +245,7 @@ inline void sram_bulk_write_next(void)
counter_up();
}
inline void sram_bulk_write( uint8_t data)
inline void sram_bulk_write(uint8_t data)
{
AVR_WR_PORT &= ~(1 << AVR_WR_PIN);
AVR_DATA_PORT = data;
@ -260,7 +263,8 @@ void sram_bulk_write_end(void)
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();
@ -294,13 +298,15 @@ void sram_bulk_copy_from_buffer(uint32_t addr, uint8_t * src, uint32_t len)
uint32_t i;
uint8_t *ptr = src;
debug_P(DEBUG_SRAM, PSTR("sram_bulk_copy_from_buffer: addr=0x%08lx src=0x%p len=%li\n\r"),
debug_P(DEBUG_SRAM,
PSTR
("sram_bulk_copy_from_buffer: addr=0x%08lx src=0x%p len=%li\n\r"),
addr, src, len);
sram_bulk_write_start(addr);
for (i = addr; i < (addr + len); i++){
for (i = addr; i < (addr + len); i++) {
sram_bulk_write(*ptr);
//hack
if ((i+1) < (addr + len))
// hack
if ((i + 1) < (addr + len))
sram_bulk_write_next();
ptr++;
}
@ -311,8 +317,10 @@ void sram_bulk_copy_into_buffer(uint32_t addr, uint8_t * dst, uint32_t len)
{
uint32_t i;
//uint8_t *ptr = dst;
debug_P(DEBUG_SRAM, PSTR("sram_bulk_copy_into_buffer: addr=0x%08lx dst=0x%p len=%li\n\r"),
// uint8_t *ptr = dst;
debug_P(DEBUG_SRAM,
PSTR
("sram_bulk_copy_into_buffer: addr=0x%08lx dst=0x%p len=%li\n\r"),
addr, dst, len);
sram_bulk_read_start(addr);
for (i = addr; i < (addr + len); i++) {
@ -322,9 +330,11 @@ void sram_bulk_copy_into_buffer(uint32_t addr, uint8_t * dst, uint32_t len)
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;
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);
for (i = addr; i < (addr + len); i++) {
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();
}

View File

@ -29,7 +29,9 @@
/* ---------------------------- PORT A ---------------------------- */
/*
* ---------------------------- PORT A ----------------------------
*/
#define AVR_DATA_PORT PORTA
#define AVR_DATA_DIR DDRA
@ -41,7 +43,9 @@
#define avr_data_out() (AVR_DATA_DIR = 0xff)
/* ---------------------------- PORT B ---------------------------- */
/*
* ---------------------------- PORT B ----------------------------
*/
#define AVR_PORT PORTB
#define AVR_DIR DDRB
@ -78,7 +82,9 @@
#define snes_irq_lo() (SNES_IRQ_PORT &= ~(1 << SNES_IRQ_PIN))
/* ---------------------------- PORT C ---------------------------- */
/*
* ---------------------------- PORT C ----------------------------
*/
#define AVR_ADDR_PORT PORTC
#define AVR_ADDR_DIR DDRC
@ -140,7 +146,9 @@
#define led_pwm_on() (LED_DIR &=~ (1 << LED_PIN))
#define led_pwm_off() (LED_DIR |= (1 << LED_PIN))
/* ---------------------------- PORT D ---------------------------- */
/*
* ---------------------------- PORT D ----------------------------
*/
#define AVR_SNES_PORT PORTD
#define AVR_SNES_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_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_restore();

View File

@ -106,13 +106,15 @@ void system_set_bus_avr()
system.bus_mode = MODE_AVR;
}
void system_set_wr_disable(){
void system_set_wr_disable()
{
snes_wr_disable();
system.wr_line = WR_DISABLE;
info_P(PSTR("Disable SNES WR\n"));
}
void system_set_wr_enable(){
void system_set_wr_enable()
{
snes_wr_enable();
system.wr_line = WR_ENABLE;
info_P(PSTR("Enable SNES WR\n"));
@ -125,7 +127,7 @@ void system_set_bus_snes()
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) {
snes_lorom();
@ -153,34 +155,39 @@ void system_set_rom_hirom()
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";
else
return "OFF";
}
char* system_status_bus(uint8_t val){
char *system_status_bus(uint8_t val)
{
if (val)
return "SNES";
else
return "AVR";
}
char* system_status_rom(uint8_t val){
char *system_status_rom(uint8_t val)
{
if (val)
return "HIROM";
else
return "LOROM";
}
void system_status(){
info_P(PSTR("\nBus Mode %s\n"),system_status_bus(system.bus_mode));
info_P(PSTR("Rom Mode %s\n"),system_status_rom(system.rom_mode));
info_P(PSTR("Reset Line %s\n"),system_status_helper(system.reset_line));
info_P(PSTR("IRQ Line %s\n"),system_status_helper(system.irq_line));
info_P(PSTR("WR Line %s\n"),system_status_helper(system.wr_line));
info_P(PSTR("Reset IRQ %s\n"),system_status_helper(system.reset_irq));
info_P(PSTR("SNES Reset 0x%02x\n"),system.snes_reset_count);
info_P(PSTR("AVR Reset 0x%02x\n"),system.avr_reset_count);
void system_status()
{
info_P(PSTR("\nBus Mode %s\n"), system_status_bus(system.bus_mode));
info_P(PSTR("Rom Mode %s\n"), system_status_rom(system.rom_mode));
info_P(PSTR("Reset Line %s\n"),
system_status_helper(system.reset_line));
info_P(PSTR("IRQ Line %s\n"), system_status_helper(system.irq_line));
info_P(PSTR("WR Line %s\n"), system_status_helper(system.wr_line));
info_P(PSTR("Reset IRQ %s\n"), system_status_helper(system.reset_irq));
info_P(PSTR("SNES Reset 0x%02x\n"), system.snes_reset_count);
info_P(PSTR("AVR Reset 0x%02x\n"), system.avr_reset_count);
}

View File

@ -45,7 +45,7 @@ void system_send_snes_reset(void);
void system_send_snes_irq(void);
void system_set_bus_avr(void);
void system_set_bus_snes(void);
void system_set_rom_mode(usb_transaction_t *usb_trans);
void system_set_rom_mode(usb_transaction_t * usb_trans);
void system_set_rom_hirom(void);
void system_set_rom_lorom(void);
void system_snes_irq_off(void);

View File

@ -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;
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);
for (addr = bottom_addr; addr < top_addr; addr++) {
if (addr % bank_size == 0){
if (addr % bank_size == 0) {
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_end();
for (addr = bottom_addr; addr < top_addr; addr+=bank_size) {
info_P(PSTR("test_memory_pattern: dump bottom_addr=0x%08lx top_addr=0x%08lx\n"), addr, addr + bank_size);
dump_memory(addr, addr + bank_size );
info_P(PSTR("----------------------------------------------------------------\n"));
for (addr = bottom_addr; addr < top_addr; addr += bank_size) {
info_P(PSTR
("test_memory_pattern: dump bottom_addr=0x%08lx top_addr=0x%08lx\n"),
addr, addr + bank_size);
dump_memory(addr, addr + bank_size);
info_P(PSTR
("----------------------------------------------------------------\n"));
}
crc_check_bulk_memory((uint32_t)bottom_addr,top_addr, bank_size);
crc_check_bulk_memory((uint32_t) bottom_addr, top_addr, bank_size);
}
void test_crc()
@ -128,4 +135,3 @@ void test_crc()
info_P(PSTR("test_crc: check\n"));
test_non_zero_memory(0x000000, 0x10000);
}

View File

@ -35,14 +35,14 @@
extern uint8_t snes_reset_line;
#ifndef OCR1A
#define OCR1A OCR1 // 2313 support
#define OCR1A OCR1 // 2313 support
#endif
#ifndef WGM12
#define WGM12 CTC1 // 2313 support
#define WGM12 CTC1 // 2313 support
#endif
//#define XTAL 11059201L // nominal value
// #define XTAL 11059201L // nominal value
#define XTAL 20000000UL
#define DEBOUNCE 500L // debounce clock (256Hz = 4msec)
@ -54,15 +54,15 @@ uint16_t prescaler;
uint16_t volatile second; // count seconds
ISR (SIG_OUTPUT_COMPARE1A)
ISR(SIG_OUTPUT_COMPARE1A)
{
#if XTAL % DEBOUNCE // bei rest
OCR1A = 20000000UL / DEBOUNCE - 1; // compare DEBOUNCE - 1 times
#endif
if( --prescaler == 0 ){
prescaler = (uint16_t)DEBOUNCE;
if (--prescaler == 0) {
prescaler = (uint16_t) DEBOUNCE;
second++; // exact one second over
#if XTAL % DEBOUNCE // handle remainder
OCR1A = XTAL / DEBOUNCE + XTAL % DEBOUNCE - 1; // compare once per second
@ -70,15 +70,15 @@ ISR (SIG_OUTPUT_COMPARE1A)
}
}
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
OCR1A = XTAL / DEBOUNCE - 1UL; // Output Compare Register
TCNT1 = 0; // Timmer startet mit 0
second = 0;
prescaler = (uint16_t)DEBOUNCE; //software teiler
TIMSK1 = 1<<OCIE1A; // beim Vergleichswertes Compare Match
prescaler = (uint16_t) DEBOUNCE; // software teiler
TIMSK1 = 1 << OCIE1A; // beim Vergleichswertes Compare Match
// Interrupt (SIG_OUTPUT_COMPARE1A)
sei();
@ -86,9 +86,6 @@ void timer_start( void )
uint16_t timer_stop_int(void)
{
uint16_t t = ((DEBOUNCE - prescaler) / DEBOUNCE ) + second;
uint16_t t = ((DEBOUNCE - prescaler) / DEBOUNCE) + second;
return t;
}

View File

@ -18,12 +18,12 @@
* =====================================================================================
*/
#ifndef __TIMER_H__
#define __TIMER_H__
#ifndef __TIMER_H__
#define __TIMER_H__
int16_t timer_start( void );
double timer_stop( void );
int16_t timer_stop_int( void );
int16_t timer_start(void);
double timer_stop(void);
int16_t timer_stop_int(void);
#endif

View File

@ -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);
void uart_init(void)
{
UCSR0A = _BV(U2X0); /* improves baud rate error @ F_CPU = 1 MHz */
UCSR0B = _BV(TXEN0) | _BV(RXEN0) | _BV(RXCIE0); /* tx/rx enable, rx complete
* intr */
UCSR0B = _BV(TXEN0) | _BV(RXEN0) | _BV(RXCIE0); /* tx/rx enable, rx complete * intr */
UBRR0L = (F_CPU / (8 * 115200UL)) - 1;
}
/*
ISR(USART0_RX_vect)
{
uint8_t c;
c = UDR0;
if (bit_is_clear(UCSR0A, FE0)) {
rxbuff = c;
intflags.rx_int = 1;
}
}
*/
* ISR(USART0_RX_vect) { uint8_t c; c = UDR0; if (bit_is_clear(UCSR0A, FE0)) { rxbuff = c; intflags.rx_int = 1; } }
*/
void uart_putc(uint8_t c)
{

View File

@ -34,6 +34,3 @@ void uart_puts(const char *s);
void uart_puts_P(PGM_P s);
#endif

View File

@ -27,8 +27,7 @@
#include <stdlib.h>
#include "usbdrv.h"
#include "oddebug.h" /* This is also an example for using debug
* macros */
#include "oddebug.h" /* This is also an example for using debug macros */
#include "config.h"
#include "requests.h" /* The custom request numbers we use */
#include "uart.h"
@ -48,18 +47,21 @@ uint8_t usbFunctionWrite(uint8_t * data, uint8_t len)
uint8_t i;
if (len > usb_trans.rx_remaining) {
info_P(PSTR("ERROR:usbFunctionWrite more data than expected remain: %i len: %i\n"),
info_P(PSTR
("ERROR:usbFunctionWrite more data than expected remain: %i len: %i\n"),
usb_trans.rx_remaining, len);
len = usb_trans.rx_remaining;
}
if (usb_trans.req_state == REQ_STATUS_BULK_UPLOAD) {
usb_trans.rx_remaining -= len;
debug_P(DEBUG_USB_TRANS, PSTR("usbFunctionWrite REQ_STATUS_BULK_UPLOAD addr: 0x%08lx len: %i rx_remaining=%i\n"),
debug_P(DEBUG_USB_TRANS,
PSTR
("usbFunctionWrite REQ_STATUS_BULK_UPLOAD addr: 0x%08lx len: %i rx_remaining=%i\n"),
usb_trans.req_addr, len, usb_trans.rx_remaining);
ptr = data;
i = len;
while(i--){
while (i--) {
sram_bulk_write(*ptr++);
sram_bulk_write_next();
}
@ -73,7 +75,8 @@ uint8_t usbFunctionRead(uint8_t * data, uint8_t len)
if (len > usb_trans.tx_remaining)
len = usb_trans.tx_remaining;
usb_trans.tx_remaining -= len;
debug_P(DEBUG_USB_TRANS, PSTR("usbFunctionRead len=%i tx_remaining=%i \n"), len, usb_trans.tx_remaining);
debug_P(DEBUG_USB_TRANS, PSTR("usbFunctionRead len=%i tx_remaining=%i \n"),
len, usb_trans.tx_remaining);
for (i = 0; i < len; i++) {
*data = usb_trans.tx_buffer[len];

View File

@ -20,325 +20,287 @@
/* Name: usbconfig.h
* Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
* Author: Christian Starkjohann
* Creation Date: 2005-04-01
* Tabsize: 4
* Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
* This Revision: $Id: usbconfig-prototype.h 740 2009-04-13 18:23:31Z cs $
/*
* Name: usbconfig.h Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers Author: Christian Starkjohann Creation Date:
* 2005-04-01 Tabsize: 4 Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH License: GNU GPL v2 (see License.txt), GNU GPL v3 or
* proprietary (CommercialLicense.txt) This Revision: $Id: usbconfig-prototype.h 740 2009-04-13 18:23:31Z cs $
*/
#ifndef __usbconfig_h_included__
#define __usbconfig_h_included__
/*
General Description:
This file is an example configuration (with inline documentation) for the USB
driver. It configures V-USB for USB D+ connected to Port D bit 2 (which is
also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may
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).
*/
* General Description: This file is an example configuration (with inline documentation) for the USB driver. It configures V-USB for USB
* D+ connected to Port D bit 2 (which is also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may 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
/* 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
/* 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
/* 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
* to interrupt pin INT0! [You can also use other interrupts, see section
* "Optional MCU Description" below, or you can 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 will also be triggered at Start-Of-Frame
* markers every millisecond.]
/*
* 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 to interrupt pin INT0! [You can also use other interrupts, see section "Optional MCU Description" below, or you can
* 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
* will also be triggered at Start-Of-Frame markers every millisecond.]
*/
#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
* crystal, they tolerate +/- 1% deviation from the nominal frequency. All
* other rates require a precision of 2000 ppm and thus a crystal!
* Default if not specified: 12 MHz
/*
* 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 crystal, they tolerate +/- 1% deviation from the nominal frequency. All other rates require a precision of 2000 ppm and
* thus a crystal! Default if not specified: 12 MHz
*/
#define USB_CFG_CHECK_CRC 0
/* Define this to 1 if you want that the driver checks integrity of incoming
* data packets (CRC checks). CRC checks cost quite a bit of code size and are
* currently only available for 18 MHz crystal clock. You must choose
* USB_CFG_CLOCK_KHZ = 18000 if you enable this option.
/*
* Define this to 1 if you want that the driver checks integrity of incoming data packets (CRC checks). CRC checks cost quite a bit of code
* size and are currently only available for 18 MHz crystal clock. You must choose USB_CFG_CLOCK_KHZ = 18000 if you enable this option.
*/
/* ----------------------- Optional Hardware Config ------------------------ */
//#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.
/*
* ----------------------- Optional Hardware Config ------------------------
*/
/* --------------------------- 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 this to 1 if you want to compile a version with two endpoints: The
* default control endpoint 0 and an interrupt-in endpoint (any other endpoint
* number).
/*
* Define this to 1 if you want to compile a version with two endpoints: The default control endpoint 0 and an interrupt-in endpoint (any
* other endpoint number).
*/
#define USB_CFG_HAVE_INTRIN_ENDPOINT3 0
/* Define 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
* configured below) and a catch-all default interrupt-in endpoint as above.
* You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature.
/*
* 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 configured below) and a catch-all default interrupt-in endpoint as above. You must also define USB_CFG_HAVE_INTRIN_ENDPOINT
* to 1 for this feature.
*/
#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
* 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_INITIAL_DATATOKEN USBPID_DATA1
*/
/*
* 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 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,
* it is required by the standard. We have made it a config option because it
* bloats the code considerably.
/*
* 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, it is required by the standard. We have made it a config option because it bloats the code considerably.
*/
#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
* usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if
* you need the interrupt-in endpoints in order to comply to an interface
* (e.g. HID), but never want to send any data. This option saves a couple
* of bytes in flash memory and the transmit buffers in RAM.
/*
* Define this to 1 if you want to declare interrupt-in endpoints, but don't want to send any data over them. If this macro is defined to
* 1, functions usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if you need the interrupt-in endpoints in order to
* comply to an interface (e.g. HID), but never want to send any data. This option saves a couple of bytes in flash memory and the transmit
* buffers in RAM.
*/
#define USB_CFG_INTR_POLL_INTERVAL 20
/* If you compile a version with endpoint 1 (interrupt-in), this is the poll
* interval. The value is in milliseconds and must not be less than 10 ms for
* low speed devices.
/*
* If you compile a version with endpoint 1 (interrupt-in), this is the poll interval. The value is in milliseconds and must not be less
* than 10 ms for low speed devices.
*/
#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
/* 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
* communicates power requirements in units of 2 mA.]
/*
* 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 communicates power requirements in units of 2 mA.]
*/
#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
* bytes.
/*
* 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 bytes.
*/
#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
* data from a static buffer, set it to 0 and return the data from
* usbFunctionSetup(). This saves a couple of bytes.
/*
* 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 data from a static buffer, set it to 0 and return the data from usbFunctionSetup(). This saves a couple of bytes.
*/
#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
* interrupt/bulk data sent to any endpoint other than 0. The endpoint number
* can be found in 'usbRxToken'.
/*
* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints. You must implement the function usbFunctionWriteOut() which
* receives all interrupt/bulk data sent to any endpoint other than 0. The endpoint number can be found in 'usbRxToken'.
*/
#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
* usbdrv.h.
/*
* Define this to 1 if you want flowcontrol over USB data. See the definition of the macros usbDisableAllRequests() and
* usbEnableAllRequests() in usbdrv.h.
*/
#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
* for long transfers increases the driver size.
/*
* 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 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
* 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_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) blinkLED();
*/
/* #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
* one parameter which distinguishes between the start of RESET state and its
* end.
/*
* 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
* 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_SET_ADDRESS_HOOK() hadAddressAssigned(); */
/* This macro (if defined) is executed when a USB SET_ADDRESS request was
* received.
/*
* #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 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 this macro to 1 if you need the global variable "usbSofCount" which
* counts SOF packets. This feature requires that the hardware interrupt is
* connected to D- instead of D+.
/*
* define this macro to 1 if you need the global variable "usbSofCount" which counts SOF packets. This feature requires that the hardware
* interrupt is connected to D- instead of D+.
*/
/* #ifdef __ASSEMBLER__
* macro myAssemblerMacro
* in YL, TCNT0
* sts timer0Snapshot, YL
* endm
* #endif
* #define USB_SOF_HOOK myAssemblerMacro
* This macro (if defined) is executed in the assembler module when a
* Start Of Frame condition is detected. It is recommended to define it to
* the name of an assembler macro which is defined here as well so that more
* than one assembler instruction can be used. The macro may use the register
* YL and modify SREG. If it lasts longer than a couple of cycles, USB messages
* immediately after an SOF pulse may be lost and must be retried by the host.
* What can you do with this hook? Since the SOF signal occurs exactly every
* 1 ms (unless the host is in sleep mode), you can use it to tune OSCCAL in
* designs running on the internal RC oscillator.
* Please note that Start Of Frame detection works only if D- is wired to the
* interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES!
/*
* #ifdef __ASSEMBLER__ macro myAssemblerMacro in YL, TCNT0 sts timer0Snapshot, YL endm #endif #define USB_SOF_HOOK myAssemblerMacro This
* macro (if defined) is executed in the assembler module when a Start Of Frame condition is detected. It is recommended to define it to
* the name of an assembler macro which is defined here as well so that more than one assembler instruction can be used. The macro may use
* the register YL and modify SREG. If it lasts longer than a couple of cycles, USB messages immediately after an SOF pulse may be lost and
* must be retried by the host. What can you do with this hook? Since the SOF signal occurs exactly every 1 ms (unless the host is in sleep
* mode), you can use it to tune OSCCAL in designs running on the internal RC oscillator. Please note that Start Of Frame detection works
* only if D- is wired to the interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES!
*/
#define USB_CFG_CHECK_DATA_TOGGLING 0
/* define this macro to 1 if you want to filter out duplicate data packets
* sent by the host. Duplicates occur only as a consequence of communication
* errors, when the host does not receive an ACK. Please note that you need to
* implement the filtering yourself in usbFunctionWriteOut() and
* usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable
* for each control- and out-endpoint to check for duplicate packets.
/*
* define this macro to 1 if you want to filter out duplicate data packets sent by the host. Duplicates occur only as a consequence of
* communication errors, when the host does not receive an ACK. Please note that you need to implement the filtering yourself in
* usbFunctionWriteOut() and usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable for each control- and
* out-endpoint to check for duplicate packets.
*/
#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0
/* define 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
/* 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
* VID/PID pairs. Be sure to read USBID-License.txt for rules!
/*
* 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 VID/PID pairs. Be sure to read USBID-License.txt for rules!
*/
#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
* or if you have licensed a PID from somebody else, define it here. Otherwise
* you use obdev's free shared VID/PID pair. Be sure to read the rules in
* USBID-License.txt!
/*
* 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 or if you have licensed a PID from somebody else, define it here. Otherwise you use obdev's free shared VID/PID pair. Be sure to
* read the rules in USBID-License.txt!
*/
#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_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
* are interpreted as Unicode (UTF-16) entities.
* If you don't want a vendor name string, undefine these macros.
* ALWAYS 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 for
* details.
/*
* 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 are interpreted as Unicode (UTF-16) entities. If you don't want a vendor name string, undefine these macros. ALWAYS
* 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
* for details.
*/
#define USB_CFG_DEVICE_NAME 'Q', 'U', 'I', 'C', 'K', 'D', 'E', 'V', '1', '6'
#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
* use a shared VID/PID.
/*
* 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 use a shared VID/PID.
*/
/*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */
/*#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_SERIAL_NUMBER 'N', 'o', 'n', 'e'
*/
/*
* #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
/* 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_SUBCLASS 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:
* 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
/*
* See USB specification if you want to conform to an existing device class or protocol. The following classes must be set at interface
* 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
*/
#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.
* If you use this define, you must add a PROGMEM character array named
* "usbHidReportDescriptor" to your code which contains the report descriptor.
* Don't forget to keep the array and this define in sync!
/*
* 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
* you use this define, you must add a PROGMEM character array named "usbHidReportDescriptor" to your code which contains the report
* descriptor. 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.
* This technique saves a couple of bytes in flash memory.
/*
* #define USB_PUBLIC static
*/
/*
* 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
* 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
* information about this function.
* Descriptor handling is configured through the descriptor's properties. If
* no properties are defined or if they are 0, the default descriptor is used.
* Possible properties are:
* + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched
* at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is
* used, the data is in FLASH by default. Add property USB_PROP_IS_RAM if
* you want RAM pointers.
* + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found
* 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 driver must know the descriptor's length. The descriptor itself is
* found at the address of a well known identifier (see below).
* List of static descriptor names (must be declared PROGMEM if in flash):
* char usbDescriptorDevice[];
* char usbDescriptorConfiguration[];
* 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'
/*
* ------------------- Fine Control over USB Descriptors -------------------
*/
/*
* 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
* 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 information about this function. Descriptor handling is configured through the descriptor's properties. If no
* properties are defined or if they are 0, the default descriptor is used. Possible properties are: + USB_PROP_IS_DYNAMIC: The data for
* the descriptor should be fetched at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is used, the data is in FLASH by
* default. Add property USB_PROP_IS_RAM if you want RAM pointers. + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or
* found 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
* driver must know the descriptor's length. The descriptor itself is found at the address of a well known identifier (see below). List of
* static descriptor names (must be declared PROGMEM if in flash): char usbDescriptorDevice[]; char usbDescriptorConfiguration[]; 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_UNKNOWN 0
/* ----------------------- 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.
/*
* ----------------------- 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
*/
/* #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__ */

View File

@ -22,7 +22,7 @@
#include <stdlib.h>
#include <string.h>
uint8_t *util_strupper(uint8_t *s)
uint8_t *util_strupper(uint8_t * s)
{
uint8_t *p;
for (p = s; *p != '\0'; p++)
@ -31,7 +31,7 @@ uint8_t *util_strupper(uint8_t *s)
return s;
}
uint8_t *util_strlower(uint8_t *s)
uint8_t *util_strlower(uint8_t * s)
{
uint8_t *p;
for (p = s; *p != '\0'; p++)
@ -40,49 +40,64 @@ uint8_t *util_strlower(uint8_t *s)
return s;
}
void util_chomp(uint8_t *s)
void util_chomp(uint8_t * s)
{
uint16_t len;
len = strlen((char*)s);
len = strlen((char *) s);
if (len >= 2 && s[len - 1] == '\n' && s[len - 2] == '\r')
s[len - 2] = '\0';
else if (len >= 1 && (s[len - 1] == '\n' || s[len - 1] == '\r'))
s[len - 1] = '\0';
}
void util_trim(uint8_t *s)
void util_trim(uint8_t * s)
{
uint8_t *p = s;
uint8_t *q;
/* skip leading whitespace */
/*
* skip leading whitespace
*/
while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n')
p++;
/* now p points at the first non-whitespace uint8_tacter */
/*
* now p points at the first non-whitespace uint8_tacter
*/
if (*p == '\0') {
/* only whitespace */
/*
* only whitespace
*/
*s = '\0';
return;
}
q = s + strlen((char*)s);
/* skip trailing whitespace */
/* we have found p < q such that *p is non-whitespace,
so this loop terminates with q >= p */
q = s + strlen((char *) s);
/*
* skip trailing whitespace
*/
/*
* we have found p < q such that *p is non-whitespace, so this loop terminates with q >= p
*/
do
q--;
while (*q == ' ' || *q == '\t' || *q == '\r' || *q == '\n');
/* now q points at the last non-whitespace uint8_tacter */
/* cut off trailing whitespace */
/*
* now q points at the last non-whitespace uint8_tacter
*/
/*
* cut off trailing whitespace
*/
*++q = '\0';
/* move to string */
/*
* 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;
if (*s == '\0')
@ -99,7 +114,7 @@ uint32_t util_sscandec(const uint8_t *s)
}
}
uint32_t util_sscanhex(const uint8_t *s)
uint32_t util_sscanhex(const uint8_t * s)
{
int32_t result;
if (*s == '\0')
@ -120,7 +135,7 @@ uint32_t util_sscanhex(const uint8_t *s)
}
}
uint8_t util_sscanbool(const uint8_t *s)
uint8_t util_sscanbool(const uint8_t * s)
{
if (*s == '0' && s[1] == '\0')
return 0;
@ -128,5 +143,3 @@ uint8_t util_sscanbool(const uint8_t *s)
return 1;
return -1;
}

View File

@ -21,12 +21,12 @@
#ifndef __UTIL_H__
#define __UTIL_H__
uint8_t *util_strupper(uint8_t *s);
uint8_t *util_strlower(uint8_t *s);
void util_chomp(uint8_t *s);
void util_trim(uint8_t *s);
uint32_t util_sscandec(const uint8_t *s);
uint32_t util_sscanhex(const uint8_t *s);
uint8_t util_sscanbool(const uint8_t *s);
uint8_t *util_strupper(uint8_t * s);
uint8_t *util_strlower(uint8_t * s);
void util_chomp(uint8_t * s);
void util_trim(uint8_t * s);
uint32_t util_sscandec(const uint8_t * s);
uint32_t util_sscanhex(const uint8_t * s);
uint8_t util_sscanbool(const uint8_t * s);
#endif

View File

@ -28,4 +28,3 @@ void wdt_init(void)
return;
}

View File

@ -27,7 +27,7 @@
#define __WATCHDOG_H__
void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3")));
void wdt_init(void) __attribute__ ((naked)) __attribute__ ((section(".init3")));
#define soft_reset() \
do \
@ -39,4 +39,3 @@ do \
} while(0)
#endif