dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_initcall.h
Go to the documentation of this file.
1 
17 /*
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful, but
24  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
25  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26  * for more details.
27  *
28  * You should have received a copy of the GNU General Public License along
29  * with this program; if not, see <http://www.gnu.org/licenses/>
30  */
31 
32 #ifndef PIOS_INITCALL_H
33 #define PIOS_INITCALL_H
34 
35 typedef int32_t (*initcall_t)(void);
36 typedef struct {
37  initcall_t fn_minit;
38  initcall_t fn_tinit;
39 } initmodule_t;
40 
41 /* Init module section */
43 
45 
46 #define MODULE_INITCALL(ifn, sfn) \
47 static void _add_init_fn(void) __attribute__((constructor)); \
48 static void _add_init_fn(void) { \
49  __module_initcall_end->fn_minit = (ifn); \
50  __module_initcall_end->fn_tinit = (sfn); \
51  __module_initcall_end++; \
52 }
53 
54 #define MODULE_HIPRI_INITCALL(ifn, sfn) \
55 static void _add_init_fn(void) __attribute__((constructor)); \
56 static void _add_init_fn(void) { \
57  __module_hipriinitcall_end->fn_minit = (ifn); \
58  __module_hipriinitcall_end->fn_tinit = (sfn); \
59  __module_hipriinitcall_end++; \
60 }
61 
62 #define MODULE_INITSYSTEM_DECLS \
63 static initmodule_t __module_initcalls[256]; \
64 static initmodule_t __module_hipriinitcalls[256]; \
65 initmodule_t *__module_initcall_start = __module_initcalls; \
66 initmodule_t *__module_initcall_end = __module_initcalls; \
67 initmodule_t *__module_hipriinitcall_start = __module_hipriinitcalls; \
68 initmodule_t *__module_hipriinitcall_end = __module_hipriinitcalls;
69 
70 #define MODULE_INITIALISE_ALL(wdgfn) { \
71  for (initmodule_t *fn = __module_hipriinitcall_start; fn < __module_hipriinitcall_end; fn++) { \
72  if (fn->fn_minit) \
73  (fn->fn_minit)(); \
74  (wdgfn)(); \
75  } ; \
76  for (initmodule_t *fn = __module_initcall_start; fn < __module_initcall_end; fn++) { \
77  if (fn->fn_minit) \
78  (fn->fn_minit)(); \
79  (wdgfn)(); \
80  } \
81 }
82 
83 #define MODULE_TASKCREATE_ALL { \
84  for (initmodule_t *fn = __module_hipriinitcall_start; fn < __module_hipriinitcall_end; fn++) { \
85  if (fn->fn_tinit) \
86  (fn->fn_tinit)(); \
87  } \
88  for (initmodule_t *fn = __module_initcall_start; fn < __module_initcall_end; fn++) { \
89  if (fn->fn_tinit) \
90  (fn->fn_tinit)(); \
91  } \
92 }
93 
94 
95 #endif /* PIOS_INITCALL_H */
96 
initmodule_t __module_initcall_start[]
initmodule_t * __module_hipriinitcall_end
int32_t(* initcall_t)(void)
Definition: pios_initcall.h:45
initmodule_t * __module_hipriinitcall_start
initmodule_t __module_initcall_end[]