summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWayne Lin <[email protected]>2021-11-10 16:01:38 +0800
committerWayne Lin <[email protected]>2021-11-10 16:01:38 +0800
commit9b44e57a6022b8eb46eda7037b719ec918fdcc55 (patch)
tree26be9facf0f37d1c38b9e4b6e4abc99d6f8b5a8d /src
parent37f5236dfa45b98d02e867536a10ac0b6622b80b (diff)
parentfdbaa2a808d12d522ad90702795c08ae8443aab9 (diff)
Merge branch 'master' of https://github.com/RT-Thread/rt-thread into nuvoton
Diffstat (limited to 'src')
-rw-r--r--src/Kconfig27
-rw-r--r--src/clock.c32
-rw-r--r--src/components.c20
-rw-r--r--src/cpu.c70
-rw-r--r--src/device.c106
-rw-r--r--src/idle.c48
-rwxr-xr-xsrc/ipc.c139
-rw-r--r--src/irq.c29
-rw-r--r--src/kservice.c281
-rw-r--r--src/mem.c59
-rw-r--r--src/memheap.c151
-rw-r--r--src/mempool.c60
-rw-r--r--src/object.c139
-rw-r--r--src/scheduler.c90
-rw-r--r--src/signal.c70
-rw-r--r--src/slab.c84
-rw-r--r--src/thread.c253
-rw-r--r--src/timer.c220
18 files changed, 1195 insertions, 683 deletions
diff --git a/src/Kconfig b/src/Kconfig
index e0582f5663..e31afc25fa 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -8,6 +8,10 @@ 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
@@ -131,6 +135,10 @@ config RT_KSERVICE_USING_TINY_SIZE
bool "Enable kservice to use tiny size"
default n
+config RT_USING_ASM_MEMCPY
+ bool
+ default n
+
endmenu
menuconfig RT_DEBUG
@@ -264,11 +272,18 @@ menu "Memory Management"
help
Using static memory fixed partition
- config RT_USING_MEMHEAP
+ menuconfig RT_USING_MEMHEAP
bool "Using memory heap object"
default n
- help
- Using memory heap object to manage dynamic memory heap.
+
+ if RT_USING_MEMHEAP
+
+ if RT_USING_MEMHEAP_AS_HEAP
+ config RT_USING_MEMHEAP_AUTO_BINDING
+ bool "Use all of memheap objects as heap"
+ default y
+ endif
+ endif
choice
prompt "Dynamic Memory Management"
@@ -285,7 +300,7 @@ menu "Memory Management"
if RT_USING_MEMHEAP
config RT_USING_MEMHEAP_AS_HEAP
- bool "Use all of memheap objects as heap"
+ bool "Use memheap objects as heap"
endif
config RT_USING_USERHEAP
@@ -352,6 +367,10 @@ menu "Kernel Device Object"
config RT_CONSOLE_DEVICE_NAME
string "the device name for console"
default "uart"
+
+ config RT_PRINTF_LONGLONG
+ bool "rt_kprintf support long long"
+ default n
endif
endmenu
diff --git a/src/clock.c b/src/clock.c
index 77516b3775..21be3a4203 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -33,9 +33,9 @@ static volatile rt_tick_t rt_tick = 0;
/**@{*/
/**
- * This function will return current tick from operating system startup
+ * @brief This function will return current tick from operating system startup.
*
- * @return current tick
+ * @return Return current tick.
*/
rt_tick_t rt_tick_get(void)
{
@@ -45,7 +45,9 @@ rt_tick_t rt_tick_get(void)
RTM_EXPORT(rt_tick_get);
/**
- * This function will set current tick
+ * @brief This function will set current tick.
+ *
+ * @param tick is the value that you will set.
*/
void rt_tick_set(rt_tick_t tick)
{
@@ -57,8 +59,8 @@ void rt_tick_set(rt_tick_t tick)
}
/**
- * This function will notify kernel there is one tick passed. Normally,
- * this function is invoked by clock ISR.
+ * @brief This function will notify kernel there is one tick passed.
+ * Normally, this function is invoked by clock ISR.
*/
void rt_tick_increase(void)
{
@@ -97,14 +99,14 @@ void rt_tick_increase(void)
}
/**
- * This function will calculate the tick from millisecond.
+ * @brief This function will calculate the tick from millisecond.
*
- * @param ms the specified millisecond
- * - Negative Number wait forever
- * - Zero not wait
- * - Max 0x7fffffff
+ * @param ms is the specified millisecond.
+ * - Negative Number wait forever
+ * - Zero not wait
+ * - Max 0x7fffffff
*
- * @return the calculated tick
+ * @return Return the calculated tick.
*/
rt_tick_t rt_tick_from_millisecond(rt_int32_t ms)
{
@@ -126,9 +128,13 @@ rt_tick_t rt_tick_from_millisecond(rt_int32_t ms)
RTM_EXPORT(rt_tick_from_millisecond);
/**
- * This function will provide the passed millisecond from boot.
+ * @brief This function will return the passed millisecond from boot.
+ *
+ * @note if the value of RT_TICK_PER_SECOND is lower than 1000 or
+ * is not an integral multiple of 1000, this function will not
+ * provide the correct 1ms-based tick.
*
- * @return passed millisecond from boot
+ * @return Return passed millisecond from boot.
*/
RT_WEAK rt_tick_t rt_tick_get_millisecond(void)
{
diff --git a/src/components.c b/src/components.c
index e156b783e4..9433b7457c 100644
--- a/src/components.c
+++ b/src/components.c
@@ -78,7 +78,9 @@ static int rti_end(void)
INIT_EXPORT(rti_end, "6.end");
/**
- * RT-Thread Components Initialization for board
+ * @brief Onboard components initialization. In this function, the board-level
+ * initialization function will be called to complete the initialization
+ * of the on-board peripherals.
*/
void rt_components_board_init(void)
{
@@ -102,7 +104,7 @@ void rt_components_board_init(void)
}
/**
- * RT-Thread Components Initialization
+ * @brief RT-Thread Components Initialization.
*/
void rt_components_init(void)
{
@@ -169,7 +171,11 @@ static rt_uint8_t main_stack[RT_MAIN_THREAD_STACK_SIZE];
struct rt_thread main_thread;
#endif /* RT_USING_HEAP */
-/* the system main thread */
+/**
+ * @brief The system main thread. In this thread will call the rt_components_init()
+ * for initialization of RT-Thread Components and call the user's programming
+ * entry main().
+ */
void main_thread_entry(void *parameter)
{
extern int main(void);
@@ -193,6 +199,10 @@ void main_thread_entry(void *parameter)
#endif
}
+/**
+ * @brief This function will create and start the main thread, but this thread
+ * will not run until the scheduler starts.
+ */
void rt_application_init(void)
{
rt_thread_t tid;
@@ -216,6 +226,10 @@ void rt_application_init(void)
rt_thread_startup(tid);
}
+/**
+ * @brief This function will call all levels of initialization functions to complete
+ * the initialization of the system, and finally start the scheduler.
+ */
int rtthread_startup(void)
{
rt_hw_interrupt_disable();
diff --git a/src/cpu.c b/src/cpu.c
index a7d56ba999..b689ecf2d7 100644
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -11,13 +11,13 @@
#include <rtthread.h>
#ifdef RT_USING_SMP
-static struct rt_cpu rt_cpus[RT_CPUS_NR];
+static struct rt_cpu _cpus[RT_CPUS_NR];
rt_hw_spinlock_t _cpus_lock;
/*
* disable scheduler
*/
-static void rt_preempt_disable(void)
+static void _cpu_preempt_disable(void)
{
register rt_base_t level;
struct rt_thread *current_thread;
@@ -42,7 +42,7 @@ static void rt_preempt_disable(void)
/*
* enable scheduler
*/
-static void rt_preempt_enable(void)
+static void _cpu_preempt_enable(void)
{
register rt_base_t level;
struct rt_thread *current_thread;
@@ -65,31 +65,59 @@ static void rt_preempt_enable(void)
rt_hw_local_irq_enable(level);
}
+/**
+ * @brief Initialize a static spinlock object.
+ *
+ * @param lock is a pointer to the spinlock to initialize.
+ */
void rt_spin_lock_init(struct rt_spinlock *lock)
{
rt_hw_spin_lock_init(&lock->lock);
}
RTM_EXPORT(rt_spin_lock_init)
+/**
+ * @brief This function will lock the spinlock.
+ *
+ * @note If the spinlock is locked, the current CPU will keep polling the spinlock state
+ * until the spinlock is unlocked.
+ *
+ * @param lock is a pointer to the spinlock.
+ */
void rt_spin_lock(struct rt_spinlock *lock)
{
- rt_preempt_disable();
+ _cpu_preempt_disable();
rt_hw_spin_lock(&lock->lock);
}
RTM_EXPORT(rt_spin_lock)
+/**
+ * @brief This function will unlock the spinlock.
+ *
+ * @param lock is a pointer to the spinlock.
+ */
void rt_spin_unlock(struct rt_spinlock *lock)
{
rt_hw_spin_unlock(&lock->lock);
- rt_preempt_enable();
+ _cpu_preempt_enable();
}
RTM_EXPORT(rt_spin_unlock)
+/**
+ * @brief This function will disable the local interrupt and then lock the spinlock.
+ *
+ * @note If the spinlock is locked, the current CPU will keep polling the spinlock state
+ * until the spinlock is unlocked.
+ *
+ * @param lock is a pointer to the spinlock.
+ *
+ * @return Return current cpu interrupt status.
+ */
rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock)
{
unsigned long level;
- rt_preempt_disable();
+ _cpu_preempt_disable();
level = rt_hw_local_irq_disable();
rt_hw_spin_lock(&lock->lock);
@@ -98,30 +126,46 @@ rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock)
}
RTM_EXPORT(rt_spin_lock_irqsave)
+/**
+ * @brief This function will unlock the spinlock and then restore current cpu interrupt status.
+ *
+ * @param lock is a pointer to the spinlock.
+ *
+ * @param level is interrupt status returned by rt_spin_lock_irqsave().
+ */
void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level)
{
rt_hw_spin_unlock(&lock->lock);
rt_hw_local_irq_enable(level);
- rt_preempt_enable();
+ _cpu_preempt_enable();
}
RTM_EXPORT(rt_spin_unlock_irqrestore)
/**
- * This fucntion will return current cpu.
+ * @brief This fucntion will return current cpu object.
+ *
+ * @return Return a pointer to the current cpu object.
*/
struct rt_cpu *rt_cpu_self(void)
{
- return &rt_cpus[rt_hw_cpu_id()];
+ return &_cpus[rt_hw_cpu_id()];
}
+/**
+ * @brief This fucntion will return the cpu object corresponding to index.
+ *
+ * @return Return a pointer to the cpu object corresponding to index.
+ */
struct rt_cpu *rt_cpu_index(int index)
{
- return &rt_cpus[index];
+ return &_cpus[index];
}
/**
- * This function will lock all cpus's scheduler and disable local irq.
+ * @brief This function will lock all cpus's scheduler and disable local irq.
+ *
+ * @return Return current cpu interrupt status.
*/
rt_base_t rt_cpus_lock(void)
{
@@ -148,7 +192,9 @@ rt_base_t rt_cpus_lock(void)
RTM_EXPORT(rt_cpus_lock);
/**
- * This function will restore all cpus's scheduler and restore local irq.
+ * @brief This function will restore all cpus's scheduler and restore local irq.
+ *
+ * @param level is interrupt status returned by rt_cpus_lock().
*/
void rt_cpus_unlock(rt_base_t level)
{
diff --git a/src/device.c b/src/device.c
index a9c244d306..6e22c2b692 100644
--- a/src/device.c
+++ b/src/device.c
@@ -39,11 +39,13 @@
#endif /* RT_USING_DEVICE_OPS */
/**
- * This function registers a device driver with specified name.
+ * @brief This function registers a device driver with a specified name.
*
- * @param dev the pointer of device driver structure
- * @param name the device driver's name
- * @param flags the capabilities flag of device
+ * @param dev is the pointer of device driver structure.
+ *
+ * @param name is the device driver's name.
+ *
+ * @param flags is the capabilities flag of device.
*
* @return the error code, RT_EOK on initialization successfully.
*/
@@ -72,9 +74,9 @@ rt_err_t rt_device_register(rt_device_t dev,
RTM_EXPORT(rt_device_register);
/**
- * This function removes a previously registered device driver
+ * @brief This function removes a previously registered device driver.
*
- * @param dev the pointer of device driver structure
+ * @param dev is the pointer of device driver structure.
*
* @return the error code, RT_EOK on successfully.
*/
@@ -91,9 +93,9 @@ rt_err_t rt_device_unregister(rt_device_t dev)
RTM_EXPORT(rt_device_unregister);
/**
- * This function finds a device driver by specified name.
+ * @brief This function finds a device driver by specified name.
*
- * @param name the device driver's name
+ * @param name is the device driver's name.
*
* @return the registered device driver on successful, or RT_NULL on failure.
*/
@@ -105,10 +107,11 @@ RTM_EXPORT(rt_device_find);
#ifdef RT_USING_HEAP
/**
- * This function creates a device object with user data size.
+ * @brief This function creates a device object with user data size.
*
- * @param type, the kind type of this device object.
- * @param attach_size, the size of user data.
+ * @param type is the type of the device object.
+ *
+ * @param attach_size is the size of user data.
*
* @return the allocated device object, or RT_NULL when failed.
*/
@@ -134,9 +137,9 @@ rt_device_t rt_device_create(int type, int attach_size)
RTM_EXPORT(rt_device_create);
/**
- * This function destroy the specific device object.
+ * @brief This function destroy the specific device object.
*
- * @param dev, the specific device object.
+ * @param dev is a specific device object.
*/
void rt_device_destroy(rt_device_t dev)
{
@@ -153,11 +156,11 @@ RTM_EXPORT(rt_device_destroy);
#endif /* RT_USING_HEAP */
/**
- * This function will initialize the specified device
+ * @brief This function will initialize the specified device.
*
- * @param dev the pointer of device driver structure
+ * @param dev is the pointer of device driver structure.
*
- * @return the result
+ * @return the result, RT_EOK on successfully.
*/
rt_err_t rt_device_init(rt_device_t dev)
{
@@ -187,12 +190,13 @@ rt_err_t rt_device_init(rt_device_t dev)
}
/**
- * This function will open a device
+ * @brief This function will open a device.
+ *
+ * @param dev is the pointer of device driver structure.
*
- * @param dev the pointer of device driver structure
- * @param oflag the flags for device open
+ * @param oflag is the flags for device open.
*
- * @return the result
+ * @return the result, RT_EOK on successfully.
*/
rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
{
@@ -253,11 +257,11 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
RTM_EXPORT(rt_device_open);
/**
- * This function will close a device
+ * @brief This function will close a device.
*
- * @param dev the pointer of device driver structure
+ * @param dev is the pointer of device driver structure.
*
- * @return the result
+ * @return the result, RT_EOK on successfully.
*/
rt_err_t rt_device_close(rt_device_t dev)
{
@@ -289,12 +293,15 @@ rt_err_t rt_device_close(rt_device_t dev)
RTM_EXPORT(rt_device_close);
/**
- * This function will read some data from a device.
+ * @brief This function will read some data from a device.
+ *
+ * @param dev is the pointer of device driver structure.
+ *
+ * @param pos is the position when reading.
+ *
+ * @param buffer is a data buffer to save the read data.
*
- * @param dev the pointer of device driver structure
- * @param pos the position of reading
- * @param buffer the data buffer to save read data
- * @param size the size of buffer
+ * @param size is the size of buffer.
*
* @return the actually read size on successful, otherwise negative returned.
*
@@ -328,12 +335,15 @@ rt_size_t rt_device_read(rt_device_t dev,
RTM_EXPORT(rt_device_read);
/**
- * This function will write some data to a device.
+ * @brief This function will write some data to a device.
*
- * @param dev the pointer of device driver structure
- * @param pos the position of written
- * @param buffer the data buffer to be written to device
- * @param size the size of buffer
+ * @param dev is the pointer of device driver structure.
+ *
+ * @param pos is the position when writing.
+ *
+ * @param buffer is the data buffer to be written to device.
+ *
+ * @param size is the size of buffer.
*
* @return the actually written size on successful, otherwise negative returned.
*
@@ -367,13 +377,15 @@ rt_size_t rt_device_write(rt_device_t dev,
RTM_EXPORT(rt_device_write);
/**
- * This function will perform a variety of control functions on devices.
+ * @brief This function will perform a variety of control functions on devices.
+ *
+ * @param dev is the pointer of device driver structure.
*
- * @param dev the pointer of device driver structure
- * @param cmd the command sent to device
- * @param arg the argument of command
+ * @param cmd is the command sent to device.
*
- * @return the result
+ * @param arg is the argument of command.
+ *
+ * @return the result, -RT_ENOSYS for failed.
*/
rt_err_t rt_device_control(rt_device_t dev, int cmd, void *arg)
{
@@ -391,11 +403,12 @@ rt_err_t rt_device_control(rt_device_t dev, int cmd, void *arg)
RTM_EXPORT(rt_device_control);
/**
- * This function will set the reception indication callback function. This callback function
- * is invoked when this device receives data.
+ * @brief This function will set the reception indication callback function. This callback function
+ * is invoked when this device receives data.
+ *
+ * @param dev is the pointer of device driver structure.
*
- * @param dev the pointer of device driver structure
- * @param rx_ind the indication callback function
+ * @param rx_ind is the indication callback function.
*
* @return RT_EOK
*/
@@ -413,11 +426,12 @@ rt_device_set_rx_indicate(rt_device_t dev,
RTM_EXPORT(rt_device_set_rx_indicate);
/**
- * This function will set the indication callback function when device has
- * written data to physical hardware.
+ * @brief This function will set a callback function. The callback function
+ * will be called when device has written data to physical hardware.
+ *
+ * @param dev is the pointer of device driver structure.
*
- * @param dev the pointer of device driver structure
- * @param tx_done the indication callback function
+ * @param tx_done is the indication callback function.
*
* @return RT_EOK
*/
diff --git a/src/idle.c b/src/idle.c
index a571e487cf..61f6a5b383 100644
--- a/src/idle.c
+++ b/src/idle.c
@@ -68,14 +68,13 @@ static struct rt_semaphore system_sem;
static void (*idle_hook_list[RT_IDLE_HOOK_LIST_SIZE])(void);
/**
- * @ingroup Hook
- * This function sets a hook function to idle thread loop. When the system performs
- * idle loop, this hook function should be invoked.
+ * @brief This function sets a hook function to idle thread loop. When the system performs
+ * idle loop, this hook function should be invoked.
*
- * @param hook the specified hook function
+ * @param hook the specified hook function.
*
- * @return RT_EOK: set OK
- * -RT_EFULL: hook list is full
+ * @return RT_EOK: set OK.
+ * -RT_EFULL: hook list is full.
*
* @note the hook function must be simple and never be blocked or suspend.
*/
@@ -104,12 +103,12 @@ rt_err_t rt_thread_idle_sethook(void (*hook)(void))
}
/**
- * delete the idle hook on hook list
+ * @brief delete the idle hook on hook list.
*
- * @param hook the specified hook function
+ * @param hook the specified hook function.
*
- * @return RT_EOK: delete OK
- * -RT_ENOSYS: hook was not found
+ * @return RT_EOK: delete OK.
+ * -RT_ENOSYS: hook was not found.
*/
rt_err_t rt_thread_idle_delhook(void (*hook)(void))
{
@@ -139,7 +138,7 @@ rt_err_t rt_thread_idle_delhook(void (*hook)(void))
#ifdef RT_USING_MODULE
/* Return whether there is defunctional thread to be deleted. */
-rt_inline int _has_defunct_thread(void)
+rt_inline int _idle_has_defunct_thread(void)
{
/* The rt_list_isempty has prototype of "int rt_list_isempty(const rt_list_t *l)".
* So the compiler has a good reason that the _rt_thread_defunct list does
@@ -153,8 +152,10 @@ rt_inline int _has_defunct_thread(void)
}
#endif /* RT_USING_MODULE */
-/* enqueue a thread to defunct queue
- * it must be called between rt_hw_interrupt_disable and rt_hw_interrupt_enable
+/**
+ * @brief Enqueue a thread to defunct queue.
+ *
+ * @note It must be called between rt_hw_interrupt_disable and rt_hw_interrupt_enable
*/
void rt_thread_defunct_enqueue(rt_thread_t thread)
{
@@ -164,8 +165,10 @@ void rt_thread_defunct_enqueue(rt_thread_t thread)
#endif
}
-/* dequeue a thread from defunct queue
- * it must be called between rt_hw_interrupt_disable and rt_hw_interrupt_enable
+/**
+ * @brief Dequeue a thread from defunct queue.
+ *
+ * @note It must be called between rt_hw_interrupt_disable and rt_hw_interrupt_enable.
*/
rt_thread_t rt_thread_defunct_dequeue(void)
{
@@ -183,9 +186,7 @@ rt_thread_t rt_thread_defunct_dequeue(void)
}
/**
- * @ingroup Thread
- *
- * This function will perform system background job when system idle.
+ * @brief This function will perform system background job when system idle.
*/
static void rt_defunct_execute(void)
{
@@ -207,7 +208,7 @@ static void rt_defunct_execute(void)
#ifdef RT_USING_MODULE
/* check whether list is empty */
- if (!_has_defunct_thread())
+ if (!_idle_has_defunct_thread())
{
rt_hw_interrupt_enable(lock);
break;
@@ -316,9 +317,7 @@ static void rt_thread_system_entry(void *parameter)
#endif
/**
- * @ingroup SystemInit
- *
- * This function will initialize idle thread, then start it.
+ * @brief This function will initialize idle thread, then start it.
*
* @note this function must be invoked when system init.
*/
@@ -365,10 +364,7 @@ void rt_thread_idle_init(void)
}
/**
- * @ingroup Thread
- *
- * This function will get the handler of the idle thread.
- *
+ * @brief This function will get the handler of the idle thread.
*/
rt_thread_t rt_thread_idle_gethandler(void)
{
diff --git a/src/ipc.c b/src/ipc.c
index 8acfd831d7..da2996a30e 100755
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -68,7 +68,7 @@ extern void (*rt_object_put_hook)(struct rt_object *object);
*
* @warning This function can be called from all IPC initialization and creation.
*/
-rt_inline rt_err_t rt_ipc_object_init(struct rt_ipc_object *ipc)
+rt_inline rt_err_t _ipc_object_init(struct rt_ipc_object *ipc)
{
/* initialize ipc object */
rt_list_init(&(ipc->suspend_thread));
@@ -106,9 +106,9 @@ rt_inline rt_err_t rt_ipc_object_init(struct rt_ipc_object *ipc)
* rt_sem_take(), rt_mutex_take(), rt_event_recv(), rt_mb_send_wait(),
* rt_mb_recv(), rt_mq_recv(), rt_mq_send_wait()
*/
-rt_inline rt_err_t rt_ipc_list_suspend(rt_list_t *list,
- struct rt_thread *thread,
- rt_uint8_t flag)
+rt_inline rt_err_t _ipc_list_suspend(rt_list_t *list,
+ struct rt_thread *thread,
+ rt_uint8_t flag)
{
/* suspend thread */
rt_thread_suspend(thread);
@@ -175,7 +175,7 @@ rt_inline rt_err_t rt_ipc_list_suspend(rt_list_t *list,
* rt_sem_release(), rt_mutex_release(), rt_mb_send_wait(), rt_mq_send_wait(),
* rt_mb_urgent(), rt_mb_recv(), rt_mq_urgent(), rt_mq_recv(),
*/
-rt_inline rt_err_t rt_ipc_list_resume(rt_list_t *list)
+rt_inline rt_err_t _ipc_list_resume(rt_list_t *list)
{
struct rt_thread *thread;
@@ -204,7 +204,7 @@ rt_inline rt_err_t rt_ipc_list_resume(rt_list_t *list)
* When the return value is any other values, it means this operation failed.
*
*/
-rt_inline rt_err_t rt_ipc_list_resume_all(rt_list_t *list)
+rt_inline rt_err_t _ipc_list_resume_all(rt_list_t *list)
{
struct rt_thread *thread;
register rt_ubase_t temp;
@@ -287,12 +287,13 @@ rt_err_t rt_sem_init(rt_sem_t sem,
{
RT_ASSERT(sem != RT_NULL);
RT_ASSERT(value < 0x10000U);
+ RT_ASSERT((flag == RT_IPC_FLAG_FIFO) || (flag == RT_IPC_FLAG_PRIO));
/* initialize object */
rt_object_init(&(sem->parent.parent), RT_Object_Class_Semaphore, name);
/* initialize ipc object */
- rt_ipc_object_init(&(sem->parent));
+ _ipc_object_init(&(sem->parent));
/* set initial value */
sem->value = (rt_uint16_t)value;
@@ -331,7 +332,7 @@ rt_err_t rt_sem_detach(rt_sem_t sem)
RT_ASSERT(rt_object_is_systemobject(&sem->parent.parent));
/* wakeup all suspended threads */
- rt_ipc_list_resume_all(&(sem->parent.suspend_thread));
+ _ipc_list_resume_all(&(sem->parent.suspend_thread));
/* detach semaphore object */
rt_object_detach(&(sem->parent.parent));
@@ -377,8 +378,10 @@ rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag)
{
rt_sem_t sem;
- RT_DEBUG_NOT_IN_INTERRUPT;
RT_ASSERT(value < 0x10000U);
+ RT_ASSERT((flag == RT_IPC_FLAG_FIFO) || (flag == RT_IPC_FLAG_PRIO));
+
+ RT_DEBUG_NOT_IN_INTERRUPT;
/* allocate object */
sem = (rt_sem_t)rt_object_allocate(RT_Object_Class_Semaphore, name);
@@ -386,7 +389,7 @@ rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag)
return sem;
/* initialize ipc object */
- rt_ipc_object_init(&(sem->parent));
+ _ipc_object_init(&(sem->parent));
/* set initial value */
sem->value = value;
@@ -419,15 +422,15 @@ RTM_EXPORT(rt_sem_create);
*/
rt_err_t rt_sem_delete(rt_sem_t sem)
{
- RT_DEBUG_NOT_IN_INTERRUPT;
-
/* parameter check */
RT_ASSERT(sem != RT_NULL);
RT_ASSERT(rt_object_get_type(&sem->parent.parent) == RT_Object_Class_Semaphore);
RT_ASSERT(rt_object_is_systemobject(&sem->parent.parent) == RT_FALSE);
+ RT_DEBUG_NOT_IN_INTERRUPT;
+
/* wakeup all suspended threads */
- rt_ipc_list_resume_all(&(sem->parent.suspend_thread));
+ _ipc_list_resume_all(&(sem->parent.suspend_thread));
/* delete semaphore object */
rt_object_delete(&(sem->parent.parent));
@@ -513,7 +516,7 @@ rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time)
thread->name));
/* suspend thread */
- rt_ipc_list_suspend(&(sem->parent.suspend_thread),
+ _ipc_list_suspend(&(sem->parent.suspend_thread),
thread,
sem->parent.parent.flag);
@@ -607,7 +610,7 @@ rt_err_t rt_sem_release(rt_sem_t sem)
if (!rt_list_isempty(&sem->parent.suspend_thread))
{
/* resume the suspended thread */
- rt_ipc_list_resume(&(sem->parent.suspend_thread));
+ _ipc_list_resume(&(sem->parent.suspend_thread));
need_schedule = RT_TRUE;
}
else
@@ -667,7 +670,7 @@ rt_err_t rt_sem_control(rt_sem_t sem, int cmd, void *arg)
level = rt_hw_interrupt_disable();
/* resume all waiting thread */
- rt_ipc_list_resume_all(&sem->parent.suspend_thread);
+ _ipc_list_resume_all(&sem->parent.suspend_thread);
/* set new value */
sem->value = (rt_uint16_t)value;
@@ -730,7 +733,7 @@ rt_err_t rt_mutex_init(rt_mutex_t mutex, const char *name, rt_uint8_t flag)
rt_object_init(&(mutex->parent.parent), RT_Object_Class_Mutex, name);
/* initialize ipc object */
- rt_ipc_object_init(&(mutex->parent));
+ _ipc_object_init(&(mutex->parent));
mutex->value = 1;
mutex->owner = RT_NULL;
@@ -771,7 +774,7 @@ rt_err_t rt_mutex_detach(rt_mutex_t mutex)
RT_ASSERT(rt_object_is_systemobject(&mutex->parent.parent));
/* wakeup all suspended threads */
- rt_ipc_list_resume_all(&(mutex->parent.suspend_thread));
+ _ipc_list_resume_all(&(mutex->parent.suspend_thread));
/* detach mutex object */
rt_object_detach(&(mutex->parent.parent));
@@ -813,7 +816,7 @@ rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag)
return mutex;
/* initialize ipc object */
- rt_ipc_object_init(&(mutex->parent));
+ _ipc_object_init(&(mutex->parent));
mutex->value = 1;
mutex->owner = RT_NULL;
@@ -848,15 +851,15 @@ RTM_EXPORT(rt_mutex_create);
*/
rt_err_t rt_mutex_delete(rt_mutex_t mutex)
{
- RT_DEBUG_NOT_IN_INTERRUPT;
-
/* parameter check */
RT_ASSERT(mutex != RT_NULL);
RT_ASSERT(rt_object_get_type(&mutex->parent.parent) == RT_Object_Class_Mutex);
RT_ASSERT(rt_object_is_systemobject(&mutex->parent.parent) == RT_FALSE);
+ RT_DEBUG_NOT_IN_INTERRUPT;
+
/* wakeup all suspended threads */
- rt_ipc_list_resume_all(&(mutex->parent.suspend_thread));
+ _ipc_list_resume_all(&(mutex->parent.suspend_thread));
/* delete mutex object */
rt_object_delete(&(mutex->parent.parent));
@@ -985,7 +988,7 @@ __again:
}
/* suspend current thread */
- rt_ipc_list_suspend(&(mutex->parent.suspend_thread),
+ _ipc_list_suspend(&(mutex->parent.suspend_thread),
thread,
mutex->parent.parent.flag);
@@ -1150,7 +1153,7 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex)
}
/* resume thread */
- rt_ipc_list_resume(&(mutex->parent.suspend_thread));
+ _ipc_list_resume(&(mutex->parent.suspend_thread));
need_schedule = RT_TRUE;
}
@@ -1234,10 +1237,6 @@ RTM_EXPORT(rt_mutex_control);
*
* @param name is a pointer to the name that given to the event.
*
- * @param value is the initial value for the event.
- * If want to share resources, you should initialize the value as the number of available resources.
- * If want to signal the occurrence of an event, you should initialize the value as 0.
- *
* @param flag is the event flag, which determines the queuing way of how multiple threads wait
* when the event is not available.
* The event flag can be ONE of the following values:
@@ -1261,6 +1260,7 @@ rt_err_t rt_event_init(rt_event_t event, const char *name, rt_uint8_t flag)
{
/* parameter check */
RT_ASSERT(event != RT_NULL);
+ RT_ASSERT((flag == RT_IPC_FLAG_FIFO) || (flag == RT_IPC_FLAG_PRIO));
/* initialize object */
rt_object_init(&(event->parent.parent), RT_Object_Class_Event, name);
@@ -1269,7 +1269,7 @@ rt_err_t rt_event_init(rt_event_t event, const char *name, rt_uint8_t flag)
event->parent.parent.flag = flag;
/* initialize ipc object */
- rt_ipc_object_init(&(event->parent));
+ _ipc_object_init(&(event->parent));
/* initialize event */
event->set = 0;
@@ -1305,7 +1305,7 @@ rt_err_t rt_event_detach(rt_event_t event)
RT_ASSERT(rt_object_is_systemobject(&event->parent.parent));
/* resume all suspended thread */
- rt_ipc_list_resume_all(&(event->parent.suspend_thread));
+ _ipc_list_resume_all(&(event->parent.suspend_thread));
/* detach event object */
rt_object_detach(&(event->parent.parent));
@@ -1347,6 +1347,8 @@ rt_event_t rt_event_create(const char *name, rt_uint8_t flag)
{
rt_event_t event;
+ RT_ASSERT((flag == RT_IPC_FLAG_FIFO) || (flag == RT_IPC_FLAG_PRIO));
+
RT_DEBUG_NOT_IN_INTERRUPT;
/* allocate object */
@@ -1358,7 +1360,7 @@ rt_event_t rt_event_create(const char *name, rt_uint8_t flag)
event->parent.parent.flag = flag;
/* initialize ipc object */
- rt_ipc_object_init(&(event->parent));
+ _ipc_object_init(&(event->parent));
/* initialize event */
event->set = 0;
@@ -1396,7 +1398,7 @@ rt_err_t rt_event_delete(rt_event_t event)
RT_DEBUG_NOT_IN_INTERRUPT;
/* resume all suspended thread */
- rt_ipc_list_resume_all(&(event->parent.suspend_thread));
+ _ipc_list_resume_all(&(event->parent.suspend_thread));
/* delete event object */
rt_object_delete(&(event->parent.parent));
@@ -1628,7 +1630,7 @@ rt_err_t rt_event_recv(rt_event_t event,
thread->event_info = option;
/* put thread to suspended thread list */
- rt_ipc_list_suspend(&(event->parent.suspend_thread),
+ _ipc_list_suspend(&(event->parent.suspend_thread),
thread,
event->parent.parent.flag);
@@ -1700,7 +1702,7 @@ rt_err_t rt_event_control(rt_event_t event, int cmd, void *arg)
level = rt_hw_interrupt_disable();
/* resume all waiting thread */
- rt_ipc_list_resume_all(&event->parent.suspend_thread);
+ _ipc_list_resume_all(&event->parent.suspend_thread);
/* initialize event set */
event->set = 0;
@@ -1741,9 +1743,6 @@ RTM_EXPORT(rt_event_control);
*
* @param name is a pointer to the name that given to the mailbox.
*
- * @param msgpoll is a pointer to the starting address of the memory space you allocated for the mailbox in advance.
- * In other words, msgpoll is a pointer to the mailbox buffer of the starting address.
- *
* @param size is the maximum number of mails in the mailbox.
* For example, when the mailbox buffer capacity is N, size is N/4.
*
@@ -1773,6 +1772,7 @@ rt_err_t rt_mb_init(rt_mailbox_t mb,
rt_uint8_t flag)
{
RT_ASSERT(mb != RT_NULL);
+ RT_ASSERT((flag == RT_IPC_FLAG_FIFO) || (flag == RT_IPC_FLAG_PRIO));
/* initialize object */
rt_object_init(&(mb->parent.parent), RT_Object_Class_MailBox, name);
@@ -1781,7 +1781,7 @@ rt_err_t rt_mb_init(rt_mailbox_t mb,
mb->parent.parent.flag = flag;
/* initialize ipc object */
- rt_ipc_object_init(&(mb->parent));
+ _ipc_object_init(&(mb->parent));
/* initialize mailbox */
mb->msg_pool = (rt_ubase_t *)msgpool;
@@ -1824,9 +1824,9 @@ rt_err_t rt_mb_detach(rt_mailbox_t mb)
RT_ASSERT(rt_object_is_systemobject(&mb->parent.parent));
/* resume all suspended thread */
- rt_ipc_list_resume_all(&(mb->parent.suspend_thread));
+ _ipc_list_resume_all(&(mb->parent.suspend_thread));
/* also resume all mailbox private suspended thread */
- rt_ipc_list_resume_all(&(mb->suspend_sender_thread));
+ _ipc_list_resume_all(&(mb->suspend_sender_thread));
/* detach mailbox object */
rt_object_detach(&(mb->parent.parent));
@@ -1871,6 +1871,8 @@ rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag)
{
rt_mailbox_t mb;
+ RT_ASSERT((flag == RT_IPC_FLAG_FIFO) || (flag == RT_IPC_FLAG_PRIO));
+
RT_DEBUG_NOT_IN_INTERRUPT;
/* allocate object */
@@ -1882,7 +1884,7 @@ rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag)
mb->parent.parent.flag = flag;
/* initialize ipc object */
- rt_ipc_object_init(&(mb->parent));
+ _ipc_object_init(&(mb->parent));
/* initialize mailbox */
mb->size = size;
@@ -1926,18 +1928,18 @@ RTM_EXPORT(rt_mb_create);
*/
rt_err_t rt_mb_delete(rt_mailbox_t mb)
{
- RT_DEBUG_NOT_IN_INTERRUPT;
-
/* parameter check */
RT_ASSERT(mb != RT_NULL);
RT_ASSERT(rt_object_get_type(&mb->parent.parent) == RT_Object_Class_MailBox);
RT_ASSERT(rt_object_is_systemobject(&mb->parent.parent) == RT_FALSE);
+ RT_DEBUG_NOT_IN_INTERRUPT;
+
/* resume all suspended thread */
- rt_ipc_list_resume_all(&(mb->parent.suspend_thread));
+ _ipc_list_resume_all(&(mb->parent.suspend_thread));
/* also resume all mailbox private suspended thread */
- rt_ipc_list_resume_all(&(mb->suspend_sender_thread));
+ _ipc_list_resume_all(&(mb->suspend_sender_thread));
/* free mailbox pool */
RT_KERNEL_FREE(mb->msg_pool);
@@ -2020,7 +2022,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb,
RT_DEBUG_IN_THREAD_CONTEXT;
/* suspend current thread */
- rt_ipc_list_suspend(&(mb->suspend_sender_thread),
+ _ipc_list_suspend(&(mb->suspend_sender_thread),
thread,
mb->parent.parent.flag);
@@ -2087,7 +2089,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb,
/* resume suspended thread */
if (!rt_list_isempty(&mb->parent.suspend_thread))
{
- rt_ipc_list_resume(&(mb->parent.suspend_thread));
+ _ipc_list_resume(&(mb->parent.suspend_thread));
/* enable interrupt */
rt_hw_interrupt_enable(temp);
@@ -2183,7 +2185,7 @@ rt_err_t rt_mb_urgent(rt_mailbox_t mb, rt_ubase_t value)
/* resume suspended thread */
if (!rt_list_isempty(&mb->parent.suspend_thread))
{
- rt_ipc_list_resume(&(mb->parent.suspend_thread));
+ _ipc_list_resume(&(mb->parent.suspend_thread));
/* enable interrupt */
rt_hw_interrupt_enable(temp);
@@ -2266,7 +2268,7 @@ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout)
RT_DEBUG_IN_THREAD_CONTEXT;
/* suspend current thread */
- rt_ipc_list_suspend(&(mb->parent.suspend_thread),
+ _ipc_list_suspend(&(mb->parent.suspend_thread),
thread,
mb->parent.parent.flag);
@@ -2329,7 +2331,7 @@ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout)
/* resume suspended thread */
if (!rt_list_isempty(&(mb->suspend_sender_thread)))
{
- rt_ipc_list_resume(&(mb->suspend_sender_thread));
+ _ipc_list_resume(&(mb->suspend_sender_thread));
/* enable interrupt */
rt_hw_interrupt_enable(temp);
@@ -2379,9 +2381,9 @@ rt_err_t rt_mb_control(rt_mailbox_t mb, int cmd, void *arg)
level = rt_hw_interrupt_disable();
/* resume all waiting thread */
- rt_ipc_list_resume_all(&(mb->parent.suspend_thread));
+ _ipc_list_resume_all(&(mb->parent.suspend_thread));
/* also resume all mailbox private suspended thread */
- rt_ipc_list_resume_all(&(mb->suspend_sender_thread));
+ _ipc_list_resume_all(&(mb->suspend_sender_thread));
/* re-init mailbox */
mb->entry = 0;
@@ -2470,6 +2472,7 @@ rt_err_t rt_mq_init(rt_mq_t mq,
/* parameter check */
RT_ASSERT(mq != RT_NULL);
+ RT_ASSERT((flag == RT_IPC_FLAG_FIFO) || (flag == RT_IPC_FLAG_PRIO));
/* initialize object */
rt_object_init(&(mq->parent.parent), RT_Object_Class_MessageQueue, name);
@@ -2478,7 +2481,7 @@ rt_err_t rt_mq_init(rt_mq_t mq,
mq->parent.parent.flag = flag;
/* initialize ipc object */
- rt_ipc_object_init(&(mq->parent));
+ _ipc_object_init(&(mq->parent));
/* set message pool */
mq->msg_pool = msgpool;
@@ -2538,9 +2541,9 @@ rt_err_t rt_mq_detach(rt_mq_t mq)
RT_ASSERT(rt_object_is_systemobject(&mq->parent.parent));
/* resume all suspended thread */
- rt_ipc_list_resume_all(&mq->parent.suspend_thread);
+ _ipc_list_resume_all(&mq->parent.suspend_thread);
/* also resume all message queue private suspended thread */
- rt_ipc_list_resume_all(&(mq->suspend_sender_thread));
+ _ipc_list_resume_all(&(mq->suspend_sender_thread));
/* detach message queue object */
rt_object_detach(&(mq->parent.parent));
@@ -2591,6 +2594,8 @@ rt_mq_t rt_mq_create(const char *name,
struct rt_mq_message *head;
register rt_base_t temp;
+ RT_ASSERT((flag == RT_IPC_FLAG_FIFO) || (flag == RT_IPC_FLAG_PRIO));
+
RT_DEBUG_NOT_IN_INTERRUPT;
/* allocate object */
@@ -2602,7 +2607,7 @@ rt_mq_t rt_mq_create(const char *name,
mq->parent.parent.flag = flag;
/* initialize ipc object */
- rt_ipc_object_init(&(mq->parent));
+ _ipc_object_init(&(mq->parent));
/* initialize message queue */
@@ -2665,17 +2670,17 @@ RTM_EXPORT(rt_mq_create);
*/
rt_err_t rt_mq_delete(rt_mq_t mq)
{
- RT_DEBUG_NOT_IN_INTERRUPT;
-
/* parameter check */
RT_ASSERT(mq != RT_NULL);
RT_ASSERT(rt_object_get_type(&mq->parent.parent) == RT_Object_Class_MessageQueue);
RT_ASSERT(rt_object_is_systemobject(&mq->parent.parent) == RT_FALSE);
+ RT_DEBUG_NOT_IN_INTERRUPT;
+
/* resume all suspended thread */
- rt_ipc_list_resume_all(&(mq->parent.suspend_thread));
+ _ipc_list_resume_all(&(mq->parent.suspend_thread));
/* also resume all message queue private suspended thread */
- rt_ipc_list_resume_all(&(mq->suspend_sender_thread));
+ _ipc_list_resume_all(&(mq->suspend_sender_thread));
/* free message queue pool */
RT_KERNEL_FREE(mq->msg_pool);
@@ -2776,7 +2781,7 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq,
RT_DEBUG_IN_THREAD_CONTEXT;
/* suspend current thread */
- rt_ipc_list_suspend(&(mq->suspend_sender_thread),
+ _ipc_list_suspend(&(mq->suspend_sender_thread),
thread,
mq->parent.parent.flag);
@@ -2862,7 +2867,7 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq,
/* resume suspended thread */
if (!rt_list_isempty(&mq->parent.suspend_thread))
{
- rt_ipc_list_resume(&(mq->parent.suspend_thread));
+ _ipc_list_resume(&(mq->parent.suspend_thread));
/* enable interrupt */
rt_hw_interrupt_enable(temp);
@@ -2991,7 +2996,7 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size)
/* resume suspended thread */
if (!rt_list_isempty(&mq->parent.suspend_thread))
{
- rt_ipc_list_resume(&(mq->parent.suspend_thread));
+ _ipc_list_resume(&(mq->parent.suspend_thread));
/* enable interrupt */
rt_hw_interrupt_enable(temp);
@@ -3081,7 +3086,7 @@ rt_err_t rt_mq_recv(rt_mq_t mq,
}
/* suspend current thread */
- rt_ipc_list_suspend(&(mq->parent.suspend_thread),
+ _ipc_list_suspend(&(mq->parent.suspend_thread),
thread,
mq->parent.parent.flag);
@@ -3157,7 +3162,7 @@ rt_err_t rt_mq_recv(rt_mq_t mq,
/* resume suspended thread */
if (!rt_list_isempty(&(mq->suspend_sender_thread)))
{
- rt_ipc_list_resume(&(mq->suspend_sender_thread));
+ _ipc_list_resume(&(mq->suspend_sender_thread));
/* enable interrupt */
rt_hw_interrupt_enable(temp);
@@ -3208,9 +3213,9 @@ rt_err_t rt_mq_control(rt_mq_t mq, int cmd, void *arg)
level = rt_hw_interrupt_disable();
/* resume all waiting thread */
- rt_ipc_list_resume_all(&mq->parent.suspend_thread);
+ _ipc_list_resume_all(&mq->parent.suspend_thread);
/* also resume all message queue private suspended thread */
- rt_ipc_list_resume_all(&(mq->suspend_sender_thread));
+ _ipc_list_resume_all(&(mq->suspend_sender_thread));
/* release all message in the queue */
while (mq->msg_queue_head != RT_NULL)
diff --git a/src/irq.c b/src/irq.c
index 6ddcb3dd4a..3889a2a2c8 100644
--- a/src/irq.c
+++ b/src/irq.c
@@ -9,6 +9,7 @@
* 2006-05-03 Bernard add IRQ_DEBUG
* 2016-08-09 ArdaFu add interrupt enter and leave hook.
* 2018-11-22 Jesven rt_interrupt_get_nest function add disable irq
+ * 2021-08-15 Supperthomas fix the comment
*/
#include <rthw.h>
@@ -21,19 +22,26 @@ static void (*rt_interrupt_leave_hook)(void);
/**
* @ingroup Hook
- * This function set a hook function when the system enter a interrupt
*
- * @note the hook function must be simple and never be blocked or suspend.
+ * @brief This function set a hook function when the system enter a interrupt
+ *
+ * @note The hook function must be simple and never be blocked or suspend.
+ *
+ * @param hook the function point to be called
*/
void rt_interrupt_enter_sethook(void (*hook)(void))
{
rt_interrupt_enter_hook = hook;
}
+
/**
* @ingroup Hook
- * This function set a hook function when the system exit a interrupt.
*
- * @note the hook function must be simple and never be blocked or suspend.
+ * @brief This function set a hook function when the system exit a interrupt.
+ *
+ * @note The hook function must be simple and never be blocked or suspend.
+ *
+ * @param hook the function point to be called
*/
void rt_interrupt_leave_sethook(void (*hook)(void))
{
@@ -53,10 +61,11 @@ void rt_interrupt_leave_sethook(void (*hook)(void))
volatile rt_uint8_t rt_interrupt_nest = 0;
#endif /* RT_USING_SMP */
+
/**
- * This function will be invoked by BSP, when enter interrupt service routine
+ * @brief This function will be invoked by BSP, when enter interrupt service routine
*
- * @note please don't invoke this routine in application
+ * @note Please don't invoke this routine in application
*
* @see rt_interrupt_leave
*/
@@ -74,10 +83,11 @@ void rt_interrupt_enter(void)
}
RTM_EXPORT(rt_interrupt_enter);
+
/**
- * This function will be invoked by BSP, when leave interrupt service routine
+ * @brief This function will be invoked by BSP, when leave interrupt service routine
*
- * @note please don't invoke this routine in application
+ * @note Please don't invoke this routine in application
*
* @see rt_interrupt_enter
*/
@@ -95,8 +105,9 @@ void rt_interrupt_leave(void)
}
RTM_EXPORT(rt_interrupt_leave);
+
/**
- * This function will return the nest of interrupt.
+ * @brief This function will return the nest of interrupt.
*
* User application can invoke this function to get whether current
* context is interrupt context.
diff --git a/src/kservice.c b/src/kservice.c
index 49e1486078..4ed30f3237 100644
--- a/src/kservice.c
+++ b/src/kservice.c
@@ -43,8 +43,8 @@ static volatile int __rt_errno;
static rt_device_t _console_device = RT_NULL;
#endif
-/*
- * This function will get errno
+/**
+ * This function gets the global errno for the current thread.
*
* @return errno
*/
@@ -66,10 +66,10 @@ rt_err_t rt_get_errno(void)
}
RTM_EXPORT(rt_get_errno);
-/*
- * This function will set errno
+/**
+ * This function sets the global errno for the current thread.
*
- * @param error the errno shall be set
+ * @param error is the errno shall be set.
*/
void rt_set_errno(rt_err_t error)
{
@@ -96,9 +96,9 @@ void rt_set_errno(rt_err_t error)
RTM_EXPORT(rt_set_errno);
/**
- * This function returns errno.
+ * This function returns the address of the current thread errno.
*
- * @return the errno in the system
+ * @return The errno address.
*/
int *_rt_errno(void)
{
@@ -116,13 +116,16 @@ int *_rt_errno(void)
RTM_EXPORT(_rt_errno);
/**
- * This function will set the content of memory to specified value
+ * This function will set the content of memory to specified value.
+ *
+ * @param s is the address of source memory, point to the memory block to be filled.
+ *
+ * @param c is the value to be set. The value is passed in int form, but the function
+ * uses the unsigned character form of the value when filling the memory block.
*
- * @param s the address of source memory
- * @param c the value shall be set in content
- * @param count the copied length
+ * @param count number of bytes to be set.
*
- * @return the address of source memory
+ * @return The address of source memory.
*/
RT_WEAK void *rt_memset(void *s, int c, rt_ubase_t count)
{
@@ -198,17 +201,19 @@ RT_WEAK void *rt_memset(void *s, int c, rt_ubase_t count)
}
RTM_EXPORT(rt_memset);
+#ifndef RT_USING_ASM_MEMCPY
/**
- * This function will copy memory content from source address to destination
- * address.
+ * This function will copy memory content from source address to destination address.
*
- * @param dst the address of destination memory
- * @param src the address of source memory
- * @param count the copied length
+ * @param dst is the address of destination memory, points to the copied content.
*
- * @return the address of destination memory
+ * @param src is the address of source memory, pointing to the data source to be copied.
+ *
+ * @param count is the copied length.
+ *
+ * @return The address of destination memory
*/
-RT_WEAK void *rt_memcpy(void *dst, const void *src, rt_ubase_t count)
+void *rt_memcpy(void *dst, const void *src, rt_ubase_t count)
{
#ifdef RT_KSERVICE_USING_TINY_SIZE
char *tmp = (char *)dst, *s = (char *)src;
@@ -280,18 +285,22 @@ RT_WEAK void *rt_memcpy(void *dst, const void *src, rt_ubase_t count)
#endif /* RT_KSERVICE_USING_TINY_SIZE */
}
RTM_EXPORT(rt_memcpy);
+#endif /* RT_USING_ASM_MEMCPY */
#ifndef RT_KSERVICE_USING_STDLIB
/**
* This function will move memory content from source address to destination
- * address.
+ * address. If the destination memory does not overlap with the source memory,
+ * the function is the same as memcpy().
+ *
+ * @param dest is the address of destination memory, points to the copied content.
*
- * @param dest the address of destination memory
- * @param src the address of source memory
- * @param n the copied length
+ * @param src is the address of source memory, point to the data source to be copied.
*
- * @return the address of destination memory
+ * @param n is the copied length.
+ *
+ * @return The address of destination memory.
*/
void *rt_memmove(void *dest, const void *src, rt_ubase_t n)
{
@@ -316,13 +325,18 @@ void *rt_memmove(void *dest, const void *src, rt_ubase_t n)
RTM_EXPORT(rt_memmove);
/**
- * This function will compare two areas of memory
+ * This function will compare two areas of memory.
+ *
+ * @param cs is a block of memory.
*
- * @param cs one area of memory
- * @param ct another area of memory
- * @param count the size of the area
+ * @param ct is another block of memory.
*
- * @return the result
+ * @param count is the size of the area.
+ *
+ * @return Compare the results:
+ * If the result < 0, cs is smaller than ct.
+ * If the result > 0, cs is greater than ct.
+ * If the result = 0, cs is equal to ct.
*/
RT_WEAK rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_ubase_t count)
{
@@ -338,12 +352,14 @@ RT_WEAK rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_ubase_t count)
RTM_EXPORT(rt_memcmp);
/**
- * This function will return the first occurrence of a string.
+ * This function will return the first occurrence of a string, without the
+ * terminator '\0'.
+ *
+ * @param s1 is the source string.
*
- * @param s1 the source string
- * @param s2 the find string
+ * @param s2 is the find string.
*
- * @return the first occurrence of a s2 in s1, or RT_NULL if no found.
+ * @return The first occurrence of a s2 in s1, or RT_NULL if no found.
*/
char *rt_strstr(const char *s1, const char *s2)
{
@@ -368,10 +384,14 @@ RTM_EXPORT(rt_strstr);
/**
* This function will compare two strings while ignoring differences in case
*
- * @param a the string to be compared
- * @param b the string to be compared
+ * @param a is the string to be compared.
+ *
+ * @param b is the string to be compared.
*
- * @return the result
+ * @return Compare the results:
+ * If the result < 0, a is smaller than a.
+ * If the result > 0, a is greater than a.
+ * If the result = 0, a is equal to a.
*/
rt_int32_t rt_strcasecmp(const char *a, const char *b)
{
@@ -395,11 +415,13 @@ RTM_EXPORT(rt_strcasecmp);
/**
* This function will copy string no more than n bytes.
*
- * @param dst the string to copy
- * @param src the string to be copied
- * @param n the maximum copied length
+ * @param dst points to the address used to store the copied content.
+ *
+ * @param src is the string to be copied.
+ *
+ * @param n is the maximum copied length.
*
- * @return the result
+ * @return The address where the copied content is stored.
*/
char *rt_strncpy(char *dst, const char *src, rt_ubase_t n)
{
@@ -425,13 +447,18 @@ char *rt_strncpy(char *dst, const char *src, rt_ubase_t n)
RTM_EXPORT(rt_strncpy);
/**
- * This function will compare two strings with specified maximum length
+ * This function will compare two strings with specified maximum length.
*
- * @param cs the string to be compared
- * @param ct the string to be compared
- * @param count the maximum compare length
+ * @param cs is the string to be compared.
*
- * @return the result
+ * @param ct is the string to be compared.
+ *
+ * @param count is the maximum compare length.
+ *
+ * @return Compare the results:
+ * If the result < 0, cs is smaller than ct.
+ * If the result > 0, cs is greater than ct.
+ * If the result = 0, cs is equal to ct.
*/
rt_int32_t rt_strncmp(const char *cs, const char *ct, rt_ubase_t count)
{
@@ -449,12 +476,16 @@ rt_int32_t rt_strncmp(const char *cs, const char *ct, rt_ubase_t count)
RTM_EXPORT(rt_strncmp);
/**
- * This function will compare two strings without specified length
+ * This function will compare two strings without specified length.
+ *
+ * @param cs is the string to be compared.
*
- * @param cs the string to be compared
- * @param ct the string to be compared
+ * @param ct is the string to be compared.
*
- * @return the result
+ * @return Compare the results:
+ * If the result < 0, cs is smaller than ct.
+ * If the result > 0, cs is greater than ct.
+ * If the result = 0, cs is equal to ct.
*/
rt_int32_t rt_strcmp(const char *cs, const char *ct)
{
@@ -469,55 +500,62 @@ rt_int32_t rt_strcmp(const char *cs, const char *ct)
RTM_EXPORT(rt_strcmp);
/**
- * The strnlen() function returns the number of characters in the
- * string pointed to by s, excluding the terminating null byte ('\0'),
- * but at most maxlen. In doing this, strnlen() looks only at the
- * first maxlen characters in the string pointed to by s and never
- * beyond s+maxlen.
+ * This function will return the length of a string, which terminate will
+ * null character.
*
- * @param s the string
- * @param maxlen the max size
- * @return the length of string
+ * @param s is the string
+ *
+ * @return The length of string.
*/
-rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen)
+rt_size_t rt_strlen(const char *s)
{
const char *sc;
- for (sc = s; *sc != '\0' && (rt_ubase_t)(sc - s) < maxlen; ++sc) /* nothing */
+ for (sc = s; *sc != '\0'; ++sc) /* nothing */
;
return sc - s;
}
-RTM_EXPORT(rt_strnlen);
+RTM_EXPORT(rt_strlen);
+#endif /* RT_KSERVICE_USING_STDLIB */
+
+#if !defined(RT_KSERVICE_USING_STDLIB) || defined(__ARMCC_VERSION)
/**
- * This function will return the length of a string, which terminate will
- * null character.
+ * The strnlen() function returns the number of characters in the
+ * string pointed to by s, excluding the terminating null byte ('\0'),
+ * but at most maxlen. In doing this, strnlen() looks only at the
+ * first maxlen characters in the string pointed to by s and never
+ * beyond s+maxlen.
+ *
+ * @param s is the string.
*
- * @param s the string
+ * @param maxlen is the max size.
*
- * @return the length of string
+ * @return The length of string.
*/
-rt_size_t rt_strlen(const char *s)
+rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen)
{
const char *sc;
- for (sc = s; *sc != '\0'; ++sc) /* nothing */
+ for (sc = s; *sc != '\0' && (rt_ubase_t)(sc - s) < maxlen; ++sc) /* nothing */
;
return sc - s;
}
-RTM_EXPORT(rt_strlen);
-
-#endif /* RT_KSERVICE_USING_STDLIB */
+RTM_EXPORT(rt_strnlen);
+#ifdef __ARMCC_VERSION
+rt_size_t strnlen(const char *s, rt_size_t maxlen) __attribute__((alias("rt_strnlen")));
+#endif /* __ARMCC_VERSION */
+#endif /* !defined(RT_KSERVICE_USING_STDLIB) || defined(__ARMCC_VERSION) */
#ifdef RT_USING_HEAP
/**
* This function will duplicate a string.
*
- * @param s the string to be duplicated
+ * @param s is the string to be duplicated.
*
- * @return the duplicated string pointer
+ * @return The string address of the copy.
*/
char *rt_strdup(const char *s)
{
@@ -534,7 +572,7 @@ char *rt_strdup(const char *s)
RTM_EXPORT(rt_strdup);
#ifdef __ARMCC_VERSION
char *strdup(const char *s) __attribute__((alias("rt_strdup")));
-#endif
+#endif /* __ARMCC_VERSION */
#endif /* RT_USING_HEAP */
/**
@@ -544,8 +582,8 @@ void rt_show_version(void)
{
rt_kprintf("\n \\ | /\n");
rt_kprintf("- RT - Thread Operating System\n");
- rt_kprintf(" / | \\ %d.%d.%d build %s\n",
- RT_VERSION, RT_SUBVERSION, RT_REVISION, __DATE__);
+ 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");
}
RTM_EXPORT(rt_show_version);
@@ -554,6 +592,15 @@ RTM_EXPORT(rt_show_version);
#define _ISDIGIT(c) ((unsigned)((c) - '0') < 10)
#ifdef RT_PRINTF_LONGLONG
+/**
+ * This function will duplicate a string.
+ *
+ * @param n is the string to be duplicated.
+ *
+ * @param base is support divide instructions value.
+ *
+ * @return the duplicated string pointer.
+ */
rt_inline int divide(long long *n, int base)
{
int res;
@@ -782,6 +829,19 @@ static char *print_number(char *buf,
return buf;
}
+/**
+ * This function will fill a formatted string to buffer.
+ *
+ * @param buf is the buffer to save formatted string.
+ *
+ * @param size is the size of buffer.
+ *
+ * @param fmt is the format parameters.
+ *
+ * @param args is a list of variable parameters.
+ *
+ * @return The number of characters actually written to buffer.
+ */
rt_int32_t rt_vsnprintf(char *buf,
rt_size_t size,
const char *fmt,
@@ -1049,11 +1109,15 @@ rt_int32_t rt_vsnprintf(char *buf,
RTM_EXPORT(rt_vsnprintf);
/**
- * This function will fill a formatted string to buffer
+ * This function will fill a formatted string to buffer.
+ *
+ * @param buf is the buffer to save formatted string.
+ *
+ * @param size is the size of buffer.
*
- * @param buf the buffer to save formatted string
- * @param size the size of buffer
- * @param fmt the format
+ * @param fmt is the format parameters.
+ *
+ * @return The number of characters actually written to buffer.
*/
rt_int32_t rt_snprintf(char *buf, rt_size_t size, const char *fmt, ...)
{
@@ -1069,11 +1133,15 @@ rt_int32_t rt_snprintf(char *buf, rt_size_t size, const char *fmt, ...)
RTM_EXPORT(rt_snprintf);
/**
- * This function will fill a formatted string to buffer
+ * This function will fill a formatted string to buffer.
*
- * @param buf the buffer to save formatted string
- * @param arg_ptr the arg_ptr
- * @param format the format
+ * @param buf is the buffer to save formatted string.
+ *
+ * @param format is the format parameters.
+ *
+ * @param arg_ptr is a list of variable parameters.
+ *
+ * @return The number of characters actually written to buffer.
*/
rt_int32_t rt_vsprintf(char *buf, const char *format, va_list arg_ptr)
{
@@ -1084,8 +1152,11 @@ RTM_EXPORT(rt_vsprintf);
/**
* This function will fill a formatted string to buffer
*
- * @param buf the buffer to save formatted string
- * @param format the format
+ * @param buf the buffer to save formatted string.
+ *
+ * @param format is the format parameters.
+ *
+ * @return The number of characters actually written to buffer.
*/
rt_int32_t rt_sprintf(char *buf, const char *format, ...)
{
@@ -1106,7 +1177,7 @@ RTM_EXPORT(rt_sprintf);
/**
* This function returns the device using in console.
*
- * @return the device using in console or RT_NULL
+ * @return Returns the console device pointer or RT_NULL.
*/
rt_device_t rt_console_get_device(void)
{
@@ -1119,7 +1190,7 @@ RTM_EXPORT(rt_console_get_device);
* After set a device to console, all output of rt_kprintf will be
* redirected to this new device.
*
- * @param name the name of new console device
+ * @param name is the name of new console device.
*
* @return the old console device handler on successful, or RT_NULL on failure.
*/
@@ -1163,7 +1234,7 @@ RTM_EXPORT(rt_hw_console_output);
/**
* This function will put string to the console.
*
- * @param str the string output to the console.
+ * @param str is the string output to the console.
*/
void rt_kputs(const char *str)
{
@@ -1176,11 +1247,7 @@ void rt_kputs(const char *str)
}
else
{
- rt_uint16_t old_flag = _console_device->open_flag;
-
- _console_device->open_flag |= RT_DEVICE_FLAG_STREAM;
rt_device_write(_console_device, 0, str, rt_strlen(str));
- _console_device->open_flag = old_flag;
}
#else
rt_hw_console_output(str);
@@ -1188,9 +1255,9 @@ void rt_kputs(const char *str)
}
/**
- * This function will print a formatted string on system console
+ * This function will print a formatted string on system console.
*
- * @param fmt the format
+ * @param fmt is the format parameters.
*/
RT_WEAK void rt_kprintf(const char *fmt, ...)
{
@@ -1214,11 +1281,7 @@ RT_WEAK void rt_kprintf(const char *fmt, ...)
}
else
{
- rt_uint16_t old_flag = _console_device->open_flag;
-
- _console_device->open_flag |= RT_DEVICE_FLAG_STREAM;
rt_device_write(_console_device, 0, rt_log_buf, length);
- _console_device->open_flag = old_flag;
}
#else
rt_hw_console_output(rt_log_buf);
@@ -1233,10 +1296,12 @@ RTM_EXPORT(rt_kprintf);
* This function allocates a memory block, which address is aligned to the
* specified alignment size.
*
- * @param size the allocated memory block size
- * @param align the alignment size
+ * @param size is the allocated memory block size.
+ *
+ * @param align is the alignment size.
*
- * @return the allocated memory block on successful, otherwise returns RT_NULL
+ * @return The memory block address was returned successfully, otherwise it was
+ * returned empty RT_NULL.
*/
RT_WEAK void *rt_malloc_align(rt_size_t size, rt_size_t align)
{
@@ -1282,7 +1347,7 @@ RTM_EXPORT(rt_malloc_align);
* This function release the memory block, which is allocated by
* rt_malloc_align function and address is aligned.
*
- * @param ptr the memory block pointer
+ * @param ptr is the memory block pointer.
*/
RT_WEAK void rt_free_align(void *ptr)
{
@@ -1322,8 +1387,8 @@ const rt_uint8_t __lowest_bit_bitmap[] =
* Bits are numbered starting at 1 (the least significant bit). A return value of
* zero from any of these functions means that the argument was zero.
*
- * @return return the index of the first bit set. If value is 0, then this function
- * shall return 0.
+ * @return Return the index of the first bit set. If value is 0, then this function
+ * shall return 0.
*/
int __rt_ffs(int value)
{
@@ -1350,7 +1415,7 @@ void (*rt_assert_hook)(const char *ex, const char *func, rt_size_t line);
/**
* This function will set a hook function to RT_ASSERT(EX). It will run when the expression is false.
*
- * @param hook the hook function
+ * @param hook is the hook function.
*/
void rt_assert_set_hook(void (*hook)(const char *ex, const char *func, rt_size_t line))
{
@@ -1360,9 +1425,11 @@ void rt_assert_set_hook(void (*hook)(const char *ex, const char *func, rt_size_t
/**
* The RT_ASSERT function.
*
- * @param ex the assertion condition string
- * @param func the function name when assertion.
- * @param line the file line number when assertion.
+ * @param ex_string is the assertion condition string.
+ *
+ * @param func is the function name when assertion.
+ *
+ * @param line is the file line number when assertion.
*/
void rt_assert_handler(const char *ex_string, const char *func, rt_size_t line)
{
diff --git a/src/mem.c b/src/mem.c
index 20ac0e588c..3c0816748e 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -66,10 +66,10 @@ static void (*rt_free_hook)(void *ptr);
/**@{*/
/**
- * This function will set a hook function, which will be invoked when a memory
- * block is allocated from heap memory.
+ * @brief This function will set a hook function, which will be invoked when a memory
+ * block is allocated from heap memory.
*
- * @param hook the hook function
+ * @param hook the hook function.
*/
void rt_malloc_sethook(void (*hook)(void *ptr, rt_size_t size))
{
@@ -77,8 +77,8 @@ void rt_malloc_sethook(void (*hook)(void *ptr, rt_size_t size))
}
/**
- * This function will set a hook function, which will be invoked when a memory
- * block is released to heap memory.
+ * @brief This function will set a hook function, which will be invoked when a memory
+ * block is released to heap memory.
*
* @param hook the hook function
*/
@@ -194,11 +194,10 @@ static void plug_holes(struct heap_mem *mem)
}
/**
- * @ingroup SystemInit
- *
- * This function will initialize system heap memory.
+ * @brief This function will initialize system heap memory.
*
* @param begin_addr the beginning address of system heap memory.
+ *
* @param end_addr the end address of system heap memory.
*/
void rt_system_heap_init(void *begin_addr, void *end_addr)
@@ -263,11 +262,11 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
/**@{*/
/**
- * Allocate a block of memory with a minimum of 'size' bytes.
+ * @brief Allocate a block of memory with a minimum of 'size' bytes.
*
* @param size is the minimum size of the requested block in bytes.
*
- * @return pointer to allocated memory or NULL if no free memory was found.
+ * @return the pointer to allocated memory or NULL if no free memory was found.
*/
void *rt_malloc(rt_size_t size)
{
@@ -411,12 +410,13 @@ void *rt_malloc(rt_size_t size)
RTM_EXPORT(rt_malloc);
/**
- * This function will change the previously allocated memory block.
+ * @brief This function will change the size of previously allocated memory block.
*
- * @param rmem pointer to memory allocated by rt_malloc
- * @param newsize the required new size
+ * @param rmem is the pointer to memory allocated by rt_malloc.
*
- * @return the changed memory block address
+ * @param newsize is the required new size.
+ *
+ * @return the changed memory block address.
*/
void *rt_realloc(void *rmem, rt_size_t newsize)
{
@@ -517,16 +517,17 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
RTM_EXPORT(rt_realloc);
/**
- * This function will contiguously allocate enough space for count objects
- * that are size bytes of memory each and returns a pointer to the allocated
- * memory.
+ * @brief This function will contiguously allocate enough space for count objects
+ * that are size bytes of memory each and returns a pointer to the allocated
+ * memory.
+ *
+ * @note The allocated memory is filled with bytes of value zero.
*
- * The allocated memory is filled with bytes of value zero.
+ * @param count is the number of objects to allocate.
*
- * @param count number of objects to allocate
- * @param size size of the objects to allocate
+ * @param size is the size of one object to allocate.
*
- * @return pointer to allocated memory / NULL pointer if there is an error
+ * @return pointer to allocated memory / NULL pointer if there is an error.
*/
void *rt_calloc(rt_size_t count, rt_size_t size)
{
@@ -544,10 +545,10 @@ void *rt_calloc(rt_size_t count, rt_size_t size)
RTM_EXPORT(rt_calloc);
/**
- * This function will release the previously allocated memory block by
- * rt_malloc. The released memory block is taken back to system heap.
+ * @brief This function will release the previously allocated memory block by
+ * rt_malloc. The released memory block is taken back to system heap.
*
- * @param rmem the address of memory which will be released
+ * @param rmem the address of memory which will be released.
*/
void rt_free(void *rmem)
{
@@ -616,6 +617,16 @@ void rt_free(void *rmem)
RTM_EXPORT(rt_free);
#ifdef RT_MEM_STATS
+/**
+* @brief This function will caculate the total memory, the used memory, and
+* the max used memory.
+*
+* @param total is a pointer to get the total size of the memory.
+*
+* @param used is a pointer to get the size of memory used.
+*
+* @param max_used is a pointer to get the maximum memory used.
+*/
void rt_memory_info(rt_uint32_t *total,
rt_uint32_t *used,
rt_uint32_t *max_used)
diff --git a/src/memheap.c b/src/memheap.c
index d77c95601e..68a15d1a8e 100644
--- a/src/memheap.c
+++ b/src/memheap.c
@@ -39,6 +39,13 @@
#define MEMITEM(ptr) (struct rt_memheap_item*)((rt_uint8_t*)ptr - RT_MEMHEAP_SIZE)
#ifdef RT_USING_MEMTRACE
+/**
+ * @brief This function will set a new name for memheap.
+ *
+ * @param item is a pointer point to a memheap object.
+ *
+ * @param name is the new name to be set.
+ */
rt_inline void rt_memheap_setname(struct rt_memheap_item *item, const char *name)
{
int index;
@@ -64,6 +71,13 @@ rt_inline void rt_memheap_setname(struct rt_memheap_item *item, const char *name
}
}
+/**
+ * @brief This function will set a new name for memheap.
+ *
+ * @param ptr is a pointer point to a memheap object.
+ *
+ * @param name is the new name to be set.
+ */
void rt_mem_set_tag(void *ptr, const char *name)
{
struct rt_memheap_item *item;
@@ -76,16 +90,28 @@ void rt_mem_set_tag(void *ptr, const char *name)
}
#endif /* RT_USING_MEMTRACE */
-/*
- * The initialized memory pool will be:
- * +-----------------------------------+--------------------------+
- * | whole freed memory block | Used Memory Block Tailer |
- * +-----------------------------------+--------------------------+
+/**
+ * @brief This function initializes a piece of memory called memheap.
*
- * block_list --> whole freed memory block
+ * @note The initialized memory pool will be:
+ * +-----------------------------------+--------------------------+
+ * | whole freed memory block | Used Memory Block Tailer |
+ * +-----------------------------------+--------------------------+
*
- * The length of Used Memory Block Tailer is 0,
- * which is prevents block merging across list
+ * block_list --> whole freed memory block
+ *
+ * The length of Used Memory Block Tailer is 0,
+ * which is prevents block merging across list
+ *
+ * @param memheap is a pointer of the memheap object.
+ *
+ * @param name is the name of the memheap.
+ *
+ * @param start_addr is the start address of the memheap.
+ *
+ * @param size is the size of the memheap.
+ *
+ * @return RT_EOK
*/
rt_err_t rt_memheap_init(struct rt_memheap *memheap,
const char *name,
@@ -165,6 +191,13 @@ rt_err_t rt_memheap_init(struct rt_memheap *memheap,
}
RTM_EXPORT(rt_memheap_init);
+/**
+ * @brief This function will remove a memheap from the system.
+ *
+ * @param heap is a pointer of memheap object.
+ *
+ * @return RT_EOK
+ */
rt_err_t rt_memheap_detach(struct rt_memheap *heap)
{
RT_ASSERT(heap);
@@ -179,6 +212,15 @@ rt_err_t rt_memheap_detach(struct rt_memheap *heap)
}
RTM_EXPORT(rt_memheap_detach);
+/**
+ * @brief Allocate a block of memory with a minimum of 'size' bytes on memheap.
+ *
+ * @param heap is a pointer for memheap object.
+ *
+ * @param size is the minimum size of the requested block in bytes.
+ *
+ * @return the pointer to allocated memory or NULL if no free memory was found.
+ */
void *rt_memheap_alloc(struct rt_memheap *heap, rt_size_t size)
{
rt_err_t result;
@@ -336,6 +378,18 @@ void *rt_memheap_alloc(struct rt_memheap *heap, rt_size_t size)
}
RTM_EXPORT(rt_memheap_alloc);
+/**
+ * @brief This function will change the size of previously allocated memory block.
+ *
+ * @param heap is a pointer to the memheap object, which will reallocate
+ * memory from the block
+ *
+ * @param ptr is a pointer to start address of memory.
+ *
+ * @param newsize is the required new size.
+ *
+ * @return the changed memory block address.
+ */
void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
{
rt_err_t result;
@@ -438,7 +492,7 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
next_ptr->pool_ptr = heap;
#ifdef RT_USING_MEMTRACE
- rt_memset(next_ptr->owner_thread_name, ' ', sizeof(next_ptr->owner_thread_name));
+ rt_memset((void *)next_ptr->owner_thread_name, ' ', sizeof(next_ptr->owner_thread_name));
#endif /* RT_USING_MEMTRACE */
next_ptr->prev = header_ptr;
@@ -556,6 +610,12 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
}
RTM_EXPORT(rt_memheap_realloc);
+/**
+ * @brief This function will release the allocated memory block by
+ * rt_malloc. The released memory block is taken back to system heap.
+ *
+ * @param ptr the address of memory which will be released.
+ */
void rt_memheap_free(void *ptr)
{
rt_err_t result;
@@ -680,7 +740,13 @@ static void _memheap_dump_tag(struct rt_memheap_item *item)
rt_kprintf("%.*s", 2 * sizeof(void *), name);
}
-
+/**
+ * @brief This function will print the memheap infomation.
+ *
+ * @param heap is the pointer to the memheap to get information.
+ *
+ * @return 0
+ */
int rt_memheap_dump(struct rt_memheap *heap)
{
struct rt_memheap_item *item, *end;
@@ -730,13 +796,15 @@ int memheaptrace(void)
if (count > 0)
{
int index;
+#if defined(RT_USING_FINSH) && defined(MSH_USING_BUILT_IN_COMMANDS)
extern int list_memheap(void);
+#endif
heaps = (struct rt_memheap **)rt_malloc(sizeof(struct rt_memheap *) * count);
if (heaps == RT_NULL) return 0;
-
+#if defined(RT_USING_FINSH) && defined(MSH_USING_BUILT_IN_COMMANDS)
list_memheap();
-
+#endif
rt_kprintf("memheap header size: %d\n", RT_MEMHEAP_SIZE);
count = rt_object_get_pointers(RT_Object_Class_MemHeap, (rt_object_t *)heaps, count);
for (index = 0; index < count; index++)
@@ -755,6 +823,13 @@ MSH_CMD_EXPORT(memheaptrace, dump memory trace information);
#ifdef RT_USING_MEMHEAP_AS_HEAP
static struct rt_memheap _heap;
+/**
+ * @brief This function initializes a heap for system.
+ *
+ * @param begin_addr is the start address of the memory.
+ *
+ * @param end_addr is the end address of the memory.
+ */
void rt_system_heap_init(void *begin_addr, void *end_addr)
{
RT_ASSERT((rt_uint32_t)end_addr > (rt_uint32_t)begin_addr);
@@ -766,12 +841,18 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
(rt_uint32_t)end_addr - (rt_uint32_t)begin_addr);
}
+/**
+ * @brief Allocate a block of memory with a minimum of 'size' bytes.
+ *
+ * @param size is the minimum size of the requested block in bytes.
+ */
void *rt_malloc(rt_size_t size)
{
void *ptr;
/* try to allocate in system heap */
ptr = rt_memheap_alloc(&_heap, size);
+#ifdef RT_USING_MEMHEAP_AUTO_BINDING
if (ptr == RT_NULL)
{
struct rt_object *object;
@@ -801,7 +882,7 @@ void *rt_malloc(rt_size_t size)
break;
}
}
-
+#endif /* RT_USING_MEMHEAP_AUTO_BINDING */
#ifdef RT_USING_MEMTRACE
if (ptr == RT_NULL)
@@ -824,12 +905,27 @@ void *rt_malloc(rt_size_t size)
}
RTM_EXPORT(rt_malloc);
+/**
+ * @brief This function will release the previously allocated memory block by
+ * rt_malloc. The released memory block is taken back to system heap.
+ *
+ * @param rmem the address of memory which will be released.
+ */
void rt_free(void *rmem)
{
rt_memheap_free(rmem);
}
RTM_EXPORT(rt_free);
+/**
+ * @brief This function will change the size of previously allocated memory block.
+ *
+ * @param rmem is the pointer to memory allocated by rt_malloc.
+ *
+ * @param newsize is the required new size.
+ *
+ * @return the changed memory block address.
+ */
void *rt_realloc(void *rmem, rt_size_t newsize)
{
void *new_ptr;
@@ -890,6 +986,19 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
}
RTM_EXPORT(rt_realloc);
+/**
+ * @brief This function will contiguously allocate enough space for count objects
+ * that are size bytes of memory each and returns a pointer to the allocated
+ * memory.
+ *
+ * @note The allocated memory is filled with bytes of value zero.
+ *
+ * @param count is the number of objects to allocate.
+ *
+ * @param size is the size of one object to allocate.
+ *
+ * @return pointer to allocated memory pointer.
+ */
void *rt_calloc(rt_size_t count, rt_size_t size)
{
void *ptr;
@@ -920,6 +1029,16 @@ void *rt_calloc(rt_size_t count, rt_size_t size)
}
RTM_EXPORT(rt_calloc);
+/**
+* @brief This function will caculate the total memory, the used memory, and
+* the max used memory.
+*
+* @param total is a pointer to get the total size of the memory.
+*
+* @param used is a pointer to get the size of memory used.
+*
+* @param max_used is a pointer to get the maximum memory used.
+*/
void rt_memory_info(rt_uint32_t *total,
rt_uint32_t *used,
rt_uint32_t *max_used)
@@ -938,12 +1057,16 @@ void rt_memory_info(rt_uint32_t *total,
#ifdef RT_USING_MEMTRACE
+/**
+ * @brief This function will print the used memheap infomation.
+ *
+ * @param mh is a pointer of the memheap object.
+ */
void dump_used_memheap(struct rt_memheap *mh)
{
struct rt_memheap_item *header_ptr;
rt_uint32_t block_size;
-
rt_kprintf("\nmemory heap address:\n");
rt_kprintf("heap_ptr: 0x%08x\n", mh->start_addr);
rt_kprintf("free : 0x%08x\n", mh->available_size);
diff --git a/src/mempool.c b/src/mempool.c
index 5ac87d2bc8..09a4955eee 100644
--- a/src/mempool.c
+++ b/src/mempool.c
@@ -32,8 +32,8 @@ static void (*rt_mp_free_hook)(struct rt_mempool *mp, void *block);
/**@{*/
/**
- * This function will set a hook function, which will be invoked when a memory
- * block is allocated from memory pool.
+ * @brief This function will set a hook function, which will be invoked when a memory
+ * block is allocated from the memory pool.
*
* @param hook the hook function
*/
@@ -43,8 +43,8 @@ void rt_mp_alloc_sethook(void (*hook)(struct rt_mempool *mp, void *block))
}
/**
- * This function will set a hook function, which will be invoked when a memory
- * block is released to memory pool.
+ * @brief This function will set a hook function, which will be invoked when a memory
+ * block is released to the memory pool.
*
* @param hook the hook function
*/
@@ -63,14 +63,18 @@ void rt_mp_free_sethook(void (*hook)(struct rt_mempool *mp, void *block))
/**@{*/
/**
- * This function will initialize a memory pool object, normally which is used
- * for static object.
+ * @brief This function will initialize a memory pool object, normally which is used
+ * for static object.
*
- * @param mp the memory pool object
- * @param name the name of memory pool
- * @param start the star address of memory pool
- * @param size the total size of memory pool
- * @param block_size the size for each block
+ * @param mp is the memory pool object.
+ *
+ * @param name is the name of the memory pool.
+ *
+ * @param start is the start address of the memory pool.
+ *
+ * @param size is the total size of the memory pool.
+ *
+ * @param block_size is the size for each block..
*
* @return RT_EOK
*/
@@ -125,9 +129,9 @@ rt_err_t rt_mp_init(struct rt_mempool *mp,
RTM_EXPORT(rt_mp_init);
/**
- * This function will detach a memory pool from system object management.
+ * @brief This function will detach a memory pool from system object management.
*
- * @param mp the memory pool object
+ * @param mp is the memory pool object.
*
* @return RT_EOK
*/
@@ -172,12 +176,14 @@ RTM_EXPORT(rt_mp_detach);
#ifdef RT_USING_HEAP
/**
- * This function will create a mempool object and allocate the memory pool from
- * heap.
+ * @brief This function will create a mempool object and allocate the memory pool from
+ * heap.
*
- * @param name the name of memory pool
- * @param block_count the count of blocks in memory pool
- * @param block_size the size for each block
+ * @param name is the name of memory pool.
+ *
+ * @param block_count is the count of blocks in memory pool.
+ *
+ * @param block_size is the size for each block.
*
* @return the created mempool object
*/
@@ -241,9 +247,9 @@ rt_mp_t rt_mp_create(const char *name,
RTM_EXPORT(rt_mp_create);
/**
- * This function will delete a memory pool and release the object memory.
+ * @brief This function will delete a memory pool and release the object memory.
*
- * @param mp the memory pool object
+ * @param mp is the memory pool object.
*
* @return RT_EOK
*/
@@ -293,12 +299,14 @@ RTM_EXPORT(rt_mp_delete);
#endif /* RT_USING_HEAP */
/**
- * This function will allocate a block from memory pool
+ * @brief This function will allocate a block from memory pool.
+ *
+ * @param mp is the memory pool object.
*
- * @param mp the memory pool object
- * @param time the waiting time
+ * @param time is the maximum waiting time for allocating memory.
+ * - 0 for not waiting, allocating memory immediately.
*
- * @return the allocated memory block or RT_NULL on allocated failed
+ * @return the allocated memory block or RT_NULL on allocated failed.
*/
void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
{
@@ -392,9 +400,9 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
RTM_EXPORT(rt_mp_alloc);
/**
- * This function will release a memory block
+ * @brief This function will release a memory block.
*
- * @param block the address of memory block to be released
+ * @param block the address of memory block to be released.
*/
void rt_mp_free(void *block)
{
diff --git a/src/object.c b/src/object.c
index ff96037c52..66d5775bd7 100644
--- a/src/object.c
+++ b/src/object.c
@@ -23,7 +23,7 @@
#endif /* RT_USING_MODULE */
/*
- * define object_info for the number of rt_object_container items.
+ * define object_info for the number of _object_container items.
*/
enum rt_object_info_type
{
@@ -60,8 +60,9 @@ enum rt_object_info_type
};
#define _OBJ_CONTAINER_LIST_INIT(c) \
- {&(rt_object_container[c].object_list), &(rt_object_container[c].object_list)}
-static struct rt_object_information rt_object_container[RT_Object_Info_Unknown] =
+ {&(_object_container[c].object_list), &(_object_container[c].object_list)}
+
+static struct rt_object_information _object_container[RT_Object_Info_Unknown] =
{
/* initialize object container - thread */
{RT_Object_Class_Thread, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_Thread), sizeof(struct rt_thread)},
@@ -119,10 +120,10 @@ void (*rt_object_put_hook)(struct rt_object *object);
/**@{*/
/**
- * This function will set a hook function, which will be invoked when object
- * attaches to kernel object system.
+ * @brief This function will set a hook function, which will be invoked when object
+ * attaches to kernel object system.
*
- * @param hook the hook function
+ * @param hook is the hook function.
*/
void rt_object_attach_sethook(void (*hook)(struct rt_object *object))
{
@@ -130,10 +131,10 @@ void rt_object_attach_sethook(void (*hook)(struct rt_object *object))
}
/**
- * This function will set a hook function, which will be invoked when object
- * detaches from kernel object system.
+ * @brief This function will set a hook function, which will be invoked when object
+ * detaches from kernel object system.
*
- * @param hook the hook function
+ * @param hook is the hook function
*/
void rt_object_detach_sethook(void (*hook)(struct rt_object *object))
{
@@ -141,17 +142,17 @@ void rt_object_detach_sethook(void (*hook)(struct rt_object *object))
}
/**
- * This function will set a hook function, which will be invoked when object
- * is taken from kernel object system.
+ * @brief This function will set a hook function, which will be invoked when object
+ * is taken from kernel object system.
*
- * The object is taken means:
- * semaphore - semaphore is taken by thread
- * mutex - mutex is taken by thread
- * event - event is received by thread
- * mailbox - mail is received by thread
- * message queue - message is received by thread
+ * The object is taken means:
+ * semaphore - semaphore is taken by thread
+ * mutex - mutex is taken by thread
+ * event - event is received by thread
+ * mailbox - mail is received by thread
+ * message queue - message is received by thread
*
- * @param hook the hook function
+ * @param hook is the hook function.
*/
void rt_object_trytake_sethook(void (*hook)(struct rt_object *object))
{
@@ -159,18 +160,18 @@ void rt_object_trytake_sethook(void (*hook)(struct rt_object *object))
}
/**
- * This function will set a hook function, which will be invoked when object
- * have been taken from kernel object system.
+ * @brief This function will set a hook function, which will be invoked when object
+ * have been taken from kernel object system.
*
- * The object have been taken means:
- * semaphore - semaphore have been taken by thread
- * mutex - mutex have been taken by thread
- * event - event have been received by thread
- * mailbox - mail have been received by thread
- * message queue - message have been received by thread
- * timer - timer is started
+ * The object have been taken means:
+ * semaphore - semaphore have been taken by thread
+ * mutex - mutex have been taken by thread
+ * event - event have been received by thread
+ * mailbox - mail have been received by thread
+ * message queue - message have been received by thread
+ * timer - timer is started
*
- * @param hook the hook function
+ * @param hook the hook function.
*/
void rt_object_take_sethook(void (*hook)(struct rt_object *object))
{
@@ -178,10 +179,10 @@ void rt_object_take_sethook(void (*hook)(struct rt_object *object))
}
/**
- * This function will set a hook function, which will be invoked when object
- * is put to kernel object system.
+ * @brief This function will set a hook function, which will be invoked when object
+ * is put to kernel object system.
*
- * @param hook the hook function
+ * @param hook is the hook function
*/
void rt_object_put_sethook(void (*hook)(struct rt_object *object))
{
@@ -198,9 +199,9 @@ void rt_object_put_sethook(void (*hook)(struct rt_object *object))
/**@{*/
/**
- * This function will return the specified type of object information.
+ * @brief This function will return the specified type of object information.
*
- * @param type the type of object, which can be
+ * @param type is the type of object, which can be
* RT_Object_Class_Thread/Semaphore/Mutex... etc
*
* @return the object type information or RT_NULL
@@ -211,17 +212,18 @@ rt_object_get_information(enum rt_object_class_type type)
int index;
for (index = 0; index < RT_Object_Info_Unknown; index ++)
- if (rt_object_container[index].type == type) return &rt_object_container[index];
+ if (_object_container[index].type == type) return &_object_container[index];
return RT_NULL;
}
RTM_EXPORT(rt_object_get_information);
/**
- * This function will return the length of object list in object container.
+ * @brief This function will return the length of object list in object container.
*
- * @param type the type of object, which can be
+ * @param type is the type of object, which can be
* RT_Object_Class_Thread/Semaphore/Mutex... etc
+ *
* @return the length of object list
*/
int rt_object_get_length(enum rt_object_class_type type)
@@ -247,15 +249,17 @@ int rt_object_get_length(enum rt_object_class_type type)
RTM_EXPORT(rt_object_get_length);
/**
- * This function will copy the object pointer of the specified type,
- * with the maximum size specified by maxlen.
+ * @brief This function will copy the object pointer of the specified type,
+ * with the maximum size specified by maxlen.
*
- * @param type the type of object, which can be
+ * @param type is the type of object, which can be
* RT_Object_Class_Thread/Semaphore/Mutex... etc
- * @param pointers the pointers will be saved to
- * @param maxlen the maximum number of pointers can be saved
*
- * @return the copied number of object pointers
+ * @param pointers is the pointer will be saved to.
+ *
+ * @param maxlen is the maximum number of pointers can be saved.
+ *
+ * @return the copied number of object pointers.
*/
int rt_object_get_pointers(enum rt_object_class_type type, rt_object_t *pointers, int maxlen)
{
@@ -289,12 +293,14 @@ int rt_object_get_pointers(enum rt_object_class_type type, rt_object_t *pointers
RTM_EXPORT(rt_object_get_pointers);
/**
- * This function will initialize an object and add it to object system
- * management.
+ * @brief This function will initialize an object and add it to object system
+ * management.
+ *
+ * @param object is the specified object to be initialized.
*
- * @param object the specified object to be initialized.
- * @param type the object type.
- * @param name the object name. In system, the object's name must be unique.
+ * @param type is the object type.
+ *
+ * @param name is the object name. In system, the object's name must be unique.
*/
void rt_object_init(struct rt_object *object,
enum rt_object_class_type type,
@@ -360,8 +366,8 @@ void rt_object_init(struct rt_object *object,
}
/**
- * This function will detach a static object from object system,
- * and the memory of static object is not freed.
+ * @brief This function will detach a static object from object system,
+ * and the memory of static object is not freed.
*
* @param object the specified object to be detached.
*/
@@ -389,10 +395,11 @@ void rt_object_detach(rt_object_t object)
#ifdef RT_USING_HEAP
/**
- * This function will allocate an object from object system
+ * @brief This function will allocate an object from object system.
+ *
+ * @param type is the type of object.
*
- * @param type the type of object
- * @param name the object name. In system, the object's name must be unique.
+ * @param name is the object name. In system, the object's name must be unique.
*
* @return object
*/
@@ -458,9 +465,9 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name)
}
/**
- * This function will delete an object and release object memory.
+ * @brief This function will delete an object and release object memory.
*
- * @param object the specified object to be deleted.
+ * @param object is the specified object to be deleted.
*/
void rt_object_delete(rt_object_t object)
{
@@ -490,11 +497,12 @@ void rt_object_delete(rt_object_t object)
#endif /* RT_USING_HEAP */
/**
- * This function will judge the object is system object or not.
- * Normally, the system object is a static object and the type
- * of object set to RT_Object_Class_Static.
+ * @brief This function will judge the object is system object or not.
*
- * @param object the specified object to be judged.
+ * @note Normally, the system object is a static object and the type
+ * of object set to RT_Object_Class_Static.
+ *
+ * @param object is the specified object to be judged.
*
* @return RT_TRUE if a system object, RT_FALSE for others.
*/
@@ -510,10 +518,10 @@ rt_bool_t rt_object_is_systemobject(rt_object_t object)
}
/**
- * This function will return the type of object without
- * RT_Object_Class_Static flag.
+ * @brief This function will return the type of object without
+ * RT_Object_Class_Static flag.
*
- * @param object the specified object to be get type.
+ * @param object is the specified object to be get type.
*
* @return the type of object.
*/
@@ -526,11 +534,12 @@ rt_uint8_t rt_object_get_type(rt_object_t object)
}
/**
- * This function will find specified name object from object
- * container.
+ * @brief This function will find specified name object from object
+ * container.
+ *
+ * @param name is the specified name of object.
*
- * @param name the specified name of object.
- * @param type the type of object
+ * @param type is the type of object
*
* @return the found object or RT_NULL if there is no this object
* in object container.
diff --git a/src/scheduler.c b/src/scheduler.c
index 353fdad5cb..6ef02f3d3c 100644
--- a/src/scheduler.c
+++ b/src/scheduler.c
@@ -23,7 +23,7 @@
* 2013-12-21 Grissiom add rt_critical_level
* 2018-11-22 Jesven remove the current task from ready queue
* add per cpu ready queue
- * add _get_highest_priority_thread to find highest priority task
+ * add _scheduler_get_highest_priority_thread to find highest priority task
* rt_schedule_insert_thread won't insert current task to ready queue
* in smp version, rt_hw_context_switch_interrupt maybe switch to
* new task directly
@@ -58,19 +58,23 @@ static void (*rt_scheduler_switch_hook)(struct rt_thread *tid);
/**@{*/
/**
- * This function will set a hook function, which will be invoked when thread
- * switch happens.
+ * @brief This function will set a hook function, which will be invoked when thread
+ * switch happens.
*
- * @param hook the hook function
+ * @param hook is the hook function.
*/
-void
-rt_scheduler_sethook(void (*hook)(struct rt_thread *from, struct rt_thread *to))
+void rt_scheduler_sethook(void (*hook)(struct rt_thread *from, struct rt_thread *to))
{
rt_scheduler_hook = hook;
}
-void
-rt_scheduler_switch_sethook(void (*hook)(struct rt_thread *tid))
+/**
+ * @brief This function will set a hook function, which will be invoked when context
+ * switch happens.
+ *
+ * @param hook is the hook function.
+ */
+void rt_scheduler_switch_sethook(void (*hook)(struct rt_thread *tid))
{
rt_scheduler_switch_hook = hook;
}
@@ -119,7 +123,7 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread)
* get the highest priority thread in ready queue
*/
#ifdef RT_USING_SMP
-static struct rt_thread* _get_highest_priority_thread(rt_ubase_t *highest_prio)
+static struct rt_thread* _scheduler_get_highest_priority_thread(rt_ubase_t *highest_prio)
{
register struct rt_thread *highest_priority_thread;
register rt_ubase_t highest_ready_priority, local_highest_ready_priority;
@@ -155,7 +159,7 @@ static struct rt_thread* _get_highest_priority_thread(rt_ubase_t *highest_prio)
return highest_priority_thread;
}
#else
-static struct rt_thread* _get_highest_priority_thread(rt_ubase_t *highest_prio)
+static struct rt_thread* _scheduler_get_highest_priority_thread(rt_ubase_t *highest_prio)
{
register struct rt_thread *highest_priority_thread;
register rt_ubase_t highest_ready_priority;
@@ -181,8 +185,7 @@ static struct rt_thread* _get_highest_priority_thread(rt_ubase_t *highest_prio)
#endif /* RT_USING_SMP */
/**
- * @ingroup SystemInit
- * This function will initialize the system scheduler
+ * @brief This function will initialize the system scheduler.
*/
void rt_system_scheduler_init(void)
{
@@ -232,16 +235,15 @@ void rt_system_scheduler_init(void)
}
/**
- * @ingroup SystemInit
- * This function will startup scheduler. It will select one thread
- * with the highest priority level, then switch to it.
+ * @brief This function will startup the scheduler. It will select one thread
+ * with the highest priority level, then switch to it.
*/
void rt_system_scheduler_start(void)
{
register struct rt_thread *to_thread;
rt_ubase_t highest_ready_priority;
- to_thread = _get_highest_priority_thread(&highest_ready_priority);
+ to_thread = _scheduler_get_highest_priority_thread(&highest_ready_priority);
#ifdef RT_USING_SMP
to_thread->oncpu = rt_hw_cpu_id();
@@ -271,12 +273,13 @@ void rt_system_scheduler_start(void)
#ifdef RT_USING_SMP
/**
- * This function will handle IPI interrupt and do a scheduling in system;
+ * @brief This function will handle IPI interrupt and do a scheduling in system.
*
- * @param vector, the number of IPI interrupt for system scheduling
- * @param param, use RT_NULL
+ * @param vector is the number of IPI interrupt for system scheduling.
*
- * NOTE: this function should be invoke or register as ISR in BSP.
+ * @param param is not used, and can be set to RT_NULL.
+ *
+ * @note this function should be invoke or register as ISR in BSP.
*/
void rt_scheduler_ipi_handler(int vector, void *param)
{
@@ -284,9 +287,9 @@ void rt_scheduler_ipi_handler(int vector, void *param)
}
/**
- * This function will perform one scheduling. It will select one thread
- * with the highest priority level in global ready queue or local ready queue,
- * then switch to it.
+ * @brief This function will perform one scheduling. It will select one thread
+ * with the highest priority level in global ready queue or local ready queue,
+ * then switch to it.
*/
void rt_schedule(void)
{
@@ -329,7 +332,7 @@ void rt_schedule(void)
if (rt_thread_ready_priority_group != 0 || pcpu->priority_group != 0)
{
- to_thread = _get_highest_priority_thread(&highest_ready_priority);
+ to_thread = _scheduler_get_highest_priority_thread(&highest_ready_priority);
current_thread->oncpu = RT_CPU_DETACHED;
if ((current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING)
{
@@ -407,8 +410,8 @@ __exit:
}
#else
/**
- * This function will perform one schedule. It will select one thread
- * with the highest priority level, and switch to it immediately.
+ * @brief This function will perform scheduling once. It will select one thread
+ * with the highest priority, and switch to it immediately.
*/
void rt_schedule(void)
{
@@ -429,7 +432,7 @@ void rt_schedule(void)
/* need_insert_from_thread: need to insert from_thread to ready queue */
int need_insert_from_thread = 0;
- to_thread = _get_highest_priority_thread(&highest_ready_priority);
+ to_thread = _scheduler_get_highest_priority_thread(&highest_ready_priority);
if ((rt_current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING)
{
@@ -536,9 +539,9 @@ __exit:
#endif /* RT_USING_SMP */
/**
- * This function checks if a scheduling is needed after IRQ context. If yes,
- * it will select one thread with the highest priority level, and then switch
- * to it.
+ * @brief This function checks whether a scheduling is needed after an IRQ context switching. If yes,
+ * it will select one thread with the highest priority level, and then switch
+ * to it.
*/
#ifdef RT_USING_SMP
void rt_scheduler_do_irq_switch(void *context)
@@ -582,7 +585,7 @@ void rt_scheduler_do_irq_switch(void *context)
if (rt_thread_ready_priority_group != 0 || pcpu->priority_group != 0)
{
- to_thread = _get_highest_priority_thread(&highest_ready_priority);
+ to_thread = _scheduler_get_highest_priority_thread(&highest_ready_priority);
current_thread->oncpu = RT_CPU_DETACHED;
if ((current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING)
{
@@ -631,12 +634,13 @@ void rt_scheduler_do_irq_switch(void *context)
}
#endif /* RT_USING_SMP */
-/*
- * This function will insert a thread to system ready queue. The state of
- * thread will be set as READY and remove from suspend queue.
+/**
+ * @brief This function will insert a thread to the system ready queue. The state of
+ * thread will be set as READY and the thread will be removed from suspend queue.
+ *
+ * @param thread is the thread to be inserted.
*
- * @param thread the thread to be inserted
- * @note Please do not invoke this function in user application.
+ * @note Please do not invoke this function in user application.
*/
#ifdef RT_USING_SMP
void rt_schedule_insert_thread(struct rt_thread *thread)
@@ -741,12 +745,12 @@ __exit:
}
#endif /* RT_USING_SMP */
-/*
- * This function will remove a thread from system ready queue.
+/**
+ * @brief This function will remove a thread from system ready queue.
*
- * @param thread the thread to be removed
+ * @param thread is the thread to be removed.
*
- * @note Please do not invoke this function in user application.
+ * @note Please do not invoke this function in user application.
*/
#ifdef RT_USING_SMP
void rt_schedule_remove_thread(struct rt_thread *thread)
@@ -835,7 +839,7 @@ void rt_schedule_remove_thread(struct rt_thread *thread)
#endif /* RT_USING_SMP */
/**
- * This function will lock the thread scheduler.
+ * @brief This function will lock the thread scheduler.
*/
#ifdef RT_USING_SMP
void rt_enter_critical(void)
@@ -897,7 +901,7 @@ void rt_enter_critical(void)
RTM_EXPORT(rt_enter_critical);
/**
- * This function will unlock the thread scheduler.
+ * @brief This function will unlock the thread scheduler.
*/
#ifdef RT_USING_SMP
void rt_exit_critical(void)
@@ -971,7 +975,7 @@ void rt_exit_critical(void)
RTM_EXPORT(rt_exit_critical);
/**
- * Get the scheduler lock level
+ * @brief Get the scheduler lock level.
*
* @return the level of the scheduler lock. 0 means unlocked.
*/
diff --git a/src/signal.c b/src/signal.c
index bb7706d9ef..14201ee948 100644
--- a/src/signal.c
+++ b/src/signal.c
@@ -35,7 +35,7 @@ struct siginfo_node
struct rt_slist_node list;
};
-static struct rt_mempool *_rt_siginfo_pool;
+static struct rt_mempool *_siginfo_pool;
static void _signal_deliver(rt_thread_t tid);
void rt_thread_handle_sig(rt_bool_t clean_state);
@@ -206,6 +206,22 @@ void *rt_signal_check(void* context)
}
#endif /* RT_USING_SMP */
+/**
+ * @brief This function will install a processing function to a specific
+ * signal and return the old processing function of this signal.
+ *
+ * @note This function needs to be used in conjunction with the
+ * rt_signal_unmask() function to make the signal effective.
+ *
+ * @see rt_signal_unmask()
+ *
+ * @param signo is a specific signal value (range: 0 ~ RT_SIG_MAX).
+ *
+ * @param handler is sets the processing of signal value.
+ *
+ * @return Return the old processing function of this signal. ONLY When the
+ * return value is SIG_ERR, the operation is failed.
+ */
rt_sighandler_t rt_signal_install(int signo, rt_sighandler_t handler)
{
rt_base_t level;
@@ -233,6 +249,17 @@ rt_sighandler_t rt_signal_install(int signo, rt_sighandler_t handler)
return old;
}
+/**
+ * @brief This function will block the specified signal.
+ *
+ * @note This function will block the specified signal, even if the
+ * rt_thread_kill() function is called to send this signal to
+ * the current thread, it will no longer take effect.
+ *
+ * @see rt_thread_kill()
+ *
+ * @param signo is a specific signal value (range: 0 ~ RT_SIG_MAX).
+ */
void rt_signal_mask(int signo)
{
rt_base_t level;
@@ -245,6 +272,17 @@ void rt_signal_mask(int signo)
rt_hw_interrupt_enable(level);
}
+/**
+ * @brief This function will unblock the specified signal.
+ *
+ * @note This function will unblock the specified signal. After calling
+ * the rt_thread_kill() function to send this signal to the current
+ * thread, it will take effect.
+ *
+ * @see rt_thread_kill()
+ *
+ * @param signo is a specific signal value (range: 0 ~ RT_SIG_MAX).
+ */
void rt_signal_unmask(int signo)
{
rt_base_t level;
@@ -266,6 +304,20 @@ void rt_signal_unmask(int signo)
}
}
+/**
+ * @brief This function will wait for the arrival of the set signal. If it does not wait for this signal, the thread will be
+ * suspended until it waits for this signal or the waiting time exceeds the specified timeout: timeout.
+ *
+ * @param set is the set of signal values to be waited for. Use the function
+ * sigaddset() to add the signal.
+ *
+ * @param si is a pointer to the received signal info. If you don't care about this value, you can use RT_NULL to set.
+ *
+ * @param timeout is a timeout period (unit: an OS tick).
+ *
+ * @return Return the operation status. When the return value is RT_EOK, the operation is successful.
+ * If the return value is any other values, it means that the signal wait failed.
+ */
int rt_signal_wait(const rt_sigset_t *set, rt_siginfo_t *si, rt_int32_t timeout)
{
int ret = RT_EOK;
@@ -497,6 +549,16 @@ void rt_thread_free_sig(rt_thread_t tid)
}
}
+/**
+ * @brief This function can be used to send any signal to any thread.
+ *
+ * @param tid is a pointer to the thread that receives the signal.
+ *
+ * @param sig is a specific signal value (range: 0 ~ RT_SIG_MAX).
+ *
+ * @return Return the operation status. When the return value is RT_EOK, the operation is successful.
+ * If the return value is any other values, it means that the signal send failed.
+ */
int rt_thread_kill(rt_thread_t tid, int sig)
{
siginfo_t si;
@@ -538,7 +600,7 @@ int rt_thread_kill(rt_thread_t tid, int sig)
}
rt_hw_interrupt_enable(level);
- si_node = (struct siginfo_node *) rt_mp_alloc(_rt_siginfo_pool, 0);
+ si_node = (struct siginfo_node *) rt_mp_alloc(_siginfo_pool, 0);
if (si_node)
{
rt_slist_init(&(si_node->list));
@@ -576,8 +638,8 @@ int rt_thread_kill(rt_thread_t tid, int sig)
int rt_system_signal_init(void)
{
- _rt_siginfo_pool = rt_mp_create("signal", RT_SIG_INFO_MAX, sizeof(struct siginfo_node));
- if (_rt_siginfo_pool == RT_NULL)
+ _siginfo_pool = rt_mp_create("signal", RT_SIG_INFO_MAX, sizeof(struct siginfo_node));
+ if (_siginfo_pool == RT_NULL)
{
LOG_E("create memory pool for signal info failed.");
RT_ASSERT(0);
diff --git a/src/slab.c b/src/slab.c
index ad1dc71811..8e0ce7bc83 100644
--- a/src/slab.c
+++ b/src/slab.c
@@ -74,10 +74,10 @@ static void (*rt_free_hook)(void *ptr);
/**@{*/
/**
- * This function will set a hook function, which will be invoked when a memory
- * block is allocated from heap memory.
+ * @brief This function will set a hook function, which will be invoked when a memory
+ * block is allocated from heap memory.
*
- * @param hook the hook function
+ * @param hook the hook function.
*/
void rt_malloc_sethook(void (*hook)(void *ptr, rt_size_t size))
{
@@ -86,8 +86,8 @@ void rt_malloc_sethook(void (*hook)(void *ptr, rt_size_t size))
RTM_EXPORT(rt_malloc_sethook);
/**
- * This function will set a hook function, which will be invoked when a memory
- * block is released to heap memory.
+ * @brief This function will set a hook function, which will be invoked when a memory
+ * block is released to heap memory.
*
* @param hook the hook function
*/
@@ -233,6 +233,11 @@ struct rt_page_head
static struct rt_page_head *rt_page_list;
static struct rt_semaphore heap_sem;
+/**
+ * @brief Alloc memory size by page.
+ *
+ * @param npages the number of pages.
+ */
void *rt_page_alloc(rt_size_t npages)
{
struct rt_page_head *b, *n;
@@ -269,6 +274,13 @@ void *rt_page_alloc(rt_size_t npages)
return b;
}
+/**
+ * @brief Free memory by page.
+ *
+ * @param addr is the head address of first page.
+ *
+ * @param npages is the number of pages.
+ */
void rt_page_free(void *addr, rt_size_t npages)
{
struct rt_page_head *b, *n;
@@ -334,12 +346,11 @@ static void rt_page_init(void *addr, rt_size_t npages)
}
/**
- * @ingroup SystemInit
+ * @brief This function will init system heap.
*
- * This function will init system heap
+ * @param begin_addr the beginning address of system page.
*
- * @param begin_addr the beginning address of system page
- * @param end_addr the end address of system page
+ * @param end_addr the end address of system page.
*/
void rt_system_heap_init(void *begin_addr, void *end_addr)
{
@@ -465,15 +476,15 @@ rt_inline int zoneindex(rt_size_t *bytes)
/**@{*/
/**
- * This function will allocate a block from system heap memory.
- * - If the nbytes is less than zero,
- * or
- * - If there is no nbytes sized memory valid in system,
- * the RT_NULL is returned.
+ * @brief This function will allocate a block from system heap memory.
+ *
+ * @note the RT_NULL is returned if
+ * - the nbytes is less than zero.
+ * - there is no nbytes sized memory valid in system.
*
- * @param size the size of memory to be allocated
+ * @param size is the size of memory to be allocated.
*
- * @return the allocated memory
+ * @return the allocated memory.
*/
void *rt_malloc(rt_size_t size)
{
@@ -668,12 +679,13 @@ __exit:
RTM_EXPORT(rt_malloc);
/**
- * This function will change the size of previously allocated memory block.
+ * @brief This function will change the size of previously allocated memory block.
+ *
+ * @param ptr is the previously allocated memory block.
*
- * @param ptr the previously allocated memory block
- * @param size the new size of memory block
+ * @param size is the new size of memory block.
*
- * @return the allocated memory
+ * @return the allocated memory.
*/
void *rt_realloc(void *ptr, rt_size_t size)
{
@@ -736,16 +748,17 @@ void *rt_realloc(void *ptr, rt_size_t size)
RTM_EXPORT(rt_realloc);
/**
- * This function will contiguously allocate enough space for count objects
- * that are size bytes of memory each and returns a pointer to the allocated
- * memory.
+ * @brief This function will contiguously allocate enough space for count objects
+ * that are size bytes of memory each and returns a pointer to the allocated
+ * memory.
*
- * The allocated memory is filled with bytes of value zero.
+ * @note The allocated memory is filled with bytes of value zero.
*
- * @param count number of objects to allocate
- * @param size size of the objects to allocate
+ * @param count is the number of objects to allocate.
*
- * @return pointer to allocated memory / NULL pointer if there is an error
+ * @param size is the size of the objects to allocate.
+ *
+ * @return pointer to allocated memory / NULL pointer if there is an error.
*/
void *rt_calloc(rt_size_t count, rt_size_t size)
{
@@ -763,10 +776,11 @@ void *rt_calloc(rt_size_t count, rt_size_t size)
RTM_EXPORT(rt_calloc);
/**
- * This function will release the previous allocated memory block by rt_malloc.
- * The released memory block is taken back to system heap.
+ * @brief This function will release the previous allocated memory block by rt_malloc.
+ *
+ * @note The released memory block is taken back to system heap.
*
- * @param ptr the address of memory which will be released
+ * @param ptr is the address of memory which will be released
*/
void rt_free(void *ptr)
{
@@ -905,6 +919,16 @@ void rt_free(void *ptr)
RTM_EXPORT(rt_free);
#ifdef RT_MEM_STATS
+/**
+* @brief This function will caculate the total memory, the used memory, and
+* the max used memory.
+*
+* @param total is a pointer to get the total size of the memory.
+*
+* @param used is a pointer to get the size of memory used.
+*
+* @param max_used is a pointer to get the maximum memory used.
+*/
void rt_memory_info(rt_uint32_t *total,
rt_uint32_t *used,
rt_uint32_t *max_used)
diff --git a/src/thread.c b/src/thread.c
index 60e6ab91d1..ab5264053e 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -38,12 +38,11 @@ static void (*rt_thread_resume_hook) (rt_thread_t thread);
static void (*rt_thread_inited_hook) (rt_thread_t thread);
/**
- * @ingroup Hook
- * This function sets a hook function when the system suspend a thread.
+ * @brief This function sets a hook function when the system suspend a thread.
*
- * @param hook the specified hook function
+ * @note The hook function must be simple and never be blocked or suspend.
*
- * @note the hook function must be simple and never be blocked or suspend.
+ * @param hook is the specified hook function.
*/
void rt_thread_suspend_sethook(void (*hook)(rt_thread_t thread))
{
@@ -51,12 +50,11 @@ void rt_thread_suspend_sethook(void (*hook)(rt_thread_t thread))
}
/**
- * @ingroup Hook
- * This function sets a hook function when the system resume a thread.
+ * @brief This function sets a hook function when the system resume a thread.
*
- * @param hook the specified hook function
+ * @note The hook function must be simple and never be blocked or suspend.
*
- * @note the hook function must be simple and never be blocked or suspend.
+ * @param hook is the specified hook function.
*/
void rt_thread_resume_sethook(void (*hook)(rt_thread_t thread))
{
@@ -64,10 +62,9 @@ void rt_thread_resume_sethook(void (*hook)(rt_thread_t thread))
}
/**
- * @ingroup Hook
- * This function sets a hook function when a thread is initialized.
+ * @brief This function sets a hook function when a thread is initialized.
*
- * @param hook the specified hook function
+ * @param hook is the specified hook function.
*/
void rt_thread_inited_sethook(void (*hook)(rt_thread_t thread))
{
@@ -76,8 +73,7 @@ void rt_thread_inited_sethook(void (*hook)(rt_thread_t thread))
#endif /* RT_USING_HOOK */
-/* must be invoke witch rt_hw_interrupt_disable */
-static void _rt_thread_cleanup_execute(rt_thread_t thread)
+static void _thread_cleanup_execute(rt_thread_t thread)
{
register rt_base_t level;
#ifdef RT_USING_MODULE
@@ -101,7 +97,7 @@ static void _rt_thread_cleanup_execute(rt_thread_t thread)
rt_hw_interrupt_enable(level);
}
-static void _rt_thread_exit(void)
+static void _thread_exit(void)
{
struct rt_thread *thread;
register rt_base_t level;
@@ -112,7 +108,7 @@ static void _rt_thread_exit(void)
/* disable interrupt */
level = rt_hw_interrupt_disable();
- _rt_thread_cleanup_execute(thread);
+ _thread_cleanup_execute(thread);
/* remove from schedule */
rt_schedule_remove_thread(thread);
@@ -139,14 +135,14 @@ static void _rt_thread_exit(void)
rt_hw_interrupt_enable(level);
}
-static rt_err_t _rt_thread_init(struct rt_thread *thread,
- const char *name,
- void (*entry)(void *parameter),
- void *parameter,
- void *stack_start,
- rt_uint32_t stack_size,
- rt_uint8_t priority,
- rt_uint32_t tick)
+static rt_err_t _thread_init(struct rt_thread *thread,
+ const char *name,
+ void (*entry)(void *parameter),
+ void *parameter,
+ void *stack_start,
+ rt_uint32_t stack_size,
+ rt_uint8_t priority,
+ rt_uint32_t tick)
{
/* init thread list */
rt_list_init(&(thread->tlist));
@@ -163,11 +159,11 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
#ifdef ARCH_CPU_STACK_GROWS_UPWARD
thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter,
(void *)((char *)thread->stack_addr),
- (void *)_rt_thread_exit);
+ (void *)_thread_exit);
#else
thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter,
(rt_uint8_t *)((char *)thread->stack_addr + thread->stack_size - sizeof(rt_ubase_t)),
- (void *)_rt_thread_exit);
+ (void *)_thread_exit);
#endif /* ARCH_CPU_STACK_GROWS_UPWARD */
/* priority init */
@@ -244,19 +240,27 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
/**@{*/
/**
- * This function will initialize a thread, normally it's used to initialize a
- * static thread object.
+ * @brief This function will initialize a thread. It's used to initialize a
+ * static thread object.
+ *
+ * @param thread is the static thread object.
+ *
+ * @param name is the name of thread, which shall be unique.
+ *
+ * @param entry is the entry function of thread.
+ *
+ * @param parameter is the parameter of thread enter function.
+ *
+ * @param stack_start is the start address of thread stack.
*
- * @param thread the static thread object
- * @param name the name of thread, which shall be unique
- * @param entry the entry function of thread
- * @param parameter the parameter of thread enter function
- * @param stack_start the start address of thread stack
- * @param stack_size the size of thread stack
- * @param priority the priority of thread
- * @param tick the time slice if there are same priority thread
+ * @param stack_size is the size of thread stack.
*
- * @return the operation status, RT_EOK on OK, -RT_ERROR on error
+ * @param priority is the priority of thread.
+ *
+ * @param tick is the time slice if there are same priority thread.
+ *
+ * @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
+ * If the return value is any other values, it means this operation failed.
*/
rt_err_t rt_thread_init(struct rt_thread *thread,
const char *name,
@@ -274,21 +278,21 @@ rt_err_t rt_thread_init(struct rt_thread *thread,
/* initialize thread object */
rt_object_init((rt_object_t)thread, RT_Object_Class_Thread, name);
- return _rt_thread_init(thread,
- name,
- entry,
- parameter,
- stack_start,
- stack_size,
- priority,
- tick);
+ return _thread_init(thread,
+ name,
+ entry,
+ parameter,
+ stack_start,
+ stack_size,
+ priority,
+ tick);
}
RTM_EXPORT(rt_thread_init);
/**
- * This function will return self thread object
+ * @brief This function will return self thread object.
*
- * @return the self thread object
+ * @return The self thread object.
*/
rt_thread_t rt_thread_self(void)
{
@@ -309,11 +313,12 @@ rt_thread_t rt_thread_self(void)
RTM_EXPORT(rt_thread_self);
/**
- * This function will start a thread and put it to system ready queue
+ * @brief This function will start a thread and put it to system ready queue.
*
- * @param thread the thread to be started
+ * @param thread is the thread to be started.
*
- * @return the operation status, RT_EOK on OK, -RT_ERROR on error
+ * @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
+ * If the return value is any other values, it means this operation failed.
*/
rt_err_t rt_thread_startup(rt_thread_t thread)
{
@@ -351,12 +356,13 @@ rt_err_t rt_thread_startup(rt_thread_t thread)
RTM_EXPORT(rt_thread_startup);
/**
- * This function will detach a thread. The thread object will be removed from
- * thread queue and detached/deleted from system object management.
+ * @brief This function will detach a thread. The thread object will be removed from
+ * thread queue and detached/deleted from the system object management.
*
- * @param thread the thread to be deleted
+ * @param thread is the thread to be deleted.
*
- * @return the operation status, RT_EOK on OK, -RT_ERROR on error
+ * @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
+ * If the return value is any other values, it means this operation failed.
*/
rt_err_t rt_thread_detach(rt_thread_t thread)
{
@@ -376,7 +382,7 @@ rt_err_t rt_thread_detach(rt_thread_t thread)
rt_schedule_remove_thread(thread);
}
- _rt_thread_cleanup_execute(thread);
+ _thread_cleanup_execute(thread);
/* release thread timer */
rt_timer_detach(&(thread->thread_timer));
@@ -404,17 +410,23 @@ RTM_EXPORT(rt_thread_detach);
#ifdef RT_USING_HEAP
/**
- * This function will create a thread object and allocate thread object memory
- * and stack.
+ * @brief This function will create a thread object and allocate thread object memory.
+ * and stack.
+ *
+ * @param name is the name of thread, which shall be unique.
+ *
+ * @param entry is the entry function of thread.
+ *
+ * @param parameter is the parameter of thread enter function.
*
- * @param name the name of thread, which shall be unique
- * @param entry the entry function of thread
- * @param parameter the parameter of thread enter function
- * @param stack_size the size of thread stack
- * @param priority the priority of thread
- * @param tick the time slice if there are same priority thread
+ * @param stack_size is the size of thread stack.
*
- * @return the created thread object
+ * @param priority is the priority of thread.
+ *
+ * @param tick is the time slice if there are same priority thread.
+ *
+ * @return If the return value is a rt_thread structure pointer, the function is successfully executed.
+ * If the return value is RT_NULL, it means this operation failed.
*/
rt_thread_t rt_thread_create(const char *name,
void (*entry)(void *parameter),
@@ -440,7 +452,7 @@ rt_thread_t rt_thread_create(const char *name,
return RT_NULL;
}
- _rt_thread_init(thread,
+ _thread_init(thread,
name,
entry,
parameter,
@@ -454,12 +466,13 @@ rt_thread_t rt_thread_create(const char *name,
RTM_EXPORT(rt_thread_create);
/**
- * This function will delete a thread. The thread object will be removed from
- * thread queue and deleted from system object management in the idle thread.
+ * @brief This function will delete a thread. The thread object will be removed from
+ * thread queue and deleted from system object management in the idle thread.
*
- * @param thread the thread to be deleted
+ * @param thread is the thread to be deleted.
*
- * @return the operation status, RT_EOK on OK, -RT_ERROR on error
+ * @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
+ * If the return value is any other values, it means this operation failed.
*/
rt_err_t rt_thread_delete(rt_thread_t thread)
{
@@ -479,7 +492,7 @@ rt_err_t rt_thread_delete(rt_thread_t thread)
rt_schedule_remove_thread(thread);
}
- _rt_thread_cleanup_execute(thread);
+ _thread_cleanup_execute(thread);
/* release thread timer */
rt_timer_detach(&(thread->thread_timer));
@@ -502,11 +515,12 @@ RTM_EXPORT(rt_thread_delete);
#endif /* RT_USING_HEAP */
/**
- * This function will let current thread yield processor, and scheduler will
- * choose a highest thread to run. After yield processor, the current thread
- * is still in READY state.
+ * @brief This function will let current thread yield processor, and scheduler will
+ * choose the highest thread to run. After yield processor, the current thread
+ * is still in READY state.
*
- * @return RT_EOK
+ * @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
+ * If the return value is any other values, it means this operation failed.
*/
rt_err_t rt_thread_yield(void)
{
@@ -525,11 +539,13 @@ rt_err_t rt_thread_yield(void)
RTM_EXPORT(rt_thread_yield);
/**
- * This function will let current thread sleep for some ticks.
+ * @brief This function will let current thread sleep for some ticks. Change current thread state to suspend,
+ * when the thread timer reaches the tick value, scheduler will awaken this thread.
*
- * @param tick the sleep ticks
+ * @param tick is the sleep ticks.
*
- * @return RT_EOK
+ * @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
+ * If the return value is any other values, it means this operation failed.
*/
rt_err_t rt_thread_sleep(rt_tick_t tick)
{
@@ -564,11 +580,12 @@ rt_err_t rt_thread_sleep(rt_tick_t tick)
}
/**
- * This function will let current thread delay for some ticks.
+ * @brief This function will let current thread delay for some ticks.
*
- * @param tick the delay ticks
+ * @param tick is the delay ticks.
*
- * @return RT_EOK
+ * @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
+ * If the return value is any other values, it means this operation failed.
*/
rt_err_t rt_thread_delay(rt_tick_t tick)
{
@@ -577,12 +594,14 @@ rt_err_t rt_thread_delay(rt_tick_t tick)
RTM_EXPORT(rt_thread_delay);
/**
- * This function will let current thread delay until (*tick + inc_tick).
+ * @brief This function will let current thread delay until (*tick + inc_tick).
+ *
+ * @param tick is the tick of last wakeup.
*
- * @param tick the tick of last wakeup.
- * @param inc_tick the increment tick
+ * @param inc_tick is the increment tick.
*
- * @return RT_EOK
+ * @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
+ * If the return value is any other values, it means this operation failed.
*/
rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick)
{
@@ -637,11 +656,12 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick)
RTM_EXPORT(rt_thread_delay_until);
/**
- * This function will let current thread delay for some milliseconds.
+ * @brief This function will let current thread delay for some milliseconds.
*
- * @param ms the delay ms time
+ * @param ms is the delay ms time.
*
- * @return RT_EOK
+ * @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
+ * If the return value is any other values, it means this operation failed.
*/
rt_err_t rt_thread_mdelay(rt_int32_t ms)
{
@@ -654,17 +674,24 @@ rt_err_t rt_thread_mdelay(rt_int32_t ms)
RTM_EXPORT(rt_thread_mdelay);
/**
- * This function will control thread behaviors according to control command.
+ * @brief This function will control thread behaviors according to control command.
+ *
+ * @param thread is the specified thread to be controlled.
+ *
+ * @param cmd is the control command, which includes.
*
- * @param thread the specified thread to be controlled
- * @param cmd the control command, which includes
- * RT_THREAD_CTRL_CHANGE_PRIORITY for changing priority level of thread;
- * RT_THREAD_CTRL_STARTUP for starting a thread;
- * RT_THREAD_CTRL_CLOSE for delete a thread;
- * RT_THREAD_CTRL_BIND_CPU for bind the thread to a CPU.
- * @param arg the argument of control command
+ * RT_THREAD_CTRL_CHANGE_PRIORITY for changing priority level of thread.
*
- * @return RT_EOK
+ * RT_THREAD_CTRL_STARTUP for starting a thread.
+ *
+ * RT_THREAD_CTRL_CLOSE for delete a thread.
+ *
+ * RT_THREAD_CTRL_BIND_CPU for bind the thread to a CPU.
+ *
+ * @param arg is the argument of control command.
+ *
+ * @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
+ * If the return value is any other values, it means this operation failed.
*/
rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
{
@@ -755,7 +782,7 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
return RT_ERROR;
}
- cpu = (rt_uint8_t)(size_t)arg;
+ cpu = (rt_uint8_t)(rt_size_t)arg;
thread->bind_cpu = cpu > RT_CPUS_NR? RT_CPUS_NR : cpu;
break;
}
@@ -770,14 +797,15 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
RTM_EXPORT(rt_thread_control);
/**
- * This function will suspend the specified thread.
+ * @brief This function will suspend the specified thread and change it to suspend state.
*
- * @param thread the thread to be suspended
+ * @note If suspend self thread, after this function call, the
+ * rt_schedule() must be invoked.
*
- * @return the operation status, RT_EOK on OK, -RT_ERROR on error
+ * @param thread is the thread to be suspended.
*
- * @note if suspend self thread, after this function call, the
- * rt_schedule() must be invoked.
+ * @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
+ * If the return value is any other values, it means this operation failed.
*/
rt_err_t rt_thread_suspend(rt_thread_t thread)
{
@@ -822,11 +850,12 @@ rt_err_t rt_thread_suspend(rt_thread_t thread)
RTM_EXPORT(rt_thread_suspend);
/**
- * This function will resume a thread and put it to system ready queue.
+ * @brief This function will resume a thread and put it to system ready queue.
*
- * @param thread the thread to be resumed
+ * @param thread is the thread to be resumed.
*
- * @return the operation status, RT_EOK on OK, -RT_ERROR on error
+ * @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
+ * If the return value is any other values, it means this operation failed.
*/
rt_err_t rt_thread_resume(rt_thread_t thread)
{
@@ -866,10 +895,10 @@ rt_err_t rt_thread_resume(rt_thread_t thread)
RTM_EXPORT(rt_thread_resume);
/**
- * This function is the timeout function for thread, normally which is invoked
- * when thread is timeout to wait some resource.
+ * @brief This function is the timeout function for thread, normally which is invoked
+ * when thread is timeout to wait some resource.
*
- * @param parameter the parameter of thread timeout function
+ * @param parameter is the parameter of thread timeout function
*/
void rt_thread_timeout(void *parameter)
{
@@ -904,18 +933,20 @@ void rt_thread_timeout(void *parameter)
RTM_EXPORT(rt_thread_timeout);
/**
- * This function will find the specified thread.
+ * @brief This function will find the specified thread.
*
- * @param name the name of thread finding
+ * @note Please don't invoke this function in interrupt status.
*
- * @return the found thread
+ * @param name is the name of thread finding.
*
- * @note please don't invoke this function in interrupt status.
+ * @return If the return value is a rt_thread structure pointer, the function is successfully executed.
+ * If the return value is RT_NULL, it means this operation failed.
*/
rt_thread_t rt_thread_find(char *name)
{
return (rt_thread_t)rt_object_find(name, RT_Object_Class_Thread);
}
+
RTM_EXPORT(rt_thread_find);
/**@}*/
diff --git a/src/timer.c b/src/timer.c
index 1c8e70fccc..25ba175306 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -16,13 +16,14 @@
* 2012-12-15 Bernard fix the next timeout issue in soft timer
* 2014-07-12 Bernard does not lock scheduler when invoking soft-timer
* timeout function.
+ * 2021-08-15 supperthomas add the comment
*/
#include <rtthread.h>
#include <rthw.h>
/* hard timer list */
-static rt_list_t rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL];
+static rt_list_t _timer_list[RT_TIMER_SKIP_LIST_LEVEL];
#ifdef RT_USING_TIMER_SOFT
@@ -38,12 +39,12 @@ static rt_list_t rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL];
#endif /* RT_TIMER_THREAD_PRIO */
/* soft timer status */
-static rt_uint8_t soft_timer_status = RT_SOFT_TIMER_IDLE;
+static rt_uint8_t _soft_timer_status = RT_SOFT_TIMER_IDLE;
/* soft timer list */
-static rt_list_t rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL];
-static struct rt_thread timer_thread;
+static rt_list_t _soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL];
+static struct rt_thread _timer_thread;
ALIGN(RT_ALIGN_SIZE)
-static rt_uint8_t timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE];
+static rt_uint8_t _timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE];
#endif /* RT_USING_TIMER_SOFT */
#ifdef RT_USING_HOOK
@@ -59,10 +60,10 @@ static void (*rt_timer_exit_hook)(struct rt_timer *timer);
/**@{*/
/**
- * This function will set a hook function, which will be invoked when enter
- * timer timeout callback function.
+ * @brief This function will set a hook function on timer,
+ * which will be invoked when enter timer timeout callback function.
*
- * @param hook the hook function
+ * @param hook is the function point of timer
*/
void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer))
{
@@ -70,10 +71,10 @@ void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer))
}
/**
- * This function will set a hook function, which will be invoked when exit
- * timer timeout callback function.
+ * @brief This function will set a hook function, which will be
+ * invoked when exit timer timeout callback function.
*
- * @param hook the hook function
+ * @param hook is the function point of timer
*/
void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer))
{
@@ -83,7 +84,25 @@ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer))
/**@}*/
#endif /* RT_USING_HOOK */
-static void _rt_timer_init(rt_timer_t timer,
+
+/**
+ * @brief [internal] The init funtion of timer
+ *
+ * The internal called function of rt_timer_init
+ *
+ * @see rt_timer_init
+ *
+ * @param timer is timer object
+ *
+ * @param timeout is the timeout function
+ *
+ * @param parameter is the parameter of timeout function
+ *
+ * @param time is the tick of timer
+ *
+ * @param flag the flag of timer
+ */
+static void _timer_init(rt_timer_t timer,
void (*timeout)(void *parameter),
void *parameter,
rt_tick_t time,
@@ -110,8 +129,14 @@ static void _rt_timer_init(rt_timer_t timer,
}
}
-/* the fist timer always in the last row */
-static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[])
+/**
+ * @brief Find the next emtpy timer ticks
+ *
+ * @param timer_list is the array of time list
+ *
+ * @return the next timer's ticks
+ */
+static rt_tick_t _timer_list_next_timeout(rt_list_t timer_list[])
{
struct rt_timer *timer;
register rt_base_t level;
@@ -133,7 +158,12 @@ static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[])
return timeout_tick;
}
-rt_inline void _rt_timer_remove(rt_timer_t timer)
+/**
+ * @brief Remove the timer
+ *
+ * @param timer the point of the timer
+ */
+rt_inline void _timer_remove(rt_timer_t timer)
{
int i;
@@ -144,7 +174,14 @@ rt_inline void _rt_timer_remove(rt_timer_t timer)
}
#if RT_DEBUG_TIMER
-static int rt_timer_count_height(struct rt_timer *timer)
+/**
+ * @brief The number of timer
+ *
+ * @param timer the head of timer
+ *
+ * @return count of timer
+ */
+static int _timer_count_height(struct rt_timer *timer)
{
int i, cnt = 0;
@@ -155,7 +192,11 @@ static int rt_timer_count_height(struct rt_timer *timer)
}
return cnt;
}
-
+/**
+ * @brief dump the all timer information
+ *
+ * @param timer_heads the head of timer
+ */
void rt_timer_dump(rt_list_t timer_heads[])
{
rt_list_t *list;
@@ -167,7 +208,7 @@ void rt_timer_dump(rt_list_t timer_heads[])
struct rt_timer *timer = rt_list_entry(list,
struct rt_timer,
row[RT_TIMER_SKIP_LIST_LEVEL - 1]);
- rt_kprintf("%d", rt_timer_count_height(timer));
+ rt_kprintf("%d", _timer_count_height(timer));
}
rt_kprintf("\n");
}
@@ -180,15 +221,20 @@ void rt_timer_dump(rt_list_t timer_heads[])
/**@{*/
/**
- * This function will initialize a timer, normally this function is used to
- * initialize a static timer object.
+ * @brief This function will initialize a timer
+ * normally this function is used to initialize a static timer object.
*
- * @param timer the static timer object
- * @param name the name of timer
- * @param timeout the timeout function
- * @param parameter the parameter of timeout function
- * @param time the tick of timer
- * @param flag the flag of timer
+ * @param timer is the point of timer
+ *
+ * @param name is a pointer to the name of the timer
+ *
+ * @param timeout is the callback of timer
+ *
+ * @param parameter is the param of the callback
+ *
+ * @param time is the ticks of timer
+ *
+ * @param flag is the flag of timer
*/
void rt_timer_init(rt_timer_t timer,
const char *name,
@@ -203,16 +249,16 @@ void rt_timer_init(rt_timer_t timer,
/* timer object initialization */
rt_object_init(&(timer->parent), RT_Object_Class_Timer, name);
- _rt_timer_init(timer, timeout, parameter, time, flag);
+ _timer_init(timer, timeout, parameter, time, flag);
}
RTM_EXPORT(rt_timer_init);
/**
- * This function will detach a timer from timer management.
+ * @brief This function will detach a timer from timer management.
*
- * @param timer the static timer object
+ * @param timer is the timer to be detached
*
- * @return the operation status, RT_EOK on OK; RT_ERROR on error
+ * @return the status of detach
*/
rt_err_t rt_timer_detach(rt_timer_t timer)
{
@@ -226,7 +272,7 @@ rt_err_t rt_timer_detach(rt_timer_t timer)
/* disable interrupt */
level = rt_hw_interrupt_disable();
- _rt_timer_remove(timer);
+ _timer_remove(timer);
/* stop timer */
timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
@@ -241,12 +287,16 @@ RTM_EXPORT(rt_timer_detach);
#ifdef RT_USING_HEAP
/**
- * This function will create a timer
+ * @brief This function will create a timer
*
* @param name the name of timer
+ *
* @param timeout the timeout function
+ *
* @param parameter the parameter of timeout function
+ *
* @param time the tick of timer
+ *
* @param flag the flag of timer
*
* @return the created timer object
@@ -266,14 +316,14 @@ rt_timer_t rt_timer_create(const char *name,
return RT_NULL;
}
- _rt_timer_init(timer, timeout, parameter, time, flag);
+ _timer_init(timer, timeout, parameter, time, flag);
return timer;
}
RTM_EXPORT(rt_timer_create);
/**
- * This function will delete a timer and release timer memory
+ * @brief This function will delete a timer and release timer memory
*
* @param timer the timer to be deleted
*
@@ -291,7 +341,7 @@ rt_err_t rt_timer_delete(rt_timer_t timer)
/* disable interrupt */
level = rt_hw_interrupt_disable();
- _rt_timer_remove(timer);
+ _timer_remove(timer);
/* stop timer */
timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
@@ -306,7 +356,7 @@ RTM_EXPORT(rt_timer_delete);
#endif /* RT_USING_HEAP */
/**
- * This function will start the timer
+ * @brief This function will start the timer
*
* @param timer the timer to be started
*
@@ -317,6 +367,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
unsigned int row_lvl;
rt_list_t *timer_list;
register rt_base_t level;
+ register rt_bool_t need_schedule;
rt_list_t *row_head[RT_TIMER_SKIP_LIST_LEVEL];
unsigned int tst_nr;
static unsigned int random_nr;
@@ -325,10 +376,12 @@ rt_err_t rt_timer_start(rt_timer_t timer)
RT_ASSERT(timer != RT_NULL);
RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer);
+ need_schedule = RT_FALSE;
+
/* stop timer firstly */
level = rt_hw_interrupt_disable();
/* remove timer from list */
- _rt_timer_remove(timer);
+ _timer_remove(timer);
/* change status of timer */
timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
@@ -345,13 +398,13 @@ rt_err_t rt_timer_start(rt_timer_t timer)
if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER)
{
/* insert timer to soft timer list */
- timer_list = rt_soft_timer_list;
+ timer_list = _soft_timer_list;
}
else
#endif /* RT_USING_TIMER_SOFT */
{
/* insert timer to system timer list */
- timer_list = rt_timer_list;
+ timer_list = _timer_list;
}
row_head[0] = &timer_list[0];
@@ -407,29 +460,34 @@ rt_err_t rt_timer_start(rt_timer_t timer)
timer->parent.flag |= RT_TIMER_FLAG_ACTIVATED;
- /* enable interrupt */
- rt_hw_interrupt_enable(level);
-
#ifdef RT_USING_TIMER_SOFT
if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER)
{
/* check whether timer thread is ready */
- if ((soft_timer_status == RT_SOFT_TIMER_IDLE) &&
- ((timer_thread.stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND))
+ if ((_soft_timer_status == RT_SOFT_TIMER_IDLE) &&
+ ((_timer_thread.stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND))
{
/* resume timer thread to check soft timer */
- rt_thread_resume(&timer_thread);
- rt_schedule();
+ rt_thread_resume(&_timer_thread);
+ need_schedule = RT_TRUE;
}
}
#endif /* RT_USING_TIMER_SOFT */
+ /* enable interrupt */
+ rt_hw_interrupt_enable(level);
+
+ if (need_schedule)
+ {
+ rt_schedule();
+ }
+
return RT_EOK;
}
RTM_EXPORT(rt_timer_start);
/**
- * This function will stop the timer
+ * @brief This function will stop the timer
*
* @param timer the timer to be stopped
*
@@ -451,7 +509,7 @@ rt_err_t rt_timer_stop(rt_timer_t timer)
/* disable interrupt */
level = rt_hw_interrupt_disable();
- _rt_timer_remove(timer);
+ _timer_remove(timer);
/* change status */
timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
@@ -463,13 +521,13 @@ rt_err_t rt_timer_stop(rt_timer_t timer)
RTM_EXPORT(rt_timer_stop);
/**
- * This function will get or set some options of the timer
+ * @brief This function will get or set some options of the timer
*
* @param timer the timer to be get or set
* @param cmd the control command
* @param arg the argument
*
- * @return RT_EOK
+ * @return the statu of control
*/
rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg)
{
@@ -521,10 +579,10 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg)
RTM_EXPORT(rt_timer_control);
/**
- * This function will check timer list, if a timeout event happens, the
- * corresponding timeout function will be invoked.
+ * @brief This function will check timer list, if a timeout event happens,
+ * the corresponding timeout function will be invoked.
*
- * @note this function shall be invoked in operating system timer interrupt.
+ * @note This function shall be invoked in operating system timer interrupt.
*/
void rt_timer_check(void)
{
@@ -542,9 +600,9 @@ void rt_timer_check(void)
/* disable interrupt */
level = rt_hw_interrupt_disable();
- while (!rt_list_isempty(&rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1]))
+ while (!rt_list_isempty(&_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1]))
{
- t = rt_list_entry(rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next,
+ t = rt_list_entry(_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next,
struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]);
/*
@@ -556,7 +614,7 @@ void rt_timer_check(void)
RT_OBJECT_HOOK_CALL(rt_timer_enter_hook, (t));
/* remove timer from timer list firstly */
- _rt_timer_remove(t);
+ _timer_remove(t);
if (!(t->parent.flag & RT_TIMER_FLAG_PERIODIC))
{
t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
@@ -596,19 +654,19 @@ void rt_timer_check(void)
}
/**
- * This function will return the next timeout tick in the system.
+ * @brief This function will return the next timeout tick in the system.
*
* @return the next timeout tick in the system
*/
rt_tick_t rt_timer_next_timeout_tick(void)
{
- return rt_timer_list_next_timeout(rt_timer_list);
+ return _timer_list_next_timeout(_timer_list);
}
#ifdef RT_USING_TIMER_SOFT
/**
- * This function will check software-timer list, if a timeout event happens, the
- * corresponding timeout function will be invoked.
+ * @brief This function will check software-timer list, if a timeout event happens, the
+ * corresponding timeout function will be invoked.
*/
void rt_soft_timer_check(void)
{
@@ -624,9 +682,9 @@ void rt_soft_timer_check(void)
/* disable interrupt */
level = rt_hw_interrupt_disable();
- while (!rt_list_isempty(&rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1]))
+ while (!rt_list_isempty(&_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1]))
{
- t = rt_list_entry(rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next,
+ t = rt_list_entry(_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next,
struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]);
current_tick = rt_tick_get();
@@ -640,7 +698,7 @@ void rt_soft_timer_check(void)
RT_OBJECT_HOOK_CALL(rt_timer_enter_hook, (t));
/* remove timer from timer list firstly */
- _rt_timer_remove(t);
+ _timer_remove(t);
if (!(t->parent.flag & RT_TIMER_FLAG_PERIODIC))
{
t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
@@ -648,7 +706,7 @@ void rt_soft_timer_check(void)
/* add timer to temporary list */
rt_list_insert_after(&list, &(t->row[RT_TIMER_SKIP_LIST_LEVEL - 1]));
- soft_timer_status = RT_SOFT_TIMER_BUSY;
+ _soft_timer_status = RT_SOFT_TIMER_BUSY;
/* enable interrupt */
rt_hw_interrupt_enable(level);
@@ -661,7 +719,7 @@ void rt_soft_timer_check(void)
/* disable interrupt */
level = rt_hw_interrupt_disable();
- soft_timer_status = RT_SOFT_TIMER_IDLE;
+ _soft_timer_status = RT_SOFT_TIMER_IDLE;
/* Check whether the timer object is detached or started again */
if (rt_list_isempty(&list))
{
@@ -684,15 +742,19 @@ void rt_soft_timer_check(void)
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check leave\n"));
}
-/* system timer thread entry */
-static void rt_thread_timer_entry(void *parameter)
+/**
+ * @brief System timer thread entry
+ *
+ * @param parameter is the arg of the thread
+ */
+static void _timer_thread_entry(void *parameter)
{
rt_tick_t next_timeout;
while (1)
{
/* get the next timeout tick */
- next_timeout = rt_timer_list_next_timeout(rt_soft_timer_list);
+ next_timeout = _timer_list_next_timeout(_soft_timer_list);
if (next_timeout == RT_TICK_MAX)
{
/* no software timer exist, suspend self. */
@@ -723,22 +785,22 @@ static void rt_thread_timer_entry(void *parameter)
/**
* @ingroup SystemInit
*
- * This function will initialize system timer
+ * @brief This function will initialize system timer
*/
void rt_system_timer_init(void)
{
int i;
- for (i = 0; i < sizeof(rt_timer_list) / sizeof(rt_timer_list[0]); i++)
+ for (i = 0; i < sizeof(_timer_list) / sizeof(_timer_list[0]); i++)
{
- rt_list_init(rt_timer_list + i);
+ rt_list_init(_timer_list + i);
}
}
/**
* @ingroup SystemInit
*
- * This function will initialize system timer thread
+ * @brief This function will initialize system timer thread
*/
void rt_system_timer_thread_init(void)
{
@@ -746,24 +808,24 @@ void rt_system_timer_thread_init(void)
int i;
for (i = 0;
- i < sizeof(rt_soft_timer_list) / sizeof(rt_soft_timer_list[0]);
+ i < sizeof(_soft_timer_list) / sizeof(_soft_timer_list[0]);
i++)
{
- rt_list_init(rt_soft_timer_list + i);
+ rt_list_init(_soft_timer_list + i);
}
/* start software timer thread */
- rt_thread_init(&timer_thread,
+ rt_thread_init(&_timer_thread,
"timer",
- rt_thread_timer_entry,
+ _timer_thread_entry,
RT_NULL,
- &timer_thread_stack[0],
- sizeof(timer_thread_stack),
+ &_timer_thread_stack[0],
+ sizeof(_timer_thread_stack),
RT_TIMER_THREAD_PRIO,
10);
/* startup */
- rt_thread_startup(&timer_thread);
+ rt_thread_startup(&_timer_thread);
#endif /* RT_USING_TIMER_SOFT */
}