Clashes of wiced_rtos_xxx_timer and wiced_rtos_delay_xxxseconds?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi guys,

Extremely new to programming for embedded devices here, and I was hoping if someone could help! I currently have a single-threaded program in a while() loop that has a 8-second delay after every run (set by wiced_rtos_delay_milliseconds(8000);), and I'm trying to implement a timer function that would take up time within that delay. In other words, I would start a timer of 4 seconds, set an 8 second delay, then stop that timer afterwards.

The problem is that while the timer runs fine (ie. everything in the timer handler function, quoted below), the main program doesn't loop anymore.

The main thread (called by application_start) has the following code:

void scan_thread_main(uint32_t arg) {

     while (scan_handle->quit != WICED_TRUE) {

          do_much_stuff();

          will_quote_if_relevant();

          relevant_function(); <-- This is where the timer is initialized, started, stopped, and deinitialized.

          wiced_result_t result = wiced_rtos_delay_milliseconds(8000);

     }

     WICED_END_OF_CURRENT_THREAD();

}

I've made sure that after the run, result is 0 (WICED_TRUE), and I've also explicitly set scan_handle->quit to WICED_FALSE.

The components involving the timer (defined in the .h file as static wiced_timer_t myfunction_timer), placed in another file, are as follows:

wiced_result_t myfunction_network_up() {

     wiced_result_t result = WICED_SUCCESS;

     wiced_network_up(...);

     wiced_rtos_init_timer(&myfunction_timer, 4000, myfunction_network_down_timer_function, NULL);

     wiced_rtos_start_timer(&myfunction_timer);

     WPRINT_APP_INFO(("My network put up."));

     return result;

}

static void myfunction_network_down_timer_function(void* arg) {

     myfunction_network_down();

     wiced_rtos_stop_timer(&myfunction_timer);

     wiced_rtos_deinit_timer(&myfunction_timer);

}

wiced_result_t myfunction_network_down() {

     wiced_result_t result = WICED_SUCCESS;

     result = wiced_network_down(WICED_AP_INTERFACE);

     return result;

}

If anyone has any hints on how to solve this, please let me know! Your help is greatly appreciated

0 Likes
5 Replies
SeyhanA_31
Employee
Employee
250 replies posted 100 replies posted 50 replies posted

Hi,

Did you check out the wiced_rtos_register_timed_event(...) and wiced_rtos_deregister_timed_event(...).

/** Requests a function be called at a regular interval

*

* This function registers a function that will be called at a regular

* interval. Since this is based on the RTOS time-slice scheduling, the

* accuracy is not high, and is affected by processor load.

*

* @param event_object  : pointer to a event handle which will be initialised

* @param worker_thread : pointer to the worker thread in whose context the

*                        callback function runs on

* @param function      : the callback function that is to be called regularly

* @param time_ms      : the time period between function calls in milliseconds

* @param arg          : an argument that will be supplied to the function when

*                        it is called

*

* @return    WICED_SUCCESS : on success.

* @return    WICED_ERROR  : if an error occurred

*/

wiced_result_t wiced_rtos_register_timed_event( wiced_timed_event_t* event_object, wiced_worker_thread_t* worker_thread, event_handler_t function, uint32_t time_ms, void* arg );

/** Removes a request for a regular function execution

*

* This function de-registers a function that has previously been set-up

* with @ref wiced_rtos_register_timed_event.

*

* @param event_object : the event handle used with @ref wiced_rtos_register_timed_event

*

* @return    WICED_SUCCESS : on success.

* @return    WICED_ERROR  : if an error occurred

*/

wiced_result_t wiced_rtos_deregister_timed_event( wiced_timed_event_t* event_object );

Seyhan

Hi,

Perhaps this may help you, Simple Usage Of Timers

Seyhan

0 Likes

Hi seyhan​,

The timer callback is running in which context?

Is there any limitation in the context running the timer callback?

0 Likes

Hi,

Timer callbacks are done context of "System Timer Thread".

If there are multiple timers set, next timer callback will be initiated after the previous timer callback returns. Therefore the timer callbacks should not block. They should signal any action to be taken to the worker thread and return.

Seyhan

Anonymous
Not applicable

Hey seyhan,

I've temporarily skirted the problem by using delays (as we're on a bit of a tight schedule), but I'll let you know again if I get to test out the timer functions again. Thanks so much for your suggestions!

0 Likes