TNeo  BETA v1.08-11-g97e5a6d
tn_sys.h
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * TNeo: 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  * TNeo: copyright 2014 Dmitry Frank.
8  *
9  * TNeo 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: TNeo.
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  * Kernel system routines: system start, tick processing, time slice managing.
41  *
42  */
43 
44 #ifndef _TN_SYS_H
45 #define _TN_SYS_H
46 
47 
48 
49 /*******************************************************************************
50  * INCLUDED FILES
51  ******************************************************************************/
52 
53 #include "tn_list.h"
54 #include "../arch/tn_arch.h"
55 #include "tn_cfg_dispatch.h"
56 
57 #include "tn_timer.h"
58 
59 
60 
61 #ifdef __cplusplus
62 extern "C" { /*}*/
63 #endif
64 
65 /*******************************************************************************
66  * EXTERNAL TYPES
67  ******************************************************************************/
68 
69 struct TN_Task;
70 struct TN_Mutex;
71 
72 
73 
74 /*******************************************************************************
75  * DEFINITIONS
76  ******************************************************************************/
77 
78 /**
79  * Convenience macro for the definition of stack array. See
80  * `tn_task_create()` for the usage example.
81  *
82  * @param name
83  * C variable name of the array
84  * @param size
85  * size of the stack array in words (`#TN_UWord`), not in bytes.
86  */
87 #define TN_STACK_ARR_DEF(name, size) \
88  TN_ARCH_STK_ATTR_BEFORE \
89  TN_UWord name[ (size) ] \
90  TN_ARCH_STK_ATTR_AFTER
91 
92 
93 #if TN_CHECK_BUILD_CFG
94 
95 /**
96  * For internal kernel usage: helper macro that fills architecture-dependent
97  * values. This macro is used by `#_TN_BUILD_CFG_STRUCT_FILL()` only.
98  */
99 #if defined (__TN_ARCH_PIC24_DSPIC__)
100 
101 # define _TN_BUILD_CFG_ARCH_STRUCT_FILL(_p_struct) \
102 { \
103  (_p_struct)->arch.p24.p24_sys_ipl = TN_P24_SYS_IPL; \
104 }
105 
106 #else
107 # define _TN_BUILD_CFG_ARCH_STRUCT_FILL(_p_struct)
108 #endif
109 
110 
111 
112 
113 /**
114  * For internal kernel usage: fill the structure `#_TN_BuildCfg` with
115  * current build-time configuration values.
116  *
117  * @param _p_struct Pointer to struct `#_TN_BuildCfg`
118  */
119 #define _TN_BUILD_CFG_STRUCT_FILL(_p_struct) \
120 { \
121  memset((_p_struct), 0x00, sizeof(*(_p_struct))); \
122  \
123  (_p_struct)->priorities_cnt = TN_PRIORITIES_CNT; \
124  (_p_struct)->check_param = TN_CHECK_PARAM; \
125  (_p_struct)->debug = TN_DEBUG; \
126  (_p_struct)->use_mutexes = TN_USE_MUTEXES; \
127  (_p_struct)->mutex_rec = TN_MUTEX_REC; \
128  (_p_struct)->mutex_deadlock_detect = TN_MUTEX_DEADLOCK_DETECT; \
129  (_p_struct)->tick_lists_cnt_minus_one = (TN_TICK_LISTS_CNT - 1); \
130  (_p_struct)->api_make_alig_arg = TN_API_MAKE_ALIG_ARG; \
131  (_p_struct)->profiler = TN_PROFILER; \
132  (_p_struct)->profiler_wait_time = TN_PROFILER_WAIT_TIME; \
133  (_p_struct)->stack_overflow_check = TN_STACK_OVERFLOW_CHECK; \
134  (_p_struct)->dynamic_tick = TN_DYNAMIC_TICK; \
135  (_p_struct)->old_events_api = TN_OLD_EVENT_API; \
136  \
137  _TN_BUILD_CFG_ARCH_STRUCT_FILL(_p_struct); \
138 }
139 
140 
141 #else
142 
143 #define _TN_BUILD_CFG_STRUCT_FILL(_p_struct) /* nothing */
144 
145 #endif // TN_CHECK_BUILD_CFG
146 
147 
148 /**
149  * For internal kernel usage: helper macro that allows functions to be inlined
150  * or not depending on configuration (see `#TN_MAX_INLINE`)
151  */
152 #if TN_MAX_INLINE
153 # define _TN_MAX_INLINED_FUNC _TN_STATIC_INLINE
154 #else
155 # define _TN_MAX_INLINED_FUNC /* nothing */
156 #endif
157 
158 
159 
160 /*******************************************************************************
161  * PUBLIC TYPES
162  ******************************************************************************/
163 
164 /**
165  * Structure with build-time configurations values; it is needed for run-time
166  * check which ensures that build-time options for the kernel match ones for
167  * the application. See `#TN_CHECK_BUILD_CFG` for details.
168  */
169 struct _TN_BuildCfg {
170  ///
171  /// Value of `#TN_PRIORITIES_CNT`
172  unsigned priorities_cnt : 7;
173  ///
174  /// Value of `#TN_CHECK_PARAM`
175  unsigned check_param : 1;
176  ///
177  /// Value of `#TN_DEBUG`
178  unsigned debug : 1;
179  //-- Note: we don't include TN_OLD_TNKERNEL_NAMES since it doesn't
180  // affect behavior of the kernel in any way.
181  ///
182  /// Value of `#TN_USE_MUTEXES`
183  unsigned use_mutexes : 1;
184  ///
185  /// Value of `#TN_MUTEX_REC`
186  unsigned mutex_rec : 1;
187  ///
188  /// Value of `#TN_MUTEX_DEADLOCK_DETECT`
189  unsigned mutex_deadlock_detect : 1;
190  ///
191  /// Value of `#TN_TICK_LISTS_CNT` minus one
193  ///
194  /// Value of `#TN_API_MAKE_ALIG_ARG`
195  unsigned api_make_alig_arg : 2;
196  ///
197  /// Value of `#TN_PROFILER`
198  unsigned profiler : 1;
199  ///
200  /// Value of `#TN_PROFILER_WAIT_TIME`
201  unsigned profiler_wait_time : 1;
202  ///
203  /// Value of `#TN_STACK_OVERFLOW_CHECK`
204  unsigned stack_overflow_check : 1;
205  ///
206  /// Value of `#TN_DYNAMIC_TICK`
207  unsigned dynamic_tick : 1;
208  ///
209  /// Value of `#TN_OLD_EVENT_API`
210  unsigned old_events_api : 1;
211  ///
212  /// Architecture-dependent values
213  union {
214  ///
215  /// On some architectures, we don't have any arch-dependent build-time
216  /// options, but we need this "dummy" value to avoid errors of crappy
217  /// compilers that don't allow empty structure initializers (like ARMCC)
219  ///
220  /// PIC24/dsPIC-dependent values
221  struct {
222  ///
223  /// Value of `#TN_P24_SYS_IPL`
224  unsigned p24_sys_ipl : 3;
225  } p24;
226  } arch;
227 };
228 
229 /**
230  * System state flags
231  */
233  ///
234  /// system is running
236  ///
237  /// deadlock is active
238  /// Note: this feature works if only `#TN_MUTEX_DEADLOCK_DETECT` is non-zero.
239  /// @see `#TN_MUTEX_DEADLOCK_DETECT`
241 };
242 
243 /**
244  * System context
245  *
246  * @see `tn_sys_context_get()`
247  */
249  ///
250  /// None: this code is possible if only system is not running
251  /// (flag (`#TN_STATE_FLAG__SYS_RUNNING` is not set in the `_tn_sys_state`))
253  ///
254  /// Task context
256  ///
257  /// ISR context
259 };
260 
261 /**
262  * User-provided callback function that is called directly from
263  * `tn_sys_start()` as a part of system startup routine; it should merely
264  * create at least one (and typically just one) user's task, which should
265  * perform all the rest application initialization.
266  *
267  * When `TN_CBUserTaskCreate()` returned, the kernel performs first context
268  * switch to the task with highest priority. If there are several tasks with
269  * highest priority, context is switched to the first created one.
270  *
271  * Refer to the section \ref starting_the_kernel for details about system
272  * startup process on the whole.
273  *
274  * **Note:** Although you're able to create more than one task here, it's
275  * usually not so good idea, because many things typically should be done at
276  * startup before tasks can go on with their job: we need to initialize various
277  * on-board peripherals (displays, flash memory chips, or whatever) as well as
278  * initialize software modules used by application. So, if many tasks are
279  * created here, you have to provide some synchronization object so that tasks
280  * will wait until all the initialization is done.
281  *
282  * It's usually easier to maintain if we create just one task here, which
283  * firstly performs all the necessary initialization, **then** creates the rest
284  * of your tasks, and eventually gets to its primary job (the job for which
285  * task was created at all). For the usage example, refer to the page \ref
286  * starting_the_kernel.
287  *
288  * \attention
289  * * The only system service is allowed to call in this function is
290  * `tn_task_create()`.
291  *
292  * @see `tn_sys_start()`
293  */
294 typedef void (TN_CBUserTaskCreate)(void);
295 
296 /**
297  * User-provided callback function which is called repeatedly from the idle
298  * task loop. Make sure that idle task has enough stack space to call this
299  * function.
300  *
301  * Typically, this callback can be used for things like:
302  *
303  * * MCU sleep/idle mode. When system has nothing to do, it often makes sense
304  * to bring processor to some power-saving mode. Of course, the application
305  * is responsible for setting some condition to wake up: typically, it's an
306  * interrupt.
307  * * Calculation of system load. The easiest implementation is to just
308  * increment some variable in the idle task. The faster value grows, the
309  * less busy system is.
310  *
311  * \attention
312  * * From withing this callback, it is illegal to invoke `#tn_task_sleep()`
313  * or any other service which could put task to waiting state, because
314  * idle task (from which this function is called) should always be
315  * runnable, by design. If `#TN_DEBUG` option is set, then this is
316  * checked, so if idle task becomes non-runnable, `_TN_FATAL_ERROR()`
317  * macro will be called.
318  *
319  * @see `tn_sys_start()`
320  */
321 typedef void (TN_CBIdle)(void);
322 
323 /**
324  * User-provided callback function that is called when the kernel detects stack
325  * overflow (see `#TN_STACK_OVERFLOW_CHECK`).
326  *
327  * @param task
328  * Task whose stack is overflowed
329  */
330 typedef void (TN_CBStackOverflow)(struct TN_Task *task);
331 
332 /**
333  * User-provided callback function that is called whenever
334  * deadlock becomes active or inactive.
335  * Note: this feature works if only `#TN_MUTEX_DEADLOCK_DETECT` is non-zero.
336  *
337  * @param active
338  * Boolean value indicating whether deadlock becomes active or inactive.
339  * Note: deadlock might become inactive if, for example, one of tasks
340  * involved in deadlock exits from waiting by timeout.
341  *
342  * @param mutex
343  * mutex that is involved in deadlock. You may find out other mutexes
344  * involved by means of `mutex->deadlock_list`.
345  *
346  * @param task
347  * task that is involved in deadlock. You may find out other tasks involved
348  * by means of `task->deadlock_list`.
349  */
350 typedef void (TN_CBDeadlock)(
351  TN_BOOL active,
352  struct TN_Mutex *mutex,
353  struct TN_Task *task
354  );
355 
356 
357 
358 
359 /*******************************************************************************
360  * DEFINITIONS
361  ******************************************************************************/
362 
363 /**
364  * Value to pass to `tn_sys_tslice_set()` to turn round-robin off.
365  */
366 #define TN_NO_TIME_SLICE 0
367 
368 /**
369  * Max value of time slice
370  */
371 #define TN_MAX_TIME_SLICE 0xFFFE
372 
373 
374 
375 
376 /*******************************************************************************
377  * PUBLIC FUNCTION PROTOTYPES
378  ******************************************************************************/
379 
380 /**
381  * Initial TNeo system start function, never returns. Typically called
382  * from main().
383  *
384  * Refer to the \ref starting_the_kernel "Starting the kernel" section for the
385  * usage example and additional comments.
386  *
387  * $(TN_CALL_FROM_MAIN)
388  * $(TN_LEGEND_LINK)
389  *
390  * @param idle_task_stack
391  * Pointer to array for idle task stack.
392  * User must either use the macro `TN_STACK_ARR_DEF()` for the definition
393  * of stack array, or allocate it manually as an array of `#TN_UWord` with
394  * `#TN_ARCH_STK_ATTR_BEFORE` and `#TN_ARCH_STK_ATTR_AFTER` macros.
395  * @param idle_task_stack_size
396  * Size of idle task stack, in words (`#TN_UWord`)
397  * @param int_stack
398  * Pointer to array for interrupt stack.
399  * User must either use the macro `TN_STACK_ARR_DEF()` for the definition
400  * of stack array, or allocate it manually as an array of `#TN_UWord` with
401  * `#TN_ARCH_STK_ATTR_BEFORE` and `#TN_ARCH_STK_ATTR_AFTER` macros.
402  * @param int_stack_size
403  * Size of interrupt stack, in words (`#TN_UWord`)
404  * @param cb_user_task_create
405  * Callback function that should create initial user's task, see
406  * `#TN_CBUserTaskCreate` for details.
407  * @param cb_idle
408  * Callback function repeatedly called from idle task, see `#TN_CBIdle` for
409  * details.
410  */
411 void tn_sys_start(
412  TN_UWord *idle_task_stack,
413  unsigned int idle_task_stack_size,
414  TN_UWord *int_stack,
415  unsigned int int_stack_size,
416  TN_CBUserTaskCreate *cb_user_task_create,
417  TN_CBIdle *cb_idle
418  );
419 
420 /**
421  * Process system tick; should be called periodically, typically
422  * from some kind of timer ISR.
423  *
424  * The period of this timer is determined by user
425  * (typically 1 ms, but user is free to set different value)
426  *
427  * Among other things, expired \ref tn_timer.h "timers" are fired from this
428  * function.
429  *
430  * For further information, refer to \ref quick_guide "Quick guide".
431  *
432  * $(TN_CALL_FROM_ISR)
433  * $(TN_CAN_SWITCH_CONTEXT)
434  * $(TN_LEGEND_LINK)
435  */
436 void tn_tick_int_processing(void);
437 
438 /**
439  * Set time slice ticks value for specified priority (see \ref round_robin).
440  *
441  * $(TN_CALL_FROM_TASK)
442  * $(TN_LEGEND_LINK)
443  *
444  * @param priority
445  * Priority of tasks for which time slice value should be set
446  * @param ticks
447  * Time slice value, in ticks. Set to `#TN_NO_TIME_SLICE` for no round-robin
448  * scheduling for given priority (it's default value). Value can't be
449  * higher than `#TN_MAX_TIME_SLICE`.
450  *
451  * @return
452  * * `#TN_RC_OK` on success;
453  * * `#TN_RC_WCONTEXT` if called from wrong context;
454  * * `#TN_RC_WPARAM` if given `priority` or `ticks` are invalid.
455  */
456 enum TN_RCode tn_sys_tslice_set(int priority, int ticks);
457 
458 /**
459  * Get current system ticks count.
460  *
461  * $(TN_CALL_FROM_TASK)
462  * $(TN_CALL_FROM_ISR)
463  * $(TN_LEGEND_LINK)
464  *
465  * @return
466  * Current system ticks count.
467  */
469 
470 
471 /**
472  * Set callback function that should be called whenever deadlock occurs or
473  * becomes inactive (say, if one of tasks involved in the deadlock was released
474  * from wait because of timeout)
475  *
476  * $(TN_CALL_FROM_MAIN)
477  * $(TN_LEGEND_LINK)
478  *
479  * **Note:** this function should be called from `main()`, before
480  * `tn_sys_start()`.
481  *
482  * @param cb
483  * Pointer to user-provided callback function.
484  *
485  * @see `#TN_MUTEX_DEADLOCK_DETECT`
486  * @see `#TN_CBDeadlock` for callback function prototype
487  */
489 
490 /**
491  * Set callback function that is called when the kernel detects stack overflow
492  * (see `#TN_STACK_OVERFLOW_CHECK`).
493  *
494  * For function prototype, refer to `#TN_CBStackOverflow`.
495  */
497 
498 /**
499  * Returns current system state flags
500  *
501  * $(TN_CALL_FROM_TASK)
502  * $(TN_CALL_FROM_ISR)
503  * $(TN_LEGEND_LINK)
504  */
506 
507 /**
508  * Returns system context: task or ISR.
509  *
510  * $(TN_CALL_FROM_TASK)
511  * $(TN_CALL_FROM_ISR)
512  * $(TN_CALL_FROM_MAIN)
513  * $(TN_LEGEND_LINK)
514  *
515  * @see `enum #TN_Context`
516  */
517 enum TN_Context tn_sys_context_get(void);
518 
519 /**
520  * Returns whether current system context is `#TN_CONTEXT_TASK`
521  *
522  * $(TN_CALL_FROM_TASK)
523  * $(TN_CALL_FROM_ISR)
524  * $(TN_CALL_FROM_MAIN)
525  * $(TN_LEGEND_LINK)
526  *
527  * @return `TN_TRUE` if current system context is `#TN_CONTEXT_TASK`,
528  * `TN_FALSE` otherwise.
529  *
530  * @see `tn_sys_context_get()`
531  * @see `enum #TN_Context`
532  */
534 {
535  return (tn_sys_context_get() == TN_CONTEXT_TASK);
536 }
537 
538 /**
539  * Returns whether current system context is `#TN_CONTEXT_ISR`
540  *
541  * $(TN_CALL_FROM_TASK)
542  * $(TN_CALL_FROM_ISR)
543  * $(TN_CALL_FROM_MAIN)
544  * $(TN_LEGEND_LINK)
545  *
546  * @return `TN_TRUE` if current system context is `#TN_CONTEXT_ISR`,
547  * `TN_FALSE` otherwise.
548  *
549  * @see `tn_sys_context_get()`
550  * @see `enum #TN_Context`
551  */
553 {
554  return (tn_sys_context_get() == TN_CONTEXT_ISR);
555 }
556 
557 /**
558  * Returns pointer to the currently running task.
559  *
560  * $(TN_CALL_FROM_TASK)
561  * $(TN_CALL_FROM_ISR)
562  * $(TN_LEGEND_LINK)
563  */
564 struct TN_Task *tn_cur_task_get(void);
565 
566 /**
567  * Returns pointer to the body function of the currently running task.
568  *
569  * $(TN_CALL_FROM_TASK)
570  * $(TN_CALL_FROM_ISR)
571  * $(TN_LEGEND_LINK)
572  */
574 
575 /**
576  * Disable kernel scheduler and return previous scheduler state.
577  *
578  * Actual behavior depends on the platform:
579  *
580  * - On Microchip platforms, only scheduler's interrupt gets disabled. All
581  * other interrupts are not affected, independently of their priorities.
582  * - On Cortex-M3/M4 platforms, we can only disable interrupts based on
583  * priority. So, this function disables all interrupts with lowest priority
584  * (since scheduler works at lowest interrupt priority).
585  * - On Cortex-M0/M0+, we have to disable all interrupts.
586  *
587  * $(TN_CALL_FROM_TASK)
588  * $(TN_CALL_FROM_ISR)
589  * $(TN_CALL_FROM_MAIN)
590  * $(TN_LEGEND_LINK)
591  *
592  * @return
593  * State to be restored later by `#tn_sched_restore()`
594  */
596 {
597  return tn_arch_sched_dis_save();
598 }
599 
600 /**
601  * Restore state of the kernel scheduler. See `#tn_sched_dis_save()`.
602  *
603  * $(TN_CALL_FROM_TASK)
604  * $(TN_CALL_FROM_ISR)
605  * $(TN_CALL_FROM_MAIN)
606  * $(TN_LEGEND_LINK)
607  *
608  * @param sched_state
609  * Value returned from `#tn_sched_dis_save()`
610  */
612 {
613  tn_arch_sched_restore(sched_state);
614 }
615 
616 
617 #if TN_DYNAMIC_TICK || defined(DOXYGEN_ACTIVE)
618 /**
619  * $(TN_IF_ONLY_DYNAMIC_TICK_SET)
620  *
621  * Set callbacks related to dynamic tick.
622  *
623  * \attention This function should be called <b>before</b> `tn_sys_start()`,
624  * otherwise, you'll run into run-time error `_TN_FATAL_ERROR()`.
625  *
626  * $(TN_CALL_FROM_MAIN)
627  * $(TN_LEGEND_LINK)
628  *
629  * @param cb_tick_schedule
630  * Pointer to callback function to schedule next time to call
631  * `tn_tick_int_processing()`, see `#TN_CBTickSchedule` for the prototype.
632  * @param cb_tick_cnt_get
633  * Pointer to callback function to get current system tick counter value,
634  * see `#TN_CBTickCntGet` for the prototype.
635  */
637  TN_CBTickSchedule *cb_tick_schedule,
638  TN_CBTickCntGet *cb_tick_cnt_get
639  );
640 #endif
641 
642 
643 #ifdef __cplusplus
644 } /* extern "C" */
645 #endif
646 
647 #endif // _TN_SYS_H
648 
unsigned mutex_rec
Value of TN_MUTEX_REC
Definition: tn_sys.h:186
unsigned old_events_api
Value of TN_OLD_EVENT_API
Definition: tn_sys.h:210
TN_UWord tn_arch_sched_dis_save(void)
Disable kernel scheduler and return previous state.
Circular doubly linked list, for internal kernel usage.
Mutex.
Definition: tn_mutex.h:122
unsigned mutex_deadlock_detect
Value of TN_MUTEX_DEADLOCK_DETECT
Definition: tn_sys.h:189
TN_Context
System context.
Definition: tn_sys.h:248
unsigned profiler_wait_time
Value of TN_PROFILER_WAIT_TIME
Definition: tn_sys.h:201
deadlock is active Note: this feature works if only TN_MUTEX_DEADLOCK_DETECT is non-zero.
Definition: tn_sys.h:240
Task.
Definition: tn_tasks.h:330
TN_RCode
Result code returned by kernel services.
Definition: tn_common.h:81
_TN_STATIC_INLINE TN_BOOL tn_is_isr_context(void)
Returns whether current system context is TN_CONTEXT_ISR
Definition: tn_sys.h:552
None: this code is possible if only system is not running (flag (TN_STATE_FLAG__SYS_RUNNING is not se...
Definition: tn_sys.h:252
void() TN_CBUserTaskCreate(void)
User-provided callback function that is called directly from tn_sys_start() as a part of system start...
Definition: tn_sys.h:294
unsigned use_mutexes
Value of TN_USE_MUTEXES
Definition: tn_sys.h:183
unsigned long TN_TickCnt
Type for system tick count, it is used by the kernel to represent absolute tick count value as well a...
Definition: tn_common.h:188
TN_TaskBody * tn_cur_task_body_get(void)
Returns pointer to the body function of the currently running task.
_TN_STATIC_INLINE void tn_sched_restore(TN_UWord sched_state)
Restore state of the kernel scheduler.
Definition: tn_sys.h:611
system is running
Definition: tn_sys.h:235
union _TN_BuildCfg::@0 arch
Architecture-dependent values.
TN_UWord dummy
On some architectures, we don&#39;t have any arch-dependent build-time options, but we need this "dummy" ...
Definition: tn_sys.h:218
void tn_arch_sched_restore(TN_UWord sched_state)
Restore state of the kernel scheduler.
void tn_callback_deadlock_set(TN_CBDeadlock *cb)
Set callback function that should be called whenever deadlock occurs or becomes inactive (say...
void() TN_CBTickSchedule(TN_TickCnt timeout)
Available if only TN_DYNAMIC_TICK is set.
Definition: tn_timer.h:268
Timer is a kernel object that is used to ask the kernel to call some user-provided function at a part...
void tn_sys_start(TN_UWord *idle_task_stack, unsigned int idle_task_stack_size, TN_UWord *int_stack, unsigned int int_stack_size, TN_CBUserTaskCreate *cb_user_task_create, TN_CBIdle *cb_idle)
Initial TNeo system start function, never returns.
_TN_STATIC_INLINE TN_UWord tn_sched_dis_save(void)
Disable kernel scheduler and return previous scheduler state.
Definition: tn_sys.h:595
_TN_STATIC_INLINE TN_BOOL tn_is_task_context(void)
Returns whether current system context is TN_CONTEXT_TASK
Definition: tn_sys.h:533
unsigned api_make_alig_arg
Value of TN_API_MAKE_ALIG_ARG
Definition: tn_sys.h:195
Dispatch configuration: set predefined options, include user-provided cfg file as well as default cfg...
TN_TickCnt() TN_CBTickCntGet(void)
Available if only TN_DYNAMIC_TICK is set.
Definition: tn_timer.h:280
enum TN_StateFlag tn_sys_state_flags_get(void)
Returns current system state flags.
Structure with build-time configurations values; it is needed for run-time check which ensures that b...
Definition: tn_sys.h:169
void tn_callback_dyn_tick_set(TN_CBTickSchedule *cb_tick_schedule, TN_CBTickCntGet *cb_tick_cnt_get)
Available if only TN_DYNAMIC_TICK is set.
enum TN_Context tn_sys_context_get(void)
Returns system context: task or ISR.
int priority
current task priority
Definition: tn_tasks.h:392
void() TN_CBDeadlock(TN_BOOL active, struct TN_Mutex *mutex, struct TN_Task *task)
User-provided callback function that is called whenever deadlock becomes active or inactive...
Definition: tn_sys.h:350
TN_TickCnt tn_sys_time_get(void)
Get current system ticks count.
void() TN_CBIdle(void)
User-provided callback function which is called repeatedly from the idle task loop.
Definition: tn_sys.h:321
#define _TN_STATIC_INLINE
For some compilers, order of these qualifiers matters (at least when _TN_INLINE expands to some compi...
void tn_callback_stack_overflow_set(TN_CBStackOverflow *cb)
Set callback function that is called when the kernel detects stack overflow (see TN_STACK_OVERFLOW_CH...
void() TN_CBStackOverflow(struct TN_Task *task)
User-provided callback function that is called when the kernel detects stack overflow (see TN_STACK_O...
Definition: tn_sys.h:330
struct TN_Task * tn_cur_task_get(void)
Returns pointer to the currently running task.
Task context.
Definition: tn_sys.h:255
unsigned priorities_cnt
Value of TN_PRIORITIES_CNT
Definition: tn_sys.h:172
unsigned p24_sys_ipl
Value of TN_P24_SYS_IPL
Definition: tn_sys.h:224
enum TN_RCode tn_sys_tslice_set(int priority, int ticks)
Set time slice ticks value for specified priority (see Round-robin scheduling).
unsigned dynamic_tick
Value of TN_DYNAMIC_TICK
Definition: tn_sys.h:207
unsigned tick_lists_cnt_minus_one
Value of TN_TICK_LISTS_CNT minus one.
Definition: tn_sys.h:192
unsigned check_param
Value of TN_CHECK_PARAM
Definition: tn_sys.h:175
void tn_tick_int_processing(void)
Process system tick; should be called periodically, typically from some kind of timer ISR...
unsigned debug
Value of TN_DEBUG
Definition: tn_sys.h:178
unsigned int TN_UWord
Unsigned integer type whose size is equal to the size of CPU register.
void() TN_TaskBody(void *param)
Prototype for task body function.
Definition: tn_common.h:145
TN_StateFlag
System state flags.
Definition: tn_sys.h:232
unsigned stack_overflow_check
Value of TN_STACK_OVERFLOW_CHECK
Definition: tn_sys.h:204
#define TN_BOOL
boolean type definition
Definition: tn_common.h:213
struct _TN_BuildCfg::@0::@1 p24
PIC24/dsPIC-dependent values.
unsigned profiler
Value of TN_PROFILER
Definition: tn_sys.h:198
ISR context.
Definition: tn_sys.h:258