Data Structures |
struct | rt_thread |
Defines |
#define | RT_THREAD_INIT 0x00 |
#define | RT_THREAD_READY 0x01 |
#define | RT_THREAD_SUSPEND 0x02 |
#define | RT_THREAD_RUNNING 0x03 |
#define | RT_THREAD_BLOCK RT_THREAD_SUSPEND |
#define | RT_THREAD_CLOSE 0x04 |
#define | RT_THREAD_CTRL_STARTUP 0x00 |
#define | RT_THREAD_CTRL_CLOSE 0x01 |
#define | RT_THREAD_CTRL_CHANGE_PRIORITY 0x02 |
#define | RT_THREAD_CTRL_INFO 0x03 |
Functions |
void | rt_thread_idle_excute (void) |
void | rt_schedule (void) |
void | rt_enter_critical (void) |
void | rt_exit_critical (void) |
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) |
rt_thread_t | rt_thread_create (const char *name, void(*entry)(void *parameter), void *parameter, rt_uint32_t stack_size, rt_uint8_t priority, rt_uint32_t tick) |
rt_thread_t | rt_thread_self (void) |
rt_err_t | rt_thread_startup (rt_thread_t thread) |
rt_err_t | rt_thread_detach (rt_thread_t thread) |
rt_err_t | rt_thread_delete (rt_thread_t thread) |
rt_err_t | rt_thread_yield (void) |
rt_err_t | rt_thread_sleep (rt_tick_t tick) |
rt_err_t | rt_thread_delay (rt_tick_t tick) |
rt_err_t | rt_thread_control (rt_thread_t thread, rt_uint8_t cmd, void *arg) |
rt_err_t | rt_thread_suspend (rt_thread_t thread) |
rt_err_t | rt_thread_resume (rt_thread_t thread) |
void | rt_thread_timeout (void *parameter) |
rt_thread_t | rt_thread_find (char *name) |
void | rt_thread_idle_init (void) |
void | rt_system_scheduler_init (void) |
void | rt_system_scheduler_start (void) |
Detailed Description
RT-Thread operating system supports multitask systems, which are based on thread scheduling.
- The scheduling is a full preemptive priority-based scheduling algorithm.
- 8/32/256 priority levels are supported, in which 0 is the highest and 7/31/255 the lowest. The 7/31/255th priority is used for idle thread.
- Threads running at same priority level are supported. The shared time-slice round-robin scheduling is used for this case.
- The time of scheduler to choose the next highest ready thread is determinant.
- There are four status in thread management
- Initialization
- Running/Ready
- Blocked
- Closed
- The number of threads in the system is unlimited, only related with RAM.
Define Documentation
thread control command definitions Starup thread.
Function Documentation
This function will perform system background job when system idle.
This function will perform one schedule. It will select one thread with the highest priority level, then switch to it.
This function will lock the thread scheduler.
This function will unlock the thread scheduler.
This function will initialize a thread, normally it's used to initialize a static thread object.
- Parameters:
-
thread | the static thread object |
name | the name of thread, which shall be unique |
entry | the entry function of thread |
parameter | the parameter of thread enter function |
stack_start | the start address of thread stack |
stack_size | the size of thread stack |
priority | the priority of thread |
tick | the time slice if there are same priority thread |
- Returns:
- the operation status, RT_EOK on OK, -RT_ERROR on error
This function will create a thread object and allocate thread object memory and stack.
- Parameters:
-
name | the name of thread, which shall be unique |
entry | the entry function of thread |
parameter | the parameter of thread enter function |
stack_size | the size of thread stack |
priority | the priority of thread |
tick | the time slice if there are same priority thread |
- Returns:
- the created thread object
This function will return self thread object
- Returns:
- the self thread object
This function will start a thread and put it to system ready queue
- Parameters:
-
thread | the thread to be started |
- Returns:
- the operation status, RT_EOK on OK, -RT_ERROR on error
This function will detach a thread. The thread object will be removed from thread queue and detached/deleted from system object management.
- Parameters:
-
thread | the thread to be deleted |
- Returns:
- the operation status, RT_EOK on OK, -RT_ERROR on error
This function will delete a thread. The thread object will be removed from thread queue and detached/deleted from system object management.
- Parameters:
-
thread | the thread to be deleted |
- Returns:
- the operation status, RT_EOK on OK, -RT_ERROR on error
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.
- Returns:
- RT_EOK
This function will let current thread sleep for some ticks.
- Parameters:
-
- Returns:
- RT_EOK
This function will let current thread delay for some ticks.
- Parameters:
-
- Returns:
- RT_EOK
This function will control thread behaviors according to control command.
- Parameters:
-
thread | the specified thread to be controlled |
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. |
arg | the argument of control command |
- Returns:
- RT_EOK
This function will suspend the specified thread.
- Parameters:
-
thread | the thread to be suspended |
- Returns:
- the operation status, RT_EOK on OK, -RT_ERROR on error
- Note:
- if suspend self thread, after this function call, the rt_schedule() must be invoked.
This function will resume a thread and put it to system ready queue.
- Parameters:
-
thread | the thread to be resumed |
- Returns:
- the operation status, RT_EOK on OK, -RT_ERROR on error
This function is the timeout function for thread, normally which is invoked when thread is timeout to wait some resourse.
- Parameters:
-
parameter | the parameter of thread timeout function |
This function will find the specified thread.
- Parameters:
-
name | the name of thread finding |
- Returns:
- the found thread
- Note:
- please don't invoke this function in interrupt status.
This function will initialize idle thread, then start it.
- Note:
- this function must be invoked when system init.
This function will initialize the system scheduler
This function will startup scheduler. It will select one thread with the highest priority level, then switch to it.