spi_flash.c (163533) | spi_flash.c (165400) |
---|---|
1/****************************************************************************** 2 * 3 * Filename: spi_flash.c 4 * 5 * Instantiation of SPI flash control routines supporting AT45DB161B 6 * 7 * Revision information: 8 * --- 5 unchanged lines hidden (view full) --- 14 * No warranty, expressed or implied, is included with this software. It is 15 * provided "AS IS" and no warranty of any kind including statutory or aspects 16 * relating to merchantability or fitness for any purpose is provided. All 17 * intellectual property rights of others is maintained with the respective 18 * owners. This software is not copyrighted and is intended for reference 19 * only. 20 * END_BLOCK 21 * | 1/****************************************************************************** 2 * 3 * Filename: spi_flash.c 4 * 5 * Instantiation of SPI flash control routines supporting AT45DB161B 6 * 7 * Revision information: 8 * --- 5 unchanged lines hidden (view full) --- 14 * No warranty, expressed or implied, is included with this software. It is 15 * provided "AS IS" and no warranty of any kind including statutory or aspects 16 * relating to merchantability or fitness for any purpose is provided. All 17 * intellectual property rights of others is maintained with the respective 18 * owners. This software is not copyrighted and is intended for reference 19 * only. 20 * END_BLOCK 21 * |
22 * $FreeBSD: head/sys/boot/arm/at91/libat91/spi_flash.c 163533 2006-10-20 09:12:05Z imp $ | 22 * $FreeBSD: head/sys/boot/arm/at91/libat91/spi_flash.c 165400 2006-12-20 18:25:16Z imp $ |
23 *****************************************************************************/ 24 25#include "at91rm9200.h" 26#include "spi_flash.h" 27#include "lib.h" 28 29/*********************** PRIVATE FUNCTIONS/DATA ******************************/ 30 --- 83 unchanged lines hidden (view full) --- 114 115 // determine page address 116 pageAddress = flash_addr / FLASH_PAGE_SIZE; 117 118 // determine byte address 119 byteAddress = flash_addr % FLASH_PAGE_SIZE; 120 121 p_memset(tx_commandBuffer, 0, 8); | 23 *****************************************************************************/ 24 25#include "at91rm9200.h" 26#include "spi_flash.h" 27#include "lib.h" 28 29/*********************** PRIVATE FUNCTIONS/DATA ******************************/ 30 --- 83 unchanged lines hidden (view full) --- 114 115 // determine page address 116 pageAddress = flash_addr / FLASH_PAGE_SIZE; 117 118 // determine byte address 119 byteAddress = flash_addr % FLASH_PAGE_SIZE; 120 121 p_memset(tx_commandBuffer, 0, 8); |
122#ifdef BOOT_BWCT 123 tx_commandBuffer[0] = 0xd2; 124 tx_commandBuffer[1] = ((pageAddress >> 6) & 0xFF); 125 tx_commandBuffer[2] = ((pageAddress << 2) & 0xFC) | 126 ((byteAddress >> 8) & 0x3); 127 tx_commandBuffer[3] = byteAddress & 0xFF; 128 spi_command.tx_cmd = tx_commandBuffer; 129 spi_command.tx_cmd_size = 8; 130 spi_command.tx_data_size = size; 131 spi_command.tx_data = dest_addr; 132 133 p_memset(rx_commandBuffer, 0, 8); 134 spi_command.rx_cmd = rx_commandBuffer; 135 spi_command.rx_cmd_size = 8; 136 spi_command.rx_data_size = size; 137 spi_command.rx_data = dest_addr; 138#else |
|
122 tx_commandBuffer[0] = CONTINUOUS_ARRAY_READ_HF; 123 tx_commandBuffer[1] = ((pageAddress >> 5) & 0xFF); 124 tx_commandBuffer[2] = ((pageAddress << 3) & 0xF8) | 125 ((byteAddress >> 8) & 0x7); 126 tx_commandBuffer[3] = byteAddress & 0xFF; 127 spi_command.tx_cmd = tx_commandBuffer; 128 spi_command.tx_cmd_size = 5; 129 spi_command.tx_data_size = size; 130 spi_command.tx_data = dest_addr; 131 132 p_memset(rx_commandBuffer, 0, 8); 133 spi_command.rx_cmd = rx_commandBuffer; 134 spi_command.rx_cmd_size = 5; 135 spi_command.rx_data_size = size; 136 spi_command.rx_data = dest_addr; | 139 tx_commandBuffer[0] = CONTINUOUS_ARRAY_READ_HF; 140 tx_commandBuffer[1] = ((pageAddress >> 5) & 0xFF); 141 tx_commandBuffer[2] = ((pageAddress << 3) & 0xF8) | 142 ((byteAddress >> 8) & 0x7); 143 tx_commandBuffer[3] = byteAddress & 0xFF; 144 spi_command.tx_cmd = tx_commandBuffer; 145 spi_command.tx_cmd_size = 5; 146 spi_command.tx_data_size = size; 147 spi_command.tx_data = dest_addr; 148 149 p_memset(rx_commandBuffer, 0, 8); 150 spi_command.rx_cmd = rx_commandBuffer; 151 spi_command.rx_cmd_size = 5; 152 spi_command.rx_data_size = size; 153 spi_command.rx_data = dest_addr; |
154#endif |
|
137 138 SendCommand(&spi_command); 139} 140 141 142/* 143 * .KB_C_FN_DEFINITION_START 144 * void SPI_WriteFlash(unsigned flash_addr, unsigned src_addr, unsigned size) --- 9 unchanged lines hidden (view full) --- 154 155 // determine page address 156 pageAddress = flash_addr / FLASH_PAGE_SIZE; 157 158 // determine byte address 159 byteAddress = flash_addr % FLASH_PAGE_SIZE; 160 161 p_memset(tx_commandBuffer, 0, 8); | 155 156 SendCommand(&spi_command); 157} 158 159 160/* 161 * .KB_C_FN_DEFINITION_START 162 * void SPI_WriteFlash(unsigned flash_addr, unsigned src_addr, unsigned size) --- 9 unchanged lines hidden (view full) --- 172 173 // determine page address 174 pageAddress = flash_addr / FLASH_PAGE_SIZE; 175 176 // determine byte address 177 byteAddress = flash_addr % FLASH_PAGE_SIZE; 178 179 p_memset(tx_commandBuffer, 0, 8); |
180#ifdef BOOT_BWCT 181 tx_commandBuffer[0] = 0x82; 182 tx_commandBuffer[1] = ((pageAddress >> 6) & 0xFF); 183 tx_commandBuffer[2] = ((pageAddress << 2) & 0xFC) | 184 ((byteAddress >> 8) & 0x3); 185 tx_commandBuffer[3] = (byteAddress & 0xFF); 186#else |
|
162 tx_commandBuffer[0] = PROGRAM_THROUGH_BUFFER; 163 tx_commandBuffer[1] = ((pageAddress >> 5) & 0xFF); 164 tx_commandBuffer[2] = ((pageAddress << 3) & 0xF8) | 165 ((byteAddress >> 8) & 0x7); 166 tx_commandBuffer[3] = (byteAddress & 0xFF); | 187 tx_commandBuffer[0] = PROGRAM_THROUGH_BUFFER; 188 tx_commandBuffer[1] = ((pageAddress >> 5) & 0xFF); 189 tx_commandBuffer[2] = ((pageAddress << 3) & 0xF8) | 190 ((byteAddress >> 8) & 0x7); 191 tx_commandBuffer[3] = (byteAddress & 0xFF); |
192#endif |
|
167 168 p_memset(rx_commandBuffer, 0, 8); 169 170 spi_command.tx_cmd = tx_commandBuffer; 171 spi_command.rx_cmd = rx_commandBuffer; 172 spi_command.rx_cmd_size = 4; 173 spi_command.tx_cmd_size = 4; 174 --- 53 unchanged lines hidden (view full) --- 228 pSPI->SPI_PTCR = AT91C_PDC_TXTEN; 229 230 value = pSPI->SPI_RDR; 231 value = pSPI->SPI_SR; 232 233 // Increment real time counter every SLCK 234 AT91C_BASE_ST->ST_RTMR = 1; 235 | 193 194 p_memset(rx_commandBuffer, 0, 8); 195 196 spi_command.tx_cmd = tx_commandBuffer; 197 spi_command.rx_cmd = rx_commandBuffer; 198 spi_command.rx_cmd_size = 4; 199 spi_command.tx_cmd_size = 4; 200 --- 53 unchanged lines hidden (view full) --- 254 pSPI->SPI_PTCR = AT91C_PDC_TXTEN; 255 256 value = pSPI->SPI_RDR; 257 value = pSPI->SPI_SR; 258 259 // Increment real time counter every SLCK 260 AT91C_BASE_ST->ST_RTMR = 1; 261 |
262#ifdef BOOT_BWCT 263 if (((value = GetFlashStatus()) & 0xFC) != 0xB4) 264 printf(" Bad SPI status: 0x%x\n", value); 265#else |
|
236 if (((value = GetFlashStatus()) & 0xFC) != 0xBC) 237 printf(" Bad SPI status: 0x%x\n", value); | 266 if (((value = GetFlashStatus()) & 0xFC) != 0xBC) 267 printf(" Bad SPI status: 0x%x\n", value); |
268#endif |
|
238} | 269} |