Skip to content

Commit ff7aaaa

Browse files
committed
wire up entdaa_ccc module
1 parent bc15a63 commit ff7aaaa

File tree

4 files changed

+232
-43
lines changed

4 files changed

+232
-43
lines changed

src/ctrl/ccc.sv

Lines changed: 101 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ module ccc
115115
input logic bus_rx_done_i,
116116
output logic bus_rx_req_bit_o,
117117
output logic bus_rx_req_byte_o,
118+
input logic arbitration_lost_i,
118119

119120
// Addr match interface
120121
input logic [6:0] target_sta_address_i,
@@ -334,6 +335,29 @@ module ccc
334335
end
335336
end
336337

338+
// Mux TX access between regular CCC and ENTDAA
339+
logic entdaa_tx_req_bit;
340+
logic entdaa_tx_req_byte;
341+
logic entdaa_tx_req_value;
342+
logic entdaa_tx_sel_od_pp;
343+
logic entdaa_rx_req_bit;
344+
logic entdaa_rx_req_byte;
345+
logic ccc_tx_req_bit;
346+
logic ccc_tx_req_byte;
347+
logic ccc_tx_req_value;
348+
logic ccc_tx_sel_od_pp;
349+
logic ccc_rx_req_bit;
350+
logic ccc_rx_req_byte;
351+
352+
always_comb begin: mux_bus_access
353+
bus_tx_req_bit_o = entdaa_o ? entdaa_tx_req_bit : ccc_tx_req_bit;
354+
bus_tx_req_byte_o = entdaa_o ? entdaa_tx_req_byte : ccc_tx_req_byte;
355+
bus_tx_req_value_o = entdaa_o ? entdaa_tx_req_value : ccc_tx_req_value;
356+
bus_tx_sel_od_pp_o = entdaa_o ? entdaa_tx_sel_od_pp : ccc_tx_sel_od_pp;
357+
bus_rx_req_bit_o = entdaa_o ? entdaa_rx_req_bit : ccc_rx_req_bit;
358+
bus_rx_req_byte_o = entdaa_o ? entdaa_rx_req_byte : ccc_rx_req_byte;
359+
end
360+
337361
logic have_defining_byte;
338362
always_comb begin : defining_byte_ccc
339363
case (command_code)
@@ -346,7 +370,6 @@ module ccc
346370
endcase
347371
end
348372

349-
// TODO: Handle Bcast CCCs
350373
typedef enum logic [7:0] {
351374
Idle,
352375
WaitCCC,
@@ -364,12 +387,14 @@ module ccc
364387
TxDataTbit,
365388
WaitForBusCond,
366389
WaitForStop,
367-
DoneCCC
390+
DoneCCC,
391+
HandleENTDAA
368392
} state_e;
369393

370394
state_e state_q, state_d;
371395

372396
assign last_tbit_valid = (state_q == RxTbit || state_q == RxDataTbit) && bus_rx_done_i;
397+
assign entdaa_o = (state_q == HandleENTDAA);
373398

374399
always_ff @(posedge clk_i or negedge rst_ni) begin : register_tbit
375400
if (~rst_ni) begin
@@ -400,6 +425,8 @@ module ccc
400425

401426
logic [7:0] rx_data_count;
402427

428+
logic entdaa_start, entdaa_done;
429+
403430
always_comb begin : addr_matching
404431
if (target_dyn_address_valid_i) begin
405432
is_byte_our_addr = command_addr == target_dyn_address_i;
@@ -461,7 +488,7 @@ module ccc
461488
if (have_defining_byte) state_d = RxDefByte;
462489
else begin
463490
// ENTDAA is special
464-
if (command_code == ENTDAA) state_d = HandleENTDAA;
491+
if (command_code == `I3C_BCAST_ENTDAA) state_d = HandleENTDAA;
465492
// broadcast CCCs
466493
else if (~is_direct_cmd) state_d = RxData;
467494
// direct CCCs
@@ -470,6 +497,9 @@ module ccc
470497
end
471498
end
472499
end
500+
HandleENTDAA: begin
501+
if (entdaa_done) state_d = Idle;
502+
end
473503
RxDefByte: begin
474504
if (bus_rx_done_i) state_d = RxDefByteTbit;
475505
end
@@ -545,13 +575,13 @@ module ccc
545575

546576

547577
always_comb begin : state_outputs
548-
bus_rx_req_bit_o = '0;
549-
bus_rx_req_byte_o = '0;
578+
ccc_rx_req_bit = '0;
579+
ccc_rx_req_byte = '0;
550580

551-
bus_tx_req_byte_o = '0;
552-
bus_tx_req_bit_o = '0;
553-
bus_tx_req_value_o = '0;
554-
bus_tx_sel_od_pp_o = '0;
581+
ccc_tx_req_byte = '0;
582+
ccc_tx_req_bit = '0;
583+
ccc_tx_req_value = '0;
584+
ccc_tx_sel_od_pp = '0;
555585

556586
done_fsm_o = '0;
557587
unique case (state_q)
@@ -562,57 +592,57 @@ module ccc
562592

563593
end
564594
RxTbit: begin
565-
bus_rx_req_bit_o = '1;
566-
bus_rx_req_byte_o = '0;
595+
ccc_rx_req_bit = '1;
596+
ccc_rx_req_byte = '0;
567597
end
568598
RxDefByte: begin
569-
bus_rx_req_bit_o = '0;
570-
bus_rx_req_byte_o = '1;
599+
ccc_rx_req_bit = '0;
600+
ccc_rx_req_byte = '1;
571601
end
572602
RxDefByteTbit: begin
573-
bus_rx_req_bit_o = '1;
574-
bus_rx_req_byte_o = '0;
603+
ccc_rx_req_bit = '1;
604+
ccc_rx_req_byte = '0;
575605
end
576606
RxByte: begin
577-
bus_rx_req_bit_o = '0;
578-
bus_rx_req_byte_o = '1;
579-
if (bus_rstart_det_i) bus_rx_req_byte_o = '0;
607+
ccc_rx_req_bit = '0;
608+
ccc_rx_req_byte = '1;
609+
if (bus_rstart_det_i) ccc_rx_req_byte = '0;
580610
end
581611
RxDirectDefByteTbit: begin
582-
bus_rx_req_bit_o = '1;
583-
bus_rx_req_byte_o = '0;
612+
ccc_rx_req_bit = '1;
613+
ccc_rx_req_byte = '0;
584614
end
585615
RxDirectAddr: begin
586-
bus_rx_req_bit_o = '0;
587-
bus_rx_req_byte_o = '1;
616+
ccc_rx_req_bit = '0;
617+
ccc_rx_req_byte = '1;
588618
end
589619
TxDirectAddrAck: begin
590-
bus_tx_req_byte_o = '0;
591-
bus_tx_req_bit_o = '1;
592-
bus_tx_req_value_o = {7'h00, ~(is_byte_our_addr | is_byte_rsvd_addr | is_byte_virtual_addr)};
620+
ccc_tx_req_byte = '0;
621+
ccc_tx_req_bit = '1;
622+
ccc_tx_req_value = {7'h00, ~(is_byte_our_addr | is_byte_rsvd_addr | is_byte_virtual_addr)};
593623
end
594624
RxSubCmdByte: begin
595625
end
596626
RxData: begin
597-
bus_rx_req_bit_o = '0;
598-
bus_rx_req_byte_o = '1;
599-
if (bus_rstart_det_i) bus_rx_req_byte_o = '0;
627+
ccc_rx_req_bit = '0;
628+
ccc_rx_req_byte = '1;
629+
if (bus_rstart_det_i) ccc_rx_req_byte = '0;
600630
end
601631
RxDataTbit: begin
602-
bus_rx_req_bit_o = '1;
603-
bus_rx_req_byte_o = '0;
632+
ccc_rx_req_bit = '1;
633+
ccc_rx_req_byte = '0;
604634
end
605635
TxData: begin
606-
bus_tx_req_byte_o = '1;
607-
bus_tx_req_bit_o = '0;
608-
bus_tx_req_value_o = tx_data;
609-
bus_tx_sel_od_pp_o = '1;
636+
ccc_tx_req_byte = '1;
637+
ccc_tx_req_bit = '0;
638+
ccc_tx_req_value = tx_data;
639+
ccc_tx_sel_od_pp = '1;
610640
end
611641
TxDataTbit: begin
612-
bus_tx_req_byte_o = '0;
613-
bus_tx_req_bit_o = '1;
614-
bus_tx_req_value_o = {7'h00, ~tx_data_done};
615-
bus_tx_sel_od_pp_o = '1;
642+
ccc_tx_req_byte = '0;
643+
ccc_tx_req_bit = '1;
644+
ccc_tx_req_value = {7'h00, ~tx_data_done};
645+
ccc_tx_sel_od_pp = '1;
616646
end
617647
DoneCCC: begin
618648
done_fsm_o = '1;
@@ -947,7 +977,38 @@ module ccc
947977
assign ent_hdr_5_o = '0;
948978
assign ent_hdr_6_o = '0;
949979
assign ent_hdr_7_o = '0;
950-
assign set_newda_o = '0;
951-
assign newda_o = '0;
952980

981+
982+
ccc_entdaa xccc_entdaa (
983+
.clk_i, // Clock
984+
.rst_ni, // Async reset, active low
985+
.id_i,
986+
987+
.start_daa_i(entdaa_start),
988+
.done_daa_o(entdaa_done),
989+
990+
// Bus RX interface
991+
.bus_rx_data_i,
992+
.bus_rx_done_i,
993+
.bus_rx_req_bit_o(entdaa_rx_req_bit),
994+
.bus_rx_req_byte_o(entdaa_rx_req_byte),
995+
996+
// Bus TX interface
997+
.bus_tx_done_i,
998+
.bus_tx_req_byte_o(entdaa_tx_req_byte),
999+
.bus_tx_req_bit_o(entdaa_tx_req_bit),
1000+
.bus_tx_req_value_o(entdaa_tx_req_value),
1001+
.bus_tx_sel_od_pp_o(entdaa_tx_sel_od_pp),
1002+
1003+
// Bus Monitor interface
1004+
.bus_rstart_det_i,
1005+
.bus_stop_det_i,
1006+
1007+
// bus access
1008+
.arbitration_lost_i,
1009+
1010+
// addr
1011+
.address_o(newda_o),
1012+
.address_valid_o(set_newda_o)
1013+
);
9531014
endmodule

src/ctrl/ccc_entdaa.sv

Lines changed: 129 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,148 @@ module ccc_entdaa
55
input logic clk_i, // Clock
66
input logic rst_ni, // Async reset, active low
77
input logic [47:0] id_i,
8-
input start_daa,
9-
output done_daa
8+
9+
input logic start_daa_i,
10+
output logic done_daa_o,
11+
12+
// Bus RX interface
13+
input logic [7:0] bus_rx_data_i,
14+
input logic bus_rx_done_i,
15+
output logic bus_rx_req_bit_o,
16+
output logic bus_rx_req_byte_o,
17+
18+
// Bus TX interface
19+
input logic bus_tx_done_i,
20+
output logic bus_tx_req_byte_o,
21+
output logic bus_tx_req_bit_o,
22+
output logic [7:0] bus_tx_req_value_o,
23+
output logic bus_tx_sel_od_pp_o,
24+
25+
// Bus Monitor interface
26+
input logic bus_rstart_det_i,
27+
input logic bus_stop_det_i,
28+
29+
// bus access
30+
input logic arbitration_lost_i,
31+
32+
// addr
33+
output logic [7:0] address_o,
34+
output logic address_valid_o
1035
);
1136

1237

1338
typedef enum logic [7:0] {
1439
Idle,
40+
WaitStart,
1541
ReceiveRsvdByte,
1642
AckRsvdByte,
43+
SendNack,
1744
SendID,
45+
LostArbitration,
1846
ReceiveAddr,
47+
AckAddr,
1948
Done,
2049
Error
2150
} state_e;
2251

2352
state_e state_q, state_d;
53+
logic [5:0] id_bit_count;
54+
logic reserved_word_det;
55+
56+
logic parity_ok;
57+
58+
assign reserved_word_det = (bus_rx_data_i[7:1] == 7'h7e && bus_rx_data_i[0] == 0);
59+
60+
always_comb begin: state_functions
61+
state_d = state_q;
62+
unique case (state_q)
63+
Idle: begin
64+
if (start_daa_i) begin
65+
state_d <= WaitStart;
66+
end
67+
end
68+
WaitStart: begin
69+
if (bus_rstart_det_i) begin
70+
state_d <= ReceiveRsvdByte;
71+
end
72+
end
73+
ReceiveRsvdByte: begin
74+
if (bus_rx_done_i) begin
75+
if (reserved_word_det) state_d <= AckRsvdByte;
76+
else state_d <= SendNack;
77+
end
78+
end
79+
AckRsvdByte: begin
80+
state_d <= SendID;
81+
end
82+
SendNack: begin
83+
state_d <= Error;
84+
end
85+
SendID: begin
86+
// our Id was overwritten by some other device
87+
if (arbitration_lost_i) begin
88+
state_d <= LostArbitration;
89+
end
90+
end
91+
ReceiveAddr: begin
92+
if (bus_rx_done_i) begin
93+
if (parity_ok) state_d <= AckAddr;
94+
else state_d <= SendNack;
95+
end
96+
end
97+
Done: begin
98+
end
99+
Error: begin
100+
// we wait here until we receive Stop
101+
end
102+
default: begin
103+
end
104+
endcase
105+
end
106+
107+
always_comb begin : state_outputs
108+
bus_rx_req_byte_o = '0;
109+
110+
bus_tx_req_bit_o = '0;
111+
bus_tx_req_value_o = '0;
112+
bus_tx_sel_od_pp_o = '0;
113+
unique case (state_q)
114+
Idle: begin
115+
end
116+
WaitStart: begin
117+
end
118+
ReceiveRsvdByte: begin
119+
bus_rx_req_byte_o = '1;
120+
end
121+
AckRsvdByte: begin
122+
bus_tx_req_bit_o = '1;
123+
bus_tx_req_value_o = '0;
124+
end
125+
SendNack: begin
126+
bus_tx_req_bit_o = '1;
127+
bus_tx_req_value_o = '0;
128+
end
129+
SendID: begin
130+
end
131+
ReceiveAddr: begin
132+
bus_rx_req_byte_o = '1;
133+
end
134+
Done: begin
135+
end
136+
Error: begin
137+
end
138+
default: begin
139+
end
140+
endcase
141+
end
142+
// Synchronous state transition
143+
always_ff @(posedge clk_i or negedge rst_ni) begin : state_transition
144+
if (!rst_ni) begin
145+
state_q <= Idle;
146+
end else begin
147+
if (bus_stop_det_i) state_q <= Done;
148+
else state_q <= state_d;
149+
end
150+
end
24151

25152
endmodule

src/ctrl/controller_standby.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ module controller_standby
381381
) xcontroller_standby_i3c (
382382
.clk_i(clk_i),
383383
.rst_ni(rst_ni),
384-
.id_i(id_i)
384+
.id_i(id_i),
385385
.ctrl_bus_i(ctrl_bus_i[1]),
386386
.ctrl_scl_o(ctrl_scl_o[1]),
387387
.ctrl_sda_o(ctrl_sda_o[1]),

0 commit comments

Comments
 (0)