在线时间445 小时
UID2011467
注册时间2013-5-17
NXP金币0
该用户从未签到
金牌会员
 
- 积分
- 5781
- 最后登录
- 1970-1-1
|
发表于 2015-7-30 15:08:57
|
显示全部楼层
这个参数指向的参数可以给回调函数进行处理,通过以下代码和数据结构,就可以将参数的地址锁定,以备回调函数应用。代码:- /*FUNCTION**********************************************************************
- *
- * Function Name : UART_DRV_InstallRxCallback
- * Description : Install receive data callback function, pass in NULL pointer
- * as callback will unistall.
- *
- *END**************************************************************************/
- uart_rx_callback_t UART_DRV_InstallRxCallback(uint32_t instance,
- uart_rx_callback_t function,
- uint8_t * rxBuff,
- void * callbackParam,
- bool alwaysEnableRxIrq)
- {
- assert(instance < UART_INSTANCE_COUNT);
- UART_Type * base = g_uartBase[instance];
- uart_state_t * uartState = (uart_state_t *)g_uartStatePtr[instance];
- uart_rx_callback_t currentCallback = uartState->rxCallback;
- uartState->rxCallback = function;
- uartState->rxCallbackParam = callbackParam;
- uartState->rxBuff = rxBuff;
- /* Enable/Disable the receive data full interrupt */
- uartState->isRxBusy = true;
- UART_BWR_C2_RIE(base, alwaysEnableRxIrq);
- return currentCallback;
- }
复制代码 数据结构:
- /*!
- * @brief Runtime state of the UART driver.
- *
- * This structure holds data that are used by the UART peripheral driver to
- * communicate between the transfer function and the interrupt handler. The
- * interrupt handler also uses this information to keep track of its progress.
- * The user passes in the memory for the run-time state structure and the
- * UART driver fills out the members.
- */
- typedef struct UartState {
- uint8_t txFifoEntryCount; /*!< Number of data word entries in TX FIFO. */
- const uint8_t * txBuff; /*!< The buffer of data being sent.*/
- uint8_t * rxBuff; /*!< The buffer of received data. */
- volatile size_t txSize; /*!< The remaining number of bytes to be transmitted. */
- volatile size_t rxSize; /*!< The remaining number of bytes to be received. */
- volatile bool isTxBusy; /*!< True if there is an active transmit. */
- volatile bool isRxBusy; /*!< True if there is an active receive. */
- volatile bool isTxBlocking; /*!< True if transmit is blocking transaction. */
- volatile bool isRxBlocking; /*!< True if receive is blocking transaction. */
- semaphore_t txIrqSync; /*!< Used to wait for ISR to complete its TX business. */
- semaphore_t rxIrqSync; /*!< Used to wait for ISR to complete its RX business. */
- uart_rx_callback_t rxCallback; /*!< Callback to invoke after receiving byte.*/
- void * rxCallbackParam; /*!< Receive callback parameter pointer.*/
- uart_tx_callback_t txCallback; /*!< Callback to invoke after transmitting byte.*/
- void * txCallbackParam; /*!< Transmit callback parameter pointer.*/
- } uart_state_t;
复制代码
|
|