テスト用です。

Dependencies:   mbed

Committer:
jksoft
Date:
Tue Oct 11 11:09:42 2016 +0000
Revision:
0:8468a4403fea
SB??ver;

Who changed what in which revision?

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