|
ChibiOS/HAL 9.0.0
|
HAL Generic Flash Driver Interface. More...
HAL Generic Flash Driver Interface.
The flash driver implements a state machine internally, not all the driver functionalities can be used in any moment, any transition not explicitly shown in the following diagram has to be considered an error and shall be captured by an assertion (if enabled).

Flash attributes | |
| #define | FLASH_ATTR_ERASED_IS_ONE 0x00000001U |
| Defines one as the erased bit state. | |
| #define | FLASH_ATTR_MEMORY_MAPPED 0x00000002U |
| The memory is accessible in a memory mapped mode. | |
| #define | FLASH_ATTR_REWRITABLE 0x00000004U |
| Programmed pages can be programmed again. | |
| #define | FLASH_ATTR_ECC_CAPABLE 0x00000008U |
| The memory is protected by an ECC mechanism. | |
| #define | FLASH_ATTR_ECC_ZERO_LINE_CAPABLE 0x00000010U |
| The device is able to overwrite zero to a line. | |
| #define | FLASH_ATTR_SUSPEND_ERASE_CAPABLE 0x00000020U |
| The device is able to suspend erase operations. | |
Macro Functions (BaseFlash) | |
| #define | getBaseFlash(ip) |
| Instance getter. | |
| #define | flashGetDescriptor(ip) |
| Gets the flash descriptor structure. | |
| #define | flashRead(ip, offset, n, rp) |
| Read operation. | |
| #define | flashProgram(ip, offset, n, pp) |
| Program operation. | |
| #define | flashStartEraseAll(ip) |
| Starts a whole-device erase operation. | |
| #define | flashStartEraseSector(ip, sector) |
| Starts an sector erase operation. | |
| #define | flashQueryErase(ip, msec) |
| Queries the driver for erase operation progress. | |
| #define | flashVerifyErase(ip, sector) |
| Returns the erase state of a sector. | |
| #define | flashAcquireExclusive(ip) |
| Acquires exclusive access to flash. | |
| #define | flashReleaseExclusive(ip) |
| Releases exclusive access to flash. | |
Data Structures | |
| struct | flash_sector_descriptor_t |
| Flash sector descriptor. More... | |
| struct | flash_descriptor_t |
| Type of a flash device descriptor. More... | |
| struct | BaseFlashVMT |
BaseFlash virtual methods table. More... | |
| struct | BaseFlash |
| Base flash class. More... | |
Macros | |
| #define | _base_flash_methods_alone |
BaseFlash specific methods. | |
| #define | _base_flash_methods |
BaseFlash specific methods with inherited ones. | |
| #define | _base_flash_data |
BaseFlash specific data. | |
Typedefs | |
| typedef uint32_t | flash_offset_t |
| Type of a flash offset. | |
| typedef uint32_t | flash_sector_t |
| Type of a flash sector number. | |
Enumerations | |
| enum | flash_state_t { FLASH_UNINIT = 0 , FLASH_STOP = 1 , FLASH_READY = 2 , FLASH_READ = 3 , FLASH_PGM = 4 , FLASH_ERASE = 5 } |
| Driver state machine possible states. More... | |
| enum | flash_error_t { FLASH_NO_ERROR = 0 , FLASH_BUSY_ERASING = 1 , FLASH_ERROR_READ = 2 , FLASH_ERROR_PROGRAM = 3 , FLASH_ERROR_ERASE = 4 , FLASH_ERROR_VERIFY = 5 , FLASH_ERROR_HW_FAILURE = 6 , FLASH_ERROR_UNIMPLEMENTED = 7 } |
| Type of a flash error code. More... | |
Functions | |
| flash_error_t | flashWaitErase (BaseFlash *devp) |
| Waits until the current erase operation is finished. | |
| flash_offset_t | flashGetSectorOffset (BaseFlash *devp, flash_sector_t sector) |
| Returns the offset of a sector. | |
| uint32_t | flashGetSectorSize (BaseFlash *devp, flash_sector_t sector) |
| Returns the size of a sector. | |
| flash_sector_t | flashGetOffsetSector (BaseFlash *devp, flash_offset_t offset) |
| Returns the sector of an offset. | |
| void * | flashGetOffsetAddress (BaseFlash *devp, flash_offset_t offset) |
| Get absolute address from offset. | |
| flash_offset_t | flashGetAddressOffset (BaseFlash *devp, void *addr) |
| Get offset from absolute address. | |
| #define FLASH_ATTR_ERASED_IS_ONE 0x00000001U |
Defines one as the erased bit state.
Definition at line 39 of file hal_flash.h.
Referenced by __mx25_objinit_impl(), and __n25q_objinit_impl().
| #define FLASH_ATTR_MEMORY_MAPPED 0x00000002U |
The memory is accessible in a memory mapped mode.
Definition at line 43 of file hal_flash.h.
| #define FLASH_ATTR_REWRITABLE 0x00000004U |
Programmed pages can be programmed again.
FLASH_ATTR_ECC_CAPABLE. Definition at line 48 of file hal_flash.h.
Referenced by __mx25_objinit_impl(), and __n25q_objinit_impl().
| #define FLASH_ATTR_ECC_CAPABLE 0x00000008U |
The memory is protected by an ECC mechanism.
Definition at line 58 of file hal_flash.h.
| #define FLASH_ATTR_ECC_ZERO_LINE_CAPABLE 0x00000010U |
The device is able to overwrite zero to a line.
FLASH_ATTR_ECC_CAPABLE must be specified. Definition at line 64 of file hal_flash.h.
| #define FLASH_ATTR_SUSPEND_ERASE_CAPABLE 0x00000020U |
The device is able to suspend erase operations.
Definition at line 68 of file hal_flash.h.
Referenced by __mx25_objinit_impl(), and __n25q_objinit_impl().
| #define _base_flash_methods_alone |
BaseFlash specific methods.
Definition at line 175 of file hal_flash.h.
| #define _base_flash_methods |
BaseFlash specific methods with inherited ones.
Definition at line 200 of file hal_flash.h.
| #define _base_flash_data |
BaseFlash specific data.
Definition at line 214 of file hal_flash.h.
| #define getBaseFlash | ( | ip | ) |
Instance getter.
This special method is used to get the instance of this class object from a derived class.
Definition at line 243 of file hal_flash.h.
| #define flashGetDescriptor | ( | ip | ) |
Gets the flash descriptor structure.
| [in] | ip | pointer to a BaseFlash or derived class |
Definition at line 253 of file hal_flash.h.
Referenced by flashGetAddressOffset(), flashGetOffsetAddress(), flashGetOffsetSector(), flashGetSectorOffset(), and flashGetSectorSize().
| #define flashRead | ( | ip, | |
| offset, | |||
| n, | |||
| rp ) |
Read operation.
| [in] | ip | pointer to a BaseFlash or derived class |
| [in] | offset | flash offset |
| [in] | n | number of bytes to be read |
| [out] | rp | pointer to the data buffer |
| FLASH_NO_ERROR | if there is no erase operation in progress. |
| FLASH_BUSY_ERASING | if there is an erase operation in progress. |
| FLASH_ERROR_READ | if the read operation failed. |
| FLASH_ERROR_HW_FAILURE | if access to the memory failed. |
Definition at line 271 of file hal_flash.h.
Referenced by mfs_flash_read().
| #define flashProgram | ( | ip, | |
| offset, | |||
| n, | |||
| pp ) |
Program operation.
| [in] | ip | pointer to a BaseFlash or derived class |
| [in] | offset | flash offset |
| [in] | n | number of bytes to be programmed |
| [in] | pp | pointer to the data buffer |
| FLASH_NO_ERROR | if there is no erase operation in progress. |
| FLASH_BUSY_ERASING | if there is an erase operation in progress. |
| FLASH_ERROR_PROGRAM | if the program operation failed. |
| FLASH_ERROR_HW_FAILURE | if access to the memory failed. |
Definition at line 289 of file hal_flash.h.
Referenced by mfs_flash_write().
| #define flashStartEraseAll | ( | ip | ) |
Starts a whole-device erase operation.
| [in] | ip | pointer to a BaseFlash or derived class |
| FLASH_NO_ERROR | if there is no erase operation in progress. |
| FLASH_BUSY_ERASING | if there is an erase operation in progress. |
| FLASH_ERROR_HW_FAILURE | if access to the memory failed. |
Definition at line 303 of file hal_flash.h.
| #define flashStartEraseSector | ( | ip, | |
| sector ) |
Starts an sector erase operation.
| [in] | ip | pointer to a BaseFlash or derived class |
| [in] | sector | sector to be erased |
| FLASH_NO_ERROR | if there is no erase operation in progress. |
| FLASH_BUSY_ERASING | if there is an erase operation in progress. |
| FLASH_ERROR_HW_FAILURE | if access to the memory failed. |
Definition at line 318 of file hal_flash.h.
Referenced by mfs_bank_erase().
| #define flashQueryErase | ( | ip, | |
| msec ) |
Queries the driver for erase operation progress.
| [in] | ip | pointer to a BaseFlash or derived class |
| [out] | msec | recommended time, in milliseconds, that should be spent before calling this function again, can be NULL |
| FLASH_NO_ERROR | if there is no erase operation in progress. |
| FLASH_BUSY_ERASING | if there is an erase operation in progress. |
| FLASH_ERROR_ERASE | if the erase operation failed. |
| FLASH_ERROR_HW_FAILURE | if access to the memory failed. |
Definition at line 336 of file hal_flash.h.
Referenced by flashWaitErase().
| #define flashVerifyErase | ( | ip, | |
| sector ) |
Returns the erase state of a sector.
| [in] | ip | pointer to a BaseFlash or derived class |
| [in] | sector | sector to be verified |
| FLASH_NO_ERROR | if the sector is erased. |
| FLASH_BUSY_ERASING | if there is an erase operation in progress. |
| FLASH_ERROR_VERIFY | if the verify operation failed. |
| FLASH_ERROR_HW_FAILURE | if access to the memory failed. |
Definition at line 352 of file hal_flash.h.
Referenced by mfs_bank_erase(), and mfs_bank_verify_erase().
| #define flashAcquireExclusive | ( | ip | ) |
Acquires exclusive access to flash.
| [in] | ip | pointer to a BaseFlash or derived class |
| FLASH_NO_ERROR | if the access is obtained. |
| FLASH_ERROR_UNIMPLEMENTED | if exclusive access not enabled |
Definition at line 364 of file hal_flash.h.
| #define flashReleaseExclusive | ( | ip | ) |
Releases exclusive access to flash.
| [in] | ip | pointer to a BaseFlash or derived class |
| FLASH_NO_ERROR | if the access is released. |
| FLASH_ERROR_UNIMPLEMENTED | if exclusive access not enabled |
Definition at line 376 of file hal_flash.h.
| typedef uint32_t flash_offset_t |
Type of a flash offset.
Definition at line 112 of file hal_flash.h.
| typedef uint32_t flash_sector_t |
Type of a flash sector number.
Definition at line 117 of file hal_flash.h.
| enum flash_state_t |
Driver state machine possible states.
| Enumerator | |
|---|---|
| FLASH_UNINIT | |
| FLASH_STOP | |
| FLASH_READY | |
| FLASH_READ | |
| FLASH_PGM | |
| FLASH_ERASE | |
Definition at line 86 of file hal_flash.h.
| enum flash_error_t |
Type of a flash error code.
| Enumerator | |
|---|---|
| FLASH_NO_ERROR | |
| FLASH_BUSY_ERASING | |
| FLASH_ERROR_READ | |
| FLASH_ERROR_PROGRAM | |
| FLASH_ERROR_ERASE | |
| FLASH_ERROR_VERIFY | |
| FLASH_ERROR_HW_FAILURE | |
| FLASH_ERROR_UNIMPLEMENTED | |
Definition at line 98 of file hal_flash.h.
| flash_error_t flashWaitErase | ( | BaseFlash * | devp | ) |
Waits until the current erase operation is finished.
| [in] | devp | pointer to a BaseFlash object |
| FLASH_NO_ERROR | if there is no erase operation in progress. |
| FLASH_ERROR_ERASE | if the erase operation failed. |
| FLASH_ERROR_HW_FAILURE | if access to the memory failed. |
Definition at line 61 of file hal_flash.c.
References FLASH_BUSY_ERASING, flashQueryErase, and osalThreadSleepMilliseconds.
Referenced by mfs_bank_erase().
| flash_offset_t flashGetSectorOffset | ( | BaseFlash * | devp, |
| flash_sector_t | sector ) |
Returns the offset of a sector.
| [in] | devp | pointer to a BaseFlash object |
| [in] | sector | flash sector number |
Definition at line 87 of file hal_flash.c.
References flashGetDescriptor, flash_sector_descriptor_t::offset, osalDbgAssert, flash_descriptor_t::sectors, and flash_descriptor_t::sectors_size.
Referenced by mfs_bank_write_header(), and mfs_flash_get_bank_offset().
| uint32_t flashGetSectorSize | ( | BaseFlash * | devp, |
| flash_sector_t | sector ) |
Returns the size of a sector.
| [in] | devp | pointer to a BaseFlash object |
| [in] | sector | flash sector number |
Definition at line 113 of file hal_flash.c.
References flashGetDescriptor, osalDbgAssert, flash_descriptor_t::sectors, flash_descriptor_t::sectors_size, and flash_sector_descriptor_t::size.
| flash_sector_t flashGetOffsetSector | ( | BaseFlash * | devp, |
| flash_offset_t | offset ) |
Returns the sector of an offset.
| [in] | devp | pointer to a BaseFlash object |
| [in] | offset | flash offset |
Definition at line 139 of file hal_flash.c.
References FALSE, flashGetDescriptor, flash_sector_descriptor_t::offset, osalDbgAssert, flash_descriptor_t::sectors, flash_descriptor_t::sectors_count, flash_descriptor_t::sectors_size, and flash_sector_descriptor_t::size.
| void * flashGetOffsetAddress | ( | BaseFlash * | devp, |
| flash_offset_t | offset ) |
Get absolute address from offset.
| [in] | devp | pointer to a BaseFlash object |
| [in] | offset | flash offset |
Definition at line 176 of file hal_flash.c.
References flash_descriptor_t::address, flashGetDescriptor, and osalDbgAssert.
| flash_offset_t flashGetAddressOffset | ( | BaseFlash * | devp, |
| void * | addr ) |
Get offset from absolute address.
| [in] | devp | pointer to a BaseFlash object |
| [in] | addr | pointer |
Definition at line 193 of file hal_flash.c.
References flash_descriptor_t::address, flashGetDescriptor, osalDbgAssert, and flash_descriptor_t::size.