Example #1
0
static int instantiate_lutn(const char *name,
			    const int argc,
			    const char**argv)
{
    struct inst_data *ip;
    int i, inst_id;



    if ((inputs < 1) || (inputs > 5)) {
	hal_print_msg(RTAPI_MSG_ERR,
		      "%s: invalid parameter inputs=%d, valid range=1..5",
		      name, inputs);
	return -1;
    }
    if ((function == 0) || (function == -1)) {
	hal_print_msg(RTAPI_MSG_ERR,
		      "%s: function=0x%x does not make sense",
		      name, function);
	return -1;
    }

    if ((inst_id = hal_inst_create(name, comp_id,
				  sizeof(struct inst_data) + inputs * sizeof(hal_bit_t *),
				   (void **)&ip)) < 0)
	return -1;

    hal_print_msg(RTAPI_MSG_DBG,
		  "%s: name='%s' inputs=%d function=0x%x ip=%p",
		  __FUNCTION__, name, inputs, function, ip);
    // record instance params
    ip->inputs = inputs;
    ip->function = function;

    // export per-instance HAL objects
    for (i = 0; i < ip->inputs; i++)
	if (hal_pin_bit_newf(HAL_IN, &(ip->in[i]), inst_id, "%s.in%d", name, i))
	    return -1;
    if (hal_pin_bit_newf(HAL_OUT, &(ip->out), inst_id, "%s.out", name))
	return -1;
   if (hal_export_functf(lutn, ip, 0, 0, inst_id, "%s.funct", name))
	return -1;
    return 0;
}
Example #2
0
// init HAL objects
static int export_halobjs(struct inst_data *ip, int owner_id, const char *name)
{
    if (hal_pin_float_newf(HAL_OUT, &ip->out, owner_id, "%s.out", name))
	return -1;
    if (hal_pin_float_newf(HAL_IN,  &ip->in,  owner_id, "%s.in", name))
	return -1;
    if (hal_param_s32_newf(HAL_RO,  &ip->iter,owner_id, "%s.iter", name))
	return -1;

    // unittest observer pins, per instance
    if (hal_pin_s32_newf(HAL_OUT, &ip->repeat_value, owner_id, "%s.repeat_value", name))
	return -1;
    if (hal_pin_s32_newf(HAL_OUT, &ip->prefix_len, owner_id, "%s.prefix_len", name))
	return -1;

    // export a thread function, passing the pointer to the instance's HAL memory blob
    if (hal_export_functf(funct, ip, 0, 0, owner_id, "%s.funct", name))
	return -1;
    return 0;
}
Example #3
0
static int export_delayline(int n)
{
    int retval, nr_of_samples, i;
    char *str_type;

    // determine the required size of the ringbuffer
    nr_of_samples = return_instance_samples(n);
    size_t sample_size = sizeof(sample_t) + (nr_of_samples * sizeof(hal_data_u));

    // add some headroom to be sure we dont overrun
    size_t rbsize = record_space(sample_size) * max_delay[n] * RB_HEADROOM;

    // create the delay queue
    if ((retval = hal_ring_newf(rbsize, sizeof(hal_delayline_t), ALLOC_HALMEM,
				"%s.samples", names[n])) < 0) {
	hal_print_msg(RTAPI_MSG_ERR,
		      "%s: failed to create new ring '%s.samples': %d\n",
		      cname, names[n], retval);
	return retval;
    }

    // use the per-using component ring access structure as the instance data,
    // which will also give us a handle on the scratchpad which we use for
    // HAL pins and other shared data
    if ((instance[n] = hal_malloc(sizeof(ringbuffer_t))) == NULL)
	return -1;
    if ((retval = hal_ring_attachf(instance[n], NULL, "%s.samples", names[n]))) {
	hal_print_msg(RTAPI_MSG_ERR,
		      "%s: attach to ring '%s.samples' failed: %d\n",
		      cname, names[n], retval);
	return -1;
    }

    // fill in instance data
    hal_delayline_t *hd = instance[n]->scratchpad;
    strncpy(hd->name, names[n], sizeof(hd->name));
    hd->nsamples = nr_of_samples;
    hd->sample_size = sample_size;
    hd->max_delay = max_delay[n];
    // set delay standard to value of zero
    hd->delay = 0;
    hd->output_ts = 0;
    hd->input_ts = hd->delay;

    // init pins, and at the same time fill the puntype array with
    // the type of pin[i] so we can later dereference proper
    char character;
    for (i = 0; i < hd->nsamples; i++) {
	character = samples[n][i];
	rtapi_print_msg(RTAPI_MSG_DBG, "\"samples=\" string = %s"
			" character %d = %c \n",
			samples[n], i, character);
	// determine type
	hal_type_t type = HAL_TYPE_UNSPECIFIED;
	switch (character) {
	case 'b':
	case 'B':
	    type = HAL_BIT;
	    break;
	case 'f':
	case 'F':
	    type = HAL_FLOAT;
	    break;
	case 's':
	    type = HAL_S32;
	    break;
	case 'u':
	    type = HAL_U32;
	    break;
	case 'S':
	    type = HAL_S64;
	    break;
	case 'U':
	    type = HAL_U64;
	    break;
	default:
	    hal_print_msg(RTAPI_MSG_ERR,
			  "%s: invalid type '%c' for pin %d\n",
			  cname, character, i);
	    return -EINVAL;
	}
	hd->pintype[i] = type;
	switch (type) {
	case HAL_BIT:
	    str_type = "bit";
	    break;
	case HAL_FLOAT:
	    str_type = "flt";
	    break;
	case HAL_U32:
	    str_type = "u32";
	    break;
	case HAL_S32:
	    str_type = "s32";
	    break;
	case HAL_S64:
	    str_type = "s64";
	    break;
	case HAL_U64:
	    str_type = "u64";
	    break;
	case HAL_TYPE_MAX:
	case HAL_TYPE_UNSPECIFIED:
	    // do nothing
	    break;
	}
	// create pins of type as requested
	if (((retval = hal_pin_newf(type,
				    HAL_IN,
				    (void **) &hd->pins_in[i],
				    comp_id,
				    "%s.in%d-%s",
				    hd->name, i, str_type)) < 0) ||
	    ((retval = hal_pin_newf(type,
				    HAL_OUT,
				    (void **) &hd->pins_out[i],
				    comp_id,
				    "%s.out%d-%s",
				    hd->name, i, str_type)) < 0)) {
	    return retval;
	}
	// post hal_pin_new(), pins are guaranteed to be set to zero
    }

    // create other pins
    if (((retval = hal_pin_bit_newf(HAL_IN, &(hd->enable), comp_id,
				    "%s.enable",  hd->name))) ||
	((retval = hal_pin_bit_newf(HAL_IN, &(hd->abort), comp_id,
				    "%s.abort",  hd->name))) ||
	((retval = hal_pin_u32_newf(HAL_IN, &(hd->pin_delay), comp_id,
				    "%s.delay", hd->name))) ||
	((retval = hal_pin_u32_newf(HAL_OUT, &(hd->write_fail), comp_id,
				    "%s.write-fail", hd->name))) ||
	((retval = hal_pin_u32_newf(HAL_OUT, &(hd->read_fail), comp_id,
				    "%s.too-old", hd->name))) ||
	((retval = hal_pin_u32_newf(HAL_OUT, &(hd->too_old), comp_id,
				    "%s.read-fail", hd->name))))
	return retval;

    // export thread functions
    if (((retval = hal_export_functf(write_sample_to_ring,
				    instance[n], 1, 0, comp_id,
				     "%s.sample", hd->name)) < 0) ||

	((retval = hal_export_functf(read_sample_from_ring,
				     instance[n], 1, 0, comp_id,
				     "%s.output", hd->name)) < 0)) {
	return retval;
    }
    return 0;
}
Example #4
0
int hal_export_funct(const char *name, void (*funct) (void *, long),
		     void *arg, int uses_fp, int reentrant, int owner_id)
{
    return hal_export_functf(funct, arg, uses_fp, reentrant, owner_id, name);
}