PCM#
Introduction#
PCM protocol is widely used in audio applications for transmitting and storing audio data. The PCM peripheral in the SI91x family supports mono audio data transmission and reception with configurable sampling rates and resolutions.
The PCM peripheral provides the following features:
Programmable audio resolutions
Configurable sampling rates
Mono audio support
DMA-based data transfer
Configuration#
The PCM module can be configured using the following parameters:
Audio resolutions supported: sl_pcm_data_resolution_t
Sampling rates supported: sl_pcm_sampling_rate_t
For more information on configuring available parameters, see the respective peripheral example readme document.
Usage#
The PCM module can be initialized and configured to transmit or receive audio data. Below are the steps to use the PCM module:
Initialize the PCM: sl_si91x_pcm_init
Configure PCM settings: sl_si91x_pcm_set_configuration
Perform data operations:
Transmit data: sl_si91x_pcm_transmit_data
Receive data: sl_si91x_pcm_receive_data
Deinitialize the PCM: sl_si91x_pcm_deinit
Additional PCM APIs include:
Register event callback: sl_si91x_pcm_register_event_callback
Unregister event callback: sl_si91x_pcm_unregister_event_callback
Get transmitted data count: sl_si91x_pcm_get_transmit_data_count
Get received data count: sl_si91x_pcm_get_receive_data_count
Abort PCM transfer: sl_si91x_pcm_end_transfer
Get PCM status: sl_si91x_pcm_get_status
(end addtogroup PCM)
Enumerations#
Enumeration for PCM audio data resolutions.
Enumeration for PCM sample rates.
Functions#
To initialize the PCM peripheral.
To uninitialize the PCM peripheral.
To configure the PCM module.
To transmit PCM data.
To receive PCM data.
To register the event callback function.
To unregister the event callback function.
To abort the PCM transfer.
To get the transmitted data count of PCM.
To get the received data count of PCM.
To get the PCM peripheral status.
Enumeration Documentation#
sl_pcm_data_resolution_t#
sl_pcm_data_resolution_t
Enumeration for PCM audio data resolutions.
This enumeration defines the various audio data resolutions for the PCM PCM peripheral. It specifies the number of bits per audio sample that can be used.
Enumerator | |
---|---|
SL_PCM_RESOLUTION_12 | 12-bit resolution. |
SL_PCM_RESOLUTION_16 | 16-bit resolution. |
SL_PCM_RESOLUTION_20 | 20-bit resolution. |
SL_PCM_RESOLUTION_24 | 24-bit resolution. |
SL_PCM_RESOLUTION_32 | 32-bit resolution. |
sl_pcm_sampling_rate_t#
sl_pcm_sampling_rate_t
Enumeration for PCM sample rates.
This enumeration defines the various sample rates for the PCM PCM peripheral. It specifies the number of samples per second (in Hz) that can be used.
Enumerator | |
---|---|
SL_PCM_SAMPLING_RATE_8000 | 8 kHz |
SL_PCM_SAMPLING_RATE_11025 | 11.025 kHz |
SL_PCM_SAMPLING_RATE_16000 | 16 kHz |
SL_PCM_SAMPLING_RATE_22050 | 22.05 kHz |
SL_PCM_SAMPLING_RATE_24000 | 24 kHz |
Function Documentation#
sl_si91x_pcm_init#
sl_status_t sl_si91x_pcm_init (uint32_t pcm_instance, sl_i2s_handle_t * pcm_handle)
To initialize the PCM peripheral.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | pcm_instance | Double pointer to the I2S/PCM driver handle sl_i2s_handle_t. |
sl_i2s_handle_t * | [in] | pcm_handle | 0 - PCM0, 1 - PCM1 (ULP_PCM) |
This API enables the clock for the PCM peripheral and configures the SCLK, WSCLK, DIN, and DOUT pins. It also requires the address of a pointer for storing the PCM handle, which can be used for other function calls.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Operation successful.
SL_STATUS_INVALID_PARAMETER - Parameters are invalid.
SL_STATUS_NULL_POINTER - Invalid null pointer received as an argument.
SL_STATUS_BUSY - Driver is busy.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_pcm_deinit#
sl_status_t sl_si91x_pcm_deinit (sl_i2s_handle_t * pcm_handle)
To uninitialize the PCM peripheral.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_i2s_handle_t * | [in] | pcm_handle | Double pointer to the I2S/PCM driver handle sl_i2s_handle_t. |
This API disables the DMA instance used for PCM transfer and powers down the PCM peripheral by disabling the clock supply to PCM.
Pre-condition:
sl_si91x_pcm_init must be called before this function.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Operation successful.
SL_STATUS_INVALID_PARAMETER - Parameters are invalid.
SL_STATUS_NULL_POINTER - Invalid null pointer received as an argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
Note
When the PCM module is used in combination with other peripherals, see the notes below while deinitializing in the application:
Whenever sl_si91x_pcm_deinit() is called, it will disable the clock for the peripheral. To power off the peripheral, you have to power down the power domain (PERI_EFUSE) which contains the following peripherals: USART, UART, I2C, SSI Master, SSI Slave, Generic-SPI Master, PCM Master, PCM Slave, Micro-DMA Controller, Config Timer, Random-Number Generator, CRC Accelerator, SIO, QEI, MCPWM, and EFUSE. Use the following API to power down the particular power domain if other peripherals are not being used: sl_si91x_peri_efuse_power_down()
Some peripherals (ULP Peripherals, UULP Peripherals, GPDMA, and SDIO-SPI) have separate domains and can be powered down independently. For additional details, see the Power Architecture section in the Hardware Reference Manual. The ULP_UART has a separate power domain, ULPSS_PWRGATE_ULP_UART, which can be powered down independently. See the rsi_power_save.h file for all power gate definitions.
sl_si91x_pcm_set_configuration#
sl_status_t sl_si91x_pcm_set_configuration (sl_i2s_handle_t pcm_handle, uint16_t pcm_sampling_frequency, uint16_t pcm_resolution, uint16_t mode)
To configure the PCM module.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_i2s_handle_t | [in] | pcm_handle | Pointer to the I2S/PCM driver handle sl_i2s_handle_t. |
uint16_t | [in] | pcm_sampling_frequency | The sampling frequency for sending or eceiving data. |
uint16_t | [in] | pcm_resolution | Data resolution for the data being sent or received. |
uint16_t | [in] | mode | Mode of operation (e.g., master or slave mode). |
Note that PCM supports only mono mode.
This API configures sampling frequency and resolution of the PCM module.
Pre-conditions:
sl_si91x_pcm_init must be called before this function.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - Parameters are invalid.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_pcm_transmit_data#
sl_status_t sl_si91x_pcm_transmit_data (sl_i2s_handle_t pcm_handle, const void * data, uint32_t size)
To transmit PCM data.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_i2s_handle_t | [in] | pcm_handle | Pointer to the I2S/PCM driver handle sl_i2s_handle_t. |
const void * | [in] | data | Address of the transmit data. |
uint32_t | [in] | size | Size of the data to be transmitted. |
This API configures the PCM Tx DMA channel descriptors and triggers the DMA transfer.
Pre-conditions:
sl_si91x_pcm_init must be called before this function.
sl_si91x_pcm_set_configuration must be called before this function.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - Parameters are invalid.
SL_STATUS_NULL_POINTER - Invalid null pointer received as an argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_pcm_receive_data#
sl_status_t sl_si91x_pcm_receive_data (sl_i2s_handle_t pcm_handle, const void * data, uint32_t size)
To receive PCM data.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_i2s_handle_t | [in] | pcm_handle | Pointer to the I2S/PCM driver handle sl_i2s_handle_t. |
const void * | [in] | data | Address of the receive data. |
uint32_t | [in] | size | Size of the data to be received. |
This API configures the PCM Rx DMA channel descriptors and triggers the DMA transfer.
Pre-conditions:
sl_si91x_pcm_init must be called before this function.
sl_si91x_pcm_set_configuration must be called before this function.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - Parameters are invalid.
SL_STATUS_NULL_POINTER - Invalid null pointer received as an argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_pcm_register_event_callback#
sl_status_t sl_si91x_pcm_register_event_callback (sl_i2s_handle_t pcm_handle, sl_i2s_signal_event_t callback_event)
To register the event callback function.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_i2s_handle_t | [in] | pcm_handle | Pointer to the I2S/PCM driver handle sl_i2s_handle_t. |
sl_i2s_signal_event_t | [in] | callback_event | Pointer to the function to be called at the time of interrupt. |
This API registers a callback function to notify the application of transfer complete events. Callbacks should be registered before starting the PCM transfer.
Pre-conditions:
sl_si91x_pcm_init must be called before this function.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_BUSY - Driver is busy.
SL_STATUS_NULL_POINTER - The parameter is a null pointer.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_pcm_unregister_event_callback#
sl_status_t sl_si91x_pcm_unregister_event_callback (sl_i2s_handle_t pcm_handle)
To unregister the event callback function.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_i2s_handle_t | [in] | pcm_handle | Pointer to the I2S/PCM driver handle sl_i2s_handle_t. |
This function unregisters the previously registered callback function. It can be used only if callbacks are registered using sl_si91x_pcm_register_event_callback().
Pre-condition:
sl_si91x_pcm_register_event_callback must be called before this function.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - Parameters are invalid.
SL_STATUS_NULL_POINTER - Invalid null pointer received as argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_pcm_end_transfer#
sl_status_t sl_si91x_pcm_end_transfer (sl_i2s_handle_t pcm_handle, sl_i2s_xfer_type_t abort_type)
To abort the PCM transfer.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_i2s_handle_t | [in] | pcm_handle | Pointer to the I2S/PCM driver handle sl_i2s_handle_t. |
sl_i2s_xfer_type_t | [in] | abort_type | Abort type, either ARM_SAI_ABORT_SEND or ARM_SAI_ABORT_RECEIVE. |
This function disables the PCM clocks and DMA channel, stopping the frame-sync generation.
Pre-conditions:
sl_si91x_pcm_init must be called before this function.
sl_si91x_pcm_transmit_data or sl_si91x_pcm_receive_data must be called before this function.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - Parameters are invalid.
SL_STATUS_NULL_POINTER - Invalid null pointer received as an argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_pcm_get_transmit_data_count#
uint32_t sl_si91x_pcm_get_transmit_data_count (sl_i2s_handle_t pcm_handle)
To get the transmitted data count of PCM.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_i2s_handle_t | [in] | pcm_handle | Pointer to the I2S/PCM driver handle sl_i2s_handle_t. |
This function retrieves the count of data bytes that have been transmitted by the PCM module. It can be used to monitor the progress of an ongoing PCM data transfer.
Pre-conditions:
sl_si91x_pcm_init must be called before this function.
sl_si91x_pcm_transmit_data must be called before this function.
Returns
uint32_t The number of data bytes transmitted.
sl_si91x_pcm_get_receive_data_count#
uint32_t sl_si91x_pcm_get_receive_data_count (sl_i2s_handle_t pcm_handle)
To get the received data count of PCM.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_i2s_handle_t | [in] | pcm_handle | Pointer to the I2S/PCM driver handle sl_i2s_handle_t. |
This function retrieves the count of data bytes that have been received by the PCM module. It can be used to monitor the progress of an ongoing PCM data transfer.
Pre-conditions:
sl_si91x_pcm_init must be called before this function.
sl_si91x_pcm_receive_data must be called before this function.
Returns
uint32_t The number of data bytes received.
sl_si91x_pcm_get_status#
sl_i2s_status_t sl_si91x_pcm_get_status (sl_i2s_handle_t pcm_handle)
To get the PCM peripheral status.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_i2s_handle_t | [in] | pcm_handle | Pointer to the I2S/PCM driver handle sl_i2s_handle_t. |
This function retrieves the current status of the PCM module, including:
Frame error
Rx busy
Rx overflow
Tx busy
Tx underflow
Pre-conditions:
sl_si91x_pcm_init must be called before this function.
Returns
sl_pcm_status_t Structure containing the pcm status information.