( ESNUG 514 Item 4 ) -------------------------------------------- [11/16/12]

Subject: Cadence reply on how to test a new Specman-Matlab-Simulink install

> He says he can install both tools from the release notes and link them
> through the C API, but he does not know how to get Specman "e" and
> Matlab Simulink to talk to each other. ... It would help if we had simple
> examples on how to access the Matlab engine from within Specman.  Want
> to use Simlink for our DSP model.
>
>     - from http://www.deepchip.com/items/0513-02.html


From: [ Avi Bloch of Cadence ]

Hi, John,

Cadence has a package that supports an interface with Matlab.  Here it is
freely available to anyone who needs it:

                          shr_sn_matlab.tar.zip

Using this package and after initialization, the following are the answers
to [ Muppet Baby ]'s questions.

>
>  1.) How do we get commands from Specman and into Matlab?
>

To send a command to Matlab from inside Specman:

   1. Define the cmds and put them in a list-of-string as in:

         var sl : list of string = {
            "rand_double_matrix = rand(20,90);";
            "rand_int_1_100 = fix(100 * rand_double_matrix);";
         };

      or as in:

         var sl : list of string = <<#:

             rand_double_matrix = rand(20,90);
             rand_int_1_100 = fix(100 * rand_double_matrix);

         end #;

  2. Use the MB macro to send the list-of-string to Matlab:

         MB sl;

     This macro can be used either as an action or on the command line of
     Specman, so that you can try sending commands right from the prompt.

            ----    ----    ----    ----    ----    ----   ----
>
>  2.) How do we get commands from Matlab into Specman?
>

This is not possible with this interface since Specman is the master.

            ----    ----    ----    ----    ----    ----   ----
>
>  3.) How do we get data from Matlab into Specman?
>
 
A type called sn_matlab_var_s is defined in the package which is used for
transferring data between Specman and Matlab.  It contains 3 fields for
holding data:

      a.) "mx_arr" which holds a pointer to the Matlab data, and
      b.) "r_data" and "i_data" which are e lists that hold the
          corresponding real and imaginary data.

To retrieve data from the Matlab:

  1. Define a sn_matlab_var_s:

         var sn_var : sn_matlab_var_s = new;

  2. Set its name to the name of the variable from the Matlab Workspace
     that you want to retrieve:

         sn_var.name = "rand_double_matrix";

  3. Use the interface method get_var() to retrieve the data:

         compute matlab.get_var(sn_var);

This will save a pointer to the retrieved data in the mx_arr field but won't
convert it to a Specman list.  In principle, there is no need to convert the
retrieved data to e lists, since the data can be accessed item by item
directly from the mx_arr field using the get_item() method:

  1. Declare the result:

         var el : sn_matlab_complex_s;

  2. Retrieve an item using a row, column notation to access an item
     from the matrix:

         el = sn_var.mx_arr.get_item(i, j);

     will retrieve the element from the row i, column j, starting from 0.
 
            ----    ----    ----    ----    ----    ----   ----
>
>  4.) How do we get data from Specman and into Matlab?
>

To send data from Specman to Matlab:

  1. Populate the e list of an object of type sn_matlab_var_s:

         var sn_var : sn_matlab_var_s = new;
         gen sn_var.r_data keeping { it.size() in [10..100]; };

  2. Set its properties:

         sn_var.its_class = MB_INT32;
         sn_var.is_complex = FALSE;
         sn_var.name = "new_matlab_var_name";

  3. Call the Matlab interface put_var() method:

         compute matlab.put_var(sn_var);

This will assign the data to the 'new_matlab_var_name' Matlab variable.  The
variable will be created if it doesn't exists yet.

            ----    ----    ----    ----    ----    ----   ----
>
>   5.) How do we deal with an "e" list vs. a Matlab array?  Must we
>       convert them?  How?

If needed one can convert the mx_arr filed to an e list using the mx_to_sn()
method:

         var s1:= matlab .mx_to_sn(mx_arr);

But as explained above it is not necessary to covert them.

            ----    ----    ----    ----    ----    ----   ----
>
>  6.) How to test the timing wheels between the two apps are synced up?
>      For example, from IES-XL in "e" we ask Matlab to calculate
>
>                      A = sin (B) + cos (C);
>     How do we know when in "e" that "A" really is "sin (B) + cos (C)"?

Not sure how do answer this question. This would be similar to asking "How
do I know that the sin() function in the C math library actually computes
a sine()?".

Here is a short example that raises a vector to a power of 2:

          start_matlab() // initialize package

          var sn_var : sn_matlab_var_s = new;
              sn_var.r_data = {1;2;3};
              sn_var.its_class = MB_INT32;
              sn_var.is_complex = FALSE;
              sn_var.name = "input";

          compute matlab.put_var(sn_var); // put variable

          var s1 := {"output = power(input,2)"}

          MB s1 // execute Matlab power command

          var ss : sn_matlab_var_s = new;
              ss.name = "output";

          compute matlab.get_var(ss) // get result

          p ss.mx_arr.get_item(1,0).r // print the second item
          var ss2:=matlab.mx_to_sn(ss.mx_arr)
          p ss2.r_data // print the list

Hopefully this example program helps [ Muppet Baby ] better understand how
the Specman/Matlab interface works.

    - Avi Bloch
      Cadence Design Systems, Inc.               Herzliya, Israel
Join    Index    Next->Item






   
 Sign up for the DeepChip newsletter.
Email
 Read what EDA tool users really think.


Feedback About Wiretaps ESNUGs SIGN UP! Downloads Trip Reports Advertise

"Relax. This is a discussion. Anything said here is just one engineer's opinion. Email in your dissenting letter and it'll be published, too."
This Web Site Is Modified Every 2-3 Days
Copyright 1991-2024 John Cooley.  All Rights Reserved.
| Contact John Cooley | Webmaster | Legal | Feedback Form |

   !!!     "It's not a BUG,
  /o o\  /  it's a FEATURE!"
 (  >  )
  \ - / 
  _] [_     (jcooley 1991)