added toplevel makefile for xpd

This commit is contained in:
dan
2014-01-22 11:00:41 +00:00
parent 7c42307440
commit 98b3bdba95
47 changed files with 2789 additions and 2778 deletions

11
Makefile Normal file
View File

@@ -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

View File

@@ -10,7 +10,7 @@
#error DFU_PID not defined! #error DFU_PID not defined!
#endif #endif
#ifndef DFU_BCD_DEVICE #ifndef DFU_BCD_DEVICE
#error DFU_BCD_DEVICE not defined! #error DFU_BCD_DEVICE not defined!
#endif #endif
@@ -36,12 +36,12 @@ unsigned char DFUdevDesc[] = {
0x00, /* 5 bDeviceSubClass: See interface */ 0x00, /* 5 bDeviceSubClass: See interface */
0, /* 6 bDeviceProtocol: See interface */ 0, /* 6 bDeviceProtocol: See interface */
64, /* 7 bMaxPacketSize */ 64, /* 7 bMaxPacketSize */
(DFU_VENDOR_ID & 0xFF), /* 8 idVendor */ (DFU_VENDOR_ID & 0xFF), /* 8 idVendor */
(DFU_VENDOR_ID >> 8), /* 9 idVendor */ (DFU_VENDOR_ID >> 8), /* 9 idVendor */
(DFU_PID & 0xFF), /* 10 idProduct */ (DFU_PID & 0xFF), /* 10 idProduct */
(DFU_PID >> 8), /* 11 idProduct */ (DFU_PID >> 8), /* 11 idProduct */
(DFU_BCD_DEVICE & 0xFF), /* 12 bcdDevice : Device release number */ (DFU_BCD_DEVICE & 0xFF), /* 12 bcdDevice : Device release number */
(DFU_BCD_DEVICE >> 8), /* 13 bcdDevice : Device release number */ (DFU_BCD_DEVICE >> 8), /* 13 bcdDevice : Device release number */
DFU_MANUFACTURER_STR_INDEX, /* 14 iManufacturer : Index of manufacturer string */ DFU_MANUFACTURER_STR_INDEX, /* 14 iManufacturer : Index of manufacturer string */
DFU_PRODUCT_STR_INDEX, /* 15 iProduct : Index of product string descriptor */ DFU_PRODUCT_STR_INDEX, /* 15 iProduct : Index of product string descriptor */
DFU_SERIAL_STR_INDEX, /* 16 iSerialNumber : Index of serial number decriptor */ DFU_SERIAL_STR_INDEX, /* 16 iSerialNumber : Index of serial number decriptor */
@@ -49,7 +49,7 @@ unsigned char DFUdevDesc[] = {
}; };
unsigned char DFUcfgDesc[] = { unsigned char DFUcfgDesc[] = {
/* Standard USB device descriptor */ /* Standard USB device descriptor */
0x09, /* 0 bLength */ 0x09, /* 0 bLength */
USB_CONFIGURATION, /* 1 bDescriptorType */ USB_CONFIGURATION, /* 1 bDescriptorType */
0x1b, /* 2 wTotalLength */ 0x1b, /* 2 wTotalLength */

View File

@@ -22,28 +22,28 @@ extern int DFU_reset_override;
extern void DFUCustomFlashEnable(); extern void DFUCustomFlashEnable();
extern void DFUCustomFlashDisable(); extern void DFUCustomFlashDisable();
void temp() void temp()
{ {
asm(".linkset DFU_reset_override, _edp.bss"); asm(".linkset DFU_reset_override, _edp.bss");
asm(".globl DFU_reset_override"); 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]; unsigned int cmd_data[16];
DFUCustomFlashEnable(); DFUCustomFlashEnable();
flash_cmd_init(); flash_cmd_init();
DFU_flash_connected = 1; DFU_flash_connected = 1;
} }
return 0; 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]; unsigned int cmd_data[16];
DFUCustomFlashDisable(); DFUCustomFlashDisable();
@@ -53,9 +53,9 @@ static int DFU_CloseFlash(chanend ?c_user_cmd)
return 0; 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; DFU_state = STATE_APP_DETACH;
@@ -64,15 +64,15 @@ static int DFU_Detach(unsigned int timeout, chanend ?c_user_cmd)
// Setup DFU timeout value // Setup DFU timeout value
DFUResetTimeout = timeout * 100000; DFUResetTimeout = timeout * 100000;
// Start DFU reset timer // Start DFU reset timer
DFUTimer :> DFUTimerStart; DFUTimer :> DFUTimerStart;
} }
else else
{ {
DFU_state = STATE_DFU_ERROR; 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) 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); DFU_OpenFlash(c_user_cmd);
switch (DFU_state) switch (DFU_state)
{ {
case STATE_DFU_IDLE: case STATE_DFU_IDLE:
case STATE_DFU_DOWNLOAD_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; 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; DFU_state = STATE_DFU_ERROR;
return 0; return 0;
} }
else if (DFU_state == STATE_DFU_IDLE) else if (DFU_state == STATE_DFU_IDLE)
{ {
fromDfuIdle = 1; fromDfuIdle = 1;
} }
else else
{ {
fromDfuIdle = 0; fromDfuIdle = 0;
} }
if (request_len == 0) if (request_len == 0)
{ {
// Host signalling complete download // Host signalling complete download
int i = 0; int i = 0;
unsigned int cmd_data[16]; unsigned int cmd_data[16];
if (subPagesLeft) if (subPagesLeft)
{ {
unsigned int subPagePad[16] = {0}; 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])); 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[])); flash_cmd_write_page((cmd_data, unsigned char[]));
DFU_state = STATE_DFU_MANIFEST_SYNC; DFU_state = STATE_DFU_MANIFEST_SYNC;
} }
else else
{ {
unsigned int i = 0; unsigned int i = 0;
unsigned int flash_cmd = 0; unsigned int flash_cmd = 0;
unsigned int flash_page_index = 0; unsigned int flash_page_index = 0;
unsigned int cmd_data[16]; unsigned int cmd_data[16];
if (fromDfuIdle) if (fromDfuIdle)
{ {
unsigned s = 0; unsigned s = 0;
// Erase flash on first block // 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 // 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. cmd_data[0] = !fromDfuIdle; // 0 for first page, 1 for other pages.
flash_cmd_write_page((cmd_data, unsigned char[64])); flash_cmd_write_page((cmd_data, unsigned char[64]));
subPagesLeft = 4; subPagesLeft = 4;
} }
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
{ {
cmd_data[i] = request_data[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; 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 cmd_data[16];
unsigned int firstRead = 0; 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) // Keep reading flash pages until read_page returns 1 (address out of range)
// Return terminating upload packet at this point // Return terminating upload packet at this point
DFU_OpenFlash(c_user_cmd); DFU_OpenFlash(c_user_cmd);
switch (DFU_state) switch (DFU_state)
{ {
case STATE_DFU_IDLE: case STATE_DFU_IDLE:
case STATE_DFU_UPLOAD_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; 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; DFU_state = STATE_DFU_ERROR;
return 0; return 0;
} }
else if (DFU_state == STATE_DFU_IDLE) else if (DFU_state == STATE_DFU_IDLE)
{ {
firstRead = 1; firstRead = 1;
subPagesLeft = 0; subPagesLeft = 0;
} }
if (!subPagesLeft) if (!subPagesLeft)
{ {
cmd_data[0] = !firstRead; cmd_data[0] = !firstRead;
@@ -207,14 +207,14 @@ static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned
subPagesLeft = 4; subPagesLeft = 4;
// If address out of range, terminate! // If address out of range, terminate!
if (cmd_data[0] == 1) if (cmd_data[0] == 1)
{ {
subPagesLeft = 0; subPagesLeft = 0;
// Back to idle state, upload complete // Back to idle state, upload complete
DFU_state = STATE_DFU_IDLE; DFU_state = STATE_DFU_IDLE;
return 0; return 0;
} }
} }
// Read page data // Read page data
flash_cmd_write_page_data((request_data, unsigned char[64])); 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; 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; unsigned int timeout = 0;
request_data[0] = timeout << 8 | (unsigned char)DFU_status; request_data[0] = timeout << 8 | (unsigned char)DFU_status;
switch (DFU_state) switch (DFU_state)
{ {
case STATE_DFU_MANIFEST: case STATE_DFU_MANIFEST:
case STATE_DFU_MANIFEST_WAIT_RESET: 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; 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; DFU_state = STATE_DFU_IDLE;
} }
else else
{ {
DFU_state = STATE_DFU_ERROR; 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; request_data[0] = DFU_state;
switch (DFU_state) switch (DFU_state)
{ {
case STATE_DFU_DOWNLOAD_BUSY: case STATE_DFU_DOWNLOAD_BUSY:
case STATE_DFU_MANIFEST: case STATE_DFU_MANIFEST:
@@ -287,22 +287,22 @@ static int DFU_GetState(unsigned int request_len, unsigned int request_data[16],
break; break;
} }
return 1; return 1;
} }
static int DFU_Abort(void) static int DFU_Abort(void)
{ {
DFU_state = STATE_DFU_IDLE; DFU_state = STATE_DFU_IDLE;
return 0; return 0;
} }
// Tell the DFU state machine that a USB reset has occured // 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 inDFU = 0;
unsigned int currentTime = 0; unsigned int currentTime = 0;
if (DFU_reset_override == 0x11042011) if (DFU_reset_override == 0x11042011)
{ {
unsigned int cmd_data[16]; unsigned int cmd_data[16];
inDFU = 1; inDFU = 1;
@@ -310,19 +310,19 @@ int DFUReportResetState(chanend ?c_user_cmd)
return inDFU; return inDFU;
} }
switch(DFU_state) switch(DFU_state)
{ {
case STATE_APP_DETACH: case STATE_APP_DETACH:
case STATE_DFU_IDLE: case STATE_DFU_IDLE:
DFU_state = STATE_DFU_IDLE; DFU_state = STATE_DFU_IDLE;
DFUTimer :> currentTime; DFUTimer :> currentTime;
if (currentTime - DFUTimerStart > DFUResetTimeout) if (currentTime - DFUTimerStart > DFUResetTimeout)
{ {
DFU_state = STATE_APP_IDLE; DFU_state = STATE_APP_IDLE;
inDFU = 0; inDFU = 0;
} }
else else
{ {
inDFU = 1; inDFU = 1;
} }
@@ -339,13 +339,13 @@ int DFUReportResetState(chanend ?c_user_cmd)
inDFU = 0; inDFU = 0;
DFU_state = STATE_APP_IDLE; DFU_state = STATE_APP_IDLE;
break; break;
default: default:
DFU_state = STATE_DFU_ERROR; DFU_state = STATE_DFU_ERROR;
inDFU = 1; inDFU = 1;
break; break;
} }
if (!inDFU) if (!inDFU)
{ {
DFU_CloseFlash(c_user_cmd); DFU_CloseFlash(c_user_cmd);
} }
@@ -363,7 +363,7 @@ static int XMOS_DFU_RevertFactory(chanend ?c_user_cmd)
DFUTimer :> s; DFUTimer :> s;
DFUTimer when timerafter(s + 25000000) :> s; // Wait for flash erase DFUTimer when timerafter(s + 25000000) :> s; // Wait for flash erase
return 0; return 0;
} }
@@ -376,7 +376,7 @@ static int XMOS_DFU_SelectImage(unsigned int index, chanend ?c_user_cmd)
static int XMOS_DFU_SaveState() static int XMOS_DFU_SaveState()
{ {
return 0; 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_len = 0;
unsigned int data_buffer[17]; unsigned int data_buffer[17];
unsigned int reset_device_after_ack = 0; 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 // Host to device
if (sp.wLength) if (sp.wLength)
data_buffer_len = XUD_GetBuffer(ep0_out, (data_buffer, unsigned char[])); data_buffer_len = XUD_GetBuffer(ep0_out, (data_buffer, unsigned char[]));
} }
// Map Standard DFU commands onto device level firmware upgrade mechanism // Map Standard DFU commands onto device level firmware upgrade mechanism
switch (sp.bRequest) switch (sp.bRequest)
{ {
case DFU_DETACH: case DFU_DETACH:
return_data_len = DFU_Detach(sp.wValue, c_user_cmd); 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; 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 // Device to host
#ifdef ARCH_G #ifdef ARCH_G
XUD_DoGetRequest(ep0_out, 0, (data_buffer, unsigned char[]), return_data_len, return_data_len); XUD_DoGetRequest(ep0_out, 0, (data_buffer, unsigned char[]), return_data_len, return_data_len);
#else #else
XUD_DoGetRequest(ep0_out, ep0_in, (data_buffer, unsigned char[]), return_data_len, return_data_len); XUD_DoGetRequest(ep0_out, ep0_in, (data_buffer, unsigned char[]), return_data_len, return_data_len);
#endif #endif
} }
else else
{ {
#ifdef ARCH_G #ifdef ARCH_G
XUD_DoSetRequestStatus(ep0_out); 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 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;
} }
} }

View File

@@ -4,7 +4,7 @@
#include <string.h> #include <string.h>
#include <xclib.h> #include <xclib.h>
#ifndef FLASH_MAX_UPGRADE_SIZE #ifndef FLASH_MAX_UPGRADE_SIZE
#define FLASH_MAX_UPGRADE_SIZE 128 * 1024 // 128K default #define FLASH_MAX_UPGRADE_SIZE 128 * 1024 // 128K default
#endif #endif
@@ -40,11 +40,11 @@ void DFUCustomFlashDisable()
return; return;
} }
int flash_cmd_init(void) int flash_cmd_init(void)
{ {
fl_BootImageInfo image; fl_BootImageInfo image;
if (!flash_device_open) if (!flash_device_open)
{ {
if (flash_cmd_enable_ports()) if (flash_cmd_enable_ports())
flash_device_open = 1; flash_device_open = 1;
@@ -56,14 +56,14 @@ int flash_cmd_init(void)
// Disable flash protection // Disable flash protection
fl_setProtection(0); fl_setProtection(0);
if (fl_getFactoryImage(&image) != 0) if (fl_getFactoryImage(&image) != 0)
{ {
return 0; return 0;
} }
factory_image = image; factory_image = image;
if (fl_getNextBootImage(&image) == 0) if (fl_getNextBootImage(&image) == 0)
{ {
upgrade_image_valid = 1; upgrade_image_valid = 1;
upgrade_image = image; upgrade_image = image;
@@ -72,43 +72,43 @@ int flash_cmd_init(void)
return 0; return 0;
} }
int flash_cmd_deinit(void) int flash_cmd_deinit(void)
{ {
if (!flash_device_open) if (!flash_device_open)
return 0; return 0;
flash_cmd_disable_ports(); flash_cmd_disable_ports();
flash_device_open = 0; flash_device_open = 0;
return 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; *(unsigned int *)data = 1;
return 4; return 4;
} }
if (*(unsigned int *)data == 0) if (*(unsigned int *)data == 0)
{ {
fl_startImageRead(&upgrade_image); fl_startImageRead(&upgrade_image);
} }
current_flash_subpage_index = 0; 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; *(unsigned int *)data = 0;
} }
else else
{ {
*(unsigned int *)data = 1; *(unsigned int *)data = 1;
} }
return 4; 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 = &current_flash_page_data[current_flash_subpage_index * 64]; unsigned char *page_data_ptr = &current_flash_page_data[current_flash_subpage_index * 64];
memcpy(data, page_data_ptr, 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 // 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 // paused on this operation it would be preferable to move to this to a
// seperate command, e.g. start_write. // seperate command, e.g. start_write.
do do
{ {
result = fl_startImageAdd(&factory_image, FLASH_MAX_UPGRADE_SIZE, 0); result = fl_startImageAdd(&factory_image, FLASH_MAX_UPGRADE_SIZE, 0);
} while (result > 0); } while (result > 0);
if (result < 0) if (result < 0)
FLASH_ERROR(); FLASH_ERROR();
} }
static int pages_written = 0; 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; unsigned int flag = *(unsigned int *)data;
if (upgrade_image_valid) if (upgrade_image_valid)
{ {
return 0; return 0;
} }
switch (flag) switch (flag)
{ {
case 0: case 0:
// First page. // First page.
@@ -158,7 +158,7 @@ int flash_cmd_write_page(unsigned char *data)
// Termination. // Termination.
if (fl_endWriteImage() != 0) if (fl_endWriteImage() != 0)
FLASH_ERROR(); FLASH_ERROR();
// Sanity check // Sanity check
fl_BootImageInfo image = factory_image; fl_BootImageInfo image = factory_image;
if (fl_getNextBootImage(&image) != 0) if (fl_getNextBootImage(&image) != 0)
@@ -173,7 +173,7 @@ int flash_cmd_write_page(unsigned char *data)
static int isAllOnes(unsigned char page[256]) static int isAllOnes(unsigned char page[256])
{ {
unsigned i; unsigned i;
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
if (page[i] != 0xff) if (page[i] != 0xff)
return 0; return 0;
@@ -181,16 +181,16 @@ static int isAllOnes(unsigned char page[256])
return 1; 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 = &current_flash_page_data[current_flash_subpage_index * 64]; unsigned char *page_data_ptr = &current_flash_page_data[current_flash_subpage_index * 64];
if (upgrade_image_valid) if (upgrade_image_valid)
{ {
return 0; return 0;
} }
if (current_flash_subpage_index >= 4) if (current_flash_subpage_index >= 4)
{ {
return 0; return 0;
} }
@@ -199,11 +199,11 @@ int flash_cmd_write_page_data(unsigned char *data)
current_flash_subpage_index++; current_flash_subpage_index++;
if (current_flash_subpage_index == 4) if (current_flash_subpage_index == 4)
{ {
if (isAllOnes(data)) if (isAllOnes(data))
FLASH_ERROR(); FLASH_ERROR();
if (fl_writeImagePage(current_flash_page_data) != 0) if (fl_writeImagePage(current_flash_page_data) != 0)
FLASH_ERROR(); FLASH_ERROR();
pages_written++; pages_written++;
} }
@@ -211,22 +211,22 @@ int flash_cmd_write_page_data(unsigned char *data)
return 0; return 0;
} }
int flash_cmd_erase_all(void) int flash_cmd_erase_all(void)
{ {
fl_BootImageInfo tmp_image = upgrade_image; fl_BootImageInfo tmp_image = upgrade_image;
if (upgrade_image_valid) if (upgrade_image_valid)
{ {
if (fl_deleteImage(&upgrade_image) != 0) if (fl_deleteImage(&upgrade_image) != 0)
{ {
FLASH_ERROR(); FLASH_ERROR();
} }
// Keep deleting all upgrade images // Keep deleting all upgrade images
// TODO Perhaps using replace would be nicer... // TODO Perhaps using replace would be nicer...
while(1) while(1)
{ {
if (fl_getNextBootImage(&tmp_image) == 0) if (fl_getNextBootImage(&tmp_image) == 0)
{ {
if (fl_deleteImage(&tmp_image) != 0) if (fl_deleteImage(&tmp_image) != 0)
{ {
@@ -238,7 +238,7 @@ int flash_cmd_erase_all(void)
break; break;
} }
} }
upgrade_image_valid = 0; upgrade_image_valid = 0;
} }
return 0; return 0;

View File

@@ -3,14 +3,14 @@
/** The audio driver thread. /** 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. * I/O threads.
* *
* \param c_in Audio sample channel connected to the mixer() thread or the * \param c_in Audio sample channel connected to the mixer() thread or the
* decouple() thread * 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 * 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. * CODEC configuration functions.
*/ */
void audio(chanend c_in, chanend ?c_dig, chanend ?c_config, chanend ?c_adc); void audio(chanend c_in, chanend ?c_dig, chanend ?c_config, chanend ?c_adc);

View File

@@ -1,11 +1,11 @@
/** /**
* @file audio.xc * @file audio.xc
* @brief XMOS L1/L2 USB 2,0 Audio Reference Design. Audio Functions. * @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. * 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. * Additionally this thread handles clocking and CODEC/DAC/ADC config.
**/ **/
#include <syscall.h> #include <syscall.h>
#include <platform.h> #include <platform.h>
@@ -25,7 +25,7 @@
unsigned testsamples[100]; unsigned testsamples[100];
int p = 0; int p = 0;
unsigned lastSample = 0; unsigned lastSample = 0;
#if (DSD_CHANS_DAC != 0) #if (DSD_CHANS_DAC != 0)
extern unsigned p_dsd_dac[DSD_CHANS_DAC]; extern unsigned p_dsd_dac[DSD_CHANS_DAC];
extern port p_dsd_clk; extern port p_dsd_clk;
#endif #endif
@@ -40,7 +40,7 @@ unsigned g_adcVal = 0;
/* I2S Data I/O*/ /* I2S Data I/O*/
#if (I2S_CHANS_DAC != 0) #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 #endif
#if (I2S_CHANS_ADC != 0) #if (I2S_CHANS_ADC != 0)
@@ -61,13 +61,13 @@ unsigned dsdMode = DSD_MODE_OFF;
/* Master clock input */ /* Master clock input */
extern port p_mclk_in; extern port p_mclk_in;
#ifdef SPDIF #ifdef SPDIF
extern buffered out port:32 p_spdif_tx; extern buffered out port:32 p_spdif_tx;
#endif #endif
extern clock clk_audio_mclk; extern clock clk_audio_mclk;
extern clock clk_audio_bclk; extern clock clk_audio_bclk;
extern clock clk_mst_spd; extern clock clk_mst_spd;
extern void device_reboot(void); extern void device_reboot(void);
@@ -81,43 +81,43 @@ extern void device_reboot(void);
#ifndef CODEC_MASTER #ifndef CODEC_MASTER
static inline void doI2SClocks(unsigned divide) static inline void doI2SClocks(unsigned divide)
{ {
switch (divide) switch (divide)
{ {
#if (MAX_DIVIDE > 16) #if (MAX_DIVIDE > 16)
#error MCLK/BCLK Ratio not supported!! #error MCLK/BCLK Ratio not supported!!
#endif #endif
#if (MAX_DIVIDE > 8) #if (MAX_DIVIDE > 8)
case 16: 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; break;
#endif #endif
#if (MAX_DIVIDE > 4) #if (MAX_DIVIDE > 4)
case 8: 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; break;
#endif #endif
#if (MAX_DIVIDE > 2) #if (MAX_DIVIDE > 2)
@@ -129,7 +129,7 @@ static inline void doI2SClocks(unsigned divide)
break; break;
#endif #endif
#if (MAX_DIVIDE > 1) #if (MAX_DIVIDE > 1)
case 2: case 2:
p_bclk <: 0xAAAAAAAA; p_bclk <: 0xAAAAAAAA;
p_bclk <: 0xAAAAAAAA; p_bclk <: 0xAAAAAAAA;
break; break;
@@ -137,7 +137,7 @@ static inline void doI2SClocks(unsigned divide)
#if (MAX_DIVIDE > 0) #if (MAX_DIVIDE > 0)
case 1: case 1:
break; break;
#endif #endif
} }
} }
#endif #endif
@@ -148,10 +148,10 @@ static inline void doI2SClocks(unsigned divide)
{ {
unsigned sample; unsigned sample;
unsigned underflow = 0; unsigned underflow = 0;
#if NUM_USB_CHAN_OUT > 0 #if NUM_USB_CHAN_OUT > 0
unsigned samplesOut[NUM_USB_CHAN_OUT]; unsigned samplesOut[NUM_USB_CHAN_OUT];
#endif #endif
#if NUM_USB_CHAN_IN > 0 #if NUM_USB_CHAN_IN > 0
unsigned samplesIn[NUM_USB_CHAN_IN]; unsigned samplesIn[NUM_USB_CHAN_IN];
unsigned samplesInPrev[NUM_USB_CHAN_IN]; unsigned samplesInPrev[NUM_USB_CHAN_IN];
#endif #endif
@@ -181,7 +181,7 @@ static inline void doI2SClocks(unsigned divide)
} }
#endif #endif
#if(DSD_CHANS_DAC != 0) #if(DSD_CHANS_DAC != 0)
if(dsdMode == DSD_MODE_DOP) if(dsdMode == DSD_MODE_DOP)
underflowWord = 0xFA969600; underflowWord = 0xFA969600;
else if(dsdMode == DSD_MODE_NATIVE) else if(dsdMode == DSD_MODE_NATIVE)
@@ -196,18 +196,18 @@ static inline void doI2SClocks(unsigned divide)
if(testct(c_out)) if(testct(c_out))
{ {
unsigned command = inct(c_out); unsigned command = inct(c_out);
#ifndef CODEC_MASTER #ifndef CODEC_MASTER
// Set clocks low // Set clocks low
p_lrclk <: 0; p_lrclk <: 0;
p_bclk <: 0; p_bclk <: 0;
#if(DSD_CHANS_DAC != 0) #if(DSD_CHANS_DAC != 0)
/* DSD Clock might not be shared with lrclk or bclk... */ /* DSD Clock might not be shared with lrclk or bclk... */
p_dsd_clk <: 0; p_dsd_clk <: 0;
#endif #endif
#endif #endif
#if (DSD_CHANS_DAC > 0) #if (DSD_CHANS_DAC > 0)
if(dsdMode == DSD_MODE_DOP) if(dsdMode == DSD_MODE_DOP)
dsdMode = DSD_MODE_OFF; dsdMode = DSD_MODE_OFF;
#endif #endif
return {command, inuint(c_out)}; return {command, inuint(c_out)};
} }
@@ -228,7 +228,7 @@ static inline void doI2SClocks(unsigned divide)
if(underflow) if(underflow)
{ {
#pragma loop unroll #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; samplesOut[i] = underflowWord;
} }
@@ -236,7 +236,7 @@ static inline void doI2SClocks(unsigned divide)
else else
{ {
#pragma loop unroll #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); samplesOut[i] = inuint(c_out);
} }
@@ -248,15 +248,15 @@ static inline void doI2SClocks(unsigned divide)
if(underflow) if(underflow)
{ {
#pragma loop unroll #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; samplesOut[i] = underflowWord;
} }
} }
else else
{ {
#pragma loop unroll #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); int tmp = inuint(c_out);
#if defined(OUT_VOLUME_IN_MIXER) && defined(OUT_VOLUME_AFTER_MIX) #if defined(OUT_VOLUME_IN_MIXER) && defined(OUT_VOLUME_AFTER_MIX)
@@ -266,7 +266,7 @@ static inline void doI2SClocks(unsigned divide)
} }
} }
#endif #endif
#if NUM_USB_CHAN_IN > 0 #if NUM_USB_CHAN_IN > 0
#pragma loop unroll #pragma loop unroll
for(int i = 0; i < NUM_USB_CHAN_IN; i++) for(int i = 0; i < NUM_USB_CHAN_IN; i++)
@@ -288,7 +288,7 @@ static inline void doI2SClocks(unsigned divide)
#endif #endif
/* Clear I2S port buffers */ /* Clear I2S port buffers */
clearbuf(p_lrclk); clearbuf(p_lrclk);
#if (I2S_CHANS_DAC != 0) #if (I2S_CHANS_DAC != 0)
for(int i = 0; i < I2S_WIRES_DAC; i++) for(int i = 0; i < I2S_WIRES_DAC; i++)
{ {
@@ -308,7 +308,7 @@ static inline void doI2SClocks(unsigned divide)
p_lrclk <: 0 @ tmp; p_lrclk <: 0 @ tmp;
tmp += 100; 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) #if (I2S_CHANS_DAC != 0)
#pragma loop unroll #pragma loop unroll
for(int i = 0; i < I2S_WIRES_DAC; i++) for(int i = 0; i < I2S_WIRES_DAC; i++)
@@ -317,13 +317,13 @@ static inline void doI2SClocks(unsigned divide)
} }
#endif #endif
p_lrclk @ tmp <: 0x7FFFFFFF; p_lrclk @ tmp <: 0x7FFFFFFF;
#if (I2S_CHANS_ADC != 0) #if (I2S_CHANS_ADC != 0)
for(int i = 0; i < I2S_WIRES_DAC; i++) 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)); asm("setpt res[%0], %1"::"r"(p_i2s_adc[i]),"r"(tmp-1));
clearbuf(p_i2s_adc[i]); clearbuf(p_i2s_adc[i]);
} }
@@ -341,11 +341,11 @@ static inline void doI2SClocks(unsigned divide)
p_i2s_dac[i] <: 0; p_i2s_dac[i] <: 0;
} }
#endif #endif
p_lrclk <: 0x7FFFFFFF;
p_lrclk <: 0x7FFFFFFF;
doI2SClocks(divide); doI2SClocks(divide);
} }
#if (DSD_CHANS_DAC > 0) #if (DSD_CHANS_DAC > 0)
} /* if (!dsdMode) */ } /* if (!dsdMode) */
@@ -356,8 +356,8 @@ static inline void doI2SClocks(unsigned divide)
//sync(p_dsd_clk); //sync(p_dsd_clk);
} }
#endif #endif
#else /* ifndef CODEC_MASTER */ #else /* ifndef CODEC_MASTER */
/* Wait for LRCLK edge */ /* Wait for LRCLK edge */
p_lrclk when pinseq(0) :> void; p_lrclk when pinseq(0) :> void;
p_lrclk when pinseq(1) :> 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(1) :> void;
p_lrclk when pinseq(0) :> void @ tmp; p_lrclk when pinseq(0) :> void @ tmp;
tmp += 33; tmp += 33;
#if (I2S_CHANS_DAC != 0) #if (I2S_CHANS_DAC != 0)
#pragma loop unroll #pragma loop unroll
for(int i = 0; i < I2S_WIRES_DAC; i++) for(int i = 0; i < I2S_WIRES_DAC; i++)
{ {
p_i2s_dac[i] @ tmp <: 0; p_i2s_dac[i] @ tmp <: 0;
} }
#endif #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++) for(int i = 0; i < I2S_WIRES_ADC; i++)
{ {
clearbuf(p_i2s_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 */ * and resync if we got a bclk glitch */
#endif #endif
/* Main Audio I/O loop */ /* Main Audio I/O loop */
while (1) while (1)
{ {
outuint(c_out, 0); outuint(c_out, 0);
/* Check for sample freq change (or other command) or new samples from mixer*/ /* Check for sample freq change (or other command) or new samples from mixer*/
if(testct(c_out)) if(testct(c_out))
{ {
@@ -400,13 +400,13 @@ static inline void doI2SClocks(unsigned divide)
// Set clocks low // Set clocks low
p_lrclk <: 0; p_lrclk <: 0;
p_bclk <: 0; p_bclk <: 0;
#if(DSD_CHANS_DAC != 0) #if(DSD_CHANS_DAC != 0)
/* DSD Clock might not be shared with lrclk or bclk... */ /* DSD Clock might not be shared with lrclk or bclk... */
p_dsd_clk <: 0; p_dsd_clk <: 0;
#endif #endif
#endif #endif
command = inct(c_out); command = inct(c_out);
#if (DSD_CHANS_DAC > 0) #if (DSD_CHANS_DAC > 0)
if(dsdMode == DSD_MODE_DOP) if(dsdMode == DSD_MODE_DOP)
dsdMode = DSD_MODE_OFF; dsdMode = DSD_MODE_OFF;
@@ -447,7 +447,7 @@ static inline void doI2SClocks(unsigned divide)
#else /* ifndef MIXER */ #else /* ifndef MIXER */
#if NUM_USB_CHAN_OUT > 0 #if NUM_USB_CHAN_OUT > 0
if(underflow) if(underflow)
{ {
for(int i = 0; i < NUM_USB_CHAN_OUT; i++) for(int i = 0; i < NUM_USB_CHAN_OUT; i++)
{ {
samplesOut[i] = underflowWord; samplesOut[i] = underflowWord;
@@ -457,7 +457,7 @@ static inline void doI2SClocks(unsigned divide)
{ {
#pragma loop unroll #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); int tmp = inuint(c_out);
#if defined(OUT_VOLUME_IN_MIXER) && defined(OUT_VOLUME_AFTER_MIX) #if defined(OUT_VOLUME_IN_MIXER) && defined(OUT_VOLUME_AFTER_MIX)
tmp<<=3; tmp<<=3;
@@ -505,11 +505,11 @@ static inline void doI2SClocks(unsigned divide)
if(dsdMode == DSD_MODE_NATIVE) if(dsdMode == DSD_MODE_NATIVE)
{ {
/* 8 bits per chan, 1st 1-bit sample in MSB */ /* 8 bits per chan, 1st 1-bit sample in MSB */
dsdSample_l = samplesOut[0]; dsdSample_l = samplesOut[0];
dsdSample_r = samplesOut[1]; dsdSample_r = samplesOut[1];
dsdSample_r = bitrev(byterev(dsdSample_r)); dsdSample_r = bitrev(byterev(dsdSample_r));
dsdSample_l = bitrev(byterev(dsdSample_l)); dsdSample_l = bitrev(byterev(dsdSample_l));
/* Output DSD data to ports then 32 clocks */ /* Output DSD data to ports then 32 clocks */
switch (divide) switch (divide)
{ {
@@ -521,28 +521,28 @@ static inline void doI2SClocks(unsigned divide)
p_dsd_clk <: 0xCCCCCCCC; p_dsd_clk <: 0xCCCCCCCC;
p_dsd_clk <: 0xCCCCCCCC; p_dsd_clk <: 0xCCCCCCCC;
break; 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[0]),"r"(dsdSample_l));
asm volatile("out res[%0], %1"::"r"(p_dsd_dac[1]),"r"(dsdSample_r)); asm volatile("out res[%0], %1"::"r"(p_dsd_dac[1]),"r"(dsdSample_r));
p_dsd_clk <: 0xAAAAAAAA; p_dsd_clk <: 0xAAAAAAAA;
p_dsd_clk <: 0xAAAAAAAA; p_dsd_clk <: 0xAAAAAAAA;
break; break;
default: default:
/* Do some clocks anyway - this will stop us interrupting decouple too much */ /* 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[0]),"r"(dsdSample_l));
asm volatile("out res[%0], %1"::"r"(p_dsd_dac[1]),"r"(dsdSample_r)); 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; break;
} }
} }
else if(dsdMode == DSD_MODE_DOP) else if(dsdMode == DSD_MODE_DOP)
@@ -551,33 +551,33 @@ static inline void doI2SClocks(unsigned divide)
{ {
dsdSample_l = ((samplesOut[0] & 0xffff00) << 8); dsdSample_l = ((samplesOut[0] & 0xffff00) << 8);
dsdSample_r = ((samplesOut[1] & 0xffff00) << 8); dsdSample_r = ((samplesOut[1] & 0xffff00) << 8);
everyOther = 1; everyOther = 1;
switch (divide) switch (divide)
{ {
case 8: 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; break;
case 4: case 4:
p_dsd_clk <: 0xCCCCCCCC; p_dsd_clk <: 0xCCCCCCCC;
p_dsd_clk <: 0xCCCCCCCC; p_dsd_clk <: 0xCCCCCCCC;
break; break;
case 2: case 2:
p_dsd_clk <: 0xAAAAAAAA; p_dsd_clk <: 0xAAAAAAAA;
break; break;
} }
} }
else // everyOther else // everyOther
{ {
everyOther = 0; everyOther = 0;
dsdSample_l = dsdSample_l | ((samplesOut[0] & 0xffff00) >> 8); dsdSample_l = dsdSample_l | ((samplesOut[0] & 0xffff00) >> 8);
dsdSample_r = dsdSample_r | ((samplesOut[1] & 0xffff00) >> 8); dsdSample_r = dsdSample_r | ((samplesOut[1] & 0xffff00) >> 8);
// Output 16 clocks DSD to all // Output 16 clocks DSD to all
//p_dsd_dac[0] <: bitrev(dsdSample_l); //p_dsd_dac[0] <: bitrev(dsdSample_l);
@@ -587,21 +587,21 @@ static inline void doI2SClocks(unsigned divide)
switch (divide) switch (divide)
{ {
case 8: 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; break;
case 4: case 4:
p_dsd_clk <: 0xCCCCCCCC; p_dsd_clk <: 0xCCCCCCCC;
p_dsd_clk <: 0xCCCCCCCC; p_dsd_clk <: 0xCCCCCCCC;
break; break;
case 2: case 2:
p_dsd_clk <: 0xAAAAAAAA; p_dsd_clk <: 0xAAAAAAAA;
break; break;
} }
} }
} }
@@ -614,26 +614,26 @@ static inline void doI2SClocks(unsigned divide)
#if (I2S_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT != 0) #if (I2S_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT != 0)
#pragma loop unroll #pragma loop unroll
for(int i = 0; i < I2S_CHANS_DAC; i+=2) for(int i = 0; i < I2S_CHANS_DAC; i+=2)
{ {
p_i2s_dac[tmp++] <: bitrev(samplesOut[i]); /* Output LEFT sample to DAC */ p_i2s_dac[tmp++] <: bitrev(samplesOut[i]); /* Output LEFT sample to DAC */
} }
#endif #endif
#ifndef CODEC_MASTER #ifndef CODEC_MASTER
/* LR clock delayed by one clock, This is so MSB is output on the falling edge of BCLK /* 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) */ * 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; p_lrclk <: 0x80000000;
doI2SClocks(divide); doI2SClocks(divide);
#endif #endif
#if (I2S_CHANS_ADC != 0) #if (I2S_CHANS_ADC != 0)
/* Input prevous R sample into R in buffer */ /* Input prevous R sample into R in buffer */
index = 0; index = 0;
#pragma loop unroll #pragma loop unroll
for(int i = 1; i < I2S_CHANS_ADC; i += 2) for(int i = 1; i < I2S_CHANS_ADC; i += 2)
{ {
p_i2s_adc[index++] :> sample; p_i2s_adc[index++] :> sample;
#if NUM_USB_CHAN_IN > 0 #if NUM_USB_CHAN_IN > 0
samplesIn[i] = bitrev(sample); samplesIn[i] = bitrev(sample);
@@ -643,28 +643,28 @@ static inline void doI2SClocks(unsigned divide)
#endif #endif
} }
#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 */ 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 */ outuint(c_spd_out, sample); /* Forward sample to S/PDIF Tx thread */
#endif #endif
tmp = 0; tmp = 0;
#pragma xta endpoint "i2s_output_r" #pragma xta endpoint "i2s_output_r"
#if (I2S_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT != 0) #if (I2S_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT != 0)
#pragma loop unroll #pragma loop unroll
for(int i = 1; i < I2S_CHANS_DAC; i+=2) for(int i = 1; i < I2S_CHANS_DAC; i+=2)
{ {
p_i2s_dac[tmp++] <: bitrev(samplesOut[i]); /* Output RIGHT sample to DAC */ p_i2s_dac[tmp++] <: bitrev(samplesOut[i]); /* Output RIGHT sample to DAC */
} }
#endif #endif
#ifndef CODEC_MASTER #ifndef CODEC_MASTER
/* Clock out data (and LR clock) */ /* Clock out data (and LR clock) */
p_lrclk <: 0x7FFFFFFF; p_lrclk <: 0x7FFFFFFF;
doI2SClocks(divide); doI2SClocks(divide);
#endif #endif
#if (I2S_CHANS_ADC != 0) #if (I2S_CHANS_ADC != 0)
/* Input previous L ADC sample */ /* Input previous L ADC sample */
@@ -690,7 +690,7 @@ static inline void doI2SClocks(unsigned divide)
#endif #endif
#endif #endif
} // !dsdMode } // !dsdMode
#if (DSD_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT > 0) #if (DSD_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT > 0)
/* Check for DSD - note we only move into DoP mode if valid DoP Freq */ /* 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 */ /* 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; dsdMode = DSD_MODE_DOP;
dsdCount = 0; dsdCount = 0;
dsdMarker = DSD_MARKER_2; dsdMarker = DSD_MARKER_2;
// Set clocks low // Set clocks low
p_lrclk <: 0; p_lrclk <: 0;
p_bclk <: 0; p_bclk <: 0;
@@ -740,7 +740,7 @@ static inline void doI2SClocks(unsigned divide)
return {0,0}; 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. */ connect to the codec ports. It is used during DFU reset. */
{unsigned,unsigned} static dummy_deliver(chanend c_out) {unsigned,unsigned} static dummy_deliver(chanend c_out)
{ {
@@ -794,7 +794,7 @@ static inline void doI2SClocks(unsigned divide)
#define SAMPLES_PER_PRINT 1 #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 #ifdef SPDIF
chan c_spdif_out; 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 */ /* I2S has 32 bits per sample. *2 as 2 channels */
unsigned numBits = 64; unsigned numBits = 64;
#if (DSD_CHANS_DAC > 0) #if (DSD_CHANS_DAC > 0)
if(dsdMode == DSD_MODE_DOP) 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 */ /* DSD native we receive in 32bit chunks */
numBits = 32; numBits = 32;
} }
#endif #endif
divide = mClk / ( curSamFreq * numBits ); divide = mClk / ( curSamFreq * numBits );
} }
#if (DSD_CHANS_DAC != 0) #if (DSD_CHANS_DAC != 0)
/* Configure audio ports */ /* Configure audio ports */
ConfigAudioPortsWrapper( ConfigAudioPortsWrapper(
@@ -925,18 +925,18 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c)
divide); divide);
#endif #endif
{ {
unsigned curFreq = curSamFreq; unsigned curFreq = curSamFreq;
#if (DSD_CHANS_DAC > 0) #if (DSD_CHANS_DAC > 0)
/* Make AudioHwConfig() implementation a little more user friendly in DSD mode...*/ /* Make AudioHwConfig() implementation a little more user friendly in DSD mode...*/
if(dsdMode == DSD_MODE_NATIVE) if(dsdMode == DSD_MODE_NATIVE)
{ {
curFreq *= 32; curFreq *= 32;
} }
else if(dsdMode == DSD_MODE_DOP) else if(dsdMode == DSD_MODE_DOP)
{ {
curFreq *= 16; curFreq *= 16;
} }
#endif #endif
/* Configure Clocking/CODEC/DAC/ADC for SampleFreq/MClk */ /* 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) if(!firstRun)
{ {
/* TODO wait for good mclk instead of delay */ /* TODO wait for good mclk instead of delay */
/* No delay for DFU modes */ /* 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 #if 0
/* User should ensure MCLK is stable in AudioHwConfig */ /* 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 */ /* Handshake back */
outct(c_mix_out, XS1_CT_END); outct(c_mix_out, XS1_CT_END);
} }
} }
firstRun = 0; firstRun = 0;
par par
{ {
#ifdef SPDIF #ifdef SPDIF
{ {
set_thread_fast_mode_on(); set_thread_fast_mode_on();
SpdifTransmit(p_spdif_tx, c_spdif_out); SpdifTransmit(p_spdif_tx, c_spdif_out);
} }
#endif #endif
{ {
#ifdef SPDIF #ifdef SPDIF
/* Communicate master clock and sample freq to S/PDIF thread */ /* Communicate master clock and sample freq to S/PDIF thread */
outuint(c_spdif_out, curSamFreq); outuint(c_spdif_out, curSamFreq);
outuint(c_spdif_out, mClk); outuint(c_spdif_out, mClk);
#endif #endif
{retVal1, retVal2} = deliver(c_mix_out, {retVal1, retVal2} = deliver(c_mix_out,
#ifdef SPDIF #ifdef SPDIF
c_spdif_out, c_spdif_out,
#else #else
null, null,
#endif #endif
divide, curSamFreq, c_dig_rx, c); divide, curSamFreq, c_dig_rx, c);
#if (DSD_CHANS_DAC != 0) #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 #endif
// Currently no more audio will happen after this point // 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); outct(c_mix_out, XS1_CT_END);
while (1) while (1)
{ {
{retVal1, curSamFreq} = dummy_deliver(c_mix_out); {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); outct(c_mix_out, XS1_CT_END);
break; 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... */ /* Notify S/PDIF thread of impending new freq... */
outct(c_spdif_out, XS1_CT_END); outct(c_spdif_out, XS1_CT_END);
#endif #endif
} }
} }

View File

@@ -4,7 +4,7 @@ void UserAudioStreamStop() __attribute__ ((weak));
void UserAudioStreamStop() void UserAudioStreamStop()
{ {
return; return;
} }
void UserAudioStreamStart() __attribute__ ((weak)); void UserAudioStreamStart() __attribute__ ((weak));
void UserAudioStreamStart() void UserAudioStreamStart()

View File

@@ -8,7 +8,7 @@
* \param c_adat_rx channel connect to ADAT receive thread * \param c_adat_rx channel connect to ADAT receive thread
* \param p port to output clock signal to drive external frequency synthesizer * \param p port to output clock signal to drive external frequency synthesizer
* \param c_audio channel connected to the audio() thread * \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 * clock
* \param c_clk_int channel connected to the decouple() thread for clock * \param c_clk_int channel connected to the decouple() thread for clock
interrupts interrupts

View File

@@ -61,7 +61,7 @@ static int channelContainsControlToken(chanend x)
static void outInterrupt(chanend c_interruptControl, int value) static void outInterrupt(chanend c_interruptControl, int value)
{ {
/* Non-blocking check for control token */ /* Non-blocking check for control token */
//if (channelContainsControlToken(c_interruptControl)) //if (channelContainsControlToken(c_interruptControl))
{ {
outuint(c_interruptControl, value); outuint(c_interruptControl, value);
outct(c_interruptControl, XS1_CT_END); outct(c_interruptControl, XS1_CT_END);
@@ -75,20 +75,20 @@ void VendorClockValidity(int valid);
#if defined(SPDIF_RX) || defined(ADAT_RX) #if defined(SPDIF_RX) || defined(ADAT_RX)
static inline void setClockValidity(chanend c_interruptControl, int clkIndex, int valid, int currentClkMode) static inline void setClockValidity(chanend c_interruptControl, int clkIndex, int valid, int currentClkMode)
{ {
if (clockValid[clkIndex] != valid) if (clockValid[clkIndex] != valid)
{ {
clockValid[clkIndex] = valid; clockValid[clkIndex] = valid;
outInterrupt(c_interruptControl, clockId[clkIndex]); outInterrupt(c_interruptControl, clockId[clkIndex]);
#ifdef CLOCK_VALIDITY_CALL #ifdef CLOCK_VALIDITY_CALL
#ifdef ADAT_RX #ifdef ADAT_RX
if (currentClkMode == CLOCK_ADAT && clkIndex == CLOCK_ADAT_INDEX) if (currentClkMode == CLOCK_ADAT && clkIndex == CLOCK_ADAT_INDEX)
{ {
VendorClockValidity(valid); VendorClockValidity(valid);
} }
#endif #endif
#ifdef SPDIF_RX #ifdef SPDIF_RX
if (currentClkMode == CLOCK_SPDIF && clkIndex == CLOCK_SPDIF_INDEX) if (currentClkMode == CLOCK_SPDIF && clkIndex == CLOCK_SPDIF_INDEX)
{ {
VendorClockValidity(valid); VendorClockValidity(valid);
} }
@@ -101,72 +101,72 @@ static inline void setClockValidity(chanend c_interruptControl, int clkIndex, in
/* Returns 1 for valid clock found else 0 */ /* 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; int diff = counter.samples - counter.savedSamples;
counter.savedSamples = counter.samples; counter.savedSamples = counter.samples;
/* Check for stable sample rate (with some small margin) */ /* 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++; counter.identicaldiffs++;
if (counter.identicaldiffs > 10) if (counter.identicaldiffs > 10)
{ {
/* Detect current sample rate (round to nearest) */ /* Detect current sample rate (round to nearest) */
int s = -1; int s = -1;
if (diff > 137 && diff < 157) if (diff > 137 && diff < 157)
{ {
s = 147; s = 147;
} }
else if (diff > 150 && diff < 170) else if (diff > 150 && diff < 170)
{ {
s = 160; s = 160;
} }
else if(diff > 284 && diff < 304) else if(diff > 284 && diff < 304)
{ {
s = 294; s = 294;
} }
else if (diff > 310 && diff < 330) else if (diff > 310 && diff < 330)
{ {
s = 320; s = 320;
} }
else if (diff > 578 && diff < 598) else if (diff > 578 && diff < 598)
{ {
s = 588; s = 588;
} }
else if (diff > 630 && diff < 650) else if (diff > 630 && diff < 650)
{ {
s = 640; s = 640;
} }
/* Check if we found a valid freq */ /* Check if we found a valid freq */
if (s != -1) if (s != -1)
{ {
/* Update expected samples per tick */ /* Update expected samples per tick */
counter.samplesPerTick = s; counter.samplesPerTick = s;
/* Update record of external clock source sample frequency */ /* Update record of external clock source sample frequency */
s *= 300; s *= 300;
if (clockFreq[clockIndex] != s)
if (clockFreq[clockIndex] != s)
{ {
clockFreq[clockIndex] = s; clockFreq[clockIndex] = s;
} }
return 1; return 1;
} }
else else
{ {
/* Not a valid frequency - Reset counter and find another run of samples */ /* Not a valid frequency - Reset counter and find another run of samples */
counter.identicaldiffs = 0; counter.identicaldiffs = 0;
} }
} }
} }
else else
{ {
counter.identicaldiffs = 0; counter.identicaldiffs = 0;
counter.lastDiff = diff; counter.lastDiff = diff;
@@ -177,7 +177,7 @@ static inline int validSamples(Counter &counter, int clockIndex)
#ifdef SPDIF_RX #ifdef SPDIF_RX
//:badParity //:badParity
/* Returns 1 for bad parity, else 0 */ /* Returns 1 for bad parity, else 0 */
static inline int badParity(unsigned x) static inline int badParity(unsigned x)
{ {
unsigned X = (x>>4); 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; int spdifReceivedTime;
unsigned tmp2; unsigned tmp2;
unsigned spdifLeft = 0; unsigned spdifLeft = 0;
#endif #endif
#ifdef ADAT_RX #ifdef ADAT_RX
/* ADAT buffer state */ /* 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; g_digData[i] = 0;
} }
/* Init clock unit state */ /* Init clock unit state */
#ifdef SPDIF_RX #ifdef SPDIF_RX
clockFreq[CLOCK_SPDIF_INDEX] = 0; clockFreq[CLOCK_SPDIF_INDEX] = 0;
clockValid[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; clockFreq[CLOCK_ADAT_INDEX] = 0;
clockInt[CLOCK_ADAT_INDEX] = 0; clockInt[CLOCK_ADAT_INDEX] = 0;
clockValid[CLOCK_ADAT_INDEX] = 0; clockValid[CLOCK_ADAT_INDEX] = 0;
clockId[CLOCK_ADAT_INDEX] = ID_CLKSRC_ADAT; clockId[CLOCK_ADAT_INDEX] = ID_CLKSRC_ADAT;
#endif #endif
#ifdef SPDIF_RX #ifdef SPDIF_RX
spdifCounters.receivedSamples = 0; spdifCounters.receivedSamples = 0;
spdifCounters.samples = 0; spdifCounters.samples = 0;
spdifCounters.savedSamples = 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; timeLastEdge = timeNextEdge;
timeNextClockDetection = timeNextEdge + (LOCAL_CLOCK_INCREMENT / 2); timeNextClockDetection = timeNextEdge + (LOCAL_CLOCK_INCREMENT / 2);
timeNextEdge += LOCAL_CLOCK_INCREMENT; timeNextEdge += LOCAL_CLOCK_INCREMENT;
#ifdef LEVEL_METER_LEDS #ifdef LEVEL_METER_LEDS
t_level :> levelTime; t_level :> levelTime;
levelTime+= LEVEL_UPDATE_RATE; levelTime+= LEVEL_UPDATE_RATE;
#endif #endif
#if defined(SPDIF_RX) || defined(ADAT_RX) #if defined(SPDIF_RX) || defined(ADAT_RX)
/* Fill channel */ /* Fill channel */
outuint(c_dig_rx, 1); outuint(c_dig_rx, 1);
#endif #endif
/* Initial ref clock output and get timestamp */ /* Initial ref clock output and get timestamp */
p <: pinVal @ pinTime; p <: pinVal @ pinTime;
pinTime += (unsigned short)(LOCAL_CLOCK_INCREMENT - (LOCAL_CLOCK_INCREMENT/2)); 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 #ifdef LEVEL_METER_LEDS
#warning Level metering enabled #warning Level metering enabled
case t_level when timerafter(levelTime) :> void: case t_level when timerafter(levelTime) :> void:
levelTime += LEVEL_UPDATE_RATE; levelTime += LEVEL_UPDATE_RATE;
/* Copy over level data and reset */ /* Copy over level data and reset */
for(int i = 0; i< NUM_USB_CHAN_IN; i++) 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]; //g_inputLevelData[i] = samples_to_host_inputs[i];
asm("ldw %0, %1[%2]":"=r"(tmp):"r"(samples_to_host_inputs),"r"(i)); asm("ldw %0, %1[%2]":"=r"(tmp):"r"(samples_to_host_inputs),"r"(i));
g_inputLevelData[i] = tmp; g_inputLevelData[i] = tmp;
//samples_to_host_inputs[i] = 0; //samples_to_host_inputs[i] = 0;
asm("stw %0, %1[%2]"::"r"(0),"r"(samples_to_host_inputs),"r"(i)); asm("stw %0, %1[%2]"::"r"(0),"r"(samples_to_host_inputs),"r"(i));
/* Guard against host polling slower than timer and missing peaks */ /* Guard against host polling slower than timer and missing peaks */
if(g_inputLevelData[i] > samples_to_host_inputs_buff[i]) 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): case inuint_byref(c_clk_ctl, tmp):
switch(tmp) switch(tmp)
{ {
case GET_SEL: case GET_SEL:
chkct(c_clk_ctl, XS1_CT_END); chkct(c_clk_ctl, XS1_CT_END);
/* Send back current clock mode */ /* Send back current clock mode */
outuint(c_clk_ctl, clkMode); outuint(c_clk_ctl, clkMode);
outct(c_clk_ctl, XS1_CT_END); outct(c_clk_ctl, XS1_CT_END);
break; break;
case SET_SEL: case SET_SEL:
/* Update clock mode */ /* Update clock mode */
tmp = inuint(c_clk_ctl); tmp = inuint(c_clk_ctl);
chkct(c_clk_ctl, XS1_CT_END); chkct(c_clk_ctl, XS1_CT_END);
if(tmp!=0) if(tmp!=0)
{ {
clkMode = tmp; clkMode = tmp;
@@ -378,7 +378,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan
break; break;
#endif #endif
#ifdef SPDIF_RX #ifdef SPDIF_RX
case CLOCK_SPDIF: case CLOCK_SPDIF:
VendorClockValidity(clockValid[CLOCK_SPDIF_INDEX]); VendorClockValidity(clockValid[CLOCK_SPDIF_INDEX]);
break; break;
#endif #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); tmp = inuint(c_clk_ctl);
chkct(c_clk_ctl, XS1_CT_END); chkct(c_clk_ctl, XS1_CT_END);
outuint(c_clk_ctl, clockValid[tmp]); outuint(c_clk_ctl, clockValid[tmp]);
outct(c_clk_ctl, XS1_CT_END); outct(c_clk_ctl, XS1_CT_END);
break; break;
case GET_FREQ: case GET_FREQ:
tmp = inuint(c_clk_ctl); tmp = inuint(c_clk_ctl);
chkct(c_clk_ctl, XS1_CT_END); chkct(c_clk_ctl, XS1_CT_END);
outuint(c_clk_ctl, clockFreq[tmp]); outuint(c_clk_ctl, clockFreq[tmp]);
outct(c_clk_ctl, XS1_CT_END); outct(c_clk_ctl, XS1_CT_END);
break; break;
case SET_SMUX: case SET_SMUX:
@@ -410,7 +410,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan
#endif #endif
chkct(c_clk_ctl, XS1_CT_END); chkct(c_clk_ctl, XS1_CT_END);
break; break;
default: default:
#ifdef VENDOR_AUDCORE_REQS #ifdef VENDOR_AUDCORE_REQS
if(VendorAudCoreReqs(tmp, c_clk_ctl)) 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"); printstrln("ERR: Bad req in clockgen\n");
break; break;
} }
break; break;
/* Generate local clock from timer */ /* Generate local clock from timer */
case t_local when timerafter(timeNextEdge) :> void: case t_local when timerafter(timeNextEdge) :> void:
/* Setup next local clock edge */ /* Setup next local clock edge */
pinTime += (short) LOCAL_CLOCK_INCREMENT; pinTime += (short) LOCAL_CLOCK_INCREMENT;
pinVal = !pinVal; 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 */ /* If we are in an external clock mode and this fire, then clock invalid */
#ifdef SPDIF_RX #ifdef SPDIF_RX
// if(clkMode == CLOCK_SPDIF) // if(clkMode == CLOCK_SPDIF)
{ {
/* We must have lost valid S/PDIF stream, reset counters, so we dont produce a double edge */ /* 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) #if defined(SPDIF_RX) || defined(ADAT_RX)
case t_external when timerafter(timeNextClockDetection) :> void: case t_external when timerafter(timeNextClockDetection) :> void:
timeNextClockDetection += (LOCAL_CLOCK_INCREMENT); timeNextClockDetection += (LOCAL_CLOCK_INCREMENT);
#ifdef SPDIF_RX #ifdef SPDIF_RX
tmp = spdifCounters.samplesPerTick; 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); tmp = validSamples(adatCounters, CLOCK_ADAT_INDEX);
setClockValidity(c_clk_int, CLOCK_ADAT_INDEX, tmp, clkMode); setClockValidity(c_clk_int, CLOCK_ADAT_INDEX, tmp, clkMode);
#endif #endif
break; break;
#endif #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 */ /* Check parity and ignore if bad */
if(badParity(tmp)) if(badParity(tmp))
continue; continue;
/* Get pre-amble */ /* Get pre-amble */
tmp2 = tmp & 0xF; tmp2 = tmp & 0xF;
switch(tmp2) switch(tmp2)
@@ -501,7 +501,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan
/* LEFT */ /* LEFT */
case FRAME_X: case FRAME_X:
case FRAME_Z: case FRAME_Z:
spdifLeft = tmp << 4; spdifLeft = tmp << 4;
break; 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) if(spdifSamps > MAX_SPDIF_SAMPLES-1)
{ {
spdifOverflow = 1; spdifOverflow = 1;
} }
/* Check for coming out of under flow */ /* Check for coming out of under flow */
if(spdifUnderflow && (spdifSamps >= (MAX_SPDIF_SAMPLES >> 1))) if(spdifUnderflow && (spdifSamps >= (MAX_SPDIF_SAMPLES >> 1)))
{ {
spdifUnderflow = 0; spdifUnderflow = 0;
} }
} }
break; 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]) if(clkMode == CLOCK_SPDIF && clockValid[CLOCK_SPDIF_INDEX])
{ {
spdifCounters.receivedSamples+=1; spdifCounters.receivedSamples+=1;
/* Inspect for if we need to produce an edge */ /* Inspect for if we need to produce an edge */
if((spdifCounters.receivedSamples >= spdifCounters.samplesPerTick)) if((spdifCounters.receivedSamples >= spdifCounters.samplesPerTick))
{ {
/* Check edge is about right... S/PDIF may have changed freq... */ /* Check edge is about right... S/PDIF may have changed freq... */
if(timeafter(spdifReceivedTime, (timeLastEdge + LOCAL_CLOCK_INCREMENT - LOCAL_CLOCK_MARGIN))) if(timeafter(spdifReceivedTime, (timeLastEdge + LOCAL_CLOCK_INCREMENT - LOCAL_CLOCK_MARGIN)))
{ {
/* Record edge time */ /* Record edge time */
timeLastEdge = spdifReceivedTime; timeLastEdge = spdifReceivedTime;
/* Setup for next edge */ /* Setup for next edge */
timeNextEdge = spdifReceivedTime + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN; timeNextEdge = spdifReceivedTime + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN;
/* Toggle edge */ /* Toggle edge */
p <: pinVal @ pinTime; p <: pinVal @ pinTime;
pinTime += (short) LOCAL_CLOCK_INCREMENT; 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; break;
#endif #endif
#ifdef ADAT_RX #ifdef ADAT_RX
/* receive sample from ADAT rx thread (streaming channel with CT_END) */ /* receive sample from ADAT rx thread (streaming channel with CT_END) */
case inuint_byref(c_adat_rx, tmp): 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 */ /* audio sample */
adatSamplesEver++; adatSamplesEver++;
adatFrame[adatChannel] = tmp; adatFrame[adatChannel] = tmp;
adatChannel++; adatChannel++;
if (adatChannel == 8) 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) if(adatChannel == 4 || adatChannel == 8)
{ {
adatCounters.samples += 1; adatCounters.samples += 1;
if (clkMode == CLOCK_ADAT && clockValid[CLOCK_ADAT_INDEX]) if (clkMode == CLOCK_ADAT && clockValid[CLOCK_ADAT_INDEX])
{ {
adatCounters.receivedSamples += 1; 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... */ /* Check edge is about right... S/PDIF may have changed freq... */
if (timeafter(adatReceivedTime, (timeLastEdge + LOCAL_CLOCK_INCREMENT - LOCAL_CLOCK_MARGIN))) if (timeafter(adatReceivedTime, (timeLastEdge + LOCAL_CLOCK_INCREMENT - LOCAL_CLOCK_MARGIN)))
{ {
/* Record edge time */ /* Record edge time */
timeLastEdge = adatReceivedTime; timeLastEdge = adatReceivedTime;
/* Setup for next edge */ /* Setup for next edge */
timeNextEdge = adatReceivedTime + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN; timeNextEdge = adatReceivedTime + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN;
/* Toggle edge */ /* Toggle edge */
p <: pinVal @ pinTime; p <: pinVal @ pinTime;
pinTime += LOCAL_CLOCK_INCREMENT; pinTime += LOCAL_CLOCK_INCREMENT;
@@ -686,7 +686,7 @@ void clockGen (streaming chanend c_spdif_rx, chanend c_adat_rx, out port p, chan
} }
else else
{ {
/* Read out samples from S/PDIF buffer and send... */ /* Read out samples from S/PDIF buffer and send... */
tmp = spdifSamples[spdifRd]; tmp = spdifSamples[spdifRd];
tmp2 = spdifSamples[spdifRd + 1]; 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 -= 2;
/* spdifSamps could go to -1 */ /* spdifSamps could go to -1 */
if(spdifSamps < 0) if(spdifSamps < 0)
{ {
/* We're out of S/PDIF samples, mark underflow condition */ /* 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; spdifOverflow = 0;
} }
} }
#endif #endif
#ifdef ADAT_RX #ifdef ADAT_RX
if (adatUnderflow) 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 */ /* TODO SMUX II mode */
/* read out samples from the ADAT buffer and send */ /* read out samples from the ADAT buffer and send */
/* always return 8 samples */ /* always return 8 samples */
if (smux) if (smux)
{ {
/* SMUX mode - 4 samples from fifo and 4 zero samples */ /* SMUX mode - 4 samples from fifo and 4 zero samples */
g_digData[2] = adatSamples[adatRd + 0]; g_digData[2] = adatSamples[adatRd + 0];
g_digData[3] = adatSamples[adatRd + 1]; g_digData[3] = adatSamples[adatRd + 1];
g_digData[4] = adatSamples[adatRd + 2]; g_digData[4] = adatSamples[adatRd + 2];
g_digData[5] = adatSamples[adatRd + 3]; g_digData[5] = adatSamples[adatRd + 3];
g_digData[6] = 0; g_digData[6] = 0;
g_digData[7] = 0; g_digData[7] = 0;
g_digData[8] = 0; g_digData[8] = 0;

View File

@@ -1,14 +1,14 @@
/** /**
* @file dbtable.h * @file dbtable.h
* @brief 128 entry + neg inf db table from -inf to 0xffffffff * @brief 128 entry + neg inf db table from -inf to 0xffffffff
* @author Ross Owen, XMOS Semiconductor * @author Ross Owen, XMOS Semiconductor
* @version 1.0 * @version 1.0
*/ */
#ifndef _DBTABLE_ #ifndef _DBTABLE_
#define _DBTABLE_ #define _DBTABLE_
static unsigned dbTable[129] = static unsigned dbTable[129] =
{ {
4294967295, /* 0 -> 0xffffffff */ 4294967295, /* 0 -> 0xffffffff */
3827893631, 3827893631,

View File

@@ -1,4 +1,4 @@
/** /**
* @brief Defines relating to device configuration and customisation. * @brief Defines relating to device configuration and customisation.
* @author Ross Owen, XMOS Limited * @author Ross Owen, XMOS Limited
*/ */
@@ -35,23 +35,23 @@
#else #else
#define NATIVE_DSD 1 /* Always enable Native DSD when DSD mode is enabled */ #define NATIVE_DSD 1 /* Always enable Native DSD when DSD mode is enabled */
#endif #endif
#else #else
#define DSD_CHANS_DAC 0 #define DSD_CHANS_DAC 0
#endif #endif
/* Max supported sample freq for device */ /* Max supported sample freq for device */
#ifndef MAX_FREQ #ifndef MAX_FREQ
#define MAX_FREQ (192000) #define MAX_FREQ (192000)
#endif #endif
/* Min supported sample freq for device */ /* Min supported sample freq for device */
#ifndef MIN_FREQ #ifndef MIN_FREQ
#define MIN_FREQ (44100) #define MIN_FREQ (44100)
#endif #endif
#if ((MCLK_44 % MIN_FREQ) == 0) #if ((MCLK_44 % MIN_FREQ) == 0)
#define MIN_FREQ_44 MIN_FREQ #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 #endif
#if ((MCLK_48 % MIN_FREQ) == 0) #if ((MCLK_48 % MIN_FREQ) == 0)
@@ -189,15 +189,15 @@
/* Default device sample frequency */ /* Default device sample frequency */
#ifndef DEFAULT_FREQ #ifndef DEFAULT_FREQ
#define DEFAULT_FREQ (MIN_FREQ) #define DEFAULT_FREQ (MIN_FREQ)
#endif #endif
/* Master clock defines (in Hz) */ /* Master clock defines (in Hz) */
#ifndef MCLK_441 #ifndef MCLK_441
#error MCLK_441 not defined #error MCLK_441 not defined
#endif #endif
#ifndef MCLK_48 #ifndef MCLK_48
#error MCLK_441 not defined #error MCLK_441 not defined
#endif #endif
@@ -209,19 +209,19 @@
#error Bad DEFAULT_MCLK_FREQ #error Bad DEFAULT_MCLK_FREQ
#endif #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) */ * Note, feedback always counts 128 SOFs (16ms @ HS, 128ms @ FS) */
#ifndef FEEDBACK_STABILITY_DELAY_HS #ifndef FEEDBACK_STABILITY_DELAY_HS
#define FEEDBACK_STABILITY_DELAY_HS (2000000) #define FEEDBACK_STABILITY_DELAY_HS (2000000)
#endif #endif
#ifndef FEEDBACK_STABILITY_DELAY_FS #ifndef FEEDBACK_STABILITY_DELAY_FS
#define FEEDBACK_STABILITY_DELAY_FS (20000000) #define FEEDBACK_STABILITY_DELAY_FS (20000000)
#endif #endif
/* Vendor String */ /* Vendor String */
#ifndef VENDOR_STR #ifndef VENDOR_STR
#define VENDOR_STR "XMOS" #define VENDOR_STR "XMOS"
#endif #endif
/* USB Vendor ID */ /* USB Vendor ID */
@@ -248,18 +248,18 @@
/* USB Product ID (PID) for Audio Class 1.0 mode */ /* USB Product ID (PID) for Audio Class 1.0 mode */
#if (AUDIO_CLASS==1) || defined(AUDIO_CLASS_FALLBACK) #if (AUDIO_CLASS==1) || defined(AUDIO_CLASS_FALLBACK)
#ifndef PID_AUDIO_1 #ifndef PID_AUDIO_1
#define PID_AUDIO_1 (0x0003) #define PID_AUDIO_1 (0x0003)
#endif #endif
#endif #endif
/* USB Product ID (PID) for Audio Class 2.0 mode */ /* USB Product ID (PID) for Audio Class 2.0 mode */
#ifndef PID_AUDIO_2 #ifndef PID_AUDIO_2
#define PID_AUDIO_2 (0x0002) #define PID_AUDIO_2 (0x0002)
#endif #endif
/* Device release number in BCD: 0xJJMN */ /* Device release number in BCD: 0xJJMN */
#define BCD_DEVICE_J 6 #define BCD_DEVICE_J 1
#define BCD_DEVICE_M 3 #define BCD_DEVICE_M 0
#define BCD_DEVICE_N 3 #define BCD_DEVICE_N 3
#ifndef BCD_DEVICE #ifndef BCD_DEVICE
@@ -269,7 +269,7 @@
/* Sample Sub-slot size (bytes) for High Speed. Default is 4 bytes */ /* Sample Sub-slot size (bytes) for High Speed. Default is 4 bytes */
#ifndef SAMPLE_SUBSLOT_SIZE_HS #ifndef SAMPLE_SUBSLOT_SIZE_HS
#define SAMPLE_SUBSLOT_SIZE_HS 4 #define SAMPLE_SUBSLOT_SIZE_HS 4
#endif #endif
#if (SAMPLE_SUBSLOT_SIZE_HS != 2) && (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_HS != 4) #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 #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 */ /* Sample Sub-slot size (bytes) for Full Speed. Default is 3 bytes */
#ifndef SAMPLE_SUBSLOT_SIZE_FS #ifndef SAMPLE_SUBSLOT_SIZE_FS
#define SAMPLE_SUBSLOT_SIZE_FS 3 #define SAMPLE_SUBSLOT_SIZE_FS 3
#endif #endif
#if (SAMPLE_SUBSLOT_SIZE_FS != 2) && (SAMPLE_SUBSLOT_SIZE_FS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 4) #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 #error Only SAMPLE_SUBSLOT_SIZE_FS 2, 3 or 4 supported
@@ -287,7 +287,7 @@
/* Sample bit resolution for High Speed. Default 24bit*/ /* Sample bit resolution for High Speed. Default 24bit*/
#ifndef SAMPLE_BIT_RESOLUTION_HS #ifndef SAMPLE_BIT_RESOLUTION_HS
#define SAMPLE_BIT_RESOLUTION_HS 24 #define SAMPLE_BIT_RESOLUTION_HS 24
#endif #endif
#if (SAMPLE_BIT_RESOLUTION_HS/8) > SAMPLE_SUBSLOT_SIZE_HS #if (SAMPLE_BIT_RESOLUTION_HS/8) > SAMPLE_SUBSLOT_SIZE_HS
#error SAMPLE_BIT_RESOLUTION_HS is too big for 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*/ /* Sample bit resolution for Full Speed. Default 24bit*/
#ifndef SAMPLE_BIT_RESOLUTION_FS #ifndef SAMPLE_BIT_RESOLUTION_FS
#define SAMPLE_BIT_RESOLUTION_FS 24 #define SAMPLE_BIT_RESOLUTION_FS 24
#endif #endif
#if (SAMPLE_BIT_RESOLUTION_FS/8) > SAMPLE_SUBSLOT_SIZE_FS #if (SAMPLE_BIT_RESOLUTION_FS/8) > SAMPLE_SUBSLOT_SIZE_FS
#error SAMPLE_BIT_RESOLUTION_FS is too big for SAMPLE_SUBSLOT_SIZE_FS #error SAMPLE_BIT_RESOLUTION_FS is too big for SAMPLE_SUBSLOT_SIZE_FS
@@ -372,7 +372,7 @@
#endif #endif
/* Define for number of audio interfaces (+1 for mandatory control interface) */ /* 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 */ /* Interface number defines */
#define INTERFACE_NUM_IAP (INPUT_INTERFACES+OUTPUT_INTERFACES+MIDI_INTERFACES+DFU_INTERFACES+1) #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 (EP_NUM_IN_IAP | 0x80)
#define EP_ADR_IN_IAP_INT (EP_NUM_IN_IAP_INT | 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_AUD EP_NUM_OUT_AUD
#define EP_ADR_OUT_MIDI EP_NUM_OUT_MIDI #define EP_ADR_OUT_MIDI EP_NUM_OUT_MIDI
#define EP_ADR_OUT_IAP EP_NUM_OUT_IAP #define EP_ADR_OUT_IAP EP_NUM_OUT_IAP
/* Endpoint count totals */ /* 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 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) #define AUDIO_STOP_FOR_DFU (0x12345678)
@@ -429,7 +429,7 @@
#define NUM_CLOCKS (3) #define NUM_CLOCKS (3)
#elif defined(SPDIF_RX) || defined(ADAT_RX) #elif defined(SPDIF_RX) || defined(ADAT_RX)
#define NUM_CLOCKS (2) #define NUM_CLOCKS (2)
#else #else
#define NUM_CLOCKS (1) #define NUM_CLOCKS (1)
#endif #endif
@@ -442,8 +442,8 @@
/* Audio Unit ID defines */ /* Audio Unit ID defines */
#define FU_USBIN 11 /* Feature Unit: USB Audio device -> host */ #define FU_USBIN 11 /* Feature Unit: USB Audio device -> host */
#define FU_USBOUT 10 /* Feature Unit: USB Audio host -> device*/ #define FU_USBOUT 10 /* Feature Unit: USB Audio host -> device*/
#define ID_IT_USB 2 /* Input terminal: USB streaming */ #define ID_IT_USB 2 /* Input terminal: USB streaming */
#define ID_IT_AUD 1 /* Input terminal: Analogue input */ #define ID_IT_AUD 1 /* Input terminal: Analogue input */
#define ID_OT_USB 22 /* Output terminal: USB streaming */ #define ID_OT_USB 22 /* Output terminal: USB streaming */
@@ -496,7 +496,7 @@
#ifndef MIN_MIXER_VOLUME #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 This is a signed 8.8 fixed point
number that must be strictly greater than -128 (0x8000) */ number that must be strictly greater than -128 (0x8000) */
/* Default min volume is -127db */ /* Default min volume is -127db */
@@ -504,7 +504,7 @@
#endif #endif
#ifndef MAX_MIXER_VOLUME #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. */ This is a signed 8.8 fixed point number. */
/* Default max volume is 0db */ /* Default max volume is 0db */
#define MAX_MIXER_VOLUME (0x0000) #define MAX_MIXER_VOLUME (0x0000)

View File

@@ -24,7 +24,7 @@ extern unsigned int multIn[NUM_USB_CHAN_IN + 1];
extern int interfaceAlt[]; extern int interfaceAlt[];
/* Global volume and mute tables */ /* Global volume and mute tables */
extern int volsOut[]; extern int volsOut[];
extern unsigned int mutesOut[]; extern unsigned int mutesOut[];
@@ -51,7 +51,7 @@ extern unsigned char mixSel[MIX_INPUTS];
/* Global var for current frequency, set to default freq */ /* Global var for current frequency, set to default freq */
unsigned int g_curSamFreq = DEFAULT_FREQ; unsigned int g_curSamFreq = DEFAULT_FREQ;
unsigned int g_curSamFreq48000Family = DEFAULT_FREQ % 48000 == 0; 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 */ /* 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) 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 */ /* Delay based on USB speed. Feedback takes longer to stabilise at FS */
void FeedbackStabilityDelay() void FeedbackStabilityDelay()
{ {
unsigned usbSpeed; unsigned usbSpeed;
timer t; timer t;
unsigned time; unsigned time;
unsigned delay; unsigned delay;
asm("ldw %0, dp[g_curUsbSpeed]" : "=r" (usbSpeed) :); asm("ldw %0, dp[g_curUsbSpeed]" : "=r" (usbSpeed) :);
if (usbSpeed == XUD_SPEED_HS) if (usbSpeed == XUD_SPEED_HS)
{ {
delay = FEEDBACK_STABILITY_DELAY_HS; delay = FEEDBACK_STABILITY_DELAY_HS;
@@ -138,7 +138,7 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl)
case FU_USBOUT: case FU_USBOUT:
{ {
unsigned master_vol = volsOut[0] == 0x8000 ? 0 : db_to_mult(volsOut[0], 8, 29); 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++) 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 */ /* 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]; x = longMul(master_vol, vol, 29) * !mutesOut[0] * !mutesOut[i];
#ifdef OUT_VOLUME_IN_MIXER #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, i-1);
outuint(c_mix_ctl, x); outuint(c_mix_ctl, x);
outct(c_mix_ctl, XS1_CT_END); outct(c_mix_ctl, XS1_CT_END);
@@ -165,7 +165,7 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl)
case FU_USBIN: case FU_USBIN:
{ {
unsigned master_vol = volsIn[0] == 0x8000 ? 0 : db_to_mult(volsIn[0], 8, 29); 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 */ /* Calc multipliers with 29 fractional bits from a db value with 8 fractional bits */
/* 0x8000 is a special value representing -inf (i.e. mute) */ /* 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 #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, i-1); outuint(c_mix_ctl, i-1);
outuint(c_mix_ctl, x); outuint(c_mix_ctl, x);
outct(c_mix_ctl, XS1_CT_END); outct(c_mix_ctl, XS1_CT_END);
@@ -191,10 +191,10 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl)
default: default:
break; break;
} }
} }
static void updateVol(int unitID, int channel, chanend ?c_mix_ctl) static void updateVol(int unitID, int channel, chanend ?c_mix_ctl)
{ {
int x; int x;
#ifndef OUT_VOLUME_IN_MIXER #ifndef OUT_VOLUME_IN_MIXER
xc_ptr p_multOut = array_to_xc_ptr(multOut); 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 ) switch( unitID )
{ {
case FU_USBOUT: case FU_USBOUT:
{ {
/* Calc multipliers with 29 fractional bits from a db value with 8 fractional bits */ /* Calc multipliers with 29 fractional bits from a db value with 8 fractional bits */
/* 0x8000 is a special value representing -inf (i.e. mute) */ /* 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 #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, channel-1); outuint(c_mix_ctl, channel-1);
outuint(c_mix_ctl, x); outuint(c_mix_ctl, x);
outct(c_mix_ctl, XS1_CT_END); outct(c_mix_ctl, XS1_CT_END);
@@ -233,7 +233,7 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl)
#endif #endif
break; break;
} }
case FU_USBIN: case FU_USBIN:
{ {
/* Calc multipliers with 29 fractional bits from a db value with 8 fractional bits */ /* Calc multipliers with 29 fractional bits from a db value with 8 fractional bits */
/* 0x8000 is a special value representing -inf (i.e. mute) */ /* 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]; x = longMul(master_vol, vol, 29) * !mutesIn[0] * !mutesIn[channel];
#ifdef IN_VOLUME_IN_MIXER #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, channel-1);
outuint(c_mix_ctl, x); outuint(c_mix_ctl, x);
outct(c_mix_ctl, XS1_CT_END); outct(c_mix_ctl, XS1_CT_END);
} }
#else #else
asm("stw %0, %1[%2]"::"r"(x),"r"(p_multIn),"r"(channel-1)); asm("stw %0, %1[%2]"::"r"(x),"r"(p_multIn),"r"(channel-1));
#endif #endif
break; break;
} }
} }
} }
} }
/* Handles the audio class specific requests /* Handles the audio class specific requests
* returns: 0 if request dealt with successfully without error, * returns: 0 if request dealt with successfully without error,
* <0 for device reset * <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 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 */ /* Inspect request, NOTE: these are class specific requests */
switch( sp.bRequest ) switch( sp.bRequest )
{ {
/* CUR Request*/ /* CUR Request*/
case CUR: case CUR:
{ {
/* Extract unitID from wIndex */ /* Extract unitID from wIndex */
unitID = sp.wIndex >> 8; 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 ) switch( unitID )
{ {
/* Clock Unit(s) */ /* Clock Unit(s) */
case ID_CLKSRC_INT: case ID_CLKSRC_INT:
case ID_CLKSRC_EXT: case ID_CLKSRC_EXT:
case ID_CLKSRC_ADAT: case ID_CLKSRC_ADAT:
{ {
/* Check Control selector (CS) */ /* Check Control selector (CS) */
switch( sp.wValue >> 8 ) switch( sp.wValue >> 8 )
{ {
/* Sample Frequency control */ /* Sample Frequency control */
case CS_SAM_FREQ_CONTROL: case CS_SAM_FREQ_CONTROL:
{ {
/* Direction: Host-to-device */ /* 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*/ /* Get OUT data with Sample Rate into buffer*/
datalength = XUD_GetBuffer(ep0_out, buffer); datalength = XUD_GetBuffer(ep0_out, buffer);
/* Check for reset/suspend */ /* Check for reset/suspend */
if(datalength < 0) if(datalength < 0)
{ {
return datalength; return datalength;
} }
if(datalength == 4) if(datalength == 4)
{ {
/* Re-construct Sample Freq */ /* 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) */ /* Instruct audio thread to change sample freq (if change required) */
if(i_tmp != g_curSamFreq) 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)); setG_curSamFreqMultiplier(g_curSamFreq/(i_tmp/512));
outuint(c_audioControl, SET_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 */ /* Wait for handshake back - i.e. PLL locked and clocks okay */
chkct(c_audioControl, XS1_CT_END); chkct(c_audioControl, XS1_CT_END);
} }
/* Allow time for our feedback to stabilise*/ /* Allow time for our feedback to stabilise*/
FeedbackStabilityDelay(); FeedbackStabilityDelay();
} }
/* Send 0 Length as status stage */ /* Send 0 Length as status stage */
XUD_DoSetRequestStatus(ep0_in); XUD_DoSetRequestStatus(ep0_in);
} }
/* Direction: Device-to-host: Send Current Sample Freq */ /* Direction: Device-to-host: Send Current Sample Freq */
else else
{ {
switch(unitID) switch(unitID)
{ {
case ID_CLKSRC_EXT: case ID_CLKSRC_EXT:
case ID_CLKSRC_ADAT: case ID_CLKSRC_ADAT:
#ifdef REPORT_SPDIF_FREQ #ifdef REPORT_SPDIF_FREQ
/* Interogate clockgen thread for 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, GET_FREQ);
outuint(c_clk_ctl, CLOCK_SPDIF_INDEX); 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; (buffer, unsigned[])[0] = g_curSamFreq;
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 4, sp.wLength ); return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 4, sp.wLength );
} }
break; break;
#endif #endif
case ID_CLKSRC_INT: case ID_CLKSRC_INT:
/* Always report our current operating frequency */ /* Always report our current operating frequency */
(buffer, unsigned[])[0] = g_curSamFreq; (buffer, unsigned[])[0] = g_curSamFreq;
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 4, sp.wLength ); return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 4, sp.wLength );
break; break;
default: default:
/* Unknown Unit ID in Sample Frequency Control Request: unitID */ /* Unknown Unit ID in Sample Frequency Control Request: unitID */
break; break;
} }
} }
break; break;
} }
/* Clock Valid Control */ /* Clock Valid Control */
case CS_CLOCK_VALID_CONTROL: case CS_CLOCK_VALID_CONTROL:
{ {
switch(unitID) switch(unitID)
{ {
case ID_CLKSRC_INT: case ID_CLKSRC_INT:
/* Internal clock always valid */ /* Internal clock always valid */
buffer[0] = 1; buffer[0] = 1;
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 1, sp.wLength); return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 1, sp.wLength);
break; break;
case ID_CLKSRC_EXT: case ID_CLKSRC_EXT:
/* Interogate clockgen thread for validity */ /* 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, GET_VALID);
outuint(c_clk_ctl, CLOCK_SPDIF_INDEX); 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: case ID_CLKSRC_ADAT:
if (!isnull(c_clk_ctl)) if (!isnull(c_clk_ctl))
{ {
outuint(c_clk_ctl, GET_VALID); outuint(c_clk_ctl, GET_VALID);
outuint(c_clk_ctl, CLOCK_ADAT_INDEX); 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); return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 1, sp.wLength);
} }
break; break;
default: default:
//Unknown Unit ID in Clock Valid Control Request //Unknown Unit ID in Clock Valid Control Request
break; break;
@@ -436,28 +436,28 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
default: default:
//Unknown Control Selector for Clock Unit: sp.wValue >> 8 //Unknown Control Selector for Clock Unit: sp.wValue >> 8
break; break;
} }
break; /* Clock Unit IDs */ break; /* Clock Unit IDs */
} }
/* Clock Selector Unit(s) */ /* 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 */ /* 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); datalength = XUD_GetBuffer(ep0_out, buffer);
if(datalength < 0) if(datalength < 0)
return datalength; return datalength;
/* Check for correct datalength for clock sel */ /* 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, SET_SEL);
outuint(c_clk_ctl, buffer[0]); 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 */ /* Send 0 Length as status stage */
return XUD_DoSetRequestStatus(ep0_in); return XUD_DoSetRequestStatus(ep0_in);
} }
} }
else else
{ {
/* Direction: Device-to-host: Send Current Selection */ /* Direction: Device-to-host: Send Current Selection */
buffer[0] = 1; buffer[0] = 1;
if (!isnull(c_clk_ctl)) if (!isnull(c_clk_ctl))
{ {
outuint(c_clk_ctl, GET_SEL); outuint(c_clk_ctl, GET_SEL);
outct(c_clk_ctl, XS1_CT_END); 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); chkct(c_clk_ctl, XS1_CT_END);
} }
return XUD_DoGetRequest( ep0_out, ep0_in, buffer, 1, sp.wLength ); return XUD_DoGetRequest( ep0_out, ep0_in, buffer, 1, sp.wLength );
} }
} }
break; break;
} }
/* Feature Units */ /* Feature Units */
case FU_USBOUT: case FU_USBOUT:
case FU_USBIN: case FU_USBIN:
/* Inspect Control Selector (CS) */ /* Inspect Control Selector (CS) */
switch(sp.wValue >> 8) switch(sp.wValue >> 8)
{ {
case FU_VOLUME_CONTROL: case FU_VOLUME_CONTROL:
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D)
{ {
/* Expect OUT here (with volume) */ /* Expect OUT here (with volume) */
loop = XUD_GetBuffer(ep0_out, buffer); loop = XUD_GetBuffer(ep0_out, buffer);
/* Check for reset */ /* Check for reset */
if(loop < 0) if(loop < 0)
return loop; return loop;
if(unitID == FU_USBOUT) 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); volsOut[ sp.wValue&0xff ] = buffer[0] | (((int) (signed char) buffer[1]) << 8);
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl ); updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl );
return XUD_DoSetRequestStatus(ep0_in); 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 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); volsIn[ sp.wValue&0xff ] = buffer[0] | (((int) (signed char) buffer[1]) << 8);
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl ); updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl );
return XUD_DoSetRequestStatus(ep0_in); 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(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[0] = volsOut[ sp.wValue&0xff ];
buffer[1] = volsOut[ sp.wValue&0xff ] >> 8; 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 else
{ {
if ((sp.wValue & 0xff) <= NUM_USB_CHAN_IN) if ((sp.wValue & 0xff) <= NUM_USB_CHAN_IN)
{ {
buffer[0] = volsIn[ sp.wValue&0xff ]; buffer[0] = volsIn[ sp.wValue&0xff ];
buffer[1] = volsIn[ sp.wValue&0xff ] >> 8; 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 */ break; /* FU_VOLUME_CONTROL */
case FU_MUTE_CONTROL: case FU_MUTE_CONTROL:
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D)
{ {
/* Expect OUT here with mute */ /* Expect OUT here with mute */
loop = XUD_GetBuffer(ep0_out, buffer); 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 (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]; mutesOut[sp.wValue & 0xff] = buffer[0];
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl); updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl);
return XUD_DoSetRequestStatus(ep0_in); 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(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]; 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 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) if((sp.wValue & 0xff) <= NUM_USB_CHAN_IN)
{ {
buffer[0] = mutesIn[ sp.wValue&0xff ]; 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; break;
default: default:
// Unknown Control Selector for FU // Unknown Control Selector for FU
break; break;
} }
break; /* FU_USBIN */ break; /* FU_USBIN */
#if defined(MIXER) && (MAX_MIX_COUNT > 0) #if defined(MIXER) && (MAX_MIX_COUNT > 0)
case ID_XU_OUT: 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; 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, SET_SAMPLES_TO_DEVICE_MAP);
outuint(c_mix_ctl, c); 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; 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, SET_SAMPLES_TO_HOST_MAP);
outuint(c_mix_ctl, c); 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 */ int cn = sp.wValue & 0xff; /* Channel number */
/* Check for Get or Set */ /* 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); datalength = XUD_GetBuffer(ep0_out, buffer);
/* Check for reset */ /* Check for reset */
if(datalength < 0) if(datalength < 0)
return datalength; return datalength;
if(datalength > 0) if(datalength > 0)
{ {
/* cn bounds check for safety..*/ /* cn bounds check for safety..*/
if(cn < MIX_INPUTS) if(cn < MIX_INPUTS)
{ {
if(cs == CS_XU_MIXSEL) 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, cn); /* Mixer input */
outuint(c_mix_ctl, (int) mixSel[cn]); /* Source */ outuint(c_mix_ctl, (int) mixSel[cn]); /* Source */
outct(c_mix_ctl, XS1_CT_END); outct(c_mix_ctl, XS1_CT_END);
} }
return XUD_DoSetRequestStatus(ep0_in); 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 else
{ {
/* Direction: Device-to-Host (GET) */ /* Direction: Device-to-Host (GET) */
buffer[0] = 0; buffer[0] = 0;
/* Channel Number bounds check for safety */ /* Channel Number bounds check for safety */
if(cn < MIX_INPUTS) 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; break;
} }
case ID_MIXER_1: case ID_MIXER_1:
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_OUT) /* Direction: Host-to-device */ if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_OUT) /* Direction: Host-to-device */
{ {
unsigned volume = 0; unsigned volume = 0;
/* Expect OUT here with mute */ /* Expect OUT here with mute */
loop = XUD_GetBuffer(ep0_out, buffer); loop = XUD_GetBuffer(ep0_out, buffer);
if(loop < 0) if(loop < 0)
return loop; return loop;
mixer1Weights[sp.wValue & 0xff] = buffer[0] | buffer[1] << 8; mixer1Weights[sp.wValue & 0xff] = buffer[0] | buffer[1] << 8;
if (mixer1Weights[sp.wValue & 0xff] == 0x8000) if (mixer1Weights[sp.wValue & 0xff] == 0x8000)
{ {
volume = 0; 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, SET_MIX_MULT);
outuint(c_mix_ctl, (sp.wValue & 0xff) % 8); outuint(c_mix_ctl, (sp.wValue & 0xff) % 8);
outuint(c_mix_ctl, (sp.wValue & 0xff) / 8); outuint(c_mix_ctl, (sp.wValue & 0xff) / 8);
outuint(c_mix_ctl, volume); 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 */ /* 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[0] = weight & 0xff;
buffer[1] = (weight >> 8) & 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; break;
#endif #endif
default: default:
/* We dont have a unit with this ID! */ /* We dont have a unit with this ID! */
break; break;
} /* switch(sp.wIndex >> 8) i.e Unit ID */ } /* switch(sp.wIndex >> 8) i.e Unit ID */
break; break;
} }
case RANGE: case RANGE:
{ {
unitID = sp.wIndex >> 8; unitID = sp.wIndex >> 8;
switch( unitID ) switch( unitID )
{ {
/* Clock Source Units */ /* Clock Source Units */
case ID_CLKSRC_EXT: case ID_CLKSRC_EXT:
case ID_CLKSRC_ADAT: case ID_CLKSRC_ADAT:
case ID_CLKSRC_INT: case ID_CLKSRC_INT:
/* Control Selector (CS) */ /* Control Selector (CS) */
switch( sp.wValue >> 8 ) switch( sp.wValue >> 8 )
{ {
case CS_SAM_FREQ_CONTROL: case CS_SAM_FREQ_CONTROL:
/* Currently always return all freqs for all clocks */ /* Currently always return all freqs for all clocks */
{ {
int num_freqs = 0; 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; unsigned maxFreq = MAX_FREQ;
#if defined (FULL_SPEED_AUDIO_2) #if defined (FULL_SPEED_AUDIO_2)
unsigned usbSpeed; unsigned usbSpeed;
asm("ldw %0, dp[g_curUsbSpeed]" : "=r" (usbSpeed) :); asm("ldw %0, dp[g_curUsbSpeed]" : "=r" (usbSpeed) :);
if (usbSpeed == XUD_SPEED_FS) if (usbSpeed == XUD_SPEED_FS)
{ {
maxFreq = MAX_FREQ_A1; maxFreq = MAX_FREQ_A1;
} }
#endif #endif
while(1) while(1)
{ {
if((currentFreq44 <= maxFreq) && (currentFreq44 >= MIN_FREQ)) 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); 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; break;
default: default:
//Unknown Control Selector in Clock Source Range Request //Unknown Control Selector in Clock Source Range Request
break; break;
} }
break; break;
/* Feature Units */ /* Feature Units */
case FU_USBIN: /* USB Data into Device */ case FU_USBIN: /* USB Data into Device */
case FU_USBOUT: /* USB Data from Device */ case FU_USBOUT: /* USB Data from Device */
/* Control Selector (CS) */ /* Control Selector (CS) */
switch( sp.wValue >> 8 ) switch( sp.wValue >> 8 )
{ {
/* Volume control, send back same range for all channels (i.e. ignore CN) */ /* 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, 0, 1);
storeShort(buffer, 2, MIN_VOLUME); storeShort(buffer, 2, MIN_VOLUME);
storeShort(buffer, 4, MAX_VOLUME); storeShort(buffer, 4, MAX_VOLUME);
storeShort(buffer, 6, VOLUME_RES); storeShort(buffer, 6, VOLUME_RES);
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; break;
default: default:
/* Unknown control selector for FU */ /* Unknown control selector for FU */
break; break;
@@ -887,92 +887,92 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
/* Mixer Unit */ /* Mixer Unit */
case ID_MIXER_1: case ID_MIXER_1:
storeShort(buffer, 0, 1); storeShort(buffer, 0, 1);
storeShort(buffer, 2, MIN_MIXER_VOLUME); storeShort(buffer, 2, MIN_MIXER_VOLUME);
storeShort(buffer, 4, MAX_MIXER_VOLUME); storeShort(buffer, 4, MAX_MIXER_VOLUME);
storeShort(buffer, 6, VOLUME_RES_MIXER); storeShort(buffer, 6, VOLUME_RES_MIXER);
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; break;
#endif #endif
default: default:
/* Unknown Unit ID in Range Request selector for FU */ /* Unknown Unit ID in Range Request selector for FU */
break; break;
} }
break; /* case: RANGE */ 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) */ case MEM: /* Memory Requests (5.2.7.1) */
unitID = sp.wIndex >> 8; unitID = sp.wIndex >> 8;
switch( unitID ) switch( unitID )
{ {
case ID_MIXER_1: 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; int length = 0;
/* Device-to-Host (GET) */ /* Device-to-Host (GET) */
switch(sp.wValue) /* offset */ switch(sp.wValue) /* offset */
{ {
case 0: /* Input levels */ case 0: /* Input levels */
length = (NUM_USB_CHAN_IN + NUM_USB_CHAN_OUT) * 2; /* 2 bytes per chan */ 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++) for(int i = 0; i < (NUM_USB_CHAN_IN + NUM_USB_CHAN_OUT); i++)
{ {
/* Get the level and truncate to 16-bit */ /* 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, GET_INPUT_LEVELS);
outuint(c_mix_ctl, (i - NUM_USB_CHAN_IN)); outuint(c_mix_ctl, (i - NUM_USB_CHAN_IN));
outct(c_mix_ctl, XS1_CT_END); outct(c_mix_ctl, XS1_CT_END);
storeShort(buffer, i*2, (inuint(c_mix_ctl)>>15)); storeShort(buffer, i*2, (inuint(c_mix_ctl)>>15));
chkct(c_mix_ctl, XS1_CT_END); chkct(c_mix_ctl, XS1_CT_END);
} }
else else
{ {
storeShort(buffer, i*2, 0); 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, GET_STREAM_LEVELS);
outuint(c_mix_ctl, (i - NUM_USB_CHAN_IN)); outuint(c_mix_ctl, (i - NUM_USB_CHAN_IN));
outct(c_mix_ctl, XS1_CT_END); outct(c_mix_ctl, XS1_CT_END);
storeShort(buffer, i*2, (inuint(c_mix_ctl) >> 15)); storeShort(buffer, i*2, (inuint(c_mix_ctl) >> 15));
chkct(c_mix_ctl, XS1_CT_END); chkct(c_mix_ctl, XS1_CT_END);
} }
else else
{ {
storeShort(buffer, i*2, 0); storeShort(buffer, i*2, 0);
} }
} }
} }
break; break;
case 1: /* Mixer Output levels */ 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++) 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, GET_OUTPUT_LEVELS);
outuint(c_mix_ctl, i); outuint(c_mix_ctl, i);
outct(c_mix_ctl, XS1_CT_END); outct(c_mix_ctl, XS1_CT_END);
storeShort(buffer, i*2, (inuint(c_mix_ctl) >> 15)); storeShort(buffer, i*2, (inuint(c_mix_ctl) >> 15));
chkct(c_mix_ctl, XS1_CT_END); chkct(c_mix_ctl, XS1_CT_END);
} }
else else
{ {
storeShort(buffer, i*2, 0); 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) 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: /* At this point we know:
* bmRequestType.Recipient = Endpoint * bmRequestType.Recipient = Endpoint
* bmRequestType.Type = Class * bmRequestType.Type = Class
* endpoint (wIndex & 0xff) is 0x01 or 0x82 * endpoint (wIndex & 0xff) is 0x01 or 0x82
*/ */
int retVal = 1; int retVal = 1;
unsigned char buffer[1024]; unsigned char buffer[1024];
/* Host to Device */ /* Host to Device */
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) 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 */ /* Check Control Selector */
unsigned short controlSelector = sp.wValue>>8; unsigned short controlSelector = sp.wValue>>8;
retVal = XUD_GetBuffer(ep0_out, buffer); retVal = XUD_GetBuffer(ep0_out, buffer);
/* Inspect for reset */ /* Inspect for reset */
if(retVal < 0) if(retVal < 0)
return retVal; return retVal;
if(controlSelector == SAMPLING_FREQ_CONTROL) if(controlSelector == SAMPLING_FREQ_CONTROL)
{ {
/* Expect length 3 for sample rate */ /* Expect length 3 for sample rate */
if((sp.wLength == 3)&&(retVal == 3)) if((sp.wLength == 3)&&(retVal == 3))
{ {
/* Recontruct sample-freq */ /* Recontruct sample-freq */
int i_tmp = buffer[0] | (buffer [1] << 8) | (buffer[2] << 16); int i_tmp = buffer[0] | (buffer [1] << 8) | (buffer[2] << 16);
if(i_tmp != g_curSamFreq) if(i_tmp != g_curSamFreq)
{ {
int curSamFreq44100Family; 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. */ * when under stress. Lets double check it here and ignore if not valid. */
g_curSamFreq48000Family = i_tmp % 48000 == 0; g_curSamFreq48000Family = i_tmp % 48000 == 0;
curSamFreq44100Family = i_tmp % 44100 == 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; i_tmp = MCLK_441;
} }
//setG_curSamFreqMultiplier(g_curSamFreq/(i_tmp/512)); //setG_curSamFreqMultiplier(g_curSamFreq/(i_tmp/512));
setG_curSamFreqMultiplier((g_curSamFreq*512)/i_tmp); setG_curSamFreqMultiplier((g_curSamFreq*512)/i_tmp);
/* Instruct audio thread to change sample freq */ /* Instruct audio thread to change sample freq */
outuint(c_audioControl, SET_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 */ /* Wait for handshake back - i.e. pll locked and clocks okay */
chkct(c_audioControl, XS1_CT_END); chkct(c_audioControl, XS1_CT_END);
/* Allow time for the change - feedback to stabilise */ /* Allow time for the change - feedback to stabilise */
FeedbackStabilityDelay(); FeedbackStabilityDelay();
} }
@@ -1111,9 +1111,9 @@ int AudioClassRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
/* Inspect for reset */ /* Inspect for reset */
if(loop < 0) if(loop < 0)
return loop; return loop;
unitID = sp.wIndex >> 8; unitID = sp.wIndex >> 8;
if (unitID == FU_USBOUT) if (unitID == FU_USBOUT)
{ {
switch ((sp.wValue>>8) & 0xff) 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) switch ((sp.wValue>>8) & 0xff)
{ {
case FU_VOLUME_CONTROL: case FU_VOLUME_CONTROL:
{ {
buffer[0] = volsOut[ sp.wValue&0xff ]; buffer[0] = volsOut[ sp.wValue&0xff ];
buffer[1] = volsOut[ sp.wValue&0xff ] >> 8; 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);
break; break;
} }
case FU_MUTE_CONTROL: case FU_MUTE_CONTROL:
{ {
buffer[0] = mutesOut[ sp.wValue & 0xff ]; buffer[0] = mutesOut[ sp.wValue & 0xff ];
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 1, sp.wLength); return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 1, sp.wLength);
break; break;
} }
} }
} }
else if (unitID == FU_USBIN) else if (unitID == FU_USBIN)
{ {
switch ((sp.wValue>>8) & 0xff) switch ((sp.wValue>>8) & 0xff)
{ {
case FU_VOLUME_CONTROL: case FU_VOLUME_CONTROL:
{ {
buffer[0] = volsIn[ sp.wValue&0xff ]; buffer[0] = volsIn[ sp.wValue&0xff ];
buffer[1] = volsIn[ sp.wValue&0xff ] >> 8; 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);
} }
case FU_MUTE_CONTROL: case FU_MUTE_CONTROL:
{ {
buffer[0] = mutesIn[ sp.wValue & 0xff ]; buffer[0] = mutesIn[ sp.wValue & 0xff ];
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 1, sp.wLength); return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 1, sp.wLength);
} }
} }
} }
break; break;
} }
case UAC_B_REQ_GET_MIN: case UAC_B_REQ_GET_MIN:
buffer[0] = (MIN_MIXER_VOLUME & 0xff); buffer[0] = (MIN_MIXER_VOLUME & 0xff);
buffer[1] = (MIN_MIXER_VOLUME >> 8); buffer[1] = (MIN_MIXER_VOLUME >> 8);
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength); return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength);
case UAC_B_REQ_GET_MAX: case UAC_B_REQ_GET_MAX:
buffer[0] = (MAX_MIXER_VOLUME & 0xff); buffer[0] = (MAX_MIXER_VOLUME & 0xff);
buffer[1] = (MAX_MIXER_VOLUME >> 8); buffer[1] = (MAX_MIXER_VOLUME >> 8);
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength); return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength);
case UAC_B_REQ_GET_RES: case UAC_B_REQ_GET_RES:
buffer[0] = (VOLUME_RES_MIXER & 0xff); buffer[0] = (VOLUME_RES_MIXER & 0xff);
buffer[1] = (VOLUME_RES_MIXER >> 8); buffer[1] = (VOLUME_RES_MIXER >> 8);

View File

@@ -8,7 +8,7 @@
Parameters: Parameters:
db - The db value to convert. 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. result_frac_bits - The number of required fractional bits in the result.
Returns: Returns:

View File

@@ -21,7 +21,7 @@ static unsigned coef[14] = {2407, 13778, 64588, 308051, 1346110, 5261991, 182775
Parameters: Parameters:
db - The db value to convert. 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. result_frac_bits - The number of required fractional bits in the result.
Returns: 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)-1); unsigned mask = ~((1<<DB_CALC_PREC)-1);
/* Make sure we get 0db bang on */ /* Make sure we get 0db bang on */
if (db == 0) if (db == 0)
return (1 << result_frac_bits); return (1 << result_frac_bits);
/* First scale the decibal value to the required precision and divide by 10 /* First scale the decibal value to the required precision and divide by 10
We scale to DB_CALC_PREC - 4 before the division with to make sure we don't overflow */ We scale to DB_CALC_PREC - 4 before the division with to make sure we don't overflow */
db = db << (DB_CALC_PREC - 4 - 1 - db_frac_bits); db = db << (DB_CALC_PREC - 4 - 1 - db_frac_bits);
db = db / 10; db = db / 10;
db = db << 4; db = db << 4;
/* Extract the integer part of the exponent and calculate the integer power */ /* Extract the integer part of the exponent and calculate the integer power */
/* This could have been done a bit more efficiently by extracting the largest multiple log_10(2) /* This could have been done a bit more efficiently by extracting the largest multiple log_10(2)
and then calculating a power of 2 (with the polynomial calc in the range [-log_10(2),log_10(2)]. and then calculating a power of 2 (with the polynomial calc in the range [-log_10(2),log_10(2)].
But we have something that works here and ultra-fast performance is not a requirement */ But we have something that works here and ultra-fast performance is not a requirement */
if (db < 0) { if (db < 0) {
intpart = ((-db) & mask); intpart = ((-db) & mask);
db = db + intpart; db = db + intpart;
intpart = intpart >> DB_CALC_PREC; intpart = intpart >> DB_CALC_PREC;
if (intpart) { if (intpart) {
@@ -65,7 +65,7 @@ unsigned db_to_mult(int db, int db_frac_bits, int result_frac_bits)
} }
else { else {
intpart = (db & mask); intpart = (db & mask);
db = db - intpart; db = db - intpart;
intpart = intpart >> DB_CALC_PREC; intpart = intpart >> DB_CALC_PREC;
if (intpart) { if (intpart) {
val0 = 1 << DB_CALC_PREC; 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 = (hi << (32-DB_CALC_PREC)) | (lo >> DB_CALC_PREC);
val += coef[i] >> (COEF_PREC - DB_CALC_PREC); val += coef[i] >> (COEF_PREC - DB_CALC_PREC);
} }
/* Finally multiply by the integer power (if there was an integer part) */ /* Finally multiply by the integer power (if there was an integer part) */
if (val0) { if (val0) {
int hi=0; int hi=0;
unsigned lo=0; unsigned lo=0;
{hi, lo} = macs(val0,val,hi,lo); {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 */ /* We now have the result, just need to scale it to the required precision */
ret = val; ret = val;
if (result_frac_bits > DB_CALC_PREC) { if (result_frac_bits > DB_CALC_PREC) {
return ret<<(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() { 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 */ Should give a value just under 0x80000 */
printhexln(db_to_mult(9,0,16)); printhexln(db_to_mult(9,0,16));

File diff suppressed because it is too large Load Diff

View File

@@ -2,12 +2,12 @@
#ifndef _ENDPOINT0_H_ #ifndef _ENDPOINT0_H_
#define _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``. * 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_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_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.) * audio (sample rate changes etc.)
* \param c_mix_ctl Optional chanend to be connected to the mixer thread if * \param c_mix_ctl Optional chanend to be connected to the mixer thread if
* present * present
@@ -15,7 +15,7 @@
* present. * present.
* \param c_usb_test Optional chanend to be connected to XUD if test modes required. * \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); chanend ?c_mix_ctl,chanend ?c_clk_ctl, chanend ?c_usb_test);
#endif #endif

View File

@@ -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]; int volsOut[NUM_USB_CHAN_OUT + 1];
unsigned int mutesOut[NUM_USB_CHAN_OUT + 1]; unsigned int mutesOut[NUM_USB_CHAN_OUT + 1];
//unsigned int multOut[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; extern unsigned char g_currentConfig;
/* Global endpoint status arrays - declared in usb_device.xc */ /* 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) */ /* Global variable for current USB bus speed (i.e. FS/HS) */
unsigned g_curUsbSpeed = 0; 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); void VendorAudioRequestsInit(chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctl);
/* Endpoint 0 function. Handles all requests to the device */ /* 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) chanend ?c_mix_ctl, chanend ?c_clk_ctl, chanend ?c_usb_test)
{ {
USB_SetupPacket_t sp; 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++) { for (int i = 0; i < 18*8; i++) {
mixer1Weights[i] = 0x8001; //-inf mixer1Weights[i] = 0x8001; //-inf
} }
/* Configure default connections */ /* Configure default connections */
mixer1Weights[0] = 0; mixer1Weights[0] = 0;
mixer1Weights[9] = 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 */ /* Setup up audio output channel mapping */
for(int i = 0; i < NUM_USB_CHAN_OUT; i++) for(int i = 0; i < NUM_USB_CHAN_OUT; i++)
{ {
channelMapAud[i] = i; channelMapAud[i] = i;
} }
#endif #endif
#if NUM_USB_CHAN_IN > 0 #if NUM_USB_CHAN_IN > 0
for(int i = 0; i < NUM_USB_CHAN_IN; i++) 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 #endif
/* Set up channel mapping default */ /* 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; channelMap[i] = i;
} }
#if MAX_MIX_COUNT > 0 #if MAX_MIX_COUNT > 0
/* Mixer outputs mapping defaults */ /* 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; 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"); safestrcpy(strDescs[ADAT_RX_INDEX + INPUT_INTERFACE_STRING_INDEX + 7], "ADAT 8");
#endif #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], "S/PDIF 1");
safestrcpy(strDescs[SPDIF_TX_INDEX + OUTPUT_INTERFACE_STRING_INDEX + 1], "S/PDIF 2"); safestrcpy(strDescs[SPDIF_TX_INDEX + OUTPUT_INTERFACE_STRING_INDEX + 1], "S/PDIF 2");
#endif #endif
@@ -218,7 +218,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
#ifdef DFU #ifdef DFU
/* Check if device has started in DFU mode */ /* Check if device has started in DFU mode */
if (DFUReportResetState(null)) if (DFUReportResetState(null))
{ {
/* Stop audio */ /* Stop audio */
outuint(c_audioControl, SET_SAMPLE_FREQ); 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 // No Handshake
//chkct(c_audioControl, XS1_CT_END); //chkct(c_audioControl, XS1_CT_END);
DFU_mode_active = 1; DFU_mode_active = 1;
} }
#endif #endif
while(1) while(1)
{ {
/* Returns 0 for success, -1 for bus reset */ /* 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; 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) ) switch( (sp.bmRequestType.Direction << 7) | (sp.bmRequestType.Recipient ) | (sp.bmRequestType.Type << 5) )
{ {
case USB_BMREQ_H2D_STANDARD_INT: case USB_BMREQ_H2D_STANDARD_INT:
/* Over-riding USB_StandardRequests implementation */ /* Over-riding USB_StandardRequests implementation */
if(sp.bRequest == USB_SET_INTERFACE) 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, SET_DSD_MODE);
outuint(c_audioControl, DSD_MODE_OFF); outuint(c_audioControl, DSD_MODE_OFF);
/* Handshake */ /* Handshake */
chkct(c_audioControl, XS1_CT_END); chkct(c_audioControl, XS1_CT_END);
g_dsdMode = 0; 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 */ /* 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...*/ /* Also note, currently we assume with won't be doing ADAT in FS/UAC1...*/
if(g_curUsbSpeed == XUD_SPEED_HS) if(g_curUsbSpeed == XUD_SPEED_HS)
{ {
outuint(c_audioControl, SET_CHAN_COUNT_OUT); outuint(c_audioControl, SET_CHAN_COUNT_OUT);
outuint(c_audioControl, NUM_USB_CHAN_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, SET_DSD_MODE);
outuint(c_audioControl, DSD_MODE_OFF); outuint(c_audioControl, DSD_MODE_OFF);
// Handshake // Handshake
chkct(c_audioControl, XS1_CT_END); chkct(c_audioControl, XS1_CT_END);
g_dsdMode = 0; g_dsdMode = 0;
@@ -294,9 +294,9 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
break; break;
#ifdef NATIVE_DSD #ifdef NATIVE_DSD
case 2: case 2:
if(!g_dsdMode) if(!g_dsdMode)
{ {
outuint(c_audioControl, SET_DSD_MODE); outuint(c_audioControl, SET_DSD_MODE);
outuint(c_audioControl, DSD_MODE_NATIVE); outuint(c_audioControl, DSD_MODE_NATIVE);
chkct(c_audioControl, XS1_CT_END); 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 */ /* 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...*/ /* Also note, currently we assume with won't be doing ADAT in FS/UAC1...*/
if(g_curUsbSpeed == XUD_SPEED_HS) if(g_curUsbSpeed == XUD_SPEED_HS)
{ {
outuint(c_audioControl, SET_CHAN_COUNT_IN); outuint(c_audioControl, SET_CHAN_COUNT_IN);
outuint(c_audioControl, NUM_USB_CHAN_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, SET_CHAN_COUNT_IN);
outuint(c_audioControl, NUM_USB_CHAN_IN_A1); outuint(c_audioControl, NUM_USB_CHAN_IN_A1);
} }
#ifdef ADAT_RX #ifdef ADAT_RX
outuint(c_clk_ctl, SET_SMUX); outuint(c_clk_ctl, SET_SMUX);
outuint(c_clk_ctl, 0); outuint(c_clk_ctl, 0);
outct(c_clk_ctl, XS1_CT_END); outct(c_clk_ctl, XS1_CT_END);
#endif #endif
break; break;
#ifdef ADAT_RX #ifdef ADAT_RX
case 2: case 2:
/* Stream active + 8 chans */ /* Stream active + 8 chans */
outuint(c_audioControl, SET_CHAN_COUNT_IN); outuint(c_audioControl, SET_CHAN_COUNT_IN);
outuint(c_audioControl, NUM_USB_CHAN_IN-4); outuint(c_audioControl, NUM_USB_CHAN_IN-4);
outuint(c_clk_ctl, SET_SMUX); outuint(c_clk_ctl, SET_SMUX);
outuint(c_clk_ctl, 1); outuint(c_clk_ctl, 1);
outct(c_clk_ctl, XS1_CT_END); outct(c_clk_ctl, XS1_CT_END);
break; 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, SET_CHAN_COUNT_IN);
outuint(c_audioControl, NUM_USB_CHAN_IN-6); outuint(c_audioControl, NUM_USB_CHAN_IN-6);
outuint(c_clk_ctl, SET_SMUX); outuint(c_clk_ctl, SET_SMUX);
outuint(c_clk_ctl, 1); outuint(c_clk_ctl, 1);
outct(c_clk_ctl, XS1_CT_END); outct(c_clk_ctl, XS1_CT_END);
break; break;
#endif #endif
} }
} }
#if 1 #if 1
#if defined(OUTPUT) && defined(INPUT) #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); retVal = XUD_DoSetRequestStatus(ep0_in);
} /* if(sp.bRequest == SET_INTERFACE) */ } /* if(sp.bRequest == SET_INTERFACE) */
break; /* BMREQ_H2D_STANDARD_INT */ break; /* BMREQ_H2D_STANDARD_INT */
case USB_BMREQ_D2H_STANDARD_INT: case USB_BMREQ_D2H_STANDARD_INT:
switch(sp.bRequest) switch(sp.bRequest)
{ {
@@ -412,29 +412,29 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
{ {
case HID_REPORT: case HID_REPORT:
/* Return HID report descriptor */ /* Return HID report descriptor */
retVal = XUD_DoGetRequest(ep0_out, ep0_in, hidReportDescriptor, retVal = XUD_DoGetRequest(ep0_out, ep0_in, hidReportDescriptor,
sizeof(hidReportDescriptor), sp.wLength); sizeof(hidReportDescriptor), sp.wLength);
break; break;
} }
} }
break; break;
#endif #endif
default: default:
break; break;
} }
break; break;
/* Recipient: Device */ /* Recipient: Device */
case USB_BMREQ_H2D_STANDARD_DEV: case USB_BMREQ_H2D_STANDARD_DEV:
/* Inspect for actual request */ /* Inspect for actual request */
switch( sp.bRequest ) switch( sp.bRequest )
{ {
/* Standard request: SetConfiguration */ /* Standard request: SetConfiguration */
/* Overriding implementation in USB_StandardRequests */ /* Overriding implementation in USB_StandardRequests */
case USB_SET_CONFIGURATION: case USB_SET_CONFIGURATION:
//g_currentConfig = sp.wValue; //g_currentConfig = sp.wValue;
//if(g_current_config == 1) //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) //if(retVal == 0)
// retVal = 1; // retVal = 1;
break; break;
default: default:
//Unknown device request" //Unknown device request"
break; break;
} }
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_H2D_CLASS_EP:
case USB_BMREQ_D2H_CLASS_EP: case USB_BMREQ_D2H_CLASS_EP:
{ {
unsigned epNum = sp.wIndex & 0xff; unsigned epNum = sp.wIndex & 0xff;
if ((epNum == 0x82) || (epNum == 0x01)) if ((epNum == 0x82) || (epNum == 0x01))
{ {
#if (AUDIO_CLASS == 2) && defined(AUDIO_CLASS_FALLBACK) #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); retVal = AudioEndpointRequests_1(ep0_out, ep0_in, sp, c_audioControl, c_mix_ctl, c_clk_ctl);
#endif #endif
} }
} }
break; break;
case USB_BMREQ_H2D_CLASS_INT: case USB_BMREQ_H2D_CLASS_INT:
case USB_BMREQ_D2H_CLASS_INT: case USB_BMREQ_D2H_CLASS_INT:
{ {
unsigned interfaceNum = sp.wIndex & 0xff; unsigned interfaceNum = sp.wIndex & 0xff;
//unsigned request = (sp.bmRequestType.Recipient ) | (sp.bmRequestType.Type << 5); //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; unsigned DFU_IF = DFU_IF_NUM;
/* DFU interface number changes based on which mode we are currently running in */ /* DFU interface number changes based on which mode we are currently running in */
if (DFU_mode_active) if (DFU_mode_active)
{ {
DFU_IF = 0; DFU_IF = 0;
} }
if (interfaceNum == DFU_IF) if (interfaceNum == DFU_IF)
{ {
/* If running in application mode stop audio */ /* If running in application mode stop audio */
/* Don't interupt audio for save and restore cmds */ /* 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)) (sp.bRequest != XMOS_DFU_RESTORESTATE))
{ {
// Stop audio // Stop audio
@@ -511,9 +511,9 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
// Handshake // Handshake
chkct(c_audioControl, XS1_CT_END); chkct(c_audioControl, XS1_CT_END);
} }
/* This will return 1 if reset requested */ /* 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; timer tmr;
unsigned s; 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 */ /* TODO we should not make the assumption that all DFU requests are handled */
retVal = 0; retVal = 0;
} }
#endif #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 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)) 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, retVal = VendorAudioRequests(ep0_out, ep0_in, sp.bRequest,
sp.wValue >> 8, sp.wValue & 0xff, sp.wValue >> 8, sp.wValue & 0xff,
sp.wIndex >> 8, sp.bmRequestType.Direction, sp.wIndex >> 8, sp.bmRequestType.Direction,
c_audioControl, c_mix_ctl, c_clk_ctl); c_audioControl, c_mix_ctl, c_clk_ctl);
} }
#endif #endif
} }
} }
break; break;
default: default:
break; break;
} }
} /* if(retVal == 0) */ } /* if(retVal == 0) */
if(retVal > 0) if(retVal > 0)
{ {
#ifdef DFU #ifdef DFU
if (!DFU_mode_active) if (!DFU_mode_active)
{ {
#endif #endif
#ifdef AUDIO_CLASS_FALLBACK #ifdef AUDIO_CLASS_FALLBACK
/* Return Audio 2.0 Descriptors with Audio 1.0 as fallback */ /* Return Audio 2.0 Descriptors with Audio 1.0 as fallback */
retVal = USB_StandardRequests(ep0_out, ep0_in, retVal = USB_StandardRequests(ep0_out, ep0_in,
devDesc_Audio2, sizeof(devDesc_Audio2), devDesc_Audio2, sizeof(devDesc_Audio2),
cfgDesc_Audio2, sizeof(cfgDesc_Audio2), cfgDesc_Audio2, sizeof(cfgDesc_Audio2),
devDesc_Audio1, sizeof(devDesc_Audio1), devDesc_Audio1, sizeof(devDesc_Audio1),
cfgDesc_Audio1, sizeof(cfgDesc_Audio1), cfgDesc_Audio1, sizeof(cfgDesc_Audio1),
strDescs, sizeof(strDescs)/sizeof(strDescs[0]), strDescs, sizeof(strDescs)/sizeof(strDescs[0]),
sp, c_usb_test, g_curUsbSpeed); sp, c_usb_test, g_curUsbSpeed);
#elif FULL_SPEED_AUDIO_2 #elif FULL_SPEED_AUDIO_2
/* Return Audio 2.0 Descriptors for high_speed and full-speed */ /* 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 */ /* Mod bSlotSize */
cfgDesc_Audio2[STREAMING_ALT1_OFFSET+4] = SAMPLE_SUBSLOT_SIZE_HS; cfgDesc_Audio2[STREAMING_ALT1_OFFSET+4] = SAMPLE_SUBSLOT_SIZE_HS;
/* Mod bBitResolution */ /* Mod bBitResolution */
cfgDesc_Audio2[STREAMING_ALT1_OFFSET+5] = SAMPLE_BIT_RESOLUTION_HS; cfgDesc_Audio2[STREAMING_ALT1_OFFSET+5] = SAMPLE_BIT_RESOLUTION_HS;
/* wMaxPacketSize */ /* 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; cfgDesc_Audio2[STREAMING_ALT1_OFFSET+11] = (MAX_PACKET_SIZE_OUT_HS&0xff00)>>8;
} }
else else
{ {
/* Mod bSlotSize */ /* Mod bSlotSize */
cfgDesc_Audio2[STREAMING_ALT1_OFFSET+4] = SAMPLE_SUBSLOT_SIZE_FS; cfgDesc_Audio2[STREAMING_ALT1_OFFSET+4] = SAMPLE_SUBSLOT_SIZE_FS;
/* Mod bBitResolution */ /* Mod bBitResolution */
cfgDesc_Audio2[STREAMING_ALT1_OFFSET+5] = SAMPLE_BIT_RESOLUTION_FS; cfgDesc_Audio2[STREAMING_ALT1_OFFSET+5] = SAMPLE_BIT_RESOLUTION_FS;
/* wMaxPacketSize */ /* 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; cfgDesc_Audio2[STREAMING_ALT1_OFFSET+11] = (MAX_PACKET_SIZE_OUT_FS&0xff00)>>8;
} }
retVal = USB_StandardRequests(ep0_out, ep0_in, retVal = USB_StandardRequests(ep0_out, ep0_in,
devDesc_Audio2, sizeof(devDesc_Audio2), devDesc_Audio2, sizeof(devDesc_Audio2),
cfgDesc_Audio2, sizeof(cfgDesc_Audio2), cfgDesc_Audio2, sizeof(cfgDesc_Audio2),
null, 0, null, 0,
null, 0, null, 0,
strDescs, sizeof(strDescs)/sizeof(strDescs[0]), sp, c_usb_test, g_curUsbSpeed); strDescs, sizeof(strDescs)/sizeof(strDescs[0]), sp, c_usb_test, g_curUsbSpeed);
#else #else
/* Return Audio 2.0 Descriptors with Null device as fallback */ /* Return Audio 2.0 Descriptors with Null device as fallback */
retVal = USB_StandardRequests(ep0_out, ep0_in, retVal = USB_StandardRequests(ep0_out, ep0_in,
devDesc_Audio2, sizeof(devDesc_Audio2), devDesc_Audio2, sizeof(devDesc_Audio2),
cfgDesc_Audio2, sizeof(cfgDesc_Audio2), cfgDesc_Audio2, sizeof(cfgDesc_Audio2),
devDesc_Null, sizeof(devDesc_Null), devDesc_Null, sizeof(devDesc_Null),
cfgDesc_Null, sizeof(cfgDesc_Null), cfgDesc_Null, sizeof(cfgDesc_Null),
strDescs, sizeof(strDescs)/sizeof(strDescs[0]), sp, c_usb_test, g_curUsbSpeed); strDescs, sizeof(strDescs)/sizeof(strDescs[0]), sp, c_usb_test, g_curUsbSpeed);
#endif #endif
#ifdef DFU #ifdef DFU
} }
else else
{ {
/* Running in DFU mode - always return same descs for DFU whether HS or FS */ /* Running in DFU mode - always return same descs for DFU whether HS or FS */
retVal = USB_StandardRequests(ep0_out, ep0_in, retVal = USB_StandardRequests(ep0_out, ep0_in,
DFUdevDesc, sizeof(DFUdevDesc), DFUdevDesc, sizeof(DFUdevDesc),
DFUcfgDesc, sizeof(DFUcfgDesc), DFUcfgDesc, sizeof(DFUcfgDesc),
null, 0, /* Used same descriptors for full and high-speed */ null, 0, /* Used same descriptors for full and high-speed */
null, 0, null, 0,
strDescs, sizeof(strDescs), sp, c_usb_test, g_curUsbSpeed); strDescs, sizeof(strDescs), sp, c_usb_test, g_curUsbSpeed);
} }
#endif #endif
} }
if (retVal < 0) if (retVal < 0)
{ {
g_curUsbSpeed = XUD_ResetEndpoint(ep0_out, ep0_in); g_curUsbSpeed = XUD_ResetEndpoint(ep0_out, ep0_in);
g_currentConfig = 0; g_currentConfig = 0;
#ifdef DFU #ifdef DFU
if (DFUReportResetState(null)) if (DFUReportResetState(null))
{ {
if (!DFU_mode_active) if (!DFU_mode_active)
{ {
timer tmr; timer tmr;
unsigned s; unsigned s;
DFU_mode_active = 1; DFU_mode_active = 1;
} }
} }
else else
{ {
if (DFU_mode_active) if (DFU_mode_active)
{ {
timer tmr; timer tmr;
unsigned s; unsigned s;

View File

@@ -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); unsigned short unitId, unsigned char direction, chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctL);
#endif #endif

View File

@@ -18,7 +18,7 @@
fl_DeviceSpec flash_devices[] = {DFU_FLASH_DEVICE}; fl_DeviceSpec flash_devices[] = {DFU_FLASH_DEVICE};
#endif #endif
fl_PortHolderStruct p_flash = fl_PortHolderStruct p_flash =
{ {
XS1_PORT_1A, XS1_PORT_1A,
XS1_PORT_1B, XS1_PORT_1B,
@@ -27,7 +27,7 @@ fl_PortHolderStruct p_flash =
XS1_CLKBLK_1 XS1_CLKBLK_1
}; };
int flash_cmd_enable_ports() int flash_cmd_enable_ports()
{ {
int result = 0; int result = 0;
setc(p_flash.spiMISO, XS1_SETC_INUSE_OFF); setc(p_flash.spiMISO, XS1_SETC_INUSE_OFF);
@@ -61,17 +61,17 @@ int flash_cmd_enable_ports()
/* Use default flash list */ /* Use default flash list */
result = fl_connect(&p_flash); result = fl_connect(&p_flash);
#endif #endif
if (!result) if (!result)
{ {
return 1; return 1;
} }
else else
{ {
return 0; return 0;
} }
} }
int flash_cmd_disable_ports() int flash_cmd_disable_ports()
{ {
fl_disconnect(); fl_disconnect();

View File

@@ -1,8 +1,8 @@
/** /**
* @file main.xc * @file main.xc
* @brief Top level for XMOS USB 2.0 Audio 2.0 Reference Designs. * @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 <syscall.h> #include <syscall.h>
#include <platform.h> #include <platform.h>
#include <xs1.h> #include <xs1.h>
@@ -15,7 +15,7 @@
#include "xud.h" /* XMOS USB Device Layer defines and functions */ #include "xud.h" /* XMOS USB Device Layer defines and functions */
#include "usb.h" /* Defines from the USB 2.0 Specification */ #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 "endpoint0.h"
#include "usb_buffer.h" #include "usb_buffer.h"
#include "decouple.h" #include "decouple.h"
@@ -42,26 +42,26 @@
/* Audio I/O - Port declarations */ /* Audio I/O - Port declarations */
#if I2S_WIRES_DAC > 0 #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, {PORT_I2S_DAC0,
#endif #endif
#if I2S_WIRES_DAC > 1 #if I2S_WIRES_DAC > 1
PORT_I2S_DAC1, PORT_I2S_DAC1,
#endif #endif
#if I2S_WIRES_DAC > 2 #if I2S_WIRES_DAC > 2
PORT_I2S_DAC2, PORT_I2S_DAC2,
#endif #endif
#if I2S_WIRES_DAC > 3 #if I2S_WIRES_DAC > 3
PORT_I2S_DAC3, PORT_I2S_DAC3,
#endif #endif
#if I2S_WIRES_DAC > 4 #if I2S_WIRES_DAC > 4
PORT_I2S_DAC4, PORT_I2S_DAC4,
#endif #endif
#if I2S_WIRES_DAC > 5 #if I2S_WIRES_DAC > 5
PORT_I2S_DAC5, PORT_I2S_DAC5,
#endif #endif
#if I2S_WIRES_DAC > 6 #if I2S_WIRES_DAC > 6
PORT_I2S_DAC6, PORT_I2S_DAC6,
#endif #endif
#if I2S_WIRES_DAC > 7 #if I2S_WIRES_DAC > 7
#error Not supported #error Not supported
@@ -71,26 +71,26 @@ on tile[AUDIO_IO_TILE] : buffered out port:32 p_i2s_dac[I2S_WIRES_DAC] =
#endif #endif
#if I2S_WIRES_ADC > 0 #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, {PORT_I2S_ADC0,
#endif #endif
#if I2S_WIRES_ADC > 1 #if I2S_WIRES_ADC > 1
PORT_I2S_ADC1, PORT_I2S_ADC1,
#endif #endif
#if I2S_WIRES_ADC > 2 #if I2S_WIRES_ADC > 2
PORT_I2S_ADC2, PORT_I2S_ADC2,
#endif #endif
#if I2S_WIRES_ADC > 3 #if I2S_WIRES_ADC > 3
PORT_I2S_ADC3, PORT_I2S_ADC3,
#endif #endif
#if I2S_WIRES_ADC > 4 #if I2S_WIRES_ADC > 4
PORT_I2S_ADC4, PORT_I2S_ADC4,
#endif #endif
#if I2S_WIRES_ADC > 5 #if I2S_WIRES_ADC > 5
PORT_I2S_ADC5, PORT_I2S_ADC5,
#endif #endif
#if I2S_WIRES_ADC > 6 #if I2S_WIRES_ADC > 6
PORT_I2S_ADC6, PORT_I2S_ADC6,
#endif #endif
#if I2S_WIRES_ADC > 7 #if I2S_WIRES_ADC > 7
#error Not supported #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[AUDIO_IO_TILE] : port p_mclk_in = PORT_MCLK_IN;
on tile[XUD_TILE] : in port p_for_mclk_count = PORT_MCLK_COUNT; 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; on tile[AUDIO_IO_TILE] : buffered out port:32 p_spdif_tx = PORT_SPDIF_OUT;
#endif #endif
@@ -128,7 +128,7 @@ on tile[AUDIO_IO_TILE] : clock clk_audio_mclk = XS1_CLKBLK_2;
#if(AUDIO_IO_TILE != XUD_TILE) #if(AUDIO_IO_TILE != XUD_TILE)
on tile[XUD_TILE] : clock clk_audio_mclk2 = XS1_CLKBLK_2; /* Master clock */ 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 #endif
@@ -160,7 +160,7 @@ on tile [AUDIO_IO_TILE] : port p_i2c_scl = PORT_I2C_SCL;
/* Endpoint type tables for XUD */ /* 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 */ XUD_EPTYPE_ISO, /* Audio */
#ifdef MIDI #ifdef MIDI
XUD_EPTYPE_BUL, /* MIDI */ XUD_EPTYPE_BUL, /* MIDI */
@@ -168,10 +168,10 @@ XUD_EpType epTypeTableOut[EP_CNT_OUT] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE,
#ifdef IAP #ifdef IAP
XUD_EPTYPE_BUL | XUD_STATUS_ENABLE /* iAP */ XUD_EPTYPE_BUL | XUD_STATUS_ENABLE /* iAP */
#endif #endif
}; };
XUD_EpType epTypeTableIn[EP_CNT_IN] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, XUD_EpType epTypeTableIn[EP_CNT_IN] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE,
XUD_EPTYPE_ISO, XUD_EPTYPE_ISO,
XUD_EPTYPE_ISO, XUD_EPTYPE_ISO,
#if defined (SPDIF_RX) || defined (ADAT_RX) #if defined (SPDIF_RX) || defined (ADAT_RX)
XUD_EPTYPE_BUL, XUD_EPTYPE_BUL,
@@ -226,49 +226,49 @@ void usb_audio_core(chanend c_mix_out
, chanend c_mix_ctl , chanend c_mix_ctl
#endif #endif
) )
{ {
chan c_sof; chan c_sof;
chan c_xud_out[EP_CNT_OUT]; /* Endpoint channels for XUD */ chan c_xud_out[EP_CNT_OUT]; /* Endpoint channels for XUD */
chan c_xud_in[EP_CNT_IN]; chan c_xud_in[EP_CNT_IN];
chan c_aud_ctl; chan c_aud_ctl;
#ifdef TEST_MODE_SUPPORT #ifdef TEST_MODE_SUPPORT
#warning Building with test mode support #warning Building with test mode support
chan c_usb_test; chan c_usb_test;
#else #else
#define c_usb_test null #define c_usb_test null
#endif #endif
#ifdef CHAN_BUFF_CTRL #ifdef CHAN_BUFF_CTRL
#warning Using channel to control buffering - this may reduce performance but improve power consumption #warning Using channel to control buffering - this may reduce performance but improve power consumption
chan c_buff_ctrl; chan c_buff_ctrl;
#endif #endif
#ifndef MIXER #ifndef MIXER
#define c_mix_ctl null #define c_mix_ctl null
#endif #endif
par par
{ {
/* USB Interface Core */ /* USB Interface Core */
#if (AUDIO_CLASS==2) #if (AUDIO_CLASS==2)
XUD_Manager(c_xud_out, EP_CNT_OUT, c_xud_in, EP_CNT_IN, XUD_Manager(c_xud_out, EP_CNT_OUT, c_xud_in, EP_CNT_IN,
c_sof, epTypeTableOut, epTypeTableIn, p_usb_rst, c_sof, epTypeTableOut, epTypeTableIn, p_usb_rst,
clk, 1, XUD_SPEED_HS, c_usb_test, pwrConfig); clk, 1, XUD_SPEED_HS, c_usb_test, pwrConfig);
#else #else
XUD_Manager(c_xud_out, EP_CNT_OUT, c_xud_in, EP_CNT_IN, XUD_Manager(c_xud_out, EP_CNT_OUT, c_xud_in, EP_CNT_IN,
c_sof, epTypeTableOut, epTypeTableIn, p_usb_rst, c_sof, epTypeTableOut, epTypeTableIn, p_usb_rst,
clk, 1, XUD_SPEED_FS, c_usb_test, pwrConfig); clk, 1, XUD_SPEED_FS, c_usb_test, pwrConfig);
#endif #endif
/* USB Packet buffering Core */ /* USB Packet buffering Core */
{ {
unsigned x; unsigned x;
thread_speed(); thread_speed();
/* Attach mclk count port to mclk clock-block (for feedback) */ /* Attach mclk count port to mclk clock-block (for feedback) */
//set_port_clock(p_for_mclk_count, clk_audio_mclk); //set_port_clock(p_for_mclk_count, clk_audio_mclk);
#if(AUDIO_IO_TILE != 0) #if(AUDIO_IO_TILE != 0)
set_clock_src(clk_audio_mclk2, p_mclk_in2); 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); start_clock(clk_audio_mclk2);
#else #else
/* Uses same clock-block as I2S */ /* 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*/ 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_AUD], /* Audio In */
c_xud_in[EP_NUM_IN_FB], /* Audio FB */ 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_out[EP_NUM_OUT_MIDI], /* MIDI Out */ // 2
c_xud_in[EP_NUM_IN_MIDI], /* MIDI In */ // 4 c_xud_in[EP_NUM_IN_MIDI], /* MIDI In */ // 4
c_midi, c_midi,
@@ -288,8 +288,8 @@ void usb_audio_core(chanend c_mix_out
#endif #endif
#if defined(SPDIF_RX) || defined(ADAT_RX) #if defined(SPDIF_RX) || defined(ADAT_RX)
/* Audio Interrupt - only used for interrupts on external clock change */ /* Audio Interrupt - only used for interrupts on external clock change */
c_xud_in[EP_NUM_IN_AUD_INT], c_xud_in[EP_NUM_IN_AUD_INT],
#endif #endif
c_sof, c_aud_ctl, p_for_mclk_count c_sof, c_aud_ctl, p_for_mclk_count
#ifdef HID_CONTROLS #ifdef HID_CONTROLS
, c_xud_in[EP_NUM_IN_HID] , c_xud_in[EP_NUM_IN_HID]
@@ -305,8 +305,8 @@ void usb_audio_core(chanend c_mix_out
thread_speed(); thread_speed();
Endpoint0( c_xud_out[0], c_xud_in[0], c_aud_ctl, c_mix_ctl, null, c_usb_test); 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(); thread_speed();
decouple(c_mix_out, null decouple(c_mix_out, null
@@ -334,24 +334,24 @@ void usb_audio_io(chanend c_aud_in, chanend ?c_adc
par par
{ {
#ifdef MIXER #ifdef MIXER
/* Mixer cores(s) */ /* Mixer cores(s) */
{ {
thread_speed(); thread_speed();
mixer(c_aud_in, c_mix_out, c_mix_ctl); mixer(c_aud_in, c_mix_out, c_mix_ctl);
} }
#endif #endif
/* Audio I/O Core (pars additional S/PDIF TX Core) */ /* Audio I/O Core (pars additional S/PDIF TX Core) */
{ {
thread_speed(); thread_speed();
#ifdef MIXER #ifdef MIXER
audio(c_mix_out, null, null, c_adc); audio(c_mix_out, null, null, c_adc);
#else #else
audio(c_aud_in, null, null, c_adc); audio(c_aud_in, null, null, c_adc);
#endif #endif
} }
/* MIDI/iAP Core */ /* MIDI/iAP Core */
#if defined (MIDI) || defined IAP #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); usb_midi(p_midi_rx, p_midi_tx, clk_midi, c_midi, 0, null, null, null, null);
#else #else
iAP(c_iap, null, null, null); iAP(c_iap, null, null, null);
#endif #endif
} }
#endif #endif
@@ -402,8 +402,8 @@ int main()
par par
{ {
on tile[XUD_TILE]: usb_audio_core(c_mix_out on tile[XUD_TILE]: usb_audio_core(c_mix_out
#ifdef MIDI #ifdef MIDI
, c_midi , c_midi
#endif #endif
#ifdef IAP #ifdef IAP
@@ -413,7 +413,7 @@ int main()
, c_mix_ctl , c_mix_ctl
#endif #endif
); );
on tile[AUDIO_IO_TILE]: usb_audio_io(c_mix_out, c_adc on tile[AUDIO_IO_TILE]: usb_audio_io(c_mix_out, c_adc
#ifdef MIDI #ifdef MIDI
, c_midi , c_midi
@@ -433,7 +433,7 @@ int main()
#ifdef SU1_ADC_ENABLE #ifdef SU1_ADC_ENABLE
xs1_su_adc_service(c_adc); xs1_su_adc_service(c_adc);
#endif #endif
return 0; return 0;
} }

View File

@@ -1,176 +1,176 @@
//#include "devicedefines.h" //#include "devicedefines.h"
#define MAX_MIX_COUNT 8 #define MAX_MIX_COUNT 8
#define MIX_INPUTS 18 #define MIX_INPUTS 18
#define DOMIX_TOP(i) \ #define DOMIX_TOP(i) \
.cc_top doMix##i.function,doMix##i; \ .cc_top doMix##i.function,doMix##i; \
.align 4 ;\ .align 4 ;\
.globl doMix##i ;\ .globl doMix##i ;\
.type doMix##i, @function ;\ .type doMix##i, @function ;\
.globl doMix##i##.nstackwords ;\ .globl doMix##i##.nstackwords ;\
.globl doMix##i##.maxthreads ; \ .globl doMix##i##.maxthreads ; \
.globl doMix##i##.maxtimers ; \ .globl doMix##i##.maxtimers ; \
.globl doMix##i##.maxchanends ; \ .globl doMix##i##.maxchanends ; \
.globl doMix##i##.maxsync ;\ .globl doMix##i##.maxsync ;\
.linkset doMix##i##.locnoside, 1; \ .linkset doMix##i##.locnoside, 1; \
.linkset doMix##i##.locnochandec, 1;\ .linkset doMix##i##.locnochandec, 1;\
.linkset doMix##i##.nstackwords, 0 ;\ .linkset doMix##i##.nstackwords, 0 ;\
.linkset doMix##i##.maxchanends, 0 ;\ .linkset doMix##i##.maxchanends, 0 ;\
.linkset doMix##i##.maxtimers, 0 ;\ .linkset doMix##i##.maxtimers, 0 ;\
.linkset doMix##i##.maxthreads, 1; \ .linkset doMix##i##.maxthreads, 1; \
doMix##i##: ;\ doMix##i##: ;\
set cp, r0; \ set cp, r0; \
set dp, r1; \ set dp, r1; \
lsub r0, r1, r0, r0, r0;\ lsub r0, r1, r0, r0, r0;\
.label_##i##: .label_##i##:
#define DOMIX_BOT(i) \ #define DOMIX_BOT(i) \
ldap r11, _dp; \ ldap r11, _dp; \
set dp, r11;\ set dp, r11;\
ldap r11, _cp;\ ldap r11, _cp;\
set cp, r11;\ set cp, r11;\
\ \
mov r0, r1;\ mov r0, r1;\
ldc r2, 0x19;\ ldc r2, 0x19;\
sext r0, r2;\ sext r0, r2;\
eq r0, r0, r1;\ eq r0, r0, r1;\
bf r0, .L20; \ bf r0, .L20; \
\ \
shl r0, r1, 0x7;\ shl r0, r1, 0x7;\
retsp 0x0;\ retsp 0x0;\
\ \
\ \
.size doMix##i, .-doMix##i; \ .size doMix##i, .-doMix##i; \
.cc_bottom doMix##i##.function; .cc_bottom doMix##i##.function;
#define N MIX_INPUTS #define N MIX_INPUTS
#define BODY(i) \ #define BODY(i) \
ldw r2,cp[i]; \ ldw r2,cp[i]; \
ldw r11, dp[i]; \ ldw r11, dp[i]; \
maccs r1, r0, r2, r11; maccs r1, r0, r2, r11;
.text .text
.L20:\ .L20:\
lss r0, r1, r3;\ lss r0, r1, r3;\
bt r0, .L16; \ bt r0, .L16; \
ldw r0, cp[.LC0];\ ldw r0, cp[.LC0];\
retsp 0x0; \ retsp 0x0; \
.L16:\ .L16:\
ldw r0, cp[.LC1];\ ldw r0, cp[.LC1];\
retsp 0x0; \ retsp 0x0; \
#if(MAX_MIX_COUNT > 0) #if(MAX_MIX_COUNT > 0)
DOMIX_TOP(0) DOMIX_TOP(0)
#include "repeat.h" #include "repeat.h"
DOMIX_BOT(0) DOMIX_BOT(0)
#endif #endif
#if(MAX_MIX_COUNT > 1) #if(MAX_MIX_COUNT > 1)
DOMIX_TOP(1) DOMIX_TOP(1)
#include "repeat.h" #include "repeat.h"
DOMIX_BOT(1) DOMIX_BOT(1)
#endif #endif
#if(MAX_MIX_COUNT > 2) #if(MAX_MIX_COUNT > 2)
DOMIX_TOP(2) DOMIX_TOP(2)
#include "repeat.h" #include "repeat.h"
DOMIX_BOT(2) DOMIX_BOT(2)
#endif #endif
#if(MAX_MIX_COUNT > 3) #if(MAX_MIX_COUNT > 3)
DOMIX_TOP(3) DOMIX_TOP(3)
#include "repeat.h" #include "repeat.h"
DOMIX_BOT(3) DOMIX_BOT(3)
#endif #endif
#if(MAX_MIX_COUNT > 4) #if(MAX_MIX_COUNT > 4)
DOMIX_TOP(4) DOMIX_TOP(4)
#include "repeat.h" #include "repeat.h"
DOMIX_BOT(4) DOMIX_BOT(4)
#endif #endif
#if(MAX_MIX_COUNT > 5) #if(MAX_MIX_COUNT > 5)
DOMIX_TOP(5) DOMIX_TOP(5)
#include "repeat.h" #include "repeat.h"
DOMIX_BOT(5) DOMIX_BOT(5)
#endif #endif
#if(MAX_MIX_COUNT > 6) #if(MAX_MIX_COUNT > 6)
DOMIX_TOP(6) DOMIX_TOP(6)
#include "repeat.h" #include "repeat.h"
DOMIX_BOT(6) DOMIX_BOT(6)
#endif #endif
#if(MAX_MIX_COUNT > 7) #if(MAX_MIX_COUNT > 7)
DOMIX_TOP(7) DOMIX_TOP(7)
#include "repeat.h" #include "repeat.h"
DOMIX_BOT(7) DOMIX_BOT(7)
#endif #endif
#if(MAX_MIX_COUNT>8) #if(MAX_MIX_COUNT>8)
#error MAX_MIX_COUNT>7 #error MAX_MIX_COUNT>7
#endif #endif
/* We need MIX_OUTPUT x setPtr functions */ /* We need MIX_OUTPUT x setPtr functions */
#undef N #undef N
#undef BODY #undef BODY
#define N MAX_MIX_COUNT #define N MAX_MIX_COUNT
.cc_top setPtr.function,setPtr; .cc_top setPtr.function,setPtr;
.align 4 ; .align 4 ;
.globl setPtr; .globl setPtr;
.type setPtr, @function .type setPtr, @function
.globl setPtr.nstackwords; .globl setPtr.nstackwords;
.globl setPtr.maxthreads; .globl setPtr.maxthreads;
.globl setPtr.maxtimers; .globl setPtr.maxtimers;
.globl setPtr.maxchanends; .globl setPtr.maxchanends;
.globl setPtr.maxsync; .globl setPtr.maxsync;
.linkset setPtr.locnoside, 1; .linkset setPtr.locnoside, 1;
.linkset setPtr.locnochandec, 1; .linkset setPtr.locnochandec, 1;
.linkset setPtr.nstackwords, 0; .linkset setPtr.nstackwords, 0;
.linkset setPtr.maxchanends, 0; .linkset setPtr.maxchanends, 0;
.linkset setPtr.maxtimers, 0; .linkset setPtr.maxtimers, 0;
.linkset setPtr.maxthreads, 1; .linkset setPtr.maxthreads, 1;
setPtr: setPtr:
shl r2, r2, 1 shl r2, r2, 1
.xtabranch .label_0 .xtabranch .label_0
bru r2 bru r2
#define BODY(i) \ #define BODY(i) \
ldap r11, .label_##i; \ ldap r11, .label_##i; \
bu setPtr_go bu setPtr_go
#include "repeat.h" #include "repeat.h"
setPtr_go: setPtr_go:
shl r0, r0, 3; shl r0, r0, 3;
ldc r2, 0x80; ldc r2, 0x80;
add r1, r1, r2; add r1, r1, r2;
st8 r1, r11[r0]; st8 r1, r11[r0];
retsp 0; retsp 0;
.size setPtr, .-setPtr .size setPtr, .-setPtr
.cc_bottom setPtr.function .cc_bottom setPtr.function
.section .cp.const4, "acM", @progbits, 4 .section .cp.const4, "acM", @progbits, 4
.cc_top .LC0.data .cc_top .LC0.data
.align 4 .align 4
.LC0: .LC0:
.int 0x7fffff00 .int 0x7fffff00
.cc_bottom .LC0.data .cc_bottom .LC0.data
.cc_top .LC1.data .cc_top .LC1.data
.align 4 .align 4
.LC1: .LC1:
.int 0x80000000 .int 0x80000000
.cc_bottom .LC1.data .cc_bottom .LC1.data
#undef N #undef N
#undef BODY #undef BODY

View File

@@ -18,14 +18,14 @@ enum mix_ctl_cmd {
* *
* This thread mixes audio streams between the decouple() thread and * This thread mixes audio streams between the decouple() thread and
* the audio() thread. * the audio() thread.
* *
* \param c_to_host a chanend connected to the decouple() thread for * \param c_to_host a chanend connected to the decouple() thread for
* receiving/transmitting samples * receiving/transmitting samples
* \param c_to_audio a chanend connected to the audio() thread for * \param c_to_audio a chanend connected to the audio() thread for
* receiving/transmitting samples * receiving/transmitting samples
* \param c_mix_ctl a chanend connected to the Endpoint0() thread for * \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); void mixer(chanend c_to_host, chanend c_to_audio, chanend c_mix_ctl);

View File

@@ -19,7 +19,7 @@ unsigned int multIn_array[NUM_USB_CHAN_IN + 1];
static xc_ptr multIn; static xc_ptr multIn;
#endif #endif
#if defined (LEVEL_METER_LEDS) || defined (LEVEL_METER_HOST) #if defined (LEVEL_METER_LEDS) || defined (LEVEL_METER_HOST)
static unsigned abs(int x) static unsigned abs(int x)
{ {
#if 0 #if 0
@@ -49,7 +49,7 @@ int mix_mult_array[MAX_MIX_COUNT][MIX_INPUTS];
xc_ptr mix_mult; 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 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)) #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]; int mix_map_array[MAX_MIX_COUNT][MIX_INPUTS];
xc_ptr mix_map; 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) #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 */ #pragma xta command "set required - 10400 ns" /* 96kHz */
#endif #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) static inline void ComputeMixerLevel(int sample, int i)
{ {
int x; int x;
@@ -88,8 +88,8 @@ static inline void ComputeMixerLevel(int sample, int i)
x = abs(sample); x = abs(sample);
/* y = samples_to_host_outputs[i] */ /* y = samples_to_host_outputs[i] */
asm("ldaw %0, dp[samples_to_host_outputs]":"=r"(ptr):); /* Might want to hoist this */ 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("ldw %0, %1[%2]":"=r"(y):"r"(ptr),"r"(i));
if(x > y) if(x > y)
{ {
@@ -116,12 +116,12 @@ int doMix8(xc_ptr samples, xc_ptr mult);
#pragma unsafe arrays #pragma unsafe arrays
static int doMix(xc_ptr samples, xc_ptr ptr, xc_ptr mult) static int doMix(xc_ptr samples, xc_ptr ptr, xc_ptr mult)
{ {
int h=0; int h=0;
int l=0; int l=0;
/* By breaking up the loop we keep things in the encoding for ldw (0-11) */ /* By breaking up the loop we keep things in the encoding for ldw (0-11) */
#pragma loop unroll #pragma loop unroll
for (int i=0; i<MIX_INPUTS; i++) for (int i=0; i<MIX_INPUTS; i++)
{ {
int sample; int sample;
int index; int index;
@@ -131,7 +131,7 @@ static int doMix(xc_ptr samples, xc_ptr ptr, xc_ptr mult)
read_via_xc_ptr_indexed(m, mult, i); read_via_xc_ptr_indexed(m, mult, i);
{h,l} = macs(sample, m, h, l); {h,l} = macs(sample, m, h, l);
} }
#if 1 #if 1
/* Perform saturation */ /* Perform saturation */
l = sext(h, 25); l = sext(h, 25);
@@ -139,7 +139,7 @@ static int doMix(xc_ptr samples, xc_ptr ptr, xc_ptr mult)
if(l != h) if(l != h)
{ {
//if(h < 0) //if(h < 0)
if(h>>32) if(h>>32)
h = (0x80000000>>7); h = (0x80000000>>7);
else else
h = (0x7fffff00>>7); h = (0x7fffff00>>7);
@@ -159,7 +159,7 @@ static void giveSamplesToHost(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr mult
#endif #endif
#pragma loop unroll #pragma loop unroll
for (int i=0;i<NUM_USB_CHAN_IN;i++) for (int i=0;i<NUM_USB_CHAN_IN;i++)
{ {
int sample; int sample;
int index; int index;
@@ -171,9 +171,9 @@ static void giveSamplesToHost(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr mult
//asm("ldw %0, %1[%2]":"=r"(mult):"r"(multIn),"r"(i)); //asm("ldw %0, %1[%2]":"=r"(mult):"r"(multIn),"r"(i));
read_via_xc_ptr_indexed(mult, multIn, i); read_via_xc_ptr_indexed(mult, multIn, i);
{h, l} = macs(mult, sample, 0, 0); {h, l} = macs(mult, sample, 0, 0);
//h <<= 3 done on other side */ //h <<= 3 done on other side */
outuint(c, h); outuint(c, h);
#else #else
outuint(c,sample); outuint(c,sample);
@@ -196,7 +196,7 @@ static void getSamplesFromHost(chanend c, xc_ptr samples, int base, unsigned und
int h; int h;
unsigned l; unsigned l;
#endif #endif
/* Receive sample from decouple */ /* Receive sample from decouple */
sample = inuint(c); sample = inuint(c);
#if defined (LEVEL_METER_HOST) || defined(LEVEL_METER_LEDS) #if defined (LEVEL_METER_HOST) || defined(LEVEL_METER_LEDS)
@@ -229,7 +229,7 @@ static void giveSamplesToDevice(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr mu
if(!underflow) if(!underflow)
{ {
#pragma loop unroll #pragma loop unroll
for (int i=0;i<NUM_USB_CHAN_OUT;i++) for (int i=0;i<NUM_USB_CHAN_OUT;i++)
{ {
int sample,x; int sample,x;
#if defined(OUT_VOLUME_IN_MIXER) && defined(OUT_VOLUME_AFTER_MIX) #if defined(OUT_VOLUME_IN_MIXER) && defined(OUT_VOLUME_AFTER_MIX)
@@ -264,7 +264,7 @@ static void getSamplesFromDevice(chanend c, xc_ptr samples, int base)
#endif #endif
#pragma loop unroll #pragma loop unroll
for (int i=0;i<NUM_USB_CHAN_IN;i++) for (int i=0;i<NUM_USB_CHAN_IN;i++)
{ {
int sample; int sample;
int x; int x;
@@ -296,7 +296,7 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2)
int mixed; int mixed;
unsigned cmd; unsigned cmd;
while (1) while (1)
{ {
#pragma xta endpoint "mixer1_req" #pragma xta endpoint "mixer1_req"
/* Request from audio() */ /* Request from audio() */
@@ -304,14 +304,14 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2)
/* Request data from decouple thread */ /* Request data from decouple thread */
outuint(c_host, 0); outuint(c_host, 0);
/* Between request to decouple and respose ~ 400nS latency for interrupt to fire */ /* Between request to decouple and respose ~ 400nS latency for interrupt to fire */
select select
{ {
case inuint_byref(c_mix_ctl, cmd): case inuint_byref(c_mix_ctl, cmd):
{ {
int mix, index, val; int mix, index, val;
switch (cmd) switch (cmd)
{ {
#if MAX_MIX_COUNT > 0 #if MAX_MIX_COUNT > 0
case SET_SAMPLES_TO_HOST_MAP: 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); inct(c_mix_ctl);
write_via_xc_ptr_indexed(samples_to_device_map,index,val); write_via_xc_ptr_indexed(samples_to_device_map,index,val);
break; break;
case SET_MIX_MULT: case SET_MIX_MULT:
mix = inuint(c_mix_ctl); mix = inuint(c_mix_ctl);
index = 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); write_word_to_mix_mult(mix, index, val);
break; break;
case SET_MIX_MAP: case SET_MIX_MAP:
mix = inuint(c_mix_ctl); mix = inuint(c_mix_ctl);
index = inuint(c_mix_ctl); /* mixer input */ 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); outct(c_mix_ctl, XS1_CT_END);
samples_to_host_streams[index] = 0; samples_to_host_streams[index] = 0;
break; break;
case GET_INPUT_LEVELS: case GET_INPUT_LEVELS:
index = inuint(c_mix_ctl); index = inuint(c_mix_ctl);
chkct(c_mix_ctl, XS1_CT_END); chkct(c_mix_ctl, XS1_CT_END);
#ifdef LEVEL_METER_LEDS #ifdef LEVEL_METER_LEDS
/* Level LEDS process reseting samples_to_host_inputs /* Level LEDS process reseting samples_to_host_inputs
* Other side makes sure we don't miss a peak */ * Other side makes sure we don't miss a peak */
read_via_xc_ptr_indexed(val, samples_to_host_inputs_buff, index); read_via_xc_ptr_indexed(val, samples_to_host_inputs_buff, index);
write_via_xc_ptr_indexed(samples_to_host_inputs_buff, index, 0); 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); outct(c_mix_ctl, XS1_CT_END);
break; break;
#if MAX_MIX_COUNT > 0 #if MAX_MIX_COUNT > 0
case GET_OUTPUT_LEVELS: case GET_OUTPUT_LEVELS:
index = inuint(c_mix_ctl); index = inuint(c_mix_ctl);
chkct(c_mix_ctl, XS1_CT_END); 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; mixer1_mix2_flag = sampFreq > 96000;
#pragma loop unroll #pragma loop unroll
for (int i=0;i<MAX_MIX_COUNT;i++) for (int i=0;i<MAX_MIX_COUNT;i++)
{ {
write_via_xc_ptr_indexed(samples, (NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + i), 0); write_via_xc_ptr_indexed(samples, (NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + i), 0);
} }
@@ -442,7 +442,7 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2)
chkct(c_mixer2, XS1_CT_END); chkct(c_mixer2, XS1_CT_END);
outct(c_host, XS1_CT_END); outct(c_host, XS1_CT_END);
} }
else else
{ {
unsigned underflow = inuint(c_host); unsigned underflow = inuint(c_host);
#if MAX_MIX_COUNT > 0 #if MAX_MIX_COUNT > 0
@@ -465,9 +465,9 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2)
ComputeMixerLevel(mixed, 0); ComputeMixerLevel(mixed, 0);
#endif #endif
#if (MAX_FREQ > 96000) #if (MAX_FREQ > 96000)
if (!mixer1_mix2_flag) if (!mixer1_mix2_flag)
#endif #endif
{ {
#if MAX_MIX_COUNT > 2 #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); static int mixer2_mix2_flag = (DEFAULT_FREQ > 96000);
#if (MAX_MIX_COUNT > 0) #if (MAX_MIX_COUNT > 0)
#pragma unsafe arrays #pragma unsafe arrays
static void mixer2(chanend c_mixer1, chanend c_audio) 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); outuint(c_mixer1, 0);
#pragma xta endpoint "mixer2_req" #pragma xta endpoint "mixer2_req"
inuint(c_audio); inuint(c_audio);
if(testct(c_mixer1)) if(testct(c_mixer1))
{ {
int sampFreq; int sampFreq;
#pragma xta endpoint "mixer2_rate_change" #pragma xta endpoint "mixer2_rate_change"
@@ -541,8 +541,8 @@ static void mixer2(chanend c_mixer1, chanend c_audio)
mixer2_mix2_flag = sampFreq > 96000; mixer2_mix2_flag = sampFreq > 96000;
for (int i=0;i<MAX_MIX_COUNT;i++) for (int i=0;i<MAX_MIX_COUNT;i++)
{ {
write_via_xc_ptr_indexed(samples, (NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + i), 0); write_via_xc_ptr_indexed(samples, (NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + i), 0);
} }
@@ -569,7 +569,7 @@ static void mixer2(chanend c_mixer1, chanend c_audio)
mixed = doMix1(samples, mix_mult_slice(1)); mixed = doMix1(samples, mix_mult_slice(1));
#else #else
mixed = doMix(samples,mix_map_slice(1),mix_mult_slice(1)); mixed = doMix(samples,mix_map_slice(1),mix_mult_slice(1));
#endif #endif
write_via_xc_ptr_indexed(samples, (NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + 1), mixed); write_via_xc_ptr_indexed(samples, (NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + 1), mixed);
@@ -580,8 +580,8 @@ static void mixer2(chanend c_mixer1, chanend c_audio)
#if (MAX_FREQ > 96000) #if (MAX_FREQ > 96000)
if (!mixer2_mix2_flag) if (!mixer2_mix2_flag)
#endif #endif
{ {
#if MAX_MIX_COUNT > 3 #if MAX_MIX_COUNT > 3
@@ -610,7 +610,7 @@ static void mixer2(chanend c_mixer1, chanend c_audio)
ComputeMixerLevel(mixed, 5); ComputeMixerLevel(mixed, 5);
#endif #endif
#endif #endif
#if MAX_MIX_COUNT > 7 #if MAX_MIX_COUNT > 7
#ifdef FAST_MIXER #ifdef FAST_MIXER
mixed = doMix7(samples, mix_mult_slice(7)); 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
#endif #endif
for (int i=0;i<NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT;i++) for (int i=0;i<NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT;i++)
{ {
write_via_xc_ptr_indexed(samples,i,0); write_via_xc_ptr_indexed(samples,i,0);
} }
{ {
int num_mixes = DEFAULT_FREQ > 96000 ? 2 : MAX_MIX_COUNT; int num_mixes = DEFAULT_FREQ > 96000 ? 2 : MAX_MIX_COUNT;
for (int i=0;i<NUM_USB_CHAN_OUT;i++) for (int i=0;i<NUM_USB_CHAN_OUT;i++)
{ {
//samples_to_device_map_array[i] = i; //samples_to_device_map_array[i] = i;
asm("stw %0, %1[%2]":: "r"(i), "r"(samples_to_device_map), "r"(i)); asm("stw %0, %1[%2]":: "r"(i), "r"(samples_to_device_map), "r"(i));
@@ -664,27 +664,27 @@ void mixer(chanend c_mix_in, chanend c_mix_out, chanend c_mix_ctl)
} }
#ifdef OUT_VOLUME_IN_MIXER #ifdef OUT_VOLUME_IN_MIXER
for (int i=0;i<NUM_USB_CHAN_OUT;i++) for (int i=0;i<NUM_USB_CHAN_OUT;i++)
{ {
write_via_xc_ptr_indexed(multOut, i, MAX_VOL); write_via_xc_ptr_indexed(multOut, i, MAX_VOL);
} }
#endif #endif
#ifdef IN_VOLUME_IN_MIXER #ifdef IN_VOLUME_IN_MIXER
for (int i=0;i<NUM_USB_CHAN_IN;i++) for (int i=0;i<NUM_USB_CHAN_IN;i++)
{ {
write_via_xc_ptr_indexed(multIn, i, MAX_VOL); write_via_xc_ptr_indexed(multIn, i, MAX_VOL);
} }
#endif #endif
for (int i=0;i<NUM_USB_CHAN_IN;i++) for (int i=0;i<NUM_USB_CHAN_IN;i++)
{ {
write_via_xc_ptr_indexed(samples_to_host_map, i, NUM_USB_CHAN_OUT + i); write_via_xc_ptr_indexed(samples_to_host_map, i, NUM_USB_CHAN_OUT + i);
} }
#if MAX_MIX_COUNT> 0 #if MAX_MIX_COUNT> 0
for (int i=0;i<MAX_MIX_COUNT;i++) for (int i=0;i<MAX_MIX_COUNT;i++)
for (int j=0;j<MIX_INPUTS;j++) for (int j=0;j<MIX_INPUTS;j++)
{ {
#ifndef FAST_MIXER #ifndef FAST_MIXER
write_word_to_mix_map(i,j, j < 16 ? j : j + 2); write_word_to_mix_map(i,j, j < 16 ? j : j + 2);
@@ -694,9 +694,9 @@ void mixer(chanend c_mix_in, chanend c_mix_out, chanend c_mix_ctl)
#endif #endif
par par
{ {
#if (MAX_MIX_COUNT > 0) #if (MAX_MIX_COUNT > 0)
mixer1(c_mix_in, c_mix_ctl, c); mixer1(c_mix_in, c_mix_ctl, c);
mixer2(c, c_mix_out); mixer2(c, c_mix_out);
#else #else

View File

@@ -11,9 +11,9 @@
#if DSD_CHANS_DAC > 0 #if DSD_CHANS_DAC > 0
port p_dsd_dac[DSD_CHANS_DAC] = { port p_dsd_dac[DSD_CHANS_DAC] = {
PORT_DSD_DAC0, PORT_DSD_DAC0,
#endif #endif
#if DSD_CHANS_DAC > 1 #if DSD_CHANS_DAC > 1
PORT_DSD_DAC1, PORT_DSD_DAC1,
#endif #endif
#if DSD_CHANS_DAC > 2 #if DSD_CHANS_DAC > 2
#error > 2 DSD chans currently not supported #error > 2 DSD chans currently not supported
@@ -44,14 +44,14 @@ void ConfigAudioPortsWrapper(
#if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0) #if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0)
#ifndef CODEC_MASTER #ifndef CODEC_MASTER
port p_lrclk, port p_lrclk,
port p_bclk, port p_bclk,
#else #else
in port p_lrclk, in port p_lrclk,
in port p_bclk, in port p_bclk,
#endif #endif
#endif #endif
unsigned int divide, unsigned int dsdMode) unsigned int divide, unsigned int dsdMode)
{ {
if(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 */ /* 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++) 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( ConfigAudioPorts(
#if (DSD_CHANS_DAC != 0) #if (DSD_CHANS_DAC != 0)
@@ -87,7 +87,7 @@ unsigned int divide, unsigned int dsdMode)
else else
{ {
ConfigAudioPorts( ConfigAudioPorts(
#if (I2S_CHANS_DAC != 0) #if (I2S_CHANS_DAC != 0)
p_i2s_dac, p_i2s_dac,
I2S_WIRES_DAC, I2S_WIRES_DAC,
#endif #endif
@@ -104,7 +104,7 @@ unsigned int divide, unsigned int dsdMode)
p_bclk, p_bclk,
#endif #endif
#endif #endif
divide); divide);
} }
} }
#endif #endif

View File

@@ -8,7 +8,7 @@ void ConfigAudioPorts_dsd(unsigned int divide);
#ifdef __XC__ #ifdef __XC__
void ConfigAudioPorts( void ConfigAudioPorts(
#if (I2S_CHANS_DAC != 0) || (DSD_CHANS_DAC != 0) #if (I2S_CHANS_DAC != 0) || (DSD_CHANS_DAC != 0)
buffered out port:32 p_i2s_dac[], buffered out port:32 p_i2s_dac[],
int numDacPorts, int numDacPorts,
@@ -32,7 +32,7 @@ void ConfigAudioPorts(
unsigned int divide); unsigned int divide);
#else #else
void ConfigAudioPorts( void ConfigAudioPorts(
#if (I2S_CHANS_DAC != 0) || (DSD_CHANS_DAC != 0) #if (I2S_CHANS_DAC != 0) || (DSD_CHANS_DAC != 0)
port p_i2s_dac[], port p_i2s_dac[],
int numDacPorts, int numDacPorts,
@@ -59,7 +59,7 @@ void ConfigAudioPorts(
#ifdef __XC__ #ifdef __XC__
void ConfigAudioPortsWrapper( void ConfigAudioPortsWrapper(
#if (I2S_CHANS_DAC != 0) #if (I2S_CHANS_DAC != 0)
buffered out port:32 p_i2s_dac[I2S_WIRES_DAC], buffered out port:32 p_i2s_dac[I2S_WIRES_DAC],
#endif #endif
@@ -80,7 +80,7 @@ void ConfigAudioPortsWrapper(
unsigned int divide, unsigned int dsdMode); unsigned int divide, unsigned int dsdMode);
#else #else
void ConfigAudioPortsWrapper( void ConfigAudioPortsWrapper(
#if (I2S_CHANS_DAC != 0) #if (I2S_CHANS_DAC != 0)
port p_i2s_dac[I2S_WIRES_DAC], port p_i2s_dac[I2S_WIRES_DAC],
#endif #endif

View File

@@ -10,7 +10,7 @@ extern clock clk_audio_bclk;
void ConfigAudioPorts( void ConfigAudioPorts(
#if (I2S_CHANS_DAC != 0) || (DSD_CHANS_DAC != 0) #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, int numPortsDac,
#endif #endif
@@ -28,12 +28,12 @@ void ConfigAudioPorts(
in port p_bclk, in port p_bclk,
#endif #endif
#endif #endif
unsigned int divide) unsigned int divide)
{ {
#ifndef CODEC_MASTER #ifndef CODEC_MASTER
/* Note this call to stop_clock() will pause forever if the port clocking the clock-block is not low. /* 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 */ * above can be enabled */
stop_clock(clk_audio_bclk); stop_clock(clk_audio_bclk);
@@ -104,7 +104,7 @@ unsigned int divide)
/* Stop bit and master clock blocks */ /* Stop bit and master clock blocks */
stop_clock(clk_audio_bclk); stop_clock(clk_audio_bclk);
/* Clock bclk clock-block from bclk pin */ /* Clock bclk clock-block from bclk pin */
configure_clock_src(clk_audio_bclk, p_bclk); configure_clock_src(clk_audio_bclk, p_bclk);

View File

@@ -1,7 +1,7 @@
#ifndef ARCH_U_POWER_SAVING_ #ifndef ARCH_U_POWER_SAVING_
#define 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 * and adjusts other features to save power
*/ */
void archU_powerSaving(); void archU_powerSaving();

View File

@@ -36,10 +36,10 @@ void archU_powerSaving()
time += (1 * PLATFORM_REFERENCE_MHZ); // Wait 1us per step time += (1 * PLATFORM_REFERENCE_MHZ); // Wait 1us per step
t when timerafter(time) :> void; t when timerafter(time) :> void;
} }
// Set switch prescaler down // 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 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 // 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_VOUT1_EN_SET(0, 1);
writeval[0] = XS1_SU_PWR_VOUT2_EN_SET(writeval[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_EN_SET(0, 1);
writevalc[0] = XS1_SU_ON_SI_OSC_SLOW_SET(writevalc[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); write_periph_8(usb_tile, XS1_SU_PER_OSC_CHANEND_NUM, XS1_SU_PER_OSC_ON_SI_CTRL_NUM, 1, writevalc);
} }
} }
#endif #endif

View File

@@ -10,7 +10,7 @@ unsigned get_tile_id(tileref);
extern tileref tile[]; extern tileref tile[];
void device_reboot_aux(void) void device_reboot_aux(void)
{ {
#if (XUD_SERIES_SUPPORT == 1) #if (XUD_SERIES_SUPPORT == 1)
/* Disconnect from bus */ /* Disconnect from bus */
@@ -25,15 +25,15 @@ void device_reboot_aux(void)
unsigned int localTileId = get_local_tile_id(); unsigned int localTileId = get_local_tile_id();
unsigned int tileId; unsigned int tileId;
unsigned int tileArrayLength; unsigned int tileArrayLength;
/* Find size of tile array - note in future tools versions this will be available from platform.h */ /* 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)); asm volatile ("ldc %0, tile.globound":"=r"(tileArrayLength));
/* Reset all remote tiles */ /* Reset all remote tiles */
for(int i = 0; i< tileArrayLength; i++) for(int i = 0; i< tileArrayLength; i++)
{ {
/* Cannot cast tileref to unsigned! */ /* Cannot cast tileref to unsigned! */
tileId = get_tile_id(tile[i]); tileId = get_tile_id(tile[i]);
/* Do not reboot local tile yet! */ /* Do not reboot local tile yet! */
if(localTileId != tileId) if(localTileId != tileId)
@@ -42,7 +42,7 @@ void device_reboot_aux(void)
write_sswitch_reg_no_ack(tileId, 6, pllVal); write_sswitch_reg_no_ack(tileId, 6, pllVal);
} }
} }
/* Finally reboot this tile! */ /* Finally reboot this tile! */
read_sswitch_reg(localTileId, 6, pllVal); read_sswitch_reg(localTileId, 6, pllVal);
write_sswitch_reg_no_ack(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 */ /* 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) #if (XUD_SERIES_SUPPORT != 1)
outct(spare, XS1_CT_END); // have to do this before freeing the chanend 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 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 */ /* Need a spare chanend so we can talk to the pll register */
asm("freer res[%0]"::"r"(spare)); asm("freer res[%0]"::"r"(spare));
#endif #endif

View File

@@ -2,9 +2,9 @@
#define __DECOUPLE_H__ #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. * Audio I/O driver.
* *
* \param c_audio_out Channel connected to the audio() or mixer() threads * \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 * \param c_clk_int Optional chanend connected to the clockGen() thread if present
*/ */

View File

@@ -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 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) #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 #ifndef OUT_VOLUME_IN_MIXER
unsigned int multOut[NUM_USB_CHAN_OUT + 1]; unsigned int multOut[NUM_USB_CHAN_OUT + 1];
static xc_ptr p_multOut; 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_start;
xc_ptr aud_from_host_fifo_end; xc_ptr aud_from_host_fifo_end;
xc_ptr g_aud_from_host_wrptr; 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_start;
xc_ptr aud_to_host_fifo_end; xc_ptr aud_to_host_fifo_end;
xc_ptr g_aud_to_host_wrptr; xc_ptr g_aud_to_host_wrptr;
xc_ptr g_aud_to_host_dptr; xc_ptr g_aud_to_host_dptr;
xc_ptr g_aud_to_host_rdptr; xc_ptr g_aud_to_host_rdptr;
xc_ptr g_aud_to_host_zeros; xc_ptr g_aud_to_host_zeros;
int sampsToWrite = 0; int sampsToWrite = 0;
int totalSampsToWrite = 0; int totalSampsToWrite = 0;
int aud_data_remaining_to_device = 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; g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_CLASS_ONE;
} }
#endif #endif
/* If in overflow condition then receive samples and throw away */ /* If in overflow condition then receive samples and throw away */
if(inOverflow || sampsToWrite == 0) if(inOverflow || sampsToWrite == 0)
{ {
#pragma loop unroll #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); (void) inuint(c_mix_out);
} }
/* Calculate how much space left in buffer */ /* Calculate how much space left in buffer */
space_left = g_aud_to_host_rdptr - g_aud_to_host_wrptr; 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 */ /* 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; inOverflow = 0;
} }
@@ -171,7 +171,7 @@ __builtin_unreachable();
#endif #endif
unsigned ptr = g_aud_to_host_dptr; 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 */ /* Receive sample */
int sample = inuint(c_mix_out); int sample = inuint(c_mix_out);
@@ -188,20 +188,20 @@ __builtin_unreachable();
sample = sample << 3; sample = sample << 3;
#endif #endif
/* Write into fifo */ /* Write into fifo */
write_via_xc_ptr(ptr, sample); write_via_xc_ptr(ptr, sample);
ptr+=4; ptr+=4;
} }
/* Update global pointer */ /* Update global pointer */
g_aud_to_host_dptr = ptr; g_aud_to_host_dptr = ptr;
break; break;
} }
case 3: case 3:
#if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3) #if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3)
__builtin_unreachable(); __builtin_unreachable();
#endif #endif
for(int i = 0; i < g_numUsbChanIn; i++) for(int i = 0; i < g_numUsbChanIn; i++)
{ {
/* Receive sample */ /* Receive sample */
int sample = inuint(c_mix_out); int sample = inuint(c_mix_out);
@@ -215,28 +215,28 @@ __builtin_unreachable();
sample = h << 3; sample = h << 3;
#endif #endif
/* Pack 3 byte samples */ /* Pack 3 byte samples */
switch (packState&0x3) switch (packState&0x3)
{ {
case 0: case 0:
packData = sample; packData = sample;
break; break;
case 1: case 1:
packData = (packData >> 8) | ((sample & 0xff00)<<16); 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; 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; packData = sample;
break; break;
case 2: case 2:
packData = (packData>>16) | ((sample & 0xffff00) << 8); 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; g_aud_to_host_dptr+=4;
packData = sample; packData = sample;
break; break;
case 3: case 3:
packData = (packData >> 24) | (sample & 0xffffff00); packData = (packData >> 24) | (sample & 0xffffff00);
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; g_aud_to_host_dptr+=4;
break; break;
} }
packState++; packState++;
@@ -248,7 +248,7 @@ __builtin_unreachable();
#if (SAMPLE_SUBSLOT_SIZE_HS != 2) && (SAMPLE_SUBSLOT_SIZE_FS != 2) #if (SAMPLE_SUBSLOT_SIZE_HS != 2) && (SAMPLE_SUBSLOT_SIZE_FS != 2)
__builtin_unreachable(); __builtin_unreachable();
#endif #endif
for(int i = 0; i < g_numUsbChanIn; i++) for(int i = 0; i < g_numUsbChanIn; i++)
{ {
/* Receive sample */ /* Receive sample */
int sample = inuint(c_mix_out); int sample = inuint(c_mix_out);
@@ -270,12 +270,12 @@ __builtin_unreachable();
switch (packState&0x1) switch (packState&0x1)
{ {
case 0: case 0:
packData = sample; packData = sample;
break; break;
case 1: case 1:
packData = (packData>>16) | (sample & 0xffff0000); packData = (packData>>16) | (sample & 0xffff0000);
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; g_aud_to_host_dptr+=4;
break; break;
} }
} }
@@ -283,24 +283,24 @@ __builtin_unreachable();
default: default:
__builtin_unreachable(); __builtin_unreachable();
break; break;
} }
/* Input any remaining channels - past this thread we always operate on max channel count */ /* 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++) for(int i = 0; i < NUM_USB_CHAN_IN - g_numUsbChanIn; i++)
{ {
inuint(c_mix_out); inuint(c_mix_out);
} }
sampsToWrite--; sampsToWrite--;
} }
if(outUnderflow) if(outUnderflow)
{ {
#pragma xta endpoint "out_underflow" #pragma xta endpoint "out_underflow"
#if 0 #if 0
/* We're still pre-buffering, send out 0 samps */ /* 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 sample;
unsigned mode; unsigned mode;
@@ -320,9 +320,9 @@ __builtin_unreachable();
{ {
outSamps += BUFF_SIZE_OUT*4; outSamps += BUFF_SIZE_OUT*4;
} }
/* If we have a decent number of samples, come out of underflow cond */ /* 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; outUnderflow = 0;
outSamps++; outSamps++;
@@ -335,19 +335,19 @@ __builtin_unreachable();
case 4: case 4:
#if (SAMPLE_SUBSLOT_SIZE_HS != 4) && (SAMPLE_SUBSLOT_SIZE_FS != 4) #if (SAMPLE_SUBSLOT_SIZE_HS != 4) && (SAMPLE_SUBSLOT_SIZE_FS != 4)
__builtin_unreachable(); __builtin_unreachable();
#endif #endif
/* Buffering not underflow condition send out some samples...*/ /* 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" #pragma xta endpoint "mixer_request"
int sample; int sample;
int mult; int mult;
int h; int h;
unsigned l; unsigned l;
read_via_xc_ptr(sample, g_aud_from_host_rdptr); read_via_xc_ptr(sample, g_aud_from_host_rdptr);
g_aud_from_host_rdptr+=4; g_aud_from_host_rdptr+=4;
#ifndef OUT_VOLUME_IN_MIXER #ifndef OUT_VOLUME_IN_MIXER
asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i)); asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i));
{h, l} = macs(mult, sample, 0, 0); {h, l} = macs(mult, sample, 0, 0);
@@ -363,13 +363,13 @@ __builtin_unreachable();
} }
break; break;
case 3: case 3:
#if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3) #if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3)
__builtin_unreachable(); __builtin_unreachable();
#endif #endif
/* Buffering not underflow condition send out some samples...*/ /* 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" #pragma xta endpoint "mixer_request"
int sample; int sample;
@@ -378,12 +378,12 @@ __builtin_unreachable();
unsigned l; unsigned l;
/* Unpack 3 byte samples */ /* Unpack 3 byte samples */
switch (unpackState&0x3) switch (unpackState&0x3)
{ {
case 0: case 0:
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; g_aud_from_host_rdptr+=4;
sample = unpackData << 8; sample = unpackData << 8;
break; break;
case 1: case 1:
sample = (unpackData >> 16); sample = (unpackData >> 16);
@@ -393,7 +393,7 @@ __builtin_unreachable();
break; break;
case 2: case 2:
sample = (unpackData >> 8); 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; g_aud_from_host_rdptr+=4;
sample = sample | (unpackData<< 24); sample = sample | (unpackData<< 24);
break; break;
@@ -402,7 +402,7 @@ __builtin_unreachable();
break; break;
} }
unpackState++; unpackState++;
#ifndef OUT_VOLUME_IN_MIXER #ifndef OUT_VOLUME_IN_MIXER
asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i)); asm("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i));
{h, l} = macs(mult, sample, 0, 0); {h, l} = macs(mult, sample, 0, 0);
@@ -418,25 +418,25 @@ __builtin_unreachable();
case 2: case 2:
#if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3) #if (SAMPLE_SUBSLOT_SIZE_HS != 3) && (SAMPLE_SUBSLOT_SIZE_FS != 3)
__builtin_unreachable(); __builtin_unreachable();
#endif #endif
/* Buffering not underflow condition send out some samples...*/ /* 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" #pragma xta endpoint "mixer_request"
int sample; int sample;
int mult; int mult;
int h; int h;
unsigned l; unsigned l;
switch (unpackState&0x1) switch (unpackState&0x1)
{ {
case 0: case 0:
read_via_xc_ptr(unpackData, g_aud_from_host_rdptr); read_via_xc_ptr(unpackData, g_aud_from_host_rdptr);
sample = unpackData << 16; sample = unpackData << 16;
break; break;
case 1: case 1:
g_aud_from_host_rdptr+=4; g_aud_from_host_rdptr+=4;
sample = unpackData & 0xffff0000; sample = unpackData & 0xffff0000;
break; break;
} }
unpackState++; unpackState++;
@@ -451,7 +451,7 @@ __builtin_unreachable();
#endif #endif
} }
break; break;
default: default:
__builtin_unreachable(); __builtin_unreachable();
break; break;
@@ -463,18 +463,18 @@ __builtin_unreachable();
{ {
outuint(c_mix_out, 0); outuint(c_mix_out, 0);
} }
/* 3/4 bytes per sample */ /* 3/4 bytes per sample */
aud_data_remaining_to_device -= (g_numUsbChanOut*g_slotSize); aud_data_remaining_to_device -= (g_numUsbChanOut*g_slotSize);
} }
if (!inOverflow) if (!inOverflow)
{ {
if (sampsToWrite == 0) if (sampsToWrite == 0)
{ {
int speed; int speed;
if (totalSampsToWrite) if (totalSampsToWrite)
{ {
unsigned datasize = totalSampsToWrite * g_slotSize * g_numUsbChanIn; unsigned datasize = totalSampsToWrite * g_slotSize * g_numUsbChanIn;
@@ -482,7 +482,7 @@ __builtin_unreachable();
datasize = (datasize+3) & (~0x3); datasize = (datasize+3) & (~0x3);
g_aud_to_host_wrptr += 4+datasize; g_aud_to_host_wrptr += 4+datasize;
if (g_aud_to_host_wrptr >= aud_to_host_fifo_end) if (g_aud_to_host_wrptr >= aud_to_host_fifo_end)
{ {
g_aud_to_host_wrptr = aud_to_host_fifo_start; g_aud_to_host_wrptr = aud_to_host_fifo_start;
@@ -491,66 +491,66 @@ __builtin_unreachable();
/* Get feedback val - ideally this would be syncronised */ /* Get feedback val - ideally this would be syncronised */
asm("ldw %0, dp[g_speed]" : "=r" (speed) :); 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; speedRem += speed;
totalSampsToWrite = speedRem >> 16; totalSampsToWrite = speedRem >> 16;
speedRem &= 0xffff; speedRem &= 0xffff;
#if 0 #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; 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; totalSampsToWrite = 0;
} }
} }
#else #else
if (totalSampsToWrite < 0 || totalSampsToWrite * g_slotSize * g_numUsbChanIn > g_maxPacketSize) if (totalSampsToWrite < 0 || totalSampsToWrite * g_slotSize * g_numUsbChanIn > g_maxPacketSize)
{ {
totalSampsToWrite = 0; totalSampsToWrite = 0;
} }
#endif #endif
/* Calc slots left in fifo */ /* Calc slots left in fifo */
space_left = g_aud_to_host_rdptr - g_aud_to_host_wrptr; space_left = g_aud_to_host_rdptr - g_aud_to_host_wrptr;
/* Mod and special case */ /* Mod and special case */
if (space_left <= 0 && g_aud_to_host_rdptr == aud_to_host_fifo_start) 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; 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 */ /* Packet okay, write to fifo */
if (totalSampsToWrite) if (totalSampsToWrite)
{ {
write_via_xc_ptr(g_aud_to_host_wrptr, totalSampsToWrite*g_slotSize*g_numUsbChanIn); write_via_xc_ptr(g_aud_to_host_wrptr, totalSampsToWrite*g_slotSize*g_numUsbChanIn);
packState = 0; packState = 0;
g_aud_to_host_dptr = g_aud_to_host_wrptr + 4; g_aud_to_host_dptr = g_aud_to_host_wrptr + 4;
} }
} }
else else
{ {
inOverflow = 1; inOverflow = 1;
totalSampsToWrite = 0; 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 */ /* 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 */ /* Round up to nearest word */
aud_data_remaining_to_device +=3 - (unpackState&0x3); 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); 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); read_via_xc_ptr(aud_data_remaining_to_device, g_aud_from_host_rdptr);
unpackState = 0; unpackState = 0;
g_aud_from_host_rdptr+=4; 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); //XUD_SetReady(int_usb_ep, 0);
//asm("ldaw %0, dp[g_intData]":"=r"(x)); //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; 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 #pragma unsafe arrays
void decouple(chanend c_mix_out, void decouple(chanend c_mix_out,
chanend ?c_clk_int chanend ?c_clk_int
#ifdef CHAN_BUFF_CTRL #ifdef CHAN_BUFF_CTRL
, chanend c_buf_ctrl , chanend c_buf_ctrl
#endif #endif
) )
{ {
unsigned sampFreq = DEFAULT_FREQ; unsigned sampFreq = DEFAULT_FREQ;
#ifdef OUTPUT #ifdef OUTPUT
int aud_from_host_flag=0; int aud_from_host_flag=0;
xc_ptr released_buffer; xc_ptr released_buffer;
#endif #endif
#ifdef INPUT #ifdef INPUT
int aud_to_host_flag = 0; int aud_to_host_flag = 0;
#endif #endif
int t = array_to_xc_ptr(outAudioBuff); int t = array_to_xc_ptr(outAudioBuff);
int aud_in_ready = 0; 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_start = t;
aud_from_host_fifo_end = aud_from_host_fifo_start + BUFF_SIZE_OUT*4; 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_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); t = array_to_xc_ptr(audioBuffIn);
aud_to_host_fifo_start = t; aud_to_host_fifo_start = t;
aud_to_host_fifo_end = aud_to_host_fifo_start + BUFF_SIZE_IN*4; 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_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); t = array_to_xc_ptr(inZeroBuff);
g_aud_to_host_zeros = t; g_aud_to_host_zeros = t;
/* Init interrupt report */ /* Init interrupt report */
g_intData[0] = 0; // Class-specific, caused by interface g_intData[0] = 0; // Class-specific, caused by interface
g_intData[1] = 1; // attribute: CUR 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)); asm("stw %0, %1[%2]"::"r"(MAX_VOL),"r"(p_multOut),"r"(i));
} }
#endif #endif
#ifndef IN_VOLUME_IN_MIXER #ifndef IN_VOLUME_IN_MIXER
for (int i = 0; i < NUM_USB_CHAN_IN + 1; i++) for (int i = 0; i < NUM_USB_CHAN_IN + 1; i++)
{ {
@@ -698,11 +698,11 @@ void decouple(chanend c_mix_out,
#ifdef OUTPUT #ifdef OUTPUT
// wait for usb_buffer to set up // 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); GET_SHARED_GLOBAL(aud_from_host_flag, g_aud_from_host_flag);
} }
aud_from_host_flag = 0; aud_from_host_flag = 0;
SET_SHARED_GLOBAL(g_aud_from_host_flag, aud_from_host_flag); SET_SHARED_GLOBAL(g_aud_from_host_flag, aud_from_host_flag);
@@ -713,11 +713,11 @@ void decouple(chanend c_mix_out,
#ifdef INPUT #ifdef INPUT
// Wait for usb_buffer to set up // 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); GET_SHARED_GLOBAL(aud_to_host_flag, g_aud_to_host_flag);
} }
aud_to_host_flag = 0; aud_to_host_flag = 0;
SET_SHARED_GLOBAL(g_aud_to_host_flag, aud_to_host_flag); 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); GET_SHARED_GLOBAL(p, g_aud_to_host_buffer);
read_via_xc_ptr(len, p) read_via_xc_ptr(len, p)
XUD_SetReady_InPtr(aud_to_host_usb_ep, g_aud_to_host_buffer, len); XUD_SetReady_InPtr(aud_to_host_usb_ep, g_aud_to_host_buffer, len);
aud_in_ready = 1; aud_in_ready = 1;
} }
#endif #endif
@@ -762,24 +762,24 @@ void decouple(chanend c_mix_out,
} }
#endif #endif
if (!isnull(c_clk_int)) if (!isnull(c_clk_int))
{ {
check_for_interrupt(c_clk_int); check_for_interrupt(c_clk_int);
} }
{ {
asm("#decouple-default"); asm("#decouple-default");
/* Check for freq change or other update */ /* Check for freq change or other update */
GET_SHARED_GLOBAL(tmp, g_freqChange_flag); GET_SHARED_GLOBAL(tmp, g_freqChange_flag);
if (tmp == SET_SAMPLE_FREQ) if (tmp == SET_SAMPLE_FREQ)
{ {
SET_SHARED_GLOBAL(g_freqChange_flag, 0); SET_SHARED_GLOBAL(g_freqChange_flag, 0);
GET_SHARED_GLOBAL(sampFreq, g_freqChange_sampFreq); GET_SHARED_GLOBAL(sampFreq, g_freqChange_sampFreq);
/* Pass on to mixer */ /* Pass on to mixer */
DISABLE_INTERRUPTS(); DISABLE_INTERRUPTS();
inuint(c_mix_out); inuint(c_mix_out);
outct(c_mix_out, SET_SAMPLE_FREQ); outct(c_mix_out, SET_SAMPLE_FREQ);
outuint(c_mix_out, sampFreq); outuint(c_mix_out, sampFreq);
@@ -792,7 +792,7 @@ void decouple(chanend c_mix_out,
aud_to_host_fifo_start); aud_to_host_fifo_start);
SET_SHARED_GLOBAL(sampsToWrite, 0); SET_SHARED_GLOBAL(sampsToWrite, 0);
SET_SHARED_GLOBAL(totalSampsToWrite, 0); SET_SHARED_GLOBAL(totalSampsToWrite, 0);
/* Set buffer to send back to zeros buffer */ /* Set buffer to send back to zeros buffer */
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);
@@ -801,7 +801,7 @@ void decouple(chanend c_mix_out,
int min, mid, max, usb_speed; int min, mid, max, usb_speed;
GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed); GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed);
GetADCCounts(sampFreq, min, mid, max); GetADCCounts(sampFreq, min, mid, max);
if (usb_speed == XUD_SPEED_HS) if (usb_speed == XUD_SPEED_HS)
mid*=NUM_USB_CHAN_IN*4; mid*=NUM_USB_CHAN_IN*4;
else else
mid*=NUM_USB_CHAN_IN_A1*3; mid*=NUM_USB_CHAN_IN_A1*3;
@@ -815,23 +815,23 @@ void decouple(chanend c_mix_out,
{ {
xc_ptr p; xc_ptr p;
int len; int len;
GET_SHARED_GLOBAL(p, g_aud_to_host_buffer); GET_SHARED_GLOBAL(p, g_aud_to_host_buffer);
read_via_xc_ptr(len, p); read_via_xc_ptr(len, p);
/* Update packet size */ /* Update packet size */
XUD_SetReady_InPtr(aud_to_host_usb_ep, p+4, len); XUD_SetReady_InPtr(aud_to_host_usb_ep, p+4, len);
} }
/* Reset OUT buffer state */ /* Reset OUT buffer state */
outUnderflow = 1; 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(g_aud_from_host_wrptr, aud_from_host_fifo_start);
SET_SHARED_GLOBAL(aud_data_remaining_to_device, 0); SET_SHARED_GLOBAL(aud_data_remaining_to_device, 0);
if(outOverflow) 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); XUD_SetReady_OutPtr(aud_from_host_usb_ep, aud_from_host_fifo_start+4);
outOverflow = 0; outOverflow = 0;
} }
@@ -842,7 +842,7 @@ void decouple(chanend c_mix_out,
SET_SHARED_GLOBAL(g_freqChange, 0); SET_SHARED_GLOBAL(g_freqChange, 0);
asm("outct res[%0],%1"::"r"(buffer_aud_ctl_chan),"r"(XS1_CT_END)); asm("outct res[%0],%1"::"r"(buffer_aud_ctl_chan),"r"(XS1_CT_END));
ENABLE_INTERRUPTS(); ENABLE_INTERRUPTS();
speedRem = 0; speedRem = 0;
@@ -851,11 +851,11 @@ void decouple(chanend c_mix_out,
else if(tmp == SET_CHAN_COUNT_IN) else if(tmp == SET_CHAN_COUNT_IN)
{ {
/* Change in IN channel count */ /* Change in IN channel count */
DISABLE_INTERRUPTS(); DISABLE_INTERRUPTS();
SET_SHARED_GLOBAL(g_freqChange_flag, 0); SET_SHARED_GLOBAL(g_freqChange_flag, 0);
GET_SHARED_GLOBAL(g_numUsbChanIn, g_freqChange_sampFreq); /* Misuse of g_freqChange_sampFreq */ GET_SHARED_GLOBAL(g_numUsbChanIn, g_freqChange_sampFreq); /* Misuse of g_freqChange_sampFreq */
/* Reset IN buffer state */ /* Reset IN buffer state */
inOverflow = 0; inOverflow = 0;
inUnderflow = 1; inUnderflow = 1;
SET_SHARED_GLOBAL(g_aud_to_host_rdptr, aud_to_host_fifo_start); 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(sampsToWrite, 0);
SET_SHARED_GLOBAL(totalSampsToWrite, 0); SET_SHARED_GLOBAL(totalSampsToWrite, 0);
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);
SET_SHARED_GLOBAL(g_freqChange, 0); SET_SHARED_GLOBAL(g_freqChange, 0);
ENABLE_INTERRUPTS(); ENABLE_INTERRUPTS();
} }
else if(tmp == SET_CHAN_COUNT_OUT) else if(tmp == SET_CHAN_COUNT_OUT)
{ {
/* Change in OUT channel count */ /* Change in OUT channel count */
DISABLE_INTERRUPTS(); DISABLE_INTERRUPTS();
SET_SHARED_GLOBAL(g_freqChange_flag, 0); SET_SHARED_GLOBAL(g_freqChange_flag, 0);
GET_SHARED_GLOBAL(g_numUsbChanOut, g_freqChange_sampFreq); /* Misuse of g_freqChange_sampFreq */ 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_rdptr, aud_from_host_fifo_start);
SET_SHARED_GLOBAL(g_aud_from_host_wrptr, aud_from_host_fifo_start); SET_SHARED_GLOBAL(g_aud_from_host_wrptr, aud_from_host_fifo_start);
outUnderflow = 1; outUnderflow = 1;
if(outOverflow) 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); XUD_SetReady_OutPtr(aud_from_host_usb_ep, aud_from_host_fifo_start+4);
outOverflow = 0; outOverflow = 0;
} }
SET_SHARED_GLOBAL(g_freqChange, 0); SET_SHARED_GLOBAL(g_freqChange, 0);
ENABLE_INTERRUPTS(); ENABLE_INTERRUPTS();
} }
@@ -893,34 +893,34 @@ void decouple(chanend c_mix_out,
else if(tmp == SET_DSD_MODE) else if(tmp == SET_DSD_MODE)
{ {
unsigned dsdMode; unsigned dsdMode;
DISABLE_INTERRUPTS(); DISABLE_INTERRUPTS();
/* Clear the buffer as we dont want to send out old PCM samples.. */ /* Clear the buffer as we dont want to send out old PCM samples.. */
SET_SHARED_GLOBAL(g_freqChange_flag, 0); SET_SHARED_GLOBAL(g_freqChange_flag, 0);
GET_SHARED_GLOBAL(dsdMode, g_freqChange_sampFreq); /* Misuse of g_freqChange_sampFreq */ 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_rdptr, aud_from_host_fifo_start);
SET_SHARED_GLOBAL(g_aud_from_host_wrptr, aud_from_host_fifo_start); SET_SHARED_GLOBAL(g_aud_from_host_wrptr, aud_from_host_fifo_start);
outUnderflow = 1; outUnderflow = 1;
if(outOverflow) 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); XUD_SetReady_OutPtr(aud_from_host_usb_ep, aud_from_host_fifo_start+4);
outOverflow = 0; outOverflow = 0;
} }
inuint(c_mix_out); inuint(c_mix_out);
outct(c_mix_out, SET_DSD_MODE); outct(c_mix_out, SET_DSD_MODE);
outuint(c_mix_out, dsdMode); outuint(c_mix_out, dsdMode);
/* Wait for handshake back */ /* Wait for handshake back */
chkct(c_mix_out, XS1_CT_END); chkct(c_mix_out, XS1_CT_END);
SET_SHARED_GLOBAL(g_freqChange, 0); SET_SHARED_GLOBAL(g_freqChange, 0);
asm("outct res[%0],%1"::"r"(buffer_aud_ctl_chan),"r"(XS1_CT_END)); asm("outct res[%0],%1"::"r"(buffer_aud_ctl_chan),"r"(XS1_CT_END));
ENABLE_INTERRUPTS(); ENABLE_INTERRUPTS();
} }
#endif #endif
@@ -938,17 +938,17 @@ void decouple(chanend c_mix_out,
int aud_from_host_rdptr; int aud_from_host_rdptr;
GET_SHARED_GLOBAL(aud_from_host_wrptr, g_aud_from_host_wrptr); GET_SHARED_GLOBAL(aud_from_host_wrptr, g_aud_from_host_wrptr);
GET_SHARED_GLOBAL(aud_from_host_rdptr, g_aud_from_host_rdptr); GET_SHARED_GLOBAL(aud_from_host_rdptr, g_aud_from_host_rdptr);
SET_SHARED_GLOBAL(g_aud_from_host_flag, 0); SET_SHARED_GLOBAL(g_aud_from_host_flag, 0);
GET_SHARED_GLOBAL(released_buffer, g_aud_from_host_buffer); GET_SHARED_GLOBAL(released_buffer, g_aud_from_host_buffer);
/* Read datalength from buffer */ /* Read datalength from buffer */
read_via_xc_ptr(datalength, released_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)) 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 */ /* 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; 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); 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 */ * back to the buffer thread */
space_left = aud_from_host_rdptr - aud_from_host_wrptr; space_left = aud_from_host_rdptr - aud_from_host_wrptr;
/* Mod and special case */ /* Mod and special case */
if(space_left <= 0 && g_aud_from_host_rdptr == aud_from_host_fifo_start) 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; 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); 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); XUD_SetReady_OutPtr(aud_from_host_usb_ep, aud_from_host_wrptr+4);
} }
else else
{ {
/* Enter OUT over flow state */ /* Enter OUT over flow state */
outOverflow = 1; outOverflow = 1;
#ifdef DEBUG_LEDS #ifdef DEBUG_LEDS
led(c_led); led(c_led);
#endif #endif
} }
continue; continue;
} }
else if (outOverflow) else if (outOverflow)
{ {
int space_left; int space_left;
int aud_from_host_wrptr; 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_wrptr, g_aud_from_host_wrptr);
GET_SHARED_GLOBAL(aud_from_host_rdptr, g_aud_from_host_rdptr); GET_SHARED_GLOBAL(aud_from_host_rdptr, g_aud_from_host_rdptr);
space_left = aud_from_host_rdptr - aud_from_host_wrptr; space_left = aud_from_host_rdptr - aud_from_host_wrptr;
if (space_left <= 0) if (space_left <= 0)
space_left += BUFF_SIZE_OUT*4; 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 */ /* Come out of OUT overflow state */
outOverflow = 0; outOverflow = 0;
@@ -1012,19 +1012,19 @@ void decouple(chanend c_mix_out,
#endif #endif
#ifdef INPUT #ifdef INPUT
{ {
/* Check if buffer() has sent a packet to host - uses shared mem flag to save chanends */ /* Check if buffer() has sent a packet to host - uses shared mem flag to save chanends */
int tmp; int tmp;
GET_SHARED_GLOBAL(tmp, g_aud_to_host_flag); GET_SHARED_GLOBAL(tmp, g_aud_to_host_flag);
//case inuint_byref(c_buf_in, tmp): //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 */ /* Reset flag */
SET_SHARED_GLOBAL(g_aud_to_host_flag, 0); SET_SHARED_GLOBAL(g_aud_to_host_flag, 0);
aud_in_ready = 0; aud_in_ready = 0;
if (inUnderflow) if (inUnderflow)
{ {
int aud_to_host_wrptr; int aud_to_host_wrptr;
int aud_to_host_rdptr; int aud_to_host_rdptr;
@@ -1038,18 +1038,18 @@ void decouple(chanend c_mix_out,
if (fill_level < 0) if (fill_level < 0)
fill_level += BUFF_SIZE_IN*4; fill_level += BUFF_SIZE_IN*4;
if (fill_level >= IN_BUFFER_PREFILL) if (fill_level >= IN_BUFFER_PREFILL)
{ {
inUnderflow = 0; inUnderflow = 0;
SET_SHARED_GLOBAL(g_aud_to_host_buffer, aud_to_host_rdptr); 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 */ /* Not in IN underflow state */
int datalength; int datalength;
@@ -1068,7 +1068,7 @@ void decouple(chanend c_mix_out,
SET_SHARED_GLOBAL(g_aud_to_host_rdptr, aud_to_host_rdptr); SET_SHARED_GLOBAL(g_aud_to_host_rdptr, aud_to_host_rdptr);
/* Check for read pointer hitting write pointer - underflow */ /* 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); SET_SHARED_GLOBAL(g_aud_to_host_buffer, aud_to_host_rdptr);
} }
@@ -1076,13 +1076,13 @@ void decouple(chanend c_mix_out,
{ {
inUnderflow = 1; inUnderflow = 1;
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);
} }
} }
/* Request to send packet */ /* Request to send packet */
{ {
int p, len; int p, len;
GET_SHARED_GLOBAL(p, g_aud_to_host_buffer); GET_SHARED_GLOBAL(p, g_aud_to_host_buffer);
asm("ldw %0, %1[0]":"=r"(len):"r"(p)); asm("ldw %0, %1[0]":"=r"(len):"r"(p));
XUD_SetReady_InPtr(aud_to_host_usb_ep, p+4, len); XUD_SetReady_InPtr(aud_to_host_usb_ep, p+4, len);

View File

@@ -1,9 +1,9 @@
extern unsigned int g_curUsbSpeed; extern unsigned int g_curUsbSpeed;
#define XUD_SPEED_HS 2 #define XUD_SPEED_HS 2
/* Returns the max and min packet sizes to send back to host for a given sample frequency /* 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) * 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; * Audio samples per frame = INT(sampFreq/frametime); Variation allowed is + 1;
* *
* For HS frame time = 8 * 1000 * For HS frame time = 8 * 1000
@@ -16,7 +16,7 @@ extern unsigned int g_curUsbSpeed;
* *
* Note: Assumes HS (i.e. 8 frames per 1ms) * Note: Assumes HS (i.e. 8 frames per 1ms)
* *
* Examples: * Examples:
* 44100: min: 5 max: 6 * 44100: min: 5 max: 6
* 48000: min: 5 max: 7 * 48000: min: 5 max: 7
* 96000: min: 11 max: 13 * 96000: min: 11 max: 13
@@ -30,9 +30,9 @@ void GetADCCounts(unsigned samFreq, int *min, int *mid, int *max)
unsigned frameTime; unsigned frameTime;
int usb_speed; int usb_speed;
usb_speed = g_curUsbSpeed; usb_speed = g_curUsbSpeed;
if (usb_speed == XUD_SPEED_HS) if (usb_speed == XUD_SPEED_HS)
frameTime = 8000; frameTime = 8000;
else else
frameTime = 1000; frameTime = 1000;
*min = samFreq / frameTime; *min = samFreq / frameTime;
@@ -40,7 +40,7 @@ void GetADCCounts(unsigned samFreq, int *min, int *mid, int *max)
*mid = *min; *mid = *min;
/* Check for INT(SampFreq/8000) == SampFreq/8000 */ /* Check for INT(SampFreq/8000) == SampFreq/8000 */
if((samFreq % frameTime) == 0) if((samFreq % frameTime) == 0)
{ {
*min -= 1; *min -= 1;

View File

@@ -2,23 +2,23 @@
#define __interrupt_h__ #define __interrupt_h__
#define store_args0(c) \ #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) \ #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) \ #define store_args2(c,x0,x1) \
asm("kentsp 21; stw %0, sp[1];" \ asm("kentsp 21; stw %0, sp[1];" \
"stw %1, sp[2];" \ "stw %1, sp[2];" \
"stw %2, sp[3];" \ "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) \ #define store_args3(c,x0,x1,x2) \
asm("kentsp 22; stw %0, sp[1];" \ asm("kentsp 22; stw %0, sp[1];" \
"stw %1, sp[2];" \ "stw %1, sp[2];" \
"stw %2, sp[3];" \ "stw %2, sp[3];" \
"stw %3, sp[4];" \ "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) \ #define store_args4(c,x0,x1,x2,x3) \
asm("kentsp 23; stw %4, sp[1];" \ asm("kentsp 23; stw %4, sp[1];" \
@@ -26,7 +26,7 @@
"stw %1, sp[3];" \ "stw %1, sp[3];" \
"stw %2, sp[4];" \ "stw %2, sp[4];" \
"stw %3, sp[5];" \ "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) \ #define store_args5(c,x0,x1,x2,x3,x4) \
asm("kentsp 24;" \ asm("kentsp 24;" \
@@ -36,7 +36,7 @@
"stw %1, sp[4];" \ "stw %1, sp[4];" \
"stw %2, sp[5];" \ "stw %2, sp[5];" \
"stw %3, sp[6];" \ "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) \ #define store_args6(c,x0,x1,x2,x3,x4,x5) \
asm("kentsp 25;" \ asm("kentsp 25;" \
@@ -47,7 +47,7 @@
"stw %1, sp[5];" \ "stw %1, sp[5];" \
"stw %2, sp[6];" \ "stw %2, sp[6];" \
"stw %3, sp[7];" \ "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) \ #define store_args7(c,x0,x1,x2,x3,x4,x5,x6) \
asm("kentsp 26;" \ asm("kentsp 26;" \
@@ -59,7 +59,7 @@
"stw %1, sp[6];" \ "stw %1, sp[6];" \
"stw %2, sp[7];" \ "stw %2, sp[7];" \
"stw %3, sp[8];" \ "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) \ #define store_args8(c,x0,x1,x2,x3,x4,x5,x6,x7) \
asm("kentsp 27;" \ asm("kentsp 27;" \
@@ -72,28 +72,28 @@
"stw %1, sp[7];" \ "stw %1, sp[7];" \
"stw %2, sp[8];" \ "stw %2, sp[8];" \
"stw %3, sp[9];" \ "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) \ #define load_args0(f) \
"ldw r0, sp[1]\n" "ldw r0, sp[1]\n"
#define load_args1(f)\ #define load_args1(f)\
"ldw r0, sp[1]\n" \ "ldw r0, sp[1]\n" \
"ldw r1, sp[2]\n" "ldw r1, sp[2]\n"
#define load_args2(f)\ #define load_args2(f)\
"ldw r0, sp[1]\n" \ "ldw r0, sp[1]\n" \
"ldw r1, sp[2]\n" \ "ldw r1, sp[2]\n" \
"ldw r2, sp[3]\n" "ldw r2, sp[3]\n"
#define load_args3(f)\ #define load_args3(f)\
"ldw r0, sp[1]\n" \ "ldw r0, sp[1]\n" \
"ldw r1, sp[2]\n" \ "ldw r1, sp[2]\n" \
"ldw r2, sp[3]\n" \ "ldw r2, sp[3]\n" \
"ldw r3, sp[4]\n" "ldw r3, sp[4]\n"
#define load_argsn(f, args) \ #define load_argsn(f, args) \
".linkset __"#f"_handler_arg0, "#args"-2\n"\ ".linkset __"#f"_handler_arg0, "#args"-2\n"\
@@ -103,13 +103,13 @@
".linkset __"#f"_handler_arg2, "#args"-0\n"\ ".linkset __"#f"_handler_arg2, "#args"-0\n"\
"ldw r2, sp[" "__"#f"_handler_arg2" "]\n" \ "ldw r2, sp[" "__"#f"_handler_arg2" "]\n" \
".linkset __"#f"_handler_arg3, "#args"+1\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_args4(f) load_argsn(f,4)
#define load_args5(f) load_argsn(f,5) #define load_args5(f) load_argsn(f,5)
#define load_args6(f) load_argsn(f,6) #define load_args6(f) load_argsn(f,6)
#define load_args7(f) load_argsn(f,7) #define load_args7(f) load_argsn(f,7)
#define load_args8(f) load_argsn(f,8) #define load_args8(f) load_argsn(f,8)
#define save_state(f,args) \ #define save_state(f,args) \
".linkset __"#f"_handler_r0_save, "#args"+12\n" \ ".linkset __"#f"_handler_r0_save, "#args"+12\n" \
@@ -123,7 +123,7 @@
".linkset __"#f"_handler_r11_save, "#args"+11\n" \ ".linkset __"#f"_handler_r11_save, "#args"+11\n" \
"stw r11, sp[" "__"#f"_handler_r11_save" "]\n" \ "stw r11, sp[" "__"#f"_handler_r11_save" "]\n" \
".linkset __"#f"_handler_lr_save, "#args"+14\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) \ #define restore_state(f,args) \
"ldw r0, sp[" "__"#f"_handler_r0_save" "]\n" \ "ldw r0, sp[" "__"#f"_handler_r0_save" "]\n" \
@@ -131,7 +131,7 @@
"ldw r2, sp[" "__"#f"_handler_r2_save" "]\n" \ "ldw r2, sp[" "__"#f"_handler_r2_save" "]\n" \
"ldw r3, sp[" "__"#f"_handler_r3_save" "]\n" \ "ldw r3, sp[" "__"#f"_handler_r3_save" "]\n" \
"ldw r11, sp[" "__"#f"_handler_r11_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 #define STRINGIFY0(x) #x

View File

@@ -5,11 +5,11 @@
#pragma select handler #pragma select handler
static inline void testct_byref(chanend c, unsigned &isCt) static inline void testct_byref(chanend c, unsigned &isCt)
{ {
if (testct(c)) if (testct(c))
{ {
isCt = 1; isCt = 1;
} }
else else
{ {
isCt = 0; isCt = 0;
} }

View File

@@ -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 */ /* 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 #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; isCt = 1;
} }
else else
{ {
isCt = 0; isCt = 0;
} }

View File

@@ -16,24 +16,24 @@
* \param c_aud_ctl Audio control channel connected to Endpoint0() * \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) * \param p_off_mclk A port that is clocked of the MCLK input (not the MCLK input itself)
*/ */
void buffer(chanend c_aud_out, void buffer(chanend c_aud_out,
chanend c_aud_in, chanend c_aud_in,
chanend c_aud_fb, chanend c_aud_fb,
#ifdef MIDI #ifdef MIDI
chanend c_midi_from_host, chanend c_midi_from_host,
chanend c_midi_to_host, chanend c_midi_to_host,
chanend c_midi, chanend c_midi,
#endif #endif
#ifdef IAP #ifdef IAP
chanend c_iap_from_host, chanend c_iap_from_host,
chanend c_iap_to_host, chanend c_iap_to_host,
chanend c_iap_to_host_int, chanend c_iap_to_host_int,
chanend c_iap, chanend c_iap,
#endif #endif
#if defined(SPDIF_RX) || defined(ADAT_RX) #if defined(SPDIF_RX) || defined(ADAT_RX)
chanend? c_int, chanend? c_int,
#endif #endif
chanend c_sof, chanend c_sof,
chanend c_aud_ctl, chanend c_aud_ctl,
in port p_off_mclk in port p_off_mclk
#ifdef HID_CONTROLS #ifdef HID_CONTROLS

View File

@@ -43,7 +43,7 @@ unsigned g_freqChange = 0;
unsigned char g_intData[8]; unsigned char g_intData[8];
#if defined (MIDI) || defined(IAP) #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; xc_ptr tmp;
tmp = a; tmp = a;
@@ -70,29 +70,29 @@ unsigned char fb_clocks[16];
#define FB_TOLERANCE 0x100 #define FB_TOLERANCE 0x100
extern unsigned inZeroBuff[]; 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_out chanend for audio from xud
* @param c_aud_in chanend for audio to xud * @param c_aud_in chanend for audio to xud
* @param c_aud_fb chanend for feeback to xud * @param c_aud_fb chanend for feeback to xud
* @return void * @return void
*/ */
void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud_fb, void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud_fb,
#ifdef MIDI #ifdef MIDI
chanend c_midi_from_host, chanend c_midi_from_host,
chanend c_midi_to_host, chanend c_midi_to_host,
chanend c_midi, chanend c_midi,
#endif #endif
#ifdef IAP #ifdef IAP
chanend c_iap_from_host, chanend c_iap_from_host,
chanend c_iap_to_host, chanend c_iap_to_host,
chanend c_iap_to_host_int, chanend c_iap_to_host_int,
chanend c_iap, chanend c_iap,
#endif #endif
#if defined(SPDIF_RX) || defined(ADAT_RX) #if defined(SPDIF_RX) || defined(ADAT_RX)
chanend ?c_int, chanend ?c_int,
#endif #endif
chanend c_sof, chanend c_sof,
chanend c_aud_ctl, chanend c_aud_ctl,
in port p_off_mclk in port p_off_mclk
#ifdef HID_CONTROLS #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 #ifdef HID_CONTROLS
XUD_ep ep_hid = XUD_InitEp(c_hid); XUD_ep ep_hid = XUD_InitEp(c_hid);
#endif #endif
int tmp; int tmp;
unsigned u_tmp; unsigned u_tmp;
unsigned sampleFreq = 0; unsigned sampleFreq = 0;
@@ -133,7 +133,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
#ifdef INPUT #ifdef INPUT
unsigned bufferIn = 1; unsigned bufferIn = 1;
#endif #endif
unsigned remnant = 0, cycles; unsigned remnant = 0, cycles;
unsigned sofCount = 0; unsigned sofCount = 0;
unsigned freqChange = 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; xc_ptr iap_from_host_rdptr;
unsigned char iap_from_host_buffer[MAX_IAP_PACKET_SIZE+4]; unsigned char iap_from_host_buffer[MAX_IAP_PACKET_SIZE+4];
unsigned char iap_to_host_buffer[MAX_IAP_PACKET_SIZE+4]; unsigned char iap_to_host_buffer[MAX_IAP_PACKET_SIZE+4];
int is_ack_iap; int is_ack_iap;
int is_reset; int is_reset;
unsigned int datum_iap; 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); xc_ptr p_inZeroBuff = array_to_xc_ptr(inZeroBuff);
#ifdef IAP #ifdef IAP
XUD_ResetEndpoint(ep_iap_from_host, null); XUD_ResetEndpoint(ep_iap_from_host, null);
iap_send_reset(c_iap); iap_send_reset(c_iap);
#endif #endif
#if defined(SPDIF_RX) || defined(ADAT_RX) #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 #endif
asm("stw %0, dp[aud_from_host_usb_ep]"::"r"(ep_aud_out)); 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[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 min, mid, max;
int usb_speed = 0; 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); GetADCCounts(DEFAULT_FREQ, min, mid, max);
asm("stw %0, dp[g_speed]"::"r"(mid << 16)); 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; mid*=NUM_USB_CHAN_IN*4;
else else
mid*=NUM_USB_CHAN_IN_A1*3; 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 #ifdef FB_TOLERANCE_TEST
expected_fb = ((DEFAULT_FREQ * 0x2000) / 1000); expected_fb = ((DEFAULT_FREQ * 0x2000) / 1000);
#endif #endif
} }
#ifdef OUTPUT #ifdef OUTPUT
SET_SHARED_GLOBAL(g_aud_from_host_flag, 1); SET_SHARED_GLOBAL(g_aud_from_host_flag, 1);
#endif #endif
#ifdef INPUT #ifdef INPUT
SET_SHARED_GLOBAL(g_aud_to_host_flag, 1); SET_SHARED_GLOBAL(g_aud_to_host_flag, 1);
#endif #endif
(fb_clocks, unsigned[])[0] = 0; (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 usb_speed;
int x; int x;
asm("ldaw %0, dp[fb_clocks]":"=r"(x)); asm("ldaw %0, dp[fb_clocks]":"=r"(x));
GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed); 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); XUD_SetReady_In(ep_aud_fb, fb_clocks, 4);
} }
else else
{ {
XUD_SetReady_In(ep_aud_fb, fb_clocks, 3); 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) #if defined(SPDIF_RX) || defined(ADAT_RX)
/* Interrupt EP, send back interrupt data. Note, request made from decouple */ /* Interrupt EP, send back interrupt data. Note, request made from decouple */
case inuint_byref(c_int, tmp): case inuint_byref(c_int, tmp):
{ {
int sent_ok = 0; int sent_ok = 0;
XUD_SetData_Inline(ep_int, c_int); XUD_SetData_Inline(ep_int, c_int);
asm("stw %0, dp[g_intFlag]" :: "r" (0) ); asm("stw %0, dp[g_intFlag]" :: "r" (0) );
break; break;
} }
#endif #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): case testct_byref(c_aud_ctl, u_tmp):
{ {
if (u_tmp) if (u_tmp)
{ {
// is a control token sent by reboot_device // is a control token sent by reboot_device
inct(c_aud_ctl); inct(c_aud_ctl);
outct(c_aud_ctl, XS1_CT_END); outct(c_aud_ctl, XS1_CT_END);
while(1) {}; while(1) {};
} }
else else
{ {
int min, mid, max; int min, mid, max;
int usb_speed; int usb_speed;
int frameTime; int frameTime;
tmp = inuint(c_aud_ctl); tmp = inuint(c_aud_ctl);
GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed); GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed);
if(tmp == SET_SAMPLE_FREQ) if(tmp == SET_SAMPLE_FREQ)
{ {
sampleFreq = inuint(c_aud_ctl); sampleFreq = inuint(c_aud_ctl);
/* Don't update things for DFU command.. */ /* Don't update things for DFU command.. */
if(sampleFreq != AUDIO_STOP_FOR_DFU) if(sampleFreq != AUDIO_STOP_FOR_DFU)
{ {
/* Tidy up double buffer, note we can do better than this for 44.1 etc but better /* Tidy up double buffer, note we can do better than this for 44.1 etc but better
* than sending two packets at old speed! */ * than sending two packets at old speed! */
if (usb_speed == XUD_SPEED_HS) if (usb_speed == XUD_SPEED_HS)
frameTime = 8000; frameTime = 8000;
else else
frameTime = 1000; frameTime = 1000;
min = sampleFreq / frameTime; min = sampleFreq / frameTime;
max = min + 1; max = min + 1;
mid = min; mid = min;
/* Check for INT(SampFreq/8000) == SampFreq/8000 */ /* Check for INT(SampFreq/8000) == SampFreq/8000 */
if((sampleFreq % frameTime) == 0) if((sampleFreq % frameTime) == 0)
{ {
min -= 1; 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 #ifdef FB_TOLERANCE_TEST
expected_fb = ((sampleFreq * 0x2000) / frameTime); expected_fb = ((sampleFreq * 0x2000) / frameTime);
#endif #endif
asm("stw %0, dp[g_speed]"::"r"(mid << 16)); 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; mid *= NUM_USB_CHAN_IN*4;
else else
mid *= NUM_USB_CHAN_IN_A1*3; mid *= NUM_USB_CHAN_IN_A1*3;
asm("stw %0, %1[0]"::"r"(mid),"r"(p_inZeroBuff)); asm("stw %0, %1[0]"::"r"(mid),"r"(p_inZeroBuff));
/* Reset FB */ /* Reset FB */
/* Note, Endpoint 0 will hold off host for a sufficient period to allow out feedback /* Note, Endpoint 0 will hold off host for a sufficient period to allow out feedback
* to stabilise (i.e. sofCount == 128 to fire) */ * to stabilise (i.e. sofCount == 128 to fire) */
sofCount = 0; sofCount = 0;
clocks = 0; clocks = 0;
remnant = 0; remnant = 0;
} }
/* Ideally we want to wait for handshake (and pass back up) here. But we cannot keep this /* 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 */ * handshake elsewhere */
/* Pass on sample freq change to decouple */ /* Pass on sample freq change to decouple */
SET_SHARED_GLOBAL0(g_freqChange, SET_SAMPLE_FREQ); 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 else
{ {
sampleFreq = inuint(c_aud_ctl); sampleFreq = inuint(c_aud_ctl);
SET_SHARED_GLOBAL0(g_freqChange, tmp); /* Set command */ SET_SHARED_GLOBAL0(g_freqChange, tmp); /* Set command */
SET_SHARED_GLOBAL(g_freqChange_sampFreq, sampleFreq); /* Set flag */ SET_SHARED_GLOBAL(g_freqChange_sampFreq, sampleFreq); /* Set flag */
SET_SHARED_GLOBAL(g_freqChange_flag, tmp); 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) */ /* (previously used 63 instead of 127) */
case inuint_byref(c_sof, u_tmp): 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 /* NOTE our feedback will be wrong for a couple of SOF's after a SF change due to
* lastClock being incorrect */ * lastClock being incorrect */
asm("#sof"); asm("#sof");
/* Get MCLK count */ /* 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); GET_SHARED_GLOBAL(freqChange, g_freqChange);
if(freqChange == SET_SAMPLE_FREQ) 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; unsigned mask = MASK_16_13, usb_speed;
GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed); GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed);
if(usb_speed != XUD_SPEED_HS) if(usb_speed != XUD_SPEED_HS)
mask = MASK_16_10; mask = MASK_16_10;
/* Number of MCLKS this SOF, approx 125 * 24 (3000), sample by sample rate */ /* Number of MCLKS this SOF, approx 125 * 24 (3000), sample by sample rate */
GET_SHARED_GLOBAL(cycles, g_curSamFreqMultiplier); GET_SHARED_GLOBAL(cycles, g_curSamFreqMultiplier);
cycles = ((int)((short)(u_tmp - lastClock))) * cycles; cycles = ((int)((short)(u_tmp - lastClock))) * cycles;
/* Any odd bits (lower than 16.23) have to be kept seperate */ /* Any odd bits (lower than 16.23) have to be kept seperate */
remnant += cycles & mask; remnant += cycles & mask;
/* Add 16.13 bits into clock count */ /* Add 16.13 bits into clock count */
clocks += (cycles & ~mask) + (remnant & ~mask); clocks += (cycles & ~mask) + (remnant & ~mask);
/* and overflow from odd bits. Remove overflow from odd bits. */ /* and overflow from odd bits. Remove overflow from odd bits. */
remnant &= mask; remnant &= mask;
/* 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 /* Store MCLK for next time around... */
* We always count 128 SOFs, so 16ms @ HS, 128ms @ FS */ lastClock = u_tmp;
if(sofCount == 128)
/* 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; sofCount = 0;
#ifdef FB_TOLERANCE_TEST #ifdef FB_TOLERANCE_TEST
if (clocks > (expected_fb - FB_TOLERANCE) && if (clocks > (expected_fb - FB_TOLERANCE) &&
clocks < (expected_fb + FB_TOLERANCE)) clocks < (expected_fb + FB_TOLERANCE))
#endif #endif
{ {
int usb_speed; 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; //fb_clocks = clocks;
GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed); GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed);
if (usb_speed == XUD_SPEED_HS) if (usb_speed == XUD_SPEED_HS)
{ {
(fb_clocks, unsigned[])[0] = clocks; (fb_clocks, unsigned[])[0] = clocks;
} }
else else
{ {
(fb_clocks, unsigned[])[0] = clocks>>2; (fb_clocks, unsigned[])[0] = clocks>>2;
} }
} }
#ifdef FB_TOLERANCE_TEST #ifdef FB_TOLERANCE_TEST
else else
{ {
} }
#endif #endif
clocks = 0; clocks = 0;
} }
sofCount++; sofCount++;
} }
break; 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): case XUD_SetData_Select(c_aud_in, ep_aud_in, tmp):
{ {
/* Inform stream that buffer sent */ /* 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; break;
#endif #endif
#ifdef OUTPUT #ifdef OUTPUT
/* Feedback Pipe */ /* Feedback Pipe */
case XUD_SetData_Select(c_aud_fb, ep_aud_fb, tmp): 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; int x;
asm("#aud fb"); asm("#aud fb");
asm("ldaw %0, dp[fb_clocks]":"=r"(x)); asm("ldaw %0, dp[fb_clocks]":"=r"(x));
GET_SHARED_GLOBAL(usb_speed, g_curUsbSpeed); 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); XUD_SetReady_In(ep_aud_fb, fb_clocks, 4);
} }
else else
{ {
XUD_SetReady_In(ep_aud_fb, fb_clocks, 3); XUD_SetReady_In(ep_aud_fb, fb_clocks, 3);
} }
} }
break; break;
/* Audio HOST -> DEVICE */ /* Audio HOST -> DEVICE */
case XUD_GetData_Select(c_aud_out, ep_aud_out, tmp): case XUD_GetData_Select(c_aud_out, ep_aud_out, tmp):
{ {
asm("#h->d aud data"); asm("#h->d aud data");
GET_SHARED_GLOBAL(aud_from_host_buffer, g_aud_from_host_buffer); GET_SHARED_GLOBAL(aud_from_host_buffer, g_aud_from_host_buffer);
write_via_xc_ptr(aud_from_host_buffer, tmp); write_via_xc_ptr(aud_from_host_buffer, tmp);
/* Sync with decouple thread */ /* Sync with decouple thread */
SET_SHARED_GLOBAL0(g_aud_from_host_flag, 1); SET_SHARED_GLOBAL0(g_aud_from_host_flag, 1);
} }
break; break;
#endif #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 */ /* 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 */ /* 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; 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); read_via_xc_ptr(datum, midi_from_host_rdptr);
outuint(c_midi, datum); outuint(c_midi, datum);
midi_from_host_rdptr += 4; midi_from_host_rdptr += 4;
midi_data_remaining_to_device -= 4; midi_data_remaining_to_device -= 4;
} }
break; break;
/* MIDI IN to host */ /* MIDI IN to host */
case XUD_SetData_Select(c_midi_to_host, ep_midi_to_host, tmp): case XUD_SetData_Select(c_midi_to_host, ep_midi_to_host, tmp):
asm("#midi d->h"); asm("#midi d->h");
/* The buffer has been sent to the host, so we can ack the midi thread */ /* 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 the collecting and sending buffer */
swap(midi_to_host_buffer_being_collected, midi_to_host_buffer_being_sent); swap(midi_to_host_buffer_being_collected, midi_to_host_buffer_being_sent);
/* Request to send packet */ /* Request to send packet */
XUD_SetReady_InPtr(ep_midi_to_host, midi_to_host_buffer_being_sent, midi_data_collected_from_device); 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 */ /* 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 */ /* Reset the collected data count */
midi_data_collected_from_device = 0; midi_data_collected_from_device = 0;
} }
else else
{ {
midi_waiting_on_send_to_host = 0; midi_waiting_on_send_to_host = 0;
} }
break; break;
#endif #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): case XUD_GetData_Select(c_iap_from_host, ep_iap_from_host, tmp):
asm("#iap h->d"); asm("#iap h->d");
if(tmp >= 0) if(tmp >= 0)
{ {
iap_data_remaining_to_device = tmp; iap_data_remaining_to_device = tmp;
if(iap_data_remaining_to_device) 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 */ /* Send out first byte in buffer */
datum_iap = iap_from_host_buffer[0]; datum_iap = iap_from_host_buffer[0];
outuint(c_iap, datum_iap); outuint(c_iap, datum_iap);
/* Set read ptr to next byte in buffer */ /* Set read ptr to next byte in buffer */
iap_from_host_rdptr = 1; iap_from_host_rdptr = 1;
iap_data_remaining_to_device -= 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; iap_data_collected_from_device = 0;
} }
break; break;
/* IAP IN to host */ /* IAP IN to host */
case XUD_SetData_Select(c_iap_to_host, ep_iap_to_host, tmp): case XUD_SetData_Select(c_iap_to_host, ep_iap_to_host, tmp):
asm("#iap d->h"); asm("#iap d->h");
/* Send out an iAP packet to host, ACK last msg from iAP to let it know we can move on..*/ /* 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); iap_send_ack(c_iap);
break; /* IAP IN to host */ break; /* IAP IN to host */
case XUD_SetData_Select(c_iap_to_host_int, ep_iap_to_host_int, tmp): case XUD_SetData_Select(c_iap_to_host_int, ep_iap_to_host_int, tmp):
asm("#iap int d->h"); asm("#iap int d->h");
/* Do nothing.. */ /* Do nothing.. */
break; break;
@@ -586,27 +586,27 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
#endif #endif
#ifdef MIDI #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): 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 /* An ack from the midi/uart thread means it has accepted some data we sent it
* we are okay to send another word */ * 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 */ /* 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 another word from the fifo and output it to MIDI thread */
read_via_xc_ptr(datum, midi_from_host_rdptr); read_via_xc_ptr(datum, midi_from_host_rdptr);
outuint(c_midi, datum); outuint(c_midi, datum);
midi_from_host_rdptr += 4; midi_from_host_rdptr += 4;
midi_data_remaining_to_device -= 4; midi_data_remaining_to_device -= 4;
} }
} }
else else
{ {
/* The midi/uart thread has sent us some data - handshake back */ /* The midi/uart thread has sent us some data - handshake back */
midi_send_ack(c_midi); 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); write_via_xc_ptr(p, datum);
midi_data_collected_from_device += 4; 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 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); swap(midi_to_host_buffer_being_collected, midi_to_host_buffer_being_sent);
// Signal other side to swap // Signal other side to swap
XUD_SetReady_InPtr(ep_midi_to_host, midi_to_host_buffer_being_sent, midi_data_collected_from_device); 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_data_collected_from_device = 0;
midi_waiting_on_send_to_host = 1; midi_waiting_on_send_to_host = 1;
} }
} }
break; break;
#endif /* ifdef MIDI */ #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 */ /* 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): 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 /* An ack from the iap/uart thread means it has accepted some data we sent it
* we are okay to send another word */ * 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 */ /* We have read an entire packet - Mark ready to receive another */
XUD_SetReady_Out(ep_iap_from_host, iap_from_host_buffer); 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 */ /* Read another byte from the fifo and output it to iap thread */
datum_iap = iap_from_host_buffer[iap_from_host_rdptr]; 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 else
{ {
if (iap_expected_data_length == 0) if (iap_expected_data_length == 0)
{ {
/* Expect a length from iAP core */ /* Expect a length from iAP core */
iap_send_ack(c_iap); iap_send_ack(c_iap);
iap_expected_data_length = datum_iap; iap_expected_data_length = datum_iap;
} }
else else
{ {
if (iap_data_collected_from_device < IAP_USB_BUFFER_TO_HOST_SIZE) 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_to_host_buffer[iap_data_collected_from_device] = datum_iap;
iap_data_collected_from_device += 1; 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 */ /* Once we have the whole message, sent it to host */
/* Note we don't ack the last byte yet... */ /* 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_int, gc_zero_buffer, 0);
XUD_SetReady_In(ep_iap_to_host, iap_to_host_buffer, iap_data_collected_from_device); XUD_SetReady_In(ep_iap_to_host, iap_to_host_buffer, iap_data_collected_from_device);

View File

@@ -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 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") #define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
#endif #endif

View File

@@ -1,3 +1,3 @@
void UserReadHIDButtons(unsigned char hidData[]); void UserReadHIDButtons(unsigned char hidData[]);

View File

@@ -16,7 +16,7 @@ void XUD_UserResume(void)
unsigned config; unsigned config;
asm("ldw %0, dp[g_currentConfig]" : "=r" (config):); asm("ldw %0, dp[g_currentConfig]" : "=r" (config):);
if(config == 1) if(config == 1)
{ {
UserHostActive(1); UserHostActive(1);

View File

@@ -8,7 +8,7 @@
* signal. Normally the 48000 function is called in a while(1) loop. If * 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 * 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 * 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); 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 * 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 * 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 * 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); void adatReceiver44100(buffered in port:32 p, chanend oChan);

File diff suppressed because it is too large Load Diff

View File

@@ -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 */ It is intended to be included in the main device descriptor definition */
/* MIDI Descriptors */ /* MIDI Descriptors */

View File

@@ -1,7 +1,7 @@
/** /**
* @file midiinparse.xc * @file midiinparse.xc
* @brief Generates USB MIDI events from MIDI events * @brief Generates USB MIDI events from MIDI events
* @author Russell Gallop, XMOS Semiconductor * @author Russell Gallop, XMOS Semiconductor
* @version 0.1 * @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) { 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++; state.received++;
// Compose sysex bytes that we've got and send them out. // Compose sysex bytes that we've got and send them out.
// This will depend how many we have. // This will depend how many we have.
state.codeIndexNumber = state.received + 0x4; state.codeIndexNumber = state.received + 0x4;
valid = 1; valid = 1;
data = makeEvent(cable_number, state.codeIndexNumber, data = makeEvent(cable_number, state.codeIndexNumber,
state.receivebuffer[0], state.receivebuffer[1], state.receivebuffer[2]); 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); reset_midi_state(state);
state.receivebuffer[state.received] = b; state.receivebuffer[state.received] = b;
state.received++; state.received++;
switch (lowNibble) switch (lowNibble)
{ {
case 0x2: // Song Position Pointer (3 byte system common) case 0x2: // Song Position Pointer (3 byte system common)
{ {
@@ -119,7 +119,7 @@ static unsigned makeEvent(unsigned cable_number, unsigned codeIndexNumber, unsig
break; break;
} }
case 0x6: // Tune request (1 byte system common) case 0x6: // Tune request (1 byte system common)
state.codeIndexNumber = 5; state.codeIndexNumber = 5;
valid = 1; valid = 1;
data = makeEvent(cable_number, state.codeIndexNumber, data = makeEvent(cable_number, state.codeIndexNumber,
state.receivebuffer[0], state.receivebuffer[1], state.receivebuffer[2]); state.receivebuffer[0], state.receivebuffer[1], state.receivebuffer[2]);
@@ -143,7 +143,7 @@ static unsigned makeEvent(unsigned cable_number, unsigned codeIndexNumber, unsig
state.received++; state.received++;
// code index number is always the high nibble for channel messages // code index number is always the high nibble for channel messages
state.codeIndexNumber = highNibble; state.codeIndexNumber = highNibble;
switch (highNibble) switch (highNibble)
{ {
case 0x8: // Note-off case 0x8: // Note-off
case 0x9: // Note-on case 0x9: // Note-on

View File

@@ -1,12 +1,12 @@
/** /**
* @file midioutparse.xc * @file midioutparse.xc
* @brief Parses USB-MIDI events into set of MIDI bytes * @brief Parses USB-MIDI events into set of MIDI bytes
* @author Russell Gallop, XMOS Semiconductor * @author Russell Gallop, XMOS Semiconductor
*/ */
#include "midioutparse.h" #include "midioutparse.h"
/** /**
* @brief Breaks a USB-MIDI event into it's constituant fields * @brief Breaks a USB-MIDI event into it's constituant fields
* *
* @param[in] ev USB-MIDI event * @param[in] ev USB-MIDI event
@@ -23,7 +23,7 @@
#endif #endif
/** /**
* @brief Parse a USB-MIDI event into the MIDI bytes and a length field * @brief Parse a USB-MIDI event into the MIDI bytes and a length field
* *
* @param[in] ev USB-MIDI event * @param[in] ev USB-MIDI event
@@ -35,7 +35,7 @@
unsigned size = 0; unsigned size = 0;
{cable_number, codeIndexNumber, midi[0], midi[1], midi[2]} = breakEvent(event); {cable_number, codeIndexNumber, midi[0], midi[1], midi[2]} = breakEvent(event);
// Not doing anything with cable number // Not doing anything with cable number
switch (codeIndexNumber) { switch (codeIndexNumber) {
case 0x3: // Three-byte system Common messages like SPP, etc. case 0x3: // Three-byte system Common messages like SPP, etc.

View File

@@ -9,13 +9,13 @@
* *
* \param p_midi_in 1-bit input port for MIDI * \param p_midi_in 1-bit input port for MIDI
* \param p_midi_out 1-bit output 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 * a rate of 100MHz
* \param c_midi chanend connected to the decouple() thread * \param c_midi chanend connected to the decouple() thread
* \param cable_number the cable number of the MIDI implementation. * \param cable_number the cable number of the MIDI implementation.
* This should be set to 0. * 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, clock ?clk_midi,
chanend ?c_midi, chanend ?c_midi,
unsigned cable_number, unsigned cable_number,

View File

@@ -107,9 +107,9 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out,
#ifdef IAP #ifdef IAP
CoProcessorDisable(); CoProcessorDisable();
#endif #endif
// p_midi_out <: 1 << MIDI_SHIFT_TX; // Start with high bit. // p_midi_out <: 1 << MIDI_SHIFT_TX; // Start with high bit.
#ifdef IAP #ifdef IAP
CoProcessorEnable(); CoProcessorEnable();
#endif #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.. init_iAP(iap_incoming_buffer, iap_outgoing_buffer, null, null, null); // uses timer for i2c initialisation pause..
} }
else else
{ {
init_iAP(iap_incoming_buffer, iap_outgoing_buffer, c_i2c, p_scl, p_sda); // uses timer for i2c initialisation pause.. init_iAP(iap_incoming_buffer, iap_outgoing_buffer, c_i2c, p_scl, p_sda); // uses timer for i2c initialisation pause..
} }
#endif #endif
@@ -130,12 +130,12 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out,
iAPTimer :> polltime; iAPTimer :> polltime;
polltime += XS1_TIMER_HZ / 2; polltime += XS1_TIMER_HZ / 2;
#endif #endif
while (1) while (1)
{ {
int is_ack; int is_ack;
int is_reset; int is_reset;
unsigned int datum; unsigned int datum;
select select
{ {
// Input to read the start bit // Input to read the start bit
#ifndef MIDI_LOOPBACK #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("setc res[%0],1"::"r"(p_midi_in));
asm("setpt res[%0],%1"::"r"(p_midi_in),"r"(rxPT)); asm("setpt res[%0],%1"::"r"(p_midi_in),"r"(rxPT));
break; break;
// Input to read the remaining bits // Input to read the remaining bits
case (!authenticating && isRX) => t2 when timerafter(rxT) :> int _ : case (!authenticating && isRX) => t2 when timerafter(rxT) :> int _ :
{ {
unsigned bit; unsigned bit;
p_midi_in :> bit; p_midi_in :> bit;
if (rxI++ < 8) if (rxI++ < 8)
{ {
// shift in bits into the high end of a word // shift in bits into the high end of a word
rxByte = (bit << 31) | (rxByte >> 1); rxByte = (bit << 31) | (rxByte >> 1);
rxT += bit_time; rxT += bit_time;
rxPT += bit_time; rxPT += bit_time;
asm("setpt res[%0],%1"::"r"(p_midi_in),"r"(rxPT)); asm("setpt res[%0],%1"::"r"(p_midi_in),"r"(rxPT));
} }
else else
{ {
// rcv and check stop bit // rcv and check stop bit
if ((bit & 0x1) == 1) if ((bit & 0x1) == 1)
{ {
unsigned valid = 0; unsigned valid = 0;
unsigned event = 0; unsigned event = 0;
@@ -173,7 +173,7 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out,
rxByte >>= 24; rxByte >>= 24;
#if 0 #if 0
// Loopback check // Loopback check
if ((rxByte != outputted_symbol)) if ((rxByte != outputted_symbol))
{ {
printhexln(rxByte); printhexln(rxByte);
printhexln(outputted_symbol); printhexln(outputted_symbol);
@@ -185,20 +185,20 @@ void usb_midi(buffered in port:1 ?p_midi_in, port ?p_midi_out,
event = byterev(event); event = byterev(event);
// data to send to host - add to fifo // data to send to host - add to fifo
if (!waiting_for_ack) if (!waiting_for_ack)
{ {
// send data // send data
// printstr("uart->decouple: "); // printstr("uart->decouple: ");
outuint(c_midi, event); outuint(c_midi, event);
waiting_for_ack = 1; waiting_for_ack = 1;
th_count++; th_count++;
} }
else else
{ {
queue_push_word(midi_to_host_fifo, midi_to_host_fifo_arr, event); queue_push_word(midi_to_host_fifo, midi_to_host_fifo_arr, event);
} }
} }
else if (valid) else if (valid)
{ {
//printstr("g"); //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 // 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 // This code will leave the output high afterwards due to the stop bit added with makeSymbol
case (!authenticating && isTX) => t when timerafter(txT) :> int _: case (!authenticating && isTX) => t when timerafter(txT) :> int _:
if (symbol == 0) if (symbol == 0)
{ {
// Got something to output but not mid-symbol. // Got something to output but not mid-symbol.
// Start sending 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; txT += bit_time;
txPT += bit_time; txPT += bit_time;
isTX = 1; isTX = 1;
} }
else else
{ {
// Mid-symbol // Mid-symbol
txT += bit_time; // Should this be after the output otherwise be double the length of the high before the start bit 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)<<MIDI_SHIFT_TX); p_midi_out @ txPT <: ((symbol & 1)<<MIDI_SHIFT_TX);
// printstr("mout2\n"); // printstr("mout2\n");
symbol >>= 1; symbol >>= 1;
if (symbol == 0) if (symbol == 0)
{ {
// Finished sending byte // Finished sending byte
uout_count++; 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): 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 // have we got more data to send
//printstr("ack\n"); //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"); //printstr("uart->decouple\n");
outuint(c_midi, queue_pop_word(midi_to_host_fifo, midi_to_host_fifo_arr)); outuint(c_midi, queue_pop_word(midi_to_host_fifo, midi_to_host_fifo_arr));
th_count++; th_count++;
} }
else else
{ {
waiting_for_ack = 0; waiting_for_ack = 0;
} }
} }
else else
{ {
unsigned midi[3]; unsigned midi[3];
unsigned size; 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)) if (queue_is_empty(midi_to_host_fifo))
{ {
// data to send to host // data to send to host
if (!waiting_for_ack) if (!waiting_for_ack)
{ {
// send data // send data
event = byterev(event); event = byterev(event);
outuint(c_midi, event); outuint(c_midi, event);
th_count++; th_count++;
waiting_for_ack = 1; waiting_for_ack = 1;
} }
else else
{ {
event = byterev(event); event = byterev(event);
queue_push_word(midi_to_host_fifo, midi_to_host_fifo_arr, 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 #else
{midi[0], midi[1], midi[2], size} = midi_out_parse(event); {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 // add symbol to fifo
queue_push_word(symbol_fifo, symbol_fifo_arr, midi[i]); 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) if (queue_space(symbol_fifo) > 3)
{ {
midi_send_ack(c_midi); midi_send_ack(c_midi);
} }
else else
{ {
midi_from_host_overflow = 1; midi_from_host_overflow = 1;
} }
// Drop through to the isTX guarded case // Drop through to the isTX guarded case
if (!isTX) if (!isTX)
{ {
t :> txT; // Should be enough to trigger the other case t :> txT; // Should be enough to trigger the other case
isTX = 1; 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); 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"); // printstrln("Completed authentication");
p_midi_in :> void; // Change port around to input again after authenticating (unique to midi+iAP case) p_midi_in :> void; // Change port around to input again after authenticating (unique to midi+iAP case)