Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2345VOR
rt-thread
提交
08af426f
R
rt-thread
项目概览
2345VOR
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
08af426f
编写于
3月 07, 2021
作者:
mysterywolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[example] 格式化整理
上级
ce860582
变更
30
展开全部
隐藏空白更改
内联
并排
Showing
30 changed file
with
1132 addition
and
1132 deletion
+1132
-1132
examples/file/listdir.c
examples/file/listdir.c
+1
-1
examples/file/readspeed.c
examples/file/readspeed.c
+3
-3
examples/file/readwrite.c
examples/file/readwrite.c
+104
-104
examples/file/seekdir.c
examples/file/seekdir.c
+26
-26
examples/file/writespeed.c
examples/file/writespeed.c
+1
-1
examples/kernel/tc_comm.h
examples/kernel/tc_comm.h
+1
-1
examples/kernel/timer_control.c
examples/kernel/timer_control.c
+1
-1
examples/kernel/timer_timeout.c
examples/kernel/timer_timeout.c
+34
-34
examples/libc/dirent.c
examples/libc/dirent.c
+41
-41
examples/libc/env.c
examples/libc/env.c
+4
-4
examples/libc/ex1.c
examples/libc/ex1.c
+17
-17
examples/libc/ex6.c
examples/libc/ex6.c
+19
-19
examples/libc/ex7.c
examples/libc/ex7.c
+73
-73
examples/libc/file.c
examples/libc/file.c
+484
-484
examples/libc/memory.c
examples/libc/memory.c
+27
-27
examples/libc/mq.c
examples/libc/mq.c
+81
-81
examples/libc/printf.c
examples/libc/printf.c
+29
-29
examples/libc/rand.c
examples/libc/rand.c
+28
-28
examples/libc/sem.c
examples/libc/sem.c
+41
-41
examples/libc/time.c
examples/libc/time.c
+7
-7
examples/network/tcpsendpacket.c
examples/network/tcpsendpacket.c
+2
-2
examples/pm/timer_app.c
examples/pm/timer_app.c
+1
-1
examples/pm/wakeup_app.c
examples/pm/wakeup_app.c
+1
-1
examples/test/dhry.h
examples/test/dhry.h
+23
-23
examples/test/dhry_1.c
examples/test/dhry_1.c
+21
-21
examples/test/dhry_2.c
examples/test/dhry_2.c
+6
-6
examples/test/hwtimer_test.c
examples/test/hwtimer_test.c
+11
-11
examples/test/net_test.c
examples/test/net_test.c
+25
-25
examples/test/rtc_test.c
examples/test/rtc_test.c
+19
-19
examples/ulog/ulog_example.c
examples/ulog/ulog_example.c
+1
-1
未找到文件。
examples/file/listdir.c
浏览文件 @
08af426f
/*
/*
* Copyright (c) 2006-202
0
, RT-Thread Development Team
* Copyright (c) 2006-202
1
, RT-Thread Development Team
*
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-License-Identifier: Apache-2.0
*
*
...
...
examples/file/readspeed.c
浏览文件 @
08af426f
/*
/*
* Copyright (c) 2006-202
0
, RT-Thread Development Team
* Copyright (c) 2006-202
1
, RT-Thread Development Team
*
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-License-Identifier: Apache-2.0
*
*
...
@@ -46,9 +46,9 @@ void readspeed(const char* filename, int block_size)
...
@@ -46,9 +46,9 @@ void readspeed(const char* filename, int block_size)
}
}
tick
=
rt_tick_get
()
-
tick
;
tick
=
rt_tick_get
()
-
tick
;
/* close file and release memory */
/* close file and release memory */
close
(
fd
);
close
(
fd
);
rt_free
(
buff_ptr
);
rt_free
(
buff_ptr
);
/* calculate read speed */
/* calculate read speed */
rt_kprintf
(
"File read speed: %d byte/s
\n
"
,
total_length
/
tick
*
RT_TICK_PER_SECOND
);
rt_kprintf
(
"File read speed: %d byte/s
\n
"
,
total_length
/
tick
*
RT_TICK_PER_SECOND
);
...
...
examples/file/readwrite.c
浏览文件 @
08af426f
/*
/*
* Copyright (c) 2006-202
0
, RT-Thread Development Team
* Copyright (c) 2006-202
1
, RT-Thread Development Team
*
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-License-Identifier: Apache-2.0
*
*
...
@@ -17,21 +17,21 @@
...
@@ -17,21 +17,21 @@
/* file read write test */
/* file read write test */
void
readwrite
(
const
char
*
filename
)
void
readwrite
(
const
char
*
filename
)
{
{
int
fd
;
int
fd
;
int
index
,
length
;
int
index
,
length
;
char
*
test_data
;
char
*
test_data
;
char
*
buffer
;
char
*
buffer
;
int
block_size
=
TEST_DATA_LEN
;
int
block_size
=
TEST_DATA_LEN
;
/* open with write only & create */
/* open with write only & create */
fd
=
open
(
filename
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0
);
fd
=
open
(
filename
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0
);
if
(
fd
<
0
)
if
(
fd
<
0
)
{
{
rt_kprintf
(
"open file for write failed
\n
"
);
rt_kprintf
(
"open file for write failed
\n
"
);
return
;
return
;
}
}
test_data
=
rt_malloc
(
block_size
);
test_data
=
rt_malloc
(
block_size
);
if
(
test_data
==
RT_NULL
)
if
(
test_data
==
RT_NULL
)
{
{
rt_kprintf
(
"no memory
\n
"
);
rt_kprintf
(
"no memory
\n
"
);
...
@@ -48,94 +48,94 @@ void readwrite(const char* filename)
...
@@ -48,94 +48,94 @@ void readwrite(const char* filename)
return
;
return
;
}
}
/* prepare some data */
/* prepare some data */
for
(
index
=
0
;
index
<
block_size
;
index
++
)
for
(
index
=
0
;
index
<
block_size
;
index
++
)
{
{
test_data
[
index
]
=
index
+
27
;
test_data
[
index
]
=
index
+
27
;
}
}
/* write to file */
/* write to file */
length
=
write
(
fd
,
test_data
,
block_size
);
length
=
write
(
fd
,
test_data
,
block_size
);
if
(
length
!=
block_size
)
if
(
length
!=
block_size
)
{
{
rt_kprintf
(
"write data failed
\n
"
);
rt_kprintf
(
"write data failed
\n
"
);
close
(
fd
);
close
(
fd
);
goto
__exit
;
goto
__exit
;
}
}
/* close file */
/* close file */
close
(
fd
);
close
(
fd
);
/* reopen the file with append to the end */
/* reopen the file with append to the end */
fd
=
open
(
filename
,
O_WRONLY
|
O_CREAT
|
O_APPEND
,
0
);
fd
=
open
(
filename
,
O_WRONLY
|
O_CREAT
|
O_APPEND
,
0
);
if
(
fd
<
0
)
if
(
fd
<
0
)
{
{
rt_kprintf
(
"open file for append write failed
\n
"
);
rt_kprintf
(
"open file for append write failed
\n
"
);
goto
__exit
;;
goto
__exit
;;
}
}
length
=
write
(
fd
,
test_data
,
block_size
);
length
=
write
(
fd
,
test_data
,
block_size
);
if
(
length
!=
block_size
)
if
(
length
!=
block_size
)
{
{
rt_kprintf
(
"append write data failed
\n
"
);
rt_kprintf
(
"append write data failed
\n
"
);
close
(
fd
);
close
(
fd
);
goto
__exit
;
goto
__exit
;
}
}
/* close the file */
/* close the file */
close
(
fd
);
close
(
fd
);
/* open the file for data validation. */
/* open the file for data validation. */
fd
=
open
(
filename
,
O_RDONLY
,
0
);
fd
=
open
(
filename
,
O_RDONLY
,
0
);
if
(
fd
<
0
)
if
(
fd
<
0
)
{
{
rt_kprintf
(
"check: open file for read failed
\n
"
);
rt_kprintf
(
"check: open file for read failed
\n
"
);
goto
__exit
;
goto
__exit
;
}
}
/* read the data (should be the data written by the first time ) */
/* read the data (should be the data written by the first time ) */
length
=
read
(
fd
,
buffer
,
block_size
);
length
=
read
(
fd
,
buffer
,
block_size
);
if
(
length
!=
block_size
)
if
(
length
!=
block_size
)
{
{
rt_kprintf
(
"check: read file failed
\n
"
);
rt_kprintf
(
"check: read file failed
\n
"
);
close
(
fd
);
close
(
fd
);
goto
__exit
;
goto
__exit
;
}
}
/* validate */
/* validate */
for
(
index
=
0
;
index
<
block_size
;
index
++
)
for
(
index
=
0
;
index
<
block_size
;
index
++
)
{
{
if
(
test_data
[
index
]
!=
buffer
[
index
])
if
(
test_data
[
index
]
!=
buffer
[
index
])
{
{
rt_kprintf
(
"check: check data failed at %d
\n
"
,
index
);
rt_kprintf
(
"check: check data failed at %d
\n
"
,
index
);
close
(
fd
);
close
(
fd
);
goto
__exit
;
goto
__exit
;
}
}
}
}
/* read the data (should be the second time data) */
/* read the data (should be the second time data) */
length
=
read
(
fd
,
buffer
,
block_size
);
length
=
read
(
fd
,
buffer
,
block_size
);
if
(
length
!=
block_size
)
if
(
length
!=
block_size
)
{
{
rt_kprintf
(
"check: read file failed
\n
"
);
rt_kprintf
(
"check: read file failed
\n
"
);
close
(
fd
);
close
(
fd
);
goto
__exit
;
goto
__exit
;
}
}
/* validate */
/* validate */
for
(
index
=
0
;
index
<
block_size
;
index
++
)
for
(
index
=
0
;
index
<
block_size
;
index
++
)
{
{
if
(
test_data
[
index
]
!=
buffer
[
index
])
if
(
test_data
[
index
]
!=
buffer
[
index
])
{
{
rt_kprintf
(
"check: check data failed at %d
\n
"
,
index
);
rt_kprintf
(
"check: check data failed at %d
\n
"
,
index
);
close
(
fd
);
close
(
fd
);
goto
__exit
;
goto
__exit
;
}
}
}
}
/* close the file */
/* close the file */
close
(
fd
);
close
(
fd
);
/* print result */
/* print result */
rt_kprintf
(
"read/write test successful!
\n
"
);
rt_kprintf
(
"read/write test successful!
\n
"
);
__exit:
__exit:
rt_free
(
test_data
);
rt_free
(
test_data
);
...
...
examples/file/seekdir.c
浏览文件 @
08af426f
/*
/*
* Copyright (c) 2006-202
0
, RT-Thread Development Team
* Copyright (c) 2006-202
1
, RT-Thread Development Team
*
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-License-Identifier: Apache-2.0
*
*
...
@@ -12,35 +12,35 @@
...
@@ -12,35 +12,35 @@
void
seekdir_test
(
void
)
void
seekdir_test
(
void
)
{
{
DIR
*
dirp
;
DIR
*
dirp
;
long
save3
=
0
;
long
save3
=
0
;
int
i
=
0
;
int
i
=
0
;
struct
dirent
*
dp
;
struct
dirent
*
dp
;
dirp
=
opendir
(
"/"
);
dirp
=
opendir
(
"/"
);
save3
=
telldir
(
dirp
);
save3
=
telldir
(
dirp
);
for
(
dp
=
readdir
(
dirp
);
dp
!=
RT_NULL
;
dp
=
readdir
(
dirp
))
for
(
dp
=
readdir
(
dirp
);
dp
!=
RT_NULL
;
dp
=
readdir
(
dirp
))
{
{
rt_kprintf
(
"direntry: %s
\n
"
,
dp
->
d_name
);
rt_kprintf
(
"direntry: %s
\n
"
,
dp
->
d_name
);
/* save the pointer of the third directory */
/* save the pointer of the third directory */
if
(
i
++
==
3
)
if
(
i
++
==
3
)
{
{
save3
=
telldir
(
dirp
);
save3
=
telldir
(
dirp
);
}
}
}
}
/* get back to the third directory */
/* get back to the third directory */
seekdir
(
dirp
,
save3
);
seekdir
(
dirp
,
save3
);
rt_kprintf
(
"seek dientry to: %d
\n
"
,
save3
);
rt_kprintf
(
"seek dientry to: %d
\n
"
,
save3
);
for
(
dp
=
readdir
(
dirp
);
dp
!=
RT_NULL
;
dp
=
readdir
(
dirp
))
for
(
dp
=
readdir
(
dirp
);
dp
!=
RT_NULL
;
dp
=
readdir
(
dirp
))
{
{
rt_kprintf
(
"direntry: %s
\n
"
,
dp
->
d_name
);
rt_kprintf
(
"direntry: %s
\n
"
,
dp
->
d_name
);
}
}
/* close the directory */
/* close the directory */
closedir
(
dirp
);
closedir
(
dirp
);
}
}
#ifdef RT_USING_FINSH
#ifdef RT_USING_FINSH
#include <finsh.h>
#include <finsh.h>
...
...
examples/file/writespeed.c
浏览文件 @
08af426f
/*
/*
* Copyright (c) 2006-202
0
, RT-Thread Development Team
* Copyright (c) 2006-202
1
, RT-Thread Development Team
*
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-License-Identifier: Apache-2.0
*
*
...
...
examples/kernel/tc_comm.h
浏览文件 @
08af426f
#ifndef __TC_COMM_H__
#ifndef __TC_COMM_H__
#define __TC_COMM_H__
#define __TC_COMM_H__
/*
/*
* RT-Thread TestCase
* RT-Thread TestCase
*
*
*/
*/
...
...
examples/kernel/timer_control.c
浏览文件 @
08af426f
...
@@ -14,7 +14,7 @@ static rt_uint8_t count;
...
@@ -14,7 +14,7 @@ static rt_uint8_t count;
static
void
timeout1
(
void
*
parameter
)
static
void
timeout1
(
void
*
parameter
)
{
{
rt_tick_t
timeout
=
50
;
rt_tick_t
timeout
=
50
;
rt_kprintf
(
"periodic timer is timeout
\n
"
);
rt_kprintf
(
"periodic timer is timeout
\n
"
);
count
++
;
count
++
;
...
...
examples/kernel/timer_timeout.c
浏览文件 @
08af426f
/*
/*
*
程序清单:消息队列例程
*
程序清单:消息队列例程
*
*
*
这个程序会创建3个动态线程,一个线程会从消息队列中收取消息;一个线程会定时给消
*
这个程序会创建3个动态线程,一个线程会从消息队列中收取消息;一个线程会定时给消
*
息队列发送消息;一个线程会定时给消息队列发送紧急消息。
*
息队列发送消息;一个线程会定时给消息队列发送紧急消息。
*/
*/
#include <rtthread.h>
#include <rtthread.h>
#include "tc_comm.h"
#include "tc_comm.h"
/*
指向线程控制块的指针
*/
/*
指向线程控制块的指针 */
static
rt_thread_t
tid
=
RT_NULL
;
static
rt_thread_t
tid
=
RT_NULL
;
/*
消息队列控制块
*/
/*
消息队列控制块 */
static
struct
rt_messagequeue
mq
;
static
struct
rt_messagequeue
mq
;
/*
消息队列中用到的放置消息的内存池
*/
/*
消息队列中用到的放置消息的内存池 */
static
char
msg_pool
[
2048
];
static
char
msg_pool
[
2048
];
/*
定时器的控制块
*/
/*
定时器的控制块 */
static
struct
rt_timer
timer
;
static
struct
rt_timer
timer
;
static
rt_uint16_t
no
=
0
;
static
rt_uint16_t
no
=
0
;
static
void
timer_timeout
(
void
*
parameter
)
static
void
timer_timeout
(
void
*
parameter
)
...
@@ -27,24 +27,24 @@ static void timer_timeout(void* parameter)
...
@@ -27,24 +27,24 @@ static void timer_timeout(void* parameter)
rt_mq_send
(
&
mq
,
&
buf
[
0
],
length
);
rt_mq_send
(
&
mq
,
&
buf
[
0
],
length
);
}
}
/*
线程入口函数
*/
/*
线程入口函数 */
static
void
thread_entry
(
void
*
parameter
)
static
void
thread_entry
(
void
*
parameter
)
{
{
char
buf
[
64
];
char
buf
[
64
];
rt_err_t
result
;
rt_err_t
result
;
/*
初始化定时器
*/
/*
初始化定时器 */
rt_timer_init
(
&
timer
,
"timer"
,
/*
定时器名字是
timer1 */
rt_timer_init
(
&
timer
,
"timer"
,
/*
定时器名字是 ti
mer1 */
timer_timeout
,
/*
超时时回调的处理函数
*/
timer_timeout
,
/*
超时时回调的处理函数 */
RT_NULL
,
/*
超时函数的入口参数
*/
RT_NULL
,
/*
超时函数的入口参数 */
1
,
/*
定时长度,以OS Tick为单位,即1个
OS Tick */
1
,
/*
定时长度,以OS Tick为单位,即1个OS T
ick */
RT_TIMER_FLAG_PERIODIC
);
/*
周期性定时器
*/
RT_TIMER_FLAG_PERIODIC
);
/*
周期性定时器 */
while
(
1
)
while
(
1
)
{
{
rt_memset
(
&
buf
[
0
],
0
,
sizeof
(
buf
));
rt_memset
(
&
buf
[
0
],
0
,
sizeof
(
buf
));
/*
从消息队列中接收消息
*/
/*
从消息队列中接收消息 */
result
=
rt_mq_recv
(
&
mq
,
&
buf
[
0
],
sizeof
(
buf
),
1
);
result
=
rt_mq_recv
(
&
mq
,
&
buf
[
0
],
sizeof
(
buf
),
1
);
if
(
result
==
RT_EOK
)
if
(
result
==
RT_EOK
)
{
{
...
@@ -59,16 +59,16 @@ static void thread_entry(void* parameter)
...
@@ -59,16 +59,16 @@ static void thread_entry(void* parameter)
int
timer_timeout_init
()
int
timer_timeout_init
()
{
{
/*
初始化消息队列
*/
/*
初始化消息队列 */
rt_mq_init
(
&
mq
,
"mqt"
,
rt_mq_init
(
&
mq
,
"mqt"
,
&
msg_pool
[
0
],
/*
内存池指向msg_pool */
&
msg_pool
[
0
],
/*
内存池指向msg_pool */
128
-
sizeof
(
void
*
),
/*
每个消息的大小是
128 - void* */
128
-
sizeof
(
void
*
),
/*
每个消息的大小是 128
- void* */
sizeof
(
msg_pool
),
/*
内存池的大小是msg_pool的大小
*/
sizeof
(
msg_pool
),
/*
内存池的大小是msg_pool的大小 */
RT_IPC_FLAG_FIFO
);
/*
如果有多个线程等待,按照先来先得到的方法分配消息
*/
RT_IPC_FLAG_FIFO
);
/*
如果有多个线程等待,按照先来先得到的方法分配消息 */
/*
创建线程
*/
/*
创建线程 *
/
tid
=
rt_thread_create
(
"t"
,
tid
=
rt_thread_create
(
"t"
,
thread_entry
,
RT_NULL
,
/*
线程入口是thread_entry, 入口参数是R
T_NULL */
thread_entry
,
RT_NULL
,
/*
线程入口是thread_entry, 入口参数是RT_NU
LL */
THREAD_STACK_SIZE
,
THREAD_PRIORITY
,
THREAD_TIMESLICE
);
THREAD_STACK_SIZE
,
THREAD_PRIORITY
,
THREAD_TIMESLICE
);
if
(
tid
!=
RT_NULL
)
if
(
tid
!=
RT_NULL
)
rt_thread_startup
(
tid
);
rt_thread_startup
(
tid
);
...
@@ -81,38 +81,38 @@ int timer_timeout_init()
...
@@ -81,38 +81,38 @@ int timer_timeout_init()
#ifdef RT_USING_TC
#ifdef RT_USING_TC
static
void
_tc_cleanup
()
static
void
_tc_cleanup
()
{
{
/*
调度器上锁,上锁后,将不再切换到其他线程,仅响应中断
*/
/*
调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
rt_enter_critical
();
rt_enter_critical
();
/*
删除线程
*/
/*
删除线程 *
/
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_mq_detach
(
&
mq
);
rt_mq_detach
(
&
mq
);
/*
执行定时器脱离
*/
/*
执行定时器脱离 */
rt_timer_detach
(
&
timer
);
rt_timer_detach
(
&
timer
);
/*
调度器解锁
*/
/*
调度器解锁 *
/
rt_exit_critical
();
rt_exit_critical
();
/*
设置TestCase状态
*/
/*
设置TestCase状态
*/
tc_done
(
TC_STAT_PASSED
);
tc_done
(
TC_STAT_PASSED
);
}
}
int
_tc_timer_timeout
()
int
_tc_timer_timeout
()
{
{
/*
设置TestCase清理回调函数
*/
/*
设置TestCase清理回调函数 */
tc_cleanup
(
_tc_cleanup
);
tc_cleanup
(
_tc_cleanup
);
timer_timeout_init
();
timer_timeout_init
();
/*
返回TestCase运行的最长时间
*/
/*
返回TestCase运行的最长时间 */
return
100
;
return
100
;
}
}
/*
输出函数命令到finsh shell中
*/
/*
输出函数命令到finsh shell中 */
FINSH_FUNCTION_EXPORT
(
_tc_timer_timeout
,
a
thread
timer
testcase
);
FINSH_FUNCTION_EXPORT
(
_tc_timer_timeout
,
a
thread
timer
testcase
);
#else
#else
/*
用户应用入口
*/
/*
用户应用入口 */
int
rt_application_init
()
int
rt_application_init
()
{
{
timer_timeout_init
();
timer_timeout_init
();
...
...
examples/libc/dirent.c
浏览文件 @
08af426f
...
@@ -11,46 +11,46 @@
...
@@ -11,46 +11,46 @@
#include <dirent.h>
#include <dirent.h>
int
libc_dirent
()
int
libc_dirent
()
{
{
DIR
*
dirp
;
DIR
*
dirp
;
long
int
save3
=
0
;
long
int
save3
=
0
;
long
int
cur
;
long
int
cur
;
int
i
=
0
;
int
i
=
0
;
int
result
=
0
;
int
result
=
0
;
struct
dirent
*
dp
;
struct
dirent
*
dp
;
dirp
=
opendir
(
"/"
);
dirp
=
opendir
(
"/"
);
for
(
dp
=
readdir
(
dirp
);
dp
!=
NULL
;
dp
=
readdir
(
dirp
))
for
(
dp
=
readdir
(
dirp
);
dp
!=
NULL
;
dp
=
readdir
(
dirp
))
{
{
/* save position 3 (after fourth entry) */
/* save position 3 (after fourth entry) */
if
(
i
++
==
3
)
if
(
i
++
==
3
)
save3
=
telldir
(
dirp
);
save3
=
telldir
(
dirp
);
printf
(
"%s
\n
"
,
dp
->
d_name
);
printf
(
"%s
\n
"
,
dp
->
d_name
);
/* stop at 400 (just to make sure dirp->__offset and dirp->__size are
/* stop at 400 (just to make sure dirp->__offset and dirp->__size are
scrambled */
scrambled */
if
(
i
==
400
)
if
(
i
==
400
)
break
;
break
;
}
}
printf
(
"going back past 4-th entry...
\n
"
);
printf
(
"going back past 4-th entry...
\n
"
);
/* go back to saved entry */
/* go back to saved entry */
seekdir
(
dirp
,
save3
);
seekdir
(
dirp
,
save3
);
/* Check whether telldir equals to save3 now. */
/* Check whether telldir equals to save3 now. */
cur
=
telldir
(
dirp
);
cur
=
telldir
(
dirp
);
if
(
cur
!=
save3
)
if
(
cur
!=
save3
)
{
{
printf
(
"seekdir (d, %ld); telldir (d) == %ld
\n
"
,
save3
,
cur
);
printf
(
"seekdir (d, %ld); telldir (d) == %ld
\n
"
,
save3
,
cur
);
result
=
1
;
result
=
1
;
}
}
/* print remaining files (3-last) */
/* print remaining files (3-last) */
for
(
dp
=
readdir
(
dirp
);
dp
!=
NULL
;
dp
=
readdir
(
dirp
))
for
(
dp
=
readdir
(
dirp
);
dp
!=
NULL
;
dp
=
readdir
(
dirp
))
printf
(
"%s
\n
"
,
dp
->
d_name
);
printf
(
"%s
\n
"
,
dp
->
d_name
);
closedir
(
dirp
);
closedir
(
dirp
);
return
result
;
return
result
;
}
}
FINSH_FUNCTION_EXPORT
(
libc_dirent
,
dirent
test
for
libc
);
FINSH_FUNCTION_EXPORT
(
libc_dirent
,
dirent
test
for
libc
);
examples/libc/env.c
浏览文件 @
08af426f
...
@@ -10,9 +10,9 @@
...
@@ -10,9 +10,9 @@
int
libc_env
()
int
libc_env
()
{
{
printf
(
"PATH=%s
\n
"
,
getenv
(
"PATH"
));
printf
(
"PATH=%s
\n
"
,
getenv
(
"PATH"
));
putenv
(
"foo=bar"
);
putenv
(
"foo=bar"
);
printf
(
"foo=%s
\n
"
,
getenv
(
"foo"
));
printf
(
"foo=%s
\n
"
,
getenv
(
"foo"
));
return
0
;
return
0
;
}
}
FINSH_FUNCTION_EXPORT
(
libc_env
,
get
/
set_env
test
);
FINSH_FUNCTION_EXPORT
(
libc_env
,
get
/
set_env
test
);
examples/libc/ex1.c
浏览文件 @
08af426f
...
@@ -9,29 +9,29 @@
...
@@ -9,29 +9,29 @@
static
void
*
process
(
void
*
arg
)
static
void
*
process
(
void
*
arg
)
{
{
int
i
;
int
i
;
printf
(
"Starting process %s
\n
"
,
(
char
*
)
arg
);
printf
(
"Starting process %s
\n
"
,
(
char
*
)
arg
);
for
(
i
=
0
;
i
<
10000
;
i
++
)
for
(
i
=
0
;
i
<
10000
;
i
++
)
write
(
1
,
(
char
*
)
arg
,
1
);
write
(
1
,
(
char
*
)
arg
,
1
);
return
NULL
;
return
NULL
;
}
}
#define sucfail(r) (r != 0 ? "failed" : "succeeded")
#define sucfail(r) (r != 0 ? "failed" : "succeeded")
int
libc_ex1
(
void
)
int
libc_ex1
(
void
)
{
{
int
pret
,
ret
=
0
;
int
pret
,
ret
=
0
;
pthread_t
th_a
,
th_b
;
pthread_t
th_a
,
th_b
;
void
*
retval
;
void
*
retval
;
ret
+=
(
pret
=
pthread_create
(
&
th_a
,
NULL
,
process
,
(
void
*
)
"a"
));
ret
+=
(
pret
=
pthread_create
(
&
th_a
,
NULL
,
process
,
(
void
*
)
"a"
));
printf
(
"create a %s %d
\n
"
,
sucfail
(
pret
),
pret
);
printf
(
"create a %s %d
\n
"
,
sucfail
(
pret
),
pret
);
ret
+=
(
pret
=
pthread_create
(
&
th_b
,
NULL
,
process
,
(
void
*
)
"b"
));
ret
+=
(
pret
=
pthread_create
(
&
th_b
,
NULL
,
process
,
(
void
*
)
"b"
));
printf
(
"create b %s %d
\n
"
,
sucfail
(
pret
),
pret
);
printf
(
"create b %s %d
\n
"
,
sucfail
(
pret
),
pret
);
ret
+=
(
pret
=
pthread_join
(
th_a
,
&
retval
));
ret
+=
(
pret
=
pthread_join
(
th_a
,
&
retval
));
printf
(
"join a %s %d
\n
"
,
sucfail
(
pret
),
pret
);
printf
(
"join a %s %d
\n
"
,
sucfail
(
pret
),
pret
);
ret
+=
(
pret
=
pthread_join
(
th_b
,
&
retval
));
ret
+=
(
pret
=
pthread_join
(
th_b
,
&
retval
));
printf
(
"join b %s %d
\n
"
,
sucfail
(
pret
),
pret
);
printf
(
"join b %s %d
\n
"
,
sucfail
(
pret
),
pret
);
return
ret
;
return
ret
;
}
}
#include <finsh.h>
#include <finsh.h>
FINSH_FUNCTION_EXPORT
(
libc_ex1
,
example
1
for
libc
);
FINSH_FUNCTION_EXPORT
(
libc_ex1
,
example
1
for
libc
);
examples/libc/ex6.c
浏览文件 @
08af426f
...
@@ -7,31 +7,31 @@
...
@@ -7,31 +7,31 @@
#define usleep rt_thread_sleep
#define usleep rt_thread_sleep
static
void
*
test_thread
(
void
*
v_param
)
{
static
void
*
test_thread
(
void
*
v_param
)
{
return
NULL
;
return
NULL
;
}
}
int
libc_ex6
(
void
)
{
int
libc_ex6
(
void
)
{
unsigned
long
count
;
unsigned
long
count
;
setvbuf
(
stdout
,
NULL
,
_IONBF
,
0
);
setvbuf
(
stdout
,
NULL
,
_IONBF
,
0
);
for
(
count
=
0
;
count
<
2000
;
++
count
)
{
for
(
count
=
0
;
count
<
2000
;
++
count
)
{
pthread_t
thread
;
pthread_t
thread
;
int
status
;
int
status
;
status
=
pthread_create
(
&
thread
,
NULL
,
test_thread
,
NULL
);
status
=
pthread_create
(
&
thread
,
NULL
,
test_thread
,
NULL
);
if
(
status
!=
0
)
{
if
(
status
!=
0
)
{
printf
(
"status = %d, count = %lu: %s
\n
"
,
status
,
count
,
strerror
(
printf
(
"status = %d, count = %lu: %s
\n
"
,
status
,
count
,
strerror
(
errno
));
errno
));
return
1
;
return
1
;
}
else
{
}
else
{
printf
(
"count = %lu
\n
"
,
count
);
printf
(
"count = %lu
\n
"
,
count
);
}
}
/* pthread_detach (thread); */
/* pthread_detach (thread); */
pthread_join
(
thread
,
NULL
);
pthread_join
(
thread
,
NULL
);
usleep
(
10
);
usleep
(
10
);
}
}
return
0
;
return
0
;
}
}
#include <finsh.h>
#include <finsh.h>
FINSH_FUNCTION_EXPORT
(
libc_ex6
,
example
6
for
libc
);
FINSH_FUNCTION_EXPORT
(
libc_ex6
,
example
6
for
libc
);
examples/libc/ex7.c
浏览文件 @
08af426f
...
@@ -14,88 +14,88 @@
...
@@ -14,88 +14,88 @@
/* Our event variable using a condition variable contruct. */
/* Our event variable using a condition variable contruct. */
typedef
struct
{
typedef
struct
{
pthread_mutex_t
mutex
;
pthread_mutex_t
mutex
;
pthread_cond_t
cond
;
pthread_cond_t
cond
;
int
flag
;
int
flag
;
}
event_t
;
}
event_t
;
/* Global event to signal main thread the timeout of the child thread. */
/* Global event to signal main thread the timeout of the child thread. */
event_t
main_event
;
event_t
main_event
;
static
void
*
test_thread
(
void
*
ms_param
)
{
static
void
*
test_thread
(
void
*
ms_param
)
{
int
status
=
0
;
int
status
=
0
;
event_t
foo
;
event_t
foo
;
struct
timespec
time
;
struct
timespec
time
;
struct
timeval
now
;
struct
timeval
now
;
long
ms
=
(
long
)
ms_param
;
long
ms
=
(
long
)
ms_param
;
/* initialize cond var */
/* initialize cond var */
pthread_cond_init
(
&
foo
.
cond
,
NULL
);
pthread_cond_init
(
&
foo
.
cond
,
NULL
);
pthread_mutex_init
(
&
foo
.
mutex
,
NULL
);
pthread_mutex_init
(
&
foo
.
mutex
,
NULL
);
foo
.
flag
=
0
;
foo
.
flag
=
0
;
/* set the time out value */
/* set the time out value */
printf
(
"waiting %ld ms ...
\n
"
,
ms
);
printf
(
"waiting %ld ms ...
\n
"
,
ms
);
gettimeofday
(
&
now
,
NULL
);
gettimeofday
(
&
now
,
NULL
);
time
.
tv_sec
=
now
.
tv_sec
+
ms
/
1000
+
(
now
.
tv_usec
+
(
ms
%
1000
)
*
1000
)
time
.
tv_sec
=
now
.
tv_sec
+
ms
/
1000
+
(
now
.
tv_usec
+
(
ms
%
1000
)
*
1000
)
/
1000000
;
/
1000000
;
time
.
tv_nsec
=
((
now
.
tv_usec
+
(
ms
%
1000
)
*
1000
)
%
1000000
)
*
1000
;
time
.
tv_nsec
=
((
now
.
tv_usec
+
(
ms
%
1000
)
*
1000
)
%
1000000
)
*
1000
;
/* Just use this to test the time out. The cond var is never signaled. */
/* Just use this to test the time out. The cond var is never signaled. */
pthread_mutex_lock
(
&
foo
.
mutex
);
pthread_mutex_lock
(
&
foo
.
mutex
);
while
(
foo
.
flag
==
0
&&
status
!=
ETIMEDOUT
)
{
while
(
foo
.
flag
==
0
&&
status
!=
ETIMEDOUT
)
{
status
=
pthread_cond_timedwait
(
&
foo
.
cond
,
&
foo
.
mutex
,
&
time
);
status
=
pthread_cond_timedwait
(
&
foo
.
cond
,
&
foo
.
mutex
,
&
time
);
}
}
pthread_mutex_unlock
(
&
foo
.
mutex
);
pthread_mutex_unlock
(
&
foo
.
mutex
);
/* post the main event */
/* post the main event */
pthread_mutex_lock
(
&
main_event
.
mutex
);
pthread_mutex_lock
(
&
main_event
.
mutex
);
main_event
.
flag
=
1
;
main_event
.
flag
=
1
;
pthread_cond_signal
(
&
main_event
.
cond
);
pthread_cond_signal
(
&
main_event
.
cond
);
pthread_mutex_unlock
(
&
main_event
.
mutex
);
pthread_mutex_unlock
(
&
main_event
.
mutex
);
/* that's it, bye */
/* that's it, bye */
return
(
void
*
)
status
;
return
(
void
*
)
status
;
}
}
int
libc_ex7
(
void
)
{
int
libc_ex7
(
void
)
{
unsigned
long
count
;
unsigned
long
count
;
setvbuf
(
stdout
,
NULL
,
_IONBF
,
0
);
setvbuf
(
stdout
,
NULL
,
_IONBF
,
0
);
/* initialize main event cond var */
/* initialize main event cond var */
pthread_cond_init
(
&
main_event
.
cond
,
NULL
);
pthread_cond_init
(
&
main_event
.
cond
,
NULL
);
pthread_mutex_init
(
&
main_event
.
mutex
,
NULL
);
pthread_mutex_init
(
&
main_event
.
mutex
,
NULL
);
main_event
.
flag
=
0
;
main_event
.
flag
=
0
;
for
(
count
=
0
;
count
<
20
;
++
count
)
{
for
(
count
=
0
;
count
<
20
;
++
count
)
{
pthread_t
thread
;
pthread_t
thread
;
int
status
;
int
status
;
/* pass down the milli-second timeout in the void* param */
/* pass down the milli-second timeout in the void* param */
status
=
pthread_create
(
&
thread
,
NULL
,
test_thread
,
(
void
*
)
(
count
status
=
pthread_create
(
&
thread
,
NULL
,
test_thread
,
(
void
*
)
(
count
*
100
));
*
100
));
if
(
status
!=
0
)
{
if
(
status
!=
0
)
{
printf
(
"status = %d, count = %lu: %s
\n
"
,
status
,
count
,
strerror
(
printf
(
"status = %d, count = %lu: %s
\n
"
,
status
,
count
,
strerror
(
errno
));
errno
));
return
1
;
return
1
;
}
else
{
}
else
{
/* wait for the event posted by the child thread */
/* wait for the event posted by the child thread */
pthread_mutex_lock
(
&
main_event
.
mutex
);
pthread_mutex_lock
(
&
main_event
.
mutex
);
while
(
main_event
.
flag
==
0
)
{
while
(
main_event
.
flag
==
0
)
{
pthread_cond_wait
(
&
main_event
.
cond
,
&
main_event
.
mutex
);
pthread_cond_wait
(
&
main_event
.
cond
,
&
main_event
.
mutex
);
}
}
main_event
.
flag
=
0
;
main_event
.
flag
=
0
;
pthread_mutex_unlock
(
&
main_event
.
mutex
);
pthread_mutex_unlock
(
&
main_event
.
mutex
);
printf
(
"count = %lu
\n
"
,
count
);
printf
(
"count = %lu
\n
"
,
count
);
}
}
usleep
(
10
);
usleep
(
10
);
}
}
return
0
;
return
0
;
}
}
#include <finsh.h>
#include <finsh.h>
FINSH_FUNCTION_EXPORT
(
libc_ex7
,
example
7
for
libc
);
FINSH_FUNCTION_EXPORT
(
libc_ex7
,
example
7
for
libc
);
examples/libc/file.c
浏览文件 @
08af426f
此差异已折叠。
点击以展开。
examples/libc/memory.c
浏览文件 @
08af426f
...
@@ -12,45 +12,45 @@
...
@@ -12,45 +12,45 @@
static
int
errors
=
0
;
static
int
errors
=
0
;
static
void
merror
(
const
char
*
msg
)
static
void
merror
(
const
char
*
msg
)
{
{
++
errors
;
++
errors
;
printf
(
"Error: %s
\n
"
,
msg
);
printf
(
"Error: %s
\n
"
,
msg
);
}
}
int
libc_mem
(
void
)
int
libc_mem
(
void
)
{
{
void
*
p
;
void
*
p
;
int
save
;
int
save
;
errno
=
0
;
errno
=
0
;
p
=
malloc
(
-
1
);
p
=
malloc
(
-
1
);
save
=
errno
;
save
=
errno
;
if
(
p
!=
NULL
)
if
(
p
!=
NULL
)
merror
(
"malloc (-1) succeeded."
);
merror
(
"malloc (-1) succeeded."
);
if
(
p
==
NULL
&&
save
!=
ENOMEM
)
if
(
p
==
NULL
&&
save
!=
ENOMEM
)
merror
(
"errno is not set correctly"
);
merror
(
"errno is not set correctly"
);
p
=
malloc
(
10
);
p
=
malloc
(
10
);
if
(
p
==
NULL
)
if
(
p
==
NULL
)
merror
(
"malloc (10) failed."
);
merror
(
"malloc (10) failed."
);
/* realloc (p, 0) == free (p). */
/* realloc (p, 0) == free (p). */
p
=
realloc
(
p
,
0
);
p
=
realloc
(
p
,
0
);
if
(
p
!=
NULL
)
if
(
p
!=
NULL
)
merror
(
"realloc (p, 0) failed."
);
merror
(
"realloc (p, 0) failed."
);
p
=
malloc
(
0
);
p
=
malloc
(
0
);
if
(
p
==
NULL
)
if
(
p
==
NULL
)
{
{
printf
(
"malloc(0) returns NULL
\n
"
);
printf
(
"malloc(0) returns NULL
\n
"
);
}
}
p
=
realloc
(
p
,
0
);
p
=
realloc
(
p
,
0
);
if
(
p
!=
NULL
)
if
(
p
!=
NULL
)
merror
(
"realloc (p, 0) failed."
);
merror
(
"realloc (p, 0) failed."
);
return
errors
!=
0
;
return
errors
!=
0
;
}
}
FINSH_FUNCTION_EXPORT
(
libc_mem
,
memory
test
for
libc
);
FINSH_FUNCTION_EXPORT
(
libc_mem
,
memory
test
for
libc
);
examples/libc/mq.c
浏览文件 @
08af426f
...
@@ -7,113 +7,113 @@
...
@@ -7,113 +7,113 @@
#define MQ_NAME_1 "testmsg1"
#define MQ_NAME_1 "testmsg1"
#define MQ_NAME_2 "testmsg2"
#define MQ_NAME_2 "testmsg2"
#define MSG_SIZE
128
#define MSG_SIZE
128
#define MAX_MSG
3
#define MAX_MSG
3
const
char
*
s_msg_ptr
[]
=
{
"msg test 1"
,
"msg test 2"
,
"msg test 3"
};
const
char
*
s_msg_ptr
[]
=
{
"msg test 1"
,
"msg test 2"
,
"msg test 3"
};
char
r_msg_ptr_1
[
MAX_MSG
][
MSG_SIZE
];
char
r_msg_ptr_1
[
MAX_MSG
][
MSG_SIZE
];
char
r_msg_ptr_2
[
MAX_MSG
][
MSG_SIZE
];
char
r_msg_ptr_2
[
MAX_MSG
][
MSG_SIZE
];
pthread_t
send1
,
send2
,
rev1
,
rev2
;
pthread_t
send1
,
send2
,
rev1
,
rev2
;
int
*
send_1
(
void
*
mq
)
int
*
send_1
(
void
*
mq
)
{
{
int
i
;
int
i
;
mqd_t
mq1
=
*
(
mqd_t
*
)
mq
;
mqd_t
mq1
=
*
(
mqd_t
*
)
mq
;
printf
(
"Enter into send_1
\n
"
);
printf
(
"Enter into send_1
\n
"
);
for
(
i
=
0
;
i
<
MAX_MSG
;
i
++
)
{
for
(
i
=
0
;
i
<
MAX_MSG
;
i
++
)
{
if
(
-
1
==
mq_send
(
mq1
,
s_msg_ptr
[
i
],
MSG_SIZE
,
i
))
{
if
(
-
1
==
mq_send
(
mq1
,
s_msg_ptr
[
i
],
MSG_SIZE
,
i
))
{
perror
(
"mq_send doesn't return success
\n
"
);
perror
(
"mq_send doesn't return success
\n
"
);
pthread_exit
((
void
*
)
1
);
pthread_exit
((
void
*
)
1
);
}
}
printf
(
"[%d] send '%s' in thread send_1.
\n
"
,
i
+
1
,
s_msg_ptr
[
i
]);
printf
(
"[%d] send '%s' in thread send_1.
\n
"
,
i
+
1
,
s_msg_ptr
[
i
]);
}
}
pthread_exit
((
void
*
)
0
);
pthread_exit
((
void
*
)
0
);
}
}
int
*
send_2
(
void
*
mq
)
int
*
send_2
(
void
*
mq
)
{
{
int
i
;
int
i
;
mqd_t
mq2
=
*
(
mqd_t
*
)
mq
;
mqd_t
mq2
=
*
(
mqd_t
*
)
mq
;
printf
(
"Enter into send_2
\n
"
);
printf
(
"Enter into send_2
\n
"
);
for
(
i
=
0
;
i
<
MAX_MSG
;
i
++
)
{
for
(
i
=
0
;
i
<
MAX_MSG
;
i
++
)
{
if
(
-
1
==
mq_send
(
mq2
,
s_msg_ptr
[
i
],
MSG_SIZE
,
i
))
{
if
(
-
1
==
mq_send
(
mq2
,
s_msg_ptr
[
i
],
MSG_SIZE
,
i
))
{
perror
(
"mq_send doesn't return success
\n
"
);
perror
(
"mq_send doesn't return success
\n
"
);
pthread_exit
((
void
*
)
1
);
pthread_exit
((
void
*
)
1
);
}
}
printf
(
"[%d] send '%s' in thread send_2.
\n
"
,
i
+
1
,
s_msg_ptr
[
i
]);
printf
(
"[%d] send '%s' in thread send_2.
\n
"
,
i
+
1
,
s_msg_ptr
[
i
]);
}
}
pthread_exit
((
void
*
)
0
);
pthread_exit
((
void
*
)
0
);
}
}
int
*
receive_1
(
void
*
mq
)
int
*
receive_1
(
void
*
mq
)
{
{
int
i
;
int
i
;
mqd_t
mq1
=
*
(
mqd_t
*
)
mq
;
mqd_t
mq1
=
*
(
mqd_t
*
)
mq
;
printf
(
"Enter into receive_1
\n
"
);
printf
(
"Enter into receive_1
\n
"
);
for
(
i
=
0
;
i
<
MAX_MSG
;
i
++
)
{
for
(
i
=
0
;
i
<
MAX_MSG
;
i
++
)
{
if
(
-
1
==
mq_receive
(
mq1
,
r_msg_ptr_1
[
i
],
MSG_SIZE
,
NULL
)
)
{
if
(
-
1
==
mq_receive
(
mq1
,
r_msg_ptr_1
[
i
],
MSG_SIZE
,
NULL
)
)
{
perror
(
"mq_receive doesn't return success
\n
"
);
perror
(
"mq_receive doesn't return success
\n
"
);
pthread_exit
((
void
*
)
1
);
pthread_exit
((
void
*
)
1
);
}
}
printf
(
"[%d] receive '%s' in thread receive_1.
\n
"
,
i
+
1
,
r_msg_ptr_1
[
i
]);
printf
(
"[%d] receive '%s' in thread receive_1.
\n
"
,
i
+
1
,
r_msg_ptr_1
[
i
]);
}
}
pthread_exit
((
void
*
)
0
);
pthread_exit
((
void
*
)
0
);
}
}
int
*
receive_2
(
void
*
mq
)
int
*
receive_2
(
void
*
mq
)
{
{
int
i
;
int
i
;
mqd_t
mq2
=
*
(
mqd_t
*
)
mq
;
mqd_t
mq2
=
*
(
mqd_t
*
)
mq
;
printf
(
"Enter into receive_2
\n
"
);
printf
(
"Enter into receive_2
\n
"
);
for
(
i
=
0
;
i
<
MAX_MSG
;
i
++
)
{
for
(
i
=
0
;
i
<
MAX_MSG
;
i
++
)
{
if
(
-
1
==
mq_receive
(
mq2
,
r_msg_ptr_2
[
i
],
MSG_SIZE
,
NULL
)
)
{
if
(
-
1
==
mq_receive
(
mq2
,
r_msg_ptr_2
[
i
],
MSG_SIZE
,
NULL
)
)
{
perror
(
"mq_receive doesn't return success
\n
"
);
perror
(
"mq_receive doesn't return success
\n
"
);
pthread_exit
((
void
*
)
1
);
pthread_exit
((
void
*
)
1
);
}
}
printf
(
"[%d] receive '%s' in thread receive_2.
\n
"
,
i
+
1
,
r_msg_ptr_2
[
i
]);
printf
(
"[%d] receive '%s' in thread receive_2.
\n
"
,
i
+
1
,
r_msg_ptr_2
[
i
]);
}
}
pthread_exit
((
void
*
)
0
);
pthread_exit
((
void
*
)
0
);
}
}
int
libc_mq
()
int
libc_mq
()
{
{
mqd_t
mq1
=
0
,
mq2
=
0
;
mqd_t
mq1
=
0
,
mq2
=
0
;
struct
mq_attr
mqstat
;
struct
mq_attr
mqstat
;
int
oflag
=
O_CREAT
|
O_RDWR
;
int
oflag
=
O_CREAT
|
O_RDWR
;
memset
(
&
mqstat
,
0
,
sizeof
(
mqstat
));
memset
(
&
mqstat
,
0
,
sizeof
(
mqstat
));
mqstat
.
mq_maxmsg
=
MAX_MSG
;
mqstat
.
mq_maxmsg
=
MAX_MSG
;
mqstat
.
mq_msgsize
=
MSG_SIZE
;
mqstat
.
mq_msgsize
=
MSG_SIZE
;
mqstat
.
mq_flags
=
0
;
mqstat
.
mq_flags
=
0
;
if
(
((
mqd_t
)
-
1
)
==
(
mq1
=
mq_open
(
MQ_NAME_1
,
oflag
,
0777
,
&
mqstat
))
)
{
printf
(
"mq_open doesn't return success
\n
"
);
return
-
1
;
}
if
(
((
mqd_t
)
-
1
)
==
(
mq2
=
mq_open
(
MQ_NAME_2
,
oflag
,
0777
,
&
mqstat
))
)
{
printf
(
"mq_open doesn't return success
\n
"
);
return
-
1
;
}
pthread_create
(
&
send1
,
NULL
,
(
void
*
)
send_1
,
(
void
*
)
&
mq1
);
pthread_create
(
&
send2
,
NULL
,
(
void
*
)
send_2
,
(
void
*
)
&
mq2
);
pthread_create
(
&
rev1
,
NULL
,
(
void
*
)
receive_1
,
(
void
*
)
&
mq1
);
pthread_create
(
&
rev2
,
NULL
,
(
void
*
)
receive_2
,
(
void
*
)
&
mq2
);
pthread_join
(
send1
,
NULL
);
pthread_join
(
send2
,
NULL
);
pthread_join
(
rev1
,
NULL
);
pthread_join
(
rev2
,
NULL
);
mq_close
(
mq1
);
mq_close
(
mq2
);
mq_unlink
(
MQ_NAME_1
);
mq_unlink
(
MQ_NAME_2
);
printf
(
"PASSED
\n
"
);
if
(
((
mqd_t
)
-
1
)
==
(
mq1
=
mq_open
(
MQ_NAME_1
,
oflag
,
0777
,
&
mqstat
))
)
{
return
0
;
printf
(
"mq_open doesn't return success
\n
"
);
return
-
1
;
}
if
(
((
mqd_t
)
-
1
)
==
(
mq2
=
mq_open
(
MQ_NAME_2
,
oflag
,
0777
,
&
mqstat
))
)
{
printf
(
"mq_open doesn't return success
\n
"
);
return
-
1
;
}
pthread_create
(
&
send1
,
NULL
,
(
void
*
)
send_1
,
(
void
*
)
&
mq1
);
pthread_create
(
&
send2
,
NULL
,
(
void
*
)
send_2
,
(
void
*
)
&
mq2
);
pthread_create
(
&
rev1
,
NULL
,
(
void
*
)
receive_1
,
(
void
*
)
&
mq1
);
pthread_create
(
&
rev2
,
NULL
,
(
void
*
)
receive_2
,
(
void
*
)
&
mq2
);
pthread_join
(
send1
,
NULL
);
pthread_join
(
send2
,
NULL
);
pthread_join
(
rev1
,
NULL
);
pthread_join
(
rev2
,
NULL
);
mq_close
(
mq1
);
mq_close
(
mq2
);
mq_unlink
(
MQ_NAME_1
);
mq_unlink
(
MQ_NAME_2
);
printf
(
"PASSED
\n
"
);
return
0
;
}
}
#include <finsh.h>
#include <finsh.h>
FINSH_FUNCTION_EXPORT
(
libc_mq
,
posix
mqueue
test
);
FINSH_FUNCTION_EXPORT
(
libc_mq
,
posix
mqueue
test
);
examples/libc/printf.c
浏览文件 @
08af426f
...
@@ -142,59 +142,59 @@ int printf_test()
...
@@ -142,59 +142,59 @@ int printf_test()
int
i
;
int
i
;
printf
(
"snprintf (
\"
%%30s
\"
,
\"
foo
\"
) == %d,
\"
%.*s
\"\n
"
,
printf
(
"snprintf (
\"
%%30s
\"
,
\"
foo
\"
) == %d,
\"
%.*s
\"\n
"
,
snprintf
(
buf
,
sizeof
(
buf
),
"%30s"
,
"foo"
),
(
int
)
sizeof
(
buf
),
snprintf
(
buf
,
sizeof
(
buf
),
"%30s"
,
"foo"
),
(
int
)
sizeof
(
buf
),
buf
);
buf
);
memset
(
buf2
,
0
,
sizeof
(
buf
));
memset
(
buf2
,
0
,
sizeof
(
buf
));
i
=
snprintf
(
buf2
,
256
,
"%.9999u"
,
10
);
i
=
snprintf
(
buf2
,
256
,
"%.9999u"
,
10
);
printf
(
"%i %i
\n
"
,
i
,
strlen
(
buf2
));
printf
(
"%i %i
\n
"
,
i
,
strlen
(
buf2
));
printf
(
"snprintf (
\"
%%.999999u
\"
, 10) == %d
\n
"
,
printf
(
"snprintf (
\"
%%.999999u
\"
, 10) == %d
\n
"
,
snprintf
(
buf2
,
sizeof
(
buf2
),
"%.999999u"
,
10
));
snprintf
(
buf2
,
sizeof
(
buf2
),
"%.999999u"
,
10
));
}
}
return
0
;
return
0
;
}
}
void
libc_printf
()
void
libc_printf
()
{
{
printf
(
"stdout test!!
\n
"
);
printf
(
"stdout test!!
\n
"
);
fprintf
(
stdout
,
"fprintf test!!
\n
"
);
fprintf
(
stdout
,
"fprintf test!!
\n
"
);
fprintf
(
stderr
,
"fprintf test!!
\n
"
);
fprintf
(
stderr
,
"fprintf test!!
\n
"
);
puts
(
"puts test!!
\n
"
);
puts
(
"puts test!!
\n
"
);
putc
(
'1'
,
stderr
);
putc
(
'1'
,
stderr
);
putc
(
'2'
,
stderr
);
putc
(
'2'
,
stderr
);
putc
(
'\n'
,
stderr
);
putc
(
'\n'
,
stderr
);
printf_test
();
printf_test
();
}
}
FINSH_FUNCTION_EXPORT
(
libc_printf
,
printf
test
in
libc
);
FINSH_FUNCTION_EXPORT
(
libc_printf
,
printf
test
in
libc
);
void
libc_dprintf
()
void
libc_dprintf
()
{
{
int
fd
;
int
fd
;
fd
=
open
(
"/dev/console"
,
O_WRONLY
,
0
);
fd
=
open
(
"/dev/console"
,
O_WRONLY
,
0
);
if
(
fd
>
0
)
if
(
fd
>
0
)
{
{
dprintf
(
fd
,
"fd:%d printf test!!
\n
"
,
fd
);
dprintf
(
fd
,
"fd:%d printf test!!
\n
"
,
fd
);
close
(
fd
);
close
(
fd
);
}
}
}
}
FINSH_FUNCTION_EXPORT
(
libc_dprintf
,
dprintf
test
);
FINSH_FUNCTION_EXPORT
(
libc_dprintf
,
dprintf
test
);
void
libc_fdopen
()
void
libc_fdopen
()
{
{
int
fd
;
int
fd
;
FILE
*
fp
;
FILE
*
fp
;
fd
=
open
(
"/dev/console"
,
O_WRONLY
,
0
);
fd
=
open
(
"/dev/console"
,
O_WRONLY
,
0
);
if
(
fd
>
0
)
if
(
fd
>
0
)
{
{
fp
=
fdopen
(
fd
,
"w"
);
fp
=
fdopen
(
fd
,
"w"
);
fprintf
(
fp
,
"fdopen test, fd %d!!
\n
"
,
fileno
(
fp
));
fprintf
(
fp
,
"fdopen test, fd %d!!
\n
"
,
fileno
(
fp
));
fclose
(
fp
);
fclose
(
fp
);
}
}
}
}
FINSH_FUNCTION_EXPORT
(
libc_fdopen
,
fdopen
test
);
FINSH_FUNCTION_EXPORT
(
libc_fdopen
,
fdopen
test
);
examples/libc/rand.c
浏览文件 @
08af426f
...
@@ -10,34 +10,34 @@
...
@@ -10,34 +10,34 @@
int
libc_rand
(
void
)
int
libc_rand
(
void
)
{
{
int
i1
,
i2
;
int
i1
,
i2
;
int
j1
,
j2
;
int
j1
,
j2
;
/* The C standard says that "If rand is called before any calls to
/* The C standard says that "If rand is called before any calls to
srand have been made, the same sequence shall be generated as
srand have been made, the same sequence shall be generated as
when srand is first called with a seed value of 1." */
when srand is first called with a seed value of 1." */
i1
=
rand
();
i1
=
rand
();
i2
=
rand
();
i2
=
rand
();
srand
(
1
);
srand
(
1
);
j1
=
rand
();
j1
=
rand
();
j2
=
rand
();
j2
=
rand
();
if
(
i1
<
0
||
i2
<
0
||
j1
<
0
||
j2
<
0
)
if
(
i1
<
0
||
i2
<
0
||
j1
<
0
||
j2
<
0
)
{
{
puts
(
"Test FAILED!"
);
puts
(
"Test FAILED!"
);
}
}
if
(
j1
==
i1
&&
j2
==
i2
)
if
(
j1
==
i1
&&
j2
==
i2
)
{
{
puts
(
"Test succeeded."
);
puts
(
"Test succeeded."
);
return
0
;
return
0
;
}
}
else
else
{
{
if
(
j1
!=
i1
)
if
(
j1
!=
i1
)
printf
(
"%d != %d
\n
"
,
j1
,
i1
);
printf
(
"%d != %d
\n
"
,
j1
,
i1
);
if
(
j2
!=
i2
)
if
(
j2
!=
i2
)
printf
(
"%d != %d
\n
"
,
j2
,
i2
);
printf
(
"%d != %d
\n
"
,
j2
,
i2
);
puts
(
"Test FAILED!"
);
puts
(
"Test FAILED!"
);
return
1
;
return
1
;
}
}
}
}
FINSH_FUNCTION_EXPORT
(
libc_rand
,
rand
test
for
libc
);
FINSH_FUNCTION_EXPORT
(
libc_rand
,
rand
test
for
libc
);
examples/libc/sem.c
浏览文件 @
08af426f
...
@@ -5,61 +5,61 @@
...
@@ -5,61 +5,61 @@
static
sem_t
sema
;
static
sem_t
sema
;
static
void
*
other_thread
()
static
void
*
other_thread
()
{
{
printf
(
"other_thread here!
\n
"
);
printf
(
"other_thread here!
\n
"
);
sleep
(
1
);
sleep
(
1
);
while
(
1
)
while
(
1
)
{
{
printf
(
"other_thread: sem_post...
\n
"
);
printf
(
"other_thread: sem_post...
\n
"
);
if
(
sem_post
(
&
sema
)
==
-
1
)
if
(
sem_post
(
&
sema
)
==
-
1
)
printf
(
"sem_post failed
\n
"
);
printf
(
"sem_post failed
\n
"
);
sleep
(
1
);
sleep
(
1
);
}
}
printf
(
"other_thread dies!
\n
"
);
printf
(
"other_thread dies!
\n
"
);
pthread_exit
(
0
);
pthread_exit
(
0
);
}
}
static
void
test_thread
(
void
*
parameter
)
static
void
test_thread
(
void
*
parameter
)
{
{
pthread_t
tid
;
pthread_t
tid
;
printf
(
"main thread here!
\n
"
);
printf
(
"sleep 5 seconds..."
);
sleep
(
5
);
printf
(
"done
\n
"
);
printf
(
"main thread here!
\n
"
);
sem_init
(
&
sema
,
0
,
0
);
printf
(
"sleep 5 seconds..."
);
sleep
(
5
);
printf
(
"done
\n
"
);
sem_init
(
&
sema
,
0
,
0
);
/* create the "other" thread */
if
(
pthread_create
(
&
tid
,
0
,
&
other_thread
,
0
)
!=
0
)
/* create the "other" thread */
/* error */
if
(
pthread_create
(
&
tid
,
0
,
&
other_thread
,
0
)
!=
0
)
printf
(
"pthread_create OtherThread failed.
\n
"
);
/* error */
else
printf
(
"pthread_create OtherThread failed.
\n
"
);
printf
(
"created OtherThread=%x
\n
"
,
tid
);
else
printf
(
"created OtherThread=%x
\n
"
,
tid
);
/* let the other thread run */
/* let the other thread run */
while
(
1
)
while
(
1
)
{
{
printf
(
"Main: sem_wait...
\n
"
);
printf
(
"Main: sem_wait...
\n
"
);
if
(
sem_wait
(
&
sema
)
==
-
1
)
if
(
sem_wait
(
&
sema
)
==
-
1
)
printf
(
"sem_wait failed
\n
"
);
printf
(
"sem_wait failed
\n
"
);
printf
(
"Main back.
\n\n
"
);
printf
(
"Main back.
\n\n
"
);
}
}
pthread_exit
(
0
);
pthread_exit
(
0
);
}
}
#include <finsh.h>
#include <finsh.h>
void
libc_sem
()
void
libc_sem
()
{
{
rt_thread_t
tid
;
rt_thread_t
tid
;
tid
=
rt_thread_create
(
"semtest"
,
test_thread
,
RT_NULL
,
tid
=
rt_thread_create
(
"semtest"
,
test_thread
,
RT_NULL
,
2048
,
20
,
5
);
2048
,
20
,
5
);
if
(
tid
!=
RT_NULL
)
if
(
tid
!=
RT_NULL
)
{
{
rt_thread_startup
(
tid
);
rt_thread_startup
(
tid
);
}
}
}
}
FINSH_FUNCTION_EXPORT
(
libc_sem
,
posix
semaphore
test
);
FINSH_FUNCTION_EXPORT
(
libc_sem
,
posix
semaphore
test
);
examples/libc/time.c
浏览文件 @
08af426f
...
@@ -11,14 +11,14 @@
...
@@ -11,14 +11,14 @@
int
speed
()
int
speed
()
{
{
int
i
;
int
i
;
time_t
t
;
time_t
t
;
printf
(
"%d
\n
"
,
time
(
0
));
printf
(
"%d
\n
"
,
time
(
0
));
for
(
i
=
0
;
i
<
10000000
;
++
i
)
for
(
i
=
0
;
i
<
10000000
;
++
i
)
t
=
time
(
0
);
t
=
time
(
0
);
printf
(
"%d
\n
"
,
time
(
0
));
printf
(
"%d
\n
"
,
time
(
0
));
return
0
;
return
0
;
}
}
FINSH_FUNCTION_EXPORT
(
speed
,
speed
test
);
FINSH_FUNCTION_EXPORT
(
speed
,
speed
test
);
examples/network/tcpsendpacket.c
浏览文件 @
08af426f
...
@@ -26,9 +26,9 @@ void tcp_senddata(const char *url, int port, int length)
...
@@ -26,9 +26,9 @@ void tcp_senddata(const char *url, int port, int length)
{
{
/* 申请内存失败 */
/* 申请内存失败 */
rt_kprintf
(
"No memory
\n
"
);
rt_kprintf
(
"No memory
\n
"
);
return
;
return
;
}
}
/* 构造发送数据 */
/* 构造发送数据 */
for
(
index
=
0
;
index
<
length
;
index
++
)
for
(
index
=
0
;
index
<
length
;
index
++
)
buffer_ptr
[
index
]
=
index
&
0xff
;
buffer_ptr
[
index
]
=
index
&
0xff
;
...
...
examples/pm/timer_app.c
浏览文件 @
08af426f
/*
/*
* Copyright (c) 2006-20
18
, RT-Thread Development Team
* Copyright (c) 2006-20
21
, RT-Thread Development Team
*
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-License-Identifier: Apache-2.0
*
*
...
...
examples/pm/wakeup_app.c
浏览文件 @
08af426f
/*
/*
* Copyright (c) 2006-20
18
, RT-Thread Development Team
* Copyright (c) 2006-20
21
, RT-Thread Development Team
*
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-License-Identifier: Apache-2.0
*
*
...
...
examples/test/dhry.h
浏览文件 @
08af426f
...
@@ -3,9 +3,9 @@
...
@@ -3,9 +3,9 @@
*
*
* "DHRYSTONE" Benchmark Program
* "DHRYSTONE" Benchmark Program
* -----------------------------
* -----------------------------
*
*
* Version: C, Version 2.1
* Version: C, Version 2.1
*
*
* File: dhry.h (part 1 of 3)
* File: dhry.h (part 1 of 3)
*
*
* Date: May 25, 1988
* Date: May 25, 1988
...
@@ -33,12 +33,12 @@
...
@@ -33,12 +33,12 @@
*
*
* Collection of Results:
* Collection of Results:
* Reinhold Weicker (address see above) and
* Reinhold Weicker (address see above) and
*
*
* Rick Richardson
* Rick Richardson
* PC Research. Inc.
* PC Research. Inc.
* 94 Apple Orchard Drive
* 94 Apple Orchard Drive
* Tinton Falls, NJ 07724
* Tinton Falls, NJ 07724
* Phone: (201) 389-8963 (9-17 EST)
* Phone: (201) 389-8963 (9-17 EST)
* Usenet: ...!uunet!pcrat!rick
* Usenet: ...!uunet!pcrat!rick
*
*
* Please send results to Rick Richardson and/or Reinhold Weicker.
* Please send results to Rick Richardson and/or Reinhold Weicker.
...
@@ -91,7 +91,7 @@
...
@@ -91,7 +91,7 @@
* version previously distributed by Reinhold Weicker.
* version previously distributed by Reinhold Weicker.
*
*
* At several places in the benchmark, code has been added,
* At several places in the benchmark, code has been added,
* but within the measurement loop only in branches that
* but within the measurement loop only in branches that
* are not executed. The intention is that optimizing compilers
* are not executed. The intention is that optimizing compilers
* should be prevented from moving code out of the measurement
* should be prevented from moving code out of the measurement
* loop, or from removing code altogether. Since the statements
* loop, or from removing code altogether. Since the statements
...
@@ -101,7 +101,7 @@
...
@@ -101,7 +101,7 @@
* still hold. Except for sophisticated optimizing compilers,
* still hold. Except for sophisticated optimizing compilers,
* execution times for this version should be the same as
* execution times for this version should be the same as
* for previous versions.
* for previous versions.
*
*
* Since it has proven difficult to subtract the time for the
* Since it has proven difficult to subtract the time for the
* measurement loop overhead in a correct way, the loop check
* measurement loop overhead in a correct way, the loop check
* has been made a part of the benchmark. This does have
* has been made a part of the benchmark. This does have
...
@@ -151,7 +151,7 @@
...
@@ -151,7 +151,7 @@
* -DTIME
* -DTIME
* The "times" function of UNIX (returning process times)
* The "times" function of UNIX (returning process times)
* or the "time" function (returning wallclock time)
* or the "time" function (returning wallclock time)
* is used for measurement.
* is used for measurement.
* For single user machines, "time ()" is adequate. For
* For single user machines, "time ()" is adequate. For
* multi-user machines where you cannot get single-user
* multi-user machines where you cannot get single-user
* access, use the "times ()" function. If you have
* access, use the "times ()" function. If you have
...
@@ -198,23 +198,23 @@
...
@@ -198,23 +198,23 @@
* different from the Ada version.]
* different from the Ada version.]
*
*
* The following program contains statements of a high level programming
* The following program contains statements of a high level programming
* language (here: C) in a distribution considered representative:
* language (here: C) in a distribution considered representative:
*
*
* assignments 52 (51.0 %)
* assignments 52 (51.0 %)
* control statements 33 (32.4 %)
* control statements 33 (32.4 %)
* procedure, function calls 17 (16.7 %)
* procedure, function calls 17 (16.7 %)
*
*
* 103 statements are dynamically executed. The program is balanced with
* 103 statements are dynamically executed. The program is balanced with
* respect to the three aspects:
* respect to the three aspects:
*
*
* - statement type
* - statement type
* - operand type
* - operand type
* - operand locality
* - operand locality
* operand global, local, parameter, or constant.
* operand global, local, parameter, or constant.
*
*
* The combination of these three aspects is balanced only approximately.
* The combination of these three aspects is balanced only approximately.
*
*
* 1. Statement Type:
* 1. Statement Type:
* ----------------- number
* ----------------- number
*
*
* V1 = V2 9
* V1 = V2 9
...
@@ -258,9 +258,9 @@
...
@@ -258,9 +258,9 @@
* library procedure 1
* library procedure 1
* X = F (...)
* X = F (...)
* function call 6
* function call 6
* user function 5
* user function 5
* library function 1
* library function 1
* --
* --
* 17 17
* 17 17
* ---
* ---
* 103
* 103
...
@@ -274,10 +274,10 @@
...
@@ -274,10 +274,10 @@
* number approximate
* number approximate
* percentage
* percentage
*
*
* Arithmetic 32 50.8
* Arithmetic 32 50.8
*
*
* + 21 33.3
* + 21 33.3
* - 7 11.1
* - 7 11.1
* * 3 4.8
* * 3 4.8
* / (int div) 1 1.6
* / (int div) 1 1.6
*
*
...
@@ -295,7 +295,7 @@
...
@@ -295,7 +295,7 @@
* && (AND-THEN) 1 1.6
* && (AND-THEN) 1 1.6
* | (OR) 1 1.6
* | (OR) 1 1.6
* ! (NOT) 2 3.2
* ! (NOT) 2 3.2
*
*
* -- -----
* -- -----
* 63 100.1
* 63 100.1
*
*
...
@@ -315,10 +315,10 @@
...
@@ -315,10 +315,10 @@
* 242 100.0 %
* 242 100.0 %
*
*
* When there is an access path leading to the final operand (e.g. a record
* When there is an access path leading to the final operand (e.g. a record
* component), only the final data type on the access path is counted.
* component), only the final data type on the access path is counted.
*
*
*
*
* 4. Operand Locality:
* 4. Operand Locality:
* -------------------
* -------------------
* number approximate
* number approximate
* percentage
* percentage
...
@@ -375,7 +375,7 @@
...
@@ -375,7 +375,7 @@
/* for strcpy, strcmp */
/* for strcpy, strcmp */
#include <rtthread.h>
#include <rtthread.h>
#define Null 0
#define Null 0
/* Value of a Null pointer */
/* Value of a Null pointer */
#define true 1
#define true 1
#define false 0
#define false 0
...
@@ -388,7 +388,7 @@ typedef char Str_30 [31];
...
@@ -388,7 +388,7 @@ typedef char Str_30 [31];
typedef
int
Arr_1_Dim
[
50
];
typedef
int
Arr_1_Dim
[
50
];
typedef
int
Arr_2_Dim
[
50
]
[
50
];
typedef
int
Arr_2_Dim
[
50
]
[
50
];
typedef
struct
record
typedef
struct
record
{
{
struct
record
*
Ptr_Comp
;
struct
record
*
Ptr_Comp
;
Enumeration
Discr
;
Enumeration
Discr
;
...
...
examples/test/dhry_1.c
浏览文件 @
08af426f
...
@@ -3,9 +3,9 @@
...
@@ -3,9 +3,9 @@
*
*
* "DHRYSTONE" Benchmark Program
* "DHRYSTONE" Benchmark Program
* -----------------------------
* -----------------------------
*
*
* Version: C, Version 2.1
* Version: C, Version 2.1
*
*
* File: dhry_1.c (part 2 of 3)
* File: dhry_1.c (part 2 of 3)
*
*
* Date: May 25, 1988
* Date: May 25, 1988
...
@@ -14,8 +14,8 @@
...
@@ -14,8 +14,8 @@
*
*
****************************************************************************
****************************************************************************
*/
*/
#define NUMBER_OF_RUNS
1000000
#define NUMBER_OF_RUNS
1000000
#include "dhry.h"
#include "dhry.h"
#define printf rt_kprintf
#define printf rt_kprintf
...
@@ -34,7 +34,7 @@ int Arr_2_Glob [50] [50];
...
@@ -34,7 +34,7 @@ int Arr_2_Glob [50] [50];
Enumeration
Func_1
();
Enumeration
Func_1
();
/* forward declaration necessary since Enumeration may not simply be int */
/* forward declaration necessary since Enumeration may not simply be int */
#ifndef REG
#ifndef REG
Boolean
Reg
=
false
;
Boolean
Reg
=
false
;
#define REG
#define REG
...
@@ -71,7 +71,7 @@ void dhry_test(void)
...
@@ -71,7 +71,7 @@ void dhry_test(void)
REG
int
Number_Of_Runs
;
REG
int
Number_Of_Runs
;
/* Initializations */
/* Initializations */
Next_Ptr_Glob
=
(
Rec_Pointer
)
rt_malloc
(
sizeof
(
Rec_Type
));
Next_Ptr_Glob
=
(
Rec_Pointer
)
rt_malloc
(
sizeof
(
Rec_Type
));
Ptr_Glob
=
(
Rec_Pointer
)
rt_malloc
(
sizeof
(
Rec_Type
));
Ptr_Glob
=
(
Rec_Pointer
)
rt_malloc
(
sizeof
(
Rec_Type
));
...
@@ -79,7 +79,7 @@ void dhry_test(void)
...
@@ -79,7 +79,7 @@ void dhry_test(void)
Ptr_Glob
->
Discr
=
Ident_1
;
Ptr_Glob
->
Discr
=
Ident_1
;
Ptr_Glob
->
variant
.
var_1
.
Enum_Comp
=
Ident_3
;
Ptr_Glob
->
variant
.
var_1
.
Enum_Comp
=
Ident_3
;
Ptr_Glob
->
variant
.
var_1
.
Int_Comp
=
40
;
Ptr_Glob
->
variant
.
var_1
.
Int_Comp
=
40
;
rt_strncpy
(
Ptr_Glob
->
variant
.
var_1
.
Str_Comp
,
rt_strncpy
(
Ptr_Glob
->
variant
.
var_1
.
Str_Comp
,
"DHRYSTONE PROGRAM, SOME STRING"
,
sizeof
(
Ptr_Glob
->
variant
.
var_1
.
Str_Comp
));
"DHRYSTONE PROGRAM, SOME STRING"
,
sizeof
(
Ptr_Glob
->
variant
.
var_1
.
Str_Comp
));
rt_strncpy
(
Str_1_Loc
,
"DHRYSTONE PROGRAM, 1'ST STRING"
,
sizeof
(
Str_1_Loc
));
rt_strncpy
(
Str_1_Loc
,
"DHRYSTONE PROGRAM, 1'ST STRING"
,
sizeof
(
Str_1_Loc
));
...
@@ -114,9 +114,9 @@ void dhry_test(void)
...
@@ -114,9 +114,9 @@ void dhry_test(void)
/***************/
/***************/
/* Start timer */
/* Start timer */
/***************/
/***************/
// Add your timer initializing code here
// Add your timer initializing code here
Begin_Time
=
rt_tick_get
();
/* get start tick */
Begin_Time
=
rt_tick_get
();
/* get start tick */
for
(
Run_Index
=
1
;
Run_Index
<=
Number_Of_Runs
;
++
Run_Index
)
for
(
Run_Index
=
1
;
Run_Index
<=
Number_Of_Runs
;
++
Run_Index
)
...
@@ -169,8 +169,8 @@ void dhry_test(void)
...
@@ -169,8 +169,8 @@ void dhry_test(void)
/* Stop timer */
/* Stop timer */
/**************/
/**************/
End_Time
=
rt_tick_get
();
// Get end tick
End_Time
=
rt_tick_get
();
// Get end tick
printf
(
"Execution ends
\n
"
);
printf
(
"Execution ends
\n
"
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
printf
(
"Final values of the variables used in the benchmark:
\n
"
);
printf
(
"Final values of the variables used in the benchmark:
\n
"
);
...
@@ -226,7 +226,7 @@ void dhry_test(void)
...
@@ -226,7 +226,7 @@ void dhry_test(void)
User_Time
=
(
End_Time
-
Begin_Time
)
/
RT_TICK_PER_SECOND
;
User_Time
=
(
End_Time
-
Begin_Time
)
/
RT_TICK_PER_SECOND
;
Microseconds
=
(
float
)
User_Time
*
Mic_secs_Per_Second
Microseconds
=
(
float
)
User_Time
*
Mic_secs_Per_Second
/
(
float
)
Number_Of_Runs
;
/
(
float
)
Number_Of_Runs
;
Dhrystones_Per_Second
=
(
float
)
Number_Of_Runs
/
(
float
)
User_Time
;
Dhrystones_Per_Second
=
(
float
)
Number_Of_Runs
/
(
float
)
User_Time
;
...
@@ -237,7 +237,7 @@ void dhry_test(void)
...
@@ -237,7 +237,7 @@ void dhry_test(void)
printf
(
"Dhrystones MIPS: "
);
printf
(
"Dhrystones MIPS: "
);
printf
(
"%6d
\n
"
,
(
int
)(
Dhrystones_Per_Second
/
1757
.
0
));
printf
(
"%6d
\n
"
,
(
int
)(
Dhrystones_Per_Second
/
1757
.
0
));
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
Proc_1
(
Ptr_Val_Par
)
Proc_1
(
Ptr_Val_Par
)
...
@@ -246,27 +246,27 @@ Proc_1 (Ptr_Val_Par)
...
@@ -246,27 +246,27 @@ Proc_1 (Ptr_Val_Par)
REG
Rec_Pointer
Ptr_Val_Par
;
REG
Rec_Pointer
Ptr_Val_Par
;
/* executed once */
/* executed once */
{
{
REG
Rec_Pointer
Next_Record
=
Ptr_Val_Par
->
Ptr_Comp
;
REG
Rec_Pointer
Next_Record
=
Ptr_Val_Par
->
Ptr_Comp
;
/* == Ptr_Glob_Next */
/* == Ptr_Glob_Next */
/* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
/* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
/* corresponds to "rename" in Ada, "with" in Pascal */
/* corresponds to "rename" in Ada, "with" in Pascal */
structassign
(
*
Ptr_Val_Par
->
Ptr_Comp
,
*
Ptr_Glob
);
structassign
(
*
Ptr_Val_Par
->
Ptr_Comp
,
*
Ptr_Glob
);
Ptr_Val_Par
->
variant
.
var_1
.
Int_Comp
=
5
;
Ptr_Val_Par
->
variant
.
var_1
.
Int_Comp
=
5
;
Next_Record
->
variant
.
var_1
.
Int_Comp
Next_Record
->
variant
.
var_1
.
Int_Comp
=
Ptr_Val_Par
->
variant
.
var_1
.
Int_Comp
;
=
Ptr_Val_Par
->
variant
.
var_1
.
Int_Comp
;
Next_Record
->
Ptr_Comp
=
Ptr_Val_Par
->
Ptr_Comp
;
Next_Record
->
Ptr_Comp
=
Ptr_Val_Par
->
Ptr_Comp
;
Proc_3
(
&
Next_Record
->
Ptr_Comp
);
Proc_3
(
&
Next_Record
->
Ptr_Comp
);
/* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
/* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
== Ptr_Glob->Ptr_Comp */
== Ptr_Glob->Ptr_Comp */
if
(
Next_Record
->
Discr
==
Ident_1
)
if
(
Next_Record
->
Discr
==
Ident_1
)
/* then, executed */
/* then, executed */
{
{
Next_Record
->
variant
.
var_1
.
Int_Comp
=
6
;
Next_Record
->
variant
.
var_1
.
Int_Comp
=
6
;
Proc_6
(
Ptr_Val_Par
->
variant
.
var_1
.
Enum_Comp
,
Proc_6
(
Ptr_Val_Par
->
variant
.
var_1
.
Enum_Comp
,
&
Next_Record
->
variant
.
var_1
.
Enum_Comp
);
&
Next_Record
->
variant
.
var_1
.
Enum_Comp
);
Next_Record
->
Ptr_Comp
=
Ptr_Glob
->
Ptr_Comp
;
Next_Record
->
Ptr_Comp
=
Ptr_Glob
->
Ptr_Comp
;
Proc_7
(
Next_Record
->
variant
.
var_1
.
Int_Comp
,
10
,
Proc_7
(
Next_Record
->
variant
.
var_1
.
Int_Comp
,
10
,
&
Next_Record
->
variant
.
var_1
.
Int_Comp
);
&
Next_Record
->
variant
.
var_1
.
Int_Comp
);
}
}
else
/* not executed */
else
/* not executed */
...
@@ -281,7 +281,7 @@ Proc_2 (Int_Par_Ref)
...
@@ -281,7 +281,7 @@ Proc_2 (Int_Par_Ref)
One_Fifty
*
Int_Par_Ref
;
One_Fifty
*
Int_Par_Ref
;
{
{
One_Fifty
Int_Loc
;
One_Fifty
Int_Loc
;
Enumeration
Enum_Loc
;
Enumeration
Enum_Loc
;
Int_Loc
=
*
Int_Par_Ref
+
10
;
Int_Loc
=
*
Int_Par_Ref
+
10
;
...
...
examples/test/dhry_2.c
浏览文件 @
08af426f
...
@@ -3,9 +3,9 @@
...
@@ -3,9 +3,9 @@
*
*
* "DHRYSTONE" Benchmark Program
* "DHRYSTONE" Benchmark Program
* -----------------------------
* -----------------------------
*
*
* Version: C, Version 2.1
* Version: C, Version 2.1
*
*
* File: dhry_2.c (part 3 of 3)
* File: dhry_2.c (part 3 of 3)
*
*
* Date: May 25, 1988
* Date: May 25, 1988
...
@@ -41,10 +41,10 @@ Enumeration *Enum_Ref_Par;
...
@@ -41,10 +41,10 @@ Enumeration *Enum_Ref_Par;
*
Enum_Ref_Par
=
Ident_4
;
*
Enum_Ref_Par
=
Ident_4
;
switch
(
Enum_Val_Par
)
switch
(
Enum_Val_Par
)
{
{
case
Ident_1
:
case
Ident_1
:
*
Enum_Ref_Par
=
Ident_1
;
*
Enum_Ref_Par
=
Ident_1
;
break
;
break
;
case
Ident_2
:
case
Ident_2
:
if
(
Int_Glob
>
100
)
if
(
Int_Glob
>
100
)
/* then */
/* then */
*
Enum_Ref_Par
=
Ident_1
;
*
Enum_Ref_Par
=
Ident_1
;
...
@@ -54,7 +54,7 @@ Enumeration *Enum_Ref_Par;
...
@@ -54,7 +54,7 @@ Enumeration *Enum_Ref_Par;
*
Enum_Ref_Par
=
Ident_2
;
*
Enum_Ref_Par
=
Ident_2
;
break
;
break
;
case
Ident_4
:
break
;
case
Ident_4
:
break
;
case
Ident_5
:
case
Ident_5
:
*
Enum_Ref_Par
=
Ident_3
;
*
Enum_Ref_Par
=
Ident_3
;
break
;
break
;
}
/* switch */
}
/* switch */
...
@@ -63,7 +63,7 @@ Enumeration *Enum_Ref_Par;
...
@@ -63,7 +63,7 @@ Enumeration *Enum_Ref_Par;
Proc_7
(
Int_1_Par_Val
,
Int_2_Par_Val
,
Int_Par_Ref
)
Proc_7
(
Int_1_Par_Val
,
Int_2_Par_Val
,
Int_Par_Ref
)
/**********************************************/
/**********************************************/
/* executed three times */
/* executed three times */
/* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */
/* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */
/* Int_Par_Ref becomes 7 */
/* Int_Par_Ref becomes 7 */
/* second call: Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
/* second call: Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
...
...
examples/test/hwtimer_test.c
浏览文件 @
08af426f
...
@@ -35,8 +35,8 @@ int hwtimer(void)
...
@@ -35,8 +35,8 @@ int hwtimer(void)
return
-
1
;
return
-
1
;
}
}
/*
时间测量
*/
/*
时间测量 *
/
/*
计数时钟设置(默认1Mhz或支持的最小计数频率
) */
/*
计数时钟设置(默认1Mhz或支持的最小计数频率) */
err
=
rt_device_control
(
dev
,
HWTIMER_CTRL_FREQ_SET
,
&
freq
);
err
=
rt_device_control
(
dev
,
HWTIMER_CTRL_FREQ_SET
,
&
freq
);
if
(
err
!=
RT_EOK
)
if
(
err
!=
RT_EOK
)
{
{
...
@@ -44,13 +44,13 @@ int hwtimer(void)
...
@@ -44,13 +44,13 @@ int hwtimer(void)
goto
EXIT
;
goto
EXIT
;
}
}
/*
周期模式
*/
/*
周期模式 *
/
mode
=
HWTIMER_MODE_PERIOD
;
mode
=
HWTIMER_MODE_PERIOD
;
err
=
rt_device_control
(
dev
,
HWTIMER_CTRL_MODE_SET
,
&
mode
);
err
=
rt_device_control
(
dev
,
HWTIMER_CTRL_MODE_SET
,
&
mode
);
tick
=
rt_tick_get
();
tick
=
rt_tick_get
();
rt_kprintf
(
"Start Timer> Tick: %d
\n
"
,
tick
);
rt_kprintf
(
"Start Timer> Tick: %d
\n
"
,
tick
);
/*
设置定时器超时值并启动定时器
*/
/*
设置定时器超时值并启动定时器 */
val
.
sec
=
t
;
val
.
sec
=
t
;
val
.
usec
=
0
;
val
.
usec
=
0
;
rt_kprintf
(
"SetTime: Sec %d, Usec %d
\n
"
,
val
.
sec
,
val
.
usec
);
rt_kprintf
(
"SetTime: Sec %d, Usec %d
\n
"
,
val
.
sec
,
val
.
usec
);
...
@@ -62,22 +62,22 @@ int hwtimer(void)
...
@@ -62,22 +62,22 @@ int hwtimer(void)
rt_kprintf
(
"Sleep %d sec
\n
"
,
t
);
rt_kprintf
(
"Sleep %d sec
\n
"
,
t
);
rt_thread_delay
(
t
*
RT_TICK_PER_SECOND
);
rt_thread_delay
(
t
*
RT_TICK_PER_SECOND
);
/*
停止定时器
*/
/*
停止定时器 *
/
err
=
rt_device_control
(
dev
,
HWTIMER_CTRL_STOP
,
RT_NULL
);
err
=
rt_device_control
(
dev
,
HWTIMER_CTRL_STOP
,
RT_NULL
);
rt_kprintf
(
"Timer Stoped
\n
"
);
rt_kprintf
(
"Timer Stoped
\n
"
);
/*
读取计数
*/
/*
读取计数 *
/
rt_device_read
(
dev
,
0
,
&
val
,
sizeof
(
val
));
rt_device_read
(
dev
,
0
,
&
val
,
sizeof
(
val
));
rt_kprintf
(
"Read: Sec = %d, Usec = %d
\n
"
,
val
.
sec
,
val
.
usec
);
rt_kprintf
(
"Read: Sec = %d, Usec = %d
\n
"
,
val
.
sec
,
val
.
usec
);
/*
定时执行回调函数 -- 单次模式
*/
/*
定时执行回调函数 -- 单次模式 */
/*
设置超时回调函数
*/
/*
设置超时回调函数 */
rt_device_set_rx_indicate
(
dev
,
timer_timeout_cb
);
rt_device_set_rx_indicate
(
dev
,
timer_timeout_cb
);
/*
单次模式
*/
/*
单次模式 *
/
mode
=
HWTIMER_MODE_PERIOD
;
mode
=
HWTIMER_MODE_PERIOD
;
err
=
rt_device_control
(
dev
,
HWTIMER_CTRL_MODE_SET
,
&
mode
);
err
=
rt_device_control
(
dev
,
HWTIMER_CTRL_MODE_SET
,
&
mode
);
/*
设置定时器超时值并启动定时器
*/
/*
设置定时器超时值并启动定时器 */
val
.
sec
=
t
;
val
.
sec
=
t
;
val
.
usec
=
0
;
val
.
usec
=
0
;
rt_kprintf
(
"SetTime: Sec %d, Usec %d
\n
"
,
val
.
sec
,
val
.
usec
);
rt_kprintf
(
"SetTime: Sec %d, Usec %d
\n
"
,
val
.
sec
,
val
.
usec
);
...
@@ -87,7 +87,7 @@ int hwtimer(void)
...
@@ -87,7 +87,7 @@ int hwtimer(void)
goto
EXIT
;
goto
EXIT
;
}
}
/*
等待回调函数执行
*/
/*
等待回调函数执行 */
rt_thread_delay
((
t
+
1
)
*
RT_TICK_PER_SECOND
);
rt_thread_delay
((
t
+
1
)
*
RT_TICK_PER_SECOND
);
EXIT:
EXIT:
...
...
examples/test/net_test.c
浏览文件 @
08af426f
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#include <lwip/sockets.h>
#include <lwip/sockets.h>
#include <lwip/init.h>
#include <lwip/init.h>
/*
/*
* UDP echo server
* UDP echo server
*/
*/
#define UDP_ECHO_PORT 7
#define UDP_ECHO_PORT 7
...
@@ -30,12 +30,12 @@ void udpecho_entry(void *parameter)
...
@@ -30,12 +30,12 @@ void udpecho_entry(void *parameter)
while
(
1
)
while
(
1
)
{
{
/* received data to buffer */
/* received data to buffer */
#if LWIP_VERSION_MINOR==3U
#if LWIP_VERSION_MINOR==3U
buf
=
netconn_recv
(
conn
);
buf
=
netconn_recv
(
conn
);
#else
#else
netconn_recv
(
conn
,
&
buf
);
netconn_recv
(
conn
,
&
buf
);
#endif
#endif
if
(
buf
==
NULL
)
if
(
buf
==
NULL
)
{
{
break
;
break
;
}
}
...
@@ -46,25 +46,25 @@ void udpecho_entry(void *parameter)
...
@@ -46,25 +46,25 @@ void udpecho_entry(void *parameter)
netconn_connect
(
conn
,
addr
,
port
);
netconn_connect
(
conn
,
addr
,
port
);
/* reset address, and send to client */
/* reset address, and send to client */
#if LWIP_VERSION_MINOR==3U
#if LWIP_VERSION_MINOR==3U
buf
->
addr
=
RT_NULL
;
buf
->
addr
=
RT_NULL
;
#else
#else
buf
->
addr
=
*
IP_ADDR_ANY
;
buf
->
addr
=
*
IP_ADDR_ANY
;
#endif
#endif
netconn_send
(
conn
,
buf
);
netconn_send
(
conn
,
buf
);
/* release buffer */
/* release buffer */
netbuf_delete
(
buf
);
netbuf_delete
(
buf
);
}
}
netconn_delete
(
conn
);
netconn_delete
(
conn
);
}
}
/*
/*
* UDP socket echo server
* UDP socket echo server
*/
*/
#define UDP_SOCKET_ECHO_PORT
700
#define UDP_SOCKET_ECHO_PORT
700
#define UDP_SOCKET_BUFFER_SIZE
4096
#define UDP_SOCKET_BUFFER_SIZE
4096
rt_thread_t
udpecho_socket_tid
=
RT_NULL
;
rt_thread_t
udpecho_socket_tid
=
RT_NULL
;
void
udpecho_socket_entry
(
void
*
parameter
)
void
udpecho_socket_entry
(
void
*
parameter
)
{
{
...
@@ -110,7 +110,7 @@ void udpecho_socket_entry(void *parameter)
...
@@ -110,7 +110,7 @@ void udpecho_socket_entry(void *parameter)
/* try to receive from UDP socket */
/* try to receive from UDP socket */
bytes_read
=
recvfrom
(
sock
,
recv_data
,
UDP_SOCKET_BUFFER_SIZE
,
0
,
bytes_read
=
recvfrom
(
sock
,
recv_data
,
UDP_SOCKET_BUFFER_SIZE
,
0
,
(
struct
sockaddr
*
)
&
client_addr
,
&
addr_len
);
(
struct
sockaddr
*
)
&
client_addr
,
&
addr_len
);
/* send back */
/* send back */
sendto
(
sock
,
recv_data
,
bytes_read
,
0
,
sendto
(
sock
,
recv_data
,
bytes_read
,
0
,
(
struct
sockaddr
*
)
&
client_addr
,
addr_len
);
(
struct
sockaddr
*
)
&
client_addr
,
addr_len
);
...
@@ -148,7 +148,7 @@ void tcpecho_entry(void *parameter)
...
@@ -148,7 +148,7 @@ void tcpecho_entry(void *parameter)
while
(
1
)
while
(
1
)
{
{
/* Grab new connection. */
/* Grab new connection. */
#if LWIP_VERSION_MINOR==3U
#if LWIP_VERSION_MINOR==3U
newconn
=
netconn_accept
(
conn
);
newconn
=
netconn_accept
(
conn
);
if
(
newconn
!=
NULL
)
if
(
newconn
!=
NULL
)
#else
#else
...
@@ -172,25 +172,25 @@ void tcpecho_entry(void *parameter)
...
@@ -172,25 +172,25 @@ void tcpecho_entry(void *parameter)
err
=
netconn_write
(
newconn
,
data
,
len
,
NETCONN_COPY
);
err
=
netconn_write
(
newconn
,
data
,
len
,
NETCONN_COPY
);
if
(
err
!=
ERR_OK
)
if
(
err
!=
ERR_OK
)
{
{
break
;
break
;
}
}
}
while
(
netbuf_next
(
buf
)
>=
0
);
}
while
(
netbuf_next
(
buf
)
>=
0
);
netbuf_delete
(
buf
);
netbuf_delete
(
buf
);
}
}
/* Close connection and discard connection identifier. */
/* Close connection and discard connection identifier. */
netconn_delete
(
newconn
);
netconn_delete
(
newconn
);
}
}
}
}
netconn_delete
(
conn
);
netconn_delete
(
conn
);
}
}
/*
/*
* TCP socket echo server
* TCP socket echo server
*/
*/
#define TCP_SOCKET_ECHO_PORT
700
#define TCP_SOCKET_ECHO_PORT
700
#define TCP_SOCKET_BUFFER_SIZE
4096
#define TCP_SOCKET_BUFFER_SIZE
4096
rt_thread_t
tcpecho_socket_tid
=
RT_NULL
;
rt_thread_t
tcpecho_socket_tid
=
RT_NULL
;
void
tcpecho_socket_entry
(
void
*
parameter
)
void
tcpecho_socket_entry
(
void
*
parameter
)
{
{
...
@@ -241,7 +241,7 @@ void tcpecho_socket_entry(void *parameter)
...
@@ -241,7 +241,7 @@ void tcpecho_socket_entry(void *parameter)
if
(
connected
>
0
)
if
(
connected
>
0
)
{
{
int
timeout
;
int
timeout
;
/* set timeout option */
/* set timeout option */
timeout
=
5000
;
/* 5second */
timeout
=
5000
;
/* 5second */
setsockopt
(
connected
,
SOL_SOCKET
,
SO_RCVTIMEO
,
&
timeout
,
sizeof
(
timeout
));
setsockopt
(
connected
,
SOL_SOCKET
,
SO_RCVTIMEO
,
&
timeout
,
sizeof
(
timeout
));
...
@@ -285,8 +285,8 @@ void net_test(void)
...
@@ -285,8 +285,8 @@ void net_test(void)
{
{
udpecho_tid
=
rt_thread_create
(
"uecho"
,
udpecho_tid
=
rt_thread_create
(
"uecho"
,
udpecho_entry
,
udpecho_entry
,
RT_NULL
,
RT_NULL
,
512
,
512
,
RT_THREAD_PRIORITY_MAX
/
2
,
5
);
RT_THREAD_PRIORITY_MAX
/
2
,
5
);
if
(
udpecho_tid
!=
RT_NULL
)
if
(
udpecho_tid
!=
RT_NULL
)
{
{
...
@@ -299,7 +299,7 @@ void net_test(void)
...
@@ -299,7 +299,7 @@ void net_test(void)
udpecho_socket_tid
=
rt_thread_create
(
"uecho_s"
,
udpecho_socket_tid
=
rt_thread_create
(
"uecho_s"
,
udpecho_socket_entry
,
udpecho_socket_entry
,
RT_NULL
,
RT_NULL
,
512
,
512
,
RT_THREAD_PRIORITY_MAX
/
2
+
1
,
5
);
RT_THREAD_PRIORITY_MAX
/
2
+
1
,
5
);
if
(
udpecho_socket_tid
!=
RT_NULL
)
if
(
udpecho_socket_tid
!=
RT_NULL
)
{
{
...
@@ -310,22 +310,22 @@ void net_test(void)
...
@@ -310,22 +310,22 @@ void net_test(void)
if
(
tcpecho_tid
==
RT_NULL
)
if
(
tcpecho_tid
==
RT_NULL
)
{
{
tcpecho_tid
=
rt_thread_create
(
"techo"
,
tcpecho_tid
=
rt_thread_create
(
"techo"
,
tcpecho_entry
,
tcpecho_entry
,
RT_NULL
,
RT_NULL
,
512
,
512
,
RT_THREAD_PRIORITY_MAX
/
2
+
2
,
5
);
RT_THREAD_PRIORITY_MAX
/
2
+
2
,
5
);
if
(
tcpecho_tid
!=
RT_NULL
)
if
(
tcpecho_tid
!=
RT_NULL
)
{
{
rt_thread_startup
(
tcpecho_tid
);
rt_thread_startup
(
tcpecho_tid
);
}
}
}
}
if
(
tcpecho_socket_tid
==
RT_NULL
)
if
(
tcpecho_socket_tid
==
RT_NULL
)
{
{
tcpecho_socket_tid
=
rt_thread_create
(
"techo_s"
,
tcpecho_socket_tid
=
rt_thread_create
(
"techo_s"
,
tcpecho_socket_entry
,
tcpecho_socket_entry
,
RT_NULL
,
RT_NULL
,
512
,
512
,
RT_THREAD_PRIORITY_MAX
/
2
+
3
,
5
);
RT_THREAD_PRIORITY_MAX
/
2
+
3
,
5
);
if
(
tcpecho_socket_tid
!=
RT_NULL
)
if
(
tcpecho_socket_tid
!=
RT_NULL
)
{
{
...
...
examples/test/rtc_test.c
浏览文件 @
08af426f
...
@@ -21,48 +21,48 @@
...
@@ -21,48 +21,48 @@
* Date Author Notes
* Date Author Notes
* 2018-01-15 Liu2guang the first version.
* 2018-01-15 Liu2guang the first version.
*/
*/
#include <rtthread.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <rtdevice.h>
int
rtc_test
(
void
)
int
rtc_test
(
void
)
{
{
uint8_t
i
;
uint8_t
i
;
time_t
now
;
time_t
now
;
rt_err_t
ret
=
RT_EOK
;
rt_err_t
ret
=
RT_EOK
;
rt_kprintf
(
"[RTC Test]RTC Test Start...
\n
"
);
rt_kprintf
(
"[RTC Test]RTC Test Start...
\n
"
);
rt_thread_delay
(
RT_TICK_PER_SECOND
);
rt_thread_delay
(
RT_TICK_PER_SECOND
);
rt_kprintf
(
"[RTC Test]Set RTC 2017-04-01 12:30:46
\n\n
"
);
rt_kprintf
(
"[RTC Test]Set RTC 2017-04-01 12:30:46
\n\n
"
);
rt_thread_delay
(
RT_TICK_PER_SECOND
);
rt_thread_delay
(
RT_TICK_PER_SECOND
);
ret
=
set_date
(
2017
,
4
,
1
);
ret
=
set_date
(
2017
,
4
,
1
);
if
(
ret
!=
RT_EOK
)
if
(
ret
!=
RT_EOK
)
{
{
rt_kprintf
(
"[RTC Test]Set RTC Date failed
\n
"
);
rt_kprintf
(
"[RTC Test]Set RTC Date failed
\n
"
);
return
RT_ERROR
;
return
RT_ERROR
;
}
}
rt_thread_delay
(
RT_TICK_PER_SECOND
);
rt_thread_delay
(
RT_TICK_PER_SECOND
);
ret
=
set_time
(
12
,
30
,
46
);
ret
=
set_time
(
12
,
30
,
46
);
if
(
ret
!=
RT_EOK
)
if
(
ret
!=
RT_EOK
)
{
{
rt_kprintf
(
"[RTC Test]Set RTC Time failed
\n
"
);
rt_kprintf
(
"[RTC Test]Set RTC Time failed
\n
"
);
return
RT_ERROR
;
return
RT_ERROR
;
}
}
rt_thread_delay
(
RT_TICK_PER_SECOND
);
rt_thread_delay
(
RT_TICK_PER_SECOND
);
for
(
i
=
0
;
i
<
10
;
i
++
)
for
(
i
=
0
;
i
<
10
;
i
++
)
{
{
rt_kprintf
(
"[RTC Test]Read RTC Date and Time: "
);
rt_kprintf
(
"[RTC Test]Read RTC Date and Time: "
);
now
=
time
(
RT_NULL
);
now
=
time
(
RT_NULL
);
rt_kprintf
(
"%s"
,
ctime
(
&
now
));
rt_kprintf
(
"%s"
,
ctime
(
&
now
));
rt_thread_delay
(
RT_TICK_PER_SECOND
);
rt_thread_delay
(
RT_TICK_PER_SECOND
);
}
}
rt_kprintf
(
"
\n
"
);
rt_kprintf
(
"
\n
"
);
return
RT_EOK
;
return
RT_EOK
;
...
@@ -70,5 +70,5 @@ int rtc_test(void)
...
@@ -70,5 +70,5 @@ int rtc_test(void)
#ifdef RT_USING_FINSH
#ifdef RT_USING_FINSH
#include <finsh.h>
#include <finsh.h>
FINSH_FUNCTION_EXPORT
(
rtc_test
,
rtc
drive
test
.
e
.
g
:
rtc_test
());
FINSH_FUNCTION_EXPORT
(
rtc_test
,
rtc
drive
test
.
e
.
g
:
rtc_test
());
MSH_CMD_EXPORT
(
rtc_test
,
rtc
drive
test
.
e
.
g
:
rtc_test
());
MSH_CMD_EXPORT
(
rtc_test
,
rtc
drive
test
.
e
.
g
:
rtc_test
());
#endif
#endif
examples/ulog/ulog_example.c
浏览文件 @
08af426f
/*
/*
* Copyright (c) 2006-20
18
, RT-Thread Development Team
* Copyright (c) 2006-20
21
, RT-Thread Development Team
*
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-License-Identifier: Apache-2.0
*
*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录