the unit of read/write offset and buffer size is changed to the block size in block device driver read/write interface.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@798 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
qiuyiuestc 2010-07-18 00:34:42 +00:00
parent d394761e22
commit 1e9996c0e5
1 changed files with 7 additions and 111 deletions

View File

@ -20,24 +20,12 @@ volatile rt_uint32_t rd_cnt;
volatile rt_uint32_t wt_cnt;
volatile rt_int32_t RCA;
/**
* This function will set a hook function, which will be invoked when a memory
* block is allocated from heap memory.
*
* @param hook the hook function
*/
static void sd_delay(rt_uint32_t ms)
{
ms *= 7326;
while(--ms);
}
/**
* This function will set a hook function, which will be invoked when a memory
* block is allocated from heap memory.
*
* @param hook the hook function
*/
static int sd_cmd_end(int cmd, int be_resp)
{
int finish0;
@ -88,12 +76,6 @@ static int sd_cmd_end(int cmd, int be_resp)
}
}
/**
* This function will set a hook function, which will be invoked when a memory
* block is allocated from heap memory.
*
* @param hook the hook function
*/
static int sd_data_end(void)
{
int finish;
@ -113,12 +95,6 @@ static int sd_data_end(void)
return RT_EOK;
}
/**
* This function will set a hook function, which will be invoked when a memory
* block is allocated from heap memory.
*
* @param hook the hook function
*/
static void sd_cmd0(void)
{
SDICARG=0x0;
@ -128,12 +104,6 @@ static void sd_cmd0(void)
SDICSTA=0x800; /* Clear cmd_end(no rsp) */
}
/**
* This function will set a hook function, which will be invoked when a memory
* block is allocated from heap memory.
*
* @param hook the hook function
*/
static int sd_cmd55(void)
{
SDICARG = RCA << 16;
@ -149,12 +119,6 @@ static int sd_cmd55(void)
return RT_EOK;
}
/**
* This function will set a hook function, which will be invoked when a memory
* block is allocated from heap memory.
*
* @param hook the hook function
*/
static void sd_sel_desel(char sel_desel)
{
if(sel_desel)
@ -182,12 +146,6 @@ RECMDD7:
}
}
/**
* This function will set a hook function, which will be invoked when a memory
* block is allocated from heap memory.
*
* @param hook the hook function
*/
static void sd_setbus(void)
{
do
@ -201,12 +159,6 @@ static void sd_setbus(void)
SDICSTA=0xa00; /* Clear cmd_end(with rsp) */
}
/**
* This function will set a hook function, which will be invoked when a memory
* block is allocated from heap memory.
*
* @param hook the hook function
*/
int sd_ocr(void)
{
int i;
@ -234,12 +186,6 @@ int sd_ocr(void)
return RT_ERROR;
}
/**
* This function will set a hook function, which will be invoked when a memory
* block is allocated from heap memory.
*
* @param hook the hook function
*/
rt_uint8_t sd_init(void)
{
//-- SD controller & card initialize
@ -295,12 +241,6 @@ RECMD3:
return RT_EOK;
}
/**
* This function will set a hook function, which will be invoked when a memory
* block is allocated from heap memory.
*
* @param hook the hook function
*/
rt_uint8_t sd_readblock(rt_uint32_t address, rt_uint8_t* buf)
{
int status;
@ -349,12 +289,6 @@ RERDCMD:
return RT_EOK;
}
/**
* This function will set a hook function, which will be invoked when a memory
* block is allocated from heap memory.
*
* @param hook the hook function
*/
rt_uint8_t sd_writeblock(rt_uint32_t address, rt_uint8_t* buf)
{
int status;
@ -401,56 +335,27 @@ REWTCMD:
struct rt_device sdcard_device[4];
struct dfs_partition part[4];
/**
* This function will set a hook function, which will be invoked when a memory
* block is allocated from heap memory.
*
* @param hook the hook function
*/
static rt_err_t rt_sdcard_init(rt_device_t dev)
{
return 0;
}
/**
* This function will set a hook function, which will be invoked when a memory
* block is allocated from heap memory.
*
* @param hook the hook function
*/
static rt_err_t rt_sdcard_open(rt_device_t dev, rt_uint16_t oflag)
{
return 0;
}
/**
* This function will set a hook function, which will be invoked when a memory
* block is allocated from heap memory.
*
* @param hook the hook function
*/
static rt_err_t rt_sdcard_close(rt_device_t dev)
{
return 0;
}
/**
* This function will set a hook function, which will be invoked when a memory
* block is allocated from heap memory.
*
* @param hook the hook function
*/
static rt_err_t rt_sdcard_control(rt_device_t dev, rt_uint8_t cmd, void *args)
{
return 0;
}
/**
* This function will set a hook function, which will be invoked when a memory
* block is allocated from heap memory.
*
* @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)
{
int i;
@ -463,10 +368,10 @@ static rt_size_t rt_sdcard_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_
}
/* read all sectors */
for (i = 0; i < size / SECTOR_SIZE; i ++)
for (i = 0; i < size; i ++)
{
rt_sem_take(part->lock, RT_WAITING_FOREVER);
sd_readblock((part->offset + i)*SECTOR_SIZE + pos,
sd_readblock((part->offset + i + pos)*SECTOR_SIZE,
(rt_uint8_t*)((rt_uint8_t*)buffer + i * SECTOR_SIZE));
rt_sem_release(part->lock);
}
@ -475,12 +380,6 @@ static rt_size_t rt_sdcard_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_
return size;
}
/**
* This function will set a hook function, which will be invoked when a memory
* block is allocated from heap memory.
*
* @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)
{
int i;
@ -493,10 +392,10 @@ static rt_size_t rt_sdcard_write (rt_device_t dev, rt_off_t pos, const void* buf
}
/* read all sectors */
for (i = 0; i < size / SECTOR_SIZE; i++)
for (i = 0; i < size; i++)
{
rt_sem_take(part->lock, RT_WAITING_FOREVER);
sd_writeblock((part->offset + i)*SECTOR_SIZE + pos,
sd_writeblock((part->offset + i + pos)*SECTOR_SIZE,
(rt_uint8_t*)((rt_uint8_t*)buffer + i * SECTOR_SIZE));
rt_sem_release(part->lock);
}
@ -505,11 +404,6 @@ static rt_size_t rt_sdcard_write (rt_device_t dev, rt_off_t pos, const void* buf
return size;
}
/**
* This function will register sd card to device system
*
* @param hook the hook function
*/
void rt_hw_sdcard_init()
{
rt_uint8_t i, status;
@ -549,6 +443,7 @@ void rt_hw_sdcard_init()
part[i].lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO);
/* register sdcard device */
sdcard_device[i].type = RT_Device_Class_Block;
sdcard_device[i].init = rt_sdcard_init;
sdcard_device[i].open = rt_sdcard_open;
sdcard_device[i].close = rt_sdcard_close;
@ -570,6 +465,7 @@ void rt_hw_sdcard_init()
part[0].lock = rt_sem_create("sem_sd0", 1, RT_IPC_FLAG_FIFO);
/* register sdcard device */
sdcard_device[0].type = RT_Device_Class_Block;
sdcard_device[0].init = rt_sdcard_init;
sdcard_device[0].open = rt_sdcard_open;
sdcard_device[0].close = rt_sdcard_close;