The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 163:e59c8e839560 1 /*
AnnaBridge 163:e59c8e839560 2 * Copyright (c) 2014 Nordic Semiconductor ASA
AnnaBridge 163:e59c8e839560 3 * All rights reserved.
AnnaBridge 163:e59c8e839560 4 *
AnnaBridge 163:e59c8e839560 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 163:e59c8e839560 6 * are permitted provided that the following conditions are met:
AnnaBridge 163:e59c8e839560 7 *
AnnaBridge 163:e59c8e839560 8 * 1. Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 163:e59c8e839560 9 * of conditions and the following disclaimer.
AnnaBridge 163:e59c8e839560 10 *
AnnaBridge 163:e59c8e839560 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
AnnaBridge 163:e59c8e839560 12 * integrated circuit in a product or a software update for such product, must reproduce
AnnaBridge 163:e59c8e839560 13 * the above copyright notice, this list of conditions and the following disclaimer in
AnnaBridge 163:e59c8e839560 14 * the documentation and/or other materials provided with the distribution.
AnnaBridge 163:e59c8e839560 15 *
AnnaBridge 163:e59c8e839560 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
AnnaBridge 163:e59c8e839560 17 * used to endorse or promote products derived from this software without specific prior
AnnaBridge 163:e59c8e839560 18 * written permission.
AnnaBridge 163:e59c8e839560 19 *
AnnaBridge 163:e59c8e839560 20 * 4. This software, with or without modification, must only be used with a
AnnaBridge 163:e59c8e839560 21 * Nordic Semiconductor ASA integrated circuit.
AnnaBridge 163:e59c8e839560 22 *
AnnaBridge 163:e59c8e839560 23 * 5. Any software provided in binary or object form under this license must not be reverse
AnnaBridge 163:e59c8e839560 24 * engineered, decompiled, modified and/or disassembled.
AnnaBridge 163:e59c8e839560 25 *
AnnaBridge 163:e59c8e839560 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 163:e59c8e839560 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 163:e59c8e839560 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 163:e59c8e839560 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 163:e59c8e839560 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 163:e59c8e839560 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 163:e59c8e839560 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 163:e59c8e839560 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 163:e59c8e839560 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 163:e59c8e839560 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 163:e59c8e839560 36 *
AnnaBridge 163:e59c8e839560 37 */
AnnaBridge 163:e59c8e839560 38
AnnaBridge 163:e59c8e839560 39 /**
AnnaBridge 163:e59c8e839560 40 * @file
AnnaBridge 163:e59c8e839560 41 * @brief RNG HAL API.
AnnaBridge 163:e59c8e839560 42 */
AnnaBridge 163:e59c8e839560 43
AnnaBridge 163:e59c8e839560 44 #ifndef NRF_RNG_H__
AnnaBridge 163:e59c8e839560 45 #define NRF_RNG_H__
AnnaBridge 163:e59c8e839560 46 /**
AnnaBridge 163:e59c8e839560 47 * @defgroup nrf_rng_hal RNG HAL
AnnaBridge 163:e59c8e839560 48 * @{
AnnaBridge 163:e59c8e839560 49 * @ingroup nrf_rng
AnnaBridge 163:e59c8e839560 50 * @brief Hardware access layer for managing the random number generator (RNG).
AnnaBridge 163:e59c8e839560 51 */
AnnaBridge 163:e59c8e839560 52
AnnaBridge 163:e59c8e839560 53 #include <stdint.h>
AnnaBridge 163:e59c8e839560 54 #include <stddef.h>
AnnaBridge 163:e59c8e839560 55 #include <stdbool.h>
AnnaBridge 163:e59c8e839560 56 #include "nrf.h"
AnnaBridge 163:e59c8e839560 57
AnnaBridge 163:e59c8e839560 58 #ifdef __cplusplus
AnnaBridge 163:e59c8e839560 59 extern "C" {
AnnaBridge 163:e59c8e839560 60 #endif
AnnaBridge 163:e59c8e839560 61
AnnaBridge 163:e59c8e839560 62 #define NRF_RNG_TASK_SET (1UL)
AnnaBridge 163:e59c8e839560 63 #define NRF_RNG_EVENT_CLEAR (0UL)
AnnaBridge 163:e59c8e839560 64 /**
AnnaBridge 163:e59c8e839560 65 * @enum nrf_rng_task_t
AnnaBridge 163:e59c8e839560 66 * @brief RNG tasks.
AnnaBridge 163:e59c8e839560 67 */
AnnaBridge 163:e59c8e839560 68 typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
AnnaBridge 163:e59c8e839560 69 {
AnnaBridge 163:e59c8e839560 70 NRF_RNG_TASK_START = offsetof(NRF_RNG_Type, TASKS_START), /**< Start the random number generator. */
AnnaBridge 163:e59c8e839560 71 NRF_RNG_TASK_STOP = offsetof(NRF_RNG_Type, TASKS_STOP) /**< Stop the random number generator. */
AnnaBridge 163:e59c8e839560 72 } nrf_rng_task_t; /*lint -restore */
AnnaBridge 163:e59c8e839560 73
AnnaBridge 163:e59c8e839560 74 /**
AnnaBridge 163:e59c8e839560 75 * @enum nrf_rng_event_t
AnnaBridge 163:e59c8e839560 76 * @brief RNG events.
AnnaBridge 163:e59c8e839560 77 */
AnnaBridge 163:e59c8e839560 78 typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
AnnaBridge 163:e59c8e839560 79 {
AnnaBridge 163:e59c8e839560 80 NRF_RNG_EVENT_VALRDY = offsetof(NRF_RNG_Type, EVENTS_VALRDY) /**< New random number generated event. */
AnnaBridge 163:e59c8e839560 81 } nrf_rng_event_t; /*lint -restore */
AnnaBridge 163:e59c8e839560 82
AnnaBridge 163:e59c8e839560 83 /**
AnnaBridge 163:e59c8e839560 84 * @enum nrf_rng_int_mask_t
AnnaBridge 163:e59c8e839560 85 * @brief RNG interrupts.
AnnaBridge 163:e59c8e839560 86 */
AnnaBridge 163:e59c8e839560 87 typedef enum
AnnaBridge 163:e59c8e839560 88 {
AnnaBridge 163:e59c8e839560 89 NRF_RNG_INT_VALRDY_MASK = RNG_INTENSET_VALRDY_Msk /**< Mask for enabling or disabling an interrupt on VALRDY event. */
AnnaBridge 163:e59c8e839560 90 } nrf_rng_int_mask_t;
AnnaBridge 163:e59c8e839560 91
AnnaBridge 163:e59c8e839560 92 /**
AnnaBridge 163:e59c8e839560 93 * @enum nrf_rng_short_mask_t
AnnaBridge 163:e59c8e839560 94 * @brief Types of RNG shortcuts.
AnnaBridge 163:e59c8e839560 95 */
AnnaBridge 163:e59c8e839560 96 typedef enum
AnnaBridge 163:e59c8e839560 97 {
AnnaBridge 163:e59c8e839560 98 NRF_RNG_SHORT_VALRDY_STOP_MASK = RNG_SHORTS_VALRDY_STOP_Msk /**< Mask for setting shortcut between EVENT_VALRDY and TASK_STOP. */
AnnaBridge 163:e59c8e839560 99 } nrf_rng_short_mask_t;
AnnaBridge 163:e59c8e839560 100
AnnaBridge 163:e59c8e839560 101 /**
AnnaBridge 163:e59c8e839560 102 * @brief Function for enabling interrupts.
AnnaBridge 163:e59c8e839560 103 *
AnnaBridge 163:e59c8e839560 104 * @param[in] rng_int_mask Mask of interrupts.
AnnaBridge 163:e59c8e839560 105 */
AnnaBridge 163:e59c8e839560 106 __STATIC_INLINE void nrf_rng_int_enable(uint32_t rng_int_mask);
AnnaBridge 163:e59c8e839560 107
AnnaBridge 163:e59c8e839560 108 /**
AnnaBridge 163:e59c8e839560 109 * @brief Function for disabling interrupts.
AnnaBridge 163:e59c8e839560 110 *
AnnaBridge 163:e59c8e839560 111 * @param[in] rng_int_mask Mask of interrupts.
AnnaBridge 163:e59c8e839560 112 */
AnnaBridge 163:e59c8e839560 113 __STATIC_INLINE void nrf_rng_int_disable(uint32_t rng_int_mask);
AnnaBridge 163:e59c8e839560 114
AnnaBridge 163:e59c8e839560 115 /**
AnnaBridge 163:e59c8e839560 116 * @brief Function for getting the state of a specific interrupt.
AnnaBridge 163:e59c8e839560 117 *
AnnaBridge 163:e59c8e839560 118 * @param[in] rng_int_mask Interrupt.
AnnaBridge 163:e59c8e839560 119 *
AnnaBridge 163:e59c8e839560 120 * @retval true If the interrupt is not enabled.
AnnaBridge 163:e59c8e839560 121 * @retval false If the interrupt is enabled.
AnnaBridge 163:e59c8e839560 122 */
AnnaBridge 163:e59c8e839560 123 __STATIC_INLINE bool nrf_rng_int_get(nrf_rng_int_mask_t rng_int_mask);
AnnaBridge 163:e59c8e839560 124
AnnaBridge 163:e59c8e839560 125 /**
AnnaBridge 163:e59c8e839560 126 * @brief Function for getting the address of a specific task.
AnnaBridge 163:e59c8e839560 127 *
AnnaBridge 163:e59c8e839560 128 * This function can be used by the PPI module.
AnnaBridge 163:e59c8e839560 129 *
AnnaBridge 163:e59c8e839560 130 * @param[in] rng_task Task.
AnnaBridge 163:e59c8e839560 131 */
AnnaBridge 163:e59c8e839560 132 __STATIC_INLINE uint32_t * nrf_rng_task_address_get(nrf_rng_task_t rng_task);
AnnaBridge 163:e59c8e839560 133
AnnaBridge 163:e59c8e839560 134 /**
AnnaBridge 163:e59c8e839560 135 * @brief Function for setting a specific task.
AnnaBridge 163:e59c8e839560 136 *
AnnaBridge 163:e59c8e839560 137 * @param[in] rng_task Task.
AnnaBridge 163:e59c8e839560 138 */
AnnaBridge 163:e59c8e839560 139 __STATIC_INLINE void nrf_rng_task_trigger(nrf_rng_task_t rng_task);
AnnaBridge 163:e59c8e839560 140
AnnaBridge 163:e59c8e839560 141 /**
AnnaBridge 163:e59c8e839560 142 * @brief Function for getting address of a specific event.
AnnaBridge 163:e59c8e839560 143 *
AnnaBridge 163:e59c8e839560 144 * This function can be used by the PPI module.
AnnaBridge 163:e59c8e839560 145 *
AnnaBridge 163:e59c8e839560 146 * @param[in] rng_event Event.
AnnaBridge 163:e59c8e839560 147 */
AnnaBridge 163:e59c8e839560 148 __STATIC_INLINE uint32_t * nrf_rng_event_address_get(nrf_rng_event_t rng_event);
AnnaBridge 163:e59c8e839560 149
AnnaBridge 163:e59c8e839560 150 /**
AnnaBridge 163:e59c8e839560 151 * @brief Function for clearing a specific event.
AnnaBridge 163:e59c8e839560 152 *
AnnaBridge 163:e59c8e839560 153 * @param[in] rng_event Event.
AnnaBridge 163:e59c8e839560 154 */
AnnaBridge 163:e59c8e839560 155 __STATIC_INLINE void nrf_rng_event_clear(nrf_rng_event_t rng_event);
AnnaBridge 163:e59c8e839560 156
AnnaBridge 163:e59c8e839560 157 /**
AnnaBridge 163:e59c8e839560 158 * @brief Function for getting the state of a specific event.
AnnaBridge 163:e59c8e839560 159 *
AnnaBridge 163:e59c8e839560 160 * @param[in] rng_event Event.
AnnaBridge 163:e59c8e839560 161 *
AnnaBridge 163:e59c8e839560 162 * @retval true If the event is not set.
AnnaBridge 163:e59c8e839560 163 * @retval false If the event is set.
AnnaBridge 163:e59c8e839560 164 */
AnnaBridge 163:e59c8e839560 165 __STATIC_INLINE bool nrf_rng_event_get(nrf_rng_event_t rng_event);
AnnaBridge 163:e59c8e839560 166
AnnaBridge 163:e59c8e839560 167 /**
AnnaBridge 163:e59c8e839560 168 * @brief Function for setting shortcuts.
AnnaBridge 163:e59c8e839560 169 *
AnnaBridge 163:e59c8e839560 170 * @param[in] rng_short_mask Mask of shortcuts.
AnnaBridge 163:e59c8e839560 171 *
AnnaBridge 163:e59c8e839560 172 */
AnnaBridge 163:e59c8e839560 173 __STATIC_INLINE void nrf_rng_shorts_enable(uint32_t rng_short_mask);
AnnaBridge 163:e59c8e839560 174
AnnaBridge 163:e59c8e839560 175 /**
AnnaBridge 163:e59c8e839560 176 * @brief Function for clearing shortcuts.
AnnaBridge 163:e59c8e839560 177 *
AnnaBridge 163:e59c8e839560 178 * @param[in] rng_short_mask Mask of shortcuts.
AnnaBridge 163:e59c8e839560 179 *
AnnaBridge 163:e59c8e839560 180 */
AnnaBridge 163:e59c8e839560 181 __STATIC_INLINE void nrf_rng_shorts_disable(uint32_t rng_short_mask);
AnnaBridge 163:e59c8e839560 182
AnnaBridge 163:e59c8e839560 183 /**
AnnaBridge 163:e59c8e839560 184 * @brief Function for getting the previously generated random value.
AnnaBridge 163:e59c8e839560 185 *
AnnaBridge 163:e59c8e839560 186 * @return Previously generated random value.
AnnaBridge 163:e59c8e839560 187 */
AnnaBridge 163:e59c8e839560 188 __STATIC_INLINE uint8_t nrf_rng_random_value_get(void);
AnnaBridge 163:e59c8e839560 189
AnnaBridge 163:e59c8e839560 190 /**
AnnaBridge 163:e59c8e839560 191 * @brief Function for enabling digital error correction.
AnnaBridge 163:e59c8e839560 192 */
AnnaBridge 163:e59c8e839560 193 __STATIC_INLINE void nrf_rng_error_correction_enable(void);
AnnaBridge 163:e59c8e839560 194
AnnaBridge 163:e59c8e839560 195 /**
AnnaBridge 163:e59c8e839560 196 * @brief Function for disabling digital error correction.
AnnaBridge 163:e59c8e839560 197 */
AnnaBridge 163:e59c8e839560 198 __STATIC_INLINE void nrf_rng_error_correction_disable(void);
AnnaBridge 163:e59c8e839560 199
AnnaBridge 163:e59c8e839560 200 /**
AnnaBridge 163:e59c8e839560 201 *@}
AnnaBridge 163:e59c8e839560 202 **/
AnnaBridge 163:e59c8e839560 203
AnnaBridge 163:e59c8e839560 204 #ifndef SUPPRESS_INLINE_IMPLEMENTATION
AnnaBridge 163:e59c8e839560 205
AnnaBridge 163:e59c8e839560 206 __STATIC_INLINE void nrf_rng_int_enable(uint32_t rng_int_mask)
AnnaBridge 163:e59c8e839560 207 {
AnnaBridge 163:e59c8e839560 208 NRF_RNG->INTENSET = rng_int_mask;
AnnaBridge 163:e59c8e839560 209 }
AnnaBridge 163:e59c8e839560 210
AnnaBridge 163:e59c8e839560 211 __STATIC_INLINE void nrf_rng_int_disable(uint32_t rng_int_mask)
AnnaBridge 163:e59c8e839560 212 {
AnnaBridge 163:e59c8e839560 213 NRF_RNG->INTENCLR = rng_int_mask;
AnnaBridge 163:e59c8e839560 214 }
AnnaBridge 163:e59c8e839560 215
AnnaBridge 163:e59c8e839560 216 __STATIC_INLINE bool nrf_rng_int_get(nrf_rng_int_mask_t rng_int_mask)
AnnaBridge 163:e59c8e839560 217 {
AnnaBridge 163:e59c8e839560 218 return (bool)(NRF_RNG->INTENCLR & rng_int_mask);
AnnaBridge 163:e59c8e839560 219 }
AnnaBridge 163:e59c8e839560 220
AnnaBridge 163:e59c8e839560 221 __STATIC_INLINE uint32_t * nrf_rng_task_address_get(nrf_rng_task_t rng_task)
AnnaBridge 163:e59c8e839560 222 {
AnnaBridge 163:e59c8e839560 223 return (uint32_t *)((uint8_t *)NRF_RNG + rng_task);
AnnaBridge 163:e59c8e839560 224 }
AnnaBridge 163:e59c8e839560 225
AnnaBridge 163:e59c8e839560 226 __STATIC_INLINE void nrf_rng_task_trigger(nrf_rng_task_t rng_task)
AnnaBridge 163:e59c8e839560 227 {
AnnaBridge 163:e59c8e839560 228 *((volatile uint32_t *)((uint8_t *)NRF_RNG + rng_task)) = NRF_RNG_TASK_SET;
AnnaBridge 163:e59c8e839560 229 }
AnnaBridge 163:e59c8e839560 230
AnnaBridge 163:e59c8e839560 231 __STATIC_INLINE uint32_t * nrf_rng_event_address_get(nrf_rng_event_t rng_event)
AnnaBridge 163:e59c8e839560 232 {
AnnaBridge 163:e59c8e839560 233 return (uint32_t *)((uint8_t *)NRF_RNG + rng_event);
AnnaBridge 163:e59c8e839560 234 }
AnnaBridge 163:e59c8e839560 235
AnnaBridge 163:e59c8e839560 236 __STATIC_INLINE void nrf_rng_event_clear(nrf_rng_event_t rng_event)
AnnaBridge 163:e59c8e839560 237 {
AnnaBridge 163:e59c8e839560 238 *((volatile uint32_t *)((uint8_t *)NRF_RNG + rng_event)) = NRF_RNG_EVENT_CLEAR;
AnnaBridge 163:e59c8e839560 239 #if __CORTEX_M == 0x04
AnnaBridge 163:e59c8e839560 240 volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_RNG + rng_event));
AnnaBridge 163:e59c8e839560 241 (void)dummy;
AnnaBridge 163:e59c8e839560 242 #endif
AnnaBridge 163:e59c8e839560 243 }
AnnaBridge 163:e59c8e839560 244
AnnaBridge 163:e59c8e839560 245 __STATIC_INLINE bool nrf_rng_event_get(nrf_rng_event_t rng_event)
AnnaBridge 163:e59c8e839560 246 {
AnnaBridge 163:e59c8e839560 247 return (bool) * ((volatile uint32_t *)((uint8_t *)NRF_RNG + rng_event));
AnnaBridge 163:e59c8e839560 248 }
AnnaBridge 163:e59c8e839560 249
AnnaBridge 163:e59c8e839560 250 __STATIC_INLINE void nrf_rng_shorts_enable(uint32_t rng_short_mask)
AnnaBridge 163:e59c8e839560 251 {
AnnaBridge 163:e59c8e839560 252 NRF_RNG->SHORTS |= rng_short_mask;
AnnaBridge 163:e59c8e839560 253 }
AnnaBridge 163:e59c8e839560 254
AnnaBridge 163:e59c8e839560 255 __STATIC_INLINE void nrf_rng_shorts_disable(uint32_t rng_short_mask)
AnnaBridge 163:e59c8e839560 256 {
AnnaBridge 163:e59c8e839560 257 NRF_RNG->SHORTS &= ~rng_short_mask;
AnnaBridge 163:e59c8e839560 258 }
AnnaBridge 163:e59c8e839560 259
AnnaBridge 163:e59c8e839560 260 __STATIC_INLINE uint8_t nrf_rng_random_value_get(void)
AnnaBridge 163:e59c8e839560 261 {
AnnaBridge 163:e59c8e839560 262 return (uint8_t)(NRF_RNG->VALUE & RNG_VALUE_VALUE_Msk);
AnnaBridge 163:e59c8e839560 263 }
AnnaBridge 163:e59c8e839560 264
AnnaBridge 163:e59c8e839560 265 __STATIC_INLINE void nrf_rng_error_correction_enable(void)
AnnaBridge 163:e59c8e839560 266 {
AnnaBridge 163:e59c8e839560 267 NRF_RNG->CONFIG |= RNG_CONFIG_DERCEN_Msk;
AnnaBridge 163:e59c8e839560 268 }
AnnaBridge 163:e59c8e839560 269
AnnaBridge 163:e59c8e839560 270 __STATIC_INLINE void nrf_rng_error_correction_disable(void)
AnnaBridge 163:e59c8e839560 271 {
AnnaBridge 163:e59c8e839560 272 NRF_RNG->CONFIG &= ~RNG_CONFIG_DERCEN_Msk;
AnnaBridge 163:e59c8e839560 273 }
AnnaBridge 163:e59c8e839560 274
AnnaBridge 163:e59c8e839560 275 #endif
AnnaBridge 163:e59c8e839560 276
AnnaBridge 163:e59c8e839560 277 #ifdef __cplusplus
AnnaBridge 163:e59c8e839560 278 }
AnnaBridge 163:e59c8e839560 279 #endif
AnnaBridge 163:e59c8e839560 280
AnnaBridge 163:e59c8e839560 281 #endif /* NRF_RNG_H__ */