?? uart.c
字號:
uiCurNData = pucOut - pucIn;
}
}
if (uiWhichFifo == RX_FIFO)
{
pucIn = PUartInfo->PdqReviceBuf->In;
pucOut = PUartInfo->PdqReviceBuf->Out;
uiMaxData = PUartInfo->PdqReviceBuf->MaxData;
if ( pucIn >= pucOut ) {
uiCurNData = pucIn - pucOut;
} else {
uiCurNData = uiMaxData - (pucOut - pucIn);
}
}
#if defined(UART_SEMCONTROL)
OSSemPost(PUartInfo->pUartSem);
#else
OS_EXIT_CRITICAL();
#endif // end #if defined(UART_SEMCONTROL)
return ( uiCurNData );
#else
if ((uiWhichFifo == TX_FIFO) && ((PUartInfo->uiUartFlag) < 0x80))
{
return (PUartInfo->PdqSendBuf->MaxData - PUartInfo->PdqSendBuf->NData);
}
if (uiWhichFifo == RX_FIFO)
{
return (PUartInfo->PdqReviceBuf->NData);
}
return 0;
#endif // end of #if defined(QUEUE_NEW_OPRT)
}
/*********************************************************************************************************
** Function name: uartFifoStatus
** Descriptions: 獲取Queue隊列的狀態
** input parameters: uiId: 子設備號
** uiWhichFifo: TX_FIFO-發送隊列;RX_FIFO-接收隊列
** Returned value: 發送隊列中可操作的空間大小,或接收隊列中可用數據個數
*********************************************************************************************************/
extern int32 uartFifoStatus (uint32 uiId,uint32 uiWhichFifo)
{
if (uiId < __UART_MAX_NUM)
return _uartQueueStatus(__GpuiUartInfoTab[uiId], uiWhichFifo);
else
return 0;
}
/*********************************************************************************************************
** Function name: uartFifoFlush
** Descriptions: 清空接收或發送Queue隊列
** input parameters: uiId: UART子設備號
** uiWhichFifo: TX_FIFO-發送隊列;RX_FIFO-接收隊列
** Output parameters: NONE
** Returned value: OPERATE_SUCCESS: 操作成功
** OPERATE_FAIL: 操作失敗
*********************************************************************************************************/
extern int32 uartFifoFlush (uint32 uiId, uint32 uiWhichFifo)
{
#if defined(UART_SEMCONTROL)
INT8U UartErr;
#endif // end #if defined(UART_SEMCONTROL)
if (uiId >__UART_MAX_NUM) {
return UART_NOK;
}
else if (uiWhichFifo == RX_FIFO) {
#if defined(UART_SEMCONTROL)
OSSemPend(__GpuiUartInfoTab[uiId]->pUartSem, 0, &UartErr);
#else
OS_ENTER_CRITICAL();
#endif // end #if defined(UART_SEMCONTROL)
QueueFlush((void *)__GpuiUartInfoTab[uiId]->PdqReviceBuf); /* 清空接收隊列 */
#if defined(UART_SEMCONTROL)
OSSemPost(__GpuiUartInfoTab[uiId]->pUartSem);
#else
OS_EXIT_CRITICAL();
#endif // end #if defined(UART_SEMCONTROL)
}
else if (uiWhichFifo == TX_FIFO) {
#if defined(UART_SEMCONTROL)
OSSemPend(__GpuiUartInfoTab[uiId]->pUartSem, 0, &UartErr);
#else
OS_ENTER_CRITICAL();
#endif // end #if defined(UART_SEMCONTROL)
QueueFlush((void *)__GpuiUartInfoTab[uiId]->PdqSendBuf);/* 清空發送隊列 */
#if defined(UART_SEMCONTROL)
OSSemPost(__GpuiUartInfoTab[uiId]->pUartSem);
#else
OS_EXIT_CRITICAL();
#endif // end #if defined(UART_SEMCONTROL)
}
else {
return UART_NOK;
}
return UART_OK;
}
/*********************************************************************************************************
** Function name: __uartGetch
** Descriptions: 無等待接收一個字節
** input parameters: PUartInfo : 指向uart信息結構體的指針
** uiRet : 存儲接收到的數據
** Returned value: UART_OK : 成功
** UART_EMPTY: 無數據
** Created by: Chenmingji
** Created Date: 2006-09-08
*********************************************************************************************************/
static uint8 __uartGetch (__PUART_INFO PUartInfo, uint8 *uiRet)
{
uint32 uiErr;
#if defined(UART_SEMCONTROL)
//OSSemPend(PUartInfo->pUartSem, 0, &UartErr);
#else
//OS_ENTER_CRITICAL();
#endif // end #if defined(UART_SEMCONTROL)
uiErr = QueueRead(uiRet, PUartInfo->PdqReviceBuf);
#if defined(UART_SEMCONTROL)
//OSSemPost(PUartInfo->pUartSem);
#else
//OS_EXIT_CRITICAL();
#endif // end #if defined(UART_SEMCONTROL)
return uiErr;
}
/*********************************************************************************************************
** Function name: uartRead
** Descriptions: 從串口設備讀取數據
** input parameters: uiId: 子設備號
** puiBuf: 保存返回數據的字符串指針地址
** uiNum: 讀取的數據個數
** pRsv: 保留參數
** Output parameters: puiBuf: 讀到的數據首地址
** Returned value: 實際讀取的數據個數
*********************************************************************************************************/
extern int32 uartRead (uint32 uiId,
uint8 *puiBuf,
uint32 uiNum,
void *pRsv)
{
uint32 i;
uint32 uiReviceNum = 0;
#if defined(UART_SEMCONTROL)
INT8U UartErr;
#endif // end #if defined(UART_SEMCONTROL)
if (uiId < __UART_MAX_NUM) {
#if defined(UART_SEMCONTROL)
OSSemPend(__GpuiUartInfoTab[uiId]->pUartSem, 0, &UartErr);
#else
OS_ENTER_CRITICAL();
#endif // end #if defined(UART_SEMCONTROL)
for (i=0;i<uiNum;i++) {
if (QUEUE_OK == ( __uartGetch(__GpuiUartInfoTab[uiId],puiBuf++))) {
uiReviceNum ++;
}
else
break;
}
#if defined(UART_SEMCONTROL)
OSSemPost(__GpuiUartInfoTab[uiId]->pUartSem);
#else
OS_EXIT_CRITICAL();
#endif // end #if defined(UART_SEMCONTROL)
}
return uiReviceNum;
}
/*********************************************************************************************************
** Function name: __uartWrite
** Descriptions: 發送多個字節數據
** input parameters: PUartInfo: 指向uart信息結構體的指針
** puiData: 要發送的數據的首地址
** uiNumByte: 發送數據的個數
** Output parameters: NONE
** Returned value: 成功發送數據的個數
*********************************************************************************************************/
static uint16 __uartWrite (__PUART_INFO PUartInfo, uint8 *puiData, uint32 uiNumByte)
{
volatile uint32 *puiAddrBase;
volatile uint32 uiOffBase;
uint32 uiSendNumbyte;
uint8 uiTemp;
#if defined(UART_SEMCONTROL)
INT8U UartErr;
#endif // end #if defined(UART_SEMCONTROL)
uiSendNumbyte = uiNumByte;
PUartInfo->uiUartFlag &= (~0x80); /* 使用隊列做為緩沖 */
if((PUartInfo->uiUartFlag) < 0x80) {
#if defined(UART_SEMCONTROL)
OSSemPend(PUartInfo->pUartSem, 0, &UartErr);
#else
OS_ENTER_CRITICAL();
#endif // end #if defined(UART_SEMCONTROL)
while (uiSendNumbyte > 0) {
if (QueueWrite((void *)PUartInfo->PdqSendBuf, *puiData++) == QUEUE_FULL) {
break;
}
uiSendNumbyte--;
}
PUartInfo->uiUartFlag |= 0x10; /* 使能發送隊列 */
if (PUartInfo->uiUartFlag > 0x0f) {
puiAddrBase = PUartInfo->puiAddrBase;
uiOffBase = PUartInfo->uiOffBase;
if ((puiAddrBase[__B_UART_IER << uiOffBase] & 0x02) == 0) {
if (QUEUE_OK == QueueRead(&uiTemp, PUartInfo->PdqSendBuf)) {
puiAddrBase[__B_UART_IER << uiOffBase] |= 0x02; /* 開發送中斷 */
puiAddrBase[__B_UART_THR << uiOffBase] = uiTemp;
}
}
}
#if defined(UART_SEMCONTROL)
OSSemPost(PUartInfo->pUartSem);
#else
OS_EXIT_CRITICAL();
#endif // end #if defined(UART_SEMCONTROL)
}
return (uiNumByte - uiSendNumbyte);
}
/*********************************************************************************************************
** Function name: __uartDirectMultiWrite
** Descriptions: 祇癳
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -