Module's Hierarchy where uart_receiver.v=ModuleA, RSD.v=ModuleB, uart_transmitter.V=ModuleC
Suppose I want to Instantiate ModuleA with inputs from different modules, B, and the name of inputs are: WR_EN from moduleB and RD_EN, DT from moduleC
module A(
input wr_EN,
input rd_EN,
input DT,
output out
);
I tried to do the below with no success, in ISE Xilinx with Verilog
B MODULE
module B(...)
assign wr_EN = 1;
...
// Now call module A from B:
module A A_instance(.wr_EN(wr_EN) );
C MODULE
module C(...)
...
assign rd_EN = 0;
assign DT = 1;
....
// And then call module A from C
module A A_instance(.rd_EN(rd_EN), .DT(DT) );
If I call module instances with same names the program doesn't make a second instance, despite the fact that I want one.
I searched but I haven't found similar example
I tried to clean up your question but I'm still not sure you intend to have two instances of A (one in B the other in C) or if your are trying to share one instance of A between B and C.
An instance represents a physical piece of hardware. The same instance cannot be shared between other module instances. You can route nets to connect instances. For example:
module TOP(...);
...
A A_instance( .wr_EN(wr_EN), .rd_EN(rd_EN), .DT(DT), .out(out) );
B B_instance( .wr_EN(wr_EN), ... );
C C_instance( .rd_EN(rd_EN), .DT(DT), ... );
endmodule
You can place A inside of B or C and route the input from the other through a parent level.
module B(
input rd_EN, // output for C connected at top
input DT, // output for C connected at top
...
);
...
assign wr_EN = 1;
A A_instance( .wr_EN(wr_EN), .rd_EN(rd_EN), .DT(DT), .out(out) );
endmodule
or
module C(
input wr_EN, // output for B connected at top
...
);
...
assign rd_EN = 0;
assign DT = 1;
A A_instance( .wr_EN(wr_EN), .rd_EN(rd_EN), .DT(DT), .out(out) );
endmodule
If you placed an instance of A in B and C, then you have two independent instances, even if the input are from a common source.
Related
I have 2 different data sources that I want to combine.
val source1: Single<List<Type1>> = Single.fromCallable({
api.getSource1()
})!!
val source2: Single<List<Type2>> = Single.fromCallable({
api.getSource2()
})!!
//PS.
class Type0()
class Type1 : Type0()
class Type2 : Type0()
I want to join 2 sources and get
Single<List<Type0>>
so I could do further processing of the data, I think I should use .zip method, but I am not sure how to do it correctly.
The zipWith operator works well here, as it lets you provide a BiFunction that describes how to combine the two Single instances (in this case, we just concatenate them with the plus operator):
val zipped: Single<List<Type0>> = source1.zipWith(source2, BiFunction { l1, l2 -> l1 + l2 })
We know that if we need to define the column names of a table using pytables we can do it by the following way:
class Project(IsDescription):
alpha = StringCol(20)
beta = StringCol(20)
gamma = StringCol(20)
where alpha, beta and gamma are the desired column names of the table.
But suppose I would like to use a list "ColumnNames_list" which contains the column names as follows:
ColumnNames_list[0] = alpha, ColumnNames_list[1] = beta, ColumnNames_list[2] = gamma
Then how should I define the above class "Project"?
I tried with the following:
ColumnNames_list = []
ColumnNames_list[0] = alpha
ColumnNames_list[1] = beta
ColumnNames_list[2] = gamma
class Project(IsDescription):
for i in range (0, 10):
ColumnNames_list[i] = StringCol(20)
It's showing the error:
TypeError: Passing an incorrect value to a table column. Expected a Col (or subclass) instance and got: "2". Please make use of the Col(), or descendant, constructor to properly initialize columns.
Define the variable first outside the loop:
ColumnNames_list = []
for i in range (0, 10):
ColumnNames_list.append(StringCol(20))
The reason I'm using append() rather than ColumnNames_list[i] = StringCol(20) is because you can't assign to an index that doesn't exist. Trying to assign ColumnNames_list[1] before it exists throws an IndexError.
The error is in the function below, I'm trying to generate 2 measures of entropy (the latter removes all events with <5 frequency).
My error:
ERROR 1200: Cannot expand macro 'TOTUPLE'. Reason: Macro must be defined before expansion.
Which is weird, because TOTUPLE is a built-in function. Other pig scripts use TOTUPLE with no problems.
Code:
define dual_entropies (search, field) returns entropies {
summary = summary_total($search, $field);
entr1 = count_sum_entropy(summary, $field);
summary = filter summary by events >= 5L;
entr2 = count_sum_entropy(summary, $field);
$entropies = TOTUPLE(entr1, entr2);
};
Note that entr1 and entr2 are both single numbers, not vectors of numbers - I suspect that's part of the issue.
I ran into similar confusions. I'm not sure if it's true in general but Pig only liked TOTUPLE when it's part of a FOREACH operation. I worked around by doing group by all, which returns a bag with a single tuple in it, followed by a FOREACH .. GENERATE such as:
B = group A ALL;
C = foreach B generate 'x', 2, TOTUPLE('a', 'b', 'c');
dump C;
...
(x,2,(hi,2,3))
Perhaps this will help
I'm using Gforth, and I want to create a word in a definition. In the cmd line of Gforth I can type:
create foo
ok
Or more specifically, I defined an array function that expects a size on the stack and creates a word with the address to that array:
: array ( n -- ) ( i -- addr)
create cells allot
does> cells + ;
So if I type 10 array foo I can then use foo later.
But if I were to write 10 array foo within another definition it gives me a compilation error. I've tried replacing foo with s" foo" which compiles, but it blows up at run time, saying:
Attempt to use zero-length string as a name
Is there a way to do this?
One way to do it in gforth:
: bar 10 s" foo" ['] array execute-parsing ;
Other implementations do it differently, e.g. http://pfe.sourceforge.net/words/w-header-015.html
It's not easy to do in Standard Forth, but this may be good enough:
: bar 10 s" array foo" evaluate ;
I guess most of what you want to do can be done by defining words, i.e. using create ... does> ... This allows you to define a word with specialized behaviour.
E.g.:
: 2const create , , does> 2# ;
can be used to create double constants like 2 3 2const a-double (that stashes 2 and 3 away in a-double) and then a-double pushes two values (2 3).
Basically:
I am making a game in the LÖVE Engine where you click to create blocks
Every time you click, a block gets created at your Mouse X and Mouse Y
But, I can only get one block to appear, because I have to name that block (or table) 'object1'
Is there any way to create table after table with increasing values? (like object1{}, object2{}, object3{}, etc... But within the main table, 'created_objects')
But only when clicked, which I suppose rules out the looping part (but if it doesn't please tell me)
Here's my code so far, but it doesn't compile.
function object_create(x, y, id) **--Agruments telling the function where the box should spawn and what the ID of the box is (variable 'obj_count' which increases every time a box is spawned)**
currobj = "obj" .. id **--Gives my currently created object a name**
crob.[currobj] = {} **--Is supposed to create a table for the current object, which holds all of its properties. **
crob.[currobj].body = love.physics.newBody(world, x, y, "dynamic")
crob.[currobj].shape = love.physics.newRectangleShape(30, 30)
crob.[currobj].fixture = love.physics.newFixture(crob.[currobj].body, crob.[currobj].shape, 1) **--The properties**
crob.[currobj].fixture:setRestitution(0.3)
But what should I replace [currobj] with?
Solved
Found what I was looking for. Here's the code if people are wondering:
function block_create(x, y, id) --(the mouse x and y, and the variable that increases)
blocks[id] = {}
blocks[id][1] = love.physics.newBody(world, x, y, "dynamic")
blocks[id][2] = love.physics.newRectangleShape(45, 45)
blocks[id][3] = love.physics.newFixture(blocks[id][1], blocks[id][2])
blocks[id][3]:setRestitution(0.2)
blocks[id][4] = math.random(0, 255) --The Color
blocks[id][5] = math.random(0, 255)
blocks[id][6] = math.random(0, 255)
blockcount = blockcount + 1
i would probably do something like this.
local blocks = {} -- equivalent of your crob table
function create_block(x, y)
local block = funcToCreateBlock() -- whatever code to create the block
table.insert(blocks, block)
return block
end
if you wanted to get a reference to the block you just created with the function, just capture it.
-- gives you the new block, automatically adds it to the list of created blocks
local new_block = create_block(0, 10)
that sticks block objects in your block table and automatically gives each one a numeric index in the table. so if you called create_block() 3 times for 3 different mouse clicks, the blocks table would look like this:
blocks = {
[1] = blockobj1,
[2] = blockobj2,
[3] = blockobj3
}
you could get the second block obj from the blocks table by doing
local block2 = blocks[2]
or you could loop over all the blocks in the table using pairs or ipairs
for idx, block in pairs(blocks) do
-- do something with each block
end
sorry if this doesn't exactly answer your question. but from what you wrote, there didn't seem to be a real reason why you'd need to name the blocks anything specific in the crob table.
If you want those tables to be global, then you can do something like:
sNameOfTable = "NAME"
_G[sNameOfTable] = {1,2}
and then you will have a table variable NAME as depicted here (Codepad).
Otherwise, if you want it to be a child to some other table, something like this would also do:
tTbl = {}
for i = 1, 20 do
local sName = string.format( "NAME%02d", i )
tTbl[sName] = {1,2}
end
for i, v in pairs(tTbl) do
print( i, v )
end
Don't worry about the unsorted output here(Codepad). Lua tables with indexes need not be sorted to be used.