Hi Jing,
On Monday 07 May 2007 02:18, liangjing wrote:
> Thank you for your reply. And I have some doubt about the interface
> Int. The demo gives some code defining command Init.init() and async
> event void Int.fired(),but I still don't know how to trigger the
> event, and I don't find it in the configuration file either. Could you
> help me explain it further?
Perhaps I misunderstood what you wanted to do? I though you wanted to perform
some action when a button on the mote was pressed. Therefore, Int.fired() is
signalled by the button. Have you read TEP 117? It describes how TinyOS
handles low level IO and is available as a link from the www.tinyos.net home
page. If it is unclear, perhaps you should make a test program out of the
code snippet and do some experimentation on your own.
Here's a summary of what the code snippet I sent is doing:
HplMsp430GeneralIOC provides an msp430 specific interface for every digital IO
available on the uC hardware. HplMsp430InterruptC provides an msp430
specific interface for every digital IO which is capable of generating an
interrupt on state change of its pin.
The example assumes the button is connected to the msp430's P2.0 pin, which is
associated with bit 0 of port 2 of the msp430 (sometimes called port20 or
port2.0, etc.). The physical button is configured such that the button
presents an active high state to the pin normally and active low when the
button is pressed. The hardware could be configured differently, of course.
SomeButtonC instantiates one each of GeneralIOC (Pin) and GpioInterruptC (Int)
components that convert the respective msp430 specific interfaces into
platform independent ones.
The boot process calls SomeButtonP's Init.init(), which configures the iopin.
This function first makes the iopin an input, then sets the interrupt to fire
on its rising edge (i.e. a low to high transition of the pin's input state).
Given the hardware assumption above, this means the interrupt actually fires
as the button is released.
Code present in core TinyOS and the configuration in SomeButtonC ensure that
when the interrupt is fired, the SomeButtonP's Int.fired() event is
signalled. This code can then deal with the event as is appropriate for the
application.
Steve
> 2007/4/30, Steve McKown <[EMAIL PROTECTED]>:
> > Hi Jing,
> >
> > On Monday 30 April 2007 01:13, liangjing wrote:
> > > In the experiment we want to trigger an event or task that implement
> > > the related work after switching off the button ? I don't know if
> > > there exists an interrupt procedure in Tinyos since I don't find some
> > > app using the kind of interrupt.Please help me.
> >
> > In tos, to handle an interrupt from a button, create and configure a
> > GpioInterrupt component and wire it to the io pin to which the button is
> > attached. Here's an example for msp430 platform where the button is
> > connected to port 2.0 of the uC. Other arches are probably similar.
> >
> > configuration SomeButtonC {
> > provides interface Init;
> > provides interface ...
> > }
> > implementation
> > {
> > components SomeButtonP;
> > Init = SomeButtonP;
> >
> > components HplMsp430GeneralIOC, new Msp430GpioC() as UserImpl;
> > UserImpl -> HplMsp430GeneralIOC.Port20;
> > SomeButtonP.Pin = UserImpl;
> >
> > components HplMsp430InterruptC, new Msp430InterruptC() as UserInt;
> > UserInt.HplInterrupt -> HplMsp430InterruptC.Port20;
> > SomeButtonP.Int = UserInt;
> > }
> >
> > And the module code...
> >
> > module SomeButtonP {
> > uses interface GeneralIO as Pin;
> > uses interface GpioInterrupt as Int;
> > provides interface Init;
> > provides interface ...
> > }
> > implementation {
> > command error_t Init.init()
> > {
> > call Pin.makeInput();
> > call Int.enableRisingEdge();
> > return SUCCESS;
> > }
> >
> > async event void Int.fired()
> > {
> > /* deal with button interrupt here, for example:
> > signal SomeInterface.button();
> > or
> > post buttonFired();
> > etc.
> > */
> > }
> > }
> >
> > You should think carefully about what constitutes a valid interrupt from
> > a user button. For simple "command type" user buttons, I usually disable
> > the interrupt as soon as one is received (in Int.fired or its call
> > chain), then have the higher level code re-enable the interrupt when it
> > is prepared to service another button press.
> >
> > Steve
>
> !DSPAM:463f2835136641565118635!
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help