bluespec.com Forum Index bluespec.com
Bluespec Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Fault simulation with bluesim

 
Post new topic   Reply to topic    bluespec.com Forum Index -> Tools: Bluesim
View previous topic :: View next topic  
Author Message
tomahawkins



Joined: 14 Dec 2012
Posts: 21

PostPosted: Mon May 12, 2014 2:54 pm    Post subject: Fault simulation with bluesim Reply with quote

Hi,

We want to use bluesim to simulate faults (e.g. single event upsets) on our bsv designs. For this we need some way to alter the state of a bluesim run. Is this possible?

Our original idea was to use bluetcl to control fault injection, but though there is a "sim get" command, there does not appear to be a "sim put" command.

Any suggestions?

-Tom
Back to top
View user's profile Send private message
tomahawkins



Joined: 14 Dec 2012
Posts: 21

PostPosted: Wed May 14, 2014 10:01 am    Post subject: Reply with quote

I found a solution by using the critcl package to embedded C++ in the tcl sim script to make method calls into the underlying simulator.

http://andreas-kupries.github.io/critcl/

Code:

# A test of writing state elements from within Bluesim.

package require critcl
package require Bluesim
namespace import Bluesim::*

# Set C++ as the language.
critcl::config language c++
critcl::clibraries -lstdc++

# Add an include search path to the bluesim libraries.
set bluespecdir $::env(BLUESPECDIR)
critcl::config I $bluespecdir/Bluesim

# Includes.
critcl::ccode {
#include "bluesim_types.h"
#include "bs_symbol.h"
#include "bs_prim_mod_reg.h"
}

# Get the value of a register (uint32).
critcl::cproc sim_get_reg_uint32 {int handle} int {
  tSymbol symbol = (tSymbol) handle;
  MOD_Reg<tUInt32> * reg = (MOD_Reg<tUInt32> *) symbol->value;
  int value = (int) (reg->METH_read());
  return value;
}

# Set the value of a register (uint32).
critcl::cproc sim_set_reg_uint32 {int handle int value} void {
  tSymbol symbol = (tSymbol) handle;
  MOD_Reg<tUInt32> * reg = (MOD_Reg<tUInt32> *) symbol->value;
  reg->METH_write((tUInt32) value);
}


puts "Load the sim object."
sim load example.so mkTop

puts "Get the symbol handle to register 'a'."
set a [sim lookup m.a]

puts "Get the value of register 'a' by both means and compare them."
puts [sim get $a]
puts [sim_get_reg_uint32 $a]

puts "Set register 'a' to 1."
sim_set_reg_uint32 $a 1

puts "Get the value of register 'a' again."
puts [sim get $a]
puts [sim_get_reg_uint32 $a]

puts "Step the simulation and check the values again."
sim step 1
puts [sim get $a]
puts [sim_get_reg_uint32 $a]

puts "Step the simulation and check the values again."
sim step 1
puts [sim get $a]
puts [sim_get_reg_uint32 $a]

exit
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bluespec.com Forum Index -> Tools: Bluesim All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
bluespec.com topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP