Bounded Modbus RTU core and explicit RS485 ports.
More...
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Go to the source code of this file.
Bounded Modbus RTU core and explicit RS485 ports.
- Author
- Nexus Team
Definition in file modbus_rtu.h.
◆ NX_MODBUS_ADU_MAX
| #define NX_MODBUS_ADU_MAX 256u |
◆ NX_MODBUS_REGISTER_MAX
| #define NX_MODBUS_REGISTER_MAX 125u |
◆ nx_modbus_link_state_t
| Enumerator |
|---|
| NX_MODBUS_RX_IDLE | |
| NX_MODBUS_RX_FRAME | |
| NX_MODBUS_RX_DISCARD | |
| NX_MODBUS_LINK_FAULTED | |
Definition at line 62 of file modbus_rtu.h.
◆ nx_modbus_register_result_t
| Enumerator |
|---|
| NX_MODBUS_OK | |
| NX_MODBUS_ILLEGAL_ADDRESS | |
| NX_MODBUS_ILLEGAL_VALUE | |
| NX_MODBUS_DEVICE_FAILURE | |
| NX_MODBUS_DEVICE_BUSY | |
Definition at line 20 of file modbus_rtu.h.
◆ nx_modbus_crc16()
| uint16_t nx_modbus_crc16 |
( |
const uint8_t * | bytes, |
|
|
size_t | length ) |
Compute standard Modbus CRC16 over caller bytes.
- Parameters
-
| [in] | bytes | Input, NULL only when length is zero |
| [in] | length | Byte count |
- Returns
- CRC16; zero for invalid NULL input with nonzero length
◆ nx_modbus_rtu_feed()
| bool nx_modbus_rtu_feed |
( |
nx_modbus_rtu_t * | server, |
|
|
uint8_t | byte, |
|
|
uint64_t | arrival_us ) |
Feed an externally timestamped UART byte.
- Parameters
-
| [in,out] | server | Initialized instance, serialized by caller |
| [in] | byte | Wire byte |
| [in] | arrival_us | Capture timestamp in port monotonic domain |
- Returns
- True if byte joined the frame, false for discard/error
- Note
- Task-only. IRQ queues are external, bounded and explicit; queue overflow must call rx_error. No live UART discovery or ISR callback.
◆ nx_modbus_rtu_init()
Initialize an unused or fully quiesced protocol instance.
- Parameters
-
| [out] | server | Caller-owned storage, no existing transport borrow |
| [in] | config | Explicit register/RS485 ports and finite budgets |
- Returns
- True when initialized into RX silence acquisition
- Note
- Task-only; configuration is copied, contexts stay live. First direction(false) failure is reported; no worker or UART is created. Reinitializing a faulted TX borrow is prohibited; stop/recover it first.
◆ nx_modbus_rtu_poll()
Service RTU silence and bounded synchronous RS485 response.
- Parameters
-
| [in,out] | server | Initialized instance, single execution owner |
| [in] | now_us | Snapshot in the same monotonic domain |
- Returns
- True for successful progress, false for clock/transport error
- Note
- Task-only, explicit external scheduling. RS485 drain must observe the final stop bit. Failed abort retains TX bytes and asserted DE in LINK_FAULTED; keep instance/port alive until successful recover or stop.
◆ nx_modbus_rtu_recover()
Settle retained TX then restore receive silence acquisition.
- Parameters
-
| [in,out] | server | Initialized serialized instance with live ports |
- Returns
- True only after actual port abort/drain and receive direction
- Note
- Explicit task maintenance action, no fabricated recovery.
◆ nx_modbus_rtu_rx_error()
Discard an errored or overrun receive frame.
- Parameters
-
| [in,out] | server | Initialized serialized instance |
| [in] | now_us | Error timestamp in port's monotonic domain |
- Note
- Task-only. Does not discard a retained faulted TX borrow.
◆ nx_modbus_rtu_stop()
Settle the port before reclaiming protocol storage.
- Parameters
-
| [in,out] | server | Initialized, exclusively owned instance |
- Returns
- True when no transport borrow remains and instance is stopped; false preserves fault state, TX bytes and all port lifetime obligations
- Note
- Stop future feed/poll users first. No future use except explicit initialization is allowed after successful stop.