board.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. * 2009-01-05 Bernard first implementation
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <stdlib.h>
  13. #include "board.h"
  14. #include "uart_console.h"
  15. /**
  16. * @addtogroup simulator on win32
  17. */
  18. rt_uint8_t *rt_hw_sram_init(void)
  19. {
  20. rt_uint8_t *heap;
  21. heap = malloc(RT_HEAP_SIZE);
  22. if (heap == RT_NULL)
  23. {
  24. rt_kprintf("there is no memory in pc.");
  25. #ifdef _WIN32
  26. _exit(1);
  27. #else
  28. exit(1);
  29. #endif
  30. }
  31. #ifdef RT_USING_HEAP
  32. /* init memory system */
  33. rt_system_heap_init((void*)heap, (void*)&heap[RT_HEAP_SIZE - 1]);
  34. #endif
  35. return heap;
  36. }
  37. #ifdef _WIN32
  38. #include <windows.h>
  39. #endif
  40. void rt_hw_win32_low_cpu(void)
  41. {
  42. #ifdef _WIN32
  43. /* in windows */
  44. Sleep(1000);
  45. #else
  46. /* in linux */
  47. sleep(1);
  48. #endif
  49. }
  50. #ifdef _MSC_VER
  51. #ifndef _CRT_TERMINATE_DEFINED
  52. #define _CRT_TERMINATE_DEFINED
  53. _CRTIMP __declspec(noreturn) void __cdecl exit(__in int _Code);
  54. _CRTIMP __declspec(noreturn) void __cdecl _exit(__in int _Code);
  55. _CRTIMP void __cdecl abort(void);
  56. #endif
  57. #endif
  58. void rt_hw_exit(void)
  59. {
  60. rt_kprintf("RT-Thread, bye\n");
  61. #if !defined(_WIN32) && defined(__GNUC__)
  62. /* *
  63. * getchar reads key from buffer, while finsh need an non-buffer getchar
  64. * in windows, getch is such an function, in linux, we had to change
  65. * the behaviour of terminal to get an non-buffer getchar.
  66. * in usart_sim.c, set_stty is called to do this work
  67. * */
  68. {
  69. extern void restore_stty(void);
  70. restore_stty();
  71. }
  72. #endif
  73. exit(0);
  74. }
  75. #if defined(RT_USING_FINSH)
  76. #include <finsh.h>
  77. FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_exit, exit, exit rt - thread);
  78. FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_exit, __cmd_quit, exit rt-thread);
  79. #endif /* RT_USING_FINSH */
  80. /**
  81. * This function will initial win32
  82. */
  83. int rt_hw_board_init(void)
  84. {
  85. /* init system memory */
  86. rt_hw_sram_init();
  87. uart_console_init();
  88. #ifdef _WIN32
  89. rt_thread_idle_sethook(rt_hw_win32_low_cpu);
  90. #endif
  91. #if defined(RT_USING_CONSOLE)
  92. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  93. #endif
  94. /* init board */
  95. #ifdef RT_USING_COMPONENTS_INIT
  96. rt_components_board_init();
  97. #endif
  98. return 0;
  99. }
  100. /*@}*/