Ejemplo n.º 1
0
int main(){

#ifndef TESTING

#include "uart.h"
#include "mmc.h"

	// Initializam modulele hardware

	uart_init();
	SPI_init();
	MMC_init();
	BTN_init();
	LCD_init();
#endif
	/* Gaseste prima partitie FAT32 de pe card*/
	init_partition(buffer);

	/**
	  * Gaseste datele despre sistemul de fisiere :
	  * nr de tabele FAT, cluster-ul directorului Root, etc.
	  */
	initFAT32(buffer);
	print_volid(buffer);

	LCD_str( "  ", 0);
	LCD_str( "  ", 0);
	LCD_str( "  Welcome to", 0);
	LCD_str( " MMC Explorer", 0);
	_delay_ms(2500);
	LCD_clear();
	printdirs(openroot());
	return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
static void printMatches(const void* buffer, size_t size)
{
    MMC_ctx* const mmc = MMC_create();
    const char* buf = (const char*)buffer;
    size_t pos = 0;

    MMC_init(mmc, buf);
    for (pos=0; pos<size; pos++)
    {
        const void* match;
        size_t const length = MMC_insertAndFindBestMatch(mmc, buf+pos, size-pos, &match);
        if (length > 0)
            printf("pos %5zu: found match of length %2zu \n", pos, length);
    }

    MMC_free(mmc);
}
/**
 *  \brief  Tests MMC card operation in POLLED mode
 *
 *   This function configures the MMCSD module in POLLED mode and
 *   verifies the operation with MMC Card. Function returns failure
 *   incase of no MMC card is detected.
 *
 *  \param  none
 *
 *  \return Test result
 */
CSL_Status CSL_mmcPollTest(void)
{
	CSL_Status	    mmcStatus;
	Uint16          looper;
	Uint16		    actCard;
	Uint16          clockDiv;

    callBckFun.isr[CSL_MMCSD_ISR_TXMT] = isr_txmt;
    callBckFun.isr[CSL_MMCSD_ISR_RCV]  = isr_rcv;

	/* Initialize data buffers */
	for(looper = 0; looper < (BUFFER_MAX_SIZE/2); looper++)
	{
	    gMmcReadBuff[looper]   = 0;
		gMmcWriteBuff[looper] = looper;
	}

	/* Get the clock divider value for the current CPU frequency */
	clockDiv = computeClkRate();

	/* Initialize the CSL MMCSD module */
	mmcStatus = MMC_init();
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_init Failed\n");
		return(mmcStatus);
	}

    /* Initialize the config parameter */
	mmcConfig.mmcblen = CSL_MMCSD_BLOCK_LENGTH;
	mmcConfig.mmcclk  = 0x10 |CSL_MMCSD_MMCCLK_CLKEN_ENABLE;
	mmcConfig.mmcctl  = CSL_MMCSD_MMCCTL_DATEG_F_EDGE;
	mmcConfig.mmcim   = 0x0;
	mmcConfig.mmcnblk = 0x1;
	mmcConfig.mmctod  = CSL_MMCSD_DATA_RW_TIMEOUT;
	mmcConfig.mmctor  = CSL_MMCSD_RESPONSE_TIMEOUT;

    /* assign the value to setup native structure */
	setupNative.blockLen		  = CSL_MMCSD_BLOCK_LENGTH;
	setupNative.cdiv			  = 0x10;
	setupNative.dat3EdgeDetection = CSL_MMCSD_MMCCTL_DATEG_F_EDGE;
	setupNative.dataTimeout 	  = CSL_MMCSD_DATA_RW_TIMEOUT;
	setupNative.dmaEnable		  = 0x1;
	setupNative.enableClkPin	  = 0x1;
	setupNative.rspTimeout		  = CSL_MMCSD_RESPONSE_TIMEOUT;

	/* Open the MMCSD module in POLLED mode */
#ifdef C5515_EZDSP
	mmcsdHandle = MMC_open(&pMmcsdContObj, CSL_MMCSD1_INST,
	                       CSL_MMCSD_OPMODE_POLLED, &mmcStatus);
#else
	mmcsdHandle = MMC_open(&pMmcsdContObj, CSL_MMCSD0_INST,
	                       CSL_MMCSD_OPMODE_POLLED, &mmcStatus);
#endif
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_open Failed\n");
		return(mmcStatus);
	}
	else
	{
		printf("API: MMC_open Successful\n");
	}

	/* Send CMD0 to the card */
	mmcStatus = MMC_sendGoIdle(mmcsdHandle);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_sendGoIdle Failed\n");
		return(mmcStatus);
	}

	/* Check for the card */
    mmcStatus = MMC_selectCard(mmcsdHandle, &mmcCardObj);
	if((mmcStatus == CSL_ESYS_BADHANDLE) ||
	   (mmcStatus == CSL_ESYS_INVPARAMS))
	{
		printf("API: MMC_selectCard Failed\n");
		return(mmcStatus);
	}

	/* Verify whether the MMC card is detected or not */
	if(mmcCardObj.cardType == CSL_MMC_CARD)
	{
		printf("MMC Card Detected!\n\n");
	}
	else
	{
		/* Check if No card is inserted */
		if(mmcCardObj.cardType == CSL_CARD_NONE)
		{
			printf("No Card Detected!\n");
		}
		else
		{
			printf("MMC Card not Detected!\n");
		}

		printf("Please Insert MMC Card!!\n");
		return(CSL_ESYS_FAIL);
	}

 	/* Send the card identification Data */
	mmcStatus = MMC_sendAllCID(mmcsdHandle, &mmcCardIdObj);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_sendAllCID Failed\n");
		return(mmcStatus);
	}

	/* Set the Relative Card Address */
	mmcStatus = MMC_setRca(mmcsdHandle, &mmcCardObj, 0x0001);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setRca Failed\n");
		return(CSL_ESYS_FAIL);
	}

	/* Read the MMC Card Specific Data */
	mmcStatus = MMC_getCardCsd(mmcsdHandle, &mmcCardCsdObj);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_getCardCsd Failed\n");
		return(mmcStatus);
	}

	/* Set the card type in internal data structures */
	mmcStatus = MMC_setCardType(&mmcCardObj, CSL_MMC_CARD);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setCardType Failed\n");
		return(mmcStatus);
	}

	/* Set the card pointer in internal data structures */
	mmcStatus = MMC_setCardPtr(mmcsdHandle, &mmcCardObj);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setCardPtr Failed\n");
		return(mmcStatus);
	}

	/* Get the number of cards */
	mmcStatus = MMC_getNumberOfCards(mmcsdHandle, &actCard);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_getNumberOfCards Failed\n");
		return(mmcStatus);
	}

	/* Set the MMC operating clock */
    mmcStatus = MMC_sendOpCond(mmcsdHandle, clockDiv);
	if(mmcStatus != CSL_SOK)
	{
	   printf("API: MMC_sendOpCond Failed\n");
	   return(mmcStatus);
	}

	/* Set the endian mode */
	mmcStatus = MMC_setEndianMode(mmcsdHandle, CSL_MMCSD_ENDIAN_LITTLE,
	                              CSL_MMCSD_ENDIAN_LITTLE);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setEndianMode Failed\n");
		return(mmcStatus);
	}

	/* Set block length for the memory card
	 * For high capacity cards setting the block length will have
	 * no effect
	 */
	mmcStatus = MMC_setBlockLength(mmcsdHandle, CSL_MMCSD_BLOCK_LENGTH);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setBlockLength Failed\n");
		return(mmcStatus);
	}

	/* Write data to the MMC card */
	mmcStatus = MMC_write(mmcsdHandle, CARD_START_ADDR, BUFFER_MAX_SIZE,
	                      gMmcWriteBuff);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_write Failed\n");
		return(mmcStatus);
	}
	else
	{
		printf("API: MMC_write Successful\n");
	}

	/* Read data from the MMC card */
	mmcStatus = MMC_read(mmcsdHandle, CARD_START_ADDR, BUFFER_MAX_SIZE,
	                     gMmcReadBuff);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_read Failed\n");
		return(mmcStatus);
	}
	else
	{
		printf("API: MMC_read Successful\n");
	}

	/* Deselect the MMC card */
	mmcStatus = MMC_deselectCard(mmcsdHandle, &mmcCardObj);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_deselectCard Failed\n");
		return(mmcStatus);
	}

	/* Following APIs have nothing to do with the test sequence
	   They are called to verify their basic functionality */

	/* Save the MMC status */
	mmcStatus = MMC_saveStatus(mmcsdHandle);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_saveStatus Failed\n");
		return(mmcStatus);
	}

	/* Read the MMC status */
	MMC_getStatus(mmcsdHandle, 0xFFFF, &mmcStatus);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_getStatus Failed\n");
		return(mmcStatus);
	}

	/* Configure the MMC module */
	mmcStatus = MMC_config(mmcsdHandle, &mmcConfig);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_config Failed\n");
		return(mmcStatus);
	}

	/* Read the configurations from the MMC module */
	mmcStatus = MMC_getConfig(mmcsdHandle, &mmcConfig);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_getConfig Failed\n");
		return(mmcStatus);
	}

	/* Setup the MMCSD native structure */
	mmcStatus = MMC_setupNative(mmcsdHandle, &setupNative);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setupNative Failed\n");
		return(mmcStatus);
	}

	/* Read the Receive Data Ready Status bit */
	MMC_drrdy(mmcsdHandle, &mmcStatus);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_drrdy Failed\n");
		return(mmcStatus);
	}

	/* Read the Transmit Data Ready Status bit */
	MMC_dxrdy(mmcsdHandle, &mmcStatus);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_dxrdy Failed\n");
		return(mmcStatus);
	}

	/* Set the MMCSD Callback functions */
	mmcStatus = MMC_setCallBack(mmcsdHandle, &callBckFun);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_setCallBack Failed\n");
		return(mmcStatus);
	}

	/* Clear the MMCSD card response registers */
	mmcStatus = MMC_clearResponse(mmcsdHandle);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_clearResponse Failed\n");
		return(mmcStatus);
	}

	/* Configure the MMCSD Interrupts  */
	mmcStatus = MMC_intEnable(mmcsdHandle, 0x0000);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_intEnable Failed\n");
		return(mmcStatus);
	}

	/* Enable the Data transfer done Interrupt */
	mmcStatus = MMC_eventEnable(mmcsdHandle, CSL_MMCSD_EDATDNE_INTERRUPT);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_eventEnable Failed\n");
		return(mmcStatus);
	}

	/* Disable the Data transfer done Interrupt */
	mmcStatus = MMC_eventDisable(mmcsdHandle, CSL_MMCSD_EDATDNE_INTERRUPT);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_eventDisable Failed\n");
		return(mmcStatus);
	}

	/* Close the MMCSD module */
	mmcStatus = MMC_close(mmcsdHandle);
	if(mmcStatus != CSL_SOK)
	{
		printf("API: MMC_close Failed\n");
		return(mmcStatus);
	}
	else
	{
		printf("API: MMC_close Successful\n");
	}

	/* Compare the MMC read and write buffers */
	for(looper = 0; looper < (BUFFER_MAX_SIZE/2); ++looper)
	{
		if(gMmcReadBuff[looper] != gMmcWriteBuff[looper])
		{
			printf("\nBuffer Miss Matched at Position %d\n",looper);
			return(CSL_ESYS_FAIL);
		}
	}

	printf("\nMMC Card Read & Write Buffer Matched\n");

	return(CSL_SOK);
}
Ejemplo n.º 4
0
void main() {
    char error,error2;
    unsigned int c =0 ,i,x,y;
    SPI1_Init();
    Glcd_init();
   // glcd_image(logo);
    GLCD_fill(255);
    i=0;
 /*   for(y=0;y<64;y++){
      for(x=0;x<128;x++){
        glcd_dot(x,y,logo[x+(i*128)]);
       }
       i++;
    }*/
    i = 128*10;
    for(x=i;x<i+128;x++){
      glcd_dot(x,1,logo[x]);
      }
    
    delay_ms(1000);
    
    while(1){
    error = MMC_init();
    if(!error){
      glcd_fill(0);
      glcd_write_text("Connected!",1,1,2);
      while(!error){
          error= MMC_init();
          if(RC2_bit==0){
             for(i=0;i<512;i++){
               xyz[i] = logo[i];
             }
            error2 = Mmc_write_Sector(1, xyz);
            for(i=0;i<512;i++){
               xyz[i] = logo[512+i];
             }
            error2 = Mmc_write_Sector(2, xyz);
            if(!error2){
               glcd_fill(0);
               glcd_write_text("Write Succ!",1,1,2);
               delay_ms(2000);
               glcd_fill(0);
               glcd_write_text("Connected!",1,1,2);
            }
            else{
               glcd_fill(0);
               glcd_write_text("Error",1,1,2);
            }
          }
          if(RC1_bit==0){
            error2 = Mmc_read_Sector(1, xyz);
            for(i=0;i<512;i++){
             //  logo[i] = xyz[i];
             }
            error2 = Mmc_write_Sector(2, xyz);
            for(i=0;i<512;i++){
              // logo[512+i] = xyz[i] ;
             }
            if(!error2){
               glcd_fill(0);

               delay_ms(2000);
               glcd_fill(0);
               glcd_write_text("Connected!",1,1,2);
            }
          }
      }
    }
    else{
      glcd_fill(0);
      glcd_write_text("Not Connected!",1,1,2);
    }
    delay_ms(200);
    }
}
Ejemplo n.º 5
0
void main() {
    char error,error2;
    uart1_init(9600);
    SPI1_Init();
    buf[0]='E';
    buf[1]='n';
    buf[2]='g';
    buf[3]='S';
    buf[4]='h';
    buf[5]='a';
    buf[6]='d';
    buf[7]='y';
    

    
    trisd=255;
  
     error = MMC_init();
    if(!error){
    uart1_write_text("connected");
    }
    else
    uart1_write_text("not connected");

    
    
    while(1)
    {
    if(rd0_bit==0)
    {
    buf[0]='E';
    buf[1]='n';
    buf[2]='g';
    buf[3]='S';
    buf[4]='h';
    buf[5]='a';
    buf[6]='d';
    buf[7]='y';
     error2 = Mmc_write_Sector(1, buf);
     if(!error2)
     {
     uart1_write_text("write success");
     }
     else
     uart1_write_text("write not success");
     while(rd0_bit==0){}
    }
    
    
        if(rd1_bit==0)
    {
     error2 = Mmc_read_Sector(1, read);
     uart1_write_text(read);
     while(rd1_bit==0){}
    }
      if(rd2_bit==0)
    {
    buf[0]='E';
    buf[1]='n';
    buf[2]='g';
    buf[3]='i';
    buf[4]='s';
    buf[5]='m';
    buf[6]='a';
    buf[7]='i';
    buf[7]='l';
     error2 = Mmc_write_Sector(1, buf);
     if(!error2)
     {
     uart1_write_text("write success");
     }
     else
     uart1_write_text("write not success");
     while(rd2_bit==0){}
    }

    
    
    
    }
    



}
Ejemplo n.º 6
0
CSL_Status configSdCard(CSL_MMCSDOpMode opMode) {
    CSL_Status status;
    Uint16 actCard;
    Uint16 clockDiv;
    Uint16 rca;

    /* Get the clock divider value for the current CPU frequency */
    clockDiv = computeClkRate();

    /* Initialize MMCSD CSL module */
    status = MMC_init();

    status = SYS_setEBSR(CSL_EBSR_FIELD_SP0MODE, CSL_EBSR_SP0MODE_0);
    status |= SYS_setEBSR(CSL_EBSR_FIELD_SP1MODE, CSL_EBSR_SP1MODE_0);
    if (CSL_SOK != status) {
        printf("SYS_setEBSR failed\n");
        return (status);
    }

    /* Open MMCSD CSL module */
#ifdef C5515_EZDSP
    mmcsdHandle = MMC_open(&pMmcsdContObj, CSL_MMCSD1_INST,
                           opMode, &status);
#else
    mmcsdHandle = MMC_open(&pMmcsdContObj, CSL_MMCSD1_INST, opMode, &status);
#endif
    if (mmcsdHandle == NULL) {
        printf("MMC_open Failed\n");
        return (status);
    }

    /* Configure the DMA in case of operating mode is set to DMA */
    if (opMode == CSL_MMCSD_OPMODE_DMA) {
        /* Initialize Dma */
        status = DMA_init();
        if (status != CSL_SOK) {
            printf("DMA_init Failed!\n");
            return (status);
        }

        /* Open Dma channel for MMCSD write */
        dmaWrHandle = DMA_open(CSL_DMA_CHAN0, &dmaWrChanObj, &status);
        if ((dmaWrHandle == NULL) || (status != CSL_SOK)) {
            printf("DMA_open for MMCSD Write Failed!\n");
            return (status);
        }

        /* Open Dma channel for MMCSD read */
        dmaRdHandle = DMA_open(CSL_DMA_CHAN1, &dmaRdChanObj, &status);
        if ((dmaRdHandle == NULL) || (status != CSL_SOK)) {
            printf("DMA_open for MMCSD Read Failed!\n");
            return (status);
        }

        /* Set the DMA handle for MMC read */
        status = MMC_setDmaHandle(mmcsdHandle, dmaWrHandle, dmaRdHandle);
        if (status != CSL_SOK) {
            printf("API: MMC_setDmaHandle for MMCSD Failed\n");
            return (status);
        }
    }

    /* Reset the SD card */
    status = MMC_sendGoIdle(mmcsdHandle);
    if (status != CSL_SOK) {
        printf("MMC_sendGoIdle Failed\n");
        return (status);
    }

    /* Check for the card */
    status = MMC_selectCard(mmcsdHandle, &mmcCardObj);
    if ((status == CSL_ESYS_BADHANDLE) || (status == CSL_ESYS_INVPARAMS)) {
        printf("MMC_selectCard Failed\n");
        return (status);
    }

    /* Verify whether the SD card is detected or not */
    if (mmcCardObj.cardType == CSL_SD_CARD) {
        printf("SD Card detected\n");

        /* Check if the card is high capacity card */
        if (mmcsdHandle->cardObj->sdHcDetected == TRUE) {
            printf("SD card is High Capacity Card\n");
            printf("Memory Access will use Block Addressing\n");
        } else {
            printf("SD card is Standard Capacity Card\n");
            printf("Memory Access will use Byte Addressing\n");
        }
    } else {
        if (mmcCardObj.cardType == CSL_CARD_NONE) {
            printf("No Card detected\n");
        } else {
            printf("SD Card not detected\n");
        }
        printf("Please Insert SD Card\n");
        return (CSL_ESYS_FAIL);
    }

    /* Set the init clock */
    status = MMC_sendOpCond(mmcsdHandle, 70);
    if (status != CSL_SOK) {
        printf("MMC_sendOpCond Failed\n");
        return (status);
    }

    /* Send the card identification Data */
    status = SD_sendAllCID(mmcsdHandle, &sdCardIdObj);
    if (status != CSL_SOK) {
        printf("SD_sendAllCID Failed\n");
        return (status);
    }

    /* Set the Relative Card Address */
    status = SD_sendRca(mmcsdHandle, &mmcCardObj, &rca);
    if (status != CSL_SOK) {
        printf("SD_sendRca Failed\n");
        return (status);
    }

    /* Read the SD Card Specific Data */
    status = SD_getCardCsd(mmcsdHandle, &sdCardCsdObj);
    if (status != CSL_SOK) {
        printf("SD_getCardCsd Failed\n");
        return (status);
    }

    /* Set the card type in internal data structures */
    status = MMC_setCardType(&mmcCardObj, CSL_SD_CARD);
    if (status != CSL_SOK) {
        printf("MMC_setCardType Failed\n");
        return (status);
    }

    /* Set the card pointer in internal data structures */
    status = MMC_setCardPtr(mmcsdHandle, &mmcCardObj);
    if (status != CSL_SOK) {
        printf("MMC_setCardPtr Failed\n");
        return (status);
    }

    /* Get the number of cards */
    status = MMC_getNumberOfCards(mmcsdHandle, &actCard);
    if (status != CSL_SOK) {
        printf("MMC_getNumberOfCards Failed\n");
        return (status);
    }

    /* Set clock for read-write access */
    status = MMC_sendOpCond(mmcsdHandle, clockDiv);
    if (status != CSL_SOK) {
        printf("MMC_sendOpCond Failed\n");
        return (status);
    }

    /* Set Endian mode for read and write operations */
    status = MMC_setEndianMode(mmcsdHandle, CSL_MMCSD_ENDIAN_LITTLE,
                               CSL_MMCSD_ENDIAN_LITTLE);
    if (status != CSL_SOK) {
        printf("MMC_setEndianMode Failed\n");
        return (status);
    }

    /* Set block length for the memory card
     * For high capacity cards setting the block length will have
     * no effect
     */
    status = MMC_setBlockLength(mmcsdHandle, CSL_MMCSD_BLOCK_LENGTH);
    if (status != CSL_SOK) {
        printf("MMC_setBlockLength Failed\n");
        return (status);
    }

    return (status);
}