@@ -80,6 +80,7 @@ typedef struct
80
80
81
81
bool tx_done : 1 ;
82
82
bool rx_done : 1 ;
83
+ bool abort : 1 ;
83
84
} spi_control_block_t ;
84
85
static spi_control_block_t m_cb [SPI_COUNT ];
85
86
@@ -202,7 +203,7 @@ ret_code_t nrf_drv_spi_init(nrf_drv_spi_t const * const p_instance,
202
203
203
204
CODE_FOR_SPIM
204
205
(
205
- NRF_SPIM_Type * p_spim = p_instance -> p_registers ;
206
+ NRF_SPIM_Type * p_spim = ( NRF_SPIM_Type * ) p_instance -> p_registers ;
206
207
nrf_spim_pins_set (p_spim , p_config -> sck_pin , mosi_pin , miso_pin );
207
208
nrf_spim_frequency_set (p_spim ,
208
209
(nrf_spim_frequency_t )p_config -> frequency );
@@ -221,7 +222,7 @@ ret_code_t nrf_drv_spi_init(nrf_drv_spi_t const * const p_instance,
221
222
)
222
223
CODE_FOR_SPI
223
224
(
224
- NRF_SPI_Type * p_spi = p_instance -> p_registers ;
225
+ NRF_SPI_Type * p_spi = ( NRF_SPI_Type * ) p_instance -> p_registers ;
225
226
nrf_spi_pins_set (p_spi , p_config -> sck_pin , mosi_pin , miso_pin );
226
227
nrf_spi_frequency_set (p_spi ,
227
228
(nrf_spi_frequency_t )p_config -> frequency );
@@ -264,7 +265,7 @@ void nrf_drv_spi_uninit(nrf_drv_spi_t const * const p_instance)
264
265
265
266
CODE_FOR_SPIM
266
267
(
267
- NRF_SPIM_Type * p_spim = p_instance -> p_registers ;
268
+ NRF_SPIM_Type * p_spim = ( NRF_SPIM_Type * ) p_instance -> p_registers ;
268
269
if (p_cb -> handler )
269
270
{
270
271
nrf_spim_int_disable (p_spim , DISABLE_ALL );
@@ -280,7 +281,7 @@ void nrf_drv_spi_uninit(nrf_drv_spi_t const * const p_instance)
280
281
)
281
282
CODE_FOR_SPI
282
283
(
283
- NRF_SPI_Type * p_spi = p_instance -> p_registers ;
284
+ NRF_SPI_Type * p_spi = ( NRF_SPI_Type * ) p_instance -> p_registers ;
284
285
if (p_cb -> handler )
285
286
{
286
287
nrf_spi_int_disable (p_spi , DISABLE_ALL );
@@ -352,6 +353,19 @@ static bool transfer_byte(NRF_SPI_Type * p_spi, spi_control_block_t * p_cb)
352
353
// see how the transfer is started in the 'nrf_drv_spi_transfer'
353
354
// function.
354
355
uint16_t bytes_used = p_cb -> bytes_transferred + 1 ;
356
+
357
+ if (p_cb -> abort )
358
+ {
359
+ if (bytes_used < p_cb -> evt .data .done .tx_length )
360
+ {
361
+ p_cb -> evt .data .done .tx_length = bytes_used ;
362
+ }
363
+ if (bytes_used < p_cb -> evt .data .done .rx_length )
364
+ {
365
+ p_cb -> evt .data .done .rx_length = bytes_used ;
366
+ }
367
+ }
368
+
355
369
if (bytes_used < p_cb -> evt .data .done .tx_length )
356
370
{
357
371
nrf_spi_txd_set (p_spi , p_cb -> evt .data .done .p_tx_buffer [bytes_used ]);
@@ -371,8 +385,8 @@ static void spi_xfer(NRF_SPI_Type * p_spi,
371
385
spi_control_block_t * p_cb ,
372
386
nrf_drv_spi_xfer_desc_t const * p_xfer_desc )
373
387
{
374
- p_cb -> bytes_transferred = 0 ;
375
388
nrf_spi_int_disable (p_spi , NRF_SPI_INT_READY_MASK );
389
+ p_cb -> bytes_transferred = 0 ;
376
390
377
391
nrf_spi_event_clear (p_spi , NRF_SPI_EVENT_READY );
378
392
@@ -516,8 +530,8 @@ ret_code_t nrf_drv_spi_xfer(nrf_drv_spi_t const * const p_instance,
516
530
{
517
531
spi_control_block_t * p_cb = & m_cb [p_instance -> drv_inst_idx ];
518
532
ASSERT (p_cb -> state != NRF_DRV_STATE_UNINITIALIZED );
519
- ASSERT (p_tx_buffer != NULL || tx_buffer_length == 0 );
520
- ASSERT (p_rx_buffer != NULL || rx_buffer_length == 0 );
533
+ ASSERT (p_xfer_desc -> p_tx_buffer != NULL || p_xfer_desc -> tx_length == 0 );
534
+ ASSERT (p_xfer_desc -> p_rx_buffer != NULL || p_xfer_desc -> rx_length == 0 );
521
535
522
536
if (p_cb -> transfer_in_progress )
523
537
{
@@ -534,14 +548,15 @@ ret_code_t nrf_drv_spi_xfer(nrf_drv_spi_t const * const p_instance,
534
548
p_cb -> evt .data .done = * p_xfer_desc ;
535
549
p_cb -> tx_done = false;
536
550
p_cb -> rx_done = false;
551
+ p_cb -> abort = false;
537
552
538
553
if (p_cb -> ss_pin != NRF_DRV_SPI_PIN_NOT_USED )
539
554
{
540
555
nrf_gpio_pin_clear (p_cb -> ss_pin );
541
556
}
542
557
CODE_FOR_SPIM
543
558
(
544
- return spim_xfer (p_instance -> p_registers , p_cb , p_xfer_desc , flags );
559
+ return spim_xfer (( NRF_SPIM_Type * ) p_instance -> p_registers , p_cb , p_xfer_desc , flags );
545
560
)
546
561
CODE_FOR_SPI
547
562
(
@@ -550,10 +565,28 @@ ret_code_t nrf_drv_spi_xfer(nrf_drv_spi_t const * const p_instance,
550
565
p_cb -> transfer_in_progress = false;
551
566
return NRF_ERROR_NOT_SUPPORTED ;
552
567
}
553
- spi_xfer (p_instance -> p_registers , p_cb , p_xfer_desc );
568
+ spi_xfer (( NRF_SPI_Type * ) p_instance -> p_registers , p_cb , p_xfer_desc );
554
569
return NRF_SUCCESS ;
555
570
)
556
571
}
572
+
573
+ void nrf_drv_spi_abort (nrf_drv_spi_t const * p_instance )
574
+ {
575
+ spi_control_block_t * p_cb = & m_cb [p_instance -> drv_inst_idx ];
576
+ ASSERT (p_cb -> state != NRF_DRV_STATE_UNINITIALIZED );
577
+
578
+ CODE_FOR_SPIM
579
+ (
580
+ nrf_spim_task_trigger (p_spim , NRF_SPIM_TASK_STOP );
581
+ while (!nrf_spim_event_check (p_spim , NRF_SPIM_EVENT_STOPPED )) {}
582
+ p_cb -> transfer_in_progress = false;
583
+ )
584
+ CODE_FOR_SPI
585
+ (
586
+ p_cb -> abort = true;
587
+ )
588
+ }
589
+
557
590
#ifdef SPIM_IN_USE
558
591
static void irq_handler_spim (NRF_SPIM_Type * p_spim , spi_control_block_t * p_cb )
559
592
{
0 commit comments