Search in sources :

Example 1 with UsbdmException

use of net.sourceforge.usbdm.jni.UsbdmException in project usbdm-eclipse-plugins by podonoghue.

the class ExampleList method parseVariables.

/**
 * @param projectInfo    project info
 *
 * @param exampleElement <example> element
 *
 * @throws UsbdmException
 */
private void parseVariables(ProjectInformation projectInfo, Element exampleElement) throws UsbdmException {
    for (Node node = exampleElement.getFirstChild(); node != null; node = node.getNextSibling()) {
        // element node for <example>
        if (node.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        Element element = (Element) node;
        if (element.getTagName() != "variable") {
            throw new UsbdmException("parseExampleList(" + node.getNodeName() + ") - not variable element");
        }
        String key = element.getAttribute("name");
        String value = element.getTextContent();
        projectInfo.addAttribute(key, value);
    }
}
Also used : Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) UsbdmException(net.sourceforge.usbdm.jni.UsbdmException)

Example 2 with UsbdmException

use of net.sourceforge.usbdm.jni.UsbdmException in project usbdm-eclipse-plugins by podonoghue.

the class ParseMenuXML method parseSignalsOption.

/**
 * Parse the pin associated with the peripheral
 *
 * @param parentModel
 * @param element
 * @throws UsbdmException
 */
private void parseSignalsOption(BaseModel parentModel, Element element) throws UsbdmException {
    // Initially assume pins refer to current peripheral
    Peripheral peripheral = fPeripheral;
    boolean optional = Boolean.valueOf(element.getAttribute("optional"));
    String peripheralName = element.getAttribute("name");
    if (!peripheralName.isEmpty()) {
        // Change to referenced peripheral
        peripheral = fPeripheral.getDeviceInfo().getPeripherals().get(peripheralName);
    }
    if (peripheral == null) {
        if (!optional) {
            throw new UsbdmException("Unable to find peripheral '" + peripheralName + "' for pins");
        }
        return;
    }
    fPeripheral.addSignals(parentModel, peripheral);
}
Also used : Peripheral(net.sourceforge.usbdm.deviceEditor.information.Peripheral) UsbdmException(net.sourceforge.usbdm.jni.UsbdmException)

Example 3 with UsbdmException

use of net.sourceforge.usbdm.jni.UsbdmException 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 4 with UsbdmException

use of net.sourceforge.usbdm.jni.UsbdmException in project usbdm-eclipse-plugins by podonoghue.

the class DeviceInfo method getDevicePeripherals.

/**
 * Get peripheral information from SVD file<br>
 * This is a time consuming operation.
 *
 * @return Peripheral information
 *
 * @throws UsbdmException
 */
public DevicePeripherals getDevicePeripherals() throws UsbdmException {
    DevicePeripheralsFactory factory = new DevicePeripheralsFactory();
    DevicePeripherals devicePeripherals = factory.getDevicePeripherals(fDeviceSubFamily);
    if (devicePeripherals == null) {
        throw new UsbdmException("Failed to create devicePeripherals from SVD for \'" + fDeviceSubFamily + "\'");
    }
    return devicePeripherals;
}
Also used : DevicePeripherals(net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals) UsbdmException(net.sourceforge.usbdm.jni.UsbdmException) DevicePeripheralsFactory(net.sourceforge.usbdm.peripheralDatabase.DevicePeripheralsFactory)

Example 5 with UsbdmException

use of net.sourceforge.usbdm.jni.UsbdmException in project usbdm-eclipse-plugins by podonoghue.

the class UsbdmJniPluginTest method main.

/**
 * @param args
 * @throws InterruptedException
 * @throws UsbdmException
 */
public static void main(String[] args) throws InterruptedException, UsbdmException {
    String errorMessage = null;
    // testDatabase();
    try {
        listEnvironment();
        // CustomClassLoader ccl = new CustomClassLoader();
        // 
        // Class<?> ca = ccl.findClass("net.sourceforge.usbdm.jni.Usbdm");
        // Object a = ca.newInstance();
        // ccl = null;
        // System.gc();
        // Print USBDM paths
        System.err.println("Application Path : " + Usbdm.getApplicationPath().toOSString());
        System.err.println("Resource Path    : " + Usbdm.getResourcePath().toOSString());
        System.err.println("Data Path        : " + Usbdm.getDataPath().toOSString());
        // listDevices();
        // Get count of devices (creates internal list)
        int deviceCount = Usbdm.findDevices();
        if (deviceCount == 0) {
            System.err.println("No USBDM devices found");
            return;
        }
        System.err.println("No of USBDM devices found " + deviceCount);
        // Open last device
        Usbdm.open(deviceCount - 1);
        System.err.println("Opened device: " + Usbdm.getBDMDescription());
        // testCFV1();
        testKinetis();
        Usbdm.close();
    } catch (Exception e) {
        e.printStackTrace();
        errorMessage = e.getMessage();
        if (errorMessage == null) {
            errorMessage = e.toString();
        }
        if (errorMessage == null) {
            errorMessage = "Unknown exception";
        }
    } finally {
        Usbdm.exit();
        if (errorMessage != null) {
            Shell shell;
            // Find the default display and get the active shell
            final Display disp = Display.getDefault();
            if (disp == null) {
                shell = new Shell(new Display());
            } else {
                shell = new Shell(disp);
            }
            MessageBox msgbox = new MessageBox(shell, SWT.OK);
            msgbox.setText("USBDM Error");
            msgbox.setMessage(errorMessage);
            msgbox.open();
        }
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) UsbdmException(net.sourceforge.usbdm.jni.UsbdmException) Display(org.eclipse.swt.widgets.Display) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

UsbdmException (net.sourceforge.usbdm.jni.UsbdmException)11 IPath (org.eclipse.core.runtime.IPath)3 Path (org.eclipse.core.runtime.Path)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Peripheral (net.sourceforge.usbdm.deviceEditor.information.Peripheral)2 DevicePeripherals (net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals)2 MessageBox (org.eclipse.swt.widgets.MessageBox)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1