TNeo  v1.08
Macros | Typedefs
tn_arch_example.h File Reference

Detailed Description

Example of architecture-dependent routines.

Definition in file tn_arch_example.h.

Go to the source code of this file.

Macros

#define _TN_FFS(x)   (32 - __builtin_clz((x) & (0 - (x))))
 FFS - find first set bit. More...
 
#define _TN_FATAL_ERROR(error_msg, ...)   {__asm__ volatile(" sdbbp 0"); __asm__ volatile ("nop");}
 Used by the kernel as a signal that something really bad happened. More...
 
#define TN_ARCH_STK_ATTR_BEFORE
 Compiler-specific attribute that should be placed before declaration of array used for stack. More...
 
#define TN_ARCH_STK_ATTR_AFTER   __attribute__((aligned(0x8)))
 Compiler-specific attribute that should be placed after declaration of array used for stack. More...
 
#define TN_MIN_STACK_SIZE   36
 Minimum task's stack size, in words, not in bytes; includes a space for context plus for parameters passed to task's body function.
 
#define TN_INT_WIDTH   32
 Width of int type.
 
#define TN_PRIORITIES_MAX_CNT   TN_INT_WIDTH
 Maximum number of priorities available, this value usually matches TN_INT_WIDTH. More...
 
#define TN_WAIT_INFINITE   (TN_TickCnt)0xFFFFFFFF
 Value for infinite waiting, usually matches ULONG_MAX, because TN_TickCnt is declared as unsigned long.
 
#define TN_FILL_STACK_VAL   0xFEEDFACE
 Value for initializing the unused space of task's stack.
 
#define TN_INTSAVE_DATA   int tn_save_status_reg = 0;
 Declares variable that is used by macros TN_INT_DIS_SAVE() and TN_INT_RESTORE() for storing status register value. More...
 
#define TN_INTSAVE_DATA_INT   TN_INTSAVE_DATA
 The same as TN_INTSAVE_DATA but for using in ISR together with TN_INT_IDIS_SAVE(), TN_INT_IRESTORE(). More...
 
#define TN_INT_DIS_SAVE()   tn_save_status_reg = tn_arch_sr_save_int_dis()
 Disable interrupts and return previous value of status register, atomically. More...
 
#define TN_INT_RESTORE()   tn_arch_sr_restore(tn_save_status_reg)
 Restore previously saved status register. More...
 
#define TN_INT_IDIS_SAVE()   TN_INT_DIS_SAVE()
 The same as TN_INT_DIS_SAVE() but for using in ISR. More...
 
#define TN_INT_IRESTORE()   TN_INT_RESTORE()
 The same as TN_INT_RESTORE() but for using in ISR. More...
 
#define TN_IS_INT_DISABLED()   ((__builtin_mfc0(12, 0) & 1) == 0)
 Returns nonzero if interrupts are disabled, zero otherwise.
 
#define _TN_CONTEXT_SWITCH_IPEND_IF_NEEDED()   _tn_context_switch_pend_if_needed()
 Pend context switch from interrupt.
 
#define _TN_SIZE_BYTES_TO_UWORDS(size_in_bytes)   ((size_in_bytes) >> 2)
 Converts size in bytes to size in TN_UWord. More...
 
#define _TN_INLINE   inline
 If compiler does not conform to c99 standard, there's no inline keyword. More...
 
#define _TN_STATIC_INLINE   static _TN_INLINE
 For some compilers, order of these qualifiers matters (at least when _TN_INLINE expands to some compiler-specific forced inline)
 
#define _TN_VOLATILE_WORKAROUND   /* nothing */
 Sometimes compilers are buggy in high-optimization modes, and these bugs are often could be worked around by adding the volatile keyword. More...
 

Typedefs

typedef unsigned int TN_UWord
 Unsigned integer type whose size is equal to the size of CPU register. More...
 
typedef unsigned int TN_UIntPtr
 Unsigned integer type that is able to store pointers. More...
 

Macro Definition Documentation

◆ _TN_FFS

#define _TN_FFS (   x)    (32 - __builtin_clz((x) & (0 - (x))))

FFS - find first set bit.

Used in _find_next_task_to_run() function. Say, for 0xa8 it should return 3.

May be not defined: in this case, naive algorithm will be used.

Definition at line 53 of file tn_arch_example.h.

◆ _TN_FATAL_ERROR

#define _TN_FATAL_ERROR (   error_msg,
  ... 
)    {__asm__ volatile(" sdbbp 0"); __asm__ volatile ("nop");}

Used by the kernel as a signal that something really bad happened.

Indicates TNeo bugs as well as illegal kernel usage, e.g. sleeping in the idle task callback or build-time configuration mismatch (see TN_CHECK_BUILD_CFG for details on the last one)

Typically, set to assembler instruction that causes debugger to halt.

Definition at line 63 of file tn_arch_example.h.

◆ TN_ARCH_STK_ATTR_BEFORE

#define TN_ARCH_STK_ATTR_BEFORE

Compiler-specific attribute that should be placed before declaration of array used for stack.

It is needed because there are often additional restrictions applied to alignment of stack, so, to meet them, stack arrays need to be declared with these macros.

See also
TN_ARCH_STK_ATTR_AFTER

Definition at line 77 of file tn_arch_example.h.

◆ TN_ARCH_STK_ATTR_AFTER

#define TN_ARCH_STK_ATTR_AFTER   __attribute__((aligned(0x8)))

Compiler-specific attribute that should be placed after declaration of array used for stack.

It is needed because there are often additional restrictions applied to alignment of stack, so, to meet them, stack arrays need to be declared with these macros.

See also
TN_ARCH_STK_ATTR_BEFORE

Definition at line 88 of file tn_arch_example.h.

◆ TN_PRIORITIES_MAX_CNT

#define TN_PRIORITIES_MAX_CNT   TN_INT_WIDTH

Maximum number of priorities available, this value usually matches TN_INT_WIDTH.

See also
TN_PRIORITIES_CNT

Definition at line 120 of file tn_arch_example.h.

◆ TN_INTSAVE_DATA

#define TN_INTSAVE_DATA   int tn_save_status_reg = 0;

Declares variable that is used by macros TN_INT_DIS_SAVE() and TN_INT_RESTORE() for storing status register value.

See also
TN_INT_DIS_SAVE()
TN_INT_RESTORE()

Definition at line 143 of file tn_arch_example.h.

◆ TN_INTSAVE_DATA_INT

#define TN_INTSAVE_DATA_INT   TN_INTSAVE_DATA

The same as TN_INTSAVE_DATA but for using in ISR together with TN_INT_IDIS_SAVE(), TN_INT_IRESTORE().

See also
TN_INT_IDIS_SAVE()
TN_INT_IRESTORE()

Definition at line 152 of file tn_arch_example.h.

◆ TN_INT_DIS_SAVE

#define TN_INT_DIS_SAVE ( )    tn_save_status_reg = tn_arch_sr_save_int_dis()

Disable interrupts and return previous value of status register, atomically.

Similar tn_arch_sr_save_int_dis(), but implemented as a macro, so it is potentially faster.

Uses TN_INTSAVE_DATA as a temporary storage.

See also
TN_INTSAVE_DATA
tn_arch_sr_save_int_dis()

Definition at line 164 of file tn_arch_example.h.

◆ TN_INT_RESTORE

#define TN_INT_RESTORE ( )    tn_arch_sr_restore(tn_save_status_reg)

Restore previously saved status register.

Similar to tn_arch_sr_restore(), but implemented as a macro, so it is potentially faster.

Uses TN_INTSAVE_DATA as a temporary storage.

See also
TN_INTSAVE_DATA
tn_arch_sr_save_int_dis()

Definition at line 176 of file tn_arch_example.h.

◆ TN_INT_IDIS_SAVE

#define TN_INT_IDIS_SAVE ( )    TN_INT_DIS_SAVE()

The same as TN_INT_DIS_SAVE() but for using in ISR.

Uses TN_INTSAVE_DATA_INT as a temporary storage.

See also
TN_INTSAVE_DATA_INT

Definition at line 185 of file tn_arch_example.h.

◆ TN_INT_IRESTORE

#define TN_INT_IRESTORE ( )    TN_INT_RESTORE()

The same as TN_INT_RESTORE() but for using in ISR.

Uses TN_INTSAVE_DATA_INT as a temporary storage.

See also
TN_INTSAVE_DATA_INT

Definition at line 194 of file tn_arch_example.h.

◆ _TN_SIZE_BYTES_TO_UWORDS

#define _TN_SIZE_BYTES_TO_UWORDS (   size_in_bytes)    ((size_in_bytes) >> 2)

Converts size in bytes to size in TN_UWord.

For 32-bit platforms, we should shift it by 2 bit to the right; for 16-bit platforms, we should shift it by 1 bit to the right.

Definition at line 213 of file tn_arch_example.h.

◆ _TN_INLINE

#define _TN_INLINE   inline

If compiler does not conform to c99 standard, there's no inline keyword.

So, there's a special macro for that.

Definition at line 223 of file tn_arch_example.h.

◆ _TN_VOLATILE_WORKAROUND

#define _TN_VOLATILE_WORKAROUND   /* nothing */

Sometimes compilers are buggy in high-optimization modes, and these bugs are often could be worked around by adding the volatile keyword.

It is compiler-dependent, so, there's a special macro for that.

Definition at line 238 of file tn_arch_example.h.

Typedef Documentation

◆ TN_UWord

typedef unsigned int TN_UWord

Unsigned integer type whose size is equal to the size of CPU register.

Typically it's plain unsigned int.

Definition at line 105 of file tn_arch_example.h.

◆ TN_UIntPtr

typedef unsigned int TN_UIntPtr

Unsigned integer type that is able to store pointers.

We need it because some platforms don't define uintptr_t. Typically it's unsigned int.

Definition at line 112 of file tn_arch_example.h.