mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-10-13 06:55:31 +08:00
app module simulator: add app module test cases
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import os
|
||||
import sys
|
||||
import SCons.cpp
|
||||
import rtconfig
|
||||
|
||||
if os.getenv('RTT_ROOT'):
|
||||
RTT_ROOT = 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')
|
||||
# RTT_RTGUI =''
|
||||
|
||||
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
|
||||
from building import *
|
||||
|
||||
Export('RTT_ROOT')
|
||||
|
||||
# add target option
|
||||
AddOption('--app',
|
||||
dest='app',
|
||||
nargs=1, type='string',
|
||||
action='store',
|
||||
metavar='DIR',
|
||||
help='installation prefix')
|
||||
|
||||
# add target option
|
||||
AddOption('--type',
|
||||
dest='type',
|
||||
nargs=1, type='string',
|
||||
action='store',
|
||||
metavar='DIR',
|
||||
help='installation prefix')
|
||||
|
||||
app = GetOption('app')
|
||||
env = Environment()
|
||||
CPPPATH = [
|
||||
RTT_ROOT + '/include',
|
||||
RTT_ROOT + '/bsp/' + rtconfig.BSP,
|
||||
RTT_ROOT + '/components/finsh',
|
||||
RTT_ROOT + '/components/libdl',
|
||||
RTT_ROOT + '/components/external/ftk/ftk/src/os/rt-thread',
|
||||
RTT_ROOT + '/components/external/ftk/ftk/src/demos',
|
||||
RTT_ROOT + '/components/external/ftk/ftk/apps/common',
|
||||
RTT_ROOT + '/components/external/ftk/ftk/src',
|
||||
RTT_ROOT + '/components/dfs',
|
||||
RTT_ROOT + '/components/dfs/include',
|
||||
RTT_ROOT + '/components/libc/newlib',
|
||||
RTT_ROOT + '/components/external/cairo/cairo-1.10.2/src',
|
||||
RTT_ROOT + '/components/external/cairo/'
|
||||
]
|
||||
if RTT_RTGUI:
|
||||
RTGUI_ROOT = RTT_RTGUI
|
||||
else:
|
||||
RTGUI_ROOT = RTT_ROOT + '/components/rtgui'
|
||||
RTGUI_PATH = [
|
||||
RTGUI_ROOT + '/include',
|
||||
RTGUI_ROOT + '/common',
|
||||
RTGUI_ROOT + '/server',
|
||||
RTGUI_ROOT + '/widgets',
|
||||
]
|
||||
CPPPATH += RTGUI_PATH
|
||||
|
||||
env.Append(CCFLAGS=rtconfig.CFLAGS)
|
||||
env.Append(LINKFLAGS=rtconfig.LFLAGS)
|
||||
env.Append(CPPPATH=CPPPATH)
|
||||
env.Append(LIBS='rtthread', LIBPATH='../')
|
||||
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
|
||||
|
||||
PrepareModuleBuilding(env, RTT_ROOT)
|
||||
|
||||
#dir = app + '/build/' + rtconfig.BSP
|
||||
dir = app + '/build/'
|
||||
objs = SConscript(app + '/Sconscript', variant_dir=dir, duplicate=0)
|
||||
TARGET = dir + '/' + app + '.' + rtconfig.TARGET_EXT
|
||||
|
||||
# build program
|
||||
#env.Program(TARGET, objs)
|
||||
env.SharedLibrary(TARGET, objs)
|
||||
@@ -0,0 +1,7 @@
|
||||
import rtconfig
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
src = Glob('*.c')
|
||||
group = DefineGroup('', src, depend = [''])
|
||||
Return('group')
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <rtthread.h>
|
||||
|
||||
static int a = 0;
|
||||
static int b = 1000000;
|
||||
int c = 100;
|
||||
|
||||
static void function(int count1, int count2, int count3)
|
||||
{
|
||||
rt_kprintf("Hello RT-Thread %d %d\n", count1, count2, count3);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
rt_kprintf("application entry\n");
|
||||
rt_kprintf("[addr]a-0x%x,b-0x%x,c-0x%x\n", &a, &b, &c);
|
||||
rt_kprintf("[value]a-%d,b-%d,c-%d\n", a, b, c);
|
||||
|
||||
for(i=0; i<100; i++)
|
||||
{
|
||||
a++;
|
||||
b--;
|
||||
c++;
|
||||
function(a, c, b );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import rtconfig
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
src = Glob('*.c')
|
||||
group = DefineGroup('', src, depend = [''])
|
||||
Return('group')
|
||||
@@ -0,0 +1,74 @@
|
||||
#include <rtthread.h>
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/rtgui_app.h>
|
||||
#include <rtgui/widgets/window.h>
|
||||
#include <rtgui/widgets/label.h>
|
||||
#include <rtgui/driver.h>
|
||||
|
||||
/* 在LCD上创建一个主窗口,这是第一个窗口 */
|
||||
static void win_thread_entry(void *parameter)
|
||||
{
|
||||
struct rtgui_app *app;
|
||||
struct rtgui_win *win;
|
||||
struct rtgui_label *label;
|
||||
struct rtgui_rect rect;
|
||||
|
||||
app = rtgui_app_create(rt_thread_self(), "MyApp");
|
||||
RT_ASSERT(app != RT_NULL);
|
||||
|
||||
/* create a full screen window */
|
||||
rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect);
|
||||
|
||||
win = rtgui_win_create(RT_NULL, "MainWin", &rect,
|
||||
RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE);
|
||||
if (win == RT_NULL)
|
||||
{
|
||||
rtgui_app_destroy(app);
|
||||
return;
|
||||
}
|
||||
|
||||
/* 建立一个label,内容为helloworld */
|
||||
label = rtgui_label_create("Hello World!");
|
||||
|
||||
/* 设置label的位置,这里是绝对坐标 */
|
||||
rect.x1 = 0;
|
||||
rect.y1 = 100;
|
||||
rect.x2 = 240;
|
||||
rect.y2 = 140;
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
|
||||
rt_kprintf("bc: %x\n", RTGUI_WIDGET_BACKGROUND(label));
|
||||
rt_kprintf("fc: %x\n", RTGUI_WIDGET_FOREGROUND(label));
|
||||
#if 0
|
||||
RTGUI_WIDGET_BACKGROUND(label) = 0;
|
||||
RTGUI_WIDGET_FOREGROUND(label) = RTGUI_RGB(0xFF, 0xFF, 0);
|
||||
#endif
|
||||
|
||||
/*添加label到主窗口*/
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label));
|
||||
|
||||
/* 显示主窗口 */
|
||||
rtgui_win_show(win, RT_FALSE);
|
||||
|
||||
/* 循环 */
|
||||
rtgui_app_run(app);
|
||||
|
||||
rtgui_win_destroy(win);
|
||||
rtgui_app_destroy(app);
|
||||
rt_kprintf("MyApp Quit.\n");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
rt_thread_t tid;
|
||||
|
||||
tid = rt_thread_create("win", win_thread_entry, RT_NULL,
|
||||
2048, 20, 20);
|
||||
if (tid != RT_NULL)
|
||||
{
|
||||
rt_thread_startup(tid);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
# bsp name
|
||||
BSP = 'simulator'
|
||||
|
||||
# toolchains
|
||||
EXEC_PATH = ''
|
||||
PREFIX = ''
|
||||
TARGET_EXT = 'dll'
|
||||
AS = PREFIX + 'cl'
|
||||
CC = PREFIX + 'cl'
|
||||
AR = PREFIX + 'cl'
|
||||
LINK = PREFIX + 'cl'
|
||||
AFLAGS = ''
|
||||
CFLAGS = ''
|
||||
LFLAGS = ''
|
||||
BUILD = 'debug'
|
||||
|
||||
if BUILD == 'debug':
|
||||
CFLAGS += ' /MTd'
|
||||
LFLAGS += ' /DEBUG'
|
||||
else:
|
||||
CFLAGS += ' /MT'
|
||||
LFLAGS += ''
|
||||
|
||||
CFLAGS += ' /ZI /Od /W 3 /WL'
|
||||
LFLAGS += ' /DEF:rttapp.def /SUBSYSTEM:CONSOLE /MACHINE:X86'
|
||||
#LFLAGS += ' /DEF:rttapp.def /SUBSYSTEM:WINDOWS /MACHINE:X86' #/ENTRY:mainCRTStartup
|
||||
|
||||
CPATH = ''
|
||||
LPATH = ''
|
||||
|
||||
'''
|
||||
EXEC_PATH = 'C:/Program Files/CodeSourcery/Sourcery G++ Lite/bin'
|
||||
PREFIX = 'arm-none-eabi-'
|
||||
CC = PREFIX + 'gcc'
|
||||
CXX = PREFIX + 'g++'
|
||||
AS = PREFIX + 'gcc'
|
||||
AR = PREFIX + 'ar'
|
||||
LINK = PREFIX + 'gcc'
|
||||
TARGET_EXT = 'so'
|
||||
SIZE = PREFIX + 'size'
|
||||
OBJDUMP = PREFIX + 'objdump'
|
||||
OBJCPY = PREFIX + 'objcopy'
|
||||
|
||||
DEVICE = ' -mcpu=arm920t'
|
||||
CFLAGS = DEVICE + ' -O0 -fPIC -DFTK_AS_PLUGIN -DRT_THREAD '
|
||||
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
|
||||
LFLAGS = DEVICE + ' -Wl,-z,max-page-size=0x4 -shared -fPIC -nostdlib -s'
|
||||
|
||||
CPATH = ''
|
||||
LPATH = ''
|
||||
'''
|
||||
@@ -0,0 +1,3 @@
|
||||
LIBRARY app
|
||||
EXPORTS
|
||||
main
|
||||
@@ -0,0 +1,7 @@
|
||||
import rtconfig
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
src = Glob('*.c')
|
||||
group = DefineGroup('', src, depend = [''])
|
||||
Return('group')
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,68 @@
|
||||
#ifndef _SNAKE_H_
|
||||
#define _SNAKE_H_
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#define snake_length_max 20 //最大蛇长
|
||||
#define snake_length_init 3 //初始化蛇长
|
||||
#define snake_room_size_hight 8 //房子高 0-255 建议>8
|
||||
#define snake_room_size_widht 8 //房子宽 0-255 建议>8
|
||||
|
||||
#define snake_init_pointx 1
|
||||
#define snake_init_pointy 2
|
||||
|
||||
typedef struct
|
||||
{
|
||||
rt_int32_t x, y;
|
||||
} point_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
rt_int32_t width; // max x
|
||||
rt_int32_t height; // max y
|
||||
rt_uint8_t *range; // map, map->range[y * map->width + x]
|
||||
point_t snake_flush[2];
|
||||
point_t food_flush[1];
|
||||
} map_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SNAKE_DIR_UP,
|
||||
SNAKE_DIR_DOWN,
|
||||
SNAKE_DIR_LEFT,
|
||||
SNAKE_DIR_RIGHT
|
||||
} SNAKE_DIR;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FOOD, // 吃到水果
|
||||
OVER, // 咬到自身
|
||||
NORMAL // 正常行动
|
||||
} SYS_STE;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
point_t body;
|
||||
rt_list_t list;
|
||||
} snake_t;
|
||||
|
||||
// 构造一个地图
|
||||
map_t *map_init(rt_uint32_t width, rt_uint32_t heigth);
|
||||
|
||||
// 构造一条指定长度的蛇在指定点
|
||||
rt_bool_t snake_init(const point_t *start, const int length, const SNAKE_DIR dir, map_t *map);
|
||||
|
||||
// 构造出食物
|
||||
rt_bool_t food_init(map_t *map, rt_uint32_t max_num);
|
||||
|
||||
void map_deinit(map_t *map);
|
||||
|
||||
void snake_deinit(void);
|
||||
|
||||
void food_deinit(void);
|
||||
|
||||
SYS_STE snake_step(SNAKE_DIR dir, map_t *map);
|
||||
|
||||
rt_bool_t snake_restart(const point_t *start, const int length, const SNAKE_DIR dir, map_t *map);
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
import rtconfig
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
src = Glob('*.c')
|
||||
group = DefineGroup('', src, depend = [''])
|
||||
Return('group')
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <rtthread.h>
|
||||
|
||||
/* rtgui\common\rtgui_object.c */
|
||||
_declspec(dllimport) void * _rtgui_object;
|
||||
|
||||
/* rtgui\common\color.c */
|
||||
_declspec(dllimport) rt_uint32_t blue;
|
||||
//extern rt_uint32_t * green;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
//rt_kprintf("green = %x, *green", green, *(rt_uint32_t *)green);
|
||||
rt_kprintf("blue = %x\n", blue);
|
||||
rt_kprintf("_rtgui_object = %x\n", _rtgui_object);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user