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:41 UTC
[27/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/libraries/hci/hci_slip.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/hci/hci_slip.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/hci/hci_slip.c
deleted file mode 100644
index 4c40808..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/hci/hci_slip.c
+++ /dev/null
@@ -1,428 +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 "hci_slip.h"
-#include <stdlib.h>
-#include "hci_transport_config.h"
-#include "app_uart.h"
-#include "nrf_error.h"
-
-#define APP_SLIP_END 0xC0 /**< SLIP code for identifying the beginning and end of a packet frame.. */
-#define APP_SLIP_ESC 0xDB /**< SLIP escape code. This code is used to specify that the following character is specially encoded. */
-#define APP_SLIP_ESC_END 0xDC /**< SLIP special code. When this code follows 0xDB, this character is interpreted as payload data 0xC0.. */
-#define APP_SLIP_ESC_ESC 0xDD /**< SLIP special code. When this code follows 0xDB, this character is interpreted as payload data 0xDB. */
-
-/** @brief States for the SLIP state machine. */
-typedef enum
-{
- SLIP_OFF, /**< SLIP state OFF. */
- SLIP_READY, /**< SLIP state ON. */
- SLIP_TRANSMITTING, /**< SLIP state is transmitting indicating write() has been called but data transmission has not completed. */
-} slip_states_t;
-
-static slip_states_t m_current_state = SLIP_OFF; /** Current state for the SLIP TX state machine. */
-
-static hci_slip_event_handler_t m_slip_event_handler; /** Event callback function for handling of SLIP events, @ref hci_slip_evt_type_t . */
-
-static const uint8_t * mp_tx_buffer; /** Pointer to the current TX buffer that is in transmission. */
-static uint32_t m_tx_buffer_length; /** Length of the current TX buffer that is in transmission. */
-static volatile uint32_t m_tx_buffer_index; /** Current index for next byte to transmit in the mp_tx_buffer. */
-
-static uint8_t * mp_rx_buffer; /** Pointer to the current RX buffer where the next SLIP decoded packet will be stored. */
-static uint32_t m_rx_buffer_length; /** Length of the current RX buffer. */
-static uint32_t m_rx_received_count; /** Number of SLIP decoded bytes received and stored in mp_rx_buffer. */
-
-
-/**@brief Function for parsing bytes received on the UART until a SLIP escape byte is received.
- *
- * @param[in] byte Byte received in UART module.
- */
-static void handle_rx_byte_default(uint8_t byte);
-
-/**@brief Function for parsing bytes received on the UART until SLIP end byte is received.
- *
- * @param[in] byte Byte received in UART module.
- */
-static void handle_rx_byte_wait_start(uint8_t byte);
-
-/**@brief Function for decoding a received SLIP escape byte.
- * It will ensure correct decoding of the byte following the SLIP escape byte.
- *
- * @param[in] byte Byte received in UART module.
- */
-static void handle_rx_byte_esc(uint8_t byte);
-
-/**@brief Function pointer for parsing and decoding SLIP bytes from the UART module.
- *
- * @param[in] byte Byte received in UART module.
- */
-static void (*handle_rx_byte) (uint8_t byte) = handle_rx_byte_wait_start;
-
-/**@brief Function pointer for sending a byte through the UART module.
- */
-static uint32_t send_tx_byte_default(void);
-
-/**@brief Function for transferring a SLIP escape byte (0xDB) when special bytes are transferred,
- * that is 0xC0 and 0xDB.
- */
-static uint32_t send_tx_byte_esc(void);
-
-/**@brief Function for transferring a byte when it collides with SLIP commands and follows the SLIP
- * escape byte, that is 0xC0 => 0xDC and 0xDB => 0xDD.
- */
-static uint32_t send_tx_byte_encoded(void);
-
-/**@brief Function for transferring the SLIP end frame byte, 0xC0.
- */
-static uint32_t send_tx_byte_end(void);
-
-/**@brief Function pointer for sending a byte through the UART module.
- */
-uint32_t (*send_tx_byte) (void) = send_tx_byte_default;
-
-
-static uint32_t send_tx_byte_end(void)
-{
- uint32_t err_code = app_uart_put(APP_SLIP_END);
-
- if ((err_code == NRF_SUCCESS) && (m_tx_buffer_index == 0))
- {
- // Packet transmission started.
- send_tx_byte = send_tx_byte_default;
- }
-
- return err_code;
-}
-
-
-static uint32_t send_tx_byte_default(void)
-{
- uint32_t err_code = app_uart_put(mp_tx_buffer[m_tx_buffer_index]);
-
- if (err_code == NRF_SUCCESS)
- {
- m_tx_buffer_index++;
- }
-
- return err_code;
-}
-
-
-static uint32_t send_tx_byte_encoded(void)
-{
- uint32_t err_code;
-
- switch(mp_tx_buffer[m_tx_buffer_index])
- {
- case APP_SLIP_END:
- err_code = app_uart_put(APP_SLIP_ESC_END);
- break;
-
- case APP_SLIP_ESC:
- err_code = app_uart_put(APP_SLIP_ESC_ESC);
- break;
-
- default:
- err_code = NRF_ERROR_NO_MEM;
- break;
- }
-
- if (err_code == NRF_SUCCESS)
- {
- m_tx_buffer_index++;
- send_tx_byte = send_tx_byte_default;
- }
-
- return err_code;
-}
-
-
-static uint32_t send_tx_byte_esc(void)
-{
- uint32_t err_code = app_uart_put(APP_SLIP_ESC);
-
- if (err_code == NRF_SUCCESS)
- {
- send_tx_byte = send_tx_byte_encoded;
- }
-
- return err_code;
-}
-
-
-/** @brief Function for transferring the content of the mp_tx_buffer to the UART.
- * It continues to transfer bytes until the UART buffer is full or the complete buffer is
- * transferred.
- */
-static void transmit_buffer(void)
-{
- uint32_t err_code = NRF_SUCCESS;
-
- while (m_tx_buffer_index < m_tx_buffer_length)
- {
- if ((mp_tx_buffer[m_tx_buffer_index] == APP_SLIP_END ||
- mp_tx_buffer[m_tx_buffer_index] == APP_SLIP_ESC) &&
- send_tx_byte == send_tx_byte_default)
- {
- send_tx_byte = send_tx_byte_esc;
- }
-
- err_code = send_tx_byte();
-
- if (err_code == NRF_ERROR_NO_MEM || err_code == NRF_ERROR_BUSY)
- {
- // No memory left in UART TX buffer. Abort and wait for APP_UART_TX_EMPTY to continue.
- return;
- }
- }
-
- send_tx_byte = send_tx_byte_end;
-
- err_code = send_tx_byte();
-
- if (err_code == NRF_SUCCESS)
- {
- // Packet transmission ended. Notify higher level.
- m_current_state = SLIP_READY;
-
- if (m_slip_event_handler != NULL)
- {
- hci_slip_evt_t event = {HCI_SLIP_TX_DONE, mp_tx_buffer, m_tx_buffer_index};
-
- m_slip_event_handler(event);
- }
- }
-}
-
-
-/** @brief Function for handling the reception of a SLIP end byte.
- * If the number of bytes received is greater than zero it will call m_slip_event_handler
- * with number of bytes received and invalidate the mp_rx_buffer to protect against data
- * corruption.
- * No new bytes can be received until a new RX buffer is supplied.
- */
-static void handle_slip_end(void)
-{
- if (m_rx_received_count > 0)
- {
- // Full packet received, push it up.
- if (m_slip_event_handler != NULL)
- {
- hci_slip_evt_t event = {HCI_SLIP_RX_RDY, mp_rx_buffer, m_rx_received_count};
-
- m_rx_received_count = 0;
- mp_rx_buffer = NULL;
-
- m_slip_event_handler(event);
- }
- }
-}
-
-
-static void handle_rx_byte_esc(uint8_t byte)
-{
- switch (byte)
- {
- case APP_SLIP_END:
- handle_slip_end();
- break;
-
- case APP_SLIP_ESC_END:
- mp_rx_buffer[m_rx_received_count++] = APP_SLIP_END;
- break;
-
- case APP_SLIP_ESC_ESC:
- mp_rx_buffer[m_rx_received_count++] = APP_SLIP_ESC;
- break;
-
- default:
- mp_rx_buffer[m_rx_received_count++] = byte;
- break;
- }
-
- handle_rx_byte = handle_rx_byte_default;
-}
-
-
-static void handle_rx_byte_default(uint8_t byte)
-{
- switch (byte)
- {
- case APP_SLIP_END:
- handle_slip_end();
- break;
-
- case APP_SLIP_ESC:
- handle_rx_byte = handle_rx_byte_esc;
- break;
-
- default:
- mp_rx_buffer[m_rx_received_count++] = byte;
- break;
- }
-}
-
-
-static void handle_rx_byte_wait_start(uint8_t byte)
-{
- if (byte == APP_SLIP_END)
- {
- handle_rx_byte = handle_rx_byte_default;
- }
-}
-
-
-/** @brief Function for checking the current index and length of the RX buffer to determine if the
- * buffer is full. If an event handler has been registered, the callback function will
- * be executed..
- *
- * @retval true If RX buffer has overflowed.
- * @retval false otherwise.
- *
- */
-static bool rx_buffer_overflowed(void)
-{
- if (mp_rx_buffer == NULL || m_rx_received_count >= m_rx_buffer_length)
- {
- if (m_slip_event_handler != NULL)
- {
- hci_slip_evt_t event = {HCI_SLIP_RX_OVERFLOW, mp_rx_buffer, m_rx_received_count};
- m_slip_event_handler(event);
- }
-
- return true;
- }
-
- return false;
-}
-
-
-/** @brief Function for handling the UART module event. It parses events from the UART when
- * bytes are received/transmitted.
- *
- * @param[in] uart_event Event received from app_uart module.
- */
-static void slip_uart_eventhandler(app_uart_evt_t * uart_event)
-{
- if (uart_event->evt_type == APP_UART_TX_EMPTY && m_current_state == SLIP_TRANSMITTING)
- {
- transmit_buffer();
- }
-
- if ((uart_event->evt_type == APP_UART_DATA) && (!rx_buffer_overflowed()))
- {
- handle_rx_byte(uart_event->data.value);
- }
-}
-
-
-/** @brief Function for enabling the UART module when the SLIP layer is opened.
- */
-static uint32_t slip_uart_open(void)
-{
- uint32_t err_code;
-
- app_uart_comm_params_t comm_params =
- {
- HCI_SLIP_UART_RX_PIN_NUMBER,
- HCI_SLIP_UART_TX_PIN_NUMBER,
- HCI_SLIP_UART_RTS_PIN_NUMBER,
- HCI_SLIP_UART_CTS_PIN_NUMBER,
- HCI_SLIP_UART_MODE,
- false,
- HCI_SLIP_UART_BAUDRATE
- };
-
- err_code = app_uart_init(&comm_params,
- NULL,
- slip_uart_eventhandler,
- APP_IRQ_PRIORITY_LOW);
-
- if (err_code == NRF_SUCCESS)
- {
- m_current_state = SLIP_READY;
- }
-
- return err_code;
-}
-
-
-uint32_t hci_slip_evt_handler_register(hci_slip_event_handler_t event_handler)
-{
- m_slip_event_handler = event_handler;
-
- return NRF_SUCCESS;
-}
-
-
-uint32_t hci_slip_open()
-{
- switch (m_current_state)
- {
- case SLIP_OFF:
- return slip_uart_open();
-
- default:
- // Do nothing.
- break;
- }
-
- return NRF_SUCCESS;
-}
-
-
-uint32_t hci_slip_close()
-{
- m_current_state = SLIP_OFF;
- uint32_t err_code = app_uart_close();
-
- return err_code;
-}
-
-
-uint32_t hci_slip_write(const uint8_t * p_buffer, uint32_t length)
-{
- if (p_buffer == NULL)
- {
- return NRF_ERROR_INVALID_ADDR;
- }
-
- switch (m_current_state)
- {
- case SLIP_READY:
- m_tx_buffer_index = 0;
- m_tx_buffer_length = length;
- mp_tx_buffer = p_buffer;
- m_current_state = SLIP_TRANSMITTING;
- send_tx_byte = send_tx_byte_end;
-
- transmit_buffer();
- return NRF_SUCCESS;
-
- case SLIP_TRANSMITTING:
- return NRF_ERROR_NO_MEM;
-
- case SLIP_OFF:
- default:
- return NRF_ERROR_INVALID_STATE;
- }
-}
-
-
-uint32_t hci_slip_rx_buffer_register(uint8_t * p_buffer, uint32_t length)
-{
- mp_rx_buffer = p_buffer;
- m_rx_buffer_length = length;
- m_rx_received_count = 0;
- handle_rx_byte = handle_rx_byte_wait_start;
- return NRF_SUCCESS;
-}
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/libraries/hci/hci_slip.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/hci/hci_slip.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/hci/hci_slip.h
deleted file mode 100644
index 43c72ea..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/hci/hci_slip.h
+++ /dev/null
@@ -1,137 +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.
- *
- */
-
-/** @file
- *
- * @defgroup hci_slip SLIP module
- * @{
- * @ingroup app_common
- *
- * @brief SLIP layer for supporting packet framing in HCI transport.
- *
- * @details This module implements SLIP packet framing as described in the Bluetooth Core
- * Specification 4.0, Volume 4, Part D, Chapter 3 SLIP Layer.
- *
- * SLIP framing ensures that all packets sent on the UART are framed as:
- * <0xC0> SLIP packet 1 <0xC0> <0xC0> SLIP packet 2 <0xC0>.
- *
- * The SLIP layer uses events to notify the upper layer when data transmission is complete
- * and when a SLIP packet is received.
- */
-
-#ifndef HCI_SLIP_H__
-#define HCI_SLIP_H__
-
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**@brief Event types from the SLIP Layer. */
-typedef enum
-{
- HCI_SLIP_RX_RDY, /**< An event indicating that an RX packet is ready to be read. */
- HCI_SLIP_TX_DONE, /**< An event indicating write completion of the TX packet provided in the function call \ref hci_slip_write . */
- HCI_SLIP_RX_OVERFLOW, /**< An event indicating that RX data has been discarded due to lack of free RX memory. */
- HCI_SLIP_ERROR, /**< An event indicating that an unrecoverable error has occurred. */
- HCI_SLIP_EVT_TYPE_MAX /**< Enumeration upper bound. */
-} hci_slip_evt_type_t;
-
-/**@brief Structure containing an event from the SLIP layer.
- */
-typedef struct
-{
- hci_slip_evt_type_t evt_type; /**< Type of event. */
- const uint8_t * packet; /**< This field contains a pointer to the packet for which the event relates, i.e. SLIP_TX_DONE: the packet transmitted, SLIP_RX_RDY: the packet received, SLIP_RX_OVERFLOW: The packet which overflow/or NULL if no receive buffer is available. */
- uint32_t packet_length; /**< Packet length, i.e. SLIP_TX_DONE: Bytes transmitted, SLIP_RX_RDY: Bytes received, SLIP_RX_OVERFLOW: index at which the packet overflowed. */
-} hci_slip_evt_t;
-
-/**@brief Function for the SLIP layer event callback.
- */
-typedef void (*hci_slip_event_handler_t)(hci_slip_evt_t event);
-
-/**@brief Function for registering the event handler provided as parameter and this event handler
- * will be used by SLIP layer to send events described in \ref hci_slip_evt_type_t.
- *
- * @note Multiple registration requests will overwrite any existing registration.
- *
- * @param[in] event_handler This function is called by the SLIP layer upon an event.
- *
- * @retval NRF_SUCCESS Operation success.
- */
-uint32_t hci_slip_evt_handler_register(hci_slip_event_handler_t event_handler);
-
-/**@brief Function for opening the SLIP layer. This function must be called before
- * \ref hci_slip_write and before any data can be received.
- *
- * @note Can be called multiple times.
- *
- * @retval NRF_SUCCESS Operation success.
- *
- * The SLIP layer module will propagate errors from underlying sub-modules.
- * This implementation is using UART module as a physical transmission layer, and hci_slip_open
- * executes \ref app_uart_init . For an extended error list, please refer to \ref app_uart_init .
- */
-uint32_t hci_slip_open(void);
-
-/**@brief Function for closing the SLIP layer. After this function is called no data can be
- * transmitted or received in this layer.
- *
- * @note This function can be called multiple times and also for an unopened channel.
- *
- * @retval NRF_SUCCESS Operation success.
- */
-uint32_t hci_slip_close(void);
-
-/**@brief Function for writing a packet with SLIP encoding. Packet transmission is confirmed when
- * the HCI_SLIP_TX_DONE event is received by the function caller.
- *
- * @param[in] p_buffer Pointer to the packet to transmit.
- * @param[in] length Packet length, in bytes.
- *
- * @retval NRF_SUCCESS Operation success. Packet was encoded and added to the
- * transmission queue and an event will be sent upon transmission
- * completion.
- * @retval NRF_ERROR_NO_MEM Operation failure. Transmission queue is full and packet was not
- * added to the transmission queue. Application shall wait for
- * the \ref HCI_SLIP_TX_DONE event. After HCI_SLIP_TX_DONE this
- * function can be executed for transmission of next packet.
- * @retval NRF_ERROR_INVALID_ADDR If a NULL pointer is provided.
- * @retval NRF_ERROR_INVALID_STATE Operation failure. Module is not open.
- */
-uint32_t hci_slip_write(const uint8_t * p_buffer, uint32_t length);
-
-/**@brief Function for registering a receive buffer. The receive buffer will be used for storage of
- * received and SLIP decoded data.
- * No data can be received by the SLIP layer until a receive buffer has been registered.
- *
- * @note The lifetime of the buffer must be valid during complete reception of data. A static
- * buffer is recommended.
- *
- * @warning Multiple registration requests will overwrite any existing registration.
- *
- * @param[in] p_buffer Pointer to receive buffer. The received and SLIP decoded packet
- * will be placed in this buffer.
- * @param[in] length Buffer length, in bytes.
- *
- * @retval NRF_SUCCESS Operation success.
- */
-uint32_t hci_slip_rx_buffer_register(uint8_t * p_buffer, uint32_t length);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // HCI_SLIP_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/libraries/hci/hci_transport.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/hci/hci_transport.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/hci/hci_transport.c
deleted file mode 100644
index fe45f24..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/hci/hci_transport.c
+++ /dev/null
@@ -1,779 +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 "hci_transport_config.h"
-#include "hci_transport.h"
-#include "hci_slip.h"
-#include "crc16.h"
-#include "hci_mem_pool.h"
-#include "hci_mem_pool_internal.h"
-#include "app_timer.h"
-#include "app_error.h"
-#include <stdio.h>
-#include "sdk_common.h"
-
-#define PKT_HDR_SIZE 4u /**< Packet header size in number of bytes. */
-#define PKT_CRC_SIZE 2u /**< Packet CRC size in number of bytes. */
-#define PKT_TYPE_VENDOR_SPECIFIC 14u /**< Packet type vendor specific. */
-#define PKT_TYPE_ACK 0 /**< Packet type acknowledgement. */
-#define DATA_INTEGRITY_MASK (1u << 6u) /**< Mask for data integrity bit in the packet header. */
-#define RELIABLE_PKT_MASK (1u << 7u) /**< Mask for reliable packet bit in the packet header. */
-#define INITIAL_ACK_NUMBER_EXPECTED 1u /**< Initial acknowledge number expected. */
-#define INITIAL_ACK_NUMBER_TX INITIAL_ACK_NUMBER_EXPECTED /**< Initial acknowledge number transmitted. */
-#define INVALID_PKT_TYPE 0xFFFFFFFFu /**< Internal invalid packet type value. */
-#define MAX_TRANSMISSION_TIME (ROUNDED_DIV((MAX_PACKET_SIZE_IN_BITS * 1000u), USED_BAUD_RATE)) /**< Max transmission time of a single application packet over UART in units of mseconds. */
-#define RETRANSMISSION_TIMEOUT_IN_MS (3u * MAX_TRANSMISSION_TIME) /**< Retransmission timeout for application packet in units of mseconds. */
-#define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */
-#define RETRANSMISSION_TIMEOUT_IN_TICKS APP_TIMER_TICKS(RETRANSMISSION_TIMEOUT_IN_MS, APP_TIMER_PRESCALER) /**< Retransmission timeout for application packet in units of timer ticks. */
-#define MAX_RETRY_COUNT 5u /**< Max retransmission retry count for application packets. */
-#define ACK_BUF_SIZE 5u /**< Length of module internal RX buffer which is big enough to hold an acknowledgement packet. */
-
-/**@brief States of the TX state machine. */
-typedef enum
-{
- TX_STATE_IDLE, /**< State for: no application transmission packet processing in progress. */
- TX_STATE_PENDING, /**< State for: TX in progress in slip layer and TX-done event is waited for to signal the end of transmission. */
- TX_STATE_ACTIVE /**< State for: application packet has been delivered to slip for transmission and peer transport entity acknowledgement packet is waited for. */
-} tx_state_t;
-
-/**@brief TX state machine events. */
-typedef enum
-{
- TX_EVENT_STATE_ENTRY, /**< Event for: state entry use case. */
- TX_EVENT_SLIP_TX_DONE, /**< Event for: HCI_SLIP_TX_DONE event use case. */
- TX_EVENT_TIMEOUT, /**< Event for: retransmission timeout use case. */
- TX_EVENT_VALID_RX_ACK /**< Event for: valid acknowledgement received for TX packet use case. */
-} tx_event_t;
-
-static void tx_sm_state_change(tx_state_t new_state);
-
-static tx_state_t m_tx_state; /**< Current TX state. */
-static hci_transport_tx_done_handler_t m_transport_tx_done_handle; /**< TX done event callback function. */
-static hci_transport_event_handler_t m_transport_event_handle; /**< Event handler callback function. */
-static uint8_t * mp_slip_used_rx_buffer; /**< Reference to RX buffer used by the slip layer. */
-static uint32_t m_packet_expected_seq_number; /**< Sequence number counter of the packet expected to be received . */
-static uint32_t m_packet_transmit_seq_number; /**< Sequence number counter of the transmitted packet for which acknowledgement packet is waited for. */
-static uint8_t * mp_tx_buffer; /**< Pointer to TX application buffer to be transmitted. */
-static uint32_t m_tx_buffer_length; /**< Length of application TX packet data to be transmitted in bytes. */
-static bool m_is_slip_decode_ready; /**< Boolean to determine has slip decode been completed or not. */
-APP_TIMER_DEF(m_app_timer_id); /**< Application timer id. */
-static uint32_t m_tx_retry_counter; /**< Application packet retransmission counter. */
-static hci_transport_tx_done_result_t m_tx_done_result_code; /**< TX done event callback function result code. */
-static uint8_t m_rx_ack_buffer[ACK_BUF_SIZE];/**< RX buffer big enough to hold an acknowledgement packet and which is taken in use upon receiving HCI_SLIP_RX_OVERFLOW event. */
-
-
-/**@brief Function for validating a received packet.
- *
- * @param[in] p_buffer Pointer to the packet data.
- * @param[in] length Length of packet data in bytes.
- *
- * @return true if received packet is valid, false in other case.
- */
-static bool is_rx_pkt_valid(const uint8_t * p_buffer, uint32_t length)
-{
- // Executed packet filtering algorithm order:
- // - verify packet overall length
- // - verify data integrity bit set
- // - verify reliable packet bit set
- // - verify supported packet type
- // - verify header checksum
- // - verify payload length field
- // - verify CRC
- if (length <= PKT_HDR_SIZE)
- {
- return false;
- }
-
- if (!(p_buffer[0] & DATA_INTEGRITY_MASK))
- {
- return false;
- }
-
- if (!(p_buffer[0] & RELIABLE_PKT_MASK))
- {
- return false;
- }
-
- if ((p_buffer[1] & 0x0Fu) != PKT_TYPE_VENDOR_SPECIFIC)
- {
- return false;
- }
-
- const uint32_t expected_checksum =
- ((p_buffer[0] + p_buffer[1] + p_buffer[2] + p_buffer[3])) & 0xFFu;
- if (expected_checksum != 0)
- {
- return false;
- }
-
- const uint16_t crc_calculated = crc16_compute(p_buffer, (length - PKT_CRC_SIZE), NULL);
- const uint16_t crc_received = uint16_decode(&p_buffer[length - PKT_CRC_SIZE]);
- if (crc_calculated != crc_received)
- {
- return false;
- }
-
- return true;
-}
-
-
-/**@brief Function for getting the sequence number of the next reliable packet expected.
- *
- * @return sequence number of the next reliable packet expected.
- */
-static __INLINE uint8_t packet_number_expected_get(void)
-{
- return (uint8_t) m_packet_expected_seq_number;
-}
-
-
-/**@brief Function for calculating a packet header checksum.
- *
- * @param[in] p_hdr Pointer to the packet header.
- *
- * @return Calculated checksum.
- */
-static uint8_t header_checksum_calculate(const uint8_t * p_hdr)
-{
- // @note: no pointer validation check needed as already checked by calling function.
- uint32_t checksum;
-
- checksum = p_hdr[0];
- checksum += p_hdr[1];
- checksum += p_hdr[2];
- checksum &= 0xFFu;
- checksum = (~checksum + 1u);
-
- return (uint8_t)checksum;
-}
-
-
-/**@brief Function for writing an acknowledgment packet for transmission.
- */
-static void ack_transmit(void)
-{
- static uint8_t ack_packet[PKT_HDR_SIZE];
-
- // TX ACK packet format:
- // - Unreliable Packet type
- // - Payload Length set to 0
- // - Sequence Number set to 0
- // - Header checksum calculated
- // - Acknowledge Number set correctly
- ack_packet[0] = (packet_number_expected_get() << 3u);
- ack_packet[1] = 0;
- ack_packet[2] = 0;
- ack_packet[3] = header_checksum_calculate(ack_packet);
-
- // @note: no return value check needed for hci_slip_write(...) call as acknowledgement packets
- // are considered to be from system design point of view unreliable packets.Use case where
- // underlying slip layer does not accept a packet for transmission is managed either by:
- // - acknowledged by possible future application packet as acknowledgement number header field
- // is included
- // - protocol peer entity will retransmit the packet
- UNUSED_VARIABLE(hci_slip_write(ack_packet, sizeof(ack_packet)));
-}
-
-
-/**@brief Function for validating a received packet.
- *
- * @param[in] p_buffer Pointer to the packet data.
- *
- * @return sequence number field of the packet header with unrelated data masked out.
- */
-static __INLINE uint8_t packet_seq_nmbr_extract(const uint8_t * p_buffer)
-{
- return (p_buffer[0] & 0x07u);
-}
-
-
-/**@brief Function for incrementing the sequence number counter for next reliable packet expected.
- */
-static __INLINE void packet_number_expected_inc(void)
-{
- ++m_packet_expected_seq_number;
- m_packet_expected_seq_number &= 0x07u;
-}
-
-
-/**@brief Function for decoding a packet type field.
- *
- * @param[in] p_buffer Pointer to the packet data.
- * @param[in] length Length of packet data in bytes.
- *
- * @return Packet type field or INVALID_PKT_TYPE in case of decode error.
- */
-static __INLINE uint32_t packet_type_decode(const uint8_t * p_buffer, uint32_t length)
-{
- // @note: no pointer validation check needed as allready checked by calling function.
- uint32_t return_value;
-
- if (length >= PKT_HDR_SIZE)
- {
- return_value = (p_buffer[1] & 0x0Fu);
- }
- else
- {
- return_value = INVALID_PKT_TYPE;
- }
-
- return return_value;
-}
-
-
-/**@brief Function for processing a received vendor specific packet.
- *
- * @param[in] p_buffer Pointer to the packet data.
- * @param[in] length Length of packet data in bytes.
- */
-static void rx_vendor_specific_pkt_type_handle(const uint8_t * p_buffer, uint32_t length)
-{
- // @note: no pointer validation check needed as allready checked by calling function.
- uint32_t err_code;
-
- if (is_rx_pkt_valid(p_buffer, length))
- {
- // RX packet is valid: validate sequence number.
- const uint8_t rx_seq_number = packet_seq_nmbr_extract(p_buffer);
- if (packet_number_expected_get() == rx_seq_number)
- {
- // Sequence number is valid: transmit acknowledgement.
- packet_number_expected_inc();
- ack_transmit();
-
- m_is_slip_decode_ready = true;
-
- err_code = hci_mem_pool_rx_data_size_set(length);
- APP_ERROR_CHECK(err_code);
-
- err_code = hci_mem_pool_rx_produce(RX_BUF_SIZE, (void **)&mp_slip_used_rx_buffer);
- APP_ERROR_CHECK_BOOL((err_code == NRF_SUCCESS) || (err_code == NRF_ERROR_NO_MEM));
-
- // If memory pool RX buffer produce succeeded we register that buffer to slip layer
- // otherwise we register the internal acknowledgement buffer.
- err_code = hci_slip_rx_buffer_register(
- (err_code == NRF_SUCCESS) ? mp_slip_used_rx_buffer : m_rx_ack_buffer,
- (err_code == NRF_SUCCESS) ? RX_BUF_SIZE : ACK_BUF_SIZE);
-
- APP_ERROR_CHECK(err_code);
-
- if (m_transport_event_handle != NULL)
- {
- // Send application event of RX packet reception.
- const hci_transport_evt_t evt = {HCI_TRANSPORT_RX_RDY};
- m_transport_event_handle(evt);
- }
- }
- else
- {
- // RX packet discarded: sequence number not valid, set the same buffer to slip layer in
- // order to avoid buffer overrun.
- err_code = hci_slip_rx_buffer_register(mp_slip_used_rx_buffer, RX_BUF_SIZE);
- APP_ERROR_CHECK(err_code);
-
- // As packet did not have expected sequence number: send acknowledgement with the
- // current expected sequence number.
- ack_transmit();
- }
- }
- else
- {
- // RX packet discarded: reset the same buffer to slip layer in order to avoid buffer
- // overrun.
- err_code = hci_slip_rx_buffer_register(mp_slip_used_rx_buffer, RX_BUF_SIZE);
- APP_ERROR_CHECK(err_code);
- }
-}
-
-
-/**@brief Function for getting the sequence number of a reliable TX packet for which peer protocol
- * entity acknowledgment is pending.
- *
- * @return sequence number of a reliable TX packet for which peer protocol entity acknowledgement
- * is pending.
- */
-static __INLINE uint8_t packet_number_to_transmit_get(void)
-{
- return m_packet_transmit_seq_number;
-}
-
-
-/**@brief Function for getting the expected acknowledgement number.
- *
- * @return expected acknowledgement number.
- */
-static __INLINE uint8_t expected_ack_number_get(void)
-{
- uint8_t seq_nmbr = packet_number_to_transmit_get();
- ++seq_nmbr;
- seq_nmbr &= 0x07u;
-
- return seq_nmbr;
-}
-
-
-/**@brief Function for processing a received acknowledgement packet.
- *
- * Verifies does the received acknowledgement packet has the expected acknowledgement number and
- * that the header checksum is correct.
- *
- * @param[in] p_buffer Pointer to the packet data.
- *
- * @return true if valid acknowledgement packet received.
- */
-static __INLINE bool rx_ack_pkt_type_handle(const uint8_t * p_buffer)
-{
- // @note: no pointer validation check needed as allready checked by calling function.
-
- // Verify header checksum.
- const uint32_t expected_checksum =
- ((p_buffer[0] + p_buffer[1] + p_buffer[2] + p_buffer[3])) & 0xFFu;
- if (expected_checksum != 0)
- {
- return false;
- }
-
- const uint8_t ack_number = (p_buffer[0] >> 3u) & 0x07u;
-
- // Verify expected acknowledgment number.
- return (ack_number == expected_ack_number_get());
-}
-
-
-/**@brief Function for incrementing the sequence number counter of the TX packet.
- */
-static __INLINE void packet_number_tx_inc(void)
-{
- ++m_packet_transmit_seq_number;
- m_packet_transmit_seq_number &= 0x07u;
-}
-
-
-/**@brief Function for TX state machine event processing in a state centric manner.
- *
- * @param[in] event Type of event occurred.
- */
-static void tx_sm_event_handle(tx_event_t event)
-{
- uint32_t err_code;
-
- switch (m_tx_state)
- {
- case TX_STATE_IDLE:
- if (event == TX_EVENT_STATE_ENTRY)
- {
- err_code = app_timer_stop(m_app_timer_id);
- APP_ERROR_CHECK(err_code);
-
- // Send TX-done event if registered handler exists.
- if (m_transport_tx_done_handle != NULL)
- {
- m_transport_tx_done_handle(m_tx_done_result_code);
- }
- }
- break;
-
- case TX_STATE_PENDING:
- if (event == TX_EVENT_SLIP_TX_DONE)
- {
- // @note: this call should always succeed as called from HCI_SLIP_TX_DONE context
- // and error cases are managed by dedicated error event from the slip layer.
- err_code = hci_slip_write(mp_tx_buffer,
- (m_tx_buffer_length + PKT_HDR_SIZE + PKT_CRC_SIZE));
- APP_ERROR_CHECK(err_code);
- tx_sm_state_change(TX_STATE_ACTIVE);
- }
- break;
-
- case TX_STATE_ACTIVE:
- switch (event)
- {
- case TX_EVENT_VALID_RX_ACK:
- // Tx sequence number counter incremented as packet transmission
- // acknowledged by peer transport entity.
- packet_number_tx_inc();
- tx_sm_state_change(TX_STATE_IDLE);
- break;
-
- case TX_EVENT_STATE_ENTRY:
- m_tx_retry_counter = 0;
- err_code = app_timer_start(m_app_timer_id,
- RETRANSMISSION_TIMEOUT_IN_TICKS,
- NULL);
- APP_ERROR_CHECK(err_code);
- break;
-
- case TX_EVENT_TIMEOUT:
- if (m_tx_retry_counter != MAX_RETRY_COUNT)
- {
- ++m_tx_retry_counter;
- // @note: no return value check done for hci_slip_write(...) call as current
- // system design allows use case where retransmission is not accepted by the
- // slip layer due to existing acknowledgement packet transmission in the
- // slip layer.
- UNUSED_VARIABLE(hci_slip_write(mp_tx_buffer,
- (m_tx_buffer_length +
- PKT_HDR_SIZE +
- PKT_CRC_SIZE)));
- }
- else
- {
- // Application packet retransmission count reached:
- // - set correct TX done event callback function result code
- // - execute state change
- // @note: m_tx_retry_counter is reset in TX_STATE_ACTIVE state entry.
- m_tx_done_result_code = HCI_TRANSPORT_TX_DONE_FAILURE;
- tx_sm_state_change(TX_STATE_IDLE);
- }
- break;
-
- default:
- // No implementation needed.
- break;
- }
- break;
-
- default:
- // No implementation needed.
- break;
- }
-}
-
-
-/**@brief Function for changing the state of the TX state machine.
- *
- * @param[in] new_state State TX state machine transits to.
- */
-static void tx_sm_state_change(tx_state_t new_state)
-{
- m_tx_state = new_state;
- tx_sm_event_handle(TX_EVENT_STATE_ENTRY);
-}
-
-
-/**@brief Function for handling slip events.
- *
- * @param[in] event The event structure.
- */
-void slip_event_handle(hci_slip_evt_t event)
-{
- uint32_t return_code;
- uint32_t err_code;
-
- switch (event.evt_type)
- {
- case HCI_SLIP_TX_DONE:
- tx_sm_event_handle(TX_EVENT_SLIP_TX_DONE);
- break;
-
- case HCI_SLIP_RX_RDY:
- return_code = packet_type_decode(event.packet, event.packet_length);
-
- switch (return_code)
- {
- case PKT_TYPE_VENDOR_SPECIFIC:
- rx_vendor_specific_pkt_type_handle(event.packet, event.packet_length);
- break;
-
- case PKT_TYPE_ACK:
- if (rx_ack_pkt_type_handle(event.packet))
- {
- // Valid expected acknowledgement packet received: set correct TX done event
- // callback function result code and execute state change.
- m_tx_done_result_code = HCI_TRANSPORT_TX_DONE_SUCCESS;
- tx_sm_event_handle(TX_EVENT_VALID_RX_ACK);
- }
-
- /* fall-through */
- default:
- // RX packet dropped: reset memory buffer to slip in order to avoid RX buffer
- // overflow.
- // If existing mem pool produced RX buffer exists reuse that one. If existing
- // mem pool produced RX buffer does not exist try to produce new one. If
- // producing fails use the internal acknowledgement buffer.
- if (mp_slip_used_rx_buffer != NULL)
- {
- err_code = hci_slip_rx_buffer_register(mp_slip_used_rx_buffer, RX_BUF_SIZE);
- APP_ERROR_CHECK(err_code);
- }
- else
- {
- err_code = hci_mem_pool_rx_produce(RX_BUF_SIZE,
- (void **)&mp_slip_used_rx_buffer);
- APP_ERROR_CHECK_BOOL((err_code == NRF_SUCCESS) ||
- (err_code == NRF_ERROR_NO_MEM));
-
- err_code = hci_slip_rx_buffer_register(
- (err_code == NRF_SUCCESS) ? mp_slip_used_rx_buffer : m_rx_ack_buffer,
- (err_code == NRF_SUCCESS) ? RX_BUF_SIZE : ACK_BUF_SIZE);
- APP_ERROR_CHECK(err_code);
- }
- break;
- }
- break;
-
- case HCI_SLIP_RX_OVERFLOW:
- err_code = hci_slip_rx_buffer_register(m_rx_ack_buffer, ACK_BUF_SIZE);
- APP_ERROR_CHECK(err_code);
- break;
-
- case HCI_SLIP_ERROR:
- APP_ERROR_HANDLER(event.evt_type);
- break;
-
- default:
- APP_ERROR_HANDLER(event.evt_type);
- break;
- }
-}
-
-
-uint32_t hci_transport_evt_handler_reg(hci_transport_event_handler_t event_handler)
-{
- uint32_t err_code;
-
- m_transport_event_handle = event_handler;
- err_code = hci_slip_evt_handler_register(slip_event_handle);
- APP_ERROR_CHECK(err_code);
-
- return (event_handler != NULL) ? NRF_SUCCESS : NRF_ERROR_NULL;
-}
-
-
-uint32_t hci_transport_tx_done_register(hci_transport_tx_done_handler_t event_handler)
-{
- uint32_t err_code;
-
- m_transport_tx_done_handle = event_handler;
- err_code = hci_slip_evt_handler_register(slip_event_handle);
- APP_ERROR_CHECK(err_code);
-
- return (event_handler != NULL) ? NRF_SUCCESS : NRF_ERROR_NULL;
-}
-
-
-/**@brief Function for handling the application packet retransmission timeout.
- *
- * This function is registered in the @ref app_timer module when a timer is created on
- * @ref hci_transport_open.
- *
- * @note This function must be executed in APP-LO context otherwise retransmission behaviour is
- * undefined, see @ref nrf51_system_integration_serialization.
- *
- * @param[in] p_context The timeout context.
- */
-void hci_transport_timeout_handle(void * p_context)
-{
- tx_sm_event_handle(TX_EVENT_TIMEOUT);
-}
-
-
-uint32_t hci_transport_open(void)
-{
- mp_tx_buffer = NULL;
- m_tx_buffer_length = 0;
- m_tx_retry_counter = 0;
- m_is_slip_decode_ready = false;
- m_tx_state = TX_STATE_IDLE;
- m_packet_expected_seq_number = INITIAL_ACK_NUMBER_EXPECTED;
- m_packet_transmit_seq_number = INITIAL_ACK_NUMBER_TX;
- m_tx_done_result_code = HCI_TRANSPORT_TX_DONE_FAILURE;
-
- uint32_t err_code = app_timer_create(&m_app_timer_id,
- APP_TIMER_MODE_REPEATED,
- hci_transport_timeout_handle);
- if (err_code != NRF_SUCCESS)
- {
- // @note: conduct required interface adjustment.
- return NRF_ERROR_INTERNAL;
- }
-
- err_code = hci_mem_pool_open();
- VERIFY_SUCCESS(err_code);
-
- err_code = hci_slip_open();
- VERIFY_SUCCESS(err_code);
-
- err_code = hci_mem_pool_rx_produce(RX_BUF_SIZE, (void **)&mp_slip_used_rx_buffer);
- if (err_code != NRF_SUCCESS)
- {
- // @note: conduct required interface adjustment.
- return NRF_ERROR_INTERNAL;
- }
-
- err_code = hci_slip_rx_buffer_register(mp_slip_used_rx_buffer, RX_BUF_SIZE);
-
- return err_code;
-}
-
-
-uint32_t hci_transport_close(void)
-{
- uint32_t err_code;
-
- m_transport_tx_done_handle = NULL;
- m_transport_event_handle = NULL;
-
- err_code = hci_mem_pool_close();
- APP_ERROR_CHECK(err_code);
- err_code = hci_slip_close();
- APP_ERROR_CHECK(err_code);
-
- // @note: NRF_ERROR_NO_MEM is the only return value which should never be returned.
- err_code = app_timer_stop(m_app_timer_id);
- APP_ERROR_CHECK_BOOL(err_code != NRF_ERROR_NO_MEM);
-
- return NRF_SUCCESS;
-}
-
-
-uint32_t hci_transport_tx_alloc(uint8_t ** pp_memory)
-{
- const uint32_t err_code = hci_mem_pool_tx_alloc((void **)pp_memory);
- if (err_code == NRF_SUCCESS)
- {
- // @note: no need to validate pp_memory against null as validation has already been done
- // by hci_mem_pool_tx_alloc(...) and visible to us from the method return code.
- //lint -e(413) "Likely use of null pointer"
- *pp_memory += PKT_HDR_SIZE;
- }
-
- return err_code;
-}
-
-
-uint32_t hci_transport_tx_free(void)
-{
- return hci_mem_pool_tx_free();
-}
-
-
-/**@brief Function for constructing 1st byte of the packet header of the packet to be transmitted.
- *
- * @return 1st byte of the packet header of the packet to be transmitted
- */
-static __INLINE uint8_t tx_packet_byte_zero_construct(void)
-{
- const uint32_t value = DATA_INTEGRITY_MASK |
- RELIABLE_PKT_MASK |
- (packet_number_expected_get() << 3u) |
- packet_number_to_transmit_get();
-
- return (uint8_t) value;
-}
-
-
-/**@brief Function for handling the application packet write request in tx-idle state.
- */
-static uint32_t pkt_write_handle(void)
-{
- uint32_t err_code;
-
- // Set packet header fields.
-
- mp_tx_buffer -= PKT_HDR_SIZE;
- mp_tx_buffer[0] = tx_packet_byte_zero_construct();
-
- const uint16_t type_and_length_fields = ((m_tx_buffer_length << 4u) | PKT_TYPE_VENDOR_SPECIFIC);
- // @note: no use case for uint16_encode(...) return value.
- UNUSED_VARIABLE(uint16_encode(type_and_length_fields, &(mp_tx_buffer[1])));
- mp_tx_buffer[3] = header_checksum_calculate(mp_tx_buffer);
-
- // Calculate, append CRC to the packet and write it.
-
- const uint16_t crc = crc16_compute(mp_tx_buffer, (PKT_HDR_SIZE + m_tx_buffer_length), NULL);
- // @note: no use case for uint16_encode(...) return value.
- UNUSED_VARIABLE(uint16_encode(crc, &(mp_tx_buffer[PKT_HDR_SIZE + m_tx_buffer_length])));
- err_code = hci_slip_write(mp_tx_buffer, (m_tx_buffer_length + PKT_HDR_SIZE + PKT_CRC_SIZE));
- switch (err_code)
- {
- case NRF_SUCCESS:
- tx_sm_state_change(TX_STATE_ACTIVE);
- break;
-
- case NRF_ERROR_NO_MEM:
- tx_sm_state_change(TX_STATE_PENDING);
- err_code = NRF_SUCCESS;
- break;
-
- default:
- // No implementation needed.
- break;
- }
-
- return err_code;
-}
-
-
-uint32_t hci_transport_pkt_write(const uint8_t * p_buffer, uint16_t length)
-{
- uint32_t err_code;
-
- if (p_buffer)
- {
- switch (m_tx_state)
- {
- case TX_STATE_IDLE:
- mp_tx_buffer = (uint8_t *)p_buffer;
- m_tx_buffer_length = length;
- err_code = pkt_write_handle();
- break;
-
- default:
- err_code = NRF_ERROR_NO_MEM;
- break;
- }
- }
- else
- {
- err_code = NRF_ERROR_NULL;
- }
-
- return err_code;
-}
-
-
-uint32_t hci_transport_rx_pkt_extract(uint8_t ** pp_buffer, uint16_t * p_length)
-{
- uint32_t err_code;
-
- if (pp_buffer != NULL && p_length != NULL)
- {
- uint32_t length = 0;
-
- if (m_is_slip_decode_ready)
- {
- m_is_slip_decode_ready = false;
- err_code = hci_mem_pool_rx_extract(pp_buffer, &length);
- length -= (PKT_HDR_SIZE + PKT_CRC_SIZE);
-
- *p_length = (uint16_t)length;
- *pp_buffer += PKT_HDR_SIZE;
- }
- else
- {
- err_code = NRF_ERROR_NO_MEM;
- }
- }
- else
- {
- err_code = NRF_ERROR_NULL;
- }
-
- return err_code;
-}
-
-
-uint32_t hci_transport_rx_pkt_consume(uint8_t * p_buffer)
-{
- return (hci_mem_pool_rx_consume(p_buffer - PKT_HDR_SIZE));
-}
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/libraries/hci/hci_transport.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/hci/hci_transport.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/hci/hci_transport.h
deleted file mode 100644
index c09203a..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/hci/hci_transport.h
+++ /dev/null
@@ -1,228 +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.
- *
- */
-
-/**@file
- *
- * @defgroup hci_transport HCI Transport
- * @{
- * @ingroup app_common
- *
- * @brief HCI transport module implementation.
- *
- * This module implements certain specific features from the three-wire UART transport layer,
- * defined by the Bluetooth specification version 4.0 [Vol 4] part D.
- *
- * \par Features supported
- * - Transmission and reception of Vendor Specific HCI packet type application packets.
- * - Transmission and reception of reliable packets: defined by chapter 6 of the specification.
- *
- * \par Features not supported
- * - Link establishment procedure: defined by chapter 8 of the specification.
- * - Low power: defined by chapter 9 of the specification.
- *
- * \par Implementation specific behaviour
- * - As Link establishment procedure is not supported following static link configuration parameters
- * are used:
- * + TX window size is 1.
- * + 16 bit CCITT-CRC must be used.
- * + Out of frame software flow control not supported.
- * + Parameters specific for resending reliable packets are compile time configurable (clarifed
- * later in this document).
- * + Acknowledgement packet transmissions are not timeout driven , meaning they are delivered for
- * transmission within same context which the corresponding application packet was received.
- *
- * \par Implementation specific limitations
- * Current implementation has the following limitations which will have impact to system wide
- * behaviour:
- * - Delayed acknowledgement scheduling not implemented:
- * There exists a possibility that acknowledgement TX packet and application TX packet will collide
- * in the TX pipeline having the end result that acknowledgement packet will be excluded from the TX
- * pipeline which will trigger the retransmission algorithm within the peer protocol entity.
- * - Delayed retransmission scheduling not implemented:
- * There exists a possibility that retransmitted application TX packet and acknowledgement TX packet
- * will collide in the TX pipeline having the end result that retransmitted application TX packet
- * will be excluded from the TX pipeline.
- * - Processing of the acknowledgement number from RX application packets:
- * Acknowledgement number is not processed from the RX application packets having the end result
- * that unnecessary application packet retransmissions can occur.
- *
- * The application TX packet processing flow is illustrated by the statemachine below.
- *
- * @image html hci_transport_tx_sm.png "TX - application packet statemachine"
- *
- * \par Component specific configuration options
- *
- * The following compile time configuration options are available, and used to configure the
- * application TX packet retransmission interval, in order to suite various application specific
- * implementations:
- * - MAC_PACKET_SIZE_IN_BITS Maximum size of a single application packet in bits.
- * - USED_BAUD_RATE Used uart baudrate.
- *
- * The following compile time configuration option is available to configure module specific
- * behaviour:
- * - MAX_RETRY_COUNT Max retransmission retry count for applicaton packets.
- */
-
-#ifndef HCI_TRANSPORT_H__
-#define HCI_TRANSPORT_H__
-
-#include <stdint.h>
-#include "nrf_error.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**@brief Generic event callback function events. */
-typedef enum
-{
- HCI_TRANSPORT_RX_RDY, /**< An event indicating that RX packet is ready for read. */
- HCI_TRANSPORT_EVT_TYPE_MAX /**< Enumeration upper bound. */
-} hci_transport_evt_type_t;
-
-/**@brief Struct containing events from the Transport layer.
- */
-typedef struct
-{
- hci_transport_evt_type_t evt_type; /**< Type of event. */
-} hci_transport_evt_t;
-
-/**@brief Transport layer generic event callback function type.
- *
- * @param[in] event Transport layer event.
- */
-typedef void (*hci_transport_event_handler_t)(hci_transport_evt_t event);
-
-/**@brief TX done event callback function result codes. */
-typedef enum
-{
- HCI_TRANSPORT_TX_DONE_SUCCESS, /**< Transmission success, peer transport entity has acknowledged the transmission. */
- HCI_TRANSPORT_TX_DONE_FAILURE /**< Transmission failure. */
-} hci_transport_tx_done_result_t;
-
-/**@brief Transport layer TX done event callback function type.
- *
- * @param[in] result TX done event result code.
- */
-typedef void (*hci_transport_tx_done_handler_t)(hci_transport_tx_done_result_t result);
-
-/**@brief Function for registering a generic event handler.
- *
- * @note Multiple registration requests will overwrite any possible existing registration.
- *
- * @param[in] event_handler The function to be called by the transport layer upon an event.
- *
- * @retval NRF_SUCCESS Operation success.
- * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
- */
-uint32_t hci_transport_evt_handler_reg(hci_transport_event_handler_t event_handler);
-
-/**@brief Function for registering a handler for TX done event.
- *
- * @note Multiple registration requests will overwrite any possible existing registration.
- *
- * @param[in] event_handler The function to be called by the transport layer upon TX done
- * event.
- *
- * @retval NRF_SUCCESS Operation success.
- * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
- */
-uint32_t hci_transport_tx_done_register(hci_transport_tx_done_handler_t event_handler);
-
-/**@brief Function for opening the transport channel and initializing the transport layer.
- *
- * @warning Must not be called for a channel which has been allready opened.
- *
- * @retval NRF_SUCCESS Operation success.
- * @retval NRF_ERROR_INTERNAL Operation failure. Internal error ocurred.
- */
-uint32_t hci_transport_open(void);
-
-/**@brief Function for closing the transport channel.
- *
- * @note Can be called multiple times and also for not opened channel.
- *
- * @retval NRF_SUCCESS Operation success.
- */
-uint32_t hci_transport_close(void);
-
-/**@brief Function for allocating tx packet memory.
- *
- * @param[out] pp_memory Pointer to the packet data.
- *
- * @retval NRF_SUCCESS Operation success. Memory was allocated.
- * @retval NRF_ERROR_NO_MEM Operation failure. No memory available.
- * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
- */
-uint32_t hci_transport_tx_alloc(uint8_t ** pp_memory);
-
-/**@brief Function for freeing tx packet memory.
- *
- * @note Memory management works in FIFO principle meaning that free order must match the alloc
- * order.
- *
- * @retval NRF_SUCCESS Operation success. Memory was freed.
- */
-uint32_t hci_transport_tx_free(void);
-
-/**@brief Function for writing a packet.
- *
- * @note Completion of this method does not guarantee that actual peripheral transmission would
- * have completed.
- *
- * @note In case of 0 byte packet length write request, message will consist of only transport
- * module specific headers.
- *
- * @retval NRF_SUCCESS Operation success. Packet was added to the transmission queue
- * and an event will be send upon transmission completion.
- * @retval NRF_ERROR_NO_MEM Operation failure. Transmission queue is full and packet was not
- * added to the transmission queue. User should wait for
- * a appropriate event prior issuing this operation again.
- * @retval NRF_ERROR_DATA_SIZE Operation failure. Packet size exceeds limit.
- * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
- * @retval NRF_ERROR_INVALID_STATE Operation failure. Channel is not open.
- */
-uint32_t hci_transport_pkt_write(const uint8_t * p_buffer, uint16_t length);
-
-/**@brief Function for extracting received packet.
- *
- * @note Extracted memory can't be reused by the underlying transport layer untill freed by call to
- * hci_transport_rx_pkt_consume().
- *
- * @param[out] pp_buffer Pointer to the packet data.
- * @param[out] p_length Length of packet data in bytes.
- *
- * @retval NRF_SUCCESS Operation success. Packet was extracted.
- * @retval NRF_ERROR_NO_MEM Operation failure. No packet available to extract.
- * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
- */
-uint32_t hci_transport_rx_pkt_extract(uint8_t ** pp_buffer, uint16_t * p_length);
-
-/**@brief Function for consuming extracted packet described by p_buffer.
- *
- * RX memory pointed to by p_buffer is freed and can be reused by the underlying transport layer.
- *
- * @param[in] p_buffer Pointer to the buffer that has been consumed.
- *
- * @retval NRF_SUCCESS Operation success.
- * @retval NRF_ERROR_NO_MEM Operation failure. No packet available to consume.
- * @retval NRF_ERROR_INVALID_ADDR Operation failure. Not a valid pointer.
- */
-uint32_t hci_transport_rx_pkt_consume(uint8_t * p_buffer);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // HCI_TRANSPORT_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/libraries/ic_info/nrf_ic_info.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ic_info/nrf_ic_info.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ic_info/nrf_ic_info.c
deleted file mode 100644
index 1572053..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ic_info/nrf_ic_info.c
+++ /dev/null
@@ -1,67 +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_ic_info.h"
-#include "nrf.h"
-
-#define PART_NO_NRF51 0x01
-#define PART_NO_NRF52 0x06
-
-void nrf_ic_info_get(nrf_ic_info_t * p_ic_info)
-{
- uint32_t ic_data = ((*((uint32_t volatile *)0xF0000FE8)) & 0x000000F0) >> 4;
- uint32_t ic_part_no = ((*((uint32_t volatile *)0xF0000FE0)) & 0x000000FF);
-
- switch (ic_part_no)
- {
-#if defined(NRF51)
- case PART_NO_NRF51:
- {
- p_ic_info->ram_size = (uint16_t) NRF_FICR->NUMRAMBLOCK;
- p_ic_info->ram_size *= (uint16_t) (NRF_FICR->SIZERAMBLOCKS / 1024);
- p_ic_info->flash_size = (uint16_t) NRF_FICR->CODESIZE;
-
- switch (ic_data)
- {
- /** IC revision 1 */
- case 1:
- p_ic_info->ic_revision = IC_REVISION_NRF51_REV1;
- break;
-
- /** IC revision 2 */
- case 4:
- p_ic_info->ic_revision = IC_REVISION_NRF51_REV2;
- break;
-
- /** IC revision 3 */
- case 7:
- /* fall through */
- case 8:
- /* fall through */
- case 9:
- p_ic_info->ic_revision = IC_REVISION_NRF51_REV3;
- break;
-
- default:
- p_ic_info->ic_revision = IC_REVISION_NRF51_UNKNOWN;
- break;
- }
- break;
- }
-#endif
- default:
- p_ic_info->ic_revision = IC_PART_UNKNOWN;
- p_ic_info->flash_size = 0;
- p_ic_info->ram_size = 0;
- break;
- }
-}
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/libraries/ic_info/nrf_ic_info.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ic_info/nrf_ic_info.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ic_info/nrf_ic_info.h
deleted file mode 100644
index db40097..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ic_info/nrf_ic_info.h
+++ /dev/null
@@ -1,65 +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_ic_info IC information
- * @{
- * @ingroup app_common
- *
- * @brief Library for checking IC information (IC revision, RAM size, FLASH size).
- *
- */
-
-#ifndef NRF51_IC_INFO_H__
-#define NRF51_IC_INFO_H__
-
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**@brief Enum identifying the IC revision as described in the Compatibility Matrix. */
-typedef enum
-{
- IC_PART_UNKNOWN = 0, /**< IC Revision unknown. */
- IC_REVISION_NRF51_REV1, /**< IC Revision 1. */
- IC_REVISION_NRF51_REV2, /**< IC Revision 2. */
- IC_REVISION_NRF51_REV3, /**< IC Revision 3. */
- IC_REVISION_NRF51_UNKNOWN /**< IC Revision unknown. */
-} nrf_ic_revision_t;
-
- /**@brief IC information struct containing the IC revision, RAM size, and FLASH size. */
-typedef struct
-{
- nrf_ic_revision_t ic_revision; /**< IC revision. */
- uint16_t ram_size; /**< RAM size in kB (16 = 16 kB RAM). */
- uint16_t flash_size; /**< FLASH size in kB (256 = 256 kB FLASH). */
-} nrf_ic_info_t;
-
-
-/**@brief Function for returning information about the IC revision, the RAM size, and the FLASH size.
- *
- * @param[out] p_ic_info Struct containing IC revision, RAM size, and FLASH size.
- *
- */
-void nrf_ic_info_get(nrf_ic_info_t* p_ic_info);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // NRF51_IC_INFO_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/libraries/led_softblink/led_softblink.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/led_softblink/led_softblink.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/led_softblink/led_softblink.c
deleted file mode 100644
index 71b2359..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/led_softblink/led_softblink.c
+++ /dev/null
@@ -1,201 +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 <string.h>
-#include "led_softblink.h"
-#include "nrf_gpio.h"
-#include "app_timer.h"
-#include "nrf_assert.h"
-#include "low_power_pwm.h"
-
-/* Period for LED softblink PWM. */
-#define PWM_PERIOD UINT8_MAX
-
-/**@bref Structure to handle timer time-outs
- *
- */
-typedef struct
-{
- bool leds_is_on; /**< Flag for indicating if LEDs are on. */
- bool is_counting_up; /**< Flag for indicating if counter is incrementing or decrementing. */
- nrf_drv_state_t led_sb_state; /**< Indicates current state of instance. */
- uint16_t duty_cycle; /**< Current pulse width. */
- uint32_t bit_mask; /**< Mask of used pins. */
- led_sb_init_params_t params; /**< Structure holding initialization parameters. */
- low_power_pwm_config_t pwm_config; /**< Structure holding parameters for initializing low level layer. */
- low_power_pwm_t pwm_instance; /**< Structure holding low-power PWM instance parameters. */
-}led_sb_context_t;
-
-static led_sb_context_t m_led_sb = {0};
-
-/**@brief Timer event handler for softblink.
- *
- * @param[in] p_context General purpose pointer. Will be passed to the time-out handler
- * when the timer expires.
- *
- */
-static void led_softblink_on_timeout(void * p_context)
-{
- static int32_t pause_ticks;
- ASSERT(m_led_sb.led_sb_state != NRF_DRV_STATE_UNINITIALIZED);
- ret_code_t err_code;
-
- if(pause_ticks <= 0)
- {
- if (m_led_sb.is_counting_up)
- {
- if (m_led_sb.duty_cycle >= (m_led_sb.params.duty_cycle_max - m_led_sb.params.duty_cycle_step))
- {
- // Max PWM duty cycle is reached, start decrementing.
- m_led_sb.is_counting_up = false;
- m_led_sb.duty_cycle = m_led_sb.params.duty_cycle_max;
- pause_ticks = m_led_sb.params.on_time_ticks ? m_led_sb.params.on_time_ticks + APP_TIMER_MIN_TIMEOUT_TICKS : 0;
- }
- else
- {
- m_led_sb.duty_cycle += m_led_sb.params.duty_cycle_step;
- }
- }
- else
- {
- if (m_led_sb.duty_cycle <= (m_led_sb.params.duty_cycle_min + m_led_sb.params.duty_cycle_step))
- {
- // Min PWM duty cycle is reached, start incrementing.
- m_led_sb.is_counting_up = true;
- m_led_sb.duty_cycle = m_led_sb.params.duty_cycle_min;
- pause_ticks = m_led_sb.params.off_time_ticks ? m_led_sb.params.off_time_ticks + APP_TIMER_MIN_TIMEOUT_TICKS : 0;
- }
- else
- {
- m_led_sb.duty_cycle -= m_led_sb.params.duty_cycle_step;
- }
- }
- }
- else
- {
- pause_ticks -= PWM_PERIOD;
- }
-
- err_code = low_power_pwm_duty_set(&m_led_sb.pwm_instance, m_led_sb.duty_cycle);
-
- APP_ERROR_CHECK(err_code);
-}
-
-
-ret_code_t led_softblink_init(led_sb_init_params_t * p_init_params)
-{
- ret_code_t err_code;
-
- ASSERT(m_led_sb.led_sb_state == NRF_DRV_STATE_UNINITIALIZED);
-
- ASSERT(p_init_params);
-
- if ( (p_init_params->duty_cycle_max == 0) ||
- (p_init_params->duty_cycle_max <= p_init_params->duty_cycle_min) ||
- (p_init_params->duty_cycle_step == 0) ||
- (p_init_params->leds_pin_bm == 0))
- {
- return NRF_ERROR_INVALID_PARAM;
- }
-
-
-
- memset(&m_led_sb, 0, sizeof(led_sb_context_t));
- memcpy(&m_led_sb.params, p_init_params, sizeof(led_sb_init_params_t));
-
- m_led_sb.is_counting_up = true;
- m_led_sb.duty_cycle = p_init_params->duty_cycle_min + p_init_params->duty_cycle_step;
- m_led_sb.leds_is_on = false;
- m_led_sb.bit_mask = p_init_params->leds_pin_bm;
-
- APP_TIMER_DEF(led_softblink_timer);
-
- m_led_sb.pwm_config.active_high = m_led_sb.params.active_high;
- m_led_sb.pwm_config.bit_mask = p_init_params->leds_pin_bm;
- m_led_sb.pwm_config.period = PWM_PERIOD;
- m_led_sb.pwm_config.p_timer_id = &led_softblink_timer;
-
- err_code = low_power_pwm_init( &m_led_sb.pwm_instance, &m_led_sb.pwm_config, led_softblink_on_timeout);
-
- if (err_code == NRF_SUCCESS)
- {
- m_led_sb.led_sb_state = NRF_DRV_STATE_INITIALIZED;
- }
- else
- {
- return err_code;
- }
-
- err_code = low_power_pwm_duty_set( &m_led_sb.pwm_instance, p_init_params->duty_cycle_min + p_init_params->duty_cycle_step);
-
- return err_code;
-}
-
-
-ret_code_t led_softblink_start(uint32_t leds_pin_bit_mask)
-{
- ret_code_t err_code;
-
- ASSERT(m_led_sb.led_sb_state == NRF_DRV_STATE_INITIALIZED);
-
- err_code = low_power_pwm_start(&m_led_sb.pwm_instance, leds_pin_bit_mask);
-
- return err_code;
-}
-
-
-ret_code_t led_softblink_stop(void)
-{
- ret_code_t err_code;
-
- err_code = low_power_pwm_stop(&m_led_sb.pwm_instance);
-
- return err_code;
-}
-
-
-void led_softblink_off_time_set(uint32_t off_time_ticks)
-{
- ASSERT(m_led_sb.led_sb_state != NRF_DRV_STATE_UNINITIALIZED);
-
- m_led_sb.params.off_time_ticks = off_time_ticks;
-}
-
-
-void led_softblink_on_time_set(uint32_t on_time_ticks)
-{
- ASSERT(m_led_sb.led_sb_state != NRF_DRV_STATE_UNINITIALIZED);
-
- m_led_sb.params.on_time_ticks = on_time_ticks;
-}
-
-
-ret_code_t led_softblink_uninit(void)
-{
- ASSERT(m_led_sb.led_sb_state != NRF_DRV_STATE_UNINITIALIZED);
-
- ret_code_t err_code;
-
- err_code = led_softblink_stop();
-
- if (err_code == NRF_SUCCESS)
- {
- m_led_sb.led_sb_state = NRF_DRV_STATE_UNINITIALIZED;
- }
- else
- {
- return err_code;
- }
-
- memset(&m_led_sb, 0, sizeof(m_led_sb));
-
- return NRF_SUCCESS;
-}
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/libraries/led_softblink/led_softblink.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/led_softblink/led_softblink.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/led_softblink/led_softblink.h
deleted file mode 100644
index 4aa976b..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/led_softblink/led_softblink.h
+++ /dev/null
@@ -1,139 +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 led_softblink LED softblink
- * @{
- * @ingroup app_common
- *
- * @brief Module for generating a changing pulse-width modulated output signal that is used to smoothly blink LEDs.
- *
- * @details This module provides an LED softblink implementation using timers and GPIO.
- *
- * LED softblink needs one timer. It can use any number of output channels that are available.
- *
- * Only one instance of LED softblink can run at a time.
- */
-
-#ifndef LED_SOFTBLINK_H__
-#define LED_SOFTBLINK_H__
-
-#include <stdbool.h>
-#include <stdint.h>
-#include "sdk_errors.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief Structure holding the initialization parameters.
- */
-typedef struct
-{
- bool active_high; /**< Activate negative polarity. */
- uint8_t duty_cycle_max; /**< Maximum impulse width. */
- uint8_t duty_cycle_min; /**< Minimum impulse width. */
- uint8_t duty_cycle_step; /**< Cycle step. */
- uint32_t off_time_ticks; /**< Ticks to stay in low impulse state. */
- uint32_t on_time_ticks; /**< Ticks to stay in high impulse state. */
- uint32_t leds_pin_bm; /**< Mask of used LEDs. */
-}led_sb_init_params_t;
-
-/**
- * @name Default settings
- * @brief Default settings for LED softblink.
- * @{
- */
-#define LED_SB_INIT_PARAMS_ACTIVE_HIGH false
-#define LED_SB_INIT_PARAMS_DUTY_CYCLE_MAX 220
-#define LED_SB_INIT_PARAMS_DUTY_CYCLE_MIN 0
-#define LED_SB_INIT_PARAMS_DUTY_CYCLE_STEP 5
-#define LED_SB_INIT_PARAMS_OFF_TIME_TICKS 65536
-#define LED_SB_INIT_PARAMS_ON_TIME_TICKS 0
-#define LED_SB_INIT_PARAMS_LEDS_PIN_BM(mask) (mask)
-/** @} */
-
-/**
- * @brief LED softblink default configuration.
- */
-#define LED_SB_INIT_DEFAULT_PARAMS(mask) \
-{ \
- .active_high = LED_SB_INIT_PARAMS_ACTIVE_HIGH, \
- .duty_cycle_max = LED_SB_INIT_PARAMS_DUTY_CYCLE_MAX, \
- .duty_cycle_min = LED_SB_INIT_PARAMS_DUTY_CYCLE_MIN, \
- .duty_cycle_step = LED_SB_INIT_PARAMS_DUTY_CYCLE_STEP, \
- .off_time_ticks = LED_SB_INIT_PARAMS_OFF_TIME_TICKS, \
- .on_time_ticks = LED_SB_INIT_PARAMS_ON_TIME_TICKS, \
- .leds_pin_bm = LED_SB_INIT_PARAMS_LEDS_PIN_BM(mask) \
-}
-
-/**
- * @brief Function for initializing LED softblink.
- *
- * @param[in] p_init_params Pointer to the initialization structure.
- *
- * @return Values returned by @ref app_timer_create.
- */
-ret_code_t led_softblink_init(led_sb_init_params_t * p_init_params);
-
-/**
- * @brief Function for starting to blink LEDs.
- *
- * @param[in] leds_pin_bit_mask Bit mask containing the pins for the LEDs to be blinked.
- *
- * @return Values returned by @ref app_timer_start.
- */
-ret_code_t led_softblink_start(uint32_t leds_pin_bit_mask);
-
-/**
- * @brief Function for stopping to blink LEDs.
- *
- * @return Values returned by @ref app_timer_stop.
- */
-ret_code_t led_softblink_stop(void);
-
-/**
- * @brief Function for setting the off time.
- *
- * This function configures the time that the LEDs will be off between each blink.
- *
- * @param[in] off_time_ticks Off time in ticks.
- *
- */
-void led_softblink_off_time_set(uint32_t off_time_ticks);
-
-/**
- * @brief Function for setting the on time.
- *
- * This function configures the time that the LEDs will be on between each blink.
- *
- * @param[in] on_time_ticks On time in ticks.
- *
- */
-void led_softblink_on_time_set(uint32_t on_time_ticks);
-
-/**
- * @brief Function for uninitializing LED softblink.
- *
- * @retval NRF_SUCCESS If LED softblink was uninitialized successfully.
- */
-ret_code_t led_softblink_uninit(void);
-#ifdef __cplusplus
-}
-#endif
-
-#endif // LED_SOFTBLINK_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/libraries/low_power_pwm/low_power_pwm.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/low_power_pwm/low_power_pwm.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/low_power_pwm/low_power_pwm.c
deleted file mode 100644
index 4408547..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/low_power_pwm/low_power_pwm.c
+++ /dev/null
@@ -1,216 +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 <string.h>
-#include "low_power_pwm.h"
-#include "nrf_gpio.h"
-#include "app_timer.h"
-#include "nrf_assert.h"
-
-/**
- * @brief Function for turning on LEDs.
- *
- * Sets the pin high state according to active_high parameter.
- *
- * @param[in] p_pwm_instance Pointer to instance of low-power PWM.
- */
-__STATIC_INLINE void led_on(low_power_pwm_t * p_pwm_instance)
-{
- if (p_pwm_instance->active_high)
- {
- nrf_gpio_pins_set(p_pwm_instance->bit_mask_toggle);
- }
- else
- {
- nrf_gpio_pins_clear(p_pwm_instance->bit_mask_toggle);
- }
- p_pwm_instance->led_is_on = true;
-}
-
-
-/**
- * @brief Function for turning off LEDs.
- *
- * Sets the pin low state according to active_high parameter.
- *
- * @param[in] p_pwm_instance Pointer to instance of low-power PWM.
- */
-__STATIC_INLINE void led_off(low_power_pwm_t * p_pwm_instance)
-{
- if (p_pwm_instance->active_high)
- {
- nrf_gpio_pins_clear(p_pwm_instance->bit_mask_toggle);
- }
- else
- {
- nrf_gpio_pins_set(p_pwm_instance->bit_mask_toggle);
- }
- p_pwm_instance->led_is_on = false;
-}
-
-
-/**
- * @brief Timer event handler for PWM.
- *
- * @param[in] p_context General purpose pointer. Will be passed to the time-out handler
- * when the timer expires.
- *
- */
-static void pwm_timeout_handler(void * p_context)
-{
- ret_code_t err_code;
- uint8_t duty_cycle;
-
- low_power_pwm_t * p_pwm_instance = (low_power_pwm_t *)p_context;
-
- p_pwm_instance->pwm_state = NRF_DRV_STATE_INITIALIZED;
-
- if(p_pwm_instance->evt_type == LOW_POWER_PWM_EVENT_PERIOD)
- {
- if (p_pwm_instance->handler)
- {
- p_pwm_instance->handler(p_pwm_instance);
- }
-
- duty_cycle = p_pwm_instance->duty_cycle;
-
- if(duty_cycle == p_pwm_instance->period) // Process duty cycle 100%
- {
- led_on(p_pwm_instance);
- p_pwm_instance->timeout_ticks = p_pwm_instance->period + APP_TIMER_MIN_TIMEOUT_TICKS;
- }
- else if (duty_cycle == 0) // Process duty cycle 0%
- {
- led_off(p_pwm_instance);
- p_pwm_instance->timeout_ticks = p_pwm_instance->period + APP_TIMER_MIN_TIMEOUT_TICKS;
- }
- else // Process any other duty cycle than 0 or 100%
- {
- led_on(p_pwm_instance);
- p_pwm_instance->timeout_ticks = ((duty_cycle*p_pwm_instance->period)>>8) +
- APP_TIMER_MIN_TIMEOUT_TICKS;
- // setting next state
- p_pwm_instance->evt_type = LOW_POWER_PWM_EVENT_DUTY_CYCLE;
- }
- }
- else
- {
- led_off(p_pwm_instance);
- p_pwm_instance->evt_type = LOW_POWER_PWM_EVENT_PERIOD;
- p_pwm_instance->timeout_ticks = (((p_pwm_instance->period - p_pwm_instance->duty_cycle)*p_pwm_instance->period)>>8) +
- APP_TIMER_MIN_TIMEOUT_TICKS;
- }
-
- if (p_pwm_instance->pwm_state == NRF_DRV_STATE_INITIALIZED)
- {
- err_code = app_timer_start(*p_pwm_instance->p_timer_id, p_pwm_instance->timeout_ticks, p_pwm_instance);
- APP_ERROR_CHECK(err_code);
- }
-}
-
-
-ret_code_t low_power_pwm_init(low_power_pwm_t * p_pwm_instance, low_power_pwm_config_t const * p_pwm_config, app_timer_timeout_handler_t handler)
-{
- ASSERT(p_pwm_instance->pwm_state == NRF_DRV_STATE_UNINITIALIZED);
- ASSERT(p_pwm_config->bit_mask != 0);
- ASSERT(p_pwm_config->period != 0);
-
- ret_code_t err_code;
- uint32_t bit_mask;
- uint32_t pin_number = 0;
-
- p_pwm_instance->handler = handler;
-
- bit_mask = p_pwm_config->bit_mask;
-
- p_pwm_instance->active_high = p_pwm_config->active_high;
- p_pwm_instance->bit_mask = p_pwm_config->bit_mask;
- p_pwm_instance->bit_mask_toggle = p_pwm_config->bit_mask;
- p_pwm_instance->period = p_pwm_config->period;
- p_pwm_instance->p_timer_id = p_pwm_config->p_timer_id;
-
- err_code = app_timer_create(p_pwm_instance->p_timer_id, APP_TIMER_MODE_SINGLE_SHOT, pwm_timeout_handler);
-
- if (err_code != NRF_SUCCESS)
- {
- return err_code;
- }
-
- while (bit_mask)
- {
- if (bit_mask & 0x1UL)
- {
- nrf_gpio_cfg_output(pin_number);
- }
-
- pin_number++;
- bit_mask >>= 1UL;
- }
-
- led_off(p_pwm_instance);
- p_pwm_instance->pwm_state = NRF_DRV_STATE_INITIALIZED;
-
- return NRF_SUCCESS;
-}
-
-
-ret_code_t low_power_pwm_start(low_power_pwm_t * p_pwm_instance,
- uint32_t leds_pin_bit_mask)
-{
- ASSERT(p_pwm_instance->pwm_state == NRF_DRV_STATE_INITIALIZED);
- ASSERT(((~p_pwm_instance->bit_mask) & leds_pin_bit_mask) == false);
-
- p_pwm_instance->pwm_state = NRF_DRV_STATE_POWERED_ON;
- p_pwm_instance->bit_mask_toggle = leds_pin_bit_mask;
-
- led_off(p_pwm_instance);
-
- p_pwm_instance->bit_mask = leds_pin_bit_mask;
- p_pwm_instance->evt_type = LOW_POWER_PWM_EVENT_PERIOD;
- pwm_timeout_handler(p_pwm_instance);
-
- return NRF_SUCCESS;
-}
-
-
-ret_code_t low_power_pwm_stop(low_power_pwm_t * p_pwm_instance)
-{
- ASSERT(p_pwm_instance->pwm_state == NRF_DRV_STATE_POWERED_ON);
-
- ret_code_t err_code;
-
- err_code = app_timer_stop(*p_pwm_instance->p_timer_id);
-
- led_off(p_pwm_instance);
-
- if (err_code != NRF_SUCCESS)
- {
- return err_code;
- }
-
- p_pwm_instance->pwm_state = NRF_DRV_STATE_INITIALIZED;
-
-
- return NRF_SUCCESS;
-}
-
-
-ret_code_t low_power_pwm_duty_set(low_power_pwm_t * p_pwm_instance, uint8_t duty_cycle)
-{
- if ( p_pwm_instance->period < duty_cycle)
- {
- return NRF_ERROR_INVALID_PARAM;
- }
-
- p_pwm_instance->duty_cycle = duty_cycle;
-
- return NRF_SUCCESS;
-}