startup.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * File : startup.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006-2013, RT-Thread Develop 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. * 2008-12-11 xuxinming first version
  13. * 2010-4-3 LiJin add init soft timer thread
  14. * 2013-05-24 Grissiom port to RM48x50
  15. */
  16. #include <rthw.h>
  17. #include <rtthread.h>
  18. #ifdef RT_USING_FINSH
  19. #include <finsh.h>
  20. extern int finsh_system_init(void);
  21. #endif
  22. #include <board.h>
  23. /**
  24. * @addtogroup LPC2478
  25. */
  26. /*@{*/
  27. extern int rt_application_init(void);
  28. #ifdef RT_USING_DEVICE
  29. extern rt_err_t rt_hw_serial_init(void);
  30. #endif
  31. #ifdef __CC_ARM
  32. extern int Image$$RW_IRAM1$$ZI$$Limit;
  33. #elif defined(__GNUC__)
  34. extern int __bss_end;
  35. #elif defined(__TI_COMPILER_VERSION__)
  36. extern unsigned char * const system_data_end;
  37. #endif
  38. #define MEMEND 0x08040000
  39. void rt_hw_pmu_enable_cnt(void)
  40. {
  41. unsigned long tmp;
  42. __asm (" MRC p15, #0, r0, c9, c12, #0");
  43. __asm (" ORR r0, r0, #0x09\n");
  44. __asm (" MCR p15, #0, r0, c9, c12, #0\n");
  45. __asm (" MOV r0, #1\n");
  46. __asm (" RBIT r0, r0\n");
  47. __asm (" MCR p15, #0, r0, c9, c12, #1\n");
  48. }
  49. void rt_hw_pmu_setcnt(unsigned long val)
  50. {
  51. __asm (" MCR p15, #0, r0, c9, c13, #0");
  52. }
  53. unsigned long rt_hw_pmu_getcnt(void)
  54. {
  55. __asm (" MRC p15, #0, r0, c9, c13, #0");
  56. }
  57. /**
  58. * This function will startup RT-Thread RTOS.
  59. */
  60. void rtthread_startup(void)
  61. {
  62. /*// RM48 does not have cache implemented
  63. *rt_hw_cpu_icache_enable();
  64. *rt_hw_cpu_dcache_enable();
  65. */
  66. /* init hardware interrupt */
  67. rt_hw_interrupt_init();
  68. /* init board */
  69. rt_hw_board_init();
  70. /* init tick */
  71. rt_system_tick_init();
  72. /* init kernel object */
  73. rt_system_object_init();
  74. rt_show_version();
  75. /* init timer system */
  76. rt_system_timer_init();
  77. /* init memory system */
  78. #ifdef RT_USING_HEAP
  79. #ifdef __CC_ARM
  80. rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)MEMEND);
  81. #elif defined(__GNUC__)
  82. rt_system_heap_init((void*)&__bss_end, (void*)MEMEND);
  83. #elif defined(__TI_COMPILER_VERSION__)
  84. rt_system_heap_init((void*)&system_data_end, (void*)MEMEND);
  85. #else
  86. #error Unkown compiler
  87. #endif
  88. #endif
  89. /* init scheduler system */
  90. rt_system_scheduler_init();
  91. /* init application */
  92. rt_application_init();
  93. #ifdef RT_USING_FINSH
  94. /* init finsh */
  95. finsh_system_init();
  96. finsh_set_device("sci2");
  97. #endif
  98. /* init soft timer thread */
  99. rt_system_timer_thread_init();
  100. /* init idle thread */
  101. rt_thread_idle_init();
  102. /* start scheduler */
  103. rt_system_scheduler_start();
  104. /* never reach here */
  105. return ;
  106. }
  107. int main(void)
  108. {
  109. /* disable interrupt first */
  110. rt_hw_interrupt_disable();
  111. /* invoke rtthread_startup */
  112. rtthread_startup();
  113. return 0;
  114. }
  115. /*@}*/