@@ -146,7 +146,6 @@ extern volatile uint32_t *const kFCCOBx;
146
146
#define SIZEOF_DOUBLE_PHRASE (16)
147
147
#endif /* #ifdef USING_KSDK2 */
148
148
149
-
150
149
/*
151
150
* forward declarations
152
151
*/
@@ -369,6 +368,8 @@ static inline void clearErrorStatusBits()
369
368
}
370
369
}
371
370
371
+ /* The following functions are only needed if using interrupt-driven operation. */
372
+ #if ASYNC_OPS
372
373
static inline void enableCommandCompletionInterrupt (void )
373
374
{
374
375
#ifdef USING_KSDK2
@@ -410,6 +411,23 @@ static inline void launchCommand(void)
410
411
#endif
411
412
}
412
413
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
+
413
431
#ifndef USING_KSDK2
414
432
static inline void setupAddressInCCOB123 (uint64_t addr )
415
433
{
@@ -547,17 +565,14 @@ static inline void setupNextErase(struct mtd_k64f_data *context)
547
565
548
566
static int32_t executeCommand (struct mtd_k64f_data * context )
549
567
{
568
+ #if ASYNC_OPS
569
+ /* Asynchronous operation */
570
+ (void )context ; /* avoid compiler warning about un-used variables */
550
571
launchCommand ();
551
572
552
573
/* At this point, The FTFE reads the command code and performs a series of
553
574
* parameter checks and protection checks, if applicable, which are unique
554
575
* to each command. */
555
-
556
- #if ASYNC_OPS
557
- /* Asynchronous operation */
558
-
559
- (void )context ; /* avoid compiler warning about un-used variables */
560
-
561
576
/* Spin waiting for the command execution to begin. */
562
577
while (!controllerCurrentlyBusy () && !failedWithAccessError () && !failedWithProtectionError ());
563
578
if (failedWithAccessError () || failedWithProtectionError ()) {
@@ -572,8 +587,7 @@ static int32_t executeCommand(struct mtd_k64f_data *context)
572
587
/* Synchronous operation. */
573
588
574
589
while (1 ) {
575
- /* Spin waiting for the command execution to complete. */
576
- while (controllerCurrentlyBusy ());
590
+ launchCommandAndWaitForCompletion ();
577
591
578
592
/* Execution may result in failure. Check for errors */
579
593
if (failedWithAccessError () || failedWithProtectionError ()) {
@@ -593,7 +607,6 @@ static int32_t executeCommand(struct mtd_k64f_data *context)
593
607
594
608
/* start the successive program operation */
595
609
setupNextProgramData (context );
596
- launchCommand ();
597
610
/* continue on to the next iteration of the parent loop */
598
611
break ;
599
612
@@ -603,7 +616,6 @@ static int32_t executeCommand(struct mtd_k64f_data *context)
603
616
}
604
617
605
618
setupNextErase (context ); /* start the successive erase operation */
606
- launchCommand ();
607
619
/* continue on to the next iteration of the parent loop */
608
620
break ;
609
621
@@ -831,7 +843,7 @@ static int32_t readData(uint64_t addr, void *data, uint32_t size)
831
843
return ARM_DRIVER_ERROR_PARAMETER ; /* illegal address range */
832
844
}
833
845
834
- context -> currentCommand = ARM_STORAGE_OPERATION_READ_DATA ;
846
+ context -> currentCommand = ARM_STORAGE_OPERATION_READ_DATA ;
835
847
memcpy (data , (const void * )(uintptr_t )addr , size );
836
848
return size ; /* signal synchronous completion. */
837
849
}
0 commit comments