Platform_common

Compiler and Platform specific definitions and typedefs common to all platforms. More...

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.



void halCommonMemCopy (void *dest, const void *src, int8u bytes)
 Refer to the C stdlib memcpy().
void halCommonMemSet (void *dest, int8u val, int16u bytes)
 Refer to the C stdlib memset().
int8s halCommonMemCompare (const void *source0, const void *source1, int8u bytes)
 Refer to the C stdlib memcmp().
#define MEMSET(d, v, l)   halCommonMemSet(d,v,l)
 Friendly convenience macro pointing to the full HAL function.
#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)

Master Program Memory Declarations

These are a set of defines for simple declarations of program memory.



#define PGM   const
 Standard program memory delcaration.
#define PGM_P   const char *
 Char pointer to program memory declaration.
#define PGM_PU   const unsigned char *
 Unsigned char pointer to program memory declaration.
#define PGM_NO_CONST
 Sometimes a second PGM is needed in a declaration.

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.



#define halCommonUDiv32By16(x, y)   ((int16u) (((int32u) (x)) / ((int16u) (y))))
 Provide a portable name for the int32u by int16u division library function (which can perform the division with only a single assembly instruction on some platforms).
#define halCommonSDiv32By16(x, y)   ((int16s) (((int32s) (x)) / ((int16s) (y))))
 Provide a portable name for the int32s by int16s division library function (which can perform the division with only a single assembly instruction on some platforms).
#define halCommonUMod32By16(x, y)   ((int16u) (((int32u) (x)) % ((int16u) (y))))
 Provide a portable name for the int32u by int16u modulo library function (which can perform the division with only a single assembly instruction on some platforms).
#define halCommonSMod32By16(x, y)   ((int16s) (((int32s) (x)) % ((int16s) (y))))
 Provide a portable name for the int32s by int16s modulo library function (which can perform the division with only a single assembly instruction on some platforms).

Generic Types



#define TRUE   1
 An alias for one, used for clarity.
#define FALSE   0
 An alias for zero, used for clarity.

Bit Manipulation Macros



#define BIT(x)   (1U << (x))
 Useful to reference a single bit of a byte.
#define BIT32(x)   (((int32u) 1) << (x))
 Useful to reference a single bit of an int32u type.
#define SETBIT(reg, bit)   reg |= BIT(bit)
 Sets bit in the reg register or byte.
#define SETBITS(reg, bits)   reg |= (bits)
 Sets the bits in the reg register or the byte as specified in the bitmask bits.
#define CLEARBIT(reg, bit)   reg &= ~(BIT(bit))
 Clears a bit in the reg register or byte.
#define CLEARBITS(reg, bits)   reg &= ~(bits)
 Clears the bits in the reg register or byte as specified in the bitmask bits.
#define READBIT(reg, bit)   (reg & (BIT(bit)))
 Returns the value of bit within the register or byte reg.
#define READBITS(reg, bits)   (reg & (bits))
 Returns the value of the bitmask bits within the register or byte reg.

Byte Manipulation Macros



#define LOW_BYTE(n)   ((int8u)((n) & 0xFF))
 Returns the low byte of the 16-bit value n as an int8u.
#define HIGH_BYTE(n)   ((int8u)(LOW_BYTE((n) >> 8)))
 Returns the high byte of the 16-bit value n as an int8u.
#define HIGH_LOW_TO_INT(high, low)
 Returns the value built from the two int8u values high and low.
#define BYTE_0(n)   ((int8u)((n) & 0xFF))
 Returns the low byte of the 32-bit value n as an int8u.
#define BYTE_1(n)   ((int8u)(BYTE_0((n) >> 8)))
 Returns the second byte of the 32-bit value n as an int8u.
#define BYTE_2(n)   ((int8u)(BYTE_0((n) >> 16)))
 Returns the third byte of the 32-bit value n as an int8u.
#define BYTE_3(n)   ((int8u)(BYTE_0((n) >> 24)))
 Returns the high byte of the 32-bit value n as an int8u.

Time Manipulation Macros



#define elapsedTimeInt8u(oldTime, newTime)   ((int8u) ((int8u)(newTime) - (int8u)(oldTime)))
 Returns the elapsed time between two 8 bit values.
#define elapsedTimeInt16u(oldTime, newTime)   ((int16u) ((int16u)(newTime) - (int16u)(oldTime)))
 Returns the elapsed time between two 16 bit values.
#define elapsedTimeInt32u(oldTime, newTime)   ((int32u) ((int32u)(newTime) - (int32u)(oldTime)))
 Returns the elapsed time between two 32 bit values.
#define MAX_INT8U_VALUE   0xFF
 Returns TRUE if t1 is greater than t2.
#define timeGTorEqualInt8u(t1, t2)   (elapsedTimeInt8u(t2, t1) <= ((MAX_INT8U_VALUE + 1) / 2))
#define MAX_INT16U_VALUE   0xFFFF
 Returns TRUE if t1 is greater than t2.
#define timeGTorEqualInt16u(t1, t2)   (elapsedTimeInt16u(t2, t1) <= ((MAX_INT16U_VALUE + 1) / 2))
#define MAX_INT32U_VALUE   0xFFFFFFFF
 Returns TRUE if t1 is greater than t2.
#define timeGTorEqualInt32u(t1, t2)   (elapsedTimeInt32u(t2, t1) <= ((MAX_INT32U_VALUE + 1) / 2))

Detailed Description

Compiler and Platform specific definitions and typedefs common to 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.


Define Documentation

#define CLEARBIT ( reg,
bit   )     reg &= ~(BIT(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.

Definition at line 221 of file platform-common.h.

#define CLEARBITS ( reg,
bits   )     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.

Definition at line 228 of file platform-common.h.

#define elapsedTimeInt16u ( oldTime,
newTime   )     ((int16u) ((int16u)(newTime) - (int16u)(oldTime)))

Returns the elapsed time between two 16 bit values.

Result may not be valid if the time samples differ by more than 32767

Definition at line 309 of file platform-common.h.

#define elapsedTimeInt32u ( oldTime,
newTime   )     ((int32u) ((int32u)(newTime) - (int32u)(oldTime)))

Returns the elapsed time between two 32 bit values.

Result may not be valid if the time samples differ by more than 2147483647

Definition at line 316 of file platform-common.h.

#define elapsedTimeInt8u ( oldTime,
newTime   )     ((int8u) ((int8u)(newTime) - (int8u)(oldTime)))

Returns the elapsed time between two 8 bit values.

Result may not be valid if the time samples differ by more than 127

Definition at line 302 of file platform-common.h.

#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.

Definition at line 331 of file platform-common.h.

#define MAX_INT32U_VALUE   0xFFFFFFFF

Returns TRUE if t1 is greater than t2.

Can only account for 1 wrap around of the variable before it is wrong.

Definition at line 339 of file platform-common.h.

#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.

Definition at line 323 of file platform-common.h.

#define PGM_NO_CONST

Sometimes a second PGM is needed in a declaration.

Having two 'const' declarations generates a warning so we have a second PGM that turns into nothing under gcc.

Definition at line 59 of file platform-common.h.

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

Sets bit in the reg register or byte.

Note:
Assuming reg is an IO register, some platforms can implement this in a single atomic operation.

Definition at line 207 of file platform-common.h.

#define SETBITS ( reg,
bits   )     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.

Definition at line 214 of file platform-common.h.


Generated on Mon Apr 11 14:23:57 2011 for Contiki 2.5 by  doxygen 1.6.1