예제 #1
0
파일: mmcmule.c 프로젝트: bill2009/lcc1802
int mmc_readsector(uint32_t lba, uint8_t *buffer)
{
    uint16_t i,retval;
	printf("\nreadsector\n");
    // send read command and logical sector address
    mmc_send_command(17,(lba>>7) & 0xffff, (lba<<9) & 0xffff);
    //mmc_send_command(17,(lba>>16) & 0xffff, (lba) & 0xffff); //wjr
	retval=mmc_get();
	printf("\ngot rc %d\n",retval);

    if (mmc_datatoken() != 0xfe)    // if no valid token
    {
        mmc_clock_and_release();    // cleanup and
        return -1;                  // return error code
    }
	spiReceiveN(buffer,512);
//    for (i=0;i<512;i++)             // read sector data
//        *buffer++ = spixfer(0xff);

    (void)spixfer(0xff);                 // ignore dummy checksum
    (void)spixfer(0xff);                 // ignore dummy checksum

    mmc_clock_and_release();        // cleanup

    return 0;                       // return success
}
예제 #2
0
파일: mmcmule.c 프로젝트: bill2009/lcc1802
uint8_t mmc_init(void)
{
    unsigned int i,retval;
	digitalWrite(SDSS,HIGH)	;
    for(i=0;i<10;i++)           // send 80 clocks while card power stabilizes
        (void)spixfer(0xff);

    mmc_send_command(0,0,0);    // send CMD0 - reset card
  	retval=mmc_get();

    if (retval != 1)         // if no valid response code
    {
		printf("\nmmc init cmd 0 failed with code %d (should have been 1)\n");
       	mmc_clock_and_release();
       	return 1;                // card cannot be detected
    }

    //
    // send CMD1 until we get a 0 back, indicating card is done initializing
    //
    i = 0xff;                     // max timeout
    while ((spixfer(0xff) != 0) && (--i))  // wait for it
    {
         mmc_send_command(1,0,0);   // send CMD1 - activate card init
    }

    mmc_clock_and_release();        // clean up

    if (i == 0){                     // if we timed out above
    	printf("\nmmc cmd 1 failed\n");
       	return 2;                    // return failure code
	}

    return 0;
}
예제 #3
0
파일: mmc.c 프로젝트: freecores/igor
/** Init MMC/SD card.
	Initialize I/O ports for the MMC/SD interface and 
	send init commands to the MMC/SD card
	\return 0 on success, other values on error 
*/
uint8_t mmc_init(void)
{
//Run configure_spi() to setup the SPI port before initializing MMC.
	
	int i;

	for(i=0;i<10;i++)	// send 8 clocks while card power stabilizes
		spi_byte(0xff);

	mmc_send_command(0,0,0);	// send CMD0 - reset card

	if (mmc_get() != 1)			// if no valid response code
	{
		mmc_clock_and_release();
		return 1;  			// card cannot be detected
	}

	//
	// send CMD1 until we get a 0 back, indicating card is done initializing 
	//
	i = 0xffff;				// max timeout
	while ((spi_byte(0xff) != 0) && (--i))	// wait for it
	{
		mmc_send_command(1,0,0);	// send CMD1 - activate card init
	}

	mmc_clock_and_release();		// clean up

	if (i == 0)				// if we timed out above
		return 2;			// return failure code

	return 0;
}
예제 #4
0
파일: mmc.c 프로젝트: freecores/igor
//Write MMC/SD sector
int mmc_writesector(uint32_t lba, uint8_t *buffer)
{
	uint16_t i;

	// send write command and logical sector address
	mmc_send_command(24,(lba>>7) & 0xffff, (lba<<9) & 0xffff);

	spi_byte(0xfe);				//Send data token

	for (i=0;i<512;i++)			//Send sector data
		spi_byte(*buffer++);

	spi_byte(0xff);				//Send dummy 16-bit checksum
	spi_byte(0xff);

	if ((mmc_get() & 0x0f) != 0x05) {	//Receive response token
		mmc_clock_and_release();
		return -1;			//Write error
	}

	while (spi_byte(0xff) == 0x00) {
		//Wait for the card to finish writing, this can take
		//a very long time, i.e. several hundred milliseconds
	}

	mmc_clock_and_release();		//Cleanup

	return 0;				//Return success
}
예제 #5
0
파일: mmc_lib.c 프로젝트: Aliandrana/uzebox
void mmc_playerStop(){
	if(mmc_player_status==MMC_PLAYER_STARTED){
		mmc_send_command(12,0,0); //stop transfers
		mmc_clock_and_release();
	}	
	mmc_player_status = MMC_PLAYER_STOPPED;
}
예제 #6
0
파일: mmc.c 프로젝트: freecores/igor
/** Read MMC/SD sector.
	 Read a single 512 byte sector from the MMC/SD card
	\param lba	Logical sectornumber to read
	\param buffer	Pointer to buffer for received data
	\return 0 on success, -1 on error
*/
int mmc_readsector(uint32_t lba, uint8_t *buffer)
{
	uint16_t i;

	// send read command and logical sector address
	mmc_send_command(17,(lba>>7) & 0xffff, (lba<<9) & 0xffff);

	if (mmc_datatoken() != 0xfe)		// if no valid token
	{
		mmc_clock_and_release();	// cleanup and	
		return -1;			// return error code
	}

	for (i=0;i<512;i++)			// read sector data
		*buffer++ = spi_byte(0xff);

	spi_byte(0xff);				// ignore dummy checksum
	spi_byte(0xff);				// ignore dummy checksum

	mmc_clock_and_release();		// cleanup

	return 0;				// return success
}
예제 #7
0
파일: mmc_lib.c 프로젝트: Aliandrana/uzebox
//starts playing wav file pointed at by lba
void mmc_playerStart(mmc_File file){

	if(mmc_player_status==MMC_PLAYER_STARTED)
	{
		mmc_player_status = MMC_PLAYER_STOPPED;
		mmc_send_command(12,0,0); //stop current transfer
		mmc_clock_and_release();
	}

	// send the multiple block read command and logical sector address
	mmc_player_sector=file.firstSector;
	mmc_send_command(18,(mmc_player_sector>>7) & 0xffff, (mmc_player_sector<<9) & 0xffff);	
	playerRead=0;
	sectorRead=0;
	samplesToPlay.value=-1;
	mmc_player_status = MMC_PLAYER_STARTED;
}