Skip to content

Commit 51738bc

Browse files
committed
applications: sdp: mspi: Reduced IPC structures-applications
Implemented smaller structures and reduced ammount of opcodes in IPC Signed-off-by: Michal Frankiewicz <[email protected]>
1 parent 36e2075 commit 51738bc

File tree

4 files changed

+74
-63
lines changed

4 files changed

+74
-63
lines changed

applications/sdp/mspi/src/hrt/hrt.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void hrt_write(hrt_xfer_t *hrt_xfer_params)
137137
}
138138

139139
/* Enable CE */
140-
if (hrt_xfer_params->ce_polarity == MSPI_CE_ACTIVE_LOW) {
140+
if (hrt_xfer_params->ce_polarity == NRFE_MSPI_POL_ACTIVE_LOW) {
141141
nrf_vpr_csr_vio_out_clear_set(BIT(hrt_xfer_params->ce_vio));
142142
} else {
143143
nrf_vpr_csr_vio_out_or_set(BIT(hrt_xfer_params->ce_vio));
@@ -171,7 +171,7 @@ void hrt_write(hrt_xfer_t *hrt_xfer_params)
171171
/* Disable CE */
172172
if (!hrt_xfer_params->ce_hold) {
173173

174-
if (hrt_xfer_params->ce_polarity == MSPI_CE_ACTIVE_LOW) {
174+
if (hrt_xfer_params->ce_polarity == NRFE_MSPI_POL_ACTIVE_LOW) {
175175
nrf_vpr_csr_vio_out_or_set(BIT(hrt_xfer_params->ce_vio));
176176
} else {
177177
nrf_vpr_csr_vio_out_clear_set(BIT(hrt_xfer_params->ce_vio));

applications/sdp/mspi/src/hrt/hrt.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ typedef struct {
9393
bool ce_hold;
9494

9595
/** @brief Chip enable pin polarity in enabled state. */
96-
enum mspi_ce_polarity ce_polarity;
96+
nrfe_mspi_polarity_t ce_polarity;
9797

9898
/** @brief When true clock signal makes 1 transition less.
9999
* It is required for spi modes 1 and 3 due to hardware issue.

applications/sdp/mspi/src/hrt/hrt.s

+10-10
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ hrt_write:
162162
#APP
163163
csrw 3022, a5
164164
#NO_APP
165-
lbu a4,66(s0)
166-
li a5,1
167-
sll a5,a5,a4
168-
lbu a4,68(s0)
165+
lbu a5,66(s0)
166+
li a4,1
167+
lbu a3,68(s0)
168+
sll a5,a4,a5
169169
slli a5,a5,16
170170
srli a5,a5,16
171-
bne a4,zero,.L21
171+
bne a3,a4,.L21
172172
#APP
173173
csrc 3008, a5
174174
#NO_APP
@@ -209,13 +209,13 @@ hrt_write:
209209
#NO_APP
210210
lbu a5,67(s0)
211211
bne a5,zero,.L13
212-
lbu a4,66(s0)
213-
li a5,1
214-
sll a5,a5,a4
215-
lbu a4,68(s0)
212+
lbu a5,66(s0)
213+
li a4,1
214+
lbu a3,68(s0)
215+
sll a5,a4,a5
216216
slli a5,a5,16
217217
srli a5,a5,16
218-
bne a4,zero,.L26
218+
bne a3,a4,.L26
219219
#APP
220220
csrs 3008, a5
221221
#NO_APP

applications/sdp/mspi/src/main.c

+61-50
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717

1818
#include <drivers/mspi/nrfe_mspi.h>
1919

20-
#define CE_PINS_MAX 9
21-
#define DATA_PINS_MAX 8
22-
#define VIO_COUNT 11
23-
2420
#define SUPPORTED_IO_MODES_COUNT 7
2521

2622
#define HRT_IRQ_PRIORITY 2
@@ -32,7 +28,7 @@
3228
/* In OCTAL mode 4 bytes for address + 32 bytes for up to 32 dummy cycles*/
3329
#define ADDR_AND_CYCLES_MAX_SIZE 36
3430

35-
static const uint8_t pin_to_vio_map[VIO_COUNT] = {
31+
static const uint8_t pin_to_vio_map[NRFE_MSPI_VIO_COUNT] = {
3632
4, /* Physical pin 0 */
3733
0, /* Physical pin 1 */
3834
1, /* Physical pin 2 */
@@ -57,18 +53,27 @@ static const hrt_xfer_bus_widths_t io_modes[SUPPORTED_IO_MODES_COUNT] = {
5753
};
5854

5955
static volatile uint8_t ce_vios_count;
60-
static volatile uint8_t ce_vios[CE_PINS_MAX];
56+
static volatile uint8_t ce_vios[NRFE_MSPI_CE_PINS_MAX];
6157
static volatile uint8_t data_vios_count;
62-
static volatile uint8_t data_vios[DATA_PINS_MAX];
63-
static volatile struct mspi_cfg nrfe_mspi_cfg;
64-
static volatile struct mspi_dev_cfg nrfe_mspi_dev_cfg;
65-
static volatile struct mspi_xfer nrfe_mspi_xfer;
58+
static volatile uint8_t data_vios[NRFE_MSPI_DATA_PINS_MAX];
59+
static volatile nrfe_mspi_xfer_config_t nrfe_mspi_xfer_config;
60+
6661
static volatile hrt_xfer_t xfer_params;
6762
static volatile uint8_t address_and_dummy_cycles[ADDR_AND_CYCLES_MAX_SIZE];
6863

6964
static struct ipc_ept ep;
7065
static atomic_t ipc_atomic_sem = ATOMIC_INIT(0);
7166

67+
NRF_STATIC_INLINE void nrf_vpr_csr_vio_out_or_set(uint16_t value)
68+
{
69+
nrf_csr_set_bits(VPRCSR_NORDIC_OUT, value);
70+
}
71+
72+
NRF_STATIC_INLINE void nrf_vpr_csr_vio_out_clear_set(uint16_t value)
73+
{
74+
nrf_csr_clear_bits(VPRCSR_NORDIC_OUT, value);
75+
}
76+
7277
static void adjust_tail(volatile hrt_xfer_data_t *xfer_data, uint16_t frame_width, uint32_t data_length)
7378
{
7479
if (data_length == 0) {
@@ -148,36 +153,37 @@ static void configure_clock(enum mspi_cpp_mode cpp_mode)
148153
nrf_vpr_csr_vio_config_set(&vio_config);
149154
}
150155

151-
static void xfer_execute(struct mspi_xfer_packet xfer_packet)
156+
static void xfer_execute(nrfe_mspi_xfer_packet_t *xfer_packet, uint8_t *buffer)
152157
{
153-
NRFX_ASSERT(nrfe_mspi_dev_cfg.ce_num < ce_vios_count);
154-
NRFX_ASSERT(nrfe_mspi_dev_cfg.io_mode < SUPPORTED_IO_MODES_COUNT);
158+
NRFX_ASSERT(nrfe_mspi_xfer_config.ce_num < ce_vios_count);
159+
NRFX_ASSERT(nrfe_mspi_xfer_config.io_mode < SUPPORTED_IO_MODES_COUNT);
160+
NRFX_ASSERT(nrfe_mspi_xfer_config.ce_polarities[nrfe_mspi_xfer_config.ce_num] != NRFE_MSPI_POL_UNDEFINED);
155161

156162
xfer_params.counter_value = 4;
157-
xfer_params.ce_vio = ce_vios[nrfe_mspi_dev_cfg.ce_num];
158-
xfer_params.ce_hold = nrfe_mspi_xfer.hold_ce;
159-
xfer_params.ce_polarity = nrfe_mspi_dev_cfg.ce_polarity;
160-
xfer_params.bus_widths = io_modes[nrfe_mspi_dev_cfg.io_mode];
161-
163+
xfer_params.ce_vio = ce_vios[nrfe_mspi_xfer_config.ce_num];
164+
xfer_params.ce_hold = nrfe_mspi_xfer_config.hold_ce;
165+
xfer_params.ce_polarity = nrfe_mspi_xfer_config.ce_polarities[nrfe_mspi_xfer_config.ce_num];
166+
xfer_params.bus_widths = io_modes[nrfe_mspi_xfer_config.io_mode];
167+
162168
/* Fix position of command if command length is < BITS_IN_WORD,
163169
* so that leading zeros would not be printed instead of data bits.
164170
*/
165-
xfer_packet.cmd = xfer_packet.cmd
166-
<< (BITS_IN_WORD - nrfe_mspi_xfer.cmd_length * BITS_IN_BYTE);
171+
xfer_packet->command = xfer_packet->command
172+
<< (BITS_IN_WORD - nrfe_mspi_xfer_config.command_length * BITS_IN_BYTE);
167173

168174
xfer_params.xfer_data[HRT_FE_COMMAND].vio_out_set = &nrf_vpr_csr_vio_out_buffered_reversed_word_set;
169-
xfer_params.xfer_data[HRT_FE_COMMAND].data = (uint8_t *)&xfer_packet.cmd;
175+
xfer_params.xfer_data[HRT_FE_COMMAND].data = (uint8_t *)&xfer_packet->command;
170176
xfer_params.xfer_data[HRT_FE_COMMAND].word_count = 0;
171177

172178
adjust_tail(&xfer_params.xfer_data[HRT_FE_COMMAND],
173179
xfer_params.bus_widths.command,
174-
nrfe_mspi_xfer.cmd_length * BITS_IN_BYTE);
180+
nrfe_mspi_xfer_config.command_length * BITS_IN_BYTE);
175181

176-
for (uint8_t i = 0; i < nrfe_mspi_xfer.addr_length; i++) {
177-
address_and_dummy_cycles[i] = *(((uint8_t *)&xfer_packet.address)+nrfe_mspi_xfer.addr_length-i-1);
182+
for (uint8_t i = 0; i < nrfe_mspi_xfer_config.address_length; i++) {
183+
address_and_dummy_cycles[i] = *(((uint8_t *)&xfer_packet->address)+nrfe_mspi_xfer_config.address_length-i-1);
178184
}
179185

180-
for (uint8_t i = nrfe_mspi_xfer.addr_length; i < ADDR_AND_CYCLES_MAX_SIZE; i++) {
186+
for (uint8_t i = nrfe_mspi_xfer_config.address_length; i < ADDR_AND_CYCLES_MAX_SIZE; i++) {
181187
address_and_dummy_cycles[i] = 0;
182188
}
183189

@@ -187,15 +193,15 @@ static void xfer_execute(struct mspi_xfer_packet xfer_packet)
187193

188194
adjust_tail(&xfer_params.xfer_data[HRT_FE_ADDRESS],
189195
xfer_params.bus_widths.address,
190-
nrfe_mspi_xfer.addr_length * BITS_IN_BYTE +
191-
nrfe_mspi_xfer.tx_dummy * xfer_params.bus_widths.address);
196+
nrfe_mspi_xfer_config.address_length * BITS_IN_BYTE +
197+
nrfe_mspi_xfer_config.tx_dummy * xfer_params.bus_widths.address);
192198

193199
xfer_params.xfer_data[HRT_FE_DATA].vio_out_set = &nrf_vpr_csr_vio_out_buffered_reversed_byte_set;
194-
xfer_params.xfer_data[HRT_FE_DATA].data = xfer_packet.data_buf;
200+
xfer_params.xfer_data[HRT_FE_DATA].data = buffer;
195201
xfer_params.xfer_data[HRT_FE_DATA].word_count = 0;
196202

197203
adjust_tail(&xfer_params.xfer_data[HRT_FE_DATA],
198-
xfer_params.bus_widths.data, xfer_packet.num_bytes * BITS_IN_BYTE);
204+
xfer_params.bus_widths.data, xfer_packet->num_bytes * BITS_IN_BYTE);
199205

200206
nrf_vpr_clic_int_pending_set(NRF_VPRCLIC, VEVIF_IRQN(HRT_VEVIF_IDX_WRITE));
201207
}
@@ -213,7 +219,7 @@ static void config_pins(nrfe_mspi_pinctrl_soc_pin_t *pins_cfg)
213219

214220
uint8_t pin_number = NRF_PIN_NUMBER_TO_PIN(psel);
215221

216-
NRFX_ASSERT(pin_number < VIO_COUNT)
222+
NRFX_ASSERT(pin_number < NRFE_MSPI_VIO_COUNT)
217223

218224
if ((fun >= NRF_FUN_SDP_MSPI_CS0) && (fun <= NRF_FUN_SDP_MSPI_CS4)) {
219225

@@ -242,7 +248,24 @@ static void config_pins(nrfe_mspi_pinctrl_soc_pin_t *pins_cfg)
242248
}
243249
}
244250
nrf_vpr_csr_vio_dir_set(xfer_params.tx_direction_mask);
245-
nrf_vpr_csr_vio_out_set(VPRCSR_NORDIC_OUT_HIGH << pin_to_vio_map[NRFE_MSPI_CS0_PIN_NUMBER]);
251+
}
252+
253+
static void set_ce_pins()
254+
{
255+
for(uint8_t i=0; (i<NRFE_MSPI_CE_PINS_MAX) && (i<ce_vios_count); i++) {
256+
257+
switch(nrfe_mspi_xfer_config.ce_polarities[i])
258+
{
259+
case NRFE_MSPI_POL_UNDEFINED:
260+
break;
261+
case NRFE_MSPI_POL_ACTIVE_LOW:
262+
nrf_vpr_csr_vio_out_or_set(BIT(ce_vios[i]));
263+
break;
264+
case NRFE_MSPI_POL_ACTIVE_HIGH:
265+
nrf_vpr_csr_vio_out_clear_set(BIT(ce_vios[i]));
266+
break;
267+
}
268+
}
246269
}
247270

248271
static void ep_bound(void *priv)
@@ -265,31 +288,19 @@ static void ep_recv(const void *data, size_t len, void *priv)
265288
config_pins(pins_cfg);
266289
break;
267290
}
268-
case NRFE_MSPI_CONFIG_CTRL: {
269-
nrfe_mspi_cfg_t *cfg = (nrfe_mspi_cfg_t *)data;
270-
nrfe_mspi_cfg = cfg->cfg;
271-
break;
272-
}
273-
case NRFE_MSPI_CONFIG_DEV: {
274-
nrfe_mspi_dev_cfg_t *cfg = (nrfe_mspi_dev_cfg_t *)data;
275-
nrfe_mspi_dev_cfg = cfg->cfg;
276-
configure_clock(nrfe_mspi_dev_cfg.cpp);
277-
break;
278-
}
279291
case NRFE_MSPI_CONFIG_XFER: {
280-
nrfe_mspi_xfer_t *xfer = (nrfe_mspi_xfer_t *)data;
281-
nrfe_mspi_xfer = xfer->xfer;
292+
nrfe_mspi_xfer_config = *(nrfe_mspi_xfer_config_t *)data;
293+
configure_clock(nrfe_mspi_xfer_config.cpp);
294+
set_ce_pins();
282295
break;
283296
}
284297
case NRFE_MSPI_TX:
298+
nrfe_mspi_xfer_packet_t *packet = (nrfe_mspi_xfer_packet_t*)data;
299+
xfer_execute(packet, (uint8_t*)((uint8_t*)data+sizeof(nrfe_mspi_xfer_packet_t)));
300+
break;
285301
case NRFE_MSPI_TXRX: {
286302
nrfe_mspi_xfer_packet_t *packet = (nrfe_mspi_xfer_packet_t *)data;
287-
288-
if (packet->packet.dir == MSPI_RX) {
289-
/* TODO: Process received data */
290-
} else if (packet->packet.dir == MSPI_TX) {
291-
xfer_execute(packet->packet);
292-
}
303+
(void)packet;
293304
break;
294305
}
295306
default:

0 commit comments

Comments
 (0)