See Common PLATFORM_HEADER Configuration for detailed documentation.

License#

Copyright 2018 Silicon Laboratories Inc. www.silabs.com

The licensor of this software is Silicon Laboratories Inc. Your use of this software is governed by the terms of Silicon Labs Master Software License Agreement (MSLA) available at www.silabs.com/about-us/legal/master-software-license-agreement. This software is distributed to you in Source Code format and is governed by the sections of the MSLA applicable to Source Code.

/***************************************************************************/
#ifndef __PLATFORMCOMMON_H__
#define __PLATFORMCOMMON_H__

#ifndef PLATCOMMONOKTOINCLUDE
//  This header should only be included by a PLATFORM_HEADER
  #error  platform-common.h should not be included directly
#endif

// Many of the common definitions must be explicitly enabled by the
//  particular PLATFORM_HEADER being used

#include <string.h>

#define TRUE  1

#define FALSE 0

#ifndef NULL

#define NULL ((void *)0)
#endif



#define BIT(x) (1U << (x))  // Unsigned avoids compiler warnings re BIT(15)

#define BIT32(x) (((uint32_t) 1) << (x))

#define SETBIT(reg, bit)      (reg) |= BIT(bit)

#define SETBITS(reg, bits)    (reg) |= (bits)

#define CLEARBIT(reg, bit)    (reg) &= ~(BIT(bit))

#define CLEARBITS(reg, bits)  (reg) &= ~(bits)

#define READBIT(reg, bit)     ((reg) & (BIT(bit)))

#define READBITS(reg, bits)   ((reg) & (bits))




#define LOW_BYTE(n)                     ((uint8_t)(n))

#define HIGH_BYTE(n)                    LOW_BYTE((n) >> 8)

#define HIGH_LOW_TO_INT(high, low) (        \
    ((uint16_t) (((uint16_t) (high)) << 8)) \
    + ((uint16_t) ((low) & 0xFFu))          \
    )

#define INT8U_TO_INT32U(byte3, byte2, byte1, byte0) ( \
    (((uint32_t) (byte3)) << 24)                      \
    + (((uint32_t) (byte2)) << 16)                    \
    + (((uint32_t) (byte1)) << 8)                     \
    + ((uint32_t) ((byte0) & 0xFFu))                  \
    )

#define BYTE_0(n)                    ((uint8_t)(n))

#define BYTE_1(n)                    BYTE_0((n) >> 8)

#define BYTE_2(n)                    BYTE_0((n) >> 16)

#define BYTE_3(n)                    BYTE_0((n) >> 24)

#define BYTE_4(n)                    BYTE_0((n) >> 32)

#define BYTE_5(n)                    BYTE_0((n) >> 40)

#define BYTE_6(n)                    BYTE_0((n) >> 48)

#define BYTE_7(n)                    BYTE_0((n) >> 56)

#define COUNTOF(a) (sizeof(a) / sizeof(a[0]))




#define elapsedTimeInt8u(oldTime, newTime) \
  ((uint8_t) ((uint8_t)(newTime) - (uint8_t)(oldTime)))

#define elapsedTimeInt16u(oldTime, newTime) \
  ((uint16_t) ((uint16_t)(newTime) - (uint16_t)(oldTime)))

#define elapsedTimeInt32u(oldTime, newTime) \
  ((uint32_t) ((uint32_t)(newTime) - (uint32_t)(oldTime)))

#define MAX_INT8U_VALUE       (0xFF)
#define HALF_MAX_INT8U_VALUE  (0x80)
#define timeGTorEqualInt8u(t1, t2) \
  (elapsedTimeInt8u(t2, t1) <= (HALF_MAX_INT8U_VALUE))

#define MAX_INT16U_VALUE      (0xFFFF)
#define HALF_MAX_INT16U_VALUE (0x8000)
#define timeGTorEqualInt16u(t1, t2) \
  (elapsedTimeInt16u(t2, t1) <= (HALF_MAX_INT16U_VALUE))

#define MAX_INT32U_VALUE      (0xFFFFFFFFUL)
#define HALF_MAX_INT32U_VALUE (0x80000000UL)
#define timeGTorEqualInt32u(t1, t2) \
  (elapsedTimeInt32u(t2, t1) <= (HALF_MAX_INT32U_VALUE))




#ifndef UNUSED_VAR

#define UNUSED_VAR(x) (void)(x)
#endif

#ifdef DEBUG_OFF
// On March 17, 2014, DEBUG_OFF was deprecated and replaced by DEBUG_STRIPPED.
// Some builds still attempt to use DEBUG_OFF and as a result there are
// failures.  On 2016-10-04 implemented a little bandaid here to define
// DEBUG_STRIPPED when debugging is meant to be "off".
  #define DEBUG_STRIPPED
#endif

#ifndef DEBUG_LEVEL
  #if defined(DEBUG) && defined(DEBUG_STRIPPED)
    #error "DEBUG and DEBUG_OFF cannot be both be defined!"
  #elif defined(DEBUG)
    #define DEBUG_LEVEL FULL_DEBUG
  #elif defined(DEBUG_STRIPPED)
    #define DEBUG_LEVEL NO_DEBUG
  #else
    #define DEBUG_LEVEL BASIC_DEBUG
  #endif
#endif

#ifndef STATIC_ASSERT
  #define STATIC_ASSERT(__condition, __errorstr)
#endif


#endif //__PLATFORMCOMMON_H__

Generic Types#

#define
TRUE 1

An alias for one, used for clarity.

#define
FALSE 0

An alias for zero, used for clarity.

#define
NULL ((void *)0)

The null pointer.

Bit Manipulation Macros#

#define
BIT (x)

Useful to reference a single bit of a byte.

#define
BIT32 (x)

Useful to reference a single bit of an uint32_t type.

#define
SETBIT (reg, bit)

Sets bit in the reg register or byte.

#define
SETBITS (reg, bits)

Sets the bits in the reg register or the byte as specified in the bitmask bits.

#define
CLEARBIT (reg, bit)

Clears a bit in the reg register or byte.

#define
CLEARBITS (reg, bits)

Clears the bits in the reg register or byte as specified in the bitmask bits.

#define
READBIT (reg, bit)

Returns the value of bit within the register or byte reg.

#define
READBITS (reg, bits)

Returns the value of the bitmask bits within the register or byte reg.

Byte Manipulation Macros#

#define
LOW_BYTE (n)

Returns the low byte of the 16-bit value n as an uint8_t.

#define
HIGH_BYTE (n)

Returns the high byte of the 16-bit value n as an uint8_t.

#define
HIGH_LOW_TO_INT (high, low)

Returns the value built from the two uint8_t values high and low.

#define
INT8U_TO_INT32U (byte3, byte2, byte1, byte0)

Returns the value built from the four uint8_t as an uint32_t.

#define
BYTE_0 (n)

Returns the low byte of the 32-bit value n as an uint8_t.

#define
BYTE_1 (n)

Returns the second byte of the 32-bit value n as an uint8_t.

#define
BYTE_2 (n)

Returns the third byte of the 32-bit value n as an uint8_t.

#define
BYTE_3 (n)

Returns the high byte of the 32-bit value n as an uint8_t.

#define
BYTE_4 (n)

Returns the fifth byte of the 64-bit value n as an uint8_t.

#define
BYTE_5 (n)

Returns the sixth byte of the 64-bit value n as an uint8_t.

#define
BYTE_6 (n)

Returns the seventh byte of the 64-bit value n as an uint8_t.

#define
BYTE_7 (n)

Returns the high byte of the 64-bit value n as an uint8_t.

#define
COUNTOF (a)

Returns the number of entries in an array.

Time Manipulation Macros#

#define
elapsedTimeInt8u (oldTime, newTime)

Returns the elapsed time between two 8 bit values. Result may not be valid if the time samples differ by more than 127.

#define
elapsedTimeInt16u (oldTime, newTime)

Returns the elapsed time between two 16 bit values. Result may not be valid if the time samples differ by more than 32767.

#define
elapsedTimeInt32u (oldTime, newTime)

Returns the elapsed time between two 32 bit values. Result may not be valid if the time samples differ by more than 2147483647.

#define
MAX_INT8U_VALUE (0xFF)

Returns true if t1 is greater than t2. Can only account for 1 wrap around of the variable before it is wrong.

#define
HALF_MAX_INT8U_VALUE (0x80)

Returns the elapsed time between two 8 bit values. Result may not be valid if the time samples differ by more than 127.

#define
timeGTorEqualInt8u (t1, t2)

Returns the elapsed time between two 8 bit values. Result may not be valid if the time samples differ by more than 127.

#define
MAX_INT16U_VALUE (0xFFFF)

Returns true if t1 is greater than t2. Can only account for 1 wrap around of the variable before it is wrong.

#define
HALF_MAX_INT16U_VALUE (0x8000)

Returns the elapsed time between two 8 bit values. Result may not be valid if the time samples differ by more than 127.

#define
timeGTorEqualInt16u (t1, t2)

Returns the elapsed time between two 8 bit values. Result may not be valid if the time samples differ by more than 127.

#define
MAX_INT32U_VALUE (0xFFFFFFFFUL)

Returns true if t1 is greater than t2. Can only account for 1 wrap around of the variable before it is wrong.

#define
HALF_MAX_INT32U_VALUE (0x80000000UL)

Returns the elapsed time between two 8 bit values. Result may not be valid if the time samples differ by more than 127.

#define
timeGTorEqualInt32u (t1, t2)

Returns the elapsed time between two 8 bit values. Result may not be valid if the time samples differ by more than 127.

Miscellaneous Macros#

#define
UNUSED_VAR (x)
#define
DEBUG_LEVEL BASIC_DEBUG

Set debug level based on whether DEBUG or DEBUG_STRIPPED are defined.

#define
STATIC_ASSERT (__condition, __errorstr)

Disable static assertions on compilers that don't support them.

Generic Types Documentation#

Bit Manipulation Macros Documentation#

Byte Manipulation Macros Documentation#

Time Manipulation Macros Documentation#

Miscellaneous Macros Documentation#