Mirror of CollapseOS
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

37 行
1.2KB

  1. #include <stdint.h>
  2. #include <stdbool.h>
  3. typedef struct {
  4. bool selected;
  5. // Initialization status. 0 == not woken 8 == woken 9 == CMD0 received
  6. // 10 == CMD8 received, 11 == CMD55 received, 12 == CMD41 received (fully
  7. // initialized).
  8. unsigned int initstat;
  9. // We receive commands into this buffer.
  10. uint8_t recvbuf[6];
  11. // Where the next SPI byte should be stored in recvbuf.
  12. unsigned int recvidx;
  13. // Buffer to the arguments for a response
  14. uint8_t sendbuf[5];
  15. // Index of the next byte from sendbuf we should return. If -1, buffer is
  16. // empty.
  17. int sendidx;
  18. // One byte response. When all other response buffers are empty, return
  19. // this.
  20. uint8_t resp;
  21. // File used for contents read/write
  22. FILE *fp;
  23. // number of bytes read into the current CMD17. -1 means no CMD17 active.
  24. int cmd17bytes;
  25. // number of bytes received for the current CMD24. -2 means no CMD24 active.
  26. // -1 means we're still waiting for the data token.
  27. int cmd24bytes;
  28. // running crc16 during read and write operations.
  29. uint16_t crc16;
  30. } SDC;
  31. void sdc_init(SDC *sdc);
  32. void sdc_ctl_wr(SDC *sdc, uint8_t val);
  33. void sdc_spi_wr(SDC *sdc, uint8_t val);
  34. uint8_t sdc_spi_rd(SDC *sdc);