3.3.3. flash — Flash memory

Source code: src/drivers/storage/flash.h, src/drivers/storage/flash.c

Test code: tst/drivers/hardware/storage/flash/main.c


Functions

int flash_module_init(void)

Initialize the flash module. This function must be called before calling any other function in this module.

The module will only be initialized once even if this function is called multiple times.

Return
zero(0) or negative error code.

int flash_init(struct flash_driver_t *self_p, struct flash_device_t *dev_p)

Initialize given driver object.

Return
zero(0) or negative error code.
Parameters
  • self_p: Driver object to initialize.
  • dev_p: Device to use.

ssize_t flash_read(struct flash_driver_t *self_p, void *dst_p, uintptr_t src, size_t size)

Read data from given flash memory.

Return
Number of read bytes or negative error code.
Parameters
  • self_p: Initialized driver object.
  • dst_p: Buffer to read into.
  • src: Address in flash memory to read from.
  • size: Number of bytes to receive.

ssize_t flash_write(struct flash_driver_t *self_p, uintptr_t dst, const void *src_p, size_t size)

Write data to given flash memory.

Return
Number of written bytes or negative error code.
Parameters
  • self_p: Initialized driver object.
  • dst: Address in flash memory to write to.
  • src_p: Buffer to write.
  • size: Number of bytes to write.

int flash_erase(struct flash_driver_t *self_p, uintptr_t addr, size_t size)

Erase all sectors part of given memory range.

Return
zero(0) or negative error code.
Parameters
  • self_p: Initialized driver object.
  • dst: Address in flash memory to erase from.
  • size: Number of bytes to erase.

Variables

struct flash_device_t flash_device[FLASH_DEVICE_MAX]