components.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * File : components.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2012, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2012-09-20 Bernard Change the name to components.c
  13. * And all components related header files.
  14. * 2012-12-23 Bernard fix the pthread initialization issue.
  15. * 2013-06-23 Bernard Add the init_call for components initialization.
  16. */
  17. #include "components.h"
  18. static int rti_start(void)
  19. {
  20. return 0;
  21. }
  22. INIT_EXPORT(rti_start, "0");
  23. static int rti_board_end(void)
  24. {
  25. return 0;
  26. }
  27. INIT_EXPORT(rti_board_end, "1.post");
  28. static int rti_end(void)
  29. {
  30. return 0;
  31. }
  32. INIT_EXPORT(rti_end,"7");
  33. #if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__))
  34. /* fixed for MSC_VC and x86_64 in GNU GCC */
  35. #define NEXT_COMPONENT_FN(fn_ptr, end) fn_ptr = _next_component_fn(fn_ptr, end)
  36. const init_fn_t* _next_component_fn(const init_fn_t* fn, const init_fn_t* end)
  37. {
  38. unsigned int *ptr;
  39. ptr = (unsigned int*) (fn + 1);
  40. while ((*ptr == 0) && ((unsigned int*)ptr < (unsigned int*)end))
  41. ptr ++;
  42. return (const init_fn_t*)ptr;
  43. }
  44. #else
  45. #define NEXT_COMPONENT_FN(fn_ptr, end) fn_ptr++
  46. #endif
  47. /**
  48. * RT-Thread Components Initialization for board
  49. */
  50. void rt_components_board_init(void)
  51. {
  52. const init_fn_t* fn_ptr;
  53. for (fn_ptr = &__rt_init_rti_start; fn_ptr < &__rt_init_rti_board_end; )
  54. {
  55. (*fn_ptr)();
  56. NEXT_COMPONENT_FN(fn_ptr, __rt_init_rti_board_end);
  57. }
  58. }
  59. /**
  60. * RT-Thread Components Initialization
  61. */
  62. void rt_components_init(void)
  63. {
  64. const init_fn_t* fn_ptr;
  65. for (fn_ptr = &__rt_init_rti_board_end; fn_ptr < &__rt_init_rti_end; )
  66. {
  67. (*fn_ptr)();
  68. NEXT_COMPONENT_FN(fn_ptr, __rt_init_rti_end);
  69. }
  70. }