board.c 2.2 KB
Newer Older
M
Ming, Bai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * File      : board.c
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2009 RT-Thread Develop Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 *
 * Change Logs:
 * Date           Author       Notes
 * 2009-01-05     Bernard      first implementation
 */

#include <rthw.h>
#include <rtthread.h>
17

M
Ming, Bai 已提交
18 19
#include <stdlib.h>

20 21 22
#include "board.h"
#include "uart_console.h"

M
Ming, Bai 已提交
23 24 25 26 27 28 29 30 31 32 33 34
/**
 * @addtogroup simulator on win32
 */
rt_uint8_t *heap;

rt_uint8_t *rt_hw_sram_init(void)
{
    rt_uint8_t *heap;
    heap = malloc(RT_HEAP_SIZE);
    if (heap == RT_NULL)
    {
        rt_kprintf("there is no memory in pc.");
P
prife 已提交
35
#ifdef _WIN32
M
Ming, Bai 已提交
36
        _exit(1);
P
prife 已提交
37 38 39
#else
        exit(1);
#endif
M
Ming, Bai 已提交
40 41 42 43
    }
    return heap;
}

P
prife 已提交
44 45 46 47
#ifdef _WIN32
#include <windows.h>
#endif

M
Ming, Bai 已提交
48 49
void rt_hw_win32_low_cpu(void)
{
P
prife 已提交
50 51
#ifdef _WIN32
    /* in windows */
M
Ming, Bai 已提交
52
    Sleep(1000);
P
prife 已提交
53 54 55 56
#else
    /* in linux */
    sleep(1);
#endif
M
Ming, Bai 已提交
57 58
}

59
#ifdef _MSC_VER
M
Ming, Bai 已提交
60 61 62 63 64 65
#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
P
prife 已提交
66
#endif
M
Ming, Bai 已提交
67 68 69 70

void rt_hw_exit(void)
{
    rt_kprintf("RT-Thread, bye\n");
P
prife 已提交
71 72 73 74 75 76 77 78 79 80 81 82
#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
M
Ming, Bai 已提交
83 84
    exit(0);
}
85 86 87

#if defined(RT_USING_FINSH)
#include <finsh.h>
M
Ming, Bai 已提交
88
FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_exit, exit, exit rt - thread);
B
bernard 已提交
89
FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_exit, __cmd_quit, exit rt-thread);
M
Ming, Bai 已提交
90 91 92 93 94 95 96 97 98 99
#endif /* RT_USING_FINSH */

/**
 * This function will initial win32
 */
void rt_hw_board_init()
{
    /* init system memory */
    heap = rt_hw_sram_init();

100 101 102 103 104
    uart_console_init();

#ifdef _WIN32
    rt_thread_idle_sethook(rt_hw_win32_low_cpu);
#endif
P
prife 已提交
105 106

#if defined(RT_USING_CONSOLE)
M
Ming, Bai 已提交
107 108 109 110
    rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
}
/*@}*/