<< >>

Component functions

The following functions provide components that can be combined in the top-level main. For details on the ethernet and TCP/IP components see the Ethernet Component Guide and the XTCP Component Guide.

Core Components

void ptp_server(chanend mac_rx, chanend mac_tx, chanend client[], int num_clients, enum ptp_server_type server_type)

This function runs the PTP server.

It takes one thread and runs indefinitely

Parameters:
  • mac_rx – chanend connected to the ethernet server (receive)
  • mac_tx – chanend connected to the ethernet server (transmit)
  • client – an array of chanends to connect to clients of the ptp server
  • num_clients – The number of clients attached
  • server_type – The type of the server (PTP_GRANDMASTER_CAPABLE or PTP_SLAVE_ONLY)
void media_clock_server(chanend media_clock_ctl, chanend ptp_svr, chanend ?buf_ctl[], int buf_ctl_size, chanend ?clk_ctl[], int clk_ctl_size)

The media clock server.

Parameters:
  • media_clock_ctl – chanend connected to the main control thread and passed into avb_init()
  • ptp_svr – chanend connected to the PTP server
  • buf_ctl[] – array of links to listener components requiring buffer management
  • buf_ctl_size – size of the buf_ctl array
  • clk_ctl[] – array of links to components requiring a media clock
  • clk_ctl_size – size of the clk_ctl array
void avb_1722_listener(chanend ethernet_rx_svr, chanend ?buf_ctl, chanend ?ptp_ctl, chanend listener_ctl, int num_streams)

An AVB IEEE 1722 audio listener thread.

This thread implements a listener. It takes IEEE 1722 packets from the ethernet MAC and splits them into output FIFOs. The buffer fill level of these streams is set in conjunction with communication to the media clock server. This thread is dynamically configured using the AVB control API.

Parameters:
  • ethernet_rx_svr – receive link to the ethernet MAC
  • ethernet_tx_svr – transmit link to the ethernet MAC
  • buf_ctl – buffer control link to the media clock server
  • ptp_ctl – PTP server link for retreiving PTP time info
  • listener_ctl – channel to configure the listener (given to avb_init())
  • num_streams – the number of streams the unit will handle
void avb_1722_talker(chanend ptp_svr, chanend ethernet_tx_svr, chanend talker_ctl, int num_streams)

An AVB IEEE 1722 audio talker thread.

This thread implements a talker, taking media input FIFOs and combining them into 1722 packets to be sent to the ethernet component. It is dynamically configured using the AVB control API.

Parameters:
  • ptp_svr – link to the PTP timing server
  • ethernet_tx_svr – transmit link to the ethernet MAC
  • talker_ctl – channel to configure the talker (given to avb_init())
  • num_streams – the number of streams the unit controls

Audio Components

The following types are used by the AVB audio components:

media_output_fifo_t

This type provides a handle to a media output FIFO.

media_output_fifo_data_t

This type provides the data structure used by a media output FIFO.

media_input_fifo_t

This type provides a handle to a media input fifo.

media_input_fifo_data_t

This type provides the data structure used by a media input fifo.

The following functions implement AVB audio components:

void init_media_input_fifos(media_input_fifo_t ififos[], media_input_fifo_data_t ififo_data[], int n)

Initialize media input fifos.

This function intializes media input FIFOs and ties the handles to their associated data structures. It should be called before the main component function on a thread to setup the FIFOs.

Parameters:
  • ififos – an array of media input FIFO handles to initialize
  • ififo_data – an array of associated data structures
  • n – the number of FIFOs to initialize
void init_media_output_fifos(media_output_fifo_t ofifos[], media_output_fifo_data_t ofifo_data[], int n)

Initialize media output FIFOs.

This function initializes media output FIFOs and ties the handles to their associated data structures. It should be called before the main component function on a thread to setup the FIFOs.

Parameters:
  • ofifos – an array of media output FIFO handles to initialize
  • ofifo_data – an array of associated data structures
  • n – the number of FIFOs to initialize
void i2s_master(const clock mclk, clock bclk, out buffered port:32 p_bclk, out buffered port:32 p_lrclk, out buffered port:32 p_dout[], int num_out, in buffered port:32 p_din[], int num_in, int master_to_word_clock_ratio, streaming chanend ?c_listener, media_input_fifo_t ?input_fifos[], chanend media_ctl, int clk_ctl_index)

Input and output audio data using I2S format with the XCore acting as master.

This function implements a thread that can handle several synchronous I2S interfaces. It inputs and outputs 24-bit data packed into 32 bits.

The function will take input from the I2S interface and put the samples directly into shared memory media input FIFOs. The output samples are received over a channel. Every two word clock periods (i.e. once a sample) a timestamp is sent from this thread over the channel and num_out samples are taken from the channel.

The master clock is generated externally by the PLL. A clock block clocks the Bit clock port (aka serial clock or sclk), from the master clock, and we write out a clock pattern on this port to generate the correct divided BCLK. Likewise, a clock block puts the BCLK as the clock for the LRCLK port. We also write out data to the LRCLK port to generate a correct LRCLK pattern.

This function can handle up to 8in and 8out at 48KHz.

Parameters:
  • mclk – clock block that clocks the system clock of the codec; needs to be configured before the function call
  • bclk – clock block that clocks the bit clock; configured within the i2s_master function
  • p_bclk – the port to output the bit clock to
  • p_lrclk – the port to output the word clock to
  • p_dout – array of ports to output data to
  • num_out – number of output ports
  • p_din – array of ports to input data from
  • num_in – number of input ports
  • master_to_word_clock_ratio – the ratio of the master clock to the word clock; must be one of 128, 256 or 512
  • c_listener – chanend connector to a listener component
  • input_fifos – a map from the inputs to local talker streams. The channels of the inputs are interleaved, for example, if you have two input ports, the map {0,1,0,1} w would map to the two stereo local talker streams 0 and 1.
  • media_ctl – the media fifo control channel
  • clk_ctl_index – the index of the clk_ctl channel array that controls the master clock fo the codec
void media_output_fifo_to_xc_channel(chanend media_ctl, streaming chanend samples_out, int clk_ctl_index, media_output_fifo_t ofifos[], int num_channels)

Output audio streams from media fifos to an XC channel.

This function outputs samples from several media output FIFOs over an XC channel over the streaming chanend samples_out.

The protocol over the channel is that the thread expects a timestamp to be sent to it and then it will output num_channels samples, pulling from the ofifos array. It will then expect another timestamp before the next set of samples.

Parameters:
  • media_ctl – chanend connected to the main control thread
  • samples_out – the chanend on which samples are output
  • clk_ctl_index – the index in the clk_ctl array passed to media_clock_server() that controls the rate of the FIFOs (i.e. the rate at which samples are pulled from the other end of the channel). This should be -1 if the pull rate is not controlled by the media clock server.
  • ofifos – array of media output FIFOs to pull from
  • num_channels – the number of channels (or FIFOs)
void media_output_fifo_to_xc_channel_split_lr(chanend media_ctl, streaming chanend samples_out, int clk_ctl_index, media_output_fifo_t output_fifos[], int num_channels)

Output audio streams from media FIFOs to an XC channel, splitting left and right pairs.

This function outputs samples from several media output FIFOs over an XC channel over the streaming chanend samples_out. The media FIFOs are assumed to be grouped in left/right stereo pairs which are then split.

The protocol over the channel is that the thread expects a timestamp to be sent to it and then it will first output num_channels/2 samples, pulling from all the even indexed elements of the ofifos array and then output all the odd elements. It will then expect another timestamp before the next set of samples.

Parameters:
  • media_ctl – chanend connected to the main control thread
  • samples_out – the chanend on which samples are output
  • clk_ctl_index – the index in the clk_ctl array passed to media_clock_server() that controls the rate of the FIFOs (i.e. the rate at which samples are pulled from the other end of the channel). This should be -1 if the pull rate is not controlled by the media clock server.
  • output_fifos – array of media output fifos to pull from
  • num_channels – the number of channels (or FIFOs)