startup.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2011-02-14 aozima first implementation for Nios II.
  9. * 2011-03-04 aozima add HEAP and finsh support .
  10. */
  11. #include <rtthread.h>
  12. #include "system.h"
  13. #include "board.h"
  14. /**
  15. * @addtogroup NIOS_II
  16. */
  17. /*@{*/
  18. extern int rt_application_init(void);
  19. #ifdef RT_USING_FINSH
  20. extern int finsh_system_init(void);
  21. extern void finsh_set_device(const char* device);
  22. #endif
  23. #ifdef RT_USING_HEAP
  24. extern int _alt_partition_sdram_load_addr;
  25. #endif
  26. /**
  27. * This function will startup RT-Thread RTOS.
  28. */
  29. void rtthread_startup(void)
  30. {
  31. /* init board */
  32. rt_hw_board_init();
  33. /* show version */
  34. rt_show_version();
  35. /* init timer system */
  36. rt_system_timer_init();
  37. #ifdef RT_USING_HEAP
  38. rt_system_heap_init( &_alt_partition_sdram_load_addr, (void*)(SDRAM_BASE + SDRAM_SPAN) );
  39. #endif
  40. /* init scheduler system */
  41. rt_system_scheduler_init();
  42. /* init application */
  43. rt_application_init();
  44. /* init timer thread */
  45. rt_system_timer_thread_init();
  46. #ifdef RT_USING_FINSH
  47. /* init finsh */
  48. finsh_system_init();
  49. #if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
  50. finsh_set_device("uart");
  51. #endif
  52. #endif
  53. /* init idle thread */
  54. rt_thread_idle_init();
  55. /* start scheduler */
  56. rt_system_scheduler_start();
  57. /* never reach here */
  58. return ;
  59. }
  60. int main(void)
  61. {
  62. /* disable interrupt first */
  63. rt_hw_interrupt_disable();
  64. /* startup RT-Thread RTOS */
  65. rtthread_startup();
  66. return 0;
  67. }
  68. /*@}*/