Skip to content

Commit 75d8c0f

Browse files
committed
K64F: Update SPI aynchronous API for tickless implementation
Do not allow entry to deep sleep mode when SPI transfer is active Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent 91349e2 commit 75d8c0f

File tree

1 file changed

+13
-0
lines changed
  • targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F

1 file changed

+13
-0
lines changed

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/spi_api.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "cmsis.h"
2424
#include "pinmap.h"
2525
#include "mbed_error.h"
26+
#include "mbed_power_mgmt.h"
2627
#include "fsl_dspi.h"
2728
#include "peripheral_clock_defines.h"
2829
#include "dma_reqs.h"
@@ -369,6 +370,9 @@ void spi_master_transfer(spi_t *obj, const void *tx, size_t tx_length, void *rx,
369370
/* Start the transfer */
370371
if (spi_master_transfer_asynch(obj) != kStatus_Success) {
371372
obj->spi.status = kDSPI_Idle;
373+
} else {
374+
// Can't enter deep sleep as long as SPI transfer is active
375+
sleep_manager_lock_deep_sleep();
372376
}
373377
}
374378

@@ -428,12 +432,18 @@ uint32_t spi_irq_handler_asynch(spi_t *obj)
428432
}
429433
obj->spi.status = kDSPI_Idle;
430434

435+
// SPI transfer done, can enter deep sleep
436+
sleep_manager_unlock_deep_sleep();
437+
431438
return SPI_EVENT_COMPLETE;
432439
}
433440
} else {
434441
/* Interrupt implementation */
435442
obj->spi.status = kDSPI_Idle;
436443

444+
// SPI transfer done, can enter deep sleep
445+
sleep_manager_unlock_deep_sleep();
446+
437447
return SPI_EVENT_COMPLETE;
438448
}
439449
}
@@ -462,6 +472,9 @@ void spi_abort_asynch(spi_t *obj)
462472
}
463473

464474
obj->spi.status = kDSPI_Idle;
475+
476+
// SPI transfer done, can enter deep sleep
477+
sleep_manager_unlock_deep_sleep();
465478
}
466479

467480
uint8_t spi_active(spi_t *obj)

0 commit comments

Comments
 (0)