Files
Matthias Blankertz 0bc4815926 - Debugged SPI module
- Debugged UART
- Firmware support for SPI, UART
- Work on SD/MMC support in firmware
- Debugged mblite core/WB interface
2013-06-08 11:53:27 +02:00

93 lines
1.7 KiB
C

// Copyright (c) 2013 Matthias Blankertz <matthias@blankertz.org>
#include <stdbool.h>
#include "spi.h"
#include "sd.h"
#include "util.h"
bool sd_por() {
// Send '1' for 80 cycles
spi_set_ss(true);
for(int i = 0;i < 10;++i)
spi_xmit(0xff);
spi_set_ss(false);
return true;
}
unsigned char sd_cmd(unsigned char cmd, unsigned param) {
spi_xmit(0x40 | cmd);
spi_xmit(param>>24);
spi_xmit(param>>16);
spi_xmit(param>>8);
spi_xmit(param&0xff);
spi_xmit(cmd==0?0x95:(cmd==41?0xe5:0x01));
unsigned char tmp;
int i = 0;
while(((tmp=spi_xmit(0xff))&0x80) && (i++<=8)) {
}
const char *s = utox(tmp);
uart_writes("0x");
uart_writes(s);
uart_writeb(' ');
return tmp;
}
unsigned char sd_acmd(unsigned char cmd, unsigned param) {
spi_xmit(0x77);
/* spi_xmit(0x00); */
/* spi_xmit(0x00); */
/* spi_xmit(0x00); */
/* spi_xmit(0x00); */
/* spi_xmit(0x95); */
spi_xmit(0x40 | cmd);
spi_xmit(param>>24);
spi_xmit(param>>16);
spi_xmit(param>>8);
spi_xmit(param&0xff);
spi_xmit(0x95);
unsigned char tmp;
int i = 0;
while(((tmp=spi_xmit(0xff))&0x80) && (i++<=8)) {
}
const char *s = utox(tmp);
uart_writes("0x");
uart_writes(s);
uart_writeb(' ');
return tmp;
}
unsigned char sd_cmd_r7(unsigned char cmd, unsigned param, unsigned *resp) {
spi_xmit(0x40 | cmd);
spi_xmit(param>>24);
spi_xmit(param>>16);
spi_xmit(param>>8);
spi_xmit(param&0xff);
spi_xmit(0x95);
unsigned char tmp;
int i = 0;
while(((tmp=spi_xmit(0xff))&0x80) && (i++<=8)) {
}
const char *s = utox(tmp);
uart_writes("0x");
uart_writes(s);
uart_writeb(' ');
if(tmp != 0xff) {
*resp = 0;
for(int i = 0;i < 4;++i) {
*resp <<= 8;
*resp |= spi_xmit(0xff);
}
}
return tmp;
}