📄 d_bt.r
字号:
Avail = 0;\
}
#define BTSend(OutputBuffer, BytesToSend)\
{\
UWORD Avail;\
AVAILOutBuf(Avail);\
if (BytesToSend < (Avail - 1))\
{\
memcpy(&(OutDma[DmaBufPtr][0]), OutputBuffer, BytesToSend);\
*AT91C_US1_TNPR = (unsigned int)&(OutDma[DmaBufPtr][0]);\
*AT91C_US1_TNCR = BytesToSend;\
DmaBufPtr = (DmaBufPtr + 1) % NO_OF_DMA_OUTBUFFERS;\
}\
}
#define BTSendMsg(OutputBuffer, BytesToSend, MsgSize)\
{\
UWORD Avail;\
AVAILOutBuf(Avail);\
if (BytesToSend < (Avail - 1))\
{\
if (2 == LengthSize)\
{\
OutDma[DmaBufPtr][0] = (UBYTE)MsgSize;\
OutDma[DmaBufPtr][1] = (UBYTE)(MsgSize>>8);\
}\
else\
{\
OutDma[DmaBufPtr][0] = (UBYTE)MsgSize;\
}\
memcpy(&(OutDma[DmaBufPtr][LengthSize]), OutputBuffer, BytesToSend);\
*AT91C_US1_TNPR = (unsigned int)&(OutDma[DmaBufPtr][0]);\
*AT91C_US1_TNCR = BytesToSend + LengthSize;\
DmaBufPtr = (DmaBufPtr + 1) % NO_OF_DMA_OUTBUFFERS;\
}\
}
#define BTReceivedData(pByteCnt, pToGo)\
{\
UWORD InCnt, Cnt;\
*pByteCnt = 0;\
*pToGo = 0;\
InCnt = (SIZE_OF_INBUF - *AT91C_US1_RCR);\
if (*AT91C_US1_RNCR == 0)\
{\
InCnt = SIZE_OF_INBUF;\
}\
InCnt -= InBufOutCnt; /* Remove already read bytes */\
if (InCnt)\
{\
if (0 == FullRxLength) /* FullRxLength still to be calculated */\
{\
while((MsgIn < LengthSize) && (InCnt > 0))\
{\
pBuffer[MsgIn] = InBuf[InBufInPtr][InBufOutCnt];\
MsgIn++;\
InBufOutCnt++;\
InCnt--;\
}\
if (LengthSize == MsgIn)\
{\
if (2 == LengthSize)\
{\
FullRxLength = pBuffer[1];\
FullRxLength <<= 8;\
FullRxLength |= pBuffer[0];\
/* Remove Length when in strean mode */\
MsgIn = 0;\
}\
else\
{\
FullRxLength = pBuffer[0];\
}\
RemainingLength = FullRxLength;\
}\
else\
{\
/* Length still not received */\
FullRxLength = 0;\
}\
}\
if (FullRxLength)\
{\
/* Incomming msg in progress */\
/* room for bytes? */\
if (InCnt >= RemainingLength)\
{\
/* Remaining msg bytes are in the buffer */\
/* Can remaining byte be stored in buffer? */\
if ((MsgIn + RemainingLength) <= SIZE_OF_INBUF)\
{\
/* All bytes can be stored */\
for (Cnt = 0; Cnt < RemainingLength; Cnt++)\
{\
pBuffer[MsgIn] = InBuf[InBufInPtr][InBufOutCnt];\
MsgIn++;\
InBufOutCnt++;\
}\
*pByteCnt = MsgIn;\
*pToGo = 0;\
FullRxLength = 0;\
RemainingLength = 0;\
MsgIn = 0;\
}\
else\
{\
for (Cnt = 0; MsgIn < SIZE_OF_INBUF; Cnt++)\
{\
pBuffer[MsgIn] = InBuf[InBufInPtr][InBufOutCnt];\
MsgIn++;\
InBufOutCnt++;\
}\
*pByteCnt = SIZE_OF_INBUF;\
RemainingLength -= Cnt;\
*pToGo = RemainingLength;\
MsgIn = 0;\
}\
}\
else\
{\
if ((InCnt + MsgIn) < SIZE_OF_INBUF)\
{\
/* Received bytes do not fill up the buffer */\
for (Cnt = 0; Cnt < InCnt; Cnt++)\
{\
pBuffer[MsgIn] = InBuf[InBufInPtr][InBufOutCnt];\
MsgIn++;\
InBufOutCnt++;\
}\
RemainingLength -= InCnt;\
}\
else\
{\
/* Received bytes fill up the buffer */\
for (Cnt = 0; MsgIn < SIZE_OF_INBUF; Cnt++)\
{\
pBuffer[MsgIn] = InBuf[InBufInPtr][InBufOutCnt];\
MsgIn++;\
InBufOutCnt++;\
}\
*pByteCnt = SIZE_OF_INBUF;\
RemainingLength -= Cnt; /* Only substract no removed */\
*pToGo = RemainingLength;\
MsgIn = 0;\
}\
}\
}\
}\
if ((*AT91C_US1_RNCR == 0) && (SIZE_OF_INBUF == InBufOutCnt))\
{\
InBufOutCnt = 0;\
*AT91C_US1_RNPR = (unsigned int)InBufPtrs[InBufInPtr];\
*AT91C_US1_RNCR = SIZE_OF_INBUF;\
InBufInPtr = (InBufInPtr + 1) % NO_OF_INBUFFERS;\
}\
}
#define BTExit {\
*AT91C_PMC_PCDR = PER_ID7_UART_1; /* Disable PMC clock for UART 1*/\
*AT91C_US1_IDR = AT91C_US_TIMEOUT; /* Disable interrupt on timeout */\
*AT91C_AIC_IDCR = UART1_INQ; /* Disable PIO interrupt */\
*AT91C_AIC_ICCR = UART1_INQ; /* Clear interrupt register */\
}
#endif
#ifdef PCWIN
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -