|
@@ -20,21 +20,21 @@ volatile rt_uint32_t wt_cnt;
|
|
volatile rt_int32_t RCA;
|
|
volatile rt_int32_t RCA;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
static void sd_delay(rt_uint32_t ms)
|
|
static void sd_delay(rt_uint32_t ms)
|
|
{
|
|
{
|
|
ms *= 7326;
|
|
ms *= 7326;
|
|
- while(--ms);
|
|
|
|
|
|
+ while(--ms);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
static int sd_cmd_end(int cmd, int be_resp)
|
|
static int sd_cmd_end(int cmd, int be_resp)
|
|
@@ -44,12 +44,12 @@ static int sd_cmd_end(int cmd, int be_resp)
|
|
if(!be_resp)
|
|
if(!be_resp)
|
|
{
|
|
{
|
|
finish0=SDICSTA;
|
|
finish0=SDICSTA;
|
|
-
|
|
|
|
|
|
+
|
|
while((finish0&0x800)!=0x800)
|
|
while((finish0&0x800)!=0x800)
|
|
finish0=SDICSTA;
|
|
finish0=SDICSTA;
|
|
|
|
|
|
SDICSTA=finish0;
|
|
SDICSTA=finish0;
|
|
-
|
|
|
|
|
|
+
|
|
return RT_EOK;
|
|
return RT_EOK;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -86,9 +86,9 @@ static int sd_cmd_end(int cmd, int be_resp)
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
static int sd_data_end(void)
|
|
static int sd_data_end(void)
|
|
@@ -109,9 +109,9 @@ static int sd_data_end(void)
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
static void sd_cmd0(void)
|
|
static void sd_cmd0(void)
|
|
@@ -123,9 +123,9 @@ static void sd_cmd0(void)
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
static int sd_cmd55(void)
|
|
static int sd_cmd55(void)
|
|
@@ -140,28 +140,28 @@ static int sd_cmd55(void)
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
static void sd_sel_desel(char sel_desel)
|
|
static void sd_sel_desel(char sel_desel)
|
|
{
|
|
{
|
|
if(sel_desel)
|
|
if(sel_desel)
|
|
{
|
|
{
|
|
-RECMDS7:
|
|
|
|
|
|
+RECMDS7:
|
|
SDICARG =RCA << 16;
|
|
SDICARG =RCA << 16;
|
|
SDICCON = (0x1 << 9) | (0x1 << 8) | 0x47;
|
|
SDICCON = (0x1 << 9) | (0x1 << 8) | 0x47;
|
|
|
|
|
|
if(sd_cmd_end(7, 1) == RT_ERROR)
|
|
if(sd_cmd_end(7, 1) == RT_ERROR)
|
|
goto RECMDS7;
|
|
goto RECMDS7;
|
|
-
|
|
|
|
|
|
+
|
|
if( SDIRSP0 & (0x1e00 != 0x800))
|
|
if( SDIRSP0 & (0x1e00 != 0x800))
|
|
goto RECMDS7;
|
|
goto RECMDS7;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
-RECMDD7:
|
|
|
|
|
|
+RECMDD7:
|
|
SDICARG=0<<16;
|
|
SDICARG=0<<16;
|
|
SDICCON=(0x1<<8)|0x47;
|
|
SDICCON=(0x1<<8)|0x47;
|
|
|
|
|
|
@@ -171,9 +171,9 @@ RECMDD7:
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
static void sd_setbus(void)
|
|
static void sd_setbus(void)
|
|
@@ -189,9 +189,9 @@ SET_BUS:
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
int sd_mmc_ocr(void)
|
|
int sd_mmc_ocr(void)
|
|
@@ -212,14 +212,14 @@ int sd_mmc_ocr(void)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
SDICSTA=0xa00;
|
|
SDICSTA=0xa00;
|
|
-
|
|
|
|
|
|
+
|
|
return RT_ERROR;
|
|
return RT_ERROR;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
int sd_ocr(void)
|
|
int sd_ocr(void)
|
|
@@ -242,26 +242,26 @@ int sd_ocr(void)
|
|
SDICSTA=0xa00;
|
|
SDICSTA=0xa00;
|
|
return RT_EOK;
|
|
return RT_EOK;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
sd_delay(200);
|
|
sd_delay(200);
|
|
}
|
|
}
|
|
SDICSTA=0xa00;
|
|
SDICSTA=0xa00;
|
|
-
|
|
|
|
|
|
+
|
|
return RT_ERROR;
|
|
return RT_ERROR;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
rt_uint8_t sd_init(void)
|
|
rt_uint8_t sd_init(void)
|
|
-{
|
|
|
|
|
|
+{
|
|
//-- SD controller & card initialize
|
|
//-- SD controller & card initialize
|
|
int i;
|
|
int i;
|
|
/* Important notice for MMC test condition */
|
|
/* Important notice for MMC test condition */
|
|
- /* Cmd & Data lines must be enabled by pull up resister */
|
|
|
|
|
|
+ /* Cmd & Data lines must be enabled by pull up resister */
|
|
SDIPRE=PCLK/(INICLK)-1;
|
|
SDIPRE=PCLK/(INICLK)-1;
|
|
SDICON=1;
|
|
SDICON=1;
|
|
SDIFSTA=SDIFSTA|(1<<16);
|
|
SDIFSTA=SDIFSTA|(1<<16);
|
|
@@ -293,18 +293,18 @@ rt_uint8_t sd_init(void)
|
|
RECMD2:
|
|
RECMD2:
|
|
SDICARG=0x0;
|
|
SDICARG=0x0;
|
|
SDICCON=(0x1<<10)|(0x1<<9)|(0x1<<8)|0x42;
|
|
SDICCON=(0x1<<10)|(0x1<<9)|(0x1<<8)|0x42;
|
|
- if(sd_cmd_end(2, 1) == RT_ERROR)
|
|
|
|
|
|
+ if(sd_cmd_end(2, 1) == RT_ERROR)
|
|
goto RECMD2;
|
|
goto RECMD2;
|
|
|
|
|
|
-RECMD3:
|
|
|
|
|
|
+RECMD3:
|
|
SDICARG=0<<16;
|
|
SDICARG=0<<16;
|
|
SDICCON=(0x1<<9)|(0x1<<8)|0x43;
|
|
SDICCON=(0x1<<9)|(0x1<<8)|0x43;
|
|
- if(sd_cmd_end(3, 1) == RT_ERROR)
|
|
|
|
|
|
+ if(sd_cmd_end(3, 1) == RT_ERROR)
|
|
goto RECMD3;
|
|
goto RECMD3;
|
|
|
|
|
|
RCA=(SDIRSP0 & 0xffff0000 )>>16;
|
|
RCA=(SDIRSP0 & 0xffff0000 )>>16;
|
|
SDIPRE=(PCLK/(SDCLK*2))-1;
|
|
SDIPRE=(PCLK/(SDCLK*2))-1;
|
|
- if( SDIRSP0 & (0x1e00!=0x600) )
|
|
|
|
|
|
+ if( SDIRSP0 & (0x1e00!=0x600) )
|
|
goto RECMD3;
|
|
goto RECMD3;
|
|
|
|
|
|
sd_sel_desel(1);
|
|
sd_sel_desel(1);
|
|
@@ -315,16 +315,16 @@ RECMD3:
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
rt_uint8_t sd_readblock(rt_uint32_t address, rt_uint8_t* buf)
|
|
rt_uint8_t sd_readblock(rt_uint32_t address, rt_uint8_t* buf)
|
|
{
|
|
{
|
|
int status;
|
|
int status;
|
|
|
|
|
|
- rd_cnt=0;
|
|
|
|
|
|
+ rd_cnt=0;
|
|
// SDICON |= (1<<1);
|
|
// SDICON |= (1<<1);
|
|
SDIDCON = (2 << 22) | (1 << 19) | (1 << 17) | (1 << 16) | (1 << 14) | (2 << 12) | (1 << 0);
|
|
SDIDCON = (2 << 22) | (1 << 19) | (1 << 17) | (1 << 16) | (1 << 14) | (2 << 12) | (1 << 0);
|
|
SDICARG = address;
|
|
SDICARG = address;
|
|
@@ -332,7 +332,7 @@ rt_uint8_t sd_readblock(rt_uint32_t address, rt_uint8_t* buf)
|
|
RERDCMD:
|
|
RERDCMD:
|
|
SDICCON = (0x1 << 9 ) | (0x1 << 8) | 0x51;
|
|
SDICCON = (0x1 << 9 ) | (0x1 << 8) | 0x51;
|
|
if(sd_cmd_end(17, 1) == RT_ERROR)
|
|
if(sd_cmd_end(17, 1) == RT_ERROR)
|
|
- goto RERDCMD;
|
|
|
|
|
|
+ goto RERDCMD;
|
|
|
|
|
|
SDICSTA = 0xa00;
|
|
SDICSTA = 0xa00;
|
|
|
|
|
|
@@ -376,16 +376,16 @@ RERDCMD:
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
rt_uint8_t sd_writeblock(rt_uint32_t address, rt_uint8_t* buf)
|
|
rt_uint8_t sd_writeblock(rt_uint32_t address, rt_uint8_t* buf)
|
|
{
|
|
{
|
|
int status;
|
|
int status;
|
|
|
|
|
|
- wt_cnt=0;
|
|
|
|
|
|
+ wt_cnt=0;
|
|
SDIFSTA = SDIFSTA | (1 << 16);
|
|
SDIFSTA = SDIFSTA | (1 << 16);
|
|
SDIDCON = (2 << 22) | (1 << 20) | (1 << 17) | (1 << 16) | (1 << 14) | (3 << 12) | (1 << 0);
|
|
SDIDCON = (2 << 22) | (1 << 20) | (1 << 17) | (1 << 16) | (1 << 14) | (3 << 12) | (1 << 0);
|
|
SDICARG = address;
|
|
SDICARG = address;
|
|
@@ -395,13 +395,13 @@ REWTCMD:
|
|
|
|
|
|
if(sd_cmd_end(24, 1) == RT_ERROR)
|
|
if(sd_cmd_end(24, 1) == RT_ERROR)
|
|
goto REWTCMD;
|
|
goto REWTCMD;
|
|
-
|
|
|
|
|
|
+
|
|
SDICSTA=0xa00;
|
|
SDICSTA=0xa00;
|
|
|
|
|
|
while(wt_cnt < 128*1)
|
|
while(wt_cnt < 128*1)
|
|
{
|
|
{
|
|
status = SDIFSTA;
|
|
status = SDIFSTA;
|
|
- if((status & 0x2000) == 0x2000)
|
|
|
|
|
|
+ if((status & 0x2000) == 0x2000)
|
|
{
|
|
{
|
|
SDIDAT=*(rt_uint32_t*)buf;
|
|
SDIDAT=*(rt_uint32_t*)buf;
|
|
wt_cnt++;
|
|
wt_cnt++;
|
|
@@ -412,7 +412,7 @@ REWTCMD:
|
|
{
|
|
{
|
|
rt_kprintf("Data Error\n");
|
|
rt_kprintf("Data Error\n");
|
|
return RT_ERROR;
|
|
return RT_ERROR;
|
|
- }
|
|
|
|
|
|
+ }
|
|
SDIDCON = SDIDCON &~ (7<<12);
|
|
SDIDCON = SDIDCON &~ (7<<12);
|
|
SDIDSTA = 0x10;
|
|
SDIDSTA = 0x10;
|
|
|
|
|
|
@@ -428,20 +428,20 @@ REWTCMD:
|
|
struct rt_device sdcard_device[4];
|
|
struct rt_device sdcard_device[4];
|
|
struct dfs_partition part[4];
|
|
struct dfs_partition part[4];
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
static rt_err_t rt_sdcard_init(rt_device_t dev)
|
|
static rt_err_t rt_sdcard_init(rt_device_t dev)
|
|
-{
|
|
|
|
|
|
+{
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
static rt_err_t rt_sdcard_open(rt_device_t dev, rt_uint16_t oflag)
|
|
static rt_err_t rt_sdcard_open(rt_device_t dev, rt_uint16_t oflag)
|
|
@@ -450,9 +450,9 @@ static rt_err_t rt_sdcard_open(rt_device_t dev, rt_uint16_t oflag)
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
static rt_err_t rt_sdcard_close(rt_device_t dev)
|
|
static rt_err_t rt_sdcard_close(rt_device_t dev)
|
|
@@ -461,9 +461,9 @@ static rt_err_t rt_sdcard_close(rt_device_t dev)
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
static rt_err_t rt_sdcard_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
|
static rt_err_t rt_sdcard_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
|
@@ -472,9 +472,9 @@ static rt_err_t rt_sdcard_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
static rt_size_t rt_sdcard_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
|
|
static rt_size_t rt_sdcard_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
|
|
@@ -482,49 +482,58 @@ static rt_size_t rt_sdcard_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_
|
|
int i;
|
|
int i;
|
|
struct dfs_partition *part = (struct dfs_partition *)dev->private;
|
|
struct dfs_partition *part = (struct dfs_partition *)dev->private;
|
|
|
|
|
|
- if ( dev == RT_NULL ) return -DFS_STATUS_EINVAL;
|
|
|
|
-
|
|
|
|
|
|
+ if ( dev == RT_NULL )
|
|
|
|
+ {
|
|
|
|
+ rt_set_errno(-DFS_STATUS_EINVAL);
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
/* read all sectors */
|
|
/* read all sectors */
|
|
for (i = 0; i < size / SECTOR_SIZE; i ++)
|
|
for (i = 0; i < size / SECTOR_SIZE; i ++)
|
|
{
|
|
{
|
|
rt_sem_take(part->lock, RT_WAITING_FOREVER);
|
|
rt_sem_take(part->lock, RT_WAITING_FOREVER);
|
|
- sd_readblock((part->offset + i)*SECTOR_SIZE + pos,
|
|
|
|
- (rt_uint8_t*)(buffer + i * SECTOR_SIZE));
|
|
|
|
|
|
+ sd_readblock((part->offset + i)*SECTOR_SIZE + pos,
|
|
|
|
+ (rt_uint8_t*)((rt_uint8_t*)buffer + i * SECTOR_SIZE));
|
|
rt_sem_release(part->lock);
|
|
rt_sem_release(part->lock);
|
|
}
|
|
}
|
|
|
|
+
|
|
/* the length of reading must align to SECTOR SIZE */
|
|
/* the length of reading must align to SECTOR SIZE */
|
|
return size;
|
|
return size;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will set a hook function, which will be invoked when a memory
|
|
|
|
|
|
+ * This function will set a hook function, which will be invoked when a memory
|
|
* block is allocated from heap memory.
|
|
* block is allocated from heap memory.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
-static rt_size_t rt_sdcard_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size)
|
|
|
|
|
|
+static rt_size_t rt_sdcard_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size)
|
|
{
|
|
{
|
|
int i;
|
|
int i;
|
|
struct dfs_partition *part = (struct dfs_partition *)dev->private;
|
|
struct dfs_partition *part = (struct dfs_partition *)dev->private;
|
|
|
|
|
|
- if ( dev == RT_NULL ) return -DFS_STATUS_EINVAL;
|
|
|
|
-
|
|
|
|
|
|
+ if ( dev == RT_NULL )
|
|
|
|
+ {
|
|
|
|
+ rt_set_errno(-DFS_STATUS_EINVAL);
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
/* read all sectors */
|
|
/* read all sectors */
|
|
for (i = 0; i < size / SECTOR_SIZE; i++)
|
|
for (i = 0; i < size / SECTOR_SIZE; i++)
|
|
{
|
|
{
|
|
rt_sem_take(part->lock, RT_WAITING_FOREVER);
|
|
rt_sem_take(part->lock, RT_WAITING_FOREVER);
|
|
- sd_writeblock((part->offset + i)*SECTOR_SIZE + pos,
|
|
|
|
- (rt_uint8_t*)(buffer + i * SECTOR_SIZE));
|
|
|
|
|
|
+ sd_writeblock((part->offset + i)*SECTOR_SIZE + pos,
|
|
|
|
+ (rt_uint8_t*)((rt_uint8_t*)buffer + i * SECTOR_SIZE));
|
|
rt_sem_release(part->lock);
|
|
rt_sem_release(part->lock);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/* the length of reading must align to SECTOR SIZE */
|
|
/* the length of reading must align to SECTOR SIZE */
|
|
return size;
|
|
return size;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* This function will register sd card to device system
|
|
* This function will register sd card to device system
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param hook the hook function
|
|
* @param hook the hook function
|
|
*/
|
|
*/
|
|
void rt_hw_sdcard_init()
|
|
void rt_hw_sdcard_init()
|
|
@@ -532,13 +541,13 @@ void rt_hw_sdcard_init()
|
|
rt_uint8_t i, status;
|
|
rt_uint8_t i, status;
|
|
rt_uint8_t *sector;
|
|
rt_uint8_t *sector;
|
|
char dname[4];
|
|
char dname[4];
|
|
- char sname[8];
|
|
|
|
-
|
|
|
|
|
|
+ char sname[8];
|
|
|
|
+
|
|
if (sd_init() == RT_EOK)
|
|
if (sd_init() == RT_EOK)
|
|
{
|
|
{
|
|
/* get the first sector to read partition table */
|
|
/* get the first sector to read partition table */
|
|
sector = (rt_uint8_t*) rt_malloc (512);
|
|
sector = (rt_uint8_t*) rt_malloc (512);
|
|
- if (sector == RT_NULL)
|
|
|
|
|
|
+ if (sector == RT_NULL)
|
|
{
|
|
{
|
|
rt_kprintf("allocate partition sector buffer failed\n");
|
|
rt_kprintf("allocate partition sector buffer failed\n");
|
|
return;
|
|
return;
|
|
@@ -554,7 +563,7 @@ void rt_hw_sdcard_init()
|
|
{
|
|
{
|
|
rt_snprintf(dname, 4, "sd%d", i);
|
|
rt_snprintf(dname, 4, "sd%d", i);
|
|
rt_snprintf(sname, 8, "sem_sd%d", i);
|
|
rt_snprintf(sname, 8, "sem_sd%d", i);
|
|
- part[i].lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO);
|
|
|
|
|
|
+ part[i].lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO);
|
|
|
|
|
|
/* register sdcard device */
|
|
/* register sdcard device */
|
|
sdcard_device[i].init = rt_sdcard_init;
|
|
sdcard_device[i].init = rt_sdcard_init;
|
|
@@ -565,17 +574,17 @@ void rt_hw_sdcard_init()
|
|
sdcard_device[i].control = rt_sdcard_control;
|
|
sdcard_device[i].control = rt_sdcard_control;
|
|
sdcard_device[i].private= &part[i];
|
|
sdcard_device[i].private= &part[i];
|
|
|
|
|
|
- rt_device_register(&sdcard_device[i], dname,
|
|
|
|
|
|
+ rt_device_register(&sdcard_device[i], dname,
|
|
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
|
|
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
|
|
}
|
|
}
|
|
- else
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
if(i == 0)
|
|
if(i == 0)
|
|
{
|
|
{
|
|
/* there is no partition table */
|
|
/* there is no partition table */
|
|
part[0].offset = 0;
|
|
part[0].offset = 0;
|
|
part[0].size = 0;
|
|
part[0].size = 0;
|
|
- part[0].lock = rt_sem_create("sem_sd0", 1, RT_IPC_FLAG_FIFO);
|
|
|
|
|
|
+ part[0].lock = rt_sem_create("sem_sd0", 1, RT_IPC_FLAG_FIFO);
|
|
|
|
|
|
/* register sdcard device */
|
|
/* register sdcard device */
|
|
sdcard_device[0].init = rt_sdcard_init;
|
|
sdcard_device[0].init = rt_sdcard_init;
|
|
@@ -586,13 +595,13 @@ void rt_hw_sdcard_init()
|
|
sdcard_device[0].control = rt_sdcard_control;
|
|
sdcard_device[0].control = rt_sdcard_control;
|
|
sdcard_device[0].private= &part[0];
|
|
sdcard_device[0].private= &part[0];
|
|
|
|
|
|
- rt_device_register(&sdcard_device[0], "sd0",
|
|
|
|
|
|
+ rt_device_register(&sdcard_device[0], "sd0",
|
|
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
|
|
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
|
|
|
|
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -601,7 +610,7 @@ void rt_hw_sdcard_init()
|
|
|
|
|
|
/* release sector buffer */
|
|
/* release sector buffer */
|
|
rt_free(sector);
|
|
rt_free(sector);
|
|
-
|
|
|
|
|
|
+
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
else
|