TNeoKernel  v1.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
tn_tasks.h
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * TNeoKernel: real-time kernel initially based on TNKernel
4  *
5  * TNKernel: copyright © 2004, 2013 Yuri Tiomkin.
6  * PIC32-specific routines: copyright © 2013, 2014 Anders Montonen.
7  * TNeoKernel: copyright © 2014 Dmitry Frank.
8  *
9  * TNeoKernel was born as a thorough review and re-implementation of
10  * TNKernel. The new kernel has well-formed code, inherited bugs are fixed
11  * as well as new features being added, and it is tested carefully with
12  * unit-tests.
13  *
14  * API is changed somewhat, so it's not 100% compatible with TNKernel,
15  * hence the new name: TNeoKernel.
16  *
17  * Permission to use, copy, modify, and distribute this software in source
18  * and binary forms and its documentation for any purpose and without fee
19  * is hereby granted, provided that the above copyright notice appear
20  * in all copies and that both that copyright notice and this permission
21  * notice appear in supporting documentation.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE DMITRY FRANK AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY FRANK OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33  * THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  ******************************************************************************/
36 
37 /**
38  * \file
39  *
40  * Various task services: create, sleep, wake up, terminate, etc.
41  *
42  */
43 
44 #ifndef _TN_TASKS_H
45 #define _TN_TASKS_H
46 
47 /*******************************************************************************
48  * INCLUDED FILES
49  ******************************************************************************/
50 
51 #include "tn_sys.h"
52 #include "tn_list.h"
53 #include "tn_common.h"
54 
55 #include "tn_eventgrp.h"
56 #include "tn_dqueue.h"
57 #include "tn_fmem.h"
58 
59 
60 
61 #ifdef __cplusplus
62 extern "C" { /*}*/
63 #endif
64 
65 /*******************************************************************************
66  * PUBLIC TYPES
67  ******************************************************************************/
68 
69 /**
70  * Task state
71  */
73  /// This state should never be publicly available.
74  /// It may be stored in task_state only temporarily,
75  /// while some system service is in progress.
77  ///
78  /// Task is ready to run (it doesn't mean that it is running at the moment)
80  ///
81  /// Task is waiting. The reason of waiting can be obtained from
82  /// `task_wait_reason` field of the `struct TN_Task`.
83  ///
84  /// @see `enum #TN_WaitReason`
85  TN_TASK_STATE_WAIT = (1 << 1),
86  ///
87  /// Task is suspended (by some other task)
89  ///
90  /// Task was previously waiting, and after this it was suspended
92  ///
93  /// Task isn't yet activated or it was terminated by `tn_task_terminate()`.
95 };
96 
97 
98 /**
99  * Task wait reason
100  */
102  ///
103  /// task isn't waiting for anything
105  ///
106  /// task has called `tn_task_sleep()`
108  ///
109  /// task waits to acquire a semaphore
110  /// @see tn_sem.h
112  ///
113  /// task waits for some event in the event group to be set
114  /// @see tn_eventgrp.h
116  ///
117  /// task wants to put some data to the data queue, and there's no space
118  /// in the queue.
119  /// @see tn_dqueue.h
121  ///
122  /// task wants to receive some data to the data queue, and there's no data
123  /// in the queue
124  /// @see tn_dqueue.h
126  ///
127  /// task wants to lock a mutex with priority ceiling
128  /// @see tn_mutex.h
130  ///
131  /// task wants to lock a mutex with priority inheritance
132  /// @see tn_mutex.h
134  ///
135  /// task wants to get memory block from memory pool, and there's no free
136  /// memory blocks
137  /// @see tn_fmem.h
139 };
140 
141 /**
142  * Options for `tn_task_create()`
143  */
145  ///
146  /// whether task should be activated right after it is created.
147  /// If this flag is not set, user must activate task manually by calling
148  /// `tn_task_activate()`.
150  ///
151  /// for internal kernel usage only: this option must be provided
152  /// when creating idle task
154 };
155 
156 /**
157  * Options for `tn_task_exit()`
158  */
160  ///
161  /// whether task should be deleted right after it is exited.
162  /// If this flag is not set, user must either delete it manually by
163  /// calling `tn_task_delete()` or re-activate it by calling
164  /// `tn_task_activate()`.
166 };
167 
168 
169 /**
170  * Task
171  */
172 struct TN_Task {
173  /// pointer to task's current stack pointer;
174  /// Note that this field **must** be a first field in the struct,
175  /// this fact is exploited by platform-specific routines.
176  unsigned int *task_stk;
177  ///
178  /// queue is used to include task in ready/wait lists
179  struct TN_ListItem task_queue;
180  ///
181  /// queue is used to include task in timer list
182  struct TN_ListItem timer_queue;
183  ///
184  /// pointer to object's (semaphore, mutex, event, etc) wait list in which
185  /// task is included for waiting
186  struct TN_ListItem *pwait_queue;
187  ///
188  /// queue is used to include task in creation list
189  /// (currently, this list is used for statistics only)
190  struct TN_ListItem create_queue;
191 
192 #if TN_USE_MUTEXES
193  ///
194  /// list of all mutexes that are locked by task
195  struct TN_ListItem mutex_queue;
196 #if TN_MUTEX_DEADLOCK_DETECT
197  ///
198  /// list of other tasks involved in deadlock. This list is non-empty
199  /// only in emergency cases, and it is here to help you fix your bug
200  /// that led to deadlock.
201  ///
202  /// @see `#TN_MUTEX_DEADLOCK_DETECT`
203  struct TN_ListItem deadlock_list;
204 #endif
205 #endif
206 
207  /// base address of task's stack space
209  ///
210  /// size of task's stack (in `sizeof(unsigned int)`, not bytes)
211  int stk_size;
212  ///
213  /// pointer to task's body function given to `tn_task_create()`
215  ///
216  /// pointer to task's parameter given to `tn_task_create()`
218  ///
219  /// base priority of the task (actual current priority may be higher than
220  /// base priority because of mutex)
222  ///
223  /// current task priority
224  int priority;
225  ///
226  /// id for object validity verification
228  ///
229  /// task state
231  ///
232  /// reason for waiting (relevant if only `task_state` is
233  /// $(TN_TASK_STATE_WAIT) or $(TN_TASK_STATE_WAITSUSP))
235  ///
236  /// waiting result code (reason why waiting finished)
238  ///
239  /// remaining time until timeout; may be `#TN_WAIT_INFINITE`.
240  unsigned long tick_count;
241  ///
242  /// time slice counter
244  ///
245  /// subsystem-specific fields that are used while task waits for something.
246  /// Do note that these fields are grouped by union, so, they must not
247  /// interfere with each other. It's quite ok here because task can't wait
248  /// for different things.
249  union {
250  /// fields specific to tn_eventgrp.h
252  ///
253  /// fields specific to tn_dqueue.h
255  ///
256  /// fields specific to tn_fmem.h
258  } subsys_wait;
259 
260 #if TN_DEBUG
261  /// task name for debug purposes, user may want to set it by hand
262  const char *name;
263 #endif
264 
265  /// Internal flag used to optimize mutex priority algorithms.
266  /// For the comments on it, see file tn_mutex.c,
267  /// function `_mutex_do_unlock()`.
269 
270 
271 // Other implementation specific fields may be added below
272 
273 };
274 
275 
276 
277 /*******************************************************************************
278  * GLOBAL VARIABLES
279  ******************************************************************************/
280 
281 /*******************************************************************************
282  * DEFINITIONS
283  ******************************************************************************/
284 
285 /**
286  * Convenience macro for the definition of stack array. See
287  * `tn_task_create()` for the usage example.
288  *
289  * @param name
290  * C variable name of the array
291  * @param size
292  * size of the stack array in words (`#TN_UWord`), not in bytes.
293  */
294 #define TN_TASK_STACK_DEF(name, size) \
295  TN_ARCH_STK_ATTR_BEFORE \
296  TN_UWord name[ (size) ] \
297  TN_ARCH_STK_ATTR_AFTER
298 
299 
300 
301 /*******************************************************************************
302  * PUBLIC FUNCTION PROTOTYPES
303  ******************************************************************************/
304 
305 /**
306  * Construct task and probably start it (depends on options, see below).
307  * `id_task` member should not contain `#TN_ID_TASK`, otherwise,
308  * `#TN_RC_WPARAM` is returned.
309  *
310  * Usage example:
311  *
312  * \code{.c}
313  * #define MY_TASK_STACK_SIZE (TN_MIN_STACK_SIZE + 200)
314  * #define MY_TASK_PRIORITY 5
315  *
316  * struct TN_Task my_task;
317  *
318  * //-- define stack array, we use convenience macro TN_TASK_STACK_DEF()
319  * // for that
320  * TN_TASK_STACK_DEF(my_task_stack, MY_TASK_STACK_SIZE);
321  *
322  * void my_task_body(void *param)
323  * {
324  * //-- an endless loop
325  * for (;;){
326  * tn_task_sleep(1);
327  *
328  * //-- probably do something useful
329  * }
330  * }
331  * \endcode
332  *
333  *
334  *
335  * And then, somewhere from other task or from the callback
336  * `#TN_CBUserTaskCreate` given to `tn_sys_start()` :
337  * \code{.c}
338  * enum TN_RCode rc = tn_task_create(
339  * &my_task,
340  * my_task_body,
341  * MY_TASK_PRIORITY,
342  * my_task_stack,
343  * MY_TASK_STACK_SIZE,
344  * NULL, //-- parameter isn't used
345  * TN_TASK_CREATE_OPT_START //-- start task on creation
346  * );
347  *
348  * if (rc != TN_RC_OK){
349  * //-- handle error
350  * }
351  * \endcode
352  *
353  * $(TN_CALL_FROM_TASK)
354  * $(TN_LEGEND_LINK)
355  *
356  * @param task
357  * Ready-allocated `struct TN_Task` structure. `id_task` member should not
358  * contain `#TN_ID_TASK`, otherwise `#TN_RC_WPARAM` is returned.
359  * @param task_func
360  * Pointer to task body function.
361  * @param priority
362  * Priority for new task. **NOTE**: the lower value, the higher priority.
363  * Must be > `0` and < `(#TN_PRIORITIES_CNT - 1)`.
364  * @param task_stack_low_addr
365  * Pointer to the stack for task.
366  * User must either use the macro `TN_TASK_STACK_DEF()` for the definition
367  * of stack array, or allocate it manually as an array of `#TN_UWord` with
368  * `#TN_ARCH_STK_ATTR_BEFORE` and `#TN_ARCH_STK_ATTR_AFTER` macros.
369  * @param task_stack_size
370  * Size of task stack array, in words (`#TN_UWord`), not in bytes.
371  * @param param
372  * Parameter that is passed to `task_func`.
373  * @param opts
374  * Options for task creation, refer to `enum #TN_TaskCreateOpt`
375  *
376  * @return
377  * * `#TN_RC_OK` on success;
378  * * `#TN_RC_WCONTEXT` if called from wrong context;
379  * * `#TN_RC_WPARAM` if wrong params were given;
380  *
381  * @see `#TN_ARCH_STK_ATTR_BEFORE`
382  * @see `#TN_ARCH_STK_ATTR_AFTER`
383  */
385  struct TN_Task *task,
386  TN_TaskBody *task_func,
387  int priority,
388  TN_UWord *task_stack_low_addr,
389  int task_stack_size,
390  void *param,
391  enum TN_TaskCreateOpt opts
392  );
393 
394 
395 /**
396  * If the task is $(TN_TASK_STATE_RUNNABLE), it is moved to the
397  * $(TN_TASK_STATE_SUSPEND) state. If the task is in the $(TN_TASK_STATE_WAIT)
398  * state, it is moved to the $(TN_TASK_STATE_WAITSUSP) state. (waiting +
399  * suspended)
400  *
401  * $(TN_CALL_FROM_TASK)
402  * $(TN_CAN_SWITCH_CONTEXT)
403  * $(TN_LEGEND_LINK)
404  *
405  * @param task Task to suspend
406  *
407  * @return
408  * * `#TN_RC_OK` on success;
409  * * `#TN_RC_WCONTEXT` if called from wrong context;
410  * * `#TN_RC_WSTATE` if task is already suspended or dormant;
411  * * If `#TN_CHECK_PARAM` is non-zero, additional return codes
412  * are available: `#TN_RC_WPARAM` and `#TN_RC_INVALID_OBJ`.
413  *
414  * @see `enum #TN_TaskState`
415  */
416 enum TN_RCode tn_task_suspend(struct TN_Task *task);
417 
418 /**
419  * Release task from $(TN_TASK_STATE_SUSPEND) state. If the given task is in
420  * the $(TN_TASK_STATE_SUSPEND) state, it is moved to $(TN_TASK_STATE_RUNNABLE)
421  * state; afterwards it has the lowest precedence among runnable tasks with the
422  * same priority. If the task is in $(TN_TASK_STATE_WAITSUSP) state, it is
423  * moved to $(TN_TASK_STATE_WAIT) state.
424  *
425  * $(TN_CALL_FROM_TASK)
426  * $(TN_CAN_SWITCH_CONTEXT)
427  * $(TN_LEGEND_LINK)
428  *
429  * @param task Task to release from suspended state
430  *
431  * @return
432  * * `#TN_RC_OK` on success;
433  * * `#TN_RC_WCONTEXT` if called from wrong context;
434  * * `#TN_RC_WSTATE` if task is not suspended;
435  * * If `#TN_CHECK_PARAM` is non-zero, additional return codes
436  * are available: `#TN_RC_WPARAM` and `#TN_RC_INVALID_OBJ`.
437  *
438  * @see enum TN_TaskState
439  */
440 enum TN_RCode tn_task_resume(struct TN_Task *task);
441 
442 /**
443  * Put current task to sleep for at most timeout ticks. When the timeout
444  * expires and the task was not suspended during the sleep, it is switched to
445  * runnable state. If the timeout value is `#TN_WAIT_INFINITE` and the task was
446  * not suspended during the sleep, the task will sleep until another function
447  * call (like `tn_task_wakeup()` or similar) will make it runnable.
448  *
449  * $(TN_CALL_FROM_TASK)
450  * $(TN_CAN_SWITCH_CONTEXT)
451  * $(TN_CAN_SLEEP)
452  * $(TN_LEGEND_LINK)
453  *
454  * @param timeout
455  * Refer to `#TN_Timeout`
456  *
457  * @returns
458  * * `#TN_RC_TIMEOUT` if task has slept specified timeout;
459  * * `#TN_RC_OK` if task was woken up from other task by `tn_task_wakeup()`
460  * * `#TN_RC_FORCED` if task was released from wait forcibly by
461  * `tn_task_release_wait()`
462  * * `#TN_RC_WCONTEXT` if called from wrong context
463  *
464  * @see TN_Timeout
465  */
466 enum TN_RCode tn_task_sleep(TN_Timeout timeout);
467 
468 /**
469  * Wake up task from sleep.
470  *
471  * Task is woken up if only it sleeps because of call to `tn_task_sleep()`.
472  * If task sleeps for some another reason, task won't be woken up,
473  * and `tn_task_wakeup()` returns `#TN_RC_WSTATE`.
474  *
475  * After this call, `tn_task_sleep()` returns `#TN_RC_OK`.
476  *
477  * $(TN_CALL_FROM_TASK)
478  * $(TN_CAN_SWITCH_CONTEXT)
479  * $(TN_LEGEND_LINK)
480  *
481  * @param task sleeping task to wake up
482  *
483  * @return
484  * * `#TN_RC_OK` if successful
485  * * `#TN_RC_WSTATE` if task is not sleeping, or it is sleeping for
486  * some reason other than `tn_task_sleep()` call.
487  * * `#TN_RC_WCONTEXT` if called from wrong context;
488  * * If `#TN_CHECK_PARAM` is non-zero, additional return codes
489  * are available: `#TN_RC_WPARAM` and `#TN_RC_INVALID_OBJ`.
490  *
491  */
492 enum TN_RCode tn_task_wakeup(struct TN_Task *task);
493 
494 /**
495  * The same as `tn_task_wakeup()` but for using in the ISR.
496  *
497  * $(TN_CALL_FROM_ISR)
498  * $(TN_CAN_SWITCH_CONTEXT)
499  * $(TN_LEGEND_LINK)
500  */
501 enum TN_RCode tn_task_iwakeup(struct TN_Task *task);
502 
503 /**
504  * Activate task that is in $(TN_TASK_STATE_DORMANT) state, that is, it was
505  * either just created by `tn_task_create()` without
506  * `#TN_TASK_CREATE_OPT_START` option, or terminated.
507  *
508  * Task is moved from $(TN_TASK_STATE_DORMANT) state to the
509  * $(TN_TASK_STATE_RUNNABLE) state.
510  *
511  * $(TN_CALL_FROM_TASK)
512  * $(TN_CAN_SWITCH_CONTEXT)
513  * $(TN_LEGEND_LINK)
514  *
515  * @param task dormant task to activate
516  *
517  * @return
518  * * `#TN_RC_OK` if successful
519  * * `#TN_RC_WSTATE` if task is not dormant
520  * * `#TN_RC_WCONTEXT` if called from wrong context;
521  * * If `#TN_CHECK_PARAM` is non-zero, additional return codes
522  * are available: `#TN_RC_WPARAM` and `#TN_RC_INVALID_OBJ`.
523  *
524  * @see TN_TaskState
525  */
526 enum TN_RCode tn_task_activate(struct TN_Task *task);
527 
528 /**
529  * The same as `tn_task_activate()` but for using in the ISR.
530  *
531  * $(TN_CALL_FROM_ISR)
532  * $(TN_CAN_SWITCH_CONTEXT)
533  * $(TN_LEGEND_LINK)
534  */
535 enum TN_RCode tn_task_iactivate(struct TN_Task *task);
536 
537 /**
538  * Release task from $(TN_TASK_STATE_WAIT) state, independently of the reason
539  * of waiting.
540  *
541  * If task is in $(TN_TASK_STATE_WAIT) state, it is moved to
542  * $(TN_TASK_STATE_RUNNABLE) state. If task is in $(TN_TASK_STATE_WAITSUSP)
543  * state, it is moved to $(TN_TASK_STATE_SUSPEND) state.
544  *
545  * `#TN_RC_FORCED` is returned to the waiting task.
546  *
547  * $(TN_CALL_FROM_TASK)
548  * $(TN_CAN_SWITCH_CONTEXT)
549  * $(TN_LEGEND_LINK)
550  *
551  * \attention Usage of this function is discouraged, since the need for
552  * it indicates bad software design
553  *
554  * @param task task waiting for anything
555  *
556  * @return
557  * * `#TN_RC_OK` if successful
558  * * `#TN_RC_WSTATE` if task is not waiting for anything
559  * * `#TN_RC_WCONTEXT` if called from wrong context;
560  * * If `#TN_CHECK_PARAM` is non-zero, additional return codes
561  * are available: `#TN_RC_WPARAM` and `#TN_RC_INVALID_OBJ`.
562  *
563  *
564  * @see TN_TaskState
565  */
566 enum TN_RCode tn_task_release_wait(struct TN_Task *task);
567 
568 /**
569  * The same as `tn_task_release_wait()` but for using in the ISR.
570  *
571  * $(TN_CALL_FROM_ISR)
572  * $(TN_CAN_SWITCH_CONTEXT)
573  * $(TN_LEGEND_LINK)
574  */
575 enum TN_RCode tn_task_irelease_wait(struct TN_Task *task);
576 
577 /**
578  * This function terminates the currently running task. The task is moved to
579  * the $(TN_TASK_STATE_DORMANT) state.
580  *
581  * After exiting, the task may be either deleted by the `tn_task_delete()`
582  * function call or reactivated by the `tn_task_activate()` /
583  * `tn_task_iactivate()` function call. In this case task starts execution from
584  * beginning (as after creation/activation). The task will have the lowest
585  * precedence among all tasks with the same priority in the
586  * $(TN_TASK_STATE_RUNNABLE) state.
587  *
588  * If this function is invoked with `#TN_TASK_EXIT_OPT_DELETE` option set, the
589  * task will be deleted after termination and cannot be reactivated (needs
590  * recreation).
591  *
592  * $(TN_CALL_FROM_TASK)
593  * $(TN_CAN_SWITCH_CONTEXT)
594  * $(TN_LEGEND_LINK)
595  *
596  * @return
597  * Returns if only called from wrong context. Normally, it never returns
598  * (since calling task becomes terminated)
599  *
600  * @see `#TN_TASK_EXIT_OPT_DELETE`
601  * @see `tn_task_delete()`
602  * @see `tn_task_activate()`
603  * @see `tn_task_iactivate()`
604  */
605 void tn_task_exit(enum TN_TaskExitOpt opts);
606 
607 
608 /**
609  * This function is similar to `tn_task_exit()` but it terminates any task
610  * other than currently running one.
611  *
612  * After task is terminated, the task may be either deleted by the
613  * `tn_task_delete()` function call or reactivated by the `tn_task_activate()`
614  * / `tn_task_iactivate()` function call. In this case task starts execution
615  * from beginning (as after creation/activation). The task will have the
616  * lowest precedence among all tasks with the same priority in the
617  * $(TN_TASK_STATE_RUNNABLE) state.
618  *
619  * $(TN_CALL_FROM_TASK)
620  * $(TN_CAN_SWITCH_CONTEXT)
621  * $(TN_LEGEND_LINK)
622  *
623  * @param task task to terminate
624  *
625  * @return
626  * * `#TN_RC_OK` if successful
627  * * `#TN_RC_WSTATE` if task is already dormant
628  * * `#TN_RC_WCONTEXT` if called from wrong context;
629  * * If `#TN_CHECK_PARAM` is non-zero, additional return codes
630  * are available: `#TN_RC_WPARAM` and `#TN_RC_INVALID_OBJ`.
631  */
632 enum TN_RCode tn_task_terminate(struct TN_Task *task);
633 
634 /**
635  * This function deletes the task specified by the task. The task must be in
636  * the $(TN_TASK_STATE_DORMANT) state, otherwise `#TN_RC_WCONTEXT` will be
637  * returned.
638  *
639  * This function resets the `id_task` field in the task structure to 0 and
640  * removes the task from the system tasks list. The task can not be reactivated
641  * after this function call (the task must be recreated).
642  *
643  * $(TN_CALL_FROM_TASK)
644  * $(TN_LEGEND_LINK)
645  *
646  * @param task dormant task to delete
647  *
648  * @return
649  * * `#TN_RC_OK` if successful
650  * * `#TN_RC_WSTATE` if task is not dormant
651  * * `#TN_RC_WCONTEXT` if called from wrong context;
652  * * If `#TN_CHECK_PARAM` is non-zero, additional return codes
653  * are available: `#TN_RC_WPARAM` and `#TN_RC_INVALID_OBJ`.
654  *
655  */
656 enum TN_RCode tn_task_delete(struct TN_Task *task);
657 
658 /**
659  * Set new priority for task.
660  * If priority is 0, then task's base_priority is set.
661  *
662  * $(TN_CALL_FROM_TASK)
663  * $(TN_LEGEND_LINK)
664  *
665  * \attention this function is obsolete and will probably be removed
666  */
667 enum TN_RCode tn_task_change_priority(struct TN_Task *task, int new_priority);
668 
669 
670 
671 #ifdef __cplusplus
672 } /* extern "C" */
673 #endif
674 
675 #endif // _TN_TASKS_H
676 
677 
678 /*******************************************************************************
679  * end of file
680  ******************************************************************************/
681 
682 
enum TN_RCode tn_task_activate(struct TN_Task *task)
Activate task that is in DORMANT state, that is, it was either just created by tn_task_create() witho...
TN_WaitReason
Task wait reason.
Definition: tn_tasks.h:101
task wants to lock a mutex with priority inheritance
Definition: tn_tasks.h:133
const char * name
task name for debug purposes, user may want to set it by hand
Definition: tn_tasks.h:262
enum TN_RCode tn_task_release_wait(struct TN_Task *task)
Release task from WAIT state, independently of the reason of waiting.
enum TN_RCode tn_task_iwakeup(struct TN_Task *task)
The same as tn_task_wakeup() but for using in the ISR.
enum TN_RCode tn_task_terminate(struct TN_Task *task)
This function is similar to tn_task_exit() but it terminates any task other than currently running on...
Task is suspended (by some other task)
Definition: tn_tasks.h:88
enum TN_RCode tn_task_create(struct TN_Task *task, TN_TaskBody *task_func, int priority, TN_UWord *task_stack_low_addr, int task_stack_size, void *param, enum TN_TaskCreateOpt opts)
Construct task and probably start it (depends on options, see below).
int stk_size
size of task's stack (in sizeof(unsigned int), not bytes)
Definition: tn_tasks.h:211
Task.
Definition: tn_tasks.h:172
TN_RCode
Result code returned by kernel services.
Definition: tn_common.h:99
DQueue-specific fields related to waiting task, to be included in struct TN_Task. ...
Definition: tn_dqueue.h:115
TN_ObjId
Magic number for object validity verification.
Definition: tn_common.h:87
unsigned long TN_Timeout
The value representing maximum number of system ticks to wait.
Definition: tn_common.h:203
EventGrp-specific fields related to waiting task, to be included in struct TN_Task.
Definition: tn_eventgrp.h:123
enum TN_WaitReason task_wait_reason
reason for waiting (relevant if only task_state is WAIT or WAIT+SUSPEND)
Definition: tn_tasks.h:234
Task was previously waiting, and after this it was suspended.
Definition: tn_tasks.h:91
struct TN_ListItem timer_queue
queue is used to include task in timer list
Definition: tn_tasks.h:182
task wants to receive some data to the data queue, and there's no data in the queue ...
Definition: tn_tasks.h:125
Definitions used through the whole kernel.
enum TN_TaskState task_state
task state
Definition: tn_tasks.h:230
enum TN_RCode tn_task_delete(struct TN_Task *task)
This function deletes the task specified by the task.
Task is waiting.
Definition: tn_tasks.h:85
TN_TaskCreateOpt
Options for tn_task_create()
Definition: tn_tasks.h:144
struct TN_EGrpTaskWait eventgrp
fields specific to tn_eventgrp.h
Definition: tn_tasks.h:251
TN_UWord * stk_start
base address of task's stack space
Definition: tn_tasks.h:208
TN_TaskBody * task_func_addr
pointer to task's body function given to tn_task_create()
Definition: tn_tasks.h:214
int tslice_count
time slice counter
Definition: tn_tasks.h:243
enum TN_RCode tn_task_change_priority(struct TN_Task *task, int new_priority)
Set new priority for task.
struct TN_ListItem deadlock_list
list of other tasks involved in deadlock.
Definition: tn_tasks.h:203
enum TN_RCode tn_task_wakeup(struct TN_Task *task)
Wake up task from sleep.
TN_TaskState
Task state.
Definition: tn_tasks.h:72
This state should never be publicly available.
Definition: tn_tasks.h:76
Fixed memory blocks pool.
enum TN_RCode tn_task_suspend(struct TN_Task *task)
If the task is RUNNABLE, it is moved to the SUSPEND state.
void tn_task_exit(enum TN_TaskExitOpt opts)
This function terminates the currently running task.
whether task should be deleted right after it is exited.
Definition: tn_tasks.h:165
enum TN_RCode tn_task_irelease_wait(struct TN_Task *task)
The same as tn_task_release_wait() but for using in the ISR.
enum TN_RCode tn_task_resume(struct TN_Task *task)
Release task from SUSPEND state.
int base_priority
base priority of the task (actual current priority may be higher than base priority because of mutex)...
Definition: tn_tasks.h:221
Event group.
Task isn't yet activated or it was terminated by tn_task_terminate().
Definition: tn_tasks.h:94
unsigned long tick_count
remaining time until timeout; may be TN_WAIT_INFINITE.
Definition: tn_tasks.h:240
task has called tn_task_sleep()
Definition: tn_tasks.h:107
enum TN_ObjId id_task
id for object validity verification
Definition: tn_tasks.h:227
Task is ready to run (it doesn't mean that it is running at the moment)
Definition: tn_tasks.h:79
task wants to get memory block from memory pool, and there's no free memory blocks ...
Definition: tn_tasks.h:138
struct TN_DQueueTaskWait dqueue
fields specific to tn_dqueue.h
Definition: tn_tasks.h:254
int priority
current task priority
Definition: tn_tasks.h:224
enum TN_RCode tn_task_iactivate(struct TN_Task *task)
The same as tn_task_activate() but for using in the ISR.
struct TN_ListItem * pwait_queue
pointer to object's (semaphore, mutex, event, etc) wait list in which task is included for waiting ...
Definition: tn_tasks.h:186
struct TN_ListItem task_queue
queue is used to include task in ready/wait lists
Definition: tn_tasks.h:179
for internal kernel usage only: this option must be provided when creating idle task ...
Definition: tn_tasks.h:153
task wants to lock a mutex with priority ceiling
Definition: tn_tasks.h:129
struct TN_FMemTaskWait fmem
fields specific to tn_fmem.h
Definition: tn_tasks.h:257
Kernel system routines: system start, tick processing, time slice managing.
union TN_Task::@0 subsys_wait
subsystem-specific fields that are used while task waits for something.
task wants to put some data to the data queue, and there's no space in the queue. ...
Definition: tn_tasks.h:120
void( TN_TaskBody)(void *param)
Prototype for task body function.
Definition: tn_common.h:163
task waits to acquire a semaphore
Definition: tn_tasks.h:111
enum TN_RCode tn_task_sleep(TN_Timeout timeout)
Put current task to sleep for at most timeout ticks.
task isn't waiting for anything
Definition: tn_tasks.h:104
unsigned priority_already_updated
Internal flag used to optimize mutex priority algorithms.
Definition: tn_tasks.h:268
whether task should be activated right after it is created.
Definition: tn_tasks.h:149
void * task_func_param
pointer to task's parameter given to tn_task_create()
Definition: tn_tasks.h:217
FMem-specific fields related to waiting task, to be included in struct TN_Task.
Definition: tn_fmem.h:107
unsigned int TN_UWord
Unsigned integer type whose size is equal to the size of CPU register.
unsigned int * task_stk
pointer to task's current stack pointer; Note that this field must be a first field in the struct...
Definition: tn_tasks.h:176
task waits for some event in the event group to be set
Definition: tn_tasks.h:115
A data queue is a FIFO that stores pointer (of type void *) in each cell, called (in uITRON style) a ...
struct TN_ListItem create_queue
queue is used to include task in creation list (currently, this list is used for statistics only) ...
Definition: tn_tasks.h:190
TN_TaskExitOpt
Options for tn_task_exit()
Definition: tn_tasks.h:159
enum TN_RCode task_wait_rc
waiting result code (reason why waiting finished)
Definition: tn_tasks.h:237
struct TN_ListItem mutex_queue
list of all mutexes that are locked by task
Definition: tn_tasks.h:195