Re: get channel number from real time thread function
Xuecheng Xi wrote:
> Dear Developers,
>
> I am writing a real time thread function in which I need to use the
> channel number. Take pid.c as an example, the number of channel =
> num_chan. For each channel, we have exported
>
> calc_pid(void* arg, long period).
>
> by using
>
> hal_export_funct(bu, calc_pid, &(pid_array[num]), 1, 0, comp_id).
>
> My question is in the function of calc_pid(void* arg, long period),
> how can I know for which channel I am doing the calculations. As from
> the arguments (void* arg, long period), there is no information
> regarding the number of channel.
>
pid_array is an array of structures, each with all the data needed for
a PID loop. Each function gets a pointer to one structure with the
data it needs, and is unaware of the other structures. If you are
writing a HAL component, you are the one who defines that structure.
You can have any fields you want in that structure, not just HAL pins
and parameters. (See stepgen for an example of a large struct with lots
of data in it). For your situation, you can add a "channel_num" field
to the structure, and initialize it before you call export_funct during
startup.
Regards,
(Continue reading)