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

📄 xuartlite_intr_tapp_example.c

📁 最新的FreeRTOS源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    /*
     * Connect the UartLite to the interrupt subsystem such that interrupts can
     * occur. This function is application specific.
     */
    Status = UartLiteSetupIntrSystem(IntcInstancePtr,
                                     UartLiteInstPtr,
                                     UartLiteIntrId);
    if (Status != XST_SUCCESS)
    {
        return XST_FAILURE;
    }

    /*
     * Setup the handlers for the UartLite that will be called from the
     * interrupt context when data has been sent and received,
     * specify a pointer to the UartLite driver instance as the callback
     * reference so the handlers are able to access the instance data.
     */
    XUartLite_SetSendHandler(UartLiteInstPtr, UartLiteSendHandler,
                             UartLiteInstPtr);
    XUartLite_SetRecvHandler(UartLiteInstPtr, UartLiteRecvHandler,
                             UartLiteInstPtr);

    /*
     * Enable the interrupt of the UartLite so that the interrupts will occur.
     */
    XUartLite_EnableInterrupt(UartLiteInstPtr);

    /*
     * Initialize the send buffer bytes with a pattern to send.
     */
    for (Index = 0; Index < TEST_BUFFER_SIZE; Index++)
    {
        SendBuffer[Index] = Index;
    }

    /*
     * Send the buffer using the UartLite.
     */
    XUartLite_Send(UartLiteInstPtr, SendBuffer, TEST_BUFFER_SIZE);

    /*
     * Wait for the entire buffer to be transmitted,  the function may get
     * locked up in this loop if the interrupts are not working correctly.
     */
    while ((TotalSentCount != TEST_BUFFER_SIZE))
    {
    }


    UartLiteDisableIntrSystem(IntcInstancePtr, UartLiteIntrId);

    return XST_SUCCESS;
}

/*****************************************************************************/
/**
*
* This function is the handler which performs processing to send data to the
* UartLite. It is called from an interrupt context such that the amount of
* processing performed should be minimized. It is called when the transmit
* FIFO of the UartLite is empty and more data can be sent through the UartLite.
*
* This handler provides an example of how to handle data for the UartLite, but
* is application specific.
*
* @param    CallBackRef contains a callback reference from the driver.
*           In this case it is the instance pointer for the UartLite driver.
* @param    EventData contains the number of bytes sent or received for sent and
*           receive events.
*
* @return   None.
*
* @note     None.
*
****************************************************************************/
static void UartLiteSendHandler(void *CallBackRef, unsigned int EventData)
{
    TotalSentCount = EventData;
}

/****************************************************************************/
/**
*
* This function is the handler which performs processing to receive data from
* the UartLite. It is called from an interrupt context such that the amount of
* processing performed should be minimized. It is called when any data is
* present in the receive FIFO of the UartLite such that the data can be
* retrieved from the UartLite. The amount of data present in the FIFO is not
* known when this function is called.
*
* This handler provides an example of how to handle data for the UartLite, but
* is application specific.
*
* @param    CallBackRef contains a callback reference from the driver, in this
*           case  it is the instance pointer for the UartLite driver.
* @param    EventData contains the number of bytes sent or received for sent and
*           receive events.
*
* @return   None.
*
* @note     None.
*
****************************************************************************/
static void UartLiteRecvHandler(void *CallBackRef, unsigned int EventData)
{

}

/****************************************************************************/
/**
*
* This function setups the interrupt system such that interrupts can occur
* for the UartLite. This function is application specific since the actual
* system may or may not have an interrupt controller. The UartLite could be
* directly connected to a processor without an interrupt controller. The
* user should modify this function to fit the application.
*
* @param    IntcInstancePtr is a pointer to the instance of the INTC component.
* @param    UartLiteInstPtr is a pointer to the instance of UartLite component.
*           XPAR_<UARTLITE_instance>_DEVICE_ID value from xparameters.h.
* @param    UartLiteIntrId is the Interrupt ID and is typically
*           XPAR_<INTC_instance>_<UARTLITE_instance>_IP2INTC_IRPT_INTR
*           value from xparameters.h.
*
* @return   XST_SUCCESS if successful, otherwise XST_FAILURE.
*
* @note     None.
*
****************************************************************************/
XStatus UartLiteSetupIntrSystem(XIntc *IntcInstancePtr,
                                XUartLite *UartLiteInstPtr,
                                Xuint16 UartLiteIntrId)
{
    XStatus Status;

#ifndef TESTAPP_GEN
    /*
     * Initialize the interrupt controller driver so that it is ready to use.
     */
    Status = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID);
    if (Status != XST_SUCCESS)
    {
        return XST_FAILURE;
    }
#endif

    /*
     * Connect a device driver handler that will be called when an interrupt
     * for the device occurs, the device driver handler performs the specific
     * interrupt processing for the device.
     */
    Status = XIntc_Connect(IntcInstancePtr, UartLiteIntrId,
                           (XInterruptHandler)XUartLite_InterruptHandler,
                           (void *)UartLiteInstPtr);
    if (Status != XST_SUCCESS)
    {
        return XST_FAILURE;
    }

#ifndef TESTAPP_GEN
    /*
     * Start the interrupt controller such that interrupts are enabled for
     * all devices that cause interrupts, specific real mode so that
     * the UART can cause interrupts thru the interrupt controller.
     */
    Status = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE);
    if (Status != XST_SUCCESS)
    {
        return XST_FAILURE;
    }
#endif

    /*
     * Enable the interrupt for the UartLite.
     */
    XIntc_Enable(IntcInstancePtr, UartLiteIntrId);

#ifndef TESTAPP_GEN

    /*
     * Initialize the PPC exception table.
     */
    XExc_Init();

    /*
     * Register the interrupt controller handler with the exception table.
     */
    XExc_RegisterHandler(XEXC_ID_NON_CRITICAL_INT,
                        (XExceptionHandler)XIntc_InterruptHandler,
                        IntcInstancePtr);

    /*
     * Enable non-critical exceptions.
     */
    XExc_mEnableExceptions(XEXC_NON_CRITICAL);


#endif /* TESTAPP_GEN */

    return XST_SUCCESS;
}

/*****************************************************************************/
/**
*
* This function disables the interrupts that occur for the UartLite.
*
* @param    IntcInstancePtr is a pointer to the instance of the INTC component.
* @param    UartLiteIntrId is the Interrupt ID and is typically
*           XPAR_<INTC_instance>_<UARTLITE_instance>_IP2INTC_IRPT_INTR
*           value from xparameters.h.
*
* @return   None.
*
* @note     None.
*
******************************************************************************/
static void UartLiteDisableIntrSystem(XIntc *IntcInstancePtr,
                                      Xuint16 UartLiteIntrId)
{

    /*
     * Disconnect and disable the interrupt for the UartLite
     */
    XIntc_Disconnect(IntcInstancePtr, UartLiteIntrId);

}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -