add serial module#413
Open
dangowrt wants to merge 7 commits into
Open
Conversation
Introduce the serial module, a native replacement for configuring tty/serial devices without invoking setserial or stty via system(). Add the SERIAL_SUPPORT build option and the shared infrastructure: get_fd() resolves the descriptor from any fs handle exposing a fileno method (or a bare integer), so every function operates on handles created via fs.open(); error() reports the last errno through the VM registry, mirroring the fs module; isatty() tests for a terminal. The module owns no resource type; device lifetime stays with the fs handle. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Add attr() and setattr() for full termios control. attr() returns the line settings as an object (iflag, oflag, cflag, lflag, ispeed, ospeed and the cc array); setattr() performs a read-modify-write, applying only the fields present and honouring an optional TCSANOW, TCSADRAIN or TCSAFLUSH selector. Export the raw termios constants (optional actions, the c_cflag, c_iflag, c_oflag and c_lflag bits, the c_cc subscripts with NCCS, and the Bxxx baud values) so callers compose configurations from named bits rather than strings. Each constant is guarded with ifdef for portability. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Layer convenience helpers over the raw termios access. setspeed() sets the input and output line speed from a Bxxx constant. setraw() switches to raw mode via cfmakeraw(), the basis for binary and TLV framing. setblocking() sets the VMIN and VTIME read controls, so a subsequent read() on the fs handle can block for an exact byte count (length-prefixed reads) or apply an inter-byte timeout. Define _DEFAULT_SOURCE so cfmakeraw() is visible under glibc. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Expose the RS-232 modem control lines. mget() returns the modem status bitmask (test individual lines by masking with the exported TIOCM_* constants); mset() replaces it; mbis() and mbic() assert and deassert individual bits. dtr() and rts() are convenience wrappers for the two output lines. Export the TIOCM_* line constants. Pseudo-terminals do not implement these ioctls and report ENOTTY via error(); real UART devices honour them. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Add the remaining line-control operations: sendbreak() transmits a break, drain() blocks until queued output has been transmitted, flush() discards buffered input and/or output, and input_waiting() and output_waiting() report the pending byte counts via TIOCINQ and TIOCOUTQ. Export the TCIFLUSH, TCOFLUSH and TCIOFLUSH queue selectors. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Provide the low-level driver configuration setserial exposes, via the Linux TIOCGSERIAL and TIOCSSERIAL ioctls; compiled only on Linux. getinfo() returns the serial_struct as an object; setinfo() applies a read-modify-write of the supplied fields, covering baud_base and custom_divisor for non-standard rates and the driver flags; lowlatency() toggles ASYNC_LOW_LATENCY for the common setserial low_latency case. Export the ASYNC_* driver flags and the PORT_* UART types. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Add a test under the gated 05_lib_serial category, skipped when serial.so is absent. It exercises the hardware-independent paths over a pseudo terminal: isatty(), attr() decoding, the setblocking() VMIN round-trip, setraw() clearing canonical mode, the exported constant relationships, and the modem error path where mget() on a non-terminal reports ENOTTY. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
serial: native serial/tty configuration module
Adds a
serialmodule to configure serial/tty devices from ucode, replacingsetserial/sttycalled viasystem().Every function operates on an
fs.open()handle (first argument) and settings are composed from raw exported constants, no string enums.attr,setattr,setspeed,setraw,setblocking(VMIN/VTIME for line-based and TLV reads)mget,mset,mbis,mbic,dtr,rtssendbreak,drain,flush,input_waiting,output_waitinggetinfo,setinfo,lowlatencyBuilt as
serial.sobehindSERIAL_SUPPORT(no extra deps). Includes a minimalist gated05_lib_serialtest.