📄 stream.c
字号:
char *pReadPtr = 0;
if (!psrtclassCom) {
return (-1);
}
if (!pcBuffer) {
return (-1);
}
if (!uiMaxBytes) {
return (0);
}
TX_DISABLE
uiReadBytes = psrtclassCom->iRecvCnt > uiMaxBytes
? uiMaxBytes
: psrtclassCom->iRecvCnt;
psrtclassCom->iRecvCnt -= uiReadBytes;
pReadPtr = psrtclassCom->pReadIndex;
psrtclassCom->pReadIndex += uiReadBytes;
psrtclassCom->pReadIndex = psrtclassCom->pReadIndex < psrtclassCom->pBufferEnd
? psrtclassCom->pReadIndex
: psrtclassCom->pReadIndex - psrtclassCom->iByfferSize;
TX_RESTORE
for (i = 0; i < uiReadBytes; i++) {
*pcBuffer++ = *pReadPtr++;
pReadPtr = pReadPtr < psrtclassCom->pBufferEnd
? pReadPtr
: psrtclassCom->pBufferStart;
}
return (uiReadBytes);
}
/*********************************************************************************************************
** Function name: streamIoctl
** Descriptions: 流类型控制
** input parameters: psrtclassCom 控制块指针
** iCommand 控制命令
** iArg 命令参数
** output parameters: NONE
** Returned value: 根据命令确定返回值
** Created by: Hanhui
** Created Date: 2007/12/18
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
int streamIoctl (PSTREAM_CLASS psrtclassCom,
int iCommand,
int iArg)
{
unsigned int iNeedReset = 0; /* 是否需要重新设置串口 */
if (!psrtclassCom) {
return (-1);
}
switch (iCommand) {
case STREAM_SET_BAUD:
psrtclassCom->uiBaud = iArg;
iNeedReset = 1; /* 需要重新设置串口 */
break;
case STREAM_GET_BAUD:
return (psrtclassCom->uiBaud);
break;
case STREAM_SET_STOPBIT:
psrtclassCom->uiStopBit = iArg;
iNeedReset = 1;
break;
case STREAM_GET_STOPBIT:
return (psrtclassCom->uiStopBit);
break;
case STREAM_SET_DATABIT:
psrtclassCom->uiDataBit = iArg;
iNeedReset = 1;
break;
case STREAM_GET_DATABIT:
return (psrtclassCom->uiDataBit);
break;
case STREAM_SET_CHECK:
psrtclassCom->uiCheck = iArg;
iNeedReset = 1;
break;
case STREAM_GET_CHECK:
return (psrtclassCom->uiCheck);
break;
}
if (iNeedReset) {
__streamInit(psrtclassCom->uiCom, UNUSE_INF,
psrtclassCom->uiDataBit,
psrtclassCom->uiStopBit,
psrtclassCom->uiCheck,
psrtclassCom->uiBaud);
}
return (0);
}
/*********************************************************************************************************
** Function name: __uartInt0
** Descriptions: UART0 中断
** input parameters: NONE
** output parameters: NONE
** Returned value: NONE
** Created by: Hanhui
** Created Date: 2007/12/18
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void __uartInt0 (void)
{
STREAM_CLASS *pStream = &__GsrtclassCom[0];
char *pBuffer = pStream->pWriteIndex;
while (rUFSTAT0 & 0x1F) {
if (pStream->iRecvCnt < pStream->iByfferSize) {
*pBuffer++ = RdURXH0();
pBuffer = pBuffer < pStream->pBufferEnd
? pBuffer
: pStream->pBufferStart;
}
}
pStream->pWriteIndex = pBuffer;
INTER_CLR_SUBSRCPND(BIT_SUB_RXD0);
INTER_CLR_PNDING(BIT_UART0);
}
/*********************************************************************************************************
** Function name: __uartInt1
** Descriptions: UART1 中断
** input parameters: NONE
** output parameters: NONE
** Returned value: NONE
** Created by: Hanhui
** Created Date: 2007/12/18
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void __uartInt1 (void)
{
STREAM_CLASS *pStream = &__GsrtclassCom[1];
char *pBuffer = pStream->pWriteIndex;
while (rUFSTAT1 & 0x1F) {
if (pStream->iRecvCnt < pStream->iByfferSize) {
*pBuffer++ = RdURXH1();
pBuffer = pBuffer < pStream->pBufferEnd
? pBuffer
: pStream->pBufferStart;
}
}
pStream->pWriteIndex = pBuffer;
INTER_CLR_SUBSRCPND(BIT_SUB_RXD1);
INTER_CLR_PNDING(BIT_UART1);
}
/*********************************************************************************************************
** Function name: __uartInt2
** Descriptions: UART2 中断
** input parameters: NONE
** output parameters: NONE
** Returned value: NONE
** Created by: Hanhui
** Created Date: 2007/12/18
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void __uartInt2 (void)
{
STREAM_CLASS *pStream = &__GsrtclassCom[2];
char *pBuffer = pStream->pWriteIndex;
while (rUFSTAT2 & 0x1F) {
if (pStream->iRecvCnt < pStream->iByfferSize) {
*pBuffer++ = RdURXH2();
pBuffer = pBuffer < pStream->pBufferEnd
? pBuffer
: pStream->pBufferStart;
}
}
pStream->pWriteIndex = pBuffer;
INTER_CLR_SUBSRCPND(BIT_SUB_RXD2);
INTER_CLR_PNDING(BIT_UART2);
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -