mirror of
https://github.com/espressif/openthread.git
synced 2026-09-05 08:40:06 +00:00
Added platform/toolchain.h toolchain abstraction layer via macros. (#107)
* Added platform/toolchain.h toolchain abstraction layer via macros: OT_TOOL_PACKED_BEGIN OT_TOOL_PACKED_END OT_TOOL_DEPRECATED(symbol) * Make pretty. Rekick travis-ci. * Added doxygen. Resolved review comments. * Fixed doxygen sample for OT_TOOL_PACKED to include type name. * Renamed OT_TOOL_PACKED_FIELD to simplify code searches for usage. Fixed all nested instances to use new naming. * Fixed OT_TOOL_PACKED_FIELD renaming in doxygen. * Make pretty. * Documentation clarifications. * Moved example into overview section. * Fixed sdcc comment. * Revised sdcc comment. * Fix code style in toolchain packed doxygen example. * Fixed example. Moved toolchain test to better match code style. * Added test for OT_TOOL_PACKED_FIELD. * Added support for clang. Just routes to gcc __attributes__. Verified by running unit test through clang on macos.
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <platform/toolchain.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -197,7 +198,7 @@ enum
|
||||
/**
|
||||
* This structure represents an IPv6 address.
|
||||
*/
|
||||
typedef struct otIp6Address
|
||||
typedef OT_TOOL_PACKED_BEGIN struct otIp6Address
|
||||
{
|
||||
union
|
||||
{
|
||||
@@ -205,7 +206,7 @@ typedef struct otIp6Address
|
||||
uint16_t m16[kIp6AddressSize / sizeof(uint16_t)];
|
||||
uint32_t m32[kIp6AddressSize / sizeof(uint32_t)];
|
||||
};
|
||||
} __attribute__((packed)) otIp6Address;
|
||||
} OT_TOOL_PACKED_END otIp6Address;
|
||||
|
||||
/**
|
||||
* This structure represents an IPv6 prefix.
|
||||
|
||||
@@ -34,6 +34,7 @@ ot_platform_headers =\
|
||||
radio.h \
|
||||
random.h \
|
||||
serial.h \
|
||||
toolchain.h \
|
||||
$(NULL)
|
||||
|
||||
ot_platformdir = $(includedir)/platform
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Nest Labs, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup toolchain Toolchain
|
||||
* @ingroup platform
|
||||
*
|
||||
* @brief
|
||||
* This module defines a toolchain abstraction layer through macros.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* @code
|
||||
*
|
||||
* typedef
|
||||
* OT_TOOL_PACKED_BEGIN
|
||||
* struct
|
||||
* {
|
||||
* char mField1;
|
||||
* union
|
||||
* {
|
||||
* char mField2;
|
||||
* long mField3;
|
||||
* } OT_TOOL_PACKED_FIELD;
|
||||
* } OT_TOOL_PACKED_END packed_struct_t;
|
||||
*
|
||||
* @endcode
|
||||
*
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TOOLCHAIN_H_
|
||||
#define TOOLCHAIN_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @def OT_TOOL_PACKED_BEGIN
|
||||
*
|
||||
* Compiler-specific indication that a class or struct must be byte packed.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @def OT_TOOL_PACKED_FIELD
|
||||
*
|
||||
* Indicate to the compiler a nested struct or union to be packed
|
||||
* within byte packed class or struct.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @def OT_TOOL_PACKED_END
|
||||
*
|
||||
* Compiler-specific indication at the end of a byte packed class or struct.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @def OT_TOOL_DEPRECATED
|
||||
*
|
||||
* Indicate to the compiler to warn upon use that a field or function
|
||||
* has been deprecated.
|
||||
*
|
||||
* @param[in] symbol The name of the field or function to deprecate.
|
||||
*
|
||||
*/
|
||||
|
||||
// =========== TOOLCHAIN SELECTION : START ===========
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
|
||||
|
||||
// https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
|
||||
// http://www.keil.com/support/man/docs/armcc/armcc_chr1359124973480.htm
|
||||
|
||||
#define OT_TOOL_PACKED_BEGIN
|
||||
#define OT_TOOL_PACKED_FIELD __attribute__((packed))
|
||||
#define OT_TOOL_PACKED_END __attribute__((packed))
|
||||
#define OT_TOOL_DEPRECATED(symbol) __attribute__((deprecated))
|
||||
|
||||
#elif defined(__ICCARM__) || defined(__ICC8051__)
|
||||
|
||||
// http://supp.iar.com/FilesPublic/UPDINFO/004916/arm/doc/EWARM_DevelopmentGuide.ENU.pdf
|
||||
|
||||
#include "intrinsics.h"
|
||||
|
||||
#define OT_TOOL_PACKED_BEGIN __packed
|
||||
#define OT_TOOL_PACKED_FIELD
|
||||
#define OT_TOOL_PACKED_END
|
||||
#define OT_TOOL_DEPRECATED(symbol)
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
|
||||
#define OT_TOOL_PACKED_BEGIN __pragma(pack(push,1))
|
||||
#define OT_TOOL_PACKED_FIELD
|
||||
#define OT_TOOL_PACKED_END __pragma(pack(pop))
|
||||
#define OT_TOOL_DEPRECATED(symbol) __pragma(deprecated(symbol))
|
||||
|
||||
#elif defined(__SDCC)
|
||||
|
||||
// Structures are packed by default in sdcc, as it primarily targets 8-bit MCUs.
|
||||
|
||||
#define OT_TOOL_PACKED_BEGIN
|
||||
#define OT_TOOL_PACKED_FIELD
|
||||
#define OT_TOOL_PACKED_END
|
||||
#define OT_TOOL_DEPRECATED(symbol)
|
||||
|
||||
#else
|
||||
|
||||
#error "Error: No valid Toolchain specified"
|
||||
|
||||
// Symbols for Doxygen
|
||||
|
||||
#define OT_TOOL_PACKED_BEGIN
|
||||
#define OT_TOOL_PACKED_FIELD
|
||||
#define OT_TOOL_PACKED_END
|
||||
#define OT_TOOL_DEPRECATED(symbol)
|
||||
|
||||
#endif
|
||||
|
||||
// =========== TOOLCHAIN SELECTION : END ===========
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // TOOLCHAIN_H_
|
||||
Reference in New Issue
Block a user