28 #include <drivers/general/adi_drivers_general.h> 29 #include <adi_sport_config.h> 30 #include <drivers/sport/adi_sport.h> 31 #include <adi_cyclecount.h> 32 #include "adi_sport_def.h" 58 #pragma diag_suppress=Pm026,Pm050,Pm073,Pm088,Pm123,Pm140,Pm143,Pm152,Pm153 63 #define SPORT0_A_REGS ((volatile ADI_SPORT_TypeDef*)REG_SPORT0_CTL_A) 64 #define SPORT0_B_REGS ((volatile ADI_SPORT_TypeDef*)REG_SPORT0_CTL_B) 66 #define SPORT0_A_CFG { 0u, 0u, 0u, 0u, 0u } 67 #define SPORT0_B_CFG { 0u, 0u, 0u, 0u, 0u } 69 #define DXS_FIFO_IS_FULL(STAT) (((STAT) & BITM_SPORT_STAT_A_DXS) == BITM_SPORT_STAT_A_DXS) 70 #define DXS_FIFO_IS_EMPTY(STAT) (((STAT) & BITM_SPORT_STAT_A_DXS) == 0u) 72 static ADI_SPORT_DEVICE_INFO gSportDevInfo [ADI_SPORT_NUM_INSTANCES][ADI_SPORT_NUM_CHANNELS] =
75 {SPORT0_A_REGS, SPORT0_A_CFG, ADI_SPORT_STATE_UNINITIALIZED, SPORT0A_CHANn, DMA0_CH2_DONE_IRQn, SPORT_A_EVT_IRQn, NULL},
76 {SPORT0_B_REGS, SPORT0_B_CFG, ADI_SPORT_STATE_UNINITIALIZED, SPORT0B_CHANn, DMA0_CH3_DONE_IRQn, SPORT_B_EVT_IRQn, NULL},
81 static const ADI_SPORT_CONFIG gSportCfg[ADI_SPORT_NUM_INSTANCES][ADI_SPORT_NUM_CHANNELS] =
194 const uint32_t nDevNum,
198 const uint32_t nMemSize,
206 if (nDevNum >= ADI_SPORT_NUM_INSTANCES)
210 else if (phDevice == NULL)
218 else if (ADI_SPORT_STATE_UNINITIALIZED != gSportDevInfo[nDevNum][eChannel].eState)
225 ADI_SPORT_DEVICE * pDevice = pMemory;
226 ADI_SPORT_DEVICE_INFO * sportInfo = &gSportDevInfo[nDevNum][eChannel];
227 ADI_SPORT_CONFIG
const * sportCfg = &gSportCfg[nDevNum][eChannel];
229 assert(eChannel < ADI_SPORT_NUM_CHANNELS);
231 memset(pMemory, 0, nMemSize);
233 pDevice->pSportInfo = sportInfo;
234 pDevice->eDirection = eDirection;
239 sport_Configure(pDevice,sportCfg);
249 ADI_SPORT_DEVICE_INFO * devInfo = &gSportDevInfo[nDevNum][eChannel];
260 ADI_INT_STATUS_ALLOC();
261 ADI_ENTER_CRITICAL_REGION();
262 devInfo->eState = ADI_SPORT_STATE_INITIALIZED;
263 devInfo->hDevice = pDevice;
264 ADI_EXIT_CRITICAL_REGION();
296 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE *) hDevice;
301 ADI_SPORT_DEVICE_INFO * pSportInfo = pDevice->pSportInfo;
304 ADI_INT_STATUS_ALLOC();
305 ADI_ENTER_CRITICAL_REGION();
306 NVIC_DisableIRQ(pSportInfo->eIRQn);
307 NVIC_DisableIRQ(pSportInfo->eDMAn);
308 pSportInfo->eState = ADI_SPORT_STATE_UNINITIALIZED;
309 pSportInfo->hDevice = NULL;
310 ADI_EXIT_CRITICAL_REGION();
316 pSportInfo->pSportRegs->CTL_A = 0u;
349 void *
const pBuffer,
350 uint32_t
const nNumBytes,
354 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE *) hDevice;
358 ADI_SPORT_CONFIG * pSportCfg = &pDevice->pSportInfo->sportCfg;
363 else if ( ((2u >= nNumBytes) && ((pDevice->pSportInfo->pSportRegs->CTL_A & BITM_SPORT_CTL_A_OPMODE) != 0u))
364 || (0u != (nNumBytes & ~(BITM_SPORT_NUMTRAN_A_VALUE)))
376 if (NULL != pDevice->sportChannel.pFreeBuffer->pStartAddress)
383 const uint32_t addr = (uint32_t) pBuffer;
396 const uint32_t dataSizeInBytes = GetBytesPerSportData(pSportCfg->CTL);
397 const uint32_t full = nNumBytes / dataSizeInBytes;
398 const uint32_t partial = nNumBytes % dataSizeInBytes;
399 const uint32_t misaligned = addr % dataSizeInBytes;
401 if ( (full > DMA_TRANSFER_LIMIT)
403 || (0u != misaligned)
409 const uint32_t misAligned = addr % 4u;
410 const uint32_t invalidNum = nNumBytes % 4u;
412 if ( (0u != misAligned)
413 || (0u != invalidNum)
422 ADI_DT_CHANNEL * pSportChnl = &pDevice->sportChannel;
424 pSportChnl->pFreeBuffer->pStartAddress = pBuffer;
425 pSportChnl->pFreeBuffer->nCount = nNumBytes;
426 pSportChnl->pFreeBuffer->nIndex = 0u;
427 pSportChnl->pFreeBuffer->bDMA = bDMA;
428 pSportChnl->pFreeBuffer->bInUse =
true;
434 pSportChnl->pFreeBuffer = pSportChnl->pFreeBuffer->pNextBuffer;
442 if (pSportChnl->eDataTranferMode == ADI_DT_MODE_NONE)
444 pSportChnl->eDataTranferMode = ADI_DT_MODE_NONBLOCKING;
449 result = sport_SubmitBufferDmaMode(pDevice, pSportChnl->pFillBuffer);
451 result = sport_SubmitBufferIntMode(pDevice, pSportChnl->pFillBuffer);
457 pSportChnl->eDataTranferMode = ADI_DT_MODE_NONE;
478 static ADI_SPORT_RESULT sport_SubmitBufferDmaMode(ADI_SPORT_DEVICE * pDevice,
479 ADI_DT_BUFF_INFO * pBuff)
482 ADI_SPORT_DEVICE_INFO * pSportInfo = pDevice->pSportInfo;
483 ADI_SPORT_CONFIG * pSportCfg = &pSportInfo->sportCfg;
486 if ( (pBuff != pDevice->sportChannel.pFillBuffer)
487 || (
true != pBuff->bInUse)
488 || (0u != pBuff->nIndex)
496 volatile ADI_SPORT_TypeDef* pSportRegs = pSportInfo->pSportRegs;
497 const uint32_t dmaChnlId = (uint32_t) pSportInfo->eDMAChnlID;
498 const uint32_t dmaChnlBit = (1u << dmaChnlId);
511 const uint32_t dmaDcc = (uint32_t) DMA_ENUM_CTL_CYCLE_CTL_BASIC;
512 const uint32_t bytesPerData = GetBytesPerSportData(pSportCfg->CTL);
514 const uint32_t dataSizeInBytes = (1u << pSportCfg->DMA_WIDTH);
515 uint32_t numDmaData = pBuff->nCount / dataSizeInBytes;
516 const uint32_t dmaDataEnd = (pBuff->nCount - dataSizeInBytes);
517 const uint32_t startAddress = (uint32_t) pBuff->pStartAddress;
518 const uint32_t numSportData = pBuff->nCount / bytesPerData;
520 assert(pBuff->nCount == (numSportData * bytesPerData));
521 assert(numSportData <= 0xFFFu);
522 assert(0u == (pBuff->nCount % dataSizeInBytes));
523 assert(numDmaData <= DMA_TRANSFER_LIMIT);
525 SPORT_CHECK_CFG_CTL(pSportCfg->CTL);
527 pSportRegs->CTL_A = 0u;
528 pADI_DMA0->SRCADDR_CLR = dmaChnlBit;
529 pADI_DMA0->EN_SET = dmaChnlBit;
530 pADI_DMA0->RMSK_CLR = dmaChnlBit;
531 pADI_DMA0->ALT_CLR = dmaChnlBit;
532 pADI_DMA0->PRI_SET = dmaChnlBit;
536 pPrimaryCCD[dmaChnlId].DMASRCEND = (uint32_t) &pSportRegs->RX_A;
537 pPrimaryCCD[dmaChnlId].DMADSTEND = startAddress + dmaDataEnd;
538 pPrimaryCCD[dmaChnlId].DMACDC =
539 (pSportCfg->DMA_INC << ((uint32_t)DMA_BITP_CTL_DST_INC)) |
540 (dmaIncNone << ((uint32_t)DMA_BITP_CTL_SRC_INC));
544 pPrimaryCCD[dmaChnlId].DMASRCEND = startAddress + dmaDataEnd;
545 pPrimaryCCD[dmaChnlId].DMADSTEND = (uint32_t) &pSportRegs->TX_A;
546 pPrimaryCCD[dmaChnlId].DMACDC =
547 (dmaIncNone << ((uint32_t)DMA_BITP_CTL_DST_INC)) |
548 (pSportCfg->DMA_INC << ((uint32_t)DMA_BITP_CTL_SRC_INC));
553 if (numDmaData < numSportData)
555 pPrimaryCCD[dmaChnlId].DMASRCEND = startAddress + dmaDataEnd + dataSizeInBytes;
559 pPrimaryCCD[dmaChnlId].DMACDC |=
560 (pSportCfg->DMA_WIDTH << ((uint32_t)DMA_BITP_CTL_SRC_SIZE)) |
561 (0u << ((uint32_t) DMA_BITP_CTL_R_POWER)) |
562 ((numDmaData - 1u) << ((uint32_t)DMA_BITP_CTL_N_MINUS_1)) |
563 (dmaDcc << ((uint32_t)DMA_BITP_CTL_CYCLE_CTL));
565 ADI_INT_STATUS_ALLOC();
566 ADI_ENTER_CRITICAL_REGION();
567 pDevice->pSportInfo->eState = ADI_SPORT_STATE_DATA_FLOW_ENABLED;
568 pSportRegs->NUMTRAN_A = numSportData;
571 NVIC_ClearPendingIRQ(pSportInfo->eIRQn);
572 NVIC_ClearPendingIRQ(pSportInfo->eDMAn);
574 uint32_t ien_a = ((uint32_t)BITM_SPORT_IEN_A_SYSDATERR) |
575 ((uint32_t)BITM_SPORT_IEN_A_FSERRMSK) |
576 ((uint32_t)BITM_SPORT_IEN_A_DERRMSK);
580 NVIC_EnableIRQ(pSportInfo->eDMAn);
585 ien_a |= ((uint32_t)BITM_SPORT_IEN_A_TF);
588 NVIC_EnableIRQ(pSportInfo->eIRQn);
590 pSportRegs->IEN_A = ien_a;
591 pSportRegs->CTL_A = pSportCfg->CTL |
592 ((uint32_t)BITM_SPORT_CTL_A_SPEN) |
593 ((uint32_t)BITM_SPORT_CTL_A_DMAEN);
594 ADI_EXIT_CRITICAL_REGION();
596 SPORT_CHECK_CFG_CTL(pSportCfg->CTL);
620 static ADI_SPORT_RESULT sport_SubmitBufferIntMode(ADI_SPORT_DEVICE * pDevice, ADI_DT_BUFF_INFO * pBuff)
624 if ( (pBuff != pDevice->sportChannel.pFillBuffer)
625 || (
true != pBuff->bInUse)
626 || (0u != pBuff->nIndex)
634 ADI_SPORT_CONFIG * pSportCfg = &pDevice->pSportInfo->sportCfg;
635 volatile ADI_SPORT_TypeDef * pSportRegs = pDevice->pSportInfo->pSportRegs;
636 uint32_t ctl = pSportCfg->CTL;
637 uint32_t bytesPerData = GetBytesPerSportData(ctl);
650 pBuff->nCount /= bytesPerData;
653 uint32_t pack = SPORT_GET_PACKEN(pSportCfg->CTL);
654 assert( ((9u > bytesPerData) && (1u == pack)) || ((17u > bytesPerData) && (2u == pack)) || (0u == pack));
656 assert(pBuff->nCount <= 0xFFFu);
657 SPORT_CHECK_CFG_CTL(pSportCfg->CTL);
659 ADI_INT_STATUS_ALLOC();
660 ADI_ENTER_CRITICAL_REGION();
661 pSportRegs->CTL_A = 0u;
662 pSportRegs->NUMTRAN_A = pBuff->nCount;
663 pDevice->pSportInfo->eState = ADI_SPORT_STATE_DATA_FLOW_ENABLED;
666 NVIC_ClearPendingIRQ(pDevice->pSportInfo->eIRQn);
667 NVIC_EnableIRQ(pDevice->pSportInfo->eIRQn);
668 pSportRegs->IEN_A |= ((uint32_t) ( BITM_SPORT_IEN_A_DATA
669 | BITM_SPORT_IEN_A_SYSDATERR
670 | BITM_SPORT_IEN_A_FSERRMSK
671 | BITM_SPORT_IEN_A_DERRMSK
672 | BITM_SPORT_IEN_A_TF
675 pSportRegs->CTL_A = pSportCfg->CTL | ((uint32_t)BITM_SPORT_CTL_A_SPEN);
676 ADI_EXIT_CRITICAL_REGION();
718 void **
const ppBuffer,
722 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE*) hDevice;
731 if (NULL != pDevice->pfCallback)
735 ADI_DT_CHANNEL * pSportChnl = &pDevice->sportChannel;
739 ADI_INT_STATUS_ALLOC();
740 ADI_ENTER_CRITICAL_REGION();
741 *pHwError = pDevice->nHwError;
742 pDevice->nHwError = 0u;
743 *ppBuffer = pSportChnl->pActiveBuffer->pStartAddress;
744 pSportChnl->pActiveBuffer->pStartAddress = NULL;
745 pSportChnl->pActiveBuffer = pSportChnl->pActiveBuffer->pNextBuffer;
746 ADI_EXIT_CRITICAL_REGION();
779 bool *
const pbAvailable)
782 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE*) hDevice;
784 *pbAvailable =
false;
791 if (NULL != pDevice->pfCallback)
797 ADI_DT_BUFF_INFO * pActiveBuffer = pDevice->sportChannel.pActiveBuffer;
799 if (pActiveBuffer->pStartAddress == NULL)
803 else if (
false == pActiveBuffer->bInUse)
837 ADI_CALLBACK
const pfCallback,
838 void *
const pCBparam)
841 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE *) hDevice;
848 else if (ADI_SPORT_STATE_DATA_FLOW_ENABLED == pDevice->pSportInfo->eState)
856 ADI_INT_STATUS_ALLOC();
857 ADI_ENTER_CRITICAL_REGION();
858 pDevice->pfCallback = pfCallback;
859 pDevice->pCBParam = pCBparam;
860 ADI_EXIT_CRITICAL_REGION();
900 const uint8_t nWordLength,
906 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE *) hDevice;
911 if(pDevice->pSportInfo->eState == ADI_SPORT_STATE_DATA_FLOW_ENABLED)
917 if (nWordLength > SPORT_WORD_TRANSFER_LENGTH)
923 ADI_SPORT_DEVICE_INFO * pSportInfo = pDevice->pSportInfo;
924 ADI_SPORT_CONFIG * pSportCfg = &pSportInfo->sportCfg;
925 const uint32_t bytesPerData = ((nWordLength < 9u) ? (1u) : ((nWordLength < 17u) ? (2u) : (4u)));
927 const uint32_t wordPos = (uint32_t) BITP_SPORT_CTL_A_SLEN;
928 const uint32_t wordLen = (uint32_t) nWordLength;
929 const uint32_t ctlSlen = (wordLen - 1u) << wordPos;
930 const uint32_t packMode = (uint32_t) ePackMode;
931 const uint32_t ctlSlenBits = (0x1Fu << wordPos);
932 const uint32_t ctlDataMask = ~(BITM_SPORT_DATA_CONFIG | ctlSlenBits | BITM_SPORT_CTL_A_LSBF);
934 uint32_t ctl = pDevice->pSportInfo->sportCfg.CTL;
936 ctl |= (packMode | ctlSlen);
937 if (
true == bLSBFirst)
939 ctl |= BITM_SPORT_CTL_A_LSBF;
941 pDevice->pSportInfo->sportCfg.CTL = ctl;
943 SPORT_CHECK_CFG_CTL(pDevice->pSportInfo->sportCfg.CTL);
945 switch (bytesPerData)
1032 const uint16_t nClockRatio,
1033 const bool bUseIntlClock,
1034 const bool bRisingEdge,
1035 const bool bGatedClk)
1038 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE *) hDevice;
1044 else if (ADI_SPORT_STATE_DATA_FLOW_ENABLED == pDevice->pSportInfo->eState)
1051 ADI_SPORT_CONFIG * pSportCfg = &pDevice->pSportInfo->sportCfg;
1052 uint32_t clockRatio = (uint32_t) nClockRatio;
1054 uint32_t ctl = pSportCfg->CTL;
1055 uint32_t dv = pSportCfg->DIV;
1057 ctl &= ~BITM_SPORT_CLOCK_CONFIG;
1059 dv &= ~BITM_SPORT_DIV_A_CLKDIV;
1060 dv |= (clockRatio & BITM_SPORT_DIV_A_CLKDIV);
1062 if (
true == bUseIntlClock)
1064 ctl |= BITM_SPORT_CTL_A_ICLK;
1066 if (
true == bRisingEdge)
1068 ctl |= BITM_SPORT_CTL_A_CKRE;
1070 if (
true == bGatedClk)
1072 ctl |= BITM_SPORT_CTL_A_GCLKEN;
1074 pDevice->pSportInfo->pSportRegs->DIV_A = pSportCfg->DIV = dv;
1075 pSportCfg->CTL = ctl;
1077 SPORT_CHECK_CFG_CTL(pSportCfg->CTL);
1163 const uint16_t nFsDivisor,
1164 const bool bFSRequired,
1165 const bool bInternalFS,
1167 const bool bActiveLowFS,
1169 const bool bFSErrorOperation)
1171 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE *) hDevice;
1179 else if(pDevice->pSportInfo->eState == ADI_SPORT_STATE_DATA_FLOW_ENABLED)
1186 ADI_SPORT_CONFIG * pSportCfg = &pDevice->pSportInfo->sportCfg;
1187 const uint32_t fsDivisor = (uint32_t) nFsDivisor;
1189 uint32_t ctl = pSportCfg->CTL;
1190 uint32_t dv = pSportCfg->DIV;
1192 dv &= ~BITM_SPORT_DIV_A_FSDIV;
1193 dv |= (fsDivisor << BITP_SPORT_DIV_A_FSDIV);
1195 ctl &= ~BITM_SPORT_FS_CONFIG;
1199 ctl |= BITM_SPORT_CTL_A_DIFS;
1201 if (
true == bFSRequired)
1203 ctl |= BITM_SPORT_CTL_A_FSR;
1205 if (
true == bInternalFS)
1207 ctl |= BITM_SPORT_CTL_A_IFS;
1209 if (
true == bActiveLowFS)
1211 ctl |= BITM_SPORT_CTL_A_LFS;
1213 if (
true == bLateFS)
1215 ctl |= BITM_SPORT_CTL_A_LAFS;
1217 if (
true == bFSErrorOperation)
1219 ctl |= BITM_SPORT_CTL_A_FSERRMODE;
1221 pDevice->pSportInfo->pSportRegs->DIV_A = pSportCfg->DIV = dv;
1222 pSportCfg->CTL = ctl;
1224 SPORT_CHECK_CFG_CTL(pSportCfg->CTL);
1259 const bool bUseOtherFS,
1260 const bool bUseOtherClk)
1263 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE *)hDevice;
1268 else if (pDevice->pSportInfo->eState == ADI_SPORT_STATE_DATA_FLOW_ENABLED)
1275 ADI_SPORT_CONFIG * pSportCfg = &pDevice->pSportInfo->sportCfg;
1276 uint32_t ctl = pSportCfg->CTL;
1279 ctl &= (uint32_t)(~(BITM_SPORT_CTL_A_CKMUXSEL | BITM_SPORT_CTL_A_FSMUXSEL));
1280 if (
true == bUseOtherFS)
1282 ctl |= BITM_SPORT_CTL_A_FSMUXSEL;
1284 if(bUseOtherClk ==
true)
1286 ctl |= BITM_SPORT_CTL_A_CKMUXSEL;
1288 pSportCfg->CTL = ctl;
1290 SPORT_CHECK_CFG_CTL(pSportCfg->CTL);
1323 const uint8_t nFSDuration,
1324 const uint8_t nWidth,
1325 const bool bActiveLow)
1328 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE*) hDevice;
1334 else if (ADI_SPORT_STATE_DATA_FLOW_ENABLED == pDevice->pSportInfo->eState)
1341 ADI_SPORT_CONFIG * pSportCfg = &pDevice->pSportInfo->sportCfg;
1342 uint32_t cnvt = pSportCfg->TIM_CONVT;
1345 cnvt &= (uint32_t)(~(BITM_SPORT_CNVT_A_POL | BITM_SPORT_CNVT_A_WID | BITM_SPORT_CNVT_A_CNVT2FS ));
1346 cnvt |= (((uint32_t) nFSDuration << ((uint32_t) BITP_SPORT_CNVT_A_CNVT2FS)) | ((uint32_t) nWidth));
1347 if(bActiveLow ==
true)
1349 cnvt |= ((uint32_t) BITM_SPORT_CNVT_A_POL);
1351 pDevice->pSportInfo->pSportRegs->CNVT_A = pSportCfg->TIM_CONVT = cnvt;
1370 static inline void sport_Init (ADI_SPORT_DEVICE *pDevice)
1373 ADI_DT_CHANNEL *pChannel = &pDevice->sportChannel;
1374 ADI_DT_BUFF_INFO *pBufInfo = &pChannel->BufInfo[0];
1375 ADI_SPORT_DEVICE_INFO * pSportInfo = pDevice->pSportInfo;
1376 ADI_SPORT_CONFIG * pSportCfg = &pSportInfo->sportCfg;
1377 const uint32_t bytesPerData = GetBytesPerSportData(pSportCfg->CTL);
1378 const uint32_t packMode = SPORT_GET_PACKEN(pSportCfg->CTL);
1381 for(i = 0u; i < ADI_DT_BUFNUM; i++)
1383 pBufInfo[i].pStartAddress = NULL;
1384 pBufInfo[i].nCount = 0u;
1385 pBufInfo[i].nIndex = 0u;
1386 pBufInfo[i].pNextBuffer = &pBufInfo[(i+1u) % ADI_DT_BUFNUM];
1388 pChannel->pFreeBuffer = &pChannel->BufInfo[0u];
1389 pChannel->pActiveBuffer = &pChannel->BufInfo[0u];
1390 pChannel->pFillBuffer = &pChannel->BufInfo[0u];
1392 switch (bytesPerData)
1395 if (SPORT_BIT_PACK_8 == packMode)
1403 assert(SPORT_BIT_PACK_NONE == packMode);
1408 if (SPORT_BIT_PACK_16 == packMode)
1416 assert(SPORT_BIT_PACK_NONE == packMode);
1423 assert((4u == bytesPerData) || (SPORT_BIT_PACK_NONE == packMode));
1436 static inline void sport_Configure (ADI_SPORT_DEVICE *pDevice, ADI_SPORT_CONFIG
const * sportCfg)
1444 volatile ADI_SPORT_TypeDef * sportRegs = pDevice->pSportInfo->pSportRegs;
1445 ADI_SPORT_CONFIG * pSportCfg = &pDevice->pSportInfo->sportCfg;
1448 memcpy(pSportCfg, sportCfg,
sizeof(ADI_SPORT_CONFIG));
1450 switch (pDevice->eDirection)
1453 pSportCfg->CTL &= ~BITM_SPORT_CTL_A_SPTRAN;
1456 pSportCfg->CTL |= BITM_SPORT_CTL_A_SPTRAN;
1463 sportRegs->CTL_A = pSportCfg->CTL;
1464 sportRegs->DIV_A = pSportCfg->DIV;
1465 sportRegs->CNVT_A = pSportCfg->TIM_CONVT;
1466 sportRegs->NUMTRAN_A = 0u;
1468 SPORT_CHECK_CFG_CTL(pSportCfg->CTL);
1475 ADI_SPORT_DEVICE * pInDevice = (ADI_SPORT_DEVICE*) hDevice;
1476 ADI_SPORT_DEVICE_INFO *poDeviceInfo = &gSportDevInfo[0][0];
1480 for (i=0u; i<(ADI_SPORT_NUM_INSTANCES << 1u); i++)
1482 if (pInDevice == poDeviceInfo->hDevice)
1494 #define recEvt ((uint32_t) (BITM_SPORT_STAT_A_SYSDATERR | BITM_SPORT_STAT_A_FSERR | BITM_SPORT_STAT_A_DERR)) 1497 #define clrEvt ((recEvt | BITM_SPORT_STAT_A_TFI)) 1499 static void sport_Terminate(ADI_SPORT_DEVICE * pDevice)
1501 ADI_SPORT_DEVICE_INFO * pSportInfo = pDevice->pSportInfo;
1502 volatile ADI_SPORT_TypeDef * pRegs = pSportInfo->pSportRegs;
1504 ADI_DT_CHANNEL * pSportChnl = &pDevice->sportChannel;
1505 ADI_DT_BUFF_INFO * pBuff = pSportChnl->pFillBuffer;
1507 pRegs->CTL_A &= ~BITM_SPORT_CTL_A_SPEN;
1508 pRegs->IEN_A &= ~(BITM_SPORT_IEN_A_TF | BITM_SPORT_IEN_A_DATA);
1509 pRegs->NUMTRAN_A = 0u;
1523 const uint32_t ctl = pRegs->CTL_A;
1524 const uint32_t bytesPerData = GetBytesPerSportData(ctl);
1525 const uint32_t nIndex = pBuff->nIndex * (4u / bytesPerData);
1526 assert((nIndex>=pBuff->nCount)||(
true==pBuff->bDMA));
1530 pBuff->bInUse =
false;
1532 NVIC_DisableIRQ(pSportInfo->eIRQn);
1533 NVIC_DisableIRQ(pSportInfo->eDMAn);
1535 pDevice->pSportInfo->eState = ADI_SPORT_STATE_PAUSED;
1537 if(NULL != pDevice->pfCallback)
1544 pDevice->pfCallback(pDevice->pCBParam,evt,pBuff->pStartAddress);
1545 pBuff->pStartAddress = NULL;
1549 SEM_POST(pSportChnl);
1551 pRegs->STAT_A = clrEvt;
1552 pSportChnl->eDataTranferMode = ADI_DT_MODE_NONE;
1553 pBuff = pBuff->pNextBuffer;
1554 pSportChnl->pFillBuffer = pBuff;
1556 if ((0u != pBuff->pStartAddress) && (
true == pBuff->bInUse))
1560 pSportChnl->eDataTranferMode = ADI_DT_MODE_NONBLOCKING;
1561 if (
true == pBuff->bDMA)
1563 result = sport_SubmitBufferDmaMode(pDevice, pBuff);
1567 result = sport_SubmitBufferIntMode(pDevice, pBuff);
1572 pSportChnl->eDataTranferMode = ADI_DT_MODE_NONE;
1588 static void sport_InterruptHandler(ADI_SPORT_DEVICE * pDevice)
1590 ADI_SPORT_DEVICE_INFO * pSportInfo = pDevice->pSportInfo;
1591 volatile ADI_SPORT_TypeDef * pRegs = pSportInfo->pSportRegs;
1592 const uint32_t sportStatus = pRegs->STAT_A;
1593 const uint32_t dataRequest = (sportStatus & BITM_SPORT_STAT_A_DATA);
1594 const uint32_t hwEvents = sportStatus & recEvt;
1608 if (NULL != pDevice->pfCallback)
1610 pDevice->pfCallback(pDevice->pCBParam,hwEvents,NULL);
1612 pDevice->nHwError |= hwEvents;
1613 SEM_POST(&pDevice->sportChannel);
1617 if (0u != dataRequest)
1619 ADI_DT_BUFF_INFO * pBuff = pDevice->sportChannel.pFillBuffer;
1620 uint32_t * pNextWord = (uint32_t*) pBuff->pStartAddress;
1622 if ((NULL != pNextWord) && (pBuff->nIndex < pBuff->nCount))
1626 pNextWord[pBuff->nIndex++] = pRegs->RX_A;
1627 while (!DXS_FIFO_IS_EMPTY(pRegs->STAT_A))
1629 pNextWord[pBuff->nIndex++] = pRegs->RX_A;
1634 pRegs->TX_A = pNextWord[pBuff->nIndex++];
1635 while ( (pBuff->nIndex < pBuff->nCount)
1636 && (!DXS_FIFO_IS_FULL(pRegs->STAT_A))
1639 pRegs->TX_A = pNextWord[pBuff->nIndex++];
1648 if (0u != (pRegs->STAT_A & BITM_SPORT_STAT_A_TFI))
1650 sport_Terminate(pDevice);
1653 #if defined(ADI_CYCLECOUNT_SPORT_ISR_ENABLED) && (ADI_CYCLECOUNT_SPORT_ISR_ENABLED == 1u) 1683 #if defined(ADI_CYCLECOUNT_SPORT_ISR_ENABLED) && (ADI_CYCLECOUNT_SPORT_ISR_ENABLED == 1u) 1698 #if defined(ADI_CYCLECOUNT_SPORT_ISR_ENABLED) && (ADI_CYCLECOUNT_SPORT_ISR_ENABLED == 1u) 1704 static void sport_DmaErrorCallback(
void *pCBParam, uint32_t Event,
void *pArg)
1706 ADI_SPORT_DEVICE * pDevice = (ADI_SPORT_DEVICE*) pCBParam;
1707 ADI_DT_BUFF_INFO * pFillBuffer = pDevice->sportChannel.pFillBuffer;
1708 ADI_DT_BUFF_INFO * pNextBuffer = pFillBuffer->pNextBuffer;
1709 uint32_t nEvent = 0u;
1719 pDevice->nHwError |= nEvent;
1720 sport_InterruptHandler(pDevice);
1722 while ( (NULL != pNextBuffer->pStartAddress)
1723 && (
true == pNextBuffer->bInUse)
1724 && (
true == pNextBuffer->bDMA)
1727 pDevice->nHwError |= nEvent;
1728 pNextBuffer->bInUse =
false;
1729 sport_InterruptHandler(pDevice);
1730 pNextBuffer = pNextBuffer->pNextBuffer;
1734 static inline uint32_t GetBytesPerSportData(
const uint32_t ctlVal)
1736 const uint32_t wlen = SPORT_GET_WLEN(ctlVal);
1737 const uint32_t bytesPerData = ((wlen < 9u) ? (1u) : ((wlen < 17u) ? (2u) : (4u)));
1738 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