Define the line rate once, in wiredsensor-core
BAUD_RATE was declared separately in firmware/src/board.rs and bridge/src/main.rs with a comment asking that they be kept in agreement by hand. A baud mismatch between two ends of an RS485 segment is silent and presents as random CRC failures, which is a poor thing to debug and a poor thing to leave to a comment. It now lives in wiredsensor_core::timing alongside the arithmetic that derives from it, because the line rate is a property of the segment rather than of any one board. board.rs re-exports it, and the bridge takes a dependency on core purely to read it — it still knows nothing about the protocol itself. INTER_FRAME_GAP_US and CHAR_TIME_US move with it and are now derived at the definition site, with a test asserting they cannot go stale if the rate changes. Also fills two documentation gaps: the bridge and PC test suite were committed without any README coverage, and the account of the RTIM pitfall still described the incomplete understanding held before the hardware test found the real mechanism. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -86,15 +86,11 @@ pub const XTAL_FREQ_HZ: u32 = 12_000_000;
|
||||
|
||||
// -------------------------------------------------------------- bus timing ---
|
||||
|
||||
/// RS485 line rate. 19200 8N1 is the Modbus default and a safe starting point
|
||||
/// for long segments; every timing constant below derives from it.
|
||||
pub const BAUD_RATE: u32 = 19_200;
|
||||
|
||||
/// Idle time that delimits one frame from the next, in microseconds.
|
||||
pub const INTER_FRAME_GAP_US: u32 = timing::inter_frame_gap_us(BAUD_RATE);
|
||||
|
||||
/// Time to clock out one character at [`BAUD_RATE`], in microseconds.
|
||||
pub const CHAR_TIME_US: u32 = timing::char_time_us(BAUD_RATE);
|
||||
// Re-exported rather than redefined. The line rate belongs to the segment, not
|
||||
// to this board, so it lives in `wiredsensor_core::timing` where the bridge
|
||||
// firmware reads the same value — a mismatch between two ends of the bus is
|
||||
// silent and presents as random CRC failures. Change it there.
|
||||
pub use timing::{BAUD_RATE, CHAR_TIME_US, INTER_FRAME_GAP_US};
|
||||
|
||||
// ------------------------------------------------------------ sensor timing ---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user