/***************************************************************************/ public static void elementWithCoverage( ILogicalElement _element , LogicValue.Enum _significantValue , LogicValue.Enum _valueToSet ) { ILineCollection inputs = _element.Inputs; ILineCollection outputs = _element.Outputs; if (inputs.hasUnknownStates()) { outputs[0].Value = LogicValue.Enum.Unknown; return; } if (inputs.hasValue(_significantValue)) { outputs[0].Value = _valueToSet; return; } if (!inputs.hasValue(LogicValue.Enum.DontCare)) { outputs[0].Value = LogicValue.invert(_valueToSet); } else { outputs[0].Value = LogicValue.Enum.DontCare; } }
/***************************************************************************/ public static void encoder(ILogicalElement _element) { ILineCollection inputs = _element.Inputs; ILineCollection outputs = _element.Outputs; if (inputs.hasValue(LogicValue.Enum.Unknown)) { outputs.setToAllLines(LogicValue.Enum.Unknown); return; } int enableIndex = inputs.Size - 1; if (inputs[enableIndex].Value == LogicValue.Enum.Low) { outputs.setToAllLines(LogicValue.Enum.Low); return; } if (inputs[enableIndex].Value == LogicValue.Enum.DontCare) { outputs.setToAllLines(LogicValue.Enum.DontCare); return; } int highValueIndex = -1; for (int i = enableIndex - 1; i >= 0; --i) { if (inputs[i].Value == LogicValue.Enum.High) { highValueIndex = i; break; } if (inputs[i].Value == LogicValue.Enum.DontCare) { outputs.setToAllLines(LogicValue.Enum.DontCare); return; } } if (highValueIndex == -1) { outputs.setToAllLines(LogicValue.Enum.DontCare); return; } int outputsCount = outputs.Size; LogicValuesNumbersConverter converter = new LogicValuesNumbersConverter(); LogicSet outputSet = converter.toLogicSet(highValueIndex, outputsCount); for (int i = 0; i < outputsCount; ++i) { outputs[i].Value = outputSet[i]; } }
/***************************************************************************/ public static void xor(ILogicalElement _element) { ILineCollection inputs = _element.Inputs; ILineCollection outputs = _element.Outputs; if (inputs.hasValue(LogicValue.Enum.Unknown)) { outputs[0].Value = LogicValue.Enum.Unknown; return; } if (inputs.hasValue(LogicValue.Enum.DontCare)) { outputs[0].Value = LogicValue.Enum.DontCare; return; } int numberOfHighValues = 0; int inputsCount = inputs.Size; for (int i = 0; i < inputs.Size; ++i) { if (inputs[i].Value == LogicValue.Enum.High) { ++numberOfHighValues; } } if (numberOfHighValues % 2 == 0) { outputs[0].Value = LogicValue.Enum.Low; } else { outputs[0].Value = LogicValue.Enum.High; } }
/***************************************************************************/ public static void dmx(ILogicalElement _element) { ILineCollection inputs = _element.Inputs; ILineCollection outputs = _element.Outputs; if (inputs.hasValue(LogicValue.Enum.Unknown)) { outputs.setToAllLines(LogicValue.Enum.Unknown); return; } outputs.setToAllLines(LogicValue.Enum.Low); int enableIndex = inputs.Size - 1; int informationInputIndex = enableIndex - 1; if (inputs[enableIndex].Value == LogicValue.Enum.Low) { return; } if (inputs[informationInputIndex].Value == LogicValue.Enum.Low) { return; } LogicValuesNumbersConverter converter = new LogicValuesNumbersConverter(); Numbers outputLineNumbers = converter.toNumbers(inputs, 0, informationInputIndex - 1); int outputLineNumbersCount = outputLineNumbers.Count; if (outputLineNumbersCount == 1) { outputs[outputLineNumbers[0]].Value = inputs[informationInputIndex].Value; } else { for (int i = 0; i < outputLineNumbersCount; ++i) { outputs[outputLineNumbers[i]].Value = LogicValue.Enum.DontCare; } } }
/***************************************************************************/ public static void mux(ILogicalElement _element) { ILineCollection inputs = _element.Inputs; int totalInputsCount = inputs.Size; int firstAddressPortIndex = totalInputsCount - _element.modifier; if (inputs.hasValue(LogicValue.Enum.Unknown)) { _element.Outputs[0].Value = LogicValue.Enum.Unknown; return; } LogicValuesNumbersConverter converter = new LogicValuesNumbersConverter(); Numbers inputLineNumbers = converter.toNumbers(inputs, firstAddressPortIndex, totalInputsCount - 1); int numbersCount = inputLineNumbers.Count; if (numbersCount < 1) { _element.Outputs[0].Value = LogicValue.Enum.Unknown; return; } LogicValue.Enum inputValue = inputs[inputLineNumbers[0]].Value; for (int i = 1; i < numbersCount; ++i) { if (inputValue != inputs[inputLineNumbers[i]].Value) { _element.Outputs[0].Value = LogicValue.Enum.DontCare; return; } } _element.Outputs[0].Value = inputValue; }