OpenCores
URL https://opencores.org/ocsvn/socgen/socgen/trunk

Subversion Repositories socgen

[/] [socgen/] [trunk/] [tools/] [verilog/] [trace_bus] - Rev 135

Compare with Previous | Blame | View Log

eval 'exec `which perl` -S $0 ${1+"$@"}'
   if 0;
#/****************************************************************************/
#/*                                                                          */
#/*   SOCGEN Design for Reuse toolset                                        */
#/*                                                                          */
#/*   Version 1.0.0                                                          */
#/*                                                                          */
#/*   Author(s):                                                             */
#/*      - John Eaton, z3qmtr45@gmail.com                                    */
#/*                                                                          */
#/****************************************************************************/
#/*                                                                          */
#/*                                                                          */
#/*             Copyright 2016 John T Eaton                                  */ 
#/*                                                                          */
#/* Licensed under the Apache License, Version 2.0 (the "License");          */
#/* you may not use this file except in compliance with the License.         */
#/* You may obtain a copy of the License at                                  */
#/*                                                                          */
#/*    http://www.apache.org/licenses/LICENSE-2.0                            */
#/*                                                                          */
#/* Unless required by applicable law or agreed to in writing, software      */
#/* distributed under the License is distributed on an "AS IS" BASIS,        */
#/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
#/* See the License for the specific language governing permissions and      */
#/* limitations under the License.                                           */
#/*                                                                          */
#/*                                                                          */
#/****************************************************************************/

############################################################################
# General PERL config
############################################################################
use Getopt::Long;
use English;
use File::Basename;
use Cwd;
use Scalar::Util qw(looks_like_number);
use XML::LibXML;
use lib './tools';
use sys::lib;
use yp::lib;
use BerkeleyDB;


$OUTPUT_AUTOFLUSH = 1; # set autoflush of stdout to TRUE.


############################################################################
### Process the options
############################################################################
Getopt::Long::config("require_order", "prefix=-");
GetOptions("h","help",
           "envidentifier=s" => \$envidentifier,
           "prefix=s"        => \$prefix,
           "vendor=s"        => \$vendor,
           "library=s"       => \$library,
           "component=s"     => \$component,
           "version=s"       => \$version,
           "path=s"          => \$path,
           "bus_name=s"      => \$bus_name,
           "test_name=s"      => \$test_name,
           "dest_dir=s"      => \$dest_dir
          
    

) || die "(use '$program_name -h' for help)";


##############################################################################
## Help option
##############################################################################
if ( $opt_h  or $opt_help  ) 
  { print "\n trace_bus -envidentifier {sim/syn}  -prefix /work -vendor vendor_name -library library_name  -component component_name  -version version_name -path root.dut.core.cpu -bus_name cpu -dest_dir dest_dir    \n";
    exit 1;
  }



#############################################################################
## 
## 
#############################################################################

$home = cwd();

unless ($prefix)
 {
 $prefix   = yp::lib::get_workspace();
 $prefix   =  "/${prefix}";
 }


unless ($path)
 {
 $path   =  "root";
 }





my   $variant;
unless(defined   $dest_dir  ){ $dest_dir            = "elab";}

my $main_module_name = yp::lib::get_module_name($vendor,$library,$component,$version);

my   $destination         = "${main_module_name}";

if($test_name)
  { 
  $destination         = "${destination}_${test_name}";
  }


my @reg_list ="";
my @param_list ="";

my $root                =      "root";

if($version)       {$variant   = "${component}_${version}";}
else               {$variant   = "${component}";}

#print "trace_bus  -prefix $prefix -vendor $vendor -library $library -component $component -version $version -path $path   -bus_name $bus_name -test_name $test_name  \n";

my $parser = XML::LibXML->new();

my $socgen_file              = $parser->parse_file(yp::lib::find_componentConfiguration($vendor,$library,$component));

#unless ($socgen_file)      { print "No socgen ip file   \n";};



my $comp_xml_sep    = yp::lib::find_comp_xml_sep($vendor,$library,$component,$version);
my $lib_comp_sep    = yp::lib::find_lib_comp_sep($vendor,$library,$component);

my $root_path;
if($dest_dir eq "elab")
{
 $root_path  = "${home}${prefix}/${vendor}__${library}${lib_comp_sep}${component}${comp_xml_sep}/../${dest_dir}";
}
else
{
 $root_path  = "${home}/${dest_dir}";
}


 unless( -e $root_path )
      {
      #print "$root_path does not exist... creating \n";
      my $cmd = "mkdir $root_path \n";
      if(system($cmd)){};
      }


 $root_path  = "${root_path}/${destination}";


 unless( -e $root_path )
      {
      #print "$root_path does not exist... creating \n";
      my $cmd = "mkdir $root_path \n";
      if(system($cmd)){};
      }



my $sw_dir     = "${root_path}/sw";
mkdir $sw_dir,0755             unless( -e $sw_dir );


my $output_file = "${sw_dir}/${path}_${bus_name}.v";
$output_file =~s/root.dut.//;
open PARAM_FILE,">$output_file" or die "unable to open $output_file";

my $output_file = "${sw_dir}/${path}_${bus_name}.h";
$output_file =~s/root.dut.//;
open PARAMH_FILE,">$output_file" or die "unable to open $output_file";


my $report_dir     = "${root_path}/memmaps";
mkdir $report_dir,0755             unless( -e $report_dir );

$output_file = "${report_dir}/${path}_${bus_name}.txt";
$output_file =~s/root.dut.//;

open DEST_FILE,">$output_file" or die "unable to open $output_file";

my $elab_db_file = yp::lib::get_elab_db_filename($vendor,$library,$component,$version,"default");



unless(-e  $elab_db_file  )
        {
        #print "$elab_db_file  root file does not exist  \n";
        }

my $root_db = new BerkeleyDB::Hash( -Filename => "$elab_db_file", -Flags => DB_CREATE ) or die "Cannot open $elab_db_file: $!";


my $comp_data;

my $bd_vendor;
my $bd_library;
my $bd_component;
my $bd_version;




#print "STARTING $path       ::  $bus_name  \n";


$root_db->db_get("component___${path}", $comp_data );
( $vendor,$library,$component,$version) = split( /\:/ , $comp_data);



my $instance_db_file  = yp::lib::get_io_busses_db_filename($vendor,$library,$component,$version,"default");



unless(-e  $instance_db_file  )
        {
        #print "$instance_db_file  instance file does not exist  \n";
        }

my $instance_db      = new BerkeleyDB::Hash( -Filename => "$instance_db_file", -Flags => DB_CREATE ) or die "Cannot open $instance_db_file: $!";


my $base_addr = hex(0x0000);


my $repo_data;

$instance_db->db_get("AbsDef.${bus_name}.master", $repo_data );



if($repo_data) 
  { 
  ( $bd_vendor,$bd_library,$bd_component,$bd_version) = split( /\:/ , $repo_data);
#  print  "MASTER $bd_vendor $bd_library $bd_component $bd_version   \n";
  $repo_data = "";


  $_ = "$path";
  if(/(\S+)\.(\S+)/)                     
    { 
    $path      = $1; 
    }
    follow_bus("${path}",$bus_name,$base_addr);
  }


$instance_db->db_get("AbsDef.${bus_name}.slave", $repo_data );
$instance_db->db_close();

if($repo_data) 
  { 
  ( $bd_vendor,$bd_library,$bd_component,$bd_version) = split( /\:/ , $repo_data);
#  print  "SLAVE $bd_vendor $bd_library $bd_component $bd_version   \n";
  $repo_data = "";
  follow_bus("${path}",$bus_name,$base_addr);
  }



$root_db->db_close();

@reg_list = sys::lib::trim_sort(@reg_list);

foreach my $reg_line (@reg_list)
{
print DEST_FILE "$reg_line  \n";
}



@param_list = sys::lib::trim_sort(@param_list);

foreach my $param_line (@param_list)
{

( $address,$parameter) = split( /\:/ , $param_line);

if($parameter)
{
print PARAM_FILE   "parameter $parameter = $address ; \n";
print PARAMH_FILE "$parameter = $address ; \n";
}
}

#print "FINISHED \n";














sub follow_bus
   {
   my @params           = @_;
   my $base_addr        = pop(@params);
   my $bus_name         = pop(@params);
   my $path            = pop(@params);

   my $vendor;
   my $library;
   my $component;
   my $version;
   my $comp_data;
   my $bd_vendor;
   my $bd_library;
   my $bd_component;
   my $bd_version;
   my $repo_data;

#   print "START_FOLLOW   $path                 == $bus_name  \n";

   $root_db->db_get("component___${path}", $comp_data );
   ( $vendor,$library,$component,$version) = split( /\:/ , $comp_data);

#   print "QQQQQQ  $path    ||  $vendor $library $component $version ==  $bus_name  \n";




   my $instance_db_file  = yp::lib::get_io_busses_db_filename($vendor,$library,$component,$version,"default");

   unless(-e  $instance_db_file  )
        {
        #print "$instance_db_file  instance file does not exist  \n";
        }

   my $instance_db = new BerkeleyDB::Hash( -Filename => "$instance_db_file", -Flags => DB_CREATE ) or die "Cannot open $instance_db_file: $!";



   $instance_db->db_get("AbsDef.${bus_name}.master", $repo_data );



   if($repo_data) 
     { 
     ( $bd_vendor,$bd_library,$bd_component,$bd_version) = split( /\:/ , $repo_data);
#  print  "MASTER $bd_vendor $bd_library $bd_component $bd_version   \n"; 
     $repo_data = "";
     }


    $instance_db->db_get("AbsDef.${bus_name}.interconnect", $repo_data );
    if($repo_data)
      {
      my @couples = split( /\:/ , $repo_data);
      foreach my $pair (@couples)
        {
        my $new_instance;
        my $new_bus_name;
        ($new_instance,$new_bus_name) = split( /\.\./ , $pair);
#        print  "INTC    $path           $new_instance  ==  $new_bus_name   \n";
        follow_bus("${path}.${new_instance}",$new_bus_name,$base_addr);
        return(1);
        }
      $repo_data = "";
      }

   $instance_db->db_get("AbsDef.${bus_name}.slave", $repo_data );


   if($repo_data) 
      { 
      ( $bd_vendor,$bd_library,$bd_component,$bd_version) = split( /\:/ , $repo_data);
#      print  "SLAVE  $bd_vendor $bd_library $bd_component $bd_version   \n";
      $repo_data = "";
      $instance_db->db_get("AbsDef.${bus_name}.bridge", $repo_data );
      if($repo_data)
         {
         $_ = "$path";
         if(/(\S+)\.(\S+)/)                     
           { 
           $path      = $1; 
           }


         my @couples = split( /\::/ , $repo_data);
         foreach my $pair (@couples)
           {
           my $new_bus_name;
           my $new_base_addr;

          ($new_bus_name,$new_base_addr) = split( /\.\./ , $pair);
           my $mapped_addr = $base_addr + $new_base_addr;
#           print  "BRIDGE  $path        ==  ${bus_name}   $new_bus_name  $mapped_addr           \n";
           $instance_db->db_get("BlkDef.${bus_name}.${new_bus_name}", $Repo_data );
#           print "BlkDef.${bus_name}.${new_bus_name} $Repo_data  \n";
           ( $Base,$Range) = split( /\::/ , $Repo_data);
           $Saddr = $Base + $base_addr;
           $Eaddr = $Base + $base_addr + $Range-1;
#           print "FRRRRRRRR $base_addr $Base  $Range   $Saddr  $Eaddr  \n";
           my $hex = sprintf("0x%04x",$Saddr);
           push @reg_list ,"$hex                                     ${component}.${path} ($component) ${bus_name}  Start "  ;
           $hex = sprintf("0x%04x",$Eaddr);
           push @reg_list ,"$hex                                     ${bus_name}  End "  ;
           follow_bus( "${path}",$new_bus_name,$mapped_addr);
           }
        $repo_data = "";
        }
      else
        {
#        print "Now dump registers for $path     $bus_name   $base_addr\n";
         my $hex = sprintf("0x%04x",$base_addr);


         my $key;
         my $value;
         my $RegDef;
         my $reg_bus;
         my $reg_name;

         my $cursor = $instance_db ->db_cursor() ;
         while ($cursor->c_get($key, $value, DB_NEXT) == 0) 
            {
            ($RegDef,$reg_bus,$reg_name) = split( /\./ , $key);
#   print " $key      $value  \n";

             if( ($RegDef eq "RegDef") && ($reg_bus eq $bus_name))
               {
               ( $Xoffset,$Xname,$Xsize,$Xaccess) = split( /\::/ , $value);
               $addr = $base_addr + $Xoffset;
               my $hex = sprintf("0x%04x    %16s ",$addr, $Xname);
               push @reg_list ,"$hex            $Xsize   $Xaccess";
               my $temp = "${path}_${Xname}";
               $temp =~s/root.dut.//;
               $temp =~s/\./_/g;
               $hex = sprintf("'h%04x:%16s ",$addr, $temp);
               if($hex) {push @param_list ,"$hex";}
 #   print  " $addr   $Xname   $Xsize   $Xaccess    \n";
   }


   if( ($RegDef eq "BlkDef") && ($reg_bus eq $bus_name))
   {
   ( $Base,$Range) = split( /\::/ , $value);

   $Saddr = $Base + $base_addr;
   $Eaddr = $Base + $base_addr + $Range-1;
#print "FRRRRRRRR $base_addr $Base  $Range   $Saddr  $Eaddr  \n";

   my $hex = sprintf("0x%04x",$Saddr);
   push @reg_list ,"$hex                                     ${component}.${path} ($component) ${bus_name}  Start "  ;
   $hex = sprintf("0x%04x",$Eaddr);
   push @reg_list ,"$hex                                     ${bus_name}  End "  ;
   }

   }
   my $status = $cursor->c_close() ;

        }
      }


$instance_db->db_get("AbsDef.${bus_name}.node", $repo_data );
if($repo_data) 
  { 
  ( $bd_vendor,$bd_library,$bd_component,$bd_version) = split( /\:/ , $repo_data);
#  print  "NODE   $bd_vendor $bd_library $bd_component $bd_version   \n";
  $repo_data = "";
  $instance_db->db_get("AbsDef.${bus_name}.interconnect", $repo_data );
  if($repo_data) 
     { 
#     print  "INTC   $repo_data \n";
     my @couples = split( /\:/ , $repo_data);
     foreach my $pair (@couples)
      {
       my $new_instance;
       my $new_bus_name;
      ($new_instance,$new_bus_name) = split( /\.\./ , $pair);

#       print  "NODE  $path         $new_instance  ==  $new_bus_name   \n";
       follow_bus("${path}.${new_instance}",$new_bus_name,$base_addr);
       return(1);
       
      }
     }
  }

$instance_db->db_close();
return(0);
   }

1

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.