uTask 0.3.3
Defines | Functions | Variables

utask.c File Reference

#include <stdint.h>
#include "utask.h"

Defines

#define utask_wait_nzero(utask, sem, timeout)   utask_wait_neq(utask, sem, 0, timeout)
#define utask_wait_zero(utask, sem, timeout)   utask_wait_eq(utask, sem, 0, timeout)

Functions

void utask_init ()
 Intializes internal variables. Must be run before all other utask functions.
void utask_sleep (utask_t *t, utask_timer_t ticks)
 Sleep task t for ticks ticks of clock.
utask_tutask_add_name (utask_fun fun, const char *name)
 Add new task with function function and name name for execution.
utask_tutask_add (utask_fun fun)
 Add new task with function function for execution.
utask_data_t utask_check_sleep ()
void utask_schedule ()
 Scheduling function, must be called forever.
void utask_sleep_process ()
 Timekeeping function, should be called from ISR.
void utask_exit (utask_t *t)
 Terminate task t.
void utask_wait_eq (utask_t *t, utask_sem_t *sem, utask_sem_t sem_val, utask_timer_t timeout)
 Wait for the semaphore sem value to be set to sem_value with timeout ticks of timeout.
void utask_wait_neq (utask_t *t, utask_sem_t *sem, utask_sem_t sem_val, utask_timer_t timeout)
 Wait for the semaphore sem value to be changed from sem_value with timeout ticks of timeout.
void utask_suspend (utask_t *t)
 Suspend task exectuion.
void utask_resume (utask_t *t)
 Resume task t.
utask_data_t utask_get_free_slots (void)
 Returns free task slots.
utask_data_t utask_get_task_cnt (utask_fun fun)
 Function returns number of tasks executing fun function.
utask_tutask_get_by_tid (utask_data_t tid)
 Returns task structure pointer by task id.

Variables

void(* utask_put_mcu_to_sleep )(utask_data_t d) = (void*)0

Detailed Description

Authors:
B.Bielawski - InventLab, Marcin Zapolski - InventLab
Date:
2010.02.28
Version:
0.3.3

Function Documentation

utask_t* utask_add ( utask_fun  fun)

Add new task with function function for execution. Can be one of two versions:

After add is called following structure members are set to as follows:

  • state is set to UTS_READY and task will be executed as soon as possible,
  • istate is set to zero,
  • sleep is set to zero,
  • arg (if enabled) is set to zero,
  • tid (if enabled) is last task's id + 1,
  • not mentioned members are in undefined state.
Parameters:
funpointer to function to be executed
Returns:
pointer to task structure describing task of NULL in case of error
Examples:
utask_example_1.c, utask_example_2.c, utask_example_3.c, and utask_example_4.c.
utask_t* utask_add_name ( utask_fun  fun,
const char *  name 
)

Add new task with function function and name name for execution. This is simple wrapper. See utask_add() for details.

Parameters:
funpointer to function to be executed
namename of the task
Returns:
pointer to task structure describing task of NULL in case of error
void utask_exit ( utask_t t)

Ends task t. utask_exit() can terminate other tasks. Do not reference t after it has been freed with utask_exit().

Parameters:
tpointer to utask structure
Examples:
utask_example_2.c.
utask_t* utask_get_by_tid ( utask_data_t  tid)

Returns task structure pointer by task id.

Parameters:
tidtask id
Returns:
pointer to the task structure or NULL if not found
utask_data_t utask_get_free_slots ( void  )

Returns free task slots.

Returns:
free task slots
utask_data_t utask_get_task_cnt ( utask_fun  fun)

Function returns number of tasks executing fun function.

Parameters:
funfunction
Returns:
numbers of tasks executing fun function.
void utask_init ( void  )

Intializes internal variables. Must be run before all other utask functions.

Returns:
nothing
Examples:
utask_example_1.c, utask_example_2.c, utask_example_3.c, and utask_example_4.c.
void utask_resume ( utask_t t)

Resume task t. It works on both on tasks put to sleep and suspended.

Parameters:
tpointer to utask structure
void utask_schedule ( void  )

Scheduling function, must be called forever (e.g. in main() in while(1) {} loop) or utask will not work!

Returns:
nothing
Examples:
utask_example_1.c, utask_example_2.c, utask_example_3.c, and utask_example_4.c.
void utask_sleep ( utask_t t,
utask_timer_t  ticks 
)

Sleep task t for ticks ticks of clock. This function can put to sleep another task.

Parameters:
tpointer to utask structure
ticksnumber of ticks of clock for task to sleep
Examples:
utask_example_1.c, utask_example_2.c, and utask_example_3.c.
void utask_sleep_process ( void  )

Function decreasing tasks' sleep timers. Must be called periodically (e.g. from timer ISR) or utask_sleep() and utask_wait_*() will not work properly! Calling frequency selects timeout tick resolution. Calling this function at 1kHz rate gives you tick equal to 1 ms. Call this function as often (or as rarely) as you need.

Returns:
nothing
Examples:
utask_example_1.c, utask_example_2.c, utask_example_3.c, and utask_example_4.c.
void utask_suspend ( utask_t t)

Suspend task exectuion. This function can suspend another task.

Parameters:
tpointer to utask structure
void utask_wait_eq ( utask_t t,
utask_sem_t sem,
utask_sem_t  sem_val,
utask_timer_t  timeout 
)

Wait for the semaphore sem value to be set to sem_value with timeout ticks of timeout. If contidion was met t->sleep != 0.

Parameters:
tpointer to utask structure
sempointer to semaphore
sem_valvalue waited for
timeoutwaiting timeout
Returns:
nothing
void utask_wait_neq ( utask_t t,
utask_sem_t sem,
utask_sem_t  sem_val,
utask_timer_t  timeout 
)

Wait for the semaphore sem value to be changed from sem_value with timeout ticks of timeout. If contidion was met t->sleep != 0.

Parameters:
tpointer to utask structure
sempointer to semaphore
sem_valvalue waited for
timeoutwaiting timeout
Returns:
nothing