auto_init_utils.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2022 Otto-von-Guericke-Universität Magdebug
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
27 #include <stdint.h>
28 #include "xfa.h"
29 #include "macros/xtstr.h"
30 #include "modules.h"
31 #if IS_USED(MODULE_PREPROCESSOR_SUCCESSOR)
32 #include "preprocessor_successor.h"
33 #endif
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #ifndef CONFIG_AUTO_INIT_ENABLE_DEBUG
43 #define CONFIG_AUTO_INIT_ENABLE_DEBUG 0
44 #endif
45 
49 typedef void (*auto_init_fn_t)(void);
50 
54 typedef uint16_t auto_init_prio_t;
55 
59 typedef struct {
61 #if IS_ACTIVE(CONFIG_AUTO_INIT_ENABLE_DEBUG) || defined(DOXYGEN)
63  const char *name;
64 #endif
66 
67 #if IS_ACTIVE(CONFIG_AUTO_INIT_ENABLE_DEBUG) || defined(DOXYGEN)
74 #define AUTO_INIT(function, priority) \
75  XFA_CONST(auto_init_module_t, auto_init_xfa, priority) \
76  auto_init_xfa_ ## function \
77  = { .init = (auto_init_fn_t)function, \
78  .prio = priority, \
79  .name = XTSTR(function) }
80 #else
81 #define AUTO_INIT(function, priority) \
82  XFA_CONST(auto_init_module_t, auto_init_xfa, priority) \
83  auto_init_xfa_ ## function \
84  = { .init = (auto_init_fn_t)function }
85 #endif
86 
91 #define AUTO_INIT_PRIORITY_AFTER(priority) RIOT_PP_SUCCESSOR(priority)
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
void(* auto_init_fn_t)(void)
Auto-init function type.
uint16_t auto_init_prio_t
Data type to store the priority of a module.
Common macros and compiler attributes/pragmas configuration.
Type to represent a module to be auto-initialized.
auto_init_prio_t prio
Module priority.
const char * name
Module auto-init function name.
auto_init_fn_t init
Function to initialize the module.
Cross File Arrays.
Macro to return string representation of x.