[Tinyos Core WG] AdcConfigure and struct return

David Gay dgay42 at gmail.com
Wed Sep 20 13:41:11 PDT 2006


[Results at end. Summary: runtime cost is 5x slower for Read.read, a
370 byte code increase and some RAM cost]

I experimented with changing the mica2 interface to the new proposal.
This basically means changing:

interface Atm128AdcConfig {
  async command uint8_t getChannel();
  async command uint8_t getRefVoltage();
  async command uint8_t getPrescaler();
}

to:
typedef struct {
  uint8_t channel;
  uint8_t refVoltage;
  uint8_t prescaler;
} adc_config_t;

interface Atm128AdcConfig {
  async command adc_config_t getConfiguration();
}

the code that uses this from
  uint8_t channel() {
    return call Atm128AdcConfig.getChannel[client]();
  }
  uint8_t refVoltage() {
    return call Atm128AdcConfig.getRefVoltage[client]();
  }
  uint8_t prescaler() {
    return call Atm128AdcConfig.getPrescaler[client]();
  }
  void sample() {
    call Atm128AdcSingle.getData(channel(), refVoltage(), TRUE, prescaler());
  }

to:
  uint8_t channel() {
    return (call Atm128AdcConfig.getConfiguration[client]()).channel;
  }
  uint8_t refVoltage() {
    return (call Atm128AdcConfig.getConfiguration[client]()).refVoltage;
  }
  uint8_t prescaler() {
    return (call Atm128AdcConfig.getConfiguration[client]()).prescaler;
  }
  void sample() {
    call Atm128AdcSingle.getData(channel(), refVoltage(), TRUE, prescaler());
  }

and a typical configuration file from:
  async command uint8_t Atm128AdcConfig.getChannel() {
    return ATM128_ADC_SNGL_GND;
  }
  async command uint8_t Atm128AdcConfig.getRefVoltage() {
    return ATM128_ADC_VREF_OFF;
  }
  async command uint8_t Atm128AdcConfig.getPrescaler() {
    return ATM128_ADC_PRESCALE_2;
  }
to:
  async command adc_config_t Atm128AdcConfig.getConfiguration[uint8_t c]() {
    adc_config_t def = { ATM128_ADC_SNGL_GND, ATM128_ADC_VREF_OFF,
ATM128_ADC_PRESCALE_2 };
    return def;
  }

The results are not very encouraging:
- there's a 3*(n+1) byte cost in RAM, where n is the number of configurations
- the Sense app (for a simple analog sensor) goes from 3506 to 3874
bytes of flash
- the time for the actual getData call goes from 106 to 533 cycles

Note that the getConfiguration commands and the channel/etc functions
are marked inline.

David


More information about the Tinyos-2.0wg mailing list