git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4537 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2012-08-06 14:57:48 +00:00
parent 52dc533877
commit a072b394a2
13 changed files with 175 additions and 253 deletions

View File

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: ChibiOS-RT_Configuration_Support
Bundle-SymbolicName: org.chibios.tools.eclipse.config;singleton:=true
Bundle-Version: 1.0.4
Bundle-Version: 1.1.0
Bundle-Activator: config_wizard.Activator
Require-Bundle: org.eclipse.core.resources,
org.eclipse.core.runtime,

View File

@ -32,4 +32,5 @@ bin.includes = plugin.xml,\
resources/gencfg/processors/boards/stm32l1xx/templates/board.h.ftl,\
resources/gencfg/processors/boards/stm32l1xx/templates/board.mk.ftl,\
resources/gencfg/schema/boards/stm32l1xx_board.xsd,\
resources/gencfg/xml/stm32l1board.xml
resources/gencfg/xml/stm32l1board.xml,\
resources/gencfg/schema/common/config_settings.xsd

View File

@ -17,14 +17,29 @@
</wizard>
</extension>
<!-- Registers the file extension .chxml as an XML type. -->
<!-- Registers the file extension .chcfg as an XML type. -->
<extension point="org.eclipse.core.contenttype.contentTypes">
<file-association
content-type="org.eclipse.core.runtime.xml"
file-extensions="chxml">
file-extensions="chcfg">
</file-association>
</extension>
<!-- XML catalog extensions. -->
<extension point="org.eclipse.wst.xml.core.catalogContributions">
<catalogContribution id="default">
<uri
name="http://www.chibios.org/xml/schema/boards/stm32f0xx_board.xsd"
uri="resources/gencfg/schema/boards/stm32f0xx_board.xsd" />
<uri
name="http://www.chibios.org/xml/schema/boards/stm32f4xx_board.xsd"
uri="resources/gencfg/schema/boards/stm32f4xx_board.xsd" />
<uri
name="http://www.chibios.org/xml/schema/boards/stm32l1xx_board.xsd"
uri="resources/gencfg/schema/boards/stm32l1xx_board.xsd" />
</catalogContribution>
</extension>
<!-- Commands. -->
<extension
point="org.eclipse.ui.commands">

View File

@ -3,10 +3,12 @@
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="../common/doc.xsd" />
<xs:include schemaLocation="../common/config_settings.xsd" />
<xs:complexType name="AbstractBoardType" abstract="true">
<xs:sequence>
<xs:element name="board_name" maxOccurs="1" minOccurs="1">
<xs:element name="configuration_settings" type="ConfigurationSettingsType" maxOccurs="1" minOccurs="1"></xs:element>
<xs:element name="board_name" maxOccurs="1" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="collapse"></xs:whiteSpace>
@ -21,25 +23,36 @@
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="board_functions" maxOccurs="1" minOccurs="1">
<xs:element name="board_functions" maxOccurs="1"
minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="__early_init" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
<xs:element name="boardInit" type="xs:string" maxOccurs="1" minOccurs="0">
</xs:element>
<xs:element name="sdc_lld_is_card_inserted" type="xs:string" maxOccurs="1" minOccurs="0">
<xs:element name="__early_init" type="xs:string"
maxOccurs="1" minOccurs="0">
</xs:element>
<xs:element name="sdc_lld_is_write_protected" type="xs:string" maxOccurs="1" minOccurs="0">
<xs:element name="boardInit" type="xs:string"
maxOccurs="1" minOccurs="0">
</xs:element>
<xs:element name="mmc_lld_is_card_inserted" type="xs:string" maxOccurs="1" minOccurs="0">
<xs:element name="sdc_lld_is_card_inserted"
type="xs:string" maxOccurs="1" minOccurs="0">
</xs:element>
<xs:element name="mmc_lld_is_write_protected" type="xs:string" maxOccurs="1" minOccurs="0">
<xs:element name="sdc_lld_is_write_protected"
type="xs:string" maxOccurs="1" minOccurs="0">
</xs:element>
<xs:element name="mmc_lld_is_card_inserted"
type="xs:string" maxOccurs="1" minOccurs="0">
</xs:element>
<xs:element name="mmc_lld_is_write_protected"
type="xs:string" maxOccurs="1" minOccurs="0">
</xs:element>
</xs:sequence>
</xs:complexType></xs:element>
<xs:element name="ethernet_phy" type="EthernetPHYType"
</xs:complexType>
</xs:element>
<xs:element name="ethernet_phy" type="EthernetPHYType"
maxOccurs="1" minOccurs="0">
</xs:element>
</xs:element>
</xs:sequence>
</xs:complexType>

View File

@ -1,63 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="../common/doc.xsd" />
<xs:include schemaLocation="../common/stm32/stm32_gpiov2_port.xsd" />
<xs:include schemaLocation="abstract_board.xsd" />
<xs:include schemaLocation="../common/doc.xsd" />
<xs:include schemaLocation="../common/stm32/stm32_gpiov2_port.xsd" />
<xs:include schemaLocation="abstract_board.xsd" />
<xs:complexType name="STM32F4xxBoardType">
<xs:complexContent>
<xs:extension base="AbstractBoardType">
<xs:sequence>
<xs:element name="clocks" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:attribute name="HSEBypass" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="collapse"></xs:whiteSpace>
<xs:enumeration value="false"></xs:enumeration>
<xs:enumeration value="true"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="HSEFrequency"
use="required">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:whiteSpace value="collapse"></xs:whiteSpace>
<xs:minInclusive value="0"></xs:minInclusive>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="LSEFrequency"
use="required">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:whiteSpace value="collapse"></xs:whiteSpace>
<xs:complexType name="STM32F4xxBoardType">
<xs:complexContent>
<xs:extension base="AbstractBoardType">
<xs:sequence>
<xs:element name="clocks" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:attribute name="HSEBypass" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="collapse"></xs:whiteSpace>
<xs:enumeration value="false"></xs:enumeration>
<xs:enumeration value="true"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="HSEFrequency" use="required">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:whiteSpace value="collapse"></xs:whiteSpace>
<xs:minInclusive value="0"></xs:minInclusive>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="LSEFrequency" use="required">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:whiteSpace value="collapse"></xs:whiteSpace>
<xs:minInclusive value="0"></xs:minInclusive>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="VDD" use="required">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:whiteSpace value="collapse"></xs:whiteSpace>
<xs:minInclusive value="0"></xs:minInclusive>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="VDD" use="required">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:whiteSpace value="collapse"></xs:whiteSpace>
<xs:minInclusive value="180"></xs:minInclusive>
<xs:minInclusive value="180"></xs:minInclusive>
<xs:maxInclusive value="360"></xs:maxInclusive>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType></xs:element>
<xs:element name="ports" type="portsType" maxOccurs="1"
minOccurs="1">
</xs:element>
</xs:sequence>
<xs:maxInclusive value="360"></xs:maxInclusive>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="ports" type="portsType" maxOccurs="1" minOccurs="1">
</xs:element>
</xs:sequence>
</xs:extension>
</xs:extension>
</xs:complexContent>
</xs:complexType>

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="ConfigurationSettingsType">
<xs:sequence>
<xs:element name="templates_path" minOccurs="1"
maxOccurs="1">
<xs:annotation>
<xs:documentation>Templates resources associated to the configuration.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"></xs:minLength>
<xs:whiteSpace value="collapse"></xs:whiteSpace>
<xs:pattern value="[\w\d_/.]+"></xs:pattern>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="output_path" maxOccurs="1"
minOccurs="1">
<xs:annotation>
<xs:documentation>Output directory relative to the configuration file.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"></xs:minLength>
<xs:whiteSpace value="collapse"></xs:whiteSpace>
<xs:pattern value="[\w\d_/.]+"></xs:pattern>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>

View File

@ -3,6 +3,10 @@
<board
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.chibios.org/xml/schema/boards/stm32f0xx_board.xsd">
<configuration_settings>
<templates_path>resources/gencfg/processors/boards/stm32f0xx/templates</templates_path>
<output_path>.</output_path>
</configuration_settings>
<board_name>-----human readable board name-----</board_name>
<board_id>BOARD_IDENTIFIER</board_id>
<board_functions></board_functions>

View File

@ -3,6 +3,10 @@
<board
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.chibios.org/xml/schema/boards/stm32f4xx_board.xsd">
<configuration_settings>
<templates_path>resources/gencfg/processors/boards/stm32f4xx/templates</templates_path>
<output_path>.</output_path>
</configuration_settings>
<board_name>-----human readable board name-----</board_name>
<board_id>BOARD_IDENTIFIER</board_id>
<board_functions></board_functions>

View File

@ -3,6 +3,10 @@
<board
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.chibios.org/xml/schema/boards/stm32l1xx_board.xsd">
<configuration_settings>
<templates_path>resources/gencfg/processors/boards/stm32l1xx/templates</templates_path>
<output_path>.</output_path>
</configuration_settings>
<board_name>-----human readable board name-----</board_name>
<board_id>BOARD_IDENTIFIER</board_id>
<board_functions></board_functions>

View File

@ -21,9 +21,7 @@
package org.chibios.tools.eclipse.config.handlers;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import org.chibios.tools.eclipse.config.utils.TemplateEngine;
import org.chibios.tools.eclipse.config.utils.TemplateException;
@ -40,6 +38,10 @@ import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.osgi.framework.Bundle;
import config_wizard.Activator;
@ -70,53 +72,32 @@ public class GenerateFiles extends AbstractHandler {
if (selection instanceof IStructuredSelection) {
/* Retrieves the full path of the configuration file. */
IPath cfgfilepath = ((IFile) ((IStructuredSelection) selection)
IPath cfgfilepath = ((IFile)((IStructuredSelection)selection)
.getFirstElement()).getLocation();
/* Determines the base path as the parent of the configuration file.*/
IPath basepath = cfgfilepath.removeLastSegments(1);
/* Reads the configuration file into a Properties object. */
Properties cfgfile = new Properties();
/* DOM tree creation. */
SAXBuilder builder = new SAXBuilder();
Document document;
try {
cfgfile.load(new FileReader(cfgfilepath.toFile()));
document = builder.build(cfgfilepath.toFile());
} catch (JDOMException e) {
return null;
} catch (IOException e) {
MessageDialog.openInformation(window.getShell(), "I/O Error",
e.getMessage());
return null;
}
/* Retrieves source property. */
String source = cfgfile.getProperty("source");
if (source == null) {
MessageDialog.openInformation(window.getShell(), "Properties Error",
"Property \"source\" not found in configuration file.");
return null;
}
/* Retrieves xmlfile property. */
String xmlfile = cfgfile.getProperty("xmlfile");
if (xmlfile == null) {
MessageDialog.openInformation(window.getShell(), "Properties Error",
"Property \"xmlfile\" not found in configuration file.");
return null;
}
/* Retrieves output property. */
String output = cfgfile.getProperty("output");
if (output == null) {
MessageDialog.openInformation(window.getShell(), "Properties Error",
"Property \"output\" not found in configuration file.");
return null;
}
/* Retrieving configuration settings info.*/
Element settings = document.getRootElement().getChild("configuration_settings");
String templates_path = settings.getChildText("templates_path");
String output_path = settings.getChildText("output_path");
/* Calculating derived paths. */
IPath sourcepath = new Path(source);
IPath tpath = new Path(templates_path);
IPath libpath = new Path("resources/gencfg/lib");
try {
Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
sourcepath = new Path(FileLocator.toFileURL(
FileLocator.find(bundle, sourcepath, null)).getFile());
tpath = new Path(FileLocator.toFileURL(
FileLocator.find(bundle, tpath, null)).getFile());
libpath = new Path(FileLocator.toFileURL(
FileLocator.find(bundle, libpath, null)).getFile());
} catch (IOException e) {
@ -127,9 +108,10 @@ public class GenerateFiles extends AbstractHandler {
/* Templates execution. */
try {
TemplateEngine.process(basepath.addTrailingSeparator().append(xmlfile)
.toFile(), libpath.toFile(), sourcepath.toFile(),
basepath.toFile(), new File(output));
TemplateEngine.process(cfgfilepath.toFile(),
libpath.toFile(),
tpath.toFile(),
new File(output_path));
} catch (TemplateException e) {
MessageDialog.openInformation(window.getShell(), "Processing Error",
e.getMessage());

View File

@ -80,16 +80,15 @@ public class TemplateEngine {
* absolute path to libraries directory
* @param sourcedir
* absolute path to templates directory
* @param basedir
* absolute path to project directory
* @param outputdir
* output directory relative to basedir
* output directory relative to xmldata
*
* @throws SettingException
* @throws ProcessingException
*/
public static void process(java.io.File xmldata, java.io.File libdir,
java.io.File sourcedir, java.io.File basedir,
public static void process(java.io.File xmldata,
java.io.File libdir,
java.io.File sourcedir,
java.io.File outputdir) throws TemplateException {
/* Finds or creates a named console. */
@ -110,7 +109,7 @@ public class TemplateEngine {
* events to be logged.
*/
try {
settings = new Settings(basedir);
settings = new Settings(xmldata.getParentFile());
} catch (SettingException e) {
e.printStackTrace();
return;

View File

@ -54,9 +54,6 @@ public class ConfigurationNewWizard extends Wizard implements INewWizard {
private String containerName;
private String projectFileName;
private String dataFileName;
private String templatesPath;
private String outputDirName;
private String defaultDataFile;
/**
@ -91,9 +88,6 @@ public class ConfigurationNewWizard extends Wizard implements INewWizard {
containerName = page.getContainerName();
projectFileName = page.getProjectFileName();
dataFileName = page.getDataFileName();
templatesPath = page.getTemplatesPath();
outputDirName = page.getOutputDirName();
defaultDataFile = page.getDefaultDataFile();
IRunnableWithProgress op = new IRunnableWithProgress() {
@ -133,36 +127,20 @@ public class ConfigurationNewWizard extends Wizard implements INewWizard {
throwCoreException("Container \"" + containerName + "\" does not exist.");
}
IContainer container = (IContainer)resource;
monitor.beginTask("Creating " + projectFileName, 4);
monitor.beginTask("Creating " + projectFileName, 3);
/* Step #1, creates the project file.*/
final IFile projectFile = container.getFile(new Path(projectFileName));
try {
InputStream stream = openProjectContentStream(templatesPath,
dataFileName,
outputDirName);
if (projectFile.exists()) {
projectFile.setContents(stream, true, true, monitor);
} else {
projectFile.create(stream, true, monitor);
}
stream.close();
} catch (IOException e) {
}
monitor.worked(1);
/* Step #2, creates the XML data file.*/
final IFile dataFile = container.getFile(new Path(dataFileName));
Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
IPath path = new Path(defaultDataFile);
String s;
try {
s = FileLocator.toFileURL(FileLocator.find(bundle, path, null)).getFile();
InputStream stream = new FileInputStream(s);
if (dataFile.exists()) {
dataFile.setContents(stream, true, true, monitor);
if (projectFile.exists()) {
projectFile.setContents(stream, true, true, monitor);
} else {
dataFile.create(stream, true, monitor);
projectFile.create(stream, true, monitor);
}
stream.close();
} catch (IOException e) {
@ -183,29 +161,11 @@ public class ConfigurationNewWizard extends Wizard implements INewWizard {
});
monitor.worked(1);
/* Step #4, refreshing local resources.*/
/* Step #3, refreshing local resources.*/
container.refreshLocal(IResource.DEPTH_INFINITE, monitor);
monitor.worked(1);
}
/**
* We will initialize file contents with a sample text.
*/
private InputStream openProjectContentStream(String templatesPath,
String dataFileName,
String outputDirName) {
String contents = "# Automatically generated configuration project file.\n\n" +
"# Templates path in the configuration plugin resources, do not modify.\n" +
"source=" + templatesPath + "\n\n" +
"# XML configuration data file path relative to this configuration file.\n" +
"xmlfile=" + dataFileName + "\n\n" +
"# Output directory path relative to directory containing this configuration\n" +
"# file.\n" +
"output=" + outputDirName + "\n";
return new ByteArrayInputStream(contents.getBytes());
}
private void throwCoreException(String message) throws CoreException {
IStatus status = new Status(IStatus.ERROR,
"org.chibios.tools.eclipse.config", IStatus.OK,

View File

@ -24,8 +24,6 @@ import java.io.IOException;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@ -65,14 +63,11 @@ public class ConfigurationNewWizardPage extends WizardPage {
private IContainer resourceContainer;
private Document processorsDocument;
private String currentTemplatesPath;
private String currentDefaultDataFile;
private Composite container;
private Combo configurationTemplatesCombo;
private Text confProjectFilenameText;
private Text confDataFilenameText;
private Text confOutputDirectoryText;
/**
* Constructor for SampleNewWizardPage.
@ -118,43 +113,15 @@ public class ConfigurationNewWizardPage extends WizardPage {
}
});
Label lbl3 = new Label(container, SWT.NONE);
lbl3.setText("Configuration data filename:");
confDataFilenameText = new Text(container, SWT.BORDER);
confDataFilenameText.setText("config.chxml");
confDataFilenameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
false, 1, 1));
confDataFilenameText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
confDataFilenameUpdated();
}
});
Label lbl4 = new Label(container, SWT.NONE);
lbl4.setText("Configuration output directory:");
confOutputDirectoryText = new Text(container, SWT.BORDER);
confOutputDirectoryText.setText(".");
confOutputDirectoryText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
true, false, 1, 1));
/* Note, it must stay after the creation of the text fields. */
configurationTemplatesCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
Element processor = getSelectedTemplate();
String basefilename = processor.getChildText("basefilename");
confProjectFilenameText.setText(basefilename.concat(".chcfg"));
confDataFilenameText.setText(basefilename.concat(".chxml"));
currentTemplatesPath = processor.getChildText("path");
currentDefaultDataFile = processor.getChildText("default");
}
});
confOutputDirectoryText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
confOutputDirectoryUpdated();
}
});
populateWizardPanel();
initialize();
@ -171,21 +138,6 @@ public class ConfigurationNewWizardPage extends WizardPage {
return confProjectFilenameText.getText();
}
public String getDataFileName() {
return confDataFilenameText.getText();
}
public String getOutputDirName() {
return confOutputDirectoryText.getText();
}
public String getTemplatesPath() {
return currentTemplatesPath;
}
public String getDefaultDataFile() {
return currentDefaultDataFile;
@ -291,52 +243,6 @@ public class ConfigurationNewWizardPage extends WizardPage {
updateStatus(null);
}
/**
* Checks the content of the confProjectFilenameText field.
*/
private void confDataFilenameUpdated() {
String fileName = getDataFileName();
if (fileName.length() == 0) {
updateStatus("File name must be specified");
return;
}
if (fileName.replace('\\', '/').indexOf('/', 1) > 0) {
updateStatus("File name must be valid");
return;
}
int dotLoc = fileName.lastIndexOf('.');
if (dotLoc != -1) {
String ext = fileName.substring(dotLoc + 1);
if (ext.equalsIgnoreCase("chxml") == false) {
updateStatus("Configuration project filename extension must be \"chxml\"");
return;
}
}
updateStatus(null);
}
/**
* Checks the content of the confOutputDirectoryText field.
*/
private void confOutputDirectoryUpdated() {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IPath outputPath = resourceContainer.getFullPath().addTrailingSeparator()
.append(getOutputDirName());
IResource outputContainer = root.findMember(outputPath);
if (outputContainer == null) {
updateStatus("The directory must exists");
return;
}
if (!(outputContainer instanceof IContainer)) {
updateStatus("A directory must be specified");
return;
}
updateStatus(null);
}
/**
* Returns the XML Element associated to the current selection in the combo
* box.