Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions examples/AN00202_gige_avb_i2s_demo/src/aem_descriptors.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ unsigned char desc_configuration_0[] =
U16(AEM_AVB_INTERFACE_TYPE),
U16(1),
U16(AEM_CLOCK_SOURCE_TYPE),
#if (AVB_NUM_SINKS > 0)
U16(2),
#else
U16(1),
#endif
U16(AEM_LOCALE_TYPE),
U16(1),
U16(AEM_MEMORY_OBJECT_TYPE),
Expand Down Expand Up @@ -225,7 +229,11 @@ unsigned char desc_stream_port_output_0[] =
U16(0), /* number_of_controls */
U16(0), /* base_control */
U16(AVB_NUM_MEDIA_INPUTS/AVB_NUM_SOURCES), /* number_of_clusters */
#if (AVB_NUM_SINKS > 0)
U16(AVB_NUM_MEDIA_OUTPUTS/AVB_NUM_SINKS), /* base_cluster */
#else
U16(0), /* base_cluster */
#endif
U16(1), /* number_of_maps */
U16(1) /* base_map */
};
Expand Down Expand Up @@ -437,16 +445,16 @@ unsigned char desc_stream_output_0[] =
AVB_NUM_MEDIA_INPUTS/AVB_NUM_SOURCES, // label_mbla_cnt
0, // label_midi_cnt[0:3], label_smptecnt[4:]
// 96
0x00, 0xa0, 0x04, AVB_NUM_MEDIA_OUTPUTS/AVB_NUM_SINKS,
0x00, 0xa0, 0x04, AVB_NUM_MEDIA_INPUTS/AVB_NUM_SOURCES,
0x40, // b[0], nb[1], reserved[2:]
0, // label_iec_60958_cnt
AVB_NUM_MEDIA_OUTPUTS/AVB_NUM_SINKS, // label_mbla_cnt
AVB_NUM_MEDIA_INPUTS/AVB_NUM_SOURCES, // label_mbla_cnt
0, // label_midi_cnt[0:3], label_smptecnt[4:]
// 192
0x00, 0xa0, 0x06, AVB_NUM_MEDIA_OUTPUTS/AVB_NUM_SINKS,
0x00, 0xa0, 0x06, AVB_NUM_MEDIA_INPUTS/AVB_NUM_SOURCES,
0x40, // b[0], nb[1], reserved[2:]
0, // label_iec_60958_cnt
AVB_NUM_MEDIA_OUTPUTS/AVB_NUM_SINKS, // label_mbla_cnt
AVB_NUM_MEDIA_INPUTS/AVB_NUM_SOURCES, // label_mbla_cnt
0 // label_midi_cnt[0:3], label_smptecnt[4:]
};
#endif
Expand Down Expand Up @@ -509,6 +517,7 @@ unsigned char desc_clock_source_0[] =
{
U16(AEM_CLOCK_SOURCE_TYPE), /* 0-1 descriptor_type */
U16(0), /* 2-3 descriptor_id */
#if (AVB_NUM_SINKS > 0)
"Input Stream", /* 4-67 object_name */
U16(AEM_NO_STRING), /* 68-69 localized_description */
U16(AEM_CLOCK_SOURCE_FLAGS_LOCAL_ID), /* 70-71 clock_source_flags */
Expand All @@ -522,6 +531,7 @@ unsigned char desc_clock_source_1[] =
{
U16(AEM_CLOCK_SOURCE_TYPE), /* 0-1 descriptor_type */
U16(1), /* 2-3 descriptor_id */
#endif
"Internal Clock", /* 4-67 object_name */
U16(AEM_NO_STRING), /* 68-69 localized_description */
U16(0), /* 70-71 clock_source_flags */
Expand Down Expand Up @@ -601,7 +611,11 @@ unsigned int aem_descriptor_list[] =
AEM_JACK_INPUT_TYPE, 1, sizeof(desc_jack_input_0), (unsigned)desc_jack_input_0,
AEM_JACK_OUTPUT_TYPE, 1, sizeof(desc_jack_output_0), (unsigned)desc_jack_output_0,
AEM_AVB_INTERFACE_TYPE, 1, sizeof(desc_avb_interface_0), (unsigned)desc_avb_interface_0,
#if (AVB_NUM_SINKS > 0)
AEM_CLOCK_SOURCE_TYPE, 2, sizeof(desc_clock_source_0), (unsigned)desc_clock_source_0, sizeof(desc_clock_source_1), (unsigned)desc_clock_source_1,
#else
AEM_CLOCK_SOURCE_TYPE, 1, sizeof(desc_clock_source_0), (unsigned)desc_clock_source_0,
#endif
AEM_MEMORY_OBJECT_TYPE, 1, sizeof(desc_upgrade_image_memory_object_0), (unsigned)desc_upgrade_image_memory_object_0,
AEM_LOCALE_TYPE, 1, sizeof(desc_locale_0), (unsigned)desc_locale_0,
AEM_STRINGS_TYPE, 1, sizeof(desc_strings_0), (unsigned)desc_strings_0,
Expand Down
109 changes: 97 additions & 12 deletions examples/AN00202_gige_avb_i2s_demo/src/main.xc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ on tile[0]: out buffered port:32 p_fs[1] = { XS1_PORT_1A }; // Low frequency PLL
on tile[0]: out buffered port:32 p_i2s_lrclk = XS1_PORT_1G;
on tile[0]: out buffered port:32 p_i2s_bclk = XS1_PORT_1H;
on tile[0]: in port p_i2s_mclk = XS1_PORT_1F;
#if AVB_NUM_MEDIA_OUTPUTS
on tile[0]: out buffered port:32 p_aud_dout[4] = {XS1_PORT_1M, XS1_PORT_1N, XS1_PORT_1O, XS1_PORT_1P};
#endif
on tile[0]: in buffered port:32 p_aud_din[4] = {XS1_PORT_1I, XS1_PORT_1J, XS1_PORT_1K, XS1_PORT_1L};
on tile[0]: clock clk_i2s_bclk = XS1_CLKBLK_3;
on tile[0]: clock clk_i2s_mclk = XS1_CLKBLK_4;
Expand Down Expand Up @@ -93,7 +95,9 @@ on tile[0]: out port p_audio_shared = XS1_PORT_8C;
void buffer_manager_to_i2s(server i2s_callback_if i2s,
streaming chanend c_audio,
client interface i2c_master_if i2c,
#if AVB_NUM_MEDIA_OUTPUTS
streaming chanend c_sound_activity,
#endif
int synth_sinewave_channel_mask,
client output_gpio_if dac_reset,
client output_gpio_if adc_reset,
Expand All @@ -102,15 +106,20 @@ void buffer_manager_to_i2s(server i2s_callback_if i2s,
{
audio_frame_t *unsafe p_in_frame;
audio_double_buffer_t *unsafe double_buffer;
#if AVB_NUM_MEDIA_OUTPUTS
int32_t *unsafe sample_out_buf;
unsigned cur_sample_rate;
const int sound_activity_threshold = 100000;
const int sound_activity_update_interval = 2500;
int sound_activity_update = 0;
int sinewave_index = 0;
int channel_mask = 0;
#else
unsigned sample_out_count = 0;
#endif
unsigned cur_sample_rate;
int sinewave_index = 0;
timer tmr;


audio_clock_CS2100CP_init(i2c);

while (1) {
Expand Down Expand Up @@ -194,6 +203,7 @@ void buffer_manager_to_i2s(server i2s_callback_if i2s,
break;

case i2s.restart_check() -> i2s_restart_t restart:
#if AVB_NUM_MEDIA_OUTPUTS
unsafe {
if (sample_out_buf[8]) {
restart = I2S_RESTART;
Expand All @@ -206,6 +216,9 @@ void buffer_manager_to_i2s(server i2s_callback_if i2s,
restart = I2S_NO_RESTART;
}
}
#else
restart = I2S_NO_RESTART;
#endif
break; // End of restart check

case i2s.receive(size_t index, int32_t sample):
Expand All @@ -221,10 +234,23 @@ void buffer_manager_to_i2s(server i2s_callback_if i2s,
if (sinewave_index == 256)
sinewave_index = 0;
}

#if !AVB_NUM_MEDIA_OUTPUTS
sample_out_count++;
if( sample_out_count == AVB_NUM_MEDIA_INPUTS )
{
tmr :> p_in_frame->timestamp;
audio_frame_t *unsafe new_frame = audio_buffers_swap_active_buffer(*double_buffer);
c_audio <: p_in_frame;
p_in_frame = new_frame;
sample_out_count = 0;
}
#endif
}
break;

case i2s.send(size_t index) -> int32_t sample:
#if AVB_NUM_MEDIA_OUTPUTS
unsafe {
if (index == 0) {
c_audio :> sample_out_buf;
Expand Down Expand Up @@ -253,6 +279,7 @@ void buffer_manager_to_i2s(server i2s_callback_if i2s,
}
}
}
#endif
break; // End of send
}
}
Expand All @@ -261,8 +288,11 @@ void buffer_manager_to_i2s(server i2s_callback_if i2s,

[[combinable]]
void ar8035_phy_driver(client interface smi_if smi,
client interface ethernet_cfg_if eth,
streaming chanend c_sound_activity) {
client interface ethernet_cfg_if eth
#if AVB_NUM_MEDIA_OUTPUTS
, streaming chanend c_sound_activity
#endif
) {
ethernet_link_state_t link_state = ETHERNET_LINK_DOWN;
ethernet_speed_t link_speed = LINK_1000_MBPS_FULL_DUPLEX;
const int phy_reset_delay_ms = 1;
Expand Down Expand Up @@ -318,8 +348,10 @@ void ar8035_phy_driver(client interface smi_if smi,
}
t += link_poll_period_ms * XS1_TIMER_KHZ;
break;
#if AVB_NUM_MEDIA_OUTPUTS
case c_sound_activity :> channel_mask:
break;
#endif
case tmr2 when timerafter(t2) :> void:
p_leds_row <: ~(flashing_on * channel_mask);
flashing_on ^= 1;
Expand All @@ -332,13 +364,13 @@ void ar8035_phy_driver(client interface smi_if smi,
enum mac_rx_lp_clients {
MAC_TO_MEDIA_CLOCK_PTP = 0,
MAC_TO_1722_1,
NUM_ETH_TX_LP_CLIENTS
NUM_ETH_RX_LP_CLIENTS
};

enum mac_tx_lp_clients {
MEDIA_CLOCK_PTP_TO_MAC = 0,
AVB1722_1_TO_MAC,
NUM_ETH_RX_LP_CLIENTS
NUM_ETH_TX_LP_CLIENTS
};

enum mac_cfg_clients {
Expand Down Expand Up @@ -389,7 +421,9 @@ int main(void)
ethernet_cfg_if i_eth_cfg[NUM_ETH_CFG_CLIENTS];
ethernet_rx_if i_eth_rx_lp[NUM_ETH_RX_LP_CLIENTS];
ethernet_tx_if i_eth_tx_lp[NUM_ETH_TX_LP_CLIENTS];
#if AVB_NUM_LISTENER_UNITS
streaming chan c_eth_rx_hp;
#endif
streaming chan c_eth_tx_hp;
smi_if i_smi;
streaming chan c_rgmii_cfg;
Expand All @@ -399,8 +433,10 @@ int main(void)

// AVB unit control
chan c_talker_ctl[AVB_NUM_TALKER_UNITS];
#if AVB_NUM_LISTENER_UNITS
chan c_listener_ctl[AVB_NUM_LISTENER_UNITS];
chan c_buf_ctl[AVB_NUM_LISTENER_UNITS];
#endif

// Media control
chan c_media_ctl[AVB_NUM_MEDIA_UNITS];
Expand All @@ -419,27 +455,46 @@ int main(void)
streaming chan c_audio;
interface push_if i_audio_in_push;
interface pull_if i_audio_in_pull;
#if AVB_NUM_LISTENER_UNITS
interface push_if i_audio_out_push;
#endif
#if AVB_NUM_MEDIA_OUTPUTS || AVB_NUM_LISTENER_UNITS
interface pull_if i_audio_out_pull;
#endif
#if AVB_NUM_MEDIA_OUTPUTS
streaming chan c_sound_activity;
#endif

par
{
on tile[1]: rgmii_ethernet_mac(i_eth_rx_lp, NUM_ETH_RX_LP_CLIENTS,
i_eth_tx_lp, NUM_ETH_TX_LP_CLIENTS,
c_eth_rx_hp, c_eth_tx_hp,
#if AVB_NUM_LISTENER_UNITS
c_eth_rx_hp,
#else
null,
#endif
c_eth_tx_hp,
c_rgmii_cfg,
rgmii_ports,
ETHERNET_DISABLE_SHAPER);

on tile[1].core[0]: rgmii_ethernet_mac_config(i_eth_cfg, NUM_ETH_CFG_CLIENTS, c_rgmii_cfg);
on tile[1].core[0]: ar8035_phy_driver(i_smi, i_eth_cfg[MAC_CFG_TO_PHY_DRIVER], c_sound_activity);
on tile[1].core[0]: ar8035_phy_driver(i_smi, i_eth_cfg[MAC_CFG_TO_PHY_DRIVER]
#if AVB_NUM_MEDIA_OUTPUTS
, c_sound_activity
#endif
);

on tile[1]: [[distribute]] smi(i_smi, p_smi_mdio, p_smi_mdc);

on tile[0]: gptp_media_clock_server(i_media_clock_ctl,
null,
#if AVB_NUM_LISTENER_UNITS
c_buf_ctl,
#else
null,
#endif
AVB_NUM_LISTENER_UNITS,
p_fs,
i_eth_rx_lp[MAC_TO_MEDIA_CLOCK_PTP],
Expand All @@ -456,18 +511,34 @@ int main(void)
configure_clock_src(clk_i2s_mclk, p_i2s_mclk);
start_clock(clk_i2s_mclk);
i2s_master(i_i2s,
p_aud_dout, AVB_NUM_MEDIA_OUTPUTS/2,
#if AVB_NUM_MEDIA_OUTPUTS
p_aud_dout,
#else
null,
#endif
AVB_NUM_MEDIA_OUTPUTS/2,
p_aud_din, AVB_NUM_MEDIA_INPUTS/2,
p_i2s_bclk,
p_i2s_lrclk,
clk_i2s_bclk,
clk_i2s_mclk);
}

on tile[0]: [[distribute]] buffer_manager_to_i2s(i_i2s, c_audio, i_i2c[I2S_TO_I2C], c_sound_activity, 0xC,
on tile[0]: [[distribute]] buffer_manager_to_i2s(i_i2s, c_audio, i_i2c[I2S_TO_I2C],
#if AVB_NUM_MEDIA_OUTPUTS
c_sound_activity,
#endif
0xC,
i_gpio[0], i_gpio[1], i_gpio[2], i_gpio[3]);

on tile[0]: audio_buffer_manager(c_audio, i_audio_in_push, i_audio_out_pull, c_media_ctl[0], AUDIO_I2S_IO);
on tile[0]: audio_buffer_manager(c_audio, i_audio_in_push,
#if AVB_NUM_MEDIA_OUTPUTS || AVB_NUM_LISTENER_UNITS
i_audio_out_pull,
#else
null,
#endif
c_media_ctl[0],
AUDIO_I2S_IO);

on tile[0]: [[distribute]] audio_input_sample_buffer(i_audio_in_push, i_audio_in_pull);

Expand All @@ -477,14 +548,18 @@ int main(void)
AVB_NUM_SOURCES,
i_audio_in_pull);

on tile[0]: [[distribute]] audio_output_sample_buffer(i_audio_out_push, i_audio_out_pull);
#if AVB_NUM_LISTENER_UNITS
on tile[0]: [[distribute]] audio_output_sample_buffer(i_audio_out_push,
i_audio_out_pull);

on tile[0]: avb_1722_listener(c_eth_rx_hp,
c_buf_ctl[0],
null,
c_listener_ctl[0],
AVB_NUM_SINKS,
i_audio_out_push);
#endif


on tile[0]: {
char mac_address[6];
Expand All @@ -497,7 +572,11 @@ int main(void)
avb_manager(i_avb, NUM_AVB_MANAGER_CHANS,
null,
c_media_ctl,
#if AVB_NUM_LISTENER_UNITS
c_listener_ctl,
#else
null,
#endif
c_talker_ctl,
i_eth_cfg[MAC_CFG_TO_AVB_MANAGER],
i_media_clock_ctl);
Expand Down Expand Up @@ -526,7 +605,11 @@ void application_task(client interface avb_interface avb,
unsigned char aem_identify_control_value = 0;

// Initialize the media clock
#if (AVB_NUM_SINKS > 0)
avb.set_device_media_clock_type(0, DEVICE_MEDIA_CLOCK_INPUT_STREAM_DERIVED);
#else
avb.set_device_media_clock_type(0, DEVICE_MEDIA_CLOCK_LOCAL_CLOCK);
#endif
avb.set_device_media_clock_rate(0, default_sample_rate);
avb.set_device_media_clock_state(0, DEVICE_MEDIA_CLOCK_STATE_ENABLED);
avb.set_device_media_clock_source(0, 0);
Expand All @@ -542,6 +625,7 @@ void application_task(client interface avb_interface avb,
avb.set_source_channels(j, channels_per_stream);
}

#if AVB_NUM_SINKS
for (int j=0; j < AVB_NUM_SINKS; j++)
{
const int channels_per_stream = AVB_NUM_MEDIA_OUTPUTS/AVB_NUM_SINKS;
Expand All @@ -552,6 +636,7 @@ void application_task(client interface avb_interface avb,
avb.set_sink_sync(j, 0);
avb.set_sink_channels(j, channels_per_stream);
}
#endif

while (1)
{
Expand Down
Loading