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/serialization/common/transport/ser_phy/ser_phy_nrf51_uart_stm_conn.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/common/transport/ser_phy/ser_phy_nrf51_uart_stm_conn.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/common/transport/ser_phy/ser_phy_nrf51_uart_stm_conn.c deleted file mode 100644 index 9422682..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/common/transport/ser_phy/ser_phy_nrf51_uart_stm_conn.c +++ /dev/null @@ -1,784 +0,0 @@ -/* Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * 4. This software must only be used in a processor manufactured by Nordic - * Semiconductor ASA, or in a processor manufactured by STMicroelectronics that - * is used in combination with a processor manufactured by Nordic Semiconductor - * or in a processor manufactured by STMicroelectronics. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - -#include <stdint.h> -#include <stdlib.h> - -#include "nordic_common.h" -#include "boards.h" -#include "nrf.h" -#include "nrf_soc.h" -#include "nrf_error.h" -#include "nrf_gpio.h" -#include "nrf_delay.h" -#include "app_util_platform.h" -#include "app_gpiote.h" -#include "ser_phy.h" -#include "ser_phy_config_conn_nrf51.h" - -#define APP_GPIOTE_MAX_USERS 1 -#define UART_PIN_DISCONNECTED 0xFFFFFFFF /**< Value indicating that no pin is connected to this UART register. */ - -/** @brief States for the app_uart state machine. */ -typedef enum -{ - UART_IDLE, /**< Indicating that the current status for either RX or TX is idle. When both RX and TX is idle the UART will be disabled in order to save power. */ - UART_RX, /**< Used to indicate that a packet is currently being received on RX. */ - UART_RX_PENDING, /**< Used to indicate that byte is ready at RXD register but no buffer was available when the byte was received. The byte will be pulled when a buffer is set. */ - UART_TX_COMPLETE, /**< Used on TX to indicate that final byte has been put on TXD register. Next TXDRDY interrupt will indicate that last byte has been transmitted. */ - UART_TX_SEND, /**< Used to indicate that a packet is currently being transmitted on TX. */ - UART_TX_LAST_BYTE_WAIT, /**< Used to indicate that the last byte on a TX packet is currently waiting to be transmitted when CTS goes low. Note that flow control is off when tranmitting final byte. */ - UART_STALL, /**< Indicates that TX is stalled because final byte is being received on the UART. */ -} uart_states_t; - -static volatile uint32_t m_pin_cts_mask; /**< CTS pin mask for UART module. */ -static app_gpiote_user_id_t m_gpiote_uid; /**< GPIOTE module user id for the UART module. */ - -static volatile uint8_t * mp_tx_stream; /**< Pointer to array of data packet to be transmitted. */ -static volatile uint16_t m_tx_stream_length; /**< Total length of data packet to be transmitted. */ -static volatile uint16_t m_tx_stream_index; /**< Index in data packet for next byte to be transmitted. */ -static uint8_t m_tx_length_buf[SER_PHY_HEADER_SIZE]; /**< Buffer needed in transmission of packet length */ - -static uint8_t * mp_rx_stream; /**< Pointer to current receive buffer. */ -static volatile uint16_t m_rx_stream_length; /**< Length of receive buffer. */ -static volatile uint16_t m_rx_stream_index; /**< Index in receive buffer where the next byte will be placed. */ -static volatile bool m_rx_stream_header; /**< Indication of whether header data (true) or payload data (false) is currently being received. */ -static uint8_t m_rx_length_buf[SER_PHY_HEADER_SIZE]; /**< Buffer needed in reception of packet length */ -static uint8_t m_rx_drop_buf[1]; /**< Additional buffer, needed by packet dropping functionality. */ - -static volatile uart_states_t m_rx_state = UART_IDLE; /**< State of the RX state machine. */ -static volatile uart_states_t m_tx_state = UART_IDLE; /**< State of the TX state machine. */ -static volatile bool m_tx_pending = false; /**< If TX state is UART_STALL and a byte is ready for tranmission the pending flag is set to true. */ -static volatile bool m_cts_high_disconnect = false; /**< If CTS was sampled low when last byte was transmitted this flag is set to true to indicate that a switch from low->high on CTS should be interpreted as transmission has completed and UART is to be disabled to save power. */ - -static volatile ser_phy_events_handler_t m_ser_phy_event_handler; -static volatile ser_phy_evt_t m_ser_phy_event_rx; -static volatile ser_phy_evt_t m_ser_phy_event_tx; - - -static void uart_peripheral_disconnect_flow(void) -{ - NRF_GPIO->OUTSET = 1 << SER_PHY_UART_RTS; - nrf_gpio_cfg_output(SER_PHY_UART_RTS); - - NRF_UART0->PSELCTS = UART_PIN_DISCONNECTED; - NRF_UART0->PSELRTS = UART_PIN_DISCONNECTED; - NRF_UART0->CONFIG &= ~(UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos); -} - - -static void uart_peripheral_connect_flow(void) -{ - NRF_UART0->PSELCTS = SER_PHY_UART_CTS; - NRF_UART0->PSELRTS = SER_PHY_UART_RTS; - NRF_UART0->CONFIG |= (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos); -} - - -static void uart_peripheral_enable_wo_flow(void) -{ - if (!(NRF_UART0->ENABLE & (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos))) - { - NRF_UART0->PSELCTS = UART_PIN_DISCONNECTED; - NRF_UART0->PSELRTS = UART_PIN_DISCONNECTED; - NRF_UART0->CONFIG &= ~(UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos); - NRF_UART0->TASKS_STARTRX = 1; - NRF_UART0->TASKS_STARTTX = 1; - NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos); - } -} - - -static void uart_peripheral_enable(void) -{ - if (!(NRF_UART0->ENABLE & (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos))) - { - NRF_UART0->PSELCTS = SER_PHY_UART_CTS; - NRF_UART0->PSELRTS = SER_PHY_UART_RTS; - NRF_UART0->CONFIG |= (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos); - NRF_UART0->TASKS_STARTRX = 1; - NRF_UART0->TASKS_STARTTX = 1; - NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos); - } -} - - -static void uart_peripheral_disable(void) -{ - if ((m_tx_state == UART_IDLE || m_tx_state == UART_STALL) && - (m_rx_state == UART_IDLE)) - { - uint32_t pins; - NRF_UART0->TASKS_STOPTX = 1; - NRF_UART0->TASKS_STOPRX = 1; - NRF_UART0->PSELCTS = UART_PIN_DISCONNECTED; - NRF_UART0->PSELRTS = UART_PIN_DISCONNECTED; - NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Disabled << UART_ENABLE_ENABLE_Pos); - - nrf_gpio_cfg_input(SER_PHY_UART_RTS, NRF_GPIO_PIN_NOPULL); - - (void) app_gpiote_user_enable(m_gpiote_uid); - (void) app_gpiote_pins_state_get(m_gpiote_uid, &pins); - - if (!pins) - { - NRF_GPIO->OUTSET = 1 << SER_PHY_UART_RTS; - nrf_gpio_cfg_output(SER_PHY_UART_RTS); - uart_peripheral_enable(); - } - } -} - - -static void uart_tx_start(void) -{ - if (mp_tx_stream != NULL) - { - //If RX is already ongoing then no wakeup signal is required. - if (m_rx_state == UART_IDLE) - { - (void) app_gpiote_user_disable(m_gpiote_uid); - uart_peripheral_enable_wo_flow(); - NRF_GPIO->OUTSET = 1 << SER_PHY_UART_RTS; - nrf_gpio_cfg_output(SER_PHY_UART_RTS); - NRF_GPIO->OUTCLR = 1 << SER_PHY_UART_RTS; - nrf_delay_us(4); - NRF_GPIO->OUTSET = 1 << SER_PHY_UART_RTS; - uart_peripheral_connect_flow(); - } - } -} - - -static void uart_tx_send(void) -{ - //First send 2 bytes of header then payload - if (m_tx_stream_index < SER_PHY_HEADER_SIZE) - { - NRF_UART0->TXD = m_tx_length_buf[m_tx_stream_index++]; - } - else if (m_tx_stream_index < m_tx_stream_length) - { - NRF_UART0->TXD = mp_tx_stream[m_tx_stream_index++ - SER_PHY_HEADER_SIZE]; - } -} - - -static void uart_tx_last_byte(void) -{ - uint32_t pins; - - uart_peripheral_disconnect_flow(); - m_tx_state = UART_TX_LAST_BYTE_WAIT; - - (void) app_gpiote_user_enable(m_gpiote_uid); - (void) app_gpiote_pins_state_get(m_gpiote_uid, &pins); - - if (!pins) //All pins are low --> last byte can be transmitted. - { - (void) app_gpiote_user_disable(m_gpiote_uid); - - //Re-check state as it might have changed due to preemption of current interrupt. - if (m_tx_state == UART_TX_LAST_BYTE_WAIT) - { - m_tx_state = UART_TX_COMPLETE; - uart_tx_send(); - } - } -} - - -static void tx_complete_event_send(void) -{ - mp_tx_stream = NULL; - m_tx_stream_length = 0; - m_tx_stream_index = 0; - - m_ser_phy_event_tx.evt_type = SER_PHY_EVT_TX_PKT_SENT; - m_ser_phy_event_handler(m_ser_phy_event_tx); -} - - -static void uart_txdrdy_handle(void) -{ - NRF_UART0->EVENTS_TXDRDY = 0; - - if (m_tx_state == UART_TX_SEND || m_tx_state == UART_IDLE) - { - if (m_tx_stream_index < (m_tx_stream_length - 1)) - { - m_tx_state = UART_TX_SEND; - uart_tx_send(); - //Keep same state. - } - else if (m_tx_stream_index == m_tx_stream_length) - { - m_tx_state = UART_IDLE; - tx_complete_event_send(); - } - else - { - uart_tx_last_byte(); - } - } - else if (m_tx_state == UART_TX_COMPLETE) - { - m_tx_state = UART_IDLE; - - if (m_rx_state == UART_IDLE) - { - uint32_t pins; - (void) app_gpiote_pins_state_get(m_gpiote_uid, &pins); - - if (pins) - { - uart_peripheral_disable(); - } - else - { - uart_peripheral_connect_flow(); - m_cts_high_disconnect = true; - (void) app_gpiote_user_enable(m_gpiote_uid); - (void) app_gpiote_pins_state_get(m_gpiote_uid, &pins); - - if (pins) - { - //If second sample show CTS high it either - //1) happened BEFORE gpiote enable and uart should be disabled. - //(m_cts_high_disconnect == true). - //2) happened AFTER gpiote enable and an interrupt low->high has occured then - //uart should NOT be disabled as the ISR has disabled the UART. - //(m_cts_high_disconnect == false). - if (m_cts_high_disconnect == true) - { - m_cts_high_disconnect = false; - uart_peripheral_disable(); - } - } - } - } - else - { - uart_peripheral_connect_flow(); - } - - tx_complete_event_send(); - } - else if (m_tx_state == UART_STALL) - { - if (m_tx_stream_index == m_tx_stream_length) - { - tx_complete_event_send(); - } - else - { - m_tx_pending = true; - } - } - else - { - //Do nothing. - } -} - - -static __INLINE void on_cts_high(void) -{ - if (m_cts_high_disconnect == true) - { - m_cts_high_disconnect = false; - - if (m_rx_state == UART_IDLE && m_tx_state == UART_IDLE) - { - if (m_tx_stream_index == m_tx_stream_length) - { - uart_peripheral_disable(); - } - } - } -} - - -static __INLINE void on_cts_low(void) -{ - m_cts_high_disconnect = false; - (void) app_gpiote_user_disable(m_gpiote_uid); - - if (m_tx_state == UART_STALL) - { - m_tx_pending = true; - } - else if (m_tx_state == UART_TX_LAST_BYTE_WAIT) - { - m_tx_state = UART_TX_COMPLETE; - uart_tx_send(); - } - else if (m_rx_state == UART_IDLE && m_tx_state == UART_IDLE) - { - NRF_GPIO->OUTSET = 1 << SER_PHY_UART_RTS; - nrf_gpio_cfg_output(SER_PHY_UART_RTS); - uart_peripheral_enable(); - } -} - - -static void uart_rxdrdy_handle(void) -{ - if (m_rx_state == UART_IDLE) - { - m_rx_state = UART_RX; - } - - //Set proper size and buff at the beginning of receiving header - if ((m_rx_stream_header == true) && !m_rx_stream_index) - { - m_rx_stream_length = SER_PHY_HEADER_SIZE; - mp_rx_stream = m_rx_length_buf; - } - - if (mp_rx_stream != NULL) - { - bool tx_dual_end = false; - - NRF_UART0->EVENTS_RXDRDY = 0; - - //Second last byte received. - //Disconnect CTS before pulling the byte and receiving the final byte. - if ((m_rx_stream_header == false) && ((m_rx_stream_index) == (m_rx_stream_length - 2))) - { - nrf_gpio_cfg_output(SER_PHY_UART_RTS); - - //Last byte is waiting for tansmission. Thus dual end TX case. - // - if (m_tx_state == UART_TX_LAST_BYTE_WAIT) - { - m_tx_state = UART_STALL; - (void) app_gpiote_user_disable(m_gpiote_uid); - - //Checking pending state. - //- If pending is true then CTS have become low after we stalled the UART and final byte should be transmitted here. - //- If pending is false we should check if final byte was tranmitted and if not, the do the transmission her. - if ((m_tx_pending == true) || (m_tx_stream_index == (m_tx_stream_length - 1))) - { - tx_dual_end = true; - NRF_GPIO->OUTSET = 1 << SER_PHY_UART_RTS; - uart_tx_send(); - } - } - - if (!tx_dual_end) - { - NRF_GPIO->OUTCLR = 1 << SER_PHY_UART_RTS; - } - m_tx_state = UART_STALL; - - NRF_UART0->PSELCTS = UART_PIN_DISCONNECTED; - NRF_UART0->PSELRTS = UART_PIN_DISCONNECTED; - NRF_UART0->CONFIG &= ~(UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos); - } - - if (m_rx_stream_index < (m_rx_stream_length - 1)) - { - if (mp_rx_stream != m_rx_drop_buf) - { - mp_rx_stream[m_rx_stream_index++] = NRF_UART0->RXD; - } - else - { - mp_rx_stream[0] = NRF_UART0->RXD; - m_rx_stream_index++; - } - - if (m_tx_stream_index == (m_tx_stream_length - 1)) - { - //Toggle CTS line to indicate ack. - //If CTS is connected to UART this code will have no effect. - //But on edge case on bi-directional last byte transfer this avoids lock-up. - NRF_GPIO->OUTSET = 1 << SER_PHY_UART_RTS; - nrf_delay_us(4); - NRF_GPIO->OUTCLR = 1 << SER_PHY_UART_RTS; - } - } - else - { - if (m_rx_stream_header == false) - { - NRF_GPIO->OUTSET = 1 << SER_PHY_UART_RTS; - - if (mp_rx_stream != m_rx_drop_buf) - { - mp_rx_stream[m_rx_stream_index++] = NRF_UART0->RXD; - } - else - { - mp_rx_stream[0] = NRF_UART0->RXD; - m_rx_stream_index++; - } - m_rx_state = UART_IDLE; - - //Last byte of payload received - notify that next transmission will be header - m_rx_stream_header = true; - - //Prepare event - if (mp_rx_stream != m_rx_drop_buf) - { - m_ser_phy_event_rx.evt_type = SER_PHY_EVT_RX_PKT_RECEIVED; - m_ser_phy_event_rx.evt_params.rx_pkt_received.num_of_bytes = m_rx_stream_index; - m_ser_phy_event_rx.evt_params.rx_pkt_received.p_buffer = mp_rx_stream; - } - else - { - m_ser_phy_event_rx.evt_type = SER_PHY_EVT_RX_PKT_DROPPED; - } - - m_rx_stream_length = 0; - m_rx_stream_index = 0; - } - else - { - mp_rx_stream[m_rx_stream_index++] = NRF_UART0->RXD; - - //Last byte of header received - notify that next transmission will be payload - m_rx_stream_header = false; - - mp_rx_stream = NULL; - - //Clear index before receiving payload - m_rx_stream_index = 0; - - //Prepare event - m_rx_stream_length = uint16_decode(m_rx_length_buf); - m_ser_phy_event_rx.evt_type = SER_PHY_EVT_RX_BUF_REQUEST; - m_ser_phy_event_rx.evt_params.rx_buf_request.num_of_bytes = m_rx_stream_length; - } - - //Notify upwards - m_ser_phy_event_handler(m_ser_phy_event_rx); - - //UART TX was stalled while receiving final byte. Restart tx. - if (m_tx_state == UART_STALL) - { - if (m_tx_stream_length == m_tx_stream_index) - { - m_tx_state = UART_IDLE; - } - else if (m_tx_stream_index == (m_tx_stream_length - 1)) - { - m_tx_state = UART_TX_LAST_BYTE_WAIT; - } - else - { - m_tx_state = UART_TX_SEND; - } - - //Critical region for avoiding timing issues in 'simultaneous RX end and TX start' - CRITICAL_REGION_ENTER(); - if (m_tx_pending == true) - { - m_tx_pending = false; - uart_tx_start(); - - if (m_tx_state == UART_TX_SEND) - { - uart_tx_send(); - } - else if (m_tx_state == UART_TX_LAST_BYTE_WAIT) - { - uart_tx_last_byte(); - } - } - CRITICAL_REGION_EXIT(); - - if (m_tx_state == UART_IDLE) - { - uart_peripheral_disable(); - } - } - } - } - else - { - m_rx_state = UART_RX_PENDING; - } -} - - -static __INLINE void uart_error_handle(void) -{ - uint32_t error_source; - - //Clear UART ERROR event flag. - NRF_UART0->EVENTS_ERROR = 0; - - //Clear error source. - error_source = NRF_UART0->ERRORSRC; - NRF_UART0->ERRORSRC = error_source; - - m_ser_phy_event_rx.evt_type = SER_PHY_EVT_HW_ERROR; - m_ser_phy_event_rx.evt_params.hw_error.error_code = error_source; - - m_ser_phy_event_handler(m_ser_phy_event_rx); -} - - -/**@brief Function for handling the GPIOTE event. - * - * @param[in] event_pins_low_to_high Mask telling which pin(s) generated an event from low->high. - * @param[in] event_pins_high_to_low Mask telling which pin(s) generated an event from high->low. - */ -static void gpiote_uart_event_handler(uint32_t event_pins_low_to_high, - uint32_t event_pins_high_to_low) -{ - if ((event_pins_high_to_low & m_pin_cts_mask) != 0) - { - on_cts_low(); - } - - if ((event_pins_low_to_high & m_pin_cts_mask) != 0) - { - on_cts_high(); - } -} - - -/**@brief Function for handling the UART Interrupt. - * - * @details UART interrupt handler to process TX Ready when TXD is available, RX Ready when a byte - * is received, or in case of error when receiving a byte. - */ -void UART0_IRQHandler(void) -{ - //Handle Reception. - if (NRF_UART0->EVENTS_RXDRDY != 0 && (NRF_UART0->INTENSET & UART_INTENSET_RXDRDY_Msk)) - { - uart_rxdrdy_handle(); - } - - //Handle transmission. - if (NRF_UART0->EVENTS_TXDRDY != 0 && (NRF_UART0->INTENSET & UART_INTENSET_TXDRDY_Msk)) - { - uart_txdrdy_handle(); - } - - //Handle errors. - if (NRF_UART0->EVENTS_ERROR != 0 && (NRF_UART0->INTENSET & UART_INTENSET_ERROR_Msk)) - { - uart_error_handle(); - } -} - - -uint32_t ser_phy_open(ser_phy_events_handler_t events_handler) -{ - uint32_t gpiote_pin_low_high_mask = 0; - uint32_t gpiote_pin_high_low_mask = 0; - - if (events_handler == NULL) - { - return NRF_ERROR_NULL; - } - - //Check if function was not called before - if (m_ser_phy_event_handler != NULL) - { - return NRF_ERROR_INVALID_STATE; - } - - //Configure GPIOTE with one user for the UART flow control feature. - APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS); - - //GPIO Setup - nrf_gpio_cfg_input(SER_PHY_UART_RTS, NRF_GPIO_PIN_NOPULL); - - NRF_GPIO->OUTSET = 1 << SER_PHY_UART_TX; - nrf_gpio_cfg_output(SER_PHY_UART_TX); - - //Setup the gpiote to handle pin events on cts-pin. - //For the UART we want to detect both low->high and high->low transitions in order to - //know when to activate/de-activate the TX/RX in the UART. - //Configure pin. - m_pin_cts_mask = (1 << SER_PHY_UART_CTS); - nrf_gpio_cfg_sense_input(SER_PHY_UART_CTS, - NRF_GPIO_PIN_PULLUP, - NRF_GPIO_PIN_SENSE_LOW); - - nrf_gpio_cfg_sense_input(SER_PHY_UART_RX, - NRF_GPIO_PIN_PULLUP, - NRF_GPIO_PIN_NOSENSE); - - gpiote_pin_low_high_mask = (1 << SER_PHY_UART_CTS); - gpiote_pin_high_low_mask = (1 << SER_PHY_UART_CTS); - - (void)app_gpiote_user_register(&m_gpiote_uid, - gpiote_pin_low_high_mask, - gpiote_pin_high_low_mask, - gpiote_uart_event_handler); - - (void)app_gpiote_user_enable(m_gpiote_uid); - - m_rx_state = UART_IDLE; - m_tx_state = UART_IDLE; - - //Set header flag - m_rx_stream_header = true; - - //UART setup - NRF_UART0->PSELRXD = SER_PHY_UART_RX; - NRF_UART0->PSELTXD = SER_PHY_UART_TX; - NRF_UART0->PSELCTS = UART_PIN_DISCONNECTED; - NRF_UART0->PSELRTS = UART_PIN_DISCONNECTED; - NRF_UART0->BAUDRATE = SER_PHY_UART_BAUDRATE; - NRF_UART0->CONFIG = (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos); - NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Disabled << UART_ENABLE_ENABLE_Pos); - - //Enable UART interrupt - NRF_UART0->INTENCLR = 0xFFFFFFFF; - NRF_UART0->INTENSET = (UART_INTENSET_TXDRDY_Set << UART_INTENSET_TXDRDY_Pos) | - (UART_INTENSET_RXDRDY_Set << UART_INTENSET_RXDRDY_Pos) | - (UART_INTENSET_ERROR_Set << UART_INTENSET_ERROR_Pos); - - NVIC_ClearPendingIRQ(UART0_IRQn); - NVIC_SetPriority(UART0_IRQn, APP_IRQ_PRIORITY_LOW); - NVIC_EnableIRQ(UART0_IRQn); - - m_ser_phy_event_handler = events_handler; - - return NRF_SUCCESS; -} - - -void ser_phy_close(void) -{ - //Disable UART interrupt. - NRF_UART0->INTENCLR = 0xFFFFFFFF; - - //Unregister callback. - m_ser_phy_event_handler = NULL; - - //Will not check err_code here as we will still continue with closure of UART despite errors. - //Note that any error will still be reported back in the system. - (void)app_gpiote_user_disable(m_gpiote_uid); - - uart_peripheral_disable(); - - //Clear internal UART states - m_rx_state = UART_IDLE; - m_tx_state = UART_IDLE; - - mp_tx_stream = NULL; - m_tx_stream_length = 0; - m_tx_stream_index = 0; - - mp_rx_stream = NULL; - m_rx_stream_length = 0; - m_rx_stream_index = 0; -} - - -uint32_t ser_phy_tx_pkt_send(const uint8_t * p_buffer, uint16_t num_of_bytes) -{ - if (p_buffer == NULL) - { - return NRF_ERROR_NULL; - } - - if (num_of_bytes == 0) - { - return NRF_ERROR_INVALID_PARAM; - } - - if (mp_tx_stream != NULL) - { - return NRF_ERROR_BUSY; - } - - m_tx_pending = true; - - (void) uint16_encode(num_of_bytes, m_tx_length_buf); - mp_tx_stream = (uint8_t *)p_buffer; - m_tx_stream_length = num_of_bytes + SER_PHY_HEADER_SIZE; - - //Critical region for avoiding timing issues in 'simultaneous RX end and TX start' - CRITICAL_REGION_ENTER(); - if ((!m_rx_stream_length) || (m_rx_stream_index < (m_rx_stream_length - 2))) - { - if (m_tx_state != UART_STALL) - { - if (m_tx_pending == true) - { - m_tx_pending = false; - uart_tx_start(); - //As no tx can be ongoing, then it is safe to call tx_send here. - uart_tx_send(); - } - } - } - CRITICAL_REGION_EXIT(); - - return NRF_SUCCESS; -} - - -uint32_t ser_phy_rx_buf_set(uint8_t * p_buffer) -{ - if (m_ser_phy_event_rx.evt_type != SER_PHY_EVT_RX_BUF_REQUEST) - { - return NRF_ERROR_INVALID_STATE; - } - - if (p_buffer != NULL) - { - mp_rx_stream = p_buffer; - } - else - { - mp_rx_stream = m_rx_drop_buf; - } - - return NRF_SUCCESS; -} - - -void ser_phy_interrupts_enable(void) -{ - NVIC_EnableIRQ(UART0_IRQn); -} - - -void ser_phy_interrupts_disable(void) -{ - NVIC_DisableIRQ(UART0_IRQn); -}
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/serialization/common/transport/ser_phy/spi_5W_master.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/common/transport/ser_phy/spi_5W_master.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/common/transport/ser_phy/spi_5W_master.c deleted file mode 100644 index f8276ab..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/common/transport/ser_phy/spi_5W_master.c +++ /dev/null @@ -1,603 +0,0 @@ -/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - -/**@file - * - * @defgroup ser_phy_spi_5W_hw_driver_master spi_5W_master.c - * @{ - * @ingroup ser_phy_spi_5W_hw_driver_master - * - * @brief SPI_5W_RAW hardware driver. - */ - -#include "app_error.h" -#include "app_util_platform.h" -#include "nrf_gpio.h" -#include "nrf.h" -#include "spi_5W_master.h" -#include "ser_config_5W_app.h" -#include "ser_phy_debug_app.h" - - -#define _static - -#define DOUBLE_BUFFERED /**< A flag for enabling double buffering. */ - -#define SPI_PIN_DISCONNECTED 0xFFFFFFFF /**< A value used to the PIN deinitialization. */ -#define SPI_DEFAULT_TX_BYTE 0x00 /**< Default byte (used to clock transmission - from slave to the master) */ - -typedef struct -{ - NRF_SPI_Type * p_nrf_spi; /**< A pointer to the NRF SPI master */ - IRQn_Type irq_type; /**< A type of NVIC IRQn */ - - uint8_t * p_tx_buffer; /**< A pointer to TX buffer. */ - uint16_t tx_length; /**< A length of TX buffer. */ - uint16_t tx_index; /**< A index of the current element in the TX buffer. */ - - uint8_t * p_rx_buffer; /**< A pointer to RX buffer. */ - uint16_t rx_length; /**< A length RX buffer. */ - uint16_t rx_index; /**< A index of the current element in the RX buffer. */ - - uint16_t max_length; /**< Max length (Max of the TX and RX length). */ - uint16_t bytes_count; - uint8_t pin_slave_select; /**< A pin for Slave Select. */ - - spi_master_event_handler_t callback_event_handler; /**< A handler for event callback function. */ - spi_master_state_t state; /**< A state of an instance of SPI master. */ - bool start_flag; - bool abort_flag; - -} spi_master_instance_t; - -#ifdef _SPI_5W_ -typedef enum -{ - HOOK_STATE_DISABLED, - HOOK_STATE_IDLE, - HOOK_STATE_GUARDED, - HOOK_STATE_ABORTED, - HOOK_STATE_RESTARTED, - HOOK_STATE_PASSING -} spi_hook_state_t; - - -_static spi_master_event_handler_t m_ser_phy_event_handler; -_static spi_master_hw_instance_t m_spi_master_hw_instance; -_static spi_hook_state_t m_hook_state = HOOK_STATE_DISABLED; -#endif - -#ifdef SER_PHY_DEBUG_APP_ENABLE -_static spi_master_raw_callback_t m_debug_callback; -#endif - -_static spi_master_instance_t m_spi_master_instances[SPI_MASTER_HW_ENABLED_COUNT]; - -static __INLINE spi_master_instance_t * spi_master_get_instance( - const spi_master_hw_instance_t spi_master_hw_instance); -static __INLINE void spi_master_send_recv_irq(spi_master_instance_t * const p_spi_instance); -static __INLINE void spi_master_signal_evt(spi_master_instance_t * const p_spi_instance, - spi_master_evt_type_t event_type, - const uint16_t data); - -#ifdef SPI_MASTER_0_ENABLE -/** - * @brief SPI0 interrupt handler. - */ -void SPI0_TWI0_IRQHandler(void) -{ - if (NRF_SPI0->EVENTS_READY != 0) - { - NRF_SPI0->EVENTS_READY = 0; - - spi_master_instance_t * p_spi_instance = spi_master_get_instance(SPI_MASTER_0); - - spi_master_send_recv_irq(p_spi_instance); - } -} -#endif //SPI_MASTER_0_ENABLE - -#ifdef SPI_MASTER_1_ENABLE -/** - * @brief SPI0 interrupt handler. - */ -void SPI1_TWI1_IRQHandler(void) -{ - if (NRF_SPI1->EVENTS_READY != 0) - { - NRF_SPI1->EVENTS_READY = 0; - - spi_master_instance_t * p_spi_instance = spi_master_get_instance(SPI_MASTER_1); - - spi_master_send_recv_irq(p_spi_instance); - } -} -#endif //SPI_MASTER_1_ENABLE - -#if defined(SPI_MASTER_0_ENABLE) || defined(SPI_MASTER_1_ENABLE) - -/**@brief Function for getting an instance of SPI master. */ -static __INLINE spi_master_instance_t * spi_master_get_instance( - const spi_master_hw_instance_t spi_master_hw_instance) -{ - return &(m_spi_master_instances[(uint8_t)spi_master_hw_instance]); -} - -/** @brief Function for initializing instance of SPI master by default values. */ -static __INLINE void spi_master_init_hw_instance(NRF_SPI_Type * p_nrf_spi, - IRQn_Type irq_type, - spi_master_instance_t * p_spi_instance) -{ - APP_ERROR_CHECK_BOOL(p_spi_instance != NULL); - - p_spi_instance->p_nrf_spi = p_nrf_spi; - p_spi_instance->irq_type = irq_type; - - p_spi_instance->p_tx_buffer = NULL; - p_spi_instance->tx_length = 0; - p_spi_instance->tx_index = 0; - - p_spi_instance->p_rx_buffer = NULL; - p_spi_instance->rx_length = 0; - p_spi_instance->rx_index = 0; - - p_spi_instance->bytes_count = 0; - p_spi_instance->max_length = 0; - p_spi_instance->pin_slave_select = 0; - - p_spi_instance->callback_event_handler = NULL; - - p_spi_instance->state = SPI_MASTER_STATE_DISABLED; - p_spi_instance->abort_flag = false; - p_spi_instance->start_flag = false; -} - -/**@brief Function for initializing TX or RX buffer. */ -static __INLINE void spi_master_buffer_init(uint8_t * const p_buf, - const uint16_t buf_len, - uint8_t * * pp_buf, - uint16_t * const p_buf_len, - uint16_t * const p_index) -{ - APP_ERROR_CHECK_BOOL(pp_buf != NULL); - APP_ERROR_CHECK_BOOL(p_buf_len != NULL); - APP_ERROR_CHECK_BOOL(p_index != NULL); - - *pp_buf = p_buf; - *p_buf_len = (p_buf != NULL) ? buf_len : 0; - *p_index = 0; -} - -/**@brief Function for releasing TX or RX buffer. */ -static __INLINE void spi_master_buffer_release(uint8_t * * const pp_buf, uint16_t * const p_buf_len) -{ - APP_ERROR_CHECK_BOOL(pp_buf != NULL); - APP_ERROR_CHECK_BOOL(p_buf_len != NULL); - - *pp_buf = NULL; - *p_buf_len = 0; -} - -/**@brief Function for sending events by callback. */ -static __INLINE void spi_master_signal_evt(spi_master_instance_t * const p_spi_instance, - spi_master_evt_type_t event_type, - const uint16_t data) -{ - APP_ERROR_CHECK_BOOL(p_spi_instance != NULL); - - if (p_spi_instance->callback_event_handler != NULL) - { - spi_master_evt_t event = {SPI_MASTER_EVT_TYPE_MAX, 0}; - event.type = event_type; - event.data = data; - p_spi_instance->callback_event_handler(event); - } -} - -/**@brief Function insert to a TX buffer another byte or two bytes (depends on flag @ref DOUBLE_BUFFERED). */ -static __INLINE void spi_master_send_initial_bytes(spi_master_instance_t * const p_spi_instance) -{ - APP_ERROR_CHECK_BOOL(p_spi_instance != NULL); - - p_spi_instance->p_nrf_spi->TXD = ((p_spi_instance->p_tx_buffer != NULL) && - (p_spi_instance->tx_index < p_spi_instance->tx_length)) ? - p_spi_instance->p_tx_buffer[p_spi_instance->tx_index] : - SPI_DEFAULT_TX_BYTE; - (p_spi_instance->tx_index)++; - - #ifdef DOUBLE_BUFFERED - - if (p_spi_instance->tx_index < p_spi_instance->max_length) - { - p_spi_instance->p_nrf_spi->TXD = ((p_spi_instance->p_tx_buffer != NULL) && - (p_spi_instance->tx_index < p_spi_instance->tx_length)) ? - p_spi_instance->p_tx_buffer[p_spi_instance->tx_index] : - SPI_DEFAULT_TX_BYTE; - (p_spi_instance->tx_index)++; - } - #endif -} - -/**@brief Function for receiving and sending data from IRQ. (The same for both IRQs). */ -static __INLINE void spi_master_send_recv_irq(spi_master_instance_t * const p_spi_instance) -{ - - uint8_t rx_byte; - - APP_ERROR_CHECK_BOOL(p_spi_instance != NULL); - APP_ERROR_CHECK_BOOL(p_spi_instance->state == SPI_MASTER_STATE_BUSY); - - p_spi_instance->bytes_count++; - rx_byte = p_spi_instance->p_nrf_spi->RXD; - - if (p_spi_instance->start_flag) - { - p_spi_instance->start_flag = false; - spi_master_signal_evt(p_spi_instance, SPI_MASTER_EVT_FIRST_BYTE_RECEIVED, (uint16_t)rx_byte); - } - else if (p_spi_instance->abort_flag ) //this is tricky, but callback for SPI_MASTER_EVT_FIRST_BYTE_RECEIVED will set this flag for a first byte, which is bad because there is still byte in a buffer - { //and for a single byte transaction you will get XFERDONE event to restart - p_spi_instance->abort_flag = false; - p_spi_instance->state = SPI_MASTER_STATE_ABORTED; - nrf_gpio_pin_set(p_spi_instance->pin_slave_select); - spi_master_signal_evt(p_spi_instance, SPI_MASTER_EVT_TRANSFER_ABORTED, 0); - return; - } - - if ((p_spi_instance->p_rx_buffer != NULL) && - (p_spi_instance->rx_index < p_spi_instance->rx_length)) - { - p_spi_instance->p_rx_buffer[p_spi_instance->rx_index++] = rx_byte; - } - - if ((p_spi_instance->tx_index < p_spi_instance->max_length) && (!(p_spi_instance->abort_flag))) //do not TX if you know that there is an abort to be done - this should work for a DOUBLE BUFFERING ??? - { - p_spi_instance->p_nrf_spi->TXD = ((p_spi_instance->p_tx_buffer != NULL) && - (p_spi_instance->tx_index < p_spi_instance->tx_length)) ? - p_spi_instance->p_tx_buffer[p_spi_instance->tx_index] : - SPI_DEFAULT_TX_BYTE; - (p_spi_instance->tx_index)++; - } - - if (p_spi_instance->bytes_count >= p_spi_instance->max_length) - { - APP_ERROR_CHECK_BOOL(p_spi_instance->bytes_count == p_spi_instance->max_length); - nrf_gpio_pin_set(p_spi_instance->pin_slave_select); - p_spi_instance->state = SPI_MASTER_STATE_IDLE; - spi_master_signal_evt(p_spi_instance, - SPI_MASTER_EVT_TRANSFER_COMPLETED, - p_spi_instance->tx_index); - } - return; -} -#endif //defined(SPI_MASTER_0_ENABLE) || defined(SPI_MASTER_1_ENABLE) - - -/** - * @brief Function for opening and initializing a SPI master driver. */ -uint32_t spi_master_open(const spi_master_hw_instance_t spi_master_hw_instance, - spi_master_config_t const * const p_spi_master_config) -{ - #if defined(SPI_MASTER_0_ENABLE) || defined(SPI_MASTER_1_ENABLE) - - - if (p_spi_master_config == NULL) - { - return NRF_ERROR_NULL; - } - - spi_master_instance_t * p_spi_instance = spi_master_get_instance(spi_master_hw_instance); - - switch (spi_master_hw_instance) - { - #ifdef SPI_MASTER_0_ENABLE - case SPI_MASTER_0: - spi_master_init_hw_instance(NRF_SPI0, SPI0_TWI0_IRQn, p_spi_instance); - break; - #endif //SPI_MASTER_0_ENABLE - - #ifdef SPI_MASTER_1_ENABLE - case SPI_MASTER_1: - spi_master_init_hw_instance(NRF_SPI1, SPI1_TWI1_IRQn, p_spi_instance); - break; - #endif //SPI_MASTER_1_ENABLE - - default: - break; - } - - //A Slave select must be set as high before setting it as output, - //because during connect it to the pin it causes glitches. - nrf_gpio_pin_set(p_spi_master_config->SPI_Pin_SS); - nrf_gpio_cfg_output(p_spi_master_config->SPI_Pin_SS); - nrf_gpio_pin_set(p_spi_master_config->SPI_Pin_SS); - - //Configure GPIO - nrf_gpio_cfg_output(p_spi_master_config->SPI_Pin_SCK); - nrf_gpio_cfg_output(p_spi_master_config->SPI_Pin_MOSI); - nrf_gpio_cfg_input(p_spi_master_config->SPI_Pin_MISO, NRF_GPIO_PIN_NOPULL); - p_spi_instance->pin_slave_select = p_spi_master_config->SPI_Pin_SS; - - /* Configure SPI hardware */ - p_spi_instance->p_nrf_spi->PSELSCK = p_spi_master_config->SPI_Pin_SCK; - p_spi_instance->p_nrf_spi->PSELMOSI = p_spi_master_config->SPI_Pin_MOSI; - p_spi_instance->p_nrf_spi->PSELMISO = p_spi_master_config->SPI_Pin_MISO; - - p_spi_instance->p_nrf_spi->FREQUENCY = p_spi_master_config->SPI_Freq; - - p_spi_instance->p_nrf_spi->CONFIG = - (uint32_t)(p_spi_master_config->SPI_CPHA << SPI_CONFIG_CPHA_Pos) | - (p_spi_master_config->SPI_CPOL << SPI_CONFIG_CPOL_Pos) | - (p_spi_master_config->SPI_ORDER << SPI_CONFIG_ORDER_Pos); - - - /* Clear waiting interrupts and events */ - p_spi_instance->p_nrf_spi->EVENTS_READY = 0; - - NVIC_ClearPendingIRQ(p_spi_instance->irq_type); - NVIC_SetPriority(p_spi_instance->irq_type, APP_IRQ_PRIORITY_MID); - - /* Clear event handler */ - p_spi_instance->callback_event_handler = NULL; - - /* Enable interrupt */ - p_spi_instance->p_nrf_spi->INTENSET = (SPI_INTENSET_READY_Set << SPI_INTENCLR_READY_Pos); - NVIC_EnableIRQ(p_spi_instance->irq_type); - - /* Enable SPI hardware */ - p_spi_instance->p_nrf_spi->ENABLE = (SPI_ENABLE_ENABLE_Enabled << SPI_ENABLE_ENABLE_Pos); - - /* Change state to IDLE */ - p_spi_instance->state = SPI_MASTER_STATE_IDLE; - - return NRF_SUCCESS; - #else - return NRF_ERROR_NOT_SUPPORTED; - #endif -} - -/** - * @brief Function for closing a SPI master driver. - */ -void spi_master_close(const spi_master_hw_instance_t spi_master_hw_instance) -{ - #if defined(SPI_MASTER_0_ENABLE) || defined(SPI_MASTER_1_ENABLE) - spi_master_instance_t * p_spi_instance = spi_master_get_instance(spi_master_hw_instance); - - /* Disable interrupt */ - NVIC_ClearPendingIRQ(p_spi_instance->irq_type); - NVIC_DisableIRQ(p_spi_instance->irq_type); - - p_spi_instance->p_nrf_spi->ENABLE = (SPI_ENABLE_ENABLE_Disabled << SPI_ENABLE_ENABLE_Pos); - - /* Disconnect pin slave select */ - nrf_gpio_pin_clear(p_spi_instance->pin_slave_select); - p_spi_instance->pin_slave_select = (uint8_t)0xFF; - - /* Disconnect pins from SPI hardware */ - p_spi_instance->p_nrf_spi->PSELSCK = (uint32_t)SPI_PIN_DISCONNECTED; - p_spi_instance->p_nrf_spi->PSELMOSI = (uint32_t)SPI_PIN_DISCONNECTED; - p_spi_instance->p_nrf_spi->PSELMISO = (uint32_t)SPI_PIN_DISCONNECTED; - - /* Reset to default values */ - spi_master_init_hw_instance(NULL, (IRQn_Type)0, p_spi_instance); - #else - return; - #endif -} - -/** - * @brief Function for getting current state of the SPI master driver. - */ -__INLINE spi_master_state_t spi_master_get_state( - const spi_master_hw_instance_t spi_master_hw_instance) -{ - #if defined(SPI_MASTER_0_ENABLE) || defined(SPI_MASTER_1_ENABLE) - spi_master_instance_t * spi_instance = spi_master_get_instance(spi_master_hw_instance); - return spi_instance->state; - #else - return SPI_MASTER_STATE_DISABLED; - #endif -} - -/** - * @brief Function for event handler registration. - */ -__INLINE void spi_master_evt_handler_reg(const spi_master_hw_instance_t spi_master_hw_instance, - spi_master_event_handler_t event_handler) -{ - #if defined(SPI_MASTER_0_ENABLE) || defined(SPI_MASTER_1_ENABLE) - spi_master_instance_t * spi_instance = spi_master_get_instance(spi_master_hw_instance); - spi_instance->callback_event_handler = event_handler; - #else - return; - #endif -} - -/** - * @brief Function for transmitting data between SPI master and SPI slave. - */ -uint32_t spi_master_send_recv(const spi_master_hw_instance_t spi_master_hw_instance, - uint8_t * const p_tx_buf, const uint16_t tx_buf_len, - uint8_t * const p_rx_buf, const uint16_t rx_buf_len) -{ - #if defined(SPI_MASTER_0_ENABLE) || defined(SPI_MASTER_1_ENABLE) - spi_master_instance_t * p_spi_instance = spi_master_get_instance(spi_master_hw_instance); - - uint32_t err_code = NRF_SUCCESS; - uint16_t max_length = 0; - - if (p_spi_instance->state == SPI_MASTER_STATE_IDLE) - { - NVIC_DisableIRQ(p_spi_instance->irq_type); - - max_length = (rx_buf_len > tx_buf_len) ? rx_buf_len : tx_buf_len; - - if (max_length > 0) - { - p_spi_instance->state = SPI_MASTER_STATE_BUSY; - p_spi_instance->start_flag = true; //abort_flag should set by abort and cleared only by restart - p_spi_instance->bytes_count = 0; - p_spi_instance->max_length = max_length; - spi_master_buffer_release(&(p_spi_instance->p_tx_buffer), &(p_spi_instance->tx_length)); - spi_master_buffer_release(&(p_spi_instance->p_rx_buffer), &(p_spi_instance->rx_length)); - /* Initialize buffers */ - spi_master_buffer_init(p_tx_buf, tx_buf_len, &(p_spi_instance->p_tx_buffer), - &(p_spi_instance->tx_length), &(p_spi_instance->tx_index)); - spi_master_buffer_init(p_rx_buf, rx_buf_len, &(p_spi_instance->p_rx_buffer), - &(p_spi_instance->rx_length), &(p_spi_instance->rx_index)); - nrf_gpio_pin_clear(p_spi_instance->pin_slave_select); - spi_master_send_initial_bytes(p_spi_instance); - spi_master_signal_evt(p_spi_instance, SPI_MASTER_EVT_TRANSFER_STARTED, max_length); - } - else - { - err_code = NRF_ERROR_INVALID_PARAM; - } - - NVIC_EnableIRQ(p_spi_instance->irq_type); - } - else - { - err_code = NRF_ERROR_BUSY; - } - - return err_code; - #else - return NRF_ERROR_NOT_SUPPORTED; - #endif -} - -#ifdef _SPI_5W_ - -/** - * @brief Function for aborting transfer - */ -uint32_t spi_master_abort(const spi_master_hw_instance_t spi_master_hw_instance) -{ - spi_master_instance_t * p_spi_instance = spi_master_get_instance(spi_master_hw_instance); - - NVIC_DisableIRQ(p_spi_instance->irq_type); - - if (p_spi_instance->state == SPI_MASTER_STATE_BUSY) - { - //set_flag - but only when there are events pending - //ignore when in IDLE - must be able to restart a completed transfer - p_spi_instance->abort_flag = true; - } - NVIC_EnableIRQ(p_spi_instance->irq_type); - return NRF_SUCCESS; -} - -/** - * @brief Function for restarting transfer - */ -uint32_t spi_master_restart(const spi_master_hw_instance_t spi_master_hw_instance) -{ - spi_master_instance_t * p_spi_instance = spi_master_get_instance(spi_master_hw_instance); - - NVIC_DisableIRQ(p_spi_instance->irq_type); - spi_master_signal_evt(p_spi_instance, SPI_MASTER_EVT_TRANSFER_RESTARTED, 0); - p_spi_instance->state = SPI_MASTER_STATE_BUSY; - p_spi_instance->bytes_count = 0; - p_spi_instance->tx_index = 0; - p_spi_instance->rx_index = 0; - p_spi_instance->start_flag = true; - p_spi_instance->abort_flag = false; //you should force clearing abort flag - no other way for 1 byte transfer - nrf_gpio_pin_clear(p_spi_instance->pin_slave_select); - spi_master_send_initial_bytes(p_spi_instance); - NVIC_EnableIRQ(p_spi_instance->irq_type); - - return NRF_SUCCESS; -} - -static void spi_5W_master_event_handler(spi_master_evt_t evt) -{ - - switch (m_hook_state) - { - case HOOK_STATE_IDLE: - - if (evt.type == SPI_MASTER_EVT_TRANSFER_STARTED) - { - DEBUG_EVT_SPI_MASTER_RAW_XFER_GUARDED(0); - m_hook_state = HOOK_STATE_GUARDED; - m_ser_phy_event_handler(evt); - } - break; - - case HOOK_STATE_GUARDED: - - if (evt.type == SPI_MASTER_EVT_FIRST_BYTE_RECEIVED) - { - if (evt.data == 0) - { - DEBUG_EVT_SPI_MASTER_RAW_XFER_PASSED(0); - m_hook_state = HOOK_STATE_PASSING; - } - else - { - DEBUG_EVT_SPI_MASTER_RAW_XFER_ABORTED(0); - m_hook_state = HOOK_STATE_ABORTED; - (void)spi_master_abort(m_spi_master_hw_instance); - } - } - break; - - case HOOK_STATE_ABORTED: - - if ((evt.type == SPI_MASTER_EVT_TRANSFER_ABORTED) || - (evt.type == SPI_MASTER_EVT_TRANSFER_COMPLETED)) - { - DEBUG_EVT_SPI_MASTER_RAW_XFER_RESTARTED(0); - m_hook_state = HOOK_STATE_RESTARTED; - (void)spi_master_restart(m_spi_master_hw_instance); - } - break; - - case HOOK_STATE_RESTARTED: - - if (evt.type == SPI_MASTER_EVT_TRANSFER_RESTARTED) - { - DEBUG_EVT_SPI_MASTER_RAW_XFER_GUARDED(0); - m_hook_state = HOOK_STATE_GUARDED; - } - break; - - case HOOK_STATE_PASSING: - - if (evt.type == SPI_MASTER_EVT_TRANSFER_COMPLETED) - { - m_hook_state = HOOK_STATE_IDLE; - m_ser_phy_event_handler(evt); //this is the only way to get a signal from complete transaction - } - break; - - default: - break; - } -} - -void spi_5W_master_evt_handler_reg(const spi_master_hw_instance_t spi_master_hw_instance, - spi_master_event_handler_t event_handler) -{ - m_ser_phy_event_handler = event_handler; - m_spi_master_hw_instance = spi_master_hw_instance; - m_hook_state = HOOK_STATE_IDLE; - spi_master_evt_handler_reg(spi_master_hw_instance, spi_5W_master_event_handler); - return; -} - -#endif - -/** @} */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/common/transport/ser_phy/spi_5W_master.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/common/transport/ser_phy/spi_5W_master.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/common/transport/ser_phy/spi_5W_master.h deleted file mode 100644 index 501eeff..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/common/transport/ser_phy/spi_5W_master.h +++ /dev/null @@ -1,178 +0,0 @@ -/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - -#ifndef APP_SPI_MASTER_H -#define APP_SPI_MASTER_H - -#include <stdint.h> -#include <stdlib.h> -#include "boards.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define _SPI_5W_ - -/**@brief Struct containing configuration parameters of the SPI master. */ -typedef struct -{ - uint32_t SPI_Freq; /**< SPI frequency. */ - uint32_t SPI_Pin_SCK; /**< SCK pin number. */ - uint32_t SPI_Pin_MISO; /**< MISO pin number. */ - uint32_t SPI_Pin_MOSI; /**< MOSI pin number .*/ - uint32_t SPI_Pin_SS; /**< Slave select pin number. */ - uint8_t SPI_ORDER; /**< Bytes order MSBFIRST or LSBFIRST. */ - uint8_t SPI_CPOL; /**< Serial clock polarity ACTIVEHIGH or ACTIVELOW. */ - uint8_t SPI_CPHA; /**< Serial clock phase LEADING or TRAILING. */ - } spi_master_config_t; - -/**@brief SPI master driver events types. */ -typedef enum -{ - SPI_MASTER_EVT_TRANSFER_STARTED = 0, /**< An event indicating that transfer has been started */ - SPI_MASTER_EVT_TRANSFER_COMPLETED, /**< An event indicating that transfer has been completed */ - SPI_MASTER_EVT_TRANSFER_ABORTED, /**< An event indicating that transfer has been aborted */ - SPI_MASTER_EVT_TRANSFER_RESTARTED, /**< An event indicating that transfer has been resumed */ - SPI_MASTER_EVT_FIRST_BYTE_RECEIVED, /**< An event indicating end of one byte transfer */ - SPI_MASTER_EVT_TYPE_MAX /**< Enumeration upper bound. */ -} spi_master_evt_type_t; - -/**@brief Struct containing parameters of the SPI MASTER event */ - typedef struct - { - spi_master_evt_type_t type; /**< Type of an event */ - uint16_t data; /**< event data - context dependent */ - } spi_master_evt_t; - - /**@brief SPI MASTER internal states types. */ - typedef enum - { - SPI_MASTER_STATE_DISABLED, /**< A state indicating that SPI master is disabled. */ - SPI_MASTER_STATE_BUSY, /**< A state indicating that SPI master is sending now. */ - SPI_MASTER_STATE_ABORTED, - SPI_MASTER_STATE_IDLE /**< A state indicating that SPI master is idle now. */ - } spi_master_state_t; - - /**@brief Instances of SPI master module. */ - typedef enum - { - #ifdef SPI_MASTER_0_ENABLE - SPI_MASTER_0, /**< A instance of SPI master 0. */ - #endif - - #ifdef SPI_MASTER_1_ENABLE - SPI_MASTER_1, /**< A instance of SPI master 1. */ - #endif - - SPI_MASTER_HW_ENABLED_COUNT /**< A number of enabled instances of SPI master. */ - } spi_master_hw_instance_t; - -/**@brief Type of generic callback function handler to be used by all SPI MASTER driver events. - * - * @param[in] spi_master_evt SPI MASTER driver event. - */ -typedef void (*spi_master_event_handler_t) (spi_master_evt_t spi_master_evt); - - -/**@brief Function for opening and initializing a SPI master driver. - * - * @note Function initializes SPI master hardware and internal module states, unregister events callback. - * - * @warning If the function has been already called, the function @ref spi_master_close has to be - * called before spi_master_open can be called again. - * - * @param[in] spi_master_hw_instance Instance of SPI master module. - * @param[in] p_spi_master_config Pointer to configuration structure which will be used - * to initialize SPI MASTER hardware. - * - * @retval NRF_SUCCESS Operation success. - * @retval NRF_ERROR_INVALID_STATE Operation failure. The function has been already called. - * To call it again the function @ref spi_master_close - * has to be called previously. - * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. - */ -uint32_t spi_master_open(const spi_master_hw_instance_t spi_master_hw_instance, - spi_master_config_t const * const p_spi_master_config); - - -/**@brief Function for closing a SPI MASTER driver. - * - * @note Function disable hardware, reset internal module states and unregister events callback - * function. - * - * @param[in] spi_master_hw_instance A instance of SPI master. - */ -void spi_master_close(const spi_master_hw_instance_t spi_master_hw_instance); - - -/**@brief Function for transferring data between SPI master and SPI slave - * - * @note Function registers buffers pointed by p_tx_buf and p_rx_buf parameters, after that starts transmission. - * Function generates an event of type @ref SPI_MASTER_EVT_TRANSFER_STARTED when transfer has been started - * and @ref SPI_MASTER_EVT_TRANSFER_COMPLETED when transfer has been completed. - * - * @param[in] spi_master_hw_instance Instance of SPI master module. - * @param[in] p_tx_buf Pointer to a transmit buffer. - * @param[in] tx_buf_len Number of octets to the transfer. - * @param[out] p_rx_buf Pointer to a receive buffer. - * @param[in] rx_buf_len Number of octets to be received. - * - * @retval NRF_SUCCESS Operation success. Packet was registered to the transmission - * and event will be send upon transmission completion. - * @retval NRF_ERROR_BUSY Operation failure. Transmitting of a data is in progress. - */ - uint32_t spi_master_send_recv(const spi_master_hw_instance_t spi_master_hw_instance, - uint8_t * const p_tx_buf, const uint16_t tx_buf_len, - uint8_t * const p_rx_buf, const uint16_t rx_buf_len); - - -/**@brief Function for registration event handler. -* -* @note Function registers a event handler to be used by SPI MASTER driver for sending events. -* @ref SPI_MASTER_EVT_TRANSFER_STARTED and @ref SPI_MASTER_EVT_TRANSFER_COMPLETED. -* -* @param[in] spi_master_hw_instance Instance of SPI master module. -* @param[in] event_handler Generic callback function handler to be used -* by all SPI master driver events. -*/ -void spi_master_evt_handler_reg(const spi_master_hw_instance_t spi_master_hw_instance, - spi_master_event_handler_t event_handler); - - -/**@brief Function for getting current state of the SPI master driver. - * - * @note Function gets current state of the SPI master driver. - * - * @param[in] spi_master_hw_instance Instance of SPI master module. - * - * @retval SPI_MASTER_STATE_DISABLED SPI MASTER is disabled. - * @retval SPI_MASTER_STATE_BUSY SPI_MASTER is sending now. - * @retval SPI_MASTER_STATE_IDLE SPI_MASTER is idle now. - */ -spi_master_state_t spi_master_get_state(const spi_master_hw_instance_t spi_master_hw_instance); - -#ifdef _SPI_5W_ - -uint32_t spi_master_abort(const spi_master_hw_instance_t spi_master_hw_instance); - -uint32_t spi_master_restart(const spi_master_hw_instance_t spi_master_hw_instance); - -void spi_5W_master_evt_handler_reg(const spi_master_hw_instance_t spi_master_hw_instance, - spi_master_event_handler_t event_handler); -#endif - -#ifdef __cplusplus -} -#endif - -#endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/common/transport/ser_phy_debug_comm.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/common/transport/ser_phy_debug_comm.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/common/transport/ser_phy_debug_comm.h deleted file mode 100644 index 5cd6c1e..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/common/transport/ser_phy_debug_comm.h +++ /dev/null @@ -1,175 +0,0 @@ -/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - -#ifndef SER_PHY_DEBUG_COMM_H__ -#define SER_PHY_DEBUG_COMM_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef SER_PHY_HCI_DEBUG_ENABLE - -// empty definitions here -#define DEBUG_EVT_HCI_PHY_EVT_TX_PKT_SENT(data) -#define DEBUG_EVT_HCI_PHY_EVT_BUF_REQUEST(data) -#define DEBUG_EVT_HCI_PHY_EVT_RX_PKT_RECEIVED(data) -#define DEBUG_EVT_HCI_PHY_EVT_RX_PKT_DROPPED(data) -#define DEBUG_EVT_HCI_PHY_EVT_TX_ERROR(data) -#define DEBUG_EVT_SLIP_PACKET_TX(data) -#define DEBUG_EVT_SLIP_ACK_TX(data) -#define DEBUG_EVT_SLIP_PACKET_TXED(data) -#define DEBUG_EVT_SLIP_ACK_TXED(data) -#define DEBUG_EVT_SLIP_PACKET_RXED(data) -#define DEBUG_EVT_SLIP_ACK_RXED(data) -#define DEBUG_EVT_SLIP_ERR_RXED(data) -#define DEBUG_EVT_TIMEOUT(data) -#define DEBUG_HCI_RETX(data) -#define DEBUG_EVT_MAIN_BUSY(data) -#define DEBUG_EVT_TX_REQ(data) - -#else -#include <stdint.h> - -//Low level hardware events -typedef enum -{ - HCI_PHY_EVT_TX_PKT_SENT, - HCI_PHY_EVT_BUF_REQUEST, - HCI_PHY_EVT_RX_PKT_RECEIVED, - HCI_PHY_EVT_RX_PKT_DROPPED, - HCI_PHY_EVT_TX_ERROR, - HCI_SLIP_EVT_PACKET_TX, - HCI_SLIP_EVT_ACK_TX, - HCI_SLIP_EVT_PACKET_TXED, - HCI_SLIP_EVT_ACK_TXED, - HCI_SLIP_EVT_PACKET_RXED, - HCI_SLIP_EVT_ACK_RXED, - HCI_SLIP_EVT_ERR_RXED, - HCI_TIMER_EVT_TIMEOUT, - HCI_RETX, - HCI_MAIN_BUSY, - HCI_TX_REQ, - HCI_PHY_EVT_MAX -} hci_dbg_evt_type_t; - - -//Low level hardware event definition -typedef struct -{ - hci_dbg_evt_type_t evt; - uint32_t data; -} hci_dbg_evt_t; - -typedef void (*hci_dbg_event_handler_t)(hci_dbg_evt_t event); - -void debug_init(hci_dbg_event_handler_t evt_callback); - -void debug_evt(hci_dbg_evt_type_t evt, uint32_t data); - - -#define DEBUG_EVT(event_type, data) \ -do { \ - debug_evt(event_type, data); \ -} while(0); - - -#define DEBUG_EVT_HCI_PHY_EVT_TX_PKT_SENT(data) \ -do { \ - DEBUG_EVT(HCI_PHY_EVT_TX_PKT_SENT, data); \ -} while (0); - - -#define DEBUG_EVT_HCI_PHY_EVT_BUF_REQUEST(data) \ -do { \ - DEBUG_EVT(HCI_PHY_EVT_BUF_REQUEST, data); \ -} while (0); - - -#define DEBUG_EVT_HCI_PHY_EVT_RX_PKT_RECEIVED(data) \ -do { \ - DEBUG_EVT(HCI_PHY_EVT_RX_PKT_RECEIVED, data); \ -} while (0); - - -#define DEBUG_EVT_HCI_PHY_EVT_RX_PKT_DROPPED(data) \ -do { \ - DEBUG_EVT(HCI_PHY_EVT_RX_PKT_DROPPED, data); \ -} while (0); - -#define DEBUG_EVT_HCI_PHY_EVT_TX_ERROR(data) \ -do { \ - DEBUG_EVT(HCI_PHY_EVT_TX_ERROR, data); \ -} while (0); - -#define DEBUG_EVT_SLIP_PACKET_TX(data) \ -do { \ - DEBUG_EVT(HCI_SLIP_EVT_PACKET_TX, data); \ -} while (0); - -#define DEBUG_EVT_SLIP_ACK_TX(data) \ -do { \ - DEBUG_EVT(HCI_SLIP_EVT_ACK_TX, data); \ -} while (0); - -#define DEBUG_EVT_SLIP_PACKET_TXED(data) \ -do { \ - DEBUG_EVT(HCI_SLIP_EVT_PACKET_TXED, data); \ -} while (0); - -#define DEBUG_EVT_SLIP_ACK_TXED(data) \ -do { \ - DEBUG_EVT(HCI_SLIP_EVT_ACK_TXED, data); \ -} while (0); - -#define DEBUG_EVT_SLIP_PACKET_RXED(data) \ -do { \ - DEBUG_EVT(HCI_SLIP_EVT_PACKET_RXED, data); \ -} while (0); - -#define DEBUG_EVT_SLIP_ACK_RXED(data) \ -do { \ - DEBUG_EVT(HCI_SLIP_EVT_ACK_RXED, data); \ -} while (0); - -#define DEBUG_EVT_SLIP_ERR_RXED(data) \ -do { \ - DEBUG_EVT(HCI_SLIP_EVT_ERR_RXED, data); \ -} while (0); - -#define DEBUG_EVT_TIMEOUT(data) \ -do { \ - DEBUG_EVT(HCI_TIMER_EVT_TIMEOUT, data); \ -} while (0); - -#define DEBUG_HCI_RETX(data) \ -do { \ - DEBUG_EVT(HCI_RETX, data); \ -} while (0); - -#define DEBUG_EVT_MAIN_BUSY(data) \ -do { \ - DEBUG_EVT(HCI_MAIN_BUSY, data); \ -} while (0); - -#define DEBUG_EVT_TX_REQ(data) \ -do { \ - DEBUG_EVT(HCI_TX_REQ, data); \ -} while (0); - -#endif // SER_PHY_HCI_DEBUG_ENABLE - -#ifdef __cplusplus -} -#endif - -#endif // SER_PHY_DEBUG_COMM_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/serialization/connectivity/codecs/common/ble_dtm_conn.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/connectivity/codecs/common/ble_dtm_conn.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/connectivity/codecs/common/ble_dtm_conn.h deleted file mode 100644 index 0ea2677..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/connectivity/codecs/common/ble_dtm_conn.h +++ /dev/null @@ -1,85 +0,0 @@ -/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - -#ifndef BLE_DTM_CONN_H__ -#define BLE_DTM_CONN_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup ser_codecs Serialization codecs - * @ingroup ble_sdk_lib_serialization - */ - -/** - * @addtogroup ser_conn_common_codecs Connectivity common codecs - * @ingroup ser_codecs - */ - -/**@file - * - * @defgroup ble_dtm_conn DTM Connectivity command request decoder and command response encoder - * @{ - * @ingroup ser_conn_common_codecs - * - * @brief DTM Connectivity command request decoder and command response encoder - */ - -#include "dtm_uart.h" - -/**@brief Decodes @ref ble_dtm_init command request. - * - * @sa @ref nrf51_dtm_init_encoding_sec for packet format, - * @ref ble_dtm_init_rsp_enc for response encoding. - * - * @param[in] p_buf Pointer to beginning of command request packet. - * @param[in] packet_len Length (in bytes) of request packet. - * @param[in] p_comm_params Pointer to the structure with DTM Uart configuration. - - * - * @retval NRF_SUCCESS Decoding success. - * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. - * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. - */ -uint32_t ble_dtm_init_req_dec(uint8_t const * const p_buf, - uint16_t packet_len, - app_uart_stream_comm_params_t * p_comm_params); - - -/**@brief Encodes @ref ble_dtm_init command response. - * - * @sa @ref nrf51_dtm_init_encoding_sec for packet format. - * @ref ble_dtm_init_req_dec for request decoding. - * - * @param[in] return_code Return code indicating if command was successful or not. - * @param[out] p_buf Pointer to buffer where encoded data command response will be - * returned. - * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. - * \c out: Length of encoded command response packet. - * - * @retval NRF_SUCCESS Encoding success. - * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. - * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. - */ -uint32_t ble_dtm_init_rsp_enc(uint32_t return_code, - uint8_t * const p_buf, - uint32_t * const p_buf_len); - -/** @} */ -#ifdef __cplusplus -} -#endif - -#endif // BLE_DTM_CONN_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/serialization/connectivity/codecs/common/ble_dtm_init.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/connectivity/codecs/common/ble_dtm_init.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/connectivity/codecs/common/ble_dtm_init.c deleted file mode 100644 index 2c46424..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/connectivity/codecs/common/ble_dtm_init.c +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - -#include "ble_dtm_conn.h" -#include "dtm_uart.h" -#include "nrf_error.h" -#include "ble_serialization.h" - -uint32_t ble_dtm_init_req_dec(uint8_t const * const p_buf, uint16_t packet_len, - app_uart_stream_comm_params_t * p_comm_params) -{ - SER_ASSERT_NOT_NULL(p_buf); - SER_ASSERT_NOT_NULL(p_comm_params); - - uint32_t index = 0; - uint32_t err_code = NRF_SUCCESS; - - err_code = uint8_t_dec(p_buf, packet_len, &index, &p_comm_params->tx_pin_no); - SER_ASSERT(err_code == NRF_SUCCESS, err_code); - - err_code = uint8_t_dec(p_buf, packet_len, &index, &p_comm_params->rx_pin_no); - SER_ASSERT(err_code == NRF_SUCCESS, err_code); - - err_code = uint8_t_dec(p_buf, packet_len, &index, &p_comm_params->baud_rate); - SER_ASSERT(err_code == NRF_SUCCESS, err_code); - - SER_ASSERT(index == packet_len, NRF_ERROR_INVALID_LENGTH); - - return err_code; -} - -uint32_t ble_dtm_init_rsp_enc(uint32_t return_code, uint8_t * const p_buf, - uint32_t * const p_buf_len) -{ - SER_ASSERT_NOT_NULL(p_buf); - SER_ASSERT_NOT_NULL(p_buf_len); - - uint32_t index = 0; - uint32_t err_code = NRF_SUCCESS; - - err_code = uint32_t_enc(&return_code, p_buf, *p_buf_len, &index); - SER_ASSERT(err_code == NRF_SUCCESS, err_code); - - *p_buf_len = index; - - return err_code; -} 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/serialization/connectivity/codecs/common/conn_mw.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/connectivity/codecs/common/conn_mw.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/connectivity/codecs/common/conn_mw.c deleted file mode 100644 index 36660c4..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/connectivity/codecs/common/conn_mw.c +++ /dev/null @@ -1,84 +0,0 @@ -/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ -#include <stddef.h> - -#include "ble_serialization.h" -#include "nrf_soc.h" -#include "ble.h" -#include "ble_l2cap.h" -#include "ble_gap.h" -#include "ble_gattc.h" -#include "ble_gatts.h" - -/**@brief Connectivity middleware handler type. */ -typedef uint32_t (*conn_mw_handler_t)(uint8_t const * const p_rx_buf, - uint32_t rx_buf_len, - uint8_t * const p_tx_buf, - uint32_t * const p_tx_buf_len); - -/**@brief Connectivity middleware item. */ -typedef struct -{ - uint8_t opcode; /**< Opcode by which specific codec is identified */ - conn_mw_handler_t fp_handler; /**< Function pointer to handler associated with given opcode */ -} conn_mw_item_t; - -/* Include handlers for given softdevice */ -#include "conn_mw_items.c" - -/**@brief Number of registered connectivity middleware handlers. */ -static const uint32_t conn_mw_item_len = sizeof (conn_mw_item) / sizeof (conn_mw_item[0]); - -/**@brief Local function for finding connectivity middleware handler in the table.. */ -static conn_mw_handler_t conn_mw_handler_get(uint8_t opcode) -{ - conn_mw_handler_t fp_handler = NULL; - uint32_t i; - - for (i = 0; i < conn_mw_item_len; i++) - { - if (opcode == conn_mw_item[i].opcode) - { - fp_handler = conn_mw_item[i].fp_handler; - break; - } - } - - return fp_handler; -} - -uint32_t conn_mw_handler(uint8_t const * const p_rx_buf, - uint32_t rx_buf_len, - uint8_t * const p_tx_buf, - uint32_t * const p_tx_buf_len) -{ - SER_ASSERT_NOT_NULL(p_rx_buf); - SER_ASSERT_NOT_NULL(p_tx_buf); - SER_ASSERT_NOT_NULL(p_tx_buf_len); - - conn_mw_handler_t fp_handler; - uint32_t err_code = NRF_SUCCESS; - uint8_t opcode = p_rx_buf[SER_CMD_OP_CODE_POS]; - - fp_handler = conn_mw_handler_get(opcode); - - if (fp_handler) - { - err_code = fp_handler(p_rx_buf, rx_buf_len, p_tx_buf, p_tx_buf_len); - } - else - { - err_code = NRF_ERROR_NOT_SUPPORTED; - } - - return err_code; -} 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/serialization/connectivity/codecs/common/conn_mw.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/connectivity/codecs/common/conn_mw.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/connectivity/codecs/common/conn_mw.h deleted file mode 100644 index 047dddf..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/connectivity/codecs/common/conn_mw.h +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ -#ifndef _CONN_MW_H -#define _CONN_MW_H - -#include <stdint.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/**@brief Connectivity Middleware dispatcher function - * - * @details It will handle decode the opcode from RX buffer and based on the opcode it will search - * for registered handler. Handler is called once it is found. - * - * @param[in] p_rx_buf Pointer to input buffer. - * @param[in] rx_buf_len Size of p_rx_buf. - * @param[out] p_tx_buf Pointer to output buffer. - * @param[in,out] p_tx_buf_len \c in: size of \p p_tx_buf buffer. - * \c out: Length of valid data in \p p_tx_buf. - * - * @retval NRF_SUCCESS Handler success. - * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. - * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. - * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. - * @retval NRF_ERROR_NOT_SUPPORTED Handler failure. Opcode not supported. - */ -uint32_t conn_mw_handler (uint8_t const * const p_rx_buf, - uint32_t rx_buf_len, - uint8_t * const p_tx_buf, - uint32_t * const p_tx_buf_len); -#ifdef __cplusplus -} -#endif - -#endif //_CONN_MW_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/serialization/connectivity/codecs/s130/middleware/conn_mw.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/connectivity/codecs/s130/middleware/conn_mw.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/connectivity/codecs/s130/middleware/conn_mw.h deleted file mode 100644 index 047dddf..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/serialization/connectivity/codecs/s130/middleware/conn_mw.h +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ -#ifndef _CONN_MW_H -#define _CONN_MW_H - -#include <stdint.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/**@brief Connectivity Middleware dispatcher function - * - * @details It will handle decode the opcode from RX buffer and based on the opcode it will search - * for registered handler. Handler is called once it is found. - * - * @param[in] p_rx_buf Pointer to input buffer. - * @param[in] rx_buf_len Size of p_rx_buf. - * @param[out] p_tx_buf Pointer to output buffer. - * @param[in,out] p_tx_buf_len \c in: size of \p p_tx_buf buffer. - * \c out: Length of valid data in \p p_tx_buf. - * - * @retval NRF_SUCCESS Handler success. - * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. - * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. - * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. - * @retval NRF_ERROR_NOT_SUPPORTED Handler failure. Opcode not supported. - */ -uint32_t conn_mw_handler (uint8_t const * const p_rx_buf, - uint32_t rx_buf_len, - uint8_t * const p_tx_buf, - uint32_t * const p_tx_buf_len); -#ifdef __cplusplus -} -#endif - -#endif //_CONN_MW_H
