Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements in Syst.IO.Port implementations #2906

Merged
merged 1 commit into from
Mar 22, 2024

Conversation

josesimoes
Copy link
Member

Description

  • Add memalloc success and buffer underrun checks in GetLineFromRxBuffer.
  • Add missing var initializers in GetLineFromRxBuffer.
  • ReadLine on all platforms now performs a global lock/unlock when calling GetLineFromRxBuffer.
  • General code improvements in ReadLine in all platforms.
  • Remove SerialDevice from ESP32 NF_PAL_UART, adjust code accordingly.
  • Reading bytes from UART on ESP32 interrupt handler doesn't have timeout anymore.
  • Uart event handler in ESP32 doesn't check if callbacks are registered anymore.

Motivation and Context

  • General code robustness improvements.
  • Need to protect access to UART ring buffer when performing potentially long operation to find read line chars. During this time, the UART interrrupt handler could access the ring buffer and add more chars to it, having the potential to break the code.
  • Removing the check for registered callbacks in ESP32 is no big deal as it imposes an imperceptible execution penalty (this happens on all other platforms). In turn it removes the pointer to the SerialPort heap block from the PAL UART struct. This was doomed to cause failure in the event of a heap reallocation operation.
  • Resolves SerialPort issues while using ReadLine and the DataReceived event Home#1424 and possibly other recent reports of misbehaviors in serial ports.

How Has This Been Tested?

  • Sample application that floods the serial port with a barrage of data. Run for 5 minutes without issues. The same application was causing a hard fault in ORGPAL3 and core panic in ESP32.

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dev Containers (changes related with Dev Containers, has no impact on code or features)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).

@josesimoes josesimoes added Area: Targets Area: Common libs Everything related with common libraries Platform: STM32 Everything related specifically with ChibiOS platform Platform: ESP32 Everything related specifically with ESP32 platform Platform: NXP Everything related specifically with FreeRTOS Platform: TI-SimpleLink Platform: Azure-RTOS labels Mar 22, 2024
- Add memalloc success and buffer underrun checks in GetLineFromRxBuffer.
- Add missing var initializers in GetLineFromRxBuffer.
- ReadLine on all platforms now performs a global lock/unlock when calling GetLineFromRxBuffer.
- General code improvements in ReadLine in all platforms.
- Remove SerialDevice from ESP32 NF_PAL_UART, adjust code accordingly.
- Reading bytes from UART on ESP32 interrupt handler doesn't have timeout anymore.
- Uart event handler in ESP32 doesn't check if callbacks are registered anymore.
@josesimoes josesimoes merged commit 1701e7f into nanoframework:main Mar 22, 2024
23 checks passed
@josesimoes josesimoes deleted the work-serialport-readline branch March 22, 2024 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Common libs Everything related with common libraries Area: Targets Platform: Azure-RTOS Platform: ESP32 Everything related specifically with ESP32 platform Platform: NXP Everything related specifically with FreeRTOS Platform: STM32 Everything related specifically with ChibiOS platform Platform: TI-SimpleLink Type: bug Type: enhancement
Projects
None yet
2 participants