From 434a16f461c81d15f9e554f619ff2533f61bd657 Mon Sep 17 00:00:00 2001 From: Michal Frankiewicz Date: Thu, 13 Feb 2025 13:20:51 +0100 Subject: [PATCH] applications: sdp: mspi: No copy IPC-applications Implemented option to pass data between cores through IPC by reference. Signed-off-by: Michal Frankiewicz --- applications/sdp/mspi/src/main.c | 49 +++++++++++++++++++------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/applications/sdp/mspi/src/main.c b/applications/sdp/mspi/src/main.c index e6666b9df4ff..cac407ae7aae 100644 --- a/applications/sdp/mspi/src/main.c +++ b/applications/sdp/mspi/src/main.c @@ -66,8 +66,9 @@ static volatile uint8_t ce_vios_count; static volatile uint8_t ce_vios[DEVICES_MAX]; static volatile uint8_t data_vios_count; static volatile uint8_t data_vios[DATA_PINS_MAX]; -static volatile nrfe_mspi_xfer_config_t nrfe_mspi_xfer_config; static volatile nrfe_mspi_dev_config_t nrfe_mspi_devices[DEVICES_MAX]; +static volatile nrfe_mspi_xfer_config_t nrfe_mspi_xfer_config; +static volatile nrfe_mspi_xfer_config_t *nrfe_mspi_xfer_config_ptr = &nrfe_mspi_xfer_config; static volatile hrt_xfer_t xfer_params; @@ -181,11 +182,11 @@ static void configure_clock(enum mspi_cpp_mode cpp_mode) static void xfer_execute(nrfe_mspi_xfer_packet_msg_t *xfer_packet) { volatile nrfe_mspi_dev_config_t *device = - &nrfe_mspi_devices[nrfe_mspi_xfer_config.device_index]; + &nrfe_mspi_devices[nrfe_mspi_xfer_config_ptr->device_index]; xfer_params.counter_value = 4; xfer_params.ce_vio = ce_vios[device->ce_index]; - xfer_params.ce_hold = nrfe_mspi_xfer_config.hold_ce; + xfer_params.ce_hold = nrfe_mspi_xfer_config_ptr->hold_ce; xfer_params.cpp_mode = device->cpp; xfer_params.ce_polarity = device->ce_polarity; xfer_params.bus_widths = io_modes[device->io_mode]; @@ -196,43 +197,44 @@ static void xfer_execute(nrfe_mspi_xfer_packet_msg_t *xfer_packet) */ xfer_packet->command = xfer_packet->command - << (BITS_IN_WORD - nrfe_mspi_xfer_config.command_length * BITS_IN_BYTE); + << (BITS_IN_WORD - nrfe_mspi_xfer_config_ptr->command_length * BITS_IN_BYTE); xfer_packet->address = xfer_packet->address - << (BITS_IN_WORD - nrfe_mspi_xfer_config.address_length * BITS_IN_BYTE); + << (BITS_IN_WORD - nrfe_mspi_xfer_config_ptr->address_length * BITS_IN_BYTE); xfer_params.xfer_data[HRT_FE_COMMAND].fun_out = HRT_FUN_OUT_WORD; xfer_params.xfer_data[HRT_FE_COMMAND].data = (uint8_t *)&xfer_packet->command; xfer_params.xfer_data[HRT_FE_COMMAND].word_count = 0; adjust_tail(&xfer_params.xfer_data[HRT_FE_COMMAND], xfer_params.bus_widths.command, - nrfe_mspi_xfer_config.command_length * BITS_IN_BYTE); + nrfe_mspi_xfer_config_ptr->command_length * BITS_IN_BYTE); xfer_params.xfer_data[HRT_FE_ADDRESS].fun_out = HRT_FUN_OUT_WORD; xfer_params.xfer_data[HRT_FE_ADDRESS].data = (uint8_t *)&xfer_packet->address; xfer_params.xfer_data[HRT_FE_ADDRESS].word_count = 0; adjust_tail(&xfer_params.xfer_data[HRT_FE_ADDRESS], xfer_params.bus_widths.address, - nrfe_mspi_xfer_config.address_length * BITS_IN_BYTE); + nrfe_mspi_xfer_config_ptr->address_length * BITS_IN_BYTE); xfer_params.xfer_data[HRT_FE_DUMMY_CYCLES].fun_out = HRT_FUN_OUT_WORD; xfer_params.xfer_data[HRT_FE_DUMMY_CYCLES].data = NULL; xfer_params.xfer_data[HRT_FE_DUMMY_CYCLES].word_count = 0; hrt_frame_element_t elem = - nrfe_mspi_xfer_config.address_length != 0 ? HRT_FE_ADDRESS : HRT_FE_COMMAND; + nrfe_mspi_xfer_config_ptr->address_length != 0 ? HRT_FE_ADDRESS : HRT_FE_COMMAND; /* Up to 63 clock pulses (including data from previous part) can be sent by simply * increasing shift count of last word in the previous part. * Beyond that, dummy cycles have to be treated af different transfer part. */ - if (xfer_params.xfer_data[elem].last_word_clocks + nrfe_mspi_xfer_config.tx_dummy <= + if (xfer_params.xfer_data[elem].last_word_clocks + nrfe_mspi_xfer_config_ptr->tx_dummy <= MAX_SHIFT_COUNT) { - xfer_params.xfer_data[elem].last_word_clocks += nrfe_mspi_xfer_config.tx_dummy; + xfer_params.xfer_data[elem].last_word_clocks += nrfe_mspi_xfer_config_ptr->tx_dummy; } else { adjust_tail(&xfer_params.xfer_data[HRT_FE_DUMMY_CYCLES], xfer_params.bus_widths.dummy_cycles, - nrfe_mspi_xfer_config.tx_dummy * xfer_params.bus_widths.dummy_cycles); + nrfe_mspi_xfer_config_ptr->tx_dummy * + xfer_params.bus_widths.dummy_cycles); } xfer_params.xfer_data[HRT_FE_DATA].fun_out = HRT_FUN_OUT_BYTE; @@ -263,12 +265,12 @@ static void xfer_execute(nrfe_mspi_xfer_packet_msg_t *xfer_packet) void prepare_and_read_data(nrfe_mspi_xfer_packet_msg_t *xfer_packet, volatile uint8_t *buffer) { volatile nrfe_mspi_dev_config_t *device = - &nrfe_mspi_devices[nrfe_mspi_xfer_config.device_index]; + &nrfe_mspi_devices[nrfe_mspi_xfer_config_ptr->device_index]; nrf_vpr_csr_vio_config_t config; xfer_params.counter_value = 4; xfer_params.ce_vio = ce_vios[device->ce_index]; - xfer_params.ce_hold = nrfe_mspi_xfer_config.hold_ce; + xfer_params.ce_hold = nrfe_mspi_xfer_config_ptr->hold_ce; xfer_params.ce_polarity = device->ce_polarity; xfer_params.bus_widths = io_modes[device->io_mode]; xfer_params.xfer_data[HRT_FE_DATA].data = buffer; @@ -283,20 +285,22 @@ void prepare_and_read_data(nrfe_mspi_xfer_packet_msg_t *xfer_packet, volatile ui */ xfer_packet->command = xfer_packet->command - << (BITS_IN_WORD - nrfe_mspi_xfer_config.command_length * BITS_IN_BYTE); + << (BITS_IN_WORD - nrfe_mspi_xfer_config_ptr->command_length * BITS_IN_BYTE); xfer_packet->address = xfer_packet->address - << (BITS_IN_WORD - nrfe_mspi_xfer_config.address_length * BITS_IN_BYTE); + << (BITS_IN_WORD - nrfe_mspi_xfer_config_ptr->address_length * BITS_IN_BYTE); /* Configure command phase. */ xfer_params.xfer_data[HRT_FE_COMMAND].fun_out = HRT_FUN_OUT_WORD; xfer_params.xfer_data[HRT_FE_COMMAND].data = (uint8_t *)&xfer_packet->command; - xfer_params.xfer_data[HRT_FE_COMMAND].word_count = nrfe_mspi_xfer_config.command_length; + xfer_params.xfer_data[HRT_FE_COMMAND].word_count = + nrfe_mspi_xfer_config_ptr->command_length; /* Configure address phase. */ xfer_params.xfer_data[HRT_FE_ADDRESS].fun_out = HRT_FUN_OUT_WORD; xfer_params.xfer_data[HRT_FE_ADDRESS].data = (uint8_t *)&xfer_packet->address; - xfer_params.xfer_data[HRT_FE_ADDRESS].word_count = nrfe_mspi_xfer_config.address_length; + xfer_params.xfer_data[HRT_FE_ADDRESS].word_count = + nrfe_mspi_xfer_config_ptr->address_length; /* Configure data phase. */ xfer_params.xfer_data[HRT_FE_DATA].word_count = xfer_packet->num_bytes; @@ -364,6 +368,10 @@ static void ep_bound(void *priv) static void ep_recv(const void *data, size_t len, void *priv) { +#ifdef CONFIG_SDP_MSPI_IPC_NO_COPY + data = *(void **)data; +#endif + (void)priv; (void)len; nrfe_mspi_flpr_response_msg_t response; @@ -415,9 +423,12 @@ static void ep_recv(const void *data, size_t len, void *priv) xfer_config->xfer_config.command_length != 0 || xfer_config->xfer_config.address_length != 0); +#ifdef CONFIG_SDP_MSPI_IPC_NO_COPY + nrfe_mspi_xfer_config_ptr = &xfer_config->xfer_config; +#else nrfe_mspi_xfer_config = xfer_config->xfer_config; - - configure_clock(nrfe_mspi_devices[nrfe_mspi_xfer_config.device_index].cpp); +#endif + configure_clock(nrfe_mspi_devices[nrfe_mspi_xfer_config_ptr->device_index].cpp); break; } case NRFE_MSPI_TX: