Search in sources :

Example 11 with DevicePeripherals

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

the class CreatePeripheralDatabase method createExpandedSvdFilesFromList.

/**
 * Produces expanded (single file per target) SVD files (based on deviceList.xml)
 *
 * @param sourceFolderPath       Should contain "DeviceList.xml" file
 * @param destinationFolderPath  Where to write expanded files to
 *
 * @throws Exception
 */
static void createExpandedSvdFilesFromList(Path sourceFolderPath, Path destinationFolderPath, boolean optimise) throws Exception {
    FileFilter fileFilter = new FileFilter(firstFileToProcess, firstFileToReject);
    if (Files.exists(destinationFolderPath)) {
        System.err.flush();
        System.err.println("Destination already exists " + destinationFolderPath);
        return;
    }
    // Set optimisations
    ModeControl.setExtractComplexStructures(optimise);
    ModeControl.setExtractDerivedPeripherals(optimise);
    ModeControl.setExtractSimpleRegisterArrays(optimise);
    ModeControl.setMapFreescalePeriperalCommonNames(optimise);
    ModeControl.setGenerateFreescaleRegisterMacros(optimise);
    ModeControl.setRegenerateAddressBlocks(optimise);
    // ModeControl.setExtractCommonPrefix(optimise);
    destinationFolderPath.toFile().mkdir();
    DeviceFileList deviceFileList = new DeviceFileList(sourceFolderPath.resolve(DEVICE_LIST_FILENAME));
    ArrayList<DeviceSvdInfo> list = deviceFileList.getArrayList();
    for (DeviceSvdInfo pair : list) {
        if (fileFilter.skipFile(pair.deviceName)) {
            continue;
        }
        System.err.println("Processing File : \"" + pair.svdName + "\"");
        try {
            // Read device description
            DevicePeripherals devicePeripherals = new DevicePeripherals(sourceFolderPath.resolve(pair.svdName + ".svd.xml"));
            // Optimise peripheral database
            devicePeripherals.optimise();
            devicePeripherals.setName(pair.deviceName);
            // Create SVD file
            Path svdFilePath = destinationFolderPath.resolve(devicePeripherals.getName() + ".svd.xml");
            System.err.println("Creating : \"" + svdFilePath + "\"");
            devicePeripherals.writeSVD(svdFilePath);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : DeviceFileList(net.sourceforge.usbdm.peripheralDatabase.DeviceFileList) IPath(org.eclipse.core.runtime.IPath) Path(java.nio.file.Path) DevicePeripherals(net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals) DeviceSvdInfo(net.sourceforge.usbdm.peripheralDatabase.DeviceFileList.DeviceSvdInfo) IOException(java.io.IOException)

Example 12 with DevicePeripherals

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

the class CreatePeripheralDatabase method createReducedDeviceList.

/**
 * Creates a minimal set of device SVD files by looking for equivalent devices.
 * A separate XML file is created that maps a device to a SVD file (deviceList.xml).
 * Note: The target directory will end up with expanded SVD files!
 * Note: Source directory may contain reduced SVD files.
 *
 * @param sourceFolderPath       Directory containing SVD files to process (all files ending in ".svd.xml").
 * @param destinationFolderPath  Where to write destination files.
 *
 * @throws Exception
 */
public static void createReducedDeviceList(Path sourceFolderPath, Path destinationFolderPath) throws Exception {
    FileFilter fileFilter = new FileFilter(firstFileToProcess, firstFileToReject);
    if (Files.exists(destinationFolderPath)) {
        System.err.flush();
        System.err.println("Destination already exists " + destinationFolderPath);
        return;
    }
    ArrayList<DevicePeripherals> deviceList = new ArrayList<DevicePeripherals>();
    // Set optimizations
    ModeControl.setExtractComplexStructures(false);
    ModeControl.setExtractDerivedPeripherals(false);
    ModeControl.setExtractSimpleRegisterArrays(false);
    ModeControl.setMapFreescalePeriperalCommonNames(false);
    ModeControl.setGenerateFreescaleRegisterMacros(false);
    ModeControl.setRegenerateAddressBlocks(false);
    ModeControl.setExpandDerivedPeripherals(true);
    ModeControl.setExpandDerivedRegisters(false);
    int maxDevices = 500;
    Files.createDirectory(destinationFolderPath);
    DirectoryStream<Path> sourceFolderStream = Files.newDirectoryStream(sourceFolderPath);
    // 
    for (Path svdSourceFile : sourceFolderStream) {
        // Create database of all devices
        if (Files.isRegularFile(svdSourceFile)) {
            String fileName = svdSourceFile.getFileName().toString();
            if (fileFilter.skipFile(fileName)) {
                continue;
            }
            if (fileName.endsWith(".svd.xml")) {
                // System.err.println("Processing File : \""+svdSourceFile.getName()+"\"");
                try {
                    // Read device description
                    DevicePeripherals device = new DevicePeripherals(svdSourceFile);
                    // Don't optimise as we want flat files for editing/checking
                    // device.optimise();
                    boolean foundEquivalent = false;
                    for (DevicePeripherals searchPeripheral : deviceList) {
                        if (searchPeripheral.equivalentStructure(device)) {
                            searchPeripheral.addEquivalentDevice(device.getName());
                            foundEquivalent = true;
                        }
                    }
                    if (!foundEquivalent) {
                        deviceList.add(device);
                        System.err.println("New       " + device.getName());
                    } else {
                        System.err.println("Equivalent " + device.getName());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (maxDevices-- < 0) {
                break;
            }
        }
    }
    System.err.println();
    // Copy devices to target directory (expanded!)
    // Produce sorted list of device->svd file
    // List of copied devices to check for mapping clashes
    ArrayList<Pair> devicePairList = new ArrayList<Pair>();
    for (DevicePeripherals device : deviceList) {
        String deviceName = device.getName();
        // Add reference to self
        for (String equivalentDevice : device.getEquivalentDevices()) {
            // Add references from other devices
            devicePairList.add(new Pair(equivalentDevice, deviceName));
        }
        device.writeSVD(destinationFolderPath.resolve(deviceName + ".svd.xml"));
    }
    sortDeviceNames(devicePairList);
    // Create deviceList.xml
    File deviceListFile = destinationFolderPath.resolve(DEVICE_LIST_FILENAME).toFile();
    PrintWriter writer = null;
    try {
        writer = new PrintWriter(deviceListFile);
        writer.print(xmlPreamble);
        writer.print(openDeviceList);
        for (Pair pair : devicePairList) {
            writer.print(String.format(deviceEntry, "<device name=\"" + pair.deviceName + "\">", pair.fileName));
        }
        writer.print(closeDeviceList);
        writer.print(xmlPostamble);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
    Files.copy(MAIN_FOLDER.getParent().resolve(CMSIS_SCHEMA_FILENAME), destinationFolderPath.resolve(CMSIS_SCHEMA_FILENAME), StandardCopyOption.REPLACE_EXISTING);
    Files.copy(MAIN_FOLDER.getParent().resolve(DEVICE_LIST_SCHEMA_FILENAME), destinationFolderPath.resolve(DEVICE_LIST_SCHEMA_FILENAME), StandardCopyOption.REPLACE_EXISTING);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(java.nio.file.Path) DevicePeripherals(net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 13 with DevicePeripherals

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

the class CreatePeripheralDatabase method createHeaderFiles.

/*
    * *************************************************************************************************************************************
    * *************************************************************************************************************************************
    */
/**
 *    Produces multiple header files from multiple device SVD files
 *    Optimisations may be applied to the SVD file before creating the header file.
 *    Header file name is based on device name in SVD file - not the source file name
 *
 *    sourceFolderPath/*.svd.xml +-> destinationPath/*.h
 *
 *  @param sourceFolderPath       - Folder containing SVD files (must have .svd.xml extension, otherwise ignored)
 *  @param destinationFolderPath  - Folder to write created header file to
 *  @param removeFolder           - Delete destination folder
 * @throws Exception
 */
public static void createHeaderFiles(Path sourceFolderPath, Path destinationFolderPath, boolean removeFolder) throws Exception {
    FileFilter fileFilter = new FileFilter(firstFileToProcess, firstFileToReject);
    if (Files.exists(destinationFolderPath)) {
        if (!removeFolder) {
            System.err.println("Destination already exists " + destinationFolderPath.toString());
        } else {
            System.err.println("Destination already exists -  deleting " + destinationFolderPath.toString());
            removeDirectoryTree(destinationFolderPath);
        }
    }
    if (!Files.exists(destinationFolderPath)) {
        Files.createDirectory(destinationFolderPath);
    }
    DirectoryStream<Path> sourceFolderStream = Files.newDirectoryStream(sourceFolderPath);
    int deviceCount = 5000;
    for (Path svdSourceFile : sourceFolderStream) {
        if (deviceCount-- == 0) {
            break;
        }
        if (Files.isRegularFile(svdSourceFile)) {
            String fileName = svdSourceFile.getFileName().toString();
            if (fileFilter.skipFile(fileName)) {
                continue;
            }
            if (fileName.endsWith(".svd.xml")) {
                System.err.println("Processing File : \"" + fileName + "\"");
                // Read device description
                DevicePeripherals devicePeripherals = new DevicePeripherals(svdSourceFile);
                // Optimise peripheral database
                devicePeripherals.optimise();
                devicePeripherals.sortPeripherals();
                // Create header file
                Path headerFilePath = destinationFolderPath.resolve(devicePeripherals.getName().toString() + ".h");
                System.err.println("Creating : \"" + headerFilePath + "\"");
                devicePeripherals.writeHeaderFile(headerFilePath);
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(java.nio.file.Path) DevicePeripherals(net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals)

Example 14 with DevicePeripherals

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

the class CreatePeripheralDatabase method createHeaderFilesFromList.

/**
 * Produces a set of header files from SVD files (based on deviceList.xml)
 * Each header file represent a device family with similar peripherals
 *
 * @param sourceFolderPath       Should contain "DeviceList.xml" file
 * @param destinationFolderPath  Where to write header files to
 * @param removeFolder           Destination folder will be deleted (otherwise files just overwrite/accumulate)
 *
 * @throws Exception
 */
static void createHeaderFilesFromList(Path sourceFolderPath, Path destinationFolderPath, boolean removeFolder) throws Exception {
    FileFilter fileFilter = new FileFilter(firstFileToProcess, firstFileToReject);
    if (Files.exists(destinationFolderPath)) {
        if (!removeFolder) {
            System.err.println("Destination already exists " + destinationFolderPath);
        } else {
            System.err.println("Destination already exists -  deleting " + destinationFolderPath);
            removeDirectoryTree(destinationFolderPath);
        }
    }
    // Set options
    ModeControl.setFreescaleFieldNames(true);
    ModeControl.setMapFreescalePeriperalCommonNames(true);
    ModeControl.setGenerateFreescaleRegisterMacros(false);
    ModeControl.setUseShiftsInFieldMacros(true);
    // Don't optimise
    ModeControl.setExtractComplexStructures(false);
    ModeControl.setExtractDerivedPeripherals(false);
    ModeControl.setExtractSimpleRegisterArrays(false);
    ModeControl.setRegenerateAddressBlocks(false);
    destinationFolderPath.toFile().mkdir();
    DeviceFileList deviceFileList = new DeviceFileList(sourceFolderPath.resolve(DEVICE_LIST_FILENAME));
    // Get full list of devices
    ArrayList<DeviceSvdInfo> list = deviceFileList.getArrayList();
    // Map of already copied files to prevent multiple copying
    HashSet<String> copiedFiles = new HashSet<String>();
    for (int index = 0; index < list.size(); index++) {
        DeviceSvdInfo pair = list.get(index);
        if (fileFilter.skipFile(pair.deviceName)) {
            continue;
        }
        System.err.println("Processing File : \"" + pair.deviceName + "\"");
        try {
            // Don't produce the same file!
            if (copiedFiles.contains(pair.svdName)) {
                continue;
            }
            copiedFiles.add(pair.svdName);
            // Read device description
            DevicePeripherals devicePeripherals = new DevicePeripherals(sourceFolderPath.resolve(pair.svdName + ".svd.xml"));
            devicePeripherals.sortPeripherals();
            devicePeripherals.setName(pair.svdName);
            devicePeripherals.addEquivalentDevice(pair.deviceName);
            for (int index2 = index + 1; index2 < list.size(); index2++) {
                if (pair.svdName.equalsIgnoreCase(list.get(index2).svdName)) {
                    devicePeripherals.addEquivalentDevice(list.get(index2).deviceName);
                }
            }
            // Create header file
            Path headerFilePath = destinationFolderPath.resolve(devicePeripherals.getName() + ".h");
            System.err.println("Creating : \"" + headerFilePath + "\"");
            devicePeripherals.writeHeaderFile(headerFilePath);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : DeviceFileList(net.sourceforge.usbdm.peripheralDatabase.DeviceFileList) IPath(org.eclipse.core.runtime.IPath) Path(java.nio.file.Path) DevicePeripherals(net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals) DeviceSvdInfo(net.sourceforge.usbdm.peripheralDatabase.DeviceFileList.DeviceSvdInfo) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 15 with DevicePeripherals

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

the class TestVectorTable method testVectorTable.

static void testVectorTable(String device) throws Exception {
    // Get description of all peripherals for device
    DevicePeripheralsFactory factory = new DevicePeripheralsFactory();
    DevicePeripherals devicePeripherals = factory.getDevicePeripherals(device);
    if (devicePeripherals == null) {
        // Return empty model
        System.err.println("Failed");
        return;
    }
    VectorTable vt = devicePeripherals.getVectorTable();
    String cVectorTable = vt.getCVectorTableEntries();
    System.err.print(cVectorTable);
}
Also used : DevicePeripherals(net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals) VectorTable(net.sourceforge.usbdm.peripheralDatabase.VectorTable) DevicePeripheralsFactory(net.sourceforge.usbdm.peripheralDatabase.DevicePeripheralsFactory)

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