Nordic stack and drivers for the mbed BLE API

Fork of nRF51822 by Nordic Semiconductor

Committer:
Vincent Coubard
Date:
Wed Sep 14 14:39:43 2016 +0100
Revision:
640:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vincent Coubard 640:c90ae1400bf2 1 /*
Vincent Coubard 640:c90ae1400bf2 2 * Copyright (c) Nordic Semiconductor ASA
Vincent Coubard 640:c90ae1400bf2 3 * All rights reserved.
Vincent Coubard 640:c90ae1400bf2 4 *
Vincent Coubard 640:c90ae1400bf2 5 * Redistribution and use in source and binary forms, with or without modification,
Vincent Coubard 640:c90ae1400bf2 6 * are permitted provided that the following conditions are met:
Vincent Coubard 640:c90ae1400bf2 7 *
Vincent Coubard 640:c90ae1400bf2 8 * 1. Redistributions of source code must retain the above copyright notice, this
Vincent Coubard 640:c90ae1400bf2 9 * list of conditions and the following disclaimer.
Vincent Coubard 640:c90ae1400bf2 10 *
Vincent Coubard 640:c90ae1400bf2 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this
Vincent Coubard 640:c90ae1400bf2 12 * list of conditions and the following disclaimer in the documentation and/or
Vincent Coubard 640:c90ae1400bf2 13 * other materials provided with the distribution.
Vincent Coubard 640:c90ae1400bf2 14 *
Vincent Coubard 640:c90ae1400bf2 15 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
Vincent Coubard 640:c90ae1400bf2 16 * contributors to this software may be used to endorse or promote products
Vincent Coubard 640:c90ae1400bf2 17 * derived from this software without specific prior written permission.
Vincent Coubard 640:c90ae1400bf2 18 *
Vincent Coubard 640:c90ae1400bf2 19 *
Vincent Coubard 640:c90ae1400bf2 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Vincent Coubard 640:c90ae1400bf2 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Vincent Coubard 640:c90ae1400bf2 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Vincent Coubard 640:c90ae1400bf2 23 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Vincent Coubard 640:c90ae1400bf2 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Vincent Coubard 640:c90ae1400bf2 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Vincent Coubard 640:c90ae1400bf2 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
Vincent Coubard 640:c90ae1400bf2 27 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Vincent Coubard 640:c90ae1400bf2 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Vincent Coubard 640:c90ae1400bf2 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Vincent Coubard 640:c90ae1400bf2 30 *
Vincent Coubard 640:c90ae1400bf2 31 */
Vincent Coubard 640:c90ae1400bf2 32
Vincent Coubard 640:c90ae1400bf2 33 /** @file
Vincent Coubard 640:c90ae1400bf2 34 * @brief Common defines and macros for firmware developed by Nordic Semiconductor.
Vincent Coubard 640:c90ae1400bf2 35 */
Vincent Coubard 640:c90ae1400bf2 36
Vincent Coubard 640:c90ae1400bf2 37 #ifndef NORDIC_COMMON_H__
Vincent Coubard 640:c90ae1400bf2 38 #define NORDIC_COMMON_H__
Vincent Coubard 640:c90ae1400bf2 39
Vincent Coubard 640:c90ae1400bf2 40 /** The upper 8 bits of a 32 bit value */
Vincent Coubard 640:c90ae1400bf2 41 //lint -emacro(572,MSB) // Suppress warning 572 "Excessive shift value"
Vincent Coubard 640:c90ae1400bf2 42 #define MSB(a) (((a) & 0xFF000000) >> 24)
Vincent Coubard 640:c90ae1400bf2 43 /** The lower 8 bits (of a 32 bit value) */
Vincent Coubard 640:c90ae1400bf2 44 #define LSB(a) ((a) & 0x000000FF)
Vincent Coubard 640:c90ae1400bf2 45
Vincent Coubard 640:c90ae1400bf2 46 /** The upper 8 bits of a 16 bit value */
Vincent Coubard 640:c90ae1400bf2 47 //lint -emacro(572,MSB_16) // Suppress warning 572 "Excessive shift value"
Vincent Coubard 640:c90ae1400bf2 48 #define MSB_16(a) (((a) & 0xFF00) >> 8)
Vincent Coubard 640:c90ae1400bf2 49 /** The lower 8 bits (of a 16 bit value) */
Vincent Coubard 640:c90ae1400bf2 50 #define LSB_16(a) ((a) & 0x00FF)
Vincent Coubard 640:c90ae1400bf2 51
Vincent Coubard 640:c90ae1400bf2 52 /** Leaves the minimum of the two 32-bit arguments */
Vincent Coubard 640:c90ae1400bf2 53 /*lint -emacro(506, MIN) */ /* Suppress "Constant value Boolean */
Vincent Coubard 640:c90ae1400bf2 54 #define MIN(a, b) ((a) < (b) ? (a) : (b))
Vincent Coubard 640:c90ae1400bf2 55 /** Leaves the maximum of the two 32-bit arguments */
Vincent Coubard 640:c90ae1400bf2 56 /*lint -emacro(506, MAX) */ /* Suppress "Constant value Boolean */
Vincent Coubard 640:c90ae1400bf2 57 #define MAX(a, b) ((a) < (b) ? (b) : (a))
Vincent Coubard 640:c90ae1400bf2 58
Vincent Coubard 640:c90ae1400bf2 59 /** Concatenates two parameters. Useful as a second level of indirection,
Vincent Coubard 640:c90ae1400bf2 60 * when a parameter can be macro itself. */
Vincent Coubard 640:c90ae1400bf2 61 #define CONCAT_2(p1, p2) p1##p2
Vincent Coubard 640:c90ae1400bf2 62 /** Concatenates three parameters. Useful as a second level of indirection,
Vincent Coubard 640:c90ae1400bf2 63 * when a parameter can be macro itself. */
Vincent Coubard 640:c90ae1400bf2 64 #define CONCAT_3(p1, p2, p3) p1##p2##p3
Vincent Coubard 640:c90ae1400bf2 65
Vincent Coubard 640:c90ae1400bf2 66 /**@brief Set a bit in the uint32 word.
Vincent Coubard 640:c90ae1400bf2 67 *
Vincent Coubard 640:c90ae1400bf2 68 * @param[in] W Word whose bit is being set.
Vincent Coubard 640:c90ae1400bf2 69 * @param[in] B Bit number in the word to be set.
Vincent Coubard 640:c90ae1400bf2 70 */
Vincent Coubard 640:c90ae1400bf2 71 #define SET_BIT(W,B) ((W) |= (uint32_t)(1U << (B)))
Vincent Coubard 640:c90ae1400bf2 72
Vincent Coubard 640:c90ae1400bf2 73
Vincent Coubard 640:c90ae1400bf2 74 /**@brief Clears a bit in the uint32 word.
Vincent Coubard 640:c90ae1400bf2 75 *
Vincent Coubard 640:c90ae1400bf2 76 * @param[in] W Word whose bit is to be cleared.
Vincent Coubard 640:c90ae1400bf2 77 * @param[in] B Bit number in the word to be cleared.
Vincent Coubard 640:c90ae1400bf2 78 */
Vincent Coubard 640:c90ae1400bf2 79 #define CLR_BIT(W, B) ((W) &= (~((uint32_t)1 << (B))))
Vincent Coubard 640:c90ae1400bf2 80
Vincent Coubard 640:c90ae1400bf2 81
Vincent Coubard 640:c90ae1400bf2 82 /**@brief Checks if a bit is set.
Vincent Coubard 640:c90ae1400bf2 83 *
Vincent Coubard 640:c90ae1400bf2 84 * @param[in] W Word whose bit is to be checked.
Vincent Coubard 640:c90ae1400bf2 85 * @param[in] B Bit number in the word to be checked.
Vincent Coubard 640:c90ae1400bf2 86 *
Vincent Coubard 640:c90ae1400bf2 87 * @retval 1 if bit is set.
Vincent Coubard 640:c90ae1400bf2 88 * @retval 0 if bit is not set.
Vincent Coubard 640:c90ae1400bf2 89 */
Vincent Coubard 640:c90ae1400bf2 90 #define IS_SET(W,B) (((W) >> (B)) & 1)
Vincent Coubard 640:c90ae1400bf2 91
Vincent Coubard 640:c90ae1400bf2 92 #define BIT_0 0x01 /**< The value of bit 0 */
Vincent Coubard 640:c90ae1400bf2 93 #define BIT_1 0x02 /**< The value of bit 1 */
Vincent Coubard 640:c90ae1400bf2 94 #define BIT_2 0x04 /**< The value of bit 2 */
Vincent Coubard 640:c90ae1400bf2 95 #define BIT_3 0x08 /**< The value of bit 3 */
Vincent Coubard 640:c90ae1400bf2 96 #define BIT_4 0x10 /**< The value of bit 4 */
Vincent Coubard 640:c90ae1400bf2 97 #define BIT_5 0x20 /**< The value of bit 5 */
Vincent Coubard 640:c90ae1400bf2 98 #define BIT_6 0x40 /**< The value of bit 6 */
Vincent Coubard 640:c90ae1400bf2 99 #define BIT_7 0x80 /**< The value of bit 7 */
Vincent Coubard 640:c90ae1400bf2 100 #define BIT_8 0x0100 /**< The value of bit 8 */
Vincent Coubard 640:c90ae1400bf2 101 #define BIT_9 0x0200 /**< The value of bit 9 */
Vincent Coubard 640:c90ae1400bf2 102 #define BIT_10 0x0400 /**< The value of bit 10 */
Vincent Coubard 640:c90ae1400bf2 103 #define BIT_11 0x0800 /**< The value of bit 11 */
Vincent Coubard 640:c90ae1400bf2 104 #define BIT_12 0x1000 /**< The value of bit 12 */
Vincent Coubard 640:c90ae1400bf2 105 #define BIT_13 0x2000 /**< The value of bit 13 */
Vincent Coubard 640:c90ae1400bf2 106 #define BIT_14 0x4000 /**< The value of bit 14 */
Vincent Coubard 640:c90ae1400bf2 107 #define BIT_15 0x8000 /**< The value of bit 15 */
Vincent Coubard 640:c90ae1400bf2 108 #define BIT_16 0x00010000 /**< The value of bit 16 */
Vincent Coubard 640:c90ae1400bf2 109 #define BIT_17 0x00020000 /**< The value of bit 17 */
Vincent Coubard 640:c90ae1400bf2 110 #define BIT_18 0x00040000 /**< The value of bit 18 */
Vincent Coubard 640:c90ae1400bf2 111 #define BIT_19 0x00080000 /**< The value of bit 19 */
Vincent Coubard 640:c90ae1400bf2 112 #define BIT_20 0x00100000 /**< The value of bit 20 */
Vincent Coubard 640:c90ae1400bf2 113 #define BIT_21 0x00200000 /**< The value of bit 21 */
Vincent Coubard 640:c90ae1400bf2 114 #define BIT_22 0x00400000 /**< The value of bit 22 */
Vincent Coubard 640:c90ae1400bf2 115 #define BIT_23 0x00800000 /**< The value of bit 23 */
Vincent Coubard 640:c90ae1400bf2 116 #define BIT_24 0x01000000 /**< The value of bit 24 */
Vincent Coubard 640:c90ae1400bf2 117 #define BIT_25 0x02000000 /**< The value of bit 25 */
Vincent Coubard 640:c90ae1400bf2 118 #define BIT_26 0x04000000 /**< The value of bit 26 */
Vincent Coubard 640:c90ae1400bf2 119 #define BIT_27 0x08000000 /**< The value of bit 27 */
Vincent Coubard 640:c90ae1400bf2 120 #define BIT_28 0x10000000 /**< The value of bit 28 */
Vincent Coubard 640:c90ae1400bf2 121 #define BIT_29 0x20000000 /**< The value of bit 29 */
Vincent Coubard 640:c90ae1400bf2 122 #define BIT_30 0x40000000 /**< The value of bit 30 */
Vincent Coubard 640:c90ae1400bf2 123 #define BIT_31 0x80000000 /**< The value of bit 31 */
Vincent Coubard 640:c90ae1400bf2 124
Vincent Coubard 640:c90ae1400bf2 125 #define UNUSED_VARIABLE(X) ((void)(X))
Vincent Coubard 640:c90ae1400bf2 126 #define UNUSED_PARAMETER(X) UNUSED_VARIABLE(X)
Vincent Coubard 640:c90ae1400bf2 127
Vincent Coubard 640:c90ae1400bf2 128 #endif // NORDIC_COMMON_H__