-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add SDD documentation for LinuxUartDriver component #4124
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0ea8029
Initial plan
Copilot 35c06c6
Add complete SDD documentation for LinuxUartDriver component
Copilot 919b1eb
Address all SDD review comments: numbering, requirement IDs, FPP exam…
Copilot 0b38458
manual fixes
thomas-bc 44bd6e6
Remove one level of section numbering in LinuxUartDriver SDD
Copilot 1b1bf9c
woop woop
thomas-bc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| # Drv::LinuxUartDriver Linux UART Driver Component | ||
|
|
||
| The LinuxUartDriver component provides a Linux-specific implementation of a UART (Universal Asynchronous Receiver-Transmitter) serial communication driver. It implements the byte stream driver model interface to enable serial communication with external devices through UART ports on Linux systems. | ||
|
|
||
| The component wraps Linux termios API functionality to provide configurable serial communication with support for various baud rates, flow control options, and parity settings. It implements bidirectional communication using a dedicated receive thread and synchronous send operations. | ||
|
|
||
| For more information on the ByteStreamDriverModel see: [`Drv::ByteStreamDriverModel`](../../ByteStreamDriverModel/docs/sdd.md). | ||
|
|
||
| ## Requirements | ||
|
|
||
| | Name | Description | Validation | | ||
| |---|---|---| | ||
| | UART-COMP-001 | The LinuxUartDriver component shall implement the ByteStreamDriverModel | inspection | | ||
| | UART-COMP-002 | The LinuxUartDriver component shall provide configurable baud rates from 9600 to 4MHz | inspection | | ||
| | UART-COMP-003 | The LinuxUartDriver component shall provide configurable flow control (none/hardware) | inspection | | ||
| | UART-COMP-004 | The LinuxUartDriver component shall provide configurable parity (none/odd/even) | inspection | | ||
| | UART-COMP-005 | The LinuxUartDriver component shall provide a dedicated read thread for receiving data | inspection | | ||
| | UART-COMP-006 | The LinuxUartDriver component shall report telemetry for bytes sent and received | inspection | | ||
| | UART-COMP-007 | The LinuxUartDriver component shall handle UART errors and report them via events | inspection | | ||
| | UART-COMP-008 | The LinuxUartDriver component shall support buffer allocation for receive operations | inspection | | ||
|
|
||
| ## Design | ||
|
|
||
| The LinuxUartDriver component implements the design specified by the [`Drv::ByteStreamDriverModel`](../../ByteStreamDriverModel/docs/sdd.md). | ||
|
|
||
| ### Architecture | ||
|
|
||
| The component consists of the following key elements: | ||
|
|
||
| - **UART Configuration**: Handles device opening, baud rate, flow control, and parity settings using Linux termios API | ||
| - **Send Handler**: Synchronous transmission of data via the `send` port | ||
| - **Receive Thread**: Asynchronous reception of data via a dedicated thread that calls the `recv` output port | ||
| - **Buffer Management**: Integration with F´ buffer allocation system for memory management | ||
| - **Telemetry Reporting**: Tracks and reports bytes sent and received statistics | ||
| - **Error Handling**: Comprehensive error detection and event reporting | ||
|
|
||
| ### Send Operation | ||
|
|
||
| When data is sent via the `send` input port: | ||
| 1. The component validates the file descriptor and buffer | ||
| 2. Data is written to the UART device using the Linux `write()` system call | ||
| 3. Bytes sent counter is updated for telemetry | ||
| 4. Status is returned indicating success or failure | ||
|
|
||
| ### Receive Operation | ||
|
|
||
| The receive operation runs in a separate thread: | ||
| 1. A buffer is allocated from the buffer manager | ||
| 2. The thread blocks on `read()` waiting for incoming data | ||
| 3. Received data is packaged in the buffer and sent via `recv` output port | ||
| 4. Bytes received counter is updated for telemetry | ||
| 5. Errors are logged and reported via events | ||
|
|
||
| ### Threading Model | ||
|
|
||
| The component uses a single dedicated thread for receive operations (`serialReadTaskEntry`). This thread: | ||
| - Runs continuously until `quitReadThread()` is called | ||
| - Allocates buffers for each receive operation | ||
| - Handles timeouts and errors gracefully | ||
| - Can be started with configurable priority and stack size | ||
|
|
||
| ## Usage | ||
|
|
||
| The LinuxUartDriver must be configured with device parameters before use. The typical usage pattern is: | ||
|
|
||
| 1. **Open Device**: Configure the UART device with desired parameters | ||
| 2. **Start Receive Thread**: Begin the receive thread for incoming data | ||
| 3. **Send/Receive Data**: Use the ByteStreamDriverModel ports for communication | ||
| 4. **Shutdown**: Stop the receive thread and close the device | ||
|
|
||
| ### Basic Configuration Example | ||
|
|
||
| ```cpp | ||
| Drv::LinuxUartDriver uart = Drv::LinuxUartDriver("UART Driver"); | ||
thomas-bc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| bool configureUart() { | ||
| // Open UART device with configuration | ||
| bool success = uart.open("/dev/ttyUSB0", // Device path | ||
thomas-bc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Drv::LinuxUartDriver::BAUD_115K, // 115200 baud | ||
| Drv::LinuxUartDriver::NO_FLOW, // No flow control | ||
| Drv::LinuxUartDriver::PARITY_NONE, // No parity | ||
| 1024); // Buffer size | ||
|
|
||
| if (success) { | ||
| // Start receive thread | ||
| uart.start(); | ||
| } | ||
|
|
||
| return success; | ||
| } | ||
|
|
||
| void shutdownUart() { | ||
| uart.quitReadThread(); | ||
| uart.join(); | ||
| } | ||
| ``` | ||
|
|
||
| ### Integration with Rate Groups | ||
|
|
||
| The component includes a `run` input port for telemetry reporting that should be connected to a rate group: | ||
|
|
||
| ```cpp | ||
| // Connect to rate group for periodic telemetry | ||
| rateGroup.connect_PingOut(0, uart.get_run_InputPort(0)); | ||
thomas-bc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| ### Device Parameters | ||
|
|
||
| | Parameter | Type | Description | Valid Values | | ||
| |-----------|------|-------------|--------------| | ||
| | device | const char* | Path to UART device | Linux device path (e.g., "/dev/ttyUSB0") | | ||
| | baud | UartBaudRate | Communication baud rate | See baud rate enumeration | | ||
| | fc | UartFlowControl | Flow control setting | NO_FLOW, HW_FLOW | | ||
| | parity | UartParity | Parity setting | PARITY_NONE, PARITY_ODD, PARITY_EVEN | | ||
| | allocationSize | FwSizeType | Receive buffer size | Positive integer (bytes) | | ||
|
|
||
| ### Baud Rate Options | ||
|
|
||
| The component supports the following baud rates: | ||
|
|
||
| | Enumeration | Numeric Value | Availability | | ||
| |-------------|---------------|--------------| | ||
| | BAUD_9600 | 9600 | All platforms | | ||
| | BAUD_19200 | 19200 | All platforms | | ||
| | BAUD_38400 | 38400 | All platforms | | ||
| | BAUD_57600 | 57600 | All platforms | | ||
| | BAUD_115K | 115200 | All platforms | | ||
| | BAUD_230K | 230400 | All platforms | | ||
| | BAUD_460K | 460800 | Linux only | | ||
| | BAUD_921K | 921600 | Linux only | | ||
| | BAUD_1000K | 1000000 | Linux only | | ||
| | BAUD_1152K | 1152000 | Linux only | | ||
| | BAUD_1500K | 1500000 | Linux only | | ||
| | BAUD_2000K | 2000000 | Linux only | | ||
| | BAUD_2500K | 2500000 | Linux only (if supported) | | ||
| | BAUD_3000K | 3000000 | Linux only (if supported) | | ||
| | BAUD_3500K | 3500000 | Linux only (if supported) | | ||
| | BAUD_4000K | 4000000 | Linux only (if supported) | | ||
|
|
||
| ### Thread Configuration | ||
|
|
||
| The receive thread can be configured with: | ||
|
|
||
| | Parameter | Type | Default | Description | | ||
| |-----------|------|---------|-------------| | ||
| | priority | FwTaskPriorityType | TASK_PRIORITY_DEFAULT | Thread priority | | ||
| | stackSize | Os::Task::ParamType | TASK_DEFAULT | Thread stack size | | ||
| | cpuAffinity | Os::Task::ParamType | TASK_DEFAULT | CPU affinity mask | | ||
|
|
||
| ### Events and Telemetry | ||
|
|
||
| The component generates the following events: | ||
| - **OpenError**: UART device open failures | ||
| - **ConfigError**: UART configuration failures | ||
| - **WriteError**: Data transmission errors | ||
| - **ReadError**: Data reception errors | ||
| - **PortOpened**: Successful device configuration | ||
| - **NoBuffers**: Buffer allocation failures | ||
| - **BufferTooSmall**: Insufficient buffer size | ||
|
|
||
| The component reports the following telemetry: | ||
| - **BytesSent**: Total bytes transmitted | ||
| - **BytesRecv**: Total bytes received | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.