components.c 2.5 KB
Newer Older
1 2 3
/*
 * File      : components.c
 * This file is part of RT-Thread RTOS
4
 * COPYRIGHT (C) 2012 - 2013, RT-Thread Development Team
5
 *
6 7 8 9 10 11 12 13 14 15 16 17 18
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 20 21 22 23
 *
 * Change Logs:
 * Date           Author       Notes
 * 2012-09-20     Bernard      Change the name to components.c
 *                             And all components related header files.
24
 * 2012-12-23     Bernard      fix the pthread initialization issue.
B
Bernard Xiong 已提交
25
 * 2013-06-23     Bernard      Add the init_call for components initialization.
26
 */
27

28 29
#include "components.h"

B
Bernard Xiong 已提交
30
static int rti_start(void)
31
{
32
    return 0;
B
Bernard Xiong 已提交
33 34
}
INIT_EXPORT(rti_start, "0");
35

B
Bernard Xiong 已提交
36 37
static int rti_board_end(void)
{
38
    return 0;
B
Bernard Xiong 已提交
39 40
}
INIT_EXPORT(rti_board_end, "1.post");
41

B
Bernard Xiong 已提交
42 43
static int rti_end(void)
{
44
    return 0;
B
Bernard Xiong 已提交
45 46
}
INIT_EXPORT(rti_end,"7");
47

B
Bernard Xiong 已提交
48 49 50
#if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__))
/* fixed for MSC_VC and x86_64 in GNU GCC */
#define NEXT_COMPONENT_FN(fn_ptr, end)  fn_ptr = _next_component_fn(fn_ptr, end)
51

52
const init_fn_t *_next_component_fn(const init_fn_t *fn, const init_fn_t *end)
B
Bernard Xiong 已提交
53
{
54 55 56 57
    unsigned int *ptr;
    ptr = (unsigned int*) (fn + 1);
    while ((*ptr == 0) && ((unsigned int*)ptr < (unsigned int*)end))
        ptr ++;
58

59
    return (const init_fn_t*)ptr;
B
Bernard Xiong 已提交
60
}
61
#else
B
Bernard Xiong 已提交
62
#define NEXT_COMPONENT_FN(fn_ptr, end)  fn_ptr++
63
#endif
64

B
Bernard Xiong 已提交
65 66 67 68 69
/**
 * RT-Thread Components Initialization for board
 */
void rt_components_board_init(void)
{
70
    const init_fn_t *fn_ptr;
71

72 73 74 75 76
    for (fn_ptr = &__rt_init_rti_start; fn_ptr < &__rt_init_rti_board_end; )
    {
        (*fn_ptr)();
        NEXT_COMPONENT_FN(fn_ptr, __rt_init_rti_board_end);
    }
B
Bernard Xiong 已提交
77 78 79 80 81 82 83
}

/**
 * RT-Thread Components Initialization
 */
void rt_components_init(void)
{
84
    const init_fn_t *fn_ptr;
85

86 87 88 89 90
    for (fn_ptr = &__rt_init_rti_board_end; fn_ptr < &__rt_init_rti_end; )
    {
        (*fn_ptr)();
        NEXT_COMPONENT_FN(fn_ptr, __rt_init_rti_end);
    }
91
}
B
Bernard Xiong 已提交
92