📄 mcbsp_edma_example.c
字号:
mcbsp_edma_setup ();
/* All done now, close the port. */
CSL_mcbspClose(hMcbsp);
/* Check data to make sure transfer was successful */
for (i = 0; i < DATATX_COUNT; i++) {
if (srcBuff[i] != dstBuff[i]) {
success = 0;
break;
}
}
for (i = 0; i < DATATX_COUNT; i++) {
if (success == 1)
printf("RxData = %d\t txData=%d\n", dstBuff[i],srcBuff[i]);
else {
printf("RxData = %d\t txData=%d\n", dstBuff[i],srcBuff[i]);
return;
}
}
printf("\n%s",success?"TRANSMISSION SUCCESS\n":"TRANSMISSION: EXAMPLE FAILED\n");
return;
}
/**
* ============================================================================
* @n@b mcbsp_edma_setup
*
* @desc
* This function performs follwing steps:
* -# Set up interrupts corresponding to EDMA and MCBSP
* -# Set up EDMA for synchronising with MCBSP
* -# Enable MCBSP to Trax Data.
* -# Wait for the interrupt and once the transfer is done close the EDMA
* ============================================================================
*/
void mcbsp_edma_setup (
void
)
{
CSL_Edma3ParamHandle hParamBasic;
CSL_Edma3ParamHandle hParamBasic1;
CSL_Edma3ParamSetup myParamSetup;
CSL_Edma3ParamSetup myParamSetup1;
CSL_Edma3ChannelObj ChObj,ChObj1;
CSL_Edma3ChannelAttr chParam;
CSL_Edma3Context edmaContext;
CSL_Edma3Obj edmaObj;
CSL_Edma3QueryInfo info;
CSL_Edma3CmdIntr regionIntr;
CSL_Edma3CmdDrae regionAccess;
Uint32 i, j;
CSL_BitMask16 ctrlMask;
for (i = 0, j = 1; i < DATATX_COUNT;i++,j++) {
srcBuff[i] = j;
dstBuff[i] = 0;
}
/* Intc Module Initialization */
intcContext.eventhandlerRecord = EventHandler;
intcContext.numEvtEntries = 10;
CSL_intcInit(&intcContext);
/* Enable NMIs */
CSL_intcGlobalNmiEnable();
/* Enable Global Interrupts */
intStat = CSL_intcGlobalEnable(&state);
/* Opening a handle for the Event edma */
vectId = CSL_INTC_VECTID_4;
hIntcEdma = CSL_intcOpen (&intcObjEdma, CSL_INTC_EVENTID_EDMA3CC_INT0,
&vectId , NULL);
/* Edma Module Initialization */
CSL_edma3Init(&edmaContext);
/* Edma Module Level Open */
hModule = CSL_edma3Open(&edmaObj,CSL_EDMA3,NULL,&status);
/* Query Module Info */
CSL_edma3GetHwStatus(hModule,CSL_EDMA3_QUERY_INFO, &info);
/********************************Setup for Tx******************************/
/* Setup the DRAE Masks */
regionAccess.region = CSL_EDMA3_REGION_0;
regionAccess.drae = 0xFFFF;
regionAccess.draeh = 0;
CSL_edma3HwControl(hModule,CSL_EDMA3_CMD_DMAREGION_ENABLE,®ionAccess);
/* Open transmit channel */
chParam.regionNum = CSL_EDMA3_REGION_0;
chParam.chaNum = CSL_EDMA3_CHA_XEVT0;
hChannel = CSL_edma3ChannelOpen(&ChObj,
CSL_EDMA3,
&chParam,
&status);
/* Channel setup */
hParamBasic = CSL_edma3GetParamHandle(hChannel,CSL_EDMA3_CHA_XEVT0, &status);
/* param setup */
myParamSetup.option = CSL_EDMA3_OPT_MAKE(CSL_EDMA3_ITCCH_DIS, \
CSL_EDMA3_TCCH_DIS, \
CSL_EDMA3_ITCINT_DIS, \
CSL_EDMA3_TCINT_EN,\
CSL_EDMA3_CHA_XEVT0, \
CSL_EDMA3_TCC_NORMAL, \
CSL_EDMA3_FIFOWIDTH_32BIT, \
CSL_EDMA3_STATIC_DIS, \
CSL_EDMA3_SYNC_A,\
CSL_EDMA3_ADDRMODE_INCR,\
CSL_EDMA3_ADDRMODE_INCR \
);
myParamSetup.srcAddr = (Uint32)srcBuff;
myParamSetup.dstAddr = (Uint32)CSL_MCBSP_0_TX_EDMA_REGS;
myParamSetup.aCntbCnt = CSL_EDMA3_CNT_MAKE(4,16);
myParamSetup.srcDstBidx = CSL_EDMA3_BIDX_MAKE(4,0);
myParamSetup.linkBcntrld = CSL_EDMA3_LINKBCNTRLD_MAKE(CSL_EDMA3_LINK_NULL,1);
myParamSetup.srcDstCidx = CSL_EDMA3_CIDX_MAKE(0,0);
myParamSetup.cCnt = 1;
CSL_edma3HwChannelSetupParam (hChannel, CSL_EDMA3_CHA_XEVT0);
CSL_edma3HwChannelSetupQue(hChannel, CSL_EDMA3_QUE_1);
CSL_edma3ParamSetup(hParamBasic,&myParamSetup);
CSL_edma3HwChannelControl(hChannel, CSL_EDMA3_CMD_CHANNEL_ENABLE, NULL);
/********************************Setup for Rx******************************/
/* Open Receive channel */
chParam.regionNum = CSL_EDMA3_REGION_0;
chParam.chaNum = CSL_EDMA3_CHA_REVT0;
hChannel1 = CSL_edma3ChannelOpen(&ChObj1,
CSL_EDMA3,
&chParam,
&status);
/* Channel Setup */
hParamBasic1 = CSL_edma3GetParamHandle(hChannel1,CSL_EDMA3_CHA_REVT0,&status);
/* Param Setup */
myParamSetup1.option = CSL_EDMA3_OPT_MAKE(FALSE,FALSE,FALSE,TRUE,\
CSL_EDMA3_CHA_REVT0, \
CSL_EDMA3_TCC_NORMAL,\
CSL_EDMA3_FIFOWIDTH_32BIT, \
CSL_EDMA3_STATIC_DIS, \
CSL_EDMA3_SYNC_A, \
CSL_EDMA3_ADDRMODE_INCR, \
CSL_EDMA3_ADDRMODE_INCR \
);
myParamSetup1.srcAddr = (Uint32)CSL_MCBSP_0_RX_EDMA_REGS;
myParamSetup1.dstAddr = (Uint32)dstBuff;
myParamSetup1.aCntbCnt = CSL_EDMA3_CNT_MAKE(4,16);
myParamSetup1.srcDstBidx = CSL_EDMA3_BIDX_MAKE(0,4);
myParamSetup1.linkBcntrld = CSL_EDMA3_LINKBCNTRLD_MAKE(
CSL_EDMA3_LINK_NULL,1);
myParamSetup1.srcDstCidx = CSL_EDMA3_CIDX_MAKE(0,0);
myParamSetup1.cCnt = 1;
CSL_edma3HwChannelSetupParam (hChannel1, CSL_EDMA3_CHA_REVT0);
CSL_edma3HwChannelSetupQue(hChannel1, CSL_EDMA3_QUE_1);
CSL_edma3ParamSetup(hParamBasic1, &myParamSetup1);
EventRecord.handler = &eventEdmaHandler;
EventRecord.arg = (void*)(hModule);
CSL_intcPlugEventHandler(hIntcEdma,&EventRecord);
/* Enabling event edma */
CSL_intcHwControl(hIntcEdma,CSL_INTC_CMD_EVTENABLE,NULL);
/* Hook up the EDMA Event with an ISR */
EdmaEventHook(CSL_EDMA3_CHA_XEVT0, txmyIsr);
EdmaEventHook(CSL_EDMA3_CHA_REVT0, rxmyIsr);
/* Enable the interrupts */
regionIntr.region = CSL_EDMA3_REGION_0;
regionIntr.intr = 0x3000;
regionIntr.intrh = 0;
CSL_edma3HwControl(hModule,CSL_EDMA3_CMD_INTR_ENABLE,®ionIntr);
/* Enable the receive channel */
CSL_edma3HwChannelControl(hChannel1, CSL_EDMA3_CMD_CHANNEL_ENABLE, NULL);
/* Enable MCBSP transmit and receive */
ctrlMask = CSL_MCBSP_CTRL_TX_ENABLE | CSL_MCBSP_CTRL_RX_ENABLE;
CSL_mcbspHwControl(hMcbsp, CSL_MCBSP_CMD_RESET_CONTROL, &ctrlMask);
WAIT_FOR_1_CLK;
/* wait for Transmit complete Interrupt */
while (!intFlag);
/* wait for Transmit complete Interrupt */
while (!rxintFlag);
/* Disable cahnnels and clear the EDMA event registers */
CSL_edma3HwChannelControl (hChannel, CSL_EDMA3_CMD_CHANNEL_DISABLE, NULL);
CSL_edma3HwChannelControl (hChannel1, CSL_EDMA3_CMD_CHANNEL_DISABLE, NULL);
CSL_edma3HwChannelControl (hChannel, CSL_EDMA3_CMD_CHANNEL_CLEAR, NULL);
CSL_edma3HwChannelControl (hChannel1, CSL_EDMA3_CMD_CHANNEL_CLEAR, NULL);
/* clear the error registers */
chErrClear.missed = TRUE;
chErrClear.secEvt = TRUE;
CSL_edma3HwChannelControl (hChannel, CSL_EDMA3_CMD_CHANNEL_CLEARERR, &chErrClear);
CSL_edma3HwChannelControl (hChannel1, CSL_EDMA3_CMD_CHANNEL_CLEARERR, &chErrClear);
CSL_edma3ChannelClose(hChannel);
CSL_edma3ChannelClose(hChannel1);
CSL_edma3Close(hModule);
CSL_intcClose (hIntcEdma);
}
/*
* ============================================================================
* @func txmyIsr
*
* @desc
* This function is the interrupt service routine for transmit data
*
* @arg
* None
*
* @return
* None
* ============================================================================
*/
void txmyIsr()
{
intFlag = 1;
}
/*
* ============================================================================
* @func rxmyIsr
*
* @desc
* This function is the interrupt service routine for receive data
*
* @arg
* None
*
* @return
* None
* ============================================================================
*/
void rxmyIsr()
{
rxintFlag = 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -