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
1 change: 1 addition & 0 deletions include/rtthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ void rt_object_put_sethook(void (*hook)(struct rt_object *object));
*/
rt_tick_t rt_tick_get(void);
rt_tick_t rt_tick_get_delta(rt_tick_t base);
rt_tick_t rt_tick_get_left(rt_tick_t base);
void rt_tick_set(rt_tick_t tick);
void rt_tick_increase(void);
void rt_tick_increase_tick(rt_tick_t tick);
Expand Down
16 changes: 16 additions & 0 deletions src/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ rt_tick_t rt_tick_get_delta(rt_tick_t base)
}
RTM_EXPORT(rt_tick_get_delta);

/**
* @brief This function will return left tick from base.
*
* @param base to consider
*
* @return Return left tick.
*/
rt_tick_t rt_tick_get_left(rt_tick_t base)
{
rt_tick_t left = base - rt_tick_get();
if (left <= base)
return left;
return RT_TICK_MAX - left + 1;
}
RTM_EXPORT(rt_tick_get_left);

/**
* @brief This function will set current tick.
*
Expand Down
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
12 changes: 3 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 */
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,11 @@ 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;

*tick += inc_tick;
left_tick = *tick - cur_tick;
left_tick = rt_tick_get_left(*tick + inc_tick);

/* suspend thread */
rt_thread_suspend_with_flag(thread, RT_UNINTERRUPTIBLE);
Expand All @@ -735,7 +729,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);

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