123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539 |
- #ifndef ZEPHYR_INCLUDE_DRIVERS_FLASH_H_
- #define ZEPHYR_INCLUDE_DRIVERS_FLASH_H_
- #include <zephyr/types.h>
- #include <stddef.h>
- #include <sys/types.h>
- #include <device.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if defined(CONFIG_FLASH_PAGE_LAYOUT)
- struct flash_pages_layout {
- size_t pages_count;
- size_t pages_size;
- };
- #endif
- struct flash_parameters {
- const size_t write_block_size;
- uint8_t erase_value;
- };
- typedef int (*flash_api_read)(const struct device *dev, off_t offset,
- void *data,
- size_t len);
- typedef int (*flash_api_write)(const struct device *dev, off_t offset,
- const void *data, size_t len);
- typedef int (*flash_api_erase)(const struct device *dev, off_t offset,
- size_t size);
- typedef int (*flash_api_write_protection)(const struct device *dev,
- bool enable);
- typedef const struct flash_parameters* (*flash_api_get_parameters)(const struct device *dev);
- #if defined(CONFIG_FLASH_PAGE_LAYOUT)
- typedef void (*flash_api_pages_layout)(const struct device *dev,
- const struct flash_pages_layout **layout,
- size_t *layout_size);
- #endif
- typedef int (*flash_api_flush)(const struct device *dev, bool efficient);
- typedef int (*flash_api_sfdp_read)(const struct device *dev, off_t offset,
- void *data, size_t len);
- typedef int (*flash_api_read_jedec_id)(const struct device *dev, uint8_t *id);
- __subsystem struct flash_driver_api {
- flash_api_read read;
- flash_api_write write;
- flash_api_erase erase;
- flash_api_write_protection write_protection;
- flash_api_get_parameters get_parameters;
- #if defined(CONFIG_FLASH_PAGE_LAYOUT)
- flash_api_pages_layout page_layout;
- #endif
- #if defined(CONFIG_FLASH_JESD216_API)
- flash_api_sfdp_read sfdp_read;
- flash_api_read_jedec_id read_jedec_id;
- #endif
- flash_api_flush flush;
- };
- __syscall int flash_read(const struct device *dev, off_t offset, void *data,
- size_t len);
- static inline int z_impl_flash_read(const struct device *dev, off_t offset,
- void *data,
- size_t len)
- {
- const struct flash_driver_api *api =
- (const struct flash_driver_api *)dev->api;
- return api->read(dev, offset, data, len);
- }
- __syscall int flash_write(const struct device *dev, off_t offset,
- const void *data,
- size_t len);
- static inline int z_impl_flash_write(const struct device *dev, off_t offset,
- const void *data, size_t len)
- {
- const struct flash_driver_api *api =
- (const struct flash_driver_api *)dev->api;
- int rc;
-
-
-
-
-
-
-
- rc = api->write(dev, offset, data, len);
-
-
-
- return rc;
- }
- __syscall int flash_erase(const struct device *dev, off_t offset, size_t size);
- static inline int z_impl_flash_erase(const struct device *dev, off_t offset,
- size_t size)
- {
- const struct flash_driver_api *api =
- (const struct flash_driver_api *)dev->api;
- int rc;
-
-
-
-
-
-
-
- rc = api->erase(dev, offset, size);
-
-
-
- return rc;
- }
- __syscall int flash_write_protection_set(const struct device *dev,
- bool enable);
- static inline int z_impl_flash_write_protection_set(const struct device *dev,
- bool enable)
- {
- const struct flash_driver_api *api =
- (const struct flash_driver_api *)dev->api;
- if (api->write_protection != NULL) {
- api->write_protection(dev, enable);
- }
- return 0;
- }
- struct flash_pages_info {
- off_t start_offset;
- size_t size;
- uint32_t index;
- };
- #if defined(CONFIG_FLASH_PAGE_LAYOUT)
- __syscall int flash_get_page_info_by_offs(const struct device *dev,
- off_t offset,
- struct flash_pages_info *info);
- __syscall int flash_get_page_info_by_idx(const struct device *dev,
- uint32_t page_index,
- struct flash_pages_info *info);
- __syscall size_t flash_get_page_count(const struct device *dev);
- typedef bool (*flash_page_cb)(const struct flash_pages_info *info, void *data);
- void flash_page_foreach(const struct device *dev, flash_page_cb cb,
- void *data);
- #endif
- #if defined(CONFIG_FLASH_JESD216_API)
- __syscall int flash_sfdp_read(const struct device *dev, off_t offset,
- void *data, size_t len);
- static inline int z_impl_flash_sfdp_read(const struct device *dev,
- off_t offset,
- void *data, size_t len)
- {
- int rv = -ENOTSUP;
- const struct flash_driver_api *api =
- (const struct flash_driver_api *)dev->api;
- if (api->sfdp_read != NULL) {
- rv = api->sfdp_read(dev, offset, data, len);
- }
- return rv;
- }
- __syscall int flash_read_jedec_id(const struct device *dev, uint8_t *id);
- static inline int z_impl_flash_read_jedec_id(const struct device *dev,
- uint8_t *id)
- {
- int rv = -ENOTSUP;
- const struct flash_driver_api *api =
- (const struct flash_driver_api *)dev->api;
- if (api->read_jedec_id != NULL) {
- rv = api->read_jedec_id(dev, id);
- }
- return rv;
- }
- #endif
- __syscall int flash_flush(const struct device *dev, bool efficient);
- static inline int z_impl_flash_flush(const struct device *dev, bool efficient)
- {
- int rv = -ENOTSUP;
- const struct flash_driver_api *api =
- (const struct flash_driver_api *)dev->api;
- if (api->flush != NULL) {
- rv = api->flush(dev, efficient);
- }
- return rv;
- }
- __syscall size_t flash_get_write_block_size(const struct device *dev);
- static inline size_t z_impl_flash_get_write_block_size(const struct device *dev)
- {
- const struct flash_driver_api *api =
- (const struct flash_driver_api *)dev->api;
- return api->get_parameters(dev)->write_block_size;
- }
- __syscall const struct flash_parameters *flash_get_parameters(const struct device *dev);
- static inline const struct flash_parameters *z_impl_flash_get_parameters(const struct device *dev)
- {
- const struct flash_driver_api *api =
- (const struct flash_driver_api *)dev->api;
- return api->get_parameters(dev);
- }
- #ifdef __cplusplus
- }
- #endif
- #include <syscalls/flash.h>
- #endif
|