Skip to content

Commit

Permalink
applications: sdp: mspi: No copy IPC-applications
Browse files Browse the repository at this point in the history
Implemented option to pass data between cores
through IPC by reference.

Signed-off-by: Michal Frankiewicz <[email protected]>
  • Loading branch information
mif1-nordic authored and masz-nordic committed Feb 14, 2025
1 parent d404788 commit 434a16f
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions applications/sdp/mspi/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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];
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 434a16f

Please sign in to comment.