mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-23 04:04:15 +08:00
merge bsp/simlinux into bsp/simulator
This commit is contained in:
Regular → Executable
+33
-4
@@ -16,7 +16,6 @@
|
||||
#include <rtthread.h>
|
||||
#include "board.h"
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
|
||||
/**
|
||||
* @addtogroup simulator on win32
|
||||
@@ -30,29 +29,56 @@ rt_uint8_t *rt_hw_sram_init(void)
|
||||
if (heap == RT_NULL)
|
||||
{
|
||||
rt_kprintf("there is no memory in pc.");
|
||||
#ifdef _WIN32
|
||||
_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
return heap;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
void rt_hw_win32_low_cpu(void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
/* in windows */
|
||||
Sleep(1000);
|
||||
#else
|
||||
/* in linux */
|
||||
sleep(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(RT_USING_FINSH)
|
||||
|
||||
#ifdef _WIN32
|
||||
#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
|
||||
#endif
|
||||
|
||||
#if defined(RT_USING_FINSH)
|
||||
#include <finsh.h>
|
||||
void rt_hw_exit(void)
|
||||
{
|
||||
rt_kprintf("RT-Thread, bye\n");
|
||||
#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
|
||||
exit(0);
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_exit, exit, exit rt - thread);
|
||||
@@ -66,8 +92,11 @@ void rt_hw_board_init()
|
||||
/* init system memory */
|
||||
heap = rt_hw_sram_init();
|
||||
|
||||
#if defined(RT_USING_CONSOLE)
|
||||
//#if defined(RT_USING_USART)
|
||||
rt_hw_usart_init();
|
||||
//#endif
|
||||
|
||||
#if defined(RT_USING_CONSOLE)
|
||||
rt_hw_serial_init();
|
||||
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
||||
#endif
|
||||
|
||||
Regular → Executable
+2
-2
@@ -1,7 +1,7 @@
|
||||
#include <rtthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
//#include <stdlib.h>
|
||||
//#include <string.h>
|
||||
#include <dfs_def.h>
|
||||
|
||||
// #define SD_TRACE rt_kprintf
|
||||
|
||||
Regular → Executable
+26
-2
@@ -1,6 +1,10 @@
|
||||
#include <rtthread.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <sdl.h>
|
||||
#else
|
||||
#include <SDL/SDL.h>
|
||||
#endif
|
||||
#include <rtdevice.h>
|
||||
#include <rtgui/driver.h>
|
||||
|
||||
@@ -104,7 +108,7 @@ static void sdlfb_hw_init(void)
|
||||
//_putenv("SDL_VIDEODRIVER=windib");
|
||||
|
||||
//if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) < 0)
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
{
|
||||
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
@@ -132,16 +136,24 @@ static void sdlfb_hw_init(void)
|
||||
sdllock = rt_mutex_create("fb", RT_IPC_FLAG_FIFO);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sdl.h>
|
||||
#include <rtgui/event.h>
|
||||
#include <rtgui/kbddef.h>
|
||||
#include <rtgui/rtgui_server.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
static DWORD WINAPI sdl_loop(LPVOID lpParam)
|
||||
#else
|
||||
static void *sdl_loop(void *lpParam)
|
||||
#endif
|
||||
{
|
||||
int quit = 0;
|
||||
SDL_Event event;
|
||||
@@ -284,6 +296,7 @@ static DWORD WINAPI sdl_loop(LPVOID lpParam)
|
||||
/* start sdl thread */
|
||||
void rt_hw_sdl_start(void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
HANDLE thread;
|
||||
DWORD thread_id;
|
||||
|
||||
@@ -301,4 +314,15 @@ void rt_hw_sdl_start(void)
|
||||
return;
|
||||
}
|
||||
ResumeThread(thread);
|
||||
#else
|
||||
/* Linux */
|
||||
pthread_t pid;
|
||||
int res;
|
||||
res = pthread_create(&pid, NULL, &sdl_loop, NULL);
|
||||
if (res)
|
||||
{
|
||||
printf("pthread create sdl thread faild, <%d>\n", res);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Regular → Executable
+8
-1
@@ -13,8 +13,12 @@
|
||||
#include "serial.h"
|
||||
#include <stdio.h>
|
||||
struct rt_device serial_device;
|
||||
extern struct serial_int_rx serial_rx;
|
||||
//extern struct serial_int_rx serial_rx;
|
||||
struct serial_int_rx serial_rx;
|
||||
|
||||
#if 0
|
||||
static FILE *fp = RT_NULL;
|
||||
#endif
|
||||
|
||||
/*@{*/
|
||||
|
||||
@@ -109,13 +113,16 @@ static rt_size_t rt_serial_write(rt_device_t dev, rt_off_t pos, const void *buff
|
||||
#if _DEBUG_SERIAL==1
|
||||
printf("in rt_serial_write()\n");
|
||||
#endif
|
||||
#if 0
|
||||
if (fp == NULL)
|
||||
fp = fopen("log.txt", "wb+");
|
||||
|
||||
if (fp != NULL)
|
||||
fwrite(buffer, size, 1, fp);
|
||||
#endif
|
||||
|
||||
printf("%s", (char *)buffer);
|
||||
fflush(stdout);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
Regular → Executable
+64
-6
@@ -1,15 +1,19 @@
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "serial.h"
|
||||
|
||||
struct serial_int_rx serial_rx;
|
||||
extern struct rt_device serial_device;
|
||||
|
||||
#ifdef _WIN32
|
||||
/*
|
||||
* Handler for OSKey Thread
|
||||
*/
|
||||
@@ -19,7 +23,6 @@ static DWORD OSKey_ThreadID;
|
||||
static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam);
|
||||
void rt_hw_usart_init(void)
|
||||
{
|
||||
|
||||
/*
|
||||
* create serial thread that receive key input from keyboard
|
||||
*/
|
||||
@@ -46,9 +49,31 @@ void rt_hw_usart_init(void)
|
||||
* Start OS get key Thread
|
||||
*/
|
||||
ResumeThread(OSKey_Thread);
|
||||
|
||||
}
|
||||
|
||||
#else /* POSIX version */
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <termios.h> /* for tcxxxattr, ECHO, etc */
|
||||
#include <unistd.h> /* for STDIN_FILENO */
|
||||
|
||||
|
||||
static void * ThreadforKeyGet(void * lpParam);
|
||||
static pthread_t OSKey_Thread;
|
||||
void rt_hw_usart_init(void)
|
||||
{
|
||||
int res;
|
||||
res = pthread_create(&OSKey_Thread, NULL, &ThreadforKeyGet, NULL);
|
||||
if (res)
|
||||
{
|
||||
printf("pthread create faild, <%d>\n", res);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* 方向键(←): 0xe04b
|
||||
* 方向键(↑): 0xe048
|
||||
@@ -100,15 +125,48 @@ static int savekey(unsigned char key)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam)
|
||||
#else
|
||||
|
||||
static struct termios oldt, newt;
|
||||
/*simulate windows' getch(), it works!!*/
|
||||
void set_stty(void)
|
||||
{
|
||||
/* get terminal input's attribute */
|
||||
tcgetattr(STDIN_FILENO, &oldt);
|
||||
newt = oldt;
|
||||
|
||||
/* set termios' local mode */
|
||||
newt.c_lflag &= ~(ECHO|ICANON);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
|
||||
}
|
||||
|
||||
void restore_stty(void)
|
||||
{
|
||||
/* recover terminal's attribute */
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
|
||||
}
|
||||
|
||||
#define getch getchar
|
||||
|
||||
static void * ThreadforKeyGet(void * lpParam)
|
||||
#endif /* not _WIN32*/
|
||||
{
|
||||
unsigned char key;
|
||||
|
||||
#ifndef _WIN32
|
||||
sigset_t sigmask, oldmask;
|
||||
/* set the getchar without buffer */
|
||||
sigfillset(&sigmask);
|
||||
pthread_sigmask(SIG_BLOCK, &sigmask, &oldmask);
|
||||
set_stty();
|
||||
#endif
|
||||
(void)lpParam; //prevent compiler warnings
|
||||
|
||||
for (;;)
|
||||
{
|
||||
key = getch();
|
||||
#ifdef _WIN32
|
||||
if (key == 0xE0)
|
||||
{
|
||||
key = getch();
|
||||
@@ -128,7 +186,7 @@ static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam)
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
#endif
|
||||
savekey(key);
|
||||
}
|
||||
} /*** ThreadforKeyGet ***/
|
||||
} /*** ThreadforKeyGet ***/
|
||||
|
||||
Reference in New Issue
Block a user