ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_esp_hosted_osi.c
Go to the documentation of this file.
1
38
39#include <stdarg.h>
40#include <stddef.h>
41#include <stdint.h>
42
43#include "esp_hosted_os_abstraction.h"
44#include "esp_hosted_transport_config.h"
45#include "esp_log.h"
50#include "ra8_attributes.h"
51#include "ra8_check.h"
55#include "ra8_esp_hosted_pins.h"
56#include "ra8_esp_hosted_port.h"
59
61
91
101static const char* const s_tag = "C6OSI";
102
112static const char* const s_event_base_wifi = "WIFI_EVENT";
113
124
134
146hosted_osi_funcs_t g_hosted_osi_funcs;
147
159struct hosted_config_t g_h = HOSTED_CONFIG_INIT_DEFAULT();
160
164{
165 if ((cb == nullptr) && (ctx != nullptr)) {
167 }
170 return k_ra8_ok;
171}
172
177 int32_t event_id,
178 const void* data,
179 size_t data_len)
180{
181 if (s_ra8_esp_hosted_event_cb == nullptr) {
182 return RET_FAIL;
183 }
184 if ((data == nullptr) && (data_len != 0U)) {
185 return RET_INVALID;
186 }
188 (base == nullptr) ? "" : base,
189 event_id,
190 data,
191 data_len);
192 return RET_OK;
193}
194
225 int32_t event_id,
226 void* event_data,
227 size_t event_data_size,
228 uint32_t ticks_to_wait)
229{
230 (void)ticks_to_wait;
231 return priv_ra8_esp_hosted_osi_dispatch_event(event_base, event_id, event_data, event_data_size);
232}
233
260static int internal_event_wifi_post(int32_t event_id,
261 void* event_data,
262 size_t event_data_size,
263 uint32_t ticks_to_wait)
264{
265 (void)ticks_to_wait;
267 event_id,
268 event_data,
269 event_data_size);
270}
271
295[[gnu::format(printf, 3, 4)]] static void
296internal_printf(int level, const char* tag, const char* format, ...)
297{
298 va_list ap;
299 va_start(ap, format);
300 priv_ra8_esp_hosted_log_vwrite(level, tag, format, ap);
301 va_end(ap);
302}
303
325static void internal_init_hook(void)
326{
328 ESP_LOGE(s_esp_hosted_tag, "core started before ra8_esp_hosted_port_init");
329 return;
330 }
331 ra8_esp_hosted_mem_dump("hosted_init_hook");
332}
333
357static int internal_restart_host(void)
358{
359 ESP_LOGE(s_esp_hosted_tag, "core asked for a host restart; declined by policy");
360 return RET_FAIL;
361}
362
389static int internal_config_host_power_save(uint32_t power_save_type,
390 void* gpio_port,
391 uint32_t gpio_num,
392 int level)
393{
394 (void)gpio_port;
396 "host power save %u not enabled (pin %u level %d)",
397 (unsigned int)power_save_type,
398 (unsigned int)gpio_num,
399 level);
400 return RET_FAIL;
401}
402
424static int internal_start_host_power_save(uint32_t power_save_type)
425{
426 ESP_LOGW(s_esp_hosted_tag, "host power save %u not enabled", (unsigned int)power_save_type);
427 return RET_FAIL;
428}
429
453 hosted_osi_funcs_t table;
455 void (*rows[sizeof(hosted_osi_funcs_t) / sizeof(void (*)(void))])(void);
457
458static_assert(sizeof(hosted_osi_funcs_t) % sizeof(void (*)(void)) == 0U,
459 "the esp-hosted vtable must be a whole number of function pointers");
460
465bool priv_ra8_esp_hosted_osi_is_complete(const hosted_osi_funcs_t* table)
466{
467 if (table == nullptr) {
468 return false;
469 }
470
471 ra8_esp_hosted_osi_view_t view = {.table = *table};
472 const uint32_t rows = (uint32_t)(sizeof(view.rows) / sizeof(view.rows[0]));
473
474 for (uint32_t i = 0U; i < rows; i++) {
475 if (view.rows[i] == nullptr) {
476 return false;
477 }
478 }
479 return true;
480}
481
486{
487 RA8_CHECK_NULL_PTR(out, s_tag, "vtable");
488
489 *out = (hosted_osi_funcs_t){};
490
492 if (err == k_ra8_ok) {
494 }
495 if (err == k_ra8_ok) {
497 }
498 if (err == k_ra8_ok) {
500 }
501 if (err == k_ra8_ok) {
503 }
504 if (err != k_ra8_ok) {
505 return err;
506 }
508
509 out->_h_event_post = internal_event_post;
510 out->_h_event_wifi_post = internal_event_wifi_post;
511 out->_h_printf = internal_printf;
512 out->_h_hosted_init_hook = internal_init_hook;
513 out->_h_restart_host = internal_restart_host;
514 out->_h_config_host_power_save_hal_impl = internal_config_host_power_save;
515 out->_h_start_host_power_save_hal_impl = internal_start_host_power_save;
516
519 }
520 return k_ra8_ok;
521}
522
523/* Every field below comes from the port headers, so the configuration the
524 vendored core reads and the pins the port actually drives cannot
525 disagree. Written as a plain comment rather than a Doxygen block: the
526 contract lives on the declaration in the vendored
527 `esp_hosted_transport_config.h`, and a Doxygen block here would attach
528 itself to the struct return type rather than to the function. */
529struct esp_hosted_spi_config esp_hosted_get_default_spi_config(void)
530{
531 struct esp_hosted_spi_config cfg = {};
532
541 cfg.pin_handshake.port = H_GPIO_HANDSHAKE_Port;
542 cfg.pin_handshake.pin = H_GPIO_HANDSHAKE_Pin;
543 cfg.pin_data_ready.port = H_GPIO_DATA_READY_Port;
544 cfg.pin_data_ready.pin = H_GPIO_DATA_READY_Pin;
545 cfg.pin_reset.port = H_GPIO_PORT_RESET;
546 cfg.pin_reset.pin = H_GPIO_PIN_RESET;
547
548 cfg.tx_queue_size = (uint16_t)k_ra8_esp_hosted_osi_queue_depth;
549 cfg.rx_queue_size = (uint16_t)k_ra8_esp_hosted_osi_queue_depth;
550 cfg.mode = (uint8_t)k_ra8_esp_hosted_osi_spi_mode;
551 cfg.clk_mhz = (uint32_t)H_SPI_FD_CLK_MHZ;
552
553 return cfg;
554}
const char * esp_event_base_t
Identity of an event-producing subsystem.
ESP-IDF-compatible logging surface, implemented by this port.
#define ESP_LOGW(tag,...)
Log something unexpected that was handled anyway.
Definition esp_log.h:329
#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_PIN_RESET
Pin index of the co-processor reset output, or -1 when unwired.
#define RA8_ESP_HOSTED_GPIO_PORT(pin_code)
Extract the void* port half of a packed RA8 pin.
#define H_GPIO_DATA_READY_Port
Opaque port handle of the DATA_READY input.
#define RA8_ESP_HOSTED_GPIO_PIN(pin_code)
Extract the int pin half of a packed RA8 pin, or -1 if unwired.
#define H_SPI_FD_CLK_MHZ
Full-duplex SPI clock, in megahertz.
#define H_TRANSPORT_QUEUE_SIZE
Frames a single transport direction can hold.
#define H_GPIO_PORT_RESET
Opaque port handle of the co-processor reset output.
#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 RET_FAIL
Operation failed for an unspecified reason.
#define RET_INVALID
A parameter was out of contract (null handle, bad size).
#define RET_OK
Operation completed.
esp-hosted port header: full-duplex SPI transport buffer size.
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
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).
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_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
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_bind(hosted_osi_funcs_t *out)
Populate the eight GPIO slots of the OS-abstraction vtable.
Module-private surface of the esp-hosted side-band GPIO slice.
void priv_ra8_esp_hosted_log_vwrite(int level, const char *tag, const char *fmt, va_list ap)
Implementation of priv_ra8_esp_hosted_log_vwrite() – formats onto a bounded stack line,...
Library-private surface of the esp-hosted logging bridge.
hosted_osi_funcs_t g_hosted_osi_funcs
The OS-abstraction vtable the vendored core calls through.
static void * s_ra8_esp_hosted_event_ctx
Opaque context handed back to s_ra8_esp_hosted_event_cb.
static void internal_printf(int level, const char *tag, const char *format,...)
Vtable row: emit one formatted log line.
ra8_err_t ra8_esp_hosted_port_set_event_cb(ra8_esp_hosted_event_cb_t cb, void *ctx)
Implementation of ra8_esp_hosted_port_set_event_cb() – stores the pair atomically enough for a bring-...
static int internal_restart_host(void)
Vtable row: restart the host processor.
static const char *const s_event_base_wifi
Namespace reported for events the core posts as Wi-Fi events.
static void internal_init_hook(void)
Vtable row: run whatever the host needs before the core starts.
int priv_ra8_esp_hosted_osi_dispatch_event(const char *base, int32_t event_id, const void *data, size_t data_len)
Implementation of priv_ra8_esp_hosted_osi_dispatch_event() – the one decision behind both event rows,...
static const char * s_esp_hosted_tag
static int internal_start_host_power_save(uint32_t power_save_type)
Vtable row: enter host power save.
static ra8_esp_hosted_event_cb_t s_ra8_esp_hosted_event_cb
Application callback invoked when the core posts a link event.
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.
union ra8_esp_hosted_osi_view ra8_esp_hosted_osi_view_t
static int internal_event_wifi_post(int32_t event_id, void *event_data, size_t event_data_size, uint32_t ticks_to_wait)
Vtable row: post a Wi-Fi event.
bool priv_ra8_esp_hosted_osi_is_complete(const hosted_osi_funcs_t *table)
Implementation of priv_ra8_esp_hosted_osi_is_complete() – scans the table row-wise through a union,...
struct hosted_config_t g_h
The handle the vendored core dereferences to reach the vtable.
static int internal_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, uint32_t ticks_to_wait)
Vtable row: post a generic esp-hosted event.
static int internal_config_host_power_save(uint32_t power_save_type, void *gpio_port, uint32_t gpio_num, int level)
Vtable row: configure the host's power-save wake source.
ra8_esp_hosted_osi_const_t
Fixed values the non-slice vtable rows report.
@ k_ra8_esp_hosted_osi_queue_depth
Queue depth for each of the two transmit and receive priority queues, restated here so the SPI config...
@ k_ra8_esp_hosted_osi_spi_mode
SPI mode the co-processor image is built for.
@ k_ra8_esp_hosted_osi_wakeup_reboot
Wake-up reason meaning the host performed an ordinary reboot.
struct esp_hosted_spi_config esp_hosted_get_default_spi_config(void)
void priv_ra8_esp_hosted_osi_bind_absent(hosted_osi_funcs_t *out)
Implementation of priv_ra8_esp_hosted_osi_bind_absent() – fills all sixteen rows so none is ever left...
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_copi
Controller-out peripheral-in data, RA8 output, routed to the SCI channel rather than driven as a GPIO...
@ k_ra8_esp_hosted_pin_cipo
Controller-in peripheral-out data, RA8 input, routed to the SCI channel rather than sampled as a GPIO...
@ k_ra8_esp_hosted_pin_sck
Serial clock, RA8 output, routed to the SCI channel.
Public entry point of the RA8D2 + ThreadX port of esp-hosted.
bool ra8_esp_hosted_port_is_ready(void)
Report whether the port is currently initialised.
void ra8_esp_hosted_mem_dump(const char *label)
Report transport pool occupancy at a named point.
void(* ra8_esp_hosted_event_cb_t)(void *ctx, const char *base, int32_t event_id, const void *data, size_t data_len)
Application handler for an event the vendored core posts.
ra8_err_t priv_ra8_esp_hosted_rtos_bind(hosted_osi_funcs_t *out)
Populate the thread, sleep, timer and clock slots of the vtable.
Module-private contract of the esp-hosted RTOS abstraction slice.
ra8_err_t priv_ra8_esp_hosted_rtos_bind_sync(hosted_osi_funcs_t *out)
Populate the mutex and semaphore slots of the vtable.
ra8_err_t priv_ra8_esp_hosted_rtos_bind_pool(hosted_osi_funcs_t *out)
Populate the memory and queue slots of the vtable.
ra8_err_t priv_ra8_esp_hosted_spi_bind(hosted_osi_funcs_t *out)
Populate the three transport slots of the OS-abstraction vtable.
Module-private surface of the esp-hosted full-duplex SPI transport.
Row-wise view of the vtable, for the completeness scan.
hosted_osi_funcs_t table
The table as the vendored core sees it.
void(*[sizeof(hosted_osi_funcs_t)/sizeof(void(*)(void))]) rows(void)
The same bytes as a flat array of rows.