Microchip® Advanced Software Framework

compiler.h File Reference

Commonly used includes, types and macros.

Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.

#include <avr/io.h>
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <parts.h>
#include "unit_test/suite.h"
#include "interrupt.h"
#include "progmem.h"

Macros

#define __always_inline   inline __attribute__((__always_inline__))
 The function should always be inlined. More...
 
#define __always_optimize   __attribute__((optimize(3)))
 The function should always be optimized. More...
 
#define ADDR_COPY_DST_SRC_16(dst, src)   memcpy((&(dst)), (&(src)), sizeof(uint16_t))
 
#define ADDR_COPY_DST_SRC_64(dst, src)   memcpy((&(dst)), (&(src)), sizeof(uint64_t))
 
#define barrier()   asm volatile("" ::: "memory")
 Memory barrier. More...
 
#define CCPU_ENDIAN_TO_LE16(x)   (x)
 
#define CCPU_ENDIAN_TO_LE32(x)   (x)
 
#define CCPU_ENDIAN_TO_LE64(x)   (x)
 
#define CLE16_TO_CPU_ENDIAN(x)   (x)
 
#define CLE32_TO_CPU_ENDIAN(x)   (x)
 
#define CLE64_TO_CPU_ENDIAN(x)   (x)
 
#define CMD_ID_OCTET   (0)
 
#define COMPILER_PACK_RESET(alignment)
 
#define COMPILER_PACK_SET(alignment)
 
#define convert_16_bit_to_byte_address(value, data)   ((*(uint16_t *)(data)) = (uint16_t)(value))
 
#define convert_16_bit_to_byte_array(value, data)   ((*(uint16_t *)(data)) = (uint16_t)(value))
 
#define convert_32_bit_to_byte_array(value, data)   ((*(uint32_t *)(data)) = (uint32_t)(value))
 
#define convert_64_bit_to_byte_array(value, data)   memcpy((data), (&(value)), sizeof(uint64_t))
 
#define convert_byte_array_to_16_bit(data)   (*(uint16_t *)(data))
 
#define convert_byte_array_to_32_bit(data)   (*(uint32_t *)(data))
 
#define convert_byte_array_to_64_bit(data)   (*(uint64_t *)(data))
 
#define convert_spec_16_bit_to_byte_array(value, data)   ((*(uint16_t *)(data)) = (uint16_t)(value))
 
#define CPU_ENDIAN_TO_LE16(x)   (x)
 
#define CPU_ENDIAN_TO_LE32(x)   (x)
 
#define CPU_ENDIAN_TO_LE64(x)   (x)
 
#define FLASH_DECLARE(x)   const x __attribute__((__progmem__))
 
#define FLASH_EXTERN(x)   extern const x
 
#define FORCE_INLINE(type, name,...)
 
#define FUNC_PTR   void *
 
#define LE16_TO_CPU_ENDIAN(x)   (x)
 
#define LE32_TO_CPU_ENDIAN(x)   (x)
 
#define LE64_TO_CPU_ENDIAN(x)   (x)
 
#define MEMCPY_ENDIAN   memcpy
 
#define nop()   do { __asm__ __volatile__ ("nop"); } while (0)
 
#define PGM_READ_BLOCK(dst, src, len)   memcpy_P((dst), (src), (len))
 
#define PGM_READ_BYTE(x)   pgm_read_byte(x)
 
#define PGM_READ_WORD(x)   pgm_read_word(x)
 
#define SHORTENUM   __attribute__ ((packed))
 
#define Swap16(u16)
 Toggles the endianism of u16 (by swapping its bytes). More...
 
#define Swap32(u32)
 Toggles the endianism of u32 (by swapping its bytes). More...
 
#define Swap64(u64)
 Toggles the endianism of u64 (by swapping its bytes). More...
 
#define UNUSED(v)   (void)(v)
 Marking v as a unused parameter or value. More...
 
#define unused(v)   do { (void)(v); } while(0)
 Marking v as a unused parameter or value. More...
 
MCU Endianism Handling

This macro is used to test fatal errors.

The macro tests if the expression is false. If it is, a fatal error is detected and the application hangs up. If TEST_SUITE_DEFINE_ASSERT_MACRO is defined, a unit test version of the macro is used, to allow execution of further tests after a false expression.

Parameters
exprExpression to evaluate and supposed to be nonzero.
#define MSB(u16)   (((uint8_t* )&u16)[1])
 
#define LSB(u16)   (((uint8_t* )&u16)[0])
 

Typedefs

typedef uint16_t U16
 16-bit unsigned integer. More...
 
typedef uint32_t U32
 32-bit unsigned integer. More...
 
typedef unsigned long long int U64
 64-bit unsigned integer. More...
 
typedef uint8_t U8
 8-bit unsigned integer. More...
 

#define __always_inline   inline __attribute__((__always_inline__))

The function should always be inlined.

This annotation instructs the compiler to ignore its inlining heuristics and inline the function no matter how big it thinks it becomes.

#define __always_optimize   __attribute__((optimize(3)))

The function should always be optimized.

This annotation instructs the compiler to ignore global optimization settings and always compile the function with a high level of optimization.

#define ADDR_COPY_DST_SRC_16 (   dst,
  src 
)    memcpy((&(dst)), (&(src)), sizeof(uint16_t))
#define ADDR_COPY_DST_SRC_64 (   dst,
  src 
)    memcpy((&(dst)), (&(src)), sizeof(uint64_t))
#define barrier ( )    asm volatile("" ::: "memory")

Memory barrier.

Referenced by __portable_avr_delay_cycles(), and cpu_irq_restore().

#define CCPU_ENDIAN_TO_LE16 (   x)    (x)
#define CCPU_ENDIAN_TO_LE32 (   x)    (x)
#define CCPU_ENDIAN_TO_LE64 (   x)    (x)
#define CLE16_TO_CPU_ENDIAN (   x)    (x)
#define CLE32_TO_CPU_ENDIAN (   x)    (x)
#define CLE64_TO_CPU_ENDIAN (   x)    (x)
#define CMD_ID_OCTET   (0)
#define COMPILER_PACK_RESET (   alignment)
#define COMPILER_PACK_SET (   alignment)
#define convert_16_bit_to_byte_address (   value,
  data 
)    ((*(uint16_t *)(data)) = (uint16_t)(value))
#define convert_16_bit_to_byte_array (   value,
  data 
)    ((*(uint16_t *)(data)) = (uint16_t)(value))
#define convert_32_bit_to_byte_array (   value,
  data 
)    ((*(uint32_t *)(data)) = (uint32_t)(value))
#define convert_64_bit_to_byte_array (   value,
  data 
)    memcpy((data), (&(value)), sizeof(uint64_t))
#define convert_byte_array_to_16_bit (   data)    (*(uint16_t *)(data))
#define convert_byte_array_to_32_bit (   data)    (*(uint32_t *)(data))
#define convert_byte_array_to_64_bit (   data)    (*(uint64_t *)(data))
#define convert_spec_16_bit_to_byte_array (   value,
  data 
)    ((*(uint16_t *)(data)) = (uint16_t)(value))
#define CPU_ENDIAN_TO_LE16 (   x)    (x)
#define CPU_ENDIAN_TO_LE32 (   x)    (x)
#define CPU_ENDIAN_TO_LE64 (   x)    (x)
#define FLASH_DECLARE (   x)    const x __attribute__((__progmem__))
#define FLASH_EXTERN (   x)    extern const x
#define FORCE_INLINE (   type,
  name,
  ... 
)
Value:
static inline type name(__VA_ARGS__) __attribute__((always_inline)); \
static inline type name(__VA_ARGS__)
#define FUNC_PTR   void *
#define LE16_TO_CPU_ENDIAN (   x)    (x)
#define LE32_TO_CPU_ENDIAN (   x)    (x)
#define LE64_TO_CPU_ENDIAN (   x)    (x)
#define LSB (   u16)    (((uint8_t* )&u16)[0])
#define MEMCPY_ENDIAN   memcpy
#define MSB (   u16)    (((uint8_t* )&u16)[1])
#define nop ( )    do { __asm__ __volatile__ ("nop"); } while (0)
#define PGM_READ_BLOCK (   dst,
  src,
  len 
)    memcpy_P((dst), (src), (len))
#define PGM_READ_BYTE (   x)    pgm_read_byte(x)
#define PGM_READ_WORD (   x)    pgm_read_word(x)
#define SHORTENUM   __attribute__ ((packed))
#define Swap16 (   u16)
Value:
((U16)(((U16)(u16) >> 8) |\
((U16)(u16) << 8)))
uint16_t U16
16-bit unsigned integer.
Definition: compiler.h:301

Toggles the endianism of u16 (by swapping its bytes).

Parameters
u16U16 of which to toggle the endianism.
Returns
Value resulting from u16 with toggled endianism.
Note
More optimized if only used with values known at compile time.
#define Swap32 (   u32)
Value:
((U32)(((U32)Swap16((U32)(u32) >> 16)) |\
((U32)Swap16((U32)(u32)) << 16)))
uint32_t U32
32-bit unsigned integer.
Definition: compiler.h:302
#define Swap16(u16)
Toggles the endianism of u16 (by swapping its bytes).
Definition: compiler.h:313

Toggles the endianism of u32 (by swapping its bytes).

Parameters
u32U32 of which to toggle the endianism.
Returns
Value resulting from u32 with toggled endianism.
Note
More optimized if only used with values known at compile time.
#define Swap64 (   u64)
Value:
((U64)(((U64)Swap32((U64)(u64) >> 32)) |\
((U64)Swap32((U64)(u64)) << 32)))
unsigned long long int U64
64-bit unsigned integer.
Definition: compiler.h:303
#define Swap32(u32)
Toggles the endianism of u32 (by swapping its bytes).
Definition: compiler.h:324

Toggles the endianism of u64 (by swapping its bytes).

Parameters
u64U64 of which to toggle the endianism.
Returns
Value resulting from u64 with toggled endianism.
Note
More optimized if only used with values known at compile time.
#define unused (   v)    do { (void)(v); } while(0)

Marking v as a unused parameter or value.

typedef uint16_t U16

16-bit unsigned integer.

typedef uint32_t U32

32-bit unsigned integer.

typedef unsigned long long int U64

64-bit unsigned integer.

typedef uint8_t U8

8-bit unsigned integer.