From 98b3bdba959bbaff0eba0e73f3b05d6adea82bbd Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 22 Jan 2014 11:00:41 +0000 Subject: [PATCH] added toplevel makefile for xpd --- Makefile | 11 + module_dfu/src/dfu.h | 16 +- module_dfu/src/dfu.xc | 152 +- module_dfu/src/flash_interface.c | 74 +- module_usb_audio/audio.h | 8 +- module_usb_audio/audio.xc | 306 +-- module_usb_audio/audiostream/audiostream.c | 2 +- module_usb_audio/clocking.h | 2 +- module_usb_audio/clocking/clockgen.xc | 174 +- module_usb_audio/dbtable.h | 4 +- module_usb_audio/devicedefines.h | 60 +- module_usb_audio/endpoint0/audiorequests.xc | 404 ++-- module_usb_audio/endpoint0/dbcalc.h | 2 +- module_usb_audio/endpoint0/dbcalc.xc | 26 +- module_usb_audio/endpoint0/descriptors.h | 750 +++---- module_usb_audio/endpoint0/endpoint0.h | 8 +- module_usb_audio/endpoint0/endpoint0.xc | 186 +- module_usb_audio/endpoint0/vendorrequests.h | 2 +- module_usb_audio/flashlib_user.c | 12 +- module_usb_audio/main.xc | 138 +- module_usb_audio/mixer/fastmix.S | 352 +-- module_usb_audio/mixer/mixer.h | 6 +- module_usb_audio/mixer/mixer.xc | 96 +- module_usb_audio/ports/audioports.c | 16 +- module_usb_audio/ports/audioports.h | 8 +- module_usb_audio/ports/audioports.xc | 8 +- .../powersave/archU_powerSaving.h | 2 +- .../powersave/archU_powerSaving.xc | 6 +- module_usb_audio/reboot.xc | 16 +- module_usb_audio/usb_buffer/decouple.h | 4 +- module_usb_audio/usb_buffer/decouple.xc | 340 +-- module_usb_audio/usb_buffer/get_adc_counts.c | 14 +- module_usb_audio/usb_buffer/interrupt.h | 42 +- module_usb_audio/usb_buffer/testct_byref.h | 4 +- module_usb_audio/usb_buffer/testct_byref.xc | 6 +- module_usb_audio/usb_buffer/usb_buffer.h | 14 +- module_usb_audio/usb_buffer/usb_buffer.xc | 300 +-- module_usb_audio/usb_buffer/xc_ptr.h | 2 +- module_usb_audio/user_hid.h | 2 +- module_usb_audio/xuduser/xuduser.c | 2 +- module_usb_audio_adat/src/adatreceiver.h | 4 +- module_usb_audio_adat/src/adatreceiver.xc | 1894 ++++++++--------- module_usb_midi/src/midi_descriptor.h | 2 +- module_usb_midi/src/midiinparse.xc | 12 +- module_usb_midi/src/midioutparse.xc | 8 +- module_usb_midi/src/usb_midi.h | 4 +- module_usb_midi/src/usb_midi.xc | 66 +- 47 files changed, 2789 insertions(+), 2778 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..a0607d6c --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ + +# This variable should contain a space separated list of all +# the directories containing buildable applications (usually +# prefixed with the app_ prefix) +# +# If the variable is set to "all" then all directories that start with app_ +# are built. +BUILD_SUBDIRS = all + +XMOS_MAKE_PATH ?= .. +include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.toplevel diff --git a/module_dfu/src/dfu.h b/module_dfu/src/dfu.h index dc6201ea..96ae11f8 100644 --- a/module_dfu/src/dfu.h +++ b/module_dfu/src/dfu.h @@ -10,7 +10,7 @@ #error DFU_PID not defined! #endif -#ifndef DFU_BCD_DEVICE +#ifndef DFU_BCD_DEVICE #error DFU_BCD_DEVICE not defined! #endif @@ -36,12 +36,12 @@ unsigned char DFUdevDesc[] = { 0x00, /* 5 bDeviceSubClass: See interface */ 0, /* 6 bDeviceProtocol: See interface */ 64, /* 7 bMaxPacketSize */ - (DFU_VENDOR_ID & 0xFF), /* 8 idVendor */ - (DFU_VENDOR_ID >> 8), /* 9 idVendor */ - (DFU_PID & 0xFF), /* 10 idProduct */ - (DFU_PID >> 8), /* 11 idProduct */ - (DFU_BCD_DEVICE & 0xFF), /* 12 bcdDevice : Device release number */ - (DFU_BCD_DEVICE >> 8), /* 13 bcdDevice : Device release number */ + (DFU_VENDOR_ID & 0xFF), /* 8 idVendor */ + (DFU_VENDOR_ID >> 8), /* 9 idVendor */ + (DFU_PID & 0xFF), /* 10 idProduct */ + (DFU_PID >> 8), /* 11 idProduct */ + (DFU_BCD_DEVICE & 0xFF), /* 12 bcdDevice : Device release number */ + (DFU_BCD_DEVICE >> 8), /* 13 bcdDevice : Device release number */ DFU_MANUFACTURER_STR_INDEX, /* 14 iManufacturer : Index of manufacturer string */ DFU_PRODUCT_STR_INDEX, /* 15 iProduct : Index of product string descriptor */ DFU_SERIAL_STR_INDEX, /* 16 iSerialNumber : Index of serial number decriptor */ @@ -49,7 +49,7 @@ unsigned char DFUdevDesc[] = { }; unsigned char DFUcfgDesc[] = { - /* Standard USB device descriptor */ + /* Standard USB device descriptor */ 0x09, /* 0 bLength */ USB_CONFIGURATION, /* 1 bDescriptorType */ 0x1b, /* 2 wTotalLength */ diff --git a/module_dfu/src/dfu.xc b/module_dfu/src/dfu.xc index a1a7e4cc..50f93a23 100644 --- a/module_dfu/src/dfu.xc +++ b/module_dfu/src/dfu.xc @@ -22,28 +22,28 @@ extern int DFU_reset_override; extern void DFUCustomFlashEnable(); extern void DFUCustomFlashDisable(); -void temp() +void temp() { asm(".linkset DFU_reset_override, _edp.bss"); asm(".globl DFU_reset_override"); } -static int DFU_OpenFlash(chanend ?c_user_cmd) +static int DFU_OpenFlash(chanend ?c_user_cmd) { - if (!DFU_flash_connected) + if (!DFU_flash_connected) { unsigned int cmd_data[16]; DFUCustomFlashEnable(); flash_cmd_init(); DFU_flash_connected = 1; } - + return 0; } -static int DFU_CloseFlash(chanend ?c_user_cmd) +static int DFU_CloseFlash(chanend ?c_user_cmd) { - if (DFU_flash_connected) + if (DFU_flash_connected) { unsigned int cmd_data[16]; DFUCustomFlashDisable(); @@ -53,9 +53,9 @@ static int DFU_CloseFlash(chanend ?c_user_cmd) return 0; } -static int DFU_Detach(unsigned int timeout, chanend ?c_user_cmd) +static int DFU_Detach(unsigned int timeout, chanend ?c_user_cmd) { - if (DFU_state == STATE_APP_IDLE) + if (DFU_state == STATE_APP_IDLE) { DFU_state = STATE_APP_DETACH; @@ -64,15 +64,15 @@ static int DFU_Detach(unsigned int timeout, chanend ?c_user_cmd) // Setup DFU timeout value DFUResetTimeout = timeout * 100000; - + // Start DFU reset timer DFUTimer :> DFUTimerStart; - } - else + } + else { DFU_state = STATE_DFU_ERROR; } - return 0; + return 0; } static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned int request_data[16], chanend ?c_user_cmd) @@ -86,7 +86,7 @@ static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned DFU_OpenFlash(c_user_cmd); - switch (DFU_state) + switch (DFU_state) { case STATE_DFU_IDLE: case STATE_DFU_DOWNLOAD_IDLE: @@ -96,29 +96,29 @@ static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned return 0; } - if ((DFU_state == STATE_DFU_IDLE) && (request_len == 0)) + if ((DFU_state == STATE_DFU_IDLE) && (request_len == 0)) { DFU_state = STATE_DFU_ERROR; return 0; - } - else if (DFU_state == STATE_DFU_IDLE) + } + else if (DFU_state == STATE_DFU_IDLE) { fromDfuIdle = 1; - } - else + } + else { fromDfuIdle = 0; } - if (request_len == 0) + if (request_len == 0) { // Host signalling complete download int i = 0; unsigned int cmd_data[16]; - if (subPagesLeft) + if (subPagesLeft) { unsigned int subPagePad[16] = {0}; - for (i = 0; i < subPagesLeft; i++) + for (i = 0; i < subPagesLeft; i++) { flash_cmd_write_page_data((subPagePad, unsigned char[64])); } @@ -128,16 +128,16 @@ static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned flash_cmd_write_page((cmd_data, unsigned char[])); DFU_state = STATE_DFU_MANIFEST_SYNC; - } - else + } + else { unsigned int i = 0; unsigned int flash_cmd = 0; unsigned int flash_page_index = 0; unsigned int cmd_data[16]; - - if (fromDfuIdle) - { + + if (fromDfuIdle) + { unsigned s = 0; // Erase flash on first block @@ -145,14 +145,14 @@ static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned } // Program firmware, STATE_DFU_DOWNLOAD_BUSY not currently used - if (!(block_num % 4)) + if (!(block_num % 4)) { cmd_data[0] = !fromDfuIdle; // 0 for first page, 1 for other pages. flash_cmd_write_page((cmd_data, unsigned char[64])); subPagesLeft = 4; } - - for (i = 0; i < 16; i++) + + for (i = 0; i < 16; i++) { cmd_data[i] = request_data[i]; } @@ -163,11 +163,11 @@ static int DFU_Dnload(unsigned int request_len, unsigned int block_num, unsigned DFU_state = STATE_DFU_DOWNLOAD_SYNC; } - return 0; + return 0; } -static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned int request_data[16], chanend ?c_user_cmd) +static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned int request_data[16], chanend ?c_user_cmd) { unsigned int cmd_data[16]; unsigned int firstRead = 0; @@ -176,8 +176,8 @@ static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned // Keep reading flash pages until read_page returns 1 (address out of range) // Return terminating upload packet at this point DFU_OpenFlash(c_user_cmd); - - switch (DFU_state) + + switch (DFU_state) { case STATE_DFU_IDLE: case STATE_DFU_UPLOAD_IDLE: @@ -187,18 +187,18 @@ static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned return 0; } - if ((DFU_state == STATE_DFU_IDLE) && (request_len == 0)) + if ((DFU_state == STATE_DFU_IDLE) && (request_len == 0)) { DFU_state = STATE_DFU_ERROR; return 0; - } - else if (DFU_state == STATE_DFU_IDLE) + } + else if (DFU_state == STATE_DFU_IDLE) { firstRead = 1; subPagesLeft = 0; } - if (!subPagesLeft) + if (!subPagesLeft) { cmd_data[0] = !firstRead; @@ -207,14 +207,14 @@ static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned subPagesLeft = 4; // If address out of range, terminate! - if (cmd_data[0] == 1) + if (cmd_data[0] == 1) { subPagesLeft = 0; // Back to idle state, upload complete DFU_state = STATE_DFU_IDLE; return 0; } - } + } // Read page data flash_cmd_write_page_data((request_data, unsigned char[64])); @@ -223,16 +223,16 @@ static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned DFU_state = STATE_DFU_UPLOAD_IDLE; - return 64; + return 64; } -static int DFU_GetStatus(unsigned int request_len, unsigned int request_data[16], chanend ?c_user_cmd) +static int DFU_GetStatus(unsigned int request_len, unsigned int request_data[16], chanend ?c_user_cmd) { unsigned int timeout = 0; request_data[0] = timeout << 8 | (unsigned char)DFU_status; - - switch (DFU_state) + + switch (DFU_state) { case STATE_DFU_MANIFEST: case STATE_DFU_MANIFEST_WAIT_RESET: @@ -255,28 +255,28 @@ static int DFU_GetStatus(unsigned int request_len, unsigned int request_data[16] request_data[1] = DFU_state; - return 6; + return 6; } -static int DFU_ClrStatus(void) +static int DFU_ClrStatus(void) { - if (DFU_state == STATE_DFU_ERROR) + if (DFU_state == STATE_DFU_ERROR) { DFU_state = STATE_DFU_IDLE; - } - else + } + else { DFU_state = STATE_DFU_ERROR; } - return 0; + return 0; } -static int DFU_GetState(unsigned int request_len, unsigned int request_data[16], chanend ?c_user_cmd) +static int DFU_GetState(unsigned int request_len, unsigned int request_data[16], chanend ?c_user_cmd) { request_data[0] = DFU_state; - switch (DFU_state) + switch (DFU_state) { case STATE_DFU_DOWNLOAD_BUSY: case STATE_DFU_MANIFEST: @@ -287,22 +287,22 @@ static int DFU_GetState(unsigned int request_len, unsigned int request_data[16], break; } - return 1; + return 1; } -static int DFU_Abort(void) +static int DFU_Abort(void) { DFU_state = STATE_DFU_IDLE; - return 0; + return 0; } // Tell the DFU state machine that a USB reset has occured -int DFUReportResetState(chanend ?c_user_cmd) +int DFUReportResetState(chanend ?c_user_cmd) { unsigned int inDFU = 0; unsigned int currentTime = 0; - if (DFU_reset_override == 0x11042011) + if (DFU_reset_override == 0x11042011) { unsigned int cmd_data[16]; inDFU = 1; @@ -310,19 +310,19 @@ int DFUReportResetState(chanend ?c_user_cmd) return inDFU; } - switch(DFU_state) + switch(DFU_state) { case STATE_APP_DETACH: case STATE_DFU_IDLE: DFU_state = STATE_DFU_IDLE; DFUTimer :> currentTime; - if (currentTime - DFUTimerStart > DFUResetTimeout) + if (currentTime - DFUTimerStart > DFUResetTimeout) { DFU_state = STATE_APP_IDLE; inDFU = 0; - } - else + } + else { inDFU = 1; } @@ -339,13 +339,13 @@ int DFUReportResetState(chanend ?c_user_cmd) inDFU = 0; DFU_state = STATE_APP_IDLE; break; - default: + default: DFU_state = STATE_DFU_ERROR; inDFU = 1; break; } - if (!inDFU) + if (!inDFU) { DFU_CloseFlash(c_user_cmd); } @@ -363,7 +363,7 @@ static int XMOS_DFU_RevertFactory(chanend ?c_user_cmd) DFUTimer :> s; DFUTimer when timerafter(s + 25000000) :> s; // Wait for flash erase - + return 0; } @@ -376,7 +376,7 @@ static int XMOS_DFU_SelectImage(unsigned int index, chanend ?c_user_cmd) static int XMOS_DFU_SaveState() -{ +{ return 0; } @@ -391,16 +391,16 @@ int DFUDeviceRequests(XUD_ep ep0_out, XUD_ep &?ep0_in, USB_SetupPacket_t &sp, ch unsigned int data_buffer_len = 0; unsigned int data_buffer[17]; unsigned int reset_device_after_ack = 0; - - if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) - { + + if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) + { // Host to device - if (sp.wLength) + if (sp.wLength) data_buffer_len = XUD_GetBuffer(ep0_out, (data_buffer, unsigned char[])); } // Map Standard DFU commands onto device level firmware upgrade mechanism - switch (sp.bRequest) + switch (sp.bRequest) { case DFU_DETACH: return_data_len = DFU_Detach(sp.wValue, c_user_cmd); @@ -456,16 +456,16 @@ int DFUDeviceRequests(XUD_ep ep0_out, XUD_ep &?ep0_in, USB_SetupPacket_t &sp, ch break; } - if (sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_D2H && sp.wLength != 0) - { + if (sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_D2H && sp.wLength != 0) + { // Device to host #ifdef ARCH_G XUD_DoGetRequest(ep0_out, 0, (data_buffer, unsigned char[]), return_data_len, return_data_len); #else XUD_DoGetRequest(ep0_out, ep0_in, (data_buffer, unsigned char[]), return_data_len, return_data_len); #endif - } - else + } + else { #ifdef ARCH_G XUD_DoSetRequestStatus(ep0_out); @@ -475,11 +475,11 @@ int DFUDeviceRequests(XUD_ep ep0_out, XUD_ep &?ep0_in, USB_SetupPacket_t &sp, ch } // If device reset requested, handle after command acknowledgement - if (reset_device_after_ack) + if (reset_device_after_ack) { - if (user_reset) + if (user_reset) { - return 1; + return 1; } } diff --git a/module_dfu/src/flash_interface.c b/module_dfu/src/flash_interface.c index 34d3e0cf..9d4d6a05 100755 --- a/module_dfu/src/flash_interface.c +++ b/module_dfu/src/flash_interface.c @@ -4,7 +4,7 @@ #include #include -#ifndef FLASH_MAX_UPGRADE_SIZE +#ifndef FLASH_MAX_UPGRADE_SIZE #define FLASH_MAX_UPGRADE_SIZE 128 * 1024 // 128K default #endif @@ -40,11 +40,11 @@ void DFUCustomFlashDisable() return; } -int flash_cmd_init(void) +int flash_cmd_init(void) { fl_BootImageInfo image; - if (!flash_device_open) + if (!flash_device_open) { if (flash_cmd_enable_ports()) flash_device_open = 1; @@ -56,14 +56,14 @@ int flash_cmd_init(void) // Disable flash protection fl_setProtection(0); - if (fl_getFactoryImage(&image) != 0) + if (fl_getFactoryImage(&image) != 0) { return 0; } - + factory_image = image; - if (fl_getNextBootImage(&image) == 0) + if (fl_getNextBootImage(&image) == 0) { upgrade_image_valid = 1; upgrade_image = image; @@ -72,43 +72,43 @@ int flash_cmd_init(void) return 0; } -int flash_cmd_deinit(void) +int flash_cmd_deinit(void) { if (!flash_device_open) return 0; - + flash_cmd_disable_ports(); flash_device_open = 0; return 0; } -int flash_cmd_read_page(unsigned char *data) +int flash_cmd_read_page(unsigned char *data) { - if (!upgrade_image_valid) + if (!upgrade_image_valid) { *(unsigned int *)data = 1; return 4; } - - if (*(unsigned int *)data == 0) + + if (*(unsigned int *)data == 0) { fl_startImageRead(&upgrade_image); } - + current_flash_subpage_index = 0; - - if (fl_readImageRead(current_flash_page_data) == 0) + + if (fl_readImageRead(current_flash_page_data) == 0) { *(unsigned int *)data = 0; - } - else + } + else { *(unsigned int *)data = 1; } return 4; } -int flash_cmd_read_page_data(unsigned char *data) +int flash_cmd_read_page_data(unsigned char *data) { unsigned char *page_data_ptr = ¤t_flash_page_data[current_flash_subpage_index * 64]; memcpy(data, page_data_ptr, 64); @@ -124,27 +124,27 @@ static void begin_write() // TODO this will take a long time. To minimise the amount of time spent // paused on this operation it would be preferable to move to this to a // seperate command, e.g. start_write. - do + do { result = fl_startImageAdd(&factory_image, FLASH_MAX_UPGRADE_SIZE, 0); } while (result > 0); - + if (result < 0) FLASH_ERROR(); } static int pages_written = 0; -int flash_cmd_write_page(unsigned char *data) +int flash_cmd_write_page(unsigned char *data) { unsigned int flag = *(unsigned int *)data; - if (upgrade_image_valid) + if (upgrade_image_valid) { return 0; - } + } - switch (flag) + switch (flag) { case 0: // First page. @@ -158,7 +158,7 @@ int flash_cmd_write_page(unsigned char *data) // Termination. if (fl_endWriteImage() != 0) FLASH_ERROR(); - + // Sanity check fl_BootImageInfo image = factory_image; if (fl_getNextBootImage(&image) != 0) @@ -173,7 +173,7 @@ int flash_cmd_write_page(unsigned char *data) static int isAllOnes(unsigned char page[256]) { unsigned i; - for (i = 0; i < 256; i++) + for (i = 0; i < 256; i++) { if (page[i] != 0xff) return 0; @@ -181,16 +181,16 @@ static int isAllOnes(unsigned char page[256]) return 1; } -int flash_cmd_write_page_data(unsigned char *data) +int flash_cmd_write_page_data(unsigned char *data) { unsigned char *page_data_ptr = ¤t_flash_page_data[current_flash_subpage_index * 64]; - if (upgrade_image_valid) + if (upgrade_image_valid) { return 0; } - if (current_flash_subpage_index >= 4) + if (current_flash_subpage_index >= 4) { return 0; } @@ -199,11 +199,11 @@ int flash_cmd_write_page_data(unsigned char *data) current_flash_subpage_index++; - if (current_flash_subpage_index == 4) + if (current_flash_subpage_index == 4) { if (isAllOnes(data)) FLASH_ERROR(); - if (fl_writeImagePage(current_flash_page_data) != 0) + if (fl_writeImagePage(current_flash_page_data) != 0) FLASH_ERROR(); pages_written++; } @@ -211,22 +211,22 @@ int flash_cmd_write_page_data(unsigned char *data) return 0; } -int flash_cmd_erase_all(void) +int flash_cmd_erase_all(void) { fl_BootImageInfo tmp_image = upgrade_image; - if (upgrade_image_valid) + if (upgrade_image_valid) { if (fl_deleteImage(&upgrade_image) != 0) { FLASH_ERROR(); } - + // Keep deleting all upgrade images - // TODO Perhaps using replace would be nicer... + // TODO Perhaps using replace would be nicer... while(1) { - if (fl_getNextBootImage(&tmp_image) == 0) + if (fl_getNextBootImage(&tmp_image) == 0) { if (fl_deleteImage(&tmp_image) != 0) { @@ -238,7 +238,7 @@ int flash_cmd_erase_all(void) break; } } - + upgrade_image_valid = 0; } return 0; diff --git a/module_usb_audio/audio.h b/module_usb_audio/audio.h index 1a4c9b45..38cb7970 100644 --- a/module_usb_audio/audio.h +++ b/module_usb_audio/audio.h @@ -3,14 +3,14 @@ /** The audio driver thread. * - * This function drives I2S ports and handles samples to/from other digital + * This function drives I2S ports and handles samples to/from other digital * I/O threads. - * + * * \param c_in Audio sample channel connected to the mixer() thread or the * decouple() thread - * \param c_dig channel connected to the clockGen() thread for + * \param c_dig channel connected to the clockGen() thread for * receiving/transmitting samples - * \param c_config An optional channel that will be passed on to the + * \param c_config An optional channel that will be passed on to the * CODEC configuration functions. */ void audio(chanend c_in, chanend ?c_dig, chanend ?c_config, chanend ?c_adc); diff --git a/module_usb_audio/audio.xc b/module_usb_audio/audio.xc index 23981939..0bcde8bf 100755 --- a/module_usb_audio/audio.xc +++ b/module_usb_audio/audio.xc @@ -1,11 +1,11 @@ /** * @file audio.xc * @brief XMOS L1/L2 USB 2,0 Audio Reference Design. Audio Functions. - * @author Ross Owen, XMOS Semiconductor Ltd + * @author Ross Owen, XMOS Semiconductor Ltd * * This thread handles I2S and pars an additional SPDIF Tx thread. It forwards samples to the SPDIF Tx thread. * Additionally this thread handles clocking and CODEC/DAC/ADC config. - **/ + **/ #include #include @@ -25,7 +25,7 @@ unsigned testsamples[100]; int p = 0; unsigned lastSample = 0; -#if (DSD_CHANS_DAC != 0) +#if (DSD_CHANS_DAC != 0) extern unsigned p_dsd_dac[DSD_CHANS_DAC]; extern port p_dsd_clk; #endif @@ -40,7 +40,7 @@ unsigned g_adcVal = 0; /* I2S Data I/O*/ #if (I2S_CHANS_DAC != 0) -extern buffered out port:32 p_i2s_dac[I2S_WIRES_DAC]; +extern buffered out port:32 p_i2s_dac[I2S_WIRES_DAC]; #endif #if (I2S_CHANS_ADC != 0) @@ -61,13 +61,13 @@ unsigned dsdMode = DSD_MODE_OFF; /* Master clock input */ extern port p_mclk_in; -#ifdef SPDIF +#ifdef SPDIF extern buffered out port:32 p_spdif_tx; #endif -extern clock clk_audio_mclk; -extern clock clk_audio_bclk; -extern clock clk_mst_spd; +extern clock clk_audio_mclk; +extern clock clk_audio_bclk; +extern clock clk_mst_spd; extern void device_reboot(void); @@ -81,43 +81,43 @@ extern void device_reboot(void); #ifndef CODEC_MASTER static inline void doI2SClocks(unsigned divide) -{ +{ switch (divide) { #if (MAX_DIVIDE > 16) -#error MCLK/BCLK Ratio not supported!! +#error MCLK/BCLK Ratio not supported!! #endif #if (MAX_DIVIDE > 8) case 16: - p_bclk <: 0xff00ff00; - p_bclk <: 0xff00ff00; - p_bclk <: 0xff00ff00; - p_bclk <: 0xff00ff00; - p_bclk <: 0xff00ff00; - p_bclk <: 0xff00ff00; - p_bclk <: 0xff00ff00; - p_bclk <: 0xff00ff00; - - p_bclk <: 0xff00ff00; - p_bclk <: 0xff00ff00; - p_bclk <: 0xff00ff00; - p_bclk <: 0xff00ff00; - p_bclk <: 0xff00ff00; - p_bclk <: 0xff00ff00; - p_bclk <: 0xff00ff00; - p_bclk <: 0xff00ff00; + p_bclk <: 0xff00ff00; + p_bclk <: 0xff00ff00; + p_bclk <: 0xff00ff00; + p_bclk <: 0xff00ff00; + p_bclk <: 0xff00ff00; + p_bclk <: 0xff00ff00; + p_bclk <: 0xff00ff00; + p_bclk <: 0xff00ff00; + + p_bclk <: 0xff00ff00; + p_bclk <: 0xff00ff00; + p_bclk <: 0xff00ff00; + p_bclk <: 0xff00ff00; + p_bclk <: 0xff00ff00; + p_bclk <: 0xff00ff00; + p_bclk <: 0xff00ff00; + p_bclk <: 0xff00ff00; break; #endif #if (MAX_DIVIDE > 4) case 8: - p_bclk <: 0xF0F0F0F0; - p_bclk <: 0xF0F0F0F0; - p_bclk <: 0xF0F0F0F0; - p_bclk <: 0xF0F0F0F0; - p_bclk <: 0xF0F0F0F0; - p_bclk <: 0xF0F0F0F0; - p_bclk <: 0xF0F0F0F0; - p_bclk <: 0xF0F0F0F0; + p_bclk <: 0xF0F0F0F0; + p_bclk <: 0xF0F0F0F0; + p_bclk <: 0xF0F0F0F0; + p_bclk <: 0xF0F0F0F0; + p_bclk <: 0xF0F0F0F0; + p_bclk <: 0xF0F0F0F0; + p_bclk <: 0xF0F0F0F0; + p_bclk <: 0xF0F0F0F0; break; #endif #if (MAX_DIVIDE > 2) @@ -129,7 +129,7 @@ static inline void doI2SClocks(unsigned divide) break; #endif #if (MAX_DIVIDE > 1) - case 2: + case 2: p_bclk <: 0xAAAAAAAA; p_bclk <: 0xAAAAAAAA; break; @@ -137,7 +137,7 @@ static inline void doI2SClocks(unsigned divide) #if (MAX_DIVIDE > 0) case 1: break; -#endif +#endif } } #endif @@ -148,10 +148,10 @@ static inline void doI2SClocks(unsigned divide) { unsigned sample; unsigned underflow = 0; -#if NUM_USB_CHAN_OUT > 0 +#if NUM_USB_CHAN_OUT > 0 unsigned samplesOut[NUM_USB_CHAN_OUT]; #endif -#if NUM_USB_CHAN_IN > 0 +#if NUM_USB_CHAN_IN > 0 unsigned samplesIn[NUM_USB_CHAN_IN]; unsigned samplesInPrev[NUM_USB_CHAN_IN]; #endif @@ -181,7 +181,7 @@ static inline void doI2SClocks(unsigned divide) } #endif -#if(DSD_CHANS_DAC != 0) +#if(DSD_CHANS_DAC != 0) if(dsdMode == DSD_MODE_DOP) underflowWord = 0xFA969600; else if(dsdMode == DSD_MODE_NATIVE) @@ -196,18 +196,18 @@ static inline void doI2SClocks(unsigned divide) if(testct(c_out)) { unsigned command = inct(c_out); -#ifndef CODEC_MASTER +#ifndef CODEC_MASTER // Set clocks low p_lrclk <: 0; p_bclk <: 0; -#if(DSD_CHANS_DAC != 0) +#if(DSD_CHANS_DAC != 0) /* DSD Clock might not be shared with lrclk or bclk... */ p_dsd_clk <: 0; #endif #endif #if (DSD_CHANS_DAC > 0) if(dsdMode == DSD_MODE_DOP) - dsdMode = DSD_MODE_OFF; + dsdMode = DSD_MODE_OFF; #endif return {command, inuint(c_out)}; } @@ -228,7 +228,7 @@ static inline void doI2SClocks(unsigned divide) if(underflow) { #pragma loop unroll - for(int i = 0; i < NUM_USB_CHAN_OUT; i++) + for(int i = 0; i < NUM_USB_CHAN_OUT; i++) { samplesOut[i] = underflowWord; } @@ -236,7 +236,7 @@ static inline void doI2SClocks(unsigned divide) else { #pragma loop unroll - for(int i = 0; i < NUM_USB_CHAN_OUT; i++) + for(int i = 0; i < NUM_USB_CHAN_OUT; i++) { samplesOut[i] = inuint(c_out); } @@ -248,15 +248,15 @@ static inline void doI2SClocks(unsigned divide) if(underflow) { #pragma loop unroll - for(int i = 0; i < NUM_USB_CHAN_OUT; i++) + for(int i = 0; i < NUM_USB_CHAN_OUT; i++) { samplesOut[i] = underflowWord; } } else - { + { #pragma loop unroll - for(int i = 0; i < NUM_USB_CHAN_OUT; i++) + for(int i = 0; i < NUM_USB_CHAN_OUT; i++) { int tmp = inuint(c_out); #if defined(OUT_VOLUME_IN_MIXER) && defined(OUT_VOLUME_AFTER_MIX) @@ -266,7 +266,7 @@ static inline void doI2SClocks(unsigned divide) } } #endif - + #if NUM_USB_CHAN_IN > 0 #pragma loop unroll for(int i = 0; i < NUM_USB_CHAN_IN; i++) @@ -288,7 +288,7 @@ static inline void doI2SClocks(unsigned divide) #endif /* Clear I2S port buffers */ clearbuf(p_lrclk); - + #if (I2S_CHANS_DAC != 0) for(int i = 0; i < I2S_WIRES_DAC; i++) { @@ -308,7 +308,7 @@ static inline void doI2SClocks(unsigned divide) p_lrclk <: 0 @ tmp; tmp += 100; - /* Since BCLK is free-running, setup outputs/inputs at a know point in the future */ + /* Since BCLK is free-running, setup outputs/inputs at a know point in the future */ #if (I2S_CHANS_DAC != 0) #pragma loop unroll for(int i = 0; i < I2S_WIRES_DAC; i++) @@ -317,13 +317,13 @@ static inline void doI2SClocks(unsigned divide) } #endif - p_lrclk @ tmp <: 0x7FFFFFFF; + p_lrclk @ tmp <: 0x7FFFFFFF; #if (I2S_CHANS_ADC != 0) for(int i = 0; i < I2S_WIRES_DAC; i++) { - //p_i2s_adc[0] @ (tmp - 1) :> void; + //p_i2s_adc[0] @ (tmp - 1) :> void; asm("setpt res[%0], %1"::"r"(p_i2s_adc[i]),"r"(tmp-1)); clearbuf(p_i2s_adc[i]); } @@ -341,11 +341,11 @@ static inline void doI2SClocks(unsigned divide) p_i2s_dac[i] <: 0; } #endif - - p_lrclk <: 0x7FFFFFFF; + + p_lrclk <: 0x7FFFFFFF; doI2SClocks(divide); - + } #if (DSD_CHANS_DAC > 0) } /* if (!dsdMode) */ @@ -356,8 +356,8 @@ static inline void doI2SClocks(unsigned divide) //sync(p_dsd_clk); } #endif -#else /* ifndef CODEC_MASTER */ - +#else /* ifndef CODEC_MASTER */ + /* Wait for LRCLK edge */ p_lrclk when pinseq(0) :> void; p_lrclk when pinseq(1) :> void; @@ -365,33 +365,33 @@ static inline void doI2SClocks(unsigned divide) p_lrclk when pinseq(1) :> void; p_lrclk when pinseq(0) :> void @ tmp; tmp += 33; - + #if (I2S_CHANS_DAC != 0) -#pragma loop unroll +#pragma loop unroll for(int i = 0; i < I2S_WIRES_DAC; i++) { p_i2s_dac[i] @ tmp <: 0; } #endif - p_i2s_adc[0] @ tmp - 1 :> void; + p_i2s_adc[0] @ tmp - 1 :> void; -#pragma loop unroll +#pragma loop unroll for(int i = 0; i < I2S_WIRES_ADC; i++) - { + { clearbuf(p_i2s_adc[i]); } - /* TODO In master mode, the i/o loop assumes L/RCLK = 32bit clocks. We should check this every interation + /* TODO In master mode, the i/o loop assumes L/RCLK = 32bit clocks. We should check this every interation * and resync if we got a bclk glitch */ #endif - /* Main Audio I/O loop */ + /* Main Audio I/O loop */ while (1) { outuint(c_out, 0); - + /* Check for sample freq change (or other command) or new samples from mixer*/ if(testct(c_out)) { @@ -400,13 +400,13 @@ static inline void doI2SClocks(unsigned divide) // Set clocks low p_lrclk <: 0; p_bclk <: 0; -#if(DSD_CHANS_DAC != 0) +#if(DSD_CHANS_DAC != 0) /* DSD Clock might not be shared with lrclk or bclk... */ p_dsd_clk <: 0; #endif #endif command = inct(c_out); - + #if (DSD_CHANS_DAC > 0) if(dsdMode == DSD_MODE_DOP) dsdMode = DSD_MODE_OFF; @@ -447,7 +447,7 @@ static inline void doI2SClocks(unsigned divide) #else /* ifndef MIXER */ #if NUM_USB_CHAN_OUT > 0 if(underflow) - { + { for(int i = 0; i < NUM_USB_CHAN_OUT; i++) { samplesOut[i] = underflowWord; @@ -457,7 +457,7 @@ static inline void doI2SClocks(unsigned divide) { #pragma loop unroll for(int i = 0; i < NUM_USB_CHAN_OUT; i++) - { + { int tmp = inuint(c_out); #if defined(OUT_VOLUME_IN_MIXER) && defined(OUT_VOLUME_AFTER_MIX) tmp<<=3; @@ -505,11 +505,11 @@ static inline void doI2SClocks(unsigned divide) if(dsdMode == DSD_MODE_NATIVE) { /* 8 bits per chan, 1st 1-bit sample in MSB */ - dsdSample_l = samplesOut[0]; + dsdSample_l = samplesOut[0]; dsdSample_r = samplesOut[1]; - dsdSample_r = bitrev(byterev(dsdSample_r)); - dsdSample_l = bitrev(byterev(dsdSample_l)); - + dsdSample_r = bitrev(byterev(dsdSample_r)); + dsdSample_l = bitrev(byterev(dsdSample_l)); + /* Output DSD data to ports then 32 clocks */ switch (divide) { @@ -521,28 +521,28 @@ static inline void doI2SClocks(unsigned divide) p_dsd_clk <: 0xCCCCCCCC; p_dsd_clk <: 0xCCCCCCCC; break; - - case 2: + + case 2: asm volatile("out res[%0], %1"::"r"(p_dsd_dac[0]),"r"(dsdSample_l)); asm volatile("out res[%0], %1"::"r"(p_dsd_dac[1]),"r"(dsdSample_r)); p_dsd_clk <: 0xAAAAAAAA; p_dsd_clk <: 0xAAAAAAAA; break; - + default: /* Do some clocks anyway - this will stop us interrupting decouple too much */ asm volatile("out res[%0], %1"::"r"(p_dsd_dac[0]),"r"(dsdSample_l)); asm volatile("out res[%0], %1"::"r"(p_dsd_dac[1]),"r"(dsdSample_r)); - p_dsd_clk <: 0xF0F0F0F0; - p_dsd_clk <: 0xF0F0F0F0; - p_dsd_clk <: 0xF0F0F0F0; - p_dsd_clk <: 0xF0F0F0F0; - p_dsd_clk <: 0xF0F0F0F0; - p_dsd_clk <: 0xF0F0F0F0; - p_dsd_clk <: 0xF0F0F0F0; - p_dsd_clk <: 0xF0F0F0F0; + p_dsd_clk <: 0xF0F0F0F0; + p_dsd_clk <: 0xF0F0F0F0; + p_dsd_clk <: 0xF0F0F0F0; + p_dsd_clk <: 0xF0F0F0F0; + p_dsd_clk <: 0xF0F0F0F0; + p_dsd_clk <: 0xF0F0F0F0; + p_dsd_clk <: 0xF0F0F0F0; + p_dsd_clk <: 0xF0F0F0F0; break; - } + } } else if(dsdMode == DSD_MODE_DOP) @@ -551,33 +551,33 @@ static inline void doI2SClocks(unsigned divide) { dsdSample_l = ((samplesOut[0] & 0xffff00) << 8); dsdSample_r = ((samplesOut[1] & 0xffff00) << 8); - + everyOther = 1; - + switch (divide) { case 8: - p_dsd_clk <: 0xF0F0F0F0; - p_dsd_clk <: 0xF0F0F0F0; - p_dsd_clk <: 0xF0F0F0F0; - p_dsd_clk <: 0xF0F0F0F0; + p_dsd_clk <: 0xF0F0F0F0; + p_dsd_clk <: 0xF0F0F0F0; + p_dsd_clk <: 0xF0F0F0F0; + p_dsd_clk <: 0xF0F0F0F0; break; - + case 4: p_dsd_clk <: 0xCCCCCCCC; p_dsd_clk <: 0xCCCCCCCC; break; - - case 2: + + case 2: p_dsd_clk <: 0xAAAAAAAA; break; - } + } } else // everyOther { everyOther = 0; - dsdSample_l = dsdSample_l | ((samplesOut[0] & 0xffff00) >> 8); - dsdSample_r = dsdSample_r | ((samplesOut[1] & 0xffff00) >> 8); + dsdSample_l = dsdSample_l | ((samplesOut[0] & 0xffff00) >> 8); + dsdSample_r = dsdSample_r | ((samplesOut[1] & 0xffff00) >> 8); // Output 16 clocks DSD to all //p_dsd_dac[0] <: bitrev(dsdSample_l); @@ -587,21 +587,21 @@ static inline void doI2SClocks(unsigned divide) switch (divide) { case 8: - p_dsd_clk <: 0xF0F0F0F0; - p_dsd_clk <: 0xF0F0F0F0; - p_dsd_clk <: 0xF0F0F0F0; - p_dsd_clk <: 0xF0F0F0F0; + p_dsd_clk <: 0xF0F0F0F0; + p_dsd_clk <: 0xF0F0F0F0; + p_dsd_clk <: 0xF0F0F0F0; + p_dsd_clk <: 0xF0F0F0F0; break; - + case 4: p_dsd_clk <: 0xCCCCCCCC; p_dsd_clk <: 0xCCCCCCCC; break; - - case 2: + + case 2: p_dsd_clk <: 0xAAAAAAAA; break; - } + } } } @@ -614,26 +614,26 @@ static inline void doI2SClocks(unsigned divide) #if (I2S_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT != 0) #pragma loop unroll for(int i = 0; i < I2S_CHANS_DAC; i+=2) - { + { p_i2s_dac[tmp++] <: bitrev(samplesOut[i]); /* Output LEFT sample to DAC */ } #endif - -#ifndef CODEC_MASTER - /* LR clock delayed by one clock, This is so MSB is output on the falling edge of BCLK + +#ifndef CODEC_MASTER + /* LR clock delayed by one clock, This is so MSB is output on the falling edge of BCLK * after the falling edge on which LRCLK was toggled. (see I2S spec) */ - /* Generate clocks LR Clock low - LEFT */ + /* Generate clocks LR Clock low - LEFT */ p_lrclk <: 0x80000000; doI2SClocks(divide); #endif - - + + #if (I2S_CHANS_ADC != 0) /* Input prevous R sample into R in buffer */ index = 0; #pragma loop unroll for(int i = 1; i < I2S_CHANS_ADC; i += 2) - { + { p_i2s_adc[index++] :> sample; #if NUM_USB_CHAN_IN > 0 samplesIn[i] = bitrev(sample); @@ -643,28 +643,28 @@ static inline void doI2SClocks(unsigned divide) #endif } #endif - -#if defined(SPDIF) && (NUM_USB_CHAN_OUT > 0) + +#if defined(SPDIF) && (NUM_USB_CHAN_OUT > 0) outuint(c_spd_out, samplesOut[SPDIF_TX_INDEX]); /* Forward sample to S/PDIF Tx thread */ - sample = samplesOut[SPDIF_TX_INDEX + 1]; + sample = samplesOut[SPDIF_TX_INDEX + 1]; outuint(c_spd_out, sample); /* Forward sample to S/PDIF Tx thread */ -#endif +#endif tmp = 0; #pragma xta endpoint "i2s_output_r" #if (I2S_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT != 0) #pragma loop unroll for(int i = 1; i < I2S_CHANS_DAC; i+=2) - { + { p_i2s_dac[tmp++] <: bitrev(samplesOut[i]); /* Output RIGHT sample to DAC */ } #endif -#ifndef CODEC_MASTER +#ifndef CODEC_MASTER /* Clock out data (and LR clock) */ p_lrclk <: 0x7FFFFFFF; doI2SClocks(divide); -#endif - +#endif + #if (I2S_CHANS_ADC != 0) /* Input previous L ADC sample */ @@ -690,7 +690,7 @@ static inline void doI2SClocks(unsigned divide) #endif #endif - } // !dsdMode + } // !dsdMode #if (DSD_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT > 0) /* Check for DSD - note we only move into DoP mode if valid DoP Freq */ /* Currently we only check on channel 0 - we get all 0's on channels without data */ @@ -705,7 +705,7 @@ static inline void doI2SClocks(unsigned divide) dsdMode = DSD_MODE_DOP; dsdCount = 0; dsdMarker = DSD_MARKER_2; - + // Set clocks low p_lrclk <: 0; p_bclk <: 0; @@ -740,7 +740,7 @@ static inline void doI2SClocks(unsigned divide) return {0,0}; } -/* This function is a dummy version of the deliver thread that does not +/* This function is a dummy version of the deliver thread that does not connect to the codec ports. It is used during DFU reset. */ {unsigned,unsigned} static dummy_deliver(chanend c_out) { @@ -794,7 +794,7 @@ static inline void doI2SClocks(unsigned divide) #define SAMPLES_PER_PRINT 1 -void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c) +void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c) { #ifdef SPDIF chan c_spdif_out; @@ -867,7 +867,7 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c) { /* I2S has 32 bits per sample. *2 as 2 channels */ unsigned numBits = 64; - + #if (DSD_CHANS_DAC > 0) if(dsdMode == DSD_MODE_DOP) { @@ -879,10 +879,10 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c) /* DSD native we receive in 32bit chunks */ numBits = 32; } -#endif +#endif divide = mClk / ( curSamFreq * numBits ); - } - + } + #if (DSD_CHANS_DAC != 0) /* Configure audio ports */ ConfigAudioPortsWrapper( @@ -925,18 +925,18 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c) divide); #endif - + { - unsigned curFreq = curSamFreq; -#if (DSD_CHANS_DAC > 0) - /* Make AudioHwConfig() implementation a little more user friendly in DSD mode...*/ + unsigned curFreq = curSamFreq; +#if (DSD_CHANS_DAC > 0) + /* Make AudioHwConfig() implementation a little more user friendly in DSD mode...*/ if(dsdMode == DSD_MODE_NATIVE) { - curFreq *= 32; + curFreq *= 32; } else if(dsdMode == DSD_MODE_DOP) { - curFreq *= 16; + curFreq *= 16; } #endif /* Configure Clocking/CODEC/DAC/ADC for SampleFreq/MClk */ @@ -945,9 +945,9 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c) if(!firstRun) { - /* TODO wait for good mclk instead of delay */ + /* TODO wait for good mclk instead of delay */ /* No delay for DFU modes */ - if ((curSamFreq != AUDIO_REBOOT_FROM_DFU) && (curSamFreq != AUDIO_STOP_FOR_DFU) && retVal1) + if ((curSamFreq != AUDIO_REBOOT_FROM_DFU) && (curSamFreq != AUDIO_STOP_FOR_DFU) && retVal1) { #if 0 /* User should ensure MCLK is stable in AudioHwConfig */ @@ -962,34 +962,34 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c) /* Handshake back */ outct(c_mix_out, XS1_CT_END); } - } + } firstRun = 0; - + par { - -#ifdef SPDIF - { + +#ifdef SPDIF + { set_thread_fast_mode_on(); SpdifTransmit(p_spdif_tx, c_spdif_out); } -#endif - - { +#endif + + { #ifdef SPDIF /* Communicate master clock and sample freq to S/PDIF thread */ outuint(c_spdif_out, curSamFreq); outuint(c_spdif_out, mClk); -#endif +#endif {retVal1, retVal2} = deliver(c_mix_out, #ifdef SPDIF c_spdif_out, #else null, -#endif +#endif divide, curSamFreq, c_dig_rx, c); #if (DSD_CHANS_DAC != 0) @@ -1010,16 +1010,16 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c) #endif // Currently no more audio will happen after this point - if (curSamFreq == AUDIO_STOP_FOR_DFU) + if (curSamFreq == AUDIO_STOP_FOR_DFU) { outct(c_mix_out, XS1_CT_END); - while (1) + while (1) { {retVal1, curSamFreq} = dummy_deliver(c_mix_out); - if (curSamFreq == AUDIO_START_FROM_DFU) + if (curSamFreq == AUDIO_START_FROM_DFU) { outct(c_mix_out, XS1_CT_END); break; @@ -1027,9 +1027,9 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c) } } -#ifdef SPDIF +#ifdef SPDIF /* Notify S/PDIF thread of impending new freq... */ - outct(c_spdif_out, XS1_CT_END); + outct(c_spdif_out, XS1_CT_END); #endif } } diff --git a/module_usb_audio/audiostream/audiostream.c b/module_usb_audio/audiostream/audiostream.c index 90436307..16eb6826 100644 --- a/module_usb_audio/audiostream/audiostream.c +++ b/module_usb_audio/audiostream/audiostream.c @@ -4,7 +4,7 @@ void UserAudioStreamStop() __attribute__ ((weak)); void UserAudioStreamStop() { return; -} +} void UserAudioStreamStart() __attribute__ ((weak)); void UserAudioStreamStart() diff --git a/module_usb_audio/clocking.h b/module_usb_audio/clocking.h index cd6e7a71..d5524128 100644 --- a/module_usb_audio/clocking.h +++ b/module_usb_audio/clocking.h @@ -8,7 +8,7 @@ * \param c_adat_rx channel connect to ADAT receive thread * \param p port to output clock signal to drive external frequency synthesizer * \param c_audio channel connected to the audio() thread - * \param c_clk_ctl channel connected to Endpoint0() for configuration of the + * \param c_clk_ctl channel connected to Endpoint0() for configuration of the * clock * \param c_clk_int channel connected to the decouple() thread for clock interrupts diff --git a/module_usb_audio/clocking/clockgen.xc b/module_usb_audio/clocking/clockgen.xc index c0269298..a2cf7ade 100644 --- a/module_usb_audio/clocking/clockgen.xc +++ b/module_usb_audio/clocking/clockgen.xc @@ -61,7 +61,7 @@ static int channelContainsControlToken(chanend x) static void outInterrupt(chanend c_interruptControl, int value) { /* Non-blocking check for control token */ - //if (channelContainsControlToken(c_interruptControl)) + //if (channelContainsControlToken(c_interruptControl)) { outuint(c_interruptControl, value); outct(c_interruptControl, XS1_CT_END); @@ -75,20 +75,20 @@ void VendorClockValidity(int valid); #if defined(SPDIF_RX) || defined(ADAT_RX) static inline void setClockValidity(chanend c_interruptControl, int clkIndex, int valid, int currentClkMode) { - if (clockValid[clkIndex] != valid) + if (clockValid[clkIndex] != valid) { clockValid[clkIndex] = valid; outInterrupt(c_interruptControl, clockId[clkIndex]); #ifdef CLOCK_VALIDITY_CALL #ifdef ADAT_RX - if (currentClkMode == CLOCK_ADAT && clkIndex == CLOCK_ADAT_INDEX) + if (currentClkMode == CLOCK_ADAT && clkIndex == CLOCK_ADAT_INDEX) { VendorClockValidity(valid); } #endif #ifdef SPDIF_RX - if (currentClkMode == CLOCK_SPDIF && clkIndex == CLOCK_SPDIF_INDEX) + if (currentClkMode == CLOCK_SPDIF && clkIndex == CLOCK_SPDIF_INDEX) { VendorClockValidity(valid); } @@ -101,72 +101,72 @@ static inline void setClockValidity(chanend c_interruptControl, int clkIndex, in /* Returns 1 for valid clock found else 0 */ -static inline int validSamples(Counter &counter, int clockIndex) +static inline int validSamples(Counter &counter, int clockIndex) { int diff = counter.samples - counter.savedSamples; counter.savedSamples = counter.samples; - + /* Check for stable sample rate (with some small margin) */ - if (diff != 0 && abs( diff - counter.lastDiff ) < 5 ) + if (diff != 0 && abs( diff - counter.lastDiff ) < 5 ) { - counter.identicaldiffs++; - - if (counter.identicaldiffs > 10) + counter.identicaldiffs++; + + if (counter.identicaldiffs > 10) { /* Detect current sample rate (round to nearest) */ int s = -1; - - if (diff > 137 && diff < 157) + + if (diff > 137 && diff < 157) { s = 147; - } - else if (diff > 150 && diff < 170) + } + else if (diff > 150 && diff < 170) { s = 160; } else if(diff > 284 && diff < 304) { - s = 294; + s = 294; } - else if (diff > 310 && diff < 330) + else if (diff > 310 && diff < 330) { s = 320; - } + } else if (diff > 578 && diff < 598) { s = 588; } - else if (diff > 630 && diff < 650) + else if (diff > 630 && diff < 650) { s = 640; } - - /* Check if we found a valid freq */ - if (s != -1) - { + + /* Check if we found a valid freq */ + if (s != -1) + { /* Update expected samples per tick */ counter.samplesPerTick = s; - + /* Update record of external clock source sample frequency */ s *= 300; - - if (clockFreq[clockIndex] != s) + + if (clockFreq[clockIndex] != s) { clockFreq[clockIndex] = s; } - + return 1; - } - else - { + } + else + { /* Not a valid frequency - Reset counter and find another run of samples */ counter.identicaldiffs = 0; } } - } - else + } + else { counter.identicaldiffs = 0; counter.lastDiff = diff; @@ -177,7 +177,7 @@ static inline int validSamples(Counter &counter, int clockIndex) #ifdef SPDIF_RX //:badParity -/* Returns 1 for bad parity, else 0 */ +/* Returns 1 for bad parity, else 0 */ static inline int badParity(unsigned x) { unsigned X = (x>>4); @@ -230,7 +230,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan int spdifReceivedTime; unsigned tmp2; unsigned spdifLeft = 0; -#endif +#endif #ifdef ADAT_RX /* ADAT buffer state */ @@ -252,9 +252,9 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan { g_digData[i] = 0; } - - - /* Init clock unit state */ + + + /* Init clock unit state */ #ifdef SPDIF_RX clockFreq[CLOCK_SPDIF_INDEX] = 0; clockValid[CLOCK_SPDIF_INDEX] = 0; @@ -269,9 +269,9 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan clockFreq[CLOCK_ADAT_INDEX] = 0; clockInt[CLOCK_ADAT_INDEX] = 0; clockValid[CLOCK_ADAT_INDEX] = 0; - clockId[CLOCK_ADAT_INDEX] = ID_CLKSRC_ADAT; -#endif -#ifdef SPDIF_RX + clockId[CLOCK_ADAT_INDEX] = ID_CLKSRC_ADAT; +#endif +#ifdef SPDIF_RX spdifCounters.receivedSamples = 0; spdifCounters.samples = 0; spdifCounters.savedSamples = 0; @@ -294,17 +294,17 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan timeLastEdge = timeNextEdge; timeNextClockDetection = timeNextEdge + (LOCAL_CLOCK_INCREMENT / 2); timeNextEdge += LOCAL_CLOCK_INCREMENT; - + #ifdef LEVEL_METER_LEDS t_level :> levelTime; levelTime+= LEVEL_UPDATE_RATE; #endif - -#if defined(SPDIF_RX) || defined(ADAT_RX) - /* Fill channel */ + +#if defined(SPDIF_RX) || defined(ADAT_RX) + /* Fill channel */ outuint(c_dig_rx, 1); #endif - + /* Initial ref clock output and get timestamp */ p <: pinVal @ pinTime; pinTime += (unsigned short)(LOCAL_CLOCK_INCREMENT - (LOCAL_CLOCK_INCREMENT/2)); @@ -317,9 +317,9 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan #ifdef LEVEL_METER_LEDS #warning Level metering enabled case t_level when timerafter(levelTime) :> void: - + levelTime += LEVEL_UPDATE_RATE; - + /* Copy over level data and reset */ for(int i = 0; i< NUM_USB_CHAN_IN; i++) { @@ -327,10 +327,10 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan //g_inputLevelData[i] = samples_to_host_inputs[i]; asm("ldw %0, %1[%2]":"=r"(tmp):"r"(samples_to_host_inputs),"r"(i)); g_inputLevelData[i] = tmp; - + //samples_to_host_inputs[i] = 0; asm("stw %0, %1[%2]"::"r"(0),"r"(samples_to_host_inputs),"r"(i)); - + /* Guard against host polling slower than timer and missing peaks */ if(g_inputLevelData[i] > samples_to_host_inputs_buff[i]) { @@ -348,20 +348,20 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan case inuint_byref(c_clk_ctl, tmp): switch(tmp) { - case GET_SEL: - chkct(c_clk_ctl, XS1_CT_END); - + case GET_SEL: + chkct(c_clk_ctl, XS1_CT_END); + /* Send back current clock mode */ outuint(c_clk_ctl, clkMode); outct(c_clk_ctl, XS1_CT_END); - + break; - + case SET_SEL: /* Update clock mode */ tmp = inuint(c_clk_ctl); chkct(c_clk_ctl, XS1_CT_END); - + if(tmp!=0) { clkMode = tmp; @@ -378,7 +378,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan break; #endif #ifdef SPDIF_RX - case CLOCK_SPDIF: + case CLOCK_SPDIF: VendorClockValidity(clockValid[CLOCK_SPDIF_INDEX]); break; #endif @@ -391,14 +391,14 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan tmp = inuint(c_clk_ctl); chkct(c_clk_ctl, XS1_CT_END); outuint(c_clk_ctl, clockValid[tmp]); - outct(c_clk_ctl, XS1_CT_END); - break; + outct(c_clk_ctl, XS1_CT_END); + break; case GET_FREQ: tmp = inuint(c_clk_ctl); chkct(c_clk_ctl, XS1_CT_END); outuint(c_clk_ctl, clockFreq[tmp]); - outct(c_clk_ctl, XS1_CT_END); + outct(c_clk_ctl, XS1_CT_END); break; case SET_SMUX: @@ -410,7 +410,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan #endif chkct(c_clk_ctl, XS1_CT_END); break; - + default: #ifdef VENDOR_AUDCORE_REQS if(VendorAudCoreReqs(tmp, c_clk_ctl)) @@ -418,13 +418,13 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan printstrln("ERR: Bad req in clockgen\n"); break; } - - break; + + break; /* Generate local clock from timer */ case t_local when timerafter(timeNextEdge) :> void: - + /* Setup next local clock edge */ pinTime += (short) LOCAL_CLOCK_INCREMENT; pinVal = !pinVal; @@ -439,7 +439,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan /* If we are in an external clock mode and this fire, then clock invalid */ -#ifdef SPDIF_RX +#ifdef SPDIF_RX // if(clkMode == CLOCK_SPDIF) { /* We must have lost valid S/PDIF stream, reset counters, so we dont produce a double edge */ @@ -465,7 +465,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan #if defined(SPDIF_RX) || defined(ADAT_RX) case t_external when timerafter(timeNextClockDetection) :> void: - + timeNextClockDetection += (LOCAL_CLOCK_INCREMENT); #ifdef SPDIF_RX tmp = spdifCounters.samplesPerTick; @@ -478,7 +478,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan tmp = validSamples(adatCounters, CLOCK_ADAT_INDEX); setClockValidity(c_clk_int, CLOCK_ADAT_INDEX, tmp, clkMode); #endif - + break; #endif @@ -493,7 +493,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan /* Check parity and ignore if bad */ if(badParity(tmp)) continue; - + /* Get pre-amble */ tmp2 = tmp & 0xF; switch(tmp2) @@ -501,7 +501,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan /* LEFT */ case FRAME_X: case FRAME_Z: - + spdifLeft = tmp << 4; break; @@ -523,12 +523,12 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan if(spdifSamps > MAX_SPDIF_SAMPLES-1) { spdifOverflow = 1; - } - + } + /* Check for coming out of under flow */ if(spdifUnderflow && (spdifSamps >= (MAX_SPDIF_SAMPLES >> 1))) { - spdifUnderflow = 0; + spdifUnderflow = 0; } } break; @@ -544,19 +544,19 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan if(clkMode == CLOCK_SPDIF && clockValid[CLOCK_SPDIF_INDEX]) { spdifCounters.receivedSamples+=1; - + /* Inspect for if we need to produce an edge */ if((spdifCounters.receivedSamples >= spdifCounters.samplesPerTick)) { /* Check edge is about right... S/PDIF may have changed freq... */ if(timeafter(spdifReceivedTime, (timeLastEdge + LOCAL_CLOCK_INCREMENT - LOCAL_CLOCK_MARGIN))) - { + { /* Record edge time */ timeLastEdge = spdifReceivedTime; - - /* Setup for next edge */ + + /* Setup for next edge */ timeNextEdge = spdifReceivedTime + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN; - + /* Toggle edge */ p <: pinVal @ pinTime; pinTime += (short) LOCAL_CLOCK_INCREMENT; @@ -569,7 +569,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan } } break; -#endif +#endif #ifdef ADAT_RX /* receive sample from ADAT rx thread (streaming channel with CT_END) */ case inuint_byref(c_adat_rx, tmp): @@ -588,7 +588,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan /* audio sample */ adatSamplesEver++; adatFrame[adatChannel] = tmp; - + adatChannel++; if (adatChannel == 8) { @@ -637,7 +637,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan if(adatChannel == 4 || adatChannel == 8) { adatCounters.samples += 1; - + if (clkMode == CLOCK_ADAT && clockValid[CLOCK_ADAT_INDEX]) { adatCounters.receivedSamples += 1; @@ -647,13 +647,13 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan { /* Check edge is about right... S/PDIF may have changed freq... */ if (timeafter(adatReceivedTime, (timeLastEdge + LOCAL_CLOCK_INCREMENT - LOCAL_CLOCK_MARGIN))) - { + { /* Record edge time */ timeLastEdge = adatReceivedTime; - - /* Setup for next edge */ + + /* Setup for next edge */ timeNextEdge = adatReceivedTime + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN; - + /* Toggle edge */ p <: pinVal @ pinTime; pinTime += LOCAL_CLOCK_INCREMENT; @@ -686,7 +686,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan } else { - /* Read out samples from S/PDIF buffer and send... */ + /* Read out samples from S/PDIF buffer and send... */ tmp = spdifSamples[spdifRd]; tmp2 = spdifSamples[spdifRd + 1]; @@ -700,7 +700,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan spdifSamps -= 2; - /* spdifSamps could go to -1 */ + /* spdifSamps could go to -1 */ if(spdifSamps < 0) { /* We're out of S/PDIF samples, mark underflow condition */ @@ -715,7 +715,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan spdifOverflow = 0; } } - + #endif #ifdef ADAT_RX if (adatUnderflow) @@ -735,14 +735,14 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan /* TODO SMUX II mode */ /* read out samples from the ADAT buffer and send */ /* always return 8 samples */ - if (smux) + if (smux) { /* SMUX mode - 4 samples from fifo and 4 zero samples */ g_digData[2] = adatSamples[adatRd + 0]; g_digData[3] = adatSamples[adatRd + 1]; g_digData[4] = adatSamples[adatRd + 2]; g_digData[5] = adatSamples[adatRd + 3]; - + g_digData[6] = 0; g_digData[7] = 0; g_digData[8] = 0; diff --git a/module_usb_audio/dbtable.h b/module_usb_audio/dbtable.h index e760ae2e..9119d7f7 100644 --- a/module_usb_audio/dbtable.h +++ b/module_usb_audio/dbtable.h @@ -1,14 +1,14 @@ /** * @file dbtable.h * @brief 128 entry + neg inf db table from -inf to 0xffffffff - * @author Ross Owen, XMOS Semiconductor + * @author Ross Owen, XMOS Semiconductor * @version 1.0 */ #ifndef _DBTABLE_ #define _DBTABLE_ -static unsigned dbTable[129] = +static unsigned dbTable[129] = { 4294967295, /* 0 -> 0xffffffff */ 3827893631, diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index cd85c3a9..863fc691 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -1,4 +1,4 @@ -/** +/** * @brief Defines relating to device configuration and customisation. * @author Ross Owen, XMOS Limited */ @@ -35,23 +35,23 @@ #else #define NATIVE_DSD 1 /* Always enable Native DSD when DSD mode is enabled */ #endif -#else +#else #define DSD_CHANS_DAC 0 #endif /* Max supported sample freq for device */ #ifndef MAX_FREQ -#define MAX_FREQ (192000) +#define MAX_FREQ (192000) #endif /* Min supported sample freq for device */ #ifndef MIN_FREQ -#define MIN_FREQ (44100) +#define MIN_FREQ (44100) #endif #if ((MCLK_44 % MIN_FREQ) == 0) #define MIN_FREQ_44 MIN_FREQ -#define MIN_FREQ_48 ((48000 * 512)/((44100 * 512)/MIN_FREQ)) +#define MIN_FREQ_48 ((48000 * 512)/((44100 * 512)/MIN_FREQ)) #endif #if ((MCLK_48 % MIN_FREQ) == 0) @@ -189,15 +189,15 @@ /* Default device sample frequency */ #ifndef DEFAULT_FREQ -#define DEFAULT_FREQ (MIN_FREQ) +#define DEFAULT_FREQ (MIN_FREQ) #endif /* Master clock defines (in Hz) */ -#ifndef MCLK_441 +#ifndef MCLK_441 #error MCLK_441 not defined #endif -#ifndef MCLK_48 +#ifndef MCLK_48 #error MCLK_441 not defined #endif @@ -209,19 +209,19 @@ #error Bad DEFAULT_MCLK_FREQ #endif -/* The number of clock ticks to wait for the audio feeback to stabalise +/* The number of clock ticks to wait for the audio feeback to stabalise * Note, feedback always counts 128 SOFs (16ms @ HS, 128ms @ FS) */ #ifndef FEEDBACK_STABILITY_DELAY_HS -#define FEEDBACK_STABILITY_DELAY_HS (2000000) +#define FEEDBACK_STABILITY_DELAY_HS (2000000) #endif #ifndef FEEDBACK_STABILITY_DELAY_FS -#define FEEDBACK_STABILITY_DELAY_FS (20000000) +#define FEEDBACK_STABILITY_DELAY_FS (20000000) #endif /* Vendor String */ #ifndef VENDOR_STR -#define VENDOR_STR "XMOS" +#define VENDOR_STR "XMOS" #endif /* USB Vendor ID */ @@ -248,18 +248,18 @@ /* USB Product ID (PID) for Audio Class 1.0 mode */ #if (AUDIO_CLASS==1) || defined(AUDIO_CLASS_FALLBACK) #ifndef PID_AUDIO_1 -#define PID_AUDIO_1 (0x0003) +#define PID_AUDIO_1 (0x0003) #endif #endif /* USB Product ID (PID) for Audio Class 2.0 mode */ #ifndef PID_AUDIO_2 -#define PID_AUDIO_2 (0x0002) +#define PID_AUDIO_2 (0x0002) #endif /* Device release number in BCD: 0xJJMN */ -#define BCD_DEVICE_J 6 -#define BCD_DEVICE_M 3 +#define BCD_DEVICE_J 1 +#define BCD_DEVICE_M 0 #define BCD_DEVICE_N 3 #ifndef BCD_DEVICE @@ -269,7 +269,7 @@ /* Sample Sub-slot size (bytes) for High Speed. Default is 4 bytes */ #ifndef SAMPLE_SUBSLOT_SIZE_HS #define SAMPLE_SUBSLOT_SIZE_HS 4 -#endif +#endif #if (SAMPLE_SUBSLOT_SIZE_HS != 2) && (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_HS != 4) #error Only SAMPLE_SUBSLOT_SIZE_HS 2, 3 or 4 supported #SAMPLE_SUBSLOT_SIZE_HS @@ -278,7 +278,7 @@ /* Sample Sub-slot size (bytes) for Full Speed. Default is 3 bytes */ #ifndef SAMPLE_SUBSLOT_SIZE_FS #define SAMPLE_SUBSLOT_SIZE_FS 3 -#endif +#endif #if (SAMPLE_SUBSLOT_SIZE_FS != 2) && (SAMPLE_SUBSLOT_SIZE_FS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 4) #error Only SAMPLE_SUBSLOT_SIZE_FS 2, 3 or 4 supported @@ -287,7 +287,7 @@ /* Sample bit resolution for High Speed. Default 24bit*/ #ifndef SAMPLE_BIT_RESOLUTION_HS #define SAMPLE_BIT_RESOLUTION_HS 24 -#endif +#endif #if (SAMPLE_BIT_RESOLUTION_HS/8) > SAMPLE_SUBSLOT_SIZE_HS #error SAMPLE_BIT_RESOLUTION_HS is too big for SAMPLE_SUBSLOT_SIZE_HS @@ -296,7 +296,7 @@ /* Sample bit resolution for Full Speed. Default 24bit*/ #ifndef SAMPLE_BIT_RESOLUTION_FS #define SAMPLE_BIT_RESOLUTION_FS 24 -#endif +#endif #if (SAMPLE_BIT_RESOLUTION_FS/8) > SAMPLE_SUBSLOT_SIZE_FS #error SAMPLE_BIT_RESOLUTION_FS is too big for SAMPLE_SUBSLOT_SIZE_FS @@ -372,7 +372,7 @@ #endif /* Define for number of audio interfaces (+1 for mandatory control interface) */ -#define AUDIO_INTERFACES (INPUT_INTERFACES + OUTPUT_INTERFACES + 1) +#define AUDIO_INTERFACES (INPUT_INTERFACES + OUTPUT_INTERFACES + 1) /* Interface number defines */ #define INTERFACE_NUM_IAP (INPUT_INTERFACES+OUTPUT_INTERFACES+MIDI_INTERFACES+DFU_INTERFACES+1) @@ -400,13 +400,13 @@ #define EP_ADR_IN_IAP (EP_NUM_IN_IAP | 0x80) #define EP_ADR_IN_IAP_INT (EP_NUM_IN_IAP_INT | 0x80) -#define EP_ADR_OUT_AUD EP_NUM_OUT_AUD -#define EP_ADR_OUT_MIDI EP_NUM_OUT_MIDI -#define EP_ADR_OUT_IAP EP_NUM_OUT_IAP +#define EP_ADR_OUT_AUD EP_NUM_OUT_AUD +#define EP_ADR_OUT_MIDI EP_NUM_OUT_MIDI +#define EP_ADR_OUT_IAP EP_NUM_OUT_IAP /* Endpoint count totals */ -#define EP_CNT_OUT (1 + 1 /*NUM_EP_OUT_AUD*/ + EP_CNT_OUT_MIDI + EP_CNT_OUT_IAP) /* +1 due to EP0 */ +#define EP_CNT_OUT (1 + 1 /*NUM_EP_OUT_AUD*/ + EP_CNT_OUT_MIDI + EP_CNT_OUT_IAP) /* +1 due to EP0 */ #define EP_CNT_IN (1 + 2 /*NUM_EP_IN_AUD*/ + EP_CNT_IN_AUD_INT + EP_CNT_IN_MIDI + EP_CNT_IN_IAP + EP_CNT_IN_HID) /* +1 due to EP0 */ #define AUDIO_STOP_FOR_DFU (0x12345678) @@ -429,7 +429,7 @@ #define NUM_CLOCKS (3) #elif defined(SPDIF_RX) || defined(ADAT_RX) #define NUM_CLOCKS (2) -#else +#else #define NUM_CLOCKS (1) #endif @@ -442,8 +442,8 @@ /* Audio Unit ID defines */ -#define FU_USBIN 11 /* Feature Unit: USB Audio device -> host */ -#define FU_USBOUT 10 /* Feature Unit: USB Audio host -> device*/ +#define FU_USBIN 11 /* Feature Unit: USB Audio device -> host */ +#define FU_USBOUT 10 /* Feature Unit: USB Audio host -> device*/ #define ID_IT_USB 2 /* Input terminal: USB streaming */ #define ID_IT_AUD 1 /* Input terminal: Analogue input */ #define ID_OT_USB 22 /* Output terminal: USB streaming */ @@ -496,7 +496,7 @@ #ifndef MIN_MIXER_VOLUME -/* The minimum volume setting for the mixer unit above -inf. +/* The minimum volume setting for the mixer unit above -inf. This is a signed 8.8 fixed point number that must be strictly greater than -128 (0x8000) */ /* Default min volume is -127db */ @@ -504,7 +504,7 @@ #endif #ifndef MAX_MIXER_VOLUME -/* The maximum volume setting for the mixer. +/* The maximum volume setting for the mixer. This is a signed 8.8 fixed point number. */ /* Default max volume is 0db */ #define MAX_MIXER_VOLUME (0x0000) diff --git a/module_usb_audio/endpoint0/audiorequests.xc b/module_usb_audio/endpoint0/audiorequests.xc index c45f37ed..c5bd4003 100644 --- a/module_usb_audio/endpoint0/audiorequests.xc +++ b/module_usb_audio/endpoint0/audiorequests.xc @@ -24,7 +24,7 @@ extern unsigned int multIn[NUM_USB_CHAN_IN + 1]; extern int interfaceAlt[]; -/* Global volume and mute tables */ +/* Global volume and mute tables */ extern int volsOut[]; extern unsigned int mutesOut[]; @@ -51,7 +51,7 @@ extern unsigned char mixSel[MIX_INPUTS]; /* Global var for current frequency, set to default freq */ unsigned int g_curSamFreq = DEFAULT_FREQ; unsigned int g_curSamFreq48000Family = DEFAULT_FREQ % 48000 == 0; -unsigned int g_curSamFreqMultiplier = DEFAULT_FREQ / (DEFAULT_MCLK_FREQ / 512); +unsigned int g_curSamFreqMultiplier = DEFAULT_FREQ / (DEFAULT_MCLK_FREQ / 512); /* Store an int into a char array: Note this allows non-word aligned access unlike reinerpret cast */ static void storeInt(unsigned char buffer[], int index, int val) @@ -83,14 +83,14 @@ static void storeFreq(unsigned char buffer[], int &i, int freq) /* Delay based on USB speed. Feedback takes longer to stabilise at FS */ void FeedbackStabilityDelay() { - - unsigned usbSpeed; + + unsigned usbSpeed; timer t; unsigned time; unsigned delay; - + asm("ldw %0, dp[g_curUsbSpeed]" : "=r" (usbSpeed) :); - + if (usbSpeed == XUD_SPEED_HS) { delay = FEEDBACK_STABILITY_DELAY_HS; @@ -138,7 +138,7 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl) case FU_USBOUT: { unsigned master_vol = volsOut[0] == 0x8000 ? 0 : db_to_mult(volsOut[0], 8, 29); - + for (int i = 1; i < (NUM_USB_CHAN_OUT + 1); i++) { /* Calc multipliers with 29 fractional bits from a db value with 8 fractional bits */ @@ -148,9 +148,9 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl) x = longMul(master_vol, vol, 29) * !mutesOut[0] * !mutesOut[i]; #ifdef OUT_VOLUME_IN_MIXER - if (!isnull(c_mix_ctl)) + if (!isnull(c_mix_ctl)) { - outuint(c_mix_ctl, SET_MIX_OUT_VOL); + outuint(c_mix_ctl, SET_MIX_OUT_VOL); outuint(c_mix_ctl, i-1); outuint(c_mix_ctl, x); outct(c_mix_ctl, XS1_CT_END); @@ -165,7 +165,7 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl) case FU_USBIN: { unsigned master_vol = volsIn[0] == 0x8000 ? 0 : db_to_mult(volsIn[0], 8, 29); - for (int i = 1; i < (NUM_USB_CHAN_IN + 1); i++) + for (int i = 1; i < (NUM_USB_CHAN_IN + 1); i++) { /* Calc multipliers with 29 fractional bits from a db value with 8 fractional bits */ /* 0x8000 is a special value representing -inf (i.e. mute) */ @@ -176,7 +176,7 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl) #ifdef IN_VOLUME_IN_MIXER if (!isnull(c_mix_ctl)) { - outuint(c_mix_ctl, SET_MIX_IN_VOL); + outuint(c_mix_ctl, SET_MIX_IN_VOL); outuint(c_mix_ctl, i-1); outuint(c_mix_ctl, x); outct(c_mix_ctl, XS1_CT_END); @@ -191,10 +191,10 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl) default: break; } -} +} static void updateVol(int unitID, int channel, chanend ?c_mix_ctl) -{ +{ int x; #ifndef OUT_VOLUME_IN_MIXER xc_ptr p_multOut = array_to_xc_ptr(multOut); @@ -211,7 +211,7 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl) { switch( unitID ) { - case FU_USBOUT: + case FU_USBOUT: { /* Calc multipliers with 29 fractional bits from a db value with 8 fractional bits */ /* 0x8000 is a special value representing -inf (i.e. mute) */ @@ -223,7 +223,7 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl) #ifdef OUT_VOLUME_IN_MIXER if (!isnull(c_mix_ctl)) { - outuint(c_mix_ctl, SET_MIX_OUT_VOL); + outuint(c_mix_ctl, SET_MIX_OUT_VOL); outuint(c_mix_ctl, channel-1); outuint(c_mix_ctl, x); outct(c_mix_ctl, XS1_CT_END); @@ -233,7 +233,7 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl) #endif break; } - case FU_USBIN: + case FU_USBIN: { /* Calc multipliers with 29 fractional bits from a db value with 8 fractional bits */ /* 0x8000 is a special value representing -inf (i.e. mute) */ @@ -243,26 +243,26 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl) x = longMul(master_vol, vol, 29) * !mutesIn[0] * !mutesIn[channel]; #ifdef IN_VOLUME_IN_MIXER - if (!isnull(c_mix_ctl)) + if (!isnull(c_mix_ctl)) { - outuint(c_mix_ctl, SET_MIX_IN_VOL); + outuint(c_mix_ctl, SET_MIX_IN_VOL); outuint(c_mix_ctl, channel-1); outuint(c_mix_ctl, x); outct(c_mix_ctl, XS1_CT_END); } #else asm("stw %0, %1[%2]"::"r"(x),"r"(p_multIn),"r"(channel-1)); -#endif +#endif break; } } } } -/* Handles the audio class specific requests - * returns: 0 if request dealt with successfully without error, +/* Handles the audio class specific requests + * returns: 0 if request dealt with successfully without error, * <0 for device reset - * else 1 + * else 1 */ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctl ) @@ -276,9 +276,9 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c /* Inspect request, NOTE: these are class specific requests */ switch( sp.bRequest ) { - + /* CUR Request*/ - case CUR: + case CUR: { /* Extract unitID from wIndex */ unitID = sp.wIndex >> 8; @@ -286,32 +286,32 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c switch( unitID ) { /* Clock Unit(s) */ - case ID_CLKSRC_INT: - case ID_CLKSRC_EXT: + case ID_CLKSRC_INT: + case ID_CLKSRC_EXT: case ID_CLKSRC_ADAT: { /* Check Control selector (CS) */ switch( sp.wValue >> 8 ) { /* Sample Frequency control */ - case CS_SAM_FREQ_CONTROL: + case CS_SAM_FREQ_CONTROL: { /* Direction: Host-to-device */ - if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) + if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) { /* Get OUT data with Sample Rate into buffer*/ datalength = XUD_GetBuffer(ep0_out, buffer); - + /* Check for reset/suspend */ if(datalength < 0) { return datalength; } - + if(datalength == 4) { /* Re-construct Sample Freq */ - i_tmp = buffer[0] | (buffer[1] << 8) | buffer[2] << 16 | buffer[3] << 24; + i_tmp = buffer[0] | (buffer[1] << 8) | buffer[2] << 16 | buffer[3] << 24; /* Instruct audio thread to change sample freq (if change required) */ if(i_tmp != g_curSamFreq) @@ -331,30 +331,30 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c setG_curSamFreqMultiplier(g_curSamFreq/(i_tmp/512)); outuint(c_audioControl, SET_SAMPLE_FREQ); - outuint(c_audioControl, g_curSamFreq); + outuint(c_audioControl, g_curSamFreq); /* Wait for handshake back - i.e. PLL locked and clocks okay */ chkct(c_audioControl, XS1_CT_END); - + } /* Allow time for our feedback to stabilise*/ FeedbackStabilityDelay(); } - + /* Send 0 Length as status stage */ - XUD_DoSetRequestStatus(ep0_in); + XUD_DoSetRequestStatus(ep0_in); } /* Direction: Device-to-host: Send Current Sample Freq */ else { - switch(unitID) + switch(unitID) { case ID_CLKSRC_EXT: case ID_CLKSRC_ADAT: #ifdef REPORT_SPDIF_FREQ /* Interogate clockgen thread for SPDIF freq */ - if (!isnull(c_clk_ctl)) + if (!isnull(c_clk_ctl)) { outuint(c_clk_ctl, GET_FREQ); outuint(c_clk_ctl, CLOCK_SPDIF_INDEX); @@ -368,40 +368,40 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c (buffer, unsigned[])[0] = g_curSamFreq; return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 4, sp.wLength ); } - - break; + + break; #endif case ID_CLKSRC_INT: /* Always report our current operating frequency */ (buffer, unsigned[])[0] = g_curSamFreq; return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 4, sp.wLength ); break; - + default: - /* Unknown Unit ID in Sample Frequency Control Request: unitID */ + /* Unknown Unit ID in Sample Frequency Control Request: unitID */ break; } - + } break; } /* Clock Valid Control */ - case CS_CLOCK_VALID_CONTROL: + case CS_CLOCK_VALID_CONTROL: { - switch(unitID) + switch(unitID) { case ID_CLKSRC_INT: - + /* Internal clock always valid */ buffer[0] = 1; return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 1, sp.wLength); break; - + case ID_CLKSRC_EXT: /* Interogate clockgen thread for validity */ - if (!isnull(c_clk_ctl)) + if (!isnull(c_clk_ctl)) { outuint(c_clk_ctl, GET_VALID); outuint(c_clk_ctl, CLOCK_SPDIF_INDEX); @@ -415,7 +415,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c case ID_CLKSRC_ADAT: - if (!isnull(c_clk_ctl)) + if (!isnull(c_clk_ctl)) { outuint(c_clk_ctl, GET_VALID); outuint(c_clk_ctl, CLOCK_ADAT_INDEX); @@ -425,7 +425,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 1, sp.wLength); } break; - + default: //Unknown Unit ID in Clock Valid Control Request break; @@ -436,28 +436,28 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c default: //Unknown Control Selector for Clock Unit: sp.wValue >> 8 break; - + } break; /* Clock Unit IDs */ } /* Clock Selector Unit(s) */ - case ID_CLKSEL: + case ID_CLKSEL: { - if ((sp.wValue >> 8) == CX_CLOCK_SELECTOR_CONTROL) + if ((sp.wValue >> 8) == CX_CLOCK_SELECTOR_CONTROL) { /* Direction: Host-to-device */ - if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D ) - { + if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D ) + { datalength = XUD_GetBuffer(ep0_out, buffer); - + if(datalength < 0) return datalength; /* Check for correct datalength for clock sel */ - if(datalength == 1) + if(datalength == 1) { - if (!isnull(c_clk_ctl)) + if (!isnull(c_clk_ctl)) { outuint(c_clk_ctl, SET_SEL); outuint(c_clk_ctl, buffer[0]); @@ -466,48 +466,48 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c /* Send 0 Length as status stage */ return XUD_DoSetRequestStatus(ep0_in); } - - } - else - { + + } + else + { /* Direction: Device-to-host: Send Current Selection */ - buffer[0] = 1; - if (!isnull(c_clk_ctl)) + buffer[0] = 1; + if (!isnull(c_clk_ctl)) { outuint(c_clk_ctl, GET_SEL); outct(c_clk_ctl, XS1_CT_END); - buffer[0] = inuint(c_clk_ctl); + buffer[0] = inuint(c_clk_ctl); chkct(c_clk_ctl, XS1_CT_END); } return XUD_DoGetRequest( ep0_out, ep0_in, buffer, 1, sp.wLength ); - } - } + } + } break; } - /* Feature Units */ - case FU_USBOUT: - case FU_USBIN: - + /* Feature Units */ + case FU_USBOUT: + case FU_USBIN: + /* Inspect Control Selector (CS) */ switch(sp.wValue >> 8) { - case FU_VOLUME_CONTROL: - - if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) + case FU_VOLUME_CONTROL: + + if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) { /* Expect OUT here (with volume) */ loop = XUD_GetBuffer(ep0_out, buffer); - - /* Check for reset */ + + /* Check for reset */ if(loop < 0) return loop; if(unitID == FU_USBOUT) - { - if ((sp.wValue & 0xff) <= NUM_USB_CHAN_OUT) - { + { + if ((sp.wValue & 0xff) <= NUM_USB_CHAN_OUT) + { volsOut[ sp.wValue&0xff ] = buffer[0] | (((int) (signed char) buffer[1]) << 8); updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl ); return XUD_DoSetRequestStatus(ep0_in); @@ -515,8 +515,8 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c } else { - if ((sp.wValue & 0xff) <= NUM_USB_CHAN_IN) - { + if ((sp.wValue & 0xff) <= NUM_USB_CHAN_IN) + { volsIn[ sp.wValue&0xff ] = buffer[0] | (((int) (signed char) buffer[1]) << 8); updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl ); return XUD_DoSetRequestStatus(ep0_in); @@ -527,28 +527,28 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c { if(unitID == FU_USBOUT) { - if ((sp.wValue & 0xff) <= NUM_USB_CHAN_OUT) - { + if ((sp.wValue & 0xff) <= NUM_USB_CHAN_OUT) + { buffer[0] = volsOut[ sp.wValue&0xff ]; buffer[1] = volsOut[ sp.wValue&0xff ] >> 8; - return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength); + return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength); } } else { - if ((sp.wValue & 0xff) <= NUM_USB_CHAN_IN) - { + if ((sp.wValue & 0xff) <= NUM_USB_CHAN_IN) + { buffer[0] = volsIn[ sp.wValue&0xff ]; buffer[1] = volsIn[ sp.wValue&0xff ] >> 8; - return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength); + return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength); } } } break; /* FU_VOLUME_CONTROL */ - - case FU_MUTE_CONTROL: - - if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) + + case FU_MUTE_CONTROL: + + if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) { /* Expect OUT here with mute */ loop = XUD_GetBuffer(ep0_out, buffer); @@ -558,8 +558,8 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c if (unitID == FU_USBOUT) { - if ((sp.wValue & 0xff) <= NUM_USB_CHAN_OUT) - { + if ((sp.wValue & 0xff) <= NUM_USB_CHAN_OUT) + { mutesOut[sp.wValue & 0xff] = buffer[0]; updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl); return XUD_DoSetRequestStatus(ep0_in); @@ -579,10 +579,10 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c { if(unitID == FU_USBOUT) { - if ((sp.wValue & 0xff) <= NUM_USB_CHAN_OUT) - { + if ((sp.wValue & 0xff) <= NUM_USB_CHAN_OUT) + { buffer[0] = mutesOut[sp.wValue&0xff]; - return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength); + return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength); } } else @@ -590,19 +590,19 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c if((sp.wValue & 0xff) <= NUM_USB_CHAN_IN) { buffer[0] = mutesIn[ sp.wValue&0xff ]; - return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength); + return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength); } } } break; - + default: // Unknown Control Selector for FU break; } - + break; /* FU_USBIN */ - + #if defined(MIXER) && (MAX_MIX_COUNT > 0) case ID_XU_OUT: { @@ -618,9 +618,9 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c channelMapAud[c] = buffer[0] | buffer[1] << 8; - if (!isnull(c_mix_ctl)) + if (!isnull(c_mix_ctl)) { - if (c < NUM_USB_CHAN_OUT) + if (c < NUM_USB_CHAN_OUT) { outuint(c_mix_ctl, SET_SAMPLES_TO_DEVICE_MAP); outuint(c_mix_ctl, c); @@ -656,9 +656,9 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c channelMapUsb[c] = buffer[0] | buffer[1] << 8; - if (c < NUM_USB_CHAN_IN) + if (c < NUM_USB_CHAN_IN) { - if (!isnull(c_mix_ctl)) + if (!isnull(c_mix_ctl)) { outuint(c_mix_ctl, SET_SAMPLES_TO_HOST_MAP); outuint(c_mix_ctl, c); @@ -683,18 +683,18 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c int cn = sp.wValue & 0xff; /* Channel number */ /* Check for Get or Set */ - if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_OUT) + if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_OUT) { - /* Direction: Host-to-device */ /* Host-to-device */ + /* Direction: Host-to-device */ /* Host-to-device */ datalength = XUD_GetBuffer(ep0_out, buffer); - + /* Check for reset */ if(datalength < 0) return datalength; - + if(datalength > 0) - { - /* cn bounds check for safety..*/ + { + /* cn bounds check for safety..*/ if(cn < MIX_INPUTS) { if(cs == CS_XU_MIXSEL) @@ -713,7 +713,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c outuint(c_mix_ctl, cn); /* Mixer input */ outuint(c_mix_ctl, (int) mixSel[cn]); /* Source */ outct(c_mix_ctl, XS1_CT_END); - } + } return XUD_DoSetRequestStatus(ep0_in); } } @@ -722,8 +722,8 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c else { /* Direction: Device-to-Host (GET) */ - buffer[0] = 0; - + buffer[0] = 0; + /* Channel Number bounds check for safety */ if(cn < MIX_INPUTS) { @@ -737,35 +737,35 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c } break; } - + case ID_MIXER_1: - + if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_OUT) /* Direction: Host-to-device */ { unsigned volume = 0; - + /* Expect OUT here with mute */ loop = XUD_GetBuffer(ep0_out, buffer); if(loop < 0) return loop; - + mixer1Weights[sp.wValue & 0xff] = buffer[0] | buffer[1] << 8; - - if (mixer1Weights[sp.wValue & 0xff] == 0x8000) + + if (mixer1Weights[sp.wValue & 0xff] == 0x8000) { volume = 0; } - else + else { - volume = db_to_mult(mixer1Weights[sp.wValue & 0xff], 8, 25); + volume = db_to_mult(mixer1Weights[sp.wValue & 0xff], 8, 25); } - if (!isnull(c_mix_ctl)) + if (!isnull(c_mix_ctl)) { outuint(c_mix_ctl, SET_MIX_MULT); outuint(c_mix_ctl, (sp.wValue & 0xff) % 8); outuint(c_mix_ctl, (sp.wValue & 0xff) / 8); outuint(c_mix_ctl, volume); - outct(c_mix_ctl, XS1_CT_END); + outct(c_mix_ctl, XS1_CT_END); } /* Send 0 Length as status stage */ @@ -777,35 +777,35 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c buffer[0] = weight & 0xff; buffer[1] = (weight >> 8) & 0xff; - return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength); + return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength); } break; - + #endif default: /* We dont have a unit with this ID! */ break; - - } /* switch(sp.wIndex >> 8) i.e Unit ID */ + + } /* switch(sp.wIndex >> 8) i.e Unit ID */ break; } - - case RANGE: + + case RANGE: { unitID = sp.wIndex >> 8; - + switch( unitID ) { /* Clock Source Units */ case ID_CLKSRC_EXT: case ID_CLKSRC_ADAT: - case ID_CLKSRC_INT: + case ID_CLKSRC_INT: /* Control Selector (CS) */ switch( sp.wValue >> 8 ) { - case CS_SAM_FREQ_CONTROL: - + case CS_SAM_FREQ_CONTROL: + /* Currently always return all freqs for all clocks */ { int num_freqs = 0; @@ -816,15 +816,15 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c unsigned maxFreq = MAX_FREQ; #if defined (FULL_SPEED_AUDIO_2) - unsigned usbSpeed; + unsigned usbSpeed; asm("ldw %0, dp[g_curUsbSpeed]" : "=r" (usbSpeed) :); if (usbSpeed == XUD_SPEED_FS) { maxFreq = MAX_FREQ_A1; - } -#endif - + } +#endif + while(1) { if((currentFreq44 <= maxFreq) && (currentFreq44 >= MIN_FREQ)) @@ -847,35 +847,35 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c } } storeShort(buffer, 0, num_freqs); - - return XUD_DoGetRequest(ep0_out, ep0_in, buffer, i, sp.wLength); + + return XUD_DoGetRequest(ep0_out, ep0_in, buffer, i, sp.wLength); } break; - + default: //Unknown Control Selector in Clock Source Range Request break; } - + break; /* Feature Units */ - case FU_USBIN: /* USB Data into Device */ + case FU_USBIN: /* USB Data into Device */ case FU_USBOUT: /* USB Data from Device */ /* Control Selector (CS) */ switch( sp.wValue >> 8 ) { /* Volume control, send back same range for all channels (i.e. ignore CN) */ - case FU_VOLUME_CONTROL: - + case FU_VOLUME_CONTROL: + storeShort(buffer, 0, 1); - storeShort(buffer, 2, MIN_VOLUME); - storeShort(buffer, 4, MAX_VOLUME); - storeShort(buffer, 6, VOLUME_RES); - return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength); + storeShort(buffer, 2, MIN_VOLUME); + storeShort(buffer, 4, MAX_VOLUME); + storeShort(buffer, 6, VOLUME_RES); + return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength); break; - + default: /* Unknown control selector for FU */ break; @@ -887,92 +887,92 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c /* Mixer Unit */ case ID_MIXER_1: storeShort(buffer, 0, 1); - storeShort(buffer, 2, MIN_MIXER_VOLUME); - storeShort(buffer, 4, MAX_MIXER_VOLUME); - storeShort(buffer, 6, VOLUME_RES_MIXER); - return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength); + storeShort(buffer, 2, MIN_MIXER_VOLUME); + storeShort(buffer, 4, MAX_MIXER_VOLUME); + storeShort(buffer, 6, VOLUME_RES_MIXER); + return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength); break; -#endif +#endif default: /* Unknown Unit ID in Range Request selector for FU */ break; - - } - + + } + break; /* case: RANGE */ } -#if defined (MIXER) && (MAX_MIX_COUNT > 0) +#if defined (MIXER) && (MAX_MIX_COUNT > 0) case MEM: /* Memory Requests (5.2.7.1) */ unitID = sp.wIndex >> 8; - + switch( unitID ) { case ID_MIXER_1: - - if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_IN) + + if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_IN) { int length = 0; - - /* Device-to-Host (GET) */ + + /* Device-to-Host (GET) */ switch(sp.wValue) /* offset */ { case 0: /* Input levels */ length = (NUM_USB_CHAN_IN + NUM_USB_CHAN_OUT) * 2; /* 2 bytes per chan */ - + for(int i = 0; i < (NUM_USB_CHAN_IN + NUM_USB_CHAN_OUT); i++) { /* Get the level and truncate to 16-bit */ - if(i < NUM_USB_CHAN_IN) + if(i < NUM_USB_CHAN_IN) { - if (!isnull(c_mix_ctl)) + if (!isnull(c_mix_ctl)) { outuint(c_mix_ctl, GET_INPUT_LEVELS); outuint(c_mix_ctl, (i - NUM_USB_CHAN_IN)); outct(c_mix_ctl, XS1_CT_END); storeShort(buffer, i*2, (inuint(c_mix_ctl)>>15)); chkct(c_mix_ctl, XS1_CT_END); - } - else + } + else { storeShort(buffer, i*2, 0); } - } - else + } + else { - if (!isnull(c_mix_ctl)) + if (!isnull(c_mix_ctl)) { outuint(c_mix_ctl, GET_STREAM_LEVELS); outuint(c_mix_ctl, (i - NUM_USB_CHAN_IN)); outct(c_mix_ctl, XS1_CT_END); storeShort(buffer, i*2, (inuint(c_mix_ctl) >> 15)); chkct(c_mix_ctl, XS1_CT_END); - } - else + } + else { storeShort(buffer, i*2, 0); } } } - + break; - + case 1: /* Mixer Output levels */ - length = MAX_MIX_COUNT * 2; /* 2 bytes per chan */ + length = MAX_MIX_COUNT * 2; /* 2 bytes per chan */ for(int i = 0; i < MAX_MIX_COUNT; i++) { - if (!isnull(c_mix_ctl)) + if (!isnull(c_mix_ctl)) { outuint(c_mix_ctl, GET_OUTPUT_LEVELS); outuint(c_mix_ctl, i); outct(c_mix_ctl, XS1_CT_END); storeShort(buffer, i*2, (inuint(c_mix_ctl) >> 15)); chkct(c_mix_ctl, XS1_CT_END); - } - else + } + else { storeShort(buffer, i*2, 0); } @@ -998,14 +998,14 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctl) { /* At this point we know: - * bmRequestType.Recipient = Endpoint + * bmRequestType.Recipient = Endpoint * bmRequestType.Type = Class * endpoint (wIndex & 0xff) is 0x01 or 0x82 */ - + int retVal = 1; - unsigned char buffer[1024]; - + unsigned char buffer[1024]; + /* Host to Device */ if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) { @@ -1016,27 +1016,27 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp { /* Check Control Selector */ unsigned short controlSelector = sp.wValue>>8; - + retVal = XUD_GetBuffer(ep0_out, buffer); /* Inspect for reset */ if(retVal < 0) return retVal; - + if(controlSelector == SAMPLING_FREQ_CONTROL) { /* Expect length 3 for sample rate */ if((sp.wLength == 3)&&(retVal == 3)) { - + /* Recontruct sample-freq */ int i_tmp = buffer[0] | (buffer [1] << 8) | (buffer[2] << 16); if(i_tmp != g_curSamFreq) { int curSamFreq44100Family; - - /* Windows Audio Class driver has a nice habbit of sending invalid SF's (e.g. 48001Hz) + + /* Windows Audio Class driver has a nice habbit of sending invalid SF's (e.g. 48001Hz) * when under stress. Lets double check it here and ignore if not valid. */ g_curSamFreq48000Family = i_tmp % 48000 == 0; curSamFreq44100Family = i_tmp % 44100 == 0; @@ -1054,16 +1054,16 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp i_tmp = MCLK_441; } - //setG_curSamFreqMultiplier(g_curSamFreq/(i_tmp/512)); - setG_curSamFreqMultiplier((g_curSamFreq*512)/i_tmp); + //setG_curSamFreqMultiplier(g_curSamFreq/(i_tmp/512)); + setG_curSamFreqMultiplier((g_curSamFreq*512)/i_tmp); /* Instruct audio thread to change sample freq */ outuint(c_audioControl, SET_SAMPLE_FREQ); - outuint(c_audioControl, g_curSamFreq); + outuint(c_audioControl, g_curSamFreq); /* Wait for handshake back - i.e. pll locked and clocks okay */ chkct(c_audioControl, XS1_CT_END); - + /* Allow time for the change - feedback to stabilise */ FeedbackStabilityDelay(); } @@ -1111,9 +1111,9 @@ int AudioClassRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c /* Inspect for reset */ if(loop < 0) return loop; - + unitID = sp.wIndex >> 8; - + if (unitID == FU_USBOUT) { switch ((sp.wValue>>8) & 0xff) @@ -1152,49 +1152,49 @@ int AudioClassRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c switch ((sp.wValue>>8) & 0xff) { case FU_VOLUME_CONTROL: - { + { buffer[0] = volsOut[ sp.wValue&0xff ]; buffer[1] = volsOut[ sp.wValue&0xff ] >> 8; return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength); break; } case FU_MUTE_CONTROL: - { + { buffer[0] = mutesOut[ sp.wValue & 0xff ]; return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 1, sp.wLength); break; } - } + } } else if (unitID == FU_USBIN) { switch ((sp.wValue>>8) & 0xff) { case FU_VOLUME_CONTROL: - { + { buffer[0] = volsIn[ sp.wValue&0xff ]; buffer[1] = volsIn[ sp.wValue&0xff ] >> 8; return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength); } case FU_MUTE_CONTROL: - { + { buffer[0] = mutesIn[ sp.wValue & 0xff ]; return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 1, sp.wLength); } - } - } + } + } break; } case UAC_B_REQ_GET_MIN: buffer[0] = (MIN_MIXER_VOLUME & 0xff); buffer[1] = (MIN_MIXER_VOLUME >> 8); return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength); - + case UAC_B_REQ_GET_MAX: buffer[0] = (MAX_MIXER_VOLUME & 0xff); buffer[1] = (MAX_MIXER_VOLUME >> 8); return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength); - + case UAC_B_REQ_GET_RES: buffer[0] = (VOLUME_RES_MIXER & 0xff); buffer[1] = (VOLUME_RES_MIXER >> 8); diff --git a/module_usb_audio/endpoint0/dbcalc.h b/module_usb_audio/endpoint0/dbcalc.h index 2207d005..81798107 100644 --- a/module_usb_audio/endpoint0/dbcalc.h +++ b/module_usb_audio/endpoint0/dbcalc.h @@ -8,7 +8,7 @@ Parameters: db - The db value to convert. - db_frac_bits - The number of binary fractional bits in the supplied decibel value + db_frac_bits - The number of binary fractional bits in the supplied decibel value result_frac_bits - The number of required fractional bits in the result. Returns: diff --git a/module_usb_audio/endpoint0/dbcalc.xc b/module_usb_audio/endpoint0/dbcalc.xc index e1a70f3b..5b6ea4a2 100644 --- a/module_usb_audio/endpoint0/dbcalc.xc +++ b/module_usb_audio/endpoint0/dbcalc.xc @@ -21,7 +21,7 @@ static unsigned coef[14] = {2407, 13778, 64588, 308051, 1346110, 5261991, 182775 Parameters: db - The db value to convert. - db_frac_bits - The number of binary fractional bits in the supplied decibel value + db_frac_bits - The number of binary fractional bits in the supplied decibel value result_frac_bits - The number of required fractional bits in the result. Returns: @@ -37,24 +37,24 @@ unsigned db_to_mult(int db, int db_frac_bits, int result_frac_bits) unsigned mask = ~((1<> DB_CALC_PREC; if (intpart) { @@ -65,7 +65,7 @@ unsigned db_to_mult(int db, int db_frac_bits, int result_frac_bits) } else { intpart = (db & mask); - db = db - intpart; + db = db - intpart; intpart = intpart >> DB_CALC_PREC; if (intpart) { val0 = 1 << DB_CALC_PREC; @@ -86,20 +86,20 @@ unsigned db_to_mult(int db, int db_frac_bits, int result_frac_bits) val = (hi << (32-DB_CALC_PREC)) | (lo >> DB_CALC_PREC); val += coef[i] >> (COEF_PREC - DB_CALC_PREC); } - + /* Finally multiply by the integer power (if there was an integer part) */ if (val0) { int hi=0; unsigned lo=0; {hi, lo} = macs(val0,val,hi,lo); - val = (hi << (32-DB_CALC_PREC)) | (lo >> DB_CALC_PREC); + val = (hi << (32-DB_CALC_PREC)) | (lo >> DB_CALC_PREC); } - + /* We now have the result, just need to scale it to the required precision */ ret = val; - + if (result_frac_bits > DB_CALC_PREC) { return ret<<(result_frac_bits-DB_CALC_PREC); } @@ -113,7 +113,7 @@ unsigned db_to_mult(int db, int db_frac_bits, int result_frac_bits) int main() { - /* Check that we don't overflow up to 9db + /* Check that we don't overflow up to 9db Should give a value just under 0x80000 */ printhexln(db_to_mult(9,0,16)); diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index 37fe7b29..67969fc7 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -1,6 +1,6 @@ -/** - * @file DeviceDescriptors.h - * @brief Device Descriptors +/** + * @file DeviceDescriptors.h + * @brief Device Descriptors * @author Ross Owen, XMOS Limited */ @@ -11,79 +11,79 @@ #include "usb.h" #include "usbaudio20.h" /* Defines from the USB Audio 2.0 Specifications */ -#include "devicedefines.h" /* Device specific define */ +#include "devicedefines.h" /* Device specific define */ /***** Device Descriptors *****/ #if defined(AUDIO_CLASS_FALLBACK) || (AUDIO_CLASS==1) /* Device Descriptor for Audio Class 1.0 (Assumes Full-Speed) */ -unsigned char devDesc_Audio1[] = -{ +unsigned char devDesc_Audio1[] = +{ 18, /* 0 bLength : Size of descriptor in Bytes (18 Bytes) */ - USB_DEVICE, /* 1 bdescriptorType */ + USB_DEVICE, /* 1 bdescriptorType */ 0x0, /* 2 bcd USB */ - 0x2, /* 3 bcdUSB */ - 0, /* 4 bDeviceClass */ - 0, /* 5 bDeviceSubClass */ - 0, /* 6 bDeviceProtocol */ + 0x2, /* 3 bcdUSB */ + 0, /* 4 bDeviceClass */ + 0, /* 5 bDeviceSubClass */ + 0, /* 6 bDeviceProtocol */ 64, /* 7 bMaxPacketSize */ - (VENDOR_ID & 0xFF), /* 8 idVendor */ - (VENDOR_ID >> 8), /* 9 idVendor */ - (PID_AUDIO_1 & 0xFF), /* 10 idProduct */ - (PID_AUDIO_1 >> 8), /* 11 idProduct */ - (BCD_DEVICE & 0xFF), /* 12 bcdDevice : Device release number */ - (BCD_DEVICE >> 8), /* 13 bcdDevice : Device release number */ - MANUFACTURER_STR_INDEX, /* 14 iManufacturer : Index of manufacturer string */ - 8, /* 15 iProduct : Index of product string descriptor */ - 0,//SERIAL_STR_INDEX, /* 16 iSerialNumber : Index of serial number decriptor */ - 0x01 /* 17 bNumConfigurations : Number of possible configs. */ -}; + (VENDOR_ID & 0xFF), /* 8 idVendor */ + (VENDOR_ID >> 8), /* 9 idVendor */ + (PID_AUDIO_1 & 0xFF), /* 10 idProduct */ + (PID_AUDIO_1 >> 8), /* 11 idProduct */ + (BCD_DEVICE & 0xFF), /* 12 bcdDevice : Device release number */ + (BCD_DEVICE >> 8), /* 13 bcdDevice : Device release number */ + MANUFACTURER_STR_INDEX, /* 14 iManufacturer : Index of manufacturer string */ + 8, /* 15 iProduct : Index of product string descriptor */ + 0,//SERIAL_STR_INDEX, /* 16 iSerialNumber : Index of serial number decriptor */ + 0x01 /* 17 bNumConfigurations : Number of possible configs. */ +}; #endif /* Device Descriptor for Audio Class 2.0 (Assumes High-Speed ) */ -unsigned char devDesc_Audio2[] = +unsigned char devDesc_Audio2[] = { - 18, /* 0 bLength : Size of descriptor in Bytes (18 Bytes) */ - USB_DEVICE, /* 1 bdescriptorType */ - 0, /* 2 bcdUSB */ - 2, /* 3 bcdUSB */ - 0xEF, /* 4 bDeviceClass (See Audio Class Spec page 45) */ - 0x02, /* 5 bDeviceSubClass */ - 0x01, /* 6 bDeviceProtocol */ - 64, /* 7 bMaxPacketSize */ - (VENDOR_ID & 0xFF), /* 8 idVendor */ - (VENDOR_ID >> 8), /* 9 idVendor */ - (PID_AUDIO_2 & 0xFF), /* 10 idProduct */ - (PID_AUDIO_2 >> 8), /* 11 idProduct */ - (BCD_DEVICE & 0xFF), /* 12 bcdDevice : Device release number */ - (BCD_DEVICE >> 8), /* 13 bcdDevice : Device release number */ - MANUFACTURER_STR_INDEX, /* 14 iManufacturer : Index of manufacturer string */ - PRODUCT_STR_INDEX_A2, /* 15 iProduct : Index of product string descriptor */ - 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. */ + 18, /* 0 bLength : Size of descriptor in Bytes (18 Bytes) */ + USB_DEVICE, /* 1 bdescriptorType */ + 0, /* 2 bcdUSB */ + 2, /* 3 bcdUSB */ + 0xEF, /* 4 bDeviceClass (See Audio Class Spec page 45) */ + 0x02, /* 5 bDeviceSubClass */ + 0x01, /* 6 bDeviceProtocol */ + 64, /* 7 bMaxPacketSize */ + (VENDOR_ID & 0xFF), /* 8 idVendor */ + (VENDOR_ID >> 8), /* 9 idVendor */ + (PID_AUDIO_2 & 0xFF), /* 10 idProduct */ + (PID_AUDIO_2 >> 8), /* 11 idProduct */ + (BCD_DEVICE & 0xFF), /* 12 bcdDevice : Device release number */ + (BCD_DEVICE >> 8), /* 13 bcdDevice : Device release number */ + MANUFACTURER_STR_INDEX, /* 14 iManufacturer : Index of manufacturer string */ + PRODUCT_STR_INDEX_A2, /* 15 iProduct : Index of product string descriptor */ + 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. */ }; /* Device Descriptor for Null Device */ -unsigned char devDesc_Null[] = +unsigned char devDesc_Null[] = { - 18, /* 0 bLength : Size of descriptor in Bytes (18 Bytes) */ - USB_DEVICE, /* 1 bdescriptorType */ - 0, /* 2 bcdUSB */ - 2, /* 3 bcdUSB */ - 0x0, /* 4 bDeviceClass */ - 0x0 , /* 5 bDeviceSubClass */ - 0x00, /* 6 bDeviceProtocol */ - 64, /* 7 bMaxPacketSize */ - (VENDOR_ID & 0xFF), /* 8 idVendor */ - (VENDOR_ID >> 8), /* 9 idVendor */ - (PID_AUDIO_2 & 0xFF), /* 10 idProduct */ - (PID_AUDIO_2 >> 8), /* 11 idProduct */ - (BCD_DEVICE & 0xFF), /* 12 bcdDevice : Device release number */ - (BCD_DEVICE >> 8), /* 13 bcdDevice : Device release number */ - MANUFACTURER_STR_INDEX, /* 14 iManufacturer : Index of manufacturer string */ - PRODUCT_STR_INDEX_A2, /* 15 iProduct : Index of product string descriptor */ - 0,//SERIAL_STR_INDEX, /* 16 iSerialNumber : Index of serial number decriptor */ + 18, /* 0 bLength : Size of descriptor in Bytes (18 Bytes) */ + USB_DEVICE, /* 1 bdescriptorType */ + 0, /* 2 bcdUSB */ + 2, /* 3 bcdUSB */ + 0x0, /* 4 bDeviceClass */ + 0x0 , /* 5 bDeviceSubClass */ + 0x00, /* 6 bDeviceProtocol */ + 64, /* 7 bMaxPacketSize */ + (VENDOR_ID & 0xFF), /* 8 idVendor */ + (VENDOR_ID >> 8), /* 9 idVendor */ + (PID_AUDIO_2 & 0xFF), /* 10 idProduct */ + (PID_AUDIO_2 >> 8), /* 11 idProduct */ + (BCD_DEVICE & 0xFF), /* 12 bcdDevice : Device release number */ + (BCD_DEVICE >> 8), /* 13 bcdDevice : Device release number */ + MANUFACTURER_STR_INDEX, /* 14 iManufacturer : Index of manufacturer string */ + PRODUCT_STR_INDEX_A2, /* 15 iProduct : Index of product string descriptor */ + 0,//SERIAL_STR_INDEX, /* 16 iSerialNumber : Index of serial number decriptor */ 0x01 /* 17 bNumConfigurations : Number of possible configs */ }; @@ -92,49 +92,49 @@ unsigned char devDesc_Null[] = /* Device Qualifier Descriptor for Audio 2.0 device (Use when running at full-speed. Matches audio 2.0 device descriptor) */ unsigned char devQualDesc_Audio2[] = -{ - 10, /* 0 bLength (10 Bytes) */ - USB_DEVICE_QUALIFIER, /* 1 bDescriptorType */ - 0x00, /* 2 bcdUSB (Binary Coded Decimal of usb version) */ - 0x02, /* 3 bcdUSB */ - 0xEF, /* 4 bDeviceClass */ - 0x02, /* 5 bDeviceSubClass */ - 0x01, /* 6 bDeviceProtocol */ - 64, /* 7 bMaxPacketSize */ - 0x01, /* 8 bNumConfigurations : Number of possible configs */ - 0x00 /* 9 bReserved (must be zero) */ +{ + 10, /* 0 bLength (10 Bytes) */ + USB_DEVICE_QUALIFIER, /* 1 bDescriptorType */ + 0x00, /* 2 bcdUSB (Binary Coded Decimal of usb version) */ + 0x02, /* 3 bcdUSB */ + 0xEF, /* 4 bDeviceClass */ + 0x02, /* 5 bDeviceSubClass */ + 0x01, /* 6 bDeviceProtocol */ + 64, /* 7 bMaxPacketSize */ + 0x01, /* 8 bNumConfigurations : Number of possible configs */ + 0x00 /* 9 bReserved (must be zero) */ }; #if defined(AUDIO_CLASS_FALLBACK) || (AUDIO_CLASS==1) /* Device Qualifier Descriptor for running at high-speed (matches audio 1.0 device descriptor) */ unsigned char devQualDesc_Audio1[] = -{ - 10, /* 0 bLength (10 Bytes) */ - USB_DEVICE_QUALIFIER, /* 1 bDescriptorType */ - 0x00, /* 2 bcdUSB (Binary Coded Decimal of usb version) */ - 0x02, /* 3 bcdUSB */ - 0x00, /* 4 bDeviceClass */ - 0x00, /* 5 bDeviceSubClass */ - 0x00, /* 6 bDeviceProtocol */ - 64, /* 7 bMaxPacketSize */ - 0x01, /* 8 bNumConfigurations : Number of possible configs */ - 0x00 /* 9 bReserved (must be zero) */ +{ + 10, /* 0 bLength (10 Bytes) */ + USB_DEVICE_QUALIFIER, /* 1 bDescriptorType */ + 0x00, /* 2 bcdUSB (Binary Coded Decimal of usb version) */ + 0x02, /* 3 bcdUSB */ + 0x00, /* 4 bDeviceClass */ + 0x00, /* 5 bDeviceSubClass */ + 0x00, /* 6 bDeviceProtocol */ + 64, /* 7 bMaxPacketSize */ + 0x01, /* 8 bNumConfigurations : Number of possible configs */ + 0x00 /* 9 bReserved (must be zero) */ }; #endif /* Device Qualifier Descriptor for Null Device (Use when running at high-speed) */ unsigned char devQualDesc_Null[] = -{ - 10, /* 0 bLength (10 Bytes) */ - USB_DEVICE_QUALIFIER, /* 1 bDescriptorType */ - 0x00, /* 2 bcdUSB (Binary Coded Decimal of usb version) */ - 0x02, /* 3 bcdUSB */ - 0x00, /* 4 bDeviceClass */ - 0x00, /* 5 bDeviceSubClass */ - 0x00, /* 6 bDeviceProtocol */ - 64, /* 7 bMaxPacketSize */ - 0x01, /* 8 bNumConfigurations : Number of possible configs */ - 0x00 /* 9 bReserved (must be zero) */ +{ + 10, /* 0 bLength (10 Bytes) */ + USB_DEVICE_QUALIFIER, /* 1 bDescriptorType */ + 0x00, /* 2 bcdUSB (Binary Coded Decimal of usb version) */ + 0x02, /* 3 bcdUSB */ + 0x00, /* 4 bDeviceClass */ + 0x00, /* 5 bDeviceSubClass */ + 0x00, /* 6 bDeviceProtocol */ + 64, /* 7 bMaxPacketSize */ + 0x01, /* 8 bNumConfigurations : Number of possible configs */ + 0x00 /* 9 bReserved (must be zero) */ }; @@ -153,13 +153,13 @@ unsigned char devQualDesc_Null[] = /* Calc total length of configuration desc based on defines */ #ifdef OUTPUT -#define LEN_FU_OUT (6 + (NUM_USB_CHAN_OUT + 1) * 4) +#define LEN_FU_OUT (6 + (NUM_USB_CHAN_OUT + 1) * 4) #else #define LEN_FU_OUT 0 #endif #ifdef INPUT -#define LEN_FU_IN (6 + (NUM_USB_CHAN_IN + 1) * 4) +#define LEN_FU_IN (6 + (NUM_USB_CHAN_IN + 1) * 4) #else #define LEN_FU_IN 0 #endif @@ -167,7 +167,7 @@ unsigned char devQualDesc_Null[] = #ifdef MIDI #define MIDI_LENGTH (92) -#else +#else #define MIDI_LENGTH (0) #endif @@ -191,7 +191,7 @@ unsigned char devQualDesc_Null[] = #define LEN_XU_IN (0) #endif -#if defined (MIXER) && (MAX_MIX_COUNT > 0) +#if defined (MIXER) && (MAX_MIX_COUNT > 0) #define LEN_XU_MIX (17) #define MIX_BMCONTROLS_LEN_TMP ((MAX_MIX_COUNT * MIX_INPUTS) / 8) @@ -306,34 +306,34 @@ unsigned char hidReportDescriptor[] = { /* We need to this for patching descriptor for audio class 1.0 mode changing */ #define STREAMING_ALT1_OFFSET (CONFIG_DESC_LENGTH + INTERFACE_ASS_LENGTH + AUD_CTRL_INT_LENGTH + TLEN_AC + AUD_INT_EP_LEN + 9 + 9 + 0x10) -/* Max packet sizes: +/* Max packet sizes: * Samples per channel. e.g (192000+7999/8000) = 24 - * Must allow 1 sample extra per chan (24 + 1) = 25 + * Must allow 1 sample extra per chan (24 + 1) = 25 * Multiply by number of channels and bytes 25 * 2 * 4 = 200 bytes */ -#define MAX_PACKET_SIZE_OUT_HS ((((MAX_FREQ+7999)/8000)+1) * NUM_USB_CHAN_OUT * 4) +#define MAX_PACKET_SIZE_OUT_HS ((((MAX_FREQ+7999)/8000)+1) * NUM_USB_CHAN_OUT * 4) #define MAX_PACKET_SIZE_OUT_FS ((((MAX_FREQ_A1+999)/1000)+1) * NUM_USB_CHAN_OUT_FS * 3) // Samples per channel -#define MAX_PACKET_SIZE_IN_HS ((((MAX_FREQ+7999)/8000)+1) * NUM_USB_CHAN_IN * 4) +#define MAX_PACKET_SIZE_IN_HS ((((MAX_FREQ+7999)/8000)+1) * NUM_USB_CHAN_IN * 4) #define MAX_PACKET_SIZE_IN_FS ((((MAX_FREQ_A1+999)/1000)+1) * NUM_USB_CHAN_IN_FS * 3) // Samples per channel /* Configuration Descriptor for Audio 2.0 (HS) operation */ -unsigned char cfgDesc_Audio2[] = +unsigned char cfgDesc_Audio2[] = { - 0x09, /* 0 bLength */ - USB_CONFIGURATION, /* 1 bDescriptorType */ - (CFG_TOTAL_LENGTH_A2 & 0xFF), /* 2 wTotalLength */ - (CFG_TOTAL_LENGTH_A2 >> 8), /* 3 wTotalLength */ - NUM_INTERFACES, /* 4 bNumInterface: Number of interfaces*/ - 0x01, /* 5 bConfigurationValue */ - 0x00, /* 6 iConfiguration */ + 0x09, /* 0 bLength */ + USB_CONFIGURATION, /* 1 bDescriptorType */ + (CFG_TOTAL_LENGTH_A2 & 0xFF), /* 2 wTotalLength */ + (CFG_TOTAL_LENGTH_A2 >> 8), /* 3 wTotalLength */ + NUM_INTERFACES, /* 4 bNumInterface: Number of interfaces*/ + 0x01, /* 5 bConfigurationValue */ + 0x00, /* 6 iConfiguration */ #ifdef SELF_POWERED 192, /* 7 bmAttributes */ #else - 128, /* 7 bmAttributes */ -#endif - BMAX_POWER, /* 8 bMaxPower */ + 128, /* 7 bmAttributes */ +#endif + BMAX_POWER, /* 8 bMaxPower */ - /* Interface Association Descriptor */ + /* Interface Association Descriptor */ 0x08, /* 0 bLength */ 0x0b, /* 1 bDescriptorType */ 0x00, /* 2 bFirstInterface */ @@ -356,7 +356,7 @@ unsigned char cfgDesc_Audio2[] = AUDIO, /* 5 bInterfaceClass: AUDIO */ AUDIOCONTROL, /* 6 bInterfaceSubClass: AUDIOCONTROL*/ IP_VERSION_02_00, /* 7 bInterfaceProtocol: IP_VERSION_02_00 */ - PRODUCT_STR_INDEX_A2, /* 8 iInterface (re-use iProduct) */ + PRODUCT_STR_INDEX_A2, /* 8 iInterface (re-use iProduct) */ /* Class Specific Audio Control Interface Header Descriptor: */ LEN_AC, /* 0 bLength */ @@ -366,22 +366,22 @@ unsigned char cfgDesc_Audio2[] = IO_BOX, /* 5 bCatagory (Primary use of audio function) */ (TLEN_AC & 0xFF), /* 6 wTotalLength */ (TLEN_AC >> 8), /* 7 wTotalLength */ - 0x00, /* 8 bmControls (0:1 Latency Control, 2:7 must be 0 */ + 0x00, /* 8 bmControls (0:1 Latency Control, 2:7 must be 0 */ - /* Clock Source Descriptor (4.7.2.1) */ + /* Clock Source Descriptor (4.7.2.1) */ LEN_CLK, /* 0 bLength: 8 */ CS_INTERFACE, /* 1 bDescriptorType */ CLOCK_SOURCE, /* 2 bDescriptorSubtype */ ID_CLKSRC_INT, /* 3 bClockID */ - 0x03, /* 4 bmAttributes: + 0x03, /* 4 bmAttributes: D[1:0] : - 00: External Clock + 00: External Clock 01: Internal Fixed Clock 10: Internal Variable Clock - 11: Internal Progamable Clock + 11: Internal Progamable Clock D[2] : Clock synced to SOF D[7:3] : Reserved (0) */ - 0x07, /* 5 bmControls + 0x07, /* 5 bmControls D[1:0] : Clock Freq Control D[3:2] : Clock Validity Control D[7:4] : Reserved (0) */ @@ -389,20 +389,20 @@ unsigned char cfgDesc_Audio2[] = INTERNAL_CLOCK_STRING_INDEX, /* 7 iClockSource (String Index) */ #ifdef SPDIF_RX - /* Clock Source Descriptor (4.7.2.1) */ + /* Clock Source Descriptor (4.7.2.1) */ LEN_CLK, /* 0 bLength: 8 */ CS_INTERFACE, /* 1 bDescriptorType */ CLOCK_SOURCE, /* 2 bDescriptorSubtype */ ID_CLKSRC_EXT, /* 3 bClockID */ - 0x00, /* 4 bmAttributes: + 0x00, /* 4 bmAttributes: D[1:0] : - 00: External Clock + 00: External Clock 01: Internal Fixed Clock 10: Internal Variable Clock - 11: Internal Progamable Clock + 11: Internal Progamable Clock D[2] : Clock synced to SOF D[7:3] : Reserved (0) */ - 0x07, /* 5 bmControls + 0x07, /* 5 bmControls D[1:0] : Clock Freq Control D[3:2] : Clock Validity Control D[7:4] : Reserved (0) */ @@ -410,27 +410,27 @@ unsigned char cfgDesc_Audio2[] = SPDIF_CLOCK_STRING_INDEX, /* 7 iClockSource (String Index) */ #endif #ifdef ADAT_RX - /* Clock Source Descriptor (4.7.2.1) */ + /* Clock Source Descriptor (4.7.2.1) */ LEN_CLK, /* 0 bLength: 8 */ CS_INTERFACE, /* 1 bDescriptorType */ CLOCK_SOURCE, /* 2 bDescriptorSubtype */ ID_CLKSRC_ADAT, /* 3 bClockID */ - 0x00, /* 4 bmAttributes: + 0x00, /* 4 bmAttributes: D[1:0] : - 00: External Clock + 00: External Clock 01: Internal Fixed Clock 10: Internal Variable Clock - 11: Internal Progamable Clock + 11: Internal Progamable Clock D[2] : Clock synced to SOF D[7:3] : Reserved (0) */ - 0x07, /* 5 bmControls + 0x07, /* 5 bmControls D[1:0] : Clock Freq Control D[3:2] : Clock Validity Control D[7:4] : Reserved (0) */ 0x00, /* 6 bAssocTerminal */ ADAT_CLOCK_STRING_INDEX, /* 7 iClockSource (String Index) */ #endif - /* Clock Selector Descriptor (4.7.2.2) */ + /* Clock Selector Descriptor (4.7.2.2) */ LEN_CLK_SEL, /* 0 bLength */ CS_INTERFACE, /* 1 bDescriptorType */ CLOCK_SELECTOR, /* 2 bDescriptorSubtype */ @@ -438,15 +438,15 @@ unsigned char cfgDesc_Audio2[] = NUM_CLOCKS, /* 4 Number of input pins*/ ID_CLKSRC_INT, #ifdef SPDIF_RX - ID_CLKSRC_EXT, + ID_CLKSRC_EXT, #endif #ifdef ADAT_RX ID_CLKSRC_ADAT, #endif - 0x03, /* 5 bmControls + 0x03, /* 5 bmControls D[1:0] : Clock Selector Control D[7:4] : Reserved (0) */ - 13, /* 7 iClockSel (String Index) */ + 13, /* 7 iClockSel (String Index) */ #ifdef OUTPUT /* OUTPUT PATH FROM HOST TO DEVICE */ @@ -475,18 +475,18 @@ unsigned char cfgDesc_Audio2[] = 1, /* 6 bNrPins */ ID_IT_USB, /* 7 baSourceId(1) */ NUM_USB_CHAN_OUT, /* 8+p bNrChannels */ - 0, /* 9+p bmChannelConfig */ - 0, /* 10+p bmChannelConfig */ - 0, /* 11+p bmChannelConfig */ - 0, /* 12+p bmChannelConfig */ + 0, /* 9+p bmChannelConfig */ + 0, /* 10+p bmChannelConfig */ + 0, /* 11+p bmChannelConfig */ + 0, /* 12+p bmChannelConfig */ 0, /* 13+p iChannelNames */ 3, /* 14+p bmControls */ 0, /* 15+p iExtension */ #endif - /* Feature Unit Descriptor */ - LEN_FU_OUT, /* 0 bLength: 6+(ch + 1)*4 */ - 0x24, /* 1 bDescriptorType: CS_INTERFACE */ + /* Feature Unit Descriptor */ + LEN_FU_OUT, /* 0 bLength: 6+(ch + 1)*4 */ + 0x24, /* 1 bDescriptorType: CS_INTERFACE */ 0x06, /* 2 bDescriptorSubType: FEATURE_UNIT */ FU_USBOUT, /* 3 bUnitID */ #ifdef AUDIO_PATH_XUS @@ -552,7 +552,7 @@ unsigned char cfgDesc_Audio2[] = #if (NUM_USB_CHAN_OUT > 18) #error NUM_USB_CHAN_OUT > 18 #endif - 0, /* 60 iFeature */ + 0, /* 60 iFeature */ /* Output Terminal Descriptor (Audio) */ 0x0C, /* 0 bLength */ @@ -594,18 +594,18 @@ unsigned char cfgDesc_Audio2[] = 1, /* 6 bNrPins */ ID_IT_AUD, /* 7 baSourceId(1) */ NUM_USB_CHAN_OUT, /* 8+p bNrChannels */ - 0, /* 9+p bmChannelConfig */ - 0, /* 10+p bmChannelConfig */ - 0, /* 11+p bmChannelConfig */ - 0, /* 12+p bmChannelConfig */ + 0, /* 9+p bmChannelConfig */ + 0, /* 10+p bmChannelConfig */ + 0, /* 11+p bmChannelConfig */ + 0, /* 12+p bmChannelConfig */ 0, /* 13+p iChannelNames */ 3, /* 14+p bmControls */ 0, /* 15+p iExtension */ #endif - /* Feature Unit Descriptor */ - LEN_FU_IN, /* 0 bLength: 6+(ch+1)*4 */ - CS_INTERFACE, /* 1 bDescriptorType: CS_INTERFACE */ + /* Feature Unit Descriptor */ + LEN_FU_IN, /* 0 bLength: 6+(ch+1)*4 */ + CS_INTERFACE, /* 1 bDescriptorType: CS_INTERFACE */ FEATURE_UNIT, /* 2 bDescriptorSubType: FEATURE_UNIT */ FU_USBIN, /* 3 bUnitID */ #ifdef AUDIO_PATH_XUS @@ -671,7 +671,7 @@ unsigned char cfgDesc_Audio2[] = #if (NUM_USB_CHAN_IN > 18) #error NUM_USB_CHAN > 18 #endif - 0, /* 60 iFeature */ + 0, /* 60 iFeature */ /* Output Terminal Descriptor (USB Streaming) */ 0x0C, /* 0 bLength */ @@ -686,7 +686,7 @@ unsigned char cfgDesc_Audio2[] = 7, /* 11 iTerminal */ #endif - + #if defined (MIXER) && (MAX_MIX_COUNT > 0) /* Extension Unit Descriptor (4.7.2.12) */ @@ -700,10 +700,10 @@ unsigned char cfgDesc_Audio2[] = ID_IT_USB, /* 7 baSourceId(1) */ ID_IT_AUD, /* 7 baSourceId(2) */ MIX_INPUTS, /* 8+p bNrChannels */ - 0, /* 9+p bmChannelConfig */ - 0, /* 10+p bmChannelConfig */ - 0, /* 11+p bmChannelConfig */ - 0, /* 12+p bmChannelConfig */ + 0, /* 9+p bmChannelConfig */ + 0, /* 10+p bmChannelConfig */ + 0, /* 11+p bmChannelConfig */ + 0, /* 12+p bmChannelConfig */ 0, /* 13+p iChannelNames */ 3, /* 14+p bmControls */ 0, /* 15+p iExtension */ @@ -727,72 +727,72 @@ unsigned char cfgDesc_Audio2[] = 0x00, 0x00, 0x00, 0x00, /* Spacial location ???? */ MIXER_STRING_INDEX, /* Channel name index */ #if MIX_BMCONTROLS_LEN > 0 /* Mixer programmable control bitmap */ - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 1 - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 2 - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 3 - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 4 - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 5 - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 6 - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 7 - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 8 - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 9 - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 10 - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 11 - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 12 - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 13 - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 14 - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 15 - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 16 - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 17 - 0xff, -#endif + 0xff, +#endif #if MIX_BMCONTROLS_LEN > 18 #error unxpected BMCONTROLS_LEN -#endif +#endif 0x00, /* bmControls */ 0, /* Mixer unit string descriptor index */ #endif #if defined(SPDIF_RX) || defined (ADAT_RX) - /* Standard AS Interrupt Endpoint Descriptor (4.8.2.1): */ + /* Standard AS Interrupt Endpoint Descriptor (4.8.2.1): */ 0x07, /* 0 bLength: 7 */ 0x05, /* 1 bDescriptorType: ENDPOINT */ EP_ADR_IN_AUD_INT, /* 2 bEndpointAddress (D7: 0:out, 1:in) */ - 3, /* 3 bmAttributes (bitmap) */ + 3, /* 3 bmAttributes (bitmap) */ 6,0, /* 4 wMaxPacketSize */ 8, /* 6 bInterval */ #endif @@ -840,13 +840,13 @@ unsigned char cfgDesc_Audio2[] = FORMAT_TYPE, /* 2 bDescriptorSubtype: FORMAT_TYPE */ FORMAT_TYPE_I, /* 3 bFormatType: FORMAT_TYPE_1 */ SAMPLE_SUBSLOT_SIZE_HS, /* 4 bSubslotSize (Number of bytes per subslot) */ - SAMPLE_BIT_RESOLUTION_HS, /* 5 bBitResolution (Number of bits used per subslot) */ + SAMPLE_BIT_RESOLUTION_HS, /* 5 bBitResolution (Number of bits used per subslot) */ /* Standard AS Isochronous Audio Data Endpoint Descriptor (4.10.1.1) */ 0x07, /* 0 bLength: 7 */ USB_ENDPOINT, /* 1 bDescriptorType: ENDPOINT */ 0x01, /* 2 bEndpointAddress (D7: 0:out, 1:in) */ - 0x05, /* 3 bmAttributes (bitmap) */ + 0x05, /* 3 bmAttributes (bitmap) */ MAX_PACKET_SIZE_OUT_HS&0xff, /* 4 wMaxPacketSize */ (MAX_PACKET_SIZE_OUT_HS&0xff00)>>8, /* 5 wMaxPacketSize */ 1, /* 6 bInterval */ @@ -864,7 +864,7 @@ unsigned char cfgDesc_Audio2[] = 0x07, /* 0 bLength: 7 */ USB_ENDPOINT, /* 1 bDescriptorType: ENDPOINT */ 0x81, /* 2 bEndpointAddress (D7: 0:out, 1:in) */ - 17, /* 3 bmAttributes (bitmap) */ + 17, /* 3 bmAttributes (bitmap) */ 4,0, /* 4 wMaxPacketSize */ 4, /* 6 bInterval. Only values <= 1 frame (4) supported by MS */ @@ -898,13 +898,13 @@ unsigned char cfgDesc_Audio2[] = FORMAT_TYPE, /* 2 bDescriptorSubtype: FORMAT_TYPE */ FORMAT_TYPE_I, /* 3 bFormatType: FORMAT_TYPE_1 */ SAMPLE_SUBSLOT_SIZE_HS, /* 4 bSubslotSize (Number of bytes per subslot) */ - 32, /* 5 bBitResolution (Number of bits used per subslot) */ + 32, /* 5 bBitResolution (Number of bits used per subslot) */ /* Standard AS Isochronous Audio Data Endpoint Descriptor (4.10.1.1) */ 0x07, /* 0 bLength: 7 */ USB_ENDPOINT, /* 1 bDescriptorType: ENDPOINT */ 0x01, /* 2 bEndpointAddress (D7: 0:out, 1:in) */ - 0x05, /* 3 bmAttributes (bitmap) */ + 0x05, /* 3 bmAttributes (bitmap) */ MAX_PACKET_SIZE_OUT_HS&0xff, /* 4 wMaxPacketSize */ (MAX_PACKET_SIZE_OUT_HS&0xff00)>>8, /* 5 wMaxPacketSize */ 1, /* 6 bInterval */ @@ -922,7 +922,7 @@ unsigned char cfgDesc_Audio2[] = 0x07, /* 0 bLength: 7 */ USB_ENDPOINT, /* 1 bDescriptorType: ENDPOINT */ 0x81, /* 2 bEndpointAddress (D7: 0:out, 1:in) */ - 17, /* 3 bmAttributes (bitmap) */ + 17, /* 3 bmAttributes (bitmap) */ 4,0, /* 4 wMaxPacketSize */ 4, /* 6 bInterval */ @@ -958,13 +958,13 @@ unsigned char cfgDesc_Audio2[] = FORMAT_TYPE, /* 2 bDescriptorSubtype: FORMAT_TYPE */ FORMAT_TYPE_I, /* 3 bFormatType: FORMAT_TYPE_1 */ SAMPLE_SUBSLOT_SIZE_HS, /* 4 bSubslotSize (Number of bytes per subslot) */ - SAMPLE_BIT_RESOLUTION_HS, /* 5 bBitResolution (Number of bits used per subslot) */ + SAMPLE_BIT_RESOLUTION_HS, /* 5 bBitResolution (Number of bits used per subslot) */ /* Standard AS Isochronous Audio Data Endpoint Descriptor (4.10.1.1) */ 0x07, /* 0 bLength: 7 */ USB_ENDPOINT, /* 1 bDescriptorType: ENDPOINT */ 0x01, /* 2 bEndpointAddress (D7: 0:out, 1:in) */ - 0x05, /* 3 bmAttributes (bitmap) */ + 0x05, /* 3 bmAttributes (bitmap) */ MAX_PACKET_SIZE_OUT_HS&0xff, /* 4 wMaxPacketSize */ (MAX_PACKET_SIZE_OUT_HS&0xff00)>>8, /* 5 wMaxPacketSize */ 1, /* 6 bInterval */ @@ -982,7 +982,7 @@ unsigned char cfgDesc_Audio2[] = 0x07, /* 0 bLength: 7 */ USB_ENDPOINT, /* 1 bDescriptorType: ENDPOINT */ 0x81, /* 2 bEndpointAddress (D7: 0:out, 1:in) */ - 17, /* 3 bmAttributes (bitmap) */ + 17, /* 3 bmAttributes (bitmap) */ 4,0, /* 4 wMaxPacketSize */ 4, /* 6 bInterval */ @@ -1027,16 +1027,16 @@ unsigned char cfgDesc_Audio2[] = /* Type 1 Format Type Descriptor */ 0x06, /* 0 bLength (in bytes): 6 */ CS_INTERFACE, /* 1 bDescriptorType: 0x24 */ - FORMAT_TYPE, /* 2 bDescriptorSubtype: FORMAT_TYPE */ + FORMAT_TYPE, /* 2 bDescriptorSubtype: FORMAT_TYPE */ FORMAT_TYPE_I, /* 3 bFormatType: FORMAT_TYPE_1 */ SAMPLE_SUBSLOT_SIZE_HS, /* 4 bSubslotSize (Number of bytes per subslot) */ - SAMPLE_BIT_RESOLUTION_HS, /* 5 bBitResolution (Number of bits used per subslot) */ + SAMPLE_BIT_RESOLUTION_HS, /* 5 bBitResolution (Number of bits used per subslot) */ /* Standard AS Isochronous Audio Data Endpoint Descriptor (4.10.1.1) */ 0x07, /* 0 bLength: 7 */ USB_ENDPOINT, /* 1 bDescriptorType: ENDPOINT */ 0x82, /* 2 bEndpointAddress (D7: 0:out, 1:in) */ - 5, /* 3 bmAttributes (bitmap) */ + 5, /* 3 bmAttributes (bitmap) */ MAX_PACKET_SIZE_IN_HS&0xff, /* 4 wMaxPacketSize */ (MAX_PACKET_SIZE_IN_HS&0xff00)>>8, /* 5 wMaxPacketSize */ 1, /* 6 bInterval */ @@ -1077,16 +1077,16 @@ unsigned char cfgDesc_Audio2[] = /* Type 1 Format Type Descriptor */ 0x06, /* 0 bLength (in bytes): 6 */ CS_INTERFACE, /* 1 bDescriptorType: 0x24 */ - FORMAT_TYPE, /* 2 bDescriptorSubtype: FORMAT_TYPE */ + FORMAT_TYPE, /* 2 bDescriptorSubtype: FORMAT_TYPE */ FORMAT_TYPE_I, /* 3 bFormatType: FORMAT_TYPE_1 */ SAMPLE_SUBSLOT_SIZE_HS, /* 4 bSubslotSize (Number of bytes per subslot) */ - SAMPLE_BIT_RESOLUTION_HS, /* 5 bBitResolution (Number of bits used per subslot) */ + SAMPLE_BIT_RESOLUTION_HS, /* 5 bBitResolution (Number of bits used per subslot) */ /* Standard AS Isochronous Audio Data Endpoint Descriptor (4.10.1.1) */ 0x07, /* 0 bLength: 7 */ USB_ENDPOINT, /* 1 bDescriptorType: ENDPOINT */ 0x82, /* 2 bEndpointAddress (D7: 0:out, 1:in) */ - 5, /* 3 bmAttributes (bitmap) */ + 5, /* 3 bmAttributes (bitmap) */ MAX_PACKET_SIZE_IN_HS&0xff, /* 4 wMaxPacketSize */ (MAX_PACKET_SIZE_IN_HS&0xff00)>>8, /* 5 wMaxPacketSize */ 1, /* 6 bInterval */ @@ -1127,16 +1127,16 @@ unsigned char cfgDesc_Audio2[] = /* Type 1 Format Type Descriptor */ 0x06, /* 0 bLength (in bytes): 6 */ CS_INTERFACE, /* 1 bDescriptorType: 0x24 */ - FORMAT_TYPE, /* 2 bDescriptorSubtype: FORMAT_TYPE */ + FORMAT_TYPE, /* 2 bDescriptorSubtype: FORMAT_TYPE */ FORMAT_TYPE_I, /* 3 bFormatType: FORMAT_TYPE_1 */ 0x04, /* 4 bSubslotSize (Number of bytes per subslot) */ - 24, /* 5 bBitResolution (Number of bits used per subslot) */ + 24, /* 5 bBitResolution (Number of bits used per subslot) */ /* Standard AS Isochronous Audio Data Endpoint Descriptor (4.10.1.1) */ 0x07, /* 0 bLength: 7 */ ENDPOINT, /* 1 bDescriptorType: ENDPOINT */ 0x82, /* 2 bEndpointAddress (D7: 0:out, 1:in) */ - 5, /* 3 bmAttributes (bitmap) */ + 5, /* 3 bmAttributes (bitmap) */ 0,4, /* 4 wMaxPacketSize */ 1, /* 6 bInterval */ @@ -1308,7 +1308,7 @@ unsigned char cfgDesc_Audio2[] = #endif #endif - + #ifdef IAP /* Interface descriptor */ 0x09, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */ @@ -1395,8 +1395,8 @@ unsigned char cfgDesc_Audio2[] = #define APPEND_PRODUCT_STR_A1(x) PRODUCT_STR_A1 " "#x -#if defined(SPDIF) -#if ((NUM_USB_CHAN_OUT - 2) <= 0) +#if defined(SPDIF) +#if ((NUM_USB_CHAN_OUT - 2) <= 0) #define SPDIF_TX_OVERLAP 1 #else #define SPDIF_TX_OVERLAP 0 @@ -1406,26 +1406,26 @@ unsigned char cfgDesc_Audio2[] = #define STR_USENG 0x0409 -static unsigned char strDescs[][40] = +static unsigned char strDescs[][40] = { { STR_USENG & 0xff, STR_USENG >> 8, '\0'}, // 0 LangID VENDOR_STR, // 1 iManufacturer (at MANUFACTURER_STRING_INDEX) "",//SERIAL_STR, // 2 iSerialNumber (at SERIAL_STR_INDEX) - + /* Audio 2.0 Strings */ PRODUCT_STR_A2, // 3 iProduct and iInterface for control interface (at PRODUCT_STR_INDEX) APPEND_PRODUCT_STR_A2(), // 4 iInterface for Streaming interaces APPEND_PRODUCT_STR_A2(), // 5 - APPEND_PRODUCT_STR_A2(), // 6 "USB Input Terminal" (User sees as output from host) - APPEND_PRODUCT_STR_A2(), // 7 "USB Output Terminal" (User sees as input to host) - + APPEND_PRODUCT_STR_A2(), // 6 "USB Input Terminal" (User sees as output from host) + APPEND_PRODUCT_STR_A2(), // 7 "USB Output Terminal" (User sees as input to host) + /* Audio 1.0 Strings */ PRODUCT_STR_A1, // 8 iProduct and iInterface for control interface APPEND_PRODUCT_STR_A1(Output), // 9 iInterface for Streaming interaces APPEND_PRODUCT_STR_A1(Input), // 10 - APPEND_PRODUCT_STR_A1(Output), // 11 "USB Input Terminal" (User sees as output from host) - APPEND_PRODUCT_STR_A1(Input), // 12 "USB Output Terminal" (User sees as input to host) + APPEND_PRODUCT_STR_A1(Output), // 11 "USB Input Terminal" (User sees as output from host) + APPEND_PRODUCT_STR_A1(Input), // 12 "USB Output Terminal" (User sees as input to host) APPEND_VENDOR_STR(Clock Selector), // 13 iClockSel APPEND_VENDOR_STR(Internal Clock), // 14 iClockSource @@ -1443,18 +1443,18 @@ static unsigned char strDescs[][40] = APPEND_VENDOR_STR(MIDI Out), // iJack for MIDI OUT APPEND_VENDOR_STR(MIDI In ), // iJack for MIDI IN #endif - + // Output channel name place holders - Get customised at runtime based on devic -#if (NUM_USB_CHAN_OUT > 0) +#if (NUM_USB_CHAN_OUT > 0) "Analogue 1", #endif -#if (NUM_USB_CHAN_OUT > 1) +#if (NUM_USB_CHAN_OUT > 1) "Analogue 2", #endif -#if (NUM_USB_CHAN_OUT > 2) +#if (NUM_USB_CHAN_OUT > 2) "Analogue 3", #endif -#if (NUM_USB_CHAN_OUT > 3) +#if (NUM_USB_CHAN_OUT > 3) "Analogue 4", #endif #if (NUM_USB_CHAN_OUT > 4) @@ -1502,60 +1502,60 @@ static unsigned char strDescs[][40] = #if (NUM_USB_CHAN_OUT > 18) #error NUM_USB_CHAN > 18 #endif - + #if (NUM_USB_CHAN_IN > 0) - "Analogue 1", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 1", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 1) - "Analogue 2", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 2", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 2) - "Analogue 3", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 3", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 3) - "Analogue 4", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 4", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 4) - "Analogue 5", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 5", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 5) - "Analogue 6", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 6", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 6) - "Analogue 7", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 7", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 7) - "Analogue 8", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 8", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 8) - "Analogue 9", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 9", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 9) - "Analogue 10", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 10", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 10) - "Analogue 11", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 11", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 11) - "Analogue 12", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 12", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 12) - "Analogue 13", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 13", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 13) - "Analogue 14", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 14", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 14) - "Analogue 15", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 15", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 15) - "Analogue 16", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 16", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 16) - "Analogue 17", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 17", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 17) - "Analogue 18", // Input channel name place holders - Get customised at runtime based on device config + "Analogue 18", // Input channel name place holders - Get customised at runtime based on device config #endif #if (NUM_USB_CHAN_IN > 18) #error NUM_USB_CHAN > 18 @@ -1597,7 +1597,7 @@ static unsigned char strDescs[][40] = }; /* Configuration Descriptor for Null device */ -unsigned char cfgDesc_Null[] = +unsigned char cfgDesc_Null[] = { 0x09, /* 0 bLength */ USB_CONFIGURATION, /* 1 bDescriptorType */ @@ -1609,7 +1609,7 @@ unsigned char cfgDesc_Null[] = #ifdef SELF_POWERED 192, /* 7 bmAttributes */ #else - 128, + 128, #endif BMAX_POWER, /* 8 bMaxPower */ @@ -1622,7 +1622,7 @@ unsigned char cfgDesc_Null[] = 0x00, /* 6 bInterfaceSubclass */ 0x00, /* 7 bInterfaceProtocol : Unused. (field size 1 bytes) */ 0x00, /* 8 iInterface : Unused. (field size 1 bytes) */ - 0x09, /* 0 bLength */ + 0x09, /* 0 bLength */ }; #if 0 @@ -1652,7 +1652,7 @@ unsigned char oSpeedCfgDesc[] = }; #endif -/* Configuration descriptor for Audio v1.0 */ +/* Configuration descriptor for Audio v1.0 */ #define AC_LENGTH (8 + INPUT_INTERFACES + OUTPUT_INTERFACES) #define AC_TOTAL_LENGTH (AC_LENGTH + (INPUT_INTERFACES * 31) + (OUTPUT_INTERFACES * 31)) #define STREAMING_INTERFACES (INPUT_INTERFACES + OUTPUT_INTERFACES) @@ -1660,12 +1660,12 @@ unsigned char oSpeedCfgDesc[] = #define CFG_TOTAL_LENGTH_A1 (18 + AC_TOTAL_LENGTH + (INPUT_INTERFACES * 61) + (OUTPUT_INTERFACES * 70)) #ifdef AUDIO_CLASS_FALLBACK -unsigned char cfgDesc_Audio1[] = -{ +unsigned char cfgDesc_Audio1[] = +{ /* Configuration descriptor */ - 0x09, - USB_CONFIGURATION, - (CFG_TOTAL_LENGTH_A1 & 0xFF), /* wTotalLength */ + 0x09, + USB_CONFIGURATION, + (CFG_TOTAL_LENGTH_A1 & 0xFF), /* wTotalLength */ (CFG_TOTAL_LENGTH_A1 >> 8), /* wTotalLength */ NUM_INTERFACES_A1, /* numInterfaces - we dont support MIDI in audio 1.0 mode*/ 0x01, /* ID of this configuration */ @@ -1673,27 +1673,27 @@ unsigned char cfgDesc_Audio1[] = #ifdef SELF_POWERED 192, /* 7 bmAttributes */ #else - 128, /* 7 bmAttributes */ -#endif - BMAX_POWER, /* 8 bMaxPower */ + 128, /* 7 bmAttributes */ +#endif + BMAX_POWER, /* 8 bMaxPower */ /* Standard AC interface descriptor */ - 0x09, - USB_INTERFACE, + 0x09, + USB_INTERFACE, 0x00, /* Interface No */ 0x00, /* Alternate setting*/ 0x00, /* Num endpoints */ - AUDIO, - AUDIOCONTROL, + AUDIO, + AUDIOCONTROL, 0x00, /* Unused */ - 8, /* iInterface - re-use iProduct */ + 8, /* iInterface - re-use iProduct */ /* CS (Class Specific) AudioControl interface header descriptor (4.3.2) */ - AC_LENGTH, - CS_INTERFACE, + AC_LENGTH, + CS_INTERFACE, 0x01, /* HEADER */ 0x00, 0x01, /* Class spec revision - 1.0 */ - (AC_TOTAL_LENGTH & 0xFF), /* wTotallength (Combined length of this descriptor and all Unit and Terminal Descriptors) */ + (AC_TOTAL_LENGTH & 0xFF), /* wTotallength (Combined length of this descriptor and all Unit and Terminal Descriptors) */ (AC_TOTAL_LENGTH >> 8), /* wTotalLength */ STREAMING_INTERFACES, /* Num streaming interfaces */ #ifdef OUTPUT @@ -1705,7 +1705,7 @@ unsigned char cfgDesc_Audio1[] = #ifdef OUTPUT /* CS_Interface Input Terminal 1 Descriptor - USB streaming Host to Device */ - 0x0C, + 0x0C, CS_INTERFACE, /* CS_INTERFACE */ 0x02, /* INPUT_TERMINAL */ 0x01, /* Terminal ID */ @@ -1717,20 +1717,20 @@ unsigned char cfgDesc_Audio1[] = 11, /* iTerminal */ /* CS_Interface class specific AC interface feature unit descriptor - mute & volume for dac */ - 0x0A, - CS_INTERFACE, - FEATURE_UNIT, + 0x0A, + CS_INTERFACE, + FEATURE_UNIT, 0x0A, /* unitID */ 0x01, /* sourceID - ID of the unit/terminal to which this feature unit is connected */ 0x01, /* controlSize - 1 */ 0x00, /* bmaControls(0) */ 0x03, /* bmaControls(1) */ 0x03, /* bmaControls(2) */ - 0x00, /* String table index */ - + 0x00, /* String table index */ + /* CS_Interface Output Terminal Descriptor - Analogue out to speaker */ - 0x09, - CS_INTERFACE, + 0x09, + CS_INTERFACE, 0x03, /* OUTPUT_TERMINAL */ 0x06, /* Terminal ID */ 0x01, 0x03, /* Type - streaming out, speaker */ @@ -1742,37 +1742,37 @@ unsigned char cfgDesc_Audio1[] = #ifdef INPUT /* CS_Interface Input Terminal 2 Descriptor - Analog in from line in */ - 0x0C, - CS_INTERFACE, + 0x0C, + CS_INTERFACE, 0x02, /* INPUT_TERMINAL */ - 0x02, /* Terminal ID */ + 0x02, /* Terminal ID */ 0x01, 0x02, /* Type - streaming in, mic */ 0x00, /* Associated terminal - unused */ - NUM_USB_CHAN_IN_FS, /* bNrChannels */ - 0x03, 0x00, /* wChannelConfigs */ - 0x00, /* iChannelNames */ - 12, /* iTerminal */ - + NUM_USB_CHAN_IN_FS, /* bNrChannels */ + 0x03, 0x00, /* wChannelConfigs */ + 0x00, /* iChannelNames */ + 12, /* iTerminal */ + /* CS_Interface Output Terminal Descriptor - USB Streaming Device to Host*/ - 0x09, - CS_INTERFACE, + 0x09, + CS_INTERFACE, 0x03, /* OUTPUT_TERMINAL */ - 0x07, /* Terminal ID */ + 0x07, /* Terminal ID */ 0x01, 0x01, /* Type - streaming */ - 0x01, /* Associated terminal - unused */ + 0x01, /* Associated terminal - unused */ 0x0B, /* sourceID - from selector unit ?? */ - 0x00, /* Unused */ - + 0x00, /* Unused */ + /* CS_Interface class specific AC interface feature unit descriptor - mute & volume for adc */ - 0x0A, - CS_INTERFACE, - FEATURE_UNIT, - 0x0B, /* unitID */ + 0x0A, + CS_INTERFACE, + FEATURE_UNIT, + 0x0B, /* unitID */ 0x02, /* sourceID - ID of the unit/terminal to which this feature unit is connected */ - 0x01, /* controlSize - 1 */ - 0x00, /* bmaControls(0) */ - 0x03, /* bmaControls(1) */ - 0x03, /* bmaControls(2) */ 0x00, /* String table index */ + 0x01, /* controlSize - 1 */ + 0x00, /* bmaControls(0) */ + 0x03, /* bmaControls(1) */ + 0x03, /* bmaControls(2) */ 0x00, /* String table index */ #endif @@ -1781,7 +1781,7 @@ unsigned char cfgDesc_Audio1[] = 0x09, /* bLength */ 0x04, /* INTERFACE */ 0x01, /* bInterfaceNumber */ - 0x00, /* bAlternateSetting */ + 0x00, /* bAlternateSetting */ 0x00, /* bnumEndpoints */ 0x01, /* bInterfaceClass - AUDIO */ 0x02, /* bInterfaceSubclass - AUDIO_STREAMING */ @@ -1789,27 +1789,27 @@ unsigned char cfgDesc_Audio1[] = 0x09, /* iInterface */ /* Standard As Interface Descriptor (4.5.1) */ - 0x09, - 0x04, /* INTERFACE */ - 0x01, /* Interface no */ - 0x01, /* AlternateSetting */ - 0x02, /* num endpoints 2: audio EP and feedback EP */ - 0x01, /* Interface class - AUDIO */ - 0x02, /* subclass - AUDIO_STREAMING */ - 0x00, /* Unused */ - 0x04, /* String table index */ + 0x09, + 0x04, /* INTERFACE */ + 0x01, /* Interface no */ + 0x01, /* AlternateSetting */ + 0x02, /* num endpoints 2: audio EP and feedback EP */ + 0x01, /* Interface class - AUDIO */ + 0x02, /* subclass - AUDIO_STREAMING */ + 0x00, /* Unused */ + 0x04, /* String table index */ /* Class-Specific AS Interface Descriptor (4.5.2) */ - 0x07, - CS_INTERFACE, /* bDescriptorType */ + 0x07, + CS_INTERFACE, /* bDescriptorType */ 0x01, /* bDescriptorSubtype - GENERAL */ 0x01, /* iTerminalLink - linked to Streaming IN terminal */ 0x01, /* bDelay */ 0x01, 0x00, /* wFormatTag - PCM */ /* CS_Interface Format Type Descriptor */ - 0x14, - CS_INTERFACE, + 0x14, + CS_INTERFACE, 0x02, /* Subtype - FORMAT_TYPE */ 0x01, /* Format type - FORMAT_TYPE_1 */ NUM_USB_CHAN_OUT_FS, /* nrChannels */ @@ -1817,31 +1817,31 @@ unsigned char cfgDesc_Audio1[] = SAMPLE_BIT_RESOLUTION_FS, /* bitResolution */ 0x04, /* SamFreqType - 4 sample freq */ 0x44, 0xAC, 0x00, /* sampleFreq - 44.1Khz */ - 0x80, 0xBB, 0x00, /* sampleFreq - 48KHz */ + 0x80, 0xBB, 0x00, /* sampleFreq - 48KHz */ #if defined(OUTPUT) && defined(INPUT) - 0x80, 0xBB, 0x00, /* sampleFreq - 48KHz */ - 0x80, 0xBB, 0x00, /* sampleFreq - 48KHz */ + 0x80, 0xBB, 0x00, /* sampleFreq - 48KHz */ + 0x80, 0xBB, 0x00, /* sampleFreq - 48KHz */ #else - 0x88, 0x58, 0x01, /* sampleFreq - 88.2KHz */ - 0x00, 0x77, 0x01, /* sampleFreq - 96KHz */ + 0x88, 0x58, 0x01, /* sampleFreq - 88.2KHz */ + 0x00, 0x77, 0x01, /* sampleFreq - 96KHz */ #endif /* Standard AS Isochronous Audio Data Endpoint Descriptor 4.6.1.1 */ - 0x09, + 0x09, 0x05, /* ENDPOINT */ - 0x01, /* endpointAddress - D7, direction (0 OUT, 1 IN). D6..4 reserved (0). D3..0 endpoint no. */ + 0x01, /* endpointAddress - D7, direction (0 OUT, 1 IN). D6..4 reserved (0). D3..0 endpoint no. */ 0x05, /* attributes - isochronous async */ -#if defined(OUTPUT) && defined(INPUT) - 0x26, 0x01, /* maxPacketSize 294 */ +#if defined(OUTPUT) && defined(INPUT) + 0x26, 0x01, /* maxPacketSize 294 */ #else - 0x46, 0x02, /* maxPacketSize 582 */ + 0x46, 0x02, /* maxPacketSize 582 */ #endif 0x01, /* bInterval */ 0x00, /* bRefresh */ 0x81, /* bSynchAdddress - address of EP used to communicate sync info */ /* CS_Endpoint Descriptor ?? */ - 0x07, + 0x07, 0x25, /* CS_ENDPOINT */ 0x01, /* subtype - GENERAL */ 0x01, /* attributes. D[0]: sample freq ctrl. */ @@ -1849,10 +1849,10 @@ unsigned char cfgDesc_Audio1[] = 0x00, 0x00, /* bLockDelay */ /* Feedback EP */ - 0x09, + 0x09, 0x05, /* bDescriptorType: ENDPOINT */ 0x81, /* bEndpointAddress (D3:0 - EP no. D6:4 - reserved 0. D7 - 0:out, 1:in) */ - 0x01, /* bmAttributes (bitmap) */ + 0x01, /* bmAttributes (bitmap) */ 0x03,0x0, /* wMaxPacketSize */ 0x01, /* bInterval - Must be 1 for compliance */ 0x04, /* bRefresh 2^x */ @@ -1861,75 +1861,75 @@ unsigned char cfgDesc_Audio1[] = #ifdef INPUT /* Standard Interface Descriptor - Audio streaming IN */ - 0x09, - 0x04, /* INTERFACE */ - (OUTPUT_INTERFACES + 1), /* bInterfaceNumber*/ - 0x00, /* AlternateSetting */ - 0x00, /* num endpoints */ - 0x01, /* Interface class - AUDIO */ - 0x02, /* subclass - AUDIO_STREAMING */ - 0x00, /* Unused */ - 0x05, /* String table index */ + 0x09, + 0x04, /* INTERFACE */ + (OUTPUT_INTERFACES + 1), /* bInterfaceNumber*/ + 0x00, /* AlternateSetting */ + 0x00, /* num endpoints */ + 0x01, /* Interface class - AUDIO */ + 0x02, /* subclass - AUDIO_STREAMING */ + 0x00, /* Unused */ + 0x05, /* String table index */ /* Standard Interface Descriptor - Audio streaming IN */ - 0x09, - 0x04, /* INTERFACE */ - (OUTPUT_INTERFACES + 1), /* bInterfaceNumber */ - 0x01, /* AlternateSetting */ - 0x01, /* num endpoints */ - 0x01, /* Interface class - AUDIO */ - 0x02, /* Subclass - AUDIO_STREAMING */ - 0x00, /* Unused */ - 0x0A, /* String table index */ + 0x09, + 0x04, /* INTERFACE */ + (OUTPUT_INTERFACES + 1), /* bInterfaceNumber */ + 0x01, /* AlternateSetting */ + 0x01, /* num endpoints */ + 0x01, /* Interface class - AUDIO */ + 0x02, /* Subclass - AUDIO_STREAMING */ + 0x00, /* Unused */ + 0x0A, /* String table index */ /* CS_Interface AC interface header descriptor */ - 0x07, - CS_INTERFACE, - 0x01, /* subtype - GENERAL */ - 0x07, /* TerminalLink - linked to Streaming OUT terminal */ - 0x01, /* Interface delay */ - 0x01,0x00, /* Format - PCM */ + 0x07, + CS_INTERFACE, + 0x01, /* subtype - GENERAL */ + 0x07, /* TerminalLink - linked to Streaming OUT terminal */ + 0x01, /* Interface delay */ + 0x01,0x00, /* Format - PCM */ /* CS_Interface Terminal Descriptor */ - 0x14, - CS_INTERFACE, - 0x02, /* Subtype - FORMAT_TYPE */ - 0x01, /* Format type - FORMAT_TYPE_1 */ - NUM_USB_CHAN_IN_FS, /* bNrChannels - Typically 2 */ + 0x14, + CS_INTERFACE, + 0x02, /* Subtype - FORMAT_TYPE */ + 0x01, /* Format type - FORMAT_TYPE_1 */ + NUM_USB_CHAN_IN_FS, /* bNrChannels - Typically 2 */ SAMPLE_SUBSLOT_SIZE_FS, /* subFrameSize - Typically 4 bytes per slot */ - SAMPLE_BIT_RESOLUTION_FS, /* bitResolution - Typically 24bit */ - 0x04, /* SamFreqType - 4 sample freq */ + SAMPLE_BIT_RESOLUTION_FS, /* bitResolution - Typically 24bit */ + 0x04, /* SamFreqType - 4 sample freq */ 0x44, 0xAC, 0x00, /* sampleFreq - 44.1Khz */ - 0x80, 0xBB, 0x00, /* sampleFreq - 48KHz */ + 0x80, 0xBB, 0x00, /* sampleFreq - 48KHz */ #if defined(OUTPUT) && defined(INPUT) - 0x80, 0xBB, 0x00, /* sampleFreq - 48KHz */ - 0x80, 0xBB, 0x00, /* sampleFreq - 48KHz */ + 0x80, 0xBB, 0x00, /* sampleFreq - 48KHz */ + 0x80, 0xBB, 0x00, /* sampleFreq - 48KHz */ #else - 0x88, 0x58, 0x01, /* sampleFreq - 88.2KHz */ - 0x00, 0x77, 0x01, /* sampleFreq - 96KHz */ + 0x88, 0x58, 0x01, /* sampleFreq - 88.2KHz */ + 0x00, 0x77, 0x01, /* sampleFreq - 96KHz */ #endif - /* Standard Endpoint Descriptor */ - 0x09, - 0x05, /* ENDPOINT */ + /* Standard Endpoint Descriptor */ + 0x09, + 0x05, /* ENDPOINT */ 0x82, /* EndpointAddress */ 0x05, /* Attributes - isochronous async */ -#if defined(OUTPUT) && defined(INPUT) - 0x26, 0x01, /* maxPacketSize 294 */ +#if defined(OUTPUT) && defined(INPUT) + 0x26, 0x01, /* maxPacketSize 294 */ #else - 0x46, 0x02, /* maxPacketSize 582 */ + 0x46, 0x02, /* maxPacketSize 582 */ #endif - 0x01, /* bInterval */ - 0x00, /* bRefresh */ - 0x00, /* bSynchAddress */ + 0x01, /* bInterval */ + 0x00, /* bRefresh */ + 0x00, /* bSynchAddress */ /* CS_Endpoint Descriptor */ - 0x07, - 0x25, /* CS_ENDPOINT */ - 0x01, /* Subtype - GENERAL */ - 0x01, /* Attributes. D[0]: sample freq ctrl. */ - 0x00, /* Unused */ - 0x00, 0x00, /* Unused */ + 0x07, + 0x25, /* CS_ENDPOINT */ + 0x01, /* Subtype - GENERAL */ + 0x01, /* Attributes. D[0]: sample freq ctrl. */ + 0x00, /* Unused */ + 0x00, 0x00, /* Unused */ #endif #if 0 @@ -1971,4 +1971,4 @@ unsigned char cfgDesc_Audio1[] = }; #endif -#endif +#endif diff --git a/module_usb_audio/endpoint0/endpoint0.h b/module_usb_audio/endpoint0/endpoint0.h index da30bf93..a464c749 100644 --- a/module_usb_audio/endpoint0/endpoint0.h +++ b/module_usb_audio/endpoint0/endpoint0.h @@ -2,12 +2,12 @@ #ifndef _ENDPOINT0_H_ #define _ENDPOINT0_H_ -/** Function implementing Endpoint 0 for enumeration, control and configuration +/** Function implementing Endpoint 0 for enumeration, control and configuration * of USB audio devices. It uses the descriptors defined in ``descriptors_2.h``. - * + * * \param c_ep0_out Chanend connected to the XUD_Manager() out endpoint array * \param c_ep0_in Chanend connected to the XUD_Manager() in endpoint array - * \param c_audioCtrl Chanend connected to the decouple thread for control + * \param c_audioCtrl Chanend connected to the decouple thread for control * audio (sample rate changes etc.) * \param c_mix_ctl Optional chanend to be connected to the mixer thread if * present @@ -15,7 +15,7 @@ * present. * \param c_usb_test Optional chanend to be connected to XUD if test modes required. */ -void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioCtrl, +void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioCtrl, chanend ?c_mix_ctl,chanend ?c_clk_ctl, chanend ?c_usb_test); #endif diff --git a/module_usb_audio/endpoint0/endpoint0.xc b/module_usb_audio/endpoint0/endpoint0.xc index 4994529a..195467ef 100755 --- a/module_usb_audio/endpoint0/endpoint0.xc +++ b/module_usb_audio/endpoint0/endpoint0.xc @@ -59,7 +59,7 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp -/* Global volume and mute tables */ +/* Global volume and mute tables */ int volsOut[NUM_USB_CHAN_OUT + 1]; unsigned int mutesOut[NUM_USB_CHAN_OUT + 1]; //unsigned int multOut[NUM_USB_CHAN_OUT + 1]; @@ -89,7 +89,7 @@ int min(int x, int y); extern unsigned char g_currentConfig; /* Global endpoint status arrays - declared in usb_device.xc */ -extern unsigned char g_interfaceAlt[]; +extern unsigned char g_interfaceAlt[]; /* Global variable for current USB bus speed (i.e. FS/HS) */ unsigned g_curUsbSpeed = 0; @@ -108,7 +108,7 @@ unsigned g_dsdMode = 0; void VendorAudioRequestsInit(chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctl); /* Endpoint 0 function. Handles all requests to the device */ -void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, +void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctl, chanend ?c_usb_test) { USB_SetupPacket_t sp; @@ -133,7 +133,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, for (int i = 0; i < 18*8; i++) { mixer1Weights[i] = 0x8001; //-inf } - + /* Configure default connections */ mixer1Weights[0] = 0; mixer1Weights[9] = 0; @@ -148,26 +148,26 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, /* Setup up audio output channel mapping */ for(int i = 0; i < NUM_USB_CHAN_OUT; i++) { - channelMapAud[i] = i; + channelMapAud[i] = i; } #endif #if NUM_USB_CHAN_IN > 0 for(int i = 0; i < NUM_USB_CHAN_IN; i++) { - channelMapUsb[i] = i + NUM_USB_CHAN_OUT; + channelMapUsb[i] = i + NUM_USB_CHAN_OUT; } #endif /* Set up channel mapping default */ - for (int i = 0; i < NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN; i++) + for (int i = 0; i < NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN; i++) { channelMap[i] = i; } #if MAX_MIX_COUNT > 0 /* Mixer outputs mapping defaults */ - for (int i = 0; i < MAX_MIX_COUNT; i++) + for (int i = 0; i < MAX_MIX_COUNT; i++) { channelMap[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + i] = i; } @@ -197,7 +197,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, safestrcpy(strDescs[ADAT_RX_INDEX + INPUT_INTERFACE_STRING_INDEX + 7], "ADAT 8"); #endif -#if defined(SPDIF) && (SPDIF_TX_INDEX != 0) /* "Analogue naming gets priority */ +#if defined(SPDIF) && (SPDIF_TX_INDEX != 0) /* "Analogue naming gets priority */ safestrcpy(strDescs[SPDIF_TX_INDEX + OUTPUT_INTERFACE_STRING_INDEX], "S/PDIF 1"); safestrcpy(strDescs[SPDIF_TX_INDEX + OUTPUT_INTERFACE_STRING_INDEX + 1], "S/PDIF 2"); #endif @@ -218,7 +218,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, #ifdef DFU /* Check if device has started in DFU mode */ - if (DFUReportResetState(null)) + if (DFUReportResetState(null)) { /* Stop audio */ outuint(c_audioControl, SET_SAMPLE_FREQ); @@ -226,9 +226,9 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, // No Handshake //chkct(c_audioControl, XS1_CT_END); DFU_mode_active = 1; - } + } #endif - + while(1) { /* Returns 0 for success, -1 for bus reset */ @@ -238,11 +238,11 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, { retVal = 1; - /* Inspect Request type and Receipient and direction */ + /* Inspect Request type and Receipient and direction */ switch( (sp.bmRequestType.Direction << 7) | (sp.bmRequestType.Recipient ) | (sp.bmRequestType.Type << 5) ) { case USB_BMREQ_H2D_STANDARD_INT: - + /* Over-riding USB_StandardRequests implementation */ if(sp.bRequest == USB_SET_INTERFACE) { @@ -259,7 +259,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, { outuint(c_audioControl, SET_DSD_MODE); outuint(c_audioControl, DSD_MODE_OFF); - + /* Handshake */ chkct(c_audioControl, XS1_CT_END); g_dsdMode = 0; @@ -271,7 +271,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, /* NOTE there could be a difference between HS/UAC1 and FS/UAC1 channel count */ /* Also note, currently we assume with won't be doing ADAT in FS/UAC1...*/ if(g_curUsbSpeed == XUD_SPEED_HS) - { + { outuint(c_audioControl, SET_CHAN_COUNT_OUT); outuint(c_audioControl, NUM_USB_CHAN_OUT); } @@ -285,7 +285,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, { outuint(c_audioControl, SET_DSD_MODE); outuint(c_audioControl, DSD_MODE_OFF); - + // Handshake chkct(c_audioControl, XS1_CT_END); g_dsdMode = 0; @@ -294,9 +294,9 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, break; #ifdef NATIVE_DSD case 2: - + if(!g_dsdMode) - { + { outuint(c_audioControl, SET_DSD_MODE); outuint(c_audioControl, DSD_MODE_NATIVE); chkct(c_audioControl, XS1_CT_END); @@ -317,7 +317,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, /* NOTE there could be a difference between HS/UAC1 and FS/UAC1 channel count */ /* Also note, currently we assume with won't be doing ADAT in FS/UAC1...*/ if(g_curUsbSpeed == XUD_SPEED_HS) - { + { outuint(c_audioControl, SET_CHAN_COUNT_IN); outuint(c_audioControl, NUM_USB_CHAN_IN); } @@ -326,20 +326,20 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, outuint(c_audioControl, SET_CHAN_COUNT_IN); outuint(c_audioControl, NUM_USB_CHAN_IN_A1); } -#ifdef ADAT_RX +#ifdef ADAT_RX outuint(c_clk_ctl, SET_SMUX); - outuint(c_clk_ctl, 0); + outuint(c_clk_ctl, 0); outct(c_clk_ctl, XS1_CT_END); #endif break; - -#ifdef ADAT_RX + +#ifdef ADAT_RX case 2: /* Stream active + 8 chans */ outuint(c_audioControl, SET_CHAN_COUNT_IN); outuint(c_audioControl, NUM_USB_CHAN_IN-4); outuint(c_clk_ctl, SET_SMUX); - outuint(c_clk_ctl, 1); + outuint(c_clk_ctl, 1); outct(c_clk_ctl, XS1_CT_END); break; @@ -347,11 +347,11 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, outuint(c_audioControl, SET_CHAN_COUNT_IN); outuint(c_audioControl, NUM_USB_CHAN_IN-6); outuint(c_clk_ctl, SET_SMUX); - outuint(c_clk_ctl, 1); + outuint(c_clk_ctl, 1); outct(c_clk_ctl, XS1_CT_END); break; #endif - } + } } #if 1 #if defined(OUTPUT) && defined(INPUT) @@ -392,11 +392,11 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, retVal = XUD_DoSetRequestStatus(ep0_in); } /* if(sp.bRequest == SET_INTERFACE) */ - + break; /* BMREQ_H2D_STANDARD_INT */ - + case USB_BMREQ_D2H_STANDARD_INT: - + switch(sp.bRequest) { @@ -412,29 +412,29 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, { case HID_REPORT: /* Return HID report descriptor */ - retVal = XUD_DoGetRequest(ep0_out, ep0_in, hidReportDescriptor, + retVal = XUD_DoGetRequest(ep0_out, ep0_in, hidReportDescriptor, sizeof(hidReportDescriptor), sp.wLength); break; } } - break; + break; #endif default: break; } break; - + /* Recipient: Device */ case USB_BMREQ_H2D_STANDARD_DEV: - + /* Inspect for actual request */ switch( sp.bRequest ) - { + { /* Standard request: SetConfiguration */ /* Overriding implementation in USB_StandardRequests */ case USB_SET_CONFIGURATION: - + //g_currentConfig = sp.wValue; //if(g_current_config == 1) { @@ -454,19 +454,19 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, //if(retVal == 0) // retVal = 1; break; - + default: //Unknown device request" break; - } + } break; - - /* Audio Class 1.0 Sampling Freqency Requests go to Endpoint */ + + /* Audio Class 1.0 Sampling Freqency Requests go to Endpoint */ case USB_BMREQ_H2D_CLASS_EP: case USB_BMREQ_D2H_CLASS_EP: { unsigned epNum = sp.wIndex & 0xff; - + if ((epNum == 0x82) || (epNum == 0x01)) { #if (AUDIO_CLASS == 2) && defined(AUDIO_CLASS_FALLBACK) @@ -478,12 +478,12 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, retVal = AudioEndpointRequests_1(ep0_out, ep0_in, sp, c_audioControl, c_mix_ctl, c_clk_ctl); #endif } - + } break; - - case USB_BMREQ_H2D_CLASS_INT: - case USB_BMREQ_D2H_CLASS_INT: + + case USB_BMREQ_H2D_CLASS_INT: + case USB_BMREQ_D2H_CLASS_INT: { unsigned interfaceNum = sp.wIndex & 0xff; //unsigned request = (sp.bmRequestType.Recipient ) | (sp.bmRequestType.Type << 5); @@ -493,16 +493,16 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, unsigned DFU_IF = DFU_IF_NUM; /* DFU interface number changes based on which mode we are currently running in */ - if (DFU_mode_active) + if (DFU_mode_active) { DFU_IF = 0; } - if (interfaceNum == DFU_IF) + if (interfaceNum == DFU_IF) { /* If running in application mode stop audio */ /* Don't interupt audio for save and restore cmds */ - if ((DFU_IF == DFU_IF_NUM) && (sp.bRequest != XMOS_DFU_SAVESTATE) && + if ((DFU_IF == DFU_IF_NUM) && (sp.bRequest != XMOS_DFU_SAVESTATE) && (sp.bRequest != XMOS_DFU_RESTORESTATE)) { // Stop audio @@ -511,9 +511,9 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, // Handshake chkct(c_audioControl, XS1_CT_END); } - + /* This will return 1 if reset requested */ - if (DFUDeviceRequests(ep0_out, ep0_in, sp, null, g_interfaceAlt[sp.wIndex], 1)) + if (DFUDeviceRequests(ep0_out, ep0_in, sp, null, g_interfaceAlt[sp.wIndex], 1)) { timer tmr; unsigned s; @@ -524,11 +524,11 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, /* TODO we should not make the assumption that all DFU requests are handled */ retVal = 0; - } + } #endif - /* Check for: - Audio CONTROL interface request - always 0, note we check for DFU first + /* Check for: - Audio CONTROL interface request - always 0, note we check for DFU first * - Audio STREAMING interface request (In or Out) - * - Audio endpoint request (Audio 1.0 Sampling freq requests are sent to the endpoint) + * - Audio endpoint request (Audio 1.0 Sampling freq requests are sent to the endpoint) */ if((interfaceNum == 0) || (interfaceNum == 1) || (interfaceNum == 2)) { @@ -555,33 +555,33 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, retVal = VendorAudioRequests(ep0_out, ep0_in, sp.bRequest, sp.wValue >> 8, sp.wValue & 0xff, sp.wIndex >> 8, sp.bmRequestType.Direction, - c_audioControl, c_mix_ctl, c_clk_ctl); + c_audioControl, c_mix_ctl, c_clk_ctl); } #endif } } break; - + default: break; } - + } /* if(retVal == 0) */ - + if(retVal > 0) { #ifdef DFU - if (!DFU_mode_active) + if (!DFU_mode_active) { #endif #ifdef AUDIO_CLASS_FALLBACK /* Return Audio 2.0 Descriptors with Audio 1.0 as fallback */ - retVal = USB_StandardRequests(ep0_out, ep0_in, - devDesc_Audio2, sizeof(devDesc_Audio2), - cfgDesc_Audio2, sizeof(cfgDesc_Audio2), - devDesc_Audio1, sizeof(devDesc_Audio1), - cfgDesc_Audio1, sizeof(cfgDesc_Audio1), - strDescs, sizeof(strDescs)/sizeof(strDescs[0]), + retVal = USB_StandardRequests(ep0_out, ep0_in, + devDesc_Audio2, sizeof(devDesc_Audio2), + cfgDesc_Audio2, sizeof(cfgDesc_Audio2), + devDesc_Audio1, sizeof(devDesc_Audio1), + cfgDesc_Audio1, sizeof(cfgDesc_Audio1), + strDescs, sizeof(strDescs)/sizeof(strDescs[0]), sp, c_usb_test, g_curUsbSpeed); #elif FULL_SPEED_AUDIO_2 /* Return Audio 2.0 Descriptors for high_speed and full-speed */ @@ -592,75 +592,75 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, /* Mod bSlotSize */ cfgDesc_Audio2[STREAMING_ALT1_OFFSET+4] = SAMPLE_SUBSLOT_SIZE_HS; - /* Mod bBitResolution */ + /* Mod bBitResolution */ cfgDesc_Audio2[STREAMING_ALT1_OFFSET+5] = SAMPLE_BIT_RESOLUTION_HS; /* wMaxPacketSize */ - cfgDesc_Audio2[STREAMING_ALT1_OFFSET+10] = MAX_PACKET_SIZE_OUT_HS&0xff; + cfgDesc_Audio2[STREAMING_ALT1_OFFSET+10] = MAX_PACKET_SIZE_OUT_HS&0xff; cfgDesc_Audio2[STREAMING_ALT1_OFFSET+11] = (MAX_PACKET_SIZE_OUT_HS&0xff00)>>8; } else { /* Mod bSlotSize */ cfgDesc_Audio2[STREAMING_ALT1_OFFSET+4] = SAMPLE_SUBSLOT_SIZE_FS; - - /* Mod bBitResolution */ + + /* Mod bBitResolution */ cfgDesc_Audio2[STREAMING_ALT1_OFFSET+5] = SAMPLE_BIT_RESOLUTION_FS; - + /* wMaxPacketSize */ - cfgDesc_Audio2[STREAMING_ALT1_OFFSET+10] = MAX_PACKET_SIZE_OUT_FS&0xff; + cfgDesc_Audio2[STREAMING_ALT1_OFFSET+10] = MAX_PACKET_SIZE_OUT_FS&0xff; cfgDesc_Audio2[STREAMING_ALT1_OFFSET+11] = (MAX_PACKET_SIZE_OUT_FS&0xff00)>>8; } - retVal = USB_StandardRequests(ep0_out, ep0_in, - devDesc_Audio2, sizeof(devDesc_Audio2), - cfgDesc_Audio2, sizeof(cfgDesc_Audio2), - null, 0, - null, 0, + retVal = USB_StandardRequests(ep0_out, ep0_in, + devDesc_Audio2, sizeof(devDesc_Audio2), + cfgDesc_Audio2, sizeof(cfgDesc_Audio2), + null, 0, + null, 0, strDescs, sizeof(strDescs)/sizeof(strDescs[0]), sp, c_usb_test, g_curUsbSpeed); #else /* Return Audio 2.0 Descriptors with Null device as fallback */ - retVal = USB_StandardRequests(ep0_out, ep0_in, - devDesc_Audio2, sizeof(devDesc_Audio2), - cfgDesc_Audio2, sizeof(cfgDesc_Audio2), - devDesc_Null, sizeof(devDesc_Null), - cfgDesc_Null, sizeof(cfgDesc_Null), + retVal = USB_StandardRequests(ep0_out, ep0_in, + devDesc_Audio2, sizeof(devDesc_Audio2), + cfgDesc_Audio2, sizeof(cfgDesc_Audio2), + devDesc_Null, sizeof(devDesc_Null), + cfgDesc_Null, sizeof(cfgDesc_Null), strDescs, sizeof(strDescs)/sizeof(strDescs[0]), sp, c_usb_test, g_curUsbSpeed); #endif #ifdef DFU - } - else + } + else { /* Running in DFU mode - always return same descs for DFU whether HS or FS */ - retVal = USB_StandardRequests(ep0_out, ep0_in, - DFUdevDesc, sizeof(DFUdevDesc), - DFUcfgDesc, sizeof(DFUcfgDesc), + retVal = USB_StandardRequests(ep0_out, ep0_in, + DFUdevDesc, sizeof(DFUdevDesc), + DFUcfgDesc, sizeof(DFUcfgDesc), null, 0, /* Used same descriptors for full and high-speed */ - null, 0, + null, 0, strDescs, sizeof(strDescs), sp, c_usb_test, g_curUsbSpeed); } #endif } - - if (retVal < 0) + + if (retVal < 0) { g_curUsbSpeed = XUD_ResetEndpoint(ep0_out, ep0_in); g_currentConfig = 0; #ifdef DFU - if (DFUReportResetState(null)) + if (DFUReportResetState(null)) { - if (!DFU_mode_active) + if (!DFU_mode_active) { timer tmr; unsigned s; DFU_mode_active = 1; } - } - else + } + else { - if (DFU_mode_active) + if (DFU_mode_active) { timer tmr; unsigned s; diff --git a/module_usb_audio/endpoint0/vendorrequests.h b/module_usb_audio/endpoint0/vendorrequests.h index 9e6c43ea..680464ba 100644 --- a/module_usb_audio/endpoint0/vendorrequests.h +++ b/module_usb_audio/endpoint0/vendorrequests.h @@ -9,7 +9,7 @@ * * */ -int VendorAudioRequests(XUD_ep ep0_out, XUD_ep ep0_in, unsigned char bRequest, unsigned char cs, unsigned char cn, +int VendorAudioRequests(XUD_ep ep0_out, XUD_ep ep0_in, unsigned char bRequest, unsigned char cs, unsigned char cn, unsigned short unitId, unsigned char direction, chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctL); #endif diff --git a/module_usb_audio/flashlib_user.c b/module_usb_audio/flashlib_user.c index b5d3a8d3..028b2760 100644 --- a/module_usb_audio/flashlib_user.c +++ b/module_usb_audio/flashlib_user.c @@ -18,7 +18,7 @@ fl_DeviceSpec flash_devices[] = {DFU_FLASH_DEVICE}; #endif -fl_PortHolderStruct p_flash = +fl_PortHolderStruct p_flash = { XS1_PORT_1A, XS1_PORT_1B, @@ -27,7 +27,7 @@ fl_PortHolderStruct p_flash = XS1_CLKBLK_1 }; -int flash_cmd_enable_ports() +int flash_cmd_enable_ports() { int result = 0; setc(p_flash.spiMISO, XS1_SETC_INUSE_OFF); @@ -61,17 +61,17 @@ int flash_cmd_enable_ports() /* Use default flash list */ result = fl_connect(&p_flash); #endif - if (!result) + if (!result) { return 1; - } - else + } + else { return 0; } } -int flash_cmd_disable_ports() +int flash_cmd_disable_ports() { fl_disconnect(); diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index e6eadbdd..83ded3c7 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -1,8 +1,8 @@ /** * @file main.xc * @brief Top level for XMOS USB 2.0 Audio 2.0 Reference Designs. - * @author Ross Owen, XMOS Semiconductor Ltd - */ + * @author Ross Owen, XMOS Semiconductor Ltd + */ #include #include #include @@ -15,7 +15,7 @@ #include "xud.h" /* XMOS USB Device Layer defines and functions */ #include "usb.h" /* Defines from the USB 2.0 Specification */ -#include "devicedefines.h" /* Device specific defines */ +#include "devicedefines.h" /* Device specific defines */ #include "endpoint0.h" #include "usb_buffer.h" #include "decouple.h" @@ -42,26 +42,26 @@ /* Audio I/O - Port declarations */ #if I2S_WIRES_DAC > 0 -on tile[AUDIO_IO_TILE] : buffered out port:32 p_i2s_dac[I2S_WIRES_DAC] = +on tile[AUDIO_IO_TILE] : buffered out port:32 p_i2s_dac[I2S_WIRES_DAC] = {PORT_I2S_DAC0, -#endif +#endif #if I2S_WIRES_DAC > 1 - PORT_I2S_DAC1, + PORT_I2S_DAC1, #endif #if I2S_WIRES_DAC > 2 - PORT_I2S_DAC2, + PORT_I2S_DAC2, #endif #if I2S_WIRES_DAC > 3 - PORT_I2S_DAC3, + PORT_I2S_DAC3, #endif #if I2S_WIRES_DAC > 4 - PORT_I2S_DAC4, + PORT_I2S_DAC4, #endif #if I2S_WIRES_DAC > 5 - PORT_I2S_DAC5, + PORT_I2S_DAC5, #endif #if I2S_WIRES_DAC > 6 - PORT_I2S_DAC6, + PORT_I2S_DAC6, #endif #if I2S_WIRES_DAC > 7 #error Not supported @@ -71,26 +71,26 @@ on tile[AUDIO_IO_TILE] : buffered out port:32 p_i2s_dac[I2S_WIRES_DAC] = #endif #if I2S_WIRES_ADC > 0 -on tile[AUDIO_IO_TILE] : buffered in port:32 p_i2s_adc[I2S_WIRES_ADC] = +on tile[AUDIO_IO_TILE] : buffered in port:32 p_i2s_adc[I2S_WIRES_ADC] = {PORT_I2S_ADC0, -#endif +#endif #if I2S_WIRES_ADC > 1 - PORT_I2S_ADC1, + PORT_I2S_ADC1, #endif #if I2S_WIRES_ADC > 2 - PORT_I2S_ADC2, + PORT_I2S_ADC2, #endif #if I2S_WIRES_ADC > 3 - PORT_I2S_ADC3, + PORT_I2S_ADC3, #endif #if I2S_WIRES_ADC > 4 - PORT_I2S_ADC4, + PORT_I2S_ADC4, #endif #if I2S_WIRES_ADC > 5 - PORT_I2S_ADC5, + PORT_I2S_ADC5, #endif #if I2S_WIRES_ADC > 6 - PORT_I2S_ADC6, + PORT_I2S_ADC6, #endif #if I2S_WIRES_ADC > 7 #error Not supported @@ -111,7 +111,7 @@ on tile[AUDIO_IO_TILE] : in port p_bclk = PORT_I2S_BCLK; on tile[AUDIO_IO_TILE] : port p_mclk_in = PORT_MCLK_IN; on tile[XUD_TILE] : in port p_for_mclk_count = PORT_MCLK_COUNT; -#ifdef SPDIF +#ifdef SPDIF on tile[AUDIO_IO_TILE] : buffered out port:32 p_spdif_tx = PORT_SPDIF_OUT; #endif @@ -128,7 +128,7 @@ on tile[AUDIO_IO_TILE] : clock clk_audio_mclk = XS1_CLKBLK_2; #if(AUDIO_IO_TILE != XUD_TILE) on tile[XUD_TILE] : clock clk_audio_mclk2 = XS1_CLKBLK_2; /* Master clock */ -on tile[XUD_TILE] : in port p_mclk_in2 = PORT_MCLK_IN2; +on tile[XUD_TILE] : in port p_mclk_in2 = PORT_MCLK_IN2; #endif @@ -160,7 +160,7 @@ on tile [AUDIO_IO_TILE] : port p_i2c_scl = PORT_I2C_SCL; /* Endpoint type tables for XUD */ -XUD_EpType epTypeTableOut[EP_CNT_OUT] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, +XUD_EpType epTypeTableOut[EP_CNT_OUT] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, XUD_EPTYPE_ISO, /* Audio */ #ifdef MIDI XUD_EPTYPE_BUL, /* MIDI */ @@ -168,10 +168,10 @@ XUD_EpType epTypeTableOut[EP_CNT_OUT] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, #ifdef IAP XUD_EPTYPE_BUL | XUD_STATUS_ENABLE /* iAP */ #endif - }; + }; XUD_EpType epTypeTableIn[EP_CNT_IN] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, - XUD_EPTYPE_ISO, + XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, #if defined (SPDIF_RX) || defined (ADAT_RX) XUD_EPTYPE_BUL, @@ -226,49 +226,49 @@ void usb_audio_core(chanend c_mix_out , chanend c_mix_ctl #endif ) -{ - chan c_sof; - chan c_xud_out[EP_CNT_OUT]; /* Endpoint channels for XUD */ - chan c_xud_in[EP_CNT_IN]; - chan c_aud_ctl; -#ifdef TEST_MODE_SUPPORT -#warning Building with test mode support - chan c_usb_test; -#else -#define c_usb_test null -#endif -#ifdef CHAN_BUFF_CTRL -#warning Using channel to control buffering - this may reduce performance but improve power consumption - chan c_buff_ctrl; -#endif +{ + chan c_sof; + chan c_xud_out[EP_CNT_OUT]; /* Endpoint channels for XUD */ + chan c_xud_in[EP_CNT_IN]; + chan c_aud_ctl; +#ifdef TEST_MODE_SUPPORT +#warning Building with test mode support + chan c_usb_test; +#else +#define c_usb_test null +#endif +#ifdef CHAN_BUFF_CTRL +#warning Using channel to control buffering - this may reduce performance but improve power consumption + chan c_buff_ctrl; +#endif #ifndef MIXER #define c_mix_ctl null #endif - par - { - /* USB Interface Core */ -#if (AUDIO_CLASS==2) - XUD_Manager(c_xud_out, EP_CNT_OUT, c_xud_in, EP_CNT_IN, - c_sof, epTypeTableOut, epTypeTableIn, p_usb_rst, - clk, 1, XUD_SPEED_HS, c_usb_test, pwrConfig); -#else - XUD_Manager(c_xud_out, EP_CNT_OUT, c_xud_in, EP_CNT_IN, - c_sof, epTypeTableOut, epTypeTableIn, p_usb_rst, - clk, 1, XUD_SPEED_FS, c_usb_test, pwrConfig); -#endif + par + { + /* USB Interface Core */ +#if (AUDIO_CLASS==2) + XUD_Manager(c_xud_out, EP_CNT_OUT, c_xud_in, EP_CNT_IN, + c_sof, epTypeTableOut, epTypeTableIn, p_usb_rst, + clk, 1, XUD_SPEED_HS, c_usb_test, pwrConfig); +#else + XUD_Manager(c_xud_out, EP_CNT_OUT, c_xud_in, EP_CNT_IN, + c_sof, epTypeTableOut, epTypeTableIn, p_usb_rst, + clk, 1, XUD_SPEED_FS, c_usb_test, pwrConfig); +#endif - /* USB Packet buffering Core */ + /* USB Packet buffering Core */ { unsigned x; thread_speed(); - + /* Attach mclk count port to mclk clock-block (for feedback) */ //set_port_clock(p_for_mclk_count, clk_audio_mclk); #if(AUDIO_IO_TILE != 0) set_clock_src(clk_audio_mclk2, p_mclk_in2); - set_port_clock(p_for_mclk_count, clk_audio_mclk2); + set_port_clock(p_for_mclk_count, clk_audio_mclk2); start_clock(clk_audio_mclk2); #else /* Uses same clock-block as I2S */ @@ -278,7 +278,7 @@ void usb_audio_core(chanend c_mix_out buffer(c_xud_out[EP_NUM_OUT_AUD],/* Audio Out*/ c_xud_in[EP_NUM_IN_AUD], /* Audio In */ c_xud_in[EP_NUM_IN_FB], /* Audio FB */ -#ifdef MIDI +#ifdef MIDI c_xud_out[EP_NUM_OUT_MIDI], /* MIDI Out */ // 2 c_xud_in[EP_NUM_IN_MIDI], /* MIDI In */ // 4 c_midi, @@ -288,8 +288,8 @@ void usb_audio_core(chanend c_mix_out #endif #if defined(SPDIF_RX) || defined(ADAT_RX) /* Audio Interrupt - only used for interrupts on external clock change */ - c_xud_in[EP_NUM_IN_AUD_INT], -#endif + c_xud_in[EP_NUM_IN_AUD_INT], +#endif c_sof, c_aud_ctl, p_for_mclk_count #ifdef HID_CONTROLS , c_xud_in[EP_NUM_IN_HID] @@ -305,8 +305,8 @@ void usb_audio_core(chanend c_mix_out thread_speed(); Endpoint0( c_xud_out[0], c_xud_in[0], c_aud_ctl, c_mix_ctl, null, c_usb_test); } - - /* Decoupling core */ + + /* Decoupling core */ { thread_speed(); decouple(c_mix_out, null @@ -334,24 +334,24 @@ void usb_audio_io(chanend c_aud_in, chanend ?c_adc par { - + #ifdef MIXER /* Mixer cores(s) */ - { + { thread_speed(); mixer(c_aud_in, c_mix_out, c_mix_ctl); } #endif - /* Audio I/O Core (pars additional S/PDIF TX Core) */ + /* Audio I/O Core (pars additional S/PDIF TX Core) */ { thread_speed(); #ifdef MIXER audio(c_mix_out, null, null, c_adc); #else audio(c_aud_in, null, null, c_adc); -#endif +#endif } - + /* MIDI/iAP Core */ #if defined (MIDI) || defined IAP { @@ -360,7 +360,7 @@ void usb_audio_io(chanend c_aud_in, chanend ?c_adc usb_midi(p_midi_rx, p_midi_tx, clk_midi, c_midi, 0, null, null, null, null); #else iAP(c_iap, null, null, null); -#endif +#endif } #endif @@ -402,8 +402,8 @@ int main() par { - on tile[XUD_TILE]: usb_audio_core(c_mix_out -#ifdef MIDI + on tile[XUD_TILE]: usb_audio_core(c_mix_out +#ifdef MIDI , c_midi #endif #ifdef IAP @@ -413,7 +413,7 @@ int main() , c_mix_ctl #endif ); - + on tile[AUDIO_IO_TILE]: usb_audio_io(c_mix_out, c_adc #ifdef MIDI , c_midi @@ -433,7 +433,7 @@ int main() #ifdef SU1_ADC_ENABLE xs1_su_adc_service(c_adc); #endif - + return 0; } diff --git a/module_usb_audio/mixer/fastmix.S b/module_usb_audio/mixer/fastmix.S index af8ca56f..db4c31ee 100644 --- a/module_usb_audio/mixer/fastmix.S +++ b/module_usb_audio/mixer/fastmix.S @@ -1,176 +1,176 @@ -//#include "devicedefines.h" - -#define MAX_MIX_COUNT 8 -#define MIX_INPUTS 18 - - - -#define DOMIX_TOP(i) \ -.cc_top doMix##i.function,doMix##i; \ - .align 4 ;\ -.globl doMix##i ;\ -.type doMix##i, @function ;\ -.globl doMix##i##.nstackwords ;\ -.globl doMix##i##.maxthreads ; \ -.globl doMix##i##.maxtimers ; \ -.globl doMix##i##.maxchanends ; \ -.globl doMix##i##.maxsync ;\ -.linkset doMix##i##.locnoside, 1; \ -.linkset doMix##i##.locnochandec, 1;\ -.linkset doMix##i##.nstackwords, 0 ;\ -.linkset doMix##i##.maxchanends, 0 ;\ -.linkset doMix##i##.maxtimers, 0 ;\ -.linkset doMix##i##.maxthreads, 1; \ -doMix##i##: ;\ - set cp, r0; \ - set dp, r1; \ - lsub r0, r1, r0, r0, r0;\ - .label_##i##: - -#define DOMIX_BOT(i) \ - ldap r11, _dp; \ - set dp, r11;\ - ldap r11, _cp;\ - set cp, r11;\ -\ - mov r0, r1;\ - ldc r2, 0x19;\ - sext r0, r2;\ - eq r0, r0, r1;\ - bf r0, .L20; \ -\ - shl r0, r1, 0x7;\ - retsp 0x0;\ -\ -\ -.size doMix##i, .-doMix##i; \ -.cc_bottom doMix##i##.function; - -#define N MIX_INPUTS -#define BODY(i) \ - ldw r2,cp[i]; \ - ldw r11, dp[i]; \ - maccs r1, r0, r2, r11; - - -.text - -.L20:\ - lss r0, r1, r3;\ - bt r0, .L16; \ - ldw r0, cp[.LC0];\ - retsp 0x0; \ -.L16:\ - ldw r0, cp[.LC1];\ - retsp 0x0; \ - - - - -#if(MAX_MIX_COUNT > 0) -DOMIX_TOP(0) -#include "repeat.h" -DOMIX_BOT(0) -#endif - - -#if(MAX_MIX_COUNT > 1) -DOMIX_TOP(1) -#include "repeat.h" -DOMIX_BOT(1) -#endif - -#if(MAX_MIX_COUNT > 2) -DOMIX_TOP(2) -#include "repeat.h" -DOMIX_BOT(2) -#endif - -#if(MAX_MIX_COUNT > 3) -DOMIX_TOP(3) -#include "repeat.h" -DOMIX_BOT(3) -#endif - -#if(MAX_MIX_COUNT > 4) -DOMIX_TOP(4) -#include "repeat.h" -DOMIX_BOT(4) -#endif - -#if(MAX_MIX_COUNT > 5) -DOMIX_TOP(5) -#include "repeat.h" -DOMIX_BOT(5) -#endif - -#if(MAX_MIX_COUNT > 6) -DOMIX_TOP(6) -#include "repeat.h" -DOMIX_BOT(6) -#endif - -#if(MAX_MIX_COUNT > 7) -DOMIX_TOP(7) -#include "repeat.h" -DOMIX_BOT(7) -#endif - -#if(MAX_MIX_COUNT>8) -#error MAX_MIX_COUNT>7 -#endif - -/* We need MIX_OUTPUT x setPtr functions */ - -#undef N -#undef BODY -#define N MAX_MIX_COUNT -.cc_top setPtr.function,setPtr; -.align 4 ; -.globl setPtr; -.type setPtr, @function -.globl setPtr.nstackwords; -.globl setPtr.maxthreads; -.globl setPtr.maxtimers; -.globl setPtr.maxchanends; -.globl setPtr.maxsync; -.linkset setPtr.locnoside, 1; -.linkset setPtr.locnochandec, 1; -.linkset setPtr.nstackwords, 0; -.linkset setPtr.maxchanends, 0; -.linkset setPtr.maxtimers, 0; -.linkset setPtr.maxthreads, 1; -setPtr: - shl r2, r2, 1 -.xtabranch .label_0 - bru r2 -#define BODY(i) \ - ldap r11, .label_##i; \ - bu setPtr_go -#include "repeat.h" -setPtr_go: - shl r0, r0, 3; - ldc r2, 0x80; - add r1, r1, r2; - st8 r1, r11[r0]; - retsp 0; -.size setPtr, .-setPtr -.cc_bottom setPtr.function - - .section .cp.const4, "acM", @progbits, 4 -.cc_top .LC0.data - .align 4 -.LC0: - .int 0x7fffff00 -.cc_bottom .LC0.data -.cc_top .LC1.data - .align 4 -.LC1: - .int 0x80000000 -.cc_bottom .LC1.data - -#undef N -#undef BODY - - - +//#include "devicedefines.h" + +#define MAX_MIX_COUNT 8 +#define MIX_INPUTS 18 + + + +#define DOMIX_TOP(i) \ +.cc_top doMix##i.function,doMix##i; \ + .align 4 ;\ +.globl doMix##i ;\ +.type doMix##i, @function ;\ +.globl doMix##i##.nstackwords ;\ +.globl doMix##i##.maxthreads ; \ +.globl doMix##i##.maxtimers ; \ +.globl doMix##i##.maxchanends ; \ +.globl doMix##i##.maxsync ;\ +.linkset doMix##i##.locnoside, 1; \ +.linkset doMix##i##.locnochandec, 1;\ +.linkset doMix##i##.nstackwords, 0 ;\ +.linkset doMix##i##.maxchanends, 0 ;\ +.linkset doMix##i##.maxtimers, 0 ;\ +.linkset doMix##i##.maxthreads, 1; \ +doMix##i##: ;\ + set cp, r0; \ + set dp, r1; \ + lsub r0, r1, r0, r0, r0;\ + .label_##i##: + +#define DOMIX_BOT(i) \ + ldap r11, _dp; \ + set dp, r11;\ + ldap r11, _cp;\ + set cp, r11;\ +\ + mov r0, r1;\ + ldc r2, 0x19;\ + sext r0, r2;\ + eq r0, r0, r1;\ + bf r0, .L20; \ +\ + shl r0, r1, 0x7;\ + retsp 0x0;\ +\ +\ +.size doMix##i, .-doMix##i; \ +.cc_bottom doMix##i##.function; + +#define N MIX_INPUTS +#define BODY(i) \ + ldw r2,cp[i]; \ + ldw r11, dp[i]; \ + maccs r1, r0, r2, r11; + + +.text + +.L20:\ + lss r0, r1, r3;\ + bt r0, .L16; \ + ldw r0, cp[.LC0];\ + retsp 0x0; \ +.L16:\ + ldw r0, cp[.LC1];\ + retsp 0x0; \ + + + + +#if(MAX_MIX_COUNT > 0) +DOMIX_TOP(0) +#include "repeat.h" +DOMIX_BOT(0) +#endif + + +#if(MAX_MIX_COUNT > 1) +DOMIX_TOP(1) +#include "repeat.h" +DOMIX_BOT(1) +#endif + +#if(MAX_MIX_COUNT > 2) +DOMIX_TOP(2) +#include "repeat.h" +DOMIX_BOT(2) +#endif + +#if(MAX_MIX_COUNT > 3) +DOMIX_TOP(3) +#include "repeat.h" +DOMIX_BOT(3) +#endif + +#if(MAX_MIX_COUNT > 4) +DOMIX_TOP(4) +#include "repeat.h" +DOMIX_BOT(4) +#endif + +#if(MAX_MIX_COUNT > 5) +DOMIX_TOP(5) +#include "repeat.h" +DOMIX_BOT(5) +#endif + +#if(MAX_MIX_COUNT > 6) +DOMIX_TOP(6) +#include "repeat.h" +DOMIX_BOT(6) +#endif + +#if(MAX_MIX_COUNT > 7) +DOMIX_TOP(7) +#include "repeat.h" +DOMIX_BOT(7) +#endif + +#if(MAX_MIX_COUNT>8) +#error MAX_MIX_COUNT>7 +#endif + +/* We need MIX_OUTPUT x setPtr functions */ + +#undef N +#undef BODY +#define N MAX_MIX_COUNT +.cc_top setPtr.function,setPtr; +.align 4 ; +.globl setPtr; +.type setPtr, @function +.globl setPtr.nstackwords; +.globl setPtr.maxthreads; +.globl setPtr.maxtimers; +.globl setPtr.maxchanends; +.globl setPtr.maxsync; +.linkset setPtr.locnoside, 1; +.linkset setPtr.locnochandec, 1; +.linkset setPtr.nstackwords, 0; +.linkset setPtr.maxchanends, 0; +.linkset setPtr.maxtimers, 0; +.linkset setPtr.maxthreads, 1; +setPtr: + shl r2, r2, 1 +.xtabranch .label_0 + bru r2 +#define BODY(i) \ + ldap r11, .label_##i; \ + bu setPtr_go +#include "repeat.h" +setPtr_go: + shl r0, r0, 3; + ldc r2, 0x80; + add r1, r1, r2; + st8 r1, r11[r0]; + retsp 0; +.size setPtr, .-setPtr +.cc_bottom setPtr.function + + .section .cp.const4, "acM", @progbits, 4 +.cc_top .LC0.data + .align 4 +.LC0: + .int 0x7fffff00 +.cc_bottom .LC0.data +.cc_top .LC1.data + .align 4 +.LC1: + .int 0x80000000 +.cc_bottom .LC1.data + +#undef N +#undef BODY + + + diff --git a/module_usb_audio/mixer/mixer.h b/module_usb_audio/mixer/mixer.h index 56d144e1..ef04b1dc 100644 --- a/module_usb_audio/mixer/mixer.h +++ b/module_usb_audio/mixer/mixer.h @@ -18,14 +18,14 @@ enum mix_ctl_cmd { * * This thread mixes audio streams between the decouple() thread and * the audio() thread. - * + * * \param c_to_host a chanend connected to the decouple() thread for * receiving/transmitting samples * \param c_to_audio a chanend connected to the audio() thread for * receiving/transmitting samples * \param c_mix_ctl a chanend connected to the Endpoint0() thread for - * receiving control commands - * + * receiving control commands + * */ void mixer(chanend c_to_host, chanend c_to_audio, chanend c_mix_ctl); diff --git a/module_usb_audio/mixer/mixer.xc b/module_usb_audio/mixer/mixer.xc index 6b2c841c..cdf7418e 100644 --- a/module_usb_audio/mixer/mixer.xc +++ b/module_usb_audio/mixer/mixer.xc @@ -19,7 +19,7 @@ unsigned int multIn_array[NUM_USB_CHAN_IN + 1]; static xc_ptr multIn; #endif -#if defined (LEVEL_METER_LEDS) || defined (LEVEL_METER_HOST) +#if defined (LEVEL_METER_LEDS) || defined (LEVEL_METER_HOST) static unsigned abs(int x) { #if 0 @@ -49,7 +49,7 @@ int mix_mult_array[MAX_MIX_COUNT][MIX_INPUTS]; xc_ptr mix_mult; #define write_word_to_mix_mult(x,y,val) write_via_xc_ptr_indexed(mix_mult,((x)*MIX_INPUTS)+(y), val) #define mix_mult_slice(x) (mix_mult + x * MIX_INPUTS * sizeof(int)) -#ifndef FAST_MIXER +#ifndef FAST_MIXER int mix_map_array[MAX_MIX_COUNT][MIX_INPUTS]; xc_ptr mix_map; #define write_word_to_mix_map(x,y,val) write_via_xc_ptr_indexed(mix_map,((x)*MIX_INPUTS)+(y), val) @@ -77,7 +77,7 @@ static int samples_to_host_outputs[NUM_USB_CHAN_OUT]; /* Device outputs */ #pragma xta command "set required - 10400 ns" /* 96kHz */ #endif -#if defined (LEVEL_METER_LEDS) || defined (LEVEL_METER_HOST) +#if defined (LEVEL_METER_LEDS) || defined (LEVEL_METER_HOST) static inline void ComputeMixerLevel(int sample, int i) { int x; @@ -88,8 +88,8 @@ static inline void ComputeMixerLevel(int sample, int i) x = abs(sample); /* y = samples_to_host_outputs[i] */ - asm("ldaw %0, dp[samples_to_host_outputs]":"=r"(ptr):); /* Might want to hoist this */ - asm("ldw %0, %1[%2]":"=r"(y):"r"(ptr),"r"(i)); + asm("ldaw %0, dp[samples_to_host_outputs]":"=r"(ptr):); /* Might want to hoist this */ + asm("ldw %0, %1[%2]":"=r"(y):"r"(ptr),"r"(i)); if(x > y) { @@ -116,12 +116,12 @@ int doMix8(xc_ptr samples, xc_ptr mult); #pragma unsafe arrays static int doMix(xc_ptr samples, xc_ptr ptr, xc_ptr mult) { - int h=0; - int l=0; + int h=0; + int l=0; /* By breaking up the loop we keep things in the encoding for ldw (0-11) */ #pragma loop unroll - for (int i=0; i>32) + if(h>>32) h = (0x80000000>>7); else h = (0x7fffff00>>7); @@ -159,7 +159,7 @@ static void giveSamplesToHost(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr mult #endif #pragma loop unroll - for (int i=0;i 0 case SET_SAMPLES_TO_HOST_MAP: @@ -331,7 +331,7 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2) inct(c_mix_ctl); write_via_xc_ptr_indexed(samples_to_device_map,index,val); break; - + case SET_MIX_MULT: mix = inuint(c_mix_ctl); index = inuint(c_mix_ctl); @@ -340,7 +340,7 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2) write_word_to_mix_mult(mix, index, val); break; - + case SET_MIX_MAP: mix = inuint(c_mix_ctl); index = inuint(c_mix_ctl); /* mixer input */ @@ -381,12 +381,12 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2) outct(c_mix_ctl, XS1_CT_END); samples_to_host_streams[index] = 0; break; - + case GET_INPUT_LEVELS: index = inuint(c_mix_ctl); chkct(c_mix_ctl, XS1_CT_END); -#ifdef LEVEL_METER_LEDS - /* Level LEDS process reseting samples_to_host_inputs +#ifdef LEVEL_METER_LEDS + /* Level LEDS process reseting samples_to_host_inputs * Other side makes sure we don't miss a peak */ read_via_xc_ptr_indexed(val, samples_to_host_inputs_buff, index); write_via_xc_ptr_indexed(samples_to_host_inputs_buff, index, 0); @@ -399,7 +399,7 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2) outct(c_mix_ctl, XS1_CT_END); break; -#if MAX_MIX_COUNT > 0 +#if MAX_MIX_COUNT > 0 case GET_OUTPUT_LEVELS: index = inuint(c_mix_ctl); chkct(c_mix_ctl, XS1_CT_END); @@ -428,8 +428,8 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2) mixer1_mix2_flag = sampFreq > 96000; -#pragma loop unroll - for (int i=0;i 0 @@ -465,9 +465,9 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2) ComputeMixerLevel(mixed, 0); #endif -#if (MAX_FREQ > 96000) +#if (MAX_FREQ > 96000) if (!mixer1_mix2_flag) -#endif +#endif { #if MAX_MIX_COUNT > 2 @@ -522,7 +522,7 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2) static int mixer2_mix2_flag = (DEFAULT_FREQ > 96000); -#if (MAX_MIX_COUNT > 0) +#if (MAX_MIX_COUNT > 0) #pragma unsafe arrays static void mixer2(chanend c_mixer1, chanend c_audio) { @@ -532,7 +532,7 @@ static void mixer2(chanend c_mixer1, chanend c_audio) outuint(c_mixer1, 0); #pragma xta endpoint "mixer2_req" inuint(c_audio); - if(testct(c_mixer1)) + if(testct(c_mixer1)) { int sampFreq; #pragma xta endpoint "mixer2_rate_change" @@ -541,8 +541,8 @@ static void mixer2(chanend c_mixer1, chanend c_audio) mixer2_mix2_flag = sampFreq > 96000; - - for (int i=0;i 96000) - if (!mixer2_mix2_flag) +#if (MAX_FREQ > 96000) + if (!mixer2_mix2_flag) #endif { #if MAX_MIX_COUNT > 3 @@ -610,7 +610,7 @@ static void mixer2(chanend c_mixer1, chanend c_audio) ComputeMixerLevel(mixed, 5); #endif #endif - + #if MAX_MIX_COUNT > 7 #ifdef FAST_MIXER mixed = doMix7(samples, mix_mult_slice(7)); @@ -649,14 +649,14 @@ void mixer(chanend c_mix_in, chanend c_mix_out, chanend c_mix_ctl) #endif #endif - for (int i=0;i 96000 ? 2 : MAX_MIX_COUNT; - for (int i=0;i 0 for (int i=0;i 0) +#if (MAX_MIX_COUNT > 0) mixer1(c_mix_in, c_mix_ctl, c); mixer2(c, c_mix_out); #else diff --git a/module_usb_audio/ports/audioports.c b/module_usb_audio/ports/audioports.c index 8b1e51cc..116b7f40 100644 --- a/module_usb_audio/ports/audioports.c +++ b/module_usb_audio/ports/audioports.c @@ -11,9 +11,9 @@ #if DSD_CHANS_DAC > 0 port p_dsd_dac[DSD_CHANS_DAC] = { PORT_DSD_DAC0, -#endif +#endif #if DSD_CHANS_DAC > 1 - PORT_DSD_DAC1, + PORT_DSD_DAC1, #endif #if DSD_CHANS_DAC > 2 #error > 2 DSD chans currently not supported @@ -44,14 +44,14 @@ void ConfigAudioPortsWrapper( #if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0) #ifndef CODEC_MASTER - port p_lrclk, + port p_lrclk, port p_bclk, #else in port p_lrclk, in port p_bclk, #endif #endif -unsigned int divide, unsigned int dsdMode) +unsigned int divide, unsigned int dsdMode) { if(dsdMode) @@ -59,9 +59,9 @@ unsigned int divide, unsigned int dsdMode) /* Make sure the ports are on and buffered - just in case they are not shared with I2S */ for(int i = 0; i< DSD_CHANS_DAC; i++) { - EnableBufferedPort(p_dsd_dac[i], 32); + EnableBufferedPort(p_dsd_dac[i], 32); } - EnableBufferedPort(p_dsd_clk, 32); + EnableBufferedPort(p_dsd_clk, 32); ConfigAudioPorts( #if (DSD_CHANS_DAC != 0) @@ -87,7 +87,7 @@ unsigned int divide, unsigned int dsdMode) else { ConfigAudioPorts( -#if (I2S_CHANS_DAC != 0) +#if (I2S_CHANS_DAC != 0) p_i2s_dac, I2S_WIRES_DAC, #endif @@ -104,7 +104,7 @@ unsigned int divide, unsigned int dsdMode) p_bclk, #endif #endif - divide); + divide); } } #endif diff --git a/module_usb_audio/ports/audioports.h b/module_usb_audio/ports/audioports.h index 6f8c506d..3933b11b 100644 --- a/module_usb_audio/ports/audioports.h +++ b/module_usb_audio/ports/audioports.h @@ -8,7 +8,7 @@ void ConfigAudioPorts_dsd(unsigned int divide); #ifdef __XC__ -void ConfigAudioPorts( +void ConfigAudioPorts( #if (I2S_CHANS_DAC != 0) || (DSD_CHANS_DAC != 0) buffered out port:32 p_i2s_dac[], int numDacPorts, @@ -32,7 +32,7 @@ void ConfigAudioPorts( unsigned int divide); #else -void ConfigAudioPorts( +void ConfigAudioPorts( #if (I2S_CHANS_DAC != 0) || (DSD_CHANS_DAC != 0) port p_i2s_dac[], int numDacPorts, @@ -59,7 +59,7 @@ void ConfigAudioPorts( #ifdef __XC__ -void ConfigAudioPortsWrapper( +void ConfigAudioPortsWrapper( #if (I2S_CHANS_DAC != 0) buffered out port:32 p_i2s_dac[I2S_WIRES_DAC], #endif @@ -80,7 +80,7 @@ void ConfigAudioPortsWrapper( unsigned int divide, unsigned int dsdMode); #else -void ConfigAudioPortsWrapper( +void ConfigAudioPortsWrapper( #if (I2S_CHANS_DAC != 0) port p_i2s_dac[I2S_WIRES_DAC], #endif diff --git a/module_usb_audio/ports/audioports.xc b/module_usb_audio/ports/audioports.xc index 589f60ac..d55e900e 100644 --- a/module_usb_audio/ports/audioports.xc +++ b/module_usb_audio/ports/audioports.xc @@ -10,7 +10,7 @@ extern clock clk_audio_bclk; void ConfigAudioPorts( #if (I2S_CHANS_DAC != 0) || (DSD_CHANS_DAC != 0) - buffered out port:32 p_i2s_dac[], + buffered out port:32 p_i2s_dac[], int numPortsDac, #endif @@ -28,12 +28,12 @@ void ConfigAudioPorts( in port p_bclk, #endif #endif -unsigned int divide) +unsigned int divide) { #ifndef CODEC_MASTER /* Note this call to stop_clock() will pause forever if the port clocking the clock-block is not low. - * deliver() should return with this being the case - however, if you are having trouble the code + * deliver() should return with this being the case - however, if you are having trouble the code * above can be enabled */ stop_clock(clk_audio_bclk); @@ -104,7 +104,7 @@ unsigned int divide) /* Stop bit and master clock blocks */ stop_clock(clk_audio_bclk); - + /* Clock bclk clock-block from bclk pin */ configure_clock_src(clk_audio_bclk, p_bclk); diff --git a/module_usb_audio/powersave/archU_powerSaving.h b/module_usb_audio/powersave/archU_powerSaving.h index b1ea5b08..e37371a2 100644 --- a/module_usb_audio/powersave/archU_powerSaving.h +++ b/module_usb_audio/powersave/archU_powerSaving.h @@ -1,7 +1,7 @@ #ifndef ARCH_U_POWER_SAVING_ #define ARCH_U_POWER_SAVING_ -/* Sets the voltage down by VOLTAGE_REDUCTION_mV (voltage is set to 10 * X + 600 mV), +/* Sets the voltage down by VOLTAGE_REDUCTION_mV (voltage is set to 10 * X + 600 mV), * and adjusts other features to save power */ void archU_powerSaving(); diff --git a/module_usb_audio/powersave/archU_powerSaving.xc b/module_usb_audio/powersave/archU_powerSaving.xc index 4f42f66c..03535cde 100644 --- a/module_usb_audio/powersave/archU_powerSaving.xc +++ b/module_usb_audio/powersave/archU_powerSaving.xc @@ -36,10 +36,10 @@ void archU_powerSaving() time += (1 * PLATFORM_REFERENCE_MHZ); // Wait 1us per step t when timerafter(time) :> void; } - + // Set switch prescaler down write_node_config_reg(tile[0], XS1_SSWITCH_CLK_DIVIDER_NUM, (ARCH_U_SSWITCH_PRESCALER - 1)); // PLL clk will be divided by value + 1 - + // Both DC-DCs in PWM mode, I/O and PLL supply on, Analogue & core on writeval[0] = XS1_SU_PWR_VOUT1_EN_SET(0, 1); writeval[0] = XS1_SU_PWR_VOUT2_EN_SET(writeval[0], 1); @@ -57,7 +57,7 @@ void archU_powerSaving() writevalc[0] = XS1_SU_ON_SI_OSC_EN_SET(0, 1); writevalc[0] = XS1_SU_ON_SI_OSC_SLOW_SET(writevalc[0], 1); write_periph_8(usb_tile, XS1_SU_PER_OSC_CHANEND_NUM, XS1_SU_PER_OSC_ON_SI_CTRL_NUM, 1, writevalc); - } + } } #endif diff --git a/module_usb_audio/reboot.xc b/module_usb_audio/reboot.xc index ace0b64a..5444b0ec 100644 --- a/module_usb_audio/reboot.xc +++ b/module_usb_audio/reboot.xc @@ -10,7 +10,7 @@ unsigned get_tile_id(tileref); extern tileref tile[]; -void device_reboot_aux(void) +void device_reboot_aux(void) { #if (XUD_SERIES_SUPPORT == 1) /* Disconnect from bus */ @@ -25,15 +25,15 @@ void device_reboot_aux(void) unsigned int localTileId = get_local_tile_id(); unsigned int tileId; unsigned int tileArrayLength; - + /* Find size of tile array - note in future tools versions this will be available from platform.h */ asm volatile ("ldc %0, tile.globound":"=r"(tileArrayLength)); - + /* Reset all remote tiles */ - for(int i = 0; i< tileArrayLength; i++) + for(int i = 0; i< tileArrayLength; i++) { /* Cannot cast tileref to unsigned! */ - tileId = get_tile_id(tile[i]); + tileId = get_tile_id(tile[i]); /* Do not reboot local tile yet! */ if(localTileId != tileId) @@ -42,7 +42,7 @@ void device_reboot_aux(void) write_sswitch_reg_no_ack(tileId, 6, pllVal); } } - + /* Finally reboot this tile! */ read_sswitch_reg(localTileId, 6, pllVal); write_sswitch_reg_no_ack(localTileId, 6, pllVal); @@ -50,12 +50,12 @@ void device_reboot_aux(void) } /* Reboots XMOS device by writing to the PLL config register */ -void device_reboot_implementation(chanend spare) +void device_reboot_implementation(chanend spare) { #if (XUD_SERIES_SUPPORT != 1) outct(spare, XS1_CT_END); // have to do this before freeing the chanend inct(spare); // Receive end ct from usb_buffer to close down in both directions - + /* Need a spare chanend so we can talk to the pll register */ asm("freer res[%0]"::"r"(spare)); #endif diff --git a/module_usb_audio/usb_buffer/decouple.h b/module_usb_audio/usb_buffer/decouple.h index 931bf25e..31e1dca7 100644 --- a/module_usb_audio/usb_buffer/decouple.h +++ b/module_usb_audio/usb_buffer/decouple.h @@ -2,9 +2,9 @@ #define __DECOUPLE_H__ -/** Manage the data transfer between the USB audio buffer and the +/** Manage the data transfer between the USB audio buffer and the * Audio I/O driver. - * + * * \param c_audio_out Channel connected to the audio() or mixer() threads * \param c_clk_int Optional chanend connected to the clockGen() thread if present */ diff --git a/module_usb_audio/usb_buffer/decouple.xc b/module_usb_audio/usb_buffer/decouple.xc index 4c6fad57..409cb137 100644 --- a/module_usb_audio/usb_buffer/decouple.xc +++ b/module_usb_audio/usb_buffer/decouple.xc @@ -22,7 +22,7 @@ #define OUT_BUFFER_PREFILL (MAX(NUM_USB_CHAN_OUT_A1*CLASS_ONE_PACKET_SIZE*3+4,NUM_USB_CHAN_OUT*CLASS_TWO_PACKET_SIZE*4+4)*1) #define IN_BUFFER_PREFILL (MAX(CLASS_ONE_PACKET_SIZE*3+4,CLASS_TWO_PACKET_SIZE*4+4)*2) -/* Volume and mute tables */ +/* Volume and mute tables */ #ifndef OUT_VOLUME_IN_MIXER unsigned int multOut[NUM_USB_CHAN_OUT + 1]; static xc_ptr p_multOut; @@ -70,14 +70,14 @@ int speedRem = 0; xc_ptr aud_from_host_fifo_start; xc_ptr aud_from_host_fifo_end; xc_ptr g_aud_from_host_wrptr; -xc_ptr g_aud_from_host_rdptr; +xc_ptr g_aud_from_host_rdptr; xc_ptr aud_to_host_fifo_start; xc_ptr aud_to_host_fifo_end; xc_ptr g_aud_to_host_wrptr; xc_ptr g_aud_to_host_dptr; -xc_ptr g_aud_to_host_rdptr; -xc_ptr g_aud_to_host_zeros; +xc_ptr g_aud_to_host_rdptr; +xc_ptr g_aud_to_host_zeros; int sampsToWrite = 0; int totalSampsToWrite = 0; int aud_data_remaining_to_device = 0; @@ -134,16 +134,16 @@ void handle_audio_request(chanend c_mix_out) g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_CLASS_ONE; } #endif - + /* If in overflow condition then receive samples and throw away */ if(inOverflow || sampsToWrite == 0) { #pragma loop unroll - for(int i = 0; i < NUM_USB_CHAN_IN; i++) + for(int i = 0; i < NUM_USB_CHAN_IN; i++) { (void) inuint(c_mix_out); } - + /* Calculate how much space left in buffer */ space_left = g_aud_to_host_rdptr - g_aud_to_host_wrptr; @@ -153,7 +153,7 @@ void handle_audio_request(chanend c_mix_out) } /* Check if we can come out of overflow */ - if (space_left > (BUFF_SIZE_IN*4/2)) + if (space_left > (BUFF_SIZE_IN*4/2)) { inOverflow = 0; } @@ -171,7 +171,7 @@ __builtin_unreachable(); #endif unsigned ptr = g_aud_to_host_dptr; - for(int i = 0; i < g_numUsbChanIn; i++) + for(int i = 0; i < g_numUsbChanIn; i++) { /* Receive sample */ int sample = inuint(c_mix_out); @@ -188,20 +188,20 @@ __builtin_unreachable(); sample = sample << 3; #endif /* Write into fifo */ - write_via_xc_ptr(ptr, sample); + write_via_xc_ptr(ptr, sample); ptr+=4; } - + /* Update global pointer */ g_aud_to_host_dptr = ptr; break; } - + case 3: #if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3) __builtin_unreachable(); #endif - for(int i = 0; i < g_numUsbChanIn; i++) + for(int i = 0; i < g_numUsbChanIn; i++) { /* Receive sample */ int sample = inuint(c_mix_out); @@ -215,28 +215,28 @@ __builtin_unreachable(); sample = h << 3; #endif /* Pack 3 byte samples */ - switch (packState&0x3) - { - case 0: + switch (packState&0x3) + { + case 0: packData = sample; break; case 1: packData = (packData >> 8) | ((sample & 0xff00)<<16); - write_via_xc_ptr(g_aud_to_host_dptr, packData); + write_via_xc_ptr(g_aud_to_host_dptr, packData); g_aud_to_host_dptr+=4; - write_via_xc_ptr(g_aud_to_host_dptr, sample>>16); + write_via_xc_ptr(g_aud_to_host_dptr, sample>>16); packData = sample; break; case 2: packData = (packData>>16) | ((sample & 0xffff00) << 8); - write_via_xc_ptr(g_aud_to_host_dptr, packData); + write_via_xc_ptr(g_aud_to_host_dptr, packData); g_aud_to_host_dptr+=4; packData = sample; break; case 3: packData = (packData >> 24) | (sample & 0xffffff00); - write_via_xc_ptr(g_aud_to_host_dptr, packData); - g_aud_to_host_dptr+=4; + write_via_xc_ptr(g_aud_to_host_dptr, packData); + g_aud_to_host_dptr+=4; break; } packState++; @@ -248,7 +248,7 @@ __builtin_unreachable(); #if (SAMPLE_SUBSLOT_SIZE_HS != 2) && (SAMPLE_SUBSLOT_SIZE_FS != 2) __builtin_unreachable(); #endif - for(int i = 0; i < g_numUsbChanIn; i++) + for(int i = 0; i < g_numUsbChanIn; i++) { /* Receive sample */ int sample = inuint(c_mix_out); @@ -270,12 +270,12 @@ __builtin_unreachable(); switch (packState&0x1) { case 0: - packData = sample; + packData = sample; break; - case 1: + case 1: packData = (packData>>16) | (sample & 0xffff0000); - write_via_xc_ptr(g_aud_to_host_dptr, packData); - g_aud_to_host_dptr+=4; + write_via_xc_ptr(g_aud_to_host_dptr, packData); + g_aud_to_host_dptr+=4; break; } } @@ -283,24 +283,24 @@ __builtin_unreachable(); default: __builtin_unreachable(); - break; + break; } - + /* Input any remaining channels - past this thread we always operate on max channel count */ for(int i = 0; i < NUM_USB_CHAN_IN - g_numUsbChanIn; i++) { inuint(c_mix_out); } - sampsToWrite--; + sampsToWrite--; } if(outUnderflow) - { + { #pragma xta endpoint "out_underflow" #if 0 /* We're still pre-buffering, send out 0 samps */ - for(int i = 0; i < NUM_USB_CHAN_OUT; i++) + for(int i = 0; i < NUM_USB_CHAN_OUT; i++) { unsigned sample; unsigned mode; @@ -320,9 +320,9 @@ __builtin_unreachable(); { outSamps += BUFF_SIZE_OUT*4; } - + /* If we have a decent number of samples, come out of underflow cond */ - if(outSamps >= (OUT_BUFFER_PREFILL)) + if(outSamps >= (OUT_BUFFER_PREFILL)) { outUnderflow = 0; outSamps++; @@ -335,19 +335,19 @@ __builtin_unreachable(); case 4: #if (SAMPLE_SUBSLOT_SIZE_HS != 4) && (SAMPLE_SUBSLOT_SIZE_FS != 4) __builtin_unreachable(); -#endif +#endif /* Buffering not underflow condition send out some samples...*/ - for(int i = 0; i < g_numUsbChanOut; i++) + for(int i = 0; i < g_numUsbChanOut; i++) { #pragma xta endpoint "mixer_request" int sample; int mult; int h; unsigned l; - + read_via_xc_ptr(sample, g_aud_from_host_rdptr); g_aud_from_host_rdptr+=4; - + #ifndef OUT_VOLUME_IN_MIXER asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i)); {h, l} = macs(mult, sample, 0, 0); @@ -363,13 +363,13 @@ __builtin_unreachable(); } break; - + case 3: #if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3) __builtin_unreachable(); -#endif +#endif /* Buffering not underflow condition send out some samples...*/ - for(int i = 0; i < g_numUsbChanOut; i++) + for(int i = 0; i < g_numUsbChanOut; i++) { #pragma xta endpoint "mixer_request" int sample; @@ -378,12 +378,12 @@ __builtin_unreachable(); unsigned l; /* Unpack 3 byte samples */ - switch (unpackState&0x3) + switch (unpackState&0x3) { case 0: read_via_xc_ptr(unpackData, g_aud_from_host_rdptr); g_aud_from_host_rdptr+=4; - sample = unpackData << 8; + sample = unpackData << 8; break; case 1: sample = (unpackData >> 16); @@ -393,7 +393,7 @@ __builtin_unreachable(); break; case 2: sample = (unpackData >> 8); - read_via_xc_ptr(unpackData, g_aud_from_host_rdptr); + read_via_xc_ptr(unpackData, g_aud_from_host_rdptr); g_aud_from_host_rdptr+=4; sample = sample | (unpackData<< 24); break; @@ -402,7 +402,7 @@ __builtin_unreachable(); break; } unpackState++; - + #ifndef OUT_VOLUME_IN_MIXER asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i)); {h, l} = macs(mult, sample, 0, 0); @@ -418,25 +418,25 @@ __builtin_unreachable(); case 2: #if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3) __builtin_unreachable(); -#endif +#endif /* Buffering not underflow condition send out some samples...*/ - for(int i = 0; i < g_numUsbChanOut; i++) + for(int i = 0; i < g_numUsbChanOut; i++) { #pragma xta endpoint "mixer_request" int sample; int mult; int h; unsigned l; - + switch (unpackState&0x1) { case 0: read_via_xc_ptr(unpackData, g_aud_from_host_rdptr); - sample = unpackData << 16; + sample = unpackData << 16; break; - case 1: + case 1: g_aud_from_host_rdptr+=4; - sample = unpackData & 0xffff0000; + sample = unpackData & 0xffff0000; break; } unpackState++; @@ -451,7 +451,7 @@ __builtin_unreachable(); #endif } break; - + default: __builtin_unreachable(); break; @@ -463,18 +463,18 @@ __builtin_unreachable(); { outuint(c_mix_out, 0); } - - /* 3/4 bytes per sample */ + + /* 3/4 bytes per sample */ aud_data_remaining_to_device -= (g_numUsbChanOut*g_slotSize); } - - if (!inOverflow) + + if (!inOverflow) { - if (sampsToWrite == 0) + if (sampsToWrite == 0) { int speed; - if (totalSampsToWrite) + if (totalSampsToWrite) { unsigned datasize = totalSampsToWrite * g_slotSize * g_numUsbChanIn; @@ -482,7 +482,7 @@ __builtin_unreachable(); datasize = (datasize+3) & (~0x3); g_aud_to_host_wrptr += 4+datasize; - + if (g_aud_to_host_wrptr >= aud_to_host_fifo_end) { g_aud_to_host_wrptr = aud_to_host_fifo_start; @@ -491,66 +491,66 @@ __builtin_unreachable(); /* Get feedback val - ideally this would be syncronised */ asm("ldw %0, dp[g_speed]" : "=r" (speed) :); - - /* Calc packet size to send back based on our fb */ + + /* Calc packet size to send back based on our fb */ speedRem += speed; totalSampsToWrite = speedRem >> 16; speedRem &= 0xffff; #if 0 - if (usb_speed == XUD_SPEED_HS) + if (usb_speed == XUD_SPEED_HS) { - if (totalSampsToWrite < 0 || totalSampsToWrite*4*g_numUsbChanIn > (MAX_DEVICE_AUD_PACKET_SIZE_CLASS_TWO)) + if (totalSampsToWrite < 0 || totalSampsToWrite*4*g_numUsbChanIn > (MAX_DEVICE_AUD_PACKET_SIZE_CLASS_TWO)) { totalSampsToWrite = 0; } } - else + else { - if (totalSampsToWrite < 0 || totalSampsToWrite*3*NUM_USB_CHAN_IN_A1 > (MAX_DEVICE_AUD_PACKET_SIZE_CLASS_ONE)) + if (totalSampsToWrite < 0 || totalSampsToWrite*3*NUM_USB_CHAN_IN_A1 > (MAX_DEVICE_AUD_PACKET_SIZE_CLASS_ONE)) { totalSampsToWrite = 0; } } #else - if (totalSampsToWrite < 0 || totalSampsToWrite * g_slotSize * g_numUsbChanIn > g_maxPacketSize) + if (totalSampsToWrite < 0 || totalSampsToWrite * g_slotSize * g_numUsbChanIn > g_maxPacketSize) { totalSampsToWrite = 0; } #endif - /* Calc slots left in fifo */ - space_left = g_aud_to_host_rdptr - g_aud_to_host_wrptr; - + /* Calc slots left in fifo */ + space_left = g_aud_to_host_rdptr - g_aud_to_host_wrptr; + /* Mod and special case */ if (space_left <= 0 && g_aud_to_host_rdptr == aud_to_host_fifo_start) { space_left = aud_to_host_fifo_end - g_aud_to_host_wrptr; } - if ((space_left <= 0) || (space_left > totalSampsToWrite*g_numUsbChanIn * 4 + 4)) - { + if ((space_left <= 0) || (space_left > totalSampsToWrite*g_numUsbChanIn * 4 + 4)) + { /* Packet okay, write to fifo */ - if (totalSampsToWrite) + if (totalSampsToWrite) { write_via_xc_ptr(g_aud_to_host_wrptr, totalSampsToWrite*g_slotSize*g_numUsbChanIn); packState = 0; g_aud_to_host_dptr = g_aud_to_host_wrptr + 4; } } - else + else { inOverflow = 1; totalSampsToWrite = 0; } - sampsToWrite = totalSampsToWrite; + sampsToWrite = totalSampsToWrite; } } - - if (!outUnderflow && (aud_data_remaining_to_device<(g_slotSize*g_numUsbChanOut))) + + if (!outUnderflow && (aud_data_remaining_to_device<(g_slotSize*g_numUsbChanOut))) { /* Handle any tail - incase a bad driver sent us a datalength not a multiple of chan count */ - if (aud_data_remaining_to_device) + if (aud_data_remaining_to_device) { /* Round up to nearest word */ aud_data_remaining_to_device +=3 - (unpackState&0x3); @@ -569,14 +569,14 @@ __builtin_unreachable(); } outUnderflow = (g_aud_from_host_rdptr == g_aud_from_host_wrptr); - - - if (!outUnderflow) - { + + + if (!outUnderflow) + { read_via_xc_ptr(aud_data_remaining_to_device, g_aud_from_host_rdptr); - + unpackState = 0; - + g_aud_from_host_rdptr+=4; } } @@ -610,7 +610,7 @@ static void check_for_interrupt(chanend ?c_clk_int) { //XUD_SetReady(int_usb_ep, 0); //asm("ldaw %0, dp[g_intData]":"=r"(x)); - //XUD_SetReady_In(int_usb_ep, g_intData, 6); + //XUD_SetReady_In(int_usb_ep, g_intData, 6); } break; @@ -619,24 +619,24 @@ static void check_for_interrupt(chanend ?c_clk_int) { } } -unsigned char tmpBuffer[1026]; +unsigned char tmpBuffer[1026]; #pragma unsafe arrays void decouple(chanend c_mix_out, chanend ?c_clk_int #ifdef CHAN_BUFF_CTRL , chanend c_buf_ctrl -#endif +#endif ) -{ +{ unsigned sampFreq = DEFAULT_FREQ; -#ifdef OUTPUT +#ifdef OUTPUT int aud_from_host_flag=0; xc_ptr released_buffer; #endif #ifdef INPUT int aud_to_host_flag = 0; -#endif +#endif int t = array_to_xc_ptr(outAudioBuff); int aud_in_ready = 0; @@ -651,18 +651,18 @@ void decouple(chanend c_mix_out, aud_from_host_fifo_start = t; aud_from_host_fifo_end = aud_from_host_fifo_start + BUFF_SIZE_OUT*4; g_aud_from_host_wrptr = aud_from_host_fifo_start; - g_aud_from_host_rdptr = aud_from_host_fifo_start; + g_aud_from_host_rdptr = aud_from_host_fifo_start; t = array_to_xc_ptr(audioBuffIn); aud_to_host_fifo_start = t; aud_to_host_fifo_end = aud_to_host_fifo_start + BUFF_SIZE_IN*4; g_aud_to_host_wrptr = aud_to_host_fifo_start; - g_aud_to_host_rdptr = aud_to_host_fifo_start; + g_aud_to_host_rdptr = aud_to_host_fifo_start; t = array_to_xc_ptr(inZeroBuff); g_aud_to_host_zeros = t; - + /* Init interrupt report */ g_intData[0] = 0; // Class-specific, caused by interface g_intData[1] = 1; // attribute: CUR @@ -678,7 +678,7 @@ void decouple(chanend c_mix_out, asm("stw %0, %1[%2]"::"r"(MAX_VOL),"r"(p_multOut),"r"(i)); } #endif - + #ifndef IN_VOLUME_IN_MIXER for (int i = 0; i < NUM_USB_CHAN_IN + 1; i++) { @@ -698,11 +698,11 @@ void decouple(chanend c_mix_out, #ifdef OUTPUT // wait for usb_buffer to set up - while(!aud_from_host_flag) + while(!aud_from_host_flag) { GET_SHARED_GLOBAL(aud_from_host_flag, g_aud_from_host_flag); } - + aud_from_host_flag = 0; SET_SHARED_GLOBAL(g_aud_from_host_flag, aud_from_host_flag); @@ -713,11 +713,11 @@ void decouple(chanend c_mix_out, #ifdef INPUT // Wait for usb_buffer to set up - while(!aud_to_host_flag) + while(!aud_to_host_flag) { GET_SHARED_GLOBAL(aud_to_host_flag, g_aud_to_host_flag); } - + aud_to_host_flag = 0; SET_SHARED_GLOBAL(g_aud_to_host_flag, aud_to_host_flag); @@ -729,9 +729,9 @@ void decouple(chanend c_mix_out, GET_SHARED_GLOBAL(p, g_aud_to_host_buffer); read_via_xc_ptr(len, p) - XUD_SetReady_InPtr(aud_to_host_usb_ep, g_aud_to_host_buffer, len); - aud_in_ready = 1; - + XUD_SetReady_InPtr(aud_to_host_usb_ep, g_aud_to_host_buffer, len); + aud_in_ready = 1; + } #endif @@ -762,24 +762,24 @@ void decouple(chanend c_mix_out, } #endif - if (!isnull(c_clk_int)) + if (!isnull(c_clk_int)) { check_for_interrupt(c_clk_int); } - + { asm("#decouple-default"); /* Check for freq change or other update */ GET_SHARED_GLOBAL(tmp, g_freqChange_flag); - if (tmp == SET_SAMPLE_FREQ) + if (tmp == SET_SAMPLE_FREQ) { SET_SHARED_GLOBAL(g_freqChange_flag, 0); GET_SHARED_GLOBAL(sampFreq, g_freqChange_sampFreq); /* Pass on to mixer */ - DISABLE_INTERRUPTS(); + DISABLE_INTERRUPTS(); inuint(c_mix_out); outct(c_mix_out, SET_SAMPLE_FREQ); outuint(c_mix_out, sampFreq); @@ -792,7 +792,7 @@ void decouple(chanend c_mix_out, aud_to_host_fifo_start); SET_SHARED_GLOBAL(sampsToWrite, 0); SET_SHARED_GLOBAL(totalSampsToWrite, 0); - + /* Set buffer to send back to zeros buffer */ SET_SHARED_GLOBAL(g_aud_to_host_buffer,g_aud_to_host_zeros); @@ -801,7 +801,7 @@ void decouple(chanend c_mix_out, int min, mid, max, usb_speed; GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed); GetADCCounts(sampFreq, min, mid, max); - if (usb_speed == XUD_SPEED_HS) + if (usb_speed == XUD_SPEED_HS) mid*=NUM_USB_CHAN_IN*4; else mid*=NUM_USB_CHAN_IN_A1*3; @@ -815,23 +815,23 @@ void decouple(chanend c_mix_out, { xc_ptr p; int len; - + GET_SHARED_GLOBAL(p, g_aud_to_host_buffer); - read_via_xc_ptr(len, p); - + read_via_xc_ptr(len, p); + /* Update packet size */ XUD_SetReady_InPtr(aud_to_host_usb_ep, p+4, len); } - /* Reset OUT buffer state */ + /* Reset OUT buffer state */ outUnderflow = 1; - SET_SHARED_GLOBAL(g_aud_from_host_rdptr, aud_from_host_fifo_start); + SET_SHARED_GLOBAL(g_aud_from_host_rdptr, aud_from_host_fifo_start); SET_SHARED_GLOBAL(g_aud_from_host_wrptr, aud_from_host_fifo_start); SET_SHARED_GLOBAL(aud_data_remaining_to_device, 0); if(outOverflow) { - /* If we were previously in overflow we wont have marked as ready */ + /* If we were previously in overflow we wont have marked as ready */ XUD_SetReady_OutPtr(aud_from_host_usb_ep, aud_from_host_fifo_start+4); outOverflow = 0; } @@ -842,7 +842,7 @@ void decouple(chanend c_mix_out, SET_SHARED_GLOBAL(g_freqChange, 0); asm("outct res[%0],%1"::"r"(buffer_aud_ctl_chan),"r"(XS1_CT_END)); - + ENABLE_INTERRUPTS(); speedRem = 0; @@ -851,11 +851,11 @@ void decouple(chanend c_mix_out, else if(tmp == SET_CHAN_COUNT_IN) { /* Change in IN channel count */ - DISABLE_INTERRUPTS(); + DISABLE_INTERRUPTS(); SET_SHARED_GLOBAL(g_freqChange_flag, 0); GET_SHARED_GLOBAL(g_numUsbChanIn, g_freqChange_sampFreq); /* Misuse of g_freqChange_sampFreq */ - - /* Reset IN buffer state */ + + /* Reset IN buffer state */ inOverflow = 0; inUnderflow = 1; SET_SHARED_GLOBAL(g_aud_to_host_rdptr, aud_to_host_fifo_start); @@ -863,29 +863,29 @@ void decouple(chanend c_mix_out, SET_SHARED_GLOBAL(sampsToWrite, 0); SET_SHARED_GLOBAL(totalSampsToWrite, 0); SET_SHARED_GLOBAL(g_aud_to_host_buffer, g_aud_to_host_zeros); - + SET_SHARED_GLOBAL(g_freqChange, 0); ENABLE_INTERRUPTS(); } else if(tmp == SET_CHAN_COUNT_OUT) { /* Change in OUT channel count */ - DISABLE_INTERRUPTS(); + DISABLE_INTERRUPTS(); SET_SHARED_GLOBAL(g_freqChange_flag, 0); GET_SHARED_GLOBAL(g_numUsbChanOut, g_freqChange_sampFreq); /* Misuse of g_freqChange_sampFreq */ - - /* Reset OUT buffer state */ + + /* Reset OUT buffer state */ SET_SHARED_GLOBAL(g_aud_from_host_rdptr, aud_from_host_fifo_start); SET_SHARED_GLOBAL(g_aud_from_host_wrptr, aud_from_host_fifo_start); - + outUnderflow = 1; if(outOverflow) { - /* If we were previously in overflow we wont have marked as ready */ + /* If we were previously in overflow we wont have marked as ready */ XUD_SetReady_OutPtr(aud_from_host_usb_ep, aud_from_host_fifo_start+4); outOverflow = 0; } - + SET_SHARED_GLOBAL(g_freqChange, 0); ENABLE_INTERRUPTS(); } @@ -893,34 +893,34 @@ void decouple(chanend c_mix_out, else if(tmp == SET_DSD_MODE) { unsigned dsdMode; - DISABLE_INTERRUPTS(); + DISABLE_INTERRUPTS(); /* Clear the buffer as we dont want to send out old PCM samples.. */ SET_SHARED_GLOBAL(g_freqChange_flag, 0); GET_SHARED_GLOBAL(dsdMode, g_freqChange_sampFreq); /* Misuse of g_freqChange_sampFreq */ - - /* Reset OUT buffer state */ + + /* Reset OUT buffer state */ SET_SHARED_GLOBAL(g_aud_from_host_rdptr, aud_from_host_fifo_start); SET_SHARED_GLOBAL(g_aud_from_host_wrptr, aud_from_host_fifo_start); - + outUnderflow = 1; if(outOverflow) { - /* If we were previously in overflow we wont have marked as ready */ + /* If we were previously in overflow we wont have marked as ready */ XUD_SetReady_OutPtr(aud_from_host_usb_ep, aud_from_host_fifo_start+4); outOverflow = 0; } - + inuint(c_mix_out); outct(c_mix_out, SET_DSD_MODE); - outuint(c_mix_out, dsdMode); - - /* Wait for handshake back */ + outuint(c_mix_out, dsdMode); + + /* Wait for handshake back */ chkct(c_mix_out, XS1_CT_END); SET_SHARED_GLOBAL(g_freqChange, 0); asm("outct res[%0],%1"::"r"(buffer_aud_ctl_chan),"r"(XS1_CT_END)); - + ENABLE_INTERRUPTS(); } #endif @@ -938,17 +938,17 @@ void decouple(chanend c_mix_out, int aud_from_host_rdptr; GET_SHARED_GLOBAL(aud_from_host_wrptr, g_aud_from_host_wrptr); GET_SHARED_GLOBAL(aud_from_host_rdptr, g_aud_from_host_rdptr); - + SET_SHARED_GLOBAL(g_aud_from_host_flag, 0); GET_SHARED_GLOBAL(released_buffer, g_aud_from_host_buffer); - + /* Read datalength from buffer */ read_via_xc_ptr(datalength, released_buffer); - /* Ignore bad small packets */ + /* Ignore bad small packets */ if ((datalength >= (g_numUsbChanOut * g_slotSize)) && (released_buffer == aud_from_host_wrptr)) { - + /* Move the write pointer of the fifo on - round up to nearest word */ aud_from_host_wrptr = aud_from_host_wrptr + ((datalength+3)&~0x3) + 4; @@ -959,36 +959,36 @@ void decouple(chanend c_mix_out, } SET_SHARED_GLOBAL(g_aud_from_host_wrptr, aud_from_host_wrptr); } - - /* if we have enough space left then send a new buffer pointer + + /* if we have enough space left then send a new buffer pointer * back to the buffer thread */ space_left = aud_from_host_rdptr - aud_from_host_wrptr; - + /* Mod and special case */ if(space_left <= 0 && g_aud_from_host_rdptr == aud_from_host_fifo_start) { space_left = aud_from_host_fifo_end - g_aud_from_host_wrptr; } - - if (space_left <= 0 || space_left >= MAX_USB_AUD_PACKET_SIZE) - { + + if (space_left <= 0 || space_left >= MAX_USB_AUD_PACKET_SIZE) + { SET_SHARED_GLOBAL(g_aud_from_host_buffer, aud_from_host_wrptr); XUD_SetReady_OutPtr(aud_from_host_usb_ep, aud_from_host_wrptr+4); } - else - { - /* Enter OUT over flow state */ - outOverflow = 1; + else + { + /* Enter OUT over flow state */ + outOverflow = 1; - -#ifdef DEBUG_LEDS + +#ifdef DEBUG_LEDS led(c_led); #endif - } + } continue; } - else if (outOverflow) + else if (outOverflow) { int space_left; int aud_from_host_wrptr; @@ -996,9 +996,9 @@ void decouple(chanend c_mix_out, GET_SHARED_GLOBAL(aud_from_host_wrptr, g_aud_from_host_wrptr); GET_SHARED_GLOBAL(aud_from_host_rdptr, g_aud_from_host_rdptr); space_left = aud_from_host_rdptr - aud_from_host_wrptr; - if (space_left <= 0) + if (space_left <= 0) space_left += BUFF_SIZE_OUT*4; - if (space_left >= (BUFF_SIZE_OUT*4/2)) + if (space_left >= (BUFF_SIZE_OUT*4/2)) { /* Come out of OUT overflow state */ outOverflow = 0; @@ -1012,19 +1012,19 @@ void decouple(chanend c_mix_out, #endif #ifdef INPUT - { + { /* Check if buffer() has sent a packet to host - uses shared mem flag to save chanends */ int tmp; GET_SHARED_GLOBAL(tmp, g_aud_to_host_flag); //case inuint_byref(c_buf_in, tmp): - if (tmp) + if (tmp) { - /* Signals that the IN endpoint has sent data from the passed buffer */ + /* Signals that the IN endpoint has sent data from the passed buffer */ /* Reset flag */ - SET_SHARED_GLOBAL(g_aud_to_host_flag, 0); + SET_SHARED_GLOBAL(g_aud_to_host_flag, 0); aud_in_ready = 0; - - if (inUnderflow) + + if (inUnderflow) { int aud_to_host_wrptr; int aud_to_host_rdptr; @@ -1038,18 +1038,18 @@ void decouple(chanend c_mix_out, if (fill_level < 0) fill_level += BUFF_SIZE_IN*4; - if (fill_level >= IN_BUFFER_PREFILL) - { + if (fill_level >= IN_BUFFER_PREFILL) + { inUnderflow = 0; SET_SHARED_GLOBAL(g_aud_to_host_buffer, aud_to_host_rdptr); } - else + else { - SET_SHARED_GLOBAL(g_aud_to_host_buffer, g_aud_to_host_zeros); + SET_SHARED_GLOBAL(g_aud_to_host_buffer, g_aud_to_host_zeros); } - } - else + } + else { /* Not in IN underflow state */ int datalength; @@ -1068,7 +1068,7 @@ void decouple(chanend c_mix_out, SET_SHARED_GLOBAL(g_aud_to_host_rdptr, aud_to_host_rdptr); /* Check for read pointer hitting write pointer - underflow */ - if (aud_to_host_rdptr != aud_to_host_wrptr) + if (aud_to_host_rdptr != aud_to_host_wrptr) { SET_SHARED_GLOBAL(g_aud_to_host_buffer, aud_to_host_rdptr); } @@ -1076,13 +1076,13 @@ void decouple(chanend c_mix_out, { inUnderflow = 1; SET_SHARED_GLOBAL(g_aud_to_host_buffer, g_aud_to_host_zeros); - + } - } - - /* Request to send packet */ + } + + /* Request to send packet */ { - int p, len; + int p, len; GET_SHARED_GLOBAL(p, g_aud_to_host_buffer); asm("ldw %0, %1[0]":"=r"(len):"r"(p)); XUD_SetReady_InPtr(aud_to_host_usb_ep, p+4, len); diff --git a/module_usb_audio/usb_buffer/get_adc_counts.c b/module_usb_audio/usb_buffer/get_adc_counts.c index e5a9c6ed..9b8e5856 100644 --- a/module_usb_audio/usb_buffer/get_adc_counts.c +++ b/module_usb_audio/usb_buffer/get_adc_counts.c @@ -1,9 +1,9 @@ extern unsigned int g_curUsbSpeed; #define XUD_SPEED_HS 2 -/* Returns the max and min packet sizes to send back to host for a given sample frequency - * See page 13 of USB Audio Device Class Definitions for Audio Data Formats Spec (v2.0) - * +/* Returns the max and min packet sizes to send back to host for a given sample frequency + * See page 13 of USB Audio Device Class Definitions for Audio Data Formats Spec (v2.0) + * * Audio samples per frame = INT(sampFreq/frametime); Variation allowed is + 1; * * For HS frame time = 8 * 1000 @@ -16,7 +16,7 @@ extern unsigned int g_curUsbSpeed; * * Note: Assumes HS (i.e. 8 frames per 1ms) * - * Examples: + * Examples: * 44100: min: 5 max: 6 * 48000: min: 5 max: 7 * 96000: min: 11 max: 13 @@ -30,9 +30,9 @@ void GetADCCounts(unsigned samFreq, int *min, int *mid, int *max) unsigned frameTime; int usb_speed; usb_speed = g_curUsbSpeed; - if (usb_speed == XUD_SPEED_HS) + if (usb_speed == XUD_SPEED_HS) frameTime = 8000; - else + else frameTime = 1000; *min = samFreq / frameTime; @@ -40,7 +40,7 @@ void GetADCCounts(unsigned samFreq, int *min, int *mid, int *max) *mid = *min; - /* Check for INT(SampFreq/8000) == SampFreq/8000 */ + /* Check for INT(SampFreq/8000) == SampFreq/8000 */ if((samFreq % frameTime) == 0) { *min -= 1; diff --git a/module_usb_audio/usb_buffer/interrupt.h b/module_usb_audio/usb_buffer/interrupt.h index d27d1ea1..d52ee1b7 100644 --- a/module_usb_audio/usb_buffer/interrupt.h +++ b/module_usb_audio/usb_buffer/interrupt.h @@ -2,23 +2,23 @@ #define __interrupt_h__ #define store_args0(c) \ - asm("kentsp 19; stw %0, sp[1]; krestsp 19"::"r"(c)); + asm("kentsp 19; stw %0, sp[1]; krestsp 19"::"r"(c)); #define store_args1(c,x) \ - asm("kentsp 20; stw %0, sp[1]; stw %1, sp[2]; krestsp 20"::"r"(c),"r"(x)); + asm("kentsp 20; stw %0, sp[1]; stw %1, sp[2]; krestsp 20"::"r"(c),"r"(x)); #define store_args2(c,x0,x1) \ asm("kentsp 21; stw %0, sp[1];" \ "stw %1, sp[2];" \ "stw %2, sp[3];" \ - " krestsp 21"::"r"(c),"r"(x0),"r"(x1)); + " krestsp 21"::"r"(c),"r"(x0),"r"(x1)); #define store_args3(c,x0,x1,x2) \ asm("kentsp 22; stw %0, sp[1];" \ "stw %1, sp[2];" \ "stw %2, sp[3];" \ "stw %3, sp[4];" \ - " krestsp 22"::"r"(c),"r"(x0),"r"(x1),"r"(x2)); + " krestsp 22"::"r"(c),"r"(x0),"r"(x1),"r"(x2)); #define store_args4(c,x0,x1,x2,x3) \ asm("kentsp 23; stw %4, sp[1];" \ @@ -26,7 +26,7 @@ "stw %1, sp[3];" \ "stw %2, sp[4];" \ "stw %3, sp[5];" \ - " krestsp 23"::"r"(c),"r"(x0),"r"(x1),"r"(x2),"r"(x3)); + " krestsp 23"::"r"(c),"r"(x0),"r"(x1),"r"(x2),"r"(x3)); #define store_args5(c,x0,x1,x2,x3,x4) \ asm("kentsp 24;" \ @@ -36,7 +36,7 @@ "stw %1, sp[4];" \ "stw %2, sp[5];" \ "stw %3, sp[6];" \ - " krestsp 24"::"r"(c),"r"(x0),"r"(x1),"r"(x2),"r"(x3),"r"(x4)); + " krestsp 24"::"r"(c),"r"(x0),"r"(x1),"r"(x2),"r"(x3),"r"(x4)); #define store_args6(c,x0,x1,x2,x3,x4,x5) \ asm("kentsp 25;" \ @@ -47,7 +47,7 @@ "stw %1, sp[5];" \ "stw %2, sp[6];" \ "stw %3, sp[7];" \ - " krestsp 25"::"r"(c),"r"(x0),"r"(x1),"r"(x2),"r"(x3),"r"(x4),"r"(x5)); + " krestsp 25"::"r"(c),"r"(x0),"r"(x1),"r"(x2),"r"(x3),"r"(x4),"r"(x5)); #define store_args7(c,x0,x1,x2,x3,x4,x5,x6) \ asm("kentsp 26;" \ @@ -59,7 +59,7 @@ "stw %1, sp[6];" \ "stw %2, sp[7];" \ "stw %3, sp[8];" \ - " krestsp 26"::"r"(c),"r"(x0),"r"(x1),"r"(x2),"r"(x3),"r"(x4),"r"(x5),"r"(x6)); + " krestsp 26"::"r"(c),"r"(x0),"r"(x1),"r"(x2),"r"(x3),"r"(x4),"r"(x5),"r"(x6)); #define store_args8(c,x0,x1,x2,x3,x4,x5,x6,x7) \ asm("kentsp 27;" \ @@ -72,28 +72,28 @@ "stw %1, sp[7];" \ "stw %2, sp[8];" \ "stw %3, sp[9];" \ - " krestsp 27"::"r"(c),"r"(x0),"r"(x1),"r"(x2),"r"(x3),"r"(x4),"r"(x5),"r"(x6),"r"(x7)); + " krestsp 27"::"r"(c),"r"(x0),"r"(x1),"r"(x2),"r"(x3),"r"(x4),"r"(x5),"r"(x6),"r"(x7)); #define load_args0(f) \ - "ldw r0, sp[1]\n" + "ldw r0, sp[1]\n" #define load_args1(f)\ "ldw r0, sp[1]\n" \ - "ldw r1, sp[2]\n" + "ldw r1, sp[2]\n" #define load_args2(f)\ "ldw r0, sp[1]\n" \ "ldw r1, sp[2]\n" \ - "ldw r2, sp[3]\n" + "ldw r2, sp[3]\n" #define load_args3(f)\ "ldw r0, sp[1]\n" \ "ldw r1, sp[2]\n" \ "ldw r2, sp[3]\n" \ - "ldw r3, sp[4]\n" + "ldw r3, sp[4]\n" #define load_argsn(f, args) \ ".linkset __"#f"_handler_arg0, "#args"-2\n"\ @@ -103,13 +103,13 @@ ".linkset __"#f"_handler_arg2, "#args"-0\n"\ "ldw r2, sp[" "__"#f"_handler_arg2" "]\n" \ ".linkset __"#f"_handler_arg3, "#args"+1\n"\ - "ldw r3, sp[" "__"#f"_handler_arg3" "]\n" + "ldw r3, sp[" "__"#f"_handler_arg3" "]\n" -#define load_args4(f) load_argsn(f,4) -#define load_args5(f) load_argsn(f,5) -#define load_args6(f) load_argsn(f,6) -#define load_args7(f) load_argsn(f,7) -#define load_args8(f) load_argsn(f,8) +#define load_args4(f) load_argsn(f,4) +#define load_args5(f) load_argsn(f,5) +#define load_args6(f) load_argsn(f,6) +#define load_args7(f) load_argsn(f,7) +#define load_args8(f) load_argsn(f,8) #define save_state(f,args) \ ".linkset __"#f"_handler_r0_save, "#args"+12\n" \ @@ -123,7 +123,7 @@ ".linkset __"#f"_handler_r11_save, "#args"+11\n" \ "stw r11, sp[" "__"#f"_handler_r11_save" "]\n" \ ".linkset __"#f"_handler_lr_save, "#args"+14\n" \ - "stw lr, sp[" "__"#f"_handler_lr_save" "]\n" + "stw lr, sp[" "__"#f"_handler_lr_save" "]\n" #define restore_state(f,args) \ "ldw r0, sp[" "__"#f"_handler_r0_save" "]\n" \ @@ -131,7 +131,7 @@ "ldw r2, sp[" "__"#f"_handler_r2_save" "]\n" \ "ldw r3, sp[" "__"#f"_handler_r3_save" "]\n" \ "ldw r11, sp[" "__"#f"_handler_r11_save" "]\n" \ - "ldw lr, sp[" "__"#f"_handler_lr_save" "]\n" + "ldw lr, sp[" "__"#f"_handler_lr_save" "]\n" #define STRINGIFY0(x) #x diff --git a/module_usb_audio/usb_buffer/testct_byref.h b/module_usb_audio/usb_buffer/testct_byref.h index 72897aee..7f8f87ec 100644 --- a/module_usb_audio/usb_buffer/testct_byref.h +++ b/module_usb_audio/usb_buffer/testct_byref.h @@ -5,11 +5,11 @@ #pragma select handler static inline void testct_byref(chanend c, unsigned &isCt) { - if (testct(c)) + if (testct(c)) { isCt = 1; } - else + else { isCt = 0; } diff --git a/module_usb_audio/usb_buffer/testct_byref.xc b/module_usb_audio/usb_buffer/testct_byref.xc index f2991ae8..b4239980 100644 --- a/module_usb_audio/usb_buffer/testct_byref.xc +++ b/module_usb_audio/usb_buffer/testct_byref.xc @@ -2,13 +2,13 @@ /* TODO Currently complier does not support inline select functions, hense this is in a seperate file to ensure this is not the case */ #pragma select handler -void testct_byrefnot(chanend c, unsigned &isCt) +void testct_byrefnot(chanend c, unsigned &isCt) { - if (testct(c)) + if (testct(c)) { isCt = 1; } - else + else { isCt = 0; } diff --git a/module_usb_audio/usb_buffer/usb_buffer.h b/module_usb_audio/usb_buffer/usb_buffer.h index c8576c9d..daed7365 100644 --- a/module_usb_audio/usb_buffer/usb_buffer.h +++ b/module_usb_audio/usb_buffer/usb_buffer.h @@ -16,24 +16,24 @@ * \param c_aud_ctl Audio control channel connected to Endpoint0() * \param p_off_mclk A port that is clocked of the MCLK input (not the MCLK input itself) */ -void buffer(chanend c_aud_out, - chanend c_aud_in, +void buffer(chanend c_aud_out, + chanend c_aud_in, chanend c_aud_fb, -#ifdef MIDI - chanend c_midi_from_host, +#ifdef MIDI + chanend c_midi_from_host, chanend c_midi_to_host, chanend c_midi, #endif #ifdef IAP - chanend c_iap_from_host, + chanend c_iap_from_host, chanend c_iap_to_host, chanend c_iap_to_host_int, chanend c_iap, #endif #if defined(SPDIF_RX) || defined(ADAT_RX) - chanend? c_int, + chanend? c_int, #endif - chanend c_sof, + chanend c_sof, chanend c_aud_ctl, in port p_off_mclk #ifdef HID_CONTROLS diff --git a/module_usb_audio/usb_buffer/usb_buffer.xc b/module_usb_audio/usb_buffer/usb_buffer.xc index d468d1cf..09fb1bf6 100644 --- a/module_usb_audio/usb_buffer/usb_buffer.xc +++ b/module_usb_audio/usb_buffer/usb_buffer.xc @@ -43,7 +43,7 @@ unsigned g_freqChange = 0; unsigned char g_intData[8]; #if defined (MIDI) || defined(IAP) -static inline void swap(xc_ptr &a, xc_ptr &b) +static inline void swap(xc_ptr &a, xc_ptr &b) { xc_ptr tmp; tmp = a; @@ -70,29 +70,29 @@ unsigned char fb_clocks[16]; #define FB_TOLERANCE 0x100 extern unsigned inZeroBuff[]; -/** - * Buffers data from audio endpoints +/** + * Buffers data from audio endpoints * @param c_aud_out chanend for audio from xud * @param c_aud_in chanend for audio to xud * @param c_aud_fb chanend for feeback to xud * @return void */ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud_fb, -#ifdef MIDI - chanend c_midi_from_host, +#ifdef MIDI + chanend c_midi_from_host, chanend c_midi_to_host, - chanend c_midi, + chanend c_midi, #endif #ifdef IAP - chanend c_iap_from_host, - chanend c_iap_to_host, + chanend c_iap_from_host, + chanend c_iap_to_host, chanend c_iap_to_host_int, - chanend c_iap, + chanend c_iap, #endif #if defined(SPDIF_RX) || defined(ADAT_RX) - chanend ?c_int, + chanend ?c_int, #endif - chanend c_sof, + chanend c_sof, chanend c_aud_ctl, in port p_off_mclk #ifdef HID_CONTROLS @@ -122,8 +122,8 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud #ifdef HID_CONTROLS XUD_ep ep_hid = XUD_InitEp(c_hid); #endif - - + + int tmp; unsigned u_tmp; unsigned sampleFreq = 0; @@ -133,7 +133,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud #ifdef INPUT unsigned bufferIn = 1; -#endif +#endif unsigned remnant = 0, cycles; unsigned sofCount = 0; unsigned freqChange = 0; @@ -162,8 +162,8 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud xc_ptr iap_from_host_rdptr; unsigned char iap_from_host_buffer[MAX_IAP_PACKET_SIZE+4]; unsigned char iap_to_host_buffer[MAX_IAP_PACKET_SIZE+4]; - - + + int is_ack_iap; int is_reset; unsigned int datum_iap; @@ -174,20 +174,20 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud xc_ptr p_inZeroBuff = array_to_xc_ptr(inZeroBuff); - + #ifdef IAP XUD_ResetEndpoint(ep_iap_from_host, null); - iap_send_reset(c_iap); + iap_send_reset(c_iap); #endif #if defined(SPDIF_RX) || defined(ADAT_RX) - asm("stw %0, dp[int_usb_ep]"::"r"(ep_int)); + asm("stw %0, dp[int_usb_ep]"::"r"(ep_int)); #endif asm("stw %0, dp[aud_from_host_usb_ep]"::"r"(ep_aud_out)); asm("stw %0, dp[aud_to_host_usb_ep]"::"r"(ep_aud_in)); - asm("stw %0, dp[buffer_aud_ctl_chan]"::"r"(c_aud_ctl)); + asm("stw %0, dp[buffer_aud_ctl_chan]"::"r"(c_aud_ctl)); - /* Wait for USB connect then setup our first packet */ + /* Wait for USB connect then setup our first packet */ { int min, mid, max; int usb_speed = 0; @@ -200,7 +200,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud GetADCCounts(DEFAULT_FREQ, min, mid, max); asm("stw %0, dp[g_speed]"::"r"(mid << 16)); - if (usb_speed == XUD_SPEED_HS) + if (usb_speed == XUD_SPEED_HS) mid*=NUM_USB_CHAN_IN*4; else mid*=NUM_USB_CHAN_IN_A1*3; @@ -210,15 +210,15 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud #ifdef FB_TOLERANCE_TEST expected_fb = ((DEFAULT_FREQ * 0x2000) / 1000); #endif - + } #ifdef OUTPUT - SET_SHARED_GLOBAL(g_aud_from_host_flag, 1); + SET_SHARED_GLOBAL(g_aud_from_host_flag, 1); #endif #ifdef INPUT - SET_SHARED_GLOBAL(g_aud_to_host_flag, 1); + SET_SHARED_GLOBAL(g_aud_to_host_flag, 1); #endif (fb_clocks, unsigned[])[0] = 0; @@ -226,15 +226,15 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud { int usb_speed; int x; - + asm("ldaw %0, dp[fb_clocks]":"=r"(x)); GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed); - - if (usb_speed == XUD_SPEED_HS) - { + + if (usb_speed == XUD_SPEED_HS) + { XUD_SetReady_In(ep_aud_fb, fb_clocks, 4); } - else + else { XUD_SetReady_In(ep_aud_fb, fb_clocks, 3); } @@ -260,54 +260,54 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud #if defined(SPDIF_RX) || defined(ADAT_RX) /* Interrupt EP, send back interrupt data. Note, request made from decouple */ case inuint_byref(c_int, tmp): - { + { int sent_ok = 0; XUD_SetData_Inline(ep_int, c_int); - asm("stw %0, dp[g_intFlag]" :: "r" (0) ); + asm("stw %0, dp[g_intFlag]" :: "r" (0) ); break; } #endif - /* Sample Freq or chan count update from ep 0 */ + /* Sample Freq or chan count update from ep 0 */ case testct_byref(c_aud_ctl, u_tmp): { - if (u_tmp) + if (u_tmp) { // is a control token sent by reboot_device inct(c_aud_ctl); outct(c_aud_ctl, XS1_CT_END); while(1) {}; - } - else + } + else { int min, mid, max; int usb_speed; int frameTime; tmp = inuint(c_aud_ctl); GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed); - + if(tmp == SET_SAMPLE_FREQ) - { + { sampleFreq = inuint(c_aud_ctl); - + /* Don't update things for DFU command.. */ if(sampleFreq != AUDIO_STOP_FOR_DFU) { - - /* Tidy up double buffer, note we can do better than this for 44.1 etc but better - * than sending two packets at old speed! */ - if (usb_speed == XUD_SPEED_HS) + + /* Tidy up double buffer, note we can do better than this for 44.1 etc but better + * than sending two packets at old speed! */ + if (usb_speed == XUD_SPEED_HS) frameTime = 8000; - else + else frameTime = 1000; - + min = sampleFreq / frameTime; - + max = min + 1; - + mid = min; - - /* Check for INT(SampFreq/8000) == SampFreq/8000 */ + + /* Check for INT(SampFreq/8000) == SampFreq/8000 */ if((sampleFreq % frameTime) == 0) { min -= 1; @@ -315,26 +315,26 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud #ifdef FB_TOLERANCE_TEST expected_fb = ((sampleFreq * 0x2000) / frameTime); #endif - + asm("stw %0, dp[g_speed]"::"r"(mid << 16)); - - if (usb_speed == XUD_SPEED_HS) + + if (usb_speed == XUD_SPEED_HS) mid *= NUM_USB_CHAN_IN*4; - else + else mid *= NUM_USB_CHAN_IN_A1*3; - + asm("stw %0, %1[0]"::"r"(mid),"r"(p_inZeroBuff)); - + /* Reset FB */ - /* Note, Endpoint 0 will hold off host for a sufficient period to allow out feedback - * to stabilise (i.e. sofCount == 128 to fire) */ + /* Note, Endpoint 0 will hold off host for a sufficient period to allow out feedback + * to stabilise (i.e. sofCount == 128 to fire) */ sofCount = 0; clocks = 0; remnant = 0; - - } + + } /* Ideally we want to wait for handshake (and pass back up) here. But we cannot keep this - * thread locked, it must stay responsive to packets/SOFs. So, set a flag and check for + * thread locked, it must stay responsive to packets/SOFs. So, set a flag and check for * handshake elsewhere */ /* Pass on sample freq change to decouple */ SET_SHARED_GLOBAL0(g_freqChange, SET_SAMPLE_FREQ); @@ -343,8 +343,8 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud } else { - sampleFreq = inuint(c_aud_ctl); - + sampleFreq = inuint(c_aud_ctl); + SET_SHARED_GLOBAL0(g_freqChange, tmp); /* Set command */ SET_SHARED_GLOBAL(g_freqChange_sampFreq, sampleFreq); /* Set flag */ SET_SHARED_GLOBAL(g_freqChange_flag, tmp); @@ -358,14 +358,14 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud /* (previously used 63 instead of 127) */ case inuint_byref(c_sof, u_tmp): - - /* NOTE our feedback will be wrong for a couple of SOF's after a SF change due to - * lastClock being incorrect */ + + /* NOTE our feedback will be wrong for a couple of SOF's after a SF change due to + * lastClock being incorrect */ asm("#sof"); - + /* Get MCLK count */ - asm (" getts %0, res[%1]" : "=r" (u_tmp) : "r" (p_off_mclk)); - + asm (" getts %0, res[%1]" : "=r" (u_tmp) : "r" (p_off_mclk)); + GET_SHARED_GLOBAL(freqChange, g_freqChange); if(freqChange == SET_SAMPLE_FREQ) { @@ -377,34 +377,34 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud unsigned mask = MASK_16_13, usb_speed; GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed); - + if(usb_speed != XUD_SPEED_HS) mask = MASK_16_10; - + /* Number of MCLKS this SOF, approx 125 * 24 (3000), sample by sample rate */ GET_SHARED_GLOBAL(cycles, g_curSamFreqMultiplier); cycles = ((int)((short)(u_tmp - lastClock))) * cycles; - + /* Any odd bits (lower than 16.23) have to be kept seperate */ - remnant += cycles & mask; - - /* Add 16.13 bits into clock count */ - clocks += (cycles & ~mask) + (remnant & ~mask); + remnant += cycles & mask; + + /* Add 16.13 bits into clock count */ + clocks += (cycles & ~mask) + (remnant & ~mask); /* and overflow from odd bits. Remove overflow from odd bits. */ - remnant &= mask; - - /* Store MCLK for next time around... */ - lastClock = u_tmp; + remnant &= mask; - /* Reset counts based on SOF counting. Expect 16ms (128 HS SOFs/16 FS SOFS) per feedback poll - * We always count 128 SOFs, so 16ms @ HS, 128ms @ FS */ - if(sofCount == 128) + /* Store MCLK for next time around... */ + lastClock = u_tmp; + + /* Reset counts based on SOF counting. Expect 16ms (128 HS SOFs/16 FS SOFS) per feedback poll + * We always count 128 SOFs, so 16ms @ HS, 128ms @ FS */ + if(sofCount == 128) { sofCount = 0; #ifdef FB_TOLERANCE_TEST if (clocks > (expected_fb - FB_TOLERANCE) && - clocks < (expected_fb + FB_TOLERANCE)) + clocks < (expected_fb + FB_TOLERANCE)) #endif { int usb_speed; @@ -412,24 +412,24 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud //fb_clocks = clocks; GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed); - - if (usb_speed == XUD_SPEED_HS) - { + + if (usb_speed == XUD_SPEED_HS) + { (fb_clocks, unsigned[])[0] = clocks; } - else + else { (fb_clocks, unsigned[])[0] = clocks>>2; } } #ifdef FB_TOLERANCE_TEST - else + else { } #endif clocks = 0; } - + sofCount++; } break; @@ -441,12 +441,12 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud case XUD_SetData_Select(c_aud_in, ep_aud_in, tmp): { /* Inform stream that buffer sent */ - SET_SHARED_GLOBAL0(g_aud_to_host_flag, bufferIn+1); + SET_SHARED_GLOBAL0(g_aud_to_host_flag, bufferIn+1); } break; #endif - -#ifdef OUTPUT + +#ifdef OUTPUT /* Feedback Pipe */ case XUD_SetData_Select(c_aud_fb, ep_aud_fb, tmp): { @@ -455,33 +455,33 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud int x; asm("#aud fb"); - + asm("ldaw %0, dp[fb_clocks]":"=r"(x)); GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed); - - if (usb_speed == XUD_SPEED_HS) - { + + if (usb_speed == XUD_SPEED_HS) + { XUD_SetReady_In(ep_aud_fb, fb_clocks, 4); } - else + else { XUD_SetReady_In(ep_aud_fb, fb_clocks, 3); } } break; - + /* Audio HOST -> DEVICE */ case XUD_GetData_Select(c_aud_out, ep_aud_out, tmp): { asm("#h->d aud data"); GET_SHARED_GLOBAL(aud_from_host_buffer, g_aud_from_host_buffer); - + write_via_xc_ptr(aud_from_host_buffer, tmp); - + /* Sync with decouple thread */ SET_SHARED_GLOBAL0(g_aud_from_host_flag, 1); - } + } break; #endif @@ -491,40 +491,40 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud /* Get buffer data from host - MIDI OUT from host always into a single buffer */ /* Write datalength (tmp) into buffer[0], data stored in buffer[4] onwards */ - midi_data_remaining_to_device = tmp; - + midi_data_remaining_to_device = tmp; + midi_from_host_rdptr = midi_from_host_buffer; - - if (midi_data_remaining_to_device) + + if (midi_data_remaining_to_device) { read_via_xc_ptr(datum, midi_from_host_rdptr); outuint(c_midi, datum); - midi_from_host_rdptr += 4; + midi_from_host_rdptr += 4; midi_data_remaining_to_device -= 4; - } + } break; - - /* MIDI IN to host */ - case XUD_SetData_Select(c_midi_to_host, ep_midi_to_host, tmp): + + /* MIDI IN to host */ + case XUD_SetData_Select(c_midi_to_host, ep_midi_to_host, tmp): asm("#midi d->h"); /* The buffer has been sent to the host, so we can ack the midi thread */ - if (midi_data_collected_from_device != 0) + if (midi_data_collected_from_device != 0) { /* Swap the collecting and sending buffer */ swap(midi_to_host_buffer_being_collected, midi_to_host_buffer_being_sent); - + /* Request to send packet */ XUD_SetReady_InPtr(ep_midi_to_host, midi_to_host_buffer_being_sent, midi_data_collected_from_device); /* Mark as waiting for host to poll us */ - midi_waiting_on_send_to_host = 1; + midi_waiting_on_send_to_host = 1; /* Reset the collected data count */ midi_data_collected_from_device = 0; } else { - midi_waiting_on_send_to_host = 0; + midi_waiting_on_send_to_host = 0; } break; #endif @@ -534,7 +534,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud case XUD_GetData_Select(c_iap_from_host, ep_iap_from_host, tmp): asm("#iap h->d"); if(tmp >= 0) - { + { iap_data_remaining_to_device = tmp; if(iap_data_remaining_to_device) @@ -546,7 +546,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud /* Send out first byte in buffer */ datum_iap = iap_from_host_buffer[0]; outuint(c_iap, datum_iap); - + /* Set read ptr to next byte in buffer */ iap_from_host_rdptr = 1; iap_data_remaining_to_device -= 1; @@ -559,16 +559,16 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud iap_data_collected_from_device = 0; } break; - - /* IAP IN to host */ - case XUD_SetData_Select(c_iap_to_host, ep_iap_to_host, tmp): + + /* IAP IN to host */ + case XUD_SetData_Select(c_iap_to_host, ep_iap_to_host, tmp): asm("#iap d->h"); - + /* Send out an iAP packet to host, ACK last msg from iAP to let it know we can move on..*/ iap_send_ack(c_iap); - break; /* IAP IN to host */ - - case XUD_SetData_Select(c_iap_to_host_int, ep_iap_to_host_int, tmp): + break; /* IAP IN to host */ + + case XUD_SetData_Select(c_iap_to_host_int, ep_iap_to_host_int, tmp): asm("#iap int d->h"); /* Do nothing.. */ break; @@ -586,27 +586,27 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud #endif #ifdef MIDI - /* Received word from MIDI thread - Check for ACK or Data */ + /* Received word from MIDI thread - Check for ACK or Data */ case midi_get_ack_or_data(c_midi, is_ack, datum): - if (is_ack) + if (is_ack) { /* An ack from the midi/uart thread means it has accepted some data we sent it * we are okay to send another word */ - if (midi_data_remaining_to_device <= 0) + if (midi_data_remaining_to_device <= 0) { /* We have read an entire packet - Mark ready to receive another */ - XUD_SetReady_OutPtr(ep_midi_from_host, midi_from_host_buffer); + XUD_SetReady_OutPtr(ep_midi_from_host, midi_from_host_buffer); } - else + else { /* Read another word from the fifo and output it to MIDI thread */ read_via_xc_ptr(datum, midi_from_host_rdptr); - outuint(c_midi, datum); - midi_from_host_rdptr += 4; + outuint(c_midi, datum); + midi_from_host_rdptr += 4; midi_data_remaining_to_device -= 4; - } + } } - else + else { /* The midi/uart thread has sent us some data - handshake back */ midi_send_ack(c_midi); @@ -618,22 +618,22 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud write_via_xc_ptr(p, datum); midi_data_collected_from_device += 4; } - else + else { - // Too many events from device - drop - } - + // Too many events from device - drop + } + // If we are not sending data to the host then initiate it - if (!midi_waiting_on_send_to_host) + if (!midi_waiting_on_send_to_host) { swap(midi_to_host_buffer_being_collected, midi_to_host_buffer_being_sent); - + // Signal other side to swap XUD_SetReady_InPtr(ep_midi_to_host, midi_to_host_buffer_being_sent, midi_data_collected_from_device); midi_data_collected_from_device = 0; - midi_waiting_on_send_to_host = 1; + midi_waiting_on_send_to_host = 1; } - } + } break; #endif /* ifdef MIDI */ @@ -641,16 +641,16 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud /* Received word from iap thread - Check for ACK or Data */ case iap_get_ack_or_reset_or_data(c_iap, is_ack_iap, is_reset, datum_iap): - if (is_ack_iap) + if (is_ack_iap) { /* An ack from the iap/uart thread means it has accepted some data we sent it * we are okay to send another word */ - if (iap_data_remaining_to_device == 0) + if (iap_data_remaining_to_device == 0) { /* We have read an entire packet - Mark ready to receive another */ XUD_SetReady_Out(ep_iap_from_host, iap_from_host_buffer); } - else + else { /* Read another byte from the fifo and output it to iap thread */ datum_iap = iap_from_host_buffer[iap_from_host_rdptr]; @@ -661,13 +661,13 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud } else { - if (iap_expected_data_length == 0) + if (iap_expected_data_length == 0) { /* Expect a length from iAP core */ iap_send_ack(c_iap); iap_expected_data_length = datum_iap; - } - else + } + else { if (iap_data_collected_from_device < IAP_USB_BUFFER_TO_HOST_SIZE) { @@ -675,14 +675,14 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud iap_to_host_buffer[iap_data_collected_from_device] = datum_iap; iap_data_collected_from_device += 1; } - else + else { - // Too many events from device - drop - } + // Too many events from device - drop + } /* Once we have the whole message, sent it to host */ /* Note we don't ack the last byte yet... */ - if (iap_data_collected_from_device == iap_expected_data_length) + if (iap_data_collected_from_device == iap_expected_data_length) { XUD_SetReady_In(ep_iap_to_host_int, gc_zero_buffer, 0); XUD_SetReady_In(ep_iap_to_host, iap_to_host_buffer, iap_data_collected_from_device); diff --git a/module_usb_audio/usb_buffer/xc_ptr.h b/module_usb_audio/usb_buffer/xc_ptr.h index eeda3c9c..bb54372b 100644 --- a/module_usb_audio/usb_buffer/xc_ptr.h +++ b/module_usb_audio/usb_buffer/xc_ptr.h @@ -31,4 +31,4 @@ inline xc_ptr array_to_xc_ptr(const unsigned a[]) #define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory") #define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory") -#endif +#endif diff --git a/module_usb_audio/user_hid.h b/module_usb_audio/user_hid.h index fbb0b346..e834aa04 100644 --- a/module_usb_audio/user_hid.h +++ b/module_usb_audio/user_hid.h @@ -1,3 +1,3 @@ -void UserReadHIDButtons(unsigned char hidData[]); +void UserReadHIDButtons(unsigned char hidData[]); diff --git a/module_usb_audio/xuduser/xuduser.c b/module_usb_audio/xuduser/xuduser.c index 6a44bdcc..5df5f90e 100644 --- a/module_usb_audio/xuduser/xuduser.c +++ b/module_usb_audio/xuduser/xuduser.c @@ -16,7 +16,7 @@ void XUD_UserResume(void) unsigned config; asm("ldw %0, dp[g_currentConfig]" : "=r" (config):); - + if(config == 1) { UserHostActive(1); diff --git a/module_usb_audio_adat/src/adatreceiver.h b/module_usb_audio_adat/src/adatreceiver.h index 55936aae..451f9df9 100644 --- a/module_usb_audio_adat/src/adatreceiver.h +++ b/module_usb_audio_adat/src/adatreceiver.h @@ -8,7 +8,7 @@ * signal. Normally the 48000 function is called in a while(1) loop. If * both 44,100 and 48,000 need to be supported, they should be called in * sequence in a while(1) loop. Note that the functions are large, and - * that 44,100 should not be called if it does not need to be supported. + * that 44,100 should not be called if it does not need to be supported. **/ void adatReceiver48000(buffered in port:32 p, chanend oChan); @@ -21,7 +21,7 @@ void adatReceiver48000(buffered in port:32 p, chanend oChan); * signal. Normally the 48000 function is called in a while(1) loop. If * both 44,100 and 48,000 need to be supported, they should be called in * sequence in a while(1) loop. Note that the functions are large, and - * that 44,100 should not be called if it does not need to be supported. + * that 44,100 should not be called if it does not need to be supported. **/ void adatReceiver44100(buffered in port:32 p, chanend oChan); diff --git a/module_usb_audio_adat/src/adatreceiver.xc b/module_usb_audio_adat/src/adatreceiver.xc index 6c372f83..a2d19ff9 100644 --- a/module_usb_audio_adat/src/adatreceiver.xc +++ b/module_usb_audio_adat/src/adatreceiver.xc @@ -1,947 +1,947 @@ -// GENERATED CODE - DO NOT EDIT -// Comments are in the generator -#include -#include -#pragma unsafe arrays -void adatReceiver48000(buffered in port:32 p, chanend oChan) { - const unsigned int mask = 0x80808080; - unsigned compressed; - unsigned nibble, word = 1, fourBits, data; - int old, violation; - unsigned int lookupCrcF[16] = {8, 9, 12, 13, 7, 6, 3, 2, 10, 11, 14, 15, 5, 4, 1, 0}; - unsigned int lookupNRTZ[32] = {0, 8, 12, 4, 6, 14, 10, 2, 3, 11, 15, 7, 5, 13, 9, 1, - 1, 9, 13, 5, 7, 15, 11, 3, 2, 10, 14, 6, 4, 12, 8, 0}; - for(int i = 0; i < 32; i++) { lookupNRTZ[i] <<= 4; } - do { - old = word; p :> word; - } while (word != old || (word != 0 && word+1 != 0)); - while(1) { - violation = word; - p when pinsneq(violation) :> int _; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - outuint(oChan, nibble << 4 | 1); - p :> word; - fourBits = (word << 3) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = nibble << 4; - p :> word; - fourBits = (word << 3) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 2) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 1) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 1) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 0) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 0) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - outuint(oChan, data); - p :> word; - fourBits = (word << 7) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - old = old | compressed << 1; - p :> word; - fourBits = (word << 7) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = nibble << 4; - p :> word; - fourBits = (word << 6) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 6) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 5) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 5) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - outuint(oChan, data); - p :> word; - fourBits = (word << 3) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = nibble << 4; - p :> word; - fourBits = (word << 2) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 2) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 1) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 1) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 0) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 0) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = (data | nibble) << 4; - outuint(oChan, data); - p :> word; - fourBits = (word << 7) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - old = compressed; - p :> word; - fourBits = (word << 7) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = nibble << 4; - p :> word; - fourBits = (word << 6) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 6) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 5) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 3) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - outuint(oChan, data); - p :> word; - fourBits = (word << 3) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = nibble << 4; - p :> word; - fourBits = (word << 2) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 2) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 1) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 1) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 0) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 0) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 7) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - outuint(oChan, data); - p :> word; - fourBits = (word << 7) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = nibble << 4; - p :> word; - fourBits = (word << 6) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 5) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 5) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 3) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = (data | nibble) << 4; - outuint(oChan, data); - p :> word; - fourBits = (word << 3) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 2) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = nibble << 4; - p :> word; - fourBits = (word << 2) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 1) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 0) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 0) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 7) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 7) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - outuint(oChan, data); - p :> word; - fourBits = (word << 6) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = nibble << 4; - p :> word; - fourBits = (word << 6) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 5) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 5) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 3) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 3) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - outuint(oChan, data); - p :> word; - if (word != 0 && word+1 != 0) return; - } -} - -// GENERATED CODE - DO NOT EDIT -// Comments are in the generator -#include -#include -#pragma unsafe arrays -void adatReceiver44100(buffered in port:32 p, chanend oChan) { - const unsigned int mask = 0x80402010; - unsigned compressed; - unsigned nibble, word = 1, fourBits, data; - int old, violation; - unsigned int lookupCrcF[16] = {8, 12, 10, 14, 9, 13, 11, 15, 7, 3, 5, 1, 6, 2, 4, 0}; - unsigned int lookupNRTZ[32] = {0, 8, 12, 4, 6, 14, 10, 2, 3, 11, 15, 7, 5, 13, 9, 1, - 1, 9, 13, 5, 7, 15, 11, 3, 2, 10, 14, 6, 4, 12, 8, 0}; - for(int i = 0; i < 32; i++) { lookupNRTZ[i] <<= 4; } - do { - old = word; p :> word; - } while (word != old || (word != 0 && word+1 != 0)); - while(1) { - violation = word; - p when pinsneq(violation) :> int _; - p :> word; - fourBits = (word << 2) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 6) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - outuint(oChan, nibble << 4 | 1); - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = nibble << 4; - p :> word; - fourBits = (word << 0) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 5) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - old = compressed; - p :> word; - fourBits = (word << 2) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 7) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 1) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 5) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - outuint(oChan, data); - p :> word; - fourBits = (word << 3) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = nibble << 4; - p :> word; - fourBits = (word << 7) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - old = compressed; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 1) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 6) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - old = old | compressed << 1; - p :> word; - fourBits = (word << 3) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 0) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 5) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - outuint(oChan, data); - p :> word; - fourBits = (word << 2) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 7) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = nibble << 4; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 1) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 5) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - old = compressed; - p :> word; - fourBits = (word << 3) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 7) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 1) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - outuint(oChan, data); - p :> word; - fourBits = (word << 6) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = nibble << 4; - p :> word; - fourBits = (word << 3) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 0) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 2) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 6) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - old = old | compressed << 1; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 0) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - outuint(oChan, data); - p :> word; - fourBits = (word << 5) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = nibble << 4; - p :> word; - fourBits = (word << 2) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 7) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 1) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 5) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - old = compressed; - p :> word; - fourBits = (word << 3) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 7) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - outuint(oChan, data); - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 1) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = nibble << 4; - p :> word; - fourBits = (word << 6) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 3) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 0) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 2) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 6) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - old = old | compressed << 1; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - outuint(oChan, data); - p :> word; - fourBits = (word << 1) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = nibble << 4; - p :> word; - fourBits = (word << 5) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 3) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 7) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 1) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 6) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - old = compressed; - p :> word; - fourBits = (word << 3) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - outuint(oChan, data); - p :> word; - fourBits = (word << 0) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = nibble << 4; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - old = old | compressed << 1; - p :> word; - fourBits = (word << 2) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 6) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; - old = compressed >> 2; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 4) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; - old = compressed >> 4; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 0) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - old = compressed; - p :> word; - fourBits = (word << 5) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - compressed = compressed >> 1; - nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; - old = compressed >> 1; - data = (data | nibble) << 4; - p :> word; - fourBits = (word << 2) & mask; - crc32(fourBits, 0xf, 0xf); - compressed = lookupCrcF[fourBits]; - nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; - old = compressed >> 3; - data = (data | nibble) << 4; - outuint(oChan, data); - p :> word; - if (word != 0 && word+1 != 0) return; - } -} - +// GENERATED CODE - DO NOT EDIT +// Comments are in the generator +#include +#include +#pragma unsafe arrays +void adatReceiver48000(buffered in port:32 p, chanend oChan) { + const unsigned int mask = 0x80808080; + unsigned compressed; + unsigned nibble, word = 1, fourBits, data; + int old, violation; + unsigned int lookupCrcF[16] = {8, 9, 12, 13, 7, 6, 3, 2, 10, 11, 14, 15, 5, 4, 1, 0}; + unsigned int lookupNRTZ[32] = {0, 8, 12, 4, 6, 14, 10, 2, 3, 11, 15, 7, 5, 13, 9, 1, + 1, 9, 13, 5, 7, 15, 11, 3, 2, 10, 14, 6, 4, 12, 8, 0}; + for(int i = 0; i < 32; i++) { lookupNRTZ[i] <<= 4; } + do { + old = word; p :> word; + } while (word != old || (word != 0 && word+1 != 0)); + while(1) { + violation = word; + p when pinsneq(violation) :> int _; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + outuint(oChan, nibble << 4 | 1); + p :> word; + fourBits = (word << 3) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = nibble << 4; + p :> word; + fourBits = (word << 3) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 2) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 1) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 1) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 0) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 0) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + outuint(oChan, data); + p :> word; + fourBits = (word << 7) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + old = old | compressed << 1; + p :> word; + fourBits = (word << 7) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = nibble << 4; + p :> word; + fourBits = (word << 6) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 6) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 5) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 5) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + outuint(oChan, data); + p :> word; + fourBits = (word << 3) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = nibble << 4; + p :> word; + fourBits = (word << 2) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 2) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 1) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 1) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 0) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 0) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = (data | nibble) << 4; + outuint(oChan, data); + p :> word; + fourBits = (word << 7) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + old = compressed; + p :> word; + fourBits = (word << 7) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = nibble << 4; + p :> word; + fourBits = (word << 6) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 6) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 5) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 3) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + outuint(oChan, data); + p :> word; + fourBits = (word << 3) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = nibble << 4; + p :> word; + fourBits = (word << 2) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 2) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 1) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 1) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 0) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 0) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 7) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + outuint(oChan, data); + p :> word; + fourBits = (word << 7) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = nibble << 4; + p :> word; + fourBits = (word << 6) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 5) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 5) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 3) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = (data | nibble) << 4; + outuint(oChan, data); + p :> word; + fourBits = (word << 3) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 2) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = nibble << 4; + p :> word; + fourBits = (word << 2) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 1) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 0) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 0) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 7) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 7) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + outuint(oChan, data); + p :> word; + fourBits = (word << 6) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = nibble << 4; + p :> word; + fourBits = (word << 6) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 5) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 5) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 3) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 3) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + outuint(oChan, data); + p :> word; + if (word != 0 && word+1 != 0) return; + } +} + +// GENERATED CODE - DO NOT EDIT +// Comments are in the generator +#include +#include +#pragma unsafe arrays +void adatReceiver44100(buffered in port:32 p, chanend oChan) { + const unsigned int mask = 0x80402010; + unsigned compressed; + unsigned nibble, word = 1, fourBits, data; + int old, violation; + unsigned int lookupCrcF[16] = {8, 12, 10, 14, 9, 13, 11, 15, 7, 3, 5, 1, 6, 2, 4, 0}; + unsigned int lookupNRTZ[32] = {0, 8, 12, 4, 6, 14, 10, 2, 3, 11, 15, 7, 5, 13, 9, 1, + 1, 9, 13, 5, 7, 15, 11, 3, 2, 10, 14, 6, 4, 12, 8, 0}; + for(int i = 0; i < 32; i++) { lookupNRTZ[i] <<= 4; } + do { + old = word; p :> word; + } while (word != old || (word != 0 && word+1 != 0)); + while(1) { + violation = word; + p when pinsneq(violation) :> int _; + p :> word; + fourBits = (word << 2) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 6) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + outuint(oChan, nibble << 4 | 1); + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = nibble << 4; + p :> word; + fourBits = (word << 0) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 5) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + old = compressed; + p :> word; + fourBits = (word << 2) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 7) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 1) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 5) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + outuint(oChan, data); + p :> word; + fourBits = (word << 3) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = nibble << 4; + p :> word; + fourBits = (word << 7) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + old = compressed; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 1) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 6) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + old = old | compressed << 1; + p :> word; + fourBits = (word << 3) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 0) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 5) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + outuint(oChan, data); + p :> word; + fourBits = (word << 2) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 7) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = nibble << 4; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 1) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 5) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + old = compressed; + p :> word; + fourBits = (word << 3) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 7) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 1) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + outuint(oChan, data); + p :> word; + fourBits = (word << 6) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = nibble << 4; + p :> word; + fourBits = (word << 3) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 0) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 2) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 6) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + old = old | compressed << 1; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 0) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + outuint(oChan, data); + p :> word; + fourBits = (word << 5) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = nibble << 4; + p :> word; + fourBits = (word << 2) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 7) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 1) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 5) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + old = compressed; + p :> word; + fourBits = (word << 3) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 7) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + outuint(oChan, data); + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 1) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = nibble << 4; + p :> word; + fourBits = (word << 6) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 3) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 0) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 2) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 6) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + old = old | compressed << 1; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + outuint(oChan, data); + p :> word; + fourBits = (word << 1) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = nibble << 4; + p :> word; + fourBits = (word << 5) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 3) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 7) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 1) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 6) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + old = compressed; + p :> word; + fourBits = (word << 3) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + outuint(oChan, data); + p :> word; + fourBits = (word << 0) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = nibble << 4; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + old = old | compressed << 1; + p :> word; + fourBits = (word << 2) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 6) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 3)) & 31]; + old = compressed >> 2; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 4) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 1)) & 31]; + old = compressed >> 4; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 0) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + old = compressed; + p :> word; + fourBits = (word << 5) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + compressed = compressed >> 1; + nibble = lookupNRTZ[(old | (compressed << 4)) & 31]; + old = compressed >> 1; + data = (data | nibble) << 4; + p :> word; + fourBits = (word << 2) & mask; + crc32(fourBits, 0xf, 0xf); + compressed = lookupCrcF[fourBits]; + nibble = lookupNRTZ[(old | (compressed << 2)) & 31]; + old = compressed >> 3; + data = (data | nibble) << 4; + outuint(oChan, data); + p :> word; + if (word != 0 && word+1 != 0) return; + } +} + diff --git a/module_usb_midi/src/midi_descriptor.h b/module_usb_midi/src/midi_descriptor.h index bcfa83ea..fb907e5c 100644 --- a/module_usb_midi/src/midi_descriptor.h +++ b/module_usb_midi/src/midi_descriptor.h @@ -1,4 +1,4 @@ -/* This file contains the MID device descriptor +/* This file contains the MID device descriptor It is intended to be included in the main device descriptor definition */ /* MIDI Descriptors */ diff --git a/module_usb_midi/src/midiinparse.xc b/module_usb_midi/src/midiinparse.xc index dd7dcf1f..020f9b61 100644 --- a/module_usb_midi/src/midiinparse.xc +++ b/module_usb_midi/src/midiinparse.xc @@ -1,7 +1,7 @@ /** * @file midiinparse.xc * @brief Generates USB MIDI events from MIDI events - * @author Russell Gallop, XMOS Semiconductor + * @author Russell Gallop, XMOS Semiconductor * @version 0.1 */ @@ -39,7 +39,7 @@ void reset_midi_state(struct midi_in_parse_state &mips) { } /** - * @brief Construct USB MIDI event + * @brief Construct USB MIDI event * */ static unsigned makeEvent(unsigned cable_number, unsigned codeIndexNumber, unsigned midi0, unsigned midi1, unsigned midi2) { @@ -92,7 +92,7 @@ static unsigned makeEvent(unsigned cable_number, unsigned codeIndexNumber, unsig state.received++; // Compose sysex bytes that we've got and send them out. // This will depend how many we have. - state.codeIndexNumber = state.received + 0x4; + state.codeIndexNumber = state.received + 0x4; valid = 1; data = makeEvent(cable_number, state.codeIndexNumber, state.receivebuffer[0], state.receivebuffer[1], state.receivebuffer[2]); @@ -101,7 +101,7 @@ static unsigned makeEvent(unsigned cable_number, unsigned codeIndexNumber, unsig reset_midi_state(state); state.receivebuffer[state.received] = b; state.received++; - switch (lowNibble) + switch (lowNibble) { case 0x2: // Song Position Pointer (3 byte system common) { @@ -119,7 +119,7 @@ static unsigned makeEvent(unsigned cable_number, unsigned codeIndexNumber, unsig break; } case 0x6: // Tune request (1 byte system common) - state.codeIndexNumber = 5; + state.codeIndexNumber = 5; valid = 1; data = makeEvent(cable_number, state.codeIndexNumber, state.receivebuffer[0], state.receivebuffer[1], state.receivebuffer[2]); @@ -143,7 +143,7 @@ static unsigned makeEvent(unsigned cable_number, unsigned codeIndexNumber, unsig state.received++; // code index number is always the high nibble for channel messages state.codeIndexNumber = highNibble; - switch (highNibble) + switch (highNibble) { case 0x8: // Note-off case 0x9: // Note-on diff --git a/module_usb_midi/src/midioutparse.xc b/module_usb_midi/src/midioutparse.xc index a84b8d53..74caec1b 100644 --- a/module_usb_midi/src/midioutparse.xc +++ b/module_usb_midi/src/midioutparse.xc @@ -1,12 +1,12 @@ /** * @file midioutparse.xc * @brief Parses USB-MIDI events into set of MIDI bytes - * @author Russell Gallop, XMOS Semiconductor + * @author Russell Gallop, XMOS Semiconductor */ #include "midioutparse.h" -/** +/** * @brief Breaks a USB-MIDI event into it's constituant fields * * @param[in] ev USB-MIDI event @@ -23,7 +23,7 @@ #endif -/** +/** * @brief Parse a USB-MIDI event into the MIDI bytes and a length field * * @param[in] ev USB-MIDI event @@ -35,7 +35,7 @@ unsigned size = 0; {cable_number, codeIndexNumber, midi[0], midi[1], midi[2]} = breakEvent(event); - + // Not doing anything with cable number switch (codeIndexNumber) { case 0x3: // Three-byte system Common messages like SPP, etc. diff --git a/module_usb_midi/src/usb_midi.h b/module_usb_midi/src/usb_midi.h index ca9a490f..6a55ce74 100644 --- a/module_usb_midi/src/usb_midi.h +++ b/module_usb_midi/src/usb_midi.h @@ -9,13 +9,13 @@ * * \param p_midi_in 1-bit input port for MIDI * \param p_midi_out 1-bit output port for MIDI - * \param clk_midi clock block used for clockin the UART; should have + * \param clk_midi clock block used for clockin the UART; should have * a rate of 100MHz * \param c_midi chanend connected to the decouple() thread * \param cable_number the cable number of the MIDI implementation. * This should be set to 0. **/ -void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, +void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, clock ?clk_midi, chanend ?c_midi, unsigned cable_number, diff --git a/module_usb_midi/src/usb_midi.xc b/module_usb_midi/src/usb_midi.xc index 3a3a4f13..f23bb415 100644 --- a/module_usb_midi/src/usb_midi.xc +++ b/module_usb_midi/src/usb_midi.xc @@ -107,9 +107,9 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, #ifdef IAP CoProcessorDisable(); #endif - + // p_midi_out <: 1 << MIDI_SHIFT_TX; // Start with high bit. -#ifdef IAP +#ifdef IAP CoProcessorEnable(); #endif @@ -120,7 +120,7 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, init_iAP(iap_incoming_buffer, iap_outgoing_buffer, null, null, null); // uses timer for i2c initialisation pause.. } else - { + { init_iAP(iap_incoming_buffer, iap_outgoing_buffer, c_i2c, p_scl, p_sda); // uses timer for i2c initialisation pause.. } #endif @@ -130,12 +130,12 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, iAPTimer :> polltime; polltime += XS1_TIMER_HZ / 2; #endif - while (1) + while (1) { int is_ack; int is_reset; unsigned int datum; - select + select { // Input to read the start bit #ifndef MIDI_LOOPBACK @@ -148,24 +148,24 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, asm("setc res[%0],1"::"r"(p_midi_in)); asm("setpt res[%0],%1"::"r"(p_midi_in),"r"(rxPT)); break; - + // Input to read the remaining bits case (!authenticating && isRX) => t2 when timerafter(rxT) :> int _ : { unsigned bit; p_midi_in :> bit; - if (rxI++ < 8) + if (rxI++ < 8) { // shift in bits into the high end of a word rxByte = (bit << 31) | (rxByte >> 1); rxT += bit_time; rxPT += bit_time; asm("setpt res[%0],%1"::"r"(p_midi_in),"r"(rxPT)); - } - else + } + else { // rcv and check stop bit - if ((bit & 0x1) == 1) + if ((bit & 0x1) == 1) { unsigned valid = 0; unsigned event = 0; @@ -173,7 +173,7 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, rxByte >>= 24; #if 0 // Loopback check - if ((rxByte != outputted_symbol)) + if ((rxByte != outputted_symbol)) { printhexln(rxByte); printhexln(outputted_symbol); @@ -185,20 +185,20 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, event = byterev(event); // data to send to host - add to fifo - if (!waiting_for_ack) + if (!waiting_for_ack) { // send data // printstr("uart->decouple: "); outuint(c_midi, event); waiting_for_ack = 1; th_count++; - } - else + } + else { queue_push_word(midi_to_host_fifo, midi_to_host_fifo_arr, event); } - } - else if (valid) + } + else if (valid) { //printstr("g"); } @@ -213,7 +213,7 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, // until symbol is zero expect pattern like 10'b1dddddddd0 // This code will leave the output high afterwards due to the stop bit added with makeSymbol case (!authenticating && isTX) => t when timerafter(txT) :> int _: - if (symbol == 0) + if (symbol == 0) { // Got something to output but not mid-symbol. // Start sending symbol. @@ -236,8 +236,8 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, txT += bit_time; txPT += bit_time; isTX = 1; - } - else + } + else { // Mid-symbol txT += bit_time; // Should this be after the output otherwise be double the length of the high before the start bit @@ -245,7 +245,7 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, p_midi_out @ txPT <: ((symbol & 1)<>= 1; - if (symbol == 0) + if (symbol == 0) { // Finished sending byte uout_count++; @@ -261,7 +261,7 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, case !authenticating => midi_get_ack_or_data(c_midi, is_ack, datum): - if (is_ack) + if (is_ack) { // have we got more data to send //printstr("ack\n"); @@ -270,13 +270,13 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, //printstr("uart->decouple\n"); outuint(c_midi, queue_pop_word(midi_to_host_fifo, midi_to_host_fifo_arr)); th_count++; - } - else + } + else { waiting_for_ack = 0; } - } - else + } + else { unsigned midi[3]; unsigned size; @@ -287,15 +287,15 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, if (queue_is_empty(midi_to_host_fifo)) { // data to send to host - if (!waiting_for_ack) + if (!waiting_for_ack) { // send data event = byterev(event); outuint(c_midi, event); th_count++; waiting_for_ack = 1; - } - else + } + else { event = byterev(event); queue_push_word(midi_to_host_fifo, midi_to_host_fifo_arr, event); @@ -308,7 +308,7 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, } #else {midi[0], midi[1], midi[2], size} = midi_out_parse(event); - for (int i = 0; i != size; i++) + for (int i = 0; i != size; i++) { // add symbol to fifo queue_push_word(symbol_fifo, symbol_fifo_arr, midi[i]); @@ -317,13 +317,13 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, if (queue_space(symbol_fifo) > 3) { midi_send_ack(c_midi); - } - else + } + else { midi_from_host_overflow = 1; } // Drop through to the isTX guarded case - if (!isTX) + if (!isTX) { t :> txT; // Should be enough to trigger the other case isTX = 1; @@ -343,7 +343,7 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out, { iap_handle_ack_or_reset_or_data(iap_incoming_buffer, iap_outgoing_buffer, is_ack, is_reset, datum, c_iap, c_i2c, p_scl, p_sda); } - if (!authenticating) + if (!authenticating) { // printstrln("Completed authentication"); p_midi_in :> void; // Change port around to input again after authenticating (unique to midi+iAP case)