From owner-p4-projects@FreeBSD.ORG Thu May 4 20:10:31 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 9ACAD16A404; Thu, 4 May 2006 20:10:31 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 488C616A401 for ; Thu, 4 May 2006 20:10:31 +0000 (UTC) (envelope-from imp@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0E89A43D45 for ; Thu, 4 May 2006 20:10:31 +0000 (GMT) (envelope-from imp@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id k44KAUpj073499 for ; Thu, 4 May 2006 20:10:30 GMT (envelope-from imp@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id k44KAUSS073493 for perforce@freebsd.org; Thu, 4 May 2006 20:10:30 GMT (envelope-from imp@freebsd.org) Date: Thu, 4 May 2006 20:10:30 GMT Message-Id: <200605042010.k44KAUSS073493@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to imp@freebsd.org using -f From: Warner Losh To: Perforce Change Reviews Cc: Subject: PERFORCE change 96666 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 May 2006 20:10:31 -0000 http://perforce.freebsd.org/chv.cgi?CH=96666 Change 96666 by imp@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); }