In development. It changes without notice.
Topic
Serial Transport
The serial line of a debug build, over a UART or the chip's USB.
It carries the console (Serial Debug Console) and the output of the diagnostics; on a computer it is the terminal.
- See also
- Logging, Serial Debug Console
Files | |
| file | src/ |
| How long a console writer waits for another task's line. | |
| file | src/ |
| Debug serial / console transport implementation. | |
| file | src/ |
| Debug serial / console transport facade. | |
Classes | |
| class | kleidos:: |
| One writer's wait for the console's writer lock. More about kleidos:: | |
| class | kleidos:: |
| Hold the console so several writes land as one run. More about kleidos:: | |
| struct | kleidos:: |
| Bytes this transport accepted and then did not send, and why. More about kleidos:: | |
Functions | |
| constexpr uint32_t | kleidos:: |
Time bytes take on a UART at baud in 8N1 framing, rounded up. | |
Variables | |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| Bits one byte takes on a UART line in 8N1 framing: start, eight data, stop. | |
Lifecycle and connection | |
| void | kleidos:: |
| Initialize the serial transport. | |
| void | kleidos:: |
| Set the read timeout. | |
| bool | kleidos:: |
| True when a host is attached. | |
| bool | kleidos:: |
| Block until a host connects or the timeout expires. | |
| void | kleidos:: |
| Route ESP logs to this transport. | |
Input | |
| int | kleidos:: |
| Bytes available to read. | |
| int | kleidos:: |
| Read one byte. | |
Output | |
| size_t | kleidos:: |
| Write raw bytes to the transport. | |
| bool | kleidos:: |
| Whether the last byte written through this transport ended a line. | |
| DropStats | kleidos:: |
| size_t | kleidos:: |
| Write raw characters to the transport. | |
| size_t | kleidos:: |
| Write a NUL-terminated string. | |
| size_t | kleidos:: |
| Write a line terminator. | |
| size_t | kleidos:: |
| Write a string followed by a newline. | |
| int | kleidos:: |
| printf-style formatted output. | |
| void | kleidos:: |
| Flush buffered output. | |
Function Documentation
atLineStart() #
Whether the last byte written through this transport ended a line.
True before anything was written. A caller that must start a line of its own (under a LineGuard, so the answer cannot change under it) writes a newline first when this is false, which is the case while another task's line is waiting for its own newline.
- Return values
-
Value Meaning true The console is at the start of a line. false The last byte written was not a newline.
available() #
Bytes available to read.
- Returns
- Number of bytes available; negative on error.
- Return values
-
Value Meaning 0 No data is currently buffered. 1 At least one byte is buffered. -1 Backend read failed.
begin() #
Initialize the serial transport.
- Parameters
-
Name Meaning baudRate Baud rate for UART targets; ignored for USB-JTAG.
dropStats() #
- Returns
- The running drop tally. Never resets; a caller compares snapshots.
isConnected() #
True when a host is attached.
- Return values
-
Value Meaning true USB/serial host is currently connected. false No host detected.
lineAirtimeMs() #
Time bytes take on a UART at baud in 8N1 framing, rounded up.
- Parameters
-
Name Direction Meaning bytes in Bytes to send. baud in Line speed in bits per second (0 yields 0).
- Returns
- Milliseconds on the wire.
print() #
Write a NUL-terminated string.
- Parameters
-
Name Meaning text String to write; must not be nullptr.
- Returns
- Number of bytes written.
printf() #
printf-style formatted output.
- Parameters
-
Name Meaning format printf format string.
- Returns
- Number of characters written, or negative on error.
println() [1/2] #
Write a line terminator.
- Returns
- Number of bytes written.
println() [2/2] #
Write a string followed by a newline.
- Parameters
-
Name Meaning text String to write; must not be nullptr.
- Returns
- Number of bytes written (including the newline).
read() #
Read one byte.
- Returns
- Byte value (0-255), or negative when no data is available.
- Return values
-
Value Meaning 0..255 The byte that was read. -1 No byte available (EOF / closed stream / native build).
setDebugOutput() #
Route ESP logs to this transport.
- Parameters
-
Name Meaning enabled True to forward ESP_LOG output to this serial transport.
setTimeout() #
Set the read timeout.
- Parameters
-
Name Meaning timeoutMs Read timeout in milliseconds.
waitForConnection() #
Block until a host connects or the timeout expires.
- Parameters
-
Name Meaning timeoutMs Maximum time to wait in milliseconds. pollMs Polling interval in milliseconds.
- Return values
-
Value Meaning true A host connected within timeoutMs.false Timeout elapsed before a host connected.
write() [1/2] #
Write raw characters to the transport.
- Parameters
-
Name Meaning data Pointer to the characters to write. length Number of characters to write.
- Returns
- Number of characters actually written.
write() [2/2] #
Write raw bytes to the transport.
One call lands as one contiguous run on the wire: a write from another task waits for it rather than landing inside it, on both backends. Each backend feeds its driver in pieces no larger than half the driver's ring and holds the console's writer lock across them, so the run stays whole because of that lock: the USB-Serial-JTAG driver takes a run all at once or not at all and refuses outright any run longer than its ring.
- Parameters
-
Name Meaning data Pointer to the bytes to write. length Number of bytes to write.
- Returns
- Number of bytes actually written.
Variable Documentation
kLineStallPatienceMs #
How long a waiter tolerates a holder that places no byte at all before it writes anyway. Longer than the longest stall a holder sits through while it still means to finish its line: the video take gives a line up after half a second without progress, and asserts that it stays below this.