AM273x MCU+ SDK  08.06.00
MCASP

The Multi Channel Audio Seiral Peripheral (MCASP) driver is a generic, full-duplex driver that transmits and receives data using the MCASP interface. This is specially designed to transmit and receive the digital audio data.

Features Supported

  • Interrupt mode operation
  • DMA mode operation
  • Internal Loopback
  • Transmit and Receive in TDM format with multi-serializer, multi-slot support.
  • Different audio buffer formats for application
  • SysConfig support for driver parameter configuration and initialization.

SysConfig Features

Note
It is strongly recommend to use SysConfig where it is available instead of using direct SW API calls. This will help simplify the SW application and also catch common mistakes early in the development cycle.
  • Note: Currently, some register configurations are supported through SysConfig, while for others, user needs to use hardcoded McASP register configurations defined in the structure "gMcaspAttrs" located in: <mcasp_loopback\am273x-evm\c66ss0_nortos\ti-c6000\generated\ti_drivers_config.c> manually by referring the register descriptions in the device TRM.

Features NOT Supported

  • Transmit in DIT mode
  • Burst Mode

Usage Overview

API Sequence

To use the MCASP driver to send data over the MCASP interface, the application calls the following APIs:

Supported Application Audio Buffer Formats

The McASP driver provides various buffer formats for sending the data to/from the audio device. The differences between these formats arise from the way the audio samples are collected from various serializers and their timeslots and arranged in the system’s memory. This way the application can choose to run audio processing algorithms over the data without the need for re-arranging those data every frame. This section provides an overview of the various formats . In the explanatory diagrams in each section, McASP controller recieves samples in frame intervals denoted by t1,t2..tn. The McASP driver collects these and arranges those samples in the memory in various formats in to the host’s System memory. We have chosen 32 bit samples and 32-bit word addresses throughout for simplicity.

  • 1-Serializer Multi-Slot Interleaved: This is applicable if multiple slots are used with one serializer. The samples from the different timeslots are stored interleaved in the memory as below. Different timeslots’ samples are denoted by different colors and are labelled t1,t2..tn according to the time they arrive at the serializer.

  • 1-Serializer Multi-Slot NonInterleaved: This is applicable if multiple slots are used with one serializer. The samples from the different timeslots are grouped together on the basis of the timeslot and stored in the memory as shown below. Different timeslots’ samples are denoted by different colors and are labelled t1,t2..tn according to the time they arrive at the serializer.

  • Multi-Serializer Multi-Slot Interleaved Type1: This is applicable if multiple serializers are used and each serializer containing multiple timeslots. The samples are stored in the memory interleaved based on serializer and timeslots as shown below. In this example, there are 3 serializers and 2 timeslots per serializers whose samples are noted by Ln (left) and Rn (right). Different serializers’ samples are denoted by different colors.

  • Multi-Serializer Multi-Slot Interleaved Type2: This is applicable if multiple serializers are used and each serializer containing multiple timeslots. The samples are grouped based on the serializer and within one serializer, the timeslots are interleaved as shown below. In this example, there are 3 serializers and 2 timeslots per serializers whose samples are noted by Ln (left) and Rn (right).Different serializers’ samples are denoted by different colors.

Loopjob Configuration

Mcasp driver allows loopjob enabled/disabled configuration to handle delayed application buffer submission at run time. Loopjob is a default buffer that gets transmitted / received into if the application fails to submit the buffers in time. When loopjob is disabled the last 2 application buffers will be re programmed and re used. The application callback corresponding to the re programmed buffers is not called.

  • Loopjob buffer is programmed in sys config. Sys config will define a uint8_t array and initialize it to 0.
  • Application can access the buffer and optionally initialize the data.
  • If the loopjob buffer is programmed, after sending the full loopjob buffer next submitted buffer is programmed.

Buffer Queuing

  • The application buffers need to be programmed before starting the transfer.
  • If the loopjob is enabled application can start without queuing any buffers, Driver will work with the loopjob buffers till application queues the actual buffers.
  • If loopjob is disabled at least 2 buffers should be queued before starting the mcasp transfer. New buffer will be programmed in the interrupt callback corresponding to current transfer. the application is expected to submit the new buffer before that else the same buffer is re programmed, so it is recommended to start the transfer with at least 3 buffers queued.

Example Usage

Include the below file to access the APIs

#include <drivers/mcasp.h>

Instance Open Example

MCASP_OpenParams mcaspParams;
MCASP_openParamsInit(&mcaspParams); /* Initialize mcasp parameters */
mcaspParams.edmaInst = 0;
mcaspParams.edmaInst = CONFIG_EDMA0,
mcaspParams.txCallbackFxn = mcasp_loopback_txcb,
mcaspParams.rxCallbackFxn = mcasp_loopback_rxcb,
gMcaspHandle = MCASP_open(CONFIG_MCASP0, &mcaspParams);
DebugP_assert(gMcaspHandle != NULL);

Instance Close Example

MCASP_close(gMcaspHandle);

Start McASP Transfer Example

MCASP_Transaction txnTx[APP_MCASP_MSG_COUNT] = {0};
MCASP_Transaction txnRx[APP_MCASP_MSG_COUNT] = {0};
uint8_t mcaspTxBuffer[APP_MCASP_MSG_COUNT][APP_MCASP_MSGSIZE];
uint8_t mcaspRxBuffer[APP_MCASP_MSG_COUNT][APP_MCASP_MSGSIZE];
uint32_t i;
for (i = 0U; i < APP_MCASP_MSG_COUNT; i++)
{
txnTx[i].buf = (void*) &mcaspTxBuffer[i][0];
txnTx[i].count = APP_MCASP_MSGSIZE/4;
txnTx[i].timeout = 0xFFFFFF;
MCASP_submitTx(gMcaspHandle, &txnTx[i]);
}
for (i = 0U; i < APP_MCASP_MSG_COUNT; i++)
{
txnRx[i].buf = (void*) &mcaspRxBuffer[i][0];
txnRx[i].count = APP_MCASP_MSGSIZE/4;
txnRx[i].timeout = 0xFFFFFF;
MCASP_submitRx(gMcaspHandle, &txnRx[i]);
}
MCASP_startTransferRx(gMcaspHandle);
MCASP_startTransferTx(gMcaspHandle);

Stop McASP Transfer Example

MCASP_stopTransferTx(gMcaspHandle);
MCASP_stopTransferRx(gMcaspHandle);
/* withdraw the buffers submitted to driver. */
{
MCASP_Transaction *transaction;
do {
transaction = MCASP_withdrawRx(gMcaspHandle);
}while (transaction != NULL);
do {
transaction = MCASP_withdrawTx(gMcaspHandle);
}while (transaction != NULL);
}

API

APIs for MCASP

MCASP_withdrawRx
MCASP_Transaction * MCASP_withdrawRx(MCASP_Handle handle)
Function to withdraw the buffer submitted to McASP driver for reception. This should be called after ...
MCASP_close
void MCASP_close(MCASP_Handle handle)
Function to close a MCASP peripheral specified by the MCASP handle.
MCASP_submitRx
int32_t MCASP_submitRx(MCASP_Handle handle, MCASP_Transaction *txn)
Function to submit the buffer to McASP driver for reception. Transaction object is held by the driver...
MCASP_withdrawTx
MCASP_Transaction * MCASP_withdrawTx(MCASP_Handle handle)
Function to withdraw the buffer submitted to McASP driver for transmission. This should be called aft...
MCASP_OpenParams::rxCallbackFxn
MCASP_RxCallbackFxn rxCallbackFxn
Definition: mcasp/v0/mcasp.h:465
MCASP_open
MCASP_Handle MCASP_open(uint32_t index, const MCASP_OpenParams *openParams)
This function opens a given MCASP peripheral.
MCASP_OpenParams::edmaInst
int32_t edmaInst
Definition: mcasp/v0/mcasp.h:443
MCASP_Transaction
Data structure used with transfer call.
Definition: mcasp/v0/mcasp.h:316
MCASP_OpenParams
MCASP Parameters.
Definition: mcasp/v0/mcasp.h:442
MCASP_stopTransferRx
int32_t MCASP_stopTransferRx(MCASP_Handle handle)
Function to stop McASP reception.
MCASP_OpenParams::transferMode
uint32_t transferMode
Definition: mcasp/v0/mcasp.h:445
MCASP_Transaction::count
uint32_t count
Definition: mcasp/v0/mcasp.h:323
MCASP_startTransferTx
int32_t MCASP_startTransferTx(MCASP_Handle handle)
Function to start McASP transmission.
MCASP_OpenParams::txCallbackFxn
MCASP_TxCallbackFxn txCallbackFxn
Definition: mcasp/v0/mcasp.h:463
mcasp.h
MCASP_openParamsInit
static void MCASP_openParamsInit(MCASP_OpenParams *openPrms)
Function to initialize the MCASP_OpenParams struct to its defaults.
Definition: mcasp/v0/mcasp.h:805
MCASP_startTransferRx
int32_t MCASP_startTransferRx(MCASP_Handle handle)
Function to start McASP reception.
MCASP_Transaction::timeout
uint32_t timeout
Definition: mcasp/v0/mcasp.h:327
DebugP_assert
#define DebugP_assert(expression)
Function to call for assert check.
Definition: DebugP.h:177
MCASP_Transaction::buf
void * buf
Definition: mcasp/v0/mcasp.h:320
MCASP_submitTx
int32_t MCASP_submitTx(MCASP_Handle handle, MCASP_Transaction *txn)
Function to submit the buffer to McASP driver for transmission. Transaction object is held by the dri...
MCASP_TRANSFER_MODE_DMA
#define MCASP_TRANSFER_MODE_DMA
MCASP read/write APIs does not block code execution and will use DMA for transfers.
Definition: mcasp/v0/mcasp.h:140
MCASP_stopTransferTx
int32_t MCASP_stopTransferTx(MCASP_Handle handle)
Function to stop McASP transmission.