From: Joel Holdsworth Date: Sat, 18 Feb 2012 08:50:24 +0000 (+0000) Subject: Added basic debugf for sending debug messages over USB X-Git-Tag: sigrok-firmware-fx2lafw-0.1.0~75 X-Git-Url: http://sigrok.org/gitweb/?a=commitdiff_plain;h=c430e296be053c17d4d5f40c53378d401ab07a17;hp=e1c8448f400a3f0099274c8f1ce4a0745f04d650;p=sigrok-firmware-fx2lafw.git Added basic debugf for sending debug messages over USB --- diff --git a/Makefile b/Makefile index 0256737c..dee42704 100644 --- a/Makefile +++ b/Makefile @@ -18,11 +18,18 @@ ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ## -SOURCES = fx2lafw.c +SOURCES = fx2lafw.c debug.c A51_SOURCES = dscr.a51 BASENAME = fx2lafw FX2LIBDIR ?= fx2lib +DEBUG ?= 0 +ifeq ($(DEBUG), 1) + SDCCFLAGS += -DDEBUG +else + SDCCFLAGS += -DNDEBUG +endif + include $(FX2LIBDIR)/lib/fx2.mk diff --git a/debug.c b/debug.c new file mode 100644 index 00000000..8dab8c70 --- /dev/null +++ b/debug.c @@ -0,0 +1,54 @@ +/* + * This file is part of the fx2lafw project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifdef DEBUG + +#include +#include + +#include +#include +#include + +#include "debug.h" + +#define MESSAGE_LENGTH_MAX 64 + +void debugf(const char *format, ...) { + va_list arg; + int count; + + // Format the string + va_start (arg, format); + count = vsprintf(EP6FIFOBUF, format, arg); + va_end (arg); + + // Zero out the rest of the buffer + while(count < MESSAGE_LENGTH_MAX) + EP6FIFOBUF[count++] = '\0'; + + // Send the buffer + count = 32; + EP6BCH = MSB(count); + SYNCDELAY4; + EP6BCL = LSB(count); +} + +#endif diff --git a/debug.h b/debug.h new file mode 100644 index 00000000..790327bf --- /dev/null +++ b/debug.h @@ -0,0 +1,29 @@ +/* + * This file is part of the fx2lafw project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifdef DEBUG + +/** + * A printf the prints messages through the UART + * EP6. + */ +void debugf(const char *format, ...); + +#endif diff --git a/dscr.a51 b/dscr.a51 index 735e55d3..c96e003d 100644 --- a/dscr.a51 +++ b/dscr.a51 @@ -97,7 +97,7 @@ highspd_dscr_end: .db DSCR_INTERFACE_TYPE .db 0 ; Interface index .db 0 ; Alternate setting index - .db 1 ; Number of endpoints + .db 2 ; Number of endpoints .db 0xff ; Class (vendor specific) .db 0xff ; Subclass (vendor specific) .db 0xff ; Protocol (vendor specific) @@ -112,6 +112,15 @@ highspd_dscr_end: .db 0x02 ; Max. packet size, MSB (512 bytes) .db 0x00 ; Polling interval + ; Endpoint 6 (IN) + .db DSCR_ENDPOINT_LEN + .db DSCR_ENDPOINT_TYPE + .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 ; Polling interval + highspd_dscr_realend: .even @@ -137,7 +146,7 @@ fullspd_dscr_end: .db DSCR_INTERFACE_TYPE .db 0 ; Interface index .db 0 ; Alternate setting index - .db 1 ; Number of endpoints + .db 2 ; Number of endpoints .db 0xff ; Class (vendor specific) .db 0xff ; Subclass (vendor specific) .db 0xff ; Protocol (vendor specific) @@ -152,6 +161,15 @@ fullspd_dscr_end: .db 0x00 ; Max. packet size, MSB (64 bytes) .db 0x00 ; Polling interval + ; Endpoint 6 (IN) + .db DSCR_ENDPOINT_LEN + .db DSCR_ENDPOINT_TYPE + .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) + .db 0x00 ; Polling interval + fullspd_dscr_realend: .even diff --git a/fx2lafw.c b/fx2lafw.c index 6c99f046..f6995516 100644 --- a/fx2lafw.c +++ b/fx2lafw.c @@ -259,21 +259,36 @@ static void setup_endpoints(void) (0 << 1) | (0 << 0); /* EP buffering: quad buffering */ SYNCDELAY(); - /* Disable all other EPs (EP1, EP4, EP6, and EP8). */ + /* Setup EP6 (IN) in the debug build. */ +#ifdef DEBUG + EP6CFG = (1 << 7) | /* EP is valid/activated */ + (1 << 6) | /* EP direction: IN */ + (1 << 5) | (0 << 4) | /* EP Type: bulk */ + (0 << 3) | /* EP buffer size: 512 */ + (0 << 2) | /* Reserved */ + (1 << 1) | (0 << 0); /* EP buffering: double buffering */ +#else + EP6CFG &= ~bmVALID; +#endif + SYNCDELAY(); + + /* Disable all other EPs (EP4 and EP8). */ EP1INCFG &= ~bmVALID; SYNCDELAY(); EP1OUTCFG &= ~bmVALID; SYNCDELAY(); EP4CFG &= ~bmVALID; SYNCDELAY(); - EP6CFG &= ~bmVALID; - SYNCDELAY(); EP8CFG &= ~bmVALID; SYNCDELAY(); /* EP2: Reset the FIFOs. */ /* Note: RESETFIFO() gets the EP number WITHOUT bit 7 set/cleared. */ RESETFIFO(0x02) +#ifdef DEBUG + /* Reset the FIFOs of EP6 when in debug mode. */ + RESETFIFO(0x06) +#endif /* EP2: Enable AUTOIN mode. Set FIFO width to 8bits. */ EP2FIFOCFG = bmAUTOIN | ~bmWORDWIDE; @@ -340,12 +355,15 @@ 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); /* (3) Restore EPs to their default conditions. */ /* Note: RESETFIFO() gets the EP number WITHOUT bit 7 set/cleared. */ RESETFIFO(0x02); /* TODO */ + RESETFIFO(0x06); + /* (4) Clear the HSNAK bit. Not needed, fx2lib does this. */ return TRUE;