From 067edff932ab3b25c1eab7613344b06e8a96e948 Mon Sep 17 00:00:00 2001 From: Bertho Stultiens Date: Mon, 30 Nov 2026 17:22:03 +0100 Subject: [PATCH] hal: Update the hostmot2 raw interface to work with the new HAL setup and make it 64-bit clean. --- docs/src/man/man9/hostmot2.9.adoc | 6 ++- src/hal/drivers/mesa-hostmot2/hostmot2.h | 4 ++ src/hal/drivers/mesa-hostmot2/raw.c | 62 ++++++++++++++---------- 3 files changed, 45 insertions(+), 27 deletions(-) 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/hal/drivers/mesa-hostmot2/hostmot2.h b/src/hal/drivers/mesa-hostmot2/hostmot2.h index 89850f312b9..1fc836843f4 100644 --- a/src/hal/drivers/mesa-hostmot2/hostmot2.h +++ b/src/hal/drivers/mesa-hostmot2/hostmot2.h @@ -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/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); }