spi_flash.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 LOG_FLASH_SECTOR_OFFSET 4
  12. #define SPI_FLASH_SECTOR_SIZE 4096
  13. #define SPI_FLASH_SECTORS_IN_BLOCK_NUMBER 16
  14. #define SPI_FLASH_BLOCK_SIZE 16
  15. #define SPI_FLASH_BLOCK_NUMBER 32
  16. //extern SemaphoreHandle_t spi_mutex;
  17. typedef struct {
  18. bool present;
  19. uint32_t sector_size;
  20. uint8_t sector_erase_op;
  21. uint16_t sector_count;
  22. } spi_flash_desc_t;
  23. bool spi_flash_init(void);
  24. ssize_t spi_flash_read(int addr, void *buf, size_t len, uint32_t timeout);
  25. ssize_t spi_flash_write(int addr, const void *buf, size_t len, uint32_t timeout);
  26. int spi_flash_erase_sector(int addr, uint32_t timeout);
  27. int spi_flash_chip_erase(uint32_t timeout);
  28. unsigned int spi_flash_get_sector_size(void);
  29. unsigned int spi_flash_get_sector_count(void);
  30. unsigned int spi_flash_get_total_size(void);
  31. bool spi_flash_is_init(void);
  32. bool spi_flash_test(void);
  33. void spi_flash_get_id(uint8_t *buf);
  34. extern spi_flash_desc_t spi_flash_desc;
  35. // -------------------------------------------------------------------------- //
  36. #endif /* SPI_FLASH_H */