wrap up nrf52 demo
This commit is contained in:
@@ -0,0 +1,495 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**@file
|
||||
*
|
||||
* @defgroup nrf_atomic Atomic operations API
|
||||
* @ingroup nrf_atfifo
|
||||
* @{
|
||||
*
|
||||
* @brief @tagAPI52 This module implements C11 stdatomic.h simplified API.
|
||||
At this point only Cortex-M3/M4 cores are supported (LDREX/STREX instructions).
|
||||
* Atomic types are limited to @ref nrf_atomic_u32_t and @ref nrf_atomic_flag_t.
|
||||
*/
|
||||
|
||||
#ifndef NRF_ATOMIC_H__
|
||||
#define NRF_ATOMIC_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
|
||||
#ifndef NRF_ATOMIC_USE_BUILD_IN
|
||||
#if (defined(__GNUC__) && defined(WIN32))
|
||||
#define NRF_ATOMIC_USE_BUILD_IN 1
|
||||
#else
|
||||
#define NRF_ATOMIC_USE_BUILD_IN 0
|
||||
#endif
|
||||
#endif // NRF_ATOMIC_USE_BUILD_IN
|
||||
|
||||
#if ((__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U))
|
||||
#define STREX_LDREX_PRESENT
|
||||
#else
|
||||
#include "app_util_platform.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Atomic 32 bit unsigned type
|
||||
* */
|
||||
typedef volatile uint32_t nrf_atomic_u32_t;
|
||||
|
||||
/**
|
||||
* @brief Atomic 1 bit flag type (technically 32 bit)
|
||||
* */
|
||||
typedef volatile uint32_t nrf_atomic_flag_t;
|
||||
|
||||
#if (NRF_ATOMIC_USE_BUILD_IN == 0) && defined(STREX_LDREX_PRESENT)
|
||||
#include "nrf_atomic_internal.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Stores value to an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value to store
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
static inline uint32_t nrf_atomic_u32_fetch_store(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_exchange_n(p_data, value, __ATOMIC_SEQ_CST);
|
||||
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
NRF_ATOMIC_OP(mov, old_val, new_val, p_data, value);
|
||||
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data = value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stores value to an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value to store
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
static inline uint32_t nrf_atomic_u32_store(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
__atomic_store_n(p_data, value, __ATOMIC_SEQ_CST);
|
||||
return value;
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(mov, old_val, new_val, p_data, value);
|
||||
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data = value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logical OR operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand OR operation
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
static inline uint32_t nrf_atomic_u32_fetch_or(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_fetch_or(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(orr, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data |= value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logical OR operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand OR operation
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
static inline uint32_t nrf_atomic_u32_or(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_or_fetch(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(orr, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data |= value;
|
||||
uint32_t new_value = *p_data;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return new_value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logical AND operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand AND operation
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
static inline uint32_t nrf_atomic_u32_fetch_and(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_fetch_and(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(and, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data &= value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logical AND operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand AND operation
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
static inline uint32_t nrf_atomic_u32_and(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_and_fetch(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(and, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data &= value;
|
||||
uint32_t new_value = *p_data;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return new_value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logical XOR operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand XOR operation
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
static inline uint32_t nrf_atomic_u32_fetch_xor(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_fetch_xor(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(eor, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data ^= value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logical XOR operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand XOR operation
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
static inline uint32_t nrf_atomic_u32_xor(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_xor_fetch(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(eor, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data ^= value;
|
||||
uint32_t new_value = *p_data;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return new_value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Arithmetic ADD operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand ADD operation
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
static inline uint32_t nrf_atomic_u32_fetch_add(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_fetch_add(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(add, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data += value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Arithmetic ADD operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand ADD operation
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
static inline uint32_t nrf_atomic_u32_add(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_add_fetch(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(add, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data += value;
|
||||
uint32_t new_value = *p_data;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return new_value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Arithmetic SUB operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand SUB operation
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
static inline uint32_t nrf_atomic_u32_fetch_sub(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_fetch_sub(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(sub, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data -= value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Arithmetic SUB operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand SUB operation
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
static inline uint32_t nrf_atomic_u32_sub(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_sub_fetch(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(sub, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data -= value;
|
||||
uint32_t new_value = *p_data;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return new_value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
/**************************************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief Logic one bit flag set operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic flag memory pointer
|
||||
*
|
||||
* @return Old flag value
|
||||
* */
|
||||
static inline uint32_t nrf_atomic_flag_set_fetch(nrf_atomic_flag_t * p_data)
|
||||
{
|
||||
return nrf_atomic_u32_fetch_or(p_data, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logic one bit flag set operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic flag memory pointer
|
||||
*
|
||||
* @return New flag value
|
||||
* */
|
||||
static inline uint32_t nrf_atomic_flag_set(nrf_atomic_flag_t * p_data)
|
||||
{
|
||||
return nrf_atomic_u32_or(p_data, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logic one bit flag clear operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic flag memory pointer
|
||||
*
|
||||
* @return Old flag value
|
||||
* */
|
||||
static inline uint32_t nrf_atomic_flag_clear_fetch(nrf_atomic_flag_t * p_data)
|
||||
{
|
||||
return nrf_atomic_u32_fetch_and(p_data, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Logic one bit flag clear operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic flag memory pointer
|
||||
*
|
||||
* @return New flag value
|
||||
* */
|
||||
static inline uint32_t nrf_atomic_flag_clear(nrf_atomic_flag_t * p_data)
|
||||
{
|
||||
return nrf_atomic_u32_and(p_data, 0);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_ATOMIC_H__ */
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,234 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef NRF_ATOMIC_INTERNAL_H__
|
||||
#define NRF_ATOMIC_INTERNAL_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
* @defgroup nrf_atomic_internal Atomic operations internals
|
||||
* @ingroup nrf_atomic
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
|
||||
/* Only Cortex M cores > 3 support LDREX/STREX instructions*/
|
||||
#if ((__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U)) == 0
|
||||
#error "Unsupported core version"
|
||||
#endif
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
static __asm uint32_t nrf_atomic_internal_mov(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
/* The base standard provides for passing arguments in core registers (r0-r3) and on the stack.
|
||||
* Registers r4 and r5 have to be saved on stack. Note that only even number of register push are
|
||||
* allowed. This is a requirement of the Procedure Call Standard for the ARM Architecture [AAPCS].
|
||||
* */
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_mov
|
||||
ldrex r0, [r4]
|
||||
mov r5, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_mov
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
|
||||
static __asm uint32_t nrf_atomic_internal_orr(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_orr
|
||||
ldrex r0, [r4]
|
||||
orr r5, r0, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_orr
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
static __asm uint32_t nrf_atomic_internal_and(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_and
|
||||
ldrex r0, [r4]
|
||||
and r5, r0, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_and
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
static __asm uint32_t nrf_atomic_internal_eor(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_eor
|
||||
ldrex r0, [r4]
|
||||
eor r5, r0, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_eor
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
static __asm uint32_t nrf_atomic_internal_add(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_add
|
||||
ldrex r0, [r4]
|
||||
add r5, r0, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_add
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
static __asm uint32_t nrf_atomic_internal_sub(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_sub
|
||||
ldrex r0, [r4]
|
||||
sub r5, r0, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_sub
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
|
||||
#define NRF_ATOMIC_OP(asm_op, old_val, new_val, ptr, value) \
|
||||
old_val = nrf_atomic_internal_##asm_op(ptr, value, &new_val)
|
||||
|
||||
#elif defined ( __ICCARM__ ) || defined ( __GNUC__ )
|
||||
|
||||
/**
|
||||
* @brief Atomic operation generic macro
|
||||
* @param[in] asm_op operation: mov, orr, and, eor, add, sub
|
||||
* @param[out] old_val atomic object output (uint32_t), value before operation
|
||||
* @param[out] new_val atomic object output (uint32_t), value after operation
|
||||
* @param[in] value atomic operation operand
|
||||
* */
|
||||
#define NRF_ATOMIC_OP(asm_op, old_val, new_val, ptr, value) \
|
||||
{ \
|
||||
uint32_t str_res; \
|
||||
__ASM volatile( \
|
||||
"1: ldrex %["#old_val"], [%["#ptr"]]\n" \
|
||||
NRF_ATOMIC_OP_##asm_op(new_val, old_val, value) \
|
||||
" strex %[str_res], %["#new_val"], [%["#ptr"]]\n" \
|
||||
" teq %[str_res], #0\n" \
|
||||
" bne.n 1b" \
|
||||
: \
|
||||
[old_val]"=&r" (old_val), \
|
||||
[new_val]"=&r" (new_val), \
|
||||
[str_res]"=&r" (str_res) \
|
||||
: \
|
||||
[ptr]"r" (ptr), \
|
||||
[value]"r" (value) \
|
||||
: "cc"); \
|
||||
UNUSED_PARAMETER(str_res); \
|
||||
}
|
||||
|
||||
#define NRF_ATOMIC_OP_mov(new_val, old_val, value) "mov %["#new_val"], %["#value"]\n"
|
||||
#define NRF_ATOMIC_OP_orr(new_val, old_val, value) "orr %["#new_val"], %["#old_val"], %["#value"]\n"
|
||||
#define NRF_ATOMIC_OP_and(new_val, old_val, value) "and %["#new_val"], %["#old_val"], %["#value"]\n"
|
||||
#define NRF_ATOMIC_OP_eor(new_val, old_val, value) "eor %["#new_val"], %["#old_val"], %["#value"]\n"
|
||||
#define NRF_ATOMIC_OP_add(new_val, old_val, value) "add %["#new_val"], %["#old_val"], %["#value"]\n"
|
||||
#define NRF_ATOMIC_OP_sub(new_val, old_val, value) "sub %["#new_val"], %["#old_val"], %["#value"]\n"
|
||||
|
||||
#else
|
||||
#error "Unsupported compiler"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_ATOMIC_INTERNAL_H__ */
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,153 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef NRF_ATOMIC_SANITY_CHECK_H__
|
||||
#define NRF_ATOMIC_SANITY_CHECK_H__
|
||||
|
||||
#include "nrf_atomic.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Quick sanity check of nrf_atomic API
|
||||
* */
|
||||
static inline void nrf_atomic_sanity_check(void)
|
||||
{
|
||||
#if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER)
|
||||
nrf_atomic_u32_t val;
|
||||
nrf_atomic_u32_t flag;
|
||||
|
||||
/*Fetch version tests*/
|
||||
val = 0;
|
||||
ASSERT(nrf_atomic_u32_store_fetch(&val, 10) == 0);
|
||||
ASSERT(nrf_atomic_u32_store_fetch(&val, 0) == 10);
|
||||
|
||||
val = 0;
|
||||
ASSERT(nrf_atomic_u32_or_fetch(&val, 1 << 16) == 0);
|
||||
ASSERT(nrf_atomic_u32_or_fetch(&val, 1 << 5) == ((1 << 16)));
|
||||
ASSERT(nrf_atomic_u32_or_fetch(&val, 1 << 5) == ((1 << 16) | (1 << 5)));
|
||||
ASSERT(nrf_atomic_u32_or_fetch(&val, 0) == ((1 << 16) | (1 << 5)));
|
||||
ASSERT(nrf_atomic_u32_or_fetch(&val, 0xFFFFFFFF) == ((1 << 16) | (1 << 5)));
|
||||
ASSERT(nrf_atomic_u32_or_fetch(&val, 0xFFFFFFFF) == (0xFFFFFFFF));
|
||||
|
||||
val = 0xFFFFFFFF;
|
||||
ASSERT(nrf_atomic_u32_and_fetch(&val, ~(1 << 16)) == 0xFFFFFFFF);
|
||||
ASSERT(nrf_atomic_u32_and_fetch(&val, ~(1 << 5)) == (0xFFFFFFFF & ~((1 << 16))));
|
||||
ASSERT(nrf_atomic_u32_and_fetch(&val, 0) == (0xFFFFFFFF & ~(((1 << 16) | (1 << 5)))));
|
||||
ASSERT(nrf_atomic_u32_and_fetch(&val, 0xFFFFFFFF) == (0));
|
||||
|
||||
val = 0;
|
||||
ASSERT(nrf_atomic_u32_xor_fetch(&val, (1 << 16)) == 0);
|
||||
ASSERT(nrf_atomic_u32_xor_fetch(&val, (1 << 5)) == ((1 << 16)));
|
||||
ASSERT(nrf_atomic_u32_xor_fetch(&val, 0) == ((1 << 16) | (1 << 5)));
|
||||
ASSERT(nrf_atomic_u32_xor_fetch(&val, (1 << 16) | (1 << 5)) == ((1 << 16) | (1 << 5)));
|
||||
ASSERT(nrf_atomic_u32_xor_fetch(&val, 0) == (0));
|
||||
|
||||
val = 0;
|
||||
ASSERT(nrf_atomic_u32_add_fetch(&val, 100) == 0);
|
||||
ASSERT(nrf_atomic_u32_add_fetch(&val, 100) == 100);
|
||||
ASSERT(nrf_atomic_u32_add_fetch(&val, 1 << 24) == 200);
|
||||
ASSERT(nrf_atomic_u32_add_fetch(&val, 0) == (200 + (1 << 24)));
|
||||
ASSERT(nrf_atomic_u32_add_fetch(&val, 0xFFFFFFFF) == (200 + (1 << 24)));
|
||||
ASSERT(nrf_atomic_u32_add_fetch(&val, 0) == (200 - 1 + (1 << 24)));
|
||||
|
||||
val = 1000;
|
||||
ASSERT(nrf_atomic_u32_sub_fetch(&val, 100) == 1000);
|
||||
ASSERT(nrf_atomic_u32_sub_fetch(&val, 100) == 900);
|
||||
ASSERT(nrf_atomic_u32_sub_fetch(&val, 0) == 800);
|
||||
ASSERT(nrf_atomic_u32_sub_fetch(&val, 0xFFFFFFFF) == 800);
|
||||
ASSERT(nrf_atomic_u32_sub_fetch(&val, 0) == 801);
|
||||
|
||||
flag = 0;
|
||||
ASSERT(nrf_atomic_flag_set_fetch(&flag) == 0);
|
||||
ASSERT(nrf_atomic_flag_set_fetch(&flag) == 1);
|
||||
ASSERT(nrf_atomic_flag_clear_fetch(&flag) == 1);
|
||||
ASSERT(nrf_atomic_flag_clear_fetch(&flag) == 0);
|
||||
|
||||
/*No fetch version tests*/
|
||||
val = 0;
|
||||
ASSERT(nrf_atomic_u32_store(&val, 10) == 10);
|
||||
ASSERT(nrf_atomic_u32_store(&val, 0) == 0);
|
||||
|
||||
val = 0;
|
||||
ASSERT(nrf_atomic_u32_or(&val, 1 << 16) == 1 << 16);
|
||||
ASSERT(nrf_atomic_u32_or(&val, 1 << 5) == ((1 << 16) | (1 << 5)));
|
||||
ASSERT(nrf_atomic_u32_or(&val, 1 << 5) == ((1 << 16) | (1 << 5)));
|
||||
ASSERT(nrf_atomic_u32_or(&val, 0) == ((1 << 16) | (1 << 5)));
|
||||
ASSERT(nrf_atomic_u32_or(&val, 0xFFFFFFFF) == 0xFFFFFFFF);
|
||||
|
||||
val = 0xFFFFFFFF;
|
||||
ASSERT(nrf_atomic_u32_and(&val, ~(1 << 16)) == (0xFFFFFFFF & ~((1 << 16))));
|
||||
ASSERT(nrf_atomic_u32_and(&val, ~(1 << 5)) == (0xFFFFFFFF & ~(((1 << 16) | (1 << 5)))));
|
||||
ASSERT(nrf_atomic_u32_and(&val, 0) == 0);
|
||||
|
||||
val = 0;
|
||||
ASSERT(nrf_atomic_u32_xor(&val, (1 << 16)) == ((1 << 16)));
|
||||
ASSERT(nrf_atomic_u32_xor(&val, (1 << 5)) == ((1 << 16) | (1 << 5)));
|
||||
ASSERT(nrf_atomic_u32_xor(&val, 0) == ((1 << 16) | (1 << 5)));
|
||||
ASSERT(nrf_atomic_u32_xor(&val, (1 << 16) | (1 << 5)) == 0);
|
||||
|
||||
val = 0;
|
||||
ASSERT(nrf_atomic_u32_add(&val, 100) == 100);
|
||||
ASSERT(nrf_atomic_u32_add(&val, 100) == 200);
|
||||
ASSERT(nrf_atomic_u32_add(&val, 1 << 24) == (200 + (1 << 24)));
|
||||
ASSERT(nrf_atomic_u32_add(&val, 0) == (200 + (1 << 24)));
|
||||
ASSERT(nrf_atomic_u32_add(&val, 0xFFFFFFFF) == (200 - 1 + (1 << 24)));
|
||||
|
||||
val = 1000;
|
||||
ASSERT(nrf_atomic_u32_sub(&val, 100) == 900);
|
||||
ASSERT(nrf_atomic_u32_sub(&val, 100) == 800);
|
||||
ASSERT(nrf_atomic_u32_sub(&val, 0) == 800);
|
||||
ASSERT(nrf_atomic_u32_sub(&val, 0xFFFFFFFF) == 801);
|
||||
|
||||
flag = 0;
|
||||
ASSERT(nrf_atomic_flag_set(&flag) == 1);
|
||||
ASSERT(nrf_atomic_flag_set(&flag) == 1);
|
||||
ASSERT(nrf_atomic_flag_clear(&flag) == 0);
|
||||
ASSERT(nrf_atomic_flag_clear(&flag) == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_ATOMIC_SANITY_CHECK_H__ */
|
||||
@@ -0,0 +1,343 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(NRF_BALLOC)
|
||||
|
||||
#include "nrf_balloc.h"
|
||||
#include "app_util_platform.h"
|
||||
|
||||
#define NRF_LOG_MODULE_NAME balloc
|
||||
#if NRF_BALLOC_CONFIG_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL NRF_BALLOC_CONFIG_LOG_LEVEL
|
||||
#define NRF_LOG_INFO_COLOR NRF_BALLOC_CONFIG_INFO_COLOR
|
||||
#define NRF_LOG_DEBUG_COLOR NRF_BALLOC_CONFIG_DEBUG_COLOR
|
||||
#else
|
||||
#define NRF_LOG_LEVEL 0
|
||||
#endif // NRF_BALLOC_CONFIG_LOG_ENABLED
|
||||
#include "nrf_log.h"
|
||||
NRF_LOG_MODULE_REGISTER();
|
||||
|
||||
#define HEAD_GUARD_FILL 0xBAADF00D /**< Magic number used to mark head guard.*/
|
||||
#define TAIL_GUARD_FILL 0xBAADCAFE /**< Magic number used to mark tail guard.*/
|
||||
#define FREE_MEM_FILL 0xBAADBAAD /**< Magic number used to mark free memory.*/
|
||||
|
||||
#if NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
#define POOL_ID(_p_pool) _p_pool->p_name
|
||||
#define POOL_MARKER "%s"
|
||||
#else
|
||||
#define POOL_ID(_p_pool) _p_pool
|
||||
#define POOL_MARKER "0x%08X"
|
||||
#endif
|
||||
|
||||
#if NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
|
||||
/**@brief Validate block memory, prepare block guards, and calculate pointer to the element.
|
||||
*
|
||||
* @param[in] p_pool Pointer to the memory pool.
|
||||
* @param[in] p_head Pointer to the beginning of the block.
|
||||
*
|
||||
* @return Pointer to the element.
|
||||
*/
|
||||
__STATIC_INLINE void * nrf_balloc_block_unwrap(nrf_balloc_t const * p_pool, void * p_head)
|
||||
{
|
||||
ASSERT((p_pool != NULL) && ((p_pool->block_size % sizeof(uint32_t)) == 0));
|
||||
ASSERT((p_head != NULL) && (((uint32_t)(p_head) % sizeof(uint32_t)) == 0));
|
||||
|
||||
uint32_t head_words = NRF_BALLOC_DEBUG_HEAD_GUARD_WORDS_GET(p_pool->debug_flags);
|
||||
uint32_t tail_words = NRF_BALLOC_DEBUG_TAIL_GUARD_WORDS_GET(p_pool->debug_flags);
|
||||
|
||||
uint32_t * p_tail = (uint32_t *)((size_t)(p_head) + p_pool->block_size);
|
||||
uint32_t * p_element = (uint32_t *)p_head + head_words;
|
||||
|
||||
if (NRF_BALLOC_DEBUG_DATA_TRASHING_CHECK_GET(p_pool->debug_flags))
|
||||
{
|
||||
for (uint32_t * ptr = p_head; ptr < p_tail; ptr++)
|
||||
{
|
||||
if (*ptr != FREE_MEM_FILL)
|
||||
{
|
||||
NRF_LOG_ERROR("Detected free memory corruption at 0x%08X (0x%08X != 0x%08X, pool: '" POOL_MARKER "')",
|
||||
ptr, *ptr, FREE_MEM_FILL, POOL_ID(p_pool));
|
||||
APP_ERROR_CHECK_BOOL(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t * ptr = p_head; ptr < p_element; ptr++)
|
||||
{
|
||||
*ptr = HEAD_GUARD_FILL;
|
||||
}
|
||||
|
||||
for (uint32_t * ptr = ( p_tail - tail_words); ptr < p_tail; ptr++)
|
||||
{
|
||||
*ptr = TAIL_GUARD_FILL;
|
||||
}
|
||||
|
||||
return p_element;
|
||||
}
|
||||
|
||||
/**@brief Calculate pointer to the block, validate block guards, and mark block memory as free.
|
||||
*
|
||||
* @param[in] p_pool Pointer to the memory pool.
|
||||
* @param[in] p_element Pointer to the element.
|
||||
*
|
||||
* @return Pointer to the beginning of the block.
|
||||
*/
|
||||
__STATIC_INLINE void * nrf_balloc_element_wrap(nrf_balloc_t const * p_pool, void * p_element)
|
||||
{
|
||||
ASSERT((p_pool != NULL) && ((p_pool->block_size % sizeof(uint32_t)) == 0));
|
||||
ASSERT((p_element != NULL) && (((uint32_t)(p_element) % sizeof(uint32_t)) == 0));
|
||||
|
||||
uint32_t head_words = NRF_BALLOC_DEBUG_HEAD_GUARD_WORDS_GET(p_pool->debug_flags);
|
||||
uint32_t tail_words = NRF_BALLOC_DEBUG_TAIL_GUARD_WORDS_GET(p_pool->debug_flags);
|
||||
|
||||
uint32_t * p_head = (uint32_t *)p_element - head_words;
|
||||
uint32_t * p_tail = (uint32_t *)((size_t)(p_head) + p_pool->block_size);
|
||||
|
||||
for (uint32_t * ptr = p_head; ptr < (uint32_t *)p_element; ptr++)
|
||||
{
|
||||
if (*ptr != HEAD_GUARD_FILL)
|
||||
{
|
||||
NRF_LOG_ERROR("Detected Head Guard corruption at 0x%08X (0x%08X != 0x%08X, pool: '" POOL_MARKER "')",
|
||||
ptr, *ptr, HEAD_GUARD_FILL, POOL_ID(p_pool));
|
||||
APP_ERROR_CHECK_BOOL(false);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t * ptr = ( p_tail - tail_words); ptr < p_tail; ptr++)
|
||||
{
|
||||
if (*ptr != TAIL_GUARD_FILL)
|
||||
{
|
||||
NRF_LOG_ERROR("Detected Tail Guard corruption at 0x%08X (0x%08X != 0x%08X, pool: '" POOL_MARKER "')",
|
||||
ptr, *ptr, TAIL_GUARD_FILL, POOL_ID(p_pool));
|
||||
APP_ERROR_CHECK_BOOL(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (NRF_BALLOC_DEBUG_DATA_TRASHING_CHECK_GET(p_pool->debug_flags))
|
||||
{
|
||||
for (uint32_t * ptr = p_head; ptr < p_tail; ptr++)
|
||||
{
|
||||
*ptr = FREE_MEM_FILL;
|
||||
}
|
||||
}
|
||||
|
||||
return p_head;
|
||||
}
|
||||
|
||||
#endif // NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
|
||||
/**@brief Convert block index to a pointer.
|
||||
*
|
||||
* @param[in] p_pool Pointer to the memory pool.
|
||||
* @param[in] idx Index of the block.
|
||||
*
|
||||
* @return Pointer to the beginning of the block.
|
||||
*/
|
||||
static void * nrf_balloc_idx2block(nrf_balloc_t const * p_pool, uint8_t idx)
|
||||
{
|
||||
ASSERT(p_pool != NULL);
|
||||
return (uint8_t *)(p_pool->p_memory_begin) + ((size_t)(idx) * p_pool->block_size);
|
||||
}
|
||||
|
||||
/**@brief Convert block pointer to index.
|
||||
*
|
||||
* @param[in] p_pool Pointer to the memory pool.
|
||||
* @param[in] p_block Pointer to the beginning of the block.
|
||||
*
|
||||
* @return Index of the block.
|
||||
*/
|
||||
static uint8_t nrf_balloc_block2idx(nrf_balloc_t const * p_pool, void const * p_block)
|
||||
{
|
||||
ASSERT(p_pool != NULL);
|
||||
return ((size_t)(p_block) - (size_t)(p_pool->p_memory_begin)) / p_pool->block_size;
|
||||
}
|
||||
|
||||
ret_code_t nrf_balloc_init(nrf_balloc_t const * p_pool)
|
||||
{
|
||||
uint8_t pool_size;
|
||||
|
||||
VERIFY_PARAM_NOT_NULL(p_pool);
|
||||
|
||||
ASSERT(p_pool->p_cb);
|
||||
ASSERT(p_pool->p_stack_base);
|
||||
ASSERT(p_pool->p_stack_limit);
|
||||
ASSERT(p_pool->p_memory_begin);
|
||||
ASSERT(p_pool->block_size);
|
||||
|
||||
pool_size = p_pool->p_stack_limit - p_pool->p_stack_base;
|
||||
|
||||
#if NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
void *p_memory_end = (uint8_t *)(p_pool->p_memory_begin) + (pool_size * p_pool->block_size);
|
||||
if (NRF_BALLOC_DEBUG_DATA_TRASHING_CHECK_GET(p_pool->debug_flags))
|
||||
{
|
||||
for (uint32_t * ptr = p_pool->p_memory_begin; ptr < (uint32_t *)(p_memory_end); ptr++)
|
||||
{
|
||||
*ptr = FREE_MEM_FILL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
NRF_LOG_INFO("Pool '" POOL_MARKER "' initialized (size: %u x %u = %u bytes)",
|
||||
POOL_ID(p_pool),
|
||||
pool_size,
|
||||
p_pool->block_size,
|
||||
pool_size * p_pool->block_size);
|
||||
|
||||
p_pool->p_cb->p_stack_pointer = p_pool->p_stack_base;
|
||||
while (pool_size--)
|
||||
{
|
||||
*(p_pool->p_cb->p_stack_pointer)++ = pool_size;
|
||||
}
|
||||
|
||||
p_pool->p_cb->max_utilization = 0;
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
void * nrf_balloc_alloc(nrf_balloc_t const * p_pool)
|
||||
{
|
||||
ASSERT(p_pool != NULL);
|
||||
|
||||
void * p_block = NULL;
|
||||
|
||||
CRITICAL_REGION_ENTER();
|
||||
|
||||
if (p_pool->p_cb->p_stack_pointer > p_pool->p_stack_base)
|
||||
{
|
||||
// Allocate block.
|
||||
p_block = nrf_balloc_idx2block(p_pool, *--(p_pool->p_cb->p_stack_pointer));
|
||||
|
||||
// Update utilization statistics.
|
||||
uint8_t utilization = p_pool->p_stack_limit - p_pool->p_cb->p_stack_pointer;
|
||||
if (p_pool->p_cb->max_utilization < utilization)
|
||||
{
|
||||
p_pool->p_cb->max_utilization = utilization;
|
||||
}
|
||||
}
|
||||
|
||||
CRITICAL_REGION_EXIT();
|
||||
|
||||
#if NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
if (p_block != NULL)
|
||||
{
|
||||
p_block = nrf_balloc_block_unwrap(p_pool, p_block);
|
||||
}
|
||||
#endif
|
||||
|
||||
NRF_LOG_DEBUG("nrf_balloc_alloc(pool: '" POOL_MARKER "', element: 0x%08X)",
|
||||
POOL_ID(p_pool), p_block);
|
||||
|
||||
return p_block;
|
||||
}
|
||||
|
||||
void nrf_balloc_free(nrf_balloc_t const * p_pool, void * p_element)
|
||||
{
|
||||
ASSERT(p_pool != NULL);
|
||||
ASSERT(p_element != NULL)
|
||||
|
||||
NRF_LOG_DEBUG("nrf_balloc_free(pool: '" POOL_MARKER "', element: 0x%08X)",
|
||||
POOL_ID(p_pool), p_element);
|
||||
|
||||
#if NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
void * p_block = nrf_balloc_element_wrap(p_pool, p_element);
|
||||
|
||||
// These checks could be done outside critical region as they use only pool configuration data.
|
||||
if (NRF_BALLOC_DEBUG_BASIC_CHECKS_GET(p_pool->debug_flags))
|
||||
{
|
||||
uint8_t pool_size = p_pool->p_stack_limit - p_pool->p_stack_base;
|
||||
void *p_memory_end = (uint8_t *)(p_pool->p_memory_begin) + (pool_size * p_pool->block_size);
|
||||
|
||||
// Check if the element belongs to this pool.
|
||||
if ((p_block < p_pool->p_memory_begin) || (p_block >= p_memory_end))
|
||||
{
|
||||
NRF_LOG_ERROR("Attempted to free element that does belong to the pool (pool: '" POOL_MARKER "', element: 0x%08X)",
|
||||
POOL_ID(p_pool), p_element);
|
||||
APP_ERROR_CHECK_BOOL(false);
|
||||
}
|
||||
|
||||
// Check if the pointer is valid.
|
||||
if ((((size_t)(p_block) - (size_t)(p_pool->p_memory_begin)) % p_pool->block_size) != 0)
|
||||
{
|
||||
NRF_LOG_ERROR("Atempted to free corrupted element address (pool: '" POOL_MARKER "', element: 0x%08X)",
|
||||
POOL_ID(p_pool), p_element);
|
||||
APP_ERROR_CHECK_BOOL(false);
|
||||
}
|
||||
}
|
||||
#else
|
||||
void * p_block = p_element;
|
||||
#endif // NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
|
||||
CRITICAL_REGION_ENTER();
|
||||
|
||||
#if NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
// These checks have to be done in critical region as they use p_pool->p_stack_pointer.
|
||||
if (NRF_BALLOC_DEBUG_BASIC_CHECKS_GET(p_pool->debug_flags))
|
||||
{
|
||||
// Check for allocated/free ballance.
|
||||
if (p_pool->p_cb->p_stack_pointer >= p_pool->p_stack_limit)
|
||||
{
|
||||
NRF_LOG_ERROR("Attempted to free an element while the pool is full (pool: '" POOL_MARKER "', element: 0x%08X)",
|
||||
POOL_ID(p_pool), p_element);
|
||||
APP_ERROR_CHECK_BOOL(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (NRF_BALLOC_DEBUG_DOUBLE_FREE_CHECK_GET(p_pool->debug_flags))
|
||||
{
|
||||
// Check for double free.
|
||||
for (uint8_t * p_idx = p_pool->p_stack_base; p_idx < p_pool->p_cb->p_stack_pointer; p_idx++)
|
||||
{
|
||||
if (nrf_balloc_idx2block(p_pool, *p_idx) == p_block)
|
||||
{
|
||||
NRF_LOG_ERROR("Attempted to double-free an element (pool: '" POOL_MARKER "', element: 0x%08X)",
|
||||
POOL_ID(p_pool), p_element);
|
||||
APP_ERROR_CHECK_BOOL(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
|
||||
// Free the element.
|
||||
*(p_pool->p_cb->p_stack_pointer)++ = nrf_balloc_block2idx(p_pool, p_block);
|
||||
|
||||
CRITICAL_REGION_EXIT();
|
||||
}
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_BALLOC)
|
||||
@@ -0,0 +1,309 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @defgroup nrf_balloc Block memory allocator
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
* @brief This module handles block memory allocator features.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef NRF_BALLOC_H__
|
||||
#define NRF_BALLOC_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "sdk_errors.h"
|
||||
#include "sdk_config.h"
|
||||
#include "app_util_platform.h"
|
||||
#include "app_util.h"
|
||||
/**@defgroup NRF_BALLOC_DEBUG Macros for preparing debug flags for block allocator module.
|
||||
* @{ */
|
||||
#define NRF_BALLOC_DEBUG_HEAD_GUARD_WORDS_SET(words) (((words) & 0xFF) << 0)
|
||||
#define NRF_BALLOC_DEBUG_HEAD_GUARD_WORDS_GET(flags) (((flags) >> 0) & 0xFF)
|
||||
#define NRF_BALLOC_DEBUG_TAIL_GUARD_WORDS_SET(words) (((words) & 0xFF) << 8)
|
||||
#define NRF_BALLOC_DEBUG_TAIL_GUARD_WORDS_GET(flags) (((flags) >> 8) & 0xFF)
|
||||
|
||||
#define NRF_BALLOC_DEBUG_BASIC_CHECKS_SET(enable) (!!(enable) << 16)
|
||||
#define NRF_BALLOC_DEBUG_BASIC_CHECKS_GET(flags) (flags & (1 << 16))
|
||||
#define NRF_BALLOC_DEBUG_DOUBLE_FREE_CHECK_SET(enable) (!!(enable) << 17)
|
||||
#define NRF_BALLOC_DEBUG_DOUBLE_FREE_CHECK_GET(flags) (flags & (1 << 17))
|
||||
#define NRF_BALLOC_DEBUG_DATA_TRASHING_CHECK_SET(enable) (!!(enable) << 18)
|
||||
#define NRF_BALLOC_DEBUG_DATA_TRASHING_CHECK_GET(flags) (flags & (1 << 18))
|
||||
/**@} */
|
||||
|
||||
/**@brief Default debug flags for @ref nrf_balloc. This is used by the @ref NRF_BALLOC_DEF macro.
|
||||
* Flags can be changed in @ref sdk_config.
|
||||
*/
|
||||
#if NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
#define NRF_BALLOC_DEFAULT_DEBUG_FLAGS \
|
||||
( \
|
||||
NRF_BALLOC_DEBUG_HEAD_GUARD_WORDS_SET(NRF_BALLOC_CONFIG_HEAD_GUARD_WORDS) | \
|
||||
NRF_BALLOC_DEBUG_TAIL_GUARD_WORDS_SET(NRF_BALLOC_CONFIG_TAIL_GUARD_WORDS) | \
|
||||
NRF_BALLOC_DEBUG_BASIC_CHECKS_SET(NRF_BALLOC_CONFIG_BASIC_CHECKS_ENABLED) | \
|
||||
NRF_BALLOC_DEBUG_DOUBLE_FREE_CHECK_SET(NRF_BALLOC_CONFIG_DOUBLE_FREE_CHECK_ENABLED) | \
|
||||
NRF_BALLOC_DEBUG_DATA_TRASHING_CHECK_SET(NRF_BALLOC_CONFIG_DATA_TRASHING_CHECK_ENABLED) \
|
||||
)
|
||||
#else
|
||||
#define NRF_BALLOC_DEFAULT_DEBUG_FLAGS 0
|
||||
#endif // NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
|
||||
/**@brief Block memory allocator control block.*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t * p_stack_pointer; //!< Current allocation stack pointer.
|
||||
uint8_t max_utilization; //!< Maximum utilization of the memory pool.
|
||||
} nrf_balloc_cb_t;
|
||||
|
||||
/**@brief Block memory allocator pool instance. The pool is made of elements of the same size. */
|
||||
typedef struct
|
||||
{
|
||||
nrf_balloc_cb_t * p_cb; //!< Pointer to the instance control block.
|
||||
uint8_t * p_stack_base; //!< Base of the allocation stack.
|
||||
/**<
|
||||
* Stack is used to store handlers to not allocated elements.
|
||||
*/
|
||||
uint8_t * p_stack_limit; //!< Maximum possible value of the allocation stack pointer.
|
||||
void * p_memory_begin; //!< Pointer to the start of the memory pool.
|
||||
/**<
|
||||
* Memory is used as a heap for blocks.
|
||||
*/
|
||||
|
||||
#if NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
const char * p_name; //!< Pointer to string with pool name.
|
||||
uint32_t debug_flags; //!< Debugging settings.
|
||||
/**<
|
||||
* Debug flag should be created by @ref NRF_BALLOC_DEBUG.
|
||||
*/
|
||||
#endif // NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
uint16_t block_size; //!< Size of the allocated block (including debug overhead).
|
||||
/**<
|
||||
* Single block contains user element with header and tail
|
||||
* words.
|
||||
*/
|
||||
} nrf_balloc_t;
|
||||
|
||||
/**@brief Get total memory consumed by single block (element size with overhead caused by debug
|
||||
* flags).
|
||||
*
|
||||
* @param[in] _element_size Size of an element.
|
||||
* @param[in] _debug_flags Debug flags.
|
||||
*/
|
||||
#if NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
#define NRF_BALLOC_BLOCK_SIZE(_element_size, _debug_flags) \
|
||||
( \
|
||||
(sizeof(uint32_t) * NRF_BALLOC_DEBUG_HEAD_GUARD_WORDS_GET(_debug_flags)) + \
|
||||
ALIGN_NUM(sizeof(uint32_t), (_element_size)) + \
|
||||
(sizeof(uint32_t) * NRF_BALLOC_DEBUG_TAIL_GUARD_WORDS_GET(_debug_flags)) \
|
||||
)
|
||||
#else
|
||||
#define NRF_BALLOC_BLOCK_SIZE(_element_size, _debug_flags) \
|
||||
ALIGN_NUM(sizeof(uint32_t), (_element_size))
|
||||
#endif // NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
|
||||
|
||||
/**@brief Get element size ( excluding debugging overhead is present)
|
||||
* flags).
|
||||
*
|
||||
* @param[in] _p_balloc Pointer to balloc instance.
|
||||
*/
|
||||
#if NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
#define NRF_BALLOC_ELEMENT_SIZE(_p_balloc) \
|
||||
(ALIGN_NUM(sizeof(uint32_t), (_p_balloc)->block_size) - \
|
||||
((sizeof(uint32_t) * NRF_BALLOC_DEBUG_HEAD_GUARD_WORDS_GET((_p_balloc)->debug_flags)) + \
|
||||
(sizeof(uint32_t) * NRF_BALLOC_DEBUG_TAIL_GUARD_WORDS_GET((_p_balloc)->debug_flags))))
|
||||
#else
|
||||
#define NRF_BALLOC_ELEMENT_SIZE(_p_balloc) \
|
||||
(_p_balloc)->block_size
|
||||
#endif // NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
|
||||
#if NRF_BALLOC_CONFIG_DEBUG_ENABLED
|
||||
#define __NRF_BALLOC_ASSIGN_POOL_NAME(_name) .p_name = STRINGIFY(_name),
|
||||
#define __NRF_BALLOC_ASSIGN_DEBUG_FLAGS(_debug_flags) .debug_flags = (_debug_flags),
|
||||
#else
|
||||
#define __NRF_BALLOC_ASSIGN_DEBUG_FLAGS(_debug_flags)
|
||||
#define __NRF_BALLOC_ASSIGN_POOL_NAME(_name)
|
||||
#endif
|
||||
|
||||
|
||||
/**@brief Create a block allocator instance with custom debug flags.
|
||||
*
|
||||
* @note This macro reserves memory for the given block allocator instance.
|
||||
*
|
||||
* @param[in] _name Name of the allocator.
|
||||
* @param[in] _element_size Size of one element.
|
||||
* @param[in] _pool_size Size of the pool.
|
||||
* @param[in] _debug_flags Debug flags (@ref NRF_BALLOC_DEBUG).
|
||||
*/
|
||||
#define NRF_BALLOC_DBG_DEF(_name, _element_size, _pool_size, _debug_flags) \
|
||||
STATIC_ASSERT((_pool_size) <= UINT8_MAX); \
|
||||
static uint8_t CONCAT_2(_name, _nrf_balloc_pool_stack)[(_pool_size)]; \
|
||||
static uint32_t CONCAT_2(_name,_nrf_balloc_pool_mem) \
|
||||
[NRF_BALLOC_BLOCK_SIZE(_element_size, _debug_flags) * (_pool_size) / sizeof(uint32_t)]; \
|
||||
static nrf_balloc_cb_t CONCAT_2(_name,_nrf_balloc_cb); \
|
||||
static const nrf_balloc_t _name = \
|
||||
{ \
|
||||
.p_cb = &CONCAT_2(_name,_nrf_balloc_cb), \
|
||||
.p_stack_base = CONCAT_2(_name,_nrf_balloc_pool_stack), \
|
||||
.p_stack_limit = CONCAT_2(_name,_nrf_balloc_pool_stack) + (_pool_size), \
|
||||
.p_memory_begin = CONCAT_2(_name,_nrf_balloc_pool_mem), \
|
||||
.block_size = NRF_BALLOC_BLOCK_SIZE(_element_size, _debug_flags), \
|
||||
\
|
||||
__NRF_BALLOC_ASSIGN_POOL_NAME(_name) \
|
||||
__NRF_BALLOC_ASSIGN_DEBUG_FLAGS(_debug_flags) \
|
||||
}
|
||||
|
||||
/**@brief Create a block allocator instance.
|
||||
*
|
||||
* @note This macro reserves memory for the given block allocator instance.
|
||||
*
|
||||
* @param[in] _name Name of the allocator.
|
||||
* @param[in] _element_size Size of one element.
|
||||
* @param[in] _pool_size Size of the pool.
|
||||
*/
|
||||
#define NRF_BALLOC_DEF(_name, _element_size, _pool_size) \
|
||||
NRF_BALLOC_DBG_DEF(_name, _element_size, _pool_size, NRF_BALLOC_DEFAULT_DEBUG_FLAGS)
|
||||
|
||||
/**@brief Create a block allocator interface.
|
||||
*
|
||||
* @param[in] _type Type which is allocated.
|
||||
* @param[in] _name Name of the allocator.
|
||||
*/
|
||||
#define NRF_BALLOC_INTERFACE_DEC(_type, _name) \
|
||||
_type * CONCAT_2(_name,_alloc)(void); \
|
||||
void CONCAT_2(_name,_free)(_type * p_element)
|
||||
|
||||
/**@brief Define a custom block allocator interface.
|
||||
*
|
||||
* @param[in] _attr Function attribute that will be added to allocator function definition.
|
||||
* @param[in] _type Type which is allocated.
|
||||
* @param[in] _name Name of the allocator.
|
||||
* @param[in] _p_pool Pool from which data will be allocated.
|
||||
*/
|
||||
#define NRF_BALLOC_INTERFACE_CUSTOM_DEF(_attr, _type, _name, _p_pool) \
|
||||
_attr _type * CONCAT_2(_name,_alloc)(void) \
|
||||
{ \
|
||||
GCC_PRAGMA("GCC diagnostic push") \
|
||||
GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \
|
||||
ASSERT((_p_pool) != NULL); \
|
||||
ASSERT((_p_pool)->block_size >= \
|
||||
NRF_BALLOC_BLOCK_SIZE(sizeof(_type), (_p_pool)->debug_flags)); \
|
||||
GCC_PRAGMA("GCC diagnostic pop") \
|
||||
return (_type *)(nrf_balloc_alloc(_p_pool)); \
|
||||
} \
|
||||
\
|
||||
_attr void CONCAT_2(_name,_free)(_type * p_element) \
|
||||
{ \
|
||||
GCC_PRAGMA("GCC diagnostic push") \
|
||||
GCC_PRAGMA("GCC diagnostic ignored \"-Waddress\"") \
|
||||
ASSERT((_p_pool) != NULL); \
|
||||
ASSERT((_p_pool)->block_size >= \
|
||||
NRF_BALLOC_BLOCK_SIZE(sizeof(_type), (_p_pool)->debug_flags)); \
|
||||
GCC_PRAGMA("GCC diagnostic pop") \
|
||||
nrf_balloc_free((_p_pool), p_element); \
|
||||
}
|
||||
|
||||
/**@brief Define block allocator interface.
|
||||
*
|
||||
* @param[in] _type Type which is allocated.
|
||||
* @param[in] _name Name of the allocator.
|
||||
* @param[in] _p_pool Pool from which data will be allocated.
|
||||
*/
|
||||
#define NRF_BALLOC_INTERFACE_DEF(_type, _name, _p_pool) \
|
||||
NRF_BALLOC_INTERFACE_CUSTOM_DEF(/* empty */, _type, _name, _p_pool)
|
||||
|
||||
/**@brief Define a local block allocator interface.
|
||||
*
|
||||
* @param[in] _type Type which is allocated.
|
||||
* @param[in] _name Name of the allocator.
|
||||
* @param[in] _p_pool Pool from which data will be allocated.
|
||||
*/
|
||||
#define NRF_BALLOC_INTERFACE_LOCAL_DEF(_type, _name, _p_pool) \
|
||||
NRF_BALLOC_INTERFACE_CUSTOM_DEF(static, _type, _name, _p_pool)
|
||||
|
||||
/**@brief Function for initializing a block memory allocator pool.
|
||||
*
|
||||
* @param[out] p_pool Pointer to the pool that is to be initialized.
|
||||
*
|
||||
* @return NRF_SUCCESS on success, otherwise error code.
|
||||
*/
|
||||
ret_code_t nrf_balloc_init(nrf_balloc_t const * p_pool);
|
||||
|
||||
/**@brief Function for allocating an element from the pool.
|
||||
*
|
||||
* @note This module guarantees that the returned memory is aligned to 4.
|
||||
*
|
||||
* @param[in] p_pool Pointer to the memory pool from which the element will be allocated.
|
||||
*
|
||||
* @return Allocated element or NULL if the specified pool is empty.
|
||||
*/
|
||||
void * nrf_balloc_alloc(nrf_balloc_t const * p_pool);
|
||||
|
||||
/**@brief Function for freeing an element back to the pool.
|
||||
*
|
||||
* @param[in] p_pool Pointer to the memory pool.
|
||||
* @param[in] p_element Element to be freed.
|
||||
*/
|
||||
void nrf_balloc_free(nrf_balloc_t const * p_pool, void * p_element);
|
||||
|
||||
/**@brief Function for getting maximum memory pool utilization.
|
||||
*
|
||||
* @param[in] p_pool Pointer to the memory pool instance.
|
||||
*
|
||||
* @return Maximum number of elements allocated from the pool.
|
||||
*/
|
||||
__STATIC_INLINE uint8_t nrf_balloc_max_utilization_get(nrf_balloc_t const * p_pool);
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
__STATIC_INLINE uint8_t nrf_balloc_max_utilization_get(nrf_balloc_t const * p_pool)
|
||||
{
|
||||
ASSERT(p_pool != NULL);
|
||||
return p_pool->p_cb->max_utilization;
|
||||
}
|
||||
#endif //SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_BALLOC_H__
|
||||
/** @} */
|
||||
@@ -0,0 +1,234 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**@file
|
||||
*
|
||||
* @defgroup nrf_log Logger module
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @brief The nrf_log module interface.
|
||||
*/
|
||||
|
||||
#ifndef NRF_LOG_H_
|
||||
#define NRF_LOG_H_
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include "nrf_section.h"
|
||||
#if NRF_MODULE_ENABLED(NRF_LOG)
|
||||
#include "nrf_strerror.h"
|
||||
#define NRF_LOG_ERROR_STRING_GET(code) nrf_strerror_get(code)
|
||||
#else
|
||||
#define NRF_LOG_ERROR_STRING_GET(code) ""
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief Severity level for the module.
|
||||
*
|
||||
* The severity level can be defined in a module to override the default.
|
||||
*/
|
||||
#ifndef NRF_LOG_LEVEL
|
||||
#define NRF_LOG_LEVEL NRF_LOG_DEFAULT_LEVEL
|
||||
#endif
|
||||
|
||||
|
||||
#include "nrf_log_internal.h"
|
||||
|
||||
/** @def NRF_LOG_ERROR
|
||||
* @brief Macro for logging error messages. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*/
|
||||
|
||||
/** @def NRF_LOG_WARNING
|
||||
* @brief Macro for logging error messages. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes warning logs.
|
||||
*/
|
||||
|
||||
/** @def NRF_LOG_INFO
|
||||
* @brief Macro for logging error messages. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes info logs.
|
||||
*/
|
||||
|
||||
/** @def NRF_LOG_DEBUG
|
||||
* @brief Macro for logging error messages. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes debug logs.
|
||||
*/
|
||||
|
||||
#define NRF_LOG_ERROR(...) NRF_LOG_INTERNAL_ERROR(__VA_ARGS__)
|
||||
#define NRF_LOG_WARNING(...) NRF_LOG_INTERNAL_WARNING( __VA_ARGS__)
|
||||
#define NRF_LOG_INFO(...) NRF_LOG_INTERNAL_INFO( __VA_ARGS__)
|
||||
#define NRF_LOG_DEBUG(...) NRF_LOG_INTERNAL_DEBUG( __VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief A macro for logging a formatted string without any prefix or timestamp.
|
||||
*/
|
||||
#define NRF_LOG_RAW_INFO(...) NRF_LOG_INTERNAL_RAW_INFO( __VA_ARGS__)
|
||||
|
||||
/** @def NRF_LOG_HEXDUMP_ERROR
|
||||
* @brief Macro for logging raw bytes.
|
||||
* @details It is compiled in only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
/** @def NRF_LOG_HEXDUMP_WARNING
|
||||
* @brief Macro for logging raw bytes.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes warning logs.
|
||||
*
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
/** @def NRF_LOG_HEXDUMP_INFO
|
||||
* @brief Macro for logging raw bytes.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes info logs.
|
||||
*
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
/** @def NRF_LOG_HEXDUMP_DEBUG
|
||||
* @brief Macro for logging raw bytes.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes debug logs.
|
||||
*
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
#define NRF_LOG_HEXDUMP_ERROR(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_ERROR(p_data, len)
|
||||
#define NRF_LOG_HEXDUMP_WARNING(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_WARNING(p_data, len)
|
||||
#define NRF_LOG_HEXDUMP_INFO(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_INFO(p_data, len)
|
||||
#define NRF_LOG_HEXDUMP_DEBUG(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_DEBUG(p_data, len)
|
||||
|
||||
/**
|
||||
* @brief Macro for logging hexdump without any prefix or timestamp.
|
||||
*/
|
||||
#define NRF_LOG_RAW_HEXDUMP_INFO(p_data, len) NRF_LOG_INTERNAL_RAW_HEXDUMP_INFO(p_data, len)
|
||||
|
||||
/**
|
||||
* @brief A macro for blocking reading from bidirectional backend used for logging.
|
||||
*
|
||||
* Macro call is blocking and returns when single byte is received.
|
||||
*/
|
||||
#define NRF_LOG_GETCHAR() NRF_LOG_INTERNAL_GETCHAR()
|
||||
|
||||
/**
|
||||
* @brief A macro for copying a string to internal logger buffer if logs are deferred.
|
||||
*
|
||||
* @param _str String.
|
||||
*/
|
||||
#define NRF_LOG_PUSH(_str) NRF_LOG_INTERNAL_LOG_PUSH(_str)
|
||||
|
||||
/**
|
||||
* @brief Function for copying a string to the internal logger buffer if logs are deferred.
|
||||
*
|
||||
* Use this function to store a string that is volatile (for example allocated
|
||||
* on stack) or that may change before the deferred logs are processed. Such string is copied
|
||||
* into the internal logger buffer and is persistent until the log is processed.
|
||||
*
|
||||
* @note If the logs are not deferred, then this function returns the input parameter.
|
||||
*
|
||||
* @param p_str Pointer to the user string.
|
||||
*
|
||||
* @return Address to the location where the string is stored in the internal logger buffer.
|
||||
*/
|
||||
uint32_t nrf_log_push(char * const p_str);
|
||||
|
||||
/**
|
||||
* @brief Macro to be used in a formatted string to a pass float number to the log.
|
||||
*
|
||||
* Macro should be used in formatted string instead of the %f specifier together with
|
||||
* @ref NRF_LOG_FLOAT macro.
|
||||
* Example: NRF_LOG_INFO("My float number" NRF_LOG_FLOAT_MARKER "\r\n", NRF_LOG_FLOAT(f)))
|
||||
*/
|
||||
#define NRF_LOG_FLOAT_MARKER "%s%d.%02d"
|
||||
|
||||
/**
|
||||
* @brief Macro for dissecting a float number into two numbers (integer and residuum).
|
||||
*/
|
||||
#define NRF_LOG_FLOAT(val) (uint32_t)(((val) < 0 && (val) > -1.0) ? "-" : ""), \
|
||||
(int32_t)(val), \
|
||||
(int32_t)((((val) > 0) ? (val) - (int32_t)(val) \
|
||||
: (int32_t)(val) - (val))*100)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @def NRF_LOG_MODULE_REGISTER
|
||||
* @brief Macro for registering an independent module.
|
||||
*/
|
||||
#if NRF_LOG_ENABLED
|
||||
|
||||
#ifdef UNIT_TEST
|
||||
#define _CONST
|
||||
#define COMPILED_LOG_LEVEL 4
|
||||
#else
|
||||
#define _CONST const
|
||||
#define COMPILED_LOG_LEVEL NRF_LOG_LEVEL
|
||||
#endif
|
||||
#define NRF_LOG_MODULE_REGISTER() \
|
||||
NRF_SECTION_ITEM_REGISTER(NRF_LOG_CONST_SECTION_NAME(NRF_LOG_MODULE_NAME), \
|
||||
_CONST nrf_log_module_const_data_t NRF_LOG_MODULE_DATA_CONST) = { \
|
||||
.p_module_name = STRINGIFY(NRF_LOG_MODULE_NAME), \
|
||||
.info_color_id = NRF_LOG_INFO_COLOR, \
|
||||
.debug_color_id = NRF_LOG_DEBUG_COLOR, \
|
||||
.compiled_lvl = COMPILED_LOG_LEVEL, \
|
||||
}; \
|
||||
NRF_SECTION_ITEM_REGISTER(NRF_LOG_DYNAMIC_SECTION_NAME(NRF_LOG_MODULE_NAME), \
|
||||
nrf_log_module_dynamic_data_t NRF_LOG_MODULE_DATA_DYNAMIC)
|
||||
#else
|
||||
#define NRF_LOG_MODULE_REGISTER() /*lint -save -e19*/ /*lint -restore*/
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_LOG_H_
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,218 @@
|
||||
/**
|
||||
* Copyright (c) 2017 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef NRF_LOG_BACKEND_INTERFACE_H
|
||||
#define NRF_LOG_BACKEND_INTERFACE_H
|
||||
|
||||
/**@file
|
||||
* @addtogroup nrf_log Logger module
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @defgroup nrf_log_backend_interface Logger backend interface
|
||||
* @{
|
||||
* @ingroup nrf_log
|
||||
* @brief The nrf_log backend interface.
|
||||
*/
|
||||
|
||||
#include "nrf_memobj.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief nrf_log entry.
|
||||
*/
|
||||
typedef nrf_memobj_t nrf_log_entry_t;
|
||||
|
||||
/* Forward declaration of the nrf_log_backend_t type. */
|
||||
typedef struct nrf_log_backend_s nrf_log_backend_t;
|
||||
|
||||
/**
|
||||
* @brief Logger backend API.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/**
|
||||
* @brief @ref nrf_log_backend_put
|
||||
*/
|
||||
void (*put)(nrf_log_backend_t const * p_backend, nrf_log_entry_t * p_entry);
|
||||
|
||||
/**
|
||||
* @brief @ref nrf_log_backend_panic_set
|
||||
*/
|
||||
void (*panic_set)(nrf_log_backend_t const * p_backend);
|
||||
|
||||
/**
|
||||
* @brief @ref nrf_log_backend_flush
|
||||
*/
|
||||
void (*flush)(nrf_log_backend_t const * p_backend);
|
||||
} nrf_log_backend_api_t;
|
||||
|
||||
/**
|
||||
* @brief Logger backend structure.
|
||||
*/
|
||||
struct nrf_log_backend_s
|
||||
{
|
||||
nrf_log_backend_api_t const * p_api; //!< Pointer to interface.
|
||||
nrf_log_backend_t * p_next; //!< Pointer to next backend added to the logger.
|
||||
uint8_t id; //!< Backend id.
|
||||
bool enabled;//!< Flag indicating backend status.
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Function for putting message with log entry to the backend.
|
||||
*
|
||||
* @param[in] p_backend Pointer to the backend instance.
|
||||
* @param[in] p_msg Pointer to message with log entry.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_log_backend_put(nrf_log_backend_t const * p_backend,
|
||||
nrf_log_entry_t * p_msg);
|
||||
|
||||
/**
|
||||
* @brief Function for reconfiguring backend to panic mode.
|
||||
*
|
||||
* @param[in] p_backend Pointer to the backend instance.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_log_backend_panic_set(nrf_log_backend_t const * p_backend);
|
||||
|
||||
/**
|
||||
* @brief Function for flushing backend.
|
||||
*
|
||||
* @param[in] p_backend Pointer to the backend instance.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_log_backend_flush(nrf_log_backend_t const * p_backend);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for setting backend id.
|
||||
*
|
||||
* @note It is used internally by the logger.
|
||||
*
|
||||
* @param[in] p_backend Pointer to the backend instance.
|
||||
* @param[in] id Id.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_log_backend_id_set(nrf_log_backend_t * p_backend, uint8_t id);
|
||||
|
||||
/**
|
||||
* @brief Function for getting backend id.
|
||||
*
|
||||
* @note It is used internally by the logger.
|
||||
*
|
||||
* @param[in] p_backend Pointer to the backend instance.
|
||||
* @return Id.
|
||||
*/
|
||||
__STATIC_INLINE uint8_t nrf_log_backend_id_get(nrf_log_backend_t const * p_backend);
|
||||
|
||||
/**
|
||||
* @brief Function for enabling backend.
|
||||
*
|
||||
* @param[in] p_backend Pointer to the backend instance.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_log_backend_enable(nrf_log_backend_t * p_backend);
|
||||
|
||||
/**
|
||||
* @brief Function for disabling backend.
|
||||
*
|
||||
* @param[in] p_backend Pointer to the backend instance.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_log_backend_disable(nrf_log_backend_t * p_backend);
|
||||
|
||||
/**
|
||||
* @brief Function for checking state of the backend.
|
||||
*
|
||||
* @param[in] p_backend Pointer to the backend instance.
|
||||
*
|
||||
* @return True if backend is enabled, false otherwise.
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_log_backend_is_enabled(nrf_log_backend_t const * p_backend);
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
__STATIC_INLINE void nrf_log_backend_put(nrf_log_backend_t const * p_backend,
|
||||
nrf_log_entry_t * p_msg)
|
||||
{
|
||||
p_backend->p_api->put(p_backend, p_msg);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_log_backend_panic_set(nrf_log_backend_t const * p_backend)
|
||||
{
|
||||
p_backend->p_api->panic_set(p_backend);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_log_backend_flush(nrf_log_backend_t const * p_backend)
|
||||
{
|
||||
p_backend->p_api->panic_set(p_backend);
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_log_backend_id_set(nrf_log_backend_t * p_backend, uint8_t id)
|
||||
{
|
||||
p_backend->id = id;
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint8_t nrf_log_backend_id_get(nrf_log_backend_t const * p_backend)
|
||||
{
|
||||
return p_backend->id;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_log_backend_enable(nrf_log_backend_t * p_backend)
|
||||
{
|
||||
p_backend->enabled = true;
|
||||
}
|
||||
|
||||
__STATIC_INLINE void nrf_log_backend_disable(nrf_log_backend_t * p_backend)
|
||||
{
|
||||
p_backend->enabled = false;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_log_backend_is_enabled(nrf_log_backend_t const * p_backend)
|
||||
{
|
||||
return p_backend->enabled;
|
||||
}
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //NRF_LOG_BACKEND_INTERFACE_H
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Copyright (c) 2017 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/**@file
|
||||
*
|
||||
* @defgroup nrf_log_backend_rtt Log RTT backend
|
||||
* @{
|
||||
* @ingroup nrf_log
|
||||
* @brief Log RTT backend.
|
||||
*/
|
||||
|
||||
#ifndef NRF_LOG_BACKEND_RTT_H
|
||||
#define NRF_LOG_BACKEND_RTT_H
|
||||
|
||||
#include "nrf_log_backend_interface.h"
|
||||
|
||||
extern const nrf_log_backend_api_t nrf_log_backend_rtt_api;
|
||||
|
||||
typedef struct {
|
||||
nrf_log_backend_t backend;
|
||||
} nrf_log_backend_rtt_t;
|
||||
|
||||
/**
|
||||
* @brief RTT backend definition
|
||||
*
|
||||
* @param _name Name of the instance.
|
||||
*/
|
||||
#define NRF_LOG_BACKEND_RTT_DEF(_name) \
|
||||
static nrf_log_backend_rtt_t _name = { \
|
||||
.backend = {.p_api = &nrf_log_backend_rtt_api}, \
|
||||
}
|
||||
|
||||
void nrf_log_backend_rtt_init(void);
|
||||
#endif //NRF_LOG_BACKEND_RTT_H
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/**@file
|
||||
*
|
||||
* @defgroup nrf_log_backend_uart Log UART backend
|
||||
* @{
|
||||
* @ingroup nrf_log
|
||||
* @brief Log UART backend.
|
||||
*/
|
||||
|
||||
#ifndef NRF_LOG_BACKEND_UART_H
|
||||
#define NRF_LOG_BACKEND_UART_H
|
||||
|
||||
#include "nrf_log_backend_interface.h"
|
||||
|
||||
extern const nrf_log_backend_api_t nrf_log_backend_uart_api;
|
||||
|
||||
typedef struct {
|
||||
nrf_log_backend_t backend;
|
||||
} nrf_log_backend_uart_t;
|
||||
|
||||
#define NRF_LOG_BACKEND_UART_DEF(name) \
|
||||
static nrf_log_backend_uart_t name = { \
|
||||
.backend = {.p_api = &nrf_log_backend_uart_api}, \
|
||||
}
|
||||
|
||||
void nrf_log_backend_uart_init(void);
|
||||
#endif //NRF_LOG_BACKEND_UART_H
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,233 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef NRF_LOG_CTRL_H
|
||||
#define NRF_LOG_CTRL_H
|
||||
|
||||
/**@file
|
||||
* @addtogroup nrf_log Logger module
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @defgroup nrf_log_ctrl Functions for controlling nrf_log
|
||||
* @{
|
||||
* @ingroup nrf_log
|
||||
* @brief The nrf_log control interface.
|
||||
*/
|
||||
|
||||
#include "sdk_config.h"
|
||||
#include "sdk_errors.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "nrf_log_ctrl_internal.h"
|
||||
#include "nrf_log_backend_interface.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
NRF_LOG_SEVERITY_NONE,
|
||||
NRF_LOG_SEVERITY_ERROR,
|
||||
NRF_LOG_SEVERITY_WARNING,
|
||||
NRF_LOG_SEVERITY_INFO,
|
||||
NRF_LOG_SEVERITY_DEBUG,
|
||||
} nrf_log_severity_t;
|
||||
|
||||
/**
|
||||
* @brief Timestamp function prototype.
|
||||
*
|
||||
* @return Timestamp value.
|
||||
*/
|
||||
typedef uint32_t (*nrf_log_timestamp_func_t)(void);
|
||||
|
||||
/**@brief Macro for initializing the logs.
|
||||
*
|
||||
* @note If timestamps are disabled in the configuration, then the provided pointer
|
||||
* can be NULL. Otherwise, it is expected that timestamp_getter is not NULL.
|
||||
*
|
||||
* @param timestamp_func Function that returns the timestamp.
|
||||
*
|
||||
* @return NRF_SUCCESS after successful initialization, otherwise an error code.
|
||||
*/
|
||||
#define NRF_LOG_INIT(timestamp_func) NRF_LOG_INTERNAL_INIT(timestamp_func)
|
||||
|
||||
|
||||
/**@brief Macro for processing a single log entry from a queue of deferred logs.
|
||||
*
|
||||
* You can call this macro from the main context or from the error handler to process
|
||||
* log entries one by one.
|
||||
*
|
||||
* @note If logs are not deferred, this call has no use and is defined as 'false'.
|
||||
*
|
||||
* @retval true There are more logs to process in the buffer.
|
||||
* @retval false No more logs in the buffer.
|
||||
*/
|
||||
#define NRF_LOG_PROCESS() NRF_LOG_INTERNAL_PROCESS()
|
||||
|
||||
/** @brief Macro for processing all log entries from the buffer.
|
||||
* It blocks until all buffered entries are processed by the backend.
|
||||
*
|
||||
* @note If logs are not deferred, this call has no use and is empty.
|
||||
*/
|
||||
#define NRF_LOG_FLUSH() NRF_LOG_INTERNAL_FLUSH()
|
||||
|
||||
/** @brief Macro for flushing log data before reset.
|
||||
*
|
||||
* @note If logs are not deferred, this call has no use and is empty.
|
||||
*
|
||||
* @note If RTT is used, then a breakpoint is hit once flushed.
|
||||
*/
|
||||
#define NRF_LOG_FINAL_FLUSH() NRF_LOG_INTERNAL_FINAL_FLUSH()
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the frontend and the default backend.
|
||||
*
|
||||
* @ref NRF_LOG_INIT calls this function to initialize the frontend and the backend.
|
||||
* If custom backend is used, then @ref NRF_LOG_INIT should not be called.
|
||||
* Instead, frontend and user backend should be verbosely initialized.
|
||||
*
|
||||
* @param timestamp_func Function for getting a 32-bit timestamp.
|
||||
*
|
||||
* @return Error status.
|
||||
*
|
||||
*/
|
||||
ret_code_t nrf_log_init(nrf_log_timestamp_func_t timestamp_func);
|
||||
|
||||
/**
|
||||
* @brief Function for adding new backend interface to the logger.
|
||||
*
|
||||
* @param p_backend Pointer to the backend interface.
|
||||
* @param severity Initial value of severity level for each module forwarded to the backend. This
|
||||
* option is only applicable if @ref NRF_LOG_FILTERS_ENABLED is set.
|
||||
* @return -1 if backend cannot be added or positive number (backend ID).
|
||||
*/
|
||||
int32_t nrf_log_backend_add(nrf_log_backend_t * p_backend, nrf_log_severity_t severity);
|
||||
|
||||
/**
|
||||
* @brief Function for removing backend from the logger.
|
||||
*
|
||||
* @param p_backend Pointer to the backend interface.
|
||||
*
|
||||
*/
|
||||
void nrf_log_backend_remove(nrf_log_backend_t * p_backend);
|
||||
|
||||
/**
|
||||
* @brief Function for setting logger backends into panic mode.
|
||||
*
|
||||
* When this function is called all attached backends are informed about panic state of the system.
|
||||
* It is up to the backend to react properly (hold or process logs in blocking mode, etc.)
|
||||
*/
|
||||
void nrf_log_panic(void);
|
||||
|
||||
/**
|
||||
* @brief Function for handling a single log entry.
|
||||
*
|
||||
* Use this function only if the logs are buffered. It takes a single entry from the
|
||||
* buffer and attempts to process it.
|
||||
*
|
||||
* @retval true If there are more entries to process.
|
||||
* @retval false If there are no more entries to process.
|
||||
*/
|
||||
bool nrf_log_frontend_dequeue(void);
|
||||
|
||||
/**
|
||||
* @brief Function for getting number of independent log modules registered into the logger.
|
||||
*
|
||||
* @return Number of registered modules.
|
||||
*/
|
||||
uint32_t nrf_log_module_cnt_get(void);
|
||||
|
||||
/**
|
||||
* @brief Function for getting module name.
|
||||
*
|
||||
* @param module_id Module ID.
|
||||
* @param is_ordered_idx Module ID is given is index in alphabetically sorted list of modules.
|
||||
* @return Pointer to string with module name.
|
||||
*/
|
||||
const char * nrf_log_module_name_get(uint32_t module_id, bool is_ordered_idx);
|
||||
|
||||
/**
|
||||
* @brief Function for getting coloring of specific logs.
|
||||
*
|
||||
* @param module_id Module ID.
|
||||
* @param severity Log severity.
|
||||
*
|
||||
* @return ID of the color.
|
||||
*/
|
||||
uint8_t nrf_log_color_id_get(uint32_t module_id, nrf_log_severity_t severity);
|
||||
|
||||
/**
|
||||
* @brief Function for configuring filtering ofs logs in the module.
|
||||
*
|
||||
* Filtering of logs in modules is independent for each backend.
|
||||
*
|
||||
* @param backend_id Backend ID which want to chenge its configuration.
|
||||
* @param module_id Module ID which logs will be reconfigured.
|
||||
* @param severity New severity filter.
|
||||
*/
|
||||
void nrf_log_module_filter_set(uint32_t backend_id,
|
||||
uint32_t module_id,
|
||||
nrf_log_severity_t severity);
|
||||
|
||||
/**
|
||||
* @brief Function for getting module severity level.
|
||||
*
|
||||
* @param backend_id Backend ID.
|
||||
* @param module_id Module ID.
|
||||
* @param is_ordered_idx Module ID is given is index in alphabetically sorted list of modules.
|
||||
* @param dynamic It true current filter for given backend is returned. If false then
|
||||
* compiled-in level is returned (maximum available). If this parameter is
|
||||
* false then backend_id parameter is not used.
|
||||
*
|
||||
* @return Severity.
|
||||
*/
|
||||
nrf_log_severity_t nrf_log_module_filter_get(uint32_t backend_id,
|
||||
uint32_t module_id,
|
||||
bool is_ordered_idx,
|
||||
bool dynamic);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_LOG_CTRL_H
|
||||
|
||||
/**
|
||||
*@}
|
||||
**/
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Copyright (c) 2017 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef NRF_LOG_DEFAULT_BACKENDS_H__
|
||||
#define NRF_LOG_DEFAULT_BACKENDS_H__
|
||||
|
||||
/**@file
|
||||
* @addtogroup nrf_log Logger module
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @defgroup nrf_log_default_backends Functions for initializing and adding default backends
|
||||
* @{
|
||||
* @ingroup nrf_log
|
||||
* @brief The nrf_log default backends.
|
||||
*/
|
||||
|
||||
#include "sdk_config.h"
|
||||
#include "sdk_errors.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def NRF_LOG_DEFAULT_BACKENDS_INIT
|
||||
* @brief Macro for initializing default backends.
|
||||
*
|
||||
* Each backend enabled in configuration is initialized and added as a backend to the logger.
|
||||
*/
|
||||
#if NRF_LOG_ENABLED
|
||||
#define NRF_LOG_DEFAULT_BACKENDS_INIT() nrf_log_default_backends_init()
|
||||
#else
|
||||
#define NRF_LOG_DEFAULT_BACKENDS_INIT()
|
||||
#endif
|
||||
|
||||
void nrf_log_default_backends_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif // NRF_LOG_DEFAULT_BACKENDS_H__
|
||||
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef NRF_LOG_STR_FORMATTER_H
|
||||
#define NRF_LOG_STR_FORMATTER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "nrf_fprintf.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t timestamp;
|
||||
uint16_t module_id;
|
||||
nrf_log_severity_t severity;
|
||||
bool raw;
|
||||
uint8_t use_colors;
|
||||
} nrf_log_str_formatter_entry_params_t;
|
||||
|
||||
void nrf_log_std_entry_process(char const * p_str,
|
||||
uint32_t const * p_args,
|
||||
uint32_t nargs,
|
||||
nrf_log_str_formatter_entry_params_t * p_params,
|
||||
nrf_fprintf_ctx_t * p_ctx);
|
||||
|
||||
void nrf_log_hexdump_entry_process(uint8_t * p_data,
|
||||
uint32_t data_len,
|
||||
nrf_log_str_formatter_entry_params_t * p_params,
|
||||
nrf_fprintf_ctx_t * p_ctx);
|
||||
|
||||
#endif //NRF_LOG_STR_FORMATTER_H
|
||||
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(NRF_LOG) && NRF_MODULE_ENABLED(NRF_LOG_BACKEND_RTT)
|
||||
#include "nrf_log_backend_rtt.h"
|
||||
#include "nrf_log_backend_serial.h"
|
||||
#include "nrf_log_str_formatter.h"
|
||||
#include "nrf_log_internal.h"
|
||||
#include <SEGGER_RTT_Conf.h>
|
||||
#include <SEGGER_RTT.h>
|
||||
|
||||
static uint8_t m_string_buff[NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE];
|
||||
|
||||
void nrf_log_backend_rtt_init(void)
|
||||
{
|
||||
SEGGER_RTT_Init();
|
||||
}
|
||||
|
||||
static void serial_tx(void const * p_context, char const * buffer, size_t len)
|
||||
{
|
||||
if (len)
|
||||
{
|
||||
uint32_t idx = 0;
|
||||
uint32_t processed;
|
||||
uint32_t watchdog_counter = 10;
|
||||
do
|
||||
{
|
||||
processed = SEGGER_RTT_WriteNoLock(0, &buffer[idx], len);
|
||||
idx += processed;
|
||||
len -= processed;
|
||||
if (processed == 0)
|
||||
{
|
||||
// If RTT is not connected then ensure that logger does not block
|
||||
watchdog_counter--;
|
||||
if (watchdog_counter == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (len);
|
||||
}
|
||||
}
|
||||
static void nrf_log_backend_rtt_put(nrf_log_backend_t const * p_backend,
|
||||
nrf_log_entry_t * p_msg)
|
||||
{
|
||||
nrf_log_backend_serial_put(p_backend, p_msg, m_string_buff, NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE, serial_tx);
|
||||
}
|
||||
|
||||
static void nrf_log_backend_rtt_flush(nrf_log_backend_t const * p_backend)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void nrf_log_backend_rtt_panic_set(nrf_log_backend_t const * p_backend)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const nrf_log_backend_api_t nrf_log_backend_rtt_api = {
|
||||
.put = nrf_log_backend_rtt_put,
|
||||
.flush = nrf_log_backend_rtt_flush,
|
||||
.panic_set = nrf_log_backend_rtt_panic_set,
|
||||
};
|
||||
#endif //NRF_MODULE_ENABLED(NRF_LOG) && NRF_MODULE_ENABLED(NRF_LOG_BACKEND_RTT)
|
||||
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(NRF_LOG)
|
||||
#include "nrf_log_backend_serial.h"
|
||||
#include "nrf_log_str_formatter.h"
|
||||
#include "nrf_log_internal.h"
|
||||
|
||||
void nrf_log_backend_serial_put(nrf_log_backend_t const * p_backend,
|
||||
nrf_log_entry_t * p_msg,
|
||||
uint8_t * p_buffer,
|
||||
uint32_t length,
|
||||
nrf_fprintf_fwrite tx_func)
|
||||
{
|
||||
nrf_memobj_get(p_msg);
|
||||
|
||||
nrf_fprintf_ctx_t fprintf_ctx = {
|
||||
.p_io_buffer = (char *)p_buffer,
|
||||
.io_buffer_size = length,
|
||||
.io_buffer_cnt = 0,
|
||||
.auto_flush = false,
|
||||
.p_user_ctx = NULL,
|
||||
.fwrite = tx_func
|
||||
};
|
||||
|
||||
nrf_log_str_formatter_entry_params_t params;
|
||||
|
||||
nrf_log_header_t header;
|
||||
uint32_t memobj_offset = 0;
|
||||
nrf_memobj_read(p_msg, &header, HEADER_SIZE*sizeof(uint32_t), memobj_offset);
|
||||
memobj_offset = HEADER_SIZE*sizeof(uint32_t);
|
||||
|
||||
params.timestamp = header.timestamp;
|
||||
params.module_id = header.module_id;
|
||||
params.use_colors = NRF_LOG_USES_COLORS;
|
||||
|
||||
/*lint -save -e438*/
|
||||
if (header.base.generic.type == HEADER_TYPE_STD)
|
||||
{
|
||||
char const * p_log_str = (char const *)((uint32_t)header.base.std.addr);
|
||||
params.severity = (nrf_log_severity_t)header.base.std.severity;
|
||||
params.raw = header.base.std.raw;
|
||||
uint32_t nargs = header.base.std.nargs;
|
||||
uint32_t args[NRF_LOG_MAX_NUM_OF_ARGS];
|
||||
|
||||
nrf_memobj_read(p_msg, args, nargs*sizeof(uint32_t), memobj_offset);
|
||||
memobj_offset += (nargs*sizeof(uint32_t));
|
||||
|
||||
nrf_log_std_entry_process(p_log_str,
|
||||
args,
|
||||
nargs,
|
||||
¶ms,
|
||||
&fprintf_ctx);
|
||||
|
||||
}
|
||||
else if (header.base.generic.type == HEADER_TYPE_HEXDUMP)
|
||||
{
|
||||
uint32_t data_len = header.base.hexdump.len;
|
||||
params.severity = (nrf_log_severity_t)header.base.hexdump.severity;
|
||||
params.raw = header.base.hexdump.raw;
|
||||
uint8_t data_buf[8];
|
||||
uint32_t chunk_len;
|
||||
do
|
||||
{
|
||||
chunk_len = sizeof(data_buf) > data_len ? data_len : sizeof(data_buf);
|
||||
nrf_memobj_read(p_msg, data_buf, chunk_len, memobj_offset);
|
||||
memobj_offset += chunk_len;
|
||||
data_len -= chunk_len;
|
||||
|
||||
nrf_log_hexdump_entry_process(data_buf,
|
||||
chunk_len,
|
||||
¶ms,
|
||||
&fprintf_ctx);
|
||||
} while (data_len > 0);
|
||||
}
|
||||
nrf_memobj_put(p_msg);
|
||||
/*lint -restore*/
|
||||
}
|
||||
#endif //NRF_LOG_ENABLED
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2017 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef NRF_LOG_BACKEND_SERIAL_H
|
||||
#define NRF_LOG_BACKEND_SERIAL_H
|
||||
/**@file
|
||||
* @addtogroup nrf_log Logger module
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @defgroup nrf_log_backend_serial Common part of serial backends
|
||||
* @{
|
||||
* @ingroup nrf_log
|
||||
* @brief The nrf_log serial backend common put function.
|
||||
*/
|
||||
|
||||
|
||||
#include "nrf_log_backend_interface.h"
|
||||
#include "nrf_fprintf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief A function for processing logger entry with simple serial interface as output.
|
||||
*
|
||||
*
|
||||
*/
|
||||
void nrf_log_backend_serial_put(nrf_log_backend_t const * p_backend,
|
||||
nrf_log_entry_t * p_msg,
|
||||
uint8_t * p_buffer,
|
||||
uint32_t length,
|
||||
nrf_fprintf_fwrite tx_func);
|
||||
|
||||
#endif //NRF_LOG_BACKEND_SERIAL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(NRF_LOG) && NRF_MODULE_ENABLED(NRF_LOG_BACKEND_UART)
|
||||
#include "nrf_log_backend_uart.h"
|
||||
#include "nrf_log_backend_serial.h"
|
||||
#include "nrf_log_internal.h"
|
||||
#include "nrf_drv_uart.h"
|
||||
#include "app_error.h"
|
||||
|
||||
nrf_drv_uart_t m_uart = NRF_DRV_UART_INSTANCE(0);
|
||||
|
||||
static uint8_t m_string_buff[NRF_LOG_BACKEND_UART_TEMP_BUFFER_SIZE];
|
||||
static volatile bool m_xfer_done;
|
||||
static bool m_async_mode;
|
||||
static void uart_evt_handler(nrf_drv_uart_event_t * p_event, void * p_context)
|
||||
{
|
||||
m_xfer_done = true;
|
||||
}
|
||||
|
||||
static void uart_init(bool async_mode)
|
||||
{
|
||||
nrf_drv_uart_config_t config = NRF_DRV_UART_DEFAULT_CONFIG;
|
||||
config.pseltxd = NRF_LOG_BACKEND_UART_TX_PIN;
|
||||
config.pselrxd = NRF_UART_PSEL_DISCONNECTED;
|
||||
config.pselcts = NRF_UART_PSEL_DISCONNECTED;
|
||||
config.pselrts = NRF_UART_PSEL_DISCONNECTED;
|
||||
config.baudrate = (nrf_uart_baudrate_t)NRF_LOG_BACKEND_UART_BAUDRATE;
|
||||
ret_code_t err_code = nrf_drv_uart_init(&m_uart, &config, async_mode ? uart_evt_handler : NULL);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
m_async_mode = async_mode;
|
||||
}
|
||||
|
||||
void nrf_log_backend_uart_init(void)
|
||||
{
|
||||
bool async_mode = NRF_LOG_DEFERRED ? true : false;
|
||||
uart_init(async_mode);
|
||||
}
|
||||
|
||||
static void serial_tx(void const * p_context, char const * p_buffer, size_t len)
|
||||
{
|
||||
uint8_t len8 = (uint8_t)(len & 0x000000FF);
|
||||
m_xfer_done = false;
|
||||
ret_code_t err_code = nrf_drv_uart_tx(&m_uart, (uint8_t *)p_buffer, len8);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
/* wait for completion since buffer is reused*/
|
||||
while (m_async_mode && (m_xfer_done == false))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void nrf_log_backend_uart_put(nrf_log_backend_t const * p_backend,
|
||||
nrf_log_entry_t * p_msg)
|
||||
{
|
||||
nrf_log_backend_serial_put(p_backend, p_msg, m_string_buff,
|
||||
NRF_LOG_BACKEND_UART_TEMP_BUFFER_SIZE, serial_tx);
|
||||
}
|
||||
|
||||
static void nrf_log_backend_uart_flush(nrf_log_backend_t const * p_backend)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void nrf_log_backend_uart_panic_set(nrf_log_backend_t const * p_backend)
|
||||
{
|
||||
nrf_drv_uart_uninit(&m_uart);
|
||||
|
||||
uart_init(false);
|
||||
}
|
||||
|
||||
const nrf_log_backend_api_t nrf_log_backend_uart_api = {
|
||||
.put = nrf_log_backend_uart_put,
|
||||
.flush = nrf_log_backend_uart_flush,
|
||||
.panic_set = nrf_log_backend_uart_panic_set,
|
||||
};
|
||||
#endif //NRF_MODULE_ENABLED(NRF_LOG) && NRF_MODULE_ENABLED(NRF_LOG_BACKEND_UART)
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef NRF_LOG_CTRL_INTERNAL_H
|
||||
#define NRF_LOG_CTRL_INTERNAL_H
|
||||
/**
|
||||
* @cond (NODOX)
|
||||
* @defgroup nrf_log_ctrl_internal Auxiliary internal types declarations
|
||||
* @{
|
||||
* @internal
|
||||
*/
|
||||
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(NRF_LOG)
|
||||
|
||||
#define NRF_LOG_INTERNAL_INIT(timestamp_func) \
|
||||
nrf_log_init(timestamp_func)
|
||||
|
||||
#define NRF_LOG_INTERNAL_PROCESS() nrf_log_frontend_dequeue()
|
||||
#define NRF_LOG_INTERNAL_FLUSH() \
|
||||
do { \
|
||||
while (NRF_LOG_INTERNAL_PROCESS()); \
|
||||
} while (0)
|
||||
|
||||
#define NRF_LOG_INTERNAL_FINAL_FLUSH() \
|
||||
do { \
|
||||
nrf_log_panic(); \
|
||||
NRF_LOG_INTERNAL_FLUSH(); \
|
||||
} while (0)
|
||||
|
||||
|
||||
#else // NRF_MODULE_ENABLED(NRF_LOG)
|
||||
#define NRF_LOG_INTERNAL_PROCESS() false
|
||||
#define NRF_LOG_INTERNAL_FLUSH()
|
||||
#define NRF_LOG_INTERNAL_INIT(timestamp_func) NRF_SUCCESS
|
||||
#define NRF_LOG_INTERNAL_HANDLERS_SET(default_handler, bytes_handler) \
|
||||
UNUSED_PARAMETER(default_handler); UNUSED_PARAMETER(bytes_handler)
|
||||
#define NRF_LOG_INTERNAL_FINAL_FLUSH()
|
||||
#endif // NRF_MODULE_ENABLED(NRF_LOG)
|
||||
|
||||
/** @}
|
||||
* @endcond
|
||||
*/
|
||||
#endif // NRF_LOG_CTRL_INTERNAL_H
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Copyright (c) 2017 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(NRF_LOG)
|
||||
#include "nrf_log_default_backends.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_internal.h"
|
||||
#include "nrf_assert.h"
|
||||
|
||||
#if defined(NRF_LOG_BACKEND_RTT_ENABLED) && NRF_LOG_BACKEND_RTT_ENABLED
|
||||
#include "nrf_log_backend_rtt.h"
|
||||
NRF_LOG_BACKEND_RTT_DEF(rtt_log_backend);
|
||||
#endif
|
||||
|
||||
#if defined(NRF_LOG_BACKEND_UART_ENABLED) && NRF_LOG_BACKEND_UART_ENABLED
|
||||
#include "nrf_log_backend_uart.h"
|
||||
NRF_LOG_BACKEND_UART_DEF(uart_log_backend);
|
||||
#endif
|
||||
|
||||
void nrf_log_default_backends_init(void)
|
||||
{
|
||||
int32_t backend_id = -1;
|
||||
(void)backend_id;
|
||||
#if defined(NRF_LOG_BACKEND_RTT_ENABLED) && NRF_LOG_BACKEND_RTT_ENABLED
|
||||
nrf_log_backend_rtt_init();
|
||||
backend_id = nrf_log_backend_add(&rtt_log_backend.backend, NRF_LOG_SEVERITY_DEBUG);
|
||||
ASSERT(backend_id >= 0);
|
||||
nrf_log_backend_enable(&rtt_log_backend.backend);
|
||||
#endif
|
||||
|
||||
#if defined(NRF_LOG_BACKEND_UART_ENABLED) && NRF_LOG_BACKEND_UART_ENABLED
|
||||
nrf_log_backend_uart_init();
|
||||
backend_id = nrf_log_backend_add(&uart_log_backend.backend, NRF_LOG_SEVERITY_DEBUG);
|
||||
ASSERT(backend_id >= 0);
|
||||
nrf_log_backend_enable(&uart_log_backend.backend);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,548 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef NRF_LOG_INTERNAL_H__
|
||||
#define NRF_LOG_INTERNAL_H__
|
||||
#include "sdk_common.h"
|
||||
#include "nrf.h"
|
||||
#include "nrf_error.h"
|
||||
#include "app_util.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef NRF_LOG_ERROR_COLOR
|
||||
#define NRF_LOG_ERROR_COLOR NRF_LOG_COLOR_DEFAULT
|
||||
#endif
|
||||
|
||||
#ifndef NRF_LOG_WARNING_COLOR
|
||||
#define NRF_LOG_WARNING_COLOR NRF_LOG_COLOR_DEFAULT
|
||||
#endif
|
||||
|
||||
#ifndef NRF_LOG_INFO_COLOR
|
||||
#define NRF_LOG_INFO_COLOR NRF_LOG_COLOR_DEFAULT
|
||||
#endif
|
||||
|
||||
#ifndef NRF_LOG_DEBUG_COLOR
|
||||
#define NRF_LOG_DEBUG_COLOR NRF_LOG_COLOR_DEFAULT
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef NRF_LOG_COLOR_DEFAULT
|
||||
#define NRF_LOG_COLOR_DEFAULT 0
|
||||
#endif
|
||||
|
||||
#ifndef NRF_LOG_DEFAULT_LEVEL
|
||||
#define NRF_LOG_DEFAULT_LEVEL 0
|
||||
#endif
|
||||
|
||||
#ifndef NRF_LOG_USES_COLORS
|
||||
#define NRF_LOG_USES_COLORS 0
|
||||
#endif
|
||||
|
||||
#ifndef NRF_LOG_USES_TIMESTAMP
|
||||
#define NRF_LOG_USES_TIMESTAMP 0
|
||||
#endif
|
||||
|
||||
#ifndef NRF_LOG_FILTERS_ENABLED
|
||||
#define NRF_LOG_FILTERS_ENABLED 0
|
||||
#endif
|
||||
|
||||
#ifndef NRF_LOG_MODULE_NAME
|
||||
#define NRF_LOG_MODULE_NAME app
|
||||
#endif
|
||||
|
||||
#define NRF_LOG_LEVEL_ERROR 1UL
|
||||
#define NRF_LOG_LEVEL_WARNING 2UL
|
||||
#define NRF_LOG_LEVEL_INFO 3UL
|
||||
#define NRF_LOG_LEVEL_DEBUG 4UL
|
||||
#define NRF_LOG_LEVEL_INTERNAL 5UL
|
||||
#define NRF_LOG_LEVEL_BITS 3
|
||||
#define NRF_LOG_LEVEL_MASK ((1UL << NRF_LOG_LEVEL_BITS) - 1)
|
||||
#define NRF_LOG_RAW_POS 4U
|
||||
#define NRF_LOG_RAW (1UL << NRF_LOG_RAW_POS)
|
||||
#define NRF_LOG_MODULE_ID_BITS 16
|
||||
#define NRF_LOG_MODULE_ID_POS 16
|
||||
#define NRF_LOG_LEVEL_INFO_RAW (NRF_LOG_RAW | NRF_LOG_LEVEL_INFO)
|
||||
|
||||
#define NRF_LOG_MAX_NUM_OF_ARGS 6
|
||||
|
||||
/*
|
||||
* For GCC sections are sorted in the group by the linker. For IAR and KEIL it is assumed that linker will sort
|
||||
* dynamic and const section in the same order (but in different locations). Proper message formatting
|
||||
* is based on that assumption.
|
||||
*/
|
||||
#if defined(__GNUC__)
|
||||
#define NRF_LOG_DYNAMIC_SECTION_NAME(_module_name) CONCAT_2(log_dynamic_data_,_module_name)
|
||||
#define NRF_LOG_CONST_SECTION_NAME(_module_name) CONCAT_2(log_const_data_,_module_name)
|
||||
#else
|
||||
#define NRF_LOG_DYNAMIC_SECTION_NAME(_module_name) log_dynamic_data
|
||||
#define NRF_LOG_CONST_SECTION_NAME(_module_name) log_const_data
|
||||
#endif
|
||||
|
||||
#define NRF_LOG_MODULE_DATA CONCAT_3(m_nrf_log_,NRF_LOG_MODULE_NAME,_logs_data)
|
||||
#define NRF_LOG_MODULE_DATA_DYNAMIC CONCAT_2(NRF_LOG_MODULE_DATA,_dynamic)
|
||||
#define NRF_LOG_MODULE_DATA_CONST CONCAT_2(NRF_LOG_MODULE_DATA,_const)
|
||||
|
||||
#if NRF_LOG_FILTERS_ENABLED && NRF_LOG_ENABLED
|
||||
#define NRF_LOG_FILTER NRF_LOG_MODULE_DATA_DYNAMIC.filter
|
||||
#else
|
||||
#undef NRF_LOG_FILTER
|
||||
#define NRF_LOG_FILTER NRF_LOG_LEVEL_DEBUG
|
||||
#endif
|
||||
|
||||
#if NRF_LOG_ENABLED
|
||||
#define NRF_LOG_MODULE_ID NRF_LOG_MODULE_DATA_DYNAMIC.module_id
|
||||
#else
|
||||
#define NRF_LOG_MODULE_ID 0
|
||||
#endif
|
||||
|
||||
|
||||
#define LOG_INTERNAL_X(N, ...) CONCAT_2(LOG_INTERNAL_, N) (__VA_ARGS__)
|
||||
#define LOG_INTERNAL(type, ...) LOG_INTERNAL_X(NUM_VA_ARGS_LESS_1( \
|
||||
__VA_ARGS__), type, __VA_ARGS__)
|
||||
#if NRF_LOG_ENABLED
|
||||
#define NRF_LOG_INTERNAL_LOG_PUSH(_str) nrf_log_push(_str)
|
||||
#define LOG_INTERNAL_0(type, str) \
|
||||
nrf_log_frontend_std_0(type, str)
|
||||
#define LOG_INTERNAL_1(type, str, arg0) \
|
||||
/*lint -save -e571*/nrf_log_frontend_std_1(type, str, (uint32_t)(arg0))/*lint -restore*/
|
||||
#define LOG_INTERNAL_2(type, str, arg0, arg1) \
|
||||
/*lint -save -e571*/nrf_log_frontend_std_2(type, str, (uint32_t)(arg0), \
|
||||
(uint32_t)(arg1))/*lint -restore*/
|
||||
#define LOG_INTERNAL_3(type, str, arg0, arg1, arg2) \
|
||||
/*lint -save -e571*/nrf_log_frontend_std_3(type, str, (uint32_t)(arg0), \
|
||||
(uint32_t)(arg1), (uint32_t)(arg2))/*lint -restore*/
|
||||
#define LOG_INTERNAL_4(type, str, arg0, arg1, arg2, arg3) \
|
||||
/*lint -save -e571*/nrf_log_frontend_std_4(type, str, (uint32_t)(arg0), \
|
||||
(uint32_t)(arg1), (uint32_t)(arg2), (uint32_t)(arg3))/*lint -restore*/
|
||||
#define LOG_INTERNAL_5(type, str, arg0, arg1, arg2, arg3, arg4) \
|
||||
/*lint -save -e571*/nrf_log_frontend_std_5(type, str, (uint32_t)(arg0), \
|
||||
(uint32_t)(arg1), (uint32_t)(arg2), (uint32_t)(arg3), (uint32_t)(arg4))/*lint -restore*/
|
||||
#define LOG_INTERNAL_6(type, str, arg0, arg1, arg2, arg3, arg4, arg5) \
|
||||
/*lint -save -e571*/nrf_log_frontend_std_6(type, str, (uint32_t)(arg0), \
|
||||
(uint32_t)(arg1), (uint32_t)(arg2), (uint32_t)(arg3), (uint32_t)(arg4), (uint32_t)(arg5))/*lint -restore*/
|
||||
|
||||
|
||||
#else //NRF_LOG_ENABLED
|
||||
#define NRF_LOG_INTERNAL_LOG_PUSH(_str) (void)(_str)
|
||||
#define LOG_INTERNAL_0(_type, _str) \
|
||||
(void)(_type); (void)(_str)
|
||||
#define LOG_INTERNAL_1(_type, _str, _arg0) \
|
||||
(void)(_type); (void)(_str); (void)(_arg0)
|
||||
#define LOG_INTERNAL_2(_type, _str, _arg0, _arg1) \
|
||||
(void)(_type); (void)(_str); (void)(_arg0); (void)(_arg1)
|
||||
#define LOG_INTERNAL_3(_type, _str, _arg0, _arg1, _arg2) \
|
||||
(void)(_type); (void)(_str); (void)(_arg0); (void)(_arg1); (void)(_arg2)
|
||||
#define LOG_INTERNAL_4(_type, _str, _arg0, _arg1, _arg2, _arg3) \
|
||||
(void)(_type); (void)(_str); (void)(_arg0); (void)(_arg1); (void)(_arg2); (void)(_arg3)
|
||||
#define LOG_INTERNAL_5(_type, _str, _arg0, _arg1, _arg2, _arg3, _arg4) \
|
||||
(void)(_type); (void)(_str); (void)(_arg0); (void)(_arg1); (void)(_arg2); (void)(_arg3); (void)(_arg4)
|
||||
#define LOG_INTERNAL_6(_type, _str, _arg0, _arg1, _arg2, _arg3, _arg4, _arg5) \
|
||||
(void)(_type); (void)(_str); (void)(_arg0); (void)(_arg1); (void)(_arg2); (void)(_arg3); (void)(_arg4); (void)(_arg5)
|
||||
#endif //NRF_LOG_ENABLED && (NRF_LOG_DEFAULT_LEVEL >= NRF_LOG_LEVEL_ERROR)
|
||||
|
||||
#define LOG_SEVERITY_MOD_ID(severity) ((severity) | NRF_LOG_MODULE_ID << NRF_LOG_MODULE_ID_POS)
|
||||
|
||||
#if NRF_LOG_ENABLED
|
||||
#define LOG_HEXDUMP(_severity, _p_data, _length) \
|
||||
nrf_log_frontend_hexdump((_severity), (_p_data), (_length))
|
||||
#else
|
||||
#define LOG_HEXDUMP(_severity, _p_data, _length) \
|
||||
(void)(_severity); (void)(_p_data); (void)_length
|
||||
#endif
|
||||
|
||||
#define NRF_LOG_INTERNAL_ERROR(...) \
|
||||
if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_ERROR) && \
|
||||
(NRF_LOG_LEVEL_ERROR <= NRF_LOG_DEFAULT_LEVEL)) \
|
||||
{ \
|
||||
if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_ERROR) \
|
||||
{ \
|
||||
LOG_INTERNAL(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_ERROR), __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define NRF_LOG_INTERNAL_HEXDUMP_ERROR(p_data, len) \
|
||||
if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_ERROR) && \
|
||||
(NRF_LOG_LEVEL_ERROR <= NRF_LOG_DEFAULT_LEVEL)) \
|
||||
{ \
|
||||
if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_ERROR) \
|
||||
{ \
|
||||
LOG_HEXDUMP(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_ERROR), \
|
||||
(p_data), (len)); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define NRF_LOG_INTERNAL_WARNING(...) \
|
||||
if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_WARNING) && \
|
||||
(NRF_LOG_LEVEL_WARNING <= NRF_LOG_DEFAULT_LEVEL)) \
|
||||
{ \
|
||||
if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_WARNING) \
|
||||
{ \
|
||||
LOG_INTERNAL(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_WARNING), __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define NRF_LOG_INTERNAL_HEXDUMP_WARNING(p_data, len) \
|
||||
if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_WARNING) && \
|
||||
(NRF_LOG_LEVEL_WARNING <= NRF_LOG_DEFAULT_LEVEL)) \
|
||||
{ \
|
||||
if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_WARNING) \
|
||||
{ \
|
||||
LOG_HEXDUMP(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_WARNING, \
|
||||
(p_data), (len)); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define NRF_LOG_INTERNAL_INFO(...) \
|
||||
if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_INFO) && \
|
||||
(NRF_LOG_LEVEL_INFO <= NRF_LOG_DEFAULT_LEVEL)) \
|
||||
{ \
|
||||
if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_INFO) \
|
||||
{ \
|
||||
LOG_INTERNAL(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_INFO), __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define NRF_LOG_INTERNAL_RAW_INFO(...) \
|
||||
if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_INFO) && \
|
||||
(NRF_LOG_LEVEL_INFO <= NRF_LOG_DEFAULT_LEVEL)) \
|
||||
{ \
|
||||
if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_INFO) \
|
||||
{ \
|
||||
LOG_INTERNAL(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_INFO | NRF_LOG_RAW), \
|
||||
__VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define NRF_LOG_INTERNAL_HEXDUMP_INFO(p_data, len) \
|
||||
if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_INFO) && \
|
||||
(NRF_LOG_LEVEL_INFO <= NRF_LOG_DEFAULT_LEVEL)) \
|
||||
{ \
|
||||
if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_INFO) \
|
||||
{ \
|
||||
LOG_HEXDUMP(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_INFO), \
|
||||
(p_data), (len)); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define NRF_LOG_INTERNAL_RAW_HEXDUMP_INFO(p_data, len) \
|
||||
if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_INFO) && \
|
||||
(NRF_LOG_LEVEL_INFO <= NRF_LOG_DEFAULT_LEVEL)) \
|
||||
{ \
|
||||
if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_INFO) \
|
||||
{ \
|
||||
LOG_HEXDUMP(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_INFO_RAW), \
|
||||
(p_data), (len)); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define NRF_LOG_INTERNAL_DEBUG(...) \
|
||||
if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_DEBUG) && \
|
||||
(NRF_LOG_LEVEL_DEBUG <= NRF_LOG_DEFAULT_LEVEL)) \
|
||||
{ \
|
||||
if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_DEBUG) \
|
||||
{ \
|
||||
LOG_INTERNAL(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_DEBUG), __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define NRF_LOG_INTERNAL_HEXDUMP_DEBUG(p_data, len) \
|
||||
if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_DEBUG) && \
|
||||
(NRF_LOG_LEVEL_DEBUG <= NRF_LOG_DEFAULT_LEVEL)) \
|
||||
{ \
|
||||
if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_DEBUG) \
|
||||
{ \
|
||||
LOG_HEXDUMP(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_DEBUG), \
|
||||
(p_data), (len)); \
|
||||
} \
|
||||
}
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_LOG)
|
||||
#define NRF_LOG_INTERNAL_GETCHAR() nrf_log_getchar()
|
||||
#else
|
||||
#define NRF_LOG_INTERNAL_GETCHAR() (void)
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t module_id;
|
||||
uint16_t order_idx;
|
||||
uint32_t filter;
|
||||
uint32_t filter_lvls;
|
||||
} nrf_log_module_dynamic_data_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const char * p_module_name;
|
||||
uint8_t info_color_id;
|
||||
uint8_t debug_color_id;
|
||||
uint8_t compiled_lvl;
|
||||
} nrf_log_module_const_data_t;
|
||||
|
||||
extern nrf_log_module_dynamic_data_t NRF_LOG_MODULE_DATA_DYNAMIC;
|
||||
|
||||
/**
|
||||
* Set of macros for encoding and decoding header for log entries.
|
||||
* There are 3 types of entries:
|
||||
* 1. Standard entry (STD)
|
||||
* An entry consists of header, pointer to string and values. Header contains
|
||||
* severity leveland determines number of arguments and thus size of the entry.
|
||||
* Since flash address space starts from 0x00000000 and is limited to kB rather
|
||||
* than MB 22 bits are used to store the address (4MB). It is used that way to
|
||||
* save one RAM memory.
|
||||
*
|
||||
* --------------------------------
|
||||
* |TYPE|SEVERITY|NARGS| P_STR |
|
||||
* |------------------------------|
|
||||
* | Module_ID (optional) |
|
||||
* |------------------------------|
|
||||
* | TIMESTAMP (optional) |
|
||||
* |------------------------------|
|
||||
* | ARG0 |
|
||||
* |------------------------------|
|
||||
* | .... |
|
||||
* |------------------------------|
|
||||
* | ARG(nargs-1) |
|
||||
* --------------------------------
|
||||
*
|
||||
* 2. Hexdump entry (HEXDUMP) is used for dumping raw data. An entry consists of
|
||||
* header, optional timestamp, pointer to string and data. A header contains
|
||||
* length (10bit) and offset which is updated after backend processes part of
|
||||
* data.
|
||||
*
|
||||
* --------------------------------
|
||||
* |TYPE|SEVERITY|NARGS|OFFSET|LEN|
|
||||
* |------------------------------|
|
||||
* | Module_ID (optional) |
|
||||
* |------------------------------|
|
||||
* | TIMESTAMP (optional) |
|
||||
* |------------------------------|
|
||||
* | P_STR |
|
||||
* |------------------------------|
|
||||
* | data |
|
||||
* |------------------------------|
|
||||
* | data | dummy |
|
||||
* --------------------------------
|
||||
*
|
||||
* 3. Pushed string. If string is pushed into the logger internal buffer it is
|
||||
* stored as PUSHED entry. It consists of header, unused data (optional) and
|
||||
* string. Unused data is present if string does not not fit into a buffer
|
||||
* without wrapping (and string cannot be wrapped). In that case header
|
||||
* contains information about offset.
|
||||
*
|
||||
* --------------------------------
|
||||
* |TYPE| OFFSET | LEN |
|
||||
* |------------------------------|
|
||||
* | OFFSET |
|
||||
* |------------------------------|
|
||||
* end| OFFSET |
|
||||
* 0|------------------------------|
|
||||
* | STRING |
|
||||
* |------------------------------|
|
||||
* | STRING | dummy |
|
||||
* --------------------------------
|
||||
*/
|
||||
|
||||
#define STD_ADDR_MASK ((uint32_t)(1U << 22) - 1U)
|
||||
#define HEADER_TYPE_STD 1U
|
||||
#define HEADER_TYPE_HEXDUMP 2U
|
||||
#define HEADER_TYPE_PUSHED 0U
|
||||
#define HEADER_TYPE_INVALID 3U
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t type : 2;
|
||||
uint32_t raw : 1;
|
||||
uint32_t data : 29;
|
||||
} nrf_log_generic_header_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t type : 2;
|
||||
uint32_t raw : 1;
|
||||
uint32_t severity : 3;
|
||||
uint32_t nargs : 4;
|
||||
uint32_t addr : 22;
|
||||
} nrf_log_std_header_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t type : 2;
|
||||
uint32_t raw : 1;
|
||||
uint32_t severity : 3;
|
||||
uint32_t offset : 10;
|
||||
uint32_t reserved : 6;
|
||||
uint32_t len : 10;
|
||||
} nrf_log_hexdump_header_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t type : 2;
|
||||
uint32_t reserved0 : 4;
|
||||
uint32_t offset : 10;
|
||||
uint32_t reserved1 : 6;
|
||||
uint32_t len : 10;
|
||||
} nrf_log_pushed_header_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
union {
|
||||
nrf_log_generic_header_t generic;
|
||||
nrf_log_std_header_t std;
|
||||
nrf_log_hexdump_header_t hexdump;
|
||||
nrf_log_pushed_header_t pushed;
|
||||
uint32_t raw;
|
||||
} base;
|
||||
uint32_t module_id;
|
||||
uint32_t timestamp;
|
||||
} nrf_log_header_t;
|
||||
|
||||
#define HEADER_SIZE (sizeof(nrf_log_header_t)/sizeof(uint32_t) - \
|
||||
(NRF_LOG_USES_TIMESTAMP ? 0 : 1))
|
||||
|
||||
#define PUSHED_HEADER_SIZE (sizeof(nrf_log_pushed_header_t)/sizeof(uint32_t))
|
||||
|
||||
//Implementation assumes that pushed header has one word.
|
||||
STATIC_ASSERT(PUSHED_HEADER_SIZE == 1);
|
||||
/**
|
||||
* @brief A function for logging raw string.
|
||||
*
|
||||
* @param severity_mid Severity.
|
||||
* @param p_str A pointer to a string.
|
||||
*/
|
||||
void nrf_log_frontend_std_0(uint32_t severity_mid, char const * const p_str);
|
||||
|
||||
/**
|
||||
* @brief A function for logging a formatted string with one argument.
|
||||
*
|
||||
* @param severity_mid Severity.
|
||||
* @param p_str A pointer to a formatted string.
|
||||
* @param val0 An argument.
|
||||
*/
|
||||
void nrf_log_frontend_std_1(uint32_t severity_mid,
|
||||
char const * const p_str,
|
||||
uint32_t val0);
|
||||
|
||||
/**
|
||||
* @brief A function for logging a formatted string with 2 arguments.
|
||||
*
|
||||
* @param severity_mid Severity.
|
||||
* @param p_str A pointer to a formatted string.
|
||||
* @param val0, val1 Arguments for formatting string.
|
||||
*/
|
||||
void nrf_log_frontend_std_2(uint32_t severity_mid,
|
||||
char const * const p_str,
|
||||
uint32_t val0,
|
||||
uint32_t val1);
|
||||
|
||||
/**
|
||||
* @brief A function for logging a formatted string with 3 arguments.
|
||||
*
|
||||
* @param severity_mid Severity.
|
||||
* @param p_str A pointer to a formatted string.
|
||||
* @param val0, val1, val2 Arguments for formatting string.
|
||||
*/
|
||||
void nrf_log_frontend_std_3(uint32_t severity_mid,
|
||||
char const * const p_str,
|
||||
uint32_t val0,
|
||||
uint32_t val1,
|
||||
uint32_t val2);
|
||||
|
||||
/**
|
||||
* @brief A function for logging a formatted string with 4 arguments.
|
||||
*
|
||||
* @param severity_mid Severity.
|
||||
* @param p_str A pointer to a formatted string.
|
||||
* @param val0, val1, val2, val3 Arguments for formatting string.
|
||||
*/
|
||||
void nrf_log_frontend_std_4(uint32_t severity_mid,
|
||||
char const * const p_str,
|
||||
uint32_t val0,
|
||||
uint32_t val1,
|
||||
uint32_t val2,
|
||||
uint32_t val3);
|
||||
|
||||
/**
|
||||
* @brief A function for logging a formatted string with 5 arguments.
|
||||
*
|
||||
* @param severity_mid Severity.
|
||||
* @param p_str A pointer to a formatted string.
|
||||
* @param val0, val1, val2, val3, val4 Arguments for formatting string.
|
||||
*/
|
||||
void nrf_log_frontend_std_5(uint32_t severity_mid,
|
||||
char const * const p_str,
|
||||
uint32_t val0,
|
||||
uint32_t val1,
|
||||
uint32_t val2,
|
||||
uint32_t val3,
|
||||
uint32_t val4);
|
||||
|
||||
/**
|
||||
* @brief A function for logging a formatted string with 6 arguments.
|
||||
*
|
||||
* @param severity_mid Severity.
|
||||
* @param p_str A pointer to a formatted string.
|
||||
* @param val0, val1, val2, val3, val4, val5 Arguments for formatting string.
|
||||
*/
|
||||
void nrf_log_frontend_std_6(uint32_t severity_mid,
|
||||
char const * const p_str,
|
||||
uint32_t val0,
|
||||
uint32_t val1,
|
||||
uint32_t val2,
|
||||
uint32_t val3,
|
||||
uint32_t val4,
|
||||
uint32_t val5);
|
||||
|
||||
/**
|
||||
* @brief A function for logging raw data.
|
||||
*
|
||||
* @param severity_mid Severity.
|
||||
* @param p_str A pointer to a string which is prefixing the data.
|
||||
* @param p_data A pointer to data to be dumped.
|
||||
* @param length Length of data (in bytes).
|
||||
*
|
||||
*/
|
||||
void nrf_log_frontend_hexdump(uint32_t severity_mid,
|
||||
const void * const p_data,
|
||||
uint16_t length);
|
||||
|
||||
/**
|
||||
* @brief A function for reading a byte from log backend.
|
||||
*
|
||||
* @return Byte.
|
||||
*/
|
||||
uint8_t nrf_log_getchar(void);
|
||||
#endif // NRF_LOG_INTERNAL_H__
|
||||
@@ -0,0 +1,209 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(NRF_LOG)
|
||||
#include "nrf_log_str_formatter.h"
|
||||
#include "nrf_log_internal.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_fprintf.h"
|
||||
#include <ctype.h>
|
||||
|
||||
#define NRF_LOG_COLOR_CODE_DEFAULT "\x1B[0m"
|
||||
#define NRF_LOG_COLOR_CODE_BLACK "\x1B[1;30m"
|
||||
#define NRF_LOG_COLOR_CODE_RED "\x1B[1;31m"
|
||||
#define NRF_LOG_COLOR_CODE_GREEN "\x1B[1;32m"
|
||||
#define NRF_LOG_COLOR_CODE_YELLOW "\x1B[1;33m"
|
||||
#define NRF_LOG_COLOR_CODE_BLUE "\x1B[1;34m"
|
||||
#define NRF_LOG_COLOR_CODE_MAGENTA "\x1B[1;35m"
|
||||
#define NRF_LOG_COLOR_CODE_CYAN "\x1B[1;36m"
|
||||
#define NRF_LOG_COLOR_CODE_WHITE "\x1B[1;37m"
|
||||
|
||||
static const char * severity_names[] = {
|
||||
NULL,
|
||||
"error",
|
||||
"warning",
|
||||
"info",
|
||||
"debug"
|
||||
};
|
||||
|
||||
static const char * m_colors[] = {
|
||||
NRF_LOG_COLOR_CODE_DEFAULT,
|
||||
NRF_LOG_COLOR_CODE_BLACK,
|
||||
NRF_LOG_COLOR_CODE_RED,
|
||||
NRF_LOG_COLOR_CODE_GREEN,
|
||||
NRF_LOG_COLOR_CODE_YELLOW,
|
||||
NRF_LOG_COLOR_CODE_BLUE,
|
||||
NRF_LOG_COLOR_CODE_MAGENTA,
|
||||
NRF_LOG_COLOR_CODE_CYAN,
|
||||
NRF_LOG_COLOR_CODE_WHITE,
|
||||
};
|
||||
|
||||
static void prefix_process(nrf_log_str_formatter_entry_params_t * p_params,
|
||||
nrf_fprintf_ctx_t * p_ctx)
|
||||
{
|
||||
if (!(p_params->raw))
|
||||
{
|
||||
if (p_params->use_colors)
|
||||
{
|
||||
nrf_fprintf(p_ctx, "%s",
|
||||
m_colors[nrf_log_color_id_get( p_params->module_id, p_params->severity)]);
|
||||
}
|
||||
|
||||
if (NRF_LOG_USES_TIMESTAMP)
|
||||
{
|
||||
nrf_fprintf(p_ctx, "[%08lu] ", p_params->timestamp);
|
||||
}
|
||||
|
||||
nrf_fprintf(p_ctx, "<%s> %s: ",
|
||||
severity_names[p_params->severity], nrf_log_module_name_get(p_params->module_id, false));
|
||||
}
|
||||
}
|
||||
|
||||
static void postfix_process(nrf_log_str_formatter_entry_params_t * p_params,
|
||||
nrf_fprintf_ctx_t * p_ctx,
|
||||
bool newline)
|
||||
{
|
||||
if (!p_params->raw)
|
||||
{
|
||||
if (p_params->use_colors)
|
||||
{
|
||||
nrf_fprintf(p_ctx, "%s", m_colors[0]);
|
||||
}
|
||||
nrf_fprintf(p_ctx, "\r\n");
|
||||
}
|
||||
else if (newline)
|
||||
{
|
||||
nrf_fprintf(p_ctx, "\r\n");
|
||||
}
|
||||
nrf_fprintf_buffer_flush(p_ctx);
|
||||
}
|
||||
|
||||
void nrf_log_std_entry_process(char const * p_str,
|
||||
uint32_t const * p_args,
|
||||
uint32_t nargs,
|
||||
nrf_log_str_formatter_entry_params_t * p_params,
|
||||
nrf_fprintf_ctx_t * p_ctx)
|
||||
{
|
||||
bool auto_flush = p_ctx->auto_flush;
|
||||
p_ctx->auto_flush = false;
|
||||
|
||||
prefix_process(p_params, p_ctx);
|
||||
|
||||
switch (nargs)
|
||||
{
|
||||
case 0:
|
||||
nrf_fprintf(p_ctx, p_str);
|
||||
break;
|
||||
case 1:
|
||||
nrf_fprintf(p_ctx, p_str, p_args[0]);
|
||||
break;
|
||||
case 2:
|
||||
nrf_fprintf(p_ctx, p_str, p_args[0], p_args[1]);
|
||||
break;
|
||||
case 3:
|
||||
nrf_fprintf(p_ctx, p_str, p_args[0], p_args[1], p_args[2]);
|
||||
break;
|
||||
case 4:
|
||||
nrf_fprintf(p_ctx, p_str, p_args[0], p_args[1], p_args[2], p_args[3]);
|
||||
break;
|
||||
case 5:
|
||||
nrf_fprintf(p_ctx, p_str, p_args[0], p_args[1], p_args[2], p_args[3], p_args[4]);
|
||||
break;
|
||||
case 6:
|
||||
nrf_fprintf(p_ctx, p_str, p_args[0], p_args[1], p_args[2], p_args[3], p_args[4], p_args[5]);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
postfix_process(p_params, p_ctx, false);
|
||||
p_ctx->auto_flush = auto_flush;
|
||||
}
|
||||
|
||||
#define HEXDUMP_BYTES_IN_LINE 8
|
||||
|
||||
void nrf_log_hexdump_entry_process(uint8_t * p_data,
|
||||
uint32_t data_len,
|
||||
nrf_log_str_formatter_entry_params_t * p_params,
|
||||
nrf_fprintf_ctx_t * p_ctx)
|
||||
{
|
||||
if (data_len > HEXDUMP_BYTES_IN_LINE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool auto_flush = p_ctx->auto_flush;
|
||||
p_ctx->auto_flush = false;
|
||||
|
||||
prefix_process(p_params, p_ctx);
|
||||
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < HEXDUMP_BYTES_IN_LINE; i++)
|
||||
{
|
||||
if (i < data_len)
|
||||
{
|
||||
nrf_fprintf(p_ctx, " %02x", p_data[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
nrf_fprintf(p_ctx, " ");
|
||||
}
|
||||
}
|
||||
nrf_fprintf(p_ctx, "|");
|
||||
|
||||
for (i = 0; i < HEXDUMP_BYTES_IN_LINE; i++)
|
||||
{
|
||||
if (i < data_len)
|
||||
{
|
||||
char c = (char)p_data[i];
|
||||
nrf_fprintf(p_ctx, "%c", isprint((int)c) ? c :'.');
|
||||
}
|
||||
else
|
||||
{
|
||||
nrf_fprintf(p_ctx, " ");
|
||||
}
|
||||
}
|
||||
|
||||
postfix_process(p_params, p_ctx, true);
|
||||
|
||||
p_ctx->auto_flush = auto_flush;
|
||||
}
|
||||
#endif //NRF_LOG_ENABLED
|
||||
@@ -0,0 +1,231 @@
|
||||
/**
|
||||
* Copyright (c) 2017 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nrf_memobj.h"
|
||||
#include "nrf_atomic.h"
|
||||
#include "nrf_assert.h"
|
||||
|
||||
typedef struct memobj_elem_s memobj_elem_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
memobj_elem_t * p_next;
|
||||
} memobj_header_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t user_cnt;
|
||||
uint8_t chunk_cnt;
|
||||
uint16_t chunk_size;
|
||||
} memobj_head_header_fields_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
union
|
||||
{
|
||||
nrf_atomic_u32_t atomic_user_cnt;
|
||||
memobj_head_header_fields_t fields;
|
||||
} data;
|
||||
} memobj_head_header_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
memobj_header_t header;
|
||||
memobj_head_header_t head_header;
|
||||
uint8_t data[1];
|
||||
} memobj_head_t;
|
||||
|
||||
STATIC_ASSERT(sizeof(memobj_header_t) == NRF_MEMOBJ_STD_HEADER_SIZE);
|
||||
|
||||
struct memobj_elem_s
|
||||
{
|
||||
memobj_header_t header;
|
||||
uint8_t data[1];
|
||||
};
|
||||
|
||||
ret_code_t nrf_memobj_pool_init(nrf_memobj_pool_t const * p_pool)
|
||||
{
|
||||
return nrf_balloc_init((nrf_balloc_t const *)p_pool);
|
||||
}
|
||||
|
||||
nrf_memobj_t * nrf_memobj_alloc(nrf_memobj_pool_t const * p_pool,
|
||||
size_t size)
|
||||
{
|
||||
uint32_t bsize = (uint32_t)NRF_BALLOC_ELEMENT_SIZE((nrf_balloc_t const *)p_pool) - sizeof(memobj_header_t);
|
||||
uint8_t num_of_chunks = (uint8_t)CEIL_DIV(size + sizeof(memobj_head_header_t), bsize);
|
||||
|
||||
memobj_head_t * p_head = nrf_balloc_alloc((nrf_balloc_t const *)p_pool);
|
||||
if (p_head == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
p_head->head_header.data.fields.user_cnt = 0;
|
||||
p_head->head_header.data.fields.chunk_cnt = 1;
|
||||
p_head->head_header.data.fields.chunk_size = bsize;
|
||||
|
||||
memobj_header_t * p_prev = (memobj_header_t *)p_head;
|
||||
memobj_header_t * p_curr;
|
||||
uint32_t i;
|
||||
uint32_t chunk_less1 = (uint32_t)num_of_chunks - 1;
|
||||
|
||||
p_prev->p_next = (memobj_elem_t *)p_pool;
|
||||
for (i = 0; i < chunk_less1; i++)
|
||||
{
|
||||
p_curr = (memobj_header_t *)nrf_balloc_alloc((nrf_balloc_t const *)p_pool);
|
||||
if (p_curr)
|
||||
{
|
||||
(p_head->head_header.data.fields.chunk_cnt)++;
|
||||
p_prev->p_next = (memobj_elem_t *)p_curr;
|
||||
p_curr->p_next = (memobj_elem_t *)p_pool;
|
||||
p_prev = p_curr;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Couldn't allocate all requested buffers
|
||||
nrf_memobj_free((nrf_memobj_t *)p_head);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return (nrf_memobj_t *)p_head;
|
||||
}
|
||||
|
||||
void nrf_memobj_free(nrf_memobj_t * p_obj)
|
||||
{
|
||||
memobj_head_t * p_head = (memobj_head_t *)p_obj;
|
||||
uint8_t chunk_cnt = p_head->head_header.data.fields.chunk_cnt;
|
||||
uint32_t i;
|
||||
memobj_header_t * p_curr = (memobj_header_t *)p_obj;
|
||||
memobj_header_t * p_next;
|
||||
uint32_t chunk_less1 = (uint32_t)chunk_cnt - 1;
|
||||
|
||||
for (i = 0; i < chunk_less1; i++)
|
||||
{
|
||||
p_curr = (memobj_header_t *)p_curr->p_next;
|
||||
}
|
||||
nrf_balloc_t const * p_pool2 = (nrf_balloc_t const *)p_curr->p_next;
|
||||
|
||||
p_curr = (memobj_header_t *)p_obj;
|
||||
for (i = 0; i < chunk_cnt; i++)
|
||||
{
|
||||
p_next = (memobj_header_t *)p_curr->p_next;
|
||||
nrf_balloc_free(p_pool2, p_curr);
|
||||
p_curr = p_next;
|
||||
}
|
||||
}
|
||||
|
||||
void nrf_memobj_get(nrf_memobj_t const * p_obj)
|
||||
{
|
||||
memobj_head_t * p_head = (memobj_head_t *)p_obj;
|
||||
(void)nrf_atomic_u32_add(&p_head->head_header.data.atomic_user_cnt, 1);
|
||||
}
|
||||
|
||||
void nrf_memobj_put(nrf_memobj_t * p_obj)
|
||||
{
|
||||
memobj_head_t * p_head = (memobj_head_t *)p_obj;
|
||||
uint32_t user_cnt = nrf_atomic_u32_sub(&p_head->head_header.data.atomic_user_cnt, 1);
|
||||
memobj_head_header_fields_t * p_fields = (memobj_head_header_fields_t *)&user_cnt;
|
||||
if (p_fields->user_cnt == 0)
|
||||
{
|
||||
nrf_memobj_free(p_obj);
|
||||
}
|
||||
}
|
||||
|
||||
static void memobj_op(nrf_memobj_t * p_obj,
|
||||
void * p_data,
|
||||
uint32_t len,
|
||||
uint32_t offset,
|
||||
bool read)
|
||||
{
|
||||
|
||||
memobj_head_t * p_head = (memobj_head_t *)p_obj;
|
||||
uint32_t space_in_chunk = p_head->head_header.data.fields.chunk_size;
|
||||
memobj_elem_t * p_curr_chunk = (memobj_elem_t *)p_obj;
|
||||
uint32_t chunk_idx = (offset + sizeof(memobj_head_header_fields_t))/space_in_chunk;
|
||||
uint32_t chunk_offset = (offset + sizeof(memobj_head_header_fields_t)) % space_in_chunk;
|
||||
|
||||
uint8_t chunks_expected = CEIL_DIV((offset + sizeof(memobj_head_header_fields_t) + len),
|
||||
space_in_chunk);
|
||||
UNUSED_VARIABLE(chunks_expected);
|
||||
ASSERT(p_head->head_header.data.fields.chunk_cnt >= chunks_expected);
|
||||
|
||||
while (chunk_idx > 0)
|
||||
{
|
||||
p_curr_chunk = p_curr_chunk->header.p_next;
|
||||
chunk_idx--;
|
||||
}
|
||||
|
||||
uint32_t src_offset = 0;
|
||||
uint32_t curr_cpy_size = space_in_chunk-chunk_offset;
|
||||
curr_cpy_size = curr_cpy_size > len ? len : curr_cpy_size;
|
||||
|
||||
while (len)
|
||||
{
|
||||
if (read)
|
||||
{
|
||||
memcpy(&((uint8_t *)p_data)[src_offset], &p_curr_chunk->data[chunk_offset], curr_cpy_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(&p_curr_chunk->data[chunk_offset], &((uint8_t *)p_data)[src_offset], curr_cpy_size);
|
||||
}
|
||||
chunk_offset = 0;
|
||||
p_curr_chunk = p_curr_chunk->header.p_next;
|
||||
len -= curr_cpy_size;
|
||||
src_offset += curr_cpy_size;
|
||||
curr_cpy_size = (space_in_chunk > len) ? len : space_in_chunk;
|
||||
}
|
||||
}
|
||||
|
||||
void nrf_memobj_write(nrf_memobj_t * p_obj,
|
||||
void * p_data,
|
||||
uint32_t len,
|
||||
uint32_t offset)
|
||||
{
|
||||
|
||||
memobj_op(p_obj, p_data, len, offset, false);
|
||||
}
|
||||
|
||||
void nrf_memobj_read(nrf_memobj_t * p_obj,
|
||||
void * p_data,
|
||||
uint32_t len,
|
||||
uint32_t offset)
|
||||
{
|
||||
memobj_op(p_obj, p_data, len, offset, true);
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
/**
|
||||
* Copyright (c) 2017 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NRF_MEMOBJ_H
|
||||
#define NRF_MEMOBJ_H
|
||||
|
||||
/**
|
||||
* @defgroup nrf_memobj Memory Object module
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
* @brief Functions for controlling memory object
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include "sdk_errors.h"
|
||||
#include "nrf_balloc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Memory object can consist of multiple object with the same size. Each object has header and data
|
||||
* part. First element in memory object is memory object head which has special header, remaining objects
|
||||
* has the same header. Model of memory object is presented below.
|
||||
*
|
||||
* |---------------------| |---------------------| |---------------------|
|
||||
* | head header (u32): | --->| std header - p_next |------->| p_memobj_pool |
|
||||
* | num_of_chunks, | | |---------------------| |---------------------|
|
||||
* | ref counter | | | | | |
|
||||
* |---------------------| | | | | |
|
||||
* | std header - p_next |-| | | .... | |
|
||||
* |---------------------| | data | | data |
|
||||
* | | | | | |
|
||||
* | data | | | | |
|
||||
* | | | | | |
|
||||
* |---------------------| |---------------------| |---------------------|
|
||||
* head mid_element last_element
|
||||
*
|
||||
*
|
||||
*/
|
||||
#define NRF_MEMOBJ_STD_HEADER_SIZE sizeof(uint32_t)
|
||||
|
||||
/**
|
||||
* @brief Macro for creating a nrf_memobj pool.
|
||||
*
|
||||
* Macro declares nrf_balloc object. Element in the pool contains user defined data part and
|
||||
* memobj header.
|
||||
*/
|
||||
#define NRF_MEMOBJ_POOL_DEF(_name, _element_size, _pool_size) \
|
||||
NRF_BALLOC_DEF(_name, ((_element_size)+NRF_MEMOBJ_STD_HEADER_SIZE), (_pool_size))
|
||||
|
||||
/**
|
||||
* @brief Pool of memobj.
|
||||
*/
|
||||
typedef nrf_balloc_t nrf_memobj_pool_t;
|
||||
|
||||
/**
|
||||
* @brief Memobj handle.
|
||||
*/
|
||||
typedef void * nrf_memobj_t;
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the memobj pool instance.
|
||||
*
|
||||
* This function initializes the pool.
|
||||
*
|
||||
* @param[in] p_pool Pointer to the memobj pool instance structure.
|
||||
*
|
||||
* @return NRF_SUCCESS on success, otherwise error code.
|
||||
*/
|
||||
ret_code_t nrf_memobj_pool_init(nrf_memobj_pool_t const * p_pool);
|
||||
|
||||
/**
|
||||
* @brief Function for allocating memobj with requested size.
|
||||
*
|
||||
* Fixed length elements in the pool are linked together to provide amount of memory requested by
|
||||
* the user. If memory object is successfully allocated then user can use memory however it is
|
||||
* fragmented into multiple object so it has to be access through the API: @ref nrf_memobj_write,
|
||||
* @ref nrf_memobj_read.
|
||||
*
|
||||
* This function initializes the pool.
|
||||
*
|
||||
* @param[in] p_pool Pointer to the memobj pool instance structure.
|
||||
* @param[in] size Data size of requested object.
|
||||
*
|
||||
* @return Pointer to memory object or NULL if requested size cannot be allocated.
|
||||
*/
|
||||
nrf_memobj_t * nrf_memobj_alloc(nrf_memobj_pool_t const * p_pool,
|
||||
size_t size);
|
||||
|
||||
/**
|
||||
* @brief Function for indicating that memory object is used and cannot be freed.
|
||||
*
|
||||
* Memory object can be shared and reused between multiple modules and this mechanism ensures that
|
||||
* object is freed when no longer used by any module. Memory object has a counter which is incremented
|
||||
* whenever this function is called. @ref nrf_memobj_put function decrements the counter.
|
||||
*
|
||||
* @param[in] p_obj Pointer to memory object.
|
||||
*/
|
||||
void nrf_memobj_get(nrf_memobj_t const * p_obj);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for indicated that memory object is no longer used by the module and can be freed
|
||||
* if no other module is using it.
|
||||
*
|
||||
* Memory object is returned to the pool if internal counter reaches 0 after decrementing. It means
|
||||
* that no other module is needing it anymore.
|
||||
*
|
||||
* @note Memory object holds pointer to the pool which was used to allocate it so it does not have
|
||||
* to be provided explicitly to this function.
|
||||
*
|
||||
* @param[in] p_obj Pointer to memory object.
|
||||
*/
|
||||
void nrf_memobj_put(nrf_memobj_t * p_obj);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for forcing freeing of the memory object.
|
||||
*
|
||||
* @note This function should be use with caution because it can lead to undefined behavior of the
|
||||
* modules since modules using the memory object are not aware that it has been freed.
|
||||
*
|
||||
* @param[in] p_obj Pointer to memory object.
|
||||
*/
|
||||
void nrf_memobj_free(nrf_memobj_t * p_obj);
|
||||
|
||||
/**
|
||||
* @brief Function for writing data to the memory object.
|
||||
*
|
||||
* @param[in] p_obj Pointer to memory object.
|
||||
* @param[in] p_data Pointer to data to be written to the memory object.
|
||||
* @param[in] len Amount of data to be written to the memory object.
|
||||
* @param[in] offset Offset.
|
||||
*/
|
||||
void nrf_memobj_write(nrf_memobj_t * p_obj,
|
||||
void * p_data,
|
||||
uint32_t len,
|
||||
uint32_t offset);
|
||||
|
||||
/**
|
||||
* @brief Function for reading data from the memory object.
|
||||
*
|
||||
* @param[in] p_obj Pointer to memory object.
|
||||
* @param[in] p_data Pointer to the destination buffer.
|
||||
* @param[in] len Amount of data to be read from the memory object.
|
||||
* @param[in] offset Offset.
|
||||
*/
|
||||
void nrf_memobj_read(nrf_memobj_t * p_obj,
|
||||
void * p_data,
|
||||
uint32_t len,
|
||||
uint32_t offset);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //NRF_MEMOBJ_H
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,191 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef NRF_SECTION_H__
|
||||
#define NRF_SECTION_H__
|
||||
|
||||
#include "nordic_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup section_vars Section variables
|
||||
* @ingroup app_common
|
||||
* @{
|
||||
*
|
||||
* @brief Section variables.
|
||||
*/
|
||||
|
||||
//lint -save -e27 -esym(526,*)
|
||||
|
||||
#if defined(__ICCARM__)
|
||||
// Enable IAR language extensions
|
||||
#pragma language=extended
|
||||
#endif
|
||||
|
||||
/**@brief Macro for obtaining the address of the beginning of a section.
|
||||
*
|
||||
* param[in] section_name Name of the section.
|
||||
* @hideinitializer
|
||||
*/
|
||||
#if defined(__CC_ARM)
|
||||
#define NRF_SECTION_START_ADDR(section_name) &CONCAT_2(section_name, $$Base)
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
#define NRF_SECTION_START_ADDR(section_name) &CONCAT_2(__start_, section_name)
|
||||
|
||||
#elif defined(__ICCARM__)
|
||||
#define NRF_SECTION_START_ADDR(section_name) __section_begin(STRINGIFY(section_name))
|
||||
#endif
|
||||
|
||||
|
||||
/**@brief Macro for obtaining the address of the end of a section.
|
||||
*
|
||||
* @param[in] section_name Name of the section.
|
||||
* @hideinitializer
|
||||
*/
|
||||
#if defined(__CC_ARM)
|
||||
#define NRF_SECTION_END_ADDR(section_name) &CONCAT_2(section_name, $$Limit)
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
#define NRF_SECTION_END_ADDR(section_name) &CONCAT_2(__stop_, section_name)
|
||||
|
||||
#elif defined(__ICCARM__)
|
||||
#define NRF_SECTION_END_ADDR(section_name) __section_end(STRINGIFY(section_name))
|
||||
#endif
|
||||
|
||||
|
||||
/**@brief Macro for retrieving the length of a given section, in bytes.
|
||||
*
|
||||
* @param[in] section_name Name of the section.
|
||||
* @hideinitializer
|
||||
*/
|
||||
#define NRF_SECTION_LENGTH(section_name) \
|
||||
((size_t)NRF_SECTION_END_ADDR(section_name) - \
|
||||
(size_t)NRF_SECTION_START_ADDR(section_name))
|
||||
|
||||
|
||||
/**@brief Macro for creating a section.
|
||||
*
|
||||
* @param[in] section_name Name of the section.
|
||||
* @param[in] data_type Data type of the variables to be registered in the section.
|
||||
*
|
||||
* @warning Data type must be word aligned to prevent padding.
|
||||
* @hideinitializer
|
||||
*/
|
||||
#if defined(__CC_ARM)
|
||||
#define NRF_SECTION_DEF(section_name, data_type) \
|
||||
extern data_type * CONCAT_2(section_name, $$Base); \
|
||||
extern void * CONCAT_2(section_name, $$Limit)
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
#define NRF_SECTION_DEF(section_name, data_type) \
|
||||
extern data_type * CONCAT_2(__start_, section_name); \
|
||||
extern void * CONCAT_2(__stop_, section_name)
|
||||
|
||||
#elif defined(__ICCARM__)
|
||||
#define NRF_SECTION_DEF(section_name, data_type) \
|
||||
_Pragma(STRINGIFY(section = STRINGIFY(section_name)));
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/**@brief Macro for declaring a variable and registering it in a section.
|
||||
*
|
||||
* @details Declares a variable and registers it in a named section. This macro ensures that the
|
||||
* variable is not stripped away when using optimizations.
|
||||
*
|
||||
* @note The order in which variables are placed in a section is dependent on the order in
|
||||
* which the linker script encounters the variables during linking.
|
||||
*
|
||||
* @param[in] section_name Name of the section.
|
||||
* @param[in] section_var Variable to register in the given section.
|
||||
* @hideinitializer
|
||||
*/
|
||||
#if defined(__CC_ARM)
|
||||
#define NRF_SECTION_ITEM_REGISTER(section_name, section_var) \
|
||||
section_var __attribute__ ((section(STRINGIFY(section_name)))) __attribute__((used))
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
#define NRF_SECTION_ITEM_REGISTER(section_name, section_var) \
|
||||
section_var __attribute__ ((section("." STRINGIFY(section_name)))) __attribute__((used))
|
||||
|
||||
#elif defined(__ICCARM__)
|
||||
#define NRF_SECTION_ITEM_REGISTER(section_name, section_var) \
|
||||
__root section_var @ STRINGIFY(section_name)
|
||||
#endif
|
||||
|
||||
|
||||
/**@brief Macro for retrieving a variable from a section.
|
||||
*
|
||||
* @warning The stored symbol can only be resolved using this macro if the
|
||||
* type of the data is word aligned. The operation of acquiring
|
||||
* the stored symbol relies on the size of the stored type. No
|
||||
* padding can exist in the named section in between individual
|
||||
* stored items or this macro will fail.
|
||||
*
|
||||
* @param[in] section_name Name of the section.
|
||||
* @param[in] data_type Data type of the variable.
|
||||
* @param[in] i Index of the variable in section.
|
||||
* @hideinitializer
|
||||
*/
|
||||
#define NRF_SECTION_ITEM_GET(section_name, data_type, i) \
|
||||
((data_type*)NRF_SECTION_START_ADDR(section_name) + (i))
|
||||
|
||||
|
||||
/**@brief Macro for getting the number of variables in a section.
|
||||
*
|
||||
* @param[in] section_name Name of the section.
|
||||
* @param[in] data_type Data type of the variables in the section.
|
||||
* @hideinitializer
|
||||
*/
|
||||
#define NRF_SECTION_ITEM_COUNT(section_name, data_type) \
|
||||
NRF_SECTION_LENGTH(section_name) / sizeof(data_type)
|
||||
|
||||
/** @} */
|
||||
|
||||
//lint -restore
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_SECTION_H__
|
||||
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_SECTION_ITER)
|
||||
|
||||
#include "nrf_section_iter.h"
|
||||
|
||||
|
||||
#if !defined(__GNUC__)
|
||||
static void nrf_section_iter_item_set(nrf_section_iter_t * p_iter)
|
||||
{
|
||||
ASSERT(p_iter != NULL);
|
||||
ASSERT(p_iter->p_set != NULL);
|
||||
ASSERT(p_iter->p_section != NULL);
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (p_iter->p_section == p_iter->p_set->p_last)
|
||||
{
|
||||
// End of the section set.
|
||||
p_iter->p_item = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_iter->p_section->p_start != p_iter->p_section->p_end)
|
||||
{
|
||||
// Not empty section.
|
||||
p_iter->p_item = p_iter->p_section->p_start;
|
||||
return;
|
||||
}
|
||||
|
||||
// Next section.
|
||||
p_iter->p_section++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void nrf_section_iter_init(nrf_section_iter_t * p_iter, nrf_section_set_t const * p_set)
|
||||
{
|
||||
ASSERT(p_iter != NULL);
|
||||
ASSERT(p_set != NULL);
|
||||
|
||||
p_iter->p_set = p_set;
|
||||
|
||||
#if defined(__GNUC__)
|
||||
p_iter->p_item = p_iter->p_set->section.p_start;
|
||||
if (p_iter->p_item == p_iter->p_set->section.p_end)
|
||||
{
|
||||
p_iter->p_item = NULL;
|
||||
}
|
||||
#else
|
||||
p_iter->p_section = p_set->p_first;
|
||||
nrf_section_iter_item_set(p_iter);
|
||||
#endif
|
||||
}
|
||||
|
||||
void nrf_section_iter_next(nrf_section_iter_t * p_iter)
|
||||
{
|
||||
ASSERT(p_iter != NULL);
|
||||
ASSERT(p_iter->p_set != NULL);
|
||||
|
||||
if (p_iter->p_item == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
p_iter->p_item = (void *)((size_t)(p_iter->p_item) + p_iter->p_set->item_size);
|
||||
|
||||
#if defined(__GNUC__)
|
||||
if (p_iter->p_item == p_iter->p_set->section.p_end)
|
||||
{
|
||||
p_iter->p_item = NULL;
|
||||
}
|
||||
#else
|
||||
ASSERT(p_iter->p_section != NULL);
|
||||
// End of current section reached?
|
||||
if (p_iter->p_item == p_iter->p_section->p_end)
|
||||
{
|
||||
p_iter->p_section++;
|
||||
nrf_section_iter_item_set(p_iter);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_SECTION_ITER)
|
||||
@@ -0,0 +1,206 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NRF_SECTION_ITER_H__
|
||||
#define NRF_SECTION_ITER_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include "nrf_section.h"
|
||||
#include "nrf_assert.h"
|
||||
#include "app_util.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup nrf_section_iter Section variables iterator
|
||||
* @ingroup app_common
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**@brief Single section description structure. */
|
||||
typedef struct
|
||||
{
|
||||
void * p_start; //!< Pointer to the start of section.
|
||||
void * p_end; //!< Pointer to the end of section.
|
||||
} nrf_section_t;
|
||||
|
||||
|
||||
/**@brief Set of the sections description structure. */
|
||||
typedef struct
|
||||
{
|
||||
#if defined(__GNUC__)
|
||||
nrf_section_t section; //!< Description of the set of sections.
|
||||
/**<
|
||||
* In case of GCC all sections in the set are sorted and
|
||||
* placed in contiguous area, because they are treated as
|
||||
* one section.
|
||||
*/
|
||||
#else
|
||||
nrf_section_t const * p_first; //!< Pointer to the first section in the set.
|
||||
nrf_section_t const * p_last; //!< Pointer to the last section in the set.
|
||||
#endif
|
||||
size_t item_size; //!< Size of the single item in the section.
|
||||
} nrf_section_set_t;
|
||||
|
||||
|
||||
/**@brief Section iterator structure. */
|
||||
typedef struct
|
||||
{
|
||||
nrf_section_set_t const * p_set; //!< Pointer to the appropriate section set.
|
||||
#if !defined(__GNUC__)
|
||||
nrf_section_t const * p_section; //!< Pointer to the selected section.
|
||||
/**<
|
||||
* In case of GCC all sections in the set are sorted and
|
||||
* placed in contiguous area, because they are treated
|
||||
* as one section.
|
||||
*/
|
||||
#endif
|
||||
void * p_item; //!< Pointer to the selected item in the section.
|
||||
} nrf_section_iter_t;
|
||||
|
||||
|
||||
/**@brief Create a set of sections.
|
||||
*
|
||||
* @note This macro reserves memory for the given set of sections.
|
||||
*
|
||||
* @details A set of sections, is an ordered collections of sections.
|
||||
*
|
||||
* @param[in] _name Name of the set.
|
||||
* @param[in] _type Type of the elements stored in the sections.
|
||||
* @param[in] _count Number of the sections in the set. This parameter is ignored in case of GCC.
|
||||
* @hideinitializer
|
||||
*/
|
||||
#if defined(__GNUC__)
|
||||
|
||||
#define NRF_SECTION_SET_DEF(_name, _type, _count) \
|
||||
\
|
||||
NRF_SECTION_DEF(_name, _type); \
|
||||
static nrf_section_set_t const _name = \
|
||||
{ \
|
||||
.section = \
|
||||
{ \
|
||||
.p_start = NRF_SECTION_START_ADDR(_name), \
|
||||
.p_end = NRF_SECTION_END_ADDR(_name), \
|
||||
}, \
|
||||
.item_size = sizeof(_type), \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define NRF_SECTION_SET_DEF(_name, _type, _count) \
|
||||
/*lint -save -emacro(14, MACRO_REPEAT_FOR*) */ \
|
||||
MACRO_REPEAT_FOR(_count, NRF_SECTION_DEF_, _name, _type) \
|
||||
static nrf_section_t const CONCAT_2(_name, _array)[] = \
|
||||
{ \
|
||||
MACRO_REPEAT_FOR(_count, NRF_SECTION_SET_DEF_, _name) \
|
||||
}; \
|
||||
/*lint -restore */ \
|
||||
static nrf_section_set_t const _name = \
|
||||
{ \
|
||||
.p_first = CONCAT_2(_name, _array), \
|
||||
.p_last = CONCAT_2(_name, _array) + ARRAY_SIZE(CONCAT_2(_name, _array)), \
|
||||
.item_size = sizeof(_type), \
|
||||
}
|
||||
|
||||
#ifndef DOXYGEN
|
||||
#define NRF_SECTION_DEF_(_priority, _name, _type) \
|
||||
NRF_SECTION_DEF(CONCAT_2(_name, _priority), _type);
|
||||
|
||||
#define NRF_SECTION_SET_DEF_(_priority, _name) \
|
||||
{ \
|
||||
.p_start = NRF_SECTION_START_ADDR(CONCAT_2(_name, _priority)), \
|
||||
.p_end = NRF_SECTION_END_ADDR(CONCAT_2(_name, _priority)), \
|
||||
},
|
||||
#endif // DOXYGEN
|
||||
#endif // __GNUC__
|
||||
|
||||
|
||||
/**@brief Macro to declare a variable and register it in the section set.
|
||||
*
|
||||
* @note The order of the section in the set is based on the priority. The order with which
|
||||
* variables are placed in a section is dependant on the order with which the linker
|
||||
* encouters the variables during linking.
|
||||
*
|
||||
* @param[in] _name Name of the section set.
|
||||
* @param[in] _priority Priority of the desired section.
|
||||
* @param[in] _var The variable to register in the given section.
|
||||
* @hideinitializer
|
||||
*/
|
||||
#define NRF_SECTION_SET_ITEM_REGISTER(_name, _priority, _var) \
|
||||
NRF_SECTION_ITEM_REGISTER(CONCAT_2(_name, _priority), _var)
|
||||
|
||||
|
||||
/**@brief Function for initializing the section set iterator.
|
||||
*
|
||||
* @param[in] p_iter Pointer to the iterator.
|
||||
* @param[in] p_set Pointer to the sections set.
|
||||
*/
|
||||
void nrf_section_iter_init(nrf_section_iter_t * p_iter, nrf_section_set_t const * p_set);
|
||||
|
||||
|
||||
/**@brief Function for incrementing iterator.
|
||||
*
|
||||
* @param[in] p_iter Pointer to the iterator.
|
||||
*/
|
||||
void nrf_section_iter_next(nrf_section_iter_t * p_iter);
|
||||
|
||||
|
||||
/**@brief Function for getting the element pointed to by the iterator.
|
||||
*
|
||||
* @param[in] p_iter Pointer to the iterator.
|
||||
*
|
||||
* @retval Pointer to the element or NULL if iterator points end of the set.
|
||||
*/
|
||||
static inline void * nrf_section_iter_get(nrf_section_iter_t const * p_iter)
|
||||
{
|
||||
ASSERT(p_iter);
|
||||
return p_iter->p_item;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_SECTION_ITER_H__
|
||||
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* Copyright (c) 2011 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(NRF_STRERROR)
|
||||
#include "nrf_strerror.h"
|
||||
|
||||
/**
|
||||
* @brief Macro for adding an entity to the description array.
|
||||
*
|
||||
* Macro that helps to create a single entity in the description array.
|
||||
*/
|
||||
#define NRF_STRERROR_ENTITY(mnemonic) {.code = mnemonic, .name = #mnemonic}
|
||||
|
||||
/**
|
||||
* @brief Array entity element that describes an error.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
ret_code_t code; /**< Error code. */
|
||||
char const * name; /**< Descriptive name (the same as the internal error mnemonic). */
|
||||
}nrf_strerror_desc_t;
|
||||
|
||||
/**
|
||||
* @brief Unknown error code.
|
||||
*
|
||||
* The constant string used by @ref nrf_strerror_get when the error description was not found.
|
||||
*/
|
||||
static char const m_unknown_str[] = "Unknown error code";
|
||||
|
||||
/**
|
||||
* @brief Array with error codes.
|
||||
*
|
||||
* Array that describes error codes.
|
||||
*
|
||||
* @note It is required for this array to have error codes placed in ascending order.
|
||||
* This condition is checked in automatic unit test before the release.
|
||||
*/
|
||||
static nrf_strerror_desc_t const nrf_strerror_array[] =
|
||||
{
|
||||
NRF_STRERROR_ENTITY(NRF_SUCCESS),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_SVC_HANDLER_MISSING),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_SOFTDEVICE_NOT_ENABLED),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_INTERNAL),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_NO_MEM),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_NOT_FOUND),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_NOT_SUPPORTED),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_INVALID_PARAM),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_INVALID_STATE),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_INVALID_LENGTH),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_INVALID_FLAGS),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_INVALID_DATA),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_DATA_SIZE),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_TIMEOUT),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_NULL),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_FORBIDDEN),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_INVALID_ADDR),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_BUSY),
|
||||
|
||||
/* SDK Common errors */
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_MODULE_NOT_INITIALZED),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_MUTEX_INIT_FAILED),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_MUTEX_LOCK_FAILED),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_MUTEX_UNLOCK_FAILED),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_MUTEX_COND_INIT_FAILED),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_MODULE_ALREADY_INITIALIZED),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_STORAGE_FULL),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_API_NOT_IMPLEMENTED),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_FEATURE_NOT_ENABLED),
|
||||
|
||||
/* TWI error codes */
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_DRV_TWI_ERR_OVERRUN),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_DRV_TWI_ERR_ANACK),
|
||||
NRF_STRERROR_ENTITY(NRF_ERROR_DRV_TWI_ERR_DNACK)
|
||||
};
|
||||
|
||||
|
||||
char const * nrf_strerror_get(ret_code_t code)
|
||||
{
|
||||
char const * p_ret = nrf_strerror_find(code);
|
||||
return (p_ret == NULL) ? m_unknown_str : p_ret;
|
||||
}
|
||||
|
||||
char const * nrf_strerror_find(ret_code_t code)
|
||||
{
|
||||
nrf_strerror_desc_t const * p_start;
|
||||
nrf_strerror_desc_t const * p_end;
|
||||
p_start = nrf_strerror_array;
|
||||
p_end = nrf_strerror_array + ARRAY_SIZE(nrf_strerror_array);
|
||||
|
||||
while (p_start < p_end)
|
||||
{
|
||||
nrf_strerror_desc_t const * p_mid = p_start + ((p_end - p_start) / 2);
|
||||
ret_code_t mid_c = p_mid->code;
|
||||
if (mid_c > code)
|
||||
{
|
||||
p_end = p_mid;
|
||||
}
|
||||
else if (mid_c < code)
|
||||
{
|
||||
p_start = p_mid + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return p_mid->name;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* NRF_STRERROR enabled */
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright (c) 2017 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup nrf_strerror Error code to string converter
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @brief Module for converting error code into a printable string.
|
||||
* @{
|
||||
*/
|
||||
#ifndef NRF_STRERROR_H__
|
||||
#define NRF_STRERROR_H__
|
||||
|
||||
#include "sdk_errors.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Function for getting a printable error string.
|
||||
*
|
||||
* @param code Error code to convert.
|
||||
*
|
||||
* @note This function cannot fail.
|
||||
* For the function that may fail with error translation, see @ref nrf_strerror_find.
|
||||
*
|
||||
* @return Pointer to the printable string.
|
||||
* If the string is not found,
|
||||
* it returns a simple string that says that the error is unknown.
|
||||
*/
|
||||
char const * nrf_strerror_get(ret_code_t code);
|
||||
|
||||
/**
|
||||
* @brief Function for finding a printable error string.
|
||||
*
|
||||
* This function gets the error string in the same way as @ref nrf_strerror_get,
|
||||
* but if the string is not found, it returns NULL.
|
||||
*
|
||||
* @param code Error code to convert.
|
||||
* @return Pointer to the printable string.
|
||||
* If the string is not found, NULL is returned.
|
||||
*/
|
||||
char const * nrf_strerror_find(ret_code_t code);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_STRERROR_H__ */
|
||||
@@ -0,0 +1,143 @@
|
||||
/**
|
||||
* Copyright (c) 2014 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @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"
|
||||
/**@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 */
|
||||
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* Copyright (c) 2013 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @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 "app_error_weak.h"
|
||||
#ifdef ANT_STACK_SUPPORT_REQD
|
||||
#include "ant_error.h"
|
||||
#endif // ANT_STACK_SUPPORT_REQD
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#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 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)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // APP_ERROR_H__
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "app_error.h"
|
||||
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_strerror.h"
|
||||
|
||||
#if defined(SOFTDEVICE_PRESENT) && SOFTDEVICE_PRESENT
|
||||
#include "nrf_sdm.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)
|
||||
{
|
||||
NRF_LOG_FINAL_FLUSH();
|
||||
|
||||
#ifndef DEBUG
|
||||
NRF_LOG_ERROR("Fatal error");
|
||||
#else
|
||||
switch (id)
|
||||
{
|
||||
#if defined(SOFTDEVICE_PRESENT) && SOFTDEVICE_PRESENT
|
||||
case NRF_FAULT_ID_SD_ASSERT:
|
||||
NRF_LOG_ERROR("SOFTDEVICE: ASSERTION FAILED");
|
||||
break;
|
||||
case NRF_FAULT_ID_APP_MEMACC:
|
||||
NRF_LOG_ERROR("SOFTDEVICE: INVALID MEMORY ACCESS");
|
||||
break;
|
||||
#endif
|
||||
case NRF_FAULT_ID_SDK_ASSERT:
|
||||
{
|
||||
assert_info_t * p_info = (assert_info_t *)info;
|
||||
NRF_LOG_ERROR("ASSERTION FAILED at %s:%u",
|
||||
p_info->p_file_name,
|
||||
p_info->line_num);
|
||||
break;
|
||||
}
|
||||
case NRF_FAULT_ID_SDK_ERROR:
|
||||
{
|
||||
error_info_t * p_info = (error_info_t *)info;
|
||||
NRF_LOG_ERROR("ERROR %u [%s] at %s:%u",
|
||||
p_info->err_code,
|
||||
nrf_strerror_get(p_info->err_code),
|
||||
p_info->p_file_name,
|
||||
p_info->line_num);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
NRF_LOG_ERROR("UNKNOWN FAULT at 0x%08X", pc);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
NRF_BREAKPOINT_COND;
|
||||
// On assert, the system can only recover with a reset.
|
||||
|
||||
#ifndef DEBUG
|
||||
NRF_LOG_WARNING("System reset");
|
||||
NVIC_SystemReset();
|
||||
#else
|
||||
app_error_save_and_stop(id, pc, info);
|
||||
#endif // DEBUG
|
||||
}
|
||||
|
||||
/*lint -restore */
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_ERROR_WEAK_H__
|
||||
#define APP_ERROR_WEAK_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @defgroup app_error Common application error handler
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @brief Common application error handler.
|
||||
*/
|
||||
|
||||
/**@brief Callback function for errors, asserts, and faults.
|
||||
*
|
||||
* @details This function is called every time an error is raised in app_error, nrf_assert, or
|
||||
* in the SoftDevice. Information about the error can be found in the @p info
|
||||
* parameter.
|
||||
*
|
||||
* See also @ref nrf_fault_handler_t for more details.
|
||||
*
|
||||
* @note The function is implemented as weak so that it can be redefined by a custom error
|
||||
* handler when needed.
|
||||
*
|
||||
* @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. The value of the @p id
|
||||
* parameter dictates how to interpret this parameter. Refer to the documentation
|
||||
* for each fault identifier (@ref NRF_FAULT_IDS and @ref APP_ERROR_FAULT_IDS) for
|
||||
* details about interpreting @p info.
|
||||
*/
|
||||
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // APP_ERROR_WEAK_H__
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,449 @@
|
||||
/**
|
||||
* Copyright (c) 2012 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @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"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // APP_UTIL_BDS_H__
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* Copyright (c) 2014 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "app_util_platform.h"
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
/* Global nvic state instance, required by nrf_nvic.h */
|
||||
nrf_nvic_state_t nrf_nvic_state;
|
||||
#endif
|
||||
|
||||
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)
|
||||
{
|
||||
#if __CORTEX_M == (0x04U)
|
||||
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)
|
||||
{
|
||||
#if __CORTEX_M == (0x04U)
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
uint8_t privilege_level_get(void)
|
||||
{
|
||||
#if __CORTEX_M == (0x00U) || defined(_WIN32) || defined(__unix) || defined(__APPLE__)
|
||||
/* the Cortex-M0 has no concept of privilege */
|
||||
return APP_LEVEL_PRIVILEGED;
|
||||
#elif __CORTEX_M == (0x04U)
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
/**
|
||||
* Copyright (c) 2014 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**@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"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if __CORTEX_M == (0x00U)
|
||||
#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 __CORTEX_M == (0x04U)
|
||||
#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
|
||||
|
||||
|
||||
//lint -save -e113 -e452
|
||||
/**@brief The interrupt priorities available to the application while the SoftDevice is active. */
|
||||
typedef enum
|
||||
{
|
||||
#ifndef 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;
|
||||
//lint -restore
|
||||
|
||||
|
||||
/*@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 */
|
||||
|
||||
/**@brief Macro for setting a breakpoint.
|
||||
*/
|
||||
#if defined(__GNUC__)
|
||||
#define NRF_BREAKPOINT __builtin_trap()
|
||||
#else
|
||||
#define NRF_BREAKPOINT __BKPT(0)
|
||||
#endif
|
||||
|
||||
/** @brief Macro for setting a breakpoint.
|
||||
*
|
||||
* If it is possible to detect debugger presence then it is set only in that case.
|
||||
*
|
||||
*/
|
||||
#if __CORTEX_M == 0x04
|
||||
#define NRF_BREAKPOINT_COND do { \
|
||||
/* C_DEBUGEN == 1 -> Debugger Connected */ \
|
||||
if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) \
|
||||
{ \
|
||||
/* Generate breakpoint if debugger is connected */ \
|
||||
NRF_BREAKPOINT; \
|
||||
} \
|
||||
}while (0)
|
||||
#else
|
||||
#define NRF_BREAKPOINT_COND NRF_BREAKPOINT
|
||||
#endif // __CORTEX_M == 0x04
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
#define PACKED(TYPE) __packed TYPE
|
||||
#define PACKED_STRUCT PACKED(struct)
|
||||
#elif defined ( __GNUC__ )
|
||||
#define PACKED __attribute__((packed))
|
||||
#define PACKED_STRUCT struct PACKED
|
||||
#elif defined (__ICCARM__)
|
||||
#define PACKED_STRUCT __packed struct
|
||||
#endif
|
||||
|
||||
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
|
||||
|
||||
/**@brief Macro for adding pragma directive only for GCC.
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
#define GCC_PRAGMA(v) _Pragma(v)
|
||||
#else
|
||||
#define GCC_PRAGMA(v)
|
||||
#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.
|
||||
*/
|
||||
uint8_t current_int_priority_get(void);
|
||||
|
||||
|
||||
/**@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.
|
||||
*/
|
||||
uint8_t privilege_level_get(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // APP_UTIL_PLATFORM_H__
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,211 @@
|
||||
/**
|
||||
* Copyright (c) 2008 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @file
|
||||
* @brief Common defines and macros for firmware developed by Nordic Semiconductor.
|
||||
*/
|
||||
|
||||
#ifndef NORDIC_COMMON_H__
|
||||
#define NORDIC_COMMON_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Check if selected module is enabled
|
||||
*
|
||||
* This is save function for driver enable checking.
|
||||
* Correct from Lint point of view (not using default of undefined value).
|
||||
*
|
||||
* Usage:
|
||||
* @code
|
||||
#if NRF_MODULE_ENABLED(UART)
|
||||
...
|
||||
#endif
|
||||
* @endcode
|
||||
*
|
||||
* @param module The module name.
|
||||
*
|
||||
* @retval 1 The macro <module>_ENABLE is defined and is non-zero.
|
||||
* @retval 0 The macro <module>_ENABLE is not defined or it equals zero.
|
||||
*
|
||||
* @note
|
||||
* This macro intentionally does not implement second expansion level.
|
||||
* The name of the module to be checked has to be given directly as a parameter.
|
||||
* And given parameter would be connected with @c _ENABLED postfix directly
|
||||
* without evaluating its value.
|
||||
*/
|
||||
//lint -emacro(491,NRF_MODULE_ENABLED) // Suppers warning 491 "non-standard use of 'defined' preprocessor operator"
|
||||
#define NRF_MODULE_ENABLED(module) \
|
||||
((defined(module ## _ENABLED) && (module ## _ENABLED)) ? 1 : 0)
|
||||
|
||||
/** The upper 8 bits of a 32 bit value */
|
||||
//lint -emacro(572,MSB_32) // 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))
|
||||
|
||||
/**@brief Concatenates two parameters.
|
||||
*
|
||||
* It realizes two level expansion to make it sure that all the parameters
|
||||
* are actually expanded before gluing them together.
|
||||
*
|
||||
* @param p1 First parameter to concatenating
|
||||
* @param p2 Second parameter to concatenating
|
||||
*
|
||||
* @return Two parameters glued together.
|
||||
* They have to create correct C mnemonic in other case
|
||||
* preprocessor error would be generated.
|
||||
*
|
||||
* @sa CONCAT_3
|
||||
*/
|
||||
#define CONCAT_2(p1, p2) CONCAT_2_(p1, p2)
|
||||
/** Auxiliary macro used by @ref CONCAT_2 */
|
||||
#define CONCAT_2_(p1, p2) p1##p2
|
||||
|
||||
/**@brief Concatenates three parameters.
|
||||
*
|
||||
* It realizes two level expansion to make it sure that all the parameters
|
||||
* are actually expanded before gluing them together.
|
||||
*
|
||||
* @param p1 First parameter to concatenating
|
||||
* @param p2 Second parameter to concatenating
|
||||
* @param p3 Third parameter to concatenating
|
||||
*
|
||||
* @return Three parameters glued together.
|
||||
* They have to create correct C mnemonic in other case
|
||||
* preprocessor error would be generated.
|
||||
*
|
||||
* @sa CONCAT_2
|
||||
*/
|
||||
#define CONCAT_3(p1, p2, p3) CONCAT_3_(p1, p2, p3)
|
||||
/** Auxiliary macro used by @ref CONCAT_3 */
|
||||
#define CONCAT_3_(p1, p2, p3) p1##p2##p3
|
||||
|
||||
#define STRINGIFY_(val) #val
|
||||
/** Converts a macro argument into a character constant.
|
||||
*/
|
||||
#define STRINGIFY(val) STRINGIFY_(val)
|
||||
|
||||
/** Counts number of elements inside the array
|
||||
*/
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
/**@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)(1U << (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)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NORDIC_COMMON_H__
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Copyright (c) 2006 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "nrf_assert.h"
|
||||
#include "app_error.h"
|
||||
#include "nordic_common.h"
|
||||
|
||||
__WEAK 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);
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* Copyright (c) 2006 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @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"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief Function for handling assertions.
|
||||
*
|
||||
*
|
||||
* @note
|
||||
* This function is called when an assertion has triggered.
|
||||
*
|
||||
* @note
|
||||
* This function is deprecated and will be removed in future releases.
|
||||
* Use app_error_fault_handler instead.
|
||||
*
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
//lint -save -esym(14, assert_nrf_callback)
|
||||
void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name);
|
||||
//lint -restore
|
||||
|
||||
#if (defined(DEBUG_NRF) || defined(DEBUG_NRF_USER))
|
||||
#define NRF_ASSERT_PRESENT 1
|
||||
#else
|
||||
#define NRF_ASSERT_PRESENT 0
|
||||
#endif
|
||||
|
||||
//#if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER)
|
||||
|
||||
/*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. */
|
||||
|
||||
#ifdef _lint
|
||||
#define ASSERT(expr) \
|
||||
if (expr) \
|
||||
{ \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
while (1); \
|
||||
}
|
||||
#else //_lint
|
||||
#define ASSERT(expr) \
|
||||
if (NRF_ASSERT_PRESENT) \
|
||||
{ \
|
||||
if (expr) \
|
||||
{ \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
assert_nrf_callback((uint16_t)__LINE__, (uint8_t *)__FILE__); \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_ASSERT_H_ */
|
||||
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* Copyright (c) 2006 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef NRF_BITMASK_H
|
||||
#define NRF_BITMASK_H
|
||||
|
||||
#include "compiler_abstraction.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define BITMASK_BYTE_GET(abs_bit) ((abs_bit)/8)
|
||||
#define BITMASK_RELBIT_GET(abs_bit) ((abs_bit) & 0x00000007)
|
||||
|
||||
/**
|
||||
* Function for checking if bit in the multi-byte bit mask is set.
|
||||
*
|
||||
* @param bit Bit index.
|
||||
* @param p_mask A pointer to mask with bit fields.
|
||||
*
|
||||
* @return 0 if bit is not set, positive value otherwise.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_bitmask_bit_is_set(uint32_t bit, void const * p_mask)
|
||||
{
|
||||
uint8_t const * p_mask8 = (uint8_t const *)p_mask;
|
||||
uint32_t byte_idx = BITMASK_BYTE_GET(bit);
|
||||
bit = BITMASK_RELBIT_GET(bit);
|
||||
return (1 << bit) & p_mask8[byte_idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for setting a bit in the multi-byte bit mask.
|
||||
*
|
||||
* @param bit Bit index.
|
||||
* @param p_mask A pointer to mask with bit fields.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_bitmask_bit_set(uint32_t bit, void * p_mask)
|
||||
{
|
||||
uint8_t * p_mask8 = (uint8_t *)p_mask;
|
||||
uint32_t byte_idx = BITMASK_BYTE_GET(bit);
|
||||
bit = BITMASK_RELBIT_GET(bit);
|
||||
p_mask8[byte_idx] |= (1 << bit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for clearing a bit in the multi-byte bit mask.
|
||||
*
|
||||
* @param bit Bit index.
|
||||
* @param p_mask A pointer to mask with bit fields.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_bitmask_bit_clear(uint32_t bit, void * p_mask)
|
||||
{
|
||||
uint8_t * p_mask8 = (uint8_t *)p_mask;
|
||||
uint32_t byte_idx = BITMASK_BYTE_GET(bit);
|
||||
bit = BITMASK_RELBIT_GET(bit);
|
||||
p_mask8[byte_idx] &= ~(1 << bit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for performing bitwise OR operation on two multi-byte bit masks.
|
||||
*
|
||||
* @param p_mask1 A pointer to the first bit mask.
|
||||
* @param p_mask2 A pointer to the second bit mask.
|
||||
* @param p_mask_out A pointer to the output bit mask.
|
||||
* @param length Length of output mask in bytes.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_bitmask_masks_or(void const * p_mask1,
|
||||
void const * p_mask2,
|
||||
void * p_out_mask,
|
||||
uint32_t length)
|
||||
{
|
||||
uint8_t const * p_mask8_1 = (uint8_t const *)p_mask1;
|
||||
uint8_t const * p_mask8_2 = (uint8_t const *)p_mask2;
|
||||
uint8_t * p_mask8_out = (uint8_t *)p_out_mask;
|
||||
uint32_t i;
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
p_mask8_out[i] = p_mask8_1[i] | p_mask8_2[i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for performing bitwise AND operation on two multi-byte bit masks.
|
||||
*
|
||||
* @param p_mask1 A pointer to the first bit mask.
|
||||
* @param p_mask2 A pointer to the second bit mask.
|
||||
* @param p_mask_out A pointer to the output bit mask.
|
||||
* @param length Length of output mask in bytes.
|
||||
*/
|
||||
__STATIC_INLINE void nrf_bitmask_masks_and(void const * p_mask1,
|
||||
void const * p_mask2,
|
||||
void * p_out_mask,
|
||||
uint32_t length)
|
||||
{
|
||||
uint8_t const * p_mask8_1 = (uint8_t const *)p_mask1;
|
||||
uint8_t const * p_mask8_2 = (uint8_t const *)p_mask2;
|
||||
uint8_t * p_mask8_out = (uint8_t *)p_out_mask;
|
||||
uint32_t i;
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
p_mask8_out[i] = p_mask8_1[i] & p_mask8_2[i];
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //NRF_BITMASK_H
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2013 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @cond */
|
||||
/**@file
|
||||
*
|
||||
* @ingroup experimental_api
|
||||
* @defgroup sdk_common SDK Common Header
|
||||
* @brief 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 "sdk_config.h"
|
||||
#include "nordic_common.h"
|
||||
#include "compiler_abstraction.h"
|
||||
#include "sdk_os.h"
|
||||
#include "sdk_errors.h"
|
||||
#include "app_util.h"
|
||||
#include "sdk_macros.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/** @} */
|
||||
/** @endcond */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SDK_COMMON_H__
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
/**
|
||||
* Copyright (c) 2013 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**@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"
|
||||
#include "sdk_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup sdk_err_base Base defined for SDK Modules
|
||||
* @{
|
||||
*/
|
||||
#define NRF_ERROR_SDK_ERROR_BASE (NRF_ERROR_BASE_NUM + 0x8000) /**< Base value defined for SDK module identifiers. */
|
||||
#define NRF_ERROR_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 NRF_ERROR_MEMORY_MANAGER_ERR_BASE (0x8100)
|
||||
#define NRF_ERROR_PERIPH_DRIVERS_ERR_BASE (0x8200)
|
||||
#define NRF_ERROR_GAZELLE_ERR_BASE (0x8300)
|
||||
#define NRF_ERROR_BLE_IPSP_ERR_BASE (0x8400)
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup sdk_iot_errors Codes reserved as identification for IoT errors.
|
||||
* @{
|
||||
*/
|
||||
#define NRF_ERROR_IOT_ERR_BASE_START (0xA000)
|
||||
#define NRF_ERROR_IOT_ERR_BASE_STOP (0xAFFF)
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup sdk_common_errors Codes reserved as identification for common errors.
|
||||
* @{
|
||||
*/
|
||||
#define NRF_ERROR_MODULE_NOT_INITIALZED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0000)
|
||||
#define NRF_ERROR_MUTEX_INIT_FAILED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0001)
|
||||
#define NRF_ERROR_MUTEX_LOCK_FAILED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0002)
|
||||
#define NRF_ERROR_MUTEX_UNLOCK_FAILED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0003)
|
||||
#define NRF_ERROR_MUTEX_COND_INIT_FAILED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0004)
|
||||
#define NRF_ERROR_MODULE_ALREADY_INITIALIZED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0005)
|
||||
#define NRF_ERROR_STORAGE_FULL (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0006)
|
||||
#define NRF_ERROR_API_NOT_IMPLEMENTED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0010)
|
||||
#define NRF_ERROR_FEATURE_NOT_ENABLED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0011)
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup drv_specific_errors Error / status codes specific to drivers.
|
||||
* @{
|
||||
*/
|
||||
#define NRF_ERROR_DRV_TWI_ERR_OVERRUN (NRF_ERROR_PERIPH_DRIVERS_ERR_BASE + 0x0000)
|
||||
#define NRF_ERROR_DRV_TWI_ERR_ANACK (NRF_ERROR_PERIPH_DRIVERS_ERR_BASE + 0x0001)
|
||||
#define NRF_ERROR_DRV_TWI_ERR_DNACK (NRF_ERROR_PERIPH_DRIVERS_ERR_BASE + 0x0002)
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup ble_ipsp_errors IPSP codes
|
||||
* @brief Error and status codes specific to IPSP.
|
||||
* @{
|
||||
*/
|
||||
#define NRF_ERROR_BLE_IPSP_RX_PKT_TRUNCATED (NRF_ERROR_BLE_IPSP_ERR_BASE + 0x0000)
|
||||
#define NRF_ERROR_BLE_IPSP_CHANNEL_ALREADY_EXISTS (NRF_ERROR_BLE_IPSP_ERR_BASE + 0x0001)
|
||||
#define NRF_ERROR_BLE_IPSP_LINK_DISCONNECTED (NRF_ERROR_BLE_IPSP_ERR_BASE + 0x0002)
|
||||
#define NRF_ERROR_BLE_IPSP_PEER_REJECTED (NRF_ERROR_BLE_IPSP_ERR_BASE + 0x0003)
|
||||
/* @} */
|
||||
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SDK_ERRORS_H__
|
||||
@@ -0,0 +1,191 @@
|
||||
/**
|
||||
* Copyright (c) 2013 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**@file
|
||||
*
|
||||
|
||||
* @defgroup sdk_common_macros SDK Common Header
|
||||
* @ingroup app_common
|
||||
* @brief Macros for parameter checking and similar tasks
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef SDK_MACROS_H__
|
||||
#define SDK_MACROS_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**@brief Macro for verifying statement to be true. It will cause the exterior function to return
|
||||
* err_code if the statement is not true.
|
||||
*
|
||||
* @param[in] statement Statement to test.
|
||||
* @param[in] err_code Error value to return if test was invalid.
|
||||
*
|
||||
* @retval nothing, but will cause the exterior function to return @p err_code if @p statement
|
||||
* is false.
|
||||
*/
|
||||
#define VERIFY_TRUE(statement, err_code) \
|
||||
do \
|
||||
{ \
|
||||
if (!(statement)) \
|
||||
{ \
|
||||
return err_code; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/**@brief Macro for verifying statement to be true. It will cause the exterior function to return
|
||||
* if the statement is not true.
|
||||
*
|
||||
* @param[in] statement Statement to test.
|
||||
*/
|
||||
#define VERIFY_TRUE_VOID(statement) VERIFY_TRUE((statement), )
|
||||
|
||||
|
||||
/**@brief Macro for verifying statement to be false. It will cause the exterior function to return
|
||||
* err_code if the statement is not false.
|
||||
*
|
||||
* @param[in] statement Statement to test.
|
||||
* @param[in] err_code Error value to return if test was invalid.
|
||||
*
|
||||
* @retval nothing, but will cause the exterior function to return @p err_code if @p statement
|
||||
* is true.
|
||||
*/
|
||||
#define VERIFY_FALSE(statement, err_code) \
|
||||
do \
|
||||
{ \
|
||||
if ((statement)) \
|
||||
{ \
|
||||
return err_code; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/**@brief Macro for verifying statement to be false. It will cause the exterior function to return
|
||||
* if the statement is not false.
|
||||
*
|
||||
* @param[in] statement Statement to test.
|
||||
*/
|
||||
#define VERIFY_FALSE_VOID(statement) VERIFY_FALSE((statement), )
|
||||
|
||||
|
||||
/**@brief Macro for verifying that a function returned NRF_SUCCESS. It will cause the exterior
|
||||
* function to return err_code if the err_code is not @ref NRF_SUCCESS.
|
||||
*
|
||||
* @param[in] err_code The error code to check.
|
||||
*/
|
||||
#ifdef DISABLE_PARAM_CHECK
|
||||
#define VERIFY_SUCCESS()
|
||||
#else
|
||||
#define VERIFY_SUCCESS(err_code) VERIFY_TRUE((err_code) == NRF_SUCCESS, (err_code))
|
||||
#endif /* DISABLE_PARAM_CHECK */
|
||||
|
||||
|
||||
/**@brief Macro for verifying that a function returned NRF_SUCCESS. It will cause the exterior
|
||||
* function to return if the err_code is not @ref NRF_SUCCESS.
|
||||
*
|
||||
* @param[in] err_code The error code to check.
|
||||
*/
|
||||
#ifdef DISABLE_PARAM_CHECK
|
||||
#define VERIFY_SUCCESS_VOID()
|
||||
#else
|
||||
#define VERIFY_SUCCESS_VOID(err_code) VERIFY_TRUE_VOID((err_code) == NRF_SUCCESS)
|
||||
#endif /* DISABLE_PARAM_CHECK */
|
||||
|
||||
|
||||
/**@brief Macro for verifying that the module is initialized. It will cause the exterior function to
|
||||
* return @ref NRF_ERROR_INVALID_STATE if not.
|
||||
*
|
||||
* @note MODULE_INITIALIZED must be defined in each module using this macro. MODULE_INITIALIZED
|
||||
* should be true if the module is initialized, false if not.
|
||||
*/
|
||||
#ifdef DISABLE_PARAM_CHECK
|
||||
#define VERIFY_MODULE_INITIALIZED()
|
||||
#else
|
||||
#define VERIFY_MODULE_INITIALIZED() VERIFY_TRUE((MODULE_INITIALIZED), NRF_ERROR_INVALID_STATE)
|
||||
#endif /* DISABLE_PARAM_CHECK */
|
||||
|
||||
|
||||
/**@brief Macro for verifying that the module is initialized. It will cause the exterior function to
|
||||
* return if not.
|
||||
*
|
||||
* @note MODULE_INITIALIZED must be defined in each module using this macro. MODULE_INITIALIZED
|
||||
* should be true if the module is initialized, false if not.
|
||||
*/
|
||||
#ifdef DISABLE_PARAM_CHECK
|
||||
#define VERIFY_MODULE_INITIALIZED_VOID()
|
||||
#else
|
||||
#define VERIFY_MODULE_INITIALIZED_VOID() VERIFY_TRUE_VOID((MODULE_INITIALIZED))
|
||||
#endif /* DISABLE_PARAM_CHECK */
|
||||
|
||||
|
||||
/**@brief Macro for verifying that the module is initialized. It will cause the exterior function to
|
||||
* return if not.
|
||||
*
|
||||
* @param[in] param The variable to check if is NULL.
|
||||
*/
|
||||
#ifdef DISABLE_PARAM_CHECK
|
||||
#define VERIFY_PARAM_NOT_NULL()
|
||||
#else
|
||||
#define VERIFY_PARAM_NOT_NULL(param) VERIFY_FALSE(((param) == NULL), NRF_ERROR_NULL)
|
||||
#endif /* DISABLE_PARAM_CHECK */
|
||||
|
||||
|
||||
/**@brief Macro for verifying that the module is initialized. It will cause the exterior function to
|
||||
* return if not.
|
||||
*
|
||||
* @param[in] param The variable to check if is NULL.
|
||||
*/
|
||||
#ifdef DISABLE_PARAM_CHECK
|
||||
#define VERIFY_PARAM_NOT_NULL_VOID()
|
||||
#else
|
||||
#define VERIFY_PARAM_NOT_NULL_VOID(param) VERIFY_FALSE_VOID(((param) == NULL))
|
||||
#endif /* DISABLE_PARAM_CHECK */
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SDK_MACROS_H__
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_mapped_flags.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include "compiler_abstraction.h"
|
||||
|
||||
|
||||
// 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 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_w_idx(uint16_t * p_keys,
|
||||
sdk_mapped_flags_t flags,
|
||||
uint16_t key,
|
||||
uint8_t * p_index)
|
||||
{
|
||||
if (p_keys != NULL)
|
||||
{
|
||||
for (uint32_t i = 0; i < SDK_MAPPED_FLAGS_N_KEYS; i++)
|
||||
{
|
||||
if (p_keys[i] == key)
|
||||
{
|
||||
if (p_index != NULL)
|
||||
{
|
||||
*p_index = i;
|
||||
}
|
||||
return sdk_mapped_flags_get_by_index(flags, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (p_index != NULL)
|
||||
{
|
||||
*p_index = SDK_MAPPED_FLAGS_N_KEYS;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
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,199 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef SDK_MAPPED_FLAGS_H__
|
||||
#define SDK_MAPPED_FLAGS_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "app_util.h"
|
||||
#include "compiler_abstraction.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @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 32 /**< 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 uint32_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. */
|
||||
|
||||
|
||||
/**@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 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 from which to read.
|
||||
* @param[in] key The key for which to get the flag.
|
||||
* @param[out] p_index If not NULL, the index of the key.
|
||||
*
|
||||
* @return The state of the flag.
|
||||
*/
|
||||
bool sdk_mapped_flags_get_by_key_w_idx(uint16_t * p_keys,
|
||||
sdk_mapped_flags_t flags,
|
||||
uint16_t key,
|
||||
uint8_t * p_index);
|
||||
|
||||
|
||||
/**@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);
|
||||
}
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDK_MAPPED_FLAGS_H__ */
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Copyright (c) 2013 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @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__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#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 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SDK_OS_H__
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @file
|
||||
* @brief Definition file for resource usage by SoftDevice, ESB and Gazell.
|
||||
*/
|
||||
|
||||
#ifndef APP_RESOURCES_H__
|
||||
#define APP_RESOURCES_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#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)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // APP_RESOURCES_H__
|
||||
Reference in New Issue
Block a user