请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:CC2652RB 尊敬的 TI:
我的 SDK 版本是 simplelink_cc13x2_26x2_SDK_4_30_00_54、我在 Rx 回调模式下使用 UART2。
我发现每次 RxRingBuffer 满时都将调用 Rx 回调函数、但这不是我所期望的。
那么、我想知道是否有某种方法可以清除 RxRingBuffer?

This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
尊敬的 TI:
我的 SDK 版本是 simplelink_cc13x2_26x2_SDK_4_30_00_54、我在 Rx 回调模式下使用 UART2。
我发现每次 RxRingBuffer 满时都将调用 Rx 回调函数、但这不是我所期望的。
那么、我想知道是否有某种方法可以清除 RxRingBuffer?

你好,junde,
您是否试用 过 UART2_flushRx? 您是否将 代码建立在 uart2callback 的基础 上、并且能否提供任何证明问题的代码摘录?
此致、
Ryan
尊敬的 TI:
我已经尝试过 UART2_flushRx、但没有影响。 我的代码如下所示:
/*
* CODE IN INIT
*/
int8_t uart2_init(void)
{
UART2_Params uartParams2;
/* Create a UART: write in BLOCKING mode, and read in callback mode*/
UART2_Params_init(&uartParams2);
uartParams2.baudRate = RSBUS_BAUDRATE;
uartParams2.readMode = UART2_Mode_CALLBACK;
uartParams2.readCallback = UART2_read_callback;
uartParams2.readReturnMode = UART2_ReadReturnMode_PARTIAL;
uartHandle = UART2_open(CONFIG_UART2_RSBUS, &uartParams2);
if (uartHandle == NULL) {
/* UART2_open() failed */
Display_printf(display, 0, 0, "UART2_open failed");
return FALSE;
}
}
/*
* CallBack for uart2 read
*/
void UART2_read_callback(UART2_Handle handle, void *buf, size_t count, void *userArg, int_fast16_t status)
{
rxBufLen = count;
sem_post(&get_uart2_cmd);
}
/*
* Code in main loop
*/
while(1)
{
static int i = 0, total_len = 0;
// UART2_flushRx(uartHandle);
rsbus_send(sendDataBuf, 6);
do{
// TODO: the RxRingBuffer must be clear, HOW TO DO?
UART2_read(uartHandle, rsbusRxBuf, RSBUS_PACK_MAX_LENGTH, NULL);
sem_wait(&get_uart2_cmd);
if(rxBufLen > 9 && !memcmp(&rsbusRxBuf[1], addr, 6))
break;
else
{
int i, len = rxBufLen;
Display_printf(display, 0, 0, "len(%d <= 9), keep recv", len);
for(i = 0; i < len; i++)
Display_printf(display, 0, 0, "0x%02x", rsbusRxBuf[i]);
}
} while(1);
total_len += rxBufLen;
if(rxBufLen > 9 && rxBufLen < 255)
{
// int cnt;
// Display_printf(display, 0, 0, "recv len: %d, total_len: %d", rxBufLen, total_len);
// for(cnt = 0; cnt < rxBufLen; cnt++)
// {
// Display_printf(display, 0, 0, "%d", rsbusRxBuf[cnt]);
// }
Display_printf(display, 0, 0, "HOST recv len: %d, total_len: %d, crc: 0x%02x 0x%02x", rxBufLen, total_len, rsbusRxBuf[rxBufLen-2], rsbusRxBuf[rxBufLen-1]);
}
Task_sleep(5000000 / Clock_tickPeriod);
}