Donal Morrissey / BLE_API_Native_blog

Dependents:   BLE_iBeacon_Exercise

Fork of BLE_API_Native by Kevin Townsend

Committer:
donalm
Date:
Sun Feb 23 12:51:12 2014 +0000
Revision:
18:f776bb9efb7a
Parent:
0:4c3097c65247
Removed hw layer.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 0:4c3097c65247 1 /**************************************************************************/
ktownsend 0:4c3097c65247 2 /*!
ktownsend 0:4c3097c65247 3 @file binary.h
ktownsend 0:4c3097c65247 4 @author hathach (tinyusb.org)
ktownsend 0:4c3097c65247 5
ktownsend 0:4c3097c65247 6 @section LICENSE
ktownsend 0:4c3097c65247 7
ktownsend 0:4c3097c65247 8 Software License Agreement (BSD License)
ktownsend 0:4c3097c65247 9
ktownsend 0:4c3097c65247 10 Copyright (c) 2013, K. Townsend (microBuilder.eu)
ktownsend 0:4c3097c65247 11 All rights reserved.
ktownsend 0:4c3097c65247 12
ktownsend 0:4c3097c65247 13 Redistribution and use in source and binary forms, with or without
ktownsend 0:4c3097c65247 14 modification, are permitted provided that the following conditions are met:
ktownsend 0:4c3097c65247 15 1. Redistributions of source code must retain the above copyright
ktownsend 0:4c3097c65247 16 notice, this list of conditions and the following disclaimer.
ktownsend 0:4c3097c65247 17 2. Redistributions in binary form must reproduce the above copyright
ktownsend 0:4c3097c65247 18 notice, this list of conditions and the following disclaimer in the
ktownsend 0:4c3097c65247 19 documentation and/or other materials provided with the distribution.
ktownsend 0:4c3097c65247 20 3. Neither the name of the copyright holders nor the
ktownsend 0:4c3097c65247 21 names of its contributors may be used to endorse or promote products
ktownsend 0:4c3097c65247 22 derived from this software without specific prior written permission.
ktownsend 0:4c3097c65247 23
ktownsend 0:4c3097c65247 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
ktownsend 0:4c3097c65247 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
ktownsend 0:4c3097c65247 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ktownsend 0:4c3097c65247 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
ktownsend 0:4c3097c65247 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
ktownsend 0:4c3097c65247 29 INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
ktownsend 0:4c3097c65247 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
ktownsend 0:4c3097c65247 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
ktownsend 0:4c3097c65247 32 INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
ktownsend 0:4c3097c65247 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ktownsend 0:4c3097c65247 34 */
ktownsend 0:4c3097c65247 35 /**************************************************************************/
ktownsend 0:4c3097c65247 36
ktownsend 0:4c3097c65247 37 /** \ingroup TBD
ktownsend 0:4c3097c65247 38 * \defgroup TBD
ktownsend 0:4c3097c65247 39 * \brief TBD
ktownsend 0:4c3097c65247 40 *
ktownsend 0:4c3097c65247 41 * @{
ktownsend 0:4c3097c65247 42 */
ktownsend 0:4c3097c65247 43
ktownsend 0:4c3097c65247 44 #ifndef _BINARY_H_
ktownsend 0:4c3097c65247 45 #define _BINARY_H_
ktownsend 0:4c3097c65247 46
ktownsend 0:4c3097c65247 47 #ifdef __cplusplus
ktownsend 0:4c3097c65247 48 extern "C" {
ktownsend 0:4c3097c65247 49 #endif
ktownsend 0:4c3097c65247 50
ktownsend 0:4c3097c65247 51 /// n-th Bit
ktownsend 0:4c3097c65247 52 #define BIT(n) (1 << (n))
ktownsend 0:4c3097c65247 53
ktownsend 0:4c3097c65247 54 /// set n-th bit of x to 1
ktownsend 0:4c3097c65247 55 #define BIT_SET(x, n) ( (x) | BIT(n) )
ktownsend 0:4c3097c65247 56
ktownsend 0:4c3097c65247 57 /// clear n-th bit of x
ktownsend 0:4c3097c65247 58 #define BIT_CLR(x, n) ( (x) & (~BIT(n)) )
ktownsend 0:4c3097c65247 59
ktownsend 0:4c3097c65247 60 /// test n-th bit of x
ktownsend 0:4c3097c65247 61 #define BIT_TEST(x, n) ( (x) & BIT(n) )
ktownsend 0:4c3097c65247 62
ktownsend 0:4c3097c65247 63 #if defined(__GNUC__) && !defined(__CC_ARM) // keil does not support binary format
ktownsend 0:4c3097c65247 64
ktownsend 0:4c3097c65247 65 #define BIN8(x) ((uint8_t) (0b##x))
ktownsend 0:4c3097c65247 66 #define BIN16(b1, b2) ((uint16_t) (0b##b1##b2))
ktownsend 0:4c3097c65247 67 #define BIN32(b1, b2, b3, b4) ((uint32_t) (0b##b1##b2##b3##b4))
ktownsend 0:4c3097c65247 68
ktownsend 0:4c3097c65247 69 #else
ktownsend 0:4c3097c65247 70
ktownsend 0:4c3097c65247 71 // internal macro of B8, B16, B32
ktownsend 0:4c3097c65247 72 #define _B8__(x) (((x&0x0000000FUL)?1:0) \
ktownsend 0:4c3097c65247 73 +((x&0x000000F0UL)?2:0) \
ktownsend 0:4c3097c65247 74 +((x&0x00000F00UL)?4:0) \
ktownsend 0:4c3097c65247 75 +((x&0x0000F000UL)?8:0) \
ktownsend 0:4c3097c65247 76 +((x&0x000F0000UL)?16:0) \
ktownsend 0:4c3097c65247 77 +((x&0x00F00000UL)?32:0) \
ktownsend 0:4c3097c65247 78 +((x&0x0F000000UL)?64:0) \
ktownsend 0:4c3097c65247 79 +((x&0xF0000000UL)?128:0))
ktownsend 0:4c3097c65247 80
ktownsend 0:4c3097c65247 81 #define BIN8(d) ((uint8_t) _B8__(0x##d##UL))
ktownsend 0:4c3097c65247 82 #define BIN16(dmsb,dlsb) (((uint16_t)BIN8(dmsb)<<8) + BIN8(dlsb))
ktownsend 0:4c3097c65247 83 #define BIN32(dmsb,db2,db3,dlsb) \
ktownsend 0:4c3097c65247 84 (((uint32_t)BIN8(dmsb)<<24) \
ktownsend 0:4c3097c65247 85 + ((uint32_t)BIN8(db2)<<16) \
ktownsend 0:4c3097c65247 86 + ((uint32_t)BIN8(db3)<<8) \
ktownsend 0:4c3097c65247 87 + BIN8(dlsb))
ktownsend 0:4c3097c65247 88 #endif
ktownsend 0:4c3097c65247 89
ktownsend 0:4c3097c65247 90 #ifdef __cplusplus
ktownsend 0:4c3097c65247 91 }
ktownsend 0:4c3097c65247 92 #endif
ktownsend 0:4c3097c65247 93
ktownsend 0:4c3097c65247 94 #endif /* _BINARY_H_ */
ktownsend 0:4c3097c65247 95
ktownsend 0:4c3097c65247 96 /** @} */