Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: mspi: sdp: merge send_data functions #21002

Merged
merged 1 commit into from
Mar 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 27 additions & 44 deletions drivers/mspi/mspi_nrfe.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,45 +196,6 @@ static void ep_recv(const void *data, size_t len, void *priv)
LOG_HEXDUMP_DBG((uint8_t *)data, len, "Received msg:");
}

/**
* @brief Send data to the flpr with the given opcode.
*
* @param opcode The opcode of the message to send.
* @param data The data to send.
* @param len The length of the data to send.
*
* @return 0 on success, -ENOMEM if there is no space in the buffer,
* -ETIMEDOUT if the transfer timed out.
*/
static int mspi_ipc_data_send(nrfe_mspi_opcode_t opcode, const void *data, size_t len)
{
int rc;

LOG_DBG("Sending msg with opcode: %d", (uint8_t)opcode);
#if defined(CONFIG_SYS_CLOCK_EXISTS)
uint32_t start = k_uptime_get_32();
#else
uint32_t repeat = EP_SEND_TIMEOUT_MS;
#endif
#if !defined(CONFIG_MULTITHREADING)
atomic_clear_bit(&ipc_atomic_sem, opcode);
#endif

do {
rc = ipc_service_send(&ep, data, len);
#if defined(CONFIG_SYS_CLOCK_EXISTS)
if ((k_uptime_get_32() - start) > EP_SEND_TIMEOUT_MS) {
#else
repeat--;
if ((rc < 0) && (repeat == 0)) {
#endif
break;
};
} while (rc == -ENOMEM); /* No space in the buffer. Retry. */

return rc;
}

/**
* @brief Waits for a response from the peer with the given opcode.
*
Expand Down Expand Up @@ -303,16 +264,38 @@ static int nrfe_mspi_wait_for_response(nrfe_mspi_opcode_t opcode, uint32_t timeo
*/
static int send_data(nrfe_mspi_opcode_t opcode, const void *data, size_t len)
{
int rc;
LOG_DBG("Sending msg with opcode: %d", (uint8_t)opcode);

int rc;
#ifdef CONFIG_MSPI_NRFE_IPC_NO_COPY
(void)len;
void *data_ptr = (void *)data;
#endif

rc = mspi_ipc_data_send(opcode, &data_ptr, sizeof(void *));
#if defined(CONFIG_SYS_CLOCK_EXISTS)
uint32_t start = k_uptime_get_32();
#else
rc = mspi_ipc_data_send(opcode, data, len);
uint32_t repeat = EP_SEND_TIMEOUT_MS;
#endif
#if !defined(CONFIG_MULTITHREADING)
atomic_clear_bit(&ipc_atomic_sem, opcode);
#endif

do {
#ifdef CONFIG_MSPI_NRFE_IPC_NO_COPY
rc = ipc_service_send(&ep, &data_ptr, sizeof(void *));
#else
rc = ipc_service_send(&ep, data, len);
#endif
#if defined(CONFIG_SYS_CLOCK_EXISTS)
if ((k_uptime_get_32() - start) > EP_SEND_TIMEOUT_MS) {
#else
repeat--;
if ((rc < 0) && (repeat == 0)) {
#endif
break;
};
} while (rc == -ENOMEM); /* No space in the buffer. Retry. */

if (rc < 0) {
LOG_ERR("Data transfer failed: %d", rc);
Expand Down Expand Up @@ -520,7 +503,7 @@ static int api_get_channel_status(const struct device *dev, uint8_t ch)
* @retval -ENOMEM if there is no space in the buffer
* @retval -ETIMEDOUT if the transfer timed out
*/
static int xfer_packet(struct mspi_xfer_packet *packet, uint32_t timeout)
static int send_packet(struct mspi_xfer_packet *packet, uint32_t timeout)
{
int rc;
nrfe_mspi_opcode_t opcode = (packet->dir == MSPI_RX) ? NRFE_MSPI_TXRX : NRFE_MSPI_TX;
Expand Down Expand Up @@ -598,7 +581,7 @@ static int start_next_packet(struct mspi_xfer *xfer, uint32_t packets_done)
return -EINVAL;
}

return xfer_packet(packet, xfer->timeout);
return send_packet(packet, xfer->timeout);
}

/**
Expand Down