[Tinyos-2-commits] CVS: tinyos-2.x-contrib/stanford-sing/s4-tinyos-2.x/tos/lib/util BufferPool.nc, NONE, 1.1 Ident.nc, NONE, 1.1 IdentM.nc, NONE, 1.1 LBlink.nc, NONE, 1.1 LBlinkC.nc, NONE, 1.1 LBlinkM.nc, NONE, 1.1 Logger.nc, NONE, 1.1 Logging.h, NONE, 1.1 UARTLogger.nc, NONE, 1.1 UARTLoggerM.nc, NONE, 1.1 util.h, NONE, 1.1
Tahir Azim
genie1 at users.sourceforge.net
Thu Oct 23 15:22:43 PDT 2008
- Previous message: [Tinyos-2-commits] CVS: tinyos-2.x-contrib/stanford-sing/s4-tinyos-2.x/tos/lib/linkestimator LinkEstimator.h, NONE, 1.1 LinkEstimator.nc, NONE, 1.1 LinkEstimatorC.nc, NONE, 1.1 LinkEstimatorM.nc, NONE, 1.1 LinkEstimatorSynch.nc, NONE, 1.1 ReverseLinkInfo.h, NONE, 1.1
- Next message: [Tinyos-2-commits] CVS: tinyos-2.x-contrib/stanford-sing/s4-tinyos-2.x/apps/TestS4Simple README, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-2.x-contrib/stanford-sing/s4-tinyos-2.x/tos/lib/util
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv29813/util
Added Files:
BufferPool.nc Ident.nc IdentM.nc LBlink.nc LBlinkC.nc
LBlinkM.nc Logger.nc Logging.h UARTLogger.nc UARTLoggerM.nc
util.h
Log Message:
tos/lib Library files for S4 tinyos 2.x port.
--- NEW FILE: BufferPool.nc ---
// ex: set tabstop=2 shiftwidth=2 expandtab syn=c:
// $Id: BufferPool.nc,v 1.1 2008/10/23 22:22:41 genie1 Exp $
/*
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* Authors: Rodrigo Fonseca
* Date: 8/8/3
* Date Last Modified: 2005/05/26
*/
/*
* Buffer pool for swapping and processing of message_t buffers.
* There is also a FIFO queue that allows in-order processing.
*
* Usage in a receive cycle (in which you need swapping of buffers and
further processing):
* 0. include this file
* 1. declare a variable of type BufferPool and call bufferPoolInit()
* 2. upon receiving a buffer for processing, call bufferPoolSwap()
* swap returns a free buffer and enqueues the received buffer, setting it
* to busy.
* 3. for processing, call processNext. This returns the first enqueued, but
* does not set it as free
* 4. after processing (e.g., sendDone), call SetFree.
* This returns the buffer to the pool for other uses
* Usage if you only need to allocate and free buffers, but not swap
* 0. include this file
* 1. declare a variable of type BufferPool and call bufferPoolInit()
* 2. When a buffer is needed, call bufferPoolGetFree()
* 3. When the buffer can be freed, call bufferPoolSetFree()
*
* These methods should not be used simultaneously for a given bufferPool
* Todo: I will separate them into QueuedBufferPool and simple BufferPool
* Other limitations: size setting is global accross buffer pools. */
enum {
BUFFER_POOL_SIZE = 24,
//DBG_FLAG = DBG_NONE,
};
typedef struct {
bool busy[BUFFER_POOL_SIZE]; // flags indicating buffers in use
uint8_t num_elements; // # buffers in use
message_t buffers[BUFFER_POOL_SIZE]; // actual buffers
message_t* bufferPtrs[BUFFER_POOL_SIZE]; // pointers to the buffers
uint8_t processQueue[BUFFER_POOL_SIZE]; // queue for processing
uint8_t q_first; // first element in queue
uint8_t q_num_elements; // number of elements in queue
} BufferPool;
inline void bufferPoolDbg(BufferPool* this) {
int i;
dbg("BVR-flag","bufferPool: num_elements: %d, q_first: %d, q_num_elements:%d\n",
this->num_elements,this->q_first, this->q_num_elements);
dbg("BVR-flag","bufferPool: ");
for (i = 0; i < BUFFER_POOL_SIZE; i++) {
dbg_clear("BVR-flag","[%d]:%p (%d) ",i,this->bufferPtrs[i], this->busy[i]);
}
dbg_clear("BVR-flag","\n");
}
//Places the integer n in the first position after the last in processQueue
//returns FAIL if queue is full, SUCCESS otherwise
inline error_t bufferPoolEnqueue(BufferPool *this, uint8_t n) {
uint8_t pos;
dbg("BVR-flag","bufferPool:enqueue\n");
bufferPoolDbg(this);
if (this->q_num_elements == BUFFER_POOL_SIZE)
return FAIL;
pos = (this->q_first + this->q_num_elements) % BUFFER_POOL_SIZE;
this->processQueue[pos] = n;
this->q_num_elements++;
return SUCCESS;
}
//Attributs to *n the first position in processQueue.
//returns FAIL if the queue was empty, SUCCESS otherwise
inline error_t bufferPoolDequeue(BufferPool *this, uint8_t* n) {
if (this->q_num_elements == 0)
return FAIL;
*n = this->processQueue[this->q_first];
this->q_first = (this->q_first + 1) % BUFFER_POOL_SIZE;
this->q_num_elements--;
dbg("BVR-flag","bufferPool: dequeueing:%d elements\n",this->q_num_elements);
return SUCCESS;
}
inline uint8_t bufferPoolGetQueueSize(BufferPool *this) {
return this->q_num_elements;
}
inline uint8_t bufferPoolGetSize(BufferPool *this) {
return BUFFER_POOL_SIZE;
}
inline uint8_t bufferPoolGetNumberFree(BufferPool *this) {
return (BUFFER_POOL_SIZE - this->num_elements);
}
inline message_t* bufferPoolProcessNext(BufferPool *this) {
uint8_t n;
dbg("BVR-flag","bufferPool:processNext\n");
bufferPoolDbg(this);
if (bufferPoolDequeue(this, &n) == SUCCESS)
return this->bufferPtrs[n];
else
return NULL;
}
inline void bufferPoolInit(BufferPool* this) {
int i;
dbg("BVR-flag","bufferPool: init with size %d\n",BUFFER_POOL_SIZE);
this->num_elements = 0;
for (i = 0; i < BUFFER_POOL_SIZE; i++) {
this->bufferPtrs[i] = &this->buffers[i];
this->busy[i] = FALSE;
this->q_first = 0;
this->q_num_elements = 0;
}
bufferPoolDbg(this);
}
inline error_t bufferPoolGetFreePos(BufferPool* this, uint8_t *pos) {
int i;
uint8_t free_pos = 255;
dbg("BVR-flag","bufferPool:getFreePos\n");
bufferPoolDbg(this);
if (this->num_elements == BUFFER_POOL_SIZE) {
*pos = 0;
return FAIL;
}
for (i = 0; (i < BUFFER_POOL_SIZE) && (free_pos == 255); i++) {
if (this->busy[i] == FALSE)
free_pos = i;
}
if (free_pos == 255) {
dbg("BVR-flag","bufferPool: ERROR! inconsistent state. Did not find pos, but num_busy=%d\n",this->num_elements);
call Leds.led0On();
*pos = free_pos;
return FAIL;
} else {
dbg("BVR-flag","bufferPool: returning position %d (%p)\n",free_pos,this->bufferPtrs[free_pos]);
*pos = free_pos;
return SUCCESS;
}
}
// If there is a free position:
//
// 1. returns the buffer associated with the free position
// 2. stores the received buffer in the same position
// 3. sets the position as busy
// 4. enqueues the position in the processFifo queue
//
inline error_t bufferPoolSwap(BufferPool *this, message_t* *rcv) {
uint8_t free_pos;
message_t* temp;
dbg("BVR-flag","bufferPool:swap. received %p\n",rcv);
//return the same buffer if we don't have space
if (bufferPoolGetFreePos(this, &free_pos) == FAIL) {
dbg("BVR-flag","bufferPool: could not get free position\n");
return FAIL;
}
temp = this->bufferPtrs[free_pos];
this->bufferPtrs[free_pos] = *rcv;
this->busy[free_pos] = TRUE;
this->num_elements++;
*rcv = temp;
dbg("BVR-flag","bufferPool: swapping. rcv: %p ret: %p. num_busy:%d\n", this->bufferPtrs[free_pos], *rcv, this->num_elements);
bufferPoolEnqueue(this, free_pos);
bufferPoolDbg(this);
dbg("BVR-flag","bufferPool: enqueued:%d\n",this->q_num_elements);
return SUCCESS;
}
// If there is a free position:
//
// 1. returns the buffer associated with the free position
// 2. sets the position as busy
//
// if error_t is FAIL,
// status = 0 if buffer full
// status = 255 if buffer inconsistent
inline error_t bufferPoolGetFree(BufferPool *this, message_t* *buffer, uint8_t *status) {
uint8_t free_pos;
dbg("BVR-flag","bufferPool:Get\n");
if (bufferPoolGetFreePos(this, &free_pos) == FAIL) {
dbg("BVR-flag","bufferPool: could not get free position\n");
*status = free_pos;
return FAIL;
}
this->busy[free_pos] = TRUE;
this->num_elements++;
*buffer = this->bufferPtrs[free_pos];
dbg("BVR-flag","bufferPoolGet: returning free buffer [%d]=%p\n",free_pos,*buffer);
bufferPoolDbg(this);
return SUCCESS;
}
//sets the busy flag to the buffer pointed to by ptr, if it is in
//the buffer pool.
//Returns SUCCESS if pointer in buffer pool, FAIL otherwise
inline error_t bufferPoolSetFree(BufferPool* this, message_t* ptr) {
int i;
uint8_t pos = 255;
dbg("BVR-flag","bufferPool:setFree.\n");
bufferPoolDbg(this);
//search for the position in which ptr is stored
for (i = 0; i < BUFFER_POOL_SIZE && pos == 255; i++) {
if (this->bufferPtrs[i] == ptr)
pos = i;
}
if (pos == 255)
return FAIL;
this->busy[pos] = FALSE;
this->num_elements--;
dbg("BVR-flag","bufferPool: freeing element %p. num_busy:%d\n",ptr,this->num_elements);
return SUCCESS;
}
--- NEW FILE: Ident.nc ---
// ex: set tabstop=2 shiftwidth=2 expandtab syn=c:
// $Id: Ident.nc,v 1.1 2008/10/23 22:22:41 genie1 Exp $
/*
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* Authors: Rodrigo Fonseca
* Date Last Modified: 2005/05/26
*/
interface Ident {
command uint16_t getInstallId();
command uint32_t getCompileTime();
}
--- NEW FILE: IdentM.nc ---
// ex: set tabstop=2 shiftwidth=2 expandtab syn=c:
// $Id: IdentM.nc,v 1.1 2008/10/23 22:22:41 genie1 Exp $
/*
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* Authors: Rodrigo Fonseca
* Date Last Modified: 2005/05/26
*/
module IdentM {
provides interface Ident;
}
implementation {
#ifdef TOSSIM
enum {install_id = 1};
enum {compile_time =1};
#else
enum {install_id = 1};
enum {compile_time =1};
#endif
command uint16_t Ident.getInstallId() {
return install_id;
}
command uint32_t Ident.getCompileTime() {
return compile_time;
}
}
--- NEW FILE: LBlink.nc ---
/**
* Used to make the leds blink a speficied number of times,
* to easily increase the number of feedback messages one can
* get from the leds.
*
* @author Rodrigo Fonseca
*/
interface LBlink {
/** Should be called at least once before using */
command error_t setRate(uint16_t rate);
command error_t yellowBlink(uint8_t times);
command error_t redBlink(uint8_t times);
command error_t greenBlink(uint8_t times);
}
--- NEW FILE: LBlinkC.nc ---
configuration LBlinkC
{
provides interface LBlink;
provides interface StdControl;
}
implementation {
components LBlinkM
#ifdef LBLINK_ON
, LedsC as Leds
#else
, NoLedsC as Leds
#endif
, new TimerMilliC()
;
LBlink = LBlinkM;
StdControl = LBlinkM;
LBlinkM.Leds -> Leds;
LBlinkM.Timer -> TimerMilliC;
}
--- NEW FILE: LBlinkM.nc ---
module LBlinkM
{
provides {
interface LBlink;
interface StdControl;
interface Init;
}
uses {
interface Leds;
interface Timer<TMilli>;
//interface StdControl as TimerControl;
}
}
implementation {
uint16_t rate;
uint8_t yellow;
uint8_t red;
uint8_t green;
bool timer_on;
bool initialized = FALSE;
command error_t LBlink.setRate(uint16_t r)
{
dbg("BVR-boot","LBlinkM$setRate: interval %d\n",r);
rate = r;
return SUCCESS;
}
command error_t Init.init() {
//call TimerControl.init();
rate = 0;
timer_on = FALSE;
yellow = red = green = 0;
initialized = TRUE;
return SUCCESS;
}
command error_t StdControl.start() {
if (!initialized) {
//call TimerControl.init();
rate = 0;
timer_on = FALSE;
yellow = red = green = 0;
initialized = TRUE;
}
//call TimerControl.start();
return SUCCESS;
}
command error_t StdControl.stop() {
//call TimerControl.stop();
return SUCCESS;
}
command error_t LBlink.yellowBlink(uint8_t times)
{
dbg("BVR-debug","LBLinkM$yellowBlink %d times\n",times);
yellow += times<<1;
if (!timer_on) {
timer_on = TRUE;
call Timer.startPeriodic(rate);
}
return SUCCESS;
}
command error_t LBlink.redBlink(uint8_t times)
{
dbg("BVR-debug","LBLinkM$redBlink %d times\n",times);
red += times<<1;
if (!timer_on) {
timer_on = TRUE;
call Timer.startPeriodic(rate);
}
return SUCCESS;
}
command error_t LBlink.greenBlink(uint8_t times)
{
dbg("BVR-debug","LBLinkM$greenBlink %d times\n",times);
green += times<<1;
if (!timer_on) {
timer_on = TRUE;
call Timer.startPeriodic(rate);
}
return SUCCESS;
}
event void Timer.fired() {
if (yellow > 0) {
call Leds.led2Toggle();
yellow--;
}
if (red > 0) {
call Leds.led0Toggle();
red--;
}
if (green > 0) {
call Leds.led1Toggle();
green--;
}
if (yellow + green + red == 0) {
timer_on = FALSE;
call Timer.stop();
}
return ;
}
}
--- NEW FILE: Logger.nc ---
// ex: set tabstop=2 shiftwidth=2 expandtab syn=c:
// $Id: Logger.nc,v 1.1 2008/10/23 22:22:41 genie1 Exp $
/*
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* Authors: Rodrigo Fonseca
* Date Last Modified: 2005/05/26
*/
/** Interface to the logger. These commands are called by the application at
* the relevant points to allow for logging of the different aspects of the
* NoGeo.
* See also: Logging.h
*/
includes LinkEstimator;
includes BVR;
interface Logger {
/* Packets */
command error_t LogSendBeacon(uint8_t seqno);
command error_t LogReceiveBeacon(uint8_t seqno, uint16_t from);
command error_t LogSendRootBeacon(uint8_t seqno, uint8_t hopcount);
command error_t LogReceiveRootBeacon(uint8_t seqno, uint8_t id, uint16_t last_hop, uint8_t hopcount, uint8_t quality);
command error_t LogSendLinkInfo();
command error_t LogReceiveLinkInfo();
command error_t LogSendAppMsg(uint8_t id, uint16_t to, uint8_t mode, uint8_t fallback_thresh, Coordinates* dest);
command error_t LogReceiveAppMsg(uint8_t id, uint8_t result);
/* State */
/* In LinkEstimatorM */
command error_t LogAddLink(LinkNeighbor* n);
command error_t LogChangeLink(LinkNeighbor* n);
command error_t LogDropLink(uint16_t addr);
/* In NeighborTable */
command error_t LogAddNeighbor(CoordinateTableEntry * ce);
command error_t LogUpdateNeighbor(CoordinateTableEntry * ce);
command error_t LogDropNeighbor(uint16_t addr);
/* in NoGeo */
command error_t LogUpdateCoordinates(Coordinates* coords, CoordsParents *parents);
command error_t LogUpdateCoordinate(uint8_t beacon, uint8_t hopcount, uint16_t parent, uint8_t combined_quality);
/* in CBRouter */
command error_t LogRouteReport(uint8_t status, uint16_t id, uint16_t origin_addr, uint16_t dest_addr, uint8_t hopcount, Coordinates* coords, Coordinates* my_coords);
/* in UARTLoggerComm */
command error_t LogUARTCommStats(
uint16_t stat_receive_duplicate_no_buffer,
uint16_t stat_receive_duplicate_send_failed,
uint16_t stat_receive_total,
uint16_t stat_send_duplicate_no_buffer,
uint16_t stat_send_duplicate_send_fail,
uint16_t stat_send_duplicate_send_done_fail,
uint16_t stat_send_duplicate_success,
uint16_t stat_send_duplicate_total,
uint16_t stat_send_original_send_done_fail,
uint16_t stat_send_original_send_failed,
uint16_t stat_send_original_success,
uint16_t stat_send_original_total);
command error_t LogLRXPkt(uint8_t type,
uint16_t sender, uint16_t sender_session_id, uint8_t sender_msg_id,
uint16_t receiver, uint16_t receiver_session_id, uint8_t receiver_msg_id,
uint8_t ctrl, uint8_t blockNum, uint8_t subCtrl, uint8_t state);
command error_t LogLRXXfer(uint8_t type,
uint16_t sender, uint16_t receiver,
uint16_t session_id, uint8_t msg_id, uint8_t numofBlock,
uint8_t success, uint8_t state);
/* Simple Debug: I know, it's not general, but should be fine for some quick thing */
command error_t LogDebug(uint8_t type, uint16_t arg1, uint16_t arg2, uint16_t arg3);
/*Retransmit Test*/
command error_t LogRetransmitReport(
uint8_t status,
uint16_t id,
uint16_t origin_addr,
uint16_t dest_addr,
uint8_t hopcount,
uint16_t next_hop,
uint8_t retransmit_count);
}
--- NEW FILE: Logging.h ---
// ex: set tabstop=2 shiftwidth=2 expandtab syn=c:
// $Id: Logging.h,v 1.1 2008/10/23 22:22:41 genie1 Exp $
/*
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* Authors: Rodrigo Fonseca
* Date Last Modified: 2005/05/26
*/
#ifndef _NOGEO_LOG
#define _NOGEO_LOG
/*
* The logging is done in message_t packets
*
*/
#include "BVR.h"
enum {
//Constants
AM_S4_LOG_MSG = 60,
AM_BVR_LOG_MSG = 61,
SELF_LOG_INTERVAL = 60000u,
UART_LOG_INTERVAL = 60000u,
};
enum {
//Packets
LOG_SEND_BEACON = 1,
LOG_RECEIVE_BEACON = 3,
LOG_SEND_ROOT_BEACON = 2,
LOG_RECEIVE_ROOT_BEACON = 4,
LOG_SEND_LINK_INFO = 5,
LOG_RECEIVE_LINK_INFO = 6,
LOG_SEND_APP_MSG = 7,
LOG_RECEIVE_APP_MSG = 8,
//Link table
LOG_ADD_LINK = 10, //0x0A
LOG_CHANGE_LINK = 11, //0x0B
LOG_DROP_LINK = 12, //0x0C
//Neighbor table (neighbor's coordinates)
LOG_ADD_NEIGHBOR = 20, //14
LOG_CHANGE_NEIGHBOR = 21,//15
LOG_DROP_NEIGHBOR = 22, //16
//State
LOG_CHANGE_COORDS = 30, //1E
LOG_CHANGE_COORD = 31, //1F
//Routing
LOG_ROUTE_START = 39, //27
LOG_ROUTE_FAIL_STUCK_0 = 40, //28
LOG_ROUTE_FAIL_STUCK = 42, //2A
LOG_ROUTE_FAIL_BEACON = 41, //29
//LOG_ROUTE_SAME_COORDS = 42, //2A
LOG_ROUTE_SUCCESS = 43, //2B
LOG_ROUTE_FAIL_NO_LOCAL_BUFFER = 44, //2C
LOG_ROUTE_FAIL_NO_QUEUE_BUFFER = 45, //2D
LOG_ROUTE_INVALID_STATUS = 46, //2E
LOG_ROUTE_TO_SELF = 47, //2F
LOG_ROUTE_STATUS_NEXT_ROUTE = 38, //26
LOG_ROUTE_BUFFER_ERROR = 37, //25
LOG_ROUTE_SENT_NORMAL_OK = 32, //20
LOG_ROUTE_SENT_FALLBACK_OK = 33, //21
LOG_ROUTE_RECEIVED_OK = 34, //22
LOG_ROUTE_RECEIVED_DUPLICATE = 35, //23
//Logging for Scoped Flood
LOG_ROUTE_BCAST_START = 64, //40
LOG_ROUTE_STATUS_BCAST_RETRY = 65, //41
LOG_ROUTE_STATUS_BCAST_FAIL = 66, //42
LOG_ROUTE_SENT_BCAST_OK = 67, //43
LOG_ROUTE_RECEIVED_BCAST_OK = 68, //44
LOG_ROUTE_BCAST_END_SCOPE = 69, //45
LOG_ROUTE_BCAST_ERROR_TIMER_FAILED = 70, //46
LOG_ROUTE_BCAST_ERROR_TIMER_PENDING = 71, //47
//Logging self logging
LOG_LOGGER_STATS = 50, //32
LOG_UART_COMM_STATS = 51, //33
//Logging For QueuedSendM
LOG_LRX_SEND = 101,
LOG_LRX_RECEIVE = 102,
LOG_LRX_SXFER_START = 103,
LOG_LRX_SXFER_FINISH = 104,
LOG_LRX_RXFER_START = 105,
LOG_LRX_RXFER_FINISH = 106,
//Logging temporary - for debugging
LOG_DBG1 = 129, //81
LOG_DBG2 = 130, //82
LOG_DBG3 = 131, //83
//Logging for retransmit test
LOG_ROUTE_RETRANSMIT_SUCCESS = 132, //84
LOG_ROUTE_RETRANSMIT_FAIL = 133, //85
};
typedef nx_struct {
nx_uint8_t type;
nx_uint16_t total;
} LogEntrySentDV;
typedef nx_struct {
nx_uint8_t type;
nx_uint16_t total;
} LogEntrySentBV;
typedef nx_struct {
nx_uint8_t type;
nx_uint16_t total;
} LogEntrySentData;
typedef nx_struct {
nx_uint8_t type;
nx_uint16_t total;
} LogEntryRTState;
/*Packets*/
//Send a coordinate beacon with coordinate info
typedef nx_struct {
nx_uint8_t type;
nx_uint8_t seqno;
} LogEntrySendBeacon;
typedef nx_struct {
nx_uint8_t type;
nx_uint8_t seqno;
nx_uint16_t from;
} LogEntryReceiveBeacon;
typedef nx_struct {
nx_uint8_t type;
nx_uint8_t seqno;
nx_uint8_t hopcount;
} LogEntrySendRootBeacon;
typedef nx_struct {
nx_uint8_t type; //LOG_RECEIVE_ROOT_BEACON
nx_uint8_t id; //which beacon
nx_uint8_t seqno;
nx_uint8_t hopcount; //how distant
nx_uint16_t last_hop; //from
nx_uint8_t quality; //combined_quality
} LogEntryReceiveRootBeacon;
typedef nx_struct {
nx_uint8_t type;
nx_uint8_t id; //the message id from the application data, if it makes sense
nx_uint16_t to; //next hop
nx_uint8_t mode; //fallback or not
nx_uint8_t fallback_thresh; //threshold to return to normal mode, if in fallback
Coordinates dest; //final destination
} LogEntrySendAppMsg;
typedef nx_struct {
nx_uint8_t type;
nx_uint8_t id;
nx_uint8_t result; //whether this will be forwarded, received, or failed
} LogEntryReceiveAppMsg;
/*Events*/
typedef nx_struct {
nx_uint8_t type;
LinkNeighbor link;
} LogEntryChangeLink;
typedef nx_struct {
nx_uint8_t type;
nx_uint16_t addr;
} LogEntryDropLink;
typedef nx_struct {
nx_uint8_t type;
CoordinateTableEntry neighbor;
} LogEntryChangeNeighbor;
typedef nx_struct {
nx_uint8_t type;
nx_uint16_t addr;
} LogEntryDropNeighbor;
//Packet type: 1E
typedef nx_struct {
nx_uint8_t type;
Coordinates Coords;
CoordsParents parents;
} LogEntryUpdateCoordinates;
//Packet type: 1F
typedef nx_struct {
nx_uint8_t type;
nx_uint8_t beacon;
nx_uint8_t hopcount;
nx_uint16_t parent;
nx_uint8_t combined_quality;
} LogEntryUpdateCoordinate;
typedef nx_struct {
nx_uint8_t type;
nx_uint16_t id;
nx_uint16_t origin_addr;
nx_uint16_t dest_addr;
nx_uint8_t hopcount;
Coordinates dest_coords;
Coordinates my_coords;
} LogEntryRouteReport;
//For link_level retransmission test
typedef nx_struct {
nx_uint8_t type;
nx_uint16_t id;
nx_uint16_t origin_addr;
nx_uint16_t dest_addr;
nx_uint8_t hopcount;
nx_uint16_t next_hop;
nx_uint8_t retransmit_count;
} LogEntryRetransmitReport;
typedef nx_struct {
nx_uint8_t type;
nx_uint8_t free_pos;
nx_uint8_t max_queue;
nx_uint32_t stat_received; // A total requests received
nx_uint32_t stat_written; // B total successfully written
nx_uint32_t stat_no_buffer; // C total failed no buffer
nx_uint32_t stat_send_failed; // D total send failed
nx_uint32_t stat_send_done_failed; //E total send done returned fail
// A = B + C + D + E
} LogEntryLoggerStats;
typedef nx_struct {
nx_uint8_t type;
nx_uint16_t stat_receive_duplicate_no_buffer; // a
nx_uint16_t stat_receive_duplicate_send_failed; // b
nx_uint16_t stat_receive_total; // c
nx_uint16_t stat_send_duplicate_no_buffer; // d
nx_uint16_t stat_send_duplicate_send_fail; // e
nx_uint16_t stat_send_duplicate_send_done_fail; // f
nx_uint16_t stat_send_duplicate_success; // g
nx_uint16_t stat_send_duplicate_total; // h
nx_uint16_t stat_send_original_send_done_fail; // i
nx_uint16_t stat_send_original_send_failed; // j
nx_uint16_t stat_send_original_success; // k
nx_uint16_t stat_send_original_total; // l
} LogEntryUARTCommStats;
typedef nx_struct {
nx_uint8_t type;
nx_uint16_t sender;
nx_uint16_t sender_session_id;
nx_uint8_t sender_msg_id;
nx_uint16_t receiver;
nx_uint16_t receiver_session_id;
nx_uint8_t receiver_msg_id;
nx_uint8_t ctrl;
nx_uint8_t blockNum;
nx_uint8_t subCtrl;
nx_uint8_t state;
} LogEntryLRXPkt;
typedef nx_struct {
nx_uint8_t type;
nx_uint16_t sender;
nx_uint16_t receiver;
nx_uint16_t session_id;
nx_uint8_t msg_id;
nx_uint8_t numofBlock;
nx_uint8_t success;
nx_uint8_t state;
} LogEntryLRXXfer;
typedef nx_struct {
nx_uint8_t type;
nx_uint16_t arg1;
nx_uint16_t arg2;
nx_uint16_t arg3;
} LogEntryDebug;
/* This is a union with a hack: to reuse the structs above, which are all
assumed to have a first field type, I define the first field of the
union to be type, so that it can be checked invariably. */
typedef nx_union {
nx_uint8_t type;
LogEntryReceiveRootBeacon receive_root_beacon;
LogEntryDropLink drop_link;
LogEntryChangeLink add_link;
LogEntryChangeLink change_link;
LogEntryChangeNeighbor add_neighbor;
LogEntryChangeNeighbor change_neighbor;
LogEntryDropNeighbor drop_neighbor;
LogEntryUpdateCoordinates update_coordinates;
LogEntryUpdateCoordinate update_coordinate;
LogEntryRouteReport route_report;
LogEntryLoggerStats logger_stats;
LogEntryUARTCommStats UART_comm_stats;
LogEntryLRXPkt lrx_pkt;
LogEntryLRXXfer lrx_xfer;
LogEntryDebug debug;
LogEntryRetransmitReport retransmit_report;
} BVRLogMsg;
typedef nx_struct BVR_Log_Msg{
LEHeader header;
BVRLogMsg log_msg;
} BVRLogMsgWrapper;
/* This is a union with a hack: to reuse the structs above, which are all
assumed to have a first field type, I define the first field of the
union to be type, so that it can be checked invariably. */
typedef nx_union {
nx_uint8_t type;
LogEntryReceiveBeacon receive_beacon;
LogEntryReceiveRootBeacon receive_root_beacon;
LogEntryDropLink drop_link;
LogEntryChangeLink add_link;
LogEntryChangeLink change_link;
LogEntryChangeNeighbor add_neighbor;
LogEntryChangeNeighbor change_neighbor;
LogEntryDropNeighbor drop_neighbor;
LogEntryUpdateCoordinates update_coordinates;
LogEntryUpdateCoordinate update_coordinate;
LogEntryRouteReport route_report;
LogEntryLoggerStats logger_stats;
LogEntryUARTCommStats UART_comm_stats;
LogEntryLRXPkt lrx_pkt;
LogEntryLRXXfer lrx_xfer;
LogEntryDebug debug;
LogEntryRetransmitReport retransmit_report;
//added by Feng Wang on Sept. 22, for more statistics logging
LogEntrySentDV sent_dv;
LogEntrySentBV sent_bv;
LogEntrySentData sent_data;
LogEntryRTState rt_state;
} S4LogMsg;
typedef nx_struct S4_Log_Msg{
LEHeader header;
S4LogMsg log_msg;
} S4LogMsgWrapper;
#endif
--- NEW FILE: UARTLogger.nc ---
/* ex: set tabstop=2 shiftwidth=2 expandtab syn=c:*/
/* $Id: UARTLogger.nc,v 1.1 2008/10/23 22:22:41 genie1 Exp $ */
/*
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* Authors: Rodrigo Fonseca
* Date Last Modified: 2005/05/26
*/
/* Warning: This configuration does not wire to BottomComm.StdControl
* It assumes someone else does start the BVRCommStack
*/
includes Logging;
configuration UARTLogger {
provides {
interface Init;
interface StdControl;
interface Logger;
}
}
implementation {
components UARTLoggerM
,S4CommStack as BottomComm //assumes StdControl elsewhere
, new TimerMilliC() //assumes StdControl elsewhere
, NoLedsC as Leds
, S4QueuedSendM as QueuedSend
, ActiveMessageC
;
Init = UARTLoggerM;
StdControl = UARTLoggerM;
Logger = UARTLoggerM;
UARTLoggerM.LogSend -> QueuedSend.QueueSendMsg[AM_S4_LOG_MSG];
UARTLoggerM.SelfTimer -> TimerMilliC;
UARTLoggerM.Leds -> Leds;
UARTLoggerM.QueueControl -> QueuedSend;
UARTLoggerM.AMPacket -> ActiveMessageC;
}
--- NEW FILE: UARTLoggerM.nc ---
/* ex: set tabstop=2 shiftwidth=2 expandtab syn=c:*/
/* $Id: UARTLoggerM.nc,v 1.1 2008/10/23 22:22:41 genie1 Exp $ */
/*
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
[...966 lines suppressed...]
if (call LogSend.send(AM_BROADCAST_ADDR,msg_ptr,msg_size) != SUCCESS) {
stat_send_failed++;
dbg("BVR-debug","Logger: send failed, freeing the buffer\n");
bufferPoolSetFree(&buffers,msg_ptr);
//return FAIL;
}
//return SUCCESS;
}
event void SelfTimer.fired() {
post LogLoggerStats();
min_available_buffers = 255;
max_queued_send = 0;
return ;
}
}
--- NEW FILE: util.h ---
// ex: set tabstop=2 shiftwidth=2 expandtab syn=c:
// $Id: util.h,v 1.1 2008/10/23 22:22:41 genie1 Exp $
/*
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* Authors: Rodrigo Fonseca
* Date Last Modified: 2005/05/26
*/
#ifndef _UTIL_H
#define _UTIL_H
/* Set the bth bit of integer a */
inline void set_bit(uint8_t *a, uint8_t b) {
*a |= (1 << b);
}
/* Get the bth bit of integer a */
inline bool get_bit(uint8_t a, uint8_t b) {
return (a & (1 << b))?1:0;
}
/* Reset the bth bit of a */
inline void reset_bit(uint8_t *a, uint8_t b) {
*a &= ~(1<<b);
}
/* Absolute value of x */
inline uint16_t int_abs(int16_t x) {
return (uint16_t)((x < 0)?-x:x);
}
#endif
- Previous message: [Tinyos-2-commits] CVS: tinyos-2.x-contrib/stanford-sing/s4-tinyos-2.x/tos/lib/linkestimator LinkEstimator.h, NONE, 1.1 LinkEstimator.nc, NONE, 1.1 LinkEstimatorC.nc, NONE, 1.1 LinkEstimatorM.nc, NONE, 1.1 LinkEstimatorSynch.nc, NONE, 1.1 ReverseLinkInfo.h, NONE, 1.1
- Next message: [Tinyos-2-commits] CVS: tinyos-2.x-contrib/stanford-sing/s4-tinyos-2.x/apps/TestS4Simple README, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-2-commits
mailing list