Bluetooth SPI MBED
Embed:
(wiki syntax)
Show/hide line numbers
common_header.h
Go to the documentation of this file.
00001 /**************************************************************************/ 00002 /*! 00003 @file common_header.h 00004 @author hathach 00005 00006 @section LICENSE 00007 00008 Software License Agreement (BSD License) 00009 00010 Copyright (c) 2016, Adafruit Industries (adafruit.com) 00011 All rights reserved. 00012 00013 Redistribution and use in source and binary forms, with or without 00014 modification, are permitted provided that the following conditions are met: 00015 1. Redistributions of source code must retain the above copyright 00016 notice, this list of conditions and the following disclaimer. 00017 2. Redistributions in binary form must reproduce the above copyright 00018 notice, this list of conditions and the following disclaimer in the 00019 documentation and/or other materials provided with the distribution. 00020 3. Neither the name of the copyright holders nor the 00021 names of its contributors may be used to endorse or promote products 00022 derived from this software without specific prior written permission. 00023 00024 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 00025 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00026 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 00028 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00029 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00031 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00033 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 */ 00035 /**************************************************************************/ 00036 00037 #ifndef _COMMON_HEADER_H_ 00038 #define _COMMON_HEADER_H_ 00039 00040 #include <stdint.h> 00041 #include <stdbool.h> 00042 00043 //--------------------------------------------------------------------+ 00044 // COMPILER 00045 //--------------------------------------------------------------------+ 00046 #define STRING_(x) #x // stringify without expand 00047 #define XSTRING_(x) STRING_(x) // expand then stringify 00048 #define STRING_CONCAT_(a, b) a##b // concat without expand 00049 #define XSTRING_CONCAT_(a, b) STRING_CONCAT_(a, b) // expand then concat 00050 00051 #define ATTR_PACKED __attribute__ ((packed)) 00052 00053 //--------------------------------------------------------------------+ 00054 // ASSERT & VERIFY 00055 //--------------------------------------------------------------------+ 00056 //#define ASSERT(condition, err) if ( !(condition) ) return err; 00057 00058 //------------- Compile-time Assert -------------// 00059 #if defined __COUNTER__ && __COUNTER__ != __COUNTER__ 00060 #define _ASSERT_COUNTER __COUNTER__ 00061 #else 00062 #define _ASSERT_COUNTER __LINE__ 00063 #endif 00064 00065 #define ASSERT_STATIC_(const_expr) enum { XSTRING_CONCAT_(static_assert_, _ASSERT_COUNTER) = 1/(!!(const_expr)) } 00066 00067 00068 #define VERIFY_(condition) if ( !(condition) ) return false; 00069 #define VERIFY_RETURN_(condition, error) if ( !(condition) ) return error; 00070 00071 //--------------------------------------------------------------------+ 00072 // INLINE FUNCTION 00073 //--------------------------------------------------------------------+ 00074 static inline bool is_within(uint32_t lower, uint32_t value, uint32_t upper) 00075 { 00076 return (lower <= value) && (value <= upper); 00077 } 00078 00079 #endif /* _COMMON_HEADER_H_ */
Generated on Fri Aug 12 2022 08:42:17 by
1.7.2