ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
mmc.c
Go to the documentation of this file.
1 
9 /*-----------------------------------------------------------------------*/
10 /* MMCv3/SDv1/SDv2 Controls via AVR SPI module */
11 /*-----------------------------------------------------------------------*/
12 /*
13 / Copyright (C) 2016, ChaN, all right reserved.
14 /
15 / * This software is a free software and there is NO WARRANTY.
16 / * No restriction on use. You can use, modify and redistribute it for
17 / any purpose as you like UNDER YOUR RESPONSIBILITY.
18 / * Redistributions of source code must retain the above copyright notice.
19 /
20 /-------------------------------------------------------------------------*/
21 
22 /* mmc.c */
23 #include "user_config.h"
24 #include "mmc_hal.h"
25 
26 #ifdef AVR
27 #include <stdlib.h>
28 #endif
29 
30 #include "printf/mathio.h"
31 
32 #ifdef ESP8266
33 #include "esp8266/hspi.h"
34 #endif
35 
36 #include "fatfs.sup/fatfs.h"
37 
38 /* Peripheral controls (Platform dependent) */
39 #define CS_LOW() mmc_spi_begin() /* Set MMC_CS = low */
40 #define CS_HIGH() mmc_spi_end() /* Set MMC_CS = high */
41 
42 #define MMC_CD mmc_ins_status() /* Test if card detected. yes:true, no:false, default:true */
43 #define MMC_WP mmc_wp_status() /* Test if write protected. yes:true, no:false, default:false */
44 #define FCLK_SLOW() mmc_slow() /* Set SPI slow clock (100-400kHz) */
45 #define FCLK_FAST() mmc_fast() /* Set SPI fast clock (20MHz max) */
46 
47 /*--------------------------------------------------------------------------
48 
49  Module Private Functions
50 
51 ---------------------------------------------------------------------------*/
52 
53 /* Definitions for MMC/SDC command */
54 #define CMD0 (0) /* GO_IDLE_STATE */
55 #define CMD1 (1) /* SEND_OP_COND (MMC) */
56 #define ACMD41 (0x80+41) /* SEND_OP_COND (SDC) */
57 #define CMD8 (8) /* SEND_IF_COND */
58 #define CMD9 (9) /* SEND_CSD */
59 #define CMD10 (10) /* SEND_CID */
60 #define CMD12 (12) /* STOP_TRANSMISSION */
61 #define ACMD13 (0x80+13) /* SD_STATUS (SDC) */
62 #define CMD16 (16) /* SET_BLOCKLEN */
63 #define CMD17 (17) /* READ_SINGLE_BLOCK */
64 #define CMD18 (18) /* READ_MULTIPLE_BLOCK */
65 #define CMD23 (23) /* SET_BLOCK_COUNT (MMC) */
66 #define ACMD23 (0x80+23) /* SET_WR_BLK_ERASE_COUNT (SDC) */
67 #define CMD24 (24) /* WRITE_BLOCK */
68 #define CMD25 (25) /* WRITE_MULTIPLE_BLOCK */
69 #define CMD32 (32) /* ERASE_ER_BLK_START */
70 #define CMD33 (33) /* ERASE_ER_BLK_END */
71 #define CMD38 (38) /* ERASE */
72 #define CMD48 (48) /* READ_EXTR_SINGLE */
73 #define CMD49 (49) /* WRITE_EXTR_SINGLE */
74 #define CMD55 (55) /* APP_CMD */
75 #define CMD58 (58) /* READ_OCR */
76 
77 
78 volatile
79 DSTATUS Stat = STA_NOINIT; /* <Disk status */
80 
81 static volatile
82 BYTE Timer1, Timer2; /* 100Hz decrement timer */
83 
84 static
85 BYTE CardType; /*< Card type flags */
86 
87 /*-----------------------------------------------------------------------*/
88 /* Power Control (Platform dependent) */
89 /*-----------------------------------------------------------------------*/
90 /* When the target system does not support socket power control, there */
91 /* is nothing to do in these functions and chk_power always returns 1. */
92 
96 static
97 void power_on (void)
98 {
99  /* Turn socket power on and wait for 10ms+ (nothing to do if no power controls) */
100  /* Configure MOSI/MISO/SCLK/CS pins */
101  /* Enable SPI module in SPI mode 0 */
102  mmc_power_on();
103 }
104 
105 
108 MEMSPACE
109 static
110 void power_off (void)
111 {
112  /* Disable SPI function */
113  /* De-configure MOSI/MISO/SCLK/CS pins (set hi-z) */
114  /* Turn socket power off (nothing to do if no power controls) */
115  mmc_power_off();
116 }
117 
118 /*-----------------------------------------------------------------------*/
119 /* Transmit/Receive data from/to MMC via SPI (Platform dependent) */
120 /*-----------------------------------------------------------------------*/
121 
125 static
126 BYTE xchg_spi ( /* Returns received data */
127  BYTE dat /* Data to be sent */
128 )
129 {
130  dat = mmc_spi_TXRX(dat);
131  return dat;
132 }
133 
138 static
140  BYTE *p, /* Data read buffer */
141  UINT cnt /* Size of data block */
142 )
143 {
144  mmc_spi_RX_buffer((uint8_t *)p, cnt);
145 }
146 
151 static
153  const BYTE *p, /* Data block to be sent */
154  UINT cnt /* Size of data block */
155 )
156 {
157  mmc_spi_TX_buffer((uint8_t *)p, cnt);
158 }
159 
160 
161 
162 
163 // =============================================
168 MEMSPACE
170 UINT wt /*< Timeout [ms] */
171 )
172 {
173  BYTE d;
174  // Timer2 = wt / 10;
175  mmc_set_ms_timeout(wt);
176  do
177  d = xchg_spi(0xFF);
178  while (d != 0xFF && !mmc_test_timeout());
179  //while (d != 0xFF && Timer2);
180 
181  return (d == 0xFF) ? 1 : 0;
182 }
183 
184 
187 MEMSPACE
188 static
189 void deselect (void)
190 {
191  CS_HIGH();
192  xchg_spi(0xFF); /*< Dummy clock (force DO hi-z for multiple slave SPI) */
193  xchg_spi(0xFF); /*< Dummy clock (force DO hi-z for multiple slave SPI) */
194 }
195 
196 
200 MEMSPACE
201 static
202 int select (void)
203 {
204  CS_LOW();
205  xchg_spi(0xFF); /* Dummy clock (force DO enabled) */
206 
207  if (wait_ready(1000))
208  return 1; /* OK */
209 
210  printf("select failed!\n");
211 
212  deselect();
213  return 0; /* Timeout */
214 }
215 
216 
222 MEMSPACE
223 static
225 BYTE *buff, /*< Data buffer to store received data */
226 UINT btr /*< Byte count (must be multiple of 4) */
227 )
228 {
229  BYTE token;
230 
231  //Timer1 = 40;
232  mmc_set_ms_timeout(1000);
233  do /* Wait for data packet in timeout of 400ms */
234  {
235  token = xchg_spi(0xFF);
236  } while ((token == 0xFF) && !mmc_test_timeout());
237  //while ((token == 0xFF) && Timer1);
238  if (token != 0xFE) return 0; /* If not valid data token, retutn with error */
239 
240  rcvr_spi_multi(buff, btr); /* Receive the data block into buffer */
241  xchg_spi(0xFF); /* Discard CRC */
242  xchg_spi(0xFF);
243 
244  return 1; /* Return with success */
245 }
246 
247 
253 #if _USE_WRITE
254 MEMSPACE
255 static
256 int xmit_datablock (
257 const BYTE *buff, /*< 512 byte data block to be transmitted */
258 BYTE token /*< Data/Stop token */
259 )
260 {
261  BYTE resp;
262 
263  if (!wait_ready(1000)) return 0;
264 
265  xchg_spi(token); /* Xmit data token */
266  if (token != 0xFD) /* Is data token */
267  {
268  xmit_spi_multi(buff, 512); /* Xmit the data block to the MMC */
269 
270  xchg_spi(0xFF); /* CRC (Dummy) */
271  xchg_spi(0xFF);
272  resp = xchg_spi(0xFF); /* Reveive data response */
273  if ((resp & 0x1F) != 0x05) /* If not accepted, return with error */
274  return 0;
275  }
276 
277  return 1;
278 }
279 #endif // ifdef _USE_WRITE
280 
286 MEMSPACE
287 static
289 BYTE cmd, /*< Command index */
290 DWORD arg /*< Argument */
291 )
292 {
293  BYTE n, res;
294 
295  if (cmd & 0x80) /* ACMD<n> is the command sequense of CMD55-CMD<n> */
296  {
297  cmd &= 0x7F;
298  res = send_cmd(CMD55, 0);
299  if (res > 1) return res;
300  }
301 
302 /* Select the card and wait for ready except to stop multiple block read */
303  if (cmd != CMD12)
304  {
305  deselect();
306  if (!select()) return 0xFF;
307  }
308 
309 /* Send command packet */
310  xchg_spi(0x40 | cmd); /* Start + Command index */
311  xchg_spi((BYTE)(arg >> 24)); /* Argument[31..24] */
312  xchg_spi((BYTE)(arg >> 16)); /* Argument[23..16] */
313  xchg_spi((BYTE)(arg >> 8)); /* Argument[15..8] */
314  xchg_spi((BYTE)arg); /* Argument[7..0] */
315  n = 0x01; /* Dummy CRC + Stop */
316  if (cmd == CMD0) n = 0x95; /* Valid CRC for CMD0(0) + Stop */
317  if (cmd == CMD8) n = 0x87; /* Valid CRC for CMD8(0x1AA) Stop */
318 
319  xchg_spi(n);
320 
321 /* Receive command response */
322  if (cmd == CMD12) xchg_spi(0xFF); /* Skip a stuff byte when stop reading */
323  n = 10; /* Wait for a valid response in timeout of 10 attempts */
324  do
325  {
326  res = xchg_spi(0xFF);
327  }
328  while ((res & 0x80) && --n);
329 
330  return res; /* Return with the response value */
331 }
332 
333 
335 
336 
339 MEMSPACE
341 {
342  BYTE n, cmd, ty, ocr[4];
343 
344  //for (Timer1 = 10; Timer1; ) ; /* Wait for 100ms */
345  if (Stat & STA_NODISK) return Stat; /* No card in the socket */
346 
347  FCLK_SLOW();
348 
349  for (n = 10; n; n--) xchg_spi(0xFF); /* 80 dummy clocks */
350 
351  ty = 0;
352  if (send_cmd(CMD0, 0) == 1) /* Enter Idle state */
353  {
354  //Timer1=100; /* Initialization timeout of 1000 msec */
355  mmc_set_ms_timeout(2000); /* Initialization timeout of 1000 msec */
356  if (send_cmd(CMD8, 0x1AA) == 1) /* SDv2? */
357  {
358  for (n = 0; n < 4; n++)
359  ocr[n] = xchg_spi(0xFF); /* Get trailing return value of R7 resp */
360  if (ocr[2] == 0x01 && ocr[3] == 0xAA) /* The card can work at vdd range of 2.7-3.6V */
361  {
362  /* Wait for leaving idle state (ACMD41 with HCS bit) */
363  //while (Timer1 && send_cmd(ACMD41, 1UL << 30))
364  while (!mmc_test_timeout() && send_cmd(ACMD41, 1UL << 30))
365  ;
366  /* Check CCS bit in the OCR */
367  //if (Timer1 && send_cmd(CMD58, 0) == 0)
368  if (!mmc_test_timeout() && send_cmd(CMD58, 0) == 0)
369  {
370  for (n = 0; n < 4; n++)
371  ocr[n] = xchg_spi(0xFF);
372  /* Check if the card is SDv2 */
373  ty = (ocr[0] & 0x40) ? CT_SD2 | CT_BLOCK : CT_SD2;
374  }
375  }
376  }
377  else
378  { /* SDv1 or MMCv3 */
379  mmc_set_ms_timeout(2000); /* Initialization timeout of 1000 msec */
380  if (send_cmd(ACMD41, 0) <= 1)
381  {
382  ty = CT_SD1; cmd = ACMD41; /* SDv1 */
383  }
384  else
385  {
386  ty = CT_MMC; cmd = CMD1; /* MMCv3 */
387  }
388  /* Wait for leaving idle state */
389  //while (Timer1 && send_cmd(cmd, 0))
390  while (!mmc_test_timeout() && send_cmd(cmd, 0))
391  ;
392  /* Set R/W block length to 512 */
393  //if (!Timer1 || send_cmd(CMD16, 512) != 0)
394  if (mmc_test_timeout() || send_cmd(CMD16, 512) != 0)
395  ty = 0;
396  }
397  }
398 
399  CardType = ty;
400  deselect();
401 
402  if (ty) /* Initialization succeded */
403  {
404  Stat &= ~STA_NOINIT; /* Clear STA_NOINIT */
405  FCLK_FAST();
406  } /* Initialization failed */
407  else
408  {
409  power_off();
410  }
411 
412  return Stat;
413 }
414 
415 
419 MEMSPACE
421 {
422  return Stat;
423 }
424 
425 
432 MEMSPACE
434 BYTE *buff, /*< Pointer to the data buffer to store read data */
435 DWORD sector, /*< Start sector number (LBA) */
436 UINT count /*< Sector count (1..128) */
437 )
438 {
439  BYTE cmd;
440 
441  if (!count)
442  {
443  deselect();
444  return RES_PARERR;
445  }
446  if (Stat & STA_NOINIT)
447  {
448  deselect();
449  return RES_NOTRDY;
450  }
451 
452  if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */
453 
454  cmd = count > 1 ? CMD18 : CMD17; /* READ_MULTIPLE_BLOCK : READ_SINGLE_BLOCK */
455  if (send_cmd(cmd, sector) == 0)
456  {
457  do
458  {
459  if (!rcvr_datablock(buff, 512))
460  break;
461  buff += 512;
462  } while (--count);
463  if (cmd == CMD18) send_cmd(CMD12, 0); /* STOP_TRANSMISSION */
464  }
465  deselect();
466 
467  return count ? RES_ERROR : RES_OK;
468 }
469 
470 
477 #if _USE_WRITE
478 MEMSPACE
480 const BYTE *buff, /*< Pointer to the data to be written */
481 DWORD sector, /*< Start sector number (LBA) */
482 UINT count /* Sector count (1..128) */
483 )
484 {
485  if (!count)
486  {
487  deselect();
488  return RES_PARERR;
489  }
490  if (Stat & STA_NOINIT)
491  {
492  deselect();
493  return RES_NOTRDY;
494  }
495  if (Stat & STA_PROTECT)
496  {
497  deselect();
498  return RES_WRPRT;
499  }
500 
501  if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */
502 
503  if (count == 1) /* Single block write */
504  {
505  if ((send_cmd(CMD24, sector) == 0) /* WRITE_BLOCK */
506  && xmit_datablock(buff, 0xFE))
507  count = 0;
508  }
509  else /* Multiple block write */
510  {
511  if (CardType & CT_SDC) send_cmd(ACMD23, count);
512  if (send_cmd(CMD25, sector) == 0) /* WRITE_MULTIPLE_BLOCK */
513  {
514  do
515  {
516  if (!xmit_datablock(buff, 0xFC)) break;
517  buff += 512;
518  } while (--count);
519  if (!xmit_datablock(0, 0xFD)) /* STOP_TRAN token */
520  count = 1;
521  }
522  }
523  deselect();
524 
525  return count ? RES_ERROR : RES_OK;
526 }
527 #endif
528 
533 #if _USE_IOCTL
534 MEMSPACE
536  BYTE cmd, /* Control code */
537  void *buff /* Buffer to send/receive control data */
538 )
539 {
540  DRESULT res = RES_NOTRDY;
541  BYTE n, csd[16], *ptr = buff;
542  DWORD *dp, st, ed, csize;
543 #if _USE_ISDIO
544  SDIO_CTRL *sdi;
545  BYTE rc, *bp;
546  UINT dc;
547 #endif
548 
549  if (Stat & STA_NOINIT)
550  {
551  return RES_NOTRDY;
552  }
553 
554  res = RES_ERROR;
555  switch (cmd) {
556  case CTRL_SYNC : /* Make sure that no pending write process. Do not remove this or written sector might not left updated. */
557  if (select()) res = RES_OK;
558 //MG
559 deselect();
560  break;
561 
562  case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */
563  if ((send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16)) {
564  if ((csd[0] >> 6) == 1) { /* SDC ver 2.00 */
565  csize = csd[9] + ((WORD)csd[8] << 8) + ((DWORD)(csd[7] & 63) << 16) + 1;
566  *(DWORD*)buff = csize << 10;
567  } else { /* SDC ver 1.XX or MMC*/
568  n = (csd[5] & 15) + ((csd[10] & 128) >> 7) + ((csd[9] & 3) << 1) + 2;
569  csize = (csd[8] >> 6) + ((WORD)csd[7] << 2) + ((WORD)(csd[6] & 3) << 10) + 1;
570  *(DWORD*)buff = csize << (n - 9);
571  }
572  res = RES_OK;
573  }
574  deselect();
575  break;
576 
577  case GET_BLOCK_SIZE : /* Get erase block size in unit of sector (DWORD) */
578  if (CardType & CT_SD2) { /* SDv2? */
579  if (send_cmd(ACMD13, 0) == 0) { /* Read SD status */
580  xchg_spi(0xFF);
581  if (rcvr_datablock(csd, 16)) { /* Read partial block */
582  for (n = 64 - 16; n; n--) xchg_spi(0xFF); /* Purge trailing data */
583  *(DWORD*)buff = 16UL << (csd[10] >> 4);
584  res = RES_OK;
585  }
586  }
587  } else { /* SDv1 or MMCv3 */
588  if ((send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16)) { /* Read CSD */
589  if (CardType & CT_SD1) { /* SDv1 */
590  *(DWORD*)buff = (((csd[10] & 63) << 1) + ((WORD)(csd[11] & 128) >> 7) + 1) << ((csd[13] >> 6) - 1);
591  } else { /* MMCv3 */
592  *(DWORD*)buff = ((WORD)((csd[10] & 124) >> 2) + 1) * (((csd[11] & 3) << 3) + ((csd[11] & 224) >> 5) + 1);
593  }
594  res = RES_OK;
595  }
596  }
597  deselect();
598  break;
599 
600  case CTRL_TRIM: /* Erase a block of sectors (used when _USE_TRIM in ffconf.h is 1) */
601  if (!(CardType & CT_SDC)) break; /* Check if the card is SDC */
602  if (mmc_disk_ioctl(MMC_GET_CSD, csd)) break; /* Get CSD */
603  if (!(csd[0] >> 6) && !(csd[10] & 0x40)) break; /* Check if sector erase can be applied to the card */
604  dp = buff; st = dp[0]; ed = dp[1]; /* Load sector block */
605  if (!(CardType & CT_BLOCK)) {
606  st *= 512; ed *= 512;
607  }
608  if (send_cmd(CMD32, st) == 0 && send_cmd(CMD33, ed) == 0 && send_cmd(CMD38, 0) == 0 && wait_ready(30000)) /* Erase sector block */
609  res = RES_OK; /* FatFs does not check result of this command */
610 //MG
611 deselect();
612  break;
613 
614  /* Following commands are never used by FatFs module */
615 
616  case MMC_GET_TYPE : /* Get card type flags (1 byte) */
617  *ptr = CardType;
618  res = RES_OK;
619  break;
620 
621  case MMC_GET_CSD : /* Receive CSD as a data block (16 bytes) */
622  if (send_cmd(CMD9, 0) == 0 && rcvr_datablock(ptr, 16)) /* READ_CSD */
623  res = RES_OK;
624  deselect();
625  break;
626 
627  case MMC_GET_CID : /* Receive CID as a data block (16 bytes) */
628  if (send_cmd(CMD10, 0) == 0 && rcvr_datablock(ptr, 16)) /* READ_CID */
629 
630  res = RES_OK;
631  deselect();
632  break;
633 
634  case MMC_GET_OCR : /* Receive OCR as an R3 resp (4 bytes) */
635  if (send_cmd(CMD58, 0) == 0) { /* READ_OCR */
636  for (n = 4; n; n--) *ptr++ = xchg_spi(0xFF);
637  res = RES_OK;
638  }
639  deselect();
640  break;
641 
642  case MMC_GET_SDSTAT : /* Receive SD statsu as a data block (64 bytes) */
643  if (send_cmd(ACMD13, 0) == 0) { /* SD_STATUS */
644  xchg_spi(0xFF);
645  if (rcvr_datablock(ptr, 64)) res = RES_OK;
646  }
647  deselect();
648  break;
649 
650  case CTRL_POWER_OFF : /* Power off */
651  power_off();
652  Stat |= STA_NOINIT;
653  res = RES_OK;
654  break;
655 #if _USE_ISDIO
656  case ISDIO_READ:
657  sdi = buff;
658  if (send_cmd(CMD48, 0x80000000 | (DWORD)sdi->func << 28 | (DWORD)sdi->addr << 9 | ((sdi->ndata - 1) & 0x1FF)) == 0) {
659  //for (Timer1 = 100; (rc = xchg_spi(0xFF)) == 0xFF && Timer1; ) ;
660  mmc_set_ms_timeout(1000);
661  while( (rc = xchg_spi(0xFF)) == 0xFF && !mmc_test_timeout() )
662  ;
663  if (rc == 0xFE) {
664  for (bp = sdi->data, dc = sdi->ndata; dc; dc--) *bp++ = xchg_spi(0xFF);
665  for (dc = 514 - sdi->ndata; dc; dc--) xchg_spi(0xFF);
666  res = RES_OK;
667  }
668  }
669  deselect();
670  break;
671 
672  case ISDIO_WRITE:
673  sdi = buff;
674  if (send_cmd(CMD49, 0x80000000 | (DWORD)sdi->func << 28 | (DWORD)sdi->addr << 9 | ((sdi->ndata - 1) & 0x1FF)) == 0) {
675  xchg_spi(0xFF); xchg_spi(0xFE);
676  for (bp = sdi->data, dc = sdi->ndata; dc; dc--) xchg_spi(*bp++);
677  for (dc = 514 - sdi->ndata; dc; dc--) xchg_spi(0xFF);
678  if ((xchg_spi(0xFF) & 0x1F) == 0x05) res = RES_OK;
679  }
680  deselect();
681  break;
682 
683  case ISDIO_MRITE:
684  sdi = buff;
685  if (send_cmd(CMD49, 0x84000000 | (DWORD)sdi->func << 28 | (DWORD)sdi->addr << 9 | sdi->ndata >> 8) == 0) {
686  xchg_spi(0xFF); xchg_spi(0xFE);
687  xchg_spi(sdi->ndata);
688  for (dc = 513; dc; dc--) xchg_spi(0xFF);
689  if ((xchg_spi(0xFF) & 0x1F) == 0x05) res = RES_OK;
690  }
691  deselect();
692  break;
693 #endif
694  default:
695  res = RES_PARERR;
696  }
697 
698  return res;
699 }
700 #endif
701 
702 /*-----------------------------------------------------------------------*/
703 /* Device Timer Interrupt Procedure */
704 /*-----------------------------------------------------------------------*/
705 /* This function must be called in period of 10ms */
706 
709 {
710  BYTE n;
711 #ifdef DETECT_WP
712  BYTE s;
713 #endif
714 
715  n = Timer1; /* 100Hz decrement timer */
716  if (n) Timer1 = --n;
717  n = Timer2;
718  if (n) Timer2 = --n;
719 
720 // FIXME our Micro SD card holder does not do WP or CD
721 // We assign STA_NODISK if we get a timeout
722 #ifdef DETECT_WP
723  s = Stat;
724 
725  if (MMC_WP) /* Write protected */
726  s |= STA_PROTECT;
727  else /* Write enabled */
728  s &= ~STA_PROTECT;
729 
730  if (MMC_CD) /* Card inserted */
731  s &= ~STA_NODISK;
732  else /* Socket empty */
733  s |= (STA_NODISK | STA_NOINIT);
734 
735  Stat = s; /* Update MMC status */
736 #endif
737 }
738 
#define GET_BLOCK_SIZE
Definition: diskio.h:64
unsigned short WORD
Definition: integer.h:26
MEMSPACE DSTATUS mmc_disk_initialize(void)
Public Functions.
Definition: mmc.c:340
#define STA_NOINIT
Definition: diskio.h:53
#define ACMD41
Definition: mmc.c:56
static BYTE CardType
Definition: mmc.c:85
#define FCLK_FAST()
Definition: mmc.c:45
MEMSPACE int wait_ready(UINT wt)
wait for card ready
Definition: mmc.c:169
Master include file for project Includes all project includes and defines here.
#define CMD58
Definition: mmc.c:75
static MEMSPACE void power_on(void)
power on
Definition: mmc.c:97
MEMSPACE DSTATUS mmc_disk_status(void)
Get Disk Status.
Definition: mmc.c:420
#define CMD48
Definition: mmc.c:72
#define FCLK_SLOW()
Definition: mmc.c:44
#define STA_PROTECT
Definition: diskio.h:55
#define MMC_GET_SDSTAT
Definition: diskio.h:80
#define ACMD23
Definition: mmc.c:66
#define CMD18
Definition: mmc.c:64
#define CMD55
Definition: mmc.c:74
static BYTE xchg_spi(BYTE dat)
send/receive a SPI byte
Definition: mmc.c:126
#define ISDIO_READ
Definition: diskio.h:81
static volatile BYTE Timer2
Definition: mmc.c:82
DWORD addr
Definition: diskio.h:35
#define CT_MMC
Definition: diskio.h:92
#define CMD25
Definition: mmc.c:68
#define CT_BLOCK
Definition: diskio.h:96
MEMSPACE DRESULT mmc_disk_write(const BYTE *buff, DWORD sector, UINT count)
void mmc_spi_RX_buffer(const uint8_t *data, int count)
SPI read buffer.
Definition: mmc_hal.c:142
MEMSPACE DRESULT mmc_disk_read(BYTE *buff, DWORD sector, UINT count)
Read Sector(s)
Definition: mmc.c:433
#define CMD8
Definition: mmc.c:57
static MEMSPACE void deselect(void)
Deselect the card and release SPI bus.
Definition: mmc.c:189
#define CTRL_POWER_OFF
Definition: diskio.h:70
#define CS_LOW()
Definition: mmc.c:39
void mmc_disk_timerproc(void)
Write Sector(s)
Definition: mmc.c:708
static MEMSPACE int select(void)
Select the card and wait for ready.
Definition: mmc.c:202
#define CMD49
Definition: mmc.c:73
static MEMSPACE int rcvr_datablock(BYTE *buff, UINT btr)
Receive a data packet from MMC.
Definition: mmc.c:224
#define GET_SECTOR_COUNT
Definition: diskio.h:62
static void rcvr_spi_multi(BYTE *p, UINT cnt)
Receive a data block fast.
Definition: mmc.c:139
unsigned long DWORD
Definition: integer.h:31
BYTE func
Definition: diskio.h:33
#define CMD1
Definition: mmc.c:55
MEMSPACE void mmc_power_off()
MMC Power OFF.
Definition: mmc_hal.c:290
#define MMC_GET_CSD
Definition: diskio.h:77
BYTE DSTATUS
Definition: diskio.h:20
DRESULT
Definition: diskio.h:23
unsigned char BYTE
Definition: integer.h:22
#define MMC_GET_TYPE
Definition: diskio.h:76
#define CT_SDC
Definition: diskio.h:95
#define ACMD13
Definition: mmc.c:61
#define CMD32
Definition: mmc.c:69
#define ISDIO_WRITE
Definition: diskio.h:82
static void xmit_spi_multi(const BYTE *p, UINT cnt)
Send a data block fast.
Definition: mmc.c:152
static MEMSPACE BYTE send_cmd(BYTE cmd, DWORD arg)
Send a data packet to MMC.
Definition: mmc.c:288
Definition: diskio.h:24
#define ISDIO_MRITE
Definition: diskio.h:83
MEMSPACE int token(char *str, char *pat)
Search for token in a string matching user pattern.
Definition: stringsup.c:671
static MEMSPACE void power_off(void)
power off
Definition: mmc.c:110
#define CMD16
Definition: mmc.c:62
#define CMD38
Definition: mmc.c:71
#define CMD33
Definition: mmc.c:70
#define CT_SD1
Definition: diskio.h:93
Math IO functions, and verious conversion code with floating point support.
uint8_t mmc_spi_TXRX(uint8_t data)
SPI read and write 1 byte.
Definition: mmc_hal.c:150
#define CMD24
Definition: mmc.c:67
WORD ndata
Definition: diskio.h:34
#define CMD17
Definition: mmc.c:63
#define CTRL_TRIM
Definition: diskio.h:65
volatile DSTATUS Stat
Definition: mmc.c:79
void mmc_spi_TX_buffer(const uint8_t *data, int count)
SPI write buffer.
Definition: mmc_hal.c:133
MEMSPACE int mmc_test_timeout()
Wait for timeout.
Definition: mmc_hal.c:172
#define MEMSPACE
Definition: cpu.h:25
unsigned int UINT
Definition: integer.h:19
#define CMD9
Definition: mmc.c:58
MEMSPACE int printf(const char *format,...)
void * data
Definition: diskio.h:36
#define MMC_WP
Definition: mmc.c:43
MEMSPACE void mmc_set_ms_timeout(uint16_t ms)
Set MMC timeout timer in Milliseconds.
Definition: mmc_hal.c:161
#define CTRL_SYNC
Definition: diskio.h:61
#define CMD0
Definition: mmc.c:54
#define CS_HIGH()
Definition: mmc.c:40
#define CMD12
Definition: mmc.c:60
unsigned char uint8_t
Definition: send.c:17
#define STA_NODISK
Definition: diskio.h:54
#define MMC_CD
Definition: mmc.c:42
#define MMC_GET_CID
Definition: diskio.h:78
#define MMC_GET_OCR
Definition: diskio.h:79
#define CT_SD2
Definition: diskio.h:94
MEMSPACE DRESULT mmc_disk_ioctl(BYTE cmd, void *buff)
static volatile BYTE Timer1
Definition: mmc.c:82
MEMSPACE void mmc_power_on()
MMC Power ON.
Definition: mmc_hal.c:282
#define CMD10
Definition: mmc.c:59