// (tmr-delay ['num] 'num) -> Nil any tmr_delay(any ex) { timer_data_type period; unsigned id = PLATFORM_TIMER_SYS_ID; any x, y; x = cdr(ex), y = EVAL(car(x)); if (plen(ex) == 1) { // We only have 1 parameter. Assume // *tmr-sys-timer* and get the time // period. NeedNum(ex, y); period = (timer_data_type)unBox(y); } else { // Minimum 2 args required here - the // id and the period. Ignore the others. NeedNum(ex, y); id = unBox(y); MOD_CHECK_TIMER(ex, id); x = cdr(x), y = EVAL(car(x)); NeedNum(ex, y); period = unBox(y); } platform_timer_delay(id, period); return Nil; }
// Lua: res = getmaxdelay( [id] ) static int tmr_getmaxdelay( lua_State* L ) { timer_data_type res; unsigned id; id = ( unsigned )luaL_optinteger( L, 1, PLATFORM_TIMER_SYS_ID ); MOD_CHECK_TIMER( id ); res = platform_timer_op( id, PLATFORM_TIMER_OP_GET_MAX_DELAY, 0 ); lua_pushnumber( L, ( lua_Number )res ); return 1; }
// Lua: delay( id, period ) static int tmr_delay( lua_State* L ) { timer_data_type period; unsigned id; id = ( unsigned )luaL_optinteger( L, 1, PLATFORM_TIMER_SYS_ID ); MOD_CHECK_TIMER( id ); period = ( timer_data_type )luaL_checknumber( L, 2 ); platform_timer_delay( id, period ); return 0; }
// Helper function for the read/start functions static int tmrh_timer_op( lua_State* L, int op ) { unsigned id; timer_data_type res; id = ( unsigned )luaL_optinteger( L, 1, PLATFORM_TIMER_SYS_ID ); MOD_CHECK_TIMER( id ); res = platform_timer_op( id, op, 0 ); lua_pushnumber( L, ( lua_Number )res ); return 1; }
// Lua: clock = getclock( [id] ) static int tmr_getclock( lua_State* L ) { u32 res; unsigned id; id = ( unsigned )luaL_optinteger( L, 1, PLATFORM_TIMER_SYS_ID ); MOD_CHECK_TIMER( id ); res = platform_timer_op( id, PLATFORM_TIMER_OP_GET_CLOCK, 0 ); lua_pushinteger( L, res ); return 1; }
// Lua: time_us = getdiffnow( id, start ) static int tmr_getdiffnow( lua_State *L ) { timer_data_type start, res; unsigned id; id = ( unsigned )luaL_optinteger( L, 1, PLATFORM_TIMER_SYS_ID ); MOD_CHECK_TIMER( id ); start = ( timer_data_type )luaL_checknumber( L, 2 ); res = platform_timer_get_diff_crt( id, start ); lua_pushnumber( L, ( lua_Number )res ); return 1; }
// Lua: realclock = setclock( id, clock ) static int tmr_setclock( lua_State* L ) { u32 clock; unsigned id; id = ( unsigned )luaL_optinteger( L, 1, PLATFORM_TIMER_SYS_ID ); MOD_CHECK_TIMER( id ); clock = ( u32 )luaL_checkinteger( L, 2 ); clock = platform_timer_op( id, PLATFORM_TIMER_OP_SET_CLOCK, clock ); lua_pushinteger( L, clock ); return 1; }
// (tmr-getclock ['num]) -> num any tmr_getclock(any ex) { timer_data_type res; unsigned id = PLATFORM_TIMER_SYS_ID; any x, y; x = cdr(ex), y = EVAL(car(x)); if (plen(ex) > 0) { NeedNum(ex, y); id = unBox(y); MOD_CHECK_TIMER(ex, id); } res = platform_timer_op(id, PLATFORM_TIMER_OP_GET_CLOCK, 0); return box(res); }
// (tmr-start ['num]) -> num any tmr_start(any ex) { unsigned id = PLATFORM_TIMER_SYS_ID; timer_data_type res; any x, y; x = cdr(ex), y = EVAL(car(x)); if (plen(ex) > 0) { NeedNum(ex, y); id = unBox(y); MOD_CHECK_TIMER(ex, id); } res = platform_timer_op(id, PLATFORM_TIMER_OP_START, 0); return box(res); }
// Lua: set_match_int( id, timeout, type ) static int tmr_set_match_int( lua_State *L ) { unsigned id; u32 res; id = ( unsigned )luaL_optinteger( L, 1, PLATFORM_TIMER_SYS_ID ); MOD_CHECK_TIMER( id ); res = platform_timer_set_match_int( id, ( timer_data_type )luaL_checknumber( L, 2 ), ( int )luaL_checkinteger( L, 3 ) ); if( res == PLATFORM_TIMER_INT_TOO_SHORT ) return luaL_error( L, "timer interval too small" ); else if( res == PLATFORM_TIMER_INT_TOO_LONG ) return luaL_error( L, "timer interval too long" ); else if( res == PLATFORM_TIMER_INT_INVALID_ID ) return luaL_error( L, "match interrupt cannot be set on this timer" ); return 0; }
// (tmr-getdiffnow 'num 'num) -> num any tmr_getdiffnow(any ex) { timer_data_type start, res; unsigned id; any x, y; x = cdr(ex), y = EVAL(car(x)); NeedNum(ex, y); id = unBox(y); // get id. MOD_CHECK_TIMER(ex, id); x = cdr(x), y = EVAL(car(x)); NeedNum(ex, y); start = unBox(y); // get start. res = platform_timer_get_diff_crt(id, start); return box(res); }
// (tmr-setclock 'num 'num) -> num any tmr_setclock(any ex) { u32 clock; unsigned id; any x, y; x = cdr(ex), y = EVAL(car(x)); NeedNum(ex, y); id = unBox(y); // get id. MOD_CHECK_TIMER(ex, id); x = cdr(x), y = EVAL(car(x)); NeedNum(ex, y); clock = unBox(y); // get clock. clock = platform_timer_op(id, PLATFORM_TIMER_OP_SET_CLOCK, clock); return box(clock); }
// (tmr-gettimediff 'num 'num 'num) -> num any tmr_gettimediff(any ex) { timer_data_type start, end, res; unsigned id = PLATFORM_TIMER_SYS_ID; any x, y; x = cdr(ex), y = EVAL(car(x)); NeedNum(ex, y); id = unBox(y); // get id. MOD_CHECK_TIMER(ex, id); x = cdr(x), y = EVAL(car(x)); NeedNum(ex, y); start = unBox(y); // get start. x = cdr(x), y = EVAL(car(x)); NeedNum(ex, y); end = unBox(y); // get end. res = platform_timer_get_diff_us(id, start, end); return box(res); }