59 #include <drivers/general/adi_drivers_general.h> 60 #include <adi_sport_config.h> 61 #include <drivers/sport/adi_sport.h> 62 #include <adi_cyclecount.h> 63 #include "adi_sport_def.h" 89 #pragma diag_suppress=Pm026,Pm050,Pm073,Pm088,Pm123,Pm140,Pm143,Pm152,Pm153 94 #define SPORT0_A_REGS ((volatile ADI_SPORT_TypeDef*)REG_SPORT0_CTL_A) 95 #define SPORT0_B_REGS ((volatile ADI_SPORT_TypeDef*)REG_SPORT0_CTL_B) 97 #define SPORT0_A_CFG { 0u, 0u, 0u, 0u, 0u } 98 #define SPORT0_B_CFG { 0u, 0u, 0u, 0u, 0u } 100 #define DXS_FIFO_IS_FULL(STAT) (((STAT) & BITM_SPORT_STAT_A_DXS) == BITM_SPORT_STAT_A_DXS) 101 #define DXS_FIFO_IS_EMPTY(STAT) (((STAT) & BITM_SPORT_STAT_A_DXS) == 0u) 103 static ADI_SPORT_DEVICE_INFO gSportDevInfo [ADI_SPORT_NUM_INSTANCES][ADI_SPORT_NUM_CHANNELS] =
106 {SPORT0_A_REGS, SPORT0_A_CFG, ADI_SPORT_STATE_UNINITIALIZED, SPORT0A_CHANn, DMA0_CH2_DONE_IRQn, SPORT_A_EVT_IRQn, NULL},
107 {SPORT0_B_REGS, SPORT0_B_CFG, ADI_SPORT_STATE_UNINITIALIZED, SPORT0B_CHANn, DMA0_CH3_DONE_IRQn, SPORT_B_EVT_IRQn, NULL},
112 static const ADI_SPORT_CONFIG gSportCfg[ADI_SPORT_NUM_INSTANCES][ADI_SPORT_NUM_CHANNELS] =
225 const uint32_t nDevNum,
229 const uint32_t nMemSize,
237 if (nDevNum >= ADI_SPORT_NUM_INSTANCES)
241 else if (phDevice == NULL)
249 else if (ADI_SPORT_STATE_UNINITIALIZED != gSportDevInfo[nDevNum][eChannel].eState)
256 ADI_SPORT_DEVICE * pDevice = pMemory;
257 ADI_SPORT_DEVICE_INFO * sportInfo = &gSportDevInfo[nDevNum][eChannel];
258 ADI_SPORT_CONFIG
const * sportCfg = &gSportCfg[nDevNum][eChannel];
260 assert(eChannel < ADI_SPORT_NUM_CHANNELS);
262 memset(pMemory, 0, nMemSize);
264 pDevice->pSportInfo = sportInfo;
265 pDevice->eDirection = eDirection;
270 sport_Configure(pDevice,sportCfg);
280 ADI_SPORT_DEVICE_INFO * devInfo = &gSportDevInfo[nDevNum][eChannel];
291 ADI_INT_STATUS_ALLOC();
292 ADI_ENTER_CRITICAL_REGION();
293 devInfo->eState = ADI_SPORT_STATE_INITIALIZED;
294 devInfo->hDevice = pDevice;
295 ADI_EXIT_CRITICAL_REGION();
327 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE *) hDevice;
332 ADI_SPORT_DEVICE_INFO * pSportInfo = pDevice->pSportInfo;
335 ADI_INT_STATUS_ALLOC();
336 ADI_ENTER_CRITICAL_REGION();
337 NVIC_DisableIRQ(pSportInfo->eIRQn);
338 NVIC_DisableIRQ(pSportInfo->eDMAn);
339 pSportInfo->eState = ADI_SPORT_STATE_UNINITIALIZED;
340 pSportInfo->hDevice = NULL;
341 ADI_EXIT_CRITICAL_REGION();
347 pSportInfo->pSportRegs->CTL_A = 0u;
380 void *
const pBuffer,
381 uint32_t
const nNumBytes,
385 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE *) hDevice;
389 ADI_SPORT_CONFIG * pSportCfg = &pDevice->pSportInfo->sportCfg;
394 else if ( ((2u >= nNumBytes) && ((pDevice->pSportInfo->pSportRegs->CTL_A & BITM_SPORT_CTL_A_OPMODE) != 0u))
395 || (0u != (nNumBytes & ~(BITM_SPORT_NUMTRAN_A_VALUE)))
407 if (NULL != pDevice->sportChannel.pFreeBuffer->pStartAddress)
414 const uint32_t addr = (uint32_t) pBuffer;
427 const uint32_t dataSizeInBytes = GetBytesPerSportData(pSportCfg->CTL);
428 const uint32_t full = nNumBytes / dataSizeInBytes;
429 const uint32_t partial = nNumBytes % dataSizeInBytes;
430 const uint32_t misaligned = addr % dataSizeInBytes;
432 if ( (full > DMA_TRANSFER_LIMIT)
434 || (0u != misaligned)
440 const uint32_t misAligned = addr % 4u;
441 const uint32_t invalidNum = nNumBytes % 4u;
443 if ( (0u != misAligned)
444 || (0u != invalidNum)
453 ADI_DT_CHANNEL * pSportChnl = &pDevice->sportChannel;
455 pSportChnl->pFreeBuffer->pStartAddress = pBuffer;
456 pSportChnl->pFreeBuffer->nCount = nNumBytes;
457 pSportChnl->pFreeBuffer->nIndex = 0u;
458 pSportChnl->pFreeBuffer->bDMA = bDMA;
459 pSportChnl->pFreeBuffer->bInUse =
true;
465 pSportChnl->pFreeBuffer = pSportChnl->pFreeBuffer->pNextBuffer;
473 if (pSportChnl->eDataTranferMode == ADI_DT_MODE_NONE)
475 pSportChnl->eDataTranferMode = ADI_DT_MODE_NONBLOCKING;
480 result = sport_SubmitBufferDmaMode(pDevice, pSportChnl->pFillBuffer);
482 result = sport_SubmitBufferIntMode(pDevice, pSportChnl->pFillBuffer);
488 pSportChnl->eDataTranferMode = ADI_DT_MODE_NONE;
509 static ADI_SPORT_RESULT sport_SubmitBufferDmaMode(ADI_SPORT_DEVICE * pDevice,
510 ADI_DT_BUFF_INFO * pBuff)
513 ADI_SPORT_DEVICE_INFO * pSportInfo = pDevice->pSportInfo;
514 ADI_SPORT_CONFIG * pSportCfg = &pSportInfo->sportCfg;
517 if ( (pBuff != pDevice->sportChannel.pFillBuffer)
518 || (
true != pBuff->bInUse)
519 || (0u != pBuff->nIndex)
527 volatile ADI_SPORT_TypeDef* pSportRegs = pSportInfo->pSportRegs;
528 const uint32_t dmaChnlId = (uint32_t) pSportInfo->eDMAChnlID;
529 const uint32_t dmaChnlBit = (1u << dmaChnlId);
542 const uint32_t dmaDcc = (uint32_t) DMA_ENUM_CTL_CYCLE_CTL_BASIC;
543 const uint32_t bytesPerData = GetBytesPerSportData(pSportCfg->CTL);
545 const uint32_t dataSizeInBytes = (1u << pSportCfg->DMA_WIDTH);
546 uint32_t numDmaData = pBuff->nCount / dataSizeInBytes;
547 const uint32_t dmaDataEnd = (pBuff->nCount - dataSizeInBytes);
548 const uint32_t startAddress = (uint32_t) pBuff->pStartAddress;
549 const uint32_t numSportData = pBuff->nCount / bytesPerData;
551 assert(pBuff->nCount == (numSportData * bytesPerData));
552 assert(numSportData <= 0xFFFu);
553 assert(0u == (pBuff->nCount % dataSizeInBytes));
554 assert(numDmaData <= DMA_TRANSFER_LIMIT);
556 SPORT_CHECK_CFG_CTL(pSportCfg->CTL);
558 pSportRegs->CTL_A = 0u;
559 pADI_DMA0->SRCADDR_CLR = dmaChnlBit;
560 pADI_DMA0->EN_SET = dmaChnlBit;
561 pADI_DMA0->RMSK_CLR = dmaChnlBit;
562 pADI_DMA0->ALT_CLR = dmaChnlBit;
563 pADI_DMA0->PRI_SET = dmaChnlBit;
567 pPrimaryCCD[dmaChnlId].DMASRCEND = (uint32_t) &pSportRegs->RX_A;
568 pPrimaryCCD[dmaChnlId].DMADSTEND = startAddress + dmaDataEnd;
569 pPrimaryCCD[dmaChnlId].DMACDC =
570 (pSportCfg->DMA_INC << ((uint32_t)DMA_BITP_CTL_DST_INC)) |
571 (dmaIncNone << ((uint32_t)DMA_BITP_CTL_SRC_INC));
575 pPrimaryCCD[dmaChnlId].DMASRCEND = startAddress + dmaDataEnd;
576 pPrimaryCCD[dmaChnlId].DMADSTEND = (uint32_t) &pSportRegs->TX_A;
577 pPrimaryCCD[dmaChnlId].DMACDC =
578 (dmaIncNone << ((uint32_t)DMA_BITP_CTL_DST_INC)) |
579 (pSportCfg->DMA_INC << ((uint32_t)DMA_BITP_CTL_SRC_INC));
584 if (numDmaData < numSportData)
586 pPrimaryCCD[dmaChnlId].DMASRCEND = startAddress + dmaDataEnd + dataSizeInBytes;
590 pPrimaryCCD[dmaChnlId].DMACDC |=
591 (pSportCfg->DMA_WIDTH << ((uint32_t)DMA_BITP_CTL_SRC_SIZE)) |
592 (0u << ((uint32_t) DMA_BITP_CTL_R_POWER)) |
593 ((numDmaData - 1u) << ((uint32_t)DMA_BITP_CTL_N_MINUS_1)) |
594 (dmaDcc << ((uint32_t)DMA_BITP_CTL_CYCLE_CTL));
596 ADI_INT_STATUS_ALLOC();
597 ADI_ENTER_CRITICAL_REGION();
598 pDevice->pSportInfo->eState = ADI_SPORT_STATE_DATA_FLOW_ENABLED;
599 pSportRegs->NUMTRAN_A = numSportData;
602 NVIC_ClearPendingIRQ(pSportInfo->eIRQn);
603 NVIC_ClearPendingIRQ(pSportInfo->eDMAn);
605 uint32_t ien_a = ((uint32_t)BITM_SPORT_IEN_A_SYSDATERR) |
606 ((uint32_t)BITM_SPORT_IEN_A_FSERRMSK) |
607 ((uint32_t)BITM_SPORT_IEN_A_DERRMSK);
611 NVIC_EnableIRQ(pSportInfo->eDMAn);
616 ien_a |= ((uint32_t)BITM_SPORT_IEN_A_TF);
619 NVIC_EnableIRQ(pSportInfo->eIRQn);
621 pSportRegs->IEN_A = ien_a;
622 pSportRegs->CTL_A = pSportCfg->CTL |
623 ((uint32_t)BITM_SPORT_CTL_A_SPEN) |
624 ((uint32_t)BITM_SPORT_CTL_A_DMAEN);
625 ADI_EXIT_CRITICAL_REGION();
627 SPORT_CHECK_CFG_CTL(pSportCfg->CTL);
651 static ADI_SPORT_RESULT sport_SubmitBufferIntMode(ADI_SPORT_DEVICE * pDevice, ADI_DT_BUFF_INFO * pBuff)
655 if ( (pBuff != pDevice->sportChannel.pFillBuffer)
656 || (
true != pBuff->bInUse)
657 || (0u != pBuff->nIndex)
665 ADI_SPORT_CONFIG * pSportCfg = &pDevice->pSportInfo->sportCfg;
666 volatile ADI_SPORT_TypeDef * pSportRegs = pDevice->pSportInfo->pSportRegs;
667 uint32_t ctl = pSportCfg->CTL;
668 uint32_t bytesPerData = GetBytesPerSportData(ctl);
681 pBuff->nCount /= bytesPerData;
684 uint32_t pack = SPORT_GET_PACKEN(pSportCfg->CTL);
685 assert( ((9u > bytesPerData) && (1u == pack)) || ((17u > bytesPerData) && (2u == pack)) || (0u == pack));
687 assert(pBuff->nCount <= 0xFFFu);
688 SPORT_CHECK_CFG_CTL(pSportCfg->CTL);
690 ADI_INT_STATUS_ALLOC();
691 ADI_ENTER_CRITICAL_REGION();
692 pSportRegs->CTL_A = 0u;
693 pSportRegs->NUMTRAN_A = pBuff->nCount;
694 pDevice->pSportInfo->eState = ADI_SPORT_STATE_DATA_FLOW_ENABLED;
697 NVIC_ClearPendingIRQ(pDevice->pSportInfo->eIRQn);
698 NVIC_EnableIRQ(pDevice->pSportInfo->eIRQn);
699 pSportRegs->IEN_A |= ((uint32_t) ( BITM_SPORT_IEN_A_DATA
700 | BITM_SPORT_IEN_A_SYSDATERR
701 | BITM_SPORT_IEN_A_FSERRMSK
702 | BITM_SPORT_IEN_A_DERRMSK
703 | BITM_SPORT_IEN_A_TF
706 pSportRegs->CTL_A = pSportCfg->CTL | ((uint32_t)BITM_SPORT_CTL_A_SPEN);
707 ADI_EXIT_CRITICAL_REGION();
749 void **
const ppBuffer,
753 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE*) hDevice;
762 if (NULL != pDevice->pfCallback)
766 ADI_DT_CHANNEL * pSportChnl = &pDevice->sportChannel;
770 ADI_INT_STATUS_ALLOC();
771 ADI_ENTER_CRITICAL_REGION();
772 *pHwError = pDevice->nHwError;
773 pDevice->nHwError = 0u;
774 *ppBuffer = pSportChnl->pActiveBuffer->pStartAddress;
775 pSportChnl->pActiveBuffer->pStartAddress = NULL;
776 pSportChnl->pActiveBuffer = pSportChnl->pActiveBuffer->pNextBuffer;
777 ADI_EXIT_CRITICAL_REGION();
810 bool *
const pbAvailable)
813 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE*) hDevice;
815 *pbAvailable =
false;
822 if (NULL != pDevice->pfCallback)
828 ADI_DT_BUFF_INFO * pActiveBuffer = pDevice->sportChannel.pActiveBuffer;
830 if (pActiveBuffer->pStartAddress == NULL)
834 else if (
false == pActiveBuffer->bInUse)
868 ADI_CALLBACK
const pfCallback,
869 void *
const pCBparam)
872 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE *) hDevice;
879 else if (ADI_SPORT_STATE_DATA_FLOW_ENABLED == pDevice->pSportInfo->eState)
887 ADI_INT_STATUS_ALLOC();
888 ADI_ENTER_CRITICAL_REGION();
889 pDevice->pfCallback = pfCallback;
890 pDevice->pCBParam = pCBparam;
891 ADI_EXIT_CRITICAL_REGION();
931 const uint8_t nWordLength,
937 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE *) hDevice;
942 if(pDevice->pSportInfo->eState == ADI_SPORT_STATE_DATA_FLOW_ENABLED)
948 if (nWordLength > SPORT_WORD_TRANSFER_LENGTH)
954 ADI_SPORT_DEVICE_INFO * pSportInfo = pDevice->pSportInfo;
955 ADI_SPORT_CONFIG * pSportCfg = &pSportInfo->sportCfg;
956 const uint32_t bytesPerData = ((nWordLength < 9u) ? (1u) : ((nWordLength < 17u) ? (2u) : (4u)));
958 const uint32_t wordPos = (uint32_t) BITP_SPORT_CTL_A_SLEN;
959 const uint32_t wordLen = (uint32_t) nWordLength;
960 const uint32_t ctlSlen = (wordLen - 1u) << wordPos;
961 const uint32_t packMode = (uint32_t) ePackMode;
962 const uint32_t ctlSlenBits = (0x1Fu << wordPos);
963 const uint32_t ctlDataMask = ~(BITM_SPORT_DATA_CONFIG | ctlSlenBits | BITM_SPORT_CTL_A_LSBF);
965 uint32_t ctl = pDevice->pSportInfo->sportCfg.CTL;
967 ctl |= (packMode | ctlSlen);
968 if (
true == bLSBFirst)
970 ctl |= BITM_SPORT_CTL_A_LSBF;
972 pDevice->pSportInfo->sportCfg.CTL = ctl;
974 SPORT_CHECK_CFG_CTL(pDevice->pSportInfo->sportCfg.CTL);
976 switch (bytesPerData)
1063 const uint16_t nClockRatio,
1064 const bool bUseIntlClock,
1065 const bool bRisingEdge,
1066 const bool bGatedClk)
1069 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE *) hDevice;
1075 else if (ADI_SPORT_STATE_DATA_FLOW_ENABLED == pDevice->pSportInfo->eState)
1082 ADI_SPORT_CONFIG * pSportCfg = &pDevice->pSportInfo->sportCfg;
1083 uint32_t clockRatio = (uint32_t) nClockRatio;
1085 uint32_t ctl = pSportCfg->CTL;
1086 uint32_t dv = pSportCfg->DIV;
1088 ctl &= ~BITM_SPORT_CLOCK_CONFIG;
1090 dv &= ~BITM_SPORT_DIV_A_CLKDIV;
1091 dv |= (clockRatio & BITM_SPORT_DIV_A_CLKDIV);
1093 if (
true == bUseIntlClock)
1095 ctl |= BITM_SPORT_CTL_A_ICLK;
1097 if (
true == bRisingEdge)
1099 ctl |= BITM_SPORT_CTL_A_CKRE;
1101 if (
true == bGatedClk)
1103 ctl |= BITM_SPORT_CTL_A_GCLKEN;
1105 pDevice->pSportInfo->pSportRegs->DIV_A = pSportCfg->DIV = dv;
1106 pSportCfg->CTL = ctl;
1108 SPORT_CHECK_CFG_CTL(pSportCfg->CTL);
1194 const uint16_t nFsDivisor,
1195 const bool bFSRequired,
1196 const bool bInternalFS,
1198 const bool bActiveLowFS,
1200 const bool bFSErrorOperation)
1202 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE *) hDevice;
1210 else if(pDevice->pSportInfo->eState == ADI_SPORT_STATE_DATA_FLOW_ENABLED)
1217 ADI_SPORT_CONFIG * pSportCfg = &pDevice->pSportInfo->sportCfg;
1218 const uint32_t fsDivisor = (uint32_t) nFsDivisor;
1220 uint32_t ctl = pSportCfg->CTL;
1221 uint32_t dv = pSportCfg->DIV;
1223 dv &= ~BITM_SPORT_DIV_A_FSDIV;
1224 dv |= (fsDivisor << BITP_SPORT_DIV_A_FSDIV);
1226 ctl &= ~BITM_SPORT_FS_CONFIG;
1230 ctl |= BITM_SPORT_CTL_A_DIFS;
1232 if (
true == bFSRequired)
1234 ctl |= BITM_SPORT_CTL_A_FSR;
1236 if (
true == bInternalFS)
1238 ctl |= BITM_SPORT_CTL_A_IFS;
1240 if (
true == bActiveLowFS)
1242 ctl |= BITM_SPORT_CTL_A_LFS;
1244 if (
true == bLateFS)
1246 ctl |= BITM_SPORT_CTL_A_LAFS;
1248 if (
true == bFSErrorOperation)
1250 ctl |= BITM_SPORT_CTL_A_FSERRMODE;
1252 pDevice->pSportInfo->pSportRegs->DIV_A = pSportCfg->DIV = dv;
1253 pSportCfg->CTL = ctl;
1255 SPORT_CHECK_CFG_CTL(pSportCfg->CTL);
1290 const bool bUseOtherFS,
1291 const bool bUseOtherClk)
1294 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE *)hDevice;
1299 else if (pDevice->pSportInfo->eState == ADI_SPORT_STATE_DATA_FLOW_ENABLED)
1306 ADI_SPORT_CONFIG * pSportCfg = &pDevice->pSportInfo->sportCfg;
1307 uint32_t ctl = pSportCfg->CTL;
1310 ctl &= (uint32_t)(~(BITM_SPORT_CTL_A_CKMUXSEL | BITM_SPORT_CTL_A_FSMUXSEL));
1311 if (
true == bUseOtherFS)
1313 ctl |= BITM_SPORT_CTL_A_FSMUXSEL;
1315 if(bUseOtherClk ==
true)
1317 ctl |= BITM_SPORT_CTL_A_CKMUXSEL;
1319 pSportCfg->CTL = ctl;
1321 SPORT_CHECK_CFG_CTL(pSportCfg->CTL);
1354 const uint8_t nFSDuration,
1355 const uint8_t nWidth,
1356 const bool bActiveLow)
1359 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE*) hDevice;
1365 else if (ADI_SPORT_STATE_DATA_FLOW_ENABLED == pDevice->pSportInfo->eState)
1372 ADI_SPORT_CONFIG * pSportCfg = &pDevice->pSportInfo->sportCfg;
1373 uint32_t cnvt = pSportCfg->TIM_CONVT;
1376 cnvt &= (uint32_t)(~(BITM_SPORT_CNVT_A_POL | BITM_SPORT_CNVT_A_WID | BITM_SPORT_CNVT_A_CNVT2FS ));
1377 cnvt |= (((uint32_t) nFSDuration << ((uint32_t) BITP_SPORT_CNVT_A_CNVT2FS)) | ((uint32_t) nWidth));
1378 if(bActiveLow ==
true)
1380 cnvt |= ((uint32_t) BITM_SPORT_CNVT_A_POL);
1382 pDevice->pSportInfo->pSportRegs->CNVT_A = pSportCfg->TIM_CONVT = cnvt;
1401 static inline void sport_Init (ADI_SPORT_DEVICE *pDevice)
1404 ADI_DT_CHANNEL *pChannel = &pDevice->sportChannel;
1405 ADI_DT_BUFF_INFO *pBufInfo = &pChannel->BufInfo[0];
1406 ADI_SPORT_DEVICE_INFO * pSportInfo = pDevice->pSportInfo;
1407 ADI_SPORT_CONFIG * pSportCfg = &pSportInfo->sportCfg;
1408 const uint32_t bytesPerData = GetBytesPerSportData(pSportCfg->CTL);
1409 const uint32_t packMode = SPORT_GET_PACKEN(pSportCfg->CTL);
1412 for(i = 0u; i < ADI_DT_BUFNUM; i++)
1414 pBufInfo[i].pStartAddress = NULL;
1415 pBufInfo[i].nCount = 0u;
1416 pBufInfo[i].nIndex = 0u;
1417 pBufInfo[i].pNextBuffer = &pBufInfo[(i+1u) % ADI_DT_BUFNUM];
1419 pChannel->pFreeBuffer = &pChannel->BufInfo[0u];
1420 pChannel->pActiveBuffer = &pChannel->BufInfo[0u];
1421 pChannel->pFillBuffer = &pChannel->BufInfo[0u];
1423 switch (bytesPerData)
1426 if (SPORT_BIT_PACK_8 == packMode)
1434 assert(SPORT_BIT_PACK_NONE == packMode);
1439 if (SPORT_BIT_PACK_16 == packMode)
1447 assert(SPORT_BIT_PACK_NONE == packMode);
1454 assert((4u == bytesPerData) || (SPORT_BIT_PACK_NONE == packMode));
1467 static inline void sport_Configure (ADI_SPORT_DEVICE *pDevice, ADI_SPORT_CONFIG
const * sportCfg)
1475 volatile ADI_SPORT_TypeDef * sportRegs = pDevice->pSportInfo->pSportRegs;
1476 ADI_SPORT_CONFIG * pSportCfg = &pDevice->pSportInfo->sportCfg;
1479 memcpy(pSportCfg, sportCfg,
sizeof(ADI_SPORT_CONFIG));
1481 switch (pDevice->eDirection)
1484 pSportCfg->CTL &= ~BITM_SPORT_CTL_A_SPTRAN;
1487 pSportCfg->CTL |= BITM_SPORT_CTL_A_SPTRAN;
1494 sportRegs->CTL_A = pSportCfg->CTL;
1495 sportRegs->DIV_A = pSportCfg->DIV;
1496 sportRegs->CNVT_A = pSportCfg->TIM_CONVT;
1497 sportRegs->NUMTRAN_A = 0u;
1499 SPORT_CHECK_CFG_CTL(pSportCfg->CTL);
1506 ADI_SPORT_DEVICE * pInDevice = (ADI_SPORT_DEVICE*) hDevice;
1507 ADI_SPORT_DEVICE_INFO *poDeviceInfo = &gSportDevInfo[0][0];
1511 for (i=0u; i<(ADI_SPORT_NUM_INSTANCES << 1u); i++)
1513 if (pInDevice == poDeviceInfo->hDevice)
1525 #define recEvt ((uint32_t) (BITM_SPORT_STAT_A_SYSDATERR | BITM_SPORT_STAT_A_FSERR | BITM_SPORT_STAT_A_DERR)) 1528 #define clrEvt ((recEvt | BITM_SPORT_STAT_A_TFI)) 1530 static void sport_Terminate(ADI_SPORT_DEVICE * pDevice)
1532 ADI_SPORT_DEVICE_INFO * pSportInfo = pDevice->pSportInfo;
1533 volatile ADI_SPORT_TypeDef * pRegs = pSportInfo->pSportRegs;
1535 ADI_DT_CHANNEL * pSportChnl = &pDevice->sportChannel;
1536 ADI_DT_BUFF_INFO * pBuff = pSportChnl->pFillBuffer;
1538 pRegs->CTL_A &= ~BITM_SPORT_CTL_A_SPEN;
1539 pRegs->IEN_A &= ~(BITM_SPORT_IEN_A_TF | BITM_SPORT_IEN_A_DATA);
1540 pRegs->NUMTRAN_A = 0u;
1554 const uint32_t ctl = pRegs->CTL_A;
1555 const uint32_t bytesPerData = GetBytesPerSportData(ctl);
1556 const uint32_t nIndex = pBuff->nIndex * (4u / bytesPerData);
1557 assert((nIndex>=pBuff->nCount)||(
true==pBuff->bDMA));
1561 pBuff->bInUse =
false;
1563 NVIC_DisableIRQ(pSportInfo->eIRQn);
1564 NVIC_DisableIRQ(pSportInfo->eDMAn);
1566 pDevice->pSportInfo->eState = ADI_SPORT_STATE_PAUSED;
1568 if(NULL != pDevice->pfCallback)
1575 pDevice->pfCallback(pDevice->pCBParam,evt,pBuff->pStartAddress);
1576 pBuff->pStartAddress = NULL;
1580 SEM_POST(pSportChnl);
1582 pRegs->STAT_A = clrEvt;
1583 pSportChnl->eDataTranferMode = ADI_DT_MODE_NONE;
1584 pBuff = pBuff->pNextBuffer;
1585 pSportChnl->pFillBuffer = pBuff;
1587 if ((0u != pBuff->pStartAddress) && (
true == pBuff->bInUse))
1591 pSportChnl->eDataTranferMode = ADI_DT_MODE_NONBLOCKING;
1592 if (
true == pBuff->bDMA)
1594 result = sport_SubmitBufferDmaMode(pDevice, pBuff);
1598 result = sport_SubmitBufferIntMode(pDevice, pBuff);
1603 pSportChnl->eDataTranferMode = ADI_DT_MODE_NONE;
1619 static void sport_InterruptHandler(ADI_SPORT_DEVICE * pDevice)
1621 ADI_SPORT_DEVICE_INFO * pSportInfo = pDevice->pSportInfo;
1622 volatile ADI_SPORT_TypeDef * pRegs = pSportInfo->pSportRegs;
1623 const uint32_t sportStatus = pRegs->STAT_A;
1624 const uint32_t dataRequest = (sportStatus & BITM_SPORT_STAT_A_DATA);
1625 const uint32_t hwEvents = sportStatus & recEvt;
1639 if (NULL != pDevice->pfCallback)
1641 pDevice->pfCallback(pDevice->pCBParam,hwEvents,NULL);
1643 pDevice->nHwError |= hwEvents;
1644 SEM_POST(&pDevice->sportChannel);
1648 if (0u != dataRequest)
1650 ADI_DT_BUFF_INFO * pBuff = pDevice->sportChannel.pFillBuffer;
1651 uint32_t * pNextWord = (uint32_t*) pBuff->pStartAddress;
1653 if ((NULL != pNextWord) && (pBuff->nIndex < pBuff->nCount))
1657 pNextWord[pBuff->nIndex++] = pRegs->RX_A;
1658 while (!DXS_FIFO_IS_EMPTY(pRegs->STAT_A))
1660 pNextWord[pBuff->nIndex++] = pRegs->RX_A;
1665 pRegs->TX_A = pNextWord[pBuff->nIndex++];
1666 while ( (pBuff->nIndex < pBuff->nCount)
1667 && (!DXS_FIFO_IS_FULL(pRegs->STAT_A))
1670 pRegs->TX_A = pNextWord[pBuff->nIndex++];
1679 if (0u != (pRegs->STAT_A & BITM_SPORT_STAT_A_TFI))
1681 sport_Terminate(pDevice);
1684 #if defined(ADI_CYCLECOUNT_SPORT_ISR_ENABLED) && (ADI_CYCLECOUNT_SPORT_ISR_ENABLED == 1u) 1714 #if defined(ADI_CYCLECOUNT_SPORT_ISR_ENABLED) && (ADI_CYCLECOUNT_SPORT_ISR_ENABLED == 1u) 1729 #if defined(ADI_CYCLECOUNT_SPORT_ISR_ENABLED) && (ADI_CYCLECOUNT_SPORT_ISR_ENABLED == 1u) 1735 static void sport_DmaErrorCallback(
void *pCBParam, uint32_t Event,
void *pArg)
1737 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE*) pCBParam;
1738 ADI_DT_BUFF_INFO * pFillBuffer = pDevice->sportChannel.pFillBuffer;
1739 ADI_DT_BUFF_INFO * pNextBuffer = pFillBuffer->pNextBuffer;
1740 uint32_t nEvent = 0u;
1750 pDevice->nHwError |= nEvent;
1751 sport_InterruptHandler(pDevice);
1753 while ( (NULL != pNextBuffer->pStartAddress)
1754 && (
true == pNextBuffer->bInUse)
1755 && (
true == pNextBuffer->bDMA)
1758 pDevice->nHwError |= nEvent;
1759 pNextBuffer->bInUse =
false;
1760 sport_InterruptHandler(pDevice);
1761 pNextBuffer = pNextBuffer->pNextBuffer;
1765 static inline uint32_t GetBytesPerSportData(
const uint32_t ctlVal)
1767 const uint32_t wlen = SPORT_GET_WLEN(ctlVal);
1768 const uint32_t bytesPerData = ((wlen < 9u) ? (1u) : ((wlen < 17u) ? (2u) : (4u)));
1769 return bytesPerData;
ADI_DMA_RESULT adi_dma_RegisterCallback(DMA_CHANn_TypeDef const eChannelID, ADI_CALLBACK const pfCallback, void *const pCBParam)
Register a call-back function for a DMA channel.
#define ADI_CFG_SPORT0A_CONVT_POLARITY
#define ADI_CFG_SPORT0A_FS_REQUIRED
#define ADI_CFG_SPORT0B_LSB_FIRST
#define ADI_CYCLECOUNT_STORE(id)
#define ADI_CFG_SPORT0A_DATA_INDEPENDENT_FS
#define ADI_CFG_SPORT0A_FS_ERROR_OPERATION
#define ADI_CFG_SPORT0A_INTERNAL_CLK
#define ADI_CFG_SPORT0B_ACTIVE_LOW_FS
#define ADI_CFG_SPORT0B_SERIAL_WLEN
#define ADI_CFG_SPORT0B_LATE_FS
void SPORT0A_Int_Handler(void)
#define ADI_CFG_SPORT0B_CONVT_WIDTH
#define ADI_CFG_SPORT0B_CLOCK_EDGE
#define ADI_CFG_SPORT0B_GATED_CLOCK
#define ADI_CFG_SPORT0A_INTERNAL_FS
void SPORT0B_Int_Handler(void)
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.
#define ADI_CFG_SPORT0B_INTERNAL_CLK
#define ADI_CFG_SPORT0B_FS_DIVISOR
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.
void DMA_SPORT0B_Int_Handler(void)
#define ADI_CFG_SPORT0B_CLOCK_DIVISOR
#define ADI_CFG_SPORT0A_ACTIVE_LOW_FS
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 buffer...
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.
#define ADI_CFG_SPORT0B_ENABLE_PACKING
void DMA_SPORT0A_Int_Handler(void)
ADI_SPORT_RESULT adi_sport_Close(ADI_SPORT_HANDLE const hDevice)
Closes the operation of specified SPORT device.
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.
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 onl...
#define ADI_CYCLECOUNT_ISR_SPORT
#define ADI_CFG_SPORT0A_OPERATION_MODE
#define ADI_CFG_SPORT0A_LATE_FS
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.
#define ADI_CFG_SPORT0B_OPERATION_MODE
#define ADI_CFG_SPORT0A_ENABLE_FSMUXSEL
#define ADI_CFG_SPORT0A_FS_DIVISOR
#define ADI_CFG_SPORT0A_CONVT_WIDTH
#define ADI_CFG_SPORT0B_CONVT_FS_DURATION
#define ADI_CFG_SPORT0A_CLOCK_EDGE
#define ADI_CFG_SPORT0B_INTERNAL_FS
#define ADI_CFG_SPORT0A_CLOCK_DIVISOR
#define ADI_CFG_SPORT0B_FS_ERROR_OPERATION
#define ADI_CFG_SPORT0A_LSB_FIRST
void adi_dma_Init(void)
Initialize the DMA peripheral.
#define ADI_CFG_SPORT0B_CONVT_POLARITY
#define ADI_CFG_SPORT0A_ENABLE_PACKING
ADI_SPORT_RESULT adi_sport_RegisterCallback(ADI_SPORT_HANDLE const hDevice, const ADI_CALLBACK pfCallback, void *const pCBparam)
Register and unregister a Callback function with the SPORT device driver. A registered call back func...
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 ...
#define ADI_CFG_SPORT0A_CONVT_FS_DURATION
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.
#define ADI_CFG_SPORT0A_SERIAL_WLEN
#define ADI_CFG_SPORT0B_FS_REQUIRED
#define ADI_CFG_SPORT0B_DATA_INDEPENDENT_FS
#define ADI_SPORT_MEMORY_SIZE
#define ADI_CFG_SPORT0A_GATED_CLOCK
#define ADI_CFG_SPORT0A_ENABLE_CKMUXSEL