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