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.
Virtual timer initialization
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Virtual timer initialization
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
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
-
genosensor
- Posts: 65
- Joined: Thu Oct 03, 2013 1:06 am
- Has thanked: 1 time
- Been thanked: 1 time
Re: Virtual timer initialization
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:
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;}
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Virtual timer initialization
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
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