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
#ifndef DOXYGEN_SHOULD_SKIP_THIS
// The XAP2b compiler uses these macros to enable and disable placement
// in zero-page memory. All other platforms do not have zero-page memory
// so these macros define to nothing.
#ifndef _HAL_USING_XAP2B_PRAGMAS_
#define XAP2B_PAGEZERO_ON
#define XAP2B_PAGEZERO_OFF
#endif
#endif //DOXYGEN_SHOULD_SKIP_THIS
#ifdef _HAL_USE_COMMON_PGM_
#define PGM const
#define PGM_P const char *
#define PGM_PU const unsigned char *
#define PGM_NO_CONST
#endif //_HAL_USE_COMMON_PGM_
#ifdef _HAL_USE_COMMON_DIVMOD_
#define halCommonUDiv32By16(x, y) ((uint16_t) (((uint32_t) (x)) / ((uint16_t) (y))))
#define halCommonSDiv32By16(x, y) ((int16_t) (((int32_t) (x)) / ((int16_t) (y))))
#define halCommonUMod32By16(x, y) ((uint16_t) (((uint32_t) (x)) % ((uint16_t) (y))))
#define halCommonSMod32By16(x, y) ((int16_t) (((int32_t) (x)) % ((int16_t) (y))))
#endif //_HAL_USE_COMMON_DIVMOD_
#ifdef _HAL_USE_COMMON_MEMUTILS_
void halCommonMemMove(void *dest, const void *src, uint16_t bytes);
void halCommonMemSet(void *dest, uint8_t val, uint16_t bytes);
int16_t halCommonMemCompare(const void *source0, const void *source1, uint16_t bytes);
int8_t halCommonMemPGMCompare(const void *source0, const void PGM_NO_CONST *source1, uint16_t bytes);
void halCommonMemPGMCopy(void* dest, const void PGM_NO_CONST *source, uint16_t bytes);
#define MEMSET(d, v, l) halCommonMemSet(d, v, l)
#define MEMCOPY(d, s, l) halCommonMemMove(d, s, l)
#define MEMMOVE(d, s, l) halCommonMemMove(d, s, l)
#define MEMPGMCOPY(d, s, l) halCommonMemPGMCopy(d, s, l)
#define MEMCOMPARE(s0, s1, l) halCommonMemCompare(s0, s1, l)
#define MEMPGMCOMPARE(s0, s1, l) halCommonMemPGMCompare(s0, s1, l)
#else
#define MEMSET(d, v, l) memset(d, v, l)
#define MEMCOPY(d, s, l) memcpy(d, s, l)
#define MEMMOVE(d, s, l) memmove(d, s, l)
#define MEMPGMCOPY(d, s, l) memcpy(d, s, l)
#define MEMCOMPARE(s0, s1, l) memcmp(s0, s1, l)
#define MEMPGMCOMPARE(s0, s1, l) memcmp(s0, s1, l)
#endif //_HAL_USE_COMMON_MEMUTILS_
// The following sections are common on all platforms
#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) & 0xFF))
#define HIGH_BYTE(n) ((uint8_t)(LOW_BYTE((n) >> 8)))
#define HIGH_LOW_TO_INT(high, low) ( \
((uint16_t) (((uint16_t) (high)) << 8)) \
+ ((uint16_t) ((low) & 0xFF)) \
)
#define INT8U_TO_INT32U(byte3, byte2, byte1, byte0) ( \
(((uint32_t) (byte3)) << 24) \
+ (((uint32_t) (byte2)) << 16) \
+ (((uint32_t) (byte1)) << 8) \
+ ((uint32_t) ((byte0) & 0xFF)) \
)
#define BYTE_0(n) ((uint8_t)((n) & 0xFF))
#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#
An alias for one, used for clarity.
An alias for zero, used for clarity.
The null pointer.
Bit Manipulation Macros#
Useful to reference a single bit of a byte.
Useful to reference a single bit of an uint32_t type.
Sets bit
in the reg
register or byte.
Sets the bits in the reg
register or the byte as specified in the bitmask bits
.
Clears a bit in the reg
register or byte.
Clears the bits in the reg
register or byte as specified in the bitmask bits
.
Returns the value of bit
within the register or byte reg
.
Returns the value of the bitmask bits
within the register or byte reg
.
Byte Manipulation Macros#
Returns the low byte of the 16-bit value n
as an uint8_t
.
Returns the high byte of the 16-bit value n
as an uint8_t
.
Returns the value built from the two uint8_t
values high
and low
.
Returns the value built from the four uint8_t
as an uint32_t
.
Returns the low byte of the 32-bit value n
as an uint8_t
.
Returns the second byte of the 32-bit value n
as an uint8_t
.
Returns the third byte of the 32-bit value n
as an uint8_t
.
Returns the high byte of the 32-bit value n
as an uint8_t
.
Returns the fifth byte of the 64-bit value n
as an uint8_t
.
Returns the sixth byte of the 64-bit value n
as an uint8_t
.
Returns the seventh byte of the 64-bit value n
as an uint8_t
.
Returns the high byte of the 64-bit value n
as an uint8_t
.
Returns the number of entries in an array.
Time Manipulation Macros#
Returns the elapsed time between two 8 bit values. Result may not be valid if the time samples differ by more than 127.
Returns the elapsed time between two 16 bit values. Result may not be valid if the time samples differ by more than 32767.
Returns the elapsed time between two 32 bit values. Result may not be valid if the time samples differ by more than 2147483647.
Returns true if t1 is greater than t2. Can only account for 1 wrap around of the variable before it is wrong.
Returns the elapsed time between two 8 bit values. Result may not be valid if the time samples differ by more than 127.
Returns the elapsed time between two 8 bit values. Result may not be valid if the time samples differ by more than 127.
Returns true if t1 is greater than t2. Can only account for 1 wrap around of the variable before it is wrong.
Returns the elapsed time between two 8 bit values. Result may not be valid if the time samples differ by more than 127.
Returns the elapsed time between two 8 bit values. Result may not be valid if the time samples differ by more than 127.
Returns true if t1 is greater than t2. Can only account for 1 wrap around of the variable before it is wrong.
Returns the elapsed time between two 8 bit values. Result may not be valid if the time samples differ by more than 127.
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#
Set debug level based on whether DEBUG or DEBUG_STRIPPED are defined.
Disable static assertions on compilers that don't support them.
Macros#
Friendly convenience macro pointing to the C Stdlib functions.
Generic Types Documentation#
TRUE#
#define TRUEValue:
1
An alias for one, used for clarity.
209
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
FALSE#
#define FALSEValue:
0
An alias for zero, used for clarity.
214
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
NULL#
#define NULLValue:
((void *)0)
The null pointer.
221
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
Bit Manipulation Macros Documentation#
BIT#
#define BITValue:
(x)
Useful to reference a single bit of a byte.
234
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
BIT32#
#define BIT32Value:
(x)
Useful to reference a single bit of an uint32_t type.
239
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
SETBIT#
#define SETBITValue:
(reg, bit)
Sets bit
in the reg
register or byte.
Note
Assuming
reg
is an IO register, some platforms (such as the AVR) can implement this in a single atomic operation.
246
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
SETBITS#
#define SETBITSValue:
(reg, bits)
Sets the bits in the reg
register or the byte as specified in the bitmask bits
.
Note
This is never a single atomic operation.
253
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
CLEARBIT#
#define CLEARBITValue:
(reg, bit)
Clears a bit in the reg
register or byte.
Note
Assuming
reg
is an IO register, some platforms (such as the AVR) can implement this in a single atomic operation.
260
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
CLEARBITS#
#define CLEARBITSValue:
(reg, bits)
Clears the bits in the reg
register or byte as specified in the bitmask bits
.
Note
This is never a single atomic operation.
267
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
READBIT#
#define READBITValue:
(reg, bit)
Returns the value of bit
within the register or byte reg
.
272
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
READBITS#
#define READBITSValue:
(reg, bits)
Returns the value of the bitmask bits
within the register or byte reg
.
278
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
Byte Manipulation Macros Documentation#
LOW_BYTE#
#define LOW_BYTEValue:
(n)
Returns the low byte of the 16-bit value n
as an uint8_t
.
292
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
HIGH_BYTE#
#define HIGH_BYTEValue:
(n)
Returns the high byte of the 16-bit value n
as an uint8_t
.
297
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
HIGH_LOW_TO_INT#
#define HIGH_LOW_TO_INTValue:
Returns the value built from the two uint8_t
values high
and low
.
303
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
INT8U_TO_INT32U#
#define INT8U_TO_INT32UValue:
Returns the value built from the four uint8_t
as an uint32_t
.
311
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
BYTE_0#
#define BYTE_0Value:
(n)
Returns the low byte of the 32-bit value n
as an uint8_t
.
321
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
BYTE_1#
#define BYTE_1Value:
(n)
Returns the second byte of the 32-bit value n
as an uint8_t
.
326
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
BYTE_2#
#define BYTE_2Value:
(n)
Returns the third byte of the 32-bit value n
as an uint8_t
.
331
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
BYTE_3#
#define BYTE_3Value:
(n)
Returns the high byte of the 32-bit value n
as an uint8_t
.
336
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
BYTE_4#
#define BYTE_4Value:
(n)
Returns the fifth byte of the 64-bit value n
as an uint8_t
.
341
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
BYTE_5#
#define BYTE_5Value:
(n)
Returns the sixth byte of the 64-bit value n
as an uint8_t
.
346
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
BYTE_6#
#define BYTE_6Value:
(n)
Returns the seventh byte of the 64-bit value n
as an uint8_t
.
351
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
BYTE_7#
#define BYTE_7Value:
(n)
Returns the high byte of the 64-bit value n
as an uint8_t
.
356
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
COUNTOF#
#define COUNTOFValue:
(a)
Returns the number of entries in an array.
361
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
Time Manipulation Macros Documentation#
elapsedTimeInt8u#
#define elapsedTimeInt8uValue:
(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.
376
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
elapsedTimeInt16u#
#define elapsedTimeInt16uValue:
(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.
383
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
elapsedTimeInt32u#
#define elapsedTimeInt32uValue:
(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.
390
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
MAX_INT8U_VALUE#
#define MAX_INT8U_VALUEValue:
(0xFF)
Returns true if t1 is greater than t2. Can only account for 1 wrap around of the variable before it is wrong.
397
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
HALF_MAX_INT8U_VALUE#
#define HALF_MAX_INT8U_VALUEValue:
(0x80)
Returns the elapsed time between two 8 bit values. Result may not be valid if the time samples differ by more than 127.
398
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
timeGTorEqualInt8u#
#define timeGTorEqualInt8uValue:
(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.
399
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
MAX_INT16U_VALUE#
#define MAX_INT16U_VALUEValue:
(0xFFFF)
Returns true if t1 is greater than t2. Can only account for 1 wrap around of the variable before it is wrong.
406
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
HALF_MAX_INT16U_VALUE#
#define HALF_MAX_INT16U_VALUEValue:
(0x8000)
Returns the elapsed time between two 8 bit values. Result may not be valid if the time samples differ by more than 127.
407
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
timeGTorEqualInt16u#
#define timeGTorEqualInt16uValue:
(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.
408
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
MAX_INT32U_VALUE#
#define MAX_INT32U_VALUEValue:
(0xFFFFFFFFUL)
Returns true if t1 is greater than t2. Can only account for 1 wrap around of the variable before it is wrong.
415
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
HALF_MAX_INT32U_VALUE#
#define HALF_MAX_INT32U_VALUEValue:
(0x80000000UL)
Returns the elapsed time between two 8 bit values. Result may not be valid if the time samples differ by more than 127.
416
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
timeGTorEqualInt32u#
#define timeGTorEqualInt32uValue:
(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.
417
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
Miscellaneous Macros Documentation#
UNUSED_VAR#
#define UNUSED_VARValue:
(x)
@description Useful macro for avoiding compiler warnings related to unused function arguments or unused variables.
435
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
DEBUG_LEVEL#
#define DEBUG_LEVELValue:
BASIC_DEBUG
Set debug level based on whether DEBUG or DEBUG_STRIPPED are defined.
457
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
STATIC_ASSERT#
#define STATIC_ASSERT
Disable static assertions on compilers that don't support them.
465
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
Macro Definition Documentation#
MEMSET#
#define MEMSETValue:
(d, v, l)
Friendly convenience macro pointing to the C Stdlib functions.
187
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
MEMCOPY#
#define MEMCOPYValue:
(d, s, l)
188
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
MEMMOVE#
#define MEMMOVEValue:
(d, s, l)
189
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
MEMPGMCOPY#
#define MEMPGMCOPYValue:
(d, s, l)
190
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
MEMCOMPARE#
#define MEMCOMPAREValue:
(s0, s1, l)
191
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h
MEMPGMCOMPARE#
#define MEMPGMCOMPAREValue:
(s0, s1, l)
192
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/generic/compiler/platform-common.h