SST39VF3201.c #include <stdio.h> #include "vxworks.h" #include "tffs/flflash.h" #include "tffs/backgrnd.h" #include "SST39VF3201.h" typedef unsigned long uint32; typedef unsigned short uint16; typedef unsigned char uint8; #define flashBaseAddr 0x10000000 /* Instance specific CFI data so that a system may have more than one CFI * device. */ typedef struct { unsigned commandSetId; /* id of a specific command set. */ unsigned altCommandSetId; /* id of alternate command set. */ FLBoolean wordMode; /* TRUE - word mode. FALSE - byte mode. */ int multiplier; /* the number of bytes in addressing scheme */ int interleaveFactor; /* Number of bytes interleaved */ unsigned maxBytesWrite; /* maximum number of bytes in multi-byte write. */ FLBoolean vpp; /* if = TRUE, need vpp. */ long optionalCommands; /* optional commands supported */ /* (1 = yes, 0 = no): */ /* bit 0 - chip erase. */ /* bit 1 - suspend erase. */ /* bit 2 - suspend write */ /* bit 3 - lock/unlock. */ /* bit 4 - queued erase. */ unsigned afterSuspend; /* functions supported after */ /* suspend (1 = yes, 0 = no): */ /* bit 0 - write after erase */ /* suspend. */ } CFI; LOCAL CFI mtdVars[DRIVES]; /* disable debugging */ #define _SST_39_VF_DEBUG #ifdef _SST_39_VF_DEBUG #define DEBUG_PRINT(x,a,b,c,d,e,f) logMsg(x,a,b,c,e,d,f) #else #undef DEBUG_PRINT #endif /* JEDEC-IDs */ #define VOYAGER_ID 0x8915 #define KING_COBRA_ID 0xb0d0 /* CFI identification strings */ #define ID_STR_LENGTH 3 #define QUERY_ID_STR "QRY" #define PRIMARY_ID_STR "PRI" #define ALTERNATE_ID_STR "ALT" #define thisCFI ((CFI *)vol.mtdVars) void FlashReadMode(){ SST39_READ(flashBaseAddr); } void FlashCfiMode(){ SST39_CFI(flashBaseAddr); } uint16 FlashDataRead(uint32 address){ return(*(volatile uint16*)(address)); } void FlashDataWrite(uint32 address ,uint16 data){ SST39_WORD_PROGRAM(flashBaseAddr,address,data); } /************************************************************************/ /* PROCEDURE: CheckData_Polling */ /* */ /* During the internal erase/program, any attempt to read DQ7 of the */ /* last byte loaded will receive the complement of the true data. */ /* Once the program cycle is completed, DQ7 will show true data. */ /* For erase, DQ7 will output 0 during busy of internal operation. */ /* DQ7 will ouput 1 once the internal erase operation is completed. */ /* */ /* Input: */ /* dstAddr any valid device address */ /* trueData this is the original (true) data */ /* */ /* Output: */ /* TRUE if Success */ /* FALSE if Not complelte */ /************************************************************************/ LOCAL uint8 CheckData_Polling(FlashWPTR dstAddr, uint16 trueData){ uint16 currData,i; dstAddr = (FlashWPTR)((uint32)dstAddr & ~(0x01)); /* Only write words on word-boundary */ trueData = trueData & 0x0080;