Has anyone used these yet? I'm trying to create a blocking ConfigStorage
implemenation using TinyOS semaphores and I'm doing a reset in
initialization, acquire during the call of the write, and release after a
write complete.
Here is my code:
#include "Storage.h"
#include "/opt/tinyos-2.x/tos/lib/tosthreads/types/semaphore.h"
module SemaphoreConfigStorageC
{
uses
{
interface Semaphore;
interface ConfigStorage;
interface Malloc;
interface Leds;
}
provides interface SemaphoreConfigStorage;
}
implementation
{
semaphore_t* flashSem;
command error_t SemaphoreConfigStorage.initSemaphore()
{
flashSem = (semaphore_t*)call Malloc.malloc(sizeof(semaphore_t));
call Semaphore.reset(flashSem,(uint8_t)1);
return SUCCESS;
}
command error_t SemaphoreConfigStorage.read(storage_addr_t addr, void*
buf, storage_len_t len)
{
error_t err;
err = call Semaphore.acquire(flashSem);
return call ConfigStorage.read(addr,buf,len);
}
event void ConfigStorage.readDone(storage_addr_t addr, void* buf,
storage_len_t len, error_t error)
{
error_t err;
err = call Semaphore.release(flashSem);
//call Leds.led0Off();
//call Leds.led1Off();
//call Leds.led2Off();
signal SemaphoreConfigStorage.readDone(addr,buf,len,error);
}
command error_t SemaphoreConfigStorage.write(storage_addr_t addr, void*
buf, storage_len_t len)
{
error_t err;
//call Leds.led0On();
//call Leds.led1On();
//call Leds.led2On();
err = call Semaphore.acquire(flashSem);
return call ConfigStorage.write(addr,buf,len);
}
event void ConfigStorage.writeDone(storage_addr_t addr, void* buf,
storage_len_t len, error_t error)
{
error_t err;
err = call Semaphore.release(flashSem);
//call Leds.led0Off();
//call Leds.led1Off();
//call Leds.led2Off();
signal SemaphoreConfigStorage.writeDone(addr,buf,len,error);
}
command error_t SemaphoreConfigStorage.commit()
{
error_t err;
//call Leds.led0On();
//call Leds.led1On();
//call Leds.led2On();
err = call Semaphore.acquire(flashSem);
return call ConfigStorage.commit();
}
event void ConfigStorage.commitDone(error_t error)
{
error_t err;
err = call Semaphore.release(flashSem);
//call Leds.led0Off();
//call Leds.led1Off();
//call Leds.led2Off();
signal SemaphoreConfigStorage.commitDone(error);
}
command storage_len_t SemaphoreConfigStorage.getSize()
{
return call ConfigStorage.getSize();
}
command bool SemaphoreConfigStorage.valid()
{
return call ConfigStorage.valid();
}
}
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help