fal_def.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-05-17 armink the first version
  9. */
  10. #ifndef _FAL_DEF_H_
  11. #define _FAL_DEF_H_
  12. #include <rtthread.h>
  13. /* FAL flash and partition device name max length */
  14. #ifndef FAL_DEV_NAME_MAX
  15. #define FAL_DEV_NAME_MAX 24
  16. #endif
  17. #ifndef FAL_DEV_BLK_MAX
  18. #define FAL_DEV_BLK_MAX 6
  19. #endif
  20. struct flash_blk
  21. {
  22. rt_size_t size;
  23. rt_size_t count;
  24. };
  25. struct fal_flash_dev
  26. {
  27. char name[FAL_DEV_NAME_MAX];
  28. /* flash device start address and len */
  29. rt_uint32_t addr;
  30. rt_size_t len;
  31. /* the block size in the flash for erase minimum granularity */
  32. rt_size_t blk_size;
  33. struct
  34. {
  35. int (*init)(void);
  36. int (*read)(long offset, rt_uint8_t *buf, rt_size_t size);
  37. int (*write)(long offset, const rt_uint8_t *buf, rt_size_t size);
  38. int (*erase)(long offset, rt_size_t size);
  39. } ops;
  40. /* write minimum granularity, unit: bit.
  41. 1(nor flash)/ 8(stm32f2/f4)/ 32(stm32f1)/ 64(stm32l4)
  42. 0 will not take effect. */
  43. rt_size_t write_gran;
  44. struct flash_blk blocks[FAL_DEV_BLK_MAX];
  45. };
  46. typedef struct fal_flash_dev *fal_flash_dev_t;
  47. /**
  48. * FAL partition
  49. */
  50. struct fal_partition
  51. {
  52. rt_uint32_t magic_word;
  53. /* partition name */
  54. char name[FAL_DEV_NAME_MAX];
  55. /* flash device name for partition */
  56. char flash_name[FAL_DEV_NAME_MAX];
  57. /* partition offset address on flash device */
  58. long offset;
  59. rt_size_t len;
  60. rt_uint32_t reserved;
  61. };
  62. typedef struct fal_partition *fal_partition_t;
  63. #endif /* _FAL_DEF_H_ */