Capsim Block Documentation
This star simulates an Ethernet local repeater
| Port | Type | Name | |
|---|---|---|---|
| 0 | float | inLeft | |
| 1 | float | cdLeft | |
| 2 | float | inRight | |
| 3 | float | cdRight |
| Port | Type | Name | |
|---|---|---|---|
| 0 | float | outLeft | |
| 1 | float | outRight |
| Num | Description | Type | Name | Default Value | |
|---|---|---|---|---|---|
| 0 | The width of a bit in samples | int | bitTime | 8 |
| Num | Type | Name | Initial Value | Description |
|---|---|---|---|---|
| 0 | int | direction | ||
| 1 | float | dataLeft | ||
| 2 | float | dataRight | ||
| 3 | float | collLeft | ||
| 4 | float | collRight | ||
| 5 | int | jamCount | ||
| 6 | int | bitCount | ||
| 7 | int | hiState |
int i; int numberSamples; double fabs(); |
|---|
direction = IDLE; dataLeft=0.0; dataRight = 0.0; collRight =0.0; collLeft = 0.0; jamCount = 0; bitCount = 0; hiState=0; |
|---|
for(numberSamples = MIN_AVAIL(); numberSamples > 0; -- numberSamples) {
IT_IN(0);
IT_IN(1);
IT_IN(2);
IT_IN(3);
if(IT_OUT(0)) {
KrnOverflow("repeater",0);
return(99);
}
if(IT_OUT(1)) {
KrnOverflow("repeater",1);
return(99);
}
dataLeft = (1.0-POLE)*dataLeft + POLE*fabs(inLeft(0));
dataRight = (1.0-POLE)*dataRight + POLE*fabs(inRight(0));
collLeft = (1.0-POLE)*collLeft + POLE*fabs(cdLeft(0));
collRight = (1.0-POLE)*collRight + POLE*fabs(cdRight(0));
switch(direction) {
case IDLE:
if(dataLeft > SQUELCH)
direction = LEFT_TO_RIGHT;
else if (dataRight > SQUELCH)
direction = RIGHT_TO_LEFT;
else if ((collLeft > SQUELCH) || (collRight > SQUELCH))
direction = COLL;
outLeft(0) = 0.0;
outRight(0) = 0.0;
break;
case LEFT_TO_RIGHT:
if (dataLeft <= SQUELCH) {
direction = IDLE;
outRight(0) =0.0;
} else {
/*
* Repeat data from left to right
*/
if ( inLeft(0) > 0.0 )
outRight(0) = PEAK;
else
outRight(0) = -1.0 * PEAK;
}
/*
* Squelch data from right to left
*/
outLeft(0) = 0.0;
if(( collLeft > SQUELCH ) || ( collRight > SQUELCH))
direction = COLL;
break;
case RIGHT_TO_LEFT:
if ( dataRight <= SQUELCH) {
direction=IDLE;
outLeft(0) = 0.0;
}
else {
/*
* Repeat data from right to left
*/
if( inRight(0) > 0.0 )
outLeft(0) = PEAK;
else
outLeft(0) = -1.0*PEAK;
}
/*
* Squelch data from left to right
*/
outRight(0) = 0.0;
if((collLeft > SQUELCH ) || ( collRight > SQUELCH))
direction= COLL;
break;
case COLL:
if (hiState) {
if( bitCount < bitTime) {
outLeft(0) = PEAK;
outRight(0) = PEAK;
}
else {
hiState = 0;
bitCount = 0;
outLeft(0) = -1.0*PEAK;
outRight(0) = -1.0*PEAK;
}
}
else {
if(bitCount < bitTime) {
outLeft(0) = -1.0 * PEAK;
outRight(0) = -1.0 * PEAK;
}
else {
hiState =1;
bitCount = 0;
outLeft(0) = PEAK;
outRight(0) = PEAK;
}
}
++bitCount;
if(( collLeft < SQUELCH) && (collRight < SQUELCH)) {
jamCount =0;
direction = JAM;
}
case JAM:
if(hiState) {
if (bitCount < bitTime ) {
outLeft(0) = PEAK;
outRight(0) = PEAK;
}
else {
hiState = 0;
bitCount = 0;
outLeft(0) = -1.0*PEAK;
outRight(0) = -1.0*PEAK;
}
}
else {
if( bitCount < bitTime) {
outLeft(0) = -1.0*PEAK;
outRight(0) = -1.0*PEAK;
}
else {
hiState = 1;
bitCount = 0;
outLeft(0) = PEAK;
outRight(0) = PEAK;
++jamCount;
}
}
++bitCount;
if((collLeft > SQUELCH ) || (collRight > SQUELCH)) {
jamCount = 0;
direction = COLL;
}
else if ( jamCount > JAM_LIMIT) {
direction = IDLE;
jamCount = 0;
}
break;
default:
fprintf(stderr,"Repeater in illegal state %i ",direction);
return(1);
break;
}
}
return(0);
|
|---|
/* Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
Copyright (C) 1989-2002 XCAD Corporation
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
http://capsimtmk.sourceforge.net
XCAD Corporation
Raleigh, North Carolina */
|
|---|
/*repeater.s*/ /* * Inputs: inLeft: The left input data signal * inRight: The right input data signal * cdLeft: The left collision signal * cdRight: The right collision signal * Outputs: outLeft: The left output data signal * outRight: The right output data signal * * Parameters: bitTime: The width of a bit in samples * * This star simulates an Ethernet local repeater * * Programmer: Prayson W. Pate * Date: September 28, 1987 * |
|---|