Skip to content

Commit

Permalink
Merge pull request #2745 from particle-iot/comms_loop_idle_callback/s…
Browse files Browse the repository at this point in the history
…c-125370

Process system tasks while cloud handshake is in progress
  • Loading branch information
sergeuz authored Feb 28, 2024
2 parents 4436513 + 92cfd29 commit 0920466
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions system/inc/system_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ extern volatile uint8_t SPARK_WLAN_CONNECT_RESTORE;
extern volatile uint8_t SPARK_WLAN_STARTED;
extern volatile uint8_t SPARK_CLOUD_SOCKETED;
extern volatile uint8_t SPARK_CLOUD_CONNECTED;
extern volatile uint8_t SPARK_CLOUD_PROTOCOL_HANDSHAKE_IN_PROGRESS;
extern volatile uint8_t SPARK_CLOUD_HANDSHAKE_PENDING;
extern volatile uint8_t SPARK_CLOUD_HANDSHAKE_NOTIFY_DONE;
extern volatile uint8_t SPARK_FLASH_UPDATE;
Expand Down
8 changes: 7 additions & 1 deletion system/src/system_cloud_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "system_cloud_connection.h"
#include "system_cloud_internal.h"
#include "system_cloud.h"
#include "system_threading.h"
#include "core_hal.h"
#include "service_debug.h"
#include "system_task.h"
Expand Down Expand Up @@ -51,6 +52,7 @@ static volatile int s_ipv4_cloud_keepalive = HAL_PLATFORM_DEFAULT_CLOUD_KEEPALIV
static volatile int s_ipv6_cloud_keepalive = HAL_PLATFORM_DEFAULT_CLOUD_KEEPALIVE_INTERVAL;
#endif

using namespace particle;
using namespace particle::system::cloud;

#if HAL_PLATFORM_CLOUD_UDP
Expand Down Expand Up @@ -250,7 +252,11 @@ int Spark_Receive_UDP(unsigned char *buf, uint32_t buflen, void* reserved)
return -1;
}

return system_cloud_recv(buf, buflen, 0);
int r = system_cloud_recv(buf, buflen, 0);
if (r == 0 && SPARK_CLOUD_PROTOCOL_HANDSHAKE_IN_PROGRESS) {
SystemISRTaskQueue.process();
}
return r;
}

#endif /* HAL_PLATFORM_CLOUD_UDP */
Expand Down
3 changes: 3 additions & 0 deletions system/src/system_cloud_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,10 @@ int Spark_Handshake(bool presence_announce)
cloud_socket_aborted = false; // Clear cancellation flag for socket operations
LOG(INFO,"Starting handshake: presense_announce=%d", presence_announce);
bool session_resumed = false;
// TODO: Perform the DTLS handshake and receive a response for the Hello message asynchronously
SPARK_CLOUD_PROTOCOL_HANDSHAKE_IN_PROGRESS = 1;
int err = spark_protocol_handshake(sp);
SPARK_CLOUD_PROTOCOL_HANDSHAKE_IN_PROGRESS = 0;

#if HAL_PLATFORM_MUXER_MAY_NEED_DELAY_IN_TX
// XXX: Adding a delay only for platforms Boron and BSoM, because older cell versions of
Expand Down
1 change: 1 addition & 0 deletions system/src/system_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ ymodem_serial_flash_update_handler Ymodem_Serial_Flash_Update_Handler = NULL;
// TODO: Use a single state variable instead of SPARK_CLOUD_XXX flags
volatile uint8_t SPARK_CLOUD_SOCKETED;
volatile uint8_t SPARK_CLOUD_CONNECTED;
volatile uint8_t SPARK_CLOUD_PROTOCOL_HANDSHAKE_IN_PROGRESS = 0;
volatile uint8_t SPARK_CLOUD_HANDSHAKE_PENDING = 0;
volatile uint8_t SPARK_CLOUD_HANDSHAKE_NOTIFY_DONE = 0;
volatile uint8_t SPARK_FLASH_UPDATE;
Expand Down

0 comments on commit 0920466

Please sign in to comment.