|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
GPIO / PORT peripheral-block model for the board emulator. More...
#include <stdint.h>#include <stdio.h>#include "board_console.h"#include "board_periph.h"#include "board_periph_block.h"#include "board_periph_eink.h"#include "emu_host_io_internal.h"Go to the source code of this file.
Data Structures | |
| struct | port_state_t |
| One PORT instance: direction + output latch (16 bits each). More... | |
| struct | led_map_t |
| Board LED -> (port index, pin index, lit colour), from the BSP. More... | |
Enumerations | |
| enum | gpio_lit_t : uint32_t { k_led3_port = 10U , k_led3_pin = 7U } |
| LED3 PORT/pin coordinates on the EK-RA8D2 (P10_07). More... | |
| enum | gpio_console_t : uint32_t { k_gpio_console_line_cap = 48U } |
| Console-tap line buffer capacity for a GPIO edge summary. More... | |
| enum | port_map_t : uint64_t { k_port_base = 0x40400000UL , k_port_stride = 0x20UL , k_port_count = 15UL , k_port_span = 0x20UL * 15UL , k_port_pcntr1 = 0x00UL , k_port_pcntr2 = 0x04UL , k_port_pcntr3 = 0x08UL , k_port_pcntr4 = 0x0CUL } |
| GPIO/PORT block geometry (ra8_port_regs.h). More... | |
| enum | port_field_t : uint32_t { k_half_shift = 16U , k_half_mask = 0xFFFFU , k_pins_per_port = 16U } |
| Generic field shifts / masks shared by the PORT halves. More... | |
| enum | sw_pin_t : uint32_t { k_sw_port = 0U , k_sw1_pin = 9U , k_sw2_pin = 8U } |
| EK-RA8D2 user-switch pins (PORT0): SW1=P009, SW2=P008 (UM Tbl 25). More... | |
| enum | led_color_t : uint16_t { k_led_rgb565_blue = 0x001FU , k_led_rgb565_green = 0x07E0U , k_led_rgb565_red = 0xF800U } |
| RGB565 lit-colour codes for the three board LEDs. More... | |
Functions | |
| static RA8_INTERNAL void | internal_port_trace_leds (uint32_t port_idx, uint16_t before, uint16_t after) |
| Note a board-LED edge when a traced port/pin output latch changes. | |
| static RA8_INTERNAL void | internal_port_set_podr (uint32_t port_idx, uint16_t new_podr) |
| Apply a new PODR value to a port and trace any LED transition. | |
| static RA8_INTERNAL uint64_t | internal_port_read (uc_engine *uc, uint64_t addr, unsigned size) |
| Dispatch a PORT register read; returns PCNTR value for the port. | |
| static RA8_INTERNAL void | internal_port_write (uc_engine *uc, uint64_t addr, unsigned size, uint64_t value) |
| Dispatch a PORT register write (PCNTR1 direction/latch, PCNTR3 set/clear). | |
| static RA8_INTERNAL void | internal_port_reset (void) |
| Clear every PORT latch / direction and the per-LED observability state. | |
| void | board_periph_gpio_set_input (uint8_t port, uint8_t pin, bool level) |
| Drive a GPIO pin's input level from outside the firmware. | |
| bool | board_periph_gpio_get_input (uint8_t port, uint8_t pin) |
| Read the externally-injected input level of a GPIO pin. | |
| uint32_t | board_periph_led_level (board_led_id_t led) |
| Read the last driven output level of a board LED. | |
| uint16_t | board_periph_led_color_rgb565 (board_led_id_t led) |
| The on-colour of a board LED as a packed RGB565 value. | |
| static RA8_INTERNAL void | internal_port_report (void) |
| Print the board-LED final level and transition-count line. | |
| static RA8_INTERNAL void | internal_board_periph_gpio_register (void) |
| Self-register the GPIO block before main runs (decentralized). | |
Variables | |
| static const led_map_t | s_k_led_map [k_board_led_count] |
| static port_state_t | s_port [k_port_count] |
| static uint32_t | s_led_level [k_board_led_count] |
| Last driven level. | |
| static uint32_t | s_led_transitions [k_board_led_count] |
| 0->1 / 1->0 count. | |
| static const board_periph_block_t | s_k_gpio_block |
| This block's descriptor (static lifetime; the core keeps the pointer). | |
GPIO / PORT peripheral-block model for the board emulator.
Models the RA8D2 GPIO/PORT block (ra8_port_regs.h): per-port direction (PDR) and output latch (PODR), the PCNTR1 combined register the FSP ioport driver writes, and the PCNTR3 atomic set/clear. The block also tracks the three EK-RA8D2 user LEDs (LED1 BLUE P600, LED2 GREEN P303, LED3 RED PA07) so the graphical board view can light each indicator in its real colour and the run summary can report each LED's level and transition count.
Self-registers its descriptor (address range + read / write / reset) with the board_periph core from a file-scope constructor, so the core needs no central block list – see board_periph_block.h.
Definition in file board_periph_gpio.c.
| enum gpio_console_t : uint32_t |
Console-tap line buffer capacity for a GPIO edge summary.
| Enumerator | |
|---|---|
| k_gpio_console_line_cap | Max chars in a "NAME -> ON/OFF" line. |
Definition at line 38 of file board_periph_gpio.c.
| enum gpio_lit_t : uint32_t |
LED3 PORT/pin coordinates on the EK-RA8D2 (P10_07).
| Enumerator | |
|---|---|
| k_led3_port | Led3 port. |
| k_led3_pin | Led3 pin. |
Definition at line 32 of file board_periph_gpio.c.
| enum led_color_t : uint16_t |
RGB565 lit-colour codes for the three board LEDs.
| Enumerator | |
|---|---|
| k_led_rgb565_blue | LED1 blue (P600) when driven high. |
| k_led_rgb565_green | LED2 green (P303) when driven high. |
| k_led_rgb565_red | LED3 red (PA07) when driven high. |
Definition at line 69 of file board_periph_gpio.c.
| enum port_field_t : uint32_t |
Generic field shifts / masks shared by the PORT halves.
| Enumerator | |
|---|---|
| k_half_shift | High-half (PODR/PORR/EIDR) shift. |
| k_half_mask | 16-bit half mask. |
| k_pins_per_port | Pins per PORT instance. |
Definition at line 55 of file board_periph_gpio.c.
| enum port_map_t : uint64_t |
GPIO/PORT block geometry (ra8_port_regs.h).
Definition at line 43 of file board_periph_gpio.c.
| enum sw_pin_t : uint32_t |
EK-RA8D2 user-switch pins (PORT0): SW1=P009, SW2=P008 (UM Tbl 25).
| Enumerator | |
|---|---|
| k_sw_port | Both user switches are on PORT0. |
| k_sw1_pin | SW1 -> P009. |
| k_sw2_pin | SW2 -> P008. |
Definition at line 62 of file board_periph_gpio.c.
| bool board_periph_gpio_get_input | ( | uint8_t | port, |
| uint8_t | pin ) |
Read the externally-injected input level of a GPIO pin.
Returns the level last set by board_periph_gpio_set_input for pin (the board's switches idle high). Lets an interactive caller toggle a push-button by reading the current state and writing its inverse – e.g. an on-screen SW1 click flips P009 between released (high) and pressed (low).
| [in] | port | PORT index (0-based; PORT0 == 0). |
| [in] | pin | Pin number within the port (0..15). |
| true | The board periph GPIO get input condition holds or completed successfully; false otherwise. |
Definition at line 276 of file board_periph_gpio.c.
References k_pins_per_port, k_port_count, pin, and s_port.
Referenced by internal_fill_status_hw().
| void board_periph_gpio_set_input | ( | uint8_t | port, |
| uint8_t | pin, | ||
| bool | level ) |
Drive a GPIO pin's input level from outside the firmware.
Lets the harness inject a pin level that the firmware reads back through PIDR (PCNTR2) – the model for a physical input such as a user push-button. The board's active-low switches SW1 (P009) / SW2 (P008) idle high (released) and are pulled low to model a press, so --button (and a live-view key) can exercise button-driven firmware paths (e.g. gpio_input_demo: SW1 -> LED1). Only the named pin's input is affected; output pins still read their latch.
| [in] | port | PORT index (0-based; PORT0 == 0). |
| [in] | pin | Pin number within the port (0..15). |
| [in] | level | Injected level: true = high, false = low. |
port / pin are within range (out-of-range is ignored). pin (when configured as input) see level. Definition at line 262 of file board_periph_gpio.c.
References k_pins_per_port, k_port_count, pin, and s_port.
Referenced by board_eink_apply_gpio_defaults(), internal_main_apply_button_battery(), and set_switch().
| uint16_t board_periph_led_color_rgb565 | ( | board_led_id_t | led | ) |
The on-colour of a board LED as a packed RGB565 value.
Returns the real EK-RA8D2 indicator colour the LED emits when driven high – LED1 blue (P600), LED2 green (P303), LED3 red (PA07) per the BSP – encoded as RGB565 so the board view can fill the indicator in the genuine colour (and the --ppm composite, also RGB565, captures it for verification). The value is the lit colour regardless of the live level; pair it with board_periph_led_level to decide lit vs dark.
| [in] | led | Board LED identity (board_led_id_t). |
led). | value | The operation-specific board periph led color rgb565 value. |
Definition at line 293 of file board_periph_gpio.c.
References k_board_led_count, and s_k_led_map.
Referenced by internal_fill_status_hw().
| uint32_t board_periph_led_level | ( | board_led_id_t | led | ) |
Read the last driven output level of a board LED.
Read-only accessor over the GPIO/PORT model's per-LED latch shadow, so the graphical board view can light each indicator without reaching into module internals. The level is the active-high pin drive recorded by the PORT write path: 1 once the firmware drives the LED's pin high, 0 once it drives it low.
| [in] | led | Board LED identity (board_led_id_t). |
led). | value | The operation-specific board periph led level value. |
Definition at line 285 of file board_periph_gpio.c.
References k_board_led_count, and s_led_level.
Referenced by internal_fill_status_hw().
|
static |
Self-register the GPIO block before main runs (decentralized).
Definition at line 335 of file board_periph_gpio.c.
References board_periph_register_block(), RA8_INTERNAL, and s_k_gpio_block.
|
static |
Dispatch a PORT register read; returns PCNTR value for the port.
Dispatch a port register read; returns pcntr value for the port; this step is contained within the board periph GPIO model and uses bounded caller or module-owned storage.
| [in,out] | uc | Unicorn engine whose emulated state is read or updated. |
| [in] | addr | Guest address involved in the operation. |
| [in] | size | Size of the requested region or access in bytes. |
| value | The operation-specific port read value. |
Definition at line 169 of file board_periph_gpio.c.
References port_state_t::in_lvl, port_state_t::in_ovr, k_half_shift, k_port_base, k_port_count, k_port_pcntr1, k_port_pcntr2, k_port_stride, port_state_t::pdr, port_state_t::podr, RA8_INTERNAL, and s_port.
|
static |
Print the board-LED final level and transition-count line.
Print the board-led final level and transition-count line; this step is contained within the board periph GPIO model and uses bounded caller or module-owned storage.
Definition at line 309 of file board_periph_gpio.c.
References k_board_led_count, priv_emu_io_errf(), RA8_INTERNAL, s_k_led_map, s_led_level, and s_led_transitions.
|
static |
Clear every PORT latch / direction and the per-LED observability state.
Clear every port latch / direction and the per-led observability state; this step is contained within the board periph GPIO model and uses bounded caller or module-owned storage.
Definition at line 240 of file board_periph_gpio.c.
References board_eink_apply_gpio_defaults(), k_board_led_count, k_port_count, k_sw1_pin, k_sw2_pin, k_sw_port, RA8_INTERNAL, s_led_level, s_led_transitions, and s_port.
|
static |
Apply a new PODR value to a port and trace any LED transition.
Apply a new podr value to a port and trace any led transition; this step is contained within the board periph GPIO model and uses bounded caller or module-owned storage.
| [in] | port_idx | Port idx input used by the operation. |
| [in] | new_podr | New podr input used by the operation. |
Definition at line 147 of file board_periph_gpio.c.
References internal_port_trace_leds(), RA8_INTERNAL, and s_port.
Referenced by internal_port_write().
|
static |
Note a board-LED edge when a traced port/pin output latch changes.
Note a board-led edge when a traced port/pin output latch changes; this step is contained within the board periph GPIO model and uses bounded caller or module-owned storage.
| [in] | port_idx | Port idx input used by the operation. |
| [in] | before | Before input used by the operation. |
| [in] | after | After input used by the operation. |
Definition at line 113 of file board_periph_gpio.c.
References board_console_push(), board_periph_trace(), k_board_console_ch_gpio, k_board_led_count, k_gpio_console_line_cap, pin, priv_emu_io_errf(), s_k_led_map, s_led_level, and s_led_transitions.
Referenced by internal_port_set_podr().
|
static |
Dispatch a PORT register write (PCNTR1 direction/latch, PCNTR3 set/clear).
Dispatch a port register write (pcntr1 direction/latch, pcntr3 set/clear); this step is contained within the board periph GPIO model and uses bounded caller or module-owned storage.
| [in,out] | uc | Unicorn engine whose emulated state is read or updated. |
| [in] | addr | Guest address involved in the operation. |
| [in] | size | Size of the requested region or access in bytes. |
| [in] | value | Register or payload value involved in the operation. |
Definition at line 207 of file board_periph_gpio.c.
References internal_port_set_podr(), k_half_mask, k_half_shift, k_port_base, k_port_count, k_port_pcntr1, k_port_pcntr3, k_port_stride, and s_port.
|
static |
This block's descriptor (static lifetime; the core keeps the pointer).
Definition at line 322 of file board_periph_gpio.c.
Referenced by internal_board_periph_gpio_register().
|
static |
Definition at line 91 of file board_periph_gpio.c.
Referenced by board_periph_led_color_rgb565(), internal_port_report(), and internal_port_trace_leds().
|
static |
Last driven level.
Definition at line 98 of file board_periph_gpio.c.
Referenced by board_periph_led_level(), internal_port_report(), internal_port_reset(), and internal_port_trace_leds().
|
static |
0->1 / 1->0 count.
Definition at line 99 of file board_periph_gpio.c.
Referenced by internal_port_report(), internal_port_reset(), and internal_port_trace_leds().
|
static |
Definition at line 97 of file board_periph_gpio.c.
Referenced by board_periph_gpio_get_input(), board_periph_gpio_set_input(), internal_port_read(), internal_port_reset(), internal_port_set_podr(), and internal_port_write().