Skip to content

Commit 7a0a66f

Browse files
committed
CCC: Nack DIRECT_SETDASA if dynamic addr is set
Signed-off-by: Karol Gugala <[email protected]>
1 parent 3a053f2 commit 7a0a66f

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
@@ -464,6 +464,11 @@ module ccc
464464
assign is_byte_our_virtual_static_addr = ((command_addr == virtual_target_sta_address_i) && virtual_target_sta_address_valid_i);
465465
assign is_byte_virtual_addr = is_byte_our_virtual_dynamic_addr | is_byte_our_virtual_static_addr;
466466

467+
logic direct_addr_ack;
468+
469+
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)) :
470+
(is_byte_our_addr | is_byte_rsvd_addr | is_byte_virtual_addr);
471+
467472
always_ff @(posedge clk_i or negedge rst_ni) begin : proc_addr
468473
if (~rst_ni) begin
469474
command_addr <= '0;
@@ -573,12 +578,19 @@ module ccc
573578
end
574579
TxDirectAddrAck: begin
575580
if (bus_tx_done_i) begin
576-
if (is_byte_rsvd_addr) state_d = NextCCC;
577-
else if ((is_byte_our_addr || is_byte_virtual_addr) && command_rnw) state_d = TxData;
578-
else if ((is_byte_our_addr || is_byte_virtual_addr) && ~command_rnw) begin
579-
if (command_code == `I3C_DIRECT_SETXTIME) state_d = RxSubCmdByte;
581+
if (command_code == `I3C_DIRECT_SETDASA) begin
582+
if (is_byte_our_static_addr && target_dyn_address_valid_i) state_d = WaitForBusCond;
583+
else if (is_byte_our_virtual_static_addr && virtual_target_dyn_address_valid_i) state_d = WaitForBusCond;
580584
else state_d = RxData;
581-
end else state_d = WaitForBusCond;
585+
end
586+
else begin
587+
if (is_byte_rsvd_addr) state_d = NextCCC;
588+
else if ((is_byte_our_addr || is_byte_virtual_addr) && command_rnw) state_d = TxData;
589+
else if ((is_byte_our_addr || is_byte_virtual_addr) && ~command_rnw) begin
590+
if (command_code == `I3C_DIRECT_SETXTIME) state_d = RxSubCmdByte;
591+
else state_d = RxData;
592+
end else state_d = WaitForBusCond;
593+
end
582594
end
583595
end
584596

@@ -664,7 +676,7 @@ module ccc
664676
TxDirectAddrAck: begin
665677
ccc_tx_req_byte = '0;
666678
ccc_tx_req_bit = '1;
667-
ccc_tx_req_value = {7'h00, ~(is_byte_our_addr | is_byte_rsvd_addr | is_byte_virtual_addr)};
679+
ccc_tx_req_value = {7'h00, ~direct_addr_ack};
668680
end
669681
RxSubCmdByte: begin
670682
end

verification/cocotb/top/lib_i3c_top/test_ccc.py

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

131131

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

0 commit comments

Comments
 (0)