use of net.sourceforge.usbdm.deviceEditor.information.Peripheral 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();
}
use of net.sourceforge.usbdm.deviceEditor.information.Peripheral in project usbdm-eclipse-plugins by podonoghue.
the class ParseFamilyCSV method parsePeripheralInfoLine.
/**
* Parse line containing Peripheral information
*
* @param line
*/
private void parsePeripheralInfoLine(String[] line) {
if (!line[0].equals("Peripheral")) {
return;
}
if (line.length < 2) {
throw new RuntimeException("Illegal Peripheral Mapping line");
}
String peripheralName = line[PERIPHERAL_NAME_COL];
Peripheral peripheral = fDeviceInfo.findOrCreatePeripheral(peripheralName);
if (peripheral == null) {
throw new RuntimeException("Unable to find peripheral " + peripheralName);
}
if (line.length < 3) {
// No parameters
return;
}
String peripheralClockReg = line[CLOCK_REG_COL];
String peripheralClockMask = null;
if (line.length > CLOCK_MASK_COL) {
peripheralClockMask = line[CLOCK_MASK_COL];
}
if ((peripheralClockMask == null) || (peripheralClockMask.isEmpty())) {
peripheralClockMask = peripheralClockReg.replace("->", "_") + "_" + peripheralName + "_MASK";
}
if ((peripheralClockReg != null) && !peripheralClockReg.isEmpty()) {
Pattern pattern = Pattern.compile("SIM->(SCGC\\d?)");
Matcher matcher = pattern.matcher(peripheralClockReg);
if (!matcher.matches()) {
throw new RuntimeException("Unexpected Peripheral Clock Register " + peripheralClockReg + " for " + peripheralName);
}
peripheralClockReg = matcher.group(1);
if (!peripheralClockMask.contains(peripheralClockReg)) {
throw new RuntimeException("Clock Mask " + peripheralClockMask + " doesn't match Clock Register " + peripheralClockReg);
}
peripheral.setClockInfo(peripheralClockReg, peripheralClockMask);
}
}
use of net.sourceforge.usbdm.deviceEditor.information.Peripheral in project usbdm-eclipse-plugins by podonoghue.
the class WriteFamilyCpp method writePeripheralInformationClasses.
/**
* Write all Peripheral Information Classes<br>
*
* <pre>
* class Adc0Info {
* ...
* };
* class Adc1Info {
* ...
* };
* </pre>
*
* @param writer
* Where to write
*
* @throws IOException
*/
private void writePeripheralInformationClasses(DocumentUtilities writer) throws IOException {
writer.writeOpenNamespace(DeviceInfo.NAME_SPACE, "Namespace enclosing USBDM classes");
writer.openUsbdmDocumentationGroup();
writePortInfo(writer);
writer.write("/** Class to static check signal mapping is valid */\n" + "template<class Info, int signalNum> class CheckSignal {\n" + "#ifdef DEBUG_BUILD\n" + " static_assert((signalNum<Info::numSignals), \"Non-existent signal - Modify Configure.usbdm\");\n" + " static_assert((signalNum>=Info::numSignals)||(Info::info[signalNum].gpioBit != UNMAPPED_PCR), \"Signal is not mapped to a pin - Modify Configure.usbdm\");\n" + " static_assert((signalNum>=Info::numSignals)||(Info::info[signalNum].gpioBit != INVALID_PCR), \"Signal doesn't exist in this device/package\");\n" + " static_assert((signalNum>=Info::numSignals)||((Info::info[signalNum].gpioBit == UNMAPPED_PCR)||(Info::info[signalNum].gpioBit == INVALID_PCR)||(Info::info[signalNum].gpioBit >= 0)), \"Illegal signal\");\n" + "#endif\n" + "};\n\n");
fDeviceInfo.writeNamespaceInfo(writer);
writer.writeBanner("Peripheral Information Classes");
DocumentationGroups groups = new DocumentationGroups(writer);
// Write these classes in order as they declare shared information etc.
ArrayList<String> priorityClasses = new ArrayList<String>();
priorityClasses.add("OSC");
priorityClasses.add("OSC0");
priorityClasses.add("OSC_RF0");
priorityClasses.add("RTC");
priorityClasses.add("MCG");
priorityClasses.add("SIM");
for (String key : priorityClasses) {
Peripheral peripheral = fDeviceInfo.getPeripherals().get(key);
if (peripheral != null) {
writePeripheralInformationClass(writer, groups, peripheral);
}
}
for (String key : fDeviceInfo.getPeripherals().keySet()) {
if (priorityClasses.contains(key)) {
continue;
}
writePeripheralInformationClass(writer, groups, fDeviceInfo.getPeripherals().get(key));
}
groups.closeGroup();
writer.closeDocumentationGroup();
writer.writeCloseNamespace();
writer.write("\n");
writer.flush();
}
use of net.sourceforge.usbdm.deviceEditor.information.Peripheral in project usbdm-eclipse-plugins by podonoghue.
the class ParseFamilyXML method parsePeripheral.
private void parsePeripheral(Element peripheralElement) throws Exception {
String baseName = peripheralElement.getAttribute("baseName");
String instance = peripheralElement.getAttribute("instance");
String version = peripheralElement.getAttribute("version");
Peripheral peripheral = null;
for (Node node = peripheralElement.getFirstChild(); node != null; node = node.getNextSibling()) {
if (node.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Element element = (Element) node;
if (element.getTagName() == "handler") {
if (peripheral != null) {
throw new Exception("Peripheral already created");
}
peripheral = fDeviceInfo.createPeripheral(baseName, instance, element.getAttribute("class"), element.getAttribute("parameters"));
} else if (element.getTagName() == "clock") {
if (peripheral == null) {
peripheral = fDeviceInfo.createPeripheral(baseName, instance);
}
peripheral.setClockInfo(element.getAttribute("reg"), element.getAttribute("mask"));
} else if (element.getTagName() == "irq") {
peripheral.addIrqNum(element.getAttribute("num"));
} else if (element.getTagName() == "dma") {
peripheral.addDmaChannel(getIntAttribute(element, "num"), element.getAttribute("source"));
} else if (element.getTagName() == "param") {
String key = element.getAttribute("key");
String value = element.getAttribute("value");
PeripheralWithState p = (PeripheralWithState) peripheral;
StringVariable v = new StringVariable(key, p.makeKey(key));
p.addVariable(v);
v.setValue(value);
p.addParam(p.makeKey(key), value);
} else {
throw new Exception("Unexpected field in PERIPHERAL, value = \'" + element.getTagName() + "\'");
}
}
peripheral.setVersion(version);
}
Aggregations