<memory name="ChannelEnable" address="0002" size="2">
<description>Enable signals/hits of the specific channel. LSB is
channel 1.</description>
- <field name="Enable" start="0" size="64" format="bitmask" />
+ <field name="ChannelEnable" start="0" size="64" format="bitmask" />
</memory>
<register name="DataTransferLimit" address="0004">
Complex Elements
==============================-->
- <xs:complexType name="grouptype">
- <xs:sequence>
- <!-- a group does not necessarily need a description -->
- <xs:choice minOccurs="0">
- <xs:element ref="description"/>
- </xs:choice>
- </xs:sequence>
- <xs:attribute ref="name" use="required" />
- <xs:attribute ref="address" />
- <xs:attribute ref="size" />
- <xs:attribute ref="purpose" />
- <xs:attribute ref="continuous" />
- <xs:attribute ref="mode" />
- <xs:attribute ref="format" />
- <xs:attribute ref="repeat" />
- </xs:complexType>
<xs:element name="enumItem">
</xs:complexType>
</xs:element>
- <xs:element name="field">
- <!-- we define this as mixed to provide values to be written (or
+
+<!-- we define this as mixed to provide values to be written (or
extracted from it). It will be converted to hex (or binary)
according to format attribute -->
- <xs:complexType mixed="true">
+ <xs:complexType name="fieldtype" mixed="true">
<xs:sequence>
<!-- description can be omitted if a register or alike only contains
one or several identical fields and the description of them can
</xs:sequence>
<xs:attribute ref="name" use="required" />
- <xs:attribute ref="start" use="required" />
+ <!-- start is defined in TrbNetEntity -->
<xs:attribute ref="size" />
<xs:attribute ref="purpose" />
<xs:attribute ref="mode" />
an error is indicated by this field -->
<xs:attribute ref="errorflag" />
</xs:complexType>
+
+
+ <xs:element name="field" type="fieldtype">
+
+
<xs:unique name="UniqueEnumItems">
<xs:selector xpath="enumItem" />
<xs:field xpath="@value" />
</xs:unique>
</xs:element>
-
<xs:complexType name="basicTrbData">
- <xs:sequence>
- <!-- every TrbData must be described -->
- <xs:choice>
- <xs:element ref="description"/>
- </xs:choice>
- <!-- but a data without any fields does not make sense for this
- database, so the default minOccurs=1 is used -->
- <xs:choice maxOccurs="unbounded">
- <xs:element ref="field" />
- </xs:choice>
- </xs:sequence>
+
<xs:attribute ref="name" use="required" />
- <xs:attribute ref="address" use="required" />
+ <!-- start is defined in TrbNetEntity as required attribute -->
<xs:attribute ref="mode" />
<xs:attribute ref="purpose" />
</xs:complexType>
they are collected in a common scheme -->
<xs:include schemaLocation="TrbNetCommon.xsd"/>
+ <!-- the next two extensions introduce required attributes and also
+ requires the description and fields *inside* registers -->
+ <xs:redefine schemaLocation="TrbNetCommon.xsd">
+ <xs:complexType name="basicTrbData">
+ <xs:complexContent>
+ <xs:extension base="basicTrbData">
+ <xs:sequence>
+ <!-- every TrbData must be described -->
+ <xs:choice>
+ <xs:element ref="description"/>
+ </xs:choice>
+ <!-- but a data without any fields does not make sense for this
+ database, so the default minOccurs=1 is used -->
+ <xs:choice maxOccurs="unbounded">
+ <xs:element ref="field" />
+ </xs:choice>
+ </xs:sequence>
+ <xs:attribute ref="address" use="required"/>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+ </xs:redefine>
+
+ <xs:redefine schemaLocation="TrbNetCommon.xsd">
+ <xs:complexType name="fieldtype">
+ <xs:complexContent>
+ <xs:extension base="fieldtype">
+ <xs:attribute ref="start" use="required"/>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+ </xs:redefine>
+
<xs:element name="TrbNetEntity">
<xs:complexType>
<xs:sequence>
</xs:choice>
<!-- may also contain groups -->
<xs:choice maxOccurs="unbounded">
- <xs:element ref="group" maxOccurs="unbounded" />
- <xs:element ref="register" maxOccurs="unbounded" />
- <xs:element ref="memory" maxOccurs="unbounded" />
- <xs:element ref="fifo" maxOccurs="unbounded" />
+ <xs:element ref="group" />
+ <xs:element ref="register" />
+ <xs:element ref="memory" />
+ <xs:element ref="fifo" />
</xs:choice>
</xs:sequence>
<xs:attribute ref="name" use="required" />
<xs:attribute ref="address" />
</xs:complexType>
-
+
<!-- although requiring "entity global" unique names usually leads
to redundant naming schemes, its makes minor modifications to
- entities very easy to specify (which is desirable in setup files) -->
+ entities very easy to specify (which is desirable in setup files) -->
<xs:unique name="UniqueFieldNames">
<xs:selector xpath=".//field" />
<xs:field xpath="@name" />
<xs:selector xpath=".//group" />
<xs:field xpath="@name" />
</xs:unique>
-
+
<!-- consistency of addresses (and start, size of fields) is
checked more precisely programmatically -->
<xs:unique name="UniqueTrbDataAddressesInTop">
<xs:element name="group">
<xs:complexType>
- <xs:complexContent>
- <xs:extension base="grouptype">
- <!-- groups in a TrbNetEntity may consist of other groups
- and "TrbData" describing things -->
- <xs:choice maxOccurs="unbounded">
- <xs:element ref="group" maxOccurs="unbounded" />
- <xs:element ref="register" maxOccurs="unbounded" />
- <xs:element ref="memory" maxOccurs="unbounded" />
- <xs:element ref="fifo" maxOccurs="unbounded" />
- </xs:choice>
- </xs:extension>
- </xs:complexContent>
+ <xs:sequence>
+ <!-- a group does not necessarily need a description -->
+ <xs:choice minOccurs="0">
+ <xs:element ref="description"/>
+ </xs:choice>
+ <xs:choice maxOccurs="unbounded">
+ <xs:element ref="group" maxOccurs="unbounded" />
+ <xs:element ref="register" maxOccurs="unbounded" />
+ <xs:element ref="memory" maxOccurs="unbounded" />
+ <xs:element ref="fifo" maxOccurs="unbounded" />
+ </xs:choice>
+ </xs:sequence>
+ <xs:attribute ref="name" use="required" />
+ <xs:attribute ref="address" />
+ <xs:attribute ref="size" />
+ <xs:attribute ref="purpose" />
+ <xs:attribute ref="continuous" />
+ <xs:attribute ref="mode" />
+ <xs:attribute ref="format" />
+ <xs:attribute ref="repeat" />
+
</xs:complexType>
<!-- consistency of addresses (and start, size of fields) is
checked more precisely programmatically -->
<xs:selector xpath="register | memory | fifo" />
<xs:field xpath="@address" />
</xs:unique>
- </xs:element>
+ </xs:element>
</xs:schema>
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="TrbNetCommon.xsd"/>
+
+ <xs:element name="TrbNetSetup">
+ <xs:complexType>
+ <xs:sequence>
+ <!-- must contain either a uid map to setup the network
+ initially, or a trb directive -->
+ <xs:choice>
+ <xs:element ref="uidMap"/>
+ <xs:element ref="trb"/>
+ </xs:choice>
+ <!-- may contain even more trb directives -->
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
+ <xs:element ref="trb" />
+ </xs:choice>
+ </xs:sequence>
+ <xs:attribute name="creator" type="xs:string" use="required" />
+ <xs:attribute name="date" type="xs:dateTime" use="required" />
+ <xs:attribute name="version" type="xs:string" use="required" />
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="trb">
+
+ </xs:element>
+
+ <xs:element name="uidMap">
+
+ </xs:element>
+
</xs:schema>
+++ /dev/null
-<?xml version="1.0" encoding="utf-8" ?>
-<TrbNetEntity xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:noNamespaceSchemaLocation="TrbNetEntity.xsd"
- name="JtagController"
- address="1000"
- >
- <description>Just some testing</description>
- <group
- name="JtagCommonControl"
- address="0000"
- size="21"
- purpose="config"
- continuous="true"
- >
-
- <register
- name="WaitBeforeStart"
- address="0007"
- mode="rw"
- purpose ="config"
- >
- <description>Wait time between write sequence and start signal.</description>
- <field
- name="WaitBeforeStart"
- start="0"
- size="20">
- <description>The number of MAPS clock cycles to wait after last write before sending the start signal. </description>
- </field>
- </register>
- </group>
-</TrbNetEntity>
--- /dev/null
+<?xml version="1.0" encoding="utf-8" ?>
+<TrbNetSetup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="TrbNetSetup.xsd"
+ creator="Andreas Neiser"
+ date="2013-06-30T16:11:56"
+ version="0.1"
+ >
+ <!-- The order of the trb elements is respected and their content is
+ evaluated after each one (if they specify a value). This is important if the resulting
+ changes to the TrbNet must happen in a certain way. -->
+
+ <!-- also note the different uses of the address attribute:
+ sometimes it's a register address, sometimes a trbnet endpoint
+ address, or sometimes it specifies the chain number of the
+ external PaDiWa frontend -->
+
+
+ <!-- this specifies the trbaddress from uid's, it can be omitted if
+ the TrbNet is already set-up -->
+ <uidMap>
+ <uid address="0200" endpoint="0">5900000337e29728</uid>
+ <uid address="0201" endpoint="1">cf00000337e29e28</uid>
+ <uid address="0202" endpoint="2">ad00000338175028</uid>
+ <uid address="0203" endpoint="3">0e00000338174b28</uid>
+ <uid address="8000" endpoint="5">4400000338174628</uid>
+ </uidMap>
+
+ <!-- we configure the trb endpoint with address 0x8000 -->
+ <trb address="8000">
+ <entity type="TrbNet" />
+
+ <!-- it has a TDC (at default register address) -->
+ <entity type="TDC">
+ <!-- this way we modify the number of channels to 5. This works
+ since group/register/memory/fifo have unique names. It
+ might be that there are several places where one should
+ change the "repeat", but how does one know? -->
+ <register name="Channel" repeat="5" />
+ </entity>
+
+ <!-- and it has a CTS -->
+ <entity type="CTS" />
+ </trb>
+
+
+ <trb address="0200">
+ <!-- Standard TrbNet enpoint with standard 65ch TDC... -->
+ <entity type="TrbNet" />
+ <entity type="TDC" />
+ <!-- ...but also some "external" PaDiWa frontends connected at
+ chain 0 and 2. The fronend has some more registers which can
+ be accessed via SPI. The idea is that there's also a
+ PaDiWa.pm in the database which handles this access, usually
+ via conventional TrbNet registers
+ -->
+ <external type="PaDiWa" address="0000" />
+ <external type="PaDiWa" address="0002" />
+ </trb>
+
+
+ <!-- An example how to execute a setting. In general, the entities
+ are identified by their type and address (if specified) -->
+ <trb address="0200">
+ <entity type="TDC">
+ <!-- this field is a bitmask, so there's a converter to easily set single bits -->
+ <field name="ChannelEnable">
+ 0-15 => 1, <!-- enables channels 0-15 -->
+ 34 => 1, <!-- enables channel 34 -->
+ </field>
+ </entity>
+ </trb>
+
+
+
+
+
+</TrbNetSetup>
'help|h' => \$help,
'man' => \$man,
'verbose|v+' => \$verbose,
- 'db-dir=s' => \$db_dir
+ 'db-dir=s' => \$db_dir
) or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-exitval => 0, -verbose => 2) if $man;
# tell something about the configuration
-if($verbose) {
+if ($verbose) {
print "Database directory: $db_dir\n";
}
&Main;
sub Main {
- # load the unmerged database
- my $db = &LoadDB;
- # load the topology
- DoSomethingWithDb($db);
+ # load the unmerged database and the provided files
+ my ($db,$files) = &LoadDBAndFiles;
+
+
+ # testing...
+ #DumpDatabase($db);
+}
+
+sub LoadFile() {
+ my $schema = XML::LibXML::Schema->new(location => "$db_dir/TrbNetSetup.xsd");
+
+
}
-sub DoSomethingWithDb($) {
+sub DumpDatabase($) {
my $db = shift;
+ foreach my $file (keys %$db) {
+ print "Dumping $file...\n";
+ DumpDatabaseFile($db->{$file});
+ }
+}
- my $doc = $db->{'TDC.xml'};
+sub DumpDatabaseFile($) {
+ my $doc = shift;
#my $doc = $db->{'testing.xml'};
#my $doc = $db->{'jtag_registers_SPEC.xml'};
#print Dumper($doc->findnodes('TrbNet')->toDebuggingHash);
my $address = $baseaddress+hex($curNode->getAttribute('address'));
#printf("%s %04x\n\n",$name,$address);
foreach my $field ($curNode->findnodes('field')) {
-
printf("%04x:%02d:%02d %s/%s\n", $address,
- $field->getAttribute('start'),
- $field->getAttribute('size') || 1,
- $name, $field->getAttribute('name'));
+ $field->getAttribute('start'),
+ $field->getAttribute('size') || 1,
+ $name, $field->getAttribute('name'));
#print $field->getAttribute('errorflag') || 'false',"\n";
}
}
}
}
-sub GetBaseNameAndAddress($) {
- my $node = shift;
-
- #return ($baseName, $baseAddress);
-}
-sub LoadDB {
- # change to he db_dir here in this subroutine
- local $CWD = $db_dir;
+sub LoadDBAndFiles {
+ my $schemas = {};
+ my $db = {};
+ my $parser = XML::LibXML->new(line_numbers => 1);
+
+ {
+ # change to the db_dir in the first part
+ local $CWD = $db_dir;
- # we first load the schemas and parse them
- # so we can validate the XML files
- my %schemas = ();
- while(<*.xsd>) {
- $schemas{$_} = XML::LibXML::Schema->new(location => $_);
- print "Loaded schema <$_>\n" if $verbose;
+
+ # we first load the schemas and parse them
+ # so we can validate the XML files
+ while (<*.xsd>) {
+ $schemas->{$_} = XML::LibXML::Schema->new(location => $_);
+ print "Loaded schema <$_> from database\n" if $verbose;
+ }
+
+ # load the xml files in the database
+ while (<*.xml>) {
+ my $doc = $parser->parse_file($_);
+ ValidateXML($doc, $schemas);
+ $db->{$_} = $doc;
+ print "Loaded and validated <$_> from database\n" if $verbose;
+ }
}
- # load the xml files
- my $parser = XML::LibXML->new(line_numbers => 1);
- my $db = {};
- while(<*.xml>) {
+ # now, back in the normal working directoy, load and
+ # validate the provided files
+ my $files = {};
+ for (@ARGV) {
my $doc = $parser->parse_file($_);
- my $xsd_file = $doc->getDocumentElement->getAttribute('xsi:noNamespaceSchemaLocation');
- die "Schema $xsd_file not found to validate <$_>" unless defined $schemas{$xsd_file};
- $schemas{$xsd_file}->validate($doc);
- $db->{$_} = $doc;
+ ValidateXML($doc, $schemas);
+ $files->{$_} = $doc;
print "Loaded and validated <$_>\n" if $verbose;
}
- return $db;
-}
-
-
+ return ($db, $files);
+}
+sub ValidateXML($$) {
+ my $doc = shift;
+ my $schemas = shift;
+ my $xsd_file = $doc->getDocumentElement->getAttribute('xsi:noNamespaceSchemaLocation');
+ die "Schema $xsd_file not found to validate <$_>" unless defined $schemas->{$xsd_file};
+ $schemas->{$xsd_file}->validate($doc);
+}
#print $xsd;
=head1 SYNOPSIS
-xml-db.pl [options] [xml file]
+xml-db.pl [options] [xml file(s)]
Options:
-h, --help brief help message