Esempio n. 1
0
void rtgui_fileview_get_fullpath(rtgui_fileview_t* view, char* path, rt_size_t len)
{
	RT_ASSERT(view != RT_NULL);

	if(view->current_dir[strlen(view->current_dir) - 1] != PATH_SEPARATOR)
		rt_snprintf(path, len, "%s%c%s",view->current_dir, PATH_SEPARATOR,
		            view->items[view->now_item].name);
	else
		rt_snprintf(path, len, "%s%s",view->current_dir,
		            view->items[view->now_item].name);
}
void play_list_append(char* fn)
{
	int media;
	char *ptr;

    play_list_size ++;
	if (play_list == RT_NULL)
		play_list = (struct play_item*) rt_malloc (play_list_size * sizeof(struct play_item));
	else
    	play_list = (struct play_item*) rt_realloc(play_list, play_list_size * sizeof(struct play_item));

	media = media_type(fn);
	if (media == MEDIA_MP3)
	{
		struct tag_info info;

		memset(&info, 0, sizeof(info));
		mp3_get_info(fn, &info);
		
		ptr = strrchr(fn, '/'); //WP MCU工作室
		rt_snprintf(play_list[play_list_size - 1].title, sizeof(play_list[play_list_size - 1].title),
				ptr+1);
		
		/*
		if (info.title[0] == '\0')
			rt_snprintf(play_list[play_list_size - 1].title, sizeof(play_list[play_list_size - 1].title),
				"<未知名音乐>");
		else
			strcpy(play_list[play_list_size - 1].title, info.title);
		*/
		play_list[play_list_size - 1].fn = rt_strdup(fn);
		play_list[play_list_size - 1].duration = info.duration;
	}
	else if (media == MEDIA_RADIO)
	{
		rt_snprintf(play_list[play_list_size - 1].title, sizeof(play_list[play_list_size - 1].title),
			"<未知名电台>");
		play_list[play_list_size - 1].fn = rt_strdup(fn);
		play_list[play_list_size - 1].duration = 0;
	}
	else if (media == MEDIA_WAV)
	{
		struct tag_info info;
		memset(&info, 0, sizeof(info));
		
		get_wav_info(fn, &info);
		ptr = strrchr(fn, '/'); //UP MCU工作室
		rt_snprintf(play_list[play_list_size - 1].title, sizeof(play_list[play_list_size - 1].title),
				ptr+1);
		play_list[play_list_size - 1].fn = rt_strdup(fn);
		play_list[play_list_size - 1].duration = info.duration;
	}
}
Esempio n. 3
0
static void _lg_fmtout(
        struct log_trace_session *session, const char *fmt, va_list argptr)
{
    /* 1 for ']' */
    static char _trace_buf[1+LOG_TRACE_BUFSZ];
    char *ptr;
    rt_size_t length;

    RT_ASSERT(session);
    RT_ASSERT(fmt);

    rt_snprintf(_trace_buf, sizeof(_trace_buf), "[%08x][", rt_tick_get());
    if (_traceout_device != RT_NULL)
    {
        rt_device_write(_traceout_device, -1, _trace_buf, 11);
        rt_device_write(_traceout_device, -1,
                session->id.name, _idname_len(session->id.num));
    }

    _trace_buf[0] = ']';
    ptr = &_trace_buf[1];
    length = rt_vsnprintf(ptr, LOG_TRACE_BUFSZ, fmt, argptr);

    if (length >= LOG_TRACE_BUFSZ)
        length = LOG_TRACE_BUFSZ - 1;

    if (_traceout_device != RT_NULL)
    {
        rt_device_write(_traceout_device, -1, _trace_buf, length + 1);
    }
}
Esempio n. 4
0
/**
 * This function will initialize hardware interrupt
 */
void rt_hw_interrupt_init(void)
{
    rt_int32_t i;
    register rt_uint32_t idx;
    rt_uint32_t *priority = at91sam9260_default_irq_priority;
    
    at91_extern_irq = (1 << AT91SAM9260_ID_IRQ0) | (1 << AT91SAM9260_ID_IRQ1)
            | (1 << AT91SAM9260_ID_IRQ2);

    /* Initialize the AIC interrupt controller */
    at91_aic_init(priority);

    /* init exceptions table */
    for(idx=0; idx < MAX_HANDLERS; idx++)
    {
        rt_snprintf(irq_desc[idx].name, RT_NAME_MAX - 1, "default");
        irq_desc[idx].handler = (rt_isr_handler_t)rt_hw_interrupt_handle;
        irq_desc[idx].param = RT_NULL;
		irq_desc[idx].counter = 0;
    }

    at91_gpio_irq_init();

    /* init interrupt nest, and context in thread sp */
    rt_interrupt_nest = 0;
    rt_interrupt_from_thread = 0;
    rt_interrupt_to_thread = 0;
    rt_thread_switch_interrupt_flag = 0;
}
Esempio n. 5
0
int dfs_elm_rename(struct dfs_filesystem *fs, const char *oldpath, const char *newpath)
{
	FRESULT result;

#if _VOLUMES > 1
	char *drivers_oldfn;
	const char *drivers_newfn;
	int vol;
	extern int elm_get_vol(FATFS *fat);

	/* add path for ELM FatFS driver support */
	vol = elm_get_vol((FATFS *)fs->data);
	if (vol < 0)
		return -DFS_STATUS_ENOENT;

	drivers_oldfn = rt_malloc(256);
	if (drivers_oldfn == RT_NULL)
		return -DFS_STATUS_ENOMEM;
	drivers_newfn = newpath;

	rt_snprintf(drivers_oldfn, 256, "%d:%s", vol, oldpath);
#else
	const char *drivers_oldfn, *drivers_newfn;

	drivers_oldfn = oldpath;
	drivers_newfn = newpath;
#endif

	result = f_rename(drivers_oldfn, drivers_newfn);
#if _VOLUMES > 1
	rt_free(drivers_oldfn);
#endif
	return elm_result_to_dfs(result);
}
Esempio n. 6
0
void tc_start(const char* tc_prefix)
{
	rt_err_t result;

	/* tesecase prefix is null */
	if (tc_prefix == RT_NULL)
	{
		rt_kprintf("TestCase Usage: tc_start(prefix)\n\n");
		rt_kprintf("list_tc() can list all testcases.\n");
		return ;
	}

	/* init tc thread */
	if (_tc_stat & TC_STAT_RUNNING)
	{
		/* stop old tc thread */
		tc_stop();
	}

	rt_memset(_tc_prefix, 0, sizeof(_tc_prefix));
	rt_snprintf(_tc_prefix, sizeof(_tc_prefix), "_tc_%s", tc_prefix);

	result = rt_thread_init(&_tc_thread, "tc",
		tc_thread_entry, RT_NULL,
		&_tc_stack[0], sizeof(_tc_stack),
		TC_PRIORITY - 3, 5);

	/* set tc stat */
	_tc_stat = TC_STAT_RUNNING | TC_STAT_FAILED;

	if (result == RT_EOK)
		rt_thread_startup(&_tc_thread);
}
Esempio n. 7
0
int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
{
	FILINFO file_info;
	FRESULT result;

#if _VOLUMES > 1
	int vol;
	char *drivers_fn;
	extern int elm_get_vol(FATFS *fat);

	/* add path for ELM FatFS driver support */
	vol = elm_get_vol((FATFS *)fs->data);
	if (vol < 0)
		return -DFS_STATUS_ENOENT;
	drivers_fn = rt_malloc(256);
	if (drivers_fn == RT_NULL)
		return -DFS_STATUS_ENOMEM;

	rt_snprintf(drivers_fn, 256, "%d:%s", vol, path);
#else
	const char *drivers_fn;
	drivers_fn = path;
#endif

#if _USE_LFN
	/* allocate long file name */
	file_info.lfname = rt_malloc(256);
	file_info.lfsize = 256;
#endif

	result = f_stat(drivers_fn, &file_info);
#if _VOLUMES > 1
	rt_free(drivers_fn);
#endif
	if (result == FR_OK)
	{
		/* convert to dfs stat structure */
		st->st_dev = 0;

		st->st_mode = DFS_S_IFREG | DFS_S_IRUSR | DFS_S_IRGRP | DFS_S_IROTH |
		DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH;
		if (file_info.fattrib & AM_DIR)
		{
			st->st_mode &= ~DFS_S_IFREG;
			st->st_mode |= DFS_S_IFDIR | DFS_S_IXUSR | DFS_S_IXGRP | DFS_S_IXOTH;
		}
		if (file_info.fattrib & AM_RDO)
			st->st_mode &= ~(DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH);

		st->st_size  = file_info.fsize;
		st->st_mtime = file_info.ftime;
		st->st_blksize = 512;
	}

#if _USE_LFN
	rt_free(file_info.lfname);
#endif

	return elm_result_to_dfs(result);
}
Esempio n. 8
0
int dfs_elm_statfs(struct dfs_filesystem *fs, struct statfs *buf)
{
	FATFS *f;
	FRESULT res;
	char driver[4];
	DWORD fre_clust, fre_sect, tot_sect;

	RT_ASSERT(fs != RT_NULL);
	RT_ASSERT(buf != RT_NULL);

	f = (FATFS *)fs->data;

	rt_snprintf(driver, sizeof(driver), "%d:", f->drv);
	res = f_getfree(driver, &fre_clust, &f);
	if (res) 
		return elm_result_to_dfs(res);

	/* Get total sectors and free sectors */
	tot_sect = (f->n_fatent - 2) * f->csize;
	fre_sect = fre_clust * f->csize;

	buf->f_bfree = fre_sect;
	buf->f_blocks = tot_sect;
#if _MAX_SS != 512
	buf->f_bsize = f->ssize;
#else
    buf->f_bsize = 512;
#endif

	return 0;
}
void* dlopen(const char *filename, int flags)
{
	rt_module_t module;
	char *fullpath;
	const char*def_path = MODULE_ROOT_DIR;

	/* check parameters */
	RT_ASSERT(filename != RT_NULL);

	if (filename[0] != '/') /* it's a absolute path, use it directly */
	{
		fullpath = rt_malloc(strlen(def_path) + strlen(filename) + 2);

		/* join path and file name */
		rt_snprintf(fullpath, strlen(def_path) + strlen(filename) + 2, 
			"%s/%s", def_path, filename);
	}
	
	/* find in module list */
	module = rt_module_find(fullpath);
	
	if(module != RT_NULL) module->nref++;
	else module = rt_module_open(fullpath);

	rt_free(fullpath);
	return (void*)module;
}
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
{
    rt_err_t result;
    char cond_name[RT_NAME_MAX];
    static rt_uint16_t cond_num = 0;

    /* parameter check */
    if (cond == RT_NULL)
        return EINVAL;
    if ((attr != RT_NULL) && (*attr != PTHREAD_PROCESS_PRIVATE))
        return EINVAL;

    rt_snprintf(cond_name, sizeof(cond_name), "cond%02d", cond_num++);

	if (attr == RT_NULL) /* use default value */
		cond->attr = PTHREAD_PROCESS_PRIVATE;
	else 
	    cond->attr = *attr;

    result = rt_sem_init(&cond->sem, cond_name, 0, RT_IPC_FLAG_FIFO);
    if (result != RT_EOK)
        return EINVAL;

    /* detach the object from system object container */
    rt_object_detach(&(cond->sem.parent.parent));

    return 0;
}
Esempio n. 11
0
void play_list_append_directory(const char* path)
{
	char fn[64];
	DIR *dir;
	int type;

	dir = opendir(path);
	if (dir != RT_NULL)
	{
		struct dirent* dirent;

		/* clear old play list */
		play_list_clear();
		do
		{
			dirent = readdir(dir);
			if (dirent == RT_NULL) break;

			type = media_type(dirent->d_name);
			if (type == MEDIA_MP3 || type == MEDIA_WAV)
			{
				/* build full path for each file */
				rt_snprintf(fn, sizeof(fn), "%s/%s", path, dirent->d_name);
				rt_kprintf("add media: %s\n", fn);

				play_list_append(fn);
			}
		} while (dirent != RT_NULL);

		closedir(dir);
	}
}
Esempio n. 12
0
static void exec_app(rtgui_widget_t* widget, void* parameter)
{
    char path[64];
    rt_module_t module;

    RT_ASSERT(parameter != RT_NULL);

    rt_snprintf(path, sizeof(path), "%s/%s/%s.mo", APP_PATH, 
        (char*)parameter, (char*)parameter);
    
#ifndef _WIN32
    module = rt_module_find((const char*)parameter);
    if(module == RT_NULL)
        rt_module_open(path);
    else
    {
        struct rtgui_app* app;
        RT_ASSERT(module->module_thread);
        app = (struct rtgui_app*)(module->module_thread->user_data);
        
        if(app != RT_NULL) rtgui_app_activate(app);
        else rt_kprintf("application is null\n");
    }
#endif
}
Esempio n. 13
0
struct rtgui_app *rtgui_app_create(const char *title)
{
    rt_thread_t tid = rt_thread_self();
    struct rtgui_app *app;
    struct rtgui_app *srv_app;
    struct rtgui_event_application event;
    char mq_name[RT_NAME_MAX];

    RT_ASSERT(tid != RT_NULL);
    RT_ASSERT(title != RT_NULL);

    /* create application */
    app = RTGUI_APP(rtgui_object_create(RTGUI_APP_TYPE));
    if (app == RT_NULL)
        return RT_NULL;

    /* one thread only can create one rtgui application */
    RT_ASSERT(tid->user_data == 0);
    app->tid = tid;

    rt_snprintf(mq_name, RT_NAME_MAX, "g%s", title);
    app->mq = rt_mq_create(mq_name, sizeof(union rtgui_event_generic), 32, RT_IPC_FLAG_FIFO);
    if (app->mq == RT_NULL)
    {
        rt_kprintf("create msgq failed.\n");
        goto __mq_err;
    }

    /* set application title */
    app->name = (unsigned char *)rt_strdup((char *)title);
    if (app->name == RT_NULL)
        goto __err;

    /* the first app should be the server */
    srv_app = rtgui_get_server();
    if (srv_app == RT_NULL)
    {
        /* set user thread */
        tid->user_data = (rt_uint32_t)app;
        return app;
    }

    RTGUI_EVENT_APP_CREATE_INIT(&event);
    event.app = app;

    /* notify rtgui server to one application has been created */
    if (rtgui_send_sync(srv_app, RTGUI_EVENT(&event), sizeof(event)) == RT_EOK)
    {
        /* set user thread */
        tid->user_data = (rt_uint32_t)app;
        return app;
    }

__err:
__mq_err:
    rtgui_object_destroy(RTGUI_OBJECT(app));
    return RT_NULL;
}
Esempio n. 14
0
int cmd_mv(int argc, char** argv)
{
    if (argc != 3)
    {
        rt_kprintf("Usage: mv SOURCE DEST\n");
        rt_kprintf("Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n");
    }
    else
    {
		int fd;
		char *dest = RT_NULL;

        rt_kprintf("%s => %s\n", argv[1], argv[2]);

		fd = open(argv[2], O_DIRECTORY, 0);
		if (fd >= 0)
		{
			char *src;
			
			close(fd);

			/* it's a directory */			
			dest = (char*)rt_malloc(DFS_PATH_MAX);
			if (dest == RT_NULL)
			{
				rt_kprintf("out of memory\n");
				return -RT_ENOMEM;
			}

			src = argv[1] + rt_strlen(argv[1]);
			while (src != argv[1]) 
			{
				if (*src == '/') break;
				src --;
			}

			rt_snprintf(dest, DFS_PATH_MAX - 1, "%s/%s", argv[2], src);
		}
		else
		{
			fd = open(argv[2], O_RDONLY, 0);
			if (fd >= 0)
			{
				close(fd);
				
				unlink(argv[2]);
			}

			dest = argv[2];
		}

		rename(argv[1], dest);
		if (dest != RT_NULL && dest != argv[2]) rt_free(dest);
    }

    return 0;
}
Esempio n. 15
0
/**
 * This function will initialize hardware interrupt
 */
void rt_hw_interrupt_init(void)
{
	int i;
	register rt_uint32_t idx;
	const rt_uint8_t *priority;
	priority = dm365_default_priorities;

	/* Clear all interrupt requests */
	davinci_irq_writel(~0x0, FIQ_REG0_OFFSET);
	davinci_irq_writel(~0x0, FIQ_REG1_OFFSET);
	davinci_irq_writel(~0x0, IRQ_REG0_OFFSET);
	davinci_irq_writel(~0x0, IRQ_REG1_OFFSET);

	/* Disable all interrupts */
	davinci_irq_writel(0x0, IRQ_ENT_REG0_OFFSET);
	davinci_irq_writel(0x0, IRQ_ENT_REG1_OFFSET);

	/* Interrupts disabled immediately, IRQ entry reflects all */
	davinci_irq_writel(0x0, IRQ_INCTL_REG_OFFSET);

	/* we don't use the hardware vector table, just its entry addresses */
	davinci_irq_writel(0, IRQ_EABASE_REG_OFFSET);

	/* Clear all interrupt requests */
	davinci_irq_writel(~0x0, FIQ_REG0_OFFSET);
	davinci_irq_writel(~0x0, FIQ_REG1_OFFSET);
	davinci_irq_writel(~0x0, IRQ_REG0_OFFSET);
	davinci_irq_writel(~0x0, IRQ_REG1_OFFSET);

	for (i = IRQ_INTPRI0_REG_OFFSET; i <= IRQ_INTPRI7_REG_OFFSET; i += 4) {
		unsigned	j;
		rt_uint32_t	pri;

		for (j = 0, pri = 0; j < 32; j += 4, priority++)
			pri |= (*priority & 0x07) << j;
		davinci_irq_writel(pri, i);
	}

	/* init exceptions table */
	for(idx=0; idx < MAX_HANDLERS; idx++)
	{
		
		irq_desc[idx].handler = (rt_isr_handler_t)rt_hw_interrupt_handle;
		irq_desc[idx].param = RT_NULL;
	#ifdef RT_USING_INTERRUPT_INFO
		rt_snprintf(irq_desc[idx].name, RT_NAME_MAX - 1, "default");
		irq_desc[idx].counter = 0;
	#endif
	}

	/* init interrupt nest, and context in thread sp */
	rt_interrupt_nest = 0;
	rt_interrupt_from_thread = 0;
	rt_interrupt_to_thread = 0;
	rt_thread_switch_interrupt_flag = 0;
}
Esempio n. 16
0
void play_list_append_m3u(const char* file)
{
	/* read all of music filename to a list */
	int fd;
	char line[64];
	const char* file_ptr;
	char *path_ptr, path[64];

	/* get parent path */
	memset(path, 0, sizeof(path));
	file_ptr = file + strlen(file) - 1;
	while (file_ptr != file) 
	{
		if (*file_ptr == '/')
		{
			strncpy(path, file, (rt_uint32_t)file_ptr - (rt_uint32_t)&file[0]);
			break;
		}
		file_ptr --;
	}
	if (file_ptr == file) strncpy(path, "/", 2);

	path_ptr = rt_malloc(DFS_PATH_MAX);
	if (path_ptr == RT_NULL) return; /* no memory */

	fd = open(file, O_RDONLY, 0);
	if (fd >= 0)
	{
		rt_uint32_t length;
	
		length = read_line(fd, line, sizeof(line));

		/* clear old play list */
		play_list_clear();

		do
		{
			length = read_line(fd, line, sizeof(line));
			if (length > 0)
			{
				if (line[0] != '/')
				{
					rt_snprintf(path_ptr, DFS_PATH_MAX, "%s/%s", path, line);
					play_list_append(path_ptr);
				}
				else play_list_append(line);
			}
		}
		while (length > 0);
	
		close(fd);
	}
	rt_free(path_ptr);
}
Esempio n. 17
0
int ff_cre_syncobj(BYTE drv, _SYNC_t *m)
{
    char name[8];
    rt_mutex_t mutex;

    rt_snprintf(name, sizeof(name), "fat%d", drv);
    mutex = rt_mutex_create(name, RT_IPC_FLAG_FIFO);
    if (mutex != RT_NULL)
    {
        *m = mutex;
        return RT_TRUE;
    }

    return RT_FALSE;
}
Esempio n. 18
0
static rt_bool_t picture_view_event_handler(rtgui_object_t *object, rtgui_event_t *event)
{
    if (event->type == RTGUI_EVENT_PAINT)
    {
        struct rtgui_dc* dc;
        struct rtgui_rect rect;
        struct rtgui_image* image = RT_NULL;
        char fn[32];

        dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(object));
        if (dc == RT_NULL) return RT_FALSE;
        rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);

        /* open image */
        rt_snprintf(fn, sizeof(fn), "%s/%s", PICTURE_DIR, current_fn);
        rt_kprintf("pic fn: %s\n", fn);
        if (strstr(fn, ".hdc") != RT_NULL ||
            strstr(fn, ".HDC") != RT_NULL)
        {
            image = rtgui_image_create_from_file("hdc",
                fn, RT_FALSE);
        }
        else if (strstr(fn, ".bmp") != RT_NULL ||
            strstr(fn, ".BMP") != RT_NULL)
        {
            image = rtgui_image_create_from_file("bmp",
                fn, RT_FALSE);
        }

        if (image != RT_NULL)
        {
            /* blit image */
            rtgui_image_blit(image, dc, &rect);
            /* destroy image */
            rtgui_image_destroy(image);
        }
        else
        {
            rtgui_dc_fill_rect(dc, &rect);
            rtgui_dc_draw_text(dc, "没有文件被打开", &rect);
        }
        rtgui_dc_end_drawing(dc);

        return RT_FALSE;
    }

    return rtgui_container_event_handler(object, event);
}
Esempio n. 19
0
static void info_timer_timeout(rtgui_timer_t* timer, void* parameter)
{
    struct rtgui_dc* dc;
    rtgui_color_t saved;

    dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(home_view));
    if (dc == RT_NULL) return ;

    saved = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view));

    RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(206, 231, 255);
    rtgui_dc_draw_hline(dc, 14, 14	+ (tinfo.position * 212) / tinfo.duration, 75);

    if ((player_mode == PLAYER_PLAY_RADIO) && ((tinfo.position * 212 + 14)/tinfo.duration) < 226)
    {
		tinfo.position = net_buf_get_usage();

        RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(82, 199, 16);
        rtgui_dc_draw_hline(dc, 14  + (tinfo.position * 212) / tinfo.duration, 226, 75);
    }
    RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = saved;

    if (player_mode == PLAYER_PLAY_FILE)
    {
    	rtgui_color_t saved;
        rtgui_rect_t rect;
        char line[32];

        play_time++;
        rt_snprintf(line, sizeof(line), "%3d:%02d", play_time / 60, play_time % 60);

        rect.x1 = 172;
        rect.y1 = 48;
        rect.x2 = 220;
        rect.y2 = rect.y1 + 16;

		saved = RTGUI_DC_BC(dc);
		RTGUI_DC_BC(dc) = RTGUI_RGB(0, 125, 198);
		rtgui_dc_fill_rect(dc, &rect);
        rtgui_dc_draw_text(dc, line, &rect);
		RTGUI_DC_BC(dc) = saved;
    }

    rtgui_dc_end_drawing(dc);
}
void _rtgui_listctrl_item_draw(struct rtgui_listctrl *list,
                               struct rtgui_dc *dc,
                               rtgui_rect_t *rect,
                               rt_uint16_t index)
{
    char age_str[8];
    rtgui_rect_t item_rect;
    struct list_item *items, *item;

    item_rect = *rect;
    item_rect.x1 += 5;
    items = (struct list_item *)list->items;
    item = &items[index];

    /* draw text */
    rtgui_dc_draw_text(dc, item->name, &item_rect);
    item_rect.x1 += 60;
    rtgui_dc_draw_vline(dc, item_rect.x1, item_rect.y1, item_rect.y2);

    item_rect.x1 += 5;
    rtgui_dc_draw_text(dc, item->gender, &item_rect);
    item_rect.x1 += 60;
    rtgui_dc_draw_vline(dc, item_rect.x1, item_rect.y1, item_rect.y2);

    item_rect.x1 += 5;
    rt_snprintf(age_str, sizeof(age_str), "%d", item->age);
    rtgui_dc_draw_text(dc, age_str, &item_rect);
    item_rect.x1 += 40;
    rtgui_dc_draw_vline(dc, item_rect.x1, item_rect.y1, item_rect.y2);

    item_rect.x1 += 5;

    /* draw image */
    if (item->image != RT_NULL)
    {
        rtgui_rect_t image_rect;

        image_rect.x1 = 0;
        image_rect.y1 = 0;
        image_rect.x2 = item->image->w;
        image_rect.y2 = item->image->h;
        rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
        rtgui_image_blit(item->image, dc, &image_rect);
    }
}
Esempio n. 21
0
/**
 * This function will install a interrupt service routine to a interrupt.
 * @param vector the interrupt number
 * @param handler the interrupt service routine to be installed
 * @param param the interrupt service function parameter
 * @param name the interrupt name
 * @return old handler
 */
rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler, 
                                    void *param, char *name)
{
    rt_isr_handler_t old_handler = RT_NULL;

    if(vector < MAX_HANDLERS)
    {
        old_handler = irq_desc[vector].handler;
        if (handler != RT_NULL)
        {
            rt_snprintf(irq_desc[vector].name, RT_NAME_MAX - 1, "%s", name);
            irq_desc[vector].handler = (rt_isr_handler_t)handler;
            irq_desc[vector].param = param;
			irq_desc[vector].counter = 0;
        }
    }

    return old_handler;
}
Esempio n. 22
0
static int dfs_uffs_mount(
	struct dfs_filesystem* fs,
    unsigned long rwflag,
    const void* data)
{
	rt_base_t index;
	uffs_MountTable * mount_part;
	struct rt_mtd_nand_device * dev;
	
	RT_ASSERT(rt_strlen(fs->path) < (UFFS_MOUNT_PATH_MAX-1));
	dev = RT_MTD_NAND_DEVICE(fs->dev_id);

	/*1. find a empty entry in partition table */
	for (index = 0; index < UFFS_DEVICE_MAX ; index ++)
	{
		if (nand_part[index].dev == RT_NULL)
			break;
	}
	if (index == UFFS_DEVICE_MAX)
		return -DFS_STATUS_ENOENT;

	/*2. fill partition structure */
	nand_part[index].dev = dev;

	/* make a right mount path for uffs, end with '/' */
	rt_snprintf(nand_part[index].mount_path, UFFS_MOUNT_PATH_MAX, "%s/", fs->path);
	if (nand_part[index].mount_path[1] == '/')
		nand_part[index].mount_path[1] = 0;

	mount_part = &(nand_part[index].mount_table);
	mount_part->mount	= nand_part[index].mount_path;
	mount_part->dev = &(nand_part[index].uffs_dev);
	rt_memset(mount_part->dev, 0, sizeof(uffs_Device));//in order to make uffs happy.
	mount_part->dev->_private = dev;   /* save dev_id into uffs */
	mount_part->start_block = dev->block_start;
	mount_part->end_block = dev->block_end;
	/*3. mount uffs */
	if (init_uffs_fs(&nand_part[index]) < 0)
	{
		return uffs_result_to_dfs(uffs_get_error());
	}
	return 0;
}
Esempio n. 23
0
err_t sys_mbox_new(sys_mbox_t *mbox, int size)
{
	static unsigned short counter = 0;
	char tname[RT_NAME_MAX];
	sys_mbox_t tmpmbox;

	RT_DEBUG_NOT_IN_INTERRUPT;

	rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_MBOX_NAME, counter);
	counter++;

	tmpmbox = rt_mb_create(tname, size, RT_IPC_FLAG_FIFO);
	if( tmpmbox != RT_NULL )
	{
		*mbox = tmpmbox;
		return ERR_OK;
	}

	return ERR_MEM;
}
Esempio n. 24
0
/** Create a new mutex
 * @param mutex pointer to the mutex to create
 * @return a new mutex */
err_t sys_mutex_new(sys_mutex_t *mutex)
{
	static unsigned short counter = 0;
	char tname[RT_NAME_MAX];
	sys_mutex_t tmpmutex;

	RT_DEBUG_NOT_IN_INTERRUPT;

	rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_MUTEX_NAME, counter);
	counter++;

	tmpmutex = rt_mutex_create(tname, RT_IPC_FLAG_FIFO);
	if( tmpmutex == RT_NULL )
		return ERR_MEM;
	else
	{
		*mutex = tmpmutex;
		return ERR_OK;
	}
}
Esempio n. 25
0
sys_sem_t sys_sem_new(u8_t count)
{
	static int counter = 0;
	char tname[RT_NAME_MAX];

	rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_SEM_NAME, counter);

#if SYS_DEBUG
	{
		struct rt_thread *thread;
	
		thread = rt_thread_self();
		LWIP_DEBUGF(SYS_DEBUG, ("%s, Create sem: %s \n",thread->name, tname));
	}
#endif

	counter++;

	return rt_sem_create(tname, count, RT_IPC_FLAG_FIFO);
}
Esempio n. 26
0
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
{
	static unsigned short counter = 0;
	char tname[RT_NAME_MAX];
	sys_sem_t tmpsem;

	RT_DEBUG_NOT_IN_INTERRUPT;

	rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_SEM_NAME, counter);
	counter++;

	tmpsem = rt_sem_create(tname, count, RT_IPC_FLAG_FIFO);
	if( tmpsem == RT_NULL )
		return ERR_MEM;
	else
	{
		*sem = tmpsem;
		return ERR_OK;
	}
}
Esempio n. 27
0
sys_mbox_t sys_mbox_new(int size)
{
	static int counter = 0;
	char tname[RT_NAME_MAX];

	rt_snprintf(tname, RT_NAME_MAX, "%s%d", SYS_LWIP_MBOX_NAME, counter);

#if SYS_DEBUG
	{
		struct rt_thread *thread;
		thread = rt_thread_self();
	
		LWIP_DEBUGF(SYS_DEBUG, ("%s, Create mbox: %s \n",thread->name, tname));
	}
#endif

	counter++;

	return rt_mb_create(tname, size, RT_IPC_FLAG_FIFO);
}
/* 打开列表视图用的按钮触发函数 */
static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
{
	rtgui_rect_t rect;
	rt_uint32_t index;

	/* 获得顶层的workbench */
	workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
	rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);

	/* 初始化图标列表 */
	if (items == RT_NULL)
	{
		char item_name[32];

		items = (struct rtgui_list_item *) rtgui_malloc((ITEM_MAX + 1) * sizeof(struct rtgui_list_item));
		for (index = 0; index < ITEM_MAX; index ++)
		{
			rt_snprintf(item_name, sizeof(item_name), "图标%d", index);
			items[index].action = listitem_action;
			items[index].image = item_icon;
			items[index].name = rt_strdup(item_name);
			items[index].parameter = (void*) index;
		}

		items[ITEM_MAX].action = return_action;
		items[ITEM_MAX].image = exit_icon;
		items[ITEM_MAX].name = "退出";
		items[ITEM_MAX].parameter = RT_NULL;
	}

	/* 创建一个列表视图, 项指定为items */
	_view = rtgui_list_view_create(items, ITEM_MAX + 1, &rect, RTGUI_LIST_VIEW_ICON);
	/* 在workbench中添加相应的视图 */
	rtgui_workbench_add_view(workbench, RTGUI_VIEW(_view));

	/* 模式显示视图 */
	rtgui_view_show(RTGUI_VIEW(_view), RT_TRUE);
	rtgui_view_destroy(RTGUI_VIEW(_view));

	_view = RT_NULL;
}
Esempio n. 29
0
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
{
	rt_err_t result;
	char name[RT_NAME_MAX];
	static rt_uint16_t pthread_mutex_number = 0;

	if (!mutex) return EINVAL;

	/* build mutex name */
	rt_snprintf(name, sizeof(name), "pmtx%02d", pthread_mutex_number ++);
	if (attr == RT_NULL) mutex->attr = pthread_default_mutexattr;
	else mutex->attr = *attr;

	/* init mutex lock */
	result = rt_mutex_init(&(mutex->lock), name, RT_IPC_FLAG_FIFO);
	if (result != RT_EOK) return EINVAL;

	/* detach the object from system object container */
	rt_object_detach(&(mutex->lock.parent.parent));

	return 0;
}
Esempio n. 30
0
static int xml_event_handler(rt_uint8_t event, const char* text, rt_size_t len, void* user)
{
    static XML_STATUS status = IDLE;
    char fn[64];

    if(event == EVENT_START)
    {
        if(strcmp(text, "name") == 0)
            status = READ_NAME;
        else if(strcmp(text, "image") == 0)
            status = READ_ICON;
        else if(strcmp(text, "author") == 0)
            status = READ_AUTHOR;
        else if(strcmp(text, "license") == 0)
            status = READ_LICENSE;
    }
    else if(event == EVENT_TEXT)
    {
        switch(status)
        {
        case READ_NAME:    
            items[++pos].name = rt_strdup(text);
            items[pos].parameter = items[pos].name;
            break;
        case READ_ICON:
            rt_snprintf(fn, sizeof(fn), "%s/%s", APP_PATH, text);
            items[pos].image = rtgui_image_create(fn, RT_FALSE);
            break;
        case READ_AUTHOR:
            break;
        case READ_LICENSE:
            break;
        }
        status = IDLE;
    }
        
    return 1;    
}