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 
16 /*
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.
21  *
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
25  * for more details.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, see <http://www.gnu.org/licenses/>
29  */
30 
31 #ifndef PIOS_INITCALL_H
32 #define PIOS_INITCALL_H
33 
34 /*
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
39  */
40 
41 /*
42  * Used for initialization calls..
43  */
44 
45 typedef int32_t (*initcall_t)(void);
46 typedef struct {
49 } initmodule_t;
50 
51 /* Init module section */
53 
54 /* initcalls are now grouped by functionality into separate
55  * subsections. Ordering inside the subsections is determined
56  * by link order.
57  *
58  * The `id' arg to __define_initcall() is needed so that multiple initcalls
59  * can point at the same handler without causing duplicate-symbol build errors.
60  */
61 
62 #define __define_module_initcall(level, ifn, sfn) \
63  static initmodule_t __initcall_##fn __attribute__((__used__)) \
64  __attribute__((__section__(".initcall." level))) = { .fn_minit = ifn, .fn_tinit = sfn };
65 
66 #define MODULE_HIPRI_INITCALL(ifn, sfn) __define_module_initcall("a_module", ifn, sfn)
67 #define MODULE_INITCALL(ifn, sfn) __define_module_initcall("module", ifn, sfn)
68 
69 #define MODULE_INITIALISE_ALL(wdgfn) { \
70  for (initmodule_t *fn = __module_initcall_start; fn < __module_initcall_end; fn++) { \
71  if (fn->fn_minit) \
72  (fn->fn_minit)(); \
73  (wdgfn)(); \
74  } \
75  }
76 
77 #define MODULE_TASKCREATE_ALL { for (initmodule_t *fn = __module_initcall_start; fn < __module_initcall_end; fn++) \
78  if (fn->fn_tinit) \
79  (fn->fn_tinit)(); }
80 
81 #endif /* PIOS_INITCALL_H */
82 
initcall_t fn_tinit
Definition: pios_initcall.h:48
initmodule_t __module_initcall_start[]
initcall_t fn_minit
Definition: pios_initcall.h:47
int32_t(* initcall_t)(void)
Definition: pios_initcall.h:45
initmodule_t __module_initcall_end[]