12345678910111213141516171819202122232425262728293031323334353637383940 |
- #ifndef SPI_FLASH_H
- #define SPI_FLASH_H
- #include <stdint.h>
- #include <stdbool.h>
- #include <stdlib.h>
- #include <string.h>
- #ifdef PRINTF_STDLIB
- #include <stdio.h>
- #endif
- #ifdef PRINTF_CUSTOM
- #include "tinystdio.h"
- #endif
- #define SPI_FLASH_SECTOR_SIZE 4096
- #define SPI_FLASH_SECTORS_IN_BLOCK_NUMBER 16
- #define SPI_FLASH_BLOCK_SIZE 16//4
- #define SPI_FLASH_BLOCK_NUMBER 32
- #if defined ( __ICCARM__ )
- typedef int ssize_t;
- #endif
- typedef struct {
- bool present;
- // uint16_t sector_size;
- uint32_t sector_size;
- uint8_t sector_erase_op;
- uint16_t sector_count;
- } spi_flash_desc_t;
- extern spi_flash_desc_t spi_flash_desc;
- extern bool spi_flash_init(void);
- extern ssize_t spi_flash_read(int addr, void *buf, size_t len, uint32_t timeout);
- extern ssize_t spi_flash_write(int addr, const void *buf, size_t len, uint32_t timeout);
- extern int spi_flash_erase_sector(int addr, uint32_t timeout);
- extern int spi_flash_chip_erase(uint32_t timeout);
- extern void spi_flash_test(void);
- #endif /* SPI_FLASH_H */
|