/* * This file is part of the Serial Flash Universal Driver Library. * * Copyright (c) 2016-2018, Armink, * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * 'Software'), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * Function: It is the configure head file for this library. * Created on: 2016-04-23 */ #ifndef _SNFUD_DEF_H_ #define _SNFUD_DEF_H_ #include "board.h" #ifdef SPI0_QSPI_MODE #define SNFUD_USING_QSPI #endif #define SNFUD_CMD_WRITE_DISABLE 0x04 #define SNFUD_CMD_WRITE_ENABLE 0x06 #define SNFUD_CMD_GET_FEATURE 0x0F #define SNFUD_CMD_SET_FEATURE 0x1F #define SNFUD_CMD_LOCK_REG 0xa0 #define SNFUD_CMD_FEATURE_REG 0xb0 #define SNFUD_CMD_STATUS_REG 0xc0 #define SNFUD_CMD_READ_ID 0x9F #define SNFUD_CMD_PAGE_READ 0x13 #define SNFUD_CMD_READ_CACHE 0x03 #define SNFUD_CMD_FAST_READ_CACHE 0x0b #define SNFUD_CMD_READ_CACHE_X2 0x3b #define SNFUD_CMD_READ_CACHE_X4 0x6b #define SNFUD_CMD_READ_CACHE_DUAL_IO 0xbb #define SNFUD_CMD_READ_CACHE_QUAD_IO 0xeb #define SNFUD_CMD_PROGRAM_EXEC 0x10 #define SNFUD_CMD_PROGRAM_LOAD 0x02 #define SNFUD_CMD_PROGRAM_LOAD4 0x32 #define SNFUD_CMD_PROGRAM_LOAD_RANDOM 0x84 #define SNFUD_CMD_PROGRAM_LOAD_RANDOM4 0xc4 #define SNFUD_CMD_BLOCK_ERASE 0xd8 #define SNFUD_CMD_RESET 0xFF #define SNFUD_ECC_EN (1 << 4) #define SNFUD_QUAD_EN (1 << 0) #define SNFUD_PROT_UNLOCK_ALL 0x0 #define SNFUD_ECC_UNCORR 0x2 #define SNFUD_STATUS_REG_ECC_MASK 0x3 #define SNFUD_STATUS_REG_ECC_SHIFT 0x4 #define SNFUD_STATUS_REG_PROG_FAIL (1 << 3) #define SNFUD_STATUS_REG_ERASE_FAIL (1 << 2) #define SNFUD_STATUS_REG_WREN (1 << 1) #define SNFUD_STATUS_REG_BUSY (1 << 0) #define SNFUD_BBT_HEADER_BLK_COUNT 2 #define SNFUD_BBT_BLK_PERCENT 2 //default: 2% #define SNFUD_BBT_HEADER_MASK "SNF BAD BLOCK TABLE" //< 20 bytes. /* * To compatible with the spi nor flash interface calls(they have different erase size), we add this macro. * The driver will manage the erase and write operations automatically. * * When write a few data within a block, the driver will first backup the block data with a buffer, * then update the new data to the buffer, and then erase the block, finally write back the buffer data. */ #define SNFUD_ERASE_WRITE_DYNAMIC_MANAGE typedef struct spi_nand_plane_select { /* plane select is used for block select */ uint32_t rpb; //read page(from nand array to cache) bit. uint32_t rcb; //read cache(from page cache to app buffer) bit. uint32_t plb; //program load(write data to cache) bit. uint32_t peb; //program excute(flush cache to nand array) bit. } sfud_ps; enum { SNF_BLK_BAD = 0, SNF_BLK_USED, SNF_BLK_GOOD = 0xFF, }; #define SNFUD_FLASH_DEVICE_TABLE \ { \ [0] = {.spi.name = "spi0"}, \ } static sfud_ps g_SnfPsArray[] = { [0] = {6, 12, 12, 6}, }; // name, MID, DID0, DID0, BBM, bytePerPage, pagePerBlk, blkCnt, spare //PlaneSelect #define SNFUD_FLASH_CHIP_TABLE \ { \ { "DS35Q1GA", 0xE5, 0x71, 0x0, 2, 2048, 64, 1024, 64, -1/* not use */}, \ { "DS35Q2GA", 0xE5, 0x72, 0x0, 2, 2048, 64, 2048, 64, 0}, \ } typedef struct _snf_blk_node { uint8_t status; uint16_t replace; //replace bad block. } snf_blk_node; typedef struct _snf_bbt { uint8_t header_mask[32]; uint8_t has_mask; snf_blk_node node[]; } snf_bbt; /* flash chip information */ typedef struct { char *name; /**< flash chip name */ uint8_t mf_id; /**< manufacturer ID */ uint8_t dev_id0; /**< device ID0 */ uint8_t dev_id1; /**< device ID1 */ uint8_t bbm_type; uint32_t byte_per_page; uint32_t page_per_blk; uint32_t total_blk; uint32_t spare_size; int PsArrayIndex; // uint32_t available_blks; uint32_t capacity; uint32_t available_capacity; uint32_t byte_per_blk; uint32_t bbt_header_blk_offset; uint32_t bbt_available_blks; snf_bbt *bbt; sfud_flash *flash; sfud_ps *ps; #ifdef SNFUD_ERASE_WRITE_DYNAMIC_MANAGE uint8_t *backup_buf; /* block backup buffer */ #endif } snfud_flash_chip; #endif /* _SFUD_CFG_H_ */