Kicad-to-HAL: Threads

The Kicad THREAD symbol (center bottom) creates the HAL addf commands connecting HAL component functions to the realtime threads:

Kicad-to-HAL Demo Schematic
Kicad-to-HAL Demo Schematic

Change the Kicad reference to match the HAL thread name. AFAICT, you can use either servo-thread or base-thread, as defined by the LoadRT configuration (center top).

Opinion: contemporary x86-64 PC architecture pretty much prevents running a base-thread at the pace required for step generation through a parallel port. In point of fact, I wrote Kicad-to-HAL specifically to configure a PC around a Mesa Electronics 5i25 FPGA controller for my Sherline CNC mill, as the real-time latency had regular glitches far exceeding the nominal 50 µs period. I suspect few new CNC installations will need a fast base thread.

The THREAD symbol has seven “Power output” pins drawn in the Clock graphic style:

Kicad symbol - THREAD
Kicad symbol – THREAD

Kicad-to-HAL finds the other components attached to each pin and generates addf commands:

# Function hookups

# Position: 1

addf		servo-thread
# Position: _

addf and2.0		servo-thread
addf constant.0		servo-thread
addf constant.1		servo-thread
addf not.0		servo-thread
addf timedelay.0		servo-thread
addf toggle.0		servo-thread
# Position: -1

addf hm2_5i25.0.write		servo-thread

FiXME: Contrary to the comment in the symbol, addf commands for each pin come out sorted by reference.

The Mesa hostmot2 HAL component (middle right in the first screenshot) generates several function names that don’t require connections, but Kicad-to-HAL produces a warning for single-pin (i.e. unconnected) nets with non-default names. Prefix the pin name with an asterisk (*read-gpio) to suppress the error message.

The motion HAL component (lower right below) has functions that do not follow the normal naming convention:

Servo Thread Hookup schematic
Servo Thread Hookup schematic

Prefix the Kicad pin name with a slash (/motion-controller) to tell Kicad-to-HAL to use the name without the standard motion. prefix:

# Position: 2

addf motion-command-handler		servo-thread
addf motion-controller		servo-thread

Perhaps they were supposed to be motion.command-handler and motion.controller, but it’s too late to change? If so, I know that feeling.

Other quirks surely lurk within other HAL components, but, on the whole, this seems to work pretty well.