|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Cellular modem AT command/response driver layered on UART. More...
Go to the source code of this file.
Data Structures | |
| struct | ra8_modem_at_io_t |
| Byte-level transport injected into the AT driver (DIP). More... | |
| struct | ra8_modem_at_cfg_t |
| Configuration handed to ra8_modem_at_init. More... | |
Typedefs | |
| typedef void(* | ra8_modem_at_urc_fn_t) (const char *line, void *ctx) |
| Unsolicited result-code (URC) handler signature. | |
Enumerations | |
| enum | ra8_modem_at_limits_t : uint8_t { k_ra8_modem_at_max_unsolicited = 8U , k_ra8_modem_at_max_prefix_len } |
| Compile-time tunables. More... | |
| enum | ra8_modem_at_timeouts_t : uint16_t { k_ra8_modem_at_default_timeout_ms = 1000U } |
| Default per-command timeout when caller passes 0 ms. More... | |
Functions | |
| ra8_err_t | ra8_modem_at_init (const ra8_modem_at_cfg_t *cfg) |
| Bind transport, buffer and timeout policy. | |
| ra8_err_t | ra8_modem_at_send_cmd (const char *cmd, const char *expected_response, uint16_t timeout_ms) |
| Send an AT command and wait for OK/ERROR/expected. | |
| ra8_err_t | ra8_modem_at_send_cmd_capture (const char *cmd, char *out_buf, size_t buf_len, uint16_t timeout_ms) |
| Send an AT command and capture the response payload. | |
| ra8_err_t | ra8_modem_at_register_unsolicited_handler (const char *prefix, ra8_modem_at_urc_fn_t fn, void *ctx) |
| Register a URC (unsolicited result code) handler. | |
| ra8_err_t | ra8_modem_at_poll (void) |
| Pump the RX path without sending a command. | |
Cellular modem AT command/response driver layered on UART.
Tiny AT-command transport for SIM7600 / Quectel BG95 / similar 3GPP modems. Sits on top of a UART-like byte transport and provides:
The line accumulator runs as:
Lines are accumulated byte-by-byte from the byte transport. CR/LF pairs split the stream into discrete lines. Each line is either
Anything else is treated as response payload and (optionally) captured into the user buffer.
NASA Power-of-10 Rule 3 compliant – zero dynamic allocation. The line accumulator buffer is owned by the caller and passed in via ra8_modem_at_cfg_t. Unsolicited-handler slots live in a fixed-size table inside the module.
Definition in file ra8_modem_at.h.
| typedef void(* ra8_modem_at_urc_fn_t) (const char *line, void *ctx) |
Unsolicited result-code (URC) handler signature.
| [in] | line | NUL-terminated full line received from the modem (e.g. "+CMTI: \"SM\\",3\"). |
| [in] | ctx | Opaque pointer registered with the handler. |
Definition at line 168 of file ra8_modem_at.h.
| enum ra8_modem_at_limits_t : uint8_t |
Compile-time tunables.
All limits are typed C23 enums so the compiler picks an exact width and the values appear by name in the debugger.
| Enumerator | |
|---|---|
| k_ra8_modem_at_max_unsolicited | Maximum number of registered URC handlers. |
| k_ra8_modem_at_max_prefix_len | Maximum bytes of a URC prefix (including + and :). |
Definition at line 81 of file ra8_modem_at.h.
| enum ra8_modem_at_timeouts_t : uint16_t |
Default per-command timeout when caller passes 0 ms.
| Enumerator | |
|---|---|
| k_ra8_modem_at_default_timeout_ms | RA8 modem at default timeout ms. |
Definition at line 90 of file ra8_modem_at.h.
|
nodiscard |
Bind transport, buffer and timeout policy.
Resets all internal state and copies cfg into module-static storage. Must be called once before any other API. Re-calling is legal – previous URC handlers are cleared.
| [in] | cfg | Pointer to a fully populated configuration. |
| k_ra8_ok | Initialized successfully. |
| k_ra8_err_null_ptr | cfg, cfg->line_buf or any IO function pointer is NULL. |
| k_ra8_err_invalid_size | line_buf_len smaller than 16. |
Definition at line 821 of file ra8_modem_at.c.
References internal_clear_urc_table(), internal_reset_line(), internal_validate_init_cfg(), k_ra8_modem_at_state_idle, k_ra8_ok, and s_mod.
Referenced by modem_bind().
|
nodiscard |
Pump the RX path without sending a command.
Drains any queued bytes, dispatches URC handlers, and returns. Useful when the application is otherwise idle but wants to service unsolicited modem traffic. Does not block beyond a single drain pass.
| k_ra8_ok | Drain completed. |
| k_ra8_err_not_initialized | Module not initialized. |
Definition at line 974 of file ra8_modem_at.c.
References internal_accumulate(), k_ra8_err_not_initialized, k_ra8_ok, priv_modem_classify(), and s_mod.
Referenced by modem_phase_registration().
|
nodiscard |
Register a URC (unsolicited result code) handler.
Whenever the line accumulator emits a complete line that starts with prefix and the driver is not currently expecting that prefix as a command response, fn(line, ctx) is invoked. Registration order is preserved, but only one handler per distinct prefix is permitted – duplicate registration replaces the previous handler.
| [in] | prefix | NUL-terminated prefix string (e.g. "+CMTI:"). Must be shorter than k_ra8_modem_at_max_prefix_len. |
| [in] | fn | Handler function (must be non-NULL). |
| [in] | ctx | Opaque pointer passed to fn on every match. |
| k_ra8_ok | Handler installed (or replaced). |
| k_ra8_err_null_ptr | prefix or fn NULL. |
| k_ra8_err_invalid_size | prefix too long or empty. |
| k_ra8_err_no_mem | Handler table full. |
| k_ra8_err_not_initialized | Module not initialized. |
Definition at line 952 of file ra8_modem_at.c.
References internal_urc_insert(), internal_urc_replace(), k_ra8_err_invalid_size, k_ra8_err_no_mem, k_ra8_err_not_initialized, k_ra8_modem_at_max_prefix_len, k_ra8_ok, priv_modem_str_len(), RA8_CHECK_NULL_PTR, RA8_MODEM_AT_TAG, and s_mod.
Referenced by modem_bind().
|
nodiscard |
Send an AT command and wait for OK/ERROR/expected.
Writes cmd followed by "\r" byte-by-byte through io.tx_byte, then drives the line accumulator until either:
| [in] | cmd | NUL-terminated AT command without the trailing "\r". |
| [in] | expected_response | Optional NUL-terminated prefix to wait for (e.g. "+CSQ:"). May be NULL when only OK matters. |
| [in] | timeout_ms | Per-command timeout in ms. 0 selects the configured default. |
| k_ra8_ok | Final OK (and expected, if set) seen. |
| k_ra8_err_null_ptr | cmd was NULL. |
| k_ra8_err_not_initialized | ra8_modem_at_init not yet called. |
| k_ra8_err_hw_error | Modem replied ERROR/+CME ERROR. |
| k_ra8_err_hw_timeout | No final result code in time. |
Definition at line 836 of file ra8_modem_at.c.
References internal_effective_timeout(), internal_reset_line(), internal_tx_command(), internal_wait_response(), k_ra8_err_not_initialized, k_ra8_ok, RA8_CHECK_NULL_PTR, RA8_MODEM_AT_TAG, and s_mod.
Referenced by modem_cmd_ok().
|
nodiscard |
Send an AT command and capture the response payload.
Identical wait policy to ra8_modem_at_send_cmd but every non-echo, non-final-result, non-URC line is appended to out_buf with '\n' separators. Truncation past buf_len - 1 bytes is silent; the buffer is always NUL-terminated.
| [in] | cmd | NUL-terminated AT command (no trailing CR). |
| [out] | out_buf | Caller buffer for captured payload. |
| [in] | buf_len | Bytes in out_buf (>= 1). |
| [in] | timeout_ms | Per-command timeout in ms (0 -> default). |
| k_ra8_ok | Command finished with OK. |
| k_ra8_err_null_ptr | cmd or out_buf NULL. |
| k_ra8_err_invalid_size | buf_len is 0. |
| k_ra8_err_not_initialized | ra8_modem_at_init not called. |
| k_ra8_err_hw_error | Modem replied ERROR. |
| k_ra8_err_hw_timeout | No final result code in time. |
Definition at line 856 of file ra8_modem_at.c.
References internal_effective_timeout(), internal_reset_line(), internal_tx_command(), internal_wait_response(), k_ra8_err_invalid_size, k_ra8_err_not_initialized, k_ra8_ok, RA8_CHECK_NULL_PTR, RA8_MODEM_AT_TAG, and s_mod.
Referenced by modem_query().