surport finsh

This commit is contained in:
prife 2013-01-14 22:38:54 +08:00
parent 8f70786c30
commit 07da6caafd
5 changed files with 37 additions and 70 deletions

View File

@ -18,6 +18,7 @@
#include <components.h> #include <components.h>
void rt_init_thread_entry(void *parameter) void rt_init_thread_entry(void *parameter)
{ {
#ifdef RT_USING_LWIP #ifdef RT_USING_LWIP
@ -74,16 +75,8 @@ void rt_init_thread_entry(void *parameter)
} }
#endif #endif
#if 0
{
extern void application_init(void);
rt_thread_delay(RT_TICK_PER_SECOND);
application_init();
}
#endif
#if defined(RT_USING_RTGUI) #if defined(RT_USING_RTGUI)
rt_thread_delay(3000); rt_thread_delay(RT_TICK_PER_SECOND);
snake_main(); snake_main();
#endif #endif
} }
@ -91,56 +84,32 @@ void rt_init_thread_entry(void *parameter)
static void rt_test_thread_entry(void *parameter) static void rt_test_thread_entry(void *parameter)
{ {
int i; int i;
for (i = 0; i < 10; i++) for (i = 0; i < 5; i++)
{ {
rt_kprintf("hello, world\n"); rt_kprintf("hello, world\n");
rt_thread_delay(RT_TICK_PER_SECOND); 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() int rt_application_init()
{ {
rt_thread_t tid; rt_thread_t tid;
#if 0
tid = rt_thread_create("init", tid = rt_thread_create("init",
rt_init_thread_entry, RT_NULL, rt_init_thread_entry, RT_NULL,
2048, RT_THREAD_PRIORITY_MAX / 3, 20); 2048, RT_THREAD_PRIORITY_MAX / 3, 20);
if (tid != RT_NULL) if (tid != RT_NULL)
rt_thread_startup(tid); rt_thread_startup(tid);
tid = rt_thread_create("test", tid = rt_thread_create("test",
rt_test_thread_entry, RT_NULL, rt_test_thread_entry, RT_NULL,
2048, RT_THREAD_PRIORITY_MAX * 3 / 4, 20); 2048, RT_THREAD_PRIORITY_MAX * 3 / 4, 20);
if (tid != RT_NULL) if (tid != RT_NULL)
rt_thread_startup(tid); 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; return 0;
} }
/*@}*/ /*@}*/

View File

@ -122,6 +122,7 @@ static rt_size_t rt_serial_write(rt_device_t dev, rt_off_t pos, const void *buff
#endif #endif
printf("%s", (char *)buffer); printf("%s", (char *)buffer);
fflush(stdout);
return size; return size;
} }

View File

@ -59,28 +59,6 @@ void rt_hw_usart_init(void)
#include <termios.h> /* for tcxxxattr, ECHO, etc */ #include <termios.h> /* for tcxxxattr, ECHO, etc */
#include <unistd.h> /* for STDIN_FILENO */ #include <unistd.h> /* 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 void * ThreadforKeyGet(void * lpParam);
static pthread_t OSKey_Thread; static pthread_t OSKey_Thread;
@ -149,16 +127,36 @@ static int savekey(unsigned char key)
#ifdef _WIN32 #ifdef _WIN32
static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam) static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam)
#else #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) static void * ThreadforKeyGet(void * lpParam)
#endif #endif /* not _WIN32*/
{ {
unsigned char key; unsigned char key;
(void)lpParam; //prevent compiler warnings (void)lpParam; //prevent compiler warnings
#ifndef _WIN32
/* set the getchar without buffer */
setgetchar();
#endif
for (;;) for (;;)
{ {
key = getch(); key = getch();
#ifdef _WIN32
if (key == 0xE0) if (key == 0xE0)
{ {
key = getch(); key = getch();
@ -178,7 +176,7 @@ static void * ThreadforKeyGet(void * lpParam)
continue; continue;
} }
#endif
savekey(key); savekey(key);
} }
} /*** ThreadforKeyGet ***/ } /*** ThreadforKeyGet ***/

View File

@ -35,11 +35,13 @@ if PLATFORM == 'gcc':
OBJCPY = PREFIX + 'objcopy' OBJCPY = PREFIX + 'objcopy'
DEVICE = ' -ffunction-sections -fdata-sections' DEVICE = ' -ffunction-sections -fdata-sections'
DEVICE = ' '
CFLAGS = DEVICE + ' -I/usr/include -w -D_REENTRANT' CFLAGS = DEVICE + ' -I/usr/include -w -D_REENTRANT'
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp' 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,-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 -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 = '' CPATH = ''
LPATH = '' LPATH = ''

View File

@ -94,9 +94,9 @@ static void thread_switch_handler(int sig)
thread_from = (thread_t *) rt_interrupt_from_thread; thread_from = (thread_t *) rt_interrupt_from_thread;
thread_to = (thread_t *) rt_interrupt_to_thread; thread_to = (thread_t *) rt_interrupt_to_thread;
/* FIXME 注意!此时 rt_thread_self的值是to线程的值 */ /* 注意!此时 rt_thread_self的值是to线程的值 */
tid = rt_thread_self(); 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); RT_ASSERT((thread_t *)(tid->sp) == thread_to);
TRACE("signal: SIGSUSPEND suspend <%s>\n", thread_from->rtthread->name); TRACE("signal: SIGSUSPEND suspend <%s>\n", thread_from->rtthread->name);
@ -124,7 +124,6 @@ static void *thread_run(void *parameter)
thread->task(thread->para); thread->task(thread->para);
TRACE("pid <%08x> tid <%s> exit...\n", (unsigned int)(thread->pthread), TRACE("pid <%08x> tid <%s> exit...\n", (unsigned int)(thread->pthread),
tid->name); tid->name);
//FIXME
thread->exit(); thread->exit();
//sem_destroy(&thread->sem); //<-------------- //sem_destroy(&thread->sem); //<--------------
@ -235,7 +234,7 @@ void rt_hw_interrupt_enable(rt_base_t level)
tid = rt_thread_self(); tid = rt_thread_self();
pid = pthread_self(); pid = pthread_self();
if (pid != mainthread_pid) if (pid != mainthread_pid && thread_from->pthread == pid)
{ {
/* 注意这段代码是在RTT普通线程函数总函数中执行的 /* 注意这段代码是在RTT普通线程函数总函数中执行的
* from线程就是当前rtt线程 */ * from线程就是当前rtt线程 */
@ -245,9 +244,6 @@ void rt_hw_interrupt_enable(rt_base_t level)
thread_from->rtthread->name, thread_from->rtthread->name,
thread_to->rtthread->name); thread_to->rtthread->name);
/* 确定一下,这两个值一定是相等的! */
RT_ASSERT(thread_from->pthread == pid);
/* 唤醒被挂起的线程 */ /* 唤醒被挂起的线程 */
sem_post(& thread_to ->sem); sem_post(& thread_to ->sem);
cpu_pending_interrupts --; cpu_pending_interrupts --;
@ -259,8 +255,9 @@ void rt_hw_interrupt_enable(rt_base_t level)
} }
else else
{ {
/* 注意这段代码是在system tick 函数中执行的, /* 注意这段代码可能在多种情况下运行:
* 线SIGALRM信号处理函数中 * 1. system tick中执行 线SIGALRM信号处理函数中执行
* 2. 线线
*/ */
TRACE("conswitch: S in pid<%x> ,suspend <%s>, resume <%s>!\n", TRACE("conswitch: S in pid<%x> ,suspend <%s>, resume <%s>!\n",
(unsigned int)pid, (unsigned int)pid,