Search in sources :

Example 6 with Peripheral

use of net.sourceforge.usbdm.deviceEditor.information.Peripheral in project usbdm-eclipse-plugins by podonoghue.

the class ParseFamilyCSV method parseFile.

/**
 * Process file
 *
 * @param filePath   File to process
 *
 * @return Class containing information from file
 *
 * @throws IOException
 */
public void parseFile(Path filePath) throws Exception {
    // Open source file
    BufferedReader sourceFile = Files.newBufferedReader(filePath, StandardCharsets.UTF_8);
    parsePreliminaryInformation(sourceFile);
    sourceFile.close();
    fDeviceInfo.initialiseTemplates();
    // Re-open source file
    sourceFile = Files.newBufferedReader(filePath, StandardCharsets.UTF_8);
    parseFile(sourceFile);
    sourceFile.close();
    // Information from device database
    final DevicePeripherals fDevicePeripherals = fDeviceInfo.getDevicePeripherals();
    // Create map to allow peripheral lookup
    final Map<String, net.sourceforge.usbdm.peripheralDatabase.Peripheral> fPeripheralMap = createPeripheralsMap(fDevicePeripherals);
    // Attach information from device database
    for (Entry<String, Peripheral> entry : fDeviceInfo.getPeripherals().entrySet()) {
        Peripheral peripheral = entry.getValue();
        // Get database peripheral entry
        net.sourceforge.usbdm.peripheralDatabase.Peripheral dbPeripheral = fPeripheralMap.get(entry.getKey());
        if ((dbPeripheral == null)) {
            if (!peripheral.isSynthetic()) {
                throw new UsbdmException("Peripheral " + entry.getKey() + " not found");
            }
            continue;
        }
        // Get peripheral version
        peripheral.setVersion(dbPeripheral.getBasePeripheral().getSourceFilename().toLowerCase());
        // Attach DMAMUX information from database
        String[] dmaMuxInputs = dbPeripheral.getDmaMuxInputs();
        if (dmaMuxInputs != null) {
            if ((dmaMuxInputs.length != 64) && (dmaMuxInputs.length != 128)) {
                throw new UsbdmException("Illegal dma table size");
            }
            int slotNum = 0;
            for (String dmaMuxInput : dmaMuxInputs) {
                if (!dmaMuxInput.startsWith("Reserved")) {
                    fDeviceInfo.createDmaInfo("0", slotNum, dmaMuxInput);
                }
                slotNum++;
            }
        }
        // Attach interrupt information
        final Pattern p = Pattern.compile("^GPIO([A-Z]).*$");
        Matcher m = p.matcher(entry.getKey());
        if (m.matches()) {
            dbPeripheral = fPeripheralMap.get(m.replaceAll("PORT$1"));
        }
        if (dbPeripheral == null) {
            throw new UsbdmException("Peripheral " + m.replaceAll("PORT$1") + " not found");
        }
        ArrayList<InterruptEntry> interruptEntries = dbPeripheral.getInterruptEntries();
        if (interruptEntries != null) {
            for (InterruptEntry interruptEntry : interruptEntries) {
                peripheral.addIrqNum(interruptEntry.getName() + "_IRQn");
            }
        }
    }
    fDeviceInfo.consistencyCheck();
}
Also used : Pattern(java.util.regex.Pattern) DevicePeripherals(net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals) Matcher(java.util.regex.Matcher) InterruptEntry(net.sourceforge.usbdm.peripheralDatabase.InterruptEntry) Peripheral(net.sourceforge.usbdm.deviceEditor.information.Peripheral) BufferedReader(java.io.BufferedReader) UsbdmException(net.sourceforge.usbdm.jni.UsbdmException)

Example 7 with Peripheral

use of net.sourceforge.usbdm.deviceEditor.information.Peripheral in project usbdm-eclipse-plugins by podonoghue.

the class ParseFamilyCSV method parsePeripheralInfoLine.

/**
 * Parse line containing Peripheral information
 *
 * @param line
 */
private void parsePeripheralInfoLine(String[] line) {
    if (!line[0].equals("Peripheral")) {
        return;
    }
    if (line.length < 2) {
        throw new RuntimeException("Illegal Peripheral Mapping line");
    }
    String peripheralName = line[PERIPHERAL_NAME_COL];
    Peripheral peripheral = fDeviceInfo.findOrCreatePeripheral(peripheralName);
    if (peripheral == null) {
        throw new RuntimeException("Unable to find peripheral " + peripheralName);
    }
    if (line.length < 3) {
        // No parameters
        return;
    }
    String peripheralClockReg = line[CLOCK_REG_COL];
    String peripheralClockMask = null;
    if (line.length > CLOCK_MASK_COL) {
        peripheralClockMask = line[CLOCK_MASK_COL];
    }
    if ((peripheralClockMask == null) || (peripheralClockMask.isEmpty())) {
        peripheralClockMask = peripheralClockReg.replace("->", "_") + "_" + peripheralName + "_MASK";
    }
    if ((peripheralClockReg != null) && !peripheralClockReg.isEmpty()) {
        Pattern pattern = Pattern.compile("SIM->(SCGC\\d?)");
        Matcher matcher = pattern.matcher(peripheralClockReg);
        if (!matcher.matches()) {
            throw new RuntimeException("Unexpected Peripheral Clock Register " + peripheralClockReg + " for " + peripheralName);
        }
        peripheralClockReg = matcher.group(1);
        if (!peripheralClockMask.contains(peripheralClockReg)) {
            throw new RuntimeException("Clock Mask " + peripheralClockMask + " doesn't match Clock Register " + peripheralClockReg);
        }
        peripheral.setClockInfo(peripheralClockReg, peripheralClockMask);
    }
}
Also used : Pattern(java.util.regex.Pattern) Peripheral(net.sourceforge.usbdm.deviceEditor.information.Peripheral) Matcher(java.util.regex.Matcher)

Example 8 with Peripheral

use of net.sourceforge.usbdm.deviceEditor.information.Peripheral in project usbdm-eclipse-plugins by podonoghue.

the class WriteFamilyCpp method writePeripheralInformationClasses.

/**
 * Write all Peripheral Information Classes<br>
 *
 * <pre>
 *  class Adc0Info {
 *   ...
 *  };
 *  class Adc1Info {
 *   ...
 *  };
 * </pre>
 *
 * @param writer
 *           Where to write
 *
 * @throws IOException
 */
private void writePeripheralInformationClasses(DocumentUtilities writer) throws IOException {
    writer.writeOpenNamespace(DeviceInfo.NAME_SPACE, "Namespace enclosing USBDM classes");
    writer.openUsbdmDocumentationGroup();
    writePortInfo(writer);
    writer.write("/** Class to static check signal mapping is valid */\n" + "template<class Info, int signalNum> class CheckSignal {\n" + "#ifdef DEBUG_BUILD\n" + "   static_assert((signalNum<Info::numSignals), \"Non-existent signal - Modify Configure.usbdm\");\n" + "   static_assert((signalNum>=Info::numSignals)||(Info::info[signalNum].gpioBit != UNMAPPED_PCR), \"Signal is not mapped to a pin - Modify Configure.usbdm\");\n" + "   static_assert((signalNum>=Info::numSignals)||(Info::info[signalNum].gpioBit != INVALID_PCR),  \"Signal doesn't exist in this device/package\");\n" + "   static_assert((signalNum>=Info::numSignals)||((Info::info[signalNum].gpioBit == UNMAPPED_PCR)||(Info::info[signalNum].gpioBit == INVALID_PCR)||(Info::info[signalNum].gpioBit >= 0)), \"Illegal signal\");\n" + "#endif\n" + "};\n\n");
    fDeviceInfo.writeNamespaceInfo(writer);
    writer.writeBanner("Peripheral Information Classes");
    DocumentationGroups groups = new DocumentationGroups(writer);
    // Write these classes in order as they declare shared information etc.
    ArrayList<String> priorityClasses = new ArrayList<String>();
    priorityClasses.add("OSC");
    priorityClasses.add("OSC0");
    priorityClasses.add("OSC_RF0");
    priorityClasses.add("RTC");
    priorityClasses.add("MCG");
    priorityClasses.add("SIM");
    for (String key : priorityClasses) {
        Peripheral peripheral = fDeviceInfo.getPeripherals().get(key);
        if (peripheral != null) {
            writePeripheralInformationClass(writer, groups, peripheral);
        }
    }
    for (String key : fDeviceInfo.getPeripherals().keySet()) {
        if (priorityClasses.contains(key)) {
            continue;
        }
        writePeripheralInformationClass(writer, groups, fDeviceInfo.getPeripherals().get(key));
    }
    groups.closeGroup();
    writer.closeDocumentationGroup();
    writer.writeCloseNamespace();
    writer.write("\n");
    writer.flush();
}
Also used : Peripheral(net.sourceforge.usbdm.deviceEditor.information.Peripheral) ArrayList(java.util.ArrayList)

Example 9 with Peripheral

use of net.sourceforge.usbdm.deviceEditor.information.Peripheral in project usbdm-eclipse-plugins by podonoghue.

the class ParseFamilyXML method parsePeripheral.

private void parsePeripheral(Element peripheralElement) throws Exception {
    String baseName = peripheralElement.getAttribute("baseName");
    String instance = peripheralElement.getAttribute("instance");
    String version = peripheralElement.getAttribute("version");
    Peripheral peripheral = null;
    for (Node node = peripheralElement.getFirstChild(); node != null; node = node.getNextSibling()) {
        if (node.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        Element element = (Element) node;
        if (element.getTagName() == "handler") {
            if (peripheral != null) {
                throw new Exception("Peripheral already created");
            }
            peripheral = fDeviceInfo.createPeripheral(baseName, instance, element.getAttribute("class"), element.getAttribute("parameters"));
        } else if (element.getTagName() == "clock") {
            if (peripheral == null) {
                peripheral = fDeviceInfo.createPeripheral(baseName, instance);
            }
            peripheral.setClockInfo(element.getAttribute("reg"), element.getAttribute("mask"));
        } else if (element.getTagName() == "irq") {
            peripheral.addIrqNum(element.getAttribute("num"));
        } else if (element.getTagName() == "dma") {
            peripheral.addDmaChannel(getIntAttribute(element, "num"), element.getAttribute("source"));
        } else if (element.getTagName() == "param") {
            String key = element.getAttribute("key");
            String value = element.getAttribute("value");
            PeripheralWithState p = (PeripheralWithState) peripheral;
            StringVariable v = new StringVariable(key, p.makeKey(key));
            p.addVariable(v);
            v.setValue(value);
            p.addParam(p.makeKey(key), value);
        } else {
            throw new Exception("Unexpected field in PERIPHERAL, value = \'" + element.getTagName() + "\'");
        }
    }
    peripheral.setVersion(version);
}
Also used : PeripheralWithState(net.sourceforge.usbdm.deviceEditor.peripherals.PeripheralWithState) Peripheral(net.sourceforge.usbdm.deviceEditor.information.Peripheral) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) StringVariable(net.sourceforge.usbdm.deviceEditor.information.StringVariable)

Aggregations

Peripheral (net.sourceforge.usbdm.deviceEditor.information.Peripheral)9 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Signal (net.sourceforge.usbdm.deviceEditor.information.Signal)2 UsbdmException (net.sourceforge.usbdm.jni.UsbdmException)2 BufferedReader (java.io.BufferedReader)1 MappingInfo (net.sourceforge.usbdm.deviceEditor.information.MappingInfo)1 MuxSelection (net.sourceforge.usbdm.deviceEditor.information.MuxSelection)1 Pin (net.sourceforge.usbdm.deviceEditor.information.Pin)1 StringVariable (net.sourceforge.usbdm.deviceEditor.information.StringVariable)1 PeripheralWithState (net.sourceforge.usbdm.deviceEditor.peripherals.PeripheralWithState)1 DevicePeripherals (net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals)1 InterruptEntry (net.sourceforge.usbdm.peripheralDatabase.InterruptEntry)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1