ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_esp_hosted_port.c
Go to the documentation of this file.
1
33
34#include "ra8_esp_hosted_port.h"
35
36#include <stdint.h>
37
38#include "esp_hosted_os_abstraction.h"
42#include "ra8_attributes.h"
43#include "ra8_check.h"
46#include "ra8_esp_hosted_pins.h"
50#include "ra8_port_constants.h"
51
53
77
90
96{
98
99 if (cfg->pclk_hz == 0U) {
101 }
102 if (cfg->sck_hz == 0U) {
104 }
105 if (cfg->edge_poll_ms == 0U) {
107 }
108 if (cfg->sci_channel >= (uint8_t)k_ra8_esp_hosted_port_sci_channels) {
110 }
111 return k_ra8_ok;
112}
113
138static bool internal_pin_in_range(uint16_t pin)
139{
140 return ((uint16_t)RA8_PIN_PORT(pin) <= (uint16_t)k_ra8_port_max) &&
141 ((uint16_t)RA8_PIN_PIN(pin) <= (uint16_t)k_ra8_pin_max);
142}
143
149 uint16_t handshake,
150 uint16_t data_ready)
151{
152 if ((chip_select == handshake) || (chip_select == data_ready) || (handshake == data_ready)) {
154 }
155 if (!internal_pin_in_range(chip_select)) {
157 }
158 if (!internal_pin_in_range(handshake)) {
160 }
161 if (!internal_pin_in_range(data_ready)) {
163 }
164 return k_ra8_ok;
165}
166
176
201{
202 if (g_h.funcs->_h_config_gpio(H_GPIO_HANDSHAKE_Port,
203 (uint32_t)H_GPIO_HANDSHAKE_Pin,
205 ESP_LOGE(s_esp_hosted_tag, "handshake pin would not configure as an input");
207 }
208 if (g_h.funcs->_h_config_gpio(H_GPIO_DATA_READY_Port,
209 (uint32_t)H_GPIO_DATA_READY_Pin,
211 ESP_LOGE(s_esp_hosted_tag, "data-ready pin would not configure as an input");
213 }
214 return k_ra8_ok;
215}
216
240{
241 /* Both release steps run before either result is folded, so neither can be
242 skipped by an earlier failure. The fold itself lives in
243 `priv_ra8_esp_hosted_port_first_error()` because it is the only decision here
244 and reaching this function needs a brought-up port. */
248 first = priv_ra8_esp_hosted_port_first_error(first, rtos_err);
249
250 g_hosted_osi_funcs = (hosted_osi_funcs_t){};
252 return first;
253}
254
259{
260 if ((first == k_ra8_ok) && (next != k_ra8_ok)) {
261 return next;
262 }
263 return first;
264}
265
307{
309
311 if (err != k_ra8_ok) {
312 return err;
313 }
314
316 if (err == k_ra8_ok) {
318 }
319 if (err == k_ra8_ok) {
321 }
322 if (err == k_ra8_ok) {
324 }
325 return err;
326}
327
332{
334 if (cfg_err != k_ra8_ok) {
335 return cfg_err;
336 }
339 }
340
342 if (pin_err != k_ra8_ok) {
343 ESP_LOGE(s_esp_hosted_tag, "pin map is not self-consistent");
344 return pin_err;
345 }
346
347 const ra8_err_t err = internal_bring_up(cfg);
348 if (err != k_ra8_ok) {
349 (void)internal_unwind();
350 return err;
351 }
352
355 "esp-hosted port up on SCI%u at %u Hz",
356 (unsigned int)cfg->sci_channel,
357 (unsigned int)cfg->sck_hz);
358 return k_ra8_ok;
359}
360
371
378
380{
382 return false;
383 }
384 const int level =
385 g_h.funcs->_h_read_gpio(H_GPIO_DATA_READY_Port, (uint32_t)H_GPIO_DATA_READY_Pin);
386 return level == H_DR_VAL_ACTIVE;
387}
#define ESP_LOGI(tag,...)
Log a normal life-cycle milestone.
Definition esp_log.h:346
#define ESP_LOGE(tag,...)
Log a fault the caller cannot recover from itself.
Definition esp_log.h:313
esp-hosted port header: transport selection, side-band pin map, link polarity.
#define H_GPIO_HANDSHAKE_Pin
Pin index of the HANDSHAKE input, or -1 when it is not wired.
#define H_GPIO_HANDSHAKE_Port
Opaque port handle of the HANDSHAKE input.
#define H_GPIO_DATA_READY_Port
Opaque port handle of the DATA_READY input.
#define H_DR_VAL_ACTIVE
Level read back on DATA_READY when a frame is waiting.
#define H_GPIO_DATA_READY_Pin
Pin index of the DATA_READY input, or -1 when it is not wired.
esp-hosted port header: the per-file log tag the core expects.
#define DEFINE_LOG_TAG(tag)
Declare the file-scope s_esp_hosted_tag string the ESP_LOGx macros use.
esp-hosted port header: RTOS handle types, return codes and budgets.
#define H_GPIO_MODE_DEF_INPUT
Configure a side-band pin as a digital input.
#define RET_OK
Operation completed.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
ra8_board_eth_pin_t pin
Pin.
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
Definition ra8_err.h:161
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
Definition ra8_err.h:235
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_gpio_conflict
GPIO pin already owned by another peripheral or driver.
Definition ra8_err.h:318
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
ra8_err_t priv_ra8_esp_hosted_gpio_set_edge_poll_ms(uint16_t period_ms)
Set the sampling period the software edge detector runs at.
Module-private surface of the esp-hosted side-band GPIO slice.
hosted_osi_funcs_t g_hosted_osi_funcs
The OS-abstraction vtable the vendored core calls through.
static const char * s_esp_hosted_tag
ra8_err_t priv_ra8_esp_hosted_osi_bind_all(hosted_osi_funcs_t *out)
Implementation of priv_ra8_esp_hosted_osi_bind_all() – fills every row, then proves none was missed.
struct hosted_config_t g_h
The handle the vendored core dereferences to reach the vtable.
Library-private surface of the esp-hosted OS-abstraction vtable.
THE single point of change for the RA8 <-> ESP32-C6 harness map.
@ k_ra8_esp_hosted_pin_chip_select
Chip select, RA8 output.
@ k_ra8_esp_hosted_pin_data_ready
DATA_READY, RA8 input, C6 output.
@ k_ra8_esp_hosted_pin_handshake
HANDSHAKE, RA8 input, C6 output.
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 c...
static ra8_err_t internal_bring_up(const ra8_esp_hosted_port_cfg_t *cfg)
Bring the port's slices up in dependency order.
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_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...
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.
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 ...
static ra8_err_t internal_unwind(void)
Release everything the bring-up path may have claimed.
ra8_esp_hosted_port_limit_t
Bounds the bring-up path validates against.
@ k_ra8_esp_hosted_port_sci_channels
SCI channels on this part; a channel index must be below this.
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...
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,...
static ra8_err_t internal_configure_sideband(void)
Configure the two side-band nets as digital inputs.
bool ra8_esp_hosted_port_rx_pending(void)
Report whether the co-processor has queued receive data.
static bool s_ra8_esp_hosted_port_ready
Whether the port has completed bring-up and not been torn down.
ra8_err_t ra8_esp_hosted_port_deinit(void)
Implementation of ra8_esp_hosted_port_deinit() – refuses when the port was never up,...
Public entry point of the RA8D2 + ThreadX port of esp-hosted.
struct ra8_esp_hosted_port_cfg ra8_esp_hosted_port_cfg_t
Library-private surface of the esp-hosted port bring-up.
ra8_err_t priv_ra8_esp_hosted_rtos_deinit(void)
Tear the RTOS substrate down, deleting every outstanding object.
ra8_err_t priv_ra8_esp_hosted_rtos_init(void)
Bring the RTOS substrate up: byte pools and empty object tables.
Module-private contract of the esp-hosted RTOS abstraction slice.
ra8_err_t priv_ra8_esp_hosted_spi_close(void)
Close the SCI Simple-SPI channel and release every pin it took.
ra8_err_t priv_ra8_esp_hosted_spi_open(uint8_t sci_channel, uint32_t pclk_hz, uint32_t sck_hz)
Route the Pmod1 SPI pins and open the SCI Simple-SPI channel.
Module-private surface of the esp-hosted full-duplex SPI transport.
Typed Port / Pin Constants for the RA8D2 IOPORT Module.
@ k_ra8_port_max
Highest valid port index.
@ k_ra8_pin_max
Highest valid pin index.
#define RA8_PIN_PORT(p)
Extract the port index from a packed ra8_port_pin_t.
#define RA8_PIN_PIN(p)
Extract the pin index from a packed ra8_port_pin_t.
uint16_t edge_poll_ms
Sampling period for pins with no ICU channel.
uint32_t pclk_hz
PCLKA rate in hertz; the SCI baud clock source.
uint32_t sck_hz
Requested SPI bit rate in hertz.
uint8_t sci_channel
SCI channel carrying Simple-SPI; 0..9.