rt-thread/bsp/simulator/drivers/board.c

116 lines
2.3 KiB
C
Raw Normal View History

2013-01-08 22:40:58 +08:00
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
2013-01-08 22:40:58 +08:00
*
* SPDX-License-Identifier: Apache-2.0
2013-01-08 22:40:58 +08:00
*
* Change Logs:
* Date Author Notes
* 2009-01-05 Bernard first implementation
*/
#include <rthw.h>
#include <rtthread.h>
2013-01-08 22:40:58 +08:00
#include <stdlib.h>
#include <unistd.h>
2013-01-08 22:40:58 +08:00
#include "board.h"
#include "uart_console.h"
2013-01-08 22:40:58 +08:00
/**
* @addtogroup simulator on win32
*/
rt_uint8_t *rt_hw_sram_init(void)
{
rt_uint8_t *heap;
heap = (rt_uint8_t *)malloc(RT_HEAP_SIZE);
2013-01-08 22:40:58 +08:00
if (heap == RT_NULL)
{
rt_kprintf("there is no memory in pc.");
2013-01-22 16:57:47 +08:00
#ifdef _WIN32
2013-01-08 22:40:58 +08:00
_exit(1);
2013-01-22 16:57:47 +08:00
#else
exit(1);
#endif
2013-01-08 22:40:58 +08:00
}
#ifdef RT_USING_HEAP
/* init memory system */
rt_system_heap_init((void*)heap, (void*)&heap[RT_HEAP_SIZE - 1]);
#endif
2013-01-08 22:40:58 +08:00
return heap;
}
2013-01-22 16:57:47 +08:00
#ifdef _WIN32
#include <windows.h>
#endif
2013-01-08 22:40:58 +08:00
void rt_hw_win32_low_cpu(void)
{
2013-01-22 16:57:47 +08:00
#ifdef _WIN32
/* in windows */
2013-01-08 22:40:58 +08:00
Sleep(1000);
2013-01-22 16:57:47 +08:00
#else
/* in linux */
sleep(1);
#endif
2013-01-08 22:40:58 +08:00
}
#ifdef _MSC_VER
2013-01-08 22:40:58 +08:00
#ifndef _CRT_TERMINATE_DEFINED
#define _CRT_TERMINATE_DEFINED
_CRTIMP __declspec(noreturn) void __cdecl exit(__in int _Code);
_CRTIMP __declspec(noreturn) void __cdecl _exit(__in int _Code);
_CRTIMP void __cdecl abort(void);
#endif
2013-01-22 16:57:47 +08:00
#endif
2013-01-08 22:40:58 +08:00
void rt_hw_exit(void)
{
rt_kprintf("RT-Thread, bye\n");
2013-01-22 16:57:47 +08:00
#if !defined(_WIN32) && defined(__GNUC__)
/* *
* getchar reads key from buffer, while finsh need an non-buffer getchar
* in windows, getch is such an function, in linux, we had to change
* the behaviour of terminal to get an non-buffer getchar.
* in usart_sim.c, set_stty is called to do this work
* */
{
extern void restore_stty(void);
restore_stty();
}
#endif
2013-01-08 22:40:58 +08:00
exit(0);
}
#if defined(RT_USING_FINSH)
#include <finsh.h>
2013-01-08 22:40:58 +08:00
FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_exit, exit, exit rt - thread);
MSH_CMD_EXPORT_ALIAS(rt_hw_exit, quit, exit rt-thread);
2013-01-08 22:40:58 +08:00
#endif /* RT_USING_FINSH */
/**
* This function will initial win32
*/
int rt_hw_board_init(void)
2013-01-08 22:40:58 +08:00
{
/* init system memory */
rt_hw_sram_init();
2013-01-08 22:40:58 +08:00
uart_console_init();
#ifdef _WIN32
rt_thread_idle_sethook(rt_hw_win32_low_cpu);
#endif
2013-01-22 16:57:47 +08:00
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
2013-01-08 22:40:58 +08:00
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
/* init board */
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
return 0;
2013-01-08 22:40:58 +08:00
}
2021-10-14 00:57:32 +08:00
2013-01-08 22:40:58 +08:00
/*@}*/