uart缓冲区大小如何设置(转载)
(2011-12-02 10:44:28)
标签:
杂谈 |
在设计串口程序时,我们都知道要设置一个缓冲区,那么到底这个缓冲区要多大呢?
在Jean J.Labrosse 的Embedded_systems_building_blocks中,他是这么说的:
When you use a buffer,the size of the buffer depends on how quickly your background process can get control of the CPU to process the information .For example,if the worst case latency of your background process is 200ms,you should plan for a buffer of at least 192 bytes if your serial port receives bytes at 9600 baud(960 bytes/sec * 200ms).
所以,按他的讲法,缓冲区大小 = 波特率*cpu处理最严重事件的等待时间。
一开始我觉得蛮有道理的。波特率越大,缓冲区也应该越大。cpu处理最严重事件的等待时间越长,缓冲区也应该越大。
但当我们用usb接收数据到内存里,然后用串口把它显示到pc时,发现会漏数据。我们使用的波特率是9600,串口缓冲区128*128,照这样算cpu处理最严重事件的等待时间可为128*128/960
=17s,怎么可能,但我们还是漏数据?? 突然发现上文讲的缓冲区大小方法是讲接受的,我搞错了,呵呵
在Jean J.Labrosse
When you use a buffer,the size of the buffer depends on how quickly your background process can get control of the CPU to process the information .For example,if the worst case latency of your background process is 200ms,you should plan for a buffer of at least 192 bytes if your serial port receives bytes at 9600 baud(960 bytes/sec * 200ms).
所以,按他的讲法,缓冲区大小 = 波特率*cpu处理最严重事件的等待时间。
一开始我觉得蛮有道理的。波特率越大,缓冲区也应该越大。cpu处理最严重事件的等待时间越长,缓冲区也应该越大。