Skip to content

Commit 02cf768

Browse files
author
Santosh Puranik
committed
Add API to find connections to a given target
1 parent 60c8e10 commit 02cf768

File tree

1 file changed

+133
-43
lines changed

1 file changed

+133
-43
lines changed

scripts/Targets.pm

+133-43
Original file line numberDiff line numberDiff line change
@@ -275,27 +275,29 @@ sub storeGroups
275275
## for accessing targets and busses
276276
## Structure:
277277
##
278-
##{TARGETS} # location of all targets
279-
##{NSTANCE_PATH} # keeps track of hierarchy
280-
## path while iterating
281-
##{TARGETS} -> target_name # specific target
282-
##{TARGETS} -> target_name -> {TARGET} # pointer to target data
283-
## from XML data struture
284-
##{TARGETS} -> target_name -> {TYPE}# special attribute
285-
##{TARGETS} -> target_name -> {PARENT} # parent target name
286-
##{TARGETS} -> target_name -> {CHILDREN} # array of children targets
287-
##{TARGETS} -> target_name -> {CONNECTION} -> {DEST} # array of connection
288-
## destination targets
289-
##{TARGETS} -> target_name -> {CONNECTION} -> {BUS} # array of busses
290-
##{TARGETS} -> target_name -> {CHILDREN} # array of children targets
291-
##{TARGETS} -> target_name -> {ATTRIBUTES} # attributes
292-
## {ENUMERATION} -> enumeration_type -> enum # value of enumeration
293-
## {BUSSES} -> bus_type[] # array of busses by
294-
## bus_type (I2C, FSI, etc)
295-
## {BUSSES} -> bus_type[] -> {BUS} # pointer to bus target
296-
## from xml structure
297-
## {BUSSES} -> bus_type[] -> {SOURCE_TARGET} # source target name
298-
## {BUSSES} -> bus_type[] -> {DEST_TARGET} # dest target name
278+
##{TARGETS} # location of all targets
279+
##{NSTANCE_PATH} # keeps track of hierarchy
280+
## path while iterating
281+
##{TARGETS} -> target_name # specific target
282+
##{TARGETS} -> target_name -> {TARGET} # pointer to target data
283+
## from XML data struture
284+
##{TARGETS} -> target_name -> {TYPE} # special attribute
285+
##{TARGETS} -> target_name -> {PARENT} # parent target name
286+
##{TARGETS} -> target_name -> {CHILDREN} # array of children targets
287+
##{TARGETS} -> target_name -> {CONNECTION} -> {DEST} # array of connection
288+
## destination targets
289+
##{TARGETS} -> target_name -> {CONNECTION} -> {SOURCE} # array of connection
290+
## source targets
291+
##{TARGETS} -> target_name -> {CONNECTION} -> {BUS} # array of busses
292+
##{TARGETS} -> target_name -> {CHILDREN} # array of children targets
293+
##{TARGETS} -> target_name -> {ATTRIBUTES} # attributes
294+
## {ENUMERATION} -> enumeration_type -> enum # value of enumeration
295+
## {BUSSES} -> bus_type[] # array of busses by
296+
## bus_type (I2C, FSI, etc)
297+
## {BUSSES} -> bus_type[] -> {BUS} # pointer to bus target
298+
## from xml structure
299+
## {BUSSES} -> bus_type[] -> {SOURCE_TARGET} # source target name
300+
## {BUSSES} -> bus_type[] -> {DEST_TARGET} # dest target name
299301

300302
sub buildHierarchy
301303
{
@@ -414,6 +416,13 @@ sub buildHierarchy
414416
},
415417
$dest_target
416418
);
419+
push(
420+
@{
421+
$self->{data}->{TARGETS}->{$dest_target}->{CONNECTION}
422+
->{SOURCE}
423+
},
424+
$source_target
425+
);
417426
push(
418427
@{
419428
$self->{data}->{TARGETS}->{$source_target}->{CONNECTION}
@@ -840,7 +849,8 @@ sub getTargetParent
840849
return $target_ptr->{PARENT};
841850
}
842851

843-
## returns the number of connections associated with target
852+
## returns the number of connections associated with target where the target is
853+
## the source
844854
sub getNumConnections
845855
{
846856
my $self = shift;
@@ -853,6 +863,20 @@ sub getNumConnections
853863
return scalar(@{ $target_ptr->{CONNECTION}->{DEST} });
854864
}
855865

866+
## returns the number of connections associated with target where the target is
867+
## the destination
868+
sub getNumDestConnections
869+
{
870+
my $self = shift;
871+
my $target = shift;
872+
my $target_ptr = $self->getTarget($target);
873+
if (!defined($target_ptr->{CONNECTION}->{SOURCE}))
874+
{
875+
return 0;
876+
}
877+
return scalar(@{ $target_ptr->{CONNECTION}->{SOURCE} });
878+
}
879+
856880
## returns destination target name of first connection
857881
## useful for point to point busses with only 1 endpoint
858882
sub getFirstConnectionDestination
@@ -880,6 +904,15 @@ sub getConnectionDestination
880904
my $target_ptr = $self->getTarget($target);
881905
return $target_ptr->{CONNECTION}->{DEST}->[$i];
882906
}
907+
## returns target name of $i source connection
908+
sub getConnectionSource
909+
{
910+
my $self = shift;
911+
my $target = shift;
912+
my $i = shift;
913+
my $target_ptr = $self->getTarget($target);
914+
return $target_ptr->{CONNECTION}->{SOURCE}->[$i];
915+
}
883916

884917
sub getConnectionBus
885918
{
@@ -921,13 +954,42 @@ sub findFirstEndpoint
921954
}
922955
return "";
923956
}
957+
958+
# Find connections _from_ $target (and it's children)
924959
sub findConnections
925960
{
926961
my $self = shift;
927962
my $target = shift;
928963
my $bus_type = shift;
929964
my $end_type = shift;
930965

966+
return $self->findConnectionsByDirection($target, $bus_type,
967+
$end_type, 0);
968+
}
969+
970+
# Find connections _to_ $target (and it's children)
971+
sub findDestConnections
972+
{
973+
my $self = shift;
974+
my $target = shift;
975+
my $bus_type = shift;
976+
my $source_type = shift;
977+
978+
return $self->findConnectionsByDirection($target, $bus_type,
979+
$source_type, 1);
980+
981+
}
982+
983+
# Find connections from/to $target (and it's children)
984+
# $to_this_target indicates the direction to find.
985+
sub findConnectionsByDirection
986+
{
987+
my $self = shift;
988+
my $target = shift;
989+
my $bus_type = shift;
990+
my $other_end_type = shift;
991+
my $to_this_target = shift;
992+
931993
my %connections;
932994
my $num=0;
933995
my $target_children = $self->getTargetChildren($target);
@@ -946,13 +1008,31 @@ sub findConnections
9461008

9471009
if ($child_bus_type eq $bus_type)
9481010
{
949-
for (my $i = 0; $i < $self->getNumConnections($child); $i++)
1011+
my $numOfConnections = 0;
1012+
if($to_this_target)
9501013
{
951-
my $dest_target = $self->getConnectionDestination($child, $i);
952-
my $dest_parent = $self->getTargetParent($dest_target);
953-
my $type = $self->getMrwType($dest_parent);
954-
my $dest_type = $self->getType($dest_parent);
955-
my $dest_class = $self->getAttribute($dest_parent,"CLASS");
1014+
$numOfConnections = $self->getNumDestConnections($child);
1015+
}
1016+
else
1017+
{
1018+
$numOfConnections = $self->getNumConnections($child);
1019+
}
1020+
for (my $i = 0; $i < $numOfConnections; $i++)
1021+
{
1022+
my $other_end_target = undef;
1023+
if($to_this_target)
1024+
{
1025+
$other_end_target = $self->getConnectionSource($child, $i);
1026+
}
1027+
else
1028+
{
1029+
$other_end_target = $self->getConnectionDestination($child,
1030+
$i);
1031+
}
1032+
my $other_end_parent = $self->getTargetParent($other_end_target);
1033+
my $type = $self->getMrwType($other_end_parent);
1034+
my $dest_type = $self->getType($other_end_parent);
1035+
my $dest_class = $self->getAttribute($other_end_parent,"CLASS");
9561036
if ($type eq "NA")
9571037
{
9581038
$type = $dest_type;
@@ -961,34 +1041,45 @@ sub findConnections
9611041
$type = $dest_class;
9621042
}
9631043

964-
if ($end_type ne "") {
965-
#Look for an end_type match on any ancestor, as
1044+
if ($other_end_type ne "") {
1045+
#Look for an other_end_type match on any ancestor, as
9661046
#connections may have a destination unit with a hierarchy
9671047
#like unit->pingroup->muxgroup->chip where the chip has
9681048
#the interesting type.
969-
while ($type ne $end_type) {
1049+
while ($type ne $other_end_type) {
9701050

971-
$dest_parent = $self->getTargetParent($dest_parent);
972-
if ($dest_parent eq "") {
1051+
$other_end_parent = $self->getTargetParent($other_end_parent);
1052+
if ($other_end_parent eq "") {
9731053
last;
9741054
}
9751055

976-
$type = $self->getMrwType($dest_parent);
1056+
$type = $self->getMrwType($other_end_parent);
9771057
if ($type eq "NA") {
978-
$type = $self->getType($dest_parent);
1058+
$type = $self->getType($other_end_parent);
9791059
}
9801060
if ($type eq "NA") {
981-
$type = $self->getAttribute($dest_parent, "CLASS");
1061+
$type = $self->getAttribute($other_end_parent, "CLASS");
9821062
}
9831063
}
9841064
}
9851065

986-
if ($type eq $end_type || $end_type eq "")
1066+
if ($type eq $other_end_type || $other_end_type eq "")
9871067
{
988-
$connections{CONN}[$num]{SOURCE}=$child;
989-
$connections{CONN}[$num]{SOURCE_PARENT}=$target;
990-
$connections{CONN}[$num]{DEST}=$dest_target;
991-
$connections{CONN}[$num]{DEST_PARENT}=$dest_parent;
1068+
if($to_this_target)
1069+
{
1070+
$connections{CONN}[$num]{SOURCE}=$other_end_target;
1071+
$connections{CONN}[$num]{SOURCE_PARENT}=
1072+
$other_end_parent;
1073+
$connections{CONN}[$num]{DEST}=$child;
1074+
$connections{CONN}[$num]{DEST_PARENT}=$target;
1075+
}
1076+
else
1077+
{
1078+
$connections{CONN}[$num]{SOURCE}=$child;
1079+
$connections{CONN}[$num]{SOURCE_PARENT}=$target;
1080+
$connections{CONN}[$num]{DEST}=$other_end_target;
1081+
$connections{CONN}[$num]{DEST_PARENT}=$other_end_parent;
1082+
}
9921083
$connections{CONN}[$num]{BUS_NUM}=$i;
9931084
$num++;
9941085
}
@@ -999,7 +1090,6 @@ sub findConnections
9991090
return \%connections;
10001091
}
10011092

1002-
10031093
## returns BUS_TYPE attribute of target
10041094
sub getBusType
10051095
{
@@ -1289,7 +1379,7 @@ sub getAllTargetChildren
12891379
push @children, @more;
12901380
}
12911381
}
1292-
1382+
12931383
return @children;
12941384
}
12951385

0 commit comments

Comments
 (0)