Serial I/O with stdio defaults and weak functions on CMSIS boards. More...
Macros | |
| #define | MCP_SERIAL_EOF (-1) |
| Read hook result: input closed or unrecoverable input error. | |
| #define | MCP_SERIAL_NO_DATA (-2) |
| Read hook result: no byte available yet; preserve the partial line. | |
| #define | MCP_SERIAL_INPUT_LOST (-3) |
| Read hook result: RX data lost; discard through the next delimiter. | |
Functions | |
| int | mcp_serial_transport_init (void) |
| Initialize the transport (weak default on CMSIS boards). | |
| void | mcp_serial_transport_close (void) |
| Release transport resources (weak default on CMSIS boards). | |
| int | mcp_serial_getchar (void) |
| Obtain one input byte (weak default on CMSIS boards). | |
| void | mcp_serial_send (const char *json, int channel) |
| Synchronous sender (weak default on CMSIS boards). | |
| int | init_serial (void) |
| Reset line-buffer state and call mcp_serial_transport_init(). | |
| int | process_serial (void) |
| Consume input until one line is processed, RX is empty or EOF occurs. | |
| void | end_serial (void) |
| Reset line-buffer state and call mcp_serial_transport_close(). | |
Serial I/O with stdio defaults and weak functions on CMSIS boards.
On boards, the defaults use CMSIS __WEAK from cmsis_compiler.h. Define any mcp_serial_* hook below with the same signature in an application source file to replace it. Do not add a weak annotation to the overrides. On Linux, macOS and Windows the defaults are ordinary functions and use stdio only. Defaults use standard C stdio, not POSIX APIs; no heap or atomic operations are required. Calls are foreground-only, single-threaded and synchronous. dispatch() and the default sender of dispatch_with_sender() use mcp_serial_send(), including when the optional input loop is disabled.
| #define MCP_SERIAL_EOF (-1) |
Read hook result: input closed or unrecoverable input error.
| #define MCP_SERIAL_INPUT_LOST (-3) |
Read hook result: RX data lost; discard through the next delimiter.
| #define MCP_SERIAL_NO_DATA (-2) |
Read hook result: no byte available yet; preserve the partial line.
| void end_serial | ( | void | ) |
Reset line-buffer state and call mcp_serial_transport_close().
Does not release registered tools/resources; use free_tools() too.
| int init_serial | ( | void | ) |
Reset line-buffer state and call mcp_serial_transport_init().
| int mcp_serial_getchar | ( | void | ) |
Obtain one input byte (weak default on CMSIS boards).
Default calls fgetc(stdin), blocking until input or EOF. Nonblocking implementations return MCP_SERIAL_NO_DATA instead of EOF when RX is empty.
| void mcp_serial_send | ( | const char * | json, |
| int | channel ) |
Synchronous sender (weak default on CMSIS boards).
| [in] | json | Borrowed null-terminated JSON without a delimiter; NULL means a notification, for which no JSON-RPC reply should be emitted. |
| [in] | channel | Opaque integer passed unchanged by the dispatcher. |
Default writes to stdout, appends LF and flushes; channel is ignored. Complete writes before returning, or copy into transport-owned storage. Do not retain the JSON pointer: the request arena is reset after this returns. An explicit dispatch_with_sender() callback takes precedence over this hook.
| void mcp_serial_transport_close | ( | void | ) |
Release transport resources (weak default on CMSIS boards).
Default does nothing and does not close stdin/stdout. Invoked by end_serial(); not by free_tools().
| int mcp_serial_transport_init | ( | void | ) |
Initialize the transport (weak default on CMSIS boards).
Default disables stdout buffering. Override if another interface needs setup. It is not implicitly called by dispatch().
| int process_serial | ( | void | ) |
Consume input until one line is processed, RX is empty or EOF occurs.
Uses a static C_MCP_SERIAL_LINE_SIZE buffer, with no request heap allocation. Preserves partial lines across calls; accepts LF, CR and CRLF. Discards oversized input, embedded null bytes and RX loss through the next delimiter. Reads at most 8192 bytes per call and dispatches at most one nonempty line. A final unterminated line is dispatched at EOF; the next call returns MCP_SERIAL_EOF. Applications decide whether EOF stops their main loop.