ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_hw_err.h
Go to the documentation of this file.
1
60
61#pragma once
62
63#ifdef __cplusplus
64extern "C" {
65#endif
66
67#include <stdint.h>
68
69#include "ra8_err.h"
70
71#if defined(RA8_OFF_TARGET) && defined(UNIT_TEST)
72/* Host unit-test MMIO fault seam (tests/mocks/src/ra8_fake_mmio.c). Consulted once per
73 * poll below so a test can drive a bounded wait to timeout or succeed-after-N,
74 * exercising the real poll/timeout legs on host with the driver short-circuits
75 * deleted (T1-01). Forward-declared here -- rather than including the test-only
76 * header -- so this production header stays test-clean; the definition links
77 * only into the host test binary. Absent in firmware and ra8_emulator builds, which
78 * do not define UNIT_TEST and take the plain register-read path below. */
79[[nodiscard]] bool ra8_fake_mmio_wait_eval(const volatile void* reg, uint32_t iter, bool real_cond);
80/* Real-condition-honoring poll consult for the raw-loop status polls in the
81 * i2c / i3c / sdhi drivers -- those were NOT written against ra8_hw_wait_* and
82 * must keep their "flag_set -> exit, else spin to the bounded timeout" contract.
83 * Unlike ra8_fake_mmio_wait_eval (unarmed -> true, the T1-01 short-circuit drop-in),
84 * this returns @p flag_set when the register is unarmed, so an unprimed flag
85 * still times out exactly as the pre-seam raw loop did and every existing test
86 * keeps its behaviour. It also invokes any registered synchronous poll-hook first
87 * (see ra8_fake_mmio_set_poll_hook) so a host test can model the peripheral on the
88 * driver's OWN poll thread, deterministically and thread-free. */
89[[nodiscard]] bool ra8_fake_mmio_poll(const volatile void* reg, uint32_t iter, bool flag_set);
120[[nodiscard]] uint32_t ra8_fake_mmio_read_to_set32(volatile uint32_t* reg, uint32_t set_mask);
121
147void ra8_fake_mmio_write1_clear32(volatile uint32_t* reg, uint32_t w1c_mask, uint32_t value);
148#endif
149
150/* =============================================================================
151 * Default budgets
152 * =============================================================================
153 */
154
171typedef enum : uint32_t {
172 k_ra8_hw_budget_short = 0x00000400U,
174 k_ra8_hw_budget_long = 0x00040000U,
175 k_ra8_hw_budget_xlong = 0x00400000U,
177
178/* =============================================================================
179 * 8-bit waiters
180 * =============================================================================
181 */
182
218static inline ra8_err_t
219ra8_hw_wait_flag_set8(volatile const uint8_t* reg, uint8_t mask, uint32_t budget)
220{
221 if (reg == nullptr) {
222 return k_ra8_err_null_ptr;
223 }
224 for (uint32_t i = 0U; i < budget; ++i) {
225#if defined(RA8_OFF_TARGET) && defined(UNIT_TEST)
226 if (ra8_fake_mmio_wait_eval(reg, i, ((*reg & mask) != 0U))) {
227 return k_ra8_ok;
228 }
229#else
230 if ((*reg & mask) != 0U) {
231 return k_ra8_ok;
232 }
233#endif
234 }
236}
237
261static inline ra8_err_t
262ra8_hw_wait_flag_clear8(volatile const uint8_t* reg, uint8_t mask, uint32_t budget)
263{
264 if (reg == nullptr) {
265 return k_ra8_err_null_ptr;
266 }
267 for (uint32_t i = 0U; i < budget; ++i) {
268#if defined(RA8_OFF_TARGET) && defined(UNIT_TEST)
269 if (ra8_fake_mmio_wait_eval(reg, i, ((*reg & mask) == 0U))) {
270 return k_ra8_ok;
271 }
272#else
273 if ((*reg & mask) == 0U) {
274 return k_ra8_ok;
275 }
276#endif
277 }
279}
280
281/* =============================================================================
282 * 32-bit waiters
283 * =============================================================================
284 */
285
308static inline ra8_err_t
309ra8_hw_wait_flag_set32(volatile const uint32_t* reg, uint32_t mask, uint32_t budget)
310{
311 if (reg == nullptr) {
312 return k_ra8_err_null_ptr;
313 }
314 for (uint32_t i = 0U; i < budget; ++i) {
315#if defined(RA8_OFF_TARGET) && defined(UNIT_TEST)
316 if (ra8_fake_mmio_wait_eval(reg, i, ((*reg & mask) != 0U))) {
317 return k_ra8_ok;
318 }
319#else
320 if ((*reg & mask) != 0U) {
321 return k_ra8_ok;
322 }
323#endif
324 }
326}
327
350static inline ra8_err_t
351ra8_hw_wait_flag_clear32(volatile const uint32_t* reg, uint32_t mask, uint32_t budget)
352{
353 if (reg == nullptr) {
354 return k_ra8_err_null_ptr;
355 }
356 for (uint32_t i = 0U; i < budget; ++i) {
357#if defined(RA8_OFF_TARGET) && defined(UNIT_TEST)
358 if (ra8_fake_mmio_wait_eval(reg, i, ((*reg & mask) == 0U))) {
359 return k_ra8_ok;
360 }
361#else
362 if ((*reg & mask) == 0U) {
363 return k_ra8_ok;
364 }
365#endif
366 }
368}
369
370#ifdef __cplusplus
371}
372#endif
Error Code Definitions for ra8-firmware.
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
Definition ra8_err.h:304
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
Definition ra8_err.h:478
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
static ra8_err_t ra8_hw_wait_flag_clear8(volatile const uint8_t *reg, uint8_t mask, uint32_t budget)
Spin until (*reg & mask) == 0 or budget runs out.
Definition ra8_hw_err.h:262
static ra8_err_t ra8_hw_wait_flag_set32(volatile const uint32_t *reg, uint32_t mask, uint32_t budget)
Spin until (*reg & mask) != 0 or budget runs out.
Definition ra8_hw_err.h:309
static ra8_err_t ra8_hw_wait_flag_set8(volatile const uint8_t *reg, uint8_t mask, uint32_t budget)
Spin until (*reg & mask) != 0 or budget runs out.
Definition ra8_hw_err.h:219
ra8_hw_err_budget_t
Default polling budgets for ra8_hw_wait_flag_*.
Definition ra8_hw_err.h:171
@ k_ra8_hw_budget_xlong
RA8 hw budget xlong.
Definition ra8_hw_err.h:175
@ k_ra8_hw_budget_medium
RA8 hw budget medium.
Definition ra8_hw_err.h:173
@ k_ra8_hw_budget_short
RA8 hw budget short.
Definition ra8_hw_err.h:172
@ k_ra8_hw_budget_long
RA8 hw budget long.
Definition ra8_hw_err.h:174
static ra8_err_t ra8_hw_wait_flag_clear32(volatile const uint32_t *reg, uint32_t mask, uint32_t budget)
Spin until (*reg & mask) == 0 or budget runs out.
Definition ra8_hw_err.h:351