diff --git a/docs/po4a.cfg b/docs/po4a.cfg index 0845450e193..c836511d8b1 100644 --- a/docs/po4a.cfg +++ b/docs/po4a.cfg @@ -415,6 +415,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 459d35a151f..a554c16f154 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 @@ -554,39 +563,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 3c30b3c6b64..7118a7aecfe 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 4bdc8c63b0d..d6fcd221743 100644 --- a/docs/src/hal/components.adoc +++ b/docs/src/hal/components.adoc @@ -286,6 +286,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/docs/src/man/man9/hostmot2.9.adoc b/docs/src/man/man9/hostmot2.9.adoc index da9f56a494f..9b0cf94bcca 100644 --- a/docs/src/man/man9/hostmot2.9.adoc +++ b/docs/src/man/man9/hostmot2.9.adoc @@ -1389,14 +1389,18 @@ and may dump the internal state of the hostmot2 driver to the syslog. The bottom 16 bits of this is used as the address to read from. .read_data (uint, out):: Each time the hm2_read() function is called, this pin is updated with the value at .read_address. + It takes one thread cycle for the data to become available. .write_address (uint, in):: The bottom 16 bits of this is used as the address to write to. .write_data (uint, in):: This is the value to write to .write_address. - .write_strobe (bool, in):: + .write_strobe (bool, io):: Each time the hm2_write() function is called, this pin is examined. If it is True, then value in .write_data is written to the address in .write_address, and .write_strobe is set back to False. + .write_queued (bool, in):: + Submit a queued write command if the driver supports it when set to True. + The default is False, using immediate writes. .dump_state (bool, io):: This pin is normally False. If it gets set to True, the hostmot2 driver will write its representation of the board's internal state to the syslog, diff --git a/src/Makefile b/src/Makefile index d46373780be..0d165f448d4 100644 --- a/src/Makefile +++ b/src/Makefile @@ -499,7 +499,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/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/drivers/mesa-hostmot2/abs_encoder.c b/src/hal/drivers/mesa-hostmot2/abs_encoder.c index 4ee291240b1..b5f9ff32802 100644 --- a/src/hal/drivers/mesa-hostmot2/abs_encoder.c +++ b/src/hal/drivers/mesa-hostmot2/abs_encoder.c @@ -241,7 +241,7 @@ int hm2_absenc_setup_fabs(hostmot2_t *hm2, hm2_sserial_remote_t *chan, // exclusively set to the unsigned value. // Setting the frequency parameter would overwrite the filter setting and // is now separated out into a separate param storage reference (fanucf). - if (hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(chan->params->param.u), + if (hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(chan->params->param.u), 0xF, "%s.filter", chan->name)) { HM2_ERR("error adding param fanuc param 2, aborting\n"); return -EINVAL; @@ -474,7 +474,7 @@ int hm2_absenc_parse_md(hostmot2_t *hm2, int md_index) { return -EINVAL; } // And Params - if (hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(chan->params->timer_num), + if (hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(chan->params->timer_num), 0, "%s.timer-number", chan->name)){ HM2_ERR("error adding %s timer number param, aborting\n", chan->name); @@ -542,7 +542,7 @@ void hm2_absenc_process_tram_read(hostmot2_t *hm2, long period) { HM2_ERR("Data transmission not complete on channel %s read." " You may need to change the timing of %s. This " "warning will not repeat\n", chan->name, - (hal_get_ui32(chan->params->timer_num) == 0) ? + (hal_get_uint(chan->params->timer_num) == 0) ? "the trigger function" : "the hm2dpll timer"); err_tag[i] = 1; } @@ -576,10 +576,10 @@ void hm2_absenc_write(hostmot2_t *hm2){ for (i = 0; i < hm2->absenc.num_chans; i ++) { hm2_sserial_remote_t *chan = &hm2->absenc.chans[i]; - rtapi_u32 timer_num = hal_get_ui32(chan->params->timer_num); + rtapi_uint timer_num = hal_get_uint(chan->params->timer_num); switch (chan->myinst){ case HM2_GTAG_SSI: - if (timer_num > 4) timer_num = hal_set_ui32(chan->params->timer_num, 4); + if (timer_num > 4) timer_num = hal_set_uint(chan->params->timer_num, 4); buff = ((rtapi_u32)(0x10000 * (hal_get_real(chan->params->param.r) * 1000 / hm2->absenc.clock_frequency))) << 16 | timer_num << 12 @@ -596,7 +596,7 @@ void hm2_absenc_write(hostmot2_t *hm2){ break; case HM2_GTAG_BISS: - if (timer_num > 4) timer_num = hal_set_ui32(chan->params->timer_num, 4); + if (timer_num > 4) timer_num = hal_set_uint(chan->params->timer_num, 4); dds = ((rtapi_u32)(0x10000 * (hal_get_real(chan->params->param.r) * 1000 / hm2->absenc.clock_frequency))); filt = 0x8000/dds; // RX data filter set to 1/2 a clock period @@ -638,11 +638,11 @@ void hm2_absenc_write(hostmot2_t *hm2){ // buff2 = (u32_param << 28) | (rtapi_u32)(0x100000 * (float_param * 1000 / hm2->absenc.clock_frequency)) // Now // buff2 = (u32_param << 28) | (rtapi_u32)(0x100000 * (fanucf * 1000 / hm2->absenc.clock_frequency)) - if (timer_num > 4) timer_num = hal_set_ui32(chan->params->timer_num, 4); - if (hal_get_ui32(chan->params->param.u) > 15) hal_set_ui32(chan->params->param.u, 15); + if (timer_num > 4) timer_num = hal_set_uint(chan->params->timer_num, 4); + if (hal_get_uint(chan->params->param.u) > 15) hal_set_uint(chan->params->param.u, 15); buff3 = (chan->num_read_bits << 24) | (rtapi_u32)(8.0e-6 * hm2->absenc.clock_frequency) << 14; - buff2 = (hal_get_ui32(chan->params->param.u) << 28) + buff2 = (hal_get_uint(chan->params->param.u) << 28) | ((rtapi_u32)(0x100000 * (hal_get_real(chan->params->fanucf) * 1000.0 / hm2->absenc.clock_frequency))); buff = (timer_num << 12) | (timer_num == 0) << 8 diff --git a/src/hal/drivers/mesa-hostmot2/dpll.c b/src/hal/drivers/mesa-hostmot2/dpll.c index 004939ac71c..4f64775efef 100644 --- a/src/hal/drivers/mesa-hostmot2/dpll.c +++ b/src/hal/drivers/mesa-hostmot2/dpll.c @@ -88,13 +88,13 @@ int hm2_dpll_parse_md(hostmot2_t *hm2, int md_index) { * +-500ppm from its nominal value, usually by timekeeping software like ntp * and ntpdate. */ - r += hal_pin_new_ui32(hm2->llio->comp_id, HAL_IN, &(hm2->dpll.pins->time_const), + r += hal_pin_new_uint(hm2->llio->comp_id, HAL_IN, &(hm2->dpll.pins->time_const), 2000, "%s.dpll.time-const", hm2->llio->name); - r += hal_pin_new_ui32(hm2->llio->comp_id, HAL_IN, &(hm2->dpll.pins->plimit), + r += hal_pin_new_uint(hm2->llio->comp_id, HAL_IN, &(hm2->dpll.pins->plimit), 0x400000, "%s.dpll.plimit", hm2->llio->name); - r += hal_pin_new_ui32(hm2->llio->comp_id, HAL_OUT, &(hm2->dpll.pins->ddssize), + r += hal_pin_new_uint(hm2->llio->comp_id, HAL_OUT, &(hm2->dpll.pins->ddssize), 0, "%s.dpll.ddsize", hm2->llio->name); - r += hal_pin_new_ui32(hm2->llio->comp_id, HAL_OUT, &(hm2->dpll.pins->prescale), + r += hal_pin_new_uint(hm2->llio->comp_id, HAL_OUT, &(hm2->dpll.pins->prescale), 1, "%s.dpll.prescale", hm2->llio->name); if (r < 0) { HM2_ERR("error adding hm2_dpll timer pins, Aborting\n"); @@ -130,7 +130,7 @@ void hm2_dpll_process_tram_read(hostmot2_t *hm2, long period){ hal_set_real(pins->phase_error, (rtapi_s32)*hm2->dpll.hm2_dpll_sync_reg * (period / 4294967296000.00)); - hal_set_ui32(pins->ddssize, *hm2->dpll.control_reg1_read & 0xFF); + hal_set_uint(pins->ddssize, *hm2->dpll.control_reg1_read & 0xFF); } void hm2_dpll_write(hostmot2_t *hm2, long period) { @@ -158,12 +158,15 @@ void hm2_dpll_write(hostmot2_t *hm2, long period) { base_freq = hal_set_real(pins->base_freq, 1000.0/period_us); } - rtapi_u32 ddssize = hal_get_ui32(pins->ddssize); + // FIXME: The ddssize is an 8-bit value, but the use below using + // '1LL << ddssize' can create a zero value when 'ddssize >= 64'. + // That will subsequently result in a divide by zero. + rtapi_u32 ddssize = hal_get_uint(pins->ddssize); rtapi_u32 prescale = (0x40000000LL * hm2->dpll.clock_frequency) / ((1LL << ddssize) * base_freq * 1000.0); if (prescale < 1) prescale = 1; - hal_set_ui32(pins->prescale, prescale); + hal_set_uint(pins->prescale, prescale); buff = (rtapi_u32)((base_freq * 1000.0 * (1LL << ddssize) @@ -177,8 +180,9 @@ void hm2_dpll_write(hostmot2_t *hm2, long period) { sizeof(rtapi_u32)); hm2->dpll.base_rate_written= buff; } + // ControlReg0: 31..24: prescale, 23..0: PLimit(W)/PError(R) buff = (rtapi_u32)(prescale << 24 - | hal_get_ui32(pins->plimit)); + | (hal_get_uint(pins->plimit) & 0xffffff)); if (buff != hm2->dpll.control_reg0_written){ hm2->llio->write(hm2->llio, hm2->dpll.control_reg0_addr, @@ -186,7 +190,8 @@ void hm2_dpll_write(hostmot2_t *hm2, long period) { sizeof(rtapi_u32)); hm2->dpll.control_reg0_written= buff; } - buff = (rtapi_u32)(hal_get_ui32(pins->time_const) << 16); + // ControlReg1: 31..16: time_const, 15..8: unused, 7..0: ddssize (R/O) + buff = (rtapi_u32)(hal_get_uint(pins->time_const) << 16); if (buff != hm2->dpll.control_reg1_written){ hm2->llio->write(hm2->llio, hm2->dpll.control_reg1_addr, diff --git a/src/hal/drivers/mesa-hostmot2/encoder.c b/src/hal/drivers/mesa-hostmot2/encoder.c index 4ed8ad05e22..b5affa086f8 100644 --- a/src/hal/drivers/mesa-hostmot2/encoder.c +++ b/src/hal/drivers/mesa-hostmot2/encoder.c @@ -157,39 +157,38 @@ static void hm2_encoder_read_control_register(hostmot2_t *hm2) { static void hm2_encoder_set_filter_rate_and_skew(hostmot2_t *hm2) { - rtapi_u32 filter_rate = hm2->encoder.clock_frequency/hal_get_ui32(hm2->encoder.hal->pin.sample_frequency); + rtapi_u32 filter_rate = hm2->encoder.clock_frequency/hal_get_uint(hm2->encoder.hal->pin.sample_frequency); if (filter_rate == 1) { filter_rate = 0xFFF; } else { filter_rate -= 2; } - hal_set_ui32(hm2->encoder.hal->pin.sample_frequency, hm2->encoder.clock_frequency/(filter_rate + 2)); + hal_set_uint(hm2->encoder.hal->pin.sample_frequency, hm2->encoder.clock_frequency/(filter_rate + 2)); HM2_DBG("Setting encoder QFilterRate to %d\n", filter_rate); if (hm2->encoder.has_skew) { rtapi_u32 divisor = (1e9/hm2->encoder.clock_frequency); // Unsigned division rounding for integers. This is only valid for unsigned division - rtapi_u32 skew = (hal_get_ui32(hm2->encoder.hal->pin.skew) + (divisor/2))/divisor; + rtapi_u32 skew = (hal_get_uint(hm2->encoder.hal->pin.skew) + (divisor/2))/divisor; if (skew > 15) { skew = 15; } HM2_DBG("Setting mux encoder skew to %d\n", skew); filter_rate |= (skew & 0xF) << 28; - hal_set_ui32(hm2->encoder.hal->pin.skew, skew*(1e9/hm2->encoder.clock_frequency)); - hm2->encoder.written_skew = hal_get_ui32(hm2->encoder.hal->pin.skew); + hal_set_uint(hm2->encoder.hal->pin.skew, skew*(1e9/hm2->encoder.clock_frequency)); + hm2->encoder.written_skew = hal_get_uint(hm2->encoder.hal->pin.skew); } hm2->llio->write(hm2->llio, hm2->encoder.filter_rate_addr, &filter_rate, sizeof(rtapi_u32)); - hm2->encoder.written_sample_frequency = hal_get_ui32(hm2->encoder.hal->pin.sample_frequency); + hm2->encoder.written_sample_frequency = hal_get_uint(hm2->encoder.hal->pin.sample_frequency); } static void hm2_encoder_set_dpll_timer_if_present(hostmot2_t *hm2) { if(!hm2->encoder.dpll_timer_num_addr) return; - uint32_t data = hm2->encoder.desired_dpll_timer_reg; + rtapi_u32 data = hm2->encoder.written_dpll_timer_reg = hm2->encoder.desired_dpll_timer_reg; hm2->llio->write(hm2->llio, hm2->encoder.dpll_timer_num_addr, &data, sizeof(data)); - hm2->encoder.written_dpll_timer_reg = data; } static void hm2_encoder_force_write_dpll_timer(hostmot2_t *hm2) { @@ -209,11 +208,11 @@ void hm2_encoder_write(hostmot2_t *hm2) { } } - if (hal_get_ui32(hm2->encoder.hal->pin.sample_frequency) != hm2->encoder.written_sample_frequency) { + if (hal_get_uint(hm2->encoder.hal->pin.sample_frequency) != hm2->encoder.written_sample_frequency) { goto force_write; } if (hm2->encoder.has_skew) { - if (hal_get_ui32(hm2->encoder.hal->pin.skew) != hm2->encoder.written_skew) { + if (hal_get_uint(hm2->encoder.hal->pin.skew) != hm2->encoder.written_skew) { goto force_write; } } @@ -268,7 +267,7 @@ void hm2_encoder_write(hostmot2_t *hm2) { } if(hm2->encoder.dpll_timer_num_addr) { - int32_t dpll_timer_num = hal_get_si32(hm2->encoder.hal->pin.dpll_timer_num); + rtapi_sint dpll_timer_num = hal_get_sint(hm2->encoder.hal->pin.dpll_timer_num); if(dpll_timer_num < -1 || dpll_timer_num > 4) dpll_timer_num = -1; if(dpll_timer_num == -1) hm2->encoder.desired_dpll_timer_reg = 0; @@ -467,14 +466,14 @@ int hm2_encoder_parse_md(hostmot2_t *hm2, int md_index) { } else { sfpinname = "encoder.sample-frequency"; } - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_IN, &(hm2->encoder.hal->pin.sample_frequency), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_IN, &(hm2->encoder.hal->pin.sample_frequency), 0, "%s.%s", hm2->llio->name, sfpinname); if (r < 0) { HM2_ERR("error %d adding pin %s.%s, aborting\n", r, hm2->llio->name, sfpinname); goto fail1; } if ((md->gtag == HM2_GTAG_MUXED_ENCODER) && (md->version > 3 )) { // >3 to include modules with probe enable - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_IN, &(hm2->encoder.hal->pin.skew), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_IN, &(hm2->encoder.hal->pin.skew), 0, "%s.encoder.muxed-skew", hm2->llio->name); if (r < 0) { HM2_ERR("error %d adding pin %s.encoder.muxed-skew, aborting\n", r, hm2->llio->name); @@ -483,7 +482,7 @@ int hm2_encoder_parse_md(hostmot2_t *hm2, int md_index) { hm2->encoder.has_skew = 1; } if(hm2->encoder.dpll_timer_num_addr) { - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_IN, &(hm2->encoder.hal->pin.dpll_timer_num), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_IN, &(hm2->encoder.hal->pin.dpll_timer_num), -1, "%s.encoder.timer-number", hm2->llio->name); if (r < 0) { HM2_ERR("error %d adding pin %s.encoder.timer-number, aborting\n", r, hm2->llio->name); @@ -500,28 +499,28 @@ int hm2_encoder_parse_md(hostmot2_t *hm2, int md_index) { for (int i = 0; i < hm2->encoder.num_instances; i ++) { // pins - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(hm2->encoder.instance[i].hal.pin.rawcounts), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(hm2->encoder.instance[i].hal.pin.rawcounts), 0, "%s.encoder.%02d.rawcounts", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.encoder.%02d.rawcounts', aborting\n", r, hm2->llio->name, i); goto fail1; } - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(hm2->encoder.instance[i].hal.pin.rawlatch), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(hm2->encoder.instance[i].hal.pin.rawlatch), 0, "%s.encoder.%02d.rawlatch", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.encoder.%02d.rawlatch', aborting\n", r, hm2->llio->name, i); goto fail1; } - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(hm2->encoder.instance[i].hal.pin.count), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(hm2->encoder.instance[i].hal.pin.count), 0, "%s.encoder.%02d.count", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.encoder.%02d.count', aborting\n", r, hm2->llio->name, i); goto fail1; } - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(hm2->encoder.instance[i].hal.pin.count_latch), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(hm2->encoder.instance[i].hal.pin.count_latch), 0, "%s.encoder.%02d.count-latched", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.encoder.%02d.count-latched', aborting\n", r, hm2->llio->name, i); @@ -698,9 +697,9 @@ int hm2_encoder_parse_md(hostmot2_t *hm2, int md_index) { if (md->gtag == HM2_GTAG_ENCODER) { - hal_set_ui32(hm2->encoder.hal->pin.sample_frequency, 25000000); + hal_set_uint(hm2->encoder.hal->pin.sample_frequency, 25000000); } else { - hal_set_ui32(hm2->encoder.hal->pin.sample_frequency, 8000000); + hal_set_uint(hm2->encoder.hal->pin.sample_frequency, 8000000); } return hm2->encoder.num_instances; @@ -728,13 +727,13 @@ void hm2_encoder_tram_init(hostmot2_t *hm2) { count = hm2_encoder_get_reg_count(hm2, i); - hal_set_si32(hm2->encoder.instance[i].hal.pin.rawcounts, count); - hal_set_si32(hm2->encoder.instance[i].hal.pin.rawlatch, count); + hal_set_sint(hm2->encoder.instance[i].hal.pin.rawcounts, count); + hal_set_sint(hm2->encoder.instance[i].hal.pin.rawlatch, count); hm2->encoder.instance[i].rawcounts_64 = count; hm2->encoder.instance[i].rawlatch_64 = count; - hal_set_si32(hm2->encoder.instance[i].hal.pin.count, 0); - hal_set_si32(hm2->encoder.instance[i].hal.pin.count_latch, 0); + hal_set_sint(hm2->encoder.instance[i].hal.pin.count, 0); + hal_set_sint(hm2->encoder.instance[i].hal.pin.count_latch, 0); hm2->encoder.instance[i].count_64 = 0; hm2->encoder.instance[i].count_latch_64 = 0; hal_set_real(hm2->encoder.instance[i].hal.pin.position, 0.0); @@ -743,8 +742,6 @@ void hm2_encoder_tram_init(hostmot2_t *hm2) { hal_set_real(hm2->encoder.instance[i].hal.pin.velocity_rpm, 0.0); hal_set_bool(hm2->encoder.instance[i].hal.pin.quadrature_error, 0); - hm2->encoder.instance[i].zero_offset = count; - hm2->encoder.instance[i].prev_reg_count = count; hm2->encoder.instance[i].zero_offset_64 = count; @@ -797,7 +794,7 @@ static void hm2_encoder_instance_update_rawcounts_and_handle_index(hostmot2_t *h reg_count = hm2_encoder_get_reg_count(hm2, instance); e->rawcounts_64 = hal_extend_counter(e->rawcounts_64, reg_count, 16); - hal_set_si32(e->hal.pin.rawcounts, (rtapi_s32)e->rawcounts_64); + hal_set_sint(e->hal.pin.rawcounts, e->rawcounts_64); // @@ -821,10 +818,9 @@ static void hm2_encoder_instance_update_rawcounts_and_handle_index(hostmot2_t *h latched_64 = hal_extend_counter(prev_rawcounts_64, latched_count, 16); if (!hal_get_bool(e->hal.pin.no_clear_on_index)) { e->zero_offset_64 = latched_64; - e->zero_offset = (rtapi_s32)latched_64; } e->rawlatch_64 = latched_64; - hal_set_si32(e->hal.pin.rawlatch, (rtapi_s32)latched_64); + hal_set_sint(e->hal.pin.rawlatch, latched_64); hal_set_bool(e->hal.pin.index_enable, 0); // may need to update interpolated position after index event because // this _may_ happen without a count but its pretty ugly... @@ -846,7 +842,7 @@ static void hm2_encoder_instance_update_rawcounts_and_handle_index(hostmot2_t *h latched_64 = hal_extend_counter(prev_rawcounts_64, latched_count, 16); e->rawlatch_64 = latched_64; - hal_set_si32(e->hal.pin.rawlatch, (rtapi_s32)latched_64); + hal_set_sint(e->hal.pin.rawlatch, latched_64); hal_set_bool(e->hal.pin.latch_enable, 0); } } @@ -893,9 +889,8 @@ static void hm2_encoder_instance_update_position(hostmot2_t *hm2, int instance) // if (hal_get_bool(e->hal.pin.reset)) { - e->zero_offset = hal_get_si32(e->hal.pin.rawcounts); e->zero_offset_64 = e->rawcounts_64; - hal_set_si32(e->hal.pin.rawlatch, e->zero_offset); + hal_set_sint(e->hal.pin.rawlatch, e->zero_offset_64); e->rawlatch_64 = e->zero_offset_64; hal_set_real(e->hal.pin.position_interpolated, hal_get_real(e->hal.pin.position)); @@ -909,10 +904,8 @@ static void hm2_encoder_instance_update_position(hostmot2_t *hm2, int instance) // From that we easily compute count and scaled position. // - hal_set_si32(e->hal.pin.count, hal_get_si32(e->hal.pin.rawcounts) - e->zero_offset); - e->count_64 = e->rawcounts_64 - e->zero_offset_64; - hal_set_si32(e->hal.pin.count_latch, hal_get_si32(e->hal.pin.rawlatch) - e->zero_offset); - e->count_latch_64 = e->rawlatch_64 - e->zero_offset_64; + e->count_64 = hal_set_sint(e->hal.pin.count, e->rawcounts_64 - e->zero_offset_64); + e->count_latch_64 = hal_set_sint(e->hal.pin.count_latch, e->rawlatch_64 - e->zero_offset_64); // @@ -921,8 +914,9 @@ static void hm2_encoder_instance_update_position(hostmot2_t *hm2, int instance) // to avoid wrap on high-resolution encoders. // - hal_set_real(e->hal.pin.position, e->count_64 / hal_get_real(e->hal.param.scale)); - hal_set_real(e->hal.pin.position_latch, e->count_latch_64 / hal_get_real(e->hal.param.scale)); + rtapi_real scale = hal_get_real(e->hal.param.scale); + hal_set_real(e->hal.pin.position, e->count_64 / scale); + hal_set_real(e->hal.pin.position_latch, e->count_latch_64 / scale); } @@ -964,7 +958,7 @@ static void hm2_encoder_instance_process_tram_read(hostmot2_t *hm2, int instance hm2_encoder_instance_update_rawcounts_and_handle_index(hm2, instance); hm2_encoder_instance_update_position(hm2, instance); - e->prev_event_rawcounts = hal_get_si32(e->hal.pin.rawcounts); + e->prev_event_rawcounts = hal_get_sint(e->hal.pin.rawcounts); e->prev_event_reg_timestamp = hm2_encoder_get_reg_timestamp(hm2, instance); e->prev_dS_counts = 0; @@ -985,7 +979,7 @@ static void hm2_encoder_instance_process_tram_read(hostmot2_t *hm2, int instance rtapi_s32 dT_clocks; double dT_s; - rtapi_s32 dS_counts; + rtapi_sint dS_counts; double dS_pos_units; // get current count from the FPGA (already read) @@ -1062,7 +1056,8 @@ static void hm2_encoder_instance_process_tram_read(hostmot2_t *hm2, int instance e->tsc_num_rollovers ++; } - dS_counts = hal_get_si32(e->hal.pin.rawcounts) - e->prev_event_rawcounts; + rtapi_sint rawcounts = hal_get_sint(e->hal.pin.rawcounts); + dS_counts = rawcounts - e->prev_event_rawcounts; // If we reversed direction and moved exactly one edge, // we can't reliably estimate velocity. The encoder might @@ -1070,8 +1065,8 @@ static void hm2_encoder_instance_process_tram_read(hostmot2_t *hm2, int instance // small dT between adjacent edges, leading to misleadingly // large velocity estimates. So we just call it 0. if ( - (((hal_get_si32(e->hal.pin.rawcounts) - e->prev_event_rawcounts) == 1) && (e->prev_dS_counts < 0)) - || (((hal_get_si32(e->hal.pin.rawcounts) - e->prev_event_rawcounts) == -1) && (e->prev_dS_counts > 0)) + (((rawcounts - e->prev_event_rawcounts) == 1) && (e->prev_dS_counts < 0)) + || (((rawcounts - e->prev_event_rawcounts) == -1) && (e->prev_dS_counts > 0)) ) { hal_set_real(e->hal.pin.velocity, 0.0); hal_set_real(e->hal.pin.velocity_rpm, 0.0); @@ -1095,7 +1090,7 @@ static void hm2_encoder_instance_process_tram_read(hostmot2_t *hm2, int instance e->prev_dS_counts = dS_counts; - e->prev_event_rawcounts = hal_get_si32(e->hal.pin.rawcounts); + e->prev_event_rawcounts = rawcounts; e->prev_event_reg_timestamp = time_of_interest; e->prev_time_of_interest = time_of_interest; diff --git a/src/hal/drivers/mesa-hostmot2/hm2_eth.c b/src/hal/drivers/mesa-hostmot2/hm2_eth.c index 4c671e76092..a305f7ecba1 100644 --- a/src/hal/drivers/mesa-hostmot2/hm2_eth.c +++ b/src/hal/drivers/mesa-hostmot2/hm2_eth.c @@ -985,14 +985,14 @@ static bool record_soft_error(hm2_eth_t *board) { if(!board->hal) return 1; // still early in hm2_eth_probe board->llio.needs_soft_reset = 1; hal_set_bool(board->hal->packet_error, 1); - hal_set_ui32(board->hal->packet_error_total, hal_get_ui32(board->hal->packet_error_total) + 1); - int32_t increment = hal_get_si32(board->hal->packet_error_increment); + hal_set_uint(board->hal->packet_error_total, hal_get_uint(board->hal->packet_error_total) + 1); + rtapi_sint increment = hal_get_sint(board->hal->packet_error_increment); if(increment < 1) increment = 1; board->comm_error_counter += increment; - if(board->comm_error_counter < 0 || board->comm_error_counter > hal_get_si32(board->hal->packet_error_limit)) - board->comm_error_counter = hal_get_si32(board->hal->packet_error_limit); - hal_set_si32(board->hal->packet_error_level, board->comm_error_counter); - bool result = board->comm_error_counter < hal_get_si32(board->hal->packet_error_limit); + if(board->comm_error_counter < 0 || board->comm_error_counter > hal_get_sint(board->hal->packet_error_limit)) + board->comm_error_counter = hal_get_sint(board->hal->packet_error_limit); + hal_set_sint(board->hal->packet_error_level, board->comm_error_counter); + bool result = board->comm_error_counter < hal_get_sint(board->hal->packet_error_limit); if(!result) hal_set_bool(*board->llio.io_error, true); hal_set_bool(board->hal->packet_error_exceeded, !result); return result; @@ -1000,11 +1000,11 @@ static bool record_soft_error(hm2_eth_t *board) { static void decrement_soft_error(hm2_eth_t *board) { if(!board->hal) return; // still early in hm2_eth_probe - int32_t decrement = hal_get_si32(board->hal->packet_error_decrement); + rtapi_sint decrement = hal_get_sint(board->hal->packet_error_decrement); if(decrement < 1) decrement = 1; board->comm_error_counter -= decrement; if(board->comm_error_counter < 0) board->comm_error_counter = 0; - hal_set_si32(board->hal->packet_error_level, board->comm_error_counter); + hal_set_sint(board->hal->packet_error_level, board->comm_error_counter); hal_set_bool(board->hal->packet_error, 0); hal_set_bool(board->hal->packet_error_exceeded, 0); } @@ -1020,11 +1020,11 @@ static int hm2_eth_receive_queued_reads(hm2_lowlevel_io_t *this) { // pin (or they did something else like fiddle with the error limit // during a run, in which case we don't care if we reset the counter // or not) - if(board->hal && board->comm_error_counter == hal_get_si32(board->hal->packet_error_limit) && !hal_get_bool(*board->llio.io_error)) { + if(board->hal && board->comm_error_counter == hal_get_sint(board->hal->packet_error_limit) && !hal_get_bool(*board->llio.io_error)) { board->comm_error_counter = 0; } - long read_timeout = board->hal ? hal_get_si32(board->hal->read_timeout) : 1600000; + long read_timeout = board->hal ? hal_get_sint(board->hal->read_timeout) : 1600000; if(read_timeout <= 0)//less than or equal to 0, use 80% of the thread period. read_timeout = 80; if(read_timeout < 100)//less than 100 is interpreted as a percentage of the thread period. @@ -1636,19 +1636,19 @@ static int hm2_eth_items(hm2_eth_t *board) { board->hal = hal_malloc(sizeof(*board->hal)); if(!board->hal) return -ENOMEM; - if((r = hal_param_new_si32(board->llio.comp_id, HAL_RW, &board->hal->read_timeout, + if((r = hal_param_new_sint(board->llio.comp_id, HAL_RW, &board->hal->read_timeout, 80, "%s.packet-read-timeout", board->llio.name)) < 0) return r; - if((r = hal_param_new_si32(board->llio.comp_id, HAL_RW, &board->hal->packet_error_limit, + if((r = hal_param_new_sint(board->llio.comp_id, HAL_RW, &board->hal->packet_error_limit, 10, "%s.packet-error-limit", board->llio.name)) < 0) return r; - if((r = hal_param_new_si32(board->llio.comp_id, HAL_RW, &board->hal->packet_error_increment, + if((r = hal_param_new_sint(board->llio.comp_id, HAL_RW, &board->hal->packet_error_increment, 2, "%s.packet-error-increment", board->llio.name)) < 0) return r; - if((r = hal_param_new_si32(board->llio.comp_id, HAL_RO, &board->hal->packet_error_decrement, + if((r = hal_param_new_sint(board->llio.comp_id, HAL_RO, &board->hal->packet_error_decrement, 1, "%s.packet-error-decrement", board->llio.name)) < 0) return r; @@ -1656,11 +1656,11 @@ static int hm2_eth_items(hm2_eth_t *board) { 0, "%s.packet-error", board->llio.name)) < 0) return r; - if((r = hal_pin_new_ui32(board->llio.comp_id, HAL_IO, &board->hal->packet_error_total, + if((r = hal_pin_new_uint(board->llio.comp_id, HAL_IO, &board->hal->packet_error_total, 0, "%s.packet-error-total", board->llio.name)) < 0) return r; - if((r = hal_pin_new_si32(board->llio.comp_id, HAL_OUT, &board->hal->packet_error_level, + if((r = hal_pin_new_sint(board->llio.comp_id, HAL_OUT, &board->hal->packet_error_level, 0, "%s.packet-error-level", board->llio.name)) < 0) return r; diff --git a/src/hal/drivers/mesa-hostmot2/hm2_eth.h b/src/hal/drivers/mesa-hostmot2/hm2_eth.h index 0741e8ff0dc..a805bdcbfca 100644 --- a/src/hal/drivers/mesa-hostmot2/hm2_eth.h +++ b/src/hal/drivers/mesa-hostmot2/hm2_eth.h @@ -74,7 +74,7 @@ struct hm2_eth_t { // Set when a queued write has set write_cnt in the board int has_written_cnt; - int comm_error_counter; + rtapi_sint comm_error_counter; uint16_t old_rxudpcount, rxudpcount; struct arpreq req; diff --git a/src/hal/drivers/mesa-hostmot2/hostmot2.c b/src/hal/drivers/mesa-hostmot2/hostmot2.c index f83e48fad84..6fc79b744a9 100644 --- a/src/hal/drivers/mesa-hostmot2/hostmot2.c +++ b/src/hal/drivers/mesa-hostmot2/hostmot2.c @@ -1770,7 +1770,7 @@ void hm2_unregister(hm2_lowlevel_io_t *llio) { // if there's a watchdog, set it to safe the board right away if (hm2->watchdog.num_instances > 0) { hm2->watchdog.instance[0].enable = 1; - hal_set_ui32(hm2->watchdog.instance[0].hal.param.timeout_ns, 1); + hal_set_uint(hm2->watchdog.instance[0].hal.param.timeout_ns, 1); hm2_watchdog_force_write(hm2); } diff --git a/src/hal/drivers/mesa-hostmot2/hostmot2.h b/src/hal/drivers/mesa-hostmot2/hostmot2.h index 89850f312b9..4318499573a 100644 --- a/src/hal/drivers/mesa-hostmot2/hostmot2.h +++ b/src/hal/drivers/mesa-hostmot2/hostmot2.h @@ -316,7 +316,7 @@ typedef struct { } hal; - rtapi_s32 zero_offset; // *hal.pin.counts == (*hal.pin.rawcounts - zero_offset) + // (all 64-bit now) rtapi_s32 zero_offset; // *hal.pin.counts == (*hal.pin.rawcounts - zero_offset) // 64-bit internals prevent float position wrap on high-count encoders. // Not exposed as HAL pins; s32 pins above are truncated views. rtapi_s64 rawcounts_64; @@ -327,7 +327,7 @@ typedef struct { rtapi_u16 prev_reg_count; // from this and the current count in the register we compute a change-in-counts, which we add to rawcounts - rtapi_s32 prev_dS_counts; // last time the function ran, it saw this many counts from the time before *that* + rtapi_sint prev_dS_counts; // last time the function ran, it saw this many counts from the time before *that* rtapi_u32 prev_control; @@ -336,7 +336,7 @@ typedef struct { // these two are the datapoint last time we moved (only valid if state == HM2_ENCODER_MOVING) - rtapi_s32 prev_event_rawcounts; + rtapi_sint prev_event_rawcounts; rtapi_u16 prev_event_reg_timestamp; rtapi_s32 tsc_num_rollovers; @@ -370,11 +370,11 @@ typedef struct { // module-global HAL objects... hm2_encoder_module_global_t *hal; - rtapi_u32 written_sample_frequency; + rtapi_uint written_sample_frequency; int has_skew; - rtapi_u32 written_skew; + rtapi_uint written_skew; rtapi_u32 written_hires_timestamp; - rtapi_u32 desired_dpll_timer_reg, written_dpll_timer_reg; + rtapi_sint desired_dpll_timer_reg, written_dpll_timer_reg; // hw registers rtapi_u32 counter_addr; @@ -536,7 +536,7 @@ typedef struct { // this keeps track of the output_type that we've told the FPGA, so we // know if we need to update it - rtapi_s32 written_output_type; + rtapi_sint written_output_type; // this keeps track of the offset_mode that we've set , so we // know if we need to update it @@ -575,8 +575,8 @@ typedef struct { // these keep track of the most recent hal->param.p{d,w}m_frequency // that we've told the FPGA about, so we know if we need to update it - rtapi_u32 written_pwm_frequency; - rtapi_u32 written_pdm_frequency; + rtapi_uint written_pwm_frequency; + rtapi_uint written_pdm_frequency; // number of bits of resolution of the PWM signal (PDM is fixed at 12 bits) int pwm_bits; @@ -1040,8 +1040,8 @@ typedef struct { // module-global HAL objects... hm2_xy2mod_module_global_t *hal; - rtapi_s32 written_dpll_rtimer_num; - rtapi_s32 written_dpll_wtimer_num; + rtapi_sint written_dpll_rtimer_num; + rtapi_sint written_dpll_wtimer_num; rtapi_u32 accx_addr; @@ -1134,7 +1134,7 @@ typedef struct { // these keep track of the most recent hal->param.p{d,w}m_frequency // that we've told the FPGA about, so we know if we need to update it - rtapi_u32 written_pwm_frequency; + rtapi_uint written_pwm_frequency; rtapi_u32 pwm_value_addr; // All three phases share a register (10 bits each) rtapi_u32 *pwm_value_reg; // Pointer to a memory block that holds the set. @@ -1261,11 +1261,11 @@ typedef struct { rtapi_s64 subcounts; rtapi_s32 zero_offset; - rtapi_u32 written_steplen; - rtapi_u32 written_stepspace; - rtapi_u32 written_dirsetup; - rtapi_u32 written_dirhold; - rtapi_u32 written_step_type; + rtapi_uint written_steplen; + rtapi_uint written_stepspace; + rtapi_uint written_dirsetup; + rtapi_uint written_dirhold; + rtapi_uint written_step_type; rtapi_u32 written_swap_step_dir; rtapi_u32 written_index_enable; rtapi_u32 written_probe_enable; @@ -1295,7 +1295,7 @@ typedef struct { // module-global HAL objects... hm2_stepgen_module_global_t *hal; - rtapi_u32 written_dpll_timer_num; + rtapi_sint written_dpll_timer_num; // write this (via TRAM) every hm2_.write rtapi_u32 step_rate_addr; @@ -1483,7 +1483,7 @@ typedef struct { } hal; - rtapi_u32 written_timeout_ns; + rtapi_uint written_timeout_ns; int enable; // gets set to 0 at load time, gets set to 1 at first pet_watchdog int written_enable; @@ -1606,10 +1606,14 @@ typedef struct { hal_uint_t write_address; hal_uint_t write_data; hal_bool_t write_strobe; + hal_bool_t write_queued; hal_bool_t dump_state; } pin; } hal; + + rtapi_u32 valread; // The value buffer written into during resolving the read + rtapi_u32 valwrite; // The value buffer used by the write } hm2_raw_t; diff --git a/src/hal/drivers/mesa-hostmot2/inm.c b/src/hal/drivers/mesa-hostmot2/inm.c index 596b9e2ba02..7239d95b780 100644 --- a/src/hal/drivers/mesa-hostmot2/inm.c +++ b/src/hal/drivers/mesa-hostmot2/inm.c @@ -186,21 +186,21 @@ int hm2_inm_parse_md(hostmot2_t *hm2, int md_index) { temp = (temp & 0x0000001f) +1; inst->scanwidth = temp; // init 20000: 20 KHz = 50 usec/scan - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(inst->hal.param.scan_rate), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(inst->hal.param.scan_rate), 20000, "%s.inm.%02d.scan_rate", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.inm.%02d.scan_rate', aborting\n", r, hm2->llio->name, i); goto fail1; } // init 500: 500*50 usec = 25 ms - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(inst->hal.param.slow_scans), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(inst->hal.param.slow_scans), 500, "%s.inm.%02d.slow_scans", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.inm.%02d.slow_scans', aborting\n", r, hm2->llio->name, i); goto fail1; } // init 5: 5*50 usec = 250 usec - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(inst->hal.param.fast_scans), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(inst->hal.param.fast_scans), 5, "%s.inm.%02d.fast_scans", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.inm.%02d.fast_scans', aborting\n", r, hm2->llio->name, i); @@ -267,7 +267,8 @@ int hm2_inm_parse_md(hostmot2_t *hm2, int md_index) { } } - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RO, &(inst->hal.param.scan_width), + // FIXME: The scan_width is not used anywhere + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RO, &(inst->hal.param.scan_width), temp, "%s.inm.%02d.scan_width", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.inm.%02d.scan_width', aborting\n", r, hm2->llio->name, i); @@ -320,7 +321,7 @@ int hm2_inm_parse_md(hostmot2_t *hm2, int md_index) { } } if (inst->enc0_present) { - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(inst->hal.pin.enc0_count), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(inst->hal.pin.enc0_count), 0, "%s.inm.%02d.enc0-count", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.inm.%02d.enc0-count', aborting\n", r, hm2->llio->name, i); @@ -335,7 +336,7 @@ int hm2_inm_parse_md(hostmot2_t *hm2, int md_index) { } if (inst->enc1_present) { - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(inst->hal.pin.enc1_count), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(inst->hal.pin.enc1_count), 0, "%s.inm.%02d.enc1-count", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.inm.%02d.enc1-count', aborting\n", r, hm2->llio->name, i); @@ -350,7 +351,7 @@ int hm2_inm_parse_md(hostmot2_t *hm2, int md_index) { } if (inst->enc2_present) { - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(inst->hal.pin.enc2_count), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(inst->hal.pin.enc2_count), 0, "%s.inm.%02d.enc2-count", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.inm.%02d.enc2-count', aborting\n", r, hm2->llio->name, i); @@ -364,7 +365,7 @@ int hm2_inm_parse_md(hostmot2_t *hm2, int md_index) { } } if (inst->enc3_present) { - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(inst->hal.pin.enc3_count), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(inst->hal.pin.enc3_count), 0, "%s.inm.%02d.enc3-count", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.inm.%02d.enc3-count', aborting\n", r, hm2->llio->name, i); @@ -418,19 +419,19 @@ void hm2_inm_force_write(hostmot2_t *hm2) { // setup control register and mpg_write for (i = 0; i < hm2->inm.num_instances; i ++) { hm2_inm_instance_t *inst = &hm2->inm.instance[i]; - scanrate = inst->scanwidth * hal_get_ui32(inst->hal.param.scan_rate); + scanrate = inst->scanwidth * hal_get_uint(inst->hal.param.scan_rate); if (scanrate > 10000000) { scanrate = 10000000; - hal_set_ui32(inst->hal.param.scan_rate, scanrate/inst->scanwidth); + hal_set_uint(inst->hal.param.scan_rate, scanrate/inst->scanwidth); } divisor = (hm2->inm.clock_frequency / (4 * scanrate)) - 1; - rtapi_u32 fast_scans = hal_get_ui32(inst->hal.param.fast_scans); + rtapi_uint fast_scans = hal_get_uint(inst->hal.param.fast_scans); if (fast_scans > 63) { - fast_scans = hal_set_ui32(inst->hal.param.fast_scans, 63); + fast_scans = hal_set_uint(inst->hal.param.fast_scans, 63); } - rtapi_u32 slow_scans = hal_get_ui32(inst->hal.param.slow_scans); + rtapi_uint slow_scans = hal_get_uint(inst->hal.param.slow_scans); if (slow_scans > 1023) { - slow_scans = hal_set_ui32(inst->hal.param.slow_scans, 1023); + slow_scans = hal_set_uint(inst->hal.param.slow_scans, 1023); } // global invert bit(5) fixed to true for now as this matches all existing hardware @@ -465,37 +466,37 @@ void hm2_inm_write(hostmot2_t *hm2) { for (i = 0; i < hm2->inm.num_instances; i ++) { hm2_inm_instance_t *inst = &hm2->inm.instance[i]; - scanrate = inst->scanwidth * hal_get_ui32(inst->hal.param.scan_rate); + scanrate = inst->scanwidth * hal_get_uint(inst->hal.param.scan_rate); // bound scanrate maximum frequency if (scanrate > 10000000) { scanrate = 10000000; - hal_set_ui32(inst->hal.param.scan_rate, scanrate/inst->scanwidth); - HM2_ERR("inm %d scanrate too high, resetting to %d \n", i, hal_get_ui32(inst->hal.param.scan_rate)); + hal_set_uint(inst->hal.param.scan_rate, scanrate/inst->scanwidth); + HM2_ERR("inm %d scanrate too high, resetting to %lu \n", i, (unsigned long)hal_get_uint(inst->hal.param.scan_rate)); } divisor = (hm2->inm.clock_frequency / (4 * scanrate)) - 1; // bound divisor so we dont splatter into other fields if ((divisor > 1023 ) | (scanrate == 0 )) { divisor = 1023; - hal_set_ui32(inst->hal.param.scan_rate, (hm2->inm.clock_frequency/4)/(divisor +1) + hal_set_uint(inst->hal.param.scan_rate, (hm2->inm.clock_frequency/4)/(divisor +1) /inst->scanwidth); - HM2_ERR("inm %d scanrate too low, resetting to %d \n", i, hal_get_ui32(inst->hal.param.scan_rate)); + HM2_ERR("inm %d scanrate too low, resetting to %lu \n", i, (unsigned long)hal_get_uint(inst->hal.param.scan_rate)); } - rtapi_u32 fast_scans = hal_get_ui32(inst->hal.param.fast_scans); + rtapi_uint fast_scans = hal_get_uint(inst->hal.param.fast_scans); if (fast_scans > 63) { - fast_scans = hal_set_ui32(inst->hal.param.fast_scans, 63); + fast_scans = hal_set_uint(inst->hal.param.fast_scans, 63); HM2_ERR("inm %d fastscans must be less than 63, resetting to %d \n", i,63); } - rtapi_u32 slow_scans = hal_get_ui32(inst->hal.param.slow_scans); + rtapi_uint slow_scans = hal_get_uint(inst->hal.param.slow_scans); if (slow_scans > 1023) { - slow_scans = hal_set_ui32(inst->hal.param.slow_scans, 1023); + slow_scans = hal_set_uint(inst->hal.param.slow_scans, 1023); HM2_ERR("inm %d slowscans must be less than 1023, resetting to %d \n", i,1023); } if (fast_scans < 1 ) { - fast_scans = hal_set_ui32(inst->hal.param.fast_scans, 1); + fast_scans = hal_set_uint(inst->hal.param.fast_scans, 1); HM2_ERR("inm %d fastscans must be greater than 0, resetting to %d \n", i,1); } if (slow_scans < 1) { - slow_scans = hal_set_ui32(inst->hal.param.slow_scans, 1); + slow_scans = hal_set_uint(inst->hal.param.slow_scans, 1); HM2_ERR("inm %d slowscans must be greater than 0, resetting to %d \n", i,1); } @@ -579,9 +580,9 @@ void hm2_inm_process_tram_read(hostmot2_t *hm2) { if (count_diff > 128) count_diff -= 256; if (count_diff < -128) count_diff += 256; if (!hal_get_bool(inst->hal.pin.enc0_reset)) { - hal_set_si32(inst->hal.pin.enc0_count, hal_get_si32(inst->hal.pin.enc0_count) + count_diff); + hal_set_sint(inst->hal.pin.enc0_count, hal_get_sint(inst->hal.pin.enc0_count) + count_diff); } else { - hal_set_si32(inst->hal.pin.enc0_count, 0); + hal_set_sint(inst->hal.pin.enc0_count, 0); } } @@ -592,9 +593,9 @@ void hm2_inm_process_tram_read(hostmot2_t *hm2) { if (count_diff > 128) count_diff -= 256; if (count_diff < -128) count_diff += 256; if (!hal_get_bool(inst->hal.pin.enc1_reset)) { - hal_set_si32(inst->hal.pin.enc1_count, hal_get_si32(inst->hal.pin.enc1_count) + count_diff); + hal_set_sint(inst->hal.pin.enc1_count, hal_get_sint(inst->hal.pin.enc1_count) + count_diff); } else { - hal_set_si32(inst->hal.pin.enc1_count, 0); + hal_set_sint(inst->hal.pin.enc1_count, 0); } } @@ -605,9 +606,9 @@ void hm2_inm_process_tram_read(hostmot2_t *hm2) { if (count_diff > 128) count_diff -= 256; if (count_diff < -128) count_diff += 256; if (!hal_get_bool(inst->hal.pin.enc2_reset)) { - hal_set_si32(inst->hal.pin.enc2_count, hal_get_si32(inst->hal.pin.enc2_count) + count_diff); + hal_set_sint(inst->hal.pin.enc2_count, hal_get_sint(inst->hal.pin.enc2_count) + count_diff); } else { - hal_set_si32(inst->hal.pin.enc2_count, 0); + hal_set_sint(inst->hal.pin.enc2_count, 0); } } @@ -618,9 +619,9 @@ void hm2_inm_process_tram_read(hostmot2_t *hm2) { if (count_diff > 128) count_diff -= 256; if (count_diff < -128) count_diff += 256; if (!hal_get_bool(inst->hal.pin.enc3_reset)) { - hal_set_si32(inst->hal.pin.enc3_count, hal_get_si32(inst->hal.pin.enc3_count) + count_diff); + hal_set_sint(inst->hal.pin.enc3_count, hal_get_sint(inst->hal.pin.enc3_count) + count_diff); } else { - hal_set_si32(inst->hal.pin.enc3_count, 0); + hal_set_sint(inst->hal.pin.enc3_count, 0); } } } diff --git a/src/hal/drivers/mesa-hostmot2/inmux.c b/src/hal/drivers/mesa-hostmot2/inmux.c index eee23922016..67eb19a0720 100644 --- a/src/hal/drivers/mesa-hostmot2/inmux.c +++ b/src/hal/drivers/mesa-hostmot2/inmux.c @@ -163,21 +163,21 @@ int hm2_inmux_parse_md(hostmot2_t *hm2, int md_index) { inst->scanwidth = temp; // init=20000: 20 KHz = 50 usec/scan - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(inst->hal.param.scan_rate), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(inst->hal.param.scan_rate), 20000, "%s.inmux.%02d.scan_rate", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.inmux.%02d.scan_rate', aborting\n", r, hm2->llio->name, i); goto fail1; } // init=500: 500*50 usec = 25 ms - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(inst->hal.param.slow_scans), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(inst->hal.param.slow_scans), 500, "%s.inmux.%02d.slow_scans", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.inmux.%02d.slow_scans', aborting\n", r, hm2->llio->name, i); goto fail1; } // init=5: 5*50 usec = 250 usec - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(inst->hal.param.fast_scans), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(inst->hal.param.fast_scans), 5, "%s.inmux.%02d.fast_scans", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.inmux.%02d.fast_scans', aborting\n", r, hm2->llio->name, i); @@ -207,7 +207,8 @@ int hm2_inmux_parse_md(hostmot2_t *hm2, int md_index) { HM2_ERR("error %d adding param '%s.inmux.%02d.enc3_4xmode', aborting\n", r, hm2->llio->name, i); goto fail1; } - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RO, &(inst->hal.param.scan_width), + // FIXME: The scan_width is not used anywhere + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RO, &(inst->hal.param.scan_width), temp, "%s.inmux.%02d.scan_width", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.inmux.%02d.scan_width', aborting\n", r, hm2->llio->name, i); @@ -247,28 +248,28 @@ int hm2_inmux_parse_md(hostmot2_t *hm2, int md_index) { } } - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(inst->hal.pin.enc0_count), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(inst->hal.pin.enc0_count), 0, "%s.inmux.%02d.enc0-count", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.inmux.%02d.enc0-count', aborting\n", r, hm2->llio->name, i); goto fail1; } - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(inst->hal.pin.enc1_count), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(inst->hal.pin.enc1_count), 0, "%s.inmux.%02d.enc1-count", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.inmux.%02d.enc1-count', aborting\n", r, hm2->llio->name, i); goto fail1; } - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(inst->hal.pin.enc2_count), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(inst->hal.pin.enc2_count), 0, "%s.inmux.%02d.enc2-count", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.inmux.%02d.enc2-count', aborting\n", r, hm2->llio->name, i); goto fail1; } - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(inst->hal.pin.enc3_count), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(inst->hal.pin.enc3_count), 0, "%s.inmux.%02d.enc3-count", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.inmux.%02d.enc3-count', aborting\n", r, hm2->llio->name, i); @@ -343,19 +344,19 @@ void hm2_inmux_force_write(hostmot2_t *hm2) { // setup control register and mpg_write for (i = 0; i < hm2->inmux.num_instances; i ++) { hm2_inmux_instance_t *inst = &hm2->inmux.instance[i]; - muxrate = inst->scanwidth * hal_get_ui32(inst->hal.param.scan_rate); + muxrate = inst->scanwidth * hal_get_uint(inst->hal.param.scan_rate); if (muxrate > 5000000) { muxrate = 5000000; - hal_set_ui32(inst->hal.param.scan_rate, muxrate/inst->scanwidth); + hal_set_uint(inst->hal.param.scan_rate, muxrate/inst->scanwidth); } divisor = (hm2->inmux.clock_frequency / (4 * muxrate)) - 1; - rtapi_u32 fast_scans = hal_get_ui32(inst->hal.param.fast_scans); + rtapi_uint fast_scans = hal_get_uint(inst->hal.param.fast_scans); if (fast_scans > 63) { - fast_scans = hal_set_ui32(inst->hal.param.fast_scans, 63); + fast_scans = hal_set_uint(inst->hal.param.fast_scans, 63); } - rtapi_u32 slow_scans = hal_get_ui32(inst->hal.param.slow_scans); + rtapi_uint slow_scans = hal_get_uint(inst->hal.param.slow_scans); if (slow_scans > 1023) { - slow_scans = hal_set_ui32(inst->hal.param.slow_scans, 1023); + slow_scans = hal_set_uint(inst->hal.param.slow_scans, 1023); } // global invert bit(5) fixed to true for now as this matches all existing hardware @@ -387,37 +388,37 @@ void hm2_inmux_write(hostmot2_t *hm2) { for (i = 0; i < hm2->inmux.num_instances; i ++) { hm2_inmux_instance_t *inst = &hm2->inmux.instance[i]; - muxrate = inst->scanwidth * hal_get_ui32(inst->hal.param.scan_rate); + muxrate = inst->scanwidth * hal_get_uint(inst->hal.param.scan_rate); // bound muxrate maximum frequency if (muxrate > 5000000) { muxrate = 5000000; - hal_set_ui32(inst->hal.param.scan_rate, muxrate/inst->scanwidth); - HM2_ERR("InMux %d scanrate too high, resetting to %d \n", i, hal_get_ui32(inst->hal.param.scan_rate)); + hal_set_uint(inst->hal.param.scan_rate, muxrate/inst->scanwidth); + HM2_ERR("InMux %d scanrate too high, resetting to %lu \n", i, (unsigned long)hal_get_uint(inst->hal.param.scan_rate)); } divisor = (hm2->inmux.clock_frequency / (4 * muxrate)) - 1; // bound divisor so we dont splatter into other fields if ((divisor > 1023 ) | (muxrate == 0 )) { divisor = 1023; - hal_set_ui32(inst->hal.param.scan_rate, + hal_set_uint(inst->hal.param.scan_rate, (hm2->inmux.clock_frequency/4) / (divisor +1) / inst->scanwidth); - HM2_ERR("InMux %d scanrate too low, resetting to %d \n", i, hal_get_ui32(inst->hal.param.scan_rate)); + HM2_ERR("InMux %d scanrate too low, resetting to %lu \n", i, (unsigned long)hal_get_uint(inst->hal.param.scan_rate)); } - rtapi_u32 fast_scans = hal_get_ui32(inst->hal.param.fast_scans); + rtapi_uint fast_scans = hal_get_uint(inst->hal.param.fast_scans); if (fast_scans > 63) { - fast_scans = hal_set_ui32(inst->hal.param.fast_scans, 63); + fast_scans = hal_set_uint(inst->hal.param.fast_scans, 63); HM2_ERR("InMux %d fastscans must be less than 63, resetting to %d \n", i,63); } - rtapi_u32 slow_scans = hal_get_ui32(inst->hal.param.slow_scans); + rtapi_uint slow_scans = hal_get_uint(inst->hal.param.slow_scans); if (slow_scans > 1023) { - slow_scans = hal_set_ui32(inst->hal.param.slow_scans, 1023); + slow_scans = hal_set_uint(inst->hal.param.slow_scans, 1023); HM2_ERR("InMux %d slowscans must be less than 1023, resetting to %d \n", i,1023); } if (fast_scans < 1 ) { - fast_scans = hal_set_ui32(inst->hal.param.fast_scans, 1); + fast_scans = hal_set_uint(inst->hal.param.fast_scans, 1); HM2_ERR("InMux %d fastscans must be greater than 0, resetting to %d \n", i,1); } if (slow_scans < 1) { - slow_scans = hal_set_ui32(inst->hal.param.slow_scans, 1); + slow_scans = hal_set_uint(inst->hal.param.slow_scans, 1); HM2_ERR("InMux %d slowscans must be greater than 0, resetting to %d \n", i,1); } @@ -487,9 +488,9 @@ void hm2_inmux_process_tram_read(hostmot2_t *hm2) { if (count_diff > 128) count_diff -= 256; if (count_diff < -128) count_diff += 256; if (!hal_get_bool(inst->hal.pin.enc0_reset)) { - hal_set_si32(inst->hal.pin.enc0_count, hal_get_si32(inst->hal.pin.enc0_count) + count_diff); + hal_set_sint(inst->hal.pin.enc0_count, hal_get_sint(inst->hal.pin.enc0_count) + count_diff); } else { - hal_set_si32(inst->hal.pin.enc0_count, 0); + hal_set_sint(inst->hal.pin.enc0_count, 0); } raw_count = (hm2->inmux.mpg_read_reg[i] >> 8) & 0x000000FF; count_diff = (rtapi_s32)raw_count - inst->prev_enc1_count; @@ -497,9 +498,9 @@ void hm2_inmux_process_tram_read(hostmot2_t *hm2) { if (count_diff > 128) count_diff -= 256; if (count_diff < -128) count_diff += 256; if (!hal_get_bool(inst->hal.pin.enc1_reset)) { - hal_set_si32(inst->hal.pin.enc1_count, hal_get_si32(inst->hal.pin.enc1_count) + count_diff); + hal_set_sint(inst->hal.pin.enc1_count, hal_get_sint(inst->hal.pin.enc1_count) + count_diff); } else { - hal_set_si32(inst->hal.pin.enc1_count, 0); + hal_set_sint(inst->hal.pin.enc1_count, 0); } raw_count = (hm2->inmux.mpg_read_reg[i] >> 16) & 0x000000FF; count_diff = (rtapi_s32)raw_count - inst->prev_enc2_count; @@ -507,9 +508,9 @@ void hm2_inmux_process_tram_read(hostmot2_t *hm2) { if (count_diff > 128) count_diff -= 256; if (count_diff < -128) count_diff += 256; if (!hal_get_bool(inst->hal.pin.enc2_reset)) { - hal_set_si32(inst->hal.pin.enc2_count, hal_get_si32(inst->hal.pin.enc2_count) + count_diff); + hal_set_sint(inst->hal.pin.enc2_count, hal_get_sint(inst->hal.pin.enc2_count) + count_diff); } else { - hal_set_si32(inst->hal.pin.enc2_count, 0); + hal_set_sint(inst->hal.pin.enc2_count, 0); } raw_count = (hm2->inmux.mpg_read_reg[i] >> 24) & 0x000000FF; count_diff = (rtapi_s32)raw_count - inst->prev_enc3_count; @@ -517,9 +518,9 @@ void hm2_inmux_process_tram_read(hostmot2_t *hm2) { if (count_diff > 128) count_diff -= 256; if (count_diff < -128) count_diff += 256; if (!hal_get_bool(inst->hal.pin.enc3_reset)) { - hal_set_si32(inst->hal.pin.enc3_count, hal_get_si32(inst->hal.pin.enc3_count) + count_diff); + hal_set_sint(inst->hal.pin.enc3_count, hal_get_sint(inst->hal.pin.enc3_count) + count_diff); } else { - hal_set_si32(inst->hal.pin.enc3_count, 0); + hal_set_sint(inst->hal.pin.enc3_count, 0); } } } diff --git a/src/hal/drivers/mesa-hostmot2/oneshot.c b/src/hal/drivers/mesa-hostmot2/oneshot.c index 4101a8f89af..46a80c2186e 100644 --- a/src/hal/drivers/mesa-hostmot2/oneshot.c +++ b/src/hal/drivers/mesa-hostmot2/oneshot.c @@ -75,24 +75,24 @@ void hm2_oneshot_update_rate(hostmot2_t *hm2, int i) { void hm2_oneshot_update_control(hostmot2_t *hm2, int i) { rtapi_u32 controlbuff; - if(hal_get_ui32(hm2->oneshot.instance[i].hal.pin.trigselect1) > 7) { + if(hal_get_uint(hm2->oneshot.instance[i].hal.pin.trigselect1) > 7) { HM2_ERR("oneshot %d has invalid trigger 1 select value , resetting to 0\n", i); - hal_set_ui32(hm2->oneshot.instance[i].hal.pin.trigselect1, 0); + hal_set_uint(hm2->oneshot.instance[i].hal.pin.trigselect1, 0); } - if(hal_get_ui32(hm2->oneshot.instance[i].hal.pin.trigselect2) > 7) { - HM2_ERR("oneshot %d has invalid trigger 2 select value , resetting to 0\n", i); - hal_set_ui32(hm2->oneshot.instance[i].hal.pin.trigselect2, 0); + if(hal_get_uint(hm2->oneshot.instance[i].hal.pin.trigselect2) > 7) { + HM2_ERR("oneshot %d has invalid trigger 2 select value , resetting to 0\n", i); + hal_set_uint(hm2->oneshot.instance[i].hal.pin.trigselect2, 0); } controlbuff = 0; - controlbuff |= (hal_get_ui32(hm2->oneshot.instance[i].hal.pin.trigselect1) << 0); + controlbuff |= (hal_get_uint(hm2->oneshot.instance[i].hal.pin.trigselect1) << 0); controlbuff |= (hal_get_bool(hm2->oneshot.instance[i].hal.pin.trigrise1) << 3); controlbuff |= (hal_get_bool(hm2->oneshot.instance[i].hal.pin.trigfall1) << 4); controlbuff |= (hal_get_bool(hm2->oneshot.instance[i].hal.pin.retrig1) << 5); controlbuff |= (hal_get_bool(hm2->oneshot.instance[i].hal.pin.enable1) << 6); controlbuff |= (hal_get_bool(hm2->oneshot.instance[i].hal.pin.reset1) << 7); controlbuff |= (hal_get_bool(hm2->oneshot.instance[i].hal.pin.swtrig1) << 10); - controlbuff |= ((hal_get_si32(hm2->oneshot.instance[i].hal.pin.dpll_timer_num) & 7) << 12); - controlbuff |= (hal_get_ui32(hm2->oneshot.instance[i].hal.pin.trigselect2) << 16); + controlbuff |= ((hal_get_sint(hm2->oneshot.instance[i].hal.pin.dpll_timer_num) & 7) << 12); + controlbuff |= (hal_get_uint(hm2->oneshot.instance[i].hal.pin.trigselect2) << 16); controlbuff |= (hal_get_bool(hm2->oneshot.instance[i].hal.pin.trigrise2) << 19); controlbuff |= (hal_get_bool(hm2->oneshot.instance[i].hal.pin.trigfall2) << 20); controlbuff |= (hal_get_bool(hm2->oneshot.instance[i].hal.pin.retrig2) << 21); @@ -300,21 +300,21 @@ int hm2_oneshot_parse_md(hostmot2_t *hm2, int md_index) { goto fail1; } - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_IN, &(hm2->oneshot.instance[i].hal.pin.trigselect1), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_IN, &(hm2->oneshot.instance[i].hal.pin.trigselect1), 0, "%s.oneshot.%02d.trigger_select1", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.oneshot.%02d.trigger_select1', aborting\n", r, hm2->llio->name, i); goto fail1; } - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_IN, &(hm2->oneshot.instance[i].hal.pin.trigselect2), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_IN, &(hm2->oneshot.instance[i].hal.pin.trigselect2), 0, "%s.oneshot.%02d.trigger_select2", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.oneshot.%02d.trigger_select2', aborting\n", r, hm2->llio->name, i); goto fail1; } - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_IN, &(hm2->oneshot.instance[i].hal.pin.dpll_timer_num), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_IN, &(hm2->oneshot.instance[i].hal.pin.dpll_timer_num), 0, "%s.oneshot.%02d.dpll_timer_number", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.oneshot.%02d.dpll_timer_number', aborting\n", r, hm2->llio->name, i); diff --git a/src/hal/drivers/mesa-hostmot2/periodm.c b/src/hal/drivers/mesa-hostmot2/periodm.c index afb1e1f3e8b..9a3a004a5e0 100644 --- a/src/hal/drivers/mesa-hostmot2/periodm.c +++ b/src/hal/drivers/mesa-hostmot2/periodm.c @@ -32,7 +32,7 @@ void hm2_periodm_update_limit(hostmot2_t *hm2, int i) { - rtapi_u32 averages = hal_get_ui32(hm2->periodm.instance[i].hal.pin.averages); + rtapi_uint averages = hal_get_uint(hm2->periodm.instance[i].hal.pin.averages); rtapi_real minfreq = hal_get_real(hm2->periodm.instance[i].hal.pin.minfreq); hm2->periodm.limit_reg[i] = ((double)hm2->periodm.clock_frequency / minfreq) * averages; if ((((double)hm2->periodm.clock_frequency / minfreq) * averages ) > 0xFFFFFFFF) { @@ -45,7 +45,7 @@ void hm2_periodm_update_limit(hostmot2_t *hm2, int i) { void hm2_periodm_update_mode(hostmot2_t *hm2, int i) { rtapi_u32 modebuff; rtapi_u32 filterclocks; - rtapi_u32 averages = hal_get_ui32(hm2->periodm.instance[i].hal.pin.averages); + rtapi_uint averages = hal_get_uint(hm2->periodm.instance[i].hal.pin.averages); filterclocks = (double)hal_get_real(hm2->periodm.instance[i].hal.pin.filtertc) * ((double)hm2->periodm.clock_frequency / (double)1e6); if (filterclocks > 0xFFFF) { HM2_ERR("periodm %d has invalid filter time constant, resetting to max\n", i); @@ -54,18 +54,18 @@ void hm2_periodm_update_mode(hostmot2_t *hm2, int i) { } if (averages > 0xFFF) { HM2_ERR("periodm %d has invalid averages number, resetting to max\n", i); - averages = hal_set_ui32(hm2->periodm.instance[i].hal.pin.averages, 0xFFF); + averages = hal_set_uint(hm2->periodm.instance[i].hal.pin.averages, 0xFFF); } if (averages < 1) { HM2_ERR("periodm %d has invalid averages number, resetting to min\n", i); - averages = hal_set_ui32(hm2->periodm.instance[i].hal.pin.averages, 1); + averages = hal_set_uint(hm2->periodm.instance[i].hal.pin.averages, 1); } modebuff = 0; modebuff |= (hal_get_bool(hm2->periodm.instance[i].hal.pin.polarity) << 0); - modebuff |= ((averages-1) << 4); + modebuff |= (rtapi_u32)((averages-1) << 4); modebuff |= (filterclocks << 16); - hm2->periodm.mode_write_reg[i] = modebuff; + hm2->periodm.mode_write_reg[i] = modebuff; } void hm2_periodm_update_regs(hostmot2_t *hm2) { @@ -259,7 +259,7 @@ int hm2_periodm_parse_md(hostmot2_t *hm2, int md_index) { goto fail1; } - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_IO, &(hm2->periodm.instance[i].hal.pin.averages), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_IO, &(hm2->periodm.instance[i].hal.pin.averages), 1, "%s.periodm.%02d.averages", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.periodm.%02d.averages', aborting\n", r, hm2->llio->name, i); @@ -346,7 +346,7 @@ void hm2_periodm_process_tram_read(hostmot2_t *hm2) { int i; rtapi_u32 mode = 0; for (i = 0; i < hm2->periodm.num_instances; i ++) { - rtapi_u32 averages = hal_get_ui32(hm2->periodm.instance[i].hal.pin.averages); + rtapi_uint averages = hal_get_uint(hm2->periodm.instance[i].hal.pin.averages); mode = hm2->periodm.mode_read_reg[i]; // hal_set_bool(hm2->periodm.instance[i].hal.pin.polarity, (mode & (1 << 0)) != 0); hal_set_bool(hm2->periodm.instance[i].hal.pin.valid, (mode & (1 << 1)) != 0); diff --git a/src/hal/drivers/mesa-hostmot2/pwmgen.c b/src/hal/drivers/mesa-hostmot2/pwmgen.c index 1ea78d90bb6..8e399434fbe 100644 --- a/src/hal/drivers/mesa-hostmot2/pwmgen.c +++ b/src/hal/drivers/mesa-hostmot2/pwmgen.c @@ -34,9 +34,9 @@ void hm2_pwmgen_handle_pwm_frequency(hostmot2_t *hm2) { rtapi_u32 dds; - if (hal_get_ui32(hm2->pwmgen.hal->param.pwm_frequency) < 1) { - HM2_ERR("pwmgen.pwm_frequency %d is too low, setting to 1\n", hal_get_ui32(hm2->pwmgen.hal->param.pwm_frequency)); - hal_set_ui32(hm2->pwmgen.hal->param.pwm_frequency, 1); + if (hal_get_uint(hm2->pwmgen.hal->param.pwm_frequency) < 1) { + HM2_ERR("pwmgen.pwm_frequency %lu is too low, setting to 1\n", (unsigned long)hal_get_uint(hm2->pwmgen.hal->param.pwm_frequency)); + hal_set_uint(hm2->pwmgen.hal->param.pwm_frequency, 1); } @@ -65,7 +65,7 @@ void hm2_pwmgen_handle_pwm_frequency(hostmot2_t *hm2) { // // can we do it with 12 bits? - dds = ((double)hal_get_ui32(hm2->pwmgen.hal->param.pwm_frequency) * 65536.0 * 4096.0) / (double)hm2->pwmgen.clock_frequency; + dds = ((double)hal_get_uint(hm2->pwmgen.hal->param.pwm_frequency) * 65536.0 * 4096.0) / (double)hm2->pwmgen.clock_frequency; if (dds < 65536) { hm2->pwmgen.pwmgen_master_rate_dds_reg = dds; hm2->pwmgen.pwm_bits = 12; @@ -73,7 +73,7 @@ void hm2_pwmgen_handle_pwm_frequency(hostmot2_t *hm2) { } // try 11 bits - dds = ((double)hal_get_ui32(hm2->pwmgen.hal->param.pwm_frequency) * 65536.0 * 2048.0) / (double)hm2->pwmgen.clock_frequency; + dds = ((double)hal_get_uint(hm2->pwmgen.hal->param.pwm_frequency) * 65536.0 * 2048.0) / (double)hm2->pwmgen.clock_frequency; if (dds < 65536) { hm2->pwmgen.pwmgen_master_rate_dds_reg = dds; hm2->pwmgen.pwm_bits = 11; @@ -81,7 +81,7 @@ void hm2_pwmgen_handle_pwm_frequency(hostmot2_t *hm2) { } // try 10 bits - dds = ((double)hal_get_ui32(hm2->pwmgen.hal->param.pwm_frequency) * 65536.0 * 1024.0) / (double)hm2->pwmgen.clock_frequency; + dds = ((double)hal_get_uint(hm2->pwmgen.hal->param.pwm_frequency) * 65536.0 * 1024.0) / (double)hm2->pwmgen.clock_frequency; if (dds < 65536) { hm2->pwmgen.pwmgen_master_rate_dds_reg = dds; hm2->pwmgen.pwm_bits = 10; @@ -89,7 +89,7 @@ void hm2_pwmgen_handle_pwm_frequency(hostmot2_t *hm2) { } // try 9 bits - dds = ((double)hal_get_ui32(hm2->pwmgen.hal->param.pwm_frequency) * 65536.0 * 512.0) / (double)hm2->pwmgen.clock_frequency; + dds = ((double)hal_get_uint(hm2->pwmgen.hal->param.pwm_frequency) * 65536.0 * 512.0) / (double)hm2->pwmgen.clock_frequency; if (dds < 65536) { hm2->pwmgen.pwmgen_master_rate_dds_reg = dds; hm2->pwmgen.pwm_bits = 9; @@ -99,8 +99,8 @@ void hm2_pwmgen_handle_pwm_frequency(hostmot2_t *hm2) { // no joy, lower frequency until it'll work with 9 bits // From above: // PWMFreq = (ClockHigh * DDS) / (65536 * 2^PWMBits) - hal_set_ui32(hm2->pwmgen.hal->param.pwm_frequency, ((double)hm2->pwmgen.clock_frequency * 65535.0) / (65536.0 * 512.0)); - HM2_ERR("max PWM frequency is %d Hz\n", hal_get_ui32(hm2->pwmgen.hal->param.pwm_frequency)); + hal_set_uint(hm2->pwmgen.hal->param.pwm_frequency, ((double)hm2->pwmgen.clock_frequency * 65535.0) / (65536.0 * 512.0)); + HM2_ERR("max PWM frequency is %lu Hz\n", (unsigned long)hal_get_uint(hm2->pwmgen.hal->param.pwm_frequency)); hm2->pwmgen.pwmgen_master_rate_dds_reg = 65535; hm2->pwmgen.pwm_bits = 9; } @@ -110,9 +110,9 @@ void hm2_pwmgen_handle_pdm_frequency(hostmot2_t *hm2) { rtapi_u32 dds; - if (hal_get_ui32(hm2->pwmgen.hal->param.pdm_frequency) < 1) { - HM2_ERR("pwmgen.pdm_frequency %d is too low, setting to 1\n", hal_get_ui32(hm2->pwmgen.hal->param.pdm_frequency)); - hal_set_ui32(hm2->pwmgen.hal->param.pdm_frequency, 1); + if (hal_get_uint(hm2->pwmgen.hal->param.pdm_frequency) < 1) { + HM2_ERR("pwmgen.pdm_frequency %lu is too low, setting to 1\n", (unsigned long)hal_get_uint(hm2->pwmgen.hal->param.pdm_frequency)); + hal_set_uint(hm2->pwmgen.hal->param.pdm_frequency, 1); } @@ -151,14 +151,14 @@ void hm2_pwmgen_handle_pdm_frequency(hostmot2_t *hm2) { // // can we do it with 12 bits? - dds = ((double)hal_get_ui32(hm2->pwmgen.hal->param.pdm_frequency) * 65536.0) / (double)hm2->pwmgen.clock_frequency; + dds = ((double)hal_get_uint(hm2->pwmgen.hal->param.pdm_frequency) * 65536.0) / (double)hm2->pwmgen.clock_frequency; if (dds == 0) { // too slow, set frequency to minimum // From above: // PulseFreq = (ClockHigh * DDS) / 65536 dds = 1; - hal_set_ui32(hm2->pwmgen.hal->param.pdm_frequency, ((double)hm2->pwmgen.clock_frequency * (double)dds) / 65536.0); - HM2_ERR("min PDM frequency is %d Hz\n", hal_get_ui32(hm2->pwmgen.hal->param.pdm_frequency)); + hal_set_uint(hm2->pwmgen.hal->param.pdm_frequency, ((double)hm2->pwmgen.clock_frequency * (double)dds) / 65536.0); + HM2_ERR("min PDM frequency is %lu Hz\n", (unsigned long)hal_get_uint(hm2->pwmgen.hal->param.pdm_frequency)); hm2->pwmgen.pdmgen_master_rate_dds_reg = 1; return; } @@ -172,8 +172,8 @@ void hm2_pwmgen_handle_pdm_frequency(hostmot2_t *hm2) { // user wants too much, lower frequency until it'll work with 12 bits // From above: // PulseFreq = (ClockHigh * DDS) / 65536 - hal_set_ui32(hm2->pwmgen.hal->param.pdm_frequency, ((double)hm2->pwmgen.clock_frequency * 65535.0) / 65536.0); - HM2_ERR("max PDM frequency is %d Hz\n", hal_get_ui32(hm2->pwmgen.hal->param.pdm_frequency)); + hal_set_uint(hm2->pwmgen.hal->param.pdm_frequency, ((double)hm2->pwmgen.clock_frequency * 65535.0) / 65536.0); + HM2_ERR("max PDM frequency is %lu Hz\n", (unsigned long)hal_get_uint(hm2->pwmgen.hal->param.pdm_frequency)); hm2->pwmgen.pdmgen_master_rate_dds_reg = 65535; } @@ -219,7 +219,7 @@ void hm2_pwmgen_force_write(hostmot2_t *hm2) { hm2->pwmgen.pwm_mode_reg[i] = pwm_width; - switch (hal_get_si32(hm2->pwmgen.instance[i].hal.param.output_type)) { + switch (hal_get_sint(hm2->pwmgen.instance[i].hal.param.output_type)) { case HM2_PWMGEN_OUTPUT_TYPE_PWM: { // leave the Output Mode bits 0 double_buffered = 1; @@ -246,8 +246,8 @@ void hm2_pwmgen_force_write(hostmot2_t *hm2) { default: { // unknown pwm mode! complain and switch to pwm/dir HM2_ERR( - "invalid pwmgen output_type %d requested\n", - hal_get_si32(hm2->pwmgen.instance[i].hal.param.output_type) + "invalid pwmgen output_type %ld requested\n", + (long)hal_get_sint(hm2->pwmgen.instance[i].hal.param.output_type) ); HM2_ERR( "supported .output-type values are: %d (PWM & Dir), %d (Up & Down), %d (PDM & Dir), and %d (Dir & PWM)\n", @@ -257,7 +257,7 @@ void hm2_pwmgen_force_write(hostmot2_t *hm2) { HM2_PWMGEN_OUTPUT_TYPE_PWM_SWAPPED ); HM2_ERR("switching to 1 (PWM & Dir)\n"); - hal_set_si32(hm2->pwmgen.instance[i].hal.param.output_type, HM2_PWMGEN_OUTPUT_TYPE_PWM); + hal_set_sint(hm2->pwmgen.instance[i].hal.param.output_type, HM2_PWMGEN_OUTPUT_TYPE_PWM); double_buffered = 1; // leave the Output Mode bits 0 break; @@ -290,14 +290,14 @@ void hm2_pwmgen_force_write(hostmot2_t *hm2) { if (hal_get_bool(*hm2->llio->io_error)) return; for (i = 0; i < hm2->pwmgen.num_instances; i ++) { - hm2->pwmgen.instance[i].written_output_type = hal_get_si32(hm2->pwmgen.instance[i].hal.param.output_type); + hm2->pwmgen.instance[i].written_output_type = hal_get_sint(hm2->pwmgen.instance[i].hal.param.output_type); hm2->pwmgen.instance[i].written_offset_mode = hal_get_bool(hm2->pwmgen.instance[i].hal.param.offset_mode); hm2->pwmgen.instance[i].written_dither = hal_get_bool(hm2->pwmgen.instance[i].hal.param.dither); hm2->pwmgen.instance[i].written_enable = hal_get_bool(hm2->pwmgen.instance[i].hal.pin.enable); } - hm2->pwmgen.written_pwm_frequency = hal_get_ui32(hm2->pwmgen.hal->param.pwm_frequency); - hm2->pwmgen.written_pdm_frequency = hal_get_ui32(hm2->pwmgen.hal->param.pdm_frequency); + hm2->pwmgen.written_pwm_frequency = hal_get_uint(hm2->pwmgen.hal->param.pwm_frequency); + hm2->pwmgen.written_pdm_frequency = hal_get_uint(hm2->pwmgen.hal->param.pdm_frequency); } @@ -314,7 +314,7 @@ void hm2_pwmgen_write(hostmot2_t *hm2) { // check output type for (i = 0; i < hm2->pwmgen.num_instances; i ++) { - if (hal_get_si32(hm2->pwmgen.instance[i].hal.param.output_type) != hm2->pwmgen.instance[i].written_output_type) { + if (hal_get_sint(hm2->pwmgen.instance[i].hal.param.output_type) != hm2->pwmgen.instance[i].written_output_type) { goto force_write; } } @@ -333,8 +333,8 @@ void hm2_pwmgen_write(hostmot2_t *hm2) { } // check pwm & pdm frequency - if (hal_get_ui32(hm2->pwmgen.hal->param.pwm_frequency) != hm2->pwmgen.written_pwm_frequency) goto force_write; - if (hal_get_ui32(hm2->pwmgen.hal->param.pdm_frequency) != hm2->pwmgen.written_pdm_frequency) goto force_write; + if (hal_get_uint(hm2->pwmgen.hal->param.pwm_frequency) != hm2->pwmgen.written_pwm_frequency) goto force_write; + if (hal_get_uint(hm2->pwmgen.hal->param.pdm_frequency) != hm2->pwmgen.written_pdm_frequency) goto force_write; // update enable register? for (i = 0; i < hm2->pwmgen.num_instances; i ++) { @@ -450,7 +450,7 @@ int hm2_pwmgen_parse_md(hostmot2_t *hm2, int md_index) { // export to HAL { // these hal parameters affect all pwmgen instances - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(hm2->pwmgen.hal->param.pwm_frequency), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(hm2->pwmgen.hal->param.pwm_frequency), 20000, "%s.pwmgen.pwm_frequency", hm2->llio->name); if (r < 0) { HM2_ERR("error %d adding '%s.pwmgen.pwm_frequency' param, aborting\n", r, hm2->llio->name); @@ -458,7 +458,7 @@ int hm2_pwmgen_parse_md(hostmot2_t *hm2, int md_index) { } hm2->pwmgen.written_pwm_frequency = 0; - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(hm2->pwmgen.hal->param.pdm_frequency), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(hm2->pwmgen.hal->param.pdm_frequency), 20000, "%s.pwmgen.pdm_frequency", hm2->llio->name); if (r < 0) { HM2_ERR("error %d adding '%s.pwmgen.pdm_frequency' param, aborting\n", r, hm2->llio->name); @@ -512,7 +512,7 @@ int hm2_pwmgen_parse_md(hostmot2_t *hm2, int md_index) { goto fail1; } - r = hal_param_new_si32(hm2->llio->comp_id, HAL_RW, &(hm2->pwmgen.instance[i].hal.param.output_type), + r = hal_param_new_sint(hm2->llio->comp_id, HAL_RW, &(hm2->pwmgen.instance[i].hal.param.output_type), HM2_PWMGEN_OUTPUT_TYPE_PWM, "%s.pwmgen.%02d.output-type", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.pwmgen.%02d.output-type', aborting\n", r, hm2->llio->name, i); @@ -614,7 +614,7 @@ void hm2_pwmgen_prepare_tram_write(hostmot2_t *hm2) { // duty_cycle goes from 0.0 to 1.0, and needs to be puffed out to pwm_bits (if it's pwm) or 12 (if it's pdm) if (!hal_get_bool(hm2->pwmgen.instance[i].hal.param.offset_mode)) { //normal PWM/PDM modes - if (hal_get_si32(hm2->pwmgen.instance[i].hal.param.output_type) == HM2_PWMGEN_OUTPUT_TYPE_PDM) { + if (hal_get_sint(hm2->pwmgen.instance[i].hal.param.output_type) == HM2_PWMGEN_OUTPUT_TYPE_PDM) { bits = 12; } else { bits = hm2->pwmgen.pwm_bits; @@ -631,7 +631,7 @@ void hm2_pwmgen_prepare_tram_write(hostmot2_t *hm2) { } else { // offset PWM/PDM modes where 0 PWM value = 50% duty cycle also choose active low - if (hal_get_si32(hm2->pwmgen.instance[i].hal.param.output_type) == HM2_PWMGEN_OUTPUT_TYPE_PDM) { + if (hal_get_sint(hm2->pwmgen.instance[i].hal.param.output_type) == HM2_PWMGEN_OUTPUT_TYPE_PDM) { bits = 11; } else { bits = hm2->pwmgen.pwm_bits -1; diff --git a/src/hal/drivers/mesa-hostmot2/raw.c b/src/hal/drivers/mesa-hostmot2/raw.c index 7ff03639ee2..ac2768d756c 100644 --- a/src/hal/drivers/mesa-hostmot2/raw.c +++ b/src/hal/drivers/mesa-hostmot2/raw.c @@ -1,4 +1,3 @@ - // // Copyright (C) 2007-2008 Sebastian Kuzminsky // @@ -17,7 +16,6 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // - #include #include @@ -26,8 +24,6 @@ #include "hostmot2.h" - - int hm2_raw_setup(hostmot2_t *hm2) { int r; @@ -43,41 +39,48 @@ int hm2_raw_setup(hostmot2_t *hm2) { return -ENOMEM; } - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_IN, &(hm2->raw->hal.pin.read_address), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_IN, &(hm2->raw->hal.pin.read_address), 0, "%s.raw.read_address", hm2->llio->name); if (r < 0) { HM2_ERR("error %d adding pin '%s.raw.read_address', aborting\n", r, hm2->llio->name); return -EINVAL; } - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_OUT, &(hm2->raw->hal.pin.read_data), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_OUT, &(hm2->raw->hal.pin.read_data), 0, "%s.raw.read_data", hm2->llio->name); if (r < 0) { HM2_ERR("error %d adding pin '%s.raw.read_data', aborting\n", r, hm2->llio->name); return -EINVAL; } - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_IN, &(hm2->raw->hal.pin.write_address), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_IN, &(hm2->raw->hal.pin.write_address), 0, "%s.raw.write_address", hm2->llio->name); if (r < 0) { HM2_ERR("error %d adding pin '%s.raw.write_address', aborting\n", r, hm2->llio->name); return -EINVAL; } - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_IN, &(hm2->raw->hal.pin.write_data), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_IN, &(hm2->raw->hal.pin.write_data), 0, "%s.raw.write_data", hm2->llio->name); if (r < 0) { HM2_ERR("error %d adding pin '%s.raw.write_data', aborting\n", r, hm2->llio->name); return -EINVAL; } - r = hal_pin_new_bool(hm2->llio->comp_id, HAL_IN, &(hm2->raw->hal.pin.write_strobe), + r = hal_pin_new_bool(hm2->llio->comp_id, HAL_IO, &(hm2->raw->hal.pin.write_strobe), 0, "%s.raw.write_strobe", hm2->llio->name); if (r < 0) { HM2_ERR("error %d adding pin '%s.raw.write_strobe', aborting\n", r, hm2->llio->name); return -EINVAL; } + r = hal_pin_new_bool(hm2->llio->comp_id, HAL_IN, &(hm2->raw->hal.pin.write_queued), + 0, "%s.raw.write_queued", hm2->llio->name); + if (r < 0) { + HM2_ERR("error %d adding pin '%s.raw.write_queued', aborting\n", r, hm2->llio->name); + return -EINVAL; + } + r = hal_pin_new_bool(hm2->llio->comp_id, HAL_IO, &(hm2->raw->hal.pin.dump_state), 0, "%s.raw.dump_state", hm2->llio->name); if (r < 0) { @@ -88,18 +91,22 @@ int hm2_raw_setup(hostmot2_t *hm2) { return 0; } +void hm2_raw_queue_read(hostmot2_t *hm2) { + if (hm2->config.enable_raw == 0) return; + // The previous read should be resolved when we get here. + // Update the pin with the previous round's value. + hal_set_uint(hm2->raw->hal.pin.read_data, hm2->raw->valread); + // If we can queue the read, do so + int (*readfn)(hm2_lowlevel_io_t *, rtapi_u32, void *, int); + readfn = hm2->llio->queue_read ? hm2->llio->queue_read : hm2->llio->read; -void hm2_raw_queue_read(hostmot2_t *hm2) { - if (hm2->config.enable_raw == 0) return; + rtapi_u32 addr = hal_get_uint(hm2->raw->hal.pin.read_address) & 0xffff; - hm2->llio->queue_read( - hm2->llio, - hal_get_ui32(hm2->raw->hal.pin.read_address) & 0xffff, - (void *)hm2->raw->hal.pin.read_data, - sizeof(rtapi_u32) - ); + // The storage location for the read value is located in the + // persistent storage of the hm2_raw_t structure. + readfn(hm2->llio, addr, &hm2->raw->valread, sizeof(hm2->raw->valread)); if (hal_get_bool(hm2->raw->hal.pin.dump_state)) { hm2_print_modules(hm2); @@ -107,20 +114,23 @@ void hm2_raw_queue_read(hostmot2_t *hm2) { } } - - - void hm2_raw_write(hostmot2_t *hm2) { if (hm2->config.enable_raw == 0) return; if (!hal_get_bool(hm2->raw->hal.pin.write_strobe)) return; - hm2->llio->write( - hm2->llio, - hal_get_ui32(hm2->raw->hal.pin.write_address) & 0xffff, - (void *)hm2->raw->hal.pin.write_data, - sizeof(rtapi_u32) - ); + // If we can queue the write, do so + int (*writefn)(hm2_lowlevel_io_t *, rtapi_u32, const void *, int); + int queue = hal_get_bool(hm2->raw->hal.pin.write_queued); + writefn = queue && hm2->llio->queue_write ? hm2->llio->queue_write : hm2->llio->write; + + rtapi_u32 addr = hal_get_uint(hm2->raw->hal.pin.write_address) & 0xffff; + + // The value to write is located in the persistent storage of the + // hm2_raw_t structure. + hm2->raw->valwrite = (rtapi_u32)hal_get_uint(hm2->raw->hal.pin.write_data); + writefn(hm2->llio, addr, &hm2->raw->valwrite, sizeof(hm2->raw->valwrite)); + // Reset the strobe hal_set_bool(hm2->raw->hal.pin.write_strobe, 0); } diff --git a/src/hal/drivers/mesa-hostmot2/resolver.c b/src/hal/drivers/mesa-hostmot2/resolver.c index f8c3a064ac2..e40566e4797 100644 --- a/src/hal/drivers/mesa-hostmot2/resolver.c +++ b/src/hal/drivers/mesa-hostmot2/resolver.c @@ -178,14 +178,14 @@ int hm2_resolver_parse_md(hostmot2_t *hm2, int md_index) { goto fail1; } - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(hm2->resolver.instance[i].hal.pin.count), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(hm2->resolver.instance[i].hal.pin.count), 0, "%s.resolver.%02d.count", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.resolver.%02d.count', aborting\n", r, hm2->llio->name, i); goto fail1; } - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(hm2->resolver.instance[i].hal.pin.rawcounts), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(hm2->resolver.instance[i].hal.pin.rawcounts), 0, "%s.resolver.%02d.rawcounts", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.resolver.%02d.rawcounts', aborting\n", r, hm2->llio->name, i); @@ -235,7 +235,7 @@ int hm2_resolver_parse_md(hostmot2_t *hm2, int md_index) { goto fail1; } - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(hm2->resolver.instance[i].hal.param.index_div), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(hm2->resolver.instance[i].hal.param.index_div), 1, "%s.resolver.%02d.index-divisor", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.resolver.%02d.index-divisor', aborting\n", r, hm2->llio->name, i); @@ -326,7 +326,7 @@ void hm2_resolver_process_tram_read(hostmot2_t *hm2, long period) { if ((res->old_reg > hm2->resolver.position_reg[i]) && (res->old_reg - hm2->resolver.position_reg[i] > 0x80000000)){ res->index_cnts++; if (hal_get_bool(res->hal.pin.index_enable)){ - rtapi_u32 index_div = hal_get_ui32(res->hal.param.index_div); + rtapi_uint index_div = hal_get_uint(res->hal.param.index_div); int r = (res->index_cnts % index_div); if ((index_div > 1 && r == 1) || (index_div == 1 && r == 0)){ @@ -337,7 +337,7 @@ void hm2_resolver_process_tram_read(hostmot2_t *hm2, long period) { } else if ((res->old_reg < hm2->resolver.position_reg[i]) && (hm2->resolver.position_reg[i] - res->old_reg > 0x80000000)){ res->index_cnts--; - if (hal_get_bool(res->hal.pin.index_enable) && (res->index_cnts % hal_get_ui32(res->hal.param.index_div) == 0)){ + if (hal_get_bool(res->hal.pin.index_enable) && (res->index_cnts % hal_get_uint(res->hal.param.index_div) == 0)){ res->offset = (res->accum - hm2->resolver.position_reg[i] + 0x100000000LL); hal_set_bool(res->hal.pin.index_enable, 0); } @@ -350,8 +350,8 @@ void hm2_resolver_process_tram_read(hostmot2_t *hm2, long period) { res->old_reg = hm2->resolver.position_reg[i]; hal_set_real(res->hal.pin.angle, hm2->resolver.position_reg[i] / 0x1P32); - hal_set_si32(res->hal.pin.rawcounts, (res->accum >> 8)); - hal_set_si32(res->hal.pin.count, (res->accum - res->offset) >> 8); + hal_set_sint(res->hal.pin.rawcounts, (res->accum >> 8)); + hal_set_sint(res->hal.pin.count, (res->accum - res->offset) >> 8); hal_set_real(res->hal.pin.position, (res->accum - res->offset) / 0x1P32 * hal_get_real(res->hal.param.scale)); hal_set_real(res->hal.pin.velocity, ((hm2->resolver.velocity_reg[i] / 0x1P32) diff --git a/src/hal/drivers/mesa-hostmot2/sserial.c b/src/hal/drivers/mesa-hostmot2/sserial.c index bf70a0cc307..6a9a486936c 100644 --- a/src/hal/drivers/mesa-hostmot2/sserial.c +++ b/src/hal/drivers/mesa-hostmot2/sserial.c @@ -65,7 +65,7 @@ int hm2_sserial_wait(hostmot2_t *hm2, hm2_sserial_instance_t *inst, long period) // real-time wait function (relies on process data) *inst->command_reg_write = 0x80000000; // mask pointless writes inst->timer -= period; - hal_set_si32(inst->debug, inst->timer); + hal_set_sint(inst->debug, inst->timer); if (*inst->command_reg_read != 0) { if (inst->timer > 0) { return 1; @@ -856,7 +856,7 @@ int hm2_sserial_parse_md(hostmot2_t *hm2, int md_index){ int hm2_sserial_setup_channel(hostmot2_t *hm2, hm2_sserial_instance_t *inst, int index){ int r; - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(inst->debug), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(inst->debug), 0, "%s.%i.debug", hm2->llio->name, index); if (r < 0) { HM2_ERR("error %d adding pin %s.sserial.%1d.run. aborting\n", @@ -872,21 +872,21 @@ int hm2_sserial_setup_channel(hostmot2_t *hm2, hm2_sserial_instance_t *inst, int return -EINVAL; } - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_OUT, &(inst->state), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_OUT, &(inst->state), 0, "%s.sserial.port-%1d.port_state", hm2->llio->name, index); if (r < 0) { HM2_ERR("error %d adding pin %s.sserial.%1d.port_state. aborting\n", r, hm2->llio->name, index); return -EINVAL; } - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_OUT, &(inst->state2), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_OUT, &(inst->state2), 0, "%s.sserial.port-%1d.port_state2", hm2->llio->name, index); if (r < 0) { HM2_ERR("error %d adding pin %s.sserial.%1d.port_state. aborting\n", r, hm2->llio->name, index); return -EINVAL; } - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_OUT, &(inst->state3), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_OUT, &(inst->state3), 0, "%s.sserial.port-%1d.port_state3", hm2->llio->name, index); if (r < 0) { HM2_ERR("error %d adding pin %s.sserial.%1d.port_state. aborting\n", @@ -894,14 +894,14 @@ int hm2_sserial_setup_channel(hostmot2_t *hm2, hm2_sserial_instance_t *inst, int return -EINVAL; } - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_OUT, &(inst->fault_count), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_OUT, &(inst->fault_count), 0, "%s.sserial.port-%1d.fault-count", hm2->llio->name, index); if (r < 0) { HM2_ERR("error %d adding pin %s.sserial.%1d.fault-count. aborting\n", r, hm2->llio->name, index); return -EINVAL; } - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(inst->fault_inc), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(inst->fault_inc), 10, "%s.sserial.port-%1d.fault-inc", hm2->llio->name, index); if (r < 0) { HM2_ERR("error %d adding parameter %s.sserial.port-%1d.fault-inc" @@ -909,7 +909,7 @@ int hm2_sserial_setup_channel(hostmot2_t *hm2, hm2_sserial_instance_t *inst, int return -EINVAL; } - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(inst->fault_dec), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(inst->fault_dec), 1, "%s.sserial.port-%1d.fault-dec", hm2->llio->name, index); if (r < 0) { HM2_ERR("error %d adding parameter %s.sserial.port-%1d.fault-dec" @@ -917,7 +917,7 @@ int hm2_sserial_setup_channel(hostmot2_t *hm2, hm2_sserial_instance_t *inst, int return -EINVAL; } - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(inst->fault_lim), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(inst->fault_lim), 200, "%s.sserial.port-%1d.fault-lim", hm2->llio->name, index); if (r < 0) { HM2_ERR("error %d adding parameter %s.sserial.port-%1d.fault-lim" @@ -1269,13 +1269,13 @@ int hm2_sserial_create_pins(hostmot2_t *hm2, hm2_sserial_remote_t *chan){ break; case LBP_ENCODER: case LBP_ENCODER_H: - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(chan->pins[i].s32_pin), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(chan->pins[i].s32_pin), 0, "%s.%s.count", chan->name, chan->confs[i].NameString); if (r < 0) { HM2_ERR("error %d adding pin '%s.%s.count', aborting\n", r, chan->name, chan->confs[i].NameString); return -EINVAL; } - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(chan->pins[i].s32_pin2), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(chan->pins[i].s32_pin2), 0, "%s.%s.rawcounts", chan->name, chan->confs[i].NameString); if (r < 0) { HM2_ERR("error %d adding pin '%s.%s.rawcounts', aborting\n", r, chan->name, chan->confs[i].NameString); @@ -1308,7 +1308,7 @@ int hm2_sserial_create_pins(hostmot2_t *hm2, hm2_sserial_remote_t *chan){ return -EINVAL; } - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(chan->pins[i].u32_param), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(chan->pins[i].u32_param), 256, "%s.%s.counts-per-rev", chan->name, chan->confs[i].NameString); if (r < 0) { HM2_ERR("error %d adding pin '%s.%s.counts-per-rev', aborting\n", @@ -1393,11 +1393,11 @@ int hm2_sserial_register_tram(hostmot2_t *hm2, hm2_sserial_remote_t *chan){ hm2_sserial_data_t *g; int shift; // used for floating point comparisons - switch (hal_get_ui32(inst->state2)){ + switch (hal_get_uint(inst->state2)){ case 0: // init loop counters inst->r_index = 0; inst->g_index = 0; - hal_set_ui32(inst->state2, 1); + hal_set_uint(inst->state2, 1); /* Fallthrough */ case 1: if (inst->num_remotes == 0) return 0; @@ -1406,15 +1406,15 @@ int hm2_sserial_register_tram(hostmot2_t *hm2, hm2_sserial_remote_t *chan){ p = &(r->params[inst->g_index]); g = &(r->globals[inst->g_index]); } else { - hal_set_ui32(inst->state2, 2); + hal_set_uint(inst->state2, 2); break; } - switch (hal_get_ui32(inst->state3)){ + switch (hal_get_uint(inst->state3)){ //Commands are queued for TRAM write, so every change in //command needs a break to poll the thread int ret; default: - HM2_ERR("Unhandled state %i", hal_get_ui32(inst->state3)); + HM2_ERR("Unhandled state %lu", (unsigned long)hal_get_uint(inst->state3)); return 1; case 0: HM2_DBG("Checking Param %s datatype %02X\n", g->NameString, p->type); @@ -1422,11 +1422,11 @@ int hm2_sserial_register_tram(hostmot2_t *hm2, hm2_sserial_remote_t *chan){ case LBP_SIGNED: case LBP_NONVOL_SIGNED: if (hal_get_si32(p->param.s) != p->s32_written) break; - return hal_set_ui32(inst->state2, 2); // increment indices + return hal_set_uint(inst->state2, 2); // increment indices case LBP_UNSIGNED: case LBP_NONVOL_UNSIGNED: if (hal_get_ui32(p->param.u) != p->u32_written) break; - return hal_set_ui32(inst->state2, 2); // increment indices + return hal_set_uint(inst->state2, 2); // increment indices case LBP_FLOAT: case LBP_NONVOL_FLOAT: // comparing floats that might have different sizes is not trivial @@ -1448,12 +1448,12 @@ int hm2_sserial_register_tram(hostmot2_t *hm2, hm2_sserial_remote_t *chan){ } // FIXME: This overlayed s64 read is very wrong! if (xlabs((hal_get_sint(p->param.s) - p->s64_written) >> shift) > 2) break; - return hal_set_ui32(inst->state2, 2); // increment indices + return hal_set_uint(inst->state2, 2); // increment indices default: - return hal_set_ui32(inst->state2, 2); // increment indices + return hal_set_uint(inst->state2, 2); // increment indices } HM2_WARN("Writing value of %s datatype %02X\n", g->NameString, p->type); - hal_set_ui32(inst->state3, 1); + hal_set_uint(inst->state3, 1); inst->timer = 20000000; *inst->command_reg_write = 0x800; // stop all break; @@ -1461,8 +1461,8 @@ int hm2_sserial_register_tram(hostmot2_t *hm2, hm2_sserial_remote_t *chan){ ret = hm2_sserial_wait(hm2, inst, period); if (ret > 0) break; // FIXME: Assigns 100 to state3 and then unconditionally assigns 2 - if (ret < 0) hal_set_ui32(inst->state3, 100); // quit and tidy up - hal_set_ui32(inst->state3, 2); + if (ret < 0) hal_set_uint(inst->state3, 100); // quit and tidy up + hal_set_uint(inst->state3, 2); inst->timer = 20000000; *inst->command_reg_write = 0xF00 | (1 << r->index); // channel in setup mode break; @@ -1470,7 +1470,7 @@ int hm2_sserial_register_tram(hostmot2_t *hm2, hm2_sserial_remote_t *chan){ ret = hm2_sserial_wait(hm2, inst, period); if (ret > 0) break; // FIXME: Assigns 100 to state3 and then 3 or 4 inside the if/else. - if (ret < 0) hal_set_ui32(inst->state3, 100); // quit and tidy up + if (ret < 0) hal_set_uint(inst->state3, 100); // quit and tidy up if ( p->type == LBP_NONVOL_FLOAT || p->type == LBP_NONVOL_UNSIGNED || p->type == LBP_NONVOL_SIGNED){ @@ -1478,21 +1478,21 @@ int hm2_sserial_register_tram(hostmot2_t *hm2, hm2_sserial_remote_t *chan){ *r->write[0] = LBPNONVOLEEPROM; *inst->command_reg_write = 0x1000 | (1 << r->index); // doit command inst->timer = 20000000; - hal_set_ui32(inst->state3, 3); + hal_set_uint(inst->state3, 3); HM2_PRINT("A non-volatile smart-serial parameter has been changed\n" "A full power-cycle will be needed before the effect is seen\n"); } else { - hal_set_ui32(inst->state3, 4); + hal_set_uint(inst->state3, 4); } break; case 3: // wait for doit clear ret = hm2_sserial_wait(hm2, inst, period); if (ret > 0) break; // FIXME: Assigns 100 to state3 and then unconditionally assigns 4 - if (ret < 0) hal_set_ui32(inst->state3, 100); // quit and tidy up + if (ret < 0) hal_set_uint(inst->state3, 100); // quit and tidy up // NV access now enabled. HM2_DBG("NV Access unlocked: param %s\n", g->NameString); - hal_set_ui32(inst->state3, 4); + hal_set_uint(inst->state3, 4); break; case 4: // Now send the data switch (p->type){ @@ -1536,13 +1536,13 @@ int hm2_sserial_register_tram(hostmot2_t *hm2, hm2_sserial_remote_t *chan){ } *inst->command_reg_write = 0x1000 | (1 << r->index); // doit command inst->timer = 200000000; - hal_set_ui32(inst->state3, 5); + hal_set_uint(inst->state3, 5); break; case 5: // wait for doit clear ret = hm2_sserial_wait(hm2, inst, period); if (ret > 0) break; // FIXME: Assigns 100 to state3 and then 7 or 8 inside the if/else. - if (ret < 0) hal_set_ui32(inst->state3, 100); // quit and tidy up + if (ret < 0) hal_set_uint(inst->state3, 100); // quit and tidy up // success? Set the written = param switch (p->type){ @@ -1571,54 +1571,54 @@ int hm2_sserial_register_tram(hostmot2_t *hm2, hm2_sserial_remote_t *chan){ *r->write[0] = LBPNONVOLCLEAR; *inst->command_reg_write = 0x1000 | (1 << r->index); // doit command inst->timer = 0x2000000; - hal_set_ui32(inst->state3, 7); + hal_set_uint(inst->state3, 7); } else { - hal_set_ui32(inst->state3, 8); + hal_set_uint(inst->state3, 8); } break; case 7: // wait for doit clear ret = hm2_sserial_wait(hm2, inst, period); if (ret > 0) break; // FIXME: Assigns 100 to state3 and then unconditionally assigns 8 - if (ret < 0) hal_set_ui32(inst->state3, 100); // quit and tidy up + if (ret < 0) hal_set_uint(inst->state3, 100); // quit and tidy up // NV access now cleared HM2_DBG("NV Access Cleared: param %s\n", g->NameString); - hal_set_ui32(inst->state3, 8); + hal_set_uint(inst->state3, 8); break; case 8: // stop-all inst->timer = 0x2000000; *inst->command_reg_write = 0x800; //stop - hal_set_ui32(inst->state3, 9); + hal_set_uint(inst->state3, 9); break; case 9: //wait for final stop-all ret = hm2_sserial_wait(hm2, inst, period); if (ret > 0) break; // FIXME: Assigns 100 to state3 and then unconditionally assigns 0 - if (ret < 0) hal_set_ui32(inst->state3, 100); // quit and tidy up + if (ret < 0) hal_set_uint(inst->state3, 100); // quit and tidy up // NV access now cleared HM2_DBG("Board out of setup mode: param %s\n", g->NameString); - hal_set_ui32(inst->state3, 0); - hal_set_ui32(inst->state2, 2); // increment indices + hal_set_uint(inst->state3, 0); + hal_set_uint(inst->state2, 2); // increment indices break; case 100: // error recovery HM2_ERR("Problem found writing sserial parameter %s\n", g->NameString); *inst->command_reg_write = 0x800; //stop all command - hal_set_ui32(inst->state3, 0); - hal_set_ui32(inst->state2, 2); // increment indices + hal_set_uint(inst->state3, 0); + hal_set_uint(inst->state2, 2); // increment indices break; } // End of switch(inst->state3) break; case 2: - hal_set_ui32(inst->state2, 1); + hal_set_uint(inst->state2, 1); if ((int)++inst->g_index >= inst->remotes[inst->r_index].num_globals){ inst->g_index = 0; if ((int)++inst->r_index >= inst->num_remotes){//checked them all - hal_set_ui32(inst->state2, 0); + hal_set_uint(inst->state2, 0); } } break; } // end of switch(inst->state2) - return hal_get_ui32(inst->state2); + return hal_get_uint(inst->state2); } void hm2_sserial_write_pins(hostmot2_t *hm2, hm2_sserial_instance_t *inst){ @@ -1630,18 +1630,18 @@ void hm2_sserial_write_pins(hostmot2_t *hm2, hm2_sserial_instance_t *inst){ // the side effect of reporting this error will suffice (void)hm2_sserial_check_remote_errors(hm2, inst); - rtapi_u32 fault_count = hal_get_ui32(inst->fault_count); - if (fault_count > hal_get_ui32(inst->fault_lim)) { + rtapi_uint fault_count = hal_get_uint(inst->fault_count); + if (fault_count > hal_get_uint(inst->fault_lim)) { // If there have been a large percentage of misses, for quite // a long time, it's time to take it seriously. hm2_sserial_check_local_errors(hm2, inst); HM2_ERR("Smart Serial Comms Error: " - "There have been more than %i errors in %i " - "thread executions at least %i times. " + "There have been more than %lu errors in %lu " + "thread executions at least %lu times. " "See other error messages for details.\n", - hal_get_ui32(inst->fault_dec), - hal_get_ui32(inst->fault_inc), - hal_get_ui32(inst->fault_lim)); + (unsigned long)hal_get_uint(inst->fault_dec), + (unsigned long)hal_get_uint(inst->fault_inc), + (unsigned long)hal_get_uint(inst->fault_lim)); HM2_ERR("***Smart Serial Port %i will be stopped***\n",inst->index); static bool printed; if(!inst->ever_read && !printed) { @@ -1651,7 +1651,7 @@ void hm2_sserial_write_pins(hostmot2_t *hm2, hm2_sserial_instance_t *inst){ "This error message will not repeat.\n"); printed = true; } - hal_set_ui32(inst->state, 10); + hal_set_uint(inst->state, 10); *inst->command_reg_write = 0x800; // stop command return; } @@ -1665,20 +1665,20 @@ void hm2_sserial_write_pins(hostmot2_t *hm2, hm2_sserial_instance_t *inst){ "if this is happening frequently.\n", inst->index, hm2->llio->name, inst->index); } - fault_count = hal_set_ui32(inst->fault_count, fault_count + hal_get_ui32(inst->fault_inc)); + fault_count = hal_set_uint(inst->fault_count, fault_count + hal_get_uint(inst->fault_inc)); *inst->command_reg_write = 0x80000000; // set bit31 for ignored cmd return; // give the register chance to clear } if (*inst->data_reg_read & 0xff) { // indicates a failed transfer - fault_count = hal_set_ui32(inst->fault_count, fault_count + hal_get_ui32(inst->fault_inc)); + fault_count = hal_set_uint(inst->fault_count, fault_count + hal_get_uint(inst->fault_inc)); } - if (fault_count > hal_get_ui32(inst->fault_dec)) { - fault_count = hal_set_ui32(inst->fault_count, fault_count - hal_get_ui32(inst->fault_dec)); + if (fault_count > hal_get_uint(inst->fault_dec)) { + fault_count = hal_set_uint(inst->fault_count, fault_count - hal_get_uint(inst->fault_dec)); } else { - fault_count = hal_set_ui32(inst->fault_count, 0); + fault_count = hal_set_uint(inst->fault_count, 0); } // All seems well, handle the pins. @@ -1775,7 +1775,7 @@ void hm2_sserial_prepare_tram_write(hostmot2_t *hm2, long period){ hm2_sserial_instance_t *inst = &(hm2->sserial.instance[i]); - switch (hal_get_ui32(inst->state) & 0xFF){ + switch (hal_get_uint(inst->state) & 0xFF){ case 0: // Idle if (! hal_get_bool(inst->run)){ break; } @@ -1785,18 +1785,18 @@ void hm2_sserial_prepare_tram_write(hostmot2_t *hm2, long period){ hm2_sserial_setmode(hm2, inst); *inst->command_reg_write = 0x900 | inst->tag; HM2_DBG("Enabled Remotes tag = = %x\n", inst->tag); - hal_set_ui32(inst->fault_count, 0); + hal_set_uint(inst->fault_count, 0); inst->doit_err_count = 0; inst->timer = 2100000000; - hal_set_ui32(inst->state, 2); + hal_set_uint(inst->state, 2); break; case 2: // just transitioning to running if (hm2_sserial_wait(hm2, inst, period) > 0) break; - hal_set_ui32(inst->state, 3); + hal_set_uint(inst->state, 3); break; case 3: // normal running if (!hal_get_bool(inst->run)){ - hal_set_ui32(inst->state, 4); + hal_set_uint(inst->state, 4); break; } hm2_sserial_write_pins(hm2, inst); @@ -1804,21 +1804,21 @@ void hm2_sserial_prepare_tram_write(hostmot2_t *hm2, long period){ case 4: // run to stop transition *inst->command_reg_write = 0x800; inst->timer = 2100000000; - hal_set_ui32(inst->state, 5); + hal_set_uint(inst->state, 5); break; case 5: if (hm2_sserial_wait(hm2, inst, period) > 0) break; - hal_set_ui32(inst->state, 0); + hal_set_uint(inst->state, 0); break; case 10:// Do-nothing state for serious errors. require run pin to cycle *inst->command_reg_write = 0x80000000; // set bit31 for ignored cmd - if ( !hal_get_bool(inst->run)){hal_set_ui32(inst->state, 0);} + if ( !hal_get_bool(inst->run)){hal_set_uint(inst->state, 0);} break; default: // Should never happen HM2_ERR("Unhandled run/stop configuration in \n" - "hm2_sserial_write (%x)\n", - hal_get_ui32(inst->state)); - hal_set_ui32(inst->state, 0); + "hm2_sserial_write (%lx)\n", + (unsigned long)hal_get_uint(inst->state)); + hal_set_uint(inst->state, 0); } } } @@ -1913,7 +1913,7 @@ int hm2_sserial_read_pins(hm2_sserial_remote_t *chan){ int bitlength; rtapi_s32 rem1, rem2; rtapi_s64 previous; - rtapi_u32 ppr = hal_get_ui32(pin->u32_param); + rtapi_uint ppr = hal_get_uint(pin->u32_param); // halpin.counts-per-rev if (conf->DataType == LBP_ENCODER){ bitlength = conf->DataLength; @@ -1976,9 +1976,9 @@ int hm2_sserial_read_pins(hm2_sserial_remote_t *chan){ } } pin->oldval = buff64; - hal_set_si32(pin->s32_pin, pin->accum - pin->offset); - hal_set_si32(pin->s32_pin2, pin->accum); - hal_set_real(pin->float_pin, (double)(pin->accum - pin->offset) / hal_get_real(pin->fullscale)); + hal_set_sint(pin->s32_pin, pin->accum - pin->offset); // halpin.count + hal_set_sint(pin->s32_pin2, pin->accum); // halpin.rawcounts + hal_set_real(pin->float_pin, (pin->accum - pin->offset) / hal_get_real(pin->fullscale)); break; case LBP_FLOAT: if (conf->DataLength == sizeof(float) * 8){ @@ -2014,7 +2014,7 @@ void hm2_sserial_process_tram_read(hostmot2_t *hm2, long period){ for (i = 0 ; i < hm2->sserial.num_instances ; i++){ hm2_sserial_instance_t *inst = &hm2->sserial.instance[i]; inst->ever_read = true; - if (hal_get_ui32(inst->state) != 3) continue ; // Only work on running instances + if (hal_get_uint(inst->state) != 3) continue ; // Only work on running instances for (c = 0 ; c < inst->num_remotes ; c++ ) { hm2_sserial_remote_t *chan = &inst->remotes[c]; hm2_sserial_read_pins(chan); diff --git a/src/hal/drivers/mesa-hostmot2/ssr.c b/src/hal/drivers/mesa-hostmot2/ssr.c index 095b927ad82..e6a15e9d1cc 100644 --- a/src/hal/drivers/mesa-hostmot2/ssr.c +++ b/src/hal/drivers/mesa-hostmot2/ssr.c @@ -127,7 +127,7 @@ int hm2_ssr_parse_md(hostmot2_t *hm2, int md_index) { { for (int i = 0; i < hm2->ssr.num_instances; i ++) { - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_IN, &(hm2->ssr.instance[i].hal.pin.rate), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_IN, &(hm2->ssr.instance[i].hal.pin.rate), 1000*1000, "%s.ssr.%02d.rate", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.ssr.%02d.rate', aborting\n", r, hm2->llio->name, i); @@ -218,7 +218,7 @@ static void hm2_ssr_compute_rate_regs(hostmot2_t *hm2) { for (i = 0; i < hm2->ssr.num_instances; i ++) { rtapi_u32 reg; - rtapi_u32 urate = hal_get_ui32(hm2->ssr.instance[i].hal.pin.rate); + rtapi_uint urate = hal_get_uint(hm2->ssr.instance[i].hal.pin.rate); if (urate <= 0) { // Writing all bits zero to the Rate register clears bit 12, // the enable bit. diff --git a/src/hal/drivers/mesa-hostmot2/stepgen.c b/src/hal/drivers/mesa-hostmot2/stepgen.c index 4daaa54f3fb..f2447563e25 100644 --- a/src/hal/drivers/mesa-hostmot2/stepgen.c +++ b/src/hal/drivers/mesa-hostmot2/stepgen.c @@ -114,7 +114,7 @@ void hm2_stepgen_process_tram_read(hostmot2_t *hm2, long l_period_ns) { inst->subcounts = 0; } - hal_set_si32(inst->hal.pin.counts, inst->subcounts >> 16); + hal_set_sint(inst->hal.pin.counts, inst->subcounts >> 16); // note that it's important to use "subcounts/65536.0" instead of just // "counts" when computing position_fb, because position_fb needs sub-count @@ -270,7 +270,7 @@ static void hm2_stepgen_instance_prepare_tram_write(hostmot2_t *hm2, long l_peri // maxvel must be >= 0.0, and may not be faster than 1 step per (steplen+stepspace) seconds { - double min_ns_per_step = hal_get_ui32(s->hal.param.steplen) + hal_get_ui32(s->hal.param.stepspace); + double min_ns_per_step = hal_get_uint(s->hal.param.steplen) + hal_get_uint(s->hal.param.stepspace); double max_steps_per_s = 1.0e9 / min_ns_per_step; physical_maxvel = max_steps_per_s / fabs(hal_get_real(s->hal.param.position_scale)); @@ -335,7 +335,7 @@ static void hm2_stepgen_instance_prepare_tram_write(hostmot2_t *hm2, long l_peri // systems. hm2->stepgen.step_rate_reg[i] = (uint32_t)(int32_t)(steps_per_sec_cmd * (4294967296.0 / (double)hm2->stepgen.clock_frequency)); - hal_set_si32(s->hal.pin.dbg_step_rate, hm2->stepgen.step_rate_reg[i]); + hal_set_sint(s->hal.pin.dbg_step_rate, hm2->stepgen.step_rate_reg[i]); } @@ -356,48 +356,48 @@ void hm2_stepgen_prepare_tram_write(hostmot2_t *hm2, long l_period_ns) { static void hm2_stepgen_update_dir_setup_time(hostmot2_t *hm2, int i) { - rtapi_u32 dirsetup = hal_get_ui32(hm2->stepgen.instance[i].hal.param.dirsetup); + rtapi_uint dirsetup = hal_get_uint(hm2->stepgen.instance[i].hal.param.dirsetup); hm2->stepgen.dir_setup_time_reg[i] = (double)dirsetup * ((double)hm2->stepgen.clock_frequency / (double)1e9); if (hm2->stepgen.dir_setup_time_reg[i] > 0x3FFF) { HM2_ERR("stepgen %d has invalid dirsetup, resetting to max\n", i); hm2->stepgen.dir_setup_time_reg[i] = 0x3FFF; - dirsetup = hal_set_ui32(hm2->stepgen.instance[i].hal.param.dirsetup, (double)hm2->stepgen.dir_setup_time_reg[i] * ((double)1e9 / (double)hm2->stepgen.clock_frequency)); + dirsetup = hal_set_uint(hm2->stepgen.instance[i].hal.param.dirsetup, (double)hm2->stepgen.dir_setup_time_reg[i] * ((double)1e9 / (double)hm2->stepgen.clock_frequency)); } hm2->stepgen.instance[i].written_dirsetup = dirsetup; } static void hm2_stepgen_update_dir_hold_time(hostmot2_t *hm2, int i) { - rtapi_u32 dirhold = hal_get_ui32(hm2->stepgen.instance[i].hal.param.dirhold); + rtapi_uint dirhold = hal_get_uint(hm2->stepgen.instance[i].hal.param.dirhold); hm2->stepgen.dir_hold_time_reg[i] = (double)dirhold * ((double)hm2->stepgen.clock_frequency / (double)1e9); if (hm2->stepgen.dir_hold_time_reg[i] > 0x3FFF) { HM2_ERR("stepgen %d has invalid dirhold, resetting to max\n", i); hm2->stepgen.dir_hold_time_reg[i] = 0x3FFF; - dirhold = hal_set_ui32(hm2->stepgen.instance[i].hal.param.dirhold, (double)hm2->stepgen.dir_hold_time_reg[i] * ((double)1e9 / (double)hm2->stepgen.clock_frequency)); + dirhold = hal_set_uint(hm2->stepgen.instance[i].hal.param.dirhold, (double)hm2->stepgen.dir_hold_time_reg[i] * ((double)1e9 / (double)hm2->stepgen.clock_frequency)); } hm2->stepgen.instance[i].written_dirhold = dirhold; } static void hm2_stepgen_update_pulse_idle_width(hostmot2_t *hm2, int i) { - rtapi_u32 stepspace = hal_get_ui32(hm2->stepgen.instance[i].hal.param.stepspace); + rtapi_uint stepspace = hal_get_uint(hm2->stepgen.instance[i].hal.param.stepspace); hm2->stepgen.pulse_idle_width_reg[i] = (double)stepspace * ((double)hm2->stepgen.clock_frequency / (double)1e9); if (hm2->stepgen.pulse_idle_width_reg[i] > 0x3FFF) { HM2_ERR("stepgen %d has invalid stepspace, resetting to max\n", i); hm2->stepgen.pulse_idle_width_reg[i] = 0x3FFF; - stepspace = hal_set_ui32(hm2->stepgen.instance[i].hal.param.stepspace, (double)hm2->stepgen.pulse_idle_width_reg[i] * ((double)1e9 / (double)hm2->stepgen.clock_frequency)); + stepspace = hal_set_uint(hm2->stepgen.instance[i].hal.param.stepspace, (double)hm2->stepgen.pulse_idle_width_reg[i] * ((double)1e9 / (double)hm2->stepgen.clock_frequency)); } hm2->stepgen.instance[i].written_stepspace = stepspace; } static void hm2_stepgen_update_pulse_width(hostmot2_t *hm2, int i) { - rtapi_u32 steplen = hal_get_ui32(hm2->stepgen.instance[i].hal.param.steplen); + rtapi_uint steplen = hal_get_uint(hm2->stepgen.instance[i].hal.param.steplen); hm2->stepgen.pulse_width_reg[i] = (double)steplen * ((double)hm2->stepgen.clock_frequency / (double)1e9); if (hm2->stepgen.pulse_width_reg[i] > 0x3FFF) { HM2_ERR("stepgen %d has invalid steplen, resetting to max\n", i); hm2->stepgen.pulse_width_reg[i] = 0x3FFF; - steplen = hal_set_ui32(hm2->stepgen.instance[i].hal.param.steplen, (double)hm2->stepgen.pulse_width_reg[i] * ((double)1e9 / (double)hm2->stepgen.clock_frequency)); + steplen = hal_set_uint(hm2->stepgen.instance[i].hal.param.steplen, (double)hm2->stepgen.pulse_width_reg[i] * ((double)1e9 / (double)hm2->stepgen.clock_frequency)); } hm2->stepgen.instance[i].written_steplen = steplen; } @@ -410,7 +410,7 @@ static void hm2_stepgen_update_mode(hostmot2_t *hm2, int i) { hm2_stepgen_instance_t *inst = &hm2->stepgen.instance[i]; // No point coming back unless something changes - rtapi_u32 step_type = hal_get_ui32(inst->hal.param.step_type); + rtapi_uint step_type = hal_get_uint(inst->hal.param.step_type); inst->written_step_type = step_type; if (hm2->stepgen.firmware_supports_swap) { inst->written_swap_step_dir = hal_get_bool(inst->hal.param.swap_step_dir); @@ -419,8 +419,8 @@ static void hm2_stepgen_update_mode(hostmot2_t *hm2, int i) { inst->written_index_polarity = hal_get_bool(inst->hal.pin.index_polarity); inst->written_probe_polarity = hal_get_bool(inst->hal.pin.latch_polarity); } - inst->tablehash = (((hal_get_ui32(inst->hal.param.table[0]) ^ hal_get_ui32(inst->hal.param.table[1])) - ^ hal_get_ui32(inst->hal.param.table[2])) ^ hal_get_ui32(inst->hal.param.table[3])); + inst->tablehash = (((hal_get_uint(inst->hal.param.table[0]) ^ hal_get_uint(inst->hal.param.table[1])) + ^ hal_get_uint(inst->hal.param.table[2])) ^ hal_get_uint(inst->hal.param.table[3])); modebuff = step_type; // start with the step mode @@ -454,16 +454,16 @@ static void hm2_stepgen_update_mode(hostmot2_t *hm2, int i) { if (inst->table_width < step_type){ HM2_ERR("the firmware only supports %i pins in the step pattern for " - "stepgen instance %i, you asked for %i. Reverting to step type 0\n", + "stepgen instance %i, you asked for %lu. Reverting to step type 0\n", inst->table_width, i, - step_type); + (unsigned long)step_type); hm2->stepgen.mode_reg[i] = 0; } if (step_type > 16){ HM2_ERR("the firmware only supports tables up to a depth of 16, you " - "requested %i. Reverting to step type 0\n", - step_type); + "requested %lu. Reverting to step type 0\n", + (unsigned long)step_type); hm2->stepgen.mode_reg[i] = 0; // Assure that we do not index outside the param.table[] array in the // loop below. But the code may be off anyway and the result is @@ -474,7 +474,7 @@ static void hm2_stepgen_update_mode(hostmot2_t *hm2, int i) { // step_type is actually the table length. for (j = step_type - 1; j >= 0 ; j--){ - buff = ((hal_get_ui32(inst->hal.param.table[j / 4]) >> ((j % 4) * 8)) & 0xFF); + buff = ((hal_get_uint(inst->hal.param.table[j / 4]) >> ((j % 4) * 8)) & 0xFF); hm2->llio->write(hm2->llio, hm2->stepgen.table_sequence_data_setup_addr + (i * sizeof(rtapi_u32)), &buff, sizeof(rtapi_u32)); } @@ -490,9 +490,9 @@ static void hm2_stepgen_update_mode(hostmot2_t *hm2, int i) { static void hm2_stepgen_set_dpll_timer(hostmot2_t *hm2) { rtapi_u32 data = 0; - rtapi_s32 dpll_timer_num = hal_get_si32(hm2->stepgen.hal->pin.dpll_timer_num); + rtapi_sint dpll_timer_num = hal_get_sint(hm2->stepgen.hal->pin.dpll_timer_num); if ((dpll_timer_num < -1) || (dpll_timer_num > 4)) { - dpll_timer_num = hal_set_si32(hm2->stepgen.hal->pin.dpll_timer_num, 0); + dpll_timer_num = hal_set_sint(hm2->stepgen.hal->pin.dpll_timer_num, 0); } if (dpll_timer_num > -1) { data = (dpll_timer_num << 12) | (1 << 15); @@ -509,31 +509,31 @@ void hm2_stepgen_write(hostmot2_t *hm2) { // FIXME for (i = 0; i < hm2->stepgen.num_instances; i ++) { hm2_stepgen_instance_t *inst = &hm2->stepgen.instance[i]; - if (hal_get_ui32(inst->hal.param.dirsetup) != inst->written_dirsetup) { + if (hal_get_uint(inst->hal.param.dirsetup) != inst->written_dirsetup) { hm2_stepgen_update_dir_setup_time(hm2, i); hm2->llio->write(hm2->llio, hm2->stepgen.dir_setup_time_addr + (i * sizeof(rtapi_u32)), &hm2->stepgen.dir_setup_time_reg[i], sizeof(rtapi_u32)); } - if (hal_get_ui32(inst->hal.param.dirhold) != inst->written_dirhold) { + if (hal_get_uint(inst->hal.param.dirhold) != inst->written_dirhold) { hm2_stepgen_update_dir_hold_time(hm2, i); hm2->llio->write(hm2->llio, hm2->stepgen.dir_hold_time_addr + (i * sizeof(rtapi_u32)), &hm2->stepgen.dir_hold_time_reg[i], sizeof(rtapi_u32)); } - if (hal_get_ui32(inst->hal.param.steplen) != inst->written_steplen) { + if (hal_get_uint(inst->hal.param.steplen) != inst->written_steplen) { hm2_stepgen_update_pulse_width(hm2, i); hm2->llio->write(hm2->llio, hm2->stepgen.pulse_width_addr + (i * sizeof(rtapi_u32)), &hm2->stepgen.pulse_width_reg[i], sizeof(rtapi_u32)); } - if (hal_get_ui32(inst->hal.param.stepspace) != inst->written_stepspace) { + if (hal_get_uint(inst->hal.param.stepspace) != inst->written_stepspace) { hm2_stepgen_update_pulse_idle_width(hm2, i); hm2->llio->write(hm2->llio, hm2->stepgen.pulse_idle_width_addr + (i * sizeof(rtapi_u32)), &hm2->stepgen.pulse_idle_width_reg[i], sizeof(rtapi_u32)); } need_mode_update=0; - if ((hal_get_ui32(inst->hal.param.step_type) != inst->written_step_type) - || (((hal_get_ui32(inst->hal.param.table[0]) ^ hal_get_ui32(inst->hal.param.table[1])) - ^ hal_get_ui32(inst->hal.param.table[2])) ^ hal_get_ui32(inst->hal.param.table[3])) + if ((hal_get_uint(inst->hal.param.step_type) != inst->written_step_type) + || (((hal_get_uint(inst->hal.param.table[0]) ^ hal_get_uint(inst->hal.param.table[1])) + ^ hal_get_uint(inst->hal.param.table[2])) ^ hal_get_uint(inst->hal.param.table[3])) != inst->tablehash) { need_mode_update = 1; } @@ -563,7 +563,7 @@ void hm2_stepgen_write(hostmot2_t *hm2) { } if (hm2->stepgen.num_instances > 0 && hm2->dpll_module_present) { - if (hal_get_si32(hm2->stepgen.hal->pin.dpll_timer_num) != (int)hm2->stepgen.written_dpll_timer_num) { + if (hal_get_sint(hm2->stepgen.hal->pin.dpll_timer_num) != hm2->stepgen.written_dpll_timer_num) { hm2_stepgen_set_dpll_timer(hm2); } } @@ -873,7 +873,7 @@ int hm2_stepgen_parse_md(hostmot2_t *hm2, int md_index) { { if (hm2->dpll_module_present) { - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_IN, &(hm2->stepgen.hal->pin.dpll_timer_num), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_IN, &(hm2->stepgen.hal->pin.dpll_timer_num), -1, "%s.stepgen.timer-number", hm2->llio->name); if (r < 0) { HM2_ERR("error %d adding pin '%s.stepgen.timer-number', aborting\n", r, hm2->llio->name); @@ -927,7 +927,7 @@ int hm2_stepgen_parse_md(hostmot2_t *hm2, int md_index) { goto fail5; } - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(hm2->stepgen.instance[i].hal.pin.counts), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(hm2->stepgen.instance[i].hal.pin.counts), 0, "%s.stepgen.%02d.counts", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.stepgen.%02d.counts', aborting\n", r, hm2->llio->name, i); @@ -1044,7 +1044,7 @@ int hm2_stepgen_parse_md(hostmot2_t *hm2, int md_index) { goto fail5; } - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_OUT, &(hm2->stepgen.instance[i].hal.pin.dbg_step_rate), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_OUT, &(hm2->stepgen.instance[i].hal.pin.dbg_step_rate), 0, "%s.stepgen.%02d.dbg_step_rate", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.stepgen.%02d.dbg_step_rate', aborting\n", r, hm2->llio->name, i); @@ -1080,7 +1080,7 @@ int hm2_stepgen_parse_md(hostmot2_t *hm2, int md_index) { // start out the slowest possible, let the user speed up if they want rtapi_u32 v = (double)0x3FFF * ((double)1e9 / (double)hm2->stepgen.clock_frequency); - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.steplen), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.steplen), v, "%s.stepgen.%02d.steplen", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.stepgen.%02d.steplen', aborting\n", r, hm2->llio->name, i); @@ -1088,7 +1088,7 @@ int hm2_stepgen_parse_md(hostmot2_t *hm2, int md_index) { goto fail5; } - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.stepspace), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.stepspace), v, "%s.stepgen.%02d.stepspace", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.stepgen.%02d.stepspace', aborting\n", r, hm2->llio->name, i); @@ -1096,7 +1096,7 @@ int hm2_stepgen_parse_md(hostmot2_t *hm2, int md_index) { goto fail5; } - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.dirsetup), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.dirsetup), v, "%s.stepgen.%02d.dirsetup", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.stepgen.%02d.dirsetup', aborting\n", r, hm2->llio->name, i); @@ -1104,7 +1104,7 @@ int hm2_stepgen_parse_md(hostmot2_t *hm2, int md_index) { goto fail5; } - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.dirhold), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.dirhold), v, "%s.stepgen.%02d.dirhold", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.stepgen.%02d.dirhold', aborting\n", r, hm2->llio->name, i); @@ -1112,7 +1112,7 @@ int hm2_stepgen_parse_md(hostmot2_t *hm2, int md_index) { goto fail5; } - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.step_type), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.step_type), 0, "%s.stepgen.%02d.step_type", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.stepgen.%02d.step_type', aborting\n", r, hm2->llio->name, i); @@ -1138,28 +1138,28 @@ int hm2_stepgen_parse_md(hostmot2_t *hm2, int md_index) { } if (hm2->stepgen.instance[i].table_width > 2){ - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.table[0]), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.table[0]), 0, "%s.stepgen.%02d.table-data-0", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.stepgen.%02d.table-data-0', aborting\n", r, hm2->llio->name, i); r = -ENOMEM; goto fail5; } - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.table[1]), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.table[1]), 0, "%s.stepgen.%02d.table-data-1", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.stepgen.%02d.table-data-1', aborting\n", r, hm2->llio->name, i); r = -ENOMEM; goto fail5; } - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.table[2]), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.table[2]), 0, "%s.stepgen.%02d.table-data-2", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.stepgen.%02d.table-data-2', aborting\n", r, hm2->llio->name, i); r = -ENOMEM; goto fail5; } - r = hal_param_new_ui32(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.table[3]), + r = hal_param_new_uint(hm2->llio->comp_id, HAL_RW, &(hm2->stepgen.instance[i].hal.param.table[3]), 0, "%s.stepgen.%02d.table-data-3", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding param '%s.stepgen.%02d.table-data-3', aborting\n", r, hm2->llio->name, i); @@ -1242,10 +1242,10 @@ void hm2_stepgen_print_module(hostmot2_t *hm2) { HM2_PRINT(" step_rate = 0x%08X\n", hm2->stepgen.step_rate_reg[i]); HM2_PRINT(" accumulator = 0x%08X\n", hm2->stepgen.accumulator_reg[i]); HM2_PRINT(" mode = 0x%08X\n", hm2->stepgen.mode_reg[i]); - HM2_PRINT(" dir_setup_time = 0x%08X (%u ns)\n", hm2->stepgen.dir_setup_time_reg[i], hal_get_ui32(hm2->stepgen.instance[i].hal.param.dirsetup)); - HM2_PRINT(" dir_hold_time = 0x%08X (%u ns)\n", hm2->stepgen.dir_hold_time_reg[i], hal_get_ui32(hm2->stepgen.instance[i].hal.param.dirhold)); - HM2_PRINT(" pulse_width = 0x%08X (%u ns)\n", hm2->stepgen.pulse_width_reg[i], hal_get_ui32(hm2->stepgen.instance[i].hal.param.steplen)); - HM2_PRINT(" pulse_idle_width = 0x%08X (%u ns)\n", hm2->stepgen.pulse_idle_width_reg[i], hal_get_ui32(hm2->stepgen.instance[i].hal.param.stepspace)); + HM2_PRINT(" dir_setup_time = 0x%08X (%lu ns)\n", hm2->stepgen.dir_setup_time_reg[i], (unsigned long)hal_get_uint(hm2->stepgen.instance[i].hal.param.dirsetup)); + HM2_PRINT(" dir_hold_time = 0x%08X (%lu ns)\n", hm2->stepgen.dir_hold_time_reg[i], (unsigned long)hal_get_uint(hm2->stepgen.instance[i].hal.param.dirhold)); + HM2_PRINT(" pulse_width = 0x%08X (%lu ns)\n", hm2->stepgen.pulse_width_reg[i], (unsigned long)hal_get_uint(hm2->stepgen.instance[i].hal.param.steplen)); + HM2_PRINT(" pulse_idle_width = 0x%08X (%lu ns)\n", hm2->stepgen.pulse_idle_width_reg[i], (unsigned long)hal_get_uint(hm2->stepgen.instance[i].hal.param.stepspace)); } } diff --git a/src/hal/drivers/mesa-hostmot2/tp_pwmgen.c b/src/hal/drivers/mesa-hostmot2/tp_pwmgen.c index fd5fa57530d..18ff25a00c4 100644 --- a/src/hal/drivers/mesa-hostmot2/tp_pwmgen.c +++ b/src/hal/drivers/mesa-hostmot2/tp_pwmgen.c @@ -32,10 +32,10 @@ void hm2_tp_pwmgen_handle_pwm_frequency(hostmot2_t *hm2) { int deadtime; int i; - rtapi_u32 pwm_frequency = hal_get_ui32(hm2->tp_pwmgen.hal->param.pwm_frequency); + rtapi_uint pwm_frequency = hal_get_uint(hm2->tp_pwmgen.hal->param.pwm_frequency); if (pwm_frequency < 1) { - HM2_ERR("3pwmgen.pwm_frequency %d is too low, setting to 1\n", pwm_frequency); - pwm_frequency = hal_set_ui32(hm2->tp_pwmgen.hal->param.pwm_frequency, 1); + HM2_ERR("3pwmgen.pwm_frequency %lu is too low, setting to 1\n", (unsigned long)pwm_frequency); + pwm_frequency = hal_set_uint(hm2->tp_pwmgen.hal->param.pwm_frequency, 1); } @@ -64,10 +64,10 @@ void hm2_tp_pwmgen_handle_pwm_frequency(hostmot2_t *hm2) { // not possible so try the fastest we can // PWMFreq = (ClockHigh * DDS) / (65536 * 2048) dds = 65535; - pwm_frequency = hal_set_ui32(hm2->tp_pwmgen.hal->param.pwm_frequency, + pwm_frequency = hal_set_uint(hm2->tp_pwmgen.hal->param.pwm_frequency, ((double)hm2->tp_pwmgen.clock_frequency * 65535.0) / (65536.0 * 2048.0)); - HM2_ERR("max PWM frequency is %d Hz\n", pwm_frequency); + HM2_ERR("max PWM frequency is %lu Hz\n", (unsigned long)pwm_frequency); hm2->tp_pwmgen.pwmgen_master_rate_dds_reg = dds; } @@ -143,7 +143,7 @@ void hm2_tp_pwmgen_force_write(hostmot2_t *hm2) { hm2->tp_pwmgen.instance[i].written_sampletime = hal_get_real(hm2->tp_pwmgen.instance[i].hal.param.sampletime); } - hm2->tp_pwmgen.written_pwm_frequency = hal_get_ui32(hm2->tp_pwmgen.hal->param.pwm_frequency); + hm2->tp_pwmgen.written_pwm_frequency = hal_get_uint(hm2->tp_pwmgen.hal->param.pwm_frequency); } @@ -157,7 +157,7 @@ void hm2_tp_pwmgen_write(hostmot2_t *hm2) { if (hm2->tp_pwmgen.num_instances == 0) return; // check pwm frequency - if (hal_get_ui32(hm2->tp_pwmgen.hal->param.pwm_frequency) != hm2->tp_pwmgen.written_pwm_frequency) goto force_write; + if (hal_get_uint(hm2->tp_pwmgen.hal->param.pwm_frequency) != hm2->tp_pwmgen.written_pwm_frequency) goto force_write; // update enable register? for (i = 0; i < hm2->tp_pwmgen.num_instances; i ++) { @@ -295,7 +295,7 @@ int hm2_tp_pwmgen_parse_md(hostmot2_t *hm2, int md_index) { // export to HAL { // this hal parameter affects all the 3-Phase pwmgen instances - r = hal_param_new_ui32( + r = hal_param_new_uint( hm2->llio->comp_id, HAL_RW, &(hm2->tp_pwmgen.hal->param.pwm_frequency), diff --git a/src/hal/drivers/mesa-hostmot2/watchdog.c b/src/hal/drivers/mesa-hostmot2/watchdog.c index e65129d4635..b99328e25fb 100644 --- a/src/hal/drivers/mesa-hostmot2/watchdog.c +++ b/src/hal/drivers/mesa-hostmot2/watchdog.c @@ -151,7 +151,7 @@ int hm2_watchdog_parse_md(hostmot2_t *hm2, int md_index) { // params // default timeout is 5 milliseconds (5*1000*1000 nanoseconds) - r = hal_param_new_ui32( + r = hal_param_new_uint( hm2->llio->comp_id, HAL_RW, &(hm2->watchdog.instance[0].hal.param.timeout_ns), @@ -194,7 +194,7 @@ void hm2_watchdog_print_module(hostmot2_t *hm2) { HM2_PRINT(" reset_addr: 0x%04X\n", hm2->watchdog.reset_addr); for (i = 0; i < hm2->watchdog.num_instances; i ++) { HM2_PRINT(" instance %d:\n", i); - HM2_PRINT(" param timeout_ns = %u\n", hal_get_ui32(hm2->watchdog.instance[i].hal.param.timeout_ns)); + HM2_PRINT(" param timeout_ns = %lu\n", (unsigned long)hal_get_uint(hm2->watchdog.instance[i].hal.param.timeout_ns)); HM2_PRINT(" pin has_bit = %d\n", (int)hal_get_bool(hm2->watchdog.instance[i].hal.pin.has_bit)); HM2_PRINT(" reg timer = 0x%08X\n", hm2->watchdog.timer_reg[i]); } @@ -221,7 +221,7 @@ void hm2_watchdog_force_write(hostmot2_t *hm2) { if (hm2->watchdog.num_instances != 1) return; - rtapi_u32 timeout_ns = hal_get_ui32(hm2->watchdog.instance[0].hal.param.timeout_ns); + rtapi_uint timeout_ns = hal_get_uint(hm2->watchdog.instance[0].hal.param.timeout_ns); if (hm2->watchdog.instance[0].enable == 0) { // watchdog is disabled, MSb=1 is secret handshake with FPGA hm2->watchdog.timer_reg[0] = 0x80000000; @@ -233,9 +233,9 @@ void hm2_watchdog_force_write(hostmot2_t *hm2) { // truncate watchdog timeout tmp = 0x7FFFFFFF; hm2->watchdog.timer_reg[0] = tmp; - timeout_ns = hal_set_ui32(hm2->watchdog.instance[0].hal.param.timeout_ns, + timeout_ns = hal_set_uint(hm2->watchdog.instance[0].hal.param.timeout_ns, (tmp + 1) / ((double)hm2->watchdog.clock_frequency / (double)(1000 * 1000 * 1000))); - HM2_ERR("requested watchdog timeout is out of range, setting it to max: %u ns\n", timeout_ns); + HM2_ERR("requested watchdog timeout is out of range, setting it to max: %lu ns\n", (unsigned long)timeout_ns); } } @@ -282,7 +282,7 @@ void hm2_watchdog_write(hostmot2_t *hm2, long period_ns) { hm2->llio->needs_reset = hm2->llio->needs_soft_reset = 0; } - rtapi_u32 timeout_ns = hal_get_ui32(hm2->watchdog.instance[0].hal.param.timeout_ns); + rtapi_uint timeout_ns = hal_get_uint(hm2->watchdog.instance[0].hal.param.timeout_ns); if ( (timeout_ns == hm2->watchdog.instance[0].written_timeout_ns) && @@ -292,10 +292,10 @@ void hm2_watchdog_write(hostmot2_t *hm2, long period_ns) { } // if the requested timeout is dangerously short compared to the petting-period, warn the user once - if (timeout_ns < (1.5 * period_ns)) { + if ((long)timeout_ns < (3 * period_ns / 2)) { HM2_PRINT( - "Watchdog timeout (%u ns) is dangerously short compared to hm2_write() period (%ld ns)\n", - timeout_ns, + "Watchdog timeout (%lu ns) is dangerously short compared to hm2_write() period (%ld ns)\n", + (unsigned long)timeout_ns, period_ns ); } diff --git a/src/hal/drivers/mesa-hostmot2/xy2mod.c b/src/hal/drivers/mesa-hostmot2/xy2mod.c index 35f10a03fd5..0d1c55d6f65 100644 --- a/src/hal/drivers/mesa-hostmot2/xy2mod.c +++ b/src/hal/drivers/mesa-hostmot2/xy2mod.c @@ -89,7 +89,7 @@ void hm2_xy2mod_process_tram_read(hostmot2_t *hm2) { hal_set_bool(s->hal.pin.posy_overflow, mode & (1 << 7)); hal_set_bool(s->hal.pin.velx_overflow, mode & (1 << 8)); hal_set_bool(s->hal.pin.vely_overflow, mode & (1 << 9)); - hal_set_ui32(s->hal.pin.status, status & 0x000FFFFF); + hal_set_uint(s->hal.pin.status, status & 0x000FFFFF); } } @@ -194,12 +194,12 @@ static void hm2_xy2mod_instance_write(hostmot2_t *hm2, int i) { hm2->llio->write(hm2->llio, hm2->xy2mod.accy_addr + istride, &hm2->xy2mod.accy_reg[i], sizeof(rtapi_u32)); s->prev_accy_cmd = accy_cmd; } - hal_set_ui32(s->hal.pin.controlx, hal_get_ui32(s->hal.pin.controlx) & 7); - hal_set_ui32(s->hal.pin.controly, hal_get_ui32(s->hal.pin.controly) & 7); + hal_set_uint(s->hal.pin.controlx, hal_get_uint(s->hal.pin.controlx) & 7); + hal_set_uint(s->hal.pin.controly, hal_get_uint(s->hal.pin.controly) & 7); hm2->xy2mod.mode_reg[i] = - (hal_get_ui32(s->hal.pin.controlx) << 0) | - (hal_get_ui32(s->hal.pin.controly) << 3) | + (hal_get_uint(s->hal.pin.controlx) << 0) | + (hal_get_uint(s->hal.pin.controly) << 3) | (hal_get_bool(s->hal.pin.mode18bitx)<< 10) | (hal_get_bool(s->hal.pin.mode18bity)<< 11) | (hal_get_bool(s->hal.pin.commandmodex)<< 12) | @@ -207,12 +207,12 @@ static void hm2_xy2mod_instance_write(hostmot2_t *hm2, int i) { hm2->llio->write(hm2->llio,hm2->xy2mod.mode_addr + istride, &hm2->xy2mod.mode_reg[i], sizeof(rtapi_u32)); - hal_set_ui32(s->hal.pin.commandx, hal_get_ui32(s->hal.pin.commandx) & 0xFFFF); - hal_set_ui32(s->hal.pin.commandy, hal_get_ui32(s->hal.pin.commandy) & 0xFFFF); + hal_set_uint(s->hal.pin.commandx, hal_get_uint(s->hal.pin.commandx) & 0xFFFF); + hal_set_uint(s->hal.pin.commandy, hal_get_uint(s->hal.pin.commandy) & 0xFFFF); hm2->xy2mod.command_reg[i] = - (hal_get_ui32(s->hal.pin.commandx) << 0) | - (hal_get_ui32(s->hal.pin.commandy) << 16); + (hal_get_uint(s->hal.pin.commandx) << 0) | + (hal_get_uint(s->hal.pin.commandy) << 16); hm2->llio->write(hm2->llio,hm2->xy2mod.command_addr + istride, &hm2->xy2mod.command_reg[i], sizeof(rtapi_u32)); @@ -256,8 +256,8 @@ static void hm2_xy2mod_instance_write(hostmot2_t *hm2, int i) { //reset control bits and overflow flags - hal_set_ui32(s->hal.pin.controlx, 1); // default to 16 bit mode - hal_set_ui32(s->hal.pin.controly, 1); + hal_set_uint(s->hal.pin.controlx, 1); // default to 16 bit mode + hal_set_uint(s->hal.pin.controly, 1); hm2->xy2mod.mode_reg[i] = 0x000003C9; // reset X and Y overflow bits when disabled hm2->llio->write(hm2->llio, hm2->xy2mod.mode_addr + istride, &hm2->xy2mod.mode_reg[i], sizeof(rtapi_u32)); } @@ -266,10 +266,10 @@ static void hm2_xy2mod_instance_write(hostmot2_t *hm2, int i) { static void hm2_xy2mod_set_dpll_rtimer(hostmot2_t *hm2) { rtapi_u32 data = 0; - rtapi_s32 dpll_rtimer_num = hal_get_si32(hm2->xy2mod.hal->pin.dpll_rtimer_num); + rtapi_sint dpll_rtimer_num = hal_get_sint(hm2->xy2mod.hal->pin.dpll_rtimer_num); if ((dpll_rtimer_num < -1) || (dpll_rtimer_num > 4)) { - dpll_rtimer_num = hal_set_si32(hm2->xy2mod.hal->pin.dpll_rtimer_num, 0); + dpll_rtimer_num = hal_set_sint(hm2->xy2mod.hal->pin.dpll_rtimer_num, 0); } if (dpll_rtimer_num > -1) { data = (dpll_rtimer_num << 12) | (1 << 15); @@ -280,10 +280,10 @@ static void hm2_xy2mod_set_dpll_rtimer(hostmot2_t *hm2) { static void hm2_xy2mod_set_dpll_wtimer(hostmot2_t *hm2) { rtapi_u32 data = 0; - rtapi_s32 dpll_wtimer_num = hal_get_si32(hm2->xy2mod.hal->pin.dpll_wtimer_num); + rtapi_sint dpll_wtimer_num = hal_get_sint(hm2->xy2mod.hal->pin.dpll_wtimer_num); if ((dpll_wtimer_num < -1) || (dpll_wtimer_num > 4)) { - dpll_wtimer_num = hal_set_si32(hm2->xy2mod.hal->pin.dpll_wtimer_num, 0); + dpll_wtimer_num = hal_set_sint(hm2->xy2mod.hal->pin.dpll_wtimer_num, 0); } if (dpll_wtimer_num > -1) { data = (dpll_wtimer_num << 12) | (1 << 15); @@ -299,10 +299,10 @@ void hm2_xy2mod_write(hostmot2_t *hm2) { hm2_xy2mod_instance_write(hm2, i); } if (hm2->xy2mod.num_instances > 0 && hm2->dpll_module_present) { - if (hal_get_si32(hm2->xy2mod.hal->pin.dpll_rtimer_num) != hm2->xy2mod.written_dpll_rtimer_num) { + if (hal_get_sint(hm2->xy2mod.hal->pin.dpll_rtimer_num) != hm2->xy2mod.written_dpll_rtimer_num) { hm2_xy2mod_set_dpll_rtimer(hm2); } - if (hal_get_si32(hm2->xy2mod.hal->pin.dpll_wtimer_num) != hm2->xy2mod.written_dpll_wtimer_num) { + if (hal_get_sint(hm2->xy2mod.hal->pin.dpll_wtimer_num) != hm2->xy2mod.written_dpll_wtimer_num) { hm2_xy2mod_set_dpll_wtimer(hm2); } } @@ -521,14 +521,14 @@ int hm2_xy2mod_parse_md(hostmot2_t *hm2, int md_index) { { if (hm2->dpll_module_present) { - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_IN, &(hm2->xy2mod.hal->pin.dpll_rtimer_num), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_IN, &(hm2->xy2mod.hal->pin.dpll_rtimer_num), -1, "%s.xy2mod.read-timer-number", hm2->llio->name); if (r < 0) { HM2_ERR("error %d adding pin '%s.xy2mod.read-timer-number', aborting\n", r, hm2->llio->name); return -EINVAL; } - r = hal_pin_new_si32(hm2->llio->comp_id, HAL_IN, &(hm2->xy2mod.hal->pin.dpll_wtimer_num), + r = hal_pin_new_sint(hm2->llio->comp_id, HAL_IN, &(hm2->xy2mod.hal->pin.dpll_wtimer_num), -1, "%s.xy2mod.write-timer-number", hm2->llio->name); if (r < 0) { HM2_ERR("error %d adding pin '%s.xy2mod.write-timer-number', aborting\n", r, hm2->llio->name); @@ -629,7 +629,7 @@ int hm2_xy2mod_parse_md(hostmot2_t *hm2, int md_index) { goto fail0; } - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_IN, &(hm2->xy2mod.instance[i].hal.pin.controlx), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_IN, &(hm2->xy2mod.instance[i].hal.pin.controlx), 1, "%s.xy2mod.%02d.controlx", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.xy2mod.%02d.controlx', aborting\n", r, hm2->llio->name, i); @@ -637,14 +637,14 @@ int hm2_xy2mod_parse_md(hostmot2_t *hm2, int md_index) { } - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_IN, &(hm2->xy2mod.instance[i].hal.pin.controly), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_IN, &(hm2->xy2mod.instance[i].hal.pin.controly), 1, "%s.xy2mod.%02d.controly", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.xy2mod.%02d.controly', aborting\n", r, hm2->llio->name, i); goto fail0; } - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_IN, &(hm2->xy2mod.instance[i].hal.pin.commandx), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_IN, &(hm2->xy2mod.instance[i].hal.pin.commandx), 0, "%s.xy2mod.%02d.commandx", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.xy2mod.%02d.commandx', aborting\n", r, hm2->llio->name, i); @@ -652,7 +652,7 @@ int hm2_xy2mod_parse_md(hostmot2_t *hm2, int md_index) { } - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_IN, &(hm2->xy2mod.instance[i].hal.pin.commandy), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_IN, &(hm2->xy2mod.instance[i].hal.pin.commandy), 0, "%s.xy2mod.%02d.commandy", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.xy2mod.%02d.commandy', aborting\n", r, hm2->llio->name, i); @@ -716,7 +716,7 @@ int hm2_xy2mod_parse_md(hostmot2_t *hm2, int md_index) { goto fail0; } - r = hal_pin_new_ui32(hm2->llio->comp_id, HAL_OUT, &(hm2->xy2mod.instance[i].hal.pin.status), + r = hal_pin_new_uint(hm2->llio->comp_id, HAL_OUT, &(hm2->xy2mod.instance[i].hal.pin.status), 0, "%s.xy2mod.%02d.status", hm2->llio->name, i); if (r < 0) { HM2_ERR("error %d adding pin '%s.xy2mod.%02d.status', aborting\n", r, hm2->llio->name, i); diff --git a/src/hal/utils/halcompile.g b/src/hal/utils/halcompile.g index 01eaa6f3c66..5ec3e0c6999 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) @@ -590,6 +610,35 @@ static int comp_id; print(" if(r != 0) return r;", file=f) 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: