You should make sure that you don't call Resource.request() while
you're still owner. You could do it by keeping state in some module
variable, but you could also do it through "if (!call
Resource.isOwner()) call Resource.request();" in your Timer.fired().
Note that this means, that your samples might not be taken at regular
intervals (you lose a sample when isOwner() returns FALSE)
Jan
On Fri, Mar 28, 2008 at 2:37 PM, Sandip Bapat <[EMAIL PROTECTED]> wrote:
> Jan
>
> I was posting a task since I didn't know whether it was safe to call release
> from within granted. After your reply, I changed the code to call release
> directly at 3 places, once in dataReady() and once each if either configure
> or getData fails. However I still see the same lockup after some time with
> Resource returning EBUSY.
>
> Also, in my real application I would like to use multiple ADC clients, but
> for the purpose of debugging, I used just one client and still observed this
> problem.
>
> I also tried sampling at 50Hz and observed the problem.
>
> I've included the new code below:
>
>
> event Timer.fired(){ // this fires every 6ms
> result = call Resource.request(); // returns SUCCESS upto some
> non-deterministic time, during which Resource is granted and I can read ADC
> correctly, after which always returns EBUSY, no more Resource.granted events
> are signalled
> }
>
>
> task void processData(){
> .. send samples to UART
> }
>
> event Resource.granted(){
> if (MultiChannel.configure(&config, &memCtl, 1, buffer, BUFFER_SIZE, 0)
> == SUCCESS)
> if (call MultiChannel.getData() != SUCCESS)
> call Resource.release();
> else
> call Resource.release();
>
> }
>
> event MultiChannel.dataReady(bufptr){
> call Resource.release();
> ...make local copy;
> post processData();
> }
>
> Thank you
> Sandip
>
>
>
> ----- Original Message ----
> From: Jan Hauer <[EMAIL PROTECTED]>
> To: Sandip Bapat <[EMAIL PROTECTED]>
> Cc: [email protected]
> Sent: Thursday, March 27, 2008 2:35:49 PM
> Subject: Re: [Tinyos-help] Resource.reserve returns EBUSY forever after some
> time
>
> You post a task to release the resource but at the same time have a
> periodic timer that requests it, so there is a race condition (your
> task can release it just after you requested it and you'll not get a
> granted). The idea of the Resource interface is that while you want to
> access the resource you must own it (must have been granted it). After
> you are finished accessing the resource you can release it. The right
> place for calling release is often in dataReady() when you're done or
> in granted() when something with the configuration fails. In your case
> if your component is the only client to the ADC then you can call
> Resource.request() in Boot.booted(), continue in granted() and never
> worry about the Resource interface again (ie. no need to call
> release()).
>
> Jan
>
>
>
>
> ____________________________________________________________________________________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile. Try it now.
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help