Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2650,7 +2650,7 @@ static rt_err_t _rt_mb_send_wait(rt_mailbox_t mb,
/* if it's not waiting forever and then re-calculate timeout tick */
if (timeout > 0)
{
tick_delta = rt_tick_get() - tick_delta;
tick_delta = rt_tick_get_delta(tick_delta);
timeout -= tick_delta;
if (timeout < 0)
timeout = 0;
Expand Down Expand Up @@ -2930,7 +2930,7 @@ static rt_err_t _rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeo
/* if it's not waiting forever and then re-calculate timeout tick */
if (timeout > 0)
{
tick_delta = rt_tick_get() - tick_delta;
tick_delta = rt_tick_get_delta(tick_delta);
timeout -= tick_delta;
if (timeout < 0)
timeout = 0;
Expand Down Expand Up @@ -3475,7 +3475,7 @@ static rt_err_t _rt_mq_send_wait(rt_mq_t mq,
/* if it's not waiting forever and then re-calculate timeout tick */
if (timeout > 0)
{
tick_delta = rt_tick_get() - tick_delta;
tick_delta = rt_tick_get_delta(tick_delta);
timeout -= tick_delta;
if (timeout < 0)
timeout = 0;
Expand Down Expand Up @@ -3855,7 +3855,7 @@ static rt_ssize_t _rt_mq_recv(rt_mq_t mq,
/* if it's not waiting forever and then re-calculate timeout tick */
if (timeout > 0)
{
tick_delta = rt_tick_get() - tick_delta;
tick_delta = rt_tick_get_delta(tick_delta);
timeout -= tick_delta;
if (timeout < 0)
timeout = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/mempool.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)

if (time > 0)
{
time -= rt_tick_get() - before_sleep;
time -= rt_tick_get_delta(before_sleep);
if (time < 0)
time = 0;
}
Expand Down
16 changes: 7 additions & 9 deletions src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,6 @@ static rt_err_t _thread_sleep(rt_tick_t tick)

thread->error = -RT_EINTR;

/* notify a pending rescheduling */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为什么要取消一次schedule?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为什么要取消一次schedule?

void rt_exit_critical(void)
{
rt_base_t level;

/* disable interrupt */
level = rt_hw_interrupt_disable();

rt_scheduler_lock_nest--;
if (rt_scheduler_lock_nest <= 0)
{
rt_scheduler_lock_nest = 0;
/* enable interrupt */
rt_hw_interrupt_enable(level);

if (rt_current_thread)
{
/* if scheduler is started, do a schedule /
rt_schedule();
}
}
else
{
/
enable interrupt */
rt_hw_interrupt_enable(level);
}

}
RTM_EXPORT(rt_exit_critical);
退出危险区 会自动调度一次

rt_schedule();

/* exit critical and do a rescheduling */
rt_exit_critical_safe(critical_level);

Expand Down Expand Up @@ -692,7 +689,6 @@ RTM_EXPORT(rt_thread_delay);
rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick)
{
struct rt_thread *thread;
rt_tick_t cur_tick;
rt_base_t critical_level;

RT_ASSERT(tick != RT_NULL);
Expand All @@ -708,13 +704,15 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick)
/* disable interrupt */
critical_level = rt_enter_critical();

cur_tick = rt_tick_get();
if (cur_tick - *tick < inc_tick)
if (rt_tick_get_delta(*tick) < inc_tick)
{
rt_tick_t left_tick;
rt_tick_t target_tick;
target_tick = *tick + inc_tick;
left_tick = target_tick - rt_tick_get();

*tick += inc_tick;
left_tick = *tick - cur_tick;
if (left_tick > target_tick)
left_tick = RT_TICK_MAX - left_tick + 1;

/* suspend thread */
rt_thread_suspend_with_flag(thread, RT_UNINTERRUPTIBLE);
Expand All @@ -735,7 +733,7 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick)
}
else
{
*tick = cur_tick;
*tick = rt_tick_get();
rt_exit_critical_safe(critical_level);
}

Expand Down
4 changes: 1 addition & 3 deletions src/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,6 @@ static void _timer_check(rt_list_t *timer_list, struct rt_spinlock *lock)

level = rt_spin_lock_irqsave(lock);

current_tick = rt_tick_get();

rt_list_init(&list);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

移除上面的赋值后,可以把rt_list_init放到irqsave的前面,这样确保关闭irq的时间更短。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

移除上面的赋值后,可以把rt_list_init放到irqsave的前面,这样确保关闭irq的时间更短。

这个是移除的 冗余代码


while (!rt_list_isempty(&timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1]))
Expand Down Expand Up @@ -762,7 +760,7 @@ void rt_timer_check(void)
rt_tick_t next_timeout;

ret = _timer_list_next_timeout(_soft_timer_list, &next_timeout);
if ((ret == RT_EOK) && (next_timeout <= rt_tick_get()))
if ((ret == RT_EOK) && ((rt_tick_get() - next_timeout) < RT_TICK_MAX / 2))
{
rt_sem_release(&_soft_timer_sem);
}
Expand Down
12 changes: 6 additions & 6 deletions tools/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def GenerateCFiles(env, project, project_name):
tool_path_conv["CMAKE_ASM_COMPILER"] = tool_path_conv_helper(rtconfig.AS)
tool_path_conv["CMAKE_AR"] = tool_path_conv_helper(rtconfig.AR)
tool_path_conv["CMAKE_LINKER"] = tool_path_conv_helper(rtconfig.LINK)
if rtconfig.PLATFORM in ['gcc']:
if rtconfig.PLATFORM in ['gcc','llvm-arm']:
tool_path_conv["CMAKE_SIZE"] = tool_path_conv_helper(rtconfig.SIZE)
tool_path_conv["CMAKE_OBJDUMP"] = tool_path_conv_helper(rtconfig.OBJDUMP)
tool_path_conv["CMAKE_OBJCOPY"] = tool_path_conv_helper(rtconfig.OBJCPY)
Expand Down Expand Up @@ -99,7 +99,7 @@ def GenerateCFiles(env, project, project_name):
AS += ".exe"
AR += ".exe"
LINK += ".exe"
if rtconfig.PLATFORM in ['gcc']:
if rtconfig.PLATFORM in ['gcc','llvm-arm']:
SIZE += ".exe"
OBJDUMP += ".exe"
OBJCOPY += ".exe"
Expand Down Expand Up @@ -129,15 +129,15 @@ def GenerateCFiles(env, project, project_name):
cm_file.write("SET(CMAKE_CXX_FLAGS \""+ CXXFLAGS + "\")\n")
cm_file.write("SET(CMAKE_CXX_COMPILER_WORKS TRUE)\n\n")

if rtconfig.PLATFORM in ['gcc']:
if rtconfig.PLATFORM in ['gcc','llvm-arm']:
cm_file.write("SET(CMAKE_OBJCOPY \""+ OBJCOPY + "\")\n")
cm_file.write("SET(CMAKE_SIZE \""+ SIZE + "\")\n\n")
elif rtconfig.PLATFORM in ['armcc', 'armclang']:
cm_file.write("SET(CMAKE_FROMELF \""+ FROMELF + "\")\n\n")

LINKER_FLAGS = ''
LINKER_LIBS = ''
if rtconfig.PLATFORM in ['gcc']:
if rtconfig.PLATFORM in ['gcc','llvm-arm']:
LINKER_FLAGS += '-T'
elif rtconfig.PLATFORM in ['armcc', 'armclang']:
LINKER_FLAGS += '--scatter'
Expand Down Expand Up @@ -186,7 +186,7 @@ def GenerateCFiles(env, project, project_name):

cm_file.write("ADD_DEFINITIONS(\n")
for i in env['CPPDEFINES']:
cm_file.write("\t-D" + i + "\n")
cm_file.write("\t-D" + str(i).replace("(", "").replace(")","").replace(",", " ") + "\n")
cm_file.write(")\n\n")

libgroups = []
Expand Down Expand Up @@ -290,7 +290,7 @@ def GenerateCFiles(env, project, project_name):
cm_file.write("\n")

cm_file.write("# Interface library search paths\n")
if rtconfig.PLATFORM in ['gcc']:
if rtconfig.PLATFORM in ['gcc','llvm-arm']:
for group in libgroups:
if not 'LIBPATH' in group.keys():
continue
Expand Down
Loading