ChibiOS/HAL 9.0.0
ccportab.h
Go to the documentation of this file.
1/*
2 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file GCC/ccportab.h
19 * @brief Compiler portability layer.
20 *
21 * @defgroup CC_PORTAB Compiler portability.
22 * @{
23 */
24
25#ifndef CCPORTAB_H
26#define CCPORTAB_H
27
28/*===========================================================================*/
29/* Module constants. */
30/*===========================================================================*/
31
32/*===========================================================================*/
33/* Module pre-compile time settings. */
34/*===========================================================================*/
35
36/*===========================================================================*/
37/* Derived constants and error checks. */
38/*===========================================================================*/
39
40/*===========================================================================*/
41/* Module data structures and types. */
42/*===========================================================================*/
43
44/*===========================================================================*/
45/* Module macros. */
46/*===========================================================================*/
47
48/**
49 * @name Compiler abstraction macros
50 * @{
51 */
52/**
53 * @brief Allocates a variable or function to a specific section.
54 * @note If the compiler does not support such a feature then this macro
55 * must not be defined or it could originate errors.
56 */
57#define CC_SECTION(s) __attribute__((section(s)))
58
59/**
60 * @brief Marks a function or variable as a weak symbol.
61 * @note If the compiler does not support such a feature then this macro
62 * must not be defined or it could originate errors.
63 */
64#define CC_WEAK __attribute__((weak))
65
66/**
67 * @brief Marks a function or variable as used.
68 * @details The compiler or linker shall not remove the marked function or
69 * variable regardless if it is referred or not in the code.
70 * @note If the compiler does not support such a feature then this macro
71 * must not be defined or it could originate errors.
72 */
73#define CC_USED __attribute__((used))
74
75/**
76 * @brief Enforces alignment of the variable declared afterward.
77 * @note If the compiler does not support such a feature then this macro
78 * must not be defined or it could originate errors.
79 */
80#define CC_ALIGN_DATA(n) __attribute__((aligned(n)))
81
82/**
83 * @brief Enforces alignment of a function declared afterward.
84 * @note If the compiler does not support such a feature then this macro
85 * must not be defined or it could originate errors.
86 */
87#define CC_ALIGN_CODE(n) __attribute__((aligned(n)))
88
89/**
90 * @brief Enforces packing of the structure declared afterward.
91 * @note If the compiler does not support such a feature then this macro
92 * must not be defined or it could originate errors.
93 */
94#define CC_PACK __attribute__((packed))
95
96/**
97 * @brief Marks a function as not inlineable.
98 * @note Can be implemented as an empty macro if not supported by the
99 * compiler.
100 */
101#define CC_NO_INLINE __attribute__((noinline))
102
103/**
104 * @brief Enforces a function inline.
105 * @note Can be implemented as an empty macro if not supported by the
106 * compiler.
107 */
108#define CC_FORCE_INLINE __attribute__((always_inline))
109
110/**
111 * @brief Marks a function as non-returning.
112 * @note Can be implemented as an empty macro if not supported by the
113 * compiler.
114 */
115#define CC_NO_RETURN __attribute__((noreturn))
116
117/**
118 * @brief Enforces a variable in a ROM area.
119 * @note Can be implemented as an empty macro if not supported by the
120 * compiler.
121 */
122#define CC_ROMCONST const
123
124/**
125 * @brief Marks a boolean expression as likely true.
126 *
127 * @param[in] x a valid expression
128 */
129#define CC_LIKELY(x) __builtin_expect(!!(x), 1)
130
131/**
132 * @brief Marks a boolean expression as likely false.
133 *
134 * @param[in] x a valid expression
135 */
136#define CC_UNLIKELY(x) __builtin_expect(!!(x), 0)
137/** @} */
138
139/*===========================================================================*/
140/* External declarations. */
141/*===========================================================================*/
142
143#ifdef __cplusplus
144extern "C" {
145#endif
146
147#ifdef __cplusplus
148}
149#endif
150
151/*===========================================================================*/
152/* Module inline functions. */
153/*===========================================================================*/
154
155#endif /* CCPORTAB_H */
156
157/** @} */