Search in sources :

Example 1 with InterruptEntry

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

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

the class PeripheralWithState method modifyVectorTable.

/**
 * Search vector table for handler and replace with class static method name
 *
 * @param vectorTable  Vector table to search
 * @param irqVariable  Describes interrupt including: <br>
 *
 * <li> pattern      Pattern to match against vector table entry. <br>
 * This is a regex.  In addition the following substitutions are done before matching:
 *    <ul>
 *    <li> %i replaced with peripheral instance e.g. FTM1 => 1, PTA => A
 *    <li> %b replaced with peripheral base name e.g. FTM1 => = FTM
 *    <li> %c replaced with peripheral C++ base class name e.g. FTM1 => = Ftm
 *    <li> _IRQHandler is appended
 *    </ul>
 * <li> classHandler Name of class method to handle interrupt <br>
 * This is a regex substitution pattern.  In addition the following substitutions are done before matching:
 *    <ul>
 *    <li> %i replaced with peripheral instance e.g. FTM1 => 1, PTA => A
 *    <li> %b replaced with peripheral base name e.g. FTM1 => = FTM
 *    <li> %c replaced with peripheral C++ base class name e.g. FTM1 => = Ftm
 *    </ul>
 * Regex substitution patterns may also be used.
 *    <ul>
 *    <li> $n reference to regex group in pattern
 *    </ul>
 * </ul>
 * @param className  Base name of C peripheral class e.g. Ftm
 */
public void modifyVectorTable(VectorTable vectorTable, IrqVariable irqVariable, String className) {
    if ((irqVariable == null) || (irqVariable.getValueAsLong() == 0)) {
        // No modification
        return;
    }
    final String headerFileName = getBaseName().toLowerCase() + ".h";
    boolean handlerSet = false;
    String pattern = irqVariable.getPattern();
    pattern = pattern.replaceAll("%b", getBaseName());
    pattern = pattern.replaceAll("%i", getInstance());
    pattern = pattern.replaceAll("%c", className);
    Pattern p = Pattern.compile(pattern);
    for (InterruptEntry entry : vectorTable.getEntries()) {
        if (entry != null) {
            Matcher m = p.matcher(entry.getName());
            if (m.matches()) {
                String modifier = "";
                if (m.groupCount() > 0) {
                    modifier = m.group(1);
                }
                String handlerName;
                switch(irqVariable.getMode()) {
                    case ClassMethod:
                        // Replace with name of class static method
                        String classHandler = irqVariable.getClassHandler();
                        classHandler = classHandler.replaceAll("%b", getBaseName());
                        classHandler = classHandler.replaceAll("%i", getInstance());
                        classHandler = classHandler.replaceAll("%c", className);
                        handlerName = DeviceInfo.NAME_SPACE + "::" + m.replaceAll(classHandler);
                        break;
                    case UserMethod:
                        // Replace with user specified name
                        // % represents 1st group from substitution
                        handlerName = irqVariable.getHandlerName().replaceAll("%", modifier);
                        break;
                    case NotInstalled:
                    default:
                        handlerName = "Default_Handler";
                        break;
                }
                entry.setHandlerName(handlerName);
                entry.setClassMemberUsedAsHandler(true);
                handlerSet = true;
            }
        }
        if (handlerSet) {
            // Add include file
            vectorTable.addIncludeFile(headerFileName);
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) InterruptEntry(net.sourceforge.usbdm.peripheralDatabase.InterruptEntry)

Aggregations

Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 InterruptEntry (net.sourceforge.usbdm.peripheralDatabase.InterruptEntry)2 BufferedReader (java.io.BufferedReader)1 Peripheral (net.sourceforge.usbdm.deviceEditor.information.Peripheral)1 UsbdmException (net.sourceforge.usbdm.jni.UsbdmException)1 DevicePeripherals (net.sourceforge.usbdm.peripheralDatabase.DevicePeripherals)1