📄 xsssp.c
字号:
* DESCRIPTION: This function is used to receive data via SSP in polled mode
* operation without regard to the status bits
*
* INPUT PARAMETERS: ctxP is a pointer to SSP context structure
* rxbufP is a pointer to the buffer where received data is
* going to be placed
* len is a specified number of bytes to read.
*
* RETURNS: INT an actual number of bytes have been read
*
* GLOBAL EFFECTS: none.
*
* ASSUMPTIONS: none.
*
*******************************************************************************
*/
static
INT readRawSsp(SspContextT * ctxP, UINT16 * rxbufP, INT len)
{
volatile SspRegT * regsP = (SspRegT *)ctxP->regsP;
INT total = len;
// Check for data in the receive FIFO.
if (statusSsp(ctxP) & SSP_SSSR_RFL_MASK)
{
// Drange the FIFO.
while (len--)
{
// Read from FIFO
*rxbufP++ = regsP->SSDR;
}
}
return total;
}
/*
*******************************************************************************
*
* FUNCTION: clearRxSsp
*
* DESCRIPTION: This function is used to clear receive FIFO of the SSP
*
* INPUT PARAMETERS: ctxP is a pointer to SSP's context structure
*
* RETURNS: INT total number of bytes read
*
* GLOBAL EFFECTS: none.
*
* ASSUMPTIONS: none.
*
*******************************************************************************
*/
static
INT clearRxSsp(SspContextT * ctxP)
{
volatile SspRegT * regsP = (SspRegT *)ctxP->regsP;
UINT readData;
INT total = 0;
while ((regsP->SSSR & SSP_SSSR_RNE) != 0)
{
readData = regsP->SSDR;
total++;
}
return total;
}
/*
*******************************************************************************
*
* FUNCTION: XsSspHWShutdown
*
* DESCRIPTION: This function is used to shutdown the SSP
* Tx and Rx FIFOs are cleared and SIU takes control of the data pins,
* and a clock is stopped.
*
* INPUT PARAMETERS: ctxP is a pointer to the SSP's context structure
*
* RETURNS: INT a contence of the SSCR0
*
* GLOBAL EFFECTS: none.
*
* ASSUMPTIONS: none.
*
*******************************************************************************
*/
static
INT XsSspHWShutdown (SspContextT * ctxP)
{
volatile SspRegT * regsP = (SspRegT *)ctxP->regsP;
// Disable SSP unit
regsP->SSCR0 &= ~SSP_SSCR0_SSE;
// Clear the peripheral clock bit for the SSP
switch (ctxP->type & 0x03)
{
case SSP1:
xsCMDisableClock (CK_SSP);
break;
case SSP2:
xsCMDisableClock (CK_SSP2);
break;
case SSP3:
xsCMDisableClock (CK_SSP3);
}
// UnRegister interrupt handler if TX/RX interrupt enabled.
if ((ctxP->cfgP->RxIntEnable == SspFIFOIntEnabled) ||
(ctxP->cfgP->TxIntEnable == SspFIFOIntEnabled))
{
// Unregister interrupt handler.
XsIcUnRegisterHandler(XSIC_SSP_SGNL);
XsIcDisableIrqDeviceInt (XSIC_SSP_SGNL);
}
return regsP->SSCR0;
}
/*
*******************************************************************************
*
* FUNCTION: InterruptHandlerDmaTxSsp
*
* DESCRIPTION: Interrupt handler for DMA Tx transfer.
* This is callback function, called by the DMA service.
*
* INPUT PARAMETERS: PVOID param - pointer to the Ssp's context structure
* UINT32 triggeringDcsr - contains the interrupts status
*
* RETURNS: None
*
* GLOBAL EFFECTS: None
*
* ASSUMPTIONS: The DMA service clears the interrupts
*
* CALLS:
*
* CALLED BY: DMA interrupt service
*
* PROTOTYPE: VOID InterruptHandlerDmaTxSsp (PVOID param, UINT32 triggeringDcsr);
*
*******************************************************************************
*/
VOID InterruptHandlerDmaTxSsp (PVOID param, UINT32 triggeringDcsr)
{
SspContextT * ctxP = (SspContextT *)param;
// Check for the bus error
if (triggeringDcsr & DCSR_BUSERRINTR)
{
DM_CwDbgPrintf(DM_CW_SSP, "Bus Error Interrupt \n");
// Increment bus errorcounter
ctxP->dmaTxIntStatusP->busErrorIntCount++;
}
// Check for completion of the current transmition
if (triggeringDcsr & DCSR_ENDINTR)
{
// Increment end interrupt counter
ctxP->dmaTxIntStatusP->endIntCount++;
if (ctxP->dmaTxIntStatusP->endIntCount >= ctxP->dmaTxCfgP->descNum)
{
DM_CwDbgPrintf(DM_CW_SSP, "End of the Tx transfer");
ctxP->xferTxComplete = TRUE;
}
}
if (triggeringDcsr & DCSR_STARTINTR)
{
// Increment start interrupt counter
ctxP->dmaTxIntStatusP->startIntCount++;
}
if (triggeringDcsr & DCSR_STOPINTR)
{
// Increment stop interrupt counter
ctxP->dmaTxIntStatusP->stopIntCount++;
DM_CwDbgPrintf(DM_CW_SSP, "End of the Tx transfer");
ctxP->xferTxComplete = TRUE;
}
}
/*
*******************************************************************************
*
* FUNCTION: InterruptHandlerDmaRxSsp
*
* DESCRIPTION: Interrupt handler for DMA Rx transfer.
* This is callback function, called by the DMA service.
*
* INPUT PARAMETERS: PVOID param - pointer to the Ssp's context structure
* UINT32 triggeringDcsr - contains the interrupts status
*
* RETURNS: None
*
* GLOBAL EFFECTS: None
*
* ASSUMPTIONS: The DMA service clears the interrupts
*
* CALLS:
*
* CALLED BY: DMA interrupt service
*
* PROTOTYPE: VOID InterruptHandlerDmaRxSsp (PVOID param, UINT32 triggeringDcsr);
*
*******************************************************************************
*/
VOID InterruptHandlerDmaRxSsp (PVOID param, UINT32 triggeringDcsr)
{
SspContextT * ctxP = (SspContextT *)param;
// Check for the bus error
if (triggeringDcsr & DCSR_BUSERRINTR)
{
DM_CwDbgPrintf(DM_CW_SSP, "Bus Error Interrupt \n");
// Increment bus errorcounter
ctxP->dmaRxIntStatusP->busErrorIntCount++;
}
// Check for completion of the current transmition
if (triggeringDcsr & DCSR_ENDINTR)
{
// Increment end interrupt counter
ctxP->dmaRxIntStatusP->endIntCount++;
if (ctxP->dmaRxIntStatusP->endIntCount >= ctxP->dmaRxCfgP->descNum)
{
DM_CwDbgPrintf(DM_CW_SSP, "End of the Rx transfer");
ctxP->xferRxComplete = TRUE;
}
}
if (triggeringDcsr & DCSR_STARTINTR)
{
// Increment start interrupt counter
ctxP->dmaRxIntStatusP->startIntCount++;
}
if (triggeringDcsr & DCSR_STOPINTR)
{
// Increment stop interrupt counter
ctxP->dmaRxIntStatusP->stopIntCount++;
DM_CwDbgPrintf(DM_CW_SSP, "End of the Rx transfer");
ctxP->xferRxComplete = TRUE;
}
}
/*
*******************************************************************************
*
* FUNCTION: XsSspSWInit
*
* DESCRIPTION: This function is used to initialize SSP's context structure.
* No hardware setup is done at this point.
*
* INPUT PARAMETERS: SspTypeT device - SSP type
*
* RETURNS: none.
*
* GLOBAL EFFECTS: none.
*
* ASSUMPTIONS: none.
*
*******************************************************************************
*/
void XsSspSWInit (SspTypeT device)
{
SspContextT * ctxP;
SspRegT * regsP;
switch (device)
{
case SSP1:
// Initialize the SSP
ctxP = &SspSerialPort;
// Initialize the SSP's register base
regsP = (SspRegT *)SSP1_REG_BASE;
// Initialize SSP ID
ctxP->type = device;
// Initialize SSP's error ID
ctxP->errorID = ERR_L_XSSSP1;
break;
case SSP2:
// Initialize the SSP
ctxP = &SspSerialPort2;
// Initialize the SSP's register base
regsP = (SspRegT *)SSP2_REG_BASE;
// Initialize SSP ID
ctxP->type = device;
// Initialize SSP's error ID
ctxP->errorID = ERR_L_XSSSP2;
break;
case SSP3:
// Initialize the SSP
ctxP = &SspSerialPort3;
// Initialize the SSP's register base
regsP = (SspRegT *)SSP3_REG_BASE;
// Initialize SSP ID
ctxP->type = device;
// Initialize SSP's error ID
ctxP->errorID = ERR_L_XSSSP3;
}
ctxP->regsP = regsP;
// Initialize the SSP's setup configuration
ctxP->cfgP = &defaultSspCfg;
// Initialize the SSP's Dma configuration
ctxP->dmaTxCfgP = &defaultDmaTxCfg;
ctxP->dmaRxCfgP = &defaultDmaRxCfg;
// Initialize the SSP's pointer to the Dma Status structure
ctxP->dmaTxIntStatusP = &defaultDmaTxStatus;
ctxP->dmaRxIntStatusP = &defaultDmaRxStatus;
// Set the context structure's functions pointers
ctxP->setupSspFnP = (SspSetupT)XsSspHWSetup;
ctxP->loopbackSspFnP = (SspLoopbackT)loopbackSsp;
ctxP->writeSspFnP = (SspWriteT)writeSsp;
ctxP->statusSspFnP = (SspStatusT)statusSsp;
ctxP->readSspFnP = (SspReadT)readSsp;
ctxP->readRawSspFnP = (SspReadRawT)readRawSsp;
ctxP->clearRxSspFnP = (SspClearRxT)clearRxSsp;
ctxP->shutdownSspFnP = (SspCleanupT)XsSspHWShutdown;
ctxP->intHandlerDmaTxFnP = (SspDmaIntHandlerT)InterruptHandlerDmaTxSsp;
ctxP->intHandlerDmaRxFnP = (SspDmaIntHandlerT)InterruptHandlerDmaRxSsp;
ctxP->loggedError = 0;
ctxP->dmaRxChannel = 0;
ctxP->dmaTxChannel = 0;
ctxP->xferTxComplete = 0;
ctxP->xferRxComplete = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -