Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
common_header.h@0:39b7f3158ebe, 2018-04-05 (annotated)
- Committer:
- wninghj
- Date:
- Thu Apr 05 21:26:10 2018 +0000
- Revision:
- 0:39b7f3158ebe
TEAM12 DJ;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| wninghj | 0:39b7f3158ebe | 1 | /**************************************************************************/ |
| wninghj | 0:39b7f3158ebe | 2 | /*! |
| wninghj | 0:39b7f3158ebe | 3 | @file common_header.h |
| wninghj | 0:39b7f3158ebe | 4 | @author hathach |
| wninghj | 0:39b7f3158ebe | 5 | |
| wninghj | 0:39b7f3158ebe | 6 | @section LICENSE |
| wninghj | 0:39b7f3158ebe | 7 | |
| wninghj | 0:39b7f3158ebe | 8 | Software License Agreement (BSD License) |
| wninghj | 0:39b7f3158ebe | 9 | |
| wninghj | 0:39b7f3158ebe | 10 | Copyright (c) 2016, Adafruit Industries (adafruit.com) |
| wninghj | 0:39b7f3158ebe | 11 | All rights reserved. |
| wninghj | 0:39b7f3158ebe | 12 | |
| wninghj | 0:39b7f3158ebe | 13 | Redistribution and use in source and binary forms, with or without |
| wninghj | 0:39b7f3158ebe | 14 | modification, are permitted provided that the following conditions are met: |
| wninghj | 0:39b7f3158ebe | 15 | 1. Redistributions of source code must retain the above copyright |
| wninghj | 0:39b7f3158ebe | 16 | notice, this list of conditions and the following disclaimer. |
| wninghj | 0:39b7f3158ebe | 17 | 2. Redistributions in binary form must reproduce the above copyright |
| wninghj | 0:39b7f3158ebe | 18 | notice, this list of conditions and the following disclaimer in the |
| wninghj | 0:39b7f3158ebe | 19 | documentation and/or other materials provided with the distribution. |
| wninghj | 0:39b7f3158ebe | 20 | 3. Neither the name of the copyright holders nor the |
| wninghj | 0:39b7f3158ebe | 21 | names of its contributors may be used to endorse or promote products |
| wninghj | 0:39b7f3158ebe | 22 | derived from this software without specific prior written permission. |
| wninghj | 0:39b7f3158ebe | 23 | |
| wninghj | 0:39b7f3158ebe | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
| wninghj | 0:39b7f3158ebe | 25 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| wninghj | 0:39b7f3158ebe | 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| wninghj | 0:39b7f3158ebe | 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY |
| wninghj | 0:39b7f3158ebe | 28 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| wninghj | 0:39b7f3158ebe | 29 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| wninghj | 0:39b7f3158ebe | 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| wninghj | 0:39b7f3158ebe | 31 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| wninghj | 0:39b7f3158ebe | 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| wninghj | 0:39b7f3158ebe | 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| wninghj | 0:39b7f3158ebe | 34 | */ |
| wninghj | 0:39b7f3158ebe | 35 | /**************************************************************************/ |
| wninghj | 0:39b7f3158ebe | 36 | |
| wninghj | 0:39b7f3158ebe | 37 | #ifndef _COMMON_HEADER_H_ |
| wninghj | 0:39b7f3158ebe | 38 | #define _COMMON_HEADER_H_ |
| wninghj | 0:39b7f3158ebe | 39 | |
| wninghj | 0:39b7f3158ebe | 40 | #include <stdint.h> |
| wninghj | 0:39b7f3158ebe | 41 | #include <stdbool.h> |
| wninghj | 0:39b7f3158ebe | 42 | |
| wninghj | 0:39b7f3158ebe | 43 | //--------------------------------------------------------------------+ |
| wninghj | 0:39b7f3158ebe | 44 | // COMPILER |
| wninghj | 0:39b7f3158ebe | 45 | //--------------------------------------------------------------------+ |
| wninghj | 0:39b7f3158ebe | 46 | #define STRING_(x) #x // stringify without expand |
| wninghj | 0:39b7f3158ebe | 47 | #define XSTRING_(x) STRING_(x) // expand then stringify |
| wninghj | 0:39b7f3158ebe | 48 | #define STRING_CONCAT_(a, b) a##b // concat without expand |
| wninghj | 0:39b7f3158ebe | 49 | #define XSTRING_CONCAT_(a, b) STRING_CONCAT_(a, b) // expand then concat |
| wninghj | 0:39b7f3158ebe | 50 | |
| wninghj | 0:39b7f3158ebe | 51 | #define ATTR_PACKED __attribute__ ((packed)) |
| wninghj | 0:39b7f3158ebe | 52 | |
| wninghj | 0:39b7f3158ebe | 53 | //--------------------------------------------------------------------+ |
| wninghj | 0:39b7f3158ebe | 54 | // ASSERT & VERIFY |
| wninghj | 0:39b7f3158ebe | 55 | //--------------------------------------------------------------------+ |
| wninghj | 0:39b7f3158ebe | 56 | //#define ASSERT(condition, err) if ( !(condition) ) return err; |
| wninghj | 0:39b7f3158ebe | 57 | |
| wninghj | 0:39b7f3158ebe | 58 | //------------- Compile-time Assert -------------// |
| wninghj | 0:39b7f3158ebe | 59 | #if defined __COUNTER__ && __COUNTER__ != __COUNTER__ |
| wninghj | 0:39b7f3158ebe | 60 | #define _ASSERT_COUNTER __COUNTER__ |
| wninghj | 0:39b7f3158ebe | 61 | #else |
| wninghj | 0:39b7f3158ebe | 62 | #define _ASSERT_COUNTER __LINE__ |
| wninghj | 0:39b7f3158ebe | 63 | #endif |
| wninghj | 0:39b7f3158ebe | 64 | |
| wninghj | 0:39b7f3158ebe | 65 | #define ASSERT_STATIC_(const_expr) enum { XSTRING_CONCAT_(static_assert_, _ASSERT_COUNTER) = 1/(!!(const_expr)) } |
| wninghj | 0:39b7f3158ebe | 66 | |
| wninghj | 0:39b7f3158ebe | 67 | |
| wninghj | 0:39b7f3158ebe | 68 | #define VERIFY_(condition) if ( !(condition) ) return false; |
| wninghj | 0:39b7f3158ebe | 69 | #define VERIFY_RETURN_(condition, error) if ( !(condition) ) return error; |
| wninghj | 0:39b7f3158ebe | 70 | |
| wninghj | 0:39b7f3158ebe | 71 | //--------------------------------------------------------------------+ |
| wninghj | 0:39b7f3158ebe | 72 | // INLINE FUNCTION |
| wninghj | 0:39b7f3158ebe | 73 | //--------------------------------------------------------------------+ |
| wninghj | 0:39b7f3158ebe | 74 | static inline bool is_within(uint32_t lower, uint32_t value, uint32_t upper) |
| wninghj | 0:39b7f3158ebe | 75 | { |
| wninghj | 0:39b7f3158ebe | 76 | return (lower <= value) && (value <= upper); |
| wninghj | 0:39b7f3158ebe | 77 | } |
| wninghj | 0:39b7f3158ebe | 78 | |
| wninghj | 0:39b7f3158ebe | 79 | #endif /* _COMMON_HEADER_H_ */ |