Chris O'Byrne - YAVRTOS

task.h File Reference


Data Structures

struct  semaphore_t
 Structure describing a semaphore. More...
struct  mailbox_t
 Structure describing mailboxes. More...
struct  task_t
 Structure describing a task. More...
struct  mutex_t
 A structure describing a mutex. More...
struct  system_struct
 

For internal use only.

Structure used by the system to hold the system stack, and a flag indicating whether an ISR is currently being executed.

More...

Defines

#define interrupt_store_t   uint8_t
 A flag indicating whether interrupts were enabled - used by disable_interrupts() and restore_interrupts().
#define save_cpu_context()
 

For internal use only.

Save the CPU context to the stack, and disable interrupts


#define restore_cpu_context()
 

For internal use only.

Restore the CPU context from the stack, possibly re-enabling interrupts


#define TASK_ISR(vector, do_task_switch)
 The macro for ISRs.

Functions

task_treserve_task (uint16_t stacklen, uint8_t pri, mutex_t *memory_mutex)
 Tasks are kept in a linked list in memory - this function reserves an "empty" task on that list, ready to be subsequently utilised by a call to create_task().
task_tcreate_task (void(*proc)(void *), void(*cleanup)(), void *init_data, uint16_t stacklen, uint8_t pri, mutex_t *memory_mutex)
 Create a task, ready to be run.
int8_t stop_task (task_t *t, uint8_t wait_for_mutexes)
 Stop a task.
void yield () __attribute__((naked))
 Stop executing the current task and try and execute a higher-priority task or another task of the same priority.
uint8_t lock_on (mutex_t *m)
 Lock on a mutex.
uint8_t lock_off (mutex_t *m)
 Unlock a mutex.
int16_t get_current_mbox_version (mailbox_t *mbox)
 Get the current version of a mailbox.
void * read_mbox_min_version (mailbox_t *mbox, int16_t *version)
 Wait for a mailbox to reach at least a certain version, and then start reading from it.
void * read_mbox (mailbox_t *mbox, int16_t *version)
 Read a mailbox.
mailbox_trelease_mbox_read ()
 Function to call when finished reading from a mailbox.
void initialise_mbox (mailbox_t *mbox, void *data, const int16_t version)
 Initialise a mailbox - this must be called on every mailbox before it is used.
void write_mbox (mailbox_t *mbox, void *data, uint8_t wait_for_receivers, uint8_t wait_for_empty_nullify)
 Write to a mailbox.
int8_t write_mbox_now (mailbox_t *mbox, void *data)
 Attempt to write to a mailbox.
void wait_for_receiver (mailbox_t *mbox)
 Wait for a task to be suspended while trying to read from a mailbox.
uint8_t wait_for_min_value (semaphore_t *s, int16_t value)
 Wait for a semaphore to reach at least a particular value.
uint8_t wait_for_increment_of (semaphore_t *p, uint16_t amount)
 Wait for a semaphore to increment its value by a certain amount.
int16_t get_semaphore_value (semaphore_t *s)
 Get the current value of a semaphore.
void increment_semaphore_by (semaphore_t *s, uint16_t amount)
 Increment the value of a semaphore by the given amount.
void task_switcher_start (void(*idle)(void *), void *idle_data, uint16_t idle_stacklen, uint16_t system_stacklen) __attribute__((naked))
 Start the whole process running.
interrupt_store_t disable_interrupts ()
 Disable interrupts system-wide.
void restore_interrupts (interrupt_store_t interrupts)
 Restore the state of the system-wide interrupts.
void switch_task () __attribute__((naked))
 

For internal use only.

Perform a task switch



Variables

task_tcurrent_task
 The current task.
struct system_struct system
 

For internal use only.

The system_struct used to hold the system stack and a flag indicating whether an ISR is currently being executed



Define Documentation

 
#define restore_cpu_context (  ) 

Value:

__asm__ volatile ( \
                "pop r0\n" \
                "pop r31\n pop r30\n pop r29\n pop r28\n pop r27\n pop r26\n pop r25\n pop r24\n" \
                "pop r23\n pop r22\n pop r21\n pop r20\n pop r19\n pop r18\n pop r17\n pop r16\n" \
                "pop r15\n pop r14\n pop r13\n pop r12\n pop r11\n pop r10\n pop  r9\n pop  r8\n" \
                "pop  r7\n pop  r6\n pop  r5\n pop  r4\n pop  r3\n pop  r2\n pop  r1\n out 0x3f, r0\n pop  r0\n" ::)

For internal use only.

Restore the CPU context from the stack, possibly re-enabling interrupts

 
#define save_cpu_context (  ) 

Value:

__asm__ volatile( \
                "push  r0\n in r0, 0x3f\n cli\n" \
                "push  r1\n push  r2\n push  r3\n push  r4\n push  r5\n push  r6\n push  r7\n" \
                "push  r8\n push  r9\n push r10\n push r11\n push r12\n push r13\n push r14\n push r15\n" \
                "push r16\n push r17\n push r18\n push r19\n push r20\n push r21\n push r22\n push r23\n" \
                "push r24\n push r25\n push r26\n push r27\n push r28\n push r29\n push r30\n push r31\n" \
                "push  r0\n" ::)

For internal use only.

Save the CPU context to the stack, and disable interrupts


Function Documentation

void switch_task (  ) 

For internal use only.

Perform a task switch

Note that interrupts must be disabled before we enter, and the stack pointer should be set up to use the system stack.


Variable Documentation

For internal use only.

The system_struct used to hold the system stack and a flag indicating whether an ISR is currently being executed


YAVRTOS and YAVRTOS documentation Copyright © 2007-2008 Chris O'Byrne. Email - chris <at> obyrne <dot> com