mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-10-07 00:59:00 +08:00
Merge branch 'master' into SQLite_on_ARMCC
This commit is contained in:
@@ -7,17 +7,9 @@ if os.getenv('RTT_ROOT'):
|
||||
else:
|
||||
RTT_ROOT = os.path.normpath(os.getcwd() + '/../..')
|
||||
|
||||
if os.getenv('RTT_RTGUI'):
|
||||
RTT_RTGUI = os.getenv('RTT_RTGUI')
|
||||
else:
|
||||
# set the rtgui root directory by hand
|
||||
# empty string means use the RTGUI in svn
|
||||
RTT_RTGUI = os.path.normpath(r'F:\Project\git\rt-gui\components\rtgui')
|
||||
|
||||
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
|
||||
from building import *
|
||||
|
||||
|
||||
env = Environment(TARGET_ARCH='x86')
|
||||
|
||||
Export('RTT_ROOT')
|
||||
@@ -84,32 +76,7 @@ else:
|
||||
|
||||
# prepare building environment
|
||||
|
||||
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False, remove_components=['rtgui'])
|
||||
if GetDepend('RT_USING_RTGUI'):
|
||||
try:
|
||||
if RTT_RTGUI:
|
||||
objs += SConscript(os.path.join(RTT_RTGUI, 'SConscript'),
|
||||
variant_dir='build/components/rtgui',
|
||||
duplicate=0)
|
||||
objs = objs + SConscript(RTT_RTGUI+'/../../demo/examples/SConscript',
|
||||
variant_dir='build/examples/gui', duplicate=0)
|
||||
else:
|
||||
objs += SConscript(os.path.join(RTT_ROOT + '/components/rtgui', 'SConscript'),
|
||||
variant_dir='build/components/rtgui',
|
||||
duplicate=0)
|
||||
objs = objs + SConscript(RTT_ROOT + '/examples/gui/SConscript',
|
||||
variant_dir='build/examples/gui', duplicate=0)
|
||||
except:
|
||||
print
|
||||
print 'RTGUI configuration is invalid!'
|
||||
print 'RT_USING_RTGUI is enabled in rtconfig.h, but scons cannot find '+\
|
||||
'RTGUI source code. In order to eliminate this error, you can '+\
|
||||
'add RTT_RTGUI in environment to point RTGUI source code, or '+\
|
||||
'disable RT_USING_RTGUI in rtconfig.h'
|
||||
exit(-1);
|
||||
|
||||
if GetDepend('RT_USING_TC'):
|
||||
objs = objs + SConscript(RTT_ROOT + '/examples/kernel/SConscript', variant_dir = 'build/tc/kernel', duplicate=0)
|
||||
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
|
||||
|
||||
def ObjRemove(objs, remove):
|
||||
for item in objs:
|
||||
|
||||
@@ -40,10 +40,6 @@ void rt_init_thread_entry(void *parameter)
|
||||
rt_hw_sdl_start();
|
||||
#endif /* RT_USING_RTGUI */
|
||||
|
||||
#if defined(RT_USING_COMPONENTS_INIT) && defined(__GNUC__) && defined(RT_USING_FINSH)
|
||||
finsh_set_device(RT_CONSOLE_DEVICE_NAME);
|
||||
#endif
|
||||
|
||||
/* File system Initialization */
|
||||
#ifdef RT_USING_DFS
|
||||
{
|
||||
@@ -94,17 +90,6 @@ void rt_init_thread_entry(void *parameter)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void rt_test_thread_entry(void *parameter)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 5; i++)
|
||||
{
|
||||
rt_kprintf("hello, world\n");
|
||||
rt_thread_delay(RT_TICK_PER_SECOND);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int rt_application_init()
|
||||
{
|
||||
rt_thread_t tid;
|
||||
@@ -116,12 +101,6 @@ int rt_application_init()
|
||||
if (tid != RT_NULL)
|
||||
rt_thread_startup(tid);
|
||||
|
||||
tid = rt_thread_create("test",
|
||||
rt_test_thread_entry, RT_NULL,
|
||||
2048, RT_THREAD_PRIORITY_MAX * 3 / 4, 20);
|
||||
if (tid != RT_NULL)
|
||||
rt_thread_startup(tid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+21
-45
@@ -1,9 +1,10 @@
|
||||
说明: 本BSP可以如下演示
|
||||
依赖软件包
|
||||
python2.7 (python2.6使用scons --target=vs -s生成工程会出现错误)
|
||||
python2.7 (python2.6无法生成vs工程)
|
||||
|
||||
一 平台及组件支持
|
||||
目前rtconfig.py中支持的编译器有
|
||||
|
||||
1). msvc 用于windows平台
|
||||
此平台支持的组件
|
||||
kernel
|
||||
@@ -24,38 +25,21 @@
|
||||
DFS, ELM FatFS, UFFS
|
||||
RTGUI
|
||||
|
||||
请根据自己的实际情况,修改rtconfig.py中CROSS_TOOL为上述某一值。
|
||||
|
||||
二 组件配置
|
||||
1) RTGUI
|
||||
当前代码中已经不含RTGUI源码,因此读者需要配置一下才能在simulator中使用RTGUI
|
||||
RTGUI的最新源码目前是托管在github上:https://github.com/RT-Thread/RTGUI
|
||||
共有两种方法。
|
||||
方法1 添加环境变量
|
||||
向系统加入RTT_RTGUI环境变量,其值为刚才github上下载的rtgui源码包的路径。
|
||||
例如笔者的rtgui源码包解压至 F:\Project\git\rt-gui\下, 则将此环境变量配置为 F:\Project\git\rt-gui\components\rtgui
|
||||
方法2 不添加环境变量
|
||||
打开SConstruct文件,
|
||||
....
|
||||
10 if os.getenv('RTT_RTGUI'):
|
||||
11 RTT_RTGUI = os.getenv('RTT_RTGUI')
|
||||
12 else:
|
||||
13 # set the rtgui root directory by hand
|
||||
14 # empty string means use the RTGUI in svn
|
||||
15 # RTT_RTGUI = os.path.normpath(r'F:\Project\git\rt-gui\components\rtgui')
|
||||
16 RTT_RTGUI =''
|
||||
....
|
||||
将15,16行修改为
|
||||
14 # empty string means use the RTGUI in svn
|
||||
15 RTT_RTGUI = os.path.normpath(r'F:\Project\git\rt-gui\components\rtgui')
|
||||
16 # RTT_RTGUI =''
|
||||
简单说明一下:
|
||||
1)#号表示注释,类似于c语言中的//,
|
||||
2)其中15行的路径为你的RTGUI路径源码,注意不是压缩包路径,而是压缩包路径下的 components\rtgui目录的绝对路径。
|
||||
RTGUI的最新源码目前托管在github上:https://github.com/RT-Thread/RTGUI
|
||||
下载最新的RTGUI源码,将RTGUI源码包中components下的rtgui目录复制到Rt-thread的components目录下。
|
||||
|
||||
三 编译
|
||||
1) 使用Visual Studio(2005以上版本)
|
||||
在当前目录中打开cmd,输入命令
|
||||
`scons --target=vs -s`
|
||||
可以生成project.vsproj,双击运行
|
||||
生成vs2005的project.vsproj,使用vs2005及以上版本可以打开(VS2005需要转换工程)。
|
||||
|
||||
或直接生成vs2012工程
|
||||
`scons --target=vs2012 -s`
|
||||
|
||||
2) 命令行编译
|
||||
修改rtconfig.py, 配置合适的编译器(msvc/mingw/gcc),及其路径
|
||||
@@ -73,31 +57,23 @@ RTGUI的最新源码目前是托管在github上:https://github.com/RT-Thread/R
|
||||
按下回车,出现finsh,然后输入`mkfs("elm", "sd0")`格式化SD卡,如下所示
|
||||
finsh>>mkfs("elm", "sd0")
|
||||
0, 0x00000000
|
||||
然后重启程序,就可以看到fatfs挂载成功了
|
||||
重启程序,可以正确挂载fat文件系统。
|
||||
|
||||
2) 测试RTGUI
|
||||
启动后就会看到GUI窗口,分辨率800x480,此时在finsh中输入snake_main()并回车,即可运行贪吃蛇程序
|
||||
打开RTGUI组件后编译,启动在finsh中输入snake_main()并回车,可运行贪吃蛇程序
|
||||
|
||||
3) 测试APP module
|
||||
rtconfig.h中需要打开RT_USING_MODULE
|
||||
在rtconfig.h中打开RT_USING_MODULE
|
||||
|
||||
测试app module需要执行3步,如下a, b, c所示。
|
||||
|
||||
a. 生成rtthread.def文件
|
||||
使用msv编译主程序时需要此文件,使用MingW编译主程序时不需要
|
||||
msvc需要此文件才能生成正确导出符号的rtthread.dll和rtthread-win32.exe。
|
||||
此目录下默认自带了一个rtthread.def文件,当修改了rtconfig.h,禁用了某些组件时,则需要重新生成rtthread.def文件.
|
||||
生成方法:
|
||||
需要借助MingW工具,修改rtconfig.py中CROSS_TOOL为'mingw',然后打开CMD执行`scons --def`就会自动更新rtthread.def。
|
||||
执行`scons --def`可以自动生成rtthread.def。
|
||||
当修改了rtconfig.h,打开或禁用了某些组件时,需要重新生成rtthread.def文件.
|
||||
|
||||
b. 生成主程序
|
||||
主程序可以使用msvc和mingw生成
|
||||
如果rtconfig.h中的使能了RTGUI,则需要参考第二节第1小节配置RTGUI
|
||||
a.1 使用msvc
|
||||
修改rtconfig.py中CROSS_TOOL为'msvc'
|
||||
首先要保证当前目录下有合适的rtthread.def文件,如果没有对默认的rtconfig.h作修改,则使用默认的rtthread.def即可
|
||||
CMD命令行执行`scons -j4`,即可生成rtthread.dll和 rtthread-win32.exe
|
||||
a.2 使用mingw
|
||||
修改rtconfig.py中CROSS_TOOL为'mingw'
|
||||
CMD命令行执行`scons -j4`,这就会生成 rtthread.dll和 rtthread-win32.exe
|
||||
|
||||
`scons -j4`
|
||||
|
||||
c. 生成app module
|
||||
进入testdll目录,再次修改 testdll/SConstruct, 同样需要配置RTT_RTGUI路径,同 1中3)
|
||||
@@ -107,8 +83,8 @@ c. 生成app module
|
||||
|
||||
然后运行simulator目录下的 rtthread-win32.exe, 在finsh中运行
|
||||
`exec("/testdll/basicapp/build/basicapp.dll")`
|
||||
如果觉得这个路径太长,就把 basicapp.dll复制到 simualtor目录下,执行
|
||||
如果觉得这个路径太长,可以将basicapp.dll复制到 simualtor目录下,执行
|
||||
`exec("/basicapp.dll")`
|
||||
|
||||
编译贪吃蛇程序
|
||||
执行`scons --app=snake`,就会在snake/build/下生成snake.dll,按照同样的方式加载即可
|
||||
执行`scons --app=snake`,会在snake/build/下生成snake.dll,按照同样的方式加载即可
|
||||
|
||||
@@ -209,7 +209,7 @@
|
||||
#define RT_LWIP_TCP_WND 8192
|
||||
|
||||
/* SECTION: RT-Thread/GUI */
|
||||
#define RT_USING_RTGUI
|
||||
/* #define RT_USING_RTGUI */
|
||||
|
||||
/* name length of RTGUI object */
|
||||
#define RTGUI_NAME_MAX 12
|
||||
|
||||
@@ -108,12 +108,8 @@
|
||||
#if _MAX_SS != 512 && _MAX_SS != 1024 && _MAX_SS != 2048 && _MAX_SS != 4096
|
||||
#error Wrong sector size.
|
||||
#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 */
|
||||
#if _FS_REENTRANT
|
||||
@@ -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 */
|
||||
if (stat & STA_NOINIT) /* Check if the initialization succeeded */
|
||||
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)
|
||||
return FR_DISK_ERR;
|
||||
#endif
|
||||
|
||||
#if !_FS_READONLY
|
||||
if (chk_wp && (stat & STA_PROTECT)) /* Check disk write protection if needed */
|
||||
return FR_WRITE_PROTECTED;
|
||||
@@ -3601,10 +3598,10 @@ FRESULT f_mkfs (
|
||||
stat = disk_initialize(drv);
|
||||
if (stat & STA_NOINIT) return FR_NOT_READY;
|
||||
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)
|
||||
return FR_DISK_ERR;
|
||||
#endif
|
||||
|
||||
if (disk_ioctl(drv, GET_SECTOR_COUNT, &n_vol) != RES_OK || n_vol < 128)
|
||||
return FR_DISK_ERR;
|
||||
b_vol = (sfd) ? 0 : 63; /* Volume start sector */
|
||||
|
||||
@@ -84,9 +84,7 @@ typedef struct {
|
||||
BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */
|
||||
WORD id; /* File system mount ID */
|
||||
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
|
||||
#if _MAX_SS != 512
|
||||
WORD ssize; /* Bytes per sector (512,1024,2048,4096) */
|
||||
#endif
|
||||
#if _FS_REENTRANT
|
||||
_SYNC_t sobj; /* Identifier of sync object */
|
||||
#endif
|
||||
|
||||
+136
-181
File diff suppressed because it is too large
Load Diff
+47
-47
@@ -1,70 +1,70 @@
|
||||
#include <rtthread.h>
|
||||
#include <rthw.h>
|
||||
|
||||
#define CPU_USAGE_CALC_TICK 10
|
||||
#define CPU_USAGE_LOOP 100
|
||||
#define CPU_USAGE_CALC_TICK 10
|
||||
#define CPU_USAGE_LOOP 100
|
||||
|
||||
static rt_uint8_t cpu_usage_major = 0, cpu_usage_minor= 0;
|
||||
static rt_uint32_t total_count = 0;
|
||||
|
||||
static void cpu_usage_idle_hook()
|
||||
{
|
||||
rt_tick_t tick;
|
||||
rt_uint32_t count;
|
||||
volatile rt_uint32_t loop;
|
||||
rt_tick_t tick;
|
||||
rt_uint32_t count;
|
||||
volatile rt_uint32_t loop;
|
||||
|
||||
if (total_count == 0)
|
||||
{
|
||||
/* get total count */
|
||||
rt_enter_critical();
|
||||
tick = rt_tick_get();
|
||||
while(rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
|
||||
{
|
||||
total_count ++;
|
||||
loop = 0;
|
||||
while (loop < CPU_USAGE_LOOP) loop ++;
|
||||
}
|
||||
rt_exit_critical();
|
||||
}
|
||||
if (total_count == 0)
|
||||
{
|
||||
/* get total count */
|
||||
rt_enter_critical();
|
||||
tick = rt_tick_get();
|
||||
while(rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
|
||||
{
|
||||
total_count ++;
|
||||
loop = 0;
|
||||
while (loop < CPU_USAGE_LOOP) loop ++;
|
||||
}
|
||||
rt_exit_critical();
|
||||
}
|
||||
|
||||
count = 0;
|
||||
/* get CPU usage */
|
||||
tick = rt_tick_get();
|
||||
while (rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
|
||||
{
|
||||
count ++;
|
||||
loop = 0;
|
||||
while (loop < CPU_USAGE_LOOP) loop ++;
|
||||
}
|
||||
count = 0;
|
||||
/* get CPU usage */
|
||||
tick = rt_tick_get();
|
||||
while (rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
|
||||
{
|
||||
count ++;
|
||||
loop = 0;
|
||||
while (loop < CPU_USAGE_LOOP) loop ++;
|
||||
}
|
||||
|
||||
/* calculate major and minor */
|
||||
if (count < total_count)
|
||||
{
|
||||
count = total_count - count;
|
||||
cpu_usage_major = (count * 100) / total_count;
|
||||
cpu_usage_minor = ((count * 100) % total_count) * 100 / total_count;
|
||||
}
|
||||
else
|
||||
{
|
||||
total_count = count;
|
||||
/* calculate major and minor */
|
||||
if (count < total_count)
|
||||
{
|
||||
count = total_count - count;
|
||||
cpu_usage_major = (count * 100) / total_count;
|
||||
cpu_usage_minor = ((count * 100) % total_count) * 100 / total_count;
|
||||
}
|
||||
else
|
||||
{
|
||||
total_count = count;
|
||||
|
||||
/* no CPU usage */
|
||||
cpu_usage_major = 0;
|
||||
cpu_usage_minor = 0;
|
||||
}
|
||||
/* no CPU usage */
|
||||
cpu_usage_major = 0;
|
||||
cpu_usage_minor = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void cpu_usage_get(rt_uint8_t *major, rt_uint8_t *minor)
|
||||
{
|
||||
RT_ASSERT(major != RT_NULL);
|
||||
RT_ASSERT(minor != RT_NULL);
|
||||
RT_ASSERT(major != RT_NULL);
|
||||
RT_ASSERT(minor != RT_NULL);
|
||||
|
||||
*major = cpu_usage_major;
|
||||
*minor = cpu_usage_minor;
|
||||
*major = cpu_usage_major;
|
||||
*minor = cpu_usage_minor;
|
||||
}
|
||||
|
||||
void cpu_usage_init()
|
||||
{
|
||||
/* set idle thread hook */
|
||||
rt_thread_idle_sethook(cpu_usage_idle_hook);
|
||||
/* set idle thread hook */
|
||||
rt_thread_idle_sethook(cpu_usage_idle_hook);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,66 +7,68 @@
|
||||
|
||||
static rt_bool_t mem_check(rt_uint8_t *ptr, rt_uint8_t value, rt_uint32_t len)
|
||||
{
|
||||
while (len)
|
||||
{
|
||||
if (*ptr != value) return RT_FALSE;
|
||||
while (len)
|
||||
{
|
||||
if (*ptr != value)
|
||||
return RT_FALSE;
|
||||
ptr ++;
|
||||
len --;
|
||||
}
|
||||
|
||||
ptr ++;
|
||||
len --;
|
||||
}
|
||||
|
||||
return RT_TRUE;
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
static void heap_malloc_init()
|
||||
{
|
||||
rt_uint8_t *ptr1, *ptr2, *ptr3, *ptr4, *ptr5;
|
||||
rt_uint8_t res = TC_STAT_PASSED;
|
||||
rt_uint8_t *ptr1, *ptr2, *ptr3, *ptr4, *ptr5;
|
||||
|
||||
ptr1 = rt_malloc(1);
|
||||
ptr2 = rt_malloc(13);
|
||||
ptr3 = rt_malloc(31);
|
||||
ptr4 = rt_malloc(127);
|
||||
ptr5 = rt_malloc(0);
|
||||
ptr1 = rt_malloc(1);
|
||||
ptr2 = rt_malloc(13);
|
||||
ptr3 = rt_malloc(31);
|
||||
ptr4 = rt_malloc(127);
|
||||
ptr5 = rt_malloc(0);
|
||||
|
||||
memset(ptr1, 1, 1);
|
||||
memset(ptr2, 2, 13);
|
||||
memset(ptr3, 3, 31);
|
||||
memset(ptr4, 4, 127);
|
||||
memset(ptr1, 1, 1);
|
||||
memset(ptr2, 2, 13);
|
||||
memset(ptr3, 3, 31);
|
||||
memset(ptr4, 4, 127);
|
||||
|
||||
if (mem_check(ptr1, 1, 1) != RT_FALSE) goto _failed;
|
||||
if (mem_check(ptr2, 2, 13) != RT_FALSE) goto _failed;
|
||||
if (mem_check(ptr3, 3, 31) != RT_FALSE) goto _failed;
|
||||
if (mem_check(ptr4, 4, 127) != RT_FALSE) goto _failed;
|
||||
if (mem_check(ptr1, 1, 1) == RT_FALSE)
|
||||
res = TC_STAT_FAILED;
|
||||
if (mem_check(ptr2, 2, 13) == RT_FALSE)
|
||||
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(ptr3);
|
||||
rt_free(ptr3);
|
||||
rt_free(ptr1);
|
||||
rt_free(ptr4);
|
||||
rt_free(ptr3);
|
||||
rt_free(ptr2);
|
||||
rt_free(ptr1);
|
||||
|
||||
if (ptr5 != RT_NULL)
|
||||
{
|
||||
rt_free(ptr5);
|
||||
}
|
||||
if (ptr5 != RT_NULL)
|
||||
{
|
||||
rt_free(ptr5);
|
||||
}
|
||||
|
||||
tc_done(TC_STAT_PASSED);
|
||||
|
||||
_failed:
|
||||
tc_done(TC_STAT_FAILED);
|
||||
tc_done(res);
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
int _tc_heap_malloc()
|
||||
{
|
||||
heap_malloc_init();
|
||||
heap_malloc_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(_tc_heap_malloc, a heap malloc test);
|
||||
#else
|
||||
int rt_application_init()
|
||||
{
|
||||
heap_malloc_init();
|
||||
heap_malloc_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -7,77 +7,96 @@
|
||||
|
||||
static rt_bool_t mem_check(rt_uint8_t *ptr, rt_uint8_t value, rt_uint32_t len)
|
||||
{
|
||||
while (len)
|
||||
{
|
||||
if (*ptr != value) return RT_FALSE;
|
||||
while (len)
|
||||
{
|
||||
if (*ptr != value) return RT_FALSE;
|
||||
|
||||
ptr ++;
|
||||
len --;
|
||||
}
|
||||
ptr ++;
|
||||
len --;
|
||||
}
|
||||
|
||||
return RT_TRUE;
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
static void heap_realloc_init()
|
||||
{
|
||||
rt_uint8_t *ptr1, *ptr2, *ptr3, *ptr4, *ptr5;
|
||||
rt_uint8_t res = TC_STAT_PASSED;
|
||||
rt_uint8_t *ptr1, *ptr2, *ptr3, *ptr4, *ptr5;
|
||||
|
||||
ptr1 = rt_malloc(1);
|
||||
ptr2 = rt_malloc(13);
|
||||
ptr3 = rt_malloc(31);
|
||||
ptr4 = rt_malloc(127);
|
||||
ptr5 = rt_malloc(0);
|
||||
ptr1 = rt_malloc(1);
|
||||
ptr2 = rt_malloc(13);
|
||||
ptr3 = rt_malloc(31);
|
||||
ptr4 = rt_malloc(127);
|
||||
ptr5 = rt_malloc(0);
|
||||
|
||||
memset(ptr1, 1, 1);
|
||||
memset(ptr2, 2, 13);
|
||||
memset(ptr3, 3, 31);
|
||||
memset(ptr4, 4, 127);
|
||||
memset(ptr1, 1, 1);
|
||||
memset(ptr2, 2, 13);
|
||||
memset(ptr3, 3, 31);
|
||||
memset(ptr4, 4, 127);
|
||||
|
||||
if (mem_check(ptr1, 1, 1) != RT_FALSE) goto _failed;
|
||||
if (mem_check(ptr2, 2, 13) != RT_FALSE) goto _failed;
|
||||
if (mem_check(ptr3, 3, 31) != RT_FALSE) goto _failed;
|
||||
if (mem_check(ptr4, 4, 127) != RT_FALSE) goto _failed;
|
||||
if (mem_check(ptr1, 1, 1) == RT_FALSE)
|
||||
{
|
||||
res = TC_STAT_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);
|
||||
ptr2 = rt_realloc(ptr2, 31);
|
||||
ptr3 = rt_realloc(ptr3, 127);
|
||||
ptr4 = rt_realloc(ptr4, 1);
|
||||
ptr5 = rt_realloc(ptr5, 0);
|
||||
ptr1 = rt_realloc(ptr1, 13);
|
||||
ptr2 = rt_realloc(ptr2, 31);
|
||||
ptr3 = rt_realloc(ptr3, 127);
|
||||
ptr4 = rt_realloc(ptr4, 1);
|
||||
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(ptr2, 2, 13) != RT_FALSE) goto _failed;
|
||||
if (mem_check(ptr3, 3, 31) != RT_FALSE) goto _failed;
|
||||
if (mem_check(ptr4, 4, 1) != RT_FALSE) goto _failed;
|
||||
if (mem_check(ptr1, 1, 1) == RT_FALSE)
|
||||
res = TC_STAT_FAILED;
|
||||
if (mem_check(ptr2, 2, 13) == RT_FALSE)
|
||||
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;
|
||||
|
||||
rt_free(ptr4);
|
||||
rt_free(ptr3);
|
||||
rt_free(ptr3);
|
||||
rt_free(ptr1);
|
||||
_free:
|
||||
rt_free(ptr4);
|
||||
rt_free(ptr3);
|
||||
rt_free(ptr2);
|
||||
rt_free(ptr1);
|
||||
|
||||
if (ptr5 != RT_NULL)
|
||||
{
|
||||
rt_free(ptr5);
|
||||
}
|
||||
|
||||
tc_done(TC_STAT_PASSED);
|
||||
|
||||
_failed:
|
||||
tc_done(TC_STAT_FAILED);
|
||||
tc_done(res);
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
int _tc_heap_realloc()
|
||||
{
|
||||
heap_realloc_init();
|
||||
heap_realloc_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(_tc_heap_realloc, a heap re-malloc test);
|
||||
#else
|
||||
int rt_application_init()
|
||||
{
|
||||
heap_realloc_init();
|
||||
heap_realloc_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -22,110 +22,110 @@ static char mb_str2[] = "this is another mail!";
|
||||
/* 线程1入口 */
|
||||
static void thread1_entry(void* parameter)
|
||||
{
|
||||
unsigned char* str;
|
||||
unsigned char* str;
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* 从邮箱中收取邮件 */
|
||||
if (rt_mb_recv(&mb, (rt_uint32_t*)&str, RT_WAITING_FOREVER) == RT_EOK)
|
||||
{
|
||||
rt_kprintf("thread1: get a mail from mailbox, the content:%s\n", str);
|
||||
while (1)
|
||||
{
|
||||
/* 从邮箱中收取邮件 */
|
||||
if (rt_mb_recv(&mb, (rt_uint32_t*)&str, RT_WAITING_FOREVER) == RT_EOK)
|
||||
{
|
||||
rt_kprintf("thread1: get a mail from mailbox, the content:%s\n", str);
|
||||
|
||||
/* 延时20个OS Tick */
|
||||
rt_thread_delay(50);
|
||||
}
|
||||
}
|
||||
/* 延时20个OS Tick */
|
||||
rt_thread_delay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 线程2入口 */
|
||||
static void thread2_entry(void* parameter)
|
||||
{
|
||||
rt_uint8_t count;
|
||||
rt_uint8_t count;
|
||||
char *str;
|
||||
|
||||
count = 0;
|
||||
while (1)
|
||||
{
|
||||
count ++;
|
||||
if (count & 0x1)
|
||||
{
|
||||
/* 发送mb_str1地址到邮箱中 */
|
||||
count = 0;
|
||||
while (1)
|
||||
{
|
||||
count ++;
|
||||
if (count & 0x1)
|
||||
{
|
||||
/* 发送mb_str1地址到邮箱中 */
|
||||
str = mb_str1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 发送mb_str2地址到邮箱中 */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 发送mb_str2地址到邮箱中 */
|
||||
str = mb_str2;
|
||||
}
|
||||
}
|
||||
|
||||
/* 不停的发送邮件,如果满了则等待10个tick,然后超时 */
|
||||
if( rt_mb_send_wait(&mb, (rt_uint32_t)str,10) == RT_EOK )
|
||||
rt_kprintf("thread2: sent a mail to mailbox, the content:%s\n", str);
|
||||
else
|
||||
rt_kprintf("thread2: timeout while waiting to send a mail.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int mbox_send_wait_init()
|
||||
{
|
||||
/* 初始化一个mailbox */
|
||||
rt_mb_init(&mb,
|
||||
"mbt", /* 名称是mbt */
|
||||
&mb_pool[0], /* 邮箱用到的内存池是mb_pool */
|
||||
sizeof(mb_pool)/4, /* 大小是mb_pool大小除以4,因为一封邮件的大小是4字节 */
|
||||
RT_IPC_FLAG_FIFO); /* 采用FIFO方式进行线程等待 */
|
||||
/* 初始化一个mailbox */
|
||||
rt_mb_init(&mb,
|
||||
"mbt", /* 名称是mbt */
|
||||
&mb_pool[0], /* 邮箱用到的内存池是mb_pool */
|
||||
sizeof(mb_pool)/4, /* 大小是mb_pool大小除以4,因为一封邮件的大小是4字节 */
|
||||
RT_IPC_FLAG_FIFO); /* 采用FIFO方式进行线程等待 */
|
||||
|
||||
/* 创建线程1 */
|
||||
tid1 = rt_thread_create("t1",
|
||||
thread1_entry, RT_NULL, /* 线程入口是thread1_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid1 != RT_NULL)
|
||||
rt_thread_startup(tid1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 创建线程1 */
|
||||
tid1 = rt_thread_create("t1",
|
||||
thread1_entry, RT_NULL, /* 线程入口是thread1_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid1 != RT_NULL)
|
||||
rt_thread_startup(tid1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
/* 创建线程2 */
|
||||
tid2 = rt_thread_create("t2",
|
||||
thread2_entry, RT_NULL, /* 线程入口是thread2_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid2 != RT_NULL)
|
||||
rt_thread_startup(tid2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 创建线程2 */
|
||||
tid2 = rt_thread_create("t2",
|
||||
thread2_entry, RT_NULL, /* 线程入口是thread2_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid2 != RT_NULL)
|
||||
rt_thread_startup(tid2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup()
|
||||
{
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
|
||||
/* 删除线程 */
|
||||
if (tid1 != RT_NULL && tid1->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid1);
|
||||
if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid2);
|
||||
/* 删除线程 */
|
||||
if (tid1 != RT_NULL && tid1->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid1);
|
||||
if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid2);
|
||||
|
||||
/* 执行邮箱对象脱离 */
|
||||
rt_mb_detach(&mb);
|
||||
/* 执行邮箱对象脱离 */
|
||||
rt_mb_detach(&mb);
|
||||
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int _tc_mbox_send_wait()
|
||||
{
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
mbox_send_wait_init();
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
mbox_send_wait_init();
|
||||
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 300;
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 300;
|
||||
}
|
||||
/* 输出函数命令到finsh shell中 */
|
||||
FINSH_FUNCTION_EXPORT(_tc_mbox_send_wait, a example of mailbox send wait);
|
||||
@@ -133,9 +133,9 @@ FINSH_FUNCTION_EXPORT(_tc_mbox_send_wait, a example of mailbox send wait);
|
||||
/* 用户应用入口 */
|
||||
int rt_application_init()
|
||||
{
|
||||
mbox_send_wait_init();
|
||||
mbox_send_wait_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -22,108 +22,108 @@ static char mb_str2[] = "this is another mail!";
|
||||
/* 线程1入口 */
|
||||
static void thread1_entry(void* parameter)
|
||||
{
|
||||
unsigned char* str;
|
||||
unsigned char* str;
|
||||
|
||||
while (1)
|
||||
{
|
||||
rt_kprintf("thread1: try to recv a mail\n");
|
||||
while (1)
|
||||
{
|
||||
rt_kprintf("thread1: try to recv a mail\n");
|
||||
|
||||
/* 从邮箱中收取邮件 */
|
||||
if (rt_mb_recv(&mb, (rt_uint32_t*)&str, RT_WAITING_FOREVER) == RT_EOK)
|
||||
{
|
||||
rt_kprintf("thread1: get a mail from mailbox, the content:%s\n", str);
|
||||
/* 从邮箱中收取邮件 */
|
||||
if (rt_mb_recv(&mb, (rt_uint32_t*)&str, RT_WAITING_FOREVER) == RT_EOK)
|
||||
{
|
||||
rt_kprintf("thread1: get a mail from mailbox, the content:%s\n", str);
|
||||
|
||||
/* 延时10个OS Tick */
|
||||
rt_thread_delay(10);
|
||||
}
|
||||
}
|
||||
/* 延时10个OS Tick */
|
||||
rt_thread_delay(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 线程2入口 */
|
||||
static void thread2_entry(void* parameter)
|
||||
{
|
||||
rt_uint8_t count;
|
||||
rt_uint8_t count;
|
||||
|
||||
count = 0;
|
||||
while (1)
|
||||
{
|
||||
count ++;
|
||||
if (count & 0x1)
|
||||
{
|
||||
/* 发送mb_str1地址到邮箱中 */
|
||||
rt_mb_send(&mb, (rt_uint32_t)&mb_str1[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 发送mb_str2地址到邮箱中 */
|
||||
rt_mb_send(&mb, (rt_uint32_t)&mb_str2[0]);
|
||||
}
|
||||
count = 0;
|
||||
while (1)
|
||||
{
|
||||
count ++;
|
||||
if (count & 0x1)
|
||||
{
|
||||
/* 发送mb_str1地址到邮箱中 */
|
||||
rt_mb_send(&mb, (rt_uint32_t)&mb_str1[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 发送mb_str2地址到邮箱中 */
|
||||
rt_mb_send(&mb, (rt_uint32_t)&mb_str2[0]);
|
||||
}
|
||||
|
||||
/* 延时20个OS Tick */
|
||||
rt_thread_delay(20);
|
||||
}
|
||||
/* 延时20个OS Tick */
|
||||
rt_thread_delay(20);
|
||||
}
|
||||
}
|
||||
|
||||
int mbox_simple_init()
|
||||
{
|
||||
/* 初始化一个mailbox */
|
||||
rt_mb_init(&mb,
|
||||
"mbt", /* 名称是mbt */
|
||||
&mb_pool[0], /* 邮箱用到的内存池是mb_pool */
|
||||
sizeof(mb_pool)/4, /* 大小是mb_pool大小除以4,因为一封邮件的大小是4字节 */
|
||||
RT_IPC_FLAG_FIFO); /* 采用FIFO方式进行线程等待 */
|
||||
/* 初始化一个mailbox */
|
||||
rt_mb_init(&mb,
|
||||
"mbt", /* 名称是mbt */
|
||||
&mb_pool[0], /* 邮箱用到的内存池是mb_pool */
|
||||
sizeof(mb_pool)/4, /* 大小是mb_pool大小除以4,因为一封邮件的大小是4字节 */
|
||||
RT_IPC_FLAG_FIFO); /* 采用FIFO方式进行线程等待 */
|
||||
|
||||
/* 创建线程1 */
|
||||
tid1 = rt_thread_create("t1",
|
||||
thread1_entry, RT_NULL, /* 线程入口是thread1_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid1 != RT_NULL)
|
||||
rt_thread_startup(tid1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 创建线程1 */
|
||||
tid1 = rt_thread_create("t1",
|
||||
thread1_entry, RT_NULL, /* 线程入口是thread1_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid1 != RT_NULL)
|
||||
rt_thread_startup(tid1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
/* 创建线程2 */
|
||||
tid2 = rt_thread_create("t2",
|
||||
thread2_entry, RT_NULL, /* 线程入口是thread2_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid2 != RT_NULL)
|
||||
rt_thread_startup(tid2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 创建线程2 */
|
||||
tid2 = rt_thread_create("t2",
|
||||
thread2_entry, RT_NULL, /* 线程入口是thread2_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid2 != RT_NULL)
|
||||
rt_thread_startup(tid2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup()
|
||||
{
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
|
||||
/* 删除线程 */
|
||||
if (tid1 != RT_NULL && tid1->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid1);
|
||||
if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid2);
|
||||
/* 删除线程 */
|
||||
if (tid1 != RT_NULL && tid1->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid1);
|
||||
if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid2);
|
||||
|
||||
/* 执行邮箱对象脱离 */
|
||||
rt_mb_detach(&mb);
|
||||
/* 执行邮箱对象脱离 */
|
||||
rt_mb_detach(&mb);
|
||||
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int _tc_mbox_simple()
|
||||
{
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
mbox_simple_init();
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
mbox_simple_init();
|
||||
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
}
|
||||
/* 输出函数命令到finsh shell中 */
|
||||
FINSH_FUNCTION_EXPORT(_tc_mbox_simple, a simple mailbox example);
|
||||
@@ -131,8 +131,8 @@ FINSH_FUNCTION_EXPORT(_tc_mbox_simple, a simple mailbox example);
|
||||
/* 用户应用入口 */
|
||||
int rt_application_init()
|
||||
{
|
||||
mbox_simple_init();
|
||||
mbox_simple_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -15,105 +15,112 @@ static rt_sem_t sem = RT_NULL;
|
||||
/* 线程入口 */
|
||||
static void thread_entry(void* parameter)
|
||||
{
|
||||
rt_err_t result;
|
||||
rt_tick_t tick;
|
||||
rt_err_t result;
|
||||
rt_tick_t tick;
|
||||
|
||||
/* 获得当前的OS Tick */
|
||||
tick = rt_tick_get();
|
||||
/* 获得当前的OS Tick */
|
||||
tick = rt_tick_get();
|
||||
|
||||
/* 试图持有一个信号量,如果10个OS Tick依然没拿到,则超时返回 */
|
||||
result = rt_sem_take(sem, 10);
|
||||
if (result == -RT_ETIMEOUT)
|
||||
{
|
||||
/* 判断是否刚好过去10个OS Tick */
|
||||
if (rt_tick_get() - tick != 10)
|
||||
{
|
||||
/* 如果失败,则测试失败 */
|
||||
tc_done(TC_STAT_FAILED);
|
||||
rt_sem_delete(sem);
|
||||
return;
|
||||
}
|
||||
rt_kprintf("take semaphore timeout\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 因为并没释放信号量,应该是超时返回,否则测试失败 */
|
||||
tc_done(TC_STAT_FAILED);
|
||||
rt_sem_delete(sem);
|
||||
return;
|
||||
}
|
||||
/* 试图持有一个信号量,如果10个OS Tick依然没拿到,则超时返回 */
|
||||
result = rt_sem_take(sem, 10);
|
||||
if (result == -RT_ETIMEOUT)
|
||||
{
|
||||
rt_tick_t new_tick = rt_tick_get();
|
||||
/* 可以有两个 tick 的误差 */
|
||||
if (new_tick - tick >= 12)
|
||||
{
|
||||
rt_kprintf("tick error to large: expect: 10, get %d\n",
|
||||
new_tick - tick);
|
||||
|
||||
/* 释放一次信号量 */
|
||||
rt_sem_release(sem);
|
||||
/* 如果失败,则测试失败 */
|
||||
tc_done(TC_STAT_FAILED);
|
||||
rt_sem_delete(sem);
|
||||
return;
|
||||
}
|
||||
rt_kprintf("take semaphore timeout\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 因为并没释放信号量,应该是超时返回,否则测试失败 */
|
||||
tc_done(TC_STAT_FAILED);
|
||||
rt_sem_delete(sem);
|
||||
return;
|
||||
}
|
||||
|
||||
/* 继续持有信号量,并永远等待直到持有到信号量 */
|
||||
result = rt_sem_take(sem, RT_WAITING_FOREVER);
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
/* 返回不正确,测试失败 */
|
||||
tc_done(TC_STAT_FAILED);
|
||||
rt_sem_delete(sem);
|
||||
return;
|
||||
}
|
||||
/* 释放一次信号量 */
|
||||
rt_sem_release(sem);
|
||||
|
||||
/* 测试成功 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 删除信号量 */
|
||||
rt_sem_delete(sem);
|
||||
/* 继续持有信号量,并永远等待直到持有到信号量 */
|
||||
result = rt_sem_take(sem, RT_WAITING_FOREVER);
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
/* 返回不正确,测试失败 */
|
||||
tc_done(TC_STAT_FAILED);
|
||||
rt_sem_delete(sem);
|
||||
return;
|
||||
}
|
||||
|
||||
/* 测试成功 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 删除信号量 */
|
||||
rt_sem_delete(sem);
|
||||
}
|
||||
|
||||
int semaphore_dynamic_init()
|
||||
{
|
||||
/* 创建一个信号量,初始值是0 */
|
||||
sem = rt_sem_create("sem", 0, RT_IPC_FLAG_FIFO);
|
||||
if (sem == RT_NULL)
|
||||
{
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
return 0;
|
||||
}
|
||||
/* 创建一个信号量,初始值是0 */
|
||||
sem = rt_sem_create("sem", 0, RT_IPC_FLAG_FIFO);
|
||||
if (sem == RT_NULL)
|
||||
{
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 创建线程 */
|
||||
tid = rt_thread_create("thread",
|
||||
thread_entry, RT_NULL, /* 线程入口是thread_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid != RT_NULL)
|
||||
rt_thread_startup(tid);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 创建线程 */
|
||||
tid = rt_thread_create("thread",
|
||||
thread_entry, RT_NULL, /* 线程入口是thread_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid != RT_NULL)
|
||||
rt_thread_startup(tid);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup()
|
||||
{
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
|
||||
/* 删除线程 */
|
||||
if (tid != RT_NULL && tid->stat != RT_THREAD_CLOSE)
|
||||
{
|
||||
rt_thread_delete(tid);
|
||||
if (sem)
|
||||
{
|
||||
rt_sem_delete(sem);
|
||||
sem = RT_NULL;
|
||||
}
|
||||
|
||||
/* 删除信号量 */
|
||||
rt_sem_delete(sem);
|
||||
}
|
||||
/* 删除线程 */
|
||||
if (tid != RT_NULL && tid->stat != RT_THREAD_CLOSE)
|
||||
{
|
||||
rt_thread_delete(tid);
|
||||
}
|
||||
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int _tc_semaphore_dynamic()
|
||||
{
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
semaphore_dynamic_init();
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
semaphore_dynamic_init();
|
||||
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
}
|
||||
/* 输出函数命令到finsh shell中 */
|
||||
FINSH_FUNCTION_EXPORT(_tc_semaphore_dynamic, a dynamic semaphore example);
|
||||
@@ -121,8 +128,8 @@ FINSH_FUNCTION_EXPORT(_tc_semaphore_dynamic, a dynamic semaphore example);
|
||||
/* 用户应用入口 */
|
||||
int rt_application_init()
|
||||
{
|
||||
semaphore_dynamic_init();
|
||||
semaphore_dynamic_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -17,107 +17,111 @@ static struct rt_semaphore sem;
|
||||
/* 线程入口 */
|
||||
static void thread_entry(void* parameter)
|
||||
{
|
||||
rt_err_t result;
|
||||
rt_tick_t tick;
|
||||
rt_err_t result;
|
||||
rt_tick_t tick;
|
||||
|
||||
/* 获得当前的OS Tick */
|
||||
tick = rt_tick_get();
|
||||
/* 获得当前的OS Tick */
|
||||
tick = rt_tick_get();
|
||||
|
||||
/* 试图持有信号量,最大等待10个OS Tick后返回 */
|
||||
result = rt_sem_take(&sem, 10);
|
||||
if (result == -RT_ETIMEOUT)
|
||||
{
|
||||
/* 超时后判断是否刚好是10个OS Tick */
|
||||
if (rt_tick_get() - tick != 10)
|
||||
{
|
||||
tc_done(TC_STAT_FAILED);
|
||||
rt_sem_detach(&sem);
|
||||
return;
|
||||
}
|
||||
rt_kprintf("take semaphore timeout\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 因为没有其他地方是否信号量,所以不应该成功持有信号量,否则测试失败 */
|
||||
tc_done(TC_STAT_FAILED);
|
||||
rt_sem_detach(&sem);
|
||||
return;
|
||||
}
|
||||
/* 试图持有信号量,最大等待10个OS Tick后返回 */
|
||||
result = rt_sem_take(&sem, 10);
|
||||
if (result == -RT_ETIMEOUT)
|
||||
{
|
||||
rt_tick_t new_tick = rt_tick_get();
|
||||
/* 可以有两个 tick 的误差 */
|
||||
if (new_tick - tick >= 12)
|
||||
{
|
||||
rt_kprintf("tick error to large: expect: 10, get %d\n",
|
||||
new_tick - tick);
|
||||
|
||||
/* 释放一次信号量 */
|
||||
rt_sem_release(&sem);
|
||||
tc_done(TC_STAT_FAILED);
|
||||
rt_sem_detach(&sem);
|
||||
return;
|
||||
}
|
||||
rt_kprintf("take semaphore timeout\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 因为没有其他地方是否信号量,所以不应该成功持有信号量,否则测试失败 */
|
||||
tc_done(TC_STAT_FAILED);
|
||||
rt_sem_detach(&sem);
|
||||
return;
|
||||
}
|
||||
|
||||
/* 永久等待方式持有信号量 */
|
||||
result = rt_sem_take(&sem, RT_WAITING_FOREVER);
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
/* 不成功则测试失败 */
|
||||
tc_done(TC_STAT_FAILED);
|
||||
rt_sem_detach(&sem);
|
||||
return;
|
||||
}
|
||||
/* 释放一次信号量 */
|
||||
rt_sem_release(&sem);
|
||||
|
||||
/* 测试通过 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 脱离信号量对象 */
|
||||
rt_sem_detach(&sem);
|
||||
/* 永久等待方式持有信号量 */
|
||||
result = rt_sem_take(&sem, RT_WAITING_FOREVER);
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
/* 不成功则测试失败 */
|
||||
tc_done(TC_STAT_FAILED);
|
||||
rt_sem_detach(&sem);
|
||||
return;
|
||||
}
|
||||
|
||||
/* 测试通过 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 脱离信号量对象 */
|
||||
rt_sem_detach(&sem);
|
||||
}
|
||||
|
||||
int semaphore_static_init(void)
|
||||
{
|
||||
rt_err_t result;
|
||||
rt_err_t result;
|
||||
|
||||
/* 初始化信号量,初始值是0 */
|
||||
result = rt_sem_init(&sem, "sem", 0, RT_IPC_FLAG_FIFO);
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
return 0;
|
||||
}
|
||||
/* 初始化信号量,初始值是0 */
|
||||
result = rt_sem_init(&sem, "sem", 0, RT_IPC_FLAG_FIFO);
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 初始化线程1 */
|
||||
result = rt_thread_init(&thread, "thread", /* 线程名:thread */
|
||||
thread_entry, RT_NULL, /* 线程的入口是thread_entry,入口参数是RT_NULL*/
|
||||
&thread_stack[0], sizeof(thread_stack), /* 线程栈是thread_stack */
|
||||
THREAD_PRIORITY, 10);
|
||||
if (result == RT_EOK) /* 如果返回正确,启动线程1 */
|
||||
rt_thread_startup(&thread);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 初始化线程1 */
|
||||
result = rt_thread_init(&thread, "thread", /* 线程名:thread */
|
||||
thread_entry, RT_NULL, /* 线程的入口是thread_entry,入口参数是RT_NULL*/
|
||||
&thread_stack[0], sizeof(thread_stack), /* 线程栈是thread_stack */
|
||||
THREAD_PRIORITY, 10);
|
||||
if (result == RT_EOK) /* 如果返回正确,启动线程1 */
|
||||
rt_thread_startup(&thread);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup(void)
|
||||
{
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
|
||||
/* 执行线程脱离 */
|
||||
if (thread.stat != RT_THREAD_CLOSE)
|
||||
{
|
||||
rt_thread_detach(&thread);
|
||||
/* 执行线程脱离 */
|
||||
if (thread.stat != RT_THREAD_CLOSE)
|
||||
{
|
||||
rt_thread_detach(&thread);
|
||||
|
||||
/* 执行信号量对象脱离 */
|
||||
rt_sem_detach(&sem);
|
||||
}
|
||||
/* 执行信号量对象脱离 */
|
||||
rt_sem_detach(&sem);
|
||||
}
|
||||
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int _tc_semaphore_static(void)
|
||||
{
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
semaphore_static_init();
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
semaphore_static_init();
|
||||
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
}
|
||||
/* 输出函数命令到finsh shell中 */
|
||||
FINSH_FUNCTION_EXPORT(_tc_semaphore_static, a static semaphore example);
|
||||
@@ -125,8 +129,8 @@ FINSH_FUNCTION_EXPORT(_tc_semaphore_static, a static semaphore example);
|
||||
/* 用户应用入口 */
|
||||
int rt_application_init(void)
|
||||
{
|
||||
semaphore_static_init();
|
||||
semaphore_static_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
+119
-105
File diff suppressed because it is too large
Load Diff
@@ -11,19 +11,19 @@
|
||||
#endif
|
||||
|
||||
#if RT_THREAD_PRIORITY_MAX == 8
|
||||
#define THREAD_PRIORITY 6
|
||||
#define THREAD_PRIORITY 6
|
||||
#elif RT_THREAD_PRIORITY_MAX == 32
|
||||
#define THREAD_PRIORITY 25
|
||||
#define THREAD_PRIORITY 25
|
||||
#elif RT_THREAD_PRIORITY_MAX == 256
|
||||
#define THREAD_PRIORITY 200
|
||||
#define THREAD_PRIORITY 200
|
||||
#endif
|
||||
#define THREAD_STACK_SIZE 512
|
||||
#define THREAD_TIMESLICE 5
|
||||
#define THREAD_STACK_SIZE 512
|
||||
#define THREAD_TIMESLICE 5
|
||||
|
||||
#define TC_STAT_END 0x00
|
||||
#define TC_STAT_RUNNING 0x01
|
||||
#define TC_STAT_FAILED 0x10
|
||||
#define TC_STAT_PASSED 0x00
|
||||
#define TC_STAT_END 0x00
|
||||
#define TC_STAT_RUNNING 0x01
|
||||
#define TC_STAT_FAILED 0x10
|
||||
#define TC_STAT_PASSED 0x00
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
void tc_start(const char* tc_prefix);
|
||||
|
||||
+30
-30
@@ -4,59 +4,59 @@
|
||||
static rt_thread_t tid = RT_NULL;
|
||||
static void sample_thread(void* parameter)
|
||||
{
|
||||
rt_kprintf("I'm sample!\n");
|
||||
rt_kprintf("I'm sample!\n");
|
||||
}
|
||||
static void sample_thread_cleanup(struct rt_thread *p)
|
||||
{
|
||||
tid = RT_NULL;
|
||||
tc_done(TC_STAT_PASSED);
|
||||
tid = RT_NULL;
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int sample_init()
|
||||
{
|
||||
tid = rt_thread_create("t",
|
||||
sample_thread, RT_NULL,
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid != RT_NULL)
|
||||
{
|
||||
rt_thread_startup(tid);
|
||||
tid->cleanup = sample_thread_cleanup;
|
||||
}
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
tid = rt_thread_create("t",
|
||||
sample_thread, RT_NULL,
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid != RT_NULL)
|
||||
{
|
||||
rt_thread_startup(tid);
|
||||
tid->cleanup = sample_thread_cleanup;
|
||||
}
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup()
|
||||
{
|
||||
/* lock scheduler */
|
||||
rt_enter_critical();
|
||||
/* delete thread */
|
||||
if (tid != RT_NULL)
|
||||
{
|
||||
rt_kprintf("tid1 is bad\n");
|
||||
tc_stat(TC_STAT_FAILED);
|
||||
}
|
||||
/* unlock scheduler */
|
||||
rt_exit_critical();
|
||||
/* lock scheduler */
|
||||
rt_enter_critical();
|
||||
/* delete thread */
|
||||
if (tid != RT_NULL)
|
||||
{
|
||||
rt_kprintf("tid1 is bad\n");
|
||||
tc_stat(TC_STAT_FAILED);
|
||||
}
|
||||
/* unlock scheduler */
|
||||
rt_exit_critical();
|
||||
}
|
||||
|
||||
int _tc_sample()
|
||||
{
|
||||
/* set tc cleanup */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
sample_init();
|
||||
/* set tc cleanup */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
sample_init();
|
||||
|
||||
return 25;
|
||||
return 25;
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(_tc_sample, a thread testcase example);
|
||||
#else
|
||||
int rt_application_init()
|
||||
{
|
||||
sample_init();
|
||||
sample_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -8,63 +8,63 @@ static struct rt_thread thread;
|
||||
static char thread_stack[THREAD_STACK_SIZE];
|
||||
static void thread_entry(void* parameter)
|
||||
{
|
||||
rt_tick_t tick;
|
||||
rt_kprintf("thread inited ok\n");
|
||||
rt_tick_t tick;
|
||||
rt_kprintf("thread inited ok\n");
|
||||
|
||||
rt_kprintf("thread delay 10 tick\n");
|
||||
tick = rt_tick_get();
|
||||
rt_thread_delay(10);
|
||||
if (rt_tick_get() - tick > 10)
|
||||
{
|
||||
tc_done(TC_STAT_FAILED);
|
||||
return;
|
||||
}
|
||||
rt_kprintf("thread delay 10 tick\n");
|
||||
tick = rt_tick_get();
|
||||
rt_thread_delay(10);
|
||||
if (rt_tick_get() - tick > 11)
|
||||
{
|
||||
tc_done(TC_STAT_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
rt_kprintf("thread delay 15 tick\n");
|
||||
tick = rt_tick_get();
|
||||
rt_thread_delay(15);
|
||||
if (rt_tick_get() - tick > 15)
|
||||
{
|
||||
tc_done(TC_STAT_FAILED);
|
||||
return;
|
||||
}
|
||||
rt_kprintf("thread delay 15 tick\n");
|
||||
tick = rt_tick_get();
|
||||
rt_thread_delay(15);
|
||||
if (rt_tick_get() - tick > 16)
|
||||
{
|
||||
tc_done(TC_STAT_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
rt_kprintf("thread exit\n");
|
||||
rt_kprintf("thread exit\n");
|
||||
|
||||
tc_done(TC_STAT_PASSED);
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
rt_err_t thread_delay_init()
|
||||
{
|
||||
rt_err_t result;
|
||||
rt_err_t result;
|
||||
|
||||
result = rt_thread_init(&thread,
|
||||
"test",
|
||||
thread_entry, RT_NULL,
|
||||
&thread_stack[0], sizeof(thread_stack),
|
||||
THREAD_PRIORITY, 10);
|
||||
result = rt_thread_init(&thread,
|
||||
"test",
|
||||
thread_entry, RT_NULL,
|
||||
&thread_stack[0], sizeof(thread_stack),
|
||||
THREAD_PRIORITY, 10);
|
||||
|
||||
if (result == RT_EOK)
|
||||
rt_thread_startup(&thread);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
if (result == RT_EOK)
|
||||
rt_thread_startup(&thread);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
int _tc_thread_delay()
|
||||
{
|
||||
thread_delay_init();
|
||||
thread_delay_init();
|
||||
|
||||
return 30;
|
||||
return 30;
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(_tc_thread_delay, a thread delay test);
|
||||
#else
|
||||
int rt_application_init()
|
||||
{
|
||||
thread_delay_init();
|
||||
thread_delay_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,92 +18,92 @@ static rt_uint8_t thread2_stack[THREAD_STACK_SIZE];
|
||||
/* 线程1入口 */
|
||||
static void thread1_entry(void* parameter)
|
||||
{
|
||||
rt_uint32_t count = 0;
|
||||
rt_uint32_t count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* 线程1采用低优先级运行,一直打印计数值 */
|
||||
rt_kprintf("thread count: %d\n", count ++);
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
/* 线程1采用低优先级运行,一直打印计数值 */
|
||||
rt_kprintf("thread count: %d\n", count ++);
|
||||
}
|
||||
}
|
||||
|
||||
/* 线程2入口 */
|
||||
static void thread2_entry(void* parameter)
|
||||
{
|
||||
/* 线程2拥有较高的优先级,以抢占线程1而获得执行 */
|
||||
/* 线程2拥有较高的优先级,以抢占线程1而获得执行 */
|
||||
|
||||
/* 线程2启动后先睡眠10个OS Tick */
|
||||
rt_thread_delay(10);
|
||||
/* 线程2启动后先睡眠10个OS Tick */
|
||||
rt_thread_delay(10);
|
||||
|
||||
/*
|
||||
* 线程2唤醒后直接执行线程1脱离,线程1将从就绪线程队列中删除
|
||||
*/
|
||||
rt_thread_detach(&thread1);
|
||||
/*
|
||||
* 线程2唤醒后直接执行线程1脱离,线程1将从就绪线程队列中删除
|
||||
*/
|
||||
rt_thread_detach(&thread1);
|
||||
|
||||
/*
|
||||
* 线程2继续休眠10个OS Tick然后退出
|
||||
*/
|
||||
rt_thread_delay(10);
|
||||
/*
|
||||
* 线程2继续休眠10个OS Tick然后退出
|
||||
*/
|
||||
rt_thread_delay(10);
|
||||
|
||||
/*
|
||||
* 线程2运行结束后也将自动被从就绪队列中删除,并脱离线程队列
|
||||
*/
|
||||
/*
|
||||
* 线程2运行结束后也将自动被从就绪队列中删除,并脱离线程队列
|
||||
*/
|
||||
}
|
||||
|
||||
int thread_detach_init()
|
||||
{
|
||||
rt_err_t result;
|
||||
rt_err_t result;
|
||||
|
||||
/* 初始化线程1 */
|
||||
result = rt_thread_init(&thread1, "t1", /* 线程名:t1 */
|
||||
thread1_entry, RT_NULL, /* 线程的入口是thread1_entry,入口参数是RT_NULL*/
|
||||
&thread1_stack[0], sizeof(thread1_stack), /* 线程栈是thread1_stack */
|
||||
THREAD_PRIORITY, 10);
|
||||
if (result == RT_EOK) /* 如果返回正确,启动线程1 */
|
||||
rt_thread_startup(&thread1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 初始化线程1 */
|
||||
result = rt_thread_init(&thread1, "t1", /* 线程名:t1 */
|
||||
thread1_entry, RT_NULL, /* 线程的入口是thread1_entry,入口参数是RT_NULL*/
|
||||
&thread1_stack[0], sizeof(thread1_stack), /* 线程栈是thread1_stack */
|
||||
THREAD_PRIORITY, 10);
|
||||
if (result == RT_EOK) /* 如果返回正确,启动线程1 */
|
||||
rt_thread_startup(&thread1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
/* 初始化线程2 */
|
||||
result = rt_thread_init(&thread2, "t2", /* 线程名:t2 */
|
||||
thread2_entry, RT_NULL, /* 线程的入口是thread2_entry,入口参数是RT_NULL*/
|
||||
&thread2_stack[0], sizeof(thread2_stack), /* 线程栈是thread2_stack */
|
||||
THREAD_PRIORITY - 1, 10);
|
||||
if (result == RT_EOK) /* 如果返回正确,启动线程2 */
|
||||
rt_thread_startup(&thread2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 初始化线程2 */
|
||||
result = rt_thread_init(&thread2, "t2", /* 线程名:t2 */
|
||||
thread2_entry, RT_NULL, /* 线程的入口是thread2_entry,入口参数是RT_NULL*/
|
||||
&thread2_stack[0], sizeof(thread2_stack), /* 线程栈是thread2_stack */
|
||||
THREAD_PRIORITY - 1, 10);
|
||||
if (result == RT_EOK) /* 如果返回正确,启动线程2 */
|
||||
rt_thread_startup(&thread2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup()
|
||||
{
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
|
||||
/* 执行线程脱离 */
|
||||
if (thread1.stat != RT_THREAD_CLOSE)
|
||||
rt_thread_detach(&thread1);
|
||||
if (thread2.stat != RT_THREAD_CLOSE)
|
||||
rt_thread_detach(&thread2);
|
||||
/* 执行线程脱离 */
|
||||
if (thread1.stat != RT_THREAD_CLOSE)
|
||||
rt_thread_detach(&thread1);
|
||||
if (thread2.stat != RT_THREAD_CLOSE)
|
||||
rt_thread_detach(&thread2);
|
||||
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int _tc_thread_detach()
|
||||
{
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
thread_detach_init();
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
thread_detach_init();
|
||||
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 25;
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 25;
|
||||
}
|
||||
/* 输出函数命令到finsh shell中 */
|
||||
FINSH_FUNCTION_EXPORT(_tc_thread_detach, a static thread example);
|
||||
@@ -111,8 +111,8 @@ FINSH_FUNCTION_EXPORT(_tc_thread_detach, a static thread example);
|
||||
/* 用户应用入口 */
|
||||
int rt_application_init()
|
||||
{
|
||||
thread_detach_init();
|
||||
thread_detach_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -3,42 +3,42 @@
|
||||
|
||||
static void thread_entry(void* parameter)
|
||||
{
|
||||
rt_kprintf("thread dynamicly created ok\n");
|
||||
rt_thread_delay(10);
|
||||
rt_kprintf("thread exit\n");
|
||||
rt_kprintf("thread dynamicly created ok\n");
|
||||
rt_thread_delay(10);
|
||||
rt_kprintf("thread exit\n");
|
||||
|
||||
tc_done(TC_STAT_PASSED);
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int thread_dynamic_init()
|
||||
{
|
||||
rt_thread_t tid;
|
||||
rt_thread_t tid;
|
||||
|
||||
tid = rt_thread_create("test",
|
||||
thread_entry, RT_NULL,
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid != RT_NULL)
|
||||
rt_thread_startup(tid);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
tid = rt_thread_create("test",
|
||||
thread_entry, RT_NULL,
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid != RT_NULL)
|
||||
rt_thread_startup(tid);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
int _tc_thread_dynamic()
|
||||
{
|
||||
thread_dynamic_init();
|
||||
thread_dynamic_init();
|
||||
|
||||
return 20;
|
||||
return 20;
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(_tc_thread_dynamic, a dynamic thread test);
|
||||
#else
|
||||
int rt_application_init()
|
||||
{
|
||||
thread_dynamic_init();
|
||||
thread_dynamic_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -12,69 +12,69 @@ static rt_thread_t tid2 = RT_NULL;
|
||||
/* 线程入口 */
|
||||
static void thread_entry(void* parameter)
|
||||
{
|
||||
rt_uint32_t count = 0;
|
||||
rt_uint32_t no = (rt_uint32_t) parameter; /* 获得正确的入口参数 */
|
||||
rt_uint32_t count = 0;
|
||||
rt_uint32_t no = (rt_uint32_t) parameter; /* 获得正确的入口参数 */
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* 打印线程计数值输出 */
|
||||
rt_kprintf("thread%d count: %d\n", no, count ++);
|
||||
while (1)
|
||||
{
|
||||
/* 打印线程计数值输出 */
|
||||
rt_kprintf("thread%d count: %d\n", no, count ++);
|
||||
|
||||
/* 休眠10个OS Tick */
|
||||
rt_thread_delay(10);
|
||||
}
|
||||
/* 休眠10个OS Tick */
|
||||
rt_thread_delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
int thread_dynamic_simple_init()
|
||||
{
|
||||
/* 创建线程1 */
|
||||
tid1 = rt_thread_create("t1",
|
||||
thread_entry, (void*)1, /* 线程入口是thread_entry, 入口参数是1 */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid1 != RT_NULL)
|
||||
rt_thread_startup(tid1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 创建线程1 */
|
||||
tid1 = rt_thread_create("t1",
|
||||
thread_entry, (void*)1, /* 线程入口是thread_entry, 入口参数是1 */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid1 != RT_NULL)
|
||||
rt_thread_startup(tid1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
/* 创建线程2 */
|
||||
tid2 = rt_thread_create("t2",
|
||||
thread_entry, (void*)2, /* 线程入口是thread_entry, 入口参数是2 */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid2 != RT_NULL)
|
||||
rt_thread_startup(tid2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 创建线程2 */
|
||||
tid2 = rt_thread_create("t2",
|
||||
thread_entry, (void*)2, /* 线程入口是thread_entry, 入口参数是2 */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid2 != RT_NULL)
|
||||
rt_thread_startup(tid2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup()
|
||||
{
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
|
||||
/* 删除线程 */
|
||||
if (tid1 != RT_NULL && tid1->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid1);
|
||||
if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid2);
|
||||
/* 删除线程 */
|
||||
if (tid1 != RT_NULL && tid1->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid1);
|
||||
if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid2);
|
||||
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int _tc_thread_dynamic_simple()
|
||||
{
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
thread_dynamic_simple_init();
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
thread_dynamic_simple_init();
|
||||
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
}
|
||||
/* 输出函数命令到finsh shell中 */
|
||||
FINSH_FUNCTION_EXPORT(_tc_thread_dynamic_simple, a dynamic thread example);
|
||||
@@ -82,8 +82,8 @@ FINSH_FUNCTION_EXPORT(_tc_thread_dynamic_simple, a dynamic thread example);
|
||||
/* 用户应用入口 */
|
||||
int rt_application_init()
|
||||
{
|
||||
thread_dynamic_simple_init();
|
||||
thread_dynamic_simple_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -12,94 +12,94 @@ static rt_uint32_t count = 0;
|
||||
*/
|
||||
static void thread1_entry(void* parameter)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
count ++;
|
||||
rt_kprintf("count = %d\n", count);
|
||||
while (1)
|
||||
{
|
||||
count ++;
|
||||
rt_kprintf("count = %d\n", count);
|
||||
|
||||
rt_thread_delay(10);
|
||||
}
|
||||
rt_thread_delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
static void thread2_entry(void* parameter)
|
||||
{
|
||||
rt_tick_t tick;
|
||||
rt_tick_t tick;
|
||||
|
||||
tick = rt_tick_get();
|
||||
while (1)
|
||||
{
|
||||
if (rt_tick_get() - tick >= 50)
|
||||
{
|
||||
if (count == 0)
|
||||
tc_done(TC_STAT_FAILED);
|
||||
else
|
||||
tc_done(TC_STAT_PASSED);
|
||||
tick = rt_tick_get();
|
||||
while (1)
|
||||
{
|
||||
if (rt_tick_get() - tick >= 50)
|
||||
{
|
||||
if (count == 0)
|
||||
tc_done(TC_STAT_FAILED);
|
||||
else
|
||||
tc_done(TC_STAT_PASSED);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int thread_priority_init()
|
||||
{
|
||||
rt_err_t result;
|
||||
rt_err_t result;
|
||||
|
||||
result = rt_thread_init(&thread1,
|
||||
"t1",
|
||||
thread1_entry, RT_NULL,
|
||||
&thread1_stack[0], sizeof(thread1_stack),
|
||||
THREAD_PRIORITY - 1, THREAD_TIMESLICE);
|
||||
|
||||
if (result == RT_EOK)
|
||||
rt_thread_startup(&thread1);
|
||||
else
|
||||
tc_stat(TC_STAT_FAILED);
|
||||
result = rt_thread_init(&thread1,
|
||||
"t1",
|
||||
thread1_entry, RT_NULL,
|
||||
&thread1_stack[0], sizeof(thread1_stack),
|
||||
THREAD_PRIORITY - 1, THREAD_TIMESLICE);
|
||||
|
||||
rt_thread_init(&thread2,
|
||||
"t2",
|
||||
thread2_entry, RT_NULL,
|
||||
&thread2_stack[0], sizeof(thread2_stack),
|
||||
THREAD_PRIORITY + 1, THREAD_TIMESLICE);
|
||||
if (result == RT_EOK)
|
||||
rt_thread_startup(&thread1);
|
||||
else
|
||||
tc_stat(TC_STAT_FAILED);
|
||||
|
||||
if (result == RT_EOK)
|
||||
rt_thread_startup(&thread2);
|
||||
else
|
||||
tc_stat(TC_STAT_FAILED);
|
||||
rt_thread_init(&thread2,
|
||||
"t2",
|
||||
thread2_entry, RT_NULL,
|
||||
&thread2_stack[0], sizeof(thread2_stack),
|
||||
THREAD_PRIORITY + 1, THREAD_TIMESLICE);
|
||||
|
||||
return 0;
|
||||
if (result == RT_EOK)
|
||||
rt_thread_startup(&thread2);
|
||||
else
|
||||
tc_stat(TC_STAT_FAILED);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup()
|
||||
{
|
||||
/* lock scheduler */
|
||||
rt_enter_critical();
|
||||
/* lock scheduler */
|
||||
rt_enter_critical();
|
||||
|
||||
if (thread1.stat != RT_THREAD_CLOSE)
|
||||
rt_thread_detach(&thread1);
|
||||
if (thread2.stat != RT_THREAD_CLOSE)
|
||||
rt_thread_detach(&thread2);
|
||||
if (thread1.stat != RT_THREAD_CLOSE)
|
||||
rt_thread_detach(&thread1);
|
||||
if (thread2.stat != RT_THREAD_CLOSE)
|
||||
rt_thread_detach(&thread2);
|
||||
|
||||
/* unlock scheduler */
|
||||
rt_exit_critical();
|
||||
/* unlock scheduler */
|
||||
rt_exit_critical();
|
||||
}
|
||||
int _tc_thread_priority()
|
||||
{
|
||||
count = 0;
|
||||
count = 0;
|
||||
|
||||
/* set tc cleanup */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
thread_priority_init();
|
||||
/* set tc cleanup */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
thread_priority_init();
|
||||
|
||||
return RT_TICK_PER_SECOND;
|
||||
return RT_TICK_PER_SECOND;
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(_tc_thread_priority, a priority thread test);
|
||||
#else
|
||||
int rt_application_init()
|
||||
{
|
||||
thread_priority_init();
|
||||
thread_priority_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -13,102 +13,102 @@ static rt_thread_t tid2 = RT_NULL;
|
||||
/* 线程1入口 */
|
||||
static void thread1_entry(void* parameter)
|
||||
{
|
||||
/* 低优先级线程1开始运行 */
|
||||
rt_kprintf("thread1 startup%d\n");
|
||||
/* 低优先级线程1开始运行 */
|
||||
rt_kprintf("thread1 startup%d\n");
|
||||
|
||||
/* 挂起自身 */
|
||||
rt_kprintf("suspend thread self\n");
|
||||
rt_thread_suspend(tid1);
|
||||
/* 主动执行线程调度 */
|
||||
rt_schedule();
|
||||
/* 挂起自身 */
|
||||
rt_kprintf("suspend thread self\n");
|
||||
rt_thread_suspend(tid1);
|
||||
/* 主动执行线程调度 */
|
||||
rt_schedule();
|
||||
|
||||
/* 当线程1被唤醒时 */
|
||||
rt_kprintf("thread1 resumed\n");
|
||||
/* 当线程1被唤醒时 */
|
||||
rt_kprintf("thread1 resumed\n");
|
||||
}
|
||||
static void thread_cleanup(rt_thread_t tid)
|
||||
{
|
||||
if (tid == tid1)
|
||||
{
|
||||
tid1 = RT_NULL;
|
||||
}
|
||||
if (tid == tid2)
|
||||
{
|
||||
tid = RT_NULL;
|
||||
}
|
||||
if (tid == tid1)
|
||||
{
|
||||
tid1 = RT_NULL;
|
||||
}
|
||||
if (tid == tid2)
|
||||
{
|
||||
tid = RT_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* 线程2入口 */
|
||||
static void thread2_entry(void* parameter)
|
||||
{
|
||||
/* 延时10个OS Tick */
|
||||
rt_thread_delay(10);
|
||||
/* 延时10个OS Tick */
|
||||
rt_thread_delay(10);
|
||||
|
||||
/* 唤醒线程1 */
|
||||
rt_thread_resume(tid1);
|
||||
rt_kprintf("thread2: to resume thread1\n");
|
||||
/* 唤醒线程1 */
|
||||
rt_thread_resume(tid1);
|
||||
rt_kprintf("thread2: to resume thread1\n");
|
||||
|
||||
/* 延时10个OS Tick */
|
||||
rt_thread_delay(10);
|
||||
/* 延时10个OS Tick */
|
||||
rt_thread_delay(10);
|
||||
|
||||
/* 线程2自动退出 */
|
||||
/* 线程2自动退出 */
|
||||
}
|
||||
|
||||
int thread_resume_init()
|
||||
{
|
||||
/* 创建线程1 */
|
||||
tid1 = rt_thread_create("thread",
|
||||
thread1_entry, RT_NULL, /* 线程入口是thread1_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid1 != RT_NULL)
|
||||
{
|
||||
tid1->cleanup = thread_cleanup;
|
||||
rt_thread_startup(tid1);
|
||||
}
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 创建线程1 */
|
||||
tid1 = rt_thread_create("thread",
|
||||
thread1_entry, RT_NULL, /* 线程入口是thread1_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid1 != RT_NULL)
|
||||
{
|
||||
tid1->cleanup = thread_cleanup;
|
||||
rt_thread_startup(tid1);
|
||||
}
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
/* 创建线程2 */
|
||||
tid2 = rt_thread_create("thread",
|
||||
thread2_entry, RT_NULL, /* 线程入口是thread2_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY - 1, THREAD_TIMESLICE);
|
||||
if (tid2 != RT_NULL)
|
||||
{
|
||||
tid2->cleanup = thread_cleanup;
|
||||
rt_thread_startup(tid2);
|
||||
}
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 创建线程2 */
|
||||
tid2 = rt_thread_create("thread",
|
||||
thread2_entry, RT_NULL, /* 线程入口是thread2_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY - 1, THREAD_TIMESLICE);
|
||||
if (tid2 != RT_NULL)
|
||||
{
|
||||
tid2->cleanup = thread_cleanup;
|
||||
rt_thread_startup(tid2);
|
||||
}
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup()
|
||||
{
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
|
||||
/* 删除线程 */
|
||||
if (tid1 != RT_NULL && tid1->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid1);
|
||||
if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid2);
|
||||
/* 删除线程 */
|
||||
if (tid1 != RT_NULL && tid1->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid1);
|
||||
if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid2);
|
||||
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int _tc_thread_resume()
|
||||
{
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
thread_resume_init();
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
thread_resume_init();
|
||||
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 25;
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 25;
|
||||
}
|
||||
/* 输出函数命令到finsh shell中 */
|
||||
FINSH_FUNCTION_EXPORT(_tc_thread_resume, a thread resume example);
|
||||
@@ -116,8 +116,8 @@ FINSH_FUNCTION_EXPORT(_tc_thread_resume, a thread resume example);
|
||||
/* 用户应用入口 */
|
||||
int rt_application_init()
|
||||
{
|
||||
thread_resume_init();
|
||||
thread_resume_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -10,87 +10,87 @@ volatile static rt_uint32_t t1_count = 0;
|
||||
volatile static rt_uint32_t t2_count = 0;
|
||||
static void thread1_entry(void* parameter)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
t1_count ++;
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
t1_count ++;
|
||||
}
|
||||
}
|
||||
|
||||
static void thread2_entry(void* parameter)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
t2_count ++;
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
t2_count ++;
|
||||
}
|
||||
}
|
||||
|
||||
rt_err_t thread_same_priority_init()
|
||||
{
|
||||
rt_err_t result;
|
||||
rt_err_t result;
|
||||
|
||||
result = rt_thread_init(&thread1,
|
||||
"t1",
|
||||
thread1_entry, RT_NULL,
|
||||
&thread1_stack[0], sizeof(thread1_stack),
|
||||
THREAD_PRIORITY, 10);
|
||||
if (result == RT_EOK)
|
||||
rt_thread_startup(&thread1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
result = rt_thread_init(&thread1,
|
||||
"t1",
|
||||
thread1_entry, RT_NULL,
|
||||
&thread1_stack[0], sizeof(thread1_stack),
|
||||
THREAD_PRIORITY, 10);
|
||||
if (result == RT_EOK)
|
||||
rt_thread_startup(&thread1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
result = rt_thread_init(&thread2,
|
||||
"t2",
|
||||
thread2_entry, RT_NULL,
|
||||
&thread2_stack[0], sizeof(thread2_stack),
|
||||
THREAD_PRIORITY, 5);
|
||||
if (result == RT_EOK)
|
||||
rt_thread_startup(&thread2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
result = rt_thread_init(&thread2,
|
||||
"t2",
|
||||
thread2_entry, RT_NULL,
|
||||
&thread2_stack[0], sizeof(thread2_stack),
|
||||
THREAD_PRIORITY, 5);
|
||||
if (result == RT_EOK)
|
||||
rt_thread_startup(&thread2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup()
|
||||
{
|
||||
/* lock scheduler */
|
||||
rt_enter_critical();
|
||||
/* lock scheduler */
|
||||
rt_enter_critical();
|
||||
|
||||
if (thread1.stat != RT_THREAD_CLOSE)
|
||||
rt_thread_detach(&thread1);
|
||||
if (thread2.stat != RT_THREAD_CLOSE)
|
||||
rt_thread_detach(&thread2);
|
||||
if (thread1.stat != RT_THREAD_CLOSE)
|
||||
rt_thread_detach(&thread1);
|
||||
if (thread2.stat != RT_THREAD_CLOSE)
|
||||
rt_thread_detach(&thread2);
|
||||
|
||||
/* unlock scheduler */
|
||||
rt_exit_critical();
|
||||
/* unlock scheduler */
|
||||
rt_exit_critical();
|
||||
|
||||
rt_kprintf("t1_count=%d t2_count=%d\n",t1_count,t2_count);
|
||||
rt_kprintf("t1_count=%d t2_count=%d\n",t1_count,t2_count);
|
||||
|
||||
if (t1_count / t2_count != 2)
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
else
|
||||
tc_done(TC_STAT_PASSED);
|
||||
if (t1_count / t2_count != 2)
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
else
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int _tc_thread_same_priority()
|
||||
{
|
||||
t1_count = 0;
|
||||
t2_count = 0;
|
||||
t1_count = 0;
|
||||
t2_count = 0;
|
||||
|
||||
/* set tc cleanup */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
/* set tc cleanup */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
|
||||
thread_same_priority_init();
|
||||
thread_same_priority_init();
|
||||
|
||||
return 100;
|
||||
return 100;
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(_tc_thread_same_priority, a same priority thread test);
|
||||
#else
|
||||
int rt_application_init()
|
||||
{
|
||||
thread_same_priority_init();
|
||||
thread_same_priority_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -8,45 +8,45 @@ static struct rt_thread thread;
|
||||
static char thread_stack[THREAD_STACK_SIZE];
|
||||
static void thread_entry(void* parameter)
|
||||
{
|
||||
rt_kprintf("thread staticly inited ok\n");
|
||||
rt_thread_delay(10);
|
||||
rt_kprintf("thread exit\n");
|
||||
rt_kprintf("thread staticly inited ok\n");
|
||||
rt_thread_delay(10);
|
||||
rt_kprintf("thread exit\n");
|
||||
|
||||
tc_done(TC_STAT_PASSED);
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
rt_err_t thread_static_init()
|
||||
{
|
||||
rt_err_t result;
|
||||
rt_err_t result;
|
||||
|
||||
result = rt_thread_init(&thread,
|
||||
"test",
|
||||
thread_entry, RT_NULL,
|
||||
&thread_stack[0], sizeof(thread_stack),
|
||||
THREAD_PRIORITY, 10);
|
||||
result = rt_thread_init(&thread,
|
||||
"test",
|
||||
thread_entry, RT_NULL,
|
||||
&thread_stack[0], sizeof(thread_stack),
|
||||
THREAD_PRIORITY, 10);
|
||||
|
||||
if (result == RT_EOK)
|
||||
rt_thread_startup(&thread);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
if (result == RT_EOK)
|
||||
rt_thread_startup(&thread);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
int _tc_thread_static()
|
||||
{
|
||||
thread_static_init();
|
||||
thread_static_init();
|
||||
|
||||
return 20;
|
||||
return 20;
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(_tc_thread_static, a static thread test);
|
||||
#else
|
||||
int rt_application_init()
|
||||
{
|
||||
thread_static_init();
|
||||
thread_static_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -18,73 +18,73 @@ static rt_uint8_t thread2_stack[THREAD_STACK_SIZE];
|
||||
/* 线程入口 */
|
||||
static void thread_entry(void* parameter)
|
||||
{
|
||||
rt_uint32_t count = 0;
|
||||
rt_uint32_t no = (rt_uint32_t) parameter; /* 获得正确的入口参数 */
|
||||
rt_uint32_t count = 0;
|
||||
rt_uint32_t no = (rt_uint32_t) parameter; /* 获得正确的入口参数 */
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* 打印线程计数值输出 */
|
||||
rt_kprintf("thread%d count: %d\n", no, count ++);
|
||||
while (1)
|
||||
{
|
||||
/* 打印线程计数值输出 */
|
||||
rt_kprintf("thread%d count: %d\n", no, count ++);
|
||||
|
||||
/* 休眠10个OS Tick */
|
||||
rt_thread_delay(10);
|
||||
}
|
||||
/* 休眠10个OS Tick */
|
||||
rt_thread_delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
int thread_static_simple_init()
|
||||
{
|
||||
rt_err_t result;
|
||||
rt_err_t result;
|
||||
|
||||
/* 初始化线程1 */
|
||||
result = rt_thread_init(&thread1, "t1", /* 线程名:t1 */
|
||||
thread_entry, (void*)1, /* 线程的入口是thread_entry,入口参数是1 */
|
||||
&thread1_stack[0], sizeof(thread1_stack), /* 线程栈是thread1_stack */
|
||||
THREAD_PRIORITY, 10);
|
||||
if (result == RT_EOK) /* 如果返回正确,启动线程1 */
|
||||
rt_thread_startup(&thread1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 初始化线程1 */
|
||||
result = rt_thread_init(&thread1, "t1", /* 线程名:t1 */
|
||||
thread_entry, (void*)1, /* 线程的入口是thread_entry,入口参数是1 */
|
||||
&thread1_stack[0], sizeof(thread1_stack), /* 线程栈是thread1_stack */
|
||||
THREAD_PRIORITY, 10);
|
||||
if (result == RT_EOK) /* 如果返回正确,启动线程1 */
|
||||
rt_thread_startup(&thread1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
/* 初始化线程2 */
|
||||
result = rt_thread_init(&thread2, "t2", /* 线程名:t2 */
|
||||
thread_entry, RT_NULL, /* 线程的入口是thread_entry,入口参数是2 */
|
||||
&thread2_stack[0], sizeof(thread2_stack), /* 线程栈是thread2_stack */
|
||||
THREAD_PRIORITY + 1, 10);
|
||||
if (result == RT_EOK) /* 如果返回正确,启动线程2 */
|
||||
rt_thread_startup(&thread2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 初始化线程2 */
|
||||
result = rt_thread_init(&thread2, "t2", /* 线程名:t2 */
|
||||
thread_entry, RT_NULL, /* 线程的入口是thread_entry,入口参数是2 */
|
||||
&thread2_stack[0], sizeof(thread2_stack), /* 线程栈是thread2_stack */
|
||||
THREAD_PRIORITY + 1, 10);
|
||||
if (result == RT_EOK) /* 如果返回正确,启动线程2 */
|
||||
rt_thread_startup(&thread2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup()
|
||||
{
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
|
||||
/* 执行线程脱离 */
|
||||
if (thread1.stat != RT_THREAD_CLOSE)
|
||||
rt_thread_detach(&thread1);
|
||||
if (thread2.stat != RT_THREAD_CLOSE)
|
||||
rt_thread_detach(&thread2);
|
||||
/* 执行线程脱离 */
|
||||
if (thread1.stat != RT_THREAD_CLOSE)
|
||||
rt_thread_detach(&thread1);
|
||||
if (thread2.stat != RT_THREAD_CLOSE)
|
||||
rt_thread_detach(&thread2);
|
||||
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int _tc_thread_static_simple()
|
||||
{
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
thread_static_simple_init();
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
thread_static_simple_init();
|
||||
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
}
|
||||
/* 输出函数命令到finsh shell中 */
|
||||
FINSH_FUNCTION_EXPORT(_tc_thread_static_simple, a static thread example);
|
||||
@@ -92,8 +92,8 @@ FINSH_FUNCTION_EXPORT(_tc_thread_static_simple, a static thread example);
|
||||
/* 用户应用入口 */
|
||||
int rt_application_init()
|
||||
{
|
||||
thread_static_simple_init();
|
||||
thread_static_simple_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -12,81 +12,81 @@ static rt_thread_t tid2 = RT_NULL;
|
||||
/* 线程1入口 */
|
||||
static void thread1_entry(void* parameter)
|
||||
{
|
||||
rt_uint32_t count = 0;
|
||||
rt_uint32_t count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* 线程1采用低优先级运行,一直打印计数值 */
|
||||
rt_kprintf("thread count: %d\n", count ++);
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
/* 线程1采用低优先级运行,一直打印计数值 */
|
||||
rt_kprintf("thread count: %d\n", count ++);
|
||||
}
|
||||
}
|
||||
|
||||
/* 线程2入口 */
|
||||
static void thread2_entry(void* parameter)
|
||||
{
|
||||
/* 延时10个OS Tick */
|
||||
rt_thread_delay(10);
|
||||
/* 延时10个OS Tick */
|
||||
rt_thread_delay(10);
|
||||
|
||||
/* 挂起线程1 */
|
||||
rt_thread_suspend(tid1);
|
||||
/* 挂起线程1 */
|
||||
rt_thread_suspend(tid1);
|
||||
|
||||
/* 延时10个OS Tick */
|
||||
rt_thread_delay(10);
|
||||
/* 延时10个OS Tick */
|
||||
rt_thread_delay(10);
|
||||
|
||||
/* 线程2自动退出 */
|
||||
tid2 = RT_NULL;
|
||||
/* 线程2自动退出 */
|
||||
tid2 = RT_NULL;
|
||||
}
|
||||
|
||||
int thread_suspend_init()
|
||||
{
|
||||
/* 创建线程1 */
|
||||
tid1 = rt_thread_create("thread",
|
||||
thread1_entry, RT_NULL, /* 线程入口是thread1_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid1 != RT_NULL)
|
||||
rt_thread_startup(tid1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 创建线程1 */
|
||||
tid1 = rt_thread_create("thread",
|
||||
thread1_entry, RT_NULL, /* 线程入口是thread1_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid1 != RT_NULL)
|
||||
rt_thread_startup(tid1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
/* 创建线程2 */
|
||||
tid2 = rt_thread_create("thread",
|
||||
thread2_entry, RT_NULL, /* 线程入口是thread2_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY - 1, THREAD_TIMESLICE);
|
||||
if (tid2 != RT_NULL)
|
||||
rt_thread_startup(tid2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 创建线程2 */
|
||||
tid2 = rt_thread_create("thread",
|
||||
thread2_entry, RT_NULL, /* 线程入口是thread2_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY - 1, THREAD_TIMESLICE);
|
||||
if (tid2 != RT_NULL)
|
||||
rt_thread_startup(tid2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup()
|
||||
{
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
|
||||
/* 删除线程 */
|
||||
if (tid1 != RT_NULL && tid1->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid1);
|
||||
if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid2);
|
||||
/* 删除线程 */
|
||||
if (tid1 != RT_NULL && tid1->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid1);
|
||||
if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid2);
|
||||
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int _tc_thread_suspend()
|
||||
{
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
thread_suspend_init();
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
thread_suspend_init();
|
||||
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
}
|
||||
/* 输出函数命令到finsh shell中 */
|
||||
FINSH_FUNCTION_EXPORT(_tc_thread_suspend, a thread suspend example);
|
||||
@@ -94,8 +94,8 @@ FINSH_FUNCTION_EXPORT(_tc_thread_suspend, a thread suspend example);
|
||||
/* 用户应用入口 */
|
||||
int rt_application_init()
|
||||
{
|
||||
thread_suspend_init();
|
||||
thread_suspend_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -10,83 +10,83 @@ static rt_thread_t tid2 = RT_NULL;
|
||||
/* 线程1入口 */
|
||||
static void thread1_entry(void* parameter)
|
||||
{
|
||||
rt_uint32_t count = 0;
|
||||
rt_uint32_t count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* 打印线程1的输出 */
|
||||
rt_kprintf("thread1: count = %d\n", count ++);
|
||||
while (1)
|
||||
{
|
||||
/* 打印线程1的输出 */
|
||||
rt_kprintf("thread1: count = %d\n", count ++);
|
||||
|
||||
/* 执行yield后应该切换到thread2执行 */
|
||||
rt_thread_yield();
|
||||
}
|
||||
/* 执行yield后应该切换到thread2执行 */
|
||||
rt_thread_yield();
|
||||
}
|
||||
}
|
||||
|
||||
/* 线程2入口 */
|
||||
static void thread2_entry(void* parameter)
|
||||
{
|
||||
rt_uint32_t count = 0;
|
||||
rt_uint32_t count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* 打印线程2的输出 */
|
||||
rt_kprintf("thread2: count = %d\n", count ++);
|
||||
while (1)
|
||||
{
|
||||
/* 打印线程2的输出 */
|
||||
rt_kprintf("thread2: count = %d\n", count ++);
|
||||
|
||||
/* 执行yield后应该切换到thread1执行 */
|
||||
rt_thread_yield();
|
||||
}
|
||||
/* 执行yield后应该切换到thread1执行 */
|
||||
rt_thread_yield();
|
||||
}
|
||||
}
|
||||
|
||||
int thread_yield_init()
|
||||
{
|
||||
/* 创建线程1 */
|
||||
tid1 = rt_thread_create("thread",
|
||||
thread1_entry, RT_NULL, /* 线程入口是thread1_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid1 != RT_NULL)
|
||||
rt_thread_startup(tid1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 创建线程1 */
|
||||
tid1 = rt_thread_create("thread",
|
||||
thread1_entry, RT_NULL, /* 线程入口是thread1_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid1 != RT_NULL)
|
||||
rt_thread_startup(tid1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
/* 创建线程2 */
|
||||
tid2 = rt_thread_create("thread",
|
||||
thread2_entry, RT_NULL, /* 线程入口是thread2_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid2 != RT_NULL)
|
||||
rt_thread_startup(tid2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 创建线程2 */
|
||||
tid2 = rt_thread_create("thread",
|
||||
thread2_entry, RT_NULL, /* 线程入口是thread2_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid2 != RT_NULL)
|
||||
rt_thread_startup(tid2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup()
|
||||
{
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
|
||||
/* 删除线程 */
|
||||
if (tid1 != RT_NULL && tid1->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid1);
|
||||
if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid2);
|
||||
/* 删除线程 */
|
||||
if (tid1 != RT_NULL && tid1->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid1);
|
||||
if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid2);
|
||||
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int _tc_thread_yield()
|
||||
{
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
thread_yield_init();
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
thread_yield_init();
|
||||
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 30;
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 30;
|
||||
}
|
||||
/* 输出函数命令到finsh shell中 */
|
||||
FINSH_FUNCTION_EXPORT(_tc_thread_yield, a thread yield example);
|
||||
@@ -94,8 +94,8 @@ FINSH_FUNCTION_EXPORT(_tc_thread_yield, a thread yield example);
|
||||
/* 用户应用入口 */
|
||||
int rt_application_init()
|
||||
{
|
||||
thread_yield_init();
|
||||
thread_yield_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -13,63 +13,63 @@ static rt_uint8_t count;
|
||||
/* 定时器超时函数 */
|
||||
static void timeout1(void* parameter)
|
||||
{
|
||||
rt_tick_t timeout = 50;
|
||||
|
||||
rt_kprintf("periodic timer is timeout\n");
|
||||
rt_tick_t timeout = 50;
|
||||
|
||||
rt_kprintf("periodic timer is timeout\n");
|
||||
|
||||
count ++;
|
||||
/* 停止定时器自身 */
|
||||
if (count >= 8)
|
||||
{
|
||||
/* 控制定时器然后更改超时时间长度 */
|
||||
rt_timer_control(timer1, RT_TIMER_CTRL_SET_TIME, (void *)&timeout);
|
||||
count = 0;
|
||||
}
|
||||
count ++;
|
||||
/* 停止定时器自身 */
|
||||
if (count >= 8)
|
||||
{
|
||||
/* 控制定时器然后更改超时时间长度 */
|
||||
rt_timer_control(timer1, RT_TIMER_CTRL_SET_TIME, (void *)&timeout);
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void timer_control_init()
|
||||
{
|
||||
/* 创建定时器1 */
|
||||
timer1 = rt_timer_create("timer1", /* 定时器名字是 timer1 */
|
||||
timeout1, /* 超时时回调的处理函数 */
|
||||
RT_NULL, /* 超时函数的入口参数 */
|
||||
10, /* 定时长度,以OS Tick为单位,即10个OS Tick */
|
||||
RT_TIMER_FLAG_PERIODIC); /* 周期性定时器 */
|
||||
/* 启动定时器 */
|
||||
if (timer1 != RT_NULL)
|
||||
rt_timer_start(timer1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 创建定时器1 */
|
||||
timer1 = rt_timer_create("timer1", /* 定时器名字是 timer1 */
|
||||
timeout1, /* 超时时回调的处理函数 */
|
||||
RT_NULL, /* 超时函数的入口参数 */
|
||||
10, /* 定时长度,以OS Tick为单位,即10个OS Tick */
|
||||
RT_TIMER_FLAG_PERIODIC); /* 周期性定时器 */
|
||||
/* 启动定时器 */
|
||||
if (timer1 != RT_NULL)
|
||||
rt_timer_start(timer1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup()
|
||||
{
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
|
||||
/* 删除定时器对象 */
|
||||
rt_timer_delete(timer1);
|
||||
timer1 = RT_NULL;
|
||||
/* 删除定时器对象 */
|
||||
rt_timer_delete(timer1);
|
||||
timer1 = RT_NULL;
|
||||
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int _tc_timer_control()
|
||||
{
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
|
||||
/* 执行定时器例程 */
|
||||
count = 0;
|
||||
timer_control_init();
|
||||
/* 执行定时器例程 */
|
||||
count = 0;
|
||||
timer_control_init();
|
||||
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
}
|
||||
/* 输出函数命令到finsh shell中 */
|
||||
FINSH_FUNCTION_EXPORT(_tc_timer_control, a timer control example);
|
||||
@@ -77,8 +77,8 @@ FINSH_FUNCTION_EXPORT(_tc_timer_control, a timer control example);
|
||||
/* 用户应用入口 */
|
||||
int rt_application_init()
|
||||
{
|
||||
timer_control_init();
|
||||
timer_control_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -13,70 +13,70 @@ static rt_timer_t timer2;
|
||||
/* 定时器1超时函数 */
|
||||
static void timeout1(void* parameter)
|
||||
{
|
||||
rt_kprintf("periodic timer is timeout\n");
|
||||
rt_kprintf("periodic timer is timeout\n");
|
||||
}
|
||||
|
||||
/* 定时器2超时函数 */
|
||||
static void timeout2(void* parameter)
|
||||
{
|
||||
rt_kprintf("one shot timer is timeout\n");
|
||||
rt_kprintf("one shot timer is timeout\n");
|
||||
}
|
||||
|
||||
void timer_create_init()
|
||||
{
|
||||
/* 创建定时器1 */
|
||||
timer1 = rt_timer_create("timer1", /* 定时器名字是 timer1 */
|
||||
timeout1, /* 超时时回调的处理函数 */
|
||||
RT_NULL, /* 超时函数的入口参数 */
|
||||
10, /* 定时长度,以OS Tick为单位,即10个OS Tick */
|
||||
RT_TIMER_FLAG_PERIODIC); /* 周期性定时器 */
|
||||
/* 启动定时器 */
|
||||
if (timer1 != RT_NULL)
|
||||
rt_timer_start(timer1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 创建定时器1 */
|
||||
timer1 = rt_timer_create("timer1", /* 定时器名字是 timer1 */
|
||||
timeout1, /* 超时时回调的处理函数 */
|
||||
RT_NULL, /* 超时函数的入口参数 */
|
||||
10, /* 定时长度,以OS Tick为单位,即10个OS Tick */
|
||||
RT_TIMER_FLAG_PERIODIC); /* 周期性定时器 */
|
||||
/* 启动定时器 */
|
||||
if (timer1 != RT_NULL)
|
||||
rt_timer_start(timer1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
/* 创建定时器2 */
|
||||
timer2 = rt_timer_create("timer2", /* 定时器名字是 timer2 */
|
||||
timeout2, /* 超时时回调的处理函数 */
|
||||
RT_NULL, /* 超时函数的入口参数 */
|
||||
30, /* 定时长度为30个OS Tick */
|
||||
RT_TIMER_FLAG_ONE_SHOT); /* 单次定时器 */
|
||||
/* 创建定时器2 */
|
||||
timer2 = rt_timer_create("timer2", /* 定时器名字是 timer2 */
|
||||
timeout2, /* 超时时回调的处理函数 */
|
||||
RT_NULL, /* 超时函数的入口参数 */
|
||||
30, /* 定时长度为30个OS Tick */
|
||||
RT_TIMER_FLAG_ONE_SHOT); /* 单次定时器 */
|
||||
|
||||
/* 启动定时器 */
|
||||
if (timer2 != RT_NULL)
|
||||
rt_timer_start(timer2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 启动定时器 */
|
||||
if (timer2 != RT_NULL)
|
||||
rt_timer_start(timer2);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup()
|
||||
{
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
|
||||
/* 删除定时器对象 */
|
||||
rt_timer_delete(timer1);
|
||||
rt_timer_delete(timer2);
|
||||
/* 删除定时器对象 */
|
||||
rt_timer_delete(timer1);
|
||||
rt_timer_delete(timer2);
|
||||
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int _tc_timer_create()
|
||||
{
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
|
||||
/* 执行定时器例程 */
|
||||
timer_create_init();
|
||||
/* 执行定时器例程 */
|
||||
timer_create_init();
|
||||
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
}
|
||||
/* 输出函数命令到finsh shell中 */
|
||||
FINSH_FUNCTION_EXPORT(_tc_timer_create, a dynamic timer example);
|
||||
@@ -84,8 +84,8 @@ FINSH_FUNCTION_EXPORT(_tc_timer_create, a dynamic timer example);
|
||||
/* 用户应用入口 */
|
||||
int rt_application_init()
|
||||
{
|
||||
timer_create_init();
|
||||
timer_create_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -13,61 +13,61 @@ static struct rt_timer timer2;
|
||||
/* 定时器1超时函数 */
|
||||
static void timeout1(void* parameter)
|
||||
{
|
||||
rt_kprintf("periodic timer is timeout\n");
|
||||
rt_kprintf("periodic timer is timeout\n");
|
||||
}
|
||||
|
||||
/* 定时器2超时函数 */
|
||||
static void timeout2(void* parameter)
|
||||
{
|
||||
rt_kprintf("one shot timer is timeout\n");
|
||||
rt_kprintf("one shot timer is timeout\n");
|
||||
}
|
||||
|
||||
void timer_static_init()
|
||||
{
|
||||
/* 初始化定时器 */
|
||||
rt_timer_init(&timer1, "timer1", /* 定时器名字是 timer1 */
|
||||
timeout1, /* 超时时回调的处理函数 */
|
||||
RT_NULL, /* 超时函数的入口参数 */
|
||||
10, /* 定时长度,以OS Tick为单位,即10个OS Tick */
|
||||
RT_TIMER_FLAG_PERIODIC); /* 周期性定时器 */
|
||||
rt_timer_init(&timer2, "timer2", /* 定时器名字是 timer2 */
|
||||
timeout2, /* 超时时回调的处理函数 */
|
||||
RT_NULL, /* 超时函数的入口参数 */
|
||||
30, /* 定时长度为30个OS Tick */
|
||||
RT_TIMER_FLAG_ONE_SHOT); /* 单次定时器 */
|
||||
/* 初始化定时器 */
|
||||
rt_timer_init(&timer1, "timer1", /* 定时器名字是 timer1 */
|
||||
timeout1, /* 超时时回调的处理函数 */
|
||||
RT_NULL, /* 超时函数的入口参数 */
|
||||
10, /* 定时长度,以OS Tick为单位,即10个OS Tick */
|
||||
RT_TIMER_FLAG_PERIODIC); /* 周期性定时器 */
|
||||
rt_timer_init(&timer2, "timer2", /* 定时器名字是 timer2 */
|
||||
timeout2, /* 超时时回调的处理函数 */
|
||||
RT_NULL, /* 超时函数的入口参数 */
|
||||
30, /* 定时长度为30个OS Tick */
|
||||
RT_TIMER_FLAG_ONE_SHOT); /* 单次定时器 */
|
||||
|
||||
/* 启动定时器 */
|
||||
rt_timer_start(&timer1);
|
||||
rt_timer_start(&timer2);
|
||||
/* 启动定时器 */
|
||||
rt_timer_start(&timer1);
|
||||
rt_timer_start(&timer2);
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup()
|
||||
{
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
|
||||
/* 执行定时器脱离 */
|
||||
rt_timer_detach(&timer1);
|
||||
rt_timer_detach(&timer2);
|
||||
/* 执行定时器脱离 */
|
||||
rt_timer_detach(&timer1);
|
||||
rt_timer_detach(&timer2);
|
||||
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int _tc_timer_static()
|
||||
{
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
|
||||
/* 执行定时器例程 */
|
||||
timer_static_init();
|
||||
/* 执行定时器例程 */
|
||||
timer_static_init();
|
||||
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
}
|
||||
/* 输出函数命令到finsh shell中 */
|
||||
FINSH_FUNCTION_EXPORT(_tc_timer_static, a static timer example);
|
||||
@@ -75,8 +75,8 @@ FINSH_FUNCTION_EXPORT(_tc_timer_static, a static timer example);
|
||||
/* 用户应用入口 */
|
||||
int rt_application_init()
|
||||
{
|
||||
timer_static_init();
|
||||
timer_static_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -13,61 +13,61 @@ static rt_uint8_t count;
|
||||
/* 定时器超时函数 */
|
||||
static void timeout1(void* parameter)
|
||||
{
|
||||
rt_kprintf("periodic timer is timeout\n");
|
||||
rt_kprintf("periodic timer is timeout\n");
|
||||
|
||||
count ++;
|
||||
/* 停止定时器自身 */
|
||||
if (count >= 8)
|
||||
{
|
||||
/* 停止定时器 */
|
||||
rt_timer_stop(timer1);
|
||||
count = 0;
|
||||
}
|
||||
count ++;
|
||||
/* 停止定时器自身 */
|
||||
if (count >= 8)
|
||||
{
|
||||
/* 停止定时器 */
|
||||
rt_timer_stop(timer1);
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void timer_stop_self_init()
|
||||
{
|
||||
/* 创建定时器1 */
|
||||
timer1 = rt_timer_create("timer1", /* 定时器名字是 timer1 */
|
||||
timeout1, /* 超时时回调的处理函数 */
|
||||
RT_NULL, /* 超时函数的入口参数 */
|
||||
10, /* 定时长度,以OS Tick为单位,即10个OS Tick */
|
||||
RT_TIMER_FLAG_PERIODIC); /* 周期性定时器 */
|
||||
/* 启动定时器 */
|
||||
if (timer1 != RT_NULL)
|
||||
rt_timer_start(timer1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 创建定时器1 */
|
||||
timer1 = rt_timer_create("timer1", /* 定时器名字是 timer1 */
|
||||
timeout1, /* 超时时回调的处理函数 */
|
||||
RT_NULL, /* 超时函数的入口参数 */
|
||||
10, /* 定时长度,以OS Tick为单位,即10个OS Tick */
|
||||
RT_TIMER_FLAG_PERIODIC); /* 周期性定时器 */
|
||||
/* 启动定时器 */
|
||||
if (timer1 != RT_NULL)
|
||||
rt_timer_start(timer1);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup()
|
||||
{
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
|
||||
/* 删除定时器对象 */
|
||||
rt_timer_delete(timer1);
|
||||
timer1 = RT_NULL;
|
||||
/* 删除定时器对象 */
|
||||
rt_timer_delete(timer1);
|
||||
timer1 = RT_NULL;
|
||||
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int _tc_timer_stop_self()
|
||||
{
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
|
||||
/* 执行定时器例程 */
|
||||
count = 0;
|
||||
timer_stop_self_init();
|
||||
/* 执行定时器例程 */
|
||||
count = 0;
|
||||
timer_stop_self_init();
|
||||
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
}
|
||||
/* 输出函数命令到finsh shell中 */
|
||||
FINSH_FUNCTION_EXPORT(_tc_timer_stop_self, a dynamic timer example);
|
||||
@@ -75,8 +75,8 @@ FINSH_FUNCTION_EXPORT(_tc_timer_stop_self, a dynamic timer example);
|
||||
/* 用户应用入口 */
|
||||
int rt_application_init()
|
||||
{
|
||||
timer_stop_self_init();
|
||||
timer_stop_self_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -20,94 +20,94 @@ static struct rt_timer timer;
|
||||
static rt_uint16_t no = 0;
|
||||
static void timer_timeout(void* parameter)
|
||||
{
|
||||
char buf[32];
|
||||
rt_uint32_t length;
|
||||
char buf[32];
|
||||
rt_uint32_t length;
|
||||
|
||||
length = rt_snprintf(buf, sizeof(buf), "message %d", no++);
|
||||
rt_mq_send(&mq, &buf[0], length);
|
||||
length = rt_snprintf(buf, sizeof(buf), "message %d", no++);
|
||||
rt_mq_send(&mq, &buf[0], length);
|
||||
}
|
||||
|
||||
/* 线程入口函数 */
|
||||
static void thread_entry(void* parameter)
|
||||
{
|
||||
char buf[64];
|
||||
rt_err_t result;
|
||||
char buf[64];
|
||||
rt_err_t result;
|
||||
|
||||
/* 初始化定时器 */
|
||||
rt_timer_init(&timer, "timer", /* 定时器名字是 timer1 */
|
||||
timer_timeout, /* 超时时回调的处理函数 */
|
||||
RT_NULL, /* 超时函数的入口参数 */
|
||||
1, /* 定时长度,以OS Tick为单位,即1个OS Tick */
|
||||
RT_TIMER_FLAG_PERIODIC); /* 周期性定时器 */
|
||||
/* 初始化定时器 */
|
||||
rt_timer_init(&timer, "timer", /* 定时器名字是 timer1 */
|
||||
timer_timeout, /* 超时时回调的处理函数 */
|
||||
RT_NULL, /* 超时函数的入口参数 */
|
||||
1, /* 定时长度,以OS Tick为单位,即1个OS Tick */
|
||||
RT_TIMER_FLAG_PERIODIC); /* 周期性定时器 */
|
||||
|
||||
while (1)
|
||||
{
|
||||
rt_memset(&buf[0], 0, sizeof(buf));
|
||||
while (1)
|
||||
{
|
||||
rt_memset(&buf[0], 0, sizeof(buf));
|
||||
|
||||
/* 从消息队列中接收消息 */
|
||||
result = rt_mq_recv(&mq, &buf[0], sizeof(buf), 1);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
rt_kprintf("recv msg: %s\n", buf);
|
||||
}
|
||||
else if (result == -RT_ETIMEOUT)
|
||||
{
|
||||
rt_kprintf("recv msg timeout\n");
|
||||
}
|
||||
}
|
||||
/* 从消息队列中接收消息 */
|
||||
result = rt_mq_recv(&mq, &buf[0], sizeof(buf), 1);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
rt_kprintf("recv msg: %s\n", buf);
|
||||
}
|
||||
else if (result == -RT_ETIMEOUT)
|
||||
{
|
||||
rt_kprintf("recv msg timeout\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int timer_timeout_init()
|
||||
{
|
||||
/* 初始化消息队列 */
|
||||
rt_mq_init(&mq, "mqt",
|
||||
&msg_pool[0], /* 内存池指向msg_pool */
|
||||
128 - sizeof(void*), /* 每个消息的大小是 128 - void* */
|
||||
sizeof(msg_pool), /* 内存池的大小是msg_pool的大小 */
|
||||
RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
|
||||
/* 初始化消息队列 */
|
||||
rt_mq_init(&mq, "mqt",
|
||||
&msg_pool[0], /* 内存池指向msg_pool */
|
||||
128 - sizeof(void*), /* 每个消息的大小是 128 - void* */
|
||||
sizeof(msg_pool), /* 内存池的大小是msg_pool的大小 */
|
||||
RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
|
||||
|
||||
/* 创建线程 */
|
||||
tid = rt_thread_create("t",
|
||||
thread_entry, RT_NULL, /* 线程入口是thread_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid != RT_NULL)
|
||||
rt_thread_startup(tid);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
/* 创建线程 */
|
||||
tid = rt_thread_create("t",
|
||||
thread_entry, RT_NULL, /* 线程入口是thread_entry, 入口参数是RT_NULL */
|
||||
THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
if (tid != RT_NULL)
|
||||
rt_thread_startup(tid);
|
||||
else
|
||||
tc_stat(TC_STAT_END | TC_STAT_FAILED);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_TC
|
||||
static void _tc_cleanup()
|
||||
{
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
|
||||
rt_enter_critical();
|
||||
|
||||
/* 删除线程 */
|
||||
if (tid != RT_NULL && tid->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid);
|
||||
/* 删除线程 */
|
||||
if (tid != RT_NULL && tid->stat != RT_THREAD_CLOSE)
|
||||
rt_thread_delete(tid);
|
||||
|
||||
/* 执行消息队列对象脱离 */
|
||||
rt_mq_detach(&mq);
|
||||
/* 执行定时器脱离 */
|
||||
rt_timer_detach(&timer);
|
||||
/* 执行消息队列对象脱离 */
|
||||
rt_mq_detach(&mq);
|
||||
/* 执行定时器脱离 */
|
||||
rt_timer_detach(&timer);
|
||||
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
/* 调度器解锁 */
|
||||
rt_exit_critical();
|
||||
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
/* 设置TestCase状态 */
|
||||
tc_done(TC_STAT_PASSED);
|
||||
}
|
||||
|
||||
int _tc_timer_timeout()
|
||||
{
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
timer_timeout_init();
|
||||
/* 设置TestCase清理回调函数 */
|
||||
tc_cleanup(_tc_cleanup);
|
||||
timer_timeout_init();
|
||||
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
/* 返回TestCase运行的最长时间 */
|
||||
return 100;
|
||||
}
|
||||
/* 输出函数命令到finsh shell中 */
|
||||
FINSH_FUNCTION_EXPORT(_tc_timer_timeout, a thread timer testcase);
|
||||
@@ -115,8 +115,8 @@ FINSH_FUNCTION_EXPORT(_tc_timer_timeout, a thread timer testcase);
|
||||
/* 用户应用入口 */
|
||||
int rt_application_init()
|
||||
{
|
||||
timer_timeout_init();
|
||||
timer_timeout_init();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -173,6 +173,7 @@ void rt_schedule_remove_thread(struct rt_thread *thread);
|
||||
|
||||
void rt_enter_critical(void);
|
||||
void rt_exit_critical(void);
|
||||
rt_uint16_t rt_critical_level(void);
|
||||
|
||||
#ifdef RT_USING_HOOK
|
||||
void rt_scheduler_sethook(void (*hook)(rt_thread_t from, rt_thread_t to));
|
||||
|
||||
+5
-2
@@ -22,6 +22,8 @@
|
||||
* 2006-03-23 Bernard the first version
|
||||
* 2010-11-10 Bernard add cleanup callback function in thread exit.
|
||||
* 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>
|
||||
@@ -72,8 +74,9 @@ void rt_thread_idle_sethook(void (*hook)(void))
|
||||
*/
|
||||
void rt_thread_idle_excute(void)
|
||||
{
|
||||
/* check the defunct thread list */
|
||||
if (!rt_list_isempty(&rt_thread_defunct))
|
||||
/* Loop until there is no dead thread. So one call to rt_thread_idle_excute
|
||||
* will do all the cleanups. */
|
||||
while (!rt_list_isempty(&rt_thread_defunct))
|
||||
{
|
||||
rt_base_t lock;
|
||||
rt_thread_t thread;
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
* issue found by kuronca
|
||||
* 2010-12-13 Bernard add defunct list initialization even if not use heap.
|
||||
* 2011-05-10 Bernard clean scheduler debug log.
|
||||
* 2013-12-21 Grissiom add rt_critical_level
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
@@ -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;
|
||||
}
|
||||
/*@}*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user