From fb1c11132f55d01563781f471157b7df7b233a58 Mon Sep 17 00:00:00 2001 From: Steins7 Date: Sun, 28 Apr 2024 19:14:28 +0200 Subject: [PATCH] Write first API macros --- srv/task.c | 8 ++++++++ srv/task.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 srv/task.c create mode 100644 srv/task.h diff --git a/srv/task.c b/srv/task.c new file mode 100644 index 0000000..4a2221d --- /dev/null +++ b/srv/task.c @@ -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 + */ + diff --git a/srv/task.h b/srv/task.h new file mode 100644 index 0000000..f91b782 --- /dev/null +++ b/srv/task.h @@ -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 + + +//--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_ +