/* ------------------------------------------------------------------------------------------------ */
/* FILE :        uAbassi.h																			*/
/*																									*/
/* CONTENTS :																						*/
/*               All typedef, definitions and function prototypes for the							*/
/*               multi-core uAbassi RTOS															*/
/*																									*/
/*																									*/
/* Copyright (c) 2013-2019, Code-Time Technologies Inc. All rights reserved.						*/
/*																									*/
/* Code-Time Technologies retains all right, title, and interest in and to this work				*/
/*																									*/
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS							*/
/* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF										*/
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL							*/
/* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR								*/
/* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,							*/
/* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR							*/
/* OTHER DEALINGS IN THE SOFTWARE.																	*/
/*																									*/
/*																									*/
/*  $Revision: 1.42 $																				*/
/*	$Date: 2019/01/10 18:06:21 $																	*/
/*																									*/
/* ------------------------------------------------------------------------------------------------ */

#ifndef __UABASSI_H__							/* To protect against re-include					*/
#define __UABASSI_H__

#ifdef __cplusplus
  extern "C" {
#endif

#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <stdarg.h>

#if defined(OS_DEF_IN_INC)						/* Defines are in the AbassiDef.h include file		*/
  #include "AbassiDef.h"
#elif defined(OS_DEMO)							/* File use by Code Time Technologies for the demos	*/
 #if ((OS_DEMO) < 0)							/* -ve Demo values are used to build the libraries	*/
  #include "AbassiLib.h"
 #else											/* Regular demos									*/
  #include "AbassiDemo.h"						/* All demo RTOS build configurations are there		*/
 #endif
#elif defined(OS_TEST_HOOK)						/* File use by Code Time Technologies for testing	*/
  #include "AbassiTestCfg.h"					/* All test RTOS build configurations are there		*/
#endif

/* ------------------------------------------------------------------------------------------------ */
/* Most build options are not used in uAbassi														*/
/* Are defined in case an application relies on them for correct set-up								*/
/* ------------------------------------------------------------------------------------------------ */

	#define OS_ALLOC_SIZE		0				/* When !=0, RTOS supplied OSalloc					*/
	#define OX_ALLOC_SIZE		0
	#define OS_COOPERATIVE		0				/* When !=0, the  kernel is in cooperative mode		*/
  	#define OX_COOPERATIVE		0
   #ifndef OS_EVENTS							/* To deal with event emulation						*/
	#define OS_EVENTS			0				/* != 0 when event flags are supported				*/
   #endif
	#define OX_EVENTS			OS_EVENT		/* To deal with event emulation						*/
	#define OS_FCFS				0				/* Allow the use of 1st come 1st serve services		*/
	#define OX_FCFS				0
	#define OS_LOGGING_TYPE		0				/* Type of logging to use							*/
	#define OX_LOGGING_TYPE		0
   #ifndef OS_MAILBOX
	#define OS_MAILBOX			0				/* != 0 when mailboxes are used						*/
   #endif
	#define OX_MAILBOX			OS_MAILBOX
	#define OS_MEM_BLOCK		0				/* If the block memory pool part of the build		*/
	#define OX_MEM_BLOCK		0
	#define OS_MIN_STACK_USE	0				/* If the kernel minimizes its stack usage			*/
	#define OX_MIN_STACK_USE	0
	#define OS_MTX_DEADLOCK		0				/* != 0 to enable mutex deadlock protection			*/
	#define OX_MTX_DEADLOCK		0
	#define OS_MTX_INVERSION	0				/* >0 priority inheritance, <0 priority ceiling		*/
	#define OX_MTX_INVERSION	0
	#define OS_NAMES			1				/* != 0 when named Tasks / Semaphores / Mailboxes	*/
	#define OX_NAMES			1
	#define OS_PRIO_CHANGE		0				/* If a task priority can be changed at run time	*/
	#define OX_PRIO_CHANGE		0
	#define OS_PRIO_MIN			32				/* Max priority, Idle = OS_PRIO_MIN, AdameEve = 0	*/
	#define OX_PRIO_MIN			32
	#define OS_PRIO_SAME		1				/* Support multiple tasks with the same priority	*/
	#define OX_PRIO_SAME		1
	#define OS_ROUND_ROBIN		0				/* Use round-robin, value specifies period in uS	*/
	#define OX_ROUND_ROBIN		0
	#define OS_RUNTIME			1				/* If create Task / Semaphore / Mailbox at run time	*/
	#define OX_RUNTIME			1
	#define OS_SEARCH_ALGO		0				/* If using a fast search							*/
	#define OX_SEARCH_ALGO		0
	#define OS_STARVE_PRIO		0				/* Priority threshold for starving protection		*/
	#define OX_STARVE_PRIO		0
	#define OS_STARVE_RUN_MAX	0				/* Maximum Timer Tick for starving protection		*/
	#define OX_STARVE_RUN_MAX	0
	#define OS_STARVE_WAIT_MAX	0				/* Maximum time on hold for starving protection		*/
	#define OX_STARVE_WAIT_MAX	0
	#define OS_STATIC_BUF_MBX	0				/* When OS_STATIC_MBX != 0, # of buffer elements	*/
	#define OX_STATIC_BUF_MBX	0
	#define OS_STATIC_MBX		0				/* If !=0 how many mailboxes						*/
	#define OX_STATIC_MBX		0
	#define OS_STATIC_NAME		0				/* If named mailboxes/semaphore/task, size in char	*/
	#define OX_STATIC_NAME		0
	#define OS_STATIC_SEM		0				/* If !=0 how many semaphores and mutexes			*/
	#define OX_STATIC_SEM		0
	#define OS_STATIC_STACK		0				/* if !=0 number of bytes for all stacks			*/
	#define OX_STATIC_STACK		0
	#define OS_STATIC_TASK		0				/* If !=0 how many tasks (excluding A&E and Idle)	*/
	#define OX_STATIC_TASK		0
	#define OS_STATIC_TIM_SRV	0				/* If !=0 how many timer services					*/
	#define OX_STATIC_TIM_SRV	0
	#define OS_TASK_SUSPEND		1				/* If a task can suspend another one				*/
	#define OX_TASK_SUSPEND		1
	#define OS_TIMEOUT			1				/* !=0 enables blocking timeout						*/
	#define OX_TIMEOUT			1
	#define OS_TIMER_CB			1				/* !=0 gives the timer callback period				*/
	#define OX_TIMER_CB			1
	#define OS_TIMER_SRV		0				/* !=0 includes the timer services					*/
	#define OX_TIMER_SRV		0
	#ifndef OS_TIMER_US
	  #define OS_TIMER_US	10000				/* OS_TIMER_US is a dummy to make sure timeouts		*/
	#endif										/* are valid and included							*/
	#define OS_USE_TASK_ARG		1				/* If tasks have arguments							*/
	#define OX_USE_TASK_ARG		1
	#define OS_WAIT_ABORT		0				/* If XXXabort() components are included			*/
	#define OX_WAIT_ABORT		0
												/* ------------------------------------------------ */
												/* OPTIONAL OPTIONS SET AS IF NOT DEFINED			*/
												/* ------------------------------------------------ */
	#define OS_C_PLUS_PLUS		0				/* When !=0, C++ abstraction layer compatibility	*/
	#define OX_C_PLUS_PLUS		0
	#define OS_GROUP			0				/* If groups of trigger are supported				*/
	#define OX_GROUP			0
	#define OS_GRP_XTRA_FIELD	0
	#define OX_GRP_XTRA_FIELD	0
	#define OS_HASH_ALL			0U
	#define OX_HASH_ALL			0U
	#define OS_HASH_MBLK		0U
	#define OX_HASH_MBLK		0U
	#define OS_HASH_MBX			0U
	#define OX_HASH_MBX			0U
	#define OS_HASH_MUTEX		0U
	#define OX_HASH_MUTEX		0U
	#define OS_HASH_SEMA		0U
	#define OX_HASH_SEMA		0U
	#define OS_HASH_TASK		0U
	#define OX_HASH_TASK		0U
	#define OS_HASH_TIMSRV		0U
	#define OX_HASH_TIMSRV		0U
	#define OS_IDLE_STACK		0				/* If IdleTask supplied & if so, stack size			*/
	#define OX_IDLE_STACK		0
	#define OS_MBX_XTRA_FIELD	0
	#define OX_MBX_XTRA_FIELD	0
	#define OS_MBLK_XTRA_FIELD	0
	#define OX_MBLK_XTRA_FIELD	0
   #ifndef OS_MBXPUT_ISR						/* Mailboxes are emulated in uAbassi				*/
	#define OS_MBXPUT_ISR		0
   #endif
	#define OX_MBXPUT_ISR		(OS_MBXPUT_ISR)
	#define OS_MTX_OWN_UNLOCK	0				/* !=0 only allows ISR and owner to unlock a mutex	*/
	#define OX_MTX_OWN_UNLOCK	0
	#define OS_NESTED_INTS		1				/* != 0 operating with nested interrupts			*/
	#define OS_OUT_OF_MEM		0				/* If trapping out of memory conditions				*/
	#define OX_OUT_OF_MEM		0
	#define OS_PERF_MON			0				/* If performance monitoring is included			*/
	#define OX_PERF_MON			0
	#define OS_PRE_CONTEXT		0				/* If the callback before OScontext is needed		*/
	#define OX_PRE_CONTEXT		0
	#define OS_SEM_XTRA_FIELD	0				/* If adding extra scratch area in SEM descriptors	*/
////#define OX_SEM_XTRA_FIELD	0				/* Is auto-computed									*/
	#define OS_STACK_CHECK		0				/* Set to != for checking stack collisions			*/
	#define OX_STACK_CHECK		0
	#define OS_STATIC_BUF_MBLK	0				/* When OS_STATIC_MBLK != 0, # of memory bytes		*/
	#define OX_STATIC_BUF_MBLK	0
	#define OS_STATIC_MBLK		0				/* If !=0 how many block memory descriptors			*/
	#define OX_STATIC_MBLK		0
	#define OS_SYS_CALL			1
	#define OX_SYS_CALL			1
	#define OS_TASK_XTRA_FIELD	0				/* If adding extra scratch area in task descriptors	*/
////#define OX_TASK_XTRA_FIELD	0				/* Is auto-computed									*/
	#define OS_TIM_TICK_MULTI	1
	#define OX_TIM_TICK_MULTI	1
	#define OS_TIM_XTRA_FIELD	0
	#define OX_TIM_XTRA_FIELD	0
	#define OS_TRACE_BACK		0
	#define OX_TRACE_BACK		0
												/* ------------------------------------------------ */
												/* MULTICORE OPTIONS THAT MUST BE DEFINED			*/
												/* ------------------------------------------------ */
	#define OX_MP_TYPE			5				/* Used to get all necessary code					*/
	extern const unsigned int	G_OS_MP_TYPE;	/* This one is only for Load Balancing				*/
	extern const int			G_OS_START_STACK;
	#define OX_START_STACK		G_OS_START_STACK

  #ifndef OS_N_CORE								/* Pick a number of cores if not specified			*/
   #ifdef OS_PLATFORM
	#if ((((OS_PLATFORM) & 0x00FFFFFF) == 0x00007020)												\
     ||  (((OS_PLATFORM) & 0x00FFFFFF) == 0x0000AA10)												\
     ||  (((OS_PLATFORM) & 0x00FFFFFF) == 0x0000AAC5))
		#define OS_N_CORE		2

	#elif ((((OS_PLATFORM) & 0x00FFFFFF) == 0x00007753)												\
       ||  (((OS_PLATFORM) & 0x00FFFFFF) == 0x0000FEE6))
		#define OS_N_CORE		4

	#else
		#error "Abassi: Cannot set a default OS_N_CORE from OS_PLATFORM"
	#endif
   #else
	#error "Abassi: OS_N_CORE must be spcified"
   #endif
  #endif
  #define OX_N_CORE		(OS_N_CORE)

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */


/* ------------------------------------------------------------------------------------------------	*/
/* ------------------------------------------------------------------------------------------------	*/
/* ------------------------------------------------------------------------------------------------	*/
/* Compiler & Target processor specifics											   				*/
/* Many defines could be set to default for the most common value but MISRA does not accept #undef	*/
/* So we use an overload definition (OX_nnn) instead of the original (OS_nnn)						*/

/* ------------------------------------------------------------------------------------------------ */
/* ARM CORTEX A9 / CCS																				*/
/* ------------------------------------------------------------------------------------------------ */

#if (defined(__TI_TMS470_V4__)																		\
 ||  defined(__TI_TMS470_V5__)																		\
 ||  defined(__TI_TMS470_V6__)																		\
 ||  defined(__TI_TMS470_V7A8__)																	\
 ||  defined(__TI_TMS470_V7R4__))
	#define OX_AE_STACK_SIZE		0			/* A&E stack is main()'s, no user overload			*/
	#if (__TI_EABI_ASSEMBLER)
		#define OS_BSS_ZERO			1			/* This ABI zeroes the BSS at start-up				*/
	#else
		#define OS_BSS_ZERO			0			/* TIEABI & TI ARM9 ABI don't zero BSS at start-up	*/
	#endif
	#ifndef OS_N_INTERRUPTS
		#define OX_N_INTERRUPTS		1024		/* Set 1024 as it's the maximum the GIC supports	*/
	#endif
	#define OX_NESTED_INTS			0			/* The ARM9 nests FIQ over IRQ: RTOS is only IRQ	*/
	#define OX_STACK_GROWTH			(-1)		/* Stack grows toward lower memory addresses		*/
	#define OX_USE_STRLIB			0			/* strcpy() under some optimization only works with	*/
												/* strings that are 4 byte aligned. So use in-line	*/
	typedef int64_t OSalign_t;					/* Data type that will use the alignment size		*/
	#define OX_CACHE_LSIZE			32			/* Cache lines are 32 bytes							*/

	extern void                   COREcacheON(void);
	extern volatile unsigned int *COREgetPeriph(void);
	extern void                   DCacheFlushRange(const void *Addr, int Len);
	extern void                   DCacheInvalRange(const void *Addr, int Len);
	extern void                  *MMUlog2Phy(const void *Addr);
	extern void                  *MMUphy2Log(const void *Addr);
	extern void                   GICenable(int IntNmb, int Prio, int Edge);
	extern void                   GICinit(void);
	extern void                   DATAabort_Handler(void);
	extern void                   FIQ_Handler(void);
	extern void                   PFabort_Handler(void);
	extern void                   SWI_Handler(int SWInmb);

	#define OX_INT_CTRL_INIT()																		\
		do {																						\
			int ij;																					\
			for (ij=0 ; ij<OX_N_CORE ; ij++) {														\
				OSisrInstall(ij, &COREwakeISR);														\
			}																						\
			GICinit();																				\
		} while(0)

/* ------------------------------------------------------------------------------------------------ */
/* ARM CORTEX A9 / ARM CC																			*/
/* MUST BE BEFORE GCC BECAUSE KEIL DEFINES __GNUC__													*/
/* ------------------------------------------------------------------------------------------------ */

#elif (defined(__CC_ARM) && defined(__TARGET_ARCH_7_A))
	#define OX_AE_STACK_SIZE		0			/* A&E stack is main()'s, no user overload			*/
	#define OS_BSS_ZERO				1			/* ARM CC zeroes the BSS at start-up				*/
	#define OX_MEMSET_LIB			1			/* The function call is smaller than in-line		*/
	#ifndef OS_N_INTERRUPTS
		#define OX_N_INTERRUPTS		1024		/* Set 1024 as it's the maximum the GIC supports	*/
	#endif
	#define OX_NESTED_INTS			0			/* The ARM9 nests FIQ over IRQ: RTOS is only IRQ	*/
	#define OX_STACK_GROWTH			(-1)		/* Stack grows toward lower memory addresses		*/
	#define OX_USE_STRLIB			1			/* The function call is more efficient than inline	*/

	typedef int64_t OSalign_t;					/* Data type that will use the alignment size		*/
	#define OX_CACHE_LSIZE			32			/* Cache lines are 32 bytes							*/

	extern void                   COREcacheON(void);
	extern volatile unsigned int *COREgetPeriph(void);
	extern void                   DCacheFlushRange(const void *Addr, int Len);
	extern void                   DCacheInvalRange(const void *Addr, int Len);
	extern void                  *MMUlog2Phy(const void *Addr);
	extern void                  *MMUphy2Log(const void *Addr);
	extern void                   GICenable(int IntNmb, int Prio, int Edge);
	extern void                   GICinit(void);
	extern void                   DATAabort_Handler(void);
	extern void                   FIQ_Handler(void);
	extern void                   PFabort_Handler(void);
	extern void                   SWI_Handler(int SWInmb);

	#define OX_INT_CTRL_INIT()																		\
		do {																						\
			int ij;																					\
			for (ij=0 ; ij<OX_N_CORE ; ij++) {														\
				OSisrInstall(ij, &COREwakeISR);														\
			}																						\
			GICinit();																				\
		} while(0)

/* ------------------------------------------------------------------------------------------------ */
/* ARM CORTEX A53 / GCC																				*/
/* ------------------------------------------------------------------------------------------------ */

#elif (defined(__GNUC__) && ((__ARM_ARCH) == 8))													\
   || (defined(__GNUC__) && defined(__aarch64__))
	#define OX_AE_STACK_SIZE		0			/* Most ports don't need a stack for Adam & Eve		*/
	#define OS_BSS_ZERO				1			/* GNU zeroes the BSS at start-up					*/
	#define OX_MEMSET_LIB			1			/* The function call is more efficient than inline	*/
	#ifndef OS_N_INTERRUPTS
		#define OX_N_INTERRUPTS		1024		/* Set 1024 as it's the maximum the GIC supports	*/
	#endif
	#define OX_NESTED_INTS			0			/* The ARM9 nests FIQ over IRQ: RTOS is only IRQ	*/
	#define OX_STACK_GROWTH			(-1)		/* Stack grows toward lower memory addresses		*/
	#define OX_USE_STRLIB			1			/* The function call is more efficient than inline	*/

	typedef __int128 OSalign_t;					/* Data type that will use the alignment size		*/
	#define OX_CACHE_LSIZE			64			/* Cache lines are 64 bytes							*/

	extern void                   COREcacheON(void);
	extern volatile unsigned int *COREgetPeriph(void);
	extern void                   DCacheFlushRange(const void *Addr, int Len);
	extern void                   DCacheInvalRange(const void *Addr, int Len);
	extern void                  *MMUlog2Phy(const void *Addr);
	extern void                  *MMUphy2Log(const void *Addr);
	extern void                   GICenable(int IntNmb, int Prio, int Edge);
	extern void                   GICinit(void);

	extern void FIQ_Handler(void);
	extern void SError_Handler(uint32_t Syndrome, void *Ret, uint32_t Pstate, int Level);
	extern void Sync_Handler(uint32_t Syndrome, void *Ret, uint32_t Pstate, int Level);

	#define OX_INT_CTRL_INIT()																		\
		do {																						\
			int ij;																					\
			for (ij=0 ; ij<OX_N_CORE ; ij++) {														\
				OSisrInstall(ij, &COREwakeISR);														\
			}																						\
			GICinit();																				\
		} while(0)

	#ifdef OS_PLATFORM
		#if (((OS_PLATFORM) & 0x00FFFFFF) == 0x00007753)
			#define OX_TIM_TICK_ACK()	 do {														\
											volatile uint32_t _dum;									\
											_dum = *((volatile uint32_t *)0xFF140054);				\
											_dum = _dum;											\
										} while(0)
		#endif
	#endif

/* ------------------------------------------------------------------------------------------------ */
/* ARM CORTEX A9 / GCC																				*/
/* MUST BE AFTER KEIL ARMCC BECAUSE KEIL ALSO DEFINES __GNUC__										*/
/* ------------------------------------------------------------------------------------------------ */

#elif (defined(__GNUC__) && defined(__ARM_ARCH_7A__))
	#define OX_AE_STACK_SIZE		0			/* Most ports don't need a stack for Adam & Eve		*/
	#define OS_BSS_ZERO				1			/* GNU zeroes the BSS at start-up					*/
	#define OX_MEMSET_LIB			1			/* The function call is more efficient than inline	*/
	#ifndef OS_N_INTERRUPTS
		#define OX_N_INTERRUPTS		1024		/* Set 1024 as it's the maximum the GIC supports	*/
	#endif
	#define OX_NESTED_INTS			0			/* The ARM9 nests FIQ over IRQ: RTOS is only IRQ	*/
	#define OX_STACK_GROWTH			(-1)		/* Stack grows toward lower memory addresses		*/
	#define OX_USE_STRLIB			1			/* The function call is more efficient than inline	*/

	typedef int64_t OSalign_t;					/* Data type that will use the alignment size		*/
	#define OX_CACHE_LSIZE			32			/* Cache lines are 32 bytes							*/

	extern void                   COREcacheON(void);
	extern volatile unsigned int *COREgetPeriph(void);
	extern void                   DCacheFlushRange(const void *Addr, int Len);
	extern void                   DCacheInvalRange(const void *Addr, int Len);
	extern void                  *MMUlog2Phy(const void *Addr);
	extern void                  *MMUphy2Log(const void *Addr);
	extern void                   GICenable(int IntNmb, int Prio, int Edge);
	extern void                   GICinit(void);
	extern void                   DATAabort_Handler(void);
	extern void                   FIQ_Handler(void);
	extern void                   PFabort_Handler(void);
	extern void                   SWI_Handler(int SWInmb);

	#define OX_INT_CTRL_INIT()																		\
		do {																						\
			int ij;																					\
			for (ij=0 ; ij<OX_N_CORE ; ij++) {														\
				OSisrInstall(ij, &COREwakeISR);														\
			}																						\
			GICinit();																				\
		} while(0)

/* ------------------------------------------------------------------------------------------------ */
/* ARM CORTEX M3 / CCS																				*/
/* ------------------------------------------------------------------------------------------------ */

#elif defined(__TI_TMS470_V7M3__)
	#define OX_AE_STACK_SIZE		0			/* A&E stack is main()'s, no user overload			*/
	#if (__TI_EABI_ASSEMBLER)
		#define OS_BSS_ZERO			1			/* This ABI zeroes the BSS at start-up				*/
	#else
		#define OS_BSS_ZERO			0			/* TI ARM9 ABI doesn't zero BSS at start-up			*/
	#endif										/* TIABI does not support the Cortex M3				*/
	#define OX_ISR_TBL_OFFSET		1			/* We need to include SysTick (interrupt # == -1)	*/
	#define OX_MEMSET_LIB			0			/* The function call same as in-line, keep in-line	*/
	#ifndef OS_N_INTERRUPTS
		#define OX_N_INTERRUPTS		241			/* NVIC has 256 sources of interrupt, drop 15 1st	*/
	#endif
	#define OX_NESTED_INTS			1			/* The ARM has 8 nested (NVIC) interrupt levels		*/
	#define OX_STACK_GROWTH			(-1)		/* Stack grows toward lower memory addresses		*/
	#define OX_USE_STRLIB			1			/* The function call is smaller than in-line		*/

	#ifndef OS_PLATFORM
		#ifdef omap4460
			#define OS_PLATFORM 			0x4460
		#endif
	#endif

	#ifndef OS_PLATFORM
		#error "Abassi: The build option OS_PLATFORM hasn't been defined"
		#error "        SMP M3 must have the target platform defined:"
		#error "		== 0xXX004460 : OMAP4460"
	#else
		#if (((OS_PLATFORM) & 0x00FFFFFF) == 0x4460)
			#define OX_INT_CTRL_INIT()	do {														\
											NVIC_enableIRQ(3);										\
											OSisrInstall(3, &COREwakeISR);							\
										} while(0)
		#else
			#error "Abassi: The build option OS_PLATFORM is set to an invalid platform"
		#endif
	#endif

	typedef int64_t OSalign_t;					/* Data type that will use the alignment size		*/
	#define OS_NVIC_OFF(_IntN) 	do {																\
									int _NN = _IntN;												\
									((((volatile uint32_t *)0xE000E180)[(_NN)/32])					\
	                          		                                        = 1U << ((_NN)&0x1F));	\
								} while(0)
	#define OS_NVIC_ON(_IntN) 	do {																\
									int _NN = _IntN;												\
									((((volatile uint32_t *)0xE000E100)[(_NN)/32])					\
									                                        = 1U << ((_NN)&0x1F));	\
								} while(0)
												/* Functions unique to CCS / M3						*/
	extern void BusFault_Handler   (void);
	extern void DebugMon_Handler   (void);
	extern void HardFault_Handler  (void);
	extern void MemManage_Handler  (void);
	extern void NMI_Handler        (void);
	extern void NVIC_enableIRQ     (int IntNmb);
	extern void SVC_Handler        (void);
	extern void UsageFault_Handler (void);

	#ifdef __UABASSI_C__
		extern void COREinit(int CoreID);		/* Only used in uAbassi.c							*/
	#endif

	#define OX_XTRA_CORE_START(__CoreID)															\
		do { 																						\
			COREinit(__CoreID);																		\
		} while(0)

/* ------------------------------------------------------------------------------------------------ */
/* UNSUPPORTED PLATFORM																				*/
/* ------------------------------------------------------------------------------------------------ */

#else
	#error "uAbassi: Unsupported processor/compiler"

#endif

/* ------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------ */
/* LIBRARIES RE-ENTRANCE PROTECTION:																*/
/*            Libraries typically uses the same re-entrance protection for all platforms			*/
/*																									*/

#ifndef	OX_INT_CTRL_INIT
	#define OX_INT_CTRL_INIT()		OX_DO_NOTHING()
#endif

/* ------------------------------------------------------------------------------------------------ */
/* TI/CCS - LIBRARY RE-ENTRANCE PROTECTION															*/
/* ------------------------------------------------------------------------------------------------ */

#if defined(__TI_COMPILER_VERSION__)

	#ifndef OX_DOING_BSS_0
		#define OX_DOING_BSS_0()	OX_DO_NOTHING()
	#endif

	#ifndef OS_CCS_REENT
		#define OS_CCS_REENT 		1
	#endif

	#if ((OS_CCS_REENT) != 0)

		#define OX_LIB_REENT_PROTECT	(OS_CCS_REENT)

		#if (defined(__ABASSI_C__) || defined(__MABASSI_C__) || defined(__UABASSI_C__))
			#include <_lock.h>					/* Install the protection for multi-threading on	*/
			void OS_CCSlock(void);				/* Abassi mutex protection for the library			*/
			void OS_CCSunlock(void);			/* Abassi mutex protection for the library			*/
			int G_OSmtxOK = 0;					/* Set to 0 in case BSS not zeroed					*/
		#else
			extern int G_OSmtxOK;
		#endif

		#define OX_DEVICE_PREINIT()																	\
			do {																					\
				G_OSmtxOK = 1;																		\
				_register_lock(&OS_CCSlock);														\
				_register_unlock(&OS_CCSunlock);													\
				OX_INT_CTRL_INIT();																	\
			} while(0)

		#define OX_XTRA_FCT																			\
			static void OS_CCSlockNone(void) { return; }											\
			int _system_pre_init(void) {															\
				OX_DOING_BSS_0();																	\
				_register_lock(&OS_CCSlockNone);													\
				_register_unlock(&OS_CCSlockNone);													\
				return(1);																			\
			}																						\
			void OS_CCSlock(void) {																	\
				if (COREreentOK() != 0) {															\
					MTXsafeLock(G_OSmutex);															\
				}																					\
				return;																				\
			}																						\
			void OS_CCSunlock(void) {																\
				if (COREreentOK() != 0) {															\
					MTXunlock(G_OSmutex);															\
				}																					\
				return;																				\
			}

	#else										/* No library protection							*/
		#if (defined(__ABASSI_C__) || defined(__MABASSI_C__) || defined(__UABASSI_C__))
			#include <_lock.h>
		#endif

		#define OX_XTRA_FCT																			\
			static void OS_CCSnolock(void) { return; }												\
			int _system_pre_init(void) {															\
				OX_DOING_BSS_0();																	\
				_register_lock(&OS_CCSnolock);														\
				_register_unlock(&OS_CCSnolock);													\
				return(1);																			\
			}

	#endif

/* ------------------------------------------------------------------------------------------------ */
/* KEIL - LIBRARY RE-ENTRANCE PROTECTION															*/
/*        MUST BE BEFORE GCC NEWLIB BECAUSE KEIL DEFINES __GNUC__									*/
/* ------------------------------------------------------------------------------------------------ */

#elif defined(__CC_ARM)

	#ifndef OS_KEIL_REENT
		#define OS_KEIL_REENT	0
	#endif
												/* MicroLib doesn't support re-entrance protection	*/
	#if (((OS_KEIL_REENT) != 0) && !defined(__MICROLIB))
		#define OX_LIB_REENT_PROTECT		(OS_KEIL_REENT)

		#ifdef OX_TASK_XTRA_FIELD_1
			#error "With library re-entrance protection enabled, 1st entry in XTRA_FIELD is"
			#error "reserved.  Use a higher OX_TASK_XTRA_FIELD_n"
		#else
			#define OX_TASK_XTRA_FIELD_1	1
		#endif

		extern char __libspace_start[96];		/* Default libspace area							*/

		#if (defined(__ABASSI_C__) || defined(__MABASSI_C__) || defined(__UABASSI_C__))
			int G_OSmtxOK;						/* No need to set to zero as BSS is zeroed			*/
		#else
			extern int G_OSmtxOK;
		#endif

		#if ((OS_KEIL_REENT) > 0)
			#if (defined(__ABASSI_C__) || defined(__MABASSI_C__) || defined(__UABASSI_C__))
		  	  #define OX_TASK_XTRA(_TskDsc, _Fct)													\
				do {																				\
					if (_Fct != NULL) {																\
						void *_Reent;																\
						_Reent = OSalloc(96);														\
						 (_TskDsc)->XtraData[0] = (intptr_t)_Reent;									\
						memset(_Reent, 0, 96);														\
					}																				\
				} while(0)
			#else								/* When used outside of Abassi.c by TSK_SETUP()		*/
		  	  #define OX_TASK_XTRA(_TskDsc, _Fct)	/* there is no need to check for A&E		*/	\
				do {																				\
					void *_Reent;																	\
					_Reent = OSalloc(96);															\
					 (_TskDsc)->XtraData[0] = (intptr_t)_Reent;										\
					memset(_Reent, 0, 96);															\
				} while(0)
			#endif

			#define TSKmultThrd(_TskDsc)	OX_DO_NOTHING()

		#else
			#define TSKmultThrd(_TskDsc)															\
				do {																				\
					void *_Reent;																	\
					_Reent = OSalloc(96);															\
					 (_TskDsc)->XtraData[0] = (intptr_t)_Reent;										\
					memset(_Reent, 0, 96);															\
				} while(0)
		#endif

		#define OX_DEVICE_PREINIT()																	\
			do {																					\
				G_OSmtxOK = 1;																		\
				OX_INT_CTRL_INIT();																	\
			} while(0)

		#define OX_XTRA_FCT																			\
			int _mutex_initialize(SEM_t *Sema) {													\
				Sema = Sema;																		\
				return(1);																			\
			}																						\
			void _mutex_acquire(SEM_t *Sema) {														\
				Sema = Sema;																		\
				if (COREreentOK() != 0) {															\
					MTXsafeLock(G_OSmutex);															\
				}																					\
			}																						\
			void _mutex_release(SEM_t *Sema) {														\
				Sema = Sema;																		\
				if (COREreentOK() != 0) {															\
					MTXunlock(G_OSmutex);															\
				}																					\
			}																						\
			void _mutex_free(SEM_t *Sema) {															\
				Sema = Sema;																		\
				return;																				\
			}																						\
			void *__user_perproc_libspace(void) {													\
				return((void *)&__libspace_start[0]);												\
			}																						\
			void *__user_perthread_libspace(void) { 												\
				void *Ptr;																			\
				Ptr = (void *)&__libspace_start[0];													\
				if (TSKmyID() != (TSK_t *)NULL) {													\
					if (TSKmyID()->XtraData[0] != (intptr_t)0) {									\
					    Ptr = (void *)TSKmyID()->XtraData[0];										\
					}																				\
				}																					\
				return(Ptr);																		\
			}
	#endif

/* ------------------------------------------------------------------------------------------------ */
/* GCC - NEWLIB RE-ENTRANCE PROTECTION																*/
/*       MUST BE AFTER KEIL ARM CC BECAUSE KEIL ALSO DEFINES __GNUC__								*/
/* ------------------------------------------------------------------------------------------------ */

#elif defined(__GNUC__)

	#ifndef OS_NEWLIB_REENT
		#define OS_NEWLIB_REENT		0
	#endif

	#if ((OS_NEWLIB_REENT) != 0)
		#include <reent.h>
		struct _reent *__getreent(void);

		#define OX_LIB_REENT_PROTECT		(OS_NEWLIB_REENT)

		#ifdef OS_CMSIS_RTOS
	      #if ((OS_CMSIS_RTOS) != 0)
			#define OS_NEWLIB_MUTEX_SINGLE -1	/* >0 :  G_OSmtxGCC	 ---   <0 : G_OSmutex 			*/
		  #else									/* ==0: individual mutexes created & destroyed		*/
			#define OS_NEWLIB_MUTEX_SINGLE	1
		  #endif
	      #if ((OS_CMSIS_RTOS)!= 0) && ((OS_NEWLIB_MUTEX_SINGLE) >= 0)
			#error "With CMSIS, OS_NEWLIB_MUTEX_SINGLE must be set to a negative value (<0)"
	      #endif								/* Due to MTXopen() not available + NO runtime		*/
		#endif

	    #ifndef OS_NEWLIB_MUTEX_SINGLE			/* If Newlib uses individual or global mutex		*/
			#define OS_NEWLIB_MUTEX_SINGLE	0	/* >0 :  G_OSmtxGCC	 ---   <0 : G_OSmutex 			*/
	    #endif									/* ==0: individual mutexes							*/

		#ifndef OS_NEWLIB_SHARE_STDIO			/* If stdio same across all tasks with reent protect*/
			#define OS_NEWLIB_SHARE_STDIO	1	/* Set to 2 if __sf_fake_??? are not found			*/
		#endif

		#ifndef OS_NEWLIB_REDEF
			#define OS_NEWLIB_REDEF			0
		#endif

		#ifdef OX_TASK_XTRA_FIELD_1
			#error "With library re-entrance protection enabled, 1st entry in XTRA_FIELD is"
			#error "reserved.  Use a higher OX_TASK_XTRA_FIELD_n"
		#else
			#define OX_TASK_XTRA_FIELD_1	1
		#endif

		#if ((OS_NEWLIB_SHARE_STDIO) != 0)		/* Sharing the same stdio							*/
			#define OX_NEWLIB_STDIO_COPY(_Tsk)	do {												\
				((struct _reent *)((_Tsk)->XtraData[0]))->_stdin     = _global_impure_ptr->_stdin;	\
				((struct _reent *)((_Tsk)->XtraData[0]))->_stdout    = _global_impure_ptr->_stdout;	\
				((struct _reent *)((_Tsk)->XtraData[0]))->_stderr    = _global_impure_ptr->_stderr;	\
				((struct _reent *)((_Tsk)->XtraData[0]))->__sdidinit = 1;							\
												} while(0)
		#else									/* Not sharing the same stdio						*/
			#define OX_NEWLIB_STDIO_COPY(_Tsk)	OX_DO_NOTHING()
		#endif

	 	#if ((defined(_REENT_SMALL) 																\
		 &&  (defined(__ABASSI_C__) || defined(__MABASSI_C__) || defined(__UABASSI_C__)))			\
		 &&  ((OS_NEWLIB_SHARE_STDIO) > 1))
			const struct __sFILE_fake __sf_fake_stdin  = {_NULL, 0, 0, 0, 0, {_NULL, 0}, 0, _NULL};
			const struct __sFILE_fake __sf_fake_stdout = {_NULL, 0, 0, 0, 0, {_NULL, 0}, 0, _NULL};
			const struct __sFILE_fake __sf_fake_stderr = {_NULL, 0, 0, 0, 0, {_NULL, 0}, 0, _NULL};
		#endif

		#if ((OS_NEWLIB_REENT) > 0)				/* Reentrance protection for all tasks				*/
			#if (defined(__ABASSI_C__) || defined(__MABASSI_C__) || defined(__UABASSI_C__))
				#define OX_TASK_XTRA(_TskDsc, _Fct)													\
					do {																			\
						if ((_Fct) != NULL) {	/* Not A&E: allocate / init / memo _reent 		*/	\
							struct _reent *_Reent;													\
							_Reent = (struct _reent *)OSalloc(sizeof(struct _reent));				\
							_REENT_INIT_PTR(_Reent);												\
							(_TskDsc)->XtraData[0] = (intptr_t)_Reent;								\
							OX_NEWLIB_STDIO_COPY(_TskDsc);											\
						}																			\
						else {					/* A&E uses the default data		 			*/	\
							(_TskDsc)->XtraData[0] = (intptr_t)_global_impure_ptr;					\
						}																			\
					} while(0)
			#else
		 		#define OX_TASK_XTRA(_TskDsc, _Fct)	/* There is no need to check for A&E		*/	\
					do {																			\
						struct _reent *_Reent;														\
						_Reent = (struct _reent *)OSalloc(sizeof(struct _reent));					\
						_REENT_INIT_PTR(_Reent);													\
						(_TskDsc)->XtraData[0] = (intptr_t)_Reent;									\
						OX_NEWLIB_STDIO_COPY(_TskDsc);												\
					} while(0)
			#endif
												/* Always define it when REENT PROTECT ENABLE		*/
			#define TSKmultThrd(_TskDsc)		OX_DO_NOTHING()

	    #else									/* Reentrance protection on selected tasks			*/
			#define OX_TASK_XTRA(_TskDsc, _Fct)														\
				do {																				\
					(_TskDsc)->XtraData[0] = (intptr_t)_global_impure_ptr;							\
				} while(0)

			#define TSKmultThrd(_TskDsc)															\
				do {																				\
					struct _reent *_Reent;															\
					_Reent = (struct _reent *)OSalloc(sizeof(struct _reent));						\
					_REENT_INIT_PTR(_Reent);														\
					(_TskDsc)->XtraData[0] = (intptr_t)_Reent;										\
					OX_NEWLIB_STDIO_COPY(_TskDsc);													\
				} while(0)

	    #endif
												/* For backward compatibility						*/
		#define OS_TASK_NEWLIB_TASK_REENT(_TskDsc)	TSKmultThrd(_TskDsc)

	    #if (defined(__ABASSI_C__) || defined(__MABASSI_C__) || defined(__UABASSI_C__))
			#include <envlock.h>				/* Includes needed with reentrance protection		*/
			#include <locale.h>
			#include <malloc.h>
			int G_OSmtxOK;						/* No need to set to 0 as BSS is zeroed				*/

		  #ifndef __gthr_generic_h				/* Depending on how libs were built, these typedef	*/
			typedef void *__gthread_key_t;		/* may or not exist if gthr_generic.h included		*/
			typedef void *__gthread_once_t;		/* __gthr_generic_h is defined in gthr_generic.h	*/
			typedef struct __gthread_mutex_s { void *__p; } __gthread_mutex_t;
			typedef struct __gthread_recursive_mutex_s { void *__p; } __gthread_recursive_mutex_t;
		  #endif

		#else
			extern int G_OSmtxOK;
	    #endif

	    #if ((OS_NEWLIB_MUTEX_SINGLE) == 0)		/* Individual mutexes inited & destroyed			*/
			#define OX_XTRA_VAR_AND_DEF MTX_t *G_OSmtxPark;											\
										MTX_t *G_OSmtxGCC;											\
										MTX_t *G_OSmtxGCCalloc;										\
										MTX_t *G_OSmtxGCCenv;										\
										MTX_t *G_OSmtxGCCtz;
			#define OX_SEM_PARKING		1		/* With init & destroy, need unused mutex parking 	*/
			#define NL_MUTEX			((*Mtx == NULL) ? G_OSmtxGCC : *Mtx)
			#define NL_MUTX_GLOB		(G_OSmtxGCC)
			#define NL_MTX_ALLOC		(G_OSmtxGCCalloc)
			#define NL_MTX_ENV			(G_OSmtxGCCenv)
			#define NL_MTX_TZ			(G_OSmtxGCCtz)
			#define NL_MTX_DESTROY()	do {														\
											if (mutex->__p != NULL) {								\
												MTXsafeLock(G_OSmtxGCC);							\
												((MTX_t *)(mutex->__p))->ParkNext = G_OSmtxPark;	\
												G_OSmtxPark = (MTX_t *)mutex->__p;					\
												MTXunlock(G_OSmtxGCC);								\
											}														\
										} while(0)
			#define NL_MTX_INIT()		do {														\
											if (G_OSmtxOK != 0) {									\
												MTXsafeLock(G_OSmtxGCC);							\
												if (G_OSmtxPark == (MTX_t *)NULL) {					\
													mutex->__p = MTXopen(NULL);						\
												}													\
												else {												\
													G_OSmtxPark->Value = 1;							\
													mutex->__p  = G_OSmtxPark;						\
													G_OSmtxPark = G_OSmtxPark->ParkNext;			\
												}													\
												MTXunlock(G_OSmtxGCC);								\
											}														\
											else {													\
												mutex->__p = NULL;									\
											}														\
										} while(0)
			#define NL_MTX_MTHR_INIT()	do {														\
										    G_OSmtxPark=NULL;										\
											G_OSmtxGCC      = MTXopen("GCC mtx");					\
											G_OSmtxGCCalloc = MTXopen("GCC alloc");					\
											G_OSmtxGCCenv   = MTXopen("GCC env");					\
											G_OSmtxGCCtz    = MTXopen("GCC tz");					\
										} while(0)

	    #elif ((OS_NEWLIB_MUTEX_SINGLE) < 0)	/* Using only G_OSmutex								*/
			#define NL_MUTEX			(G_OSmutex)
			#define NL_MUTX_GLOB		(G_OSmutex)
			#define NL_MTX_ALLOC		(G_OSmutex)
			#define NL_MTX_ENV			(G_OSmutex)
			#define NL_MTX_TZ			(G_OSmutex)
			#define NL_MTX_DESTROY()	OX_DO_NOTHING()
			#define NL_MTX_INIT()		do {mutex->__p=((G_OSmtxOK==0)?NULL:G_OSmutex);} while(0)
			#define NL_MTX_MTHR_INIT()	OX_DO_NOTHING()

	    #else									/* Using only G_OSmtxGCC							*/
			#define OX_XTRA_VAR_AND_DEF MTX_t *G_OSmtxGCC;
			#define NL_MUTEX			(G_OSmtxGCC)
			#define NL_MUTX_GLOB		(G_OSmtxGCC)
			#define NL_MTX_ALLOC		(G_OSmtxGCC)
			#define NL_MTX_ENV			(G_OSmtxGCC)
			#define NL_MTX_TZ			(G_OSmtxGCC)
			#define NL_MTX_DESTROY()	OX_DO_NOTHING()
			#define NL_MTX_INIT()		do {mutex->__p=(G_OSmtxOK==0)?NULL:G_OSmtxGCC;} while(0)
			#define NL_MTX_MTHR_INIT()	do {G_OSmtxGCC=MTXopen("GCC mutex");} while(0)
	    #endif

	    #define OX_DEVICE_PREINIT()																	\
			do {																					\
				NL_MTX_MTHR_INIT();																	\
				G_OSmtxOK = 1;																		\
				OX_INT_CTRL_INIT();																	\
			} while(0)
											/* __generic_gxx_getspecific() not included due to		*/
											/* changes of function prototype across lib versions	*/
	    #define OX_XTRA_FCT																			\
			int __generic_gxx_active_p(void) {														\
				return(G_OSmtxOK != 0);		/* G_OSmtxOK is a good indicator for Abassi active	*/	\
			}																						\
			int __generic_gxx_once(__gthread_once_t *once, void(*func)(void)) {						\
				return(-1);					/* Not supported									*/	\
			}																						\
			int __generic_gxx_key_create(__gthread_key_t *keyp, void(*dtor)(void *)) {				\
				return(-1);					/* Not supported									*/	\
			}																						\
			int __generic_gxx_key_delete(__gthread_key_t key) {										\
				return(-1);					/* Not supported									*/	\
			}																						\
			int __generic_gxx_setspecific(__gthread_key_t key, const void *ptr) {					\
				return(-1);					/* Not supported									*/	\
			}																						\
			int __generic_gxx_mutex_destroy(__gthread_mutex_t *mutex) {								\
				NL_MTX_DESTROY();			/* Code specific for single or multiple mutexes		*/	\
				return(0);																			\
			}																						\
			void __generic_gxx_recursive_mutex_init_function(__gthread_recursive_mutex_t *mutex) {	\
				NL_MTX_INIT();				/* Code specific for single or multiple mutexes		*/	\
				return;																				\
			}																						\
			int __generic_gxx_recursive_mutex_destroy(__gthread_recursive_mutex_t *mutex) {			\
				return(__generic_gxx_mutex_destroy((__gthread_mutex_t *)mutex));					\
			}																						\
			void __generic_gxx_mutex_init_function(__gthread_mutex_t *mutex) {						\
				__generic_gxx_recursive_mutex_init_function((__gthread_recursive_mutex_t *)mutex);	\
				return;																				\
			}																						\
			static int __my_gxx_lock(MTX_t **Mtx, int TimeOut) {									\
				int Ret = 1;				/* When can't lock mutex, report error				*/	\
				if (0 != COREreentOK()) {	/* Code specific for single or multiple mutexes		*/	\
					if ((0 == OSisrInfo()) && ((TimeOut) != 0)) {									\
						MTXsafeLock(NL_MUTEX);	/* Here, ISRs are disabled and Timeout == -1	*/	\
						Ret = 0;			/* Must use the safe locking						*/	\
					}																				\
					else {					/* ISR on or Timeout == 0, regular lock				*/	\
						Ret = (0 != MTXlock(NL_MUTEX, (TimeOut)));									\
					}																				\
				}																					\
				return(Ret);																		\
			}																						\
			static int __my_gxx_unlock(MTX_t **Mtx) {												\
				if (0 != COREreentOK()) {															\
					MTXunlock(NL_MUTEX);	/* Code specific for single or multiple mutexes		*/	\
				}																					\
				return(0);																			\
			}																						\
			int __generic_gxx_mutex_lock(__gthread_mutex_t *mutex) {								\
				return(__my_gxx_lock((MTX_t **)mutex, -1));											\
			}																						\
			int __generic_gxx_mutex_trylock(__gthread_mutex_t *mutex) {								\
				return(__my_gxx_lock((MTX_t **)mutex, 0));											\
			}																						\
			int __generic_gxx_mutex_unlock(__gthread_mutex_t *mutex) {								\
				return(__my_gxx_unlock((MTX_t **)mutex));											\
			}																						\
			int __generic_gxx_recursive_mutex_lock(__gthread_recursive_mutex_t *mutex) {			\
				return(__my_gxx_lock((MTX_t **)mutex, -1));											\
			}																						\
			int __generic_gxx_recursive_mutex_trylock(__gthread_recursive_mutex_t *mutex) {			\
				return(__my_gxx_lock((MTX_t **)mutex, 0));											\
			}																						\
			int __generic_gxx_recursive_mutex_unlock(__gthread_recursive_mutex_t *mutex) {			\
				return(__my_gxx_unlock((MTX_t **)mutex));											\
			}																						\
			void __malloc_lock(struct _reent *reent) {												\
				if (COREreentOK() != 0) {															\
					MTXsafeLock(NL_MTX_ALLOC);														\
				}																					\
			}																						\
			void __malloc_unlock(struct _reent *reent) {											\
				if (COREreentOK() != 0) {															\
					MTXunlock(NL_MTX_ALLOC);														\
				}																					\
			}																						\
			void __env_lock(struct _reent *reent) {													\
				if (COREreentOK() != 0) {															\
					MTXsafeLock(NL_MTX_ENV);														\
				}																					\
			}																						\
			void __env_unlock(struct _reent *reent) {												\
				if (COREreentOK() != 0) {															\
					MTXunlock(NL_MTX_ENV);															\
				}																					\
			}																						\
			void __tz_lock(void) {																	\
				if (COREreentOK() != 0) {															\
					MTXsafeLock(NL_MTX_TZ);															\
				}																					\
			}																						\
			void __tz_unlock(void) {																\
				if (COREreentOK() != 0) {															\
					MTXunlock(NL_MTX_TZ);															\
				}																					\
			}																						\
			struct _reent *__getreent(void) {														\
				return((G_OSmtxOK == 0)																\
				      ? _impure_ptr																	\
				      : ((struct _reent *)(TSKmyID()->XtraData[0])));								\
			}
												/* For Newlib not built with __DYNAMIC_REENT__		*/
		#if (((OS_N_CORE) > 1) && ((OS_NEWLIB_REDEF) != 0))
		  #include <sys/config.h>
		  #ifndef __DYNAMIC_REENT__				/* Make sure is not built with __DYNAMIC_REENT__	*/
			#include <errno.h>					/* Must include them to make sure #undef works		*/
			#include <getopt.h>					/* and if included after mAbassi.h, will not undo	*/
			#include <iconv.h>					/* the defines done here							*/
			#include <malloc.h>					/* many were included at the top of the file		*/
			#include <signal.h>
			#include <time.h>
			#include <wchar.h>
			#include <sys/file.h>
			#include <sys/stat.h>
			#include <sys/unistd.h>

			#ifdef getc
			  #undef getc
			#endif
			#ifdef getchar
			  #undef getchar
			#endif
			#ifdef getchar_unlocked
			  #undef getchar_unlocked
			#endif
			#ifdef getwc
			  #undef getwc
			#endif
			#ifdef getwchar
			  #undef getwchar
			#endif
			#ifdef putc
			  #undef putc
			#endif
			#ifdef putchar
			  #undef putchar
			#endif
			#ifdef putchar_unlocked
			  #undef putchar_unlocked
			#endif
			#ifdef putwc
			  #undef putwc
			#endif
			#ifdef putwchar
			  #undef putwchar
			#endif
			#ifdef errno
			  #undef  errno
			#endif
			#define errno                  __errno_r (__getreent())
			#ifdef  stdin
			  #undef  stdin
			#endif
			#define stdin                  _stdin_r (__getreent())
			#ifdef  stdout
			  #undef  stdout
			#endif
			#define stdout                 _stdout_r(__getreent())
			#ifdef  stderr
			  #undef  stderr
			#endif
			#define stderr                 _stderr_r(__getreent())

			#define _getopt_long_only(...)  __getopt_long_only_r  (__getreent(), ## __VA_ARGS__)
			#define _getopt_long(...)       __getopt_long_r       (__getreent(), ## __VA_ARGS__)
			#define _getopt(...)            __getopt_r            (__getreent(), ## __VA_ARGS__)
			#define _srget(...)             __srget_r             (__getreent(), ## __VA_ARGS__)
			#define _swbuf(...)             __swbuf_r             (__getreent(), ## __VA_ARGS__)
			#define asiprintf(...)          _asiprintf_r          (__getreent(), ## __VA_ARGS__)
			#define asniprintf(...)         _asniprintf_r         (__getreent(), ## __VA_ARGS__)
			#define asnprintf(...)          _asnprintf_r          (__getreent(), ## __VA_ARGS__)
			#define asprintf(...)           _asprintf_r           (__getreent(), ## __VA_ARGS__)
			#define atoi(...)               _atoi_r               (__getreent(), ## __VA_ARGS__)
			#define atol(...)               _atol_r               (__getreent(), ## __VA_ARGS__)
			#define atoll(...)              _atoll_r              (__getreent(), ## __VA_ARGS__)
			#define calloc(...)             _calloc_r             (__getreent(), ## __VA_ARGS__)
			#define close(...)              _close_r              (__getreent(), ## __VA_ARGS__)
			#define diprintf(...)           _diprintf_r           (__getreent(), ## __VA_ARGS__)
			#define dprintf(...)            _dprintf_r            (__getreent(), ## __VA_ARGS__)
			#define drand48(...)            _drand48_r            (__getreent(), ## __VA_ARGS__)
			#define dtoa(...)               _dtoa_r               (__getreent(), ## __VA_ARGS__)
			#define erand48(...)            _erand48_r            (__getreent(), ## __VA_ARGS__)
			#define execve(...)             _execve_r             (__getreent(), ## __VA_ARGS__)
			#define fclose(...)             _fclose_r             (__getreent(), ## __VA_ARGS__)
			#define fcloseall(...)          _fcloseall_r          (__getreent(), ## __VA_ARGS__)
			#define fcntl(...)              _fcntl_r              (__getreent(), ## __VA_ARGS__)
			#define fdopen64(...)           _fdopen64_r           (__getreent(), ## __VA_ARGS__)
			#define fdopen(...)             _fdopen_r             (__getreent(), ## __VA_ARGS__)
			#define fflush(...)             _fflush_r             (__getreent(), ## __VA_ARGS__)
			#define fgetc(...)              _fgetc_r              (__getreent(), ## __VA_ARGS__)
			#define fgetpos64(...)          _fgetpos64_r          (__getreent(), ## __VA_ARGS__)
			#define fgetpos(...)            _fgetpos_r            (__getreent(), ## __VA_ARGS__)
			#define fgets(...)              _fgets_r              (__getreent(), ## __VA_ARGS__)
			#define fgetwc(...)             _fgetwc_r             (__getreent(), ## __VA_ARGS__)
			#define fgetws(...)             _fgetws_r             (__getreent(), ## __VA_ARGS__)
			#define _findenv(...)           _findenv_r            (__getreent(), ## __VA_ARGS__)
			#define fiprintf(...)           _fiprintf_r           (__getreent(), ## __VA_ARGS__)
			#define fiscanf(...)            _fiscanf_r            (__getreent(), ## __VA_ARGS__)
			#define fmemopen(...)           _fmemopen_r           (__getreent(), ## __VA_ARGS__)
			#define fopen64(...)            _fopen64_r            (__getreent(), ## __VA_ARGS__)
			#define fopen(...)              _fopen_r              (__getreent(), ## __VA_ARGS__)
			#define fopencookie(...)        _fopencookie_r        (__getreent(), ## __VA_ARGS__)
			#define fork(...)               _fork_r               (__getreent(), ## __VA_ARGS__)
			#define fprintf(...)            _fprintf_r            (__getreent(), ## __VA_ARGS__)
			#define fpurge(...)             _fpurge_r             (__getreent(), ## __VA_ARGS__)
			#define fputc(...)              _fputc_r              (__getreent(), ## __VA_ARGS__)
			#define fputs(...)              _fputs_r              (__getreent(), ## __VA_ARGS__)
			#define fputwc(...)             _fputwc_r             (__getreent(), ## __VA_ARGS__)
			#define fputws(...)             _fputws_r             (__getreent(), ## __VA_ARGS__)
			#define fread(...)              _fread_r              (__getreent(), ## __VA_ARGS__)
			#define free(...)               _free_r               (__getreent(), ## __VA_ARGS__)
			#define freopen64(...)          _freopen64_r          (__getreent(), ## __VA_ARGS__)
			#define freopen(...)            _freopen_r            (__getreent(), ## __VA_ARGS__)
			#define fscanf(...)             _fscanf_r             (__getreent(), ## __VA_ARGS__)
			#define fseek(...)              _fseek_r              (__getreent(), ## __VA_ARGS__)
			#define fseeko64(...)           _fseeko64_r           (__getreent(), ## __VA_ARGS__)
			#define fseeko(...)             _fseeko_r             (__getreent(), ## __VA_ARGS__)
			#define fsetpos64(...)          _fsetpos64_r          (__getreent(), ## __VA_ARGS__)
			#define fsetpos(...)            _fsetpos_r            (__getreent(), ## __VA_ARGS__)
			#define fstat(...)              _fstat_r              (__getreent(), ## __VA_ARGS__)
			#define fstat64(...)            _fstat64_r            (__getreent(), ## __VA_ARGS__)
			#define ftell(...)              _ftell_r              (__getreent(), ## __VA_ARGS__)
			#define ftello64(...)           _ftello64_r           (__getreent(), ## __VA_ARGS__)
			#define ftello(...)             _ftello_r             (__getreent(), ## __VA_ARGS__)
			#define funopen(...)            _funopen_r            (__getreent(), ## __VA_ARGS__)
			#define fwide(...)              _fwide_r              (__getreent(), ## __VA_ARGS__)
			#define fwprintf(...)           _fwprintf_r           (__getreent(), ## __VA_ARGS__)
			#define fwrite(...)             _fwrite_r             (__getreent(), ## __VA_ARGS__)
			#define fwscanf(...)            _fwscanf_r            (__getreent(), ## __VA_ARGS__)
			#define getc(...)               _getc_r               (__getreent(), ## __VA_ARGS__)
			#define getc_unlocked(...)      _getc_unlocked_r      (__getreent(), ## __VA_ARGS__)
			#define getchar(...)            _getchar_r            (__getreent(), ## __VA_ARGS__)
			#define getchar_unlocked(...)   _getchar_unlocked_r   (__getreent(), ## __VA_ARGS__)
			#define getenv(...)             _getenv_r             (__getreent(), ## __VA_ARGS__)
			#define getpid(...)             _getpid_r             (__getreent(), ## __VA_ARGS__)
			#define gets(...)               _gets_r               (__getreent(), ## __VA_ARGS__)
			#define getwc(...)              _getwc_r              (__getreent(), ## __VA_ARGS__)
			#define getwchar(...)           _getwchar_r           (__getreent(), ## __VA_ARGS__)
			#define iconv_close(...)        _iconv_close_r        (__getreent(), ## __VA_ARGS__)
			#define iconv_open(...)         _iconv_open_r         (__getreent(), ## __VA_ARGS__)
			#define iconv(...)              _iconv_r              (__getreent(), ## __VA_ARGS__)
			#define iprintf(...)            _iprintf_r            (__getreent(), ## __VA_ARGS__)
			#define iscanf(...)             _iscanf_r             (__getreent(), ## __VA_ARGS__)
			#define isatty(...)             _isatty_r             (__getreent(), ## __VA_ARGS__)
			#define jrand48(...)            _jrand48_r            (__getreent(), ## __VA_ARGS__)
			#define kill(...)               _kill_r               (__getreent(), ## __VA_ARGS__)
			#define l64a(...)               _l64a_r               (__getreent(), ## __VA_ARGS__)
			#define lcong48(...)            _lcong48_r            (__getreent(), ## __VA_ARGS__)
			#define link(...)               _link_r               (__getreent(), ## __VA_ARGS__)
			#define localeconv(...)         _localeconv_r         (__getreent(), ## __VA_ARGS__)
			#define lrand48(...)            _lrand48_r            (__getreent(), ## __VA_ARGS__)
			#define lseek(...)              _lseek_r              (__getreent(), ## __VA_ARGS__)
			#define lseek64(...)            _lseek64_r            (__getreent(), ## __VA_ARGS__)
			#define malloc(...)             _malloc_r             (__getreent(), ## __VA_ARGS__)
			#define malloc_usable_size(...) _malloc_usable_size_r (__getreent(), ## __VA_ARGS__)
			#define malloc_stats(...)       _malloc_stats_r       (__getreent(), ## __VA_ARGS__)
			#define malloc_trim(...)        _malloc_trim_r        (__getreent(), ## __VA_ARGS__)
			#define mallopt(...)            _mallopt_r            (__getreent(), ## __VA_ARGS__)
			#define mblen(...)              _mblen_r              (__getreent(), ## __VA_ARGS__)
			#define mbrtowc(...)            _mbrtowc_r            (__getreent(), ## __VA_ARGS__)
			#define mbsnrtowcs(...)         _mbsnrtowcs_r         (__getreent(), ## __VA_ARGS__)
			#define mbsrtowcs(...)          _mbsrtowcs_r          (__getreent(), ## __VA_ARGS__)
			#define mbstowcs(...)           _mbstowcs_r           (__getreent(), ## __VA_ARGS__)
			#define mbtowc(...)             _mbtowc_r             (__getreent(), ## __VA_ARGS__)
			#define memalign(...)           _memalign_r           (__getreent(), ## __VA_ARGS__)
			#define mkdir(...)              _mkdir_r              (__getreent(), ## __VA_ARGS__)
			#define mkdtemp(...)            _mkdtemp_r            (__getreent(), ## __VA_ARGS__)
			#define mkostemp(...)           _mkostemp_r           (__getreent(), ## __VA_ARGS__)
			#define mkostemps(...)          _mkostemps_r          (__getreent(), ## __VA_ARGS__)
			#define mkstemp(...)            _mkstemp_r            (__getreent(), ## __VA_ARGS__)
			#define mkstemps(...)           _mkstemps_r           (__getreent(), ## __VA_ARGS__)
			#define mktemp(...)             _mktemp_r             (__getreent(), ## __VA_ARGS__)
			#define mrand48(...)            _mrand48_r            (__getreent(), ## __VA_ARGS__)
			#define mstats(...)             _mstats_r             (__getreent(), ## __VA_ARGS__)
			#define nrand48(...)            _nrand48_r            (__getreent(), ## __VA_ARGS__)
			#define open(...)               _open_r               (__getreent(), ## __VA_ARGS__)
			#define open64(...)             _open64_r             (__getreent(), ## __VA_ARGS__)
			#define open_memstream(...)     _open_memstream_r     (__getreent(), ## __VA_ARGS__)
			#define open_wmemstream(...)    _open_wmemstream_r    (__getreent(), ## __VA_ARGS__)
			#define perror(...)             _perror_r             (__getreent(), ## __VA_ARGS__)
			#define printf(...)             _printf_r             (__getreent(), ## __VA_ARGS__)
			#define putc(...)               _putc_r               (__getreent(), ## __VA_ARGS__)
			#define putc_unlocked(...)      _putc_unlocked_r      (__getreent(), ## __VA_ARGS__)
			#define putchar(...)            _putchar_r            (__getreent(), ## __VA_ARGS__)
			#define putchar_unlocked(...)   _putchar_unlocked_r   (__getreent(), ## __VA_ARGS__)
			#define putenv(...)             _putenv_r             (__getreent(), ## __VA_ARGS__)
			#define puts(...)               _puts_r               (__getreent(), ## __VA_ARGS__)
			#define putwc(...)              _putwc_r              (__getreent(), ## __VA_ARGS__)
			#define putwchar(...)           _putwchar_r           (__getreent(), ## __VA_ARGS__)
			#define pvalloc(...)            _pvalloc_r            (__getreent(), ## __VA_ARGS__)
			#define raise(...)              _raise_r              (__getreent(), ## __VA_ARGS__)
			#define read(...)               _read_r               (__getreent(), ## __VA_ARGS__)
			#define realloc(...)            _realloc_r            (__getreent(), ## __VA_ARGS__)
			#define reallocf(...)           _reallocf_r           (__getreent(), ## __VA_ARGS__)
			#define remove(...)             _remove_r             (__getreent(), ## __VA_ARGS__)
			#define rename(...)             _rename_r             (__getreent(), ## __VA_ARGS__)
			#define rewind(...)             _rewind_r             (__getreent(), ## __VA_ARGS__)
			#define scanf(...)              _scanf_r              (__getreent(), ## __VA_ARGS__)
			#define sbrk(...)               _sbrk_r               (__getreent(), ## __VA_ARGS__)
			#define seed48(...)             _seed48_r             (__getreent(), ## __VA_ARGS__)
			#define setenv(...)             _setenv_r             (__getreent(), ## __VA_ARGS__)
			#define setlocale(...)          _setlocale_r          (__getreent(), ## __VA_ARGS__)
			#define signal(...)             _signal_r             (__getreent(), ## __VA_ARGS__)
			#define siprintf(...)           _siprintf_r           (__getreent(), ## __VA_ARGS__)
			#define siscanf(...)            _siscanf_r            (__getreent(), ## __VA_ARGS__)
			#define sniprintf(...)          _sniprintf_r          (__getreent(), ## __VA_ARGS__)
			#define snprintf(...)           _snprintf_r           (__getreent(), ## __VA_ARGS__)
			#define sprintf(...)            _sprintf_r            (__getreent(), ## __VA_ARGS__)
			#define srand48(...)            _srand48_r            (__getreent(), ## __VA_ARGS__)
			#define sscanf(...)             _sscanf_r             (__getreent(), ## __VA_ARGS__)
			#define stat(...)               _stat_r               (__getreent(), ## __VA_ARGS__)
			#define stat64(...)             _stat64_r             (__getreent(), ## __VA_ARGS__)
			#define strdup(...)             _strdup_r             (__getreent(), ## __VA_ARGS__)
			#define strndup(...)            _strndup_r            (__getreent(), ## __VA_ARGS__)
			#define strtod(...)             _strtod_r             (__getreent(), ## __VA_ARGS__)
			#define strtol(...)             _strtol_r             (__getreent(), ## __VA_ARGS__)
			#define strtoll(...)            _strtoll_r            (__getreent(), ## __VA_ARGS__)
			#define strtoul(...)            _strtoul_r            (__getreent(), ## __VA_ARGS__)
			#define strtoull(...)           _strtoull_r           (__getreent(), ## __VA_ARGS__)
			#define swprintf(...)           _swprintf_r           (__getreent(), ## __VA_ARGS__)
			#define swscanf(...)            _swscanf_r            (__getreent(), ## __VA_ARGS__)
			#define system(...)             _system_r             (__getreent(), ## __VA_ARGS__)
			#define tempnam(...)            _tempnam_r            (__getreent(), ## __VA_ARGS__)
			#define times(...)              _times_r              (__getreent(), ## __VA_ARGS__)
			#define tmpfile64(...)          _tmpfile64_r          (__getreent(), ## __VA_ARGS__)
			#define tmpfile(...)            _tmpfile_r            (__getreent(), ## __VA_ARGS__)
			#define tmpnam(...)             _tmpnam_r             (__getreent(), ## __VA_ARGS__)
			#define tzset(...)              _tzset_r              (__getreent(), ## __VA_ARGS__)
			#define ungetc(...)             _ungetc_r             (__getreent(), ## __VA_ARGS__)
			#define ungetwc(...)            _ungetwc_r            (__getreent(), ## __VA_ARGS__)
			#define unlink(...)             _unlink_r             (__getreent(), ## __VA_ARGS__)
			#define unsetenv(...)           _unsetenv_r           (__getreent(), ## __VA_ARGS__)
			#define unsetenv(...)           _unsetenv_r           (__getreent(), ## __VA_ARGS__)
			#define valloc(...)             _valloc_r             (__getreent(), ## __VA_ARGS__)
			#define vasniprintf(...)        _vasniprintf_r        (__getreent(), ## __VA_ARGS__)
			#define vasnprintf(...)         _vasnprintf_r         (__getreent(), ## __VA_ARGS__)
			#define vasprintf(...)          _vasprintf_r          (__getreent(), ## __VA_ARGS__)
			#define vdiprintf(...)          _vdiprintf_r          (__getreent(), ## __VA_ARGS__)
			#define vdprintf(...)           _vdprintf_r           (__getreent(), ## __VA_ARGS__)
			#define vfiprintf(...)          _vfiprintf_r          (__getreent(), ## __VA_ARGS__)
			#define vfiscanf(...)           _vfiscanf_r           (__getreent(), ## __VA_ARGS__)
			#define vfprintf(...)           _vfprintf_r           (__getreent(), ## __VA_ARGS__)
			#define vfscanf(...)            _vfscanf_r            (__getreent(), ## __VA_ARGS__)
			#define vfwprintf(...)          _vfwprintf_r          (__getreent(), ## __VA_ARGS__)
			#define vfwscanf(...)           _vfwscanf_r           (__getreent(), ## __VA_ARGS__)
			#define viprintf(...)           _viprintf_r           (__getreent(), ## __VA_ARGS__)
			#define viscanf(...)            _viscanf_r            (__getreent(), ## __VA_ARGS__)
			#define vprintf(...)            _vprintf_r            (__getreent(), ## __VA_ARGS__)
			#define vscanf(...)             _vscanf_r             (__getreent(), ## __VA_ARGS__)
			#define vsiprintf(...)          _vsiprintf_r          (__getreent(), ## __VA_ARGS__)
			#define vsiscanf(...)           _vsiscanf_r           (__getreent(), ## __VA_ARGS__)
			#define vsniprintf(...)         _vsniprintf_r         (__getreent(), ## __VA_ARGS__)
			#define vsnprintf(...)          _vsnprintf_r          (__getreent(), ## __VA_ARGS__)
			#define vsprintf(...)           _vsprintf_r           (__getreent(), ## __VA_ARGS__)
			#define vsscanf(...)            _vsscanf_r            (__getreent(), ## __VA_ARGS__)
			#define vswprintf(...)          _vswprintf_r          (__getreent(), ## __VA_ARGS__)
			#define vswscanf(...)           _vswscanf_r           (__getreent(), ## __VA_ARGS__)
			#define vwprintf(...)           _vwprintf_r           (__getreent(), ## __VA_ARGS__)
			#define vwscanf(...)            _vwscanf_r            (__getreent(), ## __VA_ARGS__)
			#define wait(...)               _wait_r               (__getreent(), ## __VA_ARGS__)
			#define wcrtomb(...)            _wcrtomb_r            (__getreent(), ## __VA_ARGS__)
			#define wcsdup(...)             _wcsdup_r             (__getreent(), ## __VA_ARGS__)
			#define wcsnrtombs(...)         _wcsnrtombs_r         (__getreent(), ## __VA_ARGS__)
			#define wcsrtombs(...)          _wcsrtombs_r          (__getreent(), ## __VA_ARGS__)
			#define wcstod(...)             _wcstod_r             (__getreent(), ## __VA_ARGS__)
			#define wcstof(...)             _wcstof_r             (__getreent(), ## __VA_ARGS__)
			#define wcstol(...)             _wcstol_r             (__getreent(), ## __VA_ARGS__)
			#define wcstoll(...)            _wcstoll_r            (__getreent(), ## __VA_ARGS__)
			#define wcstombs(...)           _wcstombs_r           (__getreent(), ## __VA_ARGS__)
			#define wcstoul(...)            _wcstoul_r            (__getreent(), ## __VA_ARGS__)
			#define wcstoull(...)           _wcstoull_r           (__getreent(), ## __VA_ARGS__)
			#define wctomb(...)             _wctomb_r             (__getreent(), ## __VA_ARGS__)
			#define wprintf(...)            _wprintf_r            (__getreent(), ## __VA_ARGS__)
			#define write(...)              _write_r              (__getreent(), ## __VA_ARGS__)
			#define wscanf(...)             _wscanf_r             (__getreent(), ## __VA_ARGS__)
			#define asctime(...)            asctime_r             (__getreent(), ## __VA_ARGS__)
			#define ctime(...)              ctime_r               (__getreent(), ## __VA_ARGS__)
			#define getdate(...)            getdate_r             (__getreent(), ## __VA_ARGS__)
			#define getlogin(...)           getlogin_r            (__getreent(), ## __VA_ARGS__)
			#define gmtime(...)             gmtime_r              (__getreent(), ## __VA_ARGS__)
			#define rand(...)               rand_r                (__getreent(), ## __VA_ARGS__)
			#define strerror(...)           strerror_r            (__getreent(), ## __VA_ARGS__)
			#define strtok(...)             strtok_r              (__getreent(), ## __VA_ARGS__)
			#define ttyname(...)            ttyname_r             (__getreent(), ## __VA_ARGS__)
		  #endif
		#endif

	#else										/* GCC: internal error without this do nothing		*/
		#define OX_TASK_XTRA(_TskDsc, _Fct)		/* TC007B-hook #751 -O3 */							\
			OX_DO_NOTHING()
	#endif

/* ------------------------------------------------------------------------------------------------ */
/* IAR - LIBRARY RE-ENTRANCE PROTECTION																*/
/* ------------------------------------------------------------------------------------------------ */

#elif defined(__IAR_SYSTEMS_ICC__)

	#ifndef OS_IAR_MTHREAD
		#define OS_IAR_MTHREAD	0
	#endif

  	#if ((OS_IAR_MTHREAD) != 0)					/* Library multi-threading protection				*/
		#include <yvals.h>
		#include <DLib_Threads.h>

		#define OX_LIB_REENT_PROTECT	(OS_IAR_MTHREAD)
		#define OX_SEM_PARKING			1		/* Needed due to alloc / free of mutexes			*/
		#ifdef OX_TASK_XTRA_FIELD_1
			#error "With library re-entrance protection enabled, 1st entry in XTRA_FIELD is"
			#error "reserved.  Use a higher OX_TASK_XTRA_FIELD_n"
		#else
			#define OX_TASK_XTRA_FIELD_1	1
		#endif

		#if (defined(__ABASSI_C__) || defined(__MABASSI_C__) || defined(__UABASSI_C__))
			int G_OSmtxOK;						/* No need to set to zero as BSS is zeroed			*/
		#else
			extern int G_OSmtxOK;
		#endif

		#define OX_DEVICE_PREINIT()																	\
			do {																					\
				G_OSmtxOK = 1;																		\
				OX_INT_CTRL_INIT();																	\
			} while(0)
												/* Multi-thread protect changed in version 8.11.3	*/
		#if (defined(__ARM_PROFILE_M__) && (__VER__ >= 8011001))
			#if defined(__ARM_PROFILE_M__)		/* Provision when more target processors changed	*/
				#define OS_IAR_REENT_ACCESS_FCT		__aeabi_read_tp
				#define OS_IAR_REENT_SECTION		"__iar_tls$$DATA"
			#else
				#error "IAR Reentrance - must define the access function"
			#endif

			#if (defined(__ABASSI_C__) || defined(__MABASSI_C__) || defined(__UABASSI_C__))
				#pragma section=OS_IAR_REENT_SECTION
			#endif

			#define OX_XTRA_FCT																		\
				void * OS_IAR_REENT_ACCESS_FCT(void)												\
				{																					\
				void *MTptr;																		\
					MTptr = (void *)__section_begin(OS_IAR_REENT_SECTION);							\
					if (TSKmyID() != (TSK_t *)NULL) {												\
						if (TSKmyID()->XtraData[0] != (intptr_t)0) {								\
						    MTptr = (void *)TSKmyID()->XtraData[0];									\
						}																			\
					}																				\
					return(MTptr);																	\
				}

			#if ((OS_IAR_MTHREAD) > 0)			/* Multi-thread protection on all tasks				*/
				#if (defined(__ABASSI_C__) || defined(__MABASSI_C__) || defined(__UABASSI_C__))
					#define OX_TASK_XTRA(_TskDsc,_Fct) 												\
						do {																		\
							if ((_Fct) != NULL) {													\
							    void *MTptr;														\
								MTptr = OSalloc(__iar_tls_size());									\
								__iar_tls_init(MTptr);												\
								(_TskDsc)->XtraData[0] = (intptr_t)MTptr;							\
							}																		\
						} while(0)
				#else								/* When used outside of Abassi.c by TSK_SETUP()	*/
			  		#define OX_TASK_XTRA(_TskDsc, _Fct)	/* there is no need to check for A&E	*/	\
						do {																		\
					    	void *MTptr;															\
							MTptr = OSalloc(__iar_tls_size());										\
							__iar_tls_init(MTptr);													\
							(_TskDsc)->XtraData[0] = (intptr_t)MTptr;								\
						} while(0)
				#endif

				#define TSKmultThrd(_TskDsc)	OX_DO_NOTHING()

			#else
				#define TSKmultThrd(_TskDsc)														\
					do {																			\
						void *MTptr;																\
						MTptr = OSalloc(__iar_tls_size());											\
						__iar_tls_init(MTptr);														\
						(_TskDsc)->XtraData[0] = (intptr_t)MTptr;									\
					} while(0)

			#endif
												/* ARM pre-version 8.11.1 or non-ARM				*/
		#elif ((_DLIB_THREAD_SUPPORT) < 2)		/* ==2 is mutexes only, ==3 is mutexes + TLS		*/
			#error "Multi-thread protection is not supported by the current DLib"
												/* When 0 & 1, there are no multi-thread support	*/
		#else
			#if ((_DLIB_THREAD_SUPPORT) == 3)	/* TLS are supported								*/
				#define OX_XTRA_FCT																	\
					void _DLIB_TLS_MEMORY *__iar_dlib_perthread_access(void _DLIB_TLS_MEMORY *Symb)	\
					{																				\
					char _DLIB_TLS_MEMORY *MTptr;													\
						MTptr = (char _DLIB_TLS_MEMORY *)__segment_begin("__DLIB_PERTHREAD");		\
						if (TSKmyID() != (TSK_t *)NULL) {											\
							if (TSKmyID()->XtraData[0] != (intptr_t)0) {							\
							    MTptr = (void *)TSKmyID()->XtraData[0];								\
							}																		\
						}																			\
						MTptr += __IAR_DLIB_PERTHREAD_SYMBOL_OFFSET(Symb);							\
						return((void _DLIB_TLS_MEMORY *)MTptr);										\
					}

				#if ((OS_IAR_MTHREAD) > 0)		/* Multi-thread protection on all tasks				*/
					#if (defined(__ABASSI_C__) || defined(__MABASSI_C__) || defined(__UABASSI_C__))
						#define OX_TASK_XTRA(_TskDsc,_Fct) 											\
							do {																	\
								if ((_Fct) != NULL) {												\
								    void *MTptr;													\
									MTptr = OSalloc(__IAR_DLIB_PERTHREAD_SIZE);						\
									__iar_dlib_perthread_initialize(MTptr);							\
									(_TskDsc)->XtraData[0] = (intptr_t)MTptr;						\
								}																	\
							} while(0)
					#else							/* When used outside of Abassi.c by TSK_SETUP()	*/
				  		#define OX_TASK_XTRA(_TskDsc, _Fct)	/* there is no need to check for A&E*/	\
							do {																	\
						    	void *MTptr;														\
								MTptr = OSalloc(__IAR_DLIB_PERTHREAD_SIZE);							\
								__iar_dlib_perthread_initialize(MTptr);								\
								(_TskDsc)->XtraData[0] = (intptr_t)MTptr;							\
							} while(0)
					#endif

					#define TSKmultThrd(_TskDsc)	OX_DO_NOTHING()

				#else
					#define TSKmultThrd(_TskDsc)													\
						do {																		\
							void *MTptr;															\
							MTptr = OSalloc(__IAR_DLIB_PERTHREAD_SIZE);								\
							__iar_dlib_perthread_initialize(MTptr);									\
							(_TskDsc)->XtraData[0] = (intptr_t)MTptr;								\
						} while(0)
				#endif
			#endif
		#endif
	#endif

/* ------------------------------------------------------------------------------------------------ */
/* END OF LIBRARY RE-ENTRANCE PROTECTION															*/
/* ------------------------------------------------------------------------------------------------ */

#endif

/* ------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------ */
/* CMSIS EXTRA SET-UP																				*/

#ifdef OS_CMSIS_RTOS							/* Special stuff for CMSIS V3.0						*/

	#ifndef OX_DEVICE_INIT_XTRA
		#define OX_DEVICE_INIT_XTRA()	OX_DO_NOTHING()
	#endif

	#if (defined(__ABASSI_C__) || defined(__MABASSI_C__) || defined(__UABASSI_C__))
		int G_OSstarted = 0;					/* CMSIS needs to know if kernel started			*/
	#else
		extern int G_OSstarted;
	#endif

	#define OX_DEVICE_INIT() 																		\
		do {																						\
			OX_DEVICE_INIT_XTRA();																	\
			G_OSstarted = 1;																		\
			TSKsetPrio(TSKmyID(), 3);																\
		} while(0)
#endif

/* ------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------ */
/* LEFT OVER WHEN LIBRARY REENTRANCE PROTECTION AND/OR CMSIS NOT USED								*/

#if !defined(OX_DEVICE_PREINIT)
	#define OX_DEVICE_PREINIT()																		\
		do {																						\
			OX_INT_CTRL_INIT();																		\
		} while(0)
#endif

#if defined(OX_DEVICE_INIT_XTRA)
	#define OX_DEVICE_INIT()	OX_DEVICE_INIT_XTRA()
#endif

/* ------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------ */
/* DO NOT MODIFY ANYTHING BELOW THIS LINE UNLESS YOU ARE SURE YOU KNOW WHAT YOU ARE DOING			*/
/* DO NOT MODIFY ANYTHING BELOW THIS LINE UNLESS YOU ARE SURE YOU KNOW WHAT YOU ARE DOING			*/
/* DO NOT MODIFY ANYTHING BELOW THIS LINE UNLESS YOU ARE SURE YOU KNOW WHAT YOU ARE DOING			*/
/* ------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------ */

/* ------------------------------------------------------------------------------------------------ */
/* This macro is used to define the stack size and the stack memory itself as needed by uAbassi		*/
/* start-up code.																					*/
/* The macro arguments are:																			*/
/* Mode : Stack for the indicated processor "Mode".  All following modes must be defined:			*/
/*			        	ABORT, FIQ, IRQ, SUPER, UNDEF												*/
/* Size : Size in bytes of the stack allocated for each core.										*/
/*        It is not possible to set different stack sizes between the cores.						*/
/* ------------------------------------------------------------------------------------------------ */

#define DEF_MODE_STACK_SIZE(Mode, Size)																\
				const int G_ ## Mode ## stackSize = (OX_N_CORE) * (Size);							\
				OSalign_t G_ ## Mode ## stack      [(OX_N_CORE) * ((Size)/sizeof(OSalign_t))]


/* ------------------------------------------------------------------------------------------------ */
/* Build options validation																			*/
/* ------------------------------------------------------------------------------------------------ */

#ifndef OS_MAX_PEND_RQST
  #error "Abassi: The build option OS_MAX_PEND_RQST hasn't been defined"
#elif ((OS_MAX_PEND_RQST) < 2U)
  #error "Abassi: The build option OS_MAX_PEND_RQST must be > 1"
  #error "        It defines the size of the queue to absorb kernel requests during interrupts"
#endif

#ifndef OS_N_CORE
  #error "Abassi: The build option OS_N_CORE hasn't been defined"
#elif ((OS_N_CORE) < 2)
  #error "Abassi: The build option OS_N_CORE must be >= 2"
#endif

#ifndef OS_TIMER_US
  #error "Abassi: The build option OS_TIMER_US hasn't been defined"
#elif ((OS_TIMER_US) < 0)
  #error "Abassi: The build option OS_TIMER_US is negative"
  #error "        Must be positive (>0) as it defines the period of the timer tick"
#endif
#define OX_DO_NOTHING()			do {int _=0;_=_;} while(0)


#define OX_HANDLE_MTX			1
#define OX_STATIC

/* ------------------------------------------------------------------------------------------------ */
/* Overloading of build definitions																	*/
/* All build options are remapped to OX_XXX to avoid confusion when using the tokens				*/
/* From now on, all build options are OX_XXX														*/
/* ------------------------------------------------------------------------------------------------ */

#ifndef OX_BSS_ZERO
  #define OX_BSS_ZERO			(OS_BSS_ZERO)
#endif
#ifndef OX_ISR_TBL_OFFSET
  #define OX_ISR_TBL_OFFSET		0
#endif
#ifndef OX_LIB_REENT_PROTECT
  #define OX_LIB_REENT_PROTECT	0
#endif
#ifndef OX_MAX_PEND_RQST
  #define OX_MAX_PEND_RQST		(OS_MAX_PEND_RQST)
#endif
#ifndef OX_MIN_STACK_USE
  #define OX_MIN_STACK_USE		(OS_MIN_STACK_USE)
#endif
#ifndef OX_N_INTERRUPTS
  #define OX_N_INTERRUPTS		(OS_N_INTERRUPTS)
#endif
#ifndef OX_NESTED_INTS
 #ifndef OS_NESTED_INTS
  #error "Abassi: The build option OS_NESTED_INTS hasn't been defined"
 #endif
  #define OX_NESTED_INTS		(OS_NESTED_INTS)
#endif
#ifndef OX_PRIO_MIN
  #define OX_PRIO_MIN			(OS_PRIO_MIN)
#endif
#ifndef OS_SPINLOCK_BASE
  #define OS_SPINLOCK_BASE		0
#endif
#ifndef OX_SPINLOCK_BASE
  #define OX_SPINLOCK_BASE		(OS_SPINLOCK_BASE)
#endif
#ifndef OS_SEM_XTRA_FIELD
  #define OS_SEM_XTRA_FIELD			(0)
#else
  #if ((OS_SEM_XTRA_FIELD) < 0)
	#error "OS_SEM_XTRA_FIELD must be non-negative"
  #endif
#endif
#define OX_SEM_XTRA_MY_IDX			 (OS_SEM_XTRA_FIELD)
#define OX_SEM_1ST_XTRA_FIELD		 (0)			/* Defined for compatibility with Task			*/
#if defined(OX_SEM_XTRA_FIELD_5)
  #define OX_SEM_XTRA_FIELD			((OS_SEM_XTRA_FIELD)+5)
#elif defined(OX_SEM_XTRA_FIELD_4)
  #define OX_SEM_XTRA_FIELD			((OS_SEM_XTRA_FIELD)+4)
#elif defined(OX_SEM_XTRA_FIELD_3)
  #define OX_SEM_XTRA_FIELD			((OS_SEM_XTRA_FIELD)+3)
#elif defined(OX_SEM_XTRA_FIELD_2)
  #define OX_SEM_XTRA_FIELD			((OS_SEM_XTRA_FIELD)+2)
#elif defined(OX_SEM_XTRA_FIELD_1)
  #define OX_SEM_XTRA_FIELD			((OS_SEM_XTRA_FIELD)+1)
#else
  #define OX_SEM_XTRA_FIELD			 (OS_SEM_XTRA_FIELD)
#endif

#if defined(OX_TASK_XTRA_FIELD_5)					/* Task different: low index may be internal	*/
  #define OX_TASK_1ST_XTRA_FIELD	(OX_TASK_XTRA_FIELD_5)
#elif defined(OX_TASK_XTRA_FIELD_4)
  #define OX_TASK_1ST_XTRA_FIELD	(OX_TASK_XTRA_FIELD_4)
#elif defined(OX_TASK_XTRA_FIELD_3)
  #define OX_TASK_1ST_XTRA_FIELD	(OX_TASK_XTRA_FIELD_3)
#elif defined(OX_TASK_XTRA_FIELD_2)
  #define OX_TASK_1ST_XTRA_FIELD	(OX_TASK_XTRA_FIELD_2)
#elif defined(OX_TASK_XTRA_FIELD_1)
  #define OX_TASK_1ST_XTRA_FIELD	(OX_TASK_XTRA_FIELD_1)
#else
  #define OX_TASK_1ST_XTRA_FIELD	(0)
#endif
#ifndef OS_TASK_XTRA_FIELD
  #define OS_TASK_XTRA_FIELD		(0)
#else
  #if ((OS_TASK_XTRA_FIELD) < 0)
	#error "OS_TASK_XTRA_FIELD must be non-negative"
  #endif
#endif
#define OX_TASK_XTRA_FIELD			((OX_TASK_1ST_XTRA_FIELD)+(OS_TASK_XTRA_FIELD))

#ifdef OS_TIM_TICK_ACK
 #ifndef OX_TIM_TICK_ACK
  #define OX_TIM_TICK_ACK()		OS_TIM_TICK_ACK()
 #endif
#endif
#ifndef OX_TIMER_US
  #define OX_TIMER_US			(OS_TIMER_US)
#endif
#ifndef OX_STR_CONST
  typedef const char OSstrCnst_t;
#endif

#ifndef REENT_POST
  #define REENT_POST
#endif

#if ((OX_SYS_CALL) != 0)
  #ifndef OX_SYS_CALL_SIZE
    #define OX_SYS_CALL_SIZE	2				/* SysCall used, when size not set, most lib use 2	*/
  #endif
#endif
#ifndef OX_SYS_CALL_SIZE
  #define OX_SYS_CALL_SIZE		0
#endif

/* ------------------------------------------------------------------------------------------------ */
/* Defintion mapping RTOS timer tick <--> human time												*/
/* ------------------------------------------------------------------------------------------------ */

#if ((OX_TIMER_US) != 0)						/* If the timer is used, a few human definitions   	*/
  #define OS_TICK_PER_SEC	((int)(((((long)(OX_TIMER_US))/2)+     1000000L ) /((long)(OX_TIMER_US))))

  #define ZZ_MS_TO_TICK(x)	((int)(((((long)(OX_TIMER_US))/2)+((x)*   1000L ))/((long)(OX_TIMER_US))))
  #define ZZ_SEC_TO_TICK(x) ((int)(((((long)(OX_TIMER_US))/2)+((x)*1000000LL))/((long)(OX_TIMER_US))))
  #define OS_MS_TO_TICK(xx)				((((signed)(xx))<0)?-1:(ZZ_MS_TO_TICK(xx)))
  #define OS_SEC_TO_TICK(xx)			((((signed)(xx))<0)?-1:(ZZ_SEC_TO_TICK(xx)))
  #define OS_HMS_TO_TICK(h,m,s)			(OS_SEC_TO_TICK(((h)*60+(m))*60+(s)))

  #define OS_TICK_TO_MIN_TICK(x,m)		(((((signed)(x))<0)||(((signed)(m))<0))?-1:(				\
										(((signed)(x))>((signed)(m)))?(x):(m)))
  #define OS_MS_TO_MIN_TICK(x,m)		(OS_TICK_TO_MIN_TICK(OS_MS_TO_TICK(x),m))

  #define OS_MS_EXP(m)					(OS_TICK_EXP(OS_MS_TO_TICK(m)))
  #define OS_TICK_EXP(x)				(G_OStimCnt+(x))
  #define OS_MS_TO_MIN_TICK_EXP(x,m)	(OS_TICK_TO_MIN_TICK_EXP(OS_MS_TO_TICK(x),m))
  #define OS_TICK_TO_MIN_TICK_EXP(x,m)	(G_OStimCnt+(OS_TICK_TO_MIN_TICK(x,m)))

  #define OS_HAS_TIMEDOUT(x)			((G_OStimCnt-((int)(x)))>=0)

  #define OS_TICK_EXPIRY(xx,mm)			(OS_MS_TO_MIN_TICK_EXP(xx,mm))	/* LEGACY!!!				*/
																		/* Should use OS_TICK_EXP()	*/
#endif

/* ------------------------------------------------------------------------------------------------ */
/* Data types & definitions																			*/
/* ------------------------------------------------------------------------------------------------ */

/* ------------------------------------------------	*/
/* Semaphore descriptor								*/

typedef struct _SEM_t {							/* Semaphore descriptor								*/
	struct _TSK_t *Blocked;						/* Linked list of tasks blocked by this semaphore	*/
	struct _TSK_t *MtxOwner;					/* Owner / locker of the mutex (when it is a mutex)	*/
	struct _SEM_t *MtxNext;						/* The next Mutex owned by the same task			*/
	const char    *SemName;						/* Name of the semaphore							*/
	struct _SEM_t *SemaNext;					/* Next semaphore in system (when searching name)	*/
	int   Value;								/* Semaphore counter								*/
    int            IsMtx;						/* Mutex or semaphore								*/
	struct _SEM_t *ParkNext; 					/* Keep the "destroyed" mutex in a parking lot		*/
  #if (OX_SEM_XTRA_FIELD)
	intptr_t XtraData[OX_SEM_XTRA_FIELD];
  #endif
} SEM_t;

/* ------------------------------------------------	*/
/* Mutex descriptor									*/

typedef SEM_t MTX_t;							/* Mutexes are same data type as semaphores			*/

/* ------------------------------------------------	*/
/* Task descriptor									*/

typedef struct _TSK_t {							/* Process descriptor								*/
	void       *Stack;							/* Stack pointer when not running (context save)	*/
  #if (OX_TASK_XTRA_FIELD)						/* Some ports require custom information in here	*/
	intptr_t    XtraData[OX_TASK_XTRA_FIELD];
  #endif
	SEM_t       Priv;							/* Private semaphore								*/
	SEM_t      *Blocker;						/* Semaphore blocking this task						*/
	struct _TSK_t *Next;						/* Next task blocked/ready to run					*/
	struct _TSK_t *Prev;						/* Previous task blocked/ready to run				*/
	struct _TSK_t *Last;						/* Last ready with same priority: eliminates a scan	*/
	const char    *TskName;						/* Name of the task									*/
	struct _TSK_t *TaskNext;					/* Next task in the list (to search name)			*/
	SEM_t         *MyMutex;						/* Linked list of all mutex I'm the owner			*/
	void          *TaskArg;						/* Pointer to the argument of the task				*/
	struct _TSK_t *ToutNext;					/* Next task in the timeout linked list				*/
	struct _TSK_t *ToutPrev;					/* Previous task in the timeout linked list			*/
	int            TickTime;					/* RTOS counter tick value for timeout				*/
	int  PrevRetVal;							/* Return value before getting suspended			*/
	int         Prio;							/* Current priority of the task						*/
	unsigned int SuspRqst;						/* Request to suspend the task (Boolean)			*/
	int MyCore;									/* Core # (-1: not running) speeds load balancing	*/
	int TargetCore;								/* With BMP, needs to hold the target core info		*/
	void *EvtDsc;								/* When emulation is used							*/
	intptr_t SysCall[OX_SYS_CALL_SIZE];
	struct _TSK_t *ParkNext; 					/* Keep the "destroyed" in a parking lot			*/
} TSK_t;

/* ------------------------------------------------	*/
/* Kernel requests bit masks (must fit in 16 bits)	*/
												/* MISRA has issues with (1U<<XX)					*/
#define ABASSI_BIN         (0x0001U)			/* Binary semaphore & extra tag to some commands	*/
#define ABASSI_WAIT        (0x0002U)			/* Regular semaphore waiting / mutex unlocking		*/
#define ABASSI_MTX         (0x0004U)			/* Mutex priority inheritance checking				*/
#define ABASSI_POST        (0x0008U)			/* Semaphore posting / mutex unlocking				*/
#define ABASSI_TOUT_RM     (0x0010U)			/* Remove from timeout linked list					*/
#define ABASSI_TOUT_ADD    (0x0020U)			/* Add in the timeout list							*/
#define ABASSI_TOUT_CHK    (0x0040U)			/* Check timer expiry's								*/
#define ABASSI_ADD_BLK     (0x0080U)			/* Add the task to the blocked list					*/
#define ABASSI_ADD_RUN     (0x0100U)			/* Add the task to the ready to run list			*/
#define ABASSI_RESUSP      (0x2000U)			/* Suspend or resume a task							*/

#define ABASSI_TOUT_TSK    (0xB000U)			/* Update the time out a task is blocked on			*/
#define ABASSI_TOUT_RM0    (ABASSI_BIN)			/* Remove from timeout list + zero TimedOut			*/
#define ABASSI_SUSPEND     (ABASSI_BIN)			/* For ABASSI_RESUSP this means to suspend			*/

/* ------------------------------------------------	*/
/* Global variables									*/

  extern volatile        int G_CoreIdleDone[OX_N_CORE];
extern volatile unsigned int G_OSisrState[7][OX_N_CORE];	/* ISR state for each core				*/
extern volatile unsigned int G_OSstate;			/* Kernel state: !=0 is Core#+1 using the kernel	*/

#if ((OX_N_INTERRUPTS) > 0)
  extern        void (*G_OSisrTbl[OX_N_INTERRUPTS])(void) REENT_POST;	/* Table used by ISRdispatch*/
#else
  extern        void (*G_OSisrTbl[1])(void) REENT_POST;	/* Imported/sized in ASM file, dummy size	*/
#endif
extern OSstrCnst_t     G_OSprivName[5];				/* Name for a task's private semaphore			*/
extern OSstrCnst_t     G_OSnoName[4];				/* Name for un-named components					*/
extern          TSK_t *G_OStaskNow[OX_N_CORE];		/* Currently running tasks on each core			*/
extern volatile int    G_OStimCnt;					/* RTOS time base counter tick					*/
extern          MTX_t *G_OSmutex;				    /* OS needs a mutex for some service creation	*/

/* ------------------------------------------------	*/
/* Atomic function prototypes & other components	*/

extern int      Abassi      (unsigned int Ops, void *Ptr, intptr_t Arg) REENT_POST;

extern int  COREreentOK(void);
extern int  COREgetID  (void) REENT_POST;
extern void CORElock   (int LockNmb, volatile void *Address, int WaitFor, int WrtVal) REENT_POST;
extern void COREunlock (int LockNmb, volatile void *Address, int WrtVal) REENT_POST;
extern void SPINlock(void);
extern int  SPINtrylock(void);
extern void SPINunlock(void);

  extern TSK_t *COREtaskNow(void) REENT_POST;

extern void    *OSalloc     (size_t MemSize) REENT_POST;
extern void     OScontext   (TSK_t *NewTask, TSK_t **TaskNowPtr) REENT_POST;
extern void     OSinvalidISR(void) REENT_POST;
extern int      OSisrInfo   (void) REENT_POST;
extern void    *OSstack     (void *StackBase, int StackSize, void (*TskFct)(void) REENT_POST)
                             REENT_POST;
extern void     OSstart     (void);
#ifndef OSnoTask
  extern void   OSnoTask    (void) REENT_POST;
#endif

extern  int			       OSintCtrl(int State);/* Function that deals with both dint() and eint()	*/
#define OSdint()		  (OSintCtrl(0))		/* Could split into 2 functions but only a few		*/
#define OSeint(x)	((void)OSintCtrl(x))		/* CPU cycles are added on OSdint(), not OSeint()	*/

extern void OSintBack(int ISRstate);
extern int  OSintOff(void);
extern void OSintOn(void);

  extern SEM_t *SEM__open   (const char *Name, unsigned int Type) REENT_POST;
  extern TSK_t *TSKcreate   (const char *Name, int TskPrio,int StackSize,void (*Fct)(void) REENT_POST,
                             int State, ...) REENT_POST;
extern void     TIMcallBack (void) REENT_POST;
  extern TSK_t *TSKgetID	(const char *Name) REENT_POST;
extern void     TSKstart    (void (*TaskFct)(void)) REENT_POST;

												/* Core Idle tasks. Declared here in case the		*/
extern void COREstart0 (void) REENT_POST;		/* application supplies one or more. It sets the	*/
extern void COREstart1 (void) REENT_POST;		/* function prototype for the application			*/
extern void COREstart2 (void) REENT_POST;
extern void COREstart3 (void) REENT_POST;
extern void COREstart4 (void) REENT_POST;
extern void COREstart5 (void) REENT_POST;
extern void COREstart6 (void) REENT_POST;
extern void COREstart7 (void) REENT_POST;
extern void COREstart8 (void) REENT_POST;
extern void COREstart9 (void) REENT_POST;
extern void COREstart10(void) REENT_POST;
extern void COREstart11(void) REENT_POST;
extern void COREstart12(void) REENT_POST;
extern void COREstart13(void) REENT_POST;
extern void COREstart14(void) REENT_POST;
extern void COREstart15(void) REENT_POST;
extern void COREstart16(void) REENT_POST;
extern void COREstart17(void) REENT_POST;
extern void COREstart18(void) REENT_POST;
extern void COREstart19(void) REENT_POST;
extern void COREstart20(void) REENT_POST;
extern void COREstart21(void) REENT_POST;
extern void COREstart22(void) REENT_POST;
extern void COREstart23(void) REENT_POST;
extern void COREstart24(void) REENT_POST;
extern void COREstart25(void) REENT_POST;
extern void COREstart26(void) REENT_POST;
extern void COREstart27(void) REENT_POST;
extern void COREstart28(void) REENT_POST;
extern void COREstart29(void) REENT_POST;
extern void COREstart30(void) REENT_POST;
extern void COREstart31(void) REENT_POST;
#if ((OX_N_CORE) > 32)
	#error "Abassi: Too many cores required"
	#error "        Contact Code Time Technologies to increase the maximum"
#endif

/* ------------------------------------------------	*/
/* Function defines									*/

  extern unsigned int  COREisInISR   (void) REENT_POST;
#if ((OX_N_INTERRUPTS) != 0)
  #define OSisrInstall(Nmb, Fct)	(G_OSisrTbl[(Nmb)+(OX_ISR_TBL_OFFSET)]=(Fct))
#endif

typedef void TSKfct_t(void);						/* Useful for C++ when testing					*/
extern  void OSshell(void);

/* ------------------------------------------------	*/
/* Mutexes related macros							*/

  #define MTXopen(_Name)		(SEM__open((_Name), 1U))
#define MTXowner(_Mtx)			((_Mtx)->MtxOwner)
#define MTXlock(_Mtx, _Tout)	(Abassi(((ABASSI_WAIT)|(ABASSI_MTX)|(ABASSI_BIN)), (void *)(_Mtx),  \
								        (intptr_t)(_Tout)))
#define MTXunlock(_Mtx)			(Abassi(((ABASSI_POST)|(ABASSI_MTX)), (void *)(_Mtx), (intptr_t)0))
													/* Internal use: for ISRs disabled at start-up	*/
#define MTXsafeLock(_Mtx)		do {int _=0;_=_; } while (0 != MTXlock(_Mtx, -(OSisrInfo()!=0)))


/* ------------------------------------------------	*/
/* Semaphores related macros						*/

  #define SEMopen(_Name)		(SEM__open((_Name), 0U))
#define SEMpost(_Sem)			((void)Abassi((ABASSI_POST), (void *)(_Sem), (intptr_t)0))
#define SEMreset(_Sem)			SEMwaitBin(_Sem, 0)
#define SEMwait(_Sem, _Tout)	(Abassi((ABASSI_WAIT), (void *)(_Sem), (intptr_t)(_Tout)))
#define SEMwaitBin(_Sem, _Tout)	(Abassi(((ABASSI_WAIT)|(ABASSI_BIN)), (void *)(_Sem),				\
								        (intptr_t)(_Tout)))

/* ------------------------------------------------	*/
/* Tasks related macros								*/

#define TSKgetPrio(_Tsk)					(((volatile TSK_t *)(_Tsk))->Prio)
#define TSKmyID()							(COREtaskNow())
  #define TSKgetCore(_Tsk, _CoreID)			((_Tsk)->TargetCore)
  #define TSKsetCore(_Tsk, _CoreID)			((_Tsk)->TargetCore = (_CoreID))

  #define TSKresume(_Tsk)		((void)Abassi((ABASSI_RESUSP),  (void *)(_Tsk),  (intptr_t)0))
  #define TSKsuspend(_Tsk)		((void)Abassi(((ABASSI_RESUSP)|(ABASSI_SUSPEND)), (void *)(_Tsk),	\
								              (intptr_t)-1))
#define TSKselfSusp()			do {																\
									TSK_t *Me = TSKmyID();											\
									((void)Abassi((ABASSI_WAIT), (void *)&(Me->Priv),(intptr_t)-1));\
								} while(0)

  extern void TIMtick(void) REENT_POST;
	#define TSKsleep(_TimeOut)	 ((void)Abassi((ABASSI_WAIT), (void *)&(TSKmyID()->Priv),			\
								               (intptr_t)(_TimeOut)))
    #define TSKtout(_Tsk, _Tout)        Abassi((ABASSI_TOUT_TSK), (void *)(_Tsk), (intptr_t)_Tout)
	#define TSKtimeoutKill(_Tsk) ((void)Abassi((ABASSI_TOUT_TSK), (void *)(_Tsk), (intptr_t)0))

  #define OX_TOUT_NOTBLK(_tsk)	((TSK_t *)NULL == ((volatile TSK_t *)(_tsk))->ToutPrev)

#define TSKstate(_Tsk)			((SEM_t *)NULL == (((volatile TSK_t *)(_Tsk))->Blocker)				\
								? 0								/* 0 is running		*/				\
								: (((((volatile TSK_t *)(_Tsk))->Blocker							\
								                           == (&((volatile TSK_t *)(_Tsk))->Priv))	\
								  && (OX_TOUT_NOTBLK(_Tsk)))										\
								  ? -1			/* -ve is suspended, +ve is blocked */			 	\
								  :  1))

#define TSKisRdy(_Tsk)			((SEM_t *)NULL == ((volatile TSK_t *)(_Tsk))->Blocker)
#define TSKisBlk(_Tsk)			(TSKstate(_Tsk) > 0)
#define TSKisSusp(_Tsk)			((((volatile TSK_t *)(_Tsk))->Blocker								\
								                          == (&((volatile TSK_t *)(_Tsk))->Priv))	\
								    && (OX_TOUT_NOTBLK(_Tsk)))
  #define TSKsetArg(_Tsk, _Arg)	((_Tsk)->TaskArg=((void *)(intptr_t)_Arg))
  #define TSKgetArg()			((intptr_t)(((volatile TSK_t *)(TSKmyID()))->TaskArg))

/* ------------------------------------------------	*/
/* All H/W spinlocks reg used by uAbassi & drivers	*/

#define KERNEL_SPINLOCK		((OX_SPINLOCK_BASE)+0)
#define MBLK_SPINLOCK		((OX_SPINLOCK_BASE)+1)
#define GIC_SPINLOCK		((OX_SPINLOCK_BASE)+2)
#define CMSIS_SPINLOCK		((OX_SPINLOCK_BASE)+3)
#define CACHE_SPINLOCK		((OX_SPINLOCK_BASE)+4)
#define LWIP_SPINLOCK		((OX_SPINLOCK_BASE)+5)
#define UART_SPINLOCK		((OX_SPINLOCK_BASE)+6)
#define MBX_SPINLOCK		((OX_SPINLOCK_BASE)+7)
#define TICK_SPINLOCK		((OX_SPINLOCK_BASE)+8)
#define DMA_SPINLOCK		((OX_SPINLOCK_BASE)+9)
#define DMAI_SPINLOCK		((OX_SPINLOCK_BASE)+10)
#define GPIO_SPINLOCK		((OX_SPINLOCK_BASE)+11)
#define I2C_SPINLOCK		((OX_SPINLOCK_BASE)+12)
#define QSPI_SPINLOCK		((OX_SPINLOCK_BASE)+13)
#define SPI_SPINLOCK		((OX_SPINLOCK_BASE)+14)
#define MMC_SPINLOCK		((OX_SPINLOCK_BASE)+15)
#define ETH_SPINLOCK		((OX_SPINLOCK_BASE)+16)
#ifdef __cplusplus
  }
#endif

#endif											/* The whole file is conditional					*/

/* EOF */
