board.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 "board.h"
  17. #include <stdlib.h>
  18. /**
  19. * @addtogroup simulator on win32
  20. */
  21. rt_uint8_t *heap;
  22. rt_uint8_t *rt_hw_sram_init(void)
  23. {
  24. rt_uint8_t *heap;
  25. heap = malloc(RT_HEAP_SIZE);
  26. if (heap == RT_NULL)
  27. {
  28. rt_kprintf("there is no memory in pc.");
  29. #ifdef _WIN32
  30. _exit(1);
  31. #else
  32. exit(1);
  33. #endif
  34. }
  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. #endif /* RT_USING_FINSH */
  79. /**
  80. * This function will initial win32
  81. */
  82. void rt_hw_board_init()
  83. {
  84. /* init system memory */
  85. heap = rt_hw_sram_init();
  86. //#if defined(RT_USING_USART)
  87. rt_hw_usart_init();
  88. //#endif
  89. #if defined(RT_USING_CONSOLE)
  90. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  91. #endif
  92. }
  93. /*@}*/