![]() |
RT-Thread RTOS
An open source embedded real-time operating system
|
Data Structures | |
struct | rt_cpu_usage_stats |
struct | rt_interrupt_context |
struct | rt_thread |
Macros | |
#define | RT_THREAD_INIT 0x00 |
#define | RT_THREAD_CLOSE 0x01 |
#define | RT_THREAD_READY 0x02 |
#define | RT_THREAD_RUNNING 0x03 |
#define | RT_THREAD_SUSPEND_INTERRUPTIBLE (RT_THREAD_SUSPEND_MASK) |
#define | RT_THREAD_SUSPEND_KILLABLE (RT_THREAD_SUSPEND_MASK | RT_SIGNAL_COMMON_WAKEUP_MASK) |
#define | RT_THREAD_SUSPEND_UNINTERRUPTIBLE (RT_THREAD_SUSPEND_MASK | RT_SIGNAL_COMMON_WAKEUP_MASK | RT_SIGNAL_KILL_WAKEUP_MASK) |
#define | RT_THREAD_STAT_YIELD 0x08 |
#define | RT_THREAD_STAT_SIGNAL 0x10 |
#define | RT_THREAD_STAT_SIGNAL_WAIT 0x20 |
#define | RT_THREAD_STAT_SIGNAL_PENDING 0x40 |
#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 |
#define | RT_THREAD_CTRL_BIND_CPU 0x04 |
#define | RT_THREAD_CTRL_RESET_PRIORITY 0x05 |
Typedefs | |
typedef struct rt_interrupt_context * | rt_interrupt_context_t |
typedef void(* | rt_thread_inited_hookproto_t) (rt_thread_t thread) |
Functions | |
void | rt_scheduler_ipi_handler (int vector, void *param) |
void | rt_schedule (void) |
void | rt_scheduler_do_irq_switch (void *context) |
void | rt_schedule_insert_thread (struct rt_thread *thread) |
void | rt_schedule_remove_thread (struct rt_thread *thread) |
void | rt_enter_critical (void) |
void | rt_exit_critical (void) |
rt_uint16_t | rt_critical_level (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_self (void) |
rt_err_t | rt_thread_startup (rt_thread_t thread) |
rt_err_t | rt_thread_close (rt_thread_t thread) |
rt_err_t | rt_thread_detach (rt_thread_t thread) |
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_err_t | rt_thread_delete (rt_thread_t thread) |
rt_err_t | rt_thread_yield (void) |
rt_err_t | rt_thread_delay (rt_tick_t tick) |
rt_err_t | rt_thread_delay_until (rt_tick_t *tick, rt_tick_t inc_tick) |
rt_err_t | rt_thread_mdelay (rt_int32_t ms) |
rt_err_t | rt_thread_control (rt_thread_t thread, int cmd, void *arg) |
rt_err_t | rt_thread_suspend_to_list (rt_thread_t thread, rt_list_t *susp_list, int ipc_flags, int suspend_flag) |
rt_err_t | rt_thread_suspend_with_flag (rt_thread_t thread, int suspend_flag) |
rt_err_t | rt_thread_resume (rt_thread_t thread) |
rt_thread_t | rt_thread_find (char *name) |
rt_err_t | rt_thread_get_name (rt_thread_t thread, char *name, rt_uint8_t name_size) |
int | rt_thread_kill (rt_thread_t tid, int sig) |
void | rt_thread_idle_init (void) |
rt_err_t | rt_thread_idle_delhook (void(*hook)(void)) |
rt_thread_t | rt_thread_idle_gethandler (void) |
void | rt_system_scheduler_init (void) |
void | rt_system_scheduler_start (void) |
See Thread Management.
#define RT_THREAD_INIT 0x00 |
Initialized status
#define RT_THREAD_CLOSE 0x01 |
Closed status
#define RT_THREAD_READY 0x02 |
Ready status
#define RT_THREAD_RUNNING 0x03 |
Running status
#define RT_THREAD_SUSPEND_INTERRUPTIBLE (RT_THREAD_SUSPEND_MASK) |
Suspend interruptable 0x4
#define RT_THREAD_SUSPEND_KILLABLE (RT_THREAD_SUSPEND_MASK | RT_SIGNAL_COMMON_WAKEUP_MASK) |
Suspend with killable 0x6
#define RT_THREAD_SUSPEND_UNINTERRUPTIBLE (RT_THREAD_SUSPEND_MASK | RT_SIGNAL_COMMON_WAKEUP_MASK | RT_SIGNAL_KILL_WAKEUP_MASK) |
Suspend with uninterruptable 0x7
#define RT_THREAD_STAT_YIELD 0x08 |
indicate whether remaining_tick has been reloaded since last schedule
#define RT_THREAD_STAT_SIGNAL 0x10 |
task hold signals
#define RT_THREAD_STAT_SIGNAL_WAIT 0x20 |
task is waiting for signals
#define RT_THREAD_STAT_SIGNAL_PENDING 0x40 |
signals is held and it has not been procressed
#define RT_THREAD_CTRL_STARTUP 0x00 |
thread control command definitions Startup 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.
#define RT_THREAD_CTRL_BIND_CPU 0x04 |
Set thread bind cpu.
#define RT_THREAD_CTRL_RESET_PRIORITY 0x05 |
Reset thread priority.
typedef struct rt_interrupt_context * rt_interrupt_context_t |
interrupt/exception frame handling
typedef void(* rt_thread_inited_hookproto_t) (rt_thread_t thread) |
Sets a hook function when a thread is initialized.
thread | is the target thread that initializing |
void rt_scheduler_ipi_handler | ( | int | vector, |
void * | param | ||
) |
This function will handle IPI interrupt and do a scheduling in system.
vector | is the number of IPI interrupt for system scheduling. |
param | is not used, and can be set to RT_NULL. |
void rt_schedule | ( | void | ) |
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_scheduler_do_irq_switch | ( | void * | context | ) |
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.
context | is the context to be switched to. |
void rt_schedule_insert_thread | ( | struct rt_thread * | thread | ) |
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.
thread | is the thread to be inserted. |
void rt_schedule_remove_thread | ( | struct rt_thread * | thread | ) |
This function will remove a thread from system ready queue.
thread | is the thread to be removed. |
rt_base_t rt_enter_critical | ( | void | ) |
This function will lock the thread scheduler.
void rt_exit_critical | ( | void | ) |
This function will unlock the thread scheduler.
rt_uint16_t rt_critical_level | ( | void | ) |
Get the scheduler lock level.
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. It's used to initialize a static thread object.
thread | is the static thread object. |
name | is the name of thread, which shall be unique. |
entry | is the entry function of thread. |
parameter | is the parameter of thread enter function. |
stack_start | is the start address of thread stack. |
stack_size | is the size of thread stack. |
priority | is the priority of thread. |
tick | is the time slice if there are same priority thread. |
rt_thread_t rt_thread_self | ( | void | ) |
This function will return self thread object.
rt_err_t rt_thread_startup | ( | rt_thread_t | thread | ) |
This function will start a thread and put it to system ready queue.
thread | is the thread to be started. |
rt_err_t rt_thread_close | ( | rt_thread_t | thread | ) |
This function will close a thread. The thread object will be removed from thread queue and detached/deleted from the system object management. It's different from rt_thread_delete or rt_thread_detach that this will not enqueue the closing thread to cleanup queue.
thread | is the thread to be closed. |
rt_err_t rt_thread_detach | ( | rt_thread_t | thread | ) |
This function will detach a thread. The thread object will be removed from thread queue and detached/deleted from the system object management.
thread | is the thread to be deleted. |
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.
name | is the name of thread, which shall be unique. |
entry | is the entry function of thread. |
parameter | is the parameter of thread enter function. |
stack_size | is the size of thread stack. |
priority | is the priority of thread. |
tick | is the time slice if there are same priority thread. |
rt_err_t rt_thread_delete | ( | rt_thread_t | thread | ) |
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.
thread | is the thread to be deleted. |
rt_err_t rt_thread_yield | ( | void | ) |
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.
rt_err_t rt_thread_delay | ( | rt_tick_t | tick | ) |
This function will let current thread delay for some ticks.
tick | is the delay ticks. |
rt_err_t rt_thread_delay_until | ( | rt_tick_t * | tick, |
rt_tick_t | inc_tick | ||
) |
This function will let current thread delay until (*tick + inc_tick).
tick | is the tick of last wakeup. |
inc_tick | is the increment tick. |
rt_err_t rt_thread_mdelay | ( | rt_int32_t | ms | ) |
This function will let current thread delay for some milliseconds.
ms | is the delay ms time. |
rt_err_t rt_thread_control | ( | rt_thread_t | thread, |
int | cmd, | ||
void * | arg | ||
) |
This function will control thread behaviors according to control command.
thread | is the specified thread to be controlled. |
cmd | is 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. RT_THREAD_CTRL_RESET_PRIORITY for reset priority level of thread. |
arg | is the argument of control command. |
rt_err_t rt_thread_suspend_to_list | ( | rt_thread_t | thread, |
rt_list_t * | susp_list, | ||
int | ipc_flags, | ||
int | suspend_flag | ||
) |
This function will suspend the specified thread and change it to suspend state.
Do not use the rt_thread_suspend to suspend other threads. You have no way of knowing what code a thread is executing when you suspend it. If you suspend a thread while sharing a resouce with other threads and occupying this resouce, starvation can occur very easily.
thread | the thread to be suspended. |
susp_list | the list thread enqueued to. RT_NULL if no list. |
ipc_flags | is a flag for the thread object to be suspended. It determines how the thread is suspended. The flag can be ONE of the following values: RT_IPC_FLAG_PRIO The pending threads will queue in order of priority. RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method (also known as first-come-first-served (FCFS) scheduling strategy). NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about the first-in-first-out principle, and you clearly understand that all threads involved in this semaphore will become non-real-time threads. |
suspend_flag | status flag of the thread to be suspended. |
enqueue thread on the push list before leaving critical region of scheduler, so we won't miss notification of async events.
rt_err_t rt_thread_suspend_with_flag | ( | rt_thread_t | thread, |
int | suspend_flag | ||
) |
This function will suspend the specified thread and change it to suspend state.
Do not use the rt_thread_suspend to suspend other threads. You have no way of knowing what code a thread is executing when you suspend it. If you suspend a thread while sharing a resouce with other threads and occupying this resouce, starvation can occur very easily.
thread | the thread to be suspended. |
suspend_flag | status flag of the thread to be suspended. |
rt_err_t rt_thread_resume | ( | rt_thread_t | thread | ) |
This function will resume a thread and put it to system ready queue.
thread | is the thread to be resumed. |
RT_ESCHEDLOCKED indicates that the current thread is in a critical section, rather than 'thread' can't be resumed. Therefore, we can ignore this error.
rt_thread_t rt_thread_find | ( | char * | name | ) |
This function will find the specified thread.
name | is the name of thread finding. |
rt_err_t rt_thread_get_name | ( | rt_thread_t | thread, |
char * | name, | ||
rt_uint8_t | name_size | ||
) |
This function will return the name of the specified thread.
thread | the thread to retrieve thread name |
name | buffer to store the thread name string |
name_size | maximum size of the buffer to store the thread name |
int rt_thread_kill | ( | rt_thread_t | tid, |
int | sig | ||
) |
This function can be used to send any signal to any thread.
tid | is a pointer to the thread that receives the signal. |
sig | is a specific signal value (range: 0 ~ RT_SIG_MAX). |
void rt_thread_idle_init | ( | void | ) |
This function will initialize idle thread, then start it.
rt_err_t rt_thread_idle_delhook | ( | void(*)(void) | hook | ) |
delete the idle hook on hook list.
hook | the specified hook function. |
rt_thread_t rt_thread_idle_gethandler | ( | void | ) |
This function will get the handler of the idle thread.
void rt_system_scheduler_init | ( | void | ) |
This function will initialize the system scheduler.
void rt_system_scheduler_start | ( | void | ) |
This function will startup the scheduler. It will select one thread with the highest priority level, then switch to it.
legacy rt_cpus_lock. some bsp codes still use it as for it's critical region. Since scheduler is never touching this, here we just release it on the entry.
for the accessing of the scheduler context. Noted that we don't have current_thread at this point