41 #ifdef oC_FMC_LLD_AVAILABLE 48 #define _________________________________________DRIVER_DEFINITIONS_SECTION_________________________________________________________________ 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 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 69 #undef _________________________________________DRIVER_DEFINITIONS_SECTION_________________________________________________________________ 79 #define _________________________________________TYPES_SECTION______________________________________________________________________________ 92 oC_FMC_LLD_Result_t ConfigurationResult;
95 oC_FMC_LLD_MemoryType_t MemoryType;
101 #undef _________________________________________TYPES_SECTION______________________________________________________________________________ 108 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________ 119 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________ 126 #define _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________ 147 #undef _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________ 154 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 170 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
174 errorCode = oC_FMC_LLD_TurnOnDriver();
176 if(errorCode == oC_ErrorCode_ModuleIsTurnedOn)
178 errorCode = oC_ErrorCode_None;
181 if(!oC_ErrorOccur(errorCode))
185 errorCode = oC_ErrorCode_None;
206 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
213 errorCode = oC_FMC_LLD_TurnOffDriver();
215 if(errorCode == oC_ErrorCode_ModuleNotStartedYet)
217 errorCode = oC_ErrorCode_None;
252 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
257 ErrorCondition( isaddresscorrect(Config) , oC_ErrorCode_WrongConfigAddress ) &&
258 ErrorCondition( isram(outContext) , oC_ErrorCode_OutputAddressNotInRAM )
263 if(ErrorCondition(context !=
NULL , oC_ErrorCode_AllocationError))
266 oC_AssignErrorCode(&errorCode ,
CopyChipInfo(Config,context) ) &&
267 oC_AssignErrorCode(&errorCode ,
VerifyChipInfo(Config,context) ) &&
269 oC_AssignErrorCode(&errorCode ,
InitializeChip(Config,context) ) &&
270 oC_AssignErrorCode(&errorCode ,
ConfigureHeap(Config,context) )
273 *outContext = context;
274 errorCode = oC_ErrorCode_None;
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);
304 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
309 ErrorCondition(isaddresscorrect(Config) , oC_ErrorCode_WrongConfigAddress) &&
310 ErrorCondition(isram(outContext) , oC_ErrorCode_OutputAddressNotInRAM) &&
311 ErrorCondition(
IsContextCorrect(*outContext) , oC_ErrorCode_ContextNotCorrect )
344 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
348 ErrorCondition(
IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect ) &&
349 ErrorCondition( oC_Ioctl_IsCorrectCommand(Command) , oC_ErrorCode_CommandNotCorrect )
354 case oC_IoCtl_SpecialCommand_SetFileOffset:
355 Context->FileOffset = *((uint32_t*)(Data));
356 errorCode = oC_ErrorCode_None;
364 errorCode = oC_ErrorCode_CommandNotHandled;
391 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
395 ErrorCondition(
IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect ) &&
396 ErrorCondition( isram(outBuffer) , oC_ErrorCode_OutputAddressNotInRAM ) &&
397 ErrorCondition( Size > 0 , oC_ErrorCode_SizeNotCorrect ) &&
401 errorCode = oC_ErrorCode_None;
403 for(uint32_t index = 0; index < Size && !oC_ErrorOccur(errorCode) ; index++)
405 errorCode =
ReadData(Context,&outBuffer[index]);
430 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
434 ErrorCondition(
IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect ) &&
435 ErrorCondition( isaddresscorrect(Buffer) , oC_ErrorCode_WrongAddress ) &&
436 ErrorCondition( Size > 0 , oC_ErrorCode_SizeNotCorrect ) &&
440 errorCode = oC_ErrorCode_None;
442 for(uint32_t index = 0; index < Size && !oC_ErrorOccur(errorCode) ; index++)
444 errorCode =
WriteData(Context,Buffer[index]);
470 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
474 && ErrorCondition(
IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect )
475 && ErrorCondition( isaddresscorrect(Timeout) , oC_ErrorCode_WrongAddress )
478 errorCode = oC_FMC_LLD_SendSDRAMCommand(&Context->ConfigurationResult,Timeout,Command,Data);
499 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
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 )
509 *outAddress = Context->ConfigurationResult.MemoryStart;
510 *outMemorySize = Context->ConfigurationResult.MemorySize;
511 errorCode = oC_ErrorCode_None;
532 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
537 ErrorCondition(
IsContextCorrect(Context) , oC_ErrorCode_ContextNotCorrect )
538 && ErrorCondition( isaddresscorrect(Config) , oC_ErrorCode_WrongConfigAddress )
548 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 555 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 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 );
592 context->FileOffset = 0;
610 if(kfree(context,AllocationFlags_CanWaitForever))
626 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
628 if(Context->ConfigurationResult.DirectAccessProtection & oC_FMC_LLD_Protection_AllowRead)
630 *outData = Context->ConfigurationResult.MemoryStart[Context->FileOffset++];
631 errorCode = oC_ErrorCode_None;
635 errorCode = oC_ErrorCode_NotImplemented;
648 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
650 if(Context->ConfigurationResult.DirectAccessProtection & oC_FMC_LLD_Protection_AllowWrite)
652 Context->ConfigurationResult.MemoryStart[Context->FileOffset++] = Data;
653 errorCode = oC_ErrorCode_None;
657 errorCode = oC_ErrorCode_NotImplemented;
670 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
679 if(!oC_ErrorOccur(errorCode))
681 Context->UsedAsHeap =
true;
686 errorCode = oC_ErrorCode_None;
699 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
701 if(Context->UsedAsHeap ==
true)
707 errorCode = oC_ErrorCode_None;
720 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
722 switch(Context->MemoryType)
724 case oC_FMC_LLD_MemoryType_NAND_Flash:
725 errorCode = oC_FMC_LLD_ConfigureNANDFlash(&Config->
NANDFlash,&Context->ChipInfo.
ChipParameters,&Context->ConfigurationResult);
727 case oC_FMC_LLD_MemoryType_NOR_Flash:
728 errorCode = oC_FMC_LLD_ConfigureNORFlash(&Config->
NORFlash,&Context->ChipInfo.
ChipParameters,&Context->ConfigurationResult);
730 case oC_FMC_LLD_MemoryType_SDRAM:
731 errorCode = oC_FMC_LLD_ConfigureSDRAM(&Config->
SDRAM,&Context->ChipInfo.
ChipParameters,&Context->ConfigurationResult);
733 case oC_FMC_LLD_MemoryType_PSRAM:
734 errorCode = oC_FMC_LLD_ConfigurePSRAM(&Config->
PSRAM,&Context->ChipInfo.
ChipParameters,&Context->ConfigurationResult);
737 errorCode = oC_ErrorCode_MemoryTypeNotCorrect;
750 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
752 switch(Context->MemoryType)
754 case oC_FMC_LLD_MemoryType_NAND_Flash:
755 errorCode = oC_FMC_LLD_UnconfigureNANDFlash(&Config->
NANDFlash,&Context->ChipInfo.
ChipParameters,&Context->ConfigurationResult);
757 case oC_FMC_LLD_MemoryType_NOR_Flash:
758 errorCode = oC_FMC_LLD_UnconfigureNORFlash(&Config->
NORFlash,&Context->ChipInfo.
ChipParameters,&Context->ConfigurationResult);
760 case oC_FMC_LLD_MemoryType_SDRAM:
761 errorCode = oC_FMC_LLD_UnconfigureSDRAM(&Config->
SDRAM,&Context->ChipInfo.
ChipParameters,&Context->ConfigurationResult);
763 case oC_FMC_LLD_MemoryType_PSRAM:
764 errorCode = oC_FMC_LLD_UnconfigurePSRAM(&Config->
PSRAM,&Context->ChipInfo.
ChipParameters,&Context->ConfigurationResult);
767 errorCode = oC_ErrorCode_MemoryTypeNotCorrect;
780 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
782 switch(Context->MemoryType)
784 case oC_FMC_LLD_MemoryType_NAND_Flash:
785 errorCode = oC_FMC_LLD_FinishNANDFlashInitialization(&Config->
NANDFlash,&Context->ChipInfo.
ChipParameters,&Context->ConfigurationResult);
787 case oC_FMC_LLD_MemoryType_NOR_Flash:
788 errorCode = oC_FMC_LLD_FinishNORFlashInitialization(&Config->
NORFlash,&Context->ChipInfo.
ChipParameters,&Context->ConfigurationResult);
790 case oC_FMC_LLD_MemoryType_SDRAM:
791 errorCode = oC_FMC_LLD_FinishSDRAMInitialization(&Config->
SDRAM,&Context->ChipInfo.
ChipParameters,&Context->ConfigurationResult);
793 case oC_FMC_LLD_MemoryType_PSRAM:
794 errorCode = oC_FMC_LLD_FinishPSRAMInitialization(&Config->
PSRAM,&Context->ChipInfo.
ChipParameters,&Context->ConfigurationResult);
797 errorCode = oC_ErrorCode_MemoryTypeNotCorrect;
811 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
813 if(isaddresscorrect(Config->
ChipInfo))
815 memcpy(&Context->ChipInfo,Config->
ChipInfo,
sizeof(Context->ChipInfo));
817 errorCode = oC_ErrorCode_None;
821 errorCode = oC_ErrorCode_ChipNotDefined;
834 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
838 && ErrorCondition(isaddresscorrect(Context->ChipInfo.
InitializationFunction) , oC_ErrorCode_WrongAddress )
841 switch(Context->MemoryType)
843 case oC_FMC_LLD_MemoryType_NAND_Flash:
846 case oC_FMC_LLD_MemoryType_NOR_Flash:
849 case oC_FMC_LLD_MemoryType_SDRAM:
852 case oC_FMC_LLD_MemoryType_PSRAM:
856 errorCode = oC_ErrorCode_MemoryTypeNotCorrect;
871 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
885 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
901 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
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)
909 errorCode = oC_ErrorCode_None;
922 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
936 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
938 if(ErrorCondition(isaddresscorrect(Config->
ChipInfo),oC_ErrorCode_ChipNotDefined))
946 errorCode = oC_ErrorCode_None;
953 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 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
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
static bool oC_Bits_AreBitsSetU32(uint32_t BitMask, uint32_t BitsToCheck)
checks if all bits in field are set
oC_ErrorCode_t oC_FMC_FinishInitialization(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
finishes initialization
static oC_ErrorCode_t InitializeChip(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
calls initialization of the chip
oC_FMC_SDRAM_Command_t
commands for SDRAM
const oC_FMC_ChipInfo_t * ChipInfo
Pointer to the informations about the selected chip.
static bool Context_Delete(oC_FMC_Context_t *outContext)
releases memory allocated for context
The file with interface for FMC driver.
The file with interface for the GPIO driver.
identifier for allocations
oC_ErrorCode_t oC_MemMan_UnconfigureExternalHeapMap(void)
unconfigures external heap
oC_ErrorCode_t oC_FMC_TurnOff(void)
Turns off the FMC driver.
oC_FMC_LLD_NORFlash_Config_t NORFlash
NOR Flash configuration structure.
oC_FMC_LLD_SDRAM_CommandData_t oC_FMC_SDRAM_CommandData_t
stores data for SDRAM commands
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
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
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)
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
static const oC_Allocator_t Allocator
static oC_ErrorCode_t VerifyChipInfo(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
verify, that the given chip info is correct
bool oC_FMC_IsTurnedOn(void)
checks if the driver is turned on
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) ...
Read operations are performed.
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
static oC_ErrorCode_t CopyChipInfo(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
searches for informations about chip
oC_FMC_LLD_NANDFlash_Config_t NANDFlash
NAND Flash configuration structure.
oC_ErrorCode_t oC_FMC_Configure(const oC_FMC_Config_t *Config, oC_FMC_Context_t *outContext)
configures FMC pins to work
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)
The file with LLD interface for the FMC driver.
oC_FMC_Protection_t
stores memory protection
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
static bool oC_Module_IsTurnedOn(oC_Module_t Module)
checks if the module is turned on
uint32_t oC_ObjectControl_t
stores object control value
oC_FMC_LLD_ChipParameters_t ChipParameters
Chip parameters.
oC_ErrorCode_t oC_FMC_TurnOn(void)
turns on the module
static oC_ErrorCode_t ReadData(oC_FMC_Context_t Context, char *outData)
Reads one byte from the configured buffer.
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
static oC_ObjectControl_t oC_CountObjectControl(void *ObjectPointer, oC_ObjectId_t ObjectId)
counts object control for object
static bool oC_CheckObjectControl(void *ObjectPointer, oC_ObjectId_t ObjectId, oC_ObjectControl_t ObjectControl)
checks if object control is correct
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
oC_FMC_InitializationFunction_t InitializationFunction
Function to call for initialize the chip.
stores informations about chip
static bool IsMemoryTypeCorrect(oC_FMC_LLD_MemoryType_t MemoryType)
returns true if memory type is correct
static void oC_Module_TurnOn(oC_Module_t Module)
sets module as turned on
oC_ObjectControl_t ObjectControl
static bool IsContextCorrect(oC_FMC_Context_t Context)
Checks if the context of the FMC driver is correct.
The file with memory manager interface.
Default option - if usage of heap is possible, then use it.
oC_FMC_LLD_SDRAM_Config_t SDRAM
SDRAM configuration structure.
static oC_ErrorCode_t WriteData(oC_FMC_Context_t Context, char Data)
Writes one byte to the configured buffer.
static bool oC_Module_TurnOffVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned off
Definition of the null pointer.
static bool oC_Module_TurnOnVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned on
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
Write operations are performed.
oC_FMC_HeapUsage_t HeapUsage
Use or not the configured memory as heap.
FMC driver configuration structure.
oC_FMC_LLD_PSRAM_Config_t PSRAM
PSRAM configuration structure.
static oC_ErrorCode_t ConfigureHeap(const oC_FMC_Config_t *Config, oC_FMC_Context_t Context)
configures memory as heap
oC_ErrorCode_t oC_FMC_Unconfigure(const oC_FMC_Config_t *Config, oC_FMC_Context_t *outContext)
Unconfigures the driver.
oC_ErrorCode_t oC_FMC_Ioctl(oC_FMC_Context_t Context, oC_Ioctl_Command_t Command, void *Data)
handles input/output driver commands
static oC_FMC_Context_t Context_New(const oC_FMC_Config_t *Config)
allocates memory for new context
oC_Time_t MaximumTimeForConfiguration
Maximum time for the memory configuration.
#define NULL
pointer to a zero
static void oC_Module_TurnOff(oC_Module_t Module)
sets module as turned off