| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #ifndef CX_ZIVUOS_KERNEL_H_INCLUDED
- #define CX_ZIVUOS_KERNEL_H_INCLUDED
- #include <stdint.h>
- #include <stdbool.h>
- #include "zv_types.h"
- #include "task.h"
- #include "idle.h"
- /**
- * @brief That return number of tasks from tasks array (x for zv_task_t [x]).
- * Usefull for zv_kernel_init.
- *
- * @param X Tasks stack.
- * @return Tasks count on tasks stack.
- */
- #define ZV_COUNT_TASKS(X) (sizeof(X) / sizeof(zv_task_t))
- /**
- * @brief That is main kernel structure. Do not modify without API.
- *
- * It store pointer to tasks stack, size of that stack and idle worker.
- */
- typedef struct zv_kernel_s {
-
- /** Pointer to tasks stack. */
- zv_task_t *tasks;
- /** Size of tasks stack. */
- zv_tid_t tasks_count;
- /** That is idle worker. By default do nothing. Could be replaced. */
- zv_idle_worker_t idle_worker;
- } zv_kernel_t;
- /**
- * @brief That initialize kernel structure.
- *
- * That function initialize kernel structure. It must be called to initialize
- * kernel.
- * Kernel initialization require tasks stack and kernel structure which is
- * NULL pointers, and tasks stack count which must be greater than 0.
- *
- * @param self Pointer to kernel structure to work on.
- * @param tasks Pointer to tasks stack.
- * @param count Number of tasks slots on stack.
- * @return True when kernel initialize success, false if cannot initialize it.
- */
- bool zv_kernel_init(zv_kernel_t *self, zv_task_t *tasks, zv_tid_t count);
- /**
- * @brief That boot OS. It return when task stack is empty.
- *
- * That is main kernel loop. By default it would not return.
- * It could be break only when tasks stack is empty, or when any task
- * raise error.
- *
- * @return True when everything is executed, and all tasks had been killed.
- * False when something went wrong.
- */
- bool zv_kernel_boot(zv_kernel_t *self);
- /**
- * @brief That function create process.
- *
- * That function create process, require process worker, process priority
- * and process param. Process param is pointer to any data or number as
- * intptr_r or uintptr_t. It return task ID or ZV_TID_NULL when can not
- * create process. Process creation fails when worker is NULL pointer or
- * when tasks stack is full.
- *
- * @param self Kernel to work on.
- * @param worker Worker of the process.
- * @param priority Priority of the process. Greater number is bigger priority.
- * @param param Param of the process.
- * @return Task ID on success, ZV_TID_NULL on fail.
- */
- zv_tid_t zv_kernel_create_process(
- zv_kernel_t *self,
- zv_worker_t worker,
- zv_priority_t priority,
- void *param
- );
- /**
- * @brief That function kill process.
- *
- * That function kill process. Process can not being killed when not exists.
- *
- * @param self Kernel to work on.
- * @param target Task ID of task to kill.
- * @return True when task killed successfull, false when failed.
- */
- bool zv_kernel_kill_process(
- zv_kernel_t *self,
- zv_tid_t target
- );
- /**
- * That function return first empty slot TID or ZV_TID_NULL when tasks stack
- * is full.
- *
- * @param self Kernel to work on.
- * @return First empty task slot TID or ZV_TID_NULL when tasks stack is full.
- */
- zv_tid_t __zv_kernel_get_empty_slot(zv_kernel_t *self);
- /**
- * That function return pointer to task based on task ID.
- *
- * @param self Kernel to work on.
- * @param target Task ID to get pointer.
- * @return Pointer to task with given ID or NULL when task slot not exists.
- */
- zv_task_t * __zv_kernel_get_task(zv_kernel_t *self, zv_tid_t target);
- /**
- * That function return task ID based on pointer to task on task stack.
- *
- * @param self Kernel to work on.
- * @param target Pointer to task.
- * @return Task ID of that task.
- */
- zv_tid_t __zv_kernel_get_tid(zv_kernel_t *self, zv_task_t *target);
- #endif
|