spi_flash.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef SPI_FLASH_H
  2. #define SPI_FLASH_H
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. #if defined ( __ICCARM__ )
  6. #define ssize_t long
  7. #else
  8. #include <unistd.h>
  9. #endif
  10. #include "FreeRTOS.h"
  11. #define SPI_FLASH_SECTOR_SIZE 4096
  12. #define SPI_FLASH_SECTORS_IN_BLOCK_NUMBER 16
  13. #define SPI_FLASH_BLOCK_SIZE 16
  14. #define SPI_FLASH_BLOCK_NUMBER 32
  15. //extern SemaphoreHandle_t spi_mutex;
  16. typedef struct {
  17. bool present;
  18. uint32_t sector_size;
  19. uint8_t sector_erase_op;
  20. uint16_t sector_count;
  21. } spi_flash_desc_t;
  22. bool spi_flash_init(void);
  23. ssize_t spi_flash_read(int addr, void *buf, size_t len, uint32_t timeout);
  24. ssize_t spi_flash_write(int addr, const void *buf, size_t len, uint32_t timeout);
  25. int spi_flash_erase_sector(int addr, uint32_t timeout);
  26. int spi_flash_chip_erase(uint32_t timeout);
  27. unsigned int spi_flash_get_sector_size(void);
  28. unsigned int spi_flash_get_sector_count(void);
  29. unsigned int spi_flash_get_total_size(void);
  30. bool spi_flash_is_init(void);
  31. bool spi_flash_test(void);
  32. void spi_flash_get_id(uint8_t *buf);
  33. // -------------------------------------------------------------------------- //
  34. #endif /* SPI_FLASH_H */