ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
port_esp_hosted_host_os.h
Go to the documentation of this file.
1
37
38#pragma once
39
40#include "ra8_check.h"
41#ifndef assert
43/* NOLINTNEXTLINE(readability-identifier-naming) -- upstream-fixed lower-case macro spelling. */
44#define assert(expr) RA8_ASSERT(expr, "esp-hosted assertion")
45#endif
46#include <inttypes.h>
47#include <stddef.h>
48#include <stdint.h>
49
50/* ESP-IDF hosts reach these through their own build; on this host the
51 port supplies them, and this header is where the vendored core expects
52 its environment to arrive from. ``esp_heap_caps.h`` carries the
53 allocation capability flags the transport passes through,
54 ``<inttypes.h>`` carries the PRIu32 family the serial driver formats
55 with, ``<stdlib.h>`` declares the ``calloc`` that
56 ``transport_util_calloc`` reaches for on the non-DMA arm, and
57 ``<assert.h>`` carries the ``assert`` macro ``spi_drv.c`` guards every
58 handle creation in ``bus_init_internal`` with. Without the latter two
59 the vendored translation units compiled with C89 implicit declarations:
60 ``calloc`` came back as ``int`` (``-Wbuiltin-declaration-mismatch``) and
61 ``assert`` became a CALL to a function nothing defines, so the check was
62 not a check. */
63#include "esp_heap_caps.h"
64
65/* The allocation macros below expand to calls through ``g_h``, so the
66 vtable declaration has to come with them -- several vendored
67 translation units include this header and nothing else that declares
68 it. */
69#include "esp_hosted_os_abstraction.h"
70#include "ra8_esp_hosted_port.h"
71
72/* ----------------------------------------------------------------------- */
73/* Opaque RTOS handles */
74/* */
75/* The vendored core stores these and hands them back to the vtable; it */
76/* never dereferences one. Keeping them void* is what lets the concrete */
77/* ThreadX control blocks stay entirely inside the port. */
78/* ----------------------------------------------------------------------- */
79
89typedef void* queue_handle_t;
90
100typedef void* semaphore_handle_t;
101
111typedef void* mutex_handle_t;
112
122typedef void* thread_handle_t;
123
133typedef void* spinlock_handle_t;
134
145typedef uint8_t gpio_pin_state_t;
146
147/* ----------------------------------------------------------------------- */
148/* Return codes */
149/* ----------------------------------------------------------------------- */
150
164#define RET_OK (0)
165
178#define RET_FAIL (-1)
179
193#define RET_INVALID (-2)
194
208#define RET_FAIL_TIMEOUT (-3)
209
210/* ----------------------------------------------------------------------- */
211/* Blocking policy */
212/* ----------------------------------------------------------------------- */
213
227#define HOSTED_BLOCKING (1)
228
246#define HOSTED_BLOCK_MAX (0xFFFFFFFF)
247
263#define SEC_TO_MILLISEC(x) ((x) * (1000))
264
265/* ----------------------------------------------------------------------- */
266/* Memory */
267/* ----------------------------------------------------------------------- */
268
285#define HOSTED_MEM_ALIGNMENT_64 (64)
286
304#define HOSTED_UNLIKELY(x) (__builtin_expect(!!(x), 0))
305
320#define HOSTED_LIKELY(x) (__builtin_expect(!!(x), 1))
321
372static inline void* heap_caps_malloc(size_t size, uint32_t caps)
373{
374 void* result = nullptr;
375 if (g_h.funcs != nullptr) {
376 if (size != 0U) {
377 if ((caps & (uint32_t)MALLOC_CAP_DMA) != 0U) {
378 result = g_h.funcs->_h_malloc_align(size, (size_t)HOSTED_MEM_ALIGNMENT_64);
379 } else {
380 result = g_h.funcs->_h_malloc(size);
381 }
382 }
383 }
384 return result;
385}
386
401#define HOSTED_FREE(buff) \
402 do { \
403 if (buff) { \
404 g_h.funcs->_h_free(buff); \
405 (buff) = nullptr; \
406 } \
407 } while (0)
408
409/*
410 * HOSTED_CALLOC is DELIBERATELY NOT DEFINED. Read this before adding it.
411 *
412 * Upstream's version is an allocate-or-bail macro whose failure arm is a
413 * ``goto`` to a caller-supplied label. Defining it here would put a ``goto``
414 * in first-party code, which NASA Power of 10 Rule 1 forbids and
415 * ``scripts/checks/check_no_goto_setjmp.py`` rejects outright -- that gate has
416 * no allowlist, by design.
417 *
418 * Three ways out were considered and two were rejected:
419 * - Keeping the ``goto`` and waiving the gate. That is the allowlist this
420 * project deliberately does not have.
421 * - Substituting a plain ``return`` for the jump. This one looks tempting
422 * and is simply wrong: of the two call sites at the pinned commit, the one
423 * in ``host/drivers/serial/serial_drv.c`` jumps to a ``free_bufs`` label
424 * that releases two buffers before returning. A bare ``return`` there
425 * leaks both. The two sites also return different types, so no single
426 * substitution could serve both.
427 * - Leaving the macro out, which is what this port does.
428 *
429 * The consequence is bounded and stated in ``cmake/esp_hosted.cmake``:
430 * ``serial_drv.c`` and ``serial_if.c`` are the only vendored translation units
431 * that expand this macro, and neither is compiled. Nothing else needs it --
432 * their consumers are in the RPC layer, which does not compile in this build
433 * for an unrelated reason (it wants ESP-IDF's Wi-Fi API). When the RPC layer
434 * is brought in, those two files need a jump-free allocate-or-bail path, and
435 * that is a change to make there rather than a rule to bend here.
436 */
437
454#define MEM_DUMP(s) ra8_esp_hosted_mem_dump(s)
455
456/* ----------------------------------------------------------------------- */
457/* Thread budgets */
458/* */
459/* ThreadX priorities run 0 (highest) to TX_MAX_PRIORITIES-1 (lowest), the */
460/* opposite sense to FreeRTOS. The values below are already in ThreadX */
461/* order, so the port passes them through unchanged. */
462/* ----------------------------------------------------------------------- */
463
479#define DFLT_TASK_PRIO (12)
480
497#define DFLT_TASK_STACK_SIZE (4096)
498
513#define RPC_TASK_PRIO (14)
514
528#define RPC_TASK_STACK_SIZE (5120)
529
530/* ----------------------------------------------------------------------- */
531/* Timers */
532/* ----------------------------------------------------------------------- */
533
546#define H_TIMER_TYPE_ONESHOT (1)
547
560#define H_TIMER_TYPE_PERIODIC (2)
561
562/* ----------------------------------------------------------------------- */
563/* GPIO modes and pulls */
564/* ----------------------------------------------------------------------- */
565
578#define H_GPIO_MODE_DEF_INPUT (0)
579
594#define H_GPIO_MODE_DEF_OUTPUT (1)
595
608#define H_GPIO_PULL_UP (0)
609
625#define H_GPIO_PULL_DOWN (1)
626
627/* ----------------------------------------------------------------------- */
628/* Payload bound */
629/* ----------------------------------------------------------------------- */
630
647#define MAX_PAYLOAD_SIZE (MAX_TRANSPORT_BUFFER_SIZE - H_ESP_PAYLOAD_HEADER_OFFSET)
648
649/* ----------------------------------------------------------------------- */
650/* Placement and linkage attributes */
651/* ----------------------------------------------------------------------- */
652
670#define FAST_RAM_ATTR
671
685#define H_IRAM_ATTR
686
703#define H_WEAK_REF [[gnu::weak]]
ESP-IDF capability-flag compatibility for the esp-hosted port.
@ MALLOC_CAP_DMA
Reachable by a DMA engine.
void * queue_handle_t
Opaque handle to a port-owned message queue.
void * thread_handle_t
Opaque handle to a port-owned thread.
void * semaphore_handle_t
Opaque handle to a port-owned counting semaphore.
void * mutex_handle_t
Opaque handle to a port-owned mutex.
void * spinlock_handle_t
Opaque handle to a port-owned mempool lock.
static void * heap_caps_malloc(size_t size, uint32_t caps)
ESP-IDF capability-aware allocation, served from the port pool.
#define HOSTED_MEM_ALIGNMENT_64
Alignment, in bytes, demanded of transport buffers.
uint8_t gpio_pin_state_t
Logic level read back from, or driven onto, a side-band pin.
Validation and Error-Checking Macros for ra8-firmware.
struct hosted_config_t g_h
The handle the vendored core dereferences to reach the vtable.
Public entry point of the RA8D2 + ThreadX port of esp-hosted.