Coolquest, Inc. | Home | Products | Support | About | Contact | |||
|
<<< Previous | CBOLD Reference Home | Next >>> |
On rare occasions you may find use for the bus() function. It has two forms, one that creates a named subbus and one that accesses an existing named subbus.
bus( "OPTO_ANODE", 3, 0 ); // create the named subbuses accessed below bus( "OPTO_GND", 3, 0 ); int r = 0; // resistor index for ( int i = 0; i < 2; ++ i ) { // for each dual LED for ( int j = 0; j < 2; ++ j ) { // for each LED of dual LED VCC ^ Rled[ r ] ^ bus( "OPTO_ANODE" )( r ) << LEDopto[ i ].ANODE( j ); // four redundant LED's GND ^ Rgnd[ r ] ^ bus( "OPTO_GND" )( r ) << LEDopto[ i ].CATHODE( j ); r++; } }
The three-argument form of bus() creates a subbus using the specified name and range (e.g., 3, 0) and returns a port range that represents the entire range of the new subbus.
The one-argument form of bus() returns a port range that represents the entire range of the specified existing subbus.
The above code connects two dual LED's to power and ground via resistors. Rled and Rgnd are arrays of four resistors each. For example, the Rled's limit current while the Rgnd's provide thermal isolation during hand soldering of the LED's.
The designer wanted to implement the connections with a for loop but also wanted the connections to be named. As the connections are internal to the connecting module, the only way for the designer to achieve his goals was with the bus() function.
Consider this statement:
VCC ^ Rled[ r ] ^ bus( "OPTO_ANODE" )( r ) << LEDopto[ i ].ANODE( j ) ;
It is equivalent to:
( VCC ^ Rled[ r ] ) ^ ( bus( "OPTO_ANODE" )( r ) << LEDopto[ i ].ANODE( j ) );
The statement connects one terminal of Rled[ r ] to the connecting module's VCC port and the other terminal to bit r of the OPTO_ANODE subbus. It also connects bit j of the ANODE port of the ith LEDopto to bit r of the OPTO_ANODE subbus.
To fully understand this example, you need to understand the Connecting Functions and Operators, both their arguments and return types.
<<< Previous | CBOLD Reference Home | Next >>> |
Legal | Copyright © 2007 by Coolquest, Inc. | Contact |