提交 885045ef 编写于 作者: B bernard.xiong

add semaphore to protect sdcard driver read and write; fix window keyboard event handler.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@177 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 719f9237
......@@ -2966,6 +2966,7 @@ static void DMA_RxConfiguration(uint32_t *BufferDST, uint32_t BufferSize)
static struct rt_device sdcard_device;
static SD_CardInfo SDCardInfo;
static struct dfs_partition part;
static struct rt_semaphore sd_lock;
/* RT-Thread Device Driver Interface */
static rt_err_t rt_sdcard_init(rt_device_t dev)
......@@ -2978,6 +2979,11 @@ static rt_err_t rt_sdcard_init(rt_device_t dev)
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
if (rt_sem_init(&sd_lock, "sdlock", 1, RT_IPC_FLAG_FIFO) != RT_EOK)
{
rt_kprintf("init sd lock semaphore failed\n");
}
return RT_EOK;
}
......@@ -3001,6 +3007,7 @@ static rt_size_t rt_sdcard_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_
// rt_kprintf("read: 0x%x, size %d\n", pos, size);
rt_sem_take(&sd_lock, RT_WAITING_FOREVER);
retry = 3;
/* read all sectors */
for (i = 0; i < size / SECTOR_SIZE; i ++)
......@@ -3012,14 +3019,15 @@ __retry:
if (status != SD_OK)
{
if (--retry != 0) goto __retry;
rt_kprintf("sd card read failed, status 0x%08x\n", status);
return 0;
break;
}
}
rt_sem_release(&sd_lock);
if (status == SD_OK) return size;
rt_kprintf("read failed: %d\n", status);
rt_kprintf("read failed: %d, buffer 0x%08x\n", status, buffer);
return 0;
}
......@@ -3030,7 +3038,9 @@ static rt_size_t rt_sdcard_write (rt_device_t dev, rt_off_t pos, const void* buf
// rt_kprintf("write: 0x%x, size %d\n", pos, size);
/* read all sectors */
rt_sem_take(&sd_lock, RT_WAITING_FOREVER);
/* write all sectors */
for (i = 0; i < size / SECTOR_SIZE; i ++)
{
status = SD_WriteBlock((part.offset + i)* SECTOR_SIZE + pos,
......@@ -3039,13 +3049,14 @@ static rt_size_t rt_sdcard_write (rt_device_t dev, rt_off_t pos, const void* buf
if (status != SD_OK)
{
rt_kprintf("sd card write failed\n");
return 0;
break;
}
}
rt_sem_release(&sd_lock);
if (status == SD_OK) return size;
rt_kprintf("write failed: %d\n", status);
rt_kprintf("write failed: %d, buffer 0x%08x\n", status, buffer);
return 0;
}
......@@ -3119,3 +3130,4 @@ void rt_hw_sdcard_init()
__return:
rt_kprintf("sdcard init failed\n");
}
......@@ -275,7 +275,7 @@ const unsigned char asc16_font[] = {
struct rtgui_font_bitmap asc16 =
{
asc16_font, /* bmp */
(const rt_uint8_t*)asc16_font, /* bmp */
8, /* width */
16, /* height */
0, /* first char */
......
......@@ -190,12 +190,12 @@ struct rtgui_filerw_mem
/* inherit from rtgui_filerw */
struct rtgui_filerw parent;
rt_uint8_t *mem_base, *mem_position, *mem_end;
const rt_uint8_t *mem_base, *mem_position, *mem_end;
};
static int mem_seek(struct rtgui_filerw *context, rt_off_t offset, int whence)
{
rt_uint8_t* newpos;
const rt_uint8_t* newpos;
struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
RT_ASSERT(mem != RT_NULL);
......@@ -250,7 +250,8 @@ static int mem_read(struct rtgui_filerw *context, void *ptr, rt_size_t size, rt_
}
static int mem_write(struct rtgui_filerw *context, const void *ptr, rt_size_t size, rt_size_t num)
{
{
#if 0
struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
if ((mem->mem_position + (num * size)) > mem->mem_end)
......@@ -261,7 +262,10 @@ static int mem_write(struct rtgui_filerw *context, const void *ptr, rt_size_t si
rt_memcpy(mem->mem_position, ptr, num*size);
mem->mem_position += num*size;
return num;
return num;
#else
return 0; /* not support memory write */
#endif
}
static int mem_tell(struct rtgui_filerw* context)
......@@ -291,7 +295,7 @@ static int mem_close(struct rtgui_filerw *context)
return -1;
}
rt_uint8_t* rtgui_filerw_mem_getdata(struct rtgui_filerw* context)
const rt_uint8_t* rtgui_filerw_mem_getdata(struct rtgui_filerw* context)
{
struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
......@@ -383,7 +387,7 @@ struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char*
}
#endif
struct rtgui_filerw* rtgui_filerw_create_mem(rt_uint8_t* mem, rt_size_t size)
struct rtgui_filerw* rtgui_filerw_create_mem(const rt_uint8_t* mem, rt_size_t size)
{
struct rtgui_filerw_mem* rw;
RT_ASSERT(mem != RT_NULL);
......
......@@ -122,7 +122,7 @@ struct rtgui_image* rtgui_image_create_from_mem(const char* type, const rt_uint8
struct rtgui_image* image = RT_NULL;
/* create filerw context */
filerw = rtgui_filerw_create_mem((rt_uint8_t*)data, length);
filerw = rtgui_filerw_create_mem(data, length);
if (filerw == RT_NULL) return RT_NULL;
/* get image engine */
......
......@@ -32,7 +32,7 @@ struct rtgui_filerw
typedef struct rtgui_filerw rtgui_filerw_t;
struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode);
struct rtgui_filerw* rtgui_filerw_create_mem(rt_uint8_t* mem, rt_size_t size);
struct rtgui_filerw* rtgui_filerw_create_mem(const rt_uint8_t* mem, rt_size_t size);
int rtgui_filerw_seek (struct rtgui_filerw* context, rt_off_t offset, int whence);
int rtgui_filerw_read (struct rtgui_filerw* context, void* buffer, rt_size_t size, rt_size_t count);
......@@ -42,6 +42,6 @@ int rtgui_filerw_eof (struct rtgui_filerw* context);
int rtgui_filerw_close(struct rtgui_filerw* context);
/* get memory data from filerw memory object */
rt_uint8_t* rtgui_filerw_mem_getdata(struct rtgui_filerw* context);
const rt_uint8_t* rtgui_filerw_mem_getdata(struct rtgui_filerw* context);
#endif
......@@ -430,6 +430,13 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_even
#endif
break;
case RTGUI_EVENT_KBD:
if (RTGUI_CONTAINER(win)->focused != widget)
{
RTGUI_CONTAINER(win)->focused->event_handler(RTGUI_CONTAINER(win)->focused, event);
}
break;
default:
/* call parent event handler */
return rtgui_toplevel_event_handler(widget, event);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册