初始化和释放模块



#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");
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值