|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
CPU1-safe combined direction+level PORT primitive over PCNTR1/PCNTR2. More...
Go to the source code of this file.
Functions | |
| static ra8_err_t | ra8_pcntr_set_output (ra8_port_t port, ra8_pin_t pin, ra8_level_t level) |
| Hold a pin an output and drive it to a level, via PCNTR1 (combined). | |
| static ra8_err_t | ra8_pcntr_read (ra8_port_t port, ra8_pin_t pin, ra8_level_t *out_level) |
| Read a pin's live level from PCNTR2 (PIDR). | |
CPU1-safe combined direction+level PORT primitive over PCNTR1/PCNTR2.
A deliberately tiny, header-only GPIO primitive built directly on the per-port PCNTR registers (ra8_port_regs.h). It exists so the secondary Cortex-M33 (CPU1) image – which is built -ffreestanding and links no ra8_hal (its only project include path is libs/ra8_core/inc, plus libs/ra8_hal/inc for the two freestanding-clean PORT headers) – can drive an on-chip pin through a HAL call instead of hand-rolling raw MMIO.
The high-level ra8_gpio_* driver (gpio.c) claims each pin through the pin-validator, logs through ra8_log, and programmes direction via the PFS register bank. Every one of those pulls infrastructure the freestanding M33 image does not link. This primitive intentionally depends on nothing but ra8_port_regs.h (the register layout + the ra8_port() accessor) and the typed enums in ra8_port_constants.h – all of which compile clean under -ffreestanding -fno-builtin – so it links into the CPU1 ELF unchanged, and it is host-testable on the ra8_fake_mmap peripheral-RAM backing exactly like the rest of the PORT layer.
Each port's PCNTR1 packs the direction latch PDR in bits [15:0] and the output latch PODR in bits [31:16]; PCNTR2 returns the live pin state PIDR in bits [15:0] (read-only). See ra8_port_regs.h and HUM Ch 20 "I/O Ports".
ra8_pcntr_set_output() sets BOTH direction (output) and level in one call – the combined-idiom the CPU1 images need – via a read-modify-write of PCNTR1 that preserves every other pin on the port. A bare full-word store to PCNTR1 (the ad-hoc form this primitive replaces) would silently force all sibling pins to input with a cleared output latch; the RMW here does not, so the primitive is safe to reuse on a shared port while remaining a drop-in substitute at the single-pin CPU1 call sites (their ports carry no other driven pins, so the observable pin state is identical).
Definition in file ra8_pcntr.h.
|
inlinestaticnodiscard |
Read a pin's live level from PCNTR2 (PIDR).
Reads the port's PCNTR2 and reports the addressed pin's live input-data bit (PIDR[pin]) as a level. Works for a pin held an input or an output (PIDR reflects the actual pad state either way). Performs a single PCNTR2 read and touches nothing else. Any active-low interpretation (e.g. a push button) is left to the caller.
| [in] | port | Port index (k_ra8_port_0 .. k_ra8_port_max). |
| [in] | pin | Pin index within the port (k_ra8_pin_0 .. k_ra8_pin_max). |
| [out] | out_level | Receives the pin's level (k_ra8_level_low / k_ra8_level_high). |
| k_ra8_ok | *out_level holds the live pin level. |
| k_ra8_err_null_ptr | out_level was nullptr. |
| k_ra8_err_gpio_invalid_port | port is out of range. |
| k_ra8_err_gpio_invalid_pin | pin is out of range. |
| k_ra8_err_hw_unmapped | The port has no register window (host fake only). |
out_level points at writable storage. Definition at line 162 of file ra8_pcntr.h.
References k_ra8_err_gpio_invalid_pin, k_ra8_err_gpio_invalid_port, k_ra8_err_hw_unmapped, k_ra8_err_null_ptr, k_ra8_level_high, k_ra8_level_low, k_ra8_ok, k_ra8_pin_max, k_ra8_port_max, r_port_regs_t::PCNTR2, pin, and ra8_port().
|
inlinestaticnodiscard |
Hold a pin an output and drive it to a level, via PCNTR1 (combined).
Read-modify-writes the port's PCNTR1 so the addressed pin's direction latch (PDR) becomes output (1) and its output latch (PODR) reflects level, while every other pin's PDR/PODR bit is preserved. This is the single-call "set direction and level together" primitive the freestanding CPU1 images need; it performs one PCNTR1 read and one PCNTR1 write and touches nothing else (no PFS, no pin-validator, no logging).
| [in] | port | Port index (k_ra8_port_0 .. k_ra8_port_max). |
| [in] | pin | Pin index within the port (k_ra8_pin_0 .. k_ra8_pin_max). |
| [in] | level | Target output level (k_ra8_level_low / k_ra8_level_high). |
| k_ra8_ok | Pin configured as output and driven to level. |
| k_ra8_err_gpio_invalid_port | port is out of range. |
| k_ra8_err_gpio_invalid_pin | pin is out of range. |
| k_ra8_err_hw_unmapped | The port has no register window (host fake only). |
pin powers up routed to PORT (no PFS peripheral-mux setup is done here). level. port is modified.Definition at line 99 of file ra8_pcntr.h.
References k_ra8_err_gpio_invalid_pin, k_ra8_err_gpio_invalid_port, k_ra8_err_hw_unmapped, k_ra8_level_high, k_ra8_ok, k_ra8_pcntr_high_half_shift, k_ra8_pin_max, k_ra8_port_max, r_port_regs_t::PCNTR1, pin, and ra8_port().
Referenced by blink_m33_hal_step().