diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/config/sdk_config.h b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/config/sdk_config.h index f4d927b90e..f2a12bddbd 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/config/sdk_config.h +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/config/sdk_config.h @@ -4949,7 +4949,7 @@ // RNG_ENABLED - nrf_drv_rng - RNG peripheral driver - legacy layer //========================================================== #ifndef RNG_ENABLED -#define RNG_ENABLED 0 +#define RNG_ENABLED 1 #endif // RNG_CONFIG_ERROR_CORRECTION - Error correction @@ -6844,7 +6844,7 @@ // NRF_QUEUE_ENABLED - nrf_queue - Queue module //========================================================== #ifndef NRF_QUEUE_ENABLED -#define NRF_QUEUE_ENABLED 0 +#define NRF_QUEUE_ENABLED 1 #endif // NRF_QUEUE_CLI_CMDS - Enable CLI commands specific to the module diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/components/libraries/queue/nrf_queue.c b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/components/libraries/queue/nrf_queue.c new file mode 100644 index 0000000000..9afc16ca8a --- /dev/null +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/components/libraries/queue/nrf_queue.c @@ -0,0 +1,547 @@ +/** + * Copyright (c) 2016 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "sdk_common.h" +#if NRF_MODULE_ENABLED(NRF_QUEUE) +#include "nrf_queue.h" +#include "app_util_platform.h" + +#if NRF_QUEUE_CONFIG_LOG_ENABLED + #define NRF_LOG_LEVEL NRF_QUEUE_CONFIG_LOG_LEVEL + #define NRF_LOG_INIT_FILTER_LEVEL NRF_QUEUE_CONFIG_LOG_INIT_FILTER_LEVEL + #define NRF_LOG_INFO_COLOR NRF_QUEUE_CONFIG_INFO_COLOR + #define NRF_LOG_DEBUG_COLOR NRF_QUEUE_CONFIG_DEBUG_COLOR +#else + #define NRF_LOG_LEVEL 0 +#endif // NRF_QUEUE_CONFIG_LOG_ENABLED +#include "nrf_log.h" + +NRF_SECTION_DEF(nrf_queue, nrf_queue_t); + +#if NRF_QUEUE_CLI_CMDS +#include "nrf_cli.h" + +static void nrf_queue_status(nrf_cli_t const * p_cli, size_t argc, char **argv) +{ + UNUSED_PARAMETER(argv); + + if (nrf_cli_help_requested(p_cli)) + { + nrf_cli_help_print(p_cli, NULL, 0); + return; + } + + if (argc > 1) + { + nrf_cli_fprintf(p_cli, NRF_CLI_ERROR, "Bad argument count"); + return; + } + + uint32_t num_of_instances = NRF_SECTION_ITEM_COUNT(nrf_queue, nrf_queue_t); + uint32_t i; + + for (i = 0; i < num_of_instances; i++) + { + const nrf_queue_t * p_instance = NRF_SECTION_ITEM_GET(nrf_queue, nrf_queue_t, i); + + uint32_t element_size = p_instance->element_size; + uint32_t size = p_instance->size; + uint32_t max_util = nrf_queue_max_utilization_get(p_instance); + uint32_t util = nrf_queue_utilization_get(p_instance); + const char * p_name = p_instance->p_name; + nrf_cli_fprintf(p_cli, NRF_CLI_NORMAL, + "%s\r\n\t- Element size:\t%d\r\n" + "\t- Usage:\t%u%% (%u out of %u elements)\r\n" + "\t- Maximum:\t%u%% (%u out of %u elements)\r\n" + "\t- Mode:\t\t%s\r\n\r\n", + p_name, element_size, + 100ul * util/size, util,size, + 100ul * max_util/size, max_util,size, + (p_instance->mode == NRF_QUEUE_MODE_OVERFLOW) ? "Overflow" : "No overflow"); + + } +} +// Register "queue" command and its subcommands in CLI. +NRF_CLI_CREATE_STATIC_SUBCMD_SET(nrf_queue_commands) +{ + NRF_CLI_CMD(status, NULL, "Print status of queue instances.", nrf_queue_status), + NRF_CLI_SUBCMD_SET_END +}; + +NRF_CLI_CMD_REGISTER(queue, &nrf_queue_commands, "Commands for BALLOC management", nrf_queue_status); +#endif //NRF_QUEUE_CLI_CMDS + +/**@brief Get next element index. + * + * @param[in] p_queue Pointer to the queue instance. + * @param[in] idx Current index. + * + * @return Next element index. + */ +__STATIC_INLINE size_t nrf_queue_next_idx(nrf_queue_t const * p_queue, size_t idx) +{ + ASSERT(p_queue != NULL); + return (idx < p_queue->size) ? (idx + 1) : 0; +} + +/**@brief Get current queue utilization. This function assumes that this process will not be interrupted. + * + * @param[in] p_queue Pointer to the queue instance. + * + * @return Current queue utilization. + */ +__STATIC_INLINE size_t queue_utilization_get(nrf_queue_t const * p_queue) +{ + size_t front = p_queue->p_cb->front; + size_t back = p_queue->p_cb->back; + return (back >= front) ? (back - front) : (p_queue->size + 1 - front + back); +} + +bool nrf_queue_is_full(nrf_queue_t const * p_queue) +{ + ASSERT(p_queue != NULL); + size_t front = p_queue->p_cb->front; + size_t back = p_queue->p_cb->back; + + return (nrf_queue_next_idx(p_queue, back) == front); +} + +ret_code_t nrf_queue_push(nrf_queue_t const * p_queue, void const * p_element) +{ + ret_code_t status = NRF_SUCCESS; + + ASSERT(p_queue != NULL); + ASSERT(p_element != NULL); + + CRITICAL_REGION_ENTER(); + bool is_full = nrf_queue_is_full(p_queue); + + if (!is_full || (p_queue->mode == NRF_QUEUE_MODE_OVERFLOW)) + { + // Get write position. + size_t write_pos = p_queue->p_cb->back; + p_queue->p_cb->back = nrf_queue_next_idx(p_queue, p_queue->p_cb->back); + if (is_full) + { + // Overwrite the oldest element. + NRF_LOG_INST_WARNING(p_queue->p_log, "Queue full. Overwriting oldest element."); + p_queue->p_cb->front = nrf_queue_next_idx(p_queue, p_queue->p_cb->front); + } + + // Write a new element. + switch (p_queue->element_size) + { + case sizeof(uint8_t): + ((uint8_t *)p_queue->p_buffer)[write_pos] = *((uint8_t *)p_element); + break; + + case sizeof(uint16_t): + ((uint16_t *)p_queue->p_buffer)[write_pos] = *((uint16_t *)p_element); + break; + + case sizeof(uint32_t): + ((uint32_t *)p_queue->p_buffer)[write_pos] = *((uint32_t *)p_element); + break; + + case sizeof(uint64_t): + ((uint64_t *)p_queue->p_buffer)[write_pos] = *((uint64_t *)p_element); + break; + + default: + memcpy((void *)((size_t)p_queue->p_buffer + write_pos * p_queue->element_size), + p_element, + p_queue->element_size); + break; + } + + // Update utilization. + size_t utilization = queue_utilization_get(p_queue); + if (p_queue->p_cb->max_utilization < utilization) + { + p_queue->p_cb->max_utilization = utilization; + } + } + else + { + status = NRF_ERROR_NO_MEM; + } + + CRITICAL_REGION_EXIT(); + + NRF_LOG_INST_DEBUG(p_queue->p_log, "pushed element 0x%08X, status:%d", p_element, status); + return status; +} + +ret_code_t nrf_queue_generic_pop(nrf_queue_t const * p_queue, + void * p_element, + bool just_peek) +{ + ret_code_t status = NRF_SUCCESS; + + ASSERT(p_queue != NULL); + ASSERT(p_element != NULL); + + CRITICAL_REGION_ENTER(); + + if (!nrf_queue_is_empty(p_queue)) + { + // Get read position. + size_t read_pos = p_queue->p_cb->front; + + // Update next read position. + if (!just_peek) + { + p_queue->p_cb->front = nrf_queue_next_idx(p_queue, p_queue->p_cb->front); + } + + // Read element. + switch (p_queue->element_size) + { + case sizeof(uint8_t): + *((uint8_t *)p_element) = ((uint8_t *)p_queue->p_buffer)[read_pos]; + break; + + case sizeof(uint16_t): + *((uint16_t *)p_element) = ((uint16_t *)p_queue->p_buffer)[read_pos]; + break; + + case sizeof(uint32_t): + *((uint32_t *)p_element) = ((uint32_t *)p_queue->p_buffer)[read_pos]; + break; + + case sizeof(uint64_t): + *((uint64_t *)p_element) = ((uint64_t *)p_queue->p_buffer)[read_pos]; + break; + + default: + memcpy(p_element, + (void const *)((size_t)p_queue->p_buffer + read_pos * p_queue->element_size), + p_queue->element_size); + break; + } + } + else + { + status = NRF_ERROR_NOT_FOUND; + } + + CRITICAL_REGION_EXIT(); + NRF_LOG_INST_DEBUG(p_queue->p_log, "%s element 0x%08X, status:%d", + just_peek ? "peeked" : "popped", p_element, status); + return status; +} + +/**@brief Write elements to the queue. This function assumes that there is enough room in the queue + * to write the requested number of elements and that this process will not be interrupted. + * + * @param[in] p_queue Pointer to the nrf_queue_t instance. + * @param[in] p_data Pointer to the buffer with elements to write. + * @param[in] element_count Number of elements to write. + */ +static void queue_write(nrf_queue_t const * p_queue, void const * p_data, uint32_t element_count) +{ + size_t prev_available = nrf_queue_available_get(p_queue); + size_t continuous = p_queue->size + 1 - p_queue->p_cb->back; + void * p_write_ptr = (void *)((size_t)p_queue->p_buffer + + p_queue->p_cb->back * p_queue->element_size); + if (element_count <= continuous) + { + memcpy(p_write_ptr, + p_data, + element_count * p_queue->element_size); + + p_queue->p_cb->back = ((p_queue->p_cb->back + element_count) <= p_queue->size) + ? (p_queue->p_cb->back + element_count) + : 0; + } + else + { + size_t first_write_length = continuous * p_queue->element_size; + memcpy(p_write_ptr, + p_data, + first_write_length); + + size_t elements_left = element_count - continuous; + memcpy(p_queue->p_buffer, + (void const *)((size_t)p_data + first_write_length), + elements_left * p_queue->element_size); + + p_queue->p_cb->back = elements_left; + if (prev_available < element_count) + { + // Overwrite the oldest elements. + p_queue->p_cb->front = nrf_queue_next_idx(p_queue, p_queue->p_cb->back); + } + } + + // Update utilization. + size_t utilization = queue_utilization_get(p_queue); + if (p_queue->p_cb->max_utilization < utilization) + { + p_queue->p_cb->max_utilization = utilization; + } +} + +ret_code_t nrf_queue_write(nrf_queue_t const * p_queue, + void const * p_data, + size_t element_count) +{ + ret_code_t status = NRF_SUCCESS; + + ASSERT(p_queue != NULL); + ASSERT(p_data != NULL); + ASSERT(element_count <= p_queue->size); + + if (element_count == 0) + { + return NRF_SUCCESS; + } + + CRITICAL_REGION_ENTER(); + + if ((nrf_queue_available_get(p_queue) >= element_count) + || (p_queue->mode == NRF_QUEUE_MODE_OVERFLOW)) + { + queue_write(p_queue, p_data, element_count); + } + else + { + status = NRF_ERROR_NO_MEM; + } + + CRITICAL_REGION_EXIT(); + + NRF_LOG_INST_DEBUG(p_queue->p_log, "Write %d elements (start address: 0x%08X), status:%d", + element_count, p_data, status); + return status; +} + + +size_t nrf_queue_in(nrf_queue_t const * p_queue, + void const * p_data, + size_t element_count) +{ + ASSERT(p_queue != NULL); + ASSERT(p_data != NULL); + + size_t req_element_count = element_count; + + if (element_count == 0) + { + return 0; + } + + CRITICAL_REGION_ENTER(); + + if (p_queue->mode == NRF_QUEUE_MODE_OVERFLOW) + { + element_count = MIN(element_count, p_queue->size); + } + else + { + size_t available = nrf_queue_available_get(p_queue); + element_count = MIN(element_count, available); + } + + queue_write(p_queue, p_data, element_count); + + CRITICAL_REGION_EXIT(); + + NRF_LOG_INST_DEBUG(p_queue->p_log, "Put in %d elements (start address: 0x%08X), requested :%d", + element_count, p_data, req_element_count); + + return element_count; +} + +/**@brief Read elements from the queue. This function assumes that there are enough elements + * in the queue to read and that this process will not be interrupted. + * + * @param[in] p_queue Pointer to the nrf_queue_t instance. + * @param[out] p_data Pointer to the buffer where elements will be copied. + * @param[in] element_count Number of elements to read. + */ +static void queue_read(nrf_queue_t const * p_queue, void * p_data, uint32_t element_count) +{ + size_t front = p_queue->p_cb->front; + size_t back = p_queue->p_cb->back; + size_t continuous = (front <= back) ? (back - front) : (p_queue->size + 1 - front); + void const * p_read_ptr = (void const *)((size_t)p_queue->p_buffer + + front * p_queue->element_size); + + if (element_count <= continuous) + { + memcpy(p_data, + p_read_ptr, + element_count * p_queue->element_size); + + p_queue->p_cb->front = ((front + element_count) <= p_queue->size) + ? (front + element_count) + : 0; + } + else + { + size_t first_read_length = continuous * p_queue->element_size; + memcpy(p_data, + p_read_ptr, + first_read_length); + + size_t elements_left = element_count - continuous; + memcpy((void *)((size_t)p_data + first_read_length), + p_queue->p_buffer, + elements_left * p_queue->element_size); + + p_queue->p_cb->front = elements_left; + } +} + +ret_code_t nrf_queue_read(nrf_queue_t const * p_queue, + void * p_data, + size_t element_count) +{ + ret_code_t status = NRF_SUCCESS; + + ASSERT(p_queue != NULL); + ASSERT(p_data != NULL); + + if (element_count == 0) + { + return NRF_SUCCESS; + } + + CRITICAL_REGION_ENTER(); + + if (element_count <= queue_utilization_get(p_queue)) + { + queue_read(p_queue, p_data, element_count); + } + else + { + status = NRF_ERROR_NOT_FOUND; + } + + CRITICAL_REGION_EXIT(); + + NRF_LOG_INST_DEBUG(p_queue->p_log, "Read %d elements (start address: 0x%08X), status :%d", + element_count, p_data, status); + return status; +} + +size_t nrf_queue_out(nrf_queue_t const * p_queue, + void * p_data, + size_t element_count) +{ + ASSERT(p_queue != NULL); + ASSERT(p_data != NULL); + + size_t req_element_count = element_count; + + if (element_count == 0) + { + return 0; + } + + CRITICAL_REGION_ENTER(); + + size_t utilization = queue_utilization_get(p_queue); + element_count = MIN(element_count, utilization); + + queue_read(p_queue, p_data, element_count); + + CRITICAL_REGION_EXIT(); + + NRF_LOG_INST_DEBUG(p_queue->p_log, "Out %d elements (start address: 0x%08X), requested :%d", + element_count, p_data, req_element_count); + return element_count; +} + +void nrf_queue_reset(nrf_queue_t const * p_queue) +{ + ASSERT(p_queue != NULL); + + CRITICAL_REGION_ENTER(); + + memset(p_queue->p_cb, 0, sizeof(nrf_queue_cb_t)); + + CRITICAL_REGION_EXIT(); + + NRF_LOG_INST_DEBUG(p_queue->p_log, "Reset"); +} + +size_t nrf_queue_utilization_get(nrf_queue_t const * p_queue) +{ + size_t utilization; + ASSERT(p_queue != NULL); + + CRITICAL_REGION_ENTER(); + + utilization = queue_utilization_get(p_queue); + + CRITICAL_REGION_EXIT(); + + return utilization; +} + +bool nrf_queue_is_empty(nrf_queue_t const * p_queue) +{ + ASSERT(p_queue != NULL); + size_t front = p_queue->p_cb->front; + size_t back = p_queue->p_cb->back; + return (front == back); +} + +size_t nrf_queue_available_get(nrf_queue_t const * p_queue) +{ + ASSERT(p_queue != NULL); + return p_queue->size - nrf_queue_utilization_get(p_queue); +} + +size_t nrf_queue_max_utilization_get(nrf_queue_t const * p_queue) +{ + ASSERT(p_queue != NULL); + return p_queue->p_cb->max_utilization; +} + +void nrf_queue_max_utilization_reset(nrf_queue_t const * p_queue) +{ + ASSERT(p_queue != NULL); + p_queue->p_cb->max_utilization = 0; +} + + +#endif // NRF_MODULE_ENABLED(NRF_QUEUE) diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/components/libraries/queue/nrf_queue.h b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/components/libraries/queue/nrf_queue.h new file mode 100644 index 0000000000..1ba2a9272b --- /dev/null +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/components/libraries/queue/nrf_queue.h @@ -0,0 +1,429 @@ +/** + * Copyright (c) 2016 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/** +* @defgroup nrf_queue Queue module +* @{ +* @ingroup app_common +* @brief Functions that handle the queue instances. +*/ + +#ifndef NRF_QUEUE_H__ +#define NRF_QUEUE_H__ + +#include +#include +#include +#include "nrf_assert.h" +#include "sdk_errors.h" +#include "app_util.h" +#include "app_util_platform.h" +#include "nrf_log_instance.h" +#include "nrf_section.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @brief Name of the module used for logger messaging. + */ +#define NRF_QUEUE_LOG_NAME queue + +/**@brief Queue control block. */ +typedef struct +{ + volatile size_t front; //!< Queue front index. + volatile size_t back; //!< Queue back index. + size_t max_utilization; //!< Maximum utilization of the queue. +} nrf_queue_cb_t; + +/**@brief Supported queue modes. */ +typedef enum +{ + NRF_QUEUE_MODE_OVERFLOW, //!< If the queue is full, new element will overwrite the oldest. + NRF_QUEUE_MODE_NO_OVERFLOW, //!< If the queue is full, new element will not be accepted. +} nrf_queue_mode_t; + +/**@brief Instance of the queue. */ +typedef struct +{ + nrf_queue_cb_t * p_cb; //!< Pointer to the instance control block. + void * p_buffer; //!< Pointer to the memory that is used as storage. + size_t size; //!< Size of the queue. + size_t element_size; //!< Size of one element. + nrf_queue_mode_t mode; //!< Mode of the queue. +#if NRF_QUEUE_CLI_CMDS + const char * p_name; //!< Pointer to string with queue name. +#endif + NRF_LOG_INSTANCE_PTR_DECLARE(p_log) //!< Pointer to instance of the logger object (Conditionally compiled). +} nrf_queue_t; + +#if NRF_QUEUE_CLI_CMDS +#define __NRF_QUEUE_ASSIGN_POOL_NAME(_name) .p_name = STRINGIFY(_name), +#else +#define __NRF_QUEUE_ASSIGN_POOL_NAME(_name) +#endif +/**@brief Create a queue instance. + * + * @note This macro reserves memory for the given queue instance. + * + * @param[in] _type Type which is stored. + * @param[in] _name Name of the queue. + * @param[in] _size Size of the queue. + * @param[in] _mode Mode of the queue. + */ +#define NRF_QUEUE_DEF(_type, _name, _size, _mode) \ + static _type CONCAT_2(_name, _nrf_queue_buffer[(_size) + 1]); \ + static nrf_queue_cb_t CONCAT_2(_name, _nrf_queue_cb); \ + NRF_LOG_INSTANCE_REGISTER(NRF_QUEUE_LOG_NAME, _name, \ + NRF_QUEUE_CONFIG_INFO_COLOR, \ + NRF_QUEUE_CONFIG_DEBUG_COLOR, \ + NRF_QUEUE_CONFIG_LOG_INIT_FILTER_LEVEL, \ + NRF_QUEUE_CONFIG_LOG_ENABLED ? \ + NRF_QUEUE_CONFIG_LOG_LEVEL : NRF_LOG_SEVERITY_NONE); \ + NRF_SECTION_ITEM_REGISTER(nrf_queue, const nrf_queue_t _name) = \ + { \ + .p_cb = &CONCAT_2(_name, _nrf_queue_cb), \ + .p_buffer = CONCAT_2(_name,_nrf_queue_buffer), \ + .size = (_size), \ + .element_size = sizeof(_type), \ + .mode = _mode, \ + __NRF_QUEUE_ASSIGN_POOL_NAME(_name) \ + NRF_LOG_INSTANCE_PTR_INIT(p_log, NRF_QUEUE_LOG_NAME, _name) \ + } + +/**@brief Declare a queue interface. + * + * @param[in] _type Type which is stored. + * @param[in] _name Name of the queue. + */ +#define NRF_QUEUE_INTERFACE_DEC(_type, _name) \ + ret_code_t _name##_push(_type const * p_element); \ + ret_code_t _name##_pop(_type * p_element); \ + ret_code_t _name##_peek(_type * p_element); \ + ret_code_t _name##_write(_type const * p_data, \ + size_t element_count); \ + ret_code_t _name##_read(_type * p_data, \ + size_t element_count); \ + size_t _name##_out(_type * p_data, \ + size_t element_count); \ + size_t _name##_in(_type const * p_data, \ + size_t element_count); \ + bool _name##_is_full(void); \ + bool _name##_is_empty(void); \ + size_t _name##_utilization_get(void); \ + size_t _name##_available_get(void); \ + size_t _name##_max_utilization_get(void); \ + void _name##_reset(void) + +/**@brief Define a queue interface. + * + * @param[in] _type Type which is stored. + * @param[in] _name Name of the queue. + * @param[in] _p_queue Queue instance. + */ +#define NRF_QUEUE_INTERFACE_DEF(_type, _name, _p_queue) \ + ret_code_t _name##_push(_type const * p_element) \ + { \ + GCC_PRAGMA("GCC diagnostic push") \ + GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \ + ASSERT((_p_queue) != NULL); \ + ASSERT((_p_queue)->element_size == sizeof(_type)); \ + GCC_PRAGMA("GCC diagnostic pop") \ + return nrf_queue_push((_p_queue), p_element); \ + } \ + ret_code_t _name##_pop(_type * p_element) \ + { \ + GCC_PRAGMA("GCC diagnostic push") \ + GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \ + ASSERT((_p_queue) != NULL); \ + ASSERT((_p_queue)->element_size == sizeof(_type)); \ + GCC_PRAGMA("GCC diagnostic pop") \ + return nrf_queue_pop((_p_queue), p_element); \ + } \ + ret_code_t _name##_peek(_type * p_element) \ + { \ + GCC_PRAGMA("GCC diagnostic push") \ + GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \ + ASSERT((_p_queue) != NULL); \ + ASSERT((_p_queue)->element_size == sizeof(_type)); \ + GCC_PRAGMA("GCC diagnostic pop") \ + return nrf_queue_peek((_p_queue), p_element); \ + } \ + ret_code_t _name##_write(_type const * p_data, \ + size_t element_count) \ + { \ + GCC_PRAGMA("GCC diagnostic push") \ + GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \ + ASSERT((_p_queue) != NULL); \ + ASSERT((_p_queue)->element_size == sizeof(_type)); \ + GCC_PRAGMA("GCC diagnostic pop") \ + return nrf_queue_write((_p_queue), p_data, element_count); \ + } \ + ret_code_t _name##_read(_type * p_data, \ + size_t element_count) \ + { \ + GCC_PRAGMA("GCC diagnostic push") \ + GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \ + ASSERT((_p_queue) != NULL); \ + ASSERT((_p_queue)->element_size == sizeof(_type)); \ + GCC_PRAGMA("GCC diagnostic pop") \ + return nrf_queue_read((_p_queue), p_data, element_count); \ + } \ + size_t _name##_in(_type const * p_data, \ + size_t element_count) \ + { \ + GCC_PRAGMA("GCC diagnostic push") \ + GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \ + ASSERT((_p_queue) != NULL); \ + ASSERT((_p_queue)->element_size == sizeof(_type)); \ + GCC_PRAGMA("GCC diagnostic pop") \ + return nrf_queue_in((_p_queue), p_data, element_count); \ + } \ + size_t _name##_out(_type * p_data, \ + size_t element_count) \ + { \ + GCC_PRAGMA("GCC diagnostic push") \ + GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \ + ASSERT((_p_queue) != NULL); \ + ASSERT((_p_queue)->element_size == sizeof(_type)); \ + GCC_PRAGMA("GCC diagnostic pop") \ + return nrf_queue_out((_p_queue), p_data, element_count); \ + } \ + bool _name##_is_full(void) \ + { \ + GCC_PRAGMA("GCC diagnostic push") \ + GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \ + ASSERT((_p_queue) != NULL); \ + return nrf_queue_is_full(_p_queue); \ + GCC_PRAGMA("GCC diagnostic pop") \ + } \ + bool _name##_is_empty(void) \ + { \ + GCC_PRAGMA("GCC diagnostic push") \ + GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \ + ASSERT((_p_queue) != NULL); \ + GCC_PRAGMA("GCC diagnostic pop") \ + return nrf_queue_is_empty(_p_queue); \ + } \ + size_t _name##_utilization_get(void) \ + { \ + GCC_PRAGMA("GCC diagnostic push") \ + GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \ + ASSERT((_p_queue) != NULL); \ + GCC_PRAGMA("GCC diagnostic pop") \ + return nrf_queue_utilization_get(_p_queue); \ + } \ + size_t _name##_available_get(void) \ + { \ + GCC_PRAGMA("GCC diagnostic push") \ + GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \ + ASSERT((_p_queue) != NULL); \ + GCC_PRAGMA("GCC diagnostic pop") \ + return nrf_queue_available_get(_p_queue); \ + } \ + size_t _name##_max_utilization_get(void) \ + { \ + GCC_PRAGMA("GCC diagnostic push") \ + GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \ + ASSERT((_p_queue) != NULL); \ + GCC_PRAGMA("GCC diagnostic pop") \ + return nrf_queue_max_utilization_get(_p_queue); \ + } \ + void _name##_reset(void) \ + { \ + GCC_PRAGMA("GCC diagnostic push") \ + GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \ + ASSERT((_p_queue) != NULL); \ + GCC_PRAGMA("GCC diagnostic pop") \ + nrf_queue_reset(_p_queue); \ + } + +/**@brief Function for pushing an element to the end of queue. + * + * @param[in] p_queue Pointer to the nrf_queue_t instance. + * @param[in] p_element Pointer to the element that will be stored in the queue. + * + * @return NRF_SUCCESS If an element has been successfully added. + * @return NRF_ERROR_NO_MEM If the queue is full (only in @ref NRF_QUEUE_MODE_NO_OVERFLOW). + */ +ret_code_t nrf_queue_push(nrf_queue_t const * p_queue, void const * p_element); + +/**@brief Generic pop implementation. + * + * @param[in] p_queue Pointer to the nrf_queue_t instance. + * @param[out] p_element Pointer where the element will be copied. + * @param[out] just_peek If true, the returned element will not be removed from queue. + * + * @return NRF_SUCCESS If an element was returned. + * @return NRF_ERROR_NOT_FOUND If there are no more elements in the queue. + */ +ret_code_t nrf_queue_generic_pop(nrf_queue_t const * p_queue, + void * p_element, + bool just_peek); + +/**@brief Pop element from the front of the queue. + * + * @param[in] _p_queue Pointer to the nrf_queue_t instance. + * @param[out] _p_element Pointer where the element will be copied. + * + * @return NRF_SUCCESS If an element was returned. + * @return NRF_ERROR_NOT_FOUND If there are no more elements in the queue. + */ +#define nrf_queue_pop(_p_queue, _p_element) nrf_queue_generic_pop((_p_queue), (_p_element), false) + +/**@brief Peek element from the front of the queue. + * + * @param[in] _p_queue Pointer to the nrf_queue_t instance. + * @param[out] _p_element Pointer where the element will be copied. + * + * @return NRF_SUCCESS If an element was returned. + * @return NRF_ERROR_NOT_FOUND If there are no more elements in the queue. + */ +#define nrf_queue_peek(_p_queue, _p_element) nrf_queue_generic_pop((_p_queue), (_p_element), true) + +/**@brief Function for writing elements to the queue. + * + * @param[in] p_queue Pointer to the nrf_queue_t instance. + * @param[in] p_data Pointer to the buffer with elements to write. + * @param[in] element_count Number of elements to write. + * + * @return NRF_SUCCESS If an element was written. + * @return NRF_ERROR_NO_MEM There is not enough space in the queue. No element was written. + */ +ret_code_t nrf_queue_write(nrf_queue_t const * p_queue, + void const * p_data, + size_t element_count); + +/**@brief Function for writing a portion of elements to the queue. + * + * @param[in] p_queue Pointer to the nrf_queue_t instance. + * @param[in] p_data Pointer to the buffer with elements to write. + * @param[in] element_count Number of elements to write. + * + * @return The number of added elements. + */ +size_t nrf_queue_in(nrf_queue_t const * p_queue, + void const * p_data, + size_t element_count); + +/**@brief Function for reading elements from the queue. + * + * @param[in] p_queue Pointer to the nrf_queue_t instance. + * @param[out] p_data Pointer to the buffer where elements will be copied. + * @param[in] element_count Number of elements to read. + * + * @return NRF_SUCCESS If an element was returned. + * @return NRF_ERROR_NOT_FOUND There is not enough elements in the queue. + */ +ret_code_t nrf_queue_read(nrf_queue_t const * p_queue, + void * p_data, + size_t element_count); + +/**@brief Function for reading a portion of elements from the queue. + * + * @param[in] p_queue Pointer to the nrf_queue_t instance. + * @param[out] p_data Pointer to the buffer where elements will be copied. + * @param[in] element_count Number of elements to read. + * + * @return The number of read elements. + */ +size_t nrf_queue_out(nrf_queue_t const * p_queue, + void * p_data, + size_t element_count); + +/**@brief Function for checking if the queue is full. + * + * @param[in] p_queue Pointer to the queue instance. + * + * @return True if the queue is full. + */ +bool nrf_queue_is_full(nrf_queue_t const * p_queue); + +/**@brief Function for checking if the queue is empty. + * + * @param[in] p_queue Pointer to the queue instance. + * + * @return True if the queue is empty. + */ +bool nrf_queue_is_empty(nrf_queue_t const * p_queue); + +/**@brief Function for getting the current queue utilization. + * + * @param[in] p_queue Pointer to the queue instance. + * + * @return Current queue utilization. + */ +size_t nrf_queue_utilization_get(nrf_queue_t const * p_queue); + +/**@brief Function for getting the size of available space. + * + * @param[in] p_queue Pointer to the queue instance. + * + * @return Size of available space. + */ +size_t nrf_queue_available_get(nrf_queue_t const * p_queue); + +/**@brief Function for getting the maximal queue utilization. + * + * @param[in] p_queue Pointer to the queue instance. + * + * @return Maximal queue utilization. + */ +size_t nrf_queue_max_utilization_get(nrf_queue_t const * p_queue); + +/**@brief Function for resetting the maximal queue utilization. + * + * @param[in] p_queue Pointer to the queue instance. + * + */ +void nrf_queue_max_utilization_reset(nrf_queue_t const * p_queue); + +/**@brief Function for resetting the queue state. + * + * @param[in] p_queue Pointer to the queue instance. + */ +void nrf_queue_reset(nrf_queue_t const * p_queue); + +#ifdef __cplusplus +} +#endif + +#endif // NRF_QUEUE_H__ +/** @} */ diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/integration/nrfx/legacy/apply_old_config.h b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/integration/nrfx/legacy/apply_old_config.h deleted file mode 100644 index 62ef4755fa..0000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/integration/nrfx/legacy/apply_old_config.h +++ /dev/null @@ -1,1385 +0,0 @@ -/** - * Copyright (c) 2017 - 2018, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - - -#ifndef APPLY_OLD_CONFIG_H__ -#define APPLY_OLD_CONFIG_H__ - -//------------------------------------------------------------------------------ -// Peripheral Resource Sharing (PRS) - -#if defined(PERIPHERAL_RESOURCE_SHARING_ENABLED) - -#define NRFX_PRS_ENABLED PERIPHERAL_RESOURCE_SHARING_ENABLED -#define NRFX_PRS_BOX_0_ENABLED PERIPHERAL_RESOURCE_SHARING_ENABLED -#define NRFX_PRS_BOX_1_ENABLED PERIPHERAL_RESOURCE_SHARING_ENABLED -#define NRFX_PRS_BOX_2_ENABLED PERIPHERAL_RESOURCE_SHARING_ENABLED -#define NRFX_PRS_BOX_3_ENABLED PERIPHERAL_RESOURCE_SHARING_ENABLED -#define NRFX_PRS_BOX_4_ENABLED PERIPHERAL_RESOURCE_SHARING_ENABLED - -#if defined(COMMON_CONFIG_LOG_ENABLED) -#undef NRFX_PRS_CONFIG_LOG_ENABLED -#define NRFX_PRS_CONFIG_LOG_ENABLED COMMON_CONFIG_LOG_ENABLED -#endif -#if defined(COMMON_CONFIG_LOG_LEVEL) -#undef NRFX_PRS_CONFIG_LOG_LEVEL -#define NRFX_PRS_CONFIG_LOG_LEVEL COMMON_CONFIG_LOG_LEVEL -#endif -#if defined(COMMON_CONFIG_INFO_COLOR) -#undef NRFX_PRS_CONFIG_INFO_COLOR -#define NRFX_PRS_CONFIG_INFO_COLOR COMMON_CONFIG_INFO_COLOR -#endif -#if defined(COMMON_CONFIG_DEBUG_COLOR) -#undef NRFX_PRS_CONFIG_DEBUG_COLOR -#define NRFX_PRS_CONFIG_DEBUG_COLOR COMMON_CONFIG_DEBUG_COLOR -#endif - -#endif // defined(PERIPHERAL_RESOURCE_SHARING_ENABLED) - -//------------------------------------------------------------------------------ -// CLOCK - -#if defined(CLOCK_ENABLED) - -#undef NRFX_CLOCK_ENABLED -#define NRFX_CLOCK_ENABLED CLOCK_ENABLED - -#if defined(CLOCK_CONFIG_LF_SRC) -#undef NRFX_CLOCK_CONFIG_LF_SRC -#define NRFX_CLOCK_CONFIG_LF_SRC CLOCK_CONFIG_LF_SRC -#endif -#if defined(CLOCK_CONFIG_IRQ_PRIORITY) -#undef NRFX_CLOCK_CONFIG_IRQ_PRIORITY -#define NRFX_CLOCK_CONFIG_IRQ_PRIORITY CLOCK_CONFIG_IRQ_PRIORITY -#endif - -#if defined(CLOCK_CONFIG_LOG_ENABLED) -#undef NRFX_CLOCK_CONFIG_LOG_ENABLED -#define NRFX_CLOCK_CONFIG_LOG_ENABLED CLOCK_CONFIG_LOG_ENABLED -#endif -#if defined(CLOCK_CONFIG_LOG_LEVEL) -#undef NRFX_CLOCK_CONFIG_LOG_LEVEL -#define NRFX_CLOCK_CONFIG_LOG_LEVEL CLOCK_CONFIG_LOG_LEVEL -#endif -#if defined(CLOCK_CONFIG_INFO_COLOR) -#undef NRFX_CLOCK_CONFIG_INFO_COLOR -#define NRFX_CLOCK_CONFIG_INFO_COLOR CLOCK_CONFIG_INFO_COLOR -#endif -#if defined(CLOCK_CONFIG_DEBUG_COLOR) -#undef NRFX_CLOCK_CONFIG_DEBUG_COLOR -#define NRFX_CLOCK_CONFIG_DEBUG_COLOR CLOCK_CONFIG_DEBUG_COLOR -#endif - -#endif // defined(CLOCK_ENABLED) - -//------------------------------------------------------------------------------ -// COMP - -#if defined(COMP_ENABLED) - -#undef NRFX_COMP_ENABLED -#define NRFX_COMP_ENABLED COMP_ENABLED - -#if defined(COMP_CONFIG_REF) -#undef NRFX_COMP_CONFIG_REF -#define NRFX_COMP_CONFIG_REF COMP_CONFIG_REF -#endif -#if defined(COMP_CONFIG_MAIN_MODE) -#undef NRFX_COMP_CONFIG_MAIN_MODE -#define NRFX_COMP_CONFIG_MAIN_MODE COMP_CONFIG_MAIN_MODE -#endif -#if defined(COMP_CONFIG_SPEED_MODE) -#undef NRFX_COMP_CONFIG_SPEED_MODE -#define NRFX_COMP_CONFIG_SPEED_MODE COMP_CONFIG_SPEED_MODE -#endif -#if defined(COMP_CONFIG_HYST) -#undef NRFX_COMP_CONFIG_HYST -#define NRFX_COMP_CONFIG_HYST COMP_CONFIG_HYST -#endif -#if defined(COMP_CONFIG_ISOURCE) -#undef NRFX_COMP_CONFIG_ISOURCE -#define NRFX_COMP_CONFIG_ISOURCE COMP_CONFIG_ISOURCE -#endif -#if defined(COMP_CONFIG_INPUT) -#undef NRFX_COMP_CONFIG_INPUT -#define NRFX_COMP_CONFIG_INPUT COMP_CONFIG_INPUT -#endif -#if defined(COMP_CONFIG_IRQ_PRIORITY) -#undef NRFX_COMP_CONFIG_IRQ_PRIORITY -#define NRFX_COMP_CONFIG_IRQ_PRIORITY COMP_CONFIG_IRQ_PRIORITY -#endif - -#if defined(COMP_CONFIG_LOG_ENABLED) -#undef NRFX_COMP_CONFIG_LOG_ENABLED -#define NRFX_COMP_CONFIG_LOG_ENABLED COMP_CONFIG_LOG_ENABLED -#endif -#if defined(COMP_CONFIG_LOG_LEVEL) -#undef NRFX_COMP_CONFIG_LOG_LEVEL -#define NRFX_COMP_CONFIG_LOG_LEVEL COMP_CONFIG_LOG_LEVEL -#endif -#if defined(COMP_CONFIG_INFO_COLOR) -#undef NRFX_COMP_CONFIG_INFO_COLOR -#define NRFX_COMP_CONFIG_INFO_COLOR COMP_CONFIG_INFO_COLOR -#endif -#if defined(COMP_CONFIG_DEBUG_COLOR) -#undef NRFX_COMP_CONFIG_DEBUG_COLOR -#define NRFX_COMP_CONFIG_DEBUG_COLOR COMP_CONFIG_DEBUG_COLOR -#endif - -#endif // defined(COMP_ENABLED) - -//------------------------------------------------------------------------------ -// GPIOTE - -#if defined(GPIOTE_ENABLED) - -#undef NRFX_GPIOTE_ENABLED -#define NRFX_GPIOTE_ENABLED GPIOTE_ENABLED - -#if defined(GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS) -#undef NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS -#define NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS -#endif - -#if defined(GPIOTE_CONFIG_IRQ_PRIORITY) -#undef NRFX_GPIOTE_CONFIG_IRQ_PRIORITY -#define NRFX_GPIOTE_CONFIG_IRQ_PRIORITY GPIOTE_CONFIG_IRQ_PRIORITY -#endif - -#if defined(GPIOTE_CONFIG_LOG_ENABLED) -#undef NRFX_GPIOTE_CONFIG_LOG_ENABLED -#define NRFX_GPIOTE_CONFIG_LOG_ENABLED GPIOTE_CONFIG_LOG_ENABLED -#endif -#if defined(GPIOTE_CONFIG_LOG_LEVEL) -#undef NRFX_GPIOTE_CONFIG_LOG_LEVEL -#define NRFX_GPIOTE_CONFIG_LOG_LEVEL GPIOTE_CONFIG_LOG_LEVEL -#endif -#if defined(GPIOTE_CONFIG_INFO_COLOR) -#undef NRFX_GPIOTE_CONFIG_INFO_COLOR -#define NRFX_GPIOTE_CONFIG_INFO_COLOR GPIOTE_CONFIG_INFO_COLOR -#endif -#if defined(GPIOTE_CONFIG_DEBUG_COLOR) -#undef NRFX_GPIOTE_CONFIG_DEBUG_COLOR -#define NRFX_GPIOTE_CONFIG_DEBUG_COLOR GPIOTE_CONFIG_DEBUG_COLOR -#endif - -#endif // defined(GPIOTE_ENABLED) - -//------------------------------------------------------------------------------ -// I2S - -#if defined(I2S_ENABLED) - -#undef NRFX_I2S_ENABLED -#define NRFX_I2S_ENABLED I2S_ENABLED - -#if defined(I2S_CONFIG_SCK_PIN) -#undef NRFX_I2S_CONFIG_SCK_PIN -#define NRFX_I2S_CONFIG_SCK_PIN I2S_CONFIG_SCK_PIN -#endif -#if defined(I2S_CONFIG_LRCK_PIN) -#undef NRFX_I2S_CONFIG_LRCK_PIN -#define NRFX_I2S_CONFIG_LRCK_PIN I2S_CONFIG_LRCK_PIN -#endif -#if defined(I2S_CONFIG_MCK_PIN) -#undef NRFX_I2S_CONFIG_MCK_PIN -#define NRFX_I2S_CONFIG_MCK_PIN I2S_CONFIG_MCK_PIN -#endif -#if defined(I2S_CONFIG_SDOUT_PIN) -#undef NRFX_I2S_CONFIG_SDOUT_PIN -#define NRFX_I2S_CONFIG_SDOUT_PIN I2S_CONFIG_SDOUT_PIN -#endif -#if defined(I2S_CONFIG_SDIN_PIN) -#undef NRFX_I2S_CONFIG_SDIN_PIN -#define NRFX_I2S_CONFIG_SDIN_PIN I2S_CONFIG_SDIN_PIN -#endif - -#if defined(I2S_CONFIG_MASTER) -#undef NRFX_I2S_CONFIG_MASTER -#define NRFX_I2S_CONFIG_MASTER I2S_CONFIG_MASTER -#endif -#if defined(I2S_CONFIG_FORMAT) -#undef NRFX_I2S_CONFIG_FORMAT -#define NRFX_I2S_CONFIG_FORMAT I2S_CONFIG_FORMAT -#endif -#if defined(I2S_CONFIG_ALIGN) -#undef NRFX_I2S_CONFIG_ALIGN -#define NRFX_I2S_CONFIG_ALIGN I2S_CONFIG_ALIGN -#endif -#if defined(I2S_CONFIG_SWIDTH) -#undef NRFX_I2S_CONFIG_SWIDTH -#define NRFX_I2S_CONFIG_SWIDTH I2S_CONFIG_SWIDTH -#endif -#if defined(I2S_CONFIG_CHANNELS) -#undef NRFX_I2S_CONFIG_CHANNELS -#define NRFX_I2S_CONFIG_CHANNELS I2S_CONFIG_CHANNELS -#endif -#if defined(I2S_CONFIG_MCK_SETUP) -#undef NRFX_I2S_CONFIG_MCK_SETUP -#define NRFX_I2S_CONFIG_MCK_SETUP I2S_CONFIG_MCK_SETUP -#endif -#if defined(I2S_CONFIG_RATIO) -#undef NRFX_I2S_CONFIG_RATIO -#define NRFX_I2S_CONFIG_RATIO I2S_CONFIG_RATIO -#endif -#if defined(I2S_CONFIG_IRQ_PRIORITY) -#undef NRFX_I2S_CONFIG_IRQ_PRIORITY -#define NRFX_I2S_CONFIG_IRQ_PRIORITY I2S_CONFIG_IRQ_PRIORITY -#endif - -#if defined(I2S_CONFIG_LOG_ENABLED) -#undef NRFX_I2S_CONFIG_LOG_ENABLED -#define NRFX_I2S_CONFIG_LOG_ENABLED I2S_CONFIG_LOG_ENABLED -#endif -#if defined(I2S_CONFIG_LOG_LEVEL) -#undef NRFX_I2S_CONFIG_LOG_LEVEL -#define NRFX_I2S_CONFIG_LOG_LEVEL I2S_CONFIG_LOG_LEVEL -#endif -#if defined(I2S_CONFIG_INFO_COLOR) -#undef NRFX_I2S_CONFIG_INFO_COLOR -#define NRFX_I2S_CONFIG_INFO_COLOR I2S_CONFIG_INFO_COLOR -#endif -#if defined(I2S_CONFIG_DEBUG_COLOR) -#undef NRFX_I2S_CONFIG_DEBUG_COLOR -#define NRFX_I2S_CONFIG_DEBUG_COLOR I2S_CONFIG_DEBUG_COLOR -#endif - -#endif // defined(I2S_ENABLED) - -//------------------------------------------------------------------------------ -// LPCOMP - -#if defined(LPCOMP_ENABLED) - -#undef NRFX_LPCOMP_ENABLED -#define NRFX_LPCOMP_ENABLED LPCOMP_ENABLED - -#if defined(LPCOMP_CONFIG_REFERENCE) -#undef NRFX_LPCOMP_CONFIG_REFERENCE -#define NRFX_LPCOMP_CONFIG_REFERENCE LPCOMP_CONFIG_REFERENCE -#endif -#if defined(LPCOMP_CONFIG_DETECTION) -#undef NRFX_LPCOMP_CONFIG_DETECTION -#define NRFX_LPCOMP_CONFIG_DETECTION LPCOMP_CONFIG_DETECTION -#endif -#if defined(LPCOMP_CONFIG_INPUT) -#undef NRFX_LPCOMP_CONFIG_INPUT -#define NRFX_LPCOMP_CONFIG_INPUT LPCOMP_CONFIG_INPUT -#endif -#if defined(LPCOMP_CONFIG_HYST) -#undef NRFX_LPCOMP_CONFIG_HYST -#define NRFX_LPCOMP_CONFIG_HYST LPCOMP_CONFIG_HYST -#endif -#if defined(LPCOMP_CONFIG_IRQ_PRIORITY) -#undef NRFX_LPCOMP_CONFIG_IRQ_PRIORITY -#define NRFX_LPCOMP_CONFIG_IRQ_PRIORITY LPCOMP_CONFIG_IRQ_PRIORITY -#endif - -#if defined(LPCOMP_CONFIG_LOG_ENABLED) -#undef NRFX_LPCOMP_CONFIG_LOG_ENABLED -#define NRFX_LPCOMP_CONFIG_LOG_ENABLED LPCOMP_CONFIG_LOG_ENABLED -#endif -#if defined(LPCOMP_CONFIG_LOG_LEVEL) -#undef NRFX_LPCOMP_CONFIG_LOG_LEVEL -#define NRFX_LPCOMP_CONFIG_LOG_LEVEL LPCOMP_CONFIG_LOG_LEVEL -#endif -#if defined(LPCOMP_CONFIG_INFO_COLOR) -#undef NRFX_LPCOMP_CONFIG_INFO_COLOR -#define NRFX_LPCOMP_CONFIG_INFO_COLOR LPCOMP_CONFIG_INFO_COLOR -#endif -#if defined(LPCOMP_CONFIG_DEBUG_COLOR) -#undef NRFX_LPCOMP_CONFIG_DEBUG_COLOR -#define NRFX_LPCOMP_CONFIG_DEBUG_COLOR LPCOMP_CONFIG_DEBUG_COLOR -#endif - -#endif // defined(LPCOMP_ENABLED) - -//------------------------------------------------------------------------------ -// PDM - -#if defined(PDM_ENABLED) - -#undef NRFX_PDM_ENABLED -#define NRFX_PDM_ENABLED PDM_ENABLED - -#if defined(PDM_CONFIG_MODE) -#undef NRFX_PDM_CONFIG_MODE -#define NRFX_PDM_CONFIG_MODE PDM_CONFIG_MODE -#endif -#if defined(PDM_CONFIG_EDGE) -#undef NRFX_PDM_CONFIG_EDGE -#define NRFX_PDM_CONFIG_EDGE PDM_CONFIG_EDGE -#endif -#if defined(PDM_CONFIG_CLOCK_FREQ) -#undef NRFX_PDM_CONFIG_CLOCK_FREQ -#define NRFX_PDM_CONFIG_CLOCK_FREQ PDM_CONFIG_CLOCK_FREQ -#endif -#if defined(PDM_CONFIG_IRQ_PRIORITY) -#undef NRFX_PDM_CONFIG_IRQ_PRIORITY -#define NRFX_PDM_CONFIG_IRQ_PRIORITY PDM_CONFIG_IRQ_PRIORITY -#endif - -#if defined(PDM_CONFIG_LOG_ENABLED) -#undef NRFX_PDM_CONFIG_LOG_ENABLED -#define NRFX_PDM_CONFIG_LOG_ENABLED PDM_CONFIG_LOG_ENABLED -#endif -#if defined(PDM_CONFIG_LOG_LEVEL) -#undef NRFX_PDM_CONFIG_LOG_LEVEL -#define NRFX_PDM_CONFIG_LOG_LEVEL PDM_CONFIG_LOG_LEVEL -#endif -#if defined(PDM_CONFIG_INFO_COLOR) -#undef NRFX_PDM_CONFIG_INFO_COLOR -#define NRFX_PDM_CONFIG_INFO_COLOR PDM_CONFIG_INFO_COLOR -#endif -#if defined(PDM_CONFIG_DEBUG_COLOR) -#undef NRFX_PDM_CONFIG_DEBUG_COLOR -#define NRFX_PDM_CONFIG_DEBUG_COLOR PDM_CONFIG_DEBUG_COLOR -#endif - -#endif // defined(PDM_ENABLED) - -//------------------------------------------------------------------------------ -// POWER - -#if defined(POWER_ENABLED) - -#undef NRFX_POWER_ENABLED -#define NRFX_POWER_ENABLED POWER_ENABLED - -#if defined(POWER_CONFIG_IRQ_PRIORITY) -#undef NRFX_POWER_CONFIG_IRQ_PRIORITY -#define NRFX_POWER_CONFIG_IRQ_PRIORITY POWER_CONFIG_IRQ_PRIORITY -#endif - -#if defined(POWER_CONFIG_DEFAULT_DCDCEN) -#undef NRFX_POWER_CONFIG_DEFAULT_DCDCEN -#define NRFX_POWER_CONFIG_DEFAULT_DCDCEN POWER_CONFIG_DEFAULT_DCDCEN -#endif -#if defined(POWER_CONFIG_DEFAULT_DCDCENHV) -#undef NRFX_POWER_CONFIG_DEFAULT_DCDCENHV -#define NRFX_POWER_CONFIG_DEFAULT_DCDCENHV POWER_CONFIG_DEFAULT_DCDCENHV -#endif - -#endif // defined(POWER_ENABLED) - -//------------------------------------------------------------------------------ -// PPI - -#if defined(PPI_ENABLED) - -#undef NRFX_PPI_ENABLED -#define NRFX_PPI_ENABLED PPI_ENABLED - -#if defined(PPI_CONFIG_LOG_ENABLED) -#undef NRFX_PPI_CONFIG_LOG_ENABLED -#define NRFX_PPI_CONFIG_LOG_ENABLED PPI_CONFIG_LOG_ENABLED -#endif -#if defined(PPI_CONFIG_LOG_LEVEL) -#undef NRFX_PPI_CONFIG_LOG_LEVEL -#define NRFX_PPI_CONFIG_LOG_LEVEL PPI_CONFIG_LOG_LEVEL -#endif -#if defined(PPI_CONFIG_INFO_COLOR) -#undef NRFX_PPI_CONFIG_INFO_COLOR -#define NRFX_PPI_CONFIG_INFO_COLOR PPI_CONFIG_INFO_COLOR -#endif -#if defined(PPI_CONFIG_DEBUG_COLOR) -#undef NRFX_PPI_CONFIG_DEBUG_COLOR -#define NRFX_PPI_CONFIG_DEBUG_COLOR PPI_CONFIG_DEBUG_COLOR -#endif - -#endif // defined(PPI_ENABLED) - -//------------------------------------------------------------------------------ -// PWM - -#if defined(PWM_ENABLED) - -#undef NRFX_PWM_ENABLED -#define NRFX_PWM_ENABLED PWM_ENABLED - -#if defined(PWM0_ENABLED) -#undef NRFX_PWM0_ENABLED -#define NRFX_PWM0_ENABLED PWM0_ENABLED -#endif -#if defined(PWM1_ENABLED) -#undef NRFX_PWM1_ENABLED -#define NRFX_PWM1_ENABLED PWM1_ENABLED -#endif -#if defined(PWM2_ENABLED) -#undef NRFX_PWM2_ENABLED -#define NRFX_PWM2_ENABLED PWM2_ENABLED -#endif -#if defined(PWM3_ENABLED) -#undef NRFX_PWM3_ENABLED -#define NRFX_PWM3_ENABLED PWM3_ENABLED -#endif - -#if defined(PWM_DEFAULT_CONFIG_OUT0_PIN) -#undef NRFX_PWM_DEFAULT_CONFIG_OUT0_PIN -#define NRFX_PWM_DEFAULT_CONFIG_OUT0_PIN PWM_DEFAULT_CONFIG_OUT0_PIN -#endif -#if defined(PWM_DEFAULT_CONFIG_OUT1_PIN) -#undef NRFX_PWM_DEFAULT_CONFIG_OUT1_PIN -#define NRFX_PWM_DEFAULT_CONFIG_OUT1_PIN PWM_DEFAULT_CONFIG_OUT1_PIN -#endif -#if defined(PWM_DEFAULT_CONFIG_OUT2_PIN) -#undef NRFX_PWM_DEFAULT_CONFIG_OUT2_PIN -#define NRFX_PWM_DEFAULT_CONFIG_OUT2_PIN PWM_DEFAULT_CONFIG_OUT2_PIN -#endif -#if defined(PWM_DEFAULT_CONFIG_OUT3_PIN) -#undef NRFX_PWM_DEFAULT_CONFIG_OUT3_PIN -#define NRFX_PWM_DEFAULT_CONFIG_OUT3_PIN PWM_DEFAULT_CONFIG_OUT3_PIN -#endif -#if defined(PWM_DEFAULT_CONFIG_BASE_CLOCK) -#undef NRFX_PWM_DEFAULT_CONFIG_BASE_CLOCK -#define NRFX_PWM_DEFAULT_CONFIG_BASE_CLOCK PWM_DEFAULT_CONFIG_BASE_CLOCK -#endif -#if defined(PWM_DEFAULT_CONFIG_COUNT_MODE) -#undef NRFX_PWM_DEFAULT_CONFIG_COUNT_MODE -#define NRFX_PWM_DEFAULT_CONFIG_COUNT_MODE PWM_DEFAULT_CONFIG_COUNT_MODE -#endif -#if defined(PWM_DEFAULT_CONFIG_TOP_VALUE) -#undef NRFX_PWM_DEFAULT_CONFIG_TOP_VALUE -#define NRFX_PWM_DEFAULT_CONFIG_TOP_VALUE PWM_DEFAULT_CONFIG_TOP_VALUE -#endif -#if defined(PWM_DEFAULT_CONFIG_LOAD_MODE) -#undef NRFX_PWM_DEFAULT_CONFIG_LOAD_MODE -#define NRFX_PWM_DEFAULT_CONFIG_LOAD_MODE PWM_DEFAULT_CONFIG_LOAD_MODE -#endif -#if defined(PWM_DEFAULT_CONFIG_STEP_MODE) -#undef NRFX_PWM_DEFAULT_CONFIG_STEP_MODE -#define NRFX_PWM_DEFAULT_CONFIG_STEP_MODE PWM_DEFAULT_CONFIG_STEP_MODE -#endif -#if defined(PWM_DEFAULT_CONFIG_IRQ_PRIORITY) -#undef NRFX_PWM_DEFAULT_CONFIG_IRQ_PRIORITY -#define NRFX_PWM_DEFAULT_CONFIG_IRQ_PRIORITY PWM_DEFAULT_CONFIG_IRQ_PRIORITY -#endif - -#if defined(PWM_CONFIG_LOG_ENABLED) -#undef NRFX_PWM_CONFIG_LOG_ENABLED -#define NRFX_PWM_CONFIG_LOG_ENABLED PWM_CONFIG_LOG_ENABLED -#endif -#if defined(PWM_CONFIG_LOG_LEVEL) -#undef NRFX_PWM_CONFIG_LOG_LEVEL -#define NRFX_PWM_CONFIG_LOG_LEVEL PWM_CONFIG_LOG_LEVEL -#endif -#if defined(PWM_CONFIG_INFO_COLOR) -#undef NRFX_PWM_CONFIG_INFO_COLOR -#define NRFX_PWM_CONFIG_INFO_COLOR PWM_CONFIG_INFO_COLOR -#endif -#if defined(PWM_CONFIG_DEBUG_COLOR) -#undef NRFX_PWM_CONFIG_DEBUG_COLOR -#define NRFX_PWM_CONFIG_DEBUG_COLOR PWM_CONFIG_DEBUG_COLOR -#endif - -#if defined(PWM_NRF52_ANOMALY_109_WORKAROUND_ENABLED) -#undef NRFX_PWM_NRF52_ANOMALY_109_WORKAROUND_ENABLED -#define NRFX_PWM_NRF52_ANOMALY_109_WORKAROUND_ENABLED PWM_NRF52_ANOMALY_109_WORKAROUND_ENABLED -#endif -#if defined(PWM_NRF52_ANOMALY_109_EGU_INSTANCE) -#undef NRFX_PWM_NRF52_ANOMALY_109_EGU_INSTANCE -#define NRFX_PWM_NRF52_ANOMALY_109_EGU_INSTANCE PWM_NRF52_ANOMALY_109_EGU_INSTANCE -#endif - -#endif // defined(PWM_ENABLED) - -//------------------------------------------------------------------------------ -// QDEC - -#if defined(QDEC_ENABLED) - -#undef NRFX_QDEC_ENABLED -#define NRFX_QDEC_ENABLED QDEC_ENABLED - -#if defined(QDEC_CONFIG_REPORTPER) -#undef NRFX_QDEC_CONFIG_REPORTPER -#define NRFX_QDEC_CONFIG_REPORTPER QDEC_CONFIG_REPORTPER -#endif -#if defined(QDEC_CONFIG_SAMPLEPER) -#undef NRFX_QDEC_CONFIG_SAMPLEPER -#define NRFX_QDEC_CONFIG_SAMPLEPER QDEC_CONFIG_SAMPLEPER -#endif -#if defined(QDEC_CONFIG_PIO_A) -#undef NRFX_QDEC_CONFIG_PIO_A -#define NRFX_QDEC_CONFIG_PIO_A QDEC_CONFIG_PIO_A -#endif -#if defined(QDEC_CONFIG_PIO_B) -#undef NRFX_QDEC_CONFIG_PIO_B -#define NRFX_QDEC_CONFIG_PIO_B QDEC_CONFIG_PIO_B -#endif -#if defined(QDEC_CONFIG_PIO_LED) -#undef NRFX_QDEC_CONFIG_PIO_LED -#define NRFX_QDEC_CONFIG_PIO_LED QDEC_CONFIG_PIO_LED -#endif -#if defined(QDEC_CONFIG_LEDPRE) -#undef NRFX_QDEC_CONFIG_LEDPRE -#define NRFX_QDEC_CONFIG_LEDPRE QDEC_CONFIG_LEDPRE -#endif -#if defined(QDEC_CONFIG_LEDPOL) -#undef NRFX_QDEC_CONFIG_LEDPOL -#define NRFX_QDEC_CONFIG_LEDPOL QDEC_CONFIG_LEDPOL -#endif -#if defined(QDEC_CONFIG_DBFEN) -#undef NRFX_QDEC_CONFIG_DBFEN -#define NRFX_QDEC_CONFIG_DBFEN QDEC_CONFIG_DBFEN -#endif -#if defined(QDEC_CONFIG_SAMPLE_INTEN) -#undef NRFX_QDEC_CONFIG_SAMPLE_INTEN -#define NRFX_QDEC_CONFIG_SAMPLE_INTEN QDEC_CONFIG_SAMPLE_INTEN -#endif -#if defined(QDEC_CONFIG_IRQ_PRIORITY) -#undef NRFX_QDEC_CONFIG_IRQ_PRIORITY -#define NRFX_QDEC_CONFIG_IRQ_PRIORITY QDEC_CONFIG_IRQ_PRIORITY -#endif - -#if defined(QDEC_CONFIG_LOG_ENABLED) -#undef NRFX_QDEC_CONFIG_LOG_ENABLED -#define NRFX_QDEC_CONFIG_LOG_ENABLED QDEC_CONFIG_LOG_ENABLED -#endif -#if defined(QDEC_CONFIG_LOG_LEVEL) -#undef NRFX_QDEC_CONFIG_LOG_LEVEL -#define NRFX_QDEC_CONFIG_LOG_LEVEL QDEC_CONFIG_LOG_LEVEL -#endif -#if defined(QDEC_CONFIG_INFO_COLOR) -#undef NRFX_QDEC_CONFIG_INFO_COLOR -#define NRFX_QDEC_CONFIG_INFO_COLOR QDEC_CONFIG_INFO_COLOR -#endif -#if defined(QDEC_CONFIG_DEBUG_COLOR) -#undef NRFX_QDEC_CONFIG_DEBUG_COLOR -#define NRFX_QDEC_CONFIG_DEBUG_COLOR QDEC_CONFIG_DEBUG_COLOR -#endif - -#endif // defined(QDEC_ENABLED) - -//------------------------------------------------------------------------------ -// QSPI - -#if defined(QSPI_ENABLED) - -#undef NRFX_QSPI_ENABLED -#define NRFX_QSPI_ENABLED QSPI_ENABLED - -#if defined(QSPI_CONFIG_SCK_DELAY) -#undef NRFX_QSPI_CONFIG_SCK_DELAY -#define NRFX_QSPI_CONFIG_SCK_DELAY QSPI_CONFIG_SCK_DELAY -#endif -#if defined(QSPI_CONFIG_XIP_OFFSET) -#undef NRFX_QSPI_CONFIG_XIP_OFFSET -#define NRFX_QSPI_CONFIG_XIP_OFFSET QSPI_CONFIG_XIP_OFFSET -#endif -#if defined(QSPI_CONFIG_READOC) -#undef NRFX_QSPI_CONFIG_READOC -#define NRFX_QSPI_CONFIG_READOC QSPI_CONFIG_READOC -#endif -#if defined(QSPI_CONFIG_WRITEOC) -#undef NRFX_QSPI_CONFIG_WRITEOC -#define NRFX_QSPI_CONFIG_WRITEOC QSPI_CONFIG_WRITEOC -#endif -#if defined(QSPI_CONFIG_ADDRMODE) -#undef NRFX_QSPI_CONFIG_ADDRMODE -#define NRFX_QSPI_CONFIG_ADDRMODE QSPI_CONFIG_ADDRMODE -#endif -#if defined(QSPI_CONFIG_MODE) -#undef NRFX_QSPI_CONFIG_MODE -#define NRFX_QSPI_CONFIG_MODE QSPI_CONFIG_MODE -#endif -#if defined(QSPI_CONFIG_FREQUENCY) -#undef NRFX_QSPI_CONFIG_FREQUENCY -#define NRFX_QSPI_CONFIG_FREQUENCY QSPI_CONFIG_FREQUENCY -#endif -#if defined(QSPI_CONFIG_IRQ_PRIORITY) -#undef NRFX_QSPI_CONFIG_IRQ_PRIORITY -#define NRFX_QSPI_CONFIG_IRQ_PRIORITY QSPI_CONFIG_IRQ_PRIORITY -#endif - -#if defined(QSPI_PIN_SCK) -#undef NRFX_QSPI_PIN_SCK -#define NRFX_QSPI_PIN_SCK QSPI_PIN_SCK -#endif -#if defined(QSPI_PIN_CSN) -#undef NRFX_QSPI_PIN_CSN -#define NRFX_QSPI_PIN_CSN QSPI_PIN_CSN -#endif -#if defined(QSPI_PIN_IO0) -#undef NRFX_QSPI_PIN_IO0 -#define NRFX_QSPI_PIN_IO0 QSPI_PIN_IO0 -#endif -#if defined(QSPI_PIN_IO0) -#undef NRFX_QSPI_PIN_IO0 -#define NRFX_QSPI_PIN_IO0 QSPI_PIN_IO0 -#endif -#if defined(QSPI_PIN_IO1) -#undef NRFX_QSPI_PIN_IO1 -#define NRFX_QSPI_PIN_IO1 QSPI_PIN_IO1 -#endif -#if defined(QSPI_PIN_IO2) -#undef NRFX_QSPI_PIN_IO2 -#define NRFX_QSPI_PIN_IO2 QSPI_PIN_IO2 -#endif -#if defined(QSPI_PIN_IO3) -#undef NRFX_QSPI_PIN_IO3 -#define NRFX_QSPI_PIN_IO3 QSPI_PIN_IO3 -#endif - -#endif // defined(QSPI_ENABLED) - -//------------------------------------------------------------------------------ -// RNG - -#if defined(RNG_ENABLED) - -#undef NRFX_RNG_ENABLED -#define NRFX_RNG_ENABLED RNG_ENABLED - -#if defined(RNG_CONFIG_ERROR_CORRECTION) -#undef NRFX_RNG_CONFIG_ERROR_CORRECTION -#define NRFX_RNG_CONFIG_ERROR_CORRECTION RNG_CONFIG_ERROR_CORRECTION -#endif - -#if defined(RNG_CONFIG_IRQ_PRIORITY) -#undef NRFX_RNG_CONFIG_IRQ_PRIORITY -#define NRFX_RNG_CONFIG_IRQ_PRIORITY RNG_CONFIG_IRQ_PRIORITY -#endif - -#if defined(RNG_CONFIG_LOG_ENABLED) -#undef NRFX_RNG_CONFIG_LOG_ENABLED -#define NRFX_RNG_CONFIG_LOG_ENABLED RNG_CONFIG_LOG_ENABLED -#endif -#if defined(RNG_CONFIG_LOG_LEVEL) -#undef NRFX_RNG_CONFIG_LOG_LEVEL -#define NRFX_RNG_CONFIG_LOG_LEVEL RNG_CONFIG_LOG_LEVEL -#endif -#if defined(RNG_CONFIG_INFO_COLOR) -#undef NRFX_RNG_CONFIG_INFO_COLOR -#define NRFX_RNG_CONFIG_INFO_COLOR RNG_CONFIG_INFO_COLOR -#endif -#if defined(RNG_CONFIG_DEBUG_COLOR) -#undef NRFX_RNG_CONFIG_DEBUG_COLOR -#define NRFX_RNG_CONFIG_DEBUG_COLOR RNG_CONFIG_DEBUG_COLOR -#endif - -#endif // defined(RNG_ENABLED) - -//------------------------------------------------------------------------------ -// RTC - -#if defined(RTC_ENABLED) - -#undef NRFX_RTC_ENABLED -#define NRFX_RTC_ENABLED RTC_ENABLED - -#if defined(RTC0_ENABLED) -#undef NRFX_RTC0_ENABLED -#define NRFX_RTC0_ENABLED RTC0_ENABLED -#endif -#if defined(RTC1_ENABLED) -#undef NRFX_RTC1_ENABLED -#define NRFX_RTC1_ENABLED RTC1_ENABLED -#endif -#if defined(RTC2_ENABLED) -#undef NRFX_RTC2_ENABLED -#define NRFX_RTC2_ENABLED RTC2_ENABLED -#endif - -#if defined(RTC_DEFAULT_CONFIG_FREQUENCY) -#undef NRFX_RTC_DEFAULT_CONFIG_FREQUENCY -#define NRFX_RTC_DEFAULT_CONFIG_FREQUENCY RTC_DEFAULT_CONFIG_FREQUENCY -#endif -#if defined(RTC_DEFAULT_CONFIG_RELIABLE) -#undef NRFX_RTC_DEFAULT_CONFIG_RELIABLE -#define NRFX_RTC_DEFAULT_CONFIG_RELIABLE RTC_DEFAULT_CONFIG_RELIABLE -#endif -#if defined(RTC_DEFAULT_CONFIG_IRQ_PRIORITY) -#undef NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY -#define NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY RTC_DEFAULT_CONFIG_IRQ_PRIORITY -#endif - -#if defined(NRF_MAXIMUM_LATENCY_US) -#undef NRFX_RTC_MAXIMUM_LATENCY_US -#define NRFX_RTC_MAXIMUM_LATENCY_US NRF_MAXIMUM_LATENCY_US -#endif - -#if defined(RTC_CONFIG_LOG_ENABLED) -#undef NRFX_RTC_CONFIG_LOG_ENABLED -#define NRFX_RTC_CONFIG_LOG_ENABLED RTC_CONFIG_LOG_ENABLED -#endif -#if defined(RTC_CONFIG_LOG_LEVEL) -#undef NRFX_RTC_CONFIG_LOG_LEVEL -#define NRFX_RTC_CONFIG_LOG_LEVEL RTC_CONFIG_LOG_LEVEL -#endif -#if defined(RTC_CONFIG_INFO_COLOR) -#undef NRFX_RTC_CONFIG_INFO_COLOR -#define NRFX_RTC_CONFIG_INFO_COLOR RTC_CONFIG_INFO_COLOR -#endif -#if defined(RTC_CONFIG_DEBUG_COLOR) -#undef NRFX_RTC_CONFIG_DEBUG_COLOR -#define NRFX_RTC_CONFIG_DEBUG_COLOR RTC_CONFIG_DEBUG_COLOR -#endif - -#endif // defined(RTC_ENABLED) - -//------------------------------------------------------------------------------ -// SAADC - -#if defined(SAADC_ENABLED) - -#undef NRFX_SAADC_ENABLED -#define NRFX_SAADC_ENABLED SAADC_ENABLED - -#if defined(SAADC_CONFIG_RESOLUTION) -#undef NRFX_SAADC_CONFIG_RESOLUTION -#define NRFX_SAADC_CONFIG_RESOLUTION SAADC_CONFIG_RESOLUTION -#endif -#if defined(SAADC_CONFIG_OVERSAMPLE) -#undef NRFX_SAADC_CONFIG_OVERSAMPLE -#define NRFX_SAADC_CONFIG_OVERSAMPLE SAADC_CONFIG_OVERSAMPLE -#endif -#if defined(SAADC_CONFIG_LP_MODE) -#undef NRFX_SAADC_CONFIG_LP_MODE -#define NRFX_SAADC_CONFIG_LP_MODE SAADC_CONFIG_LP_MODE -#endif -#if defined(SAADC_CONFIG_IRQ_PRIORITY) -#undef NRFX_SAADC_CONFIG_IRQ_PRIORITY -#define NRFX_SAADC_CONFIG_IRQ_PRIORITY SAADC_CONFIG_IRQ_PRIORITY -#endif - -#if defined(SAADC_CONFIG_LOG_ENABLED) -#undef NRFX_SAADC_CONFIG_LOG_ENABLED -#define NRFX_SAADC_CONFIG_LOG_ENABLED SAADC_CONFIG_LOG_ENABLED -#endif -#if defined(SAADC_CONFIG_LOG_LEVEL) -#undef NRFX_SAADC_CONFIG_LOG_LEVEL -#define NRFX_SAADC_CONFIG_LOG_LEVEL SAADC_CONFIG_LOG_LEVEL -#endif -#if defined(SAADC_CONFIG_INFO_COLOR) -#undef NRFX_SAADC_CONFIG_INFO_COLOR -#define NRFX_SAADC_CONFIG_INFO_COLOR SAADC_CONFIG_INFO_COLOR -#endif -#if defined(SAADC_CONFIG_DEBUG_COLOR) -#undef NRFX_SAADC_CONFIG_DEBUG_COLOR -#define NRFX_SAADC_CONFIG_DEBUG_COLOR SAADC_CONFIG_DEBUG_COLOR -#endif - -#endif // defined(SAADC_ENABLED) - -//------------------------------------------------------------------------------ -// SPI - -#if defined(SPI_ENABLED) - -#undef NRFX_SPI_ENABLED -#define NRFX_SPI_ENABLED \ - (SPI_ENABLED && (NRFX_SPI0_ENABLED || NRFX_SPI1_ENABLED || NRFX_SPI2_ENABLED)) -#undef NRFX_SPIM_ENABLED -#define NRFX_SPIM_ENABLED \ - (SPI_ENABLED && (NRFX_SPIM0_ENABLED || NRFX_SPIM1_ENABLED || NRFX_SPIM2_ENABLED)) - -#if defined(SPI_PRESENT) && !defined(SPIM_PRESENT) - -#undef NRFX_SPI0_ENABLED -#define NRFX_SPI0_ENABLED SPI0_ENABLED -#undef NRFX_SPIM0_ENABLED -#define NRFX_SPIM0_ENABLED 0 - -#undef NRFX_SPI1_ENABLED -#define NRFX_SPI1_ENABLED SPI1_ENABLED -#undef NRFX_SPIM1_ENABLED -#define NRFX_SPIM1_ENABLED 0 - -#undef NRFX_SPI2_ENABLED -#define NRFX_SPI2_ENABLED SPI2_ENABLED -#undef NRFX_SPIM2_ENABLED -#define NRFX_SPIM2_ENABLED 0 - -#elif !defined(SPI_PRESENT) && defined(SPIM_PRESENT) - -#undef NRFX_SPI0_ENABLED -#define NRFX_SPI0_ENABLED 0 -#undef NRFX_SPIM0_ENABLED -#define NRFX_SPIM0_ENABLED SPI0_ENABLED - -#undef NRFX_SPI1_ENABLED -#define NRFX_SPI1_ENABLED 0 -#undef NRFX_SPIM1_ENABLED -#define NRFX_SPIM1_ENABLED SPI1_ENABLED - -#undef NRFX_SPI2_ENABLED -#define NRFX_SPI2_ENABLED 0 -#undef NRFX_SPIM2_ENABLED -#define NRFX_SPIM2_ENABLED SPI2_ENABLED - -#else // -> defined(SPI_PRESENT) && defined(SPIM_PRESENT) - -#undef NRFX_SPI0_ENABLED -#define NRFX_SPI0_ENABLED (SPI0_ENABLED && !SPI0_USE_EASY_DMA) -#undef NRFX_SPIM0_ENABLED -#define NRFX_SPIM0_ENABLED (SPI0_ENABLED && SPI0_USE_EASY_DMA) - -#undef NRFX_SPI1_ENABLED -#define NRFX_SPI1_ENABLED (SPI1_ENABLED && !SPI1_USE_EASY_DMA) -#undef NRFX_SPIM1_ENABLED -#define NRFX_SPIM1_ENABLED (SPI1_ENABLED && SPI1_USE_EASY_DMA) - -#undef NRFX_SPI2_ENABLED -#define NRFX_SPI2_ENABLED (SPI2_ENABLED && !SPI2_USE_EASY_DMA) -#undef NRFX_SPIM2_ENABLED -#define NRFX_SPIM2_ENABLED (SPI2_ENABLED && SPI2_USE_EASY_DMA) - -#endif // -> defined(SPI_PRESENT) && defined(SPIM_PRESENT) - -#if defined(NRF_SPI_DRV_MISO_PULLUP_CFG) -#undef NRFX_SPI_MISO_PULL_CFG -#define NRFX_SPI_MISO_PULL_CFG NRF_SPI_DRV_MISO_PULLUP_CFG -#undef NRFX_SPIM_MISO_PULL_CFG -#define NRFX_SPIM_MISO_PULL_CFG NRF_SPI_DRV_MISO_PULLUP_CFG -#endif - -#if defined(SPI_DEFAULT_CONFIG_IRQ_PRIORITY) -#undef NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY -#define NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY SPI_DEFAULT_CONFIG_IRQ_PRIORITY -#undef NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY -#define NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY SPI_DEFAULT_CONFIG_IRQ_PRIORITY -#endif - -#if defined(SPI_CONFIG_LOG_ENABLED) -#undef NRFX_SPI_CONFIG_LOG_ENABLED -#define NRFX_SPI_CONFIG_LOG_ENABLED SPI_CONFIG_LOG_ENABLED -#undef NRFX_SPIM_CONFIG_LOG_ENABLED -#define NRFX_SPIM_CONFIG_LOG_ENABLED SPI_CONFIG_LOG_ENABLED -#endif -#if defined(SPI_CONFIG_LOG_LEVEL) -#undef NRFX_SPI_CONFIG_LOG_LEVEL -#define NRFX_SPI_CONFIG_LOG_LEVEL SPI_CONFIG_LOG_LEVEL -#undef NRFX_SPIM_CONFIG_LOG_LEVEL -#define NRFX_SPIM_CONFIG_LOG_LEVEL SPI_CONFIG_LOG_LEVEL -#endif -#if defined(SPI_CONFIG_INFO_COLOR) -#undef NRFX_SPI_CONFIG_INFO_COLOR -#define NRFX_SPI_CONFIG_INFO_COLOR SPI_CONFIG_INFO_COLOR -#undef NRFX_SPIM_CONFIG_INFO_COLOR -#define NRFX_SPIM_CONFIG_INFO_COLOR SPI_CONFIG_INFO_COLOR -#endif -#if defined(SPI_CONFIG_DEBUG_COLOR) -#undef NRFX_SPI_CONFIG_DEBUG_COLOR -#define NRFX_SPI_CONFIG_DEBUG_COLOR SPI_CONFIG_DEBUG_COLOR -#undef NRFX_SPIM_CONFIG_DEBUG_COLOR -#define NRFX_SPIM_CONFIG_DEBUG_COLOR SPI_CONFIG_DEBUG_COLOR -#endif - -#if defined(SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED) -#undef NRFX_SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED -#define NRFX_SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED -#endif - -#endif // defined(SPI_ENABLED) - -//------------------------------------------------------------------------------ -// SPIS - -#if defined(SPIS_ENABLED) - -#undef NRFX_SPIS_ENABLED -#define NRFX_SPIS_ENABLED SPIS_ENABLED - -#if defined(SPIS0_ENABLED) -#undef NRFX_SPIS0_ENABLED -#define NRFX_SPIS0_ENABLED SPIS0_ENABLED -#endif -#if defined(SPIS1_ENABLED) -#undef NRFX_SPIS1_ENABLED -#define NRFX_SPIS1_ENABLED SPIS1_ENABLED -#endif -#if defined(SPIS2_ENABLED) -#undef NRFX_SPIS2_ENABLED -#define NRFX_SPIS2_ENABLED SPIS2_ENABLED -#endif - -#if defined(SPIS_DEFAULT_CONFIG_IRQ_PRIORITY) -#undef NRFX_SPIS_DEFAULT_CONFIG_IRQ_PRIORITY -#define NRFX_SPIS_DEFAULT_CONFIG_IRQ_PRIORITY SPIS_DEFAULT_CONFIG_IRQ_PRIORITY -#endif -#if defined(SPIS_DEFAULT_MODE) -#undef NRFX_SPIS_DEFAULT_MODE -#define NRFX_SPIS_DEFAULT_MODE SPIS_DEFAULT_MODE -#endif -#if defined(SPIS_DEFAULT_BIT_ORDER) -#undef NRFX_SPIS_DEFAULT_BIT_ORDER -#define NRFX_SPIS_DEFAULT_BIT_ORDER SPIS_DEFAULT_BIT_ORDER -#endif -#if defined(SPIS_DEFAULT_DEF) -#undef NRFX_SPIS_DEFAULT_DEF -#define NRFX_SPIS_DEFAULT_DEF SPIS_DEFAULT_DEF -#endif -#if defined(SPIS_DEFAULT_ORC) -#undef NRFX_SPIS_DEFAULT_ORC -#define NRFX_SPIS_DEFAULT_ORC SPIS_DEFAULT_ORC -#endif - -#if defined(SPIS_CONFIG_LOG_ENABLED) -#undef NRFX_SPIS_CONFIG_LOG_ENABLED -#define NRFX_SPIS_CONFIG_LOG_ENABLED SPIS_CONFIG_LOG_ENABLED -#endif -#if defined(SPIS_CONFIG_LOG_LEVEL) -#undef NRFX_SPIS_CONFIG_LOG_LEVEL -#define NRFX_SPIS_CONFIG_LOG_LEVEL SPIS_CONFIG_LOG_LEVEL -#endif -#if defined(SPIS_CONFIG_INFO_COLOR) -#undef NRFX_SPIS_CONFIG_INFO_COLOR -#define NRFX_SPIS_CONFIG_INFO_COLOR SPIS_CONFIG_INFO_COLOR -#endif -#if defined(SPIS_CONFIG_DEBUG_COLOR) -#undef NRFX_SPIS_CONFIG_DEBUG_COLOR -#define NRFX_SPIS_CONFIG_DEBUG_COLOR SPIS_CONFIG_DEBUG_COLOR -#endif - -#if defined(SPIS_NRF52_ANOMALY_109_WORKAROUND_ENABLED) -#undef NRFX_SPIS_NRF52_ANOMALY_109_WORKAROUND_ENABLED -#define NRFX_SPIS_NRF52_ANOMALY_109_WORKAROUND_ENABLED SPIS_NRF52_ANOMALY_109_WORKAROUND_ENABLED -#endif - -#endif // defined(SPIS_ENABLED) - -//------------------------------------------------------------------------------ -// SWI - -#if defined(SWI_DISABLE0) -#undef NRFX_SWI0_DISABLED -#define NRFX_SWI0_DISABLED 1 -#endif -#if defined(SWI_DISABLE1) -#undef NRFX_SWI1_DISABLED -#define NRFX_SWI1_DISABLED 1 -#endif -#if defined(SWI_DISABLE2) -#undef NRFX_SWI2_DISABLED -#define NRFX_SWI2_DISABLED 1 -#endif -#if defined(SWI_DISABLE3) -#undef NRFX_SWI3_DISABLED -#define NRFX_SWI3_DISABLED 1 -#endif -#if defined(SWI_DISABLE4) -#undef NRFX_SWI4_DISABLED -#define NRFX_SWI4_DISABLED 1 -#endif -#if defined(SWI_DISABLE5) -#undef NRFX_SWI5_DISABLED -#define NRFX_SWI5_DISABLED 1 -#endif - -#if defined(EGU_ENABLED) -#undef NRFX_EGU_ENABLED -#define NRFX_EGU_ENABLED EGU_ENABLED -#endif - -#if defined(SWI_CONFIG_LOG_ENABLED) -#undef NRFX_SWI_CONFIG_LOG_ENABLED -#define NRFX_SWI_CONFIG_LOG_ENABLED SWI_CONFIG_LOG_ENABLED -#endif -#if defined(SWI_CONFIG_LOG_LEVEL) -#undef NRFX_SWI_CONFIG_LOG_LEVEL -#define NRFX_SWI_CONFIG_LOG_LEVEL SWI_CONFIG_LOG_LEVEL -#endif -#if defined(SWI_CONFIG_INFO_COLOR) -#undef NRFX_SWI_CONFIG_INFO_COLOR -#define NRFX_SWI_CONFIG_INFO_COLOR SWI_CONFIG_INFO_COLOR -#endif -#if defined(SWI_CONFIG_DEBUG_COLOR) -#undef NRFX_SWI_CONFIG_DEBUG_COLOR -#define NRFX_SWI_CONFIG_DEBUG_COLOR SWI_CONFIG_DEBUG_COLOR -#endif - -//------------------------------------------------------------------------------ -// SysTick - -#if defined(SYSTICK_ENABLED) - -#undef NRFX_SYSTICK_ENABLED -#define NRFX_SYSTICK_ENABLED SYSTICK_ENABLED - -#endif // defined(SYSTICK_ENABLED) - -//------------------------------------------------------------------------------ -// TIMER - -#if defined(TIMER_ENABLED) - -#undef NRFX_TIMER_ENABLED -#define NRFX_TIMER_ENABLED TIMER_ENABLED - -#if defined(TIMER0_ENABLED) -#undef NRFX_TIMER0_ENABLED -#define NRFX_TIMER0_ENABLED TIMER0_ENABLED -#endif -#if defined(TIMER1_ENABLED) -#undef NRFX_TIMER1_ENABLED -#define NRFX_TIMER1_ENABLED TIMER1_ENABLED -#endif -#if defined(TIMER2_ENABLED) -#undef NRFX_TIMER2_ENABLED -#define NRFX_TIMER2_ENABLED TIMER2_ENABLED -#endif -#if defined(TIMER3_ENABLED) -#undef NRFX_TIMER3_ENABLED -#define NRFX_TIMER3_ENABLED TIMER3_ENABLED -#endif -#if defined(TIMER4_ENABLED) -#undef NRFX_TIMER4_ENABLED -#define NRFX_TIMER4_ENABLED TIMER4_ENABLED -#endif - -#if defined(TIMER_DEFAULT_CONFIG_FREQUENCY) -#undef NRFX_TIMER_DEFAULT_CONFIG_FREQUENCY -#define NRFX_TIMER_DEFAULT_CONFIG_FREQUENCY TIMER_DEFAULT_CONFIG_FREQUENCY -#endif -#if defined(TIMER_DEFAULT_CONFIG_MODE) -#undef NRFX_TIMER_DEFAULT_CONFIG_MODE -#define NRFX_TIMER_DEFAULT_CONFIG_MODE TIMER_DEFAULT_CONFIG_MODE -#endif -#if defined(TIMER_DEFAULT_CONFIG_BIT_WIDTH) -#undef NRFX_TIMER_DEFAULT_CONFIG_BIT_WIDTH -#define NRFX_TIMER_DEFAULT_CONFIG_BIT_WIDTH TIMER_DEFAULT_CONFIG_BIT_WIDTH -#endif -#if defined(TIMER_DEFAULT_CONFIG_IRQ_PRIORITY) -#undef NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY -#define NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY TIMER_DEFAULT_CONFIG_IRQ_PRIORITY -#endif - -#if defined(TIMER_CONFIG_LOG_ENABLED) -#undef NRFX_TIMER_CONFIG_LOG_ENABLED -#define NRFX_TIMER_CONFIG_LOG_ENABLED TIMER_CONFIG_LOG_ENABLED -#endif -#if defined(TIMER_CONFIG_LOG_LEVEL) -#undef NRFX_TIMER_CONFIG_LOG_LEVEL -#define NRFX_TIMER_CONFIG_LOG_LEVEL TIMER_CONFIG_LOG_LEVEL -#endif -#if defined(TIMER_CONFIG_INFO_COLOR) -#undef NRFX_TIMER_CONFIG_INFO_COLOR -#define NRFX_TIMER_CONFIG_INFO_COLOR TIMER_CONFIG_INFO_COLOR -#endif -#if defined(TIMER_CONFIG_DEBUG_COLOR) -#undef NRFX_TIMER_CONFIG_DEBUG_COLOR -#define NRFX_TIMER_CONFIG_DEBUG_COLOR TIMER_CONFIG_DEBUG_COLOR -#endif - -#endif // defined(TIMER_ENABLED) - -//------------------------------------------------------------------------------ -// TWI -#define TWI_ONLY ( defined(TWI_PRESENT) && !defined(TWIM_PRESENT)) -#define TWIM_ONLY (!defined(TWI_PRESENT) && defined(TWIM_PRESENT)) -#define TWI_AND_TWIM ( defined(TWI_PRESENT) && defined(TWIM_PRESENT)) - -#if defined(TWI_ENABLED) - -#undef NRFX_TWI_ENABLED -#define NRFX_TWI_ENABLED (TWI_ENABLED && (NRFX_TWI0_ENABLED || NRFX_TWI1_ENABLED)) -#undef NRFX_TWIM_ENABLED -#define NRFX_TWIM_ENABLED (TWI_ENABLED && (NRFX_TWIM0_ENABLED || NRFX_TWIM1_ENABLED)) - -#if defined(TWI_PRESENT) && !defined(TWIM_PRESENT) - -#undef NRFX_TWI0_ENABLED -#define NRFX_TWI0_ENABLED TWI0_ENABLED -#undef NRFX_TWIM0_ENABLED -#define NRFX_TWIM0_ENABLED 0 - -#undef NRFX_TWI1_ENABLED -#define NRFX_TWI1_ENABLED TWI1_ENABLED -#undef NRFX_TWIM1_ENABLED -#define NRFX_TWIM1_ENABLED 0 - -#elif !defined(TWI_PRESENT) && defined(TWIM_PRESENT) - -#undef NRFX_TWI0_ENABLED -#define NRFX_TWI0_ENABLED 0 -#undef NRFX_TWIM0_ENABLED -#define NRFX_TWIM0_ENABLED TWI0_ENABLED - -#undef NRFX_TWI1_ENABLED -#define NRFX_TWI1_ENABLED 0 -#undef NRFX_TWIM1_ENABLED -#define NRFX_TWIM1_ENABLED TWI1_ENABLED - -#else // -> defined(TWI_PRESENT) && defined(TWIM_PRESENT) - -#undef NRFX_TWI0_ENABLED -#define NRFX_TWI0_ENABLED (TWI0_ENABLED && !TWI0_USE_EASY_DMA) -#undef NRFX_TWIM0_ENABLED -#define NRFX_TWIM0_ENABLED (TWI0_ENABLED && TWI0_USE_EASY_DMA) - -#undef NRFX_TWI1_ENABLED -#define NRFX_TWI1_ENABLED (TWI1_ENABLED && !TWI1_USE_EASY_DMA) -#undef NRFX_TWIM1_ENABLED -#define NRFX_TWIM1_ENABLED (TWI1_ENABLED && TWI1_USE_EASY_DMA) - -#endif // -> defined(TWI_PRESENT) && defined(TWIM_PRESENT) - -#if defined(TWI_DEFAULT_CONFIG_FREQUENCY) -#undef NRFX_TWI_DEFAULT_CONFIG_FREQUENCY -#define NRFX_TWI_DEFAULT_CONFIG_FREQUENCY TWI_DEFAULT_CONFIG_FREQUENCY -#undef NRFX_TWIM_DEFAULT_CONFIG_FREQUENCY -#define NRFX_TWIM_DEFAULT_CONFIG_FREQUENCY TWI_DEFAULT_CONFIG_FREQUENCY -#endif -#if defined(TWI_DEFAULT_CONFIG_HOLD_BUS_UNINIT) -#undef NRFX_TWI_DEFAULT_CONFIG_HOLD_BUS_UNINIT -#define NRFX_TWI_DEFAULT_CONFIG_HOLD_BUS_UNINIT TWI_DEFAULT_CONFIG_HOLD_BUS_UNINIT -#undef NRFX_TWIM_DEFAULT_CONFIG_HOLD_BUS_UNINIT -#define NRFX_TWIM_DEFAULT_CONFIG_HOLD_BUS_UNINIT TWI_DEFAULT_CONFIG_HOLD_BUS_UNINIT -#endif -#if defined(TWI_DEFAULT_CONFIG_IRQ_PRIORITY) -#undef NRFX_TWI_DEFAULT_CONFIG_IRQ_PRIORITY -#define NRFX_TWI_DEFAULT_CONFIG_IRQ_PRIORITY TWI_DEFAULT_CONFIG_IRQ_PRIORITY -#undef NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY -#define NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY TWI_DEFAULT_CONFIG_IRQ_PRIORITY -#endif - -#if defined(TWI_CONFIG_LOG_ENABLED) -#undef NRFX_TWI_CONFIG_LOG_ENABLED -#define NRFX_TWI_CONFIG_LOG_ENABLED TWI_CONFIG_LOG_ENABLED -#undef NRFX_TWIM_CONFIG_LOG_ENABLED -#define NRFX_TWIM_CONFIG_LOG_ENABLED TWI_CONFIG_LOG_ENABLED -#endif -#if defined(TWI_CONFIG_LOG_LEVEL) -#undef NRFX_TWI_CONFIG_LOG_LEVEL -#define NRFX_TWI_CONFIG_LOG_LEVEL TWI_CONFIG_LOG_LEVEL -#undef NRFX_TWIM_CONFIG_LOG_LEVEL -#define NRFX_TWIM_CONFIG_LOG_LEVEL TWI_CONFIG_LOG_LEVEL -#endif -#if defined(TWI_CONFIG_INFO_COLOR) -#undef NRFX_TWI_CONFIG_INFO_COLOR -#define NRFX_TWI_CONFIG_INFO_COLOR TWI_CONFIG_INFO_COLOR -#undef NRFX_TWIM_CONFIG_INFO_COLOR -#define NRFX_TWIM_CONFIG_INFO_COLOR TWI_CONFIG_INFO_COLOR -#endif -#if defined(TWI_CONFIG_DEBUG_COLOR) -#undef NRFX_TWI_CONFIG_DEBUG_COLOR -#define NRFX_TWI_CONFIG_DEBUG_COLOR TWI_CONFIG_DEBUG_COLOR -#undef NRFX_TWIM_CONFIG_DEBUG_COLOR -#define NRFX_TWIM_CONFIG_DEBUG_COLOR TWI_CONFIG_DEBUG_COLOR -#endif - -#if defined(TWIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED) -#undef NRFX_TWIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED -#define NRFX_TWIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED TWIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED -#endif - -#endif // defined(TWI_ENABLED) - -//------------------------------------------------------------------------------ -// TWIS - -#if defined(TWIS_ENABLED) - -#undef NRFX_TWIS_ENABLED -#define NRFX_TWIS_ENABLED TWIS_ENABLED - -#if defined(TWIS0_ENABLED) -#undef NRFX_TWIS0_ENABLED -#define NRFX_TWIS0_ENABLED TWIS0_ENABLED -#endif -#if defined(TWIS1_ENABLED) -#undef NRFX_TWIS1_ENABLED -#define NRFX_TWIS1_ENABLED TWIS1_ENABLED -#endif - -#if defined(TWIS_ASSUME_INIT_AFTER_RESET_ONLY) -#undef NRFX_TWIS_ASSUME_INIT_AFTER_RESET_ONLY -#define NRFX_TWIS_ASSUME_INIT_AFTER_RESET_ONLY TWIS_ASSUME_INIT_AFTER_RESET_ONLY -#endif -#if defined(TWIS_NO_SYNC_MODE) -#undef NRFX_TWIS_NO_SYNC_MODE -#define NRFX_TWIS_NO_SYNC_MODE TWIS_NO_SYNC_MODE -#endif - -#if defined(TWIS_DEFAULT_CONFIG_ADDR0) -#undef NRFX_TWIS_DEFAULT_CONFIG_ADDR0 -#define NRFX_TWIS_DEFAULT_CONFIG_ADDR0 TWIS_DEFAULT_CONFIG_ADDR0 -#endif -#if defined(TWIS_DEFAULT_CONFIG_ADDR1) -#undef NRFX_TWIS_DEFAULT_CONFIG_ADDR1 -#define NRFX_TWIS_DEFAULT_CONFIG_ADDR1 TWIS_DEFAULT_CONFIG_ADDR1 -#endif -#if defined(TWIS_DEFAULT_CONFIG_SCL_PULL) -#undef NRFX_TWIS_DEFAULT_CONFIG_SCL_PULL -#define NRFX_TWIS_DEFAULT_CONFIG_SCL_PULL TWIS_DEFAULT_CONFIG_SCL_PULL -#endif -#if defined(TWIS_DEFAULT_CONFIG_SDA_PULL) -#undef NRFX_TWIS_DEFAULT_CONFIG_SDA_PULL -#define NRFX_TWIS_DEFAULT_CONFIG_SDA_PULL TWIS_DEFAULT_CONFIG_SDA_PULL -#endif -#if defined(TWIS_DEFAULT_CONFIG_IRQ_PRIORITY) -#undef NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY -#define NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY TWIS_DEFAULT_CONFIG_IRQ_PRIORITY -#endif - -#if defined(TWIS_CONFIG_LOG_ENABLED) -#undef NRFX_TWIS_CONFIG_LOG_ENABLED -#define NRFX_TWIS_CONFIG_LOG_ENABLED TWIS_CONFIG_LOG_ENABLED -#endif -#if defined(TWIS_CONFIG_LOG_LEVEL) -#undef NRFX_TWIS_CONFIG_LOG_LEVEL -#define NRFX_TWIS_CONFIG_LOG_LEVEL TWIS_CONFIG_LOG_LEVEL -#endif -#if defined(TWIS_CONFIG_INFO_COLOR) -#undef NRFX_TWIS_CONFIG_INFO_COLOR -#define NRFX_TWIS_CONFIG_INFO_COLOR TWIS_CONFIG_INFO_COLOR -#endif -#if defined(TWIS_CONFIG_DEBUG_COLOR) -#undef NRFX_TWIS_CONFIG_DEBUG_COLOR -#define NRFX_TWIS_CONFIG_DEBUG_COLOR TWIS_CONFIG_DEBUG_COLOR -#endif - -#endif // defined(TWIS_ENABLED) - -//------------------------------------------------------------------------------ -// UART - -#if defined(UART_ENABLED) - -#undef NRFX_UART_ENABLED -#define NRFX_UART_ENABLED (UART_ENABLED && NRFX_UART0_ENABLED) -#undef NRFX_UARTE_ENABLED -#define NRFX_UARTE_ENABLED (UART_ENABLED && (NRFX_UARTE0_ENABLED || NRFX_UARTE1_ENABLED)) - -#if defined(UART0_ENABLED) -#undef NRFX_UART0_ENABLED -#define NRFX_UART0_ENABLED (UART0_ENABLED && UART_LEGACY_SUPPORT) -#undef NRFX_UARTE0_ENABLED -#define NRFX_UARTE0_ENABLED (UART0_ENABLED && UART_EASY_DMA_SUPPORT) -#endif -#if defined(UART1_ENABLED) -#undef NRFX_UARTE1_ENABLED -#define NRFX_UARTE1_ENABLED (UART1_ENABLED && UART_EASY_DMA_SUPPORT) -#endif - -#if defined(UART_DEFAULT_CONFIG_HWFC) -#undef NRFX_UART_DEFAULT_CONFIG_HWFC -#define NRFX_UART_DEFAULT_CONFIG_HWFC UART_DEFAULT_CONFIG_HWFC -#undef NRFX_UARTE_DEFAULT_CONFIG_HWFC -#define NRFX_UARTE_DEFAULT_CONFIG_HWFC UART_DEFAULT_CONFIG_HWFC -#endif -#if defined(UART_DEFAULT_CONFIG_PARITY) -#undef NRFX_UART_DEFAULT_CONFIG_PARITY -#define NRFX_UART_DEFAULT_CONFIG_PARITY UART_DEFAULT_CONFIG_PARITY -#undef NRFX_UARTE_DEFAULT_CONFIG_PARITY -#define NRFX_UARTE_DEFAULT_CONFIG_PARITY UART_DEFAULT_CONFIG_PARITY -#endif -#if defined(UART_DEFAULT_CONFIG_BAUDRATE) -#undef NRFX_UART_DEFAULT_CONFIG_BAUDRATE -#define NRFX_UART_DEFAULT_CONFIG_BAUDRATE UART_DEFAULT_CONFIG_BAUDRATE -#undef NRFX_UARTE_DEFAULT_CONFIG_BAUDRATE -#define NRFX_UARTE_DEFAULT_CONFIG_BAUDRATE UART_DEFAULT_CONFIG_BAUDRATE -#endif -#if defined(UART_DEFAULT_CONFIG_IRQ_PRIORITY) -#undef NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY -#define NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY UART_DEFAULT_CONFIG_IRQ_PRIORITY -#undef NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY -#define NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY UART_DEFAULT_CONFIG_IRQ_PRIORITY -#endif - -#if defined(UART_CONFIG_LOG_ENABLED) -#undef NRFX_UART_CONFIG_LOG_ENABLED -#define NRFX_UART_CONFIG_LOG_ENABLED UART_CONFIG_LOG_ENABLED -#undef NRFX_UARTE_CONFIG_LOG_ENABLED -#define NRFX_UARTE_CONFIG_LOG_ENABLED UART_CONFIG_LOG_ENABLED -#endif -#if defined(UART_CONFIG_LOG_LEVEL) -#undef NRFX_UART_CONFIG_LOG_LEVEL -#define NRFX_UART_CONFIG_LOG_LEVEL UART_CONFIG_LOG_LEVEL -#undef NRFX_UARTE_CONFIG_LOG_LEVEL -#define NRFX_UARTE_CONFIG_LOG_LEVEL UART_CONFIG_LOG_LEVEL -#endif -#if defined(UART_CONFIG_INFO_COLOR) -#undef NRFX_UART_CONFIG_INFO_COLOR -#define NRFX_UART_CONFIG_INFO_COLOR UART_CONFIG_INFO_COLOR -#undef NRFX_UARTE_CONFIG_INFO_COLOR -#define NRFX_UARTE_CONFIG_INFO_COLOR UART_CONFIG_INFO_COLOR -#endif -#if defined(UART_CONFIG_DEBUG_COLOR) -#undef NRFX_UART_CONFIG_DEBUG_COLOR -#define NRFX_UART_CONFIG_DEBUG_COLOR UART_CONFIG_DEBUG_COLOR -#undef NRFX_UARTE_CONFIG_DEBUG_COLOR -#define NRFX_UARTE_CONFIG_DEBUG_COLOR UART_CONFIG_DEBUG_COLOR -#endif - -#endif // defined(UART_ENABLED) - -//------------------------------------------------------------------------------ -// WDT - -#if defined(WDT_ENABLED) - -#undef NRFX_WDT_ENABLED -#define NRFX_WDT_ENABLED WDT_ENABLED - -#if defined(WDT_CONFIG_BEHAVIOUR) -#undef NRFX_WDT_CONFIG_BEHAVIOUR -#define NRFX_WDT_CONFIG_BEHAVIOUR WDT_CONFIG_BEHAVIOUR -#endif -#if defined(WDT_CONFIG_RELOAD_VALUE) -#undef NRFX_WDT_CONFIG_RELOAD_VALUE -#define NRFX_WDT_CONFIG_RELOAD_VALUE WDT_CONFIG_RELOAD_VALUE -#endif -#if defined(WDT_CONFIG_IRQ_PRIORITY) -#undef NRFX_WDT_CONFIG_IRQ_PRIORITY -#define NRFX_WDT_CONFIG_IRQ_PRIORITY WDT_CONFIG_IRQ_PRIORITY -#endif - -#if defined(WDT_CONFIG_LOG_ENABLED) -#undef NRFX_WDT_CONFIG_LOG_ENABLED -#define NRFX_WDT_CONFIG_LOG_ENABLED WDT_CONFIG_LOG_ENABLED -#endif -#if defined(WDT_CONFIG_LOG_LEVEL) -#undef NRFX_WDT_CONFIG_LOG_LEVEL -#define NRFX_WDT_CONFIG_LOG_LEVEL WDT_CONFIG_LOG_LEVEL -#endif -#if defined(WDT_CONFIG_INFO_COLOR) -#undef NRFX_WDT_CONFIG_INFO_COLOR -#define NRFX_WDT_CONFIG_INFO_COLOR WDT_CONFIG_INFO_COLOR -#endif -#if defined(WDT_CONFIG_DEBUG_COLOR) -#undef NRFX_WDT_CONFIG_DEBUG_COLOR -#define NRFX_WDT_CONFIG_DEBUG_COLOR WDT_CONFIG_DEBUG_COLOR -#endif - -#endif // defined(WDT_ENABLED) - -#endif // APPLY_OLD_CONFIG_H__ diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/integration/nrfx/legacy/nrf_drv_rng.c b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/integration/nrfx/legacy/nrf_drv_rng.c new file mode 100644 index 0000000000..a3aed4bf86 --- /dev/null +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/integration/nrfx/legacy/nrf_drv_rng.c @@ -0,0 +1,283 @@ +/** + * Copyright (c) 2016 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "sdk_common.h" +#if NRF_MODULE_ENABLED(RNG) + +#include +#include +#include "nrf_drv_rng.h" +#include "nordic_common.h" +#include "app_util_platform.h" +#include "nrf_assert.h" +#include "nrf_queue.h" + +#ifdef SOFTDEVICE_PRESENT + #include "nrf_sdh.h" +#endif // SOFTDEVICE_PRESENT + +#define NRF_LOG_MODULE_NAME rng + +#if RNG_CONFIG_LOG_ENABLED + #define NRF_LOG_LEVEL RNG_CONFIG_LOG_LEVEL + #define NRF_LOG_INFO_COLOR RNG_CONFIG_INFO_COLOR + #define NRF_LOG_DEBUG_COLOR RNG_CONFIG_DEBUG_COLOR +#else //RNG_CONFIG_LOG_ENABLED + #define NRF_LOG_LEVEL 0 +#endif //RNG_CONFIG_LOG_ENABLED +#include "nrf_log.h" +NRF_LOG_MODULE_REGISTER(); + +typedef struct +{ + nrfx_drv_state_t state; + nrf_drv_rng_config_t config; +} nrf_drv_rng_cb_t; + +static nrf_drv_rng_cb_t m_rng_cb; +NRF_QUEUE_DEF(uint8_t, m_rand_pool, RNG_CONFIG_POOL_SIZE, NRF_QUEUE_MODE_OVERFLOW); +static const nrf_drv_rng_config_t m_default_config = NRF_DRV_RNG_DEFAULT_CONFIG; + +#ifdef SOFTDEVICE_PRESENT + #define SD_RAND_POOL_SIZE (64) + + STATIC_ASSERT(RNG_CONFIG_POOL_SIZE == SD_RAND_POOL_SIZE); + + #define NRF_DRV_RNG_LOCK() CRITICAL_REGION_ENTER() + #define NRF_DRV_RNG_RELEASE() CRITICAL_REGION_EXIT() + #define NRF_DRV_RNG_SD_IS_ENABLED() nrf_sdh_is_enabled() +#else + #define NRF_DRV_RNG_LOCK() do { } while (0) + #define NRF_DRV_RNG_RELEASE() do { } while (0) + #define NRF_DRV_RNG_SD_IS_ENABLED() false +#endif // SOFTDEVICE_PRESENT + + +static void nrfx_rng_handler(uint8_t rng_val) +{ + NRF_DRV_RNG_LOCK(); + if (!NRF_DRV_RNG_SD_IS_ENABLED()) + { + UNUSED_RETURN_VALUE(nrf_queue_push(&m_rand_pool, &rng_val)); + + if (nrf_queue_is_full(&m_rand_pool)) + { + nrfx_rng_stop(); + } + + NRF_LOG_DEBUG("Event: NRF_RNG_EVENT_VALRDY."); + } + NRF_DRV_RNG_RELEASE(); + +} + +ret_code_t nrf_drv_rng_init(nrf_drv_rng_config_t const * p_config) +{ + ret_code_t err_code = NRF_SUCCESS; + if (m_rng_cb.state != NRFX_DRV_STATE_UNINITIALIZED) + { + return NRF_ERROR_MODULE_ALREADY_INITIALIZED; + } + + if (p_config == NULL) + { + p_config = &m_default_config; + } + m_rng_cb.config = *p_config; + + NRF_DRV_RNG_LOCK(); + + if (!NRF_DRV_RNG_SD_IS_ENABLED()) + { + err_code = nrfx_rng_init(&m_rng_cb.config, nrfx_rng_handler); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + nrfx_rng_start(); + } + m_rng_cb.state = NRFX_DRV_STATE_INITIALIZED; + + NRF_DRV_RNG_RELEASE(); + + return err_code; +} + +void nrf_drv_rng_uninit(void) +{ + ASSERT(m_rng_cb.state == NRFX_DRV_STATE_INITIALIZED); + + NRF_DRV_RNG_LOCK(); + + if (!NRF_DRV_RNG_SD_IS_ENABLED()) + { + nrfx_rng_stop(); + nrfx_rng_uninit(); + } + + NRF_DRV_RNG_RELEASE(); + + nrf_queue_reset(&m_rand_pool); + m_rng_cb.state = NRFX_DRV_STATE_UNINITIALIZED; + NRF_LOG_INFO("Uninitialized."); +} + +void nrf_drv_rng_bytes_available(uint8_t * p_bytes_available) +{ + ASSERT(m_rng_cb.state == NRFX_DRV_STATE_INITIALIZED); + +#ifdef SOFTDEVICE_PRESENT + if (NRF_DRV_RNG_SD_IS_ENABLED()) + { + if (NRF_SUCCESS == sd_rand_application_bytes_available_get(p_bytes_available)) + { + return; + } + } +#endif // SOFTDEVICE_PRESENT + + *p_bytes_available = nrf_queue_utilization_get(&m_rand_pool); + + NRF_LOG_INFO("Function: %s, available bytes: %d.", (uint32_t)__func__, *p_bytes_available); +} + +ret_code_t nrf_drv_rng_rand(uint8_t * p_buff, uint8_t length) +{ + ret_code_t err_code = NRF_SUCCESS; + ASSERT(m_rng_cb.state == NRFX_DRV_STATE_INITIALIZED); + +#ifdef SOFTDEVICE_PRESENT + do { + bool sd_is_enabled; + NRF_DRV_RNG_LOCK(); + sd_is_enabled = NRF_DRV_RNG_SD_IS_ENABLED(); + if (!sd_is_enabled) +#endif // SOFTDEVICE_PRESENT + { + err_code = nrf_queue_read(&m_rand_pool, p_buff, (uint32_t)length); + nrfx_rng_start(); + } +#ifdef SOFTDEVICE_PRESENT + NRF_DRV_RNG_RELEASE(); + + if (sd_is_enabled) + { + err_code = sd_rand_application_vector_get(p_buff, length); + if (err_code == NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUES) + { + err_code = NRF_ERROR_NOT_FOUND; + } + } + } while (err_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED); +#endif // SOFTDEVICE_PRESENT + ASSERT((err_code == NRF_SUCCESS) || (err_code == NRF_ERROR_NOT_FOUND)); + +#if defined(RNG_CONFIG_RANDOM_NUMBER_LOG_ENABLED) && (RNG_CONFIG_RANDOM_NUMBER_LOG_ENABLED != 0) + NRF_LOG_DEBUG("Rand buffer data:"); + NRF_LOG_HEXDUMP_DEBUG((uint8_t *)p_buff, length); +#endif // RNG_CONFIG_RANDOM_NUMBER_LOG_ENABLED + NRF_LOG_WARNING("Function: %s, error code: %s.", + (uint32_t)__func__, + (uint32_t)NRF_LOG_ERROR_STRING_GET(err_code)); + + return err_code; +} + +void nrf_drv_rng_block_rand(uint8_t * p_buff, uint32_t length) +{ + ASSERT(m_rng_cb.state == NRFX_DRV_STATE_INITIALIZED); + + while (length) + { + uint32_t len = MIN(length, RNG_CONFIG_POOL_SIZE); + ret_code_t err_code; + + do { + err_code = nrf_drv_rng_rand(p_buff, len); + } while (err_code != NRF_SUCCESS); + + length -= len; + p_buff += len; + } + + NRF_LOG_DEBUG("Rand buffer data:"); + NRF_LOG_HEXDUMP_DEBUG((uint8_t *)p_buff, length); +} + +#ifdef SOFTDEVICE_PRESENT +static void sd_state_evt_handler(nrf_sdh_state_evt_t state, void * p_context) +{ + switch (state) + { + case NRF_SDH_EVT_STATE_ENABLE_PREPARE: + if (m_rng_cb.state == NRFX_DRV_STATE_INITIALIZED) + { + nrfx_rng_stop(); + nrfx_rng_uninit(); + } + break; + + case NRF_SDH_EVT_STATE_DISABLED: + NRF_DRV_RNG_LOCK(); + if (m_rng_cb.state == NRFX_DRV_STATE_INITIALIZED) + { + ret_code_t err_code = nrfx_rng_init(&m_rng_cb.config, nrfx_rng_handler); + if (err_code != NRF_SUCCESS) + { + ASSERT(false); + } + nrfx_rng_start(); + } + NRF_DRV_RNG_RELEASE(); + break; + + default: + break; + } +} + +NRF_SDH_STATE_OBSERVER(m_sd_state_observer, RNG_CONFIG_STATE_OBSERVER_PRIO) = +{ + .handler = sd_state_evt_handler, + .p_context = NULL, +}; + +#endif // SOFTDEVICE_PRESENT + +#endif // NRF_MODULE_ENABLED(RNG)