|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Cellular AT-modem device model for ra8_emulator (attached to SCI7). More...
#include "board_periph_modem.h"#include <stdint.h>#include <stdio.h>#include <string.h>#include "emu_host_io_internal.h"Go to the source code of this file.
Data Structures | |
| struct | modem_reply_t |
| One scripted (command -> response) pair. More... | |
| struct | modem_model_t |
| The modelled modem's whole state. More... | |
Enumerations | |
| enum | modem_geom_t : uint32_t { k_modem_channel = 7U , k_modem_cmd_cap = 64U , k_modem_resp_cap = 96U , k_modem_cr = 13U , k_modem_lf = 10U } |
| Sizing constants for the modem line model (no magic numbers). More... | |
Functions | |
| static RA8_INTERNAL uint32_t | internal_modem_emit (const char *resp, uint8_t *out, uint32_t out_cap) |
Copy a NUL-terminated response into out, bounded by out_cap. | |
| static RA8_INTERNAL uint32_t | internal_modem_answer_line (uint8_t *out, uint32_t out_cap) |
Answer the completed command line in s_modem.cmd. | |
| bool | board_modem_attach (void) |
| Attach (arm) the modelled AT cellular modem. | |
| bool | board_modem_attached (void) |
| Report whether the AT modem model is currently attached. | |
| uint8_t | board_modem_channel (void) |
| SCI channel the modem is wired to (RXD7 / TXD7 = SCI7). | |
| uint32_t | board_modem_feed_tx (uint8_t tx, uint8_t *out, uint32_t out_cap) |
| Feed one firmware-transmitted byte into the modem and drain a reply. | |
| void | board_modem_reset (void) |
| Clear the modem's parser state (keeps the attached flag). | |
| void | board_modem_report (void) |
| Print a one-line end-of-run summary if the modem was exercised. | |
Variables | |
| static const modem_reply_t | s_k_modem_script [] |
| The AT script the modelled modem answers. | |
| static const char | s_k_modem_cme_error [] = "\r\n+CME ERROR: 4\r\n" |
| Response for a command not present in s_k_modem_script. | |
| static modem_model_t | s_modem |
| The single modelled modem. | |
Cellular AT-modem device model for ra8_emulator (attached to SCI7).
Implements board_periph_modem.h. The modem is a line state machine on the SCI7 UART: it accumulates the bytes the ra8_modem_at driver clocks out one at a time (each a TDR write the SCI_B block routes here), and when the terminating \r arrives it answers with the exact byte stream a real SIM7600 / BG95-class modem would send. The SCI_B block pushes that stream back into the channel's RX queue (RDR / RDRF), so the firmware's genuine polled ra8_sci_getc_polling path drains it exactly as on silicon (EIL == HIL for the AT protocol).
The AT script answered here mirrors the modem_at_demo example. An unrecognised command is rejected with +CME ERROR: 4 ("operation not supported") exactly as a modem with AT+CMEE=1 active would, so the demo's error branch is faithful. AT+CREG=1 (enable registration URCs) answers OK and then stages an unsolicited +CREG: 1 so the demo's URC dispatch fires, matching a modem reporting its current registration on enable.
Self-registers nothing with the peripheral core – it is a pure device model the SCI_B block calls into (attach / attached / channel / feed_tx / reset / report), the same shape as board_periph_sd.c and board_periph_eink.c.
Definition in file board_periph_modem.c.
| enum modem_geom_t : uint32_t |
Sizing constants for the modem line model (no magic numbers).
Definition at line 43 of file board_periph_modem.c.
| bool board_modem_attach | ( | void | ) |
Attach (arm) the modelled AT cellular modem.
Sets the module's armed flag so board_modem_attached returns true and the SCI_B block routes the modem channel's TDR writes into board_modem_feed_tx. Idempotent: a second call re-arms and clears the parser state.
| true | Modem armed (always, on this in-memory model). |
Definition at line 150 of file board_periph_modem.c.
References board_modem_reset(), and s_modem.
Referenced by internal_args_try_mode().
| bool board_modem_attached | ( | void | ) |
Report whether the AT modem model is currently attached.
| false | No --modem was passed. |
Report whether the at modem model is currently attached; this step is contained within the board periph modem model and uses bounded caller or module-owned storage.
Definition at line 157 of file board_periph_modem.c.
References s_modem.
Referenced by internal_sci_reg_write().
| uint8_t board_modem_channel | ( | void | ) |
SCI channel the modem is wired to (RXD7 / TXD7 = SCI7).
Matches k_ra8_board_mikrobus_uart_sci_channel on the firmware side so the SCI_B block routes only that channel's bytes into the model.
| 7 | Always, for the EK-RA8D2 MikroBUS UART mapping. |
Definition at line 162 of file board_periph_modem.c.
References k_modem_channel.
Referenced by internal_sci_reg_write().
| uint32_t board_modem_feed_tx | ( | uint8_t | tx, |
| uint8_t * | out, | ||
| uint32_t | out_cap ) |
Feed one firmware-transmitted byte into the modem and drain a reply.
Appends tx to the command-line accumulator. Most bytes buffer silently and return 0; the terminating \r closes the line, looks up the scripted response for that AT command, copies it into out (bounded by out_cap) and returns its length. An unrecognised command yields +CME ERROR: 4. A command whose response also stages an unsolicited +CREG URC (the AT+CREG=1 enable) appends that URC after the OK so the demo's ra8_modem_at_poll dispatch fires exactly as on silicon.
| [in] | tx | The byte the firmware wrote to the modem-channel TDR. |
| [out] | out | Destination for any response bytes (may stay untouched). |
| [in] | out_cap | Capacity of out in bytes. |
out (0 if none this byte). | 0 | The byte was buffered; no complete line yet. |
out is non-null and points to at least out_cap bytes. out holds a full modem response (<= out_cap). Definition at line 167 of file board_periph_modem.c.
References internal_modem_answer_line(), k_modem_cmd_cap, k_modem_cr, k_modem_lf, and s_modem.
Referenced by internal_sci_reg_write().
| void board_modem_report | ( | void | ) |
Print a one-line end-of-run summary if the modem was exercised.
Print a one-line end-of-run summary if the modem was exercised; this step is contained within the board periph modem model and uses bounded caller or module-owned storage.
Definition at line 193 of file board_periph_modem.c.
References priv_emu_io_errf(), and s_modem.
Referenced by internal_sci_report().
| void board_modem_reset | ( | void | ) |
Clear the modem's parser state (keeps the attached flag).
Called from the SCI block reset so a mid-run reset re-frames the command accumulator without detaching the modem (the SCI reset re-frames transport, not the modem's presence). Run counters are retained for the end-of-run report.
Definition at line 187 of file board_periph_modem.c.
References s_modem.
Referenced by board_modem_attach(), and internal_sci_reset().
|
static |
Answer the completed command line in s_modem.cmd.
| [out] | out | Destination for the response bytes. |
| [in] | out_cap | Capacity of out in bytes. |
Answer the completed command line in s_modem.cmd; this step is contained within the board periph modem model and uses bounded caller or module-owned storage.
| value | The operation-specific modem answer line value. |
Definition at line 136 of file board_periph_modem.c.
References internal_modem_emit(), RA8_INTERNAL, s_k_modem_cme_error, s_k_modem_script, s_modem, and strcmp().
Referenced by board_modem_feed_tx().
|
static |
Copy a NUL-terminated response into out, bounded by out_cap.
| [in] | resp | NUL-terminated response string. |
| [out] | out | Destination buffer. |
| [in] | out_cap | Capacity of out in bytes. |
out_cap).Copy a nul-terminated response into out, bounded by out_cap; this step is contained within the board periph modem model and uses bounded caller or module-owned storage.
| value | The operation-specific modem emit value. |
Definition at line 113 of file board_periph_modem.c.
References RA8_INTERNAL.
Referenced by internal_modem_answer_line().
|
static |
Response for a command not present in s_k_modem_script.
Definition at line 82 of file board_periph_modem.c.
Referenced by internal_modem_answer_line().
|
static |
The AT script the modelled modem answers.
Responses are framed the way a real modem frames them: a leading \r\n, the payload line(s), a blank line, then the final OK. AT+CREG=1 additionally stages an unsolicited +CREG: 1 after its OK (the modem reporting current registration once URCs are enabled). Any command not in this table falls through to +CME ERROR: 4.
Definition at line 70 of file board_periph_modem.c.
Referenced by internal_modem_answer_line().
|
static |
The single modelled modem.
Definition at line 97 of file board_periph_modem.c.
Referenced by board_modem_attach(), board_modem_attached(), board_modem_feed_tx(), board_modem_report(), board_modem_reset(), and internal_modem_answer_line().