diff --git a/docs/po4a.cfg b/docs/po4a.cfg index 5ca4619aa21..fe0852dc513 100644 --- a/docs/po4a.cfg +++ b/docs/po4a.cfg @@ -411,6 +411,7 @@ [type: man_def] build/man/man9/conv_bool_real.9 $lang:build/man/$lang/man9/conv_bool_real.9 [type: man_def] build/man/man9/conv_bool_sint.9 $lang:build/man/$lang/man9/conv_bool_sint.9 [type: man_def] build/man/man9/conv_bool_uint.9 $lang:build/man/$lang/man9/conv_bool_uint.9 +[type: man_def] build/man/man9/conv_real_bool.9 $lang:build/man/$lang/man9/conv_real_bool.9 [type: man_def] build/man/man9/conv_real_sint.9 $lang:build/man/$lang/man9/conv_real_sint.9 [type: man_def] build/man/man9/conv_real_uint.9 $lang:build/man/$lang/man9/conv_real_uint.9 [type: man_def] build/man/man9/conv_sint_bool.9 $lang:build/man/$lang/man9/conv_sint_bool.9 diff --git a/docs/src/getting-started/updating-linuxcnc.adoc b/docs/src/getting-started/updating-linuxcnc.adoc index 63decc6e5e2..52aa5088fa8 100644 --- a/docs/src/getting-started/updating-linuxcnc.adoc +++ b/docs/src/getting-started/updating-linuxcnc.adoc @@ -13,28 +13,32 @@ updates. If you don't have an internet connection to your PC see == Upgrade to the new version -This section describes how to upgrade LinuxCNC from version 2.8.x to a 2.9.y version. -It assumes that you have an existing 2.8 install that you want to update. +This section describes how to upgrade LinuxCNC from version 2.9.x to a 2.10.y version. +It assumes that you have an existing 2.9 install that you want to update. -To upgrade LinuxCNC from a version older than 2.8, you have to first -https://linuxcnc.org/docs/2.8/html/getting-started/updating-linuxcnc.html[upgrade your old install to 2.8], +To upgrade LinuxCNC from a version older than 2.9, you have to first +https://linuxcnc.org/docs/2.9/html/getting-started/updating-linuxcnc.html[upgrade your old install to 2.9], then follow these instructions to upgrade to the new version. If you do not have an old version of LinuxCNC to upgrade, then you're best off making a fresh install of the new version as described in the section <>. -Furthermore, if you are running Ubuntu Precise, Debian Wheezy or Debian Buster it is -well worth considering making a backup of the "linuxcnc" directory on -removable media and performing a +Furthermore, if you are running Ubuntu Precise, Debian Wheezy, Debian Buster or +Debian Bullseye it is well worth considering making a backup of the "linuxcnc" +directory on removable media and performing a <> -as these releases were EOL in 2017, 2018 and 2022 respectively. +as these releases were EOL in 2017, 2018, 2022 and 2026 respectively. If you are running on Ubuntu Lucid then you will have to do this, as Lucid is no longer supported by LinuxCNC (it was EOL in 2013). -To upgrade major versions like 2.8 to 2.9 when you have a network connection at +If you are running Debian Bookworm, then we *strongly* recommend that you upgrade to Debian Trixie. +Moving to the latest Debian version allows for better compatibility and a longer stable path for your installation. +Debian Trixie will have LTS support until June 2030. + +To upgrade major versions like 2.9 to 2.10 when you have a network connection at the machine you need to disable the old linuxcnc.org apt sources in the file /etc/apt/sources.list -and add a new linuxcnc.org apt source for 2.9, then upgrade LinuxCNC. +and add a new linuxcnc.org apt source for 2.10, then upgrade LinuxCNC. The details will depend on which platform you're running on. Open a <> then type `lsb_release -ic` to find this information out: @@ -45,8 +49,8 @@ Distributor ID: Debian Codename: Trixie ---- -You should be running on Debian Bullseye, Bookworm or Trixie or Ubuntu 20.04 "Focal Fossa" or newer. -LinuxCNC 2.9.y will not run on older distributions than these. +You should be running on Debian Bookworm or, recommended, Trixie or Ubuntu 24.04 "Noble Numbat" or newer. +LinuxCNC 2.10.y may not run on older distributions than these and is not supported on anything older. You will also need to check which realtime kernel is being used: @@ -87,11 +91,10 @@ RTAI packages are available for Bookworm and Buster but not currently for Bullse [cols="3,5",options="header"] |=== | OS / Realtime Version | Repository -| Debian Bullseye - preempt m| deb https://linuxcnc.org bullseye base 2.9-uspace -| Debian Bookworm - preempt m| deb https://linuxcnc.org bookworm base 2.9-uspace -| Debian Bookworm - RTAI m| deb https://linuxcnc.org bookworm base 2.9-rt -| Debian Trixie - preempt m| deb https://linuxcnc.org trixie base 2.9-uspace -| Debian Trixie - RTAI m| deb https://linuxcnc.org trixie base 2.9-rt +| Debian Bookworm - preempt m| deb https://linuxcnc.org bookworm base 2.10-uspace +| Debian Bookworm - RTAI m| deb https://linuxcnc.org bookworm base 2.10-rt +| Debian Trixie - preempt m| deb https://linuxcnc.org trixie base 2.10-uspace +| Debian Trixie - RTAI m| deb https://linuxcnc.org trixie base 2.10-rt |=== .Figure with a screenshot of the repository configuration of the synaptic package manager. @@ -145,77 +148,83 @@ Codename: trixie ---- Pick the OS from the list then pick the major version you want like -2.9-rt for RTAI or 2.9-uspace for preempt-rt. +2.10-rt for RTAI or 2.10-uspace for preempt-rt. Next pick the type of computer you have: binary-amd64 for 64-bit PC or binary-arm64 (64bit) for Raspberry Pi. Next pick the version you want from the bottom of the list like -'linuxcnc-uspace_2.9.8_amd64.deb' (choose the latest by date). +'linuxcnc-uspace_2.10.0_amd64.deb' (choose the latest by date). Download the deb and copy it to your home directory. You can rename the file to something a bit shorter with the file manager like -'linuxcnc_2.9.8.deb' then open a terminal and install it with the +'linuxcnc_2.19.0.deb' then open a terminal and install it with the package manager with this command: ---- -sudo dpkg -i linuxcnc_2.9.8.deb +sudo dpkg -i linuxcnc_2.10.0.deb ---- +== Updating to 2.10 -== Updating Configuration Files for 2.9 - -=== Stricter handling of pluggable interpreters - -If you just run regular G-code and you don't know what a pluggable -interpreter is, then this section does not affect you. - -A seldom-used feature of LinuxCNC is support for pluggable interpreters, -controlled by the undocumented `[TASK]INTERPRETER` INI setting. +A large set of changes have been implemented in the new version. +The changes include: -Versions of LinuxCNC before 2.9.0 used to handle an incorrect -`[TASK]INTERPRETER` setting by automatically falling back to using the -default G-code interpreter. +* INI: Reworked INI-file parser with consistent types +* HAL: API breaking change implementing new HAL types +* HAL: Make the underlying HAL memory inaccessible and use a proper API +* TP: New selectable scurve trajectory planner added -Since 2.9.0, an incorrect `[TASK]INTERPRETER` value will cause -LinuxCNC to refuse to start up. Fix this condition by deleting the -`[TASK]INTERPRETER` setting from your INI file, so that LinuxCNC will -use the default G-code interpreter. +=== New HAL types +All integer HAL pins are now 64-bit only and the old HAL type names have changed: -=== Canterp +* `HAL_BOOL` - formerly HAL_BIT +* `HAL_REAL` - formerly HAL_FLOAT +* `HAL_SINT` - formerly HAL_S64 +* `HAL_UINT` - formerly HAL_U64 -If you just run regular G-code and you don't use the `canterp` pluggable -interpreter, then this section does not affect you. +The old 32-bit types have been removed: +* `HAL_S32` - removed +* `HAL_U32` - removed -In the extremely unlikely event that you are using `canterp`, -know that the module has moved from `/usr/lib/libcanterp.so` to -`/usr/lib/linuxcnc/canterp.so`, and the `[TASK]INTERPRETER` setting -correspondingly needs to change from `libcanterp.so` to `canterp.so`. - - -=== Spindle limits in the INI +[IMPORTANT] +==== +Any user components must be updated and recompiled. +The old HAL API is no longer available and access to pins/params is not done by getter/setter. +See ...FIXME... for a more detailed description how to update your components. +==== -It is now possible to add settings to the [SPINDLE] section of the INI file +=== Component changes -MAX_FORWARD_VELOCITY = 20000 The maximum spindle speed (in rpm) +Components were renamed in the HAL type replacement process because they included the old type names: +* conv_XXXX_YYYY - coversion between types now use 'bool', 'real', 'sint' and 'uint' for XXXX and YYYY. +* abs_s32 - replaced by abs_sint. +* abs_s64 - replaced by abs_sint. +* scaled_s32_sums - replaced by scaled_sint_sums. +* mux_generic - renamed pins +* demux_generic - renamed pins +* demux - renamed pin sel-s32 to sel-sint -MIN_FORWARD_VELOCITY = 3000 The minimum spindle speed (in rpm) +=== Updated Python interface -MAX_REVERSE_VELOCITY = 20000 This setting will default to -MAX_FORWARD_VELOCITY if omitted. +The HAL type update is also added to the `hal` module. +Additionally, the type names and direction names have been added as IntEnum types. +All code has been updated to use them and you are encouraged to do the same: -MIN_REVERSE_VELOCITY = 3000` This setting is equivalent to -MIN_FORWARD_VELOCITY but for reverse spindle rotation. It will default -to the MIN_FORWARD_VELOCITY if omitted. +[source,python] +---- +import hal +... -INCREMENT = 200 Sets the step size for spindle speed increment / -decrement commands. This can have a different value for each spindle. -This setting is effective with AXIS and Touchy but note that some -control screens may handle things differently. +# Old: +comp.newpin("pinname", hal.HAL_FLOAT, hal.HAL_IN) -HOME_SEARCH_VELOCITY = 100 - Accepted but currently does nothing +# New: +comp.newpin("pinname", hal.Type.REAL, hal.Dir.IN) +---- -HOME_SEQUENCE = 0 - Accepted but currently does nothing +The old HAL_S32 and HAL_U32 names have been removed and the old HAL type names +HAL_BIT, HAL_FLOAT, HAL_S64 and HAL_U64 will result in a deprecation warning. == Updating Configuration Files for 2.10.y @@ -431,39 +440,16 @@ depth/blend state a part left behind. == New HAL components === Non-Realtime -mdro -mqtt-publisher -pi500_vfd -pmx485-test -qtplasmac-cfg2prefs -qtplasmac-materials -qtplasmac-plasmac2qt -qtplasmac-setup -sim-torch -svd-ps_vfd -=== Realtime -anglejog -div2 -enum -filter_kalman -flipflop -homecomp -limit_axis -mesa_uart -millturn -scaled_s32_sums -tof -ton +...FIXME... -== New Drivers - -A framework for controlling ModBus devices using the serial ports on -many Mesa cards has been introduced. -http://linuxcnc.org/docs/2.9/html/drivers/mesa_modbus.html +=== Realtime -A new GPIO driver for any GPIO which is supported by the gpiod library -is now included: -http://linuxcnc.org/docs/2.9/html/drivers/hal_gpio.html +...FIXME... +== New Drivers +A new ModBus universal driver `hm2_modbus` for Mesa hardware has been created. +It replaces the old mesa_modbus driver and is much more capable. +See hm2_modbus(9) and mesambccc(1). +There are example configurations under `/usr/share/doc/linuxcnc/examples/sample-configs/by_interface/mesa/hm2-modbus`. diff --git a/docs/src/hal/comp.adoc b/docs/src/hal/comp.adoc index 18fca5a909a..db90427cab5 100644 --- a/docs/src/hal/comp.adoc +++ b/docs/src/hal/comp.adoc @@ -180,6 +180,7 @@ Declarations include: * 'component HALNAME (DOC);' * 'pin PINDIRECTION TYPE HALNAME ([SIZE]|[MAXSIZE: CONDSIZE]) (if CONDITION) (= STARTVALUE) (DOC) ;' * 'param PARAMDIRECTION TYPE HALNAME ([SIZE]|[MAXSIZE: CONDSIZE]) (if CONDITION) (= STARTVALUE) (DOC) ;' +* 'alias HALNAME HALNAME ;' * 'function HALNAME (fp | nofp) (DOC);' * 'option OPT (VALUE);' * 'variable CTYPE STARREDNAME ([SIZE]);' diff --git a/docs/src/hal/components.adoc b/docs/src/hal/components.adoc index f70961dab05..06fd5674a31 100644 --- a/docs/src/hal/components.adoc +++ b/docs/src/hal/components.adoc @@ -285,6 +285,7 @@ Limit its slew rate to less than maxv per second. Limit its second derivative to | link:../man/man9/conv_bool_real.9.html[conv_bool_real] |Converts from bool to real || | link:../man/man9/conv_bool_sint.9.html[conv_bool_sint] |Convert a value from bool to sint || | link:../man/man9/conv_bool_uint.9.html[conv_bool_uint] |Convert a value from bool to uint || +| link:../man/man9/conv_real_bool.9.html[conv_real_bool] |Convert a value from real to bool || | link:../man/man9/conv_real_sint.9.html[conv_real_sint] |Convert a value from real to sint || | link:../man/man9/conv_real_uint.9.html[conv_real_uint] |Convert a value from real to uint || | link:../man/man9/conv_sint_bool.9.html[conv_sint_bool] |Convert a value from sint to bool || diff --git a/src/Makefile b/src/Makefile index 927b1227fea..f6e5bee8d2b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -565,7 +565,7 @@ genclean: -rm -f ../lib/*.so.[0-9]* -rm -rf ../docs/build/man -rm -f ../rtlib/*.$(MODULE_EXT) - -rm -f hal/components/conv_*.comp + -rm -f $(patsubst %,hal/components/%,$(notdir $(CONVERTERS))) pycheck-python-files: @echo 'Checking *.py files for python3 compatibility...' diff --git a/src/hal/components/.gitignore b/src/hal/components/.gitignore index 01a447a5a38..c18fb61471b 100644 --- a/src/hal/components/.gitignore +++ b/src/hal/components/.gitignore @@ -1 +1,2 @@ conv_*.comp +!conv_real_bool.comp diff --git a/src/hal/components/boss_plc.c b/src/hal/components/boss_plc.c index 7098b9eb486..a77f4080f2d 100644 --- a/src/hal/components/boss_plc.c +++ b/src/hal/components/boss_plc.c @@ -14,74 +14,74 @@ * the component id number and is formatted as "%d". * * Pins (former parameters): - * u32 boss_plc..amp-ready-delay - * u32 boss_plc..brake-on-delay - * u32 boss_plc..brake-off-delay - * u32 boss_plc..spindle-lo-to-hi - * float boss_plc..jog-scale-0 - * float boss_plc..jog-scale-1 - * float boss_plc..jog-scale-2 + * uint boss_plc..amp-ready-delay + * uint boss_plc..brake-on-delay + * uint boss_plc..brake-off-delay + * uint boss_plc..spindle-lo-to-hi + * real boss_plc..jog-scale-0 + * real boss_plc..jog-scale-1 + * real boss_plc..jog-scale-2 * * Pins: - * bit boss_plc..cycle-start-in - * bit boss_plc..cycle-hold-in - * bit boss_plc..feed-hold-out - * float boss_plc..adaptive-feed-in - * float boss_plc..adaptive-feed-out - * bit boss_plc..tool-change-in - * bit boss_plc..tool-changed-out - * bit boss_plc..wait-user-out - * bit boss_plc..mist-on-in - * bit boss_plc..mist-on-out - * bit boss_plc..flood-on-in - * bit boss_plc..flood-on-out + * bool boss_plc..cycle-start-in + * bool boss_plc..cycle-hold-in + * bool boss_plc..feed-hold-out + * real boss_plc..adaptive-feed-in + * real boss_plc..adaptive-feed-out + * bool boss_plc..tool-change-in + * bool boss_plc..tool-changed-out + * bool boss_plc..wait-user-out + * bool boss_plc..mist-on-in + * bool boss_plc..mist-on-out + * bool boss_plc..flood-on-in + * bool boss_plc..flood-on-out * - * bit boss_plc..limit-override-in - * bit boss_plc..limit-active-out - * float boss_plc..x-position-in - * bit boss_plc..x-jog-en-in - * bit boss_plc..x-limit-in - * bit boss_plc..x-limit-pos-out - * bit boss_plc..x-limit-neg-out - * float boss_plc..y-position-in - * bit boss_plc..y-jog-en-in - * bit boss_plc..y-limit-in - * bit boss_plc..y-limit-pos-out - * bit boss_plc..y-limit-neg-out - * bit boss_plc..z-jog-en-in - * bit boss_plc..z-limit-pos-in - * bit boss_plc..z-limit-neg-in - * bit boss_plc..z-limit-pos-out - * bit boss_plc..z-limit-neg-out + * bool boss_plc..limit-override-in + * bool boss_plc..limit-active-out + * real boss_plc..x-position-in + * bool boss_plc..x-jog-en-in + * bool boss_plc..x-limit-in + * bool boss_plc..x-limit-pos-out + * bool boss_plc..x-limit-neg-out + * real boss_plc..y-position-in + * bool boss_plc..y-jog-en-in + * bool boss_plc..y-limit-in + * bool boss_plc..y-limit-pos-out + * bool boss_plc..y-limit-neg-out + * bool boss_plc..z-jog-en-in + * bool boss_plc..z-limit-pos-in + * bool boss_plc..z-limit-neg-in + * bool boss_plc..z-limit-pos-out + * bool boss_plc..z-limit-neg-out * - * bit boss_plc..x-amp-enable-in - * bit boss_plc..x-amp-ready-in - * bit boss_plc..x-amp-fault-out - * bit boss_plc..y-amp-enable-in - * bit boss_plc..y-amp-ready-in - * bit boss_plc..y-amp-fault-out - * bit boss_plc..z-amp-enable-in - * bit boss_plc..z-amp-ready-in - * bit boss_plc..z-amp-fault-out - * bit boss_plc..a-amp-enable-in - * bit boss_plc..a-amp-ready-in - * bit boss_plc..a-amp-fault-out + * bool boss_plc..x-amp-enable-in + * bool boss_plc..x-amp-ready-in + * bool boss_plc..x-amp-fault-out + * bool boss_plc..y-amp-enable-in + * bool boss_plc..y-amp-ready-in + * bool boss_plc..y-amp-fault-out + * bool boss_plc..z-amp-enable-in + * bool boss_plc..z-amp-ready-in + * bool boss_plc..z-amp-fault-out + * bool boss_plc..a-amp-enable-in + * bool boss_plc..a-amp-ready-in + * bool boss_plc..a-amp-fault-out * - * float boss_plc..spindle-speed-in - * bit boss_plc..spindle-is-on-in - * bit boss_plc..spindle-fwd-out - * bit boss_plc..spindle-rev-out - * bit boss_plc..spindle-inc-in - * bit boss_plc..spindle-dec-in - * bit boss_plc..spindle-inc-out - * bit boss_plc..spindle-dec-out - * bit boss_plc..brake-en-in - * bit boss_plc..brake-en-out + * real boss_plc..spindle-speed-in + * bool boss_plc..spindle-is-on-in + * bool boss_plc..spindle-fwd-out + * bool boss_plc..spindle-rev-out + * bool boss_plc..spindle-inc-in + * bool boss_plc..spindle-dec-in + * bool boss_plc..spindle-inc-out + * bool boss_plc..spindle-dec-out + * bool boss_plc..brake-en-in + * bool boss_plc..brake-en-out * - * bit boss_plc..jog-sel-in-0 - * bit boss_plc..jog-sel-in-1 - * bit boss_plc..jog-sel-in-2 - * bit boss_plc..jog-scale-out + * bool boss_plc..jog-sel-in-0 + * bool boss_plc..jog-sel-in-1 + * bool boss_plc..jog-sel-in-2 + * bool boss_plc..jog-scale-out * * Functions: * void boss_plc..refresh @@ -153,8 +153,8 @@ typedef struct { // Private data. BOOL enabled; rtapi_u32 nSec; - rtapi_u32 count; - rtapi_u32 timeout; + rtapi_uint count; + rtapi_uint timeout; TIMER_ROUTINE pTimeout; void *pArgs; TimerMode mode; @@ -165,7 +165,7 @@ static void Timer_Enable(Timer *this, TimerMode mode); static void Timer_Disable(Timer *this); static BOOL Timer_IsEnabled(Timer *this); static void Timer_Update(Timer *this, long period); -static void Timer_SetTimeout(Timer *this, rtapi_u32 timeout); +static void Timer_SetTimeout(Timer *this, rtapi_uint timeout); #if 0 static void Timer_SetCallback(Timer *this, TIMER_ROUTINE pCallback, void *pArgs); #endif @@ -229,7 +229,7 @@ typedef struct { static int Amp_Export(Amp *this, int compId, int id, char axis); static void Amp_Init(Amp *this); -static void Amp_Refresh(Amp *this, long period, rtapi_u32 readyDelay); +static void Amp_Refresh(Amp *this, long period, rtapi_uint readyDelay); /****************************************************************************** @@ -617,12 +617,12 @@ Plc_ExportLimits(Plc *this, int compId, int id) // Export optional parameters. if(debug > 0){ if(!error){ - error = hal_param_new_ui32(compId, HAL_RO, &this->xLimit.stateDebug, 0, + error = hal_param_new_uint(compId, HAL_RO, &this->xLimit.stateDebug, 0, "boss_plc.%d.%c-limit-state", id, axisNames[0]); } if(!error){ - error = hal_param_new_ui32(compId, HAL_RO, &this->yLimit.stateDebug, 0, + error = hal_param_new_uint(compId, HAL_RO, &this->yLimit.stateDebug, 0, "boss_plc.%d.%c-limit-state", id, axisNames[1]); } } @@ -637,7 +637,7 @@ Plc_ExportAmps(Plc *this, int compId, int id) int error, i; Amp *pAmp; - error = hal_pin_new_ui32(compId, HAL_IO, &this->ampReadyDelay, 50, + error = hal_pin_new_uint(compId, HAL_IO, &this->ampReadyDelay, 50, "boss_plc.%d.amp-ready-delay", id); pAmp = this->amps; @@ -655,11 +655,11 @@ Plc_ExportSpindle(Plc *this, int compId, int id) int error; // Export parameters. - error = hal_pin_new_ui32(compId, HAL_IO, &this->brakeOnDelay, 300, + error = hal_pin_new_uint(compId, HAL_IO, &this->brakeOnDelay, 300, "boss_plc.%d.brake-on-delay", id); if(!error){ - error = hal_pin_new_ui32(compId, HAL_IO, &this->brakeOffDelay, 500, + error = hal_pin_new_uint(compId, HAL_IO, &this->brakeOffDelay, 500, "boss_plc.%d.brake-off-delay", id); } @@ -671,7 +671,7 @@ Plc_ExportSpindle(Plc *this, int compId, int id) // Export optional parameters. if(debug > 0){ if(!error){ - error = hal_param_new_ui32(compId, HAL_RO, &this->spindleStateDebug, 0, + error = hal_param_new_uint(compId, HAL_RO, &this->spindleStateDebug, 0, "boss_plc.%d.spindle-state", id); } } @@ -782,9 +782,9 @@ Plc_Refresh(void *arg, long period) Plc_RefreshJog(this, period); if(debug > 0) { - hal_set_ui32(this->spindleStateDebug, this->spindleState); - hal_set_ui32(this->xLimit.stateDebug, this->xLimit.state); - hal_set_ui32(this->yLimit.stateDebug, this->yLimit.state); + hal_set_uint(this->spindleStateDebug, this->spindleState); + hal_set_uint(this->xLimit.stateDebug, this->xLimit.state); + hal_set_uint(this->yLimit.stateDebug, this->yLimit.state); } } @@ -855,7 +855,7 @@ Plc_RefreshAmps(Plc *this, long period) pAmp = this->amps; for(i = 0; i < NUM_AXIS; i++, pAmp++){ - Amp_Refresh(pAmp, period, hal_get_ui32(this->ampReadyDelay)); + Amp_Refresh(pAmp, period, hal_get_uint(this->ampReadyDelay)); } } @@ -870,7 +870,7 @@ Plc_RefreshSpindle(Plc *this, long period) if(!hal_get_bool(this->pBrakeEnIn)){ this->spindleState = SS_WAIT_BRAKE_OFF; hal_set_bool(this->pBrakeEnOut, 0); - Timer_SetTimeout(&this->spindleTimer, hal_get_ui32(this->brakeOffDelay)); + Timer_SetTimeout(&this->spindleTimer, hal_get_uint(this->brakeOffDelay)); Timer_Enable(&this->spindleTimer, TM_ONE_SHOT); } break; @@ -927,7 +927,7 @@ Plc_RefreshSpindle(Plc *this, long period) if(!hal_get_bool(this->pSpindleIsOnIn)){ this->spindleState = SS_WAIT_BRAKE_ON; - Timer_SetTimeout(&this->spindleTimer, hal_get_ui32(this->brakeOnDelay)); + Timer_SetTimeout(&this->spindleTimer, hal_get_uint(this->brakeOnDelay)); Timer_Enable(&this->spindleTimer, TM_ONE_SHOT); } break; @@ -1123,7 +1123,7 @@ Amp_Init(Amp *this) static void -Amp_Refresh(Amp *this, long period, rtapi_u32 readyDelay) +Amp_Refresh(Amp *this, long period, rtapi_uint readyDelay) { Timer_Update(&this->timer, period); @@ -1204,7 +1204,7 @@ Timer_Update(Timer *this, long period) static void -Timer_SetTimeout(Timer *this, rtapi_u32 timeout) +Timer_SetTimeout(Timer *this, rtapi_uint timeout) { this->count = 0; this->timeout = timeout; diff --git a/src/hal/components/comp.comp b/src/hal/components/comp.comp index cf27ca469e0..8365df255fb 100644 --- a/src/hal/components/comp.comp +++ b/src/hal/components/comp.comp @@ -16,6 +16,7 @@ option period no; function _ "Update the comparator"; license "GPL"; author "Jeff Epler"; +see_also "conv_real_bool(9)."; ;; FUNCTION(_) { rtapi_real tmp = in1 - in0; diff --git a/src/hal/components/conv_real_bool.comp b/src/hal/components/conv_real_bool.comp new file mode 100644 index 00000000000..a00ee0d2dd7 --- /dev/null +++ b/src/hal/components/conv_real_bool.comp @@ -0,0 +1,23 @@ +component conv_real_bool """Convert a value from real to bool + +The output value `out` is False when `in` is within `±eps` of zero. +The `out` pin is set to True once the `in` value reaches beyond. + +* `in` < `-eps` -> `out` = True +* `in` > `+eps` -> `out` = True +* `-eps` ≤ `in` ≤ `+eps` -> `out` = False + +In effect: `out = |in| > |eps|` + +"""; +pin in real in "Input value to convert."; +pin out bool out "Output value is False when input is within ±eps."; +param rw real eps = 1e-8 "Epsilon value to determine the input to be zero."; +option period no; +function _ "Update 'out' based on 'in' to be within 'eps' or not."; +license "GPL"; +author "LinuxCNC authors"; +see_also "comp(9)."; +include ; +;; +out_set(fabs(in) > fabs(eps)); diff --git a/src/hal/components/counter.c b/src/hal/components/counter.c index 829d1412b89..574c859b1a0 100644 --- a/src/hal/components/counter.c +++ b/src/hal/components/counter.c @@ -76,8 +76,8 @@ typedef struct { hal_real_t pos_scale; /* pin: scaling factor for pos */ double old_scale; /* stored scale value */ double scale; /* reciprocal value used for scaling */ - rtapi_s32 last_count; - rtapi_s32 last_index_count; + rtapi_sint last_count; + rtapi_sint last_index_count; } counter_t; /* pointer to array of counter_t structs in shmem, 1 per counter */ @@ -138,8 +138,8 @@ int rtapi_app_main(void) counter_array[n].oldZ = 0; counter_array[n].oldA = 0; counter_array[n].reset_on_index = 0; - hal_set_si32(counter_array[n].raw_count, 0); - hal_set_si32(counter_array[n].count, 0); + hal_set_sint(counter_array[n].raw_count, 0); + hal_set_sint(counter_array[n].count, 0); hal_set_real(counter_array[n].pos, 0.0); hal_set_real(counter_array[n].pos_scale, 1.0); counter_array[n].old_scale = 1.0; @@ -186,12 +186,12 @@ static void update(void *arg, long period) for (cntr = arg, n = 0; n < num_chan; cntr++, n++) { // count on rising edge if(!cntr->oldA && hal_get_bool(cntr->phaseA)) - hal_set_si32(cntr->raw_count, hal_get_si32(cntr->raw_count) + 1); + hal_set_sint(cntr->raw_count, hal_get_sint(cntr->raw_count) + 1); cntr->oldA = hal_get_bool(cntr->phaseA); // reset on rising edge if(cntr->reset_on_index && !cntr->oldZ && hal_get_bool(cntr->phaseZ)) { - cntr->last_index_count = hal_get_si32(cntr->raw_count); + cntr->last_index_count = hal_get_sint(cntr->raw_count); hal_set_bool(cntr->index_ena, 0); } cntr->oldZ = hal_get_bool(cntr->phaseZ); @@ -205,17 +205,17 @@ static void capture(void *arg, long period) for (cntr = arg, n = 0; n < num_chan; cntr++, n++) { /* check reset input */ - int raw_count; - int counts; + rtapi_sint raw_count; + rtapi_sint counts; if (hal_get_bool(cntr->reset)) { /* reset is active, reset the counter */ - hal_set_si32(cntr->raw_count, 0); + hal_set_sint(cntr->raw_count, 0); cntr->last_index_count = 0; cntr->last_count = 0; } /* capture raw counts to latches */ - raw_count = hal_get_si32(cntr->raw_count); - hal_set_si32(cntr->count, raw_count - cntr->last_index_count); + raw_count = hal_get_sint(cntr->raw_count); + hal_set_sint(cntr->count, raw_count - cntr->last_index_count); counts = (raw_count - cntr->last_count); cntr->last_count = raw_count; @@ -232,7 +232,7 @@ static void capture(void *arg, long period) cntr->scale = 1.0 / hal_get_real(cntr->pos_scale); } /* scale count to make floating point position */ - hal_set_real(cntr->pos, hal_get_si32(cntr->count) * cntr->scale); + hal_set_real(cntr->pos, hal_get_sint(cntr->count) * cntr->scale); /* scale counts to make floating point velocity */ hal_set_real(cntr->vel, counts * cntr->scale * 1e9 / period); @@ -273,9 +273,9 @@ static int export_counter(int num, counter_t * addr) /* export pin for the reset input */ CHK(hal_pin_new_bool(comp_id, HAL_IN, &addr->reset, 0, "counter.%d.reset", num)); /* export parameter for raw counts */ - CHK(hal_pin_new_si32(comp_id, HAL_OUT, &addr->raw_count, 0, "counter.%d.rawcounts", num)); + CHK(hal_pin_new_sint(comp_id, HAL_OUT, &addr->raw_count, 0, "counter.%d.rawcounts", num)); /* export pin for counts captured by capture() */ - CHK(hal_pin_new_si32(comp_id, HAL_OUT, &addr->count, 0, "counter.%d.counts", num)); + CHK(hal_pin_new_sint(comp_id, HAL_OUT, &addr->count, 0, "counter.%d.counts", num)); /* export pin for scaled position captured by capture() */ CHK(hal_pin_new_real(comp_id, HAL_OUT, &addr->pos, 0.0, "counter.%d.position", num)); /* export pin for scaled velocity captured by capture() */ diff --git a/src/hal/components/debounce.c b/src/hal/components/debounce.c index b8fe3d0ca4f..582becbabe9 100644 --- a/src/hal/components/debounce.c +++ b/src/hal/components/debounce.c @@ -70,7 +70,7 @@ typedef struct { #ifdef EXPORT_STATE hal_sint_t state; /* parameter*: internal state */ #else - rtapi_s32 state; /* parameter*: internal state */ + rtapi_sint state; /* parameter*: internal state */ #endif } debounce_t; @@ -173,11 +173,11 @@ void rtapi_app_exit(void) ************************************************************************/ #ifdef EXPORT_STATE -static inline rtapi_s32 get_state(hal_sint_t *s) { return hal_get_si32(*s); } -static inline rtapi_s32 set_state(hal_sint_t *s, rtapi_s32 v) { return hal_set_si32(*s, v); } +static inline rtapi_sint get_state(hal_sint_t *s) { return hal_get_sint(*s); } +static inline rtapi_sint set_state(hal_sint_t *s, rtapi_sint v) { return hal_set_sint(*s, v); } #else -static inline rtapi_s32 get_state(rtapi_s32 *s) { return *s; } -static inline rtapi_s32 set_state(rtapi_s32 *s, rtapi_s32 v) { return (*s = v); } +static inline rtapi_sint get_state(rtapi_sint *s) { return *s; } +static inline rtapi_sint set_state(rtapi_sint *s, rtapi_sint v) { return (*s = v); } #endif /** The debounce filter works by incrementing a counter whenever the @@ -205,8 +205,8 @@ static void debounce(void *arg, long period) /* point to filter group */ group = (debounce_group_t *) arg; /* first make sure delay is sane */ - if (hal_get_si32(group->delay) < 0) { - hal_set_si32(group->delay, 1); + if (hal_get_sint(group->delay) < 0) { + hal_set_sint(group->delay, 1); } /* loop thru filters */ for (n = 0; n < group->channels; n++) { @@ -215,7 +215,7 @@ static void debounce(void *arg, long period) /* update this filter */ if (hal_get_bool(filter->in)) { /* input true, is state at threshold? */ - if (get_state(&filter->state) < hal_get_si32(group->delay)) { + if (get_state(&filter->state) < hal_get_sint(group->delay)) { /* no, increment */ set_state(&filter->state, get_state(&filter->state) + 1); } else { @@ -257,7 +257,7 @@ static int export_group(int num, debounce_group_t * addr, int group_size) return -1; } /* export param variable for delay */ - retval = hal_param_new_si32(comp_id, HAL_RW, &addr->delay, 5, "debounce.%d.delay", num); + retval = hal_param_new_sint(comp_id, HAL_RW, &addr->delay, 5, "debounce.%d.delay", num); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "DEBOUNCE: ERROR: 'debounce.%d.delay' param export failed\n", num); return retval; @@ -304,7 +304,7 @@ static int export_filter(int num, debounce_t * addr, int group_num) } #ifdef EXPORT_STATE /* export parameter containing internal state */ - retval = hal_param_new_si32(comp_id, HAL_RO, &addr->state, 0, "%s.state", buf); + retval = hal_param_new_sint(comp_id, HAL_RO, &addr->state, 0, "%s.state", buf); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "DEBOUNCE: ERROR: '%s.state' param export failed\n", buf); return retval; diff --git a/src/hal/components/encoder.c b/src/hal/components/encoder.c index 6cb08cf12c5..76166a7f057 100644 --- a/src/hal/components/encoder.c +++ b/src/hal/components/encoder.c @@ -88,10 +88,10 @@ typedef struct { char count_detected; char index_detected; char latch_detected; - rtapi_s32 raw_count; + rtapi_sint raw_count; rtapi_u32 timestamp; - rtapi_s32 index_count; - rtapi_s32 latch_count; + rtapi_sint index_count; + rtapi_sint latch_count; } atomic; /* this structure contains the runtime data for a single counter @@ -120,10 +120,10 @@ typedef struct { hal_bool_t latch_in; /* c:r counter latch input */ hal_bool_t latch_rising; /* u:r latch on rising edge? */ hal_bool_t latch_falling; /* u:r latch on falling edge? */ - rtapi_s32 raw_count; /* c:rw captured raw_count */ + rtapi_sint raw_count; /* c:rw captured raw_count */ rtapi_u32 timestamp; /* c:rw captured timestamp */ - rtapi_s32 index_count; /* c:rw captured index count */ - rtapi_s32 latch_count; /* c:rw captured index count */ + rtapi_sint index_count; /* c:rw captured index count */ + rtapi_sint latch_count; /* c:rw captured index count */ hal_sint_t count; /* c:w captured binary count value */ hal_sint_t count_latch; /* c:w captured binary count value */ hal_real_t min_speed; /* c:r minimum velocity to estimate nonzero */ @@ -273,12 +273,12 @@ int rtapi_app_main(void) cntr->buf[0].index_detected = 0; cntr->buf[1].index_detected = 0; cntr->bp = &(cntr->buf[0]); - hal_set_si32(cntr->raw_counts, 0); + hal_set_sint(cntr->raw_counts, 0); cntr->raw_count = 0; cntr->timestamp = 0; cntr->index_count = 0; cntr->latch_count = 0; - hal_set_si32(cntr->count, 0); + hal_set_sint(cntr->count, 0); hal_set_real(cntr->min_speed, 1.0); hal_set_real(cntr->pos, 0.0); hal_set_real(cntr->pos_latch, 0.0); @@ -332,7 +332,7 @@ static void update(void *arg, long period) cntr = arg; for (n = 0; n < howmany; n++) { buf = (atomic *) cntr->bp; - hal_set_si32(cntr->dt, hal_get_si32(cntr->dt) + period); + hal_set_sint(cntr->dt, hal_get_sint(cntr->dt) + period); /* get state machine current state */ state = cntr->state; /* add input bits to state code */ @@ -352,15 +352,15 @@ static void update(void *arg, long period) } /* should we count? */ if (state & SM_CNT_UP_MASK) { - if (hal_get_si32(cntr->missing_teeth) && hal_get_si32(cntr->dt) > hal_get_si32(cntr->limit_dt)){ + if (hal_get_sint(cntr->missing_teeth) && hal_get_sint(cntr->dt) > hal_get_sint(cntr->limit_dt)){ cntr->gaps++; } - buf->raw_count = hal_set_si32(cntr->raw_counts, hal_get_si32(cntr->raw_counts) + 1); + buf->raw_count = hal_set_sint(cntr->raw_counts, hal_get_sint(cntr->raw_counts) + 1); buf->timestamp = timebase; buf->count_detected = 1; - hal_set_si32(cntr->dt, 0); + hal_set_sint(cntr->dt, 0); } else if (state & SM_CNT_DN_MASK) { - buf->raw_count = hal_set_si32(cntr->raw_counts, hal_get_si32(cntr->raw_counts) - 1); + buf->raw_count = hal_set_sint(cntr->raw_counts, hal_get_sint(cntr->raw_counts) - 1); buf->timestamp = timebase; buf->count_detected = 1; } @@ -376,7 +376,7 @@ static void update(void *arg, long period) /* test for index enabled and rising edge on phase Z */ if ((state & cntr->Zmask) == 1) { /* capture counts, reset Zmask */ - buf->index_count = hal_get_si32(cntr->raw_counts); + buf->index_count = hal_get_sint(cntr->raw_counts); buf->index_detected = 1; cntr->Zmask = 0; } @@ -388,7 +388,7 @@ static void update(void *arg, long period) if((rising && hal_get_bool(cntr->latch_rising)) || (falling && hal_get_bool(cntr->latch_falling))) { buf->latch_detected = 1; - buf->latch_count = hal_get_si32(cntr->raw_counts); + buf->latch_count = hal_get_sint(cntr->raw_counts); } cntr->old_latch = latch; @@ -465,12 +465,12 @@ static void capture(void *arg, long period) running count of edges seen since startup. The public "count" is the difference between raw_count and index_count, so it will become zero. */ - cntr->raw_count = hal_get_si32(cntr->raw_counts); + cntr->raw_count = hal_get_sint(cntr->raw_counts); cntr->index_count = cntr->raw_count; } /* process data from update() */ if ( buf->count_detected ) { - rtapi_s32 missing_teeth = hal_get_si32(cntr->missing_teeth); + rtapi_sint missing_teeth = hal_get_sint(cntr->missing_teeth); /* one or more counts in the last period */ buf->count_detected = 0; delta_time = buf->timestamp - cntr->timestamp; @@ -478,13 +478,13 @@ static void capture(void *arg, long period) // lowpass the gap detector deliberately ignoring missing teeth // see https://github.com/LinuxCNC/linuxcnc/issues/2635 if (delta_counts != 0){ - rtapi_s32 limit_dt = hal_get_si32(cntr->limit_dt); + rtapi_sint limit_dt = hal_get_sint(cntr->limit_dt); limit_dt *= 0.9; limit_dt += 0.1 * ((missing_teeth + 0.5) * (delta_time / delta_counts)); - hal_set_si32(cntr->limit_dt, limit_dt); + hal_set_sint(cntr->limit_dt, limit_dt); } // correct counts for tooth gap - hal_set_si32(cntr->raw_counts, hal_get_si32(cntr->raw_counts) + missing_teeth * cntr->gaps); + hal_set_sint(cntr->raw_counts, hal_get_sint(cntr->raw_counts) + missing_teeth * cntr->gaps); cntr->raw_count = buf->raw_count + missing_teeth * cntr->gaps; delta_counts += missing_teeth * cntr->gaps; cntr->gaps = 0; @@ -500,7 +500,7 @@ static void capture(void *arg, long period) if ( cntr->counts_since_timeout ) { /* calc time since last count */ delta_time = timebase - cntr->timestamp; - if (hal_get_si32(cntr->missing_teeth) && delta_time > 1.5 * hal_get_si32(cntr->limit_dt)){ + if (hal_get_sint(cntr->missing_teeth) && delta_time > 1.5 * hal_get_sint(cntr->limit_dt)){ // dont update the velocity in the tooth gap } else if ( delta_time < 1e9 / ( hal_get_real(cntr->min_speed) * cntr->scale )) { /* not to long, estimate vel if a count arrived now */ @@ -527,11 +527,11 @@ static void capture(void *arg, long period) } hal_set_real(cntr->vel_rpm, hal_get_real(cntr->vel) * 60.0); /* compute net counts */ - hal_set_si32(cntr->count, cntr->raw_count - cntr->index_count); - hal_set_si32(cntr->count_latch, cntr->latch_count - cntr->index_count); + hal_set_sint(cntr->count, cntr->raw_count - cntr->index_count); + hal_set_sint(cntr->count_latch, cntr->latch_count - cntr->index_count); /* scale count to make floating point position */ - hal_set_real(cntr->pos, hal_get_si32(cntr->count) * cntr->scale); - hal_set_real(cntr->pos_latch, hal_get_si32(cntr->count_latch) * cntr->scale); + hal_set_real(cntr->pos, hal_get_sint(cntr->count) * cntr->scale); + hal_set_real(cntr->pos_latch, hal_get_sint(cntr->count_latch) * cntr->scale); /* add interpolation value */ delta_time = timebase - cntr->timestamp; interp = hal_get_real(cntr->vel) * (delta_time * 1e-9); @@ -604,19 +604,19 @@ static int export_encoder(counter_t * addr,char * prefix) } /* export parameter for raw counts */ - retval = hal_pin_new_si32(comp_id, HAL_OUT, &(addr->raw_counts), 0, + retval = hal_pin_new_sint(comp_id, HAL_OUT, &(addr->raw_counts), 0, "%s.rawcounts", prefix); if (retval != 0) { return retval; } /* export pin for counts captured by capture() */ - retval = hal_pin_new_si32(comp_id, HAL_OUT, &(addr->count), 0, + retval = hal_pin_new_sint(comp_id, HAL_OUT, &(addr->count), 0, "%s.counts", prefix); if (retval != 0) { return retval; } /* export pin for counts latched by capture() */ - retval = hal_pin_new_si32(comp_id, HAL_OUT, &(addr->count_latch), 0, + retval = hal_pin_new_sint(comp_id, HAL_OUT, &(addr->count_latch), 0, "%s.counts-latched", prefix); if (retval != 0) { return retval; @@ -676,7 +676,7 @@ static int export_encoder(counter_t * addr,char * prefix) return retval; } /* export pin for missing-tooth index */ - retval = hal_pin_new_si32(comp_id, HAL_IN, &(addr->missing_teeth), 0, + retval = hal_pin_new_sint(comp_id, HAL_IN, &(addr->missing_teeth), 0, "%s.missing-teeth", prefix); if (retval != 0) { return retval; @@ -686,13 +686,13 @@ static int export_encoder(counter_t * addr,char * prefix) #if 0 // These two, 'dt' and 'limit_dt' are used in the code and if they are // used, then they must be created to allocate storage. - retval = hal_param_new_si32(comp_id, HAL_RO, &(addr->dt), 0, + retval = hal_param_new_sint(comp_id, HAL_RO, &(addr->dt), 0, "%s.dt", prefix); if (retval != 0) { return retval; } - retval = hal_param_new_si32(comp_id, HAL_RO, &(addr->limit_dt), 0, + retval = hal_param_new_sint(comp_id, HAL_RO, &(addr->limit_dt), 0, "%s.limit_dt", prefix); if (retval != 0) { return retval; diff --git a/src/hal/components/encoder_ratio.c b/src/hal/components/encoder_ratio.c index 6e2b65b7bca..1dfbe3f3355 100644 --- a/src/hal/components/encoder_ratio.c +++ b/src/hal/components/encoder_ratio.c @@ -121,11 +121,11 @@ typedef struct { hal_bool_t slave_A; /* quadrature input */ hal_bool_t slave_B; /* quadrature input */ hal_bool_t enable; /* enable input */ - unsigned master_state; /* quad decode state machine state */ - unsigned slave_state; /* quad decode state machine state */ - int raw_error; /* internal data */ - int master_increment; /* internal data */ - int slave_increment; /* internal data */ + rtapi_uint master_state; /* quad decode state machine state */ + rtapi_uint slave_state; /* quad decode state machine state */ + rtapi_sint raw_error; /* internal data */ + rtapi_sint master_increment; /* internal data */ + rtapi_sint slave_increment; /* internal data */ double output_scale; /* internal data */ hal_real_t error; /* error output */ hal_uint_t master_ppr; /* parameter: master encoder PPR */ @@ -279,7 +279,7 @@ static void sample(void *arg, long period) (void)period; encoder_pair_t *pair; int n; - unsigned state; + rtapi_uint state; pair = arg; for (n = 0; n < howmany; n++) { @@ -346,9 +346,9 @@ static void update(void *arg, long period) } /* update scale factors (only needed if params change, but it's faster to do it every time than to detect changes.) */ - pair->master_increment = hal_get_ui32(pair->master_teeth) * hal_get_ui32(pair->slave_ppr); - pair->slave_increment = hal_get_ui32(pair->slave_teeth) * hal_get_ui32(pair->master_ppr); - pair->output_scale = hal_get_ui32(pair->master_ppr) * hal_get_ui32(pair->slave_ppr) * hal_get_ui32(pair->slave_teeth); + pair->master_increment = hal_get_uint(pair->master_teeth) * hal_get_uint(pair->slave_ppr); + pair->slave_increment = hal_get_uint(pair->slave_teeth) * hal_get_uint(pair->master_ppr); + pair->output_scale = hal_get_uint(pair->master_ppr) * hal_get_uint(pair->slave_ppr) * hal_get_uint(pair->slave_teeth); /* move on to next pair */ pair++; } @@ -405,22 +405,22 @@ static int export_encoder_pair(int num, encoder_pair_t * addr, char* prefix) return retval; } /* export pins for config info() */ - retval = hal_pin_new_ui32(comp_id, HAL_IO, &(addr->master_ppr), 0, + retval = hal_pin_new_uint(comp_id, HAL_IO, &(addr->master_ppr), 0, "%s.master-ppr", prefix); if (retval != 0) { return retval; } - retval = hal_pin_new_ui32(comp_id, HAL_IO, &(addr->slave_ppr), 0, + retval = hal_pin_new_uint(comp_id, HAL_IO, &(addr->slave_ppr), 0, "%s.slave-ppr", prefix); if (retval != 0) { return retval; } - retval = hal_pin_new_ui32(comp_id, HAL_IO, &(addr->master_teeth), 0, + retval = hal_pin_new_uint(comp_id, HAL_IO, &(addr->master_teeth), 0, "%s.master-teeth", prefix); if (retval != 0) { return retval; } - retval = hal_pin_new_ui32(comp_id, HAL_IO, &(addr->slave_teeth), 0, + retval = hal_pin_new_uint(comp_id, HAL_IO, &(addr->slave_teeth), 0, "%s.slave-teeth", prefix); if (retval != 0) { return retval; diff --git a/src/hal/components/lcd.c b/src/hal/components/lcd.c index 6c07c263a01..6dfb059bd51 100644 --- a/src/hal/components/lcd.c +++ b/src/hal/components/lcd.c @@ -47,7 +47,7 @@ typedef struct { typedef struct { lcd_page_t *pages; - unsigned num_pages; + rtapi_uint num_pages; hal_uint_t page_num; hal_uint_t out; hal_real_t contrast; @@ -165,7 +165,7 @@ int rtapi_app_main(void){ break; case 'u': case 'c': - retval = hal_pin_new_ui32(comp_id, HAL_IN, + retval = hal_pin_new_uint(comp_id, HAL_IN, &(inst->pages[p].args[a].u), 0, "lcd.%02i.page.%02i.arg.%02i", i, p, a); @@ -175,7 +175,7 @@ int rtapi_app_main(void){ break; case 's': - retval = hal_pin_new_si32(comp_id, HAL_IN, + retval = hal_pin_new_sint(comp_id, HAL_IN, &(inst->pages[p].args[a].s), 0, "lcd.%02i.page.%02i.arg.%02i", i, p, a); @@ -207,13 +207,13 @@ int rtapi_app_main(void){ } for (i = 0; i < lcd->num_insts; i++){ - retval = hal_pin_new_ui32(comp_id, HAL_IN, &(lcd->insts[i].page_num), 0, + retval = hal_pin_new_uint(comp_id, HAL_IN, &(lcd->insts[i].page_num), 0, "lcd.%02i.page_num", i); if (retval != 0) { return retval; } lcd->insts[i].last_page = -1; // force screen refresh - retval = hal_pin_new_ui32(comp_id, HAL_OUT, &(lcd->insts[i].out), 0, + retval = hal_pin_new_uint(comp_id, HAL_OUT, &(lcd->insts[i].out), 0, "lcd.%02i.out",i); if (retval != 0) { return retval; @@ -223,7 +223,7 @@ int rtapi_app_main(void){ if (retval != 0) { return retval; } - retval = hal_param_new_ui32(comp_id, HAL_RW, &(lcd->insts[i].dp), '.', + retval = hal_param_new_uint(comp_id, HAL_RW, &(lcd->insts[i].dp), '.', "lcd.%02i.decimal-separator",i); if (retval != 0) { return retval; @@ -276,18 +276,18 @@ static void write_one(lcd_inst_t *inst){ return;} if (inst->buff[inst->c_ptr] != 0){ - hal_set_ui32(inst->out, inst->buff[inst->c_ptr++]); + hal_set_uint(inst->out, inst->buff[inst->c_ptr++]); return; } inst->c_ptr = 0; inst->buff[0] = 0; - if (hal_get_ui32(inst->page_num) >= inst->num_pages) return; // should this error? + if (hal_get_uint(inst->page_num) >= inst->num_pages) return; // should this error? - if (hal_get_ui32(inst->page_num) != inst->last_page){ - inst->last_page = hal_get_ui32(inst->page_num); - hal_set_ui32(inst->out, 0x11); //cursor off + if (hal_get_uint(inst->page_num) != inst->last_page){ + inst->last_page = hal_get_uint(inst->page_num); + hal_set_uint(inst->out, 0x11); //cursor off inst->buff[0] = 0x1E; //cursor home inst->buff[1] = 0x1A; //clear screen inst->buff[2] = 0; // end @@ -297,8 +297,8 @@ static void write_one(lcd_inst_t *inst){ return; } - if (inst->f_ptr >= inst->pages[hal_get_ui32(inst->page_num)].length){ - hal_set_ui32(inst->out, 0x1B); // ESC + if (inst->f_ptr >= inst->pages[hal_get_uint(inst->page_num)].length){ + hal_set_uint(inst->out, 0x1B); // ESC inst->buff[0] = 0x3D; // = inst->buff[1] = 0x20; // Line 0 inst->buff[2] = 0x20; // Column 0 @@ -314,7 +314,7 @@ static void write_one(lcd_inst_t *inst){ if (c > 0xBF) c = 0xBF; if (c < 0x20) c = 0x20; inst->last_contrast = hal_get_real(inst->contrast); - hal_set_ui32(inst->out, 0x1B); + hal_set_uint(inst->out, 0x1B); inst->buff[0] = 'C'; inst->buff[1] = c; inst->buff[2] = 0; @@ -322,9 +322,9 @@ static void write_one(lcd_inst_t *inst){ return; } - switch (inst->pages[hal_get_ui32(inst->page_num)].fmt[inst->f_ptr]){ + switch (inst->pages[hal_get_uint(inst->page_num)].fmt[inst->f_ptr]){ case '\\': //escape chars - c1 = inst->pages[hal_get_ui32(inst->page_num)].fmt[++inst->f_ptr]; + c1 = inst->pages[hal_get_uint(inst->page_num)].fmt[++inst->f_ptr]; switch (c1){ case 'n': case 'N': @@ -350,7 +350,7 @@ static void write_one(lcd_inst_t *inst){ /* Fallthrough */ default: //check for hex - c2 = inst->pages[hal_get_ui32(inst->page_num)].fmt[++inst->f_ptr]; + c2 = inst->pages[hal_get_uint(inst->page_num)].fmt[++inst->f_ptr]; inst->f_ptr++; if (c1 > '9') c1 &= 0xDF; //upper case if (c2 > '9') c2 &= 0xDF; @@ -362,24 +362,24 @@ static void write_one(lcd_inst_t *inst){ inst->buff[0] = 0; } } - hal_set_ui32(inst->out, inst->buff[0]); + hal_set_uint(inst->out, inst->buff[0]); inst->c_ptr = 1; return; case '%': - retval = parse_fmt(inst->pages[hal_get_ui32(inst->page_num)].fmt, + retval = parse_fmt(inst->pages[hal_get_uint(inst->page_num)].fmt, &inst->f_ptr, inst->buff, - &(inst->pages[hal_get_ui32(inst->page_num)].args[inst->a_ptr++]), - (char)hal_get_ui32(inst->dp)); + &(inst->pages[hal_get_uint(inst->page_num)].args[inst->a_ptr++]), + (char)hal_get_uint(inst->dp)); if (retval >= 0) { - hal_set_ui32(inst->out, inst->buff[0]); + hal_set_uint(inst->out, inst->buff[0]); inst->c_ptr = 1; inst->f_ptr++; return; } /* Fallthrough */ default: - hal_set_ui32(inst->out, inst->pages[hal_get_ui32(inst->page_num)].fmt[inst->f_ptr++]); + hal_set_uint(inst->out, inst->pages[hal_get_uint(inst->page_num)].fmt[inst->f_ptr++]); } } @@ -473,9 +473,9 @@ static int parse_fmt(char *in, int *ptr, char *out, hal_refs_u *val, char dp){ case 'u': if (out == NULL || val == NULL) return 'u'; { - unsigned int tmp; + rtapi_uint tmp; int i; - unsigned int v = hal_get_ui32(val->u); + rtapi_uint v = hal_get_uint(val->u); if (c < 1) c = num_digits_baseN(v, base); @@ -501,16 +501,17 @@ static int parse_fmt(char *in, int *ptr, char *out, hal_refs_u *val, char dp){ case 'i': if (out == NULL || val == NULL) return 's'; { - int tmp, s = 0; + rtapi_sint tmp; + int s = 0; int i; - int v = hal_get_si32(val->s); + rtapi_sint v = hal_get_sint(val->s); if (sgn == '+') s = 1; if (v < 0) {s = 1; sgn = '-'; v = -v;} if (c < 1) c = num_digits_baseN(v, base) + s; - tmp = abs(v); + tmp = v < 0 ? -v : v; for (i = c - 1; i >= s; i--){ if (tmp != 0 || i == c - 1){ out[i] = digits[tmp % 10]; @@ -607,7 +608,7 @@ static int parse_fmt(char *in, int *ptr, char *out, hal_refs_u *val, char dp){ if (out == NULL || val == NULL) return 'c'; { int i; - unsigned char v = hal_get_ui32(val->u); + unsigned char v = hal_get_uint(val->u) & 0xff; if (c == 0) c = 1; for (i = 0; i < c; i++){ diff --git a/src/hal/components/matrix_kb.c b/src/hal/components/matrix_kb.c index 1d49516ee09..ba2036d15f9 100644 --- a/src/hal/components/matrix_kb.c +++ b/src/hal/components/matrix_kb.c @@ -45,8 +45,8 @@ typedef struct { char name[HAL_NAME_LEN + 1]; struct input_dev *key_dev; rtapi_u32 index; - unsigned keydown; - unsigned keyup; + rtapi_uint keydown; + rtapi_uint keyup; unsigned rowshift; unsigned row; unsigned num_keys; @@ -69,10 +69,10 @@ RTAPI_MP_ARRAY_STRING(names, MAX_CHAN, "component names"); void keyup(kb_inst_t *inst){ unsigned r, c; - unsigned keycode = hal_get_ui32(inst->hal.keycode) & ~(inst->keydown | inst->keyup); + rtapi_uint keycode = hal_get_uint(inst->hal.keycode) & ~(inst->keydown | inst->keyup); r = keycode >> inst->rowshift; - c = keycode & ~(0xFFFFFFFF << inst->rowshift); + c = keycode & ((1ul << inst->rowshift) - 1); if ( r >= inst->nrows || c >= inst->ncols @@ -86,10 +86,10 @@ void keyup(kb_inst_t *inst){ } void keydown(kb_inst_t *inst){ unsigned r, c; - unsigned keycode = hal_get_ui32(inst->hal.keycode) & ~(inst->keydown | inst->keyup); + rtapi_uint keycode = hal_get_uint(inst->hal.keycode) & ~(inst->keydown | inst->keyup); r = keycode >> inst->rowshift; - c = keycode & ~(0xFFFFFFFF << inst->rowshift); + c = keycode & ((1ul << inst->rowshift) - 1); if ( r >= inst->nrows || c >= inst->ncols @@ -97,7 +97,7 @@ void keydown(kb_inst_t *inst){ return; } - if (inst->num_keys >= hal_get_ui32(inst->param.rollover)) return; + if (inst->num_keys >= hal_get_uint(inst->param.rollover)) return; inst->num_keys++; hal_set_bool(inst->hal.key[r * inst->ncols + c], 1); @@ -118,13 +118,13 @@ void loop(void *arg, long period){ for (c = 0; c < inst->ncols; c++){ int mask = 1 << c; if ((inst->then[inst->row] & mask) && !(scan & mask)){ //keyup - hal_set_ui32(inst->hal.keycode, inst->keyup + hal_set_uint(inst->hal.keycode, inst->keyup + (inst->row << inst->rowshift) + c); keyup(inst); } else if (!(inst->then[inst->row] & mask) && (scan & mask)){//keydown - hal_set_ui32(inst->hal.keycode, inst->keydown + hal_set_uint(inst->hal.keycode, inst->keydown + (inst->row << inst->rowshift) + c); @@ -133,7 +133,7 @@ void loop(void *arg, long period){ } } else { - hal_set_ui32(inst->hal.keycode, 0x40);//nochange + hal_set_uint(inst->hal.keycode, 0x40);//nochange } inst->then[inst->row] = inst->now[inst->row]; @@ -146,7 +146,7 @@ void loop(void *arg, long period){ } else { - rtapi_u32 keycode = hal_get_ui32(inst->hal.keycode); + rtapi_uint keycode = hal_get_uint(inst->hal.keycode); if (keycode == 0x40) return; if ((keycode & inst->keydown) == inst->keydown){ keydown(inst); @@ -293,7 +293,7 @@ int rtapi_app_main(void){ } } - retval = hal_pin_new_ui32(comp_id, HAL_OUT, + retval = hal_pin_new_uint(comp_id, HAL_OUT, &(inst->hal.keycode), 0, "%s.keycode",inst->name); if (retval != 0) { @@ -314,7 +314,7 @@ int rtapi_app_main(void){ } - retval = hal_param_new_ui32(comp_id, HAL_RW, + retval = hal_param_new_uint(comp_id, HAL_RW, &(inst->param.rollover), 2, "%s.key_rollover",inst->name); if (retval != 0) { @@ -327,7 +327,7 @@ int rtapi_app_main(void){ } else // scanning by 7i73 or similar { - retval = hal_pin_new_ui32(comp_id, HAL_IN, + retval = hal_pin_new_uint(comp_id, HAL_IN, &(inst->hal.keycode), 0, "%s.keycode",inst->name); if (retval != 0) { diff --git a/src/hal/components/modmath.c b/src/hal/components/modmath.c index c24ca3608e2..0714487a3c3 100644 --- a/src/hal/components/modmath.c +++ b/src/hal/components/modmath.c @@ -118,20 +118,20 @@ static void mod_dir_funct(void *arg, long period) (void)period; mod_dir_t *mod = (mod_dir_t *)arg; /* point to block data */ - rtapi_s32 min_num = hal_get_si32(mod->min_num); - rtapi_s32 max_num = hal_get_si32(mod->max_num); + rtapi_sint min_num = hal_get_sint(mod->min_num); + rtapi_sint max_num = hal_get_sint(mod->max_num); - rtapi_s32 range = max_num - min_num + 1; - rtapi_s32 act = hal_get_si32(mod->actual); + rtapi_sint range = max_num - min_num + 1; + rtapi_sint act = hal_get_sint(mod->actual); if (act > max_num || act < min_num) { act = min_num + ((act-min_num) % (range)); } - rtapi_s32 des = hal_get_si32(mod->desired); + rtapi_sint des = hal_get_sint(mod->desired); if (des > max_num || des < min_num) { des = min_num + ((des-min_num) % (range)); } - rtapi_s32 to_go = des-act; + rtapi_sint to_go = des-act; if ((hal_get_bool(mod->wrap)) && (to_go > range/2)) { to_go -= range; @@ -187,12 +187,12 @@ static int export_mod_dir(int num) CHK(hal_pin_new_bool(comp_id, HAL_OUT, &(moddir->on_target), 1, "%s.on-target", base), "on-target"); /* export input pins */ - CHK(hal_pin_new_si32(comp_id, HAL_IN, &(moddir->actual), 0, "%s.actual", base), "actual"); - CHK(hal_pin_new_si32(comp_id, HAL_IN, &(moddir->desired), 0, "%s.desired", base), "desired"); + CHK(hal_pin_new_sint(comp_id, HAL_IN, &(moddir->actual), 0, "%s.actual", base), "actual"); + CHK(hal_pin_new_sint(comp_id, HAL_IN, &(moddir->desired), 0, "%s.desired", base), "desired"); /* export pins for max and min values */ - CHK(hal_pin_new_si32(comp_id, HAL_IO, &(moddir->min_num), 0, "%s.min-num", base), "min-num"); - CHK(hal_pin_new_si32(comp_id, HAL_IO, &(moddir->max_num), 15, "%s.max-num", base), "max-num"); + CHK(hal_pin_new_sint(comp_id, HAL_IO, &(moddir->min_num), 0, "%s.min-num", base), "min-num"); + CHK(hal_pin_new_sint(comp_id, HAL_IO, &(moddir->max_num), 15, "%s.max-num", base), "max-num"); CHK(hal_pin_new_bool(comp_id, HAL_IO, &(moddir->wrap), 1, "%s.wrap", base), "wrap"); /* export function */ diff --git a/src/hal/components/pid.c b/src/hal/components/pid.c index fb0b7c87f61..9bdf2d26299 100644 --- a/src/hal/components/pid.c +++ b/src/hal/components/pid.c @@ -244,8 +244,8 @@ typedef struct { /* Private data */ State state; - rtapi_u32 cycleCount; - rtapi_u32 cyclePeriod; + rtapi_uint cycleCount; + rtapi_uint cyclePeriod; rtapi_real cycleAmplitude; rtapi_real totalTime; rtapi_real avgAmplitude; @@ -350,7 +350,7 @@ static void Pid_CycleEnd(hal_pid_t *pid) { pid->cycleCount++; - pid->avgAmplitude += pid->cycleAmplitude / hal_get_ui32(pid->tuneCycles); + pid->avgAmplitude += pid->cycleAmplitude / hal_get_uint(pid->tuneCycles); pid->cycleAmplitude = 0; pid->totalTime += pid->cyclePeriod * 0.000000001; pid->cyclePeriod = 0; @@ -440,16 +440,16 @@ Pid_AutoTune(hal_pid_t *pid, long period) // Check if the last cycle just ended. This is really the number // of half cycles. - if(pid->cycleCount < hal_get_ui32(pid->tuneCycles)) + if(pid->cycleCount < hal_get_uint(pid->tuneCycles)) break; // Calculate PID using Relay (Åström-Hägglund) method hal_set_real(pid->ultimateGain, (4.0 * fabs(hal_get_real(pid->tuneEffort)))/(PI * pid->avgAmplitude)); - hal_set_real(pid->ultimatePeriod, 2.0 * pid->totalTime / hal_get_ui32(pid->tuneCycles)); + hal_set_real(pid->ultimatePeriod, 2.0 * pid->totalTime / hal_get_uint(pid->tuneCycles)); hal_set_real(pid->ff0gain, 0); hal_set_real(pid->ff2gain, 0); - if(hal_get_ui32(pid->tuneType) == TYPE_PID){ + if(hal_get_uint(pid->tuneType) == TYPE_PID){ // insert ultimate gain and period in Ziegler-Nichols PID method hal_set_real(pid->pgain, 0.6 * hal_get_real(pid->ultimateGain)); hal_set_real(pid->igain, 1.2 * hal_get_real(pid->ultimateGain) / (hal_get_real(pid->ultimatePeriod))); @@ -677,12 +677,16 @@ static void calc_pid(void *arg, long period) if(pid->limit_state) { hal_set_bool(pid->saturated, 1); hal_set_real(pid->saturated_s, hal_get_real(pid->saturated_s) + period * 1e-9); - if(hal_get_si32(pid->saturated_count) != 2147483647) - hal_set_si32(pid->saturated_count, hal_get_si32(pid->saturated_count) + 1); + // FIXME: This comparison can now be extended to 2**63-1, but should we? + // It can also be removed... + // The time it takes to reach the top would be more than the Universe + // has existed if we counted nanoseconds. + if(hal_get_sint(pid->saturated_count) != 2147483647) + hal_set_sint(pid->saturated_count, hal_get_sint(pid->saturated_count) + 1); } else { hal_set_bool(pid->saturated, 0); hal_set_real(pid->saturated_s, 0); - hal_set_si32(pid->saturated_count, 0); + hal_set_sint(pid->saturated_count, 0); } /* done */ } @@ -722,7 +726,7 @@ static int export_pid(hal_pid_t * addr, char * prefix) CHK(hal_pin_new_real(comp_id, HAL_OUT, &(addr->output), 0.0, "%s.output", prefix)); CHK(hal_pin_new_bool(comp_id, HAL_OUT, &(addr->saturated), 0, "%s.saturated", prefix)); CHK(hal_pin_new_real(comp_id, HAL_OUT, &(addr->saturated_s), 0.0, "%s.saturated-s", prefix)); - CHK(hal_pin_new_si32(comp_id, HAL_OUT, &(addr->saturated_count), 0, "%s.saturated-count", prefix)); + CHK(hal_pin_new_sint(comp_id, HAL_OUT, &(addr->saturated_count), 0, "%s.saturated-count", prefix)); CHK(hal_pin_new_real(comp_id, HAL_IN, &(addr->pgain), 1.0, "%s.Pgain", prefix)); CHK(hal_pin_new_real(comp_id, HAL_IN, &(addr->igain), 0.0, "%s.Igain", prefix)); CHK(hal_pin_new_real(comp_id, HAL_IN, &(addr->dgain), 0.0, "%s.Dgain", prefix)); @@ -745,8 +749,8 @@ static int export_pid(hal_pid_t * addr, char * prefix) #ifdef AUTO_TUNER /* Auto tune related */ CHK(hal_pin_new_real(comp_id, HAL_IO, &(addr->tuneEffort), 0.5, "%s.tune-effort", prefix)); - CHK(hal_pin_new_ui32(comp_id, HAL_IO, &(addr->tuneCycles), 50, "%s.tune-cycles", prefix)); - CHK(hal_pin_new_ui32(comp_id, HAL_IO, &(addr->tuneType), TYPE_PID, "%s.tune-type", prefix)); + CHK(hal_pin_new_uint(comp_id, HAL_IO, &(addr->tuneCycles), 50, "%s.tune-cycles", prefix)); + CHK(hal_pin_new_uint(comp_id, HAL_IO, &(addr->tuneType), TYPE_PID, "%s.tune-type", prefix)); CHK(hal_pin_new_bool(comp_id, HAL_IN, &(addr->pTuneMode), 0, "%s.tune-mode", prefix)); CHK(hal_pin_new_bool(comp_id, HAL_IO, &(addr->pTuneStart), 0, "%s.tune-start", prefix)); #endif /* AUTO_TUNER */ diff --git a/src/hal/components/sampler.c b/src/hal/components/sampler.c index 9d273a4993f..34e84bfc412 100644 --- a/src/hal/components/sampler.c +++ b/src/hal/components/sampler.c @@ -157,7 +157,7 @@ static void sample(void *arg, long period) /* are we enabled? */ if (!hal_get_bool(samp->enable)) { - hal_set_si32(samp->curr_depth, hal_stream_depth(&samp->fifo)); + hal_set_sint(samp->curr_depth, hal_stream_depth(&samp->fifo)); hal_set_bool(samp->full, !hal_stream_writable(&samp->fifo)); return; } @@ -178,12 +178,12 @@ static void sample(void *arg, long period) if ( hal_stream_write(&samp->fifo, data) < 0) { /* fifo is full, data is lost */ /* log the overrun */ - hal_set_si32(samp->overruns, hal_get_si32(samp->overruns) + 1); + hal_set_sint(samp->overruns, hal_get_sint(samp->overruns) + 1); hal_set_bool(samp->full, 1); - hal_set_si32(samp->curr_depth, hal_stream_maxdepth(&samp->fifo)); + hal_set_sint(samp->curr_depth, hal_stream_maxdepth(&samp->fifo)); } else { hal_set_bool(samp->full, 0); - hal_set_si32(samp->curr_depth, hal_stream_depth(&samp->fifo)); + hal_set_sint(samp->curr_depth, hal_stream_depth(&samp->fifo)); } } @@ -207,17 +207,17 @@ static int init_sampler(int num, sampler_t *str) rtapi_print_msg(RTAPI_MSG_ERR, "SAMPLER: ERROR: 'enable' pin export failed\n"); return -EIO; } - retval = hal_pin_new_si32(comp_id, HAL_OUT, &str->curr_depth, 0, "%s%d.curr-depth", strbase, num); + retval = hal_pin_new_sint(comp_id, HAL_OUT, &str->curr_depth, 0, "%s%d.curr-depth", strbase, num); if (retval != 0 ) { rtapi_print_msg(RTAPI_MSG_ERR, "SAMPLER: ERROR: 'curr_depth' pin export failed\n"); return -EIO; } - retval = hal_pin_new_si32(comp_id, HAL_IO, &str->overruns, 0, "%s%d.overruns", strbase, num); + retval = hal_pin_new_sint(comp_id, HAL_IO, &str->overruns, 0, "%s%d.overruns", strbase, num); if (retval != 0 ) { rtapi_print_msg(RTAPI_MSG_ERR, "SAMPLER: ERROR: 'overruns' parameter export failed\n"); return -EIO; } - retval = hal_pin_new_si32(comp_id, HAL_IO, &str->sample_num, 0, "%s%d.sample-num", strbase, num); + retval = hal_pin_new_sint(comp_id, HAL_IO, &str->sample_num, 0, "%s%d.sample-num", strbase, num); if (retval != 0 ) { rtapi_print_msg(RTAPI_MSG_ERR, "SAMPLER: ERROR: 'sample-num' parameter export failed\n"); return -EIO; diff --git a/src/hal/components/sim_encoder.c b/src/hal/components/sim_encoder.c index 1e02030b178..fc9802b9c13 100644 --- a/src/hal/components/sim_encoder.c +++ b/src/hal/components/sim_encoder.c @@ -257,7 +257,7 @@ static void make_pulses(void *arg, long period) /* get direction bit, 1 if negative, 0 if positive */ dir = sim_enc->addval >> 31; if ( dir ) { - hal_set_si32(sim_enc->rawcounts, hal_get_si32(sim_enc->rawcounts) - 1); + hal_set_sint(sim_enc->rawcounts, hal_get_sint(sim_enc->rawcounts) - 1); /* negative rotation, decrement state, detect underflow */ if (--(sim_enc->state) < 0) { /* state underflow, roll over */ @@ -265,19 +265,19 @@ static void make_pulses(void *arg, long period) /* decrement cycle, detect underflow */ if (--(sim_enc->cycle) < 0) { /* cycle underflow, roll over */ - sim_enc->cycle += hal_get_ui32(sim_enc->ppr); + sim_enc->cycle += hal_get_uint(sim_enc->ppr); } } } else { - hal_set_si32(sim_enc->rawcounts, hal_get_si32(sim_enc->rawcounts) + 1); + hal_set_sint(sim_enc->rawcounts, hal_get_sint(sim_enc->rawcounts) + 1); /* positive rotation, increment state, detect overflow */ if (++(sim_enc->state) > 3) { /* state overflow, roll over */ sim_enc->state = 0; /* increment cycle, detect overflow */ - if (++(sim_enc->cycle) >= hal_get_ui32(sim_enc->ppr)) { + if (++(sim_enc->cycle) >= (long)hal_get_uint(sim_enc->ppr)) { /* cycle overflow, roll over */ - sim_enc->cycle -= hal_get_ui32(sim_enc->ppr); + sim_enc->cycle -= hal_get_uint(sim_enc->ppr); } } } @@ -348,7 +348,7 @@ static void update_speed(void *arg, long period) /* convert speed command (user units) to revs/sec */ rev_sec = hal_get_real(sim_enc->speed) * sim_enc->scale_mult; /* convert speed command (revs per sec) to counts/sec */ - freq = rev_sec * (hal_get_ui32(sim_enc->ppr)) * 4.0; + freq = rev_sec * (hal_get_uint(sim_enc->ppr)) * 4.0; /* limit the commanded frequency */ if (freq > maxf) { freq = maxf; @@ -377,7 +377,7 @@ static int export_sim_enc(sim_enc_t * addr, char *prefix) msg = rtapi_get_msg_level(); rtapi_set_msg_level(RTAPI_MSG_WARN); /* export param variable for pulses per rev */ - retval = hal_pin_new_ui32(comp_id, HAL_IO, &(addr->ppr), 100, + retval = hal_pin_new_uint(comp_id, HAL_IO, &(addr->ppr), 100, "%s.ppr", prefix); if (retval != 0) { return retval; @@ -411,7 +411,7 @@ static int export_sim_enc(sim_enc_t * addr, char *prefix) return retval; } /* export pin for rawcounts */ - retval = hal_pin_new_si32(comp_id, HAL_IN, &(addr->rawcounts), 0, + retval = hal_pin_new_sint(comp_id, HAL_IN, &(addr->rawcounts), 0, "%s.rawcounts", prefix); if (retval != 0) { return retval; diff --git a/src/hal/components/streamer.c b/src/hal/components/streamer.c index 12b2d363abf..73749257542 100644 --- a/src/hal/components/streamer.c +++ b/src/hal/components/streamer.c @@ -176,7 +176,7 @@ static void update(void *arg, long period) /* are we enabled? - generate doclock if enabled and right mode */ if (hal_get_bool(str->enable)) { doclk = 1; - switch (hal_get_si32(str->clock_mode)) { + switch (hal_get_sint(str->clock_mode)) { /* clock-mode 0 means do clock if enabled */ case 0: break; @@ -204,19 +204,19 @@ static void update(void *arg, long period) } /* point at user/RT fifo in other shmem */ int depth = hal_stream_depth(&str->fifo); - hal_set_si32(str->curr_depth, depth); + hal_set_sint(str->curr_depth, depth); hal_set_bool(str->empty, depth == 0); if(!doclk) return; /* done - output pins retain current values */ if(depth == 0) { /* increase underrun only for valid clock*/ - hal_set_si32(str->underruns, hal_get_si32(str->underruns) + 1); + hal_set_sint(str->underruns, hal_get_sint(str->underruns) + 1); return; } union hal_stream_data data[HAL_STREAM_MAX_PINS]; if(hal_stream_read(&str->fifo, data, NULL) < 0) { /* should not happen (single reader invariant) */ - hal_set_si32(str->underruns, hal_get_si32(str->underruns) + 1); + hal_set_sint(str->underruns, hal_get_sint(str->underruns) + 1); return; } int num_pins = hal_stream_element_count(&str->fifo); @@ -248,12 +248,12 @@ static int init_streamer(int num, streamer_t *str) rtapi_print_msg(RTAPI_MSG_ERR, "STREAMER: ERROR: 'enable' pin export failed\n"); return -EIO; } - retval = hal_pin_new_si32(comp_id, HAL_OUT, &str->curr_depth, 0, "%s%d.curr-depth", strbase, num); + retval = hal_pin_new_sint(comp_id, HAL_OUT, &str->curr_depth, 0, "%s%d.curr-depth", strbase, num); if (retval != 0 ) { rtapi_print_msg(RTAPI_MSG_ERR, "STREAMER: ERROR: 'curr_depth' pin export failed\n"); return -EIO; } - retval = hal_pin_new_si32(comp_id, HAL_IO, &str->underruns, 0, "%s%d.underruns", strbase, num); + retval = hal_pin_new_sint(comp_id, HAL_IO, &str->underruns, 0, "%s%d.underruns", strbase, num); if (retval != 0 ) { rtapi_print_msg(RTAPI_MSG_ERR, "STREAMER: ERROR: 'underruns' pin export failed\n"); return -EIO; @@ -263,7 +263,7 @@ static int init_streamer(int num, streamer_t *str) rtapi_print_msg(RTAPI_MSG_ERR, "STREAMER: ERROR: 'clock' pin export failed\n"); return -EIO; } - retval = hal_pin_new_si32(comp_id, HAL_IN, &str->clock_mode, 0, "%s%d.clock-mode", strbase, num); + retval = hal_pin_new_sint(comp_id, HAL_IN, &str->clock_mode, 0, "%s%d.clock-mode", strbase, num); if (retval != 0 ) { rtapi_print_msg(RTAPI_MSG_ERR, "STREAMER: ERROR: 'clock_mode' pin export failed\n"); return -EIO; diff --git a/src/hal/drivers/mesa-hostmot2/hm2_modbus.c b/src/hal/drivers/mesa-hostmot2/hm2_modbus.c index 01b982cc5e9..fd4a8e64970 100644 --- a/src/hal/drivers/mesa-hostmot2/hm2_modbus.c +++ b/src/hal/drivers/mesa-hostmot2/hm2_modbus.c @@ -371,7 +371,7 @@ static void setup_icdelay(hm2_modbus_inst_t *inst, unsigned baudrate, unsigned p } else { inst->maxicharbits = 0; } - hal_set_ui32(inst->hal->icdelay, inst->maxicharbits); + hal_set_uint(inst->hal->icdelay, inst->maxicharbits); } // @@ -440,12 +440,12 @@ static int send_comms_change(hm2_modbus_inst_t *inst) inst->cfg_tx.drivedelay = cc->cmd.idrvdelay ? cc->cmd.idrvdelay : 1; // Expose to HAL - hal_set_ui32(inst->hal->baudrate, baudrate); - hal_set_ui32(inst->hal->parity, parity); - hal_set_ui32(inst->hal->stopbits, stopbits); - hal_set_ui32(inst->hal->rxdelay, inst->cfg_rx.ifdelay); - hal_set_ui32(inst->hal->txdelay, inst->cfg_tx.ifdelay); - hal_set_ui32(inst->hal->drvdelay, inst->cfg_tx.drivedelay); + hal_set_uint(inst->hal->baudrate, baudrate); + hal_set_uint(inst->hal->parity, parity); + hal_set_uint(inst->hal->stopbits, stopbits); + hal_set_uint(inst->hal->rxdelay, inst->cfg_rx.ifdelay); + hal_set_uint(inst->hal->txdelay, inst->cfg_tx.ifdelay); + hal_set_uint(inst->hal->drvdelay, inst->cfg_tx.drivedelay); // Redo the inter-character delay settings setup_icdelay(inst, baudrate, parity, stopbits, cc->cmd.iicdelay); @@ -461,17 +461,17 @@ static void set_error(hm2_modbus_inst_t *inst, int errcode) if(handling_inits(inst)) { // No individual pins for init commands, use global hal_set_bool(inst->hal->fault, 1); - hal_set_ui32(inst->hal->faultcmd, inst->cmdidx); - hal_set_ui32(inst->hal->lasterror, errcode); + hal_set_uint(inst->hal->faultcmd, inst->cmdidx); + hal_set_uint(inst->hal->lasterror, errcode); return; } hm2_modbus_cmd_t *cc = current_cmd(inst); if(++cc->errors >= MAX_ERRORS || cc->disabled) { cc->disabled = 1; hal_set_bool(inst->hal->cmds[inst->cmdidx].disabled, 1); - hal_set_ui32(inst->hal->cmds[inst->cmdidx].errorcode, errcode); + hal_set_uint(inst->hal->cmds[inst->cmdidx].errorcode, errcode); } - hal_set_ui32(inst->hal->cmds[inst->cmdidx].error, cc->errors); + hal_set_uint(inst->hal->cmds[inst->cmdidx].error, cc->errors); } // @@ -619,8 +619,8 @@ static inline int next_command(hm2_modbus_inst_t *inst) inst->cmds[i].disabled = 0; inst->cmds[i].errors = 0; hal_set_bool(inst->hal->cmds[i].disabled, 0); - hal_set_ui32(inst->hal->cmds[i].error, 0); - hal_set_ui32(inst->hal->cmds[i].errorcode, 0); + hal_set_uint(inst->hal->cmds[i].error, 0); + hal_set_uint(inst->hal->cmds[i].errorcode, 0); // Honor the writeflush flag when coming out of disable. write_flush_cmd(inst, i); } @@ -635,8 +635,8 @@ static inline int next_command(hm2_modbus_inst_t *inst) inst->cmds[i].disabled = 1; inst->cmds[i].errors = 0; hal_set_bool(inst->hal->cmds[i].disabled, 1); - hal_set_ui32(inst->hal->cmds[i].error, 0); - hal_set_ui32(inst->hal->cmds[i].errorcode, EAGAIN); + hal_set_uint(inst->hal->cmds[i].error, 0); + hal_set_uint(inst->hal->cmds[i].errorcode, EAGAIN); } } } while(inst->cmdidx < inst->ncmds && inst->cmds[inst->cmdidx].disabled); @@ -721,9 +721,9 @@ static void do_timeout(hm2_modbus_inst_t *inst) MSG_DBG("Timeout reset cmd=%u %s(%d)\n", inst->cmdidx, state_names[inst->state], inst->state); force_resend(inst); queue_reset(inst); - hal_set_ui32(inst->hal->lasterror, ETIMEDOUT); + hal_set_uint(inst->hal->lasterror, ETIMEDOUT); hal_set_bool(inst->hal->fault, 1); - hal_set_ui32(inst->hal->faultcmd, inst->cmdidx); + hal_set_uint(inst->hal->faultcmd, inst->cmdidx); set_error(inst, ETIMEDOUT); set_state(inst, STATE_START); } @@ -782,8 +782,8 @@ static void process(void *arg, long period) hal_set_bool(inst->hal->cmds[i].disabled, 0); write_flush_cmd(inst, i); } - hal_set_ui32(inst->hal->cmds[i].errorcode, 0); - hal_set_ui32(inst->hal->cmds[i].error, 0); + hal_set_uint(inst->hal->cmds[i].errorcode, 0); + hal_set_uint(inst->hal->cmds[i].error, 0); inst->cmds[i].errors = 0; } } @@ -864,9 +864,9 @@ static void process(void *arg, long period) // If the next command is again the first, then we have no // messages we can send. if(next_command(inst)) { - hal_set_ui32(inst->hal->lasterror, ENODATA); + hal_set_uint(inst->hal->lasterror, ENODATA); hal_set_bool(inst->hal->fault, 1); - hal_set_ui32(inst->hal->faultcmd, 0); + hal_set_uint(inst->hal->faultcmd, 0); break; } } @@ -1098,8 +1098,8 @@ static void process(void *arg, long period) default: MSG_ERR("%s: error: Unknown state (%d) in process(), setting START state\n", inst->name, inst->state); hal_set_bool(inst->hal->fault, 1); - hal_set_ui32(inst->hal->lasterror, EINVAL); - hal_set_ui32(inst->hal->faultcmd, inst->cmdidx); + hal_set_uint(inst->hal->lasterror, EINVAL); + hal_set_uint(inst->hal->faultcmd, inst->cmdidx); set_state(inst, STATE_START); break; } @@ -2698,21 +2698,21 @@ int rtapi_app_main(void) goto errout; \ } \ } while(0) - CHECK(hal_param_new_ui32(comp_id, HAL_RO, &(inst->hal->baudrate), 0, "%s.baudrate", inst->name)); - CHECK(hal_param_new_ui32(comp_id, HAL_RO, &(inst->hal->parity), 0, "%s.parity", inst->name)); - CHECK(hal_param_new_ui32(comp_id, HAL_RO, &(inst->hal->stopbits), 0, "%s.stopbits", inst->name)); - CHECK(hal_param_new_ui32(comp_id, HAL_RO, &(inst->hal->icdelay), 0, "%s.icdelay", inst->name)); - CHECK(hal_param_new_ui32(comp_id, HAL_RO, &(inst->hal->txdelay), 0, "%s.txdelay", inst->name)); - CHECK(hal_param_new_ui32(comp_id, HAL_RO, &(inst->hal->rxdelay), 0, "%s.rxdelay", inst->name)); - CHECK(hal_param_new_ui32(comp_id, HAL_RO, &(inst->hal->drvdelay), 0, "%s.drivedelay", inst->name)); + CHECK(hal_param_new_uint(comp_id, HAL_RO, &(inst->hal->baudrate), 0, "%s.baudrate", inst->name)); + CHECK(hal_param_new_uint(comp_id, HAL_RO, &(inst->hal->parity), 0, "%s.parity", inst->name)); + CHECK(hal_param_new_uint(comp_id, HAL_RO, &(inst->hal->stopbits), 0, "%s.stopbits", inst->name)); + CHECK(hal_param_new_uint(comp_id, HAL_RO, &(inst->hal->icdelay), 0, "%s.icdelay", inst->name)); + CHECK(hal_param_new_uint(comp_id, HAL_RO, &(inst->hal->txdelay), 0, "%s.txdelay", inst->name)); + CHECK(hal_param_new_uint(comp_id, HAL_RO, &(inst->hal->rxdelay), 0, "%s.rxdelay", inst->name)); + CHECK(hal_param_new_uint(comp_id, HAL_RO, &(inst->hal->drvdelay), 0, "%s.drivedelay", inst->name)); CHECK(hal_pin_new_bool(comp_id, HAL_IN, &(inst->hal->suspend), 0, "%s.suspend", inst->name)); CHECK(hal_pin_new_bool(comp_id, HAL_IN, &(inst->hal->reset), 0, "%s.reset", inst->name)); CHECK(hal_pin_new_bool(comp_id, HAL_OUT, &(inst->hal->fault), 0, "%s.fault", inst->name)); - CHECK(hal_pin_new_ui32(comp_id, HAL_OUT, &(inst->hal->faultcmd), 0, "%s.fault-command", inst->name)); - CHECK(hal_pin_new_ui32(comp_id, HAL_OUT, &(inst->hal->lasterror), 0, "%s.last-error-code", inst->name)); + CHECK(hal_pin_new_uint(comp_id, HAL_OUT, &(inst->hal->faultcmd), 0, "%s.fault-command", inst->name)); + CHECK(hal_pin_new_uint(comp_id, HAL_OUT, &(inst->hal->lasterror), 0, "%s.last-error-code", inst->name)); - hal_set_ui32(inst->hal->baudrate, inst->cfg_rx.baudrate = inst->cfg_tx.baudrate = inst->mbccb->baudrate); + hal_set_uint(inst->hal->baudrate, inst->cfg_rx.baudrate = inst->cfg_tx.baudrate = inst->mbccb->baudrate); unsigned parity = 0; if(inst->mbccb->format & MBCCB_FORMAT_PARITYEN) { inst->cfg_rx.flags |= HM2_PKTUART_CONFIG_PARITYEN; @@ -2730,22 +2730,22 @@ int rtapi_app_main(void) inst->cfg_tx.flags |= HM2_PKTUART_CONFIG_STOPBITS2; stopbits = 2; } - hal_set_ui32(inst->hal->parity, parity); - hal_set_ui32(inst->hal->stopbits, stopbits); + hal_set_uint(inst->hal->parity, parity); + hal_set_uint(inst->hal->stopbits, stopbits); if(!inst->mbccb->rxdelay) // Auto - inst->cfg_rx.ifdelay = hal_set_ui32(inst->hal->rxdelay, calc_ifdelay(inst, inst->mbccb->baudrate, parity, stopbits) - 1); + inst->cfg_rx.ifdelay = hal_set_uint(inst->hal->rxdelay, calc_ifdelay(inst, inst->mbccb->baudrate, parity, stopbits) - 1); else // Manual - inst->cfg_rx.ifdelay = hal_set_ui32(inst->hal->rxdelay, inst->mbccb->rxdelay); + inst->cfg_rx.ifdelay = hal_set_uint(inst->hal->rxdelay, inst->mbccb->rxdelay); if(!inst->mbccb->txdelay) // Auto - inst->cfg_tx.ifdelay = hal_set_ui32(inst->hal->txdelay, calc_ifdelay(inst, inst->mbccb->baudrate, parity, stopbits) + 1); + inst->cfg_tx.ifdelay = hal_set_uint(inst->hal->txdelay, calc_ifdelay(inst, inst->mbccb->baudrate, parity, stopbits) + 1); else // Manual - inst->cfg_tx.ifdelay = hal_set_ui32(inst->hal->txdelay, inst->mbccb->txdelay); + inst->cfg_tx.ifdelay = hal_set_uint(inst->hal->txdelay, inst->mbccb->txdelay); if(!inst->mbccb->drvdelay) // Auto - inst->cfg_tx.drivedelay = hal_set_ui32(inst->hal->drvdelay, 1); + inst->cfg_tx.drivedelay = hal_set_uint(inst->hal->drvdelay, 1); else // Manual - inst->cfg_tx.drivedelay = hal_set_ui32(inst->hal->drvdelay, inst->mbccb->drvdelay); + inst->cfg_tx.drivedelay = hal_set_uint(inst->hal->drvdelay, inst->mbccb->drvdelay); inst->cfg_rx.filterrate = 0; // Zero means 2 times baudrate inst->cfg_rx.flags |= HM2_PKTUART_CONFIG_RXEN; @@ -2833,9 +2833,9 @@ int rtapi_app_main(void) 0, "%s.command.%02d.disable", inst->name, c)); CHECK(hal_pin_new_bool(comp_id, HAL_OUT, &(inst->hal->cmds[c].disabled), 0, "%s.command.%02d.disabled", inst->name, c)); - CHECK(hal_pin_new_ui32(comp_id, HAL_OUT, &(inst->hal->cmds[c].error), + CHECK(hal_pin_new_uint(comp_id, HAL_OUT, &(inst->hal->cmds[c].error), 0, "%s.command.%02d.errors", inst->name, c)); - CHECK(hal_pin_new_ui32(comp_id, HAL_OUT, &(inst->hal->cmds[c].errorcode), + CHECK(hal_pin_new_uint(comp_id, HAL_OUT, &(inst->hal->cmds[c].errorcode), 0, "%s.command.%02d.error-code", inst->name, c)); CHECK(hal_pin_new_bool(comp_id, HAL_IN, &(inst->hal->cmds[c].reset), 0, "%s.command.%02d.reset", inst->name, c)); @@ -2846,7 +2846,7 @@ int rtapi_app_main(void) if(hasdisabled(cc)) { cc->disabled = 1; hal_set_bool(inst->hal->cmds[c].disabled, 1); - hal_set_ui32(inst->hal->cmds[c].errorcode, EAGAIN); + hal_set_uint(inst->hal->cmds[c].errorcode, EAGAIN); } // Now create the pins associated with the command diff --git a/src/hal/utils/halcompile.g b/src/hal/utils/halcompile.g index 6bd2afab225..1481b16ae02 100644 --- a/src/hal/utils/halcompile.g +++ b/src/hal/utils/halcompile.g @@ -41,6 +41,7 @@ parser Hal: rule Declaration: "pin" PINDIRECTION TYPE HALNAME OptArray OptSAssign OptPersonality OptString ";" {{ pin(HALNAME, TYPE, OptArray, PINDIRECTION, OptString, OptSAssign, OptPersonality) }} | "param" PARAMDIRECTION TYPE HALNAME OptArray OptSAssign OptPersonality OptString ";" {{ param(HALNAME, TYPE, OptArray, PARAMDIRECTION, OptString, OptSAssign, OptPersonality) }} + | "alias" HALNAME OptArray {{ ppname = HALNAME; pparr = OptArray }} HALNAME OptArray ";" {{ alias(ppname, pparr, HALNAME, OptArray) }} | "function" NAME OptFP OptString ";" {{ function(NAME, OptFP, OptString) }} | "variable" NAME STARREDNAME OptSimpleArray OptAssign ";" {{ variable(NAME, STARREDNAME, OptSimpleArray, OptAssign) }} | "option" NAME OptValue ";" {{ option(NAME, OptValue) }} @@ -166,11 +167,14 @@ typemap = { def initialize(): global functions, params, pins, comp_name, names, docs, variables - global modparams, includes, hal_pin_names, hal_funct_names + global modparams, includes + global hal_pin_names, hal_funct_names global funct_derived_claims + global aliases functions = []; params = []; pins = []; options = {}; variables = [] modparams = []; docs = []; includes = []; + aliases = {} comp_name = None names = {} @@ -307,6 +311,22 @@ def param(name, type_, array, dir_, doc, value, personality): names[name] = 'param' params.append((name, type_, array, dir_, value, personality)) +def alias(name, namearr, aliasname, aliasarr): + if namearr != aliasarr: + Error(f"Alias arrays for pin '{namearr}' != '{aliasarr}'") + checkarray(name, namearr) + checkarray(aliasname, aliasarr) + if aliasname in names: + Error(f"Alias name '{aliasname}' already in use") + if name not in names: + Error(f"Pin/param name '{name}' not found, cannot alias") + if name in aliases: + Error(f"Alias for pin/param '{name}' already exists as '{aliases[name][2]}'") + if names[name] not in ('pin', 'param'): + Error(f"Expected '{name}' to be pin or param, but got '{names[name]}'"); + aliases[name] = (name, namearr, aliasname, aliasarr, names[name]) + names[aliasname] = 'alias' # Must register to prevent collision + def function(name, fp, doc): check_name_ok(name) hal_name = to_hal(name) @@ -577,6 +597,35 @@ static int comp_id; if personality: print("}", file=f) + if len(aliases) > 0: + print(" {", file=f) + print(" char pinname[HAL_NAME_LEN+1], alsname[HAL_NAME_LEN+1];", file=f) + for k, v in aliases.items(): + name, namearr, aliasname, aliasarr, nametype = v + if isinstance(array, tuple): + lim, cnt = array + print(" if((%s) > (%s)) {" % (cnt, lim), file=f) + print(' rtapi_print_msg(RTAPI_MSG_ERR,' \ + '"Alias %s: Requested size %%d exceeds max size %%d\\n",' + '(int)(%s), (int)(%s));' % (name, cnt, lim), file=f) + print(" return -ENOSPC;", file=f) + print(" }", file=f) + else: + cnt = array + if namearr: + print( " for(j = 0; j < (%s); j++) {" % cnt, file=f) + print(f" rtapi_snprintf(pinname, sizeof(pinname), \"%s.{to_hal(name)}\", prefix, j);", file=f) + print(f" rtapi_snprintf(alsname, sizeof(alsname), \"%s.{to_hal(aliasname)}\", prefix, j);", file=f) + print(f" r = {nametype}(pinname, alsname);", file=f) + print( " if(r != 0) return r;", file=f) + print( " }" % cnt, file=f) + else: + print(f" rtapi_snprintf(pinname, sizeof(pinname), \"%s.{to_hal(name)}\", prefix);", file=f) + print(f" rtapi_snprintf(alsname, sizeof(alsname), \"%s.{to_hal(aliasname)}\", prefix);", file=f) + print(f" r = hal_{nametype}_alias(pinname, alsname);", file=f) + print( " if(r != 0) return r;", file=f) + print(" }", file=f) + for type_, name, array, value in variables: if value is None: continue if array: