hal_ppmc.c
来自「CNC 的开放码,EMC2 V2.2.8版」· C语言 代码 · 共 1,961 行 · 第 1/5 页
C
1,961 行
slot->digin = hal_malloc(16 * sizeof(din_t)); if (slot->digin == 0) { rtapi_print_msg(RTAPI_MSG_ERR, "PPMC: ERROR: hal_malloc() failed\n"); return -1; } for ( n = 0 ; n < 16 ; n++ ) { /* export pins for input data */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.din.%02d.in", bus->busnum, bus->last_digin); retval = hal_pin_bit_new(buf, HAL_OUT, &(slot->digin[n].data), comp_id); if (retval != 0) { return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.din.%02d.in-not", bus->busnum, bus->last_digin); retval = hal_pin_bit_new(buf, HAL_OUT, &(slot->digin[n].data_not), comp_id); if (retval != 0) { return retval; } /* increment number to prepare for next output */ bus->last_digin++; } add_rd_funct(read_digins, slot, block(UxC_DINA, UxC_DINB)); return 0;}static int export_UxC_digout(slot_data_t *slot, bus_data_t *bus){ int retval, n; char buf[HAL_NAME_LEN + 2]; rtapi_print_msg(RTAPI_MSG_INFO, "PPMC: exporting UxC digital outputs\n"); /* do hardware init */ /* turn off all outputs */ SelWrt(0, slot->slot_base+UxC_DOUTA, slot->port_addr); if (bus->last_digout > 7) { // if not first UxC, set it to slave mode rtapi_print_msg(RTAPI_MSG_INFO, "PPMC: slave UxC addr %x\n",slot->slot_base+UxC_SLAVE); SelWrt(1,slot->slot_base+UxC_SLAVE,slot->port_addr); rtapi_print_msg(RTAPI_MSG_INFO, "PPMC: slave UxC # %d\n",bus->last_digout); } /* allocate shared memory for the digital output data */ slot->digout = hal_malloc(8 * sizeof(dout_t)); if (slot->digout == 0) { rtapi_print_msg(RTAPI_MSG_ERR, "PPMC: ERROR: hal_malloc() failed\n"); return -1; } for ( n = 0 ; n < 8 ; n++ ) { /* export pin for output data */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.dout.%02d.out", bus->busnum, bus->last_digout); retval = hal_pin_bit_new(buf, HAL_IN, &(slot->digout[n].data), comp_id); if (retval != 0) { return retval; } /* export parameter for inversion */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.dout.%02d.invert", bus->busnum, bus->last_digout); retval = hal_param_bit_new(buf, HAL_RW, &(slot->digout[n].invert), comp_id); if (retval != 0) { return retval; } slot->digout[n].invert = 0; /* increment number to prepare for next output */ bus->last_digout++; } add_wr_funct(write_digouts, slot, block(UxC_DOUTA, UxC_DOUTA)); return 0;}static int export_PPMC_digin(slot_data_t *slot, bus_data_t *bus){ int retval, n; char buf[HAL_NAME_LEN + 2]; rtapi_print_msg(RTAPI_MSG_INFO, "PPMC: exporting PPMC digital inputs\n"); /* do hardware init */ /* allocate shared memory for the digital input data */ slot->digin = hal_malloc(18 * sizeof(din_t)); // 18 inputs per unit if (slot->digin == 0) { rtapi_print_msg(RTAPI_MSG_ERR, "PPMC: ERROR: hal_malloc() failed\n"); return -1; } for ( n = 0 ; n < 16 ; n++ ) { /* export pins for input data */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.din.%02d.in", bus->busnum, bus->last_digin); retval = hal_pin_bit_new(buf, HAL_OUT, &(slot->digin[n].data), comp_id); if (retval != 0) { return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.din.%02d.in-not", bus->busnum, bus->last_digin); retval = hal_pin_bit_new(buf, HAL_OUT, &(slot->digin[n].data_not), comp_id); if (retval != 0) { return retval; } /* increment number to prepare for next output */ bus->last_digin++; } if (bus->last_digin < 31) { rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.din.estop.in", bus->busnum); retval = hal_pin_bit_new(buf, HAL_OUT, &(slot->digin[16].data), comp_id); if (retval != 0) { return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.din.estop.in-not", bus->busnum); retval = hal_pin_bit_new(buf, HAL_OUT, &(slot->digin[16].data_not), comp_id); if (retval != 0) { return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.din.fault.in", bus->busnum); retval = hal_pin_bit_new(buf, HAL_OUT, &(slot->digin[17].data), comp_id); if (retval != 0) { return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.din.fault.in-not", bus->busnum); retval = hal_pin_bit_new(buf, HAL_OUT, &(slot->digin[17].data_not), comp_id); if (retval != 0) { return retval; } add_rd_funct(read_PPMC_digins, slot, block(DIO_DINA, DIO_ESTOP_IN)); rtapi_print_msg(RTAPI_MSG_INFO, "PPMC: exporting as MASTER D In\n"); } else { add_rd_funct(read_PPMC_digins, slot, block(DIO_DINA, DIO_DINB)); rtapi_print_msg(RTAPI_MSG_INFO, "PPMC: exporting as SLAVE D In\n"); } return 0;}static int export_PPMC_digout(slot_data_t *slot, bus_data_t *bus){ int retval, n; char buf[HAL_NAME_LEN + 2]; rtapi_print_msg(RTAPI_MSG_INFO, "PPMC: exporting PPMC digital outputs\n"); /* do hardware init */ /* turn off all outputs */ SelWrt(0, slot->slot_base+DIO_DOUTA, slot->port_addr); if (bus->last_digout > 7) { // if not first PPMC DIO, set it to slave mode rtapi_print_msg(RTAPI_MSG_INFO, "PPMC: slave DIO addr %x\n",slot->slot_base+DIO_ESTOP_OUT); SelWrt(2,slot->slot_base+DIO_ESTOP_OUT,slot->port_addr); rtapi_print_msg(RTAPI_MSG_INFO, "PPMC: slave DIO # %d\n",bus->last_digout); } /* allocate shared memory for the digital output data */ slot->digout = hal_malloc(9 * sizeof(dout_t)); // 8 outputs per board + estop if (slot->digout == 0) { rtapi_print_msg(RTAPI_MSG_ERR, "PPMC: ERROR: hal_malloc() failed\n"); return -1; } for ( n = 0 ; n < 8 ; n++ ) { /* export pin for output data */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.dout.%02d.out", bus->busnum, bus->last_digout); retval = hal_pin_bit_new(buf, HAL_IN, &(slot->digout[n].data), comp_id); if (retval != 0) { return retval; } /* export parameter for inversion */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.dout.%02d.invert", bus->busnum, bus->last_digout); retval = hal_param_bit_new(buf, HAL_RW, &(slot->digout[n].invert), comp_id); if (retval != 0) { return retval; } slot->digout[n].invert = 0; /* increment number to prepare for next output */ bus->last_digout++; } /* export pin for E-Stop control */ if (bus->last_digout < 15) { // only on first DIO board rtapi_print_msg(RTAPI_MSG_INFO, "PPMC: master DIO at # %d\n",bus->last_digout); rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.dout.Estop.out", bus->busnum); retval = hal_pin_bit_new(buf, HAL_IN, &(slot->digout[8].data), comp_id); if (retval != 0) { return retval; } /* export parameter for inversion */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.dout.Estop.invert", bus->busnum); retval = hal_param_bit_new(buf, HAL_RW, &(slot->digout[8].invert), comp_id); if (retval != 0) { return retval; } slot->digout[8].invert = 0; bus->last_digout++; add_wr_funct(write_PPMC_digouts, slot, block(DIO_DOUTA, DIO_ESTOP_OUT)); rtapi_print_msg(RTAPI_MSG_INFO, "PPMC: exporting as MASTER D Out\n"); } else { add_wr_funct(write_PPMC_digouts, slot, block(DIO_DOUTA, DIO_DOUTA)); //add_wr_funct(write_PPMC_digouts, slot, DIO_DOUTA, DIO_ESTOP_OUT); // hack to keep slave boards in slave rtapi_print_msg(RTAPI_MSG_INFO, "PPMC: exporting as SLAVE D Out\n"); SelWrt(2,slot->slot_base+DIO_ESTOP_OUT,slot->port_addr); } return 0;}static int export_USC_stepgen(slot_data_t *slot, bus_data_t *bus){ int retval, n; char buf[HAL_NAME_LEN + 2]; stepgen_t *sg; rtapi_print_msg(RTAPI_MSG_INFO, "PPMC: exporting step generators\n"); /* do hardware init */ /* allocate shared memory for the digital output data */ slot->stepgen = hal_malloc(sizeof(stepgens_t)); if (slot->stepgen == 0) { rtapi_print_msg(RTAPI_MSG_ERR, "PPMC: ERROR: hal_malloc() failed\n"); return -1; } /* export params that apply to all four stepgens */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.stepgen.%02d-%02d.setup-time-ns", bus->busnum, bus->last_stepgen, bus->last_stepgen+3); retval = hal_param_u32_new(buf, HAL_RW, &(slot->stepgen->setup_time_ns), comp_id); if (retval != 0) { return retval; } /* 10uS default setup time */ slot->stepgen->setup_time_ns = 10000; rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.stepgen.%02d-%02d.pulse-width-ns", bus->busnum, bus->last_stepgen, bus->last_stepgen+3); retval = hal_param_u32_new(buf, HAL_RW, &(slot->stepgen->pulse_width_ns), comp_id); if (retval != 0) { return retval; } /* 4uS default pulse width */ slot->stepgen->pulse_width_ns = 4000; rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.stepgen.%02d-%02d.pulse-space-min-ns", bus->busnum, bus->last_stepgen, bus->last_stepgen+3); retval = hal_param_u32_new(buf, HAL_RW, &(slot->stepgen->pulse_space_ns), comp_id); if (retval != 0) { return retval; } /* 4uS default pulse spacing */ slot->stepgen->pulse_space_ns = 4000; /* export per-stepgen pins and params */ for ( n = 0 ; n < 4 ; n++ ) { /* pointer to the stepgen struct */ sg = &(slot->stepgen->sg[n]); /* enable pin */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.stepgen.%02d.enable", bus->busnum, bus->last_stepgen); retval = hal_pin_bit_new(buf, HAL_IN, &(sg->enable), comp_id); if (retval != 0) { return retval; } /* velocity command pin */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.stepgen.%02d.velocity", bus->busnum, bus->last_stepgen); retval = hal_pin_float_new(buf, HAL_IN, &(sg->vel), comp_id); if (retval != 0) { return retval; } /* velocity scaling parameter */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.stepgen.%02d.scale", bus->busnum, bus->last_stepgen); retval = hal_param_float_new(buf, HAL_RW, &(sg->scale), comp_id); if (retval != 0) { return retval; } sg->scale = 1.0; /* maximum velocity parameter */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.stepgen.%02d.max-vel", bus->busnum, bus->last_stepgen); retval = hal_param_float_new(buf, HAL_RW, &(sg->max_vel), comp_id); if (retval != 0) { return retval; } sg->max_vel = 0.0; /* actual frequency parameter */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.stepgen.%02d.freq", bus->busnum, bus->last_stepgen); retval = hal_param_float_new(buf, HAL_RO, &(sg->freq), comp_id); if (retval != 0) { return retval; } /* increment number to prepare for next output */ bus->last_stepgen++; } add_wr_funct(write_stepgens, slot, block(RATE_GEN_0, RATE_WIDTH_0)); return 0;}static int export_UPC_pwmgen(slot_data_t *slot, bus_data_t *bus){ int retval, n; char buf[HAL_NAME_LEN + 2]; pwmgen_t *pg; rtapi_print_msg(RTAPI_MSG_INFO, "PPMC: exporting PWM generators\n"); /* do hardware init */ /* allocate shared memory for the PWM generators */ slot->pwmgen = hal_malloc(sizeof(pwmgens_t)); if (slot->pwmgen == 0) { rtapi_print_msg(RTAPI_MSG_ERR, "PPMC: ERROR: hal_malloc() failed\n"); return -1; } /* export params that apply to all four pwmgens */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.pwm.%02d-%02d.freq", bus->busnum, bus->last_pwmgen, bus->last_pwmgen+3); retval = hal_param_float_new(buf, HAL_RW, &(slot->pwmgen->freq), comp_id); if (retval != 0) { return retval; } /* set initial value for param */ slot->pwmgen->freq = 0.0; /* export per-pwmgen pins and params, and set initial values */ for ( n = 0 ; n < 4 ; n++ ) { /* pointer to the pwmgen struct */ pg = &(slot->pwmgen->pg[n]); /* enable pin */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.pwm.%02d.enable", bus->busnum, bus->last_pwmgen); retval = hal_pin_bit_new(buf, HAL_IN, &(pg->enable), comp_id); if (retval != 0) { return retval; } /* value command pin */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.pwm.%02d.value", bus->busnum, bus->last_pwmgen); retval = hal_pin_float_new(buf, HAL_IN, &(pg->value), comp_id); if (retval != 0) { return retval; } /* output scaling parameter */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.pwm.%02d.scale", bus->busnum, bus->last_pwmgen); retval = hal_param_float_new(buf, HAL_RW, &(pg->scale), comp_id); if (retval != 0) { return retval; } pg->scale = 1.0; /* maximum duty cycle parameter */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.pwm.%02d.max-dc", bus->busnum, bus->last_pwmgen); retval = hal_param_float_new(buf, HAL_RW, &(pg->max_dc), comp_id); if (retval != 0) { return retval; } pg->max_dc = 1.0; /* minimum duty cycle parameter */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.pwm.%02d.min-dc", bus->busnum, bus->last_pwmgen); retval = hal_param_float_new(buf, HAL_RW, &(pg->min_dc), comp_id); if (retval != 0) { return retval; } pg->min_dc = 0.0; /* actual duty cycle parameter */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.pwm.%02d.duty-cycle", bus->busnum, bus->last_pwmgen); retval = hal_param_float_new(buf, HAL_RO, &(pg->duty_cycle), comp_id); if (retval != 0) { return retval; } /* bootstrap mode parameter */ rtapi_snprintf(buf, HAL_NAME_LEN, "ppmc.%d.pwm.%02d.bootstrap", bus->busn
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?