2 ******************************************************************************
3 * @addtogroup PIOS PIOS Initcall infrastructure
5 * @addtogroup PIOS_INITCALL Generic Initcall Macros
6 * @brief Initcall Macros
9 * @file pios_initcall.h
10 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
11 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010-2015
12 * @brief Initcall header
13 * @see The GNU Public License (GPL) Version 3
15 *****************************************************************************/
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 * You should have received a copy of the GNU General Public License along
28 * with this program; if not, write to the Free Software Foundation, Inc.,
29 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #ifndef PIOS_INITCALL_H
33 #define PIOS_INITCALL_H
36 * This implementation is heavily based on the Linux Kernel initcall
38 * http://lxr.linux.no/#linux/include/linux/init.h
39 * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=include/linux/init.h
43 * Used for initialization calls..
46 typedef int32_t (*initcall_t
)(void);
52 /* Init module section */
53 extern initmodule_t __module_initcall_start
[], __module_initcall_end
[];
54 extern volatile int initTaskDone
;
56 /* Init settings section */
57 extern initcall_t __settings_initcall_start
[], __settings_initcall_end
[];
61 extern void InitModules();
62 extern void StartModules();
63 extern int32_t SystemModInitialize(void);
65 #define MODULE_INITCALL(ifn, sfn)
67 #define SETTINGS_INITCALL(fn)
69 #define MODULE_TASKCREATE_ALL \
71 /* Start all module threads */ \
75 #define MODULE_INITIALISE_ALL \
77 /* Initialize modules */ \
79 /* Initialize the system thread */ \
80 SystemModInitialize(); \
83 #else // ifdef USE_SIM_POSIX
85 /* initcalls are now grouped by functionality into separate
86 * subsections. Ordering inside the subsections is determined
89 * The `id' arg to __define_initcall() is needed so that multiple initcalls
90 * can point at the same handler without causing duplicate-symbol build errors.
93 #define __define_initcall(level, fn, id) \
94 static initcall_t __initcall_##fn##id __attribute__((__used__)) \
95 __attribute__((__section__(".initcall" level ".init"))) = fn
97 #define __define_module_initcall(level, ifn, sfn) \
98 static initmodule_t __initcall_##ifn __attribute__((__used__)) \
99 __attribute__((__section__(".initcall" level ".init"))) = { .fn_minit = ifn, .fn_tinit = sfn }
101 #define __define_settings_initcall(level, fn) \
102 static initcall_t __initcall_##fn __attribute__((__used__)) \
103 __attribute__((__section__(".initcall" level ".init"))) = fn
106 #define MODULE_INITCALL(ifn, sfn) __define_module_initcall("module", ifn, sfn)
108 #define SETTINGS_INITCALL(fn) __define_settings_initcall("settings", fn)
110 #define MODULE_INITIALISE_ALL \
111 { for (initmodule_t *fn = __module_initcall_start; fn < __module_initcall_end; fn++) { \
112 if (fn->fn_minit) { \
113 (fn->fn_minit)(); } \
118 #define MODULE_TASKCREATE_ALL \
119 { for (initmodule_t *fn = __module_initcall_start; fn < __module_initcall_end; fn++) { \
120 if (fn->fn_tinit) { \
127 #define SETTINGS_INITIALISE_ALL \
128 { for (const initcall_t *fn = __settings_initcall_start; fn < __settings_initcall_end; fn++) { \
135 #endif /* USE_SIM_POSIX */
137 #endif /* PIOS_INITCALL_H */