mirror of
				https://github.com/openhwgroup/cvw
				synced 2025-02-11 06:05:49 +00:00 
			
		
		
		
	Added inital spi based sd card code. Working on CRC7 code that works.
This commit is contained in:
		
							parent
							
								
									53b2a51c89
								
							
						
					
					
						commit
						c7d869bc96
					
				
							
								
								
									
										31
									
								
								fpga/zsbl/sd.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								fpga/zsbl/sd.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					#include "sd.h"
 | 
				
			||||||
 | 
					#include "spi.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					uint8_t crc7(uint8_t prev, uint8_t in) {
 | 
				
			||||||
 | 
					    // CRC polynomial 0x89
 | 
				
			||||||
 | 
					    uint8_t remainder = prev & in;
 | 
				
			||||||
 | 
					    remainder ^= (remainder >> 4) ^ (remainder >> 7);
 | 
				
			||||||
 | 
					    remainder ^= remainder << 4;
 | 
				
			||||||
 | 
					    return remainder & 0x7f;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					uint16_t crc16(uint16_t crc, uint8_t data) {
 | 
				
			||||||
 | 
					    // CRC polynomial 0x11021
 | 
				
			||||||
 | 
					    crc = (uint8_t)(crc >> 8) | (crc << 8);
 | 
				
			||||||
 | 
					    crc ^= data;
 | 
				
			||||||
 | 
					    crc ^= (uint8_t)(crc >> 4) & 0xf;
 | 
				
			||||||
 | 
					    crc ^= crc << 12;
 | 
				
			||||||
 | 
					    crc ^= (crc & 0xff) << 5;
 | 
				
			||||||
 | 
					    return crc;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					uint8_t sd_cmd(uint8_t cmd, uint32_t arg, uint8_t crc) {
 | 
				
			||||||
 | 
					  spi_send_byte
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void init_sd(){
 | 
				
			||||||
 | 
					  init_spi();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										9
									
								
								fpga/zsbl/sd.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								fpga/zsbl/sd.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdint.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					uint8_t crc7(uint8_t prev, uint8_t in);
 | 
				
			||||||
 | 
					uint16_t crc16(uint16_t crc, uint8_t data);
 | 
				
			||||||
 | 
					uint8_t sd_cmd(uint8_t cmd, uint32_t arg, uint8_t crc);
 | 
				
			||||||
 | 
					void init_sd();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -48,4 +48,3 @@ uint8_t spi_send_byte(uint8_t byte) {
 | 
				
			|||||||
  return result;
 | 
					  return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -40,6 +40,7 @@
 | 
				
			|||||||
void write_reg(uintptr_t addr, uint32_t value);
 | 
					void write_reg(uintptr_t addr, uint32_t value);
 | 
				
			||||||
uint32_t read_reg(uintptr_t addr);
 | 
					uint32_t read_reg(uintptr_t addr);
 | 
				
			||||||
uint8_t spi_send_byte(uint8_t byte);
 | 
					uint8_t spi_send_byte(uint8_t byte);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void spi_init();
 | 
					void spi_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user