RT-Thread RTOS  1.0.0
An open source embedded real-time operating system
Thread Management

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.


Define Documentation

#define RT_THREAD_INIT   0x00

Initialized status

#define RT_THREAD_READY   0x01

Ready status

#define RT_THREAD_SUSPEND   0x02

Suspend status

#define RT_THREAD_RUNNING   0x03

Running status

Blocked status

#define RT_THREAD_CLOSE   0x04

Closed status

#define RT_THREAD_CTRL_STARTUP   0x00

thread control command definitions Starup thread.

#define RT_THREAD_CTRL_CLOSE   0x01

Close thread.

#define RT_THREAD_CTRL_CHANGE_PRIORITY   0x02

Change thread priority.

#define RT_THREAD_CTRL_INFO   0x03

Get thread information.


Function Documentation

void rt_thread_idle_excute ( void  )

This function will perform system background job when system idle.

void rt_schedule ( void  )

This function will perform one schedule. It will select one thread with the highest priority level, then switch to it.

void rt_enter_critical ( void  )

This function will lock the thread scheduler.

void rt_exit_critical ( void  )

This function will unlock the thread scheduler.

rt_err_t rt_thread_init ( struct rt_thread thread,
const char *  name,
void(*)(void *parameter)  entry,
void *  parameter,
void *  stack_start,
rt_uint32_t  stack_size,
rt_uint8_t  priority,
rt_uint32_t  tick 
)

This function will initialize a thread, normally it's used to initialize a static thread object.

Parameters:
threadthe static thread object
namethe name of thread, which shall be unique
entrythe entry function of thread
parameterthe parameter of thread enter function
stack_startthe start address of thread stack
stack_sizethe size of thread stack
prioritythe priority of thread
tickthe time slice if there are same priority thread
Returns:
the operation status, RT_EOK on OK, -RT_ERROR on error
rt_thread_t rt_thread_create ( const char *  name,
void(*)(void *parameter)  entry,
void *  parameter,
rt_uint32_t  stack_size,
rt_uint8_t  priority,
rt_uint32_t  tick 
)

This function will create a thread object and allocate thread object memory and stack.

Parameters:
namethe name of thread, which shall be unique
entrythe entry function of thread
parameterthe parameter of thread enter function
stack_sizethe size of thread stack
prioritythe priority of thread
tickthe 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:
threadthe 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:
threadthe 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:
threadthe 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:
tickthe sleep ticks
Returns:
RT_EOK

This function will let current thread delay for some ticks.

Parameters:
tickthe delay ticks
Returns:
RT_EOK
rt_err_t rt_thread_control ( rt_thread_t  thread,
rt_uint8_t  cmd,
void *  arg 
)

This function will control thread behaviors according to control command.

Parameters:
threadthe specified thread to be controlled
cmdthe 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.
argthe argument of control command
Returns:
RT_EOK

This function will suspend the specified thread.

Parameters:
threadthe 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:
threadthe thread to be resumed
Returns:
the operation status, RT_EOK on OK, -RT_ERROR on error
void rt_thread_timeout ( void *  parameter)

This function is the timeout function for thread, normally which is invoked when thread is timeout to wait some resourse.

Parameters:
parameterthe parameter of thread timeout function
rt_thread_t rt_thread_find ( char *  name)

This function will find the specified thread.

Parameters:
namethe name of thread finding
Returns:
the found thread
Note:
please don't invoke this function in interrupt status.
void rt_thread_idle_init ( void  )

This function will initialize idle thread, then start it.

Note:
this function must be invoked when system init.
void rt_system_scheduler_init ( void  )

This function will initialize the system scheduler

void rt_system_scheduler_start ( void  )

This function will startup scheduler. It will select one thread with the highest priority level, then switch to it.

 All Data Structures Variables