Esempio n. 1
0
// (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;
}
Esempio n. 2
0
// 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;
}
Esempio n. 3
0
// 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;
}
Esempio n. 4
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;  
}
Esempio n. 5
0
// 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;
}
Esempio n. 6
0
// 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;
}
Esempio n. 7
0
// 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;
}
Esempio n. 8
0
// (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);
}
Esempio n. 9
0
// (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);
}
Esempio n. 10
0
// 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;
}
Esempio n. 11
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);
}
Esempio n. 12
0
// (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);
}
Esempio n. 13
0
// (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);
}