⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c2635.h

📁 Flash Memory 依據標準CFI CMD做Erase/Program過程的參考碼
💻 H
📖 第 1 页 / 共 4 页
字号:
/******************************************************************************* 
     DERIVED DATATYPES
*******************************************************************************/ 

/******** CommandsType ********/ 

typedef enum { 
   BankErase,
   BankReset,
   BankResume,
   BankSuspend,
   BlockErase,
   BlockProtect, 
   BlockUnprotect, 
   BufferProgram,
   CheckBlockProtection, 
   CheckCompatibility, 
   ChipErase, 
   ChipUnprotect, 
   GroupProtect,
   Program, 
   Read, 
   ReadCfi, 
   ReadDeviceId, 
   ReadManufacturerCode, 
   Reset, 
   Resume, 
   SingleProgram, 
   Suspend, 
   Write  
} CommandType; 


/******** ReturnType ********/ 

typedef enum { 
   Flash_AddressInvalid, 
   Flash_BankEraseFailed,
   Flash_BlockEraseFailed, 
   Flash_BlockNrInvalid, 
   Flash_BlockProtected, 
   Flash_BlockProtectFailed, 
   Flash_BlockProtectionUnclear, 
   Flash_BlockUnprotected, 
   Flash_BlockUnprotectFailed, 
   Flash_CfiFailed, 
   Flash_ChipEraseFailed, 
   Flash_ChipUnprotectFailed, 
   Flash_FunctionNotSupported,
   Flash_GroupProtectFailed, 
   Flash_NoInformationAvailable,
   Flash_NoOperationToSuspend,
   Flash_OperationOngoing, 
   Flash_OperationTimeOut, 
   Flash_ProgramFailed, 
   Flash_ResponseUnclear, 
   Flash_SpecificError,
   Flash_Success, 
   Flash_VppInvalid, 
   Flash_WrongType,
   Flash_Default_Mode,
   Flash_NV_Protection_Mode,
   Flash_Password_Protection_Mode,
   Flash_ExtendedRom_Protection,
   Flash_NVPB_Unlocked,
   Flash_NVPB_Locked,
   Flash_NVPB_Unclear,
   Flash_NonVolatile_Protected,
   Flash_NonVolatile_Unprotected,
   Flash_NonVolatile_Unclear,
   Flash_Volatile_Protected,
   Flash_Volatile_Unprotected,
   Flash_Volatile_Unclear,   
} ReturnType;  
 
/******** BlockType ********/ 

typedef uword uBlockType; 
 
/******** ParameterType ********/ 
 
typedef union { 
    /**** BankErase Parameters ****/ 
    struct { 
      uBlockType ublBlockNr;
      ReturnType *rpResults; 
    } BankErase; 
     
    /**** BankReset Parameters ****/ 
    struct { 
      udword udBankAddrOff; 
    } BankReset;

    /**** BankResume Parameters ****/ 
    struct { 
      udword udAddrOff; 
    } BankResume;
     
    /**** BankSuspend Parameters ****/ 
    struct { 
      udword udAddrOff; 
    } BankSuspend;

    /**** BlockErase Parameters ****/ 
    struct { 
      uBlockType ublBlockNr; 
    } BlockErase; 

    /**** BlockProtect Parameters ****/ 
    struct { 
      uBlockType ublBlockNr; 
    } BlockProtect; 
 
    /**** BlockUnprotect Parameters ****/ 
    struct { 
      uBlockType ublBlockNr; 
    } BlockUnprotect; 
 
    /**** CheckBlockProtection Parameters ****/ 
    struct { 
      uBlockType ublBlockNr; 
    } CheckBlockProtection; 
 
    /**** CheckCompatibility has no parameters ****/ 
 
    /**** ChipErase Parameters ****/ 
    struct { 
      ReturnType *rpResults; 
    } ChipErase;  
     
    /**** ChipUnprotect Parameters ****/ 
    struct { 
      ReturnType *rpResults; 
    } ChipUnprotect;  

    /**** GroupProtect Parameters ****/ 
    struct { 
      uBlockType ublBlockNr; 
    } GroupProtect;  

    /**** Program Parameters ****/ 
    struct { 
      udword udAddrOff; 
      udword udNrOfElementsInArray;         
        void *pArray; 
      udword udMode;        
    } Program; 

    /**** Read Parameters ****/ 
    struct { 
      udword  udAddrOff; 
      uCPUBusType ucValue;  
    } Read; 
 
    /**** ReadCfi Parameters ****/ 
    struct { 
      uword  uwCfiFunc; 
      uCPUBusType ucCfiValue;        
    } ReadCfi; 

    /**** ReadDeviceId Parameters ****/ 
    struct { 
      uCPUBusType ucDeviceId; 
    } ReadDeviceId; 
 
    /**** ReadManufacturerCode Parameters ****/ 
    struct { 
      uCPUBusType ucManufacturerCode; 
    } ReadManufacturerCode; 

    /**** Reset has no parameters ****/ 

    /**** Resume has no parameters ****/ 
    
    /**** SingleProgram Parameters ****/ 
    struct { 
      udword udAddrOff; 
      uCPUBusType ucValue; 
    } SingleProgram;     
    
    /**** Suspend has no parameters ****/ 
     
    /**** Write Parameters ****/ 
    struct { 
      udword udAddrOff; 
      uCPUBusType ucValue; 
    } Write;     
 
} ParameterType; 
 
/******** ErrorInfoType ********/ 

typedef struct {
  SpecificReturnType sprRetVal;
  udword             udGeneralInfo[4];
} ErrorInfoType;

/******************************************************************************
    Global variables
*******************************************************************************/ 
extern ErrorInfoType eiErrorInfo;



/*******************************************************************************
Device Constants
*******************************************************************************/


#define ANY_ADDR (0x0)            /* Any address offset within the Flash Memory will do */
#define PASSWORD_MODE_LOCKBIT (0x04)
#define NVP_MODE_LOCKBIT  (0x02)
#define EXTENDED_BLOCK_PROTECTION_BIT (0x01)

#ifdef USE_M29W128G_8 /* The M29W128G device 8 bit */
   #define MANUFACTURER_ST (0x20)  /* ST Manufacturer Code is 0x20 */
   #define EXPECTED_DEVICE (0x7E)  /* Device code for the M29W128G */
   #define FLASH_SIZE (0x1000000)       /* Total device size in Bytes */
   #define FLASH_WRITE_BUFFER_SIZE 64   /* Write Buffer = 64 Byte */
   #define FLASH_MWA 1  /* Minimum Write Access */
   #define ShAddr(A) (A<<1)            /* Exclude A-1 address bit in ReadCFi
                                          and Protect/Unprotect commands */
   #define ConvAddr(A) (2*A+!(A&0x1))  /* Convert a word mode command to byte mode command :
                                           Word Mode Command    Byte Mode Command
                                                0x555      ->     0xAAA
                                                0x2AA      ->     0x555
                                                0x55       ->     0xAA            */
   
   static const ubyte BlockGroupOffset[] = {
      1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
      1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
      1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
      1,1,1,1,1,1,1,1,1
   }; 
   
   static const udword BlockOffset[] = {
      0x000000,  /* Start offset of block 0  */      
      0x020000,  /* Start offset of block 1  */
      0x040000,  /* Start offset of block 2  */
      0x060000,  /* Start offset of block 3  */
      0x080000,  /* Start offset of block 4  */
      0x0A0000,  /* Start offset of block 5  */
      0x0C0000,  /* Start offset of block 6  */
      0x0E0000,  /* Start offset of block 7  */
      0x100000,  /* Start offset of block 8  */
      0x120000,  /* Start offset of block 9  */
      0x140000,  /* Start offset of block 10  */
      0x160000,  /* Start offset of block 11  */
      0x180000,  /* Start offset of block 12  */
      0x1A0000,  /* Start offset of block 13  */
      0x1C0000,  /* Start offset of block 14  */
      0x1E0000,  /* Start offset of block 15  */
      0x200000,  /* Start offset of block 16  */
      0x220000,  /* Start offset of block 17  */
      0x240000,  /* Start offset of block 18  */
      0x260000,  /* Start offset of block 19  */
      0x280000,  /* Start offset of block 20  */
      0x2A0000,  /* Start offset of block 21  */
      0x2C0000,  /* Start offset of block 22  */
      0x2E0000,  /* Start offset of block 23  */
      0x300000,  /* Start offset of block 24  */
      0x320000,  /* Start offset of block 25  */
      0x340000,  /* Start offset of block 26  */
      0x360000,  /* Start offset of block 27  */
      0x380000,  /* Start offset of block 28  */
      0x3A0000,  /* Start offset of block 29  */
      0x3C0000,  /* Start offset of block 30  */
      0x3E0000,  /* Start offset of block 31  */
      0x400000,  /* Start offset of block 32  */
      0x420000,  /* Start offset of block 33  */
      0x440000,  /* Start offset of block 34  */
      0x460000,  /* Start offset of block 35  */
      0x480000,  /* Start offset of block 36  */
      0x4A0000,  /* Start offset of block 37  */
      0x4C0000,  /* Start offset of block 38  */
      0x4E0000,  /* Start offset of block 39  */
      0x500000,  /* Start offset of block 40  */
      0x520000,  /* Start offset of block 41  */
      0x540000,  /* Start offset of block 42  */
      0x560000,  /* Start offset of block 43  */
      0x580000,  /* Start offset of block 44  */
      0x5A0000,  /* Start offset of block 45  */
      0x5C0000,  /* Start offset of block 46  */
      0x5E0000,  /* Start offset of block 47  */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -