/* init_hal_io() exports HAL pins and parameters making data from the realtime control module visible and usable by the world */ static int init_hal_io(void) { int n, retval; joint_hal_t *joint_data; rtapi_print_msg(RTAPI_MSG_INFO, "MOTION: init_hal_io() starting...\n"); /* allocate shared memory for machine data */ emcmot_hal_data = hal_malloc(sizeof(emcmot_hal_data_t)); if (emcmot_hal_data == 0) { rtapi_print_msg(RTAPI_MSG_ERR, _("MOTION: emcmot_hal_data malloc failed\n")); return -1; } /* export machine wide hal pins */ if ((retval = hal_pin_bit_newf(HAL_IN, &(emcmot_hal_data->probe_input), mot_comp_id, "motion.probe-input")) < 0) goto error; if ((retval = hal_pin_bit_newf(HAL_IO, &(emcmot_hal_data->spindle_index_enable), mot_comp_id, "motion.spindle-index-enable")) < 0) goto error; if ((retval = hal_pin_bit_newf(HAL_OUT, &(emcmot_hal_data->spindle_on), mot_comp_id, "motion.spindle-on")) < 0) goto error; if ((retval = hal_pin_bit_newf(HAL_OUT, &(emcmot_hal_data->spindle_forward), mot_comp_id, "motion.spindle-forward")) < 0) goto error; if ((retval = hal_pin_bit_newf(HAL_OUT, &(emcmot_hal_data->spindle_reverse), mot_comp_id, "motion.spindle-reverse")) < 0) goto error; if ((retval = hal_pin_bit_newf(HAL_OUT, &(emcmot_hal_data->spindle_brake), mot_comp_id, "motion.spindle-brake")) < 0) goto error; if ((retval = hal_pin_float_newf(HAL_OUT, &(emcmot_hal_data->spindle_speed_out), mot_comp_id, "motion.spindle-speed-out")) < 0) goto error; if ((retval = hal_pin_float_newf(HAL_OUT, &(emcmot_hal_data->spindle_speed_out_abs), mot_comp_id, "motion.spindle-speed-out-abs")) < 0) goto error; if ((retval = hal_pin_float_newf(HAL_OUT, &(emcmot_hal_data->spindle_speed_out_rps), mot_comp_id, "motion.spindle-speed-out-rps")) < 0) goto error; if ((retval = hal_pin_float_newf(HAL_OUT, &(emcmot_hal_data->spindle_speed_out_rps_abs), mot_comp_id, "motion.spindle-speed-out-rps-abs")) < 0) goto error; if ((retval = hal_pin_float_newf(HAL_OUT, &(emcmot_hal_data->spindle_speed_cmd_rps), mot_comp_id, "motion.spindle-speed-cmd-rps")) < 0) goto error; if ((retval = hal_pin_bit_newf(HAL_IN, &(emcmot_hal_data->spindle_inhibit), mot_comp_id, "motion.spindle-inhibit")) < 0) goto error; *(emcmot_hal_data->spindle_inhibit) = 0; // spindle orient pins if ((retval = hal_pin_float_newf(HAL_OUT, &(emcmot_hal_data->spindle_orient_angle), mot_comp_id, "motion.spindle-orient-angle")) < 0) goto error; if ((retval = hal_pin_s32_newf(HAL_OUT, &(emcmot_hal_data->spindle_orient_mode), mot_comp_id, "motion.spindle-orient-mode")) < 0) goto error; if ((retval = hal_pin_bit_newf(HAL_OUT, &(emcmot_hal_data->spindle_orient), mot_comp_id, "motion.spindle-orient")) < 0) goto error; if ((retval = hal_pin_bit_newf(HAL_OUT, &(emcmot_hal_data->spindle_locked), mot_comp_id, "motion.spindle-locked")) < 0) goto error; if ((retval = hal_pin_bit_newf(HAL_IN, &(emcmot_hal_data->spindle_is_oriented), mot_comp_id, "motion.spindle-is-oriented")) < 0) goto error; if ((retval = hal_pin_s32_newf(HAL_IN, &(emcmot_hal_data->spindle_orient_fault), mot_comp_id, "motion.spindle-orient-fault")) < 0) goto error; *(emcmot_hal_data->spindle_orient_angle) = 0.0; *(emcmot_hal_data->spindle_orient_mode) = 0; *(emcmot_hal_data->spindle_orient) = 0; // if ((retval = hal_pin_bit_newf(HAL_OUT, &(emcmot_hal_data->inpos_output), mot_comp_id, "motion.motion-inpos")) < 0) goto error; if ((retval = hal_pin_float_newf(HAL_IN, &(emcmot_hal_data->spindle_revs), mot_comp_id, "motion.spindle-revs")) < 0) goto error; if ((retval = hal_pin_float_newf(HAL_IN, &(emcmot_hal_data->spindle_speed_in), mot_comp_id, "motion.spindle-speed-in")) < 0) goto error; if ((retval = hal_pin_bit_newf(HAL_IN, &(emcmot_hal_data->spindle_is_atspeed), mot_comp_id, "motion.spindle-at-speed")) < 0) goto error; *emcmot_hal_data->spindle_is_atspeed = 1; if ((retval = hal_pin_float_newf(HAL_IN, &(emcmot_hal_data->adaptive_feed), mot_comp_id, "motion.adaptive-feed")) < 0) goto error; *(emcmot_hal_data->adaptive_feed) = 1.0; if ((retval = hal_pin_bit_newf(HAL_IN, &(emcmot_hal_data->feed_hold), mot_comp_id, "motion.feed-hold")) < 0) goto error; *(emcmot_hal_data->feed_hold) = 0; if ((retval = hal_pin_bit_newf(HAL_IN, &(emcmot_hal_data->feed_inhibit), mot_comp_id, "motion.feed-inhibit")) < 0) goto error; *(emcmot_hal_data->feed_inhibit) = 0; if ((retval = hal_pin_bit_newf(HAL_IN, &(emcmot_hal_data->enable), mot_comp_id, "motion.enable")) < 0) goto error; /* export motion-synched digital output pins */ /* export motion digital input pins */ for (n = 0; n < num_dio; n++) { if ((retval = hal_pin_bit_newf(HAL_OUT, &(emcmot_hal_data->synch_do[n]), mot_comp_id, "motion.digital-out-%02d", n)) < 0) goto error; if ((retval = hal_pin_bit_newf(HAL_IN, &(emcmot_hal_data->synch_di[n]), mot_comp_id, "motion.digital-in-%02d", n)) < 0) goto error; } /* export motion analog input pins */ for (n = 0; n < num_aio; n++) { if ((retval = hal_pin_float_newf(HAL_OUT, &(emcmot_hal_data->analog_output[n]), mot_comp_id, "motion.analog-out-%02d", n)) < 0) goto error; if ((retval = hal_pin_float_newf(HAL_IN, &(emcmot_hal_data->analog_input[n]), mot_comp_id, "motion.analog-in-%02d", n)) < 0) goto error; } /* export machine wide hal parameters */ retval = hal_pin_bit_new("motion.motion-enabled", HAL_OUT, &(emcmot_hal_data->motion_enabled), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_bit_new("motion.in-position", HAL_OUT, &(emcmot_hal_data->in_position), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_bit_new("motion.coord-mode", HAL_OUT, &(emcmot_hal_data->coord_mode), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_bit_new("motion.teleop-mode", HAL_OUT, &(emcmot_hal_data->teleop_mode), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_bit_new("motion.coord-error", HAL_OUT, &(emcmot_hal_data->coord_error), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_bit_new("motion.on-soft-limit", HAL_OUT, &(emcmot_hal_data->on_soft_limit), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_float_new("motion.current-vel", HAL_OUT, &(emcmot_hal_data->current_vel), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_float_new("motion.requested-vel", HAL_OUT, &(emcmot_hal_data->requested_vel), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_float_new("motion.distance-to-go", HAL_OUT, &(emcmot_hal_data->distance_to_go), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_s32_new("motion.program-line", HAL_OUT, &(emcmot_hal_data->program_line), mot_comp_id); if (retval != 0) { return retval; } /* export debug parameters */ /* these can be used to view any internal variable, simply change a line in control.c:output_to_hal() and recompile */ retval = hal_param_bit_new("motion.debug-bit-0", HAL_RO, &(emcmot_hal_data->debug_bit_0), mot_comp_id); if (retval != 0) { return retval; } retval = hal_param_bit_new("motion.debug-bit-1", HAL_RO, &(emcmot_hal_data->debug_bit_1), mot_comp_id); if (retval != 0) { return retval; } retval = hal_param_float_new("motion.debug-float-0", HAL_RO, &(emcmot_hal_data->debug_float_0), mot_comp_id); if (retval != 0) { return retval; } retval = hal_param_float_new("motion.debug-float-1", HAL_RO, &(emcmot_hal_data->debug_float_1), mot_comp_id); if (retval != 0) { return retval; } retval = hal_param_float_new("motion.debug-float-2", HAL_RO, &(emcmot_hal_data->debug_float_2), mot_comp_id); if (retval != 0) { return retval; } retval = hal_param_float_new("motion.debug-float-3", HAL_RO, &(emcmot_hal_data->debug_float_3), mot_comp_id); if (retval != 0) { return retval; } retval = hal_param_s32_new("motion.debug-s32-0", HAL_RO, &(emcmot_hal_data->debug_s32_0), mot_comp_id); if (retval != 0) { return retval; } retval = hal_param_s32_new("motion.debug-s32-1", HAL_RO, &(emcmot_hal_data->debug_s32_1), mot_comp_id); if (retval != 0) { return retval; } // FIXME - debug only, remove later // export HAL parameters for some trajectory planner internal variables // so they can be scoped retval = hal_param_float_new("traj.pos_out", HAL_RO, &(emcmot_hal_data->traj_pos_out), mot_comp_id); if (retval != 0) { return retval; } retval = hal_param_float_new("traj.vel_out", HAL_RO, &(emcmot_hal_data->traj_vel_out), mot_comp_id); if (retval != 0) { return retval; } retval = hal_param_u32_new("traj.active_tc", HAL_RO, &(emcmot_hal_data->traj_active_tc), mot_comp_id); if (retval != 0) { return retval; } for ( n = 0 ; n < 4 ; n++ ) { retval = hal_param_float_newf(HAL_RO, &(emcmot_hal_data->tc_pos[n]), mot_comp_id, "tc.%d.pos", n); if (retval != 0) { return retval; } retval = hal_param_float_newf(HAL_RO, &(emcmot_hal_data->tc_vel[n]), mot_comp_id, "tc.%d.vel", n); if (retval != 0) { return retval; } retval = hal_param_float_newf(HAL_RO, &(emcmot_hal_data->tc_acc[n]), mot_comp_id, "tc.%d.acc", n); if (retval != 0) { return retval; } } // end of exporting trajectory planner internals // export timing related HAL parameters so they can be scoped retval = hal_param_u32_new("motion.servo.last-period", HAL_RO, &(emcmot_hal_data->last_period), mot_comp_id); if (retval != 0) { return retval; } #ifdef HAVE_CPU_KHZ retval = hal_param_float_new("motion.servo.last-period-ns", HAL_RO, &(emcmot_hal_data->last_period_ns), mot_comp_id); if (retval != 0) { return retval; } #endif retval = hal_param_u32_new("motion.servo.overruns", HAL_RW, &(emcmot_hal_data->overruns), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_float_new("motion.tooloffset.x", HAL_OUT, &(emcmot_hal_data->tooloffset_x), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_float_new("motion.tooloffset.y", HAL_OUT, &(emcmot_hal_data->tooloffset_y), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_float_new("motion.tooloffset.z", HAL_OUT, &(emcmot_hal_data->tooloffset_z), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_float_new("motion.tooloffset.a", HAL_OUT, &(emcmot_hal_data->tooloffset_a), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_float_new("motion.tooloffset.b", HAL_OUT, &(emcmot_hal_data->tooloffset_b), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_float_new("motion.tooloffset.c", HAL_OUT, &(emcmot_hal_data->tooloffset_c), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_float_new("motion.tooloffset.u", HAL_OUT, &(emcmot_hal_data->tooloffset_u), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_float_new("motion.tooloffset.v", HAL_OUT, &(emcmot_hal_data->tooloffset_v), mot_comp_id); if (retval != 0) { return retval; } retval = hal_pin_float_new("motion.tooloffset.w", HAL_OUT, &(emcmot_hal_data->tooloffset_w), mot_comp_id); if (retval != 0) { return retval; } /* initialize machine wide pins and parameters */ *(emcmot_hal_data->probe_input) = 0; /* default value of enable is TRUE, so simple machines can leave it disconnected */ *(emcmot_hal_data->enable) = 1; /* motion synched dio, init to not enabled */ for (n = 0; n < num_dio; n++) { *(emcmot_hal_data->synch_do[n]) = 0; *(emcmot_hal_data->synch_di[n]) = 0; } for (n = 0; n < num_aio; n++) { *(emcmot_hal_data->analog_output[n]) = 0.0; *(emcmot_hal_data->analog_input[n]) = 0.0; } /*! \todo FIXME - these don't really need initialized, since they are written with data from the emcmotStatus struct */ *(emcmot_hal_data->motion_enabled) = 0; *(emcmot_hal_data->in_position) = 0; *(emcmot_hal_data->coord_mode) = 0; *(emcmot_hal_data->teleop_mode) = 0; *(emcmot_hal_data->coord_error) = 0; *(emcmot_hal_data->on_soft_limit) = 0; /* init debug parameters */ emcmot_hal_data->debug_bit_0 = 0; emcmot_hal_data->debug_bit_1 = 0; emcmot_hal_data->debug_float_0 = 0.0; emcmot_hal_data->debug_float_1 = 0.0; emcmot_hal_data->debug_float_2 = 0.0; emcmot_hal_data->debug_float_3 = 0.0; emcmot_hal_data->overruns = 0; emcmot_hal_data->last_period = 0; /* export joint pins and parameters */ for (n = 0; n < num_joints; n++) { /* point to axis data */ joint_data = &(emcmot_hal_data->joint[n]); /* export all vars */ retval = export_joint(n, joint_data); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, _("MOTION: joint %d pin/param export failed\n"), n); return -1; } /* init axis pins and parameters */ /* FIXME - struct members are in a state of flux - make sure to update this - most won't need initing anyway */ *(joint_data->amp_enable) = 0; *(joint_data->home_state) = 0; /* We'll init the index model to EXT_ENCODER_INDEX_MODEL_RAW for now, because it is always supported. */ } /* Done! */ rtapi_print_msg(RTAPI_MSG_INFO, "MOTION: init_hal_io() complete, %d axes.\n", n); return 0; error: return retval; }
int rtapi_app_main(void) { int result, i; CopySizesInfosFromModuleParams(); compId = hal_init("classicladder_rt"); if(compId < 0) return compId; rtapi_print("creating ladder-state\n"); result = hal_export_funct("classicladder.0.refresh",hal_task,0,1, 0, compId); if(result < 0) { error: hal_exit(compId); return result; } hal_state = hal_malloc(sizeof(hal_s32_t)); result = hal_param_s32_new("classicladder.ladder-state", HAL_RO, hal_state, compId); if(result < 0) { hal_exit(compId); return result; } hal_inputs = hal_malloc(sizeof(hal_bit_t*) * numPhysInputs); if(!hal_inputs) { result = -ENOMEM; goto error; } hide_gui = hal_malloc(sizeof(hal_bit_t*)); if(!hide_gui) { result = -ENOMEM; goto error; } hal_s32_inputs = hal_malloc(sizeof(hal_s32_t*) * numS32in); if(!hal_s32_inputs) { result = -ENOMEM; goto error; } hal_float_inputs = hal_malloc(sizeof(hal_float_t*) * numFloatIn); if(!hal_float_inputs) { result = -ENOMEM; goto error; } hal_outputs = hal_malloc(sizeof(hal_bit_t*) * numPhysOutputs); if(!hal_outputs) { result = -ENOMEM; goto error; } hal_s32_outputs = hal_malloc(sizeof(hal_s32_t*) * numS32out); if(!hal_s32_outputs) { result = -ENOMEM; goto error; } hal_float_outputs = hal_malloc(sizeof(hal_float_t*) * numFloatOut); if(!hal_float_outputs) { result = -ENOMEM; goto error; } for(i=0; i<numPhysInputs; i++) { result = hal_pin_bit_newf(HAL_IN, &hal_inputs[i], compId, "classicladder.0.in-%02d", i); if(result < 0) goto error; } result = hal_pin_bit_newf(HAL_IN, &hide_gui[0], compId, "classicladder.0.hide_gui"); if(result < 0) goto error; for(i=0; i<numS32in; i++) { result = hal_pin_s32_newf(HAL_IN, &hal_s32_inputs[i], compId, "classicladder.0.s32in-%02d", i); if(result < 0) goto error; } for(i=0; i<numFloatIn; i++) { result = hal_pin_float_newf(HAL_IN, &hal_float_inputs[i], compId, "classicladder.0.floatin-%02d", i); if(result < 0) goto error; } for(i=0; i<numPhysOutputs; i++) { result = hal_pin_bit_newf(HAL_OUT, &hal_outputs[i], compId, "classicladder.0.out-%02d", i); if(result < 0) goto error; } for(i=0; i<numS32out; i++) { result = hal_pin_s32_newf(HAL_OUT, &hal_s32_outputs[i], compId, "classicladder.0.s32out-%02d", i); if(result < 0) goto error; } for(i=0; i<numFloatOut; i++) { result = hal_pin_float_newf(HAL_OUT, &hal_float_outputs[i], compId, "classicladder.0.floatout-%02d", i); if(result < 0) goto error; } hal_ready(compId); ClassicLadder_AllocAll( ); return 0; }
static int export_freqgen(int num, freqgen_t * addr, int step_type) { int n, retval, msg; char buf[HAL_NAME_LEN + 2]; /* This function exports a lot of stuff, which results in a lot of logging if msg_level is at INFO or ALL. So we save the current value of msg_level and restore it later. If you actually need to log this function's actions, change the second line below */ msg = rtapi_get_msg_level(); rtapi_set_msg_level(RTAPI_MSG_WARN); /* export param variable for raw counts */ rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.rawcounts", num); retval = hal_param_s32_new(buf, HAL_RO, &(addr->rawcount), comp_id); if (retval != 0) { return retval; } /* export pin for counts captured by update() */ rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.counts", num); retval = hal_pin_s32_new(buf, HAL_OUT, &(addr->count), comp_id); if (retval != 0) { return retval; } /* export pin for scaled position captured by update() */ rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.position-fb", num); retval = hal_pin_float_new(buf, HAL_OUT, &(addr->pos), comp_id); if (retval != 0) { return retval; } /* export parameter for position scaling */ rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.position-scale", num); retval = hal_param_float_new(buf, HAL_RW, &(addr->pos_scale), comp_id); if (retval != 0) { return retval; } /* export pin for frequency command */ rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.velocity", num); retval = hal_pin_float_new(buf, HAL_IN, &(addr->vel), comp_id); if (retval != 0) { return retval; } /* export parameter for frequency scaling */ rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.velocity-scale", num); retval = hal_param_float_new(buf, HAL_RW, &(addr->vel_scale), comp_id); if (retval != 0) { return retval; } /* export parameter for max frequency */ rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.maxfreq", num); retval = hal_param_float_new(buf, HAL_RW, &(addr->maxfreq), comp_id); if (retval != 0) { return retval; } /* export param for scaled velocity (frequency in Hz) */ rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.frequency", num); retval = hal_param_float_new(buf, HAL_RO, &(addr->freq), comp_id); if (retval != 0) { return retval; } /* export parameter for max accel/decel */ rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.maxaccel", num); retval = hal_param_float_new(buf, HAL_RW, &(addr->maxaccel), comp_id); if (retval != 0) { return retval; } /* set default parameter values */ addr->pos_scale = 1.0; addr->vel_scale = 1.0; /* set maxfreq very high - let update_freq() fix it */ addr->maxfreq = 1e15; addr->maxaccel = 0.0; addr->wd.st0.step_type = step_type; /* init the step generator core to zero output */ addr->accum = 0; addr->addval = 0; addr->newaddval = 0; addr->deltalim = 0; addr->rawcount = 0; addr->printed_error = 0; if (step_type == 0) { /* setup for stepping type 0 - step/dir */ addr->wd.st0.need_step = 0; addr->wd.st0.setup_timer = 0; addr->wd.st0.hold_timer = 0; addr->wd.st0.space_timer = 0; addr->wd.st0.len_timer = 0; /* export parameters for step/dir pulse timing */ rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.dirsetup", num); retval = hal_param_u32_new(buf, HAL_RW, &(addr->wd.st0.dir_setup), comp_id); if (retval != 0) { return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.dirhold", num); retval = hal_param_u32_new(buf, HAL_RW, &(addr->wd.st0.dir_hold), comp_id); if (retval != 0) { return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.steplen", num); retval = hal_param_u32_new(buf, HAL_RW, &(addr->wd.st0.step_len), comp_id); if (retval != 0) { return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.stepspace", num); retval = hal_param_u32_new(buf, HAL_RW, &(addr->wd.st0.step_space), comp_id); if (retval != 0) { return retval; } /* init the parameters */ addr->wd.st0.dir_setup = 1; addr->wd.st0.dir_hold = 1; addr->wd.st0.step_len = 1; addr->wd.st0.step_space = 1; /* export pins for step and direction */ rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.step", num); retval = hal_pin_bit_new(buf, HAL_OUT, &(addr->phase[STEP_PIN]), comp_id); if (retval != 0) { return retval; } *(addr->phase[STEP_PIN]) = 0; rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.dir", num); retval = hal_pin_bit_new(buf, HAL_OUT, &(addr->phase[DIR_PIN]), comp_id); if (retval != 0) { return retval; } *(addr->phase[DIR_PIN]) = 0; } else if (step_type == 1) { /* setup for stepping type 1 - pseudo-PWM */ /* export pins for up and down */ rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.up", num); retval = hal_pin_bit_new(buf, HAL_OUT, &(addr->phase[UP_PIN]), comp_id); if (retval != 0) { return retval; } *(addr->phase[UP_PIN]) = 0; rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.down", num); retval = hal_pin_bit_new(buf, HAL_OUT, &(addr->phase[DOWN_PIN]), comp_id); if (retval != 0) { return retval; } *(addr->phase[DOWN_PIN]) = 0; rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.count", num); retval = hal_pin_bit_new(buf, HAL_OUT, &(addr->phase[COUNT_PIN]), comp_id); if (retval != 0) { return retval; } *(addr->phase[COUNT_PIN]) = 0; } else { /* setup for stepping types 2 and higher */ addr->wd.st2.state = 0; addr->wd.st2.cycle_max = cycle_len_lut[step_type - 2] - 1; addr->wd.st2.num_phases = num_phases_lut[step_type - 2]; addr->wd.st2.lut = &(master_lut[step_type - 2][0]); /* export pins for output phases */ for (n = 0; n < addr->wd.st2.num_phases; n++) { rtapi_snprintf(buf, HAL_NAME_LEN, "freqgen.%d.phase-%c", num, n + 'A'); retval = hal_pin_bit_new(buf, HAL_OUT, &(addr->phase[n]), comp_id); if (retval != 0) { return retval; } *(addr->phase[n]) = 0; } } /* set initial pin values */ *(addr->count) = 0; *(addr->pos) = 0.0; *(addr->vel) = 0.0; /* restore saved message level */ rtapi_set_msg_level(msg); return 0; }
static int export_wsum(int num, int num_bits, wsum_t *addr, wsum_bit_t *bitaddr) { int retval, i, w; char buf[HAL_NAME_LEN + 2], base[HAL_NAME_LEN]; rtapi_snprintf(base, HAL_NAME_LEN, "wsum.%d", num); /* export pin for offset (input) */ rtapi_snprintf(buf, HAL_NAME_LEN, "%s.offset", base); retval = hal_param_s32_new(buf, HAL_RW, &(addr->offset), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "WEIGHTED_SUM: ERROR: '%s' param export failed\n", buf); return retval; } /* export pin for output sum */ rtapi_snprintf(buf, HAL_NAME_LEN, "%s.sum", base); retval = hal_pin_s32_new(buf, HAL_OUT, &(addr->sum), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "WEIGHTED_SUM: ERROR: '%s' pin export failed\n", buf); return retval; } /* export pin for update hold */ rtapi_snprintf(buf, HAL_NAME_LEN, "%s.hold", base); retval = hal_pin_bit_new(buf, HAL_IN, &(addr->hold), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "WEIGHTED_SUM: ERROR: '%s' pin export failed\n", buf); return retval; } addr->bits = bitaddr; addr->num_bits = num_bits; /* export the input bits and weight parameters, and set the default weights */ w = 1; for (i=0;i<num_bits;i++) { rtapi_snprintf(buf, HAL_NAME_LEN, "%s.bit.%d.in", base, i); retval = hal_pin_bit_new(buf, HAL_IN, &(addr->bits[i].bit), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "WEIGHTED_SUM: ERROR: '%s' pin export failed\n", buf); return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "%s.bit.%d.weight", base, i); retval = hal_param_s32_new(buf, HAL_RW, &(addr->bits[i].weight), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "WEIGHTED_SUM: ERROR: '%s' param export failed\n", buf); return retval; } addr->bits[i].weight = w; w <<= 1; } /* set initial parameter and pin values */ addr->offset = 0; *(addr->sum) = 0; return 0; }