summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSherman <[email protected]>2022-01-26 17:48:46 +0800
committerSherman <[email protected]>2022-01-26 17:48:46 +0800
commit544c721d89ee7c6e7d3f88dd5bd555a221d8222e (patch)
treeaafdd34b49eca60159844a6712883cd01fd478b7 /src
parentfc3c29df709798bcbf0c40e4146e628975c40b9e (diff)
parent032ce63ed39c1bbb9f68068c0cf8b876771f27c8 (diff)
Merge branch 'master' of github.com:RT-Thread/rt-thread
Diffstat (limited to 'src')
-rw-r--r--src/Kconfig4
-rw-r--r--src/device.c21
-rw-r--r--src/idle.c2
-rwxr-xr-xsrc/ipc.c22
-rw-r--r--src/kservice.c14
-rw-r--r--src/thread.c47
-rw-r--r--src/timer.c42
7 files changed, 87 insertions, 65 deletions
diff --git a/src/Kconfig b/src/Kconfig
index 69edd20641..6dc73bc400 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -8,10 +8,6 @@ config RT_NAME_MAX
Each kernel object, such as thread, timer, semaphore etc, has a name,
the RT_NAME_MAX is the maximal size of this object name.
-config RT_USING_BIG_ENDIAN
- bool
- default n
-
config RT_USING_ARCH_DATA_TYPE
bool "Use the data types defined in ARCH_CPU"
default n
diff --git a/src/device.c b/src/device.c
index ebb8f26854..9bfaf776d6 100644
--- a/src/device.c
+++ b/src/device.c
@@ -82,6 +82,7 @@ RTM_EXPORT(rt_device_register);
*/
rt_err_t rt_device_unregister(rt_device_t dev)
{
+ /* parameter check */
RT_ASSERT(dev != RT_NULL);
RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device);
RT_ASSERT(rt_object_is_systemobject(&dev->parent));
@@ -143,6 +144,7 @@ RTM_EXPORT(rt_device_create);
*/
void rt_device_destroy(rt_device_t dev)
{
+ /* parameter check */
RT_ASSERT(dev != RT_NULL);
RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device);
RT_ASSERT(rt_object_is_systemobject(&dev->parent) == RT_FALSE);
@@ -202,6 +204,7 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
{
rt_err_t result = RT_EOK;
+ /* parameter check */
RT_ASSERT(dev != RT_NULL);
RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device);
@@ -267,6 +270,7 @@ rt_err_t rt_device_close(rt_device_t dev)
{
rt_err_t result = RT_EOK;
+ /* parameter check */
RT_ASSERT(dev != RT_NULL);
RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device);
@@ -312,6 +316,7 @@ rt_size_t rt_device_read(rt_device_t dev,
void *buffer,
rt_size_t size)
{
+ /* parameter check */
RT_ASSERT(dev != RT_NULL);
RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device);
@@ -354,6 +359,7 @@ rt_size_t rt_device_write(rt_device_t dev,
const void *buffer,
rt_size_t size)
{
+ /* parameter check */
RT_ASSERT(dev != RT_NULL);
RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device);
@@ -389,6 +395,7 @@ RTM_EXPORT(rt_device_write);
*/
rt_err_t rt_device_control(rt_device_t dev, int cmd, void *arg)
{
+ /* parameter check */
RT_ASSERT(dev != RT_NULL);
RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device);
@@ -412,10 +419,11 @@ RTM_EXPORT(rt_device_control);
*
* @return RT_EOK
*/
-rt_err_t
-rt_device_set_rx_indicate(rt_device_t dev,
- rt_err_t (*rx_ind)(rt_device_t dev, rt_size_t size))
+rt_err_t rt_device_set_rx_indicate(rt_device_t dev,
+ rt_err_t (*rx_ind)(rt_device_t dev,
+ rt_size_t size))
{
+ /* parameter check */
RT_ASSERT(dev != RT_NULL);
RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device);
@@ -435,10 +443,11 @@ RTM_EXPORT(rt_device_set_rx_indicate);
*
* @return RT_EOK
*/
-rt_err_t
-rt_device_set_tx_complete(rt_device_t dev,
- rt_err_t (*tx_done)(rt_device_t dev, void *buffer))
+rt_err_t rt_device_set_tx_complete(rt_device_t dev,
+ rt_err_t (*tx_done)(rt_device_t dev,
+ void *buffer))
{
+ /* parameter check */
RT_ASSERT(dev != RT_NULL);
RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device);
diff --git a/src/idle.c b/src/idle.c
index e3b16c856c..7ea0cd15de 100644
--- a/src/idle.c
+++ b/src/idle.c
@@ -241,7 +241,6 @@ static void rt_defunct_execute(void)
}
}
-extern void rt_system_power_manager(void);
static void rt_thread_idle_entry(void *parameter)
{
#ifdef RT_USING_SMP
@@ -275,6 +274,7 @@ static void rt_thread_idle_entry(void *parameter)
#endif /* RT_USING_SMP */
#ifdef RT_USING_PM
+ void rt_system_power_manager(void);
rt_system_power_manager();
#endif /* RT_USING_PM */
}
diff --git a/src/ipc.c b/src/ipc.c
index 09cc74e103..5d4a2d018f 100755
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -40,6 +40,7 @@
* 2021-01-03 Meco Man implement rt_mb_urgent()
* 2021-05-30 Meco Man implement rt_mutex_trytake()
* 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to ipc.c
+ * 2022-01-24 THEWON let rt_mutex_take return thread->error when using signal
*/
#include <rtthread.h>
@@ -725,8 +726,7 @@ RTM_EXPORT(rt_sem_control);
*
* @param flag is the mutex flag, which determines the queuing way of how multiple threads wait
* when the mutex is not available.
- * NOTE: The mutex flag can ONLY be RT_IPC_FLAG_PRIO. Using RT_IPC_FLAG_FIFO will seriously affect
- * the real-time performance of the system.
+ * NOTE: This parameter has been obsoleted. It can be RT_IPC_FLAG_PRIO, RT_IPC_FLAG_FIFO or RT_NULL.
*
* @return Return the operation status. When the return value is RT_EOK, the initialization is successful.
* If the return value is any other values, it represents the initialization failed.
@@ -735,7 +735,8 @@ RTM_EXPORT(rt_sem_control);
*/
rt_err_t rt_mutex_init(rt_mutex_t mutex, const char *name, rt_uint8_t flag)
{
- (void)flag;
+ /* flag parameter has been obsoleted */
+ RT_UNUSED(flag);
/* parameter check */
RT_ASSERT(mutex != RT_NULL);
@@ -807,8 +808,7 @@ RTM_EXPORT(rt_mutex_detach);
*
* @param flag is the mutex flag, which determines the queuing way of how multiple threads wait
* when the mutex is not available.
- * NOTE: The mutex flag can ONLY be RT_IPC_FLAG_PRIO. Using RT_IPC_FLAG_FIFO will seriously affect
- * the real-time performance of the system.
+ * NOTE: This parameter has been obsoleted. It can be RT_IPC_FLAG_PRIO, RT_IPC_FLAG_FIFO or RT_NULL.
*
* @return Return a pointer to the mutex object. When the return value is RT_NULL, it means the creation failed.
*
@@ -817,7 +817,9 @@ RTM_EXPORT(rt_mutex_detach);
rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag)
{
struct rt_mutex *mutex;
- (void)flag;
+
+ /* flag parameter has been obsoleted */
+ RT_UNUSED(flag);
RT_DEBUG_NOT_IN_INTERRUPT;
@@ -946,9 +948,6 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time)
}
else
{
-#ifdef RT_USING_SIGNALS
-__again:
-#endif /* RT_USING_SIGNALS */
/* The value of mutex is 1 in initial status. Therefore, if the
* value is great than 0, it indicates the mutex is avaible.
*/
@@ -1025,11 +1024,6 @@ __again:
if (thread->error != RT_EOK)
{
-#ifdef RT_USING_SIGNALS
- /* interrupt by signal, try it again */
- if (thread->error == -RT_EINTR) goto __again;
-#endif /* RT_USING_SIGNALS */
-
/* return error */
return thread->error;
}
diff --git a/src/kservice.c b/src/kservice.c
index f112ec92de..d39d3c614e 100644
--- a/src/kservice.c
+++ b/src/kservice.c
@@ -461,7 +461,17 @@ RTM_EXPORT(rt_strncpy);
*/
char *rt_strcpy(char *dst, const char *src)
{
- return rt_strncpy(dst, src, (rt_size_t)-1);
+ char *dest = dst;
+
+ while (*src != '\0')
+ {
+ *dst = *src;
+ dst++;
+ src++;
+ }
+
+ *dst = '\0';
+ return dest;
}
RTM_EXPORT(rt_strcpy);
@@ -603,7 +613,7 @@ void rt_show_version(void)
rt_kprintf("- RT - Thread Operating System\n");
rt_kprintf(" / | \\ %d.%d.%d build %s %s\n",
RT_VERSION, RT_SUBVERSION, RT_REVISION, __DATE__, __TIME__);
- rt_kprintf(" 2006 - 2021 Copyright by rt-thread team\n");
+ rt_kprintf(" 2006 - 2022 Copyright by RT-Thread team\n");
}
RTM_EXPORT(rt_show_version);
diff --git a/src/thread.c b/src/thread.c
index a024a3b7dc..30208f1dd1 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -28,7 +28,9 @@
* add support for tasks bound to cpu
* 2021-02-24 Meco Man rearrange rt_thread_control() - schedule the thread when close it
* 2021-11-15 THEWON Remove duplicate work between idle and _thread_exit
+ * 2021-12-27 Meco Man remove .init_priority
* 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to thread.c
+ * 2022-01-24 THEWON let rt_thread_sleep return thread->error when using signal
*/
#include <rthw.h>
@@ -129,7 +131,7 @@ static void _thread_timeout(void *parameter)
thread = (struct rt_thread *)parameter;
- /* thread check */
+ /* parameter check */
RT_ASSERT(thread != RT_NULL);
RT_ASSERT((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND);
RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread);
@@ -186,7 +188,6 @@ static rt_err_t _thread_init(struct rt_thread *thread,
/* priority init */
RT_ASSERT(priority < RT_THREAD_PRIORITY_MAX);
- thread->init_priority = priority;
thread->current_priority = priority;
thread->number_mask = 0;
@@ -289,7 +290,7 @@ rt_err_t rt_thread_init(struct rt_thread *thread,
rt_uint8_t priority,
rt_uint32_t tick)
{
- /* thread check */
+ /* parameter check */
RT_ASSERT(thread != RT_NULL);
RT_ASSERT(stack_start != RT_NULL);
@@ -340,14 +341,11 @@ RTM_EXPORT(rt_thread_self);
*/
rt_err_t rt_thread_startup(rt_thread_t thread)
{
- /* thread check */
+ /* parameter check */
RT_ASSERT(thread != RT_NULL);
RT_ASSERT((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_INIT);
RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread);
- /* set current priority to initialize priority */
- thread->current_priority = thread->init_priority;
-
/* calculate priority attribute */
#if RT_THREAD_PRIORITY_MAX > 32
thread->number = thread->current_priority >> 3; /* 5bit */
@@ -358,7 +356,7 @@ rt_err_t rt_thread_startup(rt_thread_t thread)
#endif /* RT_THREAD_PRIORITY_MAX > 32 */
RT_DEBUG_LOG(RT_DEBUG_THREAD, ("startup a thread:%s with priority:%d\n",
- thread->name, thread->init_priority));
+ thread->name, thread->current_priority));
/* change thread stat */
thread->stat = RT_THREAD_SUSPEND;
/* then resume it */
@@ -386,7 +384,7 @@ rt_err_t rt_thread_detach(rt_thread_t thread)
{
rt_base_t lock;
- /* thread check */
+ /* parameter check */
RT_ASSERT(thread != RT_NULL);
RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread);
RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread));
@@ -489,7 +487,7 @@ rt_err_t rt_thread_delete(rt_thread_t thread)
{
rt_base_t lock;
- /* thread check */
+ /* parameter check */
RT_ASSERT(thread != RT_NULL);
RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread);
RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread) == RT_FALSE);
@@ -569,6 +567,9 @@ rt_err_t rt_thread_sleep(rt_tick_t tick)
/* disable interrupt */
temp = rt_hw_interrupt_disable();
+ /* reset thread error */
+ thread->error = RT_EOK;
+
/* suspend thread */
rt_thread_suspend(thread);
@@ -585,7 +586,7 @@ rt_err_t rt_thread_sleep(rt_tick_t tick)
if (thread->error == -RT_ETIMEOUT)
thread->error = RT_EOK;
- return RT_EOK;
+ return thread->error;
}
/**
@@ -628,6 +629,9 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick)
/* disable interrupt */
level = rt_hw_interrupt_disable();
+ /* reset thread error */
+ thread->error = RT_EOK;
+
cur_tick = rt_tick_get();
if (cur_tick - *tick < inc_tick)
{
@@ -660,7 +664,7 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick)
rt_hw_interrupt_enable(level);
}
- return RT_EOK;
+ return thread->error;
}
RTM_EXPORT(rt_thread_delay_until);
@@ -706,7 +710,7 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
{
register rt_base_t temp;
- /* thread check */
+ /* parameter check */
RT_ASSERT(thread != RT_NULL);
RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread);
@@ -808,7 +812,11 @@ RTM_EXPORT(rt_thread_control);
/**
* @brief This function will suspend the specified thread and change it to suspend state.
*
- * @note This function only can suspend current thread itself.
+ * @note This function ONLY can suspend current thread itself.
+ * Do not use the rt_thread_suspend and rt_thread_resume functions to synchronize the activities of threads.
+ * You have no way of knowing what code a thread is executing when you suspend it.
+ * If you suspend a thread while it is executing a critical area which is protected by a mutex,
+ * other threads attempt to use that mutex and have to wait. Deadlocks can occur very easily.
*
* @param thread is the thread to be suspended.
*
@@ -820,7 +828,7 @@ rt_err_t rt_thread_suspend(rt_thread_t thread)
register rt_base_t stat;
register rt_base_t temp;
- /* thread check */
+ /* parameter check */
RT_ASSERT(thread != RT_NULL);
RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread);
RT_ASSERT(thread == rt_thread_self());
@@ -836,11 +844,6 @@ rt_err_t rt_thread_suspend(rt_thread_t thread)
/* disable interrupt */
temp = rt_hw_interrupt_disable();
- if (stat == RT_THREAD_RUNNING)
- {
- /* not suspend running status thread on other core */
- RT_ASSERT(thread == rt_thread_self());
- }
/* change thread stat */
rt_schedule_remove_thread(thread);
@@ -860,6 +863,8 @@ RTM_EXPORT(rt_thread_suspend);
/**
* @brief This function will resume a thread and put it to system ready queue.
*
+ * @note Do not use the rt_thread_suspend and rt_thread_resume functions to synchronize the activities of threads.
+ *
* @param thread is the thread to be resumed.
*
* @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
@@ -869,7 +874,7 @@ rt_err_t rt_thread_resume(rt_thread_t thread)
{
register rt_base_t temp;
- /* thread check */
+ /* parameter check */
RT_ASSERT(thread != RT_NULL);
RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread);
diff --git a/src/timer.c b/src/timer.c
index da113298da..5d54f85dbd 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -246,9 +246,12 @@ void rt_timer_dump(rt_list_t timer_heads[])
*
* @param parameter is the param of the callback
*
- * @param time is the ticks of timer
+ * @param time is timeout ticks of timer
+ *
+ * NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1).
*
* @param flag is the flag of timer
+ *
*/
void rt_timer_init(rt_timer_t timer,
const char *name,
@@ -257,8 +260,10 @@ void rt_timer_init(rt_timer_t timer,
rt_tick_t time,
rt_uint8_t flag)
{
- /* timer check */
+ /* parameter check */
RT_ASSERT(timer != RT_NULL);
+ RT_ASSERT(timeout != RT_NULL);
+ RT_ASSERT(time < RT_TICK_MAX / 2);
/* timer object initialization */
rt_object_init(&(timer->parent), RT_Object_Class_Timer, name);
@@ -278,7 +283,7 @@ rt_err_t rt_timer_detach(rt_timer_t timer)
{
register rt_base_t level;
- /* timer check */
+ /* parameter check */
RT_ASSERT(timer != RT_NULL);
RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer);
RT_ASSERT(rt_object_is_systemobject(&timer->parent));
@@ -303,15 +308,17 @@ RTM_EXPORT(rt_timer_detach);
/**
* @brief This function will create a timer
*
- * @param name the name of timer
+ * @param name is the name of timer
+ *
+ * @param timeout is the timeout function
*
- * @param timeout the timeout function
+ * @param parameter is the parameter of timeout function
*
- * @param parameter the parameter of timeout function
+ * @param time is timeout ticks of the timer
*
- * @param time the tick of timer
+ * NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1).
*
- * @param flag the flag of timer
+ * @param flag is the flag of timer
*
* @return the created timer object
*/
@@ -323,6 +330,10 @@ rt_timer_t rt_timer_create(const char *name,
{
struct rt_timer *timer;
+ /* parameter check */
+ RT_ASSERT(timeout != RT_NULL);
+ RT_ASSERT(time < RT_TICK_MAX / 2);
+
/* allocate a object */
timer = (struct rt_timer *)rt_object_allocate(RT_Object_Class_Timer, name);
if (timer == RT_NULL)
@@ -347,7 +358,7 @@ rt_err_t rt_timer_delete(rt_timer_t timer)
{
register rt_base_t level;
- /* timer check */
+ /* parameter check */
RT_ASSERT(timer != RT_NULL);
RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer);
RT_ASSERT(rt_object_is_systemobject(&timer->parent) == RT_FALSE);
@@ -386,7 +397,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
unsigned int tst_nr;
static unsigned int random_nr;
- /* timer check */
+ /* parameter check */
RT_ASSERT(timer != RT_NULL);
RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer);
@@ -401,11 +412,6 @@ rt_err_t rt_timer_start(rt_timer_t timer)
RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(timer->parent)));
- /*
- * get timeout tick,
- * the max timeout tick shall not great than RT_TICK_MAX/2
- */
- RT_ASSERT(timer->init_tick < RT_TICK_MAX / 2);
timer->timeout_tick = rt_tick_get() + timer->init_tick;
#ifdef RT_USING_TIMER_SOFT
@@ -511,7 +517,7 @@ rt_err_t rt_timer_stop(rt_timer_t timer)
{
register rt_base_t level;
- /* timer check */
+ /* parameter check */
RT_ASSERT(timer != RT_NULL);
RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer);
@@ -547,7 +553,7 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg)
{
register rt_base_t level;
- /* timer check */
+ /* parameter check */
RT_ASSERT(timer != RT_NULL);
RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer);
@@ -581,6 +587,8 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg)
/*timer is stop*/
*(rt_uint32_t *)arg = RT_TIMER_FLAG_DEACTIVATED;
}
+ case RT_TIMER_CTRL_GET_REMAIN_TIME:
+ *(rt_tick_t *)arg = timer->timeout_tick;
break;
default: