Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 7 months ago.
How does the RX buffer synchronization/critical section work?
Hi Sam,
Can you explain how the RX buffer synchronization works. Bytes are inserted in an IRQ function and extracted by 'main' but I don't see any synchronization, disabling interrupts, etc?
(I want to use it in an app that can have a fast burst of incoming bytes).
Question relating to:
2 Answers
9 years, 6 months ago.
I have a clone and added some code, not sure how to commit to this lib.
Import libraryBufferedSerial
Inherit from Serial and use software buffers for TX and RX. This allows the UART peripherals to operate in a IRQ driven mode. Overrides most (but not all) stdio functions as Serial did
9 years, 6 months ago.
Since it uses a circular buffer with seperate read/write pointers it is a relative save buffer implementation. However I do see that the compiles result might very well increase the buffer counter before writing the data, so then it would be possible you read data before it was written to the buffer, and that could indeed be a problem.
Thanks for the prompt answer. You are using the Buffers class and for the RX push from an IRQ and pull from main. This requires critical section protection to avoid pushing while a pull is in progress. Have you made sure that Buffers protects itself and if not, did you add critical section protection in your buffered serial class?
You can read more about it here https://developer.mbed.org/cookbook/Serial-Interrupts#critical-sections-using-enable-and . Notice how they disable the interrupt to avoid an IRQ while the buffer is accessed by main.
posted by Zapta Z. 06 Apr 2015