ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
board_periph_modem.h File Reference

Cellular AT-modem device model for ra8_emulator (attached to SCI7 UART). More...

#include <stdint.h>
Include dependency graph for board_periph_modem.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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.

Detailed Description

Cellular AT-modem device model for ra8_emulator (attached to SCI7 UART).

Models a 3GPP AT-command cellular modem (SIM7600 / Quectel BG95 class) wired to the EK-RA8D2 MikroBUS UART – RXD7 / TXD7, i.e. SCI channel 7 (k_ra8_board_mikrobus_uart_sci_channel). A MikroE cellular Click (LTE IoT / 4G LTE / NB-IoT) presents its modem UART on exactly these pads.

The model is transport-symmetric with board_periph_sd.c / board_periph_eink.c: it is attached with --modem and one seam ties it into the rest of the emulator. The SCI_B block model (board_periph_sci.c) routes every TDR byte the firmware writes on the modem channel into board_modem_feed_tx; the model accumulates a command line, and when the terminating \r arrives it answers with the exact bytes a real modem would send, which the SCI block pushes back into that channel's RX queue (RDR / RDRF). The genuine firmware path – ra8_modem_at over ra8_sci polled TX/RX – then runs byte for byte, so the modem_at_demo example brings the modem up, walks its AT state machine (sync / SIM / signal / registration / attach), dispatches a +CREG URC and exercises the +CME ERROR path with no physical modem (EIL == HIL for the protocol; the physical RF link is the only unmodelled part, hence the app is hw_pending).

The AT script answered here mirrors what the demo sends; an unrecognised command is rejected with +CME ERROR: 4 exactly as a modem with AT+CMEE=1 active would, so the demo's error branch is faithful too.

Since
0.1.0

Definition in file board_periph_modem.h.

Function Documentation

◆ board_modem_attach()

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.

Returns
true once the modem is armed and answering.
Return values
trueModem armed (always, on this in-memory model).
Precondition
Called once during ra8_emulator start-up (single-threaded arg parse).
No physical hardware is required.
Postcondition
board_modem_attached returns true.
The command accumulator and response FIFO are empty.
Note
Not thread-safe; ra8_emulator is single-threaded.
Since
0.1.0

Definition at line 150 of file board_periph_modem.c.

References board_modem_reset(), and s_modem.

Referenced by internal_args_try_mode().

◆ board_modem_attached()

bool board_modem_attached ( void )

Report whether the AT modem model is currently attached.

Returns
true if --modem armed the model.
Return values
falseNo --modem was passed.
Precondition
None.
None.
Postcondition
No state is modified.
No state is modified.
Note
Not thread-safe; ra8_emulator is single-threaded.
Since
0.1.0

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().

◆ board_modem_channel()

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.

Returns
The modem's SCI channel number (7).
Return values
7Always, for the EK-RA8D2 MikroBUS UART mapping.
Precondition
None.
None.
Postcondition
No state is modified.
No state is modified.
Since
0.1.0
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 162 of file board_periph_modem.c.

References k_modem_channel.

Referenced by internal_sci_reg_write().

◆ board_modem_feed_tx()

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.

Parameters
[in]txThe byte the firmware wrote to the modem-channel TDR.
[out]outDestination for any response bytes (may stay untouched).
[in]out_capCapacity of out in bytes.
Returns
Number of response bytes written to out (0 if none this byte).
Return values
0The byte was buffered; no complete line yet.
Precondition
out is non-null and points to at least out_cap bytes.
The model is attached (callers guard with board_modem_attached).
Postcondition
On a completed line out holds a full modem response (<= out_cap).
The command accumulator is reset after a completed line.
Note
Not thread-safe; ra8_emulator is single-threaded.
Since
0.1.0

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().

◆ board_modem_report()

void board_modem_report ( void )

Print a one-line end-of-run summary if the modem was exercised.

Precondition
None.
None.
Postcondition
One line is written to injected error sink iff at least one command was answered.
No state is modified.
Since
0.1.0

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.

Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 193 of file board_periph_modem.c.

References priv_emu_io_errf(), and s_modem.

Referenced by internal_sci_report().

◆ board_modem_reset()

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.

Precondition
None.
None.
Postcondition
The command accumulator is empty; the attached flag is unchanged.
Run counters (commands answered, errors) are retained.
Since
0.1.0
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 187 of file board_periph_modem.c.

References s_modem.

Referenced by board_modem_attach(), and internal_sci_reset().