Added inital spi based sd card code. Working on CRC7 code that works.

This commit is contained in:
Jacob Pease 2024-07-20 14:00:43 -05:00
parent 53b2a51c89
commit c7d869bc96
4 changed files with 41 additions and 1 deletions

31
fpga/zsbl/sd.c Normal file
View 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
View 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();

View file

@ -48,4 +48,3 @@ uint8_t spi_send_byte(uint8_t byte) {
return result;
}

View file

@ -40,6 +40,7 @@
void write_reg(uintptr_t addr, uint32_t value);
uint32_t read_reg(uintptr_t addr);
uint8_t spi_send_byte(uint8_t byte);
void spi_init();
#endif