![]() |
Synergy Software Package User's Manual
|
The I2S Audio Playback Framework module provides a high-level API for Audio Playback applications and handles the synchronization needed to play 8-bit or 16-bit pulse-code modulation (PCM) samples. The Audio Playback Framework uses the I2S, Timer (AGT or GPT) and Data Transfer (DMA or DTC) peripherals on a Synergy MCU. A user defined callback can be created to respond to the need for additional data.
The Audio Playback I2S Framework module defines APIs for operations such as opening, starting, playing and stopping. A complete list of the available APIs, an example API call and a short description of each can be found in the following table. A table of status return values follows the API summary table.
Audio Playback I2S Framework Module API Summary
| Function Name | Example API Call and Description |
|---|---|
| open | g_sf_audio_playback_hw0.p_api->open( g_sf_audio_playback_hw0.p_ctrl, g_sf_audio_playback_hw0.p_cfg);Open a device channel for read/write and control. |
| start | g_sf_audio_playback_hw0.p_api->start( g_sf_audio_playback_hw0.p_ctrl, &p_data, Timeout);Start Audio Playback Hardware. |
| stop | g_sf_audio_playback_hw0.p_api->stop( g_sf_audio_playback_hw0.p_ctrl);Stop Audio Playback Hardware. |
| play | g_sf_audio_playback_hw0.p_api->play (g_sf_audio_playback_hw0.p_ctrl, p_buffer, length);Play audio buffer. |
| dataTypeGet | g_sf_audio_playback_hw0.p_api->dataTypeGet( g_sf_audio_playback_hw0.p_ctrl, p_data_type);Stores expected data type in provided pointer p_data_type. |
| close | g_sf_audio_playback_hw0.p_api->close( g_sf_audio_playback_hw0.p_ctrl);Close the audio module. |
| versionGet | g_sf_audio_playback_hw0.p_api->versionGet(&version);Return the version of the module with the version pointer. |
Status Return Values
| Name | Description |
|---|---|
| SSP_SUCCESS | Function successful. |
| SSP_ERR_OUT_OF_MEMORY | The number of streams open at once is limited to SF_AUDIO_PLAYBACK_CFG_MAX_STREAMS. If thisnumber is exceeded, an out of memory error occurs. |
| SSP_ERR_TIMEOUT | Timeout occurred before playback finished. |
The I2S Audio Playback Framework module creates a thread internally to support audio playback. The figure below shows a flowchart of the audio playback framework thread and its interactions with public Audio Playback Framework APIs.
Suggested use of the audio playback framework:
The Audio Playback Framework supports multiple audio streams on a single hardware port. A block diagram of the modules required if two streams are used is shown in following figure:
This section describes how to include the Audio Playback I2S Framework module in an application using the SSP configurator.
To add the Audio Playback I2S Framework module to an application, simply add it to a HAL /Common thread using the stacks selection sequence given in the following table. (The default name for the Audio Playback I2S Framework module is g_sf_audio_playback_hw0. This name can be changed in the associated Properties window.)
Audio Playback I2S Framework Module Selection Sequence
| Resource | ISDE Tab | Stacks Selection Sequence |
|---|---|---|
| g_sf_audio_playback_hw0 Audio Playback Hardware Framework on sf_audio_playback_hw_i2s | Threads | New Stack> Framework> Audio> Audio Playback Hardware Framework on sf_audio_playback_hw_i2s |
When the Audio Playback I2S Framework module on sf_audio_playback_hw_i2s is added to the thread stack as shown in the following figure, the configurator automatically adds any needed lower‑level modules. Any modules needing additional configuration information have the box text highlighted in Red. Modules with a Gray band are individual modules that stand alone. Modules with a Blue band are shared or common; they need only be added once and can be used by multiple stacks. Modules with a Pink band can require the selection of lower-level modules; these are either optional or recommended. (This is indicated in the block with the inclusion of this text.) If the addition of lower-level modules is required, the module description include Add in the text. Clicking on any Pink banded modules brings up the New icon and displays possible choices.
The Audio Playback I2S Framework module must be configured by the user for the desired operation. The SSP configuration window will automatically identify (by highlighting the block in red) any required configuration selections, such as interrupts or operating modes, which must be configured for lower-level modules in order to ensure successful operation. Furthermore, only those properties that can be changed without causing conflicts are available for modification. Other properties are 'locked' and are not available for changes, and are identified with a lock icon for the 'locked' property in the Properties window in the ISDE. This approach simplifies the configuration process and makes it much less error-prone than previous 'manual' approaches to configuration. The available configuration settings and defaults for all the user-accessible properties are given in the Properties tab within the SSP configurator, and are shown in the following tables for easy reference.
Configuration Settings for the Audio Playback I2S Framework Module on sf_audio_playback_hw_i2s
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Enable or disable the parameter error checking. |
| Name | g_sf_audio_playback_hw0 | Module name. |
In some cases, settings other than the defaults for lower level modules can be desirable. For example, it might be useful to select the DAC or I2S Channel based on the target hardware implementation. The configurable properties for the lower level stack modules are given in the following sections for completeness and as a reference.
Typically, only a small number of settings must be modified from the default for lower-level drivers as indicated with red text in the thread stack block. Notice that some of the configuration properties must be set to a certain value for proper framework operation and will be locked to prevent user modification. The following table identifies all the settings within the properties section for the module.
Configuration Settings for the I2S HAL Module on r_ssi
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Enables or disables the parameter checking. |
| Name | g_i2s0 | Module name. |
| Channel | 0 | Physical hardware channel. |
| Audio Clock Frequency (Hertz) | 2822400 | Input audio clock frequency, used to generate the I2S clock. Must be a multiple between 1 and 128 of: (sampling_freq_hz * word_length_in_bits). |
| Sampling Frequecy (Hertz) | 44100 | Sampling frequency of audio data. |
| Data Bits | 8 bits, 16, 18, 20, 22, 24 Default: 16 bits | Bit depth of audio data, which is the size in bits of one sample of audio data. |
| Word Length | 8 bits, 16, 24, 32 Default: 16 bits | Word length of audio data, must be at least the same size as the bit depth (Data Bits field). |
| WS Continue Mode | Enabled, Disabled Default: Disabled | Enable WS continue mode to continue to output the word select line when the peripheral is idle. Disable to stop outputting the word select line when the peripheral is idle. |
| Name of I2S callback function to be defined by user | NULL | A user callback function must be registered in open. The callback will be called from the interrupt service routine (ISR) when the transmission FIFO reaches the high watermark point after all data for transmission is transmitted or when reception is complete (the requested number of bytes have been received). Warning: Since the callback is called from an ISR, care should be taken not to use blocking calls or lengthy processing. Spending excessive time in an ISR can affect the responsiveness of the system. |
| Transmit Interrupt Priority | Priority 0 (highest), Priority 1:14, Priority 15 (lowest - not valid if using ThreadX) Default: Disabled | Transmit interrupt priority selection. |
| Receive Interrupt Priority | Priority 0 (highest), Priority 1:14, Priority 15 (lowest - not valid if using ThreadX) Default: Disabled | Receive interrupt priority selection. |
| Idle/Error Interrupt Priority | Priority 0 (highest), Priority 1:14, Priority 15 (lowest - not valid if using ThreadX) Default: Priority 12 | Idle/error interrupt priority selection. |
Configuration Settings for the Transfer Driver on r_dtc Software Activation 1
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Parameter selection. |
| Software Start | Enabled, Disabled Default: Disabled | Software start selection. |
| Linker section to keep DTC vector table | .ssp_dtc_vector_table | Linker section to keep DTC vector table. |
| Name | g_transfer0 | Driver name. |
| Mode | Normal | Mode selection. |
| Transfer Size | 4 Bytes | Transfer size selection. |
| Destination Address Mode | Fixed | Destination address mode selection. |
| Source Address Mode | Incremented | Source address mode selection. |
| Repeat Area (Unused in Normal Mode | Source | Repeat area selection. |
| Interrupt Frequency | After all transfers have completed | Interrupt frequency selection. |
| Destination Pointer | NULL | Destination pointer selection. |
| Source Pointer | NULL | Source pointer selection. |
| Number of Transfers | 0 | Number of transfers selection. |
| Number of Blocks (Valid only in Block Mode) | 0 | Number of blocks selection. |
| Activation Source (Must enable IRQ) | Software Activation 1, Software Activiation 2, Peripheral Events Default: Software Activation 1 | Activation source selection. |
| Auto Enable | False | Auto enable selection. |
| Callback (Only valid with Software start) | NULL | Callback selection. |
| ELC Software Event Interrupt Priority | Priority 0 (highest), Priority 1:14, Priority 15 (lowest - not valid if using ThreadX) Default: Disabled | ELC software event interrupt priority selection. |
Configuration Settings for the Transfer Driver on r_dtc Software Activation 1
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Parameter selection. |
| Software Start | Enabled, Disabled Default: Disabled | Software start selection. |
| Linker section to keep DTC vector table | .ssp_dtc_vector_table | Linker section to keep DTC vector table. |
| Name | g_transfer1 | Driver name. |
| Mode | Normal | Mode selection. |
| Transfer Size | 4 Bytes | Transfer size selection. |
| Destination Address Mode | Incremented | Destination address mode selection. |
| Source Address Mode | Fixed | Source address mode selection. |
| Repeat Area (Unused in Normal Mode | Destination | Repeat area selection. |
| Interrupt Frequency | After all transfers have completed | Interrupt frequency selection. |
| Destination Pointer | NULL | Destination pointer selection. |
| Source Pointer | NULL | Source pointer selection. |
| Number of Transfers | 0 | Number of transfers selection. |
| Number of Blocks (Valid only in Block Mode) | 0 | Number of blocks selection. |
| Activation Source (Must enable IRQ) | Software Activation 1, Software Activiation 2, Peripheral Events Default: Software Activation 1 | Activation source selection. |
| Auto Enable | False | Auto enable selection. |
| Callback (Only valid with Software start) | NULL | Callback selection. |
| ELC Software Event Interrupt Priority | Priority 0 (highest), Priority 1:14, Priority 15 (lowest - not valid if using ThreadX) Default: Disabled | ELC software event interrupt priority selection. |
Configuration Settings for the Timer Driver on r_agt
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Enables or disables parameter checking. |
| Name | g_timer0 | Module name. |
| Channel | 0 | Physical hardware channel. |
| Mode | Periodic | Warning: One-shot functionality is not available in the GPT hardware, so it is implemented in software by stopping the timer in the ISR called when the period expires. For this reason, ISRs must be enabled for one-shot mode even if the callback is unused. |
| Period Value | 10 | See Timer Period Calculation. |
| Period Unit | Hertz | See Timer Period Calculation. |
| Auto Start | False | Set to true to start the timer after configuring or false to leave the timer stopped until timer_api_t::start is called. |
| Count Source | PCLKB, PCLKB/8, PCLKB/2, LOCO, AGT0 Underflow, AGT0 fSub Default: PCLKB | The clock source for the AGT counter. |
| AGTO Output Enabled | True, False Default: False | Set to true to output the timer signal on a port pin configured for AGT (AGTO pin). Set to false for no output of the timer signal. |
| AGTIO Output Enabled | True, False Default: False | Set to true to output the timer signal on a port pin configured for AGT (AGTIO pin). Set to false for no output of the timer signal. |
| Output Inverted | True, False Default: False | Set to false to start the output signal low. Set to true to start the output signal high. |
| Enable comparator A output pin | True, False Default: False | Enable comparator A output pin selection. |
| Enable comparator B output pin | True, False Default: False | Enable comparator B output pin selection. |
| Callback | NULL | A user callback function can be registered in timer_api_t::open. If this callback function is provided, it will be called from the interrupt service routine (ISR) each time the timer period elapses. Warning: Since the callback is called from an ISR, care should be taken not to use blocking calls or lengthy processing. Spending excessive time in an ISR can affect the responsiveness of the system. |
| Interrupt Priority | Priority 0 (highest), Priority 1:14, Priority 15 (lowest - not valid if using ThreadX) Default: Disabled | Timer interrupt priority. 0 is the highest priority. |
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Enables or disables parameter checking. |
| Name | g_timer0 | Module name. |
| Channel | 0 | Physical hardware channel. |
Configuration Settings for the Timer Driver on r_gpt
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Parameter selection. |
| Name | g_timer0 | Module name. |
| Channel | 0 | Channel selection. |
| Mode | Periodic | Mode selection. |
| Period Value | 2822400 *2 | Period value selection. |
| Period Unit | Hertz | Period unit selection. |
| Duty Cycle Value | 50 | Duty cycle value selection. |
| Duty Cycle Unit | Unit Raw Counts, Unit Percent, Unit Percent x 1000 Default: Unit Raw Counts | Duty cycle unit selection. |
| Auto Start | FALSE | Auto start selection. |
| GTIOCA Output Enabled | True, False Default: False | GTIOCA output enabled selection. |
| GTIOCA Stop Level | Pin Level Low, Pin Level High, Pin Level Retained Default: Pin Level Low | GTIOCA stop level selection. |
| GTIOCB Output Enabled | True, False Default: False | GTIOCB output enabled selection. |
| GTIOCB Stop Level | Pin Level Low, Pin Level High, Pin Level Retained Default: Pin Level Low | GTIOCB stop level selection. |
| Callback | NULL | Callback selection. |
| Overflow Interrupt Priority | Priority 0 (highest), Priority 1:14, Priority 15 (lowest - not valid if using ThreadX) Default: Disabled | Interrupt priority selection. |
The Audio Playback I2S Framework hardware modules use the peripheral clocks available in the clock configuration window.
The SSI peripheral module uses pins on the MCU to communicate to external devices. I/O pins must be selected and configured as required by the external device. The following tables illustrate the method for selecting the pins within the SSP configuration window and shows an example selection for the associated pins.
Pin Selection Sequence for the Audio Playback I2S Framework Module
| Resource | ISDE Tab | Pin selection Sequence |
|---|---|---|
| I2S | Pins | Select Peripherals > Connectivity:SSI > SSI0/SSI1. |
Pin Configuration Settings for the I2S Driver on r_ssi
| Pin Configuration Property | Value | Description |
|---|---|---|
| Pin Group Selection | _A only, _B only, Mixed | Pin group for I2S port. |
| Operation Mode | Enabled, Custom, Disabled | Operation selection. |
| SSISCK | None, P204 Default: None | SSI Serial clock. |
| SSIWS | None, P205 Default: None | SSI Stereo pin selection. |
| SSIDATA | None, P206 Default: None | SSI Data pin selection. |
The typical steps in using the Audio Playback I2S Framework module in an application are:
1. Initialize the Audio Playback I2S Framework using the sf_audio_playback_hw_api_t::open API.
2. Start the low level hardware of the Audio Playback I2S framework using the sf_audio_playback_hw_api_t::start API.
3. Play the PCM audio samples using the sf_audio_playback_hw_api_t::play API.
4. PCM audio samples supported by the hardware is provided by the sf_audio_playback_hw_api_t::dataTypeGet API.
5. Stop the low level hardware of the Audio Playback I2S Framework using sf_audio_playback_hw_api_t::stop API.
6. Close the Audio Playback I2S framework using the sf_audio_playback_hw_api_t::close API.
These common steps are illustrated in a typical operational flow in the following figure: