TNeo  v1.07
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 /*******************************************************************************
150  * PUBLIC TYPES
151  ******************************************************************************/
152 
153 /**
154  * Structure with build-time configurations values; it is needed for run-time
155  * check which ensures that build-time options for the kernel match ones for
156  * the application. See `#TN_CHECK_BUILD_CFG` for details.
157  */
158 struct _TN_BuildCfg {
159  ///
160  /// Value of `#TN_PRIORITIES_CNT`
161  unsigned priorities_cnt : 7;
162  ///
163  /// Value of `#TN_CHECK_PARAM`
164  unsigned check_param : 1;
165  ///
166  /// Value of `#TN_DEBUG`
167  unsigned debug : 1;
168  //-- Note: we don't include TN_OLD_TNKERNEL_NAMES since it doesn't
169  // affect behavior of the kernel in any way.
170  ///
171  /// Value of `#TN_USE_MUTEXES`
172  unsigned use_mutexes : 1;
173  ///
174  /// Value of `#TN_MUTEX_REC`
175  unsigned mutex_rec : 1;
176  ///
177  /// Value of `#TN_MUTEX_DEADLOCK_DETECT`
178  unsigned mutex_deadlock_detect : 1;
179  ///
180  /// Value of `#TN_TICK_LISTS_CNT` minus one
182  ///
183  /// Value of `#TN_API_MAKE_ALIG_ARG`
184  unsigned api_make_alig_arg : 2;
185  ///
186  /// Value of `#TN_PROFILER`
187  unsigned profiler : 1;
188  ///
189  /// Value of `#TN_PROFILER_WAIT_TIME`
190  unsigned profiler_wait_time : 1;
191  ///
192  /// Value of `#TN_STACK_OVERFLOW_CHECK`
193  unsigned stack_overflow_check : 1;
194  ///
195  /// Value of `#TN_DYNAMIC_TICK`
196  unsigned dynamic_tick : 1;
197  ///
198  /// Value of `#TN_OLD_EVENT_API`
199  unsigned old_events_api : 1;
200  ///
201  /// Architecture-dependent values
202  union {
203  ///
204  /// On some architectures, we don't have any arch-dependent build-time
205  /// options, but we need this "dummy" value to avoid errors of crappy
206  /// compilers that don't allow empty structure initializers (like ARMCC)
208  ///
209  /// PIC24/dsPIC-dependent values
210  struct {
211  ///
212  /// Value of `#TN_P24_SYS_IPL`
213  unsigned p24_sys_ipl : 3;
214  } p24;
215  } arch;
216 };
217 
218 /**
219  * System state flags
220  */
222  ///
223  /// system is running
225  ///
226  /// deadlock is active
227  /// Note: this feature works if only `#TN_MUTEX_DEADLOCK_DETECT` is non-zero.
228  /// @see `#TN_MUTEX_DEADLOCK_DETECT`
230 };
231 
232 /**
233  * System context
234  *
235  * @see `tn_sys_context_get()`
236  */
238  ///
239  /// None: this code is possible if only system is not running
240  /// (flag (`#TN_STATE_FLAG__SYS_RUNNING` is not set in the `_tn_sys_state`))
242  ///
243  /// Task context
245  ///
246  /// ISR context
248 };
249 
250 /**
251  * User-provided callback function that is called directly from
252  * `tn_sys_start()` as a part of system startup routine; it should merely
253  * create at least one (and typically just one) user's task, which should
254  * perform all the rest application initialization.
255  *
256  * When `TN_CBUserTaskCreate()` returned, the kernel performs first context
257  * switch to the task with highest priority. If there are several tasks with
258  * highest priority, context is switched to the first created one.
259  *
260  * Refer to the section \ref starting_the_kernel for details about system
261  * startup process on the whole.
262  *
263  * **Note:** Although you're able to create more than one task here, it's
264  * usually not so good idea, because many things typically should be done at
265  * startup before tasks can go on with their job: we need to initialize various
266  * on-board peripherals (displays, flash memory chips, or whatever) as well as
267  * initialize software modules used by application. So, if many tasks are
268  * created here, you have to provide some synchronization object so that tasks
269  * will wait until all the initialization is done.
270  *
271  * It's usually easier to maintain if we create just one task here, which
272  * firstly performs all the necessary initialization, **then** creates the rest
273  * of your tasks, and eventually gets to its primary job (the job for which
274  * task was created at all). For the usage example, refer to the page \ref
275  * starting_the_kernel.
276  *
277  * \attention
278  * * The only system service is allowed to call in this function is
279  * `tn_task_create()`.
280  *
281  * @see `tn_sys_start()`
282  */
283 typedef void (TN_CBUserTaskCreate)(void);
284 
285 /**
286  * User-provided callback function that is called repeatedly from the idle task
287  * loop. Make sure that idle task has enough stack space to call this function.
288  *
289  * \attention
290  * * It is illegal to sleep here, because idle task (from which this
291  * function is called) should always be runnable, by design. If `#TN_DEBUG`
292  * option is set, then sleeping in idle task is checked, so if you try to
293  * sleep here, `_TN_FATAL_ERROR()` macro will be called.
294  *
295  *
296  * @see `tn_sys_start()`
297  */
298 typedef void (TN_CBIdle)(void);
299 
300 /**
301  * User-provided callback function that is called when the kernel detects stack
302  * overflow (see `#TN_STACK_OVERFLOW_CHECK`).
303  *
304  * @param task
305  * Task whose stack is overflowed
306  */
307 typedef void (TN_CBStackOverflow)(struct TN_Task *task);
308 
309 /**
310  * User-provided callback function that is called whenever
311  * deadlock becomes active or inactive.
312  * Note: this feature works if only `#TN_MUTEX_DEADLOCK_DETECT` is non-zero.
313  *
314  * @param active
315  * Boolean value indicating whether deadlock becomes active or inactive.
316  * Note: deadlock might become inactive if, for example, one of tasks
317  * involved in deadlock exits from waiting by timeout.
318  *
319  * @param mutex
320  * mutex that is involved in deadlock. You may find out other mutexes
321  * involved by means of `mutex->deadlock_list`.
322  *
323  * @param task
324  * task that is involved in deadlock. You may find out other tasks involved
325  * by means of `task->deadlock_list`.
326  */
327 typedef void (TN_CBDeadlock)(
328  TN_BOOL active,
329  struct TN_Mutex *mutex,
330  struct TN_Task *task
331  );
332 
333 
334 
335 
336 /*******************************************************************************
337  * DEFINITIONS
338  ******************************************************************************/
339 
340 /**
341  * Value to pass to `tn_sys_tslice_set()` to turn round-robin off.
342  */
343 #define TN_NO_TIME_SLICE 0
344 
345 /**
346  * Max value of time slice
347  */
348 #define TN_MAX_TIME_SLICE 0xFFFE
349 
350 
351 
352 
353 /*******************************************************************************
354  * PUBLIC FUNCTION PROTOTYPES
355  ******************************************************************************/
356 
357 /**
358  * Initial TNeo system start function, never returns. Typically called
359  * from main().
360  *
361  * Refer to the \ref starting_the_kernel "Starting the kernel" section for the
362  * usage example and additional comments.
363  *
364  * $(TN_CALL_FROM_MAIN)
365  * $(TN_LEGEND_LINK)
366  *
367  * @param idle_task_stack
368  * Pointer to array for idle task stack.
369  * User must either use the macro `TN_STACK_ARR_DEF()` for the definition
370  * of stack array, or allocate it manually as an array of `#TN_UWord` with
371  * `#TN_ARCH_STK_ATTR_BEFORE` and `#TN_ARCH_STK_ATTR_AFTER` macros.
372  * @param idle_task_stack_size
373  * Size of idle task stack, in words (`#TN_UWord`)
374  * @param int_stack
375  * Pointer to array for interrupt stack.
376  * User must either use the macro `TN_STACK_ARR_DEF()` for the definition
377  * of stack array, or allocate it manually as an array of `#TN_UWord` with
378  * `#TN_ARCH_STK_ATTR_BEFORE` and `#TN_ARCH_STK_ATTR_AFTER` macros.
379  * @param int_stack_size
380  * Size of interrupt stack, in words (`#TN_UWord`)
381  * @param cb_user_task_create
382  * Callback function that should create initial user's task, see
383  * `#TN_CBUserTaskCreate` for details.
384  * @param cb_idle
385  * Callback function repeatedly called from idle task, see `#TN_CBIdle` for
386  * details.
387  */
388 void tn_sys_start(
389  TN_UWord *idle_task_stack,
390  unsigned int idle_task_stack_size,
391  TN_UWord *int_stack,
392  unsigned int int_stack_size,
393  TN_CBUserTaskCreate *cb_user_task_create,
394  TN_CBIdle *cb_idle
395  );
396 
397 /**
398  * Process system tick; should be called periodically, typically
399  * from some kind of timer ISR.
400  *
401  * The period of this timer is determined by user
402  * (typically 1 ms, but user is free to set different value)
403  *
404  * Among other things, expired \ref tn_timer.h "timers" are fired from this
405  * function.
406  *
407  * For further information, refer to \ref quick_guide "Quick guide".
408  *
409  * $(TN_CALL_FROM_ISR)
410  * $(TN_CAN_SWITCH_CONTEXT)
411  * $(TN_LEGEND_LINK)
412  */
413 void tn_tick_int_processing(void);
414 
415 /**
416  * Set time slice ticks value for specified priority (see \ref round_robin).
417  *
418  * $(TN_CALL_FROM_TASK)
419  * $(TN_LEGEND_LINK)
420  *
421  * @param priority
422  * Priority of tasks for which time slice value should be set
423  * @param ticks
424  * Time slice value, in ticks. Set to `#TN_NO_TIME_SLICE` for no round-robin
425  * scheduling for given priority (it's default value). Value can't be
426  * higher than `#TN_MAX_TIME_SLICE`.
427  *
428  * @return
429  * * `#TN_RC_OK` on success;
430  * * `#TN_RC_WCONTEXT` if called from wrong context;
431  * * `#TN_RC_WPARAM` if given `priority` or `ticks` are invalid.
432  */
433 enum TN_RCode tn_sys_tslice_set(int priority, int ticks);
434 
435 /**
436  * Get current system ticks count.
437  *
438  * $(TN_CALL_FROM_TASK)
439  * $(TN_CALL_FROM_ISR)
440  * $(TN_LEGEND_LINK)
441  *
442  * @return
443  * Current system ticks count.
444  */
446 
447 
448 /**
449  * Set callback function that should be called whenever deadlock occurs or
450  * becomes inactive (say, if one of tasks involved in the deadlock was released
451  * from wait because of timeout)
452  *
453  * $(TN_CALL_FROM_MAIN)
454  * $(TN_LEGEND_LINK)
455  *
456  * **Note:** this function should be called from `main()`, before
457  * `tn_sys_start()`.
458  *
459  * @param cb
460  * Pointer to user-provided callback function.
461  *
462  * @see `#TN_MUTEX_DEADLOCK_DETECT`
463  * @see `#TN_CBDeadlock` for callback function prototype
464  */
466 
467 /**
468  * Set callback function that is called when the kernel detects stack overflow
469  * (see `#TN_STACK_OVERFLOW_CHECK`).
470  *
471  * For function prototype, refer to `#TN_CBStackOverflow`.
472  */
474 
475 /**
476  * Returns current system state flags
477  *
478  * $(TN_CALL_FROM_TASK)
479  * $(TN_CALL_FROM_ISR)
480  * $(TN_LEGEND_LINK)
481  */
483 
484 /**
485  * Returns system context: task or ISR.
486  *
487  * $(TN_CALL_FROM_TASK)
488  * $(TN_CALL_FROM_ISR)
489  * $(TN_CALL_FROM_MAIN)
490  * $(TN_LEGEND_LINK)
491  *
492  * @see `enum #TN_Context`
493  */
494 enum TN_Context tn_sys_context_get(void);
495 
496 /**
497  * Returns whether current system context is `#TN_CONTEXT_TASK`
498  *
499  * $(TN_CALL_FROM_TASK)
500  * $(TN_CALL_FROM_ISR)
501  * $(TN_CALL_FROM_MAIN)
502  * $(TN_LEGEND_LINK)
503  *
504  * @return `TN_TRUE` if current system context is `#TN_CONTEXT_TASK`,
505  * `TN_FALSE` otherwise.
506  *
507  * @see `tn_sys_context_get()`
508  * @see `enum #TN_Context`
509  */
511 {
512  return (tn_sys_context_get() == TN_CONTEXT_TASK);
513 }
514 
515 /**
516  * Returns whether current system context is `#TN_CONTEXT_ISR`
517  *
518  * $(TN_CALL_FROM_TASK)
519  * $(TN_CALL_FROM_ISR)
520  * $(TN_CALL_FROM_MAIN)
521  * $(TN_LEGEND_LINK)
522  *
523  * @return `TN_TRUE` if current system context is `#TN_CONTEXT_ISR`,
524  * `TN_FALSE` otherwise.
525  *
526  * @see `tn_sys_context_get()`
527  * @see `enum #TN_Context`
528  */
530 {
531  return (tn_sys_context_get() == TN_CONTEXT_ISR);
532 }
533 
534 /**
535  * Returns pointer to the currently running task.
536  *
537  * $(TN_CALL_FROM_TASK)
538  * $(TN_CALL_FROM_ISR)
539  * $(TN_LEGEND_LINK)
540  */
541 struct TN_Task *tn_cur_task_get(void);
542 
543 /**
544  * Returns pointer to the body function of the currently running task.
545  *
546  * $(TN_CALL_FROM_TASK)
547  * $(TN_CALL_FROM_ISR)
548  * $(TN_LEGEND_LINK)
549  */
551 
552 /**
553  * Disable kernel scheduler and return previous scheduler state.
554  *
555  * On several platforms (namely, on Microchip platforms), there's possible to
556  * just disable scheduler, but on others (Cortex-M platforms) we can only
557  * disable interrupts based on priority. So, on Cortex-M platforms, this
558  * function disables all interrupts with lowest priority (since scheduler works
559  * at lowest interrupt priority), but on Microchip platforms this function
560  * disables scheduler precisely, no other interrupts are affected.
561  *
562  * $(TN_CALL_FROM_TASK)
563  * $(TN_CALL_FROM_ISR)
564  * $(TN_CALL_FROM_MAIN)
565  * $(TN_LEGEND_LINK)
566  *
567  * @return
568  * State to be restored later by `#tn_sched_restore()`
569  */
571 {
572  return tn_arch_sched_dis_save();
573 }
574 
575 /**
576  * Restore state of the kernel scheduler. See `#tn_sched_dis_save()`.
577  *
578  * $(TN_CALL_FROM_TASK)
579  * $(TN_CALL_FROM_ISR)
580  * $(TN_CALL_FROM_MAIN)
581  * $(TN_LEGEND_LINK)
582  *
583  * @param sched_state
584  * Value returned from `#tn_sched_dis_save()`
585  */
586 static _TN_INLINE void tn_sched_restore(TN_UWord sched_state)
587 {
588  tn_arch_sched_restore(sched_state);
589 }
590 
591 
592 #if TN_DYNAMIC_TICK || defined(DOXYGEN_ACTIVE)
593 /**
594  * $(TN_IF_ONLY_DYNAMIC_TICK_SET)
595  *
596  * Set callbacks related to dynamic tick.
597  *
598  * \attention This function should be called <b>before</b> `tn_sys_start()`,
599  * otherwise, you'll run into run-time error `_TN_FATAL_ERROR()`.
600  *
601  * $(TN_CALL_FROM_MAIN)
602  * $(TN_LEGEND_LINK)
603  *
604  * @param cb_tick_schedule
605  * Pointer to callback function to schedule next time to call
606  * `tn_tick_int_processing()`, see `#TN_CBTickSchedule` for the prototype.
607  * @param cb_tick_cnt_get
608  * Pointer to callback function to get current system tick counter value,
609  * see `#TN_CBTickCntGet` for the prototype.
610  */
612  TN_CBTickSchedule *cb_tick_schedule,
613  TN_CBTickCntGet *cb_tick_cnt_get
614  );
615 #endif
616 
617 
618 #ifdef __cplusplus
619 } /* extern "C" */
620 #endif
621 
622 #endif // _TN_SYS_H
623 
unsigned mutex_rec
Value of TN_MUTEX_REC
Definition: tn_sys.h:175
unsigned old_events_api
Value of TN_OLD_EVENT_API
Definition: tn_sys.h:199
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:178
TN_Context
System context.
Definition: tn_sys.h:237
unsigned profiler_wait_time
Value of TN_PROFILER_WAIT_TIME
Definition: tn_sys.h:190
deadlock is active Note: this feature works if only TN_MUTEX_DEADLOCK_DETECT is non-zero.
Definition: tn_sys.h:229
Task.
Definition: tn_tasks.h:330
TN_RCode
Result code returned by kernel services.
Definition: tn_common.h:81
#define _TN_INLINE
If compiler does not conform to c99 standard, there's no inline keyword.
None: this code is possible if only system is not running (flag (TN_STATE_FLAG__SYS_RUNNING is not se...
Definition: tn_sys.h:241
unsigned use_mutexes
Value of TN_USE_MUTEXES
Definition: tn_sys.h:172
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
static _TN_INLINE TN_BOOL tn_is_isr_context(void)
Returns whether current system context is TN_CONTEXT_ISR
Definition: tn_sys.h:529
TN_TaskBody * tn_cur_task_body_get(void)
Returns pointer to the body function of the currently running task.
system is running
Definition: tn_sys.h:224
union _TN_BuildCfg::@0 arch
Architecture-dependent values.
TN_UWord dummy
On some architectures, we don't have any arch-dependent build-time options, but we need this "dummy" ...
Definition: tn_sys.h:207
void tn_arch_sched_restore(TN_UWord sched_state)
Restore state of the kernel scheduler.
void( TN_CBTickSchedule)(TN_TickCnt timeout)
Available if only TN_DYNAMIC_TICK is set.
Definition: tn_timer.h:270
void tn_callback_deadlock_set(TN_CBDeadlock *cb)
Set callback function that should be called whenever deadlock occurs or becomes inactive (say...
TN_TickCnt( TN_CBTickCntGet)(void)
Available if only TN_DYNAMIC_TICK is set.
Definition: tn_timer.h:282
static _TN_INLINE TN_BOOL tn_is_task_context(void)
Returns whether current system context is TN_CONTEXT_TASK
Definition: tn_sys.h:510
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.
unsigned api_make_alig_arg
Value of TN_API_MAKE_ALIG_ARG
Definition: tn_sys.h:184
Dispatch configuration: set predefined options, include user-provided cfg file as well as default cfg...
enum TN_StateFlag tn_sys_state_flags_get(void)
Returns current system state flags.
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:283
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:327
Structure with build-time configurations values; it is needed for run-time check which ensures that b...
Definition: tn_sys.h:158
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.
static _TN_INLINE TN_UWord tn_sched_dis_save(void)
Disable kernel scheduler and return previous scheduler state.
Definition: tn_sys.h:570
static _TN_INLINE void tn_sched_restore(TN_UWord sched_state)
Restore state of the kernel scheduler.
Definition: tn_sys.h:586
enum TN_Context tn_sys_context_get(void)
Returns system context: task or ISR.
int priority
current task priority
Definition: tn_tasks.h:392
TN_TickCnt tn_sys_time_get(void)
Get current system ticks count.
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...
struct TN_Task * tn_cur_task_get(void)
Returns pointer to the currently running task.
Task context.
Definition: tn_sys.h:244
void( TN_CBIdle)(void)
User-provided callback function that is called repeatedly from the idle task loop.
Definition: tn_sys.h:298
unsigned priorities_cnt
Value of TN_PRIORITIES_CNT
Definition: tn_sys.h:161
unsigned p24_sys_ipl
Value of TN_P24_SYS_IPL
Definition: tn_sys.h:213
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:196
unsigned tick_lists_cnt_minus_one
Value of TN_TICK_LISTS_CNT minus one.
Definition: tn_sys.h:181
unsigned check_param
Value of TN_CHECK_PARAM
Definition: tn_sys.h:164
void( TN_TaskBody)(void *param)
Prototype for task body function.
Definition: tn_common.h:145
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:167
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:307
unsigned int TN_UWord
Unsigned integer type whose size is equal to the size of CPU register.
TN_StateFlag
System state flags.
Definition: tn_sys.h:221
unsigned stack_overflow_check
Value of TN_STACK_OVERFLOW_CHECK
Definition: tn_sys.h:193
#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:187
ISR context.
Definition: tn_sys.h:247