ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_err.h File Reference

Error Code Definitions for ra8-firmware. More...

#include <stdint.h>
Include dependency graph for ra8_err.h:

Go to the source code of this file.

Typedefs

typedef ra8_err_codes_t ra8_err_t
 Canonical error-return type used by every ra8-firmware API.

Enumerations

enum  ra8_err_codes_t : uint16_t {
  k_ra8_ok = 0 ,
  k_ra8_fail = 0x101 ,
  k_ra8_err_no_mem = 0x102 ,
  k_ra8_err_invalid_arg = 0x103 ,
  k_ra8_err_invalid_state = 0x104 ,
  k_ra8_err_invalid_size = 0x105 ,
  k_ra8_err_not_found = 0x106 ,
  k_ra8_err_not_supported = 0x107 ,
  k_ra8_err_timeout = 0x108 ,
  k_ra8_err_busy = 0x109 ,
  k_ra8_err_no_data = 0x10A ,
  k_ra8_err_would_block = 0x10B ,
  k_ra8_err_exists = 0x10C ,
  k_ra8_err_empty = 0x10D ,
  k_ra8_err_cancelled = 0x10E ,
  k_ra8_err_not_initialized = 0x10F ,
  k_ra8_err_estop = 0x110 ,
  k_ra8_err_not_empty = 0x111 ,
  k_ra8_err_access_denied = 0x112 ,
  k_ra8_err_hw_init_failed = 0x201 ,
  k_ra8_err_hw_not_ready = 0x202 ,
  k_ra8_err_hw_timeout = 0x203 ,
  k_ra8_err_hw_error = 0x204 ,
  k_ra8_err_gpio_conflict = 0x205 ,
  k_ra8_err_gpio_invalid_port = 0x206 ,
  k_ra8_err_gpio_invalid_pin = 0x207 ,
  k_ra8_err_out_of_range = 0x208 ,
  k_ra8_err_hw_unmapped = 0x209 ,
  k_ra8_err_rtos_error = 0x301 ,
  k_ra8_err_rtos_thread_create = 0x302 ,
  k_ra8_err_rtos_semaphore = 0x303 ,
  k_ra8_err_rtos_mutex = 0x304 ,
  k_ra8_err_rtos_queue = 0x305 ,
  k_ra8_err_rtos_timer = 0x306 ,
  k_ra8_err_comm_error = 0x401 ,
  k_ra8_err_spi_error = 0x402 ,
  k_ra8_err_uart_error = 0x403 ,
  k_ra8_err_i2c_error = 0x404 ,
  k_ra8_err_crc_mismatch = 0x405 ,
  k_ra8_err_protocol_error = 0x406 ,
  k_ra8_err_nack = 0x407 ,
  k_ra8_err_conflict = 0x408 ,
  k_ra8_err_retry_limit = 0x409 ,
  k_ra8_err_validation_failed = 0x501 ,
  k_ra8_err_checksum_mismatch = 0x502 ,
  k_ra8_err_range_check_failed = 0x503 ,
  k_ra8_err_null_ptr = 0x504 ,
  k_ra8_err_decomp_output_cap = 0x505 ,
  k_ra8_err_decomp_ratio = 0x506 ,
  k_ra8_err_decomp_entries = 0x507 ,
  k_ra8_err_decomp_depth = 0x508 ,
  k_ra8_err_decomp_iterations = 0x509
}
 Canonical error code list for ra8-firmware. More...

Functions

static bool ra8_err_is_error (ra8_err_t err)
 Test whether a code represents failure.
const char * ra8_err_to_str (ra8_err_t err)
 Human-readable string for an error code.

Detailed Description

Error Code Definitions for ra8-firmware.

Single source of truth for all error codes returned across the firmware. Every public API that can fail returns ra8_err_t; every caller checks it via the macros in ra8_check.h (RA8_RETURN_ON_ERROR, RA8_ERROR_CHECK, etc.). There are no other error channels (no errno, no exceptions, no longjmp, no global error flags) – this is NASA Power of 10 Rule 7 ("check all return values") enforced at the type level.

Design

  • Single enum: one ra8_err_codes_t with uint16_t underlying type holds every possible error, organised by category (0x1xx generic, 0x2xx hardware, 0x3xx RTOS, 0x4xx communication, 0x5xx validation).
  • 0 is success: k_ra8_ok == 0 so the idiom if (err) treats any non-zero value as a failure without requiring != k_ra8_ok.
  • Stable numeric values: values are explicit (= 0x101 etc.) so remote logging, telemetry and debugger views can decode codes without needing the source.
  • C23 typed enum: typedef enum : uint16_t { ... } pins the underlying type at 2 bytes, keeping struct layouts stable across compilers and host/target builds.

Usage pattern

{
RA8_CHECK_NULL_PTR(cfg, "SCI", "cfg must not be nullptr");
if (cfg->channel >= k_ra8_sci_channel_count) {
return k_ra8_err_gpio_invalid_port; // reusing a generic "out-of-range" code
}
if (g_initialized[cfg->channel]) {
}
// ... programme the peripheral ...
g_initialized[cfg->channel] = true;
return k_ra8_ok;
}
#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_exists
Item already exists – cannot create again.
Definition ra8_err.h:216
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_gpio_invalid_port
GPIO port index out of range for this MCU.
Definition ra8_err.h:325
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 ra8_sci_init(uint8_t channel, const ra8_sci_cfg_t *cfg)
Initialise an SCI channel using the descriptor.
Definition ra8_sci.c:410
@ k_ra8_sci_channel_count
SCI0..SCI9.
Configuration descriptor for ra8_sci_init.
Definition ra8_sci.h:103

Category layout

Range Category Typical source
0x000 Success Normal return
0x101 – 0x1FF Generic Argument/state/lifecycle
0x201 – 0x2FF Hardware Peripheral init, GPIO, sensor range, faults
0x301 – 0x3FF RTOS (reserved) Future RTOS (not used in v0.x bare-metal)
0x401 – 0x4FF Communication Bus-level errors, framing, CRC
0x501 – 0x5FF Validation Assertion and pre/post-condition failures

The RTOS category is preserved (identical values to the rx72n project) so that any shared utility code can be moved between projects without renumbering. The bare-metal firmware does not currently return any k_ra8_err_rtos_* code.

NASA Power of 10 Compliance

  • Rule 5: error codes ARE the assertion vocabulary. Every check in ra8_check.h returns one of the values below.
  • Rule 7: every API that can fail returns ra8_err_t. [[nodiscard]] is applied to the important ones so ignoring the return is a compile error, not a warning.
  • Rule 8: uses a C23 typed enum (: uint16_t), not #defines.
  • Rule 10: compiles clean with -Wall -Wextra -Werror.

Definition in file ra8_err.h.

Typedef Documentation

◆ ra8_err_t

Canonical error-return type used by every ra8-firmware API.

Always returns a value from ra8_err_codes_t. Use the helpers in ra8_check.h to propagate and check.

Note
Defined as a distinct typedef rather than using the enum name directly so the error-code set can be extended without touching every function signature in the tree.

Definition at line 546 of file ra8_err.h.

Enumeration Type Documentation

◆ ra8_err_codes_t

enum ra8_err_codes_t : uint16_t

Canonical error code list for ra8-firmware.

Every public API that can fail returns one of these values cast to ra8_err_t. Values are grouped by category and use stable hexadecimal numbering so logs, telemetry, and debugger watch expressions decode without needing source.

Invariant
k_ra8_ok == 0 (success is the only zero value).
All error values are within uint16_t range.
No two distinct error names share a value (except documented aliases such as k_ra8_err_threadx).
Note
This enum is pinned to uint16_t. Do NOT rely on implicit conversion to int in public API signatures; always use the typedef ra8_err_t.
Enumerator
k_ra8_ok 

Success – operation completed with all postconditions satisfied.

The only non-error value. Callers should always compare against k_ra8_ok rather than the numeric 0 for clarity.

k_ra8_fail 

Generic unspecified failure.

Last-resort code when nothing more specific fits. Prefer a purpose-built code when one exists.

Value: 0x101
k_ra8_err_no_mem 

Static buffer exhausted (no dynamic memory on this project).

Returned when a statically-sized pool / ring / queue has no space left. In a zero-alloc system this almost always means the buffer was sized too small for the worst-case load.

Value: 0x102
k_ra8_err_invalid_arg 

Invalid function argument.

Parameter out of range, NULL where non-NULL required, or logically inconsistent inputs.

Value: 0x103
See also
k_ra8_err_null_ptr More specific: pointer was NULL
k_ra8_err_range_check_failed More specific: numeric out of range
k_ra8_err_invalid_state 

Module in wrong state for requested operation.

E.g. calling _start() before _init() succeeded, or _init() twice in a row.

Value: 0x104
See also
k_ra8_err_not_initialized More specific: init() never ran
k_ra8_err_invalid_size 

Invalid size parameter (too large, too small, or misaligned).

Value: 0x105
k_ra8_err_not_found 

Requested item not found (lookup / search missed).

Value: 0x106
k_ra8_err_not_supported 

Requested feature not compiled in, not wired, or not supported by this MCU variant.

Value: 0x107
k_ra8_err_timeout 

Operation exceeded its time budget.

Generic timeout. For hardware-specific waits (e.g. PLL lock, peripheral busy) prefer k_ra8_err_hw_timeout.

Value: 0x108
k_ra8_err_busy 

Resource busy – blocking operation cannot proceed.

Value: 0x109
See also
k_ra8_err_would_block Non-blocking flavour
k_ra8_err_no_data 

No application data available (e.g.

only a control frame arrived).

Not a failure condition – the caller should continue polling.

Value: 0x10A
k_ra8_err_would_block 

Non-blocking operation would have blocked.

Returned by non-blocking APIs when the underlying resource is not immediately available.

Value: 0x10B
k_ra8_err_exists 

Item already exists – cannot create again.

Value: 0x10C
k_ra8_err_empty 

Container empty – nothing to retrieve.

Value: 0x10D
k_ra8_err_cancelled 

Operation cancelled before completion.

The operation had no side effects (atomic cancellation).

Value: 0x10E
k_ra8_err_not_initialized 

Module not initialized – _init() not yet called successfully.

Value: 0x10F
k_ra8_err_estop 

Emergency stop active – operation forbidden until cleared.

Safety-critical: do not bypass. Once set, requires explicit reset via the safety supervisor.

Value: 0x110
Warning
This is a safety latch. Never return this code from a fast path without also driving the hardware into a safe state.
k_ra8_err_not_empty 

Container still holds members – the operation requires it empty.

The exact inverse of k_ra8_err_empty: that one reports "nothing to retrieve", this one reports "something is still in there". Returned by ra8_fs_rmdir() for a directory that still has entries, the POSIX ENOTEMPTY condition. Distinct from k_ra8_err_invalid_arg on purpose: a caller that wants to remove a tree must be able to tell "you named the wrong thing" from "empty it first and retry".

Value: 0x111
k_ra8_err_access_denied 

Operation refused because the target is protected against it.

The POSIX EACCES condition, returned when a mutating request is denied by a permission the target itself carries rather than by a bad argument or a broken device. Its first use is the FAT/exFAT read-only attribute: ra8_fs_open() for writing, ra8_fs_write_file(), ra8_fs_unlink() and ra8_fs_rename() return it rather than overwrite or delete a file a host marked read-only. The bit is checked at OPEN time, so ra8_fs_write() on a handle opened before the file became read-only is unaffected. Distinct from k_ra8_err_invalid_arg, which says the request was malformed: here the request is well-formed and the answer is "not allowed".

Value: 0x112
See also
k_ra8_err_invalid_arg Malformed request, not a protected target.
k_ra8_err_hw_init_failed 

Hardware peripheral failed to initialise.

Clock gating failed, register verify failed, or the block never reached ready state.

Value: 0x201
k_ra8_err_hw_not_ready 

Hardware peripheral exists but not ready yet.

Examples: PLL not locked, ADC not calibrated, LVD still below threshold.

Value: 0x202
k_ra8_err_hw_timeout 

Hardware timed out waiting for a flag or handshake.

Value: 0x203
k_ra8_err_hw_error 

Generic hardware fault detected (error flag set, fault interrupt).

Value: 0x204
k_ra8_err_gpio_conflict 

GPIO pin already owned by another peripheral or driver.

Raised by ra8_pin_validator when two modules both try to claim the same pin.

Value: 0x205
k_ra8_err_gpio_invalid_port 

GPIO port index out of range for this MCU.

Valid RA8D2 ports are 0..14 (not all pins bonded out on BGA 289).

Value: 0x206
k_ra8_err_gpio_invalid_pin 

GPIO pin index out of range within its port (valid: 0..15).

Value: 0x207
k_ra8_err_out_of_range 

Sensor or peripheral output out of valid range.

Value: 0x208
k_ra8_err_hw_unmapped 

Peripheral register block is not mapped in this MCU variant.

Raised when driver code is built for a chip that does not actually have the addressed peripheral.

Value: 0x209
k_ra8_err_rtos_error 

Generic RTOS error (reserved for future use).

Value: 0x301
k_ra8_err_rtos_thread_create 

Thread create failed (reserved for future use).

Value: 0x302
k_ra8_err_rtos_semaphore 

Semaphore API error (reserved for future use).

Value: 0x303
k_ra8_err_rtos_mutex 

Mutex API error (reserved for future use).

Value: 0x304
k_ra8_err_rtos_queue 

Queue / message API error (reserved for future use).

Value: 0x305
k_ra8_err_rtos_timer 

Timer API error (reserved for future use).

Value: 0x306
k_ra8_err_comm_error 

Generic communication error (use a more specific code when possible).

Value: 0x401
k_ra8_err_spi_error 

SPI transfer failed (bus fault, mode fault, overrun, ...).

Value: 0x402
k_ra8_err_uart_error 

UART / SCI error (framing, parity, overrun, break).

Value: 0x403
k_ra8_err_i2c_error 

I2C / IIC error (arbitration lost, NACK, timeout, bus error).

Value: 0x404
k_ra8_err_crc_mismatch 

CRC mismatch detected on received data.

Value: 0x405
k_ra8_err_protocol_error 

Protocol-level error (e.g.

unexpected opcode, bad sequence number).

Value: 0x406
k_ra8_err_nack 

Peer responded with NACK (negative acknowledgement).

Value: 0x407
k_ra8_err_conflict 

Conflict with concurrent access detected.

Value: 0x408
k_ra8_err_retry_limit 

Retry budget exhausted – operation still failing after all attempts.

Value: 0x409
k_ra8_err_validation_failed 

Validation rule failed (caller-supplied invariant not satisfied).

Value: 0x501
k_ra8_err_checksum_mismatch 

Stored / transmitted checksum does not match computed value.

Value: 0x502
k_ra8_err_range_check_failed 

Value outside range enforced by RA8_CHECK_RANGE / RA8_CHECK_RANGE_TAG.

Value: 0x503
k_ra8_err_null_ptr 

Pointer was NULL where a valid pointer was required.

This is the value returned by RA8_CHECK_NULL_PTR.

Value: 0x504
k_ra8_err_decomp_output_cap 

Decompression output cap breached (ra8_decomp_limits_t).

A decode unit (one archive member or one wrapped stream) either declared or actually produced more bytes than the policy's max_output_bytes. The decoder stops fail-closed; nothing past the cap is written.

Value: 0x505
See also
ra8_decomp_limits.h The unified decompression-limits policy.
k_ra8_err_decomp_ratio 

Compression ratio bound breached (ra8_decomp_limits_t).

A decode unit's output exceeded input * max_ratio + ratio_grace_bytes – the decompression-bomb signature. The decoder stops fail-closed at the breach point.

Value: 0x506
See also
ra8_decomp_limits.h The unified decompression-limits policy.
k_ra8_err_decomp_entries 

Archive entry-count cap breached (ra8_decomp_limits_t).

An archive enumerated more members than the policy's max_entries – the many-tiny-entries resource-exhaustion shape. The whole archive is rejected fail-closed.

Value: 0x507
See also
ra8_decomp_limits.h The unified decompression-limits policy.
k_ra8_err_decomp_depth 

Container nesting-depth cap breached (ra8_decomp_limits_t).

Decoder plumbing was asked to stack more layers (e.g. a compressed stream inside a compressed stream) than the policy's max_depth – the recursive-bomb shape. Rejected fail-closed before any inner decode starts.

Value: 0x508
See also
ra8_decomp_limits.h The unified decompression-limits policy.
k_ra8_err_decomp_iterations 

Decode-loop iteration budget exhausted (ra8_decomp_limits_t).

A decode loop charged more iterations than the policy's max_iterations without finishing – the stuck-stream / no-progress shape (NASA P10 Rule 2 backstop). The decoder stops fail-closed.

Value: 0x509
See also
ra8_decomp_limits.h The unified decompression-limits policy.

Definition at line 108 of file ra8_err.h.

Function Documentation

◆ ra8_err_is_error()

bool ra8_err_is_error ( ra8_err_t err)
inlinestatic

Test whether a code represents failure.

Parameters
[in]errCode to test.
Returns
true if err != k_ra8_ok, false otherwise.
Note
Inline, zero overhead. Provided so call sites can read as if (ra8_err_is_error(err)) instead of if (err != k_ra8_ok).

See implementation for details.

Return values
0Success or default value.
Precondition
Module has been initialized.
Caller has validated arguments.
Postcondition
Side effects bounded to documented state.
State reflects operation result.
Since
0.1.0

Definition at line 568 of file ra8_err.h.

References k_ra8_ok.

◆ ra8_err_to_str()

const char * ra8_err_to_str ( ra8_err_t err)

Human-readable string for an error code.

Returns a pointer to a static literal describing the code. Useful for logging and UART dumps. The returned pointer is valid for the lifetime of the program and must NOT be freed.

Parameters
[in]errCode to look up.
Returns
Pointer to a static C string. Never NULL; an unknown code returns the literal "unknown".
Return values
okReturned for k_ra8_ok.
<name>Returned for any known k_ra8_err_* code.
unknownReturned for any code not in the lookup table.
Precondition
None – pure lookup; safe to call before init.
Module-level lookup table s_ra8_err_names is fully populated.
Postcondition
No internal state is modified.
Returned pointer remains valid for the program lifetime.
Note
Implementation lives in ra8_err.c. Declared [[nodiscard]]-free intentionally: it is common to pass the result straight into a variadic log macro. Thread-safe – pure read of .rodata.
Since
0.1.0

Human-readable string for an error code.

Walks s_ra8_err_names and returns the matching name. Returns the literal "unknown" if no entry matches.

Parameters
[in]errError code to look up.
Returns
Pointer to a static C string. Never NULL.
Return values
okReturned for k_ra8_ok.
<name>Returned for any known k_ra8_err_* code.
unknownReturned for any code not in the table.
Precondition
None – pure lookup.
Module-level table is populated at compile time.
Postcondition
No state modified.
Returned pointer remains valid for the program lifetime.
Note
Thread-safe (read-only walk of .rodata).
Since
0.1.0

Definition at line 737 of file ra8_log.c.

References s_ra8_err_names, and s_ra8_err_names_count.

Referenced by c6_cam_camera_report_last_error(), c6_fwver_phase_caps(), c6_fwver_phase_request(), c6_fwver_worker_entry(), c6_hosted_worker_entry(), c6_join_phase_ip(), c6_join_phase_ready(), c6_join_report_fault(), c6_join_worker_entry(), c6_wifi_phase_ready(), c6_wifi_report_fault(), c6_wifi_worker_entry(), internal_c6_cam_http_frame(), internal_c6_cam_join(), internal_c6_cam_prepare_camera(), internal_c6_cam_prepare_link(), internal_c6_cam_prepare_media(), internal_c6_cam_report_fault(), internal_c6_cam_worker_entry(), internal_fail(), internal_report_sccb_state(), sensor_report_register(), wifi_hal_report(), wifi_hal_run(), and wifi_hal_worker_entry().