Page 1 of 1
Virtual timer initialization
Posted: Thu Nov 07, 2013 4:24 pm
by Anubirux
Hello,
I've seen that for "Virtual Timer" there is no initializer. When I allocate memory for vt from heap I can have random values inside (and I have it). That is making mess when I use reset or set function on this object. Of course I can manually set "vt_func" parameter to NULL and everything is ok, but I was a little surprise about that behavior. I didn't see any information about need of initialization of "Virtual Timers" and I guess it should be.
Re: Virtual timer initialization
Posted: Thu Nov 07, 2013 5:38 pm
by Giovanni
Hi,
The vtp parameter of the function chVTSetI() documented as "out" so it is only written and there is no need of an initializer unless you need to to check if the timer is armed and it is an automatic variable.
In ChibiOS 3.0 a specific initializer has been added in order to give timers the same look and feel of other objects.
Giovanni
Re: Virtual timer initialization
Posted: Tue Dec 10, 2013 8:05 pm
by genosensor
That's exactly what I need. In some cases timers are allocated on the call stack or even on the heap.
How does this explicit initializer in ChBiOS 3.x work?
Can it be backported to 2.6x?
For now, I just added a chVTInit() macro to explicitly assign NULL to a newly allocated Vtimer's function pointer.
In os/kernel/include/chvt.h:
Code: Select all
/**
* @brief First time initialization of a Virtual Timer.
* @note Necessary if RAM in which timer is allocated is not cleared to zero
*
* @param[in] vtp the @p VirtualTimer structure pointer
*
* @api
*/
#define chVTInit(vtp) {(vtp)->vt_func = NULL;}
Re: Virtual timer initialization
Posted: Wed Dec 11, 2013 9:45 am
by Giovanni
Hi,
In 2.6 you don't need an initializer because chVTSetI() writes the object. In 3.0 it is different, chVTSetI() checks the object first so an initializer is required.
The only case in 2.6 where a timer should be initialized is if you check if it is armed before calling chVTSetI() (which is the default behavior in 3.0).
Giovanni