Hal driver in C - setting parameters

More
09 Jun 2022 20:16 #244816 by mwidlok
Hello,
I'm new here so please forgive if I mess something up. I'm working on a hal driver for steppers in C (for my own board - project made for fun and to learn), that will have very similar interface to "stepgen". Each stepper needs only 3 signals that change in real time (joint.X.motor-pos-cmd, joint.X.motor-pos-fb and joint.X.amp-enable-out) and quite a lot of other parameters that should be set at startup only (pos-scale, dir-pin, dir-hold, etc.).
It is clear for me how to use the real-time signals - just connect them with "net" hal command:
"net joint.0.motor-pos-cmd => driver.stepper.0.pos-cmd",
but I'm not sure what to do with parameters. It would be nice to set them with:
"setp driver.stepper.0.pos-scale 1234",
but this means that real time thread will need to make some calculations over and over again with the same data, that is rather inefficient.

Is it possible to export C function to HAL that will be called when parameter is changed/set? Or is there any "good" method to handle "constantly changing" signals and "set only once at startup" parameters from a driver written in C?
Thanks in advance,
Michael Widlok

Please Log in or Create an account to join the conversation.

More
09 Jun 2022 21:44 - 09 Jun 2022 21:44 #244822 by PCW
Typically parameters are only set at startup and the HAL driver
that handles that parameter checks for changes in the
parameter value (and does nothing unless a change is detected)

Pins rather than parameters are used for dynamic values
Last edit: 09 Jun 2022 21:44 by PCW.

Please Log in or Create an account to join the conversation.

More
10 Jun 2022 06:43 #244848 by mwidlok
Thanks for reply. So I assume that I should check every parameter for a change in real time thread every time it is called - is that right?

If yes then I'm a bit surprised that there is no possibility to have a hal function that is called whenever configuration parameter changes/is set. It would reduce workload on real time threads a bit.

Please Log in or Create an account to join the conversation.

More
12 Jun 2022 23:41 #245031 by andypugh

If yes then I'm a bit surprised that there is no possibility to have a hal function that is called whenever configuration parameter changes/is set. It would reduce workload on real time threads a bit.

The realtime code of each function runs every thread cycle. What you are talking about would generally be handled by an interrupt. But basically the realtime threads _are_ an interrupt. 

There is very little overhead in a HAL component asking "Does this variable of mine still hold the same value as last time". Basically a parameter is a variable that publishes its memory address so that other code can change it. 

Have you found the "other" stepgen? The one that controls the Mesa cards might be useful to look at:
github.com/LinuxCNC/linuxcnc/blob/master...a-hostmot2/stepgen.c
 

Please Log in or Create an account to join the conversation.

Time to create page: 0.107 seconds
Powered by Kunena Forum