verilog RTL 'case' width defined in a parameter? - case

I'm using a generate block to create a pipelined mux:
Is there a way to parameterize the cases in the case statement?
module muxNto1byW(
input clk,
input reset,
input wire[(SELECT_WIDTH-1):0] select,
input wire[(DATA_WIDTH*NUM_INPUTS-1):0] din,
output reg[(DATA_WIDTH-1):0] y
);
/* 4 LUT_WIDTH = 6, SEL DATA_INPUTS = 2 */
parameter SELECT_WIDTH = LUT_WIDTH - DATA_INPUTS;
...
generate
/* some for loops */
// register this stage's muxes
reg[(DATA_WIDTH-1):0] pipelineStage;
// assign values to each mux in this stage
always#(posedge reset or posedge clk)
if( reset )
pipelineStage <= {DATA_WIDTH{1'b0}};
else
begin
if( i == 0 ) // Stage 0 evaluates the inputs
case ( select[(SELECT_BITS_PER_STAGE-1):0] )
2'b00 : /* do something */
2'b01 : /* do something different */
2'b10 : /* you get the picture */
2'b11 : /* the last case */
endcase
endgenerate
SELECT_BITS_PER_STAGE in my target technology is 2,
so the cases are 2 bits wide 00, 01, 10 , 11
How can write this code so that if a different technology can only implement a 2 to 1 mux, (SELECT_BITS_PER_STAGE == 1), the case statement automatically changes to:
case ( )
1'b0: /* do something */
1'b1: /* do something different
endcase

That use of generate does not look very clean, I would take the code you are trying to wrap up and turn it into a sub-module. The generate can then make multiple instantiations of the sub-module and wire them up. The generate can then set parameters as required on instances. This breaks the problem down into the generate and then the module scaling correctly.
How can write this code so that if a different technology can only implement a 2 to 1 mux,
This is a slightly confusing statement to me. Are you referring to changing you RTL based on the libraries available for synthesis? Synthesis will be able to implement you implied logic from available 2 to 1 muxes, combining 3 of them to create a 4 to 1.
RTL should be independent of the library used for synthesis, its portability is an advantage.
If you mean RTL which can have its functionality expanded based on a parameters then I would zero pad the MSBs of select so that the case statement was unaffected, except having unreachable states.
parameter SELECT_BITS_PER_STAGE = 1;
localparam SELECT_MAX_WIDTH = 2;
localparam SELECT_EXTEND_BY = SELECT_MAX_WIDTH-SELECT_BITS_PER_STAGE;
wire select_ext = { {SELECT_EXTEND_BY{1'b0}}, select};
alway #* begin //just putting case statement in valid syntax
//...
case ( select_ext )
2'b00 : /* do something */
2'b01 : /* do something different */
2'b10 : /* you get the picture */
2'b11 : /* the last case */
default : /* catch all when select larger than 2 bits */
endcase
//...
end
NB: if you remove the width and base from the case statements they are interpreted as decimal values (probably integer width). Below is valid: I would not normally do this but might make sense in a context where the width of the select can change based on params.
case ( select_ext )
0 : /* do something */
1 : /* do something different */
2 : /* you get the picture */
3 : /* the last case */
default : /* catch all when select larger than 2 bits */
endcase

Related

How to use MDX constants/functions in icCube Reporting?

I have several functions/constants defined in the schema. An example is:
_latestPeriodWithData() which returns a date.
Goal: I want to use this value in the Reporting to set a Guide in a chart, using the demo example 'On Widget Options':
This is what I tried so far:
I have assigned this function as 'MDX / Value' for a Report Constant _lastDate and obtained the value for this constant using the java script function: context.eventValue('_lastDate'); but that just gives me the caption. The function context.eventObject("_lastDate").options.asMdx gives me _latestPeriodWithData(), but not its value.
On Widget Options
/**
* Result will be used while rendering.
*/
function(context, options, $box) {
// for debugging purpose
console.log(context.eventObject("_lastDate").options.asMdx);
options.guides[0].value = context.eventObject("_lastDate").options.asMdx; // <-- gives me _latestPeriodeWith data
// but not its value
options.guides[0].toValue = context.eventObject("_lastDate").options.asMdx;
options.guides[0].lineAlpha = 1;
options.guides[0].lineColor = "#c44";
return options;
}

Using non-scalar variables in BuildMaster otter-script plans

I'm pulling my hair out trying to get some very basic iteration working using non-execution set variables (ie setting things at Global with potential to override at lower scope).
Setting a $variable to some value works fine but I need to do something like...
foreach $DeployConfigKey in #MapKeys(%DeployConfigs)
{
...
}
So far I'm getting nowhere fast with execution errors saying "Invalid value for property Map; expected map."
Further doing something like set %executionvar = %DeployConfigs complains that a map cannot be set to a scaler value.
The variable, DeployConfigs looks like ...
%{"Web.config": ["Web.Beta.config", "Web.Release.config"]}
and is defined at Global scope.
What am I doing wrong?
I'm using buildmaster 5.7.3
Maps are specified as %(key: value), here is an example plan that should help:
set %map = %(Web.config: #("Web.Beta.config", "Web.Release.config"));
foreach $key in #MapKeys(%map)
{
set #values = %map[$key];
Log-Information `$key = $key;
Log-Information `#values = $Join(", ", #values);
}
Sleep 3;

Combining a string and a variable value to access an existing variable

Imagine I have the following set of defined variables:
$sportmenu_1: #23765c;
$sportmenu_3: #5e6b34;
$sportmenu_4: #7d7e6c;
$sportmenu_6: #786857;
$sportmenu_8: #487a91;
I also have a list containing the "id" or the last digit of each variable as:
$list: 1 3 4 6 8;
I then want to the $sportmenu_ variables to both name the css selectors and populate the properties, I'm using a list and a foreach as follows:
#each $id in $list_id_sports {
#sportmenu_#{$id} { //this works fine
.menu-sport-item {
background-color: #{$sportmenu_}#{$id}; //here's the issue!
}
}
}
The problem is that I cannot find a way to combine a string and the $id from the foreach to generate a variable that the Sass compiler will understand. Basically, I want the foreach to create a new variable by combining $sportmenu_ and the value of $id. Not sure if this is possible.
My solution doesn't work, since $sportmenu_ doesn't exist. I've tried combining a string and the $id as: "$sportmenu_"#{$id} but this just creates a string followed by the value of $id.
Thanks!
Why can't you do something like this? Using maps
$list: (1: #23765c, 3: #5e6b34, 4: #7d7e6c, 6: #786857, 8: #487a91);
//$id grabs your map index, and $val grabs your hex color values
#each $id, $val in $list {
#sportmenu_#{$id} {
.menu-sport-item {
background-color: #{$val};
}
}
}
You can try it out on SassMeister. Which outputs :
#sportmenu_1 .menu-sport-item {
background-color: #23765c;
}
.....
All I am doing over here is nothing but using maps(kind of hash), looping over, and printing colors accordingly.
Also, what you were trying won't work. You are trying to interpolate two variables and trying to create a dynamic variable name on compile.
#{$sportmenu_}#{$id}; //will throw undefined $sprotsmenu_ error

OpenVx immediate code and Graphs not giving similar results

I have converted the following OpenVx Sobel immediate code to Graph based . But the results done match.
Immediate code works fine, it gives proper result. Whereas Graph code takes "longer" than the immediate code for a single image and produces wrong results too.
So is my conversion correct ?
Immediate Code :
/* Intermediate images. */
vx_image dx = vxCreateImage(context, width, height, VX_DF_IMAGE_S16);
vx_image dy = vxCreateImage(context, width, height, VX_DF_IMAGE_S16);
vx_image mag = vxCreateImage(context, width, height, VX_DF_IMAGE_S16);
/* Perform Sobel convolution. */
if (vxuSobel3x3(context,image,dx, dy)!=VX_SUCCESS)
{
printf("ERROR: failed to do sobel!\n");
}
/* Calculate magnitude from gradients. */
if (vxuMagnitude(context,dx,dy,mag)!=VX_SUCCESS)
{
printf("ERROR: failed to do magnitude!\n");
}
//Convert result back to U8 image.
if (vxuConvertDepth(context,mag,image,VX_CONVERT_POLICY_WRAP,0)!=VX_SUCCESS)
{
printf("ERROR: failed to do color convert!\n");
}
Graph based code of the above immediate code
vx_graph graph = vxCreateGraph( context );
vx_image intermediate1 = vxCreateVirtualImage( graph, width, height, VX_DF_IMAGE_S16 );
vx_image intermediate2 = vxCreateVirtualImage( graph, width, height, VX_DF_IMAGE_S16 );
vx_image intermediate3 = vxCreateVirtualImage( graph, width, height, VX_DF_IMAGE_S16 );
if(vxSobel3x3Node(graph,image,intermediate1,intermediate2) == 0)
{
printf("FAILED TO Create 1 graph node");
}
if(vxMagnitudeNode(graph,intermediate1,intermediate2,intermediate3) == 0)
{
printf("ERROR: failed to do magnitude!\n");
}
if(vxConvertDepthNode(graph,intermediate3,image,VX_CONVERT_POLICY_WRAP,0) == 0)
{
printf("ERROR failed to do color convert");
}
vxVerifyGraph( graph );
vxProcessGraph( graph ); // run in a loop
At first, you should inspect the result of the vxVerifyGraph. Like this:
vx_status stat = vxVerifyGraph(graph);
if (stat != VX_SUCCESS)
printf("Graph failed (%d)\n", stat);
else
vxProcessGraph(graph);
For your example it returns "-4" for the vxConvertDepthNode function.
vx_types.h says:
VX_ERROR_NOT_SUFFICIENT = -4, /*!< \brief Indicates that the given graph has failed verification due to an insufficient
number of required parameters, which cannot be automatically created.
Typically this indicates required atomic parameters. \see
vxVerifyGraph. */
The proper use is (I don't remember where we got it):
vx_int32 shift = 0;
vx_scalar sshift = vxCreateScalar(context, VX_TYPE_INT32, &shift);
if(vxConvertDepthNode(graph,intermediate3,image,VX_CONVERT_POLICY_WRAP,sshift) == 0) {
printf("ERROR failed to do color convert");
}
Now vxVerifyGraph returns "-18".
VX_ERROR_INVALID_GRAPH = -18, /*!< \brief Indicates that the supplied graph has invalid connections (cycles). */
That's what about #jet47 says. You should use another image for output:
if(vxConvertDepthNode(graph,intermediate3,imageOut,VX_CONVERT_POLICY_WRAP,sshift ) == 0) {
printf("ERROR failed to do color convert");
}
Now it works fine.
Please check return code of vxVerifyGraph. You graph contains a loop (image object), which is forbidden, so it should fail on verification stage. To fix this use another image for vxConvertDepthNode output.

Drupal: How to override a function from a contrib module

I am using a module that builds a price table for Drupal Commerce items. There is a function that formats the table headers:
/**
* Helper function that takes care of the quantity displayed in the headers of
* the price table.
*/
function commerce_price_table_display_quantity_headers($item) {
// Set the quantity text to unlimited if it's -1.
$max_qty = $item['max_qty'] == -1 ? t('Unlimited') : $item['max_qty'];
// If max and min qtys are the same, only show one.
if ($item['min_qty'] == $max_qty) {
$quantity_text = $item['min_qty'];
}
else {
$quantity_text = $item['min_qty'] . ' - ' . $max_qty;
}
return $quantity_text;
}
As you can see, this is not a theme function where I can override it in template.php but I can to tweak some of the output.
How can I redefine this function so I can chop and change a few things?
My work so far...
So far, I have tried to create it as a seperate module with a few subtle changes to show if it's working or not, but it's not overriding any of the output.
Info file
; $id$
name = Price Table: Tweaked Display
description = A different layout for the price table as shown on the product display nodes
package = Commerce (contrib)
core = 7.x
dependencies[] = commerce_product
dependencies[] = commerce_price
dependencies[] = commerce_price_table
Module File
/**
* Override of the helper function that takes care of the quantity displayed in the headers of
* the price table.
*/
function commerce_table_tweak_display_quantity_headers($item) {
// Set the quantity text to unlimited if it's -1.
$max_qty = $item['max_qty'] == -1 ? t('Unlimited gnhh') : $item['max_qty'];
// If max and min qtys are the same, only show one.
if ($item['min_qty'] == $max_qty) {
$quantity_text = $item['min_qty'];
}
else {
$quantity_text = $item['min_qty'] . ' - this is working - ' . $max_qty;
}
return $quantity_text;
}
Most drupal modules I believe have a hook_function (or at least ones that are hookable) I don't do this much so I would search the drupal api for how to hook functions and if your module will support it.

Resources