/* ##########################  Compiler control architecture macros  ################################# */
/**
\defgroup comp_cntrl_gr Compiler Control
\brief Compiler agnostic \#define symbols for generic C/C++ source code
\details
The CMSIS-Core provides the header file \b cmsis_compiler.h with consistent \#define symbols to generate C or C++ source files that should be compiler agnostic.
Each CMSIS compliant compiler should support the functionality described in this section.
@{
*/

/**
\def __ARMCC_VERSION
*/

/**
\def __ARM_ARCH_7A__
\brief Set to 1 when generating code for Armv7-A (Cortex-A7)
\details
The \b \#define __ARM_ARCH_7A__ is set to 1 when generating code for the Armv7-A architecture. This architecture is for example used by the Cortex-A7 processor.
*/
#define __ARM_ARCH_7A__

/**
\def __ASM
\brief Pass information from the compiler to the assembler.
\details
The \b __ASM keyword can declare or define an embedded assembly function or incorporate inline assembly into a function
(shown in the code example below).
 
<b>Code Example:</b>
\code
// Reverse bit order of value
 
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
{
  uint32_t result;
 
   __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
   return(result);
}
\endcode
*/

/**
\def __INLINE
\brief Recommend that function should be inlined by the compiler.
\details
Inline functions offer a trade-off between code size and performance. By default, the compiler decides during optimization whether to
inline code or not. The \b __INLINE attribute gives the compiler an hint to inline this function. 
Still, the compiler may decide not to inline the function. As the function is global an callable function is also generated. 

<b> Code Example:</b>
\code
const uint32_t led_mask[] = {1U << 4, 1U << 5, 1U << 6, 1U << 7};
 
//------------------------------------------------------------------------------
// Switch on LEDs
//------------------------------------------------------------------------------
__INLINE static void LED_On (uint32_t led) {
 
  PTD->PCOR   = led_mask[led];
}
\endcode
*/

/**
\def __STATIC_INLINE
\brief Define a static function should be inlined by the compiler.
\details
Defines a static function that may be inlined by the compiler. If the compiler generates inline code for 
all calls to this functions, no additional function implementation is generated which may further optimize space.

<b> Code Example:</b>
\code
__STATIC_INLINE uint32_t GIC_GetPriority(IRQn_Type IRQn)
{
  return((uint32_t)GICDistributor->D_IPRIORITYR[((uint32_t)(int32_t)IRQn)]);
}
\endcode
*/

/**************************************************************************************************/
/**
\def __STATIC_FORCEINLINE
\brief Define a static function that should be always inlined by the compiler.
\details
Defines a static function that should be always inlined by the compiler. 

\note
For compilers that do not allow to force function inlining, the macro maps to \ref __STATIC_INLINE.

<b> Code Example:</b>
\code
\\ Get Interrupt Vector
__STATIC_FORCEINLINE uint32_t NVIC_GetVector(IRQn_Type IRQn)
{
    uint32_t *vectors = (uint32_t *) ((uintptr_t) SCB->VTOR);
    return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET];
}
\endcode

*/
#define __STATIC_FORCEINLINE

/**  
\def __NO_RETURN
\brief Inform the compiler that a function does not return.
\details
Informs the compiler that the function does not return. The compiler can then perform optimizations by
removing code that is never reached.
 
<b> Code Example:</b>
\code
// OS idle demon (running when no other thread is ready to run).
 
__NO_RETURN void os_idle_demon (void);
\endcode
*/

/**
\def __USED
\brief Inform that a variable shall be retained in executable image.
\details
Definitions tagged with \b __USED in the source code should be not removed by the linker when detected as unused.
 
<b> Code Example:</b>
\code
// Export following variables for debugging 
__USED uint32_t const CMSIS_RTOS_API_Version = osCMSIS;
__USED uint32_t const CMSIS_RTOS_RTX_Version = osCMSIS_RTX;
__USED uint32_t const os_clockrate = OS_TICK;
__USED uint32_t const os_timernum  = 0;
\endcode
**/

/**
\def __WEAK
\brief Export a function or variable weakly to allow overwrites.
\details
Functions defined with \b __WEAK export their symbols weakly. A function defined weak behaves like a normal defined
function unless a non-weak function with the same name is linked into the same image. If both a non-weak
function and a weak defined function exist in the same image, then all calls to the function resolve to the non-weak
function.

Functions declared with \b __WEAK and then defined without \b __WEAK behave as non-weak functions.
 
<b> Code Example:</b>
\code
__WEAK void SystemInit(void)
{
  SystemCoreSetup();
  SystemCoreClockSetup(); 
}
\endcode
*/

/**
\def __ALIGNED(x)
\brief Minimum alignment for a variable.
\details
Specifies a minimum alignment for a variable or structure field, measured in bytes.
 
<b> Code Example:</b>
\code
uint32_t stack_space[0x100] __ALIGNED(8);   // 8-byte alignment required
\endcode
*/

/**
\def __PACKED
\brief Request smallest possible alignment.
\details
Specifies that a type must have the smallest possible alignment.
 
<b> Code Example:</b>
\code
struct foo {
  uint8_t  u8;
  uint32_t u32[2] __PACKED;
};
\endcode
*/
/**************************************************************************************************/
/**
\def __PACKED_STRUCT
\brief Request smallest possible alignment for a structure.
\details
Specifies that a structure must have the smallest possible alignment.
 
<b> Code Example:</b>
\code
__PACKED_STRUCT foo {
  uint8_t   u8;
  uint32_t  u32;
  uint16_t  u16;
};
\endcode

*/
#define __PACKED_STRUCT

/**************************************************************************************************/
/**
\def __UNALIGNED_UINT16_READ
\brief Pointer for unaligned read of a uint16_t variable.
\details
Defines a pointer to a uint16_t from an address that does not need to be aligned. This can then be used in read
operations. The compiler will generate the appropriate access (aligned or non-aligned) depending on the underlying Arm
processor core and compiler settings.
 
<b> Code Example:</b>
\code
uint16_t val16;
 
void test (uint8_t *ptr) {
   val16 = __UNALIGNED_UINT16_READ(ptr);
}
\endcode

*/
#define __UNALIGNED_UINT16_READ

/**************************************************************************************************/
/**
\def __UNALIGNED_UINT16_WRITE
\brief Pointer for unaligned write of a uint16_t variable.
\details
Defines a pointer to a uint16_t from an address that does not need to be aligned. This can then be used in write
operations. The compiler will generate the appropriate access (aligned or non-aligned) depending on the underlying Arm
processor core and compiler settings.
 
<b> Code Example:</b>
\code
uint16_t val16 = 0U;
 
void test (uint8_t *ptr) {
   __UNALIGNED_UINT16_WRITE(ptr, val16);
}
\endcode

*/
#define __UNALIGNED_UINT16_WRITE

/**************************************************************************************************/
/**
\def __UNALIGNED_UINT32_READ
\brief Pointer for unaligned read of a uint32_t variable.
\details
Defines a pointer to a uint32_t from an address that does not need to be aligned. This can then be used in read
operations. The compiler will generate the appropriate access (aligned or non-aligned) depending on the underlying Arm
processor core and compiler settings.
 
<b> Code Example:</b>
\code
uint32_t val32;
 
void test (uint8_t *ptr) {
   val32 = __UNALIGNED_UINT32_READ(ptr);
}
\endcode

*/
#define __UNALIGNED_UINT32_READ

/**************************************************************************************************/
/**
\def __UNALIGNED_UINT32_WRITE
\brief Pointer for unaligned write of a uint32_t variable.
\details
Defines a pointer to a uint32_t from an address that does not need to be aligned. This can then be used in write
operations. The compiler will generate the appropriate access (aligned or non-aligned) depending on the underlying Arm
processor core and compiler settings.
 
<b> Code Example:</b>
\code
uint32_t val32 = 0U;
 
void test (uint8_t *ptr) {
   __UNALIGNED_UINT32_WRITE(ptr, val32);
}
\endcode

*/
#define __UNALIGNED_UINT32_WRITE

/**
@}
*/
/* end group comp_cntrl_gr */

/* ##########################  Core Instruction Access  ######################### */
/** 
\defgroup CMSIS_Core_InstructionInterface Intrinsic Functions 
\brief Functions that generate specific Cortex-A CPU Instructions
@{
*/

/**
\def __NOP
\details No Operation does nothing. This instruction can be used for code alignment purposes.


\def __WFI
\details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.

\def __WFE
\details Wait For Event is a hint instruction that permits the processor to enter

\def __SEV
\details Send Event is a hint instruction. It causes an event to be signaled to the CPU.

\def __ISB()
\details Instruction Synchronization Barrier flushes the pipeline in the processor,
           so that all instructions following the ISB are fetched from cache or memory,
           after the instruction has been completed.

\def __DSB()
\details Acts as a special kind of Data Memory Barrier.
           It completes when all explicit memory accesses before this instruction complete.

\def __DMB()
\details Ensures the apparent order of the explicit memory operations before
           and after the instruction, without ensuring their completion.

\def __BKPT(value)
\details Causes the processor to enter Debug state.
           Debug tools can use this to investigate system state when the instruction at a particular address is reached.
*/

/**
  \brief   Reverse byte order (32 bit)
  \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
  \param [in]    value  Value to reverse
  \return               Reversed value
 */
uint32_t __REV(uint32_t value);

/**
  \brief   Reverse byte order (16 bit)
  \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
  \param [in]    value  Value to reverse
  \return               Reversed value
 */
uint16_t __REV16(uint16_t value);

/**
  \brief   Reverse byte order (16 bit)
  \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
  \param [in]    value  Value to reverse
  \return               Reversed value
 */
int32_t __REVSH(int32_t value);

/**
  \brief   Rotate Right in unsigned value (32 bit)
  \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
  \param [in]    op1  Value to rotate
  \param [in]    op2  Number of Bits to rotate
  \return               Rotated value
 */
uint32_t __ROR(uint32_t op1, uint32_t op2);

/**
  \brief   Reverse bit order of value
  \details Reverses the bit order of the given value.
  \param [in]    value  Value to reverse
  \return               Reversed value
 */
uint32_t __RBIT(uint32_t value);

/**
  \brief   	Count leading zeros.
  \details Counts the number of leading zeros of a data value.
  \param [in]    value  Value to count the leading zeros
  \return               number of leading zeros in value
 */
uint8_t __CLZ(uint32_t value);

/** @}*/ 
/* end of group CMSIS_Core_InstructionInterface */


