• No results found

Using the CFI Flash Service

The CFI flash service implements basic flash operation primitives, such as erasing a device and erasing a sector or programming data to the flash device. For programming data, it does not perform a sector read,

superimpose, or program because there may be memory constraints. If you want to write at non-sector boundary offsets, you must read the affected sector, superimpose the overlapping data, and use the primitive to erase or program the data. The primitives also enable you to access information on sector regions for sector read facilitation.

LATTICEMICO RUN-TIME ENVIRONMENT : Run-Time Services

Program Data The LatticeMico32CFIFlashProgramData function, shown in Figure 80, enables you to program a chunk of data to the flash component, if supported by the flash configuration driver. If the flash configuration driver does not support the functionality, an appropriate error is returned, as shown in this section.

This function erases the affected sectors and programs the new data. It does not save data in those sectors that are only partially affected. These sectors are usually the first sector or the last sector for program operations that are not on sector boundaries. The function does not save data in these sectors because the driver would otherwise need a minimum of one sector’s worth of memory storage, which can range from a few bytes to many kilobytes. For partial sector programming operation, you must first read the affected sector, impose the new data on the read data, and use this data in the function call to program data.

The configuration driver may impose restrictions on the offset, the amount of bytes to program, or both. For example, a dual 16-bit flash configuration may require the byte offset to be aligned to a 32-bit word boundary and that the amount of data be a multiple of four bytes.

LATTICEMICO RUN-TIME ENVIRONMENT : Run-Time Services

Erase LatticeMico Flash Component The

LatticeMico32CFIFlashEraseDevice function, shown in Figure 81, enables you to erase the entire flash region, if the flash configuration is identified and it supports erasing the entire flash region.

Erase LatticeMico32 Flash Sector The LatticeMico32CFIFlashEraseBlock function, shown in Figure 82, enables you to erase the sectors containing the provided offset.

Write Data The functions shown in Figure 83 enable you to write data in well-known sizes to the supplied byte offset in the flash region. Depending on the flash configuration, not all functions may be supported and will return the appropriate error value. These write functions assume that the affected Figure 81: Erasing the LatticeMico Flash Component

LATTICEMICO RUN-TIME ENVIRONMENT : Run-Time Services

sectors have been erased before calling them, unlike the

LatticeMico32CFIFlashProgramData function call described earlier, which erases the affected sectors and writes the data.

For example, two 16-bit flash devices operating in 16-bit mode cannot support an 8-bit write primitive. To achieve an 8-bit write for such a configuration, the driver would have to read the affected 32-bit data that would contain just the 8-bit data and then would have to make a copy of the entire sector,

superimpose the 8-bit data, and then write the entire sector back. So not all configurations support the aforementioned data sizes. The configuration driver may impose restrictions on the byte offset alignment; for example, a 32-bit write may expect the byte offset to be aligned on a 32-bit boundary.

Write Block of Data The LatticeMico32CFIFlashWrite function, shown in Figure 84, enables you to write a block of data to a flash component. The configuration driver may or may not support this functionality, which results in an appropriate error code being returned. Also, the configuration driver may impose restrictions on the amount of bytes to program and the offset (that is, the byte offset) of where to program.

LATTICEMICO RUN-TIME ENVIRONMENT : Run-Time Services

For example, a two 16-bit flash device region may require the amount of data to be a multiple of four bytes. Also, it may impose a restriction that the byte offset be aligned on a 32-bit boundary.

LATTICEMICO RUN-TIME ENVIRONMENT : Run-Time Services

Obtaining Sector Information The LatticeMico32CFIFlashSectorInfo function, shown in Figure 85, enables you to obtain sector information. You can use this function to identify a sector and read its contents.

Flash Component Reset Some flash devices have a soft reset command that is used especially if there is an error during a programming operation or erase operation. You can use the LatticeMico32CFIFlashReset function, shown in Figure 86, to reset a flash component, if it is supported by the flash configuration driver.

Figure 85: Obtaining Sector Information

LATTICEMICO RUN-TIME ENVIRONMENT : Run-Time Services