⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xsicp.c

📁 优龙YLP270开发板 光盘自带的BIOS和实验例程源码 强烈推荐
💻 C
📖 第 1 页 / 共 2 页
字号:
*
* ASSUMPTIONS:      none.
*
*******************************************************************************
*/

static
INT clearTxIcp (IcpContextT * ctxP)
{
    volatile IcpRegsT * regsP = (IcpRegsT *)ctxP->regsP;

	regsP->ICCR0 &= ~ICP_ICCR0_TXE;
    return regsP->ICCR0;
}



/*
*******************************************************************************
*
* FUNCTION:         readBitStatusReg0Icp
*
* DESCRIPTION:      This function is used to read a specific bit in the status register 
*                   ICSR0 of the Icp
*
* INPUT PARAMETERS: IcpContextT * ctxP    is a pointer to the ICP's context structure
*					INT bit - bit mask of the bit of interest 
*
* RETURNS:          INT   - status of the bit of interest  
*
* GLOBAL EFFECTS:   none.
*
* ASSUMPTIONS:      none.
*
*******************************************************************************
*/

static
INT readBitStatusReg0Icp (IcpContextT * ctxP, IcpStatusReg0BitsT bit)
{
    volatile IcpRegsT * regsP = (IcpRegsT *)ctxP->regsP;
	INT status;

	status = regsP->ICSR0 & (1 << bit);
	status = (status >> bit); 

    return status;
}

/*
*******************************************************************************
*
* FUNCTION:         readStatusReg0Icp
*
* DESCRIPTION:      This function is used to read the status register ICSR0 of the Icp
*
* INPUT PARAMETERS: IcpContextT * ctxP    is a pointer to the ICP's context structure
*
* RETURNS:          INT   - The status of the ICSR0  
*
* GLOBAL EFFECTS:   none.
*
* ASSUMPTIONS:      none.
*
*******************************************************************************
*/

static
INT readStatusReg0Icp (IcpContextT * ctxP)
{
    volatile IcpRegsT * regsP = (IcpRegsT *)ctxP->regsP;

	return (regsP->ICSR0);
}


/*
*******************************************************************************
*
* FUNCTION:         readBitStatusReg1Icp
*
* DESCRIPTION:      This function is used to read the status register ICSR1 of the Icp
*
* DESCRIPTION:      This function is used to read a specific bit in the status register 
*                   ICSR1 of the Icp
*
* RETURNS:          INT   - status of the bit of interest  
*
* GLOBAL EFFECTS:   none.
*
* ASSUMPTIONS:      none.
*
*******************************************************************************
*/

static
INT readBitStatusReg1Icp (IcpContextT * ctxP, IcpStatusReg1BitsT bit)
{
    volatile IcpRegsT * regsP = (IcpRegsT *)ctxP->regsP;
	INT status;

	status = regsP->ICSR1 & (1 << bit);
	status = (status >> bit); 

    return status;
}

/*
*******************************************************************************
*
* FUNCTION:         readStatusReg1Icp
*
* DESCRIPTION:      This function is used to read the status register ICSR1 of the Icp
*
* INPUT PARAMETERS: IcpContextT * ctxP    is a pointer to the ICP's context structure
*
* RETURNS:          INT   - The status of the ICSR0  
*
* GLOBAL EFFECTS:   none.
*
* ASSUMPTIONS:      none.
*
*******************************************************************************
*/

static
INT readStatusReg1Icp (IcpContextT * ctxP)
{
    volatile IcpRegsT * regsP = (IcpRegsT *)ctxP->regsP;

	return (regsP->ICSR1);
}


/*
*******************************************************************************
*
* FUNCTION:         shutdownIcp
*
* DESCRIPTION:      This function is used to shutdown the Icp
*                   Tx and Rx FIFOs are cleared and SIU takes control of the data pins 
*
* INPUT PARAMETERS: ctxP    is a pointer to the ICP's context structure
*
* RETURNS:          INT     a contence of the ICCR0
*
* GLOBAL EFFECTS:   none.
*
* ASSUMPTIONS:      none.
*
*******************************************************************************
*/

static
INT shutdownIcp (IcpContextT * ctxP)
{
    volatile IcpRegsT * regsP = (IcpRegsT *)ctxP->regsP;
	
	// Unregister Interrupt Handler
    XsIcUnRegisterHandler (XSIC_ICP_SGNL);

//    XsIcDisableIrqDeviceInt (XSIC_ICP_SGNL);

	regsP->ICCR0 &= ~ICP_ICCR0_TXE;
	regsP->ICCR0 &= ~ICP_ICCR0_RXE;

	// Disable ICP unit
	regsP->ICCR0 &= ~ICP_ICCR0_ITR;

	// Clear the peripheral clock bit for the ICP
	xsCMDisableClock (CK_ICP);

    return regsP->ICCR0;
}


/*
*******************************************************************************
*
* FUNCTION:         InterruptHandlerDmaTxIcp
*
* DESCRIPTION:      Interrupt handler for DMA Tx transfer.
*					This is callback function, called by the DMA service. 
*
* INPUT PARAMETERS: PVOID param - pointer to the ICP'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 InterruptHandlerDmaTxIcp (PVOID param, UINT32 triggeringDcsr);
*
*******************************************************************************
*/

VOID InterruptHandlerDmaTxIcp (PVOID param, UINT32 triggeringDcsr)
{
    IcpContextT * ctxP = (IcpContextT *)param;

	// Check for the bus error
    if (triggeringDcsr & DCSR_BUSERRINTR)
    {
		DM_CwDbgPrintf(DM_CW_FIR_0, "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_FIR_0, "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++;
    }
}  

/*
*******************************************************************************
*
* FUNCTION:         InterruptHandlerDmaRxIcp
*
* DESCRIPTION:      Interrupt handler for DMA Rx transfer.
*					This is callback function, called by the DMA service. 
*
* INPUT PARAMETERS: PVOID param - pointer to the Uart'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 InterruptHandlerDmaRxIcp (PVOID param, UINT32 triggeringDcsr);
*
*******************************************************************************
*/

VOID InterruptHandlerDmaRxIcp (PVOID param, UINT32 triggeringDcsr)
{
    IcpContextT * ctxP = (IcpContextT *)param;

	// Check for the bus error
    if (triggeringDcsr & DCSR_BUSERRINTR)
    {
		DM_CwDbgPrintf(DM_CW_FIR_0, "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_FIR_0, "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++;
    }
}  

/*
*******************************************************************************
*
* FUNCTION:         XsIcpInterruptHandler
*
* DESCRIPTION:      Interrupt handler for the Infrared Communication Controller. 
*
* INPUT PARAMETERS: PVOID param - is a pointer to the ICP's context structure
*
* RETURNS:          None
*
* GLOBAL EFFECTS:   None
*
* ASSUMPTIONS:      The service clears the interrupts 
*
* CALLS:            
*
* CALLED BY:        The Interrupt service
*
* PROTOTYPE:        VOID XsIcpInterruptHandler (PVOID param);
*
*******************************************************************************
*/

VOID XsIcpInterruptHandler (IcpContextT * ctxP)
{
    volatile IcpRegsT * regsP = (IcpRegsT *)ctxP->regsP;
    INT interruptStatus;
    INT statusFlags;
    INT tempData;
	PCHAR buffP;

    // Read the contence of the ICSR0 to determine the source of the interrupts
	interruptStatus = ctxP->readStatusReg0IcpFnP (ctxP);
	
	// Clear the interrupts
	regsP->ICSR0 = interruptStatus;

    // Check a Framing Error
    if (interruptStatus | ICP_ICSR0_FRE)
    {
        // Increment a framing error counter
        ctxP->intStatusP->endErrorIntCount++;
    }

    // Check a receiver abort interrupt
    if (interruptStatus | ICP_ICSR0_RAB)
    {
        // Increment a receiver abort error counter
        ctxP->intStatusP->rxAbortIntCount++;
    }

    // Check a transmiter underun interrupt
    // This interrupt would be generated if not masked by ICCR0[TUS]
    if (interruptStatus | ICP_ICSR0_TUR)
    {
        // Increment a transmit underun counter
        ctxP->intStatusP->txUnderunIntCount++;
    }
    
    // An error or the trailing byte in the receive FIFO interrupt
    // This interrupt is cleared by the hardware when Rx FIFO is cleared
    if (interruptStatus)
    {
		buffP = (PCHAR)ctxP->trailingBytesBuffer;
        while (ctxP->readBitStatusReg1IcpFnP (ctxP, IcpRxNotEmpty) == TRUE)
        {
            // Check EOF,CRE, and ROR status flags in ICSR1
            statusFlags = ctxP->readStatusReg1IcpFnP(ctxP);
            if (statusFlags | ICP_ICSR1_STATUS)
            {
                // Discard the bad data
                tempData = regsP->ICDR;
                // Set a flag to signal a need to repeat a transfer
            }
			else
			{
				// This is trailing bytes, so read all of them and place them  
				// to the temp. buffer 
                *buffP++ = regsP->ICDR;
				ctxP->intStatusP->trailingBytesCount++;
			}
         }

        // Increment end/error counter
        ctxP->intStatusP->endErrorIntCount++;
    }

    // Check a receive FIFO service request											
    interruptStatus = ctxP->readBitStatusReg0IcpFnP(ctxP, IcpRxFifoServReq);
    if (interruptStatus)
    {
        // Unload Rx FIFO and place the data in the Rx buffer
    }

    // Check a transmit FIFO service request
    interruptStatus = ctxP->readBitStatusReg0IcpFnP(ctxP, IcpTxFifoServReq);
    if (interruptStatus)
    {
        // Load Tx FIFO with a new chunk of data
    }
}

/*
*******************************************************************************
*
* FUNCTION:         XsIcpSWInit         
*
* DESCRIPTION:      This function is used to initialize ICP's context structure. 
*                   No hardware setup is done at this point.
*
* INPUT PARAMETERS: none.
*
* RETURNS:          none.
*
* GLOBAL EFFECTS:   none.
*
* ASSUMPTIONS:      none.
*
*******************************************************************************
*/

void XsIcpSWInit (void)
{
    // Initialize the ICP
    IcpContextT * ctxP = &FastInfraredCommPort;

    // Initialize the ICP's register base
    ctxP->regsP = (IcpRegsT *)ICP_REGS_BASE;

    // Initialize the ICP's setup configuration
    ctxP->cfgP = &defaultIcpCfg;

    // Initialize the ICP's Dma configuration
	ctxP->dmaTxCfgP = &defaultDmaTxCfg;
	ctxP->dmaRxCfgP = &defaultDmaRxCfg;

    // Initialize the ICP's pointer to the Dma Status structure
	ctxP->dmaTxIntStatusP = &defaultDmaTxStatus;
	ctxP->dmaRxIntStatusP = &defaultDmaRxStatus;
    memset (&defaultDmaTxStatus, 0, sizeof(IcpDmaStatusT));
    memset (&defaultDmaRxStatus, 0, sizeof(IcpDmaStatusT));

    // Initialize the ICP's pointer to the Interrupt Status structure
    ctxP->intStatusP = &defaultIntStatus;
    memset (&defaultIntStatus, 0, sizeof(IcpIntStatusT));

    // Set the context structure's functions pointers 
    ctxP->setupIcpFnP = (IcpSetupT)XsIcpHWSetup;
    ctxP->loopbackIcpFnP = (IcpLoopbackT)loopbackIcp;
	ctxP->clearRxIcpFnP = (IcpClearRxT)clearRxIcp;
	ctxP->clearTxIcpFnP = (IcpClearTxT)clearTxIcp;
	ctxP->writeIcpFnP = (IcpWriteT)writeIcp;
	ctxP->readIcpFnP = (IcpReadT)readIcp;
    ctxP->shutdownIcpFnP = (IcpCleanupT)shutdownIcp;
	ctxP->readStatusReg0IcpFnP = (IcpReadStatRegT)readStatusReg0Icp;
	ctxP->readBitStatusReg0IcpFnP = (IcpReadBitStatRegT)readBitStatusReg0Icp; 						
	ctxP->readStatusReg1IcpFnP = (IcpReadStatRegT)readStatusReg1Icp; 						
	ctxP->readBitStatusReg1IcpFnP = (IcpReadBitStatRegT)readBitStatusReg1Icp;
    ctxP->intHandlerDmaTxFnP = (IcpDmaIntHandlerT)InterruptHandlerDmaTxIcp;
    ctxP->intHandlerDmaRxFnP = (IcpDmaIntHandlerT)InterruptHandlerDmaRxIcp;
    ctxP->intHandlerIcpFnP = (IcpIntHandlerT)XsIcpInterruptHandler;

	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 + -