forked from len0rd/rockbox
hwstub: add delay function
Change-Id: Iab208ed59a9a2540a64b190357411d3de28f288e
This commit is contained in:
parent
1dc91b4560
commit
5b865de73a
2 changed files with 21 additions and 0 deletions
|
|
@ -27,6 +27,7 @@
|
||||||
#include <readline/readline.h>
|
#include <readline/readline.h>
|
||||||
#include <readline/history.h>
|
#include <readline/history.h>
|
||||||
#include <lua.hpp>
|
#include <lua.hpp>
|
||||||
|
#include <unistd.h>
|
||||||
#include "soc_desc.hpp"
|
#include "soc_desc.hpp"
|
||||||
|
|
||||||
#if LUA_VERSION_NUM < 502
|
#if LUA_VERSION_NUM < 502
|
||||||
|
|
@ -244,6 +245,16 @@ int my_lua_quit(lua_State *state)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int my_lua_udelay(lua_State *state)
|
||||||
|
{
|
||||||
|
int n = lua_gettop(state);
|
||||||
|
if(n != 1)
|
||||||
|
luaL_error(state, "udelay takes one argument");
|
||||||
|
long usec = lua_tointeger(state, -1);
|
||||||
|
usleep(usec);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool my_lua_import_hwstub()
|
bool my_lua_import_hwstub()
|
||||||
{
|
{
|
||||||
int oldtop = lua_gettop(g_lua);
|
int oldtop = lua_gettop(g_lua);
|
||||||
|
|
@ -377,6 +388,9 @@ bool my_lua_import_hwstub()
|
||||||
lua_settable(g_lua, -3);
|
lua_settable(g_lua, -3);
|
||||||
lua_setfield(g_lua, -2, "help");
|
lua_setfield(g_lua, -2, "help");
|
||||||
|
|
||||||
|
lua_pushcclosure(g_lua, my_lua_udelay, 0);
|
||||||
|
lua_setfield(g_lua, -2, "udelay");
|
||||||
|
|
||||||
lua_setglobal(g_lua, "hwstub");
|
lua_setglobal(g_lua, "hwstub");
|
||||||
|
|
||||||
lua_pushcfunction(g_lua, my_lua_help);
|
lua_pushcfunction(g_lua, my_lua_help);
|
||||||
|
|
|
||||||
|
|
@ -108,4 +108,11 @@ end
|
||||||
--
|
--
|
||||||
DEV = hwstub.dev
|
DEV = hwstub.dev
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Misc
|
||||||
|
--
|
||||||
|
function hwstub.mdelay(msec)
|
||||||
|
hwstub.udelay(msec * 1000)
|
||||||
|
end
|
||||||
|
|
||||||
require "lua/load"
|
require "lua/load"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue