/** * @file eeprom_m95.h * @author xxx * @date 2023-08-30 14:05:55 * @brief 头文件 eeprom_m95.h * @copyright Copyright (c) 2023 by xxx, All Rights Reserved. */ #ifndef __EEPROM_M95_H #define __EEPROM_M95_H #include "main.h" #include "spis.h" #define _M95010_ 128 #define _M95020_ 256 #define _M95040_ 512 #define _M95080_ 1024 #define _M95160_ 2048 #define _M95320_ 4096 #define _M95640_ 8192 #define _M95128_ 16384 #define _M95256_ 32768 #define _M95512_ 65536 ///< 65K #define _M95M02_ 262144 ///< 256K #define _M95_SIZE _M95512_ #define M95_CMD_RDSR 0x05 /*!< Read Status Register instruction */ #define M95_CMD_WRSR 0x01 /*!< Write Status Register instruction */ #define M95_CMD_WREN 0x06 /*!< Write enable instruction */ #define M95_CMD_WRDI 0x04 /*!< Write disable instruction */ #define M95_CMD_READ 0x03 /*!< Read from Memory instruction */ #define M95_CMD_WRITE 0x02 /*!< Write to Memory instruction */ ///< Instruction available only for the M95_2-D device. #define M95_CMD_RDID 0x83 /*!< Read identification page*/ #define M95_CMD_WRID 0x82 /*!< Write identification page*/ #define M95_CMD_RDLS 0x83 /*!< Reads the Identification page lock status*/ #define M95_CMD_LID 0x82 /*!< Locks the Identification page in read-only mode*/ #define M95_DUMMY_BYTE 0xA5 ///< 虚拟字节 ///< 定义存储器大小(Bytes) typedef enum { M95_PAGE_SIZE_16 = 16, ///< _M95010_ 、_M95020_ 、_M95040_ M95_PAGE_SIZE_32 = 32, ///< _M95080_ 、_M95160_、_M95320_、_M95640_ M95_PAGE_SIZE_64 = 64, ///< _M95128_、_M95256_ M95_PAGE_SIZE_128 = 128, ///< _M95512_ M95_PAGE_SIZE_256 = 256, ///< _M95M02_ } m95_page_size_e; typedef enum { M95_1, M95_2, M95_MAX, } m95_number_e; ///< 板卡上2块m95芯片定义 typedef union { uint8_t data; struct { uint8_t wip : 1; ///< Write in progress uint8_t wel : 1; ///< Write enable latch uint8_t bp0 : 1; ///< Block protect 0 uint8_t bp1 : 1; ///< Block protect 1 uint8_t reserve : 3; uint8_t srwd : 1; ///< Status register write protect } bits; } m95_write_protection_u; typedef struct { m95_number_e num; m95_write_protection_u write_protection; spi_t *spi; } m95_number_t; extern m95_number_t eeprom_m95s[M95_MAX]; ///< m95芯片数组 /** * @brief Initializes the M95 EEPROM module. * * @param num The M95 EEPROM number. */ extern void eeprom_m95_init(m95_number_e num); /** * @brief Deinitializes the M95 EEPROM module. * * @param num The M95 EEPROM number. */ extern void eeprom_m95_dinit(m95_number_e num); /** * @brief Enables the M95 EEPROM module. */ extern void eeprom_m95_enable(void); /** * @brief Disables the M95 EEPROM module. */ extern void eeprom_m95_disable(void); /** * @brief Closes the write protection of the M95 EEPROM module. * * @param num The M95 EEPROM number. */ extern void eeprom_m95_write_protection_close(m95_number_e num); /** * @brief write protection state of the M95 EEPROM module. * * @param num The M95 EEPROM number. */ extern BOOL eeprom_m95_write_protection_state(m95_number_e num); /** * @brief Reads data from the M95 EEPROM module. * * @param num The M95 EEPROM number. * @param read_addr The address to read from. * @param data The buffer to store the read data. * @param length The number of bytes to read. */ extern BOOL eeprom_m95_read(m95_number_e num, uint32_t read_addr, uint8_t *data, uint16_t length); /** * @brief Writes data to the M95 EEPROM module. * * @param num The M95 EEPROM number. * @param write_addr The address to write to. * @param data The data to write. * @param length The number of bytes to write. */ extern BOOL eeprom_m95_write(m95_number_e num, uint32_t write_addr, uint8_t *data, uint16_t length); /** * @brief Performs a test on the M95 EEPROM module. * * @param num The M95 EEPROM number. */ extern void eeprom_m95_test(m95_number_e num); extern BOOL eeprom_m95_1_read(uint32_t addr, uint8_t *buf, uint16_t size); extern BOOL eeprom_m95_1_write(uint32_t addr, uint8_t *buf, uint16_t size); extern BOOL eeprom_m95_2_read(uint32_t addr, uint8_t *buf, uint16_t size); extern BOOL eeprom_m95_2_write(uint32_t addr, uint8_t *buf, uint16_t size); #endif ///< __EEPROM_M95_H