From: Uwe Hermann Date: Wed, 22 Feb 2012 22:30:13 +0000 (+0100) Subject: Various cosmetics and bugfixes. X-Git-Tag: sigrok-firmware-fx2lafw-0.1.0~65 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=106ee45c35ebae9b2ec9370813ab20cbbe22d2e2;p=sigrok-firmware-fx2lafw.git Various cosmetics and bugfixes. --- diff --git a/cwav-usbeeax/Makefile b/cwav-usbeeax/Makefile index ff05a1eb..a60f2af7 100644 --- a/cwav-usbeeax/Makefile +++ b/cwav-usbeeax/Makefile @@ -18,10 +18,7 @@ ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ## -SOURCES = \ - main.c \ - ../fx2lafw.c \ - ../debug.c +SOURCES = main.c ../fx2lafw.c ../debug.c A51_SOURCES = ../dscr.a51 BASENAME = fx2lafw-cwav-usbeeax diff --git a/cwav-usbeeax/main.c b/cwav-usbeeax/main.c index 8f7be941..1c398f5b 100644 --- a/cwav-usbeeax/main.c +++ b/cwav-usbeeax/main.c @@ -25,7 +25,6 @@ void main(void) { fx2lafw_init(); - while(1) + while (1) fx2lafw_run(); } - diff --git a/debug.c b/debug.c index 11807589..ba8d3f16 100644 --- a/debug.c +++ b/debug.c @@ -22,39 +22,40 @@ #include #include - #include #include #include - #include "debug.h" #define MESSAGE_LENGTH_MAX 64 -void debugf(const char *format, ...) { +void debugf(const char *format, ...) +{ va_list arg; int count; - // Format the string - va_start (arg, format); + /* Format the string. */ + va_start(arg, format); count = vsprintf(EP6FIFOBUF, format, arg); - va_end (arg); + va_end(arg); - // Zero out the rest of the buffer - while(count < MESSAGE_LENGTH_MAX) + /* Zero out the rest of the buffer. */ + while (count < MESSAGE_LENGTH_MAX) EP6FIFOBUF[count++] = '\0'; - // Send the buffer + /* Send the buffer. */ count = 32; EP6BCH = MSB(count); SYNCDELAY4; EP6BCL = LSB(count); + SYNCDELAY4; } -void _assert(char *expr, const char *filename, unsigned int linenumber) { +void _assert(char *expr, const char *filename, unsigned int linenumber) +{ debugf("Assert(%s) failed at line %u in file %s.\n", - expr, linenumber, filename); - while(1); + expr, linenumber, filename); + while (1); } #endif diff --git a/dscr.a51 b/dscr.a51 index c96e003d..76b3401f 100644 --- a/dscr.a51 +++ b/dscr.a51 @@ -115,10 +115,10 @@ highspd_dscr_end: ; Endpoint 6 (IN) .db DSCR_ENDPOINT_LEN .db DSCR_ENDPOINT_TYPE - .db 0x86 ; EP number (6), direction (IN) + .db 0x86 ; EP number (6), direction (IN) .db ENDPOINT_TYPE_BULK ; Endpoint type (bulk) - .db 0x00 ; Max. packet size, LSB (64 bytes) - .db 0x02 ; Max. packet size, MSB (64 bytes) + .db 0x00 ; Max. packet size, LSB (512 bytes) + .db 0x02 ; Max. packet size, MSB (512 bytes) .db 0x00 ; Polling interval highspd_dscr_realend: @@ -164,7 +164,7 @@ fullspd_dscr_end: ; Endpoint 6 (IN) .db DSCR_ENDPOINT_LEN .db DSCR_ENDPOINT_TYPE - .db 0x86 ; EP number (6), direction (IN) + .db 0x86 ; EP number (6), direction (IN) .db ENDPOINT_TYPE_BULK ; Endpoint type (bulk) .db 0x40 ; Max. packet size, LSB (64 bytes) .db 0x00 ; Max. packet size, MSB (64 bytes) diff --git a/fx2lafw.c b/fx2lafw.c index 24c05909..2a64b84a 100644 --- a/fx2lafw.c +++ b/fx2lafw.c @@ -272,7 +272,7 @@ static void setup_endpoints(void) #endif SYNCDELAY(); - /* Disable all other EPs (EP4 and EP8). */ + /* Disable all other EPs (EP1, EP4, and EP8). */ EP1INCFG &= ~bmVALID; SYNCDELAY(); EP1OUTCFG &= ~bmVALID; @@ -355,14 +355,17 @@ BOOL handle_set_interface(BYTE ifc, BYTE alt_ifc) /* (2) Reset data toggles of the EPs in the interface. */ /* Note: RESETTOGGLE() gets the EP number WITH bit 7 set/cleared. */ RESETTOGGLE(0x82); - RESETTOGGLE(0x76); +#ifdef DEBUG + RESETTOGGLE(0x86); +#endif /* (3) Restore EPs to their default conditions. */ /* Note: RESETFIFO() gets the EP number WITHOUT bit 7 set/cleared. */ RESETFIFO(0x02); /* TODO */ - +#ifdef DEBUG RESETFIFO(0x06); +#endif /* (4) Clear the HSNAK bit. Not needed, fx2lib does this. */ diff --git a/fx2lafw.mk b/fx2lafw.mk index a8f7a3b4..c4af71df 100644 --- a/fx2lafw.mk +++ b/fx2lafw.mk @@ -31,3 +31,4 @@ endif SDCCFLAGS += -I../include/ include $(FX2LIBDIR)/lib/fx2.mk + diff --git a/include/debug.h b/include/debug.h index 5cb6861e..1d631c39 100644 --- a/include/debug.h +++ b/include/debug.h @@ -20,43 +20,30 @@ #ifdef DEBUG -#define ERRF(fmt, ...) \ - do { debugf("E " fmt, __VA_ARGS__); \ - while(1); } while(0) -#define ERR(msg) \ - ERRF("%s", msg) - -#define WARNF(fmt, ...) \ - debugf("W " fmt, __VA_ARGS__) -#define WARN(msg) \ - WARNF("%s", msg) - -#define INFOF(fmt, ...) \ - debugf("I " fmt, __VA_ARGS__) -#define INFO(msg) \ - INFOF("%s", msg) +#define ERRF(fmt, ...) do { debugf("E " fmt, __VA_ARGS__); \ + while(1); } while(0) +#define ERR(msg) ERRF("%s", msg) + +#define WARNF(fmt, ...) debugf("W " fmt, __VA_ARGS__) +#define WARN(msg) WARNF("%s", msg) + +#define INFOF(fmt, ...) debugf("I " fmt, __VA_ARGS__) +#define INFO(msg) INFOF("%s", msg) /** - * A printf the prints messages through the UART - * EP6. + * A printf that prints messages through EP6. */ void debugf(const char *format, ...); #else -#define ERRF(fmt, ...) \ - ((void) 0) -#define ERR(msg) \ - ((void) 0) +#define ERRF(fmt, ...) ((void)0) +#define ERR(msg) ((void)0) -#define WARNF(fmt, ...) \ - ((void) 0) -#define WARN(msg) \ - ((void) 0) +#define WARNF(fmt, ...) ((void)0) +#define WARN(msg) ((void)0) -#define INFOF(fmt, ...) \ - ((void) 0) -#define INFO(msg) \ - ((void) 0) +#define INFOF(fmt, ...) ((void)0) +#define INFO(msg) ((void)0) #endif diff --git a/tools/debug.py b/tools/debug.py index cd197762..b3be5180 100755 --- a/tools/debug.py +++ b/tools/debug.py @@ -17,15 +17,15 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -import struct +import struct from fx2load import * -# Connect to the device +# Connect to the device. openfx2(0x6666, 0x0019) -# Read debug messages +# Read debug messages. while 1: - buf='\x00'*200 - f.ep_bulk( buf, 0x86, 1000) - print buf + buf = '\x00' * 200 + f.ep_bulk(buf, 0x86, 1000) + print(buf)