Unverified Commit be298105 authored by Bjørn Inge Hanssen's avatar Bjørn Inge Hanssen Committed by GitHub
Browse files

Merge pull request #62 from NordicSemiconductor/fix/NCP-1255-retransmission

Fix problem related to control packet state transitions
parents a3a0b93b 8b0091e6
......@@ -144,7 +144,19 @@ diff --git a/components/serialization/common/transport/ser_phy/ser_phy_hci.c b/c
#define TX_EVT_QUEUE_SIZE 16
#define RX_EVT_QUEUE_SIZE 16
#define PKT_TYPE_VENDOR_SPECIFIC 14 /**< Packet type vendor specific. */
@@ -756,6 +758,11 @@ static void hci_slip_event_handler(ser_phy_hci_slip_evt_t * p_event)
@@ -48,7 +50,11 @@
#define INITIAL_SEQ_NUMBER INITIAL_ACK_NUMBER_EXPECTED /**< Initial acknowledge number transmitted. */
#define INVALID_PKT_TYPE 0xFFFFFFFFu /**< Internal invalid packet type value. */
#define MAX_TRANSMISSION_TIME_ms (MAX_PACKET_SIZE_IN_BITS * BAUD_TIME_us / 1000uL) /**< Max transmission time of a single application packet over UART in units of mseconds. */
+#if SER_PHY_UART_BAUDRATE == UART_BAUDRATE_BAUDRATE_Baud115200
#define RETRANSMISSION_TIMEOUT_IN_ms (10uL * MAX_TRANSMISSION_TIME_ms) /**< Retransmission timeout for application packet in units of mseconds. */
+#else
+#define RETRANSMISSION_TIMEOUT_IN_ms (50uL * MAX_TRANSMISSION_TIME_ms) /**< Retransmission timeout for application packet in units of mseconds. */
+#endif
#ifdef HCI_LINK_CONTROL
#define HCI_PKT_SYNC 0x7E01u /**< Link Control Packet: type SYNC */
@@ -756,6 +762,11 @@ static void hci_slip_event_handler(ser_phy_hci_slip_evt_t * p_event)
event.evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer,
event.evt.ser_phy_slip_evt.evt_params.received_pkt.num_of_bytes);
......@@ -486,7 +498,7 @@ diff --git a/examples/ble_central_and_peripheral/ble_connectivity/main.c b/examp
+ .revision_hash = 0,
+ .version_major = 2,
+ .version_minor = 0,
+ .version_patch = 0,
+ .version_patch = 1,
+ .rfu1 = 0xFF,
+ .sd_ble_api_version = 2,
+ .transport_type = 1,
......
......@@ -63,27 +63,36 @@ index 9eaf33a..7b4fe8e 100644
#ifdef __cplusplus
diff --git a/components/serialization/common/transport/ser_phy/ser_phy_hci.c b/components/serialization/common/transport/ser_phy/ser_phy_hci.c
index 516ebf9..861c34d 100644
index 216ed97..147d7d5 100644
--- a/components/serialization/common/transport/ser_phy/ser_phy_hci.c
+++ b/components/serialization/common/transport/ser_phy/ser_phy_hci.c
@@ -67,6 +67,8 @@ NRF_LOG_MODULE_REGISTER();
@@ -39,6 +39,8 @@
(SER_HAL_TRANSPORT_MAX_PKT_SIZE + PKT_HDR_SIZE + PKT_CRC_SIZE))
#define BAUD_TIME_us (1000000uL / SER_PHY_UART_BAUDRATE_VAL)
+#define PKT_TYPE_RESET 5
+
#define TX_EVT_QUEUE_SIZE 16
#define RX_EVT_QUEUE_SIZE 16
#define PKT_TYPE_VENDOR_SPECIFIC 14 /**< Packet type vendor specific. */
@@ -794,6 +796,10 @@ static void hci_slip_event_handler(ser_phy_hci_slip_evt_t * p_event)
NRF_LOG_DEBUG("EVT_PKT_RECEIVED 0x%X/%u", packet_type,
@@ -50,7 +52,7 @@
#define INITIAL_SEQ_NUMBER INITIAL_ACK_NUMBER_EXPECTED /**< Initial acknowledge number transmitted. */
#define INVALID_PKT_TYPE 0xFFFFFFFFu /**< Internal invalid packet type value. */
#define MAX_TRANSMISSION_TIME_ms (MAX_PACKET_SIZE_IN_BITS * BAUD_TIME_us / 1000uL) /**< Max transmission time of a single application packet over UART in units of mseconds. */
-#define RETRANSMISSION_TIMEOUT_IN_ms (10uL * MAX_TRANSMISSION_TIME_ms) /**< Retransmission timeout for application packet in units of mseconds. */
+#define RETRANSMISSION_TIMEOUT_IN_ms (50uL * MAX_TRANSMISSION_TIME_ms) /**< Retransmission timeout for application packet in units of mseconds. */
#ifdef HCI_LINK_CONTROL
#define HCI_PKT_SYNC 0x7E01u /**< Link Control Packet: type SYNC */
@@ -770,6 +772,10 @@ static void hci_slip_event_handler(ser_phy_hci_slip_evt_t * p_event)
NRF_LOG_DEBUG("EVT_PKT_RECEIVED 0x%X/%u\r\n", packet_type,
p_event->evt_params.received_pkt.num_of_bytes);
+ if (packet_type == PKT_TYPE_RESET)
+ {
+ NVIC_SystemReset();
+ }
if (packet_type == PKT_TYPE_ACK )
{
diff --git a/components/serialization/connectivity/ser_conn_error_handling.c b/components/serialization/connectivity/ser_conn_error_handling.c
......@@ -160,7 +169,7 @@ index bcb67e3..516ccd7 100644
+ .revision_hash = 0,
+ .version_major = 2,
+ .version_minor = 0,
+ .version_patch = 0,
+ .version_patch = 1,
+ .rfu1 = 0xFF,
+ .sd_ble_api_version = NRF_SD_BLE_API_VERSION,
+ .transport_type = 1,
......
......@@ -130,27 +130,21 @@ class InitializedExitCriterias : public ExitCriterias
public:
bool syncConfigSent;
bool syncConfigRspReceived;
bool syncConfigReceived;
bool syncConfigRspSent;
InitializedExitCriterias()
: ExitCriterias(),
syncConfigSent(false),
syncConfigRspReceived(false),
syncConfigReceived(false),
syncConfigRspSent(false) {}
syncConfigRspReceived(false) {}
bool isFullfilled() const override
{
return ioResourceError || close || (syncConfigSent && syncConfigRspReceived && syncConfigReceived && syncConfigRspSent);
return ioResourceError || close || (syncConfigSent && syncConfigRspReceived);
}
void reset() override
{
ExitCriterias::reset();
syncConfigSent = false;
syncConfigRspSent = false;
syncConfigReceived = false;
syncConfigRspReceived = false;
};
......
......@@ -69,7 +69,7 @@
// Constants use for state machine states UNINITIALIZED and INITIALIZED
const auto NON_ACTIVE_STATE_TIMEOUT = std::chrono::milliseconds(250); // Duration to wait until resending a packet
const uint8_t PACKET_RETRANSMISSIONS = 4; // Number of times to send reliable packets before giving in
const uint8_t PACKET_RETRANSMISSIONS = 6; // Number of times to send reliable packets before giving in
// Other constants
const auto OPEN_WAIT_TIMEOUT = std::chrono::milliseconds(2000); // Duration to wait for state ACTIVE after open is called
......@@ -316,14 +316,14 @@ void H5Transport::processPacket(std::vector<uint8_t> &packet)
if (isSyncConfigPacket)
{
exit->syncConfigReceived = true;
sendControlPacket(CONTROL_PKT_SYNC_CONFIG_RESPONSE);
exit->syncConfigRspSent = true;
syncWaitCondition.notify_all();
}
if (isSyncPacket) {
if (isSyncPacket)
{
sendControlPacket(CONTROL_PKT_SYNC_RESPONSE);
syncWaitCondition.notify_all();
}
}
else if (currentState == STATE_ACTIVE)
......@@ -335,6 +335,11 @@ void H5Transport::processPacket(std::vector<uint8_t> &packet)
exit->syncReceived = true;
syncWaitCondition.notify_all();
}
if (isSyncConfigPacket)
{
sendControlPacket(CONTROL_PKT_SYNC_CONFIG_RESPONSE);
}
}
}
else if (packet_type == VENDOR_SPECIFIC_PACKET)
......@@ -522,11 +527,12 @@ void H5Transport::setupStateMachine()
uint8_t syncRetransmission = PACKET_RETRANSMISSIONS;
std::unique_lock<std::mutex> syncGuard(syncMutex);
while (!exit->isFullfilled() && syncRetransmission--)
while (!exit->isFullfilled() && syncRetransmission > 0)
{
sendControlPacket(CONTROL_PKT_SYNC);
exit->syncSent = true;
syncWaitCondition.wait_for(syncGuard, NON_ACTIVE_STATE_TIMEOUT);
syncRetransmission--;
}
if (exit->isFullfilled())
......@@ -548,22 +554,16 @@ void H5Transport::setupStateMachine()
std::unique_lock<std::mutex> syncGuard(syncMutex);
// Send a package immediately
sendControlPacket(CONTROL_PKT_SYNC_CONFIG);
exit->syncConfigSent = true;
while (!exit->isFullfilled() && syncRetransmission > 0)
{
auto status = syncWaitCondition.wait_for(syncGuard, NON_ACTIVE_STATE_TIMEOUT);
if (status == std::cv_status::timeout)
{
sendControlPacket(CONTROL_PKT_SYNC_CONFIG);
syncRetransmission--;
}
sendControlPacket(CONTROL_PKT_SYNC_CONFIG);
exit->syncConfigSent = true;
syncWaitCondition.wait_for(syncGuard, NON_ACTIVE_STATE_TIMEOUT);
syncRetransmission--;
}
if (exit->syncConfigSent && exit->syncConfigRspReceived
&& exit->syncConfigReceived && exit->syncConfigRspSent)
if (exit->syncConfigSent && exit->syncConfigRspReceived)
{
return STATE_ACTIVE;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment