Skip to content

Commit 804d776

Browse files
committed
CCC: Nack DIRECT_SETDASA if dynamic addr is set
Signed-off-by: Karol Gugala <[email protected]>
1 parent 0d832ed commit 804d776

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

src/ctrl/ccc.sv

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,11 @@ module ccc
462462
assign is_byte_our_virtual_static_addr = ((command_addr == virtual_target_sta_address_i) && virtual_target_sta_address_valid_i);
463463
assign is_byte_virtual_addr = is_byte_our_virtual_dynamic_addr | is_byte_our_virtual_static_addr;
464464

465+
logic direct_addr_ack;
466+
467+
assign direct_addr_ack = (command_code == `I3C_DIRECT_SETDASA) ? ((is_byte_our_static_addr && ~target_dyn_address_valid_i) | (is_byte_our_virtual_static_addr && ~virtual_target_dyn_address_valid_i)) :
468+
(is_byte_our_addr | is_byte_rsvd_addr | is_byte_virtual_addr);
469+
465470
always_ff @(posedge clk_i or negedge rst_ni) begin : proc_addr
466471
if (~rst_ni) begin
467472
command_addr <= '0;
@@ -571,12 +576,19 @@ module ccc
571576
end
572577
TxDirectAddrAck: begin
573578
if (bus_tx_done_i) begin
574-
if (is_byte_rsvd_addr) state_d = NextCCC;
575-
else if ((is_byte_our_addr || is_byte_virtual_addr) && command_rnw) state_d = TxData;
576-
else if ((is_byte_our_addr || is_byte_virtual_addr) && ~command_rnw) begin
577-
if (command_code == `I3C_DIRECT_SETXTIME) state_d = RxSubCmdByte;
579+
if (command_code == `I3C_DIRECT_SETDASA) begin
580+
if (is_byte_our_static_addr && target_dyn_address_valid_i) state_d = WaitForBusCond;
581+
else if (is_byte_our_virtual_static_addr && virtual_target_dyn_address_valid_i) state_d = WaitForBusCond;
578582
else state_d = RxData;
579-
end else state_d = WaitForBusCond;
583+
end
584+
else begin
585+
if (is_byte_rsvd_addr) state_d = NextCCC;
586+
else if ((is_byte_our_addr || is_byte_virtual_addr) && command_rnw) state_d = TxData;
587+
else if ((is_byte_our_addr || is_byte_virtual_addr) && ~command_rnw) begin
588+
if (command_code == `I3C_DIRECT_SETXTIME) state_d = RxSubCmdByte;
589+
else state_d = RxData;
590+
end else state_d = WaitForBusCond;
591+
end
580592
end
581593
end
582594

@@ -662,7 +674,7 @@ module ccc
662674
TxDirectAddrAck: begin
663675
ccc_tx_req_byte = '0;
664676
ccc_tx_req_bit = '1;
665-
ccc_tx_req_value = {7'h00, ~(is_byte_our_addr | is_byte_rsvd_addr | is_byte_virtual_addr)};
677+
ccc_tx_req_value = {7'h00, ~direct_addr_ack};
666678
end
667679
RxSubCmdByte: begin
668680
end

verification/cocotb/top/lib_i3c_top/test_ccc.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,42 @@ async def test_ccc_setdasa(dut):
125125
assert virt_dynamic_address_valid == 1, "New VIRT DYNAMIC ADDRESS is not set as valid"
126126

127127

128+
@cocotb.test()
129+
async def test_ccc_setdasa_nack(dut):
130+
131+
STATIC_ADDR = 0x5A
132+
VIRT_STATIC_ADDR = 0x5B
133+
DYNAMIC_ADDR = 0x52
134+
VIRT_DYNAMIC_ADDR = 0x53
135+
136+
i3c_controller, i3c_target, tb = await test_setup(dut)
137+
# set regular device dynamic address
138+
ack = await i3c_controller.i3c_ccc_write(
139+
ccc=CCC.DIRECT.SETDASA, directed_data=[(STATIC_ADDR, [DYNAMIC_ADDR << 1])], stop=False
140+
)
141+
# check ACK
142+
assert ack[0] == True
143+
144+
# try to send SETDASA again (should be NACKed)
145+
ack = await i3c_controller.i3c_ccc_write(
146+
ccc=CCC.DIRECT.SETDASA, directed_data=[(STATIC_ADDR, [DYNAMIC_ADDR << 1])], stop=False
147+
)
148+
assert ack[0] == False
149+
150+
# set virtual device dynamic address
151+
ack = await i3c_controller.i3c_ccc_write(
152+
ccc=CCC.DIRECT.SETDASA, directed_data=[(VIRT_STATIC_ADDR, [VIRT_DYNAMIC_ADDR << 1])]
153+
)
154+
# check ACK
155+
assert ack[0] == True
156+
157+
# try to send SETDASA again (should be NACKed)
158+
ack = await i3c_controller.i3c_ccc_write(
159+
ccc=CCC.DIRECT.SETDASA, directed_data=[(VIRT_STATIC_ADDR, [VIRT_DYNAMIC_ADDR << 1])]
160+
)
161+
assert ack[0] == False
162+
163+
128164
@cocotb.test()
129165
async def test_ccc_setnewda(dut):
130166

0 commit comments

Comments
 (0)