add files from nrf52832 bootloader project
This commit is contained in:
		
							
								
								
									
										124
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										124
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,124 @@
 | 
			
		||||
/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/** @file
 | 
			
		||||
 *
 | 
			
		||||
 * @defgroup app_error Common application error handler
 | 
			
		||||
 * @{
 | 
			
		||||
 * @ingroup app_common
 | 
			
		||||
 *
 | 
			
		||||
 * @brief Common application error handler.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "nrf.h"
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include "app_error.h"
 | 
			
		||||
#include "nordic_common.h"
 | 
			
		||||
#include "sdk_errors.h"
 | 
			
		||||
#include "nrf_log.h"
 | 
			
		||||
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
#include "bsp.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for error handling, which is called when an error has occurred.
 | 
			
		||||
 *
 | 
			
		||||
 * @warning This handler is an example only and does not fit a final product. You need to analyze
 | 
			
		||||
 *          how your product is supposed to react in case of error.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] error_code  Error code supplied to the handler.
 | 
			
		||||
 * @param[in] line_num    Line number where the handler is called.
 | 
			
		||||
 * @param[in] p_file_name Pointer to the file name.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/*lint -save -e14 */
 | 
			
		||||
void app_error_handler(ret_code_t error_code, uint32_t line_num, const uint8_t * p_file_name)
 | 
			
		||||
{
 | 
			
		||||
    error_info_t error_info =
 | 
			
		||||
    {
 | 
			
		||||
        .line_num    = line_num,
 | 
			
		||||
        .p_file_name = p_file_name,
 | 
			
		||||
        .err_code    = error_code,
 | 
			
		||||
    };
 | 
			
		||||
    app_error_fault_handler(NRF_FAULT_ID_SDK_ERROR, 0, (uint32_t)(&error_info));
 | 
			
		||||
 | 
			
		||||
    UNUSED_VARIABLE(error_info);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*lint -save -e14 */
 | 
			
		||||
void app_error_handler_bare(ret_code_t error_code)
 | 
			
		||||
{
 | 
			
		||||
    error_info_t error_info =
 | 
			
		||||
    {
 | 
			
		||||
        .line_num    = 0,
 | 
			
		||||
        .p_file_name = NULL,
 | 
			
		||||
        .err_code    = error_code,
 | 
			
		||||
    };
 | 
			
		||||
    app_error_fault_handler(NRF_FAULT_ID_SDK_ERROR, 0, (uint32_t)(&error_info));
 | 
			
		||||
 | 
			
		||||
    UNUSED_VARIABLE(error_info);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void app_error_save_and_stop(uint32_t id, uint32_t pc, uint32_t info)
 | 
			
		||||
{
 | 
			
		||||
    /* static error variables - in order to prevent removal by optimizers */
 | 
			
		||||
    static volatile struct
 | 
			
		||||
    {
 | 
			
		||||
        uint32_t        fault_id;
 | 
			
		||||
        uint32_t        pc;
 | 
			
		||||
        uint32_t        error_info;
 | 
			
		||||
        assert_info_t * p_assert_info;
 | 
			
		||||
        error_info_t  * p_error_info;
 | 
			
		||||
        ret_code_t      err_code;
 | 
			
		||||
        uint32_t        line_num;
 | 
			
		||||
        const uint8_t * p_file_name;
 | 
			
		||||
    } m_error_data = {0};
 | 
			
		||||
 | 
			
		||||
    // The following variable helps Keil keep the call stack visible, in addition, it can be set to
 | 
			
		||||
    // 0 in the debugger to continue executing code after the error check.
 | 
			
		||||
    volatile bool loop = true;
 | 
			
		||||
    UNUSED_VARIABLE(loop);
 | 
			
		||||
 | 
			
		||||
    m_error_data.fault_id   = id;
 | 
			
		||||
    m_error_data.pc         = pc;
 | 
			
		||||
    m_error_data.error_info = info;
 | 
			
		||||
 | 
			
		||||
    switch (id)
 | 
			
		||||
    {
 | 
			
		||||
        case NRF_FAULT_ID_SDK_ASSERT:
 | 
			
		||||
            m_error_data.p_assert_info = (assert_info_t *)info;
 | 
			
		||||
            m_error_data.line_num      = m_error_data.p_assert_info->line_num;
 | 
			
		||||
            m_error_data.p_file_name   = m_error_data.p_assert_info->p_file_name;
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case NRF_FAULT_ID_SDK_ERROR:
 | 
			
		||||
            m_error_data.p_error_info = (error_info_t *)info;
 | 
			
		||||
            m_error_data.err_code     = m_error_data.p_error_info->err_code;
 | 
			
		||||
            m_error_data.line_num     = m_error_data.p_error_info->line_num;
 | 
			
		||||
            m_error_data.p_file_name  = m_error_data.p_error_info->p_file_name;
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    UNUSED_VARIABLE(m_error_data);
 | 
			
		||||
 | 
			
		||||
    // If printing is disrupted, remove the irq calls, or set the loop variable to 0 in the debugger.
 | 
			
		||||
    __disable_irq();
 | 
			
		||||
 | 
			
		||||
    while(loop);
 | 
			
		||||
 | 
			
		||||
    __enable_irq();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*lint -restore */
 | 
			
		||||
							
								
								
									
										201
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										201
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,201 @@
 | 
			
		||||
/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/** @file
 | 
			
		||||
 *
 | 
			
		||||
 * @defgroup app_error Common application error handler
 | 
			
		||||
 * @{
 | 
			
		||||
 * @ingroup app_common
 | 
			
		||||
 *
 | 
			
		||||
 * @brief Common application error handler and macros for utilizing a common error handler.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef APP_ERROR_H__
 | 
			
		||||
#define APP_ERROR_H__
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include "nrf.h"
 | 
			
		||||
#include "sdk_errors.h"
 | 
			
		||||
#include "nordic_common.h"
 | 
			
		||||
#include "nrf_log.h"
 | 
			
		||||
#include "app_error_weak.h"
 | 
			
		||||
 | 
			
		||||
#define NRF_FAULT_ID_SDK_RANGE_START 0x00004000 /**< The start of the range of error IDs defined in the SDK. */
 | 
			
		||||
 | 
			
		||||
/**@defgroup APP_ERROR_FAULT_IDS Fault ID types
 | 
			
		||||
 * @{ */
 | 
			
		||||
#define NRF_FAULT_ID_SDK_ERROR       NRF_FAULT_ID_SDK_RANGE_START + 1 /**< An error stemming from a call to @ref APP_ERROR_CHECK or @ref APP_ERROR_CHECK_BOOL. The info parameter is a pointer to an @ref error_info_t variable. */
 | 
			
		||||
#define NRF_FAULT_ID_SDK_ASSERT      NRF_FAULT_ID_SDK_RANGE_START + 2 /**< An error stemming from a call to ASSERT (nrf_assert.h). The info parameter is a pointer to an @ref assert_info_t variable. */
 | 
			
		||||
/**@} */
 | 
			
		||||
 | 
			
		||||
/**@brief Structure containing info about an error of the type @ref NRF_FAULT_ID_SDK_ERROR.
 | 
			
		||||
 */
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
    uint16_t        line_num;    /**< The line number where the error occurred. */
 | 
			
		||||
    uint8_t const * p_file_name; /**< The file in which the error occurred. */
 | 
			
		||||
    uint32_t        err_code;    /**< The error code representing the error that occurred. */
 | 
			
		||||
} error_info_t;
 | 
			
		||||
 | 
			
		||||
/**@brief Structure containing info about an error of the type @ref NRF_FAULT_ID_SDK_ASSERT.
 | 
			
		||||
 */
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
    uint16_t        line_num;    /**< The line number where the error occurred. */
 | 
			
		||||
    uint8_t const * p_file_name; /**< The file in which the error occurred. */
 | 
			
		||||
} assert_info_t;
 | 
			
		||||
 | 
			
		||||
/**@brief Function for error handling, which is called when an error has occurred.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] error_code  Error code supplied to the handler.
 | 
			
		||||
 * @param[in] line_num    Line number where the handler is called.
 | 
			
		||||
 * @param[in] p_file_name Pointer to the file name.
 | 
			
		||||
 */
 | 
			
		||||
void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for error handling, which is called when an error has occurred.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] error_code  Error code supplied to the handler.
 | 
			
		||||
 */
 | 
			
		||||
void app_error_handler_bare(ret_code_t error_code);
 | 
			
		||||
 | 
			
		||||
/**@brief       Function for saving the parameters and entering an eternal loop, for debug purposes.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] id    Fault identifier. See @ref NRF_FAULT_IDS.
 | 
			
		||||
 * @param[in] pc    The program counter of the instruction that triggered the fault, or 0 if
 | 
			
		||||
 *                  unavailable.
 | 
			
		||||
 * @param[in] info  Optional additional information regarding the fault. Refer to each fault
 | 
			
		||||
 *                  identifier for details.
 | 
			
		||||
 */
 | 
			
		||||
void app_error_save_and_stop(uint32_t id, uint32_t pc, uint32_t info);
 | 
			
		||||
 | 
			
		||||
/**@brief       Function for printing all error info (using nrf_log).
 | 
			
		||||
 *
 | 
			
		||||
 * @details     Nrf_log library must be initialized using NRF_LOG_INIT macro before calling
 | 
			
		||||
 *              this function.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] id    Fault identifier. See @ref NRF_FAULT_IDS.
 | 
			
		||||
 * @param[in] pc    The program counter of the instruction that triggered the fault, or 0 if
 | 
			
		||||
 *                  unavailable.
 | 
			
		||||
 * @param[in] info  Optional additional information regarding the fault. Refer to each fault
 | 
			
		||||
 *                  identifier for details.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE void app_error_log(uint32_t id, uint32_t pc, uint32_t info)
 | 
			
		||||
{
 | 
			
		||||
    switch (id)
 | 
			
		||||
    {
 | 
			
		||||
        case NRF_FAULT_ID_SDK_ASSERT:
 | 
			
		||||
            NRF_LOG(NRF_LOG_COLOR_RED "\n*** ASSERTION FAILED ***\n");
 | 
			
		||||
            if (((assert_info_t *)(info))->p_file_name)
 | 
			
		||||
            {
 | 
			
		||||
                NRF_LOG_PRINTF(NRF_LOG_COLOR_WHITE "Line Number: %u\n", (unsigned int) ((assert_info_t *)(info))->line_num);
 | 
			
		||||
                NRF_LOG_PRINTF("File Name:   %s\n", ((assert_info_t *)(info))->p_file_name);
 | 
			
		||||
            }
 | 
			
		||||
            NRF_LOG_PRINTF(NRF_LOG_COLOR_DEFAULT "\n");
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case NRF_FAULT_ID_SDK_ERROR:
 | 
			
		||||
            NRF_LOG(NRF_LOG_COLOR_RED "\n*** APPLICATION ERROR *** \n" NRF_LOG_COLOR_WHITE);
 | 
			
		||||
            if (((error_info_t *)(info))->p_file_name)
 | 
			
		||||
            {
 | 
			
		||||
                NRF_LOG_PRINTF("Line Number: %u\n", (unsigned int) ((error_info_t *)(info))->line_num);
 | 
			
		||||
                NRF_LOG_PRINTF("File Name:   %s\n", ((error_info_t *)(info))->p_file_name);
 | 
			
		||||
            }
 | 
			
		||||
            NRF_LOG_PRINTF("Error Code:  0x%X\n" NRF_LOG_COLOR_DEFAULT "\n", (unsigned int) ((error_info_t *)(info))->err_code);
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**@brief       Function for printing all error info (using printf).
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] id    Fault identifier. See @ref NRF_FAULT_IDS.
 | 
			
		||||
 * @param[in] pc    The program counter of the instruction that triggered the fault, or 0 if
 | 
			
		||||
 *                  unavailable.
 | 
			
		||||
 * @param[in] info  Optional additional information regarding the fault. Refer to each fault
 | 
			
		||||
 *                  identifier for details.
 | 
			
		||||
 */
 | 
			
		||||
//lint -save -e438
 | 
			
		||||
static __INLINE void app_error_print(uint32_t id, uint32_t pc, uint32_t info)
 | 
			
		||||
{
 | 
			
		||||
    unsigned int tmp = id;
 | 
			
		||||
    printf("app_error_print():\r\n");
 | 
			
		||||
    printf("Fault identifier:  0x%X\r\n", tmp);
 | 
			
		||||
    printf("Program counter:   0x%X\r\n", tmp = pc);
 | 
			
		||||
    printf("Fault information: 0x%X\r\n", tmp = info);
 | 
			
		||||
 | 
			
		||||
    switch (id)
 | 
			
		||||
    {
 | 
			
		||||
        case NRF_FAULT_ID_SDK_ASSERT:
 | 
			
		||||
            printf("Line Number: %u\r\n", tmp = ((assert_info_t *)(info))->line_num);
 | 
			
		||||
            printf("File Name:   %s\r\n",       ((assert_info_t *)(info))->p_file_name);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case NRF_FAULT_ID_SDK_ERROR:
 | 
			
		||||
            printf("Line Number: %u\r\n",   tmp = ((error_info_t *)(info))->line_num);
 | 
			
		||||
            printf("File Name:   %s\r\n",         ((error_info_t *)(info))->p_file_name);
 | 
			
		||||
            printf("Error Code:  0x%X\r\n", tmp = ((error_info_t *)(info))->err_code);
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
//lint -restore
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for calling error handler function.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] ERR_CODE Error code supplied to the error handler.
 | 
			
		||||
 */
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
#define APP_ERROR_HANDLER(ERR_CODE)                                    \
 | 
			
		||||
    do                                                                 \
 | 
			
		||||
    {                                                                  \
 | 
			
		||||
        app_error_handler((ERR_CODE), __LINE__, (uint8_t*) __FILE__);  \
 | 
			
		||||
    } while (0)
 | 
			
		||||
#else
 | 
			
		||||
#define APP_ERROR_HANDLER(ERR_CODE)                                    \
 | 
			
		||||
    do                                                                 \
 | 
			
		||||
    {                                                                  \
 | 
			
		||||
        app_error_handler_bare((ERR_CODE));                            \
 | 
			
		||||
    } while (0)
 | 
			
		||||
#endif
 | 
			
		||||
/**@brief Macro for calling error handler function if supplied error code any other than NRF_SUCCESS.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] ERR_CODE Error code supplied to the error handler.
 | 
			
		||||
 */
 | 
			
		||||
#define APP_ERROR_CHECK(ERR_CODE)                           \
 | 
			
		||||
    do                                                      \
 | 
			
		||||
    {                                                       \
 | 
			
		||||
        const uint32_t LOCAL_ERR_CODE = (ERR_CODE);         \
 | 
			
		||||
        if (LOCAL_ERR_CODE != NRF_SUCCESS)                  \
 | 
			
		||||
        {                                                   \
 | 
			
		||||
            APP_ERROR_HANDLER(LOCAL_ERR_CODE);              \
 | 
			
		||||
        }                                                   \
 | 
			
		||||
    } while (0)
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for calling error handler function if supplied boolean value is false.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] BOOLEAN_VALUE Boolean value to be evaluated.
 | 
			
		||||
 */
 | 
			
		||||
#define APP_ERROR_CHECK_BOOL(BOOLEAN_VALUE)                   \
 | 
			
		||||
    do                                                        \
 | 
			
		||||
    {                                                         \
 | 
			
		||||
        const uint32_t LOCAL_BOOLEAN_VALUE = (BOOLEAN_VALUE); \
 | 
			
		||||
        if (!LOCAL_BOOLEAN_VALUE)                             \
 | 
			
		||||
        {                                                     \
 | 
			
		||||
            APP_ERROR_HANDLER(0);                             \
 | 
			
		||||
        }                                                     \
 | 
			
		||||
    } while (0)
 | 
			
		||||
 | 
			
		||||
#endif // APP_ERROR_H__
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
@@ -0,0 +1,53 @@
 | 
			
		||||
/* Copyright (c) 2016 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "app_error.h"
 | 
			
		||||
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
#include "bsp.h"
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
/*lint -save -e14 */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Function is implemented as weak so that it can be overwritten by custom application error handler
 | 
			
		||||
 * when needed.
 | 
			
		||||
 */
 | 
			
		||||
__WEAK void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
 | 
			
		||||
{
 | 
			
		||||
    // On assert, the system can only recover with a reset.
 | 
			
		||||
#ifndef DEBUG
 | 
			
		||||
    NVIC_SystemReset();
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
#ifdef BSP_DEFINES_ONLY
 | 
			
		||||
    LEDS_ON(LEDS_MASK);
 | 
			
		||||
#else
 | 
			
		||||
    UNUSED_VARIABLE(bsp_indication_set(BSP_INDICATE_FATAL_ERROR));
 | 
			
		||||
    // This call can be used for debug purposes during application development.
 | 
			
		||||
    // @note CAUTION: Activating this code will write the stack to flash on an error.
 | 
			
		||||
    //                This function should NOT be used in a final product.
 | 
			
		||||
    //                It is intended STRICTLY for development/debugging purposes.
 | 
			
		||||
    //                The flash write will happen EVEN if the radio is active, thus interrupting
 | 
			
		||||
    //                any communication.
 | 
			
		||||
    //                Use with care. Uncomment the line below to use.
 | 
			
		||||
    //ble_debug_assert_handler(error_code, line_num, p_file_name);
 | 
			
		||||
#endif // BSP_DEFINES_ONLY
 | 
			
		||||
 | 
			
		||||
    app_error_save_and_stop(id, pc, info);
 | 
			
		||||
 | 
			
		||||
#endif // DEBUG
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*lint -restore */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,51 @@
 | 
			
		||||
/* Copyright (c) 2016 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef APP_ERROR_WEAK_H__
 | 
			
		||||
#define APP_ERROR_WEAK_H__
 | 
			
		||||
 | 
			
		||||
/** @file
 | 
			
		||||
 *
 | 
			
		||||
 * @defgroup app_error Common application error handler
 | 
			
		||||
 * @{
 | 
			
		||||
 * @ingroup app_common
 | 
			
		||||
 *
 | 
			
		||||
 * @brief Common application error handler.
 | 
			
		||||
 */
 | 
			
		||||
 
 | 
			
		||||
/**@brief       Callback function for asserts in the SoftDevice.
 | 
			
		||||
 *
 | 
			
		||||
 * @details     A pointer to this function will be passed to the SoftDevice. This function will be
 | 
			
		||||
 *              called by the SoftDevice if certain unrecoverable errors occur within the
 | 
			
		||||
 *              application or SoftDevice.
 | 
			
		||||
 *
 | 
			
		||||
 *              See @ref nrf_fault_handler_t for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] id    Fault identifier. See @ref NRF_FAULT_IDS.
 | 
			
		||||
 * @param[in] pc    The program counter of the instruction that triggered the fault, or 0 if
 | 
			
		||||
 *                  unavailable.
 | 
			
		||||
 * @param[in] info  Optional additional information regarding the fault. Refer to each fault
 | 
			
		||||
 *                  identifier for details.
 | 
			
		||||
 *
 | 
			
		||||
 * @remarks Function is implemented as weak so that it can be overwritten by custom application
 | 
			
		||||
 *          error handler when needed.
 | 
			
		||||
 */
 | 
			
		||||
#ifdef __CC_ARM
 | 
			
		||||
	     void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info);
 | 
			
		||||
#else
 | 
			
		||||
__WEAK void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
 | 
			
		||||
#endif // APP_ERROR_WEAK_H__
 | 
			
		||||
							
								
								
									
										493
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										493
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,493 @@
 | 
			
		||||
/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/** @file
 | 
			
		||||
 *
 | 
			
		||||
 * @defgroup app_util Utility Functions and Definitions
 | 
			
		||||
 * @{
 | 
			
		||||
 * @ingroup app_common
 | 
			
		||||
 *
 | 
			
		||||
 * @brief Various types and definitions available to all applications.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef APP_UTIL_H__
 | 
			
		||||
#define APP_UTIL_H__
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include "compiler_abstraction.h"
 | 
			
		||||
#include "nrf.h"
 | 
			
		||||
 | 
			
		||||
//lint -save -e27 -e10 -e19
 | 
			
		||||
#if defined ( __CC_ARM )
 | 
			
		||||
extern char STACK$$Base;
 | 
			
		||||
extern char STACK$$Length;
 | 
			
		||||
#define STACK_BASE    &STACK$$Base
 | 
			
		||||
#define STACK_TOP    ((void*)((uint32_t)STACK_BASE + (uint32_t)&STACK$$Length))
 | 
			
		||||
#elif defined ( __ICCARM__ )
 | 
			
		||||
extern char CSTACK$$Base;
 | 
			
		||||
extern char CSTACK$$Length;
 | 
			
		||||
#define STACK_BASE    &CSTACK$$Base
 | 
			
		||||
#define STACK_TOP    ((void*)((uint32_t)STACK_BASE + (uint32_t)&CSTACK$$Length))
 | 
			
		||||
#elif defined   ( __GNUC__ )
 | 
			
		||||
extern uint32_t __StackTop;
 | 
			
		||||
extern uint32_t __StackLimit;
 | 
			
		||||
#define STACK_BASE    &__StackLimit
 | 
			
		||||
#define STACK_TOP     &__StackTop
 | 
			
		||||
#endif
 | 
			
		||||
//lint -restore
 | 
			
		||||
 | 
			
		||||
enum
 | 
			
		||||
{
 | 
			
		||||
    UNIT_0_625_MS = 625,                                /**< Number of microseconds in 0.625 milliseconds. */
 | 
			
		||||
    UNIT_1_25_MS  = 1250,                               /**< Number of microseconds in 1.25 milliseconds. */
 | 
			
		||||
    UNIT_10_MS    = 10000                               /**< Number of microseconds in 10 milliseconds. */
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Implementation specific macro for delayed macro expansion used in string concatenation
 | 
			
		||||
*
 | 
			
		||||
* @param[in]   lhs   Left hand side in concatenation
 | 
			
		||||
* @param[in]   rhs   Right hand side in concatenation
 | 
			
		||||
*/
 | 
			
		||||
#define STRING_CONCATENATE_IMPL(lhs, rhs) lhs ## rhs
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro used to concatenate string using delayed macro expansion
 | 
			
		||||
*
 | 
			
		||||
* @note This macro will delay concatenation until the expressions have been resolved
 | 
			
		||||
*
 | 
			
		||||
* @param[in]   lhs   Left hand side in concatenation
 | 
			
		||||
* @param[in]   rhs   Right hand side in concatenation
 | 
			
		||||
*/
 | 
			
		||||
#define STRING_CONCATENATE(lhs, rhs) STRING_CONCATENATE_IMPL(lhs, rhs)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Disable lint-warnings/errors for STATIC_ASSERT
 | 
			
		||||
//lint --emacro(10,STATIC_ASSERT)
 | 
			
		||||
//lint --emacro(18,STATIC_ASSERT)
 | 
			
		||||
//lint --emacro(19,STATIC_ASSERT)
 | 
			
		||||
//lint --emacro(30,STATIC_ASSERT)
 | 
			
		||||
//lint --emacro(37,STATIC_ASSERT)
 | 
			
		||||
//lint --emacro(42,STATIC_ASSERT)
 | 
			
		||||
//lint --emacro(26,STATIC_ASSERT)
 | 
			
		||||
//lint --emacro(102,STATIC_ASSERT)
 | 
			
		||||
//lint --emacro(533,STATIC_ASSERT)
 | 
			
		||||
//lint --emacro(534,STATIC_ASSERT)
 | 
			
		||||
//lint --emacro(132,STATIC_ASSERT)
 | 
			
		||||
//lint --emacro(414,STATIC_ASSERT)
 | 
			
		||||
//lint --emacro(578,STATIC_ASSERT)
 | 
			
		||||
//lint --emacro(628,STATIC_ASSERT)
 | 
			
		||||
//lint --emacro(648,STATIC_ASSERT)
 | 
			
		||||
//lint --emacro(830,STATIC_ASSERT)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for doing static (i.e. compile time) assertion.
 | 
			
		||||
*
 | 
			
		||||
* @note If the EXPR isn't resolvable, then the error message won't be shown.
 | 
			
		||||
*
 | 
			
		||||
* @note The output of STATIC_ASSERT will be different across different compilers.
 | 
			
		||||
*
 | 
			
		||||
* @param[in] EXPR Constant expression to be verified.
 | 
			
		||||
*/
 | 
			
		||||
#if defined ( __COUNTER__ )
 | 
			
		||||
 | 
			
		||||
#define STATIC_ASSERT(EXPR) \
 | 
			
		||||
    ;enum { STRING_CONCATENATE(static_assert_, __COUNTER__) = 1/(!!(EXPR)) }
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
#define STATIC_ASSERT(EXPR) \
 | 
			
		||||
    ;enum { STRING_CONCATENATE(assert_line_, __LINE__) = 1/(!!(EXPR)) }
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Implementation details for NUM_VAR_ARGS */
 | 
			
		||||
#define NUM_VA_ARGS_IMPL(                              \
 | 
			
		||||
    _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10,       \
 | 
			
		||||
    _11, _12, _13, _14, _15, _16, _17, _18, _19, _20,  \
 | 
			
		||||
    _21, _22, _23, _24, _25, _26, _27, _28, _29, _30,  \
 | 
			
		||||
    _31, _32, _33, _34, _35, _36, _37, _38, _39, _40,  \
 | 
			
		||||
    _41, _42, _43, _44, _45, _46, _47, _48, _49, _50,  \
 | 
			
		||||
    _51, _52, _53, _54, _55, _56, _57, _58, _59, _60,  \
 | 
			
		||||
    _61, _62, N, ...) N
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro to get the number of arguments in a call variadic macro call
 | 
			
		||||
 *
 | 
			
		||||
 * param[in]    ...     List of arguments
 | 
			
		||||
 *
 | 
			
		||||
 * @retval  Number of variadic arguments in the argument list
 | 
			
		||||
 */
 | 
			
		||||
#define NUM_VA_ARGS(...) NUM_VA_ARGS_IMPL(__VA_ARGS__, 63, 62, 61,  \
 | 
			
		||||
    60, 59, 58, 57, 56, 55, 54, 53, 52, 51,                         \
 | 
			
		||||
    50, 49, 48, 47, 46, 45, 44, 43, 42, 41,                         \
 | 
			
		||||
    40, 39, 38, 37, 36, 35, 34, 33, 32, 31,                         \
 | 
			
		||||
    30, 29, 28, 27, 26, 25, 24, 23, 22, 21,                         \
 | 
			
		||||
    20, 19, 18, 17, 16, 15, 14, 13, 12, 11,                         \
 | 
			
		||||
    10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief type for holding an encoded (i.e. little endian) 16 bit unsigned integer. */
 | 
			
		||||
typedef uint8_t uint16_le_t[2];
 | 
			
		||||
 | 
			
		||||
/**@brief Type for holding an encoded (i.e. little endian) 32 bit unsigned integer. */
 | 
			
		||||
typedef uint8_t uint32_le_t[4];
 | 
			
		||||
 | 
			
		||||
/**@brief Byte array type. */
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
    uint16_t  size;                 /**< Number of array entries. */
 | 
			
		||||
    uint8_t * p_data;               /**< Pointer to array entries. */
 | 
			
		||||
} uint8_array_t;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for performing rounded integer division (as opposed to truncating the result).
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   A   Numerator.
 | 
			
		||||
 * @param[in]   B   Denominator.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Rounded (integer) result of dividing A by B.
 | 
			
		||||
 */
 | 
			
		||||
#define ROUNDED_DIV(A, B) (((A) + ((B) / 2)) / (B))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for checking if an integer is a power of two.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   A   Number to be tested.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      true if value is power of two.
 | 
			
		||||
 * @return      false if value not power of two.
 | 
			
		||||
 */
 | 
			
		||||
#define IS_POWER_OF_TWO(A) ( ((A) != 0) && ((((A) - 1) & (A)) == 0) )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for converting milliseconds to ticks.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] TIME          Number of milliseconds to convert.
 | 
			
		||||
 * @param[in] RESOLUTION    Unit to be converted to in [us/ticks].
 | 
			
		||||
 */
 | 
			
		||||
#define MSEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000) / (RESOLUTION))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for performing integer division, making sure the result is rounded up.
 | 
			
		||||
 *
 | 
			
		||||
 * @details One typical use for this is to compute the number of objects with size B is needed to
 | 
			
		||||
 *          hold A number of bytes.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   A   Numerator.
 | 
			
		||||
 * @param[in]   B   Denominator.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Integer result of dividing A by B, rounded up.
 | 
			
		||||
 */
 | 
			
		||||
#define CEIL_DIV(A, B)      \
 | 
			
		||||
    (((A) + (B) - 1) / (B))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for creating a buffer aligned to 4 bytes.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   NAME        Name of the buffor.
 | 
			
		||||
 * @param[in]   MIN_SIZE    Size of this buffor (it will be rounded up to multiples of 4 bytes).
 | 
			
		||||
 */
 | 
			
		||||
#define WORD_ALIGNED_MEM_BUFF(NAME, MIN_SIZE) static uint32_t NAME[CEIL_DIV(MIN_SIZE, sizeof(uint32_t))]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for calculating the number of words that are needed to hold a number of bytes.
 | 
			
		||||
 *
 | 
			
		||||
 * @details Adds 3 and divides by 4.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]  n_bytes  The number of bytes.
 | 
			
		||||
 *
 | 
			
		||||
 * @return The number of words that @p n_bytes take up (rounded up).
 | 
			
		||||
 */
 | 
			
		||||
#define BYTES_TO_WORDS(n_bytes) (((n_bytes) + 3) >> 2)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief The number of bytes in a word.
 | 
			
		||||
 */
 | 
			
		||||
#define BYTES_PER_WORD (4)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for increasing a number to the nearest (larger) multiple of another number.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]  alignment  The number to align to.
 | 
			
		||||
 * @param[in]  number     The number to align (increase).
 | 
			
		||||
 *
 | 
			
		||||
 * @return The aligned (increased) @p number.
 | 
			
		||||
 */
 | 
			
		||||
#define ALIGN_NUM(alignment, number) ((number - 1) + alignment - ((number - 1) % alignment))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for changing the value unit.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   value               Value to be rescaled.
 | 
			
		||||
 * @param[in]   old_unit_reversal   Reversal of the incoming unit.
 | 
			
		||||
 * @param[in]   new_unit_reversal   Reversal of the desired unit.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Number of bytes written.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint64_t value_rescale(uint32_t value, uint32_t old_unit_reversal, uint16_t new_unit_reversal)
 | 
			
		||||
{
 | 
			
		||||
    return (uint64_t)ROUNDED_DIV((uint64_t)value * new_unit_reversal, old_unit_reversal);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**@brief Function for encoding a uint16 value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   value            Value to be encoded.
 | 
			
		||||
 * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Number of bytes written.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t uint16_encode(uint16_t value, uint8_t * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    p_encoded_data[0] = (uint8_t) ((value & 0x00FF) >> 0);
 | 
			
		||||
    p_encoded_data[1] = (uint8_t) ((value & 0xFF00) >> 8);
 | 
			
		||||
    return sizeof(uint16_t);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**@brief Function for encoding a three-byte value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   value            Value to be encoded.
 | 
			
		||||
 * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Number of bytes written.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t uint24_encode(uint32_t value, uint8_t * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    p_encoded_data[0] = (uint8_t) ((value & 0x000000FF) >> 0);
 | 
			
		||||
    p_encoded_data[1] = (uint8_t) ((value & 0x0000FF00) >> 8);
 | 
			
		||||
    p_encoded_data[2] = (uint8_t) ((value & 0x00FF0000) >> 16);
 | 
			
		||||
    return 3;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**@brief Function for encoding a uint32 value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   value            Value to be encoded.
 | 
			
		||||
 * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Number of bytes written.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t uint32_encode(uint32_t value, uint8_t * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    p_encoded_data[0] = (uint8_t) ((value & 0x000000FF) >> 0);
 | 
			
		||||
    p_encoded_data[1] = (uint8_t) ((value & 0x0000FF00) >> 8);
 | 
			
		||||
    p_encoded_data[2] = (uint8_t) ((value & 0x00FF0000) >> 16);
 | 
			
		||||
    p_encoded_data[3] = (uint8_t) ((value & 0xFF000000) >> 24);
 | 
			
		||||
    return sizeof(uint32_t);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**@brief Function for encoding a uint48 value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   value            Value to be encoded.
 | 
			
		||||
 * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Number of bytes written.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t uint48_encode(uint64_t value, uint8_t * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    p_encoded_data[0] = (uint8_t) ((value & 0x0000000000FF) >> 0);
 | 
			
		||||
    p_encoded_data[1] = (uint8_t) ((value & 0x00000000FF00) >> 8);
 | 
			
		||||
    p_encoded_data[2] = (uint8_t) ((value & 0x000000FF0000) >> 16);
 | 
			
		||||
    p_encoded_data[3] = (uint8_t) ((value & 0x0000FF000000) >> 24);
 | 
			
		||||
    p_encoded_data[4] = (uint8_t) ((value & 0x00FF00000000) >> 32);
 | 
			
		||||
    p_encoded_data[5] = (uint8_t) ((value & 0xFF0000000000) >> 40);
 | 
			
		||||
    return 6;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**@brief Function for decoding a uint16 value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Decoded value.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint16_t uint16_decode(const uint8_t * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
        return ( (((uint16_t)((uint8_t *)p_encoded_data)[0])) |
 | 
			
		||||
                 (((uint16_t)((uint8_t *)p_encoded_data)[1]) << 8 ));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**@brief Function for decoding a uint16 value in big-endian format.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Decoded value.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint16_t uint16_big_decode(const uint8_t * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
        return ( (((uint16_t)((uint8_t *)p_encoded_data)[0]) << 8 ) |
 | 
			
		||||
                 (((uint16_t)((uint8_t *)p_encoded_data)[1])) );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**@brief Function for decoding a three-byte value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Decoded value (uint32_t).
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint32_t uint24_decode(const uint8_t * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    return ( (((uint32_t)((uint8_t *)p_encoded_data)[0]) << 0)  |
 | 
			
		||||
             (((uint32_t)((uint8_t *)p_encoded_data)[1]) << 8)  |
 | 
			
		||||
             (((uint32_t)((uint8_t *)p_encoded_data)[2]) << 16));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**@brief Function for decoding a uint32 value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Decoded value.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint32_t uint32_decode(const uint8_t * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    return ( (((uint32_t)((uint8_t *)p_encoded_data)[0]) << 0)  |
 | 
			
		||||
             (((uint32_t)((uint8_t *)p_encoded_data)[1]) << 8)  |
 | 
			
		||||
             (((uint32_t)((uint8_t *)p_encoded_data)[2]) << 16) |
 | 
			
		||||
             (((uint32_t)((uint8_t *)p_encoded_data)[3]) << 24 ));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**@brief Function for decoding a uint32 value in big-endian format.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Decoded value.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint32_t uint32_big_decode(const uint8_t * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    return ( (((uint32_t)((uint8_t *)p_encoded_data)[0]) << 24) |
 | 
			
		||||
             (((uint32_t)((uint8_t *)p_encoded_data)[1]) << 16) |
 | 
			
		||||
             (((uint32_t)((uint8_t *)p_encoded_data)[2]) << 8)  |
 | 
			
		||||
             (((uint32_t)((uint8_t *)p_encoded_data)[3]) << 0) );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**@brief Function for encoding a uint32 value in big-endian format.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   value            Value to be encoded.
 | 
			
		||||
 * @param[out]  p_encoded_data   Buffer where the encoded data will be written.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Number of bytes written.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t uint32_big_encode(uint32_t value, uint8_t * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
#ifdef NRF51
 | 
			
		||||
    p_encoded_data[0] = (uint8_t) ((value & 0xFF000000) >> 24);
 | 
			
		||||
    p_encoded_data[1] = (uint8_t) ((value & 0x00FF0000) >> 16);
 | 
			
		||||
    p_encoded_data[2] = (uint8_t) ((value & 0x0000FF00) >> 8);
 | 
			
		||||
    p_encoded_data[3] = (uint8_t) ((value & 0x000000FF) >> 0);
 | 
			
		||||
#elif NRF52
 | 
			
		||||
    *(uint32_t *)p_encoded_data = __REV(value);
 | 
			
		||||
#endif
 | 
			
		||||
    return sizeof(uint32_t);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**@brief Function for decoding a uint48 value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Decoded value. (uint64_t)
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint64_t uint48_decode(const uint8_t * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    return ( (((uint64_t)((uint8_t *)p_encoded_data)[0]) << 0)  |
 | 
			
		||||
             (((uint64_t)((uint8_t *)p_encoded_data)[1]) << 8)  |
 | 
			
		||||
             (((uint64_t)((uint8_t *)p_encoded_data)[2]) << 16) |
 | 
			
		||||
             (((uint64_t)((uint8_t *)p_encoded_data)[3]) << 24) |
 | 
			
		||||
             (((uint64_t)((uint8_t *)p_encoded_data)[4]) << 32) |
 | 
			
		||||
             (((uint64_t)((uint8_t *)p_encoded_data)[5]) << 40 ));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** @brief Function for converting the input voltage (in milli volts) into percentage of 3.0 Volts.
 | 
			
		||||
 *
 | 
			
		||||
 *  @details The calculation is based on a linearized version of the battery's discharge
 | 
			
		||||
 *           curve. 3.0V returns 100% battery level. The limit for power failure is 2.1V and
 | 
			
		||||
 *           is considered to be the lower boundary.
 | 
			
		||||
 *
 | 
			
		||||
 *           The discharge curve for CR2032 is non-linear. In this model it is split into
 | 
			
		||||
 *           4 linear sections:
 | 
			
		||||
 *           - Section 1: 3.0V - 2.9V = 100% - 42% (58% drop on 100 mV)
 | 
			
		||||
 *           - Section 2: 2.9V - 2.74V = 42% - 18% (24% drop on 160 mV)
 | 
			
		||||
 *           - Section 3: 2.74V - 2.44V = 18% - 6% (12% drop on 300 mV)
 | 
			
		||||
 *           - Section 4: 2.44V - 2.1V = 6% - 0% (6% drop on 340 mV)
 | 
			
		||||
 *
 | 
			
		||||
 *           These numbers are by no means accurate. Temperature and
 | 
			
		||||
 *           load in the actual application is not accounted for!
 | 
			
		||||
 *
 | 
			
		||||
 *  @param[in] mvolts The voltage in mV
 | 
			
		||||
 *
 | 
			
		||||
 *  @return    Battery level in percent.
 | 
			
		||||
*/
 | 
			
		||||
static __INLINE uint8_t battery_level_in_percent(const uint16_t mvolts)
 | 
			
		||||
{
 | 
			
		||||
    uint8_t battery_level;
 | 
			
		||||
 | 
			
		||||
    if (mvolts >= 3000)
 | 
			
		||||
    {
 | 
			
		||||
        battery_level = 100;
 | 
			
		||||
    }
 | 
			
		||||
    else if (mvolts > 2900)
 | 
			
		||||
    {
 | 
			
		||||
        battery_level = 100 - ((3000 - mvolts) * 58) / 100;
 | 
			
		||||
    }
 | 
			
		||||
    else if (mvolts > 2740)
 | 
			
		||||
    {
 | 
			
		||||
        battery_level = 42 - ((2900 - mvolts) * 24) / 160;
 | 
			
		||||
    }
 | 
			
		||||
    else if (mvolts > 2440)
 | 
			
		||||
    {
 | 
			
		||||
        battery_level = 18 - ((2740 - mvolts) * 12) / 300;
 | 
			
		||||
    }
 | 
			
		||||
    else if (mvolts > 2100)
 | 
			
		||||
    {
 | 
			
		||||
        battery_level = 6 - ((2440 - mvolts) * 6) / 340;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        battery_level = 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return battery_level;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**@brief Function for checking if a pointer value is aligned to a 4 byte boundary.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p   Pointer value to be checked.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      TRUE if pointer is aligned to a 4 byte boundary, FALSE otherwise.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE bool is_word_aligned(void const* p)
 | 
			
		||||
{
 | 
			
		||||
    return (((uintptr_t)p & 0x03) == 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for checking if provided address is located in stack space.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   ptr Pointer to be checked.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      true if address is in stack space, false otherwise.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE bool is_address_from_stack(void * ptr)
 | 
			
		||||
{
 | 
			
		||||
    if (((uint32_t)ptr >= (uint32_t)STACK_BASE) &&
 | 
			
		||||
        ((uint32_t)ptr <  (uint32_t)STACK_TOP) )
 | 
			
		||||
    {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // APP_UTIL_H__
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
							
								
								
									
										413
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util_bds.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										413
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util_bds.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,413 @@
 | 
			
		||||
/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/** @file
 | 
			
		||||
 *
 | 
			
		||||
 * @defgroup app_util Utility Functions and Definitions
 | 
			
		||||
 * @{
 | 
			
		||||
 * @ingroup app_common
 | 
			
		||||
 *
 | 
			
		||||
 * @brief Various types and definitions available to all applications.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef APP_UTIL_BDS_H__
 | 
			
		||||
#define APP_UTIL_BDS_H__
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include "compiler_abstraction.h"
 | 
			
		||||
#include "app_util.h"
 | 
			
		||||
#include "ble_srv_common.h"
 | 
			
		||||
#include "nordic_common.h"
 | 
			
		||||
    
 | 
			
		||||
typedef uint8_t nibble_t;
 | 
			
		||||
typedef uint32_t uint24_t;
 | 
			
		||||
typedef uint64_t uint40_t;
 | 
			
		||||
 | 
			
		||||
/**@brief IEEE 11073-20601 Regulatory Certification Data List Structure */
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
    uint8_t *  p_list;                                          /**< Pointer the byte array containing the encoded opaque structure based on IEEE 11073-20601 specification. */
 | 
			
		||||
    uint8_t    list_len;                                        /**< Length of the byte array. */
 | 
			
		||||
} regcertdatalist_t;
 | 
			
		||||
 | 
			
		||||
/**@brief SFLOAT format (IEEE-11073 16-bit FLOAT, meaning 4 bits for exponent (base 10) and 12 bits mantissa) */
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
  int8_t exponent;                                             /**< Base 10 exponent, should be using only 4 bits */
 | 
			
		||||
  int16_t mantissa;                                            /**< Mantissa, should be using only 12 bits */
 | 
			
		||||
} sfloat_t;
 | 
			
		||||
 | 
			
		||||
/**@brief Date and Time structure. */
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
    uint16_t year;
 | 
			
		||||
    uint8_t  month;
 | 
			
		||||
    uint8_t  day;
 | 
			
		||||
    uint8_t  hours;
 | 
			
		||||
    uint8_t  minutes;
 | 
			
		||||
    uint8_t  seconds;
 | 
			
		||||
} ble_date_time_t;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for encoding a uint16 value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p_value          Value to be encoded.
 | 
			
		||||
 * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Number of bytes written.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_uint16_encode(const uint16_t * p_value, uint8_t * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    p_encoded_data[0] = (uint8_t) ((*p_value & 0x00FF) >> 0);
 | 
			
		||||
    p_encoded_data[1] = (uint8_t) ((*p_value & 0xFF00) >> 8);
 | 
			
		||||
    return sizeof(uint16_t);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static __INLINE uint8_t bds_int16_encode(const int16_t * p_value, uint8_t * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    uint16_t tmp = *p_value;
 | 
			
		||||
    return bds_uint16_encode(&tmp, p_encoded_data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**@brief Function for encoding a uint24 value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p_value          Value to be encoded.
 | 
			
		||||
 * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Number of bytes written.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_uint24_encode(const uint32_t * p_value, uint8_t * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    p_encoded_data[0] = (uint8_t) ((*p_value & 0x000000FF) >> 0);
 | 
			
		||||
    p_encoded_data[1] = (uint8_t) ((*p_value & 0x0000FF00) >> 8);
 | 
			
		||||
    p_encoded_data[2] = (uint8_t) ((*p_value & 0x00FF0000) >> 16);
 | 
			
		||||
    return (3);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
/**@brief Function for encoding a uint32 value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p_value          Value to be encoded.
 | 
			
		||||
 * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Number of bytes written.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_uint32_encode(const uint32_t * p_value, uint8_t * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    p_encoded_data[0] = (uint8_t) ((*p_value & 0x000000FF) >> 0);
 | 
			
		||||
    p_encoded_data[1] = (uint8_t) ((*p_value & 0x0000FF00) >> 8);
 | 
			
		||||
    p_encoded_data[2] = (uint8_t) ((*p_value & 0x00FF0000) >> 16);
 | 
			
		||||
    p_encoded_data[3] = (uint8_t) ((*p_value & 0xFF000000) >> 24);
 | 
			
		||||
    return sizeof(uint32_t);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
/**@brief Function for encoding a uint40 value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p_value          Value to be encoded.
 | 
			
		||||
 * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Number of bytes written.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_uint40_encode(const uint64_t * p_value, uint8_t * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    p_encoded_data[0] = (uint8_t) ((*p_value & 0x00000000000000FF) >> 0);
 | 
			
		||||
    p_encoded_data[1] = (uint8_t) ((*p_value & 0x000000000000FF00) >> 8);
 | 
			
		||||
    p_encoded_data[2] = (uint8_t) ((*p_value & 0x0000000000FF0000) >> 16);
 | 
			
		||||
    p_encoded_data[3] = (uint8_t) ((*p_value & 0x00000000FF000000) >> 24);
 | 
			
		||||
    p_encoded_data[4] = (uint8_t) ((*p_value & 0x000000FF00000000) >> 32);
 | 
			
		||||
    return 5;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**@brief Function for encoding a sfloat value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p_value          Value to be encoded.
 | 
			
		||||
 * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
 | 
			
		||||
 *
 | 
			
		||||
 * @return      Number of bytes written.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_sfloat_encode(const sfloat_t * p_value, uint8_t * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    uint16_t encoded_val;
 | 
			
		||||
 | 
			
		||||
    encoded_val = ((p_value->exponent << 12) & 0xF000) |
 | 
			
		||||
                            ((p_value->mantissa <<  0) & 0x0FFF);
 | 
			
		||||
 | 
			
		||||
    return(bds_uint16_encode(&encoded_val, p_encoded_data));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for encoding a uint8_array value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p_value          Value to be encoded.
 | 
			
		||||
 * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_uint8_array_encode(const uint8_array_t * p_value, 
 | 
			
		||||
                                               uint8_t             * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    memcpy(p_encoded_data, p_value->p_data, p_value->size);
 | 
			
		||||
    return p_value->size;
 | 
			
		||||
}    
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for encoding a utf8_str value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p_value          Value to be encoded.
 | 
			
		||||
 * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
 | 
			
		||||
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_ble_srv_utf8_str_encode(const ble_srv_utf8_str_t * p_value,
 | 
			
		||||
                                                    uint8_t                  * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    memcpy(p_encoded_data, p_value->p_str, p_value->length);
 | 
			
		||||
    return p_value->length;
 | 
			
		||||
}    
 | 
			
		||||
 | 
			
		||||
/**@brief Function for encoding a regcertdatalist value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p_value          Value to be encoded.
 | 
			
		||||
 * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
 | 
			
		||||
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_regcertdatalist_encode(const regcertdatalist_t * p_value, 
 | 
			
		||||
                                                   uint8_t                 * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    memcpy(p_encoded_data, p_value->p_list, p_value->list_len);
 | 
			
		||||
    return p_value->list_len;
 | 
			
		||||
}    
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for decoding a date_time value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   p_date_time    pointer to the date_time structure to encode.
 | 
			
		||||
 * @param[in]   p_encoded_data pointer to the encoded data
 | 
			
		||||
 * @return      length of the encoded field.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_ble_date_time_encode(const ble_date_time_t * p_date_time,
 | 
			
		||||
                                                 uint8_t               * p_encoded_data)
 | 
			
		||||
{
 | 
			
		||||
    uint8_t len = bds_uint16_encode(&p_date_time->year, &p_encoded_data[0]);
 | 
			
		||||
    
 | 
			
		||||
    p_encoded_data[len++] = p_date_time->month;
 | 
			
		||||
    p_encoded_data[len++] = p_date_time->day;
 | 
			
		||||
    p_encoded_data[len++] = p_date_time->hours;
 | 
			
		||||
    p_encoded_data[len++] = p_date_time->minutes;
 | 
			
		||||
    p_encoded_data[len++] = p_date_time->seconds;
 | 
			
		||||
    
 | 
			
		||||
    return len;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for decoding a uint16 value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   len              length of the field to be decoded.
 | 
			
		||||
 * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
 | 
			
		||||
 * @param[in]   p_decoded_val    pointer to the decoded value
 | 
			
		||||
 * @return      length of the decoded field.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_uint16_decode(const uint8_t len, 
 | 
			
		||||
                                          const uint8_t * p_encoded_data, 
 | 
			
		||||
                                          uint16_t      * p_decoded_val)
 | 
			
		||||
{
 | 
			
		||||
    UNUSED_VARIABLE(len);
 | 
			
		||||
    *p_decoded_val = (((uint16_t)((uint8_t *)p_encoded_data)[0])) | 
 | 
			
		||||
                     (((uint16_t)((uint8_t *)p_encoded_data)[1]) << 8 );
 | 
			
		||||
    return (sizeof(uint16_t));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for decoding a int16 value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   len              length of the field to be decoded.
 | 
			
		||||
 * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
 | 
			
		||||
 * @param[in]   p_decoded_val    pointer to the decoded value
 | 
			
		||||
 * @return      length of the decoded field.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_int16_decode(const uint8_t len, 
 | 
			
		||||
                                         const uint8_t * p_encoded_data, 
 | 
			
		||||
                                         int16_t       * p_decoded_val)
 | 
			
		||||
{
 | 
			
		||||
    UNUSED_VARIABLE(len);
 | 
			
		||||
    uint16_t tmp = 0;
 | 
			
		||||
    uint8_t retval = bds_uint16_decode(len, p_encoded_data, &tmp);
 | 
			
		||||
    *p_decoded_val = (int16_t)tmp;
 | 
			
		||||
    return retval;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for decoding a uint24 value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   len              length of the field to be decoded.
 | 
			
		||||
 * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
 | 
			
		||||
 * @param[in]   p_decoded_val    pointer to the decoded value
 | 
			
		||||
 *
 | 
			
		||||
 * @return      length of the decoded field.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_uint24_decode(const uint8_t len, 
 | 
			
		||||
                                          const uint8_t * p_encoded_data, 
 | 
			
		||||
                                          uint32_t      * p_decoded_val)
 | 
			
		||||
{
 | 
			
		||||
    UNUSED_VARIABLE(len);
 | 
			
		||||
    *p_decoded_val = (((uint32_t)((uint8_t *)p_encoded_data)[0]) << 0)  |
 | 
			
		||||
                     (((uint32_t)((uint8_t *)p_encoded_data)[1]) << 8)  |
 | 
			
		||||
                     (((uint32_t)((uint8_t *)p_encoded_data)[2]) << 16);
 | 
			
		||||
    return (3);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for decoding a uint32 value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   len              length of the field to be decoded.
 | 
			
		||||
 * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
 | 
			
		||||
 * @param[in]   p_decoded_val    pointer to the decoded value
 | 
			
		||||
 *
 | 
			
		||||
 * @return      length of the decoded field.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_uint32_decode(const uint8_t len, 
 | 
			
		||||
                                          const uint8_t * p_encoded_data, 
 | 
			
		||||
                                          uint32_t      * p_decoded_val)
 | 
			
		||||
{
 | 
			
		||||
    UNUSED_VARIABLE(len);
 | 
			
		||||
    *p_decoded_val = (((uint32_t)((uint8_t *)p_encoded_data)[0]) << 0)  |
 | 
			
		||||
                     (((uint32_t)((uint8_t *)p_encoded_data)[1]) << 8)  |
 | 
			
		||||
                     (((uint32_t)((uint8_t *)p_encoded_data)[2]) << 16) |
 | 
			
		||||
                     (((uint32_t)((uint8_t *)p_encoded_data)[3]) << 24 );
 | 
			
		||||
    return (sizeof(uint32_t));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for decoding a uint40 value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   len              length of the field to be decoded.
 | 
			
		||||
 * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
 | 
			
		||||
 * @param[in]   p_decoded_val    pointer to the decoded value
 | 
			
		||||
 *
 | 
			
		||||
 * @return      length of the decoded field.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_uint40_decode(const uint8_t len, 
 | 
			
		||||
                                          const uint8_t * p_encoded_data, 
 | 
			
		||||
                                          uint64_t      * p_decoded_val)
 | 
			
		||||
{
 | 
			
		||||
    UNUSED_VARIABLE(len);
 | 
			
		||||
    *p_decoded_val = (((uint64_t)((uint8_t *)p_encoded_data)[0]) << 0)  |
 | 
			
		||||
                     (((uint64_t)((uint8_t *)p_encoded_data)[1]) << 8)  |
 | 
			
		||||
                     (((uint64_t)((uint8_t *)p_encoded_data)[2]) << 16) |
 | 
			
		||||
                     (((uint64_t)((uint8_t *)p_encoded_data)[3]) << 24 )|
 | 
			
		||||
                     (((uint64_t)((uint8_t *)p_encoded_data)[4]) << 32 );
 | 
			
		||||
    return (40);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for decoding a sfloat value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   len              length of the field to be decoded.
 | 
			
		||||
 * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
 | 
			
		||||
 * @param[in]   p_decoded_val    pointer to the decoded value
 | 
			
		||||
 *
 | 
			
		||||
 * @return      length of the decoded field.
 | 
			
		||||
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_sfloat_decode(const uint8_t len, 
 | 
			
		||||
                                          const uint8_t * p_encoded_data, 
 | 
			
		||||
                                          sfloat_t      * p_decoded_val)
 | 
			
		||||
{
 | 
			
		||||
    
 | 
			
		||||
    p_decoded_val->exponent = 0;
 | 
			
		||||
    bds_uint16_decode(len, p_encoded_data, (uint16_t*)&p_decoded_val->mantissa);
 | 
			
		||||
    p_decoded_val->exponent = (uint8_t)((p_decoded_val->mantissa & 0xF000) >> 12);
 | 
			
		||||
    p_decoded_val->mantissa &= 0x0FFF;
 | 
			
		||||
    return len;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for decoding a uint8_array value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   len              length of the field to be decoded.
 | 
			
		||||
 * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
 | 
			
		||||
 * @param[in]   p_decoded_val    pointer to the decoded value
 | 
			
		||||
 *
 | 
			
		||||
 * @return      length of the decoded field.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_uint8_array_decode(const uint8_t len, 
 | 
			
		||||
                                               const uint8_t * p_encoded_data,
 | 
			
		||||
                                               uint8_array_t * p_decoded_val)
 | 
			
		||||
{
 | 
			
		||||
    memcpy(p_decoded_val->p_data, p_encoded_data, len);
 | 
			
		||||
    p_decoded_val->size = len;
 | 
			
		||||
    return p_decoded_val->size;
 | 
			
		||||
}   
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for decoding a utf8_str value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   len              length of the field to be decoded.
 | 
			
		||||
 * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
 | 
			
		||||
 * @param[in]   p_decoded_val    pointer to the decoded value
 | 
			
		||||
 *
 | 
			
		||||
 * @return      length of the decoded field.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_ble_srv_utf8_str_decode(const uint8_t      len, 
 | 
			
		||||
                                                    const uint8_t      * p_encoded_data, 
 | 
			
		||||
                                                    ble_srv_utf8_str_t * p_decoded_val)
 | 
			
		||||
{
 | 
			
		||||
    p_decoded_val->p_str = (uint8_t*)p_encoded_data;
 | 
			
		||||
    p_decoded_val->length = len;
 | 
			
		||||
    return p_decoded_val->length;
 | 
			
		||||
}   
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for decoding a regcertdatalist value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   len              length of the field to be decoded.
 | 
			
		||||
 * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
 | 
			
		||||
 * @param[in]   p_decoded_val    pointer to the decoded value
 | 
			
		||||
 *
 | 
			
		||||
 * @return      length of the decoded field.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_regcertdatalist_decode(const uint8_t     len, 
 | 
			
		||||
                                                   const uint8_t     * p_encoded_data, 
 | 
			
		||||
                                                   regcertdatalist_t * p_decoded_val)
 | 
			
		||||
{
 | 
			
		||||
    memcpy(p_decoded_val->p_list, p_encoded_data, len);
 | 
			
		||||
    p_decoded_val->list_len = len;
 | 
			
		||||
    return p_decoded_val->list_len;
 | 
			
		||||
}    
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for decoding a date_time value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]   len              length of the field to be decoded.
 | 
			
		||||
 * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
 | 
			
		||||
 * @param[in]   p_date_time      pointer to the decoded value
 | 
			
		||||
 *
 | 
			
		||||
 * @return      length of the decoded field.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t bds_ble_date_time_decode(const uint8_t   len, 
 | 
			
		||||
                                                 const uint8_t   * p_encoded_data, 
 | 
			
		||||
                                                 ble_date_time_t * p_date_time)
 | 
			
		||||
{
 | 
			
		||||
    UNUSED_VARIABLE(len);
 | 
			
		||||
    uint8_t pos          = bds_uint16_decode(len, &p_encoded_data[0], &p_date_time->year);
 | 
			
		||||
    p_date_time->month   = p_encoded_data[pos++];
 | 
			
		||||
    p_date_time->day     = p_encoded_data[pos++];
 | 
			
		||||
    p_date_time->hours   = p_encoded_data[pos++];
 | 
			
		||||
    p_date_time->minutes = p_encoded_data[pos++];
 | 
			
		||||
    p_date_time->seconds = p_encoded_data[pos++];
 | 
			
		||||
 | 
			
		||||
    return pos;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // APP_UTIL_BDS_H__
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
@@ -0,0 +1,60 @@
 | 
			
		||||
/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "app_util_platform.h"
 | 
			
		||||
 | 
			
		||||
static uint32_t m_in_critical_region = 0;
 | 
			
		||||
 | 
			
		||||
void app_util_disable_irq(void)
 | 
			
		||||
{
 | 
			
		||||
    __disable_irq();    
 | 
			
		||||
    m_in_critical_region++;    
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void app_util_enable_irq(void)
 | 
			
		||||
{
 | 
			
		||||
    m_in_critical_region--;    
 | 
			
		||||
    if (m_in_critical_region == 0)
 | 
			
		||||
    {
 | 
			
		||||
        __enable_irq();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void app_util_critical_region_enter(uint8_t *p_nested)
 | 
			
		||||
{
 | 
			
		||||
#ifdef NRF52
 | 
			
		||||
    ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if defined(SOFTDEVICE_PRESENT)
 | 
			
		||||
    /* return value can be safely ignored */
 | 
			
		||||
    (void) sd_nvic_critical_region_enter(p_nested);
 | 
			
		||||
#else
 | 
			
		||||
    app_util_disable_irq();
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void app_util_critical_region_exit(uint8_t nested)
 | 
			
		||||
{
 | 
			
		||||
#ifdef NRF52
 | 
			
		||||
    ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if defined(SOFTDEVICE_PRESENT)
 | 
			
		||||
    /* return value can be safely ignored */
 | 
			
		||||
    (void) sd_nvic_critical_region_exit(nested);
 | 
			
		||||
#else
 | 
			
		||||
    app_util_enable_irq();
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,211 @@
 | 
			
		||||
/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/**@file
 | 
			
		||||
 *
 | 
			
		||||
 * @defgroup app_util_platform Utility Functions and Definitions (Platform)
 | 
			
		||||
 * @{
 | 
			
		||||
 * @ingroup app_common
 | 
			
		||||
 *
 | 
			
		||||
 * @brief Various types and definitions available to all applications when using SoftDevice.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef APP_UTIL_PLATFORM_H__
 | 
			
		||||
#define APP_UTIL_PLATFORM_H__
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include "compiler_abstraction.h"
 | 
			
		||||
#include "nrf.h"
 | 
			
		||||
#ifdef SOFTDEVICE_PRESENT
 | 
			
		||||
#include "nrf_soc.h"
 | 
			
		||||
#include "nrf_nvic.h"
 | 
			
		||||
#endif
 | 
			
		||||
#include "nrf_assert.h"
 | 
			
		||||
#include "app_error.h"
 | 
			
		||||
 | 
			
		||||
#if defined(NRF51)
 | 
			
		||||
#define _PRIO_SD_HIGH       0
 | 
			
		||||
#define _PRIO_APP_HIGH      1
 | 
			
		||||
#define _PRIO_APP_MID       1
 | 
			
		||||
#define _PRIO_SD_LOW        2
 | 
			
		||||
#define _PRIO_APP_LOW       3
 | 
			
		||||
#define _PRIO_APP_LOWEST    3
 | 
			
		||||
#define _PRIO_THREAD        4
 | 
			
		||||
#elif defined(NRF52)
 | 
			
		||||
#define _PRIO_SD_HIGH       0
 | 
			
		||||
#define _PRIO_SD_MID        1
 | 
			
		||||
#define _PRIO_APP_HIGH      2
 | 
			
		||||
#define _PRIO_APP_MID       3
 | 
			
		||||
#define _PRIO_SD_LOW        4
 | 
			
		||||
#define _PRIO_SD_LOWEST     5
 | 
			
		||||
#define _PRIO_APP_LOW       6
 | 
			
		||||
#define _PRIO_APP_LOWEST    7
 | 
			
		||||
#define _PRIO_THREAD        15
 | 
			
		||||
#else
 | 
			
		||||
    #error "No platform defined"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/**@brief The interrupt priorities available to the application while the SoftDevice is active. */
 | 
			
		||||
typedef enum
 | 
			
		||||
{
 | 
			
		||||
#ifdef SOFTDEVICE_PRESENT
 | 
			
		||||
    APP_IRQ_PRIORITY_HIGHEST = _PRIO_SD_HIGH,
 | 
			
		||||
#else
 | 
			
		||||
    APP_IRQ_PRIORITY_HIGHEST = _PRIO_APP_HIGH,
 | 
			
		||||
#endif
 | 
			
		||||
    APP_IRQ_PRIORITY_HIGH    = _PRIO_APP_HIGH,
 | 
			
		||||
#ifndef SOFTDEVICE_PRESENT
 | 
			
		||||
    APP_IRQ_PRIORITY_MID     = _PRIO_SD_LOW,
 | 
			
		||||
#else
 | 
			
		||||
    APP_IRQ_PRIORITY_MID     = _PRIO_APP_MID,
 | 
			
		||||
#endif
 | 
			
		||||
    APP_IRQ_PRIORITY_LOW     = _PRIO_APP_LOW,
 | 
			
		||||
    APP_IRQ_PRIORITY_LOWEST  = _PRIO_APP_LOWEST,
 | 
			
		||||
    APP_IRQ_PRIORITY_THREAD  = _PRIO_THREAD     /**< "Interrupt level" when running in Thread Mode. */
 | 
			
		||||
} app_irq_priority_t;
 | 
			
		||||
 | 
			
		||||
/*@brief The privilege levels available to applications in Thread Mode */
 | 
			
		||||
typedef enum
 | 
			
		||||
{
 | 
			
		||||
    APP_LEVEL_UNPRIVILEGED,
 | 
			
		||||
    APP_LEVEL_PRIVILEGED
 | 
			
		||||
} app_level_t;
 | 
			
		||||
 | 
			
		||||
/**@cond NO_DOXYGEN */
 | 
			
		||||
#define EXTERNAL_INT_VECTOR_OFFSET 16
 | 
			
		||||
/**@endcond */
 | 
			
		||||
 | 
			
		||||
#define PACKED(TYPE) __packed TYPE
 | 
			
		||||
 | 
			
		||||
void app_util_critical_region_enter (uint8_t *p_nested);
 | 
			
		||||
void app_util_critical_region_exit (uint8_t nested);
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for entering a critical region.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Due to implementation details, there must exist one and only one call to
 | 
			
		||||
 *       CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
 | 
			
		||||
 *       in the same scope.
 | 
			
		||||
 */
 | 
			
		||||
#ifdef SOFTDEVICE_PRESENT
 | 
			
		||||
#define CRITICAL_REGION_ENTER()                                                             \
 | 
			
		||||
    {                                                                                       \
 | 
			
		||||
        uint8_t __CR_NESTED = 0;                                                            \
 | 
			
		||||
        app_util_critical_region_enter(&__CR_NESTED);
 | 
			
		||||
#else
 | 
			
		||||
#define CRITICAL_REGION_ENTER() app_util_critical_region_enter(NULL)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for leaving a critical region.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Due to implementation details, there must exist one and only one call to
 | 
			
		||||
 *       CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
 | 
			
		||||
 *       in the same scope.
 | 
			
		||||
 */
 | 
			
		||||
#ifdef SOFTDEVICE_PRESENT
 | 
			
		||||
#define CRITICAL_REGION_EXIT()                                                              \
 | 
			
		||||
        app_util_critical_region_exit(__CR_NESTED);                                         \
 | 
			
		||||
    }
 | 
			
		||||
#else
 | 
			
		||||
#define CRITICAL_REGION_EXIT() app_util_critical_region_exit(0)
 | 
			
		||||
#endif 
 | 
			
		||||
 | 
			
		||||
/* Workaround for Keil 4 */
 | 
			
		||||
#ifndef IPSR_ISR_Msk
 | 
			
		||||
#define IPSR_ISR_Msk                       (0x1FFUL /*<< IPSR_ISR_Pos*/)                  /*!< IPSR: ISR Mask */
 | 
			
		||||
#endif
 | 
			
		||||
       
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro to enable anonymous unions from a certain point in the code.
 | 
			
		||||
 */
 | 
			
		||||
#if defined(__CC_ARM)
 | 
			
		||||
    #define ANON_UNIONS_ENABLE _Pragma("push") \
 | 
			
		||||
                               _Pragma("anon_unions")
 | 
			
		||||
#elif defined(__ICCARM__)
 | 
			
		||||
    #define ANON_UNIONS_ENABLE _Pragma("language=extended")
 | 
			
		||||
#else
 | 
			
		||||
    #define ANON_UNIONS_ENABLE
 | 
			
		||||
    // No action will be taken.
 | 
			
		||||
    // For GCC anonymous unions are enabled by default.
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/**@brief Macro to disable anonymous unions from a certain point in the code.
 | 
			
		||||
 * @note Call only after first calling @ref ANON_UNIONS_ENABLE.
 | 
			
		||||
 */
 | 
			
		||||
#if defined(__CC_ARM)
 | 
			
		||||
    #define ANON_UNIONS_DISABLE _Pragma("pop")
 | 
			
		||||
#elif defined(__ICCARM__)
 | 
			
		||||
    #define ANON_UNIONS_DISABLE
 | 
			
		||||
    // for IAR leave anonymous unions enabled
 | 
			
		||||
#else
 | 
			
		||||
    #define ANON_UNIONS_DISABLE
 | 
			
		||||
    // No action will be taken.
 | 
			
		||||
    // For GCC anonymous unions are enabled by default.
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* Workaround for Keil 4 */
 | 
			
		||||
#ifndef CONTROL_nPRIV_Msk
 | 
			
		||||
#define CONTROL_nPRIV_Msk                  (1UL /*<< CONTROL_nPRIV_Pos*/)                 /*!< CONTROL: nPRIV Mask */
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/**@brief Function for finding the current interrupt level.
 | 
			
		||||
 *
 | 
			
		||||
 * @return   Current interrupt level.
 | 
			
		||||
 * @retval   APP_IRQ_PRIORITY_HIGH    We are running in Application High interrupt level.
 | 
			
		||||
 * @retval   APP_IRQ_PRIORITY_LOW     We are running in Application Low interrupt level.
 | 
			
		||||
 * @retval   APP_IRQ_PRIORITY_THREAD  We are running in Thread Mode.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t current_int_priority_get(void)
 | 
			
		||||
{
 | 
			
		||||
    uint32_t isr_vector_num = __get_IPSR() & IPSR_ISR_Msk ;
 | 
			
		||||
    if (isr_vector_num > 0)
 | 
			
		||||
    {
 | 
			
		||||
        int32_t irq_type = ((int32_t)isr_vector_num - EXTERNAL_INT_VECTOR_OFFSET);
 | 
			
		||||
        return (NVIC_GetPriority((IRQn_Type)irq_type) & 0xFF);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        return APP_IRQ_PRIORITY_THREAD;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**@brief Function for finding out the current privilege level.
 | 
			
		||||
 *
 | 
			
		||||
 * @return   Current privilege level.
 | 
			
		||||
 * @retval   APP_LEVEL_UNPRIVILEGED    We are running in unprivileged level.
 | 
			
		||||
 * @retval   APP_LEVEL_PRIVILEGED    We are running in privileged level.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE uint8_t privilege_level_get(void)
 | 
			
		||||
{
 | 
			
		||||
#if defined(NRF51)
 | 
			
		||||
    /* the Cortex-M0 has no concept of privilege */
 | 
			
		||||
    return APP_LEVEL_PRIVILEGED;
 | 
			
		||||
#elif defined(NRF52)
 | 
			
		||||
    uint32_t isr_vector_num = __get_IPSR() & IPSR_ISR_Msk ;
 | 
			
		||||
    if (0 == isr_vector_num)
 | 
			
		||||
    {
 | 
			
		||||
        /* Thread Mode, check nPRIV */
 | 
			
		||||
        int32_t control = __get_CONTROL();
 | 
			
		||||
        return control & CONTROL_nPRIV_Msk ? APP_LEVEL_UNPRIVILEGED : APP_LEVEL_PRIVILEGED;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        /* Handler Mode, always privileged */
 | 
			
		||||
        return APP_LEVEL_PRIVILEGED;
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // APP_UTIL_PLATFORM_H__
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
							
								
								
									
										38
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/common.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/common.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef COMMON_H
 | 
			
		||||
#define COMMON_H
 | 
			
		||||
 | 
			
		||||
/*lint ++flb "Enter library region" */
 | 
			
		||||
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
/* @file
 | 
			
		||||
* @brief Common header file for generic macros and definitions
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * GPIO glue macros, this can be used to define a pin number in source/header file and use that macro for pin
 | 
			
		||||
 * configuration using this expansion.
 | 
			
		||||
 * example:
 | 
			
		||||
 * #define RESET_PIN    8
 | 
			
		||||
 * NRF_GPIO->PINCNF(RESET_PIN) = XXX  ;  // Expanded NRF_GPIO->PIN_CNF[8] = XXX
 | 
			
		||||
 */
 | 
			
		||||
#define PINX_GLUE(x, y, z)       x##y##_##z            /*!< first level glue for pin macros */
 | 
			
		||||
#define PINCNF(p)                PINX_GLUE(PIN,p,CNF)  /*!< gpio configure pin number 'p' */
 | 
			
		||||
#define PINOUT(p)                PINX_GLUE(PIN,p,OUT)  /*!< gpio out pin number 'p' */
 | 
			
		||||
 | 
			
		||||
/*lint --flb "Leave library region" */
 | 
			
		||||
#endif
 | 
			
		||||
@@ -0,0 +1,108 @@
 | 
			
		||||
/* Copyright (c) 2008 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/** @file
 | 
			
		||||
 * @brief Common defines and macros for firmware developed by Nordic Semiconductor.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef NORDIC_COMMON_H__
 | 
			
		||||
#define NORDIC_COMMON_H__
 | 
			
		||||
 | 
			
		||||
/** The upper 8 bits of a 32 bit value */
 | 
			
		||||
//lint -emacro(572,MSB) // Suppress warning 572 "Excessive shift value"
 | 
			
		||||
#define MSB_32(a) (((a) & 0xFF000000) >> 24)
 | 
			
		||||
/** The lower 8 bits (of a 32 bit value) */
 | 
			
		||||
#define LSB_32(a) ((a) & 0x000000FF)
 | 
			
		||||
 | 
			
		||||
/** The upper 8 bits of a 16 bit value */
 | 
			
		||||
//lint -emacro(572,MSB_16) // Suppress warning 572 "Excessive shift value"
 | 
			
		||||
#define MSB_16(a) (((a) & 0xFF00) >> 8)
 | 
			
		||||
/** The lower 8 bits (of a 16 bit value) */
 | 
			
		||||
#define LSB_16(a) ((a) & 0x00FF)
 | 
			
		||||
 | 
			
		||||
/** Leaves the minimum of the two 32-bit arguments */
 | 
			
		||||
/*lint -emacro(506, MIN) */ /* Suppress "Constant value Boolean */
 | 
			
		||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
 | 
			
		||||
/** Leaves the maximum of the two 32-bit arguments */
 | 
			
		||||
/*lint -emacro(506, MAX) */ /* Suppress "Constant value Boolean */
 | 
			
		||||
#define MAX(a, b) ((a) < (b) ? (b) : (a))
 | 
			
		||||
 | 
			
		||||
/** Concatenates two parameters. Useful as a second level of indirection,
 | 
			
		||||
 *  when a parameter can be macro itself. */
 | 
			
		||||
#define CONCAT_2(p1, p2)      p1##p2
 | 
			
		||||
/** Concatenates three parameters. Useful as a second level of indirection,
 | 
			
		||||
 *  when a parameter can be macro itself. */
 | 
			
		||||
#define CONCAT_3(p1, p2, p3)  p1##p2##p3
 | 
			
		||||
 | 
			
		||||
/**@brief Set a bit in the uint32 word.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] W  Word whose bit is being set.
 | 
			
		||||
 * @param[in] B  Bit number in the word to be set.
 | 
			
		||||
 */
 | 
			
		||||
#define SET_BIT(W,B)  ((W) |= (uint32_t)(1U << (B)))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Clears a bit in the uint32 word.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] W   Word whose bit is to be cleared.
 | 
			
		||||
 * @param[in] B   Bit number in the word to be cleared.
 | 
			
		||||
 */
 | 
			
		||||
#define CLR_BIT(W, B) ((W) &= (~((uint32_t)1 << (B))))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Checks if a bit is set.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] W   Word whose bit is to be checked.
 | 
			
		||||
 * @param[in] B   Bit number in the word to be checked.
 | 
			
		||||
 *
 | 
			
		||||
 * @retval 1 if bit is set.
 | 
			
		||||
 * @retval 0 if bit is not set.
 | 
			
		||||
 */
 | 
			
		||||
#define IS_SET(W,B) (((W) >> (B)) & 1)
 | 
			
		||||
 | 
			
		||||
#define BIT_0 0x01 /**< The value of bit 0 */
 | 
			
		||||
#define BIT_1 0x02 /**< The value of bit 1 */
 | 
			
		||||
#define BIT_2 0x04 /**< The value of bit 2 */
 | 
			
		||||
#define BIT_3 0x08 /**< The value of bit 3 */
 | 
			
		||||
#define BIT_4 0x10 /**< The value of bit 4 */
 | 
			
		||||
#define BIT_5 0x20 /**< The value of bit 5 */
 | 
			
		||||
#define BIT_6 0x40 /**< The value of bit 6 */
 | 
			
		||||
#define BIT_7 0x80 /**< The value of bit 7 */
 | 
			
		||||
#define BIT_8 0x0100 /**< The value of bit 8 */
 | 
			
		||||
#define BIT_9 0x0200 /**< The value of bit 9 */
 | 
			
		||||
#define BIT_10 0x0400 /**< The value of bit 10 */
 | 
			
		||||
#define BIT_11 0x0800 /**< The value of bit 11 */
 | 
			
		||||
#define BIT_12 0x1000 /**< The value of bit 12 */
 | 
			
		||||
#define BIT_13 0x2000 /**< The value of bit 13 */
 | 
			
		||||
#define BIT_14 0x4000 /**< The value of bit 14 */
 | 
			
		||||
#define BIT_15 0x8000 /**< The value of bit 15 */
 | 
			
		||||
#define BIT_16 0x00010000 /**< The value of bit 16 */
 | 
			
		||||
#define BIT_17 0x00020000 /**< The value of bit 17 */
 | 
			
		||||
#define BIT_18 0x00040000 /**< The value of bit 18 */
 | 
			
		||||
#define BIT_19 0x00080000 /**< The value of bit 19 */
 | 
			
		||||
#define BIT_20 0x00100000 /**< The value of bit 20 */
 | 
			
		||||
#define BIT_21 0x00200000 /**< The value of bit 21 */
 | 
			
		||||
#define BIT_22 0x00400000 /**< The value of bit 22 */
 | 
			
		||||
#define BIT_23 0x00800000 /**< The value of bit 23 */
 | 
			
		||||
#define BIT_24 0x01000000 /**< The value of bit 24 */
 | 
			
		||||
#define BIT_25 0x02000000 /**< The value of bit 25 */
 | 
			
		||||
#define BIT_26 0x04000000 /**< The value of bit 26 */
 | 
			
		||||
#define BIT_27 0x08000000 /**< The value of bit 27 */
 | 
			
		||||
#define BIT_28 0x10000000 /**< The value of bit 28 */
 | 
			
		||||
#define BIT_29 0x20000000 /**< The value of bit 29 */
 | 
			
		||||
#define BIT_30 0x40000000 /**< The value of bit 30 */
 | 
			
		||||
#define BIT_31 0x80000000 /**< The value of bit 31 */
 | 
			
		||||
 | 
			
		||||
#define UNUSED_VARIABLE(X)  ((void)(X))
 | 
			
		||||
#define UNUSED_PARAMETER(X) UNUSED_VARIABLE(X)
 | 
			
		||||
#define UNUSED_RETURN_VALUE(X) UNUSED_VARIABLE(X)
 | 
			
		||||
 | 
			
		||||
#endif // NORDIC_COMMON_H__
 | 
			
		||||
@@ -0,0 +1,28 @@
 | 
			
		||||
/* Copyright (c) 2006 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
#include "nrf_assert.h"
 | 
			
		||||
#include "app_error.h"
 | 
			
		||||
#include "nordic_common.h"
 | 
			
		||||
 | 
			
		||||
#if defined(DEBUG_NRF)
 | 
			
		||||
void assert_nrf_callback(uint16_t line_num, const uint8_t * file_name)
 | 
			
		||||
{
 | 
			
		||||
    assert_info_t assert_info =
 | 
			
		||||
    {
 | 
			
		||||
        .line_num    = line_num,
 | 
			
		||||
        .p_file_name = file_name,
 | 
			
		||||
    };
 | 
			
		||||
    app_error_fault_handler(NRF_FAULT_ID_SDK_ASSERT, 0, (uint32_t)(&assert_info));
 | 
			
		||||
 | 
			
		||||
    UNUSED_VARIABLE(assert_info);
 | 
			
		||||
}
 | 
			
		||||
#endif /* DEBUG_NRF */
 | 
			
		||||
@@ -0,0 +1,60 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2006 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is confidential property of Nordic Semiconductor. The use,
 | 
			
		||||
 * copying, transfer or disclosure of such information is prohibited except by express written
 | 
			
		||||
 * agreement with Nordic Semiconductor.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/** @file
 | 
			
		||||
 * @brief Utilities for verifying program logic
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef NRF_ASSERT_H_
 | 
			
		||||
#define NRF_ASSERT_H_
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include "nrf.h"
 | 
			
		||||
#include "app_error.h"
 | 
			
		||||
 | 
			
		||||
#if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER)
 | 
			
		||||
 | 
			
		||||
/** @brief Function for handling assertions.
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 * @note
 | 
			
		||||
 * This function is called when an assertion has triggered.
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 * @post
 | 
			
		||||
 * All hardware is put into an idle non-emitting state (in particular the radio is highly
 | 
			
		||||
 * important to switch off since the radio might be in a state that makes it send
 | 
			
		||||
 * packets continiously while a typical final infinit ASSERT loop is executing).
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 * @param line_num The line number where the assertion is called
 | 
			
		||||
 * @param file_name Pointer to the file name
 | 
			
		||||
 */
 | 
			
		||||
void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name);
 | 
			
		||||
 | 
			
		||||
/*lint -emacro(506, ASSERT) */ /* Suppress "Constant value Boolean */ 
 | 
			
		||||
/*lint -emacro(774, ASSERT) */ /* Suppress "Boolean within 'if' always evaluates to True" */ \
 | 
			
		||||
 | 
			
		||||
/** @brief Function for checking intended for production code.
 | 
			
		||||
 *
 | 
			
		||||
 * Check passes if "expr" evaluates to true. */
 | 
			
		||||
#define ASSERT(expr) \
 | 
			
		||||
if (expr)                                                                     \
 | 
			
		||||
{                                                                             \
 | 
			
		||||
}                                                                             \
 | 
			
		||||
else                                                                          \
 | 
			
		||||
{                                                                             \
 | 
			
		||||
    assert_nrf_callback((uint16_t)__LINE__, (uint8_t *)__FILE__);             \
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
#define ASSERT(expr) //!< Assert empty when disabled
 | 
			
		||||
__WEAK void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name);
 | 
			
		||||
#endif /* defined(DEBUG_NRF) || defined(DEBUG_NRF_USER) */
 | 
			
		||||
 | 
			
		||||
#endif /* NRF_ASSERT_H_ */
 | 
			
		||||
							
								
								
									
										425
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/nrf_log.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										425
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/nrf_log.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,425 @@
 | 
			
		||||
#include "nrf.h"
 | 
			
		||||
#include "nrf_log.h"
 | 
			
		||||
#include "nrf_error.h"
 | 
			
		||||
#include <stdarg.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
#if defined(NRF_LOG_USES_RTT) && NRF_LOG_USES_RTT == 1
 | 
			
		||||
 | 
			
		||||
#include <SEGGER_RTT_Conf.h>
 | 
			
		||||
#include <SEGGER_RTT.h>
 | 
			
		||||
 | 
			
		||||
static char buf_normal_up[BUFFER_SIZE_UP];
 | 
			
		||||
static char buf_down[BUFFER_SIZE_DOWN];
 | 
			
		||||
 | 
			
		||||
uint32_t log_rtt_init(void)
 | 
			
		||||
{
 | 
			
		||||
    static bool initialized = false;
 | 
			
		||||
    if (initialized)
 | 
			
		||||
    {
 | 
			
		||||
        return NRF_SUCCESS;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (SEGGER_RTT_ConfigUpBuffer(LOG_TERMINAL_NORMAL,
 | 
			
		||||
                                  "Normal",
 | 
			
		||||
                                  buf_normal_up,
 | 
			
		||||
                                  BUFFER_SIZE_UP,
 | 
			
		||||
                                  SEGGER_RTT_MODE_NO_BLOCK_TRIM
 | 
			
		||||
                                 )
 | 
			
		||||
        != 0)
 | 
			
		||||
    {
 | 
			
		||||
        return NRF_ERROR_INVALID_STATE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (SEGGER_RTT_ConfigDownBuffer(LOG_TERMINAL_INPUT,
 | 
			
		||||
                                   "Input",
 | 
			
		||||
                                   buf_down,
 | 
			
		||||
                                   BUFFER_SIZE_DOWN,
 | 
			
		||||
                                   SEGGER_RTT_MODE_NO_BLOCK_SKIP
 | 
			
		||||
                                  )
 | 
			
		||||
        != 0)
 | 
			
		||||
    {
 | 
			
		||||
        return NRF_ERROR_INVALID_STATE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    initialized = true;
 | 
			
		||||
 | 
			
		||||
    return NRF_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Forward declaration of SEGGER RTT vprintf function
 | 
			
		||||
int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);
 | 
			
		||||
 | 
			
		||||
void log_rtt_printf(int terminal_index, char * format_msg, ...)
 | 
			
		||||
{
 | 
			
		||||
    //lint -save -e526 -e628 -e530
 | 
			
		||||
    va_list p_args;
 | 
			
		||||
    va_start(p_args, format_msg);
 | 
			
		||||
    (void)SEGGER_RTT_vprintf(terminal_index, format_msg, &p_args);
 | 
			
		||||
    va_end(p_args);
 | 
			
		||||
    //lint -restore
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
__INLINE void log_rtt_write_string(int terminal_index, int num_args, ...)
 | 
			
		||||
{
 | 
			
		||||
    const char* msg;
 | 
			
		||||
    //lint -save -e516 -e530
 | 
			
		||||
    va_list p_args;
 | 
			
		||||
    va_start(p_args, num_args);
 | 
			
		||||
    //lint -restore
 | 
			
		||||
 | 
			
		||||
    for (int i = 0; i < num_args; i++)
 | 
			
		||||
    {
 | 
			
		||||
        //lint -save -e26 -e10 -e64 -e526 -e628 -e530
 | 
			
		||||
        msg = va_arg(p_args, const char*);
 | 
			
		||||
        //lint -restore
 | 
			
		||||
        (void)SEGGER_RTT_WriteString(terminal_index, msg);
 | 
			
		||||
    }
 | 
			
		||||
    va_end(p_args);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void log_rtt_write_hex(int terminal_index, uint32_t value)
 | 
			
		||||
{
 | 
			
		||||
    char temp[11];
 | 
			
		||||
    temp[0] = '0';
 | 
			
		||||
    temp[1] = 'x';
 | 
			
		||||
    temp[10] = 0; // Null termination
 | 
			
		||||
    uint8_t nibble;
 | 
			
		||||
    uint8_t i = 8;
 | 
			
		||||
 | 
			
		||||
    while(i-- != 0)
 | 
			
		||||
    {
 | 
			
		||||
        nibble = (value >> (4 * i)) & 0x0F;
 | 
			
		||||
        temp[9-i] = (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    (void)SEGGER_RTT_WriteString(terminal_index, temp);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void log_rtt_write_hex_char(int terminal_index, uint8_t value)
 | 
			
		||||
{
 | 
			
		||||
    char temp[3];
 | 
			
		||||
    temp[2] = 0; // Null termination
 | 
			
		||||
    uint8_t nibble;
 | 
			
		||||
    uint8_t i = 2;
 | 
			
		||||
 | 
			
		||||
    while(i-- != 0)
 | 
			
		||||
    {
 | 
			
		||||
        nibble = (value >> (4 * i)) & 0x0F;
 | 
			
		||||
        temp[1-i] = (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    (void)SEGGER_RTT_WriteString(terminal_index, temp);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
__INLINE int log_rtt_has_input()
 | 
			
		||||
{
 | 
			
		||||
    return SEGGER_RTT_HasKey();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t log_rtt_read_input(char * c)
 | 
			
		||||
{
 | 
			
		||||
    int r;
 | 
			
		||||
 | 
			
		||||
    r = SEGGER_RTT_Read(LOG_TERMINAL_INPUT, c, 1);
 | 
			
		||||
    if (r == 1)
 | 
			
		||||
        return NRF_SUCCESS;
 | 
			
		||||
    else
 | 
			
		||||
        return NRF_ERROR_NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#elif defined(NRF_LOG_USES_UART) && NRF_LOG_USES_UART == 1
 | 
			
		||||
 | 
			
		||||
#include "app_uart.h"
 | 
			
		||||
#include "app_error.h"
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include "nrf.h"
 | 
			
		||||
#include "bsp.h"
 | 
			
		||||
 | 
			
		||||
#define MAX_TEST_DATA_BYTES     (15U)                /**< max number of test bytes to be used for tx and rx. */
 | 
			
		||||
#define UART_TX_BUF_SIZE 512                         /**< UART TX buffer size. */
 | 
			
		||||
#define UART_RX_BUF_SIZE 1                           /**< UART RX buffer size. */
 | 
			
		||||
 | 
			
		||||
static uint8_t m_uart_data;
 | 
			
		||||
static bool m_uart_has_input;
 | 
			
		||||
 | 
			
		||||
void uart_error_cb(app_uart_evt_t * p_event)
 | 
			
		||||
{
 | 
			
		||||
    if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
 | 
			
		||||
    {
 | 
			
		||||
        APP_ERROR_HANDLER(p_event->data.error_communication);
 | 
			
		||||
    }
 | 
			
		||||
    else if (p_event->evt_type == APP_UART_FIFO_ERROR)
 | 
			
		||||
    {
 | 
			
		||||
        APP_ERROR_HANDLER(p_event->data.error_code);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t log_uart_init()
 | 
			
		||||
{
 | 
			
		||||
    static bool initialized = false;
 | 
			
		||||
    if (initialized)
 | 
			
		||||
    {
 | 
			
		||||
        return NRF_SUCCESS;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    uint32_t err_code;
 | 
			
		||||
    const app_uart_comm_params_t comm_params =
 | 
			
		||||
    {
 | 
			
		||||
        RX_PIN_NUMBER,
 | 
			
		||||
        TX_PIN_NUMBER,
 | 
			
		||||
        RTS_PIN_NUMBER,
 | 
			
		||||
        CTS_PIN_NUMBER,
 | 
			
		||||
        APP_UART_FLOW_CONTROL_ENABLED,
 | 
			
		||||
        false,
 | 
			
		||||
        UART_BAUDRATE_BAUDRATE_Baud115200
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    APP_UART_FIFO_INIT(&comm_params,
 | 
			
		||||
                         UART_RX_BUF_SIZE,
 | 
			
		||||
                         UART_TX_BUF_SIZE,
 | 
			
		||||
                         uart_error_cb,
 | 
			
		||||
                         APP_IRQ_PRIORITY_LOW,
 | 
			
		||||
                         err_code);
 | 
			
		||||
 | 
			
		||||
    initialized = true;
 | 
			
		||||
 | 
			
		||||
    return err_code;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//lint -save -e530 -e64
 | 
			
		||||
void log_uart_printf(const char * format_msg, ...)
 | 
			
		||||
{
 | 
			
		||||
    va_list p_args;
 | 
			
		||||
    va_start(p_args, format_msg);
 | 
			
		||||
    (void)vprintf(format_msg, p_args);
 | 
			
		||||
    va_end(p_args);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
__INLINE void log_uart_write_string_many(int num_args, ...)
 | 
			
		||||
{
 | 
			
		||||
    const char* msg;
 | 
			
		||||
    va_list p_args;
 | 
			
		||||
    va_start(p_args, num_args);
 | 
			
		||||
 | 
			
		||||
    for (int i = 0; i < num_args; i++)
 | 
			
		||||
    {
 | 
			
		||||
        msg = va_arg(p_args, const char*);
 | 
			
		||||
        log_uart_write_string(msg);
 | 
			
		||||
    }
 | 
			
		||||
    va_end(p_args);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
__INLINE void log_uart_write_string(const char* msg)
 | 
			
		||||
{
 | 
			
		||||
    while( *msg )
 | 
			
		||||
    {
 | 
			
		||||
        (void)app_uart_put(*msg++);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
//lint -restore
 | 
			
		||||
 | 
			
		||||
void log_uart_write_hex(uint32_t value)
 | 
			
		||||
{
 | 
			
		||||
    uint8_t nibble;
 | 
			
		||||
    uint8_t i = 8;
 | 
			
		||||
 | 
			
		||||
    (void)app_uart_put('0');
 | 
			
		||||
    (void)app_uart_put('x');
 | 
			
		||||
    while( i-- != 0 )
 | 
			
		||||
    {
 | 
			
		||||
        nibble = (value >> (4 * i)) & 0x0F;
 | 
			
		||||
        (void)app_uart_put( (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble) );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void log_uart_write_hex_char(uint8_t c)
 | 
			
		||||
{
 | 
			
		||||
    uint8_t nibble;
 | 
			
		||||
    uint8_t i = 2;
 | 
			
		||||
 | 
			
		||||
    while( i-- != 0 )
 | 
			
		||||
    {
 | 
			
		||||
        nibble = (c >> (4 * i)) & 0x0F;
 | 
			
		||||
        (void)app_uart_put( (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble) );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
__INLINE int log_uart_has_input()
 | 
			
		||||
{
 | 
			
		||||
    if (m_uart_has_input) return 1;
 | 
			
		||||
    if (app_uart_get(&m_uart_data) == NRF_SUCCESS)
 | 
			
		||||
    {
 | 
			
		||||
        m_uart_has_input = true;
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t log_uart_read_input(char * c)
 | 
			
		||||
{
 | 
			
		||||
    if (m_uart_has_input)
 | 
			
		||||
    {
 | 
			
		||||
        *c = (char)m_uart_data;
 | 
			
		||||
        m_uart_has_input = false;
 | 
			
		||||
        return NRF_SUCCESS;
 | 
			
		||||
    }
 | 
			
		||||
    if (app_uart_get((uint8_t *)c) == NRF_SUCCESS)
 | 
			
		||||
    {
 | 
			
		||||
        return NRF_SUCCESS;
 | 
			
		||||
    }
 | 
			
		||||
    return NRF_ERROR_NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#elif defined(NRF_LOG_USES_RAW_UART) && NRF_LOG_USES_RAW_UART == 1
 | 
			
		||||
 | 
			
		||||
#include "app_uart.h"
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include "bsp.h"
 | 
			
		||||
 | 
			
		||||
uint32_t log_raw_uart_init()
 | 
			
		||||
{
 | 
			
		||||
    // Disable UART
 | 
			
		||||
    NRF_UART0->ENABLE = UART_ENABLE_ENABLE_Disabled;
 | 
			
		||||
 | 
			
		||||
    // Configure RX/TX pins
 | 
			
		||||
    nrf_gpio_cfg_output( TX_PIN_NUMBER );
 | 
			
		||||
    nrf_gpio_cfg_input(RX_PIN_NUMBER, NRF_GPIO_PIN_NOPULL);
 | 
			
		||||
 | 
			
		||||
    // Set a default baud rate of UART0_CONFIG_BAUDRATE
 | 
			
		||||
    NRF_UART0->PSELTXD  = TX_PIN_NUMBER;
 | 
			
		||||
    NRF_UART0->BAUDRATE = UART0_CONFIG_BAUDRATE;
 | 
			
		||||
 | 
			
		||||
    NRF_UART0->PSELRTS  = 0xFFFFFFFF;
 | 
			
		||||
    NRF_UART0->PSELCTS  = 0xFFFFFFFF;
 | 
			
		||||
 | 
			
		||||
    // Disable parity and interrupt
 | 
			
		||||
    NRF_UART0->CONFIG   = (UART_CONFIG_PARITY_Excluded  << UART_CONFIG_PARITY_Pos );
 | 
			
		||||
    NRF_UART0->CONFIG  |= (UART_CONFIG_HWFC_Disabled    << UART_CONFIG_HWFC_Pos   );
 | 
			
		||||
 | 
			
		||||
    // Re-enable the UART
 | 
			
		||||
    NRF_UART0->ENABLE           = UART_ENABLE_ENABLE_Enabled;
 | 
			
		||||
    NRF_UART0->INTENSET         = 0;
 | 
			
		||||
    NRF_UART0->TASKS_STARTTX    = 1;
 | 
			
		||||
    NRF_UART0->TASKS_STARTRX    = 1;
 | 
			
		||||
 | 
			
		||||
    return NRF_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void log_raw_uart_printf(const char * format_msg, ...)
 | 
			
		||||
{
 | 
			
		||||
    static char buffer[256];
 | 
			
		||||
 | 
			
		||||
    va_list p_args;
 | 
			
		||||
    va_start(p_args, format_msg);
 | 
			
		||||
    sprintf(buffer, format_msg, p_args);
 | 
			
		||||
    va_end(p_args);
 | 
			
		||||
 | 
			
		||||
    log_raw_uart_write_string(buffer);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
__INLINE void log_raw_uart_write_char(const char c)
 | 
			
		||||
{
 | 
			
		||||
    NRF_UART0->TXD = c;
 | 
			
		||||
    while( NRF_UART0->EVENTS_TXDRDY != 1 );
 | 
			
		||||
    NRF_UART0->EVENTS_TXDRDY = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
__INLINE void log_raw_uart_write_string_many(int num_args, ...)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    const char* msg;
 | 
			
		||||
    va_list p_args;
 | 
			
		||||
    va_start(p_args, num_args);
 | 
			
		||||
 | 
			
		||||
    for (int i = 0; i < num_args; i++)
 | 
			
		||||
    {
 | 
			
		||||
        msg = va_arg(p_args, const char*);
 | 
			
		||||
        log_raw_uart_write_string(msg);
 | 
			
		||||
    }
 | 
			
		||||
    va_end(p_args);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
__INLINE void log_raw_uart_write_string(const char* msg)
 | 
			
		||||
{
 | 
			
		||||
    while( *msg )
 | 
			
		||||
    {
 | 
			
		||||
        NRF_UART0->TXD = *msg++;
 | 
			
		||||
        while( NRF_UART0->EVENTS_TXDRDY != 1 );
 | 
			
		||||
        NRF_UART0->EVENTS_TXDRDY = 0;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void log_raw_uart_write_hex(uint32_t value)
 | 
			
		||||
{
 | 
			
		||||
    uint8_t nibble;
 | 
			
		||||
    uint8_t i = 8;
 | 
			
		||||
 | 
			
		||||
    log_raw_uart_write_string( "0x" );
 | 
			
		||||
    while( i-- != 0 )
 | 
			
		||||
    {
 | 
			
		||||
        nibble = (value >> (4 * i)) & 0x0F;
 | 
			
		||||
        log_raw_uart_write_char( (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble) );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void log_raw_uart_write_hex_char(uint8_t c)
 | 
			
		||||
{
 | 
			
		||||
    uint8_t nibble;
 | 
			
		||||
    uint8_t i = 2;
 | 
			
		||||
 | 
			
		||||
    while( i-- != 0 )
 | 
			
		||||
    {
 | 
			
		||||
        nibble = (c >> (4 * i)) & 0x0F;
 | 
			
		||||
        log_raw_uart_write_hex( (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble) );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
__INLINE int log_raw_uart_has_input()
 | 
			
		||||
{
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t log_raw_uart_read_input(char * c)
 | 
			
		||||
{
 | 
			
		||||
    return NRF_ERROR_NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // NRF_LOG_USES_RAW_UART == 1
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const char* log_hex_char(const char c)
 | 
			
		||||
{
 | 
			
		||||
    static volatile char hex_string[3];
 | 
			
		||||
    hex_string[2] = 0; // Null termination
 | 
			
		||||
    uint8_t nibble;
 | 
			
		||||
    uint8_t i = 2;
 | 
			
		||||
    while(i-- != 0)
 | 
			
		||||
    {
 | 
			
		||||
        nibble = (c >> (4 * i)) & 0x0F;
 | 
			
		||||
        hex_string[1-i] = (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble);
 | 
			
		||||
    }
 | 
			
		||||
    return (const char*) hex_string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* log_hex(uint32_t value)
 | 
			
		||||
{
 | 
			
		||||
    static volatile char hex_string[11];
 | 
			
		||||
    hex_string[0] = '0';
 | 
			
		||||
    hex_string[1] = 'x';
 | 
			
		||||
    hex_string[10] = 0;
 | 
			
		||||
    uint8_t nibble;
 | 
			
		||||
    uint8_t i = 8;
 | 
			
		||||
 | 
			
		||||
    while(i-- != 0)
 | 
			
		||||
    {
 | 
			
		||||
        nibble = (value >> (4 * i)) & 0x0F;
 | 
			
		||||
        hex_string[9-i] = (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return (const char*)hex_string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										699
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/nrf_log.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										699
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/nrf_log.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,699 @@
 | 
			
		||||
#ifndef NRF_LOG_H_
 | 
			
		||||
#define NRF_LOG_H_
 | 
			
		||||
 | 
			
		||||
#ifndef DOXYGEN
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <stdarg.h>
 | 
			
		||||
#include <app_util.h>
 | 
			
		||||
 | 
			
		||||
#ifndef NRF_LOG_USES_RTT
 | 
			
		||||
#define NRF_LOG_USES_RTT 0
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef NRF_LOG_USES_UART
 | 
			
		||||
#define NRF_LOG_USES_UART 0
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef NRF_LOG_USES_RAW_UART
 | 
			
		||||
#define NRF_LOG_USES_RAW_UART 0
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef NRF_LOG_USES_COLORS
 | 
			
		||||
    #define NRF_LOG_USES_COLORS 1
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if NRF_LOG_USES_COLORS == 1
 | 
			
		||||
    #define NRF_LOG_COLOR_DEFAULT  "\x1B[0m"
 | 
			
		||||
    #define NRF_LOG_COLOR_BLACK    "\x1B[1;30m"
 | 
			
		||||
    #define NRF_LOG_COLOR_RED      "\x1B[1;31m"
 | 
			
		||||
    #define NRF_LOG_COLOR_GREEN    "\x1B[1;32m"
 | 
			
		||||
    #define NRF_LOG_COLOR_YELLOW   "\x1B[1;33m"
 | 
			
		||||
    #define NRF_LOG_COLOR_BLUE     "\x1B[1;34m"
 | 
			
		||||
    #define NRF_LOG_COLOR_MAGENTA  "\x1B[1;35m"
 | 
			
		||||
    #define NRF_LOG_COLOR_CYAN     "\x1B[1;36m"
 | 
			
		||||
    #define NRF_LOG_COLOR_WHITE    "\x1B[1;37m"
 | 
			
		||||
#else
 | 
			
		||||
    #define NRF_LOG_COLOR_DEFAULT
 | 
			
		||||
    #define NRF_LOG_COLOR_BLACK
 | 
			
		||||
    #define NRF_LOG_COLOR_RED
 | 
			
		||||
    #define NRF_LOG_COLOR_GREEN
 | 
			
		||||
    #define NRF_LOG_COLOR_YELLOW
 | 
			
		||||
    #define NRF_LOG_COLOR_BLUE
 | 
			
		||||
    #define NRF_LOG_COLOR_MAGENTA
 | 
			
		||||
    #define NRF_LOG_COLOR_CYAN
 | 
			
		||||
    #define NRF_LOG_COLOR_WHITE
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if defined(NRF_LOG_USES_RTT) && NRF_LOG_USES_RTT == 1
 | 
			
		||||
 | 
			
		||||
#define LOG_TERMINAL_NORMAL         (0)
 | 
			
		||||
#define LOG_TERMINAL_ERROR          (1)
 | 
			
		||||
#define LOG_TERMINAL_INPUT          (0)
 | 
			
		||||
 | 
			
		||||
/**@brief Function for initializing the SEGGER RTT logger.
 | 
			
		||||
 *
 | 
			
		||||
 * @details See <a href="https://www.segger.com/jlink-rtt.html" target="_blank">segger.com</a>
 | 
			
		||||
 *          for information about SEGGER Real Time Transfer (RTT).
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_RTT is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use the macro @ref NRF_LOG_INIT instead.
 | 
			
		||||
 *
 | 
			
		||||
 * @retval     NRF_SUCCESS     If initialization was successful.
 | 
			
		||||
 * @retval     NRF_ERROR       Otherwise.
 | 
			
		||||
 */
 | 
			
		||||
uint32_t log_rtt_init(void);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for writing a printf string using RTT.
 | 
			
		||||
 *
 | 
			
		||||
 * @details The printf implementation in SEGGER's RTT is more efficient than
 | 
			
		||||
 * the standard implementation. However, printf requires more processor time
 | 
			
		||||
 * than other logging functions. Therefore, applications that require logging
 | 
			
		||||
 * but need it to interfere as little as possible with the execution, should
 | 
			
		||||
 * avoid using printf.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_RTT is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use one of the following macros instead:
 | 
			
		||||
 * - @ref NRF_LOG_PRINTF
 | 
			
		||||
 * - @ref NRF_LOG_PRINTF_DEBUG
 | 
			
		||||
 * - @ref NRF_LOG_PRINTF_ERROR
 | 
			
		||||
 *
 | 
			
		||||
 * @param   terminal_index  Segger RTT terminal index to use as output.
 | 
			
		||||
 * @param   format_msg      Printf format string.
 | 
			
		||||
 */
 | 
			
		||||
void log_rtt_printf(int terminal_index, char * format_msg, ...);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for writing a string using RTT.
 | 
			
		||||
 *
 | 
			
		||||
 * @details The string to write must be null-terminated, but the null termination will not be stored
 | 
			
		||||
 *          in the ring buffer.
 | 
			
		||||
 *          The impact of running this function should be very low compared to writing to UART.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_RTT is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use one of the following macros instead:
 | 
			
		||||
 * - @ref NRF_LOG
 | 
			
		||||
 * - @ref NRF_LOG_DEBUG
 | 
			
		||||
 * - @ref NRF_LOG_ERROR
 | 
			
		||||
 *
 | 
			
		||||
 * @param   terminal_index  Segger RTT terminal index to use as output.
 | 
			
		||||
 * @param   num_args        Number of arguments.
 | 
			
		||||
 */
 | 
			
		||||
void log_rtt_write_string(int terminal_index, int num_args, ...);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for writing an integer as HEX using RTT.
 | 
			
		||||
 *
 | 
			
		||||
 * The output data is formatted as, for example, 0x89ABCDEF.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_RTT is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use one of the following macros instead:
 | 
			
		||||
 * - @ref NRF_LOG_HEX
 | 
			
		||||
 * - @ref NRF_LOG_HEX_DEBUG
 | 
			
		||||
 * - @ref NRF_LOG_HEX_ERROR
 | 
			
		||||
 *
 | 
			
		||||
 * @param   terminal_index  Segger RTT terminal index to use as output.
 | 
			
		||||
 * @param   value           Integer value to be printed as HEX.
 | 
			
		||||
 */
 | 
			
		||||
void log_rtt_write_hex(int terminal_index, uint32_t value);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for writing a single character as HEX using RTT.
 | 
			
		||||
 *
 | 
			
		||||
 * The output string is formatted as, for example, AA.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_RTT is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use one of the following macros instead:
 | 
			
		||||
 * - @ref NRF_LOG_HEX_CHAR
 | 
			
		||||
 * - @ref NRF_LOG_HEX_CHAR_DEBUG
 | 
			
		||||
 * - @ref NRF_LOG_HEX_CHAR_ERROR
 | 
			
		||||
 *
 | 
			
		||||
 * @param   terminal_index  Segger RTT terminal index to use as output.
 | 
			
		||||
 * @param   value           Character to print as HEX.
 | 
			
		||||
 */
 | 
			
		||||
void log_rtt_write_hex_char(int terminal_index, uint8_t value);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for checking if data is available in the input buffer.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_RTT is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use @ref NRF_LOG_HAS_INPUT instead.
 | 
			
		||||
 *
 | 
			
		||||
 * @retval      1 If characters are available to read.
 | 
			
		||||
 * @retval      0 If no characters are available.
 | 
			
		||||
 */
 | 
			
		||||
int log_rtt_has_input(void);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for reading one character from the input buffer.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[out] p_char  Pointer where to store the character.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_RTT is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use @ref NRF_LOG_READ_INPUT instead.
 | 
			
		||||
 *
 | 
			
		||||
 * @retval      NRF_SUCCESS If the character was read out.
 | 
			
		||||
 * @retval      NRF_ERROR_INVALID_DATA If no character could be read.
 | 
			
		||||
 */
 | 
			
		||||
uint32_t log_rtt_read_input(char* p_char);
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_INIT()                  log_rtt_init()                                                                          /*!< Initialize the module. */
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_PRINTF(...)             log_rtt_printf(LOG_TERMINAL_NORMAL, ##__VA_ARGS__)                                      /*!< Print a log message using printf. */
 | 
			
		||||
#define NRF_LOG_PRINTF_DEBUG(...)       log_rtt_printf(LOG_TERMINAL_NORMAL, ##__VA_ARGS__)                                      /*!< If DEBUG is set, print a log message using printf. */
 | 
			
		||||
#define NRF_LOG_PRINTF_ERROR(...)       log_rtt_printf(LOG_TERMINAL_ERROR, ##__VA_ARGS__)                                       /*!< Print a log message using printf to the error stream. */
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG(...)                    log_rtt_write_string(LOG_TERMINAL_NORMAL, NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__)      /*!< Print a log message. The input string must be null-terminated. */
 | 
			
		||||
#define NRF_LOG_DEBUG(...)              log_rtt_write_string(LOG_TERMINAL_NORMAL, NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__)      /*!< If DEBUG is set, print a log message. The input string must be null-terminated. */
 | 
			
		||||
#define NRF_LOG_ERROR(...)              log_rtt_write_string(LOG_TERMINAL_ERROR, NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__)       /*!< Print a log message to the error stream. The input string must be null-terminated. */
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_HEX(val)                log_rtt_write_hex(LOG_TERMINAL_NORMAL, val)                                             /*!< Log an integer as HEX value (example output: 0x89ABCDEF). */
 | 
			
		||||
#define NRF_LOG_HEX_DEBUG(val)          log_rtt_write_hex(LOG_TERMINAL_NORMAL, val)                                             /*!< If DEBUG is set, log an integer as HEX value (example output: 0x89ABCDEF). */
 | 
			
		||||
#define NRF_LOG_HEX_ERROR(val)          log_rtt_write_hex(LOG_TERMINAL_ERROR, val)                                              /*!< Log an integer as HEX value to the error stream (example output: 0x89ABCDEF). */
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_HEX_CHAR(val)           log_rtt_write_hex_char(LOG_TERMINAL_NORMAL, val)                                        /*!< Log a character as HEX value (example output: AA). */
 | 
			
		||||
#define NRF_LOG_HEX_CHAR_DEBUG(val)     log_rtt_write_hex_char(LOG_TERMINAL_NORMAL, val)                                        /*!< If DEBUG is set, log a character as HEX value (example output: AA). */
 | 
			
		||||
#define NRF_LOG_HEX_CHAR_ERROR(val)     log_rtt_write_hex_char(LOG_TERMINAL_ERROR, val)                                         /*!< Log a character as HEX value to the error stream (example output: AA). */
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_HAS_INPUT()             log_rtt_has_input()                                                                     /*!< Check if the input buffer has unconsumed characters. */
 | 
			
		||||
#define NRF_LOG_READ_INPUT(p_char)      log_rtt_read_input(p_char)                                                              /*!< Consume a character from the input buffer. */
 | 
			
		||||
 | 
			
		||||
#if !defined(DEBUG) && !defined(DOXYGEN)
 | 
			
		||||
 | 
			
		||||
#undef NRF_LOG_DEBUG
 | 
			
		||||
#define NRF_LOG_DEBUG(...)
 | 
			
		||||
 | 
			
		||||
#undef NRF_LOG_STR_DEBUG
 | 
			
		||||
#define NRF_LOG_STR_DEBUG(...)
 | 
			
		||||
 | 
			
		||||
#undef NRF_LOG_HEX_DEBUG
 | 
			
		||||
#define NRF_LOG_HEX_DEBUG(...)
 | 
			
		||||
 | 
			
		||||
#undef NRF_LOG_HEX_CHAR_DEBUG
 | 
			
		||||
#define NRF_LOG_HEX_CHAR_DEBUG(...)
 | 
			
		||||
 | 
			
		||||
#endif // !defined(DEBUG) && !defined(DOXYGEN)
 | 
			
		||||
 | 
			
		||||
#elif defined(NRF_LOG_USES_UART) && NRF_LOG_USES_UART == 1
 | 
			
		||||
 | 
			
		||||
/**@brief Function for initializing the UART logger.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use the macro @ref NRF_LOG_INIT instead.
 | 
			
		||||
 *
 | 
			
		||||
 * @retval     NRF_SUCCESS     If initialization was successful.
 | 
			
		||||
 * @retval     NRF_ERROR       Otherwise.
 | 
			
		||||
 */
 | 
			
		||||
uint32_t log_uart_init(void);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for logging a printf string to UART.
 | 
			
		||||
 *
 | 
			
		||||
 * @details  Printf requires more processor time
 | 
			
		||||
 * than other logging functions. Therefore, applications that require logging
 | 
			
		||||
 * but need it to interfere as little as possible with the execution, should
 | 
			
		||||
 * avoid using printf.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note This function is non-blocking. If too much data is sent to the UART,
 | 
			
		||||
 *          some characters might be skipped.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use one of the following macros instead:
 | 
			
		||||
 * - @ref NRF_LOG_PRINTF
 | 
			
		||||
 * - @ref NRF_LOG_PRINTF_DEBUG
 | 
			
		||||
 * - @ref NRF_LOG_PRINTF_ERROR
 | 
			
		||||
 *
 | 
			
		||||
 * @param  format_msg      Printf format string.
 | 
			
		||||
 */
 | 
			
		||||
void log_uart_printf(const char * format_msg, ...);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for logging a single character to UART.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @param  c     Character.
 | 
			
		||||
 */
 | 
			
		||||
void log_uart_write_char(const char c);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for logging null-terminated strings to UART.
 | 
			
		||||
 *
 | 
			
		||||
 * @details This function is more efficient than using printf.
 | 
			
		||||
 *          The null termination will not be logged.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use one of the following macros instead:
 | 
			
		||||
 * - @ref NRF_LOG
 | 
			
		||||
 * - @ref NRF_LOG_DEBUG
 | 
			
		||||
 * - @ref NRF_LOG_ERROR
 | 
			
		||||
 *
 | 
			
		||||
 * @param  num_args     Number of arguments.
 | 
			
		||||
 */
 | 
			
		||||
void log_uart_write_string_many(int num_args, ...);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for logging a null-terminated string to UART.
 | 
			
		||||
 *
 | 
			
		||||
 * @details This function is more efficient than using printf.
 | 
			
		||||
 *          The null termination will not be logged.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use one of the following macros instead:
 | 
			
		||||
 * - @ref NRF_LOG
 | 
			
		||||
 * - @ref NRF_LOG_DEBUG
 | 
			
		||||
 * - @ref NRF_LOG_ERROR
 | 
			
		||||
 *
 | 
			
		||||
 * @param  msg     Null-terminated string.
 | 
			
		||||
 */
 | 
			
		||||
void log_uart_write_string(const char* msg);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for logging an integer value as HEX to UART.
 | 
			
		||||
 *
 | 
			
		||||
 * @details The output data is formatted as, for example, 0x89ABCDEF.
 | 
			
		||||
 * This function is more efficient than printf.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note This function is non-blocking. If too much data is sent to the UART,
 | 
			
		||||
 *          some characters might be skipped.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use one of the following macros instead:
 | 
			
		||||
 * - @ref NRF_LOG_HEX
 | 
			
		||||
 * - @ref NRF_LOG_HEX_DEBUG
 | 
			
		||||
 * - @ref NRF_LOG_HEX_ERROR
 | 
			
		||||
 *
 | 
			
		||||
 * @param   value   Integer value to be printed as HEX.
 | 
			
		||||
 */
 | 
			
		||||
void log_uart_write_hex(uint32_t value);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for logging a single character as HEX to UART.
 | 
			
		||||
 *
 | 
			
		||||
 * @details The output string is formatted as, for example, AA.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note This function is non-blocking. If too much data is sent to the UART,
 | 
			
		||||
 *          some characters might be skipped.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use one of the following macros instead:
 | 
			
		||||
 * - @ref NRF_LOG_HEX_CHAR
 | 
			
		||||
 * - @ref NRF_LOG_HEX_CHAR_DEBUG
 | 
			
		||||
 * - @ref NRF_LOG_HEX_CHAR_ERROR
 | 
			
		||||
 *
 | 
			
		||||
 * @param c Character.
 | 
			
		||||
  */
 | 
			
		||||
void log_uart_write_hex_char(uint8_t c);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for checking if data is available in the input buffer.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use @ref NRF_LOG_HAS_INPUT instead.
 | 
			
		||||
 *
 | 
			
		||||
 * @retval      1 If characters are available to read.
 | 
			
		||||
 * @retval      0 If no characters are available.
 | 
			
		||||
 */
 | 
			
		||||
int log_uart_has_input(void);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for reading one character from the input buffer.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[out]   p_char  Pointer where to store the character.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use NRF_LOG_READ_INPUT instead.
 | 
			
		||||
 *
 | 
			
		||||
 * @retval      NRF_SUCCESS If the character was read out.
 | 
			
		||||
 * @retval      NRF_ERROR_INVALID_DATA If no character could be read.
 | 
			
		||||
 */
 | 
			
		||||
uint32_t log_uart_read_input(char* p_char);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_INIT()                  log_uart_init()                                                         /*!< Initialize the module. */
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_PRINTF(...)             log_uart_printf(__VA_ARGS__)                                            /*!< Print a log message using printf. */
 | 
			
		||||
#define NRF_LOG_PRINTF_DEBUG(...)       log_uart_printf(__VA_ARGS__)                                            /*!< If DEBUG is set, print a log message using printf. */
 | 
			
		||||
#define NRF_LOG_PRINTF_ERROR(...)       log_uart_printf(__VA_ARGS__)                                            /*!< Print a log message using printf to the error stream. */
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG(...)                    log_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__)     /*!< Print a log message. The input string must be null-terminated. */
 | 
			
		||||
#define NRF_LOG_DEBUG(...)              log_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__)     /*!< If DEBUG is set, print a log message. The input string must be null-terminated. */
 | 
			
		||||
#define NRF_LOG_ERROR(...)              log_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__)     /*!< Print a log message to the error stream. The input string must be null-terminated. */
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_HEX(val)                log_uart_write_hex(val)                                                 /*!< Log an integer as HEX value (example output: 0x89ABCDEF). */
 | 
			
		||||
#define NRF_LOG_HEX_DEBUG(val)          log_uart_write_hex(val)                                                 /*!< If DEBUG is set, log an integer as HEX value (example output: 0x89ABCDEF). */
 | 
			
		||||
#define NRF_LOG_HEX_ERROR(val)          log_uart_write_hex(val)                                                 /*!< Log an integer as HEX value to the error stream (example output: 0x89ABCDEF). */
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_HEX_CHAR(val)           log_uart_write_hex_char(val)                                            /*!< Log a character as HEX value (example output: AA). */
 | 
			
		||||
#define NRF_LOG_HEX_CHAR_DEBUG(val)     log_uart_write_hex_char(val)                                            /*!< If DEBUG is set, log a character as HEX value (example output: AA). */
 | 
			
		||||
#define NRF_LOG_HEX_CHAR_ERROR(val)     log_uart_write_hex_char(val)                                            /*!< Log a character as HEX value to the error stream (example output: AA). */
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_HAS_INPUT()             log_uart_has_input()                                                    /*!< Check if the input buffer has unconsumed characters. */
 | 
			
		||||
#define NRF_LOG_READ_INPUT(p_char)      log_uart_read_input(p_char)                                             /*!< Consume a character from the input buffer. */
 | 
			
		||||
 | 
			
		||||
#if !defined(DEBUG) && !defined(DOXYGEN)
 | 
			
		||||
 | 
			
		||||
#undef NRF_LOG_DEBUG
 | 
			
		||||
#define NRF_LOG_DEBUG(...)
 | 
			
		||||
 | 
			
		||||
#undef NRF_LOG_PRINTF_DEBUG
 | 
			
		||||
#define NRF_LOG_PRINTF_DEBUG(...)
 | 
			
		||||
 | 
			
		||||
#undef NRF_LOG_STR_DEBUG
 | 
			
		||||
#define NRF_LOG_STR_DEBUG(...)
 | 
			
		||||
 | 
			
		||||
#undef NRF_LOG_HEX_DEBUG
 | 
			
		||||
#define NRF_LOG_HEX_DEBUG(...)
 | 
			
		||||
 | 
			
		||||
#undef NRF_LOG_HEX_CHAR_DEBUG
 | 
			
		||||
#define NRF_LOG_HEX_CHAR_DEBUG(...)
 | 
			
		||||
 | 
			
		||||
#endif // !defined(DEBUG) && !defined(DOXYGEN)
 | 
			
		||||
 | 
			
		||||
#elif defined(NRF_LOG_USES_RAW_UART) && NRF_LOG_USES_RAW_UART == 1
 | 
			
		||||
 | 
			
		||||
/**@brief Function for initializing the raw UART logger.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use the macro @ref NRF_LOG_INIT instead.
 | 
			
		||||
 *
 | 
			
		||||
 * @retval     NRF_SUCCESS     If initialization was successful.
 | 
			
		||||
 * @retval     NRF_ERROR       Otherwise.
 | 
			
		||||
 */
 | 
			
		||||
uint32_t log_raw_uart_init(void);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for logging a printf string to raw UART.
 | 
			
		||||
 *
 | 
			
		||||
 * @details  Printf requires more processor time
 | 
			
		||||
 * than other logging functions. Therefore, applications that require logging
 | 
			
		||||
 * but need it to interfere as little as possible with the execution, should
 | 
			
		||||
 * avoid using printf.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note This function is non-blocking. If too much data is sent to the UART,
 | 
			
		||||
 *          some characters might be skipped.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use one of the following macros instead:
 | 
			
		||||
 * - @ref NRF_LOG_PRINTF
 | 
			
		||||
 * - @ref NRF_LOG_PRINTF_DEBUG
 | 
			
		||||
 * - @ref NRF_LOG_PRINTF_ERROR
 | 
			
		||||
 *
 | 
			
		||||
 * @param  format_msg      Printf format string.
 | 
			
		||||
 */
 | 
			
		||||
void log_raw_uart_printf(const char * format_msg, ...);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for logging a single character to raw UART.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @param  c     Character.
 | 
			
		||||
 */
 | 
			
		||||
void log_raw_uart_write_char(const char c);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for logging null-terminated strings to raw UART.
 | 
			
		||||
 *
 | 
			
		||||
 * @details This function is more efficient than using printf.
 | 
			
		||||
 *          The null termination will not be logged.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use one of the following macros instead:
 | 
			
		||||
 * - @ref NRF_LOG
 | 
			
		||||
 * - @ref NRF_LOG_DEBUG
 | 
			
		||||
 * - @ref NRF_LOG_ERROR
 | 
			
		||||
 *
 | 
			
		||||
 * @param  num_args     Number of arguments.
 | 
			
		||||
 */
 | 
			
		||||
void log_raw_uart_write_string_many(int num_args, ...);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for logging a null-terminated string to raw UART.
 | 
			
		||||
 *
 | 
			
		||||
 * @details This function is more efficient than using printf.
 | 
			
		||||
 *          The null termination will not be logged.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use one of the following macros instead:
 | 
			
		||||
 * - @ref NRF_LOG
 | 
			
		||||
 * - @ref NRF_LOG_DEBUG
 | 
			
		||||
 * - @ref NRF_LOG_ERROR
 | 
			
		||||
 *
 | 
			
		||||
 * @param  str     Null-terminated string.
 | 
			
		||||
 */
 | 
			
		||||
void log_raw_uart_write_string(const char * str);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for logging an integer value as HEX to raw UART.
 | 
			
		||||
 *
 | 
			
		||||
 * @details The output data is formatted as, for example, 0x89ABCDEF.
 | 
			
		||||
 * This function is more efficient than printf.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note This function is non-blocking. If too much data is sent to the UART,
 | 
			
		||||
 *          some characters might be skipped.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use one of the following macros instead:
 | 
			
		||||
 * - @ref NRF_LOG_HEX
 | 
			
		||||
 * - @ref NRF_LOG_HEX_DEBUG
 | 
			
		||||
 * - @ref NRF_LOG_HEX_ERROR
 | 
			
		||||
 *
 | 
			
		||||
 * @param   value   Integer value to be printed as HEX.
 | 
			
		||||
 */
 | 
			
		||||
void log_raw_uart_write_hex(uint32_t value);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for logging a single character as HEX to raw UART.
 | 
			
		||||
 *
 | 
			
		||||
 * @details The output string is formatted as, for example, AA.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note This function is non-blocking. If too much data is sent to the UART,
 | 
			
		||||
 *          some characters might be skipped.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use one of the following macros instead:
 | 
			
		||||
 * - @ref NRF_LOG_HEX_CHAR
 | 
			
		||||
 * - @ref NRF_LOG_HEX_CHAR_DEBUG
 | 
			
		||||
 * - @ref NRF_LOG_HEX_CHAR_ERROR
 | 
			
		||||
 *
 | 
			
		||||
 * @param c Character.
 | 
			
		||||
  */
 | 
			
		||||
void log_raw_uart_write_hex_char(uint8_t c);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for checking if data is available in the input buffer.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use @ref NRF_LOG_HAS_INPUT instead.
 | 
			
		||||
 *
 | 
			
		||||
 * @retval      1 If characters are available to read.
 | 
			
		||||
 * @retval      0 If no characters are available.
 | 
			
		||||
 */
 | 
			
		||||
int log_raw_uart_has_input(void);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for reading one character from the input buffer.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[out]   p_char  Pointer where to store the character.
 | 
			
		||||
 *
 | 
			
		||||
 * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Do not call this function directly. Use NRF_LOG_READ_INPUT instead.
 | 
			
		||||
 *
 | 
			
		||||
 * @retval      NRF_SUCCESS If the character was read out.
 | 
			
		||||
 * @retval      NRF_ERROR_INVALID_DATA If no character could be read.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
uint32_t log_raw_uart_read_input(char* p_char);
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_INIT()                  log_raw_uart_init()                                                         /*!< nitialize the module. */
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_PRINTF(...)             log_raw_uart_printf(__VA_ARGS__)                                            /*!< Print a log message using printf. */
 | 
			
		||||
#define NRF_LOG_PRINTF_DEBUG(...)       log_raw_uart_printf(__VA_ARGS__)                                            /*!< If DEBUG is set, print a log message using printf. */
 | 
			
		||||
#define NRF_LOG_PRINTF_ERROR(...)       log_raw_uart_printf(__VA_ARGS__)                                            /*!< Print a log message using printf to the error stream. */
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG(...)                    log_raw_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__)     /*!< Print a log message. The input string must be null-terminated. */
 | 
			
		||||
#define NRF_LOG_DEBUG(...)              log_raw_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__)     /*!< If DEBUG is set, print a log message. The input string must be null-terminated. */
 | 
			
		||||
#define NRF_LOG_ERROR(...)              log_raw_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__)     /*!< Print a log message to the error stream. The input string must be null-terminated. */
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_HEX(val)                log_raw_uart_write_hex(val)                                                 /*!< Log an integer as HEX value (example output: 0x89ABCDEF). */
 | 
			
		||||
#define NRF_LOG_HEX_DEBUG(val)          log_raw_uart_write_hex(val)                                                 /*!< If DEBUG is set, log an integer as HEX value (example output: 0x89ABCDEF). */
 | 
			
		||||
#define NRF_LOG_HEX_ERROR(val)          log_raw_uart_write_hex(val)                                                 /*!< Log an integer as HEX value to the error stream (example output: 0x89ABCDEF). */
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_HEX_CHAR(val)           log_raw_uart_write_hex_char(val)                                            /*!< Log a character as HEX value (example output: AA). */
 | 
			
		||||
#define NRF_LOG_HEX_CHAR_DEBUG(val)     log_raw_uart_write_hex_char(val)                                            /*!< If DEBUG is set, log a character as HEX value (example output: AA). */
 | 
			
		||||
#define NRF_LOG_HEX_CHAR_ERROR(val)     log_raw_uart_write_hex_char(val)                                            /*!< Log a character as HEX value to the error stream (example output: AA). */
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_HAS_INPUT()             log_raw_uart_has_input()                                                    /*!< Check if the input buffer has unconsumed characters. */
 | 
			
		||||
#define NRF_LOG_READ_INPUT(p_char)      log_raw_uart_read_input(p_char)                                             /*!< Consume a character from the input buffer. */
 | 
			
		||||
 | 
			
		||||
#if !defined(DEBUG) && !defined(DOXYGEN)
 | 
			
		||||
 | 
			
		||||
#undef NRF_LOG_DEBUG
 | 
			
		||||
#define NRF_LOG_DEBUG(...)
 | 
			
		||||
 | 
			
		||||
#undef NRF_LOG_PRINTF_DEBUG
 | 
			
		||||
#define NRF_LOG_PRINTF_DEBUG(...)
 | 
			
		||||
 | 
			
		||||
#undef NRF_LOG_STR_DEBUG
 | 
			
		||||
#define NRF_LOG_STR_DEBUG(...)
 | 
			
		||||
 | 
			
		||||
#undef NRF_LOG_HEX_DEBUG
 | 
			
		||||
#define NRF_LOG_HEX_DEBUG(...)
 | 
			
		||||
 | 
			
		||||
#undef NRF_LOG_HEX_CHAR_DEBUG
 | 
			
		||||
#define NRF_LOG_HEX_CHAR_DEBUG(...)
 | 
			
		||||
 | 
			
		||||
#endif // !defined(DEBUG) && !defined(DOXYGEN)
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
#include "nrf_error.h"
 | 
			
		||||
#include "nordic_common.h"
 | 
			
		||||
 | 
			
		||||
// Empty definitions
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_INIT()                 NRF_SUCCESS
 | 
			
		||||
#define NRF_LOG(...)
 | 
			
		||||
#define NRF_LOG_DEBUG(...)
 | 
			
		||||
#define NRF_LOG_ERROR(...)
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_PRINTF(...)
 | 
			
		||||
#define NRF_LOG_PRINTF_DEBUG(...)
 | 
			
		||||
#define NRF_LOG_PRINTF_ERROR(...)
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_HEX(val)
 | 
			
		||||
#define NRF_LOG_HEX_DEBUG(val)
 | 
			
		||||
#define NRF_LOG_HEX_ERROR(val)
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_HEX_CHAR(val)
 | 
			
		||||
#define NRF_LOG_HEX_CHAR_DEBUG(val)
 | 
			
		||||
#define NRF_LOG_HEX_CHAR_ERROR(val)
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_HAS_INPUT()              0
 | 
			
		||||
#define NRF_LOG_READ_INPUT(ignore)       NRF_SUCCESS
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/**@brief Function for writing HEX values.
 | 
			
		||||
 *
 | 
			
		||||
 * @note This function not thread-safe. It is written for convenience.
 | 
			
		||||
 *          If you log from different application contexts, you might get different results.
 | 
			
		||||
 *
 | 
			
		||||
 * @retval NULL By default.
 | 
			
		||||
 */
 | 
			
		||||
const char* log_hex(uint32_t value);
 | 
			
		||||
 | 
			
		||||
/**@brief Function for writing HEX characters.
 | 
			
		||||
 *
 | 
			
		||||
 * @note This function not thread-safe. It is written for convenience.
 | 
			
		||||
 *          If you log from different application contexts, you might get different results.
 | 
			
		||||
 *
 | 
			
		||||
 * @retval NULL By default.
 | 
			
		||||
 */
 | 
			
		||||
const char* log_hex_char(const char value);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#else // DOXYGEN
 | 
			
		||||
 | 
			
		||||
/** @defgroup nrf_log UART/RTT logging
 | 
			
		||||
 * @{
 | 
			
		||||
 * @ingroup app_common
 | 
			
		||||
 *
 | 
			
		||||
 * @brief Library to output logging information over SEGGER's Real Time Transfer
 | 
			
		||||
 *       (RTT), UART, or raw UART.
 | 
			
		||||
 *
 | 
			
		||||
 * This library provides macros that call the respective functions depending on
 | 
			
		||||
 * which protocol is used. Define LOG_USES_RTT=1 to enable logging over RTT,
 | 
			
		||||
 * NRF_LOG_USES_UART=1 to enable logging over UART, or NRF_LOG_USES_RAW_UART=1
 | 
			
		||||
 * to enable logging over raw UART. One of these defines must be set for any of
 | 
			
		||||
 * the macros to have effect. If you choose to not output information, all
 | 
			
		||||
 * logging macros can be left in the code without any cost; they will just be
 | 
			
		||||
 * ignored.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for initializing the logger.
 | 
			
		||||
 *
 | 
			
		||||
 * @retval     NRF_SUCCESS     If initialization was successful.
 | 
			
		||||
 * @retval     NRF_ERROR       Otherwise.
 | 
			
		||||
 */
 | 
			
		||||
uint32_t NRF_LOG_INIT(void);
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for logging null-terminated strings.
 | 
			
		||||
 *
 | 
			
		||||
 * @details This function is more efficient than using printf.
 | 
			
		||||
 *          The null termination will not be logged.
 | 
			
		||||
 *
 | 
			
		||||
 * @param  msg  Null-terminated string.
 | 
			
		||||
 */
 | 
			
		||||
void NRF_LOG(const char* msg);
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for logging a printf string.
 | 
			
		||||
 *
 | 
			
		||||
 * @details  Printf requires more processor time
 | 
			
		||||
 * than other logging functions. Therefore, applications that require logging
 | 
			
		||||
 * but need it to interfere as little as possible with the execution, should
 | 
			
		||||
 * avoid using printf.
 | 
			
		||||
 *
 | 
			
		||||
 * @note When NRF_LOG_USES_UART is set to 1, this macro is non-blocking.
 | 
			
		||||
 *       If too much data is sent, some characters might be skipped.
 | 
			
		||||
 *
 | 
			
		||||
 * @param  format_msg      Printf format string.
 | 
			
		||||
 * @param  ...             Additional arguments replacing format specifiers in format_msg.
 | 
			
		||||
 */
 | 
			
		||||
void NRF_LOG_PRINTF(const char * format_msg, ...);
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for logging an integer value as HEX.
 | 
			
		||||
 *
 | 
			
		||||
 * @details The output data is formatted as, for example, 0x89ABCDEF.
 | 
			
		||||
 * This function is more efficient than printf.
 | 
			
		||||
 *
 | 
			
		||||
 * @note When NRF_LOG_USES_UART is set to 1, this macro is non-blocking.
 | 
			
		||||
 *       If too much data is sent, some characters might be skipped.
 | 
			
		||||
 *
 | 
			
		||||
 * @param   value   Integer value to be printed as HEX.
 | 
			
		||||
 */
 | 
			
		||||
void NRF_LOG_HEX(uint32_t value);
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for logging a single character as HEX.
 | 
			
		||||
 *
 | 
			
		||||
 * @details The output string is formatted as, for example, AA.
 | 
			
		||||
 *
 | 
			
		||||
 * @note When NRF_LOG_USES_UART is set to 1, this macro is non-blocking.
 | 
			
		||||
 *       If too much data is sent, some characters might be skipped.
 | 
			
		||||
 *
 | 
			
		||||
 * @param c Character.
 | 
			
		||||
  */
 | 
			
		||||
void NRF_LOG_HEX_CHAR(uint8_t c);
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for checking if data is available in the input buffer.
 | 
			
		||||
 *
 | 
			
		||||
 * @note When NRF_LOG_USES_UART is set to 1, this macro is non-blocking.
 | 
			
		||||
 *       If too much data is sent, some characters might be skipped.
 | 
			
		||||
 *
 | 
			
		||||
 * @retval      1 If characters are available to read.
 | 
			
		||||
 * @retval      0 If no characters are available.
 | 
			
		||||
 */
 | 
			
		||||
int NRF_LOG_HAS_INPUT(void);
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for reading one character from the input buffer.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[out]   p_char  Pointer where to store the character.
 | 
			
		||||
 *
 | 
			
		||||
 * @retval      NRF_SUCCESS If the character was read out.
 | 
			
		||||
 * @retval      NRF_ERROR_INVALID_DATA If no character could be read.
 | 
			
		||||
 */
 | 
			
		||||
uint32_t NRF_LOG_READ_INPUT(char* p_char);
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
#endif // DOXYGEN
 | 
			
		||||
#endif // NRF_LOG_H_
 | 
			
		||||
							
								
								
									
										174
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/sdk_common.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										174
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/sdk_common.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,174 @@
 | 
			
		||||
/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/** @cond */
 | 
			
		||||
/**@file
 | 
			
		||||
 *
 | 
			
		||||
 * @ingroup experimental_api
 | 
			
		||||
 * @defgroup sdk_common SDK Common Header
 | 
			
		||||
 * @breif All common headers needed for SDK examples will be included here so that application
 | 
			
		||||
 *       developer does not have to include headers on him/herself.
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef SDK_COMMON_H__
 | 
			
		||||
#define SDK_COMMON_H__
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include "nordic_common.h"
 | 
			
		||||
#include "compiler_abstraction.h"
 | 
			
		||||
#include "sdk_os.h"
 | 
			
		||||
#include "sdk_errors.h"
 | 
			
		||||
#include "app_util.h"
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for verifying that the module is initialized. It will cause the function to return
 | 
			
		||||
 *        if not.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] param  The variable to check if is NULL.
 | 
			
		||||
 */
 | 
			
		||||
#ifndef DISABLE_PARAM_CHECK
 | 
			
		||||
#define VERIFY_PARAM_NOT_NULL(param)                \
 | 
			
		||||
do                                                  \
 | 
			
		||||
{                                                   \
 | 
			
		||||
    if (param == NULL)                              \
 | 
			
		||||
    {                                               \
 | 
			
		||||
        return NRF_ERROR_NULL;                      \
 | 
			
		||||
    }                                               \
 | 
			
		||||
} while(0)
 | 
			
		||||
#else
 | 
			
		||||
#define VERIFY_PARAM_NOT_NULL()
 | 
			
		||||
#endif /* DISABLE_PARAM_CHECK */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for verifying that the module is initialized. It will cause the function to return
 | 
			
		||||
 *        if not.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] param  The variable to check if is NULL.
 | 
			
		||||
 */
 | 
			
		||||
#ifndef DISABLE_PARAM_CHECK
 | 
			
		||||
#define VERIFY_PARAM_NOT_NULL_VOID(param)           \
 | 
			
		||||
do                                                  \
 | 
			
		||||
{                                                   \
 | 
			
		||||
    if (param == NULL)                              \
 | 
			
		||||
    {                                               \
 | 
			
		||||
        return;                                     \
 | 
			
		||||
    }                                               \
 | 
			
		||||
} while(0)
 | 
			
		||||
#else
 | 
			
		||||
#define VERIFY_PARAM_NOT_NULL_VOID()
 | 
			
		||||
#endif /* DISABLE_PARAM_CHECK */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for verifying that a function returned NRF_SUCCESS. Will return the err code
 | 
			
		||||
 * if not.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] err_code The error code to check.
 | 
			
		||||
 */
 | 
			
		||||
#ifndef DISABLE_PARAM_CHECK
 | 
			
		||||
#define VERIFY_SUCCESS(err_code)            \
 | 
			
		||||
do                                          \
 | 
			
		||||
{                                           \
 | 
			
		||||
    if (err_code != NRF_SUCCESS)            \
 | 
			
		||||
    {                                       \
 | 
			
		||||
        return err_code;                    \
 | 
			
		||||
    }                                       \
 | 
			
		||||
} while(0)
 | 
			
		||||
#else
 | 
			
		||||
#define VERIFY_SUCCESS()
 | 
			
		||||
#endif /* DISABLE_PARAM_CHECK */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for verifying that a function returned NRF_SUCCESS. Will return if not.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] err_code The error code to check.
 | 
			
		||||
 */
 | 
			
		||||
#ifndef DISABLE_PARAM_CHECK
 | 
			
		||||
#define VERIFY_SUCCESS_VOID(err_code)       \
 | 
			
		||||
do                                          \
 | 
			
		||||
{                                           \
 | 
			
		||||
    if (err_code != NRF_SUCCESS)            \
 | 
			
		||||
    {                                       \
 | 
			
		||||
        return;                             \
 | 
			
		||||
    }                                       \
 | 
			
		||||
} while(0)
 | 
			
		||||
#else
 | 
			
		||||
#define VERIFY_SUCCESS_VOID()
 | 
			
		||||
#endif /* DISABLE_PARAM_CHECK */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for verifying statement to be true. Will return err_code if not.
 | 
			
		||||
*
 | 
			
		||||
* @param[in]   statement   Statement to test.
 | 
			
		||||
* @param[in]   err_code     Error value to return if test was invalid.
 | 
			
		||||
*
 | 
			
		||||
* @retval      err_code if test fails.
 | 
			
		||||
*/
 | 
			
		||||
#define VERIFY_TRUE(statement, err_code)    \
 | 
			
		||||
do                                          \
 | 
			
		||||
{                                           \
 | 
			
		||||
    if (!(statement))                       \
 | 
			
		||||
    {                                       \
 | 
			
		||||
        return err_code;                    \
 | 
			
		||||
    }                                       \
 | 
			
		||||
} while(0)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for verifying statement to be true. Will return if not.
 | 
			
		||||
*
 | 
			
		||||
* @param[in]   statement   Statement to test.
 | 
			
		||||
*/
 | 
			
		||||
#define VERIFY_TRUE_VOID(statement)         \
 | 
			
		||||
do                                          \
 | 
			
		||||
{                                           \
 | 
			
		||||
    if (!(statement))                       \
 | 
			
		||||
    {                                       \
 | 
			
		||||
        return;                             \
 | 
			
		||||
    }                                       \
 | 
			
		||||
} while(0)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for verifying statement to be false. Will return err_code if not.
 | 
			
		||||
*
 | 
			
		||||
* @param[in]   statement   Statement to test.
 | 
			
		||||
* @param[in]   err_code     Error value to return if test was invalid.
 | 
			
		||||
*
 | 
			
		||||
* @retval      err_code if test fails.
 | 
			
		||||
*/
 | 
			
		||||
#define VERIFY_FALSE(statement, err_code)   \
 | 
			
		||||
do                                          \
 | 
			
		||||
{                                           \
 | 
			
		||||
    if ((statement))                        \
 | 
			
		||||
    {                                       \
 | 
			
		||||
        return err_code;                    \
 | 
			
		||||
    }                                       \
 | 
			
		||||
} while(0)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for verifying statement to be false. Will return if not.
 | 
			
		||||
*
 | 
			
		||||
* @param[in]   statement    Statement to test.
 | 
			
		||||
*/
 | 
			
		||||
#define VERIFY_FALSE_VOID(statement)        \
 | 
			
		||||
do                                          \
 | 
			
		||||
{                                           \
 | 
			
		||||
    if ((statement))                        \
 | 
			
		||||
    {                                       \
 | 
			
		||||
        return;                             \
 | 
			
		||||
    }                                       \
 | 
			
		||||
} while(0)
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
/** @endcond */
 | 
			
		||||
#endif // SDK_COMMON_H__
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										115
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/sdk_errors.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										115
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/sdk_errors.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,115 @@
 | 
			
		||||
/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/**@file
 | 
			
		||||
 *
 | 
			
		||||
 * @defgroup sdk_error SDK Error codes
 | 
			
		||||
 * @{
 | 
			
		||||
 * @ingroup app_common
 | 
			
		||||
 * @{
 | 
			
		||||
 * @details Error codes are 32-bit unsigned integers with the most significant 16-bit reserved for
 | 
			
		||||
 *          identifying the module where the error occurred while the least least significant LSB
 | 
			
		||||
 *          are used to provide the cause or nature of error. Each module is assigned a 16-bit
 | 
			
		||||
 *          unsigned integer. Which it will use to identify all errors that occurred in it. 16-bit
 | 
			
		||||
 *          LSB range is with module id as the MSB in the 32-bit error code is reserved for the
 | 
			
		||||
 *          module. As an example, if 0x8800 identifies a certain SDK module, all values from 
 | 
			
		||||
 *          0x88000000 - 0x8800FFFF are reserved for this module.
 | 
			
		||||
 *          It should be noted that common error reasons have been assigned values to make it 
 | 
			
		||||
 *          possible to decode error reason easily. As an example, lets module uninitialized has
 | 
			
		||||
 *          been assigned an error code 0x000A0. Then, if application encounters an error code
 | 
			
		||||
 *          0xZZZZ00A0, it knows that it accessing a certain module without initializing it.
 | 
			
		||||
 *          Apart from this, each module is allowed to define error codes that are not covered by
 | 
			
		||||
 *          the common ones, however, these values are defined in a range that does not conflict
 | 
			
		||||
 *          with common error values. For module, specific error however, it is possible that the
 | 
			
		||||
 *          same error value is used by two different modules to indicated errors of very different
 | 
			
		||||
 *          nature. If error is already defined by the NRF common error codes, these are reused.
 | 
			
		||||
 *          A range is reserved for application as well, it can use this range for defining
 | 
			
		||||
 *          application specific errors.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Success code, NRF_SUCCESS, does not include any module identifier.          
 | 
			
		||||
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef SDK_ERRORS_H__
 | 
			
		||||
#define SDK_ERRORS_H__
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include "nrf_error.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @defgroup sdk_err_base Base defined for SDK Modules
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
#define SDK_ERROR_BASE         (NRF_ERROR_BASE_NUM + 0x8000)   /**< Base value defined for SDK module identifiers. */
 | 
			
		||||
#define SDK_COMMON_ERROR_BASE  (NRF_ERROR_BASE_NUM + 0x0080)   /**< Base error value to be used for SDK error values. */
 | 
			
		||||
/* @} */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @defgroup sdk_module_codes Codes reserved as identification for module where the error occurred.
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
#define DEVICE_MANAGER_ERR_BASE   (0x8000)
 | 
			
		||||
#define MEMORY_MANAGER_ERR_BASE   (0x8100)
 | 
			
		||||
/* @} */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @defgroup sdk_iot_errors Codes reserved as identification for IoT errors.
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
#define IOT_ERR_BASE_START        (0xA000)
 | 
			
		||||
#define IOT_ERR_BASE_STOP         (0xAFFF)
 | 
			
		||||
/* @} */
 | 
			
		||||
 
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @defgroup sdk_common_errors Codes reserved as identification for common errors.
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
#define MODULE_NOT_INITIALZED      (SDK_COMMON_ERROR_BASE + 0x0000)
 | 
			
		||||
#define MUTEX_INIT_FAILED          (SDK_COMMON_ERROR_BASE + 0x0001)
 | 
			
		||||
#define MUTEX_LOCK_FAILED          (SDK_COMMON_ERROR_BASE + 0x0002)
 | 
			
		||||
#define MUTEX_UNLOCK_FAILED        (SDK_COMMON_ERROR_BASE + 0x0003)
 | 
			
		||||
#define MUTEX_COND_INIT_FAILED     (SDK_COMMON_ERROR_BASE + 0x0004)
 | 
			
		||||
#define MODULE_ALREADY_INITIALIZED (SDK_COMMON_ERROR_BASE + 0x0005)
 | 
			
		||||
#define API_NOT_IMPLEMENTED        (SDK_COMMON_ERROR_BASE + 0x0010)
 | 
			
		||||
#define FEATURE_NOT_ENABLED        (SDK_COMMON_ERROR_BASE + 0x0011)
 | 
			
		||||
/* @} */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @defgroup dm_specific_errors Error / status codes specific to device manager.
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
#define DM_NO_APP_CONTEXT                (DEVICE_MANAGER_ERR_BASE + 0x0040)
 | 
			
		||||
#define DM_SERVICE_CONTEXT_NOT_APPLIED   (DEVICE_MANAGER_ERR_BASE + 0x0041)
 | 
			
		||||
#define DM_CONTEXT_INFO_LOST             (DEVICE_MANAGER_ERR_BASE + 0x0042)
 | 
			
		||||
#define DM_DEVICE_CONTEXT_FULL           (DEVICE_MANAGER_ERR_BASE + 0x0043)
 | 
			
		||||
/* @} */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief API Result.
 | 
			
		||||
 *
 | 
			
		||||
 * @details Indicates success or failure of an API procedure. In case of failure, a comprehensive
 | 
			
		||||
 *          error code indicating cause or reason for failure is provided.
 | 
			
		||||
 *
 | 
			
		||||
 *          Though called an API result, it could used in Asynchronous notifications callback along
 | 
			
		||||
 *          with asynchronous callback as event result. This mechanism is employed when an event
 | 
			
		||||
 *          marks the end of procedure initiated using API. API result, in this case, will only be
 | 
			
		||||
 *          an indicative of whether the procedure has been requested successfully.
 | 
			
		||||
 */
 | 
			
		||||
typedef uint32_t ret_code_t;
 | 
			
		||||
/** @} */
 | 
			
		||||
/** @} */
 | 
			
		||||
 | 
			
		||||
#endif // SDK_ERRORS_H__
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,72 @@
 | 
			
		||||
/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/** @cond */
 | 
			
		||||
/**@file
 | 
			
		||||
 *
 | 
			
		||||
 * @ingroup sdk_util
 | 
			
		||||
 * @defgroup sdk_common_macros SDK Common Header
 | 
			
		||||
 * @breif Macros for parameter checking and similar tasks
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef SDK_MACROS_H__
 | 
			
		||||
#define SDK_MACROS_H__
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for verifying that the module is initialized. It will cause the function to return
 | 
			
		||||
 *        @ref NRF_ERROR_INVALID_STATE if not.
 | 
			
		||||
 */
 | 
			
		||||
#ifdef DISABLE_PARAM_CHECK
 | 
			
		||||
#define VERIFY_MODULE_INITIALIZED()
 | 
			
		||||
#else
 | 
			
		||||
#ifdef MODULE_INITIALIZED
 | 
			
		||||
#define VERIFY_MODULE_INITIALIZED()                 \
 | 
			
		||||
do                                          \
 | 
			
		||||
{                                           \
 | 
			
		||||
    if (!MODULE_INITIALIZED)                \
 | 
			
		||||
    {                                       \
 | 
			
		||||
        return NRF_ERROR_INVALID_STATE;     \
 | 
			
		||||
    }                                       \
 | 
			
		||||
} while(0)
 | 
			
		||||
#else
 | 
			
		||||
#define VERIFY_MODULE_INITIALIZED()
 | 
			
		||||
#endif /* MODULE_INITIALIZED  */
 | 
			
		||||
#endif /* DISABLE_PARAM_CHECK */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Macro for verifying that the module is initialized. It will cause the function to return
 | 
			
		||||
 *        if not.
 | 
			
		||||
 */
 | 
			
		||||
#ifdef DISABLE_PARAM_CHECK
 | 
			
		||||
#define VERIFY_MODULE_INITIALIZED_VOID()
 | 
			
		||||
#else
 | 
			
		||||
#ifdef MODULE_INITIALIZED
 | 
			
		||||
#define VERIFY_MODULE_INITIALIZED_VOID()            \
 | 
			
		||||
do                                                  \
 | 
			
		||||
{                                                   \
 | 
			
		||||
    if (!MODULE_INITIALIZED)                        \
 | 
			
		||||
    {                                               \
 | 
			
		||||
        return;                                     \
 | 
			
		||||
    }                                               \
 | 
			
		||||
} while(0)
 | 
			
		||||
#else
 | 
			
		||||
#define VERIFY_MODULE_INITIALIZED_VOID()
 | 
			
		||||
#endif /* MODULE_INITIALIZED  */
 | 
			
		||||
#endif /* DISABLE_PARAM_CHECK */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
/** @endcond */
 | 
			
		||||
#endif // SDK_MACROS_H__
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,161 @@
 | 
			
		||||
/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "sdk_mapped_flags.h"
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include <stddef.h>
 | 
			
		||||
#include "compiler_abstraction.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for setting the state of a flag to true.
 | 
			
		||||
 *
 | 
			
		||||
 * @note This function does not check whether the index is valid.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]  p_flags  The collection of flags to modify.
 | 
			
		||||
 * @param[in]  index    The index of the flag to modify.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE void sdk_mapped_flags_set_by_index(sdk_mapped_flags_t * p_flags, uint16_t index)
 | 
			
		||||
{
 | 
			
		||||
    *p_flags |= (1U << index);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for setting the state of a flag to false.
 | 
			
		||||
 *
 | 
			
		||||
 * @note This function does not check whether the index is valid.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]  p_flags  The collection of flags to modify.
 | 
			
		||||
 * @param[in]  index    The index of the flag to modify.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE void sdk_mapped_flags_clear_by_index(sdk_mapped_flags_t * p_flags, uint16_t index)
 | 
			
		||||
{
 | 
			
		||||
    *p_flags &= ~(1U << index);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for getting the state of a flag.
 | 
			
		||||
 *
 | 
			
		||||
 * @note This function does not check whether the index is valid.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]  p_flags  The collection of flags to read.
 | 
			
		||||
 * @param[in]  index    The index of the flag to get.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE bool sdk_mapped_flags_get_by_index(sdk_mapped_flags_t flags, uint16_t index)
 | 
			
		||||
{
 | 
			
		||||
    return ((flags & (1 << index)) != 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint16_t sdk_mapped_flags_first_key_index_get(sdk_mapped_flags_t flags)
 | 
			
		||||
{
 | 
			
		||||
    for (uint16_t i = 0; i < SDK_MAPPED_FLAGS_N_KEYS; i++)
 | 
			
		||||
    {
 | 
			
		||||
        if (sdk_mapped_flags_get_by_index(flags, i))
 | 
			
		||||
        {
 | 
			
		||||
            return i;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return SDK_MAPPED_FLAGS_INVALID_INDEX;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void sdk_mapped_flags_update_by_key(uint16_t           * p_keys,
 | 
			
		||||
                                    sdk_mapped_flags_t * p_flags,
 | 
			
		||||
                                    uint16_t             key,
 | 
			
		||||
                                    bool                 value)
 | 
			
		||||
{
 | 
			
		||||
    sdk_mapped_flags_bulk_update_by_key(p_keys, p_flags, 1, key, value);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void sdk_mapped_flags_bulk_update_by_key(uint16_t           * p_keys,
 | 
			
		||||
                                         sdk_mapped_flags_t * p_flags,
 | 
			
		||||
                                         uint32_t             n_flag_collections,
 | 
			
		||||
                                         uint16_t             key,
 | 
			
		||||
                                         bool                 value)
 | 
			
		||||
{
 | 
			
		||||
    if ((p_keys != NULL) && (p_flags != NULL) && (n_flag_collections > 0))
 | 
			
		||||
    {
 | 
			
		||||
        for (uint32_t i = 0; i < SDK_MAPPED_FLAGS_N_KEYS; i++)
 | 
			
		||||
        {
 | 
			
		||||
            if (p_keys[i] == key)
 | 
			
		||||
            {
 | 
			
		||||
                for (uint32_t j = 0; j < n_flag_collections; j++)
 | 
			
		||||
                {
 | 
			
		||||
                    if (value)
 | 
			
		||||
                    {
 | 
			
		||||
                        sdk_mapped_flags_set_by_index(&p_flags[j], i);
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        sdk_mapped_flags_clear_by_index(&p_flags[j], i);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool sdk_mapped_flags_get_by_key(uint16_t * p_keys, sdk_mapped_flags_t flags, uint16_t key)
 | 
			
		||||
{
 | 
			
		||||
    if (p_keys != NULL)
 | 
			
		||||
    {
 | 
			
		||||
        for (uint32_t i = 0; i < SDK_MAPPED_FLAGS_N_KEYS; i++)
 | 
			
		||||
        {
 | 
			
		||||
            if (p_keys[i] == key)
 | 
			
		||||
            {
 | 
			
		||||
                return sdk_mapped_flags_get_by_index(flags, i);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
sdk_mapped_flags_key_list_t sdk_mapped_flags_key_list_get(uint16_t           * p_keys,
 | 
			
		||||
                                                          sdk_mapped_flags_t   flags)
 | 
			
		||||
{
 | 
			
		||||
    sdk_mapped_flags_key_list_t key_list;
 | 
			
		||||
    key_list.len = 0;
 | 
			
		||||
 | 
			
		||||
    if (p_keys != NULL)
 | 
			
		||||
    {
 | 
			
		||||
        for (uint32_t i = 0; i < SDK_MAPPED_FLAGS_N_KEYS; i++)
 | 
			
		||||
        {
 | 
			
		||||
            if (sdk_mapped_flags_get_by_index(flags, i))
 | 
			
		||||
            {
 | 
			
		||||
                key_list.flag_keys[key_list.len++] = p_keys[i];
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return key_list;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t sdk_mapped_flags_n_flags_set(sdk_mapped_flags_t flags)
 | 
			
		||||
{
 | 
			
		||||
    uint32_t n_flags_set = 0;
 | 
			
		||||
 | 
			
		||||
    for (uint32_t i = 0; i < SDK_MAPPED_FLAGS_N_KEYS; i++)
 | 
			
		||||
    {
 | 
			
		||||
        if (sdk_mapped_flags_get_by_index(flags, i))
 | 
			
		||||
        {
 | 
			
		||||
            n_flags_set += 1;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return n_flags_set;
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,153 @@
 | 
			
		||||
/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef SDK_MAPPED_FLAGS_H__
 | 
			
		||||
#define SDK_MAPPED_FLAGS_H__
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include "app_util.h"
 | 
			
		||||
#include "compiler_abstraction.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @file
 | 
			
		||||
 * @defgroup sdk_mapped_flags Mapped flags
 | 
			
		||||
 * @ingroup app_common
 | 
			
		||||
 * @{
 | 
			
		||||
 * @brief Module for writing and reading flags that are associated
 | 
			
		||||
 *        with keys.
 | 
			
		||||
 *
 | 
			
		||||
 * @details The flags are represented as bits in a bitmap called a <i>flag collection</i>. The keys
 | 
			
		||||
 *          are uint16_t. Each flag collection contains all flags of the same type, one flag for
 | 
			
		||||
 *          each key.
 | 
			
		||||
 *
 | 
			
		||||
 *          The mapped flags module does not keep the flag states, nor the list of keys. These are
 | 
			
		||||
 *          provided in the API calls. A key's index in the key list determines which bit in the
 | 
			
		||||
 *          flag collection is associated with it. This module does not ever edit the key list, and
 | 
			
		||||
 *          does not edit flags except in function calls that take the flag collection as a pointer.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#define SDK_MAPPED_FLAGS_N_KEYS          8       /**< The number of keys to keep flags for. This is also the number of flags in a flag collection. If changing this value, you might also need change the width of the sdk_mapped_flags_t type. */
 | 
			
		||||
#define SDK_MAPPED_FLAGS_N_KEYS_PER_BYTE 8       /**< The number of flags that fit in one byte. */
 | 
			
		||||
#define SDK_MAPPED_FLAGS_INVALID_INDEX   0xFFFF  /**< A flag index guaranteed to be invalid. */
 | 
			
		||||
 | 
			
		||||
typedef uint8_t sdk_mapped_flags_t; /**< The bitmap to hold flags. Each flag is one bit, and each bit represents the flag state associated with one key. */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Test whether the flag collection type is large enough to hold all the flags. If this fails,
 | 
			
		||||
// reduce SDK_MAPPED_FLAGS_N_KEYS or increase the size of sdk_mapped_flags_t.
 | 
			
		||||
STATIC_ASSERT((
 | 
			
		||||
    sizeof(sdk_mapped_flags_t)*SDK_MAPPED_FLAGS_N_KEYS_PER_BYTE) >= SDK_MAPPED_FLAGS_N_KEYS);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Type used to present a subset of the registered keys.
 | 
			
		||||
 */
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
    uint32_t len;                                 /**< The length of the list. */
 | 
			
		||||
    uint16_t flag_keys[SDK_MAPPED_FLAGS_N_KEYS];  /**< The list of keys. */
 | 
			
		||||
} sdk_mapped_flags_key_list_t;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for getting the first index at which the flag is true in the provided
 | 
			
		||||
 *        collection.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]  flags   The flag collection to search for a flag set to true.
 | 
			
		||||
 *
 | 
			
		||||
 * @return  The first index that has its flag set to true. If none were found, the
 | 
			
		||||
 *          function returns @ref SDK_MAPPED_FLAGS_INVALID_INDEX.
 | 
			
		||||
 */
 | 
			
		||||
uint16_t sdk_mapped_flags_first_key_index_get(sdk_mapped_flags_t flags);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for updating the state of a flag.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]  p_keys   The list of associated keys (assumed to have a length of
 | 
			
		||||
 *                      @ref SDK_MAPPED_FLAGS_N_KEYS).
 | 
			
		||||
 * @param[out] p_flags  The flag collection to modify.
 | 
			
		||||
 * @param[in]  key      The key to modify the flag of.
 | 
			
		||||
 * @param[in]  value    The state to set the flag to.
 | 
			
		||||
 */
 | 
			
		||||
void sdk_mapped_flags_update_by_key(uint16_t           * p_keys,
 | 
			
		||||
                                    sdk_mapped_flags_t * p_flags,
 | 
			
		||||
                                    uint16_t             key,
 | 
			
		||||
                                    bool                 value);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for updating the state of the same flag in multiple flag collections.
 | 
			
		||||
 *
 | 
			
		||||
 * @details The key and value are the same for all flag collections in the p_flags array.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]  p_keys              The list of associated keys (assumed to have a length of
 | 
			
		||||
 *                                 @ref SDK_MAPPED_FLAGS_N_KEYS).
 | 
			
		||||
 * @param[out] p_flags             The flag collections to modify.
 | 
			
		||||
 * @param[out] n_flag_collections  The number of flag collections in p_flags.
 | 
			
		||||
 * @param[in]  key                 The key to modify the flag of.
 | 
			
		||||
 * @param[in]  value               The state to set the flag to.
 | 
			
		||||
 */
 | 
			
		||||
void sdk_mapped_flags_bulk_update_by_key(uint16_t           * p_keys,
 | 
			
		||||
                                         sdk_mapped_flags_t * p_flags,
 | 
			
		||||
                                         uint32_t             n_flag_collections,
 | 
			
		||||
                                         uint16_t             key,
 | 
			
		||||
                                         bool                 value);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for getting the state of a specific flag.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]  p_keys  The list of associated keys (assumed to have a length of
 | 
			
		||||
 *                     @ref SDK_MAPPED_FLAGS_N_KEYS).
 | 
			
		||||
 * @param[in]  flags   The flag collection to read from.
 | 
			
		||||
 * @param[in]  key     The key to get the flag for.
 | 
			
		||||
 *
 | 
			
		||||
 * @return  The state of the flag.
 | 
			
		||||
 */
 | 
			
		||||
bool sdk_mapped_flags_get_by_key(uint16_t * p_keys, sdk_mapped_flags_t flags, uint16_t key);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for getting a list of all keys that have a specific flag set to true.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]  p_keys  The list of associated keys (assumed to have a length of
 | 
			
		||||
 *                     @ref SDK_MAPPED_FLAGS_N_KEYS).
 | 
			
		||||
 * @param[in]  flags   The flag collection to search.
 | 
			
		||||
 *
 | 
			
		||||
 * @return  The list of keys.
 | 
			
		||||
 */
 | 
			
		||||
sdk_mapped_flags_key_list_t sdk_mapped_flags_key_list_get(uint16_t           * p_keys,
 | 
			
		||||
                                                          sdk_mapped_flags_t   flags);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for getting the number of keys that have a specific flag set to true.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]  flags  The flag collection to search.
 | 
			
		||||
 *
 | 
			
		||||
 * @return  The number of keys.
 | 
			
		||||
 */
 | 
			
		||||
uint32_t sdk_mapped_flags_n_flags_set(sdk_mapped_flags_t flags);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**@brief Function for querying whether any flags in the collection are set.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in]  flags  The flag collection to query.
 | 
			
		||||
 *
 | 
			
		||||
 * @retval  true If one or more flags are set to true.
 | 
			
		||||
 * @retval  false Otherwise.
 | 
			
		||||
 */
 | 
			
		||||
static __INLINE bool sdk_mapped_flags_any_set(sdk_mapped_flags_t flags)
 | 
			
		||||
{
 | 
			
		||||
    return (flags != 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
 | 
			
		||||
#endif /* SDK_MAPPED_FLAGS_H__ */
 | 
			
		||||
							
								
								
									
										40
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/sdk_os.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								nRF5_SDK_11.0.0_89a8197/components/libraries/util/sdk_os.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
 /** @cond */
 | 
			
		||||
/**@file
 | 
			
		||||
 *
 | 
			
		||||
 * @defgroup sdk_os SDK OS Abstraction
 | 
			
		||||
 * @ingroup experimental_api
 | 
			
		||||
 * @details In order to made SDK modules independent of use of an embedded OS, and permit
 | 
			
		||||
 *          application with varied task architecture, SDK abstracts the OS specific
 | 
			
		||||
 *          elements here in order to make all other modules agnostic to the OS or task
 | 
			
		||||
 *          architecture.
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef SDK_OS_H__
 | 
			
		||||
#define SDK_OS_H__
 | 
			
		||||
 | 
			
		||||
#define SDK_MUTEX_DEFINE(X)
 | 
			
		||||
#define SDK_MUTEX_INIT(X)
 | 
			
		||||
#define SDK_MUTEX_LOCK(X)
 | 
			
		||||
#define SDK_MUTEX_UNLOCK(X)
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @defgroup os_data_type Data types.
 | 
			
		||||
 */
 | 
			
		||||
 
 | 
			
		||||
/** @} */
 | 
			
		||||
/** @endcond */
 | 
			
		||||
#endif // SDK_OS_H__
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,50 @@
 | 
			
		||||
/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/** @file
 | 
			
		||||
 * @brief Definition file for resource usage by SoftDevice, ESB and Gazell.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef APP_RESOURCES_H__
 | 
			
		||||
#define APP_RESOURCES_H__
 | 
			
		||||
 | 
			
		||||
#ifdef SOFTDEVICE_PRESENT
 | 
			
		||||
	#include "nrf_sd_def.h"
 | 
			
		||||
#else
 | 
			
		||||
	#define SD_PPI_RESTRICTED	      0uL /**< 1 if PPI peripheral is restricted, 0 otherwise. */
 | 
			
		||||
	#define SD_PPI_CHANNELS_USED      0uL /**< PPI channels utilized by SotfDevice (not available to th spplication). */
 | 
			
		||||
	#define SD_PPI_GROUPS_USED        0uL /**< PPI groups utilized by SotfDevice (not available to th spplication). */
 | 
			
		||||
	#define SD_TIMERS_USED            0uL /**< Timers used by SoftDevice. */
 | 
			
		||||
	#define SD_SWI_USED               0uL /**< Software interrupts used by SoftDevice. */
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef GAZELL_PRESENT
 | 
			
		||||
	#include "nrf_gzll_resources.h"
 | 
			
		||||
#else
 | 
			
		||||
	#define GZLL_PPI_CHANNELS_USED    0uL /**< PPI channels utilized by Gazell (not available to th spplication). */
 | 
			
		||||
	#define GZLL_TIMERS_USED          0uL /**< Timers used by Gazell. */
 | 
			
		||||
	#define GZLL_SWI_USED             0uL /**< Software interrupts used by Gazell */
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef ESB_PRESENT
 | 
			
		||||
	#include "nrf_esb_resources.h"
 | 
			
		||||
#else
 | 
			
		||||
	#define ESB_PPI_CHANNELS_USED    0uL /**< PPI channels utilized by ESB (not available to th spplication). */
 | 
			
		||||
	#define ESB_TIMERS_USED          0uL /**< Timers used by ESB. */
 | 
			
		||||
	#define ESB_SWI_USED             0uL /**< Software interrupts used by ESB */
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define NRF_PPI_CHANNELS_USED (SD_PPI_CHANNELS_USED | GZLL_PPI_CHANNELS_USED | ESB_PPI_CHANNELS_USED)
 | 
			
		||||
#define NRF_PPI_GROUPS_USED   (SD_PPI_GROUPS_USED)
 | 
			
		||||
#define NRF_SWI_USED          (SD_SWI_USED | GZLL_SWI_USED | ESB_SWI_USED)
 | 
			
		||||
#define NRF_TIMERS_USED       (SD_TIMERS_USED | GZLL_TIMERS_USED | ESB_TIMERS_USED)
 | 
			
		||||
 | 
			
		||||
#endif // APP_RESOURCES_H__
 | 
			
		||||
		Reference in New Issue
	
	Block a user