The Contiki multi-threading library requires some architecture specific support for setting up and switching stacks.
This support requires four stack manipulation functions to be implemented: mtarch_start(), which sets up the stack frame for a new thread, mtarch_exec(), which switches in the stack of a thread, mtarch_yield(), which restores the kernel stack from a thread's stack and mtarch_stop(), which cleans up the stack of a thread. Additionally, two functions for controlling the preemption (if any) must be implemented: mtarch_pstart() and mtarch_pstop(). If no preemption is used, these functions can be implemented as empty functions. Finally, the function mtarch_init() is called by mt_init(), and can be used for initialization of timer interrupts, or any other mechanisms required for correct operation of the architecture specific support functions while mtarch_remove() is called by mt_remove() to clean up those resources.
Files | |
file | mt.h |
Header file for the preemptive multitasking library for Contiki. | |
Functions | |
void | mtarch_exec (struct mtarch_thread *thread) |
Start executing a thread. More... | |
void | mtarch_init (void) |
Initialize the architecture specific support functions for the multi-thread library. More... | |
void | mtarch_pstart (void) |
void | mtarch_pstop (void) |
void | mtarch_remove (void) |
Uninstall library and clean up. More... | |
void | mtarch_start (struct mtarch_thread *thread, void(*function)(void *data), void *data) |
Setup the stack frame for a thread that is being started. More... | |
void | mtarch_stop (struct mtarch_thread *thread) |
Clean up the stack of a thread. More... | |
void | mtarch_yield (void) |
Yield the processor. More... | |
void mtarch_exec | ( | struct mtarch_thread * | thread | ) |
Start executing a thread.
This function is called from mt_exec() and the purpose of the function is to start execution of the thread. The function should switch in the stack of the thread, and does not return until the thread has explicitly yielded (using mt_yield()) or until it is preempted.
thread | A pointer to a struct mtarch_thread for the thread to be executed. |
Referenced by mt_exec().
void mtarch_init | ( | void | ) |
Initialize the architecture specific support functions for the multi-thread library.
This function is implemented by the architecture specific functions for the multi-thread library and is called by the mt_init() function as part of the initialization of the library. The mtarch_init() function can be used for, e.g., starting preemption timers or other architecture specific mechanisms required for the operation of the library.
Referenced by mt_init().
void mtarch_pstart | ( | void | ) |
void mtarch_pstop | ( | void | ) |
Referenced by mt_yield().
void mtarch_remove | ( | void | ) |
Uninstall library and clean up.
Referenced by mt_remove().
void mtarch_start | ( | struct mtarch_thread * | thread, |
void(*)(void *data) | function, | ||
void * | data | ||
) |
Setup the stack frame for a thread that is being started.
This function is called by the mt_start() function in order to set up the architecture specific stack of the thread to be started.
thread | A pointer to a struct mtarch_thread for the thread to be started. |
function | A pointer to the function that the thread will start executing the first time it is scheduled to run. |
data | A pointer to the argument that the function should be passed. |
Referenced by mt_start().
void mtarch_stop | ( | struct mtarch_thread * | thread | ) |
Clean up the stack of a thread.
This function is called by the mt_stop() function in order to clean up the architecture specific stack of the thread to be stopped.
thread | A pointer to a struct mtarch_thread for the thread to be stopped. |
Referenced by mt_stop().
void mtarch_yield | ( | void | ) |
Yield the processor.
This function is called by the mt_yield() function, which is called from the running thread in order to give up the processor.
Referenced by mt_exit(), and mt_yield().