ERROR_CODE GetRCR ( u16* uwRCR ) { WriteFlash( 0x0000, 0x90 ); /* send the auto select command to the flash */ ReadFlash ( 0x000A, uwRCR ); /* now we can read the RCR */ ResetFlash(); return NO_ERR; }
ERROR_CODE SetRCR ( u16 uwRCR ) { WriteFlash( uwRCR << 1, 0x60 ); /* RCR setup */ WriteFlash( uwRCR << 1, 0x03 ); ResetFlash(); return NO_ERR; }
ERROR_CODE GetCodes(void) { WriteFlash ( 0x0000, 0x90 ); /* send the auto select command to the flash */ ReadFlash ( 0x0000, &uwManufactureCode ); /* now we can read the codes */ uwManufactureCode &= 0x00FF; ReadFlash ( 0x0002, &uwDeviceCode ); uwDeviceCode &= 0xFFFF; uwRCR_Default = 0xBFCF; /* hardwired to facilitate the test , it may be GetRCR( &RCR_Default ); */ ResetFlash(); /* we need to issue another command to get the part out of auto select mode so issue a reset which just puts the device back in read mode */ return NO_ERR; }
ERROR_CODE PollToggleBit(unsigned long ulAddr) { ERROR_CODE ErrorCode = NO_ERR; // flag to indicate error unsigned short sVal1; unsigned short sVal2; // read flash 1 time ReadFlash( ulAddr, &sVal1 ); while( ErrorCode == NO_ERR ) { // read the value 2 times ReadFlash( ulAddr, &sVal1 ); ReadFlash( ulAddr, &sVal2 ); // XOR to see if any bits are different sVal1 ^= sVal2; // see if we are toggling if( !(sVal1 & 0x40) ) break; // check error bit if( !(sVal2 & 0x20) ) continue; else { // read the value 2 times ReadFlash( ulAddr, &sVal1 ); ReadFlash( ulAddr, &sVal2 ); // XOR to see if any bits are different sVal1 ^= sVal2; // see if we are toggling if( !(sVal1 & 0x40) ) break; else { ErrorCode = POLL_TIMEOUT; ResetFlash(ulAddr); } } } // we can return return ErrorCode; }
ERROR_CODE SetToPageMode(void) { SetupForFlash(); GetCodes(); *pEBIU_AMGCTL = 0x0000; /* disable the Async Memory */ /* Set the mode to async Mode (0-async mode, 1-flash mode, 2-page mode, 3-burst mode) */ *pEBIU_MODE = ( B0MODE_PAGE | B1MODE_PAGE | B2MODE_PAGE | B3MODE_PAGE ); *pEBIU_FCTL = ( PGWS | BCLK ); *pEBIU_AMGCTL = ( AMCKEN | AMBEN ); /* enable the Async Memory */ ssync(); SetRCR ( uwRCR_Default ); ResetFlash(); return NO_ERR; }
ERROR_CODE GetCodes(int *pnManCode, int *pnDevCode, unsigned long ulAddr) { unsigned long ulFlashStartAddr; //flash start address // get flash start address from absolute address // The ulAddr should ideally be pointing to the flash start // address. However we just verify it here again. ulFlashStartAddr = GetFlashStartAddress(ulAddr); // send the auto select command to the flash WriteFlash( ulFlashStartAddr + 0x0aaa, 0xaa ); WriteFlash( ulFlashStartAddr + 0x0554, 0x55 ); WriteFlash( ulFlashStartAddr + 0x0aaa, 0x90 ); // now we can read the codes ReadFlash( ulFlashStartAddr + 0x0000,(unsigned short *)pnManCode ); *pnManCode &= 0x00FF; ReadFlash( ulFlashStartAddr + 0x0002, (unsigned short *)pnDevCode ); *pnDevCode &= 0x00FF; if( *pnDevCode == 0x5B ) { gNumSectors = 19; pFlashDesc = "S29AL008D(512 x 16)"; } else { gNumSectors = 11; pFlashDesc = "S29AL004D(256 x 16)"; } // we need to issue another command to get the part out // of auto select mode so issue a reset which just puts // the device back in read mode ResetFlash(ulAddr); // ok return NO_ERR; }
ERROR_CODE SetToBurstMode(void) { u16 uwRCRtmp; SetupForFlash(); GetCodes(); *pEBIU_AMGCTL = 0x0000; /* disable the Async Memory */ /* Set the mode to async Mode (0-async mode, 1-flash mode, 2-page mode, 3-burst mode) */ *pEBIU_MODE = ( B0MODE_BURST | B1MODE_BURST | B2MODE_BURST | B3MODE_BURST ); *pEBIU_FCTL = ( BCLK ); *pEBIU_AMGCTL = ( AMCKEN | AMBEN ); /* enable the Async Memory */ ssync(); uwRCRtmp = uwRCR_Default & 0x05F0; uwRCRtmp |= 0x0003; uwRCRtmp |= 3 << 11; SetRCR ( uwRCRtmp ); ResetFlash(); return NO_ERR; }
ERROR_CODE GetCodes(int *pnManCode, int *pnDevCode, unsigned long ulAddr) { // send the auto select command to the flash WriteFlash( ulAddr + 0x0AAA, 0xaa ); WriteFlash( ulAddr + 0x0554, 0x55 ); WriteFlash( ulAddr + 0x0AAA, 0x90 ); // now we can read the codes ReadFlash( ulAddr + 0x0400,(unsigned short *)pnManCode ); *pnManCode &= 0x00FF; ReadFlash( ulAddr + 0x0402, (unsigned short *)pnDevCode ); *pnDevCode &= 0xFFFF; // if it is the M29W320DB if( *pnDevCode == 0x22CB ) { gNumSectors = 67; pFlashDesc = "STMicro. M29W320DB"; } else if( *pnDevCode == 0x2257 ) { gNumSectors = 71; pFlashDesc = "STMicro. M29W320EB"; } else return PROCESS_COMMAND_ERR; // we need to issue another command to get the part out // of auto select mode so issue a reset which just puts // the device back in read mode ResetFlash(ulAddr); // ok return NO_ERR; }
u32 adi_pdd_Control( ADI_DEV_PDD_HANDLE PDDHandle, u32 Command, void *pArg) { ERROR_CODE ErrorCode = NO_ERR; COMMAND_STRUCT *pCmdStruct = (COMMAND_STRUCT *)pArg; // switch on the command switch ( Command ) { // erase all case CNTRL_ERASE_ALL: ErrorCode = EraseFlash(pCmdStruct->SEraseAll.ulFlashStartAddr); break; // erase sector case CNTRL_ERASE_SECT: ErrorCode = EraseBlock( pCmdStruct->SEraseSect.nSectorNum, pCmdStruct->SEraseSect.ulFlashStartAddr ); break; // get manufacturer and device codes case CNTRL_GET_CODES: ErrorCode = GetCodes((int *)pCmdStruct->SGetCodes.pManCode, (int *)pCmdStruct->SGetCodes.pDevCode, (unsigned long)pCmdStruct->SGetCodes.ulFlashStartAddr); break; case CNTRL_GET_DESC: //Filling the contents with data pCmdStruct->SGetDesc.pDesc = pFlashDesc; pCmdStruct->SGetDesc.pFlashCompany = pDeviceCompany; break; // get sector number based on address case CNTRL_GET_SECTNUM: ErrorCode = GetSectorNumber( pCmdStruct->SGetSectNum.ulOffset, (int *)pCmdStruct->SGetSectNum.pSectorNum ); break; // get sector number start and end offset case CNTRL_GET_SECSTARTEND: ErrorCode = GetSectorStartEnd( pCmdStruct->SSectStartEnd.pStartOffset, pCmdStruct->SSectStartEnd.pEndOffset, pCmdStruct->SSectStartEnd.nSectorNum ); break; // get the number of sectors case CNTRL_GETNUM_SECTORS: pCmdStruct->SGetNumSectors.pnNumSectors[0] = gNumSectors; break; // reset case CNTRL_RESET: ErrorCode = ResetFlash(pCmdStruct->SReset.ulFlashStartAddr); break; // turn on dataflow (command required of all device drivers) case ADI_DEV_CMD_SET_DATAFLOW: ErrorCode = NO_ERR; break; case ADI_DEV_CMD_SET_DATAFLOW_METHOD: // Do nothing & simply return back for these commands break; // get peripheral DMA support (command required of all device drivers) case ADI_DEV_CMD_GET_PERIPHERAL_DMA_SUPPORT: (*(u32 *)pArg) = FALSE; // no, this device is not supported by peripheral DMA break; // no command or unknown command do nothing default: // set our error ErrorCode = UNKNOWN_COMMAND; break; } // return return(ErrorCode); }
ERROR_CODE GetCodes(int *pnManCode, int *pnDevCode, unsigned long ulAddr) { unsigned long ulFlashStartAddr; //flash start address // get flash start address from absolute address // The ulAddr should ideally be pointing to the flash start // address. However we just verify it here again. ulFlashStartAddr = GetFlashStartAddress(ulAddr); // send the auto select command to the flash // WriteFlash( ulFlashStartAddr + 0x0AAA, 0xaa ); // WriteFlash( ulFlashStartAddr + 0x0554, 0x55 ); // WriteFlash( ulFlashStartAddr + 0x0AAA, 0x90 ); WriteFlash( ulFlashStartAddr + 2*0x0555, 0xaa ); WriteFlash( ulFlashStartAddr + 2*0x02aa, 0x55 ); WriteFlash( ulFlashStartAddr + 2*0x0555, 0x90 ); // now we can read the codes // ReadFlash( ulFlashStartAddr + 0x0402, (unsigned short *)pnManCode ); ReadFlash( ulFlashStartAddr + 2*0x0000, (unsigned short *)pnManCode ); *pnManCode &= 0x00FF; // ReadFlash( ulFlashStartAddr + 0x0400, (unsigned short *)pnDevCode ); ReadFlash( ulFlashStartAddr + 2*0x0001, (unsigned short *)pnDevCode ); *pnDevCode &= 0xFFFF; // ReadFlash( 0x1ffffffc, (unsigned short *)pnDevCode ); // *pnDevCode &= 0xFFFF; // we need to issue another command to get the part out // of auto select mode so issue a reset which just puts // the device back in read mode ResetFlash(ulAddr); ResetFlash(ulAddr); return NO_ERR; WriteFlash( ulFlashStartAddr + 2*0x0055, 0x98 ); unsigned long int a=0, b=0, c=0, d=0; // ReadFlash( ulFlashStartAddr + 2*0x10, (unsigned short *) &a ); // ReadFlash( ulFlashStartAddr + 2*0x11, (unsigned short *) &b ); // ReadFlash( ulFlashStartAddr + 2*0x12, (unsigned short *) &c ); // ReadFlash( ulFlashStartAddr + 2*0x13, (unsigned short *) &d ); // ReadFlash( ulFlashStartAddr + 2*0x40, (unsigned short *) &a ); // ReadFlash( ulFlashStartAddr + 2*0x41, (unsigned short *) &b ); // ReadFlash( ulFlashStartAddr + 2*0x42, (unsigned short *) &c ); // ReadFlash( ulFlashStartAddr + 2*0x43, (unsigned short *) &d ); // ReadFlash( ulFlashStartAddr + 2*0x27, (unsigned short *) &a ); // ReadFlash( ulFlashStartAddr + 2*0x28, (unsigned short *) &b ); // ReadFlash( ulFlashStartAddr + 2*0x29, (unsigned short *) &c ); // ReadFlash( ulFlashStartAddr + 2*0x4e, (unsigned short *) &d ); // ReadFlash( ulFlashStartAddr + 2*0x61, (unsigned short *) &a ); // ReadFlash( ulFlashStartAddr + 2*0x62, (unsigned short *) &b ); // ReadFlash( ulFlashStartAddr + 2*0x63, (unsigned short *) &c ); // ReadFlash( ulFlashStartAddr + 2*0x64, (unsigned short *) &d ); // ReadFlash( ulFlashStartAddr + 2*0x2d, (unsigned short *) &a ); // ReadFlash( ulFlashStartAddr + 2*0x2e, (unsigned short *) &b ); // ReadFlash( ulFlashStartAddr + 2*0x2f, (unsigned short *) &c ); // ReadFlash( ulFlashStartAddr + 2*0x30, (unsigned short *) &d ); ReadFlash( ulFlashStartAddr + 2*0x31, (unsigned short *) &a ); // ReadFlash( ulFlashStartAddr + 2*0x32, (unsigned short *) &b ); // ReadFlash( ulFlashStartAddr + 2*0x33, (unsigned short *) &c ); // ReadFlash( ulFlashStartAddr + 2*0x34, (unsigned short *) &d ); a &= 0xFFFF; b &= 0xFFFF; c &= 0xFFFF; d &= 0xFFFF; // a &= 0xFF; b &= 0xFF; c &= 0xFF; d &= 0xFF; // *pnDevCode = a<<24 + b<<26 + c<<8 + d; // *pnDevCode = a*16777216 + b*65536 + c*256 + d; // *pnDevCode = a*65536 + b; // *pnDevCode = c*65536 + d; // *pnDevCode = d; *pnDevCode = a; // *pnDevCode &= 0xFFFF; /* while(1) { WriteFlash( ulFlashStartAddr + 2*0x0055, 0x98 ); ReadFlash( ulFlashStartAddr + 2*0x34, (unsigned short *) &a ); a &= 0xFFFF; ResetFlash(ulAddr); WriteFlash( ulFlashStartAddr + 2*0x34, a ); ResetFlash(ulAddr); } */ ResetFlash(ulAddr); ResetFlash(ulAddr); // ok return NO_ERR; }
u32 adi_pdd_Control( ADI_DEV_PDD_HANDLE PDDHandle, u32 Command, void *pArg) { ERROR_CODE ErrorCode = NO_ERR; COMMAND_STRUCT *pCmdStruct = (COMMAND_STRUCT *)pArg; // switch on the command switch ( Command ) { // erase all case CNTRL_ERASE_ALL: ErrorCode = EraseFlash(pCmdStruct->SEraseAll.ulFlashStartAddr); break; // erase sector case CNTRL_ERASE_SECT: ErrorCode = EraseBlock( pCmdStruct->SEraseSect.nSectorNum, pCmdStruct->SEraseSect.ulFlashStartAddr ); break; // get manufacturer and device codes case CNTRL_GET_CODES: ErrorCode = GetCodes((int *)pCmdStruct->SGetCodes.pManCode, (int *)pCmdStruct->SGetCodes.pDevCode, (unsigned long)pCmdStruct->SGetCodes.ulFlashStartAddr); break; //Filling the contents with data case CNTRL_GET_DESC: pCmdStruct->SGetDesc.pTitle = pEzKitTitle; pCmdStruct->SGetDesc.pDesc = pFlashDesc; pCmdStruct->SGetDesc.pFlashCompany = pDeviceCompany; break; // get sector number based on address case CNTRL_GET_SECTNUM: ErrorCode = GetSectorNumber( pCmdStruct->SGetSectNum.ulOffset, (int *)pCmdStruct->SGetSectNum.pSectorNum ); break; // get sector number start and end offset case CNTRL_GET_SECSTARTEND: ErrorCode = GetSectorStartEnd( pCmdStruct->SSectStartEnd.pStartOffset, pCmdStruct->SSectStartEnd.pEndOffset, pCmdStruct->SSectStartEnd.nSectorNum ); break; // get the number of sectors case CNTRL_GETNUM_SECTORS: pCmdStruct->SGetNumSectors.pnNumSectors[0] = NUM_SECTORS; break; // reset case CNTRL_RESET: ErrorCode = ResetFlash(pCmdStruct->SReset.ulFlashStartAddr); break; // no command or unknown command do nothing default: // set our error ErrorCode = UNKNOWN_COMMAND; break; } // return return(ErrorCode); }