├── tools
├── PackTag
├── PushTool
├── PackTag.exe
├── PushTool.exe
└── packtag.py
├── linkit
├── lib
│ └── LINKIT10
│ │ └── armgcc
│ │ ├── percommon.a
│ │ └── scat.ld
└── include
│ ├── vmalarm.h
│ ├── vmgsm.h
│ ├── vmusb.h
│ ├── vmdrv_tp.h
│ ├── vmkeypad.h
│ ├── vmdns.h
│ ├── vmwdt.h
│ ├── vmdcl_kbd.h
│ ├── vmcmd.h
│ ├── vmtouch.h
│ ├── vmmemory.h
│ ├── vmaudio_record.h
│ ├── vmtype.h
│ ├── vmgsm_cell.h
│ └── vmboard.h
├── lua
├── legc.c
├── lapi.h
├── legc.h
├── Makefile
├── lrodefs.h
├── ldebug.h
├── lstring.h
├── lualib.h
├── ltm.h
├── lvm.h
├── lfunc.h
├── ltable.h
├── lmem.h
├── lundump.h
├── lzio.c
├── ldo.h
├── lzio.h
├── ltm.c
├── lrotable.h
├── llex.h
├── lmem.c
├── linenoise.h
├── lparser.h
├── llimits.h
├── lcode.h
├── lopcodes.c
├── linit.c
├── lrotable.c
├── lgc.h
├── lstring.c
├── lfunc.c
├── print.c
├── lstate.h
└── lobject.c
├── src
├── shell.h
├── tp_i2c.h
├── main.c
├── retarget.c
├── tp_goodix_gt9xx.h
└── shell.c
├── .gitignore
├── bindings
├── Makefile
├── button.c
├── timer.c
├── gpio.c
├── tcp.c
└── audio.c
├── lua.workspace
├── .github
└── workflows
│ └── sync_issues.yml
├── modules
├── matrix.lua
├── basic_sensors.lua
└── blingbling.lua
├── README.md
└── Makefile
/tools/PackTag:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/Lua_for_RePhone/HEAD/tools/PackTag
--------------------------------------------------------------------------------
/tools/PushTool:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/Lua_for_RePhone/HEAD/tools/PushTool
--------------------------------------------------------------------------------
/tools/PackTag.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/Lua_for_RePhone/HEAD/tools/PackTag.exe
--------------------------------------------------------------------------------
/tools/PushTool.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/Lua_for_RePhone/HEAD/tools/PushTool.exe
--------------------------------------------------------------------------------
/linkit/lib/LINKIT10/armgcc/percommon.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/Lua_for_RePhone/HEAD/linkit/lib/LINKIT10/armgcc/percommon.a
--------------------------------------------------------------------------------
/lua/legc.c:
--------------------------------------------------------------------------------
1 | // Lua EGC (Emergeny Garbage Collector) interface
2 |
3 | #include "legc.h"
4 | #include "lstate.h"
5 |
6 | void legc_set_mode(lua_State *L, int mode, unsigned limit) {
7 | global_State *g = G(L);
8 |
9 | g->egcmode = mode;
10 | g->memlimit = limit;
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/src/shell.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef __SHELL_H__
3 | #define __SHELL_H__
4 |
5 | #include "vmthread.h"
6 | #include "lua.h"
7 |
8 | #define SHELL_MESSAGE_ID 326
9 |
10 | VMINT32 shell_thread(VM_THREAD_HANDLE thread_handle, void* user_data);
11 |
12 | void shell_docall(lua_State *L);
13 |
14 | #endif // __SHELL_H__
15 |
--------------------------------------------------------------------------------
/lua/lapi.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Auxiliary functions from Lua API
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lapi_h
8 | #define lapi_h
9 |
10 |
11 | #include "lobject.h"
12 |
13 |
14 | LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o);
15 |
16 | #endif
17 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.map
2 | *.vxp
3 |
4 | # Object files
5 | *.o
6 | *.ko
7 | *.obj
8 | *.elf
9 |
10 | # Precompiled Headers
11 | *.gch
12 | *.pch
13 |
14 | # Libraries
15 | *.lib
16 | *.a
17 | *.la
18 | *.lo
19 |
20 | # Shared objects (inc. Windows DLLs)
21 | *.dll
22 | *.so
23 | *.so.*
24 | *.dylib
25 |
26 | # Executables
27 | *.out
28 | *.app
29 | *.i*86
30 | *.x86_64
31 | *.hex
32 |
33 | # Debug files
34 | *.dSYM/
35 |
--------------------------------------------------------------------------------
/bindings/Makefile:
--------------------------------------------------------------------------------
1 |
2 | OBJECTS += $(WORKSPACE_PATH)bindings/audio.o $(WORKSPACE_PATH)bindings/gsm.o $(WORKSPACE_PATH)bindings/gpio.o \
3 | $(WORKSPACE_PATH)bindings/i2c.o $(WORKSPACE_PATH)bindings/timer.o $(WORKSPACE_PATH)bindings/tcp.o \
4 | $(WORKSPACE_PATH)bindings/screen.o $(WORKSPACE_PATH)bindings/https.o $(WORKSPACE_PATH)bindings/bluetooth.o $(WORKSPACE_PATH)bindings/button.o
5 | INCLUDE_PATHS += -I$(WORKSPACE_PATH)bindings
--------------------------------------------------------------------------------
/lua.workspace:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/lua/legc.h:
--------------------------------------------------------------------------------
1 | // Lua EGC (Emergeny Garbage Collector) interface
2 |
3 | #ifndef __LEGC_H__
4 | #define __LEGC_H__
5 |
6 | #include "lstate.h"
7 |
8 | // EGC operations modes
9 | #define EGC_NOT_ACTIVE 0 // EGC disabled
10 | #define EGC_ON_ALLOC_FAILURE 1 // run EGC on allocation failure
11 | #define EGC_ON_MEM_LIMIT 2 // run EGC when an upper memory limit is hit
12 | #define EGC_ALWAYS 4 // always run EGC before an allocation
13 |
14 | void legc_set_mode(lua_State *L, int mode, unsigned limit);
15 |
16 | #endif
17 |
18 |
--------------------------------------------------------------------------------
/.github/workflows/sync_issues.yml:
--------------------------------------------------------------------------------
1 | name: Automate Issue Management
2 |
3 | on:
4 | issues:
5 | types:
6 | - opened
7 | - edited
8 | - assigned
9 | - unassigned
10 | - labeled
11 | - unlabeled
12 | - reopened
13 |
14 | jobs:
15 | add_issue_to_project:
16 | runs-on: ubuntu-latest
17 | steps:
18 | - name: Add issue to GitHub Project
19 | uses: actions/add-to-project@v1.0.2
20 | with:
21 | project-url: https://github.com/orgs/Seeed-Studio/projects/17
22 | github-token: ${{ secrets.ISSUE_ASSEMBLE }}
23 | labeled: bug
24 | label-operator: NOT
--------------------------------------------------------------------------------
/modules/matrix.lua:
--------------------------------------------------------------------------------
1 |
2 | local matrix = {}
3 | local i2c_address = 33
4 | local i2c_speed = 100 -- 100 kbps
5 |
6 | -- display a character for some time (millisecond)
7 | function matrix.char(c, duration)
8 | duration = duration or 1000
9 | command = string.char(0x80, string.byte(c, 1), (duration / 256) % 256, duration % 256)
10 | i2c.setup(i2c_address, i2c_speed)
11 | i2c.send(command)
12 | end
13 |
14 | function matrix.emoji(e, duration)
15 | duration = duration or 1000
16 | command = string.char(0x84, e, (duration / 256) % 256, duration % 256)
17 | i2c.setup(i2c_address, i2c_speed)
18 | i2c.send(command)
19 | end
20 |
21 | function matrix.string(s, speed)
22 | speed = speed or 100
23 | if string.len(s) > 4 then
24 | s = string.sub(s, 1, 4)
25 | end
26 | command = string.char(0x81, string.len(s)) .. s .. string.char((speed / 256) % 256, speed % 256)
27 | i2c.setup(i2c_address, i2c_speed)
28 | i2c.send(command)
29 | end
30 |
31 | return matrix
32 |
33 |
--------------------------------------------------------------------------------
/lua/Makefile:
--------------------------------------------------------------------------------
1 |
2 | OBJECTS += $(WORKSPACE_PATH)lua/lapi.o $(WORKSPACE_PATH)lua/lcode.o $(WORKSPACE_PATH)lua/ldebug.o $(WORKSPACE_PATH)lua/ldo.o $(WORKSPACE_PATH)lua/ldump.o \
3 | $(WORKSPACE_PATH)lua/lfunc.o $(WORKSPACE_PATH)lua/lgc.o $(WORKSPACE_PATH)lua/llex.o $(WORKSPACE_PATH)lua/lmem.o $(WORKSPACE_PATH)lua/lobject.o $(WORKSPACE_PATH)lua/lopcodes.o \
4 | $(WORKSPACE_PATH)lua/lparser.o $(WORKSPACE_PATH)lua/lstate.o $(WORKSPACE_PATH)lua/lstring.o $(WORKSPACE_PATH)lua/ltable.o $(WORKSPACE_PATH)lua/ltm.o \
5 | $(WORKSPACE_PATH)lua/lundump.o $(WORKSPACE_PATH)lua/lvm.o $(WORKSPACE_PATH)lua/lzio.o $(WORKSPACE_PATH)lua/lrotable.o $(WORKSPACE_PATH)lua/lauxlib.o $(WORKSPACE_PATH)lua/lbaselib.o \
6 | $(WORKSPACE_PATH)lua/ldblib.o $(WORKSPACE_PATH)lua/liolib.o $(WORKSPACE_PATH)lua/lmathlib.o $(WORKSPACE_PATH)lua/loslib.o $(WORKSPACE_PATH)lua/ltablib.o \
7 | $(WORKSPACE_PATH)lua/lstrlib.o $(WORKSPACE_PATH)lua/loadlib.o $(WORKSPACE_PATH)lua/linit.o $(WORKSPACE_PATH)lua/print.o $(WORKSPACE_PATH)lua/linenoise.o
8 |
9 | INCLUDE_PATHS += -I$(WORKSPACE_PATH)lua
--------------------------------------------------------------------------------
/lua/lrodefs.h:
--------------------------------------------------------------------------------
1 | /* Read-only tables helper */
2 |
3 | #undef LUA_REG_TYPE
4 | #undef LSTRKEY
5 | #undef LNILKEY
6 | #undef LNUMKEY
7 | #undef LFUNCVAL
8 | #undef LNUMVAL
9 | #undef LROVAL
10 | #undef LNILVAL
11 | #undef LREGISTER
12 |
13 | #if (MIN_OPT_LEVEL > 0) && (LUA_OPTIMIZE_MEMORY >= MIN_OPT_LEVEL)
14 | #define LUA_REG_TYPE luaR_entry
15 | #define LSTRKEY LRO_STRKEY
16 | #define LNUMKEY LRO_NUMKEY
17 | #define LNILKEY LRO_NILKEY
18 | #define LFUNCVAL LRO_FUNCVAL
19 | #define LNUMVAL LRO_NUMVAL
20 | #define LROVAL LRO_ROVAL
21 | #define LNILVAL LRO_NILVAL
22 | #define LREGISTER(L, name, table)\
23 | return 0
24 | #else
25 | #define LUA_REG_TYPE luaL_reg
26 | #define LSTRKEY(x) x
27 | #define LNILKEY NULL
28 | #define LFUNCVAL(x) x
29 | #define LNILVAL NULL
30 | #define LREGISTER(L, name, table)\
31 | luaL_register(L, name, table);\
32 | return 1
33 | #endif
34 |
35 |
--------------------------------------------------------------------------------
/lua/ldebug.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Auxiliary functions from Debug Interface module
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef ldebug_h
8 | #define ldebug_h
9 |
10 |
11 | #include "lstate.h"
12 |
13 |
14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1)
15 |
16 | #define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0)
17 |
18 | #define resethookcount(L) (L->hookcount = L->basehookcount)
19 |
20 |
21 | LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o,
22 | const char *opname);
23 | LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
24 | LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1,
25 | const TValue *p2);
26 | LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1,
27 | const TValue *p2);
28 | LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...);
29 | LUAI_FUNC void luaG_errormsg (lua_State *L);
30 | LUAI_FUNC int luaG_checkcode (const Proto *pt);
31 | LUAI_FUNC int luaG_checkopenop (Instruction i);
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/lua/lstring.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** String table (keep all strings handled by Lua)
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lstring_h
8 | #define lstring_h
9 |
10 |
11 | #include "lgc.h"
12 | #include "lobject.h"
13 | #include "lstate.h"
14 |
15 |
16 | #define sizestring(s) (sizeof(union TString)+(luaS_isreadonly(s) ? sizeof(char **) : ((s)->len+1)*sizeof(char)))
17 |
18 | #define sizeudata(u) (sizeof(union Udata)+(u)->len)
19 |
20 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s)))
21 | #define luaS_newro(L, s) (luaS_newrolstr(L, s, strlen(s)))
22 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
23 | (sizeof(s)/sizeof(char))-1))
24 |
25 | #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT)
26 | #define luaS_readonly(s) l_setbit((s)->tsv.marked, READONLYBIT)
27 | #define luaS_isreadonly(s) testbit((s)->marked, READONLYBIT)
28 |
29 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
30 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e);
31 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
32 | LUAI_FUNC TString *luaS_newrolstr (lua_State *L, const char *str, size_t l);
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/lua/lualib.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Lua standard libraries
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 |
8 | #ifndef lualib_h
9 | #define lualib_h
10 |
11 | #include "lua.h"
12 |
13 |
14 | /* Key to file-handle type */
15 | #define LUA_FILEHANDLE "FILE*"
16 |
17 |
18 | #define LUA_COLIBNAME "coroutine"
19 | LUALIB_API int (luaopen_base) (lua_State *L);
20 |
21 | #define LUA_TABLIBNAME "table"
22 | LUALIB_API int (luaopen_table) (lua_State *L);
23 |
24 | #define LUA_IOLIBNAME "io"
25 | LUALIB_API int (luaopen_io) (lua_State *L);
26 |
27 | #define LUA_OSLIBNAME "os"
28 | LUALIB_API int (luaopen_os) (lua_State *L);
29 |
30 | #define LUA_STRLIBNAME "string"
31 | LUALIB_API int (luaopen_string) (lua_State *L);
32 |
33 | #define LUA_MATHLIBNAME "math"
34 | LUALIB_API int (luaopen_math) (lua_State *L);
35 |
36 | #define LUA_DBLIBNAME "debug"
37 | LUALIB_API int (luaopen_debug) (lua_State *L);
38 |
39 | #define LUA_LOADLIBNAME "package"
40 | LUALIB_API int (luaopen_package) (lua_State *L);
41 |
42 |
43 | /* open all previous libraries */
44 | LUALIB_API void (luaL_openlibs) (lua_State *L);
45 |
46 |
47 |
48 | #ifndef lua_assert
49 | #define lua_assert(x) ((void)0)
50 | #endif
51 |
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/modules/basic_sensors.lua:
--------------------------------------------------------------------------------
1 |
2 | local sensors = {}
3 | local i2c_address = 0x03
4 | local i2c_speed = 100 -- 100 kbps
5 |
6 | local id_table = {'acc_x'; 'acc_y', 'acc_z', 'light', 'temperature'}
7 |
8 | function sensors.update()
9 | i2c.setup(i2c_address, i2c_speed)
10 | info = i2c.txrx(0, 4)
11 | f, ff, fff, n = string.byte(info, 1, 4)
12 | for i = 0, n, 1 do
13 | if f % 2 then
14 | f = f / 2
15 | sensor_data = i2c.txrx(i * 8 + 4, 8)
16 | if not sensor_data then
17 | return
18 | end
19 | t, r, id1, id2 = string.byte(sensor_data, 1, 4)
20 | v1, v2, v3, v4 = string.byte(sensor_data, 5, 8)
21 | v = v1 + v2 * 0x100 + v3 * 0x10000 + v4 * 0x1000000
22 | sensors[id_table[id1 + 1]] = v
23 | end
24 |
25 | end
26 | end
27 |
28 | function sensors.get_temperature()
29 | sensors.update()
30 |
31 | return sensors.temperature
32 | end
33 |
34 | function sensors.get_light()
35 | sensors.update()
36 |
37 | return sensors.light
38 | end
39 |
40 | function sensors.get_acc()
41 | sensors.update()
42 |
43 | return sensors.acc_x, sensors.acc_y, sensors.acc_z
44 | end
45 |
46 | return sensors
47 |
48 |
--------------------------------------------------------------------------------
/lua/ltm.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Tag methods
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef ltm_h
8 | #define ltm_h
9 |
10 |
11 | #include "lobject.h"
12 |
13 |
14 | /*
15 | * WARNING: if you change the order of this enumeration,
16 | * grep "ORDER TM"
17 | */
18 | typedef enum {
19 | TM_INDEX,
20 | TM_NEWINDEX,
21 | TM_GC,
22 | TM_MODE,
23 | TM_EQ, /* last tag method with `fast' access */
24 | TM_ADD,
25 | TM_SUB,
26 | TM_MUL,
27 | TM_DIV,
28 | TM_MOD,
29 | TM_POW,
30 | TM_UNM,
31 | TM_LEN,
32 | TM_LT,
33 | TM_LE,
34 | TM_CONCAT,
35 | TM_CALL,
36 | TM_N /* number of elements in the enum */
37 | } TMS;
38 |
39 |
40 |
41 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \
42 | !luaR_isrotable(et) && ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))
43 |
44 | #define fasttm(l,et,e) gfasttm(G(l), et, e)
45 |
46 | LUAI_DATA const char *const luaT_typenames[];
47 |
48 |
49 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);
50 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o,
51 | TMS event);
52 | LUAI_FUNC void luaT_init (lua_State *L);
53 |
54 | #endif
55 |
--------------------------------------------------------------------------------
/lua/lvm.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Lua virtual machine
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lvm_h
8 | #define lvm_h
9 |
10 |
11 | #include "ldo.h"
12 | #include "lobject.h"
13 | #include "ltm.h"
14 |
15 |
16 | #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o)))
17 |
18 | #define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \
19 | (((o) = luaV_tonumber(o,n)) != NULL))
20 |
21 | #define equalobj(L,o1,o2) \
22 | (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2))
23 |
24 |
25 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
26 | LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2);
27 | LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n);
28 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj);
29 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key,
30 | StkId val);
31 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key,
32 | StkId val);
33 | LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls);
34 | LUAI_FUNC void luaV_concat (lua_State *L, int total, int last);
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/modules/blingbling.lua:
--------------------------------------------------------------------------------
1 |
2 | local blingbling = {}
3 | local i2c_address = 35
4 | local i2c_speed = 100 -- 100 kbps
5 |
6 | function blingbling.on()
7 | i2c.setup(i2c_address, i2c_speed)
8 | i2c.send(0x81, 1)
9 | end
10 |
11 | function blingbling.off()
12 | i2c.setup(i2c_address, i2c_speed)
13 | i2c.send(0x81, 0)
14 | end
15 |
16 | -- set the color of a pixel
17 | function blingbling.pixel(n, color)
18 | i2c.setup(i2c_address, i2c_speed)
19 | i2c.send(0x80, n, color.r, color.g, color.b)
20 | end
21 |
22 | function blingbling.monochrome(n, color, duration)
23 | duration = duration or 1000
24 | i2c.setup(i2c_address, i2c_speed)
25 | command = string.char(0x81, 2, n, color.r, color.g, color.b, duration / 256, duration % 256)
26 | i2c.send(command)
27 | end
28 |
29 | function blingbling.marquee(n, color, duration)
30 | duration = duration or 1000
31 | i2c.setup(i2c_address, i2c_speed)
32 | command = string.char(0x81, 3, n, color.r, color.g, color.b, duration / 256, duration % 256)
33 | i2c.send(command)
34 | end
35 |
36 | function blingbling.rainbow(n, duration)
37 | duration = duration or 1000
38 | i2c.setup(i2c_address, i2c_speed)
39 | i2c.send(0x81, 4, n, duration / 256, duration % 256)
40 | end
41 |
42 | function blingbling.rgb(red, green, blue)
43 | return {r=red; g=green; b=blue}
44 | end
45 |
46 | return blingbling
47 |
48 |
--------------------------------------------------------------------------------
/lua/lfunc.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Auxiliary functions to manipulate prototypes and closures
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lfunc_h
8 | #define lfunc_h
9 |
10 |
11 | #include "lobject.h"
12 |
13 | #include "lgc.h"
14 |
15 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \
16 | cast(int, sizeof(TValue)*((n)-1)))
17 |
18 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \
19 | cast(int, sizeof(TValue *)*((n)-1)))
20 |
21 | #define proto_readonly(p) l_setbit((p)->marked, READONLYBIT)
22 | #define proto_is_readonly(p) testbit((p)->marked, READONLYBIT)
23 |
24 | LUAI_FUNC Proto *luaF_newproto (lua_State *L);
25 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e);
26 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e);
27 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L);
28 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
29 | LUAI_FUNC void luaF_close (lua_State *L, StkId level);
30 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
31 | LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c);
32 | LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv);
33 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
34 | int pc);
35 |
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/src/tp_i2c.h:
--------------------------------------------------------------------------------
1 | #ifndef __TP_I2C_H__
2 | #define __TP_I2C_H__
3 |
4 | #include "vmtype.h"
5 | #include "vmdrv_tp.h"
6 |
7 | #define CTP_I2C_LOW 0
8 | #define CTP_I2C_HIGH 1
9 | #define CTP_I2C_ACK CTP_I2C_LOW
10 | #define CTP_I2C_NAK CTP_I2C_HIGH
11 |
12 | //delay
13 | void ctp_i2c_udelay(VMUINT32 delay);
14 |
15 | //power on I2C
16 | void ctp_i2c_power_on(VM_DRV_TP_BOOL ON, VMUINT32 ldo, VMUINT32 ldo_volt);
17 |
18 | //configure SW I2C or HW I2C parameters
19 | void ctp_i2c_configure(VMUINT32 slave_addr, VMUINT32 speed);
20 |
21 | // Start bit of I2C waveform
22 | extern void ctp_i2c_start(void);
23 |
24 | // Stop bit of I2C waveform
25 | extern void ctp_i2c_stop(void);
26 |
27 | // Send one byte from host to client
28 | extern VM_DRV_TP_BOOL ctp_i2c_send_byte(VMUINT8 ucData);
29 |
30 | // Receive one byte form client to host
31 | extern VMUINT8 ctp_i2c_receive_byte(VM_DRV_TP_BOOL bAck);
32 |
33 | // I2C send data fuction
34 | extern VM_DRV_TP_BOOL ctp_i2c_send(VMUINT8 ucDeviceAddr, VMUINT8 ucBufferIndex, VMUINT8* pucData, VMUINT32 unDataLength);
35 |
36 | // I2C receive data function
37 | extern VM_DRV_TP_BOOL ctp_i2c_receive(VMUINT8 ucDeviceAddr, VMUINT8 ucBufferIndex, VMUINT8* pucData, VMUINT32 unDataLength);
38 |
39 | // I2C send data for 16 bits address fuction
40 | extern VM_DRV_TP_BOOL ctp_i2c_send_ext(VMUINT8 ucDeviceAddr, VMUINT16 ucBufferIndex, VMUINT8* pucData, VMUINT32 unDataLength);
41 |
42 | // I2C receive data for 16 bits address function
43 | extern VM_DRV_TP_BOOL ctp_i2c_receive_ext(VMUINT8 ucDeviceAddr, VMUINT16 ucBufferIndex, VMUINT8* pucData, VMUINT32 unDataLength);
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/lua/ltable.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Lua tables (hash)
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef ltable_h
8 | #define ltable_h
9 |
10 | #include "lobject.h"
11 |
12 |
13 | #define gnode(t,i) (&(t)->node[i])
14 | #define gkey(n) (&(n)->i_key.tvk)
15 | #define gval(n) (&(n)->i_val)
16 | #define gnext(n) ((n)->i_key.nk.next)
17 |
18 | #define key2tval(n) (&(n)->i_key.tvk)
19 |
20 |
21 | LUAI_FUNC const TValue *luaH_getnum (Table *t, int key);
22 | LUAI_FUNC const TValue *luaH_getnum_ro (void *t, int key);
23 | LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key);
24 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
25 | LUAI_FUNC const TValue *luaH_getstr_ro (void *t, TString *key);
26 | LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key);
27 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
28 | LUAI_FUNC const TValue *luaH_get_ro (void *t, const TValue *key);
29 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);
30 | LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash);
31 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize);
32 | LUAI_FUNC void luaH_free (lua_State *L, Table *t);
33 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
34 | LUAI_FUNC int luaH_next_ro (lua_State *L, void *t, StkId key);
35 | LUAI_FUNC int luaH_getn (Table *t);
36 | LUAI_FUNC int luaH_getn_ro (void *t);
37 |
38 | #if defined(LUA_DEBUG)
39 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
40 | LUAI_FUNC int luaH_isdummy (Node *n);
41 | #endif
42 |
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/bindings/button.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | #include "vmdcl.h"
4 | #include "vmdcl_kbd.h"
5 | #include "vmkeypad.h"
6 |
7 | #include "lua.h"
8 | #include "lauxlib.h"
9 |
10 |
11 | extern lua_State *L;
12 | int g_button_cb_ref = LUA_NOREF;
13 |
14 |
15 | VMINT handle_keypad_event(VM_KEYPAD_EVENT event, VMINT code)
16 | {
17 | /* output log to monitor or catcher */
18 | // vm_log_info("key event=%d,key code=%d", event, code); /* event value refer to VM_KEYPAD_EVENT */
19 |
20 | if(code == 30) {
21 | // 3 - long pressed
22 | // 2 - down
23 | // 1 - up
24 | lua_rawgeti(L, LUA_REGISTRYINDEX, g_button_cb_ref);
25 | lua_pushinteger(L, event);
26 | lua_call(L, 1, 0);
27 | }
28 | return 0;
29 | }
30 |
31 | int button_attach(lua_State *L)
32 | {
33 | lua_pushvalue(L, 1);
34 | g_button_cb_ref = luaL_ref(L, LUA_REGISTRYINDEX);
35 |
36 | return 0;
37 | }
38 |
39 |
40 | #undef MIN_OPT_LEVEL
41 | #define MIN_OPT_LEVEL 0
42 | #include "lrodefs.h"
43 |
44 | const LUA_REG_TYPE button_map[] =
45 | {
46 | {LSTRKEY("attach"), LFUNCVAL(button_attach)},
47 | {LNILKEY, LNILVAL}
48 | };
49 |
50 |
51 | LUALIB_API int luaopen_button(lua_State *L)
52 | {
53 | VM_DCL_HANDLE kbd_handle;
54 | vm_dcl_kbd_control_pin_t kbdmap;
55 |
56 | kbd_handle = vm_dcl_open(VM_DCL_KBD, 0);
57 | kbdmap.col_map = 0x09;
58 | kbdmap.row_map = 0x05;
59 | vm_dcl_control(kbd_handle, VM_DCL_KBD_COMMAND_CONFIG_PIN, (void*)(&kbdmap));
60 |
61 | vm_dcl_close(kbd_handle);
62 |
63 | vm_keypad_register_event_callback(handle_keypad_event);
64 |
65 | luaL_register(L, "button", button_map);
66 | return 1;
67 | }
68 |
--------------------------------------------------------------------------------
/lua/lmem.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Interface to Memory Manager
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lmem_h
8 | #define lmem_h
9 |
10 |
11 | #include
12 |
13 | #include "llimits.h"
14 | #include "lua.h"
15 |
16 | #define MEMERRMSG "not enough memory"
17 |
18 |
19 | #define luaM_reallocv(L,b,on,n,e) \
20 | ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \
21 | luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \
22 | luaM_toobig(L))
23 |
24 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0)
25 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0)
26 | #define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t))
27 |
28 | #define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t))
29 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t)))
30 | #define luaM_newvector(L,n,t) \
31 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))
32 |
33 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \
34 | if ((nelems)+1 > (size)) \
35 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))
36 |
37 | #define luaM_reallocvector(L, v,oldn,n,t) \
38 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
39 |
40 |
41 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
42 | size_t size);
43 | LUAI_FUNC void *luaM_toobig (lua_State *L);
44 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,
45 | size_t size_elem, int limit,
46 | const char *errormsg);
47 |
48 | #endif
49 |
50 |
--------------------------------------------------------------------------------
/lua/lundump.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** load precompiled Lua chunks
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lundump_h
8 | #define lundump_h
9 |
10 | #include
11 |
12 | #include "lobject.h"
13 | #include "lzio.h"
14 |
15 | typedef uint32_t strsize_t;
16 |
17 | /* info about target machine for cross-compilation */
18 | typedef struct {
19 | int little_endian;
20 | int sizeof_int;
21 | int sizeof_strsize_t;
22 | int sizeof_lua_Number;
23 | int lua_Number_integral;
24 | int is_arm_fpa;
25 | } DumpTargetInfo;
26 |
27 | /* load one chunk; from lundump.c */
28 | LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name);
29 |
30 | /* make header; from lundump.c */
31 | LUAI_FUNC void luaU_header (char* h);
32 |
33 | /* dump one chunk to a different target; from ldump.c */
34 | int luaU_dump_crosscompile (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip, DumpTargetInfo target);
35 |
36 | /* dump one chunk; from ldump.c */
37 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
38 |
39 | #ifdef luac_c
40 | /* print one chunk; from print.c */
41 | LUAI_FUNC void luaU_print (const Proto* f, int full);
42 | #endif
43 |
44 | /* for header of binary files -- this is Lua 5.1 */
45 | #define LUAC_VERSION 0x51
46 |
47 | /* for header of binary files -- this is the official format */
48 | #define LUAC_FORMAT 0
49 |
50 | /* size of header of binary files */
51 | #define LUAC_HEADERSIZE 12
52 |
53 | /* error codes from cross-compiler */
54 | /* target integer is too small to hold a value */
55 | #define LUA_ERR_CC_INTOVERFLOW 101
56 |
57 | /* target lua_Number is integral but a constant is non-integer */
58 | #define LUA_ERR_CC_NOTINTEGER 102
59 |
60 | #endif
61 |
--------------------------------------------------------------------------------
/lua/lzio.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** a generic input stream interface
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 |
8 | #include
9 |
10 | #define lzio_c
11 | #define LUA_CORE
12 |
13 | #include "lua.h"
14 |
15 | #include "llimits.h"
16 | #include "lmem.h"
17 | #include "lstate.h"
18 | #include "lzio.h"
19 |
20 |
21 | int luaZ_fill (ZIO *z) {
22 | size_t size;
23 | lua_State *L = z->L;
24 | const char *buff;
25 | lua_unlock(L);
26 | buff = z->reader(L, z->data, &size);
27 | lua_lock(L);
28 | if (buff == NULL || size == 0) return EOZ;
29 | z->n = size - 1;
30 | z->p = buff;
31 | return char2int(*(z->p++));
32 | }
33 |
34 |
35 | int luaZ_lookahead (ZIO *z) {
36 | if (z->n == 0) {
37 | if (luaZ_fill(z) == EOZ)
38 | return EOZ;
39 | else {
40 | z->n++; /* luaZ_fill removed first byte; put back it */
41 | z->p--;
42 | }
43 | }
44 | return char2int(*z->p);
45 | }
46 |
47 |
48 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
49 | z->L = L;
50 | z->reader = reader;
51 | z->data = data;
52 | z->n = z->i = 0;
53 | z->p = NULL;
54 | }
55 |
56 |
57 | /* --------------------------------------------------------------- read --- */
58 | size_t luaZ_read (ZIO *z, void *b, size_t n) {
59 | while (n) {
60 | size_t m;
61 | if (luaZ_lookahead(z) == EOZ)
62 | return n; /* return number of missing bytes */
63 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
64 | if (b)
65 | memcpy(b, z->p, m);
66 | z->n -= m;
67 | z->i += m;
68 | z->p += m;
69 | if (b)
70 | b = (char *)b + m;
71 | n -= m;
72 | }
73 | return 0;
74 | }
75 |
76 | /* ------------------------------------------------------------------------ */
77 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) {
78 | if (n > buff->buffsize) {
79 | if (n < LUA_MINBUFFER) n = LUA_MINBUFFER;
80 | luaZ_resizebuffer(L, buff, n);
81 | }
82 | return buff->buffer;
83 | }
84 |
85 |
86 |
--------------------------------------------------------------------------------
/lua/ldo.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Stack and Call structure of Lua
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef ldo_h
8 | #define ldo_h
9 |
10 |
11 | #include "lobject.h"
12 | #include "lstate.h"
13 | #include "lzio.h"
14 |
15 |
16 | #define luaD_checkstack(L,n) \
17 | if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \
18 | luaD_growstack(L, n); \
19 | else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1));
20 |
21 |
22 | #define incr_top(L) {luaD_checkstack(L,1); L->top++;}
23 |
24 | #define savestack(L,p) ((char *)(p) - (char *)L->stack)
25 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n)))
26 |
27 | #define saveci(L,p) ((char *)(p) - (char *)L->base_ci)
28 | #define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n)))
29 |
30 |
31 | /* results from luaD_precall */
32 | #define PCRLUA 0 /* initiated a call to a Lua function */
33 | #define PCRC 1 /* did a call to a C function */
34 | #define PCRYIELD 2 /* C funtion yielded */
35 |
36 |
37 | /* type of protected functions, to be ran by `runprotected' */
38 | typedef void (*Pfunc) (lua_State *L, void *ud);
39 |
40 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name);
41 | LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line);
42 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults);
43 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
44 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,
45 | ptrdiff_t oldtop, ptrdiff_t ef);
46 | LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult);
47 | LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize);
48 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);
49 | LUAI_FUNC void luaD_growstack (lua_State *L, int n);
50 |
51 | LUAI_FUNC void luaD_throw (lua_State *L, int errcode);
52 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
53 |
54 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
55 |
56 | #endif
57 |
58 |
--------------------------------------------------------------------------------
/lua/lzio.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Buffered streams
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 |
8 | #ifndef lzio_h
9 | #define lzio_h
10 |
11 | #include "lua.h"
12 |
13 | #include "lmem.h"
14 |
15 |
16 | #define EOZ (-1) /* end of stream */
17 |
18 | typedef struct Zio ZIO;
19 |
20 | #define char2int(c) cast(int, cast(unsigned char, (c)))
21 |
22 | #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z))
23 |
24 | typedef struct Mbuffer {
25 | char *buffer;
26 | size_t n;
27 | size_t buffsize;
28 | } Mbuffer;
29 |
30 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->n = 0, (buff)->buffsize = 0)
31 |
32 | #define luaZ_buffer(buff) ((buff)->buffer)
33 | #define luaZ_sizebuffer(buff) ((buff)->buffsize)
34 | #define luaZ_bufflen(buff) ((buff)->n)
35 |
36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0)
37 |
38 |
39 | #define luaZ_resizebuffer(L, buff, size) \
40 | (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
41 | (buff)->buffsize = size)
42 |
43 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
44 |
45 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
46 | #define luaZ_get_base_address(zio) ((const char *)((zio)->reader(NULL, (zio)->data, NULL)))
47 | #define luaZ_direct_mode(zio) (luaZ_get_base_address(zio) != NULL)
48 | #define luaZ_get_crt_address(zio) (luaZ_get_base_address(zio) + (zio)->i)
49 |
50 | LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
51 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
52 | void *data);
53 | LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
54 | LUAI_FUNC int luaZ_lookahead (ZIO *z);
55 |
56 |
57 |
58 | /* --------- Private Part ------------------ */
59 |
60 | struct Zio {
61 | size_t n; /* bytes still unread */
62 | size_t i; /* buffer offset */
63 | const char *p; /* current position in buffer */
64 | lua_Reader reader;
65 | void* data; /* additional data */
66 | lua_State *L; /* Lua state (for reader) */
67 | };
68 |
69 |
70 | LUAI_FUNC int luaZ_fill (ZIO *z);
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/lua/ltm.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Tag methods
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 |
8 | #include
9 |
10 | #define ltm_c
11 | #define LUA_CORE
12 |
13 | #include "lua.h"
14 |
15 | #include "lobject.h"
16 | #include "lstate.h"
17 | #include "lstring.h"
18 | #include "ltable.h"
19 | #include "ltm.h"
20 | #include "lrotable.h"
21 |
22 |
23 |
24 | const char *const luaT_typenames[] = {
25 | "nil", "boolean", "romtable", "lightfunction", "userdata", "number",
26 | "string", "table", "function", "userdata", "thread",
27 | "proto", "upval"
28 | };
29 |
30 |
31 | void luaT_init (lua_State *L) {
32 | static const char *const luaT_eventname[] = { /* ORDER TM */
33 | "__index", "__newindex",
34 | "__gc", "__mode", "__eq",
35 | "__add", "__sub", "__mul", "__div", "__mod",
36 | "__pow", "__unm", "__len", "__lt", "__le",
37 | "__concat", "__call"
38 | };
39 | int i;
40 | for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]);
42 | luaS_fix(G(L)->tmname[i]); /* never collect these names */
43 | }
44 | }
45 |
46 |
47 | /*
48 | ** function to be used with macro "fasttm": optimized for absence of
49 | ** tag methods
50 | */
51 | const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
52 | const TValue *tm = luaR_isrotable(events) ? luaH_getstr_ro(events, ename) : luaH_getstr(events, ename);
53 | lua_assert(event <= TM_EQ);
54 | if (ttisnil(tm)) { /* no tag method? */
55 | if (!luaR_isrotable(events))
56 | events->flags |= cast_byte(1u<metatable;
68 | break;
69 | case LUA_TROTABLE:
70 | mt = (Table*)luaR_getmeta(rvalue(o));
71 | break;
72 | case LUA_TUSERDATA:
73 | mt = uvalue(o)->metatable;
74 | break;
75 | default:
76 | mt = G(L)->mt[ttype(o)];
77 | }
78 | if (!mt)
79 | return luaO_nilobject;
80 | else if (luaR_isrotable(mt))
81 | return luaH_getstr_ro(mt, G(L)->tmname[event]);
82 | else
83 | return luaH_getstr(mt, G(L)->tmname[event]);
84 | }
85 |
--------------------------------------------------------------------------------
/linkit/include/vmalarm.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * Copyright Statement:
3 | * --------------------
4 | * This software is protected by Copyright and the information contained
5 | * herein is confidential. The software may not be copied and the information
6 | * contained herein may not be used or disclosed except with the written
7 | * permission of MediaTek Inc. (C) 2005-2015
8 | *
9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21 | *
22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27 | *
28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33 | *
34 | *****************************************************************************/
35 |
36 | #ifndef VMALARM_SDK_H_
37 | #define VMALARM_SDK_H_
38 |
39 | #ifdef __cplusplus
40 | extern "C" {
41 | #endif
42 |
43 | #include "vmsys.h"
44 |
45 |
46 |
47 | #ifdef __cplusplus
48 | }
49 | #endif
50 |
51 | #endif /* VMALARM_SDK_H_ */
52 |
--------------------------------------------------------------------------------
/lua/lrotable.h:
--------------------------------------------------------------------------------
1 | /* Read-only tables for Lua */
2 |
3 | #ifndef lrotable_h
4 | #define lrotable_h
5 |
6 | #include "lua.h"
7 | #include "llimits.h"
8 | #include "lobject.h"
9 | #include "luaconf.h"
10 |
11 | /* Macros one can use to define rotable entries */
12 | #ifndef LUA_PACK_VALUE
13 | #define LRO_FUNCVAL(v) {{.p = v}, LUA_TLIGHTFUNCTION}
14 | #define LRO_NUMVAL(v) {{.n = v}, LUA_TNUMBER}
15 | #define LRO_ROVAL(v) {{.p = (void*)v}, LUA_TROTABLE}
16 | #define LRO_NILVAL {{.p = NULL}, LUA_TNIL}
17 | #else // #ifndef LUA_PACK_VALUE
18 | #define LRO_NUMVAL(v) {.value.n = v}
19 | #ifdef ELUA_ENDIAN_LITTLE
20 | #define LRO_FUNCVAL(v) {{(int)v, add_sig(LUA_TLIGHTFUNCTION)}}
21 | #define LRO_ROVAL(v) {{(int)v, add_sig(LUA_TROTABLE)}}
22 | #define LRO_NILVAL {{0, add_sig(LUA_TNIL)}}
23 | #else // #ifdef ELUA_ENDIAN_LITTLE
24 | #define LRO_FUNCVAL(v) {{add_sig(LUA_TLIGHTFUNCTION), (int)v}}
25 | #define LRO_ROVAL(v) {{add_sig(LUA_TROTABLE), (int)v}}
26 | #define LRO_NILVAL {{add_sig(LUA_TNIL), 0}}
27 | #endif // #ifdef ELUA_ENDIAN_LITTLE
28 | #endif // #ifndef LUA_PACK_VALUE
29 |
30 | #define LRO_STRKEY(k) {LUA_TSTRING, {.strkey = k}}
31 | #define LRO_NUMKEY(k) {LUA_TNUMBER, {.numkey = k}}
32 | #define LRO_NILKEY {LUA_TNIL, {.strkey=NULL}}
33 |
34 | /* Maximum length of a rotable name and of a string key*/
35 | #define LUA_MAX_ROTABLE_NAME 32
36 |
37 | /* Type of a numeric key in a rotable */
38 | typedef int luaR_numkey;
39 |
40 | /* The next structure defines the type of a key */
41 | typedef struct
42 | {
43 | int type;
44 | union
45 | {
46 | const char* strkey;
47 | luaR_numkey numkey;
48 | } id;
49 | } luaR_key;
50 |
51 | /* An entry in the read only table */
52 | typedef struct
53 | {
54 | const luaR_key key;
55 | const TValue value;
56 | } luaR_entry;
57 |
58 | /* A rotable */
59 | typedef struct
60 | {
61 | const char *name;
62 | const luaR_entry *pentries;
63 | } luaR_table;
64 |
65 | void* luaR_findglobal(const char *key, unsigned len);
66 | int luaR_findfunction(lua_State *L, const luaR_entry *ptable);
67 | const TValue* luaR_findentry(void *data, const char *strkey, luaR_numkey numkey, unsigned *ppos);
68 | void luaR_getcstr(char *dest, const TString *src, size_t maxsize);
69 | void luaR_next(lua_State *L, void *data, TValue *key, TValue *val);
70 | void* luaR_getmeta(void *data);
71 | #ifdef LUA_META_ROTABLES
72 | int luaR_isrotable(void *p);
73 | #else
74 | #define luaR_isrotable(p) (0)
75 | #endif
76 |
77 | #endif
78 |
--------------------------------------------------------------------------------
/lua/llex.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Lexical Analyzer
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef llex_h
8 | #define llex_h
9 |
10 | #include "lobject.h"
11 | #include "lzio.h"
12 |
13 |
14 | #define FIRST_RESERVED 257
15 |
16 | /* maximum length of a reserved word */
17 | #define TOKEN_LEN (sizeof("function")/sizeof(char))
18 |
19 |
20 | /*
21 | * WARNING: if you change the order of this enumeration,
22 | * grep "ORDER RESERVED"
23 | */
24 | enum RESERVED {
25 | /* terminal symbols denoted by reserved words */
26 | TK_AND = FIRST_RESERVED, TK_BREAK,
27 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
28 | TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
29 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
30 | /* other terminal symbols */
31 | TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER,
32 | TK_NAME, TK_STRING, TK_EOS
33 | };
34 |
35 | /* number of reserved words */
36 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1))
37 |
38 |
39 | /* array with token `names' */
40 | LUAI_DATA const char *const luaX_tokens [];
41 |
42 |
43 | typedef union {
44 | lua_Number r;
45 | TString *ts;
46 | } SemInfo; /* semantics information */
47 |
48 |
49 | typedef struct Token {
50 | int token;
51 | SemInfo seminfo;
52 | } Token;
53 |
54 |
55 | typedef struct LexState {
56 | int current; /* current character (charint) */
57 | int linenumber; /* input line counter */
58 | int lastline; /* line of last token `consumed' */
59 | Token t; /* current token */
60 | Token lookahead; /* look ahead token */
61 | struct FuncState *fs; /* `FuncState' is private to the parser */
62 | struct lua_State *L;
63 | ZIO *z; /* input stream */
64 | Mbuffer *buff; /* buffer for tokens */
65 | TString *source; /* current source name */
66 | char decpoint; /* locale decimal point */
67 | } LexState;
68 |
69 |
70 | LUAI_FUNC void luaX_init (lua_State *L);
71 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,
72 | TString *source);
73 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);
74 | LUAI_FUNC void luaX_next (LexState *ls);
75 | LUAI_FUNC void luaX_lookahead (LexState *ls);
76 | LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token);
77 | LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s);
78 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
79 |
80 |
81 | #endif
82 |
--------------------------------------------------------------------------------
/lua/lmem.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Interface to Memory Manager
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 |
8 | #include
9 |
10 | #define lmem_c
11 | #define LUA_CORE
12 |
13 | #include "lua.h"
14 |
15 | #include "ldebug.h"
16 | #include "ldo.h"
17 | #include "lmem.h"
18 | #include "lobject.h"
19 | #include "lstate.h"
20 |
21 |
22 |
23 | /*
24 | ** About the realloc function:
25 | ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize);
26 | ** (`osize' is the old size, `nsize' is the new size)
27 | **
28 | ** Lua ensures that (ptr == NULL) iff (osize == 0).
29 | **
30 | ** * frealloc(ud, NULL, 0, x) creates a new block of size `x'
31 | **
32 | ** * frealloc(ud, p, x, 0) frees the block `p'
33 | ** (in this specific case, frealloc must return NULL).
34 | ** particularly, frealloc(ud, NULL, 0, 0) does nothing
35 | ** (which is equivalent to free(NULL) in ANSI C)
36 | **
37 | ** frealloc returns NULL if it cannot create or reallocate the area
38 | ** (any reallocation to an equal or smaller size cannot fail!)
39 | */
40 |
41 |
42 |
43 | #define MINSIZEARRAY 4
44 |
45 |
46 | void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,
47 | int limit, const char *errormsg) {
48 | void *newblock;
49 | int newsize;
50 | if (*size >= limit/2) { /* cannot double it? */
51 | if (*size >= limit) /* cannot grow even a little? */
52 | luaG_runerror(L, errormsg);
53 | newsize = limit; /* still have at least one free place */
54 | }
55 | else {
56 | newsize = (*size)*2;
57 | if (newsize < MINSIZEARRAY)
58 | newsize = MINSIZEARRAY; /* minimum size */
59 | }
60 | newblock = luaM_reallocv(L, block, *size, newsize, size_elems);
61 | *size = newsize; /* update only when everything else is OK */
62 | return newblock;
63 | }
64 |
65 |
66 | void *luaM_toobig (lua_State *L) {
67 | luaG_runerror(L, "memory allocation error: block too big");
68 | return NULL; /* to avoid warnings */
69 | }
70 |
71 |
72 |
73 | /*
74 | ** generic allocation routine.
75 | */
76 | void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
77 | global_State *g = G(L);
78 | lua_assert((osize == 0) == (block == NULL));
79 | block = (*g->frealloc)(g->ud, block, osize, nsize);
80 | if (block == NULL && nsize > 0)
81 | luaD_throw(L, LUA_ERRMEM);
82 | lua_assert((nsize == 0) == (block == NULL));
83 | g->totalbytes = (g->totalbytes - osize) + nsize;
84 | return block;
85 | }
86 |
87 |
--------------------------------------------------------------------------------
/lua/linenoise.h:
--------------------------------------------------------------------------------
1 | /* linenoise.h -- guerrilla line editing library against the idea that a
2 | * line editing lib needs to be 20,000 lines of C code.
3 | *
4 | * See linenoise.c for more information.
5 | *
6 | * Copyright (c) 2010, Salvatore Sanfilippo
7 | * All rights reserved.
8 | *
9 | * Redistribution and use in source and binary forms, with or without
10 | * modification, are permitted provided that the following conditions are met:
11 | *
12 | * * Redistributions of source code must retain the above copyright notice,
13 | * this list of conditions and the following disclaimer.
14 | * * Redistributions in binary form must reproduce the above copyright
15 | * notice, this list of conditions and the following disclaimer in the
16 | * documentation and/or other materials provided with the distribution.
17 | * * Neither the name of Redis nor the names of its contributors may be used
18 | * to endorse or promote products derived from this software without
19 | * specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 | * POSSIBILITY OF SUCH DAMAGE.
32 | */
33 |
34 | #ifndef __LINENOISE_H
35 | #define __LINENOISE_H
36 |
37 | // Error codes
38 | #define LINENOISE_HISTORY_NOT_ENABLED ( -2 )
39 | #define LINENOISE_HISTORY_EMPTY ( -3 )
40 |
41 | // Components that use linenoise in eLua
42 | #define LINENOISE_ID_LUA 0
43 | #define LINENOISE_ID_SHELL 1
44 | #define LINENOISE_TOTAL_COMPONENTS 2
45 |
46 | int linenoise_getline( int id, char* buffer, int maxinput, const char* prompt );
47 | int linenoise_addhistory( int id, const char *line );
48 | void linenoise_cleanup( int id );
49 | int linenoise_savehistory( int id, const char* filename );
50 |
51 | #endif /* __LINENOISE_H */
52 |
--------------------------------------------------------------------------------
/bindings/timer.c:
--------------------------------------------------------------------------------
1 |
2 | #include "vmtimer.h"
3 |
4 | #include "lua.h"
5 | #include "lauxlib.h"
6 |
7 | #define LUA_TIMER "timer"
8 |
9 | typedef struct {
10 | VM_TIMER_ID_PRECISE timer_id;
11 | int cb_ref;
12 | lua_State *L;
13 | } timer_info_t;
14 |
15 | static void __timer_callback(VM_TIMER_ID_PRECISE sys_timer_id, void* user_data)
16 | {
17 | timer_info_t *p = (timer_info_t *)user_data;
18 | lua_State *L = p->L;
19 |
20 | lua_rawgeti(L, LUA_REGISTRYINDEX, p->cb_ref);
21 | lua_call(L, 0, 0);
22 | }
23 |
24 | int timer_create(lua_State *L)
25 | {
26 | timer_info_t *p;
27 | int ref;
28 | unsigned interval = luaL_checkinteger(L, 1);
29 |
30 | lua_pushvalue(L, 2);
31 |
32 | ref = luaL_ref(L, LUA_REGISTRYINDEX);
33 |
34 | p = (timer_info_t *)lua_newuserdata(L, sizeof(timer_info_t));
35 |
36 | luaL_getmetatable(L, LUA_TIMER);
37 | lua_setmetatable(L, -2);
38 |
39 | p->L = L;
40 | p->cb_ref = ref;
41 | p->timer_id = vm_timer_create_precise(interval, __timer_callback, p);
42 |
43 | return 1;
44 | }
45 |
46 | int timer_delete(lua_State *L)
47 | {
48 | timer_info_t *p = ((timer_info_t *)luaL_checkudata(L, -1, LUA_TIMER));
49 |
50 | vm_timer_delete_precise(p->timer_id);
51 |
52 | return 0;
53 | }
54 |
55 | int timer_gc(lua_State *L)
56 | {
57 | timer_info_t *p = ((timer_info_t *)luaL_checkudata(L, -1, LUA_TIMER));
58 |
59 | // vm_timer_delete_precise(p->timer_id);
60 | return 0;
61 | }
62 |
63 | int timer_tostring(lua_State *L)
64 | {
65 | timer_info_t *p = ((timer_info_t *)luaL_checkudata(L, -1, LUA_TIMER));
66 | lua_pushfstring(L, "timer (%p)", p->timer_id);
67 | return 1;
68 | }
69 |
70 | #undef MIN_OPT_LEVEL
71 | #define MIN_OPT_LEVEL 0
72 | #include "lrodefs.h"
73 |
74 | const LUA_REG_TYPE timer_map[] =
75 | {
76 | {LSTRKEY("create"), LFUNCVAL(timer_create)},
77 | {LSTRKEY("delete"), LFUNCVAL(timer_delete)},
78 | {LNILKEY, LNILVAL}
79 | };
80 |
81 | const LUA_REG_TYPE timer_table[] = {
82 | {LSTRKEY("delete"), LFUNCVAL(timer_delete)},
83 | {LSTRKEY("__gc"), LFUNCVAL(timer_gc)},
84 | {LSTRKEY("__tostring"), LFUNCVAL(timer_tostring)},
85 | {LNILKEY, LNILVAL}
86 | };
87 |
88 | LUALIB_API int luaopen_timer(lua_State *L)
89 | {
90 | luaL_newmetatable(L, LUA_TIMER); /* create metatable for file handles */
91 | lua_pushvalue(L, -1); /* push metatable */
92 | lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
93 | luaL_register(L, NULL, timer_table); /* file methods */
94 |
95 | luaL_register(L, "timer", timer_map);
96 | return 1;
97 | }
98 |
--------------------------------------------------------------------------------
/lua/lparser.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Lua Parser
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lparser_h
8 | #define lparser_h
9 |
10 | #include "llimits.h"
11 | #include "lobject.h"
12 | #include "lzio.h"
13 |
14 |
15 | /*
16 | ** Expression descriptor
17 | */
18 |
19 | typedef enum {
20 | VVOID, /* no value */
21 | VNIL,
22 | VTRUE,
23 | VFALSE,
24 | VK, /* info = index of constant in `k' */
25 | VKNUM, /* nval = numerical value */
26 | VLOCAL, /* info = local register */
27 | VUPVAL, /* info = index of upvalue in `upvalues' */
28 | VGLOBAL, /* info = index of table; aux = index of global name in `k' */
29 | VINDEXED, /* info = table register; aux = index register (or `k') */
30 | VJMP, /* info = instruction pc */
31 | VRELOCABLE, /* info = instruction pc */
32 | VNONRELOC, /* info = result register */
33 | VCALL, /* info = instruction pc */
34 | VVARARG /* info = instruction pc */
35 | } expkind;
36 |
37 | typedef struct expdesc {
38 | expkind k;
39 | union {
40 | struct { int info, aux; } s;
41 | lua_Number nval;
42 | } u;
43 | int t; /* patch list of `exit when true' */
44 | int f; /* patch list of `exit when false' */
45 | } expdesc;
46 |
47 |
48 | typedef struct upvaldesc {
49 | lu_byte k;
50 | lu_byte info;
51 | } upvaldesc;
52 |
53 |
54 | struct BlockCnt; /* defined in lparser.c */
55 |
56 |
57 | /* state needed to generate code for a given function */
58 | typedef struct FuncState {
59 | Proto *f; /* current function header */
60 | Table *h; /* table to find (and reuse) elements in `k' */
61 | struct FuncState *prev; /* enclosing function */
62 | struct LexState *ls; /* lexical state */
63 | struct lua_State *L; /* copy of the Lua state */
64 | struct BlockCnt *bl; /* chain of current blocks */
65 | int pc; /* next position to code (equivalent to `ncode') */
66 | int lasttarget; /* `pc' of last `jump target' */
67 | int jpc; /* list of pending jumps to `pc' */
68 | int freereg; /* first free register */
69 | int nk; /* number of elements in `k' */
70 | int np; /* number of elements in `p' */
71 | short nlocvars; /* number of elements in `locvars' */
72 | lu_byte nactvar; /* number of active local variables */
73 | upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */
74 | unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */
75 | } FuncState;
76 |
77 |
78 | LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
79 | const char *name);
80 |
81 |
82 | #endif
83 |
--------------------------------------------------------------------------------
/src/main.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #include "vmtype.h"
6 | #include "vmlog.h"
7 | #include "vmsystem.h"
8 | #include "vmgsm_tel.h"
9 | #include "vmgsm_sim.h"
10 | #include "vmtimer.h"
11 | #include "vmthread.h"
12 |
13 | #include "shell.h"
14 |
15 | #include "lua.h"
16 | #include "lualib.h"
17 | #include "lauxlib.h"
18 |
19 | extern void retarget_setup();
20 | extern int luaopen_audio(lua_State* L);
21 | extern int luaopen_gsm(lua_State* L);
22 | extern int luaopen_timer(lua_State* L);
23 | extern int luaopen_gpio(lua_State* L);
24 | extern int luaopen_screen(lua_State* L);
25 | extern int luaopen_i2c(lua_State* L);
26 | extern int luaopen_tcp(lua_State* L);
27 | extern int luaopen_https(lua_State* L);
28 | extern int luaopen_bluetooth(lua_State* L);
29 | extern int luaopen_button(lua_State* L);
30 |
31 | lua_State* L = NULL;
32 |
33 | VM_TIMER_ID_PRECISE sys_timer_id = 0;
34 |
35 |
36 | void sys_timer_callback(VM_TIMER_ID_PRECISE sys_timer_id, void* user_data)
37 | {
38 | vm_log_info("tick");
39 | }
40 |
41 | static int msleep_c(lua_State* L)
42 | {
43 | long ms = lua_tointeger(L, -1);
44 | vm_thread_sleep(ms);
45 | return 0;
46 | }
47 |
48 | void lua_setup()
49 | {
50 | VM_THREAD_HANDLE handle;
51 |
52 | L = lua_open();
53 | lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
54 | luaL_openlibs(L); /* open libraries */
55 |
56 | luaopen_audio(L);
57 | luaopen_gsm(L);
58 | luaopen_timer(L);
59 | luaopen_gpio(L);
60 | luaopen_screen(L);
61 | luaopen_i2c(L);
62 | luaopen_tcp(L);
63 | luaopen_https(L);
64 | luaopen_bluetooth(L);
65 | luaopen_button(L);
66 |
67 | lua_register(L, "msleep", msleep_c);
68 |
69 | lua_gc(L, LUA_GCRESTART, 0);
70 |
71 | luaL_dofile(L, "init.lua");
72 |
73 | handle = vm_thread_create(shell_thread, L, 0);
74 | vm_thread_change_priority(handle, 245);
75 | }
76 |
77 | void handle_sysevt(VMINT message, VMINT param)
78 | {
79 | switch(message) {
80 | case VM_EVENT_CREATE:
81 | // sys_timer_id = vm_timer_create_precise(1000, sys_timer_callback, NULL);
82 | lua_setup();
83 | break;
84 | case SHELL_MESSAGE_ID:
85 | shell_docall(L);
86 | break;
87 | case VM_EVENT_QUIT:
88 | break;
89 | }
90 | }
91 |
92 | /* Entry point */
93 | void vm_main(void)
94 | {
95 |
96 | retarget_setup();
97 | fputs("hello, linkit assist\n", stdout);
98 |
99 | /* register system events handler */
100 | vm_pmng_register_system_event_callback(handle_sysevt);
101 | }
102 |
--------------------------------------------------------------------------------
/lua/llimits.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Limits, basic types, and some other `installation-dependent' definitions
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef llimits_h
8 | #define llimits_h
9 |
10 |
11 | #include
12 | #include
13 |
14 |
15 | #include "lua.h"
16 |
17 |
18 | typedef LUAI_UINT32 lu_int32;
19 |
20 | typedef LUAI_UMEM lu_mem;
21 |
22 | typedef LUAI_MEM l_mem;
23 |
24 |
25 |
26 | /* chars used as small naturals (so that `char' is reserved for characters) */
27 | typedef unsigned char lu_byte;
28 |
29 |
30 | #define MAX_SIZET ((size_t)(~(size_t)0)-2)
31 |
32 | #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)
33 |
34 |
35 | #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
36 |
37 | /*
38 | ** conversion of pointer to integer
39 | ** this is for hashing only; there is no problem if the integer
40 | ** cannot hold the whole pointer value
41 | */
42 | #define IntPoint(p) ((unsigned int)(lu_mem)(p))
43 |
44 |
45 |
46 | /* type to ensure maximum alignment */
47 | typedef LUAI_USER_ALIGNMENT_T L_Umaxalign;
48 |
49 |
50 | /* result of a `usual argument conversion' over lua_Number */
51 | typedef LUAI_UACNUMBER l_uacNumber;
52 |
53 |
54 | /* internal assertions for in-house debugging */
55 | #ifdef lua_assert
56 |
57 | #define check_exp(c,e) (lua_assert(c), (e))
58 | #define api_check(l,e) lua_assert(e)
59 |
60 | #else
61 |
62 | #define lua_assert(c) ((void)0)
63 | #define check_exp(c,e) (e)
64 | #define api_check luai_apicheck
65 |
66 | #endif
67 |
68 |
69 | #ifndef UNUSED
70 | #define UNUSED(x) ((void)(x)) /* to avoid warnings */
71 | #endif
72 |
73 |
74 | #ifndef cast
75 | #define cast(t, exp) ((t)(exp))
76 | #endif
77 |
78 | #define cast_byte(i) cast(lu_byte, (i))
79 | #define cast_num(i) cast(lua_Number, (i))
80 | #define cast_int(i) cast(int, (i))
81 |
82 |
83 |
84 | /*
85 | ** type for virtual-machine instructions
86 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
87 | */
88 | typedef lu_int32 Instruction;
89 |
90 |
91 |
92 | /* maximum stack for a Lua function */
93 | #define MAXSTACK 250
94 |
95 |
96 |
97 | /* minimum size for the string table (must be power of 2) */
98 | #ifndef MINSTRTABSIZE
99 | #define MINSTRTABSIZE 32
100 | #endif
101 |
102 |
103 | /* minimum size for string buffer */
104 | #ifndef LUA_MINBUFFER
105 | #define LUA_MINBUFFER 32
106 | #endif
107 |
108 |
109 | #ifndef lua_lock
110 | #define lua_lock(L) ((void) 0)
111 | #define lua_unlock(L) ((void) 0)
112 | #endif
113 |
114 | #ifndef luai_threadyield
115 | #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);}
116 | #endif
117 |
118 |
119 | /*
120 | ** macro to control inclusion of some hard tests on stack reallocation
121 | */
122 | #ifndef HARDSTACKTESTS
123 | #define condhardstacktests(x) ((void)0)
124 | #else
125 | #define condhardstacktests(x) x
126 | #endif
127 |
128 | #endif
129 |
--------------------------------------------------------------------------------
/lua/lcode.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Code generator for Lua
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lcode_h
8 | #define lcode_h
9 |
10 | #include "llex.h"
11 | #include "lobject.h"
12 | #include "lopcodes.h"
13 | #include "lparser.h"
14 |
15 |
16 | /*
17 | ** Marks the end of a patch list. It is an invalid value both as an absolute
18 | ** address, and as a list link (would link an element to itself).
19 | */
20 | #define NO_JUMP (-1)
21 |
22 |
23 | /*
24 | ** grep "ORDER OPR" if you change these enums
25 | */
26 | typedef enum BinOpr {
27 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,
28 | OPR_CONCAT,
29 | OPR_NE, OPR_EQ,
30 | OPR_LT, OPR_LE, OPR_GT, OPR_GE,
31 | OPR_AND, OPR_OR,
32 | OPR_NOBINOPR
33 | } BinOpr;
34 |
35 |
36 | typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
37 |
38 |
39 | #define getcode(fs,e) ((fs)->f->code[(e)->u.s.info])
40 |
41 | #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)
42 |
43 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET)
44 |
45 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
46 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);
47 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
48 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);
49 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);
50 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n);
51 | LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s);
52 | LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r);
53 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);
54 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);
55 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e);
56 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);
57 | LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e);
58 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);
59 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);
60 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);
61 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);
62 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);
63 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);
64 | LUAI_FUNC int luaK_jump (FuncState *fs);
65 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret);
66 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);
67 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);
68 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);
69 | LUAI_FUNC int luaK_getlabel (FuncState *fs);
70 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v);
71 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);
72 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2);
73 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
74 |
75 |
76 | #endif
77 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Lua_for_RePhone
2 |
3 | ## Requirements
4 | + [gcc-arm-embedded](https://launchpad.net/gcc-arm-embedded)
5 | + make
6 |
7 | Add gcc-arm-embedded path to PATH variable.
8 |
9 | # Compile & Download
10 | Run `make` to get lua.vxp file, follow [the guide](http://www.seeedstudio.com/wiki/Lua_for_RePhone#Download_Lua_for_RePhone_Application) to download it to the RePhone.
11 |
12 | 1. [Upgrade firmware](http://www.seeedstudio.com/wiki/Arduino_IDE_for_RePhone_Kit#Update.2FFlash_the_Firmware) to get serial console support
13 | 2. Hold the RePhone's button, and turn it into storage mode in which we'll be able to see a USB disk on the computer.
14 | 3. Copy the vxp file to the disk
15 | 4. Change the path of `autostart.txt`, which is in the root directory of the disk, with the new vxp file path.
16 |
17 | ## Get started with Lua
18 |
19 | >Note:
20 | >To use the serial console, [a firmware upgrade](http://www.seeedstudio.com/wiki/Arduino_IDE_for_RePhone_Kit#Update.2FFlash_the_Firmware) is a must.
21 |
22 |
23 | Use serial port tool like miniterm.py to open RePhone USB Modem Port and enter:
24 | ```
25 | print('hello, lua')
26 | ```
27 |
28 | ## API
29 | + audio
30 | - audio.play(music.mp3)
31 | - audio.pause()
32 | - audio.resume()
33 | - audio.stop()
34 | - audio.set_volume(n), n from 1 to 6
35 | - audio.get_volume()
36 |
37 | + gsm
38 | - gsm.call(phone_number)
39 | - gsm.hang()
40 | - gsm.accept()
41 | - [gsm.on_incoming_call(function (phone_number) print('incoming call') end)](https://github.com/Seeed-Studio/Lua_for_RePhone/wiki/Telephone-rings)
42 | - gsm.text(phone_number, message)
43 | - [gsm.on_new_message(function (phone_number, message) print('got a message') end)](https://github.com/Seeed-Studio/Lua_for_RePhone/wiki/Auto-reply-text-message)
44 |
45 |
46 | + timer
47 | - id = timer.create(interval, repeat_function)
48 | - timer.delete(id)
49 |
50 | + button
51 | - [button.attach(function (event) print('button:', event) end)](https://github.com/Seeed-Studio/Lua_for_RePhone/wiki/Speed-Dial)
52 |
53 | + gpio
54 | - gpio.mode(pin, mode) - mode: gpio.INPUT, gpio.OUTPUT, gpio.INPUT_PULLUP
55 | - gpio.read(pin)
56 | - gpio.write(pin, value)
57 |
58 | + i2c
59 | - i2c.setup(address, speed)
60 | - i2c.send(number [, string, table, ...])
61 | - i2c.recv(size) - return string
62 | - i2c.txrx(number [, string, table, ...], size)
63 |
64 | + screen
65 | - screen.init()
66 | - screen.set_color(rgb)
67 | - screen.get_color()
68 | - screen.point(x, y)
69 | - screen.line(x1, y1, x2, y2 [, rgb])
70 | - screen.rectangle(x, y, width, height [, rgb])
71 | - screen.fill(x, y, width, height [, rgb])
72 | - screen.update()
73 | - screen.set_brightness()
74 | - screen.touch()
75 |
76 | + tcp
77 | - s = tcp.connect(ip, port)
78 | - tcp.write(s, str)
79 | - tcp.read(s, size)
80 | - tcp.close(s)
81 |
82 | + https
83 | - [https.get(url, callback)](https://github.com/Seeed-Studio/Lua_for_RePhone/wiki/HTPPS-GET-to-trigger-an-event-of-IFTTT-Maker-channel)
84 |
85 |
--------------------------------------------------------------------------------
/linkit/include/vmgsm.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * Copyright Statement:
3 | * --------------------
4 | * This software is protected by Copyright and the information contained
5 | * herein is confidential. The software may not be copied and the information
6 | * contained herein may not be used or disclosed except with the written
7 | * permission of MediaTek Inc. (C) 2005
8 | *
9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21 | *
22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27 | *
28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33 | *
34 | *****************************************************************************/
35 |
36 | #ifndef VMGSM_SDK_H
37 | #define VMGSM_SDK_H
38 |
39 | #ifdef __cplusplus
40 | extern "C" {
41 | #endif
42 |
43 | #include "vmtype.h"
44 |
45 | typedef void (*vm_gsm_switch_mode_callback_t)(VMBOOL switched_successfully);
46 |
47 | /*****************************************************************************
48 | * FUNCTION
49 | * vm_gsm_switch_mode
50 | * DESCRIPTION
51 | * Switch the GSM on or off.
52 | * PARAMETERS
53 | * on: [IN] Switch on or not.
54 | * callback: [IN] Callback funtion when switching finished.
55 | * RETURNS
56 | * If return VM_FALSE means the mode is switching, please try again later.
57 | *****************************************************************************/
58 | extern VMBOOL vm_gsm_switch_mode(VMBOOL on, vm_gsm_switch_mode_callback_t callback);
59 |
60 | #ifdef __cplusplus
61 | }
62 | #endif
63 |
64 | #endif /* VMGSM_SDK_H */
65 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 |
2 | PROJECT = lua
3 |
4 | OBJECTS += src/main.o src/retarget.o src/shell.o src/lcd_sitronix_st7789s.o src/tp_goodix_gt9xx.o src/tp_i2c.o
5 |
6 | WORKSPACE_PATH = ./
7 |
8 | include $(WORKSPACE_PATH)lua/Makefile
9 | include $(WORKSPACE_PATH)bindings/Makefile
10 |
11 | SYS_OBJECTS += $(WORKSPACE_PATH)linkit/lib/LINKIT10/src/gccmain.o
12 | INCLUDE_PATHS += -I. -I$(LINKIT_ASSIST_SDK_PATH)linkit/include -I$(WORKSPACE_PATH)src -I$(WORKSPACE_PATH)bindings
13 | LIBRARY_PATHS += -L$(LINKIT_ASSIST_SDK_PATH)linkit/lib
14 | LIBRARIES += $(LINKIT_ASSIST_SDK_PATH)linkit/lib/LINKIT10/armgcc/percommon.a -lm
15 | LINKER_SCRIPT = $(LINKIT_ASSIST_SDK_PATH)linkit/lib/LINKIT10/armgcc/scat.ld
16 |
17 | ###############################################################################
18 | AS = $(GCC_BIN)arm-none-eabi-as
19 | CC = $(GCC_BIN)arm-none-eabi-gcc
20 | CPP = $(GCC_BIN)arm-none-eabi-g++
21 | LD = $(GCC_BIN)arm-none-eabi-gcc
22 | OBJCOPY = $(GCC_BIN)arm-none-eabi-objcopy
23 | OBJDUMP = $(GCC_BIN)arm-none-eabi-objdump
24 | SIZE = $(GCC_BIN)arm-none-eabi-size
25 |
26 | ifeq ($(OS),Windows_NT)
27 | PACK = $(WORKSPACE_PATH)tools/PackTag.exe
28 | #PUSH = $(LINKIT_ASSIST_SDK_PATH)tools/PushCmdShell.exe $(PROJECT_PATH)/$(PROJECT).vxp
29 | PUSH = $(WORKSPACE_PATH)tools/PushTool.exe -v -v -v -v -t arduino -clear -port $(PORT) -app $(PROJECT).vxp
30 | else
31 | UNAME_S := $(shell uname -s)
32 | ifeq ($(UNAME_S),Linux)
33 | PACK = python $(WORKSPACE_PATH)tools/packtag.py
34 | PUSH = @echo use
35 | endif
36 | ifeq ($(UNAME_S),Darwin)
37 | PACK = $(WORKSPACE_PATH)tools/PackTag
38 | PUSH = $(WORKSPACE_PATH)tools/PushTool -v -v -v -v -d arduino -b $(PORT) -p $(PROJECT).vxp
39 | endif
40 | endif
41 |
42 | CPU = -mcpu=arm7tdmi-s -mthumb -mlittle-endian
43 | CC_FLAGS = $(CPU) -c -fvisibility=hidden -fpic -O2
44 | CC_SYMBOLS += -D__HDK_LINKIT_ASSIST_2502__ -D__COMPILER_GCC__
45 |
46 | LD_FLAGS = $(CPU) -O2 -Wl,--gc-sections --specs=nosys.specs -fpic -pie -Wl,-Map=$(PROJECT).map -Wl,--entry=gcc_entry -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-unresolved-symbols
47 | LD_SYS_LIBS =
48 |
49 |
50 | all: $(PROJECT).vxp size
51 |
52 | clean:
53 | rm -f $(PROJECT).vxp $(PROJECT).bin $(PROJECT).elf $(PROJECT).hex $(PROJECT).map $(PROJECT).lst $(OBJECTS)
54 |
55 | .s.o:
56 | $(AS) $(CPU) -o $@ $<
57 |
58 | .c.o:
59 | $(CC) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu99 $(INCLUDE_PATHS) -o $@ $<
60 |
61 | .cpp.o:
62 | $(CPP) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu++98 $(INCLUDE_PATHS) -o $@ $<
63 |
64 |
65 | $(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS)
66 | $(LD) $(LD_FLAGS) -T$(LINKER_SCRIPT) $(LIBRARY_PATHS) -o $@ -Wl,--start-group $^ $(LIBRARIES) $(LD_SYS_LIBS) -Wl,--end-group
67 |
68 | $(PROJECT).bin: $(PROJECT).elf
69 | @$(OBJCOPY) -O binary $< $@
70 |
71 | $(PROJECT).hex: $(PROJECT).elf
72 | @$(OBJCOPY) -O ihex $< $@
73 |
74 | $(PROJECT).vxp: $(PROJECT).elf
75 | @$(OBJCOPY) --strip-debug $<
76 | @$(PACK) $< $@
77 |
78 | $(PROJECT).lst: $(PROJECT).elf
79 | @$(OBJDUMP) -Sdh $< > $@
80 |
81 | lst: $(PROJECT).lst
82 |
83 | size: $(PROJECT).elf
84 | $(SIZE) $(PROJECT).elf
85 |
86 | flash: $(PROJECT).vxp
87 | $(PUSH)
88 |
--------------------------------------------------------------------------------
/linkit/include/vmusb.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * Copyright Statement:
3 | * --------------------
4 | * This software is protected by Copyright and the information contained
5 | * herein is confidential. The software may not be copied and the information
6 | * contained herein may not be used or disclosed except with the written
7 | * permission of MediaTek Inc. (C) 2005-2015
8 | *
9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21 | *
22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27 | *
28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33 | *
34 | *****************************************************************************/
35 |
36 | #ifndef VMUSB_SDK_H
37 | #define VMUSB_SDK_H
38 |
39 | #ifdef __cplusplus
40 | extern "C" {
41 | #endif
42 |
43 | #include "vmtype.h"
44 |
45 | /* The USB cable status. */
46 | typedef enum
47 | {
48 | VM_USB_CABLE_PLUG_IN, /* The USB cable is in plug-in status. */
49 | VM_USB_CABLE_PLUG_OUT, /* The USB cable is in plug-out status. */
50 | } VM_USB_CABLE_STATUS;
51 |
52 |
53 | /*******************************************************************************
54 | * FUNCTION
55 | * vm_usb_get_cable_status
56 | * DESCRIPTION
57 | * Get the usb cable status.
58 | * RETURNS
59 | * Refer to VM_USB_CABLE_STATUS for details.
60 | * EXAMPLE
61 | *
62 | * usb_status = vm_usb_get_cable_status();
63 | *
64 | *******************************************************************************/
65 | VM_USB_CABLE_STATUS vm_usb_get_cable_status(void);
66 |
67 | #ifdef __cplusplus
68 | }
69 | #endif
70 |
71 | #endif /* VMUSB_SDK_H */
--------------------------------------------------------------------------------
/lua/lopcodes.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** See Copyright Notice in lua.h
4 | */
5 |
6 |
7 | #define lopcodes_c
8 | #define LUA_CORE
9 |
10 |
11 | #include "lopcodes.h"
12 |
13 |
14 | /* ORDER OP */
15 |
16 | const char *const luaP_opnames[NUM_OPCODES+1] = {
17 | "MOVE",
18 | "LOADK",
19 | "LOADBOOL",
20 | "LOADNIL",
21 | "GETUPVAL",
22 | "GETGLOBAL",
23 | "GETTABLE",
24 | "SETGLOBAL",
25 | "SETUPVAL",
26 | "SETTABLE",
27 | "NEWTABLE",
28 | "SELF",
29 | "ADD",
30 | "SUB",
31 | "MUL",
32 | "DIV",
33 | "MOD",
34 | "POW",
35 | "UNM",
36 | "NOT",
37 | "LEN",
38 | "CONCAT",
39 | "JMP",
40 | "EQ",
41 | "LT",
42 | "LE",
43 | "TEST",
44 | "TESTSET",
45 | "CALL",
46 | "TAILCALL",
47 | "RETURN",
48 | "FORLOOP",
49 | "FORPREP",
50 | "TFORLOOP",
51 | "SETLIST",
52 | "CLOSE",
53 | "CLOSURE",
54 | "VARARG",
55 | NULL
56 | };
57 |
58 |
59 | #define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m))
60 |
61 | const lu_byte luaP_opmodes[NUM_OPCODES] = {
62 | /* T A B C mode opcode */
63 | opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */
64 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */
65 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */
66 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */
67 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */
68 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */
69 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */
70 | ,opmode(0, 0, OpArgK, OpArgN, iABx) /* OP_SETGLOBAL */
71 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */
72 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */
73 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */
74 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */
75 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */
76 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */
77 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */
78 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */
79 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */
80 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */
81 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */
82 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */
83 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */
84 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */
85 | ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */
86 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */
87 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */
88 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */
89 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */
90 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */
91 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */
92 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */
93 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */
94 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */
95 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */
96 | ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */
97 | ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */
98 | ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */
99 | ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */
100 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */
101 | };
102 |
103 |
--------------------------------------------------------------------------------
/tools/packtag.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import sys
4 | from struct import pack
5 |
6 | suffix = '\x04\x00\x00\x00\n\x00\x00\x00D\x00e\x00m\x00o\x00\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\xff\xff\xff\xff\x03\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x05\x00\x00\x00\x04\x00\x00\x00\x00\x00\x01\x00\x16\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x06\x00\x00\x00\x18\x00\x00\x00\xde\x07\x00\x00\x03\x00\x00\x00\x1c\x00\x00\x00\x0f\x00\x00\x00(\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x18\x00\x00\x00\xde\x07\x00\x00\x05\x00\x00\x00\x1c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x04\x00\x00\x00\x00\x04\x00\x00\x10\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x11\x00\x00\x00\x04\x00\x00\x00\x00\x00\xc4\t!\x00\x00\x00\x04\x00\x00\x00\x06\x00\x00\x00#\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00"\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x18\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x002\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00/\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x001\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x1c\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00)\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00*\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00,\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x04\x00\x00\x00\xff\xff\xff\xff.\x00\x00\x00\x02\x00\x00\x00\x00\x00\x01\x00\x00\x00\x1c\x00\x00\x00M\x00e\x00d\x00i\x00a\x00T\x00e\x00k\x00 \x00I\x00n\x00c\x00.\x00\x00\x00%\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x003\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x12\x00\x00\x00\n\x00\x00\x001234567890\x17\x00\x00\x00\x10\x00\x00\x00c\x00o\x00n\x00t\x00e\x00n\x00t\x00\x00\x00\x19\x00\x00\x00>\x00\x00\x00\x01\x00\x00\x00\n\x00\x00\x00D\x00e\x00m\x00o\x00\x00\x00\x02\x00\x00\x00\n\x00\x00\x00D\x00e\x00m\x00o\x00\x00\x00\x03\x00\x00\x00\n\x00\x00\x00D\x00e\x00m\x00o\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x13\x00\x00\x00\xd0\x00\x00\x00\x88\x13\x00\x00\x01\x00\x00\x00\x89\x13\x00\x00\x01\x00\x00\x00\x8a\x13\x00\x00\x01\x00\x00\x00\x8b\x13\x00\x00\x01\x00\x00\x00\x8c\x13\x00\x00\x01\x00\x00\x00\x8d\x13\x00\x00\x01\x00\x00\x00\x8e\x13\x00\x00\x01\x00\x00\x00\x8f\x13\x00\x00\x01\x00\x00\x00\x90\x13\x00\x00\x01\x00\x00\x00\x91\x13\x00\x00\x01\x00\x00\x00\x92\x13\x00\x00\x01\x00\x00\x00\x93\x13\x00\x00\x01\x00\x00\x00\x94\x13\x00\x00\x01\x00\x00\x00\x95\x13\x00\x00\x01\x00\x00\x00\x96\x13\x00\x00\x01\x00\x00\x00\x97\x13\x00\x00\x01\x00\x00\x00\x98\x13\x00\x00\x01\x00\x00\x00\x99\x13\x00\x00\x01\x00\x00\x00\x9a\x13\x00\x00\x01\x00\x00\x00\x9b\x13\x00\x00\x01\x00\x00\x00\x9c\x13\x00\x00\x01\x00\x00\x00\x9d\x13\x00\x00\x01\x00\x00\x00\x9e\x13\x00\x00\x01\x00\x00\x00\x9f\x13\x00\x00\x01\x00\x00\x00\xa0\x13\x00\x00\x01\x00\x00\x00\xa1\x13\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb4VDE10\x01\x00\x00\x00LV)\xfb\xed\xfe\xb6\xd0\x9e\xa6\xe0\xcb\xb3\x122\xa6\xff8\xdd\xf5\xfc\xb2i2X\xe1\x10\x9dw}\x19\xdd;0V*\x92\x9bo\xf8\x0f\xf0\xa0 "\xd9\x12$\x01f\xe3\x0f\xc1\n\xff\xa5\xae\x9a\xeb\xae4\x81\xed\xbb'
7 |
8 |
9 | if __name__ == '__main__':
10 | if len(sys.argv) < 2:
11 | print('Usage: %s input.elf output.vxp' % sys.argv[0])
12 | sys.exit(-1)
13 |
14 | elfname = sys.argv[1]
15 | vxpname = elfname + '.vxp'
16 | if len(sys.argv) > 2:
17 | vxpname = sys.argv[2]
18 |
19 | elf = open(elfname, 'rb')
20 | if not elf:
21 | print('Can not open %s' % elfname)
22 | sys.exit(-2)
23 |
24 | vxp = open(vxpname, 'wb')
25 | if not vxp:
26 | print('Can not open %s' % vxp)
27 | sys.exit(-3)
28 |
29 | vxp.write(elf.read())
30 | elf.close()
31 |
32 | # append 0xff
33 | vxp.write('\xff')
34 | size = vxp.tell()
35 |
36 | # align with 0x30
37 | while size & 0x3:
38 | vxp.write('\x30')
39 | size += 1
40 |
41 | vxp.write(suffix)
42 |
43 | # add elf file length information
44 | lengthinfo = pack('qi', size, 0)
45 | vxp.write(lengthinfo)
46 | vxp.close()
47 |
48 |
--------------------------------------------------------------------------------
/bindings/gpio.c:
--------------------------------------------------------------------------------
1 |
2 | #include "vmdcl.h"
3 | #include "vmdcl_gpio.h"
4 |
5 | #include "lua.h"
6 | #include "lauxlib.h"
7 |
8 | #define INPUT 0
9 | #define OUTPUT 1
10 | #define INPUT_PULLUP 2
11 | #define HIGH 1
12 | #define LOW 0
13 |
14 | extern int gpio_get_handle(int pin, VM_DCL_HANDLE* handle);
15 |
16 | int gpio_mode(lua_State* L)
17 | {
18 | VM_DCL_HANDLE handle;
19 | int pin = luaL_checkinteger(L, 1);
20 | int mode = luaL_checkinteger(L, 2);
21 |
22 | if (gpio_get_handle(pin, &handle)) {
23 | return 0;
24 | }
25 |
26 | vm_dcl_control(handle, VM_DCL_GPIO_COMMAND_SET_MODE_0, NULL);
27 |
28 | if (mode == INPUT) {
29 | vm_dcl_control(handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_IN, NULL);
30 | } else if (mode == OUTPUT) {
31 | vm_dcl_control(handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_OUT, NULL);
32 | } else {
33 | vm_dcl_control(handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_IN, NULL);
34 | vm_dcl_control(handle, VM_DCL_GPIO_COMMAND_ENABLE_PULL, NULL);
35 | vm_dcl_control(handle, VM_DCL_GPIO_COMMAND_SET_PULL_HIGH, NULL);
36 | }
37 |
38 | return 0;
39 | }
40 |
41 | int gpio_read(lua_State* L)
42 | {
43 | VM_DCL_HANDLE handle;
44 | vm_dcl_gpio_control_level_status_t data;
45 | int pin = luaL_checkinteger(L, 1);
46 |
47 | gpio_get_handle(pin, &handle);
48 | vm_dcl_control(handle, VM_DCL_GPIO_COMMAND_READ, &data);
49 |
50 | lua_pushnumber(L, data.level_status);
51 |
52 | return 1;
53 | }
54 |
55 | int gpio_write(lua_State* L)
56 | {
57 | VM_DCL_HANDLE handle;
58 | int pin = luaL_checkinteger(L, 1);
59 | int value = luaL_checkinteger(L, 2);
60 |
61 | gpio_get_handle(pin, &handle);
62 | if (value) {
63 | vm_dcl_control(handle, VM_DCL_GPIO_COMMAND_WRITE_HIGH, NULL);
64 | } else {
65 | vm_dcl_control(handle, VM_DCL_GPIO_COMMAND_WRITE_LOW, NULL);
66 | }
67 |
68 | return 0;
69 | }
70 |
71 | #undef MIN_OPT_LEVEL
72 | #define MIN_OPT_LEVEL 0
73 | #include "lrodefs.h"
74 |
75 | #define MOD_REG_NUMBER(L, name, value) \
76 | lua_pushnumber(L, value); \
77 | lua_setfield(L, -2, name)
78 |
79 | #define GLOBAL_NUMBER(l, name, value) \
80 | lua_pushnumber(L, value); \
81 | lua_setglobal(L, name)
82 |
83 | const LUA_REG_TYPE gpio_map[] = { { LSTRKEY("mode"), LFUNCVAL(gpio_mode) },
84 | { LSTRKEY("read"), LFUNCVAL(gpio_read) },
85 | { LSTRKEY("write"), LFUNCVAL(gpio_write) },
86 | #if LUA_OPTIMIZE_MEMORY > 0
87 | { LSTRKEY("OUTPUT"), LNUMVAL(OUTPUT) },
88 | { LSTRKEY("INPUT"), LNUMVAL(INPUT) },
89 | { LSTRKEY("HIGH"), LNUMVAL(HIGH) },
90 | { LSTRKEY("LOW"), LNUMVAL(LOW) },
91 | { LSTRKEY("INPUT_PULLUP"), LNUMVAL(INPUT_PULLUP) },
92 | #endif
93 | { LNILKEY, LNILVAL } };
94 |
95 | LUALIB_API int luaopen_gpio(lua_State* L)
96 | {
97 | lua_register(L, "pinMode", gpio_mode);
98 | lua_register(L, "digitalRead", gpio_read);
99 | lua_register(L, "digitalWrite", gpio_write);
100 |
101 | GLOBAL_NUMBER(L, "OUTPUT", OUTPUT);
102 | GLOBAL_NUMBER(L, "INPUT", INPUT);
103 | GLOBAL_NUMBER(L, "HIGH", HIGH);
104 | GLOBAL_NUMBER(L, "LOW", LOW);
105 | GLOBAL_NUMBER(L, "INPUT_PULLUP", INPUT_PULLUP);
106 |
107 | #if LUA_OPTIMIZE_MEMORY > 0
108 | return 0;
109 | #else // #if LUA_OPTIMIZE_MEMORY > 0
110 |
111 | luaL_register(L, "gpio", gpio_map);
112 | // Add constants
113 | MOD_REG_NUMBER(L, "OUTPUT", OUTPUT);
114 | MOD_REG_NUMBER(L, "INPUT", INPUT);
115 | MOD_REG_NUMBER(L, "HIGH", HIGH);
116 | MOD_REG_NUMBER(L, "LOW", LOW);
117 | MOD_REG_NUMBER(L, "INPUT_PULLUP", INPUT_PULLUP);
118 | return 1;
119 | #endif // #if LUA_OPTIMIZE_MEMORY > 0
120 | }
121 |
--------------------------------------------------------------------------------
/src/retarget.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include "vmdcl.h"
4 | #include "vmdcl_sio.h"
5 | #include "vmboard.h"
6 | #include "vmthread.h"
7 | #include "vmlog.h"
8 |
9 | #define SERIAL_BUFFER_SIZE 64
10 |
11 | /* Module owner of APP */
12 | static VM_DCL_OWNER_ID g_owner_id = 0;
13 | static VM_DCL_HANDLE retarget_device_handle = -1;
14 | VM_SIGNAL_ID retarget_rx_signal_id;
15 | static char retarget_rx_buffer[SERIAL_BUFFER_SIZE];
16 | unsigned retarget_rx_buffer_head = 0;
17 | unsigned retarget_rx_buffer_tail = 0;
18 |
19 | void __retarget_irq_handler(void* parameter, VM_DCL_EVENT event, VM_DCL_HANDLE device_handle)
20 | {
21 | if(event == VM_DCL_SIO_UART_READY_TO_READ)
22 | {
23 | char data[SERIAL_BUFFER_SIZE];
24 | int i;
25 | VM_DCL_STATUS status;
26 | VM_DCL_BUFFER_LENGTH returned_len = 0;
27 |
28 | status = vm_dcl_read(device_handle,
29 | (VM_DCL_BUFFER *)data,
30 | SERIAL_BUFFER_SIZE,
31 | &returned_len,
32 | g_owner_id);
33 | if(status < VM_DCL_STATUS_OK)
34 | {
35 | // vm_log_info((char*)"read failed");
36 | }
37 | else if (returned_len)
38 | {
39 | if (retarget_rx_buffer_head == retarget_rx_buffer_tail) {
40 | vm_signal_post(retarget_rx_signal_id);
41 | }
42 |
43 | for (i = 0; i < returned_len; i++)
44 | {
45 | retarget_rx_buffer[retarget_rx_buffer_head % SERIAL_BUFFER_SIZE] = data[i];
46 | retarget_rx_buffer_head++;
47 | if ((unsigned)(retarget_rx_buffer_head - retarget_rx_buffer_tail) > SERIAL_BUFFER_SIZE) {
48 | retarget_rx_buffer_tail = retarget_rx_buffer_head - SERIAL_BUFFER_SIZE;
49 | }
50 | }
51 | }
52 |
53 | }
54 | else
55 | {
56 | }
57 | }
58 |
59 | void retarget_setup(void)
60 | {
61 | VM_DCL_HANDLE uart_handle;
62 | vm_dcl_sio_control_dcb_t settings;
63 |
64 | g_owner_id = vm_dcl_get_owner_id();
65 |
66 | if (retarget_device_handle != -1)
67 | {
68 | return;
69 | }
70 |
71 | #if 0
72 | vm_dcl_config_pin_mode(10, VM_DCL_PIN_MODE_UART);
73 | vm_dcl_config_pin_mode(11, VM_DCL_PIN_MODE_UART);
74 | uart_handle = vm_dcl_open(VM_DCL_SIO_UART_PORT1, g_owner_id);
75 | #else
76 | uart_handle = vm_dcl_open(VM_DCL_SIO_USB_PORT1, g_owner_id);
77 | #endif
78 |
79 | settings.owner_id = g_owner_id;
80 | settings.config.dsr_check = 0;
81 | settings.config.data_bits_per_char_length = VM_DCL_SIO_UART_BITS_PER_CHAR_LENGTH_8;
82 | settings.config.flow_control = VM_DCL_SIO_UART_FLOW_CONTROL_NONE;
83 | settings.config.parity = VM_DCL_SIO_UART_PARITY_NONE;
84 | settings.config.stop_bits = VM_DCL_SIO_UART_STOP_BITS_1;
85 | settings.config.baud_rate = VM_DCL_SIO_UART_BAUDRATE_115200;
86 | settings.config.sw_xoff_char = 0x13;
87 | settings.config.sw_xon_char = 0x11;
88 | vm_dcl_control(uart_handle, VM_DCL_SIO_COMMAND_SET_DCB_CONFIG, (void *)&settings);
89 |
90 | retarget_rx_signal_id = vm_signal_create();
91 |
92 | vm_dcl_register_callback(uart_handle,
93 | VM_DCL_SIO_UART_READY_TO_READ,
94 | (vm_dcl_callback)__retarget_irq_handler,
95 | (void*)NULL);
96 |
97 | retarget_device_handle = uart_handle;
98 | }
99 |
100 | void retarget_putc(char ch)
101 | {
102 | VM_DCL_BUFFER_LENGTH writen_len = 0;
103 | vm_dcl_write(retarget_device_handle, (VM_DCL_BUFFER *)&ch, 1, &writen_len, g_owner_id);
104 | }
105 |
106 | void retarget_puts(const char *str)
107 | {
108 | VM_DCL_BUFFER_LENGTH writen_len = 0;
109 | VM_DCL_BUFFER_LENGTH len = strlen(str);
110 |
111 | vm_dcl_write(retarget_device_handle, (VM_DCL_BUFFER *)str, len, &writen_len, g_owner_id);
112 | }
113 |
114 | int retarget_getc(void)
115 | {
116 | char ch;
117 | if (retarget_rx_buffer_head == retarget_rx_buffer_tail)
118 | {
119 | vm_signal_wait(retarget_rx_signal_id);
120 | }
121 |
122 |
123 | ch = retarget_rx_buffer[retarget_rx_buffer_tail % SERIAL_BUFFER_SIZE];
124 | retarget_rx_buffer_tail++;
125 |
126 | return ch;
127 | }
128 |
--------------------------------------------------------------------------------
/bindings/tcp.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 |
4 | #include "vmtcp.h"
5 |
6 | #include "lua.h"
7 | #include "lauxlib.h"
8 |
9 | #define LUA_TCP "tcp"
10 |
11 | typedef struct {
12 | VM_TCP_HANDLE handle;
13 | int cb_ref;
14 | lua_State* L;
15 | } tcp_info_t;
16 |
17 | static void __tcp_callback(VM_TCP_HANDLE handle, VM_TCP_EVENT event, void* user_data)
18 | {
19 | tcp_info_t* p = (tcp_info_t*)user_data;
20 | lua_State* L = p->L;
21 |
22 | lua_rawgeti(L, LUA_REGISTRYINDEX, p->cb_ref);
23 | lua_pushlightuserdata(L, p);
24 | luaL_getmetatable(L, LUA_TCP);
25 | lua_setmetatable(L, -2);
26 | lua_pushinteger(L, (int)event);
27 | lua_call(L, 2, 0);
28 | }
29 |
30 | int tcp_connect(lua_State* L)
31 | {
32 | tcp_info_t* p;
33 | int ref;
34 | char* addr = luaL_checkstring(L, 1);
35 | unsigned port = luaL_checkinteger(L, 2);
36 |
37 | lua_pushvalue(L, 3);
38 |
39 | ref = luaL_ref(L, LUA_REGISTRYINDEX);
40 |
41 | p = (tcp_info_t*)lua_newuserdata(L, sizeof(tcp_info_t));
42 |
43 | luaL_getmetatable(L, LUA_TCP);
44 | lua_setmetatable(L, -2);
45 |
46 | p->L = L;
47 | p->cb_ref = ref;
48 | p->handle = vm_tcp_connect(addr, port, VM_BEARER_DATA_ACCOUNT_TYPE_GPRS_NONE_PROXY_APN, p, __tcp_callback);
49 |
50 | return 1;
51 | }
52 |
53 | int tcp_write(lua_State* L)
54 | {
55 | tcp_info_t* p = ((tcp_info_t*)luaL_checkudata(L, 1, LUA_TCP));
56 | int len;
57 | char* str = luaL_checklstring(L, 2, &len);
58 |
59 | lua_pushinteger(L, vm_tcp_write(p->handle, str, len));
60 |
61 | return 1;
62 | }
63 |
64 | int tcp_read(lua_State* L)
65 | {
66 | tcp_info_t* p = ((tcp_info_t*)luaL_checkudata(L, 1, LUA_TCP));
67 | size_t size = luaL_checkinteger(L, 2);
68 | luaL_Buffer b;
69 | int nread;
70 | int i;
71 | int ret;
72 |
73 | char* buf = malloc(size);
74 | if(buf == 0) {
75 | return luaL_error(L, "malloc() failed");
76 | }
77 |
78 | nread = vm_tcp_read(p->handle, buf, size);
79 | if(nread < 0) {
80 | ret = luaL_error(L, "tcp failed to read");
81 | } else if(nread == 0) {
82 | // receives the FIN from the server
83 | ret = 0;
84 | } else {
85 | luaL_buffinit(L, &b);
86 | for(i = 0; i < size; i++) {
87 | luaL_addchar(&b, buf[i]);
88 | }
89 |
90 | luaL_pushresult(&b);
91 | ret = 1;
92 | }
93 |
94 | free(buf);
95 | return ret;
96 | }
97 |
98 | int tcp_close(lua_State* L)
99 | {
100 | tcp_info_t* p = ((tcp_info_t*)luaL_checkudata(L, 1, LUA_TCP));
101 |
102 | vm_tcp_close(p->handle);
103 |
104 | return 0;
105 | }
106 |
107 | int tcp_gc(lua_State* L)
108 | {
109 | tcp_info_t* p = ((tcp_info_t*)luaL_checkudata(L, 1, LUA_TCP));
110 |
111 | return 0;
112 | }
113 |
114 | int tcp_tostring(lua_State* L)
115 | {
116 | tcp_info_t* p = ((tcp_info_t*)luaL_checkudata(L, 1, LUA_TCP));
117 | lua_pushfstring(L, "tcp (%p)", p->handle);
118 | return 1;
119 | }
120 |
121 | #undef MIN_OPT_LEVEL
122 | #define MIN_OPT_LEVEL 0
123 | #include "lrodefs.h"
124 |
125 | const LUA_REG_TYPE tcp_map[] = { { LSTRKEY("connect"), LFUNCVAL(tcp_connect) },
126 | { LSTRKEY("read"), LFUNCVAL(tcp_read) },
127 | { LSTRKEY("write"), LFUNCVAL(tcp_write) },
128 | { LSTRKEY("close"), LFUNCVAL(tcp_close) },
129 | { LNILKEY, LNILVAL } };
130 |
131 | const LUA_REG_TYPE tcp_type_table[] = { { LSTRKEY("read"), LFUNCVAL(tcp_read) },
132 | { LSTRKEY("write"), LFUNCVAL(tcp_write) },
133 | { LSTRKEY("close"), LFUNCVAL(tcp_close) },
134 | { LSTRKEY("__gc"), LFUNCVAL(tcp_gc) },
135 | { LSTRKEY("__tostring"), LFUNCVAL(tcp_tostring) },
136 | { LNILKEY, LNILVAL } };
137 |
138 | LUALIB_API int luaopen_tcp(lua_State* L)
139 | {
140 | luaL_newmetatable(L, LUA_TCP); /* create metatable for file handles */
141 | lua_pushvalue(L, -1); /* push metatable */
142 | lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
143 | luaL_register(L, NULL, tcp_type_table); /* file methods */
144 |
145 | luaL_register(L, "tcp", tcp_map);
146 | return 1;
147 | }
--------------------------------------------------------------------------------
/lua/linit.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Initialization of libraries for lua.c
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 |
8 | #define linit_c
9 | #define LUA_LIB
10 |
11 | #include "lua.h"
12 |
13 | #include "lualib.h"
14 | #include "lauxlib.h"
15 | #include "lrotable.h"
16 | #include "luaconf.h"
17 | #ifndef LUA_CROSS_COMPILER
18 | #include "platform_conf.h"
19 | #endif
20 |
21 | #ifdef LUA_RPC
22 | #include "desktop_conf.h"
23 | #endif
24 |
25 | LUALIB_API int luaopen_platform (lua_State *L);
26 | int luaopen_dummy(lua_State *L);
27 |
28 | // Declare table
29 | #if defined(LUA_PLATFORM_LIBS_ROM) && LUA_OPTIMIZE_MEMORY == 2
30 | #undef _ROM
31 | #define _ROM( name, openf, table ) extern const luaR_entry table[];
32 | LUA_PLATFORM_LIBS_ROM;
33 | #endif
34 |
35 | // ****************************************************************************
36 | // Platform module handling
37 | // Automatically generate all the data required for platform modules
38 |
39 | #if defined( PLATFORM_MODULES_ENABLE )
40 |
41 | #if LUA_OPTIMIZE_MEMORY == 2
42 | #undef _ROM
43 | #define _ROM( name, openf, table ) extern const luaR_entry table[];
44 | PLATFORM_MODULES_LIBS_ROM
45 | #else // #if LUA_OPTIMIZE_MEMORY == 2
46 | #undef _ROM
47 | #define _ROM( name, openf, table ) extern const luaL_reg table[];
48 | PLATFORM_MODULES_LIBS_ROM
49 | #endif // #if LUA_OPTIMIZE_MEMORY == 2
50 |
51 | #if LUA_OPTIMIZE_MEMORY == 2
52 | const luaR_entry platform_map[] = {
53 | #undef _ROM
54 | #define _ROM( name, openf, table ) { LRO_STRKEY( name ), LRO_ROVAL( table ) },
55 | PLATFORM_MODULES_LIBS_ROM
56 | { LRO_NILKEY, LRO_NILVAL }
57 | };
58 | #else // #if LUA_OPTIMIZE_MEMORY == 2
59 | typedef struct {
60 | const char *name;
61 | const luaL_reg *table;
62 | } PLATFORM_MODULE_ENTRY;
63 |
64 | static const PLATFORM_MODULE_ENTRY platform_map_tables[] = {
65 | #undef _ROM
66 | #define _ROM( name, openf, table ) { name, table },
67 | PLATFORM_MODULES_LIBS_ROM
68 | { NULL, NULL }
69 | };
70 | #endif // #if LUA_OPTIMIZE_MEMORY == 2
71 |
72 | #undef _ROM
73 | #define _ROM( name, openf, table ) int openf (lua_State*);
74 | PLATFORM_MODULES_LIBS_ROM
75 | static const lua_CFunction platform_open_funcs[] = {
76 | #undef _ROM
77 | #define _ROM( name, openf, table ) openf,
78 | PLATFORM_MODULES_LIBS_ROM
79 | luaopen_dummy
80 | };
81 |
82 | LUALIB_API int luaopen_platform (lua_State *L)
83 | {
84 | #if LUA_OPTIMIZE_MEMORY == 0
85 | // Register the platform table first and each of the platform module's tables
86 | const PLATFORM_MODULE_ENTRY *plibs = platform_map_tables;
87 |
88 | lua_newtable(L);
89 | lua_pushvalue(L, -1);
90 | lua_setfield(L, LUA_GLOBALSINDEX, PS_LIB_TABLE_NAME);
91 | for(; plibs->name; plibs ++) {
92 | lua_newtable(L);
93 | luaL_register(L, NULL, plibs->table);
94 | lua_setfield(L, -2, plibs->name);
95 | }
96 | lua_pop(L, 1);
97 | #endif // #if LUA_OPTIMIZE_MEMORY == 0
98 | // In any case, call each platform module's initialization function if present
99 | unsigned i;
100 | for (i = 0; i < sizeof(platform_open_funcs) / sizeof(lua_CFunction); i++) {
101 | lua_pushcfunction(L, platform_open_funcs[i]);
102 | lua_call(L, 0, 0);
103 | }
104 | return 0;
105 | }
106 | #endif // #if defined( PLATFORM_MODULES_ENABLE )
107 |
108 | // End of platform module section
109 | // ****************************************************************************
110 |
111 |
112 | // Dummy open function
113 | int luaopen_dummy(lua_State *L)
114 | {
115 | return 0;
116 | }
117 |
118 | #undef _ROM
119 | #define _ROM( name, openf, table ) { name, openf },
120 |
121 | static const luaL_Reg lualibs[] = {
122 | {"", luaopen_base},
123 | {LUA_LOADLIBNAME, luaopen_package},
124 | {LUA_TABLIBNAME, luaopen_table},
125 | {LUA_IOLIBNAME, luaopen_io},
126 | {LUA_STRLIBNAME, luaopen_string},
127 | {LUA_MATHLIBNAME, luaopen_math},
128 | #if defined(LUA_PLATFORM_LIBS_ROM)
129 | LUA_PLATFORM_LIBS_ROM
130 | #endif
131 | #if defined(LUA_LIBS_NOLTR)
132 | LUA_LIBS_NOLTR
133 | #endif
134 | {NULL, NULL}
135 | };
136 |
137 | const luaR_table lua_rotable[] =
138 | {
139 | #if defined(LUA_PLATFORM_LIBS_ROM) && LUA_OPTIMIZE_MEMORY == 2
140 | #undef _ROM
141 | #define _ROM( name, openf, table ) { name, table },
142 | LUA_PLATFORM_LIBS_ROM
143 | #endif
144 | {NULL, NULL}
145 | };
146 |
147 | LUALIB_API void luaL_openlibs (lua_State *L) {
148 | const luaL_Reg *lib = lualibs;
149 | for (; lib->name; lib++)
150 | if (lib->func) {
151 | lua_pushcfunction(L, lib->func);
152 | lua_pushstring(L, lib->name);
153 | lua_call(L, 1, 0);
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/lua/lrotable.c:
--------------------------------------------------------------------------------
1 | /* Read-only tables for Lua */
2 |
3 | #include
4 | #include "lrotable.h"
5 | #include "lua.h"
6 | #include "lauxlib.h"
7 | #include "lstring.h"
8 | #include "lobject.h"
9 | #include "lapi.h"
10 |
11 | /* Local defines */
12 | #define LUAR_FINDFUNCTION 0
13 | #define LUAR_FINDVALUE 1
14 |
15 | /* Externally defined read-only table array */
16 | extern const luaR_table lua_rotable[];
17 |
18 | /* Find a global "read only table" in the constant lua_rotable array */
19 | void* luaR_findglobal(const char *name, unsigned len) {
20 | unsigned i;
21 |
22 | if (strlen(name) > LUA_MAX_ROTABLE_NAME)
23 | return NULL;
24 | for (i=0; lua_rotable[i].name; i ++)
25 | if (*lua_rotable[i].name != '\0' && strlen(lua_rotable[i].name) == len && !strncmp(lua_rotable[i].name, name, len)) {
26 | return (void*)(lua_rotable[i].pentries);
27 | }
28 | return NULL;
29 | }
30 |
31 | /* Find an entry in a rotable and return it */
32 | static const TValue* luaR_auxfind(const luaR_entry *pentry, const char *strkey, luaR_numkey numkey, unsigned *ppos) {
33 | const TValue *res = NULL;
34 | unsigned i = 0;
35 |
36 | if (pentry == NULL)
37 | return NULL;
38 | while(pentry->key.type != LUA_TNIL) {
39 | if ((strkey && (pentry->key.type == LUA_TSTRING) && (!strcmp(pentry->key.id.strkey, strkey))) ||
40 | (!strkey && (pentry->key.type == LUA_TNUMBER) && ((luaR_numkey)pentry->key.id.numkey == numkey))) {
41 | res = &pentry->value;
42 | break;
43 | }
44 | i ++; pentry ++;
45 | }
46 | if (res && ppos)
47 | *ppos = i;
48 | return res;
49 | }
50 |
51 | int luaR_findfunction(lua_State *L, const luaR_entry *ptable) {
52 | const TValue *res = NULL;
53 | const char *key = luaL_checkstring(L, 2);
54 |
55 | res = luaR_auxfind(ptable, key, 0, NULL);
56 | if (res && ttislightfunction(res)) {
57 | luaA_pushobject(L, res);
58 | return 1;
59 | }
60 | else
61 | return 0;
62 | }
63 |
64 | /* Find an entry in a rotable and return its type
65 | If "strkey" is not NULL, the function will look for a string key,
66 | otherwise it will look for a number key */
67 | const TValue* luaR_findentry(void *data, const char *strkey, luaR_numkey numkey, unsigned *ppos) {
68 | return luaR_auxfind((const luaR_entry*)data, strkey, numkey, ppos);
69 | }
70 |
71 | /* Find the metatable of a given table */
72 | void* luaR_getmeta(void *data) {
73 | #ifdef LUA_META_ROTABLES
74 | const TValue *res = luaR_auxfind((const luaR_entry*)data, "__metatable", 0, NULL);
75 | return res && ttisrotable(res) ? rvalue(res) : NULL;
76 | #else
77 | return NULL;
78 | #endif
79 | }
80 |
81 | static void luaR_next_helper(lua_State *L, const luaR_entry *pentries, int pos, TValue *key, TValue *val) {
82 | setnilvalue(key);
83 | setnilvalue(val);
84 | if (pentries[pos].key.type != LUA_TNIL) {
85 | /* Found an entry */
86 | if (pentries[pos].key.type == LUA_TSTRING)
87 | setsvalue(L, key, luaS_newro(L, pentries[pos].key.id.strkey))
88 | else
89 | setnvalue(key, (lua_Number)pentries[pos].key.id.numkey)
90 | setobj2s(L, val, &pentries[pos].value);
91 | }
92 | }
93 | /* next (used for iteration) */
94 | void luaR_next(lua_State *L, void *data, TValue *key, TValue *val) {
95 | const luaR_entry* pentries = (const luaR_entry*)data;
96 | char strkey[LUA_MAX_ROTABLE_NAME + 1], *pstrkey = NULL;
97 | luaR_numkey numkey = 0;
98 | unsigned keypos;
99 |
100 | /* Special case: if key is nil, return the first element of the rotable */
101 | if (ttisnil(key))
102 | luaR_next_helper(L, pentries, 0, key, val);
103 | else if (ttisstring(key) || ttisnumber(key)) {
104 | /* Find the previoud key again */
105 | if (ttisstring(key)) {
106 | luaR_getcstr(strkey, rawtsvalue(key), LUA_MAX_ROTABLE_NAME);
107 | pstrkey = strkey;
108 | } else
109 | numkey = (luaR_numkey)nvalue(key);
110 | luaR_findentry(data, pstrkey, numkey, &keypos);
111 | /* Advance to next key */
112 | keypos ++;
113 | luaR_next_helper(L, pentries, keypos, key, val);
114 | }
115 | }
116 |
117 | /* Convert a Lua string to a C string */
118 | void luaR_getcstr(char *dest, const TString *src, size_t maxsize) {
119 | if (src->tsv.len+1 > maxsize)
120 | dest[0] = '\0';
121 | else {
122 | memcpy(dest, getstr(src), src->tsv.len);
123 | dest[src->tsv.len] = '\0';
124 | }
125 | }
126 |
127 | /* Return 1 if the given pointer is a rotable */
128 | #ifdef LUA_META_ROTABLES
129 | extern char stext;
130 | extern char etext;
131 | int luaR_isrotable(void *p) {
132 | return &stext <= ( char* )p && ( char* )p <= &etext;
133 | }
134 | #endif
135 |
--------------------------------------------------------------------------------
/bindings/audio.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 |
4 | #include "vmsystem.h"
5 | #include "vmlog.h"
6 | #include "vmfs.h"
7 | #include "vmchset.h"
8 | #include "vmaudio_play.h"
9 |
10 | #include "lua.h"
11 | #include "lauxlib.h"
12 |
13 | #define MAX_NAME_LEN 32 /* Max length of file name */
14 |
15 | static VMINT g_audio_handle = -1; /* The handle of play */
16 | static VMINT g_audio_interrupt_handle = 0; /* The handle of interrupt */
17 |
18 | /* The callback function when playing. */
19 | void audio_play_callback(VM_AUDIO_HANDLE handle, VM_AUDIO_RESULT result, void* userdata)
20 | {
21 | switch (result)
22 | {
23 | case VM_AUDIO_RESULT_END_OF_FILE:
24 | /* When the end of file is reached, it needs to stop and close the handle */
25 | vm_audio_play_stop(g_audio_handle);
26 | vm_audio_play_close(g_audio_handle);
27 | g_audio_handle = -1;
28 | break;
29 | case VM_AUDIO_RESULT_INTERRUPT:
30 | /* The playback is terminated by another application, for example an incoming call */
31 | vm_audio_play_stop(g_audio_handle);
32 | vm_audio_play_close(g_audio_handle);
33 | g_audio_handle = -1;
34 | break;
35 | default:
36 | break;
37 | }
38 | }
39 |
40 | /* Play the audio file. */
41 | static void _audio_play(char *name)
42 | {
43 | VMINT drv ;
44 | VMWCHAR w_file_name[MAX_NAME_LEN] = {0};
45 | VMCHAR file_name[MAX_NAME_LEN];
46 | vm_audio_play_parameters_t play_parameters;
47 |
48 | /* get file path */
49 | drv = vm_fs_get_removable_drive_letter();
50 | if(drv <0)
51 | {
52 | drv = vm_fs_get_internal_drive_letter();
53 | if(drv <0)
54 | {
55 | vm_log_fatal("not find driver");
56 | return ;
57 | }
58 | }
59 | sprintf(file_name, (VMSTR)"%c:\\%s", drv, name);
60 | vm_chset_ascii_to_ucs2(w_file_name, MAX_NAME_LEN, file_name);
61 |
62 | /* set play parameters */
63 | memset(&play_parameters, 0, sizeof(vm_audio_play_parameters_t));
64 | play_parameters.filename = w_file_name;
65 | play_parameters.reserved = 0; /* no use, set to 0 */
66 | play_parameters.format = VM_AUDIO_FORMAT_MP3; /* file format */
67 | play_parameters.output_path = VM_AUDIO_DEVICE_SPEAKER2; /* set device to output */
68 | play_parameters.async_mode = 0;
69 | play_parameters.callback = audio_play_callback;
70 | play_parameters.user_data = NULL;
71 | g_audio_handle = vm_audio_play_open(&play_parameters);
72 | if(g_audio_handle >= VM_OK)
73 | {
74 | vm_log_info("open success");
75 | }
76 | else
77 | {
78 | vm_log_error("open failed");
79 | }
80 | /* start to play */
81 | vm_audio_play_start(g_audio_handle);
82 | /* register interrupt callback */
83 | g_audio_interrupt_handle = vm_audio_register_interrupt_callback(audio_play_callback,NULL);
84 | }
85 |
86 |
87 | int audio_play(lua_State *L)
88 | {
89 | char *name = lua_tostring(L, -1);
90 |
91 | _audio_play(name);
92 |
93 | return 0;
94 | }
95 |
96 | int audio_stop(lua_State *L)
97 | {
98 | if(g_audio_handle >= 0)
99 | {
100 | vm_audio_play_stop(g_audio_handle);
101 | vm_audio_play_close(g_audio_handle);
102 |
103 | if(g_audio_interrupt_handle!=0)
104 | {
105 | vm_audio_clear_interrupt_callback(g_audio_interrupt_handle);
106 | }
107 | }
108 |
109 | return 0;
110 | }
111 |
112 | int audio_pause(lua_State *L)
113 | {
114 | if(g_audio_handle >= 0)
115 | {
116 | vm_audio_play_pause(g_audio_handle);
117 | return 0;
118 | }
119 |
120 | return -1;
121 | }
122 |
123 | int audio_resume(lua_State *L)
124 | {
125 | if(g_audio_handle >= 0)
126 | {
127 | vm_audio_play_resume(g_audio_handle);
128 | return 0;
129 | }
130 | return -1;
131 | }
132 |
133 |
134 | int audio_set_volume(lua_State *L)
135 | {
136 | int volume = lua_tointeger(L, -1);
137 |
138 | vm_audio_set_volume(volume);
139 |
140 | return 0;
141 | }
142 |
143 | int audio_get_volume(lua_State *L)
144 | {
145 | int volume = vm_audio_get_volume();
146 |
147 | lua_pushnumber(L, volume);
148 |
149 | return 1;
150 | }
151 |
152 | #undef MIN_OPT_LEVEL
153 | #define MIN_OPT_LEVEL 0
154 | #include "lrodefs.h"
155 |
156 | const LUA_REG_TYPE audio_map[] =
157 | {
158 | {LSTRKEY("play"), LFUNCVAL(audio_play)},
159 | {LSTRKEY("stop"), LFUNCVAL(audio_stop)},
160 | {LSTRKEY("pause"), LFUNCVAL(audio_pause)},
161 | {LSTRKEY("resume"), LFUNCVAL(audio_resume)},
162 | {LSTRKEY("set_volume"), LFUNCVAL(audio_set_volume)},
163 | {LSTRKEY("get_volume"), LFUNCVAL(audio_get_volume)},
164 | {LNILKEY, LNILVAL}
165 | };
166 |
167 | LUALIB_API int luaopen_audio(lua_State *L)
168 | {
169 | luaL_register(L, "audio", audio_map);
170 | return 1;
171 | }
172 |
--------------------------------------------------------------------------------
/linkit/lib/LINKIT10/armgcc/scat.ld:
--------------------------------------------------------------------------------
1 |
2 | /* Script for --shared -z combreloc: shared library, combine & sort relocs */
3 | OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm",
4 | "elf32-littlearm")
5 | OUTPUT_ARCH(arm)
6 | ENTRY(gcc_entry)
7 |
8 | SECTIONS
9 | {
10 | /* Read-only sections, merged into text segment: */
11 | . = SEGMENT_START("text-segment", 0) + SIZEOF_HEADERS;
12 | .hash : { *(.hash) }
13 | .gnu.hash : { *(.gnu.hash) }
14 | .dynsym : { *(.dynsym) }
15 | .dynstr : { *(.dynstr) }
16 | .rel.dyn :
17 | {
18 | *(.rel.init)
19 | *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)
20 | *(.rel.fini)
21 | *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)
22 | *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*)
23 | *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
24 | *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)
25 | *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)
26 | *(.rel.ctors)
27 | *(.rel.dtors)
28 | *(.rel.got)
29 | *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)
30 | *(.rel.iplt)
31 | }
32 | .rela.dyn :
33 | {
34 | *(.rela.init)
35 | *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
36 | *(.rela.fini)
37 | *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
38 | *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
39 | *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
40 | *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
41 | *(.rela.ctors)
42 | *(.rela.dtors)
43 | *(.rela.got)
44 | *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
45 | *(.rela.iplt)
46 | }
47 | .rel.plt :
48 | {
49 | *(.rel.plt)
50 | }
51 | .rela.plt :
52 | {
53 | *(.rela.plt)
54 | }
55 | .init :
56 | {
57 | KEEP (*(.init))
58 | } =0
59 | .plt : { *(.plt) }
60 | .iplt : { *(.iplt) }
61 | .text :
62 | {
63 | *(.text.unlikely .text.*_unlikely)
64 | *(.text .stub .text.* .gnu.linkonce.t.*)
65 | /* .gnu.warning sections are handled specially by elf32.em. */
66 | *(.gnu.warning)
67 | *(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx)
68 | } =0
69 | .fini :
70 | {
71 | KEEP (*(.fini))
72 | } =0
73 | PROVIDE (__etext = .);
74 | PROVIDE (_etext = .);
75 | PROVIDE (etext = .);
76 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
77 | .rodata1 : { *(.rodata1) }
78 | .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) }
79 | PROVIDE_HIDDEN (__exidx_start = .);
80 | .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) }
81 | PROVIDE_HIDDEN (__exidx_end = .);
82 | .init_array :
83 | {
84 | KEEP (*(SORT(.init_array.*)))
85 | KEEP (*(.init_array))
86 | }
87 | .fini_array :
88 | {
89 | KEEP (*(SORT(.fini_array.*)))
90 | KEEP (*(.fini_array))
91 | }
92 | .jcr : { KEEP (*(.jcr)) }
93 | .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }
94 | .dynamic : { *(.dynamic) }
95 | .got : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) }
96 | .data :
97 | {
98 | __data_start = . ;
99 | *(.data .data.* .gnu.linkonce.d.*)
100 | SORT(CONSTRUCTORS)
101 | }
102 | .data1 : { *(.data1) }
103 | _edata = .; PROVIDE (edata = .);
104 | __bss_start = .;
105 | __bss_start__ = .;
106 | .bss :
107 | {
108 | *(.dynbss)
109 | *(.bss .bss.* .gnu.linkonce.b.*)
110 | *(COMMON)
111 | /* Align here to ensure that the .bss section occupies space up to
112 | _end. Align after .bss to ensure correct alignment even if the
113 | .bss section disappears because there are no input sections.
114 | FIXME: Why do we need it? When there is no .bss section, we don't
115 | pad the .data section. */
116 | . = ALIGN(. != 0 ? 32 / 8 : 1);
117 | }
118 | _bss_end__ = . ; __bss_end__ = . ;
119 | . = ALIGN(32 / 8);
120 | . = ALIGN(32 / 8);
121 | __end__ = . ;
122 | _end = .; PROVIDE (end = .);
123 | /* Stabs debugging sections. */
124 | .stab 0 : { *(.stab) }
125 | .stabstr 0 : { *(.stabstr) }
126 | .stab.excl 0 : { *(.stab.excl) }
127 | .stab.exclstr 0 : { *(.stab.exclstr) }
128 | .stab.index 0 : { *(.stab.index) }
129 | .stab.indexstr 0 : { *(.stab.indexstr) }
130 | .comment 0 : { *(.comment) }
131 | .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }
132 | .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
133 | /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
134 | }
135 |
--------------------------------------------------------------------------------
/linkit/include/vmdrv_tp.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * Copyright Statement:
3 | * ____________________
4 | * This software is protected by Copyright and the information contained
5 | * herein is confidential. The software may not be copied and the information
6 | * contained herein may not be used or disclosed except with the written
7 | * permission of MediaTek Inc. (C) 2006
8 | *
9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12 | * AN "AS_IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21 | *
22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27 | *
28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33 | *
34 | *****************************************************************************/
35 |
36 | #ifndef VMDRV_TP_SDK_H
37 | #define VMDRV_TP_SDK_H
38 |
39 | #ifdef _cplusplus
40 | extern "C" {
41 | #endif
42 |
43 | #include "vmtype.h"
44 | typedef enum
45 | {
46 | VM_DRV_TP_FALSE,
47 | VM_DRV_TP_TRUE
48 | }VM_DRV_TP_BOOL;
49 |
50 | typedef enum {
51 | VM_DRV_TP_ACTIVE_MODE,
52 | VM_DRV_TP_IDLE_MODE,
53 | VM_DRV_TP_SLEEP_MODE,
54 | VM_DRV_TP_GESTURE_DETECTION_MODE,
55 | VM_DRV_TP_MULTIPLE_POINT_MODE,
56 | VM_DRV_TP_FIRMWARE_UPDATE,
57 | VM_DRV_TP_FM_ENABLE,
58 | VM_DRV_TP_FM_DISABLE
59 | }VM_DRV_TP_DEVICE_MODE;
60 |
61 | typedef enum {
62 | VM_DRV_TP_COMMAND_GET_VERSION,
63 | VM_DRV_TP_COMMAND_GET_CONFIG,
64 | VM_DRV_TP_COMMAND_LOAD_INT_CONFIG,
65 | VM_DRV_TP_COMMAND_LOAD_EXT_CONFIG,
66 | VM_DRV_TP_COMMAND_GET_DIFF_DATA,
67 | VM_DRV_TP_COMMAND_GET_FW_BUFFER,
68 | VM_DRV_TP_COMMAND_DO_FW_UPDATE
69 | }VM_DRV_TP_CTRL_COMMAND;
70 |
71 | typedef struct
72 | {
73 | VMUINT16 event;
74 | VMUINT16 x;
75 | VMUINT16 y;
76 | VMUINT16 z;
77 | }vm_drv_tp_single_event_t;
78 |
79 | typedef struct
80 | {
81 | VMUINT16 model; // Single/Dual/Triple/Four/Five/All gesture
82 | VMUINT16 padding; //currently use for check the structure format correctness, 0xAA
83 | VMUINT32 time_stamp;
84 | vm_drv_tp_single_event_t points[5];
85 | }vm_drv_tp_multiple_event_t;
86 |
87 | typedef struct
88 | {
89 | VMUINT16 resolution;
90 | VMUINT16 threshold;
91 | VMUINT16 report_interval;
92 | VMUINT16 idle_time_interval;
93 | VMUINT16 sleep_time_interval;
94 | VMUINT16 gesture_active_distance;
95 | VMUINT16 ms_calibration[128];
96 | }vm_drv_tp_parameters_t;
97 |
98 | typedef enum {
99 | VM_DRV_TP_UP,
100 | VM_DRV_TP_DOWN
101 | }VM_DRV_TP_PEN_STATE;
102 |
103 | #define VM_DRV_TP_PATTERN 0xAA
104 | #define VM_DRV_TP_CONFIG_LENGTH 106
105 |
106 | typedef struct{
107 | VM_DRV_TP_BOOL (*vm_drv_tp_init_ptr)(void);
108 | VM_DRV_TP_BOOL (*vm_drv_tp_set_device_mode_ptr)(VM_DRV_TP_DEVICE_MODE);
109 | VM_DRV_TP_PEN_STATE (*vm_drv_tp_hisr_ptr)(void);
110 | VM_DRV_TP_BOOL (*vm_drv_tp_get_data_ptr)(vm_drv_tp_multiple_event_t *);
111 | VM_DRV_TP_BOOL (*vm_drv_tp_parameters_ptr)(vm_drv_tp_parameters_t *, VMUINT32, VMUINT32);
112 | void (*vm_drv_tp_power_on_ptr)(VM_DRV_TP_BOOL);
113 | VMUINT32 (*vm_drv_tp_command_ptr)(VMUINT32, void *, void *);
114 | }vm_drv_tp_function_list_t;
115 |
116 | VMINT vm_drv_tp_setup_driver(vm_drv_tp_function_list_t* func_list);
117 | VMUINT32 vm_drv_tp_get_time_stamp(void);
118 |
119 | #ifdef _cplusplus
120 | }
121 | #endif
122 |
123 | #endif
124 |
--------------------------------------------------------------------------------
/linkit/include/vmkeypad.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * Copyright Statement:
3 | * --------------------
4 | * This software is protected by Copyright and the information contained
5 | * herein is confidential. The software may not be copied and the information
6 | * contained herein may not be used or disclosed except with the written
7 | * permission of MediaTek Inc. (C) 2005-2015
8 | *
9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21 | *
22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27 | *
28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33 | *
34 | *****************************************************************************/
35 |
36 | #ifndef VMKEYPAD_SDK_H
37 | #define VMKEYPAD_SDK_H
38 |
39 | #ifdef __cplusplus
40 | extern "C" {
41 | #endif
42 |
43 | #include "vmtype.h"
44 |
45 | /* Keypad events passed to vm_keypad_event_callback. */
46 | typedef enum
47 | {
48 | VM_KEYPAD_EVENT_UP = 1, /* Key up event. */
49 | VM_KEYPAD_EVENT_DOWN = 2, /* Key down event. */
50 | VM_KEYPAD_EVENT_LONG_PRESS = 3, /* Key long press event. */
51 | VM_KEYPAD_EVENT_REPEAT = 4, /* Key repeat event. */
52 |
53 | VM_KEYPAD_EVENT_MAX = 0x7FFFFFFF
54 | } VM_KEYPAD_EVENT;
55 |
56 | /*****************************************************************************
57 | * FUNCTION
58 | * vm_keypad_event_callback
59 | * DESCRIPTION
60 | * Callback function of keypad event handler. Register this callback with
61 | * vm_keypad_register_event_callback to receive key events processed by
62 | * underlying framework.
63 | * The underlying system framework may process special key codes such as
64 | * power key. Developers may choose to intercept the key code
65 | * by returning non-zero values in this callback function, or bypassing
66 | * the key code to system framework by returning 0.
67 | * PARAMETERS
68 | * event: [IN] Refer to VM_KEYPAD_EVENT.
69 | * code: [IN] The key code associated with the event.
70 | * RETURNS
71 | * This event handler should return non-zero values if application has
72 | * processed the key event and don't want to pass the key event to the
73 | * system framework.
74 | * Return 0 to bypass this key event to underlying system framework.
75 | *****************************************************************************/
76 | typedef VMINT (*vm_keypad_event_callback)(VM_KEYPAD_EVENT event, VMINT code);
77 |
78 |
79 | /*****************************************************************************
80 | * FUNCTION
81 | * vm_reg_keyboard_callback
82 | * DESCRIPTION
83 | * Registers system keypad event callback.
84 | * The keypad events are passed to the registered callback.
85 | * There can only have one handler registered at the same time.
86 | * PARAMETERS
87 | * vm_keypad_event_callback: [IN] Callback function that processes the keypad
88 | * event. Pass NULL to de-register the callback.
89 | * RETURNS
90 | * VM_RESULT
91 | *****************************************************************************/
92 | VM_RESULT vm_keypad_register_event_callback(vm_keypad_event_callback callback);
93 |
94 |
95 | #ifdef __cplusplus
96 | }
97 | #endif
98 |
99 | #endif /* VMKEYPAD_SDK_H */
100 |
101 |
--------------------------------------------------------------------------------
/lua/lgc.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Garbage Collector
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lgc_h
8 | #define lgc_h
9 |
10 |
11 | #include "lobject.h"
12 |
13 |
14 | /*
15 | ** Possible states of the Garbage Collector
16 | */
17 | #define GCSpause 0
18 | #define GCSpropagate 1
19 | #define GCSsweepstring 2
20 | #define GCSsweep 3
21 | #define GCSfinalize 4
22 |
23 |
24 | /*
25 | ** some userful bit tricks
26 | */
27 | #define resetbits(x,m) ((x) &= cast(lu_byte, ~(m)))
28 | #define setbits(x,m) ((x) |= (m))
29 | #define testbits(x,m) ((x) & (m))
30 | #define bitmask(b) (1<<(b))
31 | #define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2))
32 | #define l_setbit(x,b) setbits(x, bitmask(b))
33 | #define resetbit(x,b) resetbits(x, bitmask(b))
34 | #define testbit(x,b) testbits(x, bitmask(b))
35 | #define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2)))
36 | #define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2)))
37 | #define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2)))
38 |
39 |
40 | /*
41 | ** Possible Garbage Collector flags.
42 | ** Layout for bit use in 'gsflags' field in global_State structure.
43 | ** bit 0 - Protect GC from recursive calls.
44 | ** bit 1 - Don't try to shrink string table if EGC was called during a string table resize.
45 | */
46 | #define GCFlagsNone 0
47 | #define GCBlockGCBit 0
48 | #define GCResizingStringsBit 1
49 |
50 |
51 | #define is_block_gc(L) testbit(G(L)->gcflags, GCBlockGCBit)
52 | #define set_block_gc(L) l_setbit(G(L)->gcflags, GCBlockGCBit)
53 | #define unset_block_gc(L) resetbit(G(L)->gcflags, GCBlockGCBit)
54 | #define is_resizing_strings_gc(L) testbit(G(L)->gcflags, GCResizingStringsBit)
55 | #define set_resizing_strings_gc(L) l_setbit(G(L)->gcflags, GCResizingStringsBit)
56 | #define unset_resizing_strings_gc(L) resetbit(G(L)->gcflags, GCResizingStringsBit)
57 |
58 | /*
59 | ** Layout for bit use in `marked' field:
60 | ** bit 0 - object is white (type 0)
61 | ** bit 1 - object is white (type 1)
62 | ** bit 2 - object is black
63 | ** bit 3 - for thread: Don't resize thread's stack
64 | ** bit 3 - for userdata: has been finalized
65 | ** bit 3 - for tables: has weak keys
66 | ** bit 4 - for tables: has weak values
67 | ** bit 5 - object is fixed (should not be collected)
68 | ** bit 6 - object is "super" fixed (only the main thread)
69 | ** bit 7 - object is (partially) stored in read-only memory
70 | */
71 |
72 |
73 | #define WHITE0BIT 0
74 | #define WHITE1BIT 1
75 | #define BLACKBIT 2
76 | #define FIXEDSTACKBIT 3
77 | #define FINALIZEDBIT 3
78 | #define KEYWEAKBIT 3
79 | #define VALUEWEAKBIT 4
80 | #define FIXEDBIT 5
81 | #define SFIXEDBIT 6
82 | #define READONLYBIT 7
83 | #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT)
84 |
85 |
86 | #define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
87 | #define isblack(x) testbit((x)->gch.marked, BLACKBIT)
88 | #define isgray(x) (!isblack(x) && !iswhite(x))
89 |
90 | #define otherwhite(g) (g->currentwhite ^ WHITEBITS)
91 | #define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS)
92 |
93 | #define changewhite(x) ((x)->gch.marked ^= WHITEBITS)
94 | #define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT)
95 |
96 | #define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x)))
97 |
98 | #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS)
99 |
100 | #define isfixedstack(x) testbit((x)->marked, FIXEDSTACKBIT)
101 | #define fixedstack(x) l_setbit((x)->marked, FIXEDSTACKBIT)
102 | #define unfixedstack(x) resetbit((x)->marked, FIXEDSTACKBIT)
103 |
104 | #define luaC_checkGC(L) { \
105 | condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \
106 | if (G(L)->totalbytes >= G(L)->GCthreshold) \
107 | luaC_step(L); }
108 |
109 |
110 | #define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \
111 | luaC_barrierf(L,obj2gco(p),gcvalue(v)); }
112 |
113 | #define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \
114 | luaC_barrierback(L,t); }
115 |
116 | #define luaC_objbarrier(L,p,o) \
117 | { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
118 | luaC_barrierf(L,obj2gco(p),obj2gco(o)); }
119 |
120 | #define luaC_objbarriert(L,t,o) \
121 | { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); }
122 |
123 | LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all);
124 | LUAI_FUNC void luaC_callGCTM (lua_State *L);
125 | LUAI_FUNC void luaC_freeall (lua_State *L);
126 | LUAI_FUNC void luaC_step (lua_State *L);
127 | LUAI_FUNC void luaC_fullgc (lua_State *L);
128 | LUAI_FUNC int luaC_sweepstrgc (lua_State *L);
129 | LUAI_FUNC void luaC_marknew (lua_State *L, GCObject *o);
130 | LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt);
131 | LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv);
132 | LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v);
133 | LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t);
134 |
135 |
136 | #endif
137 |
--------------------------------------------------------------------------------
/linkit/include/vmdns.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * Copyright Statement:
3 | * --------------------
4 | * This software is protected by Copyright and the information contained
5 | * herein is confidential. The software may not be copied and the information
6 | * contained herein may not be used or disclosed except with the written
7 | * permission of MediaTek Inc. (C) 2005-2015
8 | *
9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21 | *
22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27 | *
28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33 | *
34 | *****************************************************************************/
35 |
36 | #ifndef VMDNS_SDK_H
37 | #define VMDNS_SDK_H
38 |
39 | #ifdef __cplusplus
40 | extern "C" {
41 | #endif
42 |
43 | #include "vmtype.h"
44 | #include "vmgsm_gprs.h"
45 | #include "vmbearer.h"
46 |
47 | /* The DNS handle */
48 | typedef VMINT VM_DNS_HANDLE;
49 |
50 | /* The DNS maximum address length */
51 | #define VM_SOC_DNS_MAX_ADDRESS 5
52 |
53 | /* The DNS query result struct */
54 | typedef struct
55 | {
56 | VMUINT address[VM_SOC_DNS_MAX_ADDRESS]; /* The IP address. */
57 | VMINT number; /* The number of result. */
58 | VMINT error_cause; /* The vm_ps_cause_enum */
59 | } vm_dns_result_t;
60 |
61 | /* DNS result */
62 | typedef enum
63 | {
64 | VM_DNS_SUCCESS = 0, /* The success result. */
65 | VM_DNS_ERROR = -1, /* The general error result. */
66 | VM_DNS_INVALID_PARAMETER = -2, /* The parameter is invalid result. */
67 | VM_DNS_LIMIT_RESOURCE = -3, /* The resource is used up result. */
68 | } VM_DNS_RESULT;
69 |
70 | /*****************************************************************************
71 | * FUNCTION
72 | * vm_dns_get_host_by_name_callback
73 | * DESCRIPTION
74 | * This is the callback function of vm_dns_get_host_by_name, it will be called if it doesn't get the DNS result immediately.
75 | * PARAMETERS
76 | * handle : [IN] The DNS handle.
77 | * result : [IN] The DNS result.
78 | * user_data : [IN] The user data.
79 | * RETURNS
80 | * VM_RESULT
81 | *****************************************************************************/
82 | typedef VM_RESULT (*vm_dns_get_host_by_name_callback)(VM_DNS_HANDLE handle, vm_dns_result_t* result, void* user_data);
83 |
84 |
85 | /*****************************************************************************
86 | * FUNCTION
87 | * vm_dns_get_host_by_name
88 | * DESCRIPTION
89 | * This function retrieves the IP addresses associated with the specified host name.
90 | * PARAMETERS
91 | * data_account_type : [IN] The data account type bearer.
92 | * host : [IN] The domain to be resolved.
93 | * result : [OUT] The DNS parsed result.
94 | * callback : [IN] The callback function.
95 | * user_data : [IN] The ser data.
96 | * RETURNS
97 | * VM_DNS_HANDLE
98 | *****************************************************************************/
99 | VM_DNS_HANDLE vm_dns_get_host_by_name(VM_BEARER_DATA_ACCOUNT_TYPE data_account_type,
100 | const VMCHAR* host,
101 | vm_dns_result_t* result,
102 | vm_dns_get_host_by_name_callback callback, void* user_data);
103 |
104 | #ifdef __cplusplus
105 | }
106 | #endif
107 | #endif
108 |
--------------------------------------------------------------------------------
/linkit/include/vmwdt.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * Copyright Statement:
3 | * --------------------
4 | * This software is protected by Copyright and the information contained
5 | * herein is confidential. The software may not be copied and the information
6 | * contained herein may not be used or disclosed except with the written
7 | * permission of MediaTek Inc. (C) 2005-2015
8 | *
9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21 | *
22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27 | *
28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33 | *
34 | *****************************************************************************/
35 |
36 | #ifndef VMWDT_SDK_H
37 | #define VMWDT_SDK_H
38 |
39 | #ifdef __cplusplus
40 | extern "C" {
41 | #endif
42 |
43 | #include "vmtype.h"
44 |
45 | /* Watchdog handle */
46 | typedef VMINT VM_WDT_HANDLE;
47 |
48 |
49 | /*****************************************************************************
50 | * FUNCTION
51 | * vm_wdt_start
52 | * DESCRIPTION
53 | * Starts a watchdog.
54 | * PARAMETERS
55 | * tick: [IN] The value of the watchdog timer, in ticks.
56 | * RETURNS
57 | * If it returns a positive integer, it is the handle of the watchdog.
58 | * Otherwise, it returns a negative integer.
59 | * EXAMPLE
60 | *
61 | * VM_WDT_HANDLE handle = vm_wdt_start(1000);
62 | *
63 | * if (handle >= 0) {
64 | * // Do something.
65 | * vm_wdt_reset(handle);
66 | * } else {
67 | * // Do error logging.
68 | * }
69 | *
70 | * // Done with doing something.
71 | * vm_wdt_stop(handle);
72 | *
73 | *****************************************************************************/
74 | VM_WDT_HANDLE vm_wdt_start(VMUINT tick);
75 |
76 | /*****************************************************************************
77 | * FUNCTION
78 | * vm_wdt_reset
79 | * DESCRIPTION
80 | * Resets the watchdog timer. The timer will start again immediately and will
81 | * fire after the number of ticks set in the vm_wdt_start() elapses.
82 | * PARAMETERS
83 | * handle: [IN] The watchdog handle returned from vm_wdt_start().
84 | * EXAMPLE
85 | *
86 | * // Time out is set to 1,000 ticks.
87 | * VM_WDT_HANDLE handle = vm_wdt_start(1000);
88 | *
89 | * // Check the return value.
90 | * if (handle >= 0) {
91 | * // Do something.
92 | * vm_wdt_reset(handle);
93 | * } else {
94 | * // Do error logging.
95 | * }
96 | *
97 | * // Do something.
98 | * vm_wdt_reset(handle);
99 | *
100 | * // Done with the watchdog timer.
101 | * vm_wdt_stop(handle);
102 | *****************************************************************************/
103 | void vm_wdt_reset(VM_WDT_HANDLE handle);
104 |
105 | /*****************************************************************************
106 | * FUNCTION
107 | * vm_wdt_stop
108 | * DESCRIPTION
109 | * Stops the watchdog timer.
110 | * PARAMETERS
111 | * handle: [IN] The watchdog handle returned from vm_wdt_start().
112 | * RETURNS
113 | * void
114 | * EXAMPLE
115 | *
116 | * VM_WDT_HANDLE handle = vm_wdt_start(1000);
117 | *
118 | * // Do something.
119 | * vm_wdt_reset(handle);
120 | *
121 | * // Done with the watchdog timer.
122 | * vm_wdt_stop(handle);
123 | *****************************************************************************/
124 | void vm_wdt_stop(VM_WDT_HANDLE handle);
125 |
126 | #ifdef __cplusplus
127 | }
128 | #endif
129 |
130 | #endif /* VMWDT_SDK_H */
131 |
132 |
--------------------------------------------------------------------------------
/linkit/include/vmdcl_kbd.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * Copyright Statement:
3 | * ____________________
4 | * This software is protected by Copyright and the information contained
5 | * herein is confidential. The software may not be copied and the information
6 | * contained herein may not be used or disclosed except with the written
7 | * permission of MediaTek Inc. (C) 2006
8 | *
9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12 | * AN "AS_IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21 | *
22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27 | *
28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33 | *
34 | *****************************************************************************/
35 |
36 | #ifndef VMDCL_KBD_SDK_H
37 | #define VMDCL_KBD_SDK_H
38 |
39 |
40 | #ifdef __cplusplus
41 | extern "C" {
42 | #endif
43 |
44 | /******************************************************************
45 | * DESCRIPTION
46 | * This enum defines the device for kbd module,used in vm_dcl_open as a parameter.
47 | * To control KBD, you should use DCL(Driver Common Layer) APIs.
48 | * EXAMPLE
49 | *
50 | * #include "vm_dcl.h"
51 | * VM_DCL_HANDLE kbd_handle; // Declare a VM_DCL_HANDLE variable.
52 | * kbd_handle = vm_dcl_open(VM_DCL_KBD,0); // Call vm_dcl_open to get a handle.
53 | *
54 | *******************************************************************/
55 | typedef enum
56 | {
57 | VM_DCL_KBD_START = VM_DCL_KBD_GROUP_START, /*KBD device start*/
58 | VM_DCL_KBD, /*This device is used to control keypad.*/
59 | }VM_DCL_KBD_DEVICE;
60 |
61 | /******************************************************************
62 | * DESCRIPTION
63 | * This enum define the control command for KBD module,used in vm_dcl_control as parameter.
64 | * With different commands, user could control the different function of the KBD.
65 | * To control KBD, you should use DCL(Driver Common Layer) APIs.
66 | * EXAMPLE
67 | *
68 | * #include "vm_dcl.h"
69 | * VM_DCL_HANDLE kbd_handle; // Declare a VM_DCL_HANDLE variable.
70 | * vm_dcl_kbd_control_pin_t kbdmap;
71 | * kbd_handle = vm_dcl_open(VM_DCL_KBD,0); // First, we call vm_dcl_open to get a handle. the second parameter always fill 0.
72 | * kbdmap.colmap = 0x01;
73 | * kbdmap.rowmap = 0x01;
74 | * vm_dcl_control(kbd_handle,VM_DCL_KBD_COMMAND_CONFIG_PIN,(void *)(&kbdmap)); // we call vm_dcl_control to set the col and row.
75 | * vm_dcl_close(kbd_handle); // Finally, we call vm_dcl_close
76 | *
77 | *******************************************************************/
78 |
79 | typedef enum
80 | {
81 | VM_DCL_KBD_COMMAND_CONFIG_PIN = 0xC0D, //control keypad row and col
82 | }VM_DCL_KBD_COMMAND;
83 |
84 |
85 | /******************************************************************
86 | * DESCRIPTION
87 | * This struct is for VM_DCL_KBD_COMMAND_CONFIG_PIN control command,used in vm_dcl_control as parameter.
88 | * With this command, you can set the HW keypad col and row,and enable it.
89 | * You can find the sample code in the description of VM_DCL_KBD_COMMAND.
90 | * All commands have similar usage.
91 | *******************************************************************/
92 |
93 | /*the control command data for configure col and row pin enalbe*/
94 | typedef struct
95 | {
96 | VMUINT16 col_map; /*col map,lowest is col0*/
97 | VMUINT16 row_map; /*row map,lowest is row0*/
98 | }vm_dcl_kbd_control_pin_t;
99 |
100 | #ifdef __cplusplus
101 | }
102 | #endif
103 |
104 | #endif
105 |
106 |
--------------------------------------------------------------------------------
/src/tp_goodix_gt9xx.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef __TP_GOODIX_GT9XX_H__
3 | #define __TP_GOODIX_GT9XX_H__
4 |
5 | #include "vmtype.h"
6 | #include "vmdrv_tp.h"
7 |
8 | #define CTP_SLAVE_ADDR 0xBA
9 | #define CTP_POWER_MODE_REG 0x8040
10 | #define CTP_FW_HEADER_SIZE 0
11 | #define CTP_VERSION_INFO_REG 0x8140
12 | #define CTP_MASTER_CODE_REG 0xC000
13 | #define CTP_FIRMWARE_SIZE (0x8000+CTP_FW_HEADER_SIZE)
14 | #define CTP_TOUCH_INFO_REG_BASE 0x814E
15 | #define CTP_POINT_INFO_REG_BASE 0x814F
16 | #define CTP_CONFIG_REG_BASE 0x8047
17 | #define CTP_FIRMWARE_VERSION 0x8147
18 | #define CTP_NVRAM_I2C_ADDRESS 0x5094
19 | #define CTP_NVRAM_OPERATION_SIZE 0x5096
20 | #define CTP_NVRAM_FILE_OFFSET 0x4196
21 | #define CTP_NVRAM_OPERATION_CHECKSUM 0x4194
22 | #define CTP_FLASH_POWER_OFF 0x4284
23 |
24 | #define CTP_SRAM_BANK 0x4048
25 | #define CTP_MEM_CD_EN 0x4049
26 | #define CTP_CACHE_EN 0x404B
27 | #define CTP_TMR0_EN 0x40B0
28 | #define CTP_SWRST_B0_ 0x4180
29 | #define CTP_CPU_SWRST_PULSE 0x4184
30 | #define CTP_BOOTCTL_B0_ 0x4190
31 | #define CTP_BOOT_OPT_B0_ 0x4218
32 | #define CTP_BOOT_CTL_ 0x5094
33 | #define CTP_ANA_RXADC_B0_ 0x4250
34 | #define CTP_RG_LDO_A18_PWD 0x426f
35 | #define CTP_RG_BG_PWD 0x426a
36 | #define CTP_RG_CLKGEN_PWD 0x4269
37 | #define CTP_RG_DMY 0x4282
38 | #define CTP_RG_OSC_CALIB 0x4268
39 | #define CTP_OSC_CK_SEL 0x4030
40 |
41 | #define CTP_HANDSHAKING_START_REG 0xFFF
42 | #define CTP_HANDSHAKING_END_REG 0x8000
43 | #define CTP_SOFT_RESET_MODE 0x01
44 | #define CTP_POINT_INFO_LEN 8
45 | #define TPD_MAX_POINTS 5
46 | #define MAX_TRANSACTION_LENGTH 8
47 | #define I2C_DEVICE_ADDRESS_LEN 2
48 |
49 | #define TPD_PROXIMITY_WORK_REG_BASE 0x920
50 | #define TPD_PROXIMITY_SAMPLE_REG 0xA88
51 | #define TPD_PROXIMITY_BASE_REG 0xAD8
52 | #define TPD_LARGE_OBJECT_DETECT_REG 0x71D
53 |
54 | #define _FW_TOTAL_PAGES 32
55 | #define _FW_FRAME_PAGES 16
56 | #define _DSP_TOTAL_PAGES 4
57 | #define _BOOTCODE_TOTAL_PAGES 32
58 | #define _FW_FRAME_BYTES (_FW_FRAME_PAGES*1024)
59 | #define _DSP_TOTAL_BYTES (_DSP_TOTAL_PAGES*1024)
60 | #define _BOOTCODE_TOTAL_BYTES (_BOOTCODE_TOTAL_PAGES*1024)
61 |
62 | #define CTP_STAT_NUMBER_TOUCH 0xF
63 | #define GPIO_CTP_INT_PIN gpio_ctp_eint_pin
64 | #define GPIO_CTP_SHUTDN_PIN gpio_ctp_reset_pin
65 | #define GPIO_CTP_EINT_NO 4
66 | #define CONFIG_LEN (186)
67 |
68 | //hotknot
69 | #define GTP_COMPATIBLE_MODE 0 //not use in FLASH series
70 | #ifdef __HOTKNOT_SUPPORT__
71 | #define GTP_HOTKNOT_MODULE 1 //for HOTKNOT feature
72 | #else
73 | #define GTP_HOTKNOT_MODULE 0 //for HOTKNOT feature
74 | #endif
75 | #define GTP_AUTO_UPDATE_HOTKNOT 0 //for HOTKNOT update firmware in FS
76 | #define GTP_DEBUG_ARRAY_ON 1
77 | #define GTP_SUPPORT_I2C_DMA 1
78 |
79 |
80 |
81 | #define GTP_DEBUG_ON 1
82 |
83 | #define REG_2ND_CMD 0x8040
84 | #define REG_1ST_CMD 0x8046
85 | #define REG_LINK_MODE 0x81A8
86 | #define REG_PAIR_FLAG 0x81AA
87 | #define REG_XFE_STATE 0xAB10
88 | #define REG_NOTIFY_STATE 0xAB1F
89 | #define REG_SNDBUF_START 0xAC90
90 | #define REG_DATA_FRESH 0xAD91
91 | #define REG_RCVBUF_STATE 0xAE10
92 | #define REG_RCVBUF_START 0xAE12
93 |
94 | #define CMD_ENTER_SLAVE 0x20
95 | #define CMD_ENTER_MASTER 0x21
96 | #define CMD_ENTER_TRANSFER 0x22
97 | #define CMD_EXIT_SLAVE 0x28
98 | #define CMD_EXIT_MASTER 0x29
99 | #define CMD_EXIT_TRANSFER 0x2A
100 |
101 | #define MODE_TOUCH_ONLY 0x00
102 | #define MODE_PAIRED 0X55
103 | #define MODE_SLAVE 0x88
104 | #define MODE_MASTER 0x99
105 | #define MODE_SEND 0xAA
106 | #define MODE_RECEIVE 0xBB
107 |
108 | typedef enum
109 | {
110 | CHIP_TYPE_GT9 = 0,
111 | CHIP_TYPE_GT9F = 1,
112 | }CHIP_TYPE_T;
113 |
114 |
115 | //end
116 | typedef struct
117 | {
118 | VMUINT8 vendor_id_1;
119 | VMUINT8 vendor_id_2;
120 | VMUINT8 product_id_1;
121 | VMUINT8 product_id_2;
122 | VMUINT8 version_1;
123 | VMUINT8 version_2;
124 | } ctp_info_t;
125 |
126 | extern VM_DRV_TP_BOOL ctp_i2c_receive_ext(VMUINT8 ucDeviceAddr, VMUINT16 ucBufferIndex, VMUINT8* pucData, VMUINT32 unDataLength);
127 | extern VM_DRV_TP_BOOL ctp_i2c_send(VMUINT8 ucDeviceAddr, VMUINT8 ucBufferIndex, VMUINT8* pucData, VMUINT32 unDataLength);
128 |
129 | void tp_gt9xx_init(void);
130 | VM_DRV_TP_BOOL ctp_goodix_gt9xx_get_data(vm_drv_tp_multiple_event_t *tpes);
131 |
132 | #define CTP_I2C_read(a,b,c) ctp_i2c_receive_ext( CTP_SLAVE_ADDR, a, b, c)
133 | #define CTP_I2C_send(a,b,c) ctp_i2c_send_ext( CTP_SLAVE_ADDR, a, b, c)
134 |
135 |
136 | #endif
137 |
--------------------------------------------------------------------------------
/lua/lstring.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** String table (keeps all strings handled by Lua)
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 |
8 | #include
9 |
10 | #define lstring_c
11 | #define LUA_CORE
12 |
13 | #include "lua.h"
14 |
15 | #include "lmem.h"
16 | #include "lobject.h"
17 | #include "lstate.h"
18 | #include "lstring.h"
19 |
20 | #define LUAS_READONLY_STRING 1
21 | #define LUAS_REGULAR_STRING 0
22 |
23 | void luaS_resize (lua_State *L, int newsize) {
24 | stringtable *tb;
25 | int i;
26 | tb = &G(L)->strt;
27 | if (luaC_sweepstrgc(L) || newsize == tb->size || is_resizing_strings_gc(L))
28 | return; /* cannot resize during GC traverse or doesn't need to be resized */
29 | set_resizing_strings_gc(L);
30 | if (newsize > tb->size) {
31 | luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *);
32 | for (i=tb->size; ihash[i] = NULL;
33 | }
34 | /* rehash */
35 | for (i=0; isize; i++) {
36 | GCObject *p = tb->hash[i];
37 | tb->hash[i] = NULL;
38 | while (p) { /* for each node in the list */
39 | GCObject *next = p->gch.next; /* save next */
40 | unsigned int h = gco2ts(p)->hash;
41 | int h1 = lmod(h, newsize); /* new position */
42 | lua_assert(cast_int(h%newsize) == lmod(h, newsize));
43 | p->gch.next = tb->hash[h1]; /* chain it */
44 | tb->hash[h1] = p;
45 | p = next;
46 | }
47 | }
48 | if (newsize < tb->size)
49 | luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *);
50 | tb->size = newsize;
51 | unset_resizing_strings_gc(L);
52 | }
53 |
54 | static TString *newlstr (lua_State *L, const char *str, size_t l,
55 | unsigned int h, int readonly) {
56 | TString *ts;
57 | stringtable *tb;
58 | if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char))
59 | luaM_toobig(L);
60 | tb = &G(L)->strt;
61 | if ((tb->nuse + 1) > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2)
62 | luaS_resize(L, tb->size*2); /* too crowded */
63 | ts = cast(TString *, luaM_malloc(L, readonly ? sizeof(char**)+sizeof(TString) : (l+1)*sizeof(char)+sizeof(TString)));
64 | ts->tsv.len = l;
65 | ts->tsv.hash = h;
66 | ts->tsv.marked = luaC_white(G(L));
67 | ts->tsv.tt = LUA_TSTRING;
68 | if (!readonly) {
69 | memcpy(ts+1, str, l*sizeof(char));
70 | ((char *)(ts+1))[l] = '\0'; /* ending 0 */
71 | } else {
72 | *(char **)(ts+1) = (char *)str;
73 | luaS_readonly(ts);
74 | }
75 | h = lmod(h, tb->size);
76 | ts->tsv.next = tb->hash[h]; /* chain new entry */
77 | tb->hash[h] = obj2gco(ts);
78 | tb->nuse++;
79 | return ts;
80 | }
81 |
82 |
83 | static TString *luaS_newlstr_helper (lua_State *L, const char *str, size_t l, int readonly) {
84 | GCObject *o;
85 | unsigned int h = cast(unsigned int, l); /* seed */
86 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */
87 | size_t l1;
88 | for (l1=l; l1>=step; l1-=step) /* compute hash */
89 | h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1]));
90 | for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)];
91 | o != NULL;
92 | o = o->gch.next) {
93 | TString *ts = rawgco2ts(o);
94 | if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) {
95 | /* string may be dead */
96 | if (isdead(G(L), o)) changewhite(o);
97 | return ts;
98 | }
99 | }
100 | return newlstr(L, str, l, h, readonly); /* not found */
101 | }
102 |
103 | extern char stext;
104 | extern char etext;
105 |
106 | static int lua_is_ptr_in_ro_area(const char *p) {
107 | #ifdef LUA_CROSS_COMPILER
108 | return 0;
109 | #else
110 | return p >= &stext && p <= &etext;
111 | #endif
112 | }
113 |
114 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
115 | // If the pointer is in a read-only memory and the string is at least 4 chars in length,
116 | // create it as a read-only string instead
117 | if(lua_is_ptr_in_ro_area(str) && l+1 > sizeof(char**) && l == strlen(str))
118 | return luaS_newlstr_helper(L, str, l, LUAS_READONLY_STRING);
119 | else
120 | return luaS_newlstr_helper(L, str, l, LUAS_REGULAR_STRING);
121 | }
122 |
123 |
124 | LUAI_FUNC TString *luaS_newrolstr (lua_State *L, const char *str, size_t l) {
125 | if(l+1 > sizeof(char**) && l == strlen(str))
126 | return luaS_newlstr_helper(L, str, l, LUAS_READONLY_STRING);
127 | else // no point in creating a RO string, as it would actually be larger
128 | return luaS_newlstr_helper(L, str, l, LUAS_REGULAR_STRING);
129 | }
130 |
131 |
132 | Udata *luaS_newudata (lua_State *L, size_t s, Table *e) {
133 | Udata *u;
134 | if (s > MAX_SIZET - sizeof(Udata))
135 | luaM_toobig(L);
136 | u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata)));
137 | u->uv.marked = luaC_white(G(L)); /* is not finalized */
138 | u->uv.tt = LUA_TUSERDATA;
139 | u->uv.len = s;
140 | u->uv.metatable = NULL;
141 | u->uv.env = e;
142 | /* chain it on udata list (after main thread) */
143 | u->uv.next = G(L)->mainthread->next;
144 | G(L)->mainthread->next = obj2gco(u);
145 | return u;
146 | }
147 |
148 |
--------------------------------------------------------------------------------
/linkit/include/vmcmd.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * Copyright Statement:
3 | * --------------------
4 | * This software is protected by Copyright and the information contained
5 | * herein is confidential. The software may not be copied and the information
6 | * contained herein may not be used or disclosed except with the written
7 | * permission of MediaTek Inc. (C) 2005-2015
8 | *
9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21 | *
22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27 | *
28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33 | *
34 | *****************************************************************************/
35 |
36 | #ifndef VMCMD_SDK_H
37 | #define VMCMD_SDK_H
38 |
39 | #ifdef __cplusplus
40 | extern "C" {
41 | #endif
42 |
43 | #include "vmtype.h"
44 |
45 | /* This function represents the incoming command from the Monitor tool. */
46 | typedef struct
47 | {
48 | VMUINT32 command_type; /* Reserved type. */
49 | VMUINT32 command_buffer_size; /* The size of the incoming command buffer. */
50 | VMSTR command_buffer; /* The buffer that stores the command. */
51 | } vm_cmd_command_t;
52 |
53 | /*****************************************************************************
54 | * FUNCTION
55 | * vm_cmd_callback
56 | * DESCRIPTION
57 | * This represents the callback function that handles incoming commands from the Monitor tool.
58 | * This callback is invoked in the main thread.
59 | *
60 | * PARAMETERS
61 | * command : [IN] The command that is passed from the Monitor tool.
62 | * The content of the buffer is only valid within the
63 | * callback. Once the callback returns, buffer pointed by
64 | * command.command_buffer becomes invalid.
65 | * user_data : [IN] The user_data passed to vm_cmd_open_port.
66 | * RETURNS
67 | * void.
68 | *****************************************************************************/
69 | typedef void (*vm_cmd_callback)(vm_cmd_command_t* command, void* user_data);
70 |
71 | /*****************************************************************************
72 | * FUNCTION
73 | * vm_cmd_open_port
74 | * DESCRIPTION
75 | * This function is called to start listening for commands from the Monitor tool.
76 | * Commands are passed from the port, which ranges from 500 to 65535.
77 | *
78 | * For example, if the command is passed into port 5000, then
79 | * only the callback registered with port number 5000 will be invoked.
80 | *
81 | * This API fails when invalid port number is assigned.
82 | *
83 | * PARAMETERS
84 | * port : [IN] The port number, which ranges from 500 to 65535.
85 | * callback : [IN] The callback that is invoked when it receives command
86 | * from the assigned port.
87 | * user_data : [IN] User data for the callback; Pass NULL if unused.
88 | * RETURNS
89 | * VM_RESULT.
90 | *****************************************************************************/
91 | VM_RESULT vm_cmd_open_port(VMUINT16 port,
92 | vm_cmd_callback callback,
93 | void* user_data);
94 |
95 | /*****************************************************************************
96 | * FUNCTION
97 | * vm_cmd_close_port
98 | * DESCRIPTION
99 | * This function closes the command port. The callback will no longer be invoked even when
100 | * Monitor tool passes command.
101 | * PARAMETERS
102 | * port : [IN] The port number that is opened by vm_open_command_port().
103 | *****************************************************************************/
104 | void vm_cmd_close_port(VMUINT16 port);
105 |
106 |
107 | #ifdef __cplusplus
108 | }
109 | #endif
110 |
111 | #endif /* VMCMD_SDK_H */
112 |
113 |
--------------------------------------------------------------------------------
/linkit/include/vmtouch.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * Copyright Statement:
3 | * --------------------
4 | * This software is protected by Copyright and the information contained
5 | * herein is confidential. The software may not be copied and the information
6 | * contained herein may not be used or disclosed except with the written
7 | * permission of MediaTek Inc. (C) 2005-2015
8 | *
9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21 | *
22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27 | *
28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33 | *
34 | *****************************************************************************/
35 |
36 | #ifndef VMTOUCH_SDK_H
37 | #define VMTOUCH_SDK_H
38 |
39 | #ifdef __cplusplus
40 | extern "C" {
41 | #endif
42 |
43 | #include "vmtype.h"
44 |
45 | typedef enum
46 | {
47 | VM_TOUCH_EVENT_TAP = 1, /* Touch down event. */
48 | VM_TOUCH_EVENT_RELEASE = 2, /* Touch release event. */
49 | VM_TOUCH_EVENT_MOVE = 3, /* Touch move event. */
50 | VM_TOUCH_EVENT_LONG_TAP = 4, /* Touch long tap event. Note:
51 | 1. VM_TOUCH_EVENT_LONG_TAP event is
52 | invoked when the Touch is tapped for
53 | a period of time and stays at the
54 | same place where it is tapped down.
55 | 2. If Touch move happen after Touch down,
56 | there will be no
57 | VM_TOUCH_EVENT_LONG_TAP event.
58 | 3. VM_TOUCH_EVENT_LONG_TAP can only
59 | happen one time at most before
60 | VM_TOUCH_EVENT_RELEASE. */
61 | VM_TOUCH_EVENT_DOUBLE_CLICK = 5,/* Touch double click event. */
62 | VM_TOUCH_EVENT_REPEAT = 6, /* Touch repeat event. Note:
63 | 1. VM_TOUCH_EVENT_REPEAT can happen after
64 | VM_TOUCH_EVENT_LONG_TAP or
65 | VM_TOUCH_EVENT_MOVE or another
66 | VM_TOUCH_EVENT_REPEAT.
67 | 2. The coordinate follows
68 | previous VM_TOUCH_EVENT_REPEAT
69 | events.*/
70 | VM_TOUCH_EVENT_ABORT = 7, /* Touch abort event. */
71 |
72 | VM_TOUCH_EVENT_MAX = 0x7FFFFFFF
73 | } VM_TOUCH_EVENT;
74 |
75 | /*****************************************************************************
76 | * FUNCTION
77 | * vm_touch_event_callback
78 | * DESCRIPTION
79 | * Callback of touch events.
80 | * PARAMETERS
81 | * event: [IN] touch event,see VM_TOUCH_EVENT
82 | * x: [IN] x coordinate, starting from upper-left of the display, in pixels.
83 | * y: [IN] y coordinate, starting from upper-left of the display, in pixels.
84 | * RETURNS
85 | * void
86 | *****************************************************************************/
87 | typedef void (*vm_touch_event_callback)(VM_TOUCH_EVENT event, VMINT x, VMINT y);
88 |
89 | /*****************************************************************************
90 | * FUNCTION
91 | * vm_touch_register_event_callback
92 | * DESCRIPTION
93 | * Registers touch event callback.
94 | * PARAMETERS
95 | * callback : [IN] touch event callback.
96 | * RETURNS
97 | * VM_RESULT
98 | *****************************************************************************/
99 | VM_RESULT vm_touch_register_event_callback(vm_touch_event_callback callback);
100 |
101 | #ifdef __cplusplus
102 | }
103 | #endif
104 |
105 | #endif /* VMTOUCH_SDK_H */
106 |
107 |
--------------------------------------------------------------------------------
/lua/lfunc.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $
3 | ** Auxiliary functions to manipulate prototypes and closures
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 |
8 | #include
9 |
10 | #define lfunc_c
11 | #define LUA_CORE
12 |
13 | #include "lua.h"
14 |
15 | #include "lfunc.h"
16 | #include "lgc.h"
17 | #include "lmem.h"
18 | #include "lobject.h"
19 | #include "lstate.h"
20 |
21 |
22 |
23 | Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) {
24 | Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems)));
25 | luaC_link(L, obj2gco(c), LUA_TFUNCTION);
26 | c->c.isC = 1;
27 | c->c.env = e;
28 | c->c.nupvalues = cast_byte(nelems);
29 | return c;
30 | }
31 |
32 |
33 | Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) {
34 | Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems)));
35 | luaC_link(L, obj2gco(c), LUA_TFUNCTION);
36 | c->l.isC = 0;
37 | c->l.env = e;
38 | c->l.nupvalues = cast_byte(nelems);
39 | while (nelems--) c->l.upvals[nelems] = NULL;
40 | return c;
41 | }
42 |
43 |
44 | UpVal *luaF_newupval (lua_State *L) {
45 | UpVal *uv = luaM_new(L, UpVal);
46 | luaC_link(L, obj2gco(uv), LUA_TUPVAL);
47 | uv->v = &uv->u.value;
48 | setnilvalue(uv->v);
49 | return uv;
50 | }
51 |
52 |
53 | UpVal *luaF_findupval (lua_State *L, StkId level) {
54 | global_State *g = G(L);
55 | GCObject **pp = &L->openupval;
56 | UpVal *p;
57 | UpVal *uv;
58 | while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) {
59 | lua_assert(p->v != &p->u.value);
60 | if (p->v == level) { /* found a corresponding upvalue? */
61 | if (isdead(g, obj2gco(p))) /* is it dead? */
62 | changewhite(obj2gco(p)); /* ressurect it */
63 | return p;
64 | }
65 | pp = &p->next;
66 | }
67 | uv = luaM_new(L, UpVal); /* not found: create a new one */
68 | uv->tt = LUA_TUPVAL;
69 | uv->v = level; /* current value lives in the stack */
70 | uv->next = *pp; /* chain it in the proper position */
71 | *pp = obj2gco(uv);
72 | uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */
73 | uv->u.l.next = g->uvhead.u.l.next;
74 | uv->u.l.next->u.l.prev = uv;
75 | g->uvhead.u.l.next = uv;
76 | luaC_marknew(L, obj2gco(uv));
77 | lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
78 | return uv;
79 | }
80 |
81 |
82 | static void unlinkupval (UpVal *uv) {
83 | lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
84 | uv->u.l.next->u.l.prev = uv->u.l.prev; /* remove from `uvhead' list */
85 | uv->u.l.prev->u.l.next = uv->u.l.next;
86 | }
87 |
88 |
89 | void luaF_freeupval (lua_State *L, UpVal *uv) {
90 | if (uv->v != &uv->u.value) /* is it open? */
91 | unlinkupval(uv); /* remove from open list */
92 | luaM_free(L, uv); /* free upvalue */
93 | }
94 |
95 |
96 | void luaF_close (lua_State *L, StkId level) {
97 | UpVal *uv;
98 | global_State *g = G(L);
99 | while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) {
100 | GCObject *o = obj2gco(uv);
101 | lua_assert(!isblack(o) && uv->v != &uv->u.value);
102 | L->openupval = uv->next; /* remove from `open' list */
103 | if (isdead(g, o))
104 | luaF_freeupval(L, uv); /* free upvalue */
105 | else {
106 | unlinkupval(uv);
107 | setobj(L, &uv->u.value, uv->v);
108 | uv->v = &uv->u.value; /* now current value lives here */
109 | luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */
110 | }
111 | }
112 | }
113 |
114 |
115 | Proto *luaF_newproto (lua_State *L) {
116 | Proto *f = luaM_new(L, Proto);
117 | luaC_link(L, obj2gco(f), LUA_TPROTO);
118 | f->k = NULL;
119 | f->sizek = 0;
120 | f->p = NULL;
121 | f->sizep = 0;
122 | f->code = NULL;
123 | f->sizecode = 0;
124 | f->sizelineinfo = 0;
125 | f->sizeupvalues = 0;
126 | f->nups = 0;
127 | f->upvalues = NULL;
128 | f->numparams = 0;
129 | f->is_vararg = 0;
130 | f->maxstacksize = 0;
131 | f->lineinfo = NULL;
132 | f->sizelocvars = 0;
133 | f->locvars = NULL;
134 | f->linedefined = 0;
135 | f->lastlinedefined = 0;
136 | f->source = NULL;
137 | return f;
138 | }
139 |
140 |
141 | void luaF_freeproto (lua_State *L, Proto *f) {
142 | luaM_freearray(L, f->p, f->sizep, Proto *);
143 | luaM_freearray(L, f->k, f->sizek, TValue);
144 | luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
145 | luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);
146 | if (!proto_is_readonly(f)) {
147 | luaM_freearray(L, f->code, f->sizecode, Instruction);
148 | luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);
149 | }
150 | luaM_free(L, f);
151 | }
152 |
153 |
154 | void luaF_freeclosure (lua_State *L, Closure *c) {
155 | int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) :
156 | sizeLclosure(c->l.nupvalues);
157 | luaM_freemem(L, c, size);
158 | }
159 |
160 |
161 | /*
162 | ** Look for n-th local variable at line `line' in function `func'.
163 | ** Returns NULL if not found.
164 | */
165 | const char *luaF_getlocalname (const Proto *f, int local_number, int pc) {
166 | int i;
167 | for (i = 0; isizelocvars && f->locvars[i].startpc <= pc; i++) {
168 | if (pc < f->locvars[i].endpc) { /* is variable active? */
169 | local_number--;
170 | if (local_number == 0)
171 | return getstr(f->locvars[i].varname);
172 | }
173 | }
174 | return NULL; /* not found */
175 | }
176 |
177 |
--------------------------------------------------------------------------------
/linkit/include/vmmemory.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * Copyright Statement:
3 | * --------------------
4 | * This software is protected by Copyright and the information contained
5 | * herein is confidential. The software may not be copied and the information
6 | * contained herein may not be used or disclosed except with the written
7 | * permission of MediaTek Inc. (C) 2005-2015
8 | *
9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21 | *
22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27 | *
28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33 | *
34 | *****************************************************************************/
35 |
36 | #ifndef VMMEMORY_SDK_H
37 | #define VMMEMORY_SDK_H
38 |
39 | #ifdef __cplusplus
40 | extern "C" {
41 | #endif
42 |
43 | #include "vmtype.h"
44 |
45 | /*****************************************************************************
46 | * FUNCTION
47 | * vm_malloc
48 | * DESCRIPTION
49 | * Allocates the specified size of memory. Uses vm_pmng_get_memory_status()
50 | * to query the available max size of memory that can be allocated. User should
51 | * configure the memory pool size of the VXP. The max size of available memory
52 | * may not be allocated due to memory fragmentation.
53 | * PARAMETERS
54 | * size : [IN] The number of bytes to be allocated.
55 | * RETURNS
56 | * A pointer to the memory allocated. NULL if allocation failed.
57 | *****************************************************************************/
58 | void* vm_malloc(VMUINT size);
59 |
60 | /*****************************************************************************
61 | * FUNCTION
62 | * vm_calloc
63 | * DESCRIPTION
64 | * Allocates the specified size of memory and clear the memory with zeros.
65 | * PARAMETERS
66 | * size : [IN] The number of bytes to be allocated.
67 | * RETURNS
68 | * A pointer to the memory allocated. NULL if allocation failed.
69 | *****************************************************************************/
70 | void* vm_calloc(VMUINT size);
71 |
72 | /*****************************************************************************
73 | * FUNCTION
74 | * vm_realloc
75 | * DESCRIPTION
76 | * Reallocates the specified size of memory for the memory already allocated before.
77 | * The content of the memory will be "copied".
78 | * PARAMETERS
79 | * ptr : [IN] The pointer to the memory to be copied. If allocation succeeds,
80 | * the memory pointed to by the ptr will be freed.
81 | * size : [IN] The number of bytes to be allocated.
82 | * RETURNS
83 | * A pointer to the memory allocated. Returns NULL if allocation failed, and
84 | * the memory pointed to by the ptr will not be freed.
85 | *****************************************************************************/
86 | void* vm_realloc(void* ptr, VMUINT size);
87 |
88 | /*****************************************************************************
89 | * FUNCTION
90 | * vm_free
91 | * DESCRIPTION
92 | * Frees the memory allocated by vm_malloc(), vm_calloc(), vm_realloc(),
93 | * or vm_malloc_dma(). Frees null is allowed.
94 | * PARAMETERS
95 | * ptr : [IN] The pointer to the memory to be freed. It can be NULL.
96 | * RETURNS
97 | * void
98 | *****************************************************************************/
99 | void vm_free(void* ptr);
100 |
101 | /*****************************************************************************
102 | * FUNCTION
103 | * vm_malloc_dma
104 | * DESCRIPTION
105 | * Allocates non-cacheable (e.g. DMA - Direct Memory Access), which provide
106 | * faster memory access. This function is mostly used by graphic related features.
107 | * PARAMETERS
108 | * size : [IN] The number of bytes to be allocated.
109 | * RETURNS
110 | * A pointer to the memory allocated. Returns NULL if allocation failed.
111 | *****************************************************************************/
112 | void* vm_malloc_dma(VMUINT size);
113 |
114 |
115 | #ifdef __cplusplus
116 | }
117 | #endif
118 |
119 | #endif /* VMSYS_SDK_H_ */
120 |
--------------------------------------------------------------------------------
/linkit/include/vmaudio_record.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * Copyright Statement:
3 | * --------------------
4 | * This software is protected by Copyright and the information contained
5 | * herein is confidential. The software may not be copied and the information
6 | * contained herein may not be used or disclosed except with the written
7 | * permission of MediaTek Inc. (C) 2005-2015
8 | *
9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21 | *
22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27 | *
28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33 | *
34 | *****************************************************************************/
35 |
36 |
37 |
38 |
39 | #ifndef VMAUDIO_RECORD_SDK_H
40 | #define VMAUDIO_RECORD_SDK_H
41 |
42 |
43 |
44 | #ifdef __cplusplus
45 | extern "C" {
46 | #endif
47 |
48 | #include "vmaudio.h"
49 |
50 | /* record operation result */
51 | typedef enum
52 | {
53 | VM_AUDIO_RECORD_SUCCESS = 0,
54 | VM_AUDIO_RECORD_TERMINATED = 1, /* Record was terminated, like stop record */
55 | VM_AUDIO_RECORD_INTERRUPT = 7, /* Interrupted by other application like voice call */
56 | VM_AUDIO_RECORD_INTERRUPT_RESUME = 8, /* Resume from interrupt */
57 | VM_AUDIO_RECORD_ERROR = -1, /* General recording error */
58 | VM_AUDIO_RECORD_ERROR_NO_SPACE = -2, /* No space to record. If it is recording to a T card and the card is disconnected while recording, the application will receive this message*/
59 | VM_AUDIO_RECORD_RESULT_MAX = 0x7FFFFFFF /* Ensure the compiler treat this enum as 32-bit integer. */
60 | } VM_AUDIO_RECORD_RESULT;
61 |
62 | /****************************************************************************** VM_AUDIO_RECORD_RESULT
63 | * FUNCTION
64 | * vm_audio_record_result_callback
65 | * DESCRIPTION
66 | * Record callback function.
67 | * PARAMETERS
68 | * result: [IN] Operation result.
69 | * user_data: [IN] User data.
70 | *****************************************************************************/
71 | typedef void(*vm_audio_record_result_callback)(VM_AUDIO_RECORD_RESULT result, void* user_data);
72 |
73 | /*****************************************************************************
74 | * FUNCTION
75 | * vm_audio_record_start
76 | * DESCRIPTION
77 | * Starts recording.
78 | * PARAMETERS
79 | * filename : [IN] Recording file name.
80 | * format : [IN] Recording file format, VM_FORMAT_AMR and VM_FORMAT_WAV.
81 | * callback : [IN] Callback function. The application should handle VM_AUDIO_RECORD_RESULT/VM_AUDIO_RECORD_ERROR_NO_SPACE within this callback.
82 | * user_data : [IN] User data.
83 | * RETURNS
84 | * VM_RESULT refer to VM_AUDIO_RECORD_RESULT
85 |
86 | *****************************************************************************/
87 | VM_RESULT vm_audio_record_start(VMCWSTR filename, VM_AUDIO_FORMAT format, vm_audio_record_result_callback callback, void* user_data);
88 |
89 |
90 | /*****************************************************************************
91 | * FUNCTION
92 | * vm_audio_record_pause
93 | * DESCRIPTION
94 | * Pause recording.
95 | * RETURNS
96 | * VM_RESULT refer to VM_AUDIO_RECORD_RESULT
97 | *****************************************************************************/
98 | VM_RESULT vm_audio_record_pause(void);
99 |
100 |
101 | /*****************************************************************************
102 | * FUNCTION
103 | * vm_audio_record_resume
104 | * DESCRIPTION
105 | * Resume recording.
106 | * RETURNS
107 | * VM_RESULT refer to VM_AUDIO_RECORD_RESULT
108 | *****************************************************************************/
109 | VM_RESULT vm_audio_record_resume(void);
110 |
111 |
112 | /*****************************************************************************
113 | * FUNCTION
114 | * vm_audio_record_stop
115 | * DESCRIPTION
116 | * Stops recording.
117 | * RETURNS
118 | * VM_RESULT refer to VM_AUDIO_RECORD_RESULT
119 | *****************************************************************************/
120 | VM_RESULT vm_audio_record_stop(void);
121 |
122 |
123 | #ifdef __cplusplus
124 | }
125 | #endif
126 |
127 | #endif /* VMAUDIO_RECORD_SDK_H */
128 |
--------------------------------------------------------------------------------
/lua/print.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $
3 | ** print bytecodes
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #include
8 | #include
9 |
10 | #define luac_c
11 | #define LUA_CORE
12 |
13 | #include "ldebug.h"
14 | #include "lobject.h"
15 | #include "lopcodes.h"
16 | #include "lundump.h"
17 |
18 | #define PrintFunction luaU_print
19 |
20 | #define Sizeof(x) ((int)sizeof(x))
21 | #define VOID(p) ((const void*)(p))
22 |
23 | static void PrintString(const TString* ts)
24 | {
25 | const char* s=getstr(ts);
26 | size_t i,n=ts->tsv.len;
27 | putchar('"');
28 | for (i=0; ik[i];
54 | switch (ttype(o))
55 | {
56 | case LUA_TNIL:
57 | printf("nil");
58 | break;
59 | case LUA_TBOOLEAN:
60 | printf(bvalue(o) ? "true" : "false");
61 | break;
62 | case LUA_TNUMBER:
63 | printf(LUA_NUMBER_FMT,nvalue(o));
64 | break;
65 | case LUA_TSTRING:
66 | PrintString(rawtsvalue(o));
67 | break;
68 | default: /* cannot happen */
69 | printf("? type=%d",ttype(o));
70 | break;
71 | }
72 | }
73 |
74 | static void PrintCode(const Proto* f)
75 | {
76 | const Instruction* code=f->code;
77 | int pc,n=f->sizecode;
78 | for (pc=0; pc0) printf("[%d]\t",line); else printf("[-]\t");
90 | printf("%-9s\t",luaP_opnames[o]);
91 | switch (getOpMode(o))
92 | {
93 | case iABC:
94 | printf("%d",a);
95 | if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b);
96 | if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c);
97 | break;
98 | case iABx:
99 | if (getBMode(o)==OpArgK) printf("%d %d",a,-1-bx); else printf("%d %d",a,bx);
100 | break;
101 | case iAsBx:
102 | if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx);
103 | break;
104 | }
105 | switch (o)
106 | {
107 | case OP_LOADK:
108 | printf("\t; "); PrintConstant(f,bx);
109 | break;
110 | case OP_GETUPVAL:
111 | case OP_SETUPVAL:
112 | printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : "-");
113 | break;
114 | case OP_GETGLOBAL:
115 | case OP_SETGLOBAL:
116 | printf("\t; %s",svalue(&f->k[bx]));
117 | break;
118 | case OP_GETTABLE:
119 | case OP_SELF:
120 | if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
121 | break;
122 | case OP_SETTABLE:
123 | case OP_ADD:
124 | case OP_SUB:
125 | case OP_MUL:
126 | case OP_DIV:
127 | case OP_POW:
128 | case OP_EQ:
129 | case OP_LT:
130 | case OP_LE:
131 | if (ISK(b) || ISK(c))
132 | {
133 | printf("\t; ");
134 | if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-");
135 | printf(" ");
136 | if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
137 | }
138 | break;
139 | case OP_JMP:
140 | case OP_FORLOOP:
141 | case OP_FORPREP:
142 | printf("\t; to %d",sbx+pc+2);
143 | break;
144 | case OP_CLOSURE:
145 | printf("\t; %p",VOID(f->p[bx]));
146 | break;
147 | case OP_SETLIST:
148 | if (c==0) printf("\t; %d",(int)code[++pc]);
149 | else printf("\t; %d",c);
150 | break;
151 | default:
152 | break;
153 | }
154 | printf("\n");
155 | }
156 | }
157 |
158 | #define SS(x) (x==1)?"":"s"
159 | #define S(x) x,SS(x)
160 |
161 | static void PrintHeader(const Proto* f)
162 | {
163 | const char* s=getstr(f->source);
164 | if (*s=='@' || *s=='=')
165 | s++;
166 | else if (*s==LUA_SIGNATURE[0])
167 | s="(bstring)";
168 | else
169 | s="(string)";
170 | printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n",
171 | (f->linedefined==0)?"main":"function",s,
172 | f->linedefined,f->lastlinedefined,
173 | S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f));
174 | printf("%d%s param%s, %d slot%s, %d upvalue%s, ",
175 | f->numparams,f->is_vararg?"+":"",SS(f->numparams),
176 | S(f->maxstacksize),S(f->nups));
177 | printf("%d local%s, %d constant%s, %d function%s\n",
178 | S(f->sizelocvars),S(f->sizek),S(f->sizep));
179 | }
180 |
181 | static void PrintConstants(const Proto* f)
182 | {
183 | int i,n=f->sizek;
184 | printf("constants (%d) for %p:\n",n,VOID(f));
185 | for (i=0; isizelocvars;
196 | printf("locals (%d) for %p:\n",n,VOID(f));
197 | for (i=0; ilocvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);
201 | }
202 | }
203 |
204 | static void PrintUpvalues(const Proto* f)
205 | {
206 | int i,n=f->sizeupvalues;
207 | printf("upvalues (%d) for %p:\n",n,VOID(f));
208 | if (f->upvalues==NULL) return;
209 | for (i=0; iupvalues[i]));
212 | }
213 | }
214 |
215 | void PrintFunction(const Proto* f, int full)
216 | {
217 | int i,n=f->sizep;
218 | PrintHeader(f);
219 | PrintCode(f);
220 | if (full)
221 | {
222 | PrintConstants(f);
223 | PrintLocals(f);
224 | PrintUpvalues(f);
225 | }
226 | for (i=0; ip[i],full);
227 | }
228 |
--------------------------------------------------------------------------------
/lua/lstate.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $
3 | ** Global State
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lstate_h
8 | #define lstate_h
9 |
10 | #include "lua.h"
11 |
12 | #include "lobject.h"
13 | #include "ltm.h"
14 | #include "lzio.h"
15 |
16 |
17 |
18 | struct lua_longjmp; /* defined in ldo.c */
19 |
20 |
21 | /* table of globals */
22 | #define gt(L) (&L->l_gt)
23 |
24 | /* registry */
25 | #define registry(L) (&G(L)->l_registry)
26 |
27 |
28 | /* extra stack space to handle TM calls and some other extras */
29 | #define EXTRA_STACK 5
30 |
31 |
32 | #define BASIC_CI_SIZE 8
33 |
34 | #define BASIC_STACK_SIZE (2*LUA_MINSTACK)
35 |
36 |
37 |
38 | typedef struct stringtable {
39 | GCObject **hash;
40 | lu_int32 nuse; /* number of elements */
41 | int size;
42 | } stringtable;
43 |
44 |
45 | /*
46 | ** informations about a call
47 | */
48 | typedef struct CallInfo {
49 | StkId base; /* base for this function */
50 | StkId func; /* function index in the stack */
51 | StkId top; /* top for this function */
52 | const Instruction *savedpc;
53 | int nresults; /* expected number of results from this function */
54 | int tailcalls; /* number of tail calls lost under this entry */
55 | } CallInfo;
56 |
57 |
58 |
59 | #define curr_func(L) (ttisfunction(L->ci->func) ? clvalue(L->ci->func) : NULL)
60 | #define ci_func(ci) (ttisfunction((ci)->func) ? clvalue((ci)->func) : NULL)
61 | #define f_isLua(ci) (!ttislightfunction((ci)->func) && !ci_func(ci)->c.isC)
62 | #define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci))
63 |
64 |
65 | /*
66 | ** `global state', shared by all threads of this state
67 | */
68 | typedef struct global_State {
69 | stringtable strt; /* hash table for strings */
70 | lua_Alloc frealloc; /* function to reallocate memory */
71 | void *ud; /* auxiliary data to `frealloc' */
72 | lu_byte currentwhite;
73 | lu_byte gcstate; /* state of garbage collector */
74 | lu_byte gcflags; /* flags for the garbage collector */
75 | int sweepstrgc; /* position of sweep in `strt' */
76 | GCObject *rootgc; /* list of all collectable objects */
77 | GCObject **sweepgc; /* position of sweep in `rootgc' */
78 | GCObject *gray; /* list of gray objects */
79 | GCObject *grayagain; /* list of objects to be traversed atomically */
80 | GCObject *weak; /* list of weak tables (to be cleared) */
81 | GCObject *tmudata; /* last element of list of userdata to be GC */
82 | Mbuffer buff; /* temporary buffer for string concatentation */
83 | lu_mem GCthreshold;
84 | lu_mem totalbytes; /* number of bytes currently allocated */
85 | lu_mem memlimit; /* maximum number of bytes that can be allocated, 0 = no limit. */
86 | lu_mem estimate; /* an estimate of number of bytes actually in use */
87 | lu_mem gcdept; /* how much GC is `behind schedule' */
88 | int gcpause; /* size of pause between successive GCs */
89 | int gcstepmul; /* GC `granularity' */
90 | int egcmode; /* emergency garbage collection operation mode */
91 | lua_CFunction panic; /* to be called in unprotected errors */
92 | TValue l_registry;
93 | struct lua_State *mainthread;
94 | UpVal uvhead; /* head of double-linked list of all open upvalues */
95 | struct Table *mt[NUM_TAGS]; /* metatables for basic types */
96 | TString *tmname[TM_N]; /* array with tag-method names */
97 | } global_State;
98 |
99 |
100 | /*
101 | ** `per thread' state
102 | */
103 | struct lua_State {
104 | CommonHeader;
105 | lu_byte status;
106 | StkId top; /* first free slot in the stack */
107 | StkId base; /* base of current function */
108 | global_State *l_G;
109 | CallInfo *ci; /* call info for current function */
110 | const Instruction *savedpc; /* `savedpc' of current function */
111 | StkId stack_last; /* last free slot in the stack */
112 | StkId stack; /* stack base */
113 | CallInfo *end_ci; /* points after end of ci array*/
114 | CallInfo *base_ci; /* array of CallInfo's */
115 | int stacksize;
116 | int size_ci; /* size of array `base_ci' */
117 | unsigned short nCcalls; /* number of nested C calls */
118 | unsigned short baseCcalls; /* nested C calls when resuming coroutine */
119 | lu_byte hookmask;
120 | lu_byte allowhook;
121 | int basehookcount;
122 | int hookcount;
123 | lua_Hook hook;
124 | TValue l_gt; /* table of globals */
125 | TValue env; /* temporary place for environments */
126 | GCObject *openupval; /* list of open upvalues in this stack */
127 | GCObject *gclist;
128 | struct lua_longjmp *errorJmp; /* current error recover point */
129 | ptrdiff_t errfunc; /* current error handling function (stack index) */
130 | };
131 |
132 |
133 | #define G(L) (L->l_G)
134 |
135 |
136 | /*
137 | ** Union of all collectable objects
138 | */
139 | union GCObject {
140 | GCheader gch;
141 | union TString ts;
142 | union Udata u;
143 | union Closure cl;
144 | struct Table h;
145 | struct Proto p;
146 | struct UpVal uv;
147 | struct lua_State th; /* thread */
148 | };
149 |
150 |
151 | /* macros to convert a GCObject into a specific value */
152 | #define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
153 | #define gco2ts(o) (&rawgco2ts(o)->tsv)
154 | #define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
155 | #define gco2u(o) (&rawgco2u(o)->uv)
156 | #define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
157 | #define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
158 | #define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
159 | #define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
160 | #define ngcotouv(o) \
161 | check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
162 | #define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
163 |
164 | /* macro to convert any Lua object into a GCObject */
165 | #define obj2gco(v) (cast(GCObject *, (v)))
166 |
167 | LUAI_FUNC lua_State *luaE_newthread (lua_State *L);
168 | LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
169 |
170 | #endif
171 |
172 |
--------------------------------------------------------------------------------
/linkit/include/vmtype.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * Copyright Statement:
3 | * --------------------
4 | * This software is protected by Copyright and the information contained
5 | * herein is confidential. The software may not be copied and the information
6 | * contained herein may not be used or disclosed except with the written
7 | * permission of MediaTek Inc. (C) 2005-2015
8 | *
9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21 | *
22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27 | *
28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33 | *
34 | *****************************************************************************/
35 |
36 | #ifndef VMTYPE_SDK_H
37 | #define VMTYPE_SDK_H
38 |
39 | #ifdef __cplusplus
40 | extern "C" {
41 | #endif
42 |
43 | #ifndef TRUE
44 | #define TRUE (1) /* 1 */
45 | #endif
46 |
47 | #ifndef FALSE
48 | #define FALSE (0) /* 0 */
49 | #endif
50 |
51 | #ifndef NULL
52 | #define NULL (0) /* 0 */
53 | #endif
54 |
55 |
56 | typedef unsigned char VMUINT8; /* unsigned char, 8-bit, range: 0 - 2^8-1 */
57 | typedef unsigned short VMUINT16; /* unsigned short, 16-bit, range: 0 - 2^16-1 */
58 | typedef unsigned int VMUINT; /* unsigned int, 32-bit, range: 0 - 2^32-1 */
59 | typedef unsigned long VMUINT32; /* unsigned long, 32-bit, range: 0 - 2^32-1 */
60 |
61 |
62 | typedef unsigned long long VMUINT64; /* unsigned long long, 64-bit, range: 0 - 2^64-1 */
63 | typedef long long VMINT64; /* long long, 64-bit, range: -2^63 - 2^63-1 */
64 |
65 |
66 | typedef signed char VMINT8; /* char, 8-bit, range: -2^7 - 2^7-1 */
67 | typedef short VMINT16; /* short, 16-bit, range: -2^15 - 2^15-1 */
68 | typedef int VMINT; /* int, 32-bit, range: -2^31 - 2^31-1 */
69 | typedef long VMINT32; /* long, 32-bit, range: -2^31 - 2^31-1 */
70 |
71 | typedef unsigned char VMUCHAR; /* unsigned char, 8-bit, range: 0 - 2^8-1 */
72 | typedef unsigned short VMUWCHAR; /* unsigned short, 16-bit, range: 0 - 2^16-1 */
73 |
74 | typedef signed char VMCHAR; /* char, 8-bit, range: -2^7 - 2^7-1 */
75 | typedef short VMWCHAR; /* short, 16-bit, range: -2^15 - 2^15-1 */
76 | typedef signed char* VMSTR; /* signed char*, a NULL-terminated single-byte string. */
77 | typedef short* VMWSTR; /* short*, a NULL-terminated two-byte string. */
78 |
79 | typedef const VMWCHAR* VMCWSTR; /* const short *, a const NULL-terminated two-bye string */
80 | typedef const VMCHAR* VMCSTR; /* const signed char *, a const NULL-terminated single-byte string. */
81 |
82 | typedef unsigned char VMBYTE; /* unsigned char, 8-bit, range: 0 - 2^8-1 */
83 | typedef unsigned short VMUSHORT; /* unsigned short, 16-bit, range: 0 - 2^16-1 */
84 | typedef short VMSHORT; /* short, 16-bit, range: -2^15 - 2^15-1 */
85 |
86 |
87 | typedef int VMBOOL; /* int, 32-bit, range: -2^31 - 2^31-1 */
88 |
89 |
90 | typedef float VMFLOAT; /* float, 32-bit, single precision. */
91 | typedef double VMDOUBLE; /* double, 64-bit, double precision. */
92 |
93 |
94 | #define VM_TRUE TRUE /* Boolean value true. */
95 | #define VM_FALSE FALSE /* Boolean value false. */
96 | #define VM_RESULT VMINT /* General result type for LinkIt SDK API. Must be used with VM_IS_SUCCEEDED() and VM_IS_FAILED() to confirm sucess or not. Do not compare with VM_SUCESS and VM_FAIL directly. */
97 | #define VM_SUCCESS (1) /* Do not compare it with VM_RESULT directly, i.e. DO NOT USE if(VM_SUCCESS==xxxx()) to determine a success or not. Instead, use if(VM_IS_SUCCEEDED(xxx()). */
98 | #define VM_OK (0) /* Do not compare it with VM_RESULT directly. */
99 | #define VM_FAIL (-1) /* Do not compare it with VM_RESULT directly, i.e. DO NOT USE if(VM_FAIL==xxxx()) to determine a failure or not. Instead, use if(VM_IS_FAILED(xxx()). */
100 |
101 |
102 | #define VM_IS_SUCCEEDED(x) (((x)>=0)?VM_TRUE:VM_FALSE) /* Use this macro to determine if a VM_RESULT is a success or not. */
103 | #define VM_IS_FAILED(x) (((x)<0)?VM_TRUE:VM_FALSE) /* Use this macro to determine if a VM_RESULT is a failure or not. */
104 |
105 |
106 | #define VM_SYMBOL_NOT_FOUND (-103) /* The error code (-103) means a symbol cannot be found in the firmware. */
107 |
108 |
109 | #ifdef __cplusplus
110 | }
111 | #endif
112 |
113 | #endif /* VMTYPE_SDK_H */
114 |
--------------------------------------------------------------------------------
/src/shell.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #define lua_c
9 |
10 | #include "lua.h"
11 |
12 | #include "lauxlib.h"
13 | #include "lualib.h"
14 |
15 | #include "shell.h"
16 |
17 | VM_THREAD_HANDLE g_main_handle;
18 | vm_thread_message_t g_shell_message = {SHELL_MESSAGE_ID, 0};
19 | VM_SIGNAL_ID g_shell_signal;
20 | int g_shell_result;
21 |
22 | static lua_State *globalL = NULL;
23 |
24 | static const char *progname = LUA_PROGNAME;
25 |
26 | static int remote_docall(void);
27 |
28 | static void lstop (lua_State *L, lua_Debug *ar) {
29 | (void)ar; /* unused arg. */
30 | lua_sethook(L, NULL, 0, 0);
31 | luaL_error(L, "interrupted!");
32 | }
33 |
34 |
35 | static void laction (int i) {
36 | signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
37 | terminate process (default action) */
38 | lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
39 | }
40 |
41 |
42 | static void l_message (const char *pname, const char *msg) {
43 | if (pname) fprintf(stderr, "%s: ", pname);
44 | fprintf(stderr, "%s\n", msg);
45 | fflush(stderr);
46 | }
47 |
48 |
49 | static int report (lua_State *L, int status) {
50 | if (status && !lua_isnil(L, -1)) {
51 | const char *msg = lua_tostring(L, -1);
52 | if (msg == NULL) msg = "(error object is not a string)";
53 | l_message(progname, msg);
54 | lua_pop(L, 1);
55 | }
56 | return status;
57 | }
58 |
59 |
60 | static int traceback (lua_State *L) {
61 | if (!lua_isstring(L, 1)) /* 'message' not a string? */
62 | return 1; /* keep it intact */
63 | lua_getfield(L, LUA_GLOBALSINDEX, "debug");
64 | if (!lua_istable(L, -1) && !lua_isrotable(L, -1)) {
65 | lua_pop(L, 1);
66 | return 1;
67 | }
68 | lua_getfield(L, -1, "traceback");
69 | if (!lua_isfunction(L, -1) && !lua_islightfunction(L, -1)) {
70 | lua_pop(L, 2);
71 | return 1;
72 | }
73 | lua_pushvalue(L, 1); /* pass error message */
74 | lua_pushinteger(L, 2); /* skip this function and traceback */
75 | lua_call(L, 2, 1); /* call debug.traceback */
76 | return 1;
77 | }
78 |
79 |
80 | static int docall (lua_State *L, int narg, int clear) {
81 | int status;
82 | int base = lua_gettop(L) - narg; /* function index */
83 | lua_pushcfunction(L, traceback); /* push traceback function */
84 | lua_insert(L, base); /* put it under chunk and args */
85 | signal(SIGINT, laction);
86 | status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
87 | signal(SIGINT, SIG_DFL);
88 | lua_remove(L, base); /* remove traceback function */
89 | /* force a complete garbage collection in case of errors */
90 | if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);
91 | return status;
92 | }
93 |
94 |
95 | static const char *get_prompt (lua_State *L, int firstline) {
96 | const char *p;
97 | lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2");
98 | p = lua_tostring(L, -1);
99 | if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);
100 | lua_pop(L, 1); /* remove global */
101 | return p;
102 | }
103 |
104 |
105 | static int incomplete (lua_State *L, int status) {
106 | if (status == LUA_ERRSYNTAX) {
107 | size_t lmsg;
108 | const char *msg = lua_tolstring(L, -1, &lmsg);
109 | const char *tp = msg + lmsg - (sizeof(LUA_QL("")) - 1);
110 | if (strstr(msg, LUA_QL("")) == tp) {
111 | lua_pop(L, 1);
112 | return 1;
113 | }
114 | }
115 | return 0; /* else... */
116 | }
117 |
118 |
119 | static int pushline (lua_State *L, int firstline) {
120 | char buffer[LUA_MAXINPUT];
121 | char *b = buffer;
122 | size_t l;
123 | const char *prmt = get_prompt(L, firstline);
124 | if (lua_readline(L, b, prmt) == 0)
125 | return 0; /* no input */
126 | l = strlen(b);
127 | if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
128 | b[l-1] = '\0'; /* remove it */
129 | if (firstline && b[0] == '=') /* first line starts with `=' ? */
130 | lua_pushfstring(L, "return %s", b+1); /* change it to `return' */
131 | else
132 | lua_pushstring(L, b);
133 | lua_freeline(L, b);
134 | return 1;
135 | }
136 |
137 |
138 | static int loadline (lua_State *L) {
139 | int status;
140 | lua_settop(L, 0);
141 | if (!pushline(L, 1))
142 | return -1; /* no input */
143 | for (;;) { /* repeat until gets a complete line */
144 | status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
145 | if (!incomplete(L, status)) break; /* cannot try to add lines? */
146 | if (!pushline(L, 0)) /* no more input? */
147 | return -1;
148 | lua_pushliteral(L, "\n"); /* add a new line... */
149 | lua_insert(L, -2); /* ...between the two lines */
150 | lua_concat(L, 3); /* join them */
151 | }
152 | lua_saveline(L, 1);
153 | lua_remove(L, 1); /* remove line */
154 | return status;
155 | }
156 |
157 | static void dotty (lua_State *L) {
158 | int status;
159 | const char *oldprogname = progname;
160 | progname = NULL;
161 | while ((status = loadline(L)) != -1) {
162 | if (status == 0) status = remote_docall(); //docall(L, 0, 0);
163 | report(L, status);
164 | if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
165 | lua_getglobal(L, "print");
166 | lua_insert(L, 1);
167 | if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
168 | l_message(progname, lua_pushfstring(L,
169 | "error calling " LUA_QL("print") " (%s)",
170 | lua_tostring(L, -1)));
171 | }
172 | }
173 | lua_settop(L, 0); /* clear stack */
174 | fputs("\n", stdout);
175 | fflush(stdout);
176 | progname = oldprogname;
177 | }
178 |
179 | static int remote_docall(void)
180 | {
181 | vm_thread_send_message(g_main_handle, &g_shell_message);
182 | vm_signal_wait(g_shell_signal);
183 | return g_shell_result;
184 | }
185 |
186 | void shell_docall(lua_State *L)
187 | {
188 | g_shell_result = docall(L, 0, 0);
189 | vm_signal_post(g_shell_signal);
190 | }
191 |
192 | VMINT32 shell_thread(VM_THREAD_HANDLE thread_handle, void* user_data)
193 | {
194 | lua_State *L = (lua_State *)user_data;
195 |
196 | g_main_handle = vm_thread_get_main_handle();
197 | g_shell_message.message_id = SHELL_MESSAGE_ID;
198 | g_shell_signal = vm_signal_create();
199 |
200 | dotty(L);
201 | }
202 |
--------------------------------------------------------------------------------
/linkit/include/vmgsm_cell.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * Copyright Statement:
3 | * --------------------
4 | * This software is protected by Copyright and the information contained
5 | * herein is confidential. The software may not be copied and the information
6 | * contained herein may not be used or disclosed except with the written
7 | * permission of MediaTek Inc. (C) 2005-2015
8 | *
9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21 | *
22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27 | *
28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33 | *
34 | *****************************************************************************/
35 |
36 | #ifndef VMGSM_CELL_SDK_H
37 | #define VMGSM_CELL_SDK_H
38 |
39 | #include "vmtype.h"
40 |
41 | #ifdef __cplusplus
42 | extern "C" {
43 | #endif
44 |
45 | /* Cell info struct. */
46 | typedef struct
47 | {
48 | VMUINT16 arfcn; /* ARFCN. */
49 | VMUINT8 bsic; /* BSIC. */
50 | VMUINT8 rxlev; /* Received signal level. */
51 | VMUINT16 mcc; /* MCC. */
52 | VMUINT16 mnc; /* MNC. */
53 | VMUINT16 lac; /* LAC. */
54 | VMUINT16 ci; /* CI. */
55 | } vm_gsm_cell_info_t;
56 |
57 | /* Cell open result */
58 | typedef enum
59 | {
60 | VM_GSM_CELL_OPEN_SUCCESS = 0, /* Opens successfully. */
61 | VM_GSM_CELL_OPEN_ALREADY_OPEN = 1, /* Already opened. */
62 | VM_GSM_CELL_OPEN_ERROR_NO_RESOURCE = -1, /* Lack of resource. */
63 | VM_GSM_CELL_OPEN_ERROR_REGISTER = -2, /* Registration error. */
64 | VM_GSM_CELL_RESULT_MAX = 0x7FFFFFFF /* Forces the compiler to use 4-byte integer for enum. */
65 | } VM_GSM_CELL_RESULT;
66 |
67 | /*****************************************************************************
68 | * FUNCTION
69 | * vm_gsm_cell_open
70 | * DESCRIPTION
71 | * Opens CELL ID resource.
72 | * PARAMETERS
73 | * void
74 | * RETURNS
75 | * VM_RESULT. It returns 0 if the open operation is successful.
76 | * Refer to VM_GSM_CELL_RESULT for error code.
77 | *****************************************************************************/
78 | VM_RESULT vm_gsm_cell_open(void);
79 |
80 | /*****************************************************************************
81 | * FUNCTION
82 | * vm_gsm_cell_close
83 | * DESCRIPTION
84 | * Closes CELL ID resource.
85 | * PARAMETERS
86 | * void
87 | * RETURNS
88 | * void
89 | *****************************************************************************/
90 | void vm_gsm_cell_close(void);
91 |
92 | /*****************************************************************************
93 | * FUNCTION
94 | * vm_gsm_cell_get_current_cell_info
95 | * DESCRIPTION
96 | * Gets current cell information. The vm_gsm_cell_open() should be called
97 | * before calling this function. Otherwise, NULL will be returned to cell_info.
98 | * PARAMETERS
99 | * cell_info: [OUT] Contains the current cell information after this function returns.
100 | * RETURNS
101 | * VM_RESULT. Refer to VM_GSM_CELL_RESULT for error code.
102 | *****************************************************************************/
103 | VM_RESULT vm_gsm_cell_get_current_cell_info(vm_gsm_cell_info_t* cell_info);
104 |
105 |
106 | /*****************************************************************************
107 | * FUNCTION
108 | * vm_gsm_cell_get_neighbor_cell_info
109 | * DESCRIPTION
110 | * Gets neighbor cell information. The vm_gsm_cell_open() should be called
111 | * before calling this function. Otherwise, NULL will be returned to cell_info.
112 | * PARAMETERS
113 | * cell_info: [OUT] Contains the neighbor cell information after this function returns.
114 | * cell_index: [IN] The index number of the neighbor cells. The total number
115 | * of neighbor cells is obtained by calling vm_gsm_cell_get_neighbor_number().
116 | * If there are 3 neighbor cells, the range of index will be
117 | * 0, 1 and 2.
118 | * RETURNS
119 | * VM_RESULT. Refer to VM_GSM_CELL_RESULT for error code.
120 | *****************************************************************************/
121 | VM_RESULT vm_gsm_cell_get_neighbor_cell_info(vm_gsm_cell_info_t* cell_info, VMINT cell_index);
122 |
123 | /*****************************************************************************
124 | * FUNCTION
125 | * vm_gsm_cell_get_neighbor_number
126 | * DESCRIPTION
127 | * Gets the total number of neighbor cells. The vm_gsm_cell_open() should be called
128 | * before calling this function.
129 | * PARAMETERS
130 | * void
131 | * RETURNS
132 | * The total number of neighbor cells.
133 | *****************************************************************************/
134 | VMINT vm_gsm_cell_get_neighbor_number(void);
135 |
136 | #ifdef __cplusplus
137 | }
138 | #endif
139 | #endif /* VMGSM_CELL_SDK_H */
140 |
141 |
--------------------------------------------------------------------------------
/lua/lobject.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Some generic functions over Lua objects
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #define lobject_c
14 | #define LUA_CORE
15 |
16 | #include "lua.h"
17 |
18 | #include "ldo.h"
19 | #include "lmem.h"
20 | #include "lobject.h"
21 | #include "lstate.h"
22 | #include "lstring.h"
23 | #include "lvm.h"
24 |
25 |
26 |
27 | const TValue luaO_nilobject_ = {LUA_TVALUE_NIL};
28 |
29 |
30 | /*
31 | ** converts an integer to a "floating point byte", represented as
32 | ** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if
33 | ** eeeee != 0 and (xxx) otherwise.
34 | */
35 | int luaO_int2fb (unsigned int x) {
36 | int e = 0; /* expoent */
37 | while (x >= 16) {
38 | x = (x+1) >> 1;
39 | e++;
40 | }
41 | if (x < 8) return x;
42 | else return ((e+1) << 3) | (cast_int(x) - 8);
43 | }
44 |
45 |
46 | /* converts back */
47 | int luaO_fb2int (int x) {
48 | int e = (x >> 3) & 31;
49 | if (e == 0) return x;
50 | else return ((x & 7)+8) << (e - 1);
51 | }
52 |
53 |
54 | int luaO_log2 (unsigned int x) {
55 | static const lu_byte log_2[256] = {
56 | 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
57 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
58 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
59 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
60 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
61 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
62 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
63 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
64 | };
65 | int l = -1;
66 | while (x >= 256) { l += 8; x >>= 8; }
67 | return l + log_2[x];
68 |
69 | }
70 |
71 |
72 | int luaO_rawequalObj (const TValue *t1, const TValue *t2) {
73 | if (ttype(t1) != ttype(t2)) return 0;
74 | else switch (ttype(t1)) {
75 | case LUA_TNIL:
76 | return 1;
77 | case LUA_TNUMBER:
78 | return luai_numeq(nvalue(t1), nvalue(t2));
79 | case LUA_TBOOLEAN:
80 | return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */
81 | case LUA_TLIGHTUSERDATA:
82 | case LUA_TROTABLE:
83 | case LUA_TLIGHTFUNCTION:
84 | return pvalue(t1) == pvalue(t2);
85 | default:
86 | lua_assert(iscollectable(t1));
87 | return gcvalue(t1) == gcvalue(t2);
88 | }
89 | }
90 |
91 |
92 | int luaO_str2d (const char *s, lua_Number *result) {
93 | char *endptr;
94 | *result = lua_str2number(s, &endptr);
95 | if (endptr == s) return 0; /* conversion failed */
96 | if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */
97 | *result = cast_num(strtoul(s, &endptr, 16));
98 | if (*endptr == '\0') return 1; /* most common case */
99 | while (isspace(cast(unsigned char, *endptr))) endptr++;
100 | if (*endptr != '\0') return 0; /* invalid trailing characters? */
101 | return 1;
102 | }
103 |
104 |
105 |
106 | static void pushstr (lua_State *L, const char *str) {
107 | setsvalue2s(L, L->top, luaS_new(L, str));
108 | incr_top(L);
109 | }
110 |
111 |
112 | /* this function handles only `%d', `%c', %f, %p, and `%s' formats */
113 | const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
114 | int n = 1;
115 | pushstr(L, "");
116 | for (;;) {
117 | const char *e = strchr(fmt, '%');
118 | if (e == NULL) break;
119 | setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt));
120 | incr_top(L);
121 | switch (*(e+1)) {
122 | case 's': {
123 | const char *s = va_arg(argp, char *);
124 | if (s == NULL) s = "(null)";
125 | pushstr(L, s);
126 | break;
127 | }
128 | case 'c': {
129 | char buff[2];
130 | buff[0] = cast(char, va_arg(argp, int));
131 | buff[1] = '\0';
132 | pushstr(L, buff);
133 | break;
134 | }
135 | case 'd': {
136 | setnvalue(L->top, cast_num(va_arg(argp, int)));
137 | incr_top(L);
138 | break;
139 | }
140 | case 'f': {
141 | setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));
142 | incr_top(L);
143 | break;
144 | }
145 | case 'p': {
146 | char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */
147 | sprintf(buff, "%p", va_arg(argp, void *));
148 | pushstr(L, buff);
149 | break;
150 | }
151 | case '%': {
152 | pushstr(L, "%");
153 | break;
154 | }
155 | default: {
156 | char buff[3];
157 | buff[0] = '%';
158 | buff[1] = *(e+1);
159 | buff[2] = '\0';
160 | pushstr(L, buff);
161 | break;
162 | }
163 | }
164 | n += 2;
165 | fmt = e+2;
166 | }
167 | pushstr(L, fmt);
168 | luaV_concat(L, n+1, cast_int(L->top - L->base) - 1);
169 | L->top -= n;
170 | return svalue(L->top - 1);
171 | }
172 |
173 |
174 | const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {
175 | const char *msg;
176 | va_list argp;
177 | va_start(argp, fmt);
178 | msg = luaO_pushvfstring(L, fmt, argp);
179 | va_end(argp);
180 | return msg;
181 | }
182 |
183 |
184 | void luaO_chunkid (char *out, const char *source, size_t bufflen) {
185 | if (*source == '=') {
186 | strncpy(out, source+1, bufflen); /* remove first char */
187 | out[bufflen-1] = '\0'; /* ensures null termination */
188 | }
189 | else { /* out = "source", or "...source" */
190 | if (*source == '@') {
191 | size_t l;
192 | source++; /* skip the `@' */
193 | bufflen -= sizeof(" '...' ");
194 | l = strlen(source);
195 | strcpy(out, "");
196 | if (l > bufflen) {
197 | source += (l-bufflen); /* get last part of file name */
198 | strcat(out, "...");
199 | }
200 | strcat(out, source);
201 | }
202 | else { /* out = [string "string"] */
203 | size_t len = strcspn(source, "\n\r"); /* stop at first newline */
204 | bufflen -= sizeof(" [string \"...\"] ");
205 | if (len > bufflen) len = bufflen;
206 | strcpy(out, "[string \"");
207 | if (source[len] != '\0') { /* must truncate? */
208 | strncat(out, source, len);
209 | strcat(out, "...");
210 | }
211 | else
212 | strcat(out, source);
213 | strcat(out, "\"]");
214 | }
215 | }
216 | }
217 |
--------------------------------------------------------------------------------
/linkit/include/vmboard.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * Copyright Statement:
3 | * --------------------
4 | * This software is protected by Copyright and the information contained
5 | * herein is confidential. The software may not be copied and the information
6 | * contained herein may not be used or disclosed except with the written
7 | * permission of MediaTek Inc. (C) 2005-2015
8 | *
9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21 | *
22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27 | *
28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33 | *
34 | *****************************************************************************/
35 |
36 | #ifndef _VMBOARD_SDK_H
37 | #define _VMBOARD_SDK_H
38 |
39 | #ifdef __cplusplus
40 | extern "C" {
41 | #endif
42 |
43 | #include "vmtype.h"
44 |
45 | /* pin mux mode */
46 | typedef enum
47 | {
48 | VM_DCL_PIN_MODE_GPIO = 1, /* gpio mode */
49 | VM_DCL_PIN_MODE_ADC, /* adc mode */
50 | VM_DCL_PIN_MODE_PWM, /* pwm mode */
51 | VM_DCL_PIN_MODE_UART, /* uart mode */
52 | VM_DCL_PIN_MODE_EINT, /* eint mode */
53 | VM_DCL_PIN_MODE_SPI, /* spi mode */
54 | VM_DCL_PIN_MODE_I2C, /* i2c mode */
55 | VM_DCL_PIN_MODE_SDIO, /* sdio mode */
56 | VM_DCL_PIN_MODE_DBI_C, /* dbi mode */
57 | } VM_DCL_PIN_MODE;
58 |
59 | #if defined(__HDK_LINKIT_ONE_V1__)
60 | #define VM_PIN_D0 10 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_UART */
61 | #define VM_PIN_D1 11 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_UART */
62 | #define VM_PIN_D2 46 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_EINT */
63 | #define VM_PIN_D3 13 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_EINT / VM_DCL_PIN_MODE_PWM */
64 | #define VM_PIN_D4 40 /* Pin mux, VM_DCL_PIN_MODE_GPIO */
65 | #define VM_PIN_D5 3 /* Pin mux, VM_DCL_PIN_MODE_GPIO */
66 | #define VM_PIN_D6 25 /* Pin mux, VM_DCL_PIN_MODE_GPIO */
67 | #define VM_PIN_D7 50 /* Pin mux, VM_DCL_PIN_MODE_GPIO */
68 | #define VM_PIN_D8 48 /* Pin mux, VM_DCL_PIN_MODE_GPIO */
69 | #define VM_PIN_D9 19 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_PWM */
70 | #define VM_PIN_D10 26 /* Pin mux, VM_DCL_PIN_MODE_GPIO */
71 | #define VM_PIN_D11 28 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_SPI / VM_DCL_PIN_MODE_SDIO */
72 | #define VM_PIN_D12 29 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_SPI / VM_DCL_PIN_MODE_SDIO */
73 | #define VM_PIN_D13 27 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_SPI / VM_DCL_PIN_MODE_SDIO */
74 | #define VM_PIN_D14 0 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_ADC */
75 | #define VM_PIN_D15 1 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_ADC */
76 | #define VM_PIN_D16 2 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_ADC */
77 | #define VM_PIN_D18 44 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_I2C */
78 | #define VM_PIN_D19 43 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_I2C */
79 | #define VM_PIN_A0 0 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_ADC */
80 | #define VM_PIN_A1 1 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_ADC */
81 | #define VM_PIN_A2 2 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_ADC */
82 | #define VM_PIN_SDA 44 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_I2C */
83 | #define VM_PIN_SCL 43 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_I2C */
84 | #define VM_PIN_RX 10 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_UART */
85 | #define VM_PIN_TX 11 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_UART */
86 | #elif defined(__HDK_LINKIT_ASSIST_2502__)
87 | #define VM_PIN_P0 13 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_PWM / VM_DCL_PIN_MODE_EINT*/
88 | #define VM_PIN_P1 3 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_PWM */
89 | #define VM_PIN_P2 27 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_SPI */
90 | #define VM_PIN_P3 28 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_SPI */
91 | #define VM_PIN_P4 29 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_SPI */
92 | #define VM_PIN_P5 19 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_SPI */
93 | #define VM_PIN_P6 43 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_I2C */
94 | #define VM_PIN_P7 44 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_I2C */
95 | #define VM_PIN_P8 10 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_UART */
96 | #define VM_PIN_P9 11 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_UART */
97 | #define VM_PIN_P10 57 /* Pin mux, VM_DCL_PIN_MODE_ADC */
98 | #define VM_PIN_P11 0 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_EINT / VM_DCL_PIN_MODE_ADC */
99 | #define VM_PIN_P12 1 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_EINT / VM_DCL_PIN_MODE_ADC */
100 | #define VM_PIN_P13 2 /* Pin mux, VM_DCL_PIN_MODE_GPIO / VM_DCL_PIN_MODE_EINT / VM_DCL_PIN_MODE_ADC */
101 | #define VM_PIN_P14 52 /* Pin mux, VM_DCL_PIN_MODE_EINT */
102 | #else
103 | #define VM_PIN_P0 0
104 | #endif
105 |
106 | #ifdef __cplusplus
107 | }
108 | #endif
109 |
110 | #endif /* _VMBOARD_SDK_H */
111 |
112 |
--------------------------------------------------------------------------------