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

Board-support layer for the Renesas RA8P1 (R7KA8P1KFLCAC) target board. More...

#include <stddef.h>
#include <stdint.h>
#include "ra8_err.h"
#include "ra8_port_constants.h"
Include dependency graph for ra8_board_ra8p1.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ra8_board_info_t
 Snapshot of board identity strings. More...

Typedefs

typedef void(* ra8_board_sw_irq_cb_t) (void *ctx)
 Switch IRQ callback signature.

Enumerations

enum  ra8_board_led_id_t : uint8_t {
  k_ra8_board_led1 = 0U ,
  k_ra8_board_led2 = 1U ,
  k_ra8_board_led3 = 2U ,
  k_ra8_board_led_blue = k_ra8_board_led1 ,
  k_ra8_board_led_green = k_ra8_board_led2 ,
  k_ra8_board_led_red = k_ra8_board_led3 ,
  k_ra8_board_led_count = 3U
}
 Identifiers for the three user LEDs on the RA8P1 foundation board. More...
enum  ra8_board_sw_id_t : uint8_t {
  k_ra8_board_sw1 = 0U ,
  k_ra8_board_sw2 = 1U ,
  k_ra8_board_sw_count = 2U
}
 Identifiers for the on-board user push-buttons. More...
enum  ra8_board_sw_irq_t : uint8_t {
  k_ra8_board_sw1_irq = 13U ,
  k_ra8_board_sw2_irq = 12U
}
 Per-switch ICU IRQ channel numbers (provisional). More...
enum  ra8_board_sw_state_t : uint8_t {
  k_ra8_board_sw_released = 0U ,
  k_ra8_board_sw_pressed = 1U
}
 Logical "pressed" / "released" state of a user switch. More...
enum  ra8_board_uart_t : uint8_t { k_ra8_board_uart_console = 0U }
 Identifiers for board-routed UART consoles. More...
enum  ra8_board_uart_sci_channel_t : uint8_t { k_ra8_board_uart_console_sci_channel = 8U }
 SCI channel that backs k_ra8_board_uart_console (provisional). More...
enum  ra8_board_uart_console_pin_t : uint16_t {
  k_ra8_board_uart_console_pin_txd ,
  k_ra8_board_uart_console_pin_rxd ,
  k_ra8_board_uart_console_pin_rts ,
  k_ra8_board_uart_console_pin_cts
}
 Pin assignments for the debug VCOM console (provisional). More...

Functions

ra8_err_t ra8_board_get_info (ra8_board_info_t *out)
 Copy the three board-identity strings into out.
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).
ra8_err_t ra8_board_led_off (ra8_board_led_id_t led)
 Drive led LOW (extinguish it).
ra8_err_t ra8_board_led_toggle (ra8_board_led_id_t led)
 Toggle led's output state.
ra8_err_t ra8_board_led_pin (ra8_board_led_id_t led, ra8_port_pin_t *out_pin)
 Translate a board LED id into its underlying ra8_port_pin_t.
ra8_err_t ra8_board_sw_init (ra8_board_sw_id_t sw)
 Configure a switch pin as an input with internal pull-up.
ra8_err_t ra8_board_sw_read (ra8_board_sw_id_t sw, ra8_board_sw_state_t *out_pressed)
 Sample the current state of sw.
ra8_err_t ra8_board_sw_attach_irq (ra8_board_sw_id_t sw, ra8_board_sw_irq_cb_t cb, void *ctx)
 Wire sw to the ICU and register a falling-edge callback.
ra8_err_t ra8_board_sw_pin (ra8_board_sw_id_t sw, ra8_port_pin_t *out_pin)
 Translate a board switch id into its underlying ra8_port_pin_t.
ra8_err_t ra8_board_uart_console_init (uint32_t baud)
 Configure SCI8 + PD02/PD03 as the debug-console UART.
ra8_err_t ra8_board_uart_console_write (const uint8_t *data, size_t len)
 Polled blocking write to the debug VCOM console.
ra8_err_t ra8_board_uart_console_read (uint8_t *out, size_t cap, size_t *out_len)
 Polled non-blocking read from the debug VCOM console.
ra8_err_t ra8_board_uart_console_flush (void)
 Block until every byte queued on the console has clocked out.

Variables

const char *const k_ra8_board_name
 Human-readable strings identifying this BSP target.
const char *const k_ra8_board_doc_rev
 "R01UH1064EJ (chip HUM)".
const char *const k_ra8_board_mcu
 "R7KA8P1KFLCAC".

Detailed Description

Board-support layer for the Renesas RA8P1 (R7KA8P1KFLCAC) target board.

Tag
[Ring 5 / BSP] {World: S}

Focused board-support layer for the project's RA8P1 target board, the counterpart of libs/ra8_board_ek_ra8d2 for the RA8D2. It names the LEDs, user switches, and the debug UART console so application code can speak in board coordinates ("LED1", "SW1", "the console") instead of chip coordinates ("P600", "P009", "SCI8"). The public API is deliberately IDENTICAL to the EK-RA8D2 board's LED / switch / console surface so a foundation app is a pure board substitution (SOLID-L): only the #include changes, the calls do not.

Scope of this layer

This is a FOUNDATION board layer, not the full EK-RA8D2 connector zoo. It carries only the LED / switch / console pieces the RA8P1 foundation apps (examples/ra8p1_foundation) exercise and the first bring-up needs. The EK-RA8D2-specific expansion connectors (parallel-RGB J1, Arduino, Pmod, MikroBUS, OSPI/SDHI/audio/camera/Ethernet) are board wiring particular to that evaluation kit and are intentionally absent here; a future RA8P1 board grows its own connector map from its own schematic.

Provisional pin map – TODO(EK-RA8P1 UM / ra8p1_kicad)

There is NO RA8P1 board in hand yet: the Renesas EK-RA8P1 User's Manual is not committed to docs/reference/ and the project's own RA8P1 PCB (ra8p1_kicad/) does not exist. The RA8P1 is pin-compatible with the RA8D2 in the same 289-pin BGA and register/pin-function-identical (see libs/ra8_core/inc/ra8_device.h and the RA8P1 HUM R01UH1064EJ), so the LED / switch / console pins below are PROVISIONALLY mirrored from the EK-RA8D2 layout: every pin is a valid GPIO / SCI alternate on the RA8P1 (chip HUM R01UH1064EJ Ch 20 "I/O Ports"). Each assignment carries a TODO(EK-RA8P1 UM / ra8p1_kicad) marker: the board-level "which LED sits on which pin" is a schematic decision that is re-derived, and re-cited to the board manual, once the RA8P1 board is defined and the first on-silicon bring-up runs. This layer builds and runs in ra8_emulator --device ra8p1 today; on-silicon validation is deferred to that board.

Underlying chip register access is delegated to libs/ra8_hal: the BSP itself does NO register pokes – it translates board names into the right ra8_port_pin_t / ra8_psel_t / ra8_icu_irq_cfg_t values and forwards to the HAL.

Since
0.1.0

Definition in file ra8_board_ra8p1.h.

Typedef Documentation

◆ ra8_board_sw_irq_cb_t

typedef void(* ra8_board_sw_irq_cb_t) (void *ctx)

Switch IRQ callback signature.

Parameters
[in,out]ctxOpaque context pointer passed at registration.

Definition at line 355 of file ra8_board_ra8p1.h.

Enumeration Type Documentation

◆ ra8_board_led_id_t

enum ra8_board_led_id_t : uint8_t

Identifiers for the three user LEDs on the RA8P1 foundation board.

PROVISIONAL pins mirrored from the EK-RA8D2 layout (P600 / P303 / PA07); all three are valid GPIO outputs on the pin-compatible RA8P1 (chip HUM R01UH1064EJ Ch 20 "I/O Ports"). All three are treated as active-high. TODO(EK-RA8P1 UM / ra8p1_kicad): confirm the LED-to-pin mapping and polarity against the RA8P1 board schematic once it exists.

Invariant
Enumerators are contiguous 0..k_ra8_board_led_count-1.
See also
ra8_board_led_init
Enumerator
k_ra8_board_led1 

LED1: provisional P600.

TODO(EK-RA8P1 UM / ra8p1_kicad).

k_ra8_board_led2 

LED2: provisional P303.

TODO(EK-RA8P1 UM / ra8p1_kicad).

k_ra8_board_led3 

LED3: provisional PA07.

TODO(EK-RA8P1 UM / ra8p1_kicad).

k_ra8_board_led_blue 

Convenience aliases by the EK-RA8D2 colour order (also provisional).

k_ra8_board_led_green 

RA8 board led green.

k_ra8_board_led_red 

RA8 board led red.

k_ra8_board_led_count 

Number of user LEDs.

Definition at line 147 of file ra8_board_ra8p1.h.

◆ ra8_board_sw_id_t

enum ra8_board_sw_id_t : uint8_t

Identifiers for the on-board user push-buttons.

PROVISIONAL pins mirrored from the EK-RA8D2 layout (SW1 -> P009, SW2 -> P008); both are valid IRQ-capable GPIO inputs on the pin-compatible RA8P1 (chip HUM R01UH1064EJ Ch 20 "I/O Ports"). Both are wired active-low. TODO(EK-RA8P1 UM / ra8p1_kicad): confirm the switch-to-pin mapping against the RA8P1 board schematic once it exists.

Invariant
Enumerators are contiguous 0..k_ra8_board_sw_count-1.
See also
ra8_board_sw_init
Enumerator
k_ra8_board_sw1 

SW1: provisional P009 (IRQ13).

TODO(EK-RA8P1 UM / ra8p1_kicad).

k_ra8_board_sw2 

SW2: provisional P008 (IRQ12).

TODO(EK-RA8P1 UM / ra8p1_kicad).

k_ra8_board_sw_count 

Number of user switches.

Definition at line 269 of file ra8_board_ra8p1.h.

◆ ra8_board_sw_irq_t

enum ra8_board_sw_irq_t : uint8_t

Per-switch ICU IRQ channel numbers (provisional).

SW1 -> IRQ13, SW2 -> IRQ12, mirrored from the EK-RA8D2 layout. Values are bare IRQ channel numbers usable with ra8_icu_configure_irq_pin. TODO(EK-RA8P1 UM / ra8p1_kicad): re-confirm the IRQ channel per pin.

Invariant
Each value is a valid ICU external-IRQ channel (0..31).
See also
ra8_board_sw_attach_irq
Enumerator
k_ra8_board_sw1_irq 

SW1 -> IRQ13.

TODO(EK-RA8P1 UM / ra8p1_kicad).

k_ra8_board_sw2_irq 

SW2 -> IRQ12.

TODO(EK-RA8P1 UM / ra8p1_kicad).

Definition at line 287 of file ra8_board_ra8p1.h.

◆ ra8_board_sw_state_t

enum ra8_board_sw_state_t : uint8_t

Logical "pressed" / "released" state of a user switch.

Invariant
Exactly one of the two values.
See also
ra8_board_sw_read
Enumerator
k_ra8_board_sw_released 

Button not held (pin high, active-low).

k_ra8_board_sw_pressed 

Button held (pin low, active-low).

Definition at line 299 of file ra8_board_ra8p1.h.

◆ ra8_board_uart_console_pin_t

Pin assignments for the debug VCOM console (provisional).

PD02 (TXD) / PD03 (RXD) are the always-wired console lines; PD04 (RTS) / PD05 (CTS) are the optional hardware-flow-control lines. Chip-coordinate names: P1302 / P1303 / P1304 / P1305 (port 13, pins 2..5). Mirrored from the EK-RA8D2 layout. TODO(EK-RA8P1 UM / ra8p1_kicad): confirm.

Invariant
Each value is a (port << 8) | pin encoding on port 13.
See also
ra8_board_uart_console_init
Enumerator
k_ra8_board_uart_console_pin_txd 

PD02 TXD (provisional).

k_ra8_board_uart_console_pin_rxd 

PD03 RXD (provisional).

k_ra8_board_uart_console_pin_rts 

PD04 RTS (provisional).

k_ra8_board_uart_console_pin_cts 

PD05 CTS (provisional).

Definition at line 460 of file ra8_board_ra8p1.h.

◆ ra8_board_uart_sci_channel_t

SCI channel that backs k_ra8_board_uart_console (provisional).

Exposed as a typed enum (not a macro) so applications reference the channel without re-encoding the number. Provisional value 8 (SCI8), mirrored from the EK-RA8D2 console. TODO(EK-RA8P1 UM / ra8p1_kicad): confirm.

Invariant
Value is a valid SCI channel index.
See also
ra8_board_uart_console_init
Enumerator
k_ra8_board_uart_console_sci_channel 

PD02/PD03 -> SCI8 (provisional).

Definition at line 443 of file ra8_board_ra8p1.h.

◆ ra8_board_uart_t

enum ra8_board_uart_t : uint8_t

Identifiers for board-routed UART consoles.

The RA8P1 foundation board exposes one debug console, provisionally routed exactly like the EK-RA8D2 J-Link OB VCOM bridge: PD02 (TXD) / PD03 (RXD) on SCI8. On the RA8P1 PD02/PD03 are the SCI8 TXD8/RXD8 alternate functions (chip HUM R01UH1064EJ Ch 20 "I/O Ports", Multiplexed Pin Function Selector). TODO(EK-RA8P1 UM / ra8p1_kicad): confirm the VCOM pins / SCI channel against the RA8P1 board schematic once it exists.

Invariant
Single enumerator (one console).
See also
ra8_board_uart_console_init
Enumerator
k_ra8_board_uart_console 

Debug VCOM console: provisional PD02/PD03 on SCI8.

Definition at line 427 of file ra8_board_ra8p1.h.

Function Documentation

◆ ra8_board_get_info()

ra8_err_t ra8_board_get_info ( ra8_board_info_t * out)
nodiscard

Copy the three board-identity strings into out.

Parameters
[out]outDestination struct, must be non-NULL.
Returns
ra8_err_t Error code.
Return values
k_ra8_okFilled.
k_ra8_err_invalid_argout == NULL.
Precondition
out is writable.
out has storage for three pointers.
Postcondition
On success out->name / doc_rev / mcu point at the global k_ra8_board_* strings.
On failure out is left unmodified.
Note
Not thread-safe with respect to nothing – pure copy of const globals.
See also
k_ra8_board_name
Since
0.1.0
Parameters
[out]outDestination struct, must be non-NULL.
Return values
k_ra8_okFilled.
k_ra8_err_invalid_argout == NULL.
Precondition
out is writable.
Postcondition
On success out->name / doc_rev / mcu point at the global k_ra8_board_* strings.
Since
0.1.0

Definition at line 50 of file ra8_board_ek_ra8d2.c.

References ra8_board_info_t::doc_rev, k_ra8_board_doc_rev, k_ra8_board_mcu, k_ra8_board_name, k_ra8_err_invalid_arg, k_ra8_ok, ra8_board_info_t::mcu, and ra8_board_info_t::name.

◆ ra8_board_led_init()

ra8_err_t ra8_board_led_init ( ra8_board_led_id_t led)
nodiscard

Configure led as a digital output, initial level low (off).

Parameters
[in]ledLED identifier (< k_ra8_board_led_count).
Returns
ra8_err_t Error code.
Return values
k_ra8_okPin claimed and driven low.
k_ra8_err_invalid_argled >= k_ra8_board_led_count.
k_ra8_err_gpio_conflictPin already owned.
Precondition
HAL pin validator initialized (single-threaded boot context).
led is a valid ra8_board_led_id_t enumerator.
Postcondition
On success the LED is off and its pin is a digital output.
On failure no pin state changes.
Note
Not thread-safe; call from the single boot / render context.
See also
ra8_board_led_on
Since
0.1.0
Return values
k_ra8_okPin claimed and driven low.
k_ra8_err_invalid_argled >= k_ra8_board_led_count.
k_ra8_err_gpio_conflictPin already owned.
Precondition
HAL pin validator initialized (single-threaded boot context).
Postcondition
LED is off and pin is configured as a digital output.
Since
0.1.0

Definition at line 91 of file ra8_board_ek_ra8d2.c.

References k_ra8_level_low, k_ra8_ok, k_ra8_pin_none, pin, ra8_board_led_pin(), and ra8_gpio_output_init().

◆ ra8_board_led_off()

ra8_err_t ra8_board_led_off ( ra8_board_led_id_t led)
nodiscard

Drive led LOW (extinguish it).

Parameters
[in]ledLED identifier (< k_ra8_board_led_count).
Returns
ra8_err_t Error code.
Return values
k_ra8_okOutput latch cleared.
k_ra8_err_invalid_argled out of range.
Precondition
ra8_board_led_init(led) succeeded.
led is a valid enumerator.
Postcondition
LED pin output latch == 0.
No other pin changes.
Note
Not thread-safe.
See also
ra8_board_led_on
Since
0.1.0
Return values
k_ra8_ok/ k_ra8_err_invalid_arg
Precondition
ra8_board_led_init(led) succeeded.
Postcondition
LED pin output latch == 0.

Definition at line 111 of file ra8_board_ek_ra8d2.c.

References k_ra8_level_low, k_ra8_ok, k_ra8_pin_none, pin, ra8_board_led_pin(), and ra8_gpio_write().

◆ ra8_board_led_on()

ra8_err_t ra8_board_led_on ( ra8_board_led_id_t led)
nodiscard

Drive led HIGH (light it).

Parameters
[in]ledLED identifier (< k_ra8_board_led_count).
Returns
ra8_err_t Error code.
Return values
k_ra8_okOutput latch set high.
k_ra8_err_invalid_argled out of range.
Precondition
ra8_board_led_init(led) succeeded.
led is a valid enumerator.
Postcondition
LED pin output latch == 1.
No other pin changes.
Note
Not thread-safe.
See also
ra8_board_led_off
Since
0.1.0
Return values
k_ra8_ok/ k_ra8_err_invalid_arg
Precondition
ra8_board_led_init(led) succeeded.
Postcondition
LED pin output latch == 1.

Definition at line 101 of file ra8_board_ek_ra8d2.c.

References k_ra8_level_high, k_ra8_ok, k_ra8_pin_none, pin, ra8_board_led_pin(), and ra8_gpio_write().

◆ ra8_board_led_pin()

ra8_err_t ra8_board_led_pin ( ra8_board_led_id_t led,
ra8_port_pin_t * out_pin )
nodiscard

Translate a board LED id into its underlying ra8_port_pin_t.

Parameters
[in]ledLED identifier (< k_ra8_board_led_count).
[out]out_pinDestination pin id; must be non-NULL.
Returns
ra8_err_t Error code.
Return values
k_ra8_ok*out_pin holds the mapped pin.
k_ra8_err_invalid_argled out of range or out_pin NULL.
Precondition
out_pin is writable.
led is a valid enumerator.
Postcondition
On success *out_pin is the provisional pin for led.
On failure *out_pin is unmodified.
Note
Pure lookup; ISR-safe.
See also
ra8_board_led_init
Since
0.1.0
Parameters
[in]ledLED identifier.
[out]out_pinDestination pin id.
Return values
k_ra8_ok/ k_ra8_err_invalid_arg
Since
0.1.0

Definition at line 79 of file ra8_board_ek_ra8d2.c.

References k_ra8_board_led_count, k_ra8_err_invalid_arg, k_ra8_ok, and s_led_pins.

Referenced by ra8_board_led_init(), ra8_board_led_off(), ra8_board_led_on(), and ra8_board_led_toggle().

◆ ra8_board_led_toggle()

ra8_err_t ra8_board_led_toggle ( ra8_board_led_id_t led)
nodiscard

Toggle led's output state.

Parameters
[in]ledLED identifier (< k_ra8_board_led_count).
Returns
ra8_err_t Error code.
Return values
k_ra8_okOutput latch inverted.
k_ra8_err_invalid_argled out of range.
Precondition
ra8_board_led_init(led) succeeded.
led is a valid enumerator.
Postcondition
LED pin output latch is inverted from its prior value.
No other pin changes.
Note
Not thread-safe.
See also
ra8_board_led_init
Since
0.1.0
Return values
k_ra8_ok/ k_ra8_err_invalid_arg
Precondition
ra8_board_led_init(led) succeeded.
Postcondition
LED pin output latch is inverted from its prior value.

Definition at line 121 of file ra8_board_ek_ra8d2.c.

References k_ra8_ok, k_ra8_pin_none, pin, ra8_board_led_pin(), and ra8_gpio_toggle().

◆ ra8_board_sw_attach_irq()

ra8_err_t ra8_board_sw_attach_irq ( ra8_board_sw_id_t sw,
ra8_board_sw_irq_cb_t cb,
void * ctx )
nodiscard

Wire sw to the ICU and register a falling-edge callback.

Buttons are active-low so a falling edge corresponds to a press. The HAL handles the PFS routing, IRQCR programming, and NVIC enable; this veneer hides the specific channel number from the caller.

Parameters
[in]swSwitch id (< k_ra8_board_sw_count).
[in]cbFalling-edge callback; must be non-NULL.
[in,out]ctxOpaque context forwarded to cb; may be NULL.
Returns
ra8_err_t Error code.
Return values
k_ra8_okIRQ wired and callback registered.
k_ra8_err_invalid_argsw out of range or cb NULL.
k_ra8_err_gpio_conflictUnderlying pin/IRQ already owned.
Precondition
ra8_icu_init() has been called once during boot.
cb is non-NULL.
Postcondition
On success pressing sw invokes cb(ctx) from the ICU ISR.
On failure no IRQ or NVIC line is enabled for sw.
Note
Not thread-safe.
See also
ra8_board_sw_init
Since
0.1.0

Buttons are active-low so a falling edge corresponds to a press. The HAL takes care of the PFS routing, IRQCR programming, and NVIC enable; this veneer just hides the specific channel number (UM Table 25) from the caller.

Return values
k_ra8_ok/ k_ra8_err_invalid_arg / k_ra8_err_gpio_conflict
Precondition
ra8_icu_init() has been called once during boot.
Postcondition
Pressing sw invokes cb(ctx) from the ICU ISR context.

Definition at line 196 of file ra8_board_ek_ra8d2.c.

References k_ra8_board_sw1, k_ra8_board_sw_count, k_ra8_elc_event_icu_irq12, k_ra8_elc_event_icu_irq13, k_ra8_err_invalid_arg, k_ra8_icu_fclksel_pclkb, k_ra8_icu_irqmd_falling, k_ra8_isr_prio_default, k_ra8_ok, ra8_icu_configure_irq_pin(), ra8_isr_register(), and s_sw_irq_nums.

◆ ra8_board_sw_init()

ra8_err_t ra8_board_sw_init ( ra8_board_sw_id_t sw)
nodiscard

Configure a switch pin as an input with internal pull-up.

Parameters
[in]swSwitch id (< k_ra8_board_sw_count).
Returns
ra8_err_t Error code.
Return values
k_ra8_okPin configured as pulled-up input.
k_ra8_err_invalid_argsw out of range.
k_ra8_err_gpio_conflictPin already owned.
Precondition
HAL pin validator initialized.
sw is a valid enumerator.
Postcondition
On success the pin is a digital input with pull-up enabled.
On failure no pin state changes.
Note
Not thread-safe.
See also
ra8_board_sw_read
Since
0.1.0
Return values
k_ra8_ok/ k_ra8_err_invalid_arg / k_ra8_err_gpio_conflict
Precondition
HAL pin validator initialized.
Postcondition
Pin is digital input, pull-up enabled.
Since
0.1.0

Definition at line 165 of file ra8_board_ek_ra8d2.c.

References k_ra8_ok, k_ra8_pin_none, k_ra8_pull_up, pin, ra8_board_sw_pin(), and ra8_gpio_input_init().

◆ ra8_board_sw_pin()

ra8_err_t ra8_board_sw_pin ( ra8_board_sw_id_t sw,
ra8_port_pin_t * out_pin )
nodiscard

Translate a board switch id into its underlying ra8_port_pin_t.

Parameters
[in]swSwitch id (< k_ra8_board_sw_count).
[out]out_pinDestination pin id; must be non-NULL.
Returns
ra8_err_t Error code.
Return values
k_ra8_ok*out_pin holds the mapped pin.
k_ra8_err_invalid_argsw out of range or out_pin NULL.
Precondition
out_pin is writable.
sw is a valid enumerator.
Postcondition
On success *out_pin is the provisional pin for sw.
On failure *out_pin is unmodified.
Note
Pure lookup; ISR-safe.
See also
ra8_board_sw_init
Since
0.1.0
0.1.0

Definition at line 153 of file ra8_board_ek_ra8d2.c.

References k_ra8_board_sw_count, k_ra8_err_invalid_arg, k_ra8_ok, and s_sw_pins.

Referenced by ra8_board_sw_init(), and ra8_board_sw_read().

◆ ra8_board_sw_read()

ra8_err_t ra8_board_sw_read ( ra8_board_sw_id_t sw,
ra8_board_sw_state_t * out_pressed )
nodiscard

Sample the current state of sw.

The buttons are wired active-low (a press shorts the pin to GND); this function inverts the level so callers receive a positive "pressed = true" semantic.

Parameters
[in]swSwitch id (< k_ra8_board_sw_count).
[out]out_pressedSet to one of {released, pressed}; must be non-NULL.
Returns
ra8_err_t Error code.
Return values
k_ra8_okRead complete.
k_ra8_err_invalid_argsw out of range or out_pressed NULL.
Precondition
ra8_board_sw_init(sw) succeeded.
out_pressed is writable.
Postcondition
On success *out_pressed is one of {released, pressed}.
On failure *out_pressed is unmodified.
Note
Not thread-safe.
See also
ra8_board_sw_init
Since
0.1.0

The buttons are wired active-low (press shorts the pin to GND); this function inverts the level so callers receive a positive "pressed = true" semantic.

Parameters
[in]swSwitch id.
[out]out_pressedSet to k_ra8_board_sw_pressed if held.
Return values
k_ra8_okRead complete.
k_ra8_err_invalid_argsw out of range or out_pressed NULL.
Precondition
ra8_board_sw_init(sw) succeeded.
Postcondition
*out_pressed is one of {released, pressed}.
Since
0.1.0

Definition at line 175 of file ra8_board_ek_ra8d2.c.

References k_ra8_board_sw_pressed, k_ra8_board_sw_released, k_ra8_err_invalid_arg, k_ra8_level_high, k_ra8_level_low, k_ra8_ok, k_ra8_pin_none, pin, ra8_board_sw_pin(), and ra8_gpio_read().

◆ ra8_board_uart_console_flush()

ra8_err_t ra8_board_uart_console_flush ( void )
nodiscard

Block until every byte queued on the console has clocked out.

Thin wrapper around ra8_sci_flush(k_ra8_board_uart_console_sci_channel) that polls the SCI8 transmit-complete status. Intended for a panic handler that must get its failure log to the host before WFI gates the SCI clock. The CSR.TEND register poke lives in ra8_sci_flush (HAL), which carries the HUM citation; this veneer touches no registers.

Returns
ra8_err_t Error code.
Return values
k_ra8_okTransmit complete (or fake stub).
k_ra8_err_not_initializedconsole_init not called.
k_ra8_err_hw_timeoutSpin budget elapsed without completion.
Precondition
ra8_board_uart_console_init succeeded.
The caller has previously written bytes to drain.
Postcondition
On success every prior console byte has been transmitted.
On failure the console state is unchanged.
Note
Not thread-safe with respect to a concurrent write.
See also
ra8_board_uart_console_write
Since
0.1.0

Block until every byte queued on the console has clocked out.

Thin wrapper around ra8_sci_flush(k_ra8_board_uart_console_sci_channel) that polls CSR.TEND on the SCI8 channel that backs the J-Link OB VCOM bridge (HUM Ch 38.2.17 "CSR : Common Status Register", p 2225). The intended caller is a panic-handler that needs the failure log to reach the host before WFI gates the SCI clock and silently drops the remaining FIFO contents.

Returns
ra8_err_t error code.
Return values
k_ra8_okTEND observed (or fake stub).
k_ra8_err_not_initializedra8_board_uart_console_init not called.
k_ra8_err_hw_timeoutSpin budget elapsed without TEND.
Precondition
ra8_board_uart_console_init succeeded.
Postcondition
On success, every byte previously passed to ra8_board_uart_console_write has been transmitted.
Note
Not thread-safe with respect to a concurrent ra8_board_uart_console_write – the writer may refill the shift register while the flush is polling.
See also
ra8_sci_flush
ra8_board_uart_console_write
Since
0.1.0

Definition at line 348 of file ra8_board_ek_ra8d2_comms.c.

References k_ra8_board_uart_console_sci_channel, k_ra8_err_not_initialized, ra8_sci_flush(), and s_uart_console_initialized.

◆ ra8_board_uart_console_init()

ra8_err_t ra8_board_uart_console_init ( uint32_t baud)
nodiscard

Configure SCI8 + PD02/PD03 as the debug-console UART.

Routes PD02 -> TXD8 and PD03 -> RXD8 (PSEL = SCI async) and brings SCI8 up via ra8_sci_init with 8N1 framing at the requested baud. The SCI module operating clock on the RA8P1 is PCLKA (byte-identical to the RA8D2 SCI_B); the BRR divisor is computed from the CURRENT PCLKA frequency reported by ra8_cgc_get_clock_hz, so callers MUST call ra8_cgc_init() before this.

Parameters
[in]baudTarget line rate in bps (e.g. 115200); must be non-zero.
Returns
ra8_err_t Error code.
Return values
k_ra8_okConsole up, ready to TX/RX.
k_ra8_err_invalid_argbaud == 0.
k_ra8_err_not_initializedCGC has not published a usable PCLKA yet.
k_ra8_err_gpio_conflictPD02 or PD03 already owned.
k_ra8_err_hw_init_failedUnderlying ra8_sci_init failed.
Precondition
HAL pin validator initialized (single-threaded boot context).
ra8_cgc_init() has run and PCLKA is post-PLL.
Postcondition
On success SCI8 is enabled (TE=RE=1) and PD02/PD03 route to SCI8.
On failure the console stays uninitialised and writes are refused.
Note
Not thread-safe; call once during board bring-up.
See also
ra8_board_uart_console_write
Since
0.1.0

Routes PD02 -> TXD8 and PD03 -> RXD8 (PSEL = SCI async) and brings SCI8 up via ra8_sci_init with 8N1 framing at the requested baud. The SCI module operating clock on RA8D2 is PCLKA (chip HUM Ch 38.2 "SCI registers"); the BRR divisor is computed from the current PCLKA frequency reported by ra8_cgc_get_clock_hz, so callers must call ra8_cgc_init() before ra8_board_uart_console_init. Applications that retune CGC afterwards must additionally call ra8_sci_set_baud((uint8_t)k_ra8_board_uart_console_sci_channel, baud, new_pclka_hz) to recompute the divisor.

Parameters
[in]baudTarget line rate in bps (e.g. 115200).
Return values
k_ra8_okConsole up, ready to TX/RX.
k_ra8_err_invalid_argbaud == 0.
k_ra8_err_not_initializedra8_cgc_init has not yet published a usable PCLKA value (chip still on MOCO / pre-PLL).
k_ra8_err_gpio_conflictPD02 or PD03 already owned.
k_ra8_err_hw_init_failedUnderlying ra8_sci_init failed.
Precondition
HAL pin validator initialized (single-threaded boot context).
ra8_cgc_init() has run and PCLKA is post-PLL.
ra8_mstp_init() has run.
Postcondition
SCI8 is enabled with TE=RE=1; PD02/PD03 are routed to SCI8.
BRR computed against the live PCLKA value (no hardcoded clock).
Note
Not thread-safe; call once during board bring-up.
Since
0.1.0

Definition at line 240 of file ra8_board_ek_ra8d2_comms.c.

References k_ra8_board_uart_console_min_pclka_hz, k_ra8_board_uart_console_pin_rxd, k_ra8_board_uart_console_pin_txd, k_ra8_board_uart_console_sci_channel, k_ra8_clock_id_pclka, k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_ok, k_ra8_psel_sci_async, k_ra8_sci_data_8, k_ra8_sci_parity_none, k_ra8_sci_stop_1, ra8_cgc_get_clock_hz(), ra8_pfs_route_peripheral(), ra8_sci_init(), and s_uart_console_initialized.

◆ ra8_board_uart_console_read()

ra8_err_t ra8_board_uart_console_read ( uint8_t * out,
size_t cap,
size_t * out_len )
nodiscard

Polled non-blocking read from the debug VCOM console.

Drains up to cap bytes from SCI8 RDR while data is available. Stops (without error) the first time the SCI reports no byte so the call never blocks waiting for a silent host.

Parameters
[out]outDestination buffer (non-NULL when cap > 0).
[in]capCapacity of out in bytes.
[out]out_lenNumber of bytes actually read; must be non-NULL.
Returns
ra8_err_t Error code.
Return values
k_ra8_okRead complete; *out_len in [0, cap].
k_ra8_err_invalid_argout / out_len NULL with non-zero cap.
k_ra8_err_not_initializedconsole_init not called.
Precondition
ra8_board_uart_console_init succeeded (for cap > 0).
out covers cap bytes.
Postcondition
On success 0 <= *out_len <= cap.
On failure *out_len is 0 (when writable).
Note
Not thread-safe.
See also
ra8_board_uart_console_write
Since
0.1.0

Polled non-blocking read from the debug VCOM console.

Drains up to cap bytes from SCI8 RDR while RDRF stays set. Stops (without error) the first time RDRF clears so the call never blocks waiting for a host that is silent.

Parameters
[out]outDestination buffer (non-NULL when cap > 0).
[in]capCapacity of out in bytes.
[out]out_lenNumber of bytes actually read; non-NULL.
Return values
k_ra8_okRead complete; *out_len in [0, cap].
k_ra8_err_invalid_argout / out_len NULL with non-zero cap.
k_ra8_err_not_initializedConsole not initialized.
Precondition
ra8_board_uart_console_init succeeded.
Postcondition
0 <= *out_len <= cap.
Since
0.1.0

Definition at line 308 of file ra8_board_ek_ra8d2_comms.c.

References k_ra8_board_uart_console_sci_channel, k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_ok, ra8_sci_getc_polling(), and s_uart_console_initialized.

◆ ra8_board_uart_console_write()

ra8_err_t ra8_board_uart_console_write ( const uint8_t * data,
size_t len )
nodiscard

Polled blocking write to the debug VCOM console.

Parameters
[in]dataBytes to transmit; must be non-NULL when len > 0.
[in]lenNumber of bytes in data.
Returns
ra8_err_t Error code.
Return values
k_ra8_okAll bytes pushed to the SCI8 TDR (or len 0).
k_ra8_err_invalid_argdata NULL with non-zero len.
k_ra8_err_not_initializedconsole_init not called.
Precondition
ra8_board_uart_console_init succeeded (for len > 0).
data covers len bytes.
Postcondition
On success all len bytes have been handed to the SCI8 TDR.
On failure no bytes are transmitted.
Note
Not thread-safe.
See also
ra8_board_uart_console_init
Since
0.1.0

Polled blocking write to the debug VCOM console.

Parameters
[in]dataBytes to transmit; must be non-NULL when len > 0.
[in]lenNumber of bytes in data.
Return values
k_ra8_okAll bytes pushed to TDR.
k_ra8_err_invalid_argdata NULL with non-zero len.
k_ra8_err_not_initializedra8_board_uart_console_init not called.
Precondition
ra8_board_uart_console_init succeeded.
Postcondition
All len bytes have been handed to the SCI8 TDR shift register.
Since
0.1.0

Definition at line 294 of file ra8_board_ek_ra8d2_comms.c.

References k_ra8_board_uart_console_sci_channel, k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_ok, ra8_sci_write_polling(), and s_uart_console_initialized.

Variable Documentation

◆ k_ra8_board_doc_rev

const char* const k_ra8_board_doc_rev
extern

"R01UH1064EJ (chip HUM)".

"R01UH1064EJ (chip HUM)".

Definition at line 47 of file ra8_board_ek_ra8d2.c.

◆ k_ra8_board_mcu

const char* const k_ra8_board_mcu
extern

"R7KA8P1KFLCAC".

"R7KA8P1KFLCAC".

Definition at line 48 of file ra8_board_ek_ra8d2.c.

◆ k_ra8_board_name

const char* const k_ra8_board_name
extern

Human-readable strings identifying this BSP target.

Returned by ra8_board_get_info() so applications can log / verify the board they were built for. All three are ASCII string literals with permanent storage duration. "RA8P1 foundation board".

Returned by ra8_board_get_info() so applications can log / verify the board they were built for. All three are ASCII string literals with permanent storage duration. "EK-RA8D2 v1".

Definition at line 46 of file ra8_board_ek_ra8d2.c.