Skip to content

Commit

Permalink
1. Reset CCC status in I3C_Slave_Handle_DMA() to drop unwanted receiv…
Browse files Browse the repository at this point in the history
…ed data.

2. Update MAXRD = 256 and MAXWR = 256 in MAXLIMITS register
3. Don't handle Slave DMA if START comes after STOP too quickly.
4. Remove the redundant delay in sir_allowed_worker() and test_i3c_ci()
  • Loading branch information
su-shih-hsin committed Sep 4, 2023
1 parent 3dd7ca8 commit e6b6ca5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
22 changes: 13 additions & 9 deletions drivers/i3c/i3c_npcm4xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,8 @@ I3C_ErrCode_Enum hal_I3C_Config_Device(I3C_DEVICE_INFO_t *pDevice)
PDMA->SCATBA = (uint32_t) I3C_SCATTER_GATHER_TABLE.SCAT_DSCT;
}

// hal_I3C_set_MAXRD(port, pDevice->max_rd_len);
// hal_I3C_set_MAXWR(port, pDevice->max_wr_len);
hal_I3C_set_MAXRD(port, pDevice->max_rd_len);
hal_I3C_set_MAXWR(port, pDevice->max_wr_len);

/* Used for the Mixed bus to send the first START frame */
mconfig &= ~I3C_MCONFIG_ODHPP_MASK;
Expand Down Expand Up @@ -3430,7 +3430,10 @@ if (intmasked == 0) return;
* 1. We must terminate previous RX DMA / FIFO before master send "Index" / Data
* 2. We must init RX DMA to get "Index" and data
*/
I3C_Slave_Handle_DMA((uint32_t)pDevice);
if (intmasked & I3C_INTMASKED_STOP_MASK) {
/* update tx buffer here, only when slave doesn't get STOP */
I3C_Slave_Handle_DMA((uint32_t)pDevice);
}

I3C_SET_REG_STATUS(I3C_IF, I3C_STATUS_START_MASK);
}
Expand All @@ -3441,7 +3444,8 @@ if (intmasked == 0) return;
}

if (intmasked & I3C_INTMASKED_CCC_MASK) {
I3C_SET_REG_STATUS(I3C_IF, I3C_STATUS_CCC_MASK);
/* Can't reset here, will validate CCC in I3C_Slave_Handle_DMA() */
/* I3C_SET_REG_STATUS(I3C_IF, I3C_STATUS_CCC_MASK); */
}

if (intmasked & I3C_INTMASKED_DDRMATCHED_MASK) {
Expand Down Expand Up @@ -3645,9 +3649,9 @@ void I3C_Slave_Handle_DMA(__u32 Parm)
PDMA->CHCTL &= ~MaskBit(port + I3C_PORT_MAX);

if (I3C_GET_REG_STATUS(port) & I3C_STATUS_CCC_MASK) {
/* reserved for vendor CCC */
/* reserved for vendor CCC, drop rx data directly */
if (slvRxBuf[port][0] == CCC_BROADCAST_SETAASA) {

LOG_WRN("rcv setaasa...");
}

/* we can't support SETAASA because DYNADDR is RO. */
Expand Down Expand Up @@ -3938,7 +3942,7 @@ static void sir_allowed_worker(struct k_work *work)
{
struct i3c_npcm4xx_obj *obj = CONTAINER_OF(work, struct i3c_npcm4xx_obj, work);

k_msleep(1000);
/* k_msleep(1000); */
obj->sir_allowed_by_sw = 1;
}

Expand Down Expand Up @@ -3991,8 +3995,8 @@ static int i3c_npcm4xx_init(const struct device *dev)

pDevice->staticAddr = config->assigned_addr;

pDevice->max_rd_len = 1024; // I3C_PAYLOAD_SIZE_MAX;
pDevice->max_wr_len = 1024; // I3C_PAYLOAD_SIZE_MAX;
pDevice->max_rd_len = I3C_PAYLOAD_SIZE_MAX;
pDevice->max_wr_len = I3C_PAYLOAD_SIZE_MAX;

if (config->slave) {
if (config->secondary)
Expand Down
2 changes: 1 addition & 1 deletion tests/boards/npcm400f_evb/boards/npcm400f_evb.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
reg = <0x21>;
msg-size = <256>;
num-of-msgs = <4>;
mandatory-data-byte = <0xB0>;
mandatory-data-byte = <0xAE>;
label = "I3C_1_SMQ";
status = "okay";
};
Expand Down
14 changes: 8 additions & 6 deletions tests/boards/npcm400f_evb/src/i3c.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static void test_i3c_slave_task(void *arg1, void *arg2, void *arg3)
/* Test part 1: read and compare the data */

/* reset rx buffer */
/* memset(test_data_rx_slv, 0x00, sizeof(test_data_rx_slv)); */
memset(test_data_rx_slv, 0x00, sizeof(test_data_rx_slv));

while (1) {
ret = i3c_slave_mqueue_read(slave_mq, (uint8_t *)test_data_rx_slv, TEST_PRIV_XFER_SIZE);
Expand All @@ -108,6 +108,8 @@ static void test_i3c_slave_task(void *arg1, void *arg2, void *arg3)

/* Test part 2: send IBI to notify the master device to get the pending data */
/* prepare_test_data(test_data_tx_slv, TEST_IBI_PAYLOAD_SIZE); */

/* for debug only */
memcpy(test_data_tx_slv, test_data_rx_slv, TEST_IBI_PAYLOAD_SIZE);
ret = i3c_slave_mqueue_write(slave_mq, test_data_tx_slv, TEST_IBI_PAYLOAD_SIZE);
ast_zassert_equal(ret, 0, "failed to do slave mqueue write");
Expand Down Expand Up @@ -157,14 +159,12 @@ static void test_i3c_ci(int count)
/* try to enter i3c mode */
/* assign dynamic address with setdasa or entdaa, doesn't support setaasa in slave mode */
i3c_master_send_rstdaa(dev_master);
/* i3c_master_send_aasa(dev_master); */
i3c_master_send_aasa(dev_master); /* Compatibility test for JESD403 */
i3c_master_send_entdaa(slave);
slave->info.i2c_mode = 0;

/* must wait for a while, for slave finish sir_allowed_worker ? */
/* if skip the delay, the following getpid will be nacked */
/* and dma will capture enec mask data later */
k_sleep(K_MSEC(2000));
/* k_sleep(K_USEC(1)); */

/* try to collect more slave info if called setaasa in the former */
i3c_master_send_getpid(dev_master, slave->info.dynamic_addr, &slave->info.pid);
Expand Down Expand Up @@ -193,7 +193,8 @@ static void test_i3c_ci(int count)
for (i = 0; i < count; i++) {
/* prepare request message */
prepare_test_data(test_data_tx_mst, TEST_PRIV_XFER_SIZE);
test_data_tx_mst[0] = i; /* for debug only */
/* test_data_tx_mst[0] = i; */ /* for debug only */
/* k_usleep(100); */ /* debug only */

/* Requester send request message */
xfer[0].rnw = 0;
Expand Down Expand Up @@ -227,6 +228,7 @@ static void test_i3c_ci(int count)
k_yield();
ret = i3c_master_priv_xfer(slave, &xfer[0], 1);
ast_zassert_mem_equal(test_data_tx_slv, test_data_rx_mst, TEST_IBI_PAYLOAD_SIZE, "data mismatch");
/*k_usleep(100);*/ /* debug only */
}
}

Expand Down

0 comments on commit e6b6ca5

Please sign in to comment.