Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wwsmg1
rt-thread
提交
7b42f926
R
rt-thread
项目概览
wwsmg1
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7b42f926
编写于
1月 14, 2013
作者:
P
prife
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
re-write the rt_hw_interrupt_enable/disable
上级
5685a395
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
80 addition
and
67 deletion
+80
-67
libcpu/sim/posix/cpu_port.c
libcpu/sim/posix/cpu_port.c
+80
-67
未找到文件。
libcpu/sim/posix/cpu_port.c
浏览文件 @
7b42f926
...
...
@@ -186,89 +186,60 @@ rt_uint8_t *rt_hw_stack_init(
return
(
rt_uint8_t
*
)
thread
;
}
static
int
dis_count
;
static
int
en_count
;
/* TODO: 此函数还没有真正实现 */
rt_base_t
rt_hw_interrupt_disable
(
void
)
{
long
back
;
if
(
ptr_int_mutex
==
NULL
)
{
return
0
;
}
pthread_mutex_lock
(
ptr_int_mutex
);
back
=
interrupt_disable_flag
;
interrupt_disable_flag
=
INTERRUPT_DISABLE
;
/*TODO: It may need to unmask the signal */
dis_count
++
;
return
back
;
}
/* TODO: 此函数还没有真正实现 */
void
rt_hw_interrupt_enable
(
rt_base_t
level
)
{
interrupt_disable_flag
=
level
;
en_count
++
;
/*TODO: It may need to unmask the signal */
}
void
rt_hw_context_switch_interrupt
(
rt_uint32_t
from
,
rt_uint32_t
to
)
{
rt_hw_context_switch
(
from
,
to
);
}
void
rt_hw_context_switch
(
rt_uint32_t
from
,
rt_uint32_t
to
)
{
struct
rt_thread
*
tid
;
pthread_t
pid
;
thread_t
*
thread_from
;
thread_t
*
thread_to
;
RT_ASSERT
(
from
!=
to
);
if
(
ptr_int_mutex
==
NULL
)
return
;
#if 0
//TODO: 还需要考虑嵌套切换的情况
if (rt_thread_switch_interrupt_flag != 1)
interrupt_disable_flag
=
level
;
pthread_mutex_unlock
(
ptr_int_mutex
);
/* 如果已经中断仍然关闭 */
if
(
interrupt_disable_flag
)
{
rt_thread_switch_interrupt_flag = 1;
return
;
}
// set rt_interrupt_from_thread
rt_interrupt_from_thread = *((rt_uint32_t *)from);
/* 表示当前中断打开, 检查是否有挂起的中断 */
pthread_mutex_lock
(
ptr_int_mutex
);
if
(
!
cpu_pending_interrupts
)
{
pthread_mutex_unlock
(
ptr_int_mutex
);
return
;
}
#endif
rt_interrupt_from_thread
=
*
((
rt_uint32_t
*
)
from
);
rt_interrupt_to_thread
=
*
((
rt_uint32_t
*
)
to
);
thread_from
=
(
thread_t
*
)
rt_interrupt_from_thread
;
thread_to
=
(
thread_t
*
)
rt_interrupt_to_thread
;
/* FIXME note: now, rt_current_thread is the thread_to! scheduler.c:272 */
tid
=
rt_thread_self
();
pid
=
pthread_self
();
/*
* FIXME: 这段代码应该删除,因为rt_schedule函数中是先关闭中断,然后再开启的
* 开启就会出发PendSV(以stm32为例)中断,cpu_port.c的win32版本可以模拟这种
* 情形,因为它的中断是在主线程代码实现的,而本设计中,切换分为两种情况,
* 1) 普通rtt线程调用rt_thread_delay/rt_sem_take等主动挂起时,即刻实现切换
* 2) 当rt_thread_delay定时到期时,主线程的SIGALRM信号处理函数中实现线程切换
*
* 在第一种情况下,如果添加打开如下代码,由于if中语句为真,会导致失败退出。
*
if (interrupt_disable_flag != 0)
{
printf("dis_count=%d, en_count=%d\n", dis_count, en_count);
printf("interrupt_disable_flag = %d\n", interrupt_disable_flag);
printf("bug! interrupt is disabled! You may forget enable interrupt\n");
exit(EXIT_FAILURE);
}
*/
if
(
pid
!=
mainthread_pid
)
{
/*
FIXME:
注意这段代码是在RTT普通线程函数总函数中执行的,
/* 注意这段代码是在RTT普通线程函数总函数中执行的,
* from线程就是当前rtt线程 */
/* 需要检查是否有挂起的中断需要处理 */
TRACE
(
"conswitch: P in pid<%x> ,suspend <%s>, resume <%s>!
\n
"
,
(
unsigned
int
)
pid
,
thread_from
->
rtthread
->
name
,
...
...
@@ -277,29 +248,72 @@ void rt_hw_context_switch(rt_uint32_t from,
/* 确定一下,这两个值一定是相等的! */
RT_ASSERT
(
thread_from
->
pthread
==
pid
);
/* 唤醒to线程 */
sem_post
(
&
thread_to
->
sem
);
/* 唤醒被挂起的线程 */
sem_post
(
&
thread_to
->
sem
);
cpu_pending_interrupts
--
;
/* 挂起from线程, 既然from线程就是当前线程,所以应该直接
* 挂起在这里 */
pthread_mutex_unlock
(
ptr_int_mutex
);
/* 挂起当前的线程 */
sem_wait
(
&
thread_from
->
sem
);
}
else
{
/*
FIXME:
注意这段代码是在system tick 函数中执行的,
/* 注意这段代码是在system tick 函数中执行的,
* 即此时位于主线程的SIGALRM信号处理函数中
*/
TRACE
(
"conswitch: S in pid<%x> ,suspend <%s>, resume <%s>!
\n
"
,
(
unsigned
int
)
pid
,
thread_from
->
rtthread
->
name
,
thread_to
->
rtthread
->
name
);
/* 挂起from线程 */
pthread_kill
(
thread_from
->
pthread
,
MSG_SUSPEND
);
cpu_pending_interrupts
--
;
pthread_mutex_unlock
(
ptr_int_mutex
);
/* 唤醒to线程 */
sem_post
(
&
thread_to
->
sem
);
}
/*TODO: It may need to unmask the signal */
}
void
rt_hw_context_switch_interrupt
(
rt_uint32_t
from
,
rt_uint32_t
to
)
{
rt_hw_context_switch
(
from
,
to
);
}
void
rt_hw_context_switch
(
rt_uint32_t
from
,
rt_uint32_t
to
)
{
struct
rt_thread
*
tid
;
pthread_t
pid
;
thread_t
*
thread_from
;
thread_t
*
thread_to
;
RT_ASSERT
(
from
!=
to
);
#if 0
//TODO: 还需要考虑嵌套切换的情况
if (rt_thread_switch_interrupt_flag != 1)
{
rt_thread_switch_interrupt_flag = 1;
// set rt_interrupt_from_thread
rt_interrupt_from_thread = *((rt_uint32_t *)from);
}
#endif
rt_interrupt_from_thread
=
*
((
rt_uint32_t
*
)
from
);
rt_interrupt_to_thread
=
*
((
rt_uint32_t
*
)
to
);
/* 这个函数只是并不会真正执行中断处理函数,而只是简单的
* 设置一下中断挂起标志位
*/
pthread_mutex_lock
(
ptr_int_mutex
);
cpu_pending_interrupts
++
;
pthread_mutex_unlock
(
ptr_int_mutex
);
}
void
rt_hw_context_switch_to
(
rt_uint32_t
to
)
...
...
@@ -331,7 +345,6 @@ static int mainthread_scheduler(void)
thread_t
*
thread_to
;
pthread_mutex_t
mutex
;
pthread_mutexattr_t
mutexattr
;
unsigned
int
contex_switch_mask
;
/* save the main thread id */
mainthread_pid
=
pthread_self
();
...
...
@@ -342,14 +355,11 @@ static int mainthread_scheduler(void)
/* install signal handler used to suspend itself */
signal_install
(
MSG_SUSPEND
,
thread_switch_handler
);
#if 0
/* create a mutex and condition val, used to indicate interrupts occrue */
ptr_int_mutex
=
&
mutex
;
pthread_mutexattr_init
(
&
mutexattr
);
pthread_mutexattr_settype
(
&
mutexattr
,
PTHREAD_MUTEX_RECURSIVE
);
pthread_mutex_init
(
ptr_int_mutex
,
&
mutexattr
);
pthread_cond_init(&cond_int_hit, NULL);
#endif
/* start timer */
start_sys_timer
();
...
...
@@ -405,17 +415,20 @@ static void start_sys_timer(void)
static
void
mthread_signal_tick
(
int
sig
)
{
int
res
;
pthread_t
pid
=
pthread_self
();
if
(
sig
==
SIGALRM
)
{
TRACE
(
"pid <%x> signal: SIGALRM enter!
\n
"
,
(
unsigned
int
)
pid
);
/* FIXME: 下面这条语句不能打开,打开就会导致失败tick_interrupt_isry
* 永远无法执行
*/
/* if (! interrupt_disable_flag) */
if
(
pthread_mutex_trylock
(
ptr_int_mutex
)
!=
0
)
{
TRACE
(
"try lock failed.
\n
"
);
return
;
}
tick_interrupt_isr
();
pthread_mutex_unlock
(
ptr_int_mutex
);
TRACE
(
"pid <%x> signal: SIGALRM leave!
\n
"
,
(
unsigned
int
)
pid
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录