![]() |
| | #1 |
| Registered User Join Date: Jun 2009
Posts: 4
| Data structure for storing serial port data in firmware I am sending data from a linux application through serial port to an embedded device. In the current implementation a byte circular buffer is used in the firmware. (Nothing but an array with a read and write pointer) As the bytes come in, it is written to the circular bufffer. Now the PC application appears to be sending the data too fast for the firmware to handle. Bytes are missed resulting in the firmware returning WRONG_INPUT too mant times. I think baud rate (115200) is not the issue. A more efficient data structure at the firmware side might help. Any suggestions on choice of data structure? Thanks |
| james457 is offline | |
| | #2 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| <help withdrawn due to abuse from OP>
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #3 |
| Registered User Join Date: Oct 2008 Location: TX
Posts: 1,262
| Implement flow control either in hardware using the CTS/RTS signals (as noted) or in software using the XON/XOFF characters. Check if the embedded device supports hardware flow control as it isn't supported by all devices / OSes. Last edited by itCbitC; 06-13-2009 at 03:01 AM. |
| itCbitC is offline | |
| | #4 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| If you are sending data in bursts, you may also consider a larger circular buffer. Also bear in mind that circular buffers where you use "pos = (pos + 1) % SIZE", if you pick a size that is 2 ^ n, you can use "pos = (pos + 1) & (SIZE-1)", which will be a much faster operation than the divide that the compiler MAY decide to generate for the % operator. The other option is to use an if-statement to modify the position. Also highly likely to be faster than the modulo operator (%). Since this is done twice for every character received, it may help to improve the peroformance. The other aspect is of course what you are doing to extract from the circular buffer - for example, are you allocating memory when extracting? Are you doing some lengthy work to calculate something, or search for something with the received data - does that prevent incoming data from being accepted. Could you change that? -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #5 | |
| Registered User Join Date: Jun 2009
Posts: 4
| Quote:
| |
| james457 is offline | |
![]() |
| Tags |
| c programming, data structure, linux, serial port |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Count number of 1 in a binary data trame through the serial port DB9 | minhdung_hoang | C Programming | 5 | 01-28-2009 04:34 PM |
| HELP with storing serial port data into txt file | inmaterichard | C Programming | 2 | 04-02-2008 02:20 AM |
| brace-enclosed error | jdc18 | C++ Programming | 53 | 05-03-2007 05:49 PM |
| HUGE fps jump | DavidP | Game Programming | 23 | 07-01-2004 10:36 AM |
| Serial Communications in C | ExDigit | Windows Programming | 7 | 01-09-2002 10:52 AM |