[Tinyos-beta-commits] CVS: tinyos-1.x/beta/TOSSIM-CC2420 HPLCC2420.c, NONE, 1.1 HPLCC2420.h, NONE, 1.1 HPLCC2420M.nc, 1.3, 1.4 README.txt, 1.1, 1.2 TimerJiffyAsyncC.nc, 1.1, 1.2 TimerJiffyAsyncM.nc, 1.1, 1.2 hardware.c, 1.1, 1.2 hardware.h, 1.2, 1.3

Yang overbored at users.sourceforge.net
Mon May 16 00:01:00 PDT 2005


Update of /cvsroot/tinyos/tinyos-1.x/beta/TOSSIM-CC2420
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv668

Modified Files:
	HPLCC2420M.nc README.txt TimerJiffyAsyncC.nc 
	TimerJiffyAsyncM.nc hardware.c hardware.h 
Added Files:
	HPLCC2420.c HPLCC2420.h 
Log Message:
Lots of bug fixes/minor enhancements; used in SP; basic power measurement.


--- NEW FILE: HPLCC2420.c ---
#include "HPLCC2420.h"

void* alloc(size_t size) {
	// XXX BUG:
	// ==11928==  Address 0x1BC84094 is 0 bytes after a block of size 28 alloc'd
	// ==11928==    at 0x1B903D1C: malloc (vg_replace_malloc.c:131)
	// ==11928==    by 0x804E413: HPLCC2420M$alloc (HPLCC2420M.nc:361)
	// ==11928==    by 0x8050473: HPLCC2420M$createFrame (HPLCC2420M.nc:2205)
	// ==11928==    by 0x80604D6: HPLCC2420M$handlePreambleSentEvent (HPLCC2420M.nc:1950)
	void* pointer = malloc(size);
	assert(pointer != NULL);
	return pointer;
}

//// Converts symbol periods to seconds.
//// 1 symbol period = 16 microsecond.
//double symbolsToSeconds(double syms) {
//	return (syms * 16.0) / 1000000.0;
//}
//
//// Converts seconds to TinyOS units of time (ticks).
//// 1 second = 4,000,000 ticks.
//uint64_t secondsToTicks(double seconds) {
//	return (uint64_t) (seconds * 4000000.0);
//}
//
//// Converts symbol periods to TinyOS units of time (ticks).
//uint64_t symbolsToTicks(double syms) {
//	return secondsToTicks(symbolsToSeconds(syms));
//}
//
//// Converts jiffies to seconds.
//double jiffiesToSeconds(double jiffies) {
//	return jiffies * (1.0 / 32768.0);
//}
//
//// Converts jiffies to TinyOS units of time (ticks).
//uint64_t jiffiesToTicks(double jiffies) {
//	return secondsToTicks(jiffiesToSeconds(jiffies));
//}
//
//// Converts seconds to jiffies.
//double secondsToJiffies(double seconds) {
//	return seconds * 32768.0;
//}
//
//// Converts TinyOS units of time (ticks) to seconds.
//double ticksToSeconds(uint64_t ticks) {
//	return ((double) ticks) / 4000000.0;
//}
//
//// Converts TinyOS units of time (ticks) to jiffies.
//double ticksToJiffies(uint64_t ticks) {
//	return secondsToJiffies(ticksToSeconds(ticks));
//}
//
//// Returns the current time in jiffies.
//uint32_t getCurrentTimeInJiffies() {
//	double jiffies = ticksToJiffies(tos_state.tos_time -
//			tos_state.node_state[NODE_NUM].time);
//	uint32_t castedJiffies = (uint32_t) jiffies;
//	assert( tos_state.tos_time >= tos_state.node_state[NODE_NUM].time
//			&& "the current time is less than the bootup time" );
//	assert( jiffies >= 0 && jiffies <= UINT32_MAX
//			&& "double cannot safely be converted into uint32_t" );
//	assert( floor(jiffies) == (double) castedJiffies
//			&& "the number of jiffies has overflowed our 32-bit number" );
//	return castedJiffies;
//}

--- NEW FILE: HPLCC2420.h ---
#ifndef __HPLCC2420_H
#define __HPLCC2420_H

#define DEBUG

#define MAX_BUF 255
#define TIME_BUF 32
#define NODE_COLOR_COUNT 9

//char* DbgNormal        = "\E[0;39m";
//char* DbgDarkBlue      = "\E[0;34m";
//char* DbgDarkGreen     = "\E[0;32m";
//char* DbgDarkCyan      = "\E[0;36m";
//char* DbgDarkRed       = "\E[0;31m";
//char* DbgDarkMagenta   = "\E[0;35m";
//char* DbgBrown         = "\E[0;33m";
//char* DbgBlack         = "\E[0;30m";
//char* DbgBold_White    = "\E[1;37m";
//char* DbgBrightBlue    = "\E[1;34m";
//char* DbgBrightGreen   = "\E[1;32m";
//char* DbgBrightCyan    = "\E[1;36m";
//char* DbgBrightRed     = "\E[1;31m";
//char* DbgBrightMagenta = "\E[1;35m";
//char* DbgYellow        = "\E[1;33m";
//char* DbgDarkGray      = "\E[1;30m";
//char* DbgWhite         = "\E[0;37m";
//char* DbgBrightWhite   = "\E[1;37m";

#define DbgNormal          "\E[0;39m"
#define DbgDarkBlue        "\E[0;34m"
#define DbgDarkGreen       "\E[0;32m"
#define DbgDarkCyan        "\E[0;36m"
#define DbgDarkRed         "\E[0;31m"
#define DbgDarkMagenta     "\E[0;35m"
#define DbgBrown           "\E[0;33m"
#define DbgBlack           "\E[0;30m"
#define DbgBold_White      "\E[1;37m"
#define DbgBrightBlue      "\E[1;34m"
#define DbgBrightGreen     "\E[1;32m"
#define DbgBrightCyan      "\E[1;36m"
#define DbgBrightRed       "\E[1;31m"
#define DbgBrightMagenta   "\E[1;35m"
#define DbgYellow          "\E[1;33m"
#define DbgDarkGray        "\E[1;30m"
#define DbgWhite           "\E[0;37m"
#define DbgBrightWhite     "\E[1;37m"

// Aliases
//char* DbgBlue          = DbgBrightBlue;
//char* DbgGreen         = DbgBrightGreen;
//char* DbgCyan          = DbgBrightCyan;
//char* DbgRed           = DbgBrightRed;
//char* DbgMagenta       = DbgBrightMagenta;

#define DbgBlue            DbgDarkBlue
#define DbgGreen           DbgDarkGreen
#define DbgCyan            DbgDarkCyan
#define DbgRed             DbgDarkRed
#define DbgMagenta         DbgDarkMagenta

// 100 ms
#define PRINT_TIME_MARKERS       FALSE
#define PRINT_MAJOR_TIME_MARKERS TRUE
#define MARKER_INTERVAL          (0.1 * 4000000.0)

#ifdef DEBUG
char* NODE_COLORS[NODE_COLOR_COUNT] = {
	DbgBrightBlue,
	DbgBrightMagenta,
	DbgBrightGreen,
	DbgBrightCyan,
	DbgBrightRed,
	DbgYellow,
	DbgDarkGray,
	DbgNormal,
	DbgWhite
};

typedef struct DebugMode {
	bool isOn;
	TOS_dbg_mode mode;
	char* color;
	char* label;
} DebugMode;

void ppp(TOS_dbg_mode mode, const char * fmt, ...);
void pppp(DebugMode mode, const char * fmt, ...);
#endif // DEBUG

#ifdef DEBUG
#define ifdbg(x) x
#else
#define ifdbg(x)
#endif // DEBUG

//#define assert(w) ((!(w)) ? (*((int*) 0) = 1) : 0)
#define assert(w) ((!(w)) ? assert2() : 0)
#define fail(reason) assert(FALSE && reason)

static uint64_t lastTime = 0;

void assert2() {
	printf("");
}

// Converts symbol periods to seconds.
// 1 symbol period = 16 microsecond.
double symbolsToSeconds(double syms) {
	return (syms * 16.0) / 1000000.0;
}

// Converts seconds to TinyOS units of time (ticks).
// 1 second = 4,000,000 ticks.
uint64_t secondsToTicks(double seconds) {
	return (uint64_t) (seconds * 4000000.0);
}

// Converts symbol periods to TinyOS units of time (ticks).
uint64_t symbolsToTicks(double syms) {
	return secondsToTicks(symbolsToSeconds(syms));
}

// Converts jiffies to seconds.
double jiffiesToSeconds(double jiffies) {
	return jiffies * (1.0 / 32768.0);
}

// Converts jiffies to TinyOS units of time (ticks).
uint64_t jiffiesToTicks(double jiffies) {
	return secondsToTicks(jiffiesToSeconds(jiffies));
}

// Converts seconds to jiffies.
double secondsToJiffies(double seconds) {
	return seconds * 32768.0;
}

// Converts TinyOS units of time (ticks) to seconds.
double ticksToSeconds(uint64_t ticks) {
	return ((double) ticks) / 4000000.0;
}

// Converts TinyOS units of time (ticks) to jiffies.
double ticksToJiffies(uint64_t ticks) {
	return secondsToJiffies(ticksToSeconds(ticks));
}

// Returns the current time in jiffies.
uint32_t getCurrentTimeInJiffies() {
	double jiffies = ticksToJiffies(tos_state.tos_time -
			tos_state.node_state[NODE_NUM].time);
	uint32_t castedJiffies = (uint32_t) jiffies;
	assert( tos_state.tos_time >= tos_state.node_state[NODE_NUM].time
			&& "the current time is less than the bootup time" );
	assert( jiffies >= 0 && jiffies <= UINT32_MAX
			&& "double cannot safely be converted into uint32_t" );
	assert( floor(jiffies) == (double) castedJiffies
			&& "the number of jiffies has overflowed our 32-bit number" );
	return castedJiffies;
}

// Convenience function for outputting debug information.
void ppp(TOS_dbg_mode mode, const char *fmt, ...) {
	va_list argp;
	static char str[MAX_BUF];
	static char timeStr[TIME_BUF];

	va_start(argp, fmt);
	vsnprintf(str, MAX_BUF, fmt, argp);
	va_end(argp);

	printTime(timeStr, TIME_BUF);
	dbg(mode, "(%s): %s\n", timeStr, str);
}

//#define SLOW_SCROLL 250000
#define SLOW_SCROLL 0

// Convenience function for outputting debug information.
void pppp(DebugMode mode, const char * fmt, ...) {
	if (mode.isOn && dbg_active(mode.mode)) {
		va_list argp;
		static char str[MAX_BUF];
		static char timeStr[TIME_BUF];

		uint64_t currTime = tos_state.tos_time;
		if (lastTime != 0) {
			int lastPeriod = lastTime / MARKER_INTERVAL;
			int currPeriod = currTime / MARKER_INTERVAL;
			int i;
			for (i = lastPeriod; i < currPeriod; i++) {
				if (i % 10 == 9) {
					if (PRINT_MAJOR_TIME_MARKERS) {
						printf("=====\n");
					}
				} else {
					if (PRINT_TIME_MARKERS) {
						printf("-\n");
					}
				}
			}
		}
		lastTime = currTime;

		va_start(argp, fmt);
		vsnprintf(str, MAX_BUF, fmt, argp);
		va_end(argp);

		//printTime(timeStr, TIME_BUF);
		printf( "%s%hd (G%f, L%f) %s%s : %s%s\n",
				mode.mode == DBG_USR3 ? "" : NODE_COLORS[NODE_NUM % NODE_COLOR_COUNT],
				NODE_NUM, //timeStr,
				ticksToSeconds(tos_state.tos_time),
				ticksToSeconds(tos_state.tos_time - tos_state.node_state[NODE_NUM].time),
				mode.mode == DBG_USR3 ? "" : mode.color,
				mode.label, str,
				mode.mode == DBG_USR3 ? "" : DbgNormal);
	}

	if (SLOW_SCROLL) {
		usleep(SLOW_SCROLL);
	}
}

#define printd(mode,fmt,...) pppp(mode,fmt , ## __VA_ARGS__ )

//// TODO Can I get a real assert()? I grepped the other .nc files but didn't
//// find assert!
//#define assert(w) ((!(w)) ? (*((int*) 0) = 1) : 0)
//#define fail(reason) assert(FALSE && reason)

void* alloc(size_t size);
double symbolsToSecondS(double syms);
uint64_t secondsToTicks(double secs);
uint64_t symbolsToTicks(double syms);
double jiffiesToSeconds(double jiffies);
uint64_t jiffiesToTicks(double jiffies);
double secondsToJiffies(double seconds);
double ticksToSeconds(uint64_t ticks);
double ticksToJiffies(uint64_t ticks);
uint32_t getCurrentTimeInJiffies();

#endif // __HPLCC2420_H

Index: HPLCC2420M.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/TOSSIM-CC2420/HPLCC2420M.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** HPLCC2420M.nc	13 Mar 2005 08:13:50 -0000	1.3
--- HPLCC2420M.nc	16 May 2005 07:00:51 -0000	1.4
***************
*** 42,47 ****
--- 42,53 ----
  // CC2420Lib.
  
+ includes HPLCC2420;
  includes simplatform;
  
+ // monitor the on/off status of the radio
+ #define DBG_STDCTL DBG_USR1
+ // high-level indicator that a packet was successfully received and accepted
+ #define DBG_TRANSMIT DBG_USR1
[...1087 lines suppressed...]
! //          // TODO note that TOSH_wait doesn't actually do anything!
! //          // so this timeout mechanism *will not* work
!           createOscillatorOnEvent();
! //          // TODO this is a temporary workaround
! //          handleOscillatorOnEvent(NULL, NULL);
  
            break;
***************
*** 2779,2783 ****
    task void signalSfdCaptured() {
      // TODO the time being passed is zero; this seems to be OK....
!     result_t result = signal SFD.captured(0);
      sfdEnabled = result == SUCCESS;
    }
--- 2903,2907 ----
    task void signalSfdCaptured() {
      // TODO the time being passed is zero; this seems to be OK....
!     result_t result = signal SFD.captured((uint16_t) getCurrentTimeInJiffies());
      sfdEnabled = result == SUCCESS;
    }

Index: README.txt
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/TOSSIM-CC2420/README.txt,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** README.txt	15 Feb 2005 04:15:13 -0000	1.1
--- README.txt	16 May 2005 07:00:51 -0000	1.2
***************
*** 4,8 ****
  
  - This directory contains components that engage a prototype emulator of
!   the CC2420 transciever hardware.
  
  Usage notes:
--- 4,8 ----
  
  - This directory contains components that engage a prototype emulator of
!   the CC2420 transceiver hardware.
  
  Usage notes:
***************
*** 17,27 ****
  - No changes to the Makefile are needed.
  
  - To use TinyViz with this, run tinyviz from a directory containing the
!   platform.properties file in this directory. (Due to TinyViz's quirky
    behavior, if you'd like to use the SetLocations/RadioLinks plugins,
    make sure you activate those first before you attach to the TOSSIM
!   instance, which you should start with.)
  
! - For debug output, include "packet" in your DBG flag.
  
  General notes (description & features):
--- 17,59 ----
  - No changes to the Makefile are needed.
  
+ - For debug output, include "packet" in your DBG flag.
+ 
+ TinyViz notes:
+ 
+ - First, build the Telos version of net.tinyos.message.telos.TOSMsg. To do
+   this, first look at net/tinyos/message/telos/Makefile. You should see this
+   comment:
+ 
+     #TO REMAKE BaseTOSMsg, uncomment the line below and type make telos msg
+     #include $(TOS)/../apps/Makerules
+ 
+   Make sure that the line is actually commented out, and run "make" from that
+   directory. (If you don't, a BaseTOSMsg will be regenerated by MIG when you
+   run "make telos msg". Unfortunately, this new BaseTOSMsg will not inherit
+   from net.tinyos.message.TOSMsg, but directly from net.tinyos.message.Message.
+   This is will cause class cast exceptions because TinyViz will expect
+   net.tinyos.message.telos.TOSMsg to be a subclass of
+   net.tinyos.message.TOSMsg.)
+ 
+ - Now that you have .class files in net/tinyos/message/telos/, rebuild
+   TinyViz to include them. To do this, edit net/tinyos/sim/Makefile by
+   inserting this path under the rule for "jarfile: plugins/plugins.list":
+ 
+                 net/tinyos/message/telos/*.class        \
+ 
+   Then run make from that directory. Now TinyViz supports the TOSMsg format
+   used by Telos.
+ 
  - To use TinyViz with this, run tinyviz from a directory containing the
!   platform.properties file in this directory. Due to TinyViz's quirky
    behavior, if you'd like to use the SetLocations/RadioLinks plugins,
    make sure you activate those first before you attach to the TOSSIM
!   instance, which you should start with. So:
  
!   1. Run tinyviz from a directory containing platforms.properties.
!   2. Enable the RadioLinks plugin and the SetLocations plugin.
!   3. Run main.exe with the -gui option.
!   4. Click the "connect" button in TinyViz.
!   5. Start the simulation.
  
  General notes (description & features):
***************
*** 72,75 ****
--- 104,112 ----
  General action items:
  
+ - Fix the 256+ node bug. The simulator runs into an inconsistent state
+   when simulating more than 256 nodes. In particular, for certain nodes,
+   when the number of channel sources drops to 0, the channel energy does
+   not become 0.
+ 
  - Sample from a normal distribution when generating random LQI and RSSI
    numbers.

Index: TimerJiffyAsyncC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/TOSSIM-CC2420/TimerJiffyAsyncC.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** TimerJiffyAsyncC.nc	13 Mar 2005 07:23:06 -0000	1.1
--- TimerJiffyAsyncC.nc	16 May 2005 07:00:51 -0000	1.2
***************
*** 10,22 ****
  {
    components TimerJiffyAsyncM
! 	   , TimerC
  	   ;
  
    StdControl = TimerJiffyAsyncM;
!   StdControl = TimerC;
  
    TimerJiffyAsync = TimerJiffyAsyncM;
  
!   TimerJiffyAsyncM.Timer -> TimerC.Timer[unique("Timer")];
  }
  
--- 10,22 ----
  {
    components TimerJiffyAsyncM
! 	   //, TimerC
  	   ;
  
    StdControl = TimerJiffyAsyncM;
! //  StdControl = TimerC;
  
    TimerJiffyAsync = TimerJiffyAsyncM;
  
!   //TimerJiffyAsyncM.Timer -> TimerC.Timer[unique("Timer")];
  }
  

Index: TimerJiffyAsyncM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/TOSSIM-CC2420/TimerJiffyAsyncM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** TimerJiffyAsyncM.nc	13 Mar 2005 07:23:06 -0000	1.1
--- TimerJiffyAsyncM.nc	16 May 2005 07:00:51 -0000	1.2
***************
*** 7,13 ****
      interface TimerJiffyAsync;
    }
!   uses {
!     interface Timer;
!   }
  }
  
--- 7,13 ----
      interface TimerJiffyAsync;
    }
! //  uses {
! //    interface Timer;
! //  }
  }
  
***************
*** 33,44 ****
    }
  
    async command result_t TimerJiffyAsync.setOneShot( uint32_t jiffy )
    {
-     result_t result;
      atomic {
        bSet = TRUE;
!       result = call Timer.start(TIMER_ONE_SHOT, jiffy);
      }
!     return result;
    }
  
--- 33,67 ----
    }
  
+   void handleTimerJiffyEvent(event_t* ev, struct TOS_state* state) {
+     assert(ev->data == NULL);
+     signal TimerJiffyAsync.fired();
+     event_cleanup(ev);
+   }
+ 
+   void cleanupTimerJiffyEvent(event_t* ev) {
+     free(ev);
+   }
+ 
+   void createTimerJiffyEvent(uint32_t jiffies) {
+     event_t* ev;
+ 
+     ev = (event_t*) alloc(sizeof(event_t));
+     ev->mote = NODE_NUM;
+     ev->data = NULL;
+     ev->handle = handleTimerJiffyEvent;
+     ev->cleanup = cleanupTimerJiffyEvent;
+     ev->time = tos_state.tos_time + jiffiesToTicks(jiffies);
+     ev->pause = 0;
+ 
+     TOS_queue_insert_event(ev);
+   }
+ 
    async command result_t TimerJiffyAsync.setOneShot( uint32_t jiffy )
    {
      atomic {
        bSet = TRUE;
!       createTimerJiffyEvent(jiffy);
      }
!     return SUCCESS;
    }
  
***************
*** 57,65 ****
      return SUCCESS;
    }
- 
-   event result_t Timer.fired()
-   {
-     return signal TimerJiffyAsync.fired();
-   }
  }
  
--- 80,83 ----

Index: hardware.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/TOSSIM-CC2420/hardware.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** hardware.c	15 Feb 2005 04:15:13 -0000	1.1
--- hardware.c	16 May 2005 07:00:51 -0000	1.2
***************
*** 38,41 ****
--- 38,42 ----
  
  #include <dbg.h>
+ #include "HPLCC2420.c"
  
  typedef struct {

Index: hardware.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/TOSSIM-CC2420/hardware.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** hardware.h	30 Mar 2005 01:03:47 -0000	1.2
--- hardware.h	16 May 2005 07:00:51 -0000	1.3
***************
*** 68,71 ****
--- 68,73 ----
  extern norace TOS_dbg_mode dbg_modes;
  
+ //#include "HPLCC2420.h"
+ 
  
  norace TOS_state_t tos_state;



More information about the Tinyos-beta-commits mailing list