Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
a93251ae
R
rt-thread
项目概览
BaiXuePrincess
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
a93251ae
编写于
12月 29, 2013
作者:
B
bernard
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
https://github.com/RT-Thread/rt-thread
上级
42ae1c63
939176d1
变更
49
显示空白变更内容
内联
并排
Showing
49 changed file
with
2715 addition
and
2431 deletion
+2715
-2431
bsp/beaglebone/applications/startup.c
bsp/beaglebone/applications/startup.c
+2
-1
components/dfs/filesystems/elmfat/ff.c
components/dfs/filesystems/elmfat/ff.c
+6
-9
components/dfs/filesystems/elmfat/ff.h
components/dfs/filesystems/elmfat/ff.h
+0
-2
components/dfs/src/dfs_fs.c
components/dfs/src/dfs_fs.c
+130
-175
components/external/SQLite-3.8.1/SQLiteLib/README
components/external/SQLite-3.8.1/SQLiteLib/README
+6
-4
components/external/SQLite-3.8.1/SQLiteLib/sqlite3.c
components/external/SQLite-3.8.1/SQLiteLib/sqlite3.c
+143
-18
components/external/SQLite-3.8.1/make/Makefile
components/external/SQLite-3.8.1/make/Makefile
+2
-0
components/external/SQLite-3.8.1/src/os_rtthread.c
components/external/SQLite-3.8.1/src/os_rtthread.c
+77
-17
components/external/SQLite-3.8.1/src/sqlite_config_rtthread.h
...onents/external/SQLite-3.8.1/src/sqlite_config_rtthread.h
+62
-0
components/external/SQLite-3.8.1/tool/mksqlite3c.tcl
components/external/SQLite-3.8.1/tool/mksqlite3c.tcl
+1
-0
components/pthreads/posix_types.h
components/pthreads/posix_types.h
+3
-0
examples/kernel/SConscript
examples/kernel/SConscript
+3
-1
examples/kernel/cpuusage.c
examples/kernel/cpuusage.c
+47
-47
examples/kernel/event_simple.c
examples/kernel/event_simple.c
+90
-90
examples/kernel/heap_malloc.c
examples/kernel/heap_malloc.c
+40
-38
examples/kernel/heap_realloc.c
examples/kernel/heap_realloc.c
+73
-54
examples/kernel/mbox_send_wait.c
examples/kernel/mbox_send_wait.c
+73
-73
examples/kernel/mbox_simple.c
examples/kernel/mbox_simple.c
+78
-78
examples/kernel/memp_simple.c
examples/kernel/memp_simple.c
+88
-88
examples/kernel/messageq_simple.c
examples/kernel/messageq_simple.c
+101
-101
examples/kernel/mutex_simple.c
examples/kernel/mutex_simple.c
+114
-114
examples/kernel/semaphore_buffer_worker.c
examples/kernel/semaphore_buffer_worker.c
+189
-189
examples/kernel/semaphore_dynamic.c
examples/kernel/semaphore_dynamic.c
+94
-87
examples/kernel/semaphore_priority.c
examples/kernel/semaphore_priority.c
+95
-89
examples/kernel/semaphore_producer_consumer.c
examples/kernel/semaphore_producer_consumer.c
+93
-89
examples/kernel/semaphore_static.c
examples/kernel/semaphore_static.c
+89
-85
examples/kernel/tc_comm.c
examples/kernel/tc_comm.c
+144
-122
examples/kernel/tc_comm.h
examples/kernel/tc_comm.h
+9
-9
examples/kernel/tc_sample.c
examples/kernel/tc_sample.c
+30
-30
examples/kernel/thread_delay.c
examples/kernel/thread_delay.c
+35
-35
examples/kernel/thread_delete.c
examples/kernel/thread_delete.c
+91
-93
examples/kernel/thread_detach.c
examples/kernel/thread_detach.c
+61
-61
examples/kernel/thread_dynamic.c
examples/kernel/thread_dynamic.c
+17
-17
examples/kernel/thread_dynamic_simple.c
examples/kernel/thread_dynamic_simple.c
+44
-44
examples/kernel/thread_priority.c
examples/kernel/thread_priority.c
+61
-61
examples/kernel/thread_resume.c
examples/kernel/thread_resume.c
+68
-68
examples/kernel/thread_same_priority.c
examples/kernel/thread_same_priority.c
+52
-52
examples/kernel/thread_static.c
examples/kernel/thread_static.c
+19
-19
examples/kernel/thread_static_simple.c
examples/kernel/thread_static_simple.c
+47
-47
examples/kernel/thread_suspend.c
examples/kernel/thread_suspend.c
+51
-51
examples/kernel/thread_yield.c
examples/kernel/thread_yield.c
+53
-53
examples/kernel/timer_control.c
examples/kernel/timer_control.c
+40
-40
examples/kernel/timer_dynamic.c
examples/kernel/timer_dynamic.c
+41
-41
examples/kernel/timer_static.c
examples/kernel/timer_static.c
+33
-33
examples/kernel/timer_stop_self.c
examples/kernel/timer_stop_self.c
+38
-38
examples/kernel/timer_timeout.c
examples/kernel/timer_timeout.c
+66
-66
include/rtthread.h
include/rtthread.h
+1
-0
src/idle.c
src/idle.c
+5
-2
src/scheduler.c
src/scheduler.c
+10
-0
未找到文件。
bsp/beaglebone/applications/startup.c
浏览文件 @
a93251ae
...
@@ -43,7 +43,8 @@ void rtthread_startup(void)
...
@@ -43,7 +43,8 @@ void rtthread_startup(void)
/* initialize timer */
/* initialize timer */
rt_system_timer_init
();
rt_system_timer_init
();
/* initialize soft timer thread */
/* initialize timer */
rt_system_timer_init
();
rt_system_timer_thread_init
();
rt_system_timer_thread_init
();
/* initialize application */
/* initialize application */
...
...
components/dfs/filesystems/elmfat/ff.c
浏览文件 @
a93251ae
...
@@ -108,12 +108,8 @@
...
@@ -108,12 +108,8 @@
#if _MAX_SS != 512 && _MAX_SS != 1024 && _MAX_SS != 2048 && _MAX_SS != 4096
#if _MAX_SS != 512 && _MAX_SS != 1024 && _MAX_SS != 2048 && _MAX_SS != 4096
#error Wrong sector size.
#error Wrong sector size.
#endif
#endif
#if _MAX_SS != 512
#define SS(fs) ((fs)->ssize)
/* Multiple sector size */
#else
#define SS(fs) 512U
/* Fixed sector size */
#endif
#define SS(fs) ((fs)->ssize)
/* sector size */
/* Reentrancy related */
/* Reentrancy related */
#if _FS_REENTRANT
#if _FS_REENTRANT
...
@@ -2058,10 +2054,11 @@ FRESULT chk_mounted ( /* FR_OK(0): successful, !=0: any error occurred */
...
@@ -2058,10 +2054,11 @@ FRESULT chk_mounted ( /* FR_OK(0): successful, !=0: any error occurred */
stat
=
disk_initialize
(
fs
->
drv
);
/* Initialize low level disk I/O layer */
stat
=
disk_initialize
(
fs
->
drv
);
/* Initialize low level disk I/O layer */
if
(
stat
&
STA_NOINIT
)
/* Check if the initialization succeeded */
if
(
stat
&
STA_NOINIT
)
/* Check if the initialization succeeded */
return
FR_NOT_READY
;
/* Failed to initialize due to no media or hard error */
return
FR_NOT_READY
;
/* Failed to initialize due to no media or hard error */
#if _MAX_SS != 512
/* Get disk sector size (variable sector size cfg only) */
/* Get disk sector size (variable sector size cfg only) */
if
(
disk_ioctl
(
fs
->
drv
,
GET_SECTOR_SIZE
,
&
fs
->
ssize
)
!=
RES_OK
)
if
(
disk_ioctl
(
fs
->
drv
,
GET_SECTOR_SIZE
,
&
fs
->
ssize
)
!=
RES_OK
)
return
FR_DISK_ERR
;
return
FR_DISK_ERR
;
#endif
#if !_FS_READONLY
#if !_FS_READONLY
if
(
chk_wp
&&
(
stat
&
STA_PROTECT
))
/* Check disk write protection if needed */
if
(
chk_wp
&&
(
stat
&
STA_PROTECT
))
/* Check disk write protection if needed */
return
FR_WRITE_PROTECTED
;
return
FR_WRITE_PROTECTED
;
...
@@ -3601,10 +3598,10 @@ FRESULT f_mkfs (
...
@@ -3601,10 +3598,10 @@ FRESULT f_mkfs (
stat
=
disk_initialize
(
drv
);
stat
=
disk_initialize
(
drv
);
if
(
stat
&
STA_NOINIT
)
return
FR_NOT_READY
;
if
(
stat
&
STA_NOINIT
)
return
FR_NOT_READY
;
if
(
stat
&
STA_PROTECT
)
return
FR_WRITE_PROTECTED
;
if
(
stat
&
STA_PROTECT
)
return
FR_WRITE_PROTECTED
;
#if _MAX_SS != 512
/* Get disk sector size */
/* Get disk sector size */
if
(
disk_ioctl
(
drv
,
GET_SECTOR_SIZE
,
&
SS
(
fs
))
!=
RES_OK
)
if
(
disk_ioctl
(
drv
,
GET_SECTOR_SIZE
,
&
SS
(
fs
))
!=
RES_OK
)
return
FR_DISK_ERR
;
return
FR_DISK_ERR
;
#endif
if
(
disk_ioctl
(
drv
,
GET_SECTOR_COUNT
,
&
n_vol
)
!=
RES_OK
||
n_vol
<
128
)
if
(
disk_ioctl
(
drv
,
GET_SECTOR_COUNT
,
&
n_vol
)
!=
RES_OK
||
n_vol
<
128
)
return
FR_DISK_ERR
;
return
FR_DISK_ERR
;
b_vol
=
(
sfd
)
?
0
:
63
;
/* Volume start sector */
b_vol
=
(
sfd
)
?
0
:
63
;
/* Volume start sector */
...
...
components/dfs/filesystems/elmfat/ff.h
浏览文件 @
a93251ae
...
@@ -84,9 +84,7 @@ typedef struct {
...
@@ -84,9 +84,7 @@ typedef struct {
BYTE
fsi_flag
;
/* fsinfo dirty flag (1:must be written back) */
BYTE
fsi_flag
;
/* fsinfo dirty flag (1:must be written back) */
WORD
id
;
/* File system mount ID */
WORD
id
;
/* File system mount ID */
WORD
n_rootdir
;
/* Number of root directory entries (FAT12/16) */
WORD
n_rootdir
;
/* Number of root directory entries (FAT12/16) */
#if _MAX_SS != 512
WORD
ssize
;
/* Bytes per sector (512,1024,2048,4096) */
WORD
ssize
;
/* Bytes per sector (512,1024,2048,4096) */
#endif
#if _FS_REENTRANT
#if _FS_REENTRANT
_SYNC_t
sobj
;
/* Identifier of sync object */
_SYNC_t
sobj
;
/* Identifier of sync object */
#endif
#endif
...
...
components/dfs/src/dfs_fs.c
浏览文件 @
a93251ae
...
@@ -37,48 +37,36 @@
...
@@ -37,48 +37,36 @@
*
*
* @param ops the file system instance to be registered.
* @param ops the file system instance to be registered.
*
*
* @return
0 on successful, -1
on failed.
* @return
RT_EOK on successful, -RT_ERROR
on failed.
*/
*/
int
dfs_register
(
const
struct
dfs_filesystem_operation
*
ops
)
int
dfs_register
(
const
struct
dfs_filesystem_operation
*
ops
)
{
{
int
index
,
result
;
int
ret
=
RT_EOK
;
int
free_index
;
const
struct
dfs_filesystem_operation
**
empty
=
RT_NULL
;
const
struct
dfs_filesystem_operation
**
iter
;
result
=
0
;
free_index
=
DFS_FILESYSTEM_TYPES_MAX
;
/* lock filesystem */
/* lock filesystem */
dfs_lock
();
dfs_lock
();
/* check if this filesystem was already registered */
/* check if this filesystem was already registered */
for
(
index
=
0
;
index
<
DFS_FILESYSTEM_TYPES_MAX
;
index
++
)
for
(
iter
=
&
filesystem_operation_table
[
0
];
{
iter
<
&
filesystem_operation_table
[
DFS_FILESYSTEM_TYPES_MAX
];
iter
++
)
if
(
filesystem_operation_table
[
index
]
==
RT_NULL
)
{
{
/* find out an empty filesystem type entry */
/* find out an empty filesystem type entry */
if
(
free_index
==
DFS_FILESYSTEM_TYPES_MAX
)
if
(
*
iter
==
RT_NULL
)
free_index
=
index
;
(
empty
==
RT_NULL
)
?
(
empty
=
iter
)
:
0
;
}
else
if
(
strcmp
((
*
iter
)
->
name
,
ops
->
name
)
==
0
)
else
if
(
strcmp
(
filesystem_operation_table
[
index
]
->
name
,
ops
->
name
)
==
0
)
{
{
result
=
-
1
;
ret
=
-
1
;
goto
err
;
break
;
}
}
}
/* filesystem type table full */
if
(
free_index
==
DFS_FILESYSTEM_TYPES_MAX
)
{
result
=
-
1
;
goto
err
;
}
}
/* save the filesystem's operations */
/* save the filesystem's operations */
filesystem_operation_table
[
free_index
]
=
ops
;
if
((
ret
==
RT_EOK
)
&&
(
empty
!=
RT_NULL
))
*
empty
=
ops
;
err:
dfs_unlock
();
dfs_unlock
();
return
re
sul
t
;
return
ret
;
}
}
/**
/**
...
@@ -91,38 +79,34 @@ err:
...
@@ -91,38 +79,34 @@ err:
*/
*/
struct
dfs_filesystem
*
dfs_filesystem_lookup
(
const
char
*
path
)
struct
dfs_filesystem
*
dfs_filesystem_lookup
(
const
char
*
path
)
{
{
struct
dfs_filesystem
*
fs
;
struct
dfs_filesystem
*
iter
;
rt_uint32_t
index
,
fspath
,
prefixlen
;
struct
dfs_filesystem
*
fs
=
RT_NULL
;
rt_uint32_t
fspath
,
prefixlen
;
fs
=
RT_NULL
;
prefixlen
=
0
;
prefixlen
=
0
;
/* lock filesystem */
/* lock filesystem */
dfs_lock
();
dfs_lock
();
/* lookup it in the filesystem table */
/* lookup it in the filesystem table */
for
(
index
=
0
;
index
<
DFS_FILESYSTEMS_MAX
;
index
++
)
for
(
iter
=
&
filesystem_table
[
0
];
iter
<
&
filesystem_table
[
DFS_FILESYSTEMS_MAX
];
iter
++
)
{
{
if
(
filesystem_table
[
index
].
path
==
RT_NULL
)
if
(
(
iter
->
path
==
RT_NULL
)
||
(
iter
->
ops
==
RT_NULL
)
)
continue
;
continue
;
else
{
fspath
=
strlen
(
iter
->
path
);
fspath
=
strlen
(
filesystem_table
[
index
].
path
);
if
((
fspath
<
prefixlen
)
if
(
fspath
<
prefixlen
)
||
(
strncmp
(
iter
->
path
,
path
,
fspath
)
!=
0
)
)
continue
;
continue
;
}
if
((
filesystem_table
[
index
].
ops
!=
RT_NULL
)
&&
(
strncmp
(
filesystem_table
[
index
].
path
,
path
,
fspath
)
==
0
))
{
/* check next path separator */
/* check next path separator */
if
(
fspath
>
1
&&
(
strlen
(
path
)
>
fspath
)
&&
(
path
[
fspath
]
!=
'/'
))
if
(
fspath
>
1
&&
(
strlen
(
path
)
>
fspath
)
&&
(
path
[
fspath
]
!=
'/'
))
continue
;
continue
;
fs
=
&
filesystem_table
[
index
]
;
fs
=
iter
;
prefixlen
=
fspath
;
prefixlen
=
fspath
;
}
}
}
dfs_unlock
();
dfs_unlock
();
...
@@ -147,64 +131,42 @@ rt_err_t dfs_filesystem_get_partition(struct dfs_partition *part,
...
@@ -147,64 +131,42 @@ rt_err_t dfs_filesystem_get_partition(struct dfs_partition *part,
rt_uint8_t
*
dpt
;
rt_uint8_t
*
dpt
;
rt_uint8_t
type
;
rt_uint8_t
type
;
rt_err_t
result
;
RT_ASSERT
(
part
!=
RT_NULL
);
RT_ASSERT
(
part
!=
RT_NULL
);
RT_ASSERT
(
buf
!=
RT_NULL
);
RT_ASSERT
(
buf
!=
RT_NULL
);
result
=
RT_EOK
;
dpt
=
buf
+
DPT_ADDRESS
+
pindex
*
DPT_ITEM_SIZE
;
dpt
=
buf
+
DPT_ADDRESS
+
pindex
*
DPT_ITEM_SIZE
;
/* check if it is a valid partition table */
if
((
*
dpt
!=
0x80
)
&&
(
*
dpt
!=
0x00
))
if
((
*
dpt
!=
0x80
)
&&
(
*
dpt
!=
0x00
))
{
return
-
RT_ERROR
;
/* which is not a partition table */
result
=
-
RT_ERROR
;
return
result
;
}
/* get partition type */
/* get partition type */
type
=
*
(
dpt
+
4
);
type
=
*
(
dpt
+
4
);
if
(
type
==
0
)
return
-
RT_ERROR
;
if
(
type
!=
0
)
/* set partition information
{
* size is the number of 512-Byte */
/* set partition type */
part
->
type
=
type
;
part
->
type
=
type
;
/* get partition offset and size */
part
->
offset
=
*
(
dpt
+
8
)
|
*
(
dpt
+
9
)
<<
8
|
*
(
dpt
+
10
)
<<
16
|
*
(
dpt
+
11
)
<<
24
;
part
->
offset
=
*
(
dpt
+
8
)
|
*
(
dpt
+
9
)
<<
8
|
*
(
dpt
+
10
)
<<
16
|
*
(
dpt
+
11
)
<<
24
;
part
->
size
=
*
(
dpt
+
12
)
|
*
(
dpt
+
13
)
<<
8
|
*
(
dpt
+
14
)
<<
16
|
*
(
dpt
+
15
)
<<
24
;
part
->
size
=
*
(
dpt
+
12
)
|
*
(
dpt
+
13
)
<<
8
|
*
(
dpt
+
14
)
<<
16
|
*
(
dpt
+
15
)
<<
24
;
rt_kprintf
(
"found part[%d], begin: %d, size: "
,
rt_kprintf
(
"found part[%d], begin: %d, size: "
,
pindex
,
part
->
offset
*
512
);
pindex
,
part
->
offset
*
512
);
if
((
part
->
size
>>
11
)
>
0
)
/* MB */
if
((
part
->
size
>>
11
)
==
0
)
{
rt_kprintf
(
"%d%s"
,
part
->
size
>>
1
,
"KB
\n
"
);
/* KB */
unsigned
int
part_size
;
part_size
=
part
->
size
>>
11
;
/* MB */
if
((
part_size
>>
10
)
>
0
)
/* GB */
{
/* GB */
rt_kprintf
(
"%d.%d%s"
,
part_size
>>
10
,
part_size
&
0x3FF
,
"GB
\r\n
"
);
}
else
else
{
{
/* MB */
unsigned
int
part_size
;
rt_kprintf
(
"%d.%d%s"
,
part_size
,(
part
->
size
>>
1
)
&
0x3FF
,
"MB
\r\n
"
);
part_size
=
part
->
size
>>
11
;
/* MB */
}
if
((
part_size
>>
10
)
==
0
)
}
rt_kprintf
(
"%d.%d%s"
,
part_size
,(
part
->
size
>>
1
)
&
0x3FF
,
"MB
\n
"
);
else
{
/* KB */
rt_kprintf
(
"%d%s"
,
part
->
size
>>
1
,
"KB
\r\n
"
);
}
}
else
else
{
rt_kprintf
(
"%d.%d%s"
,
part_size
>>
10
,
part_size
&
0x3FF
,
"GB
\n
"
);
result
=
-
RT_ERROR
;
}
}
return
result
;
return
RT_EOK
;
}
}
/**
/**
...
@@ -224,57 +186,54 @@ int dfs_mount(const char *device_name,
...
@@ -224,57 +186,54 @@ int dfs_mount(const char *device_name,
unsigned
long
rwflag
,
unsigned
long
rwflag
,
const
void
*
data
)
const
void
*
data
)
{
{
const
struct
dfs_filesystem_operation
*
ops
;
const
struct
dfs_filesystem_operation
**
ops
;
struct
dfs_filesystem
*
fs
;
struct
dfs_filesystem
*
iter
;
char
*
fullpath
=
RT_NULL
;
struct
dfs_filesystem
*
fs
=
RT_NULL
;
char
*
fullpath
=
RT_NULL
;
rt_device_t
dev_id
;
rt_device_t
dev_id
;
int
index
,
free_index
;
/* open specific device */
/* open specific device */
if
(
device_name
!
=
RT_NULL
)
if
(
device_name
=
=
RT_NULL
)
{
{
dev_id
=
rt_device_find
(
device_name
);
/* which is a non-device filesystem mount */
if
(
dev_id
==
RT_NULL
)
dev_id
=
NULL
;
}
else
if
((
dev_id
=
rt_device_find
(
device_name
))
==
RT_NULL
)
{
{
/* no this device */
/* no this device */
rt_set_errno
(
-
DFS_STATUS_ENODEV
);
rt_set_errno
(
-
DFS_STATUS_ENODEV
);
return
-
1
;
return
-
1
;
}
}
}
else
{
/* which is a non-device filesystem mount */
dev_id
=
RT_NULL
;
}
/* find out specific filesystem */
/* find out
the
specific filesystem */
dfs_lock
();
dfs_lock
();
for
(
index
=
0
;
index
<
DFS_FILESYSTEM_TYPES_MAX
;
index
++
)
{
if
(
filesystem_operation_table
[
index
]
==
RT_NULL
)
continue
;
if
(
strcmp
(
filesystem_operation_table
[
index
]
->
name
,
filesystemtype
)
==
0
)
for
(
ops
=
&
filesystem_operation_table
[
0
];
ops
<
&
filesystem_operation_table
[
DFS_FILESYSTEM_TYPES_MAX
];
ops
++
)
if
((
ops
!=
RT_NULL
)
&&
(
strcmp
((
*
ops
)
->
name
,
filesystemtype
)
==
0
))
break
;
break
;
}
dfs_unlock
();
dfs_unlock
();
/* can't find filesystem */
if
(
ops
==
&
filesystem_operation_table
[
DFS_FILESYSTEM_TYPES_MAX
])
if
(
index
==
DFS_FILESYSTEM_TYPES_MAX
)
{
{
/* can't find filesystem */
rt_set_errno
(
-
DFS_STATUS_ENODEV
);
rt_set_errno
(
-
DFS_STATUS_ENODEV
);
return
-
1
;
}
/* check if there is mount implementation */
if
((
*
ops
==
NULL
)
||
((
*
ops
)
->
mount
==
NULL
))
{
rt_set_errno
(
-
DFS_STATUS_ENOSYS
);
return
-
1
;
return
-
1
;
}
}
ops
=
filesystem_operation_table
[
index
];
/* make full path for special file */
/* make full path for special file */
fullpath
=
dfs_normalize_path
(
RT_NULL
,
path
);
fullpath
=
dfs_normalize_path
(
RT_NULL
,
path
);
if
(
fullpath
==
RT_NULL
)
/* not an abstract path */
if
(
fullpath
==
RT_NULL
)
/* not an abstract path */
{
{
rt_set_errno
(
-
DFS_STATUS_ENOTDIR
);
rt_set_errno
(
-
DFS_STATUS_ENOTDIR
);
return
-
1
;
return
-
1
;
}
}
...
@@ -293,60 +252,52 @@ int dfs_mount(const char *device_name,
...
@@ -293,60 +252,52 @@ int dfs_mount(const char *device_name,
dfs_file_close
(
&
fd
);
dfs_file_close
(
&
fd
);
}
}
free_index
=
DFS_FILESYSTEMS_MAX
;
/* check whether the file system mounted or not in the filesystem table
/* check whether the file system mounted or not
*/
* if it is unmounted yet, find out an empty entry
*/
dfs_lock
();
dfs_lock
();
for
(
index
=
0
;
index
<
DFS_FILESYSTEMS_MAX
;
index
++
)
{
for
(
iter
=
&
filesystem_table
[
0
];
if
(
filesystem_table
[
index
].
ops
==
RT_NULL
)
iter
<
&
filesystem_table
[
DFS_FILESYSTEMS_MAX
];
iter
++
)
{
{
/* find out an empty filesystem table entry
*/
/* check if it is an empty filesystem table entry? if it is, save fs
*/
if
(
free_index
==
DFS_FILESYSTEMS_MAX
)
if
(
iter
->
ops
==
RT_NULL
)
free_index
=
index
;
(
fs
==
RT_NULL
)
?
(
fs
=
iter
)
:
0
;
}
/* check if the PATH is mounted */
else
if
(
strcmp
(
filesystem_table
[
index
].
path
,
path
)
==
0
)
else
if
(
strcmp
(
iter
->
path
,
path
)
==
0
)
{
{
rt_set_errno
(
-
DFS_STATUS_EINVAL
);
rt_set_errno
(
-
DFS_STATUS_EINVAL
);
goto
err1
;
goto
err1
;
}
}
}
}
/* can't find en empty filesystem table entry */
if
((
fs
==
RT_NULL
)
&&
(
iter
==
&
filesystem_table
[
DFS_FILESYSTEMS_MAX
]))
if
(
free_index
==
DFS_FILESYSTEMS_MAX
)
{
{
rt_set_errno
(
-
DFS_STATUS_ENOSPC
);
rt_set_errno
(
-
DFS_STATUS_ENOSPC
);
goto
err1
;
goto
err1
;
}
}
/* register file system */
/* register file system */
fs
=
&
(
filesystem_table
[
free_index
]);
fs
->
path
=
fullpath
;
fs
->
path
=
fullpath
;
fs
->
ops
=
ops
;
fs
->
ops
=
*
ops
;
fs
->
dev_id
=
dev_id
;
fs
->
dev_id
=
dev_id
;
/* release filesystem_table lock */
/* release filesystem_table lock */
dfs_unlock
();
dfs_unlock
();
/* open device, but do not check the status of device */
/* open device, but do not check the status of device */
if
(
dev_id
!=
RT_NULL
)
if
(
dev_id
!=
RT_NULL
)
rt_device_open
(
fs
->
dev_id
,
RT_DEVICE_OFLAG_RDWR
);
/* there is no mount implementation */
if
(
ops
->
mount
==
RT_NULL
)
{
{
if
(
dev_id
!=
RT_NULL
)
if
(
rt_device_open
(
fs
->
dev_id
,
rt_device_close
(
dev_id
);
RT_DEVICE_OFLAG_RDWR
)
!=
RT_EOK
)
{
/* The underlaying device has error, clear the entry. */
dfs_lock
();
dfs_lock
();
/* clear filesystem table entry */
rt_memset
(
fs
,
0
,
sizeof
(
struct
dfs_filesystem
));
rt_memset
(
fs
,
0
,
sizeof
(
struct
dfs_filesystem
));
dfs_unlock
();
goto
err1
;
rt_free
(
fullpath
);
rt_set_errno
(
-
DFS_STATUS_ENOSYS
);
return
-
1
;
}
}
}
/* call mount of this filesystem */
/* call mount of this filesystem */
else
if
(
ops
->
mount
(
fs
,
rwflag
,
data
)
<
0
)
if
((
*
ops
)
->
mount
(
fs
,
rwflag
,
data
)
<
0
)
{
{
/* close device */
/* close device */
if
(
dev_id
!=
RT_NULL
)
if
(
dev_id
!=
RT_NULL
)
...
@@ -356,18 +307,13 @@ int dfs_mount(const char *device_name,
...
@@ -356,18 +307,13 @@ int dfs_mount(const char *device_name,
dfs_lock
();
dfs_lock
();
/* clear filesystem table entry */
/* clear filesystem table entry */
rt_memset
(
fs
,
0
,
sizeof
(
struct
dfs_filesystem
));
rt_memset
(
fs
,
0
,
sizeof
(
struct
dfs_filesystem
));
dfs_unlock
();
goto
err1
;
rt_free
(
fullpath
);
return
-
1
;
}
}
return
0
;
return
0
;
err1:
err1:
dfs_unlock
();
dfs_unlock
();
if
(
fullpath
!=
RT_NULL
)
rt_free
(
fullpath
);
rt_free
(
fullpath
);
return
-
1
;
return
-
1
;
...
@@ -383,6 +329,7 @@ err1:
...
@@ -383,6 +329,7 @@ err1:
int
dfs_unmount
(
const
char
*
specialfile
)
int
dfs_unmount
(
const
char
*
specialfile
)
{
{
char
*
fullpath
;
char
*
fullpath
;
struct
dfs_filesystem
*
iter
;
struct
dfs_filesystem
*
fs
=
RT_NULL
;
struct
dfs_filesystem
*
fs
=
RT_NULL
;
fullpath
=
dfs_normalize_path
(
RT_NULL
,
specialfile
);
fullpath
=
dfs_normalize_path
(
RT_NULL
,
specialfile
);
...
@@ -396,7 +343,17 @@ int dfs_unmount(const char *specialfile)
...
@@ -396,7 +343,17 @@ int dfs_unmount(const char *specialfile)
/* lock filesystem */
/* lock filesystem */
dfs_lock
();
dfs_lock
();
fs
=
dfs_filesystem_lookup
(
fullpath
);
for
(
iter
=
&
filesystem_table
[
0
];
iter
<
&
filesystem_table
[
DFS_FILESYSTEMS_MAX
];
iter
++
)
{
/* check if the PATH is mounted */
if
((
iter
->
path
!=
NULL
)
&&
(
strcmp
(
iter
->
path
,
fullpath
)
==
0
))
{
fs
=
iter
;
break
;
}
}
if
(
fs
==
RT_NULL
||
if
(
fs
==
RT_NULL
||
fs
->
ops
->
unmount
==
RT_NULL
||
fs
->
ops
->
unmount
==
RT_NULL
||
fs
->
ops
->
unmount
(
fs
)
<
0
)
fs
->
ops
->
unmount
(
fs
)
<
0
)
...
@@ -437,12 +394,10 @@ err1:
...
@@ -437,12 +394,10 @@ err1:
int
dfs_mkfs
(
const
char
*
fs_name
,
const
char
*
device_name
)
int
dfs_mkfs
(
const
char
*
fs_name
,
const
char
*
device_name
)
{
{
int
index
;
int
index
;
rt_device_t
dev_id
;
rt_device_t
dev_id
=
RT_NULL
;
/* check device name, and it should not be NULL */
/* check device name, and it should not be NULL */
if
(
device_name
==
RT_NULL
)
if
(
device_name
!=
RT_NULL
)
dev_id
=
RT_NULL
;
else
dev_id
=
rt_device_find
(
device_name
);
dev_id
=
rt_device_find
(
device_name
);
if
(
dev_id
==
RT_NULL
)
if
(
dev_id
==
RT_NULL
)
...
@@ -458,18 +413,22 @@ int dfs_mkfs(const char *fs_name, const char *device_name)
...
@@ -458,18 +413,22 @@ int dfs_mkfs(const char *fs_name, const char *device_name)
{
{
if
(
filesystem_operation_table
[
index
]
!=
RT_NULL
&&
if
(
filesystem_operation_table
[
index
]
!=
RT_NULL
&&
strcmp
(
filesystem_operation_table
[
index
]
->
name
,
fs_name
)
==
0
)
strcmp
(
filesystem_operation_table
[
index
]
->
name
,
fs_name
)
==
0
)
break
;
}
dfs_unlock
();
if
(
index
<
DFS_FILESYSTEM_TYPES_MAX
)
{
{
/* find file system operation */
/* find file system operation */
const
struct
dfs_filesystem_operation
*
ops
=
filesystem_operation_table
[
index
];
const
struct
dfs_filesystem_operation
*
ops
=
filesystem_operation_table
[
index
];
dfs_unlock
();
if
(
ops
->
mkfs
==
RT_NULL
)
{
rt_set_errno
(
-
DFS_STATUS_ENOSYS
);
return
-
1
;
}
if
(
ops
->
mkfs
!=
RT_NULL
)
return
ops
->
mkfs
(
dev_id
);
return
ops
->
mkfs
(
dev_id
);
break
;
}
}
}
dfs_unlock
();
rt_kprintf
(
"Can not find the file system which named as %s.
\n
"
,
fs_name
);
rt_kprintf
(
"Can not find the file system which named as %s.
\n
"
,
fs_name
);
return
-
1
;
return
-
1
;
...
@@ -538,11 +497,7 @@ int df(const char *path)
...
@@ -538,11 +497,7 @@ int df(const char *path)
long
long
cap
;
long
long
cap
;
struct
statfs
buffer
;
struct
statfs
buffer
;
if
(
path
==
RT_NULL
)
result
=
dfs_statfs
(
path
?
path
:
RT_NULL
,
&
buffer
);
result
=
dfs_statfs
(
"/"
,
&
buffer
);
else
result
=
dfs_statfs
(
path
,
&
buffer
);
if
(
result
!=
0
)
if
(
result
!=
0
)
{
{
rt_kprintf
(
"dfs_statfs failed.
\n
"
);
rt_kprintf
(
"dfs_statfs failed.
\n
"
);
...
...
components/external/SQLite-3.8.1/SQLiteLib/README
浏览文件 @
a93251ae
...
@@ -10,6 +10,8 @@
...
@@ -10,6 +10,8 @@
* SQLite compile macro
* SQLite compile macro
*/
*/
#define RT_USING_SQLITE
#define RT_USING_SQLITE
2.
关注SQLite目录下的src/sqlite_config_rtthread.h
#define SQLITE_MINIMUM_FILE_DESCRIPTOR 0
#define SQLITE_MINIMUM_FILE_DESCRIPTOR 0
#define SQLITE_OMIT_LOAD_EXTENSION 1
#define SQLITE_OMIT_LOAD_EXTENSION 1
#define SQLITE_OMIT_WAL
#define SQLITE_OMIT_WAL
...
@@ -23,8 +25,8 @@
...
@@ -23,8 +25,8 @@
#define _HAVE_SQLITE_CONFIG_H
#define _HAVE_SQLITE_CONFIG_H
#define BUILD_sqlite
#define BUILD_sqlite
#define SQLITE_OS_OTHER 1
#define SQLITE_OS_OTHER 1
#define SQLITE_OS_RTT 1
#define SQLITE_OS_RTT
HREAD
1
2
.
3
.
用test目录下的test10.c来进行测试.
用test目录下的test10.c来进行测试.
推荐用mini2440bsp,因为板子的ram较大。
推荐用mini2440bsp,因为板子的ram较大。
...
...
components/external/SQLite-3.8.1/SQLiteLib/sqlite3.c
浏览文件 @
a93251ae
...
@@ -25,6 +25,71 @@
...
@@ -25,6 +25,71 @@
#ifndef SQLITE_API
#ifndef SQLITE_API
# define SQLITE_API
# define SQLITE_API
#endif
#endif
/************** Begin file sqlite_config_rtthread.h **************************/
#ifndef _SQLITE_CONFIG_RTTHREAD_H_
#define _SQLITE_CONFIG_RTTHREAD_H_
/*
* SQLite compile macro
*/
#ifndef SQLITE_MINIMUM_FILE_DESCRIPTOR
#define SQLITE_MINIMUM_FILE_DESCRIPTOR 0
#endif
#ifndef SQLITE_OMIT_LOAD_EXTENSION
#define SQLITE_OMIT_LOAD_EXTENSION 1
#endif
//#ifndef #define SQLITE_OMIT_WAL
#define SQLITE_OMIT_WAL
//#endif
#ifndef SQLITE_RTTHREAD_NO_WIDE
#define SQLITE_RTTHREAD_NO_WIDE 1
#endif
#ifndef SQLITE_ENABLE_LOCKING_STYLE
#define SQLITE_ENABLE_LOCKING_STYLE 0
#endif
#ifndef SQLITE_DISABLE_LOCKING_STYLE
#define SQLITE_DISABLE_LOCKING_STYLE 1
#endif
#ifndef SQLITE_TEMP_STORE
#define SQLITE_TEMP_STORE 1
#endif
#ifndef SQLITE_THREADSAFE
#define SQLITE_THREADSAFE 1
#endif
#ifndef HAVE_READLINE
#define HAVE_READLINE 0
#endif
#ifndef NDEBUG
#define NDEBUG
#endif
#ifndef _HAVE_SQLITE_CONFIG_H
#define _HAVE_SQLITE_CONFIG_H
#endif
#ifndef BUILD_sqlite
#define BUILD_sqlite
#endif
#ifndef SQLITE_OS_OTHER
#define SQLITE_OS_OTHER 1
#endif
#ifndef SQLITE_OS_RTTHREAD
#define SQLITE_OS_RTTHREAD 1
#endif
#endif
/************** End of sqlite_config_rtthread.h ******************************/
/************** Begin file sqlite3.h *****************************************/
/************** Begin file sqlite3.h *****************************************/
/*
/*
** 2001 September 15
** 2001 September 15
...
@@ -22649,6 +22714,7 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
...
@@ -22649,6 +22714,7 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
#if SQLITE_OS_RTTHREAD /* This file is used for rt-thread only */
#if SQLITE_OS_RTTHREAD /* This file is used for rt-thread only */
/* #include <rtthread.h> */
/* #include <rtthread.h> */
#include <dfs_posix.h>
/*
/*
** Include code that is common to all os_*.c files
** Include code that is common to all os_*.c files
...
@@ -22863,6 +22929,51 @@ SQLITE_API int sqlite3_open_file_count = 0;
...
@@ -22863,6 +22929,51 @@ SQLITE_API int sqlite3_open_file_count = 0;
/************** End of os_common.h *******************************************/
/************** End of os_common.h *******************************************/
/************** Continuing where we left off in os_rtthread.c ****************/
/************** Continuing where we left off in os_rtthread.c ****************/
#ifndef RT_USING_NEWLIB
#ifndef EINTR
#define EINTR 4 /* Interrupted system call */
#endif
#ifndef ENOLCK
#define ENOLCK 46 /* No record locks available */
#endif
#ifndef EACCES
#define EACCES 13 /* Permission denied */
#endif
#ifndef EPERM
#define EPERM 1 /* Operation not permitted */
#endif
#ifndef ETIMEDOUT
#define ETIMEDOUT 145 /* Connection timed out */
#endif
#ifndef ENOTCONN
#define ENOTCONN 134 /* Transport endpoint is not connected */
#endif
#if defined(__GNUC__) || defined(__ADSPBLACKFIN__)
int _gettimeofday(struct timeval *tp, void *ignore) __attribute__((weak));
int _gettimeofday(struct timeval *tp, void *ignore)
#elif defined(__CC_ARM)
__weak int _gettimeofday(struct timeval *tp, void *ignore)
#elif defined(__IAR_SYSTEMS_ICC__)
#if __VER__ > 540
__weak
#endif
int _gettimeofday(struct timeval *tp, void *ignore)
#else
int _gettimeofday(struct timeval *tp, void *ignore)
#endif
{
return 0;
}
#endif /* RT_USING_NEWLIB */
/*
/*
** Compiling and using WAL mode requires several APIs that are not
** Compiling and using WAL mode requires several APIs that are not
** available in rt-thread.
** available in rt-thread.
...
@@ -23019,7 +23130,7 @@ static int sqlite3_os_type = 0;
...
@@ -23019,7 +23130,7 @@ static int sqlite3_os_type = 0;
# define SYSCALL sqlite3_syscall_ptr
# define SYSCALL sqlite3_syscall_ptr
#endif
#endif
#include <dfs_posix.h>
/* #include <dfs_posix.h> */
static int _Access(const char *pathname, int mode)
static int _Access(const char *pathname, int mode)
{
{
...
@@ -23110,10 +23221,10 @@ static struct rtthread_syscall {
...
@@ -23110,10 +23221,10 @@ static struct rtthread_syscall {
#define osFstat ((int(*)(int,struct stat*))aSyscall[5].pCurrent)
#define osFstat ((int(*)(int,struct stat*))aSyscall[5].pCurrent)
{ "read", (sqlite3_syscall_ptr)read, 0 },
{ "read", (sqlite3_syscall_ptr)read, 0 },
#define osRead ((
ssize_
t(*)(int,void*,size_t))aSyscall[6].pCurrent)
#define osRead ((
in
t(*)(int,void*,size_t))aSyscall[6].pCurrent)
{ "write", (sqlite3_syscall_ptr)write, 0 },
{ "write", (sqlite3_syscall_ptr)write, 0 },
#define osWrite ((
ssize_
t(*)(int,const void*,size_t))aSyscall[7].pCurrent)
#define osWrite ((
in
t(*)(int,const void*,size_t))aSyscall[7].pCurrent)
{ "unlink", (sqlite3_syscall_ptr)unlink, 0 },
{ "unlink", (sqlite3_syscall_ptr)unlink, 0 },
#define osUnlink ((int(*)(const char*))aSyscall[8].pCurrent)
#define osUnlink ((int(*)(const char*))aSyscall[8].pCurrent)
...
@@ -23465,9 +23576,9 @@ static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) {
...
@@ -23465,9 +23576,9 @@ static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) {
return SQLITE_OK;
return SQLITE_OK;
#endif
#endif
case EAGAIN:
case
DFS_STATUS_
EAGAIN:
case ETIMEDOUT:
case ETIMEDOUT:
case EBUSY:
case
DFS_STATUS_
EBUSY:
case EINTR:
case EINTR:
case ENOLCK:
case ENOLCK:
/* random NFS retry error, unless during file system support
/* random NFS retry error, unless during file system support
...
@@ -23506,17 +23617,17 @@ static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) {
...
@@ -23506,17 +23617,17 @@ static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) {
/* invalid fd, unless during file system support introspection, in which
/* invalid fd, unless during file system support introspection, in which
* it actually means what it says */
* it actually means what it says */
#endif
#endif
case EIO:
case
DFS_STATUS_
EIO:
case EBADF:
case
DFS_STATUS_
EBADF:
case EINVAL:
case
DFS_STATUS_
EINVAL:
case ENOTCONN:
case ENOTCONN:
case ENODEV:
case
DFS_STATUS_
ENODEV:
case ENXIO:
case
DFS_STATUS_
ENXIO:
case ENOENT:
case
DFS_STATUS_
ENOENT:
#ifdef ESTALE /* ESTALE is not defined on Interix systems */
#ifdef ESTALE /* ESTALE is not defined on Interix systems */
case ESTALE:
case ESTALE:
#endif
#endif
case ENOSYS:
case
DFS_STATUS_
ENOSYS:
/* these should force the client to close the file and reconnect */
/* these should force the client to close the file and reconnect */
default:
default:
...
@@ -23573,11 +23684,14 @@ static void verifyDbFile(rtthreadFile *pFile){
...
@@ -23573,11 +23684,14 @@ static void verifyDbFile(rtthreadFile *pFile){
pFile->ctrlFlags |= UNIXFILE_WARNED;
pFile->ctrlFlags |= UNIXFILE_WARNED;
return;
return;
}
}
#warning " struct \"stat\" has no field \"st_nlink\""
#ifndef RT_USING_SQLITE
if( buf.st_nlink==0 && (pFile->ctrlFlags & UNIXFILE_DELETE)==0 ){
if( buf.st_nlink==0 && (pFile->ctrlFlags & UNIXFILE_DELETE)==0 ){
sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath);
sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath);
pFile->ctrlFlags |= UNIXFILE_WARNED;
pFile->ctrlFlags |= UNIXFILE_WARNED;
return;
return;
}
}
#endif
}
}
/*
/*
...
@@ -23760,7 +23874,7 @@ static int dotlockLock(sqlite3_file *id, int eFileLock) {
...
@@ -23760,7 +23874,7 @@ static int dotlockLock(sqlite3_file *id, int eFileLock) {
if( rc<0 ){
if( rc<0 ){
/* failed to open/create the lock directory */
/* failed to open/create the lock directory */
int tErrno = errno;
int tErrno = errno;
if( EEXIST == tErrno ){
if(
DFS_STATUS_
EEXIST == tErrno ){
rc = SQLITE_BUSY;
rc = SQLITE_BUSY;
} else {
} else {
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
...
@@ -23811,11 +23925,11 @@ static int dotlockUnlock(sqlite3_file *id, int eFileLock) {
...
@@ -23811,11 +23925,11 @@ static int dotlockUnlock(sqlite3_file *id, int eFileLock) {
/* To fully unlock the database, delete the lock file */
/* To fully unlock the database, delete the lock file */
assert( eFileLock==NO_LOCK );
assert( eFileLock==NO_LOCK );
rc = osRmdir(zLockFile);
rc = osRmdir(zLockFile);
if( rc<0 && errno==ENOTDIR ) rc = osUnlink(zLockFile);
if( rc<0 && errno==
DFS_STATUS_
ENOTDIR ) rc = osUnlink(zLockFile);
if( rc<0 ){
if( rc<0 ){
int tErrno = errno;
int tErrno = errno;
rc = 0;
rc = 0;
if( ENOENT != tErrno ){
if(
DFS_STATUS_
ENOENT != tErrno ){
rc = SQLITE_IOERR_UNLOCK;
rc = SQLITE_IOERR_UNLOCK;
}
}
if( IS_LOCK_ERROR(rc) ){
if( IS_LOCK_ERROR(rc) ){
...
@@ -24258,7 +24372,7 @@ static int rtthreadWrite(
...
@@ -24258,7 +24372,7 @@ static int rtthreadWrite(
SimulateDiskfullError(( wrote=0, amt=1 ));
SimulateDiskfullError(( wrote=0, amt=1 ));
if( amt>0 ){
if( amt>0 ){
if( wrote<0 && pFile->lastErrno!=ENOSPC ){
if( wrote<0 && pFile->lastErrno!=
DFS_STATUS_
ENOSPC ){
/* lastErrno set by seekAndWrite */
/* lastErrno set by seekAndWrite */
return SQLITE_IOERR_WRITE;
return SQLITE_IOERR_WRITE;
}else{
}else{
...
@@ -25090,7 +25204,7 @@ static int rtthreadOpen(
...
@@ -25090,7 +25204,7 @@ static int rtthreadOpen(
fd = robust_open(zName, openFlags, openMode);
fd = robust_open(zName, openFlags, openMode);
OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags));
OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags));
if( fd<0 && errno!=EISDIR && isReadWrite && !isExclusive ){
if( fd<0 && errno!=
DFS_STATUS_
EISDIR && isReadWrite && !isExclusive ){
/* Failed to open the file for read/write access. Try read-only. */
/* Failed to open the file for read/write access. Try read-only. */
flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
openFlags &= ~(O_RDWR|O_CREAT);
openFlags &= ~(O_RDWR|O_CREAT);
...
@@ -25148,7 +25262,7 @@ static int rtthreadDelete(
...
@@ -25148,7 +25262,7 @@ static int rtthreadDelete(
UNUSED_PARAMETER(NotUsed);
UNUSED_PARAMETER(NotUsed);
SimulateIOError(return SQLITE_IOERR_DELETE);
SimulateIOError(return SQLITE_IOERR_DELETE);
if( osUnlink(zPath)==(-1) ){
if( osUnlink(zPath)==(-1) ){
if( errno==ENOENT ){
if( errno==
DFS_STATUS_
ENOENT ){
rc = SQLITE_IOERR_DELETE_NOENT;
rc = SQLITE_IOERR_DELETE_NOENT;
}else{
}else{
rc = rtthreadLogError(SQLITE_IOERR_DELETE, "unlink", zPath);
rc = rtthreadLogError(SQLITE_IOERR_DELETE, "unlink", zPath);
...
@@ -25179,6 +25293,17 @@ static int rtthreadDelete(
...
@@ -25179,6 +25293,17 @@ static int rtthreadDelete(
**
**
** Otherwise return 0.
** Otherwise return 0.
*/
*/
#ifndef F_OK
# define F_OK 0
#endif
#ifndef R_OK
# define R_OK 4
#endif
#ifndef W_OK
# define W_OK 2
#endif
static int rtthreadAccess(
static int rtthreadAccess(
sqlite3_vfs *NotUsed, /* The VFS containing this xAccess method */
sqlite3_vfs *NotUsed, /* The VFS containing this xAccess method */
const char *zPath, /* Path of the file to examine */
const char *zPath, /* Path of the file to examine */
components/external/SQLite-3.8.1/make/Makefile
浏览文件 @
a93251ae
...
@@ -347,6 +347,8 @@ SRC += \
...
@@ -347,6 +347,8 @@ SRC += \
config.h
\
config.h
\
sqlite3.h
sqlite3.h
SRC
+=
$(TOP)
/src/sqlite_config_rtthread.h
# Source code to the test files.
# Source code to the test files.
#
#
TESTSRC
=
\
TESTSRC
=
\
...
...
components/external/SQLite-3.8.1/src/os_rtthread.c
浏览文件 @
a93251ae
...
@@ -16,12 +16,58 @@
...
@@ -16,12 +16,58 @@
#if SQLITE_OS_RTTHREAD
/* This file is used for rt-thread only */
#if SQLITE_OS_RTTHREAD
/* This file is used for rt-thread only */
#include <rtthread.h>
#include <rtthread.h>
#include <dfs_posix.h>
/*
/*
** Include code that is common to all os_*.c files
** Include code that is common to all os_*.c files
*/
*/
#include "os_common.h"
#include "os_common.h"
#ifndef RT_USING_NEWLIB
#ifndef EINTR
#define EINTR 4
/* Interrupted system call */
#endif
#ifndef ENOLCK
#define ENOLCK 46
/* No record locks available */
#endif
#ifndef EACCES
#define EACCES 13
/* Permission denied */
#endif
#ifndef EPERM
#define EPERM 1
/* Operation not permitted */
#endif
#ifndef ETIMEDOUT
#define ETIMEDOUT 145
/* Connection timed out */
#endif
#ifndef ENOTCONN
#define ENOTCONN 134
/* Transport endpoint is not connected */
#endif
#if defined(__GNUC__) || defined(__ADSPBLACKFIN__)
int
_gettimeofday
(
struct
timeval
*
tp
,
void
*
ignore
)
__attribute__
((
weak
));
int
_gettimeofday
(
struct
timeval
*
tp
,
void
*
ignore
)
#elif defined(__CC_ARM)
__weak
int
_gettimeofday
(
struct
timeval
*
tp
,
void
*
ignore
)
#elif defined(__IAR_SYSTEMS_ICC__)
#if __VER__ > 540
__weak
#endif
int
_gettimeofday
(
struct
timeval
*
tp
,
void
*
ignore
)
#else
int
_gettimeofday
(
struct
timeval
*
tp
,
void
*
ignore
)
#endif
{
return
0
;
}
#endif
/* RT_USING_NEWLIB */
/*
/*
** Compiling and using WAL mode requires several APIs that are not
** Compiling and using WAL mode requires several APIs that are not
** available in rt-thread.
** available in rt-thread.
...
@@ -269,10 +315,10 @@ static struct rtthread_syscall {
...
@@ -269,10 +315,10 @@ static struct rtthread_syscall {
#define osFstat ((int(*)(int,struct stat*))aSyscall[5].pCurrent)
#define osFstat ((int(*)(int,struct stat*))aSyscall[5].pCurrent)
{
"read"
,
(
sqlite3_syscall_ptr
)
read
,
0
},
{
"read"
,
(
sqlite3_syscall_ptr
)
read
,
0
},
#define osRead ((
ssize_
t(*)(int,void*,size_t))aSyscall[6].pCurrent)
#define osRead ((
in
t(*)(int,void*,size_t))aSyscall[6].pCurrent)
{
"write"
,
(
sqlite3_syscall_ptr
)
write
,
0
},
{
"write"
,
(
sqlite3_syscall_ptr
)
write
,
0
},
#define osWrite ((
ssize_
t(*)(int,const void*,size_t))aSyscall[7].pCurrent)
#define osWrite ((
in
t(*)(int,const void*,size_t))aSyscall[7].pCurrent)
{
"unlink"
,
(
sqlite3_syscall_ptr
)
unlink
,
0
},
{
"unlink"
,
(
sqlite3_syscall_ptr
)
unlink
,
0
},
#define osUnlink ((int(*)(const char*))aSyscall[8].pCurrent)
#define osUnlink ((int(*)(const char*))aSyscall[8].pCurrent)
...
@@ -624,9 +670,9 @@ static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) {
...
@@ -624,9 +670,9 @@ static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) {
return SQLITE_OK;
return SQLITE_OK;
#endif
#endif
case
EAGAIN
:
case
DFS_STATUS_
EAGAIN
:
case
ETIMEDOUT
:
case
ETIMEDOUT
:
case
EBUSY
:
case
DFS_STATUS_
EBUSY
:
case
EINTR
:
case
EINTR
:
case
ENOLCK
:
case
ENOLCK
:
/* random NFS retry error, unless during file system support
/* random NFS retry error, unless during file system support
...
@@ -665,17 +711,17 @@ static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) {
...
@@ -665,17 +711,17 @@ static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) {
/* invalid fd, unless during file system support introspection, in which
/* invalid fd, unless during file system support introspection, in which
* it actually means what it says */
* it actually means what it says */
#endif
#endif
case
EIO
:
case
DFS_STATUS_
EIO
:
case
EBADF
:
case
DFS_STATUS_
EBADF
:
case
EINVAL
:
case
DFS_STATUS_
EINVAL
:
case
ENOTCONN
:
case
ENOTCONN
:
case
ENODEV
:
case
DFS_STATUS_
ENODEV
:
case
ENXIO
:
case
DFS_STATUS_
ENXIO
:
case
ENOENT
:
case
DFS_STATUS_
ENOENT
:
#ifdef ESTALE
/* ESTALE is not defined on Interix systems */
#ifdef ESTALE
/* ESTALE is not defined on Interix systems */
case
ESTALE
:
case
ESTALE
:
#endif
#endif
case
ENOSYS
:
case
DFS_STATUS_
ENOSYS
:
/* these should force the client to close the file and reconnect */
/* these should force the client to close the file and reconnect */
default:
default:
...
@@ -732,11 +778,14 @@ static void verifyDbFile(rtthreadFile *pFile){
...
@@ -732,11 +778,14 @@ static void verifyDbFile(rtthreadFile *pFile){
pFile
->
ctrlFlags
|=
UNIXFILE_WARNED
;
pFile
->
ctrlFlags
|=
UNIXFILE_WARNED
;
return
;
return
;
}
}
#warning " struct \"stat\" has no field \"st_nlink\""
#ifndef RT_USING_SQLITE
if
(
buf
.
st_nlink
==
0
&&
(
pFile
->
ctrlFlags
&
UNIXFILE_DELETE
)
==
0
){
if
(
buf
.
st_nlink
==
0
&&
(
pFile
->
ctrlFlags
&
UNIXFILE_DELETE
)
==
0
){
sqlite3_log
(
SQLITE_WARNING
,
"file unlinked while open: %s"
,
pFile
->
zPath
);
sqlite3_log
(
SQLITE_WARNING
,
"file unlinked while open: %s"
,
pFile
->
zPath
);
pFile
->
ctrlFlags
|=
UNIXFILE_WARNED
;
pFile
->
ctrlFlags
|=
UNIXFILE_WARNED
;
return
;
return
;
}
}
#endif
}
}
/*
/*
...
@@ -919,7 +968,7 @@ static int dotlockLock(sqlite3_file *id, int eFileLock) {
...
@@ -919,7 +968,7 @@ static int dotlockLock(sqlite3_file *id, int eFileLock) {
if
(
rc
<
0
){
if
(
rc
<
0
){
/* failed to open/create the lock directory */
/* failed to open/create the lock directory */
int
tErrno
=
errno
;
int
tErrno
=
errno
;
if
(
EEXIST
==
tErrno
){
if
(
DFS_STATUS_
EEXIST
==
tErrno
){
rc
=
SQLITE_BUSY
;
rc
=
SQLITE_BUSY
;
}
else
{
}
else
{
rc
=
sqliteErrorFromPosixError
(
tErrno
,
SQLITE_IOERR_LOCK
);
rc
=
sqliteErrorFromPosixError
(
tErrno
,
SQLITE_IOERR_LOCK
);
...
@@ -970,11 +1019,11 @@ static int dotlockUnlock(sqlite3_file *id, int eFileLock) {
...
@@ -970,11 +1019,11 @@ static int dotlockUnlock(sqlite3_file *id, int eFileLock) {
/* To fully unlock the database, delete the lock file */
/* To fully unlock the database, delete the lock file */
assert
(
eFileLock
==
NO_LOCK
);
assert
(
eFileLock
==
NO_LOCK
);
rc
=
osRmdir
(
zLockFile
);
rc
=
osRmdir
(
zLockFile
);
if
(
rc
<
0
&&
errno
==
ENOTDIR
)
rc
=
osUnlink
(
zLockFile
);
if
(
rc
<
0
&&
errno
==
DFS_STATUS_
ENOTDIR
)
rc
=
osUnlink
(
zLockFile
);
if
(
rc
<
0
){
if
(
rc
<
0
){
int
tErrno
=
errno
;
int
tErrno
=
errno
;
rc
=
0
;
rc
=
0
;
if
(
ENOENT
!=
tErrno
){
if
(
DFS_STATUS_
ENOENT
!=
tErrno
){
rc
=
SQLITE_IOERR_UNLOCK
;
rc
=
SQLITE_IOERR_UNLOCK
;
}
}
if
(
IS_LOCK_ERROR
(
rc
)
){
if
(
IS_LOCK_ERROR
(
rc
)
){
...
@@ -1417,7 +1466,7 @@ static int rtthreadWrite(
...
@@ -1417,7 +1466,7 @@ static int rtthreadWrite(
SimulateDiskfullError
((
wrote
=
0
,
amt
=
1
));
SimulateDiskfullError
((
wrote
=
0
,
amt
=
1
));
if
(
amt
>
0
){
if
(
amt
>
0
){
if
(
wrote
<
0
&&
pFile
->
lastErrno
!=
ENOSPC
){
if
(
wrote
<
0
&&
pFile
->
lastErrno
!=
DFS_STATUS_
ENOSPC
){
/* lastErrno set by seekAndWrite */
/* lastErrno set by seekAndWrite */
return
SQLITE_IOERR_WRITE
;
return
SQLITE_IOERR_WRITE
;
}
else
{
}
else
{
...
@@ -2249,7 +2298,7 @@ static int rtthreadOpen(
...
@@ -2249,7 +2298,7 @@ static int rtthreadOpen(
fd
=
robust_open
(
zName
,
openFlags
,
openMode
);
fd
=
robust_open
(
zName
,
openFlags
,
openMode
);
OSTRACE
((
"OPENX %-3d %s 0%o
\n
"
,
fd
,
zName
,
openFlags
));
OSTRACE
((
"OPENX %-3d %s 0%o
\n
"
,
fd
,
zName
,
openFlags
));
if
(
fd
<
0
&&
errno
!=
EISDIR
&&
isReadWrite
&&
!
isExclusive
){
if
(
fd
<
0
&&
errno
!=
DFS_STATUS_
EISDIR
&&
isReadWrite
&&
!
isExclusive
){
/* Failed to open the file for read/write access. Try read-only. */
/* Failed to open the file for read/write access. Try read-only. */
flags
&=
~
(
SQLITE_OPEN_READWRITE
|
SQLITE_OPEN_CREATE
);
flags
&=
~
(
SQLITE_OPEN_READWRITE
|
SQLITE_OPEN_CREATE
);
openFlags
&=
~
(
O_RDWR
|
O_CREAT
);
openFlags
&=
~
(
O_RDWR
|
O_CREAT
);
...
@@ -2307,7 +2356,7 @@ static int rtthreadDelete(
...
@@ -2307,7 +2356,7 @@ static int rtthreadDelete(
UNUSED_PARAMETER
(
NotUsed
);
UNUSED_PARAMETER
(
NotUsed
);
SimulateIOError
(
return
SQLITE_IOERR_DELETE
);
SimulateIOError
(
return
SQLITE_IOERR_DELETE
);
if
(
osUnlink
(
zPath
)
==
(
-
1
)
){
if
(
osUnlink
(
zPath
)
==
(
-
1
)
){
if
(
errno
==
ENOENT
){
if
(
errno
==
DFS_STATUS_
ENOENT
){
rc
=
SQLITE_IOERR_DELETE_NOENT
;
rc
=
SQLITE_IOERR_DELETE_NOENT
;
}
else
{
}
else
{
rc
=
rtthreadLogError
(
SQLITE_IOERR_DELETE
,
"unlink"
,
zPath
);
rc
=
rtthreadLogError
(
SQLITE_IOERR_DELETE
,
"unlink"
,
zPath
);
...
@@ -2338,6 +2387,17 @@ static int rtthreadDelete(
...
@@ -2338,6 +2387,17 @@ static int rtthreadDelete(
**
**
** Otherwise return 0.
** Otherwise return 0.
*/
*/
#ifndef F_OK
# define F_OK 0
#endif
#ifndef R_OK
# define R_OK 4
#endif
#ifndef W_OK
# define W_OK 2
#endif
static
int
rtthreadAccess
(
static
int
rtthreadAccess
(
sqlite3_vfs
*
NotUsed
,
/* The VFS containing this xAccess method */
sqlite3_vfs
*
NotUsed
,
/* The VFS containing this xAccess method */
const
char
*
zPath
,
/* Path of the file to examine */
const
char
*
zPath
,
/* Path of the file to examine */
...
...
components/external/SQLite-3.8.1/src/sqlite_config_rtthread.h
0 → 100644
浏览文件 @
a93251ae
#ifndef _SQLITE_CONFIG_RTTHREAD_H_
#define _SQLITE_CONFIG_RTTHREAD_H_
/*
* SQLite compile macro
*/
#ifndef SQLITE_MINIMUM_FILE_DESCRIPTOR
#define SQLITE_MINIMUM_FILE_DESCRIPTOR 0
#endif
#ifndef SQLITE_OMIT_LOAD_EXTENSION
#define SQLITE_OMIT_LOAD_EXTENSION 1
#endif
//#ifndef #define SQLITE_OMIT_WAL
#define SQLITE_OMIT_WAL
//#endif
#ifndef SQLITE_RTTHREAD_NO_WIDE
#define SQLITE_RTTHREAD_NO_WIDE 1
#endif
#ifndef SQLITE_ENABLE_LOCKING_STYLE
#define SQLITE_ENABLE_LOCKING_STYLE 0
#endif
#ifndef SQLITE_DISABLE_LOCKING_STYLE
#define SQLITE_DISABLE_LOCKING_STYLE 1
#endif
#ifndef SQLITE_TEMP_STORE
#define SQLITE_TEMP_STORE 1
#endif
#ifndef SQLITE_THREADSAFE
#define SQLITE_THREADSAFE 1
#endif
#ifndef HAVE_READLINE
#define HAVE_READLINE 0
#endif
#ifndef NDEBUG
#define NDEBUG
#endif
#ifndef _HAVE_SQLITE_CONFIG_H
#define _HAVE_SQLITE_CONFIG_H
#endif
#ifndef BUILD_sqlite
#define BUILD_sqlite
#endif
#ifndef SQLITE_OS_OTHER
#define SQLITE_OS_OTHER 1
#endif
#ifndef SQLITE_OS_RTTHREAD
#define SQLITE_OS_RTTHREAD 1
#endif
#endif
components/external/SQLite-3.8.1/tool/mksqlite3c.tcl
浏览文件 @
a93251ae
...
@@ -228,6 +228,7 @@ proc copy_file {filename} {
...
@@ -228,6 +228,7 @@ proc copy_file {filename} {
# inlining opportunities.
# inlining opportunities.
#
#
foreach file
{
foreach file
{
sqlite_config_rtthread.h
sqlite3.h
sqlite3.h
sqliteInt.h
sqliteInt.h
...
...
components/pthreads/posix_types.h
浏览文件 @
a93251ae
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
*
*
* Change Logs:
* Change Logs:
* Date Author Notes
* Date Author Notes
* 2013-12-23 Bernard Add the checking for ESHUTDOWN
*/
*/
#ifndef __POSIX_TYPES_H__
#ifndef __POSIX_TYPES_H__
...
@@ -37,7 +38,9 @@
...
@@ -37,7 +38,9 @@
#include <errno.h>
#include <errno.h>
#include <stdarg.h>
#include <stdarg.h>
#ifndef ESHUTDOWN
#define ESHUTDOWN 180
#define ESHUTDOWN 180
#endif
#else
#else
...
...
examples/kernel/SConscript
浏览文件 @
a93251ae
...
@@ -34,6 +34,8 @@ memp_simple.c
...
@@ -34,6 +34,8 @@ memp_simple.c
tc_sample.c
tc_sample.c
"""
)
"""
)
group
=
DefineGroup
(
'examples'
,
src
,
depend
=
[
'RT_USING_TC'
])
group
=
DefineGroup
(
'examples'
,
src
,
depend
=
[
'RT_USING_TC'
],
CPPPATH
=
[
GetCurrentDir
()])
Return
(
'group'
)
Return
(
'group'
)
examples/kernel/cpuusage.c
浏览文件 @
a93251ae
examples/kernel/event_simple.c
浏览文件 @
a93251ae
examples/kernel/heap_malloc.c
浏览文件 @
a93251ae
...
@@ -9,8 +9,8 @@ static rt_bool_t mem_check(rt_uint8_t *ptr, rt_uint8_t value, rt_uint32_t len)
...
@@ -9,8 +9,8 @@ static rt_bool_t mem_check(rt_uint8_t *ptr, rt_uint8_t value, rt_uint32_t len)
{
{
while
(
len
)
while
(
len
)
{
{
if
(
*
ptr
!=
value
)
return
RT_FALSE
;
if
(
*
ptr
!=
value
)
return
RT_FALSE
;
ptr
++
;
ptr
++
;
len
--
;
len
--
;
}
}
...
@@ -20,6 +20,7 @@ static rt_bool_t mem_check(rt_uint8_t *ptr, rt_uint8_t value, rt_uint32_t len)
...
@@ -20,6 +20,7 @@ static rt_bool_t mem_check(rt_uint8_t *ptr, rt_uint8_t value, rt_uint32_t len)
static
void
heap_malloc_init
()
static
void
heap_malloc_init
()
{
{
rt_uint8_t
res
=
TC_STAT_PASSED
;
rt_uint8_t
*
ptr1
,
*
ptr2
,
*
ptr3
,
*
ptr4
,
*
ptr5
;
rt_uint8_t
*
ptr1
,
*
ptr2
,
*
ptr3
,
*
ptr4
,
*
ptr5
;
ptr1
=
rt_malloc
(
1
);
ptr1
=
rt_malloc
(
1
);
...
@@ -33,14 +34,18 @@ static void heap_malloc_init()
...
@@ -33,14 +34,18 @@ static void heap_malloc_init()
memset
(
ptr3
,
3
,
31
);
memset
(
ptr3
,
3
,
31
);
memset
(
ptr4
,
4
,
127
);
memset
(
ptr4
,
4
,
127
);
if
(
mem_check
(
ptr1
,
1
,
1
)
!=
RT_FALSE
)
goto
_failed
;
if
(
mem_check
(
ptr1
,
1
,
1
)
==
RT_FALSE
)
if
(
mem_check
(
ptr2
,
2
,
13
)
!=
RT_FALSE
)
goto
_failed
;
res
=
TC_STAT_FAILED
;
if
(
mem_check
(
ptr3
,
3
,
31
)
!=
RT_FALSE
)
goto
_failed
;
if
(
mem_check
(
ptr2
,
2
,
13
)
==
RT_FALSE
)
if
(
mem_check
(
ptr4
,
4
,
127
)
!=
RT_FALSE
)
goto
_failed
;
res
=
TC_STAT_FAILED
;
if
(
mem_check
(
ptr3
,
3
,
31
)
==
RT_FALSE
)
res
=
TC_STAT_FAILED
;
if
(
mem_check
(
ptr4
,
4
,
127
)
==
RT_FALSE
)
res
=
TC_STAT_FAILED
;
rt_free
(
ptr4
);
rt_free
(
ptr4
);
rt_free
(
ptr3
);
rt_free
(
ptr3
);
rt_free
(
ptr3
);
rt_free
(
ptr2
);
rt_free
(
ptr1
);
rt_free
(
ptr1
);
if
(
ptr5
!=
RT_NULL
)
if
(
ptr5
!=
RT_NULL
)
...
@@ -48,10 +53,7 @@ static void heap_malloc_init()
...
@@ -48,10 +53,7 @@ static void heap_malloc_init()
rt_free
(
ptr5
);
rt_free
(
ptr5
);
}
}
tc_done
(
TC_STAT_PASSED
);
tc_done
(
res
);
_failed:
tc_done
(
TC_STAT_FAILED
);
}
}
#ifdef RT_USING_TC
#ifdef RT_USING_TC
...
...
examples/kernel/heap_realloc.c
浏览文件 @
a93251ae
...
@@ -20,6 +20,7 @@ static rt_bool_t mem_check(rt_uint8_t *ptr, rt_uint8_t value, rt_uint32_t len)
...
@@ -20,6 +20,7 @@ static rt_bool_t mem_check(rt_uint8_t *ptr, rt_uint8_t value, rt_uint32_t len)
static
void
heap_realloc_init
()
static
void
heap_realloc_init
()
{
{
rt_uint8_t
res
=
TC_STAT_PASSED
;
rt_uint8_t
*
ptr1
,
*
ptr2
,
*
ptr3
,
*
ptr4
,
*
ptr5
;
rt_uint8_t
*
ptr1
,
*
ptr2
,
*
ptr3
,
*
ptr4
,
*
ptr5
;
ptr1
=
rt_malloc
(
1
);
ptr1
=
rt_malloc
(
1
);
...
@@ -33,36 +34,54 @@ static void heap_realloc_init()
...
@@ -33,36 +34,54 @@ static void heap_realloc_init()
memset
(
ptr3
,
3
,
31
);
memset
(
ptr3
,
3
,
31
);
memset
(
ptr4
,
4
,
127
);
memset
(
ptr4
,
4
,
127
);
if
(
mem_check
(
ptr1
,
1
,
1
)
!=
RT_FALSE
)
goto
_failed
;
if
(
mem_check
(
ptr1
,
1
,
1
)
==
RT_FALSE
)
if
(
mem_check
(
ptr2
,
2
,
13
)
!=
RT_FALSE
)
goto
_failed
;
{
if
(
mem_check
(
ptr3
,
3
,
31
)
!=
RT_FALSE
)
goto
_failed
;
res
=
TC_STAT_FAILED
;
if
(
mem_check
(
ptr4
,
4
,
127
)
!=
RT_FALSE
)
goto
_failed
;
goto
_free
;
}
if
(
mem_check
(
ptr2
,
2
,
13
)
==
RT_FALSE
)
{
res
=
TC_STAT_FAILED
;
goto
_free
;
}
if
(
mem_check
(
ptr3
,
3
,
31
)
==
RT_FALSE
)
{
res
=
TC_STAT_FAILED
;
goto
_free
;
}
if
(
mem_check
(
ptr4
,
4
,
127
)
==
RT_FALSE
)
{
res
=
TC_STAT_FAILED
;
goto
_free
;
}
ptr1
=
rt_realloc
(
ptr1
,
13
);
ptr1
=
rt_realloc
(
ptr1
,
13
);
ptr2
=
rt_realloc
(
ptr2
,
31
);
ptr2
=
rt_realloc
(
ptr2
,
31
);
ptr3
=
rt_realloc
(
ptr3
,
127
);
ptr3
=
rt_realloc
(
ptr3
,
127
);
ptr4
=
rt_realloc
(
ptr4
,
1
);
ptr4
=
rt_realloc
(
ptr4
,
1
);
ptr5
=
rt_realloc
(
ptr5
,
0
);
ptr5
=
rt_realloc
(
ptr5
,
0
);
if
(
ptr5
)
{
rt_kprintf
(
"realloc(ptr, 0) should return NULL
\n
"
);
res
=
TC_STAT_FAILED
;
}
if
(
mem_check
(
ptr1
,
1
,
1
)
!=
RT_FALSE
)
goto
_failed
;
if
(
mem_check
(
ptr1
,
1
,
1
)
==
RT_FALSE
)
if
(
mem_check
(
ptr2
,
2
,
13
)
!=
RT_FALSE
)
goto
_failed
;
res
=
TC_STAT_FAILED
;
if
(
mem_check
(
ptr3
,
3
,
31
)
!=
RT_FALSE
)
goto
_failed
;
if
(
mem_check
(
ptr2
,
2
,
13
)
==
RT_FALSE
)
if
(
mem_check
(
ptr4
,
4
,
1
)
!=
RT_FALSE
)
goto
_failed
;
res
=
TC_STAT_FAILED
;
if
(
mem_check
(
ptr3
,
3
,
31
)
==
RT_FALSE
)
res
=
TC_STAT_FAILED
;
if
(
mem_check
(
ptr4
,
4
,
1
)
==
RT_FALSE
)
res
=
TC_STAT_FAILED
;
_free:
rt_free
(
ptr4
);
rt_free
(
ptr4
);
rt_free
(
ptr3
);
rt_free
(
ptr3
);
rt_free
(
ptr3
);
rt_free
(
ptr2
);
rt_free
(
ptr1
);
rt_free
(
ptr1
);
if
(
ptr5
!=
RT_NULL
)
tc_done
(
res
);
{
rt_free
(
ptr5
);
}
tc_done
(
TC_STAT_PASSED
);
_failed:
tc_done
(
TC_STAT_FAILED
);
}
}
#ifdef RT_USING_TC
#ifdef RT_USING_TC
...
...
examples/kernel/mbox_send_wait.c
浏览文件 @
a93251ae
examples/kernel/mbox_simple.c
浏览文件 @
a93251ae
examples/kernel/memp_simple.c
浏览文件 @
a93251ae
examples/kernel/messageq_simple.c
浏览文件 @
a93251ae
examples/kernel/mutex_simple.c
浏览文件 @
a93251ae
examples/kernel/semaphore_buffer_worker.c
浏览文件 @
a93251ae
examples/kernel/semaphore_dynamic.c
浏览文件 @
a93251ae
...
@@ -25,9 +25,13 @@ static void thread_entry(void* parameter)
...
@@ -25,9 +25,13 @@ static void thread_entry(void* parameter)
result
=
rt_sem_take
(
sem
,
10
);
result
=
rt_sem_take
(
sem
,
10
);
if
(
result
==
-
RT_ETIMEOUT
)
if
(
result
==
-
RT_ETIMEOUT
)
{
{
/* 判断是否刚好过去10个OS Tick */
rt_tick_t
new_tick
=
rt_tick_get
();
if
(
rt_tick_get
()
-
tick
!=
10
)
/* 可以有两个 tick 的误差 */
if
(
new_tick
-
tick
>=
12
)
{
{
rt_kprintf
(
"tick error to large: expect: 10, get %d
\n
"
,
new_tick
-
tick
);
/* 如果失败,则测试失败 */
/* 如果失败,则测试失败 */
tc_done
(
TC_STAT_FAILED
);
tc_done
(
TC_STAT_FAILED
);
rt_sem_delete
(
sem
);
rt_sem_delete
(
sem
);
...
@@ -90,13 +94,16 @@ static void _tc_cleanup()
...
@@ -90,13 +94,16 @@ static void _tc_cleanup()
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
rt_enter_critical
();
rt_enter_critical
();
if
(
sem
)
{
rt_sem_delete
(
sem
);
sem
=
RT_NULL
;
}
/* 删除线程 */
/* 删除线程 */
if
(
tid
!=
RT_NULL
&&
tid
->
stat
!=
RT_THREAD_CLOSE
)
if
(
tid
!=
RT_NULL
&&
tid
->
stat
!=
RT_THREAD_CLOSE
)
{
{
rt_thread_delete
(
tid
);
rt_thread_delete
(
tid
);
/* 删除信号量 */
rt_sem_delete
(
sem
);
}
}
/* 调度器解锁 */
/* 调度器解锁 */
...
...
examples/kernel/semaphore_priority.c
浏览文件 @
a93251ae
...
@@ -100,6 +100,12 @@ static void _tc_cleanup()
...
@@ -100,6 +100,12 @@ static void _tc_cleanup()
rt_thread_delete
(
t2
);
rt_thread_delete
(
t2
);
rt_thread_delete
(
worker
);
rt_thread_delete
(
worker
);
if
(
sem
)
{
rt_sem_delete
(
sem
);
sem
=
RT_NULL
;
}
if
(
t1_count
>
t2_count
)
if
(
t1_count
>
t2_count
)
tc_done
(
TC_STAT_FAILED
);
tc_done
(
TC_STAT_FAILED
);
else
else
...
...
examples/kernel/semaphore_producer_consumer.c
浏览文件 @
a93251ae
...
@@ -119,6 +119,10 @@ static void _tc_cleanup()
...
@@ -119,6 +119,10 @@ static void _tc_cleanup()
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
rt_enter_critical
();
rt_enter_critical
();
rt_sem_detach
(
&
sem_lock
);
rt_sem_detach
(
&
sem_empty
);
rt_sem_detach
(
&
sem_full
);
/* 删除线程 */
/* 删除线程 */
if
(
producer_tid
!=
RT_NULL
&&
producer_tid
->
stat
!=
RT_THREAD_CLOSE
)
if
(
producer_tid
!=
RT_NULL
&&
producer_tid
->
stat
!=
RT_THREAD_CLOSE
)
rt_thread_delete
(
producer_tid
);
rt_thread_delete
(
producer_tid
);
...
...
examples/kernel/semaphore_static.c
浏览文件 @
a93251ae
...
@@ -27,9 +27,13 @@ static void thread_entry(void* parameter)
...
@@ -27,9 +27,13 @@ static void thread_entry(void* parameter)
result
=
rt_sem_take
(
&
sem
,
10
);
result
=
rt_sem_take
(
&
sem
,
10
);
if
(
result
==
-
RT_ETIMEOUT
)
if
(
result
==
-
RT_ETIMEOUT
)
{
{
/* 超时后判断是否刚好是10个OS Tick */
rt_tick_t
new_tick
=
rt_tick_get
();
if
(
rt_tick_get
()
-
tick
!=
10
)
/* 可以有两个 tick 的误差 */
if
(
new_tick
-
tick
>=
12
)
{
{
rt_kprintf
(
"tick error to large: expect: 10, get %d
\n
"
,
new_tick
-
tick
);
tc_done
(
TC_STAT_FAILED
);
tc_done
(
TC_STAT_FAILED
);
rt_sem_detach
(
&
sem
);
rt_sem_detach
(
&
sem
);
return
;
return
;
...
...
examples/kernel/tc_comm.c
浏览文件 @
a93251ae
...
@@ -18,15 +18,17 @@ static void (*_tc_cleanup)(void) = RT_NULL;
...
@@ -18,15 +18,17 @@ static void (*_tc_cleanup)(void) = RT_NULL;
static
rt_uint32_t
_tc_scale
=
1
;
static
rt_uint32_t
_tc_scale
=
1
;
FINSH_VAR_EXPORT
(
_tc_scale
,
finsh_type_int
,
the
testcase
timer
timeout
scale
)
FINSH_VAR_EXPORT
(
_tc_scale
,
finsh_type_int
,
the
testcase
timer
timeout
scale
)
static
rt_uint32_t
_tc_loop
;
void
tc_thread_entry
(
void
*
parameter
)
void
tc_thread_entry
(
void
*
parameter
)
{
{
unsigned
int
fail_count
=
0
;
struct
finsh_syscall
*
index
;
struct
finsh_syscall
*
index
;
/* create tc semaphore */
/* create tc semaphore */
rt_sem_init
(
&
_tc_sem
,
"tc"
,
0
,
RT_IPC_FLAG_FIFO
);
rt_sem_init
(
&
_tc_sem
,
"tc"
,
0
,
RT_IPC_FLAG_FIFO
);
while
(
_tc_stat
&
TC_STAT_RUNNING
)
do
{
{
for
(
index
=
_syscall_table_begin
;
index
<
_syscall_table_end
;
FINSH_NEXT_SYSCALL
(
index
))
for
(
index
=
_syscall_table_begin
;
index
<
_syscall_table_end
;
FINSH_NEXT_SYSCALL
(
index
))
{
{
/* search testcase */
/* search testcase */
...
@@ -40,7 +42,10 @@ void tc_thread_entry(void* parameter)
...
@@ -40,7 +42,10 @@ void tc_thread_entry(void* parameter)
tick
=
index
->
func
();
tick
=
index
->
func
();
if
(
tick
>
0
)
if
(
tick
>
0
)
{
{
/* Make sure we are going to be blocked. */
rt_sem_control
(
&
_tc_sem
,
RT_IPC_CMD_RESET
,
0
);
rt_sem_take
(
&
_tc_sem
,
tick
*
_tc_scale
);
rt_sem_take
(
&
_tc_sem
,
tick
*
_tc_scale
);
}
if
(
_tc_cleanup
!=
RT_NULL
)
if
(
_tc_cleanup
!=
RT_NULL
)
{
{
...
@@ -49,36 +54,46 @@ void tc_thread_entry(void* parameter)
...
@@ -49,36 +54,46 @@ void tc_thread_entry(void* parameter)
_tc_cleanup
=
RT_NULL
;
_tc_cleanup
=
RT_NULL
;
}
}
rt_sem_trytake
(
&
_tc_sem
);
/* by nl1031 */
if
(
_tc_stat
&
TC_STAT_RUNNING
)
{
rt_kprintf
(
"TestCase[%s] exit with stat TC_STAT_RUNNING."
" Please fix the TC.
\n
"
,
_tc_current
);
/* If the TC forgot to clear the flag, we do it. */
_tc_stat
&=
~
TC_STAT_RUNNING
;
}
if
(
_tc_stat
&
TC_STAT_FAILED
)
if
(
_tc_stat
&
TC_STAT_FAILED
)
{
rt_kprintf
(
"TestCase[%s] failed
\n
"
,
_tc_current
);
rt_kprintf
(
"TestCase[%s] failed
\n
"
,
_tc_current
);
else
fail_count
++
;
rt_kprintf
(
"TestCase[%s] passed
\n
"
,
_tc_current
);
}
}
else
else
{
{
if
(
_tc_cleanup
!=
RT_NULL
)
rt_kprintf
(
"TestCase[%s] passed
\n
"
,
_tc_current
);
{
/* perform testcase cleanup */
_tc_cleanup
();
_tc_cleanup
=
RT_NULL
;
}
}
}
}
}
}
}
}
}
while
(
_tc_loop
);
rt_kprintf
(
"RT-Thread TestCase Running Done!
\n
"
);
rt_kprintf
(
"RT-Thread TestCase Running Done!
\n
"
);
if
(
fail_count
)
{
rt_kprintf
(
"%d tests failed
\n
"
,
fail_count
);
}
else
{
rt_kprintf
(
"All tests passed
\n
"
);
}
/* detach tc semaphore */
/* detach tc semaphore */
rt_sem_detach
(
&
_tc_sem
);
rt_sem_detach
(
&
_tc_sem
);
}
}
void
tc_stop
()
void
tc_stop
()
{
{
_tc_stat
&=
~
TC_STAT_RUNNING
;
_tc_loop
=
0
;
rt_thread_delay
(
RT_TICK_PER_SECOND
/
2
);
rt_thread_delay
(
10
*
RT_TICK_PER_SECOND
);
if
(
_tc_thread
.
stat
!=
RT_THREAD_INIT
)
if
(
_tc_thread
.
stat
!=
RT_THREAD_INIT
)
{
{
/* lock scheduler */
/* lock scheduler */
...
@@ -153,6 +168,13 @@ void tc_start(const char* tc_prefix)
...
@@ -153,6 +168,13 @@ void tc_start(const char* tc_prefix)
}
}
FINSH_FUNCTION_EXPORT
(
tc_start
,
start
testcase
with
testcase
prefix
or
name
);
FINSH_FUNCTION_EXPORT
(
tc_start
,
start
testcase
with
testcase
prefix
or
name
);
void
tc_loop
(
const
char
*
tc_prefix
)
{
_tc_loop
=
1
;
tc_start
(
tc_prefix
);
}
FINSH_FUNCTION_EXPORT
(
tc_loop
,
start
testcase
with
testcase
prefix
or
name
in
loop
mode
);
void
list_tc
()
void
list_tc
()
{
{
struct
finsh_syscall
*
index
;
struct
finsh_syscall
*
index
;
...
...
examples/kernel/tc_comm.h
浏览文件 @
a93251ae
examples/kernel/tc_sample.c
浏览文件 @
a93251ae
examples/kernel/thread_delay.c
浏览文件 @
a93251ae
...
@@ -14,7 +14,7 @@ static void thread_entry(void* parameter)
...
@@ -14,7 +14,7 @@ static void thread_entry(void* parameter)
rt_kprintf
(
"thread delay 10 tick
\n
"
);
rt_kprintf
(
"thread delay 10 tick
\n
"
);
tick
=
rt_tick_get
();
tick
=
rt_tick_get
();
rt_thread_delay
(
10
);
rt_thread_delay
(
10
);
if
(
rt_tick_get
()
-
tick
>
10
)
if
(
rt_tick_get
()
-
tick
>
11
)
{
{
tc_done
(
TC_STAT_FAILED
);
tc_done
(
TC_STAT_FAILED
);
return
;
return
;
...
@@ -23,7 +23,7 @@ static void thread_entry(void* parameter)
...
@@ -23,7 +23,7 @@ static void thread_entry(void* parameter)
rt_kprintf
(
"thread delay 15 tick
\n
"
);
rt_kprintf
(
"thread delay 15 tick
\n
"
);
tick
=
rt_tick_get
();
tick
=
rt_tick_get
();
rt_thread_delay
(
15
);
rt_thread_delay
(
15
);
if
(
rt_tick_get
()
-
tick
>
15
)
if
(
rt_tick_get
()
-
tick
>
16
)
{
{
tc_done
(
TC_STAT_FAILED
);
tc_done
(
TC_STAT_FAILED
);
return
;
return
;
...
...
examples/kernel/thread_delete.c
浏览文件 @
a93251ae
...
@@ -41,7 +41,7 @@ static void thread2_entry(void* parameter)
...
@@ -41,7 +41,7 @@ static void thread2_entry(void* parameter)
/* 线程2拥有较高的优先级,以抢占线程1而获得执行 */
/* 线程2拥有较高的优先级,以抢占线程1而获得执行 */
/* 线程2启动后先睡眠10个OS Tick */
/* 线程2启动后先睡眠10个OS Tick */
rt_thread_delay
(
10
);
rt_thread_delay
(
RT_TICK_PER_SECOND
);
/*
/*
* 线程2唤醒后直接删除线程1,删除线程1后,线程1自动脱离就绪线程
* 线程2唤醒后直接删除线程1,删除线程1后,线程1自动脱离就绪线程
...
@@ -53,7 +53,7 @@ static void thread2_entry(void* parameter)
...
@@ -53,7 +53,7 @@ static void thread2_entry(void* parameter)
* 线程2继续休眠10个OS Tick然后退出,线程2休眠后应切换到idle线程
* 线程2继续休眠10个OS Tick然后退出,线程2休眠后应切换到idle线程
* idle线程将执行真正的线程1控制块和线程栈的删除
* idle线程将执行真正的线程1控制块和线程栈的删除
*/
*/
rt_thread_delay
(
10
);
rt_thread_delay
(
RT_TICK_PER_SECOND
);
}
}
static
void
thread2_cleanup
(
struct
rt_thread
*
tid
)
static
void
thread2_cleanup
(
struct
rt_thread
*
tid
)
...
@@ -100,7 +100,7 @@ int thread_delete_init()
...
@@ -100,7 +100,7 @@ int thread_delete_init()
else
else
tc_stat
(
TC_STAT_END
|
TC_STAT_FAILED
);
tc_stat
(
TC_STAT_END
|
TC_STAT_FAILED
);
return
0
;
return
10
*
RT_TICK_PER_SECOND
;
}
}
#ifdef RT_USING_TC
#ifdef RT_USING_TC
...
@@ -112,12 +112,12 @@ static void _tc_cleanup()
...
@@ -112,12 +112,12 @@ static void _tc_cleanup()
/* delete thread */
/* delete thread */
if
(
tid1
!=
RT_NULL
)
if
(
tid1
!=
RT_NULL
)
{
{
rt_kprintf
(
"tid1 is bad
\n
"
);
rt_kprintf
(
"tid1 is %p, should be NULL
\n
"
,
tid1
);
tc_stat
(
TC_STAT_FAILED
);
tc_stat
(
TC_STAT_FAILED
);
}
}
if
(
tid2
!=
RT_NULL
)
if
(
tid2
!=
RT_NULL
)
{
{
rt_kprintf
(
"tid2 is bad
\n
"
);
rt_kprintf
(
"tid2 is %p, should be NULL
\n
"
,
tid2
);
tc_stat
(
TC_STAT_FAILED
);
tc_stat
(
TC_STAT_FAILED
);
}
}
...
@@ -129,9 +129,7 @@ int _tc_thread_delete()
...
@@ -129,9 +129,7 @@ int _tc_thread_delete()
{
{
/* set tc cleanup */
/* set tc cleanup */
tc_cleanup
(
_tc_cleanup
);
tc_cleanup
(
_tc_cleanup
);
thread_delete_init
();
return
thread_delete_init
();
return
27
;
}
}
FINSH_FUNCTION_EXPORT
(
_tc_thread_delete
,
a
thread
delete
example
);
FINSH_FUNCTION_EXPORT
(
_tc_thread_delete
,
a
thread
delete
example
);
#else
#else
...
...
examples/kernel/thread_detach.c
浏览文件 @
a93251ae
examples/kernel/thread_dynamic.c
浏览文件 @
a93251ae
examples/kernel/thread_dynamic_simple.c
浏览文件 @
a93251ae
examples/kernel/thread_priority.c
浏览文件 @
a93251ae
examples/kernel/thread_resume.c
浏览文件 @
a93251ae
examples/kernel/thread_same_priority.c
浏览文件 @
a93251ae
examples/kernel/thread_static.c
浏览文件 @
a93251ae
examples/kernel/thread_static_simple.c
浏览文件 @
a93251ae
examples/kernel/thread_suspend.c
浏览文件 @
a93251ae
examples/kernel/thread_yield.c
浏览文件 @
a93251ae
examples/kernel/timer_control.c
浏览文件 @
a93251ae
examples/kernel/timer_dynamic.c
浏览文件 @
a93251ae
examples/kernel/timer_static.c
浏览文件 @
a93251ae
examples/kernel/timer_stop_self.c
浏览文件 @
a93251ae
examples/kernel/timer_timeout.c
浏览文件 @
a93251ae
include/rtthread.h
浏览文件 @
a93251ae
...
@@ -173,6 +173,7 @@ void rt_schedule_remove_thread(struct rt_thread *thread);
...
@@ -173,6 +173,7 @@ void rt_schedule_remove_thread(struct rt_thread *thread);
void
rt_enter_critical
(
void
);
void
rt_enter_critical
(
void
);
void
rt_exit_critical
(
void
);
void
rt_exit_critical
(
void
);
rt_uint16_t
rt_critical_level
(
void
);
#ifdef RT_USING_HOOK
#ifdef RT_USING_HOOK
void
rt_scheduler_sethook
(
void
(
*
hook
)(
rt_thread_t
from
,
rt_thread_t
to
));
void
rt_scheduler_sethook
(
void
(
*
hook
)(
rt_thread_t
from
,
rt_thread_t
to
));
...
...
src/idle.c
浏览文件 @
a93251ae
...
@@ -22,6 +22,8 @@
...
@@ -22,6 +22,8 @@
* 2006-03-23 Bernard the first version
* 2006-03-23 Bernard the first version
* 2010-11-10 Bernard add cleanup callback function in thread exit.
* 2010-11-10 Bernard add cleanup callback function in thread exit.
* 2012-12-29 Bernard fix compiling warning.
* 2012-12-29 Bernard fix compiling warning.
* 2013-12-21 Grissiom let rt_thread_idle_excute loop until there is no
* dead thread.
*/
*/
#include <rthw.h>
#include <rthw.h>
...
@@ -72,8 +74,9 @@ void rt_thread_idle_sethook(void (*hook)(void))
...
@@ -72,8 +74,9 @@ void rt_thread_idle_sethook(void (*hook)(void))
*/
*/
void
rt_thread_idle_excute
(
void
)
void
rt_thread_idle_excute
(
void
)
{
{
/* check the defunct thread list */
/* Loop until there is no dead thread. So one call to rt_thread_idle_excute
if
(
!
rt_list_isempty
(
&
rt_thread_defunct
))
* will do all the cleanups. */
while
(
!
rt_list_isempty
(
&
rt_thread_defunct
))
{
{
rt_base_t
lock
;
rt_base_t
lock
;
rt_thread_t
thread
;
rt_thread_t
thread
;
...
...
src/scheduler.c
浏览文件 @
a93251ae
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
* issue found by kuronca
* issue found by kuronca
* 2010-12-13 Bernard add defunct list initialization even if not use heap.
* 2010-12-13 Bernard add defunct list initialization even if not use heap.
* 2011-05-10 Bernard clean scheduler debug log.
* 2011-05-10 Bernard clean scheduler debug log.
* 2013-12-21 Grissiom add rt_critical_level
*/
*/
#include <rtthread.h>
#include <rtthread.h>
...
@@ -398,5 +399,14 @@ void rt_exit_critical(void)
...
@@ -398,5 +399,14 @@ void rt_exit_critical(void)
}
}
}
}
/**
* Get the scheduler lock level
*
* @return the level of the scheduler lock. 0 means unlocked.
*/
rt_uint16_t
rt_critical_level
(
void
)
{
return
rt_scheduler_lock_nest
;
}
/*@}*/
/*@}*/
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录