/* * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2018-01-26 armink the first version */ #include "eeprom_m95.h" #include static int init(void); static int erase(long offset, size_t size); static int read1(long offset, uint8_t *buf, size_t size); static int read2(long offset, uint8_t *buf, size_t size); static int write1(long offset, const uint8_t *buf, size_t size); static int write2(long offset, const uint8_t *buf, size_t size); // 1.定义 flash 设备 struct fal_flash_dev eeprom_m95_1 = { .name = EEPROM_M95_1_DEV_NAME, .addr = 10 * M95_PAGE_SIZE_256, .len = EEPROM_M95_1_SIZE - 10 * M95_PAGE_SIZE_256, .blk_size = EEPROM_M95_1_BLOCK_SIZE, .ops = {init, read1, write1, erase}, .write_gran = 1}; // 设置写粒度,单位 bit,EPPROM写粒度为1bit struct fal_flash_dev eeprom_m95_2 = { .name = EEPROM_M95_2_DEV_NAME, .addr = 0x000000, .len = EEPROM_M95_2_SIZE, .blk_size = EEPROM_M95_2_BLOCK_SIZE, .ops = {init, read2, write2, erase}, .write_gran = 1}; static int init(void) { return 1; } static int erase(long offset, size_t size) { // uint8_t erase_size = size > FAL_ERASE_SIZE ? FAL_ERASE_SIZE : size; // uint8_t buf[FAL_ERASE_SIZE]; // osel_memset(buf, 0xFF, FAL_ERASE_SIZE); // for (uint8_t i = 0; i < (size / M95_PAGE_SIZE_256); i++) // { // uint32_t addr = eeprom_m95_1.addr + offset + i * M95_PAGE_SIZE_256; // eeprom_m95_write(M95_1, addr, (uint8_t *)buf, erase_size); // } return size; } static int read1(long offset, uint8_t *buf, size_t size) { /* You can add your code under here. */ uint32_t addr = eeprom_m95_1.addr + offset; BOOL res = eeprom_m95_read(M95_1, addr, buf, size); return res == TRUE ? size : 0; } static int write1(long offset, const uint8_t *buf, size_t size) { uint32_t addr = eeprom_m95_1.addr + offset; BOOL res = eeprom_m95_write(M95_1, addr, (uint8_t *)buf, size); return res == TRUE ? (int)size : -1; } static int read2(long offset, uint8_t *buf, size_t size) { /* You can add your code under here. */ uint32_t addr = eeprom_m95_2.addr + offset; BOOL res = eeprom_m95_read(M95_2, addr, buf, size); return res == TRUE ? size : 0; } static int write2(long offset, const uint8_t *buf, size_t size) { uint32_t addr = eeprom_m95_2.addr + offset; BOOL res = eeprom_m95_write(M95_2, addr, (uint8_t *)buf, size); return res == TRUE ? (int)size : -1; }