⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tep109.txt

📁 tinyos-2.x.rar
💻 TXT
📖 第 1 页 / 共 3 页
字号:

This bus-connected sensor is overly complex because it does not rely
on a shared framework of bus manipulation components. A sensor built
on top of the I2C or SPI bus would likely require fewer components.

::

  tos/platforms/telosa/chips/sht11/SensirionSht11C.nc
  
  // HIL interface to Sensirion SHT11 temperature and humidity sensor
  generic configuration SensirionSht11C() {  
    provides interface Read<uint16_t> as Temperature;
    provides interface DeviceMetadata as TemperatureDeviceMetadata;
    provides interface Read<uint16_t> as Humidity;
    provides interface DeviceMetadata as HumidityDeviceMetadata;
  }
  implementation {
    // Instantiate the module providing the HIL interfaces
    components new SensirionSht11ReaderP();
  
    Temperature = SensirionSht11ReaderP.Temperature;
    TemperatureDeviceMetadata = SensirionSht11ReaderP.TemperatureDeviceMetadata;
    Humidity = SensirionSht11ReaderP.Humidity;
    HumidityDeviceMetadata = SensirionSht11ReaderP.HumidityDeviceMetadata;

    // And connect it to the HAL component for the Sensirion SHT11
    components HalSensirionSht11C;
  
    enum { TEMP_KEY = unique("Sht11.Resource") };
    enum { HUM_KEY = unique("Sht11.Resource") };
  
    SensirionSht11ReaderP.TempResource -> HalSensirionSht11C.Resource[ TEMP_KEY ];
    SensirionSht11ReaderP.Sht11Temp -> HalSensirionSht11C.SensirionSht11[ TEMP_KEY ];
    SensirionSht11ReaderP.HumResource -> HalSensirionSht11C.Resource[ HUM_KEY ];
    SensirionSht11ReaderP.Sht11Hum -> HalSensirionSht11C.SensirionSht11[ HUM_KEY ];
  }
  
::
  
  tos/chips/sht11/SensirionSht11ReaderP.nc
  
  // Convert Sensirion SHT11 HAL to HIL interfaces for a single
  // client, performing automatic resource arbitration
  generic module SensirionSht11ReaderP() {
    provides interface Read<uint16_t> as Temperature;
    provides interface DeviceMetadata as TemperatureDeviceMetadata;
    provides interface Read<uint16_t> as Humidity;
    provides interface DeviceMetadata as HumidityDeviceMetadata;
    
    // Using separate resource interfaces for temperature and humidity allows
    // temperature and humidity measurements to be requested simultaneously
    // (if a single Resource interface was used, a request for temperature would
    // prevent any humidity requests until the temperature measurement was complete) 
    uses interface Resource as TempResource;
    uses interface Resource as HumResource;
    uses interface SensirionSht11 as Sht11Temp;
    uses interface SensirionSht11 as Sht11Hum;
  }
  implementation {
    command error_t Temperature.read() {
      // Start by requesting access to the SHT11
      return call TempResource.request();
    }
  
    event void TempResource.granted() {
      error_t result;
      // If the HAL measurement fails, release the SHT11 and signal failure
      if ((result = call Sht11Temp.measureTemperature()) != SUCCESS) {
        call TempResource.release();
        signal Temperature.readDone( result, 0 );
      }
    }
  
    event void Sht11Temp.measureTemperatureDone( error_t result, uint16_t val ) {
      // Release the SHT11 and signal the result
      call TempResource.release();
      signal Temperature.readDone( result, val );
    }

    command uint8_t TemperatureDeviceMetadata.getSignificantBits() { return 14; }

    command error_t Humidity.read() {
      // Start by requesting access to the SHT11
      return call HumResource.request();
    }
  
    event void HumResource.granted() {
      error_t result;
      // If the HAL measurement fails, release the SHT11 and signal failure
      if ((result = call Sht11Hum.measureHumidity()) != SUCCESS) {
        call HumResource.release();
        signal Humidity.readDone( result, 0 );
      }
    }
  
    event void Sht11Hum.measureHumidityDone( error_t result, uint16_t val ) {
      // Release the SHT11 and signal the result
      call HumResource.release();
      signal Humidity.readDone( result, val );
    }
  
    command uint8_t HumidityDeviceMetadata.getSignificantBits() { return 12; }

    // Dummy handlers for unused portions of the HAL interface
    event void Sht11Temp.resetDone( error_t result ) { }
    event void Sht11Temp.measureHumidityDone( error_t result, uint16_t val ) { }
    event void Sht11Temp.readStatusRegDone( error_t result, uint8_t val ) { }
    event void Sht11Temp.writeStatusRegDone( error_t result ) { }
  
    event void Sht11Hum.resetDone( error_t result ) { }
    event void Sht11Hum.measureTemperatureDone( error_t result, uint16_t val ) { }
    event void Sht11Hum.readStatusRegDone( error_t result, uint8_t val ) { }
    event void Sht11Hum.writeStatusRegDone( error_t result ) { }
  
    // We need default handlers as a client may wire to only the Temperature
    // sensor or only the Humidity sensor
    default event void Temperature.readDone( error_t result, uint16_t val ) { }
    default event void Humidity.readDone( error_t result, uint16_t val ) { }
  }
  
::
  
  tos/platforms/telosa/chips/sht11/HalSensirionSht11C.nc
  
  // HAL interface to Sensirion SHT11 temperature and humidity sensor
  configuration HalSensirionSht11C {
    // The SHT11 HAL uses resource arbitration to allow the sensor to shared
    // between multiple clients and for automatic power management (the SHT11
    // is switched off when no clients are waiting to use it)
    provides interface Resource[ uint8_t client ];
    provides interface SensirionSht11[ uint8_t client ];
  }
  implementation {
    // The HAL implementation logic
    components new SensirionSht11LogicP();
    SensirionSht11 = SensirionSht11LogicP;
  
    // And it's wiring to the SHT11 HPL - the actual resource management is
    // provided at the HPL layer
    components HplSensirionSht11C;
    Resource = HplSensirionSht11C.Resource;
    SensirionSht11LogicP.DATA -> HplSensirionSht11C.DATA;
    SensirionSht11LogicP.CLOCK -> HplSensirionSht11C.SCK;
    SensirionSht11LogicP.InterruptDATA -> HplSensirionSht11C.InterruptDATA;
    
    components new TimerMilliC();
    SensirionSht11LogicP.Timer -> TimerMilliC;
  
    components LedsC;
    SensirionSht11LogicP.Leds -> LedsC;
  }
  
::
  
  tos/chips/sht11/SensirionSht11LogicP.nc
  
  generic module SensirionSht11LogicP() {
    provides interface SensirionSht11[ uint8_t client ];
  
    uses interface GeneralIO as DATA;
    uses interface GeneralIO as CLOCK;
    uses interface GpioInterrupt as InterruptDATA;
  
    uses interface Timer<TMilli>;
  
    uses interface Leds;
  }
  implementation {
  
    ... bus protocol details omitted for brevity ...
  
  }
  
::
  
  tos/platforms/telosa/chips/sht11/HplSensirionSht11C.nc

  // Low-level, platform-specific glue-code to access the SHT11 sensor found
  // on telos-family motes - here  the HPL just provides resource management
  // and access to the SHT11 data, clock and interrupt pins
  configuration HplSensirionSht11C {
    provides interface Resource[ uint8_t id ];
    provides interface GeneralIO as DATA;
    provides interface GeneralIO as SCK;
    provides interface GpioInterrupt as InterruptDATA;
  }
  implementation {
    // Pins used to access the SHT11
    components HplMsp430GeneralIOC;
    
    components new Msp430GpioC() as DATAM;
    DATAM -> HplMsp430GeneralIOC.Port15;
    DATA = DATAM;
  
    components new Msp430GpioC() as SCKM;
    SCKM -> HplMsp430GeneralIOC.Port16;
    SCK = SCKM;
  
    components new Msp430GpioC() as PWRM;
    PWRM -> HplMsp430GeneralIOC.Port17;
  
    // HPL logic for switching the SHT11 on and off
    components HplSensirionSht11P;
    HplSensirionSht11P.PWR -> PWRM;
    HplSensirionSht11P.DATA -> DATAM;
    HplSensirionSht11P.SCK -> SCKM;
  
    components new TimerMilliC();
    HplSensirionSht11P.Timer -> TimerMilliC;
  
    components HplMsp430InterruptC;
    components new Msp430InterruptC() as InterruptDATAC;
    InterruptDATAC.HplInterrupt -> HplMsp430InterruptC.Port15;
    InterruptDATA = InterruptDATAC.Interrupt;
  
    // The arbiter and power manager for the SHT11
    components new FcfsArbiterC( "Sht11.Resource" ) as Arbiter;
    Resource = Arbiter;
    
    components new SplitControlPowerManagerC();
    SplitControlPowerManagerC.SplitControl -> HplSensirionSht11P;
    SplitControlPowerManagerC.ArbiterInit -> Arbiter.Init;
    SplitControlPowerManagerC.ArbiterInfo -> Arbiter.ArbiterInfo;
    SplitControlPowerManagerC.ResourceDefaultOwner -> Arbiter.ResourceDefaultOwner;
  }
  
::
  
  tos/platforms/telosa/chips/sht11/HplSensirionSht11P.nc
  
  // Switch the SHT11 on and off, and handle the 11ms warmup delay
  module HplSensirionSht11P {
    // The SplitControl interface powers the SHT11 on or off (it's automatically
    // called by the SHT11 power manager, see HplSensirionSht11C)
    // We use a SplitControl interface as we need to wait 11ms for the sensor to
    // warm up
    provides interface SplitControl;
    uses interface Timer<TMilli>;
    uses interface GeneralIO as PWR;
    uses interface GeneralIO as DATA;
    uses interface GeneralIO as SCK;
  }
  implementation {
    task void stopTask();
  
    command error_t SplitControl.start() {
      // Power SHT11 on and wait for 11ms
      call PWR.makeOutput();
      call PWR.set();
      call Timer.startOneShot( 11 );
      return SUCCESS;
    }
    
    event void Timer.fired() {
      signal SplitControl.startDone( SUCCESS );
    }
  
    command error_t SplitControl.stop() {
      // Power the SHT11 off
      call SCK.makeInput();
      call SCK.clr();
      call DATA.makeInput();
      call DATA.clr();
      call PWR.clr();
      post stopTask();
      return SUCCESS;
    }
  
    task void stopTask() {
      signal SplitControl.stopDone( SUCCESS );
    }
  }

4. MDA100 Sensor Board Directory Organization
---------------------------------------------

Here we show the organization of the sensor board directory for the
mica-family Xbow MDA100CA and MDA100CB sensor boards, which have
temperature and light sensors. It is found in
``tos/sensorboards/mda100``::

  ./tos/sensorboards/mda100:
  .sensor					# Compiler configuration
  ArbitratedPhotoDeviceP.nc			# Light sensor support component
  ArbitratedTempDeviceP.nc			# Temperature sensor support component
  DemoSensorC.nc				# Override TinyOS's default sensor
  PhotoC.nc					# Light sensor HIL
  PhotoImplP.nc					# Light sensor support component
  PhotoTempConfigC.nc				# Shared support component
  PhotoTempConfigP.nc				# Shared support component
  SharedAnalogDeviceC.nc			# Shared support component
  SharedAnalogDeviceP.nc			# Shared support component
  TempC.nc					# Temperature Sensor HIL
  ca/TempImplP.nc				# Temperature sensor support component
  						# (MDA100CA board)
  cb/TempImplP.nc				# Temperature sensor support component
  						# (MDA100CB board)
  mda100.h					# Header file for mda100

This sensor board provides only a HIL (PhotoC and TempC components), and overrides the
TinyOS demo sensor (DemoSensorC). The demo sensor is an alias for PhotoC.

The two forms of the mda100 differ only by the wiring of the
temperature sensor.  The user has to specify which form of the sensor
board is in use by providing a ``-I%T/sensorboards/mda100/ca`` or
``-I%T/sensorboards/mda100/cb`` compiler option.

This sensor board relies on a platform-provided ``MicaBusC`` component
that specifies how the mica-family sensor board bus is connected to
the microcontroller.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -