You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/11/22 20:06:50 UTC
[36/59] [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/timer/nrf_drv_timer.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/timer/nrf_drv_timer.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/timer/nrf_drv_timer.h
deleted file mode 100644
index f0ab9b4..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/timer/nrf_drv_timer.h
+++ /dev/null
@@ -1,380 +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
- * @addtogroup nrf_timer Timer HAL and driver
- * @ingroup nrf_drivers
- * @brief Timer APIs.
- * @details The timer HAL provides basic APIs for accessing the registers
- * of the timer. The timer driver provides APIs on a higher level.
- *
- * @defgroup lib_driver_timer Timer driver
- * @{
- * @ingroup nrf_timer
- * @brief Multi-instance timer driver.
- */
-
-#ifndef NRF_DRV_TIMER_H__
-#define NRF_DRV_TIMER_H__
-
-#include "nordic_common.h"
-#include "nrf_drv_config.h"
-#include "nrf_timer.h"
-#include "sdk_errors.h"
-#include "nrf_assert.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief Timer driver instance data structure.
- */
-typedef struct
-{
- NRF_TIMER_Type * p_reg; ///< Pointer to the structure with TIMER peripheral instance registers.
- uint8_t instance_id; ///< Driver instance index.
- uint8_t cc_channel_count; ///< Number of capture/compare channels.
-} nrf_drv_timer_t;
-
-/**
- * @brief Macro for creating a timer driver instance.
- */
-#define NRF_DRV_TIMER_INSTANCE(id) \
-{ \
- .p_reg = CONCAT_2(NRF_TIMER, id), \
- .instance_id = CONCAT_3(TIMER, id, _INSTANCE_INDEX), \
- .cc_channel_count = NRF_TIMER_CC_CHANNEL_COUNT(id), \
-}
-
-/**
- * @brief Timer driver instance configuration structure.
- */
-typedef struct
-{
- nrf_timer_frequency_t frequency; ///< Frequency.
- nrf_timer_mode_t mode; ///< Mode of operation.
- nrf_timer_bit_width_t bit_width; ///< Bit width.
- uint8_t interrupt_priority; ///< Interrupt priority.
- void * p_context; ///< Context passed to interrupt handler.
-} nrf_drv_timer_config_t;
-
-#define TIMER_CONFIG_FREQUENCY(id) CONCAT_3(TIMER, id, _CONFIG_FREQUENCY)
-#define TIMER_CONFIG_MODE(id) CONCAT_3(TIMER, id, _CONFIG_MODE)
-#define TIMER_CONFIG_BIT_WIDTH(id) CONCAT_3(TIMER, id, _CONFIG_BIT_WIDTH)
-#define TIMER_CONFIG_IRQ_PRIORITY(id) CONCAT_3(TIMER, id, _CONFIG_IRQ_PRIORITY)
-
-/**
- * @brief Timer driver instance default configuration.
- */
-#define NRF_DRV_TIMER_DEFAULT_CONFIG(id) \
-{ \
- .frequency = TIMER_CONFIG_FREQUENCY(id), \
- .mode = (nrf_timer_mode_t)TIMER_CONFIG_MODE(id), \
- .bit_width = (nrf_timer_bit_width_t)TIMER_CONFIG_BIT_WIDTH(id), \
- .interrupt_priority = TIMER_CONFIG_IRQ_PRIORITY(id), \
- .p_context = NULL \
-}
-
-/**
- * @brief Timer driver event handler type.
- *
- * @param[in] event_type Timer event.
- * @param[in] p_context General purpose parameter set during initialization of
- * the timer. This parameter can be used to pass
- * additional information to the handler function, for
- * example, the timer ID.
- */
-typedef void (* nrf_timer_event_handler_t)(nrf_timer_event_t event_type,
- void * p_context);
-
-/**
- * @brief Function for initializing the timer.
- *
- * @param[in] p_instance Timer instance.
- * @param[in] p_config Initial configuration.
- * If NULL, the default configuration is used.
- * @param[in] timer_event_handler Event handler provided by the user.
- * Must not be NULL.
- *
- * @retval NRF_SUCCESS If initialization was successful.
- * @retval NRF_ERROR_INVALID_STATE If the instance is already initialized.
- * @retval NRF_ERROR_INVALID_PARAM If no handler was provided.
- */
-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);
-
-/**
- * @brief Function for uninitializing the timer.
- *
- * @param[in] p_instance Timer instance.
- */
-void nrf_drv_timer_uninit(nrf_drv_timer_t const * const p_instance);
-
-/**
- * @brief Function for turning on the timer.
- *
- * @param[in] p_instance Timer instance.
- */
-void nrf_drv_timer_enable(nrf_drv_timer_t const * const p_instance);
-
-/**
- * @brief Function for turning off the timer.
- *
- * Note that the timer will allow to enter the lowest possible SYSTEM_ON state
- * only after this function is called.
- *
- * @param[in] p_instance Timer instance.
- */
-void nrf_drv_timer_disable(nrf_drv_timer_t const * const p_instance);
-
-/**
- * @brief Function for pausing the timer.
- *
- * @param[in] p_instance Timer instance.
- */
-void nrf_drv_timer_pause(nrf_drv_timer_t const * const p_instance);
-
-/**
- * @brief Function for resuming the timer.
- *
- * @param[in] p_instance Timer instance.
- */
-void nrf_drv_timer_resume(nrf_drv_timer_t const * const p_instance);
-
-/**
- * @brief Function for clearing the timer.
- *
- * @param[in] p_instance Timer instance.
- */
-void nrf_drv_timer_clear(nrf_drv_timer_t const * const p_instance);
-
-/**
- * @brief Function for incrementing the timer.
- *
- * @param[in] p_instance Timer instance.
- */
-void nrf_drv_timer_increment(nrf_drv_timer_t const * const p_instance);
-
-/**
- * @brief Function for returning the address of a specific timer task.
- *
- * @param[in] p_instance Timer instance.
- * @param[in] timer_task Timer task.
- *
- * @return Task address.
- */
-__STATIC_INLINE uint32_t nrf_drv_timer_task_address_get(
- nrf_drv_timer_t const * const p_instance,
- nrf_timer_task_t timer_task);
-
-/**
- * @brief Function for returning the address of a specific timer capture task.
- *
- * @param[in] p_instance Timer instance.
- * @param[in] channel Capture channel number.
- *
- * @return Task address.
- */
-__STATIC_INLINE uint32_t nrf_drv_timer_capture_task_address_get(
- nrf_drv_timer_t const * const p_instance,
- uint32_t channel);
-
-/**
- * @brief Function for returning the address of a specific timer event.
- *
- * @param[in] p_instance Timer instance.
- * @param[in] timer_event Timer event.
- *
- * @return Event address.
- */
-__STATIC_INLINE uint32_t nrf_drv_timer_event_address_get(
- nrf_drv_timer_t const * const p_instance,
- nrf_timer_event_t timer_event);
-
-/**
- * @brief Function for returning the address of a specific timer compare event.
- *
- * @param[in] p_instance Timer instance.
- * @param[in] channel Compare channel number.
- *
- * @return Event address.
- */
-__STATIC_INLINE uint32_t nrf_drv_timer_compare_event_address_get(
- nrf_drv_timer_t const * const p_instance,
- uint32_t channel);
-
-/**
- * @brief Function for capturing the timer value.
- *
- * @param[in] p_instance Timer instance.
- * @param[in] cc_channel Capture channel number.
- *
- * @return Captured value.
- */
-uint32_t nrf_drv_timer_capture(nrf_drv_timer_t const * const p_instance,
- nrf_timer_cc_channel_t cc_channel);
-
-/**
- * @brief Function for returning the capture value from a specific channel.
- *
- * Use this function to read channel values when PPI is used for capturing.
- *
- * @param[in] p_instance Timer instance.
- * @param[in] cc_channel Capture channel number.
- *
- * @return Captured value.
- */
-__STATIC_INLINE uint32_t nrf_drv_timer_capture_get(
- nrf_drv_timer_t const * const p_instance,
- nrf_timer_cc_channel_t cc_channel);
-
-/**
- * @brief Function for setting the timer channel in compare mode.
- *
- * @param[in] p_instance Timer instance.
- * @param[in] cc_channel Compare channel number.
- * @param[in] cc_value Compare value.
- * @param[in] enable_int Enable or disable the interrupt for the compare 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);
-
-/**
- * @brief Function for setting the timer channel in extended compare mode.
- *
- * @param[in] p_instance Timer instance.
- * @param[in] cc_channel Compare channel number.
- * @param[in] cc_value Compare value.
- * @param[in] timer_short_mask Shortcut between the compare event on the channel
- * and the timer task (STOP or CLEAR).
- * @param[in] enable_int Enable or disable the interrupt for the compare
- * channel.
- */
-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);
-
-/**
- * @brief Function for converting time in microseconds to timer ticks.
- *
- * @param[in] p_instance Timer instance.
- * @param[in] time_us Time in microseconds.
- *
- * @return Number of ticks.
- */
-__STATIC_INLINE uint32_t nrf_drv_timer_us_to_ticks(
- nrf_drv_timer_t const * const p_instance,
- uint32_t time_us);
-
-/**
- * @brief Function for converting time in milliseconds to timer ticks.
- *
- * @param[in] p_instance Timer instance.
- * @param[in] time_ms Time in milliseconds.
- *
- * @return Number of ticks.
- */
-__STATIC_INLINE uint32_t nrf_drv_timer_ms_to_ticks(
- nrf_drv_timer_t const * const p_instance,
- uint32_t time_ms);
-
-/**
- * @brief Function for enabling timer compare interrupt.
- *
- * @param[in] p_instance Timer instance.
- * @param[in] channel Compare channel.
- */
-void nrf_drv_timer_compare_int_enable(nrf_drv_timer_t const * const p_instance,
- uint32_t channel);
-
-/**
- * @brief Function for disabling timer compare interrupt.
- *
- * @param[in] p_instance Timer instance.
- * @param[in] channel Compare channel.
- */
-void nrf_drv_timer_compare_int_disable(nrf_drv_timer_t const * const p_instance,
- uint32_t channel);
-
-
-#ifndef SUPPRESS_INLINE_IMPLEMENTATION
-
-__STATIC_INLINE uint32_t nrf_drv_timer_task_address_get(
- nrf_drv_timer_t const * const p_instance,
- nrf_timer_task_t timer_task)
-{
- return (uint32_t)nrf_timer_task_address_get(p_instance->p_reg, timer_task);
-}
-
-__STATIC_INLINE uint32_t nrf_drv_timer_capture_task_address_get(
- nrf_drv_timer_t const * const p_instance,
- uint32_t channel)
-{
- ASSERT(channel < p_instance->cc_channel_count);
- return (uint32_t)nrf_timer_task_address_get(p_instance->p_reg,
- nrf_timer_capture_task_get(channel));
-}
-
-__STATIC_INLINE uint32_t nrf_drv_timer_event_address_get(
- nrf_drv_timer_t const * const p_instance,
- nrf_timer_event_t timer_event)
-{
- return (uint32_t)nrf_timer_event_address_get(p_instance->p_reg, timer_event);
-}
-
-__STATIC_INLINE uint32_t nrf_drv_timer_compare_event_address_get(
- nrf_drv_timer_t const * const p_instance,
- uint32_t channel)
-{
- ASSERT(channel < p_instance->cc_channel_count);
- return (uint32_t)nrf_timer_event_address_get(p_instance->p_reg,
- nrf_timer_compare_event_get(channel));
-}
-
-__STATIC_INLINE uint32_t nrf_drv_timer_capture_get(
- nrf_drv_timer_t const * const p_instance,
- nrf_timer_cc_channel_t cc_channel)
-{
- return nrf_timer_cc_read(p_instance->p_reg, cc_channel);
-}
-
-__STATIC_INLINE uint32_t nrf_drv_timer_us_to_ticks(
- nrf_drv_timer_t const * const p_instance,
- uint32_t timer_us)
-{
- return nrf_timer_us_to_ticks(timer_us,
- nrf_timer_frequency_get(p_instance->p_reg));
-}
-
-__STATIC_INLINE uint32_t nrf_drv_timer_ms_to_ticks(
- nrf_drv_timer_t const * const p_instance,
- uint32_t timer_ms)
-{
- return nrf_timer_ms_to_ticks(timer_ms,
- nrf_timer_frequency_get(p_instance->p_reg));
-}
-
-#endif // SUPPRESS_INLINE_IMPLEMENTATION
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // NRF_DRV_TIMER_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/twi_master/deprecated/config/twi_master_config.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/twi_master/deprecated/config/twi_master_config.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/twi_master/deprecated/config/twi_master_config.h
deleted file mode 100644
index 7d2b169..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/twi_master/deprecated/config/twi_master_config.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is property of Nordic Semiconductor ASA.
- * Terms and conditions of usage are described in detail in NORDIC
- * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
-#ifndef TWI_MASTER_CONFIG
-#define TWI_MASTER_CONFIG
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER (24U)
-#define TWI_MASTER_CONFIG_DATA_PIN_NUMBER (25U)
-
-#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/twi_master/deprecated/twi_hw_master.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/twi_master/deprecated/twi_hw_master.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/twi_master/deprecated/twi_hw_master.c
deleted file mode 100644
index bf54bb7..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/twi_master/deprecated/twi_hw_master.c
+++ /dev/null
@@ -1,304 +0,0 @@
-/* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is property of Nordic Semiconductor ASA.
- * Terms and conditions of usage are described in detail in NORDIC
- * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
-
-#include "twi_master.h"
-#include "twi_master_config.h"
-#include <stdbool.h>
-#include <stdint.h>
-#include "nrf.h"
-#include "nrf_delay.h"
-#include "nrf_gpio.h"
-
-/* Max cycles approximately to wait on RXDREADY and TXDREADY event,
- * This is optimized way instead of using timers, this is not power aware. */
-#define MAX_TIMEOUT_LOOPS (20000UL) /**< MAX while loops to wait for RXD/TXD event */
-
-static bool twi_master_write(uint8_t * data, uint8_t data_length, bool issue_stop_condition)
-{
- uint32_t timeout = MAX_TIMEOUT_LOOPS; /* max loops to wait for EVENTS_TXDSENT event*/
-
- if (data_length == 0)
- {
- /* Return false for requesting data of size 0 */
- return false;
- }
-
- NRF_TWI1->TXD = *data++;
- NRF_TWI1->TASKS_STARTTX = 1;
-
- /** @snippet [TWI HW master write] */
- while (true)
- {
- while (NRF_TWI1->EVENTS_TXDSENT == 0 && NRF_TWI1->EVENTS_ERROR == 0 && (--timeout))
- {
- // Do nothing.
- }
-
- if (timeout == 0 || NRF_TWI1->EVENTS_ERROR != 0)
- {
- // Recover the peripheral as indicated by PAN 56: "TWI: TWI module lock-up." found at
- // Product Anomaly Notification document found at
- // https://www.nordicsemi.com/eng/Products/Bluetooth-R-low-energy/nRF51822/#Downloads
- NRF_TWI1->EVENTS_ERROR = 0;
- NRF_TWI1->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
- NRF_TWI1->POWER = 0;
- nrf_delay_us(5);
- NRF_TWI1->POWER = 1;
- NRF_TWI1->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
-
- (void)twi_master_init();
-
- return false;
- }
- NRF_TWI1->EVENTS_TXDSENT = 0;
- if (--data_length == 0)
- {
- break;
- }
-
- NRF_TWI1->TXD = *data++;
- }
- /** @snippet [TWI HW master write] */
-
- if (issue_stop_condition)
- {
- NRF_TWI1->EVENTS_STOPPED = 0;
- NRF_TWI1->TASKS_STOP = 1;
- /* Wait until stop sequence is sent */
- while(NRF_TWI1->EVENTS_STOPPED == 0)
- {
- // Do nothing.
- }
- }
- return true;
-}
-
-
-/** @brief Function for read by twi_master.
- */
-static bool twi_master_read(uint8_t * data, uint8_t data_length, bool issue_stop_condition)
-{
- uint32_t timeout = MAX_TIMEOUT_LOOPS; /* max loops to wait for RXDREADY event*/
-
- if (data_length == 0)
- {
- /* Return false for requesting data of size 0 */
- return false;
- }
- else if (data_length == 1)
- {
- NRF_PPI->CH[0].TEP = (uint32_t)&NRF_TWI1->TASKS_STOP;
- }
- else
- {
- NRF_PPI->CH[0].TEP = (uint32_t)&NRF_TWI1->TASKS_SUSPEND;
- }
-
- NRF_PPI->CHENSET = PPI_CHENSET_CH0_Msk;
- NRF_TWI1->EVENTS_RXDREADY = 0;
- NRF_TWI1->TASKS_STARTRX = 1;
-
- /** @snippet [TWI HW master read] */
- while (true)
- {
- while (NRF_TWI1->EVENTS_RXDREADY == 0 && NRF_TWI1->EVENTS_ERROR == 0 && (--timeout))
- {
- // Do nothing.
- }
- NRF_TWI1->EVENTS_RXDREADY = 0;
-
- if (timeout == 0 || NRF_TWI1->EVENTS_ERROR != 0)
- {
- // Recover the peripheral as indicated by PAN 56: "TWI: TWI module lock-up." found at
- // Product Anomaly Notification document found at
- // https://www.nordicsemi.com/eng/Products/Bluetooth-R-low-energy/nRF51822/#Downloads
- NRF_TWI1->EVENTS_ERROR = 0;
- NRF_TWI1->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
- NRF_TWI1->POWER = 0;
- nrf_delay_us(5);
- NRF_TWI1->POWER = 1;
- NRF_TWI1->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
-
- (void)twi_master_init();
-
- return false;
- }
-
- *data++ = NRF_TWI1->RXD;
-
- /* Configure PPI to stop TWI master before we get last BB event */
- if (--data_length == 1)
- {
- NRF_PPI->CH[0].TEP = (uint32_t)&NRF_TWI1->TASKS_STOP;
- }
-
- if (data_length == 0)
- {
- break;
- }
-
- // Recover the peripheral as indicated by PAN 56: "TWI: TWI module lock-up." found at
- // Product Anomaly Notification document found at
- // https://www.nordicsemi.com/eng/Products/Bluetooth-R-low-energy/nRF51822/#Downloads
- nrf_delay_us(20);
- NRF_TWI1->TASKS_RESUME = 1;
- }
- /** @snippet [TWI HW master read] */
-
- /* Wait until stop sequence is sent */
- while(NRF_TWI1->EVENTS_STOPPED == 0)
- {
- // Do nothing.
- }
- NRF_TWI1->EVENTS_STOPPED = 0;
-
- NRF_PPI->CHENCLR = PPI_CHENCLR_CH0_Msk;
- return true;
-}
-
-
-/**
- * @brief Function for detecting stuck slaves (SDA = 0 and SCL = 1) and tries to clear the bus.
- *
- * @return
- * @retval false Bus is stuck.
- * @retval true Bus is clear.
- */
-static bool twi_master_clear_bus(void)
-{
- uint32_t twi_state;
- bool bus_clear;
- uint32_t clk_pin_config;
- uint32_t data_pin_config;
-
- // Save and disable TWI hardware so software can take control over the pins.
- twi_state = NRF_TWI1->ENABLE;
- NRF_TWI1->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
-
- clk_pin_config = \
- NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER];
- NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER] = \
- (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \
- | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) \
- | (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) \
- | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) \
- | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
-
- data_pin_config = \
- NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_DATA_PIN_NUMBER];
- NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_DATA_PIN_NUMBER] = \
- (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \
- | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) \
- | (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) \
- | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) \
- | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
-
- TWI_SDA_HIGH();
- TWI_SCL_HIGH();
- TWI_DELAY();
-
- if ((TWI_SDA_READ() == 1) && (TWI_SCL_READ() == 1))
- {
- bus_clear = true;
- }
- else
- {
- uint_fast8_t i;
- bus_clear = false;
-
- // Clock max 18 pulses worst case scenario(9 for master to send the rest of command and 9
- // for slave to respond) to SCL line and wait for SDA come high.
- for (i=18; i--;)
- {
- TWI_SCL_LOW();
- TWI_DELAY();
- TWI_SCL_HIGH();
- TWI_DELAY();
-
- if (TWI_SDA_READ() == 1)
- {
- bus_clear = true;
- break;
- }
- }
- }
-
- NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER] = clk_pin_config;
- NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_DATA_PIN_NUMBER] = data_pin_config;
-
- NRF_TWI1->ENABLE = twi_state;
-
- return bus_clear;
-}
-
-
-/** @brief Function for initializing the twi_master.
- */
-bool twi_master_init(void)
-{
- /* To secure correct signal levels on the pins used by the TWI
- master when the system is in OFF mode, and when the TWI master is
- disabled, these pins must be configured in the GPIO peripheral.
- */
- NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER] = \
- (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \
- | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) \
- | (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) \
- | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) \
- | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
-
- NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_DATA_PIN_NUMBER] = \
- (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \
- | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) \
- | (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) \
- | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) \
- | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
-
- NRF_TWI1->EVENTS_RXDREADY = 0;
- NRF_TWI1->EVENTS_TXDSENT = 0;
- NRF_TWI1->PSELSCL = TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER;
- NRF_TWI1->PSELSDA = TWI_MASTER_CONFIG_DATA_PIN_NUMBER;
- NRF_TWI1->FREQUENCY = TWI_FREQUENCY_FREQUENCY_K100 << TWI_FREQUENCY_FREQUENCY_Pos;
- NRF_PPI->CH[0].EEP = (uint32_t)&NRF_TWI1->EVENTS_BB;
- NRF_PPI->CH[0].TEP = (uint32_t)&NRF_TWI1->TASKS_SUSPEND;
- NRF_PPI->CHENCLR = PPI_CHENCLR_CH0_Msk;
- NRF_TWI1->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
-
- return twi_master_clear_bus();
-}
-
-
-/** @brief Function for transfer by twi_master.
- */
-bool twi_master_transfer(uint8_t address,
- uint8_t * data,
- uint8_t data_length,
- bool issue_stop_condition)
-{
- bool transfer_succeeded = false;
- if (data_length > 0 && twi_master_clear_bus())
- {
- NRF_TWI1->ADDRESS = (address >> 1);
-
- if ((address & TWI_READ_BIT))
- {
- transfer_succeeded = twi_master_read(data, data_length, issue_stop_condition);
- }
- else
- {
- transfer_succeeded = twi_master_write(data, data_length, issue_stop_condition);
- }
- }
- return transfer_succeeded;
-}
-
-/*lint --flb "Leave library region" */
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/twi_master/deprecated/twi_master.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/twi_master/deprecated/twi_master.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/twi_master/deprecated/twi_master.h
deleted file mode 100644
index 2ac62cc..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/twi_master/deprecated/twi_master.h
+++ /dev/null
@@ -1,109 +0,0 @@
- /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is property of Nordic Semiconductor ASA.
- * Terms and conditions of usage are described in detail in NORDIC
- * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
-
-#ifndef TWI_MASTER_H
-#define TWI_MASTER_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*lint ++flb "Enter library region" */
-
-#include <stdbool.h>
-#include <stdint.h>
-
-/** @file
-* @brief Software controlled TWI Master driver.
-*
-*
-* @defgroup lib_driver_twi_master Software controlled TWI Master driver
-* @{
-* @ingroup nrf_twi
-* @brief Software controlled TWI Master driver (deprecated).
-*
-* @warning This module is deprecated.
-*
-* Supported features:
-* - Repeated start
-* - No multi-master
-* - Only 7-bit addressing
-* - Supports clock stretching (with optional SMBus style slave timeout)
-* - Tries to handle slaves stuck in the middle of transfer
-*/
-
-#define TWI_READ_BIT (0x01) //!< If this bit is set in the address field, transfer direction is from slave to master.
-
-#define TWI_ISSUE_STOP ((bool)true) //!< Parameter for @ref twi_master_transfer
-#define TWI_DONT_ISSUE_STOP ((bool)false) //!< Parameter for @ref twi_master_transfer
-
-/* These macros are needed to see if the slave is stuck and we as master send dummy clock cycles to end its wait */
-/*lint -e717 -save "Suppress do {} while (0) for these macros" */
-/*lint ++flb "Enter library region" */
-#define TWI_SCL_HIGH() do { NRF_GPIO->OUTSET = (1UL << TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER); } while(0) /*!< Pulls SCL line high */
-#define TWI_SCL_LOW() do { NRF_GPIO->OUTCLR = (1UL << TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER); } while(0) /*!< Pulls SCL line low */
-#define TWI_SDA_HIGH() do { NRF_GPIO->OUTSET = (1UL << TWI_MASTER_CONFIG_DATA_PIN_NUMBER); } while(0) /*!< Pulls SDA line high */
-#define TWI_SDA_LOW() do { NRF_GPIO->OUTCLR = (1UL << TWI_MASTER_CONFIG_DATA_PIN_NUMBER); } while(0) /*!< Pulls SDA line low */
-#define TWI_SDA_INPUT() do { NRF_GPIO->DIRCLR = (1UL << TWI_MASTER_CONFIG_DATA_PIN_NUMBER); } while(0) /*!< Configures SDA pin as input */
-#define TWI_SDA_OUTPUT() do { NRF_GPIO->DIRSET = (1UL << TWI_MASTER_CONFIG_DATA_PIN_NUMBER); } while(0) /*!< Configures SDA pin as output */
-#define TWI_SCL_OUTPUT() do { NRF_GPIO->DIRSET = (1UL << TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER); } while(0) /*!< Configures SCL pin as output */
-/*lint -restore */
-
-#define TWI_SDA_READ() ((NRF_GPIO->IN >> TWI_MASTER_CONFIG_DATA_PIN_NUMBER) & 0x1UL) /*!< Reads current state of SDA */
-#define TWI_SCL_READ() ((NRF_GPIO->IN >> TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER) & 0x1UL) /*!< Reads current state of SCL */
-
-#define TWI_DELAY() nrf_delay_us(4) /*!< Time to wait when pin states are changed. For fast-mode the delay can be zero and for standard-mode 4 us delay is sufficient. */
-
-
-/**
- * @brief Function for initializing TWI bus IO pins and checks if the bus is operational.
- *
- * Both pins are configured as Standard-0, No-drive-1 (open drain).
- *
- * @return
- * @retval true TWI bus is clear for transfers.
- * @retval false TWI bus is stuck.
- */
-bool twi_master_init(void);
-
-/**
- * @brief Function for transferring data over TWI bus.
- *
- * If TWI master detects even one NACK from the slave or timeout occurs, STOP condition is issued
- * and the function returns false.
- * Bit 0 (@ref TWI_READ_BIT) in the address parameter controls transfer direction;
- * - If 1, master reads data_length number of bytes from the slave
- * - If 0, master writes data_length number of bytes to the slave.
- *
- * @note Make sure at least data_length number of bytes is allocated in data if TWI_READ_BIT is set.
- * @note @ref TWI_ISSUE_STOP
- *
- * @param address Data transfer direction (LSB) / Slave address (7 MSBs).
- * @param data Pointer to data.
- * @param data_length Number of bytes to transfer.
- * @param issue_stop_condition If @ref TWI_ISSUE_STOP, STOP condition is issued before exiting function. If @ref TWI_DONT_ISSUE_STOP, STOP condition is not issued before exiting function. If transfer failed for any reason, STOP condition will be issued in any case.
- * @return
- * @retval true Data transfer succeeded without errors.
- * @retval false Data transfer failed.
- */
-bool twi_master_transfer(uint8_t address, uint8_t *data, uint8_t data_length, bool issue_stop_condition);
-
-/**
- *@}
- **/
-
-/*lint --flb "Leave library region" */
-#ifdef __cplusplus
-}
-#endif
-
-#endif //TWI_MASTER_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/twi_master/deprecated/twi_sw_master.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/twi_master/deprecated/twi_sw_master.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/twi_master/deprecated/twi_sw_master.c
deleted file mode 100644
index cbd1432..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/twi_master/deprecated/twi_sw_master.c
+++ /dev/null
@@ -1,492 +0,0 @@
-/* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is property of Nordic Semiconductor ASA.
- * Terms and conditions of usage are described in detail in NORDIC
- * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
-
-#include <stdbool.h>
-#include <stdint.h>
-#include "twi_master.h"
-#include "nrf_delay.h"
-
-#include "twi_master_config.h"
-
-/*lint -e415 -e845 -save "Out of bounds access" */
-#define TWI_SDA_STANDARD0_NODRIVE1() do { \
- NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_DATA_PIN_NUMBER] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \
- |(GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) \
- |(GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) \
- |(GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) \
- |(GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); \
-} while (0) /*!< Configures SDA pin to Standard-0, No-drive 1 */
-
-
-#define TWI_SCL_STANDARD0_NODRIVE1() do { \
- NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \
- |(GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) \
- |(GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) \
- |(GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) \
- |(GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); \
-} while (0) /*!< Configures SCL pin to Standard-0, No-drive 1 */
-
-
-/*lint -restore */
-
-#ifndef TWI_MASTER_TIMEOUT_COUNTER_LOAD_VALUE
-#define TWI_MASTER_TIMEOUT_COUNTER_LOAD_VALUE (0UL) //!< Unit is number of empty loops. Timeout for SMBus devices is 35 ms. Set to zero to disable slave timeout altogether.
-#endif
-
-static bool twi_master_clear_bus(void);
-static bool twi_master_issue_startcondition(void);
-static bool twi_master_issue_stopcondition(void);
-static bool twi_master_clock_byte(uint_fast8_t databyte);
-static bool twi_master_clock_byte_in(uint8_t * databyte, bool ack);
-static bool twi_master_wait_while_scl_low(void);
-
-bool twi_master_init(void)
-{
- // Configure both pins to output Standard 0, No-drive (open-drain) 1
- TWI_SDA_STANDARD0_NODRIVE1(); /*lint !e416 "Creation of out of bounds pointer" */
- TWI_SCL_STANDARD0_NODRIVE1(); /*lint !e416 "Creation of out of bounds pointer" */
-
- // Configure SCL as output
- TWI_SCL_HIGH();
- TWI_SCL_OUTPUT();
-
- // Configure SDA as output
- TWI_SDA_HIGH();
- TWI_SDA_OUTPUT();
-
- return twi_master_clear_bus();
-}
-
-bool twi_master_transfer(uint8_t address, uint8_t * data, uint8_t data_length, bool issue_stop_condition)
-{
- bool transfer_succeeded = true;
-
- transfer_succeeded &= twi_master_issue_startcondition();
- transfer_succeeded &= twi_master_clock_byte(address);
-
- if (address & TWI_READ_BIT)
- {
- /* Transfer direction is from Slave to Master */
- while (data_length-- && transfer_succeeded)
- {
- // To indicate to slave that we've finished transferring last data byte
- // we need to NACK the last transfer.
- if (data_length == 0)
- {
- transfer_succeeded &= twi_master_clock_byte_in(data, (bool)false);
- }
- else
- {
- transfer_succeeded &= twi_master_clock_byte_in(data, (bool)true);
- }
- data++;
- }
- }
- else
- {
- /* Transfer direction is from Master to Slave */
- while (data_length-- && transfer_succeeded)
- {
- transfer_succeeded &= twi_master_clock_byte(*data);
- data++;
- }
- }
-
- if (issue_stop_condition || !transfer_succeeded)
- {
- transfer_succeeded &= twi_master_issue_stopcondition();
- }
-
- return transfer_succeeded;
-}
-
-/**
- * @brief Function for detecting stuck slaves and tries to clear the bus.
- *
- * @return
- * @retval false Bus is stuck.
- * @retval true Bus is clear.
- */
-static bool twi_master_clear_bus(void)
-{
- bool bus_clear;
-
- TWI_SDA_HIGH();
- TWI_SCL_HIGH();
- TWI_DELAY();
-
-
- if (TWI_SDA_READ() == 1 && TWI_SCL_READ() == 1)
- {
- bus_clear = true;
- }
- else if (TWI_SCL_READ() == 1)
- {
- bus_clear = false;
- // Clock max 18 pulses worst case scenario(9 for master to send the rest of command and 9 for slave to respond) to SCL line and wait for SDA come high
- for (uint_fast8_t i = 18; i--;)
- {
- TWI_SCL_LOW();
- TWI_DELAY();
- TWI_SCL_HIGH();
- TWI_DELAY();
-
- if (TWI_SDA_READ() == 1)
- {
- bus_clear = true;
- break;
- }
- }
- }
- else
- {
- bus_clear = false;
- }
-
- return bus_clear;
-}
-
-/**
- * @brief Function for issuing TWI START condition to the bus.
- *
- * START condition is signaled by pulling SDA low while SCL is high. After this function SCL and SDA will be low.
- *
- * @return
- * @retval false Timeout detected
- * @retval true Clocking succeeded
- */
-static bool twi_master_issue_startcondition(void)
-{
-#if 0
- if (TWI_SCL_READ() == 1 && TWI_SDA_READ() == 1)
- {
- // Pull SDA low
- TWI_SDA_LOW();
- }
- else if (TWI_SCL_READ() == 1 && TWI_SDA_READ() == 0)
- {
- // Issue Stop by pulling SDA high
- TWI_SDA_HIGH();
- TWI_DELAY();
-
- // Then Start by pulling SDA low
- TWI_SDA_LOW();
- }
- else if (TWI_SCL_READ() == 0 && TWI_SDA_READ() == 0)
- {
- // First pull SDA high
- TWI_SDA_HIGH();
-
- // Then SCL high
- if (!twi_master_wait_while_scl_low())
- {
- return false;
- }
-
- // Then SDA low
- TWI_SDA_LOW();
- }
- else if (TWI_SCL_READ() == 0 && TWI_SDA_READ() == 1)
- {
- // SCL high
- if (!twi_master_wait_while_scl_low())
- {
- return false;
- }
-
- // Then SDA low
- TWI_SDA_LOW();
- }
-
- TWI_DELAY();
- TWI_SCL_LOW();
-#endif
-
- // Make sure both SDA and SCL are high before pulling SDA low.
- TWI_SDA_HIGH();
- TWI_DELAY();
- if (!twi_master_wait_while_scl_low())
- {
- return false;
- }
-
- TWI_SDA_LOW();
- TWI_DELAY();
-
- // Other module function expect SCL to be low
- TWI_SCL_LOW();
- TWI_DELAY();
-
- return true;
-}
-
-/**
- * @brief Function for issuing TWI STOP condition to the bus.
- *
- * STOP condition is signaled by pulling SDA high while SCL is high. After this function SDA and SCL will be high.
- *
- * @return
- * @retval false Timeout detected
- * @retval true Clocking succeeded
- */
-static bool twi_master_issue_stopcondition(void)
-{
-#if 0
- if (TWI_SCL_READ() == 1 && TWI_SDA_READ() == 1)
- {
- // Issue start, then issue stop
-
- // Pull SDA low to issue START
- TWI_SDA_LOW();
- TWI_DELAY();
-
- // Pull SDA high while SCL is high to issue STOP
- TWI_SDA_HIGH();
- }
- else if (TWI_SCL_READ() == 1 && TWI_SDA_READ() == 0)
- {
- // Pull SDA high while SCL is high to issue STOP
- TWI_SDA_HIGH();
- }
- else if (TWI_SCL_READ() == 0 && TWI_SDA_READ() == 0)
- {
- if (!twi_master_wait_while_scl_low())
- {
- return false;
- }
-
- // Pull SDA high while SCL is high to issue STOP
- TWI_SDA_HIGH();
- }
- else if (TWI_SCL_READ() == 0 && TWI_SDA_READ() == 1)
- {
- TWI_SDA_LOW();
- TWI_DELAY();
-
- // SCL high
- if (!twi_master_wait_while_scl_low())
- {
- return false;
- }
-
- // Pull SDA high while SCL is high to issue STOP
- TWI_SDA_HIGH();
- }
-
- TWI_DELAY();
-#endif
-
- TWI_SDA_LOW();
- TWI_DELAY();
- if (!twi_master_wait_while_scl_low())
- {
- return false;
- }
-
- TWI_SDA_HIGH();
- TWI_DELAY();
-
- return true;
-}
-
-/**
- * @brief Function for clocking one data byte out and reads slave acknowledgment.
- *
- * Can handle clock stretching.
- * After calling this function SCL is low and SDA low/high depending on the
- * value of LSB of the data byte.
- * SCL is expected to be output and low when entering this function.
- *
- * @param databyte Data byte to clock out.
- * @return
- * @retval true Slave acknowledged byte.
- * @retval false Timeout or slave didn't acknowledge byte.
- */
-static bool twi_master_clock_byte(uint_fast8_t databyte)
-{
- bool transfer_succeeded = true;
-
- /** @snippet [TWI SW master write] */
- // Make sure SDA is an output
- TWI_SDA_OUTPUT();
-
- // MSB first
- for (uint_fast8_t i = 0x80; i != 0; i >>= 1)
- {
- TWI_SCL_LOW();
- TWI_DELAY();
-
- if (databyte & i)
- {
- TWI_SDA_HIGH();
- }
- else
- {
- TWI_SDA_LOW();
- }
-
- if (!twi_master_wait_while_scl_low())
- {
- transfer_succeeded = false; // Timeout
- break;
- }
- }
-
- // Finish last data bit by pulling SCL low
- TWI_SCL_LOW();
- TWI_DELAY();
-
- /** @snippet [TWI SW master write] */
-
- // Configure TWI_SDA pin as input for receiving the ACK bit
- TWI_SDA_INPUT();
-
- // Give some time for the slave to load the ACK bit on the line
- TWI_DELAY();
-
- // Pull SCL high and wait a moment for SDA line to settle
- // Make sure slave is not stretching the clock
- transfer_succeeded &= twi_master_wait_while_scl_low();
-
- // Read ACK/NACK. NACK == 1, ACK == 0
- transfer_succeeded &= !(TWI_SDA_READ());
-
- // Finish ACK/NACK bit clock cycle and give slave a moment to release control
- // of the SDA line
- TWI_SCL_LOW();
- TWI_DELAY();
-
- // Configure TWI_SDA pin as output as other module functions expect that
- TWI_SDA_OUTPUT();
-
- return transfer_succeeded;
-}
-
-
-/**
- * @brief Function for clocking one data byte in and sends ACK/NACK bit.
- *
- * Can handle clock stretching.
- * SCL is expected to be output and low when entering this function.
- * After calling this function, SCL is high and SDA low/high depending if ACK/NACK was sent.
- *
- * @param databyte Data byte to clock out.
- * @param ack If true, send ACK. Otherwise send NACK.
- * @return
- * @retval true Byte read succesfully
- * @retval false Timeout detected
- */
-static bool twi_master_clock_byte_in(uint8_t *databyte, bool ack)
-{
- uint_fast8_t byte_read = 0;
- bool transfer_succeeded = true;
-
- /** @snippet [TWI SW master read] */
- // Make sure SDA is an input
- TWI_SDA_INPUT();
-
- // SCL state is guaranteed to be high here
-
- // MSB first
- for (uint_fast8_t i = 0x80; i != 0; i >>= 1)
- {
- if (!twi_master_wait_while_scl_low())
- {
- transfer_succeeded = false;
- break;
- }
-
- if (TWI_SDA_READ())
- {
- byte_read |= i;
- }
- else
- {
- // No need to do anything
- }
-
- TWI_SCL_LOW();
- TWI_DELAY();
- }
-
- // Make sure SDA is an output before we exit the function
- TWI_SDA_OUTPUT();
- /** @snippet [TWI SW master read] */
-
- *databyte = (uint8_t)byte_read;
-
- // Send ACK bit
-
- // SDA high == NACK, SDA low == ACK
- if (ack)
- {
- TWI_SDA_LOW();
- }
- else
- {
- TWI_SDA_HIGH();
- }
-
- // Let SDA line settle for a moment
- TWI_DELAY();
-
- // Drive SCL high to start ACK/NACK bit transfer
- // Wait until SCL is high, or timeout occurs
- if (!twi_master_wait_while_scl_low())
- {
- transfer_succeeded = false; // Timeout
- }
-
- // Finish ACK/NACK bit clock cycle and give slave a moment to react
- TWI_SCL_LOW();
- TWI_DELAY();
-
- return transfer_succeeded;
-}
-
-
-/**
- * @brief Function for pulling SCL high and waits until it is high or timeout occurs.
- *
- * SCL is expected to be output before entering this function.
- * @note If TWI_MASTER_TIMEOUT_COUNTER_LOAD_VALUE is set to zero, timeout functionality is not compiled in.
- * @return
- * @retval true SCL is now high.
- * @retval false Timeout occurred and SCL is still low.
- */
-static bool twi_master_wait_while_scl_low(void)
-{
-#if TWI_MASTER_TIMEOUT_COUNTER_LOAD_VALUE != 0
- uint32_t volatile timeout_counter = TWI_MASTER_TIMEOUT_COUNTER_LOAD_VALUE;
-#endif
-
- // Pull SCL high just in case if something left it low
- TWI_SCL_HIGH();
- TWI_DELAY();
-
- while (TWI_SCL_READ() == 0)
- {
- // If SCL is low, one of the slaves is busy and we must wait
-
-#if TWI_MASTER_TIMEOUT_COUNTER_LOAD_VALUE != 0
- if (timeout_counter-- == 0)
- {
- // If timeout_detected, return false
- return false;
- }
-#endif
- }
-
- return true;
-}
-
-/*lint --flb "Leave library region" */
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/twi_master/nrf_drv_twi.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/twi_master/nrf_drv_twi.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/twi_master/nrf_drv_twi.c
deleted file mode 100644
index 2a9c2e4..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/twi_master/nrf_drv_twi.c
+++ /dev/null
@@ -1,1014 +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_twi.h"
-#include "nrf_drv_common.h"
-#include "nrf_gpio.h"
-#include "nrf_assert.h"
-#include "app_util_platform.h"
-#include "nrf_delay.h"
-
-#include <stdio.h>
-
-#define TWI0_IRQ_HANDLER SPI0_TWI0_IRQHandler
-#define TWI1_IRQ_HANDLER SPI1_TWI1_IRQHandler
-
-#if (defined(TWIM_IN_USE) && defined(TWI_IN_USE))
- // TWIM and TWI combined
- #define CODE_FOR_TWIM(code) if (p_instance->use_easy_dma) { code }
- #define CODE_FOR_TWI(code) else { code }
-#elif (defined(TWIM_IN_USE) && !defined(TWI_IN_USE))
- // TWIM only
- #define CODE_FOR_TWIM(code) { code }
- #define CODE_FOR_TWI(code)
-#elif (!defined(TWIM_IN_USE) && defined(TWI_IN_USE))
- // TWI only
- #define CODE_FOR_TWIM(code)
- #define CODE_FOR_TWI(code) { code }
-#else
- #error "Wrong configuration."
-#endif
-
-// All interrupt flags
-#define DISABLE_ALL 0xFFFFFFFF
-
-#define SCL_PIN_CONF ((GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \
- | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) \
- | (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) \
- | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) \
- | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos))
-
-#define SDA_PIN_CONF SCL_PIN_CONF
-
-#define SCL_PIN_CONF_CLR ((GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \
- | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) \
- | (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) \
- | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) \
- | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos))
-
-#define SDA_PIN_CONF_CLR SCL_PIN_CONF_CLR
-
-// Control block - driver instance local data.
-typedef struct
-{
- nrf_drv_twi_evt_handler_t handler;
- void * p_context;
- volatile uint32_t int_mask;
- nrf_drv_twi_xfer_desc_t xfer_desc;
- uint32_t flags;
- uint8_t * p_curr_buf;
- uint8_t curr_length;
- bool curr_no_stop;
- nrf_drv_state_t state;
- bool error;
- volatile bool busy;
- bool repeated;
- uint8_t bytes_transferred;
-} twi_control_block_t;
-
-static twi_control_block_t m_cb[TWI_COUNT];
-
-static nrf_drv_twi_config_t const m_default_config[TWI_COUNT] = {
-#if TWI0_ENABLED
- NRF_DRV_TWI_DEFAULT_CONFIG(0),
-#endif
-#if TWI1_ENABLED
- NRF_DRV_TWI_DEFAULT_CONFIG(1),
-#endif
-};
-
-#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 TWI0_ENABLED
- IRQ_HANDLER(0);
- #endif
- #if TWI1_ENABLED
- IRQ_HANDLER(1);
- #endif
- static nrf_drv_irq_handler_t const m_irq_handlers[TWI_COUNT] = {
- #if TWI0_ENABLED
- IRQ_HANDLER_NAME(0),
- #endif
- #if TWI1_ENABLED
- IRQ_HANDLER_NAME(1),
- #endif
- };
-#else
- #define IRQ_HANDLER(n) void SPI##n##_TWI##n##_IRQHandler(void)
-#endif // PERIPHERAL_RESOURCE_SHARING_ENABLED
-
-static void twi_clear_bus(nrf_drv_twi_t const * const p_instance,
- nrf_drv_twi_config_t const * p_config)
-{
- NRF_GPIO->PIN_CNF[p_config->scl] = SCL_PIN_CONF;
- NRF_GPIO->PIN_CNF[p_config->sda] = SDA_PIN_CONF;
-
- nrf_gpio_pin_set(p_config->scl);
- nrf_gpio_pin_set(p_config->sda);
-
- NRF_GPIO->PIN_CNF[p_config->scl] = SCL_PIN_CONF_CLR;
- NRF_GPIO->PIN_CNF[p_config->sda] = SDA_PIN_CONF_CLR;
-
- nrf_delay_us(4);
-
- for(int i = 0; i < 9; i++)
- {
- if (nrf_gpio_pin_read(p_config->sda))
- {
- if(i == 0)
- {
- return;
- }
- else
- {
- break;
- }
- }
- nrf_gpio_pin_clear(p_config->scl);
- nrf_delay_us(4);
- nrf_gpio_pin_set(p_config->scl);
- nrf_delay_us(4);
- }
- nrf_gpio_pin_clear(p_config->sda);
- nrf_delay_us(4);
- nrf_gpio_pin_set(p_config->sda);
-}
-
-ret_code_t nrf_drv_twi_init(nrf_drv_twi_t const * p_instance,
- nrf_drv_twi_config_t const * p_config,
- nrf_drv_twi_evt_handler_t event_handler,
- void * p_context)
-{
- twi_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx];
-
- if (p_cb->state != NRF_DRV_STATE_UNINITIALIZED)
- {
- return NRF_ERROR_INVALID_STATE;
- }
-
- if (p_config == NULL)
- {
- p_config = &m_default_config[p_instance->drv_inst_idx];
- }
-
-#if PERIPHERAL_RESOURCE_SHARING_ENABLED
- if (nrf_drv_common_per_res_acquire(p_instance->reg.p_twi,
- m_irq_handlers[p_instance->drv_inst_idx]) != NRF_SUCCESS)
- {
- return NRF_ERROR_BUSY;
- }
-#endif // PERIPHERAL_RESOURCE_SHARING_ENABLED
-
- p_cb->handler = event_handler;
- p_cb->p_context = p_context;
- p_cb->int_mask = 0;
- p_cb->repeated = false;
- p_cb->busy = false;
-
- twi_clear_bus(p_instance, p_config);
-
- /* To secure correct signal levels on the pins used by the TWI
- master when the system is in OFF mode, and when the TWI master is
- disabled, these pins must be configured in the GPIO peripheral.
- */
- NRF_GPIO->PIN_CNF[p_config->scl] = SCL_PIN_CONF;
- NRF_GPIO->PIN_CNF[p_config->sda] = SDA_PIN_CONF;
-
- CODE_FOR_TWIM
- (
- NRF_TWIM_Type * p_twim = p_instance->reg.p_twim;
- nrf_twim_pins_set(p_twim, p_config->scl, p_config->sda);
- nrf_twim_frequency_set(p_twim,
- (nrf_twim_frequency_t)p_config->frequency);
- )
- CODE_FOR_TWI
- (
- NRF_TWI_Type * p_twi = p_instance->reg.p_twi;
- nrf_twi_pins_set(p_twi, p_config->scl, p_config->sda);
- nrf_twi_frequency_set(p_twi,
- (nrf_twi_frequency_t)p_config->frequency);
- )
-
- if (p_cb->handler)
- {
- CODE_FOR_TWIM
- (
- nrf_drv_common_irq_enable(nrf_drv_get_IRQn((void *)p_instance->reg.p_twim),
- p_config->interrupt_priority);
- )
- CODE_FOR_TWI
- (
- nrf_drv_common_irq_enable(nrf_drv_get_IRQn((void *)p_instance->reg.p_twi),
- p_config->interrupt_priority);
- )
- }
-
- p_cb->state = NRF_DRV_STATE_INITIALIZED;
-
- return NRF_SUCCESS;
-}
-
-void nrf_drv_twi_uninit(nrf_drv_twi_t const * p_instance)
-{
- twi_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx];
- ASSERT(p_cb->state != NRF_DRV_STATE_UNINITIALIZED);
-
- if (p_cb->handler)
- {
- CODE_FOR_TWIM
- (
- nrf_drv_common_irq_disable(nrf_drv_get_IRQn((void *)p_instance->reg.p_twim));
- )
- CODE_FOR_TWI
- (
- nrf_drv_common_irq_disable(nrf_drv_get_IRQn((void *)p_instance->reg.p_twi));
- )
- }
- nrf_drv_twi_disable(p_instance);
-
-#if PERIPHERAL_RESOURCE_SHARING_ENABLED
- nrf_drv_common_per_res_release(p_instance->reg.p_twi);
-#endif
-
- p_cb->state = NRF_DRV_STATE_UNINITIALIZED;
-}
-
-void nrf_drv_twi_enable(nrf_drv_twi_t const * p_instance)
-{
- twi_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx];
- ASSERT(p_cb->state == NRF_DRV_STATE_INITIALIZED);
-
- CODE_FOR_TWIM
- (
- NRF_TWIM_Type * p_twim = p_instance->reg.p_twim;
-
- nrf_twim_enable(p_twim);
- )
- CODE_FOR_TWI
- (
- NRF_TWI_Type * p_twi = p_instance->reg.p_twi;
-
- nrf_twi_enable(p_twi);
- )
-
- p_cb->state = NRF_DRV_STATE_POWERED_ON;
-}
-
-void nrf_drv_twi_disable(nrf_drv_twi_t const * p_instance)
-{
- twi_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx];
- ASSERT(p_cb->state != NRF_DRV_STATE_UNINITIALIZED);
-
- CODE_FOR_TWIM
- (
- NRF_TWIM_Type * p_twim = p_instance->reg.p_twim;
- p_cb->int_mask = 0;
- nrf_twim_int_disable(p_twim, DISABLE_ALL);
- nrf_twim_shorts_disable(p_twim, DISABLE_ALL);
- nrf_twim_disable(p_twim);
- )
- CODE_FOR_TWI
- (
- NRF_TWI_Type * p_twi = p_instance->reg.p_twi;
- nrf_twi_int_disable(p_twi, DISABLE_ALL);
- nrf_twi_shorts_disable(p_twi, DISABLE_ALL);
- nrf_twi_disable(p_twi);
- )
-
- p_cb->state = NRF_DRV_STATE_INITIALIZED;
-}
-
-#ifdef TWI_IN_USE
-static bool twi_send_byte(NRF_TWI_Type * p_twi,
- uint8_t const * p_data,
- uint8_t length,
- uint8_t * p_bytes_transferred,
- bool no_stop)
-{
- if (*p_bytes_transferred < length)
- {
- nrf_twi_txd_set(p_twi, p_data[*p_bytes_transferred]);
- ++(*p_bytes_transferred);
- }
- else
- {
- if (no_stop)
- {
- nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_SUSPEND);
- return false;
- }
- else
- {
- nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_STOP);
- }
- }
- return true;
-}
-
-static bool twi_receive_byte(NRF_TWI_Type * p_twi,
- uint8_t * p_data,
- uint8_t length,
- uint8_t * p_bytes_transferred,
- bool no_stop)
-{
- if (*p_bytes_transferred < length)
- {
- p_data[*p_bytes_transferred] = nrf_twi_rxd_get(p_twi);
-
- ++(*p_bytes_transferred);
-
- if ((*p_bytes_transferred == length-1) && !no_stop)
- {
- nrf_twi_shorts_set(p_twi, NRF_TWI_SHORT_BB_STOP_MASK);
- }
- else if (*p_bytes_transferred == length)
- {
- goto xfer_done;
- }
-
- nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_RESUME);
-
- return true;
- }
-
-xfer_done:
- if (no_stop) {
- return false;
- } else {
- return true;
- }
-}
-
-static bool twi_transfer(NRF_TWI_Type * p_twi,
- bool * p_error,
- uint8_t * p_bytes_transferred,
- uint8_t * p_data,
- uint8_t length,
- bool no_stop)
-{
- bool do_stop_check;
-
- if ((*p_error == true) || (*p_bytes_transferred == length))
- {
- do_stop_check = true;
- }
- else
- {
- do_stop_check = false;
- }
-
- if (*p_error)
- {
- nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_ERROR);
- nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_TXDSENT);
- nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_RXDREADY);
- }
- else if (nrf_twi_event_check(p_twi, NRF_TWI_EVENT_ERROR))
- {
- nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_ERROR);
- nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_STOP);
- *p_error = true;
- }
- else
- {
- if (nrf_twi_event_check(p_twi, NRF_TWI_EVENT_TXDSENT))
- {
- nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_TXDSENT);
- if (nrf_twi_event_check(p_twi, NRF_TWI_EVENT_ERROR))
- {
- nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_ERROR);
- nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_STOP);
- *p_error = true;
- }
- else
- {
- if (!twi_send_byte(p_twi, p_data, length, p_bytes_transferred, no_stop))
- {
- return false;
- }
- }
- }
- else if (nrf_twi_event_check(p_twi, NRF_TWI_EVENT_RXDREADY))
- {
- nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_RXDREADY);
- if (nrf_twi_event_check(p_twi, NRF_TWI_EVENT_ERROR))
- {
- nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_ERROR);
- nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_STOP);
- *p_error = true;
- }
- else
- {
- if (!twi_receive_byte(p_twi, p_data, length,
- p_bytes_transferred, no_stop))
- {
- return false;
- }
- }
- }
- }
-
- if (do_stop_check && nrf_twi_event_check(p_twi, NRF_TWI_EVENT_STOPPED))
- {
- nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_STOPPED);
- return false;
- }
-
- return true;
-}
-
-static ret_code_t twi_tx_start_transfer(twi_control_block_t * p_cb,
- NRF_TWI_Type * p_twi,
- uint8_t const * p_data,
- uint8_t length,
- bool no_stop)
-{
- ret_code_t ret_code = NRF_SUCCESS;
-
- nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_STOPPED);
- nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_ERROR);
- nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_TXDSENT);
- nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_RXDREADY);
- nrf_twi_shorts_set(p_twi, 0);
-
- p_cb->bytes_transferred = 0;
- p_cb->error = false;
-
- // In case TWI is suspended resume its operation.
- nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_RESUME);
- nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_STARTTX);
-
- (void)twi_send_byte(p_twi, p_data, length, &p_cb->bytes_transferred, no_stop);
-
- if (p_cb->handler)
- {
- p_cb->int_mask = NRF_TWI_INT_STOPPED_MASK |
- NRF_TWI_INT_ERROR_MASK |
- NRF_TWI_INT_TXDSENT_MASK |
- NRF_TWI_INT_RXDREADY_MASK;
- nrf_twi_int_enable(p_twi, p_cb->int_mask);
- }
- else
- {
- while (twi_transfer(p_twi, &p_cb->error, &p_cb->bytes_transferred, (uint8_t *)p_data, length, no_stop))
- {}
-
- if (p_cb->error)
- {
- ret_code = NRF_ERROR_INTERNAL;
- }
- }
- return ret_code;
-}
-
-static ret_code_t twi_rx_start_transfer(twi_control_block_t * p_cb,
- NRF_TWI_Type * p_twi,
- uint8_t const * p_data,
- uint8_t length)
-{
- bool no_stop;
- ret_code_t ret_code = NRF_SUCCESS;
-
- nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_STOPPED);
- nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_ERROR);
- nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_TXDSENT);
- nrf_twi_event_clear(p_twi, NRF_TWI_EVENT_RXDREADY);
-
- p_cb->bytes_transferred = 0;
- p_cb->error = false;
-
- if (p_cb->flags & NRF_DRV_TWI_FLAG_RX_NO_STOP)
- {
- no_stop = true;
- } else
- {
- no_stop = false;
- }
-
- if ((length == 1) && !no_stop)
- {
- nrf_twi_shorts_set(p_twi, NRF_TWI_SHORT_BB_STOP_MASK);
- }
- else
- {
- nrf_twi_shorts_set(p_twi, NRF_TWI_SHORT_BB_SUSPEND_MASK);
- }
- // In case TWI is suspended resume its operation.
- nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_RESUME);
- nrf_twi_task_trigger(p_twi, NRF_TWI_TASK_STARTRX);
-
- if (p_cb->handler)
- {
- p_cb->int_mask = NRF_TWI_INT_STOPPED_MASK |
- NRF_TWI_INT_ERROR_MASK |
- NRF_TWI_INT_TXDSENT_MASK |
- NRF_TWI_INT_RXDREADY_MASK;
- nrf_twi_int_enable(p_twi, p_cb->int_mask);
- }
- else
- {
- while (twi_transfer(p_twi, &p_cb->error, &p_cb->bytes_transferred,
- (uint8_t *)p_data, length, no_stop))
- {}
-
- if (p_cb->error)
- {
- ret_code = NRF_ERROR_INTERNAL;
- }
- }
- return ret_code;
-}
-
-__STATIC_INLINE ret_code_t twi_xfer(twi_control_block_t * p_cb,
- NRF_TWI_Type * p_twi,
- nrf_drv_twi_xfer_desc_t const * p_xfer_desc,
- uint32_t flags)
-{
- ret_code_t ret = NRF_SUCCESS;
-
- /* Block TWI interrupts to ensure that function is not interrupted by TWI interrupt. */
- nrf_twi_int_disable(p_twi, DISABLE_ALL);
-
- if (p_cb->busy)
- {
- nrf_twi_int_enable(p_twi, p_cb->int_mask);
- return NRF_ERROR_BUSY;
- }
- else
- {
- p_cb->busy = (NRF_DRV_TWI_FLAG_NO_XFER_EVT_HANDLER & flags) ? false : true;
- }
-
- if (flags & NRF_DRV_TWI_FLAG_HOLD_XFER)
- {
- return NRF_ERROR_NOT_SUPPORTED;
- }
-
- p_cb->flags = flags;
- p_cb->xfer_desc = *p_xfer_desc;
- p_cb->curr_length = p_xfer_desc->primary_length;
- p_cb->p_curr_buf = p_xfer_desc->p_primary_buf;
- nrf_twi_address_set(p_twi, p_xfer_desc->address);
-
- if (p_xfer_desc->type != NRF_DRV_TWI_XFER_RX)
- {
- p_cb->curr_no_stop = ((p_xfer_desc->type == NRF_DRV_TWI_XFER_TX) &&
- !(flags & NRF_DRV_TWI_FLAG_TX_NO_STOP)) ? false : true;
- ret = twi_tx_start_transfer(p_cb, p_twi, p_xfer_desc->p_primary_buf, p_xfer_desc->primary_length, p_cb->curr_no_stop);
- }
- else
- {
- p_cb->curr_no_stop = false;
- ret = twi_rx_start_transfer(p_cb, p_twi, p_xfer_desc->p_primary_buf, p_xfer_desc->primary_length);
- }
- if (p_cb->handler == NULL)
- {
- p_cb->busy = false;
- }
- return ret;
-}
-#endif
-
-#ifdef TWIM_IN_USE
-__STATIC_INLINE void twim_list_enable_handle(NRF_TWIM_Type * p_twim, uint32_t flags)
-{
- if (NRF_DRV_TWI_FLAG_TX_POSTINC & flags)
- {
- nrf_twim_tx_list_enable(p_twim);
- }
- else
- {
- nrf_twim_tx_list_disable(p_twim);
- }
-
- if (NRF_DRV_TWI_FLAG_RX_POSTINC & flags)
- {
- nrf_twim_rx_list_enable(p_twim);
- }
- else
- {
- nrf_twim_rx_list_disable(p_twim);
- }
-#ifndef NRF52_PAN_46
-#endif
-}
-__STATIC_INLINE ret_code_t twim_xfer(twi_control_block_t * p_cb,
- NRF_TWIM_Type * p_twim,
- nrf_drv_twi_xfer_desc_t const * p_xfer_desc,
- uint32_t flags)
-{
- ret_code_t ret = NRF_SUCCESS;
- nrf_twim_task_t start_task = NRF_TWIM_TASK_STARTTX;
- nrf_twim_event_t evt_to_wait = NRF_TWIM_EVENT_STOPPED;
-
- if (!nrf_drv_is_in_RAM(p_xfer_desc->p_primary_buf))
- {
- return NRF_ERROR_INVALID_ADDR;
- }
- /* Block TWI interrupts to ensure that function is not interrupted by TWI interrupt. */
- nrf_twim_int_disable(p_twim, DISABLE_ALL);
- if (p_cb->busy)
- {
- nrf_twim_int_enable(p_twim, p_cb->int_mask);
- return NRF_ERROR_BUSY;
- }
- else
- {
-
- p_cb->busy = ((NRF_DRV_TWI_FLAG_NO_XFER_EVT_HANDLER & flags) ||
- (NRF_DRV_TWI_FLAG_REPEATED_XFER & flags)) ? false: true;
- }
-
- p_cb->xfer_desc = *p_xfer_desc;
- p_cb->repeated = (flags & NRF_DRV_TWI_FLAG_REPEATED_XFER) ? true : false;
- nrf_twim_address_set(p_twim, p_xfer_desc->address);
-
- nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_STOPPED);
- nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_ERROR);
-
- twim_list_enable_handle(p_twim, flags);
- switch (p_xfer_desc->type)
- {
- case NRF_DRV_TWI_XFER_TXTX:
- ASSERT(!(flags & NRF_DRV_TWI_FLAG_REPEATED_XFER));
- ASSERT(!(flags & NRF_DRV_TWI_FLAG_HOLD_XFER));
- ASSERT(!(flags & NRF_DRV_TWI_FLAG_NO_XFER_EVT_HANDLER));
- if (!nrf_drv_is_in_RAM(p_xfer_desc->p_secondary_buf))
- {
- return NRF_ERROR_INVALID_ADDR;
- }
- nrf_twim_shorts_set(p_twim, NRF_TWIM_SHORT_LASTTX_SUSPEND_MASK);
- nrf_twim_tx_buffer_set(p_twim, p_xfer_desc->p_primary_buf, p_xfer_desc->primary_length);
- nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_TXSTARTED);
- nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_LASTTX);
- nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_SUSPENDED);
- nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_RESUME);
- nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_STARTTX);
- while(!nrf_twim_event_check(p_twim, NRF_TWIM_EVENT_TXSTARTED))
- {}
- nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_TXSTARTED);
- nrf_twim_tx_buffer_set(p_twim, p_xfer_desc->p_secondary_buf, p_xfer_desc->secondary_length);
- p_cb->int_mask = NRF_TWIM_INT_SUSPENDED_MASK | NRF_TWIM_INT_ERROR_MASK;
- break;
- case NRF_DRV_TWI_XFER_TXRX:
- nrf_twim_tx_buffer_set(p_twim, p_xfer_desc->p_primary_buf, p_xfer_desc->primary_length);
- nrf_twim_rx_buffer_set(p_twim, p_xfer_desc->p_secondary_buf, p_xfer_desc->secondary_length);
- nrf_twim_shorts_set(p_twim, NRF_TWIM_SHORT_LASTTX_STARTRX_MASK |
- NRF_TWIM_SHORT_LASTRX_STOP_MASK);
- p_cb->int_mask = NRF_TWIM_INT_STOPPED_MASK | NRF_TWIM_INT_ERROR_MASK;
- break;
- case NRF_DRV_TWI_XFER_TX:
- nrf_twim_tx_buffer_set(p_twim, p_xfer_desc->p_primary_buf, p_xfer_desc->primary_length);
- if (NRF_DRV_TWI_FLAG_TX_NO_STOP & flags)
- {
- nrf_twim_shorts_set(p_twim, NRF_TWIM_SHORT_LASTTX_SUSPEND_MASK);
- p_cb->int_mask = NRF_TWIM_INT_SUSPENDED_MASK | NRF_TWIM_INT_ERROR_MASK;
- nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_SUSPENDED);
- evt_to_wait = NRF_TWIM_EVENT_SUSPENDED;
- }
- else
- {
- nrf_twim_shorts_set(p_twim, NRF_TWIM_SHORT_LASTTX_STOP_MASK);
- p_cb->int_mask = NRF_TWIM_INT_STOPPED_MASK | NRF_TWIM_INT_ERROR_MASK;
- }
- nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_RESUME);
- break;
- case NRF_DRV_TWI_XFER_RX:
- nrf_twim_rx_buffer_set(p_twim, p_xfer_desc->p_primary_buf, p_xfer_desc->primary_length);
- nrf_twim_shorts_set(p_twim, NRF_TWIM_SHORT_LASTRX_STOP_MASK);
- p_cb->int_mask = NRF_TWIM_INT_STOPPED_MASK | NRF_TWIM_INT_ERROR_MASK;
- start_task = NRF_TWIM_TASK_STARTRX;
- nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_RESUME);
- break;
- default:
- ret = NRF_ERROR_INVALID_PARAM;
- break;
- }
-
- if (!(flags & NRF_DRV_TWI_FLAG_HOLD_XFER) && (p_xfer_desc->type != NRF_DRV_TWI_XFER_TXTX))
- {
- nrf_twim_task_trigger(p_twim, start_task);
- }
-
- if (p_cb->handler)
- {
- if (flags & NRF_DRV_TWI_FLAG_NO_XFER_EVT_HANDLER)
- {
- p_cb->int_mask = NRF_TWIM_INT_ERROR_MASK;
- }
- nrf_twim_int_enable(p_twim, p_cb->int_mask);
- }
- else
- {
- while (!nrf_twim_event_check(p_twim, evt_to_wait))
- {
- if (nrf_twim_event_check(p_twim, NRF_TWIM_EVENT_ERROR))
- {
- nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_ERROR);
- nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_RESUME);
- nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_STOP);
- evt_to_wait = NRF_TWIM_EVENT_STOPPED;
- }
- }
-
- uint32_t errorsrc = nrf_twim_errorsrc_get_and_clear(p_twim);
-
- p_cb->busy = false;
-
- if (errorsrc)
- {
- ret = NRF_ERROR_INTERNAL;
- }
- }
- return ret;
-}
-#endif
-
-ret_code_t nrf_drv_twi_xfer(nrf_drv_twi_t const * p_instance,
- nrf_drv_twi_xfer_desc_t const * p_xfer_desc,
- uint32_t flags)
-{
- ret_code_t ret = NRF_SUCCESS;
- twi_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx];
-
- // TXRX and TXTX transfers are support only in non-blocking mode.
- ASSERT( !((p_cb->handler == NULL) && (p_xfer_desc->type == NRF_DRV_TWI_XFER_TXRX)));
- ASSERT( !((p_cb->handler == NULL) && (p_xfer_desc->type == NRF_DRV_TWI_XFER_TXTX)));
-
- CODE_FOR_TWIM
- (
- ret = twim_xfer(p_cb, (NRF_TWIM_Type *)p_instance->reg.p_twim, p_xfer_desc, flags);
- )
- CODE_FOR_TWI
- (
- if ( (NRF_DRV_TWI_FLAG_TX_POSTINC | NRF_DRV_TWI_FLAG_RX_POSTINC) & flags)
- {
- return NRF_ERROR_NOT_SUPPORTED;
- }
- ret = twi_xfer(p_cb, (NRF_TWI_Type *)p_instance->reg.p_twi, p_xfer_desc, flags);
- )
- return ret;
-}
-
-ret_code_t nrf_drv_twi_tx(nrf_drv_twi_t const * p_instance,
- uint8_t address,
- uint8_t const * p_data,
- uint8_t length,
- bool no_stop)
-{
- nrf_drv_twi_xfer_desc_t xfer = NRF_DRV_TWI_XFER_DESC_TX(address, (uint8_t*)p_data, length);
-
- return nrf_drv_twi_xfer(p_instance, &xfer, no_stop ? NRF_DRV_TWI_FLAG_TX_NO_STOP : 0);
-}
-
-ret_code_t nrf_drv_twi_rx(nrf_drv_twi_t const * p_instance,
- uint8_t address,
- uint8_t * p_data,
- uint8_t length)
-{
- nrf_drv_twi_xfer_desc_t xfer = NRF_DRV_TWI_XFER_DESC_RX(address, p_data, length);
- return nrf_drv_twi_xfer(p_instance, &xfer, 0);
-}
-
-ret_code_t nrf_drv_twi_rx_ext(nrf_drv_twi_t const * p_instance,
- uint8_t address,
- uint8_t * p_data,
- uint8_t length,
- bool no_stop)
-{
- uint32_t flags;
- nrf_drv_twi_xfer_desc_t xfer = NRF_DRV_TWI_XFER_DESC_RX(address, p_data, length);
-
- if (no_stop) {
- flags = NRF_DRV_TWI_FLAG_RX_NO_STOP;
- } else {
- flags = 0;
- }
- return nrf_drv_twi_xfer(p_instance, &xfer, flags);
-}
-
-
-uint32_t nrf_drv_twi_data_count_get(nrf_drv_twi_t const * const p_instance)
-{
- CODE_FOR_TWIM
- (
- ASSERT(false);
- return 0;
- )
- CODE_FOR_TWI
- (
- return m_cb[p_instance->drv_inst_idx].bytes_transferred;
- )
-}
-uint32_t nrf_drv_twi_start_task_get(nrf_drv_twi_t const * p_instance, nrf_drv_twi_xfer_type_t xfer_type)
-{
- CODE_FOR_TWIM
- (
- return (uint32_t)nrf_twim_task_address_get(p_instance->reg.p_twim,
- (xfer_type != NRF_DRV_TWI_XFER_RX) ? NRF_TWIM_TASK_STARTTX : NRF_TWIM_TASK_STARTRX);
- )
- CODE_FOR_TWI
- (
- return (uint32_t)nrf_twi_task_address_get(p_instance->reg.p_twi,
- (xfer_type != NRF_DRV_TWI_XFER_RX) ? NRF_TWI_TASK_STARTTX : NRF_TWI_TASK_STARTRX);
- )
-}
-
-uint32_t nrf_drv_twi_stopped_event_get(nrf_drv_twi_t const * p_instance)
-{
- CODE_FOR_TWIM
- (
- return (uint32_t)nrf_twim_event_address_get(p_instance->reg.p_twim, NRF_TWIM_EVENT_STOPPED);
- )
- CODE_FOR_TWI
- (
- return (uint32_t)nrf_twi_event_address_get(p_instance->reg.p_twi, NRF_TWI_EVENT_STOPPED);
- )
-}
-
-#ifdef TWIM_IN_USE
-static void irq_handler_twim(NRF_TWIM_Type * p_twim, twi_control_block_t * p_cb)
-{
- ASSERT(p_cb->handler);
-
- if (nrf_twim_event_check(p_twim, NRF_TWIM_EVENT_ERROR))
- {
- nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_ERROR);
- if (!nrf_twim_event_check(p_twim, NRF_TWIM_EVENT_STOPPED))
- {
- nrf_twim_int_disable(p_twim, p_cb->int_mask);
- p_cb->int_mask = NRF_TWIM_INT_STOPPED_MASK;
- nrf_twim_int_enable(p_twim, p_cb->int_mask);
-
- nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_RESUME);
- nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_STOP);
- return;
- }
- }
-
- nrf_drv_twi_evt_t event;
-
- if (nrf_twim_event_check(p_twim, NRF_TWIM_EVENT_STOPPED))
- {
- nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_STOPPED);
- event.xfer_desc = p_cb->xfer_desc;
- if (p_cb->error)
- {
-
- event.xfer_desc.primary_length = (p_cb->xfer_desc.type == NRF_DRV_TWI_XFER_RX) ?
- (uint8_t)nrf_twim_rxd_amount_get(p_twim) : (uint8_t)nrf_twim_txd_amount_get(p_twim);
- event.xfer_desc.secondary_length = (p_cb->xfer_desc.type == NRF_DRV_TWI_XFER_TXRX) ?
- (uint8_t)nrf_twim_rxd_amount_get(p_twim) : (uint8_t)nrf_twim_txd_amount_get(p_twim);
-
- }
- nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_LASTTX);
- nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_LASTRX);
- if (!p_cb->repeated || p_cb->error)
- {
- nrf_twim_shorts_set(p_twim, 0);
- p_cb->int_mask = 0;
- nrf_twim_int_disable(p_twim, DISABLE_ALL);
- }
- }
- else
- {
- nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_SUSPENDED);
- if (p_cb->xfer_desc.type == NRF_DRV_TWI_XFER_TX)
- {
- event.xfer_desc = p_cb->xfer_desc;
- if (!p_cb->repeated)
- {
- nrf_twim_shorts_set(p_twim, 0);
- p_cb->int_mask = 0;
- nrf_twim_int_disable(p_twim, DISABLE_ALL);
- }
- }
- else
- {
- nrf_twim_shorts_set(p_twim, NRF_TWIM_SHORT_LASTTX_STOP_MASK);
- p_cb->int_mask = NRF_TWIM_INT_STOPPED_MASK | NRF_TWIM_INT_ERROR_MASK;
- nrf_twim_int_disable(p_twim, DISABLE_ALL);
- nrf_twim_int_enable(p_twim, p_cb->int_mask);
- nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_STARTTX);
- nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_RESUME);
- return;
- }
- }
-
- uint32_t errorsrc = nrf_twim_errorsrc_get_and_clear(p_twim);
- if (errorsrc & NRF_TWIM_ERROR_ADDRESS_NACK)
- {
- event.type = NRF_DRV_TWI_EVT_ADDRESS_NACK;
- }
- else if (errorsrc & NRF_TWIM_ERROR_DATA_NACK)
- {
- event.type = NRF_DRV_TWI_EVT_DATA_NACK;
- }
- else
- {
- event.type = NRF_DRV_TWI_EVT_DONE;
- }
-
- if (!p_cb->repeated)
- {
- p_cb->busy = false;
- }
- p_cb->handler(&event, p_cb->p_context);
-}
-#endif // TWIM_IN_USE
-
-#ifdef TWI_IN_USE
-static void irq_handler_twi(NRF_TWI_Type * p_twi, twi_control_block_t * p_cb)
-{
- ASSERT(p_cb->handler);
-
- if (twi_transfer(p_twi, &p_cb->error, &p_cb->bytes_transferred, p_cb->p_curr_buf, p_cb->curr_length, p_cb->curr_no_stop ))
- {
- return;
- }
-
- if (!p_cb->error &&
- ((p_cb->xfer_desc.type == NRF_DRV_TWI_XFER_TXRX) ||
- (p_cb->xfer_desc.type == NRF_DRV_TWI_XFER_TXTX)) &&
- p_cb->p_curr_buf == p_cb->xfer_desc.p_primary_buf)
- {
- p_cb->p_curr_buf = p_cb->xfer_desc.p_secondary_buf;
- p_cb->curr_length = p_cb->xfer_desc.secondary_length;
- p_cb->curr_no_stop = (p_cb->flags & NRF_DRV_TWI_FLAG_TX_NO_STOP);
-
- if (p_cb->xfer_desc.type == NRF_DRV_TWI_XFER_TXTX)
- {
- (void)twi_tx_start_transfer(p_cb, p_twi, p_cb->p_curr_buf, p_cb->curr_length, p_cb->curr_no_stop);
- }
- else
- {
- (void)twi_rx_start_transfer(p_cb, p_twi, p_cb->p_curr_buf, p_cb->curr_length);
- }
- }
- else
- {
- nrf_drv_twi_evt_t event;
- event.xfer_desc = p_cb->xfer_desc;
-
- if (p_cb->error)
- {
- uint32_t errorsrc = nrf_twi_errorsrc_get_and_clear(p_twi);
- if (errorsrc & NRF_TWI_ERROR_ADDRESS_NACK)
- {
- event.type = NRF_DRV_TWI_EVT_ADDRESS_NACK;
- }
- else if (errorsrc & NRF_TWI_ERROR_DATA_NACK)
- {
- event.type = NRF_DRV_TWI_EVT_DATA_NACK;
- }
- }
- else
- {
- event.type = NRF_DRV_TWI_EVT_DONE;
- }
-
- p_cb->busy = false;
-
- if (!(NRF_DRV_TWI_FLAG_NO_XFER_EVT_HANDLER & p_cb->flags))
- {
- p_cb->handler(&event, p_cb->p_context);
- }
- }
-
-}
-#endif // TWI_IN_USE
-
-#if TWI0_ENABLED
-IRQ_HANDLER(0)
-{
- #if (TWI0_USE_EASY_DMA == 1) && defined(NRF52)
- irq_handler_twim(NRF_TWIM0,
- #else
- irq_handler_twi(NRF_TWI0,
- #endif
- &m_cb[TWI0_INSTANCE_INDEX]);
-}
-#endif // TWI0_ENABLED
-
-#if TWI1_ENABLED
-IRQ_HANDLER(1)
-{
- #if (TWI1_USE_EASY_DMA == 1)
- irq_handler_twim(NRF_TWIM1,
- #else
- irq_handler_twi(NRF_TWI1,
- #endif
- &m_cb[TWI1_INSTANCE_INDEX]);
-}
-#endif // TWI1_ENABLED