board.c 2.2 KB

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