Repository navigation
hal: Update the hostmot2 raw interface to work with the new HAL setup #4939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <rtapi.h> | ||
| #include <rtapi_string.h> | ||
|
|
||
|
|
@@ -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,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); | ||
|
|
||
| // 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can |
||
|
|
||
| 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| 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); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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 fromhm2_read()afterhm2_finish_read(), likehm2_tp_pwmgen_process_read(), be the hook for the resolved read? It would put the value onread_datain the same cycle, andread_datawould always match the currentread_addressinstead of the previous one. The "one thread cycle" note in the man page could then go.