diff --git a/avr/usbload/Makefile b/avr/usbload/Makefile index 8bc5e17..ac14318 100644 --- a/avr/usbload/Makefile +++ b/avr/usbload/Makefile @@ -33,13 +33,13 @@ ifeq ($(DEBUG),1) OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o \ main.o usb_bulk.o uart.o fifo.o sram.o crc.o debug.o \ dump.o timer.o watchdog.o rle.c loader.o info.o shared_memory.o \ - pwm.o shell.o irq.o command.o testing.o + pwm.o util.o shell.o irq.o command.o testing.o else LDFLAGS =-Wl,-u CFLAGS =-Iusbdrv -I. -DDEBUG_LEVEL=0 -DNO_DEBUG -DNO_INFO OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o usb_bulk.o \ uart.o fifo.o sram.o crc.o debug.o dump.o timer.o watchdog.o rle.c loader.o \ - pwm.o shell.o info.o shared_memory.o command.o irq.o + pwm.o uril.o shell.o info.o shared_memory.o command.o irq.o endif COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE) diff --git a/avr/usbload/shell.c b/avr/usbload/shell.c index 9cadb15..962478d 100644 --- a/avr/usbload/shell.c +++ b/avr/usbload/shell.c @@ -33,6 +33,109 @@ volatile uint8_t recv_counter = 0; volatile uint8_t cr = 0; + + static char *token_ptr; + + static char *get_token(void) + { + char *p = token_ptr; + while (*p == ' ') + p++; + if (*p == '\0') + return NULL; + token_ptr = p; + do { + token_ptr++; + if (*token_ptr == ' ') { + *token_ptr++ = '\0'; + break; + } + } while (*token_ptr != '\0'); + return p; + } + + static int get_dec(int *decval) + { + const char *t; + t = get_token(); + if (t != NULL) { + int x = Util_sscandec(t); + if (x < 0) + return FALSE; + *decval = x; + return TRUE; + } + return FALSE; + } + + static int parse_hex(const char *s, UWORD *hexval) + { + int x = Util_sscanhex(s); + #ifdef MONITOR_HINTS + int y = find_label_value(s); + if (y >= 0) { + if (x < 0 || x > 0xffff || x == y) { + *hexval = (UWORD) y; + return TRUE; + } + /* s can be a hex number or a label name */ + printf("%s is ambiguous. Use 0%X or %X instead.\n", s, x, y); + return FALSE; + } + #endif + if (x < 0 || x > 0xffff) + return FALSE; + *hexval = (UWORD) x; + return TRUE; + } + + static int get_hex(UWORD *hexval) + { + const char *t; + t = get_token(); + if (t != NULL) + return parse_hex(t, hexval); + return FALSE; + } + + static int get_hex2(UWORD *hexval1, UWORD *hexval2) + { + return get_hex(hexval1) && get_hex(hexval2); + } + + static int get_hex3(UWORD *hexval1, UWORD *hexval2, UWORD *hexval3) + { + return get_hex(hexval1) && get_hex(hexval2) && get_hex(hexval3); + } + + static void get_uword(UWORD *val) + { + if (!get_hex(val)) + printf("Invalid argument!\n"); + } + + static void get_ubyte(UBYTE *val) + { + UWORD uword; + if (!get_hex(&uword) || uword > 0xff) + printf("Invalid argument!\n"); + else + *val = (UBYTE) uword; + } + + static int get_bool(void) + { + const char *t; + t = get_token(); + if (t != NULL) { + int result = Util_sscanbool(t); + if (result >= 0) + return result; + } + printf("Invalid argument (should be 0 or 1)!\n"); + return -1; + } + ISR(USART0_RX_vect) // Interrupt for UART Byte received { UCSR0B &= (255 - (1<'); @@ -52,7 +156,10 @@ ISR(USART0_RX_vect) // Interrupt for UART Byte received cr = 1; // found a CR, so the application should do something recv_buf[++recv_counter]='\0'; // terminate string recv_counter = 0; + uart_putc('\r'); uart_putc('\n'); + uart_putc(':'); + uart_putc('>'); } else { // we accept backspace or delete if ((recv_buf[recv_counter] == 0x08 || recv_buf[recv_counter] == 0x7f) && recv_counter > 0) { diff --git a/avr/usbload/util.c b/avr/usbload/util.c new file mode 100644 index 0000000..84bf7d6 --- /dev/null +++ b/avr/usbload/util.c @@ -0,0 +1,132 @@ +/* + * ===================================================================================== + * + * ________ .__ __ ________ ____ ________ + * \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/ + * / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \ + * / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \ + * \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ / + * \__> \/ \/ \/ \/ \/ + * + * www.optixx.org + * + * + * Version: 1.0 + * Created: 07/21/2009 03:32:16 PM + * Author: david@optixx.org + * + * ===================================================================================== + */ + +#include +#include +#include + +uint8_t *util_strupper(uint8_t *s) +{ + uint8_t *p; + for (p = s; *p != '\0'; p++) + if (*p >= 'a' && *p <= 'z') + *p += 'A' - 'a'; + return s; +} + +uint8_t *util_strlower(uint8_t *s) +{ + uint8_t *p; + for (p = s; *p != '\0'; p++) + if (*p >= 'A' && *p <= 'Z') + *p += 'a' - 'A'; + return s; +} + +void util_chomp(uint8_t *s) +{ + uint16_t len; + + len = strlen((char*)s); + if (len >= 2 && s[len - 1] == '\n' && s[len - 2] == '\r') + s[len - 2] = '\0'; + else if (len >= 1 && (s[len - 1] == '\n' || s[len - 1] == '\r')) + s[len - 1] = '\0'; +} + +void util_trim(uint8_t *s) +{ + uint8_t *p = s; + uint8_t *q; + /* skip leading whitespace */ + while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n') + p++; + /* now p points at the first non-whitespace uint8_tacter */ + + if (*p == '\0') { + /* only whitespace */ + *s = '\0'; + return; + } + + q = s + strlen((char*)s); + /* skip trailing whitespace */ + /* we have found p < q such that *p is non-whitespace, + so this loop terminates with q >= p */ + do + q--; + while (*q == ' ' || *q == '\t' || *q == '\r' || *q == '\n'); + + /* now q points at the last non-whitespace uint8_tacter */ + /* cut off trailing whitespace */ + *++q = '\0'; + + /* move to string */ + memmove(s, p, q + 1 - p); +} + +uint32_t util_sscandec(const uint8_t *s) +{ + uint32_t result; + if (*s == '\0') + return -1; + result = 0; + for (;;) { + if (*s >= '0' && *s <= '9') + result = 10 * result + *s - '0'; + else if (*s == '\0') + return result; + else + return -1; + s++; + } +} + +uint32_t util_sscanhex(const uint8_t *s) +{ + uint32_t result; + if (*s == '\0') + return -1; + result = 0; + for (;;) { + if (*s >= '0' && *s <= '9') + result = 16 * result + *s - '0'; + else if (*s >= 'A' && *s <= 'F') + result = 16 * result + *s - 'A' + 10; + else if (*s >= 'a' && *s <= 'f') + result = 16 * result + *s - 'a' + 10; + else if (*s == '\0') + return result; + else + return -1; + s++; + } +} + +uint8_t util_sscanbool(const uint8_t *s) +{ + if (*s == '0' && s[1] == '\0') + return 0; + if (*s == '1' && s[1] == '\0') + return 1; + return -1; +} + + diff --git a/avr/usbload/util.h b/avr/usbload/util.h new file mode 100644 index 0000000..0afd213 --- /dev/null +++ b/avr/usbload/util.h @@ -0,0 +1,32 @@ +/* + * ===================================================================================== + * + * ________ .__ __ ________ ____ ________ + * \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/ + * / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \ + * / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \ + * \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ / + * \__> \/ \/ \/ \/ \/ + * + * www.optixx.org + * + * + * Version: 1.0 + * Created: 07/21/2009 03:32:16 PM + * Author: david@optixx.org + * + * ===================================================================================== + */ + +#ifndef __UTIL_H__ +#define __UTIL_H__ + + uint8_t *util_strupper(uint8_t *s); +uint8_t *util_strlower(uint8_t *s); +void util_chomp(uint8_t *s); +void util_trim(uint8_t *s); +uint32_t util_sscandec(const uint8_t *s); +uint32_t util_sscanhex(const uint8_t *s); +uint8_t util_sscanbool(const uint8_t *s); + +#endif diff --git a/quickdev16.tmproj b/quickdev16.tmproj index eea636f..76bee95 100644 --- a/quickdev16.tmproj +++ b/quickdev16.tmproj @@ -3,7 +3,7 @@ currentDocument - avr/usbload/sram.h + avr/usbload/util.c documents @@ -21,451 +21,19 @@ 271 metaData - README - - caret - - column - 49 - line - 7 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 0 - selectFrom - - column - 1 - line - 7 - - selectTo - - column - 49 - line - 7 - - - avr/bootloader/bootloader.c - - caret - - column - 0 - line - 31 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 0 - selectFrom - - column - 0 - line - 30 - - selectTo - - column - 0 - line - 31 - - - avr/bootloader/bootloader.hex - - caret - - column - 0 - line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/bootloader/config.h - - caret - - column - 0 - line - 22 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/bootloader/interrupts.S - - caret - - column - 0 - line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/bootloader/usbconfig.h - - caret - - column - 39 - line - 50 - - firstVisibleColumn - 0 - firstVisibleLine - 144 - - avr/usbload/checksize - - caret - - column - 0 - line - 12 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/command.c - - caret - - column - 0 - line - 22 - - firstVisibleColumn - 0 - firstVisibleLine - 14 - - avr/usbload/command.h - - caret - - column - 16 - line - 25 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 0 - selectFrom - - column - 0 - line - 0 - - selectTo - - column - 0 - line - 29 - - - avr/usbload/config.h - - caret - - column - 38 - line - 46 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/crc.c - - caret - - column - 20 - line - 81 - - firstVisibleColumn - 0 - firstVisibleLine - 41 - - avr/usbload/crc.h - - caret - - column - 26 - line - 6 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/debug.c - - caret - - column - 31 - line - 39 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/debug.h - - caret - - column - 0 - line - 33 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 0 - selectFrom - - column - 0 - line - 31 - - selectTo - - column - 0 - line - 33 - - - avr/usbload/dump.c - - caret - - column - 13 - line - 67 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 31 - selectFrom - - column - 5 - line - 67 - - selectTo - - column - 16 - line - 67 - - - avr/usbload/dump.h - - caret - - column - 0 - line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/fifo.c - - caret - - column - 17 - line - 22 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/fifo.h - - caret - - column - 0 - line - 19 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/info.c - - caret - - column - 4 - line - 33 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/info.h - - caret - - column - 22 - line - 32 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/irq.c - - caret - - column - 0 - line - 28 - - firstVisibleColumn - 0 - firstVisibleLine - 21 - - avr/usbload/irq.h - - caret - - column - 13 - line - 22 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/loader.c - - caret - - column - 0 - line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 443 - - avr/usbload/loader.h - - caret - - column - 0 - line - 9 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - avr/usbload/main.c caret column - 0 + 42 line - 30 + 252 - columnSelection - firstVisibleColumn 0 firstVisibleLine - 0 - selectFrom - - column - 0 - line - 29 - - selectTo - - column - 0 - line - 30 - + 247 avr/usbload/rle.h @@ -476,154 +44,28 @@ line 0 - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/shared_memory.c - - caret - - column - 41 - line - 135 - - firstVisibleColumn - 0 - firstVisibleLine - 108 - - avr/usbload/shared_memory.h - - caret - - column - 50 - line - 50 - - firstVisibleColumn - 0 - firstVisibleLine - 22 - - avr/usbload/sram.c - - caret - - column - 24 - line - 34 - - firstVisibleColumn - 0 - firstVisibleLine - 141 - - avr/usbload/sram.h - - caret - - column - 66 - line - 154 - - firstVisibleColumn - 0 - firstVisibleLine - 132 - - avr/usbload/testing.c - - caret - - column - 0 - line - 106 - - firstVisibleColumn - 0 - firstVisibleLine - 25 - - avr/usbload/testing.h - - caret - - column - 0 - line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/timer.c - - caret - - column - 41 - line - 61 - columnSelection firstVisibleColumn 0 firstVisibleLine - 28 + 0 selectFrom column - 0 + 17 line - 0 + 21 selectTo column 0 line - 94 - - - avr/usbload/timer.h - - caret - - column 0 - line - 29 - firstVisibleColumn - 0 - firstVisibleLine - 0 - avr/usbload/uart.c - - caret - - column - 0 - line - 34 - - firstVisibleColumn - 0 - firstVisibleLine - 44 - - avr/usbload/usb_bulk.c + avr/usbload/shell.c caret @@ -632,171 +74,159 @@ line 74 - firstVisibleColumn - 0 - firstVisibleLine - 40 - - avr/usbload/usbconfig.h - - caret - - column - 80 - line - 251 - columnSelection firstVisibleColumn 0 firstVisibleLine - 231 + 80 selectFrom column - 32 + 0 line - 251 + 73 selectTo column - 80 + 0 line - 251 + 74 - avr/usbload/watchdog.c + avr/usbload/shell.h caret column 0 line + 0 + + columnSelection + + firstVisibleColumn + 0 + firstVisibleLine + 0 + selectFrom + + column + 0 + line + 19 + + selectTo + + column + 0 + line + 0 + + + avr/usbload/sram.c + + caret + + column 22 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - avr/usbload/watchdog.h - - caret - - column - 0 line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - poc/avr_sdcard/fat.c - - caret - - column - 0 - line - 38 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - poc/avr_sdcard/fat.h - - caret - - column - 4 - line - 63 + 287 columnSelection firstVisibleColumn 0 firstVisibleLine - 23 + 206 selectFrom column - 1 - line - 63 - - selectTo - - column - 9 - line - 63 - - - poc/avr_sdcard/main.c - - caret - - column - 12 - line - 170 - - columnSelection - - firstVisibleColumn - 0 - firstVisibleLine - 137 - selectFrom - - column - 1 - line - 170 - - selectTo - - column - 20 - line - 170 - - - poc/avr_sdcard/main.lst - - caret - - column - 0 - line - 0 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - poc/avr_usbload/sram.c - - caret - - column - 17 - line 5 + line + 287 + + selectTo + + column + 31 + line + 287 + + + avr/usbload/uart.c + + caret + + column + 0 + line + 20 + + firstVisibleColumn + 0 + firstVisibleLine + 26 + + avr/usbload/usb_bulk.h + + caret + + column + 0 + line + 0 firstVisibleColumn 0 firstVisibleLine 0 + avr/usbload/util.c + + caret + + column + 15 + line + 46 + + firstVisibleColumn + 0 + firstVisibleLine + 14 + + avr/usbload/util.h + + caret + + column + 0 + line + 0 + + columnSelection + + firstVisibleColumn + 0 + firstVisibleLine + 0 + selectFrom + + column + 3 + line + 18 + + selectTo + + column + 0 + line + 0 + + snes/banktest/LoadGraphics.asm caret @@ -828,50 +258,15 @@ openDocuments - avr/usbload/testing.h - avr/usbload/testing.c - avr/usbload/timer.c - avr/usbload/irq.c - avr/bootloader/bootloader.hex - avr/usbload/irq.h - avr/usbload/timer.h - avr/usbload/uart.c - avr/usbload/usb_bulk.c - avr/usbload/watchdog.c - avr/usbload/watchdog.h - poc/avr_sdcard/fat.c - poc/avr_sdcard/fat.h - poc/avr_sdcard/main.lst - avr/bootloader/config.h - avr/bootloader/bootloader.c - README - avr/bootloader/usbconfig.h - avr/usbload/debug.c - avr/usbload/dump.h - avr/usbload/crc.c - avr/usbload/command.h - avr/usbload/dump.c - avr/usbload/loader.h - avr/usbload/info.h - avr/usbload/loader.c - avr/usbload/fifo.c - avr/usbload/command.c - avr/usbload/debug.h - avr/usbload/rle.h - avr/usbload/config.h - poc/avr_sdcard/main.c - poc/avr_usbload/sram.c - avr/usbload/sram.h - avr/usbload/shared_memory.h - avr/usbload/checksize - avr/usbload/shared_memory.c - avr/bootloader/interrupts.S - avr/usbload/info.c - avr/usbload/fifo.h - avr/usbload/main.c avr/usbload/sram.c - avr/usbload/usbconfig.h - avr/usbload/crc.h + avr/usbload/main.c + avr/usbload/shell.c + avr/usbload/uart.c + avr/usbload/util.c + avr/usbload/util.h + avr/usbload/usb_bulk.h + avr/usbload/rle.h + avr/usbload/shell.h showFileHierarchyDrawer @@ -891,13 +286,6 @@ subItems - bootloader - - isExpanded - - subItems - - usbload isExpanded @@ -907,6 +295,13 @@ + scripts + + isExpanded + + subItems + +