able to build
This commit is contained in:
		@@ -1,26 +1,70 @@
 | 
			
		||||
/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
/**
 | 
			
		||||
 * 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 <stddef.h>
 | 
			
		||||
#include "nrf_drv_common.h"
 | 
			
		||||
#include "nrf_assert.h"
 | 
			
		||||
#include "app_util_platform.h"
 | 
			
		||||
#include "nrf_peripherals.h"
 | 
			
		||||
 | 
			
		||||
#if NRF_DRV_COMMON_POWER_CLOCK_ISR
 | 
			
		||||
#include "nrf_drv_power.h"
 | 
			
		||||
#include "nrf_drv_clock.h"
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef SOFTDEVICE_PRESENT
 | 
			
		||||
#include "nrf_soc.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if NRF_MODULE_ENABLED(PERIPHERAL_RESOURCE_SHARING)
 | 
			
		||||
 | 
			
		||||
#define NRF_LOG_MODULE_NAME common
 | 
			
		||||
 | 
			
		||||
#if COMMON_CONFIG_LOG_ENABLED
 | 
			
		||||
#define NRF_LOG_LEVEL       COMMON_CONFIG_LOG_LEVEL
 | 
			
		||||
#define NRF_LOG_INFO_COLOR  COMMON_CONFIG_INFO_COLOR
 | 
			
		||||
#define NRF_LOG_DEBUG_COLOR COMMON_CONFIG_DEBUG_COLOR
 | 
			
		||||
#else //COMMON_CONFIG_LOG_ENABLED
 | 
			
		||||
#define NRF_LOG_LEVEL       0
 | 
			
		||||
#endif //COMMON_CONFIG_LOG_ENABLED
 | 
			
		||||
#include "nrf_log.h"
 | 
			
		||||
NRF_LOG_MODULE_REGISTER();
 | 
			
		||||
 | 
			
		||||
#if PERIPHERAL_RESOURCE_SHARING_ENABLED
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
    nrf_drv_irq_handler_t handler;
 | 
			
		||||
@@ -28,7 +72,7 @@ typedef struct {
 | 
			
		||||
} shared_resource_t;
 | 
			
		||||
 | 
			
		||||
// SPIM0, SPIS0, SPI0, TWIM0, TWIS0, TWI0
 | 
			
		||||
#if (SPI0_ENABLED || SPIS0_ENABLED || TWI0_ENABLED || TWIS0_ENABLED)
 | 
			
		||||
#if (NRF_MODULE_ENABLED(SPI0) || NRF_MODULE_ENABLED(SPIS0) || NRF_MODULE_ENABLED(TWI0) || NRF_MODULE_ENABLED(TWIS0))
 | 
			
		||||
    #define SERIAL_BOX_0_IN_USE
 | 
			
		||||
    // [this checking may need a different form in unit tests, hence macro]
 | 
			
		||||
    #ifndef IS_SERIAL_BOX_0
 | 
			
		||||
@@ -41,10 +85,10 @@ typedef struct {
 | 
			
		||||
        ASSERT(m_serial_box_0.handler);
 | 
			
		||||
        m_serial_box_0.handler();
 | 
			
		||||
    }
 | 
			
		||||
#endif // (SPI0_ENABLED || SPIS0_ENABLED || TWI0_ENABLED || TWIS0_ENABLED)
 | 
			
		||||
#endif // (NRF_MODULE_ENABLED(SPI0) || NRF_MODULE_ENABLED(SPIS0) || NRF_MODULE_ENABLED(TWI0) || NRF_MODULE_ENABLED(TWIS0))
 | 
			
		||||
 | 
			
		||||
// SPIM1, SPIS1, SPI1, TWIM1, TWIS1, TWI1
 | 
			
		||||
#if (SPI1_ENABLED || SPIS1_ENABLED || TWI1_ENABLED || TWIS1_ENABLED)
 | 
			
		||||
#if (NRF_MODULE_ENABLED(SPI1) || NRF_MODULE_ENABLED(SPIS1) || NRF_MODULE_ENABLED(TWI1) || NRF_MODULE_ENABLED(TWIS1))
 | 
			
		||||
    #define SERIAL_BOX_1_IN_USE
 | 
			
		||||
    // [this checking may need a different form in unit tests, hence macro]
 | 
			
		||||
    #ifndef IS_SERIAL_BOX_1
 | 
			
		||||
@@ -52,15 +96,19 @@ typedef struct {
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    static shared_resource_t m_serial_box_1 = { .acquired = false };
 | 
			
		||||
#ifdef TWIM_PRESENT
 | 
			
		||||
    void SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler(void)
 | 
			
		||||
#else
 | 
			
		||||
    void SPI1_TWI1_IRQHandler(void)
 | 
			
		||||
#endif
 | 
			
		||||
    {
 | 
			
		||||
        ASSERT(m_serial_box_1.handler);
 | 
			
		||||
        m_serial_box_1.handler();
 | 
			
		||||
    }
 | 
			
		||||
#endif // (SPI1_ENABLED || SPIS1_ENABLED || TWI1_ENABLED || TWIS1_ENABLED)
 | 
			
		||||
#endif // (NRF_MODULE_ENABLED(SPI1) || NRF_MODULE_ENABLED(SPIS1) || NRF_MODULE_ENABLED(TWI1) || NRF_MODULE_ENABLED(TWIS1))
 | 
			
		||||
 | 
			
		||||
// SPIM2, SPIS2, SPI2
 | 
			
		||||
#if (SPI2_ENABLED || SPIS2_ENABLED)
 | 
			
		||||
#if (NRF_MODULE_ENABLED(SPI2) || NRF_MODULE_ENABLED(SPIS2))
 | 
			
		||||
    #define SERIAL_BOX_2_IN_USE
 | 
			
		||||
    // [this checking may need a different form in unit tests, hence macro]
 | 
			
		||||
    #ifndef IS_SERIAL_BOX_2
 | 
			
		||||
@@ -73,31 +121,33 @@ typedef struct {
 | 
			
		||||
        ASSERT(m_serial_box_2.handler);
 | 
			
		||||
        m_serial_box_2.handler();
 | 
			
		||||
    }
 | 
			
		||||
#endif // (SPI2_ENABLED || SPIS2_ENABLED)
 | 
			
		||||
#endif // (NRF_MODULE_ENABLED(SPI2) || NRF_MODULE_ENABLED(SPIS2))
 | 
			
		||||
 | 
			
		||||
// COMP, LPCOMP
 | 
			
		||||
#if (COMP_ENABLED || LPCOMP_ENABLED)
 | 
			
		||||
	#define COMP_LPCOMP_IN_USE
 | 
			
		||||
#if (NRF_MODULE_ENABLED(COMP) || NRF_MODULE_ENABLED(LPCOMP))
 | 
			
		||||
    #define COMP_LPCOMP_IN_USE
 | 
			
		||||
 | 
			
		||||
	#ifndef IS_COMP_LPCOMP
 | 
			
		||||
		#define IS_COMP_LPCOMP(p_per_base)  ((p_per_base) == NRF_LPCOMP)
 | 
			
		||||
	#endif
 | 
			
		||||
    #ifndef IS_COMP_LPCOMP
 | 
			
		||||
        #define IS_COMP_LPCOMP(p_per_base)  ((p_per_base) == NRF_LPCOMP)
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    static shared_resource_t m_comp_lpcomp = { .acquired = false };
 | 
			
		||||
    void LPCOMP_IRQHandler(void)
 | 
			
		||||
    {
 | 
			
		||||
    	ASSERT(m_comp_lpcomp.handler);
 | 
			
		||||
    	m_comp_lpcomp.handler();
 | 
			
		||||
        ASSERT(m_comp_lpcomp.handler);
 | 
			
		||||
        m_comp_lpcomp.handler();
 | 
			
		||||
    }
 | 
			
		||||
#endif	// (COMP_ENABLED || LPCOMP_ENABLED)
 | 
			
		||||
#endif    // (NRF_MODULE_ENABLED(COMP) || NRF_MODULE_ENABLED(LPCOMP))
 | 
			
		||||
 | 
			
		||||
#if defined(SERIAL_BOX_0_IN_USE) || \
 | 
			
		||||
    defined(SERIAL_BOX_1_IN_USE) || \
 | 
			
		||||
    defined(SERIAL_BOX_2_IN_USE) || \
 | 
			
		||||
	defined(COMP_LPCOMP_IN_USE)
 | 
			
		||||
    defined(COMP_LPCOMP_IN_USE)
 | 
			
		||||
static ret_code_t acquire_shared_resource(shared_resource_t * p_resource,
 | 
			
		||||
                                          nrf_drv_irq_handler_t handler)
 | 
			
		||||
{
 | 
			
		||||
    ret_code_t err_code;
 | 
			
		||||
 | 
			
		||||
    bool busy = false;
 | 
			
		||||
 | 
			
		||||
    CRITICAL_REGION_ENTER();
 | 
			
		||||
@@ -113,11 +163,15 @@ static ret_code_t acquire_shared_resource(shared_resource_t * p_resource,
 | 
			
		||||
 | 
			
		||||
    if (busy)
 | 
			
		||||
    {
 | 
			
		||||
        return NRF_ERROR_BUSY;
 | 
			
		||||
        err_code = NRF_ERROR_BUSY;
 | 
			
		||||
        NRF_LOG_WARNING("Function: %s, error code: %s.", (uint32_t)__func__, (uint32_t)NRF_LOG_ERROR_STRING_GET(err_code));
 | 
			
		||||
        return err_code;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    p_resource->handler = handler;
 | 
			
		||||
    return NRF_SUCCESS;
 | 
			
		||||
    err_code = NRF_SUCCESS;
 | 
			
		||||
    NRF_LOG_INFO("Function: %s, error code: %s.", (uint32_t)__func__, (uint32_t)NRF_LOG_ERROR_STRING_GET(err_code));
 | 
			
		||||
    return err_code;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
@@ -148,11 +202,14 @@ ret_code_t nrf_drv_common_per_res_acquire(void const * p_per_base,
 | 
			
		||||
#ifdef COMP_LPCOMP_IN_USE
 | 
			
		||||
    if (IS_COMP_LPCOMP(p_per_base))
 | 
			
		||||
    {
 | 
			
		||||
    	return acquire_shared_resource(&m_comp_lpcomp, handler);
 | 
			
		||||
        return acquire_shared_resource(&m_comp_lpcomp, handler);
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
    ret_code_t err_code;
 | 
			
		||||
 | 
			
		||||
    return NRF_ERROR_INVALID_PARAM;
 | 
			
		||||
    err_code = NRF_ERROR_INVALID_PARAM;
 | 
			
		||||
    NRF_LOG_WARNING("Function: %s, error code: %s.", (uint32_t)__func__, (uint32_t)NRF_LOG_ERROR_STRING_GET(err_code));
 | 
			
		||||
    return err_code;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void nrf_drv_common_per_res_release(void const * p_per_base)
 | 
			
		||||
@@ -182,25 +239,57 @@ void nrf_drv_common_per_res_release(void const * p_per_base)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef COMP_LPCOMP_IN_USE
 | 
			
		||||
	if (IS_COMP_LPCOMP(p_per_base))
 | 
			
		||||
    if (IS_COMP_LPCOMP(p_per_base))
 | 
			
		||||
    {
 | 
			
		||||
        m_comp_lpcomp.acquired = false;
 | 
			
		||||
    }
 | 
			
		||||
	else
 | 
			
		||||
    else
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    {}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // PERIPHERAL_RESOURCE_SHARING_ENABLED
 | 
			
		||||
#endif // NRF_MODULE_ENABLED(PERIPHERAL_RESOURCE_SHARING)
 | 
			
		||||
 | 
			
		||||
#if NRF_MODULE_ENABLED(POWER)
 | 
			
		||||
void nrf_drv_common_power_irq_disable(void)
 | 
			
		||||
{
 | 
			
		||||
#if NRF_DRV_COMMON_POWER_CLOCK_ISR
 | 
			
		||||
    if (!nrf_drv_clock_init_check())
 | 
			
		||||
#endif
 | 
			
		||||
    {
 | 
			
		||||
        nrf_drv_common_irq_disable(POWER_CLOCK_IRQn);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if NRF_MODULE_ENABLED(CLOCK)
 | 
			
		||||
void nrf_drv_common_clock_irq_disable(void)
 | 
			
		||||
{
 | 
			
		||||
#if NRF_DRV_COMMON_POWER_CLOCK_ISR
 | 
			
		||||
    if (!nrf_drv_power_init_check())
 | 
			
		||||
#endif
 | 
			
		||||
    {
 | 
			
		||||
        nrf_drv_common_irq_disable(POWER_CLOCK_IRQn);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if NRF_DRV_COMMON_POWER_CLOCK_ISR
 | 
			
		||||
void POWER_CLOCK_IRQHandler(void)
 | 
			
		||||
{
 | 
			
		||||
    extern void nrf_drv_clock_onIRQ(void);
 | 
			
		||||
    extern void nrf_drv_power_onIRQ(void);
 | 
			
		||||
 | 
			
		||||
    nrf_drv_clock_onIRQ();
 | 
			
		||||
    nrf_drv_power_onIRQ();
 | 
			
		||||
}
 | 
			
		||||
#endif // NRF_DRV_COMMON_POWER_CLOCK_ISR
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void nrf_drv_common_irq_enable(IRQn_Type IRQn, uint8_t priority)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
#ifdef SOFTDEVICE_PRESENT
 | 
			
		||||
    ASSERT((priority == APP_IRQ_PRIORITY_LOW) || (priority == APP_IRQ_PRIORITY_HIGH));
 | 
			
		||||
#endif
 | 
			
		||||
    INTERRUPT_PRIORITY_ASSERT(priority);
 | 
			
		||||
 | 
			
		||||
    NVIC_SetPriority(IRQn, priority);
 | 
			
		||||
    NVIC_ClearPendingIRQ(IRQn);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,15 +1,42 @@
 | 
			
		||||
/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * The information contained herein is property of Nordic Semiconductor ASA.
 | 
			
		||||
 * Terms and conditions of usage are described in detail in NORDIC
 | 
			
		||||
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensees are granted free, non-transferable use of the information. NO
 | 
			
		||||
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 | 
			
		||||
 * the file.
 | 
			
		||||
 *
 | 
			
		||||
/**
 | 
			
		||||
 * 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 NRF_DRV_COMMON_H__
 | 
			
		||||
#define NRF_DRV_COMMON_H__
 | 
			
		||||
 | 
			
		||||
@@ -17,24 +44,66 @@
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include "nrf.h"
 | 
			
		||||
#include "sdk_errors.h"
 | 
			
		||||
#include "nrf_drv_config.h"
 | 
			
		||||
#include "sdk_common.h"
 | 
			
		||||
#include "nrf_assert.h"
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef NRF51
 | 
			
		||||
#ifdef SOFTDEVICE_PRESENT
 | 
			
		||||
#define INTERRUPT_PRIORITY_IS_VALID(pri) (((pri) == 1) || ((pri) == 3))
 | 
			
		||||
#else
 | 
			
		||||
#define INTERRUPT_PRIORITY_IS_VALID(pri) ((pri) < 4)
 | 
			
		||||
#endif //SOFTDEVICE_PRESENT
 | 
			
		||||
#else
 | 
			
		||||
#ifdef SOFTDEVICE_PRESENT
 | 
			
		||||
#define INTERRUPT_PRIORITY_IS_VALID(pri) ((((pri) > 1) && ((pri) < 4)) || \
 | 
			
		||||
                                          (((pri) > 4) && ((pri) < 8)))
 | 
			
		||||
#else
 | 
			
		||||
#define INTERRUPT_PRIORITY_IS_VALID(pri) ((pri) < 8)
 | 
			
		||||
#endif //SOFTDEVICE_PRESENT
 | 
			
		||||
#endif //NRF52
 | 
			
		||||
 | 
			
		||||
#define INTERRUPT_PRIORITY_VALIDATION(pri) STATIC_ASSERT(INTERRUPT_PRIORITY_IS_VALID((pri)))
 | 
			
		||||
#define INTERRUPT_PRIORITY_ASSERT(pri)     ASSERT(INTERRUPT_PRIORITY_IS_VALID((pri)))
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Offset of event registers in every peripheral instance
 | 
			
		||||
 * @defgroup nrf_drv_common Peripheral drivers common module
 | 
			
		||||
 * @{
 | 
			
		||||
 * @ingroup nrf_drivers
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Offset of event registers in every peripheral instance.
 | 
			
		||||
 *
 | 
			
		||||
 * This is the offset where event registers start in the every peripheral.
 | 
			
		||||
 * This is the offset where event registers start in  every peripheral.
 | 
			
		||||
 */
 | 
			
		||||
#define NRF_DRV_COMMON_EVREGS_OFFSET 0x100U
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief The flag that is set when POWER_CLOCK ISR is implemented in common module
 | 
			
		||||
 *
 | 
			
		||||
 * This flag means that the function POWER_CLOCK_IRQHandler is implemented in
 | 
			
		||||
 * nrf_drv_common.c file. In the @c clock and @c power modules functions
 | 
			
		||||
 * nrf_drv_clock_onIRQ nrf_drv_power_onIRQ should be implemented
 | 
			
		||||
 * and they would be called from common implementation.
 | 
			
		||||
 *
 | 
			
		||||
 * None of the checking is done here.
 | 
			
		||||
 * The implementation functions in @c clock and @c power are required to handle
 | 
			
		||||
 * correctly the case when they are called without any event bit set.
 | 
			
		||||
 */
 | 
			
		||||
#define NRF_DRV_COMMON_POWER_CLOCK_ISR (NRF_MODULE_ENABLED(CLOCK) && NRF_MODULE_ENABLED(POWER))
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Driver state.
 | 
			
		||||
 */
 | 
			
		||||
typedef enum 
 | 
			
		||||
{ 
 | 
			
		||||
	NRF_DRV_STATE_UNINITIALIZED, /**< Uninitialized. */
 | 
			
		||||
	NRF_DRV_STATE_INITIALIZED, /**< Initialized but powered off. */
 | 
			
		||||
	NRF_DRV_STATE_POWERED_ON
 | 
			
		||||
typedef enum
 | 
			
		||||
{
 | 
			
		||||
    NRF_DRV_STATE_UNINITIALIZED, /**< Uninitialized. */
 | 
			
		||||
    NRF_DRV_STATE_INITIALIZED, /**< Initialized but powered off. */
 | 
			
		||||
    NRF_DRV_STATE_POWERED_ON
 | 
			
		||||
} nrf_drv_state_t;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -52,7 +121,7 @@ typedef enum
 | 
			
		||||
typedef void (*nrf_drv_irq_handler_t)(void);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#if PERIPHERAL_RESOURCE_SHARING_ENABLED
 | 
			
		||||
#if NRF_MODULE_ENABLED(PERIPHERAL_RESOURCE_SHARING)
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for acquiring shared peripheral resources associated with
 | 
			
		||||
@@ -74,8 +143,8 @@ typedef void (*nrf_drv_irq_handler_t)(void);
 | 
			
		||||
 *
 | 
			
		||||
 * @retval NRF_SUCCESS             If resources were acquired successfully.
 | 
			
		||||
 * @retval NRF_ERROR_BUSY          If resources were already acquired.
 | 
			
		||||
 * @retval NRF_ERROR_INVALID_PARAM If the specified peripheral is not enabled 
 | 
			
		||||
 *                                 or the peripheral does not share resources 
 | 
			
		||||
 * @retval NRF_ERROR_INVALID_PARAM If the specified peripheral is not enabled
 | 
			
		||||
 *                                 or the peripheral does not share resources
 | 
			
		||||
 *                                 with other peripherals.
 | 
			
		||||
 */
 | 
			
		||||
ret_code_t nrf_drv_common_per_res_acquire(void const * p_per_base,
 | 
			
		||||
@@ -89,7 +158,7 @@ ret_code_t nrf_drv_common_per_res_acquire(void const * p_per_base,
 | 
			
		||||
 */
 | 
			
		||||
void nrf_drv_common_per_res_release(void const * p_per_base);
 | 
			
		||||
 | 
			
		||||
#endif // PERIPHERAL_RESOURCE_SHARING_ENABLED
 | 
			
		||||
#endif // NRF_MODULE_ENABLED(PERIPHERAL_RESOURCE_SHARING)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -102,6 +171,44 @@ void nrf_drv_common_per_res_release(void const * p_per_base);
 | 
			
		||||
 */
 | 
			
		||||
void nrf_drv_common_irq_enable(IRQn_Type IRQn, uint8_t priority);
 | 
			
		||||
 | 
			
		||||
#if NRF_MODULE_ENABLED(POWER)
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Disable power IRQ
 | 
			
		||||
 *
 | 
			
		||||
 * Power and clock peripheral uses the same IRQ.
 | 
			
		||||
 * This function disables POWER_CLOCK IRQ only if CLOCK driver
 | 
			
		||||
 * is uninitialized.
 | 
			
		||||
 *
 | 
			
		||||
 * @sa nrf_drv_common_power_clock_irq_init
 | 
			
		||||
 */
 | 
			
		||||
void nrf_drv_common_power_irq_disable(void);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if NRF_MODULE_ENABLED(CLOCK)
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Disable clock IRQ
 | 
			
		||||
 *
 | 
			
		||||
 * Power and clock peripheral uses the same IRQ.
 | 
			
		||||
 * This function disables POWER_CLOCK IRQ only if POWER driver
 | 
			
		||||
 * is uninitialized.
 | 
			
		||||
 *
 | 
			
		||||
 * @sa nrf_drv_common_power_clock_irq_init
 | 
			
		||||
 */
 | 
			
		||||
void nrf_drv_common_clock_irq_disable(void);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Check if interrupt is enabled
 | 
			
		||||
 *
 | 
			
		||||
 * Function that checks if selected interrupt is enabled.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] IRQn     Interrupt id
 | 
			
		||||
 *
 | 
			
		||||
 * @retval true  Selected IRQ is enabled.
 | 
			
		||||
 * @retval false Selected IRQ is disabled.
 | 
			
		||||
 */
 | 
			
		||||
__STATIC_INLINE bool nrf_drv_common_irq_enable_check(IRQn_Type IRQn);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function disables NVIC interrupt
 | 
			
		||||
 *
 | 
			
		||||
@@ -117,7 +224,7 @@ __STATIC_INLINE void nrf_drv_common_irq_disable(IRQn_Type IRQn);
 | 
			
		||||
 * of peripheral instance.
 | 
			
		||||
 *
 | 
			
		||||
 * For example the result of this function can be casted directly to
 | 
			
		||||
 * the types like @ref nrf_twis_event_t or @ref nrf_rng_events_t...
 | 
			
		||||
 * the types like @ref nrf_twis_event_t or @ref nrf_rng_event_t
 | 
			
		||||
 *
 | 
			
		||||
 * @param bit Bit position in INTEN register
 | 
			
		||||
 * @return Event code to be casted to the right enum type or to be used in functions like
 | 
			
		||||
@@ -133,7 +240,7 @@ __STATIC_INLINE uint32_t nrf_drv_bitpos_to_event(uint32_t bit);
 | 
			
		||||
 * This function can be used to get bit position in INTEN register from event code.
 | 
			
		||||
 *
 | 
			
		||||
 * @param event Event code that may be casted from enum values from types like
 | 
			
		||||
 * @ref nrf_twis_event_t or @ref nrf_rng_events_t
 | 
			
		||||
 * @ref nrf_twis_event_t or @ref nrf_rng_event_t
 | 
			
		||||
 * @return Bit position in INTEN register that corresponds to the given code.
 | 
			
		||||
 *
 | 
			
		||||
 * @sa nrf_drv_bitpos_to_event
 | 
			
		||||
@@ -149,6 +256,29 @@ __STATIC_INLINE uint32_t nrf_drv_event_to_bitpos(uint32_t event);
 | 
			
		||||
 */
 | 
			
		||||
__STATIC_INLINE IRQn_Type nrf_drv_get_IRQn(void const * const pinst);
 | 
			
		||||
 | 
			
		||||
#if NRF_MODULE_ENABLED(CLOCK) || NRF_MODULE_ENABLED(POWER)
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Enable and setup power clock IRQ
 | 
			
		||||
 *
 | 
			
		||||
 * This function would be called from @ref nrf_drv_clock and @ref nrf_drv_power
 | 
			
		||||
 * to enable related interrupt.
 | 
			
		||||
 * This function avoids multiple interrupt configuration.
 | 
			
		||||
 *
 | 
			
		||||
 * @note
 | 
			
		||||
 * This function is aviable only if @ref nrf_drv_clock or @ref nrf_drv_power
 | 
			
		||||
 * module is enabled.
 | 
			
		||||
 *
 | 
			
		||||
 * @note
 | 
			
		||||
 * If both @ref nrf_drv_clock and @ref nrf_drv_power modules are enabled,
 | 
			
		||||
 * during the compilation the check is made that
 | 
			
		||||
 * @ref CLOCK_CONFIG_IRQ_PRIORITY equals @ref POWER_CONFIG_IRQ_PRIORITY.
 | 
			
		||||
 *
 | 
			
		||||
 * @sa nrf_drv_common_power_irq_disable
 | 
			
		||||
 * @sa nrf_drv_common_clock_irq_disable
 | 
			
		||||
 */
 | 
			
		||||
__STATIC_INLINE void nrf_drv_common_power_clock_irq_init(void);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Check if given object is in RAM
 | 
			
		||||
 *
 | 
			
		||||
@@ -160,9 +290,14 @@ __STATIC_INLINE IRQn_Type nrf_drv_get_IRQn(void const * const pinst);
 | 
			
		||||
 */
 | 
			
		||||
__STATIC_INLINE bool nrf_drv_is_in_RAM(void const * const ptr);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
 | 
			
		||||
 | 
			
		||||
__STATIC_INLINE bool nrf_drv_common_irq_enable_check(IRQn_Type IRQn)
 | 
			
		||||
{
 | 
			
		||||
    return 0 != (NVIC->ISER[(((uint32_t)(int32_t)IRQn) >> 5UL)] &
 | 
			
		||||
        (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
__STATIC_INLINE void nrf_drv_common_irq_disable(IRQn_Type IRQn)
 | 
			
		||||
{
 | 
			
		||||
    NVIC_DisableIRQ(IRQn);
 | 
			
		||||
@@ -184,6 +319,28 @@ __STATIC_INLINE IRQn_Type nrf_drv_get_IRQn(void const * const pinst)
 | 
			
		||||
    return (IRQn_Type) ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if NRF_MODULE_ENABLED(CLOCK) || NRF_MODULE_ENABLED(POWER)
 | 
			
		||||
__STATIC_INLINE void nrf_drv_common_power_clock_irq_init(void)
 | 
			
		||||
{
 | 
			
		||||
    if (!nrf_drv_common_irq_enable_check(POWER_CLOCK_IRQn))
 | 
			
		||||
    {
 | 
			
		||||
        nrf_drv_common_irq_enable(
 | 
			
		||||
            POWER_CLOCK_IRQn,
 | 
			
		||||
#if NRF_DRV_COMMON_POWER_CLOCK_ISR
 | 
			
		||||
    #if CLOCK_CONFIG_IRQ_PRIORITY != POWER_CONFIG_IRQ_PRIORITY
 | 
			
		||||
    #error CLOCK_CONFIG_IRQ_PRIORITY and POWER_CONFIG_IRQ_PRIORITY have to be the same.
 | 
			
		||||
    #endif
 | 
			
		||||
            CLOCK_CONFIG_IRQ_PRIORITY
 | 
			
		||||
#elif NRF_MODULE_ENABLED(CLOCK)
 | 
			
		||||
            CLOCK_CONFIG_IRQ_PRIORITY
 | 
			
		||||
#elif NRF_MODULE_ENABLED(POWER)
 | 
			
		||||
            POWER_CONFIG_IRQ_PRIORITY
 | 
			
		||||
#endif
 | 
			
		||||
            );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
__STATIC_INLINE bool nrf_drv_is_in_RAM(void const * const ptr)
 | 
			
		||||
{
 | 
			
		||||
    return ((((uintptr_t)ptr) & 0xE0000000u) == 0x20000000u);
 | 
			
		||||
@@ -191,4 +348,11 @@ __STATIC_INLINE bool nrf_drv_is_in_RAM(void const * const ptr)
 | 
			
		||||
 | 
			
		||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif // NRF_DRV_COMMON_H__
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user