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
23 changes: 14 additions & 9 deletions src/hal/drivers/mesa-hostmot2/dpll.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -177,16 +180,18 @@ 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,
&buff,
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,
Expand Down
2 changes: 1 addition & 1 deletion src/hal/drivers/mesa-hostmot2/hostmot2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
14 changes: 7 additions & 7 deletions src/hal/drivers/mesa-hostmot2/hostmot2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
67 changes: 34 additions & 33 deletions src/hal/drivers/mesa-hostmot2/inm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}
}
Expand Down
Loading