nrfx 4.5.0
Loading...
Searching...
No Matches
TDM driver

Time Division Multiplexed Audio Interface (TDM) peripheral driver. More...

Topics

 TDM peripheral driver configuration
 

Data Structures

struct  nrfx_tdm_clk_params_t
 Parameters used to describe TDM clock prescaling. More...
 
struct  nrfx_tdm_prescalers_t
 TDM prescalers structure. More...
 
struct  nrfx_tdm_buffers_t
 TDM transfer buffers structure. More...
 
struct  nrfx_tdm_config_t
 TDM driver configuration structure. More...
 
struct  nrfx_tdm_t
 TDM driver instance data structure. More...
 

Macros

#define NRFX_TDM_DEFAULT_CONFIG(_sck_pin, _fsync_pin, _mck_pin, _sdout_pin, _sdin_pin)
 TDM driver default configuration.
 
#define NRFX_TDM_NUM_OF_CHANNELS   (TDM_CONFIG_CHANNEL_NUM_NUM_Max + 1)
 Maximum number of TDM channels.
 
#define NRFX_TDM_MIN_TRANSFER_SIZE   TDM_MIN_TRANSFER_SIZE
 Minimal transfer size of TDM buffer in 32-bit words.
 
#define NRFX_TDM_MIN_TRANSFER_SIZE   TDM_MIN_TRANSFER_SIZE
 Minimal transfer size of TDM buffer in 32-bit words.
 
#define NRFX_TDM_STATUS_NEXT_BUFFERS_NEEDED   (1UL << 0)
 TDM status flag indicating that the application must provide buffers that are to be used in the next part of the transfer. A call to nrfx_tdm_next_buffers_set must be done before the currently used buffers are completely processed (that is, the time remaining for supplying the next buffers depends on the used size of the buffers).
 
#define NRFX_TDM_STATUS_TRANSFER_STOPPED   (1UL << 1)
 TDM status flag indicating that The peripheral has been stopped and all buffers that were passed to the driver have been released.
 
#define NRFX_TDM_INSTANCE(reg)
 Macro for creating a TDM driver instance.
 

Typedefs

typedef void(* nrfx_tdm_data_handler_t) (nrfx_tdm_buffers_t const *p_released, uint32_t status)
 TDM driver data handler type.
 

Functions

int nrfx_tdm_init (nrfx_tdm_t *p_instance, nrfx_tdm_config_t const *p_config, nrfx_tdm_data_handler_t handler)
 Function for initializing the TDM driver.
 
void nrfx_tdm_uninit (nrfx_tdm_t *p_instance)
 Function for uninitializing the TDM driver.
 
bool nrfx_tdm_init_check (nrfx_tdm_t const *p_instance)
 Function for checking if the TDM driver instance is initialized.
 
int nrfx_tdm_reconfigure (nrfx_tdm_t *p_instance, nrfx_tdm_config_t const *p_config)
 Function for reconfiguring the TDM driver.
 
int nrfx_tdm_start (nrfx_tdm_t *p_instance, nrfx_tdm_buffers_t const *p_initial_buffers)
 Function for starting the continuous TDM transfer.
 
int nrfx_tdm_next_buffers_set (nrfx_tdm_t *p_instance, nrfx_tdm_buffers_t const *p_buffers)
 Function for supplying the buffers to be used in the next part of the transfer.
 
void nrfx_tdm_stop (nrfx_tdm_t *p_instance, bool abort)
 Function for stopping the TDM transfer.
 
int nrfx_tdm_prescalers_calc (nrfx_tdm_clk_params_t const *clk_params, nrfx_tdm_prescalers_t *prescalers)
 Function for calculating TDM clock prescaler values.
 
void nrfx_tdm_irq_handler (nrfx_tdm_t *p_instance)
 Driver interrupt handler.
 

Detailed Description

Time Division Multiplexed Audio Interface (TDM) peripheral driver.

Macro Definition Documentation

◆ NRFX_TDM_DEFAULT_CONFIG

#define NRFX_TDM_DEFAULT_CONFIG ( _sck_pin,
_fsync_pin,
_mck_pin,
_sdout_pin,
_sdin_pin )
Value:
{ \
.sck_pin = _sck_pin, \
.fsync_pin = _fsync_pin, \
.mck_pin = _mck_pin, \
.sdout_pin = _sdout_pin, \
.sdin_pin = _sdin_pin, \
.irq_priority = NRFX_TDM_DEFAULT_CONFIG_IRQ_PRIORITY, \
.alignment = NRF_TDM_ALIGN_LEFT, \
.sample_width = NRF_TDM_SWIDTH_16BIT, \
.rx_channel_mask = NRF_TDM_CHANNEL_RX0_MASK, \
.tx_channel_mask = NRF_TDM_CHANNEL_TX0_MASK, \
.channel_number = 2, \
.channel_delay = NRF_TDM_CHANNEL_DELAY_1CK, \
.sck_polarity = NRF_TDM_POLARITY_POSEDGE, \
.fsync_polarity = NRF_TDM_POLARITY_NEGEDGE, \
.fsync_duration = NRFX_TDM_DEFAULT_FSYNC_DURATION, \
.ors = 0, \
.mck_src = NRF_TDM_SRC_PCLK32M, \
.sck_src = NRF_TDM_SRC_PCLK32M, \
.prescalers = \
{ \
.mck_div = NRF_TDM_MCK_DIV_8, \
.sck_div = NRF_TDM_SCK_DIV_8, \
}, \
}
@ NRF_TDM_SRC_PCLK32M
32MHz peripheral clock.
Definition nrf_tdm.h:205
@ NRF_TDM_POLARITY_POSEDGE
Synchronization at rising edge of the reference signal.
Definition nrf_tdm.h:277
@ NRF_TDM_POLARITY_NEGEDGE
Synchronization at falling edge of the reference signal.
Definition nrf_tdm.h:278
@ NRF_TDM_MODE_MASTER
Master mode.
Definition nrf_tdm.h:143
@ NRF_TDM_SWIDTH_16BIT
16 bit.
Definition nrf_tdm.h:216
@ NRF_TDM_ALIGN_LEFT
Left-aligned.
Definition nrf_tdm.h:228
@ NRF_TDM_CHANNEL_DELAY_1CK
1 clock pulse delay. Used with original TDM format.
Definition nrf_tdm.h:270
@ NRF_TDM_CHANNEL_RX0_MASK
Enable RX channel 0 data.
Definition nrf_tdm.h:235
@ NRF_TDM_CHANNEL_TX0_MASK
Enable TX channel 0 data.
Definition nrf_tdm.h:243
@ NRF_TDM_MCK_DIV_8
MCK divided by 8.
Definition nrf_tdm.h:163
@ NRF_TDM_SCK_DIV_8
SCK divided by 8.
Definition nrf_tdm.h:186

TDM driver default configuration.

This configuration sets up TDM with the following options:

  • Master mode
  • Left alignment
  • 16 bit sample width
  • One RX channel enabled
  • One TX channel enabled
  • Delay of one clock pulse
  • TX on the falling edge of SCK, RX on the rising edge of SCK
  • Frame starts at falling edge of FSYNC.
  • Zeros sent as over-read
  • PCLK32M clock source
  • MCK frequency divider equal to 8
  • SCK frequency divider equal to 8
Parameters
[in]_sck_pinSerial clock pin number.
[in]_fsync_pinFrame Synchronization pin number.
[in]_mck_pinMaster clock pin number.
[in]_sdout_pinSerial Data Output pin number.
[in]_sdin_pinSerial Data Input pin number.

◆ NRFX_TDM_INSTANCE

#define NRFX_TDM_INSTANCE ( reg)
Value:
{ \
.p_reg = (NRF_TDM_Type *)reg, \
.cb = {0}, \
}

Macro for creating a TDM driver instance.

◆ NRFX_TDM_MIN_TRANSFER_SIZE [1/2]

#define NRFX_TDM_MIN_TRANSFER_SIZE   TDM_MIN_TRANSFER_SIZE

Minimal transfer size of TDM buffer in 32-bit words.

Minimum TDM transfer size in bytes.

◆ NRFX_TDM_MIN_TRANSFER_SIZE [2/2]

#define NRFX_TDM_MIN_TRANSFER_SIZE   TDM_MIN_TRANSFER_SIZE

Minimal transfer size of TDM buffer in 32-bit words.

Minimum TDM transfer size in bytes.

Typedef Documentation

◆ nrfx_tdm_data_handler_t

typedef void(* nrfx_tdm_data_handler_t) (nrfx_tdm_buffers_t const *p_released, uint32_t status)

TDM driver data handler type.

A data handling function of this type must be specified during the initialization of the driver. The driver will call this function when it finishes transfer using buffers passed to it by the application, and when it needs to be provided with buffers for the next part of the transfer.

Note
The p_released pointer passed to this function is temporary and will be invalid after the function returns, hence it cannot be stored and used later. If needed, the pointed content (that is, buffers pointers) must be copied instead.
Parameters
[in]p_releasedPointer to a structure with pointers to buffers passed previously to the driver that will no longer be accessed by it (they can be now safely released or used for another purpose, in particular for a next part of the transfer). This pointer will be NULL if the application did not supply the buffers for the next part of the transfer (via a call to nrfx_tdm_next_buffers_set) since the previous time the data handler signaled such need. This means that data corruption occurred (the previous buffers are used for the second time) and no buffers can be released at the moment. Both pointers in this structure are NULL when the handler is called for the first time after a transfer is started, because no data has been transferred yet at this point. In all successive calls, the pointers specify what has been sent (TX) and what has been received (RX) in the part of the transfer that has just been completed (provided that a given direction is enabled, see nrfx_tdm_start).
Note
Since the peripheral is stopped asynchronously, buffers that are released after the call to nrfx_tdm_stop are not used entirely. In this case, only a part (if any) of the TX buffer has been actually transmitted and only a part (if any) of the RX buffer is filled with received data.
Parameters
[in]statusBit field describing the current status of the transfer. It can be 0 or a combination of the following flags:

Function Documentation

◆ nrfx_tdm_init()

int nrfx_tdm_init ( nrfx_tdm_t * p_instance,
nrfx_tdm_config_t const * p_config,
nrfx_tdm_data_handler_t handler )

Function for initializing the TDM driver.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_configPointer to the structure with the initial configuration.
[in]handlerData handler provided by the user.
Return values
0Initialization was successful.
-EALREADYThe driver is already initialized.
-EINVALThe requested combination of configuration options is not allowed by the TDM peripheral.

◆ nrfx_tdm_init_check()

bool nrfx_tdm_init_check ( nrfx_tdm_t const * p_instance)

Function for checking if the TDM driver instance is initialized.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
trueInstance is already initialized.
falseInstance is not initialized.

◆ nrfx_tdm_irq_handler()

void nrfx_tdm_irq_handler ( nrfx_tdm_t * p_instance)

Driver interrupt handler.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_tdm_next_buffers_set()

int nrfx_tdm_next_buffers_set ( nrfx_tdm_t * p_instance,
nrfx_tdm_buffers_t const * p_buffers )

Function for supplying the buffers to be used in the next part of the transfer.

The application must call this function when the data handler receives NRFX_TDM_STATUS_NEXT_BUFFERS_NEEDED in the status parameter. The call can be done immediately from the data handler function or later, but it has to be done before the TDM peripheral finishes processing the buffers supplied previously. Otherwise, data corruption will occur.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_buffersPointer to a structure specifying the buffers to be used in the upcoming part of the transfer.
Return values
0If the operation was successful.
-EINPROGRESSIf the buffers were already supplied or the peripheral is currently being stopped.
-EINVALRequired buffers were not provided or the provided transfer length is too short.
-EACCESThe provided buffers are not placed in the Data RAM region.

◆ nrfx_tdm_prescalers_calc()

int nrfx_tdm_prescalers_calc ( nrfx_tdm_clk_params_t const * clk_params,
nrfx_tdm_prescalers_t * prescalers )

Function for calculating TDM clock prescaler values.

Call this function to find suitable value for prescalers in nrfx_tdm_config_t structure.

If prescaler calculation for a specific clock is to be skipped, its desired frequency should be set to 0.

Application must ensure that requested clock frequency can be achieved using its base clock frequency.

Parameters
[in]clk_paramsParameters used to describe clock prescaling.
[out]prescalersPrescaler structure pointer to be filled with prescaler values.
Return values
0Suitable prescaler values were found for both clocks.
-EINVALNo suitable prescaler values were found for either of the clocks.

◆ nrfx_tdm_reconfigure()

int nrfx_tdm_reconfigure ( nrfx_tdm_t * p_instance,
nrfx_tdm_config_t const * p_config )

Function for reconfiguring the TDM driver.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_configPointer to the structure with the configuration.
Return values
0Reconfiguration was successful.
-EINPROGRESSThe driver is uninitialized.
-EINVALThe requested combination of configuration options is not allowed by the TDM peripheral.

◆ nrfx_tdm_start()

int nrfx_tdm_start ( nrfx_tdm_t * p_instance,
nrfx_tdm_buffers_t const * p_initial_buffers )

Function for starting the continuous TDM transfer.

The TDM data transfer can be performed in one of three modes: RX (reception) only, TX (transmission) only, or in both directions simultaneously. The mode is selected by specifying a proper buffer for a given direction in the call to this function or by passing NULL instead if this direction is to be disabled.

The length of the buffer (which is a common value for RX and TX if both directions are enabled) is specified in 32-bit words. One 32-bit memory word can either contain four 8-bit samples, two 16-bit samples, or one right-aligned 24-bit sample sign-extended to a 32-bit value. For a detailed memory mapping for different supported configurations, see the Product Specification.

Note
Peripherals using EasyDMA (including TDM) require the transfer buffers to be placed in the Data RAM region. If this condition is not met, this function will fail with the error code -EACCES.
Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_initial_buffersPointer to a structure specifying the buffers to be used in the initial part of the transfer (buffers for all consecutive parts are provided through the data handler).
Return values
0The operation was successful.
-EINPROGRESSThe driver has not been initialized.
-EALREADYTransfer has already been already started.
-EINVALNo buffers were provided or the provided transfer length is too short.
-EACCESThe provided buffers are not placed in the Data RAM region.

◆ nrfx_tdm_stop()

void nrfx_tdm_stop ( nrfx_tdm_t * p_instance,
bool abort )

Function for stopping the TDM transfer.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]abortTrue if transfer is to be stopped immediately, false if transfer is to be stopped only after currently processed buffers are filled.

◆ nrfx_tdm_uninit()

void nrfx_tdm_uninit ( nrfx_tdm_t * p_instance)

Function for uninitializing the TDM driver.

Parameters
[in]p_instancePointer to the driver instance structure.