ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_check.h
Go to the documentation of this file.
1
57
58#pragma once
59
60#ifdef __cplusplus
61extern "C" {
62#endif
63
64#include <stdint.h>
65
66#include "ra8_err.h"
67#include "ra8_log.h"
68
69/* =============================================================================
70 * Fatal-error sink
71 * =============================================================================
72 */
73
74/* ra8_fatal_error is declared in ra8_error_handler.h. Include
75 * it here so RA8_ASSERT / RA8_ERROR_CHECK can call it without the caller
76 * having to pull in the other header. */
77#include "ra8_error_handler.h"
78
79/* =============================================================================
80 * Static assertion -- enforces compile-time invariants
81 * =============================================================================
82 */
83
99#define RA8_STATIC_ASSERT(cond, msg) static_assert((cond), msg)
100
101/* =============================================================================
102 * Runtime assertion
103 * =============================================================================
104 */
105
123#define RA8_ASSERT(condition, message) \
124 do { \
125 if (!(condition)) { \
126 ra8_fatal_error("ASSERT", (message), (uint32_t)k_ra8_err_validation_failed); \
127 } \
128 } while (0)
129
130/* =============================================================================
131 * Error propagation
132 * =============================================================================
133 */
134
147#define RA8_ERROR_CHECK(err) \
148 do { \
149 ra8_err_t err_rc_ = (err); \
150 if (ra8_err_is_error(err_rc_)) { \
151 ra8_fatal_error("ERROR_CHECK", "Fatal error", (uint32_t)err_rc_); \
152 } \
153 } while (0)
154
165#define RA8_ERROR_CHECK_NO_ABORT(err) \
166 do { \
167 ra8_err_t err_rc_ = (err); \
168 if (ra8_err_is_error(err_rc_)) { \
169 ra8_log_error_val("ERROR_CHECK", "Non-fatal error", (uint32_t)err_rc_); \
170 } \
171 } while (0)
172
184#define RA8_RETURN_ON_ERROR(err, tag, message) \
185 do { \
186 ra8_err_t err_rc_ = (err); \
187 if (ra8_err_is_error(err_rc_)) { \
188 ra8_log_error((tag), (message)); \
189 ra8_log_error_val((tag), "Error", (uint32_t)err_rc_); \
190 return err_rc_; \
191 } \
192 } while (0)
193
201#define RA8_RETURN_VOID_ON_ERROR(err, tag, message) \
202 do { \
203 ra8_err_t err_rc_ = (err); \
204 if (ra8_err_is_error(err_rc_)) { \
205 ra8_log_error((tag), (message)); \
206 ra8_log_error_val((tag), "Error", (uint32_t)err_rc_); \
207 return; \
208 } \
209 } while (0)
210
218#define RA8_RETURN_NULL_ON_ERROR(err, tag, message) \
219 do { \
220 ra8_err_t err_rc_ = (err); \
221 if (ra8_err_is_error(err_rc_)) { \
222 ra8_log_error((tag), (message)); \
223 ra8_log_error_val((tag), "Error", (uint32_t)err_rc_); \
224 return nullptr; \
225 } \
226 } while (0)
227
228/* =============================================================================
229 * Precondition checks
230 * =============================================================================
231 */
232
243#define RA8_CHECK_NULL_PTR(ptr, tag, message) \
244 do { \
245 if ((ptr) == nullptr) { \
246 ra8_log_error((tag), (message)); \
247 return k_ra8_err_null_ptr; \
248 } \
249 } while (0)
250
276#define RA8_CHECK_NULL_PTR_RETURN(ptr, return_value, tag, message) \
277 do { \
278 if ((ptr) == nullptr) { \
279 ra8_log_error((tag), (message)); \
280 return (return_value); \
281 } \
282 } while (0)
283
292#define RA8_CHECK_RANGE(value, min, max, errcode) \
293 do { \
294 if (((value) < (min)) || ((value) > (max))) { \
295 ra8_log_error("CHECK", "Range check failed"); \
296 return (errcode); \
297 } \
298 } while (0)
299
311#define RA8_CHECK_RANGE_TAG(value, min, max, errcode, tag) \
312 do { \
313 (void)(min); \
314 if ((value) > (max)) { \
315 ra8_log_error((tag), "Range check failed"); \
316 return (errcode); \
317 } \
318 } while (0)
319
323#define RA8_VALIDATE_PTR(ptr, tag, message) RA8_CHECK_NULL_PTR(ptr, tag, message)
324
334#define RA8_VALIDATE_INIT(initialized, tag, message) \
335 do { \
336 if (!(initialized)) { \
337 ra8_log_error((tag), (message)); \
338 return k_ra8_err_not_initialized; \
339 } \
340 } while (0)
341
342#ifdef __cplusplus
343}
344#endif
Error Code Definitions for ra8-firmware.
Centralised fatal-error sink.
Lightweight Logging Interface for ra8-firmware.