24int8_t Is_Initialized=0,SDtype=0;
25uint32_t LogicSector=0;
76 uint32_t
volatile loop;
77 for(loop=0; loop<count; loop++);
101static uint32_t
GenerateCRC(uint32_t u32Data, uint32_t u32GenPoly, uint32_t u32Accum)
108 if ((u32Data ^ u32Accum) & 0x8000)
109 u32Accum = (u32Accum << 1) ^ u32GenPoly;
145 static uint32_t current_blklen = 512;
146 uint32_t old_blklen = 512;
154 current_command = command_list[nCmd];
178 current_blklen = nArg;
187 old_blklen = current_blklen;
196 for(counter=3; counter>=0; counter--)
199 dummy_CRC.
i =
GenerateCRC(long_arg.
b[counter], 0x1200, dummy_CRC.
i);
202 dummy_CRC.
i = (dummy_CRC.
i >> 8)| 0x01;
226 if(!++loopguard)
break;
229 DBG_PRINTF(
"R1:0x%x, counter:%d\n",card_response.
b[0],loopguard);
234 *response=card_response.
b[0];
242 if(!++loopguard)
break;
253 if(!++loopguard)
break;
257 DBG_PRINTF(
"R2:0x%x, counter:%d\n",card_response.
i,loopguard);
262 *response=card_response.
i;
271 if(!++loopguard)
break;
274 DBG_PRINTF(
"R3:0x%x, counter:%d\n",card_response.
b[0],loopguard);
286 *response=card_response.
b[0];
295 if(!++loopguard)
break;
298 DBG_PRINTF(
"R7:0x%x, counter:%d\n",card_response.
b[0],loopguard);
310 *response=card_response.
b[0];
341 for (counter=0; counter<current_blklen; counter++)
351 for (; counter<current_blklen; counter++)
376 for (counter=0; counter<current_blklen; counter++)
386 for (counter=0; counter<current_blklen; counter++)
403 for (counter=0; counter<current_blklen; counter++)
407 dummy_CRC.
i =
GenerateCRC(*(pchar+counter), 0x1021, dummy_CRC.
i);
417 if(!++loopguard)
break;
438 current_blklen = old_blklen;
454 uint32_t c_size,bl_len;
466 for(counter = 0; counter < 10; counter++)
481 if (pchar[2] == 0x01 && pchar[3] == 0x5A)
488 if(!++loopguard)
break;
509 if(!++loopguard)
break;
523 if(!++loopguard)
break;
558 bl_len = 1 << (pchar[5] & 0x0f) ;
559 c_size = ((pchar[7] & 0x3F) << 16) |(pchar[8] << 8) | (pchar[9]);
560 LogicSector=c_size*((512*1024)/bl_len);
564 bl_len = 1 << (pchar[5] & 0x0f) ;
565 c_size = ((pchar[6] & 0x03) << 10) |(pchar[7] << 2) | ((pchar[8] &0xc0) >> 6);
566 c_mult = (((pchar[9] & 0x03) << 1) | ((pchar[10] & 0x80) >> 7));
567 LogicSector=(c_size+1)*(1 << (c_mult+2))*(bl_len/512);
569 DBG_PRINTF(
"\nLogicSector:%d, PHYSICAL_SIZE:%dMB\n",LogicSector,(LogicSector/2/1024));
574 if(!++loopguard)
break;
628 if (LogicSector == 0)
631 *pu32TotSecCnt = LogicSector;
652void SpiRead(uint32_t addr, uint32_t size, uint8_t* buffer)
687void SpiWrite(uint32_t addr, uint32_t size, uint8_t* buffer)
Nano100 series peripheral access layer header file. This file contains all the peripheral register's ...
Nano100 series SD Card driver header file.
#define SPI1
Pointer to SPI1 register structure.
#define PHYSICAL_BLOCK_SIZE
#define READ_SINGLE_BLOCK
uint32_t SDCARD_Open(void)
This function is used to Open GPIO function and initial SDCARD.
static uint32_t SingleWrite(uint32_t u32Data)
This function is used to send data though SPI to general clock for SDCARD operation.
uint32_t GetLogicSector(void)
This function is used to get logic sector size.
void SpiWrite(uint32_t addr, uint32_t size, uint8_t *buffer)
This function is used to store data into SD card.
void SpiRead(uint32_t addr, uint32_t size, uint8_t *buffer)
This function is used to Get data from SD card.
void SD_Delay(uint32_t count)
Delay function.
void MMC_FLASH_Init(void)
This function is used to initialize the flash card.
void SDCARD_Close(void)
This function is used to close SDCARD.
static uint32_t GenerateCRC(uint32_t u32Data, uint32_t u32GenPoly, uint32_t u32Accum)
This function is used to generate CRC value.
uint32_t MMC_Command_Exec(uint8_t nCmd, uint32_t nArg, uint8_t *pchar, uint32_t *response)
This function is used to Send SDCARD CMD and Receive Response.
uint32_t SDCARD_GetCardSize(uint32_t *pu32TotSecCnt)
This function is used to get card total sector after SDCARD is opened.
#define SPI_WRITE_TX0(spi, u32TxData)
Write datum to TX0 register.
#define SPI_TRIGGER(spi)
Set the GO_BUSY bit to trigger SPI transfer.
#define SPI_READ_RX0(spi)
Get the datum read from RX0 FIFO.
void SPI_DisableAutoSS(SPI_T *spi)
Disable the automatic slave select function.
#define SPI_SET_MSB_FIRST(spi)
Set the SPI transfer sequence with MSB first.
#define SPI_SET_SS0_LOW(spi)
Set SPIn_SS0 pin to low state.
uint32_t SPI_SetBusClock(SPI_T *spi, uint32_t u32BusClock)
Set the SPI bus clock. Only available in Master mode.
void SPI_Close(SPI_T *spi)
Reset SPI module and disable SPI peripheral clock.
#define SPI_IS_BUSY(spi)
Get the SPI busy state.
#define SPI_SET_SS0_HIGH(spi)
Set SPIn_SS0 pin to high state.
uint32_t SPI_Open(SPI_T *spi, uint32_t u32MasterSlave, uint32_t u32SPIMode, uint32_t u32DataWidth, uint32_t u32BusClock)
This function make SPI module be ready to transfer. By default, the SPI transfer sequence is MSB firs...
uint32_t SPI_GetBusClock(SPI_T *spi)
Get the actual frequency of SPI bus clock. Only available in Master mode.
#define TRUE
Boolean true, define to use in API parameters or return value.
#define FALSE
Boolean false, define to use in API parameters or return value.