Skip to content

Commit

Permalink
suit: start worker thread on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Sep 4, 2022
1 parent fbf4f5d commit 10f2fef
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 31 deletions.
2 changes: 0 additions & 2 deletions examples/suit_update/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ int main(void)
#endif
/* initialize suit storage */
suit_storage_init_all();
/* start suit updater thread */
suit_worker_run();

/* start nanocoap server thread */
thread_create(_nanocoap_server_stack, sizeof(_nanocoap_server_stack),
Expand Down
4 changes: 1 addition & 3 deletions sys/include/suit/transport/coap.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ extern "C" {
/**
* @brief Start SUIT CoAP thread
*
* @deprecated This is an alias for @ref suit_worker_run and will be removed
* after after the 2023.01 release.
* @deprecated This will be removed after after the 2023.01 release.
*/
static inline void suit_coap_run(void)
{
suit_worker_run();
}

/**
Expand Down
5 changes: 0 additions & 5 deletions sys/include/suit/transport/worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
extern "C" {
#endif

/**
* @brief Start SUIT worker thread
*/
void suit_worker_run(void);

/**
* @brief Trigger a SUIT udate via a worker thread
*
Expand Down
38 changes: 17 additions & 21 deletions sys/suit/transport/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static char _stack[SUIT_WORKER_STACKSIZE];
static char _url[CONFIG_SOCK_URLPATH_MAXLEN];
static uint8_t _manifest_buf[SUIT_MANIFEST_BUFSIZE];

static mutex_t _worker_lock = MUTEX_INIT_LOCKED;
static mutex_t _worker_lock;

int suit_handle_url(const char *url)
{
Expand Down Expand Up @@ -140,33 +140,29 @@ static void *_suit_worker_thread(void *arg)

LOG_INFO("suit_worker: started.\n");

while (true) {
mutex_lock(&_worker_lock);

if (suit_handle_url(_url) == 0) {
LOG_INFO("suit_worker: update successful\n");
if (IS_USED(MODULE_SUIT_STORAGE_FLASHWRITE)) {
LOG_INFO("suit_worker: rebooting...\n");
pm_reboot();
}
}
else {
LOG_INFO("suit_worker: update failed, hdr invalid\n ");
if (suit_handle_url(_url) == 0) {
LOG_INFO("suit_worker: update successful\n");
if (IS_USED(MODULE_SUIT_STORAGE_FLASHWRITE)) {
LOG_INFO("suit_worker: rebooting...\n");
pm_reboot();
}
}
return NULL;
}
else {
LOG_INFO("suit_worker: update failed, hdr invalid\n ");
}

void suit_worker_run(void)
{
thread_create(_stack, SUIT_WORKER_STACKSIZE, SUIT_COAP_WORKER_PRIO,
THREAD_CREATE_STACKTEST,
_suit_worker_thread, NULL, "suit worker");
mutex_unlock(&_worker_lock);
return NULL;
}

void suit_worker_trigger(const char *url, size_t len)
{
mutex_lock(&_worker_lock);

memcpy(_url, url, len);
_url[len] = '\0';
mutex_unlock(&_worker_lock);

thread_create(_stack, SUIT_WORKER_STACKSIZE, SUIT_COAP_WORKER_PRIO,
THREAD_CREATE_STACKTEST,
_suit_worker_thread, NULL, "suit worker");
}

0 comments on commit 10f2fef

Please sign in to comment.