#/////////////////////////////////////////////////////////////////////////////
#/  Copyright (C) by RivieraWaves.
#/  This module is a confidential and proprietary property of RivieraWaves
#/  and a possession or use of this module requires written permission 
#/  from RivieraWaves.
#/----------------------------------------------------------------------------
#/ $Author: $
#/ Company          : RivieraWaves
#/----------------------------------------------------------------------------
#/ $Revision: $
#/ $Date: $
#/ ---------------------------------------------------------------------------
#/ Dependencies     : None
#/ Description      : Commands to be executed by ncsim for power estimation
#/ Application Note :
#/ Terms & concepts :
#/ Bugs             :
#/ Open issues and future enhancements :
#/ References       :
#/ Revision History :
#/ ---------------------------------------------------------------------------
#/
#/////////////////////////////////////////////////////////////////////////////

#
# Function gen_database 
# Input Parameters :
#    name            : name of the database to be created
#    conditionstart  : the database will start on the edge (defined by valuestart) of the <conditionstart> signal.
#                      If set to "none", the generation start immediately 
#    valuestart      : edge definition of <conditionstart> signal. 0 : falling 1 : rising
#    conditionstop   : the database will stop on the rising edge of the <conditionstop> signal
#    valuestop       : edge definition of <conditionstop> signal. 0 : falling 1 : rising
#
# Output :
#    A Cadence waveform database named <name>.shm will be created in waveform_dir folder (if shmgen = 1)
#    A VCD file named <name>.vcd will be created in waveform_dir folder (if vcdgen = 1)
#    A SAIF file named <name>.saif will be created in waveform_dir folder (if saifgen = 1)
#    A FSDB file named <name>.fsdb will be created in waveform_dir folder (if fsdbgen = 1)
#
#    The output format is selected using the parameters shmgen, vcdgen and fsdbgen.
#    By setting one or several variable to 1 enables the corresponding output generation
#    Otherwise, they shall be set to 0
#    
#    The scope used for the waveform generation is selected by the parameter toplevelpath defined below. 
#    
# Usage :
#
# gen_database <name> <path to signal use to start> <value of the start signal>  <path to signal use to stop> <value of the stop signal>
#
# To start immediately, the start condition shall be set to "none" 
# To stop the generation only at the end of the simulation, the stop condition shall be set to "none" 
#
proc gen_database {name conditionstart valuestart conditionstop valuestop} {

  set shmgen  0 
  set vcdgen  0 
  set saifgen 0 
  set fsdbgen 1 
  set toplevelpath U_rw_he_top_cpu

  if {$conditionstart != "none"} {
    stop -name STARTCOND -condition { [value $conditionstart] == $valuestart }
    run
    stop -delete STARTCOND
  }
  puts "" 
  puts "WAVEFORM GEN: Begining of $name phase" 
  if {$shmgen == 1} {
    puts "WAVEFORM GEN: Create $name.shm database for $toplevelpath" 
    database -open simu_shm.db -into waveform_dir/$name.shm -default
    probe  -database simu_shm.db -create $toplevelpath -all -depth all
  }

  if {$vcdgen == 1} {
    puts "WAVEFORM GEN: Create $name.vcd file for $toplevelpath" 
    database -open simu_vcd.db -vcd -into waveform_dir/$name.vcd -default
    probe  -database simu_vcd.db -create $toplevelpath -all -depth all
  }
  if {$saifgen == 1} {
    puts "WAVEFORM GEN: Create $name.saif file for $toplevelpath" 
    dumpsaif -scope $toplevelpath  -output waveform_dir/$name.saif -overwrite
  }
  if {$fsdbgen == 1} {
    puts "WAVEFORM GEN: Create $name.fsdb file for $toplevelpath" 
    call fsdbDumpfile "waveform_dir/$name" 
    call fsdbDumpvars 0 $toplevelpath
    call fsdbDumpMDA 0 $toplevelpath
  }   
  if {$conditionstop != "none"} {
    stop -name STOPCOND -condition { [value $conditionstop] == $valuestop }
  }  
  puts "" 
  run
  puts "WAVEFORM GEN: End of $name phase" 
  if {$conditionstop != "none"} {
    stop -delete STOPCOND
  }  
  if {$shmgen == 1} {
    puts "WAVEFORM GEN: Close $name.shm database" 
    database -close simu_shm.db
  }
  if {$vcdgen == 1} {
    puts "WAVEFORM GEN: Close $name.vcd file" 
    database -close simu_vcd.db
  }
  if {$saifgen == 1} {
    puts "WAVEFORM GEN: Close $name.saif file" 
    dumpsaif -end
  }
  if {$fsdbgen == 1} {
    puts "WAVEFORM GEN: Close $name.fsdb file" 
    call fsdbDumpflush
    call fsdbDumpFinish
  }
  puts "" 
}


assertion -summary -final


# Generate waveform for specfic phase
#gen_database after_reset U_rw_he_top_cpu.master_nrst 1 none 0
gen_database full none 0 none 0

run


exit
#-------------------------------------------------------------------------------
#- End of file
#-------------------------------------------------------------------------------
