Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions docs/src/hal/basic-hal.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,27 @@ $ halrun
halcmd: loadrt or2
halcmd: show function
Exported Functions:
Owner CodeAddr Arg FP Users Name
00004 f8bc5000 f8f950c8 NO 0 or2.0
Owner CodeAddr Arg Users Name
00004 f8bc5000 f8f950c8 0 or2.0
----

You have to add a function from a HAL real time component to a thread to get the function to update at the rate of the thread.
Usually there are two threads as shown in this example.
Some components use floating point math and must be added to a thread that supports floating point math.
The `FP` indicates if floating point math is supported in that thread.

----
$ halrun
halcmd: loadrt motmod base_period_nsec=55555 servo_period_nsec=1000000 num_joints=3
halcmd: show thread
Realtime Threads:
Period FP Name ( Time, Max-Time )
995976 YES servo-thread ( 0, 0 )
55332 NO base-thread ( 0, 0 )
Period Name ( Time, Max-Time )
995976 servo-thread ( 0, 0 )
55332 base-thread ( 0, 0 )
----

- base-thread (the high-speed thread):
This thread handles items that need a fast response, like making step pulses, and reading and writing the parallel port.
Does not support floating point math.
- servo-thread (the slow-speed thread):
This thread handles items that can tolerate a slower response, like the motion controller, ClassicLadder, and the motion command handler and supports floating point math.
This thread handles items that can tolerate a slower response, like the motion controller, ClassicLadder, and the motion command handler.

.addf Syntax and Example
[source,{hal}]
Expand All @@ -94,9 +91,6 @@ addf <function> <thread>
addf mux4.0 servo-thread
----

[NOTE]
If the component requires a floating point thread that is usually the slower servo-thread.

[[sub:hal-loadusr]]
=== loadusr

Expand Down
8 changes: 4 additions & 4 deletions docs/src/hal/rtcomps.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ image::images/stepgen-type11-14.png["Step Types: Five-Phase",align="center"]
The component exports three functions.
Each function acts on all of the step pulse generators - running different generators in different threads is not supported.

* (funct) `stepgen.make-pulses` - High speed function to generate and count pulses (no floating point).
* (funct) `stepgen.make-pulses` - High speed function to generate and count pulses.
* (funct) `stepgen.update-freq` - Low speed function does position to velocity conversion, scaling and limiting.
* (funct) `stepgen.capture-position` - Low speed function for feedback, updates latches and scales position.

Expand Down Expand Up @@ -258,7 +258,7 @@ Each PWM generator will also have some of these pins, depending on the output ty

The component exports two functions. Each function acts on all of the PWM generators - running different generators in different threads is not supported.

* (funct) `pwmgen.make-pulses` - High speed function to generate PWM waveforms (no floating point).
* (funct) `pwmgen.make-pulses` - High speed function to generate PWM waveforms.
The high speed function `pwmgen.make-pulses` should be run in the base (fastest) thread, from 10 to 50&#8239;µs depending on the capabilities of the computer.
That thread's period determines the maximum PWM carrier frequency, as well as the resolution of the PWM or PDM signals.
If the base thread is 50,000&#8239;ns then every 50&#8239;µs the module decides if it is time to change the state of the output.
Expand Down Expand Up @@ -361,7 +361,7 @@ halcmd: unloadrt encoder
The component exports two functions.
Each function acts on all of the encoder counters - running different counters in different threads is not supported.

* (funct) `encoder.update-counters` - High speed function to count pulses (no floating point).
* (funct) `encoder.update-counters` - High speed function to count pulses.
* (funct) `encoder.capture-position` - Low speed function to update latches and scale position.

[[sec:pid]]
Expand Down Expand Up @@ -515,7 +515,7 @@ Most encoder counters will count four times during one complete cycle.

The component exports two functions. Each function affects all simulated encoders.

* (funct) `sim-encoder.make-pulses` - High speed function to generate quadrature pulses (no floating point).
* (funct) `sim-encoder.make-pulses` - High speed function to generate quadrature pulses.
* (funct) `sim-encoder.update-speed` - Low speed function to read `.speed`, do scaling, and set up `.make-pulses`.

[[sec:debounce]]
Expand Down
3 changes: 1 addition & 2 deletions docs/src/hal/tools.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ or
2. If no pinname is specified, default is: `motion-command-handler.time`.
3. This app may be opened for 5 pins.
4. Pintypes float, s32, u32, bit are supported.
5. The pin must be associated with a thread supporting floating point.
For a base thread, this may require using `loadrt motmod ... base_thread_fp=1` .
5. The pin must be associated with a realtime thread.

.hal-histogram Window
image::images/hal-histogram.png["hal-histogram Window"]
Expand Down
17 changes: 7 additions & 10 deletions docs/src/hal/tutorial.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ Owner CodeAddr Arg FP Users Name
----

The siggen component exported a single function.
It requires floating point.
It is not currently linked to any threads, so 'users' is
zero footnote:[CodeAddr and Arg fields were used during development and
should probably disappear.].
Expand Down Expand Up @@ -241,7 +240,7 @@ Realtime Threads:

It did. The period is not exactly 1,000,000 ns because of hardware
limitations, but we have a thread that runs at approximately the
correct rate, and which can handle floating point functions.
correct rate.
The next step is to connect the function to the thread:

.Add Function
Expand Down Expand Up @@ -557,13 +556,12 @@ component.
halrun
halcmd: loadrt stepgen step_type=0,0 ctrl_type=v,v
halcmd: loadrt siggen
halcmd: loadrt threads name1=fast fp1=0 period1=50000 name2=slow period2=1000000
halcmd: loadrt threads name1=fast period1=50000 name2=slow period2=1000000
----

The first command loads two step generators, both configured to generate stepping type 0.
The second command loads our old friend siggen, and the third one creates two threads,
a fast one with a period of 50 microseconds (µs) and a slow one with a period of 1 millisecond (ms).
The fast thread doesn't support floating point functions.

As before, we can use `halcmd show` to take a look at the HAL.
This time we have a lot more pins and parameters than before:
Expand Down Expand Up @@ -731,7 +729,6 @@ is time to take a step, and if so sets the outputs accordingly.
For smooth step pulses, it should run as frequently as possible.
Because it needs to run so fast, 'make_pulses'
is highly optimized and performs only a few calculations.
Unlike the others, it does not need floating point math.

The last function, `stepgen.update-freq`, is responsible for doing
scaling and some other calculations that need to be performed
Expand All @@ -752,15 +749,15 @@ Let's see what threads we have available.
halcmd: show thread

Realtime Threads:
Period FP Name ( Time, Max-Time )
996980 YES slow ( 0, 0 )
49849 NO fast ( 0, 0 )
Period Name ( Time, Max-Time )
996980 slow ( 0, 0 )
49849 fast ( 0, 0 )
----

The two threads were created when we loaded `threads`.
The first one, 'slow', runs every millisecond, and is capable of running floating point functions.
The first one, 'slow', runs every millisecond.
We will use it for `siggen.0.update` and `stepgen.update_freq`.
The second thread is 'fast', which runs every 50 microseconds (µs), and does not support floating point.
The second thread is 'fast', which runs every 50 microseconds (µs).
We will use it for `stepgen.make_pulses`.
To connect the functions to the proper thread, we use the `addf` command.
We specify the function first, followed by the thread.
Expand Down
4 changes: 1 addition & 3 deletions docs/src/man/man3/hal_create_thread.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ hal_create_thread - Create a HAL thread

== SYNTAX

int hal_create_thread(const char* _name_, unsigned long _period_, int _uses_fp_)
int hal_create_thread(const char* _name_, unsigned long _period_)

int hal_thread_delete(const char* _name_)

Expand All @@ -16,8 +16,6 @@ name::
The name of the thread.
period::
The interval, in nanoseconds, between iterations of the thread.
uses_fp::
Must be nonzero if a function which uses floating-point will be attached to this thread.

== DESCRIPTION

Expand Down
5 changes: 1 addition & 4 deletions docs/src/man/man3/hal_export_funct.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ hal_export_funct, hal_export_functf - create a realtime function callable from a

typedef void(*hal_funct_t)(void* _arg_, long _period_)

int hal_export_funct(const char* _name_, hal_funct_t _funct_, void* _arg_, int _uses_fp_, int _reentrant_, int _comp_id_)
int hal_export_funct(const char* _name_, hal_funct_t _funct_, void* _arg_, int _reentrant_, int _comp_id_)

== ARGUMENTS

Expand All @@ -20,9 +20,6 @@ funct::
The pointer to the function.
arg::
The argument to be passed as the first parameter of _funct_.
uses_fp::
Nonzero if the function uses floating-point operations, including
assignment of floating point values with "=".
reentrant::
If reentrant is non-zero, the function may be preempted and called again before the first call completes.
Otherwise, it may only be added to one thread.
Expand Down
4 changes: 1 addition & 3 deletions docs/src/man/man3/rtapi_task_new.3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ rtapi_task_new, rtapi_task_delete - create a realtime task
[source,c]
----
int rtapi_task_new(void (*_taskcode_)(void*), void *_arg_, int _prio_,
unsigned long _stacksize_, int _uses_fp_);
unsigned long _stacksize_);
int rtapi_task_delete(int _task_id_);
----

Expand All @@ -23,8 +23,6 @@ arg::
An argument to be passed to the _taskcode_ function when the task is started
prio::
A task priority value returned by *rtapi_prio_xxxx*
uses_fp::
A flag that tells the OS whether the task uses floating point or not.
task_id::
A task ID returned by a previous call to *rtapi_task_new*

Expand Down
7 changes: 1 addition & 6 deletions docs/src/man/man9/motion.9.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ motion, axis - accepts NML motion commands, interacts with HAL in realtime

== SYNOPSIS

**loadrt motmod** [**base_period_nsec=**_period_] [**base_thread_fp=**_0 or 1_] [**servo_period_nsec=**_period_] [**traj_period_nsec=**_period_] [**num_joints=**_[1-16]_] [**num_dio=**_[1-64]_ | **names_dout=**_name_[,...] **names_din=**_name_[,...]] [**num_aio=**_[1-64]_ | **names_aout=**_name_[,...] __names_ain=_*_name_[,...]] [**num_misc_error=**_[0-64]_] [**num_spindles=**_[1-8]_] [**unlock_joints_mask=**_jointmask_] [**num_extrajoints=**_[0-16]_]
**loadrt motmod** [**base_period_nsec=**_period_] [**servo_period_nsec=**_period_] [**traj_period_nsec=**_period_] [**num_joints=**_[1-16]_] [**num_dio=**_[1-64]_ | **names_dout=**_name_[,...] **names_din=**_name_[,...]] [**num_aio=**_[1-64]_ | **names_aout=**_name_[,...] __names_ain=_*_name_[,...]] [**num_misc_error=**_[0-64]_] [**num_spindles=**_[1-8]_] [**unlock_joints_mask=**_jointmask_] [**num_extrajoints=**_[0-16]_]

The limits for the following items are compile-time settings:

Expand Down Expand Up @@ -60,11 +60,6 @@ the motion-controller function.

== DESCRIPTION

By default, the base thread does not support floating point. Software
stepping, software encoder counting, and software pwm do not use floating point.
*base_thread_fp* can be used to enable floating point in
the base thread (for example for brushless DC motor control).

These pins and parameters are created by the realtime *motmod* module.
This module provides a HAL interface for LinuxCNC's motion planner.
Basically *motmod* takes in a list of waypoints and generates a nice
Expand Down
13 changes: 5 additions & 8 deletions src/emc/motion/motion.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ static int key = DEFAULT_SHMEM_KEY; /* the shared memory key, default value */
RTAPI_MP_INT(key, "shared memory key");
static long base_period_nsec = 0; /* fastest thread period */
RTAPI_MP_LONG(base_period_nsec, "fastest thread period (nsecs)");
int base_thread_fp = 0; /* default is no floating point in base thread */
RTAPI_MP_INT(base_thread_fp, "floating point in base thread?");
static long servo_period_nsec = 1000000; /* servo thread period */
RTAPI_MP_LONG(servo_period_nsec, "servo thread period (nsecs)");
static long traj_period_nsec = 0; /* trajectory planner period */
Expand Down Expand Up @@ -1006,15 +1004,15 @@ static int init_threads(void)
/* create HAL threads for each period */
/* only create base thread if it is faster than servo thread */
if (servo_base_ratio > 1) {
retval = hal_create_thread("base-thread", base_period_nsec, base_thread_fp);
retval = hal_create_thread("base-thread", base_period_nsec);
if (retval < 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"MOTION: failed to create %ld nsec base thread\n",
base_period_nsec);
return -1;
}
}
retval = hal_create_thread("servo-thread", servo_period_nsec, 1);
retval = hal_create_thread("servo-thread", servo_period_nsec);
if (retval < 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"MOTION: failed to create %ld nsec servo thread\n",
Expand All @@ -1023,14 +1021,14 @@ static int init_threads(void)
}
/* export realtime functions that do the real work */
retval = hal_export_funct("motion-controller", emcmotController, 0 /* arg
*/ , 1 /* uses_fp */ , 0 /* reentrant */ , mot_comp_id);
*/ , 0 /* reentrant */ , mot_comp_id);
if (retval < 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"MOTION: failed to export controller function\n");
return -1;
}
retval = hal_export_funct("motion-command-handler", emcmotCommandHandler, 0 /* arg
*/ , 1 /* uses_fp */ , 0 /* reentrant */ , mot_comp_id);
*/ , 0 /* reentrant */ , mot_comp_id);
if (retval < 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"MOTION: failed to export command handler function\n");
Expand All @@ -1041,8 +1039,7 @@ static int init_threads(void)
/*! \todo FIXME - currently the traj planner is called from the controller */
/* eventually it will be a separate function */
retval = hal_export_funct("motion-traj-planner", emcmotTrajPlanner, 0 /* arg
*/ , 1 /* uses_fp */ ,
0 /* reentrant */ , mot_comp_id);
*/ , 0 /* reentrant */ , mot_comp_id);
if (retval < 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"MOTION: failed to export traj planner function\n");
Expand Down
2 changes: 1 addition & 1 deletion src/hal/classicladder/module_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ int rtapi_app_main(void) {

rtapi_print("creating ladder-state\n");

result = hal_export_funct("classicladder.0.refresh",hal_task,0,1, 0, compId);
result = hal_export_funct("classicladder.0.refresh",hal_task,0, 0, compId);
if(result < 0) {
error:
hal_exit(compId);
Expand Down
2 changes: 1 addition & 1 deletion src/hal/components/abs_s32.comp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pin out bit is_positive "TRUE if input is positive, FALSE if input is 0 or negat
pin out bit is_negative "TRUE if input is negative, FALSE if input is 0 or positive";

option period no;
function _ nofp;
function _;
license "GPL";
author "Sebastian Kuzminsky";
;;
Expand Down
2 changes: 1 addition & 1 deletion src/hal/components/abs_s64.comp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pin out bit is_positive "true if input is positive, false if input is 0 or negat
pin out bit is_negative "true if input is negative, false if input is 0 or positive";

option period no;
function _ nofp;
function _;
license "GPL";
author "ArcEye based on code from Sebastian Kuzminsky";
;;
Expand Down
2 changes: 1 addition & 1 deletion src/hal/components/and2.comp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ to the following truth table:
"""
;
option period no;
function _ nofp;
function _;
see_also """
*logic*(9),
*lut5*(9),
Expand Down
2 changes: 1 addition & 1 deletion src/hal/components/bin2gray.comp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ pin out unsigned out "gray code out";
license "GPL";
author "Andy Pugh";
option period no;
function _ nofp;
function _;
;;
out = (in >> 1) ^ in;
2 changes: 1 addition & 1 deletion src/hal/components/bitmerge.comp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pin out u32 out "The output value";
pin in bit in-##[32:personality];
author "Andy Pugh";
license "GPL2+";
function _ nofp;
function _;
option personality yes;
option period no;
;;
Expand Down
2 changes: 1 addition & 1 deletion src/hal/components/bitslice.comp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pin in u32 in "The input value";
pin out bit out-##[32:personality];
author "Andy Pugh";
license "GPL2+";
function _ nofp;
function _;
option personality yes;
option period no;
;;
Expand Down
2 changes: 1 addition & 1 deletion src/hal/components/bitwise.comp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pin out u32 out-xnor "The inverse of the bitwise XOR";

author "Andy Pugh";
license "GPL 2+";
function _ nofp;
function _;
option period no;
;;

Expand Down
2 changes: 1 addition & 1 deletion src/hal/components/boss_plc.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ Plc_Export(Plc *this, int compId, int id)

// Export functions.
if(!error){
error = hal_export_functf(Plc_Refresh, this, 1, 0, compId, "boss_plc.%d.refresh", id);
error = hal_export_functf(Plc_Refresh, this, 0, compId, "boss_plc.%d.refresh", id);
}

// Restore saved message level.
Expand Down
2 changes: 1 addition & 1 deletion src/hal/components/charge_pump.comp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pin out bit out "Square wave if 'enable' is TRUE or unconnected, low if 'enable'
pin out bit out-2 "Square wave at half the frequency of 'out'";
pin out bit out-4 "Square wave at a quarter of the frequency of 'out'";
pin in bit enable = TRUE "If FALSE, forces all 'out' pins to be low";
function _ nofp "Toggle the output bit (if enabled)";
function _ "Toggle the output bit (if enabled)";
description """
The 'Charge Pump' should be added to the base thread function.
When enabled the output is on for one period and off for one period. To calculate the
Expand Down
2 changes: 1 addition & 1 deletion src/hal/components/comp.comp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Keep in mind that floating point calculations are never absolute
and it is wise to always set *hyst* if you intend to use equal """;

option period no;
function _ fp "Update the comparator";
function _ "Update the comparator";
license "GPL";
author "Jeff Epler";
;;
Expand Down
2 changes: 1 addition & 1 deletion src/hal/components/conv.comp.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pin out @OUT@ out;
@CC@pin out bit out_of_range "TRUE when 'in' is not in the range of @OUT@";
@CC@param rw bit clamp """If TRUE, then clamp to the range of @OUT@. If FALSE, then allow the value to "wrap around".""";
option period no;
function _ @FP@ "Update 'out' based on 'in'";
function _ "Update 'out' based on 'in'";
license "GPL";
author "Jeff Epler";

Expand Down
Loading
Loading