Threading
[Kernel API]


Data Structures

struct  thread_s
 Thread structure definition. More...

Defines

#define MAX_THREADS   10
 Maximum number of allowed threads.
#define IDLE_STACK_SIZE   256
 Size of stack for initial/idle thread.
#define START_STACK_SIZE   128
 Size of stack for start thread.
#define MSECS_PER_SLEEP_TICK   31
 The msec period of a single prescaled sleep clock tick.
#define SLEEP_TICK_OVERFLOW   4
 MSECS_PER_SLEEP_TICK should really be 31.25 Divide your number by SLEEP_TICK_OVERFLOW and add it to the result for more precise math.
#define MSECS_MAX_SLEEP   8000
 The msec period of the maximum sleep time (256 * 32).
#define STACK_MIN   MIN_STACK_SIZE
 Minimum stack size.
#define STACK_SMALL   STACK_MIN * 2
 Small stack size.
#define STACK_MEDIUM   STACK_MIN * 3
 Medium stack size.
#define STACK_LARGE   STACK_MIN * 4
 Large stack size.
#define HEAP_TOP   MEMORY_BASE + (MEMORY_SIZE - IDLE_STACK_SIZE)
 Address just past top of heap.
#define THREAD_OK   0
 Thread returns ok.
#define NO_MORE_THREADS   1
 Thread manager has no more threads left.
#define NO_MORE_MEMORY   2
 Thread manager has run out of memory.
#define BAD_THREAD_PRIORITY   3
 Bad thread priority specified.
#define CONTEXT_SWITCH_DISABLED   0
 State that disables context switching.
#define CONTEXT_SWITCH_ENABLED   1
 State that enables context switching.
#define mos_thread_set_suspend_state(state)   _current_thread->suspend_state = state
 Set the suspend state of the current running thread this is the minimum sleep state allowed by the active thread.
#define mos_thread_get_suspend_state()   _current_thread->suspend_state
 Get the suspend state of the current running thread.
#define mos_thread_get_port()   _current_thread->port
 Get the port the current thread will block on.
#define mos_thread_set_port(port)   _current_thread->port = port
 Set the port the current thread is blocked on.
#define mos_thread_suspend()   mos_thread_suspend_state (SUSPEND_STATE_IDLE);
 Block the currently running thread.
#define mos_thread_current()   _current_thread
 Get a pointer to the currently executing thread.

Typedefs

typedef thread_s mos_thread_t
 Thread structure definition.

Enumerations

enum  {
  EMPTY = 0,
  RUNNING,
  READY,
  BLOCKED,
  SLEEPING
}
 Thread states. More...
enum  {
  PRIORITY_KERNEL = 0,
  PRIORITY_SLEEP,
  PRIORITY_HIGH,
  PRIORITY_NORMAL,
  PRIORITY_IDLE,
  NUM_PRIORITIES
}
 Thread priorities. More...
enum  {
  SUSPEND_STATE_IDLE = 0,
  SUSPEND_STATE_SLEEP,
  SUSPEND_STATE_MAX
}
 Suspend states. More...

Functions

void sched_init (void)
void mos_sched_start (void)
uint8_t mos_thread_new (void(*function_start)(void), memtype_t stack_size, uint8_t priority)
 Create a new thread and put it on the ready queue.
uint8_t mos_thread_new_havestack (void(*function_start)(void), memtype_t stack_size, stackval_t *stack_addr, uint8_t priority)
 Create a new thread with the given stack and put it on the ready queue.
void mos_thread_exit (void)
 Terminate the calling thread.
void mos_thread_suspend_state (uint8_t state)
 Suspend to a specific state.
void mos_thread_resume (mos_thread_t *thread)
 Resume a blocked thread.
void mos_thread_sleep (uint32_t sleeptime)
 Put the currently running thread to sleep. Units are in ms Minimum sleeptime is 128 ms (will be promoted).
void mos_single_threaded (void)
 Put the kernel in single-threaded operation mode.
void mos_multi_threaded (void)
 Put the kernel in multi-threaded operation mode.
int context_switch_enabled (void)
 Return whether context switching is enabled or not.
int mos_check_sleep_time (uint8_t sleep_time)
 Enable interrupts if we are not nested in another disable_ints call. Disable interrupts.

Detailed Description

This group contains functions, structures and values related to creating and managing threads.

Define Documentation

 
#define mos_thread_current  )     _current_thread
 

Returns:
Currently running thread

Definition at line 270 of file msched.h.


Enumeration Type Documentation

anonymous enum
 

Enumerator:
EMPTY  Thread is empty.
RUNNING  Thread is running.
READY  Thread will run at next opportunity.
BLOCKED  Thread is blocked.
SLEEPING  Thread is sleeping.

Definition at line 63 of file msched.h.

00063      {
00065    EMPTY = 0,
00067    RUNNING,
00069    READY,
00071    BLOCKED,
00073    SLEEPING
00074 };

anonymous enum
 

Enumerator:
PRIORITY_KERNEL  Kernel level priority.
PRIORITY_SLEEP  Sleep level priority.
PRIORITY_HIGH  High level priority, pre-empts everything.
PRIORITY_NORMAL  Normal level priority.
PRIORITY_IDLE  Idle priority.
NUM_PRIORITIES  Total number of priorities.

Definition at line 106 of file msched.h.

00106      {
00108    PRIORITY_KERNEL = 0,
00110    PRIORITY_SLEEP,
00112    PRIORITY_HIGH,
00114    PRIORITY_NORMAL,
00116    PRIORITY_IDLE,
00118    NUM_PRIORITIES
00119 };

anonymous enum
 

Enumerator:
SUSPEND_STATE_IDLE  Thread is not waiting on interrupts, ok to sleep.
SUSPEND_STATE_SLEEP  Thread needs an interrupt, do not sleep.
SUSPEND_STATE_MAX  Total number of suspend states.

Definition at line 122 of file msched.h.

00122      {
00124    SUSPEND_STATE_IDLE = 0,
00126    SUSPEND_STATE_SLEEP,
00128    SUSPEND_STATE_MAX
00129 };


Function Documentation

int mos_check_sleep_time uint8_t  sleep_time  ) 
 

Returns:
Interrupt handle (use with mos_enable_ints)

void mos_sched_start void   ) 
 

For internal use only.

Start scheduling threads.

Must add thread(s) before calling start. (NOTE: This function never returns.)

uint8_t mos_thread_new void(*)(void)  function_start,
memtype_t  stack_size,
uint8_t  priority
 

Note: There is no memory protection so watch your stack sizes.

Parameters:
function_start Pointer to function to call on thread start
stack_size Stack space to give the thread. If the specified stack size is smaller than MIN_STACK_SIZE, MIN_STACK_SIZE will be used instead.
priority Priority of the thread
Returns:
THREAD_OK, NO_MORE_THREADS, NO_MORE_MEMORY, BAD_THREAD_PRIORITY

uint8_t mos_thread_new_havestack void(*)(void)  function_start,
memtype_t  stack_size,
stackval_t stack_addr,
uint8_t  priority
 

Note: There is no memory protection so watch your stack sizes. Also, this thread should not exit, or the memory allocator will try to free the stack.

Parameters:
function_start Pointer to function to call on thread start
stack_size Size of the thread's stack
stack_addr Stack space that you have already allocated
priority Priority of the thread
Returns:
THREAD_OK, NO_MORE_THREADS, NO_MORE_MEMORY, BAD_THREAD_PRIORITY

void mos_thread_resume mos_thread_t thread  ) 
 

Parameters:
thread Thread to resume

void mos_thread_suspend_state uint8_t  state  ) 
 

Parameters:
state the state to suspend to

void sched_init void   ) 
 

For internal use only.

Init the scheduler.

Must call this before adding any threads.


Generated on Mon Nov 23 06:26:00 2009 for MANTIS by  doxygen 1.4.6