微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI蓝牙设计交流 > CC2541透传数据不完整问题

CC2541透传数据不完整问题

时间:10-02 整理:3721RD 点击:

大家好,我在使用CC2541 BLE-CC254x-1.4.2.2 SDK的BLE_Bridge工程实现蓝牙透传功能时,修改了串口接收数据部分的代码,不采用第一个字节表示串口数据总长度的方式,但是这样导致通过串口透传的数据有时不完整,请问怎么解决?

void cSerialPacketParser( uint8 port, uint8 events )
{
//unused input parameters
(void)port;
(void)events;

uint8 done = FALSE;
uint8 numBytes;

// get the number of available bytes to process
numBytes = NPI_RxBufLen();

// check if there's any serial port data to process
while ( (numBytes > 0) && (!done) )
{
switch (serialRxState)
{
case SERIAL_STATE_LEN:
//read the length
//(void)NPI_ReadTransport((uint8 *)&packet_length, 1);
// decrement the number of available bytes
//numBytes -= 1;
//wirten by jason.
packet_length = numBytes;

// next state
serialRxState = SERIAL_STATE_DATA;

//DROP THROUGH

case SERIAL_STATE_DATA:
//check if we've dma'd the entire packet
if (numBytes >= packet_length)
{
// alloc temporary buffer
uint8 *temp_buf;
temp_buf = osal_mem_alloc( packet_length );

//store dma buffer into temp buffer
(void)NPI_ReadTransport(temp_buf, packet_length);

// copy data from temp buffer into rx circular buffer
for (uint8 i = 0; i < packet_length; i++)
{
//copy one byte to data buffer
serialBuffer[serialBufferOffset] = temp_buf[i];
//update offset
serialBufferOffset = circular_add(serialBufferOffset,1);
}
//free temp buffer
osal_mem_free(temp_buf);

//decrement number of available bytes
numBytes -= packet_length;

//reset state machine
serialRxState = SERIAL_STATE_LEN;
}
else
{
//not enough data to progress, so leave it in driver buffer
done = TRUE;
}
break;
}
}
}

串口接收数据可以采用中断模式。

@大秦正声  就是采用的中断,但是串口接收数据的时候是不连续的,可能是几个中断才能收完。透传事件timeout触发后就发送数据了,无法保证完整收下数据后再发送。有没有办法?

谢谢!

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top