surenyi
6 years ago
22 changed files with 53 additions and 873 deletions
@ -1,12 +0,0 @@ |
|||
/*! |
|||
* @p(html) |
|||
* <head> |
|||
* <meta charset="UTF-8"> |
|||
* <title> Settings for lua library </title> |
|||
* </head> |
|||
* @p |
|||
*/ |
|||
|
|||
metaonly module Settings { |
|||
} |
|||
|
@ -1,16 +0,0 @@ |
|||
var Build = xdc.useModule('xdc.bld.BuildEnvironment'); |
|||
|
|||
var toolsDir = java.lang.System.getenv("XDCCGROOT") |
|||
var C66P = xdc.useModule('ti.targets.elf.C66'); |
|||
|
|||
C66P.rootDir = toolsDir |
|||
|
|||
/* include path */ |
|||
var libdspPath = "$(PKGROOT)/vsky/libdsp/"; |
|||
var libdspPathInclude = " -i" + libdspPath + "/inc" + " -i" + libdspPath + "/lua/5.3.5"; |
|||
|
|||
var Pkg = xdc.useModule("xdc.bld.PackageContents"); |
|||
Pkg.generatedFiles.$add("lib/"); |
|||
|
|||
Build.targets = [C66P]; |
|||
|
@ -1,2 +0,0 @@ |
|||
package |
|||
lib |
@ -1,158 +0,0 @@ |
|||
/*=========================================================================*\
|
|||
* Auxiliar routines for class hierarchy manipulation |
|||
* LuaSocket toolkit |
|||
\*=========================================================================*/ |
|||
#include <string.h> |
|||
#include <stdio.h> |
|||
|
|||
#include "auxiliar.h" |
|||
|
|||
/*=========================================================================*\
|
|||
* Exported functions |
|||
\*=========================================================================*/ |
|||
/*-------------------------------------------------------------------------*\
|
|||
* Initializes the module |
|||
\*-------------------------------------------------------------------------*/ |
|||
int auxiliar_open(lua_State *L) { |
|||
(void) L; |
|||
return 0; |
|||
} |
|||
|
|||
/*-------------------------------------------------------------------------*\
|
|||
* Creates a new class with given methods |
|||
* Methods whose names start with __ are passed directly to the metatable. |
|||
\*-------------------------------------------------------------------------*/ |
|||
void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func) { |
|||
luaL_newmetatable(L, classname); /* mt */ |
|||
/* create __index table to place methods */ |
|||
lua_pushstring(L, "__index"); /* mt,"__index" */ |
|||
lua_newtable(L); /* mt,"__index",it */ |
|||
/* put class name into class metatable */ |
|||
lua_pushstring(L, "class"); /* mt,"__index",it,"class" */ |
|||
lua_pushstring(L, classname); /* mt,"__index",it,"class",classname */ |
|||
lua_rawset(L, -3); /* mt,"__index",it */ |
|||
/* pass all methods that start with _ to the metatable, and all others
|
|||
* to the index table */ |
|||
for (; func->name; func++) { /* mt,"__index",it */ |
|||
lua_pushstring(L, func->name); |
|||
lua_pushcfunction(L, func->func); |
|||
lua_rawset(L, func->name[0] == '_' ? -5: -3); |
|||
} |
|||
lua_rawset(L, -3); /* mt */ |
|||
lua_pop(L, 1); |
|||
} |
|||
|
|||
/*-------------------------------------------------------------------------*\
|
|||
* Prints the value of a class in a nice way |
|||
\*-------------------------------------------------------------------------*/ |
|||
int auxiliar_tostring(lua_State *L) { |
|||
char buf[32]; |
|||
if (!lua_getmetatable(L, 1)) goto error; |
|||
lua_pushstring(L, "__index"); |
|||
lua_gettable(L, -2); |
|||
if (!lua_istable(L, -1)) goto error; |
|||
lua_pushstring(L, "class"); |
|||
lua_gettable(L, -2); |
|||
if (!lua_isstring(L, -1)) goto error; |
|||
sprintf(buf, "%p", lua_touserdata(L, 1)); |
|||
lua_pushfstring(L, "%s: %s", lua_tostring(L, -1), buf); |
|||
return 1; |
|||
error: |
|||
lua_pushstring(L, "invalid object passed to 'auxiliar.c:__tostring'"); |
|||
lua_error(L); |
|||
return 1; |
|||
} |
|||
|
|||
/*-------------------------------------------------------------------------*\
|
|||
* Insert class into group |
|||
\*-------------------------------------------------------------------------*/ |
|||
void auxiliar_add2group(lua_State *L, const char *classname, const char *groupname) { |
|||
luaL_getmetatable(L, classname); |
|||
lua_pushstring(L, groupname); |
|||
lua_pushboolean(L, 1); |
|||
lua_rawset(L, -3); |
|||
lua_pop(L, 1); |
|||
} |
|||
|
|||
/*-------------------------------------------------------------------------*\
|
|||
* Make sure argument is a boolean |
|||
\*-------------------------------------------------------------------------*/ |
|||
int auxiliar_checkboolean(lua_State *L, int objidx) { |
|||
if (!lua_isboolean(L, objidx)) |
|||
auxiliar_typeerror(L, objidx, lua_typename(L, LUA_TBOOLEAN)); |
|||
return lua_toboolean(L, objidx); |
|||
} |
|||
|
|||
/*-------------------------------------------------------------------------*\
|
|||
* Return userdata pointer if object belongs to a given class, abort with |
|||
* error otherwise |
|||
\*-------------------------------------------------------------------------*/ |
|||
void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx) { |
|||
void *data = auxiliar_getclassudata(L, classname, objidx); |
|||
if (!data) { |
|||
char msg[45]; |
|||
sprintf(msg, "%.35s expected", classname); |
|||
luaL_argerror(L, objidx, msg); |
|||
} |
|||
return data; |
|||
} |
|||
|
|||
/*-------------------------------------------------------------------------*\
|
|||
* Return userdata pointer if object belongs to a given group, abort with |
|||
* error otherwise |
|||
\*-------------------------------------------------------------------------*/ |
|||
void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx) { |
|||
void *data = auxiliar_getgroupudata(L, groupname, objidx); |
|||
if (!data) { |
|||
char msg[45]; |
|||
sprintf(msg, "%.35s expected", groupname); |
|||
luaL_argerror(L, objidx, msg); |
|||
} |
|||
return data; |
|||
} |
|||
|
|||
/*-------------------------------------------------------------------------*\
|
|||
* Set object class |
|||
\*-------------------------------------------------------------------------*/ |
|||
void auxiliar_setclass(lua_State *L, const char *classname, int objidx) { |
|||
luaL_getmetatable(L, classname); |
|||
if (objidx < 0) objidx--; |
|||
lua_setmetatable(L, objidx); |
|||
} |
|||
|
|||
/*-------------------------------------------------------------------------*\
|
|||
* Get a userdata pointer if object belongs to a given group. Return NULL |
|||
* otherwise |
|||
\*-------------------------------------------------------------------------*/ |
|||
void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx) { |
|||
if (!lua_getmetatable(L, objidx)) |
|||
return NULL; |
|||
lua_pushstring(L, groupname); |
|||
lua_rawget(L, -2); |
|||
if (lua_isnil(L, -1)) { |
|||
lua_pop(L, 2); |
|||
return NULL; |
|||
} else { |
|||
lua_pop(L, 2); |
|||
return lua_touserdata(L, objidx); |
|||
} |
|||
} |
|||
|
|||
/*-------------------------------------------------------------------------*\
|
|||
* Get a userdata pointer if object belongs to a given class. Return NULL |
|||
* otherwise |
|||
\*-------------------------------------------------------------------------*/ |
|||
void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) { |
|||
return luaL_checkudata(L, objidx, classname); |
|||
} |
|||
|
|||
/*-------------------------------------------------------------------------*\
|
|||
* Throws error when argument does not have correct type. |
|||
* Used to be part of lauxlib in Lua 5.1, was dropped from 5.2. |
|||
\*-------------------------------------------------------------------------*/ |
|||
int auxiliar_typeerror (lua_State *L, int narg, const char *tname) { |
|||
const char *msg = lua_pushfstring(L, "%s expected, got %s", tname, |
|||
luaL_typename(L, narg)); |
|||
return luaL_argerror(L, narg, msg); |
|||
} |
|||
|
@ -1,48 +0,0 @@ |
|||
#ifndef AUXILIAR_H |
|||
#define AUXILIAR_H |
|||
/*=========================================================================*\
|
|||
* Auxiliar routines for class hierarchy manipulation |
|||
* LuaSocket toolkit (but completely independent of other LuaSocket modules) |
|||
* |
|||
* A LuaSocket class is a name associated with Lua metatables. A LuaSocket |
|||
* group is a name associated with a class. A class can belong to any number |
|||
* of groups. This module provides the functionality to: |
|||
* |
|||
* - create new classes |
|||
* - add classes to groups |
|||
* - set the class of objects |
|||
* - check if an object belongs to a given class or group |
|||
* - get the userdata associated to objects |
|||
* - print objects in a pretty way |
|||
* |
|||
* LuaSocket class names follow the convention <module>{<class>}. Modules |
|||
* can define any number of classes and groups. The module tcp.c, for |
|||
* example, defines the classes tcp{master}, tcp{client} and tcp{server} and |
|||
* the groups tcp{client,server} and tcp{any}. Module functions can then |
|||
* perform type-checking on their arguments by either class or group. |
|||
* |
|||
* LuaSocket metatables define the __index metamethod as being a table. This |
|||
* table has one field for each method supported by the class, and a field |
|||
* "class" with the class name. |
|||
* |
|||
* The mapping from class name to the corresponding metatable and the |
|||
* reverse mapping are done using lauxlib. |
|||
\*=========================================================================*/ |
|||
|
|||
#include "lua.h" |
|||
#include "lauxlib.h" |
|||
#include "compat.h" |
|||
|
|||
int auxiliar_open(lua_State *L); |
|||
void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func); |
|||
void auxiliar_add2group(lua_State *L, const char *classname, const char *group); |
|||
void auxiliar_setclass(lua_State *L, const char *classname, int objidx); |
|||
void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx); |
|||
void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx); |
|||
void *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx); |
|||
void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx); |
|||
int auxiliar_checkboolean(lua_State *L, int objidx); |
|||
int auxiliar_tostring(lua_State *L); |
|||
int auxiliar_typeerror(lua_State *L, int narg, const char *tname); |
|||
|
|||
#endif /* AUXILIAR_H */ |
@ -1,19 +0,0 @@ |
|||
#include "compat.h" |
|||
|
|||
#if LUA_VERSION_NUM==501 |
|||
/*
|
|||
** Adapted from Lua 5.2 |
|||
*/ |
|||
void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { |
|||
luaL_checkstack(L, nup+1, "too many upvalues"); |
|||
for (; l->name != NULL; l++) { /* fill the table with given functions */ |
|||
int i; |
|||
lua_pushstring(L, l->name); |
|||
for (i = 0; i < nup; i++) /* copy upvalues to the top */ |
|||
lua_pushvalue(L, -(nup+1)); |
|||
lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ |
|||
lua_settable(L, -(nup + 3)); |
|||
} |
|||
lua_pop(L, nup); /* remove upvalues */ |
|||
} |
|||
#endif |
@ -1,11 +0,0 @@ |
|||
#ifndef COMPAT_H |
|||
#define COMPAT_H |
|||
|
|||
#include "lua.h" |
|||
#include "lauxlib.h" |
|||
|
|||
#if LUA_VERSION_NUM==501 |
|||
void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); |
|||
#endif |
|||
|
|||
#endif |
@ -1,16 +0,0 @@ |
|||
var Build = xdc.useModule('xdc.bld.BuildEnvironment'); |
|||
|
|||
var toolsDir = java.lang.System.getenv("XDCCGROOT") |
|||
var C66P = xdc.useModule('ti.targets.elf.C66'); |
|||
|
|||
C66P.rootDir = toolsDir |
|||
|
|||
/* include path */ |
|||
var libdspPath = "$(PKGROOT)/vsky/libdsp/"; |
|||
var libdspPathInclude = " -i" + libdspPath + "/inc" + " -i" + libdspPath + "/lua/5.3.5"; |
|||
|
|||
var Pkg = xdc.useModule("xdc.bld.PackageContents"); |
|||
Pkg.generatedFiles.$add("lib/"); |
|||
|
|||
Build.targets = [C66P]; |
|||
|
@ -1,442 +0,0 @@ |
|||
#include <string.h> |
|||
#include <stdlib.h> |
|||
#ifdef LUA_INTERPRTER |
|||
#include "nor.h" |
|||
#include "gpio.h" |
|||
#include "tsc.h" |
|||
#include "lua.h" |
|||
#include "lualib.h" |
|||
#include "lauxlib.h" |
|||
#include "utils.h" |
|||
#include "uart.h" |
|||
#include "power_ctrl.h" |
|||
#else |
|||
#include <vsky/libdsp/inc/nor.h> |
|||
#include <vsky/libdsp/inc/gpio.h> |
|||
#include <vsky/libdsp/inc/tsc.h> |
|||
#include <vsky/libdsp/inc/utils.h> |
|||
#include <vsky/libdsp/inc/uart.h> |
|||
#include <vsky/libdsp/inc/power_ctrl.h> |
|||
#include <vsky/libdsp/lua/5.3.5/lua.h> |
|||
#include <vsky/libdsp/lua/5.3.5/lualib.h> |
|||
#include <vsky/libdsp/lua/5.3.5/lauxlib.h> |
|||
#endif |
|||
#include "kit.h" |
|||
#include "auxiliar.h" |
|||
|
|||
#define NOR_CLASS_NAME "flash{class}" |
|||
#define NOR_GROUP_NAME "flash{any}" |
|||
|
|||
#define UART_CLASS_NAME "uart{class}" |
|||
#define UART_GROUP_NAME "uart{any}" |
|||
|
|||
static void __add_funcs(lua_State *L, struct luaL_Reg funcs[], const char *name) |
|||
{ |
|||
lua_newtable(L); |
|||
luaL_setfuncs(L, funcs, 0); |
|||
lua_setglobal(L, name); |
|||
} |
|||
|
|||
static int __nor_write(lua_State *L) |
|||
{ |
|||
int r; |
|||
void **ud = (void **)auxiliar_checkgroup(L, NOR_GROUP_NAME, 1); |
|||
nor_flash_t nf = *ud; |
|||
unsigned int addr = luaL_checkinteger(L, 2); |
|||
const char *s; |
|||
size_t len; |
|||
s = luaL_checklstring(L, 3, &len); |
|||
r = nor_flash_write(nf, s, addr, len); |
|||
lua_pushboolean(L, r == 0); |
|||
return 1; |
|||
} |
|||
|
|||
static int __nor_erase(lua_State *L) |
|||
{ |
|||
int r; |
|||
void **ud = (void **)auxiliar_checkgroup(L, NOR_GROUP_NAME, 1); |
|||
nor_flash_t nf = *ud; |
|||
unsigned int s = luaL_checkinteger(L, 2); |
|||
int cnt = luaL_checkinteger(L, 3); |
|||
|
|||
r = nor_flash_erase(nf, s, s + cnt - 1); |
|||
lua_pushboolean(L, r == 0); |
|||
return 1; |
|||
} |
|||
|
|||
static int __nor_read(lua_State *L) |
|||
{ |
|||
int r = 0; |
|||
void **ud = (void **)auxiliar_checkgroup(L, NOR_GROUP_NAME, 1); |
|||
nor_flash_t nf = *ud; |
|||
unsigned int addr = luaL_checkinteger(L, 2); |
|||
int cnt = luaL_checkinteger(L, 3); |
|||
uint8_t *to = malloc(cnt); |
|||
|
|||
if (to == NULL) { |
|||
goto error; |
|||
} |
|||
r = nor_flash_read(nf, to, addr, cnt); |
|||
if (r == 0) { |
|||
lua_pushboolean(L, 1); |
|||
lua_pushlstring(L, (char *)to, r); |
|||
free(to); |
|||
return 2; |
|||
} |
|||
free(to); |
|||
error: |
|||
lua_pushboolean(L, 0); |
|||
return 1; |
|||
} |
|||
|
|||
static int __nor_size(lua_State *L) |
|||
{ |
|||
void **ud = (void **)auxiliar_checkgroup(L, NOR_GROUP_NAME, 1); |
|||
nor_flash_t nf = *ud; |
|||
lua_pushinteger(L, nor_flash_size(nf)); |
|||
return 1; |
|||
} |
|||
|
|||
static int __nor_sectors(lua_State *L) |
|||
{ |
|||
void **ud = (void **)auxiliar_checkgroup(L, NOR_GROUP_NAME, 1); |
|||
nor_flash_t nf = *ud; |
|||
lua_pushinteger(L, nor_flash_sectors(nf)); |
|||
return 1; |
|||
} |
|||
|
|||
static int __nor_sec_size(lua_State *L) |
|||
{ |
|||
void **ud = (void **)auxiliar_checkgroup(L, NOR_GROUP_NAME, 1); |
|||
nor_flash_t nf = *ud; |
|||
lua_pushinteger(L, nor_flash_sector_size(nf)); |
|||
return 1; |
|||
} |
|||
|
|||
static int __nor_close(lua_State *L) |
|||
{ |
|||
void **ud = (void **)auxiliar_checkgroup(L, NOR_GROUP_NAME, 1); |
|||
nor_flash_t nf = *ud; |
|||
|
|||
if (nf) { |
|||
nor_flash_close(nf); |
|||
*ud = NULL; |
|||
} |
|||
return 0; |
|||
} |
|||
|
|||
static struct luaL_Reg __nor_methods[] = { |
|||
{"erase", __nor_erase}, |
|||
{"write", __nor_write}, |
|||
{"read", __nor_read}, |
|||
{"size", __nor_size}, |
|||
{"sectors", __nor_sectors}, |
|||
{"sector_size", __nor_sec_size}, |
|||
{"close", __nor_close}, |
|||
{"__gc", __nor_close}, |
|||
{"__tostring", auxiliar_tostring}, |
|||
{NULL, NULL} |
|||
}; |
|||
|
|||
static int __flash_open(lua_State *L) |
|||
{ |
|||
const char *s = luaL_checkstring(L, 1); |
|||
int cs = luaL_checkinteger(L, 2); |
|||
nor_flash_t nf = NULL; |
|||
void **ud; |
|||
int mode, use_def = 1; |
|||
|
|||
if (strcmp(s, "spi") == 0) { |
|||
mode = NOR_FLASH_MODE_SPI; |
|||
} else if (strcmp(s, "emif") == 0) { |
|||
mode = NOR_FLASH_MODE_EMIF; |
|||
} else { |
|||
return 0; |
|||
} |
|||
|
|||
if ((lua_gettop(L) >= 3) && (lua_type(L, 3) == LUA_TBOOLEAN)) { |
|||
use_def = lua_toboolean(L, 3); |
|||
} |
|||
|
|||
nf = nor_flash_open(mode, cs, use_def); |
|||
|
|||
if (nf == NULL) |
|||
return 0; |
|||
ud = (void **)lua_newuserdata(L, sizeof (void *)); |
|||
*ud = nf; |
|||
auxiliar_setclass(L, NOR_CLASS_NAME, -1); |
|||
|
|||
return 1; |
|||
} |
|||
|
|||
static void flash_init(lua_State *L) |
|||
{ |
|||
auxiliar_newclass(L, NOR_CLASS_NAME, __nor_methods); |
|||
auxiliar_add2group(L, NOR_CLASS_NAME, NOR_GROUP_NAME); |
|||
} |
|||
|
|||
static int __uart_meth_getc(lua_State *L) |
|||
{ |
|||
void **ud = (void **)auxiliar_checkgroup(L, UART_GROUP_NAME, 1); |
|||
uart_t uart = *ud; |
|||
lua_pushinteger(L, uart_read(uart)); |
|||
return 1; |
|||
} |
|||
|
|||
static int __uart_meth_putc(lua_State *L) |
|||
{ |
|||
void **ud = (void **)auxiliar_checkgroup(L, UART_GROUP_NAME, 1); |
|||
uart_t uart = *ud; |
|||
int c = luaL_checkinteger(L, 2); |
|||
|
|||
uart_write(uart, c); |
|||
return 0; |
|||
} |
|||
|
|||
static int __uart_meth_puts(lua_State *L) |
|||
{ |
|||
void **ud = (void **)auxiliar_checkgroup(L, UART_GROUP_NAME, 1); |
|||
uart_t uart = *ud; |
|||
const char *s = luaL_checkstring(L, 2); |
|||
|
|||
while (*s) { |
|||
uart_write(uart, *s++); |
|||
} |
|||
return 0; |
|||
} |
|||
|
|||
static int __uart_meth_ready(lua_State *L) |
|||
{ |
|||
void **ud = (void **)auxiliar_checkgroup(L, UART_GROUP_NAME, 1); |
|||
uart_t uart = *ud; |
|||
lua_pushboolean(L, uart_is_ready(uart)); |
|||
return 1; |
|||
} |
|||
|
|||
static int __uart_meth_close(lua_State *L) |
|||
{ |
|||
void **ud = (void **)auxiliar_checkgroup(L, UART_GROUP_NAME, 1); |
|||
uart_t uart = *ud; |
|||
if (uart) { |
|||
uart_close(uart); |
|||
*ud = NULL; |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
static int __uart_meth_set_baudrate(lua_State *L) |
|||
{ |
|||
void **ud = (void **)auxiliar_checkgroup(L, UART_GROUP_NAME, 1); |
|||
uart_t uart = *ud; |
|||
int bps = luaL_checkinteger(L, 2); |
|||
|
|||
uart_set_databits(uart, bps); |
|||
return 0; |
|||
} |
|||
|
|||
static int __uart_meth_set_databits(lua_State *L) |
|||
{ |
|||
void **ud = (void **)auxiliar_checkgroup(L, UART_GROUP_NAME, 1); |
|||
uart_t uart = *ud; |
|||
int v = luaL_checkinteger(L, 2); |
|||
|
|||
uart_set_baudrate(uart, v); |
|||
return 0; |
|||
} |
|||
|
|||
static int __uart_meth_set_stopbits(lua_State *L) |
|||
{ |
|||
void **ud = (void **)auxiliar_checkgroup(L, UART_GROUP_NAME, 1); |
|||
uart_t uart = *ud; |
|||
int v = luaL_checkinteger(L, 2); |
|||
|
|||
uart_set_stopbits(uart, v); |
|||
return 0; |
|||
} |
|||
|
|||
static int __uart_meth_set_parity(lua_State *L) |
|||
{ |
|||
void **ud = (void **)auxiliar_checkgroup(L, UART_GROUP_NAME, 1); |
|||
uart_t uart = *ud; |
|||
const char * v = luaL_checkstring(L, 2); |
|||
|
|||
if (strcmp(v, "none") == 0) { |
|||
uart_set_parity(uart, PARITY_NONE); |
|||
} else if (strcmp(v, "even") == 0) { |
|||
uart_set_parity(uart, PARITY_EVEN); |
|||
} else if (strcmp(v, "odd") == 0) { |
|||
uart_set_parity(uart, PARITY_ODD); |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
static struct luaL_Reg uart_meths[] = { |
|||
{"getc", __uart_meth_getc}, |
|||
{"putc", __uart_meth_putc}, |
|||
{"puts", __uart_meth_puts}, |
|||
{"ready",__uart_meth_ready}, |
|||
{"close",__uart_meth_close}, |
|||
{"set_baudrate", __uart_meth_set_baudrate}, |
|||
{"set_databits", __uart_meth_set_databits}, |
|||
{"set_stopbits", __uart_meth_set_stopbits}, |
|||
{"set_parity", __uart_meth_set_parity}, |
|||
{"__gc", __uart_meth_close}, |
|||
{"__tostring", auxiliar_tostring}, |
|||
|
|||
{NULL, NULL} |
|||
}; |
|||
|
|||
static void uart_init(lua_State *L) |
|||
{ |
|||
auxiliar_newclass(L, UART_CLASS_NAME, uart_meths); |
|||
auxiliar_add2group(L,UART_CLASS_NAME, UART_GROUP_NAME); |
|||
} |
|||
|
|||
static int __uart_open(lua_State *L) |
|||
{ |
|||
uart_t u; |
|||
int id = luaL_checkinteger(L, 1); |
|||
u = uart_open(id); |
|||
if (u) { |
|||
void **ud = (void **)lua_newuserdata(L, sizeof (void *)); |
|||
if (ud) { |
|||
*ud = u; |
|||
auxiliar_setclass(L, UART_CLASS_NAME, -1); |
|||
} else { |
|||
uart_close(u); |
|||
u = NULL; |
|||
} |
|||
} |
|||
return u ? 1 : 0; |
|||
} |
|||
|
|||
static int __tsc_init(lua_State *L) |
|||
{ |
|||
tsc_init(); |
|||
return 0; |
|||
} |
|||
|
|||
static int __tsc_msleep(lua_State *L) |
|||
{ |
|||
uint64_t r = luaL_checkinteger(L, 1) * 1000; |
|||
tsc_delay(r); |
|||
return 0; |
|||
} |
|||
|
|||
static int __tsc_ticks(lua_State *L) |
|||
{ |
|||
uint64_t ticks = tsc_get_ticks(); |
|||
lua_pushinteger(L, ticks); |
|||
return 1; |
|||
} |
|||
|
|||
static struct luaL_Reg __tsc[] = { |
|||
{"init", __tsc_init}, |
|||
{"msleep", __tsc_msleep}, |
|||
{"ticks", __tsc_ticks}, |
|||
{NULL, NULL} |
|||
}; |
|||
|
|||
static int __gpio_input(lua_State *L) |
|||
{ |
|||
int io = luaL_checkinteger(L, 1); |
|||
int r; |
|||
|
|||
r = gpio_get_value(io); |
|||
lua_pushinteger(L, r); |
|||
return 1; |
|||
} |
|||
|
|||
static int __gpio_output(lua_State *L) |
|||
{ |
|||
int io = luaL_checkinteger(L, 1); |
|||
int b = luaL_checkinteger(L, 2); |
|||
|
|||
gpio_set_value(io, b); |
|||
return 0; |
|||
} |
|||
|
|||
static int __gpio_direction(lua_State *L) |
|||
{ |
|||
int io = luaL_checkinteger(L, 1); |
|||
const char *s = luaL_checkstring(L, 2); |
|||
int r = 0; |
|||
|
|||
if (strcmp(s, "in") == 0) { |
|||
gpio_direction_input(io); |
|||
} else if (strcmp(s, "out") == 0) { |
|||
gpio_direction_output(io); |
|||
} else { |
|||
r = -1; |
|||
} |
|||
lua_pushboolean(L, r == 0); |
|||
return 1; |
|||
} |
|||
|
|||
static struct luaL_Reg gpios[] = { |
|||
{"dir", __gpio_direction}, |
|||
{"in", __gpio_input}, |
|||
{"out", __gpio_output}, |
|||
{NULL, NULL} |
|||
}; |
|||
|
|||
static int __get_core_id(lua_State *L) |
|||
{ |
|||
lua_pushinteger(L, get_core_id()); |
|||
return 1; |
|||
} |
|||
|
|||
static int __to_l2_address(lua_State *L) |
|||
{ |
|||
unsigned int adr = lua_tointeger(L, 1); |
|||
lua_pushinteger(L, get_global_l2_address(adr)); |
|||
return 1; |
|||
} |
|||
|
|||
static int __strtoul(lua_State *L) |
|||
{ |
|||
const char *s = luaL_checkstring(L, 1); |
|||
unsigned int v; |
|||
|
|||
v = strtoul(s, NULL, 0); |
|||
lua_pushinteger(L, v); |
|||
return 1; |
|||
} |
|||
|
|||
static struct luaL_Reg utils[] = { |
|||
{"core_id", __get_core_id}, |
|||
{"l2_address",__to_l2_address}, |
|||
{"strtoul", __strtoul}, |
|||
{NULL, NULL} |
|||
}; |
|||
|
|||
static int __powerup(lua_State *L) |
|||
{ |
|||
const char *s = luaL_checkstring(L, 1); |
|||
if (strcmp(s, "all") == 0) { |
|||
power_up_domains(); |
|||
} else if (strcmp(s, "srio") == 0) { |
|||
power_up_srio(); |
|||
} |
|||
return 0; |
|||
} |
|||
static struct luaL_Reg board[] = { |
|||
{"flash", __flash_open}, |
|||
{"uart", __uart_open}, |
|||
{"power", __powerup}, |
|||
{NULL, NULL} |
|||
}; |
|||
|
|||
int luaopen_dspkits(struct lua_State *L) |
|||
{ |
|||
__add_funcs(L, gpios, "gpio"); |
|||
__add_funcs(L, __tsc, "tsc"); |
|||
__add_funcs(L, utils, "utils"); |
|||
flash_init(L); |
|||
uart_init(L); |
|||
__add_funcs(L, board, "board"); |
|||
return 0; |
|||
} |
|||
|
@ -1,8 +0,0 @@ |
|||
#ifndef __LUA_KIT__H__ |
|||
#define __LUA_KIT__H__ |
|||
struct lua_State; |
|||
|
|||
int luaopen_dspkits(struct lua_State *L); |
|||
|
|||
#endif |
|||
|
@ -1,37 +0,0 @@ |
|||
Pkg.otherFiles = [ |
|||
"config.bld", |
|||
"package.bld", |
|||
"package.xdc", |
|||
"package.inc", |
|||
"kit.h" |
|||
]; |
|||
|
|||
var luaFiles = [ |
|||
"kit.c", |
|||
"auxiliar.c", |
|||
"compat.c", |
|||
]; |
|||
|
|||
var objFiles = luaFiles |
|||
|
|||
for (var i = 0; i < Build.targets.length; i++) { |
|||
var targ = Build.targets[i]; |
|||
var libName = "luakit"; |
|||
|
|||
var libOptions = { |
|||
incs: libdspPathInclude, |
|||
copts: '--gcc', |
|||
defs: '-DLUA_COMPAT_5_2', |
|||
}; |
|||
|
|||
var lib = Pkg.addLibrary("lib/" + libName, targ, libOptions); |
|||
lib.addObjects(objFiles); |
|||
} |
|||
|
|||
Pkg.attrs.profile = "debug"; |
|||
|
|||
Pkg.attrs.exportSrc = false; |
|||
Pkg.attrs.exportCfg = true; |
|||
Pkg.attrs.compress = true; |
|||
Pkg.attrs.archiver = "tar"; |
|||
|
@ -1,11 +0,0 @@ |
|||
/* |
|||
* Package specification file for libdsp |
|||
*/ |
|||
|
|||
/*! |
|||
* ======== vsky.ligbdsp ======== |
|||
* dspkit library |
|||
*/ |
|||
package vsky.libdsp.lua.kit [1, 0, 0, 0] { |
|||
} |
|||
|
@ -1,70 +0,0 @@ |
|||
Pkg.otherFiles = [ |
|||
"config.bld", |
|||
"package.bld", |
|||
"package.xdc", |
|||
"package.inc", |
|||
"5.3.5/lua.h", |
|||
"5.3.5/lauxlib.h", |
|||
"5.3.5/luaconf.h", |
|||
"5.3.5/lualib.h", |
|||
]; |
|||
|
|||
var luaFiles = [ |
|||
"5.3.5/lapi.c", |
|||
"5.3.5/lauxlib.c", |
|||
"5.3.5/lbaselib.c", |
|||
"5.3.5/lbitlib.c", |
|||
"5.3.5/lcode.c", |
|||
"5.3.5/lcorolib.c", |
|||
"5.3.5/lctype.c", |
|||
"5.3.5/ldblib.c", |
|||
"5.3.5/ldebug.c", |
|||
"5.3.5/ldo.c", |
|||
"5.3.5/ldump.c", |
|||
"5.3.5/lfunc.c", |
|||
"5.3.5/lgc.c", |
|||
"5.3.5/linit.c", |
|||
"5.3.5/liolib.c", |
|||
"5.3.5/llex.c", |
|||
"5.3.5/lmathlib.c", |
|||
"5.3.5/lmem.c", |
|||
"5.3.5/loadlib.c", |
|||
"5.3.5/lobject.c", |
|||
"5.3.5/lopcodes.c", |
|||
"5.3.5/loslib.c", |
|||
"5.3.5/lparser.c", |
|||
"5.3.5/lstate.c", |
|||
"5.3.5/lstring.c", |
|||
"5.3.5/lstrlib.c", |
|||
"5.3.5/ltable.c", |
|||
"5.3.5/ltablib.c", |
|||
"5.3.5/ltm.c", |
|||
"5.3.5/lundump.c", |
|||
"5.3.5/lutf8lib.c", |
|||
"5.3.5/lvm.c", |
|||
"5.3.5/lzio.c" |
|||
]; |
|||
|
|||
var objFiles = luaFiles |
|||
|
|||
for (var i = 0; i < Build.targets.length; i++) { |
|||
var targ = Build.targets[i]; |
|||
var libName = "lua"; |
|||
|
|||
var libOptions = { |
|||
incs: libdspPathInclude, |
|||
copts: '--gcc', |
|||
defs: '-DLUA_COMPAT_5_2', |
|||
}; |
|||
|
|||
var lib = Pkg.addLibrary("lib/" + libName, targ, libOptions); |
|||
lib.addObjects(objFiles); |
|||
} |
|||
|
|||
Pkg.attrs.profile = "debug"; |
|||
|
|||
Pkg.attrs.exportSrc = false; |
|||
Pkg.attrs.exportCfg = true; |
|||
Pkg.attrs.compress = true; |
|||
Pkg.attrs.archiver = "tar"; |
|||
|
@ -1,12 +0,0 @@ |
|||
/* |
|||
* Package specification file for libdsp |
|||
*/ |
|||
|
|||
/*! |
|||
* ======== vsky.ligbdsp ======== |
|||
* dspkit library |
|||
*/ |
|||
package vsky.libdsp.lua [1, 0, 0, 0] { |
|||
module Settings; |
|||
} |
|||
|
Loading…
Reference in new issue