#define Define_Section_Init(a) [a] = { \
.start=(void *)&__start_module_##a##_init, \
.stop=(void *)&__stop_module_##a##_init \
}
#define Define_Section_Exit(a) [a] = { \
.start=(void *)&__start_module_##a##_exit, \
.stop=(void *)&__stop_module_##a##_exit \
}
struct TSection
{
void (**start)(void);
void (**stop)(void);
} ;
static struct TSection module_init_sections[] =
{
Define_Section_Init(0), Define_Section_Init(1), Define_Section_Init(2),
Define_Section_Init(3), Define_Section_Init(4), Define_Section_Init(5),
Define_Section_Init(6), Define_Section_Init(7), Define_Section_Init(8),
Define_Section_Init(9),
};
static struct TSection module_exit_sections[] =
{
Define_Section_Exit(0), Define_Section_Exit(1), Define_Section_Exit(2),
Define_Section_Exit(3), Define_Section_Exit(4), Define_Section_Exit(5),
Define_Section_Exit(6), Define_Section_Exit(7), Define_Section_Exit(8),
Define_Section_Exit(9),
};
/**
* Initial all modules
*/
void ModuleInitAll(void)
{
uint32_t i;
for (i = 0; i<ARRAY_SIZE(module_init_sections); i++)
{
void (**iter)(void) =module_init_sections[i].start;
for(;iter<module_init_sections[i].stop;iter++)
{
(*iter)();
}
}
}
/**
* Uninitialize all modules
*/
void ModuleDeinitAll(void)
{
int32_t i;
printf("Exit In progress\n");
for (i = ARRAY_SIZE(module_exit_sections) - 1; i >= 0; i--)
{
void (**iter)(void) =module_exit_sections[i].start;
for(;iter<module_exit_sections[i].stop;iter++)
{
(*iter)();
}
}
printf("Exit In progress Done\n");
}