Abraham Marsen / Mbed 2 deprecated Jazz_Hands_Nordic

Dependencies:   mbed

Committer:
Grimmkey
Date:
Thu Apr 30 20:46:27 2015 +0000
Revision:
0:b8221deeaa87
Georgia Institute of Technology ECE 4180 Spring 2015 Jazz Hands project, Nordic nRF51822 half

Who changed what in which revision?

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