Contiki 2.6

Architecture support for multi-threading

The Contiki multi-threading library requires some architecture specific support for setting up and switching stacks. More...

Files

file  mt.h
 

Header file for the preemptive multitasking library for Contiki.


Functions

void mtarch_init (void)
 Initialize the architecture specific support functions for the multi-thread library.
void mtarch_remove (void)
 Uninstall library and clean up.
void mtarch_start (struct mtarch_thread *thread, void(*function)(void *data), void *data)
 Setup the stack frame for a thread that is being started.
void mtarch_exec (struct mtarch_thread *thread)
 Start executing a thread.
void mtarch_yield (void)
 Yield the processor.
void mtarch_stop (struct mtarch_thread *thread)
 Clean up the stack of a thread.

Detailed Description

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.


Function Documentation

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.

Parameters:
threadA pointer to a struct mtarch_thread for the thread to be executed.

Definition at line 128 of file mtarch.c.

References NULL.

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.

Definition at line 46 of file mtarch.c.

References NULL.

Referenced by mt_init().

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.

Parameters:
threadA pointer to a struct mtarch_thread for the thread to be started.
functionA pointer to the function that the thread will start executing the first time it is scheduled to run.
dataA pointer to the argument that the function should be passed.

Definition at line 60 of file mtarch.c.

References NULL.

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.

Note:
If the stack is wholly contained in struct mtarch_thread this function may very well be empty.
Parameters:
threadA pointer to a struct mtarch_thread for the thread to be stopped.

Definition at line 160 of file mtarch.c.

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.

Definition at line 142 of file mtarch.c.

References NULL.

Referenced by mt_exit(), and mt_yield().