1 | |
---|
2 | function count_ones_32b_config(this_block) |
---|
3 | |
---|
4 | this_block.setTopLevelLanguage('Verilog'); |
---|
5 | |
---|
6 | this_block.setEntityName('count_ones_32b'); |
---|
7 | |
---|
8 | % System Generator has to assume that your entity has a combinational feed through; |
---|
9 | % if it doesn't, then comment out the following line: |
---|
10 | this_block.tagAsCombinational; |
---|
11 | |
---|
12 | this_block.addSimulinkInport('x'); |
---|
13 | |
---|
14 | this_block.addSimulinkOutport('num_ones'); |
---|
15 | |
---|
16 | num_ones_port = this_block.port('num_ones'); |
---|
17 | num_ones_port.setType('UFix_6_0'); |
---|
18 | |
---|
19 | % ----------------------------- |
---|
20 | if (this_block.inputTypesKnown) |
---|
21 | % do input type checking, dynamic output type and generic setup in this code block. |
---|
22 | |
---|
23 | if (this_block.port('x').width ~= 32); |
---|
24 | this_block.setError('Input data type for port "x" must have width=32.'); |
---|
25 | end |
---|
26 | |
---|
27 | end % if(inputTypesKnown) |
---|
28 | % ----------------------------- |
---|
29 | |
---|
30 | % ----------------------------- |
---|
31 | if (this_block.inputRatesKnown) |
---|
32 | setup_as_single_rate(this_block,'clk','ce') |
---|
33 | end % if(inputRatesKnown) |
---|
34 | % ----------------------------- |
---|
35 | |
---|
36 | % (!) Set the inout port rate to be the same as the first input |
---|
37 | % rate. Change the following code if this is untrue. |
---|
38 | uniqueInputRates = unique(this_block.getInputRates); |
---|
39 | |
---|
40 | |
---|
41 | % Add addtional source files as needed. |
---|
42 | % |------------- |
---|
43 | % | Add files in the order in which they should be compiled. |
---|
44 | % | If two files "a.vhd" and "b.vhd" contain the entities |
---|
45 | % | entity_a and entity_b, and entity_a contains a |
---|
46 | % | component of type entity_b, the correct sequence of |
---|
47 | % | addFile() calls would be: |
---|
48 | % | this_block.addFile('b.vhd'); |
---|
49 | % | this_block.addFile('a.vhd'); |
---|
50 | % |------------- |
---|
51 | |
---|
52 | % this_block.addFile(''); |
---|
53 | % this_block.addFile(''); |
---|
54 | this_block.addFile('blackboxes/count_ones_32b.v'); |
---|
55 | |
---|
56 | return; |
---|
57 | |
---|
58 | |
---|
59 | % ------------------------------------------------------------ |
---|
60 | |
---|
61 | function setup_as_single_rate(block,clkname,cename) |
---|
62 | inputRates = block.inputRates; |
---|
63 | uniqueInputRates = unique(inputRates); |
---|
64 | if (length(uniqueInputRates)==1 & uniqueInputRates(1)==Inf) |
---|
65 | block.addError('The inputs to this block cannot all be constant.'); |
---|
66 | return; |
---|
67 | end |
---|
68 | if (uniqueInputRates(end) == Inf) |
---|
69 | hasConstantInput = true; |
---|
70 | uniqueInputRates = uniqueInputRates(1:end-1); |
---|
71 | end |
---|
72 | if (length(uniqueInputRates) ~= 1) |
---|
73 | block.addError('The inputs to this block must run at a single rate.'); |
---|
74 | return; |
---|
75 | end |
---|
76 | theInputRate = uniqueInputRates(1); |
---|
77 | for i = 1:block.numSimulinkOutports |
---|
78 | block.outport(i).setRate(theInputRate); |
---|
79 | end |
---|
80 | block.addClkCEPair(clkname,cename,theInputRate); |
---|
81 | return; |
---|
82 | |
---|
83 | % ------------------------------------------------------------ |
---|
84 | |
---|