2020-10-30 06:01:25 +11:00
|
|
|
#include "emul.h"
|
2020-04-18 05:11:32 +10:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
// Initialization status. 0 == not woken 8 == woken 9 == CMD0 received
|
|
|
|
// 10 == CMD8 received, 11 == CMD55 received, 12 == CMD41 received (fully
|
|
|
|
// initialized).
|
|
|
|
unsigned int initstat;
|
|
|
|
// We receive commands into this buffer.
|
2020-10-30 06:01:25 +11:00
|
|
|
byte recvbuf[6];
|
2020-04-18 05:11:32 +10:00
|
|
|
// Where the next SPI byte should be stored in recvbuf.
|
|
|
|
unsigned int recvidx;
|
|
|
|
// Buffer to the arguments for a response
|
2020-10-30 06:01:25 +11:00
|
|
|
byte sendbuf[5];
|
2020-04-18 05:11:32 +10:00
|
|
|
// Index of the next byte from sendbuf we should return. If -1, buffer is
|
|
|
|
// empty.
|
|
|
|
int sendidx;
|
2020-04-18 09:10:22 +10:00
|
|
|
// File used for contents read/write
|
|
|
|
FILE *fp;
|
|
|
|
// number of bytes read into the current CMD17. -1 means no CMD17 active.
|
|
|
|
int cmd17bytes;
|
2020-04-18 10:19:55 +10:00
|
|
|
// number of bytes received for the current CMD24. -2 means no CMD24 active.
|
|
|
|
// -1 means we're still waiting for the data token.
|
|
|
|
int cmd24bytes;
|
2020-04-18 09:10:22 +10:00
|
|
|
// running crc16 during read and write operations.
|
|
|
|
uint16_t crc16;
|
2020-04-18 05:11:32 +10:00
|
|
|
} SDC;
|
|
|
|
|
|
|
|
void sdc_init(SDC *sdc);
|
2020-10-30 06:01:25 +11:00
|
|
|
byte sdc_spix(SDC *sdc, byte val);
|