70typedef enum : uint32_t {
80typedef enum : uint16_t {
85typedef enum : uint32_t {
92typedef enum : uint8_t {
99typedef enum : uint8_t {
109typedef enum : uint8_t {
252modem_run_ok(
bool sim_ready,
bool signal_ok,
bool registered,
bool attached,
bool cme_ok)
254 return sim_ready && signal_ok && registered && attached && cme_ok;
284 if ((line ==
nullptr) || (out ==
nullptr)) {
288 while ((i < (uint32_t)
k_modem_scan_max) && (line[i] !=
'\0') && (line[i] !=
':')) {
298 if ((i >= (uint32_t)
k_modem_scan_max) || (line[i] <
'0') || (line[i] >
'9')) {
302 while ((i < (uint32_t)
k_modem_scan_max) && (line[i] >=
'0') && (line[i] <=
'9')) {
333 if ((line ==
nullptr) || (out ==
nullptr)) {
340 if ((line[i] >=
'0') && (line[i] <=
'9')) {
342 while ((i < (uint32_t)
k_modem_scan_max) && (line[i] >=
'0') && (line[i] <=
'9')) {
375 if ((line ==
nullptr) || (needle ==
nullptr)) {
378 for (uint32_t i = 0U; (i < (uint32_t)
k_modem_scan_max) && (line[i] !=
'\0'); i++) {
380 while ((j < (uint32_t)
k_modem_scan_max) && (needle[j] !=
'\0') && (line[i + j] == needle[j])) {
383 if (needle[j] ==
'\0') {
415 tmp[n] = (uint8_t)
'0';
424 for (uint32_t i = 0U; i < n; i++) {
425 out[i] = tmp[n - 1U - i];
443static void modem_tx(
const uint8_t* bytes, uint32_t len)
462static void modem_emit_kv(
const uint8_t* label, uint32_t label_len, uint32_t value)
514 if (line ==
nullptr) {
539 __asm__
volatile(
"wfi");
557 uint32_t cpuclk0_hz = 0U;
588 "modem_at_demo.txd7") !=
k_ra8_ok) {
593 "modem_at_demo.rxd7") !=
k_ra8_ok) {
609 uint32_t pclka_hz = 0U;
658 .line_buf = line_buf,
659 .line_buf_len = line_buf_len,
719static void modem_fail(
const uint8_t* step, uint32_t step_len)
721 static const uint8_t k_pfx[] =
"modem: ";
722 static const uint8_t k_sfx[] =
" FAIL\r\n";
723 modem_tx(k_pfx, (uint32_t)(
sizeof(k_pfx) - 1U));
725 modem_tx(k_sfx, (uint32_t)(
sizeof(k_sfx) - 1U));
748 static const uint8_t k_step[] =
"sync";
750 modem_fail(k_step, (uint32_t)(
sizeof(k_step) - 1U));
753 modem_fail(k_step, (uint32_t)(
sizeof(k_step) - 1U));
756 modem_fail(k_step, (uint32_t)(
sizeof(k_step) - 1U));
775 static const uint8_t k_step[] =
"cpin";
778 modem_fail(k_step, (uint32_t)(
sizeof(k_step) - 1U));
797 static const uint8_t k_step[] =
"csq";
800 modem_fail(k_step, (uint32_t)(
sizeof(k_step) - 1U));
822 static const uint8_t k_step[] =
"creg";
824 modem_fail(k_step, (uint32_t)(
sizeof(k_step) - 1U));
829 modem_fail(k_step, (uint32_t)(
sizeof(k_step) - 1U));
848 static const uint8_t k_step[] =
"cgatt";
851 modem_fail(k_step, (uint32_t)(
sizeof(k_step) - 1U));
898 static const uint8_t k_step[] =
"init";
899 modem_fail(k_step, (uint32_t)(
sizeof(k_step) - 1U));
910 const bool ok =
modem_run_ok(sim_ready, signal_ok, registered, attached, cme_ok);
void main(void)
Secure fallback main entry point.
static ra8_err_t modem_tx_byte(void *ctx, uint8_t byte)
static bool modem_run_ok(bool sim_ready, bool signal_ok, bool registered, bool attached, bool cme_ok)
Overall run verdict: every probed condition must hold.
static bool modem_phase_error(void)
Error-path phase: send an unsupported command, expect +CME ERROR.
static bool modem_parse_first_uint(const char *line, uint32_t *out)
Parse the first unsigned integer after the : in an AT reply line.
static bool s_creg_seen
True once at least one +CREG line has been parsed.
static uint32_t modem_now_ms(void *ctx)
static const uint8_t k_modem_str_no[]
static bool modem_phase_sim(void)
SIM phase: query AT+CPIN? and confirm READY.
modem_csq_t
CSQ (signal-quality) sentinels: RSSI range 0..31, 99 = unknown.
@ k_modem_csq_min_bars
Minimum RSSI treated as a usable signal.
@ k_modem_csq_unknown
CSQ "not known / not detectable".
@ k_modem_csq_max
Highest valid CSQ RSSI index.
static bool modem_line_contains(const char *line, const char *needle)
Does line contain the substring needle?
static const uint8_t k_modem_str_attach[]
static void modem_fail(const uint8_t *step, uint32_t step_len)
Print a modem: <step> FAIL banner, latch LED2, and park.
static void modem_panic_halt(void)
Park forever after a fatal error.
static const uint8_t k_modem_str_reg[]
static uint8_t s_creg_stat
Latest registration status parsed from a +CREG line.
modem_timeout_t
Per-command timeout handed to ra8_modem_at (ms).
@ k_modem_cmd_timeout_ms
Modem cmd timeout ms.
static void modem_phase_sync(void)
Sync phase: probe (AT), disable echo (ATE0), numeric CME errors.
static bool modem_signal_valid(uint32_t rssi)
Is a CSQ RSSI reading a known, usable signal?
static const uint8_t k_modem_str_ok[]
static const uint8_t k_modem_str_cme[]
modem_const_t
App-wide numeric tunables (typed enum – no magic numbers).
@ k_modem_heartbeat_ms
LED heartbeat period after PASS.
@ k_modem_baud
SIM7600/BG95 default line rate.
@ k_modem_dec_base
Radix for integer-to-ASCII.
@ k_modem_console_baud
J-Link OB VCOM console line rate.
@ k_modem_uart_channel
SCI7.
static bool modem_step_passed(bool is_cme_probe, ra8_err_t err)
Did an AT step return the outcome the app expected?
modem_cgatt_t
CGATT PS-attach flag values.
@ k_modem_cgatt_attached
Attached to the PS domain.
@ k_modem_cgatt_detached
Not attached to the PS domain.
static void modem_on_creg_urc(const char *line, void *ctx)
URC handler for unsolicited + solicited +CREG lines.
static ra8_err_t modem_cmd_ok(const char *cmd)
Send an AT command and require a bare OK.
static uint32_t modem_u32_to_dec(uint32_t value, uint8_t *out)
Convert an unsigned 32-bit int into a decimal ASCII string.
static void modem_setup_or_halt(void)
Bring CGC + console (SCI8) + modem UART (SCI7) + LEDs up.
static bool modem_creg_registered(uint32_t stat)
Is the modem registered on a network (home or roaming)?
static bool modem_phase_signal(uint32_t *out_rssi)
Signal phase: query AT+CSQ and parse + print the RSSI.
static ra8_err_t modem_rx_byte(void *ctx, uint8_t *out_byte)
static bool modem_parse_last_uint(const char *line, uint32_t *out)
Parse the LAST unsigned integer anywhere in an AT reply line.
static void modem_emit_kv(const uint8_t *label, uint32_t label_len, uint32_t value)
Emit a labelled unsigned integer: <label><value>.
static void modem_clocks_or_halt(uint32_t *out_pclka_hz)
Bring CGC + SysTick + MSTP up; publish PCLKA via out_pclka_hz.
static bool modem_phase_attach(void)
Attach phase: query AT+CGATT? and parse + print the flag.
static void modem_pfs_or_halt(void)
Route the MikroBUS UART pins (TXD7 / RXD7) via PFS.
static ra8_err_t modem_query(const char *cmd, char *buf, size_t cap)
Send an AT query and capture its response payload.
static void modem_tx(const uint8_t *bytes, uint32_t len)
Emit a byte run on the J-Link OB VCOM console (SCI8).
static const uint8_t k_modem_str_pass[]
static const uint8_t k_modem_str_fail[]
static bool modem_phase_registration(void)
Registration phase: enable +CREG URCs, poll one, then query.
static ra8_err_t modem_bind(uint8_t *line_buf, uint16_t line_buf_len)
Bind ra8_modem_at to the SCI7 transport + register the URC handler.
static const uint8_t k_modem_banner_prefix[]
modem_creg_stat_t
+CREG registration-status codes (3GPP 27.007).
@ k_modem_creg_home
Registered, home network.
@ k_modem_creg_roaming
Registered, roaming.
@ k_modem_creg_denied
Registration denied.
@ k_modem_creg_unknown
Unknown (e.g.
@ k_modem_creg_searching
Not registered, searching.
@ k_modem_creg_not_registered
Not registered, not searching.
modem_cap_t
Small fixed buffer capacities.
@ k_modem_capture_cap
Capture buffer for one response payload.
@ k_modem_scan_max
Static bound for every line-scan loop.
@ k_modem_dec_cap
Digits for a uint32_t decimal (+ slack).
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
@ k_ra8_board_mikrobus_uart_sci_channel
P808/P809 -> RXD7/TXD7 = SCI7 (SW4-4 ON).
ra8_err_t ra8_board_led_toggle(ra8_board_led_id_t led)
Toggle led's output state.
ra8_err_t ra8_board_led_init(ra8_board_led_id_t led)
Configure led as a digital output, initial level low (off).
ra8_err_t ra8_board_led_on(ra8_board_led_id_t led)
Drive led HIGH (light it).
@ k_ra8_board_mikrobus_rx
J22.3 RX – UART RX (RXD7, SW4-4 ON).
@ k_ra8_board_mikrobus_tx
J22.4 TX – UART TX (TXD7, SW4-4 ON).
@ k_ra8_board_led2
LED2, GREEN, P303 (jumper E26).
@ k_ra8_board_led1
LED1, BLUE, P600 (jumper E27).
ra8_err_t ra8_board_uart_console_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
ra8_err_t ra8_board_uart_console_init(uint32_t baud)
Configure SCI8 + PD02/PD03 as the debug-console UART.
Boot entry points shared between a vector table and its startup code.
High-level Clock Generation Circuit driver.
ra8_err_t ra8_cgc_get_clock_hz(ra8_clock_id_t id, uint32_t *out_hz)
Query the current frequency of a clock-tree domain.
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
@ k_ra8_clock_id_pclka
PCLKA.
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_hw_error
Generic hardware fault detected (error flag set, fault interrupt).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
PSEL codes for peripheral pin routing on the RA8D2.
@ k_ra8_psel_sci_async
00100b: SCI async serial (UART).
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Cellular modem AT command/response driver layered on UART.
ra8_err_t ra8_modem_at_poll(void)
Pump the RX path without sending a command.
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_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_init(const ra8_modem_at_cfg_t *cfg)
Bind transport, buffer and timeout policy.
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_init(void)
Re-establish the ra8_mstp ref-count table from current hardware state.
ra8_port_pin_t
Packed (port << 8) | pin pin identifier.
High-level GPIO helpers on top of the PORT + PFS register layer.
ra8_err_t ra8_pfs_route_peripheral(ra8_port_pin_t pin, ra8_psel_t psel, const char *owner)
Route a pin to a non-IRQ peripheral function via PFS.PSEL.
Full-featured Serial Communications Interface driver.
@ k_ra8_sci_stop_1
RA8 SCI stop 1.
@ k_ra8_sci_parity_none
RA8 SCI parity none.
ra8_err_t ra8_sci_init(uint8_t channel, const ra8_sci_cfg_t *cfg)
Initialise an SCI channel using the descriptor.
ra8_err_t ra8_sci_getc_polling(uint8_t channel, uint8_t *out_byte)
Poll-receive one byte (blocking, bounded spin).
@ k_ra8_sci_data_8
RA8 SCI data 8.
ra8_err_t ra8_sci_putc_polling(uint8_t channel, uint8_t byte)
Poll-send one byte (blocking, bounded by ra8_hw_err spin budget).
SysTick-based tick counter, delay and timestamp helpers.
ra8_err_t ra8_time_init(uint32_t cpu_hz)
Initialise SysTick for a 1 kHz tick interrupt.
void ra8_delay_ms(uint32_t ms)
Busy-wait for at least ms milliseconds.
uint32_t ra8_now_ms(void)
Short-form alias for ra8_time_ms().
Configuration handed to ra8_modem_at_init.
Configuration descriptor for ra8_sci_init.