components.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * File : components.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2012 - 2013, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2012-09-20 Bernard Change the name to components.c
  23. * And all components related header files.
  24. * 2012-12-23 Bernard fix the pthread initialization issue.
  25. * 2013-06-23 Bernard Add the init_call for components initialization.
  26. */
  27. #include "components.h"
  28. static int rti_start(void)
  29. {
  30. return 0;
  31. }
  32. INIT_EXPORT(rti_start, "0");
  33. static int rti_board_end(void)
  34. {
  35. return 0;
  36. }
  37. INIT_EXPORT(rti_board_end, "1.post");
  38. static int rti_end(void)
  39. {
  40. return 0;
  41. }
  42. INIT_EXPORT(rti_end,"7");
  43. #if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__))
  44. /* fixed for MSC_VC and x86_64 in GNU GCC */
  45. #define NEXT_COMPONENT_FN(fn_ptr, end) fn_ptr = _next_component_fn(fn_ptr, end)
  46. const init_fn_t *_next_component_fn(const init_fn_t *fn, const init_fn_t *end)
  47. {
  48. unsigned int *ptr;
  49. ptr = (unsigned int*) (fn + 1);
  50. while ((*ptr == 0) && ((unsigned int*)ptr < (unsigned int*)end))
  51. ptr ++;
  52. return (const init_fn_t*)ptr;
  53. }
  54. #else
  55. #define NEXT_COMPONENT_FN(fn_ptr, end) fn_ptr++
  56. #endif
  57. /**
  58. * RT-Thread Components Initialization for board
  59. */
  60. void rt_components_board_init(void)
  61. {
  62. const init_fn_t *fn_ptr;
  63. for (fn_ptr = &__rt_init_rti_start; fn_ptr < &__rt_init_rti_board_end; )
  64. {
  65. (*fn_ptr)();
  66. NEXT_COMPONENT_FN(fn_ptr, __rt_init_rti_board_end);
  67. }
  68. }
  69. /**
  70. * RT-Thread Components Initialization
  71. */
  72. void rt_components_init(void)
  73. {
  74. const init_fn_t *fn_ptr;
  75. for (fn_ptr = &__rt_init_rti_board_end; fn_ptr < &__rt_init_rti_end; )
  76. {
  77. (*fn_ptr)();
  78. NEXT_COMPONENT_FN(fn_ptr, __rt_init_rti_end);
  79. }
  80. }