Page 1 of 1
chThdCreate() syntax
Posted: Sun Sep 01, 2019 6:01 pm
by Alucard
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
Re: chThdCreate() syntax
Posted: Sun Sep 01, 2019 6:04 pm
by Giovanni
You need chThdCreateSuspended(), it takes parameters in a structure of type thread_descriptor_t:
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
Posted: Sun Sep 01, 2019 8:51 pm
by Alucard
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 ?
Re: chThdCreate() syntax
Posted: Sun Sep 01, 2019 9:09 pm
by Giovanni
THD_WORKING_AREA_BASE(your_workingarea)
THD_WORKING_AREA_END(your_workingarea)
Giovanni