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

<<< Previous CBOLD Reference Home Next >>>

 

6.4. Registering Array Members

When an array is registered using the rega() or regab() macro, CBOLD registers the elements of the array individually. All are assigned the same name, but each is assigned a different number. The number has no intrinsic meaning, but simply serves to distinguish the individual elements of the array. The rega() and regab() macros use each element's index within the array as the element's number. For example, if a four–element array called Caps[] is registered like this:

virtual void Register() {
  rega( Caps, 5 );
  ...
}

then the elements of Caps[] are registered as Caps 0, Caps 1, Caps 2, and Caps 3.

If you prefer numbers other than the zero-based default, you cannot use the CBOLD registering macros. Instead, you must register each element of the array by calling Reg(), and, for arrays of busses, SetRange(). See the example below as well as the macro definitions in cb_base.h.

If you simply want to use a small base other than zero, you can declare an array larger than what you need and then register only the elements you need. For example, a VME backplane might have slots 1-21 rather than 0-20:

class CM_VME_Backplane : public TModule {
public:
  CM_VME_Slot   Slots[ 22 ];   // declare array of 22 slots -- Slots[ 0 ] will not be registered
  ...
  virtual void Register() {
    for ( int i = 1; i <= 21; ++ i ) {
      regn( Slots, i );
    }
    ...
  }

If you have an array of ports in which the ranges of the individual ports are not identical, you cannot use regab() to register the array. Instead, as shown below, you can use regn() and SetRange() to register each port in the array. This technique is common in FPGA wrapper modules, in which each I/O bank of the FPGA is represented as a port in an array.

class CM_MyFPGA : public TModule {
public:
  int   IO_PerBank[ 8 ];      // number of I/O pins per bank, e.g., initialized in the class's constructor
  ...
  port        Bank[ 8 ];      // I/O for each bank
  ...
  virtual void Register() {
    for ( int b = 0; b < 8; ++ b ) {           // register each member of Bank[]
      int IO_Count = IO_PerBank[ b ];          // the number of I/O's in each bank varies slightly
      regn( Bank, b );                         // register array member
      Bank[ b ].SetRange( IO_Count - 1, 0 );   // set range of member
    }
    ...
  }

For a more detailed example of FPGA I/O, see the IROD section of the CBOLD Example Designs

Though CBOLD does not provide a macro for registering multidimensional arrays of members, the designer may still use such arrays. The designer must register each element individually and assign a unique number to each element. For example:

class CM_MyModule : public TModule {
public:
  CP_FPGA FPGAS[ 2 ][ 3 ];            // 2x3 array of FPGA's
  ...
  virtual void Register() {
    int e = 0;                        // unique number for each element of FPGAS[][]
    for ( int i = 0; i < 2; ++ i ) {
      for ( int j = 0; j < 3; ++ j ) {
        Reg( & FPGAS[ i ][ j ], "FPGAS", e++ );
      }
    }
    ...
  }
};

The above example would register the elements of the FPGAS array as follows:

Array Element Element's Designator
FPGAS[ 0 ][ 0 ] FPGAS 0
FPGAS[ 0 ][ 1 ] FPGAS 1
FPGAS[ 0 ][ 2 ] FPGAS 2
FPGAS[ 1 ][ 0 ] FPGAS 3
FPGAS[ 1 ][ 1 ] FPGAS 4
FPGAS[ 1 ][ 2 ] FPGAS 5

Because the numbers assigned can be any non–negative integers as long as they are unique, the designer may have chosen any one of the following numbering schemes in order to enhance readability of output files:

Array Element Registered as ... or Registered as
FPGAS[ 0 ][ 0 ] FPGAS 0 FPGAS 100
FPGAS[ 0 ][ 1 ] FPGAS 1 FPGAS 101
FPGAS[ 0 ][ 2 ] FPGAS 2 FPGAS 102
FPGAS[ 1 ][ 0 ] FPGAS 10 FPGAS 110
FPGAS[ 1 ][ 1 ] FPGAS 11 FPGAS 111
FPGAS[ 1 ][ 2 ] FPGAS 12 FPGAS 112

Once an array is registered, the CBOLD framework treats its elements just like non–array members.

 

<<< Previous CBOLD Reference Home Next >>>

Legal Copyright © 2007 by Coolquest, Inc. Contact