recover the terminal's behaviour when runing exit in finsh

This commit is contained in:
prife 2013-01-17 12:06:23 +08:00
parent b8aaa6e730
commit 8999948650
2 changed files with 28 additions and 10 deletions

View File

@ -32,7 +32,7 @@ rt_uint8_t *rt_hw_sram_init(void)
#ifdef _WIN32
_exit(1);
#else
exit(1);
exit(1);
#endif
}
return heap;
@ -45,11 +45,11 @@ rt_uint8_t *rt_hw_sram_init(void)
void rt_hw_win32_low_cpu(void)
{
#ifdef _WIN32
/* in windows */
/* in windows */
Sleep(1000);
#else
/* in linux */
sleep(1);
/* in linux */
sleep(1);
#endif
}
@ -67,6 +67,18 @@ _CRTIMP void __cdecl abort(void);
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);

View File

@ -129,19 +129,25 @@ static int savekey(unsigned char key)
static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam)
#else
static struct termios oldt, newt;
/*simulate windows' getch(), it works!!*/
static void setgetchar(void)
void set_stty(void)
{
struct termios oldt, newt;
// get terminal input's attribute
/* get terminal input's attribute */
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
//set termios' local mode
/* 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)
@ -154,7 +160,7 @@ static void * ThreadforKeyGet(void * lpParam)
/* set the getchar without buffer */
sigfillset(&sigmask);
pthread_sigmask(SIG_BLOCK, &sigmask, &oldmask);
setgetchar();
set_stty();
#endif
(void)lpParam; //prevent compiler warnings
for (;;)