Coolquest, Inc. Home Products Support About Contact
cbold_logo_gif C++BOLD Reference Manual cbold_logo_gif

<<< Previous CBOLD Reference Home Next >>>

 

4.5. TPortRange

The TPortRange class makes possible connections to a subset of a port. Such a subset is called a port range. The user rarely declares instances of TPortRange. Instead, the C++ compiler applies operators within the CBOLD framework to create temporary instances of TPortRange as needed. Some examples are shown below:

class CM_MyModule : public TModule {
public:
  ...
  virtual void Connect() {
    DATA          <<  Ram.D;          // example 1: connect entire range of Ram.D to DATA
    ADDR( 4 )     <<  Pld.IO( 55 );   // example 2: connect 1 bit of Pld.IO to one bit of ADDR
    DATA( 7 , 0)  <<  Flash.D;        // example 3: connect entire range of Flash.D to 8 LSB's of DATA
    ...
  }
  ...
};

The << operator accepts TPortRange's as arguments, not TPort's. TPort contains three member operators that return TPortRange's. From the CBOLD framework source code:

operator TPortRange() { return operator()( LeftRange, RightRange ); }      // full range shorthand, e.g., P
TPortRange operator()( int aLeft ) { return operator()( aLeft, aLeft ); }  // single wire shorthand, e.g., P(4)
TPortRange operator()( int aLeft, int aRight )...                          // range shorthand, e.g., P(31,0)

In example 1, the compiler uses the conversion operator twice, once to get the full range of DATA and once to get the full range of Ram.D. The conversion operator converts the DATA and Ram.D ports into equivalent TPortRanges that cover the full range of the ports.

In example 2, the compiler uses the single-argument function call operator (operator()) twice, once for ADDR( 4 ) and once for PLD.IO( 55 ). This operator is explicitly specified by the user's code. I.e., in C++, if ADDR is an instance of TPort, then ADDR( 4 ) tells the compiler to call ADDR's member operator()( int aLeft ) with argument aLeft = 4.

In example 3, the compiler uses the conversion operator to convert Flash.D to a TPortRange and the two-argument function call operator to create a TPortRange that represents the eight LSB's of the DATA port.

In all cases, the << operator checks that its two TPortRange arguments have the same width. A runtime error would result, for example, if the Flash.D port were sixteen bits wide.

 

<<< Previous CBOLD Reference Home Next >>>

Legal Copyright © 2007 by Coolquest, Inc. Contact