Browse files

o Reformatting the README file to markdown formatting.

o Adding an Ant build-tck.xml file to build and run the TCK suite.
o Fixing an API bug in UsbDevice.
o Adding a start of some firmware images to run the TCK. Does not work yet.
  • Loading branch information...
1 parent a6b9cd6 commit 33bfdd9e685881d8fa631fc32191ff9dc8f58c67 @trygvis committed Jul 18, 2010
View
2 .gitignore
@@ -1,6 +1,7 @@
*.iml
*.ipr
*.iwp
+*.iws
*.la
*.lo
*.log
@@ -9,5 +10,6 @@
*.swp
.idea
.libs
+build
hs_err_*.log
target
View
22 README
@@ -1,22 +0,0 @@
-Technical Implementation Details
-
-The device and handle references are stored internally in the Device and Interface classes
-as integers. These should be byte arrays to be a bit more generic.
-
-To control the debugging level from libusb set the system property
-"javax.usb.libusb.debug" to the desired level:
-
- -Djavax.usb.libusb.debug=3
-
-See their documentation for the up to date values. Current values:
-
- Level 0: no messages ever printed by the library (default)
- Level 1: error messages are printed to stderr
- Level 2: warning and error messages are printed to stderr
- Level 3: informational messages are printed to stdout, warning and error
- messages are printed to stderr
-
-To trace all calls to libusb, truss/strace/kdump style set the system property
-"javax.usb.libusb.trace" to true
-
- -Djavax.usb.libusb.trace=true
View
109 README.markdown
@@ -0,0 +1,109 @@
+Technical Implementation Details
+================================
+
+The device and handle references are stored internally in the Device
+and Interface classes as integers. These should be byte arrays to
+be a bit more generic.
+
+To control the debugging level from libusb set the system property
+"javax.usb.libusb.debug" to the desired level:
+
+> -Djavax.usb.libusb.debug=3`
+
+See their documentation for the up to date values. Current values:
+
+ * Level 0: no messages ever printed by the library (default)
+ * Level 1: error messages are printed to `stderr`
+ * Level 2: warning and error messages are printed to `stderr`
+ * Level 3: informational messages are printed to `stdout`, warning
+ and error messages are printed to `stderr`
+
+To trace all calls to libusb, truss/strace/kdump style set the
+system property "javax.usb.libusb.trace" to true
+
+> -Djavax.usb.libusb.trace=true`
+
+Notes on Building
+-----------------
+
+To build this software you need:
+
+ * A working SDCC installation in your PATH that supports the "mcs51"
+ target. I'm using v2.9.0.
+
+ * My libusb repository to get the required libusb_get_speed methods.
+ You can get it with this command:
+
+ git clone git://git.libusb.org/libusb-trygvis.git
+
+ Online repository: http://git.libusb.org/?p=libusb-trygvis.git;a=summary
+
+This is the command used to create and synchronize the upstream CVS repositories:
+
+> git cvsimport -d :pserver:anonymous@javax-usb.cvs.sourceforge.net:/cvsroot/javax-usb javax-usb
+
+### The Firmware
+
+The original firmware images are not used as it's not clear which
+images they represent. In addition I can't use any tools that work
+on OS X/Linux to upload the firmware.
+
+The sources depend on [fx2lib] which is a "Library routines for
+creating firmware for the Cypress FX2 (CY7C68013 and variants) with
+SDCC". Fx2lib includes its own build system which the Makefile calls out to.
+
+To be able to build the images you need to create a Makefile.local
+with references to your fx2 library and add `cycfx2prog` to your
+PATH. For example:
+
+ FX2LIBDIR=/Users/trygvis/dev/com.github/mulicheng/fx2lib/
+ PATH:=/Users/trygvis/src/cycfx2prog-0.47:$(PATH)
+
+#### Building the Firmware
+
+Building the firmware is easy once your have all the prerequisites set up:
+
+ cd tck/images
+ make
+
+#### The Build
+
+### Loading the Firmware
+
+To load the firmware:
+
+ 1. Make sure that the device is available. You can do this with `make list`:
+
+ $ make list
+ cycfx2prog --list
+ Bus 004 Device 001: ID 05ac:8005
+ Bus 004 Device 002: ID 05ac:0237
+ Bus 004 Device 003: ID 05ac:8242
+ Bus 036 Device 001: ID 05ac:8006
+ Bus 036 Device 002: ID 05ac:8507
+ Bus 006 Device 001: ID 05ac:8005
+ Bus 038 Device 001: ID 05ac:8006
+ Bus 038 Device 002: ID 04b4:8613 (unconfigured FX2)
+
+ Here you can see that the device was disovered and as long as
+ there's only one device on the system it will be used directly.
+
+ 1. Program the device with the wanted image using the `program-%`
+ target where the percentage sign is replaced with either
+ `topology`, `bulk` or `iso`.
+
+ $ make program-topology
+ make topology
+ make -f Makefile.topology
+ make[2]: Nothing to be done for `ihx'.
+ cycfx2prog prg:build/topology.ihx run
+ Using ID 04b4:8613 on 038.002.
+ Putting 8051 into reset.
+ Programming 8051 using "build/topology.ihx".
+ Putting 8051 out of reset.
+
+ 1. The device should be ready for the TCK now.
+
+ TODO: Add output of `make list`.
+
+[fx2lib]: http://github.com/mulicheng/fx2lib "fx2lib"
View
5 build-default.properties
@@ -0,0 +1,5 @@
+tck.path=../javax-usb-tck
+javax.usb.path=../javax-usb
+libusb.lib.path=${user.home}/opt/libusb-git/lib
+
+# Set maven.repo.local if it's not located under ${user.home}/.m2/repository
View
111 build-tck.xml
@@ -0,0 +1,111 @@
+<project name="javax-usb-libusb1">
+
+ <property file="build.properties"/>
+ <loadproperties srcFile="build-default.properties"/>
+ <property name="maven.repo.local" value="${user.home}/.m2/repository"/>
+
+ <target name="compile" depends="compile-tck,compile-javalibusb1"/>
+
+ <path id="compile">
+ <pathelement location="javax.usb/target/classes"/>
+ <pathelement location="javalibusb1/target/classes"/>
+ </path>
+
+ <path id="test">
+ <pathelement location="javax.usb/target/classes"/>
+ <pathelement location="javax.usb/target/test-classes"/>
+
+ <pathelement location="javalibusb1/target/classes"/>
+ <pathelement location="javalibusb1/target/test-classes"/>
+
+ <pathelement location="${tck.path}/target/classes"/>
+ <pathelement location="${tck.path}/target/test-classes"/>
+
+ <pathelement location="${maven.repo.local}/junit/junit/3.8.1/junit-3.8.1.jar"/>
+ </path>
+
+ <target name="clean">
+ <delete dir="javax.usb/target/classes"/>
+ <delete dir="javalibusb1/target/classes"/>
+ <delete dir="javalibusb1/target/test-classes"/>
+ <exec executable="make">
+ <arg line="-C javalibusb1 clean"/>
+ </exec>
+ <delete dir="${tck.path}/target/classes"/>
+ <delete dir="${tck.path}/target/test-classes"/>
+
+ <delete dir="${javax.usb.path}/target/classes"/>
+ <delete dir="${javax.usb.path}/target/test-classes"/>
+ </target>
+
+ <target name="compile-javax-usb">
+ <mkdir dir="javax.usb/target/classes"/>
+ <javac srcdir="javax.usb/src/main/java" destdir="javax.usb/target/classes"/>
+ </target>
+
+ <target name="compile-javalibusb1" depends="compile-javax-usb">
+ <mkdir dir="javalibusb1/target/classes"/>
+ <javac srcdir="javalibusb1/src/main/java" destdir="javalibusb1/target/classes" classpathref="compile"/>
+ <copy todir="javalibusb1/target/classes">
+ <fileset dir="javalibusb1/src/main/resources"/>
+ </copy>
+ <exec executable="make">
+ <arg line="-C javalibusb1 all"/>
+ </exec>
+
+ <mkdir dir="javalibusb1/target/test-classes"/>
+ <javac srcdir="javalibusb1/src/test/java" destdir="javalibusb1/target/test-classes" classpathref="test"/>
+ </target>
+
+ <target name="compile-tck" depends="compile-javax-usb">
+ <mkdir dir="${tck.path}/target/classes"/>
+ <mkdir dir="${tck.path}/target/test-classes"/>
+
+ <mkdir dir="${javax.usb.path}/target/classes"/>
+ <mkdir dir="${javax.usb.path}/target/test-classes"/>
+ <!--
+ The local javax.usb implementation is not complete enough so
+ compile against the original javax.usb implementation.
+
+ <javac srcdir="${tck.path}/src/javax" destdir="${tck.path}/target/classes" classpathref="test"/>
+ -->
+
+ <javac srcdir="${javax.usb.path}/src" destdir="${javax.usb.path}/target/classes"/>
+
+ <javac srcdir="${tck.path}/src" destdir="${tck.path}/target/test-classes">
+ <classpath>
+ <file file="${maven.repo.local}/junit/junit/3.8.1/junit-3.8.1.jar"/>
+ <dirset dir="${javax.usb.path}/target/classes"/>
+ </classpath>
+ </javac>
+ </target>
+
+ <target name="prepare-tck" depends="compile">
+ </target>
+
+ <target name="tck-1" depends="prepare-tck">
+ <echo>Running TCK Test CONFIG1_TOPOLOGY_B6_IMAGE</echo>
+ <echo>See tck.log for output.</echo>
+
+ <!-- This uses the local javax.usb + TCK classes -->
+ <java fork="true" failonerror="true" output="tck.log" classpathref="test"
+ classname="javax.usb.tck.CONFIG1_TOPOLOGY_B6_IMAGE">
+ <sysproperty key="javaxusbtck_home" value="${tck.path}"/>
+ <sysproperty key="java.library.path" value="javalibusb1/.libs"/>
+ <env key="LD_LIBRARY_PATH" value="${libusb.lib.path}"/>
+ <!-- For Darwin/OS X -->
+ <env key="DYLD_LIBRARY_PATH" value="${libusb.lib.path}"/>
+ </java>
+
+ <!--
+ javax.usb.tck.CONFIG2_TOPOLOGY_B6_IMAGE
+ javax.usb.tck.CONFIG3_BULKINT_B6_IMAGE
+ javax.usb.tck.CONFIG3_ISODCP_B6_IMAGE
+ javax.usb.tck.CONFIG3_TOPOLOGY_B6_IMAGE
+ javax.usb.tck.OPT_CONFIG3_ISODCP_ISOCHRONOUS
+ javax.usb.tck.OPT_CONFIG3_TOPOLOGY_SET_CONFIG
+ javax.usb.tck.OPT_CONFIG3_TOPOLOGY_SET_INTERFACE
+ javax.usb.tck.SIGNATURE
+ -->
+ </target>
+</project>
View
4 javalibusb1/Makefile.local.Darwin
@@ -1 +1,3 @@
-CCFLAGS += -L/Users/trygvis/opt/libusb-git/lib -I/Users/trygvis/opt/libusb-git/include/libusb-1.0
+CCFLAGS += -L/Users/trygvis/opt/libusb-git/lib
+#CCFLAGS += -R/Users/trygvis/opt/libusb-git/lib
+CCFLAGS += -I/Users/trygvis/opt/libusb-git/include/libusb-1.0
View
11 javalibusb1/src/main/java/javalibusb1/Libusb1UsbDevice.java
@@ -132,8 +132,15 @@ public boolean containsUsbConfiguration(byte number) throws UsbPlatformException
return nativeGetUsbConfiguration(number) != null;
}
- public UsbConfiguration getUsbConfiguration(byte number) throws UsbPlatformException {
- return nativeGetUsbConfiguration(number);
+ /**
+ * This is not right. The configurations probably have to be cached somewhere as we can't throw the exception out.
+ */
+ public UsbConfiguration getUsbConfiguration(byte number) {
+ try {
+ return nativeGetUsbConfiguration(number);
+ } catch (UsbPlatformException e) {
+ return null;
+ }
}
public List<UsbConfiguration> getUsbConfigurations() throws UsbPlatformException {
View
3 javalibusb1/src/test/java/javalibusb1/test/lsusb.java
@@ -56,9 +56,6 @@ private static void dump(UsbDevice usbDevice) {
UsbConfiguration usbConfiguration = null;
try {
usbConfiguration = usbDevice.getUsbConfiguration((byte) i);
- } catch (UsbPlatformException e) {
- System.out.println(" Configuration #" + i + " - unable to read from device");
- continue;
} catch (Exception e) {
System.out.println(" Configuration #" + i + " - unable to read from device");
continue;
View
2 javax.usb/src/main/java/javax/usb/UsbDevice.java
@@ -58,7 +58,7 @@
boolean containsUsbConfiguration(byte number) throws UsbPlatformException;
- UsbConfiguration getUsbConfiguration(byte number) throws UsbPlatformException;
+ UsbConfiguration getUsbConfiguration(byte number);
List<UsbConfiguration> getUsbConfigurations() throws UsbPlatformException;
}
View
1 tck/images/.gitignore
@@ -0,0 +1 @@
+*.*.asm
View
45 tck/images/Makefile
@@ -0,0 +1,45 @@
+include Makefile.local
+
+CPP=sdcpp
+CPP=cpp
+
+ifeq ($(FX2LIBDIR),)
+$(error FX2LIBDIR has to be defined in Makefile.local)
+endif
+
+ifeq ($(DEVICE),)
+OPT_D=
+else
+OPT_D=-d=$(DEVICE)
+endif
+
+all: topology bulkint iso
+
+clean:
+ rm -f $(wildcard *.rel *.lst *.sym *.*.asm)
+ $(MAKE) -f Makefile.topology clean
+
+list:
+ cycfx2prog --list
+
+dscr.topology.asm: dscr.asm
+ $(CPP) -DTOPOLOGY dscr.asm | grep -v "^#" > dscr.topology.asm
+
+dscr.bulkint.asm: dscr.asm
+ $(CPP) -DBULKINT dscr.asm | grep -v "^#" > dscr.bulkint.asm
+
+dscr.iso.asm: dscr.asm
+ $(CPP) -DISO dscr.asm | grep -v "^#" > dscr.iso.asm
+
+program-%:
+ $(MAKE) $(patsubst program-%,%,$@)
+ cycfx2prog $(OPT_D) prg:build/$(patsubst program-%,%,$@).ihx run
+
+topology: dscr.topology.asm
+ $(MAKE) -f Makefile.topology
+
+bulkint: dscr.bulkint.asm
+ $(MAKE) -f Makefile.bulkint
+
+iso: dscr.iso.asm
+ $(MAKE) -f Makefile.iso
View
9 tck/images/Makefile.bulkint
@@ -0,0 +1,9 @@
+BASENAME = bulkint
+SOURCES=main.c
+A51_SOURCES=dscr.bulkint.asm
+PID=0x1004
+
+include Makefile.local
+include $(FX2LIBDIR)/lib/fx2.mk
+
+INT2JT=
View
9 tck/images/Makefile.iso
@@ -0,0 +1,9 @@
+BASENAME = iso
+SOURCES=main.c
+A51_SOURCES=dscr.iso.asm
+PID=0x1004
+
+include Makefile.local
+include $(FX2LIBDIR)/lib/fx2.mk
+
+INT2JT=
View
2 tck/images/Makefile.local
@@ -0,0 +1,2 @@
+FX2LIBDIR=/Users/trygvis/dev/com.github/mulicheng/fx2lib
+PATH:=/Users/trygvis/src/cycfx2prog-0.47:$(PATH)
View
9 tck/images/Makefile.topology
@@ -0,0 +1,9 @@
+BASENAME = topology
+SOURCES=main.c
+A51_SOURCES=dscr.topology.asm
+PID=0x1004
+
+include Makefile.local
+include $(FX2LIBDIR)/lib/fx2.mk
+
+INT2JT=
View
225 tck/images/dscr.asm
@@ -0,0 +1,225 @@
+; Copyright (C) 2009 Ubixum, Inc.
+;
+; This library is free software; you can redistribute it and/or
+; modify it under the terms of the GNU Lesser General Public
+; License as published by the Free Software Foundation; either
+; version 2.1 of the License, or (at your option) any later version.
+;
+; This library 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
+; Lesser General Public License for more details.
+;
+; You should have received a copy of the GNU Lesser General Public
+; License along with this library; if not, write to the Free Software
+; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+; this is a the default
+; full speed and high speed
+; descriptors found in the TRM
+; change however you want but leave
+; the descriptor pointers so the setupdat.c file works right
+
+
+.module DEV_DSCR
+
+; descriptor types
+; same as setupdat.h
+DSCR_DEVICE_TYPE=1
+DSCR_CONFIG_TYPE=2
+DSCR_STRING_TYPE=3
+DSCR_INTERFACE_TYPE=4
+DSCR_ENDPOINT_TYPE=5
+DSCR_DEVQUAL_TYPE=6
+
+; for the repeating interfaces
+DSCR_INTERFACE_LEN=9
+DSCR_ENDPOINT_LEN=7
+
+; endpoint types
+ENDPOINT_TYPE_CONTROL=0
+ENDPOINT_TYPE_ISO=1
+ENDPOINT_TYPE_BULK=2
+ENDPOINT_TYPE_INT=3
+
+ .globl _dev_dscr, _dev_qual_dscr, _highspd_dscr, _fullspd_dscr, _dev_strings, _dev_strings_end
+; These need to be in code memory. If
+; they aren't you'll have to manully copy them somewhere
+; in code memory otherwise SUDPTRH:L don't work right
+ .area DSCR_AREA (CODE)
+
+_dev_dscr:
+ .db dev_dscr_end-_dev_dscr ; len
+ .db DSCR_DEVICE_TYPE ; type
+ .dw 0x0002 ; usb 2.0
+ .db 0xff ; class (vendor specific)
+ .db 0xff ; subclass (vendor specific)
+ .db 0xff ; protocol (vendor specific)
+ .db 64 ; packet size (ep0)
+ .dw 0x4705 ; vendor id
+ .dw 0x01ff ; product id
+ .dw 0x0100 ; version id
+ .db 2 ; manufacturure str idx
+ .db 1 ; product str idx
+ .db 0 ; serial str idx
+ .db 1 ; n configurations
+dev_dscr_end:
+
+_dev_qual_dscr:
+ .db dev_qualdscr_end-_dev_qual_dscr
+ .db DSCR_DEVQUAL_TYPE
+ .dw 0x0002 ; usb 2.0
+ .db 0xff
+ .db 0xff
+ .db 0xff
+ .db 64 ; max packet
+ .db 1 ; n configs
+ .db 0 ; extra reserved byte
+dev_qualdscr_end:
+
+_highspd_dscr:
+ .db highspd_dscr_end-_highspd_dscr ; dscr len ;; Descriptor length
+ .db DSCR_CONFIG_TYPE
+ ; can't use .dw because byte order is different
+ .db (highspd_dscr_realend-_highspd_dscr) % 256 ; total length of config lsb
+ .db (highspd_dscr_realend-_highspd_dscr) / 256 ; total length of config msb
+ .db 1 ; n interfaces
+ .db 1 ; config number
+ .db 0 ; config string
+ .db 0x80 ; attrs = bus powered, no wakeup
+ .db 0x32 ; max power = 100ma
+highspd_dscr_end:
+
+; all the interfaces next
+; NOTE the default TRM actually has more alt interfaces
+; but you can add them back in if you need them.
+; here, we just use the default alt setting 1 from the trm
+ .db DSCR_INTERFACE_LEN
+ .db DSCR_INTERFACE_TYPE
+ .db 0 ; index
+ .db 0 ; alt setting idx
+ .db 2 ; n endpoints
+ .db 0xff ; class
+ .db 0xff
+ .db 0xff
+ .db 3 ; string index
+
+; endpoint 2 out
+ .db DSCR_ENDPOINT_LEN
+ .db DSCR_ENDPOINT_TYPE
+ .db 0x02 ; ep2 dir=OUT and address
+ .db ENDPOINT_TYPE_BULK ; type
+ .db 0x00 ; max packet LSB
+ .db 0x02 ; max packet size=512 bytes
+ .db 0x00 ; polling interval
+
+; endpoint 6 in
+ .db DSCR_ENDPOINT_LEN
+ .db DSCR_ENDPOINT_TYPE
+ .db 0x86 ; ep6 dir=in and address
+ .db ENDPOINT_TYPE_BULK ; type
+ .db 0x00 ; max packet LSB
+ .db 0x02 ; max packet size=512 bytes
+ .db 0x00 ; polling interval
+
+highspd_dscr_realend:
+
+ .even
+_fullspd_dscr:
+ .db fullspd_dscr_end-_fullspd_dscr ; dscr len
+ .db DSCR_CONFIG_TYPE
+ ; can't use .dw because byte order is different
+ .db (fullspd_dscr_realend-_fullspd_dscr) % 256 ; total length of config lsb
+ .db (fullspd_dscr_realend-_fullspd_dscr) / 256 ; total length of config msb
+ .db 1 ; n interfaces
+ .db 1 ; config number
+ .db 0 ; config string
+ .db 0x80 ; attrs = bus powered, no wakeup
+ .db 0x32 ; max power = 100ma
+fullspd_dscr_end:
+
+; all the interfaces next
+; NOTE the default TRM actually has more alt interfaces
+; but you can add them back in if you need them.
+; here, we just use the default alt setting 1 from the trm
+ .db DSCR_INTERFACE_LEN
+ .db DSCR_INTERFACE_TYPE
+ .db 0 ; index
+ .db 0 ; alt setting idx
+ .db 2 ; n endpoints
+ .db 0xff ; class
+ .db 0xff
+ .db 0xff
+ .db 3 ; string index
+
+; endpoint 2 out
+ .db DSCR_ENDPOINT_LEN
+ .db DSCR_ENDPOINT_TYPE
+ .db 0x02 ; ep2 dir=OUT and address
+ .db ENDPOINT_TYPE_BULK ; type
+ .db 0x40 ; max packet LSB
+ .db 0x00 ; max packet size=64 bytes
+ .db 0x00 ; polling interval
+
+; endpoint 6 in
+ .db DSCR_ENDPOINT_LEN
+ .db DSCR_ENDPOINT_TYPE
+ .db 0x86 ; ep6 dir=in and address
+ .db ENDPOINT_TYPE_BULK ; type
+ .db 0x40 ; max packet LSB
+ .db 0x00 ; max packet size=64 bytes
+ .db 0x00 ; polling interval
+
+fullspd_dscr_realend:
+
+.even
+_dev_strings:
+; sample string
+_string0:
+ .db string0end-_string0 ; len
+ .db DSCR_STRING_TYPE
+ .db 0x09, 0x04 ; who knows
+string0end:
+; add more strings here
+
+_string1:
+ .db string1end-_string1
+ .db DSCR_STRING_TYPE
+ .ascii 'H'
+ .db 0
+ .ascii 'i'
+ .db 0
+string1end:
+
+_string2:
+ .db string2end-_string2
+ .db DSCR_STRING_TYPE
+ .ascii 'T'
+ .db 0
+ .ascii 'h'
+ .db 0
+ .ascii 'e'
+ .db 0
+ .ascii 'r'
+ .db 0
+ .ascii 'e'
+ .db 0
+string2end:
+
+_string3:
+ .db string3end-_string3
+ .db DSCR_STRING_TYPE
+ .ascii 'i'
+ .db 0
+ .ascii 'F'
+ .db 0
+ .ascii 'a'
+ .db 0
+ .ascii 'c'
+ .db 0
+ .ascii 'e'
+ .db 0
+string3end:
+
+_dev_strings_end:
+ .dw 0x0000 ; just in case someone passes an index higher than the end to the firmware
View
223 tck/images/main.c
@@ -0,0 +1,223 @@
+/**
+ * Copyright (C) 2009 Ubixum, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ **/
+#include <stdio.h>
+
+#include <fx2regs.h>
+#include <fx2macros.h>
+#include <serial.h>
+#include <delay.h>
+#include <autovector.h>
+#include <lights.h>
+#include <setupdat.h>
+#include <eputils.h>
+
+
+#define SYNCDELAY() SYNCDELAY4
+#define REARMVAL 0x80
+#define REARM() EP2BCL=REARMVAL
+
+
+
+volatile WORD bytes;
+volatile bit gotbuf;
+volatile BYTE icount;
+volatile bit got_sud;
+DWORD lcount;
+bit on;
+
+void main() {
+
+ REVCTL=0; // not using advanced endpoint controls
+
+ d2off();
+ on=0;
+ lcount=0;
+ got_sud=FALSE;
+ icount=0;
+ gotbuf=FALSE;
+ bytes=0;
+
+ // renumerate
+ RENUMERATE_UNCOND();
+
+
+ SETCPUFREQ(CLK_48M);
+ SETIF48MHZ();
+ sio0_init(57600);
+
+
+ //USE_USB_INTS();
+ //ENABLE_SUDAV();
+ //ENABLE_SOF();
+ //ENABLE_HISPEED();
+ //ENABLE_USBRESET();
+
+
+ // only valid endpoints are 2/6
+ EP2CFG = 0xA2; // 10100010
+ SYNCDELAY();
+ EP6CFG = 0xE2; // 11100010
+ SYNCDELAY();
+ EP1INCFG &= ~bmVALID;
+ SYNCDELAY();
+ EP1OUTCFG &= ~bmVALID;
+ SYNCDELAY();
+ EP4CFG &= ~bmVALID;
+ SYNCDELAY();
+ EP8CFG &= ~bmVALID;
+ SYNCDELAY();
+
+
+ // arm ep2
+ EP2BCL = 0x80; // write once
+ SYNCDELAY();
+ EP2BCL = 0x80; // do it again
+
+
+ // make it so we enumberate
+
+
+ EA=1; // global interrupt enable
+ printf ( "Done initializing stuff\n" );
+
+
+ d3off();
+
+ while(TRUE) {
+
+ if ( got_sud ) {
+ printf ( "Handle setupdata\n" );
+ handle_setupdata();
+ got_sud=FALSE;
+ }
+
+ if ( !(EP2468STAT & bmEP2EMPTY) ) {
+ printf ( "ep2 out received data\n" );
+ if ( !(EP2468STAT & bmEP6FULL) ) { // wait for at least one empty in buffer
+ WORD i;
+ printf ( "Sending data to ep6 in\n");
+
+ bytes = MAKEWORD(EP2BCH,EP2BCL);
+
+ for (i=0;i<bytes;++i) EP6FIFOBUF[i] = EP2FIFOBUF[i];
+
+ // can copy whole string w/ autoptr instead.
+ // or copy directly from one buf to another
+
+ // ARM ep6 out
+ EP6BCH=MSB(bytes);
+ SYNCDELAY();
+ EP6BCL=LSB(bytes);
+
+ REARM(); // ep2
+ //printf ( "Re-Armed ep2\n" );
+
+ }
+ }
+ }
+
+}
+
+// copied routines from setupdat.h
+
+// value (low byte) = ep
+#define VC_EPSTAT 0xB1
+
+BOOL handle_vendorcommand(BYTE cmd) {
+
+ switch ( cmd ) {
+
+ case VC_EPSTAT:
+ {
+ xdata BYTE* pep= ep_addr(SETUPDAT[2]);
+ printf ( "ep %02x\n" , *pep );
+ if (pep) {
+ EP0BUF[0] = *pep;
+ EP0BCH=0;
+ EP0BCL=1;
+ return TRUE;
+ }
+ }
+ default:
+ printf ( "Need to implement vendor command: %02x\n", cmd );
+ }
+ return FALSE;
+}
+
+// this firmware only supports 0,0
+BOOL handle_get_interface(BYTE ifc, BYTE* alt_ifc) {
+ printf ( "Get Interface\n" );
+ if (ifc==0) {*alt_ifc=0; return TRUE;} else { return FALSE;}
+}
+BOOL handle_set_interface(BYTE ifc, BYTE alt_ifc) {
+ printf ( "Set interface %d to alt: %d\n" , ifc, alt_ifc );
+
+ if (ifc==0&&alt_ifc==0) {
+ // SEE TRM 2.3.7
+ // reset toggles
+ RESETTOGGLE(0x02);
+ RESETTOGGLE(0x86);
+ // restore endpoints to default condition
+ RESETFIFO(0x02);
+ EP2BCL=0x80;
+ SYNCDELAY();
+ EP2BCL=0X80;
+ SYNCDELAY();
+ RESETFIFO(0x86);
+ return TRUE;
+ } else
+ return FALSE;
+}
+
+// get/set configuration
+BYTE handle_get_configuration() {
+ return 1;
+ }
+BOOL handle_set_configuration(BYTE cfg) {
+ return cfg==1 ? TRUE : FALSE; // we only handle cfg 1
+}
+
+
+// copied usb jt routines from usbjt.h
+void sudav_isr() interrupt SUDAV_ISR {
+
+ got_sud=TRUE;
+ CLEAR_SUDAV();
+}
+
+bit on5;
+xdata WORD sofct=0;
+void sof_isr () interrupt SOF_ISR using 1 {
+ ++sofct;
+ if(sofct==8000) { // about 8000 sof interrupts per second at high speed
+ on5=!on5;
+ if (on5) {d5on();} else {d5off();}
+ sofct=0;
+ }
+ CLEAR_SOF();
+}
+
+void usbreset_isr() interrupt USBRESET_ISR {
+ handle_hispeed(FALSE);
+ CLEAR_USBRESET();
+}
+void hispeed_isr() interrupt HISPEED_ISR {
+ handle_hispeed(TRUE);
+ CLEAR_HISPEED();
+}
+

0 comments on commit 33bfdd9

Please sign in to comment.