TDM Slave#

TDM Slave Tx Usage#

The following code snippet demonstrates the basic usage of a TDM slave Tx device.

#include <xs1.h>
#include "i2s_tdm_slave.h"

// Setup ports and clocks
port_t p_bclk = XS1_PORT_1A;
port_t p_fsync = XS1_PORT_1B;
port_t p_dout = XS1_PORT_1C;

xclock_t clk_bclk = XS1_CLKBLK_1;

// Setup callbacks
// NOTE: See API or sln_voice examples for more on using the callbacks
i2s_tdm_ctx_t ctx;
i2s_callback_group_t i_i2s = {
        .init = (i2s_init_t) i2s_init,
        .restart_check = (i2s_restart_check_t) i2s_restart_check,
        .receive = NULL,
        .send = (i2s_send_t) i2s_send,
        .app_data = NULL,
};

// Initialize the TDM slave
i2s_tdm_slave_tx_16_init(
        &ctx,
        &i_i2s,
        p_dout,
        p_fsync,
        p_bclk,
        clk_bclk,
        0,
        I2S_SLAVE_SAMPLE_ON_BCLK_FALLING,
        NULL);

// Start the slave device in this thread
// NOTE: You may wish to launch the slave device in a different thread.
//       See the XTC Tools documentation reference for lib_xcore.
i2s_tdm_slave_tx_16_thread(&ctx);

TDM Slave Tx API#

The following structures and functions are used to initialize and start a TDM slave Tx instance.

void i2s_tdm_slave_tx_16_init(i2s_tdm_ctx_t *ctx, i2s_callback_group_t *i2s_cbg, port_t p_dout, port_t p_fsync, port_t p_bclk, xclock_t bclk, uint32_t tx_offset, i2s_slave_bclk_polarity_t slave_bclk_polarity, tdm_post_port_init_t tdm_post_port_init)#

I2S TDM slave context initialization for 16 channel TX only with 1 output port, 32b word length, 32b channel length, and 16 channels per frame.

This prepares a context for I2S TDM slave on the provided pins.

The resulting context can be used with i2s_tdm_slave_tx_16_thread().

Parameters:
  • ctx – A pointer to the I2S TDM context to use.

  • i2s_cbg – The I2S callback group pointing to the application’s functions to use for initialization and getting and receiving frames. For TDM the app_data variable within this struct is NOT used.

  • p_dout – The data output port. MUST be a 1b port

  • p_fsync – The fsync input port. MUST be a 1b port

  • p_bclk – The bit clock input port. MUST be a 1b port

  • bclk – A clock that will get configured for use with the bit clock

  • tx_offset – The number of bclks from FSYNC transition to the MSB of Slot 0

  • slave_bclk_pol – The polarity of bclk

  • tdm_post_port_init – Callback to be called just after resource init. Allows for modification of port timing for >15MHz clocks. Set to NULL if not needed.

void i2s_tdm_slave_tx_16_thread(i2s_tdm_ctx_t *ctx)#

I2S TDM TX 16 ch slave task

This task performs I2S TDM slave on the provided context which was initialized with i2s_tdm_slave_tx_16_init(). It will perform callbacks over the i2s_callback_group_t callback group to get data from the application using this component.

This thread assumes 1 data output port, 32b word length, 32b channel length, and 16 channels per frame.

The component performs I2S TDM slave so will expect the fsync and bit clock to be driven externally.

Parameters:
  • ctx – A pointer to the I2S TDM context to use.