Search in sources :

Example 1 with PeripheralWithState

use of net.sourceforge.usbdm.deviceEditor.peripherals.PeripheralWithState in project usbdm-eclipse-plugins by podonoghue.

the class DeviceInfo method generateCppFiles.

/**
 * Generate CPP files (pin_mapping.h, gpio.h)<br>
 * Used for testing (files created relative to executable)
 *
 * @throws Exception
 */
public void generateCppFiles() throws Exception {
    // Output directory for test files
    Path folder = Paths.get("Testing");
    // Generate device header file
    Path headerfilePath = folder.resolve(UsbdmConstants.PROJECT_INCLUDE_FOLDER).resolve(getDeviceSubFamily() + ".h");
    DevicePeripherals devicePeripherals = getDevicePeripherals();
    devicePeripherals.writeHeaderFile(headerfilePath, new NullProgressMonitor());
    // Generate pinmapping.h etc
    WriteFamilyCpp writer = new WriteFamilyCpp();
    writer.writeCppFiles(folder, "", this);
    // Regenerate vectors.cpp
    Map<String, String> variableMap = getSimpleSymbolMap();
    generateVectorTable(variableMap, devicePeripherals, new NullProgressMonitor());
    FileUtility.refreshFile(folder.resolve(UsbdmConstants.PROJECT_VECTOR_CPP_PATH), variableMap);
    ProcessProjectActions processProjectActions = new ProcessProjectActions();
    regenerateProjectFiles(processProjectActions, null, new NullProgressMonitor());
    for (String key : fPeripheralsMap.keySet()) {
        Peripheral p = fPeripheralsMap.get(key);
        if (p instanceof PeripheralWithState) {
            ((PeripheralWithState) p).regenerateProjectFiles(processProjectActions, null, new NullProgressMonitor());
        }
    }
}
Also used : Path(java.nio.file.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) PeripheralWithState(net.sourceforge.usbdm.deviceEditor.peripherals.PeripheralWithState) ProcessProjectActions(net.sourceforge.usbdm.deviceEditor.peripherals.ProcessProjectActions) DevicePeripherals(net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals) WriteFamilyCpp(net.sourceforge.usbdm.deviceEditor.peripherals.WriteFamilyCpp)

Example 2 with PeripheralWithState

use of net.sourceforge.usbdm.deviceEditor.peripherals.PeripheralWithState in project usbdm-eclipse-plugins by podonoghue.

the class DeviceInfo method parse.

/**
 * Load hardware description from file
 *
 * @param hardwarePath  Path to load from
 *
 * @throws Exception
 */
private void parse(Path hardwarePath) throws Exception {
    System.err.println("DeviceInfo.parse(" + hardwarePath.toAbsolutePath() + ")");
    fHardwarePath = hardwarePath;
    String filename = fHardwarePath.getFileName().toString();
    if (filename.endsWith(HARDWARE_CSV_FILE_EXTENSION)) {
        ParseFamilyCSV parser = new ParseFamilyCSV(this);
        parser.parseFile(fHardwarePath);
    } else if ((filename.endsWith("xml")) || (filename.endsWith(HARDWARE_FILE_EXTENSION))) {
        ParseFamilyXML parser = new ParseFamilyXML();
        parser.parseFile(this, fHardwarePath);
        fVariableProvider = new VariableProvider("Common Settings", this) {

            // Add change lister to mark editor dirty
            @Override
            public void addVariable(Variable variable) {
                super.addVariable(variable);
                variable.addListener(DeviceInfo.this);
            }
        };
        fMenuData = ParseMenuXML.parseMenuFile("_common_settings", fVariableProvider);
        ArrayList<PeripheralWithState> peripheralWithStateList = new ArrayList<PeripheralWithState>();
        // Construct list of all PeripheralWithState
        for (String name : fPeripheralsMap.keySet()) {
            Peripheral p = fPeripheralsMap.get(name);
            if (p instanceof PeripheralWithState) {
                peripheralWithStateList.add((PeripheralWithState) fPeripheralsMap.get(name));
            }
        }
        // Sort in priority order
        Collections.sort(peripheralWithStateList, new Comparator<PeripheralWithState>() {

            @Override
            public int compare(PeripheralWithState o1, PeripheralWithState o2) {
                return o2.getPriority() - o1.getPriority();
            }
        });
        // Construct peripherals
        for (PeripheralWithState p : peripheralWithStateList) {
            if (p instanceof PeripheralWithState) {
                // System.err.println("Constructing " + p);
                ((PeripheralWithState) p).loadModels();
            }
        }
        for (PeripheralWithState p : peripheralWithStateList) {
            if (p instanceof PeripheralWithState) {
                p.instantiateAliases();
            }
        }
    } else {
        throw new Exception("Unexpected file type for " + hardwarePath);
    }
}
Also used : PeripheralWithState(net.sourceforge.usbdm.deviceEditor.peripherals.PeripheralWithState) ParseFamilyCSV(net.sourceforge.usbdm.deviceEditor.peripherals.ParseFamilyCSV) VariableProvider(net.sourceforge.usbdm.deviceEditor.peripherals.VariableProvider) ArrayList(java.util.ArrayList) ParseFamilyXML(net.sourceforge.usbdm.deviceEditor.xmlParser.ParseFamilyXML) CoreException(org.eclipse.core.runtime.CoreException) UsbdmException(net.sourceforge.usbdm.jni.UsbdmException) IOException(java.io.IOException) Comparator(java.util.Comparator)

Example 3 with PeripheralWithState

use of net.sourceforge.usbdm.deviceEditor.peripherals.PeripheralWithState in project usbdm-eclipse-plugins by podonoghue.

the class DeviceInfo method generateCppFiles.

/**
 * Generate CPP files (pin_mapping.h, gpio.h etc) within an Eclipse C++ project
 *
 * @param project       Destination Eclipse C++ project
 * @param monitor
 * @throws Exception
 */
public void generateCppFiles(IProject project, IProgressMonitor monitor) throws Exception {
    SubMonitor subMonitor = SubMonitor.convert(monitor, (fPeripheralsMap.size() + 5) * 100);
    // Generate device header file
    Path projectDirectory = Paths.get(project.getLocation().toPortableString());
    Path headerfilePath = projectDirectory.resolve(UsbdmConstants.PROJECT_INCLUDE_FOLDER).resolve(getDeviceSubFamily() + ".h");
    subMonitor.subTask("Parse SVD file");
    DevicePeripherals devicePeripherals = getDevicePeripherals();
    subMonitor.worked(10);
    devicePeripherals.writeHeaderFile(headerfilePath, subMonitor.newChild(10));
    // Generate pinmapping.h etc
    WriteFamilyCpp writer = new WriteFamilyCpp();
    writer.writeCppFiles(project, this, subMonitor.newChild(10));
    // Regenerate vectors.cpp
    Map<String, String> variableMap = new HashMap<String, String>();
    generateVectorTable(variableMap, devicePeripherals, subMonitor.newChild(10));
    FileUtility.refreshFile(project, UsbdmConstants.PROJECT_VECTOR_CPP_PATH, variableMap, subMonitor.newChild(10));
    ProcessProjectActions processProjectActions = new ProcessProjectActions();
    regenerateProjectFiles(processProjectActions, project, subMonitor.newChild(10));
    for (String key : fPeripheralsMap.keySet()) {
        Peripheral p = fPeripheralsMap.get(key);
        if (p instanceof PeripheralWithState) {
            ((PeripheralWithState) p).regenerateProjectFiles(processProjectActions, project, subMonitor.newChild(10));
        }
    }
}
Also used : Path(java.nio.file.Path) PeripheralWithState(net.sourceforge.usbdm.deviceEditor.peripherals.PeripheralWithState) ProcessProjectActions(net.sourceforge.usbdm.deviceEditor.peripherals.ProcessProjectActions) DevicePeripherals(net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals) HashMap(java.util.HashMap) WriteFamilyCpp(net.sourceforge.usbdm.deviceEditor.peripherals.WriteFamilyCpp) SubMonitor(org.eclipse.core.runtime.SubMonitor)

Example 4 with PeripheralWithState

use of net.sourceforge.usbdm.deviceEditor.peripherals.PeripheralWithState in project usbdm-eclipse-plugins by podonoghue.

the class DeviceInfo method loadSettings.

/**
 * Load persistent settings
 */
public void loadSettings(Settings settings) {
    try {
        String variantName = settings.get(USBDMPROJECT_VARIANT_SETTING_KEY);
        setVariantName(variantName);
        Path path = locateFile("/peripherals/symbols/" + variantName + ".xml");
        if (path != null) {
            settings.load(path);
        }
        String subFamilyName = settings.get(USBDMPROJECT_SUBFAMILY_SETTING_KEY);
        if (subFamilyName == null) {
            subFamilyName = settings.get(USBDMPROJECT_OLD_SUBFAMILY_SETTING_KEY);
        }
        setDeviceSubFamily(subFamilyName);
        for (String pinName : fPins.keySet()) {
            Pin pin = fPins.get(pinName);
            pin.loadSettings(settings);
        }
        for (String peripheralName : fPeripheralsMap.keySet()) {
            Peripheral peripheral = fPeripheralsMap.get(peripheralName);
            peripheral.loadSettings(settings);
        }
        for (String key : settings.getKeys()) {
            Variable var = fVariables.get(key);
            String value = settings.get(key);
            if (var != null) {
                if (!var.isDerived()) {
                    // Load persistent value associated with variable
                    var.setPersistentValue(value);
                // System.err.println("Setting Variable "+key+" to "+value);
                }
            } else if (key.startsWith("$")) {
            // Ignore these as loaded earlier
            // System.err.println("WARNING: Discarding system setting "+key+" to "+value);
            } else if (key.startsWith("/")) {
                // Shouldn't be any unmatched peripheral settings
                System.err.println("WARNING: Discarding unmatched peripheral settings " + key + "(" + value + ")");
            } else {
                // Load persistent value (parameter)
                // System.err.println("Creating Variable "+key+"("+value+")");
                var = new StringVariable(key, key);
                var.setPersistentValue(value);
                var.setDerived(true);
                addVariable(key, var);
            }
        }
        // Create dependencies between peripherals
        for (Entry<String, Peripheral> entry : fPeripheralsMap.entrySet()) {
            Peripheral peripheral = entry.getValue();
            ArrayList<Validator> validators = peripheral.getValidators();
            for (Validator validator : validators) {
                // validator.createDependencies();
                validator.addDependencies();
            }
        }
        // System.err.println("Make sure peripherals have been updated");
        /*
          * Make sure critical peripherals have been updated in order first
          */
        String[] criticalPeripherals = { "RTC", "OSC", "OSC0", "OSC_RF0", "MCG", "SIM" };
        for (String name : criticalPeripherals) {
            Peripheral peripheral = fPeripheralsMap.get(name);
            if (peripheral instanceof PeripheralWithState) {
                ((PeripheralWithState) peripheral).variableChanged(null);
            }
        }
        for (Entry<String, Peripheral> entry : fPeripheralsMap.entrySet()) {
            Peripheral peripheral = entry.getValue();
            if (peripheral instanceof PeripheralWithState) {
                ((PeripheralWithState) peripheral).variableChanged(null);
            }
        }
        /*
        * Notify changes of persistent variables, 
        * even on variables that were not loaded
        * Shouldn't be necessary
        */
        for (Entry<String, Variable> entry : fVariables.entrySet()) {
            Variable var = entry.getValue();
            if (!var.isDerived()) {
                var.notifyListeners();
            }
        }
        /**
         * Sanity check - (usually) no persistent variables should change value initially
         */
        for (Entry<String, Variable> entry : fVariables.entrySet()) {
            String value = settings.get(entry.getKey());
            if (value != null) {
                Variable var = fVariables.get(entry.getKey());
                if (!var.isDerived()) {
                    if (!var.getPersistentValue().equals(value)) {
                        System.err.println("WARNING: deviceEditor.information.DeviceInfo.loadSettings - Variable changed " + var.getName());
                        System.err.println("Current value    = " + value);
                        System.err.println("Persistent value = " + var.getPersistentValue());
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    setDirty(false);
}
Also used : Path(java.nio.file.Path) CoreException(org.eclipse.core.runtime.CoreException) UsbdmException(net.sourceforge.usbdm.jni.UsbdmException) IOException(java.io.IOException) PeripheralWithState(net.sourceforge.usbdm.deviceEditor.peripherals.PeripheralWithState) Validator(net.sourceforge.usbdm.deviceEditor.validators.Validator)

Example 5 with PeripheralWithState

use of net.sourceforge.usbdm.deviceEditor.peripherals.PeripheralWithState 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

PeripheralWithState (net.sourceforge.usbdm.deviceEditor.peripherals.PeripheralWithState)5 Path (java.nio.file.Path)3 IOException (java.io.IOException)2 ProcessProjectActions (net.sourceforge.usbdm.deviceEditor.peripherals.ProcessProjectActions)2 WriteFamilyCpp (net.sourceforge.usbdm.deviceEditor.peripherals.WriteFamilyCpp)2 UsbdmException (net.sourceforge.usbdm.jni.UsbdmException)2 DevicePeripherals (net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals)2 CoreException (org.eclipse.core.runtime.CoreException)2 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 Peripheral (net.sourceforge.usbdm.deviceEditor.information.Peripheral)1 StringVariable (net.sourceforge.usbdm.deviceEditor.information.StringVariable)1 ParseFamilyCSV (net.sourceforge.usbdm.deviceEditor.peripherals.ParseFamilyCSV)1 VariableProvider (net.sourceforge.usbdm.deviceEditor.peripherals.VariableProvider)1 Validator (net.sourceforge.usbdm.deviceEditor.validators.Validator)1 ParseFamilyXML (net.sourceforge.usbdm.deviceEditor.xmlParser.ParseFamilyXML)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 Element (org.w3c.dom.Element)1