Search in sources :

Example 1 with DevicePeripherals

use of net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals in project usbdm-eclipse-plugins by podonoghue.

the class UsbdmDeviceSelectionPage_2 method addDeviceAttributes.

/**
 * Adds device specific attributes to map
 *
 * @param paramMap Map to add attributes to
 * @param device   Device needed to obtain attributes
 */
private void addDeviceAttributes(Map<String, String> paramMap, Device device) {
    if (device == null) {
        return;
    }
    // Try to locate device specific header file
    String externalHeaderFile = getExternalProjectHeaderFile(device);
    // System.err.println("Result for device header file: \'" + externalHeaderFile + "\'"); //$NON-NLS-1$
    // Try to locate device specific vector table file
    String externalVectorTableFile = getExternalVectorTable(device);
    // System.err.println("Result for vector table file: \'" + externalVectorTableFile + "\'"); //$NON-NLS-1$
    addLinkerMemoryMap(device, paramMap);
    addDeviceCodeValues(paramMap, device);
    try {
        if (externalVectorTableFile.isEmpty()) {
            // Generate vector table from SVD files if possible
            DevicePeripherals devicePeripherals = getDevicePeripherals(device);
            String cVectorTable = null;
            if (devicePeripherals != null) {
                cVectorTable = devicePeripherals.getCVectorTableEntries();
            }
            if (cVectorTable == null) {
                // System.err.println("UsbdmProjectParametersPage.addDeviceAttributes() - generating default vector table");
                switch(fInterfaceType) {
                    case T_ARM:
                    default:
                        cVectorTable = VECTOR_TABLE_INTRO + VectorTable.factory("CM4").getCVectorTableEntries();
                        break;
                    case T_CFV1:
                        cVectorTable = VECTOR_TABLE_INTRO + VectorTable.factory("CFV1").getCVectorTableEntries();
                        break;
                    case T_CFVX:
                        cVectorTable = VECTOR_TABLE_INTRO + VectorTable.factory("CFV2").getCVectorTableEntries();
                        break;
                }
            }
            paramMap.put(UsbdmConstants.C_VECTOR_TABLE_KEY, cVectorTable);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    paramMap.put(UsbdmConstants.EXTERNAL_HEADER_FILE_KEY, externalHeaderFile);
    paramMap.put(UsbdmConstants.EXTERNAL_VECTOR_TABLE_KEY, externalVectorTableFile);
}
Also used : DevicePeripherals(net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals)

Example 2 with DevicePeripherals

use of net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals 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 3 with DevicePeripherals

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

use of net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals 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 DevicePeripherals

use of net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals 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)

Aggregations

DevicePeripherals (net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals)17 Path (java.nio.file.Path)8 IPath (org.eclipse.core.runtime.IPath)5 DevicePeripheralsFactory (net.sourceforge.usbdm.peripheralDatabase.DevicePeripheralsFactory)4 IOException (java.io.IOException)3 PrintWriter (java.io.PrintWriter)2 HashMap (java.util.HashMap)2 Pattern (java.util.regex.Pattern)2 PeripheralWithState (net.sourceforge.usbdm.deviceEditor.peripherals.PeripheralWithState)2 ProcessProjectActions (net.sourceforge.usbdm.deviceEditor.peripherals.ProcessProjectActions)2 WriteFamilyCpp (net.sourceforge.usbdm.deviceEditor.peripherals.WriteFamilyCpp)2 UsbdmException (net.sourceforge.usbdm.jni.UsbdmException)2 DeviceFileList (net.sourceforge.usbdm.peripheralDatabase.DeviceFileList)2 DeviceSvdInfo (net.sourceforge.usbdm.peripheralDatabase.DeviceFileList.DeviceSvdInfo)2 Peripheral (net.sourceforge.usbdm.peripheralDatabase.Peripheral)2 SVDIdentifier (net.sourceforge.usbdm.peripheralDatabase.SVDIdentifier)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1