}
}
implementation {
- error_t amRadioStart() @C() @spontaneous() {
+ error_t amRadioStart() @C() AT_SPONTANEOUS {
return call BlockingStdControl.start();
}
- error_t amRadioStop() @C() @spontaneous() {
+ error_t amRadioStop() @C() AT_SPONTANEOUS {
return call BlockingStdControl.stop();
}
- error_t amRadioReceive(message_t* m, uint32_t timeout, am_id_t amId) @C() @spontaneous() {
+ error_t amRadioReceive(message_t* m, uint32_t timeout, am_id_t amId) @C() AT_SPONTANEOUS {
if(amId == AM_RECEIVE_FROM_ANY)
return call BlockingReceiveAny.receive(m, timeout);
else
return call BlockingReceive.receive[amId](m, timeout);
}
- error_t amRadioSnoop(message_t* m, uint32_t timeout, am_id_t amId) @C() @spontaneous() {
+ error_t amRadioSnoop(message_t* m, uint32_t timeout, am_id_t amId) @C() AT_SPONTANEOUS {
if(amId == AM_RECEIVE_FROM_ANY)
return call BlockingSnoopAny.receive(m, timeout);
else
return call BlockingSnoop.receive[amId](m, timeout);
}
- error_t amRadioSend(am_addr_t addr, message_t* msg, uint8_t len, am_id_t amId) @C() @spontaneous() {
+ error_t amRadioSend(am_addr_t addr, message_t* msg, uint8_t len, am_id_t amId) @C() AT_SPONTANEOUS {
return call Send.send[amId](addr, msg, len);
}
- am_addr_t amRadioGetLocalAddress() @C() @spontaneous() {
+ am_addr_t amRadioGetLocalAddress() @C() AT_SPONTANEOUS {
return call AMPacket.address();
}
- am_group_t amRadioGetLocalGroup() @C() @spontaneous() {
+ am_group_t amRadioGetLocalGroup() @C() AT_SPONTANEOUS {
return call AMPacket.localGroup();
}
- am_addr_t amRadioGetDestination(message_t* amsg) @C() @spontaneous() {
+ am_addr_t amRadioGetDestination(message_t* amsg) @C() AT_SPONTANEOUS {
return call AMPacket.destination(amsg);
}
- am_addr_t amRadioGetSource(message_t* amsg) @C() @spontaneous() {
+ am_addr_t amRadioGetSource(message_t* amsg) @C() AT_SPONTANEOUS {
return call AMPacket.source(amsg);
}
- void amRadioSetDestination(message_t* amsg, am_addr_t addr) @C() @spontaneous() {
+ void amRadioSetDestination(message_t* amsg, am_addr_t addr) @C() AT_SPONTANEOUS {
call AMPacket.setDestination(amsg, addr);
}
- void amRadioSetSource(message_t* amsg, am_addr_t addr) @C() @spontaneous() {
+ void amRadioSetSource(message_t* amsg, am_addr_t addr) @C() AT_SPONTANEOUS {
call AMPacket.setSource(amsg, addr);
}
- bool amRadioIsForMe(message_t* amsg) @C() @spontaneous() {
+ bool amRadioIsForMe(message_t* amsg) @C() AT_SPONTANEOUS {
return call AMPacket.isForMe(amsg);
}
- am_id_t amRadioGetType(message_t* amsg) @C() @spontaneous() {
+ am_id_t amRadioGetType(message_t* amsg) @C() AT_SPONTANEOUS {
return call AMPacket.type(amsg);
}
- void amRadioSetType(message_t* amsg, am_id_t t) @C() @spontaneous() {
+ void amRadioSetType(message_t* amsg, am_id_t t) @C() AT_SPONTANEOUS {
call AMPacket.setType(amsg, t);
}
- am_group_t amRadioGetGroup(message_t* amsg) @C() @spontaneous() {
+ am_group_t amRadioGetGroup(message_t* amsg) @C() AT_SPONTANEOUS {
return call AMPacket.group(amsg);
}
- void amRadioSetGroup(message_t* amsg, am_group_t grp) @C() @spontaneous() {
+ void amRadioSetGroup(message_t* amsg, am_group_t grp) @C() AT_SPONTANEOUS {
call AMPacket.setGroup(amsg, grp);
}
- void radioClear(message_t* msg) @C() @spontaneous() {
+ void radioClear(message_t* msg) @C() AT_SPONTANEOUS {
call Packet.clear(msg);
}
- uint8_t radioGetPayloadLength(message_t* msg) @C() @spontaneous() {
+ uint8_t radioGetPayloadLength(message_t* msg) @C() AT_SPONTANEOUS {
return call Packet.payloadLength(msg);
}
- void radioSetPayloadLength(message_t* msg, uint8_t len) @C() @spontaneous() {
+ void radioSetPayloadLength(message_t* msg, uint8_t len) @C() AT_SPONTANEOUS {
call Packet.setPayloadLength(msg, len);
}
- uint8_t radioMaxPayloadLength() @C() @spontaneous() {
+ uint8_t radioMaxPayloadLength() @C() AT_SPONTANEOUS {
return call Packet.maxPayloadLength();
}
- void* radioGetPayload(message_t* msg, uint8_t len) @C() @spontaneous() {
+ void* radioGetPayload(message_t* msg, uint8_t len) @C() AT_SPONTANEOUS {
return call Packet.getPayload(msg, len);
}
- error_t radioRequestAck( message_t* msg ) @C() @spontaneous() {
+ error_t radioRequestAck( message_t* msg ) @C() AT_SPONTANEOUS {
return call PacketAcknowledgements.requestAck(msg);
}
- error_t radioNoAck( message_t* msg ) @C() @spontaneous() {
+ error_t radioNoAck( message_t* msg ) @C() AT_SPONTANEOUS {
return call PacketAcknowledgements.noAck(msg);
}
- bool radioWasAcked(message_t* msg) @C() @spontaneous() {
+ bool radioWasAcked(message_t* msg) @C() AT_SPONTANEOUS {
return call PacketAcknowledgements.wasAcked(msg);
}
}
}
}
implementation {
- error_t amSerialStart() @C() @spontaneous() {
+ error_t amSerialStart() @C() AT_SPONTANEOUS {
return call BlockingStdControl.start();
}
- error_t amSerialStop() @C() @spontaneous() {
+ error_t amSerialStop() @C() AT_SPONTANEOUS {
return call BlockingStdControl.stop();
}
- error_t amSerialReceive(message_t* m, uint32_t timeout, am_id_t amId) @C() @spontaneous() {
+ error_t amSerialReceive(message_t* m, uint32_t timeout, am_id_t amId) @C() AT_SPONTANEOUS {
if(amId == AM_RECEIVE_FROM_ANY)
return call BlockingReceiveAny.receive(m, timeout);
else
return call BlockingReceive.receive[amId](m, timeout);
}
- error_t amSerialSend(am_addr_t addr, message_t* msg, uint8_t len, am_id_t amId) @C() @spontaneous() {
+ error_t amSerialSend(am_addr_t addr, message_t* msg, uint8_t len, am_id_t amId) @C() AT_SPONTANEOUS {
return call Send.send[amId](addr, msg, len);
}
- am_addr_t amSerialLocalAddress() @C() @spontaneous() {
+ am_addr_t amSerialLocalAddress() @C() AT_SPONTANEOUS {
return call AMPacket.address();
}
- am_group_t amSerialGetLocalGroup() @C() @spontaneous() {
+ am_group_t amSerialGetLocalGroup() @C() AT_SPONTANEOUS {
return call AMPacket.localGroup();
}
- am_addr_t amSerialGetDestination(message_t* amsg) @C() @spontaneous() {
+ am_addr_t amSerialGetDestination(message_t* amsg) @C() AT_SPONTANEOUS {
return call AMPacket.destination(amsg);
}
- am_addr_t amSerialGetSource(message_t* amsg) @C() @spontaneous() {
+ am_addr_t amSerialGetSource(message_t* amsg) @C() AT_SPONTANEOUS {
return call AMPacket.source(amsg);
}
- void amSerialSetDestination(message_t* amsg, am_addr_t addr) @C() @spontaneous() {
+ void amSerialSetDestination(message_t* amsg, am_addr_t addr) @C() AT_SPONTANEOUS {
call AMPacket.setDestination(amsg, addr);
}
- void amSerialSetSource(message_t* amsg, am_addr_t addr) @C() @spontaneous() {
+ void amSerialSetSource(message_t* amsg, am_addr_t addr) @C() AT_SPONTANEOUS {
call AMPacket.setSource(amsg, addr);
}
- bool amSerialIsForMe(message_t* amsg) @C() @spontaneous() {
+ bool amSerialIsForMe(message_t* amsg) @C() AT_SPONTANEOUS {
return call AMPacket.isForMe(amsg);
}
- am_id_t amSerialGetType(message_t* amsg) @C() @spontaneous() {
+ am_id_t amSerialGetType(message_t* amsg) @C() AT_SPONTANEOUS {
return call AMPacket.type(amsg);
}
- void amSerialSetType(message_t* amsg, am_id_t t) @C() @spontaneous() {
+ void amSerialSetType(message_t* amsg, am_id_t t) @C() AT_SPONTANEOUS {
call AMPacket.setType(amsg, t);
}
- am_group_t amSerialGetGroup(message_t* amsg) @C() @spontaneous() {
+ am_group_t amSerialGetGroup(message_t* amsg) @C() AT_SPONTANEOUS {
return call AMPacket.group(amsg);
}
- void amSerialSetGroup(message_t* amsg, am_group_t grp) @C() @spontaneous() {
+ void amSerialSetGroup(message_t* amsg, am_group_t grp) @C() AT_SPONTANEOUS {
call AMPacket.setGroup(amsg, grp);
}
- void serialClear(message_t* msg) @C() @spontaneous() {
+ void serialClear(message_t* msg) @C() AT_SPONTANEOUS {
call Packet.clear(msg);
}
- uint8_t serialGetPayloadLength(message_t* msg) @C() @spontaneous() {
+ uint8_t serialGetPayloadLength(message_t* msg) @C() AT_SPONTANEOUS {
return call Packet.payloadLength(msg);
}
- void serialSetPayloadLength(message_t* msg, uint8_t len) @C() @spontaneous() {
+ void serialSetPayloadLength(message_t* msg, uint8_t len) @C() AT_SPONTANEOUS {
call Packet.setPayloadLength(msg, len);
}
- uint8_t serialMaxPayloadLength() @C() @spontaneous() {
+ uint8_t serialMaxPayloadLength() @C() AT_SPONTANEOUS {
return call Packet.maxPayloadLength();
}
- void* serialGetPayload(message_t* msg, uint8_t len) @C() @spontaneous() {
+ void* serialGetPayload(message_t* msg, uint8_t len) @C() AT_SPONTANEOUS {
return call Packet.getPayload(msg, len);
}
- error_t serialRequestAck( message_t* msg ) @C() @spontaneous() {
+ error_t serialRequestAck( message_t* msg ) @C() AT_SPONTANEOUS {
return call PacketAcknowledgements.requestAck(msg);
}
- error_t serialNoAck( message_t* msg ) @C() @spontaneous() {
+ error_t serialNoAck( message_t* msg ) @C() AT_SPONTANEOUS {
return call PacketAcknowledgements.noAck(msg);
}
- bool serialWasAcked(message_t* msg) @C() @spontaneous() {
+ bool serialWasAcked(message_t* msg) @C() AT_SPONTANEOUS {
return call PacketAcknowledgements.wasAcked(msg);
}
}
}
implementation {
- error_t volumeBlockRead(uint8_t volumeId, storage_addr_t addr, void* buf, storage_len_t* len) @C() @spontaneous()
+ error_t volumeBlockRead(uint8_t volumeId, storage_addr_t addr, void* buf, storage_len_t* len) @C() AT_SPONTANEOUS
{
return call BlockingBlock.read[volumeId](addr, buf, len);
}
- error_t volumeBlockWrite(uint8_t volumeId, storage_addr_t addr, void* buf, storage_len_t* len) @C() @spontaneous()
+ error_t volumeBlockWrite(uint8_t volumeId, storage_addr_t addr, void* buf, storage_len_t* len) @C() AT_SPONTANEOUS
{
return call BlockingBlock.write[volumeId](addr, buf, len);
}
- error_t volumeBlockCrc(uint8_t volumeId, storage_addr_t addr, storage_len_t* len, uint16_t crc, uint16_t *finalCrc) @C() @spontaneous()
+ error_t volumeBlockCrc(uint8_t volumeId, storage_addr_t addr, storage_len_t* len, uint16_t crc, uint16_t *finalCrc) @C() AT_SPONTANEOUS
{
return call BlockingBlock.computeCrc[volumeId](addr, len, crc, finalCrc);
}
- error_t volumeBlockErase(uint8_t volumeId) @C() @spontaneous()
+ error_t volumeBlockErase(uint8_t volumeId) @C() AT_SPONTANEOUS
{
return call BlockingBlock.erase[volumeId]();
}
- error_t volumeBlockSync(uint8_t volumeId) @C() @spontaneous()
+ error_t volumeBlockSync(uint8_t volumeId) @C() AT_SPONTANEOUS
{
return call BlockingBlock.sync[volumeId]();
}
}
}
implementation {
- void led0On() @C() @spontaneous(){
+ void led0On() @C() AT_SPONTANEOUS {
call Leds.led0On();
}
- void led0Off() @C() @spontaneous(){
+ void led0Off() @C() AT_SPONTANEOUS {
call Leds.led0Off();
}
- void led0Toggle() @C() @spontaneous(){
+ void led0Toggle() @C() AT_SPONTANEOUS{
call Leds.led0Toggle();
}
- void led1On() @C() @spontaneous(){
+ void led1On() @C() AT_SPONTANEOUS{
call Leds.led1On();
}
- void led1Off() @C() @spontaneous(){
+ void led1Off() @C() AT_SPONTANEOUS{
call Leds.led1Off();
}
- void led1Toggle() @C() @spontaneous(){
+ void led1Toggle() @C() AT_SPONTANEOUS{
call Leds.led1Toggle();
}
- void led2On() @C() @spontaneous(){
+ void led2On() @C() AT_SPONTANEOUS{
call Leds.led2On();
}
- void led2Off() @C() @spontaneous(){
+ void led2Off() @C() AT_SPONTANEOUS{
call Leds.led2Off();
}
- void led2Toggle() @C() @spontaneous(){
+ void led2Toggle() @C() AT_SPONTANEOUS{
call Leds.led2Toggle();
}
- uint8_t getLeds() @C() @spontaneous(){
+ uint8_t getLeds() @C() AT_SPONTANEOUS{
return call Leds.get();
}
- void setLeds(uint8_t val) @C() @spontaneous(){
+ void setLeds(uint8_t val) @C() AT_SPONTANEOUS{
call Leds.set(val);
}
}
uses interface LinkedList;
}
implementation {
- void linked_list_init(linked_list_t* l) @C() @spontaneous() {
+ void linked_list_init(linked_list_t* l) @C() AT_SPONTANEOUS {
call LinkedList.init(l);
}
- void linked_list_clear(linked_list_t* l) @C() @spontaneous() {
+ void linked_list_clear(linked_list_t* l) @C() AT_SPONTANEOUS {
call LinkedList.clear(l);
}
- uint8_t linked_list_size(linked_list_t* l) @C() @spontaneous() {
+ uint8_t linked_list_size(linked_list_t* l) @C() AT_SPONTANEOUS {
return call LinkedList.size(l);
}
- error_t linked_list_addFirst(linked_list_t* l, list_element_t* e) @C() @spontaneous() {
+ error_t linked_list_addFirst(linked_list_t* l, list_element_t* e) @C() AT_SPONTANEOUS {
return call LinkedList.addFirst(l, e);
}
- list_element_t* linked_list_getFirst(linked_list_t* l) @C() @spontaneous() {
+ list_element_t* linked_list_getFirst(linked_list_t* l) @C() AT_SPONTANEOUS {
return call LinkedList.getFirst(l);
}
- list_element_t* linked_list_removeFirst(linked_list_t* l) @C() @spontaneous() {
+ list_element_t* linked_list_removeFirst(linked_list_t* l) @C() AT_SPONTANEOUS {
return call LinkedList.removeFirst(l);
}
- error_t linked_list_addLast(linked_list_t* l, list_element_t* e) @C() @spontaneous() {
+ error_t linked_list_addLast(linked_list_t* l, list_element_t* e) @C() AT_SPONTANEOUS {
return call LinkedList.addLast(l, e);
}
- list_element_t* linked_list_getLast(linked_list_t* l) @C() @spontaneous() {
+ list_element_t* linked_list_getLast(linked_list_t* l) @C() AT_SPONTANEOUS {
return call LinkedList.getLast(l);
}
- list_element_t* linked_list_removeLast(linked_list_t* l) @C() @spontaneous() {
+ list_element_t* linked_list_removeLast(linked_list_t* l) @C() AT_SPONTANEOUS {
return call LinkedList.removeLast(l);
}
- error_t linked_list_addAt(linked_list_t* l, list_element_t* e, uint8_t i) @C() @spontaneous() {
+ error_t linked_list_addAt(linked_list_t* l, list_element_t* e, uint8_t i) @C() AT_SPONTANEOUS {
return call LinkedList.addAt(l, e, i);
}
- list_element_t* linked_list_getAt(linked_list_t* l, uint8_t i) @C() @spontaneous() {
+ list_element_t* linked_list_getAt(linked_list_t* l, uint8_t i) @C() AT_SPONTANEOUS {
return call LinkedList.getAt(l, i);
}
- list_element_t* linked_list_removeAt(linked_list_t* l, uint8_t i) @C() @spontaneous() {
+ list_element_t* linked_list_removeAt(linked_list_t* l, uint8_t i) @C() AT_SPONTANEOUS {
return call LinkedList.removeAt(l, i);
}
- error_t linked_list_addAfter(linked_list_t* l, list_element_t* first, list_element_t* second) @C() @spontaneous() {
+ error_t linked_list_addAfter(linked_list_t* l, list_element_t* first, list_element_t* second) @C() AT_SPONTANEOUS {
return call LinkedList.addAfter(l, first, second);
}
- error_t linked_list_addBefore(linked_list_t* l, list_element_t* first, list_element_t* e) @C() @spontaneous() {
+ error_t linked_list_addBefore(linked_list_t* l, list_element_t* first, list_element_t* e) @C() AT_SPONTANEOUS {
return call LinkedList.addBefore(l, first, e);
}
- list_element_t* linked_list_getAfter(linked_list_t* l, list_element_t* e) @C() @spontaneous() {
+ list_element_t* linked_list_getAfter(linked_list_t* l, list_element_t* e) @C() AT_SPONTANEOUS {
return call LinkedList.getAfter(l, e);
}
- list_element_t* linked_list_getBefore(linked_list_t* l, list_element_t* e) @C() @spontaneous() {
+ list_element_t* linked_list_getBefore(linked_list_t* l, list_element_t* e) @C() AT_SPONTANEOUS {
return call LinkedList.getBefore(l, e);
}
- list_element_t* linked_list_remove(linked_list_t* l, list_element_t* e) @C() @spontaneous() {
+ list_element_t* linked_list_remove(linked_list_t* l, list_element_t* e) @C() AT_SPONTANEOUS {
return call LinkedList.remove(l, e);
}
- list_element_t* linked_list_removeBefore(linked_list_t* l, list_element_t* e) @C() @spontaneous() {
+ list_element_t* linked_list_removeBefore(linked_list_t* l, list_element_t* e) @C() AT_SPONTANEOUS {
return call LinkedList.removeBefore(l, e);
}
- list_element_t* linked_list_removeAfter(linked_list_t* l, list_element_t* e) @C() @spontaneous() {
+ list_element_t* linked_list_removeAfter(linked_list_t* l, list_element_t* e) @C() AT_SPONTANEOUS {
return call LinkedList.removeAfter(l, e);
}
- uint8_t linked_list_indexOf(linked_list_t* l, list_element_t* e) @C() @spontaneous() {
+ uint8_t linked_list_indexOf(linked_list_t* l, list_element_t* e) @C() AT_SPONTANEOUS {
return call LinkedList.indexOf(l, e);
}
}
}
}
implementation {
- error_t volumeLogRead(uint8_t volumeId, void *buf, storage_len_t *len) @C() @spontaneous() {
+ error_t volumeLogRead(uint8_t volumeId, void *buf, storage_len_t *len) @C() AT_SPONTANEOUS {
return call BlockingLog.read[volumeId](buf, len);
}
- storage_cookie_t volumeLogCurrentReadOffset(uint8_t volumeId) @C() @spontaneous() {
+ storage_cookie_t volumeLogCurrentReadOffset(uint8_t volumeId) @C() AT_SPONTANEOUS {
return call BlockingLog.currentReadOffset[volumeId]();
}
- error_t volumeLogSeek(uint8_t volumeId, storage_cookie_t offset) @C() @spontaneous() {
+ error_t volumeLogSeek(uint8_t volumeId, storage_cookie_t offset) @C() AT_SPONTANEOUS {
return call BlockingLog.seek[volumeId](offset);
}
- storage_len_t volumeLogGetSize(uint8_t volumeId) @C() @spontaneous() {
+ storage_len_t volumeLogGetSize(uint8_t volumeId) @C() AT_SPONTANEOUS {
return call BlockingLog.getSize[volumeId]();
}
- error_t volumeLogAppend(uint8_t volumeId, void* buf, storage_len_t *len, bool *recordsLost) @C() @spontaneous() {
+ error_t volumeLogAppend(uint8_t volumeId, void* buf, storage_len_t *len, bool *recordsLost) @C() AT_SPONTANEOUS {
return call BlockingLog.append[volumeId](buf, len, recordsLost);
}
- storage_cookie_t volumeLogCurrentWriteOffset(uint8_t volumeId) @C() @spontaneous() {
+ storage_cookie_t volumeLogCurrentWriteOffset(uint8_t volumeId) @C() AT_SPONTANEOUS {
return call BlockingLog.currentWriteOffset[volumeId]();
}
- error_t volumeLogErase(uint8_t volumeId) @C() @spontaneous() {
+ error_t volumeLogErase(uint8_t volumeId) @C() AT_SPONTANEOUS {
return call BlockingLog.erase[volumeId]();
}
- error_t volumeLogSync(uint8_t volumeId) @C() @spontaneous() {
+ error_t volumeLogSync(uint8_t volumeId) @C() AT_SPONTANEOUS {
return call BlockingLog.sync[volumeId]();
}
}
module CQueueC {}
implementation {
- void queue_init(queue_t* q) @C() @spontaneous() {
+ void queue_init(queue_t* q) @C() AT_SPONTANEOUS {
linked_list_init( &(q->l) );
}
- void queue_clear(queue_t* q) @C() @spontaneous() {
+ void queue_clear(queue_t* q) @C() AT_SPONTANEOUS {
linked_list_clear( &(q->l) );
}
- error_t queue_enqueue(queue_t* q, queue_element_t* e) @C() @spontaneous() {
+ error_t queue_enqueue(queue_t* q, queue_element_t* e) @C() AT_SPONTANEOUS {
return linked_list_addLast(&(q->l), (list_element_t*)e);
}
- queue_element_t* queue_dequeue(queue_t* q) @C() @spontaneous() {
+ queue_element_t* queue_dequeue(queue_t* q) @C() AT_SPONTANEOUS {
return (queue_element_t*)linked_list_removeFirst( &(q->l) );
}
- queue_element_t* queue_remove(queue_t* q, queue_element_t* e) @C() @spontaneous() {
+ queue_element_t* queue_remove(queue_t* q, queue_element_t* e) @C() AT_SPONTANEOUS {
return (queue_element_t*)linked_list_remove(&(q->l), (list_element_t*)e);
}
- uint8_t queue_size(queue_t* q) @C() @spontaneous() {
+ uint8_t queue_size(queue_t* q) @C() AT_SPONTANEOUS {
return linked_list_size( &(q->l) );
}
- bool queue_is_empty(queue_t* q) @C() @spontaneous() {
+ bool queue_is_empty(queue_t* q) @C() AT_SPONTANEOUS {
return (linked_list_size( &(q->l) ) == 0);
}
}
}
implementation {
- error_t tosthread_create(tosthread_t* t, void (*start_routine)(void*), void* arg, uint16_t stack_size) @C() @spontaneous() {
+ error_t tosthread_create(tosthread_t* t, void (*start_routine)(void*), void* arg, uint16_t stack_size) @C() AT_SPONTANEOUS {
return call DynamicThread.create(t, start_routine, arg, stack_size);
}
- error_t tosthread_destroy(tosthread_t* t) @C() @spontaneous() {
+ error_t tosthread_destroy(tosthread_t* t) @C() AT_SPONTANEOUS {
return call DynamicThread.destroy(t);
}
- error_t tosthread_pause(tosthread_t* t) @C() @spontaneous() {
+ error_t tosthread_pause(tosthread_t* t) @C() AT_SPONTANEOUS {
return call DynamicThread.pause(t);
}
- error_t tosthread_resume(tosthread_t* t) @C() @spontaneous() {
+ error_t tosthread_resume(tosthread_t* t) @C() AT_SPONTANEOUS {
return call DynamicThread.resume(t);
}
- error_t tosthread_sleep(uint32_t milli) @C() @spontaneous() {
+ error_t tosthread_sleep(uint32_t milli) @C() AT_SPONTANEOUS {
return call DynamicThread.sleep(milli);
}
+ error_t tosthread_join(tosthread_t* t) @C() AT_SPONTANEOUS {
+ return call DynamicThread.join(t);
+ }
}
}
implementation {
/******************** Mutex ***************************/
- void mutex_init(mutex_t* m) @C() @spontaneous() {
+ void mutex_init(mutex_t* m) @C() AT_SPONTANEOUS {
call Mutex.init(m);
}
- error_t mutex_lock(mutex_t* m) @C() @spontaneous() {
+ error_t mutex_lock(mutex_t* m) @C() AT_SPONTANEOUS {
return call Mutex.lock(m);
}
- error_t mutex_unlock(mutex_t* m) @C() @spontaneous() {
+ error_t mutex_unlock(mutex_t* m) @C() AT_SPONTANEOUS {
return call Mutex.unlock(m);
}
/******************** Semaphore ***************************/
- void semaphore_reset(semaphore_t* s, uint8_t v) @C() @spontaneous() {
+ void semaphore_reset(semaphore_t* s, uint8_t v) @C() AT_SPONTANEOUS {
call Semaphore.reset(s, v);
}
- error_t semaphore_acquire(semaphore_t* s) @C() @spontaneous() {
+ error_t semaphore_acquire(semaphore_t* s) @C() AT_SPONTANEOUS {
return call Semaphore.acquire(s);
}
- error_t semaphore_release(semaphore_t* s) @C() @spontaneous() {
+ error_t semaphore_release(semaphore_t* s) @C() AT_SPONTANEOUS {
return call Semaphore.release(s);
}
/******************** Barrier ***************************/
- void barrier_reset(barrier_t* b, uint8_t count) @C() @spontaneous() {
+ void barrier_reset(barrier_t* b, uint8_t count) @C() AT_SPONTANEOUS {
call Barrier.reset(b, count);
}
- void barrier_block(barrier_t* b) @C() @spontaneous() {
+ void barrier_block(barrier_t* b) @C() AT_SPONTANEOUS {
call Barrier.block(b);
}
- bool barrier_isBlocking(barrier_t* b) @C() @spontaneous() {
+ bool barrier_isBlocking(barrier_t* b) @C() AT_SPONTANEOUS {
return call Barrier.isBlocking(b);
}
- void condvar_init(condvar_t* c) @C() @spontaneous() {
+ void condvar_init(condvar_t* c) @C() AT_SPONTANEOUS {
call ConditionVariable.init(c);
}
/******************** Condition Variable ***************************/
- void condvar_wait(condvar_t* c, mutex_t* m) @C() @spontaneous() {
+ void condvar_wait(condvar_t* c, mutex_t* m) @C() AT_SPONTANEOUS {
call ConditionVariable.wait(c, m);
}
- void condvar_signalNext(condvar_t* c) @C() @spontaneous() {
+ void condvar_signalNext(condvar_t* c) @C() AT_SPONTANEOUS {
call ConditionVariable.signalNext(c);
}
- void condvar_signalAll(condvar_t* c) @C() @spontaneous() {
+ void condvar_signalAll(condvar_t* c) @C() AT_SPONTANEOUS {
call ConditionVariable.signalAll(c);
}
- bool condvar_isBlocking(condvar_t* c) @C() @spontaneous() {
+ bool condvar_isBlocking(condvar_t* c) @C() AT_SPONTANEOUS {
return call ConditionVariable.isBlocking(c);
}
/******************** Reference Counter ***************************/
- void refcounter_init(refcounter_t* r) @C() @spontaneous() {
+ void refcounter_init(refcounter_t* r) @C() AT_SPONTANEOUS {
call ReferenceCounter.init(r);
}
- void refcounter_increment(refcounter_t* r) @C() @spontaneous() {
+ void refcounter_increment(refcounter_t* r) @C() AT_SPONTANEOUS {
call ReferenceCounter.increment(r);
}
- void refcounter_decrement(refcounter_t* r) @C() @spontaneous() {
+ void refcounter_decrement(refcounter_t* r) @C() AT_SPONTANEOUS {
call ReferenceCounter.decrement(r);
}
- void refcounter_waitOnValue(refcounter_t* r, uint8_t count) @C() @spontaneous() {
+ void refcounter_waitOnValue(refcounter_t* r, uint8_t count) @C() AT_SPONTANEOUS {
call ReferenceCounter.waitOnValue(r, count);
}
- uint8_t refcounter_count(refcounter_t* r) @C() @spontaneous() {
+ uint8_t refcounter_count(refcounter_t* r) @C() AT_SPONTANEOUS {
return call ReferenceCounter.count(r);
}
}
#include "tosthread.h"
+#ifdef DYNTHREADS
+ #define AT_SPONTANEOUS @spontaneous()
+#else
+ #define AT_SPONTANEOUS
+#endif
+
configuration TinyOSEntryPointC {
}
implementation {
*/
extern error_t tosthread_sleep(uint32_t milli);
+/**
+ * tosthread_join(tosthread_t* t)
+ *
+ * This function bocks until the thread passed as a parameter has completed
+ *
+ * @param id The handle to the thread to block on
+ * @return An error code indicating whether the thread could be waited on or not
+ * SUCCESS - The thread has been waited on and is now completed
+ * EALREADY - The thread we are trying to wait on has already completed
+ * FAIL - The thread could not waited on
+ */
+extern error_t tosthread_join(tosthread_t* id);
+
#endif //TOSTHREAD_H_INCLUDED
* FAIL - The thread could not be put to sleep
*/
command error_t sleep(uint32_t milli);
+
+ /**
+ * join(tosthread_t* t)
+ *
+ * This function bocks until the thread passed as a parameter has completed
+ *
+ * @param id The handle to the thread to block on
+ * @return An error code indicating whether the thread could be waited on or not
+ * SUCCESS - The thread has been waited on and is now completed
+ * EALREADY - The thread we are trying to wait on has already completed
+ * FAIL - The thread could not waited on
+ */
+ command error_t join(tosthread_t* id);
}
command error_t resume();
command error_t sleep(uint32_t milli);
event void run(void* arg);
+ command error_t join();
}
#include "thread.h"
interface ThreadInfo {
+ async command error_t reset();
async command thread_t* get();
}
async command error_t interruptCurrentThread();
async command error_t wakeupThread(thread_id_t id);
+ async command error_t joinThread(thread_id_t id);
}
return call CCollectionId.fetch(id);
}
- error_t collectionSetCollectionId(uint8_t clientid, collection_id_t collectionid) @C() @spontaneous() {
+ error_t collectionSetCollectionId(uint8_t clientid, collection_id_t collectionid) @C() AT_SPONTANEOUS {
return call CCollectionId.set(clientid, collectionid);
}
- error_t collectionRoutingStart() @C() @spontaneous() {
+ error_t collectionRoutingStart() @C() AT_SPONTANEOUS {
return call RoutingControl.start();
}
- error_t collectionRoutingStop() @C() @spontaneous() {
+ error_t collectionRoutingStop() @C() AT_SPONTANEOUS {
return call RoutingControl.stop();
}
- error_t collectionReceive(message_t* m, uint32_t timeout, collection_id_t id) @C() @spontaneous() {
+ error_t collectionReceive(message_t* m, uint32_t timeout, collection_id_t id) @C() AT_SPONTANEOUS {
return call BlockingReceive.receive[id](m, timeout);
}
- error_t collectionSnoop(message_t* m, uint32_t timeout, collection_id_t id) @C() @spontaneous() {
+ error_t collectionSnoop(message_t* m, uint32_t timeout, collection_id_t id) @C() AT_SPONTANEOUS {
return call BlockingSnoop.receive[id](m, timeout);
}
- error_t collectionSend(message_t* msg, uint8_t len, uint8_t id) @C() @spontaneous() {
+ error_t collectionSend(message_t* msg, uint8_t len, uint8_t id) @C() AT_SPONTANEOUS {
return call BlockingSend.send[id](msg, len);
}
- void collectionClear(message_t* msg) @C() @spontaneous() {
+ void collectionClear(message_t* msg) @C() AT_SPONTANEOUS {
call Packet.clear(msg);
}
- uint8_t collectionGetPayloadLength(message_t* msg) @C() @spontaneous() {
+ uint8_t collectionGetPayloadLength(message_t* msg) @C() AT_SPONTANEOUS {
return call Packet.payloadLength(msg);
}
- void collectionSetPayloadLength(message_t* msg, uint8_t len) @C() @spontaneous() {
+ void collectionSetPayloadLength(message_t* msg, uint8_t len) @C() AT_SPONTANEOUS {
call Packet.setPayloadLength(msg, len);
}
- uint8_t collectionMaxPayloadLength() @C() @spontaneous() {
+ uint8_t collectionMaxPayloadLength() @C() AT_SPONTANEOUS {
return call Packet.maxPayloadLength();
}
- void* collectionGetPayload(message_t* msg, uint8_t len) @C() @spontaneous() {
+ void* collectionGetPayload(message_t* msg, uint8_t len) @C() AT_SPONTANEOUS {
return call Packet.getPayload(msg, len);
}
- am_addr_t collectionGetOrigin(message_t* msg) @C() @spontaneous() {
+ am_addr_t collectionGetOrigin(message_t* msg) @C() AT_SPONTANEOUS {
return call CollectionPacket.getOrigin(msg);
}
- void collectionSetOrigin(message_t* msg, am_addr_t addr) @C() @spontaneous() {
+ void collectionSetOrigin(message_t* msg, am_addr_t addr) @C() AT_SPONTANEOUS {
call CollectionPacket.setOrigin(msg, addr);
}
- collection_id_t collectionGetType(message_t* msg) @C() @spontaneous() {
+ collection_id_t collectionGetType(message_t* msg) @C() AT_SPONTANEOUS {
return call CollectionPacket.getType(msg);
}
- void collectionSetType(message_t* msg, collection_id_t id) @C() @spontaneous() {
+ void collectionSetType(message_t* msg, collection_id_t id) @C() AT_SPONTANEOUS {
call CollectionPacket.setType(msg, id);
}
- uint8_t collectionGetSequenceNumber(message_t* msg) @C() @spontaneous() {
+ uint8_t collectionGetSequenceNumber(message_t* msg) @C() AT_SPONTANEOUS {
return call CollectionPacket.getSequenceNumber(msg);
}
- void collectionSetSequenceNumber(message_t* msg, uint8_t seqno) @C() @spontaneous() {
+ void collectionSetSequenceNumber(message_t* msg, uint8_t seqno) @C() AT_SPONTANEOUS {
call CollectionPacket.setSequenceNumber(msg, seqno);
}
- error_t collectionSetRoot() @C() @spontaneous() {
+ error_t collectionSetRoot() @C() AT_SPONTANEOUS {
return call RootControl.setRoot();
}
- error_t collectionUnsetRoot() @C() @spontaneous() {
+ error_t collectionUnsetRoot() @C() AT_SPONTANEOUS {
return call RootControl.unsetRoot();
}
- bool collectionIsRoot() @C() @spontaneous() {
+ bool collectionIsRoot() @C() AT_SPONTANEOUS {
return call RootControl.isRoot();
}
}
return call CCollectionId.fetch(id);
}
- error_t collectionSetCollectionId(uint8_t clientid, collection_id_t collectionid) @C() @spontaneous() {
+ error_t collectionSetCollectionId(uint8_t clientid, collection_id_t collectionid) @C() AT_SPONTANEOUS {
return call CCollectionId.set(clientid, collectionid);
}
- error_t collectionRoutingStart() @C() @spontaneous() {
+ error_t collectionRoutingStart() @C() AT_SPONTANEOUS {
return call RoutingControl.start();
}
- error_t collectionRoutingStop() @C() @spontaneous() {
+ error_t collectionRoutingStop() @C() AT_SPONTANEOUS {
return call RoutingControl.stop();
}
- error_t collectionReceive(message_t* m, uint32_t timeout, collection_id_t id) @C() @spontaneous() {
+ error_t collectionReceive(message_t* m, uint32_t timeout, collection_id_t id) @C() AT_SPONTANEOUS {
return call BlockingReceive.receive[id](m, timeout);
}
- error_t collectionSnoop(message_t* m, uint32_t timeout, collection_id_t id) @C() @spontaneous() {
+ error_t collectionSnoop(message_t* m, uint32_t timeout, collection_id_t id) @C() AT_SPONTANEOUS {
return call BlockingSnoop.receive[id](m, timeout);
}
- error_t collectionSend(message_t* msg, uint8_t len, uint8_t id) @C() @spontaneous() {
+ error_t collectionSend(message_t* msg, uint8_t len, uint8_t id) @C() AT_SPONTANEOUS {
call CollectionPacket.setType(msg, call CCollectionId.fetch(id));
return call BlockingSend.send[id](msg, len);
}
- void collectionClear(message_t* msg) @C() @spontaneous() {
+ void collectionClear(message_t* msg) @C() AT_SPONTANEOUS {
call Packet.clear(msg);
}
- uint8_t collectionGetPayloadLength(message_t* msg) @C() @spontaneous() {
+ uint8_t collectionGetPayloadLength(message_t* msg) @C() AT_SPONTANEOUS {
return call Packet.payloadLength(msg);
}
- void collectionSetPayloadLength(message_t* msg, uint8_t len) @C() @spontaneous() {
+ void collectionSetPayloadLength(message_t* msg, uint8_t len) @C() AT_SPONTANEOUS {
call Packet.setPayloadLength(msg, len);
}
- uint8_t collectionMaxPayloadLength() @C() @spontaneous() {
+ uint8_t collectionMaxPayloadLength() @C() AT_SPONTANEOUS {
return call Packet.maxPayloadLength();
}
- void* collectionGetPayload(message_t* msg, uint8_t len) @C() @spontaneous() {
+ void* collectionGetPayload(message_t* msg, uint8_t len) @C() AT_SPONTANEOUS {
return call Packet.getPayload(msg, len);
}
- am_addr_t collectionGetOrigin(message_t* msg) @C() @spontaneous() {
+ am_addr_t collectionGetOrigin(message_t* msg) @C() AT_SPONTANEOUS {
return call CollectionPacket.getOrigin(msg);
}
- void collectionSetOrigin(message_t* msg, am_addr_t addr) @C() @spontaneous() {
+ void collectionSetOrigin(message_t* msg, am_addr_t addr) @C() AT_SPONTANEOUS {
call CollectionPacket.setOrigin(msg, addr);
}
- collection_id_t collectionGetType(message_t* msg) @C() @spontaneous() {
+ collection_id_t collectionGetType(message_t* msg) @C() AT_SPONTANEOUS {
return call CollectionPacket.getType(msg);
}
- void collectionSetType(message_t* msg, collection_id_t id) @C() @spontaneous() {
+ void collectionSetType(message_t* msg, collection_id_t id) @C() AT_SPONTANEOUS {
call CollectionPacket.setType(msg, id);
}
- uint8_t collectionGetSequenceNumber(message_t* msg) @C() @spontaneous() {
+ uint8_t collectionGetSequenceNumber(message_t* msg) @C() AT_SPONTANEOUS {
return call CollectionPacket.getSequenceNumber(msg);
}
- void collectionSetSequenceNumber(message_t* msg, uint8_t seqno) @C() @spontaneous() {
+ void collectionSetSequenceNumber(message_t* msg, uint8_t seqno) @C() AT_SPONTANEOUS {
call CollectionPacket.setSequenceNumber(msg, seqno);
}
- error_t collectionSetRoot() @C() @spontaneous() {
+ error_t collectionSetRoot() @C() AT_SPONTANEOUS {
return call RootControl.setRoot();
}
- error_t collectionUnsetRoot() @C() @spontaneous() {
+ error_t collectionUnsetRoot() @C() AT_SPONTANEOUS {
return call RootControl.unsetRoot();
}
- bool collectionIsRoot() @C() @spontaneous() {
+ bool collectionIsRoot() @C() AT_SPONTANEOUS {
return call RootControl.isRoot();
}
}
}
}
- int printfflush() @C() @spontaneous() {
+ int printfflush() @C() AT_SPONTANEOUS {
call Barrier.block(&flushstart_barrier);
call Barrier.reset(&flushstart_barrier, 2);
call Barrier.block(&flushdone_barrier);
}
}
implementation {
- error_t photo_read(uint16_t* val) @C() @spontaneous() {
+ error_t photo_read(uint16_t* val) @C() AT_SPONTANEOUS {
return call BlockingRead.read(val);
}
- error_t photo_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() @spontaneous() {
+ error_t photo_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() AT_SPONTANEOUS {
return call BlockingReadStream.read(usPeriod, buf, count);
}
}
}
}
implementation {
- error_t temp_read(uint16_t* val) @C() @spontaneous() {
+ error_t temp_read(uint16_t* val) @C() AT_SPONTANEOUS {
return call BlockingRead.read(val);
}
- error_t temp_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() @spontaneous() {
+ error_t temp_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() AT_SPONTANEOUS {
return call BlockingReadStream.read(usPeriod, buf, count);
}
}
}
}
implementation {
- error_t hamamatsuS10871_tsr_read(uint16_t* val) @C() @spontaneous() {
+ error_t hamamatsuS10871_tsr_read(uint16_t* val) @C() AT_SPONTANEOUS {
return call Read.read(val);
}
- error_t hamamatsuS10871_tsr_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() @spontaneous() {
+ error_t hamamatsuS10871_tsr_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() AT_SPONTANEOUS {
return call ReadStream.read(usPeriod, buf, count);
}
- uint8_t hamamatsuS10871_tsr_getNumBits() @C() @spontaneous() {
+ uint8_t hamamatsuS10871_tsr_getNumBits() @C() AT_SPONTANEOUS {
return call DeviceMetadata.getSignificantBits();
}
}
}
implementation {
- error_t hamamatsuS1087_par_read(uint16_t* val) @C() @spontaneous() {
+ error_t hamamatsuS1087_par_read(uint16_t* val) @C() AT_SPONTANEOUS {
return call Read.read(val);
}
- error_t hamamatsuS1087_par_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() @spontaneous() {
+ error_t hamamatsuS1087_par_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() AT_SPONTANEOUS {
return call ReadStream.read(usPeriod, buf, count);
}
- uint8_t hamamatsuS1087_par_getNumBits() @C() @spontaneous() {
+ uint8_t hamamatsuS1087_par_getNumBits() @C() AT_SPONTANEOUS {
return call DeviceMetadata.getSignificantBits();
}
}
}
}
implementation {
- error_t sensirionSht11_humidity_read(uint16_t* val) @C() @spontaneous() {
+ error_t sensirionSht11_humidity_read(uint16_t* val) @C() AT_SPONTANEOUS {
return call Humidity.read(val);
}
- uint8_t sensirionSht11_humidity_getNumBits() @C() @spontaneous() {
+ uint8_t sensirionSht11_humidity_getNumBits() @C() AT_SPONTANEOUS {
return call HumidityMetadata.getSignificantBits();
}
- error_t sensirionSht11_temperature_read(uint16_t* val) @C() @spontaneous() {
+ error_t sensirionSht11_temperature_read(uint16_t* val) @C() AT_SPONTANEOUS {
return call Temperature.read(val);
}
- uint8_t sensirionSht11_temperature_getNumBits() @C() @spontaneous() {
+ uint8_t sensirionSht11_temperature_getNumBits() @C() AT_SPONTANEOUS {
return call TemperatureMetadata.getSignificantBits();
}
}
}
}
implementation {
- error_t sinesensor_read(uint16_t* val) @C() @spontaneous() {
+ error_t sinesensor_read(uint16_t* val) @C() AT_SPONTANEOUS {
return call BlockingRead.read(val);
}
}
implementation {
typedef struct params {
- message_t* msg;
uint32_t* timeout;
+ message_t* msg;
error_t error;
} params_t;
BlockingResource = BlockingResourceP;
Resource = BlockingResourceP;
- components ThreadTimersC;
- BlockingResourceP.Timer -> ThreadTimersC;
+ components ThreadSleepC;
+ BlockingResourceP.ThreadSleep -> ThreadSleepC;
components SystemCallC;
components TinyThreadSchedulerC;
interface SystemCall;
interface ThreadScheduler;
interface Resource;
- interface Timer<TMilli>[uint8_t id];
+ interface ThreadSleep;
}
}
implementation {
typedef struct params {
- uint32_t* milli;
error_t error;
} params_t;
}
/************************* Timed Release *****************************/
- void timerTask(syscall_t* s) {
- params_t* p = s->params;
- call Timer.startOneShot[s->thread->id](*(p->milli));
- }
-
command error_t BlockingResource.timedRelease(uint32_t milli) {
syscall_t s;
params_t p;
resource_call = &s;
}
- if(milli != 0) {
- p.milli = &milli;
- call SystemCall.start(timerTask, &s, INVALID_ID, &p);
- }
- else {
- call SystemCall.start(releaseTask, &s, INVALID_ID, &p);
- if(p.error == SUCCESS)
- call SystemCall.start(requestTask, &s, INVALID_ID, &p);
- }
+ if(milli != 0)
+ call ThreadSleep.sleep(milli);
+
+ call SystemCall.start(releaseTask, &s, INVALID_ID, &p);
+ if(p.error == SUCCESS)
+ call SystemCall.start(requestTask, &s, INVALID_ID, &p);
atomic {
resource_call = NULL;
}
}
- event void Timer.fired[uint8_t id]() {
- thread_t* t = call ThreadScheduler.threadInfo(id);
- syscall_t* s = t->syscall;
- params_t* p = t->syscall->params;
- call SystemCall.start(releaseTask, s, INVALID_ID, p);
- if(p->error == SUCCESS)
- call SystemCall.start(requestTask, s, INVALID_ID, p);
- else call SystemCall.finish(s);
- }
-
/************************* isOwner pass through *****************************/
command error_t BlockingResource.isOwner() {
return call Resource.isOwner();
command error_t DynamicThread.sleep(uint32_t milli) {
return call ThreadSleep.sleep(milli);
}
+ command error_t DynamicThread.join(tosthread_t* t) {
+ return call ThreadScheduler.joinThread(*t);
+ }
async command thread_t* ThreadInfo.get[uint8_t id]() {
atomic return thread_info[id - TOSTHREAD_NUM_STATIC_THREADS];
}
+ async command error_t ThreadInfo.reset[uint8_t id]() {
+ return FAIL;
+ }
+
async event void ThreadCleanup.cleanup[uint8_t id]() {
signal ThreadNotification.aboutToDestroy[id]();
atomic {
thread_info->start_arg_ptr = arg;
thread_info->mutex_count = 0;
thread_info->next_thread = NULL;
- return call ThreadScheduler.initThread(id);
+ return ecombine(call ThreadInfo.reset[id](), call ThreadScheduler.initThread(id));
}
command error_t Thread.start[uint8_t id](void* arg) {
return call ThreadSleep.sleep(milli);
}
+ command error_t Thread.join[uint8_t id]() {
+ return call ThreadScheduler.joinThread(id);
+ }
+
event void ThreadFunction.signalThreadRun[uint8_t id](void *arg) {
signal Thread.run[id](arg);
}
default event void Thread.run[uint8_t id](void* arg) {}
default async command thread_t* ThreadInfo.get[uint8_t id]() {return NULL;}
+ default async command error_t ThreadInfo.reset[uint8_t id]() {return FAIL;}
default async event void ThreadNotification.justCreated[uint8_t id]() {}
default async event void ThreadNotification.aboutToDestroy[uint8_t id]() {}
signal ThreadFunction.signalThreadRun(arg);
}
- command error_t Init.init() {
+ error_t init() {
thread_info.next_thread = NULL;
thread_info.id = thread_id;
thread_info.init_block = NULL;
return SUCCESS;
}
+ command error_t Init.init() {
+ return init();
+ }
+
+ async command error_t ThreadInfo.reset() {
+ return init();
+ }
+
async command thread_t* ThreadInfo.get() {
return &thread_info;
}
async command thread_t* ThreadInfo.get[uint8_t id]() {
return call StaticThreadInfo.get[id]();
}
+ async command error_t ThreadInfo.reset[uint8_t id]() {
+ return call StaticThreadInfo.reset[id]();
+ }
default async command thread_t* StaticThreadInfo.get[uint8_t id]() {
return call DynamicThreadInfo.get[id]();
}
+ default async command error_t StaticThreadInfo.reset[uint8_t id]() {
+ return call DynamicThreadInfo.reset[id]();
+ }
default async command thread_t* DynamicThreadInfo.get[uint8_t id]() {
return call StaticThreadInfo.get[id]();
}
+ default async command error_t DynamicThreadInfo.reset[uint8_t id]() {
+ return call StaticThreadInfo.reset[id]();
+ }
async event void ThreadCleanup.cleanup[uint8_t id]() {
signal StaticThreadCleanup.cleanup[id]();
}
return SUCCESS;
}
+ //Need to add a cancel command so that components like
+ //BlockingAMReceiverImplP can use the ThreadSleep interface
+ //directly instead of reusing the underlying ThreadTimerC
+ //component. The current implementation does things this way
+ //and causes us to be defensive in here since the same
+ //TimerMilli.fired() event is sent to that component as well.
+ //Basically its just broken.... cancel() would get rid of this.
+
+ //Also need some sort of a sleepWithSyscall command
+ //Need to think about this one a little more
+
event void TimerMilli.fired[uint8_t id]() {
thread_t* t = call ThreadScheduler.threadInfo(id);
- call SystemCall.finish(t->syscall);
+ if(t->syscall->syscall_ptr == sleepTask)
+ call SystemCall.finish(t->syscall);
}
}
call TaskScheduler.taskLoop();
}
+
+ async command error_t ThreadInfo.reset() {
+ return FAIL;
+ }
async command thread_t* ThreadInfo.get() {
return &thread_info;
ThreadScheduler = Sched;
Sched.McuSleep -> Sleep;
+ components BitArrayUtilsC;
+ Sched.BitArrayUtils -> BitArrayUtilsC;
+
components ThreadQueueC;
Sched.ThreadQueue -> ThreadQueueC;
interface Boot as ThreadSchedulerBoot;
interface ThreadInfo[uint8_t id];
interface ThreadQueue;
+ interface BitArrayUtils;
interface McuSleep;
interface Leds;
interface Timer<TMilli> as PreemptionAlarm;
* threads by the thread scheduler.
*/
void stop(thread_t* t) {
+ int i;
t->state = TOSTHREAD_STATE_INACTIVE;
num_started_threads--;
+ for(i=0; i<TOSTHREAD_MAX_NUM_THREADS; i++) {
+ if(call BitArrayUtils.getBit(t->joinedOnMe, i))
+ call ThreadScheduler.wakeupThread(i);
+ }
if(num_started_threads == 1)
call PreemptionAlarm.stop();
signal ThreadCleanup.cleanup[t->id]();
thread_t* t = (call ThreadInfo.get[id]());
t->state = TOSTHREAD_STATE_INACTIVE;
t->init_block = current_thread->init_block;
+ call BitArrayUtils.clrArray(t->joinedOnMe, sizeof(t->joinedOnMe));
PREPARE_THREAD(t, threadWrapper);
return SUCCESS;
}
}
}
+ async command error_t ThreadScheduler.joinThread(thread_id_t id) {
+ thread_t* t = call ThreadInfo.get[id]();
+ atomic {
+ if(current_thread == tos_thread)
+ return FAIL;
+ if (t->state != TOSTHREAD_STATE_INACTIVE) {
+ call BitArrayUtils.setBit(t->joinedOnMe, current_thread->id);
+ call ThreadScheduler.suspendCurrentThread();
+ return SUCCESS;
+ }
+ }
+ return EALREADY;
+ }
+
async command error_t ThreadScheduler.wakeupThread(uint8_t id) {
thread_t* t = call ThreadInfo.get[id]();
if((t->state) == TOSTHREAD_STATE_SUSPENDED) {
size_t malloc_heap[MALLOC_HEAP_SIZE];
- void *tos_malloc (size_t size) @C() @spontaneous()
+ void *tos_malloc (size_t size) @C() AT_SPONTANEOUS
{
static char once = 0;
size_t * heap_bottom = &(malloc_heap[MALLOC_HEAP_SIZE]);
return NULL;
}
- void tos_free (void *p) @C() @spontaneous()
+ void tos_free (void *p) @C() AT_SPONTANEOUS
{
size_t *t = (size_t*)p - 1;
MARK_FREE (t);
};
//This is a thread data structure
-//This structure is 43 bytes long...
struct thread {
//***** next_thread must be at first position in struct for casting purposes *******
volatile struct thread* next_thread; //Pointer to next thread for use in queues when blocked
stack_ptr_t stack_ptr; //Pointer to this threads stack
volatile uint8_t state; //Current state the thread is in
volatile uint8_t mutex_count; //A reference count of the number of mutexes held by this thread
+ uint8_t joinedOnMe[(TOSTHREAD_MAX_NUM_THREADS - 1) / 8 + 1]; //Bitmask of threads waiting for me to finish
void (*start_ptr)(void*); //Pointer to the start function of this thread
void* start_arg_ptr; //Pointer to the argument passed as a parameter to the start function of this thread
syscall_t* syscall; //Pointer to an instance of a system call