/** @file task.h * Module handling the task creation and management * * The module provides an API to create, run and manage lightweight, stack-less * threads (tasks). This system is based on protothreads, * see https://dunkels.com/adam/pt/index.html */ #ifndef _task_h_ #define _task_h_ //--includes-------------------------------------------------------------------- #include //--functions------------------------------------------------------------------- #define TASK(fct_name) uint8_t fct_name(uint8_t __task_context) #define task_begin() do { \ _TASK_COUNT_INIT; \ switch (__task_context) { \ } while (0) #define task_end() do { \ } \ return _TASK_COUNT_STOP; \ while (0) #define task_wait_until(cond) _task_wait_until(cond, _TASK_COUNT_INCR) //--internal_functions---------------------------------------------------------- #define _TASK_COUNT_INIT enum { TASK_COUNTER_BASE = __COUNTER__ } #define _TASK_COUNT_INCR (uint8_t)(__COUNTER__ - TASK_COUNTER_BASE - 1) #define _TASK_COUNT_STOP UINT8_MAX #define _task(fct_name) #define _task_wait_until(cond, count) do { \ case (count): \ if (!(cond)) { \ return count; \ } \ /* fall through */ \ while (0) #endif //_task_h_