board.c 2.0 KB

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