spi_flash.h 1.4 KB

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