1 | module histogram
|
---|
2 | (
|
---|
3 | input wire clock, frame, reset,
|
---|
4 |
|
---|
5 | input wire [40:0] cfg_data,
|
---|
6 |
|
---|
7 | input wire hst_good,
|
---|
8 | input wire [11:0] hst_data,
|
---|
9 |
|
---|
10 | input wire bus_ssel, bus_wren,
|
---|
11 | input wire [12:0] bus_addr,
|
---|
12 | input wire [15:0] bus_mosi,
|
---|
13 |
|
---|
14 | output wire [15:0] bus_miso,
|
---|
15 | output wire bus_busy
|
---|
16 | );
|
---|
17 |
|
---|
18 | // signal declaration
|
---|
19 | reg [3:0] int_case_reg, int_case_next;
|
---|
20 | reg int_wren_reg, int_wren_next;
|
---|
21 | reg [11:0] int_addr_reg, int_addr_next;
|
---|
22 | reg [31:0] int_data_reg, int_data_next;
|
---|
23 |
|
---|
24 | reg [12:0] bus_addr_reg, bus_addr_next;
|
---|
25 | reg [15:0] bus_miso_reg, bus_miso_next;
|
---|
26 |
|
---|
27 | reg bus_wren_reg, bus_wren_next;
|
---|
28 | reg [15:0] bus_mosi_reg, bus_mosi_next;
|
---|
29 |
|
---|
30 | wire [31:0] q_a_wire;
|
---|
31 | wire [15:0] q_b_wire;
|
---|
32 |
|
---|
33 | altsyncram #(
|
---|
34 | .address_reg_b("CLOCK0"),
|
---|
35 | .clock_enable_input_a("BYPASS"),
|
---|
36 | .clock_enable_input_b("BYPASS"),
|
---|
37 | .clock_enable_output_a("BYPASS"),
|
---|
38 | .clock_enable_output_b("BYPASS"),
|
---|
39 | .indata_reg_b("CLOCK0"),
|
---|
40 | .intended_device_family("Cyclone III"),
|
---|
41 | .lpm_type("altsyncram"),
|
---|
42 | .numwords_a(4096),
|
---|
43 | .numwords_b(8192),
|
---|
44 | .operation_mode("BIDIR_DUAL_PORT"),
|
---|
45 | .outdata_aclr_a("NONE"),
|
---|
46 | .outdata_aclr_b("NONE"),
|
---|
47 | .outdata_reg_a("CLOCK0"),
|
---|
48 | .outdata_reg_b("CLOCK0"),
|
---|
49 | .power_up_uninitialized("FALSE"),
|
---|
50 | .read_during_write_mode_mixed_ports("OLD_DATA"),
|
---|
51 | .read_during_write_mode_port_a("NEW_DATA_NO_NBE_READ"),
|
---|
52 | .read_during_write_mode_port_b("NEW_DATA_NO_NBE_READ"),
|
---|
53 | .widthad_a(12),
|
---|
54 | .widthad_b(13),
|
---|
55 | .width_a(32),
|
---|
56 | .width_b(16),
|
---|
57 | .width_byteena_a(1),
|
---|
58 | .width_byteena_b(1),
|
---|
59 | .wrcontrol_wraddress_reg_b("CLOCK0")) hst_ram_unit(
|
---|
60 | .wren_a(int_wren_reg),
|
---|
61 | .clock0(clock),
|
---|
62 | .wren_b(bus_wren_reg),
|
---|
63 | .address_a(int_addr_reg),
|
---|
64 | .address_b(bus_addr_reg),
|
---|
65 | .data_a(int_data_reg),
|
---|
66 | .data_b(bus_mosi_reg),
|
---|
67 | .q_a(q_a_wire),
|
---|
68 | .q_b(q_b_wire),
|
---|
69 | .aclr0(1'b0),
|
---|
70 | .aclr1(1'b0),
|
---|
71 | .addressstall_a(1'b0),
|
---|
72 | .addressstall_b(1'b0),
|
---|
73 | .byteena_a(1'b1),
|
---|
74 | .byteena_b(1'b1),
|
---|
75 | .clock1(1'b1),
|
---|
76 | .clocken0(1'b1),
|
---|
77 | .clocken1(1'b1),
|
---|
78 | .clocken2(1'b1),
|
---|
79 | .clocken3(1'b1),
|
---|
80 | .eccstatus(),
|
---|
81 | .rden_a(1'b1),
|
---|
82 | .rden_b(1'b1));
|
---|
83 |
|
---|
84 | // body
|
---|
85 | always @(posedge clock)
|
---|
86 | begin
|
---|
87 | if (reset)
|
---|
88 | begin
|
---|
89 | int_wren_reg <= 1'b1;
|
---|
90 | int_addr_reg <= 12'd0;
|
---|
91 | int_data_reg <= 32'd0;
|
---|
92 | int_case_reg <= 4'b1;
|
---|
93 | bus_addr_reg <= 13'd0;
|
---|
94 | bus_miso_reg <= 16'd0;
|
---|
95 | bus_wren_reg <= 1'b0;
|
---|
96 | bus_mosi_reg <= 16'd0;
|
---|
97 | end
|
---|
98 | else
|
---|
99 | begin
|
---|
100 | int_wren_reg <= int_wren_next;
|
---|
101 | int_addr_reg <= int_addr_next;
|
---|
102 | int_data_reg <= int_data_next;
|
---|
103 | int_case_reg <= int_case_next;
|
---|
104 | bus_addr_reg <= bus_addr_next;
|
---|
105 | bus_miso_reg <= bus_miso_next;
|
---|
106 | bus_wren_reg <= bus_wren_next;
|
---|
107 | bus_mosi_reg <= bus_mosi_next;
|
---|
108 | end
|
---|
109 | end
|
---|
110 |
|
---|
111 | always @*
|
---|
112 | begin
|
---|
113 | bus_addr_next = bus_addr_reg;
|
---|
114 | bus_miso_next = bus_miso_reg;
|
---|
115 |
|
---|
116 | bus_wren_next = 1'b0;
|
---|
117 | bus_mosi_next = bus_mosi_reg;
|
---|
118 |
|
---|
119 | if (bus_ssel)
|
---|
120 | begin
|
---|
121 | bus_miso_next = q_b_wire;
|
---|
122 | bus_addr_next = bus_addr;
|
---|
123 | bus_wren_next = bus_wren;
|
---|
124 | if (bus_wren)
|
---|
125 | begin
|
---|
126 | bus_mosi_next = bus_mosi;
|
---|
127 | end
|
---|
128 | end
|
---|
129 | end
|
---|
130 |
|
---|
131 | always @*
|
---|
132 | begin
|
---|
133 | int_wren_next = int_wren_reg;
|
---|
134 | int_addr_next = int_addr_reg;
|
---|
135 | int_data_next = int_data_reg;
|
---|
136 | int_case_next = int_case_reg;
|
---|
137 |
|
---|
138 | case (int_case_reg)
|
---|
139 | 0:
|
---|
140 | begin
|
---|
141 | int_wren_next = 1'b0;
|
---|
142 | int_addr_next = 12'd0;
|
---|
143 | int_data_next = 32'd0;
|
---|
144 | end
|
---|
145 |
|
---|
146 | 1:
|
---|
147 | begin
|
---|
148 | // write zeros
|
---|
149 | if (&int_addr_reg)
|
---|
150 | begin
|
---|
151 | int_wren_next = 1'b0;
|
---|
152 | int_case_next = 4'd2;
|
---|
153 | end
|
---|
154 | else
|
---|
155 | begin
|
---|
156 | int_addr_next = int_addr_reg + 12'd1;
|
---|
157 | end
|
---|
158 | end
|
---|
159 |
|
---|
160 | 2:
|
---|
161 | begin
|
---|
162 | int_wren_next = 1'b0;
|
---|
163 | if (&int_data_reg)
|
---|
164 | begin
|
---|
165 | int_case_next = 4'd0;
|
---|
166 | end
|
---|
167 | else if (frame & hst_good)
|
---|
168 | begin
|
---|
169 | int_addr_next = hst_data;
|
---|
170 | int_case_next = 4'd3;
|
---|
171 | end
|
---|
172 | end
|
---|
173 |
|
---|
174 | 3:
|
---|
175 | begin
|
---|
176 | int_case_next = 4'd4;
|
---|
177 | end
|
---|
178 |
|
---|
179 | 4:
|
---|
180 | begin
|
---|
181 | int_case_next = 4'd5;
|
---|
182 | end
|
---|
183 |
|
---|
184 | 5:
|
---|
185 | begin
|
---|
186 | int_wren_next = 1'b1;
|
---|
187 | int_data_next = q_a_wire + 32'd1;
|
---|
188 | int_case_next = 4'd2;
|
---|
189 | end
|
---|
190 |
|
---|
191 | default:
|
---|
192 | begin
|
---|
193 | int_wren_next = 1'b0;
|
---|
194 | int_addr_next = 12'd0;
|
---|
195 | int_data_next = 32'd0;
|
---|
196 | int_case_next = 4'd0;
|
---|
197 | end
|
---|
198 | endcase
|
---|
199 | end
|
---|
200 |
|
---|
201 | // output logic
|
---|
202 | assign bus_miso = bus_miso_reg;
|
---|
203 | assign bus_busy = 1'b0;
|
---|
204 | endmodule
|
---|