Search in sources :

Example 1 with DeviceSvdInfo

use of net.sourceforge.usbdm.peripheralDatabase.DeviceFileList.DeviceSvdInfo 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 2 with DeviceSvdInfo

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

Aggregations

IOException (java.io.IOException)2 Path (java.nio.file.Path)2 DeviceFileList (net.sourceforge.usbdm.peripheralDatabase.DeviceFileList)2 DeviceSvdInfo (net.sourceforge.usbdm.peripheralDatabase.DeviceFileList.DeviceSvdInfo)2 DevicePeripherals (net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals)2 IPath (org.eclipse.core.runtime.IPath)2 HashSet (java.util.HashSet)1