[sv-cc] Modified "perspectives from a user" examples


Subject: [sv-cc] Modified "perspectives from a user" examples
From: Stickley, John (john_stickley@mentorg.com)
Date: Tue Apr 08 2003 - 09:12:39 PDT


Team,

Here's a re-send of the modified example I sent out
last week for Andrzej to review.

-- johnS

Team,

At Doug's request for is SV-CC DAC tutorial I've created
two variations of my "perspectives from a user example to reflect
Andrzej's suggestions of how they can be written
more efficiently with a better choice of data types
than bit vectors.

Andrzej, can you look these over and see if you can
find any syntax errors or differences in what you were
trying to point out about more efficient usage of data types.
Doug want's to polish these up for a tutorial he's working on.

Here are the two variations:

Variation 1:
      Direct use of native C struct for input, function return
      for output - binary compatible

Variation 2:
      Direct use of integers for small bit vector inputs and outputs
      - source compatible

----------------------------------------------------------
Variation 1:

In the following example, an ethernet packet header struct
is directly passed to an exported SV function. A computed CRC
is returned as a function return argument and compared.

Here's the C definition of the header:

      struct etherHeaderT {
          unsigned type;
          unsigned length;
          unsigned long long dest_addr;
          unsigned long long src_addr;
      };

The same struct and exported HDL function is declared on the SV side
as follows:

      typedef struct {
          int unsigned type; // 16 bit type
          int unsigned length; // 16 bit length
          longint unsigned dest_addr; // 48 bit dest_addr
          longint unsigned src_addr; // 48 bit src_addr
      } etherHeaderT;

      export "DPI" SendPacketHeader=handlePacketHeader;
      function int unsigned handlePacketHeader( // Returns 32 bit CRC
          input etherHeaderT header );
          ...
          return computedCRC;
      endfunction

The SV function will return a computed CRC as an return arg.

The required prototype for the C function wrapper then,
according to the current DPI is as follows:

      unsigned SendPacketHeader( // function int unsigned
          const etherHeaderT header ); // input etherHeaderT header

Here is a scenario for how this function might be called
from a C model. This code is binary compatiable across all
implementations:

void MyCModel::SendPacketHeader( const etherHeaderT *header, unsigned crc ){
      if( crc != SendPacketHeader( header ) error("mismatched crcs" );
}

Pretty efficient ! A far cry from my original "awkward" binary
compatible example using bit vectors.

----------------------------------------------------------
Variation 2:

In the following example, the data members of an ethernet packet
header struct are passed as arguments to an exported SV function.
A computed CRC is returned as a function output argument and compared.

Native types are used for all arguments except for the source
and destination address which are passed as bit vectors.

Here's the C definition of the header:

      struct etherHeaderT {
          unsigned type;
          unsigned length;
          unsigned long long dest_addr;
          unsigned long long src_addr;
      };

The exported HDL function is declared on the SV side
as follows:

      export "DPI" SendPacketHeader=handlePacketHeader;
      function void handlePacketHeader(
          input unsigned int type, // 16 bit type
          input unsigned int length, // 16 bit length
          input bit [47:0] destAddr, // 48 bit dest_addr
          input bit [47:0] srcAddr, // 48 bit src_addr
          output unsigned int crc ); // 32 bit crc
          ...
          crc = computedCRC;
       endfunction

The SV function will return a computed CRC as an return arg.

The required prototype for the C function wrapper then,
according to the current DPI is as follows:

      void SendPacketHeader(
          const unsigned type, // input int unsigned type;
          const unsigned length, // input int unsigned length;
          const svBitPackedArrRef destAddr, // input bit [47:0] destAddr;
          const svBitPackedArrRef srcAddr, // input bit [47:0] srcAddr;
          unsigned *crc ); // output int unsigned crc;

Here is a scenario for how this function might be called
from a C model. This code is source (not binary) compatiable
across all implementations:

#include "svdpi_src.h"

void MyCModel::SendPacketHeader( const etherHeaderT *header, unsigned crc ){

      // Declare source compatible, implementation required space for each arg
      SV_BIT_PACKED_ARRAY( 48, destAddr );
      SV_BIT_PACKED_ARRAY( 48, srcAddr );
      unsigned compareCrc;

      // Pack args into allocated implementation required storage areas
      svPutPartSelectBit( destAddr, (svBitVec32)(header->destAddr), 0, 32);
      svPutPartSelectBit( destAddr, (svBitVec32)(header->destAddr>>32), 32, 16 );
      svPutPartSelectBit( srcAddr, (svBitVec32)(header->srcAddr), 0, 32);
      svPutPartSelectBit( srcAddr, (svBitVec32)(header->srcAddr>>32), 32, 16 );

      // Now call actual function.
      SendPacketHeader(
          header->type, header->length, destAddr, srcAddr, &compareCrc );

      // Compare returned CRC to actual.
      if( compareCrc != crc ) error( "mismatched crcs" );
}

-- johnS
                                                             __
                         ______ | \
______________________/ \__ / \
                                  \ H Dome ___/ |
John Stickley E | a __ ___/ / \____
Principal Engineer l | l | \ /
Verification Solutions Group | f | \/ ____
Mentor Graphics Corp. - MED C \ -- / /
17 E. Cedar Place a \ __/ / /
Ramsey, NJ 07446 p | / ___/
                                   | / /
mailto:John_Stickley@mentor.com \ /
Phone: (201)818-2585 \ /
                                     ---------



This archive was generated by hypermail 2b28 : Tue Apr 08 2003 - 09:14:31 PDT