-
Notifications
You must be signed in to change notification settings - Fork 23
Add UART passthrough #146
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
Add UART passthrough #146
Conversation
Reviewer's GuideThis PR introduces a UART passthrough mode by extending the UART handle, adding global state to manage disabled buffers, and implementing enable/disable functions that swap the underlying RX/TX buffers and install a passthrough callback to forward data between two UART buses. Sequence diagram for UART passthrough data forwardingsequenceDiagram
participant "UART_Handle 1"
participant "UART_Handle 2"
participant "passthrough_callback()"
"UART_Handle 1"->>passthrough_callback(): Data received
passthrough_callback()->>"UART_Handle 2": start_transmission()
"UART_Handle 2"->>"UART_Handle 1": Data forwarded
Class diagram for updated UART_Handle and passthrough functionsclassDiagram
class UART_Handle {
int bus_id
CircularBuffer* rx_buffer
CircularBuffer* tx_buffer
UART_RxCallback rx_callback
uint32_t rx_threshold
bool initialized
UART_Handle* passthrough_target
}
class CircularBuffer
class UART_RxCallback
UART_Handle --> CircularBuffer : uses rx_buffer
UART_Handle --> CircularBuffer : uses tx_buffer
UART_Handle --> UART_RxCallback : uses rx_callback
UART_Handle --> UART_Handle : passthrough_target
class UART {
+UART_enable_passthrough(UART_Handle* handle1, UART_Handle* handle2)
+UART_disable_passthrough(UART_Handle* handle1, UART_Handle* handle2)
}
UART ..> UART_Handle : operates on
UART ..> CircularBuffer : manages disabled tx_buffers
Flow diagram for enabling UART passthroughflowchart TD
A["UART_enable_passthrough(handle1, handle2)"] --> B["Check if passthrough already active"]
B -->|No| C["Check if handles are initialized"]
C -->|Yes| D["Store original tx_buffers"]
D --> E["Swap tx_buffer and rx_buffer between handles"]
E --> F["Set passthrough_target for each handle"]
F --> G["Install passthrough_callback as rx_callback"]
B -->|Yes| H["THROW(ERROR_RESOURCE_BUSY)"]
C -->|No| I["THROW(ERROR_DEVICE_NOT_READY)"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- enable_passthrough should validate that the two handles are distinct (i.e. not the same instance) to avoid self-passthrough edge cases.
- Currently enable_passthrough/disble_passthrough drops any existing RX callback and threshold; consider saving/restoring those so user callbacks aren’t permanently lost.
- The global g_disabled_tx_buffers relies on calling disable_passthrough in the same handle order; storing original TX buffers in each handle would let you restore them regardless of argument order.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- enable_passthrough should validate that the two handles are distinct (i.e. not the same instance) to avoid self-passthrough edge cases.
- Currently enable_passthrough/disble_passthrough drops any existing RX callback and threshold; consider saving/restoring those so user callbacks aren’t permanently lost.
- The global g_disabled_tx_buffers relies on calling disable_passthrough in the same handle order; storing original TX buffers in each handle would let you restore them regardless of argument order.
## Individual Comments
### Comment 1
<location> `tests/test_uart.c:483-492` </location>
<code_context>
+void test_UART_enable_passthrough_success(void)
</code_context>
<issue_to_address>
**suggestion (testing):** Missing test for enabling passthrough when one or both handles are uninitialized.
Please add a test where a handle is non-null but uninitialized, and confirm that ERROR_DEVICE_NOT_READY is thrown.
</issue_to_address>
### Comment 2
<location> `tests/test_uart.c:589-532` </location>
<code_context>
+void test_UART_passthrough_data_flow_bus0_to_bus1(void)
</code_context>
<issue_to_address>
**suggestion (testing):** Missing test for data overflow in passthrough mode.
Please add a test that simulates RX buffer overflow and verifies passthrough mode maintains data integrity.
</issue_to_address>
### Comment 3
<location> `tests/test_uart.c:864-873` </location>
<code_context>
+void test_UART_disable_passthrough_invalid_pair(void)
</code_context>
<issue_to_address>
**suggestion (testing):** Missing test for disabling passthrough with null handles.
Please add a test to ensure disabling passthrough with null handles returns ERROR_INVALID_ARGUMENT or the correct error.
</issue_to_address>
### Comment 4
<location> `tests/test_uart.c:1018-532` </location>
<code_context>
+void test_UART_deinit_with_active_passthrough(void)
</code_context>
<issue_to_address>
**suggestion (testing):** Missing test for deinit on the second handle while passthrough is active.
Please add a test to confirm that deinit on handle2 throws ERROR_RESOURCE_BUSY when passthrough is active.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| void test_UART_disable_passthrough_invalid_pair(void) | ||
| { | ||
| // Arrange - Initialize three UART buses | ||
| CircularBuffer rx_buffer1, tx_buffer1; | ||
| CircularBuffer rx_buffer2, tx_buffer2; | ||
| CircularBuffer rx_buffer3, tx_buffer3; | ||
| uint8_t rx_data1[256], tx_data1[256]; | ||
| uint8_t rx_data2[256], tx_data2[256]; | ||
| uint8_t rx_data3[256], tx_data3[256]; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Missing test for disabling passthrough with null handles.
Please add a test to ensure disabling passthrough with null handles returns ERROR_INVALID_ARGUMENT or the correct error.
| UART_LL_set_tx_complete_callback_Ignore(); | ||
|
|
||
| UART_deinit(handle1); | ||
| UART_deinit(handle2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Missing test for deinit on the second handle while passthrough is active.
Please add a test to confirm that deinit on handle2 throws ERROR_RESOURCE_BUSY when passthrough is active.
deca450 to
ddc48f1
Compare
This PR adds UART_enable_passthrough and UART_disable_passthrough to system/bus/uart. In passthrough mode, all data received on either bus is forwarded and output on the other.
Summary by Sourcery
Introduce UART passthrough mode to forward received data between two UART buses, with enable/disable APIs and safety guards.
New Features:
Enhancements:
Documentation:
Tests: