Advertisement
DimkaM

Untitled

Nov 4th, 2020
2,008
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. DRESULT disk_writep (const BYTE* buff, DWORD sc){
  2.     static WORD wr_cnt;
  3.     if(sd_blsize == 0xff) return RES_NOTRDY;
  4.    
  5.     if (!buff) {
  6.         if (sc) {
  7.             CS_LOW
  8.             spi_io(0xff);
  9.             spi_io(0xff);
  10.             if(sd_blsize == 0x00) sc *= 512;
  11.             spi_io(CMD_24);
  12.             spi_io(((BYTE*) &sc)[3]);
  13.             spi_io(((BYTE*) &sc)[2]);
  14.             spi_io(((BYTE*) &sc)[1]);
  15.             spi_io(((BYTE*) &sc)[0]);
  16.             spi_io(0xff);
  17.             if(in_oout() != 0X00) return RES_ERROR;
  18.             spi_io(0xff);
  19.             spi_io(0xfe);
  20.            
  21.             writep_status=1;
  22.             wr_cnt = 512;
  23.         } else {
  24.             // Finalize write process
  25.             if(writep_status == 0) return RES_NOTRDY;
  26.             while(wr_cnt--){
  27.                 spi_io(0x00);
  28.             }
  29.             in_oout();
  30.             while(spi_io(0xff) != 0xff);
  31.             writep_status = 0x00;
  32.             CS_HIGH
  33.         }
  34.     } else {
  35.         if(writep_status == 0) return RES_NOTRDY;
  36.         wr_cnt -= (WORD)sc;
  37.             while(sc--){
  38.                 spi_io(*buff++);
  39.             }
  40.     }
  41.     return RES_OK;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement