• No results found

Enhancing CFI Flash Service

For the current release of LatticeMico Mico System Builder (MSB), the only supported flash configuration consists of two 16-bit flash devices operating in 16-bit mode, providing an effective 32-bit data bus width. Also, the only supported flash command set is the basic AMD command set.

The steps required to enhance the LatticeMico32 CFI flash service for supporting a custom configuration are as follows:

 Enhance the CFI flash configuration identification algorithm.

 Write your configuration-specific routines, as required by LatticeMico32 CFI flash service.

 Register your configuration information.

Enhance the CFI Flash Configuration Algorithm You must first enhance the provided flash configuration identification algorithm by updating the following three specific functions:

 CFIIdentifyConfiguration function

The CFIIdentifyConfiguration function resides in CFICfgIdentifier.c. It is responsible for identifying the flashboard configuration, specifically the number of flash modules operating in parallel and the mode they are operating in, and must complete this information in the

FlashBoardCfgInfo_t structure referenced by the pointer argument to this function. The CFI functions assume that you are using the same flash component in parallel, that is, that the programming characteristics of the flash devices operating in parallel are identical.

LATTICEMICO RUN-TIME ENVIRONMENT : Run-Time Services

The CFIIdentifyConfiguration function is shown in Figure 87.

The FlashBoardCfgInfo_t structure is shown in Figure 88.

In the FlashBoardCfgInfo_t structure, the first parallels element identifies the total flash devices operating in parallel. The second element, mode, identifies the mode (8, 16, 32) in which the devices are operating. This board configuration information is used to select the appropriate configuration functions, as described in subsequent sections.  GetCFICfgAddressMultiplier

The GetCFICfgAddressMultiplier function resides in CFICfgIdentifier.c. It returns the address multiplier that obtains the physical address offsets for the CFI tables when the CFI device offsets specified by the CFI

specification are multiplied.

For example, for two 16-bit flash devices operating in 16-bit mode, the CFI address multiplier is four; that is, the standard CFI address offsets must be multiplied by four to compensate for the board configuration and flash operational mode. You must use the BoardInfo parameter to identify the board configuration and provide the appropriate address multiplier as the return value.

The GetCFICfgAddressMultiplier function is shown in Figure 89:  ValidateCFIBoardCfg

The ValidateCFIBoardCfg function resides in CFICfgIdentifier.c. It is used by the CFI routines to avoid using invalid board information.

The ValidateCFIBoardCfg function is shown in Figure 90. Figure 87: CFIIdentifyConfiguration Function

Figure 88: FlashBoardCfgInfo_t Structure typedef struct st_FlashBoardCfgInfo {

unsigned int parallels; /* total flash devices sharing address bus */

unsigned int mode; /* 8-bit mode, 16-bit mode, etc. */

LATTICEMICO RUN-TIME ENVIRONMENT : Run-Time Services

Implement Configuration-Specific Routines The LatticeMico32 CFI flash service relies on the configuration-specific function implementations shown in Table 9:

Figure 89: GetCFICfgAddressMultiplier Function

Figure 90: ValidateCFIBoardCfg Function

Table 9: Functions for the CFI Flash Service

Function Description

ProgramData Erases appropriate sectors and writes bulk data

SectorInfo Retrieves sector-offset and sector-size that contains a specified offset

WriteData Writes bulk-data (assumes affected sectors are erased)

LATTICEMICO RUN-TIME ENVIRONMENT : Run-Time Services

The prototypes for the expected functionalities are defined in the st_FlashCfgFnTbl structure in the LatticeMico32CFI.h header file. This structure is the flash configuration function table.

These function implementations must return 0 if the operation is successfully completed. If the operation is not successfully completed, they must return a non-zero value. You must allocate a static instance of this flash configuration function table structure and fill in the function pointers to the corresponding function implementation. You can set the function pointers of the structure element to zero (null) if your configuration does not need a corresponding functional implementation. This static instance is used in the next step as part of registering your configuration functions.

EraseChip Erases entire flash region

EraseSector Erases sector containing a given offset

FlashReset Resets the flash parts in a flash region

FlashInit Initializes flash parts in a flash region

Table 9: Functions for the CFI Flash Service (Continued)

Note

You can use AmdSCS_2_16_16.c and AmdSCS_2_16_16.h as a reference for implementing your configuration-specific routines. These files implement a 2 x 16 x 16 flash configuration, that is, two 16-bit flash devices operating in 16-bit mode, using the AMD command set. The routines in this file have been tested on Macronix

29LV128MBT flash device configuration. These files are located in asram_top\drivers\device folder in your LatticeMico components repository.

LATTICEMICO RUN-TIME ENVIRONMENT : Run-Time Services

These function prototypes take the CFI flash device context structure as an argument. This structure is shown in Figure 92.

Your function implementation does not need to populate information within this structure, because it is filled in by the LatticeMico32 CFI flash service. The two important elements of this structure are as follows:

 CFIInfo_t CFIInfo

This element is the CFI information structure as defined in the

CFIRoutines.h header file and contains CFI information for the identified flash part, such as timeout-values for writing and erasing and sector layout information that you can use as part of your function

implementation.  void *cfgFnTbl

This element is a pointer to your FlashCfgFnTbl_t structure, which you provide as part of registering your configuration’s functional routines. Register the Configuration Function Table Once you have implemented the configuration routines, you must register this configuration information with the LatticeMico32 CFI flash service. This registration must occur before you use any of the LatticeMico32 CFI flash service APIs for writing or erasing the flash device. Registration allows the LatticeMico32 CFI flash service to refer to the functions provided in the function table for flash operations once the flash configuration has been identified.

There are two ways to register:

 Modify the InitializeCFIConfigurations function located in the

CFIFlashConfigurations.c source file to register your function table using the LatticeMico32RegisterFlashCfg function.

 Call the LatticeMico32RegisterFlashCfg function from your application before calling any of the LatticeMico32 CFI flash service APIs for writing or erasing the flash device.

LATTICEMICO RUN-TIME ENVIRONMENT : Run-Time Services

The LatticeMico32RegisterFlashCfg function is shown in Figure 93.

This function takes a single parameter that is a pointer to a

FlashConfiguration_st structure, shown in Figure 94. You must allocate a static instance of this structure and provide its pointer as part of registration.

This structure has three elements:

 VendorCSId – You must fill in this structure element with the value corresponding to the supported CFI flash command-set identification.  BoardInfo – This is a pointer to a static allocation of the

FlashBoardCfgInfo_t structure described earlier. You must fill in the elements of this structure with the expected flash layout information (number of flash devices in parallel and operating mode).

 cfgFnTbl – This is a pointer to a static allocation of the FlashCfgFnTbl_t structure that you created in the previous step. This structure contains pointers to your flash configuration’s function implementation.

The LatticeMico32 CFI flash service uses the command-set identification and the board information that you provided to register your flash configuration’s functional implementation to determine if the CFI flash device that it finds has a corresponding functional implementation. Then it fills this information in the CFI flash device context structure. This information is filled in the first time that an application calls a LatticeMico32 CFI flash-service API function. If a Figure 93: LatticeMico32RegisterFlashCfg Function

/*

* This function registers a flash configuration with

* LatticeMico32 CFI Flash Service. This function must be called * prior to performing any of the LatticeMico32 CFI Flash

* Service API (write/erase/program). *

* Arguments:

* FlashConfiguration_st * pCfg: pointer to a valid flash * configuration information structure. This structure must * not be modified once registered.

*

* Return Values:

* unsigned int 0: If configuration was successfully * registered.

*/

unsigned int LatticeMico32RegisterFlashCfg (FlashConfiguration_st *pCfg);

LATTICEMICO RUN-TIME ENVIRONMENT : Run-Time Services

configuration function table that matches the command-set identification and the flash layout information is not found, the LatticeMico32 CFI flash APIs return failure codes, as described in “CFI Flash Device Service” on page 105. The LatticeMico32 CFI flash service APIs invoke the functions pointed to by the flash configuration function table contained in the CFI flash device context to perform write, erase, and program operations on the flash device.