2011-02-26 16:25:33 +08:00
|
|
|
/*
|
|
|
|
* File : application.c
|
|
|
|
* This file is part of RT-Thread RTOS
|
2012-06-26 11:30:07 +08:00
|
|
|
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
|
2011-02-26 16:25:33 +08:00
|
|
|
*
|
|
|
|
* The license and distribution terms for this file may be
|
|
|
|
* found in the file LICENSE in this distribution or at
|
|
|
|
* http://www.rt-thread.org/license/LICENSE
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2007-11-20 Yi.Qiu add rtgui application
|
|
|
|
* 2008-6-28 Bernard no rtgui init
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2012-06-26 11:30:07 +08:00
|
|
|
* @addtogroup mini4020
|
2011-02-26 16:25:33 +08:00
|
|
|
*/
|
2012-06-26 11:30:07 +08:00
|
|
|
|
2011-02-26 16:25:33 +08:00
|
|
|
/*@{*/
|
|
|
|
|
|
|
|
#include <board.h>
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
|
|
|
#ifdef RT_USING_DFS
|
|
|
|
#include <dfs_init.h>
|
|
|
|
#include <dfs_elm.h>
|
|
|
|
#include <dfs_fs.h>
|
|
|
|
#include <dfs_posix.h>
|
|
|
|
#endif
|
2012-06-26 11:30:07 +08:00
|
|
|
|
2011-02-26 16:25:33 +08:00
|
|
|
#ifdef RT_USING_RTGUI
|
|
|
|
#include <rtgui/rtgui.h>
|
|
|
|
extern void radio_rtgui_init(void);
|
|
|
|
#endif
|
2012-06-26 11:30:07 +08:00
|
|
|
|
2011-02-26 16:25:33 +08:00
|
|
|
#define RT_INIT_THREAD_STACK_SIZE (2*1024)
|
|
|
|
|
2012-06-26 11:30:07 +08:00
|
|
|
void rt_init_thread_entry(void *parameter)
|
2011-02-26 16:25:33 +08:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
rt_uint32_t sz;
|
|
|
|
char buffer[20];
|
|
|
|
#ifdef RT_USING_DFS
|
|
|
|
dfs_init();
|
2011-02-27 21:26:17 +08:00
|
|
|
#ifdef RT_USING_DFS_ELMFAT
|
2011-02-26 16:25:33 +08:00
|
|
|
elm_init();
|
|
|
|
/* mount sd card fat partition 1 as root directory */
|
|
|
|
if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
|
|
|
|
{
|
|
|
|
rt_kprintf("File System initialized!\n");
|
|
|
|
|
|
|
|
/*Open a file*/
|
|
|
|
fd = open("/fattest.txt", O_RDWR|O_CREAT, 0);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
rt_kprintf("open file for write failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sz = write(fd,"Hello RT-Thread!",sizeof("Hello RT-Thread!"));
|
|
|
|
|
2012-06-26 11:30:07 +08:00
|
|
|
if (sz != 0)
|
2011-02-26 16:25:33 +08:00
|
|
|
{
|
|
|
|
rt_kprintf("written %d\n",sz);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rt_kprintf("haven't written\n");
|
|
|
|
|
2012-06-26 11:30:07 +08:00
|
|
|
lseek(fd, 0, SEEK_SET);
|
2011-02-26 16:25:33 +08:00
|
|
|
|
2012-06-26 11:30:07 +08:00
|
|
|
sz = read(fd, buffer, sizeof(buffer));
|
2011-02-26 16:25:33 +08:00
|
|
|
|
2012-06-26 11:30:07 +08:00
|
|
|
if (sz != 0)
|
2011-02-26 16:25:33 +08:00
|
|
|
{
|
|
|
|
rt_kprintf("READ %d:",sz);
|
2012-06-26 11:30:07 +08:00
|
|
|
while (sz--)
|
2011-02-26 16:25:33 +08:00
|
|
|
rt_kprintf("%c",buffer[sz]);//opposite
|
|
|
|
rt_kprintf("\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rt_kprintf("haven't read\n");
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rt_kprintf("File System initialzation failed!\n");
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-06-26 11:30:07 +08:00
|
|
|
void rt_led_thread_entry(void *parameter)
|
2011-02-26 16:25:33 +08:00
|
|
|
{
|
2012-06-26 11:30:07 +08:00
|
|
|
/*
|
2011-02-26 16:25:33 +08:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
*(RP)GPIO_PORTE_DATA |= 0x1<<4;
|
|
|
|
rt_thread_delay(RT_TICK_PER_SECOND*2);
|
|
|
|
|
|
|
|
*(RP)GPIO_PORTE_DATA &= ~(0x1<<4);
|
|
|
|
rt_thread_delay(RT_TICK_PER_SECOND*2);
|
|
|
|
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-26 11:30:07 +08:00
|
|
|
int rt_application_init(void)
|
2011-02-26 16:25:33 +08:00
|
|
|
{
|
|
|
|
rt_thread_t init_thread;
|
|
|
|
rt_thread_t led_thread;
|
|
|
|
|
|
|
|
init_thread = rt_thread_create("init",
|
|
|
|
rt_init_thread_entry, RT_NULL,
|
|
|
|
RT_INIT_THREAD_STACK_SIZE, 8, 20);
|
|
|
|
led_thread = rt_thread_create("led",
|
|
|
|
rt_led_thread_entry, RT_NULL,
|
|
|
|
512, 200, 20);
|
|
|
|
|
|
|
|
if (init_thread != RT_NULL)
|
|
|
|
rt_thread_startup(init_thread);
|
|
|
|
|
|
|
|
if (led_thread != RT_NULL)
|
|
|
|
rt_thread_startup(led_thread);
|
2012-06-26 11:30:07 +08:00
|
|
|
|
2011-02-26 16:25:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*@}*/
|