Skip to content

Commit a52cf83

Browse files
committed
drivers: mspi: RX no copy - drivers
Added no copy functionality to RX. Signed-off-by: Michal Frankiewicz <michal.frankiewicz@nordicsemi.no>
1 parent 8300f15 commit a52cf83

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

drivers/mspi/mspi_nrfe.c

+31-18
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,12 @@ static int xfer_packet(struct mspi_xfer_packet *packet, uint32_t timeout)
524524
xfer_packet->num_bytes = packet->num_bytes;
525525

526526
#ifdef CONFIG_MSPI_NRFE_IPC_NO_COPY
527-
/* Check for alignlemt problems. */
527+
/* Check for alignment problems. */
528528
if (((uint32_t)packet->data_buf) % sizeof(uint32_t) != 0) {
529-
memcpy((void *)(buffer + sizeof(nrfe_mspi_xfer_packet_msg_t)),
530-
(void *)packet->data_buf, packet->num_bytes);
529+
if (packet->dir == MSPI_TX) {
530+
memcpy((void *)(buffer + sizeof(nrfe_mspi_xfer_packet_msg_t)),
531+
(void *)packet->data_buf, packet->num_bytes);
532+
}
531533
xfer_packet->data = buffer + sizeof(nrfe_mspi_xfer_packet_msg_t);
532534
} else {
533535
xfer_packet->data = packet->data_buf;
@@ -539,20 +541,32 @@ static int xfer_packet(struct mspi_xfer_packet *packet, uint32_t timeout)
539541
rc = send_data(xfer_packet->opcode, xfer_packet, len);
540542

541543
/* Wait for the transfer to complete and receive data. */
542-
if ((packet->dir == MSPI_RX) && (ipc_receive_buffer != NULL) && (ipc_received > 0)) {
543-
/*
544-
* It is not possible to check whether received data is valid, so packet->num_bytes
545-
* should always be equal to ipc_received. If it is not, then something went wrong.
546-
*/
547-
if (packet->num_bytes != ipc_received) {
548-
rc = -EIO;
549-
} else {
550-
memcpy((void *)packet->data_buf, (void *)ipc_receive_buffer, ipc_received);
544+
if (packet->dir == MSPI_RX) {
545+
#ifdef CONFIG_MSPI_NRFE_IPC_NO_COPY
546+
/* Not aligned buffer. */
547+
if (((uint32_t)packet->data_buf) % sizeof(uint32_t) != 0) {
548+
memcpy((void *)packet->data_buf, (void *)xfer_packet->data,
549+
packet->num_bytes);
551550
}
552-
553-
/* Clear the receive buffer pointer and size */
554-
ipc_receive_buffer = NULL;
555-
ipc_received = 0;
551+
#else
552+
if ((ipc_receive_buffer != NULL) && (ipc_received > 0)) {
553+
/*
554+
* It is not possible to check whether received data is valid, so
555+
* packet->num_bytes should always be equal to ipc_received. If it is not,
556+
* then something went wrong.
557+
*/
558+
if (packet->num_bytes != ipc_received) {
559+
rc = -EIO;
560+
} else {
561+
memcpy((void *)packet->data_buf, (void *)ipc_receive_buffer,
562+
ipc_received);
563+
}
564+
565+
/* Clear the receive buffer pointer and size */
566+
ipc_receive_buffer = NULL;
567+
ipc_received = 0;
568+
}
569+
#endif
556570
}
557571

558572
return rc;
@@ -713,8 +727,7 @@ static int nrfe_mspi_init(const struct device *dev)
713727
.callback = flpr_fault_handler,
714728
.user_data = NULL,
715729
.flags = 0,
716-
.ticks = counter_us_to_ticks(flpr_fault_timer, CONFIG_MSPI_NRFE_FAULT_TIMEOUT)
717-
};
730+
.ticks = counter_us_to_ticks(flpr_fault_timer, CONFIG_MSPI_NRFE_FAULT_TIMEOUT)};
718731
#endif
719732

720733
ret = pinctrl_apply_state(drv_cfg->pcfg, PINCTRL_STATE_DEFAULT);

0 commit comments

Comments
 (0)