Ejemplo n.º 1
0
// (adc-setclock 'num 'num 'num) -> num
any plisp_adc_setclock(any ex) {
  s32 sfreq; // signed version for negative checking.
  u32 freq;
  unsigned id, timer_id = 0;
  any x, y;

  x = cdr(ex);
  NeedNum(ex, y = EVAL(car(x)));
  id = unBox(y); // get adc id.
  MOD_CHECK_ID(ex, adc, id);

  x = cdr(x);
  NeedNum(ex, y = EVAL(car(x)));
  sfreq = unBox(y); // get frequency.
  if (sfreq < 0)
    err(ex, y, "frequency must be 0 or positive");

  freq = (u32) sfreq;
  if (freq > 0) {
    x = cdr(x);
    NeedNum(ex, y = EVAL(car(x)));
    timer_id = unBox(y); // get timer id.
    MOD_CHECK_ID(ex, timer, timer_id);
    MOD_CHECK_RES_ID(ex, adc, id, timer, timer_id);
  }

  platform_adc_set_timer(id, timer_id);
  freq = platform_adc_set_clock(id, freq);
  return box(freq);
}
Ejemplo n.º 2
0
// PicoC: realclock = adc_setclock(id, freq, timer_id);
static void adc_setclock(pstate *p, val *r, val **param, int n)
{
  s32 sfreq; // signed version for negative checking
  u32 freq;
  unsigned id, timer_id = 0;
  
  id = param[0]->Val->UnsignedInteger;
  MOD_CHECK_ID(adc, id);
  sfreq = param[1]->Val->LongInteger;
  if (sfreq < 0)
    return pmod_error("frequency must be 0 or positive");
  freq = (u32) sfreq;
  if (freq > 0) {
    timer_id = param[2]->Val->UnsignedInteger;
    MOD_CHECK_ID(timer, timer_id);
    MOD_CHECK_RES_ID(adc, id, timer, timer_id);
  }
  
  platform_adc_set_timer(id, timer_id);
  freq = platform_adc_set_clock(id, freq);
  r->Val->UnsignedLongInteger = freq;
}
Ejemplo n.º 3
0
// Lua: realclock = setclock( id, freq, [timer_id] )
static int adc_setclock( lua_State *L )
{
	s32 sfreq; // signed version for negative checking
	u32 freq;
	unsigned id, timer_id = 0;

	id = luaL_checkinteger( L, 1 );
	MOD_CHECK_ID( adc, id );
	sfreq = luaL_checkinteger( L, 2 );
	if ( sfreq < 0 )
		return luaL_error( L, "frequency must be 0 or positive" );
	freq = ( u32 ) sfreq;
	if ( freq > 0 ) {
		timer_id = luaL_checkinteger( L, 3 );
		MOD_CHECK_ID( timer, timer_id );
		MOD_CHECK_RES_ID( adc, id, timer, timer_id );
	}

	platform_adc_set_timer( id, timer_id );
	freq = platform_adc_set_clock( id, freq );
	lua_pushinteger( L, freq );
	return 1;
}