Ejemplo n.º 1
0
int hal_ccomp_report(hal_compiled_comp_t *cc,
		     comp_report_callback_t report_cb,
		     void *cb_data, int report_all)
{
    int retval, i;
    hal_data_u *data_ptr;
    hal_pin_t *pin;
    hal_sig_t *sig;

    if (!report_cb)
	return 0;
    if ((retval = report_cb(REPORT_BEGIN, cc, NULL, NULL, cb_data)) < 0)
	return retval;

    for (i = 0; i < cc->n_pins; i++) {
	if (report_all || RTAPI_BIT_TEST(cc->changed, i)) {
	    pin = cc->pin[i];
	    if (pin->signal != 0) {
		sig = SHMPTR(pin->signal);
		data_ptr = (hal_data_u *)SHMPTR(sig->data_ptr);
	    } else {
		data_ptr = (hal_data_u *)(hal_shmem_base + SHMOFF(&(pin->dummysig)));
	    }
	    if ((retval = report_cb(REPORT_PIN, cc, pin,
				    data_ptr, cb_data)) < 0)
		return retval;
	}
    }
    return report_cb(REPORT_END, cc, NULL, NULL, cb_data);
}
Ejemplo n.º 2
0
int hal_set_constructor(int comp_id, constructor make) {
    int next;
    hal_comp_t *comp  __attribute__((cleanup(halpr_autorelease_mutex)));

    rtapi_mutex_get(&(hal_data->mutex));

    /* search component list for 'comp_id' */
    next = hal_data->comp_list_ptr;
    if (next == 0) {
	/* list is empty - should never happen, but... */
	hal_print_msg(RTAPI_MSG_ERR,
	    "HAL: ERROR: component %d not found\n", comp_id);
	return -EINVAL;
    }

    comp = SHMPTR(next);
    while (comp->comp_id != comp_id) {
	/* not a match, try the next one */
	next = comp->next_ptr;
	if (next == 0) {
	    /* reached end of list without finding component */
	    hal_print_msg(RTAPI_MSG_ERR,
		"HAL: ERROR: component %d not found\n", comp_id);
	    return -EINVAL;
	}
	comp = SHMPTR(next);
    }
    comp->make = make;
    return 0;
}
Ejemplo n.º 3
0
static char *setp_generator(const char *text, int state) {
    static int len;
    static int next;
    static int what;
    if(!state) {
        what = 0;
        next = hal_data->param_list_ptr;
        len = strlen(text);
    }

    if(what == 0) {
        while(next) {
            hal_param_t *param = SHMPTR(next);
            next = param->next_ptr;
            if ( param->dir != HAL_RO && strncmp(text, param->name, len) == 0 )
                return strdup(param->name);
        }
        what = 1;
        next = hal_data->pin_list_ptr;
    }
    while(next) {
        hal_pin_t *pin = SHMPTR(next);
        next = pin->next_ptr;
        if ( pin->dir != HAL_OUT && pin->signal == 0 && 
                 strncmp(text, pin->name, len) == 0 )
            return strdup(pin->name);
    }

    return NULL;
}
Ejemplo n.º 4
0
int hal_ready(int comp_id) {
    int next;
    hal_comp_t *comp  __attribute__((cleanup(halpr_autorelease_mutex)));

    rtapi_mutex_get(&(hal_data->mutex));

    /* search component list for 'comp_id' */
    next = hal_data->comp_list_ptr;
    if (next == 0) {
	/* list is empty - should never happen, but... */
	HALERR("BUG: no components defined - %d", comp_id);
	return -EINVAL;
    }

    comp = SHMPTR(next);
    while (comp->comp_id != comp_id) {
	/* not a match, try the next one */
	next = comp->next_ptr;
	if (next == 0) {
	    /* reached end of list without finding component */
	    HALERR("component %d not found", comp_id);
	    return -EINVAL;
	}
	comp = SHMPTR(next);
    }
    if(comp->state > COMP_INITIALIZING) {
	HALERR("component '%s' id %d already ready (state %d)",
	       comp->name, comp->comp_id, comp->state);
        return -EINVAL;
    }
    comp->state = (comp->type == TYPE_REMOTE ?  COMP_UNBOUND : COMP_READY);
    return 0;
}
Ejemplo n.º 5
0
void free_funct_struct(hal_funct_t * funct)
{
    int next_thread;
    hal_thread_t *thread;
    hal_list_t *list_root, *list_entry;
    hal_funct_entry_t *funct_entry;

    if (funct->users > 0) {
	/* We can't casually delete the function, there are thread(s) which
	   will call it.  So we must check all the threads and remove any
	   funct_entrys that call this function */
	/* start at root of thread list */
	next_thread = hal_data->thread_list_ptr;
	/* run through thread list */
	while (next_thread != 0) {
	    /* point to thread */
	    thread = SHMPTR(next_thread);
	    /* start at root of funct_entry list */
	    list_root = &(thread->funct_list);
	    list_entry = list_next(list_root);
	    /* run thru funct_entry list */
	    while (list_entry != list_root) {
		/* point to funct entry */
		funct_entry = (hal_funct_entry_t *) list_entry;
		/* test it */
		if (SHMPTR(funct_entry->funct_ptr) == funct) {
		    /* this funct entry points to our funct, unlink */
		    list_entry = list_remove_entry(list_entry);
		    /* and delete it */
		    free_funct_entry_struct(funct_entry);
		} else {
		    /* no match, try the next one */
		    list_entry = list_next(list_entry);
		}
	    }
	    /* move on to the next thread */
	    next_thread = thread->next_ptr;
	}
    }
    /* clear contents of struct */
    funct->uses_fp = 0;
    funct->owner_id = 0;
    funct->reentrant = 0;
    funct->users = 0;
    funct->arg = 0;
    funct->funct.l = 0;
    funct->runtime = 0;
    funct->name[0] = '\0';

    /* add it to free list */
    funct->next_ptr = hal_data->funct_free_ptr;
    hal_data->funct_free_ptr = SHMOFF(funct);
}
Ejemplo n.º 6
0
hal_funct_t *alloc_funct_struct(void)
{
    hal_funct_t *p;

    /* check the free list */
    if (hal_data->funct_free_ptr != 0) {
	/* found a free structure, point to it */
	p = SHMPTR(hal_data->funct_free_ptr);
	/* unlink it from the free list */
	hal_data->funct_free_ptr = p->next_ptr;
	p->next_ptr = 0;
    } else {
	/* nothing on free list, allocate a brand new one */
	p = shmalloc_dn(sizeof(hal_funct_t));
    }
    if (p) {
	/* make sure it's empty */
	p->next_ptr = 0;
	p->uses_fp = 0;
	p->owner_id = 0;
	p->reentrant = 0;
	p->users = 0;
	p->arg = 0;
	p->funct.l = 0;
	p->name[0] = '\0';
    }
    return p;
}
Ejemplo n.º 7
0
void *shmalloc_rt(size_t size)
{
    long int tmp_top;
    void *retval;

    /* tentatively allocate memory */
    tmp_top = hal_data->shmem_top - size;
    /* deal with alignment requirements */
    if (size >= 8) {
	/* align on 8 byte boundary */
	tmp_top &= (~7);
    } else if (size >= 4) {
	/* align on 4 byte boundary */
	tmp_top &= (~3);
    } else if (size == 2) {
	/* align on 2 byte boundary */
	tmp_top &= (~1);
    }
    /* is there enough memory available? */
    if (tmp_top < hal_data->shmem_bot) {
	/* no */
	HALFAIL_NULL(ENOMEM, "giving up - can't allocate %zu bytes", size);
    }
    size_t waste = hal_data->shmem_top - tmp_top - size;
    hal_data->rt_alignment_loss += waste;

    /* memory is available, allocate it */
    retval = SHMPTR(tmp_top);
    hal_data->shmem_top = tmp_top;
    return retval;
}
Ejemplo n.º 8
0
hal_comp_t *halpr_alloc_comp_struct(void)
{
    hal_comp_t *p;

    /* check the free list */
    if (hal_data->comp_free_ptr != 0) {
	/* found a free structure, point to it */
	p = SHMPTR(hal_data->comp_free_ptr);
	/* unlink it from the free list */
	hal_data->comp_free_ptr = p->next_ptr;
	p->next_ptr = 0;
    } else {
	/* nothing on free list, allocate a brand new one */
	p = shmalloc_dn(sizeof(hal_comp_t));
    }
    if (p) {
	/* make sure it's empty */
	p->next_ptr = 0;
	p->comp_id = 0;
	p->type = TYPE_INVALID;
	p->state = COMP_INVALID;
	p->shmem_base = 0;
	p->name[0] = '\0';
    }
    return p;
}
Ejemplo n.º 9
0
int hal_del_funct_from_thread(const char *funct_name, const char *thread_name)
{
    hal_funct_t *funct;
    hal_list_t *list_root, *list_entry;
    hal_funct_entry_t *funct_entry;

    CHECK_HALDATA();
    CHECK_LOCK(HAL_LOCK_CONFIG);
    CHECK_STR(funct_name);
    CHECK_STR(thread_name);

    HALDBG("removing function '%s' from thread '%s'", funct_name, thread_name);
    {
	hal_thread_t *thread __attribute__((cleanup(halpr_autorelease_mutex)));

	/* get mutex before accessing data structures */
	rtapi_mutex_get(&(hal_data->mutex));

	/* search function list for the function */
	funct = halpr_find_funct_by_name(funct_name);
	if (funct == 0) {
	    HALERR("function '%s' not found", funct_name);
	    return -EINVAL;
	}
	/* found the function, is it in use? */
	if (funct->users == 0) {
	    HALERR("function '%s' is not in use", funct_name);
	    return -EINVAL;
	}
	/* search thread list for thread_name */
	thread = halpr_find_thread_by_name(thread_name);
	if (thread == 0) {
	    /* thread not found */
	    HALERR("thread '%s' not found", thread_name);
	    return -EINVAL;
	}
	/* ok, we have thread and function, does thread use funct? */
	list_root = &(thread->funct_list);
	list_entry = list_next(list_root);
	while (1) {
	    if (list_entry == list_root) {
		/* reached end of list, funct not found */
		HALERR("thread '%s' doesn't use %s",
		       thread_name, funct_name);
		return -EINVAL;
	    }
	    funct_entry = (hal_funct_entry_t *) list_entry;
	    if (SHMPTR(funct_entry->funct_ptr) == funct) {
		/* this funct entry points to our funct, unlink */
		list_remove_entry(list_entry);
		/* and delete it */
		free_funct_entry_struct(funct_entry);
		/* done */
		return 0;
	    }
	    /* try next one */
	    list_entry = list_next(list_entry);
	}
    }
}
Ejemplo n.º 10
0
// iterate over insts owned by a particular comp.
// if comp_id < 0, return ALL instances, regardless which comp owns them.
hal_inst_t *halpr_find_inst_by_owning_comp(const int comp_id, hal_inst_t *start)
{
    int next;
    hal_inst_t *inst;

    /* is this the first call? */
    if (start == 0) {
	/* yes, start at beginning of inst list */
	next = hal_data->inst_list_ptr;
    } else {
	/* no, start at next inst */
	next = start->next_ptr;
    }
    while (next != 0) {
	inst = SHMPTR(next);
	if (comp_id < 0) // all insts
	    return inst;
	if (inst->comp_id == comp_id) {
	    return inst;
	}
	/* didn't find it yet, look at next one */
	next = inst->next_ptr;
    }
    /* if loop terminates, we reached end of list without finding a match */
    return 0;
}
Ejemplo n.º 11
0
/** The 'halpr_find_funct_by_instance_id()' function find functs owned by a specific
    instance id.  If 'start' is NULL, they start at the beginning of the
    appropriate list, and return the first item owned by 'instance'.
    Otherwise they assume that 'start' is the value returned by a prior
    call, and return the next matching item.  If no match is found, they
    return NULL.
*/
hal_funct_t *halpr_find_funct_by_instance_id(const int inst_id,
					     const hal_funct_t * start)
{
    int next;
    hal_funct_t *funct;

     /* is this the first call? */
    if (start == 0) {
	/* yes, start at beginning of funct list */
	next = hal_data->funct_list_ptr;
    } else {
	/* no, start at next funct */
	next = start->next_ptr;
    }
    while (next != 0) {
	funct = SHMPTR(next);
	if (funct->owner_id == inst_id) {
	    /* found a match */
	    return funct;
	}
	/* didn't find it yet, look at next one */
	next = funct->next_ptr;
    }
    /* if loop terminates, we reached end of list without finding a match */
    return 0;
}
Ejemplo n.º 12
0
static hal_inst_t *alloc_inst_struct(void)
{
    hal_inst_t *hi;

    /* check the free list */
    if (hal_data->inst_free_ptr != 0) {
	/* found a free structure, point to it */
	hi = SHMPTR(hal_data->inst_free_ptr);
	/* unlink it from the free list */
	hal_data->inst_free_ptr = hi->next_ptr;
	hi->next_ptr = 0;
    } else {
	/* nothing on free list, allocate a brand new one */
	hi = shmalloc_dn(sizeof(hal_inst_t));
    }
    if (hi) {
	/* make sure it's empty */
	hi->next_ptr = 0;
	hi->comp_id = 0;
	hi->inst_id = 0;
	hi->inst_data_ptr = 0;
	hi->inst_size = 0;
	hi->name[0] = '\0';
    }
    return hi;
}
Ejemplo n.º 13
0
void *shmalloc_up(long int size)
{
    long int tmp_bot;
    void *retval;

    /* deal with alignment requirements */
    tmp_bot = hal_data->shmem_bot;
    if (size >= 8) {
        /* align on 8 byte boundary */
        tmp_bot = (tmp_bot + 7) & (~7);
    } else if (size >= 4) {
        /* align on 4 byte boundary */
        tmp_bot = (tmp_bot + 3) & (~3);
    } else if (size == 2) {
        /* align on 2 byte boundary */
        tmp_bot = (tmp_bot + 1) & (~1);
    }
    /* is there enough memory available? */
    if ((hal_data->shmem_top - tmp_bot) < size) {
        /* no */
        return 0;
    }
    /* memory is available, allocate it */
    retval = SHMPTR(tmp_bot);
    hal_data->shmem_bot = tmp_bot + size;
    hal_data->shmem_avail = hal_data->shmem_top - hal_data->shmem_bot;
    return retval;
}
Ejemplo n.º 14
0
void *shmalloc_dn(long int size)
{
    long int tmp_top;
    void *retval;

    /* tentatively allocate memory */
    tmp_top = hal_data->shmem_top - size;
    /* deal with alignment requirements */
    if (size >= 8) {
        /* align on 8 byte boundary */
        tmp_top &= (~7);
    } else if (size >= 4) {
        /* align on 4 byte boundary */
        tmp_top &= (~3);
    } else if (size == 2) {
        /* align on 2 byte boundary */
        tmp_top &= (~1);
    }
    /* is there enough memory available? */
    if (tmp_top < hal_data->shmem_bot) {
        /* no */
        return 0;
    }
    /* memory is available, allocate it */
    retval = SHMPTR(tmp_top);
    hal_data->shmem_top = tmp_top;
    hal_data->shmem_avail = hal_data->shmem_top - hal_data->shmem_bot;
    return retval;
}
Ejemplo n.º 15
0
/** The 'halpr_find_param_by_instance_id()' function find params owned by a specific
    instance.  If 'start' is NULL, they start at the beginning of the
    appropriate list, and return the first item owned by 'instance'.
    Otherwise they assume that 'start' is the value returned by a prior
    call, and return the next matching item.  If no match is found, they
    return NULL.
*/
hal_param_t *halpr_find_param_by_instance_id(const int inst_id,
					     const hal_param_t *start)
{
    int next;
    hal_param_t *param;

    /* is this the first call? */
    if (start == 0) {
	/* yes, start at beginning of param list */
	next = hal_data->param_list_ptr;
    } else {
	/* no, start at next param */
	next = start->next_ptr;
    }
    while (next != 0) {
	param = SHMPTR(next);
	if (param->owner_id == inst_id) {
	    /* found a match */
	    return param;
	}
	/* didn't find it yet, look at next one */
	next = param->next_ptr;
    }
    /* if loop terminates, we reached end of list without finding a match */
    return 0;
}
Ejemplo n.º 16
0
static char *pin_generator(const char *text, int state) {
    static int len;
    static int next;
    static int aliased;
    char *name;

    if(!state) {
        next = hal_data->pin_list_ptr;
        len = strlen(text);
        aliased = 0;
    }

    while(next) {
        hal_pin_t *pin = SHMPTR(next);
        switch (aliased) {
            case 0: // alias (if any) has not been output
                if (pin->oldname != 0) {
                    // there's an alias, so use that and do not update the pin pointer
                    hal_oldname_t *oldname = SHMPTR(pin->oldname);
                    name = oldname->name;
                    aliased = 1;
                } else {
                    // no alias, so use the name and update the pin pointer
                    name = pin->name;
                    next = pin->next_ptr;
                }
            break;
            case 1:  // there is an alias, and it has been processed already
                name = pin->name;
                next = pin->next_ptr;
                aliased = 0;
            break;
            default:
                // shouldn't be able to get here, so assume we're done
                rl_attempted_completion_over = 1;
                return NULL;
            break;
        }
        if ( !writer_match( pin->dir, match_writers ) ) continue;
        if ( !direction_match( pin->dir, match_direction ) ) continue;
        if ( match_type != HAL_TYPE_UNSPECIFIED && match_type != pin->type ) continue; 
	if ( strncmp(text, name, len) == 0 )
            return strdup(name);
    }
    rl_attempted_completion_over = 1;
    return NULL;
}
Ejemplo n.º 17
0
static void check_match_type_pin(const char *name) {
    int next = hal_data->pin_list_ptr;
    int sz = strcspn(name, " \t");

    while(next) {
        hal_pin_t *pin = SHMPTR(next);
        next = pin->next_ptr;
	if ( sz == strlen(pin->name) && strncmp(name, pin->name, sz) == 0 ) {
            match_type = pin->type;
            match_direction = pin->dir;
            return;
        }
    }
}
Ejemplo n.º 18
0
static void check_match_type_signal(const char *name) {
    int next = hal_data->sig_list_ptr;
    int sz = strcspn(name, " \t");

    while(next) {
        hal_sig_t *sig = SHMPTR(next);
        next = sig->next_ptr;
	if ( sz == strlen(sig->name) && strncmp(name, sig->name, sz) == 0 ) {
            match_type = sig->type;
            match_writers = sig->writers;
            return;
        }
    }
}
Ejemplo n.º 19
0
// lookup instance by instance ID
hal_inst_t *halpr_find_inst_by_id(const int id)
{
    int next;
    hal_inst_t *inst;

    next = hal_data->inst_list_ptr;
    while (next != 0) {
	inst = SHMPTR(next);
	if (inst->inst_id == id) {
	    return inst;
	}
	next = inst->next_ptr;
    }
    return 0;
}
Ejemplo n.º 20
0
static char *thread_generator(const char *text, int state) { 
    static int len;
    static int next;
    if(!state) {
        next = hal_data->thread_list_ptr;
        len = strlen(text);
    }

    while(next) {
        hal_thread_t *thread = SHMPTR(next);
        next = thread->next_ptr;
	if ( strncmp(text, thread->name, len) == 0 )
            return strdup(thread->name);
    }
    return NULL;
}
Ejemplo n.º 21
0
void free_funct_entry_struct(hal_funct_entry_t * funct_entry)
{
    hal_funct_t *funct;

    if (funct_entry->funct_ptr > 0) {
	/* entry points to a function, update the function struct */
	funct = SHMPTR(funct_entry->funct_ptr);
	funct->users--;
    }
    /* clear contents of struct */
    funct_entry->funct_ptr = 0;
    funct_entry->arg = 0;
    funct_entry->funct.l = 0;
    /* add it to free list */
    list_add_after((hal_list_t *) funct_entry, &(hal_data->funct_entry_free));
}
Ejemplo n.º 22
0
static hal_ring_t *alloc_ring_struct(void)
{
    hal_ring_t *p;

    /* check the free list */
    if (hal_data->ring_free_ptr != 0) {
	/* found a free structure, point to it */
	p = SHMPTR(hal_data->ring_free_ptr);
	/* unlink it from the free list */
	hal_data->ring_free_ptr = p->next_ptr;
	p->next_ptr = 0;
    } else {
	/* nothing on free list, allocate a brand new one */
	p = shmalloc_dn(sizeof(hal_ring_t));
    }
    return p;
}
Ejemplo n.º 23
0
static char *funct_generator_common(const char *text, int state, int inuse) { 
    static int len;
    static int next;
    if(!state) {
        next = hal_data->funct_list_ptr;
        len = strlen(text);
    }

    while(next) {
        hal_funct_t *funct = SHMPTR(next);
        next = funct->next_ptr;
	if (( strncmp(text, funct->name, len) == 0 ) 
            && (inuse == funct->users))
            return strdup(funct->name);
    }
    return NULL;
}
Ejemplo n.º 24
0
static char *group_generator(const char *text, int state) {
    static int len;
    static int next;

    if(!state) {
        next = hal_data->group_list_ptr;
        len = strlen(text);
    }

    while(next) {
        hal_group_t *group = SHMPTR(next);
        next = group->next_ptr;
        if ( strncmp(text, group->name, len) == 0 )
            return strdup(group->name);
    }
    return NULL;
}
Ejemplo n.º 25
0
static char *ring_generator(const char *text, int state) {
    static int len;
    static int next;

    if(!state) {
        next = hal_data->ring_list_ptr;
        len = strlen(text);
    }

    while(next) {
        hal_ring_t *ring = SHMPTR(next);
        next = ring->next_ptr;
        if ( strncmp(text, ring->name, len) == 0 )
            return strdup(ring->name);
    }
    return NULL;
}
Ejemplo n.º 26
0
static char *signal_generator(const char *text, int state) {
    static int len;
    static int next;
    if(!state) {
        next = hal_data->sig_list_ptr;
        len = strlen(text);
    }

    while(next) {
        hal_sig_t *sig = SHMPTR(next);
        next = sig->next_ptr;
        if ( match_type != HAL_TYPE_UNSPECIFIED && match_type != sig->type ) continue; 
        if ( !writer_match( match_direction, sig->writers ) ) continue;
	if ( strncmp(text, sig->name, len) == 0 )
            return strdup(sig->name);
    }
    return NULL;
}
Ejemplo n.º 27
0
static char *pin_alias_generator(const char *text, int state) {
    static int len;
    static int next;

    if(!state) {
        next = hal_data->pin_list_ptr;
        len = strlen(text);
    }

    while(next) {
        hal_pin_t *pin = SHMPTR(next);
        next = pin->next_ptr;
        if (pin->oldname==0) continue;  // no alias here, move along
        if ( strncmp(text, pin->name, len) == 0 )
            return strdup(pin->name);
    }
    return NULL;
}
Ejemplo n.º 28
0
static char *comp_generator(const char *text, int state) {
    static int len;
    static int next;
    if(!state) {
        next = hal_data->comp_list_ptr;
        len = strlen(text);
        if(strncmp(text, "all", len) == 0)
            return strdup("all");
    }

    while(next) {
        hal_comp_t *comp = SHMPTR(next);
        next = comp->next_ptr;
	if ( strncmp(text, comp->name, len) == 0 )
            return strdup(comp->name);
    }
    rl_attempted_completion_over = 1;
    return NULL;
}
Ejemplo n.º 29
0
hal_comp_t *halpr_find_comp_by_id(int id)
{
    int next;
    hal_comp_t *comp;

    /* search list for 'comp_id' */
    next = hal_data->comp_list_ptr;
    while (next != 0) {
	comp = SHMPTR(next);
	if (comp->comp_id == id) {
	    /* found a match */
	    return comp;
	}
	/* didn't find it yet, look at next one */
	next = comp->next_ptr;
    }
    /* if loop terminates, we reached end of list without finding a match */
    return 0;
}
Ejemplo n.º 30
0
hal_comp_t *halpr_find_comp_by_name(const char *name)
{
    int next;
    hal_comp_t *comp;

    /* search component list for 'name' */
    next = hal_data->comp_list_ptr;
    while (next != 0) {
	comp = SHMPTR(next);
	if (strcmp(comp->name, name) == 0) {
	    /* found a match */
	    return comp;
	}
	/* didn't find it yet, look at next one */
	next = comp->next_ptr;
    }
    /* if loop terminates, we reached end of list with no match */
    return 0;
}