eCos Reference Manual
Prev | Chapter 28. The Version 2 eCos FLASH API | Next

# FLASH device API

This section describes the API between the FLASH IO library the FLASH device drivers.

## The FLASH device Structure

This structure keeps all the information about a single driver.

    struct cyg_flash_dev {
      const struct cyg_flash_dev_funs *funs;            // Function pointers
      cyg_uint32                      flags;            // Device characteristics
      cyg_flashaddr_t                 start;            // First address
      cyg_flashaddr_t                 end;              // Last address
      cyg_uint32                      num_block_infos;  // Number of entries
      const cyg_flash_block_info_t    *block_info;      // Info about one block size

      const void                      *priv;            // Devices private data

      // The following are only written to by the FLASH IO layer.
      cyg_flash_printf                *pf;              // Pointer to diagnostic printf
      bool                            init;             // Device has been initialised
    #ifdef CYGPKG_KERNEL
      cyg_mutex_t                     mutex;            // Mutex for thread safeness
    #endif
    #if (CYGHWR_IO_FLASH_DEVICE > 1)
      struct cyg_flash_dev            *next;            // Pointer to next device
    #endif
    };

    struct cyg_flash_dev_funs {
      int     (*flash_init) (struct cyg_flash_dev *dev);
      size_t  (*flash_query) (struct cyg_flash_dev *dev, void * data, size_t len);
      int     (*flash_erase_block) (struct cyg_flash_dev *dev, cyg_flashaddr_t block_base);
      int     (*flash_program) (struct cyg_flash_dev *dev, cyg_flashaddr_t base, const void* data, size_t len);
      int     (*flash_read) (struct cyg_flash_dev *dev, const cyg_flashaddr_t base, void* data, size_t len);
    #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
      int     (*flash_block_lock) (struct cyg_flash_dev *dev, const cyg_flashaddr_t block_base);
      int     (*flash_block_unlock) (struct cyg_flash_dev *dev, const cyg_flashaddr_t block_base);
    #endif
    };

The FLASH IO layer will only pass requests for operations on a single block.

Prev | Home | Next
The Version 2 eCos FLASH API | Up | The legacy Version 1 eCos FLASH API