mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-30 22:38:09 +11:00
1a6a549857
Working on programming AVR chips exposes a glaring omission in my first design of the SPI Relay: not allowing multiple devices make this task hard. I constantly have to unplug my SD card before, plug the AVR chip holder, then play a bit, then unplug the AVR holder, then replug the SD card... My prototype for a SPI relay design is built, but I haven't tested it yet. I need to adapt the code first, which is what I do here. When the prototype is tested, I'll update the SDC recipe with a new schema.
37 lines
1.2 KiB
C
37 lines
1.2 KiB
C
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
typedef struct {
|
|
bool selected;
|
|
// 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.
|
|
uint8_t recvbuf[6];
|
|
// Where the next SPI byte should be stored in recvbuf.
|
|
unsigned int recvidx;
|
|
// Buffer to the arguments for a response
|
|
uint8_t sendbuf[5];
|
|
// Index of the next byte from sendbuf we should return. If -1, buffer is
|
|
// empty.
|
|
int sendidx;
|
|
// One byte response. When all other response buffers are empty, return
|
|
// this.
|
|
uint8_t resp;
|
|
// File used for contents read/write
|
|
FILE *fp;
|
|
// number of bytes read into the current CMD17. -1 means no CMD17 active.
|
|
int cmd17bytes;
|
|
// 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;
|
|
// running crc16 during read and write operations.
|
|
uint16_t crc16;
|
|
} SDC;
|
|
|
|
void sdc_init(SDC *sdc);
|
|
void sdc_ctl_wr(SDC *sdc, uint8_t val);
|
|
void sdc_spi_wr(SDC *sdc, uint8_t val);
|
|
uint8_t sdc_spi_rd(SDC *sdc);
|