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.
pull/2219/head
Rohit Grover 2016-07-22 09:12:50 +01:00
parent 4b441c9e9e
commit 4f2c3edf5b
1 changed files with 24 additions and 12 deletions

View File

@ -146,7 +146,6 @@ extern volatile uint32_t *const kFCCOBx;
#define SIZEOF_DOUBLE_PHRASE (16) #define SIZEOF_DOUBLE_PHRASE (16)
#endif /* #ifdef USING_KSDK2 */ #endif /* #ifdef USING_KSDK2 */
/* /*
* forward declarations * forward declarations
*/ */
@ -369,6 +368,8 @@ static inline void clearErrorStatusBits()
} }
} }
/* The following functions are only needed if using interrupt-driven operation. */
#if ASYNC_OPS
static inline void enableCommandCompletionInterrupt(void) static inline void enableCommandCompletionInterrupt(void)
{ {
#ifdef USING_KSDK2 #ifdef USING_KSDK2
@ -410,6 +411,23 @@ static inline void launchCommand(void)
#endif #endif
} }
#else /* #if !ASYNC_OPS */
static void launchCommandAndWaitForCompletion()
{
// It contains the inlined equivalent of the following code snippet:
// launchCommand();
// while (controllerCurrentlyBusy()) {
// /* Spin waiting for the command execution to complete. */
// }
FTFx->FSTAT = FTFx_FSTAT_CCIF_MASK; /* launchcommand() */
while ((FTFx->FSTAT & FTFx_FSTAT_CCIF_MASK) == 0) {
/* Spin waiting for the command execution to complete. */
}
}
#endif /* #if !ASYNC_OPS */
#ifndef USING_KSDK2 #ifndef USING_KSDK2
static inline void setupAddressInCCOB123(uint64_t addr) static inline void setupAddressInCCOB123(uint64_t addr)
{ {
@ -547,17 +565,14 @@ static inline void setupNextErase(struct mtd_k64f_data *context)
static int32_t executeCommand(struct mtd_k64f_data *context) static int32_t executeCommand(struct mtd_k64f_data *context)
{ {
#if ASYNC_OPS
/* Asynchronous operation */
(void)context; /* avoid compiler warning about un-used variables */
launchCommand(); launchCommand();
/* At this point, The FTFE reads the command code and performs a series of /* At this point, The FTFE reads the command code and performs a series of
* parameter checks and protection checks, if applicable, which are unique * parameter checks and protection checks, if applicable, which are unique
* to each command. */ * to each command. */
#if ASYNC_OPS
/* Asynchronous operation */
(void)context; /* avoid compiler warning about un-used variables */
/* Spin waiting for the command execution to begin. */ /* Spin waiting for the command execution to begin. */
while (!controllerCurrentlyBusy() && !failedWithAccessError() && !failedWithProtectionError()); while (!controllerCurrentlyBusy() && !failedWithAccessError() && !failedWithProtectionError());
if (failedWithAccessError() || failedWithProtectionError()) { if (failedWithAccessError() || failedWithProtectionError()) {
@ -572,8 +587,7 @@ static int32_t executeCommand(struct mtd_k64f_data *context)
/* Synchronous operation. */ /* Synchronous operation. */
while (1) { while (1) {
/* Spin waiting for the command execution to complete. */ launchCommandAndWaitForCompletion();
while (controllerCurrentlyBusy());
/* Execution may result in failure. Check for errors */ /* Execution may result in failure. Check for errors */
if (failedWithAccessError() || failedWithProtectionError()) { if (failedWithAccessError() || failedWithProtectionError()) {
@ -593,7 +607,6 @@ static int32_t executeCommand(struct mtd_k64f_data *context)
/* start the successive program operation */ /* start the successive program operation */
setupNextProgramData(context); setupNextProgramData(context);
launchCommand();
/* continue on to the next iteration of the parent loop */ /* continue on to the next iteration of the parent loop */
break; break;
@ -603,7 +616,6 @@ static int32_t executeCommand(struct mtd_k64f_data *context)
} }
setupNextErase(context); /* start the successive erase operation */ setupNextErase(context); /* start the successive erase operation */
launchCommand();
/* continue on to the next iteration of the parent loop */ /* continue on to the next iteration of the parent loop */
break; break;