wm_flash.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**
  2. * @file wm_flash.h
  3. *
  4. * @brief flash Driver module
  5. *
  6. * @author dave
  7. *
  8. * Copyright (c) 2015 Winner Microelectronics Co., Ltd.
  9. */
  10. #ifndef WM_FLASH_H
  11. #define WM_FLASH_H
  12. #include "wm_type_def.h"
  13. #include "wm_osal.h"
  14. #define TLS_FLS_STATUS_OK (0)
  15. #define TLS_FLS_STATUS_EINVAL (1)
  16. #define TLS_FLS_STATUS_EBUSY (2)
  17. #define TLS_FLS_STATUS_EPERM (3)
  18. #define TLS_FLS_STATUS_ENOSUPPORT (4)
  19. #define TLS_FLS_STATUS_EEXIST (5)
  20. #define TLS_FLS_STATUS_ENOMEM (6)
  21. #define TLS_FLS_STATUS_EOVERFLOW (7)
  22. #define TLS_FLS_STATUS_ENODEV (8)
  23. #define TLS_FLS_STATUS_EDEV (9)
  24. #define TLS_FLS_STATUS_EIO (10)
  25. #define TLS_FLS_STATUS_ENODRV (11)
  26. #define TLS_FLS_PARAM_TYPE_ID (0)
  27. #define TLS_FLS_PARAM_TYPE_SIZE (1)
  28. #define TLS_FLS_PARAM_TYPE_PAGE_SIZE (2)
  29. #define TLS_FLS_PARAM_TYPE_PROG_SIZE (3)
  30. #define TLS_FLS_PARAM_TYPE_SECTOR_SIZE (4)
  31. #define TLS_FLS_FLAG_UNDER_PROTECT (1<<0)
  32. #define TLS_FLS_FLAG_FAST_READ (1<<1)
  33. #define TLS_FLS_FLAG_AAAI (1<<2)
  34. #define FLS_CMD_READ_DEV_ID (0x9F) // read device id //(0x9f)
  35. /**
  36. * @struct fls_list list
  37. */
  38. struct fls_list
  39. {
  40. struct fls_list *next;
  41. struct fls_list *prev;
  42. };
  43. /**
  44. * @struct tls_fls_drv flash driver
  45. */
  46. struct tls_fls_drv
  47. {
  48. struct fls_list drv_list;
  49. u32 id;
  50. u32 total_size;
  51. u32 page_size;
  52. u32 program_size;
  53. u32 sector_size;
  54. u32 clock;
  55. u8 mode;
  56. u8 cs_active;
  57. u8 flags;
  58. int (*read) (u32, u8 *, u32);
  59. int (*fast_read) (u32, u8 *, u32);
  60. int (*page_write) (u32, u8 *);
  61. int (*erase) (u32);
  62. int (*chip_erase) (void);
  63. int (*probe)(u32 id);
  64. void (*remove) (void);
  65. };
  66. /**
  67. * @struct tls_fls flash
  68. */
  69. struct tls_fls
  70. {
  71. struct fls_list fls_drvs;
  72. struct tls_fls_drv *current_drv;
  73. tls_os_sem_t *fls_lock;
  74. };
  75. /**
  76. * @defgroup Driver_APIs Driver APIs
  77. * @brief Driver APIs
  78. */
  79. /**
  80. * @addtogroup Driver_APIs
  81. * @{
  82. */
  83. /**
  84. * @defgroup SPIFLASH_Driver_APIs SPI FLASH Driver APIs
  85. * @brief SPI FLASH driver APIs
  86. */
  87. /**
  88. * @addtogroup SPIFLASH_Driver_APIs
  89. * @{
  90. */
  91. /**
  92. * @brief This function is used to initial flash module structer.
  93. *
  94. * @param[in] None
  95. *
  96. * @retval TLS_FLS_STATUS_OK if init sucsess
  97. * @retval TLS_FLS_STATUS_EBUSY already inited
  98. * @retval TLS_FLS_STATUS_ENOMEM memory error
  99. *
  100. * @note None
  101. */
  102. int tls_spifls_init(void);
  103. /**
  104. * @brief This function is used to read data from the flash.
  105. *
  106. * @param[in] addr Specifies the starting address to read from
  107. * @param[in] buf Pointer to a byte array that is to be written.
  108. * @param[in] len length to read.
  109. *
  110. * @retval TLS_FLS_STATUS_OK if read sucsess
  111. * @retval TLS_FLS_STATUS_EIO if read fail
  112. *
  113. * @note None
  114. */
  115. int tls_spifls_read(u32 addr, u8 * buf, u32 len);
  116. /**
  117. * @brief This function is used to write data into the flash.
  118. *
  119. * @param[in] addr Specifies the starting address to write to.
  120. * @param[in] buf Pointer to a byte array that holds the data to be written.
  121. * @param[in] len length to write.
  122. *
  123. * @retval TLS_FLS_STATUS_OK if write flash success
  124. * @retval TLS_FLS_STATUS_EPERM if flash struct point is null
  125. * @retval TLS_FLS_STATUS_ENODRV if flash driver is not installed
  126. * @retval TLS_FLS_STATUS_EINVAL if argument is invalid
  127. * @retval TLS_FLS_STATUS_EIO if io error
  128. *
  129. * @note None
  130. */
  131. int tls_spifls_write(u32 addr, u8 * buf, u32 len);
  132. /**
  133. * @}
  134. */
  135. /**
  136. * @}
  137. */
  138. #endif /* WM_FLASH_H */