Skip to content

Commit 0096914

Browse files
committed
drivers: mspi: sdp: merge send_data functions
The mspi_ipc_data_send and send_data functions have been merged into one to prevent misuse due to the lack of NO_COPY distinction in the mspi_ipc_data_send function. Signed-off-by: Jakub Zymelka <jakub.zymelka@nordicsemi.no>
1 parent 0011ff5 commit 0096914

File tree

1 file changed

+27
-44
lines changed

1 file changed

+27
-44
lines changed

drivers/mspi/mspi_nrfe.c

+27-44
Original file line numberDiff line numberDiff line change
@@ -196,45 +196,6 @@ static void ep_recv(const void *data, size_t len, void *priv)
196196
LOG_HEXDUMP_DBG((uint8_t *)data, len, "Received msg:");
197197
}
198198

199-
/**
200-
* @brief Send data to the flpr with the given opcode.
201-
*
202-
* @param opcode The opcode of the message to send.
203-
* @param data The data to send.
204-
* @param len The length of the data to send.
205-
*
206-
* @return 0 on success, -ENOMEM if there is no space in the buffer,
207-
* -ETIMEDOUT if the transfer timed out.
208-
*/
209-
static int mspi_ipc_data_send(nrfe_mspi_opcode_t opcode, const void *data, size_t len)
210-
{
211-
int rc;
212-
213-
LOG_DBG("Sending msg with opcode: %d", (uint8_t)opcode);
214-
#if defined(CONFIG_SYS_CLOCK_EXISTS)
215-
uint32_t start = k_uptime_get_32();
216-
#else
217-
uint32_t repeat = EP_SEND_TIMEOUT_MS;
218-
#endif
219-
#if !defined(CONFIG_MULTITHREADING)
220-
atomic_clear_bit(&ipc_atomic_sem, opcode);
221-
#endif
222-
223-
do {
224-
rc = ipc_service_send(&ep, data, len);
225-
#if defined(CONFIG_SYS_CLOCK_EXISTS)
226-
if ((k_uptime_get_32() - start) > EP_SEND_TIMEOUT_MS) {
227-
#else
228-
repeat--;
229-
if ((rc < 0) && (repeat == 0)) {
230-
#endif
231-
break;
232-
};
233-
} while (rc == -ENOMEM); /* No space in the buffer. Retry. */
234-
235-
return rc;
236-
}
237-
238199
/**
239200
* @brief Waits for a response from the peer with the given opcode.
240201
*
@@ -303,16 +264,38 @@ static int nrfe_mspi_wait_for_response(nrfe_mspi_opcode_t opcode, uint32_t timeo
303264
*/
304265
static int send_data(nrfe_mspi_opcode_t opcode, const void *data, size_t len)
305266
{
306-
int rc;
267+
LOG_DBG("Sending msg with opcode: %d", (uint8_t)opcode);
307268

269+
int rc;
308270
#ifdef CONFIG_MSPI_NRFE_IPC_NO_COPY
309271
(void)len;
310272
void *data_ptr = (void *)data;
273+
#endif
311274

312-
rc = mspi_ipc_data_send(opcode, &data_ptr, sizeof(void *));
275+
#if defined(CONFIG_SYS_CLOCK_EXISTS)
276+
uint32_t start = k_uptime_get_32();
313277
#else
314-
rc = mspi_ipc_data_send(opcode, data, len);
278+
uint32_t repeat = EP_SEND_TIMEOUT_MS;
315279
#endif
280+
#if !defined(CONFIG_MULTITHREADING)
281+
atomic_clear_bit(&ipc_atomic_sem, opcode);
282+
#endif
283+
284+
do {
285+
#ifdef CONFIG_MSPI_NRFE_IPC_NO_COPY
286+
rc = ipc_service_send(&ep, &data_ptr, sizeof(void *));
287+
#else
288+
rc = ipc_service_send(&ep, data, len);
289+
#endif
290+
#if defined(CONFIG_SYS_CLOCK_EXISTS)
291+
if ((k_uptime_get_32() - start) > EP_SEND_TIMEOUT_MS) {
292+
#else
293+
repeat--;
294+
if ((rc < 0) && (repeat == 0)) {
295+
#endif
296+
break;
297+
};
298+
} while (rc == -ENOMEM); /* No space in the buffer. Retry. */
316299

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

601-
return xfer_packet(packet, xfer->timeout);
584+
return send_packet(packet, xfer->timeout);
602585
}
603586

604587
/**

0 commit comments

Comments
 (0)