Hi Jung,

My advice is to use individual interface, especially for small number of
interfaces. You'll reduce bug, and its easier to read.

But for the sake of learning parameterized interface in nesC, here's the
modified Blink application (taken from TOS1/apps/Blink).
---------------------------
Blink.nc:
configuration Blink {
}
implementation {
  components Main, BlinkM, TimerC, LedsC;
  Main.StdControl -> TimerC.StdControl;
  Main.StdControl -> BlinkM.StdControl;

  BlinkM.Timer[0] -> TimerC.Timer[unique("Timer")];
  BlinkM.Timer[1] -> TimerC.Timer[unique("Timer")];
  BlinkM.Timer[2] -> TimerC.Timer[unique("Timer")];

  BlinkM.Leds -> LedsC;
}
---------------------------
BlinkM.nc:
module BlinkM {
  provides {
    interface StdControl;
  }
  uses {
    interface Timer[uint8_t id];
    interface Leds;
  }
}
implementation {

  enum {
    RED_LED    = 0,
    YELLOW_LED = 1,
    GREEN_LED  = 2
  };

  /**
   * Initialize the component.
   * 
   * @return Always returns <code>SUCCESS</code>
   **/
  command result_t StdControl.init() {
    call Leds.init(); 
    return SUCCESS;
  }

  /**
   * Start things up.  This just sets the rate for the clock component.
   * 
   * @return Always returns <code>SUCCESS</code>
   **/
  command result_t StdControl.start() {
    // Start a repeating timer that fires every 1000ms
    call Timer.start[RED_LED](TIMER_REPEAT, 250);
    call Timer.start[YELLOW_LED](TIMER_REPEAT, 500);
    call Timer.start[GREEN_LED](TIMER_REPEAT, 1000);

    return SUCCESS;
  }

  /**
   * Halt execution of the application.
   * This just disables the clock component.
   * 
   * @return Always returns <code>SUCCESS</code>
   **/
  command result_t StdControl.stop() {
    call Timer.stop[RED_LED]();
    call Timer.stop[YELLOW_LED]();
    call Timer.stop[GREEN_LED]();

    return SUCCESS;
  }

  /**
   * Toggle the red LED in response to the 
   * <code>Timer.fired</code> event.
   *
   * @return Always returns <code>SUCCESS</code>
   **/
  event result_t Timer.fired[uint8_t id]()
  {
    if (id == RED_LED) {
      call Leds.redToggle();
    } else 
      if (id == YELLOW_LED) {
        call Leds.yellowToggle();
      } else 
        if (id == GREEN_LED) {
          call Leds.greenToggle();
        }

    return SUCCESS;
  }

  default command result_t Timer.start[uint8_t id]
                                  (char type, uint32_t interval)
  {
    return FAIL;
  }
}
---------------------------
Makefile:
COMPONENT=Blink
include $(MAKERULES)
---------------------------

Please use it at your own risk. Hope it helps.

Regards,
-daniel

On Mon, 2008-04-07 at 11:03 +0000, JungDoyeong wrote:
> 
> 
> Hi~daniel??
> First of all , Thanks so much for your fast reply.
> I don't want to bother you. But I have a further question about this.
>  
> Actually, I've got the point of yours.
>  
> The fact is I need to parameterized interface. and I need to know how
> to use it.
>  
> Let me explain the why I need it.
>  
> enum{AckOne=0,AckTwo=1,...};
>  
> configuration A{
>  
>   }
>  
> { components TimerC, ...,..., ;
>  
>  BeaconMoteM.Ack[AckOne] -> TimerC.Timer[unique("Timer")];
>  BeaconMoteM.Ack[AckTwo] -> TimerC.Timer[unique("Timer")];
>  BeaconMoteM.Ack[AckThree] -> TimerC.Timer[unique("Timer")];
>  BeaconMoteM.Ack[AckFour] -> TimerC.Timer[unique("Timer")];
> }
>  
> module A{
>  
>  uses interface Timer Ack[4];
>  
> }
>  
> Originally, I need parameterized interace with Timer interface type.
>  
> I want to start and stop the timer by Ack[index] indivisually. by
> not unique interface instance name one by one.
>  
> That's why I need parameterized interface.
>  
> The Reference manual of nesC v1.1 says that you can use interface
> SendMsg S[uint8_t id ] as a parameter interface
>  
> instead of interface X  as Y as simple interface. 
> 
> Is there a way to call start function of the timer by index of
> Ack[index]. not acktimer1 or acktimer2.
>  
> like these one, call Ack[index].start (.....) or call
> Ack.start[index](.........).
>  
> I'm not sure that it is enough for you to understand what I want.
>  
> Thanks for your reply again.
>  
> With regards
>  
> Jung   



_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to