Esempio n. 1
0
DRESULT disk_write (BYTE drv,const BYTE* buff,DWORD sector,BYTE count)
{
u8 res;

    if (drv || !count)
    {    
        return RES_PARERR;  //仅支持单磁盘操作,count不能等于0,否则返回参数错误
    }
  	if(SD_Insert_Status())
    {
        return RES_NOTRDY;  //没有检测到SD卡,报NOT READY错误
    }

    // 读写操作
    if(count == 1)
    {
        res = SD_WriteSingleBlock(sector, buff);
    }
    else
    {
        res = SD_WriteMultiBlock(sector, buff, count);
    }
    // 返回值转换
    if(res == 0)
    {
        return RES_OK;
    }
    else
    {
        return RES_ERROR;
    }
}
Esempio n. 2
0
/***************************SD卡写入***********************************/
void Sd_X(void)
{
	uint8_t i;
	for(i=0;i<=127;i++) Send_Data[i] = 0;
	for(i=0;i<=127;i++) Send_Data[i] = Pixel[i];
	Send_Data[197] = Left;
	Send_Data[198] = Right;
	Send_Data[199] = Center;
	while(SD_WriteSingleBlock(SD_X,Send_Data) != ESDHC_OK);
	SD_X++;
}
Esempio n. 3
0
DRESULT disk_write (
	BYTE drv,			/* Physical drive nmuber (0..) */
	const BYTE *buff,	/* Data to be written */
	DWORD sector,		/* Sector address (LBA) */
	BYTE count			/* Number of sectors to write (1..255) */
)
{
	u8 res;

    if (drv || !count)
    {    
        return RES_PARERR;  // only supports single disk operation, count is not equal to 0, otherwise parameter error
    }
	/*
    if(!SD_DET())
    {
        return RES_NOTRDY;  // does not detect SD card, NOT READY error reported
    }  */

    // Read and write operations
    if(count == 1)
    {
        res = SD_WriteSingleBlock(sector, buff);
    }
    else
    {
        res = SD_WriteMultiBlock(sector, buff, count);
    }
    // Return value to
    if(res == 0)
    {
        return RES_OK;
    }
    else
    {
        return RES_ERROR;
    }
}
Esempio n. 4
0
DRESULT disk_write (
	BYTE drv,			/* Physical drive nmuber (0..) */
	const BYTE *buff,	/* Data to be written */
	DWORD sector,		/* Sector address (LBA) */
	BYTE count			/* Number of sectors to write (1..255) */
)
{
	u8 res;

    if (drv || !count)
    {    
        return RES_PARERR;  //仅支持单磁盘操作,count不能等于0,否则返回参数错误
    }
    if(!SD_DET())
    {
        return RES_NOTRDY;  //没有检测到SD卡,报NOT READY错误
    }

    // 读写操作
    if(count == 1)
    {
        res = SD_WriteSingleBlock(sector, buff);
    }
    else
    {
        res = SD_WriteMultiBlock(sector, buff, count);
    }
    // 返回值转换
    if(res == 0)
    {
        return RES_OK;
    }
    else
    {
        return RES_ERROR;
    }
}
Esempio n. 5
0
void SDCardReadWriteTextTask(void* parameters)
{
	uint8_t outbuf[512];
	uint8_t inbuf[512];
	int i;

	//LED_LowLevel_Init();
	//UART_LowLevel_Init();
	SD_LowLevel_Init();   //Initialize PINS, vector table and SDIO interface
	//UART_SendLine("Ready...Steady\n");

	printf("SSD\n\r");
	LEDOn(LED2);

	//Initialize the SD
	SD_Init();  //After return from this function sd is in transfer mode.
	//UART_SendLine("GO\n");

	printf("SDI\n\r");
	LEDOff(LED2);

	//Write a single block to the SD
	for (i=0;i<512;i++) {
		outbuf[i]='a';
	}

	//Single Block Test
	SD_WriteSingleBlock(outbuf, 3000);
	SD_ReadSingleBlock(inbuf, 3000);
	//UART_SendLine("First Block\n");
	//UART_Send(inbuf,512);
	printf("\n\r%s", "First Block");
	printf("\n\r%i,%i,%i,%i", (int)inbuf[0], (int)inbuf[1], (int)inbuf[2], (int)inbuf[3]);

	SD_WriteSingleBlock(outbuf, 3001);
	SD_ReadSingleBlock(inbuf, 3001);
	//UART_SendLine("Second Block\n");
	//UART_Send(inbuf,512);
	printf("\n\r%s", "Second Block");
	printf("\n\r%i,%i,%i,%i", (int)inbuf[0], (int)inbuf[1], (int)inbuf[2], (int)inbuf[3]);

	//Multiple block
	SD_StartMultipleBlockWrite(1000);
	SD_WriteData(outbuf,500);
	SD_WriteData(outbuf+50,50);
	SD_WriteData(outbuf,500);
	SD_StopMultipleBlockWrite();


	SD_ReadSingleBlock(inbuf, 1000);
	//UART_SendLine("Mult. Block 1\n");
	//UART_Send(inbuf,512);
	printf("\n\r%s", "Mult. Block 1");
	printf("\n\r%i,%i,%i,%i", (int)inbuf[0], (int)inbuf[1], (int)inbuf[2], (int)inbuf[3]);
	SD_WaitTransmissionEnd();
	SD_ReadSingleBlock(inbuf, 1001);
	//UART_SendLine("Mult. Block 2\n");
	//UART_Send(inbuf,512);
	printf("\n\r%s", "Mult. Block 2");
	printf("\n\r%i,%i,%i,%i", (int)inbuf[0], (int)inbuf[1], (int)inbuf[2], (int)inbuf[3]);

//	LEDOn(LED6);

	portTickType lastExecutionTime = xTaskGetTickCount();
	for (;;)
	{
		DelayUntilTime( &lastExecutionTime, SDCardReadWriteTextTaskT);

	}
}
Esempio n. 6
0
/*-----------------------------------*/
static int  WriteSectors(void * DriveData, DWORD Sector, UINT Sectors, void * Buffer)
{
    SDC_CMD_STATUS status;
    kal_uint8 retry = 0;
    kal_uint32 adrs;

#if defined(__SIM_PLUS__)
    sd_select_enum sel;

    if((MSDC_HANDLE *)DriveData == &MSDC_Blk[0])
        sel = SD_EXT;
    else
        sel = SD_SIM;
    MSDC_Switch_Card(sel);
#endif

#if defined(SD_MMC_HIGH_DENSITY_SUPPORT)
    if(gSD->flags & SD_FLAG_HCS_SUPPORT)
        adrs = Sector;
    else
#endif
        adrs = Sector * SECTOR_SIZE;
    gMSDC_Handle->timeout_count = 0;
start:
    if(!gMSDC_Handle->mIsInitialized)
    {
        //dbg_print("Write but not Initialized \r\n");
        MSDC_PDNControl(KAL_TRUE);
        return FS_MSDC_WRITE_SECTOR_ERROR;
    }
    retry++;
    MSDC_PDNControl(KAL_FALSE);
#ifndef LSD_SINGLE_WRITE
    if(Sectors > 1)
    {
        if(gMSDC_Handle->mMSDC_type == SD_CARD)
            SD_SetPreEraseBlk(Sectors);
        status = SD_WriteMultiBlock((kal_uint32)adrs,(kal_uint32*)Buffer,(kal_uint32)Sectors);
    }
    else
        status = SD_WriteSingleBlock((kal_uint32)adrs,(kal_uint32*)Buffer);
#else
    while(Sectors) {
        status = SD_WriteSingleBlock((kal_uint32)adrs,(kal_uint32*)Buffer);

        if(status != NO_ERROR )
            break;
        (kal_uint8 *)Buffer += SECTOR_SIZE;
        Sector ++;
#if defined(SD_MMC_HIGH_DENSITY_SUPPORT)
        if(gSD->flags & SD_FLAG_HCS_SUPPORT)
            adrs = Sector;
        else
#endif
            adrs = Sector * SECTOR_SIZE;

        Sectors--;
    }
#endif
    if(status != NO_ERROR)
    {
        sd_w++;
        if(kal_query_systemInit()== KAL_TRUE)
        {
            MSDC_PDNControl(KAL_TRUE);
            return FS_MSDC_WRITE_SECTOR_ERROR;
        }
        //dbg_print("write retry:%d,status:%d,total %d\r\n",retry,status,sd_w);
        if(status == ERR_CMD_TIMEOUT || status == MSDC_GPT_TIMEOUT_ERR)
            gMSDC_Handle->timeout_count++;
        if(gMSDC_Handle->timeout_count++ == 3 && gMSDC_Handle->mIsPresent == KAL_TRUE)
        {
            kal_print("[MSDC]:SD re-mount (write fail)");
            gMSDC_Handle->mIsInitialized = KAL_FALSE;
            retry = 0;
            if(SD_Initialize() != NO_ERROR)
            {
                MSDC_PDNControl(KAL_TRUE);
                return FS_MSDC_WRITE_SECTOR_ERROR;
            }
        }
        if(retry >= SD_MAX_RETRY)
        {
            MSDC_PDNControl(KAL_TRUE);
            return FS_MSDC_WRITE_SECTOR_ERROR;
        }
        else
        {
            // kal_prompt_trace(MOD_AUD,"CRC write Error retry %d",retry);
            goto start;
        }
    }
    MSDC_PDNControl(KAL_TRUE);
    return FS_NO_ERROR;
}