From 69fb8e42d5e8f1a9404a84da32cae620186f12af Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Tue, 31 Jul 2012 15:43:52 +0100 Subject: [PATCH] serial string removal and dfu changes for su1 --- module_dfu/README | 2 + module_dfu/host/xmos_dfu_osx/Makefile.OSX | 2 + .../host/xmos_dfu_osx/libusb-1.0.0.dylib | Bin 0 -> 64976 bytes module_dfu/host/xmos_dfu_osx/libusb.h | 1233 +++++++++++++++++ module_dfu/host/xmos_dfu_osx/setup.sh | 1 + module_dfu/host/xmos_dfu_osx/testdfu.sh | 45 + module_dfu/host/xmos_dfu_osx/xmosdfu.cpp | 415 ++++++ module_dfu/src/dfu.h | 4 +- module_dfu/src/dfu.xc | 86 +- module_usb_aud_shared/devicedefines.h | 5 - .../endpoint0/descriptors_2.h | 15 +- module_usb_aud_shared/endpoint0/endpoint0.xc | 39 + module_usb_aud_shared/reboot.xc | 55 + 13 files changed, 1848 insertions(+), 54 deletions(-) create mode 100644 module_dfu/host/xmos_dfu_osx/Makefile.OSX create mode 100755 module_dfu/host/xmos_dfu_osx/libusb-1.0.0.dylib create mode 100755 module_dfu/host/xmos_dfu_osx/libusb.h create mode 100644 module_dfu/host/xmos_dfu_osx/setup.sh create mode 100755 module_dfu/host/xmos_dfu_osx/testdfu.sh create mode 100755 module_dfu/host/xmos_dfu_osx/xmosdfu.cpp diff --git a/module_dfu/README b/module_dfu/README index 248e6492..1a762260 100644 --- a/module_dfu/README +++ b/module_dfu/README @@ -1 +1,3 @@ Code providing firmware upgrade over USB. + +./host provides an example of a host application for DFU. This is written and tested for OSX. LibUSB is used to aid cross-platform porting. diff --git a/module_dfu/host/xmos_dfu_osx/Makefile.OSX b/module_dfu/host/xmos_dfu_osx/Makefile.OSX new file mode 100644 index 00000000..fa957396 --- /dev/null +++ b/module_dfu/host/xmos_dfu_osx/Makefile.OSX @@ -0,0 +1,2 @@ +all: + g++ -g -o xmosdfu xmosdfu.cpp -I. -IOSX libusb-1.0.0.dylib -m32 diff --git a/module_dfu/host/xmos_dfu_osx/libusb-1.0.0.dylib b/module_dfu/host/xmos_dfu_osx/libusb-1.0.0.dylib new file mode 100755 index 0000000000000000000000000000000000000000..d8e65b373ff4523784a390410edcc4a93fc84c97 GIT binary patch literal 64976 zcmeFa4R}=5wLg4j7{Z8=2^tYC!k|&1QcW-d5zr7b2`GVp4rr~0kPpcHD z66JUt4Mkg9wWY0XwN;B%fm+mnn1E7E5tUZds3;RdZEPtb^_u_hw?AgiOi=HA@B2Q_ z`#vv$le5k~Yp=cbT5GSp_Q%=qO9Ap^A09+}!PQsNv&@ftzG{XhB4OdCY)q!iS z2H^Z@RS&o`Ke8BZl~hs^s%Q+U2i%hL7Y{Xz?=3bA-aTU+jVd9T z#-l3@qX7AN*X0t`36uXj@vEdHf7;d46d~Tods_Ui>(4syr=+C3G*l{K`P@H$HD7>^ z&J)L$5NIr`E{~@s^H7bvUcBbr$#Xmh`6#QcX^0ClnMM=x-h&Lhe>ERvl}(@0-y z7=F;;{j2#{*wEl$ESW|&@}{cyP8tw>?1yk0u9A`&Ma8q{#;s{R64P+0J9WWJ(5V3a;U}WIBJlj0?jJ^%qvxmX%gt zSY5S{SGZx}cd{OXVBwy*u*u8!t{?IPh;JKm757ud<$`ci-;~;}bkQ z^jE_eceY`ih%~aopQT9Wl@0i}xL=O@p*Q67J$ofDJ8)l$^v>4}V+QVRxC2$x!7LKTZIoLRN7zO;VXg$4Dciz}Aa*5A}{;f&c= zR)sF8)Cm{PgCeV7)E7>ZuLR9SPMRn01I-_N9nH&Y>njRs!!>B6Aa!iwi8!E7-YJVX z?@m2P4cu5(R?=`mR!siMc|5LKP|&)Qd1Tcu$ctqH#_^xy5;!h_;}SS7f#VW5E`j3` zI4*(X5;!h_|9?mz%4%NIx8b*#m#~{oTV)u1T{6vX8YG@t6Mll$hx5#X>2}y_WoJaU z-VOYMaRl1{TD|7>^c!}*;2V{17?t8T@Xdo`tnd-$Sn-8@sa@d7>1Y^Z2U0ChM)a{h z{G?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Go};r=bL0`e5UWAstuNOOa|_txZ{EccWj3cIphO8fwBx zpIS(WQM-2rk3uH_cl_c!0c#xfPozuuy*eS|vtmfB@Jc9oika?s!+htLI%!s0 zyPD>`c4AXwy}pq4SuvIjXn3+sps!30RM$qs!m{i+(>1n|2`Fm#FD*yxP*%)2Aiv2Eepo1OqmDjcy>`3*xx*?U!m~ z{CCcTS`+7WIbKS@pJJY{AIy~gag`n0y*yVd!8UY`r5;-Lb*K8W5v}$K<*f^&ER3|8 zpP~sgIZ58o5c>3X_+~d8cQew)p=s5EEGiekqYsLOoFW~#rWy}eb;{J)n!0CtpjWLu zFuATlP$l!f+72dB?fmWVjo5hgFyC%(sps(R?U*PX;YjE|JSMX9=CwyV#M24}!W{@= Iw^ + * Copyright (c) 2001 Johannes Erdfelt + * + * 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 + */ + +#ifndef __LIBUSB_H__ +#define __LIBUSB_H__ + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** \def libusb_cpu_to_le16 + * \ingroup misc + * Convert a 16-bit value from host-endian to little-endian format. On + * little endian systems, this function does nothing. On big endian systems, + * the bytes are swapped. + * \param x the host-endian value to convert + * \returns the value in little-endian byte order + */ +#define libusb_cpu_to_le16(x) ({ \ + union { \ + uint8_t b8[2]; \ + uint16_t b16; \ + } _tmp; \ + uint16_t _tmp2 = (uint16_t)(x); \ + _tmp.b8[1] = _tmp2 >> 8; \ + _tmp.b8[0] = _tmp2 & 0xff; \ + _tmp.b16; \ +}) + +/** \def libusb_le16_to_cpu + * \ingroup misc + * Convert a 16-bit value from little-endian to host-endian format. On + * little endian systems, this function does nothing. On big endian systems, + * the bytes are swapped. + * \param x the little-endian value to convert + * \returns the value in host-endian byte order + */ +#define libusb_le16_to_cpu libusb_cpu_to_le16 + +/* standard USB stuff */ + +/** \ingroup desc + * Device and/or Interface Class codes */ +enum libusb_class_code { + /** In the context of a \ref libusb_device_descriptor "device descriptor", + * this bDeviceClass value indicates that each interface specifies its + * own class information and all interfaces operate independently. + */ + LIBUSB_CLASS_PER_INTERFACE = 0, + + /** Audio class */ + LIBUSB_CLASS_AUDIO = 1, + + /** Communications class */ + LIBUSB_CLASS_COMM = 2, + + /** Human Interface Device class */ + LIBUSB_CLASS_HID = 3, + + /** Printer dclass */ + LIBUSB_CLASS_PRINTER = 7, + + /** Picture transfer protocol class */ + LIBUSB_CLASS_PTP = 6, + + /** Mass storage class */ + LIBUSB_CLASS_MASS_STORAGE = 8, + + /** Hub class */ + LIBUSB_CLASS_HUB = 9, + + /** Data class */ + LIBUSB_CLASS_DATA = 10, + + /** Class is vendor-specific */ + LIBUSB_CLASS_VENDOR_SPEC = 0xff +}; + +/** \ingroup desc + * Descriptor types as defined by the USB specification. */ +enum libusb_descriptor_type { + /** Device descriptor. See libusb_device_descriptor. */ + LIBUSB_DT_DEVICE = 0x01, + + /** Configuration descriptor. See libusb_config_descriptor. */ + LIBUSB_DT_CONFIG = 0x02, + + /** String descriptor */ + LIBUSB_DT_STRING = 0x03, + + /** Interface descriptor. See libusb_interface_descriptor. */ + LIBUSB_DT_INTERFACE = 0x04, + + /** Endpoint descriptor. See libusb_endpoint_descriptor. */ + LIBUSB_DT_ENDPOINT = 0x05, + + /** HID descriptor */ + LIBUSB_DT_HID = 0x21, + + /** HID report descriptor */ + LIBUSB_DT_REPORT = 0x22, + + /** Physical descriptor */ + LIBUSB_DT_PHYSICAL = 0x23, + + /** Hub descriptor */ + LIBUSB_DT_HUB = 0x29 +}; + +/* Descriptor sizes per descriptor type */ +#define LIBUSB_DT_DEVICE_SIZE 18 +#define LIBUSB_DT_CONFIG_SIZE 9 +#define LIBUSB_DT_INTERFACE_SIZE 9 +#define LIBUSB_DT_ENDPOINT_SIZE 7 +#define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */ +#define LIBUSB_DT_HUB_NONVAR_SIZE 7 + +#define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */ +#define LIBUSB_ENDPOINT_DIR_MASK 0x80 + +/** \ingroup desc + * Endpoint direction. Values for bit 7 of the + * \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme. + */ +enum libusb_endpoint_direction { + /** In: device-to-host */ + LIBUSB_ENDPOINT_IN = 0x80, + + /** Out: host-to-device */ + LIBUSB_ENDPOINT_OUT = 0x00 +}; + +#define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */ + +/** \ingroup desc + * Endpoint transfer type. Values for bits 0:1 of the + * \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field. + */ +enum libusb_transfer_type { + /** Control endpoint */ + LIBUSB_TRANSFER_TYPE_CONTROL = 0, + + /** Isochronous endpoint */ + LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1, + + /** Bulk endpoint */ + LIBUSB_TRANSFER_TYPE_BULK = 2, + + /** Interrupt endpoint */ + LIBUSB_TRANSFER_TYPE_INTERRUPT = 3 +}; + +/** \ingroup misc + * Standard requests, as defined in table 9-3 of the USB2 specifications */ +enum libusb_standard_request { + /** Request status of the specific recipient */ + LIBUSB_REQUEST_GET_STATUS = 0x00, + + /** Clear or disable a specific feature */ + LIBUSB_REQUEST_CLEAR_FEATURE = 0x01, + + /* 0x02 is reserved */ + + /** Set or enable a specific feature */ + LIBUSB_REQUEST_SET_FEATURE = 0x03, + + /* 0x04 is reserved */ + + /** Set device address for all future accesses */ + LIBUSB_REQUEST_SET_ADDRESS = 0x05, + + /** Get the specified descriptor */ + LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06, + + /** Used to update existing descriptors or add new descriptors */ + LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07, + + /** Get the current device configuration value */ + LIBUSB_REQUEST_GET_CONFIGURATION = 0x08, + + /** Set device configuration */ + LIBUSB_REQUEST_SET_CONFIGURATION = 0x09, + + /** Return the selected alternate setting for the specified interface */ + LIBUSB_REQUEST_GET_INTERFACE = 0x0A, + + /** Select an alternate interface for the specified interface */ + LIBUSB_REQUEST_SET_INTERFACE = 0x0B, + + /** Set then report an endpoint's synchronization frame */ + LIBUSB_REQUEST_SYNCH_FRAME = 0x0C +}; + +/** \ingroup misc + * Request type bits of the + * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control + * transfers. */ +enum libusb_request_type { + /** Standard */ + LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5), + + /** Class */ + LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5), + + /** Vendor */ + LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5), + + /** Reserved */ + LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5) +}; + +/** \ingroup misc + * Recipient bits of the + * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control + * transfers. Values 4 through 31 are reserved. */ +enum libusb_request_recipient { + /** Device */ + LIBUSB_RECIPIENT_DEVICE = 0x00, + + /** Interface */ + LIBUSB_RECIPIENT_INTERFACE = 0x01, + + /** Endpoint */ + LIBUSB_RECIPIENT_ENDPOINT = 0x02, + + /** Other */ + LIBUSB_RECIPIENT_OTHER = 0x03 +}; + +#define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C + +/** \ingroup desc + * Synchronization type for isochronous endpoints. Values for bits 2:3 of the + * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in + * libusb_endpoint_descriptor. + */ +enum libusb_iso_sync_type { + /** No synchronization */ + LIBUSB_ISO_SYNC_TYPE_NONE = 0, + + /** Asynchronous */ + LIBUSB_ISO_SYNC_TYPE_ASYNC = 1, + + /** Adaptive */ + LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2, + + /** Synchronous */ + LIBUSB_ISO_SYNC_TYPE_SYNC = 3 +}; + +#define LIBUSB_ISO_USAGE_TYPE_MASK 0x30 + +/** \ingroup desc + * Usage type for isochronous endpoints. Values for bits 4:5 of the + * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in + * libusb_endpoint_descriptor. + */ +enum libusb_iso_usage_type { + /** Data endpoint */ + LIBUSB_ISO_USAGE_TYPE_DATA = 0, + + /** Feedback endpoint */ + LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1, + + /** Implicit feedback Data endpoint */ + LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2 +}; + +/** \ingroup desc + * A structure representing the standard USB device descriptor. This + * descriptor is documented in section 9.6.1 of the USB 2.0 specification. + * All multiple-byte fields are represented in host-endian format. + */ +struct libusb_device_descriptor { + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE LIBUSB_DT_DEVICE in this + * context. */ + uint8_t bDescriptorType; + + /** USB specification release number in binary-coded decimal. A value of + * 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */ + uint16_t bcdUSB; + + /** USB-IF class code for the device. See \ref libusb_class_code. */ + uint8_t bDeviceClass; + + /** USB-IF subclass code for the device, qualified by the bDeviceClass + * value */ + uint8_t bDeviceSubClass; + + /** USB-IF protocol code for the device, qualified by the bDeviceClass and + * bDeviceSubClass values */ + uint8_t bDeviceProtocol; + + /** Maximum packet size for endpoint 0 */ + uint8_t bMaxPacketSize0; + + /** USB-IF vendor ID */ + uint16_t idVendor; + + /** USB-IF product ID */ + uint16_t idProduct; + + /** Device release number in binary-coded decimal */ + uint16_t bcdDevice; + + /** Index of string descriptor describing manufacturer */ + uint8_t iManufacturer; + + /** Index of string descriptor describing product */ + uint8_t iProduct; + + /** Index of string descriptor containing device serial number */ + uint8_t iSerialNumber; + + /** Number of possible configurations */ + uint8_t bNumConfigurations; +}; + +/** \ingroup desc + * A structure representing the standard USB endpoint descriptor. This + * descriptor is documented in section 9.6.3 of the USB 2.0 specification. + * All multiple-byte fields are represented in host-endian format. + */ +struct libusb_endpoint_descriptor { + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_ENDPOINT LIBUSB_DT_ENDPOINT in + * this context. */ + uint8_t bDescriptorType; + + /** The address of the endpoint described by this descriptor. Bits 0:3 are + * the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction, + * see \ref libusb_endpoint_direction. + */ + uint8_t bEndpointAddress; + + /** Attributes which apply to the endpoint when it is configured using + * the bConfigurationValue. Bits 0:1 determine the transfer type and + * correspond to \ref libusb_transfer_type. Bits 2:3 are only used for + * isochronous endpoints and correspond to \ref libusb_iso_sync_type. + * Bits 4:5 are also only used for isochronous endpoints and correspond to + * \ref libusb_iso_usage_type. Bits 6:7 are reserved. + */ + uint8_t bmAttributes; + + /** Maximum packet size this endpoint is capable of sending/receiving. */ + uint16_t wMaxPacketSize; + + /** Interval for polling endpoint for data transfers. */ + uint8_t bInterval; + + /** For audio devices only: the rate at which synchronization feedback + * is provided. */ + uint8_t bRefresh; + + /** For audio devices only: the address if the synch endpoint */ + uint8_t bSynchAddress; + + /** Extra descriptors. If libusb encounters unknown endpoint descriptors, + * it will store them here, should you wish to parse them. */ + const unsigned char *extra; + + /** Length of the extra descriptors, in bytes. */ + int extra_length; +}; + +/** \ingroup desc + * A structure representing the standard USB interface descriptor. This + * descriptor is documented in section 9.6.5 of the USB 2.0 specification. + * All multiple-byte fields are represented in host-endian format. + */ +struct libusb_interface_descriptor { + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE LIBUSB_DT_INTERFACE + * in this context. */ + uint8_t bDescriptorType; + + /** Number of this interface */ + uint8_t bInterfaceNumber; + + /** Value used to select this alternate setting for this interface */ + uint8_t bAlternateSetting; + + /** Number of endpoints used by this interface (excluding the control + * endpoint). */ + uint8_t bNumEndpoints; + + /** USB-IF class code for this interface. See \ref libusb_class_code. */ + uint8_t bInterfaceClass; + + /** USB-IF subclass code for this interface, qualified by the + * bInterfaceClass value */ + uint8_t bInterfaceSubClass; + + /** USB-IF protocol code for this interface, qualified by the + * bInterfaceClass and bInterfaceSubClass values */ + uint8_t bInterfaceProtocol; + + /** Index of string descriptor describing this interface */ + uint8_t iInterface; + + /** Array of endpoint descriptors. This length of this array is determined + * by the bNumEndpoints field. */ + const struct libusb_endpoint_descriptor *endpoint; + + /** Extra descriptors. If libusb encounters unknown interface descriptors, + * it will store them here, should you wish to parse them. */ + const unsigned char *extra; + + /** Length of the extra descriptors, in bytes. */ + int extra_length; +}; + +/** \ingroup desc + * A collection of alternate settings for a particular USB interface. + */ +struct libusb_interface { + /** Array of interface descriptors. The length of this array is determined + * by the num_altsetting field. */ + const struct libusb_interface_descriptor *altsetting; + + /** The number of alternate settings that belong to this interface */ + int num_altsetting; +}; + +/** \ingroup desc + * A structure representing the standard USB configuration descriptor. This + * descriptor is documented in section 9.6.3 of the USB 2.0 specification. + * All multiple-byte fields are represented in host-endian format. + */ +struct libusb_config_descriptor { + /** Size of this descriptor (in bytes) */ + uint8_t bLength; + + /** Descriptor type. Will have value + * \ref libusb_descriptor_type::LIBUSB_DT_CONFIG LIBUSB_DT_CONFIG + * in this context. */ + uint8_t bDescriptorType; + + /** Total length of data returned for this configuration */ + uint16_t wTotalLength; + + /** Number of interfaces supported by this configuration */ + uint8_t bNumInterfaces; + + /** Identifier value for this configuration */ + uint8_t bConfigurationValue; + + /** Index of string descriptor describing this configuration */ + uint8_t iConfiguration; + + /** Configuration characteristics */ + uint8_t bmAttributes; + + /** Maximum power consumption of the USB device from this bus in this + * configuration when the device is fully opreation. Expressed in units + * of 2 mA. */ + uint8_t MaxPower; + + /** Array of interfaces supported by this configuration. The length of + * this array is determined by the bNumInterfaces field. */ + const struct libusb_interface *interface; + + /** Extra descriptors. If libusb encounters unknown configuration + * descriptors, it will store them here, should you wish to parse them. */ + const unsigned char *extra; + + /** Length of the extra descriptors, in bytes. */ + int extra_length; +}; + +/** \ingroup asyncio + * Setup packet for control transfers. */ +struct libusb_control_setup { + /** Request type. Bits 0:4 determine recipient, see + * \ref libusb_request_recipient. Bits 5:6 determine type, see + * \ref libusb_request_type. Bit 7 determines data transfer direction, see + * \ref libusb_endpoint_direction. + */ + uint8_t bmRequestType; + + /** Request. If the type bits of bmRequestType are equal to + * \ref libusb_request_type::LIBUSB_REQUEST_TYPE_STANDARD + * "LIBUSB_REQUEST_TYPE_STANDARD" then this field refers to + * \ref libusb_standard_request. For other cases, use of this field is + * application-specific. */ + uint8_t bRequest; + + /** Value. Varies according to request */ + uint16_t wValue; + + /** Index. Varies according to request, typically used to pass an index + * or offset */ + uint16_t wIndex; + + /** Number of bytes to transfer */ + uint16_t wLength; +}; + +#define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup)) + +/* libusb */ + +struct libusb_context; +struct libusb_device; +struct libusb_device_handle; + +/** \ingroup lib + * Structure representing a libusb session. The concept of individual libusb + * sessions allows for your program to use two libraries (or dynamically + * load two modules) which both independently use libusb. This will prevent + * interference between the individual libusb users - for example + * libusb_set_debug() will not affect the other user of the library, and + * libusb_exit() will not destroy resources that the other user is still + * using. + * + * Sessions are created by libusb_init() and destroyed through libusb_exit(). + * If your application is guaranteed to only ever include a single libusb + * user (i.e. you), you do not have to worry about contexts: pass NULL in + * every function call where a context is required. The default context + * will be used. + * + * For more information, see \ref contexts. + */ +typedef struct libusb_context libusb_context; + +/** \ingroup dev + * Structure representing a USB device detected on the system. This is an + * opaque type for which you are only ever provided with a pointer, usually + * originating from libusb_get_device_list(). + * + * Certain operations can be performed on a device, but in order to do any + * I/O you will have to first obtain a device handle using libusb_open(). + * + * Devices are reference counted with libusb_device_ref() and + * libusb_device_unref(), and are freed when the reference count reaches 0. + * New devices presented by libusb_get_device_list() have a reference count of + * 1, and libusb_free_device_list() can optionally decrease the reference count + * on all devices in the list. libusb_open() adds another reference which is + * later destroyed by libusb_close(). + */ +typedef struct libusb_device libusb_device; + + +/** \ingroup dev + * Structure representing a handle on a USB device. This is an opaque type for + * which you are only ever provided with a pointer, usually originating from + * libusb_open(). + * + * A device handle is used to perform I/O and other operations. When finished + * with a device handle, you should call libusb_close(). + */ +typedef struct libusb_device_handle libusb_device_handle; + +/** \ingroup misc + * Error codes. Most libusb functions return 0 on success or one of these + * codes on failure. + */ +enum libusb_error { + /** Success (no error) */ + LIBUSB_SUCCESS = 0, + + /** Input/output error */ + LIBUSB_ERROR_IO = -1, + + /** Invalid parameter */ + LIBUSB_ERROR_INVALID_PARAM = -2, + + /** Access denied (insufficient permissions) */ + LIBUSB_ERROR_ACCESS = -3, + + /** No such device (it may have been disconnected) */ + LIBUSB_ERROR_NO_DEVICE = -4, + + /** Entity not found */ + LIBUSB_ERROR_NOT_FOUND = -5, + + /** Resource busy */ + LIBUSB_ERROR_BUSY = -6, + + /** Operation timed out */ + LIBUSB_ERROR_TIMEOUT = -7, + + /** Overflow */ + LIBUSB_ERROR_OVERFLOW = -8, + + /** Pipe error */ + LIBUSB_ERROR_PIPE = -9, + + /** System call interrupted (perhaps due to signal) */ + LIBUSB_ERROR_INTERRUPTED = -10, + + /** Insufficient memory */ + LIBUSB_ERROR_NO_MEM = -11, + + /** Operation not supported or unimplemented on this platform */ + LIBUSB_ERROR_NOT_SUPPORTED = -12, + + /** Other error */ + LIBUSB_ERROR_OTHER = -99 +}; + +/** \ingroup asyncio + * Transfer status codes */ +enum libusb_transfer_status { + /** Transfer completed without error. Note that this does not indicate + * that the entire amount of requested data was transferred. */ + LIBUSB_TRANSFER_COMPLETED, + + /** Transfer failed */ + LIBUSB_TRANSFER_ERROR, + + /** Transfer timed out */ + LIBUSB_TRANSFER_TIMED_OUT, + + /** Transfer was cancelled */ + LIBUSB_TRANSFER_CANCELLED, + + /** For bulk/interrupt endpoints: halt condition detected (endpoint + * stalled). For control endpoints: control request not supported. */ + LIBUSB_TRANSFER_STALL, + + /** Device was disconnected */ + LIBUSB_TRANSFER_NO_DEVICE, + + /** Device sent more data than requested */ + LIBUSB_TRANSFER_OVERFLOW +}; + +/** \ingroup asyncio + * libusb_transfer.flags values */ +enum libusb_transfer_flags { + /** Report short frames as errors */ + LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0, + + /** Automatically free() transfer buffer during libusb_free_transfer() */ + LIBUSB_TRANSFER_FREE_BUFFER = 1<<1, + + /** Automatically call libusb_free_transfer() after callback returns. + * If this flag is set, it is illegal to call libusb_free_transfer() + * from your transfer callback, as this will result in a double-free + * when this flag is acted upon. */ + LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2 +}; + +/** \ingroup asyncio + * Isochronous packet descriptor. */ +struct libusb_iso_packet_descriptor { + /** Length of data to request in this packet */ + unsigned int length; + + /** Amount of data that was actually transferred */ + unsigned int actual_length; + + /** Status code for this packet */ + enum libusb_transfer_status status; +}; + +struct libusb_transfer; + +/** \ingroup asyncio + * Asynchronous transfer callback function type. When submitting asynchronous + * transfers, you pass a pointer to a callback function of this type via the + * \ref libusb_transfer::callback "callback" member of the libusb_transfer + * structure. libusb will call this function later, when the transfer has + * completed or failed. See \ref asyncio for more information. + * \param transfer The libusb_transfer struct the callback function is being + * notified about. + */ +typedef void (*libusb_transfer_cb_fn)(struct libusb_transfer *transfer); + +/** \ingroup asyncio + * The generic USB transfer structure. The user populates this structure and + * then submits it in order to request a transfer. After the transfer has + * completed, the library populates the transfer with the results and passes + * it back to the user. + */ +struct libusb_transfer { + /** Handle of the device that this transfer will be submitted to */ + libusb_device_handle *dev_handle; + + /** A bitwise OR combination of \ref libusb_transfer_flags. */ + uint8_t flags; + + /** Address of the endpoint where this transfer will be sent. */ + unsigned char endpoint; + + /** Type of the endpoint from \ref libusb_transfer_type */ + unsigned char type; + + /** Timeout for this transfer in millseconds. A value of 0 indicates no + * timeout. */ + unsigned int timeout; + + /** The status of the transfer. Read-only, and only for use within + * transfer callback function. + * + * If this is an isochronous transfer, this field may read COMPLETED even + * if there were errors in the frames. Use the + * \ref libusb_iso_packet_descriptor::status "status" field in each packet + * to determine if errors occurred. */ + enum libusb_transfer_status status; + + /** Length of the data buffer */ + int length; + + /** Actual length of data that was transferred. Read-only, and only for + * use within transfer callback function. Not valid for isochronous + * endpoint transfers. */ + int actual_length; + + /** Callback function. This will be invoked when the transfer completes, + * fails, or is cancelled. */ + libusb_transfer_cb_fn callback; + + /** User context data to pass to the callback function. */ + void *user_data; + + /** Data buffer */ + unsigned char *buffer; + + /** Number of isochronous packets. Only used for I/O with isochronous + * endpoints. */ + int num_iso_packets; + + /** Isochronous packet descriptors, for isochronous transfers only. */ + struct libusb_iso_packet_descriptor iso_packet_desc +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) + [] /* valid C99 code */ +#else + [0] /* non-standard, but usually working code */ +#endif + ; +}; + +int libusb_init(libusb_context **ctx); +void libusb_exit(libusb_context *ctx); +void libusb_set_debug(libusb_context *ctx, int level); + +ssize_t libusb_get_device_list(libusb_context *ctx, + libusb_device ***list); +void libusb_free_device_list(libusb_device **list, int unref_devices); +libusb_device *libusb_ref_device(libusb_device *dev); +void libusb_unref_device(libusb_device *dev); + +int libusb_get_configuration(libusb_device_handle *dev, int *config); +int libusb_get_device_descriptor(libusb_device *dev, + struct libusb_device_descriptor *desc); +int libusb_get_active_config_descriptor(libusb_device *dev, + struct libusb_config_descriptor **config); +int libusb_get_config_descriptor(libusb_device *dev, uint8_t config_index, + struct libusb_config_descriptor **config); +int libusb_get_config_descriptor_by_value(libusb_device *dev, + uint8_t bConfigurationValue, struct libusb_config_descriptor **config); +void libusb_free_config_descriptor(struct libusb_config_descriptor *config); +uint8_t libusb_get_bus_number(libusb_device *dev); +uint8_t libusb_get_device_address(libusb_device *dev); +int libusb_get_max_packet_size(libusb_device *dev, unsigned char endpoint); + +int libusb_open(libusb_device *dev, libusb_device_handle **handle); +void libusb_close(libusb_device_handle *dev_handle); +libusb_device *libusb_get_device(libusb_device_handle *dev_handle); + +int libusb_set_configuration(libusb_device_handle *dev, int configuration); +int libusb_claim_interface(libusb_device_handle *dev, int iface); +int libusb_release_interface(libusb_device_handle *dev, int iface); + +libusb_device_handle *libusb_open_device_with_vid_pid(libusb_context *ctx, + uint16_t vendor_id, uint16_t product_id); + +int libusb_set_interface_alt_setting(libusb_device_handle *dev, + int interface_number, int alternate_setting); +int libusb_clear_halt(libusb_device_handle *dev, unsigned char endpoint); +int libusb_reset_device(libusb_device_handle *dev); + +int libusb_kernel_driver_active(libusb_device_handle *dev, int interface); +int libusb_detach_kernel_driver(libusb_device_handle *dev, int interface); +int libusb_attach_kernel_driver(libusb_device_handle *dev, int interface); + +/* async I/O */ + +/** \ingroup asyncio + * Get the data section of a control transfer. This convenience function is here + * to remind you that the data does not start until 8 bytes into the actual + * buffer, as the setup packet comes first. + * + * Calling this function only makes sense from a transfer callback function, + * or situations where you have already allocated a suitably sized buffer at + * transfer->buffer. + * + * \param transfer a transfer + * \returns pointer to the first byte of the data section + */ +static inline unsigned char *libusb_control_transfer_get_data( + struct libusb_transfer *transfer) +{ + return transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE; +} + +/** \ingroup asyncio + * Get the control setup packet of a control transfer. This convenience + * function is here to remind you that the control setup occupies the first + * 8 bytes of the transfer data buffer. + * + * Calling this function only makes sense from a transfer callback function, + * or situations where you have already allocated a suitably sized buffer at + * transfer->buffer. + * + * \param transfer a transfer + * \returns a casted pointer to the start of the transfer data buffer + */ +static inline struct libusb_control_setup *libusb_control_transfer_get_setup( + struct libusb_transfer *transfer) +{ + return (struct libusb_control_setup *) transfer->buffer; +} + +/** \ingroup asyncio + * Helper function to populate the setup packet (first 8 bytes of the data + * buffer) for a control transfer. The wIndex, wValue and wLength values should + * be given in host-endian byte order. + * + * \param buffer buffer to output the setup packet into + * \param bmRequestType see the + * \ref libusb_control_setup::bmRequestType "bmRequestType" field of + * \ref libusb_control_setup + * \param bRequest see the + * \ref libusb_control_setup::bRequest "bRequest" field of + * \ref libusb_control_setup + * \param wValue see the + * \ref libusb_control_setup::wValue "wValue" field of + * \ref libusb_control_setup + * \param wIndex see the + * \ref libusb_control_setup::wIndex "wIndex" field of + * \ref libusb_control_setup + * \param wLength see the + * \ref libusb_control_setup::wLength "wLength" field of + * \ref libusb_control_setup + */ +static inline void libusb_fill_control_setup(unsigned char *buffer, + uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, + uint16_t wLength) +{ + struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer; + setup->bmRequestType = bmRequestType; + setup->bRequest = bRequest; + setup->wValue = libusb_cpu_to_le16(wValue); + setup->wIndex = libusb_cpu_to_le16(wIndex); + setup->wLength = libusb_cpu_to_le16(wLength); +} + +struct libusb_transfer *libusb_alloc_transfer(int iso_packets); +int libusb_submit_transfer(struct libusb_transfer *transfer); +int libusb_cancel_transfer(struct libusb_transfer *transfer); +void libusb_free_transfer(struct libusb_transfer *transfer); + +/** \ingroup asyncio + * Helper function to populate the required \ref libusb_transfer fields + * for a control transfer. + * + * If you pass a transfer buffer to this function, the first 8 bytes will + * be interpreted as a control setup packet, and the wLength field will be + * used to automatically populate the \ref libusb_transfer::length "length" + * field of the transfer. Therefore the recommended approach is: + * -# Allocate a suitably sized data buffer (including space for control setup) + * -# Call libusb_fill_control_setup() + * -# If this is a host-to-device transfer with a data stage, put the data + * in place after the setup packet + * -# Call this function + * -# Call libusb_submit_transfer() + * + * It is also legal to pass a NULL buffer to this function, in which case this + * function will not attempt to populate the length field. Remember that you + * must then populate the buffer and length fields later. + * + * \param transfer the transfer to populate + * \param dev_handle handle of the device that will handle the transfer + * \param buffer data buffer. If provided, this function will interpret the + * first 8 bytes as a setup packet and infer the transfer length from that. + * \param callback callback function to be invoked on transfer completion + * \param user_data user data to pass to callback function + * \param timeout timeout for the transfer in milliseconds + */ +static inline void libusb_fill_control_transfer( + struct libusb_transfer *transfer, libusb_device_handle *dev_handle, + unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data, + unsigned int timeout) +{ + struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer; + transfer->dev_handle = dev_handle; + transfer->endpoint = 0; + transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL; + transfer->timeout = timeout; + transfer->buffer = buffer; + if (setup) + transfer->length = LIBUSB_CONTROL_SETUP_SIZE + + libusb_le16_to_cpu(setup->wLength); + transfer->user_data = user_data; + transfer->callback = callback; +} + +/** \ingroup asyncio + * Helper function to populate the required \ref libusb_transfer fields + * for a bulk transfer. + * + * \param transfer the transfer to populate + * \param dev_handle handle of the device that will handle the transfer + * \param endpoint address of the endpoint where this transfer will be sent + * \param buffer data buffer + * \param length length of data buffer + * \param callback callback function to be invoked on transfer completion + * \param user_data user data to pass to callback function + * \param timeout timeout for the transfer in milliseconds + */ +static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer, + libusb_device_handle *dev_handle, unsigned char endpoint, + unsigned char *buffer, int length, libusb_transfer_cb_fn callback, + void *user_data, unsigned int timeout) +{ + transfer->dev_handle = dev_handle; + transfer->endpoint = endpoint; + transfer->type = LIBUSB_TRANSFER_TYPE_BULK; + transfer->timeout = timeout; + transfer->buffer = buffer; + transfer->length = length; + transfer->user_data = user_data; + transfer->callback = callback; +} + +/** \ingroup asyncio + * Helper function to populate the required \ref libusb_transfer fields + * for an interrupt transfer. + * + * \param transfer the transfer to populate + * \param dev_handle handle of the device that will handle the transfer + * \param endpoint address of the endpoint where this transfer will be sent + * \param buffer data buffer + * \param length length of data buffer + * \param callback callback function to be invoked on transfer completion + * \param user_data user data to pass to callback function + * \param timeout timeout for the transfer in milliseconds + */ +static inline void libusb_fill_interrupt_transfer( + struct libusb_transfer *transfer, libusb_device_handle *dev_handle, + unsigned char endpoint, unsigned char *buffer, int length, + libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout) +{ + transfer->dev_handle = dev_handle; + transfer->endpoint = endpoint; + transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT; + transfer->timeout = timeout; + transfer->buffer = buffer; + transfer->length = length; + transfer->user_data = user_data; + transfer->callback = callback; +} + +/** \ingroup asyncio + * Helper function to populate the required \ref libusb_transfer fields + * for an isochronous transfer. + * + * \param transfer the transfer to populate + * \param dev_handle handle of the device that will handle the transfer + * \param endpoint address of the endpoint where this transfer will be sent + * \param buffer data buffer + * \param length length of data buffer + * \param num_iso_packets the number of isochronous packets + * \param callback callback function to be invoked on transfer completion + * \param user_data user data to pass to callback function + * \param timeout timeout for the transfer in milliseconds + */ +static inline void libusb_fill_iso_transfer(struct libusb_transfer *transfer, + libusb_device_handle *dev_handle, unsigned char endpoint, + unsigned char *buffer, int length, int num_iso_packets, + libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout) +{ + transfer->dev_handle = dev_handle; + transfer->endpoint = endpoint; + transfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS; + transfer->timeout = timeout; + transfer->buffer = buffer; + transfer->length = length; + transfer->num_iso_packets = num_iso_packets; + transfer->user_data = user_data; + transfer->callback = callback; +} + +/** \ingroup asyncio + * Convenience function to set the length of all packets in an isochronous + * transfer, based on the num_iso_packets field in the transfer structure. + * + * \param transfer a transfer + * \param length the length to set in each isochronous packet descriptor + * \see libusb_get_max_packet_size() + */ +static inline void libusb_set_iso_packet_lengths( + struct libusb_transfer *transfer, unsigned int length) +{ + int i; + for (i = 0; i < transfer->num_iso_packets; i++) + transfer->iso_packet_desc[i].length = length; +} + +/** \ingroup asyncio + * Convenience function to locate the position of an isochronous packet + * within the buffer of an isochronous transfer. + * + * This is a thorough function which loops through all preceding packets, + * accumulating their lengths to find the position of the specified packet. + * Typically you will assign equal lengths to each packet in the transfer, + * and hence the above method is sub-optimal. You may wish to use + * libusb_get_iso_packet_buffer_simple() instead. + * + * \param transfer a transfer + * \param packet the packet to return the address of + * \returns the base address of the packet buffer inside the transfer buffer, + * or NULL if the packet does not exist. + * \see libusb_get_iso_packet_buffer_simple() + */ +static inline unsigned char *libusb_get_iso_packet_buffer( + struct libusb_transfer *transfer, unsigned int packet) +{ + int i; + size_t offset = 0; + int _packet; + + /* oops..slight bug in the API. packet is an unsigned int, but we use + * signed integers almost everywhere else. range-check and convert to + * signed to avoid compiler warnings. FIXME for libusb-2. */ + if (packet > INT_MAX) + return NULL; + _packet = packet; + + if (_packet >= transfer->num_iso_packets) + return NULL; + + for (i = 0; i < _packet; i++) + offset += transfer->iso_packet_desc[i].length; + + return transfer->buffer + offset; +} + +/** \ingroup asyncio + * Convenience function to locate the position of an isochronous packet + * within the buffer of an isochronous transfer, for transfers where each + * packet is of identical size. + * + * This function relies on the assumption that every packet within the transfer + * is of identical size to the first packet. Calculating the location of + * the packet buffer is then just a simple calculation: + * buffer + (packet_size * packet) + * + * Do not use this function on transfers other than those that have identical + * packet lengths for each packet. + * + * \param transfer a transfer + * \param packet the packet to return the address of + * \returns the base address of the packet buffer inside the transfer buffer, + * or NULL if the packet does not exist. + * \see libusb_get_iso_packet_buffer() + */ +static inline unsigned char *libusb_get_iso_packet_buffer_simple( + struct libusb_transfer *transfer, unsigned int packet) +{ + int _packet; + + /* oops..slight bug in the API. packet is an unsigned int, but we use + * signed integers almost everywhere else. range-check and convert to + * signed to avoid compiler warnings. FIXME for libusb-2. */ + if (packet > INT_MAX) + return NULL; + _packet = packet; + + if (_packet >= transfer->num_iso_packets) + return NULL; + + return transfer->buffer + (transfer->iso_packet_desc[0].length * _packet); +} + +/* sync I/O */ + +int libusb_control_transfer(libusb_device_handle *dev_handle, + uint8_t request_type, uint8_t request, uint16_t value, uint16_t index, + unsigned char *data, uint16_t length, unsigned int timeout); + +int libusb_bulk_transfer(libusb_device_handle *dev_handle, + unsigned char endpoint, unsigned char *data, int length, + int *actual_length, unsigned int timeout); + +int libusb_interrupt_transfer(libusb_device_handle *dev_handle, + unsigned char endpoint, unsigned char *data, int length, + int *actual_length, unsigned int timeout); + +/** \ingroup desc + * Retrieve a descriptor from the default control pipe. + * This is a convenience function which formulates the appropriate control + * message to retrieve the descriptor. + * + * \param dev a device handle + * \param desc_type the descriptor type, see \ref libusb_descriptor_type + * \param desc_index the index of the descriptor to retrieve + * \param data output buffer for descriptor + * \param length size of data buffer + * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure + */ +static inline int libusb_get_descriptor(libusb_device_handle *dev, + uint8_t desc_type, uint8_t desc_index, unsigned char *data, int length) +{ + return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN, + LIBUSB_REQUEST_GET_DESCRIPTOR, (desc_type << 8) | desc_index, 0, data, + length, 1000); +} + +/** \ingroup desc + * Retrieve a descriptor from a device. + * This is a convenience function which formulates the appropriate control + * message to retrieve the descriptor. The string returned is Unicode, as + * detailed in the USB specifications. + * + * \param dev a device handle + * \param desc_index the index of the descriptor to retrieve + * \param langid the language ID for the string descriptor + * \param data output buffer for descriptor + * \param length size of data buffer + * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure + * \see libusb_get_string_descriptor_ascii() + */ +static inline int libusb_get_string_descriptor(libusb_device_handle *dev, + uint8_t desc_index, uint16_t langid, unsigned char *data, int length) +{ + return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN, + LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | desc_index, + langid, data, length, 1000); +} + +int libusb_get_string_descriptor_ascii(libusb_device_handle *dev, + uint8_t index, unsigned char *data, int length); + +/* polling and timeouts */ + +int libusb_try_lock_events(libusb_context *ctx); +void libusb_lock_events(libusb_context *ctx); +void libusb_unlock_events(libusb_context *ctx); +int libusb_event_handling_ok(libusb_context *ctx); +int libusb_event_handler_active(libusb_context *ctx); +void libusb_lock_event_waiters(libusb_context *ctx); +void libusb_unlock_event_waiters(libusb_context *ctx); +int libusb_wait_for_event(libusb_context *ctx, struct timeval *tv); + +int libusb_handle_events_timeout(libusb_context *ctx, struct timeval *tv); +int libusb_handle_events(libusb_context *ctx); +int libusb_handle_events_locked(libusb_context *ctx, struct timeval *tv); +int libusb_get_next_timeout(libusb_context *ctx, struct timeval *tv); + +/** \ingroup poll + * File descriptor for polling + */ +struct libusb_pollfd { + /** Numeric file descriptor */ + int fd; + + /** Event flags to poll for from . POLLIN indicates that you + * should monitor this file descriptor for becoming ready to read from, + * and POLLOUT indicates that you should monitor this file descriptor for + * nonblocking write readiness. */ + short events; +}; + +/** \ingroup poll + * Callback function, invoked when a new file descriptor should be added + * to the set of file descriptors monitored for events. + * \param fd the new file descriptor + * \param events events to monitor for, see \ref libusb_pollfd for a + * description + * \param user_data User data pointer specified in + * libusb_set_pollfd_notifiers() call + * \see libusb_set_pollfd_notifiers() + */ +typedef void (*libusb_pollfd_added_cb)(int fd, short events, void *user_data); + +/** \ingroup poll + * Callback function, invoked when a file descriptor should be removed from + * the set of file descriptors being monitored for events. After returning + * from this callback, do not use that file descriptor again. + * \param fd the file descriptor to stop monitoring + * \param user_data User data pointer specified in + * libusb_set_pollfd_notifiers() call + * \see libusb_set_pollfd_notifiers() + */ +typedef void (*libusb_pollfd_removed_cb)(int fd, void *user_data); + +const struct libusb_pollfd **libusb_get_pollfds(libusb_context *ctx); +void libusb_set_pollfd_notifiers(libusb_context *ctx, + libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb, + void *user_data); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/module_dfu/host/xmos_dfu_osx/setup.sh b/module_dfu/host/xmos_dfu_osx/setup.sh new file mode 100644 index 00000000..cc8bd663 --- /dev/null +++ b/module_dfu/host/xmos_dfu_osx/setup.sh @@ -0,0 +1 @@ +export DYLD_LIBRARY_PATH=$PWD:$DYLD_LIBRARY_PATH diff --git a/module_dfu/host/xmos_dfu_osx/testdfu.sh b/module_dfu/host/xmos_dfu_osx/testdfu.sh new file mode 100755 index 00000000..06c83dba --- /dev/null +++ b/module_dfu/host/xmos_dfu_osx/testdfu.sh @@ -0,0 +1,45 @@ +#! /bin/bash +################################################################################ + +#find out were we are running from so we only exec this programs +PROGDIR=`dirname $0` + +#setup environment +export DYLD_LIBRARY_PATH=$PWD:$DYLD_LIBRARY_PATH + +#check if we were given a binary name, otherwise use the default one +updatebin=testbin +if [ "$1" != "" ]; then + updatebin=$1 +fi + +#basic check for binary +if [ ! -f $updatebin ]; then + echo "FATAL: can't find update binary named $updatebin" + exit 1 +else + using $updatebin +fi + +#------------------------------------------------------------------------------- +for i in 1 2 3 4 5 6 7 8 9 10; do + echo "" + echo DFU test iteration $i + echo --------------------- + echo "" + echo "*** DFU revert to factory ***" + $PROGDIR/xmosdfu --revertfactory + sleep 2 + echo "" + echo "*** DFU download new firmware ***" + $PROGDIR/xmosdfu --download $updatebin + sleep 2 + echo "" + echo "*** DFU upload existing firmware ***" + $PROGDIR/xmosdfu --upload $updatebin + sleep 2 + echo "" +done + +echo DFU Test Complete! + diff --git a/module_dfu/host/xmos_dfu_osx/xmosdfu.cpp b/module_dfu/host/xmos_dfu_osx/xmosdfu.cpp new file mode 100755 index 00000000..dad06fd8 --- /dev/null +++ b/module_dfu/host/xmos_dfu_osx/xmosdfu.cpp @@ -0,0 +1,415 @@ +#include +#include +#include +#include "libusb.h" + +/* the device's vendor and product id */ +#define XMOS_VID 0x20b1 +#define XMOS_L1_AUDIO2_PID 0x0002 +#define XMOS_L1_AUDIO1_PID 0x0003 +#define XMOS_L2_AUDIO2_PID 0x0004 +unsigned int XMOS_DFU_IF = 0; + +#define DFU_REQUEST_TO_DEV 0x21 +#define DFU_REQUEST_FROM_DEV 0xa1 + +// Standard DFU requests +#define DFU_DETACH 0 +#define DFU_DNLOAD 1 +#define DFU_UPLOAD 2 +#define DFU_GETSTATUS 3 +#define DFU_CLRSTATUS 4 +#define DFU_GETSTATE 5 +#define DFU_ABORT 6 + +// XMOS alternate setting requests +#define XMOS_DFU_RESETDEVICE 0xf0 +#define XMOS_DFU_REVERTFACTORY 0xf1 +#define XMOS_DFU_RESETINTODFU 0xf2 +#define XMOS_DFU_RESETFROMDFU 0xf3 +#define XMOS_DFU_SAVESTATE 0xf5 +#define XMOS_DFU_RESTORESTATE 0xf6 + +static libusb_device_handle *devh = NULL; + +static int find_xmos_device(unsigned int id) +{ + libusb_device *dev; + libusb_device **devs; + int i = 0; + int found = 0; + + libusb_get_device_list(NULL, &devs); + + while ((dev = devs[i++]) != NULL) + { + struct libusb_device_descriptor desc; + libusb_get_device_descriptor(dev, &desc); + printf("VID = 0x%x, PID = 0x%x\n", desc.idVendor, desc.idProduct); + if (desc.idVendor == XMOS_VID && + ((desc.idProduct == XMOS_L1_AUDIO1_PID) || + (desc.idProduct == XMOS_L1_AUDIO2_PID) || + (desc.idProduct == XMOS_L2_AUDIO2_PID))) + { + if (found == id) + { + if (libusb_open(dev, &devh) < 0) + { + return -1; + } + else + { + libusb_config_descriptor *config_desc = NULL; + libusb_get_active_config_descriptor(dev, &config_desc); + if (config_desc != NULL) + { + for (int j = 0; j < config_desc->bNumInterfaces; j++) + { + const libusb_interface_descriptor *inter_desc = ((libusb_interface *)&config_desc->interface[j])->altsetting; + if (inter_desc->bInterfaceClass == 0xFE && inter_desc->bInterfaceSubClass == 0x1) + { + XMOS_DFU_IF = j; + } + } + } + else + { + XMOS_DFU_IF = 0; + } + } + break; + } + found++; + } + } + + libusb_free_device_list(devs, 1); + + return devh ? 0 : -1; +} + +int xmos_dfu_resetdevice(void) { + libusb_control_transfer(devh, DFU_REQUEST_TO_DEV, XMOS_DFU_RESETDEVICE, 0, 0, NULL, 0, 0); +} + +int xmos_dfu_revertfactory(void) { + libusb_control_transfer(devh, DFU_REQUEST_TO_DEV, XMOS_DFU_REVERTFACTORY, 0, 0, NULL, 0, 0); +} + +int xmos_dfu_resetintodfu(unsigned int interface) { + libusb_control_transfer(devh, DFU_REQUEST_TO_DEV, XMOS_DFU_RESETINTODFU, 0, interface, NULL, 0, 0); +} + +int xmos_dfu_resetfromdfu(unsigned int interface) { + libusb_control_transfer(devh, DFU_REQUEST_TO_DEV, XMOS_DFU_RESETFROMDFU, 0, interface, NULL, 0, 0); +} + +int dfu_detach(unsigned int interface, unsigned int timeout) { + libusb_control_transfer(devh, DFU_REQUEST_TO_DEV, DFU_DETACH, timeout, interface, NULL, 0, 0); + return 0; +} + +int dfu_getState(unsigned int interface, unsigned char *state) { + libusb_control_transfer(devh, DFU_REQUEST_FROM_DEV, DFU_GETSTATE, 0, interface, state, 1, 0); + return 0; +} + +int dfu_getStatus(unsigned int interface, unsigned char *state, unsigned int *timeout, + unsigned char *nextState, unsigned char *strIndex) { + unsigned int data[2]; + libusb_control_transfer(devh, DFU_REQUEST_FROM_DEV, DFU_GETSTATUS, 0, interface, (unsigned char *)data, 6, 0); + + *state = data[0] & 0xff; + *timeout = (data[0] >> 8) & 0xffffff; + *nextState = data[1] & 0xff; + *strIndex = (data[1] >> 8) & 0xff; + return 0; +} + +int dfu_clrStatus(unsigned int interface) { + libusb_control_transfer(devh, DFU_REQUEST_TO_DEV, DFU_CLRSTATUS, 0, interface, NULL, 0, 0); + return 0; +} + +int dfu_abort(unsigned int interface) { + libusb_control_transfer(devh, DFU_REQUEST_TO_DEV, DFU_ABORT, 0, interface, NULL, 0, 0); + return 0; +} + + +int xmos_dfu_save_state(unsigned int interface) { + libusb_control_transfer(devh, DFU_REQUEST_TO_DEV, XMOS_DFU_SAVESTATE, 0, interface, NULL, 0, 0); + printf("Save state command sent\n"); + return 0; +} + +int xmos_dfu_restore_state(unsigned int interface) { + libusb_control_transfer(devh, DFU_REQUEST_TO_DEV, XMOS_DFU_RESTORESTATE, 0, interface, NULL, 0, 0); + printf("Restore state command sent\n"); + return 0; +} + +int dfu_download(unsigned int interface, unsigned int block_num, unsigned int size, unsigned char *data) { + //printf("... Downloading block number %d size %d\r", block_num, size); + libusb_control_transfer(devh, DFU_REQUEST_TO_DEV, DFU_DNLOAD, block_num, interface, data, size, 0); + return 0; +} + +int dfu_upload(unsigned int interface, unsigned int block_num, unsigned int size, unsigned char*data) { + unsigned int numBytes = 0; + numBytes = libusb_control_transfer(devh, DFU_REQUEST_FROM_DEV, DFU_UPLOAD, block_num, interface, (unsigned char *)data, size, 0); + return numBytes; +} + +int write_dfu_image(char *file) { + int i = 0; + FILE* inFile = NULL; + int image_size = 0; + unsigned int num_blocks = 0; + unsigned int block_size = 64; + unsigned int remainder = 0; + unsigned char block_data[256]; + + unsigned char dfuState = 0; + unsigned char nextDfuState = 0; + unsigned int timeout = 0; + unsigned char strIndex = 0; + unsigned int dfuBlockCount = 0; + + inFile = fopen( file, "rb" ); + if( inFile == NULL ) { + fprintf(stderr,"Error: Failed to open input data file.\n"); + return -1; + } + + /* Discover the size of the image. */ + if( 0 != fseek( inFile, 0, SEEK_END ) ) { + fprintf(stderr,"Error: Failed to discover input data file size.\n"); + return -1; + } + + image_size = (int)ftell( inFile ); + + if( 0 != fseek( inFile, 0, SEEK_SET ) ) { + fprintf(stderr,"Error: Failed to input file pointer.\n"); + return -1; + } + + num_blocks = image_size/block_size; + remainder = image_size - (num_blocks * block_size); + + printf("... Downloading image (%s) to device\n", file); + + dfuBlockCount = 0; + + for (i = 0; i < num_blocks; i++) { + memset(block_data, 0x0, block_size); + fread(block_data, 1, block_size, inFile); + dfu_download(0, dfuBlockCount, block_size, block_data); + dfu_getStatus(0, &dfuState, &timeout, &nextDfuState, &strIndex); + dfuBlockCount++; + } + + if (remainder) { + memset(block_data, 0x0, block_size); + fread(block_data, 1, remainder, inFile); + dfu_download(0, dfuBlockCount, block_size, block_data); + dfu_getStatus(0, &dfuState, &timeout, &nextDfuState, &strIndex); + } + + // 0 length download terminates + dfu_download(0, 0, 0, NULL); + dfu_getStatus(0, &dfuState, &timeout, &nextDfuState, &strIndex); + + printf("... Download complete\n"); + + return 0; +} + +int read_dfu_image(char *file) { + FILE *outFile = NULL; + unsigned int block_count = 0; + unsigned int block_size = 64; + unsigned char block_data[64]; + + outFile = fopen( file, "wb" ); + if( outFile == NULL ) { + fprintf(stderr,"Error: Failed to open output data file.\n"); + return -1; + } + + printf("... Uploading image (%s) from device\n", file); + + while (1) { + unsigned int numBytes = 0; + numBytes = dfu_upload(0, block_count, 64, block_data); + if (numBytes == 0) + break; + fwrite(block_data, 1, block_size, outFile); + block_count++; + } + + fclose(outFile); +} + +int main(int argc, char **argv) { + int r = 1; + unsigned char dfuState = 0; + unsigned char nextDfuState = 0; + unsigned int timeout = 0; + unsigned char strIndex = 0; + + unsigned int download = 0; + unsigned int upload = 0; + unsigned int revert = 0; + unsigned int save = 0; + unsigned int restore = 0; + + char *firmware_filename = NULL; + + if (argc < 2) { + fprintf(stderr, "No options passed to dfu application\n"); + return -1; + } + + if (strcmp(argv[1], "--download") == 0) { + if (argv[2]) { + firmware_filename = argv[2]; + } else { + fprintf(stderr, "No filename specified for download option\n"); + return -1; + } + download = 1; + } else if (strcmp(argv[1], "--upload") == 0) { + if (argv[2]) { + firmware_filename = argv[2]; + } else { + fprintf(stderr, "No filename specified for upload option\n"); + return -1; + } + upload = 1; + } else if (strcmp(argv[1], "--revertfactory") == 0) { + revert = 1; + } + else if(strcmp(argv[1], "--savecustomstate") == 0) + { + save = 1; + } + else if(strcmp(argv[1], "--restorecustomstate") == 0) + { + restore = 1; + } + else { + fprintf(stderr, "Invalid option passed to dfu application\n"); + return -1; + } + + + + r = libusb_init(NULL); + if (r < 0) { + fprintf(stderr, "failed to initialise libusb\n"); + return -1; + } + + r = find_xmos_device(0); + if (r < 0) { + fprintf(stderr, "Could not find/open device\n"); + return -1; + } + + r = libusb_claim_interface(devh, XMOS_DFU_IF); + if (r < 0) { + fprintf(stderr, "Error claiming interface %d %d\n", XMOS_DFU_IF, r); + return -1; + } + printf("XMOS DFU application started - Interface %d claimed\n", XMOS_DFU_IF); + + /* Dont go into DFU mode for save/restore */ + if(save) + { + xmos_dfu_save_state(XMOS_DFU_IF); + } + else if(restore) + { + xmos_dfu_restore_state(XMOS_DFU_IF); + } + else + { + + printf("Detaching device from application mode.\n"); + xmos_dfu_resetintodfu(XMOS_DFU_IF); + + libusb_release_interface(devh, XMOS_DFU_IF); + libusb_close(devh); + + + printf("Waiting for device to restart and enter DFU mode...\n"); + + // Wait for device to enter dfu mode and restart + system("sleep 20"); + + // NOW IN DFU APPLICATION MODE + + r = find_xmos_device(0); + if (r < 0) { + fprintf(stderr, "Could not find/open device\n"); + return -1; + } + + r = libusb_claim_interface(devh, 0); + if (r != 0) + { + fprintf(stderr, "Error claiming interface 0\n"); + + switch(r) + { + case LIBUSB_ERROR_NOT_FOUND: + printf("The requested interface does not exist'n"); + break; + case LIBUSB_ERROR_BUSY: + printf("Another program or driver has claimed the interface\n"); + break; + case LIBUSB_ERROR_NO_DEVICE: + printf("The device has been disconnected\n"); + break; + case LIBUSB_ERROR_ACCESS: + printf("Access denied\n"); + break; + default: + printf("Unknown error code: %d\n", r); + break; + + } + return -1; + } + + printf("... DFU firmware upgrade device opened\n"); + + if (download) { + write_dfu_image(firmware_filename); + xmos_dfu_resetfromdfu(XMOS_DFU_IF); + } else if (upload) { + read_dfu_image(firmware_filename); + xmos_dfu_resetfromdfu(XMOS_DFU_IF); + } else if (revert) { + printf("... Reverting device to factory image\n"); + xmos_dfu_revertfactory(); + // Give device time to revert firmware + system("sleep 2"); + xmos_dfu_resetfromdfu(XMOS_DFU_IF); + } + else{ + xmos_dfu_resetfromdfu(XMOS_DFU_IF); + } + + printf("... Returning device to application mode\n"); +} +// END OF DFU APPLICATION MODE + + libusb_release_interface(devh, 0); + libusb_close(devh); + libusb_exit(NULL); + + return true; +} diff --git a/module_dfu/src/dfu.h b/module_dfu/src/dfu.h index cecb9e36..296ce84a 100644 --- a/module_dfu/src/dfu.h +++ b/module_dfu/src/dfu.h @@ -17,8 +17,8 @@ #endif #ifndef DFU_SERIAL_STR_INDEX -#error DFU_SERIAL_STR_INDEX NOT DEFINED! -//#define DFU_SERIAL_STR_INDEX 0x00 +/* By default no serial string */ +#define DFU_SERIAL_STR_INDEX 0x00 #endif #ifndef DFU_PRODUCT_INDEX diff --git a/module_dfu/src/dfu.xc b/module_dfu/src/dfu.xc index 57a3a15c..c4a3982a 100644 --- a/module_dfu/src/dfu.xc +++ b/module_dfu/src/dfu.xc @@ -272,48 +272,54 @@ static int DFU_Abort(void) { } // Tell the DFU state machine that a USB reset has occured -int DFUReportResetState(chanend ?c_user_cmd) { - unsigned int inDFU = 0; - unsigned int currentTime = 0; +int DFUReportResetState(chanend ?c_user_cmd) +{ + unsigned int inDFU = 0; + unsigned int currentTime = 0; - if (DFU_reset_override == 0x11042011) { - unsigned int cmd_data[16]; - inDFU = 1; - DFU_state = STATE_DFU_IDLE; - return inDFU; - } - - switch(DFU_state) { - case STATE_APP_DETACH: - case STATE_DFU_IDLE: - DFU_state = STATE_DFU_IDLE; - - DFUTimer :> currentTime; - if (currentTime - DFUTimerStart > DFUResetTimeout) { - DFU_state = STATE_APP_IDLE; - //printintln(currentTime - DFUTimerStart); - //printintln(DFUResetTimeout); - inDFU = 0; - } else { + if (DFU_reset_override == 0x11042011) + { + unsigned int cmd_data[16]; inDFU = 1; - } - break; - case STATE_APP_IDLE: - case STATE_DFU_DOWNLOAD_SYNC: - case STATE_DFU_DOWNLOAD_BUSY: - case STATE_DFU_DOWNLOAD_IDLE: - case STATE_DFU_MANIFEST_SYNC: - case STATE_DFU_MANIFEST: - case STATE_DFU_MANIFEST_WAIT_RESET: - case STATE_DFU_UPLOAD_IDLE: - case STATE_DFU_ERROR: - inDFU = 0; - DFU_state = STATE_APP_IDLE; - break; - default: - DFU_state = STATE_DFU_ERROR; - inDFU = 1; - break; + DFU_state = STATE_DFU_IDLE; + return inDFU; + } + + switch(DFU_state) + { + case STATE_APP_DETACH: + case STATE_DFU_IDLE: + DFU_state = STATE_DFU_IDLE; + + DFUTimer :> currentTime; + if (currentTime - DFUTimerStart > DFUResetTimeout) + { + DFU_state = STATE_APP_IDLE; + //printintln(currentTime - DFUTimerStart); + //printintln(DFUResetTimeout); + inDFU = 0; + } + else + { + inDFU = 1; + } + break; + case STATE_APP_IDLE: + case STATE_DFU_DOWNLOAD_SYNC: + case STATE_DFU_DOWNLOAD_BUSY: + case STATE_DFU_DOWNLOAD_IDLE: + case STATE_DFU_MANIFEST_SYNC: + case STATE_DFU_MANIFEST: + case STATE_DFU_MANIFEST_WAIT_RESET: + case STATE_DFU_UPLOAD_IDLE: + case STATE_DFU_ERROR: + inDFU = 0; + DFU_state = STATE_APP_IDLE; + break; + default: + DFU_state = STATE_DFU_ERROR; + inDFU = 1; + break; } if (!inDFU) { diff --git a/module_usb_aud_shared/devicedefines.h b/module_usb_aud_shared/devicedefines.h index 1f98cb37..7b01659c 100644 --- a/module_usb_aud_shared/devicedefines.h +++ b/module_usb_aud_shared/devicedefines.h @@ -292,11 +292,6 @@ #define ID_MIXER_1 60 -#ifndef SERIAL_STR -#define SERIAL_STR "0000" /* Serial number string */ -#endif - -#define SERIAL_STR_INDEX 0x03 #define MANUFACTURER_STR_INDEX 0x01 #define PRODUCT_STR_INDEX 0x02 diff --git a/module_usb_aud_shared/endpoint0/descriptors_2.h b/module_usb_aud_shared/endpoint0/descriptors_2.h index 19afb760..6b8cd403 100644 --- a/module_usb_aud_shared/endpoint0/descriptors_2.h +++ b/module_usb_aud_shared/endpoint0/descriptors_2.h @@ -36,7 +36,7 @@ unsigned char devDesc_Audio1[] = (BCD_DEVICE >> 8), /* 13 bcdDevice : Device release number */ MANUFACTURER_STR_INDEX, /* 14 iManufacturer : Index of manufacturer string */ PRODUCT_STR_INDEX, /* 15 iProduct : Index of product string descriptor */ - SERIAL_STR_INDEX, /* 16 iSerialNumber : Index of serial number decriptor */ + 0,//SERIAL_STR_INDEX, /* 16 iSerialNumber : Index of serial number decriptor */ 0x01 /* 17 bNumConfigurations : Number of possible configs. */ }; #endif @@ -60,7 +60,7 @@ unsigned char devDesc_Audio2[] = (BCD_DEVICE >> 8), /* 13 bcdDevice : Device release number */ MANUFACTURER_STR_INDEX, /* 14 iManufacturer : Index of manufacturer string */ PRODUCT_STR_INDEX, /* 15 iProduct : Index of product string descriptor */ - SERIAL_STR_INDEX, /* 16 iSerialNumber : Index of serial number decriptor */ + 0,// SERIAL_STR_INDEX, /* 16 iSerialNumber : Index of serial number decriptor */ 0x02 /* 17 bNumConfigurations : Number of possible configs. Set to 2 so that Windows does not load Composite driver. */ }; @@ -84,7 +84,7 @@ unsigned char devDesc_Null[] = (BCD_DEVICE >> 8), /* 13 bcdDevice : Device release number */ MANUFACTURER_STR_INDEX, /* 14 iManufacturer : Index of manufacturer string */ PRODUCT_STR_INDEX, /* 15 iProduct : Index of product string descriptor */ - SERIAL_STR_INDEX, /* 16 iSerialNumber : Index of serial number decriptor */ + 0,//SERIAL_STR_INDEX, /* 16 iSerialNumber : Index of serial number decriptor */ 0x01 /* 17 bNumConfigurations : Number of possible configs */ }; @@ -1338,7 +1338,7 @@ static unsigned char strDescs_Audio2[][40] = "Langids", /* String 0 (LangIDs) place holder */ APPEND_VENDOR_STR( ), // 1 iManufacturer (at MANUFACTURER_STRING_INDEX) APPEND_VENDOR_STR(USB Audio 2.0), // 2 iProduct and iInterface for control interface (at PRODUCT_STR_INDEX) - SERIAL_STR, // 3 iSerialNumber (at SERIAL_STR_INDEX) + "",//SERIAL_STR, // 3 iSerialNumber (at SERIAL_STR_INDEX) APPEND_VENDOR_STR(USB 2.0 Audio Out), // 4 iInterface for Streaming interaces APPEND_VENDOR_STR(USB 2.0 Audio In), // 5 @@ -1576,7 +1576,7 @@ unsigned char oSpeedCfgDesc[] = #define STREAMING_INTERFACES (INPUT_INTERFACES + OUTPUT_INTERFACES) -#define CFG_TOTAL_LENGTH_A1 (18 + AC_TOTAL_LENGTH + (INPUT_INTERFACES * 61) + (OUTPUT_INTERFACES * 70) + (DFU_INTERFACES * 18)) +#define CFG_TOTAL_LENGTH_A1 (18 + AC_TOTAL_LENGTH + (INPUT_INTERFACES * 61) + (OUTPUT_INTERFACES * 70)) #ifdef AUDIO_CLASS_FALLBACK unsigned char cfgDesc_Audio1[] = { @@ -1876,6 +1876,7 @@ unsigned char cfgDesc_Audio1[] = 0x40, 0x00 #else +#if 0 /* DFU 1.1 Run-Time DFU Functional Descriptor */ 0x09, /* 0 Size */ 0x21, /* 1 bDescriptorType : DFU FUNCTIONAL */ @@ -1886,7 +1887,7 @@ unsigned char cfgDesc_Audio1[] = 0x00, /* 6 wTransferSize */ 0x10, /* 7 bcdDFUVersion */ 0x01, /* 7 bcdDFUVersion */ - +#endif #endif }; @@ -1899,7 +1900,7 @@ static unsigned char strDescs_Audio1[][40] = "Langids", /* String 0 (LangIDs) place holder */ APPEND_VENDOR_STR(), // 1 iManufacturer APPEND_VENDOR_STR(USB Audio 1.0), // 2 iProduct and iInterface for control interface - SERIAL_STR, // 3 iSerialNumber + "",//SERIAL_STR, // 3 iSerialNumber APPEND_VENDOR_STR(USB 1.0 Audio Out), // 4 iInterface for Streaming interaces APPEND_VENDOR_STR(USB 1.0 Audio In), // 5 diff --git a/module_usb_aud_shared/endpoint0/endpoint0.xc b/module_usb_aud_shared/endpoint0/endpoint0.xc index 1a763efd..97a6ebf3 100755 --- a/module_usb_aud_shared/endpoint0/endpoint0.xc +++ b/module_usb_aud_shared/endpoint0/endpoint0.xc @@ -24,6 +24,20 @@ #include "hid.h" #endif +#define GLXID 0x0001 +#define PLL_CTRL_VAL ((1<<23) | (499<<8) | (2<<0)) +void glx_link_setup(unsigned myid, unsigned glxid); +void glx_link_setup_with(unsigned myid, unsigned glxid, unsigned link_setup_val); +int write_glx_periph_word(unsigned destId, unsigned periphAddress, unsigned destRegAddr, unsigned data); +int read_glx_periph_word(unsigned dest_id, unsigned periph_addr, unsigned dest_reg_addr, unsigned &rd_data); +int read_glx_periph_reg(unsigned dest_id, unsigned periph_addr, unsigned dest_reg_addr, unsigned bad_format, unsigned data_size, char buf[]); +int write_glx_periph_reg(unsigned dest_id, unsigned periph_addr, unsigned dest_reg_addr, unsigned bad_packet, unsigned data_size, char buf[]); +void read_sswitch_reg_verify(unsigned coreid, unsigned reg, unsigned &data, unsigned failval); +void write_sswitch_reg_verify(unsigned coreid, unsigned reg, unsigned data, unsigned failval); + +#define XS1_GLX_PERIPH_SCTH_ID 0x3 + + /* Windows does not have a built in DFU driver (windows will prompt), so warn that DFU will not be functional in Audio 1.0 mode.Udi * Of course, OSX is unaffected. */ @@ -267,6 +281,24 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, VendorAudioRequestsInit(c_audioControl, c_mix_ctl, c_clk_ctl); #endif +#if 0 + { + char rdata[1]; + char wdata[1]; + + //wdata[0] = 77; + //write_glx_periph_reg(GLXID, XS1_GLX_PERIPH_SCTH_ID, 0x0, 0, 1, wdata); + + + read_glx_periph_reg(GLXID, XS1_GLX_PERIPH_SCTH_ID, 0x1, 0, 1, rdata); + + if(rdata[0] != 0) + { + while(1); + } + // printintln(rdata[0]); +#endif + #ifdef DFU /* Check if device has started in DFU mode */ if (DFUReportResetState(null)) @@ -867,6 +899,13 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, // Restart audio //outuint(c_audioControl, AUDIO_START_FROM_DFU); DFU_mode_active = 0; + + { + unsigned char wdata[1]; + wdata[0] = 77; + write_glx_periph_reg(GLXID, XS1_GLX_PERIPH_SCTH_ID, 0x0, 0, 1, wdata); + } + // Send reboot command //outuint(c_audioControl, SET_SAMPLE_FREQ); //outuint(c_audioControl, AUDIO_REBOOT_FROM_DFU); diff --git a/module_usb_aud_shared/reboot.xc b/module_usb_aud_shared/reboot.xc index c437e19d..c8a7186a 100644 --- a/module_usb_aud_shared/reboot.xc +++ b/module_usb_aud_shared/reboot.xc @@ -1,11 +1,63 @@ #include #include +#define GLXID 0x0001 +#define XS1_GLX_PERIPH_USB_ID 0x1 +#define XS1_GLX_CFG_RST_MISC_ADRS 0x50 +#define XS1_UIFM_PHY_CONTROL_REG 0x3c +#define XS1_UIFM_PHY_CONTROL_FORCERESET 0x0 +#define XS1_GLX_CFG_USB_CLK_EN_BASE 0x3 +#define XS1_GLX_CFG_USB_EN_BASE 0x2 +#define XS1_GLX_PERIPH_SCTH_ID 0x3 + +#define XS1_UIFM_FUNC_CONTROL_REG 0xc +#define XS1_UIFM_FUNC_CONTROL_XCVRSELECT 0x0 +#define XS1_UIFM_FUNC_CONTROL_TERMSELECT 0x1 int write_sswitch_reg_blind(unsigned coreid, unsigned reg, unsigned data); +void write_sswitch_reg_verify(unsigned coreid, unsigned reg, unsigned data, unsigned failval); +int write_glx_periph_word(unsigned destId, unsigned periphAddress, unsigned destRegAddr, unsigned data); +int write_glx_periph_reg(unsigned dest_id, unsigned periph_addr, unsigned dest_reg_addr, unsigned bad_packet, unsigned data_size, char buf[]); +void read_sswitch_reg_verify(unsigned coreid, unsigned reg, unsigned &data, unsigned failval); /* Reboots XMOS device by writing to the PLL config register */ void device_reboot_implementation(chanend spare) { +//#ifdef ARCH_S + #if 1 + + unsigned wdata; + char wdatac[1]; + + write_glx_periph_word(GLXID, XS1_GLX_PERIPH_USB_ID, XS1_UIFM_FUNC_CONTROL_REG, 4); + // (0<