Skip to content

Commit 4f2c3ed

Browse files
author
Rohit Grover
committed
salvaging the changes from PR#2150 which are useful in spite of fix to RWW
The RWW fix is controversial because it requires holding off interrupts for periods of around 5ms at a time. But there were still some minor improvements around that change which could be retained. This commit contains these changes.
1 parent 4b441c9 commit 4f2c3ed

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

hal/targets/hal/TARGET_Freescale/TARGET_KSDK2_MCUS/TARGET_K64F/storage_driver.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ extern volatile uint32_t *const kFCCOBx;
146146
#define SIZEOF_DOUBLE_PHRASE (16)
147147
#endif /* #ifdef USING_KSDK2 */
148148

149-
150149
/*
151150
* forward declarations
152151
*/
@@ -369,6 +368,8 @@ static inline void clearErrorStatusBits()
369368
}
370369
}
371370

371+
/* The following functions are only needed if using interrupt-driven operation. */
372+
#if ASYNC_OPS
372373
static inline void enableCommandCompletionInterrupt(void)
373374
{
374375
#ifdef USING_KSDK2
@@ -410,6 +411,23 @@ static inline void launchCommand(void)
410411
#endif
411412
}
412413

414+
#else /* #if !ASYNC_OPS */
415+
416+
static void launchCommandAndWaitForCompletion()
417+
{
418+
// It contains the inlined equivalent of the following code snippet:
419+
// launchCommand();
420+
// while (controllerCurrentlyBusy()) {
421+
// /* Spin waiting for the command execution to complete. */
422+
// }
423+
424+
FTFx->FSTAT = FTFx_FSTAT_CCIF_MASK; /* launchcommand() */
425+
while ((FTFx->FSTAT & FTFx_FSTAT_CCIF_MASK) == 0) {
426+
/* Spin waiting for the command execution to complete. */
427+
}
428+
}
429+
#endif /* #if !ASYNC_OPS */
430+
413431
#ifndef USING_KSDK2
414432
static inline void setupAddressInCCOB123(uint64_t addr)
415433
{
@@ -547,17 +565,14 @@ static inline void setupNextErase(struct mtd_k64f_data *context)
547565

548566
static int32_t executeCommand(struct mtd_k64f_data *context)
549567
{
568+
#if ASYNC_OPS
569+
/* Asynchronous operation */
570+
(void)context; /* avoid compiler warning about un-used variables */
550571
launchCommand();
551572

552573
/* At this point, The FTFE reads the command code and performs a series of
553574
* parameter checks and protection checks, if applicable, which are unique
554575
* to each command. */
555-
556-
#if ASYNC_OPS
557-
/* Asynchronous operation */
558-
559-
(void)context; /* avoid compiler warning about un-used variables */
560-
561576
/* Spin waiting for the command execution to begin. */
562577
while (!controllerCurrentlyBusy() && !failedWithAccessError() && !failedWithProtectionError());
563578
if (failedWithAccessError() || failedWithProtectionError()) {
@@ -572,8 +587,7 @@ static int32_t executeCommand(struct mtd_k64f_data *context)
572587
/* Synchronous operation. */
573588

574589
while (1) {
575-
/* Spin waiting for the command execution to complete. */
576-
while (controllerCurrentlyBusy());
590+
launchCommandAndWaitForCompletion();
577591

578592
/* Execution may result in failure. Check for errors */
579593
if (failedWithAccessError() || failedWithProtectionError()) {
@@ -593,7 +607,6 @@ static int32_t executeCommand(struct mtd_k64f_data *context)
593607

594608
/* start the successive program operation */
595609
setupNextProgramData(context);
596-
launchCommand();
597610
/* continue on to the next iteration of the parent loop */
598611
break;
599612

@@ -603,7 +616,6 @@ static int32_t executeCommand(struct mtd_k64f_data *context)
603616
}
604617

605618
setupNextErase(context); /* start the successive erase operation */
606-
launchCommand();
607619
/* continue on to the next iteration of the parent loop */
608620
break;
609621

@@ -831,7 +843,7 @@ static int32_t readData(uint64_t addr, void *data, uint32_t size)
831843
return ARM_DRIVER_ERROR_PARAMETER; /* illegal address range */
832844
}
833845

834-
context->currentCommand = ARM_STORAGE_OPERATION_READ_DATA;
846+
context->currentCommand = ARM_STORAGE_OPERATION_READ_DATA;
835847
memcpy(data, (const void *)(uintptr_t)addr, size);
836848
return size; /* signal synchronous completion. */
837849
}

0 commit comments

Comments
 (0)