Hi,
I'm having a problem using the _timer_start_oneshot_at_ticks function. For my application I need to set a timer to count a certain amount of time and call a function only once. For this I'm calling _timer_start_oneshot_at_ticks and everything seems to work ok at the beginning.
The problem is that I need to repeat this operation for an unlimited number of times but it seems that every time I call _timer_start_oneshot_at_ticks, the return value of the function increases like if a new timer is created every time the function is called, and after a certain amount of time the _timer_start_oneshot_at_ticks starts returning TIMER_NULL_ID.
Any idea of how to turnaround this problem?
Thanks!
Solved! Go to Solution.
Hello,
I think the timer is not canceled within the callback because it's not in the context of task that created it.
So I suggest to cancel the timer before you're going to use it again in your task.
Regards,
PetrM
timer_cancel ?
Hi,
I have investigated more deeply the _timer_cancel function and I have the following problem : I step into the function (id is 1 as I was expecting.. - see attached screenshot 1) , then the timer_component_ptr is created and I am not sure that the "SIZE" from ELAPSED_TIMER_ENTRIES should be "0" (see screenshot2). In the end the function is returning MQX_INVALID_PARAMETER (see screenshot 3). I tried to find a solution debugging this issue, but no success, even that I passed the correct parameter to the function.
Anyone of you can help, please ?
Thanks
Is this enabled in your BSP?
#define MQX_USE_TIMER 1
Your handle should be a memory location not 1.
Yes, MQX_USE_TIMER is set to 1 in BSP...
Hi Paleantrop,
Have you created the timer module before calling the timer function?
error = _timer_create_component(TIMER_DEFAULT_TASK_PRIORITY,
TIMER_DEFAULT_STACK_SIZE);
Can you create reduced code snippet and post?
Regards,
David
if (_timer_create_component(TIMER_DEFAULT_TASK_PRIORITY, TIMER_DEFAULT_STACK_SIZE)!= MQX_OK) { _mqx_exit(1); } while(TRUE) { req = _mem_alloc((_mem_size)sizeof(uchar)); nBytes =3; req = data; uart2_timer = (80000 * nBytes / 1152) / 250; uart2_timer += 2; uart2_timer = uart2_timer * 250; _time_init_ticks(&ticks, 0); _time_init_ticks(&dticks, 0); SetEnable(); for(i=0;i<nBytes;i++) write(uart2_ptr,(char_ptr)req + i,1); _time_get_elapsed_ticks(&ticks); _time_add_usec_to_ticks(&ticks,uart2_timer); _time_add_usec_to_ticks(&dticks,uart2_timer); com_timer = _timer_start_oneshot_at_ticks(check_uart_timer, 0, TIMER_ELAPSED_TIME_MODE, &dticks); _time_delay(50);
Hi,
Thanks for your answer.
As you can see I have initialized the _timer_component and the _timer_cancel function is called inside check_uart_timer.
Do you have any other idea?
Hello,
I think the timer is not canceled within the callback because it's not in the context of task that created it.
So I suggest to cancel the timer before you're going to use it again in your task.
Regards,
PetrM
Hi,
Thanks for reply. I've tried with _timer_cancel but no succes. Any other idea?