task #5
8
srv/task.c
Normal file
8
srv/task.c
Normal file
@ -0,0 +1,8 @@
|
||||
/** @file task.c
|
||||
* 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
|
||||
*/
|
||||
|
||||
52
srv/task.h
Normal file
52
srv/task.h
Normal file
@ -0,0 +1,52 @@
|
||||
/** @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 <stdint.h>
|
||||
|
||||
|
||||
//--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_
|
||||
|
||||
Loading…
Reference in New Issue
Block a user