use of net.sourceforge.usbdm.deviceEditor.information.MuxSelection in project usbdm-eclipse-plugins by podonoghue.
the class WriteFamilyCpp method writeMappedSignals.
/**
* Write declarations for simple peripheral signals (e.g. GPIO,ADC,PWM) that
* are mapped to pins e.g.
*
* <pre>
* using adc_p53 = const USBDM::Adc1<4>;
* using adc_p54 = const USBDM::Adc1<5>;
* </pre>
*
* @param writer
* Where to write
*
* @throws Exception
*/
private void writeMappedSignals(DocumentUtilities writer) throws IOException {
writeIncludes(writer);
writer.writeOpenNamespace(DeviceInfo.NAME_SPACE, "Namespace enclosing USBDM classes");
writer.openUsbdmDocumentationGroup();
DocumentationGroups startGroup = new DocumentationGroups(writer);
for (String key : fDeviceInfo.getPeripherals().keySet()) {
Peripheral peripheral = fDeviceInfo.getPeripherals().get(key);
for (Entry<String, Pin> pinEntry : fDeviceInfo.getPins().entrySet()) {
Pin pin = pinEntry.getValue();
Map<MuxSelection, MappingInfo> mappedSignals = pin.getMappableSignals();
if (mappedSignals == null) {
continue;
}
for (Entry<MuxSelection, MappingInfo> muxEntry : mappedSignals.entrySet()) {
if (muxEntry.getKey() == MuxSelection.unassigned) {
continue;
}
MappingInfo mappedSignal = muxEntry.getValue();
for (int fnIndex = 0; fnIndex < mappedSignal.getSignals().size(); fnIndex++) {
Signal function = mappedSignal.getSignals().get(fnIndex);
if (function.getPeripheral() == peripheral) {
String template = getMappedSignals(peripheral, mappedSignal, fnIndex);
if (template != null) {
startGroup.openGroup(peripheral);
writer.write(template);
writer.flush();
}
}
}
}
}
}
startGroup.closeGroup();
writer.writeDocBanner("Used to configure pin-mapping before 1st use of peripherals");
writer.write("extern void " + DO_PIN_MAPPING_FUNCTION + "();\n");
writer.closeDocumentationGroup();
writer.writeCloseNamespace();
writer.flush();
}
use of net.sourceforge.usbdm.deviceEditor.information.MuxSelection in project usbdm-eclipse-plugins by podonoghue.
the class WriteFamilyCpp method writeDocumentation.
/**
* Write pin mapping documentation
*
* @param writer
* Where to write
*
* @throws IOException
*/
private void writeDocumentation(DocumentUtilities writer) throws IOException {
Map<String, Pin> pinsByLocation = new TreeMap<String, Pin>(Signal.comparator);
Map<String, Pin> pinsByFunction = new TreeMap<String, Pin>(Signal.comparator);
writer.write(DOCUMENTATION_OPEN);
writer.write(String.format(TABLE_OPEN, "PinsByPinName", "Pins by Pin Name"));
for (String pinName : fDeviceInfo.getPins().keySet()) {
Pin pin = fDeviceInfo.getPins().get(pinName);
if (!pin.isAvailableInPackage()) {
// Discard pins without package location
continue;
}
String useDescription = pin.getPinUseDescription();
if (useDescription.isEmpty()) {
useDescription = "-";
}
Map<MuxSelection, MappingInfo> mappableSignals = pin.getMappableSignals();
MappingInfo mappedSignal = mappableSignals.get(pin.getMuxValue());
String signalList;
if (mappedSignal == null) {
signalList = "-";
} else {
signalList = mappedSignal.getSignalList();
}
writer.write(String.format(DOCUMENTATION_TEMPLATE, pin.getName(), signalList, pin.getLocation(), useDescription));
if ((pin.getLocation() != null) && !pin.getLocation().isEmpty()) {
pinsByLocation.put(pin.getLocation(), pin);
}
pinsByFunction.put(signalList, pin);
}
writer.write(TABLE_CLOSE);
writer.write(String.format(TABLE_OPEN, "PinsByLocation", "Pins by Location"));
for (String pinName : pinsByLocation.keySet()) {
Pin pin = pinsByLocation.get(pinName);
String useDescription = pin.getPinUseDescription();
if (useDescription.isEmpty()) {
useDescription = "-";
}
Map<MuxSelection, MappingInfo> mappableSignals = pin.getMappableSignals();
MappingInfo mappedSignal = mappableSignals.get(pin.getMuxValue());
String signalList;
if (mappedSignal == null) {
signalList = "-";
} else {
signalList = mappedSignal.getSignalList();
}
writer.write(String.format(DOCUMENTATION_TEMPLATE, pin.getName(), signalList, pin.getLocation(), useDescription));
}
writer.write(TABLE_CLOSE);
writer.write(String.format(TABLE_OPEN, "PinsByFunction", "Pins by Function"));
for (String pinName : pinsByFunction.keySet()) {
Pin pin = pinsByFunction.get(pinName);
String useDescription = pin.getPinUseDescription();
if (useDescription.isEmpty()) {
useDescription = "-";
}
Map<MuxSelection, MappingInfo> mappableSignals = pin.getMappableSignals();
MappingInfo mappedSignal = mappableSignals.get(pin.getMuxValue());
String signalList;
if (mappedSignal == null) {
signalList = "-";
} else {
signalList = mappedSignal.getSignalList();
}
writer.write(String.format(DOCUMENTATION_TEMPLATE, pin.getName(), signalList, pin.getLocation(), useDescription));
}
writer.write(TABLE_CLOSE);
writer.write(DOCUMENTATION_CLOSE);
writer.flush();
}
use of net.sourceforge.usbdm.deviceEditor.information.MuxSelection in project usbdm-eclipse-plugins by podonoghue.
the class FamilyXmlWriter method writePin.
/**
* Writes XML describing how peripheral signals are mapped to a pin
* e.g.<pre>
* <pin name=="PTD7">
* <mux sel="mux1" signal="GPIOD_7" />
* <mux sel="mux2" signal="CMT_IRO" />
* <reset sel="Disabled" />
* <default sel="mux1" />
* </pin>
* </pre>
*
* @param documentUtilities Where to write
* @param pin Pin to write definitions for
*
* @throws IOException
*/
private void writePin(XmlDocumentUtilities documentUtilities, Pin pin) throws IOException {
documentUtilities.openTag("pin");
Map<MuxSelection, MappingInfo> mappingInfo = pin.getMappableSignals();
Set<MuxSelection> sortedSelectionIndexes = mappingInfo.keySet();
boolean isFixed = false;
// Construct list of alternatives
StringBuffer alternativeHint = new StringBuffer();
for (MuxSelection selection : mappingInfo.keySet()) {
if (selection == MuxSelection.fixed) {
isFixed = true;
}
MappingInfo mInfo = mappingInfo.get(selection);
StringBuffer name = new StringBuffer();
name.append(mInfo.getSignalList());
if (alternativeHint.length() != 0) {
alternativeHint.append(", ");
}
alternativeHint.append(name);
}
documentUtilities.writeAttribute("name", pin.getName());
if (isFixed) {
documentUtilities.writeAttribute("isFixed", "true");
}
for (MuxSelection selection : sortedSelectionIndexes) {
MappingInfo mInfo = mappingInfo.get(selection);
StringBuffer name = new StringBuffer();
name.append(mInfo.getSignalList());
for (Signal fn : mInfo.getSignals()) {
documentUtilities.openTag("mux");
documentUtilities.writeAttribute("sel", selection.name());
documentUtilities.writeAttribute("signal", fn.getName());
documentUtilities.closeTag();
}
}
documentUtilities.openTag("reset");
documentUtilities.writeAttribute("sel", pin.getResetValue().name());
documentUtilities.closeTag();
// documentUtilities.openTag("default");
// documentUtilities.writeAttribute("sel", pin.getDefaultValue().name());
// documentUtilities.closeTag();
documentUtilities.closeTag();
}
use of net.sourceforge.usbdm.deviceEditor.information.MuxSelection in project usbdm-eclipse-plugins by podonoghue.
the class ParseFamilyCSV method parsePinLine.
/**
* Parse line containing Pin information
*
* @param line
* @throws Exception
*/
private void parsePinLine(String[] line) throws Exception {
StringBuffer sb = new StringBuffer();
if (!line[0].equals("Pin")) {
return;
}
String pinName = line[fPinIndex];
if ((pinName == null) || (pinName.isEmpty())) {
throw new Exception("No pin name");
}
pinName = fixSignalName(pinName);
// Use first name on pin as Pin name e.g. PTC4/LLWU_P8 => PTC4
Pattern p = Pattern.compile("(.+?)/.*");
Matcher m = p.matcher(pinName);
if (m.matches()) {
pinName = m.group(1);
}
final Pin pin = fDeviceInfo.createPin(pinName);
sb.append(String.format("%-10s => ", pin.getName()));
boolean pinIsMapped = false;
for (int col = fAltStartIndex; col <= fAltEndIndex; col++) {
if (col >= line.length) {
break;
}
ArrayList<Signal> signals = createSignalsFromString(line[col], true);
for (Signal signal : signals) {
sb.append(signal.getName() + ", ");
if ((signal != null)) {
MuxSelection muxValue = MuxSelection.valueOf(col - fAltStartIndex);
fDeviceInfo.createMapping(signal, pin, muxValue);
pinIsMapped = true;
}
}
}
if ((line.length > fResetIndex) && (line[fResetIndex] != null) && (!line[fResetIndex].isEmpty())) {
String resetName = line[fResetIndex];
ArrayList<Signal> resetSignals = createSignalsFromString(resetName, true);
if (!pinIsMapped) {
for (Signal resetSignal : resetSignals) {
sb.append("R:" + resetSignal.getName() + ", ");
// Pin is not mapped to this signal in the ALT columns - must be a non-mappable pin
MappingInfo mapping = fDeviceInfo.createMapping(resetSignal, pin, MuxSelection.fixed);
for (Signal signal : mapping.getSignals()) {
signal.setResetPin(mapping);
}
}
}
pin.setResetSignals(fDeviceInfo, resetName);
} else {
sb.append("R:" + Signal.DISABLED_SIGNAL.getName() + ", ");
fDeviceInfo.createMapping(Signal.DISABLED_SIGNAL, pin, MuxSelection.unassigned);
pin.setResetSignals(fDeviceInfo, Signal.DISABLED_SIGNAL.getName());
}
for (PackageColumnInfo pkgIndex : fPackageIndexes) {
String pinNum = line[pkgIndex.index];
if (pinNum.equals("*")) {
continue;
}
DevicePackage devicePackage = fDeviceInfo.findDevicePackage(pkgIndex.name);
if (devicePackage == null) {
throw new RuntimeException("Failed to find package " + pkgIndex.name + ", for " + pinName);
}
devicePackage.addPin(pin, pinNum);
sb.append("(" + pkgIndex.name + ":" + pinNum + ") ");
}
}
use of net.sourceforge.usbdm.deviceEditor.information.MuxSelection in project usbdm-eclipse-plugins by podonoghue.
the class ParseFamilyXML method parsePin.
/**
* Parse <pin>
*
* @param pinElement
* @throws Exception
*/
private void parsePin(Element pinElement) throws Exception {
Pin pin = fDeviceInfo.createPin(pinElement.getAttribute("name"));
for (Node node = pinElement.getFirstChild(); node != null; node = node.getNextSibling()) {
if (node.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Element element = (Element) node;
if (element.getTagName() == "mux") {
// factory.createMapping(factory.findSignal(element.getAttribute("signal")), pin, MuxSelection.valueOf(element.getAttribute("sel")));
Signal signal = fDeviceInfo.findOrCreateSignal(element.getAttribute("signal"));
MuxSelection muxSelection = MuxSelection.valueOf(element.getAttribute("sel"));
fDeviceInfo.createMapping(signal, pin, muxSelection);
if (signal.getName().startsWith("GPIO")) {
pin.setPort(signal);
}
} else if (element.getTagName() == "reset") {
MuxSelection muxSelection = MuxSelection.valueOf(element.getAttribute("sel"));
pin.setResetValue(muxSelection);
} else {
throw new Exception("Unexpected field in PIN, value = \'" + element.getTagName() + "\'");
}
}
}
Aggregations