Choco OS  V.0.16.9.0
Join to the chocolate world
oc_fmc.c
Go to the documentation of this file.
1 
30 #include <oc_fmc.h>
31 #include <oc_fmc_lld.h>
32 #include <oc_compiler.h>
33 #include <oc_module.h>
34 #include <oc_intman.h>
35 #include <oc_null.h>
36 #include <oc_math.h>
37 #include <oc_memman.h>
38 #include <oc_struct.h>
39 #include <oc_gpio.h>
40 
41 #ifdef oC_FMC_LLD_AVAILABLE
42 
48 #define _________________________________________DRIVER_DEFINITIONS_SECTION_________________________________________________________________
49 
50 #define DRIVER_SOURCE
51 
52 /* Driver basic definitions */
53 #define DRIVER_NAME FMC
54 #define DRIVER_FILE_NAME "fmc"
55 #define DRIVER_VERSION oC_Driver_MakeVersion(1,0,0)
56 #define REQUIRED_DRIVERS &GPIO
57 #define REQUIRED_BOOT_LEVEL oC_Boot_Level_RequireMemoryManager | oC_Boot_Level_RequireDriversManager
58 
59 /* Driver interface definitions */
60 #define DRIVER_CONFIGURE oC_FMC_Configure
61 #define DRIVER_UNCONFIGURE oC_FMC_Unconfigure
62 #define DRIVER_TURN_ON oC_FMC_TurnOn
63 #define DRIVER_TURN_OFF oC_FMC_TurnOff
64 #define IS_TURNED_ON oC_FMC_IsTurnedOn
65 #define HANDLE_IOCTL oC_FMC_Ioctl
66 #define READ_FROM_DRIVER oC_FMC_Read
67 #define WRITE_TO_DRIVER oC_FMC_Write
68 
69 #undef _________________________________________DRIVER_DEFINITIONS_SECTION_________________________________________________________________
70 
71 /* This header must be always at the end of include list */
72 #include <oc_driver.h>
73 
79 #define _________________________________________TYPES_SECTION______________________________________________________________________________
80 
81 //==========================================================================================================================================
87 //==========================================================================================================================================
88 struct Context_t
89 {
92  oC_FMC_LLD_Result_t ConfigurationResult;
93  oC_UInt_t FileOffset;
94  oC_FMC_Protection_t Protection;
95  oC_FMC_LLD_MemoryType_t MemoryType;
96  oC_FMC_ChipInfo_t ChipInfo;
97  oC_Time_t Timeout;
98  bool UsedAsHeap;
99 };
100 
101 #undef _________________________________________TYPES_SECTION______________________________________________________________________________
102 
108 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________
109 
110 //==========================================================================================================================================
114 //==========================================================================================================================================
115 static const oC_Allocator_t Allocator = {
116  .Name = "fmc module"
117 };
118 
119 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________
120 
126 #define _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________
127 
128 static inline bool IsContextCorrect ( oC_FMC_Context_t Context );
129 static inline bool IsMemoryTypeCorrect ( oC_FMC_LLD_MemoryType_t MemoryType );
130 static oC_FMC_Context_t Context_New ( const oC_FMC_Config_t * Config );
131 static bool Context_Delete ( oC_FMC_Context_t * outContext );
132 static oC_ErrorCode_t ReadData ( oC_FMC_Context_t Context , char * outData );
133 static oC_ErrorCode_t WriteData ( oC_FMC_Context_t Context , char Data );
134 static oC_ErrorCode_t ConfigureHeap ( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context );
135 static oC_ErrorCode_t UnconfigureHeap ( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context );
136 static oC_ErrorCode_t ConfigureMemoryInLld ( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context );
137 static oC_ErrorCode_t UnconfigureMemoryInLld ( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context );
138 static oC_ErrorCode_t FinishMemoryInitializationInLld ( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context );
139 static oC_ErrorCode_t CopyChipInfo ( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context );
140 static oC_ErrorCode_t VerifyChipInfo ( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context );
141 static oC_ErrorCode_t VerifyNANDFlashChipParameters ( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context );
142 static oC_ErrorCode_t VerifyNORFlashChipParameters ( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context );
143 static oC_ErrorCode_t VerifySDRAMChipParameters ( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context );
144 static oC_ErrorCode_t VerifyPSRAMChipParameters ( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context );
145 static oC_ErrorCode_t InitializeChip ( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context );
146 
147 #undef _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________
148 
154 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
155 
156 //==========================================================================================================================================
167 //==========================================================================================================================================
168 oC_ErrorCode_t oC_FMC_TurnOn( void )
169 {
170  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
171 
172  if(oC_Module_TurnOffVerification(&errorCode , oC_Module_FMC))
173  {
174  errorCode = oC_FMC_LLD_TurnOnDriver();
175 
176  if(errorCode == oC_ErrorCode_ModuleIsTurnedOn)
177  {
178  errorCode = oC_ErrorCode_None;
179  }
180 
181  if(!oC_ErrorOccur(errorCode))
182  {
183  /* This must be always at the end of the function */
184  oC_Module_TurnOn(oC_Module_FMC);
185  errorCode = oC_ErrorCode_None;
186  }
187  }
188 
189  return errorCode;
190 }
191 
192 //==========================================================================================================================================
203 //==========================================================================================================================================
204 oC_ErrorCode_t oC_FMC_TurnOff( void )
205 {
206  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
207 
208  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_FMC))
209  {
210  /* This must be at the start of the function */
211  oC_Module_TurnOff(oC_Module_FMC);
212 
213  errorCode = oC_FMC_LLD_TurnOffDriver();
214 
215  if(errorCode == oC_ErrorCode_ModuleNotStartedYet)
216  {
217  errorCode = oC_ErrorCode_None;
218  }
219  }
220 
221  return errorCode;
222 }
223 
224 //==========================================================================================================================================
230 //==========================================================================================================================================
231 bool oC_FMC_IsTurnedOn( void )
232 {
233  return oC_Module_IsTurnedOn(oC_Module_FMC);
234 }
235 
236 //==========================================================================================================================================
249 //==========================================================================================================================================
250 oC_ErrorCode_t oC_FMC_Configure( const oC_FMC_Config_t * Config , oC_FMC_Context_t * outContext )
251 {
252  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
253 
254  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_FMC))
255  {
256  if(
257  ErrorCondition( isaddresscorrect(Config) , oC_ErrorCode_WrongConfigAddress ) &&
258  ErrorCondition( isram(outContext) , oC_ErrorCode_OutputAddressNotInRAM )
259  )
260  {
261  oC_FMC_Context_t context = Context_New(Config);
262 
263  if(ErrorCondition(context != NULL , oC_ErrorCode_AllocationError))
264  {
265  if(
266  oC_AssignErrorCode(&errorCode , CopyChipInfo(Config,context) ) &&
267  oC_AssignErrorCode(&errorCode , VerifyChipInfo(Config,context) ) &&
268  oC_AssignErrorCode(&errorCode , ConfigureMemoryInLld(Config,context)) &&
269  oC_AssignErrorCode(&errorCode , InitializeChip(Config,context) ) &&
270  oC_AssignErrorCode(&errorCode , ConfigureHeap(Config,context) )
271  )
272  {
273  *outContext = context;
274  errorCode = oC_ErrorCode_None;
275  }
276  else
277  {
278  oC_SaveIfErrorOccur("FMC:Configure - cannot unconfigure after failure", UnconfigureMemoryInLld(Config,context));
279  oC_SaveIfFalse("FMC:Configure - cannot delete context: " , Context_Delete(&context) , oC_ErrorCode_ReleaseError);
280  }
281  }
282  }
283  }
284 
285  return errorCode;
286 }
287 
288 //==========================================================================================================================================
301 //==========================================================================================================================================
302 oC_ErrorCode_t oC_FMC_Unconfigure( const oC_FMC_Config_t * Config , oC_FMC_Context_t * outContext )
303 {
304  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
305 
306  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_FMC))
307  {
308  if(
309  ErrorCondition(isaddresscorrect(Config) , oC_ErrorCode_WrongConfigAddress) &&
310  ErrorCondition(isram(outContext) , oC_ErrorCode_OutputAddressNotInRAM) &&
311  ErrorCondition(IsContextCorrect(*outContext) , oC_ErrorCode_ContextNotCorrect )
312  )
313  {
314  if(
315  oC_AssignErrorCode(&errorCode , UnconfigureHeap(Config,*outContext))
316  && oC_AssignErrorCode(&errorCode , UnconfigureMemoryInLld(Config,*outContext))
317  )
318  {
319  errorCode = Context_Delete(outContext);
320  }
321  }
322  }
323 
324  return errorCode;
325 }
326 
327 //==========================================================================================================================================
341 //==========================================================================================================================================
342 oC_ErrorCode_t oC_FMC_Ioctl( oC_FMC_Context_t Context , oC_Ioctl_Command_t Command , void * Data )
343 {
344  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
345 
346  if(
347  oC_Module_TurnOnVerification(&errorCode , oC_Module_FMC ) &&
348  ErrorCondition( IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect ) &&
349  ErrorCondition( oC_Ioctl_IsCorrectCommand(Command) , oC_ErrorCode_CommandNotCorrect )
350  )
351  {
352  switch(Command)
353  {
354  case oC_IoCtl_SpecialCommand_SetFileOffset:
355  Context->FileOffset = *((uint32_t*)(Data));
356  errorCode = oC_ErrorCode_None;
357  break;
358  //==============================================================================================================================
359  /*
360  * Not handled commands
361  */
362  //==============================================================================================================================
363  default:
364  errorCode = oC_ErrorCode_CommandNotHandled;
365  break;
366  }
367  }
368 
369  return errorCode;
370 }
371 
372 
373 //==========================================================================================================================================
388 //==========================================================================================================================================
389 oC_ErrorCode_t oC_FMC_Read( oC_FMC_Context_t Context , char * outBuffer , uint32_t Size , oC_IoFlags_t IoFlags )
390 {
391  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
392 
393  if(
394  oC_Module_TurnOnVerification(&errorCode , oC_Module_FMC) &&
395  ErrorCondition( IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect ) &&
396  ErrorCondition( isram(outBuffer) , oC_ErrorCode_OutputAddressNotInRAM ) &&
397  ErrorCondition( Size > 0 , oC_ErrorCode_SizeNotCorrect ) &&
398  ErrorCondition( Context->Protection & oC_FMC_Protection_AllowRead , oC_ErrorCode_ReadingNotPermitted )
399  )
400  {
401  errorCode = oC_ErrorCode_None;
402 
403  for(uint32_t index = 0; index < Size && !oC_ErrorOccur(errorCode) ; index++)
404  {
405  errorCode = ReadData(Context,&outBuffer[index]);
406  }
407  }
408 
409  return errorCode;
410 }
411 
412 //==========================================================================================================================================
427 //==========================================================================================================================================
428 oC_ErrorCode_t oC_FMC_Write( oC_FMC_Context_t Context , const char * Buffer , uint32_t Size , oC_IoFlags_t IoFlags )
429 {
430  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
431 
432  if(
433  oC_Module_TurnOnVerification(&errorCode , oC_Module_FMC) &&
434  ErrorCondition( IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect ) &&
435  ErrorCondition( isaddresscorrect(Buffer) , oC_ErrorCode_WrongAddress ) &&
436  ErrorCondition( Size > 0 , oC_ErrorCode_SizeNotCorrect ) &&
437  ErrorCondition( Context->Protection & oC_FMC_Protection_AllowWrite , oC_ErrorCode_WritingNotPermitted )
438  )
439  {
440  errorCode = oC_ErrorCode_None;
441 
442  for(uint32_t index = 0; index < Size && !oC_ErrorOccur(errorCode) ; index++)
443  {
444  errorCode = WriteData(Context,Buffer[index]);
445  }
446 
447  }
448 
449  return errorCode;
450 }
451 
452 //==========================================================================================================================================
467 //==========================================================================================================================================
468 oC_ErrorCode_t oC_FMC_SDRAM_SendCommand( oC_FMC_Context_t Context , oC_Time_t * Timeout , oC_FMC_SDRAM_Command_t Command , const oC_FMC_SDRAM_CommandData_t * Data )
469 {
470  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
471 
472  if(
473  oC_Module_TurnOnVerification(&errorCode , oC_Module_FMC)
474  && ErrorCondition( IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect )
475  && ErrorCondition( isaddresscorrect(Timeout) , oC_ErrorCode_WrongAddress )
476  )
477  {
478  errorCode = oC_FMC_LLD_SendSDRAMCommand(&Context->ConfigurationResult,Timeout,Command,Data);
479  }
480 
481  return errorCode;
482 }
483 
484 //==========================================================================================================================================
496 //==========================================================================================================================================
497 oC_ErrorCode_t oC_FMC_ReadDirectAddress( oC_FMC_Context_t Context , void ** outAddress , oC_MemorySize_t * outMemorySize )
498 {
499  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
500 
501  if(
502  oC_Module_TurnOnVerification(&errorCode , oC_Module_FMC)
503  && ErrorCondition( IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect )
504  && ErrorCondition( isram(outAddress) , oC_ErrorCode_OutputAddressNotInRAM )
505  && ErrorCondition( isram(outMemorySize) , oC_ErrorCode_OutputAddressNotInRAM )
506  && ErrorCondition( Context->ConfigurationResult.MemoryStart != NULL , oC_ErrorCode_DirectAccessNotPossible )
507  )
508  {
509  *outAddress = Context->ConfigurationResult.MemoryStart;
510  *outMemorySize = Context->ConfigurationResult.MemorySize;
511  errorCode = oC_ErrorCode_None;
512  }
513 
514  return errorCode;
515 }
516 
517 //==========================================================================================================================================
529 //==========================================================================================================================================
530 oC_ErrorCode_t oC_FMC_FinishInitialization( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context )
531 {
532  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
533 
534  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_FMC))
535  {
536  if(
537  ErrorCondition( IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect )
538  && ErrorCondition( isaddresscorrect(Config) , oC_ErrorCode_WrongConfigAddress )
539  )
540  {
541  errorCode = FinishMemoryInitializationInLld(Config,Context);
542  }
543  }
544 
545  return errorCode;
546 }
547 
548 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
549 
555 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
556 
557 //==========================================================================================================================================
561 //==========================================================================================================================================
562 static inline bool IsContextCorrect( oC_FMC_Context_t Context )
563 {
564  return isram(Context) && oC_CheckObjectControl(Context,oC_ObjectId_FmcContext,Context->ObjectControl);
565 }
566 
567 //==========================================================================================================================================
571 //==========================================================================================================================================
572 static inline bool IsMemoryTypeCorrect( oC_FMC_LLD_MemoryType_t MemoryType )
573 {
574  return (MemoryType == oC_FMC_LLD_MemoryType_NAND_Flash)
575  || (MemoryType == oC_FMC_LLD_MemoryType_NOR_Flash )
576  || (MemoryType == oC_FMC_LLD_MemoryType_PSRAM )
577  || (MemoryType == oC_FMC_LLD_MemoryType_SDRAM );
578 }
579 
580 //==========================================================================================================================================
584 //==========================================================================================================================================
586 {
587  oC_FMC_Context_t context = kmalloc(sizeof(struct Context_t) , &Allocator , AllocationFlags_ZeroFill);
588 
589  if(context)
590  {
591  context->ObjectControl = oC_CountObjectControl(context,oC_ObjectId_FmcContext);
592  context->FileOffset = 0;
593  context->Timeout = Config->MaximumTimeForConfiguration;
594  }
595 
596  return context;
597 }
598 //==========================================================================================================================================
602 //==========================================================================================================================================
603 static bool Context_Delete( oC_FMC_Context_t * outContext )
604 {
605  bool result = false;
606  oC_FMC_Context_t context = *outContext;
607 
608  context->ObjectControl = 0;
609 
610  if(kfree(context,AllocationFlags_CanWaitForever))
611  {
612  *outContext = NULL;
613  result = true;
614  }
615 
616  return result;
617 }
618 
619 //==========================================================================================================================================
623 //==========================================================================================================================================
624 static oC_ErrorCode_t ReadData( oC_FMC_Context_t Context , char * outData )
625 {
626  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
627 
628  if(Context->ConfigurationResult.DirectAccessProtection & oC_FMC_LLD_Protection_AllowRead)
629  {
630  *outData = Context->ConfigurationResult.MemoryStart[Context->FileOffset++];
631  errorCode = oC_ErrorCode_None;
632  }
633  else
634  {
635  errorCode = oC_ErrorCode_NotImplemented;
636  }
637 
638  return errorCode;
639 }
640 
641 //==========================================================================================================================================
645 //==========================================================================================================================================
646 static oC_ErrorCode_t WriteData( oC_FMC_Context_t Context , char Data )
647 {
648  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
649 
650  if(Context->ConfigurationResult.DirectAccessProtection & oC_FMC_LLD_Protection_AllowWrite)
651  {
652  Context->ConfigurationResult.MemoryStart[Context->FileOffset++] = Data;
653  errorCode = oC_ErrorCode_None;
654  }
655  else
656  {
657  errorCode = oC_ErrorCode_NotImplemented;
658  }
659 
660  return errorCode;
661 }
662 
663 //==========================================================================================================================================
667 //==========================================================================================================================================
668 static oC_ErrorCode_t ConfigureHeap( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context )
669 {
670  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
671 
672  if(
674  oC_Bits_AreBitsSetU32(Context->MemoryType , oC_FMC_LLD_MemoryType_RAM ) &&
675  oC_Bits_AreBitsSetU32(Context->ConfigurationResult.DirectAccessProtection , oC_FMC_Protection_AllowRead | oC_FMC_Protection_AllowWrite )
676  )
677  {
678  errorCode = oC_MemMan_ConfigureExternalHeapMap(Context->ConfigurationResult.MemoryStart,Context->ConfigurationResult.MemorySize);
679  if(!oC_ErrorOccur(errorCode))
680  {
681  Context->UsedAsHeap = true;
682  }
683  }
684  else
685  {
686  errorCode = oC_ErrorCode_None;
687  }
688 
689  return errorCode;
690 }
691 
692 //==========================================================================================================================================
696 //==========================================================================================================================================
697 static oC_ErrorCode_t UnconfigureHeap( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context )
698 {
699  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
700 
701  if(Context->UsedAsHeap == true)
702  {
704  }
705  else
706  {
707  errorCode = oC_ErrorCode_None;
708  }
709 
710  return errorCode;
711 }
712 
713 //==========================================================================================================================================
717 //==========================================================================================================================================
718 static oC_ErrorCode_t ConfigureMemoryInLld( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context )
719 {
720  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
721 
722  switch(Context->MemoryType)
723  {
724  case oC_FMC_LLD_MemoryType_NAND_Flash:
725  errorCode = oC_FMC_LLD_ConfigureNANDFlash(&Config->NANDFlash,&Context->ChipInfo.ChipParameters,&Context->ConfigurationResult);
726  break;
727  case oC_FMC_LLD_MemoryType_NOR_Flash:
728  errorCode = oC_FMC_LLD_ConfigureNORFlash(&Config->NORFlash,&Context->ChipInfo.ChipParameters,&Context->ConfigurationResult);
729  break;
730  case oC_FMC_LLD_MemoryType_SDRAM:
731  errorCode = oC_FMC_LLD_ConfigureSDRAM(&Config->SDRAM,&Context->ChipInfo.ChipParameters,&Context->ConfigurationResult);
732  break;
733  case oC_FMC_LLD_MemoryType_PSRAM:
734  errorCode = oC_FMC_LLD_ConfigurePSRAM(&Config->PSRAM,&Context->ChipInfo.ChipParameters,&Context->ConfigurationResult);
735  break;
736  default:
737  errorCode = oC_ErrorCode_MemoryTypeNotCorrect;
738  break;
739  }
740  return errorCode;
741 }
742 
743 //==========================================================================================================================================
747 //==========================================================================================================================================
748 static oC_ErrorCode_t UnconfigureMemoryInLld( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context )
749 {
750  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
751 
752  switch(Context->MemoryType)
753  {
754  case oC_FMC_LLD_MemoryType_NAND_Flash:
755  errorCode = oC_FMC_LLD_UnconfigureNANDFlash(&Config->NANDFlash,&Context->ChipInfo.ChipParameters,&Context->ConfigurationResult);
756  break;
757  case oC_FMC_LLD_MemoryType_NOR_Flash:
758  errorCode = oC_FMC_LLD_UnconfigureNORFlash(&Config->NORFlash,&Context->ChipInfo.ChipParameters,&Context->ConfigurationResult);
759  break;
760  case oC_FMC_LLD_MemoryType_SDRAM:
761  errorCode = oC_FMC_LLD_UnconfigureSDRAM(&Config->SDRAM,&Context->ChipInfo.ChipParameters,&Context->ConfigurationResult);
762  break;
763  case oC_FMC_LLD_MemoryType_PSRAM:
764  errorCode = oC_FMC_LLD_UnconfigurePSRAM(&Config->PSRAM,&Context->ChipInfo.ChipParameters,&Context->ConfigurationResult);
765  break;
766  default:
767  errorCode = oC_ErrorCode_MemoryTypeNotCorrect;
768  break;
769  }
770  return errorCode;
771 }
772 
773 //==========================================================================================================================================
777 //==========================================================================================================================================
778 static oC_ErrorCode_t FinishMemoryInitializationInLld( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context )
779 {
780  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
781 
782  switch(Context->MemoryType)
783  {
784  case oC_FMC_LLD_MemoryType_NAND_Flash:
785  errorCode = oC_FMC_LLD_FinishNANDFlashInitialization(&Config->NANDFlash,&Context->ChipInfo.ChipParameters,&Context->ConfigurationResult);
786  break;
787  case oC_FMC_LLD_MemoryType_NOR_Flash:
788  errorCode = oC_FMC_LLD_FinishNORFlashInitialization(&Config->NORFlash,&Context->ChipInfo.ChipParameters,&Context->ConfigurationResult);
789  break;
790  case oC_FMC_LLD_MemoryType_SDRAM:
791  errorCode = oC_FMC_LLD_FinishSDRAMInitialization(&Config->SDRAM,&Context->ChipInfo.ChipParameters,&Context->ConfigurationResult);
792  break;
793  case oC_FMC_LLD_MemoryType_PSRAM:
794  errorCode = oC_FMC_LLD_FinishPSRAMInitialization(&Config->PSRAM,&Context->ChipInfo.ChipParameters,&Context->ConfigurationResult);
795  break;
796  default:
797  errorCode = oC_ErrorCode_MemoryTypeNotCorrect;
798  break;
799  }
800  return errorCode;
801 }
802 
803 
804 //==========================================================================================================================================
808 //==========================================================================================================================================
809 static oC_ErrorCode_t CopyChipInfo( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context )
810 {
811  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
812 
813  if(isaddresscorrect(Config->ChipInfo))
814  {
815  memcpy(&Context->ChipInfo,Config->ChipInfo,sizeof(Context->ChipInfo));
816  Context->MemoryType = Config->ChipInfo->ChipParameters.MemoryType;
817  errorCode = oC_ErrorCode_None;
818  }
819  else
820  {
821  errorCode = oC_ErrorCode_ChipNotDefined;
822  }
823 
824  return errorCode;
825 }
826 
827 //==========================================================================================================================================
831 //==========================================================================================================================================
832 static oC_ErrorCode_t VerifyChipInfo( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context )
833 {
834  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
835 
836  if(
837  ErrorCondition(IsMemoryTypeCorrect(Context->ChipInfo.ChipParameters.MemoryType) , oC_ErrorCode_MemoryTypeNotCorrect )
838  && ErrorCondition(isaddresscorrect(Context->ChipInfo.InitializationFunction) , oC_ErrorCode_WrongAddress )
839  )
840  {
841  switch(Context->MemoryType)
842  {
843  case oC_FMC_LLD_MemoryType_NAND_Flash:
844  errorCode = VerifyNANDFlashChipParameters(Config,Context);
845  break;
846  case oC_FMC_LLD_MemoryType_NOR_Flash:
847  errorCode = VerifyNORFlashChipParameters(Config,Context);
848  break;
849  case oC_FMC_LLD_MemoryType_SDRAM:
850  errorCode = VerifySDRAMChipParameters(Config,Context);
851  break;
852  case oC_FMC_LLD_MemoryType_PSRAM:
853  errorCode = VerifyPSRAMChipParameters(Config,Context);
854  break;
855  default:
856  errorCode = oC_ErrorCode_MemoryTypeNotCorrect;
857  break;
858  }
859  }
860 
861  return errorCode;
862 }
863 
864 //==========================================================================================================================================
868 //==========================================================================================================================================
869 static oC_ErrorCode_t VerifyNANDFlashChipParameters( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context )
870 {
871  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
872 
873 
874 
875  return errorCode;
876 }
877 
878 //==========================================================================================================================================
882 //==========================================================================================================================================
883 static oC_ErrorCode_t VerifyNORFlashChipParameters( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context )
884 {
885  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
886 
887 
888 
889  return errorCode;
890 }
891 
892 //==========================================================================================================================================
898 //==========================================================================================================================================
899 static oC_ErrorCode_t VerifySDRAMChipParameters( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context )
900 {
901  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
902 
903  if(
904  ErrorCondition(Context->ChipInfo.ChipParameters.SDRAM.Size > 0 , oC_ErrorCode_SizeNotCorrect)
905  && ErrorCondition(Context->ChipInfo.ChipParameters.SDRAM.BankSize > 0 , oC_ErrorCode_SizeNotCorrect)
906  && ErrorCondition(Context->ChipInfo.ChipParameters.SDRAM.NumberOfBanks > 0 , oC_ErrorCode_NumberOfBanksNotCorrect)
907  )
908  {
909  errorCode = oC_ErrorCode_None;
910  }
911 
912  return errorCode;
913 }
914 
915 //==========================================================================================================================================
919 //==========================================================================================================================================
920 static oC_ErrorCode_t VerifyPSRAMChipParameters( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context )
921 {
922  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
923 
924 
925 
926  return errorCode;
927 }
928 
929 //==========================================================================================================================================
933 //==========================================================================================================================================
934 static oC_ErrorCode_t InitializeChip( const oC_FMC_Config_t * Config , oC_FMC_Context_t Context )
935 {
936  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
937 
938  if(ErrorCondition(isaddresscorrect(Config->ChipInfo),oC_ErrorCode_ChipNotDefined))
939  {
940  if(isaddresscorrect(Context->ChipInfo.InitializationFunction))
941  {
942  errorCode = Context->ChipInfo.InitializationFunction(Config,Context,&Context->Timeout);
943  }
944  else
945  {
946  errorCode = oC_ErrorCode_None;
947  }
948  }
949 
950  return errorCode;
951 }
952 
953 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
954 
955 #endif
static oC_ErrorCode_t VerifyNANDFlashChipParameters(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
verifies chip info structure for the NAND flash memory type
Definition: oc_fmc.c:869
static oC_ErrorCode_t VerifyNORFlashChipParameters(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
verifies chip info structure for the NOR Flash memory type
Definition: oc_fmc.c:883
Basic math operations.
static bool oC_Bits_AreBitsSetU32(uint32_t BitMask, uint32_t BitsToCheck)
checks if all bits in field are set
Definition: oc_bits.h:884
oC_ErrorCode_t oC_FMC_FinishInitialization(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
finishes initialization
Definition: oc_fmc.c:530
static oC_ErrorCode_t InitializeChip(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
calls initialization of the chip
Definition: oc_fmc.c:934
oC_FMC_SDRAM_Command_t
commands for SDRAM
Definition: oc_fmc.h:97
const oC_FMC_ChipInfo_t * ChipInfo
Pointer to the informations about the selected chip.
Definition: oc_fmc.h:179
static bool Context_Delete(oC_FMC_Context_t *outContext)
releases memory allocated for context
Definition: oc_fmc.c:603
const char * Name
Definition: oc_stdlib.h:161
The file with interface for FMC driver.
The file with interface for the GPIO driver.
identifier for allocations
Definition: oc_stdlib.h:159
oC_ErrorCode_t oC_MemMan_UnconfigureExternalHeapMap(void)
unconfigures external heap
Definition: oc_memman.c:1809
oC_ErrorCode_t oC_FMC_TurnOff(void)
Turns off the FMC driver.
Definition: oc_fmc.c:204
oC_FMC_LLD_NORFlash_Config_t NORFlash
NOR Flash configuration structure.
Definition: oc_fmc.h:186
oC_FMC_LLD_SDRAM_CommandData_t oC_FMC_SDRAM_CommandData_t
stores data for SDRAM commands
Definition: oc_fmc.h:121
The file contains definitions for the compiler, that helps to manage errors, etc. ...
static oC_ErrorCode_t UnconfigureHeap(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
unconfigures memory as heap
Definition: oc_fmc.c:697
oC_ErrorCode_t oC_FMC_Write(oC_FMC_Context_t Context, const char *Buffer, uint32_t Size, oC_IoFlags_t IoFlags)
write buffer to the driver
Definition: oc_fmc.c:428
static oC_ErrorCode_t UnconfigureMemoryInLld(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
unconfigures memory (calls a LLD function according to the memory type)
Definition: oc_fmc.c:748
static oC_ErrorCode_t VerifySDRAMChipParameters(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
verifies chip parameters structure for the SDRAM memory type
Definition: oc_fmc.c:899
static const oC_Allocator_t Allocator
Definition: oc_fmc.c:115
static oC_ErrorCode_t VerifyChipInfo(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
verify, that the given chip info is correct
Definition: oc_fmc.c:832
bool oC_FMC_IsTurnedOn(void)
checks if the driver is turned on
Definition: oc_fmc.c:231
static oC_ErrorCode_t FinishMemoryInitializationInLld(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
finishes memory initialization (calls a LLD function according to the memory type) ...
Definition: oc_fmc.c:778
Read operations are performed.
Definition: oc_fmc.h:68
The file with interface for the GPIO driver.
oC_ErrorCode_t oC_MemMan_ConfigureExternalHeapMap(void *StartAddress, oC_UInt_t Size)
prepares HeapMap stored in external RAM
Definition: oc_memman.c:1782
static oC_ErrorCode_t CopyChipInfo(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
searches for informations about chip
Definition: oc_fmc.c:809
oC_FMC_LLD_NANDFlash_Config_t NANDFlash
NAND Flash configuration structure.
Definition: oc_fmc.h:185
oC_ErrorCode_t oC_FMC_Configure(const oC_FMC_Config_t *Config, oC_FMC_Context_t *outContext)
configures FMC pins to work
Definition: oc_fmc.c:250
The file with interface for driver creating.
static oC_ErrorCode_t ConfigureMemoryInLld(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
configures memory (calls a LLD function according to the memory type)
Definition: oc_fmc.c:718
The file with LLD interface for the FMC driver.
oC_FMC_Protection_t
stores memory protection
Definition: oc_fmc.h:64
The file with interface for the module library.
oC_ErrorCode_t oC_FMC_SDRAM_SendCommand(oC_FMC_Context_t Context, oC_Time_t *Timeout, oC_FMC_SDRAM_Command_t Command, const oC_FMC_SDRAM_CommandData_t *Data)
sends command to SDRAM chips
Definition: oc_fmc.c:468
static bool oC_Module_IsTurnedOn(oC_Module_t Module)
checks if the module is turned on
Definition: oc_module.h:121
uint32_t oC_ObjectControl_t
stores object control value
Definition: oc_object.h:141
oC_FMC_LLD_ChipParameters_t ChipParameters
Chip parameters.
Definition: oc_fmc.h:160
oC_ErrorCode_t oC_FMC_TurnOn(void)
turns on the module
Definition: oc_fmc.c:168
static oC_ErrorCode_t ReadData(oC_FMC_Context_t Context, char *outData)
Reads one byte from the configured buffer.
Definition: oc_fmc.c:624
The file with interface for interrupt manager.
oC_ErrorCode_t oC_FMC_Read(oC_FMC_Context_t Context, char *outBuffer, uint32_t Size, oC_IoFlags_t IoFlags)
reads buffer from the driver
Definition: oc_fmc.c:389
static oC_ObjectControl_t oC_CountObjectControl(void *ObjectPointer, oC_ObjectId_t ObjectId)
counts object control for object
Definition: oc_object.h:168
static bool oC_CheckObjectControl(void *ObjectPointer, oC_ObjectId_t ObjectId, oC_ObjectControl_t ObjectControl)
checks if object control is correct
Definition: oc_object.h:203
static oC_ErrorCode_t VerifyPSRAMChipParameters(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
verifies chip info structure for the PSRAM memory type
Definition: oc_fmc.c:920
oC_FMC_InitializationFunction_t InitializationFunction
Function to call for initialize the chip.
Definition: oc_fmc.h:161
stores informations about chip
Definition: oc_fmc.h:158
static bool IsMemoryTypeCorrect(oC_FMC_LLD_MemoryType_t MemoryType)
returns true if memory type is correct
Definition: oc_fmc.c:572
static void oC_Module_TurnOn(oC_Module_t Module)
sets module as turned on
Definition: oc_module.h:170
oC_ObjectControl_t ObjectControl
Definition: oc_eth.c:100
static bool IsContextCorrect(oC_FMC_Context_t Context)
Checks if the context of the FMC driver is correct.
Definition: oc_fmc.c:562
stores ETH context
Definition: oc_eth.c:97
The file with memory manager interface.
Default option - if usage of heap is possible, then use it.
Definition: oc_fmc.h:83
oC_FMC_LLD_SDRAM_Config_t SDRAM
SDRAM configuration structure.
Definition: oc_fmc.h:183
static oC_ErrorCode_t WriteData(oC_FMC_Context_t Context, char Data)
Writes one byte to the configured buffer.
Definition: oc_fmc.c:646
static bool oC_Module_TurnOffVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned off
Definition: oc_module.h:155
Definition of the null pointer.
static bool oC_Module_TurnOnVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned on
Definition: oc_module.h:138
oC_ErrorCode_t oC_FMC_ReadDirectAddress(oC_FMC_Context_t Context, void **outAddress, oC_MemorySize_t *outMemorySize)
returns an address for direct access to the memory
Definition: oc_fmc.c:497
Write operations are performed.
Definition: oc_fmc.h:67
oC_FMC_HeapUsage_t HeapUsage
Use or not the configured memory as heap.
Definition: oc_fmc.h:178
FMC driver configuration structure.
Definition: oc_fmc.h:176
oC_FMC_LLD_PSRAM_Config_t PSRAM
PSRAM configuration structure.
Definition: oc_fmc.h:184
static oC_ErrorCode_t ConfigureHeap(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
configures memory as heap
Definition: oc_fmc.c:668
oC_ErrorCode_t oC_FMC_Unconfigure(const oC_FMC_Config_t *Config, oC_FMC_Context_t *outContext)
Unconfigures the driver.
Definition: oc_fmc.c:302
oC_ErrorCode_t oC_FMC_Ioctl(oC_FMC_Context_t Context, oC_Ioctl_Command_t Command, void *Data)
handles input/output driver commands
Definition: oc_fmc.c:342
static oC_FMC_Context_t Context_New(const oC_FMC_Config_t *Config)
allocates memory for new context
Definition: oc_fmc.c:585
oC_Time_t MaximumTimeForConfiguration
Maximum time for the memory configuration.
Definition: oc_fmc.h:180
#define NULL
pointer to a zero
Definition: oc_null.h:37
static void oC_Module_TurnOff(oC_Module_t Module)
sets module as turned off
Definition: oc_module.h:185