@@ -42,21 +42,38 @@ module ccc_entdaa
42
42
AckRsvdByte = 'h3 ,
43
43
SendNack = 'h4 ,
44
44
SendID = 'h5 ,
45
- LostArbitration = 'h6 ,
46
- ReceiveAddr = 'h7 ,
47
- AckAddr = 'h8 ,
48
- Done = 'h9 ,
49
- Error = 'ha
45
+ PrepareIDBit = 'h6 ,
46
+ SendIDBit = 'h7 ,
47
+ LostArbitration = 'h8 ,
48
+ ReceiveAddr = 'h9 ,
49
+ AckAddr = 'ha ,
50
+ Done = 'hb ,
51
+ Error = 'hc
50
52
} state_e ;
51
53
52
54
state_e state_q, state_d;
53
55
logic [5 : 0 ] id_bit_count;
56
+ logic load_id_counter, tick_id_counter;
54
57
logic reserved_word_det;
55
58
56
59
logic parity_ok;
57
60
58
61
assign reserved_word_det = (bus_rx_data_i[7 : 1 ] == 7'h7e && bus_rx_data_i[0 ] == 1'b1 );
59
62
63
+ always_ff @ (posedge clk_i or negedge rst_ni) begin : id_bit_counter
64
+ if (! rst_ni) begin
65
+ id_bit_count <= '0 ;
66
+ end else begin
67
+ if (load_id_counter) begin
68
+ id_bit_count <= 6'd48 ;
69
+ end else if (tick_id_counter) begin
70
+ id_bit_count <= id_bit_count - 1'b1 ;
71
+ end else begin
72
+ id_bit_count <= id_bit_count;
73
+ end
74
+ end
75
+ end
76
+
60
77
always_comb begin : state_functions
61
78
state_d = state_q;
62
79
unique case (state_q)
@@ -78,20 +95,34 @@ module ccc_entdaa
78
95
end
79
96
AckRsvdByte: begin
80
97
if (bus_tx_done_i) begin
81
- state_d = SendID;
82
- end
98
+ state_d = SendID;
99
+ end
83
100
end
84
101
SendNack: begin
85
102
if (bus_tx_done_i) begin
86
103
state_d = Error;
87
- end
104
+ end
88
105
end
89
106
SendID: begin
107
+ // load ID counter
108
+ state_d = PrepareIDBit;
109
+ end
110
+ PrepareIDBit: begin
111
+ if (id_bit_count != '0 ) begin
112
+ state_d = SendIDBit;
113
+ end
114
+ end
115
+ SendIDBit: begin
90
116
if (bus_tx_done_i) begin
91
117
// our Id was overwritten by some other device
92
118
if (arbitration_lost_i) begin
93
119
state_d = LostArbitration;
94
120
end
121
+ if (id_bit_count == '0 ) begin
122
+ state_d = ReceiveAddr;
123
+ end else begin
124
+ state_d = PrepareIDBit;
125
+ end
95
126
end
96
127
end
97
128
LostArbitration: begin
@@ -120,6 +151,9 @@ module ccc_entdaa
120
151
bus_tx_req_bit_o = '0 ;
121
152
bus_tx_req_value_o = '0 ;
122
153
bus_tx_sel_od_pp_o = '0 ;
154
+
155
+ load_id_counter = '0 ;
156
+ tick_id_counter = '0 ;
123
157
unique case (state_q)
124
158
Idle: begin
125
159
end
@@ -138,6 +172,14 @@ module ccc_entdaa
138
172
bus_tx_req_value_o = '1 ;
139
173
end
140
174
SendID: begin
175
+ load_id_counter = '1 ;
176
+ end
177
+ PrepareIDBit: begin
178
+ tick_id_counter = '1 ;
179
+ end
180
+ SendIDBit: begin
181
+ bus_tx_req_bit_o = '1 ;
182
+ bus_tx_req_value_o = id_i[id_bit_count];
141
183
end
142
184
ReceiveAddr: begin
143
185
bus_rx_req_byte_o = '1 ;
0 commit comments