-
Notifications
You must be signed in to change notification settings - Fork 0
/
sensor_ctrl.sv
66 lines (58 loc) · 1.36 KB
/
sensor_ctrl.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//================================================
// Auther: Hsieh Hsien-Hua (Henry)
// Filename: sensor_ctrl.sv
// Description: High speed sensor controller
// Version: 0.1
//================================================
module sensor_ctrl(
input clk,
input rst,
// Core inputs
input sctrl_en,
input sctrl_clear,
input [5:0] sctrl_addr,
// Core outputs
output logic sctrl_interrupt,
output logic [31:0] sctrl_out,
// Sensor inputs
input sensor_ready,
input [31:0] sensor_out,
// Sensor outputs
output logic sensor_en
);
logic [31:0] mem[0:63];
logic [5:0] counter;
logic full;
always_ff@(posedge clk)
begin
if (rst)
counter <= 6'd0;
else if (sctrl_clear)
counter <= 6'd0;
else if (sctrl_en && (~full) && sensor_ready)
counter <= counter + 6'b1;
end
always_comb
begin
sctrl_out = mem[sctrl_addr];
sensor_en = (sctrl_en && (~full) && (~sctrl_clear));
sctrl_interrupt = full;
end
always_ff@(posedge clk)
begin
if (rst)
for (int i=0; i<64; i++)
mem[i] <= 32'd0;
else if (sctrl_en && (~full) && sensor_ready)
mem[counter] <= sensor_out;
end
always_ff@(posedge clk)
begin
if (rst)
full <= 1'b0;
else if (sctrl_clear)
full <= 1'b0;
else if (sctrl_en && (counter == 6'd63) && sensor_ready)
full <= 1'b1;
end
endmodule