📄 lld_uart.c
字号:
tVoid (*LLD_UART_isrMgrUart0)(tU8) = DEFAULT_UART_MGR;
tVoid (*LLD_UART_isrMgrUart1)(tU8) = DEFAULT_UART_MGR;
/* Al */
/************************************************************************
|function implementation (scope: module-local)
|-----------------------------------------------------------------------*/
/* Al: custom interrupt manager */
static tVoid INT_vUart_Default_manager (tU8 data) { }
/************************************************************************
* *
* FUNCTIONS *
* *
* INT_vUartTxEmpty *
* *
* DESCRIPTION *
* *
* Isr routine for uart Tx empty *
* *
* CALLS *
* *
* None *
* *
* INPUTS *
* *
* None *
* *
* OUTPUTS *
* *
* None *
* *
************************************************************************/
tVoid INT_vUartTxEmpty(UART_tenId enId)
{
/* Check if no other bytes have to be transmitted,
or if no buffer is available */
if( (arUartBuffCtrl[enId].u32wrNbytes == (tU32)0) ||
(arUartBuffCtrl[enId].ps8wrBuffer == NULL) )
{
/* Disable TxFifoEmpty interrupt */
LLD_UART_vSetIntEnable(enId, UART_EN_OFF, UART_EN_TX_EMPTY);
/* Release resource */
LLD_UART_vSetTxStatus(enId,UART_EN_IDLE);
}
else
{
/* Send Data */
tS8 *ps8wrBuffStart = arUartBuffCtrl[enId].ps8wrBuffer;
tS8 *ps8wrBuffEnd = (tS8 *)((tU32)arUartBuffCtrl[enId].ps8wrBuffer +
arUartBuffCtrl[enId].u32wrBuffSize);
tS8 s8UartFlag = 1;
/* Fill Tx FIFO */
do
{
LLD_UART_vWriteTxBuffer(enId, *(arUartBuffCtrl[enId].ps8wrBufferISR));
arUartBuffCtrl[enId].ps8wrBufferISR++;
/* Check for wrap around */
if( arUartBuffCtrl[enId].ps8wrBufferISR >= ps8wrBuffEnd )
{
/* wrap around the end... */
arUartBuffCtrl[enId].ps8wrBufferISR = ps8wrBuffStart;
}
/* Decrement number of bytes to be transmitted */
arUartBuffCtrl[enId].u32wrNbytes--;
if( UART_EN_0 == enId )
{
s8UartFlag = rd16(Uart0, UART_SR, TxFull);
}
else if( UART_EN_1 == enId )
{
s8UartFlag = rd16(Uart1, UART_SR, TxFull);
}
else
{
s8UartFlag = 1;
}
} while( (s8UartFlag == 0) &&
(arUartBuffCtrl[enId].u32wrNbytes > 0) );
/* Buffer will now be OK */
arUartStatus[enId].enTxFull = FALSE;
}
}
/************************************************************************
* *
* FUNCTIONS *
* *
* INT_vUartRxHalf2Full *
* *
* DESCRIPTION *
* *
* Isr routine for uart Rx half full *
* *
* CALLS *
* *
* None *
* *
* INPUTS *
* *
* None *
* *
* OUTPUTS *
* *
* None *
* *
************************************************************************/
tVoid INT_vUartRxHalf2Full(UART_tenId enId)
{
tS8 s8Data;
tS8 *ps8rdBuffStart = arUartBuffCtrl[enId].ps8rdBuffer;
tS8 *ps8rdBuffEnd = (tS8 *)((tU32)arUartBuffCtrl[enId].ps8rdBuffer +
arUartBuffCtrl[enId].u32rdBuffSize);
tS8 s8UartFlag = 0;
/* Read data from Rx buffer while RxBuff flag is set */
do
{
/* Read data from Hw fifo */
s8Data = LLD_UART_s8ReadRxBuffer(enId);
if( (ps8rdBuffStart != NULL) )
{
/* If Fifo Buffer is not full store data read from Hw Fifo */
if( arUartBuffCtrl[enId].u32rdNbytes < arUartBuffCtrl[enId].u32rdBuffSize )
{
*(arUartBuffCtrl[enId].ps8rdBufferISR) = s8Data;
/* wrap pointer around Rx fifo buffer size */
arUartBuffCtrl[enId].ps8rdBufferISR++;
if( arUartBuffCtrl[enId].ps8rdBufferISR >= ps8rdBuffEnd )
{
arUartBuffCtrl[enId].ps8rdBufferISR = ps8rdBuffStart;
}
arUartBuffCtrl[enId].u32rdNbytes++;
}
else
{
/* Buffer will now be FULL */
if( arUartStatus[enId].enRxFull == FALSE )
{
arUartBuffCtrl[enId].u32rdNumberOfOverflows++;
arUartStatus[enId].enRxFull = TRUE;
}
arUartBuffCtrl[enId].u32rdNumberOfOverflowBytes++;
}
}
if( UART_EN_0 == enId )
{
s8UartFlag = rd16(Uart0, UART_SR, RxBuffFull);
}
else if( UART_EN_1 == enId )
{
s8UartFlag = rd16(Uart1, UART_SR, RxBuffFull);
}
else
{
s8UartFlag = 0;
}
} while( s8UartFlag != 0 );
}
/************************************************************************
|function prototype (scope: global)
|-----------------------------------------------------------------------*/
/************************************************************************
|function implementation (scope: global)
|-----------------------------------------------------------------------*/
/************************************************************************
* *
* FUNCTIONS *
* *
* INT_vUart0IntrMngr *
* *
* DESCRIPTION *
* *
* Uart0 interrupt manager. Check interrupt cause and call *
* appropiate function *
* *
* CALLS *
* *
* LLD macros *
* *
* INPUTS *
* *
* None *
* *
* OUTPUTS *
* *
* None *
* *
************************************************************************/
tVoid INT_vUart0IntrMngr(tVoid)
{
/* Serve only one interrupt pending for each call */
if( rd16(Uart0, UART_SR, RxBuffFull) &&
rd16(Uart0, UART_IER, RxBuffFullIE) )
{
INT_vUartRxHalf2Full(UART_EN_0);
}
else if( rd16(Uart0, UART_SR, TxEmpty) &&
rd16(Uart0, UART_IER, TxEmptyIE) )
{
INT_vUartTxEmpty(UART_EN_0);
}
else if( rd16(Uart0, UART_SR, RxHalfFull) &&
rd16(Uart0, UART_IER, RxHalfFullIE) )
{
INT_vUartRxHalf2Full(UART_EN_0);
}
return;
}
/************************************************************************
* *
* FUNCTIONS *
* *
* INT_vUart1IntrMngr *
* *
* DESCRIPTION *
* *
* Uart1 interrupt manager. Check interrupt cause and call *
* appropiate function *
* *
* CALLS *
* *
* LLD macros *
* *
* INPUTS *
* *
* None *
* *
* OUTPUTS *
* *
* None *
* *
************************************************************************/
tVoid INT_vUart1IntrMngr(tVoid)
{
/* Serve only one interrupt pending for each call */
if( rd16(Uart1, UART_SR, RxBuffFull) &&
rd16(Uart1, UART_IER, RxBuffFullIE) )
{
INT_vUartRxHalf2Full(UART_EN_1);
}
else if( rd16(Uart1, UART_SR, TxEmpty) &&
rd16(Uart1, UART_IER, TxEmptyIE) )
{
INT_vUartTxEmpty(UART_EN_1);
}
else if( rd16(Uart1, UART_SR, RxHalfFull) &&
rd16(Uart1, UART_IER, RxHalfFullIE) )
{
INT_vUartRxHalf2Full(UART_EN_1);
}
return;
}
/************************************************************************
* *
* FUNCTIONS *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -