PERFORCE change 96666 for review

Warner Losh imp at FreeBSD.org
Thu May 4 20:10:31 UTC 2006


http://perforce.freebsd.org/chv.cgi?CH=96666

Change 96666 by imp at imp_hammer on 2006/05/04 20:09:44

	Make spi write flash function simpler.

Affected files ...

.. //depot/projects/arm/src/sys/boot/arm/at91/libat91/spi_flash.c#12 edit

Differences ...

==== //depot/projects/arm/src/sys/boot/arm/at91/libat91/spi_flash.c#12 (text+ko) ====

@@ -96,47 +96,6 @@
 	while (!(GetFlashStatus() & 0x80)) ;
 }
 
-
-/*
- * .KB_C_FN_DEFINITION_START
- * void ProgramBuffer(unsigned pageAddress, unsigned byteAddress,
- *			 unsigned src_addr, unsigned size);
- *  Private function to program Flash through the buffer.  Note this
- * will corrupt any data on the same page not intended for modification.
- * To preserve this data, read it first, modify it in RAM, then write back
- * data in FLASH_PAGE_SIZE intervals.  This also corrupts the data in RAM.
- * .KB_C_FN_DEFINITION_END
- */
-static void
-ProgramBuffer(unsigned pageAddress, unsigned byteAddress,
-    char *src_addr, unsigned size)
-{
-
-	p_memset(tx_commandBuffer, 0, 8);
-	tx_commandBuffer[0] = PROGRAM_THROUGH_BUFFER;
-//	tx_commandBuffer[0] = 0x84;	// write buffer 1
-	tx_commandBuffer[1] = ((pageAddress >> 5) & 0xFF);
-	tx_commandBuffer[2] = ((pageAddress << 3) & 0xF8) |
-				((byteAddress >> 8) & 0x7);
-	tx_commandBuffer[3] = (byteAddress & 0xFF);
-
-	p_memset(rx_commandBuffer, 0, 8);
-
-	spi_command.tx_cmd = tx_commandBuffer;
-	spi_command.rx_cmd = rx_commandBuffer;
-	spi_command.rx_cmd_size = 4;
-	spi_command.tx_cmd_size = 4;
-
-	spi_command.tx_data_size = size;
-	spi_command.tx_data = src_addr;
-	spi_command.rx_data_size = size;
-	spi_command.rx_data = src_addr;
-
-	SendCommand(&spi_command);
-
-	WaitForDeviceReady();
-}
-
 /*************************** GLOBAL FUNCTIONS ********************************/
 
 
@@ -190,7 +149,7 @@
 void
 SPI_WriteFlash(unsigned flash_addr, char *src_addr, unsigned size)
 {
-	unsigned	pageAddress, byteAddress, this_size;
+	unsigned	pageAddress, byteAddress;
 
 	// determine page address
 	pageAddress = flash_addr / FLASH_PAGE_SIZE;
@@ -198,20 +157,28 @@
 	// determine byte address
 	byteAddress = flash_addr % FLASH_PAGE_SIZE;
 
-	while (size) {
+	p_memset(tx_commandBuffer, 0, 8);
+	tx_commandBuffer[0] = PROGRAM_THROUGH_BUFFER;
+	tx_commandBuffer[1] = ((pageAddress >> 5) & 0xFF);
+	tx_commandBuffer[2] = ((pageAddress << 3) & 0xF8) |
+				((byteAddress >> 8) & 0x7);
+	tx_commandBuffer[3] = (byteAddress & 0xFF);
+
+	p_memset(rx_commandBuffer, 0, 8);
+
+	spi_command.tx_cmd = tx_commandBuffer;
+	spi_command.rx_cmd = rx_commandBuffer;
+	spi_command.rx_cmd_size = 4;
+	spi_command.tx_cmd_size = 4;
 
-		this_size = FLASH_PAGE_SIZE - byteAddress;
-		if (this_size > size)
-			this_size = size;
+	spi_command.tx_data_size = size;
+	spi_command.tx_data = src_addr;
+	spi_command.rx_data_size = size;
+	spi_command.rx_data = src_addr;
 
-		// write through buffer to flash
-		ProgramBuffer(pageAddress, byteAddress, src_addr, this_size);
+	SendCommand(&spi_command);
 
-		size -= this_size;
-		src_addr += this_size;
-		byteAddress = 0;
-		++pageAddress;
-	}
+	WaitForDeviceReady();
 }
 
 /*
@@ -266,5 +233,5 @@
 	AT91C_BASE_ST->ST_RTMR = 1;
 
 	if (((value = GetFlashStatus()) & 0xFC) != 0xBC)
-		printf(" Unexpected SPI flash status: 0x%x\r\n", value);
+		printf(" Bad SPI status: 0x%x\r\n", value);
 }


More information about the p4-projects mailing list