summaryrefslogtreecommitdiff
path: root/bsp/simulator/drivers
diff options
context:
space:
mode:
authoryygg_you <[email protected]>2017-10-20 13:26:47 +0800
committeryygg_you <[email protected]>2017-10-20 13:26:47 +0800
commit2d0c10a0ca78bc4257ce9e5be9e222745c0dc0a7 (patch)
treef7a237ec341e73822ba8d44bfdc613c551e9f5d7 /bsp/simulator/drivers
parente448ecc6ad805109480ecc191f0e2d786216a297 (diff)
修改simulator,匹配RTT 3.0
Diffstat (limited to 'bsp/simulator/drivers')
-rw-r--r--bsp/simulator/drivers/dfs_win32.c102
-rwxr-xr-xbsp/simulator/drivers/sd_sim.c13
2 files changed, 59 insertions, 56 deletions
diff --git a/bsp/simulator/drivers/dfs_win32.c b/bsp/simulator/drivers/dfs_win32.c
index 68ac541770..b868d421f9 100644
--- a/bsp/simulator/drivers/dfs_win32.c
+++ b/bsp/simulator/drivers/dfs_win32.c
@@ -11,13 +11,14 @@
* Date Author Notes
* 2012-11-27 prife the first version
* 2013-03-03 aozima add dfs_win32_stat st_mtime support.
+ * 2017-10-20 urey support rt-thread 3.0
*/
#include <rtthread.h>
+#include <rtlibc.h>
#include <dfs_fs.h>
-#include <dfs_def.h>
+#include <dfs_file.h>
#include <rtdevice.h>
-//#include "dfs_win32.h"
#include <io.h>
#include <fcntl.h>
@@ -48,7 +49,7 @@
*/
#define FILE_PATH_MAX 256 /* the longest file path */
-#define WIN32_DIRDISK_ROOT "." /* "F:\\Project\\svn\\rtt\\trunk\\bsp\\simulator_test" */
+#define WIN32_DIRDISK_ROOT "./disk" /* "F:\\Project\\svn\\rtt\\trunk\\bsp\\simulator_test" */
typedef struct {
HANDLE handle;
@@ -71,13 +72,13 @@ struct _errcode_map
static const struct _errcode_map errcode_table[] =
{
- {DFS_STATUS_ENOENT, ERROR_FILE_NOT_FOUND },
- {DFS_STATUS_ENOENT, ERROR_PATH_NOT_FOUND },
- {DFS_STATUS_EEXIST, ERROR_FILE_EXISTS },
- {DFS_STATUS_EEXIST, ERROR_ALREADY_EXISTS },
- {DFS_STATUS_ENOTEMPTY, ERROR_DIR_NOT_EMPTY },
- {DFS_STATUS_EBUSY, ERROR_PATH_BUSY },
- {DFS_STATUS_EINVAL, ERROR_ACCESS_DENIED },
+ {ENOENT, ERROR_FILE_NOT_FOUND },
+ {ENOENT, ERROR_PATH_NOT_FOUND },
+ {EEXIST, ERROR_FILE_EXISTS },
+ {EEXIST, ERROR_ALREADY_EXISTS },
+ {ENOTEMPTY, ERROR_DIR_NOT_EMPTY },
+ {EBUSY, ERROR_PATH_BUSY },
+ {EINVAL, ERROR_ACCESS_DENIED },
#if 0 /* TODO: MORE NEED BE ADDED */
{DFS_STATUS_EISDIR, ERROR_FILE_EXISTS },
@@ -121,13 +122,13 @@ static int dfs_win32_unmount(struct dfs_filesystem *fs)
static int dfs_win32_mkfs(rt_device_t devid)
{
- return -DFS_STATUS_ENOSYS;
+ return -ENOSYS;
}
static int dfs_win32_statfs(struct dfs_filesystem *fs,
struct statfs *buf)
{
- return -DFS_STATUS_ENOSYS;
+ return -ENOSYS;
}
static char *winpath_dirdup(char *des, const char *src)
@@ -167,12 +168,12 @@ char * dfs_win32_dirdup(char * path)
static int dfs_win32_open(struct dfs_fd *file)
{
int fd;
- int oflag, mode;
+ uint32_t oflag, mode;
char *file_path;
int res;
oflag = file->flags;
- if (oflag & DFS_O_DIRECTORY) /* operations about dir */
+ if (oflag & O_DIRECTORY) /* operations about dir */
{
WINDIR *wdirp;
HANDLE handle;
@@ -180,7 +181,7 @@ static int dfs_win32_open(struct dfs_fd *file)
file_path = winpath_dirdup(WIN32_DIRDISK_ROOT, file->path);
- if (oflag & DFS_O_CREAT) /* create a dir*/
+ if (oflag & O_CREAT) /* create a dir*/
{
res = CreateDirectory(file_path, NULL);
if (res == 0)
@@ -218,19 +219,19 @@ static int dfs_win32_open(struct dfs_fd *file)
file->data = (void *)wdirp;
rt_free(file_path);
- return DFS_STATUS_OK;
+ return 0;
}
/* regular file operations */
mode = O_BINARY;
- if (oflag & DFS_O_RDONLY) mode |= O_RDONLY;
- if (oflag & DFS_O_WRONLY) mode |= O_WRONLY;
- if (oflag & DFS_O_RDWR) mode |= O_RDWR;
+ if (oflag & O_RDONLY) mode |= O_RDONLY;
+ if (oflag & O_WRONLY) mode |= O_WRONLY;
+ if (oflag & O_RDWR) mode |= O_RDWR;
/* Opens the file, if it is existing. If not, a new file is created. */
- if (oflag & DFS_O_CREAT) mode |= O_CREAT;
+ if (oflag & O_CREAT) mode |= O_CREAT;
/* Creates a new file. If the file is existing, it is truncated and overwritten. */
- if (oflag & DFS_O_TRUNC) mode |= O_TRUNC;
+ if (oflag & O_TRUNC) mode |= O_TRUNC;
/* Creates a new file. The function fails if the file is already existing. */
- if (oflag & DFS_O_EXCL) mode |= O_EXCL;
+ if (oflag & O_EXCL) mode |= O_EXCL;
file_path = winpath_dirdup(WIN32_DIRDISK_ROOT, file->path);
fd = _open(file_path, mode, 0x0100 | 0x0080); /* _S_IREAD | _S_IWRITE */
@@ -245,7 +246,7 @@ static int dfs_win32_open(struct dfs_fd *file)
file->pos = 0;
file->size = _lseek(fd, 0, SEEK_END);
- if (oflag & DFS_O_APPEND)
+ if (oflag & O_APPEND)
{
file->pos = file->size;
}
@@ -261,7 +262,7 @@ __err:
static int dfs_win32_close(struct dfs_fd *file)
{
- if (file->flags & DFS_O_DIRECTORY)
+ if (file->flags & O_DIRECTORY)
{
WINDIR *wdirp = (WINDIR*)(file->data);
RT_ASSERT(wdirp != RT_NULL);
@@ -282,10 +283,10 @@ static int dfs_win32_close(struct dfs_fd *file)
static int dfs_win32_ioctl(struct dfs_fd *file, int cmd, void *args)
{
- return -DFS_STATUS_ENOSYS;
+ return -ENOSYS;
}
-static int dfs_win32_read(struct dfs_fd *file, void *buf, rt_size_t len)
+static int dfs_win32_read(struct dfs_fd *file, void *buf, size_t len)
{
int fd;
int char_read;
@@ -300,9 +301,7 @@ static int dfs_win32_read(struct dfs_fd *file, void *buf, rt_size_t len)
return char_read;
}
-static int dfs_win32_write(struct dfs_fd *file,
- const void *buf,
- rt_size_t len)
+static int dfs_win32_write(struct dfs_fd *file, const void *buf, size_t len)
{
int fd;
int char_write;
@@ -347,10 +346,7 @@ static int dfs_win32_seek(struct dfs_fd *file,
}
/* return the size of struct dirent*/
-static int dfs_win32_getdents(
- struct dfs_fd *file,
- struct dirent *dirp,
- rt_uint32_t count)
+static int dfs_win32_getdents(struct dfs_fd *file, struct dirent *dirp, rt_uint32_t count)
{
WINDIR *wdirp;
struct dirent *d = dirp;
@@ -358,7 +354,7 @@ static int dfs_win32_getdents(
/* make integer count */
if (count / sizeof(struct dirent) != 1)
- return -DFS_STATUS_EINVAL;
+ return -EINVAL;
wdirp = (WINDIR*)(file->data);
RT_ASSERT(wdirp != RT_NULL);
@@ -367,9 +363,9 @@ static int dfs_win32_getdents(
/* get the current entry */
if (wdirp->finddata.attrib & _A_SUBDIR)
- d->d_type = DFS_DT_DIR;
+ d->d_type = DT_DIR;
else
- d->d_type = DFS_DT_REG;
+ d->d_type = DT_REG;
d->d_namlen = strlen(wdirp->curr);
strncpy(d->d_name, wdirp->curr, DFS_PATH_MAX);
d->d_reclen = (rt_uint16_t)sizeof(struct dirent);
@@ -408,7 +404,7 @@ static int dfs_win32_unlink(struct dfs_filesystem *fs, const char *path)
if (fp == RT_NULL)
{
rt_kprintf("out of memory.\n");
- return -DFS_STATUS_ENOMEM;
+ return -ENOMEM;
}
result = GetFileAttributes(fp);
@@ -445,7 +441,7 @@ static int dfs_win32_rename(
if (op == RT_NULL || np == RT_NULL)
{
rt_kprintf("out of memory.\n");
- return -DFS_STATUS_ENOMEM;
+ return -ENOMEM;
}
/* If the function fails, the return value is zero. */
@@ -469,7 +465,7 @@ static int dfs_win32_stat(struct dfs_filesystem *fs, const char *path, struct st
if (fp == RT_NULL)
{
rt_kprintf("out of memory.\n");
- return -DFS_STATUS_ENOMEM;
+ return -ENOMEM;
}
hFind = FindFirstFile(fp, &fileInfo);
@@ -478,14 +474,14 @@ static int dfs_win32_stat(struct dfs_filesystem *fs, const char *path, struct st
if (hFind == INVALID_HANDLE_VALUE)
goto __err;
- st->st_mode = DFS_S_IFREG | DFS_S_IRUSR | DFS_S_IRGRP | DFS_S_IROTH |
- DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH;
+ st->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH |
+ S_IWUSR | S_IWGRP | S_IWOTH;
/* convert file info to dfs stat structure */
if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
- st->st_mode &= ~DFS_S_IFREG;
- st->st_mode |= DFS_S_IFDIR | DFS_S_IXUSR | DFS_S_IXGRP | DFS_S_IXOTH;
+ st->st_mode &= ~S_IFREG;
+ st->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
}
st->st_dev = 0;
@@ -513,15 +509,8 @@ __err:
return win32_result_to_dfs(GetLastError());
}
-static const struct dfs_filesystem_operation dfs_win32_ops =
+static const struct dfs_file_ops dfs_win32_file_ops =
{
- "wdir", /* file system type: dir */
- DFS_FS_FLAG_DEFAULT,
- dfs_win32_mount,
- dfs_win32_unmount,
- dfs_win32_mkfs,
- dfs_win32_statfs,
-
dfs_win32_open,
dfs_win32_close,
dfs_win32_ioctl,
@@ -530,6 +519,17 @@ static const struct dfs_filesystem_operation dfs_win32_ops =
dfs_win32_flush,
dfs_win32_seek,
dfs_win32_getdents,
+};
+
+static const struct dfs_filesystem_ops dfs_win32_ops =
+{
+ "wdir", /* file system type: dir */
+ DFS_FS_FLAG_DEFAULT,
+ &dfs_win32_file_ops,
+ dfs_win32_mount,
+ dfs_win32_unmount,
+ dfs_win32_mkfs,
+ dfs_win32_statfs,
dfs_win32_unlink,
dfs_win32_stat,
dfs_win32_rename,
diff --git a/bsp/simulator/drivers/sd_sim.c b/bsp/simulator/drivers/sd_sim.c
index 77adfba024..4a5739b4b6 100755
--- a/bsp/simulator/drivers/sd_sim.c
+++ b/bsp/simulator/drivers/sd_sim.c
@@ -1,14 +1,17 @@
+#include <rtthread.h>
+#include <dfs.h>
+
#include <stdio.h>
#include <string.h>
#ifdef _WIN32
#include <stdlib.h>
#endif
-#include <rtthread.h>
-#include <dfs_def.h>
-
-// #define SD_TRACE rt_kprintf
-#define SD_TRACE(...)
+#ifdef DEBUG
+# define SD_TRACE rt_kprintf
+#else
+# define SD_TRACE(...)
+#endif
#define SDCARD_SIM "sd.bin"
#define SDCARD_SIZE (16*1024*1024) //16M