|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Bring-up and teardown of the esp-hosted RA8D2 + ThreadX port. More...
#include "ra8_esp_hosted_port.h"#include <stdint.h>#include "esp_hosted_os_abstraction.h"#include "port_esp_hosted_host_config.h"#include "port_esp_hosted_host_log.h"#include "port_esp_hosted_host_os.h"#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_esp_hosted_gpio_internal.h"#include "ra8_esp_hosted_osi_internal.h"#include "ra8_esp_hosted_pins.h"#include "ra8_esp_hosted_port_internal.h"#include "ra8_esp_hosted_rtos_internal.h"#include "ra8_esp_hosted_spi_internal.h"#include "ra8_port_constants.h"Go to the source code of this file.
Enumerations | |
| enum | ra8_esp_hosted_port_limit_t : uint8_t { k_ra8_esp_hosted_port_sci_channels = 10U } |
| Bounds the bring-up path validates against. More... | |
Functions | |
| DEFINE_LOG_TAG (port) | |
| ra8_err_t | priv_ra8_esp_hosted_port_cfg_check (const ra8_esp_hosted_port_cfg_t *cfg) |
| Implementation of priv_ra8_esp_hosted_port_cfg_check() – a pure predicate, so bring-up can reject a configuration before claiming anything. | |
| static bool | internal_pin_in_range (uint16_t pin) |
| Whether a packed pin code decodes to a legal port and pin index. | |
| ra8_err_t | priv_ra8_esp_hosted_port_pins_check_values (uint16_t chip_select, uint16_t handshake, uint16_t data_ready) |
| Implementation of priv_ra8_esp_hosted_port_pins_check_values() – distinctness first, then range, so a duplicated assignment is reported as such rather than as an out-of-range pin. | |
| ra8_err_t | priv_ra8_esp_hosted_port_pins_check (void) |
| Implementation of priv_ra8_esp_hosted_port_pins_check() – applies the value check to the compiled-in map. | |
| static ra8_err_t | internal_configure_sideband (void) |
| Configure the two side-band nets as digital inputs. | |
| static ra8_err_t | internal_unwind (void) |
| Release everything the bring-up path may have claimed. | |
| ra8_err_t | priv_ra8_esp_hosted_port_first_error (ra8_err_t first, ra8_err_t next) |
| Implementation of priv_ra8_esp_hosted_port_first_error() – a pure fold, so the unwind path carries no decision of its own. | |
| static ra8_err_t | internal_bring_up (const ra8_esp_hosted_port_cfg_t *cfg) |
| Bring the port's slices up in dependency order. | |
| ra8_err_t | ra8_esp_hosted_port_init (const ra8_esp_hosted_port_cfg_t *cfg) |
| Implementation of ra8_esp_hosted_port_init() – validate, then bring the slices up in dependency order, unwinding on the first failure. | |
| ra8_err_t | ra8_esp_hosted_port_deinit (void) |
| Implementation of ra8_esp_hosted_port_deinit() – refuses when the port was never up, so a double teardown is visible rather than silently accepted. | |
| bool | ra8_esp_hosted_port_is_ready (void) |
| Implementation of ra8_esp_hosted_port_is_ready() – one aligned load, so it is safe from any context. | |
| bool | ra8_esp_hosted_port_rx_pending (void) |
| Report whether the co-processor has queued receive data. | |
Variables | |
| static bool | s_ra8_esp_hosted_port_ready |
| Whether the port has completed bring-up and not been torn down. | |
Bring-up and teardown of the esp-hosted RA8D2 + ThreadX port.
Sequences the port's four slices and unwinds them in the opposite order. The order is not arbitrary:
Teardown walks back up, and every step runs even if an earlier one reports a problem – a teardown that stops at the first error leaves exactly the stranded pin it was supposed to release.
Definition in file ra8_esp_hosted_port.c.
| enum ra8_esp_hosted_port_limit_t : uint8_t |
Bounds the bring-up path validates against.
Named so each rejection reads as a contract violation rather than a comparison against a bare number.
| Enumerator | |
|---|---|
| k_ra8_esp_hosted_port_sci_channels | SCI channels on this part; a channel index must be below this. |
Definition at line 73 of file ra8_esp_hosted_port.c.
| DEFINE_LOG_TAG | ( | port | ) |
|
static |
Bring the port's slices up in dependency order.
The second half of ra8_esp_hosted_port_init, split out so validation and bring-up are separately readable and each stays inside the project's function-length limit. Every step depends on the one before it: the RTOS substrate must exist before the vtable can be bound, the vtable must be bound before the edge-poll period or the side-band pins can be reached through it, and the bus must be open before the co-processor is spoken to.
The RTOS init is separate from the chain below it because it is the only step whose failure leaves nothing to release: the err == k_ra8_ok ladder starts once there is state a caller would have to unwind.
The readiness of the port is not re-tested here; ra8_esp_hosted_port_init establishes it before calling, and a second test would be a branch no caller can reach.
| [in] | cfg | Validated configuration; must be non-null and already accepted by priv_ra8_esp_hosted_port_cfg_check. |
| k_ra8_ok | Every slice came up. |
| k_ra8_err_null_ptr | cfg was null. |
| k_ra8_err_rtos_error | The ThreadX substrate would not initialise. |
| k_ra8_err_spi_error | The SCI channel would not open. |
| k_ra8_err_gpio_conflict | A side-band pin would not configure. |
cfg has already passed priv_ra8_esp_hosted_port_cfg_check. Definition at line 306 of file ra8_esp_hosted_port.c.
References ra8_esp_hosted_port_cfg::edge_poll_ms, g_hosted_osi_funcs, internal_configure_sideband(), k_ra8_ok, ra8_esp_hosted_port_cfg::pclk_hz, priv_ra8_esp_hosted_gpio_set_edge_poll_ms(), priv_ra8_esp_hosted_osi_bind_all(), priv_ra8_esp_hosted_rtos_init(), priv_ra8_esp_hosted_spi_open(), RA8_CHECK_NULL_PTR, s_esp_hosted_tag, ra8_esp_hosted_port_cfg::sci_channel, and ra8_esp_hosted_port_cfg::sck_hz.
Referenced by ra8_esp_hosted_port_init().
|
static |
Configure the two side-band nets as digital inputs.
Goes through the freshly-bound vtable rather than calling the GPIO HAL directly, so bring-up exercises the same rows the vendored driver will use. A row bound to the wrong function therefore fails here, where the error message names the port, instead of on the first frame.
| k_ra8_ok | Both pins are inputs. |
| k_ra8_err_gpio_conflict | A pin is owned by another module, or a vtable row rejected the request. |
Definition at line 200 of file ra8_esp_hosted_port.c.
References ESP_LOGE, g_h, H_GPIO_DATA_READY_Pin, H_GPIO_DATA_READY_Port, H_GPIO_HANDSHAKE_Pin, H_GPIO_HANDSHAKE_Port, H_GPIO_MODE_DEF_INPUT, k_ra8_err_gpio_conflict, k_ra8_ok, RET_OK, and s_esp_hosted_tag.
Referenced by internal_bring_up().
|
static |
Whether a packed pin code decodes to a legal port and pin index.
k_ra8_pin_none decodes to port 255, pin 255, so the range test rejects it without needing a separate comparison against the sentinel.
| [in] | pin | Packed RA8_PIN(port, pin) code. |
| true | The port is at most k_ra8_port_max and the pin at most k_ra8_pin_max. |
| false | Either half is out of range, including the no-pin sentinel. |
Definition at line 138 of file ra8_esp_hosted_port.c.
References k_ra8_pin_max, k_ra8_port_max, pin, RA8_PIN_PIN, and RA8_PIN_PORT.
Referenced by priv_ra8_esp_hosted_port_pins_check_values().
|
static |
Release everything the bring-up path may have claimed.
Runs every step regardless of what the previous one reported, because a teardown that stops at the first error strands exactly the resource it was meant to release. The first error seen is what it returns.
| k_ra8_ok | Every step released cleanly. |
| k_ra8_err_rtos_error | ThreadX refused to release an object. |
| k_ra8_err_spi_error | The SCI channel would not close. |
Definition at line 239 of file ra8_esp_hosted_port.c.
References g_hosted_osi_funcs, k_ra8_ok, priv_ra8_esp_hosted_port_first_error(), priv_ra8_esp_hosted_rtos_deinit(), priv_ra8_esp_hosted_spi_close(), and s_ra8_esp_hosted_port_ready.
Referenced by ra8_esp_hosted_port_deinit(), and ra8_esp_hosted_port_init().
|
nodiscard |
Implementation of priv_ra8_esp_hosted_port_cfg_check() – a pure predicate, so bring-up can reject a configuration before claiming anything.
Check a port configuration against its documented contract.
Definition at line 95 of file ra8_esp_hosted_port.c.
References ra8_esp_hosted_port_cfg::edge_poll_ms, k_ra8_err_invalid_arg, k_ra8_esp_hosted_port_sci_channels, k_ra8_ok, ra8_esp_hosted_port_cfg::pclk_hz, RA8_CHECK_NULL_PTR, s_esp_hosted_tag, ra8_esp_hosted_port_cfg::sci_channel, and ra8_esp_hosted_port_cfg::sck_hz.
Referenced by ra8_esp_hosted_port_init().
Implementation of priv_ra8_esp_hosted_port_first_error() – a pure fold, so the unwind path carries no decision of its own.
Keep the first error of a teardown sequence, discarding later ones.
Definition at line 258 of file ra8_esp_hosted_port.c.
References k_ra8_ok.
Referenced by internal_unwind().
|
nodiscard |
Implementation of priv_ra8_esp_hosted_port_pins_check() – applies the value check to the compiled-in map.
Check the compiled-in pin map for self-consistency.
Definition at line 170 of file ra8_esp_hosted_port.c.
References k_ra8_esp_hosted_pin_chip_select, k_ra8_esp_hosted_pin_data_ready, k_ra8_esp_hosted_pin_handshake, and priv_ra8_esp_hosted_port_pins_check_values().
Referenced by ra8_esp_hosted_port_init().
|
nodiscard |
Implementation of priv_ra8_esp_hosted_port_pins_check_values() – distinctness first, then range, so a duplicated assignment is reported as such rather than as an out-of-range pin.
Check three candidate pin assignments for self-consistency.
Definition at line 148 of file ra8_esp_hosted_port.c.
References internal_pin_in_range(), k_ra8_err_invalid_arg, and k_ra8_ok.
Referenced by priv_ra8_esp_hosted_port_pins_check().
|
nodiscard |
Implementation of ra8_esp_hosted_port_deinit() – refuses when the port was never up, so a double teardown is visible rather than silently accepted.
Tear the port down, releasing every pin, interrupt and pool.
Definition at line 364 of file ra8_esp_hosted_port.c.
References internal_unwind(), k_ra8_err_not_initialized, and s_ra8_esp_hosted_port_ready.
|
nodiscard |
Implementation of ra8_esp_hosted_port_init() – validate, then bring the slices up in dependency order, unwinding on the first failure.
Bring the esp-hosted port up and publish the OS-abstraction vtable.
Definition at line 331 of file ra8_esp_hosted_port.c.
References ESP_LOGE, ESP_LOGI, internal_bring_up(), internal_unwind(), k_ra8_err_invalid_state, k_ra8_ok, priv_ra8_esp_hosted_port_cfg_check(), priv_ra8_esp_hosted_port_pins_check(), s_esp_hosted_tag, s_ra8_esp_hosted_port_ready, ra8_esp_hosted_port_cfg::sci_channel, and ra8_esp_hosted_port_cfg::sck_hz.
Referenced by tx_application_define().
|
nodiscard |
Implementation of ra8_esp_hosted_port_is_ready() – one aligned load, so it is safe from any context.
Report whether the port is currently initialised.
Definition at line 374 of file ra8_esp_hosted_port.c.
References s_ra8_esp_hosted_port_ready.
Referenced by c6_fwver_pump_check(), c6_hosted_heartbeat(), internal_init_hook(), internal_ra8_esp_hosted_c6link_delay(), internal_ra8_esp_hosted_c6link_handshake(), internal_ra8_esp_hosted_c6link_transfer(), and ra8_esp_hosted_c6link_bind().
|
nodiscard |
Report whether the co-processor has queued receive data.
Samples the held DATA_READY side-band signal through the bound esp-hosted GPIO seam. This is a non-blocking level check for poll schedulers; it does not clock SPI or consume the pending frame.
| true | DATA_READY is asserted on an initialized port. |
| false | The port is not initialized or DATA_READY is inactive. |
Definition at line 379 of file ra8_esp_hosted_port.c.
References g_h, H_DR_VAL_ACTIVE, H_GPIO_DATA_READY_Pin, H_GPIO_DATA_READY_Port, and s_ra8_esp_hosted_port_ready.
Referenced by internal_rx_worker_entry().
|
static |
Whether the port has completed bring-up and not been torn down.
The single piece of module state. Set only after every slice has reported success, so a partially-initialised port never reports ready.
Definition at line 89 of file ra8_esp_hosted_port.c.
Referenced by internal_unwind(), ra8_esp_hosted_port_deinit(), ra8_esp_hosted_port_init(), ra8_esp_hosted_port_is_ready(), and ra8_esp_hosted_port_rx_pending().