remove alignment memory allocation from SDIO framework.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1995 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong@gmail.com 2012-03-14 07:59:50 +00:00
parent 484af67a52
commit 7022b8285f
3 changed files with 16 additions and 52 deletions

View File

@ -154,25 +154,7 @@ static rt_err_t rt_mmcsd_req_blk(struct rt_mmcsd_card *card, rt_uint32_t sector,
}
mmcsd_set_data_timeout(&data, card);
if (((rt_uint32_t)buf & (32 - 1)) != 0) /* the buf address is not aligned to 32 */
{
aligned_buf = rt_malloc_align(data.blks * data.blksize, 32);
if (aligned_buf == RT_NULL)
{
rt_kprintf("allocate memory failed\n");
return -RT_ENOMEM;
}
if (dir)//write
rt_memcpy(aligned_buf, buf, data.blks*data.blksize);
data.buf = aligned_buf;
}
else
data.buf = buf;
mmcsd_send_request(host, &req);
if (!controller_is_spi(card->host) && dir != 0)
@ -206,19 +188,9 @@ static rt_err_t rt_mmcsd_req_blk(struct rt_mmcsd_card *card, rt_uint32_t sector,
rt_kprintf("mmcsd request blocks error\n");
rt_kprintf("%d,%d,%d, 0x%08x,0x%08x\n", cmd.err, data.err, stop.err, data.flags, sector);
if (((rt_uint32_t)buf & (32 - 1)) != 0)
rt_free_align(aligned_buf);
return -RT_ERROR;
}
if (((rt_uint32_t)buf & (32 - 1)) != 0)
{
if (!dir)//read
rt_memcpy(buf, data.buf, data.blks*data.blksize);
rt_free_align(aligned_buf);
}
return RT_EOK;
}
@ -257,7 +229,7 @@ static rt_size_t rt_mmcsd_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_s
struct mmcsd_blk_device *blk_dev = (struct mmcsd_blk_device *)dev->user_data;
struct dfs_partition *part = &blk_dev->part;
if ( dev == RT_NULL )
if (dev == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EINVAL);
return 0;
@ -342,7 +314,7 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
}
/* get the first sector to read partition table */
sector = (rt_uint8_t *)rt_malloc_align(SECTOR_SIZE, 32);
sector = (rt_uint8_t *) rt_malloc(SECTOR_SIZE);
if (sector == RT_NULL)
{
rt_kprintf("allocate partition sector buffer failed\n");
@ -444,7 +416,7 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
}
/* release sector buffer */
rt_free_align(sector);
rt_free(sector);
return err;
}

View File

@ -175,10 +175,10 @@ rt_int32_t mmcsd_get_cid(struct rt_mmcsd_host *host, rt_uint32_t *cid)
return 0;
}
buf = rt_malloc_align(16, 32);
buf = (rt_uint8_t *)rt_malloc(16);
if (!buf)
{
rt_kprintf("malloc mem failed\n");
rt_kprintf("allocate memory failed\n");
return -RT_ENOMEM;
}
@ -214,13 +214,13 @@ rt_int32_t mmcsd_get_cid(struct rt_mmcsd_host *host, rt_uint32_t *cid)
if (cmd.err || data.err)
{
rt_free_align(buf);
rt_free(buf);
return -RT_ERROR;
}
for (i = 0;i < 4;i++)
cid[i] = buf[i];
rt_free_align(buf);
rt_free(buf);
return 0;
}
@ -248,10 +248,10 @@ rt_int32_t mmcsd_get_csd(struct rt_mmcsd_card *card, rt_uint32_t *csd)
return 0;
}
buf = rt_malloc_align(16, 32);
buf = (rt_uint8_t*)rt_malloc(16);
if (!buf)
{
rt_kprintf("malloc mem failed\n");
rt_kprintf("allocate memory failed\n");
return -RT_ENOMEM;
}
@ -288,13 +288,13 @@ rt_int32_t mmcsd_get_csd(struct rt_mmcsd_card *card, rt_uint32_t *csd)
if (cmd.err || data.err)
{
rt_free_align(buf);
rt_free(buf);
return -RT_ERROR;
}
for (i = 0;i < 4;i++)
csd[i] = buf[i];
rt_free_align(buf);
rt_free(buf);
return 0;
}

View File

@ -179,14 +179,13 @@ static rt_int32_t mmcsd_switch(struct rt_mmcsd_card *card)
struct rt_mmcsd_data data;
rt_uint8_t *buf;
buf = rt_malloc_align(64, 32);
buf = (rt_uint8_t*)rt_malloc(64);
if (!buf)
{
rt_kprintf("alloc memory failed\n");
return -RT_ENOMEM;
}
if (card->card_type != CARD_TYPE_SD)
goto err;
if (card->scr.sd_version < SCR_SPEC_VER_1)
@ -258,19 +257,12 @@ static rt_int32_t mmcsd_switch(struct rt_mmcsd_card *card)
card->flags |= CARD_FLAG_HIGHSPEED;
err:
rt_free_align(buf);
rt_free(buf);
return 0;
err1:
if (cmd.err)
{
err = cmd.err;
}
if (data.err)
{
err = data.err;
}
if (cmd.err) err = cmd.err;
if (data.err) err = data.err;
return err;
}