mirror of
https://github.com/jam422470459/EPD-nRF52-hema213.git
synced 2025-12-18 14:23:20 +08:00
move components to SDK dir
This commit is contained in:
@@ -0,0 +1,282 @@
|
||||
/**
|
||||
* Copyright (c) 2014 - 2017, 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, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, 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 its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "ser_sd_transport.h"
|
||||
#include "ser_hal_transport.h"
|
||||
#include "nrf_error.h"
|
||||
#include "app_error.h"
|
||||
#include "ble_serialization.h"
|
||||
#include "ser_dbg_sd_str.h"
|
||||
#include "ser_app_power_system_off.h"
|
||||
#include "app_util.h"
|
||||
#define NRF_LOG_MODULE_NAME "SER_XFER"
|
||||
#include "nrf_log.h"
|
||||
|
||||
/** SoftDevice event handler. */
|
||||
static ser_sd_transport_evt_handler_t m_evt_handler = NULL;
|
||||
|
||||
/** 'One time' handler called in task context while waiting for response to scheduled command. */
|
||||
static ser_sd_transport_rsp_wait_handler_t m_ot_rsp_wait_handler = NULL;
|
||||
|
||||
/** Handler called in task context while waiting for response to scheduled command. */
|
||||
static ser_sd_transport_rsp_wait_handler_t m_os_rsp_wait_handler = NULL;
|
||||
|
||||
/** Handler called in serial peripheral interrupt context when response is received. */
|
||||
static ser_sd_transport_rsp_set_handler_t m_os_rsp_set_handler = NULL;
|
||||
|
||||
/** Handler called when hal_transport notifies that packet reception has started. */
|
||||
static ser_sd_transport_rx_notification_handler_t m_rx_notify_handler = NULL;
|
||||
|
||||
/** User decoder handler for expected response packet. */
|
||||
static ser_sd_transport_rsp_handler_t m_rsp_dec_handler = NULL;
|
||||
|
||||
/** Flag indicated whether module is waiting for response packet. */
|
||||
static volatile bool m_rsp_wait = false;
|
||||
|
||||
/** SoftDevice call return value decoded by user decoder handler. */
|
||||
static uint32_t m_return_value;
|
||||
|
||||
/**@brief Function for handling the rx packets comming from hal_transport.
|
||||
*
|
||||
* @details
|
||||
* This function is called in serial peripheral interrupt context. Response packets are handled in
|
||||
* this context. Events are passed to the application and it is up to application in which context
|
||||
* they are handled.
|
||||
*
|
||||
* @param[in] p_data Pointer to received data.
|
||||
* @param[in] length Size of data.
|
||||
*/
|
||||
static void ser_sd_transport_rx_packet_handler(uint8_t * p_data, uint16_t length)
|
||||
{
|
||||
if (p_data && (length >= SER_PKT_TYPE_SIZE))
|
||||
{
|
||||
const uint8_t packet_type = p_data[SER_PKT_TYPE_POS];
|
||||
p_data += SER_PKT_TYPE_SIZE;
|
||||
length -= SER_PKT_TYPE_SIZE;
|
||||
|
||||
switch (packet_type)
|
||||
{
|
||||
case SER_PKT_TYPE_RESP:
|
||||
case SER_PKT_TYPE_DTM_RESP:
|
||||
|
||||
if (m_rsp_wait)
|
||||
{
|
||||
m_return_value = m_rsp_dec_handler(p_data, length);
|
||||
(void)ser_sd_transport_rx_free(p_data);
|
||||
|
||||
/* Reset response flag - cmd_write function is pending on it.*/
|
||||
m_rsp_wait = false;
|
||||
|
||||
/* If os handler is set, signal os that response has arrived.*/
|
||||
if (m_os_rsp_set_handler)
|
||||
{
|
||||
m_os_rsp_set_handler();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Unexpected packet. */
|
||||
(void)ser_sd_transport_rx_free(p_data);
|
||||
APP_ERROR_HANDLER(packet_type);
|
||||
}
|
||||
break;
|
||||
|
||||
case SER_PKT_TYPE_EVT:
|
||||
/* It is ensured during opening that handler is not NULL. No check needed. */
|
||||
NRF_LOG_DEBUG("[EVT]: %s \r\n", (uint32_t)ser_dbg_sd_evt_str_get(uint16_decode(&p_data[SER_EVT_ID_POS]))); // p_data points to EVT_ID
|
||||
m_evt_handler(p_data, length);
|
||||
break;
|
||||
|
||||
default:
|
||||
(void)ser_sd_transport_rx_free(p_data);
|
||||
APP_ERROR_HANDLER(packet_type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**@brief Function for handling the event from hal_transport.
|
||||
*
|
||||
* @param[in] event Event from hal_transport.
|
||||
*/
|
||||
static void ser_sd_transport_hal_handler(ser_hal_transport_evt_t event)
|
||||
{
|
||||
switch (event.evt_type)
|
||||
{
|
||||
case SER_HAL_TRANSP_EVT_RX_PKT_RECEIVED:
|
||||
ser_sd_transport_rx_packet_handler(event.evt_params.rx_pkt_received.p_buffer,
|
||||
event.evt_params.rx_pkt_received.num_of_bytes);
|
||||
break;
|
||||
case SER_HAL_TRANSP_EVT_RX_PKT_RECEIVING:
|
||||
if (m_rx_notify_handler)
|
||||
{
|
||||
m_rx_notify_handler();
|
||||
}
|
||||
break;
|
||||
case SER_HAL_TRANSP_EVT_TX_PKT_SENT:
|
||||
if (ser_app_power_system_off_get() == true)
|
||||
{
|
||||
ser_app_power_system_off_enter();
|
||||
}
|
||||
break;
|
||||
case SER_HAL_TRANSP_EVT_PHY_ERROR:
|
||||
|
||||
if (m_rsp_wait)
|
||||
{
|
||||
m_return_value = NRF_ERROR_INTERNAL;
|
||||
|
||||
/* Reset response flag - cmd_write function is pending on it.*/
|
||||
m_rsp_wait = false;
|
||||
|
||||
/* If os handler is set, signal os that response has arrived.*/
|
||||
if (m_os_rsp_set_handler)
|
||||
{
|
||||
m_os_rsp_set_handler();
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ser_sd_transport_open(ser_sd_transport_evt_handler_t evt_handler,
|
||||
ser_sd_transport_rsp_wait_handler_t os_rsp_wait_handler,
|
||||
ser_sd_transport_rsp_set_handler_t os_rsp_set_handler,
|
||||
ser_sd_transport_rx_notification_handler_t rx_notify_handler)
|
||||
{
|
||||
m_os_rsp_wait_handler = os_rsp_wait_handler;
|
||||
m_os_rsp_set_handler = os_rsp_set_handler;
|
||||
m_rx_notify_handler = rx_notify_handler;
|
||||
m_ot_rsp_wait_handler = NULL;
|
||||
m_evt_handler = evt_handler;
|
||||
|
||||
if (evt_handler == NULL)
|
||||
{
|
||||
return NRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
return ser_hal_transport_open(ser_sd_transport_hal_handler);
|
||||
}
|
||||
|
||||
uint32_t ser_sd_transport_close(void)
|
||||
{
|
||||
m_evt_handler = NULL;
|
||||
m_os_rsp_wait_handler = NULL;
|
||||
m_os_rsp_set_handler = NULL;
|
||||
m_ot_rsp_wait_handler = NULL;
|
||||
|
||||
ser_hal_transport_close();
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t ser_sd_transport_ot_rsp_wait_handler_set(ser_sd_transport_rsp_wait_handler_t handler)
|
||||
{
|
||||
m_ot_rsp_wait_handler = handler;
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
bool ser_sd_transport_is_busy(void)
|
||||
{
|
||||
return m_rsp_wait;
|
||||
}
|
||||
|
||||
uint32_t ser_sd_transport_tx_alloc(uint8_t * * pp_data, uint16_t * p_len)
|
||||
{
|
||||
uint32_t err_code;
|
||||
|
||||
if (m_rsp_wait)
|
||||
{
|
||||
err_code = NRF_ERROR_BUSY;
|
||||
}
|
||||
else
|
||||
{
|
||||
err_code = ser_hal_transport_tx_pkt_alloc(pp_data, p_len);
|
||||
}
|
||||
return err_code;
|
||||
}
|
||||
|
||||
uint32_t ser_sd_transport_tx_free(uint8_t * p_data)
|
||||
{
|
||||
return ser_hal_transport_tx_pkt_free(p_data);
|
||||
}
|
||||
|
||||
uint32_t ser_sd_transport_rx_free(uint8_t * p_data)
|
||||
{
|
||||
p_data -= SER_PKT_TYPE_SIZE;
|
||||
return ser_hal_transport_rx_pkt_free(p_data);
|
||||
}
|
||||
|
||||
uint32_t ser_sd_transport_cmd_write(const uint8_t * p_buffer,
|
||||
uint16_t length,
|
||||
ser_sd_transport_rsp_handler_t cmd_rsp_decode_callback)
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
m_rsp_wait = true;
|
||||
m_rsp_dec_handler = cmd_rsp_decode_callback;
|
||||
err_code = ser_hal_transport_tx_pkt_send(p_buffer, length);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
/* Execute callback for response decoding only if one was provided.*/
|
||||
if ((err_code == NRF_SUCCESS) && cmd_rsp_decode_callback)
|
||||
{
|
||||
if (m_ot_rsp_wait_handler)
|
||||
{
|
||||
m_ot_rsp_wait_handler();
|
||||
m_ot_rsp_wait_handler = NULL;
|
||||
}
|
||||
|
||||
m_os_rsp_wait_handler();
|
||||
err_code = m_return_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_rsp_wait = false;
|
||||
}
|
||||
|
||||
NRF_LOG_DEBUG("[SD_CALL]:%s, err_code= 0x%X\r\n", (uint32_t)ser_dbg_sd_call_str_get(p_buffer[1]), err_code);
|
||||
return err_code;
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
/**
|
||||
* Copyright (c) 2014 - 2017, 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, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, 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 its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup ser_app Application side code
|
||||
* @ingroup ble_sdk_lib_serialization
|
||||
* @brief @tagAPI52832 SoftDevice handler and transport on the application side.
|
||||
*/
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @defgroup ser_sd_transport Serialization SoftDevice Transport
|
||||
* @{
|
||||
* @ingroup ser_app
|
||||
*
|
||||
* @brief Serialization SoftDevice Transport on application side.
|
||||
*
|
||||
* @details This file contains declarations of functions and definitions of data structures and
|
||||
* identifiers (typedef enum) used as API of the serialization of SoftDevice. This layer
|
||||
* ensures atomic nature of SoftDevice calls (command and waiting for response). Packet
|
||||
* type field of incoming packets is handled in this layer - responses are handled by
|
||||
* ser_sd_transport (using response decoder handler provided for each SoftDevice call), but
|
||||
* events are forwarded to the user so it is up to the user to free the RX buffer.
|
||||
*
|
||||
*/
|
||||
#ifndef SER_SD_TRANSPORT_H_
|
||||
#define SER_SD_TRANSPORT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*ser_sd_transport_evt_handler_t)(uint8_t * p_buffer, uint16_t length);
|
||||
typedef void (*ser_sd_transport_rsp_wait_handler_t)(void);
|
||||
typedef void (*ser_sd_transport_rsp_set_handler_t)(void);
|
||||
typedef void (*ser_sd_transport_rx_notification_handler_t)(void);
|
||||
|
||||
typedef uint32_t (*ser_sd_transport_rsp_handler_t)(const uint8_t * p_buffer, uint16_t length);
|
||||
|
||||
/**@brief Function for opening the module.
|
||||
*
|
||||
* @note 'Wait for response' and 'Response set' callbacks can be set in RTOS environment.
|
||||
* It enables rescheduling while waiting for the Connectivity Chip response. In a nonOS environment,
|
||||
* usually 'Wait for response' will only be used for handling incoming events or forcing the
|
||||
* application to low power mode.
|
||||
*
|
||||
* @param[in] evt_handler Handler to be called when event packet is received.
|
||||
* @param[in] os_rsp_wait_handler Handler to be called after the request is send. It should
|
||||
* implement a 'Wait for signal' functionality in an OS environment.
|
||||
* @param[in] os_rsp_set_handler Handler to be called after response reception. It should
|
||||
* implement a 'Signal Set' functionality in an OS environment.
|
||||
* @param[in] rx_not_handler Handler to be called after the transport layer notifies that
|
||||
* an incoming RX packet is detected.
|
||||
*
|
||||
* @retval NRF_SUCCESS Operation success.
|
||||
* @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
|
||||
* @retval NRF_ERROR_INVALID_PARAM Operation failure. Parameter propagated from ser_hal_transport
|
||||
* opening or timer creation.
|
||||
* @retval NRF_ERROR_INVALID_STATE Operation failure. Parameter propagated from ser_hal_transport
|
||||
* opening or timer creation.
|
||||
* @retval NRF_ERROR_INTERNAL Operation failure. Parameter propagated from ser_hal_transport
|
||||
* opening or timer creation.
|
||||
* @retval NRF_ERROR_NO_MEM Operation failure. Parameter propagated from timer creation.
|
||||
*/
|
||||
uint32_t ser_sd_transport_open(ser_sd_transport_evt_handler_t evt_handler,
|
||||
ser_sd_transport_rsp_wait_handler_t os_rsp_wait_handler,
|
||||
ser_sd_transport_rsp_set_handler_t os_rsp_set_handler,
|
||||
ser_sd_transport_rx_notification_handler_t rx_not_handler);
|
||||
|
||||
/**@brief Function setting a 'One Time' handler to be called between sending the next request packet and
|
||||
* receiving the response packet.
|
||||
* @note It is intended to be used in a nonOS environment to implement concurrency.
|
||||
* @note It is a 'One Time' handler meaning that it is valid only for the next SoftDevice call processing.
|
||||
*
|
||||
*
|
||||
* @param[in] wait_handler Handler to be called after the request packet is sent.
|
||||
*
|
||||
* @retval NRF_SUCCESS Operation success.
|
||||
*/
|
||||
uint32_t ser_sd_transport_ot_rsp_wait_handler_set(ser_sd_transport_rsp_wait_handler_t wait_handler);
|
||||
|
||||
|
||||
/**@brief Function for closing the module.
|
||||
*
|
||||
* @retval NRF_SUCCESS Operation success.
|
||||
*/
|
||||
uint32_t ser_sd_transport_close(void);
|
||||
|
||||
/**@brief Function for allocating a TX packet to be used for request command.
|
||||
*
|
||||
* @param[out] pp_data Pointer to the data pointer to be set to point to allocated buffer.
|
||||
* @param[out] p_len Pointer to allocated buffer length.
|
||||
*
|
||||
* @retval NRF_SUCCESS Operation success.
|
||||
*/
|
||||
uint32_t ser_sd_transport_tx_alloc(uint8_t * * pp_data, uint16_t * p_len);
|
||||
|
||||
|
||||
/**@brief Function for freeing a TX packet.
|
||||
*
|
||||
* @note Function should be called once the command is processed.
|
||||
*
|
||||
* @param[out] p_data Pointer to the allocated TX buffer.
|
||||
*
|
||||
* @retval NRF_SUCCESS Operation success.
|
||||
*/
|
||||
uint32_t ser_sd_transport_tx_free(uint8_t * p_data);
|
||||
|
||||
|
||||
/**@brief Function for freeing an RX event packet.
|
||||
*
|
||||
* @note Function should be called once the SoftDevice event buffer is processed.
|
||||
*
|
||||
* @param[out] p_data Pointer to the allocated RX buffer.
|
||||
*
|
||||
* @retval NRF_SUCCESS Operation success.
|
||||
*/
|
||||
uint32_t ser_sd_transport_rx_free(uint8_t * p_data);
|
||||
|
||||
|
||||
/**@brief Function for checking if module is busy waiting for response from connectivity side.
|
||||
*
|
||||
* @retval true Module busy. Cannot accept the next command.
|
||||
* @retval false Module not busy. Can accept next the command.
|
||||
*/
|
||||
bool ser_sd_transport_is_busy(void);
|
||||
|
||||
/**@brief Function for handling a SoftDevice command.
|
||||
*
|
||||
* @note Function blocks task context until response is received and processed.
|
||||
* @note Non-blocking functionality can be achieved using OS handlers or a 'One Time' handler
|
||||
* @warning Function should not be called from interrupt context, which would block switching to
|
||||
* serial port interrupt.
|
||||
*
|
||||
* @param[in] p_buffer Pointer to command.
|
||||
* @param[in] length Pointer to allocated buffer length.
|
||||
* @param[in] cmd_resp_decode_callback Pointer to a function for decoding the response packet.
|
||||
*
|
||||
* @retval NRF_SUCCESS Operation success.
|
||||
*/
|
||||
uint32_t ser_sd_transport_cmd_write(const uint8_t * p_buffer,
|
||||
uint16_t length,
|
||||
ser_sd_transport_rsp_handler_t cmd_resp_decode_callback);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SER_SD_TRANSPORT_H_ */
|
||||
/** @} */
|
||||
@@ -0,0 +1,214 @@
|
||||
/**
|
||||
* Copyright (c) 2014 - 2017, 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, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, 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 its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "ble_app.h"
|
||||
#include "nrf_queue.h"
|
||||
#include "app_scheduler.h"
|
||||
#include "softdevice_handler.h"
|
||||
#include "ser_sd_transport.h"
|
||||
#include "ser_app_hal.h"
|
||||
#include "ser_config.h"
|
||||
#include "nrf_soc.h"
|
||||
|
||||
|
||||
#define SD_BLE_EVT_MAILBOX_QUEUE_SIZE 5 /**< Size of mailbox queue. */
|
||||
|
||||
/** @brief Structure used to pass packet details through mailbox.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t evt_data[CEIL_DIV(BLE_STACK_EVT_MSG_BUF_SIZE, sizeof (uint32_t))]; /**< Buffer for decoded event */
|
||||
} ser_sd_handler_evt_data_t;
|
||||
|
||||
/** @brief
|
||||
* Mailbox used for communication between event handler (called from serial stream
|
||||
* interrupt context) and event processing function (called from scheduler or interrupt context).
|
||||
*/
|
||||
NRF_QUEUE_DEF(ser_sd_handler_evt_data_t,
|
||||
m_sd_ble_evt_mailbox,
|
||||
SD_BLE_EVT_MAILBOX_QUEUE_SIZE,
|
||||
NRF_QUEUE_MODE_NO_OVERFLOW);
|
||||
|
||||
NRF_QUEUE_DEF(uint32_t,
|
||||
m_sd_soc_evt_mailbox,
|
||||
SD_BLE_EVT_MAILBOX_QUEUE_SIZE,
|
||||
NRF_QUEUE_MODE_NO_OVERFLOW);
|
||||
|
||||
/**
|
||||
* @brief Function to be replaced by user implementation if needed.
|
||||
*
|
||||
* Weak function - user can add different implementation of this function if application needs it.
|
||||
*/
|
||||
__WEAK void os_rsp_set_handler(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void connectivity_reset_low(void)
|
||||
{
|
||||
//Signal a reset to the connectivity chip by setting the reset pin low.
|
||||
ser_app_hal_nrf_reset_pin_clear();
|
||||
ser_app_hal_delay(CONN_CHIP_RESET_TIME);
|
||||
|
||||
}
|
||||
|
||||
static void connectivity_reset_high(void)
|
||||
{
|
||||
|
||||
//Set the reset level to high again.
|
||||
ser_app_hal_nrf_reset_pin_set();
|
||||
|
||||
//Wait for connectivity chip to be ready.
|
||||
ser_app_hal_delay(CONN_CHIP_WAKEUP_TIME);
|
||||
}
|
||||
|
||||
static void ser_softdevice_evt_handler(uint8_t * p_data, uint16_t length)
|
||||
{
|
||||
ser_sd_handler_evt_data_t item;
|
||||
uint32_t err_code;
|
||||
uint32_t len32 = sizeof (item.evt_data);
|
||||
|
||||
err_code = ble_event_dec(p_data, length, (ble_evt_t *)item.evt_data, &len32);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = ser_sd_transport_rx_free(p_data);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_queue_push(&m_sd_ble_evt_mailbox, &item);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
ser_app_hal_nrf_evt_pending();
|
||||
}
|
||||
|
||||
void ser_softdevice_flash_operation_success_evt(bool success)
|
||||
{
|
||||
uint32_t evt_type = success ? NRF_EVT_FLASH_OPERATION_SUCCESS :
|
||||
NRF_EVT_FLASH_OPERATION_ERROR;
|
||||
|
||||
uint32_t err_code = nrf_queue_push(&m_sd_soc_evt_mailbox, &evt_type);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
ser_app_hal_nrf_evt_pending();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function called while waiting for connectivity chip response. It handles incoming events.
|
||||
*/
|
||||
static void ser_sd_rsp_wait(void)
|
||||
{
|
||||
do
|
||||
{
|
||||
(void)sd_app_evt_wait();
|
||||
|
||||
//intern_softdevice_events_execute();
|
||||
}
|
||||
while (ser_sd_transport_is_busy());
|
||||
}
|
||||
|
||||
uint32_t sd_evt_get(uint32_t * p_evt_id)
|
||||
{
|
||||
return nrf_queue_pop(&m_sd_soc_evt_mailbox, p_evt_id);
|
||||
}
|
||||
|
||||
uint32_t sd_ble_evt_get(uint8_t * p_data, uint16_t * p_len)
|
||||
{
|
||||
uint32_t err_code = nrf_queue_pop(&m_sd_ble_evt_mailbox, p_data);
|
||||
|
||||
if (err_code == NRF_SUCCESS) //if anything in the mailbox
|
||||
{
|
||||
if (((ble_evt_t *)p_data)->header.evt_len > *p_len)
|
||||
{
|
||||
err_code = NRF_ERROR_DATA_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
*p_len = ((ble_evt_t *)p_data)->header.evt_len;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
err_code = NRF_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
uint32_t sd_ble_evt_mailbox_length_get(uint32_t * p_mailbox_length)
|
||||
{
|
||||
*p_mailbox_length = nrf_queue_utilization_get(&m_sd_ble_evt_mailbox);
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t sd_softdevice_enable(nrf_clock_lf_cfg_t const * p_clock_lf_cfg,
|
||||
nrf_fault_handler_t assertion_handler)
|
||||
{
|
||||
uint32_t err_code;
|
||||
|
||||
err_code = ser_app_hal_hw_init(ser_softdevice_flash_operation_success_evt);
|
||||
|
||||
if (err_code == NRF_SUCCESS)
|
||||
{
|
||||
connectivity_reset_low();
|
||||
|
||||
nrf_queue_reset(&m_sd_soc_evt_mailbox);
|
||||
nrf_queue_reset(&m_sd_ble_evt_mailbox);
|
||||
|
||||
err_code = ser_sd_transport_open(ser_softdevice_evt_handler,
|
||||
ser_sd_rsp_wait,
|
||||
os_rsp_set_handler,
|
||||
NULL);
|
||||
if (err_code == NRF_SUCCESS)
|
||||
{
|
||||
connectivity_reset_high();
|
||||
}
|
||||
|
||||
ser_app_hal_nrf_evt_irq_priority_set();
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
uint32_t sd_softdevice_disable(void)
|
||||
{
|
||||
return ser_sd_transport_close();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Copyright (c) 2014 - 2017, 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, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, 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 its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup ser_app Application side code
|
||||
* @ingroup ble_sdk_lib_serialization
|
||||
*/
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @defgroup ser_softdevice_handler Serialization SoftDevice Handler
|
||||
* @{
|
||||
* @ingroup ser_app
|
||||
*
|
||||
* @brief Serialization SoftDevice Handler on application side.
|
||||
*
|
||||
*/
|
||||
#ifndef SER_SOFTDEVICE_HANDLER_H_
|
||||
#define SER_SOFTDEVICE_HANDLER_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**@brief Function for checking if there are any more events in the internal mailbox.
|
||||
*
|
||||
* @param[in] p_mailbox_length Pointer to mailbox length.
|
||||
*
|
||||
* @retval ::NRF_SUCCESS Length succesfully obtained.
|
||||
* @retval ::NRF_ERROR_NULL Null pointer provided.
|
||||
*/
|
||||
uint32_t sd_ble_evt_mailbox_length_get(uint32_t * p_mailbox_length);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SER_SOFTDEVICE_HANDLER_H_ */
|
||||
/** @} */
|
||||
Reference in New Issue
Block a user