@@ -204,6 +204,13 @@ static const ARM_DRIVER_VERSION version = {
204
204
.drv = ARM_DRIVER_VERSION_MAJOR_MINOR (1 ,00 )
205
205
};
206
206
207
+
208
+ #if (!defined(CONFIG_HARDWARE_MTD_ASYNC_OPS ) || CONFIG_HARDWARE_MTD_ASYNC_OPS )
209
+ #define ASYNC_OPS 1
210
+ #else
211
+ #define ASYNC_OPS 0
212
+ #endif
213
+
207
214
static const ARM_STORAGE_CAPABILITIES caps = {
208
215
/**< Signal Flash Ready event. In other words, can APIs like initialize,
209
216
* read, erase, program, etc. operate in asynchronous mode?
@@ -214,11 +221,7 @@ static const ARM_STORAGE_CAPABILITIES caps = {
214
221
* 1, drivers may still complete asynchronous operations synchronously as
215
222
* necessary--in which case they return a positive error code to indicate
216
223
* synchronous completion. */
217
- #ifndef CONFIG_HARDWARE_MTD_ASYNC_OPS
218
- .asynchronous_ops = 1 ,
219
- #else
220
- .asynchronous_ops = CONFIG_HARDWARE_MTD_ASYNC_OPS ,
221
- #endif
224
+ .asynchronous_ops = ASYNC_OPS ,
222
225
223
226
/* Enable chip-erase functionality if we own all of block-1. */
224
227
#if ((!defined (CONFIG_HARDWARE_MTD_START_ADDR ) || (CONFIG_HARDWARE_MTD_START_ADDR == BLOCK1_START_ADDR )) && \
@@ -271,7 +274,6 @@ enum FlashCommandOps {
271
274
SETRAM = (uint8_t )0x81 , /* Set FlexRAM. (unused for now) */
272
275
};
273
276
274
-
275
277
/**
276
278
* Read out the CCIF (Command Complete Interrupt Flag) to ensure all previous
277
279
* operations have completed.
@@ -394,11 +396,6 @@ static inline bool commandCompletionInterruptEnabled(void)
394
396
#endif
395
397
}
396
398
397
- static inline bool asyncOperationsEnabled (void )
398
- {
399
- return caps .asynchronous_ops ;
400
- }
401
-
402
399
/**
403
400
* Once all relevant command parameters have been loaded, the user launches the
404
401
* command by clearing the FSTAT[CCIF] bit by writing a '1' to it. The CCIF flag
@@ -556,66 +553,68 @@ static int32_t executeCommand(struct mtd_k64f_data *context)
556
553
* parameter checks and protection checks, if applicable, which are unique
557
554
* to each command. */
558
555
559
- if (asyncOperationsEnabled ()) {
560
- /* Asynchronous operation */
556
+ #if ASYNC_OPS
557
+ /* Asynchronous operation */
558
+
559
+ (void )context ; /* avoid compiler warning about un-used variables */
560
+
561
+ /* Spin waiting for the command execution to begin. */
562
+ while (!controllerCurrentlyBusy () && !failedWithAccessError () && !failedWithProtectionError ());
563
+ if (failedWithAccessError () || failedWithProtectionError ()) {
564
+ clearErrorStatusBits ();
565
+ return ARM_DRIVER_ERROR_PARAMETER ;
566
+ }
567
+
568
+ enableCommandCompletionInterrupt ();
561
569
562
- /* Spin waiting for the command execution to begin. */
563
- while (!controllerCurrentlyBusy () && !failedWithAccessError () && !failedWithProtectionError ());
570
+ return ARM_DRIVER_OK ; /* signal asynchronous completion. An interrupt will signal completion later. */
571
+ #else /* #if ASYNC_OPS */
572
+ /* Synchronous operation. */
573
+
574
+ while (1 ) {
575
+ /* Spin waiting for the command execution to complete. */
576
+ while (controllerCurrentlyBusy ());
577
+
578
+ /* Execution may result in failure. Check for errors */
564
579
if (failedWithAccessError () || failedWithProtectionError ()) {
565
580
clearErrorStatusBits ();
566
581
return ARM_DRIVER_ERROR_PARAMETER ;
567
582
}
583
+ if (failedWithRunTimeError ()) {
584
+ return ARM_DRIVER_ERROR ; /* unspecified runtime error. */
585
+ }
568
586
569
- enableCommandCompletionInterrupt ();
570
-
571
- return ARM_DRIVER_OK ; /* signal asynchronous completion. An interrupt will signal completion later. */
572
- } else {
573
- /* Synchronous operation. */
587
+ /* signal synchronous completion. */
588
+ switch (context -> currentCommand ) {
589
+ case ARM_STORAGE_OPERATION_PROGRAM_DATA :
590
+ if (context -> amountLeftToOperate == 0 ) {
591
+ return context -> sizeofCurrentOperation ;
592
+ }
574
593
575
- while (1 ) {
594
+ /* start the successive program operation */
595
+ setupNextProgramData (context );
596
+ launchCommand ();
597
+ /* continue on to the next iteration of the parent loop */
598
+ break ;
576
599
577
- /* Spin waiting for the command execution to complete. */
578
- while (controllerCurrentlyBusy ());
600
+ case ARM_STORAGE_OPERATION_ERASE :
601
+ if (context -> amountLeftToOperate == 0 ) {
602
+ return context -> sizeofCurrentOperation ;
603
+ }
579
604
580
- /* Execution may result in failure. Check for errors */
581
- if (failedWithAccessError () || failedWithProtectionError ()) {
582
- clearErrorStatusBits ();
583
- return ARM_DRIVER_ERROR_PARAMETER ;
584
- }
585
- if (failedWithRunTimeError ()) {
586
- return ARM_DRIVER_ERROR ; /* unspecified runtime error. */
587
- }
605
+ setupNextErase (context ); /* start the successive erase operation */
606
+ launchCommand ();
607
+ /* continue on to the next iteration of the parent loop */
608
+ break ;
588
609
589
- /* signal synchronous completion. */
590
- switch (context -> currentCommand ) {
591
- case ARM_STORAGE_OPERATION_PROGRAM_DATA :
592
- if (context -> amountLeftToOperate == 0 ) {
593
- return context -> sizeofCurrentOperation ;
594
- }
595
-
596
- /* start the successive program operation */
597
- setupNextProgramData (context );
598
- launchCommand ();
599
- /* continue on to the next iteration of the parent loop */
600
- break ;
601
-
602
- case ARM_STORAGE_OPERATION_ERASE :
603
- if (context -> amountLeftToOperate == 0 ) {
604
- return context -> sizeofCurrentOperation ;
605
- }
606
-
607
- setupNextErase (context ); /* start the successive erase operation */
608
- launchCommand ();
609
- /* continue on to the next iteration of the parent loop */
610
- break ;
611
-
612
- default :
613
- return 1 ;
614
- }
610
+ default :
611
+ return 1 ;
615
612
}
616
613
}
614
+ #endif /* #ifdef ASYNC_OPS */
617
615
}
618
616
617
+ #if ASYNC_OPS
619
618
static void ftfe_ccie_irq_handler (void )
620
619
{
621
620
disbleCommandCompletionInterrupt ();
@@ -691,6 +690,7 @@ static void ftfe_ccie_irq_handler(void)
691
690
break ;
692
691
}
693
692
}
693
+ #endif /* #if ASYNC_OPS */
694
694
695
695
/**
696
696
* This is a helper function which can be used to do arbitrary sanity checking
@@ -772,11 +772,11 @@ static int32_t initialize(ARM_Storage_Callback_t callback)
772
772
context -> commandCompletionCallback = callback ;
773
773
774
774
/* Enable the command-completion interrupt. */
775
- if ( asyncOperationsEnabled ()) {
776
- NVIC_SetVector (FTFE_IRQn , (uint32_t )ftfe_ccie_irq_handler );
777
- NVIC_ClearPendingIRQ (FTFE_IRQn );
778
- NVIC_EnableIRQ (FTFE_IRQn );
779
- }
775
+ # if ASYNC_OPS
776
+ NVIC_SetVector (FTFE_IRQn , (uint32_t )ftfe_ccie_irq_handler );
777
+ NVIC_ClearPendingIRQ (FTFE_IRQn );
778
+ NVIC_EnableIRQ (FTFE_IRQn );
779
+ #endif
780
780
781
781
context -> initialized = true;
782
782
@@ -792,11 +792,13 @@ static int32_t uninitialize(void) {
792
792
}
793
793
794
794
/* Disable the command-completion interrupt. */
795
- if (asyncOperationsEnabled () && commandCompletionInterruptEnabled ()) {
795
+ #if ASYNC_OPS
796
+ if (commandCompletionInterruptEnabled ()) {
796
797
disbleCommandCompletionInterrupt ();
797
798
NVIC_DisableIRQ (FTFE_IRQn );
798
799
NVIC_ClearPendingIRQ (FTFE_IRQn );
799
800
}
801
+ #endif
800
802
801
803
context -> commandCompletionCallback = NULL ;
802
804
context -> initialized = false;
0 commit comments