17
17
18
18
#include <drivers/mspi/nrfe_mspi.h>
19
19
20
- #define CE_PINS_MAX 9
21
- #define DATA_PINS_MAX 8
22
- #define VIO_COUNT 11
23
-
24
20
#define SUPPORTED_IO_MODES_COUNT 7
25
21
26
22
#define HRT_IRQ_PRIORITY 2
32
28
/* In OCTAL mode 4 bytes for address + 32 bytes for up to 32 dummy cycles*/
33
29
#define ADDR_AND_CYCLES_MAX_SIZE 36
34
30
35
- static const uint8_t pin_to_vio_map [VIO_COUNT ] = {
31
+ static const uint8_t pin_to_vio_map [NRFE_MSPI_VIO_COUNT ] = {
36
32
4 , /* Physical pin 0 */
37
33
0 , /* Physical pin 1 */
38
34
1 , /* Physical pin 2 */
@@ -57,18 +53,27 @@ static const hrt_xfer_bus_widths_t io_modes[SUPPORTED_IO_MODES_COUNT] = {
57
53
};
58
54
59
55
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 ];
61
57
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
+
66
61
static volatile hrt_xfer_t xfer_params ;
67
62
static volatile uint8_t address_and_dummy_cycles [ADDR_AND_CYCLES_MAX_SIZE ];
68
63
69
64
static struct ipc_ept ep ;
70
65
static atomic_t ipc_atomic_sem = ATOMIC_INIT (0 );
71
66
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
+
72
77
static void adjust_tail (volatile hrt_xfer_data_t * xfer_data , uint16_t frame_width , uint32_t data_length )
73
78
{
74
79
if (data_length == 0 ) {
@@ -148,36 +153,37 @@ static void configure_clock(enum mspi_cpp_mode cpp_mode)
148
153
nrf_vpr_csr_vio_config_set (& vio_config );
149
154
}
150
155
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 )
152
157
{
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 );
155
161
156
162
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
+
162
168
/* Fix position of command if command length is < BITS_IN_WORD,
163
169
* so that leading zeros would not be printed instead of data bits.
164
170
*/
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 );
167
173
168
174
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 ;
170
176
xfer_params .xfer_data [HRT_FE_COMMAND ].word_count = 0 ;
171
177
172
178
adjust_tail (& xfer_params .xfer_data [HRT_FE_COMMAND ],
173
179
xfer_params .bus_widths .command ,
174
- nrfe_mspi_xfer . cmd_length * BITS_IN_BYTE );
180
+ nrfe_mspi_xfer_config . command_length * BITS_IN_BYTE );
175
181
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 );
178
184
}
179
185
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 ++ ) {
181
187
address_and_dummy_cycles [i ] = 0 ;
182
188
}
183
189
@@ -187,15 +193,15 @@ static void xfer_execute(struct mspi_xfer_packet xfer_packet)
187
193
188
194
adjust_tail (& xfer_params .xfer_data [HRT_FE_ADDRESS ],
189
195
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 );
192
198
193
199
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 ;
195
201
xfer_params .xfer_data [HRT_FE_DATA ].word_count = 0 ;
196
202
197
203
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 );
199
205
200
206
nrf_vpr_clic_int_pending_set (NRF_VPRCLIC , VEVIF_IRQN (HRT_VEVIF_IDX_WRITE ));
201
207
}
@@ -213,7 +219,7 @@ static void config_pins(nrfe_mspi_pinctrl_soc_pin_t *pins_cfg)
213
219
214
220
uint8_t pin_number = NRF_PIN_NUMBER_TO_PIN (psel );
215
221
216
- NRFX_ASSERT (pin_number < VIO_COUNT )
222
+ NRFX_ASSERT (pin_number < NRFE_MSPI_VIO_COUNT )
217
223
218
224
if ((fun >= NRF_FUN_SDP_MSPI_CS0 ) && (fun <= NRF_FUN_SDP_MSPI_CS4 )) {
219
225
@@ -242,7 +248,24 @@ static void config_pins(nrfe_mspi_pinctrl_soc_pin_t *pins_cfg)
242
248
}
243
249
}
244
250
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
+ }
246
269
}
247
270
248
271
static void ep_bound (void * priv )
@@ -265,31 +288,19 @@ static void ep_recv(const void *data, size_t len, void *priv)
265
288
config_pins (pins_cfg );
266
289
break ;
267
290
}
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
- }
279
291
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 ();
282
295
break ;
283
296
}
284
297
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 ;
285
301
case NRFE_MSPI_TXRX : {
286
302
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 ;
293
304
break ;
294
305
}
295
306
default :
0 commit comments