2013-08-10 14:31:43 +02:00
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Compiler and Platform specific definitions and typedefs common to
|
2010-10-25 11:03:38 +02:00
|
|
|
* all platforms.
|
|
|
|
*
|
|
|
|
* platform-common.h provides PLATFORM_HEADER defaults and common definitions.
|
|
|
|
* This head should never be included directly, it should only be included
|
|
|
|
* by the specific PLATFORM_HEADER used by your platform.
|
|
|
|
*
|
|
|
|
* See platform-common.h for source code.
|
|
|
|
*@{
|
|
|
|
*/
|
2013-03-15 16:14:09 +01:00
|
|
|
|
2013-08-10 14:31:43 +02:00
|
|
|
/**
|
|
|
|
* @addtogroup stm32w-cpu
|
|
|
|
* @{ */
|
|
|
|
|
2013-03-15 16:14:09 +01:00
|
|
|
/** \file hal/micro/generic/compiler/platform-common.h
|
|
|
|
* See \ref platform_common for detailed documentation.
|
|
|
|
*
|
|
|
|
* <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. -->
|
|
|
|
*/
|
|
|
|
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
#ifndef PLATCOMMONOKTOINCLUDE
|
|
|
|
// This header should only be included by a PLATFORM_HEADER
|
|
|
|
#error platform-common.h should not be included directly
|
|
|
|
#endif
|
|
|
|
|
2013-11-24 16:57:08 +01:00
|
|
|
#ifndef PLATFORMCOMMON_H_
|
|
|
|
#define PLATFORMCOMMON_H_
|
2010-10-25 11:03:38 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Many of the common definitions must be explicitly enabled by the
|
|
|
|
// particular PLATFORM_HEADER being used
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifdef _HAL_USE_COMMON_PGM_
|
|
|
|
/** \name Master Program Memory Declarations
|
|
|
|
* These are a set of defines for simple declarations of program memory.
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Standard program memory delcaration.
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
|
|
|
#define PGM const
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Char pointer to program memory declaration.
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
|
|
|
#define PGM_P const char *
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Unsigned char pointer to program memory declaration.
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
|
|
|
#define PGM_PU const unsigned char *
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Sometimes a second PGM is needed in a declaration. Having two
|
2010-10-25 11:03:38 +02:00
|
|
|
* 'const' declarations generates a warning so we have a second PGM that turns
|
|
|
|
* into nothing under gcc.
|
|
|
|
*/
|
|
|
|
#define PGM_NO_CONST
|
|
|
|
//@} \\END MASTER PROGRAM MEMORY DECLARATIONS
|
|
|
|
#endif //_HAL_USE_COMMON_PGM_
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifdef _HAL_USE_COMMON_DIVMOD_
|
|
|
|
/** \name Divide and Modulus Operations
|
|
|
|
* Some platforms can perform divide and modulus operations on 32 bit
|
|
|
|
* quantities more efficiently when the divisor is only a 16 bit quantity.
|
|
|
|
* C compilers will always promote the divisor to 32 bits before performing the
|
|
|
|
* operation, so the following utility functions are instead required to take
|
|
|
|
* advantage of this optimisation.
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Provide a portable name for the uint32_t by uint16_t division
|
2010-10-25 11:03:38 +02:00
|
|
|
* library function (which can perform the division with only a single
|
|
|
|
* assembly instruction on some platforms)
|
|
|
|
*/
|
2013-03-15 16:14:09 +01:00
|
|
|
#define halCommonUDiv32By16(x, y) ((uint16_t) (((uint32_t) (x)) / ((uint16_t) (y))))
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Provide a portable name for the int32_t by int16_t division
|
2010-10-25 11:03:38 +02:00
|
|
|
* library function (which can perform the division with only a single
|
|
|
|
* assembly instruction on some platforms)
|
|
|
|
*/
|
2013-03-15 16:14:09 +01:00
|
|
|
#define halCommonSDiv32By16(x, y) ((int16_t) (((int32_t) (x)) / ((int16_t) (y))))
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Provide a portable name for the uint32_t by uint16_t modulo
|
2010-10-25 11:03:38 +02:00
|
|
|
* library function (which can perform the division with only a single
|
|
|
|
* assembly instruction on some platforms)
|
|
|
|
*/
|
2013-03-15 16:14:09 +01:00
|
|
|
#define halCommonUMod32By16(x, y) ((uint16_t) (((uint32_t) (x)) % ((uint16_t) (y))))
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Provide a portable name for the int32_t by int16_t modulo
|
2010-10-25 11:03:38 +02:00
|
|
|
* library function (which can perform the division with only a single
|
|
|
|
* assembly instruction on some platforms)
|
|
|
|
*/
|
2013-03-15 16:14:09 +01:00
|
|
|
#define halCommonSMod32By16(x, y) ((int16_t) (((int32_t) (x)) % ((int16_t) (y))))
|
2010-10-25 11:03:38 +02:00
|
|
|
//@} \\END DIVIDE and MODULUS OPERATIONS
|
|
|
|
#endif //_HAL_USE_COMMON_DIVMOD_
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifdef _HAL_USE_COMMON_MEMUTILS_
|
|
|
|
/** \name C Standard Library Memory Utilities
|
|
|
|
* These should be used in place of the standard library functions.
|
|
|
|
*
|
|
|
|
* These functions have the same parameters and expected results as their C
|
|
|
|
* Standard Library equivalents but may take advantage of certain implementation
|
|
|
|
* optimizations.
|
|
|
|
*
|
|
|
|
* Unless otherwise noted, these functions are utilized by the StStack and are
|
|
|
|
* therefore required to be implemented in the HAL. Additionally, unless otherwise
|
|
|
|
* noted, applications that find these functions useful may utilze them.
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Refer to the C stdlib memcpy().
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
2013-03-15 16:14:09 +01:00
|
|
|
void halCommonMemCopy(void *dest, const void *src, uint8_t bytes);
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Refer to the C stdlib memset().
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
2013-03-15 16:14:09 +01:00
|
|
|
void halCommonMemSet(void *dest, uint8_t val, uint16_t bytes);
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Refer to the C stdlib memcmp().
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
2013-03-15 16:14:09 +01:00
|
|
|
int8_t halCommonMemCompare(const void *source0, const void *source1, uint8_t bytes);
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Friendly convenience macro pointing to the full HAL function.
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
|
|
|
#define MEMSET(d,v,l) halCommonMemSet(d,v,l)
|
|
|
|
#define MEMCOPY(d,s,l) halCommonMemCopy(d,s,l)
|
|
|
|
#define MEMCOMPARE(s0,s1,l) halCommonMemCompare(s0, s1, l)
|
|
|
|
#define MEMPGMCOMPARE(s0,s1,l) halCommonMemPGMCompare(s0, s1, l)
|
|
|
|
|
|
|
|
//@} // end of C Standard Library Memory Utilities
|
|
|
|
#endif //_HAL_USE_COMMON_MEMUTILS_
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// The following sections are common on all platforms
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
|
|
* @name Generic Types
|
|
|
|
*@{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief An alias for one, used for clarity.
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
|
|
|
#define TRUE 1
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief An alias for zero, used for clarity.
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
|
|
|
#define FALSE 0
|
|
|
|
|
|
|
|
#ifndef NULL
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief The null pointer.
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
|
|
|
#define NULL ((void *)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//@} \\END Generic Types
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Bit Manipulation Macros
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Useful to reference a single bit of a byte.
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
|
|
|
#define BIT(x) (1U << (x)) // Unsigned avoids compiler warnings re BIT(15)
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Useful to reference a single bit of an uint32_t type.
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
2013-03-15 16:14:09 +01:00
|
|
|
#define BIT32(x) (((uint32_t) 1) << (x))
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Sets \c bit in the \c reg register or byte.
|
2010-10-25 11:03:38 +02:00
|
|
|
* @note Assuming \c reg is an IO register, some platforms
|
|
|
|
* can implement this in a single atomic operation.
|
|
|
|
*/
|
|
|
|
#define SETBIT(reg, bit) reg |= BIT(bit)
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Sets the bits in the \c reg register or the byte
|
2010-10-25 11:03:38 +02:00
|
|
|
* as specified in the bitmask \c bits.
|
|
|
|
* @note This is never a single atomic operation.
|
|
|
|
*/
|
|
|
|
#define SETBITS(reg, bits) reg |= (bits)
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Clears a bit in the \c reg register or byte.
|
2010-10-25 11:03:38 +02:00
|
|
|
* @note Assuming \c reg is an IO register, some platforms (such as the AVR)
|
|
|
|
* can implement this in a single atomic operation.
|
|
|
|
*/
|
|
|
|
#define CLEARBIT(reg, bit) reg &= ~(BIT(bit))
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Clears the bits in the \c reg register or byte
|
2010-10-25 11:03:38 +02:00
|
|
|
* as specified in the bitmask \c bits.
|
|
|
|
* @note This is never a single atomic operation.
|
|
|
|
*/
|
|
|
|
#define CLEARBITS(reg, bits) reg &= ~(bits)
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Returns the value of \c bit within the register or byte \c reg.
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
|
|
|
#define READBIT(reg, bit) (reg & (BIT(bit)))
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Returns the value of the bitmask \c bits within
|
2010-10-25 11:03:38 +02:00
|
|
|
* the register or byte \c reg.
|
|
|
|
*/
|
|
|
|
#define READBITS(reg, bits) (reg & (bits))
|
|
|
|
|
|
|
|
//@} \\END Bit Manipulation Macros
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
|
|
* @name Byte Manipulation Macros
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Returns the low byte of the 16-bit value \c n as an \c uint8_t.
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
2013-03-15 16:14:09 +01:00
|
|
|
#define LOW_BYTE(n) ((uint8_t)((n) & 0xFF))
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Returns the high byte of the 16-bit value \c n as an \c uint8_t.
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
2013-03-15 16:14:09 +01:00
|
|
|
#define HIGH_BYTE(n) ((uint8_t)(LOW_BYTE((n) >> 8)))
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Returns the value built from the two \c uint8_t
|
2010-10-25 11:03:38 +02:00
|
|
|
* values \c high and \c low.
|
|
|
|
*/
|
|
|
|
#define HIGH_LOW_TO_INT(high, low) ( \
|
2013-03-15 16:14:09 +01:00
|
|
|
(( (uint16_t) (high) ) << 8) + \
|
|
|
|
( (uint16_t) ( (low) & 0xFF)) \
|
2010-10-25 11:03:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Returns the low byte of the 32-bit value \c n as an \c uint8_t.
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
2013-03-15 16:14:09 +01:00
|
|
|
#define BYTE_0(n) ((uint8_t)((n) & 0xFF))
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Returns the second byte of the 32-bit value \c n as an \c uint8_t.
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
2013-03-15 16:14:09 +01:00
|
|
|
#define BYTE_1(n) ((uint8_t)(BYTE_0((n) >> 8)))
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Returns the third byte of the 32-bit value \c n as an \c uint8_t.
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
2013-03-15 16:14:09 +01:00
|
|
|
#define BYTE_2(n) ((uint8_t)(BYTE_0((n) >> 16)))
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Returns the high byte of the 32-bit value \c n as an \c uint8_t.
|
2010-10-25 11:03:38 +02:00
|
|
|
*/
|
2013-03-15 16:14:09 +01:00
|
|
|
#define BYTE_3(n) ((uint8_t)(BYTE_0((n) >> 24)))
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
//@} \\END Byte manipulation macros
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
|
|
* @name Time Manipulation Macros
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Returns the elapsed time between two 8 bit values.
|
2010-10-25 11:03:38 +02:00
|
|
|
* Result may not be valid if the time samples differ by more than 127
|
|
|
|
*/
|
|
|
|
#define elapsedTimeInt8u(oldTime, newTime) \
|
2013-03-15 16:14:09 +01:00
|
|
|
((uint8_t) ((uint8_t)(newTime) - (uint8_t)(oldTime)))
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Returns the elapsed time between two 16 bit values.
|
2010-10-25 11:03:38 +02:00
|
|
|
* Result may not be valid if the time samples differ by more than 32767
|
|
|
|
*/
|
|
|
|
#define elapsedTimeInt16u(oldTime, newTime) \
|
2013-03-15 16:14:09 +01:00
|
|
|
((uint16_t) ((uint16_t)(newTime) - (uint16_t)(oldTime)))
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Returns the elapsed time between two 32 bit values.
|
2010-10-25 11:03:38 +02:00
|
|
|
* Result may not be valid if the time samples differ by more than 2147483647
|
|
|
|
*/
|
|
|
|
#define elapsedTimeInt32u(oldTime, newTime) \
|
2013-03-15 16:14:09 +01:00
|
|
|
((uint32_t) ((uint32_t)(newTime) - (uint32_t)(oldTime)))
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Returns TRUE if t1 is greater than t2. Can only account for 1 wrap
|
2010-10-25 11:03:38 +02:00
|
|
|
* around of the variable before it is wrong.
|
|
|
|
*/
|
|
|
|
#define MAX_INT8U_VALUE 0xFF
|
|
|
|
#define timeGTorEqualInt8u(t1, t2) \
|
|
|
|
(elapsedTimeInt8u(t2, t1) <= ((MAX_INT8U_VALUE + 1) / 2))
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Returns TRUE if t1 is greater than t2. Can only account for 1 wrap
|
2010-10-25 11:03:38 +02:00
|
|
|
* around of the variable before it is wrong.
|
|
|
|
*/
|
|
|
|
#define MAX_INT16U_VALUE 0xFFFF
|
|
|
|
#define timeGTorEqualInt16u(t1, t2) \
|
|
|
|
(elapsedTimeInt16u(t2, t1) <= ((MAX_INT16U_VALUE + 1) / 2))
|
|
|
|
|
|
|
|
/**
|
2013-03-15 16:14:09 +01:00
|
|
|
* \brief Returns TRUE if t1 is greater than t2. Can only account for 1 wrap
|
2010-10-25 11:03:38 +02:00
|
|
|
* around of the variable before it is wrong.
|
|
|
|
*/
|
|
|
|
#define MAX_INT32U_VALUE 0xFFFFFFFF
|
|
|
|
#define timeGTorEqualInt32u(t1, t2) \
|
|
|
|
(elapsedTimeInt32u(t2, t1) <= ((MAX_INT32U_VALUE + 1) / 2))
|
|
|
|
|
|
|
|
//@} \\END Time manipulation macros
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-24 16:57:08 +01:00
|
|
|
#endif //PLATFORMCOMMON_H_
|
2010-10-25 11:03:38 +02:00
|
|
|
|
|
|
|
/** @} END addtogroup */
|
2013-08-10 14:31:43 +02:00
|
|
|
/** @} */
|
2010-10-25 11:03:38 +02:00
|
|
|
|