chThdCreate() syntax

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
Alucard
Posts: 4
Joined: Thu Aug 08, 2019 11:29 am
Has thanked: 1 time

chThdCreate() syntax

Post 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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chThdCreate() syntax

Post 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
Alucard
Posts: 4
Joined: Thu Aug 08, 2019 11:29 am
Has thanked: 1 time

Re: chThdCreate() syntax

Post 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 ?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chThdCreate() syntax

Post by Giovanni »

THD_WORKING_AREA_BASE(your_workingarea)
THD_WORKING_AREA_END(your_workingarea)

Giovanni
Post Reply