Statistics: Posted by Xiong Yu — Tue Nov 27, 2018 8:23 pm
Code:
static inline uart_numOfReceivedBytes(int uart_num) {
return FIELD2VAL(UART_STATUS_RXFIFO_COUNT, UART(uart_num).status);
}
bool receiveData(void) {
uint32_t timeStart = timer_get_count(FRC2) / 5000;
uint32_t timeNow = 0;
int numOfBytes = uart_numOfReceivedBytes(0);
int i;
bool received = false;
if(numOfBytes == 0) {
return false;
}
do{
if(numOfBytes > 2) {
for(i = 0; i < numOfBytes; i++)
g_rcvBuffer[i] = uart_getc(0);
received = true;
break;
} else {
numOfBytes = uart_numOfReceivedBytes(0);
}
timeNow = timer_get_count(FRC2) / 5000;
} while ((timeNow - timeStart) < 50);
do{
int leftToRead = g_rcvBuffer[2] - numOfBytes;
if(leftToRead == 0) {
received = true;
break;
}
if(leftToRead + CRC_LEN <= uart_numOfReceivedBytes(0)) {
for(i = 0; i < uart_numOfReceivedBytes(0); i++) {
g_rcvBuffer[numOfBytes+i] = uart_getc(0);
}
received = true;
}
timeNow = timer_get_count(FRC2) / 5000;
} while ((timeNow - timeStart) < 50 && received == false);
if(received == true) {
for(i = 0; i < 3; i++){
uint32_t timeStart = timer_get_count(FRC2)/5000;
while(timer_get_count(FRC2)/5000 - timeStart < 3);
//uart_putc(0, g_rcvBuffer[i]);
}
return isProtocolOk(&g_rcvBuffer[0]);
} else {
for(i = 0; i < numOfBytes; i++)
uart_getc(0);
}
return false;
}
Statistics: Posted by morcillo — Sat Jul 14, 2018 2:03 am