Skip to content

Commit 9fcedc2

Browse files
authored
Merge pull request #4913 from BsAtHome/hal64_xhc-pendents
hal: Update the XHC pendents to 64-bit clean HAL operation.
2 parents 65b35c0 + 5dc3dd8 commit 9fcedc2

3 files changed

Lines changed: 30 additions & 24 deletions

File tree

‎src/hal/user_comps/xhc-hb04.cc‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ typedef struct {
164164
unsigned char button_step; // Used in simulation mode to handle the STEP increment
165165

166166
// Variables for velocity computation
167-
rtapi_s32 last_jog_counts;
167+
rtapi_sint last_jog_counts;
168168
struct timeval last_tv;
169169

170170
struct timeval last_wakeup;
@@ -233,7 +233,7 @@ void xhc_display_encode(xhc_t *xhc, unsigned char *data, int len)
233233
p += xhc_encode_s16(round(60.0 * hal_get_real(xhc->hal->feedrate)), p);
234234
p += xhc_encode_s16(round(60.0 * hal_get_real(xhc->hal->spindle_rps)), p);
235235

236-
switch (hal_get_si32(xhc->hal->stepsize)) {
236+
switch (hal_get_sint(xhc->hal->stepsize)) {
237237
case 0: buf[STEPSIZE_BYTE] = STEPSIZE_DISPLAY_0; break;
238238
case 1: buf[STEPSIZE_BYTE] = STEPSIZE_DISPLAY_1; break;
239239
case 5: buf[STEPSIZE_BYTE] = STEPSIZE_DISPLAY_5; break;
@@ -296,15 +296,15 @@ void hexdump(unsigned char *data, int len)
296296

297297
void linuxcnc_simu(xhc_t *xhc)
298298
{
299-
static int last_jog_counts;
299+
static rtapi_sint last_jog_counts;
300300
xhc_hal_t *hal = xhc->hal;
301301

302302
// for simu, always step up
303303
hal_set_bool(hal->stepsize_up, (xhc->button_step && xhc->button_code == xhc->button_step));
304304

305-
if (hal_get_si32(hal->jog_counts) != last_jog_counts) {
306-
int delta_int = hal_get_si32(hal->jog_counts) - last_jog_counts;
307-
float delta = delta_int * hal_get_real(hal->jog_scale);
305+
if (hal_get_sint(hal->jog_counts) != last_jog_counts) {
306+
rtapi_sint delta_int = hal_get_sint(hal->jog_counts) - last_jog_counts;
307+
rtapi_real delta = delta_int * hal_get_real(hal->jog_scale);
308308
if (hal_get_bool(hal->jog_enable_x)) {
309309
hal_set_real(hal->x_mc, hal_get_real(hal->x_mc) + delta);
310310
hal_set_real(hal->x_wc, hal_get_real(hal->x_wc) + delta);
@@ -339,7 +339,7 @@ void linuxcnc_simu(xhc_t *xhc)
339339
hal_set_real(hal->feedrate, 3000.0/60.0 * hal_get_real(hal->feedrate_override));
340340
}
341341

342-
last_jog_counts = hal_get_si32(hal->jog_counts);
342+
last_jog_counts = hal_get_sint(hal->jog_counts);
343343
}
344344
}
345345

@@ -353,7 +353,7 @@ void compute_velocity(xhc_t *xhc)
353353
float elapsed = delta_tv.tv_sec + 1e-6f*delta_tv.tv_usec;
354354
if (elapsed <= 0) return;
355355

356-
float delta_pos = (hal_get_si32(xhc->hal->jog_counts) - xhc->last_jog_counts) * hal_get_real(xhc->hal->jog_scale);
356+
float delta_pos = (hal_get_sint(xhc->hal->jog_counts) - xhc->last_jog_counts) * hal_get_real(xhc->hal->jog_scale);
357357
float velocity = hal_get_real(xhc->hal->jog_max_velocity) * 60.0f * hal_get_real(xhc->hal->jog_scale);
358358
float k = 0.05f;
359359

@@ -368,7 +368,7 @@ void compute_velocity(xhc_t *xhc)
368368
hal_set_bool(xhc->hal->jog_minus_z, (delta_pos < 0) && hal_get_bool(xhc->hal->jog_enable_z));
369369
hal_set_bool(xhc->hal->jog_plus_a, (delta_pos > 0) && hal_get_bool(xhc->hal->jog_enable_a));
370370
hal_set_bool(xhc->hal->jog_minus_a, (delta_pos < 0) && hal_get_bool(xhc->hal->jog_enable_a));
371-
xhc->last_jog_counts = hal_get_si32(xhc->hal->jog_counts);
371+
xhc->last_jog_counts = hal_get_sint(xhc->hal->jog_counts);
372372
xhc->last_tv = now;
373373
}
374374
else {
@@ -390,7 +390,7 @@ void compute_velocity(xhc_t *xhc)
390390
void handle_step(xhc_t *xhc)
391391
{
392392
int _inc_step_status = STEP_NONE;
393-
int _stepsize = hal_get_si32(xhc->hal->stepsize); // Use a local variable to avoid STEP display as 0 on pendant during transitions
393+
rtapi_sint _stepsize = hal_get_sint(xhc->hal->stepsize); // Use a local variable to avoid STEP display as 0 on pendant during transitions
394394

395395
if (hal_get_bool(xhc->hal->stepsize_up)) {
396396
_inc_step_status = STEP_UP;
@@ -419,8 +419,8 @@ void handle_step(xhc_t *xhc)
419419

420420
xhc->old_inc_step_status = _inc_step_status;
421421

422-
hal_set_si32(xhc->hal->stepsize, _stepsize);
423-
hal_set_real(xhc->hal->jog_scale, hal_get_si32(xhc->hal->stepsize) * 0.001f);
422+
hal_set_sint(xhc->hal->stepsize, _stepsize);
423+
hal_set_real(xhc->hal->jog_scale, hal_get_sint(xhc->hal->stepsize) * 0.001f);
424424
}
425425

426426
void cb_response_in(struct libusb_transfer *transfer)
@@ -434,8 +434,8 @@ void cb_response_in(struct libusb_transfer *transfer)
434434
xhc.button_code = in_buf[1];
435435
xhc.axis = (xhc_axis_t)in_buf[3];
436436

437-
hal_set_si32(xhc.hal->jog_counts, hal_get_si32(xhc.hal->jog_counts) + ((signed char)in_buf[4]));
438-
hal_set_si32(xhc.hal->jog_counts_neg, - hal_get_si32(xhc.hal->jog_counts));
437+
hal_set_sint(xhc.hal->jog_counts, hal_get_sint(xhc.hal->jog_counts) + ((signed char)in_buf[4]));
438+
hal_set_sint(xhc.hal->jog_counts_neg, - hal_get_sint(xhc.hal->jog_counts));
439439
hal_set_bool(xhc.hal->jog_enable_off, xhc.axis == axis_off);
440440
hal_set_bool(xhc.hal->jog_enable_x, xhc.axis == axis_x);
441441
hal_set_bool(xhc.hal->jog_enable_y, xhc.axis == axis_y);
@@ -554,7 +554,7 @@ int _hal_pin_sint_newf(hal_pdir_t dir, hal_sint_t *data_ptr_addr, int comp_id, c
554554
return hal_pin_simu(pin_name, (void**)data_ptr_addr, sizeof(hal_query_value_u));
555555
}
556556
else {
557-
return hal_pin_new_si32(comp_id, dir, data_ptr_addr, 0, "%s", pin_name);
557+
return hal_pin_new_sint(comp_id, dir, data_ptr_addr, 0, "%s", pin_name);
558558
}
559559
}
560560

@@ -812,7 +812,7 @@ int main (int argc,char **argv)
812812
hal_set_bool(xhc.hal->connected, 0);
813813
wait_secs = 0;
814814
hal_set_bool(xhc.hal->require_pendant, wait_for_pendant_before_HAL);
815-
hal_set_si32(xhc.hal->stepsize, stepsize_sequence[0]);
815+
hal_set_sint(xhc.hal->stepsize, stepsize_sequence[0]);
816816

817817
do {
818818
cnt = libusb_get_device_list(ctx, &devs);

‎src/hal/user_comps/xhc-whb04b-6/hal.cc‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ int Hal::newHalSigned32(hal_pdir_t direction, hal_sint_t *ptr, int componentId,
298298
}
299299
else
300300
{
301-
int r = hal_pin_new_si32(componentId, direction, ptr, 0, "%s", pin_name);
301+
int r = hal_pin_new_sint(componentId, direction, ptr, 0, "%s", pin_name);
302302
assert(r == 0);
303303
return r;
304304
}
@@ -334,7 +334,7 @@ int Hal::newHalUnsigned32(hal_pdir_t direction, hal_uint_t *ptr, int componentId
334334
}
335335
else
336336
{
337-
int r = hal_pin_new_ui32(componentId, direction, ptr, 0, "%s", pin_name);
337+
int r = hal_pin_new_uint(componentId, direction, ptr, 0, "%s", pin_name);
338338
assert(r == 0);
339339
return r;
340340
}
@@ -1321,12 +1321,12 @@ void Hal::setJogCounts(const HandWheelCounters& counters)
13211321
else if (hal_get_bool(memory->out.axisCSelect) && !hal_get_bool(memory->in.JointCisHomed)) {requestTeleopMode(true);}
13221322
{requestManualMode(true);}
13231323

1324-
hal_set_si32(memory->out.axisXJogCounts, counters.counts(HandWheelCounters::CounterNameToIndex::AXIS_X));
1325-
hal_set_si32(memory->out.axisYJogCounts, counters.counts(HandWheelCounters::CounterNameToIndex::AXIS_Y));
1326-
hal_set_si32(memory->out.axisZJogCounts, counters.counts(HandWheelCounters::CounterNameToIndex::AXIS_Z));
1327-
hal_set_si32(memory->out.axisAJogCounts, counters.counts(HandWheelCounters::CounterNameToIndex::AXIS_A));
1328-
hal_set_si32(memory->out.axisBJogCounts, counters.counts(HandWheelCounters::CounterNameToIndex::AXIS_B));
1329-
hal_set_si32(memory->out.axisCJogCounts, counters.counts(HandWheelCounters::CounterNameToIndex::AXIS_C));
1324+
hal_set_sint(memory->out.axisXJogCounts, counters.counts(HandWheelCounters::CounterNameToIndex::AXIS_X));
1325+
hal_set_sint(memory->out.axisYJogCounts, counters.counts(HandWheelCounters::CounterNameToIndex::AXIS_Y));
1326+
hal_set_sint(memory->out.axisZJogCounts, counters.counts(HandWheelCounters::CounterNameToIndex::AXIS_Z));
1327+
hal_set_sint(memory->out.axisAJogCounts, counters.counts(HandWheelCounters::CounterNameToIndex::AXIS_A));
1328+
hal_set_sint(memory->out.axisBJogCounts, counters.counts(HandWheelCounters::CounterNameToIndex::AXIS_B));
1329+
hal_set_sint(memory->out.axisCJogCounts, counters.counts(HandWheelCounters::CounterNameToIndex::AXIS_C));
13301330

13311331
requestManualMode(false);
13321332
requestTeleopMode(false);

‎src/hal/user_comps/xhc-whb04b-6/pendant-types.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ class HandWheelCounters
6060

6161
HandWheelCounters();
6262

63+
// The underlying counters in this class (mCounters array below) are still
64+
// int32_t. They are written into hal_sint_t pins. But that does not really
65+
// matter. If the counters here run out, then it would probably have been a
66+
// problem before. Now the HAL pin writes are simply sign-extended when fed
67+
// from the counts() method.
68+
6369
void count(int8_t delta);
6470
//! Return the currently active counter which is in-/decreased by \xrefitem count(uint8_t).
6571
//! The current counter mode is set via \xrefitem setModeActive(CounterNameToIndex).

0 commit comments

Comments
 (0)