First stab at iOS in 6v0. Replug (i.e. reset notification) not working yet

This commit is contained in:
Ross Owen
2013-01-29 16:47:53 +00:00
parent 127711e425
commit 4aafabd7cc
8 changed files with 127 additions and 55 deletions

View File

@@ -38,6 +38,10 @@
#undef IAP
#endif
#if defined(SU1_ADC_ENABLE) && (SU1_ADC_ENABLE == 0)
#undef SU1_ADC_ENABLE
#endif
#if defined(HID_CONTROLS) && (HID_CONTROLS == 0)
#undef HID_CONTROLS
#endif
@@ -240,7 +244,7 @@
#define EP_NUM_OUT_AUD (1) /* Always 1 */
#define EP_NUM_OUT_MIDI (2) /* Always 2 */
#define EP_NUM_OUT_IAP (3) /* Always 3 */
#define EP_NUM_OUT_IAP (EP_NUM_OUT_AUD + EP_CNT_OUT_MIDI + 1)
/* Endpoint Address Defines */
#define EP_ADR_IN_FB (EP_NUM_IN_FB | 0x80)
@@ -249,12 +253,13 @@
#define EP_ADR_IN_MIDI (EP_NUM_IN_MIDI | 0x80)
#define EP_ADR_IN_HID (EP_NUM_IN_HID | 0x80)
#define EP_ADR_IN_IAP (EP_NUM_IN_IAP | 0x80)
#define EP_ADR_IN_IAP_INT (EP_NUM_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_MIDI EP_NUM_OUT_MIDI
#define EP_ADR_OUT_IAP EP_NUM_OUT_IAP
/* Endpoint count totals */
#define EP_CNT_OUT (1 + 1 /*NUM_EP_OUT_AUD*/ + EP_CNT_OUT_MIDI + EP_CNT_OUT_IAP) /* +1 due to EP0 */
#define EP_CNT_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 */

View File

@@ -1225,8 +1225,7 @@ unsigned char cfgDesc_Audio2[] =
#endif
#ifdef IAP
/* Please write an iAP descriptor here */
/* Interface descriptor */
/* Interface descriptor */
0x09, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */
0x04, /* 1 bDescriptorType : INTERFACE descriptor. (field size 1 bytes) */
(INPUT_INTERFACES+OUTPUT_INTERFACES+MIDI_INTERFACES+DFU_INTERFACES+1), /* 2 bInterfaceNumber : Index of this interface. (field size 1 bytes) */
@@ -1240,7 +1239,7 @@ unsigned char cfgDesc_Audio2[] =
/* iAP Bulk OUT Endpoint Descriptor */
0x07, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */
0x05, /* 1 bDescriptorType : ENDPOINT descriptor. (field size 1 bytes) */
0x03, /* 2 bEndpointAddress : OUT Endpoint 3. High bit isIn (field size 1 bytes) */
EP_ADR_OUT_IAP, /* 2 bEndpointAddress : OUT Endpoint 3. High bit isIn (field size 1 bytes) */
0x02, /* 3 bmAttributes : Bulk, not shared. (field size 1 bytes) */
0x00, /* 4 wMaxPacketSize : 64 bytes per packet. (field size 2 bytes) - has to be 0x200 for compliance*/
0x02, /* 5 wMaxPacketSize */
@@ -1249,7 +1248,7 @@ unsigned char cfgDesc_Audio2[] =
/* iAP Bulk IN Endpoint Descriptor */
0x07, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */
0x05, /* 1 bDescriptorType : ENDPOINT descriptor. (field size 1 bytes) */
0x85, /* 2 bEndpointAddress : IN Endpoint 5. (field size 1 bytes) */
EP_ADR_IN_IAP, /* 2 bEndpointAddress : IN Endpoint 5. (field size 1 bytes) */
0x02, /* 3 bmAttributes : Bulk, not shared. (field size 1 bytes) */
0x00, /* 4 wMaxPacketSize : 64 bytes per packet. (field size 2 bytes) - has to be 0x200 for compliance*/
0x02, /* 5 wMaxPacketSize */
@@ -1258,7 +1257,7 @@ unsigned char cfgDesc_Audio2[] =
/* iAP Interrupt IN Endpoint Descriptor */
0x07, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */
0x05, /* 1 bDescriptorType : ENDPOINT descriptor. (field size 1 bytes) */
0x86, /* 2 bEndpointAddress : IN Endpoint 6. (field size 1 bytes) */
EP_ADR_IN_IAP_INT, /* 2 bEndpointAddress : IN Endpoint 6. (field size 1 bytes) */
0x03, /* 3 bmAttributes : Interrupt, not shared. (field size 1 bytes) */
0x40, /* 4 wMaxPacketSize : 64 bytes per packet. (field size 2 bytes) - has to be 0x40 for compliance*/
0x00, /* 5 wMaxPacketSize */

View File

@@ -24,6 +24,10 @@
#include "audio.h"
#include "ports.h" /* Portmap defines and ports for current app instance */
#ifdef IAP
#include "iap.h"
#endif
/* Audio I/O */
#if I2S_WIRES_DAC > 0
on stdcore[0] : buffered out port:32 p_i2s_dac[I2S_WIRES_DAC] =
@@ -95,26 +99,26 @@ on stdcore[AUDIO_IO_CORE] : in port p_lrclk = PORT_I2S_LRCLK;
on stdcore[AUDIO_IO_CORE] : in port p_bclk = PORT_I2S_BCLK;
#endif
on stdcore[AUDIO_IO_CORE] : port p_mclk = PORT_MCLK_IN;
on stdcore[0] : in port p_for_mclk_count = PORT_MCLK_COUNT;
on stdcore[AUDIO_IO_CORE] : port p_mclk = PORT_MCLK_IN;
on stdcore[0] : in port p_for_mclk_count = PORT_MCLK_COUNT;
#ifdef SPDIF
on stdcore[AUDIO_IO_CORE] : buffered out port:32 p_spdif_tx = PORT_SPDIF_OUT;
on stdcore[AUDIO_IO_CORE] : buffered out port:32 p_spdif_tx = PORT_SPDIF_OUT;
#endif
#ifdef MIDI
on stdcore[AUDIO_IO_CORE] : port p_midi_tx = PORT_MIDI_OUT;
on stdcore[AUDIO_IO_CORE] : in port p_midi_rx = PORT_MIDI_IN;
on stdcore[AUDIO_IO_CORE] : port p_midi_rx = PORT_MIDI_IN;
#endif
/* Clock blocks */
#ifdef MIDI
on stdcore[AUDIO_IO_CORE] : clock clk_midi = XS1_CLKBLK_REF;
on stdcore[AUDIO_IO_CORE] : clock clk_midi = XS1_CLKBLK_REF;
#endif
on stdcore[AUDIO_IO_CORE] : clock clk_audio_mclk = XS1_CLKBLK_2; /* Master clock */
on stdcore[AUDIO_IO_CORE] : clock clk_audio_bclk = XS1_CLKBLK_3; /* Bit clock */
on stdcore[AUDIO_IO_CORE] : clock clk_audio_mclk = XS1_CLKBLK_2; /* Master clock */
on stdcore[AUDIO_IO_CORE] : clock clk_audio_bclk = XS1_CLKBLK_3; /* Bit clock */
#ifdef SPDIF
on stdcore[AUDIO_IO_CORE] : clock clk_mst_spd = XS1_CLKBLK_1;
on stdcore[AUDIO_IO_CORE] : clock clk_mst_spd = XS1_CLKBLK_1;
#endif
/* L Series needs a port to use for USB reset */
@@ -136,6 +140,10 @@ XUD_EpType epTypeTableOut[EP_CNT_OUT] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE,
#ifdef MIDI
XUD_EPTYPE_BUL /* MIDI */
#endif
#ifdef IAP
XUD_EPTYPE_BUL /* iAP */
#endif
};
XUD_EpType epTypeTableIn[EP_CNT_IN] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE,
@@ -149,6 +157,10 @@ XUD_EpType epTypeTableIn[EP_CNT_IN] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE,
#endif
#ifdef HID_CONTROLS
XUD_EPTYPE_BUL,
#endif
#ifdef IAP
XUD_EPTYPE_BUL,
XUD_EPTYPE_BUL,
#endif
};
#define FAST_MODE 0
@@ -198,7 +210,6 @@ int main()
#define c_adc null
#endif
par
{
@@ -240,7 +251,7 @@ int main()
c_midi,
#endif
#ifdef IAP
c_xud_out[3], c_xud_in[5], c_xud_in[6],
c_xud_out[EP_NUM_OUT_IAP], c_xud_in[EP_NUM_IN_IAP], c_xud_in[EP_NUM_IN_IAP_INT],
#endif
#if defined(SPDIF_RX) || defined(ADAT_RX)
/* Audio Interrupt - only used for interrupts on external clock change */
@@ -272,11 +283,15 @@ int main()
audio(c_mix_out, null, null, c_adc);
}
#ifdef MIDI
#if defined (MIDI) || defined IAP
on stdcore[AUDIO_IO_CORE]:
{
thread_speed();
#ifdef MIDI
usb_midi(p_midi_rx, p_midi_tx, clk_midi, c_midi, 0, null, null, null, null);
#else
iAP(c_iap, null, p_i2c_scl, p_i2c_sda);
#endif
}
#endif

View File

@@ -18,7 +18,6 @@ void device_reboot_implementation(chanend spare)
/* Disable USB and issue reset to xcore only - not analogue chip */
write_node_config_reg(xs1_su, XS1_SU_CFG_RST_MISC_NUM,0b10);
#else
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

View File

@@ -77,8 +77,7 @@ unsigned dir = 0;
void GetADCCounts(unsigned samFreq, int &min, int &mid, int &max);
//#ifdef IAP
#if 0
#ifdef IAP
static inline void swap(xc_ptr &a, xc_ptr &b)
{
xc_ptr tmp;
@@ -88,7 +87,7 @@ static inline void swap(xc_ptr &a, xc_ptr &b)
return;
}
unsigned g_iap_reset = 0;
unsigned g_iap_reset = 1;
unsigned g_iap_from_host_flag = 0;
unsigned g_iap_to_host_flag = 0;
int iap_to_host_usb_ep = 0;
@@ -98,6 +97,7 @@ unsigned int g_iap_to_host_buffer_A[MAX_IAP_PACKET_SIZE/4+4];
unsigned int g_iap_to_host_buffer_B[MAX_IAP_PACKET_SIZE/4+4];
int g_iap_from_host_buffer[MAX_IAP_PACKET_SIZE/4+4];
unsigned g_zero_buffer[1];
unsigned char gc_zero_buffer[4];
#endif
//#ifdef HID_CONTROLS
@@ -567,6 +567,26 @@ void decouple(chanend c_mix_out,
int aud_to_host_flag = 0;
#endif
#ifdef IAP
xc_ptr iap_from_host_rdptr;
xc_ptr iap_from_host_buffer;
xc_ptr iap_to_host_buffer_being_sent = array_to_xc_ptr(g_iap_to_host_buffer_A);
xc_ptr iap_to_host_buffer_being_collected = array_to_xc_ptr(g_iap_to_host_buffer_B);
xc_ptr zero_buffer = array_to_xc_ptr(g_zero_buffer);
int is_ack_iap;
int is_reset;
int iap_reset;
unsigned int datum_iap;
int iap_data_remaining_to_device = 0;
int iap_data_collected_from_device = 0;
int iap_waiting_on_send_to_host = 0;
int iap_to_host_flag = 0;
int iap_from_host_flag = 0;
int iap_expecting_length = 1;
int iap_expecting_data_length = 0;
#endif
int t = array_to_xc_ptr(outAudioBuff);
int aud_in_ready = 0;
@@ -625,16 +645,16 @@ void decouple(chanend c_mix_out,
set_interrupt_handler(handle_audio_request, 200, 1, c_mix_out, 0);
#if 0
//#ifdef IAP
#ifdef IAP
//asm("ldaw %0, dp[g_iap_to_host_buffer]":"=r"(iap_to_host_buffer));
asm("ldaw %0, dp[g_iap_from_host_buffer]":"=r"(iap_from_host_buffer));
// wait for usb_buffer to set up
while(!iap_from_host_flag) {
GET_SHARED_GLOBAL(iap_from_host_flag, g_iap_from_host_flag);
while(!iap_from_host_flag)
{
GET_SHARED_GLOBAL(iap_from_host_flag, g_iap_from_host_flag);
}
iap_from_host_flag = 0;
SET_SHARED_GLOBAL(g_iap_from_host_flag, iap_from_host_flag);
@@ -968,8 +988,8 @@ void decouple(chanend c_mix_out,
#endif // INPUT
#if 0
//#ifdef IAP
//#if 0
#ifdef IAP
GET_SHARED_GLOBAL(iap_reset, g_iap_reset);
if (iap_reset)
{
@@ -997,8 +1017,8 @@ void decouple(chanend c_mix_out,
swap(iap_to_host_buffer_being_collected, iap_to_host_buffer_being_sent);
/* Request to send packet */
//XUD_SetReady_InPtr(iap_to_host_int_usb_ep, 0, zero_buffer, 0); // ZLP to int ep
//XUD_SetReady_InPtr(iap_to_host_usb_ep, 0, iap_to_host_buffer_being_sent+4, iap_data_collected_from_device);
XUD_SetReady_In(iap_to_host_int_usb_ep, gc_zero_buffer, 0); // ZLP to int ep
XUD_SetReady_InPtr(iap_to_host_usb_ep, iap_to_host_buffer_being_sent+4, iap_data_collected_from_device);
/* Mark as waiting for host to poll us */
iap_waiting_on_send_to_host = 1;
@@ -1028,12 +1048,15 @@ void decouple(chanend c_mix_out,
// Don't expect ack from this to make it simpler
outuint(c_iap, iap_data_remaining_to_device);
//printintln(iap_data_remaining_to_device);
/* Increment read pointer - buffer[0] is length */
iap_from_host_rdptr = iap_from_host_buffer + 4;
if (iap_data_remaining_to_device)
{
read_byte_via_xc_ptr(datum_iap, iap_from_host_rdptr);
//printintln(datum_iap);
outuint(c_iap, datum_iap);
iap_from_host_rdptr += 1;
iap_data_remaining_to_device -= 1;
@@ -1045,6 +1068,7 @@ void decouple(chanend c_mix_out,
{
/* Received word from iap thread - Check for ACK or Data */
case iap_get_ack_or_reset_or_data(c_iap, is_ack_iap, is_reset, datum_iap):
if (is_ack_iap)
{
/* An ack from the iap/uart thread means it has accepted some data we sent it
@@ -1052,7 +1076,7 @@ void decouple(chanend c_mix_out,
if (iap_data_remaining_to_device == 0)
{
/* We have read an entire packet - Mark ready to receive another */
//XUD_SetReady(iap_from_host_usb_ep, 1);
XUD_SetReady_OutPtr(iap_from_host_usb_ep, iap_from_host_buffer+4);
}
else
{
@@ -1093,8 +1117,9 @@ void decouple(chanend c_mix_out,
swap(iap_to_host_buffer_being_collected, iap_to_host_buffer_being_sent);
// Signal other side to swap
//XUD_SetReady_In(iap_to_host_int_usb_ep, 0, zero_buffer, 0);
//XUD_SetReady_In(iap_to_host_usb_ep, 0, iap_to_host_buffer_being_sent+4, iap_data_collected_from_device);
XUD_SetReady_In(iap_to_host_int_usb_ep, gc_zero_buffer, 0);
//printintln(iap_data_collected_from_device);
XUD_SetReady_InPtr(iap_to_host_usb_ep, iap_to_host_buffer_being_sent+4, iap_data_collected_from_device);
iap_data_collected_from_device = 0;
iap_waiting_on_send_to_host = 1;
iap_expecting_length = 1;

View File

@@ -59,8 +59,8 @@ int g_midi_from_host_buffer[MAX_USB_MIDI_PACKET_SIZE/4+4];
#ifdef IAP
/* iAP buffers */
unsigned int g_iap_to_host_buffer_A[MAX_IAP_PACKET_SIZE/4+4];
unsigned int g_iap_to_host_buffer_B[MAX_IAP_PACKET_SIZE/4+4];
//unsigned int g_iap_to_host_buffer_A[MAX_IAP_PACKET_SIZE/4+4];
//unsigned int g_iap_to_host_buffer_B[MAX_IAP_PACKET_SIZE/4+4];
#endif
unsigned char fb_clocks[16];
@@ -158,7 +158,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
#ifdef IAP
xc_ptr iap_from_host_rdptr;
xc_ptr iap_from_host_buffer;
//xc_ptr iap_from_host_buffer;
//xc_ptr iap_to_host_buffer_being_sent = array_to_xc_ptr(g_iap_to_host_buffer_A);
//xc_ptr iap_to_host_buffer_being_collected = array_to_xc_ptr(g_iap_to_host_buffer_B);
//xc_ptr zero_buffer = array_to_xc_ptr(g_zero_buffer);
@@ -174,6 +174,10 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
int iap_from_host_flag = 0;
int iap_expecting_length = 1;
int iap_expecting_data_length = 0;
xc_ptr iap_from_host_buffer =0;
xc_ptr iap_to_host_buffer = 0;
xc_ptr iap_to_host_waiting_buffer = 0;
#endif
@@ -183,12 +187,17 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
#ifdef IAP
/* Note the order here is important */
XUD_ResetDrain(c_iap_to_host);
XUD_ResetDrain(c_iap_to_host_int);
XUD_GetBusSpeed(c_iap_to_host);
XUD_GetBusSpeed(c_iap_to_host_int);
//XUD_ResetDrain(c_iap_to_host);
//XUD_ResetDrain(c_iap_to_host_int);
//XUD_GetBusSpeed(c_iap_to_host);
//XUD_GetBusSpeed(c_iap_to_host_int);
#warning TODO ADD BACK IAP RESET
#endif
#if defined(SPDIF_RX) || defined(ADAT_RX)
asm("stw %0, dp[int_usb_ep]"::"r"(ep_int));
#endif
@@ -233,18 +242,18 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
#ifdef IAP
// get the two buffers to use for iap device->host
// asm("ldaw %0, dp[g_iap_to_host_buffer_A]":"=r"(iap_to_host_buffer));
// asm("ldaw %0, dp[g_iap_to_host_buffer_B]":"=r"(iap_to_host_waiting_buffer));
// asm("ldaw %0, dp[g_iap_from_host_buffer]":"=r"(iap_from_host_buffer));
asm("ldaw %0, dp[g_iap_to_host_buffer_A]":"=r"(iap_to_host_buffer));
asm("ldaw %0, dp[g_iap_to_host_buffer_B]":"=r"(iap_to_host_waiting_buffer));
asm("ldaw %0, dp[g_iap_from_host_buffer]":"=r"(iap_from_host_buffer));
// pass the iap->XUD chanends to decouple so that thread can
// initialize comm with XUD
// asm("stw %0, dp[iap_to_host_usb_ep]"::"r"(ep_iap_to_host));
//asm("stw %0, dp[iap_to_host_int_usb_ep]"::"r"(ep_iap_to_host_int));
//asm("stw %0, dp[iap_from_host_usb_ep]"::"r"(ep_iap_from_host));
//swap(iap_to_host_buffer, iap_to_host_waiting_buffer);
//SET_SHARED_GLOBAL(g_iap_from_host_flag, 1);
asm("stw %0, dp[iap_to_host_usb_ep]"::"r"(ep_iap_to_host));
asm("stw %0, dp[iap_to_host_int_usb_ep]"::"r"(ep_iap_to_host_int));
asm("stw %0, dp[iap_from_host_usb_ep]"::"r"(ep_iap_from_host));
swap(iap_to_host_buffer, iap_to_host_waiting_buffer);
SET_SHARED_GLOBAL(g_iap_from_host_flag, 1);
#endif
#ifdef OUTPUT
@@ -279,6 +288,10 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
XUD_SetReady_OutPtr(ep_midi_from_host, midi_from_host_buffer);
#endif
#ifdef IAP
XUD_SetReady_OutPtr(ep_iap_from_host, iap_from_host_buffer+4);
#endif
#ifdef HID_CONTROLS
XUD_SetReady_In(ep_hid, g_hidData, 1);
#endif
@@ -570,15 +583,30 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud
#endif
#ifdef IAP
#error IAP NOT SUPPORTED IN THIS RELEASE!!
#warning IAP NOT SUPPORTED IN THIS RELEASE!!
/* IAP OUT from host */
case XUD_GetData_Select(c_iap_from_host, ep_iap_from_host, tmp):
asm("#iap h->d");
write_via_xc_ptr(iap_from_host_buffer, tmp);
/* release the buffer */
SET_SHARED_GLOBAL(g_iap_from_host_flag, 1);
break;
/* IAP IN to host */
case testct_byref(c_iap_to_host, tmp):
case XUD_SetData_Select(c_iap_to_host, ep_iap_to_host, tmp):
asm("#iap d->h");
// ack the decouple thread to say it has been sent to host
SET_SHARED_GLOBAL(g_iap_to_host_flag, 1);
swap(iap_to_host_buffer, iap_to_host_waiting_buffer);
break; /* IAP IN to host */
case XUD_SetData_Select(c_iap_to_host_int, ep_iap_to_host_int, tmp):
asm("#iap int d->h");
//printintln(1);
break;
#endif