chThdCreate() syntax
Moderators: RoccoMarco, lbednarz, tfAteba
chThdCreate() syntax
hi everyone, i am trying to initialize a thread in the main function without starting it. Itried to switch from chThdCreateStatic() to chThdCreate() but i don't understand the correct syntax required, the official documentation says i need to use a thread descriptor but without an example i am having trouble in figuring out how should i use the command. thank you
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: chThdCreate() syntax
You need chThdCreateSuspended(), it takes parameters in a structure of type thread_descriptor_t:
For working area pointers you can use the following helpers:
The thread is then started using chThdStart().
Giovanni
Code: Select all
/**
* @brief Type of a thread descriptor.
*/
typedef struct {
/**
* @brief Thread name.
*/
const char *name;
/**
* @brief Pointer to the working area base.
*/
stkalign_t *wbase;
/**
* @brief End of the working area.
*/
stkalign_t *wend;
/**
* @brief Thread priority.
*/
tprio_t prio;
/**
* @brief Thread function pointer.
*/
tfunc_t funcp;
/**
* @brief Thread argument.
*/
void *arg;
} thread_descriptor_t;
For working area pointers you can use the following helpers:
Code: Select all
/**
* @brief Base of a working area casted to the correct type.
*
* @param[in] s name of the working area
*/
#define THD_WORKING_AREA_BASE(s) ((stkalign_t *)(s))
/**
* @brief End of a working area casted to the correct type.
*
* @param[in] s name of the working area
*/
#define THD_WORKING_AREA_END(s) (THD_WORKING_AREA_BASE(s) + \
(sizeof (s) / sizeof (stkalign_t)))
The thread is then started using chThdStart().
Giovanni
Re: chThdCreate() syntax
thank you for your answer but i am afraid i still don't get what the wbase and wend fields require. let's suppose that i want to create a thread for the integrated led with a working area of 128byte, what should i put in *wbase and *wend ?
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: chThdCreate() syntax
THD_WORKING_AREA_BASE(your_workingarea)
THD_WORKING_AREA_END(your_workingarea)
Giovanni
THD_WORKING_AREA_END(your_workingarea)
Giovanni