I am writing some customizations in simple-c code. I am trying to write a code block which would reset the node periodically if the node is a tag. I have created a new thread in dwm_user_start as:
rvrst = dwm_thread_create(THREAD_APP_PRIO, app_restart, (void*)NULL,"apprst", THREAD_APP_STACK_SIZERST, &hndlrst);
APP_ERR_CHECK(rvrst);
dwm_thread_resume(hndlrst);
The function app_restart which is being called from this thread is as follows:
Steps:
-Use a reset counter
-
Run a while loop with thread delay of few seconds
-
Once a time span of 1 min has surpassed, suspend the main thread which is capturing all the events (position, iot receive, iot sent etc)
-
Wake up dwm using dwm_wake_up
-
Pass command dwm_reset() if 1 min has surpassed and the node is a tag
void app_restart(uint32_t data){ int rst_cnt = 0; int cnt_cut = 10; int cnt_dly = 6; //every (cnt_cut*cnt_dly) secs reset dwm_cfg_t cfg; APP_ERR_CHECK(dwm_cfg_get(&cfg)); while(1){ rst_cnt++; printf("rst cnt %i\n",rst_cnt); if(rst_cnt>=cnt_cut && cfg.mode==0){ APP_ERR_CHECK(dwm_thread_suspend(hndl)); dwm_thread_delay(500); printf("thread suspended \n"); dwm_wake_up(); dwm_thread_delay(500); printf("dwm wakeup \n"); printf("resetting \n"); dwm_reset(); } if(rst_cnt>=cnt_cut){ rst_cnt = 0; } dwm_thread_delay(cnt_dly*100); //100 = 1 sec; } }
The code is working as expected if the tag is in responsive mode or the dwm shell is active + responsive mode disabled (printing statements using serial comm). But when I disable responsive mode and disconnect the serial comm/dwm shell, the node doesn’t reset.
Please advice.