add files from nrf52832 bootloader project
This commit is contained in:
@ -0,0 +1,208 @@
|
||||
/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
|
||||
*
|
||||
* The information contained herein is property of Nordic Semiconductor ASA.
|
||||
* Terms and conditions of usage are described in detail in NORDIC
|
||||
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
|
||||
*
|
||||
* Licensees are granted free, non-transferable use of the information. NO
|
||||
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
|
||||
* the file.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include "nrf_drv_common.h"
|
||||
#include "nrf_assert.h"
|
||||
#include "app_util_platform.h"
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
#include "nrf_soc.h"
|
||||
#endif
|
||||
|
||||
|
||||
#if PERIPHERAL_RESOURCE_SHARING_ENABLED
|
||||
|
||||
typedef struct {
|
||||
nrf_drv_irq_handler_t handler;
|
||||
bool acquired;
|
||||
} shared_resource_t;
|
||||
|
||||
// SPIM0, SPIS0, SPI0, TWIM0, TWIS0, TWI0
|
||||
#if (SPI0_ENABLED || SPIS0_ENABLED || TWI0_ENABLED || TWIS0_ENABLED)
|
||||
#define SERIAL_BOX_0_IN_USE
|
||||
// [this checking may need a different form in unit tests, hence macro]
|
||||
#ifndef IS_SERIAL_BOX_0
|
||||
#define IS_SERIAL_BOX_0(p_per_base) (p_per_base == NRF_SPI0)
|
||||
#endif
|
||||
|
||||
static shared_resource_t m_serial_box_0 = { .acquired = false };
|
||||
void SPI0_TWI0_IRQHandler(void)
|
||||
{
|
||||
ASSERT(m_serial_box_0.handler);
|
||||
m_serial_box_0.handler();
|
||||
}
|
||||
#endif // (SPI0_ENABLED || SPIS0_ENABLED || TWI0_ENABLED || TWIS0_ENABLED)
|
||||
|
||||
// SPIM1, SPIS1, SPI1, TWIM1, TWIS1, TWI1
|
||||
#if (SPI1_ENABLED || SPIS1_ENABLED || TWI1_ENABLED || TWIS1_ENABLED)
|
||||
#define SERIAL_BOX_1_IN_USE
|
||||
// [this checking may need a different form in unit tests, hence macro]
|
||||
#ifndef IS_SERIAL_BOX_1
|
||||
#define IS_SERIAL_BOX_1(p_per_base) (p_per_base == NRF_SPI1)
|
||||
#endif
|
||||
|
||||
static shared_resource_t m_serial_box_1 = { .acquired = false };
|
||||
void SPI1_TWI1_IRQHandler(void)
|
||||
{
|
||||
ASSERT(m_serial_box_1.handler);
|
||||
m_serial_box_1.handler();
|
||||
}
|
||||
#endif // (SPI1_ENABLED || SPIS1_ENABLED || TWI1_ENABLED || TWIS1_ENABLED)
|
||||
|
||||
// SPIM2, SPIS2, SPI2
|
||||
#if (SPI2_ENABLED || SPIS2_ENABLED)
|
||||
#define SERIAL_BOX_2_IN_USE
|
||||
// [this checking may need a different form in unit tests, hence macro]
|
||||
#ifndef IS_SERIAL_BOX_2
|
||||
#define IS_SERIAL_BOX_2(p_per_base) (p_per_base == NRF_SPI2)
|
||||
#endif
|
||||
|
||||
static shared_resource_t m_serial_box_2 = { .acquired = false };
|
||||
void SPIM2_SPIS2_SPI2_IRQHandler(void)
|
||||
{
|
||||
ASSERT(m_serial_box_2.handler);
|
||||
m_serial_box_2.handler();
|
||||
}
|
||||
#endif // (SPI2_ENABLED || SPIS2_ENABLED)
|
||||
|
||||
// COMP, LPCOMP
|
||||
#if (COMP_ENABLED || LPCOMP_ENABLED)
|
||||
#define COMP_LPCOMP_IN_USE
|
||||
|
||||
#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();
|
||||
}
|
||||
#endif // (COMP_ENABLED || LPCOMP_ENABLED)
|
||||
|
||||
#if defined(SERIAL_BOX_0_IN_USE) || \
|
||||
defined(SERIAL_BOX_1_IN_USE) || \
|
||||
defined(SERIAL_BOX_2_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)
|
||||
{
|
||||
bool busy = false;
|
||||
|
||||
CRITICAL_REGION_ENTER();
|
||||
if (p_resource->acquired)
|
||||
{
|
||||
busy = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
p_resource->acquired = true;
|
||||
}
|
||||
CRITICAL_REGION_EXIT();
|
||||
|
||||
if (busy)
|
||||
{
|
||||
return NRF_ERROR_BUSY;
|
||||
}
|
||||
|
||||
p_resource->handler = handler;
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
ret_code_t nrf_drv_common_per_res_acquire(void const * p_per_base,
|
||||
nrf_drv_irq_handler_t handler)
|
||||
{
|
||||
#ifdef SERIAL_BOX_0_IN_USE
|
||||
if (IS_SERIAL_BOX_0(p_per_base))
|
||||
{
|
||||
return acquire_shared_resource(&m_serial_box_0, handler);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SERIAL_BOX_1_IN_USE
|
||||
if (IS_SERIAL_BOX_1(p_per_base))
|
||||
{
|
||||
return acquire_shared_resource(&m_serial_box_1, handler);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SERIAL_BOX_2_IN_USE
|
||||
if (IS_SERIAL_BOX_2(p_per_base))
|
||||
{
|
||||
return acquire_shared_resource(&m_serial_box_2, handler);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef COMP_LPCOMP_IN_USE
|
||||
if (IS_COMP_LPCOMP(p_per_base))
|
||||
{
|
||||
return acquire_shared_resource(&m_comp_lpcomp, handler);
|
||||
}
|
||||
#endif
|
||||
|
||||
return NRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
void nrf_drv_common_per_res_release(void const * p_per_base)
|
||||
{
|
||||
#ifdef SERIAL_BOX_0_IN_USE
|
||||
if (IS_SERIAL_BOX_0(p_per_base))
|
||||
{
|
||||
m_serial_box_0.acquired = false;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
||||
#ifdef SERIAL_BOX_1_IN_USE
|
||||
if (IS_SERIAL_BOX_1(p_per_base))
|
||||
{
|
||||
m_serial_box_1.acquired = false;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
||||
#ifdef SERIAL_BOX_2_IN_USE
|
||||
if (IS_SERIAL_BOX_2(p_per_base))
|
||||
{
|
||||
m_serial_box_2.acquired = false;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
||||
#ifdef COMP_LPCOMP_IN_USE
|
||||
if (IS_COMP_LPCOMP(p_per_base))
|
||||
{
|
||||
m_comp_lpcomp.acquired = false;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
||||
{}
|
||||
}
|
||||
|
||||
#endif // PERIPHERAL_RESOURCE_SHARING_ENABLED
|
||||
|
||||
|
||||
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
|
||||
|
||||
NVIC_SetPriority(IRQn, priority);
|
||||
NVIC_ClearPendingIRQ(IRQn);
|
||||
NVIC_EnableIRQ(IRQn);
|
||||
}
|
@ -0,0 +1,194 @@
|
||||
/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
|
||||
*
|
||||
* The information contained herein is property of Nordic Semiconductor ASA.
|
||||
* Terms and conditions of usage are described in detail in NORDIC
|
||||
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
|
||||
*
|
||||
* Licensees are granted free, non-transferable use of the information. NO
|
||||
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
|
||||
* the file.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NRF_DRV_COMMON_H__
|
||||
#define NRF_DRV_COMMON_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "nrf.h"
|
||||
#include "sdk_errors.h"
|
||||
#include "nrf_drv_config.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief Offset of event registers in every peripheral instance
|
||||
*
|
||||
* This is the offset where event registers start in the every peripheral.
|
||||
*/
|
||||
#define NRF_DRV_COMMON_EVREGS_OFFSET 0x100U
|
||||
|
||||
/**
|
||||
* @brief Driver state.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_DRV_STATE_UNINITIALIZED, /**< Uninitialized. */
|
||||
NRF_DRV_STATE_INITIALIZED, /**< Initialized but powered off. */
|
||||
NRF_DRV_STATE_POWERED_ON
|
||||
} nrf_drv_state_t;
|
||||
|
||||
/**
|
||||
* @brief Driver power state selection.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_DRV_PWR_CTRL_ON, /**< Power on request. */
|
||||
NRF_DRV_PWR_CTRL_OFF /**< Power off request. */
|
||||
} nrf_drv_pwr_ctrl_t;
|
||||
|
||||
/**
|
||||
* @brief IRQ handler type.
|
||||
*/
|
||||
typedef void (*nrf_drv_irq_handler_t)(void);
|
||||
|
||||
|
||||
#if PERIPHERAL_RESOURCE_SHARING_ENABLED
|
||||
|
||||
/**
|
||||
* @brief Function for acquiring shared peripheral resources associated with
|
||||
* the specified peripheral.
|
||||
*
|
||||
* Certain resources and registers are shared among peripherals that have
|
||||
* the same ID (for example: SPI0, SPIM0, SPIS0, TWI0, TWIM0, and TWIS0).
|
||||
* Only one of them can be utilized at a given time. This function reserves
|
||||
* proper resources to be used by the specified peripheral.
|
||||
* If PERIPHERAL_RESOURCE_SHARING_ENABLED is set to a non-zero value, IRQ
|
||||
* handlers for peripherals that are sharing resources with others are
|
||||
* implemented by the nrf_drv_common module instead of individual drivers.
|
||||
* The drivers must then specify their interrupt handling routines and
|
||||
* register them by using this function.
|
||||
*
|
||||
* @param[in] p_per_base Requested peripheral base pointer.
|
||||
* @param[in] handler Interrupt handler to register. May be NULL
|
||||
* if interrupts are not used for the peripheral.
|
||||
*
|
||||
* @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
|
||||
* with other peripherals.
|
||||
*/
|
||||
ret_code_t nrf_drv_common_per_res_acquire(void const * p_per_base,
|
||||
nrf_drv_irq_handler_t handler);
|
||||
|
||||
/**
|
||||
* @brief Function for releasing shared resources reserved previously by
|
||||
* @ref nrf_drv_common_per_res_acquire() for the specified peripheral.
|
||||
*
|
||||
* @param[in] p_per_base Requested peripheral base pointer.
|
||||
*/
|
||||
void nrf_drv_common_per_res_release(void const * p_per_base);
|
||||
|
||||
#endif // PERIPHERAL_RESOURCE_SHARING_ENABLED
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function sets priority and enables NVIC interrupt
|
||||
*
|
||||
* @note Function checks if correct priority is used when softdevice is present
|
||||
*
|
||||
* @param[in] IRQn Interrupt id
|
||||
* @param[in] priority Interrupt priority
|
||||
*/
|
||||
void nrf_drv_common_irq_enable(IRQn_Type IRQn, uint8_t priority);
|
||||
|
||||
/**
|
||||
* @brief Function disables NVIC interrupt
|
||||
*
|
||||
* @param[in] IRQn Interrupt id
|
||||
*/
|
||||
__STATIC_INLINE void nrf_drv_common_irq_disable(IRQn_Type IRQn);
|
||||
|
||||
/**
|
||||
* @brief Convert bit position to event code
|
||||
*
|
||||
* Function for converting the bit position in INTEN register to event code
|
||||
* that is equivalent to the offset of the event register from the beginning
|
||||
* 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...
|
||||
*
|
||||
* @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
|
||||
* @ref nrf_rng_event_get
|
||||
*
|
||||
* @sa nrf_drv_event_to_bitpos
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_drv_bitpos_to_event(uint32_t bit);
|
||||
|
||||
/**
|
||||
* @brief Convert event code to bit position
|
||||
*
|
||||
* 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
|
||||
* @return Bit position in INTEN register that corresponds to the given code.
|
||||
*
|
||||
* @sa nrf_drv_bitpos_to_event
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_drv_event_to_bitpos(uint32_t event);
|
||||
|
||||
/**
|
||||
* @brief Get interrupt number connected with given instance
|
||||
*
|
||||
* Function returns interrupt number for a given instance of any peripheral.
|
||||
* @param[in] pinst Pointer to peripheral registry
|
||||
* @return Interrupt number
|
||||
*/
|
||||
__STATIC_INLINE IRQn_Type nrf_drv_get_IRQn(void const * const pinst);
|
||||
|
||||
/**
|
||||
* @brief Check if given object is in RAM
|
||||
*
|
||||
* Function for analyzing if given location is placed in RAM.
|
||||
* This function is used to determine if we have address that can be supported by EasyDMA.
|
||||
* @param[in] ptr Pointer to the object
|
||||
* @retval true Object is located in RAM
|
||||
* @retval false Object is not located in RAM
|
||||
*/
|
||||
__STATIC_INLINE bool nrf_drv_is_in_RAM(void const * const ptr);
|
||||
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
__STATIC_INLINE void nrf_drv_common_irq_disable(IRQn_Type IRQn)
|
||||
{
|
||||
NVIC_DisableIRQ(IRQn);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_drv_bitpos_to_event(uint32_t bit)
|
||||
{
|
||||
return NRF_DRV_COMMON_EVREGS_OFFSET + bit * sizeof(uint32_t);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_drv_event_to_bitpos(uint32_t event)
|
||||
{
|
||||
return (event - NRF_DRV_COMMON_EVREGS_OFFSET) / sizeof(uint32_t);
|
||||
}
|
||||
|
||||
__STATIC_INLINE IRQn_Type nrf_drv_get_IRQn(void const * const pinst)
|
||||
{
|
||||
uint8_t ret = (uint8_t)((uint32_t)pinst>>12U);
|
||||
return (IRQn_Type) ret;
|
||||
}
|
||||
|
||||
__STATIC_INLINE bool nrf_drv_is_in_RAM(void const * const ptr)
|
||||
{
|
||||
return ((((uintptr_t)ptr) & 0xE0000000u) == 0x20000000u);
|
||||
}
|
||||
|
||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
#endif // NRF_DRV_COMMON_H__
|
Reference in New Issue
Block a user