target/linux/at91/image/dfboot/src/at45.c
/*----------------------------------------------------------------------*/
/* \fn    AT91F_DataFlashSendCommand					*/
/* \brief Generic function to send a command to the dataflash		*/
/*----------------------------------------------------------------------*/
\fn    AT91F_DataFlashSendCommand
\brief Generic function to send a command to the dataflash
\ fn AT91F_DataFlashSendCommand \ brief Generic function to send a command to the dataflash
static AT91S_DataFlashStatus AT91F_DataFlashSendCommand(
	AT91PS_DataFlash pDataFlash,
	unsigned char OpCode,
	unsigned int CmdSize,
	unsigned int DataflashAddress)
{
	unsigned int adr;
	adr = ((DataflashAddress / (pDataFlash->pDevice->pages_size)) 
	        << pDataFlash->pDevice->page_offset) +
	        (DataflashAddress % (pDataFlash->pDevice->pages_size));
	pDataFlash->pDataFlashDesc->command[0] = OpCode;
	if (pDataFlash->pDevice->pages_number >= 16384)
	{
		pDataFlash->pDataFlashDesc->command[1] = (unsigned char)((adr & 0x0F000000) >> 24);
		pDataFlash->pDataFlashDesc->command[2] = (unsigned char)((adr & 0x00FF0000) >> 16);
		pDataFlash->pDataFlashDesc->command[3] = (unsigned char)((adr & 0x0000FF00) >> 8);
		pDataFlash->pDataFlashDesc->command[4] = (unsigned char)(adr & 0x000000FF);
	}
	else
	{	
		pDataFlash->pDataFlashDesc->command[1] = (unsigned char)((adr & 0x00FF0000) >> 16);
		pDataFlash->pDataFlashDesc->command[2] = (unsigned char)((adr & 0x0000FF00) >> 8);
		pDataFlash->pDataFlashDesc->command[3] = (unsigned char)(adr & 0x000000FF) ;
		pDataFlash->pDataFlashDesc->command[4] = 0;
	}
	pDataFlash->pDataFlashDesc->command[5] = 0;
	pDataFlash->pDataFlashDesc->command[6] = 0;
	pDataFlash->pDataFlashDesc->command[7] = 0;
	pDataFlash->pDataFlashDesc->tx_cmd_pt   =  pDataFlash->pDataFlashDesc->command ;
	pDataFlash->pDataFlashDesc->tx_cmd_size =  CmdSize ;
	pDataFlash->pDataFlashDesc->rx_cmd_pt   =  pDataFlash->pDataFlashDesc->command ;
	pDataFlash->pDataFlashDesc->rx_cmd_size =  CmdSize ;
	return AT91F_SpiWrite(pDataFlash->pDataFlashDesc);			
}
static AT91S_DataFlashStatus AT91F_DataFlashSendCommand ( AT91PS_DataFlash pDataFlash , unsigned char OpCode , unsigned int CmdSize , unsigned int DataflashAddress ) { unsigned int adr ; adr = ( ( DataflashAddress / ( pDataFlash -> pDevice -> pages_size ) ) << pDataFlash -> pDevice -> page_offset ) + ( DataflashAddress % ( pDataFlash -> pDevice -> pages_size ) ) ; pDataFlash -> pDataFlashDesc -> command [ 0 ] = OpCode ; if ( pDataFlash -> pDevice -> pages_number >= 16384 ) { pDataFlash -> pDataFlashDesc -> command [ 1 ] = ( unsigned char ) ( ( adr & 0x0F000000 ) >> 24 ) ; pDataFlash -> pDataFlashDesc -> command [ 2 ] = ( unsigned char ) ( ( adr & 0x00FF0000 ) >> 16 ) ; pDataFlash -> pDataFlashDesc -> command [ 3 ] = ( unsigned char ) ( ( adr & 0x0000FF00 ) >> 8 ) ; pDataFlash -> pDataFlashDesc -> command [ 4 ] = ( unsigned char ) ( adr & 0x000000FF ) ; } else { pDataFlash -> pDataFlashDesc -> command [ 1 ] = ( unsigned char ) ( ( adr & 0x00FF0000 ) >> 16 ) ; pDataFlash -> pDataFlashDesc -> command [ 2 ] = ( unsigned char ) ( ( adr & 0x0000FF00 ) >> 8 ) ; pDataFlash -> pDataFlashDesc -> command [ 3 ] = ( unsigned char ) ( adr & 0x000000FF ) ; pDataFlash -> pDataFlashDesc -> command [ 4 ] = 0 ; } pDataFlash -> pDataFlashDesc -> command [ 5 ] = 0 ; pDataFlash -> pDataFlashDesc -> command [ 6 ] = 0 ; pDataFlash -> pDataFlashDesc -> command [ 7 ] = 0 ; pDataFlash -> pDataFlashDesc -> tx_cmd_pt = pDataFlash -> pDataFlashDesc -> command ; pDataFlash -> pDataFlashDesc -> tx_cmd_size = CmdSize ; pDataFlash -> pDataFlashDesc -> rx_cmd_pt = pDataFlash -> pDataFlashDesc -> command ; pDataFlash -> pDataFlashDesc -> rx_cmd_size = CmdSize ; return AT91F_SpiWrite ( pDataFlash -> pDataFlashDesc ) ; }
\fn    AT91F_DataFlashSendCommand
\brief Generic function to send a command to the dataflash
\ fn AT91F_DataFlashSendCommand \ brief Generic function to send a command to the dataflash
/* process the address to obtain page address and byte address */ /* fill the  command  buffer */ /* Initialize the SpiData structure for the spi write fuction */