ra8-firmware
0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_attributes.h
Go to the documentation of this file.
1
39
40
#pragma once
41
42
#ifdef __cplusplus
43
extern
"C"
{
44
#endif
45
46
/* =============================================================================
47
* Backend selection
48
*
49
* Each RA8_* annotation macro lowers to `[[clang::annotate("...")]]` under
50
* clang and is exposed through libclang as `clang_Cursor_getAnnotations`. The
51
* C23/C++11 attribute-specifier form is used (not the GNU
52
* `__attribute__((annotate(...)))` form) because it is the spelling libclang
53
* surfaces on a declaration. GCC parses the same syntax silently but does not
54
* surface it; either way codegen is unaffected. We gate on `__clang__` so
55
* non-clang toolchains compile a literal no-op (a pure comment placeholder).
56
*
57
* These annotations attach to a DECLARATION -- a function, variable, or type --
58
* and NOWHERE ELSE. `[[clang::annotate]]` is not valid in statement position:
59
* clang rejects `[[clang::annotate("x")]] for (...)` as "'annotate' attribute
60
* cannot be applied to a statement", and under a non-clang toolchain the
61
* comment no-op evaporates, binding to nothing. A per-LOOP bound therefore
62
* cannot be one of these annotations, and a statement-position
63
* `RA8_BOUNDED_LOOP(x);` was for that reason a hard clang error and a silent
64
* GCC no-op that bound to no loop at all. `RA8_BOUNDED_LOOP` (section 15) is a
65
* FUNCTION-level annotation: it decorates the function declaration and the
66
* checker walks that function's loops. To bind a bound to ONE specific loop in
67
* statement position, use `RA8_LOOP_BOUND` / `RA8_LOOP_BOUND_RUNTIME`
68
* (sections 15b/15c) -- these are real C (a `static_assert`, or a symbol
69
* reference), not annotations, so they compile and are enforced identically
70
* under every toolchain and cannot degrade to a no-op.
71
*
72
* `__CPPCHECK__` is excluded because cppcheck's C parser cannot represent a
73
* scoped attribute carrying a string argument: on `[[clang::annotate("x")]]`
74
* it mis-parses the declaration that follows, and the damaged parse surfaces
75
* as phantom MISRA findings in the annotated function (14.2 / 16.2 / 17.3
76
* appearing where the source has no loop, no switch and no implicit
77
* declaration, plus inflated 15.5 exit-point counts). cppcheck explores both
78
* arms of the `#ifdef` above, so without this exclusion the audit reports the
79
* defects of a configuration that is never built. The firmware ships compiled
80
* by arm-none-eabi-gcc, where these macros are already comments -- pinning
81
* cppcheck to that arm analyses the code that actually ships, and keeps the
82
* annotation visible to clang-tidy and to the libclang annotation gate
83
* (`scripts/checks/check_annotations.py`), neither of which defines
84
* `__CPPCHECK__`. Suppressing the rules or absorbing the findings into the
85
* MISRA baseline instead would blind the ratchet to real defects in every
86
* annotated file.
87
* =============================================================================
88
*/
89
90
#if defined(__clang__) && !defined(__CPPCHECK__)
92
#define RA8_INTERNAL_ANNOTATE(tag) [[clang::annotate(tag)]]
93
#else
95
#define RA8_INTERNAL_ANNOTATE(tag)
/* annotation: tag */
96
#endif
97
116
#define RA8_INTERNAL_ANNOTATE_ARG(tag, arg) RA8_INTERNAL_ANNOTATE(tag arg)
117
138
#define RA8_NODISCARD __attribute__((warn_unused_result))
/* ATTR-OK: cppcheck 2.13, C23 gap */
139
140
/* =============================================================================
141
* 1. RA8_TEST_HELPER
142
* =============================================================================
143
*/
144
166
#define RA8_TEST_HELPER RA8_INTERNAL_ANNOTATE("ra8_test_helper")
167
168
/* =============================================================================
169
* 2. RA8_INTERNAL
170
* =============================================================================
171
*/
172
190
#define RA8_INTERNAL RA8_INTERNAL_ANNOTATE("ra8_internal")
191
192
/* =============================================================================
193
* 3. RA8_PRIV
194
* =============================================================================
195
*/
196
219
#define RA8_PRIV RA8_INTERNAL_ANNOTATE("ra8_priv")
220
221
/* =============================================================================
222
* 4. RA8_DI_SLOT(role)
223
* =============================================================================
224
*/
225
251
#define RA8_DI_SLOT(role) RA8_INTERNAL_ANNOTATE_ARG("ra8_di_slot:", role)
252
253
/* =============================================================================
254
* 5. RA8_NSC_VENEER
255
* =============================================================================
256
*/
257
296
#define RA8_NSC_VENEER RA8_INTERNAL_ANNOTATE("ra8_nsc_veneer")
297
298
/* =============================================================================
299
* 6. RA8_HW_REGISTER_ACCESS
300
* =============================================================================
301
*/
302
326
#define RA8_HW_REGISTER_ACCESS RA8_INTERNAL_ANNOTATE("ra8_hw_register_access")
327
328
/* =============================================================================
329
* 7. RA8_NASA_RULE_3_OK(reason)
330
* =============================================================================
331
*/
332
360
#define RA8_NASA_RULE_3_OK(reason) RA8_INTERNAL_ANNOTATE_ARG("ra8_nasa_rule_3_ok:", reason)
361
362
/* =============================================================================
363
* 8. RA8_MCDC_DEACTIVATED(reason)
364
* =============================================================================
365
*/
366
394
#define RA8_MCDC_DEACTIVATED(reason) RA8_INTERNAL_ANNOTATE_ARG("ra8_mcdc_deactivated:", reason)
395
396
/* =============================================================================
397
* 9. RA8_MAX_STACK(bytes)
398
* =============================================================================
399
*/
400
423
#define RA8_MAX_STACK(bytes) RA8_INTERNAL_ANNOTATE("ra8_max_stack:" #bytes)
424
425
/* =============================================================================
426
* 10. RA8_ISR_SAFE
427
* =============================================================================
428
*/
429
451
#define RA8_ISR_SAFE RA8_INTERNAL_ANNOTATE("ra8_isr_safe")
452
453
/* =============================================================================
454
* 11. RA8_EXPECTS_LOCK(name)
455
* =============================================================================
456
*/
457
499
#define RA8_EXPECTS_LOCK(name) RA8_INTERNAL_ANNOTATE_ARG("ra8_expects_lock:", name)
500
501
/* =============================================================================
502
* 12. RA8_HOST_FRIENDLY
503
* =============================================================================
504
*/
505
526
#define RA8_HOST_FRIENDLY RA8_INTERNAL_ANNOTATE("ra8_host_friendly")
527
528
/* =============================================================================
529
* 13. RA8_LATENCY_BUDGET_NS(n)
530
* =============================================================================
531
*/
532
554
#define RA8_LATENCY_BUDGET_NS(n) RA8_INTERNAL_ANNOTATE("ra8_latency_budget_ns:" #n)
555
556
/* =============================================================================
557
* 14. RA8_NO_RECURSION
558
* =============================================================================
559
*/
560
581
#define RA8_NO_RECURSION RA8_INTERNAL_ANNOTATE("ra8_no_recursion")
582
583
/* =============================================================================
584
* 15. RA8_BOUNDED_LOOP(symbol)
585
* =============================================================================
586
*/
587
623
#define RA8_BOUNDED_LOOP(symbol) RA8_INTERNAL_ANNOTATE("ra8_bounded_loop:" #symbol)
624
625
/* =============================================================================
626
* 15b. RA8_LOOP_BOUND(ceiling)
627
* =============================================================================
628
*/
629
674
#define RA8_LOOP_BOUND(ceiling) \
675
static_assert((uint32_t)(ceiling) > 0U, \
676
"RA8_LOOP_BOUND requires a positive compile-time constant bound")
677
678
/* =============================================================================
679
* 15c. RA8_LOOP_BOUND_RUNTIME(ceiling_ref)
680
* =============================================================================
681
*/
682
726
#define RA8_LOOP_BOUND_RUNTIME(ceiling_ref) ((void)sizeof(&(ceiling_ref)))
727
728
/* =============================================================================
729
* 16. RA8_VALIDATES(n)
730
* =============================================================================
731
*/
732
754
#define RA8_VALIDATES(n) RA8_INTERNAL_ANNOTATE("ra8_validates:" #n)
755
756
/* =============================================================================
757
* 17. RA8_OWNS_RESOURCE(kind)
758
* =============================================================================
759
*/
760
785
#define RA8_OWNS_RESOURCE(kind) RA8_INTERNAL_ANNOTATE_ARG("ra8_owns_resource:", kind)
786
816
#define RA8_RELEASES_RESOURCE(kind) RA8_INTERNAL_ANNOTATE_ARG("ra8_releases_resource:", kind)
817
818
/* =============================================================================
819
* 18. RA8_REVIEWED_BY(name)
820
* =============================================================================
821
*/
822
846
#define RA8_REVIEWED_BY(name) RA8_INTERNAL_ANNOTATE_ARG("ra8_reviewed_by:", name)
847
848
/* =============================================================================
849
* 19. RA8_REGISTER_BANK(peripheral)
850
* =============================================================================
851
*/
852
878
#define RA8_REGISTER_BANK(peripheral) RA8_INTERNAL_ANNOTATE_ARG("ra8_register_bank:", peripheral)
879
880
#ifdef __cplusplus
881
}
882
#endif
libs
ra8_core
inc
ra8_attributes.h
Generated by
1.16.1