diff --git a/bsp/simlinux/applications/application.c b/bsp/simlinux/applications/application.c index c8ced1accb..e5ddc6d16b 100755 --- a/bsp/simlinux/applications/application.c +++ b/bsp/simlinux/applications/application.c @@ -18,6 +18,7 @@ #include + void rt_init_thread_entry(void *parameter) { #ifdef RT_USING_LWIP @@ -74,16 +75,8 @@ void rt_init_thread_entry(void *parameter) } #endif -#if 0 - { - extern void application_init(void); - rt_thread_delay(RT_TICK_PER_SECOND); - application_init(); - } -#endif - #if defined(RT_USING_RTGUI) - rt_thread_delay(3000); + rt_thread_delay(RT_TICK_PER_SECOND); snake_main(); #endif } @@ -91,56 +84,32 @@ void rt_init_thread_entry(void *parameter) static void rt_test_thread_entry(void *parameter) { int i; - for (i = 0; i < 10; i++) + for (i = 0; i < 5; i++) { rt_kprintf("hello, world\n"); rt_thread_delay(RT_TICK_PER_SECOND); } } -static void rt_high_thread_entry(void *parameter) -{ - int i; - for (i = 0; i < 3; i++) - { - rt_kprintf("high thread <%d> \n", i); - rt_thread_delay(2*RT_TICK_PER_SECOND); - } -} int rt_application_init() { rt_thread_t tid; -#if 0 tid = rt_thread_create("init", rt_init_thread_entry, RT_NULL, 2048, RT_THREAD_PRIORITY_MAX / 3, 20); if (tid != RT_NULL) rt_thread_startup(tid); + tid = rt_thread_create("test", rt_test_thread_entry, RT_NULL, 2048, RT_THREAD_PRIORITY_MAX * 3 / 4, 20); if (tid != RT_NULL) rt_thread_startup(tid); -#endif - - tid = rt_thread_create("test1", - rt_high_thread_entry, RT_NULL, - 2048, RT_THREAD_PRIORITY_MAX / 2, 20); - if (tid != RT_NULL) - rt_thread_startup(tid); - - tid = rt_thread_create("test2", - rt_test_thread_entry, RT_NULL, - 2048, RT_THREAD_PRIORITY_MAX / 2, 20); - if (tid != RT_NULL) - rt_thread_startup(tid); - return 0; } - /*@}*/ diff --git a/bsp/simlinux/drivers/serial.c b/bsp/simlinux/drivers/serial.c index 2bcdb15866..87de4d0498 100755 --- a/bsp/simlinux/drivers/serial.c +++ b/bsp/simlinux/drivers/serial.c @@ -122,6 +122,7 @@ static rt_size_t rt_serial_write(rt_device_t dev, rt_off_t pos, const void *buff #endif printf("%s", (char *)buffer); + fflush(stdout); return size; } diff --git a/bsp/simlinux/drivers/usart_sim.c b/bsp/simlinux/drivers/usart_sim.c index 5331f34679..e554fbb55a 100755 --- a/bsp/simlinux/drivers/usart_sim.c +++ b/bsp/simlinux/drivers/usart_sim.c @@ -59,28 +59,6 @@ void rt_hw_usart_init(void) #include /* for tcxxxattr, ECHO, etc */ #include /* for STDIN_FILENO */ -/*simulate windows' getch(), it works!!*/ -int getch(void) -{ - int ch; - struct termios oldt, newt; - - // 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); - - //read character from terminal input - ch = getchar(); - - //recover terminal's attribute - tcsetattr(STDIN_FILENO, TCSANOW, &oldt); - - return ch; -} static void * ThreadforKeyGet(void * lpParam); static pthread_t OSKey_Thread; @@ -149,16 +127,36 @@ static int savekey(unsigned char key) #ifdef _WIN32 static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam) #else + +/*simulate windows' getch(), it works!!*/ +static void setgetchar(void) +{ + struct termios oldt, newt; + + // 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); +} +#define getch getchar + static void * ThreadforKeyGet(void * lpParam) -#endif +#endif /* not _WIN32*/ { unsigned char key; (void)lpParam; //prevent compiler warnings - +#ifndef _WIN32 + /* set the getchar without buffer */ + setgetchar(); +#endif for (;;) { key = getch(); +#ifdef _WIN32 if (key == 0xE0) { key = getch(); @@ -178,7 +176,7 @@ static void * ThreadforKeyGet(void * lpParam) continue; } - +#endif savekey(key); } } /*** ThreadforKeyGet ***/ diff --git a/bsp/simlinux/rtconfig.py b/bsp/simlinux/rtconfig.py index 020649f329..6a660e832f 100755 --- a/bsp/simlinux/rtconfig.py +++ b/bsp/simlinux/rtconfig.py @@ -35,11 +35,13 @@ if PLATFORM == 'gcc': OBJCPY = PREFIX + 'objcopy' DEVICE = ' -ffunction-sections -fdata-sections' + DEVICE = ' ' CFLAGS = DEVICE + ' -I/usr/include -w -D_REENTRANT' AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp' #LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-linux.map,-cref,-u,Reset_Handler -T stm32_rom.ld' #LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-linux.map -lpthread' - LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-linux.map -pthread' + #LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-linux.map -pthread' + LFLAGS = DEVICE + ' -Wl,-Map=rtthread-linux.map -pthread -T gcc.ld' CPATH = '' LPATH = '' diff --git a/libcpu/sim/posix/cpu_port.c b/libcpu/sim/posix/cpu_port.c index 6d2b517cff..622a3bdc29 100644 --- a/libcpu/sim/posix/cpu_port.c +++ b/libcpu/sim/posix/cpu_port.c @@ -94,9 +94,9 @@ static void thread_switch_handler(int sig) thread_from = (thread_t *) rt_interrupt_from_thread; thread_to = (thread_t *) rt_interrupt_to_thread; - /* FIXME 注意!此时 rt_thread_self的值是to线程的值! */ + /* 注意!此时 rt_thread_self的值是to线程的值! */ tid = rt_thread_self(); - RT_ASSERT(thread_from->pthread == pid); + /* FIXME RT_ASSERT(thread_from->pthread == pid); */ RT_ASSERT((thread_t *)(tid->sp) == thread_to); TRACE("signal: SIGSUSPEND suspend <%s>\n", thread_from->rtthread->name); @@ -124,7 +124,6 @@ static void *thread_run(void *parameter) thread->task(thread->para); TRACE("pid <%08x> tid <%s> exit...\n", (unsigned int)(thread->pthread), tid->name); - //FIXME thread->exit(); //sem_destroy(&thread->sem); //<-------------- @@ -235,7 +234,7 @@ void rt_hw_interrupt_enable(rt_base_t level) tid = rt_thread_self(); pid = pthread_self(); - if (pid != mainthread_pid) + if (pid != mainthread_pid && thread_from->pthread == pid) { /* 注意这段代码是在RTT普通线程函数总函数中执行的, * from线程就是当前rtt线程 */ @@ -245,9 +244,6 @@ void rt_hw_interrupt_enable(rt_base_t level) thread_from->rtthread->name, thread_to->rtthread->name); - /* 确定一下,这两个值一定是相等的! */ - RT_ASSERT(thread_from->pthread == pid); - /* 唤醒被挂起的线程 */ sem_post(& thread_to ->sem); cpu_pending_interrupts --; @@ -259,8 +255,9 @@ void rt_hw_interrupt_enable(rt_base_t level) } else { - /* 注意这段代码是在system tick 函数中执行的, - * 即此时位于主线程的SIGALRM信号处理函数中 + /* 注意这段代码可能在多种情况下运行: + * 1. 在system tick中执行, 即主线程的SIGALRM信号处理函数中执行 + * 2. 其他线程中调用,比如用于获取按键输入的线程中调用 */ TRACE("conswitch: S in pid<%x> ,suspend <%s>, resume <%s>!\n", (unsigned int)pid,