board.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #if defined(RT_USING_FINSH)
  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. #include <finsh.h>
  58. void rt_hw_exit(void)
  59. {
  60. rt_kprintf("RT-Thread, bye\n");
  61. exit(0);
  62. }
  63. FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_exit, exit, exit rt - thread);
  64. #endif /* RT_USING_FINSH */
  65. /**
  66. * This function will initial win32
  67. */
  68. void rt_hw_board_init()
  69. {
  70. /* init system memory */
  71. heap = rt_hw_sram_init();
  72. #if defined(RT_USING_USART)
  73. rt_hw_usart_init();
  74. #endif
  75. #if defined(RT_USING_CONSOLE)
  76. rt_hw_serial_init();
  77. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  78. #endif
  79. }
  80. /*@}*/