lib/sw_services/xilflash/src/xilflash_amd.c
int WriteSingleBuffer(XFlash * InstancePtr, void *DestPtr,
			 void *SrcPtr, u32 Bytes)
{
	u16 *SourcePtr = (u16*)SrcPtr;
	u32 DestinationPtr = (u32)DestPtr;
	u32 BaseAddress;
	u32 Index = 0;
	int Status = (int)XST_FAILURE;
	XFlashVendorData_Amd *DevDataPtr;
	u32 SectorAddress;
	u32 WordCount = Bytes/2;
	u16 StartRegion;
	u16 EndRegion;
	u16 StartBlock;
	u16 EndBlock;
	u32 Dummy;
	u32 BlockAddress;
	volatile u16 FlashStatus;
	XFlashGeometry *GeomPtr;

	GeomPtr = &InstancePtr->Geometry;
	Status = XFlashGeometry_ToBlock(GeomPtr, (u32)DestPtr/2, &StartRegion,
					&StartBlock, &Dummy);
	(void) XFlashGeometry_ToAbsolute(GeomPtr, StartRegion, StartBlock, 0,
						 &BlockAddress);
	SectorAddress = BlockAddress *2;
	DevDataPtr = GET_PARTDATA(InstancePtr);
	BaseAddress = InstancePtr->Geometry.BaseAddress;
	DestinationPtr = DestinationPtr/2;

	/* Wait until device is ready. */
	AmdDevice_is_Ready(InstancePtr);

	/* Send Status Register Clear Command. */
	DevDataPtr->SendCmd(BaseAddress,XFL_AMD_CMD1_ADDR,
				XFL_AMD_CMD_STATUS_REG_CLEAR);
	/* Send two Unlock cycles Commands. */
	DevDataPtr->SendCmdSeq(BaseAddress,
				XFL_AMD_CMD1_ADDR, XFL_AMD_CMD2_ADDR,
				XFL_AMD_CMD1_DATA, XFL_AMD_CMD2_DATA);
	/* Send Write to Buffer Command. */
	DevDataPtr->SendCmd(BaseAddress,(SectorAddress/2),
				XFL_AMD_CMD_WRITE_BUFFER);
	/* Issue Number of words to Write at sector address. */
	DevDataPtr->SendCmd(BaseAddress,(SectorAddress/2),
				(WordCount -  1));
	Index = 0;

	/* Write Data to Buffer. */
	while (WordCount != 0) {
		DevDataPtr->WriteFlash(BaseAddress,
				(u32)DestinationPtr, SourcePtr[Index]);
		DestinationPtr++;
		Index++;
		WordCount -= 1;
	}

	/* Send Write buffer program confirm command. */
	DevDataPtr->WriteFlash(BaseAddress,(SectorAddress/2),
				XFL_AMD_CMD_PROGRAM_BUFFER);
	Status = DevDataPtr->PollSR(BaseAddress,(u32)(DestinationPtr * 2));
	if (Status != XFLASH_READY) {
		(void) XFlashAmd_ResetBank(InstancePtr, (u32)DestPtr,
					Bytes);
		return Status;
	}
	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* This function is used to program Buffer sized data. It does not erase
* the flash first and will fail if the block(s) are not erased first. The
* device(s) are programmed in parallel.
*
* @param	InstancePtr is the instance to work on.
* @param	DestPtr is the physical destination address in flash memory
*		space.
* @param	SrcPtr is the source data.
* @param	Bytes is the number of bytes to program.
*
* @return
*		- XST_SUCCESS if successful.
*		- XFLASH_ERROR if a write error occurred. This error is
*		  usually device specific.
*
* @note		None.
*
******************************************************************************/
This function is used to program Buffer sized data. It does not erase
the flash first and will fail if the block(s) are not erased first. The
device(s) are programmed in parallel.
This function is used to program Buffer sized data . It does not erase the flash first and will fail if the block ( s ) are not erased first . The device ( s ) are programmed in parallel .
int WriteSingleBuffer(XFlash * InstancePtr, void *DestPtr,
			 void *SrcPtr, u32 Bytes)
{
	u16 *SourcePtr = (u16*)SrcPtr;
	u32 DestinationPtr = (u32)DestPtr;
	u32 BaseAddress;
	u32 Index = 0;
	int Status = (int)XST_FAILURE;
	XFlashVendorData_Amd *DevDataPtr;
	u32 SectorAddress;
	u32 WordCount = Bytes/2;
	u16 StartRegion;
	u16 EndRegion;
	u16 StartBlock;
	u16 EndBlock;
	u32 Dummy;
	u32 BlockAddress;
	volatile u16 FlashStatus;
	XFlashGeometry *GeomPtr;
	GeomPtr = &InstancePtr->Geometry;
	Status = XFlashGeometry_ToBlock(GeomPtr, (u32)DestPtr/2, &StartRegion,
					&StartBlock, &Dummy);
	(void) XFlashGeometry_ToAbsolute(GeomPtr, StartRegion, StartBlock, 0,
						 &BlockAddress);
	SectorAddress = BlockAddress *2;
	DevDataPtr = GET_PARTDATA(InstancePtr);
	BaseAddress = InstancePtr->Geometry.BaseAddress;
	DestinationPtr = DestinationPtr/2;
	AmdDevice_is_Ready(InstancePtr);
	DevDataPtr->SendCmd(BaseAddress,XFL_AMD_CMD1_ADDR,
				XFL_AMD_CMD_STATUS_REG_CLEAR);
	DevDataPtr->SendCmdSeq(BaseAddress,
				XFL_AMD_CMD1_ADDR, XFL_AMD_CMD2_ADDR,
				XFL_AMD_CMD1_DATA, XFL_AMD_CMD2_DATA);
	DevDataPtr->SendCmd(BaseAddress,(SectorAddress/2),
				XFL_AMD_CMD_WRITE_BUFFER);
	DevDataPtr->SendCmd(BaseAddress,(SectorAddress/2),
				(WordCount -  1));
	Index = 0;
	while (WordCount != 0) {
		DevDataPtr->WriteFlash(BaseAddress,
				(u32)DestinationPtr, SourcePtr[Index]);
		DestinationPtr++;
		Index++;
		WordCount -= 1;
	}
	DevDataPtr->WriteFlash(BaseAddress,(SectorAddress/2),
				XFL_AMD_CMD_PROGRAM_BUFFER);
	Status = DevDataPtr->PollSR(BaseAddress,(u32)(DestinationPtr * 2));
	if (Status != XFLASH_READY) {
		(void) XFlashAmd_ResetBank(InstancePtr, (u32)DestPtr,
					Bytes);
		return Status;
	}
	return XST_SUCCESS;
}
int WriteSingleBuffer ( XFlash * InstancePtr , void * DestPtr , void * SrcPtr , u32 Bytes ) { u16 * SourcePtr = ( u16 * ) SrcPtr ; u32 DestinationPtr = ( u32 ) DestPtr ; u32 BaseAddress ; u32 Index = 0 ; int Status = ( int ) XST_FAILURE ; XFlashVendorData_Amd * DevDataPtr ; u32 SectorAddress ; u32 WordCount = Bytes / 2 ; u16 StartRegion ; u16 EndRegion ; u16 StartBlock ; u16 EndBlock ; u32 Dummy ; u32 BlockAddress ; volatile u16 FlashStatus ; XFlashGeometry * GeomPtr ; GeomPtr = & InstancePtr -> Geometry ; Status = XFlashGeometry_ToBlock ( GeomPtr , ( u32 ) DestPtr / 2 , & StartRegion , & StartBlock , & Dummy ) ; ( void ) XFlashGeometry_ToAbsolute ( GeomPtr , StartRegion , StartBlock , 0 , & BlockAddress ) ; SectorAddress = BlockAddress * 2 ; DevDataPtr = GET_PARTDATA ( InstancePtr ) ; BaseAddress = InstancePtr -> Geometry . BaseAddress ; DestinationPtr = DestinationPtr / 2 ; AmdDevice_is_Ready ( InstancePtr ) ; DevDataPtr -> SendCmd ( BaseAddress , XFL_AMD_CMD1_ADDR , XFL_AMD_CMD_STATUS_REG_CLEAR ) ; DevDataPtr -> SendCmdSeq ( BaseAddress , XFL_AMD_CMD1_ADDR , XFL_AMD_CMD2_ADDR , XFL_AMD_CMD1_DATA , XFL_AMD_CMD2_DATA ) ; DevDataPtr -> SendCmd ( BaseAddress , ( SectorAddress / 2 ) , XFL_AMD_CMD_WRITE_BUFFER ) ; DevDataPtr -> SendCmd ( BaseAddress , ( SectorAddress / 2 ) , ( WordCount - 1 ) ) ; Index = 0 ; while ( WordCount != 0 ) { DevDataPtr -> WriteFlash ( BaseAddress , ( u32 ) DestinationPtr , SourcePtr [ Index ] ) ; DestinationPtr ++ ; Index ++ ; WordCount -= 1 ; } DevDataPtr -> WriteFlash ( BaseAddress , ( SectorAddress / 2 ) , XFL_AMD_CMD_PROGRAM_BUFFER ) ; Status = DevDataPtr -> PollSR ( BaseAddress , ( u32 ) ( DestinationPtr * 2 ) ) ; if ( Status != XFLASH_READY ) { ( void ) XFlashAmd_ResetBank ( InstancePtr , ( u32 ) DestPtr , Bytes ) ; return Status ; } return XST_SUCCESS ; }
This function is used to program Buffer sized data.
This function is used to program Buffer sized data .
/* Wait until device is ready. */ /* Send Status Register Clear Command. */ /* Send two Unlock cycles Commands. */ /* Send Write to Buffer Command. */ /* Issue Number of words to Write at sector address. */ /* Write Data to Buffer. */ /* Send Write buffer program confirm command. */