-
Notifications
You must be signed in to change notification settings - Fork 0
/
Temp.bsv
86 lines (65 loc) · 1.77 KB
/
Temp.bsv
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package Temp;
import I2C::*;
import I2CUtil::*;
import StmtFSM::*;
interface Temp;
interface I2C_Pins i2c;
method Stmt init();
method Stmt read_val(Reg#(Bit#(8)) result);
endinterface
module mkTemp #(parameter Bit#(7) slave_addr) (Temp);
I2C temp <- mkI2C(125);
method Stmt init() = seq
i2c_write_byte(temp, slave_addr, 8'h0A, 8'b00010100);
endseq;
method Stmt read_val(Reg#(Bit#(8)) result);
seq
i2c_read_byte(temp, slave_addr, 8'h01);
action
let data <- i2c_get_byte(temp);
result <= data;
endaction
endseq;
endmethod
interface I2C_Pins i2c = temp.i2c;
endmodule: mkTemp
interface TempReaderIfc;
(* prefix = "TEMP_I2C" *)
interface I2C_Pins i2c;
(* always_enabled, always_ready *)
method Bit#(8) get_temp ();
endinterface
(* synthesize *)
module mkTempReader (TempReaderIfc);
Reg#(Bit#(8)) cur_temp <- mkReg(0);
Reg#(Bit#(32)) cnt <- mkReg(50000000);
Temp temp <- mkTemp(7'b0011100); //DE10 Temp IC addr 0x1C
PulseWire pw <- mkPulseWire;
(* fire_when_enabled, no_implicit_conditions *)
rule counter (cnt > 0);
cnt <= cnt-1;
endrule
(* fire_when_enabled, no_implicit_conditions *)
rule counter_rst (cnt == 0 && pw);
cnt <= 50000000;
endrule
Stmt test =
seq
await(cnt == 0);
temp.init();
while(True) seq
temp.read_val(cur_temp);
pw.send();
await(cnt == 0);
endseq
endseq;
FSM main <- mkFSM( test );
rule run_main;
main.start();
endrule
interface I2C_Pins i2c = temp.i2c;
method Bit#(8) get_temp();
return cur_temp;
endmethod
endmodule
endpackage: Temp