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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/src/man/man9/hostmot2.9.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/hal/drivers/mesa-hostmot2/hostmot2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
62 changes: 36 additions & 26 deletions src/hal/drivers/mesa-hostmot2/raw.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

//
// Copyright (C) 2007-2008 Sebastian Kuzminsky
//
Expand All @@ -17,7 +16,6 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//


#include <rtapi.h>
#include <rtapi_string.h>

Expand All @@ -26,8 +24,6 @@
#include "hostmot2.h"




int hm2_raw_setup(hostmot2_t *hm2) {
int r;

Expand All @@ -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) {
Expand All @@ -88,39 +91,46 @@ 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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a hm2_raw_process_read() called from hm2_read() after hm2_finish_read(), like hm2_tp_pwmgen_process_read(), be the hook for the resolved read? It would put the value on read_data in the same cycle, and read_data would always match the current read_address instead of the previous one. The "one thread cycle" note in the man page could then go.


// 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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can queue_read ever be NULL here? If I read hm2_register() right, it installs dummy_queue_read() when the llio has none, and that falls back to ->read. Then a plain hm2->llio->queue_read(...) would cover both cases.


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);
hal_set_bool(hm2->raw->hal.pin.dump_state, 0);
}
}




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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm2_raw_write() runs just before hm2_finish_write(), which sends the queue, and queue_write falls back to dummy_queue_write() when the llio has none. Is there a case where a queued write behaves differently from an immediate one? If not, could it always queue and drop the write_queued pin?


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);
}