From: John K. <cv...@cv...> - 2007-01-15 00:52:32
|
Modified file emc2/src/hal/hal_lib.c Full file: <http://cvs.linuxcnc.org/cvs/emc2/src/hal/hal_lib.c?rev=1.51> Difference: <http://cvs.linuxcnc.org/cvs/emc2/src/hal/hal_lib.c.diff?r1=1.50;r2=1.51> Branch: HEAD Log: revision 1.51 date: 2007/01/15 00:52:22; author: jmkasunich; state: Exp; lines: +33 -9 track OUT and IO pins connected to a signal separately, and enforce consistent rules for connecting such pins to signals, also make link() properly handle links that already exist --- hal_lib.c 2006/11/18 03:04:56 1.50 +++ hal_lib.c 2007/01/15 00:52:22 1.51 @@ -15,9 +15,9 @@ * Copyright (c) 2003 All rights reserved. * * Last change: -# $Revision: 1.50 $ +# $Revision: 1.51 $ * $Author: jmkasunich $ -* $Date: 2006/11/18 03:04:56 $ +* $Date: 2007/01/15 00:52:22 $ ********************************************************************/ /** Copyright (C) 2003 John Kasunich @@ -736,6 +736,7 @@ new->type = type; new->readers = 0; new->writers = 0; + new->bidirs = 0; rtapi_snprintf(new->name, HAL_NAME_LEN, "%s", name); /* search list for 'name' and insert new structure */ prev = &(hal_data->sig_list_ptr); @@ -864,19 +865,34 @@ "HAL: ERROR: signal '%s' not found\n", sig_name); return HAL_INVAL; } - /* found both pin and signal, check types */ + /* found both pin and signal, are they already connected? */ + if (SHMPTR(pin->signal) == sig) { + rtapi_mutex_give(&(hal_data->mutex)); + rtapi_print_msg(RTAPI_MSG_WARN, + "HAL: Warning: pin '%s' already linked to '%s'\n", pin_name, sig_name); + return HAL_SUCCESS; + } + /* check types */ if (pin->type != sig->type) { rtapi_mutex_give(&(hal_data->mutex)); rtapi_print_msg(RTAPI_MSG_ERR, "HAL: ERROR: type mismatch '%s' <- '%s'\n", pin_name, sig_name); return HAL_INVAL; } - /* are we linking output pin to sig that already has writer? */ - if ((pin->dir == HAL_OUT) && (sig->writers > 0)) { + /* linking output pin to sig that already has output or I/O pins? */ + if ((pin->dir == HAL_OUT) && ((sig->writers > 0) || (sig->bidirs > 0 ))) { + /* yes, can't do that */ + rtapi_mutex_give(&(hal_data->mutex)); + rtapi_print_msg(RTAPI_MSG_ERR, + "HAL: ERROR: signal '%s' already has output or I/O pin(s)\n", sig_name); + return HAL_INVAL; + } + /* linking bidir pin to sig that already has output pin? */ + if ((pin->dir == HAL_IO) && (sig->writers > 0)) { /* yes, can't do that */ rtapi_mutex_give(&(hal_data->mutex)); rtapi_print_msg(RTAPI_MSG_ERR, - "HAL: ERROR: signal '%s' already has writer(s)\n", sig_name); + "HAL: ERROR: signal '%s' already has output pin\n", sig_name); return HAL_INVAL; } /* everything is OK, break any old link */ @@ -886,13 +902,16 @@ comp = SHMPTR(pin->owner_ptr); data_addr = comp->shmem_base + sig->data_ptr; *data_ptr_addr = data_addr; - /* update the signal's reader/writer counts */ + /* update the signal's reader/writer/bidir counts */ if ((pin->dir & HAL_IN) != 0) { sig->readers++; } - if ((pin->dir & HAL_OUT) != 0) { + if (pin->dir == HAL_OUT) { sig->writers++; } + if (pin->dir == HAL_IO) { + sig->bidirs++; + } /* and update the pin */ pin->signal = SHMOFF(sig); /* done, release the mutex and return */ @@ -2427,6 +2446,7 @@ p->type = 0; p->readers = 0; p->writers = 0; + p->bidirs = 0; p->name[0] = '\0'; } return p; @@ -2638,9 +2658,12 @@ if ((pin->dir & HAL_IN) != 0) { sig->readers--; } - if ((pin->dir & HAL_OUT) != 0) { + if (pin->dir == HAL_OUT) { sig->writers--; } + if (pin->dir == HAL_IO) { Modified file emc2/src/hal/hal_priv.h Full file: <http://cvs.linuxcnc.org/cvs/emc2/src/hal/hal_priv.h?rev=1.27> Difference: <http://cvs.linuxcnc.org/cvs/emc2/src/hal/hal_priv.h.diff?r1=1.26;r2=1.27> Branch: HEAD Log: revision 1.27 date: 2007/01/15 00:52:22; author: jmkasunich; state: Exp; lines: +7 -6 track OUT and IO pins connected to a signal separately, and enforce consistent rules for connecting such pins to signals, also make link() properly handle links that already exist --- hal_priv.h 2006/10/31 03:14:24 1.26 +++ hal_priv.h 2007/01/15 00:52:22 1.27 @@ -20,9 +20,9 @@ * Copyright (c) 2003 All rights reserved. * * Last change: -# $Revision: 1.26 $ -* $Author: jepler $ -* $Date: 2006/10/31 03:14:24 $ +# $Revision: 1.27 $ +* $Author: jmkasunich $ +* $Date: 2007/01/15 00:52:22 $ ********************************************************************/ @@ -215,8 +215,9 @@ int next_ptr; /* next signal in linked list */ int data_ptr; /* offset of signal value */ hal_type_t type; /* data type */ - int readers; /* number of read pins linked */ - int writers; /* number of write pins linked */ + int readers; /* number of input pins linked */ + int writers; /* number of output pins linked */ + int bidirs; /* number of I/O pins linked */ char name[HAL_NAME_LEN + 1]; /* signal name */ } hal_sig_t; @@ -305,7 +306,7 @@ */ #define HAL_KEY 0x48414C32 /* key used to open HAL shared memory */ -#define HAL_VER 0x00000006 /* version code */ +#define HAL_VER 0x00000007 /* version code */ #define HAL_SIZE 131000 /* These pointers are set by hal_init() to point to the shmem block |