konashi/SBBLEのテスト

Dependencies:   BLE_API mbed

Fork of BLE_LoopbackUART by Bluetooth Low Energy

Committer:
robo8080
Date:
Sun Aug 17 00:53:23 2014 +0000
Revision:
8:a62b8f7d5dcf
Parent:
5:61109bce11fe
DeviceName??

Who changed what in which revision?

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