You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/11/23 18:52:00 UTC
[37/70] [abbrv] [partial] incubator-mynewt-core git commit: Remove
non-Apache-compatible Nordic SDK files.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/spi_master/spi_5W_master.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/spi_master/spi_5W_master.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/spi_master/spi_5W_master.c
deleted file mode 100644
index 8811d55..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/spi_master/spi_5W_master.c
+++ /dev/null
@@ -1,602 +0,0 @@
-/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is property of Nordic Semiconductor ASA.
- * Terms and conditions of usage are described in detail in NORDIC
- * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
-
-/**@file
- *
- * @defgroup ser_phy_spi_5W_hw_driver_master spi_5W_master.c
- * @{
- * @ingroup ser_phy_spi_5W_hw_driver_master
- *
- * @brief SPI_5W_RAW hardware driver.
- */
-
-#include "app_error.h"
-#include "app_util_platform.h"
-#include "nrf_gpio.h"
-#include "nrf.h"
-#include "spi_5W_master.h"
-#include "ser_config_5W_app.h"
-#include "ser_phy_debug_app.h"
-#include "sdk_common.h"
-
-
-#define _static
-
-#define DOUBLE_BUFFERED /**< A flag for enabling double buffering. */
-
-#define SPI_PIN_DISCONNECTED 0xFFFFFFFF /**< A value used to the PIN deinitialization. */
-#define SPI_DEFAULT_TX_BYTE 0x00 /**< Default byte (used to clock transmission
- from slave to the master) */
-
-typedef struct
-{
- NRF_SPI_Type * p_nrf_spi; /**< A pointer to the NRF SPI master */
- IRQn_Type irq_type; /**< A type of NVIC IRQn */
-
- uint8_t * p_tx_buffer; /**< A pointer to TX buffer. */
- uint16_t tx_length; /**< A length of TX buffer. */
- uint16_t tx_index; /**< A index of the current element in the TX buffer. */
-
- uint8_t * p_rx_buffer; /**< A pointer to RX buffer. */
- uint16_t rx_length; /**< A length RX buffer. */
- uint16_t rx_index; /**< A index of the current element in the RX buffer. */
-
- uint16_t max_length; /**< Max length (Max of the TX and RX length). */
- uint16_t bytes_count;
- uint8_t pin_slave_select; /**< A pin for Slave Select. */
-
- spi_master_event_handler_t callback_event_handler; /**< A handler for event callback function. */
- spi_master_state_t state; /**< A state of an instance of SPI master. */
- bool start_flag;
- bool abort_flag;
-
-} spi_master_instance_t;
-
-#ifdef _SPI_5W_
-typedef enum
-{
- HOOK_STATE_DISABLED,
- HOOK_STATE_IDLE,
- HOOK_STATE_GUARDED,
- HOOK_STATE_ABORTED,
- HOOK_STATE_RESTARTED,
- HOOK_STATE_PASSING
-} spi_hook_state_t;
-
-
-_static spi_master_event_handler_t m_ser_phy_event_handler;
-_static spi_master_hw_instance_t m_spi_master_hw_instance;
-_static spi_hook_state_t m_hook_state = HOOK_STATE_DISABLED;
-#endif
-
-#ifdef SER_PHY_DEBUG_APP_ENABLE
-_static spi_master_raw_callback_t m_debug_callback;
-#endif
-
-_static spi_master_instance_t m_spi_master_instances[SPI_MASTER_HW_ENABLED_COUNT];
-
-static __INLINE spi_master_instance_t * spi_master_get_instance(
- const spi_master_hw_instance_t spi_master_hw_instance);
-static __INLINE void spi_master_send_recv_irq(spi_master_instance_t * const p_spi_instance);
-static __INLINE void spi_master_signal_evt(spi_master_instance_t * const p_spi_instance,
- spi_master_evt_type_t event_type,
- const uint16_t data);
-
-#ifdef SPI_MASTER_0_ENABLE
-/**
- * @brief SPI0 interrupt handler.
- */
-void SPI0_TWI0_IRQHandler(void)
-{
- if (NRF_SPI0->EVENTS_READY != 0)
- {
- NRF_SPI0->EVENTS_READY = 0;
-
- spi_master_instance_t * p_spi_instance = spi_master_get_instance(SPI_MASTER_0);
-
- spi_master_send_recv_irq(p_spi_instance);
- }
-}
-#endif //SPI_MASTER_0_ENABLE
-
-#ifdef SPI_MASTER_1_ENABLE
-/**
- * @brief SPI0 interrupt handler.
- */
-void SPI1_TWI1_IRQHandler(void)
-{
- if (NRF_SPI1->EVENTS_READY != 0)
- {
- NRF_SPI1->EVENTS_READY = 0;
-
- spi_master_instance_t * p_spi_instance = spi_master_get_instance(SPI_MASTER_1);
-
- spi_master_send_recv_irq(p_spi_instance);
- }
-}
-#endif //SPI_MASTER_1_ENABLE
-
-#if defined(SPI_MASTER_0_ENABLE) || defined(SPI_MASTER_1_ENABLE)
-
-/**@brief Function for getting an instance of SPI master. */
-static __INLINE spi_master_instance_t * spi_master_get_instance(
- const spi_master_hw_instance_t spi_master_hw_instance)
-{
- return &(m_spi_master_instances[(uint8_t)spi_master_hw_instance]);
-}
-
-/** @brief Function for initializing instance of SPI master by default values. */
-static __INLINE void spi_master_init_hw_instance(NRF_SPI_Type * p_nrf_spi,
- IRQn_Type irq_type,
- spi_master_instance_t * p_spi_instance)
-{
- APP_ERROR_CHECK_BOOL(p_spi_instance != NULL);
-
- p_spi_instance->p_nrf_spi = p_nrf_spi;
- p_spi_instance->irq_type = irq_type;
-
- p_spi_instance->p_tx_buffer = NULL;
- p_spi_instance->tx_length = 0;
- p_spi_instance->tx_index = 0;
-
- p_spi_instance->p_rx_buffer = NULL;
- p_spi_instance->rx_length = 0;
- p_spi_instance->rx_index = 0;
-
- p_spi_instance->bytes_count = 0;
- p_spi_instance->max_length = 0;
- p_spi_instance->pin_slave_select = 0;
-
- p_spi_instance->callback_event_handler = NULL;
-
- p_spi_instance->state = SPI_MASTER_STATE_DISABLED;
- p_spi_instance->abort_flag = false;
- p_spi_instance->start_flag = false;
-}
-
-/**@brief Function for initializing TX or RX buffer. */
-static __INLINE void spi_master_buffer_init(uint8_t * const p_buf,
- const uint16_t buf_len,
- uint8_t * * pp_buf,
- uint16_t * const p_buf_len,
- uint16_t * const p_index)
-{
- APP_ERROR_CHECK_BOOL(pp_buf != NULL);
- APP_ERROR_CHECK_BOOL(p_buf_len != NULL);
- APP_ERROR_CHECK_BOOL(p_index != NULL);
-
- *pp_buf = p_buf;
- *p_buf_len = (p_buf != NULL) ? buf_len : 0;
- *p_index = 0;
-}
-
-/**@brief Function for releasing TX or RX buffer. */
-static __INLINE void spi_master_buffer_release(uint8_t * * const pp_buf, uint16_t * const p_buf_len)
-{
- APP_ERROR_CHECK_BOOL(pp_buf != NULL);
- APP_ERROR_CHECK_BOOL(p_buf_len != NULL);
-
- *pp_buf = NULL;
- *p_buf_len = 0;
-}
-
-/**@brief Function for sending events by callback. */
-static __INLINE void spi_master_signal_evt(spi_master_instance_t * const p_spi_instance,
- spi_master_evt_type_t event_type,
- const uint16_t data)
-{
- APP_ERROR_CHECK_BOOL(p_spi_instance != NULL);
-
- if (p_spi_instance->callback_event_handler != NULL)
- {
- spi_master_evt_t event = {SPI_MASTER_EVT_TYPE_MAX, 0};
- event.type = event_type;
- event.data = data;
- p_spi_instance->callback_event_handler(event);
- }
-}
-
-/**@brief Function insert to a TX buffer another byte or two bytes (depends on flag @ref DOUBLE_BUFFERED). */
-static __INLINE void spi_master_send_initial_bytes(spi_master_instance_t * const p_spi_instance)
-{
- APP_ERROR_CHECK_BOOL(p_spi_instance != NULL);
-
- p_spi_instance->p_nrf_spi->TXD = ((p_spi_instance->p_tx_buffer != NULL) &&
- (p_spi_instance->tx_index < p_spi_instance->tx_length)) ?
- p_spi_instance->p_tx_buffer[p_spi_instance->tx_index] :
- SPI_DEFAULT_TX_BYTE;
- (p_spi_instance->tx_index)++;
-
- #ifdef DOUBLE_BUFFERED
-
- if (p_spi_instance->tx_index < p_spi_instance->max_length)
- {
- p_spi_instance->p_nrf_spi->TXD = ((p_spi_instance->p_tx_buffer != NULL) &&
- (p_spi_instance->tx_index < p_spi_instance->tx_length)) ?
- p_spi_instance->p_tx_buffer[p_spi_instance->tx_index] :
- SPI_DEFAULT_TX_BYTE;
- (p_spi_instance->tx_index)++;
- }
- #endif
-}
-
-/**@brief Function for receiving and sending data from IRQ. (The same for both IRQs). */
-static __INLINE void spi_master_send_recv_irq(spi_master_instance_t * const p_spi_instance)
-{
-
- uint8_t rx_byte;
-
- APP_ERROR_CHECK_BOOL(p_spi_instance != NULL);
- APP_ERROR_CHECK_BOOL(p_spi_instance->state == SPI_MASTER_STATE_BUSY);
-
- p_spi_instance->bytes_count++;
- rx_byte = p_spi_instance->p_nrf_spi->RXD;
-
- if (p_spi_instance->start_flag)
- {
- p_spi_instance->start_flag = false;
- spi_master_signal_evt(p_spi_instance, SPI_MASTER_EVT_FIRST_BYTE_RECEIVED, (uint16_t)rx_byte);
- }
- else if (p_spi_instance->abort_flag ) //this is tricky, but callback for SPI_MASTER_EVT_FIRST_BYTE_RECEIVED will set this flag for a first byte, which is bad because there is still byte in a buffer
- { //and for a single byte transaction you will get XFERDONE event to restart
- p_spi_instance->abort_flag = false;
- p_spi_instance->state = SPI_MASTER_STATE_ABORTED;
- nrf_gpio_pin_set(p_spi_instance->pin_slave_select);
- spi_master_signal_evt(p_spi_instance, SPI_MASTER_EVT_TRANSFER_ABORTED, 0);
- return;
- }
-
- if ((p_spi_instance->p_rx_buffer != NULL) &&
- (p_spi_instance->rx_index < p_spi_instance->rx_length))
- {
- p_spi_instance->p_rx_buffer[p_spi_instance->rx_index++] = rx_byte;
- }
-
- if ((p_spi_instance->tx_index < p_spi_instance->max_length) && (!(p_spi_instance->abort_flag))) //do not TX if you know that there is an abort to be done - this should work for a DOUBLE BUFFERING ???
- {
- p_spi_instance->p_nrf_spi->TXD = ((p_spi_instance->p_tx_buffer != NULL) &&
- (p_spi_instance->tx_index < p_spi_instance->tx_length)) ?
- p_spi_instance->p_tx_buffer[p_spi_instance->tx_index] :
- SPI_DEFAULT_TX_BYTE;
- (p_spi_instance->tx_index)++;
- }
-
- if (p_spi_instance->bytes_count >= p_spi_instance->max_length)
- {
- APP_ERROR_CHECK_BOOL(p_spi_instance->bytes_count == p_spi_instance->max_length);
- nrf_gpio_pin_set(p_spi_instance->pin_slave_select);
- p_spi_instance->state = SPI_MASTER_STATE_IDLE;
- spi_master_signal_evt(p_spi_instance,
- SPI_MASTER_EVT_TRANSFER_COMPLETED,
- p_spi_instance->tx_index);
- }
- return;
-}
-#endif //defined(SPI_MASTER_0_ENABLE) || defined(SPI_MASTER_1_ENABLE)
-
-
-/**
- * @brief Function for opening and initializing a SPI master driver. */
-uint32_t spi_master_open(const spi_master_hw_instance_t spi_master_hw_instance,
- spi_master_config_t const * const p_spi_master_config)
-{
- #if defined(SPI_MASTER_0_ENABLE) || defined(SPI_MASTER_1_ENABLE)
-
-
- VERIFY_PARAM_NOT_NULL(p_spi_master_config);
-
- spi_master_instance_t * p_spi_instance = spi_master_get_instance(spi_master_hw_instance);
-
- switch (spi_master_hw_instance)
- {
- #ifdef SPI_MASTER_0_ENABLE
- case SPI_MASTER_0:
- spi_master_init_hw_instance(NRF_SPI0, SPI0_TWI0_IRQn, p_spi_instance);
- break;
- #endif //SPI_MASTER_0_ENABLE
-
- #ifdef SPI_MASTER_1_ENABLE
- case SPI_MASTER_1:
- spi_master_init_hw_instance(NRF_SPI1, SPI1_TWI1_IRQn, p_spi_instance);
- break;
- #endif //SPI_MASTER_1_ENABLE
-
- default:
- break;
- }
-
- //A Slave select must be set as high before setting it as output,
- //because during connect it to the pin it causes glitches.
- nrf_gpio_pin_set(p_spi_master_config->SPI_Pin_SS);
- nrf_gpio_cfg_output(p_spi_master_config->SPI_Pin_SS);
- nrf_gpio_pin_set(p_spi_master_config->SPI_Pin_SS);
-
- //Configure GPIO
- nrf_gpio_cfg_output(p_spi_master_config->SPI_Pin_SCK);
- nrf_gpio_cfg_output(p_spi_master_config->SPI_Pin_MOSI);
- nrf_gpio_cfg_input(p_spi_master_config->SPI_Pin_MISO, NRF_GPIO_PIN_NOPULL);
- p_spi_instance->pin_slave_select = p_spi_master_config->SPI_Pin_SS;
-
- /* Configure SPI hardware */
- p_spi_instance->p_nrf_spi->PSELSCK = p_spi_master_config->SPI_Pin_SCK;
- p_spi_instance->p_nrf_spi->PSELMOSI = p_spi_master_config->SPI_Pin_MOSI;
- p_spi_instance->p_nrf_spi->PSELMISO = p_spi_master_config->SPI_Pin_MISO;
-
- p_spi_instance->p_nrf_spi->FREQUENCY = p_spi_master_config->SPI_Freq;
-
- p_spi_instance->p_nrf_spi->CONFIG =
- (uint32_t)(p_spi_master_config->SPI_CPHA << SPI_CONFIG_CPHA_Pos) |
- (p_spi_master_config->SPI_CPOL << SPI_CONFIG_CPOL_Pos) |
- (p_spi_master_config->SPI_ORDER << SPI_CONFIG_ORDER_Pos);
-
-
- /* Clear waiting interrupts and events */
- p_spi_instance->p_nrf_spi->EVENTS_READY = 0;
-
- NVIC_ClearPendingIRQ(p_spi_instance->irq_type);
- NVIC_SetPriority(p_spi_instance->irq_type, APP_IRQ_PRIORITY_MID);
-
- /* Clear event handler */
- p_spi_instance->callback_event_handler = NULL;
-
- /* Enable interrupt */
- p_spi_instance->p_nrf_spi->INTENSET = (SPI_INTENSET_READY_Set << SPI_INTENCLR_READY_Pos);
- NVIC_EnableIRQ(p_spi_instance->irq_type);
-
- /* Enable SPI hardware */
- p_spi_instance->p_nrf_spi->ENABLE = (SPI_ENABLE_ENABLE_Enabled << SPI_ENABLE_ENABLE_Pos);
-
- /* Change state to IDLE */
- p_spi_instance->state = SPI_MASTER_STATE_IDLE;
-
- return NRF_SUCCESS;
- #else
- return NRF_ERROR_NOT_SUPPORTED;
- #endif
-}
-
-/**
- * @brief Function for closing a SPI master driver.
- */
-void spi_master_close(const spi_master_hw_instance_t spi_master_hw_instance)
-{
- #if defined(SPI_MASTER_0_ENABLE) || defined(SPI_MASTER_1_ENABLE)
- spi_master_instance_t * p_spi_instance = spi_master_get_instance(spi_master_hw_instance);
-
- /* Disable interrupt */
- NVIC_ClearPendingIRQ(p_spi_instance->irq_type);
- NVIC_DisableIRQ(p_spi_instance->irq_type);
-
- p_spi_instance->p_nrf_spi->ENABLE = (SPI_ENABLE_ENABLE_Disabled << SPI_ENABLE_ENABLE_Pos);
-
- /* Set Slave Select pin as input with pull-up. */
- nrf_gpio_pin_set(p_spi_instance->pin_slave_select);
- nrf_gpio_cfg_input(p_spi_instance->pin_slave_select, NRF_GPIO_PIN_PULLUP);
- p_spi_instance->pin_slave_select = (uint8_t)0xFF;
-
- /* Disconnect pins from SPI hardware */
- p_spi_instance->p_nrf_spi->PSELSCK = (uint32_t)SPI_PIN_DISCONNECTED;
- p_spi_instance->p_nrf_spi->PSELMOSI = (uint32_t)SPI_PIN_DISCONNECTED;
- p_spi_instance->p_nrf_spi->PSELMISO = (uint32_t)SPI_PIN_DISCONNECTED;
-
- /* Reset to default values */
- spi_master_init_hw_instance(NULL, (IRQn_Type)0, p_spi_instance);
- #else
- return;
- #endif
-}
-
-/**
- * @brief Function for getting current state of the SPI master driver.
- */
-__INLINE spi_master_state_t spi_master_get_state(
- const spi_master_hw_instance_t spi_master_hw_instance)
-{
- #if defined(SPI_MASTER_0_ENABLE) || defined(SPI_MASTER_1_ENABLE)
- spi_master_instance_t * spi_instance = spi_master_get_instance(spi_master_hw_instance);
- return spi_instance->state;
- #else
- return SPI_MASTER_STATE_DISABLED;
- #endif
-}
-
-/**
- * @brief Function for event handler registration.
- */
-__INLINE void spi_master_evt_handler_reg(const spi_master_hw_instance_t spi_master_hw_instance,
- spi_master_event_handler_t event_handler)
-{
- #if defined(SPI_MASTER_0_ENABLE) || defined(SPI_MASTER_1_ENABLE)
- spi_master_instance_t * spi_instance = spi_master_get_instance(spi_master_hw_instance);
- spi_instance->callback_event_handler = event_handler;
- #else
- return;
- #endif
-}
-
-/**
- * @brief Function for transmitting data between SPI master and SPI slave.
- */
-uint32_t spi_master_send_recv(const spi_master_hw_instance_t spi_master_hw_instance,
- uint8_t * const p_tx_buf, const uint16_t tx_buf_len,
- uint8_t * const p_rx_buf, const uint16_t rx_buf_len)
-{
- #if defined(SPI_MASTER_0_ENABLE) || defined(SPI_MASTER_1_ENABLE)
- spi_master_instance_t * p_spi_instance = spi_master_get_instance(spi_master_hw_instance);
-
- uint32_t err_code = NRF_SUCCESS;
- uint16_t max_length = 0;
-
- if (p_spi_instance->state == SPI_MASTER_STATE_IDLE)
- {
- NVIC_DisableIRQ(p_spi_instance->irq_type);
-
- max_length = (rx_buf_len > tx_buf_len) ? rx_buf_len : tx_buf_len;
-
- if (max_length > 0)
- {
- p_spi_instance->state = SPI_MASTER_STATE_BUSY;
- p_spi_instance->start_flag = true; //abort_flag should set by abort and cleared only by restart
- p_spi_instance->bytes_count = 0;
- p_spi_instance->max_length = max_length;
- spi_master_buffer_release(&(p_spi_instance->p_tx_buffer), &(p_spi_instance->tx_length));
- spi_master_buffer_release(&(p_spi_instance->p_rx_buffer), &(p_spi_instance->rx_length));
- /* Initialize buffers */
- spi_master_buffer_init(p_tx_buf, tx_buf_len, &(p_spi_instance->p_tx_buffer),
- &(p_spi_instance->tx_length), &(p_spi_instance->tx_index));
- spi_master_buffer_init(p_rx_buf, rx_buf_len, &(p_spi_instance->p_rx_buffer),
- &(p_spi_instance->rx_length), &(p_spi_instance->rx_index));
- nrf_gpio_pin_clear(p_spi_instance->pin_slave_select);
- spi_master_send_initial_bytes(p_spi_instance);
- spi_master_signal_evt(p_spi_instance, SPI_MASTER_EVT_TRANSFER_STARTED, max_length);
- }
- else
- {
- err_code = NRF_ERROR_INVALID_PARAM;
- }
-
- NVIC_EnableIRQ(p_spi_instance->irq_type);
- }
- else
- {
- err_code = NRF_ERROR_BUSY;
- }
-
- return err_code;
- #else
- return NRF_ERROR_NOT_SUPPORTED;
- #endif
-}
-
-#ifdef _SPI_5W_
-
-/**
- * @brief Function for aborting transfer
- */
-uint32_t spi_master_abort(const spi_master_hw_instance_t spi_master_hw_instance)
-{
- spi_master_instance_t * p_spi_instance = spi_master_get_instance(spi_master_hw_instance);
-
- NVIC_DisableIRQ(p_spi_instance->irq_type);
-
- if (p_spi_instance->state == SPI_MASTER_STATE_BUSY)
- {
- //set_flag - but only when there are events pending
- //ignore when in IDLE - must be able to restart a completed transfer
- p_spi_instance->abort_flag = true;
- }
- NVIC_EnableIRQ(p_spi_instance->irq_type);
- return NRF_SUCCESS;
-}
-
-/**
- * @brief Function for restarting transfer
- */
-uint32_t spi_master_restart(const spi_master_hw_instance_t spi_master_hw_instance)
-{
- spi_master_instance_t * p_spi_instance = spi_master_get_instance(spi_master_hw_instance);
-
- NVIC_DisableIRQ(p_spi_instance->irq_type);
- spi_master_signal_evt(p_spi_instance, SPI_MASTER_EVT_TRANSFER_RESTARTED, 0);
- p_spi_instance->state = SPI_MASTER_STATE_BUSY;
- p_spi_instance->bytes_count = 0;
- p_spi_instance->tx_index = 0;
- p_spi_instance->rx_index = 0;
- p_spi_instance->start_flag = true;
- p_spi_instance->abort_flag = false; //you should force clearing abort flag - no other way for 1 byte transfer
- nrf_gpio_pin_clear(p_spi_instance->pin_slave_select);
- spi_master_send_initial_bytes(p_spi_instance);
- NVIC_EnableIRQ(p_spi_instance->irq_type);
-
- return NRF_SUCCESS;
-}
-
-static void spi_5W_master_event_handler(spi_master_evt_t evt)
-{
-
- switch (m_hook_state)
- {
- case HOOK_STATE_IDLE:
-
- if (evt.type == SPI_MASTER_EVT_TRANSFER_STARTED)
- {
- DEBUG_EVT_SPI_MASTER_RAW_XFER_GUARDED(0);
- m_hook_state = HOOK_STATE_GUARDED;
- m_ser_phy_event_handler(evt);
- }
- break;
-
- case HOOK_STATE_GUARDED:
-
- if (evt.type == SPI_MASTER_EVT_FIRST_BYTE_RECEIVED)
- {
- if (evt.data == 0)
- {
- DEBUG_EVT_SPI_MASTER_RAW_XFER_PASSED(0);
- m_hook_state = HOOK_STATE_PASSING;
- }
- else
- {
- DEBUG_EVT_SPI_MASTER_RAW_XFER_ABORTED(0);
- m_hook_state = HOOK_STATE_ABORTED;
- (void)spi_master_abort(m_spi_master_hw_instance);
- }
- }
- break;
-
- case HOOK_STATE_ABORTED:
-
- if ((evt.type == SPI_MASTER_EVT_TRANSFER_ABORTED) ||
- (evt.type == SPI_MASTER_EVT_TRANSFER_COMPLETED))
- {
- DEBUG_EVT_SPI_MASTER_RAW_XFER_RESTARTED(0);
- m_hook_state = HOOK_STATE_RESTARTED;
- (void)spi_master_restart(m_spi_master_hw_instance);
- }
- break;
-
- case HOOK_STATE_RESTARTED:
-
- if (evt.type == SPI_MASTER_EVT_TRANSFER_RESTARTED)
- {
- DEBUG_EVT_SPI_MASTER_RAW_XFER_GUARDED(0);
- m_hook_state = HOOK_STATE_GUARDED;
- }
- break;
-
- case HOOK_STATE_PASSING:
-
- if (evt.type == SPI_MASTER_EVT_TRANSFER_COMPLETED)
- {
- m_hook_state = HOOK_STATE_IDLE;
- m_ser_phy_event_handler(evt); //this is the only way to get a signal from complete transaction
- }
- break;
-
- default:
- break;
- }
-}
-
-void spi_5W_master_evt_handler_reg(const spi_master_hw_instance_t spi_master_hw_instance,
- spi_master_event_handler_t event_handler)
-{
- m_ser_phy_event_handler = event_handler;
- m_spi_master_hw_instance = spi_master_hw_instance;
- m_hook_state = HOOK_STATE_IDLE;
- spi_master_evt_handler_reg(spi_master_hw_instance, spi_5W_master_event_handler);
- return;
-}
-
-#endif
-
-/** @} */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/spi_master/spi_5W_master.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/spi_master/spi_5W_master.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/spi_master/spi_5W_master.h
deleted file mode 100644
index 501eeff..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/spi_master/spi_5W_master.h
+++ /dev/null
@@ -1,178 +0,0 @@
-/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is property of Nordic Semiconductor ASA.
- * Terms and conditions of usage are described in detail in NORDIC
- * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
-
-#ifndef APP_SPI_MASTER_H
-#define APP_SPI_MASTER_H
-
-#include <stdint.h>
-#include <stdlib.h>
-#include "boards.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define _SPI_5W_
-
-/**@brief Struct containing configuration parameters of the SPI master. */
-typedef struct
-{
- uint32_t SPI_Freq; /**< SPI frequency. */
- uint32_t SPI_Pin_SCK; /**< SCK pin number. */
- uint32_t SPI_Pin_MISO; /**< MISO pin number. */
- uint32_t SPI_Pin_MOSI; /**< MOSI pin number .*/
- uint32_t SPI_Pin_SS; /**< Slave select pin number. */
- uint8_t SPI_ORDER; /**< Bytes order MSBFIRST or LSBFIRST. */
- uint8_t SPI_CPOL; /**< Serial clock polarity ACTIVEHIGH or ACTIVELOW. */
- uint8_t SPI_CPHA; /**< Serial clock phase LEADING or TRAILING. */
- } spi_master_config_t;
-
-/**@brief SPI master driver events types. */
-typedef enum
-{
- SPI_MASTER_EVT_TRANSFER_STARTED = 0, /**< An event indicating that transfer has been started */
- SPI_MASTER_EVT_TRANSFER_COMPLETED, /**< An event indicating that transfer has been completed */
- SPI_MASTER_EVT_TRANSFER_ABORTED, /**< An event indicating that transfer has been aborted */
- SPI_MASTER_EVT_TRANSFER_RESTARTED, /**< An event indicating that transfer has been resumed */
- SPI_MASTER_EVT_FIRST_BYTE_RECEIVED, /**< An event indicating end of one byte transfer */
- SPI_MASTER_EVT_TYPE_MAX /**< Enumeration upper bound. */
-} spi_master_evt_type_t;
-
-/**@brief Struct containing parameters of the SPI MASTER event */
- typedef struct
- {
- spi_master_evt_type_t type; /**< Type of an event */
- uint16_t data; /**< event data - context dependent */
- } spi_master_evt_t;
-
- /**@brief SPI MASTER internal states types. */
- typedef enum
- {
- SPI_MASTER_STATE_DISABLED, /**< A state indicating that SPI master is disabled. */
- SPI_MASTER_STATE_BUSY, /**< A state indicating that SPI master is sending now. */
- SPI_MASTER_STATE_ABORTED,
- SPI_MASTER_STATE_IDLE /**< A state indicating that SPI master is idle now. */
- } spi_master_state_t;
-
- /**@brief Instances of SPI master module. */
- typedef enum
- {
- #ifdef SPI_MASTER_0_ENABLE
- SPI_MASTER_0, /**< A instance of SPI master 0. */
- #endif
-
- #ifdef SPI_MASTER_1_ENABLE
- SPI_MASTER_1, /**< A instance of SPI master 1. */
- #endif
-
- SPI_MASTER_HW_ENABLED_COUNT /**< A number of enabled instances of SPI master. */
- } spi_master_hw_instance_t;
-
-/**@brief Type of generic callback function handler to be used by all SPI MASTER driver events.
- *
- * @param[in] spi_master_evt SPI MASTER driver event.
- */
-typedef void (*spi_master_event_handler_t) (spi_master_evt_t spi_master_evt);
-
-
-/**@brief Function for opening and initializing a SPI master driver.
- *
- * @note Function initializes SPI master hardware and internal module states, unregister events callback.
- *
- * @warning If the function has been already called, the function @ref spi_master_close has to be
- * called before spi_master_open can be called again.
- *
- * @param[in] spi_master_hw_instance Instance of SPI master module.
- * @param[in] p_spi_master_config Pointer to configuration structure which will be used
- * to initialize SPI MASTER hardware.
- *
- * @retval NRF_SUCCESS Operation success.
- * @retval NRF_ERROR_INVALID_STATE Operation failure. The function has been already called.
- * To call it again the function @ref spi_master_close
- * has to be called previously.
- * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
- */
-uint32_t spi_master_open(const spi_master_hw_instance_t spi_master_hw_instance,
- spi_master_config_t const * const p_spi_master_config);
-
-
-/**@brief Function for closing a SPI MASTER driver.
- *
- * @note Function disable hardware, reset internal module states and unregister events callback
- * function.
- *
- * @param[in] spi_master_hw_instance A instance of SPI master.
- */
-void spi_master_close(const spi_master_hw_instance_t spi_master_hw_instance);
-
-
-/**@brief Function for transferring data between SPI master and SPI slave
- *
- * @note Function registers buffers pointed by p_tx_buf and p_rx_buf parameters, after that starts transmission.
- * Function generates an event of type @ref SPI_MASTER_EVT_TRANSFER_STARTED when transfer has been started
- * and @ref SPI_MASTER_EVT_TRANSFER_COMPLETED when transfer has been completed.
- *
- * @param[in] spi_master_hw_instance Instance of SPI master module.
- * @param[in] p_tx_buf Pointer to a transmit buffer.
- * @param[in] tx_buf_len Number of octets to the transfer.
- * @param[out] p_rx_buf Pointer to a receive buffer.
- * @param[in] rx_buf_len Number of octets to be received.
- *
- * @retval NRF_SUCCESS Operation success. Packet was registered to the transmission
- * and event will be send upon transmission completion.
- * @retval NRF_ERROR_BUSY Operation failure. Transmitting of a data is in progress.
- */
- uint32_t spi_master_send_recv(const spi_master_hw_instance_t spi_master_hw_instance,
- uint8_t * const p_tx_buf, const uint16_t tx_buf_len,
- uint8_t * const p_rx_buf, const uint16_t rx_buf_len);
-
-
-/**@brief Function for registration event handler.
-*
-* @note Function registers a event handler to be used by SPI MASTER driver for sending events.
-* @ref SPI_MASTER_EVT_TRANSFER_STARTED and @ref SPI_MASTER_EVT_TRANSFER_COMPLETED.
-*
-* @param[in] spi_master_hw_instance Instance of SPI master module.
-* @param[in] event_handler Generic callback function handler to be used
-* by all SPI master driver events.
-*/
-void spi_master_evt_handler_reg(const spi_master_hw_instance_t spi_master_hw_instance,
- spi_master_event_handler_t event_handler);
-
-
-/**@brief Function for getting current state of the SPI master driver.
- *
- * @note Function gets current state of the SPI master driver.
- *
- * @param[in] spi_master_hw_instance Instance of SPI master module.
- *
- * @retval SPI_MASTER_STATE_DISABLED SPI MASTER is disabled.
- * @retval SPI_MASTER_STATE_BUSY SPI_MASTER is sending now.
- * @retval SPI_MASTER_STATE_IDLE SPI_MASTER is idle now.
- */
-spi_master_state_t spi_master_get_state(const spi_master_hw_instance_t spi_master_hw_instance);
-
-#ifdef _SPI_5W_
-
-uint32_t spi_master_abort(const spi_master_hw_instance_t spi_master_hw_instance);
-
-uint32_t spi_master_restart(const spi_master_hw_instance_t spi_master_hw_instance);
-
-void spi_5W_master_evt_handler_reg(const spi_master_hw_instance_t spi_master_hw_instance,
- spi_master_event_handler_t event_handler);
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/spi_slave/nrf_drv_spis.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/spi_slave/nrf_drv_spis.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/spi_slave/nrf_drv_spis.c
deleted file mode 100644
index c62496d..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/spi_slave/nrf_drv_spis.c
+++ /dev/null
@@ -1,396 +0,0 @@
-/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is property of Nordic Semiconductor ASA.
- * Terms and conditions of usage are described in detail in NORDIC
- * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
-
-#include "nrf_drv_spis.h"
-#include <stdbool.h>
-#include <stdio.h>
-#include "nrf.h"
-#include "nrf_gpio.h"
-#include "app_error.h"
-#include "app_util_platform.h"
-#include "nrf_drv_config.h"
-#include "nrf_drv_common.h"
-#include "nordic_common.h"
-#include "sdk_common.h"
-#include "nrf_assert.h"
-
-#if !SPIS_COUNT
- #warning No SPIS instances enabled.
-#else
-
-/**@brief States of the SPI transaction state machine. */
-typedef enum
-{
- SPIS_STATE_INIT, /**< Initialization state. In this state the module waits for a call to @ref spi_slave_buffers_set. */
- SPIS_BUFFER_RESOURCE_REQUESTED, /**< State where the configuration of the memory buffers, which are to be used in SPI transaction, has started. */
- SPIS_BUFFER_RESOURCE_CONFIGURED, /**< State where the configuration of the memory buffers, which are to be used in SPI transaction, has completed. */
- SPIS_XFER_COMPLETED /**< State where SPI transaction has been completed. */
-} nrf_drv_spis_state_t;
-
-
-#if PERIPHERAL_RESOURCE_SHARING_ENABLED
- #define IRQ_HANDLER_NAME(n) irq_handler_for_instance_##n
- #define IRQ_HANDLER(n) static void IRQ_HANDLER_NAME(n)(void)
-
- #if SPIS0_ENABLED
- IRQ_HANDLER(0);
- #endif
- #if SPIS1_ENABLED
- IRQ_HANDLER(1);
- #endif
- #if SPIS2_ENABLED
- IRQ_HANDLER(2);
- #endif
- static nrf_drv_irq_handler_t const m_irq_handlers[SPIS_COUNT] = {
- #if SPIS0_ENABLED
- IRQ_HANDLER_NAME(0),
- #endif
- #if SPIS1_ENABLED
- IRQ_HANDLER_NAME(1),
- #endif
- #if SPIS2_ENABLED
- IRQ_HANDLER_NAME(2),
- #endif
- };
-#else
- #define IRQ_HANDLER(n) void SPIS##n##_IRQ_HANDLER(void)
-#endif // PERIPHERAL_RESOURCE_SHARING_ENABLED
-
-#define SPIS_IRQHANDLER_TEMPLATE(NUM) \
- IRQ_HANDLER(NUM) \
- { \
- spis_irq_handler(NRF_SPIS##NUM, &m_cb[SPIS##NUM##_INSTANCE_INDEX]); \
- }
-
-
-/**@brief SPIS control block - driver instance local data. */
-typedef struct
-{
- volatile uint32_t tx_buffer_size; //!< SPI slave TX buffer size in bytes.
- volatile uint32_t rx_buffer_size; //!< SPI slave RX buffer size in bytes.
- nrf_drv_spis_event_handler_t handler; //!< SPI event handler.
- volatile const uint8_t * tx_buffer; //!< SPI slave TX buffer.
- volatile uint8_t * rx_buffer; //!< SPI slave RX buffer.
- nrf_drv_state_t state; //!< driver initialization state.
- volatile nrf_drv_spis_state_t spi_state; //!< SPI slave state.
-} spis_cb_t;
-
-static spis_cb_t m_cb[SPIS_COUNT];
-
-static nrf_drv_spis_config_t const m_default_config[SPIS_COUNT] = {
-#if SPIS0_ENABLED
- NRF_DRV_SPIS_DEFAULT_CONFIG(0),
-#endif
-#if SPIS1_ENABLED
- NRF_DRV_SPIS_DEFAULT_CONFIG(1),
-#endif
-#if SPIS2_ENABLED
- NRF_DRV_SPIS_DEFAULT_CONFIG(2),
-#endif
-};
-
-
-ret_code_t nrf_drv_spis_init(nrf_drv_spis_t const * const p_instance,
- nrf_drv_spis_config_t const * p_config,
- nrf_drv_spis_event_handler_t event_handler)
-{
- spis_cb_t * p_cb = &m_cb[p_instance->instance_id];
-
- NRF_SPIS_Type * p_spis = p_instance->p_reg;
-
- if (p_cb->state != NRF_DRV_STATE_UNINITIALIZED)
- {
- return NRF_ERROR_INVALID_STATE;
- }
- if (p_config == NULL)
- {
- p_config = &m_default_config[p_instance->instance_id];
- }
- if ((uint32_t)p_config->mode > (uint32_t)NRF_DRV_SPIS_MODE_3)
- {
- return NRF_ERROR_INVALID_PARAM;
- }
- if (!event_handler)
- {
- return NRF_ERROR_NULL;
- }
-#if PERIPHERAL_RESOURCE_SHARING_ENABLED
- if (nrf_drv_common_per_res_acquire(p_spis,
- m_irq_handlers[p_instance->instance_id]) != NRF_SUCCESS)
- {
- return NRF_ERROR_BUSY;
- }
-#endif
-
- // Configure the SPI pins for input.
- uint32_t mosi_pin;
- uint32_t miso_pin;
-
- if (p_config->miso_pin != NRF_DRV_SPIS_PIN_NOT_USED)
- {
- nrf_gpio_cfg(p_config->miso_pin,
- NRF_GPIO_PIN_DIR_INPUT,
- NRF_GPIO_PIN_INPUT_CONNECT,
- NRF_GPIO_PIN_NOPULL,
- p_config->miso_drive,
- NRF_GPIO_PIN_NOSENSE);
- miso_pin = p_config->miso_pin;
- }
- else
- {
- miso_pin = NRF_SPIS_PIN_NOT_CONNECTED;
- }
-
- if (p_config->mosi_pin != NRF_DRV_SPIS_PIN_NOT_USED)
- {
- nrf_gpio_cfg(p_config->mosi_pin,
- NRF_GPIO_PIN_DIR_INPUT,
- NRF_GPIO_PIN_INPUT_CONNECT,
- NRF_GPIO_PIN_NOPULL,
- NRF_GPIO_PIN_S0S1,
- NRF_GPIO_PIN_NOSENSE);
- mosi_pin = p_config->mosi_pin;
- }
- else
- {
- mosi_pin = NRF_SPIS_PIN_NOT_CONNECTED;
- }
-
- nrf_gpio_cfg(p_config->csn_pin,
- NRF_GPIO_PIN_DIR_INPUT,
- NRF_GPIO_PIN_INPUT_CONNECT,
- p_config->csn_pullup,
- NRF_GPIO_PIN_S0S1,
- NRF_GPIO_PIN_NOSENSE);
-
- nrf_gpio_cfg(p_config->sck_pin,
- NRF_GPIO_PIN_DIR_INPUT,
- NRF_GPIO_PIN_INPUT_CONNECT,
- NRF_GPIO_PIN_NOPULL,
- NRF_GPIO_PIN_S0S1,
- NRF_GPIO_PIN_NOSENSE);
-
- nrf_spis_pins_set(p_spis, p_config->sck_pin, mosi_pin, miso_pin, p_config->csn_pin);
-
- nrf_spis_rx_buffer_set(p_spis, NULL, 0);
- nrf_spis_tx_buffer_set(p_spis, NULL, 0);
-
- // Configure SPI mode.
- nrf_spis_configure(p_spis, (nrf_spis_mode_t) p_config->mode,
- (nrf_spis_bit_order_t) p_config->bit_order);
-
- // Configure DEF and ORC characters.
- nrf_spis_def_set(p_spis, p_config->def);
- nrf_spis_orc_set(p_spis, p_config->orc);
-
- // Clear possible pending events.
- nrf_spis_event_clear(p_spis, NRF_SPIS_EVENT_END);
- nrf_spis_event_clear(p_spis, NRF_SPIS_EVENT_ACQUIRED);
-
- // Enable END_ACQUIRE shortcut.
- nrf_spis_shorts_enable(p_spis, NRF_SPIS_SHORT_END_ACQUIRE);
-
- m_cb[p_instance->instance_id].spi_state = SPIS_STATE_INIT;
- m_cb[p_instance->instance_id].handler = event_handler;
-
-
- // Enable IRQ.
- nrf_spis_int_enable(p_spis, NRF_SPIS_INT_ACQUIRED_MASK | NRF_SPIS_INT_END_MASK);
- nrf_drv_common_irq_enable(p_instance->irq, p_config->irq_priority);
-
- p_cb->state = NRF_DRV_STATE_INITIALIZED;
-
- // Enable SPI slave device.
- nrf_spis_enable(p_spis);
-
- return NRF_SUCCESS;
-}
-
-
-void nrf_drv_spis_uninit(nrf_drv_spis_t const * const p_instance)
-{
- spis_cb_t * p_cb = &m_cb[p_instance->instance_id];
- ASSERT(p_cb->state != NRF_DRV_STATE_UNINITIALIZED);
-
- NRF_SPIS_Type * p_spis = p_instance->p_reg;
-
- #define DISABLE_ALL 0xFFFFFFFF
- nrf_spis_disable(p_spis);
- nrf_drv_common_irq_disable(p_instance->irq);
- nrf_spis_int_disable(p_spis, DISABLE_ALL);
- #undef DISABLE_ALL
-
-#if PERIPHERAL_RESOURCE_SHARING_ENABLED
- nrf_drv_common_per_res_release(p_spis);
-#endif
-
- p_cb->state = NRF_DRV_STATE_UNINITIALIZED;
-}
-
-
-/**@brief Function for executing the state entry action. */
-static void spis_state_entry_action_execute(NRF_SPIS_Type * p_spis,
- spis_cb_t * p_cb)
-{
- nrf_drv_spis_event_t event;
-
- switch (p_cb->spi_state)
- {
- case SPIS_BUFFER_RESOURCE_REQUESTED:
- nrf_spis_task_trigger(p_spis, NRF_SPIS_TASK_ACQUIRE);
- break;
-
- case SPIS_BUFFER_RESOURCE_CONFIGURED:
- event.evt_type = NRF_DRV_SPIS_BUFFERS_SET_DONE;
- event.rx_amount = 0;
- event.tx_amount = 0;
-
- APP_ERROR_CHECK_BOOL(p_cb->handler != NULL);
- p_cb->handler(event);
- break;
-
- case SPIS_XFER_COMPLETED:
- event.evt_type = NRF_DRV_SPIS_XFER_DONE;
- event.rx_amount = nrf_spis_rx_amount_get(p_spis);
- event.tx_amount = nrf_spis_tx_amount_get(p_spis);
- APP_ERROR_CHECK_BOOL(p_cb->handler != NULL);
- p_cb->handler(event);
- break;
-
- default:
- // No implementation required.
- break;
- }
-}
-
-/**@brief Function for changing the state of the SPI state machine.
- *
- * @param[in] p_spis SPIS instance register.
- * @param[in] p_cb SPIS instance control block.
- * @param[in] new_state State where the state machine transits to.
- */
-static void spis_state_change(NRF_SPIS_Type * p_spis,
- spis_cb_t * p_cb,
- nrf_drv_spis_state_t new_state)
-{
- p_cb->spi_state = new_state;
- spis_state_entry_action_execute(p_spis, p_cb);
-}
-
-
-ret_code_t nrf_drv_spis_buffers_set(nrf_drv_spis_t const * const p_instance,
- const uint8_t * p_tx_buffer,
- uint8_t tx_buffer_length,
- uint8_t * p_rx_buffer,
- uint8_t rx_buffer_length)
-{
- spis_cb_t * p_cb = &m_cb[p_instance->instance_id];
- uint32_t err_code;
-
- VERIFY_PARAM_NOT_NULL(p_rx_buffer);
- VERIFY_PARAM_NOT_NULL(p_tx_buffer);
-
- // EasyDMA requires that transfer buffers are placed in Data RAM region;
- // signal error if they are not.
- if ((p_tx_buffer != NULL && !nrf_drv_is_in_RAM(p_tx_buffer)) ||
- (p_rx_buffer != NULL && !nrf_drv_is_in_RAM(p_rx_buffer)))
- {
- return NRF_ERROR_INVALID_ADDR;
- }
-
- switch (p_cb->spi_state)
- {
- case SPIS_STATE_INIT:
- case SPIS_XFER_COMPLETED:
- case SPIS_BUFFER_RESOURCE_CONFIGURED:
- p_cb->tx_buffer = p_tx_buffer;
- p_cb->rx_buffer = p_rx_buffer;
- p_cb->tx_buffer_size = tx_buffer_length;
- p_cb->rx_buffer_size = rx_buffer_length;
- err_code = NRF_SUCCESS;
-
- spis_state_change(p_instance->p_reg, p_cb, SPIS_BUFFER_RESOURCE_REQUESTED);
- break;
-
- case SPIS_BUFFER_RESOURCE_REQUESTED:
- err_code = NRF_ERROR_INVALID_STATE;
- break;
-
- default:
- // @note: execution of this code path would imply internal error in the design.
- err_code = NRF_ERROR_INTERNAL;
- break;
- }
-
- return err_code;
-}
-
-static void spis_irq_handler(NRF_SPIS_Type * p_spis, spis_cb_t * p_cb)
-{
- // @note: as multiple events can be pending for processing, the correct event processing order
- // is as follows:
- // - SPI semaphore acquired event.
- // - SPI transaction complete event.
-
- // Check for SPI semaphore acquired event.
- if (nrf_spis_event_check(p_spis, NRF_SPIS_EVENT_ACQUIRED))
- {
- nrf_spis_event_clear(p_spis, NRF_SPIS_EVENT_ACQUIRED);
-
- switch (p_cb->spi_state)
- {
- case SPIS_BUFFER_RESOURCE_REQUESTED:
- nrf_spis_tx_buffer_set(p_spis, (uint8_t *)p_cb->tx_buffer, p_cb->tx_buffer_size);
- nrf_spis_rx_buffer_set(p_spis, (uint8_t *)p_cb->rx_buffer, p_cb->rx_buffer_size);
-
- nrf_spis_task_trigger(p_spis, NRF_SPIS_TASK_RELEASE);
-
- spis_state_change(p_spis, p_cb, SPIS_BUFFER_RESOURCE_CONFIGURED);
- break;
-
- default:
- // No implementation required.
- break;
- }
- }
-
- // Check for SPI transaction complete event.
- if (nrf_spis_event_check(p_spis, NRF_SPIS_EVENT_END))
- {
- nrf_spis_event_clear(p_spis, NRF_SPIS_EVENT_END);
-
- switch (p_cb->spi_state)
- {
- case SPIS_BUFFER_RESOURCE_CONFIGURED:
- spis_state_change(p_spis, p_cb, SPIS_XFER_COMPLETED);
- break;
-
- default:
- // No implementation required.
- break;
- }
- }
-}
-
-#if SPIS0_ENABLED
- SPIS_IRQHANDLER_TEMPLATE(0)
-#endif
-
-#if SPIS1_ENABLED
- SPIS_IRQHANDLER_TEMPLATE(1)
-#endif
-
-#if SPIS2_ENABLED
- SPIS_IRQHANDLER_TEMPLATE(2)
-#endif
-
-#endif // SPI_COUNT > 0
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/spi_slave/nrf_drv_spis.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/spi_slave/nrf_drv_spis.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/spi_slave/nrf_drv_spis.h
deleted file mode 100644
index 9734466..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/spi_slave/nrf_drv_spis.h
+++ /dev/null
@@ -1,231 +0,0 @@
-/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is property of Nordic Semiconductor ASA.
- * Terms and conditions of usage are described in detail in NORDIC
- * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
-
-/**@file
- * @defgroup nrf_spis SPI slave HAL and driver
- * @ingroup nrf_spi
- * @brief SPI slave API.
- * @details The SPIS HAL provides basic APIs for accessing the registers
- * of the SPIS. The SPIS driver provides APIs on a higher level.
- **/
-
-#ifndef SPI_SLAVE_H__
-#define SPI_SLAVE_H__
-
-#include <stdint.h>
-#include "nrf.h"
-#include "nrf_error.h"
-#include "nrf_drv_config.h"
-#include "nrf_spis.h"
-#include "nrf_gpio.h"
-#include "sdk_common.h"
-#include "app_util_platform.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if defined(NRF52)
- #define SPIS2_IRQ SPIM2_SPIS2_SPI2_IRQn
- #define SPIS2_IRQ_HANDLER SPIM2_SPIS2_SPI2_IRQHandler
- #define SPIS0_IRQ SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn
- #define SPIS0_IRQ_HANDLER SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler
- #define SPIS1_IRQ SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn
- #define SPIS1_IRQ_HANDLER SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler
-#else
- #define SPIS0_IRQ SPI0_TWI0_IRQn
- #define SPIS0_IRQ_HANDLER SPI0_TWI0_IRQHandler
- #define SPIS1_IRQ SPI1_TWI1_IRQn
- #define SPIS1_IRQ_HANDLER SPI1_TWI1_IRQHandler
-#endif
-
-/**
- * @defgroup nrf_drv_spi_slave SPI slave driver
- * @{
- * @ingroup nrf_spis
- *
- * @brief Multi-instance SPI slave driver.
- */
-
-#define NRF_DRV_SPIS_DEFAULT_CSN_PULLUP NRF_GPIO_PIN_NOPULL /**< Default pull-up configuration of the SPI CS. */
-#define NRF_DRV_SPIS_DEFAULT_MISO_DRIVE NRF_GPIO_PIN_S0S1 /**< Default drive configuration of the SPI MISO. */
-#define NRF_DRV_SPIS_DEFAULT_DEF 0xFF /**< Default DEF character. */
-#define NRF_DRV_SPIS_DEFAULT_ORC 0xFF /**< Default ORC character. */
-
-/**
-* @brief This value can be provided instead of a pin number for the signals MOSI
-* and MISO to specify that the given signal is not used and therefore
-* does not need to be connected to a pin.
-*/
-#define NRF_DRV_SPIS_PIN_NOT_USED 0xFF
-
-/** @brief SPIS transaction bit order definitions. */
-typedef enum
-{
- NRF_DRV_SPIS_BIT_ORDER_LSB_FIRST = NRF_SPIS_BIT_ORDER_LSB_FIRST, /**< Least significant bit shifted out first. */
- NRF_DRV_SPIS_BIT_ORDER_MSB_FIRST = NRF_SPIS_BIT_ORDER_MSB_FIRST /**< Most significant bit shifted out first. */
-} nrf_drv_spis_endian_t;
-
-/** @brief SPIS mode definitions for clock polarity and phase. */
-typedef enum
-{
- NRF_DRV_SPIS_MODE_0 = NRF_SPIS_MODE_0, /**< (CPOL = 0, CPHA = 0). */
- NRF_DRV_SPIS_MODE_1 = NRF_SPIS_MODE_1, /**< (CPOL = 0, CPHA = 1). */
- NRF_DRV_SPIS_MODE_2 = NRF_SPIS_MODE_2, /**< (CPOL = 1, CPHA = 0). */
- NRF_DRV_SPIS_MODE_3 = NRF_SPIS_MODE_3 /**< (CPOL = 1, CPHA = 1). */
-} nrf_drv_spis_mode_t;
-
-/** @brief Event callback function event definitions. */
-typedef enum
-{
- NRF_DRV_SPIS_BUFFERS_SET_DONE, /**< Memory buffer set event. Memory buffers have been set successfully to the SPI slave device, and SPI transactions can be done. */
- NRF_DRV_SPIS_XFER_DONE, /**< SPI transaction event. SPI transaction has been completed. */
- NRF_DRV_SPIS_EVT_TYPE_MAX /**< Enumeration upper bound. */
-} nrf_drv_spis_event_type_t;
-
-/** @brief Structure containing the event context from the SPI slave driver. */
-typedef struct
-{
- nrf_drv_spis_event_type_t evt_type; //!< Type of event.
- uint32_t rx_amount; //!< Number of bytes received in last transaction. This parameter is only valid for @ref NRF_DRV_SPIS_XFER_DONE events.
- uint32_t tx_amount; //!< Number of bytes transmitted in last transaction. This parameter is only valid for @ref NRF_DRV_SPIS_XFER_DONE events.
-} nrf_drv_spis_event_t;
-
-/** @brief SPI slave driver instance data structure. */
-typedef struct
-{
- NRF_SPIS_Type * p_reg; //!< SPIS instance register.
- uint8_t instance_id; //!< SPIS instance ID.
- IRQn_Type irq; //!< IRQ of the specific instance.
-} nrf_drv_spis_t;
-
-/** @brief Macro for creating an SPI slave driver instance. */
-#define NRF_DRV_SPIS_INSTANCE(id) \
-{ \
- .p_reg = CONCAT_2(NRF_SPIS, id), \
- .irq = CONCAT_3(SPIS, id, _IRQ), \
- .instance_id = CONCAT_3(SPIS, id, _INSTANCE_INDEX), \
-}
-
-/** @brief SPI slave instance default configuration. */
-#define NRF_DRV_SPIS_DEFAULT_CONFIG(id) \
-{ \
- .sck_pin = CONCAT_3(SPIS, id, _CONFIG_SCK_PIN), \
- .mosi_pin = CONCAT_3(SPIS, id, _CONFIG_MOSI_PIN), \
- .miso_pin = CONCAT_3(SPIS, id, _CONFIG_MISO_PIN), \
- .csn_pin = NRF_DRV_SPIS_PIN_NOT_USED, \
- .miso_drive = NRF_DRV_SPIS_DEFAULT_MISO_DRIVE, \
- .csn_pullup = NRF_DRV_SPIS_DEFAULT_CSN_PULLUP, \
- .orc = NRF_DRV_SPIS_DEFAULT_ORC, \
- .def = NRF_DRV_SPIS_DEFAULT_DEF, \
- .mode = NRF_DRV_SPIS_MODE_0, \
- .bit_order = NRF_DRV_SPIS_BIT_ORDER_MSB_FIRST, \
- .irq_priority = CONCAT_3(SPIS, id, _CONFIG_IRQ_PRIORITY), \
-}
-
-/** @brief SPI peripheral device configuration data. */
-typedef struct
-{
- uint32_t miso_pin; //!< SPI MISO pin (optional).
- /**< Set @ref NRF_DRV_SPIS_PIN_NOT_USED
- * if this signal is not needed. */
- uint32_t mosi_pin; //!< SPI MOSI pin (optional).
- /**< Set @ref NRF_DRV_SPIS_PIN_NOT_USED
- * if this signal is not needed. */
- uint32_t sck_pin; //!< SPI SCK pin.
- uint32_t csn_pin; //!< SPI CSN pin.
- nrf_drv_spis_mode_t mode; //!< SPI mode.
- nrf_drv_spis_endian_t bit_order; //!< SPI transaction bit order.
- nrf_gpio_pin_pull_t csn_pullup; //!< CSN pin pull-up configuration.
- nrf_gpio_pin_drive_t miso_drive; //!< MISO pin drive configuration.
- uint8_t def; //!< Character clocked out in case of an ignored transaction.
- uint8_t orc; //!< Character clocked out after an over-read of the transmit buffer.
- uint8_t irq_priority; //!< Interrupt priority.
-} nrf_drv_spis_config_t;
-
-
-/** @brief SPI slave event callback function type.
- *
- * @param[in] event SPI slave driver event.
- */
-typedef void (*nrf_drv_spis_event_handler_t)(nrf_drv_spis_event_t event);
-
-/** @brief Function for initializing the SPI slave driver instance.
- *
- * @param[in] p_instance Pointer to the instance structure.
- * @param[in] p_config Pointer to the structure with the initial configuration.
- * If NULL, the default configuration will be used.
- * @param[in] event_handler Function to be called by the SPI slave driver upon event.
- *
- * @retval NRF_SUCCESS If the initialization was successful.
- * @retval NRF_ERROR_INVALID_PARAM If an invalid parameter is supplied.
- * @retval NRF_ERROR_BUSY If some other peripheral with the same
- * instance ID is already in use. This is
- * possible only if PERIPHERAL_RESOURCE_SHARING_ENABLED
- * is set to a value other than zero.
- */
-ret_code_t nrf_drv_spis_init(nrf_drv_spis_t const * const p_instance,
- nrf_drv_spis_config_t const * p_config,
- nrf_drv_spis_event_handler_t event_handler);
-
-/**
- * @brief Function for uninitializing the SPI slave driver instance.
- *
- * @param[in] p_instance Pointer to the instance structure.
- */
-void nrf_drv_spis_uninit(nrf_drv_spis_t const * const p_instance);
-
-/** @brief Function for preparing the SPI slave instance for a single SPI transaction.
- *
- * This function prepares the SPI slave device to be ready for a single SPI transaction. It configures
- * the SPI slave device to use the memory supplied with the function call in SPI transactions.
- *
- * When either the memory buffer configuration or the SPI transaction has been
- * completed, the event callback function will be called with the appropriate event
- * @ref nrf_drv_spis_event_type_t. Note that the callback function can be called before returning from
- * this function, because it is called from the SPI slave interrupt context.
- *
- * @note This function can be called from the callback function context.
- *
- * @note Client applications must call this function after every @ref NRF_DRV_SPIS_XFER_DONE event if
- * the SPI slave driver should be prepared for a possible new SPI transaction.
- *
- * @note Peripherals that are using EasyDMA (for example, SPIS) require the transfer buffers
- * to be placed in the Data RAM region. Otherwise, this function will fail
- * with the error code NRF_ERROR_INVALID_ADDR.
- *
- * @param[in] p_instance SPIS instance.
- * @param[in] p_tx_buffer Pointer to the TX buffer.
- * @param[in] p_rx_buffer Pointer to the RX buffer.
- * @param[in] tx_buffer_length Length of the TX buffer in bytes.
- * @param[in] rx_buffer_length Length of the RX buffer in bytes.
- *
- * @retval NRF_SUCCESS If the operation was successful.
- * @retval NRF_ERROR_NULL If the operation failed because a NULL pointer was supplied.
- * @retval NRF_ERROR_INVALID_STATE If the operation failed because the SPI slave device is in an incorrect state.
- * @retval NRF_ERROR_INVALID_ADDR If the provided buffers are not placed in the Data
- * RAM region.
- * @retval NRF_ERROR_INTERNAL If the operation failed because of an internal error.
- */
-ret_code_t nrf_drv_spis_buffers_set(nrf_drv_spis_t const * const p_instance,
- const uint8_t * p_tx_buffer,
- uint8_t tx_buffer_length,
- uint8_t * p_rx_buffer,
- uint8_t rx_buffer_length);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // SPI_SLAVE_H__
-
-/** @} */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/swi/nrf_drv_swi.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/swi/nrf_drv_swi.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/swi/nrf_drv_swi.c
deleted file mode 100644
index e8c2bb2..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/swi/nrf_drv_swi.c
+++ /dev/null
@@ -1,326 +0,0 @@
-/* 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 "nrf_drv_common.h"
-#include "nrf_error.h"
-#include "nrf_assert.h"
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include "nrf_drv_swi.h"
-#include "app_util_platform.h"
-
-STATIC_ASSERT(SWI_COUNT > 0);
-STATIC_ASSERT(SWI_COUNT <= SWI_MAX);
-STATIC_ASSERT(SWI_MAX_FLAGS <= sizeof(nrf_swi_flags_t) * 8);
-
-#ifdef SWI_DISABLE0
- #undef SWI_DISABLE0
- #define SWI_DISABLE0 1uL
-#else
- #if SWI_COUNT > 0
- #define SWI_DISABLE0 0uL
- #else
- #define SWI_DISABLE0 1uL
- #endif
-#endif
-
-#ifdef SWI_DISABLE1
- #undef SWI_DISABLE1
- #define SWI_DISABLE1 1uL
-#else
- #if SWI_COUNT > 1
- #define SWI_DISABLE1 0uL
- #else
- #define SWI_DISABLE1 1uL
- #endif
-#endif
-
-#ifdef SWI_DISABLE2
- #undef SWI_DISABLE2
- #define SWI_DISABLE2 1uL
-#else
- #if SWI_COUNT > 2
- #define SWI_DISABLE2 0uL
- #else
- #define SWI_DISABLE2 1uL
- #endif
-#endif
-
-#ifdef SWI_DISABLE3
- #undef SWI_DISABLE3
- #define SWI_DISABLE3 1uL
-#else
- #if SWI_COUNT > 3
- #define SWI_DISABLE3 0uL
- #else
- #define SWI_DISABLE3 1uL
- #endif
-#endif
-
-#ifdef SWI_DISABLE4
- #undef SWI_DISABLE4
- #define SWI_DISABLE4 1uL
-#else
- #if SWI_COUNT > 4
- #define SWI_DISABLE4 0uL
- #else
- #define SWI_DISABLE4 1uL
- #endif
-#endif
-
-#ifdef SWI_DISABLE5
- #undef SWI_DISABLE5
- #define SWI_DISABLE5 1uL
-#else
- #if SWI_COUNT > 5
- #define SWI_DISABLE5 0uL
- #else
- #define SWI_DISABLE5 1uL
- #endif
-#endif
-
-#define SWI_START_NUMBER ( (SWI_DISABLE0) \
- + (SWI_DISABLE0 * SWI_DISABLE1) \
- + (SWI_DISABLE0 * SWI_DISABLE1 * SWI_DISABLE2) \
- + (SWI_DISABLE0 * SWI_DISABLE1 * SWI_DISABLE2 * SWI_DISABLE3) \
- + (SWI_DISABLE0 * SWI_DISABLE1 * SWI_DISABLE2 * SWI_DISABLE3 * SWI_DISABLE4) \
- + (SWI_DISABLE0 * SWI_DISABLE1 * SWI_DISABLE2 * SWI_DISABLE3 * SWI_DISABLE4 \
- * SWI_DISABLE5) )
-
-#define SWI_ARRAY_SIZE (SWI_COUNT - SWI_START_NUMBER)
-
-#if (SWI_COUNT <= SWI_START_NUMBER)
- #undef SWI_ARRAY_SIZE
- #define SWI_ARRAY_SIZE 1
-#endif
-
-static nrf_drv_state_t m_drv_state = NRF_DRV_STATE_UNINITIALIZED;
-static nrf_swi_handler_t m_swi_handlers[SWI_ARRAY_SIZE];
-
-#if !EGU_ENABLED
-static nrf_swi_flags_t m_swi_flags[SWI_ARRAY_SIZE];
-#endif
-
-
-#if EGU_ENABLED > 0
-
-/**@brief Get the specific EGU instance. */
-__STATIC_INLINE NRF_EGU_Type * egu_instance_get(nrf_swi_t swi)
-{
- return (NRF_EGU_Type*) (NRF_EGU0_BASE + (((uint32_t) swi) * (NRF_EGU1_BASE - NRF_EGU0_BASE)));
-}
-
-/**@brief Software interrupt handler (using EGU). */
-static void nrf_drv_swi_process(nrf_swi_t swi)
-{
- ASSERT(m_swi_handlers[swi - SWI_START_NUMBER]);
- nrf_swi_flags_t flags = 0;
- NRF_EGU_Type * NRF_EGUx = egu_instance_get(swi);
-
- for (uint8_t i = 0; i < NRF_EGU_CHANNEL_COUNT; ++i)
- {
- nrf_egu_event_t egu_event = nrf_egu_event_triggered_get(i);
- if (nrf_egu_event_check(NRF_EGUx, egu_event))
- {
- flags |= (1u << i);
- nrf_egu_event_clear(NRF_EGUx, egu_event);
- }
- }
-
- m_swi_handlers[swi - SWI_START_NUMBER](swi, flags);
-}
-
-#define SWI_HANDLER_TEMPLATE(NUM) void SWI##NUM##_EGU##NUM##_IRQHandler(void) \
- { \
- nrf_drv_swi_process(NUM); \
- }
-
-#else
-
-/**@brief Software interrupt handler (without EGU). */
-static void nrf_drv_swi_process(nrf_swi_t swi, nrf_swi_flags_t flags)
-{
- ASSERT(m_swi_handlers[swi - SWI_START_NUMBER]);
- m_swi_flags[swi - SWI_START_NUMBER] &= ~flags;
- m_swi_handlers[swi - SWI_START_NUMBER](swi, flags);
-}
-
-
-#define SWI_HANDLER_TEMPLATE(NUM) void SWI##NUM##_IRQHandler(void) \
- { \
- nrf_drv_swi_process((NUM), m_swi_flags[(NUM) - SWI_START_NUMBER]); \
- }
-
-#endif
-
-#if SWI_DISABLE0 == 0
-SWI_HANDLER_TEMPLATE(0)
-#endif
-
-#if SWI_DISABLE1 == 0
-SWI_HANDLER_TEMPLATE(1)
-#endif
-
-#if SWI_DISABLE2 == 0
-SWI_HANDLER_TEMPLATE(2)
-#endif
-
-#if SWI_DISABLE3 == 0
-SWI_HANDLER_TEMPLATE(3)
-#endif
-
-#if SWI_DISABLE4 == 0
-SWI_HANDLER_TEMPLATE(4)
-#endif
-
-#if SWI_DISABLE5 == 0
-SWI_HANDLER_TEMPLATE(5)
-#endif
-
-#define AVAILABLE_SWI (0x3FuL & ~( \
- (SWI_DISABLE0 << 0) | (SWI_DISABLE1 << 1) | (SWI_DISABLE2 << 2) \
- | (SWI_DISABLE3 << 3) | (SWI_DISABLE4 << 4) | (SWI_DISABLE5 << 5) \
- ))
-
-#if (AVAILABLE_SWI == 0)
- #warning No available SWIs.
-#endif
-
-/**@brief Function for converting SWI number to system interrupt number.
- *
- * @param[in] swi SWI number.
- *
- * @retval IRQ number.
- */
-__STATIC_INLINE IRQn_Type nrf_drv_swi_irq_of(nrf_swi_t swi)
-{
- return (IRQn_Type)((uint32_t)SWI0_IRQn + (uint32_t)swi);
-}
-
-
-/**@brief Function for checking if given SWI is allocated.
- *
- * @param[in] swi SWI number.
- */
-__STATIC_INLINE bool swi_is_allocated(nrf_swi_t swi)
-{
- ASSERT(swi < SWI_COUNT);
-#if SWI_START_NUMBER > 0
- if (swi < SWI_START_NUMBER)
- {
- return false;
- }
-#endif
- /*lint -e(661) out of range case handled by assert above*/
- return m_swi_handlers[swi - SWI_START_NUMBER];
-}
-
-
-ret_code_t nrf_drv_swi_init(void)
-{
- if (m_drv_state == NRF_DRV_STATE_UNINITIALIZED)
- {
- m_drv_state = NRF_DRV_STATE_INITIALIZED;
- return NRF_SUCCESS;
- }
- return MODULE_ALREADY_INITIALIZED;
-}
-
-
-void nrf_drv_swi_uninit(void)
-{
- ASSERT(m_drv_state != NRF_DRV_STATE_UNINITIALIZED)
-
- for (uint32_t i = SWI_START_NUMBER; i < SWI_COUNT; ++i)
- {
- m_swi_handlers[i - SWI_START_NUMBER] = NULL;
- nrf_drv_common_irq_disable(nrf_drv_swi_irq_of((nrf_swi_t) i));
-#if EGU_ENABLED > 0
- NRF_EGU_Type * NRF_EGUx = egu_instance_get(i);
- nrf_egu_int_disable(NRF_EGUx, NRF_EGU_INT_ALL);
-#endif
- }
- m_drv_state = NRF_DRV_STATE_UNINITIALIZED;
- return;
-}
-
-
-void nrf_drv_swi_free(nrf_swi_t * p_swi)
-{
- ASSERT(swi_is_allocated(*p_swi));
- nrf_drv_common_irq_disable(nrf_drv_swi_irq_of(*p_swi));
- m_swi_handlers[(*p_swi) - SWI_START_NUMBER] = NULL;
- *p_swi = NRF_SWI_UNALLOCATED;
-}
-
-
-ret_code_t nrf_drv_swi_alloc(nrf_swi_t * p_swi, nrf_swi_handler_t event_handler, uint32_t priority)
-{
- ASSERT(event_handler);
- uint32_t err_code = NRF_ERROR_NO_MEM;
-
- for (uint32_t i = SWI_START_NUMBER; i < SWI_COUNT; i++)
- {
- CRITICAL_REGION_ENTER();
- if ((!swi_is_allocated(i)) && (AVAILABLE_SWI & (1 << i)))
- {
- m_swi_handlers[i - SWI_START_NUMBER] = event_handler;
- *p_swi = (nrf_swi_t) i;
- nrf_drv_common_irq_enable(nrf_drv_swi_irq_of(*p_swi), priority);
-#if EGU_ENABLED > 0
- NRF_EGU_Type * NRF_EGUx = egu_instance_get(i);
- nrf_egu_int_enable(NRF_EGUx, NRF_EGU_INT_ALL);
-#endif
- err_code = NRF_SUCCESS;
- }
- CRITICAL_REGION_EXIT();
- if (err_code == NRF_SUCCESS)
- {
- break;
- }
- }
- return err_code;
-}
-
-
-void nrf_drv_swi_trigger(nrf_swi_t swi, uint8_t flag_number)
-{
- ASSERT(swi_is_allocated((uint32_t) swi));
-#if EGU_ENABLED > 0
- ASSERT(flag_number < NRF_EGU_CHANNEL_COUNT);
- NRF_EGU_Type * NRF_EGUx = egu_instance_get(swi);
- nrf_egu_task_trigger(NRF_EGUx, nrf_egu_task_trigger_get(flag_number));
-#else
- ASSERT(flag_number < SWI_MAX_FLAGS);
- m_swi_flags[swi - SWI_START_NUMBER] |= (1 << flag_number);
- NVIC_SetPendingIRQ(nrf_drv_swi_irq_of(swi));
-#endif
-}
-
-
-#if EGU_ENABLED > 0
-
-uint32_t nrf_drv_swi_task_trigger_address_get(nrf_swi_t swi, uint8_t channel)
-{
- NRF_EGU_Type * NRF_EGUx = egu_instance_get(swi);
- return (uint32_t) nrf_egu_task_trigger_addres_get(NRF_EGUx, channel);
-}
-
-uint32_t nrf_drv_swi_event_triggered_address_get(nrf_swi_t swi, uint8_t channel)
-{
- NRF_EGU_Type * NRF_EGUx = egu_instance_get(swi);
- return (uint32_t) nrf_egu_event_triggered_addres_get(NRF_EGUx, channel);
-}
-
-#endif
-
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/swi/nrf_drv_swi.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/swi/nrf_drv_swi.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/swi/nrf_drv_swi.h
deleted file mode 100644
index 9ce71a0..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/swi/nrf_drv_swi.h
+++ /dev/null
@@ -1,175 +0,0 @@
-/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is property of Nordic Semiconductor ASA.
- * Terms and conditions of usage are described in detail in NORDIC
- * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
-
-/**@file
- *
- * @defgroup lib_driver_swi SWI driver
- * @{
- * @ingroup nrf_drivers
- *
- * @brief Driver for software interrupts (SWI).
- * @details The SWI driver allows the user to allocate SWIs and pass extra flags to interrupt handler functions.
- */
-
-#ifndef NRF_DRV_SWI_H__
-#define NRF_DRV_SWI_H__
-
-#include <stdbool.h>
-#include <stdint.h>
-#include "app_util.h"
-#include "app_util_platform.h"
-#include "nrf_drv_config.h"
-#include "sdk_errors.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef EGU_ENABLED
- #define EGU_ENABLED 0
-#endif
-
-#if EGU_ENABLED > 0
-#include "nrf_egu.h"
-#endif
-
-typedef uint8_t nrf_swi_t; ///< @brief SWI channel (unsigned integer).
-
-/** @brief SWI user flags (unsigned integer).
- *
- * User flags are set during the SWI trigger and passed to the callback function as an argument.
- */
-typedef uint16_t nrf_swi_flags_t;
-
-/** @brief Unallocated channel value. */
-#define NRF_SWI_UNALLOCATED ((nrf_swi_t) 0xFFFFFFFFuL)
-
-/** @brief SWI handler function.
- *
- * Takes two arguments: SWI number (nrf_swi_t) and flags (nrf_swi_flags_t).
- */
-typedef void (* nrf_swi_handler_t)(nrf_swi_t, nrf_swi_flags_t);
-
-/**@brief Maximum numbers of SWIs. This number is fixed for a specific chip. */
-#if EGU_ENABLED > 0
-#define SWI_MAX NRF_EGU_COUNT
-#else
-#define SWI_MAX 6
-#endif
-
-/**@brief Number of flags per SWI (fixed number). */
-#if EGU_ENABLED > 0
-#define SWI_MAX_FLAGS NRF_EGU_CHANNEL_COUNT
-#else
-#define SWI_MAX_FLAGS 16
-#endif
-
-#ifndef SWI_COUNT
-/** @brief Number of software interrupts available.
- *
- * This number can be set in the range from 1 to SWI_MAX.
- */
-#define SWI_COUNT 4
-#endif
-
-#ifdef SOFTDEVICE_PRESENT
- #if SWI_COUNT > 2
- #undef SWI_COUNT
- #define SWI_COUNT 2
- #endif
-#else
- #ifdef SVCALL_AS_NORMAL_FUNCTION
- // Serialization is enabled.
- #if SWI_COUNT > 2
- #undef SWI_COUNT
- #define SWI_COUNT 2
- #endif
- #endif
-#endif
-
-/**@brief Default SWI priority. */
-#define SWI_DEFAULT_PRIORITY APP_IRQ_PRIORITY_LOW
-
-
-/**@brief Function for initializing the SWI module.
- *
- * @retval NRF_SUCCESS If the module was successfully initialized.
- * @retval MODULE_ALREADY_INITIALIZED If the module has already been initialized.
- */
-ret_code_t nrf_drv_swi_init(void);
-
-
-/**@brief Function for uninitializing the SWI module.
- *
- * This function also disables all SWIs.
- */
-void nrf_drv_swi_uninit(void);
-
-
-/**@brief Function for allocating a first unused SWI instance and setting a handler.
- * @details The event handler function returns void and takes one uint32_t argument (SWI number).
- *
- * @param[out] p_swi Pointer to the SWI that has been allocated.
- * @param[in] event_handler Event handler function (must not be NULL).
- * @param[in] priority Interrupt priority.
- *
- * @retval NRF_SUCCESS If the SWI was successfully allocated.
- * @retval NRF_ERROR_NO_MEM If there is no available SWI to be used.
- */
-ret_code_t nrf_drv_swi_alloc(nrf_swi_t * p_swi, nrf_swi_handler_t event_handler, uint32_t priority);
-
-
-/**@brief Function for freeing a previously allocated SWI.
- *
- * @param[in,out] p_swi SWI to free. The value is changed to NRF_SWI_UNALLOCATED on success.
- */
-void nrf_drv_swi_free(nrf_swi_t * p_swi);
-
-
-/**@brief Function for triggering the SWI.
- *
- * @param[in] swi SWI to trigger.
- * @param[in] flag_number Number of user flag to trigger.
- */
-void nrf_drv_swi_trigger(nrf_swi_t swi, uint8_t flag_number);
-
-
-#if EGU_ENABLED > 0
-
-/**@brief Function for returning the EGU trigger task address.
- *
- * @param[in] swi SWI instance.
- * @param[in] channel Number of the EGU channel.
- *
- * @returns EGU trigger task address.
- */
-uint32_t nrf_drv_swi_task_trigger_address_get(nrf_swi_t swi, uint8_t channel);
-
-/**@brief Function for returning the EGU triggered event address.
- *
- * @param[in] swi SWI instance.
- * @param[in] channel Number of the EGU channel.
- *
- * @returns EGU triggered event address.
- */
-uint32_t nrf_drv_swi_event_triggered_address_get(nrf_swi_t swi, uint8_t channel);
-
-#endif // EGU_ENABLED > 0
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // NRF_DRV_SWI_H__
-
-/** @} */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/timer/nrf_drv_timer.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/timer/nrf_drv_timer.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/timer/nrf_drv_timer.c
deleted file mode 100644
index 1cbb846..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/timer/nrf_drv_timer.c
+++ /dev/null
@@ -1,280 +0,0 @@
-/* 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 "nrf_drv_timer.h"
-#include "nrf_drv_common.h"
-#include "app_util_platform.h"
-
-#if (TIMER_COUNT == 0)
- #error "No TIMER instances enabled in the driver configuration file."
-#endif
-
-
-/**@brief Timer control block. */
-typedef struct
-{
- nrf_timer_event_handler_t handler;
- void * context;
- nrf_drv_state_t state;
-} timer_control_block_t;
-
-static timer_control_block_t m_cb[TIMER_COUNT];
-
-static const nrf_drv_timer_config_t m_default_config[TIMER_COUNT] = {
-#if TIMER0_ENABLED
- NRF_DRV_TIMER_DEFAULT_CONFIG(0),
-#endif
-#if TIMER1_ENABLED
- NRF_DRV_TIMER_DEFAULT_CONFIG(1),
-#endif
-#if TIMER2_ENABLED
- NRF_DRV_TIMER_DEFAULT_CONFIG(2),
-#endif
-#if TIMER3_ENABLED
- NRF_DRV_TIMER_DEFAULT_CONFIG(3),
-#endif
-#if TIMER4_ENABLED
- NRF_DRV_TIMER_DEFAULT_CONFIG(4),
-#endif
-};
-
-
-ret_code_t nrf_drv_timer_init(nrf_drv_timer_t const * const p_instance,
- nrf_drv_timer_config_t const * p_config,
- nrf_timer_event_handler_t timer_event_handler)
-{
- timer_control_block_t * p_cb = &m_cb[p_instance->instance_id];
-
-#ifdef SOFTDEVICE_PRESENT
- ASSERT(p_instance->p_reg != NRF_TIMER0);
-#endif
- ASSERT(NRF_TIMER_IS_BIT_WIDTH_VALID(p_instance->p_reg, p_config->bit_width));
-
- if (p_cb->state != NRF_DRV_STATE_UNINITIALIZED)
- {
- return NRF_ERROR_INVALID_STATE;
- }
-
- if (timer_event_handler == NULL)
- {
- return NRF_ERROR_INVALID_PARAM;
- }
-
- if (p_config == NULL)
- {
- p_config = &m_default_config[p_instance->instance_id];
- }
-
- p_cb->handler = timer_event_handler;
- p_cb->context = p_config->p_context;
-
- uint8_t i;
- for (i = 0; i < p_instance->cc_channel_count; ++i)
- {
- nrf_timer_event_clear(p_instance->p_reg,
- nrf_timer_compare_event_get(i));
- }
-
- nrf_drv_common_irq_enable(nrf_drv_get_IRQn(p_instance->p_reg),
- p_config->interrupt_priority);
-
- nrf_timer_mode_set(p_instance->p_reg, p_config->mode);
- nrf_timer_bit_width_set(p_instance->p_reg, p_config->bit_width);
- nrf_timer_frequency_set(p_instance->p_reg, p_config->frequency);
-
- p_cb->state = NRF_DRV_STATE_INITIALIZED;
-
- return NRF_SUCCESS;
-}
-
-void nrf_drv_timer_uninit(nrf_drv_timer_t const * const p_instance)
-{
- nrf_drv_common_irq_disable(nrf_drv_get_IRQn(p_instance->p_reg));
-
- #define DISABLE_ALL UINT32_MAX
- nrf_timer_shorts_disable(p_instance->p_reg, DISABLE_ALL);
- nrf_timer_int_disable(p_instance->p_reg, DISABLE_ALL);
- #undef DISABLE_ALL
-
- nrf_drv_timer_disable(p_instance);
-
- m_cb[p_instance->instance_id].state = NRF_DRV_STATE_UNINITIALIZED;
-}
-
-void nrf_drv_timer_enable(nrf_drv_timer_t const * const p_instance)
-{
- ASSERT(m_cb[p_instance->instance_id].state == NRF_DRV_STATE_INITIALIZED);
- nrf_timer_task_trigger(p_instance->p_reg, NRF_TIMER_TASK_START);
- m_cb[p_instance->instance_id].state = NRF_DRV_STATE_POWERED_ON;
-}
-
-void nrf_drv_timer_disable(nrf_drv_timer_t const * const p_instance)
-{
- ASSERT(m_cb[p_instance->instance_id].state == NRF_DRV_STATE_POWERED_ON);
- nrf_timer_task_trigger(p_instance->p_reg, NRF_TIMER_TASK_SHUTDOWN);
- m_cb[p_instance->instance_id].state = NRF_DRV_STATE_INITIALIZED;
-}
-
-void nrf_drv_timer_resume(nrf_drv_timer_t const * const p_instance)
-{
- ASSERT(m_cb[p_instance->instance_id].state == NRF_DRV_STATE_POWERED_ON);
- nrf_timer_task_trigger(p_instance->p_reg, NRF_TIMER_TASK_START);
-}
-
-void nrf_drv_timer_pause(nrf_drv_timer_t const * const p_instance)
-{
- ASSERT(m_cb[p_instance->instance_id].state == NRF_DRV_STATE_POWERED_ON);
- nrf_timer_task_trigger(p_instance->p_reg, NRF_TIMER_TASK_STOP);
-}
-
-void nrf_drv_timer_clear(nrf_drv_timer_t const * const p_instance)
-{
- ASSERT(m_cb[p_instance->instance_id].state != NRF_DRV_STATE_UNINITIALIZED);
- nrf_timer_task_trigger(p_instance->p_reg, NRF_TIMER_TASK_CLEAR);
-}
-
-void nrf_drv_timer_increment(nrf_drv_timer_t const * const p_instance)
-{
- ASSERT(m_cb[p_instance->instance_id].state == NRF_DRV_STATE_POWERED_ON);
- ASSERT(nrf_timer_mode_get(p_instance->p_reg) != NRF_TIMER_MODE_TIMER);
-
- nrf_timer_task_trigger(p_instance->p_reg, NRF_TIMER_TASK_COUNT);
-}
-
-uint32_t nrf_drv_timer_capture(nrf_drv_timer_t const * const p_instance,
- nrf_timer_cc_channel_t cc_channel)
-{
- ASSERT(m_cb[p_instance->instance_id].state == NRF_DRV_STATE_POWERED_ON);
- ASSERT(cc_channel < p_instance->cc_channel_count);
-
- nrf_timer_task_trigger(p_instance->p_reg,
- nrf_timer_capture_task_get(cc_channel));
- return nrf_timer_cc_read(p_instance->p_reg, cc_channel);
-}
-
-void nrf_drv_timer_compare(nrf_drv_timer_t const * const p_instance,
- nrf_timer_cc_channel_t cc_channel,
- uint32_t cc_value,
- bool enable_int)
-{
- nrf_timer_int_mask_t timer_int = nrf_timer_compare_int_get(cc_channel);
-
- if (enable_int)
- {
- nrf_timer_int_enable(p_instance->p_reg, timer_int);
- }
- else
- {
- nrf_timer_int_disable(p_instance->p_reg, timer_int);
- }
-
- nrf_timer_cc_write(p_instance->p_reg, cc_channel, cc_value);
-}
-
-void nrf_drv_timer_extended_compare(nrf_drv_timer_t const * const p_instance,
- nrf_timer_cc_channel_t cc_channel,
- uint32_t cc_value,
- nrf_timer_short_mask_t timer_short_mask,
- bool enable_int)
-{
- nrf_timer_shorts_disable(p_instance->p_reg,
- (TIMER_SHORTS_COMPARE0_STOP_Msk << cc_channel) |
- (TIMER_SHORTS_COMPARE0_CLEAR_Msk << cc_channel));
-
- nrf_timer_shorts_enable(p_instance->p_reg, timer_short_mask);
-
- (void)nrf_drv_timer_compare(p_instance,
- cc_channel,
- cc_value,
- enable_int);
-}
-
-void nrf_drv_timer_compare_int_enable(nrf_drv_timer_t const * const p_instance,
- uint32_t channel)
-{
- ASSERT(m_cb[p_instance->instance_id].state != NRF_DRV_STATE_UNINITIALIZED);
- ASSERT(channel < p_instance->cc_channel_count);
-
- nrf_timer_event_clear(p_instance->p_reg,
- nrf_timer_compare_event_get(channel));
- nrf_timer_int_enable(p_instance->p_reg,
- nrf_timer_compare_int_get(channel));
-}
-
-void nrf_drv_timer_compare_int_disable(nrf_drv_timer_t const * const p_instance,
- uint32_t channel)
-{
- ASSERT(m_cb[p_instance->instance_id].state != NRF_DRV_STATE_UNINITIALIZED);
- ASSERT(channel < p_instance->cc_channel_count);
-
- nrf_timer_int_disable(p_instance->p_reg,
- nrf_timer_compare_int_get(channel));
-}
-
-static void irq_handler(NRF_TIMER_Type * p_reg,
- timer_control_block_t * p_cb,
- uint8_t channel_count)
-{
- uint8_t i;
- for (i = 0; i < channel_count; ++i)
- {
- nrf_timer_event_t event = nrf_timer_compare_event_get(i);
- nrf_timer_int_mask_t int_mask = nrf_timer_compare_int_get(i);
-
- if (nrf_timer_event_check(p_reg, event) &&
- nrf_timer_int_enable_check(p_reg, int_mask))
- {
- nrf_timer_event_clear(p_reg, event);
- p_cb->handler(event, p_cb->context);
- }
- }
-}
-
-#if TIMER0_ENABLED
-void TIMER0_IRQHandler(void)
-{
- irq_handler(NRF_TIMER0, &m_cb[TIMER0_INSTANCE_INDEX],
- NRF_TIMER_CC_CHANNEL_COUNT(0));
-}
-#endif
-
-#if TIMER1_ENABLED
-void TIMER1_IRQHandler(void)
-{
- irq_handler(NRF_TIMER1, &m_cb[TIMER1_INSTANCE_INDEX],
- NRF_TIMER_CC_CHANNEL_COUNT(1));
-}
-#endif
-
-#if TIMER2_ENABLED
-void TIMER2_IRQHandler(void)
-{
- irq_handler(NRF_TIMER2, &m_cb[TIMER2_INSTANCE_INDEX],
- NRF_TIMER_CC_CHANNEL_COUNT(2));
-}
-#endif
-
-#if TIMER3_ENABLED
-void TIMER3_IRQHandler(void)
-{
- irq_handler(NRF_TIMER3, &m_cb[TIMER3_INSTANCE_INDEX],
- NRF_TIMER_CC_CHANNEL_COUNT(3));
-}
-#endif
-
-#if TIMER4_ENABLED
-void TIMER4_IRQHandler(void)
-{
- irq_handler(NRF_TIMER4, &m_cb[TIMER4_INSTANCE_INDEX],
- NRF_TIMER_CC_CHANNEL_COUNT(4));
-}
-#endif