ADuCM4x50 Device Drivers API Reference Manual  Release 4.0.0.0
SPORT Driver

Modules

 Static Configuration
 

Macros

#define ADI_SPORT_MEMORY_SIZE   (76u + ADI_SEM_SIZE)
 

Typedefs

typedef void * ADI_SPORT_HANDLE
 

Enumerations

enum  ADI_SPORT_CHANNEL {
  ADI_HALF_SPORT_A = 0,
  ADI_HALF_SPORT_B = 1
}
 
enum  ADI_SPORT_DIRECTION {
  ADI_SPORT_DIR_RX,
  ADI_SPORT_DIR_TX
}
 
enum  ADI_SPORT_PACKING_MODE {
  ADI_SPORT_NO_PACKING = 0,
  ADI_SPORT_8BIT_PACKING = ENUM_SPORT_CTL_A_CTL_PACK_8BIT,
  ADI_SPORT_16BIT_PACKING = ENUM_SPORT_CTL_A_CTL_PACK_16BIT
}
 
enum  ADI_SPORT_EVENT {
  ADI_SPORT_HW_NO_ERR = 0x00,
  ADI_SPORT_HW_ERR_RX_OVERFLOW = 0x02,
  ADI_SPORT_HW_ERR_TX_UNDERFLOW = 0x02,
  ADI_SPORT_HW_ERR_FS = 0x04,
  ADI_SPORT_HW_ERR_SYSDATAERR = 0x10,
  ADI_SPORT_EVENT_RX_BUFFER_PROCESSED = 0x20,
  ADI_SPORT_EVENT_TX_BUFFER_PROCESSED = 0x40,
  ADI_SPORT_DMA_ERR_BUS = 0x100,
  ADI_SPORT_DMA_ERR_INVALID_DESCRIPTOR = 0x200
}
 
enum  ADI_SPORT_RESULT {
  ADI_SPORT_SUCCESS,
  ADI_SPORT_FAILED,
  ADI_SPORT_INVALID_DEVICE_NUM,
  ADI_SPORT_INVALID_NULL_POINTER,
  ADI_SPORT_INVALID_HANDLE,
  ADI_SPORT_INVALID_PARAMETER,
  ADI_SPORT_DMA_REGISTER_FAILED,
  ADI_SPORT_DEVICE_IN_USE,
  ADI_SPORT_INVALID_CONFIGURATION,
  ADI_SPORT_BUFFERS_NOT_SUBMITTED,
  ADI_SPORT_INVALID_WORD_LENGTH,
  ADI_SPORT_OPERATION_NOT_ALLOWED,
  ADI_SPORT_HW_ERROR
}
 

Functions

ADI_SPORT_RESULT adi_sport_Open (const uint32_t nDevNum, const ADI_SPORT_CHANNEL eChannel, const ADI_SPORT_DIRECTION eDirection, void *pMemory, const uint32_t nMemSize, ADI_SPORT_HANDLE *const phDevice)
 Initialization function for SPORT device. More...
 
ADI_SPORT_RESULT adi_sport_Close (ADI_SPORT_HANDLE const hDevice)
 Closes the operation of specified SPORT device. More...
 
ADI_SPORT_RESULT adi_sport_SubmitBuffer (ADI_SPORT_HANDLE const hDevice, void *const pBuffer, uint32_t const nNumBytes, bool const bDMA)
 Submit the buffer for transmitting/receiving the data. This function can be used to submit the buffers for both transmitting and receiving. It will be returned after successfully submitting the buffer for transmitting data. User will be notified if a call back function is registered with an event code ADI_SPORT_EVENT_RX_BUFFER_PROCESSED or ADI_SPORT_EVENT_TX_BUFFER_PROCESSED" depending on the direction in which device is operating. More...
 
ADI_SPORT_RESULT adi_sport_GetBuffer (ADI_SPORT_HANDLE const hDevice, void **const ppBuffer, uint32_t *pHwError)
 This function returns the address of a processed buffer. This is a blocking function: it waits until a buffer has been dealt with. This function returns an error if a callback function is registered. adi_sport_IsBufferAvailable can be used as a peek function to know whether a buffer is available. More...
 
ADI_SPORT_RESULT adi_sport_IsBufferAvailable (ADI_SPORT_HANDLE const hDevice, bool *const pbAvailable)
 Peek function to know whether an empty/filled buffer is available. Call to this function is valid only if the call back function is not registered. Call to this function results in error if a call back function is registered. More...
 
ADI_SPORT_RESULT adi_sport_RegisterCallback (ADI_SPORT_HANDLE const hDevice, ADI_CALLBACK const pfCallback, void *const pCBparam)
 Register and unregister a Callback function with the SPORT device driver. A registered call back function will be called, if not NULL, when a buffer is processed OR hardware error(s) encountered. More...
 
ADI_SPORT_RESULT adi_sport_ConfigData (ADI_SPORT_HANDLE const hDevice, const uint8_t nWordLength, const ADI_SPORT_PACKING_MODE ePackMode, const bool bLSBFirst)
 Sets data format for the specified SPORT device. More...
 
ADI_SPORT_RESULT adi_sport_ConfigClock (ADI_SPORT_HANDLE const hDevice, const uint16_t nClockRatio, const bool bUseIntlClock, const bool bRisingEdge, const bool bGatedClk)
 Configure the clock for the specified SPORT device. More...
 
ADI_SPORT_RESULT adi_sport_ConfigFrameSync (ADI_SPORT_HANDLE const hDevice, const uint16_t nFsDivisor, const bool bFSRequired, const bool bInternalFS, const bool bDataFS, const bool bActiveLowFS, const bool bLateFS, const bool bFSErrorOperation)
 Frame Sync(FS) configuration for the specified SPORT. More...
 
ADI_SPORT_RESULT adi_sport_MultiplexSportSignal (ADI_SPORT_HANDLE const hDevice, const bool bUseOtherFS, const bool bUseOtherClk)
 Configure the SPORT use the Clocks and Frame Sync of other Half-Sport. More...
 
ADI_SPORT_RESULT adi_sport_ConfigTimerMode (ADI_SPORT_HANDLE const hDevice, const uint8_t nFSDuration, const uint8_t nWidth, const bool bActiveLow)
 Configure the SPORT use the Clocks and Frame Sync of other Half-Sport. More...
 
void SPORT0A_Int_Handler (void)
 
void SPORT0B_Int_Handler (void)
 
void DMA_SPORT0A_Int_Handler (void)
 
void DMA_SPORT0B_Int_Handler (void)
 

Detailed Description

Note
The application must include drivers/sport/adi_sport.h to use this driver
This documentation presented here is API documentation only. The device drive user's guide, located in the Documents folder, explains how to use these APIs in an application.

Macro Definition Documentation

◆ ADI_SPORT_MEMORY_SIZE

#define ADI_SPORT_MEMORY_SIZE   (76u + ADI_SEM_SIZE)

Amount of memory (bytes) required by the SPORT device driver for managing the operation in interrupt mode. This memory is completely owned by the driver till the end of the operation.

Definition at line 40 of file adi_sport.h.

Typedef Documentation

◆ ADI_SPORT_HANDLE

typedef void* ADI_SPORT_HANDLE

Handle to the SPORT Device

Definition at line 42 of file adi_sport.h.

Enumeration Type Documentation

◆ ADI_SPORT_CHANNEL

Enumeration of different channels of the SPORT

Enumerator
ADI_HALF_SPORT_A 

First half SPORT

ADI_HALF_SPORT_B 

Second half SPORT

Definition at line 47 of file adi_sport.h.

◆ ADI_SPORT_DIRECTION

Enumeration for the direction of operation.

Enumerator
ADI_SPORT_DIR_RX 

Sport in Rx mode

ADI_SPORT_DIR_TX 

Sport in Tx mode

Definition at line 56 of file adi_sport.h.

◆ ADI_SPORT_PACKING_MODE

Enumeration for enabling packing.

Enumerator
ADI_SPORT_NO_PACKING 

No Packing

ADI_SPORT_8BIT_PACKING 

8-bit packing

ADI_SPORT_16BIT_PACKING 

16-Bit packing

Definition at line 65 of file adi_sport.h.

◆ ADI_SPORT_EVENT

Enumeration for Hardware Error encountered by the SPORT device.

Enumerator
ADI_SPORT_HW_NO_ERR 

No Hardware error

ADI_SPORT_HW_ERR_RX_OVERFLOW 

Data overflow for Rx (same value as Tx underflow)

ADI_SPORT_HW_ERR_TX_UNDERFLOW 

Data underflow for Tx (same value as Rx overflow)

ADI_SPORT_HW_ERR_FS 

Frame sync error

ADI_SPORT_HW_ERR_SYSDATAERR 

System Data Error

ADI_SPORT_EVENT_RX_BUFFER_PROCESSED 

Processed the submitted RX buffer

ADI_SPORT_EVENT_TX_BUFFER_PROCESSED 

Processed the submitted TX buffer

ADI_SPORT_DMA_ERR_BUS 

SPORT DMA bus error detected

ADI_SPORT_DMA_ERR_INVALID_DESCRIPTOR 

SPORT DMA invalid descriptor error detected

Definition at line 75 of file adi_sport.h.

◆ ADI_SPORT_RESULT

Enumeration for result code returned from the SPORT device driver functions.

Enumerator
ADI_SPORT_SUCCESS 

Success

ADI_SPORT_FAILED 

Generic Failure to indicate a call to SPORT driver function returned unsuccessful

ADI_SPORT_INVALID_DEVICE_NUM 

Invalid device number

ADI_SPORT_INVALID_NULL_POINTER 

Specified pointer is invalid

ADI_SPORT_INVALID_HANDLE 

The given handle is invalid

ADI_SPORT_INVALID_PARAMETER 

Specified parameter is not valid

ADI_SPORT_DMA_REGISTER_FAILED 

Registering DMA error handler failed

ADI_SPORT_DEVICE_IN_USE 

The specified SPORT channel is already open and in use

ADI_SPORT_INVALID_CONFIGURATION 

The SPORT configuration is invalid

ADI_SPORT_BUFFERS_NOT_SUBMITTED 

Buffer submission failed

ADI_SPORT_INVALID_WORD_LENGTH 

Invalid word size

ADI_SPORT_OPERATION_NOT_ALLOWED 

Specified operation is not allowed when SPORT is transmitting/receiving data

ADI_SPORT_HW_ERROR 

SPORT hardware or DMA reports an error

Definition at line 94 of file adi_sport.h.

Function Documentation

◆ adi_sport_Open()

ADI_SPORT_RESULT adi_sport_Open ( const uint32_t  nDevNum,
const ADI_SPORT_CHANNEL  eChannel,
const ADI_SPORT_DIRECTION  eDirection,
void *  pMemory,
const uint32_t  nMemSize,
ADI_SPORT_HANDLE *const  phDevice 
)

Initialization function for SPORT device.

Initialization function for SPORT device. This function must be called before operating any SPORT device.

Parameters
[in]nDevNumSPORT Device instance to be opened.
[in]eChannelChannel ID of the SPORT device (A or B)
[in]eDirectionDirection of the SPORT operation (i.e Rx or Tx)
[in]pMemoryPointer to a 32 bit aligned buffer containing ADI_SPORT_MEMORY_SIZE bytes. This buffer is required by the SPORT driver for its operations. The "ADI_SPORT_MEMORY_SIZE" varies based on the configuration.
[in]nMemSizeSize of the buffer to which "pMemory" points.
[out]phDevicePointer to a location where a handle to the opened SPORT driver can be stored. This handle will be used to identity a SPORT device when calling SPORT management functions.
Returns
Status
See also
adi_sport_Close()

Definition at line 193 of file adi_sport.c.

◆ adi_sport_Close()

ADI_SPORT_RESULT adi_sport_Close ( ADI_SPORT_HANDLE const  hDevice)

Closes the operation of specified SPORT device.

Closes the operation of specified SPORT device. Device need to be opened again for any further use.

Parameters
[in]hDeviceSPORT device handle whose operation is to be closed. This handle was obtained when a SPORT device is opened successfully.
Returns
Status
 - #ADI_SPORT_SUCCESS            Successfully closed the specified device.
 - #ADI_SPORT_INVALID_HANDLE [D] Invalid SPORT device handle.
 - #ADI_SPORT_FAILED         [D] SPORT device internal error.
Note
It is user's responsibility to free/reuse the memory supplied during the opening of the device.
See also
adi_sport_Open()

Definition at line 293 of file adi_sport.c.

Referenced by adi_sport_Open().

◆ adi_sport_SubmitBuffer()

ADI_SPORT_RESULT adi_sport_SubmitBuffer ( ADI_SPORT_HANDLE const  hDevice,
void *const  pBuffer,
uint32_t const  nNumBytes,
bool const  bDMA 
)

Submit the buffer for transmitting/receiving the data. This function can be used to submit the buffers for both transmitting and receiving. It will be returned after successfully submitting the buffer for transmitting data. User will be notified if a call back function is registered with an event code ADI_SPORT_EVENT_RX_BUFFER_PROCESSED or ADI_SPORT_EVENT_TX_BUFFER_PROCESSED" depending on the direction in which device is operating.

Parameters
[in]hDeviceDevice handle to SPORT device is obtained when a SPORT device is opened successfully.
[in]pBufferPointer to buffer from where data need to be transmitted OR to which received data need to to be written.
[in]nNumBytesSize in bytes of the data to be transmitted/received.
[in]bDMATrue if the buffer must be processed through DMA-driven SPORT operations.
Returns
Status
See also
adi_sport_GetBuffer()

Definition at line 348 of file adi_sport.c.

◆ adi_sport_GetBuffer()

ADI_SPORT_RESULT adi_sport_GetBuffer ( ADI_SPORT_HANDLE const  hDevice,
void **const  ppBuffer,
uint32_t *  pHwError 
)

This function returns the address of a processed buffer. This is a blocking function: it waits until a buffer has been dealt with. This function returns an error if a callback function is registered. adi_sport_IsBufferAvailable can be used as a peek function to know whether a buffer is available.

Parameters
[in]hDeviceDevice handle to SPORT device, obtained when a SPORT device is openedsuccessfully.
[out]ppBufferPointer to a location where the the address of the buffer is to be written. Contains the address of an "empty" buffer (i.e the content of the buffer is transmitted) OR "filled" buffer which contains the received data.
[out]pHwErrorPointer to 32-bit value reporting SPORT/DMA events that can occur when processing buffer ppBuffer.
Returns
Status
See also
adi_sport_SubmitBuffer()
adi_sport_IsBufferAvailable()

Definition at line 717 of file adi_sport.c.

◆ adi_sport_IsBufferAvailable()

ADI_SPORT_RESULT adi_sport_IsBufferAvailable ( ADI_SPORT_HANDLE const  hDevice,
bool *const  pbAvailable 
)

Peek function to know whether an empty/filled buffer is available. Call to this function is valid only if the call back function is not registered. Call to this function results in error if a call back function is registered.

Parameters
[in]hDeviceDevice handle to SPORT device obtained when a SPORT device is opened successfully.
[out]pbAvailablePointer to a boolean variable. Contains "True" if there is an empty/filled buffer and a call to adi_sport_GetBuffer is ensured to be successful. Contains "false" if there is no empty buffer.
Returns
Status
See also
adi_sport_GetBuffer()
adi_sport_GetBuffer()

Definition at line 778 of file adi_sport.c.

◆ adi_sport_RegisterCallback()

ADI_SPORT_RESULT adi_sport_RegisterCallback ( ADI_SPORT_HANDLE const  hDevice,
ADI_CALLBACK const  pfCallback,
void *const  pCBparam 
)

Register and unregister a Callback function with the SPORT device driver. A registered call back function will be called, if not NULL, when a buffer is processed OR hardware error(s) encountered.

Parameters
[in]hDeviceDevice handle to SPORT device is obtained when a SPORT device is opened successfully.
[in]pfCallbackFunction pointer to Callback function. Passing a NULL pointer will unregister the call back function.
[in]pCBparamCall back function parameter.
Returns
Status

Definition at line 836 of file adi_sport.c.

◆ adi_sport_ConfigData()

ADI_SPORT_RESULT adi_sport_ConfigData ( ADI_SPORT_HANDLE const  hDevice,
const uint8_t  nWordLength,
const ADI_SPORT_PACKING_MODE  ePackMode,
const bool  bLSBFirst 
)

Sets data format for the specified SPORT device.

Sets data type,Big endian (MSB first) OR Little endian (LSB first) and word length(in bits) for the specified SPORT device.This function return error if the device is already enabled.

Parameters
[in]hDeviceDevice handle to SPORT device.
[in]nWordLengthSpecify the word size of the data. Valid range is from 4(nWordLength = 3) to 32(nWordLength =31).
[in]bLSBFirstConfigure the specified SPORT device to operate either LSB first or MSB first.

true : LSB first (Little endian) .

false : MSB first (Big endian)
[in]ePackModeMode of packging need to configured. Please refer ADI_SPORT_PACKING_MODE.
Returns
Status

Definition at line 899 of file adi_sport.c.

◆ adi_sport_ConfigClock()

ADI_SPORT_RESULT adi_sport_ConfigClock ( ADI_SPORT_HANDLE const  hDevice,
const uint16_t  nClockRatio,
const bool  bUseIntlClock,
const bool  bRisingEdge,
const bool  bGatedClk 
)

Configure the clock for the specified SPORT device.

Configure the SPORT device to use the "internal/external " rising/falling clock edge,clock edge and for enabling the gated Clock Mode.

fspclk = fsclk/(2*( nClockRatio + 1))

fspclk: frequency of SPORT clock

Parameters
[in]hDeviceDevice handle to SPORT device.
[in]nClockRatioThe value which determines the ratio between System clock and SPORT clock as explained above.
[in]bUseIntlClockBoolean flag to indicate whether to use internal clock or external clock for data transmission. By default, device is configured to use the external clock.

true : Device configured to use Internal clock.

false : Device configured to use external clock..
[in]bRisingEdgeBoolean flag to indicate whether to drive data and internal frame sync with rising edge OR falling edge of SP clock.

true : Use falling edge of the clock.

false : Use rising edge of the clock.
[in]bGatedClkBoolean flag to indicate whether to enable/disable gated clock for the specified SPORT channel.Ignored in Multi channel mode. Clock will be active only when active data is getting transmitted or received when this mode is enabled.
true : Enable gated clock mode.

false : Disable gated clock mode.
Returns
Status

Definition at line 1031 of file adi_sport.c.

◆ adi_sport_ConfigFrameSync()

ADI_SPORT_RESULT adi_sport_ConfigFrameSync ( ADI_SPORT_HANDLE const  hDevice,
const uint16_t  nFsDivisor,
const bool  bFSRequired,
const bool  bInternalFS,
const bool  bDataFS,
const bool  bActiveLowFS,
const bool  bLateFS,
const bool  bFSErrorOperation 
)

Frame Sync(FS) configuration for the specified SPORT.

Configure the SPORT to use internal/external frame sync,level/edge sensitive early/late frame sync etc.

Parameters
[in]hDeviceDevice handle to SPORT device.
[in]nFsDivisorThe value which decides the number of SPORT clock cycles between each frame count.
[in]bFSRequiredBoolean flag to indicate whether frame sync required OR not to the frame sync for the data transfer.

true : Device requires a frame sync for its operation.

false : Device does not requires a frame sync for its operation

[in]bInternalFSBoolean flag to indicate whether to configure the specified SPORT device to use the internal frame sync OR external frame sync as below.

true : Use internal frame sync.

false : Use external frame sync

[in]bDataFSBoolean flag to indicate whether to configure the specified SPORT device to use the data-independent frame sync OR Serial port uses a data-dependent frame sync. Valid only if the specified device is in "transmit"(TX)mode . Ignored if the device is opened in "receive"(RX) mode.

true : Use data-independent frame sync.

false : Use data-dependent frame sync.

[in]bActiveLowFSBoolean flag to indicate whether to configure the specified SPORT device for active low frame sync OR active high frame sync. Call to this function will return error if SPORT is configured in I2S mode.

true : Use active low frame sync.

false : Use active high frame sync.

[in]bLateFSBoolean flag to indicate whether to use the late frame sync OR Early frame sync.

true : Use late frame sync.

false : Use Early frame sync.

[in]bFSErrorOperationFrame Sync Error Operation. This
decides the way the SPORT responds when a frame sync error occurs.

true : When frame Sync error occurs, discard the receive data.

false : Flag the Frame Sync error and continue normal operation

Returns
Status

Definition at line 1162 of file adi_sport.c.

◆ adi_sport_MultiplexSportSignal()

ADI_SPORT_RESULT adi_sport_MultiplexSportSignal ( ADI_SPORT_HANDLE const  hDevice,
const bool  bUseOtherFS,
const bool  bUseOtherClk 
)

Configure the SPORT use the Clocks and Frame Sync of other Half-Sport.

Parameters
[in]hDeviceDevice handle to SPORT device.
[in]bUseOtherFSBoolean flag to indicate whether to use own Frame Sync(false) OR to use frame sync of other half SPORT (true).

true : Use frame sync of other half SPORT device.

false : Use own frame sync.
[in]bUseOtherClkBoolean flag to indicate whether to use own clock clock(false) OR to use clock of other half SPORT(true).

true : Use clock of other half SPORT device.

false : Use own clock.
Returns
Status

Definition at line 1258 of file adi_sport.c.

◆ adi_sport_ConfigTimerMode()

ADI_SPORT_RESULT adi_sport_ConfigTimerMode ( ADI_SPORT_HANDLE const  hDevice,
const uint8_t  nFSDuration,
const uint8_t  nWidth,
const bool  bActiveLow 
)

Configure the SPORT use the Clocks and Frame Sync of other Half-Sport.

Parameters
[in]hDeviceDevice handle to SPORT device.
[in]nFSDurationSpecify the value of the number of clocks which would be programmed corresponding to the desired time duration from assertion of CONVT signal to Frame sync signal
[in]nWidthSpecify the value of the number of serial clocks for which CONVT signal should be active.
[in]bActiveLowBoolean flag to indicate the polarity of the Convt signal.

true : Active low Polarity.

false : Active High Polarity.
Returns
Status

Definition at line 1322 of file adi_sport.c.

◆ SPORT0A_Int_Handler()

void SPORT0A_Int_Handler ( void  )

Interrupt handler for the SPORT0-A

◆ SPORT0B_Int_Handler()

void SPORT0B_Int_Handler ( void  )

Interrupt handler for the SPORT0-B

◆ DMA_SPORT0A_Int_Handler()

void DMA_SPORT0A_Int_Handler ( void  )

DMA handler for the SPORT0-A

◆ DMA_SPORT0B_Int_Handler()

void DMA_SPORT0B_Int_Handler ( void  )

DMA handler for the SPORT0-B