mirror of
				https://github.com/openhwgroup/cvw
				synced 2025-02-11 06:05:49 +00:00 
			
		
		
		
	Progress made on implementing new disk read function.
This commit is contained in:
		
							parent
							
								
									9ccb0eb027
								
							
						
					
					
						commit
						57eeba5c8c
					
				| @ -1,6 +1,9 @@ | ||||
| #include <stddef.h> | ||||
| #include "boot.h" | ||||
| #include "gpt.h" | ||||
| #include "uart.h" | ||||
| #include "spi.h" | ||||
| #include "sd.h" | ||||
| 
 | ||||
| /* int disk_read(BYTE * buf, LBA_t sector, UINT count, BYTE card_type) { */ | ||||
| 
 | ||||
| @ -32,7 +35,27 @@ | ||||
| /* } */ | ||||
| 
 | ||||
| int disk_read(BYTE * buf, LBA_t sector, UINT count) { | ||||
|   uint64_t r; | ||||
|   UINT i; | ||||
|    | ||||
|   uint8_t crc = 0; | ||||
|   crc = crc7(crc, 0x40 | SD_CMD_READ_BLOCK_MULTIPLE); | ||||
|   crc = crc7(crc, (sector >> 24) & 0xff); | ||||
|   crc = crc7(crc, (sector >> 16) & 0xff); | ||||
|   crc = crc7(crc, (sector >> 8) & 0xff); | ||||
|   crc = crc7(crc, sector & 0xff); | ||||
|   crc = crc | 1; | ||||
|    | ||||
|   if (sd_cmd(18, sector &, crc) != 0x00) { | ||||
|     print_uart("disk_read: CMD18 failed. r = "); | ||||
|     print_byte(r & 0xff); | ||||
|     return -1; | ||||
|   } | ||||
| 
 | ||||
|   // Begin reading 
 | ||||
|   for (i = 0; i < count; i++) { | ||||
|      | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| // copyFlash: --------------------------------------------------------
 | ||||
| @ -48,7 +71,7 @@ void copyFlash(QWORD address, QWORD * Dst, DWORD numBlocks) { | ||||
|   // Print the wally banner
 | ||||
|   print_uart(BANNER); | ||||
| 
 | ||||
|    | ||||
|   // Intialize the SD card
 | ||||
|   init_sd(); | ||||
|    | ||||
|   ret = gpt_load_partitions(card_type); | ||||
|  | ||||
| @ -99,6 +99,7 @@ uint64_t sd_cmd(uint8_t cmd, uint32_t arg, uint8_t crc) { | ||||
|   return r; | ||||
| } // sd_cmd
 | ||||
| 
 | ||||
| 
 | ||||
| // Utility defines for CMD0, CMD8, CMD55, and ACMD41
 | ||||
| #define CMD0()   sd_cmd( 0, 0x00000000, 0x95) // Reset SD card into IDLE state
 | ||||
| #define CMD8()   sd_cmd( 8, 0x000001aa, 0x87) // 
 | ||||
|  | ||||
| @ -58,6 +58,24 @@ inline void waitrx() { | ||||
|   while(read_reg(SPI_IP) & 2)) {} | ||||
| } | ||||
| 
 | ||||
| uint64_t spi_read64() { | ||||
|   uint64_t r; | ||||
|   uint8_t rbyte; | ||||
|   int i; | ||||
| 
 | ||||
|   for (i = 0; i < 8; i++) { | ||||
|     spi_sendbyte(0xFF); | ||||
|   } | ||||
| 
 | ||||
|   waittx(); | ||||
| 
 | ||||
|   for (i = 0; i < 8; i++) { | ||||
|     rbyte = spi_readbyte(); | ||||
|     r = r | (rbyte << ((8 - 1 - i)*8)); | ||||
|   } | ||||
| 
 | ||||
|   return r; | ||||
| } | ||||
| 
 | ||||
| // Initialize Sifive FU540 based SPI Controller
 | ||||
| void spi_init() { | ||||
|  | ||||
| @ -55,7 +55,7 @@ inline void waittx(); | ||||
| inline void waitrx(); | ||||
| uint8_t spi_txrx(uint8_t byte); | ||||
| inline uint8_t spi_readbyte(); | ||||
| 
 | ||||
| uint64_t spi_read64(); | ||||
| void spi_init(); | ||||
| 
 | ||||
| #endif | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user