OP-1516 fixed boundf mistake
[librepilot.git] / flight / pios / inc / pios_initcall.h
blob2b9f324188ae2ec1645cfbeb6deb6524150da2ad
1 /**
2 ******************************************************************************
3 * @addtogroup PIOS PIOS Initcall infrastructure
4 * @{
5 * @addtogroup PIOS_INITCALL Generic Initcall Macros
6 * @brief Initcall Macros
7 * @{
9 * @file pios_initcall.h
10 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2011.
11 * @brief Initcall header
12 * @see The GNU Public License (GPL) Version 3
14 *****************************************************************************/
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * for more details.
26 * You should have received a copy of the GNU General Public License along
27 * with this program; if not, write to the Free Software Foundation, Inc.,
28 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #ifndef PIOS_INITCALL_H
32 #define PIOS_INITCALL_H
35 * This implementation is heavily based on the Linux Kernel initcall
36 * infrastructure:
37 * http://lxr.linux.no/#linux/include/linux/init.h
38 * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=include/linux/init.h
42 * Used for initialization calls..
45 typedef int32_t (*initcall_t)(void);
46 typedef struct {
47 initcall_t fn_minit;
48 initcall_t fn_tinit;
49 } initmodule_t;
51 /* Init module section */
52 extern initmodule_t __module_initcall_start[], __module_initcall_end[];
54 #ifdef USE_SIM_POSIX
56 extern void InitModules();
57 extern void StartModules();
59 #define MODULE_INITCALL(ifn, sfn)
61 #define MODULE_TASKCREATE_ALL \
62 { \
63 /* Start all module threads */ \
64 StartModules(); \
67 #define MODULE_INITIALISE_ALL \
68 { \
69 /* Initialize modules */ \
70 InitModules(); \
71 /* Initialize the system thread */ \
72 SystemModInitialize(); }
74 #else
76 /* initcalls are now grouped by functionality into separate
77 * subsections. Ordering inside the subsections is determined
78 * by link order.
80 * The `id' arg to __define_initcall() is needed so that multiple initcalls
81 * can point at the same handler without causing duplicate-symbol build errors.
84 #define __define_initcall(level, fn, id) \
85 static initcall_t __initcall_##fn##id __attribute__((__used__)) \
86 __attribute__((__section__(".initcall" level ".init"))) = fn
88 #define __define_module_initcall(level, ifn, sfn) \
89 static initmodule_t __initcall_##ifn __attribute__((__used__)) \
90 __attribute__((__section__(".initcall" level ".init"))) = { .fn_minit = ifn, .fn_tinit = sfn }
92 #define MODULE_INITCALL(ifn, sfn) __define_module_initcall("module", ifn, sfn)
94 #define MODULE_INITIALISE_ALL \
95 { for (initmodule_t *fn = __module_initcall_start; fn < __module_initcall_end; fn++) { \
96 if (fn->fn_minit) { \
97 (fn->fn_minit)(); } \
98 } \
101 #define MODULE_TASKCREATE_ALL \
102 { for (initmodule_t *fn = __module_initcall_start; fn < __module_initcall_end; fn++) { \
103 if (fn->fn_tinit) { \
104 (fn->fn_tinit)(); } \
108 #endif /* USE_SIM_POSIX */
110 #endif /* PIOS_INITCALL_H */
113 * @}
114 * @}