[Tinyos-beta-commits] CVS: tinyos-1.x/beta/platform/imote ADXLM.nc,
NONE, 1.1 AlphaDisp.nc, NONE, 1.1 AlphaDispM.nc, NONE,
1.1 BluSH.h, NONE, 1.1 BluSHC.nc, NONE, 1.1 BluSHM.nc, NONE,
1.1 BluSH_AppI.nc, NONE, 1.1 BluSH_types.h, NONE, 1.1 Clock.nc,
NONE, 1.1 DebugC.nc, NONE, 1.1 DebugM.nc, NONE,
1.1 DebugUART.nc, NONE, 1.1 DebugUARTBufferC.nc, NONE,
1.1 DebugUARTBufferM.nc, NONE, 1.1 DebugUARTM.nc, NONE,
1.1 FileSystem.nc, NONE, 1.1 FileSystemM.nc, NONE,
1.1 FileSystemTypes.h, NONE, 1.1 Flash.h, NONE, 1.1 Flash.nc,
NONE, 1.1 FlashAccessM.nc, NONE, 1.1 FlashFS.h, NONE,
1.1 FlashFS.nc, NONE, 1.1 FlashFSC.nc, NONE, 1.1 FlashFSM.nc,
NONE, 1.1 GPIO.nc, NONE, 1.1 HPLByteDMAM.nc, NONE,
1.1 HPLDMA.nc, NONE, 1.1 HPLDebugUartC.nc, NONE,
1.1 HPLDebugUartM.nc, NONE, 1.1 HPLFlashM.nc, NONE,
1.1 HPLMainUartC.nc, NONE, 1.1 HPLMainUartM.nc, NONE,
1.1 HPLUART.nc, NONE, 1.1 LoggerRead.nc, NONE,
1.1 LoggerWrite.nc, NONE, 1.1 NewTimer.h, NONE,
1.1 ReliablePacket.nc, NONE, 1.1 ReliablePacketC.nc, NONE,
1.1 ReliablePacketM.nc, NONE, 1.1 ReliableTransportC.nc, NONE,
1.1 ReliableTransportM.nc, NONE, 1.1 ReliableTransportParams.h,
NONE, 1.1 StatsLogger.nc, NONE, 1.1 StatsLoggerM.nc, NONE,
1.1 StatsTypes.h, NONE, 1.1 SystemTime.nc, NONE, 1.1 TimerC.nc,
NONE, 1.1 UtilitiesM.nc, NONE, 1.1 WSN.h, NONE,
1.1 WSN_Messages.h, NONE, 1.1 cmdlinetools.c, NONE,
1.1 BTLowerLayersM.nc, 1.1, 1.2 DebugLedM.nc, 1.1,
1.2 FindRootScatternetFormationC.nc, 1.1,
1.2 FindRootScatternetFormationM.nc, 1.1,
1.2 GenericPacketM.nc, 1.1, 1.2 HPLClock.nc, 1.2,
1.3 HPLDMAUart.nc, 1.1, 1.2 HPLDMAUartC.nc, 1.1,
1.2 HPLDMAUartM.nc, 1.1, 1.2 HPLPowerManagementM.nc, 1.1,
1.2 HPLUARTC.nc, 1.1, 1.2 LowPowerM.nc, 1.1, 1.2 NetworkC.nc,
1.1, 1.2 NetworkCommand.h, 1.1, 1.2 NetworkDataM.nc, 1.1,
1.2 NetworkHardwiredC.nc, 1.1, 1.2 NetworkLinkQueuesM.nc, 1.2,
1.3 NetworkManagerM.nc, 1.1, 1.2 NetworkMonitorC.nc, 1.2,
1.3 NetworkMonitorM.nc, 1.2, 1.3 NetworkPageM.nc, 1.1,
1.2 NetworkPropertiesM.nc, 1.1, 1.2 NetworkRelayM.nc, 1.2,
1.3 NetworkTopologyM.nc, 1.1, 1.2 SensorC.nc, 1.1,
1.2 SensorM.nc, 1.1, 1.2 SignalStrengthM.nc, 1.1,
1.2 TempHum.nc, 1.1, 1.2 TempHumM.nc, 1.1, 1.2 TimerM.nc, 1.1,
1.2 TreeRoutingM.nc, 1.2, 1.3 UARTBufferM.nc, 1.2,
1.3 WDTControlM.nc, 1.1, 1.2
Lama Nachman
lnachman at users.sourceforge.net
Tue Sep 6 01:28:03 PDT 2005
- Previous message: [Tinyos-beta-commits]
CVS: tinyos-1.x/beta/platform/imote/zeevo1.2/ChipBase/Common
Config.h, 1.1, 1.2 ZvDynamicScript.sp, 1.1, 1.2
- Next message: [Tinyos-beta-commits] CVS: tinyos-1.x/beta/platform/pxa27x
PXA27XHPLDMAM.nc, 1.1, 1.2 PXA27XHPLDMA.nc, 1.1,
1.2 PXA27XDMAM.nc, 1.2, 1.3 PXA27XDMAChannel.nc, 1.2, 1.3
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-1.x/beta/platform/imote
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27772
Modified Files:
BTLowerLayersM.nc DebugLedM.nc FindRootScatternetFormationC.nc
FindRootScatternetFormationM.nc GenericPacketM.nc HPLClock.nc
HPLDMAUart.nc HPLDMAUartC.nc HPLDMAUartM.nc
HPLPowerManagementM.nc HPLUARTC.nc LowPowerM.nc NetworkC.nc
NetworkCommand.h NetworkDataM.nc NetworkHardwiredC.nc
NetworkLinkQueuesM.nc NetworkManagerM.nc NetworkMonitorC.nc
NetworkMonitorM.nc NetworkPageM.nc NetworkPropertiesM.nc
NetworkRelayM.nc NetworkTopologyM.nc SensorC.nc SensorM.nc
SignalStrengthM.nc TempHum.nc TempHumM.nc TimerM.nc
TreeRoutingM.nc UARTBufferM.nc WDTControlM.nc
Added Files:
ADXLM.nc AlphaDisp.nc AlphaDispM.nc BluSH.h BluSHC.nc
BluSHM.nc BluSH_AppI.nc BluSH_types.h Clock.nc DebugC.nc
DebugM.nc DebugUART.nc DebugUARTBufferC.nc DebugUARTBufferM.nc
DebugUARTM.nc FileSystem.nc FileSystemM.nc FileSystemTypes.h
Flash.h Flash.nc FlashAccessM.nc FlashFS.h FlashFS.nc
FlashFSC.nc FlashFSM.nc GPIO.nc HPLByteDMAM.nc HPLDMA.nc
HPLDebugUartC.nc HPLDebugUartM.nc HPLFlashM.nc HPLMainUartC.nc
HPLMainUartM.nc HPLUART.nc LoggerRead.nc LoggerWrite.nc
NewTimer.h ReliablePacket.nc ReliablePacketC.nc
ReliablePacketM.nc ReliableTransportC.nc ReliableTransportM.nc
ReliableTransportParams.h StatsLogger.nc StatsLoggerM.nc
StatsTypes.h SystemTime.nc TimerC.nc UtilitiesM.nc WSN.h
WSN_Messages.h cmdlinetools.c
Log Message:
New Imote release, v2.0
--- NEW FILE: ADXLM.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This module provides an interface for a pulse width modulated (PWM) signal.
* After starting, the module triggers an event on the rising edge of the
* clock, returning the duty cycle of the most recent pulse. Two values are
* returned, the duration of the period and the duration of the high phase.
*/
module ADXLM
{
provides {
interface StdControl;
interface ADXL;
}
}
implementation
{
// This should move to HPLInterrupt
extern void TM_PIOIsr_ISR() __attribute__ ((C, spontaneous));
// time stamps for the most recent rise and fall of the signal
signed short Ta, Tb, Tc, Td, tempX, tempY;
unsigned short T1x,T1y,Time;
enum eState{getTa, getTb, getTc, done}state;
command result_t StdControl.init() {
TM_RegisterInterrupt(eTM_PIO, (tIntFunc) TM_PIOIsr_ISR, eTM_ProLow);
TM_SetPioAsOutput(0);
TM_SetPioAsOutput(1);
TM_SetPioAsInput(2);
//TM_SetPioAsInput(3);
TM_SetPioAsOutput(3);
TM_SetPioAsOutput(4);
TM_SetPioAsOutput(5);
TM_SetPioAsOutput(6);
TM_SetPioAsOutput(7);
state = getTa;
return SUCCESS;
}
command result_t StdControl.start() {
TM_LOAD_SVR(0x7FFFFFFF);
TM_SET_SVR_CTRL(TM_TMR_ENABLE | TM_TMR_FREERUN_MODE);
// TM_LOAD_RTOS(0x7FFFFFFF);
//TM_SET_RTOS_CTRL(TM_TMR_ENABLE | TM_TMR_FREERUN_MODE);
TM_Dis_WDTmrClk();
TM_EnablePIOInt();
return SUCCESS;
}
command result_t StdControl.stop() {
TM_DisablePIOInt();
return SUCCESS;
}
default event result_t ADXL.Pulse(unsigned short x, unsigned short y, unsigned short period){
//default event result_t ADXL.Pulse(signed short a, signed short b, signed short c, signed short d){
return SUCCESS;
}
/*
* Detect any changes on PWM input. This routine is called when any of the
* GPIO states change.
*
* GPIO2 = PWMx, GPIO3 = PWMy
*/
void TM_PIO_InterruptHdl() __attribute__ ((C, spontaneous)) {
TM_DisablePIOInt();
Time = TM_GetSvrTmrCnter();
//Time = TM_GetRtosTmrCnter();
switch(state)
{
//Note: Apparently our timer is based on the 32k crystal and is only 16 bits
// For some terrible reason, it also seems to count down instead of up.
case getTa:
if(TM_ReadPio(2))
{//need to make sure that we align to the rising edge of GPIO2
Ta = Time;
state = getTb;
}
break;
case getTb:
//should be the falling edge of GPIO2
if(TM_ReadPio(2) == 0)
{
Tb = Time;
tempX = Ta-Tb;
T1x = (unsigned short)tempX;
TM_SetPioAsOutput(2);
TM_SetPioAsInput(3);
state = getTc;
}
break;
case getTc:
//should be the rising edge of GPIO3
if(TM_ReadPio(3))
{
Tc = Time;
state = done;
}
break;
case done:
//should be the falling edge of GPIO3
if(TM_ReadPio(3) == 0)
{
Td = Time;
tempY = Tc-Td;
T1y = (unsigned short)(tempY);
//signal ADXL.Pulse(T1x, T1y, (unsigned)( (Ta- (((signed)T1x)>>2)) - (((signed)T1y)>>2)));
TM_SetPioAsInput(2);
TM_SetPioAsOutput(3);
TM_LOAD_SVR(0x7FFFFFFF);
//TM_LOAD_RTOS(0x7FFFFFFF); //for some reason, I occasionally miss a Pio interrupt when the timer underflows
state = getTa;
signal ADXL.Pulse(T1x, T1y, (unsigned short)((Ta - (((signed short)T1x)>>2)) - (Tc - (((signed short)T1y)>>2))));
// signal ADXL.Pulse(Ta, Tb, Tc, Td);
}
break;
}
TM_ClearPioInterrupt();
TM_EnablePIOInt();
}
}
--- NEW FILE: AlphaDisp.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
interface AlphaDisp
{
// initializes AlphaDisp
// numStatusChars = number of characters used to display link status
// each character can display up to 2 status
// values range 0 to 2
command result_t init(uint8 numStatusChars);
// puts display to power-saving sleep mode
command result_t sleep();
// Display up to 4 static characters
// c = pointer to the character array
// count = number of characters to display (up to 4-numStatusChars)
// bright = brightness of display (1 to 15)
command result_t staticDisp(char *c, uint8 count, uint8 bright);
// Scroll an array of characters in an infinite loop
// c = pointer to the character array
// count = number of characters to display (up to 40 characters)
// bright = brightness of display (1 to 15)
command result_t scrollInit(char *c, uint8 count, uint8 bright);
// Sets the refresh rate of scroll
// refresh = refresh interval (in msec)
command result_t setRefresh(int refresh);
// Update the link quality status indicator
// dispID = ID of the link quality indicator. The indicators use
// the right 2 (or 1) characters of the display in according
// to the following placement:
// | 2 | 0 |
// | 3 | 1 |
// linkQuality = link quality in the range 0:15. The number of dots
// showing up on the display indicates this value
command result_t linkStatusDisp(uint8 dispID, uint8 linkQuality);
}
--- NEW FILE: AlphaDispM.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#define TIC TOSH_SET_LED7_PIN();TOSH_CLR_LED7_PIN()
#define RS_LOW TOSH_CLR_LED2_PIN()
#define RS_HI TOSH_SET_LED2_PIN()
#define CE_LOW TOSH_CLR_LED5_PIN()
#define CE_HI TOSH_SET_LED5_PIN()
#define SEND0 TOSH_CLR_LED6_PIN()
#define SEND1 TOSH_SET_LED6_PIN()
#define TABLE_SZ 96*5
#define REMOVED 32
#define NUM_DISP_CHAR 4
#define MAX_NUM_STAT_CHAR 2
#define MAX_SCROLL_CHAR 40
#define COLUMNS_PER_CHAR 5
#define BITS_PER_COLUMN 8
module AlphaDispM {
provides {
interface AlphaDisp;
}
uses {
interface Timer;
}
}
implementation
{
char buf[TABLE_SZ]; // buffer where the Display bitmaps are stored
// format is 5 bytes per ASCII character
// each byte corresponds to a column in the bitmap
char outbuf[NUM_DISP_CHAR*COLUMNS_PER_CHAR];
uint8 num_active; // number of characters available to staticDisp() and scrollInit()
uint8 num_status; // number of characters used to display status
char status_bitmap[COLUMNS_PER_CHAR*MAX_NUM_STAT_CHAR]; // status can use up to 10 columns of display
int s_len, s_i;
char s_bitmap[MAX_SCROLL_CHAR*COLUMNS_PER_CHAR+NUM_DISP_CHAR*COLUMNS_PER_CHAR];
int refresh_rate; // number of msec
void blankDisp();
void setBright(uint8 bright);
void updateDisp (char *buffer);
char* copyBitmap (char *dest, char *src);
command result_t AlphaDisp.init(uint8 numStatus) {
int i;
//uint8 c;
char buf_i[TABLE_SZ] = {
// The first 32 characters of the ASCII table are control characters which are not
// used in the display. Therefor the corresponding bitmap is commented out to save
// memory.
/*0x3f,0x3f,0x3f,0x3f,0x0,0x8,0x1c,0x3e,0x1c,0x8,0x2a,0x15,0x2a,0x15,0x0,0xf,0x12,0x7f,0x10,0x0,
0xf,0x5,0x78,0x28,0x0,0x7,0x7d,0x28,0x50,0x0,0x7,0x4,0x78,0x28,0x0,0x0,0x2,0x5,0x2,0x0,
0x0,0x12,0x17,0x12,0x0,0xf,0x2,0x74,0x4f,0x0,0x7,0x18,0x77,0x10,0x0,0x8,0x8,0xf,0x0,0x0,
0x8,0x8,0x78,0x0,0x0,0x0,0x0,0x78,0x8,0x8,0x0,0x0,0xf,0x8,0x8,0x8,0x8,0x7f,0x8,0x8,
0x2,0x2,0x2,0x2,0x2,0x4,0x4,0x4,0x4,0x4,0x8,0x8,0x8,0x8,0x8,0x10,0x10,0x10,0x10,0x10,
0x20,0x20,0x20,0x20,0x20,0x0,0x0,0x7f,0x8,0x8,0x8,0x8,0x7f,0x0,0x0,0x8,0x8,0xf,0x8,0x8,
0x8,0x8,0x78,0x8,0x8,0x0,0x0,0x7f,0x0,0x0,0x0,0x24,0x2a,0x31,0x0,0x0,0x31,0x2a,0x24,0x0,
0x0,0x3c,0x4,0x3c,0x0,0x0,0x34,0x1c,0x16,0x0,0x28,0x1c,0x2a,0x22,0x0,0x0,0x0,0x8,0x0,0x0,*/
0x0,0x0,0x0,0x0,0x0,0xa,0x0,0x75,0x0,0xa,0x0,0x7,0x0,0x7,0x0,0x14,0x3e,0x14,0x3e,0x14,
0x4,0x2a,0x3e,0x2a,0x10,0x13,0x8,0x4,0x32,0x0,0x14,0x2a,0x14,0x20,0x0,0x4,0x3,0x1,0x0,0x0,
0x0,0x1e,0x21,0x0,0x0,0x0,0x21,0x1e,0x0,0x0,0x2a,0x1c,0x2a,0x0,0x0,0x8,0x8,0x3e,0x8,0x8,
0x40,0x30,0x10,0x0,0x0,0x8,0x8,0x8,0x8,0x0,0x0,0x30,0x30,0x0,0x0,0x10,0x8,0x4,0x2,0x0,
0x1e,0x21,0x1e,0x0,0x0,0x22,0x3f,0x20,0x0,0x0,0x22,0x31,0x29,0x26,0x0,0x11,0x25,0x25,0x1b,0x0,
0xc,0xa,0x3f,0x8,0x0,0x17,0x25,0x25,0x19,0x0,0x1e,0x25,0x25,0x18,0x0,0x1,0x31,0xd,0x3,0x0,
0x1a,0x25,0x25,0x1a,0x0,0x6,0x29,0x29,0x1e,0x0,0x0,0x36,0x36,0x0,0x0,0x40,0x36,0x16,0x0,0x0,
0x8,0x14,0x22,0x0,0x0,0x14,0x14,0x14,0x14,0x0,0x22,0x14,0x8,0x0,0x0,0x2,0x29,0x6,0x0,0x0,
0x1e,0x21,0x2d,0xe,0x0,0x3e,0x9,0x9,0x3e,0x0,0x3f,0x25,0x25,0x1a,0x0,0x1e,0x21,0x21,0x12,0x0,
0x3f,0x21,0x21,0x1e,0x0,0x3f,0x25,0x25,0x21,0x0,0x3f,0x5,0x5,0x1,0x0,0x1e,0x21,0x29,0x3a,0x0,
0x3f,0x4,0x4,0x3f,0x0,0x21,0x3f,0x21,0x0,0x0,0x10,0x20,0x20,0x1f,0x0,0x3f,0xc,0x12,0x21,0x0,
0x3f,0x20,0x20,0x20,0x0,0x3f,0x6,0x6,0x3f,0x0,0x3f,0x6,0x18,0x3f,0x0,0x1e,0x21,0x21,0x1e,0x0,
0x3f,0x9,0x9,0x6,0x0,0x1e,0x31,0x21,0x5e,0x0,0x3f,0x9,0x19,0x26,0x0,0x12,0x25,0x29,0x12,0x0,
0x1,0x3f,0x1,0x0,0x0,0x1f,0x20,0x20,0x1f,0x0,0xf,0x30,0x30,0xf,0x0,0x3f,0x18,0x18,0x3f,0x0,
0x33,0xc,0xc,0x33,0x0,0x7,0x38,0x7,0x0,0x0,0x31,0x29,0x25,0x23,0x0,0x3f,0x21,0x21,0x0,0x0,
0x2,0x4,0x8,0x10,0x0,0x21,0x21,0x3f,0x0,0x0,0x2,0x1,0x2,0x0,0x0,0x20,0x20,0x20,0x20,0x0,
0x1,0x3,0x4,0x0,0x0,0x18,0x24,0x14,0x3c,0x0,0x3f,0x24,0x24,0x18,0x0,0x18,0x24,0x24,0x0,0x0,
0x18,0x24,0x24,0x3f,0x0,0x18,0x34,0x2c,0x8,0x0,0x8,0x3e,0x9,0x2,0x0,0x28,0x54,0x54,0x4c,0x0,
0x3f,0x4,0x4,0x38,0x0,0x24,0x3d,0x20,0x0,0x0,0x20,0x40,0x3d,0x0,0x0,0x3f,0x8,0x14,0x20,0x0,
0x21,0x3f,0x20,0x0,0x0,0x3c,0x8,0xc,0x38,0x0,0x3c,0x4,0x4,0x38,0x0,0x18,0x24,0x24,0x18,0x0,
0x7c,0x24,0x24,0x18,0x0,0x18,0x24,0x24,0x7c,0x0,0x3c,0x4,0x4,0x8,0x0,0x28,0x2c,0x34,0x14,0x0,
0x4,0x1f,0x24,0x20,0x0,0x1c,0x20,0x20,0x3c,0x0,0x1c,0x20,0x1c,0x0,0x0,0x3c,0x30,0x30,0x3c,0x0,
0x24,0x18,0x18,0x24,0x0,0xc,0x50,0x20,0x1c,0x0,0x24,0x34,0x2c,0x24,0x0,0x4,0x1e,0x21,0x0,0x0,
0x0,0x3f,0x0,0x0,0x0,0x21,0x1e,0x4,0x0,0x0,0x2,0x1,0x2,0x1,0x0};
/* clear DOT register */
blankDisp();
/* set to lowest power consumption */
setBright(1);
/* initialize the bitmap table */
for (i=0; i<TABLE_SZ; i++)
buf[i]=buf_i[i];
if (numStatus<=2) {
num_status = numStatus;
num_active = NUM_DISP_CHAR - numStatus;
}
else {
num_status = 0;
num_active = NUM_DISP_CHAR;
}
for (i=0; i<numStatus*COLUMNS_PER_CHAR; i++)
status_bitmap[i]=0;
refresh_rate = 300; // default rate of update is 300 msec
return SUCCESS;
}
// put display to sleep
command result_t AlphaDisp.sleep() {
uint8 c;
int i;
call Timer.stop();
RS_HI;
CE_LOW;
c = 0x00;
for (i=7; i>=0; i--) {
if ((c & (1<<i)) == 0)
SEND0;
else
SEND1;
TIC;
}
CE_HI;
return SUCCESS;
}
// display static characters
command result_t AlphaDisp.staticDisp(char *c, uint8 count, uint8 bright) {
int i;
char *buf_ptr, *bitmap_ptr, c_temp;
uint16 buf_st;
if (count>num_active)
count = num_active;
call Timer.stop(); // disable the scrolling
blankDisp();
setBright(bright);
bitmap_ptr = &outbuf[0];
for (i=0; i<count; i++) {
c_temp = c[i] & 0x7f;
buf_st = (c_temp-REMOVED)*COLUMNS_PER_CHAR;
buf_ptr = &buf[buf_st];
bitmap_ptr=copyBitmap(bitmap_ptr, buf_ptr);
}
if (num_status>2)
buf_ptr = &status_bitmap[0];
else
buf_ptr = &status_bitmap[5];
//for (i=count; i<NUM_DISP_CHAR; i++)
// bitmap_ptr=copyBitmap(bitmap_ptr, buf_ptr);
updateDisp(outbuf);
return SUCCESS;
}
// scroll the characters continuously
command result_t AlphaDisp.scrollInit(char *c, uint8 count, uint8 bright) {
int i, buf_st;
char *bitmap_ptr, *buf_ptr, c_temp;
blankDisp();
setBright(bright);
s_len = count*COLUMNS_PER_CHAR+NUM_DISP_CHAR*COLUMNS_PER_CHAR; // blank the first 4 characters
bitmap_ptr = &s_bitmap[0];
for (i=0; i<NUM_DISP_CHAR*COLUMNS_PER_CHAR; i++)
*bitmap_ptr++=0;
for (i=0; i<count; i++) {
c_temp = c[i] & 0x7f;
buf_st = (c_temp-REMOVED)*COLUMNS_PER_CHAR;
buf_ptr = &buf[buf_st];
bitmap_ptr=copyBitmap(bitmap_ptr, buf_ptr);
}
s_i = 0;
call Timer.start(TIMER_REPEAT, refresh_rate);
return SUCCESS;
}
// set refresh rate
// refresh value is in msec
command result_t AlphaDisp.setRefresh(int refresh) {
refresh_rate = refresh;
call Timer.start(TIMER_REPEAT, refresh_rate);
return SUCCESS;
}
// update scroll characters
event result_t Timer.fired() {
//char outbuf[COLUMNS_PER_CHAR*NUM_DISP_CHAR];
int i, offset, offset2;
for (i=0; i<COLUMNS_PER_CHAR*num_active; i++) {
if (s_i==s_len)
s_i = 0;
outbuf[i]=s_bitmap[s_i++];
}
s_i = s_i-(num_active-1)*COLUMNS_PER_CHAR;
if (s_i<0)
s_i = s_len+s_i;
offset = i;
offset2 = 0;
if (num_status <=2)
offset2 = 5;
for (i=0; i<num_status*COLUMNS_PER_CHAR; i++)
outbuf[i+offset]=status_bitmap[i+offset2];
updateDisp(outbuf);
return SUCCESS;
}
// update status character bitmap according to linkQuality value
command result_t AlphaDisp.linkStatusDisp(uint8 dispId, uint8 linkQuality) {
char temp[15], tempBitmap[COLUMNS_PER_CHAR], *ptr, mask;
int i, j, sh;
//if ((dispId>>1) != (num_status>>1))
// return FAIL;
for (i=0; i<linkQuality; i++)
temp[i]=1;
for (i=linkQuality; i<15; i++)
temp[i]=0;
ptr = &temp[0];
for (i=0; i<COLUMNS_PER_CHAR; i++) {
tempBitmap[i]=0;
for (j=0; j<3; j++)
tempBitmap[i] = tempBitmap[i] | (*ptr++ << j);
}
if ((dispId&1) == 0) {
mask = 0x70;
sh = 0;
}
else {
mask = 0x07;
sh = 4;
}
if ((dispId&2) == 0)
//ptr = &status_bitmap[5];
ptr = &outbuf[15];
else
//ptr = &status_bitmap[0];
ptr = &outbuf[10];
for (i=0; i<COLUMNS_PER_CHAR; i++) {
*ptr = *ptr & mask;
*ptr = *ptr++ | (tempBitmap[i] << sh);
}
updateDisp(outbuf);
return SUCCESS;
}
// display the bitmap stored in outbuf
void updateDisp (char *buffer) {
int i, j;
RS_LOW;
CE_LOW;
for (i=0; i<COLUMNS_PER_CHAR*NUM_DISP_CHAR; i++) {
for (j=7; j>=0; j--) {
if ((buf[i] & (1<<j)) == 0)
SEND0;
else
SEND1;
TIC;
}
}
CE_HI;
}
// put display to sleep
void blankDisp() {
int i;
RS_LOW;
CE_LOW;
for (i=0; i<BITS_PER_COLUMN*COLUMNS_PER_CHAR*NUM_DISP_CHAR; i++) {
SEND0;
TIC;
}
CE_HI;
}
// set brightness of display
// bright = 1 ---->> dimest
// bright = 15 ---->> brightest
void setBright(uint8 bright) {
uint8 ctrl;
int i;
RS_HI;
CE_LOW;
ctrl = 0x60 | (bright&0xf);
for (i=7; i>=0; i--) {
if ((ctrl & (1<<i)) == 0)
SEND0;
else
SEND1;
TIC;
}
CE_HI;
}
// copy the bitmap of 1 ASCII character
char* copyBitmap (char *dest, char *src) {
*dest++ = *src++;
*dest++ = *src++;
*dest++ = *src++;
*dest++ = *src++;
*dest++ = *src++;
return dest;
}
}
--- NEW FILE: BluSH.h ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
// Number of interfaces.
#define __BLUSH_APP_COUNT__ uniqueCount("BluSH")
enum
{
BLUSH_APP_COUNT = __BLUSH_APP_COUNT__
};
--- NEW FILE: BluSHC.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
configuration BluSHC {
provides interface StdControl;
uses interface BluSH_AppI[uint8_t id];
}
implementation {
components
//UARTBufferC as UARTBuffer,
DebugUARTBufferC as UARTBuffer,
NetworkCommandM,
BluSHM;
StdControl = BluSHM;
BluSHM.UartControl -> UARTBuffer.Control;
BluSHM.UartSend -> UARTBuffer.SendVarLenPacket;
BluSHM.UartReceive -> UARTBuffer.ReceiveData;
BluSHM.NetworkCommand -> NetworkCommandM;
BluSH_AppI = BluSHM;
}
--- NEW FILE: BluSHM.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
module BluSHM {
provides
{
interface StdControl;
}
uses
{
interface StdControl as UartControl;
interface SendVarLenPacket as UartSend;
interface ReceiveData as UartReceive;
interface NetworkCommand;
interface BluSH_AppI[uint8_t id];
}
}
implementation
{
#include "cmdlinetools.c"
#include "BluSH_types.h"
#define BLUSH_PROMPT_LENGTH 32
char blush_prompt[ BLUSH_PROMPT_LENGTH ];
// Index 0 is the current command line.
#define BLUSH_HISTORY_LENGTH 2
#define BLUSH_CMDLINE_LENGTH 40
char blush_history[ BLUSH_HISTORY_LENGTH ][ BLUSH_CMDLINE_LENGTH ];
uint16_t blush_cmdline_idx;
uint16_t blush_history_idx;
uint8_t funcIdx;
uint8_t funcIdxInUse;
char funcCmd[ BLUSH_CMDLINE_LENGTH ];
#define MAX_RETURN_STRING 255
// Internal commands: help, ls, prompt, readmem, writemem.
void TraceCallback(char *buf, uint16 buflen) __attribute__((C, spontaneous)){
call UartSend.send(buf,buflen);
}
command result_t StdControl.init()
{
uint16_t i;
uint32_t my_nodeid;
blush_cmdline_idx = 0;
blush_history_idx = 0;
funcIdxInUse = 0;
// Clear history.
for( i = 0; i < BLUSH_HISTORY_LENGTH; i++ )
{
blush_history[i][0] = '\0';
}
trace_set(DBG_USR1|DBG_USR2|DBG_USR3);
call UartControl.init();
call NetworkCommand.GetMoteID(&my_nodeid);
snprintf(blush_prompt,BLUSH_PROMPT_LENGTH, "%.5x>",my_nodeid);
//strncpy( blush_prompt, "BluSH>", BLUSH_PROMPT_LENGTH );
return SUCCESS;
}
command result_t StdControl.start(){
call UartControl.start();
call UartSend.send( "\r\n", strlen("\r\n") );
call UartSend.send( blush_prompt, strlen(blush_prompt) );
return SUCCESS;
}
command result_t StdControl.stop(){
call UartControl.stop();
return SUCCESS;
}
default command BluSH_result_t BluSH_AppI.getName[uint8_t id](char* buff, uint8_t len )
{
buff[0] = '\0';
return BLUSH_SUCCESS_DONE;
}
default command BluSH_result_t BluSH_AppI.callApp[uint8_t id]( char* cmdBuff, uint8_t cmdLen,
char* resBuff, uint8_t resLen )
{
resBuff[0] = '\0';
return BLUSH_SUCCESS_DONE;
}
task void ls()
{
uint8_t i;
char temp[ BLUSH_CMDLINE_LENGTH ];
for( i = 0; i < BLUSH_APP_COUNT; i++ )
{
call BluSH_AppI.getName[i]( temp, BLUSH_CMDLINE_LENGTH );
call UartSend.send( temp, strlen(temp) );
call UartSend.send( "\r\n", 2 );
}
}
task void help()
{
call UartSend.send( "Blue Shell v1.0 (BluSH)\r\n",
strlen("Blue Shell v1.0 (BluSH)\r\n") );
call UartSend.send( "help - Display this list\r\n",
strlen("help - Display this list\r\n") );
call UartSend.send( "ls - Display all application commands\r\n",
strlen("ls - Display all application commands\r\n") );
call UartSend.send( "history - Display the command history\r\n",
strlen("history - Display the command history\r\n") );
call UartSend.send( "prompt - Allows you to change the prompt\r\n",
strlen("prompt - Allows you to change the prompt\r\n") );
}
task void history()
{
uint16_t hist_idx;
for( hist_idx = BLUSH_HISTORY_LENGTH-1; hist_idx > 0; hist_idx-- )
{
if( blush_history[ hist_idx ][0] != '\0' )
{
call UartSend.send( blush_history[ hist_idx ],
strlen(blush_history[ hist_idx ]) );
call UartSend.send( "\r\n", strlen("\r\n") );
}
}
}
/*
task void prompt()
{
uint16_t frstSpc;
frstSpc = firstSpace( blush_history[0], 0 );
if( frstSpc == 0 )
{
call UartSend.send( "prompt <new prompt string>\r\n",
strlen("prompt <new prompt string>\r\n") );
}
else
{
strncpy( blush_prompt, &(blush_history[0][frstSpc+1]), BLUSH_PROMPT_LENGTH );
}
}
*/
task void printCmdLine()
{
// Print out prompt.
call UartSend.send( blush_prompt, strlen(blush_prompt) );
// Last but not least, null terminate the command line.
blush_history[0][0] = '\0';
blush_cmdline_idx = 0;
blush_history_idx = 0;
}
task void callFunc()
{
char retStr[ MAX_RETURN_STRING ];
call BluSH_AppI.callApp[funcIdx]( funcCmd, BLUSH_CMDLINE_LENGTH,
retStr, MAX_RETURN_STRING );
// Watch out for buffer overflow.
retStr[ MAX_RETURN_STRING - 1 ] = '\0';
call UartSend.send( retStr, strlen(retStr) );
funcIdxInUse = 0;
}
#define UP_ARROW 0x41
#define DOWN_ARROW 0x42
event result_t UartReceive.receive( uint8_t* buff, uint32_t numBytesRead )
{
uint16_t i, hist_idx, cmd_idx;
char temp[ BLUSH_CMDLINE_LENGTH ];
uint8_t frstSpc;
static uint8 uSpecialChar=0;
for( i = 0; i < numBytesRead; i++ )
{
// Need to look for special characters:
// ENTER is 0x0d
if( buff[i] == 0x0d )
{
// Append \0
blush_history[0][ blush_cmdline_idx ] = '\0';
// Output new line.
call UartSend.send( "\r\n", 2 );
// Get rid of whitespace.
killWhiteSpace( blush_history[0] );
// check if there is anything meaningful
if( blush_history[0][ 0 ] == '\0' )
{
// Do nothing.
post printCmdLine();
}
else
{
// Copy history
for( hist_idx = BLUSH_HISTORY_LENGTH-1; hist_idx > 0; hist_idx-- )
{
// Rollover to 65535 is intentional.
cmd_idx = -1;
do
{
cmd_idx++;
blush_history[ hist_idx ][ cmd_idx ] =
blush_history[ hist_idx-1 ][ cmd_idx ];
}
while( cmd_idx < BLUSH_CMDLINE_LENGTH
&& blush_history[ hist_idx-1 ][ cmd_idx ] != '\0' );
}
// Process cmdline.
// Look for internal commands first, then blush_app commands.
if( 0 == strncmp( "help", blush_history[0], strlen("help") ) )
{
post help();
post printCmdLine();
/*
call UartSend.send( "Blue Shell v1.0 (BluSH) Native Commands\r\n",
strlen("Blue Shell (BluSH) Native Commands\r\n") );
call UartSend.send( "help - Display this list\r\n",
strlen("help - Display this list\r\n") );
call UartSend.send( "ls - Display all application commands\r\n",
strlen("ls - Display all application commands\r\n") );
call UartSend.send( "history - Display the command history\r\n",
strlen("history - Display the command history\r\n") );
call UartSend.send( "prompt - Allows you to change the prompt\r\n",
strlen("prompt - Allows you to change the prompt\r\n") );
*/
}
else if( 0 == strncmp( "ls", blush_history[0], strlen("ls") ) )
{
post ls();
post printCmdLine();
/*
for( i = 0; i < BLUSH_APP_COUNT; i++ )
{
call BluSH_AppI.getName[i]( temp, BLUSH_CMDLINE_LENGTH );
call UartSend.send( temp, strlen(temp) );
call UartSend.send( "\r\n", 2 );
}
*/
}
else if( 0 == strncmp( "prompt", blush_history[0], strlen("prompt") ) )
{
//post prompt();
//post printCmdLine();
frstSpc = firstSpace( blush_history[0], 0 );
if( frstSpc == 0 )
{
call UartSend.send( "prompt <new prompt string>\r\n",
strlen("prompt <new prompt string>\r\n") );
}
else
{
strncpy( blush_prompt, &(blush_history[0][frstSpc+1]), BLUSH_PROMPT_LENGTH );
}
post printCmdLine();
}
else if( 0 == strncmp( "history", blush_history[0], strlen("history") ) )
{
post history();
post printCmdLine();
/*
for( hist_idx = BLUSH_HISTORY_LENGTH-1; hist_idx > 0; hist_idx-- )
{
if( blush_history[ hist_idx ][0] != '\0' )
{
call UartSend.send( blush_history[ hist_idx ],
strlen(blush_history[ hist_idx ]) );
sprintf( temp, "%d", strlen(blush_history[ hist_idx ]) );
//call UartSend.send( temp,
//strlen(temp) );
call UartSend.send( "\r\n", strlen("\r\n") );
}
}
*/
}
else
{
if( funcIdxInUse == 0 )
{
// Loop through app commands.
for( i = 0; i < BLUSH_APP_COUNT; i++ )
{
call BluSH_AppI.getName[i]( temp, BLUSH_CMDLINE_LENGTH );
if( (strncmp( temp,
blush_history[0],
strlen(temp)) == 0)
&& ((blush_history[0][strlen(temp)] == ' ')
|| (blush_history[0][strlen(temp)] == '\0')) )
{
funcIdx = i;
funcIdxInUse = 1;
strcpy( funcCmd, blush_history[0] );
post callFunc();
/*
call BluSH_AppI.callApp[i]( blush_history[0], BLUSH_CMDLINE_LENGTH,
temp2, BLUSH_CMDLINE_LENGTH );
call UartSend.send( temp2, strlen(temp2) );
*/
break;
}
}
if( i == BLUSH_APP_COUNT )
{
call UartSend.send( "Bad command\r\n", strlen("Bad command\r\n") );
}
}
else
{
call UartSend.send( "Shell Busy\r\n",
strlen("Shell Busy\r\n") );
}
post printCmdLine();
}
}
/*
// Print out prompt.
call UartSend.send( blush_prompt, strlen(blush_prompt) );
// Last but not least, null terminate the command line.
blush_history[0][0] = '\0';
blush_cmdline_idx = 0;
blush_history_idx = 0;
*/
}
// CTRL-C
else if( buff[i] == 0x03 )
{
// Discard history.
blush_cmdline_idx = 0;
blush_history_idx = 0;
blush_history[0][0] = '\0';
// print out new line and prompt.
call UartSend.send( "\r\n", 2 );
call UartSend.send( blush_prompt, strlen(blush_prompt) );
}
// TAB is 0x09
else if( buff[i] == 0x09 )
{
// Tab completetion.
// Search through list of available names.
// Ouput correct one, or beep.
for( i = 0; i < BLUSH_APP_COUNT; i++ )
{
call BluSH_AppI.getName[i]( temp, BLUSH_CMDLINE_LENGTH );
if( strncmp( blush_history[0],
temp,
strlen(blush_history[0])) == 0 )
{
call UartSend.send( temp+strlen(blush_history[0]),
strlen(temp)-strlen(blush_history[0]) );
call UartSend.send( " ", 1 );
strcat( blush_history[0], temp+strlen(blush_history[0]) );
strcat( blush_history[0], " " );
blush_cmdline_idx = strlen(temp)+1;
// add NULL.
blush_history[0][blush_cmdline_idx] = '\0';
break;
}
}
if( i >= BLUSH_APP_COUNT )
{
// No match found. Send beep.
call UartSend.send( "\a", 1 );
}
}
// Arror keys.
else if( buff[i] == 0x1b || uSpecialChar!=0 ){
static int special_i=0;
//check to see if the current char is part of the escape sequence
switch(special_i){
case 0:
uSpecialChar=1;
special_i++;
break;
case 1:
if(buff[i]!=0x5b){
uSpecialChar=0;
special_i=0;
//at this point, we know that our escape sequence was invalid, so we should treat
//the current character as a normal character...need to fall through on the outer loop
//at the moment, I'm happy with losing a character if the escape key is pressed
continue;
}
special_i++;
break;
case 2:
uSpecialChar=buff[i];
case 3:
case 4:
case 5:
//pretty much need to assume that these characters are 0's
special_i++;
}
if( special_i == 6 && uSpecialChar == UP_ARROW ){
// Then it is an up arrow.
if( blush_history_idx < BLUSH_HISTORY_LENGTH-1 ){
blush_history_idx++;
// Erase what's currently there.
for( i = 0; i < blush_cmdline_idx; i++ ){
// send backspace space backspace sequenence
call UartSend.send("\b \b", 3 );
}
// Copy history index.
strcpy( blush_history[0], blush_history[ blush_history_idx ] );
call UartSend.send( blush_history[0], strlen(blush_history[0]) );
blush_cmdline_idx = strlen(blush_history[0]);
}
else{
call UartSend.send( "\a", 1 );
}
} // Check for up arrow.
else if( special_i == 6 && uSpecialChar == DOWN_ARROW ){
// Then it is a down arrow.
if( blush_history_idx > 0 ){
blush_history_idx--;
if( blush_history_idx == 0 ){
// Erase what's currently there.
for( i = 0; i < blush_cmdline_idx; i++ ){
// send backspace space backspace sequence
call UartSend.send("\b \b", 3 );
}
blush_cmdline_idx = 0;
blush_history[0][0] = '\0';
}
else{
// Erase what's currently there.
for( i = 0; i < blush_cmdline_idx; i++ ){
// send backspace space backspace sequence
call UartSend.send("\b \b", 3 );
}
// Copy history index.
strcpy( blush_history[0], blush_history[ blush_history_idx ] );
call UartSend.send( blush_history[0], strlen(blush_history[0]) );
blush_cmdline_idx = strlen(blush_history[0]);
}
}
else{
call UartSend.send( "\a", 1 );
}
} // check for down arrow.
if(special_i==6){
special_i=0;
uSpecialChar=0;
}
} // Special char check.
// Backspace
else if( buff[i] == '\b' )
{
if( blush_cmdline_idx > 0 )
{
// Echo the character back.
call UartSend.send( &buff[i], 1 );
// Print a space
call UartSend.send( " ", 1 );
// Echo the character back.
call UartSend.send( &buff[i], 1 );
blush_cmdline_idx--;
blush_history[0][blush_cmdline_idx] = '\0';
}
else
{
call UartSend.send( "\a", 1 );
}
}
else // Normal character.
{
// By this time we know that it's not a special character.
// Copy it into our buffer.
if( blush_cmdline_idx < BLUSH_CMDLINE_LENGTH - 1 )
{
blush_history[0][ blush_cmdline_idx ] = buff[ i ];
blush_cmdline_idx++;
// Put a \0 on the end for safety.
blush_history[0][ blush_cmdline_idx ] = '\0';
// Echo the character back.
call UartSend.send( &buff[i], 1 );
}
else
{
// Send bell back, avoid buffer overflow.
//buff[i] = '\a';
call UartSend.send( "\a", 1 );
}
}
}
return SUCCESS;
}
event result_t UartSend.sendDone(uint8_t* packet, result_t success)
{
// This function does nothing.
return SUCCESS;
}
/*
* Start of NetworkCommand interface.
*/
event result_t NetworkCommand.CommandResult( uint32 Command, uint32 value) {
return SUCCESS;
}
}
--- NEW FILE: BluSH_AppI.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* Blue Shell (BluSH) application (aka module) interface */
includes BluSH_types;
includes BluSH;
interface BluSH_AppI
{
command BluSH_result_t getName( char* buff, uint8_t len );
command BluSH_result_t callApp( char* cmdBuff, uint8_t cmdLen,
char* resBuff, uint8_t resLen );
}
--- NEW FILE: BluSH_types.h ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
enum
{
BLUSH_SUCCESS_DONE = 0,
BLUSH_SUCCESS_NOT_DONE,
BLUSH_FAIL
};
typedef uint8_t BluSH_result_t;
--- NEW FILE: Clock.nc ---
// $Id: Clock.nc,v 1.1 2005/09/06 08:27:58 lnachman Exp $
/* tab:4
* "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: Jason Hill, David Gay, Philip Levis, Nelson Lee
* Date last modified: 6/25/02
*
*
*/
/**
* The hardware clock interface.
* @author Jason Hill
* @author David Gay
* @author Philip Levis
* @author Nelson Lee
**/
includes Clock;
interface Clock {
/**
* Set the clock rate. For the specific meanings of interval
* and scale, refer to the processor data sheet. For the mica and rene:
* <p>
* <pre>
* Clock scale
* 0 - off
* 1 - 32768 ticks/second
* 2 - 4096 ticks/second
* 3 - 1024 ticks/second
* 4 - 512 ticks/second
* 5 - 256 ticks/second
* 6 - 128 ticks/second
* 7 - 32 ticks/second
* </pre>
* <p>
*
* Interval is how many ticks per clock firing.
* For example, setRate(160,7) will result in an event every 160/32
* seconds.
*
* See also: <code>Clock.h</code> for predefined macros:
*
* <p>
* <pre>
* interval scale result
* TOS_I1000PS TOS_S1000PS 1000 ticks/sec
* TOS_I100PS TOS_S100PS 100 ticks/sec
* TOS_I10PS TOS_S10PS 10 ticks/sec
* TOS_I4096PS TOS_S4096PS 4096 ticks/sec
* TOS_I2048PS TOS_S2048PS 2048 ticks/sec
* TOS_I1024PS TOS_S1024PS 1024 ticks/sec
* TOS_I512PS TOS_S512PS 512 ticks/sec
* TOS_I256PS TOS_S256PS 256 ticks/sec
* TOS_I128PS TOS_S128PS 128 ticks/sec
* TOS_I64PS TOS_S64PS 64 ticks/sec
* TOS_I32PS TOS_S32PS 32 ticks/sec
* TOS_I16PS TOS_S16PS 16 ticks/sec
* TOS_I8PS TOS_S8PS 8 ticks/sec
* TOS_I4PS TOS_S4PS 4 ticks/sec
* TOS_I2PS TOS_S2PS 2 ticks/sec
* TOS_I1PS TOS_S1PS 1 tick/sec
* TOS_I0PS TOS_S0PS 0 ticks/sec (clock off)
* </pre>
**/
async command result_t setRate(uint32_t interval, char scale);
/**
* Set clock interval
*
* @param value New clock interval
*
* @return none
**/
async command void setInterval(uint32_t value);
/**
* Set clock interval at next clock interrupt time
*
* @param value New clock interval
*
* @return none
**/
async command void setNextInterval(uint8_t value);
/**
* Get clock interval
*
* @return current clock interval
**/
async command uint8_t getInterval();
/**
* Get clock scale
*
* @return current clock scale level
**/
async command uint8_t getScale();
/**
* Set clock scale at next clock interrupt time
*
* @param scale New clock scale
*
* @return none
**/
async command void setNextScale(uint8_t scale);
/**
* Set both clock interval and scale
*
* @param interval New clock interval
*
* @param scale New clock scale
*
* @return SUCCESS or FAILED
**/
async command result_t setIntervalAndScale(uint8_t interval, uint8_t scale);
/**
* Read HW clock counter
*/
async command uint32_t readCounter() ;
/**
* Set HW clock counter to a specified value
*
* @param n Value to write to TCNT0
*
* @return None
*/
async command void setCounter(uint32_t n);
/**
* Disable Clock interrupt
*/
async command void intDisable();
/**
* Enable Clock interrupt
*/
async command void intEnable() ;
/**
* An event sent when the clock goes off.
**/
async event result_t fire();
}
--- NEW FILE: DebugC.nc ---
configuration DebugC{
provides interface StdControl;
}
implementation {
components DebugM, DebugUARTBufferC;
StdControl = DebugM;
DebugM.SendVarLenPacket -> DebugUARTBufferC;
DebugM.SendVarLenPacketControl -> DebugUARTBufferC;
}
--- NEW FILE: DebugM.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
module DebugM {
provides {
interface StdControl as DebugControl;
}
uses {
interface SendVarLenPacket;
interface StdControl as SendVarLenPacketControl;
}
}
implementation {
#include "motelib.h"
void TraceCallback(char *buf, uint16 buflen) __attribute__((C, spontaneous)){
call SendVarLenPacket.send(buf,buflen);
}
command result_t DebugControl.init(){
trace_set(DBG_ALL);
return call SendVarLenPacketControl.init();
}
command result_t DebugControl.start(){
return call SendVarLenPacketControl.start();
}
command result_t DebugControl.stop(){
return call SendVarLenPacketControl.stop();
}
event result_t SendVarLenPacket.sendDone(uint8* data, result_t suc) {
return suc;
}
}
--- NEW FILE: DebugUART.nc ---
// $Id: DebugUART.nc,v 1.1 2005/09/06 08:27:58 lnachman Exp $
/* tab:4
* "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: Jason Hill, David Gay, Philip Levis
* Date last modified: 6/25/02
*
*/
/**
* @author Jason Hill
* @author David Gay
* @author Philip Levis
*/
configuration DebugUART {
provides {
interface ByteComm;
interface StdControl as Control;
}
}
implementation {
components DebugUARTM, HPLDebugUartC;
ByteComm = DebugUARTM;
Control = DebugUARTM;
DebugUARTM.HPLUART -> HPLDebugUartC;
}
--- NEW FILE: DebugUARTBufferC.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
configuration DebugUARTBufferC {
provides {
interface StdControl as Control;
interface SendVarLenPacket;
interface ReceiveData;
}
}
implementation {
components DebugUARTBufferM, DebugUART;
Control = DebugUARTBufferM;
SendVarLenPacket = DebugUARTBufferM;
ReceiveData = DebugUARTBufferM;
DebugUARTBufferM.ByteComm -> DebugUART;
DebugUARTBufferM.ByteControl -> DebugUART;
}
--- NEW FILE: DebugUARTBufferM.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This module maintains a buffer of characters to put on the UART.
* It copies incoming characters into the buffer and streams them out the
* UART as each previous character finishes.
*/
module DebugUARTBufferM {
provides {
interface StdControl as Control;
interface SendVarLenPacket;
interface ReceiveData;
}
uses {
interface ByteComm;
interface StdControl as ByteControl;
}
}
implementation
{
uint32 Head; // Next entry in the buffer to fill
uint32 Tail; // Oldest entry in the buffer
// Head == Tail -> buffer is empty
#define NEXT_BUFFER(ent, max) (((ent) >= ((max) - 1)) ? 0 : ((ent) + 1))
#define BUFFER_SIZE 100 // maximum characters buffered in the queue
char Buffer[BUFFER_SIZE]; // circular buffer of characters
bool BytePending; // whether there is a byte sent w/o a
// corresponding sendDone
/*
* Start of StdControl interface
*/
command result_t Control.init() {
Head = 0;
Tail = 0;
atomic {
BytePending = FALSE;
}
return call ByteControl.init();
}
command result_t Control.start() {
return call ByteControl.start();
}
command result_t Control.stop() {
return call ByteControl.stop();
}
/*
* End of StdControl interface
*/
result_t SendNextByte() {
bool busy;
atomic {
busy = (BytePending == TRUE);
}
if (busy) {
return FAIL;
}
if (Head == Tail) return SUCCESS; // buffer is empty
atomic {
BytePending = TRUE;
}
call ByteComm.txByte(Buffer[Tail]);
// if (call ByteComm.txByte(Buffer[Tail]) == FAIL) {
// // UART not enabled
// Tail = Head;
// BytePending = FALSE;
// }
return SUCCESS;
}
/*
* Start of SendVarLenPacket interface
*/
command result_t SendVarLenPacket.send(uint8* data, uint8 length) {
int i, size;
bool not_busy;
// see if there's enough room for this packet
size = (Head < Tail) ? Head + BUFFER_SIZE - Tail : Head - Tail;
if (size + length >= BUFFER_SIZE) return FAIL; // not enough room
// copy incoming bytes to the buffer
for (i = 0; i < length; i++) {
Buffer[Head] = data[i];
Head = NEXT_BUFFER(Head, BUFFER_SIZE);
}
atomic {
not_busy = (BytePending == FALSE);
}
if (not_busy) SendNextByte();
return SUCCESS;
}
default event result_t SendVarLenPacket.sendDone(uint8* data, result_t suc) {
return suc;
}
/*
* End of SendVarLenPacket interface
*/
/*
* Start of ByteComm interface
*/
async event result_t ByteComm.txByteReady(bool success) {
atomic {
BytePending = FALSE;
}
if (Head == Tail) return SUCCESS;
Tail = NEXT_BUFFER(Tail, BUFFER_SIZE);
SendNextByte();
return SUCCESS;
}
// this appears to be redundant in the interface with txByteReady
async event result_t ByteComm.txDone() { return SUCCESS; }
async event result_t ByteComm.rxByteReady(uint8 data, bool error, uint16_t str) {
signal ReceiveData.receive(&data, 1);
return SUCCESS;
}
/*
* End of ByteComm interface
*/
/*
* Start of ReceiveData interface
*/
default event result_t ReceiveData.receive(uint8* Data, uint32 Length) {
return SUCCESS;
}
/*
* End of ReceiveData interface
*/
}
--- NEW FILE: DebugUARTM.nc ---
// $Id: DebugUARTM.nc,v 1.1 2005/09/06 08:27:58 lnachman Exp $
/* tab:4
* "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: Jason Hill, David Gay, Philip Levis
* Date last modified: 5/27/03
*
* 5/27/03 pal Added atomic sections for safety.
*
*/
/**
* @author Jason Hill
* @author David Gay
* @author Philip Levis
*/
module DebugUARTM {
provides {
interface ByteComm;
interface StdControl as Control;
}
uses {
interface HPLUART;
}
}
implementation
{
bool state;
command result_t Control.init() {
dbg(DBG_BOOT, "UART initialized\n");
atomic {
state = FALSE;
}
return SUCCESS;
}
command result_t Control.start() {
return call HPLUART.init();
}
command result_t Control.stop() {
return call HPLUART.stop();
}
async event result_t HPLUART.get(uint8_t data) {
// Changed SRM 7.8.02 -- No reason to clear state just because
// we received some data, I think...
// state = FALSE;
signal ByteComm.rxByteReady(data, FALSE, 0);
dbg(DBG_UART, "signal: state %d\n", state);
return SUCCESS;
}
async event result_t HPLUART.putDone() {
bool oldState;
atomic {
dbg(DBG_UART, "intr: state %d\n", state);
oldState = state;
state = FALSE;
}
/* Note that the state transition/event signalling is not atomic.
It is possible, after state has been set to FALSE, that
someone calls txByte before txDone is signalled. The event
handler therefore may not be able to transmit. Sharing
the byte level can be very tricky, unless we assure non-preemptiveness
or have client ids. The UART implementation is non-preemptive,
but is not assuredly so. -pal*/
if (oldState) {
signal ByteComm.txDone();
signal ByteComm.txByteReady(TRUE);
}
return SUCCESS;
}
async command result_t ByteComm.txByte(uint8_t data) {
bool oldState;
dbg(DBG_UART, "UART_write_Byte_inlet %x\n", data);
atomic {
oldState = state;
state = TRUE;
}
if (oldState)
return FAIL;
call HPLUART.put(data);
return SUCCESS;
}
}
--- NEW FILE: FileSystem.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
includes FileSystemTypes;
interface FileSystem{
result_t async command create(userId_t ID, uint16_t size);
result_t async command delete(userId_t ID);
uint16_t async command append(userId_t ID, uint8_t *buffer, uint16_t size);
uint16_t async command write(userId_t ID, uint8_t *buffer, uint16_t location, uint16_t size);
uint16_t async command getFileSize(userId_t ID);
uint16_t async command read(userId_t ID, uint8_t *buffer, uint16_t location, uint16_t length);
result_t async command commit(userId_t ID);
result_t async command getFileInfo(FileInfo* fi);
}
--- NEW FILE: FileSystemM.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
[...1048 lines suppressed...]
}
result_t async command FileSystem.getFileInfo(FileInfo* fi){
uint16_t i,j;
result_t success=!SUCCESS;
j=0;
atomic{
for(i=0;i<MAX_FILES;i++){
if(bootSector.record[i].flags&CREATED){
fi[j].ID = bootSector.record[i].userId;
fi[j].size = bootSector.record[i].size;
j++;
success=SUCCESS;
}
}
}
return success;
}
}
--- NEW FILE: FileSystemTypes.h ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
typedef uint16_t zeevoId_t;
typedef uint16_t userId_t;
typedef uint8_t magicNum_t ;
typedef struct{
userId_t ID;
uint16_t size;
}FileInfo;
#define FS_DEBUG
#ifdef FS_DEBUG
//#define WRITE_CRASH_ID 666 //(this is for testing boot crash)
//#define MAX_ZEEVO_IDS 4 // this is for testing failure of zeevo
//id distribution
#endif
--- NEW FILE: Flash.h ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Defines to mirror unix file io
*/
enum {
FFS_O_RDONLY = 0x0000,
FFS_O_WRONLY = 0x0001,
FFS_O_RDWR = 0x0002,
FFS_O_APPEND = 0x0008,
FFS_O_CREAT = 0x0200,
FFS_O_TRUNC = 0x0400
};
enum {
FFS_SEEK_SET = 0x1,
FFS_SEEK_CUR = 0x2,
FFS_SEEK_END = 0x3
};
// Zeevo recomends < 200 B block size so make things simple by rounding to a
// power of 2. Must match block size in config file
enum {
BLOCK_SIZE = 256
};
--- NEW FILE: Flash.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Interface for directly manipulating the flash.
*/
includes Flash;
interface Flash {
/*
* Gets a memory pointer to a block for reading. In this implementation
* the memory is accessed directly from flash. This pointer cannot be used
* to modify the contents in flash. Any writes to the pointer will result
* in unpredicted behavior.
*/
command void *getReadBlock(int blockIndex);
/*
* Gets a memory pointer to a block for writing. The contents of the block
* can be read or written using this pointer. Changes to the block are not
* committed until the commitBlock command is called.
*/
command void *getWriteBlock(int blockIndex);
/*
* Write a block from core memory back into flash memory and deallocate the
* pointer. Future writes to the same block must first call getWriteBlock.
*/
command result_t commitBlock(int blockIndex);
}
--- NEW FILE: FlashAccessM.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
module FlashAccessM
{
provides {
interface StdControl as FlashControl;
interface LoggerWrite as FlashWrite;
interface LoggerRead as FlashRead;
}
uses {
interface Leds;
}
}
implementation{
uint16_t curFlashWriteID, curFlashReadID;
uint16_t rec_size=1024;
command result_t FlashControl.init() {
// TM_InitFlashControl();
// bool res = TM_InitFlashDynamicDB();
curFlashWriteID = TM_FLASH_LAST_USER_ID-TM_FLASH_MAX_RECS;
curFlashReadID = TM_FLASH_LAST_USER_ID-TM_FLASH_MAX_RECS;
call Leds.init();
}
command result_t FlashControl.start() {
}
command result_t FlashControl.stop() {
}
command result_t FlashRead.read(uint16_t ID, uint8_t *buffer){
uint8_t *rd_ptr;
result_t result;
rd_ptr = TM_API_GetFlashReadPtr(ID);
if(rd_ptr){
result = SUCCESS;
//call Leds.greenToggle();
}
else
result = !SUCCESS;
buffer = rd_ptr;
return signal FlashRead.readDone(rd_ptr,result);
}
command result_t FlashRead.readNext(uint8_t *buffer){
curFlashReadID++;
return call FlashRead.read(curFlashReadID,buffer);
}
command result_t FlashRead.resetPointer(){
curFlashReadID = TM_FLASH_LAST_USER_ID - TM_FLASH_MAX_RECS;
return SUCCESS;
}
command result_t FlashRead.setPointer(uint16_t ID){
curFlashReadID = ID;
}
command result_t FlashWrite.append(uint8_t *buffer){
curFlashWriteID++;
return call FlashWrite.write(curFlashWriteID,buffer);
}
command result_t FlashWrite.write(uint16_t ID, uint8_t* buffer){
uint8_t* wrt_ptr;
result_t result;
wrt_ptr = TM_API_GetFlashWritePtr(ID,rec_size);
if(wrt_ptr){
//memcpy(wrt_ptr,buffer,16);
TM_API_FlashWriteDone(ID);
result=SUCCESS;
//call Leds.greenToggle();
}
else{
result=!SUCCESS;
//call Leds.greenToggle();
}
return signal FlashWrite.writeDone(result);
}
command result_t FlashWrite.resetPointer(){
curFlashWriteID = TM_FLASH_LAST_USER_ID - TM_FLASH_MAX_RECS;
return SUCCESS;
}
command result_t FlashWrite.setPointer(uint16_t ID){
curFlashReadID = ID;
}
}
--- NEW FILE: FlashFS.h ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Defines and typedef's for inode structure
*/
#define MAX_NAME_LENGTH 10 // arbitrary; chosen to align to 16B
#define MAX_INODE 3 // making this larger breaks the assumption that
// all inodes are in the 0-page
#define ZERO_LEVEL_BLOCKS 4 // Number of direct block indexes contained in the
// inode
#define FIRST_LEVEL_BLOCKS 8 // Number of first level block indexes contained
// in the inode
#define FINODE_VALID 0xABCD
typedef struct {
char name[MAX_NAME_LENGTH];
uint16 flags;
uint32 fileSize;
int16_t dataBlock[ZERO_LEVEL_BLOCKS];
int16_t firstLevel[FIRST_LEVEL_BLOCKS];
} FInode;
--- NEW FILE: FlashFS.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
includes Flash;
includes FlashFS;
interface FlashFS {
/*
* Opens a file for reading or writing. If the file does not exist and the
* FFS_O_CREAT flag is set then a new file is created. The return value is
* a file descriptor used by the other file io functions or a -1 if there
* was an error.
*/
command int open(char *name, int flags);
/*
* Moves the read/ write pointer within a file. The whence flag indicates
* whether the new location is relative to the beginning, current location,
* or end of the file.
*/
command void lseek(int fd, int offset, int whence);
/*
* Copy the contents of the file to the buffer and advance the index pointer
* by size. The return value is the nuber of bytes read.
*/
command int read (int fd, char *inbuf, int size);
/*
* Copy the contents fo the buffer to the file and advance the index pointer.
* The return value is the number of bytes copied.
*/
command int write (int fd, char *outbuf, int size);
/*
* Close the file and commit all of the changes to flash. The return value
* is -1 if there was an error.
*/
command int close (int fd);
/*
* Write the in-core contents of the file back to the storage device.
*/
command int flush (int fd);
/*
* Release the storage associated with the file name. The contents of the
* file may not be 0'd out. If an error occurs, -1 is returned.
*/
command int delete (char *name);
/*
* Get a pointer to the inode data structure. This should only be used to
* display the contents of the structure. Any modification of the structure
* will result in unpredictable behavior. The parameter next is an index
* for the next value to return. To start at the beginning, set next to 0.
* When the last element is returned, next is set to -1.
*/
command FInode *getInode(int *next);
}
--- NEW FILE: FlashFSC.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
configuration FlashFSC {
provides {
interface StdControl as FlashControl;
interface FlashFS;
}
}
implementation {
components FlashFSM, HPLFlashM;
FlashControl = FlashFSM;
FlashFS = FlashFSM;
FlashFSM.Flash -> HPLFlashM;
}
--- NEW FILE: FlashFSM.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This file system is loosely modeled after the unix file system with the
* following paramters:
* Block size = 128B (page size == block size)
* i-node structure = 40B
* File i-nodes are limited to block 0
* Used page bitmask occupies block 1 => 128KB max
* i-node contains 4 direct block indexes
* i-node contains 8 1st level index blocks so max theoretical size =
* (4 + 8 * 64) * 128B ~= 66 KB
*
* No attempt is made to load balance the writes.
*/
module FlashFSM {
provides {
interface StdControl as Control;
interface FlashFS;
}
uses {
interface Flash;
}
}
implementation
{
#define MAX_FD 3 // can't be larger than MAX_INODE
#define MAX_BLOCKS 1024 // arbitrary
#define INDEXES_PER_BLOCK (BLOCK_SIZE >> 1) // assume 2B per index
// macros to generate the index of a block within the first and second level
// tables
#define FINDEX(block) (((block) - ZERO_LEVEL_BLOCKS) & (INDEXES_PER_BLOCK -1))
#define SINDEX(block) (((block) - ZERO_LEVEL_BLOCKS) >> IndexBits)
typedef struct fileDescriptor {
uint32 inode; // index into FInode structure
uint32 fileOffset; // current pointer offset into the file
bool valid; // whether this fd is currently valid
int Mode; // Current file access mode R, W, RW
int currentBlock; // index of physical block of current pointer
// -1 if no blocks are open for writting
char *mptr; // pointer to page currently open for writting
int fBlock; // block id of the first level block open for
// writing; -1 if no blocks are open
int16_t *fptr; // pointer to currently open first level index
// page
} fileDescriptor;
fileDescriptor fDesc[MAX_FD];// statically allocate space for the maximum
// number of files
uint32 FlashBase; // starting block id for lower level flash
// filesystem
FInode *inode; // array pointer to the 0-page inode table
// When inode == NULL, there are no open files
char *usedPages; // array pointer to the 1-page bit mask of
// used blocks
int lastEmptyPage; // index into usedPages array indicating where
// the last empty page came from. This is just
// an optimization to accellerate finding the
// next empty page.
int BlockBits; // optimization for manipulating offsets
int IndexBits; // optimization for manipulating offsets
/*
* Start of StdControl interface.
*/
command result_t Control.init() {
int i;
inode = NULL;
usedPages = NULL;
lastEmptyPage = 0;
for (i = 0; i < MAX_FD; i++) {
fDesc[i].valid = FALSE;
fDesc[i].currentBlock = -1;
fDesc[i].mptr = NULL;
fDesc[i].fBlock = -1;
fDesc[i].fptr = NULL;
}
BlockBits = -1; for (i = BLOCK_SIZE; i != 0; i>>=1) BlockBits++;
IndexBits = -1; for (i = INDEXES_PER_BLOCK; i != 0; i>>=1) IndexBits++;
return SUCCESS;
}
command result_t Control.start() {
// load the 0-page from flash by casting the inode array on top of it
// this page stays open until the filesystem is stopped
inode = (FInode *) call Flash.getWriteBlock(0);
usedPages = (char *) call Flash.getWriteBlock(1);
// mark first two pages as used for inode and used pages mask
usedPages[0] = usedPages[0] | 0xC0;
return SUCCESS;
}
command result_t Control.stop() {
if (inode != NULL) {
call Flash.commitBlock(0);
}
if (usedPages != NULL) {
call Flash.commitBlock(1);
}
}
/*
* End of StdControl interface.
*/
/*
* Look through the usedPages bitmask to find an unused page. If one is found
* mark it as used and return the physical block index. If no empty pages are
* found, return -1.
*/
int AllocateEmptyBlock() {
int i, j;
for (i = 0; i < BLOCK_SIZE; i++) {
if (usedPages[lastEmptyPage] != 0xff) {
// find first empty bit corresponding to first unused block
for (j = 0; j < 8; j++) {
if ((usedPages[lastEmptyPage] & (0x80 >> j)) == 0) {
// mark block as used and return index
usedPages[lastEmptyPage] |= (0x80 >> j);
return ((lastEmptyPage << 3) | j);
}
}
// shouldn't get here
}
lastEmptyPage = (lastEmptyPage < (MAX_BLOCKS - 1)) ? lastEmptyPage+1 : 0;
}
// if flow gets to this point, there are no pages left
return -1;
}
/*
* Figure out which physical block contains the byte at <offset> in the
* given inode.
*/
int GetBlockIndex(int fd, int offset) {
int inumber;
int block; // virtual block offset within this inode
int sindex;// virtual block offset within 1st level
int ind; // physical block index of 1st level table
int16_t *table; // pointer used to access blocks which contain block indexes
inumber = fDesc[fd].inode;
block = offset >> BlockBits;
if (block < ZERO_LEVEL_BLOCKS) {
// block index is in the inode structure
return (inode[inumber].dataBlock[block]);
} else {
// block index is accessed through first level index
sindex = SINDEX(block);
// if the requested block shares the same first level table as the current
// block and that table is in core, use the cached version
if ((inode[inumber].firstLevel[sindex] == fDesc[fd].fBlock) &&
(fDesc[fd].fptr != NULL)) {
table = fDesc[fd].fptr;
} else {
ind = inode[inumber].firstLevel[sindex];
table = (int16_t *) call Flash.getReadBlock(ind);
}
return table[FINDEX(block)];
}
// shouldn't get here
return -1;
}
/*
* Allocate blocks and update the inode structure to a file size of offset.
* Update file size.
*/
result_t AppendBlocksToOffset (int fd, int offset) {
int curBlocks; // current number of blocks in the file
int newBlocks; // new number of blocks needed
int block; // physical index of new block
int foffset; // virtual block offset within 1st level array
int fInd; // virtual block index in first level table
int16_t *fptr; // pointer to first level index table
int inumber;
int tmp;
char *buf;
inumber = fDesc[fd].inode;
curBlocks = inode[inumber].fileSize >> BlockBits;
newBlocks = offset >> BlockBits;
fptr = fDesc[fd].fptr;
while (curBlocks < newBlocks) {
if ((block = AllocateEmptyBlock()) == -1) return FAIL; // should clean up?
curBlocks++;
if (curBlocks < ZERO_LEVEL_BLOCKS) {
inode[inumber].dataBlock[curBlocks] = block;
} else {
foffset = (curBlocks - ZERO_LEVEL_BLOCKS) >> IndexBits;
fInd = (curBlocks - ZERO_LEVEL_BLOCKS) & (INDEXES_PER_BLOCK - 1);
if (fInd == 0) {
// allocate 1st level page
if ((inode[inumber].firstLevel[foffset]=AllocateEmptyBlock()) == -1) {
return FAIL; // should clean up?
}
if (fptr != NULL) { // close previous page
call Flash.commitBlock(inode[inumber].firstLevel[foffset - 1]);
fptr = NULL;
}
}
if (fptr == NULL) { // allocate page for writting
tmp = inode[inumber].firstLevel[foffset];
buf = call Flash.getWriteBlock(tmp);
fptr = (int16_t *) buf;
fDesc[fd].fptr = fptr;
fDesc[fd].fBlock = tmp;
if (fptr == NULL) {
return FAIL;
}
}
fptr[fInd] = block;
}
inode[inumber].fileSize = curBlocks << BlockBits;
}
// leave page open and cache pointer
/* // close open pages
if (fptr != NULL) {
call Flash.commitBlock(inode[inumber].firstLevel[foffset]);
}
*/
if (inode[inumber].fileSize > offset) { // don't shrink the file
inode[inumber].fileSize = offset;
}
return SUCCESS;
}
/*
* Allocate an entry in the inode table and initialize the contents.
* Return -1 if the entry could not be created.
*/
int CreateInode(char *name) {
int i, j, block;
// find an empty inode and set the valid flag
for (i = 0; i < MAX_INODE; i++) {
if (inode[i].flags != FINODE_VALID) {
// make sure there is at least one empty block before setting up inode
if ((block = AllocateEmptyBlock()) == -1) {
return -1;
}
strncpy (&(inode[i].name[0]), name, MAX_NAME_LENGTH);
if (strlen(name) >= MAX_NAME_LENGTH) inode[i].name[MAX_NAME_LENGTH-1]=0;
inode[i].flags = FINODE_VALID;
inode[i].fileSize = 0;
inode[i].dataBlock[0] = block;
for (j = 1; j < ZERO_LEVEL_BLOCKS; j++) inode[i].dataBlock[j] = 0;
for (j = 0; j < FIRST_LEVEL_BLOCKS; j++) inode[i].firstLevel[j] = 0;
return i;
}
}
return -1;
}
/*
* Match string name to the file descriptor
*/
int GetInode(char *name) {
int i;
for (i = 0; i < MAX_INODE; i++) {
if (inode[i].flags == FINODE_VALID) {
if (strcmp(name, inode[i].name) == 0) return i;
}
}
return -1; // not found
}
/*
* Match string name to the file descriptor
*/
int GetFileDescriptor(int inumber) {
int i;
for (i = 0; i < MAX_FD; i++) {
if ((fDesc[i].valid == TRUE) && (fDesc[i].inode == inumber)) {
return i;
}
}
return -1; // not found
}
/*
* Return the lowest file descriptor which is not currently valid. If all
* of the file descriptors are taken, return -1.
*/
int AllocateNewFileDescriptor(int inumber) {
int i;
for (i = 0; i < MAX_FD; i++) {
if (fDesc[i].valid == FALSE) {
fDesc[i].valid = TRUE;
fDesc[i].currentBlock = -1;
fDesc[i].mptr = NULL;
fDesc[i].fBlock = -1;
fDesc[i].fptr = NULL;
return i;
}
}
return -1;
}
int GetLowestFileDescriptor() {
int i;
for (i = 0; i < MAX_FD; i++) {
if (fDesc[i].valid == FALSE) return i;
}
return -1;
}
/*
* Start of FlashFS interface.
*/
bool ValidFD(int fd) {
return ((fd >= 0) && (fd < MAX_FD) && (fDesc[fd].valid == TRUE));
}
/*
* Opens a file for reading or writing. If the file does not exist and the
* FFS_CREAT flag is set then a new file is created. The return value is
* a file descriptor used by the other file io functions or a -1 if there
* was an error.
*/
command int FlashFS.open(char *name, int flags) {
int inumber; // inode index associated with name
int fd; // file descriptor associated with name
// make sure the inode page is in core
if (inode == NULL) {
inode = (FInode *) call Flash.getWriteBlock(0);
usedPages = (char *) call Flash.getWriteBlock(1);
}
inumber = GetInode(name);
if ((inumber == -1) && (flags & FFS_O_CREAT)) {
inumber = CreateInode(name);
}
if (inumber == -1) {
return -1; // file doesn't exist and we didn't create it
}
// If file is already open make sure that that access modes match.
// The file must be closed and reopened to change the access mode.
fd = GetFileDescriptor(inumber);
if ((fd != -1) && (fDesc[fd].Mode != (flags & 0x3))) {
return -1;
}
if (fd == -1) { // try to open the file
if ((fd = AllocateNewFileDescriptor(inumber)) == -1) return -1;
fDesc[fd].Mode = flags & 0x03;
if ((flags & FFS_O_APPEND) && (flags & (FFS_O_WRONLY | FFS_O_RDWR))) {
fDesc[fd].fileOffset = inode[inumber].fileSize;
} else {
fDesc[fd].fileOffset = 0;
}
fDesc[fd].inode = inumber;
}
// if the current access mode is write enabled, load the current page
if (flags & (FFS_O_WRONLY | FFS_O_RDWR)) {
fDesc[fd].currentBlock =
GetBlockIndex(fd, fDesc[fd].fileOffset);
fDesc[fd].mptr = call Flash.getWriteBlock(fDesc[fd].currentBlock);
if ((fDesc[fd].fileOffset >> BlockBits) >= ZERO_LEVEL_BLOCKS) {
fDesc[fd].fBlock = inode[inumber].firstLevel[SINDEX(fDesc[fd].fileOffset >> BlockBits)];
fDesc[fd].fptr = call Flash.getWriteBlock(fDesc[fd].fBlock);
}
}
return (fd);
}
/*
* Moves the read/ write pointer within a file. The whence flag indicates
* whether the new location is relative to the beginning, current location,
* or end of the file.
*/
command void FlashFS.lseek(int fd, int offset, int whence) {
int curOffset, newOffset, curSize;
int oldFL, newFL;
// verify that file descriptor is valid
if (ValidFD(fd) == FALSE) return;
curOffset = fDesc[fd].fileOffset;
curSize = inode[fDesc[fd].inode].fileSize;
if (whence == FFS_SEEK_SET) {
newOffset = offset;
} else if (whence == FFS_SEEK_CUR) {
newOffset = curOffset + offset;
} else if (whence == FFS_SEEK_END) {
newOffset = curSize + offset;
}
// if we've scanned past the last block of the file, allocate more blocks
if (newOffset > curSize) {
if (AppendBlocksToOffset (fd, newOffset) == FAIL) {
return;
};
}
// if the file is write enable and the seek enters a new block, close the
// old one and open the new one for writting
if ((fDesc[fd].currentBlock != -1) &&
(fDesc[fd].Mode & (FFS_O_WRONLY | FFS_O_RDWR))) {
if ((curOffset >> BlockBits) != (newOffset >> BlockBits)) {
call Flash.commitBlock(fDesc[fd].currentBlock);
fDesc[fd].currentBlock = GetBlockIndex(fd, newOffset);
fDesc[fd].mptr = call Flash.getWriteBlock(fDesc[fd].currentBlock);
// If the seek enters a block indexed by a different first level entry
// then close the old entry and open the new one
oldFL = ((fDesc[fd].fileOffset >> BlockBits) - ZERO_LEVEL_BLOCKS)
>> IndexBits;
newFL = ((newOffset >> BlockBits) - ZERO_LEVEL_BLOCKS) >> IndexBits;
if (oldFL != newFL) {
call Flash.commitBlock(oldFL);
fDesc[fd].fptr = (int16_t *) call Flash.getWriteBlock(newFL);
}
}
}
fDesc[fd].fileOffset = newOffset;
return;
}
/*
* Copy the contents of the file to the buffer and advance the index pointer
* by size. The return value is the nuber of bytes read.
*/
command int FlashFS.read (int fd, char *inbuf, int size) {
int i;
int block; // physical block index of the current block
int offset;
int fileSize;
char *fbuf;
int oldFL, newFL;
// verify that file descriptor is valid
if (ValidFD(fd) == FALSE) return 0;
// verify access mode
if ((fDesc[fd].Mode != FFS_O_RDONLY) && (fDesc[fd].Mode != FFS_O_RDWR)) {
return 0;
}
offset = fDesc[fd].fileOffset;
fileSize = inode[fDesc[fd].inode].fileSize;
block = GetBlockIndex(fd, offset);
fbuf = call Flash.getReadBlock(block);
for (i = 0; (i < size) && ((offset + i) < fileSize); i++) {
if (((offset + i) & (BLOCK_SIZE - 1)) == 0) {
block = GetBlockIndex(fd, offset + i);
fbuf = call Flash.getReadBlock(block);
}
((char *)inbuf)[i] = fbuf[(offset + i) & (BLOCK_SIZE - 1)];
}
// if the current access mode is read/ write and we've entered a new block,
// close the old block and open the new block for writing
if ((fDesc[fd].currentBlock != -1) && (fDesc[fd].Mode & FFS_O_RDWR)) {
if ((fDesc[fd].fileOffset >> BlockBits) !=
((fDesc[fd].fileOffset + i) >> BlockBits)) {
call Flash.commitBlock(fDesc[fd].currentBlock);
fDesc[fd].currentBlock =
GetBlockIndex(fd, fDesc[fd].fileOffset + i);
fDesc[fd].mptr = call Flash.getWriteBlock(fDesc[fd].currentBlock);
// If the seek enters a block indexed by a different first level entry
// then close the old entry and open the new one
oldFL = ((offset >> BlockBits) - ZERO_LEVEL_BLOCKS) >> IndexBits;
newFL = (((offset + i) >> BlockBits) - ZERO_LEVEL_BLOCKS) >> IndexBits;
if (oldFL != newFL) {
call Flash.commitBlock(oldFL);
fDesc[fd].fptr = (int16_t *) call Flash.getWriteBlock(newFL);
}
}
}
fDesc[fd].fileOffset += i;
return (i);
}
/*
* Copy the contents of the buffer to the file and advance the index pointer.
* The return value is the number of bytes copied.
*/
command int FlashFS.write (int fd, char *outbuf, int size) {
int i;
int block; // physical block index of the current block
int offset;
int fileSize;
char *bufptr;
// verify that file descriptor is valid
if (ValidFD(fd) == FALSE) return 0;
// verify acces mode
if ((fDesc[fd].Mode != FFS_O_WRONLY) && (fDesc[fd].Mode != FFS_O_RDWR)) {
return 0;
}
offset = fDesc[fd].fileOffset;
fileSize = inode[fDesc[fd].inode].fileSize;
block = fDesc[fd].currentBlock;
bufptr = fDesc[fd].mptr;
// make sure there is enough space to write
if ((offset + size) > fileSize) {
if (AppendBlocksToOffset (fd, offset + size) == FAIL) {
return 0;
}
}
for (i = 0; i < size; i++) {
if (((offset + i) & (BLOCK_SIZE - 1)) == 0) {
if (block != -1) {
call Flash.commitBlock(block);
}
block = GetBlockIndex(fd, offset + i);
bufptr = call Flash.getWriteBlock(block);
}
bufptr[(offset + i) & (BLOCK_SIZE - 1)] = ((char *)outbuf)[i];
}
fDesc[fd].fileOffset += i;
if (fDesc[fd].fileOffset > inode[fDesc[fd].inode].fileSize) {
inode[fDesc[fd].inode].fileSize = fDesc[fd].fileOffset;
}
fDesc[fd].currentBlock = block;
fDesc[fd].mptr = bufptr;
return (i);
}
/*
* Test whether there are any open file descriptors. If there are not, write
* the 0-page and 1-page back to flash.
*/
void TestAndFlushInodes() {
int i;
for (i = 0; i < MAX_FD; i++) {
if (fDesc[i].valid == TRUE) return;
}
/* leave them open for testing
call Flash.commitBlock(0);
call Flash.commitBlock(1);
inode = NULL;
usedPages = NULL;
*/
}
/*
* Close the file and commit all of the changes to flash. The return value
* is -1 if there was an error.
*/
command int FlashFS.close (int fd) {
if (ValidFD(fd) == FALSE) return -1;
if (fDesc[fd].currentBlock != -1) {
call Flash.commitBlock(fDesc[fd].currentBlock);
fDesc[fd].mptr = NULL;
}
if (fDesc[fd].fBlock != -1) {
call Flash.commitBlock(fDesc[fd].fBlock);
fDesc[fd].fptr = NULL;
}
fDesc[fd].valid = FALSE;
TestAndFlushInodes();
return 0;
}
/*
* Write the in-core contents of the file back to the storage device
* and leave the block open for writing.
*/
command int FlashFS.flush (int fd) {
int block, i;
// flush all files to avoid inode synchronization issues
if (ValidFD(fd) == FALSE) return -1;
for (i = 0; i < MAX_FD; i++) {
if ((block = fDesc[i].currentBlock) != -1) {
call Flash.commitBlock(block);
fDesc[i].mptr = (char *)call Flash.getWriteBlock(block);
}
if ((block = fDesc[i].fBlock) != -1) {
call Flash.commitBlock(block);
fDesc[i].fptr = (int16_t *) call Flash.getWriteBlock(block);
}
}
call Flash.commitBlock(0);
inode = (FInode *) call Flash.getWriteBlock(0);
call Flash.commitBlock(1);
usedPages = (char *) call Flash.getWriteBlock(1);
return 0;
}
/*
* Release the storage associated with the file name. The contents of the
* file may not be 0'd out. If an error occurs, -1 is returned.
*/
command int FlashFS.delete (char *name) {
int inumber; // inode index corresponding to name
int blocks; // number of block in this inode
int16_t *fptr; // index pointer to first and second level tables
int ind, fInd; // physical block index for direct, first, and
// second level tables
int i;
inumber = GetInode(name);
// Make sure there are no open descriptors for this inode
for (i = 0; i < MAX_FD; i++) {
if ((fDesc[i].valid == TRUE) && (fDesc[i].inode == inumber)) return 0;
}
// Mark pages as available
if (usedPages == NULL) {
usedPages = (char *) call Flash.getWriteBlock(1);
}
blocks = inode[inumber].fileSize >> BlockBits;
// free up direct data blocks;
for (i = 0; (i < ZERO_LEVEL_BLOCKS) && (i < blocks); i++) {
ind = inode[inumber].dataBlock[i];
usedPages[ind >> 3] &= ~(1 << (ind & 0x7));
}
// free up first level data blocks
blocks -= ZERO_LEVEL_BLOCKS;
if (blocks > 0) {
for (i = 0; (i < FIRST_LEVEL_BLOCKS) && (i < (blocks >> IndexBits)); i++){
fInd = inode[inumber].firstLevel[i];
fptr = (int16_t *) call Flash.getReadBlock(fInd);
for (i = 0; (i < INDEXES_PER_BLOCK) && (i < blocks); i++) {
ind = fptr[i];
usedPages[ind >> 3] &= ~(1 << (ind & 0x7)) ;
}
usedPages[fInd >> 3] &= ~(1 << (fInd & 0x7)) ;
}
}
// close any open write pages
TestAndFlushInodes();
return 0;
}
/*
* Return a pointer to the inode structure for printing.
*/
command FInode *FlashFS.getInode (int *next) {
int i;
if (next < 0) return NULL;
for (i = *next; i < MAX_INODE; i++) {
if (inode[i].flags == FINODE_VALID) {
*next = i + 1;
return (&(inode[i]));
}
}
*next = -1;
return (NULL);
}
/*
* End of FlashFS interface.
*/
}
--- NEW FILE: GPIO.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
interface GPIO {
command result_t init();
command result_t enable();
command result_t disable();
command result_t set(uint8 state);
command uint8 get();
command result_t input(uint8 reg);
command result_t output(uint8 reg);
event result_t stateChanged();
}
--- NEW FILE: HPLByteDMAM.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This module uses the DMA mode to implement the 1 byte HPLUART interface
* Note this should not be used if other modules intend to use the DMA
* interface directly, as this module will always control the receive
*/
includes motelib;
module HPLByteDMAM {
provides interface HPLUART;
uses interface HPLUART as UART;
uses interface HPLDMA as DMA;
uses interface Timer;
}
implementation
{
#define DEFAULT_BAUDRATE eTM_B115200
#define RETRY_DELAY 5000
#define NUM_RETRIES 100
uint8 baudrate = DEFAULT_BAUDRATE;
extern tTOSBufferVar *TOSBuffer __attribute__ ((C));
uint8 retries;
async command result_t HPLUART.init() {
uint32 temp;
call UART.setRate(baudrate);
call UART.init();
temp = TM_UartLineOfStatus(TM_MainUartReg);
if ((temp & 0x1E) == 0) {
call DMA.DMAGet(TOSBuffer->UARTRxBuffer,1);
retries = 0;
return SUCCESS;
}
retries = NUM_RETRIES;
call Timer.start(TIMER_ONE_SHOT, RETRY_DELAY);
return FAIL;
}
command result_t HPLUART.setRate(uint8 newbaudrate){
baudrate=newbaudrate;
return SUCCESS;
}
async command result_t HPLUART.stop() {
return SUCCESS;
}
async command result_t HPLUART.put(uint8_t data) {
TOSBuffer->UARTTxBuffer[0] = data;
call DMA.DMAPut(TOSBuffer->UARTTxBuffer, 1);
return SUCCESS;
}
async event uint8* DMA.DMAGetDone(uint8 *data, uint16 Bytes) {
if (Bytes == 1) {
signal HPLUART.get(*data);
}
return TOSBuffer->UARTRxBuffer;
}
async event result_t DMA.DMAPutDone(uint8 *data) {
signal HPLUART.putDone();
return SUCCESS;
}
async event result_t UART.get(uint8 data) {
return SUCCESS;
}
async event result_t UART.putDone() {
return SUCCESS;
}
event result_t Timer.fired() {
uint32 temp;
if (retries > 0) {
call UART.init();
temp = TM_UartLineOfStatus(TM_MainUartReg);
if ((temp & 0x1E) == 0) {
call DMA.DMAGet(TOSBuffer->UARTRxBuffer,1);
retries = 0;
return SUCCESS;
}
retries--;
call Timer.start(TIMER_ONE_SHOT, RETRY_DELAY);
}
}
}
--- NEW FILE: HPLDMA.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* The HPLDMA interface is intended to provide the functionality of a DMA
* controller on both the send and receive sides of a transaction. In order
* to provide this functionality, the interface provide 2 commands and 2
* events. Because the DMA interface is intended to supplement a standard
* byte based interface, there is no init, start, or stop. Instead
* either of the 2 commands may return fail if for some reason there is
* something wrong with port when the command is issued
*/
interface HPLDMA {
/*
* Begin a DMAGet (receive). The parameters should be the initial buffer
* to place data into and the inital number of bytes. DMA receive chaining
* may be accomplished by returning a new buffer in the associated DMAGetDone
* event
*/
async command result_t DMAGet(uint8 *RxBuffer, uint16 NumBytes) ;
/*
* This command informs the FlexUart component to send NumBytes to the
* Uart using the TxBuffer parameter as the source.
*/
async command result_t DMAPut(uint8 *TxBuffer, uint16 NumBytes) ;
/*
* This event is signaled to inform the application that NumBytes
* have been received. No assumptions can be made about the
* contents of the RxBuffer once this event returns. If the caller
* wants to hold onto these bytes, it should save a copy of it. To
* chain receives OF THE SAME LENGTH together, return a new buffer from this
* event. If a new transaction of a different length is required or if
* the application is done receiving data, return NULL and trigger the new
* transaction from outside this event. If for some reason
* the hardware was unable to capture NumBytes of contiguous data without
* an overrun condition occuring, the event will be signaled with NumBytes 0.
* In this case, the data pointer will be valid so as to allow the application
* to free the memory associated with the original get request.
*
*/
async event uint8 *DMAGetDone(uint8 *data, uint16 NumBytes);
/*
* This event is signaled by the UART driver to indicate to the application
* that the bytes have been sent out.
*/
async event result_t DMAPutDone(uint8 *data);
}
--- NEW FILE: HPLDebugUartC.nc ---
/* tab:4
*
*
* "Copyright (c) 2000-2002 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."
*
*/
/* tab:4
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
* downloading, copying, installing or using the software you agree to
* this license. If you do not agree to this license, do not download,
* install, copy or use the software.
*
* Intel Open Source License
*
* Copyright (c) 2002 Intel Corporation
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
/*
*
* Authors: Jason Hill, David Gay, Philip Levis
* Date last modified: 6/25/02
*
*/
// The hardware presentation layer. See hpl.h for the C side.
// Note: there's a separate C side (hpl.h) to get access to the avr macros
// The model is that HPL is stateless. If the desired interface is as stateless
// it can be implemented here (Clock, FlashBitSPI). Otherwise you should
// create a separate component
configuration HPLDebugUartC {
provides interface HPLUART;
}
implementation
{
components HPLDebugUartM;
HPLUART = HPLDebugUartM;
}
--- NEW FILE: HPLDebugUartM.nc ---
/* tab:4
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
* downloading, copying, installing or using the software you agree to
* this license. If you do not agree to this license, do not download,
* install, copy or use the software.
*
* Intel Open Source License
*
* Copyright (c) 2002 Intel Corporation
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
// The hardware presentation layer. See hpl.h for the C side.
// Note: there's a separate C side (hpl.h) to get access to the avr macros
// The model is that HPL is stateless. If the desired interface is as stateless
// it can be implemented here (Clock, FlashBitSPI). Otherwise you should
// create a separate component
includes motelib;
module HPLDebugUartM {
provides interface HPLUART as UART;
}
implementation
{
//note, this is the maximum standard rate that the Debug UART will run at
#define DEFAULT_BAUDRATE eTM_B57600
bool bInitialized = false;
uint8 baudrate = DEFAULT_BAUDRATE;
async command result_t UART.init() {
if(InitializeDebugUart(baudrate) == SUCCESS) {
bInitialized = true;
return SUCCESS;
}
else{
bInitialized = false;
return FAIL;
}
}
command result_t UART.setRate(uint8 newbaudrate){
if((bInitialized==false) && (newbaudrate <=eTM_B921600)){
baudrate=newbaudrate;
return SUCCESS;
}
else{
return FAIL;
}
}
async command result_t UART.stop() {
return SUCCESS;
}
async command result_t UART.put(uint8_t data) {
if(bInitialized==true)
DebugUartTransmit(data);
return SUCCESS;
}
void DebugUartInterrupt(uint16 Id, tIoStatus UartStatus) __attribute__((C, spontaneous)) {
//something bad happened...need to figure out what to do...most likely just ignore
}
void DebugUartTransmitInterrupt() __attribute__ ((C, spontaneous)) {
signal UART.putDone();
}
void DebugUartReceiveInterrupt(uint8 data) __attribute__ ((C, spontaneous)) {
signal UART.get(data);
}
default async event result_t UART.get(uint8 data) { return SUCCESS; }
default async event result_t UART.putDone() { return SUCCESS; }
}
--- NEW FILE: HPLFlashM.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This module provides a generic block i/o interface to the hardware's flash
* Read operations directly access the flash. Write operations must first
* call getWriteBlock to get a memory pointer to an in-core copy of the
* flash contents. The block can then be manipulated. After all modifications
* are done the block is written back to the flash with the commitBlock command.
*
* The number of writable blocks is limited by the in-core memory allocation,
* currently set to <8 blocks.
*/
module HPLFlashM {
provides {
interface Flash;
}
}
implementation
{
//#undef TM_FLASH_TOS
//#define TM_FLASH_TOS 0
/*
* Gets a memory pointer to a block for reading. In this implementation
* the memory is accessed directly from flash. This pointer cannot be used
* to modify the contents in flash. Any writes to the pointer will result
* in unpredicted behavior.
*/
command void *Flash.getReadBlock(int blockIndex) {
return TM_API_GetFlashReadPtr(blockIndex + TM_FLASH_TOS);
}
/*
* Gets a memory pointer to a block for writing. The contents of the block
* can be read or written using this pointer. Changes to the block are not
* committed until the commitBlock command is called.
*/
command void *Flash.getWriteBlock(int blockIndex) {
return TM_API_GetFlashWritePtr(blockIndex + TM_FLASH_TOS, BLOCK_SIZE);
}
/*
* Write a block from core memory back into flash memory and deallocate the
* pointer. Future writes to the same block must first call getWriteBlock.
*/
command result_t Flash.commitBlock(int blockIndex) {
TM_API_FlashWriteDone(blockIndex + TM_FLASH_TOS);
return SUCCESS;
}
}
--- NEW FILE: HPLMainUartC.nc ---
/* tab:4
*
*
* "Copyright (c) 2000-2002 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."
*
*/
/* tab:4
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
* downloading, copying, installing or using the software you agree to
* this license. If you do not agree to this license, do not download,
* install, copy or use the software.
*
* Intel Open Source License
*
* Copyright (c) 2002 Intel Corporation
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
/*
*
* Authors: Jason Hill, David Gay, Philip Levis
* Date last modified: 6/25/02
*
*/
// The hardware presentation layer. See hpl.h for the C side.
// Note: there's a separate C side (hpl.h) to get access to the avr macros
// The model is that HPL is stateless. If the desired interface is as stateless
// it can be implemented here (Clock, FlashBitSPI). Otherwise you should
// create a separate component
configuration HPLMainUartC {
provides interface HPLUART;
provides interface HPLDMA;
}
implementation
{
components HPLMainUartM;
HPLUART = HPLMainUartM;
HPLDMA = HPLMainUartM;
}
--- NEW FILE: HPLMainUartM.nc ---
/* tab:4
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
* downloading, copying, installing or using the software you agree to
* this license. If you do not agree to this license, do not download,
* install, copy or use the software.
*
* Intel Open Source License
*
* Copyright (c) 2002 Intel Corporation
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
// The hardware presentation layer. See hpl.h for the C side.
// Note: there's a separate C side (hpl.h) to get access to the avr macros
// The model is that HPL is stateless. If the desired interface is as stateless
// it can be implemented here (Clock, FlashBitSPI). Otherwise you should
// create a separate component
includes motelib;
module HPLMainUartM {
provides interface HPLUART as UART;
provides interface HPLDMA as DMA;
}
implementation
{
#define DEFAULT_BAUDRATE eTM_B115200
bool bInitialized = false;
uint8 baudrate = DEFAULT_BAUDRATE;
async command result_t UART.init() {
if(InitializeMainUart(baudrate) == SUCCESS) {
bInitialized = true;
return SUCCESS;
}
else{
bInitialized = false;
return FAIL;
}
}
command result_t UART.setRate(uint8 newbaudrate){
if((bInitialized==false) && (newbaudrate <=eTM_B921600)){
baudrate=newbaudrate;
return SUCCESS;
}
else{
return FAIL;
}
}
async command result_t UART.stop() {
return SUCCESS;
}
async command result_t UART.put(uint8_t data) {
MainUartTransmit(data);
return SUCCESS;
}
async command result_t DMA.DMAGet(uint8 *RxBuffer, uint16 NumBytes){
if(bInitialized){
SetupMainUartDMAReceive(RxBuffer, NumBytes);
return SUCCESS;
}
return FAIL;
}
async command result_t DMA.DMAPut(uint8 *TxBuffer, uint16 NumBytes){
if(bInitialized){
MainUartDMATransmit(TxBuffer, NumBytes);
return SUCCESS;
}
return FAIL;
}
void MainUartInterrupt(uint16 Id, tIoStatus UartStatus) __attribute__((C, spontaneous)) {
//something bad happened...need to figure out what to do...most likely just ignore
}
void MainUartTransmitInterrupt() __attribute__ ((C, spontaneous)) {
signal UART.putDone();
}
void MainUartDMATransmitInterrupt(uint8 *data,uint16 NumBytes) __attribute__ ((C, spontaneous)) {
signal DMA.DMAPutDone(data);
}
void MainUartReceiveInterrupt(uint8 data) __attribute__ ((C, spontaneous)) {
signal UART.get(data);
}
uint8 *MainUartDMAReceiveInterrupt(uint8 *data, uint16 NumBytes) __attribute__ ((C, spontaneous)) {
return signal DMA.DMAGetDone(data,NumBytes);
}
default async event result_t UART.get(uint8 data) { return SUCCESS; }
default async event result_t UART.putDone() { return SUCCESS; }
default async event uint8* DMA.DMAGetDone(uint8 *data, uint16 NumBytes){
return NULL;
}
default async event result_t DMA.DMAPutDone(uint8 *data){ return SUCCESS;}
}
--- NEW FILE: HPLUART.nc ---
// $Id: HPLUART.nc,v 1.1 2005/09/06 08:27:59 lnachman Exp $
/* tab:4
* "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: Jason Hill, David Gay, Philip Levis
* Date last modified: 6/25/02
*
*
*/
/**
* The byte-level interface to the UART, which can send and receive
* simultaneously.
*
* <p> This interface, as it directly abstracts hardware, follows the
* hardware interface convention of not maintaining state. Therefore,
* some conditions that could be understood by a higher layer to be
* errors execute properly; for example, one can call
* <code>txBit</code> when in receive mode. A higher level interface
* must provide the checks for conditions such as this.
*
* @author Jason Hill
* @author David Gay
* @author Philip Levis
*/
interface HPLUART {
/**
* Initialize the UART.
*
* @return SUCCESS always.
*/
async command result_t init();
/**
*Set the rate that the UART communicates at
*
*@returns SUCCESS if the rate is valid, FAIL otherwise
*
*/
command result_t setRate(uint8 baudrate);
/**
* TUrn off the UART
*
* @return SUCCESS always
*/
async command result_t stop();
/**
* Send one byte of data. There should only one outstanding send at
* any time; one must wait for the <code>putDone</code> event before
* calling <code>put</code> again.
*
* @return SUCCESS always.
*/
async command result_t put(uint8_t data);
/**
* A byte of data has been received.
*
* @return SUCCESS always.
*/
async event result_t get(uint8_t data);
/**
* The previous call to <code>put</code> has completed; another byte
* may now be sent.
*
* @return SUCCESS always.
*/
async event result_t putDone();
}
--- NEW FILE: LoggerRead.nc ---
// $Id: LoggerRead.nc,v 1.1 2005/09/06 08:27:59 lnachman Exp $
/* tab:4
* "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: Matt Welsh
* Date last modified: 8/27/02
*
*
*/
/**
* @author Matt Welsh
*/
//includes EEPROM;
/**
* Interface to read a line at a time from the EEPROM, maintaining
* an internal "current line" pointer.
*/
interface LoggerRead {
/**
* Read the next line from the log, wrapping around to the beginning
* of the log.
* @param buffer The buffer to read data into.
* @return FAIL if the component is busy, SUCCESS otherwise.
*/
command result_t readNext(uint8_t *buffer);
/**
* Equivalent to calling setPointer(line) followed by read(buffer).
* @param line The line to read from
* @param buffer The buffer to read data into.
* @return FAIL if the component is busy or the line is invalid,
* SUCCESS otherwise.
*/
command result_t read(uint16_t line, uint8_t *buffer);
/**
* Reset the current read pointer to the beginning of the log.
* @return Always return SUCCESS.
*/
command result_t resetPointer();
/**
* Set the current read pointer to the given value.
* Not all pointer values are valid.
* @param line The line to set the pointer to.
* @return FAIL if the line is invalid, SUCCESS otherwise.
*/
command result_t setPointer(uint16_t line);
/**
* Signaled when a read completes.
* @param buffer The buffer containing the read data.
* @param success Whether the read was successful. If FAIL, the
* buffer data is invalid.
*/
event result_t readDone(uint8_t *buffer, result_t success);
}
--- NEW FILE: LoggerWrite.nc ---
// $Id: LoggerWrite.nc,v 1.1 2005/09/06 08:27:59 lnachman Exp $
/* tab:4
* "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: Jason Hill, David Gay, Philip Levis
* Date last modified: 6/25/02
*
* $Id: LoggerWrite.nc,v 1.1 2005/09/06 08:27:59 lnachman Exp $
*/
/**
* @author Jason Hill
* @author David Gay
* @author Philip Levis
*/
//includes EEPROM;
/**
* Implements a circular log interface.
* Allows a line at a time to be written, automatically
* maintaining a current line pointer. The pointer wraps around to the
* beginning of the log.
*/
interface LoggerWrite {
/**
* Writes data to the current line in the EEPROM. If the call
* does not return <code>FAIL</code>, the next call to append will write to
* (current line + 1).
* <p>
* <code>writeDone()</code> will be signaled if result
* is not <code>FAIL</code>
*
* @param data the data to be appended to the log
*
* @return FAIL if the write cannot occur, SUCCESS otherwise
*/
command result_t append(uint8_t *data);
/**
* Reset the current line pointer to the beginning of the log.
*
* @return SUCCESS if the line pointer can be moved and no other operations
* are pending.
*/
command result_t resetPointer();
/**
* Set the current line pointer to the value of 'line'.
* Not all line values are valid.
*
* @param line The address of the line to set the current pointer to.
*
* @return FAIL if the line is invalid, SUCCESS otherwise.
*/
command result_t setPointer(uint16_t line);
/**
* Write a specified line to the log.
* <p>
* Sets the current line to the input <code>line</code>
* and then behaves as <code>append(data)</code>.
* <p>
* Equivalent to calling <code>setPointer(line)</code>
* followed by <code>append(data)</code>
*
* @param line the address of the line
* @param data the data to be written to the log
*
* @return FAIL if the write cannot occur, SUCCESS otherwise
*/
command result_t write(uint16_t line, uint8_t *data);
/**
* Notification that a write command has been completed.
* Signaled by both <code>write()</code>
* and <code>append()</code>.
*
* @param success SUCCESS if the write was successfully written to the log
*
* @return SUCCESS to notify the logger to keep its bookmark
* (current line) in the log
*/
event result_t writeDone(result_t success);
}
--- NEW FILE: NewTimer.h ---
#define USE_NEW_TIMER 1
--- NEW FILE: ReliablePacket.nc ---
/* tab:4
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
* downloading, copying, installing or using the software you agree to
* this license. If you do not agree to this license, do not download,
* install, copy or use the software.
*
* Intel Open Source License
*
* Copyright (c) 2002 Intel Corporation
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
/*
* This interface provides a reliable packet. It is similar to NetworkPacket
* except for the semantics of the SendDone, and the addition of another
* event and command
*/
interface ReliablePacket {
/*
* The data pointer passed to Send needs to have 4 bytes for the sequence
* number of the reliable packet protocol and another 4 bytes available before
* the data packet for the L2CAP header plus room for the iMote header. Also
* the data must reside in the BRAM memory region. Both of these condiditions
* are enforced by the allocate/ release routines contained in this interface.
*/
command result_t Initialize( );
command result_t Send( uint32 Destination,
uint8 *Data,
uint16 Length);
/*
* This commands sets the number of retries that the lower layer will
* attempt before quitting and returning a FAIL
*/
command result_t SetNumRetries(uint8 NumRetries);
/*
* The SendDone passes the status to the app. A SUCCESS indicates that the
* packet was received and acknowledged by the destination. A FAIL means
* that the number of retries was reached and no response was received from
* the destination.
*/
event result_t SendDone(char *data, result_t status);
event result_t Receive( uint32 Source,
uint8 *Data,
uint16 Length);
command char *AllocateBuffer( uint16 BufferSize);
command result_t ReleaseBuffer( char *BufferPtr);
}
--- NEW FILE: ReliablePacketC.nc ---
/* tab:4
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
* downloading, copying, installing or using the software you agree to
* this license. If you do not agree to this license, do not download,
* install, copy or use the software.
*
* Intel Open Source License
*
* Copyright (c) 2002 Intel Corporation
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
configuration ReliablePacketC
{
provides {
interface ReliablePacket;
}
}
implementation
{
components ReliablePacketM,
TimerC,
NetworkLinkQueuesM;
ReliablePacket = ReliablePacketM;
ReliablePacketM.Timer -> TimerC.Timer[unique("Timer")];
ReliablePacketM.NetworkPacket -> NetworkLinkQueuesM.NetworkPacket[10];
}
--- NEW FILE: ReliablePacketM.nc ---
/* tab:4
*
*
* "Copyright (c) 2000-2002 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."
*
*/
/* tab:4
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
* downloading, copying, installing or using the software you agree to
* this license. If you do not agree to this license, do not download,
* install, copy or use the software.
*
* Intel Open Source License
*
* Copyright (c) 2002 Intel Corporation
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
/*
* This module implements a simple reliable packet protocol. A sequence
* number is added to the sent packet. When the destination received
* the packet, it sends an ACK packet. The ACK packet consists of only
* the sequence number, no command field is needed, a 0 payload packet
* is assumed to be an ACK packet. When this module receives the
* ACK, it removes the entry and signals the SendDone to the app.
* A fixed retry interval is set and retry count is set, the module will
* continue sending the packet, until an ACK is received, or the retry
* count is exhausted.
* Only 4 extra bytes of overhead are used
*/
module ReliablePacketM {
provides {
interface ReliablePacket;
}
uses {
interface NetworkPacket;
interface Timer;
}
}
implementation {
//#define TRACE_DEBUG_LEVEL 0ULL // disable debug
#define TRACE_DEBUG_LEVEL DBG_USR1 // enable debug
#define MAX_PACKETS 8
#define RETRY_INTERVAL 400
#define NUM_RETRIES 60
#define ACK_FLAG 0x80000000 // msb indicates an ACK packet
#define SEQ_MASK 0x7fffffff
#define MAX_SEQ ACK_FLAG
uint32 CurrentSeq;
uint16 Retries;
uint16 RetryInterval;
uint8 NumPacketsInProgress;
uint8 NextSlot;
bool TimerRunning;
typedef struct tSendInfo {
uint32 seq;
uint32 dest;
uint8 *packet;
uint16 len;
uint8 retries;
uint8 acked; // Send done returned by lower layer
} tSendInfo;
tSendInfo PacketInfo[MAX_PACKETS];
uint8 GetEmptySlot() {
uint8 i;
for (i=0; i<MAX_PACKETS; i++) {
if (PacketInfo[i].dest == 0) {
return i;
}
}
return MAX_PACKETS;
}
/*
* Find a slot with a specific Dest and seq number. If the passed dest or seq = 0
* then it is a don't care in the search
*/
uint8 FindSlot(uint32 Dest, uint32 Seq) {
uint8 i;
for (i=0; i<MAX_PACKETS; i++) {
if (((PacketInfo[i].dest == Dest) || (Dest == 0)) &&
((PacketInfo[i].seq == Seq) || (Seq == 0))) {
return i;
}
}
return MAX_PACKETS;
}
void init() {
uint8 i;
TimerRunning = false;
CurrentSeq = 1;
Retries = NUM_RETRIES; // call can override
NumPacketsInProgress = 0;
NextSlot = 0;
for (i=0; i<MAX_PACKETS; i++) {
PacketInfo[i].dest = 0;
}
}
/*
* Reliable NetworkPacket Interface
*/
command result_t ReliablePacket.Initialize() {
init();
return call NetworkPacket.Initialize();
}
command result_t ReliablePacket.SetNumRetries(uint8 NumRetries) {
Retries = NumRetries;
return SUCCESS;
}
command result_t ReliablePacket.Send(uint32 Destination, uint8 *Data,
uint16 Length) {
uint8 slot;
uint32 *Hdr;
// Check if we have enough space, don't allow 0 size packet
if ((Length == 0) || (NumPacketsInProgress >= MAX_PACKETS)) {
trace(TRACE_DEBUG_LEVEL,"RP : can't send\r\n");
return FAIL;
}
// Put in Array and send it out
slot = GetEmptySlot();
if (slot == MAX_PACKETS) {
trace(TRACE_DEBUG_LEVEL,"RP : no slots\r\n");
return FAIL;
}
if (!TimerRunning) {
atomic {
call Timer.start(TIMER_REPEAT, RETRY_INTERVAL);
TimerRunning = true;
}
}
// Add sequence to header
Data = Data - 4;
Hdr = (uint32 *) Data;
*Hdr = CurrentSeq;
PacketInfo[slot].dest = Destination;
PacketInfo[slot].packet = Data;
PacketInfo[slot].len = Length+4;
PacketInfo[slot].seq = CurrentSeq;
PacketInfo[slot].retries = Retries;
PacketInfo[slot].acked = 0;
CurrentSeq++;
if (CurrentSeq == MAX_SEQ) {
CurrentSeq = 1;
}
NumPacketsInProgress++;
// Send Packet
if (call NetworkPacket.Send(Destination, Data, Length+4) == SUCCESS) {
trace(TRACE_DEBUG_LEVEL,"RP:Sent packet to %5X, Seq %x\r\n",
Destination, PacketInfo[slot].seq);
return SUCCESS;
}
trace(TRACE_DEBUG_LEVEL,"RP:Failed sending packet, %x to %5X\r\n",
PacketInfo[slot].seq, Destination);
PacketInfo[slot].acked = 1; // Didn't send it, don't wait for send done
return FAIL;
}
command char *ReliablePacket.AllocateBuffer(uint16 BufferSize) {
char *Hdr;
// Add space for this layer's header, just sequence number
Hdr = call NetworkPacket.AllocateBuffer(BufferSize+4);
if (Hdr == NULL) {
return NULL;
}
return (Hdr+4);
}
command result_t ReliablePacket.ReleaseBuffer(char *BufferPtr) {
return call NetworkPacket.ReleaseBuffer(BufferPtr-4);
}
/*
* Regular Network Packet
*/
event result_t NetworkPacket.SendDone(char *data) {
uint32 *Hdr;
uint8 slot;
Hdr = (uint32 *) data;
trace(TRACE_DEBUG_LEVEL,"RP:senddone : seq %x\r\n", *Hdr);
// If ACK packet, just release the buffer
if ((*Hdr & ACK_FLAG) == ACK_FLAG) {
call NetworkPacket.ReleaseBuffer(data);
return SUCCESS;
}
// Data Packet, Find the packet, set the Acked flag
slot = FindSlot(0, *Hdr); // Dest field is don't care
if (slot == MAX_PACKETS) {
trace(TRACE_DEBUG_LEVEL,"RP:senddone : can't find slot %x\r\n", *Hdr);
call NetworkPacket.ReleaseBuffer(data);
return SUCCESS;
}
PacketInfo[slot].acked = 1;
trace(TRACE_DEBUG_LEVEL,"RP:senddone : packet sent %x\r\n", *Hdr);
return SUCCESS;
}
event result_t NetworkPacket.Receive(uint32 source, uint8 *data,
uint16 len) {
uint32 *Hdr;
uint8 slot;
uint8 *AckPacket;
uint32 seq;
uint32 *seq_ptr;
Hdr = (uint32 *) data;
/*
* check if this is a data packet or an ACK packet
*/
if ((*Hdr & ACK_FLAG) == ACK_FLAG) {
/*
* Only sequence number, ACK packet
* Find it in the list, and signal send done to app, for now we allow
* multiple ACKS to go to the app, later we can add book keeping
*/
seq = *Hdr & SEQ_MASK;
slot = FindSlot(source, seq); // Dest field is don't care
if (slot == MAX_PACKETS) {
trace(TRACE_DEBUG_LEVEL,"RP:ACK, can't find slot, %x\r\n", seq);
return SUCCESS;
}
// Found the packet, send up the send done
trace(TRACE_DEBUG_LEVEL,"RP:ACK, seq %X\r\n", seq);
signal ReliablePacket.SendDone(PacketInfo[slot].packet+4, SUCCESS);
NumPacketsInProgress--;
PacketInfo[slot].dest = 0;
if (TimerRunning && (NumPacketsInProgress == 0)) {
atomic {
call Timer.stop();
TimerRunning = false;
}
}
return SUCCESS;
}
// This is a data packet, send ACK to the other side and send the data up
seq_ptr = (uint32 *) data;
seq = *seq_ptr;
trace(TRACE_DEBUG_LEVEL,"RP:Recv data from %5X, seq %x\r\n", source, seq);
signal ReliablePacket.Receive(source, data+4, len-4);
AckPacket = call NetworkPacket.AllocateBuffer(4);
if (AckPacket == NULL) {
return SUCCESS;
}
seq_ptr = (uint32 *) AckPacket;
*seq_ptr = seq | ACK_FLAG;
call NetworkPacket.Send(source, AckPacket, 4);
return SUCCESS;
}
void task SendPackets() {
uint8 i;
uint32 *temp;
if (NumPacketsInProgress == 0) {
return;
}
for (i=0; i<MAX_PACKETS; i++) {
NextSlot++;
if (NextSlot == MAX_PACKETS) {
NextSlot = 0;
}
if ((PacketInfo[NextSlot].dest != 0) && (PacketInfo[NextSlot].acked == 1)) {
if (PacketInfo[NextSlot].retries == 0) {
// Delete it, and signal to app
trace(TRACE_DEBUG_LEVEL,"RP : Max retries, dropping packet, %x\r\n", PacketInfo[NextSlot].seq);
signal ReliablePacket.SendDone(PacketInfo[NextSlot].packet+4, FAIL);
NumPacketsInProgress--;
PacketInfo[NextSlot].dest = 0;
if (TimerRunning && (NumPacketsInProgress == 0)) {
atomic {
call Timer.stop();
TimerRunning = false;
}
}
continue; // find next slot
}
if (call NetworkPacket.Send(PacketInfo[NextSlot].dest,
PacketInfo[NextSlot].packet,
PacketInfo[NextSlot].len) == SUCCESS) {
PacketInfo[NextSlot].acked = 0;
PacketInfo[NextSlot].retries--;
temp = (uint32 *) PacketInfo[NextSlot].packet;
trace(TRACE_DEBUG_LEVEL,"RP : retrying packet slot %d, %x, %x\r\n",
NextSlot, PacketInfo[NextSlot].seq, *temp);
return;
}
}
}
}
/*
* Start of Timer interface.
*/
event result_t Timer.fired() {
post SendPackets();
return SUCCESS;
}
}
--- NEW FILE: ReliableTransportC.nc ---
/* tab:4
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
* downloading, copying, installing or using the software you agree to
* this license. If you do not agree to this license, do not download,
* install, copy or use the software.
*
* Intel Open Source License
*
* Copyright (c) 2002 Intel Corporation
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
includes WSN;
includes WSN_Messages;
includes ReliableTransportParams;
includes StatsTypes;
configuration ReliableTransportC
{
provides {
interface VarSend[uint8 app_id];
interface VarRecv[uint8 app_id];
interface StdControl as Control;
}
}
implementation
{
components ReliableTransportM,
GenericPacketM,
TimerC,
UtilitiesM,
StatsLoggerM,
NetworkLinkQueuesM;
VarSend = ReliableTransportM;
VarRecv = ReliableTransportM;
Control = ReliableTransportM;
ReliableTransportM.GenericPacket -> GenericPacketM;
ReliableTransportM.RTCommControl -> GenericPacketM.Control;
ReliableTransportM.Timer -> TimerC.Timer[unique("Timer")];
ReliableTransportM.StatsLogger -> StatsLoggerM;
GenericPacketM.NetworkPacket -> NetworkLinkQueuesM.NetworkPacket[11];
GenericPacketM.iMoteToTOSAddr -> UtilitiesM;
GenericPacketM.TOSToIMoteAddr -> UtilitiesM;
}
--- NEW FILE: ReliableTransportM.nc ---
/*
* Copyright (c) 2003-2004 Intel Corporation
*/
/*
* Authors: Jasmeet Chhabra
*
*/
/**
* WARNING: This module packs addresses into 8 bytes. Be careful when
* using 16-byte addressing.
* This code assumes that only Send can be pending at any given time
*/
//****************************************************************************
//*************************Important notes************************************
//-------------------------------1--------------------------------------------
//*** Window size used in nacks is assumed to be a multipole of 8*************
//*** This is not too restrictive, and allows for ease of implementation******
[...2007 lines suppressed...]
return SUCCESS;
}
default event result_t VarSend.sendDone[uint8_t app](void *Handle,
result_t Result){
return SUCCESS;
}
default event result_t VarRecv.recvReq[uint8_t app](uint16_t SrcAddr, uint16_t NumBytes, uint8_t TransactionID){
return SUCCESS;
}
default event result_t VarRecv.putSegReq[uint8_t app](void *Handle, uint16_t MsgOffset, uint8_t *SegBuf, uint8_t SegSize){
return SUCCESS;
}
default event result_t VarRecv.recvDone[uint8_t app](void *Handle, result_t Result){
return SUCCESS;
}
}
--- NEW FILE: ReliableTransportParams.h ---
/* tab:4
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
* downloading, copying, installing or using the software you agree to
* this license. If you do not agree to this license, do not download,
*
*/
/* tab:4
* "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."
*
*/
//#define RELIABLE_TRANSPORT_DEBUG
#define REL_MAIN_TIMER (40L)
/*
* Default parameters
*/
#define REL_VER_NUM (1) // version
/*
* REL_FRAG_PERIOD : sender throttling delay,
* The minimum time (in ms) between two consecutive fragments
*/
#define REL_FRAG_PERIOD (40L)
/*
* REL_WIN_SIZE : The size of the ACK window, should be multiple of 8
*/
#define REL_WIN_SIZE (32L)
/*
* REL_ACK_STATUS_ARRAY_SIZE : This assumes that the window size is
* a multiple of 8
*/
#define REL_ACK_STATUS_ARRAY_SIZE (REL_WIN_SIZE/8)
/*
* BITMAP size is a function of the window size, this assumes a max window
* size of 40
*/
#define REL_MAX_ACK_BITMAP_SIZE (8)
/*
* Imote frag size, max of 94, assume DM3 packets for now, and adjust
* for header overhead
*/
#define REL_MAX_FRAG_SIZE (94)
/*
* Scale of these timers in MAIN_TIMER ticks
*/
#define REL_RESEND_CONN_REQ_TIMER (28)
#define REL_RESEND_ACK_RESEND_TIMER (32)
#define REL_RESEND_CONN_REQ_MAX_TRIES (50)
#define REL_RESEND_ACK_RESEND_MAX_TRIES (10)
/*
* Maximum number of connections allowed by the receiver
*/
#define REL_MAX_CONN_NUM (1)
/*
* In ms
*/
#define REL_MAX_NET_DELAY (50)
/*
* Scale in ms, used by first short nack
*/
#define REL_MAX_DATA_STARTUP_TIME (1500)
#define REL_MAX_NACK_TRIES (5)
#define REL_NMAX_ACKS (3)
--- NEW FILE: StatsLogger.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
interface StatsLogger {
/*
* This command is used to add a value to a predefined counter
*/
command result_t BumpCounter(uint8 counter_type, uint32 value);
/*
* This command overwrites the counter with the passed value
*/
command result_t OverwriteCounter(uint8 counter_type, uint32 value);
/*
* This command captures the value of the local time, a later call
* to StopTimerUpdateCounter will subtract the stored local time value
* from the new time and bump up the specified counter with that value
*/
command result_t StartTimer(uint8 counter_type);
command result_t StopTimerUpdateCounter(uint8 counter_type);
/*
* This command resets all the counters
*/
command result_t ResetCounters();
/*
* This command prints the counter values into a buffer in the
* following format:
* First byte contains number of counters
* For each counter, it will add the following info
* type <1B>, len <1B>, value <len B>
*/
command uint8 *GetCounterBuffer(uint32 *buffer_size);
/*
* This command frees the buffer
*/
command result_t FreeCounterBuffer(uint8 *CounterBuffer);
}
--- NEW FILE: StatsLoggerM.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
module StatsLoggerM {
provides {
interface StdControl;
interface StatsLogger;
}
uses {
interface Timer;
interface Memory;
}
}
implementation {
#define MY_TICK 10 // 10 ms
uint32 StatCounters[NUM_TYPES];
uint8 CounterSizes[NUM_TYPES];
uint32 MyTime;
uint32 StartTimes[NUM_TYPES];
uint8 NumRunningTimers;
bool RunCounters;
uint8 MaxLogSize;
void DisplayStr(char *str) C_ROUTINE;
void debug_msg (char *str) {
DisplayStr(str);
}
void InitCounterSizes() {
uint8 i;
CounterSizes[MSEC_MOTE_ON] = 4;
CounterSizes[MSEC_MOTE_TX] = 4;
CounterSizes[MSEC_SENSOR_BOARD_ON] = 4;
CounterSizes[MSEC_SENSOR_ANALOG_ON] = 4;
CounterSizes[MSEC_NETWORK_FORMATION] = 4;
CounterSizes[MSEC_PER_SENSOR_TRANSFER] = 4;
CounterSizes[MSEC_PER_MOTE_TRANSFER] = 4;
CounterSizes[MSEC_PER_CLUSTER_TRANSFER] = 4;
CounterSizes[NUM_RT_SEND_DATA] = 2;
CounterSizes[NUM_RT_RECV_DATA] = 2;
CounterSizes[NUM_RT_SEND_NACK] = 2;
CounterSizes[NUM_RT_RECV_NACK] = 2;
CounterSizes[NUM_ROUTING_SEND] = 2;
CounterSizes[NUM_ROUTING_RECV] = 2;
CounterSizes[NUM_PS_SEND] = 2;
CounterSizes[NUM_PS_RECV] = 2;
CounterSizes[NUM_DS_SEND] = 2;
CounterSizes[NUM_DS_RECV] = 2;
CounterSizes[NUM_TOTAL_SEND] = 2;
CounterSizes[NUM_TOTAL_RECV] = 2;
CounterSizes[HOP_COUNT_TO_CH] = 2;
CounterSizes[ID_OF_NEXT_HOP] = 2;
CounterSizes[NUM_NM_SEND] = 2;
CounterSizes[NUM_NM_RECV] = 2;
CounterSizes[NUM_NP_SEND] = 2;
CounterSizes[NUM_NP_RECV] = 2;
CounterSizes[NUM_SF_SEND] = 2;
CounterSizes[NUM_SF_RECV] = 2;
MaxLogSize = 1; // Num of fields
for (i=0; i<NUM_TYPES; i++) {
MaxLogSize+= CounterSizes[i] + 2; // type, value, len
}
}
void ResetCounters() {
uint8 i;
for (i=0; i<NUM_TYPES; i++) {
StatCounters[i] = 0;
StartTimes[i] = 0;
}
}
command result_t StdControl.init() {
ResetCounters();
MyTime = 1;
NumRunningTimers = 0;
RunCounters = false;
InitCounterSizes();
return SUCCESS;
}
command result_t StdControl.start() {
RunCounters = true;
return SUCCESS;
}
command result_t StdControl.stop() {
RunCounters = false;
return SUCCESS;
}
command result_t StatsLogger.BumpCounter(uint8 counter_type, uint32 value) {
if ((counter_type < NUM_TYPES) && RunCounters) {
StatCounters[counter_type] += value;
}
return SUCCESS;
}
command result_t StatsLogger.OverwriteCounter(uint8 counter_type, uint32 value) {
if ((counter_type < NUM_TYPES) && RunCounters) {
StatCounters[counter_type] = value;
}
return SUCCESS;
}
command result_t StatsLogger.StartTimer(uint8 counter_type) {
if ((counter_type < NUM_TYPES) && RunCounters) {
if (NumRunningTimers == 0) {
call Timer.start(TIMER_REPEAT, MY_TICK);
}
if (StartTimes[counter_type] == 0) {
StartTimes[counter_type] = MyTime;
NumRunningTimers++;
}
}
return SUCCESS;
}
command result_t StatsLogger.StopTimerUpdateCounter(uint8 counter_type) {
uint32 TimePassed;
if ((counter_type < NUM_TYPES) && RunCounters) {
if (StartTimes[counter_type] > 0) {
// was a running counter, update the value
TimePassed = (MyTime - StartTimes[counter_type]) * MY_TICK;
StatCounters[counter_type] += TimePassed;
// Stop the counter, update state
NumRunningTimers--;
StartTimes[counter_type] = 0;
if (NumRunningTimers == 0) {
call Timer.stop();
}
}
}
return SUCCESS;
}
command result_t StatsLogger.ResetCounters() {
ResetCounters();
if (NumRunningTimers > 0) {
call Timer.stop();
NumRunningTimers = 0;
}
return SUCCESS;
}
/*
* Write up the buffer in the following format
* Number of counters <1B> field
* Type <1B>, len <1B>, value
*/
command uint8 *StatsLogger.GetCounterBuffer(uint32 *BufferSize) {
uint8 *membuf, *tempbuf;
uint8 NumBytes, NumFields;
uint8 i, type_size;
membuf = call Memory.alloc(MaxLogSize);
if (membuf == NULL) {
return NULL;
}
NumBytes = 1;
NumFields = 0;
tempbuf = membuf + 1; // first byte is the number of fields
for (i=0; i<NUM_TYPES; i++) {
if (StatCounters[i] > 0) {
NumFields++;
type_size = CounterSizes[i];
NumBytes+= type_size + 2;
tempbuf[0] = i; // type
tempbuf[1] = type_size; //len
tempbuf+= 2;
switch (type_size) {
case 1:
tempbuf[0] = (uint8) StatCounters[i];
tempbuf++;
break;
case 2:
tempbuf[0] = (uint8) (StatCounters[i] & 0xff);
tempbuf[1] = (uint8) ((StatCounters[i] >> 8) & 0xff);
tempbuf+= 2;
break;
case 4:
tempbuf[0] = (uint8) (StatCounters[i] & 0xff);
tempbuf[1] = (uint8) ((StatCounters[i] >> 8) & 0xff);
tempbuf[2] = (uint8) ((StatCounters[i] >> 16) & 0xff);
tempbuf[3] = (uint8) ((StatCounters[i] >> 24) & 0xff);
tempbuf+= 4;
break;
}
}
}
membuf[0] = NumFields;
*BufferSize = NumBytes;
return membuf;
}
command result_t StatsLogger.FreeCounterBuffer(uint8 *CounterBuffer) {
call Memory.free(CounterBuffer);
return SUCCESS;
}
event result_t Timer.fired() {
MyTime++;
return SUCCESS;
}
}
--- NEW FILE: StatsTypes.h ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
// Possible actions handled by the power-tracker
enum {
/*
* Time in milliseconds, all these fields are 4 bytes long
* All these counters exclude statistics related times
* WARNING : If you add enums, update the stats logger with the new
* sizes
*/
MSEC_MOTE_ON = 0, // 0 -
MSEC_MOTE_TX, // 1 -
MSEC_SENSOR_BOARD_ON, // 2 -
MSEC_SENSOR_ANALOG_ON, // 3 -
MSEC_NETWORK_FORMATION, // 4 -
MSEC_PER_SENSOR_TRANSFER, // 5 -
MSEC_PER_MOTE_TRANSFER, // 6 -
MSEC_PER_CLUSTER_TRANSFER, // 7
// Num packets : All these fields are 2 bytes long
NUM_RT_SEND_DATA, // 8 -
NUM_RT_RECV_DATA, // 9
NUM_RT_SEND_NACK, // 10
NUM_RT_RECV_NACK, // 11 -
NUM_ROUTING_SEND, // 12 -
NUM_ROUTING_RECV, // 13 -
NUM_PS_SEND, // 14 -
NUM_PS_RECV, // 15 -
NUM_DS_SEND, // 16 -
NUM_DS_RECV, // 17 -
NUM_TOTAL_SEND, // 18 -
NUM_TOTAL_RECV, // 19 -
// Other : 2 bytes each
HOP_COUNT_TO_CH, // 20 -
ID_OF_NEXT_HOP, // 21 -
// Imote specifics
NUM_NM_SEND, // 22 -
NUM_NM_RECV, // 23 -
NUM_NP_SEND, // 24 -
NUM_NP_RECV, // 25 -
NUM_SF_SEND, // 26 -
NUM_SF_RECV, // 27 -
NUM_NODES_FOUND, // 28 -
// END
NUM_TYPES
};
--- NEW FILE: SystemTime.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*author krishna - Intel santa clara*/
interface SystemTime{
/*gets the 32 bit system time*/
command uint32_t getSystemTime();
/*sets the 32 bit system time*/
command void setSystemTime(uint32_t time);
}
--- NEW FILE: TimerC.nc ---
// $Id: TimerC.nc,v 1.1 2005/09/06 08:27:59 lnachman Exp $
/* tab:4
* "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: Su Ping, (converted to nesC by Sam Madden)
* David Gay, Intel Research Berkeley Lab
* Phil Levis
* Date: 4/12/2002
* NesC conversion: 6/28/2002
* interface cleanup: 7/16/2002
* Configuration: 8/12/2002
*/
/**
* @author Su Ping
* @author (converted to nesC by Sam Madden)
* @author David Gay
* @author Intel Research Berkeley Lab
* @author Phil Levis
*/
configuration TimerC {
provides interface Timer[uint8_t id];
provides interface StdControl;
}
implementation {
components TimerM, ClockC, HPLPowerManagementM;
TimerM.Clock -> ClockC;
TimerM.PowerManagement -> HPLPowerManagementM;
StdControl = TimerM;
Timer = TimerM;
}
--- NEW FILE: UtilitiesM.nc ---
/*
* Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* The WSN addresses are 8 bits, the iMote addresses are 32 bits
* and they start with 0x85000. For now, the WSN addresses are restricted
* to 8 bits, they will change it to 16 which will be sufficient for iMotes
* For now, assume range is 0x85100 - 0x85255. Subtract/Add offset when
* converting.
* TODO : Need to fix when WSN moves to 16 bits
*/
//#define ADDR_OFFSET 0x85100
#define ADDR_OFFSET 0
#define TABLE_MAP 0
includes WSN;
module UtilitiesM {
provides {
command result_t iMoteToTOSAddr(uint32 Imote_Addr, uint16 *TOSAddr);
command result_t TOSToIMoteAddr(uint16 TOSAddr, uint32 *Imote_Addr);
}
}
implementation {
uint16 TableImoteToTOS(uint32 imote_addr) {
switch(imote_addr) {
case 0x86140 :
return 100;
case 0x86132 :
return 101;
case 0x86289 :
return 102;
case 0x86259:
return 103;
case 0x86206:
return 104;
case 0x86202:
return 105;
case 0x86314:
return 106;
case 0x85064:
return 107;
case 0x86316:
return 122;
case 0x86208:
return 123;
case 0x86308:
return 124;
case 0x86266:
return 125;
default :
return 199;
}
}
uint32 TableTOSToImote(uint16 TOS_Addr) {
switch(TOS_Addr) {
case 100:
return 0x86140;
case 101:
return 0x86132;
case 102:
return 0x86289;
case 103:
return 0x86259;
case 104:
return 0x86206;
case 105:
return 0x86202;
case 106:
return 0x86314;
case 107:
return 0x85064;
case 122:
return 0x86316;
case 123:
return 0x86208;
case 124:
return 0x86308;
case 125:
return 0x86266;
default :
return 0x86000;
}
}
command result_t iMoteToTOSAddr(uint32 Imote_Addr, uint16 *TOSAddr) {
#if TABLE_MAP
*TOSAddr = TableImoteToTOS(Imote_Addr);
#else
uint32 temp;
temp = Imote_Addr - ADDR_OFFSET;
*TOSAddr = (uint16) temp;
#endif
return SUCCESS;
}
command result_t TOSToIMoteAddr(uint16 TOSAddr, uint32 *Imote_Addr) {
#if TABLE_MAP
*Imote_Addr = TableTOSToImote(TOSAddr);
#else
*Imote_Addr = ADDR_OFFSET + TOSAddr;
#endif
return SUCCESS;
}
}
--- NEW FILE: WSN.h ---
/* tab:4
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
* downloading, copying, installing or using the software you agree to
* this license. If you do not agree to this license, do not download,
*
*/
/* tab:4
* "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."
*
*/
/* tab:4
* Copyright (c) 2003 Intel Corporation
* All rights reserved Contributions to the above software program by Intel
* Corporation is program is licensed subject to the BSD License, available at
* http://www.opensource.org/licenses/bsd-license.html
*
*/
/*
* Authors: Mark Yarvis, York Liu
*
*/
enum {
#ifdef CONST_TXRES_VAL
TXRES_VAL = CONST_TXRES_VAL
#else
TXRES_VAL = 70
#endif
};
enum {
#ifdef CONST_PROGVER
PROGVER = CONST_PROGVER
#else
PROGVER = 0
#endif
};
// A result that indicates what to do with a packet
typedef uint8_t PacketResult_t;
enum {
FORWARD = 0,
DROP = 1,
RTS = 2 // return to sender
};
enum {
INVALID_NODE_ID = 255,
INVALID_INDEX = 255
};
enum {
TASK_DONE = 0,
TASK_PENDING = 1,
TASK_REPOSTREQ = 2
};
typedef uint8_t wsnAddr;
#ifndef CLOCK_SCALE
#define CLOCK_SCALE 1000L
#endif
--- NEW FILE: WSN_Messages.h ---
/* tab:4
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
* downloading, copying, installing or using the software you agree to
* this license. If you do not agree to this license, do not download,
*
*/
/* tab:4
* "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."
*
*/
/* tab:4
* Copyright (c) 2003 Intel Corporation
* All rights reserved Contributions to the above software program by Intel
* Corporation is program is licensed subject to the BSD License, available at
* http://www.opensource.org/licenses/bsd-license.html
*
*/
/*
* Authors: Mark Yarvis, Nandu Kushalnagar, Jasmeet Chhabra
*
*/
// active message id's are used to distinguish single-hop messages
enum {
AM_ID_FLOOD = 2, // FLOOD data packet
AM_ID_DSDV = 3, // DSDV data packet
AM_ID_DSDV_SOI = 4, // DSDV data packet with source sphere id
AM_ID_DSDV_RUPDATE_HOPS = 5, // DSDV rupdate with hop count metric
AM_ID_DSDV_RUPDATE_QUALITY = 6, // DSDV rupdate with quality metric
AM_ID_DSDV_RUPDATE_SOI = 7, // DSDV rupdate with SoI metric
AM_ID_DSDV_RUPDATE_CLUSTER = 9, // DSDV rupdate with clustering
AM_ID_DSDV_RUPDATE_REQ = 8, // DSDV rupdate request
AM_ID_AODV = 9, // AODV data packet
AM_ID_AODV_RREQ = 10, // AODV route request
AM_ID_AODV_RREPLY = 11, // AODV route reply
AM_ID_AODV_RERR = 12, // AODV route reply
AM_ID_AODV_RREQ_HOPS = 13,
AM_ID_AODV_RREPLY_HOPS = 14,
AM_ID_AODV_RERR_HOPS = 15,
AM_ID_SOURCEROUTE = 16,
AM_ID_RT_ACK = 17,
AM_ID_FAB_TMP_DATA_CAP = 18 // this is a temp message used to initiate capture until we do not have power saving protocol integrated
};
// application id's are used to distinguish multi-hop messages
enum {
APP_ID_SETTINGS = 2,
APP_ID_TRACEROUTE = 3,
APP_ID_TRACEROUTE_SOI = 4,
APP_ID_SOURCEROUTE =5,
APP_ID_AODV_TEST = 6,
APP_ID_CONF_ROOM_STATUS = 7,
APP_ID_CONF_ROOM_RESERVATION = 8,
APP_ID_CONF_ROOM_RES_BEACON = 9,
APP_ID_CLUSTER_SLEEP = 10,
APP_ID_RELIABLE_TRANSPORT = 11, // special app for reliable transport protocol
APP_ID_FAB_TMP_DATA_CAP = 12 // temp for data cap msg in fab app
};
// reliable app id's are used to demultiplex between apps using the reliable transport protocol
enum {
RELIABLE_APP_ID_DATA_TRANSFER = 2,
RELIABLE_APP_ID_STATS_TRANSFER
};
typedef struct {
wsnAddr src;
uint8_t seq;
uint8_t data[1]; // start of payload; size is not known at compile time
} SHop_Msg;
typedef SHop_Msg *SHop_MsgPtr;
typedef union {
SHop_MsgPtr msg;
uint8_t* bytes;
} SHop_MsgPtr_u;
typedef struct {
wsnAddr src;
wsnAddr dest;
uint8_t app;
wsnAddr length;
} MHop_Header;
typedef struct {
MHop_Header mhop;
uint8_t seq;
uint8_t ttl;
uint8_t data[1]; // start of payload; size is not known at compile time
} Flood_Msg;
typedef Flood_Msg *Flood_MsgPtr;
typedef union {
Flood_MsgPtr msg;
uint8_t* bytes;
} Flood_MsgPtr_u;
typedef struct {
MHop_Header mhop;
uint8_t seq;
uint8_t ttl;
uint8_t data[1]; // start of payload; size is not known at compile time
} DSDV_Msg;
typedef DSDV_Msg *DSDV_MsgPtr;
typedef union {
DSDV_MsgPtr msg;
uint8_t* bytes;
} DSDV_MsgPtr_u;
typedef struct {
wsnAddr dest;
uint8_t seq;
uint8_t metric[1]; // space for the metric(s) and piggyback info
} DSDV_Rupdate_Msg;
typedef DSDV_Rupdate_Msg *DSDV_Rupdate_MsgPtr;
typedef union {
DSDV_Rupdate_MsgPtr msg;
uint8_t* bytes;
} DSDV_Rupdate_MsgPtr_u;
typedef struct {
MHop_Header mhop;
uint8_t seq;
uint8_t ttl;
uint8_t data[1]; // start of payload; size is not known at compile time
} AODV_Msg;
typedef AODV_Msg *AODV_MsgPtr;
typedef struct {
wsnAddr dest;
wsnAddr src;
uint16_t rreqID;
uint16_t srcSeq; // seq# used for storing entries back to the source
uint16_t destSeq; // seq# last received from the destination by the source
uint8_t metric[1];
uint8_t data[1];
} AODV_Rreq_Msg;
typedef AODV_Rreq_Msg* AODV_Rreq_MsgPtr;
typedef struct {
wsnAddr dest;
wsnAddr src;
uint16_t destSeq;
uint8_t metric[1];
uint8_t data[1];
} AODV_Rreply_Msg;
typedef AODV_Rreply_Msg* AODV_Rreply_MsgPtr;
typedef struct {
wsnAddr dest;
uint16_t destSeq;
uint8_t data[1];
} AODV_Rerr_Msg;
typedef AODV_Rerr_Msg* AODV_Rerr_MsgPtr;
typedef struct{
uint8_t cmd;
uint8_t seq;
wsnAddr src;
wsnAddr dest;
uint8_t sensor;
uint8_t dataSet;
uint8_t data[1];
}DataCapCmdMsg;
enum { //CMD types for data cap message
DATA_CAP_INIT = 15,
DATA_CAP_ACK = 16
};
typedef DataCapCmdMsg* DataCapCmdMsgPtr;
typedef __attribute__((packed)) struct{
uint16_t sensor;
uint16_t len;
uint32_t timestamp;
uint8_t data[1];
}SensorSampleHeader;
typedef SensorSampleHeader* SensorSampleHeaderPtr;
typedef __attribute__((packed)) struct{
uint8_t mtc;
uint8_t appId;
uint8_t tId;
} RelHeader;
typedef RelHeader* RelHeaderPtr;
typedef __attribute__((packed)) struct{
RelHeader rHead;
uint8_t ver;
__attribute__ ((packed)) uint16_t dataSize;
__attribute__ ((packed)) uint16_t fragSize;
__attribute__ ((packed)) uint16_t fragPeriod;
__attribute__ ((packed)) uint16_t netDelay;
uint8_t winSize;
uint8_t data[1];
}RelConnReq;
typedef RelConnReq* RelConnReqPtr;
typedef __attribute__ ((packed)) struct{
RelHeader rHead;
__attribute__ ((packed)) uint16_t dataSize;
__attribute__ ((packed)) uint16_t fragSize;
__attribute__ ((packed)) uint16_t nackPeriod;
uint8_t winSize;
uint8_t data[1];
}RelConnAcc;
typedef RelConnAcc* RelConnAccPtr;
typedef __attribute__((packed)) struct{
RelHeader rHead;
uint8_t reasonCode;
uint8_t data[1];
}RelConnRej;
typedef RelConnRej* RelConnRejPtr;
typedef __attribute__((packed)) struct{
RelHeader rHead;
__attribute__ ((packed)) uint16_t fragIndex;
uint8_t data[1];
}RelData;
typedef RelData* RelDataPtr;
typedef __attribute__((packed)) struct{
RelHeader rHead;
uint8_t seq;
__attribute__ ((packed)) uint16_t startFrag;
uint8_t data[1];
}RelNack;
typedef RelNack* RelNackPtr;
typedef __attribute__((packed)) struct{
RelHeader rHead;
uint8_t data[1];
}RelLastAck;
typedef RelLastAck* RelLastAckPtr;
typedef __attribute__((packed)) struct{
RelHeader rHead;
uint8_t data[1];
}RelRecLastAck;
typedef RelRecLastAck* RelRecLastAckPtr;
enum {
SHOP_HEADER_LEN = offsetof(SHop_Msg, data),
FLOOD_HEADER_LEN = offsetof(Flood_Msg, data),
DSDV_HEADER_LEN = offsetof(DSDV_Msg, data),
AODV_HEADER_LEN = offsetof(AODV_Msg, data), //temp stuff
AODV_RREQ_HEADER_LEN = offsetof(AODV_Rreq_Msg, data),
AODV_RREPLY_HEADER_LEN = offsetof(AODV_Rreply_Msg, data),
AODV_RERR_HEADER_LEN = offsetof(AODV_Rerr_Msg, data),
DSDV_RUPDATE_HEADER_LEN = offsetof(DSDV_Rupdate_Msg, metric),
DATA_CAP_MSG_LEN = offsetof(DataCapCmdMsg, data),
SENSOR_SAMPLE_HEADER_LEN = offsetof(SensorSampleHeader, data),
REL_CONN_REQ_LEN = offsetof(RelConnReq, data),
REL_CONN_ACC_LEN = offsetof(RelConnAcc, data),
REL_CONN_REJ_LEN = offsetof(RelConnRej, data),
REL_DATA_LEN = offsetof(RelData, data),
REL_NACK_LEN = offsetof(RelNack, data),
REL_LAST_ACK_LEN = offsetof(RelLastAck, data),
REL_REC_LAST_ACK_LEN = offsetof(RelRecLastAck, data)
// AODV_RUPDATE_HEADER_LEN = offsetof(AODV_Rupdate_Msg, metric) //temp stuff
};
--- NEW FILE: cmdlinetools.c ---
#include <inttypes.h>
// Command line tools.
// Get rid of extra whitespace.
void killWhiteSpace( char* str );
void killWhiteSpace( char* str )
{
uint16_t i, j;
uint16_t startIdx;
// Find first character or line end.
for( i = 0; str[i] != '\0'; i++ )
{
if( str[i] != ' ' )
{
break;
}
}
// Check for end of line.
if( str[i] == '\0' )
{
// Empty string.
str[0] = '\0';
return;
}
startIdx = 0;
while( 1 )
{
// i is the first character of the next word.
// startIdx is where it needs to be copied to.
// Copy line back.
j = startIdx;
while( str[i] != '\0' )
{
str[j] = str[i];
i++;
j++;
}
// Append '\0';
str[j] = '\0';
// Move startIdx to end of word.
for( ; str[startIdx] != ' ' && str[startIdx] != '\0'; startIdx++ )
{}
// See if next word exists;
// Looking for a isalpha.
for( j = startIdx; str[j] != '\0'; j++ )
{
if( str[j] != ' ' )
{
break;
}
}
// See if we fell off the end.
if( str[j] == '\0' )
{
// We're done.
// Copy the \0.
str[startIdx] = '\0';
return;
}
// Copy a space.
str[startIdx] = ' ';
startIdx++;
// j is the start of the next word.
i = j;
}
}
uint16_t firstSpace( char* str, uint16_t start )
{
uint16_t i;
for( i = start; str[i] != '\0'; i++ )
{
if( str[i] == ' ' )
{
return i;
}
}
return start;
}
uint16_t cntArgs( char* str, uint16_t start )
{
uint16_t count, i;
count = i = 0;
// Rollover of i is intentional.
i--;
do
{
i++;
if( str[i] == ' ' || str[i] == '\0' )
{
count++;
}
}
while( str[i] != '\0' );
return count;
}
Index: BTLowerLayersM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/BTLowerLayersM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** BTLowerLayersM.nc 29 Jun 2004 14:56:14 -0000 1.1
--- BTLowerLayersM.nc 6 Sep 2005 08:27:58 -0000 1.2
***************
*** 29,32 ****
--- 29,33 ----
* POSSIBILITY OF SUCH DAMAGE.
*/
+
/*
* This module provides a HCI interface to the lower level Bluetooth stack.
***************
*** 40,44 ****
*/
-
includes motelib;
--- 41,44 ----
***************
*** 61,71 ****
{
! //#define BTLL_DEBUG
!
! #ifdef BTLL_DEBUG
! void DisplayStr(char *str) __attribute__ ((C, spontaneous));
! #else
! #define DisplayStr(str)
! #endif
#define BLL_PACKETS_INFLIGHT 4
--- 61,65 ----
{
! #define TRACE_DEBUG_LEVEL DBG_RADIO
#define BLL_PACKETS_INFLIGHT 4
***************
*** 147,154 ****
void DisplayReceivePacketsPending() {
! char str[80];
!
! sprintf(str, "Warning - %d receive packets pending\r\n", ReceivePacketsPending);
! DisplayStr(str);
}
--- 141,146 ----
void DisplayReceivePacketsPending() {
!
! trace(TRACE_DEBUG_LEVEL,"Warning - %d receive packets pending\r\n", ReceivePacketsPending);
}
***************
*** 236,242 ****
void HCIEvent_Hardware_Error (tSIG_LmHardwareError *p) __attribute__ ((C, spontaneous)) {
! char str[80];
! sprintf(str, "Hardware Error %d \n", p->ErrorCode);
! DisplayStr(str);
}
void HCIEvent_PIN_Code_Request (tSIG_LmPinCodeRequest *p) __attribute__ ((C, spontaneous)) {}
--- 228,232 ----
void HCIEvent_Hardware_Error (tSIG_LmHardwareError *p) __attribute__ ((C, spontaneous)) {
! trace(TRACE_DEBUG_LEVEL,"Hardware Error %d \n", p->ErrorCode);
}
void HCIEvent_PIN_Code_Request (tSIG_LmPinCodeRequest *p) __attribute__ ((C, spontaneous)) {}
Index: DebugLedM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/DebugLedM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DebugLedM.nc 29 Jun 2004 14:56:14 -0000 1.1
--- DebugLedM.nc 6 Sep 2005 08:27:58 -0000 1.2
***************
*** 48,51 ****
--- 48,52 ----
interface NetworkTopology;
interface LowPower;
+ interface StatsLogger;
command result_t GetRootNodeID(uint32 *ID);
}
***************
*** 65,68 ****
--- 66,70 ----
bool RootNode;
bool LowPowerMode;
+ bool StopLed;
/*
***************
*** 75,78 ****
--- 77,81 ----
RootNodeID = INVALID_NODE;
LowPowerMode = false;
+ StopLed = false;
return SUCCESS;
}
***************
*** 85,88 ****
--- 88,92 ----
command result_t StdControl.stop() {
+ StopLed = true;
return SUCCESS;
}
***************
*** 133,140 ****
event result_t Timer.fired() {
uint32 HopCount;
MyTime++;
! if (LowPowerMode) {
// In Low Power, turn off all LEDS
TM_ResetPio(4);
--- 137,146 ----
event result_t Timer.fired() {
uint32 HopCount;
+ uint32 NextNode;
+ tHandle NextHandle;
MyTime++;
! if (LowPowerMode || StopLed) {
// In Low Power, turn off all LEDS
TM_ResetPio(4);
***************
*** 142,145 ****
--- 148,154 ----
TM_ResetPio(6);
LedOn = false;
+ if (StopLed) {
+ call Timer.stop();
+ }
return SUCCESS;
}
***************
*** 164,167 ****
--- 173,180 ----
}
+ call StatsLogger.OverwriteCounter(HOP_COUNT_TO_CH, HopCount);
+ call NetworkTopology.GetNextConnection(RootNodeID, &NextNode, &NextHandle);
+ call StatsLogger.OverwriteCounter(ID_OF_NEXT_HOP, NextNode);
+
if (MyTime > LastPacketTransfer + DEBUG_LAG_TIME) {
// Stop blinking
Index: FindRootScatternetFormationC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/FindRootScatternetFormationC.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FindRootScatternetFormationC.nc 29 Jun 2004 14:56:14 -0000 1.1
--- FindRootScatternetFormationC.nc 6 Sep 2005 08:27:58 -0000 1.2
***************
*** 29,32 ****
--- 29,33 ----
* POSSIBILITY OF SUCH DAMAGE.
*/
+
configuration FindRootScatternetFormationC
{
***************
*** 41,45 ****
interface NetworkPacket;
event result_t SuspendDataTraffic(bool status);
- command result_t Display(char *str);
}
}
--- 42,45 ----
***************
*** 53,56 ****
--- 53,57 ----
NetworkTopologyM,
WDTControlM,
+ StatsLoggerM,
RandomLFSR;
***************
*** 68,71 ****
--- 69,73 ----
FindRootScatternetFormationM.HCILinkPolicy -> BTLowerLayersM;
FindRootScatternetFormationM.HCIBaseband -> BTLowerLayersM;
+ FindRootScatternetFormationM.StatsLogger -> StatsLoggerM;
FindRootScatternetFormationM.NetworkTopology -> NetworkTopologyM;
Index: FindRootScatternetFormationM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/FindRootScatternetFormationM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FindRootScatternetFormationM.nc 29 Jun 2004 14:56:14 -0000 1.1
--- FindRootScatternetFormationM.nc 6 Sep 2005 08:27:58 -0000 1.2
***************
*** 29,32 ****
--- 29,33 ----
* POSSIBILITY OF SUCH DAMAGE.
*/
+
/*
* This module manages the network connections for each node.
***************
*** 61,64 ****
--- 62,67 ----
[...974 lines suppressed...]
} else {
***************
*** 1957,1965 ****
PendingConnection.Handle = Connection_Handle;
StateTreeDisconnectPendingConnection();
! sprintf(str, "Error - Page complete %05X in state %d\n", NodeID, NodeState);
! DisplayStr(str);
} else {
! sprintf(str, "Warning - Page complete %05X with invalid handle in state %d\n", NodeID, NodeState);
! DisplayStr(str);
}
}
--- 2089,2095 ----
PendingConnection.Handle = Connection_Handle;
StateTreeDisconnectPendingConnection();
! trace(TRACE_DEBUG_LEVEL,"Error - Page complete %05X in state %d\n", NodeID, NodeState);
} else {
! trace(TRACE_DEBUG_LEVEL,"Warning - Page complete %05X with invalid handle in state %d\n", NodeID, NodeState);
}
}
Index: GenericPacketM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/GenericPacketM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** GenericPacketM.nc 29 Jun 2004 14:56:14 -0000 1.1
--- GenericPacketM.nc 6 Sep 2005 08:27:58 -0000 1.2
***************
*** 1,25 ****
- /* tab:4
- *
- *
- * "Copyright (c) 2000-2002 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) 2004, Intel Corporation
--- 1,2 ----
***************
*** 75,85 ****
implementation {
! //#define GENERIC_PACKET_DEBUG
!
! #ifdef GENERIC_PACKET_DEBUG
! void DisplayStr(char *str) __attribute__ ((C, spontaneous));
! #else
! #define DisplayStr(str)
! #endif
--- 52,56 ----
implementation {
! #define TRACE_DEBUG_LEVEL DBG_PACKET
***************
*** 156,165 ****
uint16 PayloadSize) {
uint8 *Packet;
! {
! char str[80];
! sprintf(str, "GenericPacket Allocate %X len %d\n\r", Dest, PayloadSize);
! DisplayStr(str);
! }
!
if (NumPackets >= MAX_NUM_PACKETS) {
return NULL;
--- 127,132 ----
uint16 PayloadSize) {
uint8 *Packet;
! trace(TRACE_DEBUG_LEVEL,"GenericPacket Allocate %X len %d\n\r", Dest, PayloadSize);
!
if (NumPackets >= MAX_NUM_PACKETS) {
return NULL;
***************
*** 174,183 ****
command result_t GenericPacket.FreeBuffer(uint8 *Buffer) {
! {
! char str[80];
! sprintf(str, "GenericPacket Free\n\r");
! DisplayStr(str);
! }
! RemovePacket(Buffer);
return call NetworkPacket.ReleaseBuffer(Buffer);
}
--- 141,147 ----
command result_t GenericPacket.FreeBuffer(uint8 *Buffer) {
! trace(TRACE_DEBUG_LEVEL,"GenericPacket Free\n\r");
!
! RemovePacket(Buffer);
return call NetworkPacket.ReleaseBuffer(Buffer);
}
***************
*** 192,203 ****
uint16 PayloadSize) {
uint32 temp;
! {
! char str[80];
! sprintf(str, "GenericPacket send %x len %d data %x %x %x %x %x %x %x %x %x %x %x\n\r",
! addr, PayloadSize, Buffer[0], Buffer[1], Buffer[2], Buffer[3],
! Buffer[4], Buffer[5], Buffer[6], Buffer[7], Buffer[8],
! Buffer[9], Buffer[10]);
! DisplayStr(str);
! }
call TOSToIMoteAddr((uint16)addr, &temp);
return call NetworkPacket.Send(temp, Buffer, PayloadSize);
--- 156,164 ----
uint16 PayloadSize) {
uint32 temp;
! trace(TRACE_DEBUG_LEVEL, "GenericPacket send %x len %d data %x %x %x %x %x %x %x %x %x %x %x\n\r",
! addr, PayloadSize, Buffer[0], Buffer[1], Buffer[2], Buffer[3],
! Buffer[4], Buffer[5], Buffer[6], Buffer[7], Buffer[8],
! Buffer[9], Buffer[10]);
!
call TOSToIMoteAddr((uint16)addr, &temp);
return call NetworkPacket.Send(temp, Buffer, PayloadSize);
***************
*** 208,217 ****
*/
event result_t NetworkPacket.SendDone(char *data) {
! {
! char str[80];
! sprintf(str, "GenericPacket Send Done \n\r");
! DisplayStr(str);
! }
! signal GenericPacket.SendDone(data, SUCCESS);
return SUCCESS;
}
--- 169,176 ----
*/
event result_t NetworkPacket.SendDone(char *data) {
!
! trace(TRACE_DEBUG_LEVEL,"GenericPacket Send Done \n\r");
!
! signal GenericPacket.SendDone(data, SUCCESS);
return SUCCESS;
}
***************
*** 225,235 ****
*/
uint16 temp;
! {
! char str[80];
! sprintf(str, "GenericPacket Receive %x len %d data %x %x %x %x %x %x %x %x %x %x %x\n\r",
! source, len, data[0], data[1], data[2], data[3], data[4], data[5],
! data[6], data[7], data[8],data[9], data[10]);
! DisplayStr(str);
! }
call iMoteToTOSAddr(source, &temp);
signal GenericPacket.Receive((wsnAddr)temp, data, len);
--- 184,192 ----
*/
uint16 temp;
!
! trace(TRACE_DEBUG_LEVEL,"GenericPacket Receive %x len %d data %x %x %x %x %x %x %x %x %x %x %x\n\r",
! source, len, data[0], data[1], data[2], data[3], data[4], data[5],
! data[6], data[7], data[8],data[9], data[10]);
!
call iMoteToTOSAddr(source, &temp);
signal GenericPacket.Receive((wsnAddr)temp, data, len);
Index: HPLClock.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/HPLClock.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** HPLClock.nc 16 Aug 2004 18:14:06 -0000 1.2
--- HPLClock.nc 6 Sep 2005 08:27:58 -0000 1.3
***************
*** 1,32 ****
- /*
- * Copyright (c) 2004, Intel Corporation
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * Neither the name of the Intel Corporation nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
/* tab:4
*
--- 1,2 ----
***************
*** 52,55 ****
--- 22,62 ----
*
*/
+ /* tab:4
+ * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
+ * downloading, copying, installing or using the software you agree to
+ * this license. If you do not agree to this license, do not download,
+ * install, copy or use the software.
+ *
+ * Intel Open Source License
+ *
+ * Copyright (c) 2002 Intel Corporation
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ */
/*modified my krishna - intel SC to get system time,
***************
*** 62,66 ****
module HPLClock {
provides interface Clock;
! //provides interface SystemTime;
provides interface StdControl;
}
--- 69,73 ----
module HPLClock {
provides interface Clock;
! provides interface SystemTime;
provides interface StdControl;
}
***************
*** 69,172 ****
implementation
{
! uint8_t gmScale;
! uint8_t gmInterval;
! uint8_t gmCounter;
! uint32_t systemTime;
! bool clk_init=false;
! bool clk_start=false;
!
! void RTOSClockInterrupt() __attribute__ ((C, spontaneous)) {
! bool fFireEvent = FALSE;
! atomic {
! gmCounter++;
! systemTime++; //increment system time
! if (gmCounter >= gmInterval) {
! gmCounter = 0;
! fFireEvent = TRUE;
! }
! }
! if (fFireEvent) {
! signal Clock.fire();
}
! }
! command result_t StdControl.init() {
! atomic {
! if(clk_init==false){
! gmScale = DEFAULT_SCALE;
! gmInterval = DEFAULT_INTERVAL;
! gmCounter = 0;
! systemTime = 0; //initialize system time to zero
! clk_init=true;
}
! }
! return SUCCESS;
! }
! command result_t StdControl.start() {
! uint8_t mInt, mScl;
! atomic {
! if(clk_start==false){
! mInt = gmInterval;
! mScl = gmScale;
! gmCounter = 0;
! clk_start=true;
! }
}
- StartRTOSClock();
-
- call Clock.setRate(mInt,mScl);
- return SUCCESS;
- }
-
command result_t StdControl.stop() {
! uint8_t mInt;
!
! atomic mInt = gmInterval;
!
! StopRTOSClock();
!
! call Clock.setRate(mInt,0);
!
! return SUCCESS;
}
! async command result_t Clock.setRate(char interval, char scale) {
! // roughly translate mica's clock since it sits in the common interface
! // directory. Base on interfaces/Clock.h the following mapping is ~correct.
! // Arm core has a 12M external clock. Need to move Clock.h to platform
! // specific section and use arm's granularities.
! uint32 rate;
!
! atomic {
! gmScale = scale;
! gmInterval = interval;
! gmCounter = 0;
! }
!
! switch (scale) {
! case 0: rate = (0 << 0); break;
! case 1: rate = (1 << 0); break;
! case 2: rate = (1 << 3); break;
! case 3: rate = (1 << 5); break;
! case 4: rate = (1 << 6); break;
! case 5: rate = (1 << 7); break;
! case 6: rate = (1 << 8); break;
! default: rate = 0;
! }
!
! SetRTOSClockRate(rate);
!
! return SUCCESS;
}
!
! async command void Clock.setInterval(uint8_t value) {
! atomic {
! gmInterval = value;
! }
! return;
}
--- 76,220 ----
implementation
{
! #include "NewTimer.h"
!
! #if USE_NEW_TIMER
! #else
! uint8_t gmScale;
! uint8_t gmInterval;
! uint8_t gmCounter;
! #endif
! uint32_t systemTime;
! bool clk_init=false;
! bool clk_start=false;
!
!
! void RTOSClockInterrupt() __attribute__ ((C, spontaneous)) {
! #if USE_NEW_TIMER
! signal Clock.fire();
! #else
! bool fFireEvent = FALSE;
! atomic{
! gmCounter++;
! systemTime++; //increment system time
! if (gmCounter >= gmInterval) {
! gmCounter =0;
! fFireEvent = TRUE;
! }
! }
! if(fFireEvent) {
! signal Clock.fire();
! }
! #endif
}
!
! command result_t StdControl.init() {
! atomic {
! if(clk_init==false){
! systemTime = 0; //initialize system time to zero
! #if USE_NEW_TIMER
! InitRTOSTimer();
! #else
! gmScale = DEFAULT_SCALE;
! gmInterval = DEFAULT_INTERVAL;
! gmCounter = 0;
! #endif
! clk_init = true;
! }
! }
! return SUCCESS;
}
!
! command result_t StdControl.start() {
! #if USE_NEW_TIMER
! #else
! uint8_t mInt, mScl;
! atomic {
! if(clk_start==false){
! mInt = gmInterval;
! mScl = gmScale;
! gmCounter = 0;
! clk_start=true;
! }
! }
! StartRTOSClock();
!
! call Clock.setRate(mInt,mScl);
! #endif
! return SUCCESS;
}
command result_t StdControl.stop() {
! #if USE_NEW_TIMER
! StopRTOSClock();
! #else
! uint8_t mInt;
!
! atomic mInt = gmInterval;
!
! StopRTOSClock();
!
! call Clock.setRate(mInt,0);
! #endif
! return SUCCESS;
}
! async command result_t Clock.setRate(uint32_t interval, char scale) {
! // roughly translate mica's clock since it sits in the common interface
! // directory. Base on interfaces/Clock.h the following mapping is ~correct.
! // Arm core has a 12M external clock. Need to move Clock.h to platform
! // specific section and use arm's granularities.
! #if USE_NEW_TIMER
! atomic {
! if(clk_init == false){
! systemTime = 0; //initialize system time to zero
! InitRTOSTimer();
! clk_init=true;
! }
! }
! call Clock.setInterval(interval);
! #else
! uint32 rate;
!
! atomic {
! gmScale = scale;
! gmInterval = interval;
! gmCounter = 0;
! if(clk_init == false){
! StartRTOSClock();
! clk_init=true;
! }
! }
! switch (scale) {
! case 0: rate = (0 << 0); break;
! case 1: rate = (1 << 0); break;
! case 2: rate = (1 << 3); break;
! case 3: rate = (1 << 5); break;
! case 4: rate = (1 << 6); break;
! case 5: rate = (1 << 7); break;
! case 6: rate = (1 << 8); break;
! default: rate = 0;
! }
!
! SetRTOSClockRate(rate);
! #endif
! return SUCCESS;
}
!
! async command void Clock.setInterval(uint32_t value) {
! #if USE_NEW_TIMER
! SetRTOSInterval(value<<5);
! atomic{
! systemTime +=value;
! }
! #else
! atomic {
! gmInterval = value;
! }
! #endif
! return;
}
***************
*** 191,203 ****
}
! async command uint8_t Clock.readCounter() {
! uint8_t CntrVal;
! atomic {
! CntrVal = gmCounter;
! }
! return CntrVal;
}
! async command void Clock.setCounter(uint8_t n) {
}
--- 239,256 ----
}
! async command uint32_t Clock.readCounter() {
! #if USE_NEW_TIMER
! //return TM_GetRtosTmrCnter();
! return 0;
! #else
! uint32_t CntrVal;
! atomic {
! CntrVal = gmCounter;
! }
! return CntrVal;
! #endif
}
! async command void Clock.setCounter(uint32_t n) {
}
***************
*** 211,223 ****
}
! default async event result_t Clock.fire() { return SUCCESS; }
! #if 0
command uint32_t SystemTime.getSystemTime(){
! return(systemTime);
}
command void SystemTime.setSystemTime(uint32_t time){
! systemTime = time;
}
#endif
--- 264,283 ----
}
! default async event result_t Clock.fire() {
! return SUCCESS; }
! #if 1
command uint32_t SystemTime.getSystemTime(){
! uint32_t time;
! atomic{
! time = systemTime + TM_GetRtosTmrCnter();;
! }
! return(time);
}
command void SystemTime.setSystemTime(uint32_t time){
! atomic{
! systemTime = time;
! }
}
#endif
Index: HPLDMAUart.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/HPLDMAUart.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** HPLDMAUart.nc 29 Jun 2004 14:56:14 -0000 1.1
--- HPLDMAUart.nc 6 Sep 2005 08:27:58 -0000 1.2
***************
*** 30,34 ****
*/
/*
! * The HPLDMAUART interface is used to transmit and receive multiple bytes
* at once. This is more efficient that HPLUart when transfering larger
* data chunks. Currently, the maximum allowed chunk is 32 bytes.
--- 30,34 ----
*/
/*
! * The FlexUART interface is used to transmit and receive multiple bytes
* at once. This is more efficient that HPLUart when transfering larger
* data chunks. Currently, the maximum allowed chunk is 32 bytes.
Index: HPLDMAUartC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/HPLDMAUartC.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** HPLDMAUartC.nc 29 Jun 2004 14:56:14 -0000 1.1
--- HPLDMAUartC.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 31,40 ****
configuration HPLDMAUartC {
! provides interface HPLDMAUart;
}
implementation
{
! components HPLDMAUartM;
! HPLDMAUart = HPLDMAUartM;
}
--- 31,44 ----
configuration HPLDMAUartC {
! provides interface HPLUART;
! provides interface HPLDMA;
}
implementation
{
! //the point of this component is to create an abstraction between the component providing
! //the dma'able uart and the actual port providing the functionality (in the case of multiple ports)
! components HPLMainUartM;
! HPLUART = HPLMainUartM;
! HPLDMA = HPLMainUartM;
}
Index: HPLDMAUartM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/HPLDMAUartM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** HPLDMAUartM.nc 29 Jun 2004 14:56:14 -0000 1.1
--- HPLDMAUartM.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 64,75 ****
localBaudrate=baudrate;
}
! return (InitializeMainUart(baudrate) ? SUCCESS : FAIL);
}
-
-
async command result_t HPLDMAUart.start(uint8 *newRxBuffer, uint16 newRxSize ) {
uint8 lfault, lbaud;
!
atomic {
lfault = fault;
--- 64,78 ----
localBaudrate=baudrate;
}
! //return (InitializeMainUart(baudrate) ? SUCCESS : FAIL);
! InitializeMainUart(baudrate);
! // TM_MainUartReg->intEnable |= TM_UART_EN_RX_BUF_FULL_INT_MASK;
! TM_MainUartReg->fifoControl=0;
! TM_MainUartReg->fifoControl=0x1 | 0x8 | 0x80;
! return SUCCESS;
}
async command result_t HPLDMAUart.start(uint8 *newRxBuffer, uint16 newRxSize ) {
uint8 lfault, lbaud;
!
atomic {
lfault = fault;
***************
*** 109,117 ****
}
!
!
! void MainUartInterrupt() __attribute__ ((C, spontaneous)) {
! atomic fault=true;
! }
--- 112,148 ----
}
! void MainUartInterrupt(uint16 Id, tIoStatus UartStatus) __attribute__ ((C, spontaneous)) {
! TM_SetPioAsOutput(4);
! TM_SetPioAsOutput(5);
! TM_SetPioAsOutput(6);
! TM_ResetPio(5);
! TM_ResetPio(6);
! TM_ResetPio(4);
! if(Id==TM_UART_RX_LINE_STATUS){
! switch(UartStatus){
! case eTM_OverrunError:
! TM_SetPio(4);
! break;
! case eTM_BreakError:
! TM_SetPio(5);
! break;
! case eTM_FramError:
! TM_SetPio(6);
! break;
! default:
! TM_SetPio(4);
! TM_SetPio(6);
! break;
! }
! while(1); //die here so we can tell...
! fault=true;
! }
! else{
! //TM_SetPio(4);
! //TM_SetPio(5);
! //TM_SetPio(6);
! //TMFlushUartDmaRxBuffer();
! }
! }
***************
*** 122,127 ****
}
-
-
void MainUartReceiveInterrupt(uint8 *pRxBuf, int RxLen) __attribute__ ((C, spontaneous)) {
char *ret;
--- 153,156 ----
***************
*** 129,141 ****
if(!(ret=signal HPLDMAUart.get(pRxBuf, RxLen))){
! atomic RxSize=0;
! }
! atomic {
! RxBuffer = ret;
! lsize = RxSize;
}
! //TMSetupUartDmaRxNextTransc(RxBuffer, RxSize);
! //TM_MainUartChTmroutEnable();
! SetNextReceiveBuffer(ret, lsize);
}
--- 158,175 ----
if(!(ret=signal HPLDMAUart.get(pRxBuf, RxLen))){
!
! atomic {
! RxBuffer = ret;
! RxSize = 0;
! lsize = RxSize;
! }
}
! else{
! atomic {
! RxBuffer = ret;
! lsize = RxSize;
! }
! SetNextReceiveBuffer(ret, lsize);
! }
}
Index: HPLPowerManagementM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/HPLPowerManagementM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** HPLPowerManagementM.nc 29 Jun 2004 14:56:14 -0000 1.1
--- HPLPowerManagementM.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 1,38 ****
! /*
! * Copyright (c) 2004, Intel Corporation
* All rights reserved.
*
! * Redistribution and use in source and binary forms, with or without
! * modification, are permitted provided that the following conditions are met:
! *
! * Redistributions of source code must retain the above copyright notice,
! * this list of conditions and the following disclaimer.
*
! * Redistributions in binary form must reproduce the above copyright notice,
! * this list of conditions and the following disclaimer in the documentation
! * and/or other materials provided with the distribution.
*
! * Neither the name of the Intel Corporation nor the names of its contributors
! * may be used to endorse or promote products derived from this software
! * without specific prior written permission.
*
! * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
! * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
! * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
! * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
! * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
! * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
! * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
! * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! * POSSIBILITY OF SUCH DAMAGE.
*/
module HPLPowerManagementM {
provides {
interface PowerManagement;
- command result_t Enable();
- command result_t Disable();
}
}
--- 1,46 ----
! // $Id$
!
! /* tab:4
! * "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.
! */
!
! /* Author: Robert Szewczyk
*
! * $Id$
! */
!
! /**
! * @author Robert Szewczyk
*/
+
module HPLPowerManagementM {
provides {
interface PowerManagement;
}
}
***************
*** 45,54 ****
}
! command result_t Enable() {
atomic disabled = FALSE;
return SUCCESS;
}
! command result_t Disable() {
atomic disabled = TRUE;
return SUCCESS;
--- 53,62 ----
}
! async command result_t PowerManagement.enable() {
atomic disabled = FALSE;
return SUCCESS;
}
! async command result_t PowerManagement.disable() {
atomic disabled = TRUE;
return SUCCESS;
Index: HPLUARTC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/HPLUARTC.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** HPLUARTC.nc 29 Jun 2004 14:56:14 -0000 1.1
--- HPLUARTC.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 1,32 ****
- /*
- * Copyright (c) 2004, Intel Corporation
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * Neither the name of the Intel Corporation nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
/* tab:4
*
--- 1,2 ----
***************
*** 52,55 ****
--- 22,62 ----
*
*/
+ /* tab:4
+ * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
+ * downloading, copying, installing or using the software you agree to
+ * this license. If you do not agree to this license, do not download,
+ * install, copy or use the software.
+ *
+ * Intel Open Source License
+ *
+ * Copyright (c) 2002 Intel Corporation
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ */
/*
*
***************
*** 66,76 ****
// create a separate component
configuration HPLUARTC {
! provides interface HPLUART as UART;
}
implementation
{
! components HPLUARTM, HPLDMAUartC;
! UART = HPLUARTM;
! HPLUARTM.HPLDMAUart -> HPLDMAUartC;
}
--- 73,85 ----
// create a separate component
configuration HPLUARTC {
! provides interface HPLUART;
}
implementation
{
! components HPLByteDMAM, HPLMainUartM, TimerC;
! HPLUART = HPLByteDMAM;
! HPLByteDMAM.UART -> HPLMainUartM.UART;
! HPLByteDMAM.DMA -> HPLMainUartM.DMA;
! HPLByteDMAM.Timer -> TimerC.Timer[unique("Timer")];
}
Index: LowPowerM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/LowPowerM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** LowPowerM.nc 29 Jun 2004 14:56:14 -0000 1.1
--- LowPowerM.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 29,32 ****
--- 29,33 ----
* POSSIBILITY OF SUCH DAMAGE.
*/
+
#define ACTIVE_MODE 0
#define HOLD_MODE 1
***************
*** 50,59 ****
}
implementation {
!
! #ifdef LP_DEBUG
! void DisplayStr(char *str) __attribute__ ((C, spontaneous));
! #else
! #define DisplayStr(str)
! #endif
uint16 min_sleep, max_sleep;
--- 51,55 ----
}
implementation {
! #define TRACE_DEBUG_LEVEL 0ULL
uint16 min_sleep, max_sleep;
***************
*** 80,97 ****
call NetworkTopology.GetNextConnection (nodeID[i], NULL, &handle[i]);
call HCILinkPolicy.Hold_Mode (handle[i], min_sleep, max_sleep);
! {
! char str[80];
! sprintf(str, "Entering low power for node %05X, handle %d\r\n", nodeID[i], handle[i]);
! DisplayStr(str);
! }
handle_flag[i] = 0;
}
handle_completed = 0;
signal LowPower.PowerModeChange(true);
! {
! char str[80];
! sprintf(str, "PowerModeChange signaled, true\r\n");
! DisplayStr(str);
! }
return SUCCESS;
}
--- 76,85 ----
call NetworkTopology.GetNextConnection (nodeID[i], NULL, &handle[i]);
call HCILinkPolicy.Hold_Mode (handle[i], min_sleep, max_sleep);
! trace(TRACE_DEBUG_LEVEL,"Entering low power for node %05X, handle %d\r\n", nodeID[i], handle[i]);
handle_flag[i] = 0;
}
handle_completed = 0;
signal LowPower.PowerModeChange(true);
! trace(TRACE_DEBUG_LEVEL,"PowerModeChange signaled, true\r\n");
return SUCCESS;
}
***************
*** 100,109 ****
uint8 Current_Mode, uint16 Interval) {
uint8 i, handle_exist;
!
! {
! char str[80];
! sprintf(str, "Mode change status %d, handle %d, mode %d\r\n", Status, Connection_Handle, Current_Mode);
! DisplayStr(str);
! }
// check to see if all links have entered hold
if (low_power_enabled && (Current_Mode==HOLD_MODE)) {
--- 88,93 ----
uint8 Current_Mode, uint16 Interval) {
uint8 i, handle_exist;
! trace(TRACE_DEBUG_LEVEL,"Mode change status %d, handle %d, mode %d\r\n", Status, Connection_Handle, Current_Mode);
!
// check to see if all links have entered hold
if (low_power_enabled && (Current_Mode==HOLD_MODE)) {
***************
*** 142,150 ****
low_power_enabled = 0;
signal LowPower.PowerModeChange(false);
! {
! char str[80];
! sprintf(str, "PowerModeChange signaled, false\r\n");
! DisplayStr(str);
! }
return SUCCESS;
}
--- 126,130 ----
low_power_enabled = 0;
signal LowPower.PowerModeChange(false);
! trace(TRACE_DEBUG_LEVEL,"PowerModeChange signaled, false\r\n");
return SUCCESS;
}
Index: NetworkC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/NetworkC.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NetworkC.nc 29 Jun 2004 14:56:14 -0000 1.1
--- NetworkC.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 1,34 ****
! /*
! * Copyright (c) 2004, Intel Corporation
! * All rights reserved.
*
! * Redistribution and use in source and binary forms, with or without
! * modification, are permitted provided that the following conditions are met:
*
! * Redistributions of source code must retain the above copyright notice,
! * this list of conditions and the following disclaimer.
*
! * Redistributions in binary form must reproduce the above copyright notice,
! * this list of conditions and the following disclaimer in the documentation
! * and/or other materials provided with the distribution.
*
- * Neither the name of the Intel Corporation nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
*/
#define DEBUG_LED 1
configuration NetworkC
--- 1,42 ----
! /* tab:4
! * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
! * downloading, copying, installing or using the software you agree to
! * this license. If you do not agree to this license, do not download,
! * install, copy or use the software.
*
! * Intel Open Source License
*
! * Copyright (c) 2002 Intel Corporation
! * All rights reserved.
! * Redistribution and use in source and binary forms, with or without
! * modification, are permitted provided that the following conditions are
! * met:
*
! * Redistributions of source code must retain the above copyright
! * notice, this list of conditions and the following disclaimer.
! * Redistributions in binary form must reproduce the above copyright
! * notice, this list of conditions and the following disclaimer in the
! * documentation and/or other materials provided with the distribution.
! * Neither the name of the Intel Corporation nor the names of its
! * contributors may be used to endorse or promote products derived from
! * this software without specific prior written permission.
! *
! * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
! * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
! * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
! * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
! * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
! * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
! * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
! * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
! * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
! * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
! * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
#define DEBUG_LED 1
+ includes StatsTypes;
configuration NetworkC
***************
*** 40,43 ****
--- 48,52 ----
interface NetworkLowPower;
command result_t SendTraceRoute();
+ command result_t NetworkResetNodes(uint32 ResetDelayMS);
}
}
***************
*** 59,62 ****
--- 68,72 ----
WDTControlM,
LowPowerC,
+ StatsLoggerM,
#if DEBUG_LED
DebugLedM,
***************
*** 70,73 ****
--- 80,84 ----
NetworkLowPower = NetworkMonitorC;
SendTraceRoute = NetworkMonitorC;
+ NetworkResetNodes = NetworkMonitorC.NetworkResetNodes;
NetworkCommandM.BTLowerLayersControl -> BTLowerLayersM;
***************
*** 85,89 ****
// remove after debug
! FindRootScatternetFormationC.Display -> NetworkMonitorC;
FindRootScatternetFormationC.SuspendDataTraffic -> NetworkLinkQueuesM;
--- 96,100 ----
// remove after debug
! // FindRootScatternetFormationC.Display -> NetworkMonitorC;
FindRootScatternetFormationC.SuspendDataTraffic -> NetworkLinkQueuesM;
***************
*** 96,99 ****
--- 107,111 ----
NetworkPropertiesM.NetworkTopology -> NetworkTopologyM.NetworkTopology;
NetworkPropertiesM.NetworkPacket -> NetworkLinkQueuesM.NetworkPacket[4];
+ NetworkPropertiesM.StatsLogger -> StatsLoggerM;
NetworkRelayM.NetworkPacket -> NetworkLinkQueuesM.RelayPacket;
***************
*** 111,114 ****
--- 123,129 ----
NetworkLinkQueuesM.InvalidDest -> TreeRoutingM;
+ NetworkLinkQueuesM.StatsLogger -> StatsLoggerM;
+ NetworkLinkQueuesM.Memory -> MemoryM;
+
BTBufferM.Memory -> MemoryM;
***************
*** 122,125 ****
--- 137,143 ----
TreeRoutingM.WDTControl -> WDTControlM;
WDTControlM.Timer -> TimerC.Timer[unique("Timer")];
+ TreeRoutingM.StatsLogger -> StatsLoggerM;
+ StatsLoggerM.Timer -> TimerC.Timer[unique("Timer")];
+ StatsLoggerM.Memory -> MemoryM;
#if DEBUG_LED
***************
*** 130,133 ****
--- 148,152 ----
DebugLedM.GetRootNodeID -> FindRootScatternetFormationC;
DebugLedM.LowPower -> LowPowerC;
+ DebugLedM.StatsLogger -> StatsLoggerM;
#endif
}
Index: NetworkCommand.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/NetworkCommand.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NetworkCommand.h 29 Jun 2004 14:56:14 -0000 1.1
--- NetworkCommand.h 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 1,32 ****
- /*
- * Copyright (c) 2004, Intel Corporation
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * Neither the name of the Intel Corporation nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
#define SCATTERNET_FORMATION_COMMAND 0x40
#define ROUTE_DISCOVERY_COMMAND 0x80
--- 1,2 ----
***************
*** 55,59 ****
NETWORK_PROPERTY_APP_SENSIRION,
NETWORK_PROPERTY_APP_ACCELEROMETER,
! NETWORK_PROPERTY_APP_STREAMING_ACCEL
} NetworkProperty;
--- 25,31 ----
NETWORK_PROPERTY_APP_SENSIRION,
NETWORK_PROPERTY_APP_ACCELEROMETER,
! NETWORK_PROPERTY_APP_STREAMING_ACCEL,
! NETWORK_PROPERTY_APP_CAMERA,
! NETWORK_PROPERTY_APP_BOSTON_WATER,
} NetworkProperty;
Index: NetworkDataM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/NetworkDataM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NetworkDataM.nc 29 Jun 2004 14:56:14 -0000 1.1
--- NetworkDataM.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 63,73 ****
implementation
{
! //#define NETWORK_DATA_DEBUG
!
! #ifdef NETWORK_DATA_DEBUG
! void DisplayStr(char *str) __attribute__ ((C, spontaneous));
! #else
! #define DisplayStr(str)
! #endif
// The PacketList contains the list of destinations and packet pointers
--- 63,67 ----
implementation
{
! #define TRACE_DEBUG_LEVEL DBG_PACKET
// The PacketList contains the list of destinations and packet pointers
***************
*** 165,169 ****
data = (char *) ((uint32) RetryList[i].Packet + sizeof(tiMoteHeader));
if (call BTBuffer.IsAllocated(data) != SUCCESS) {
! DisplayStr("Unallocated packet in the retry queue\n");
return;
}
--- 159,163 ----
data = (char *) ((uint32) RetryList[i].Packet + sizeof(tiMoteHeader));
if (call BTBuffer.IsAllocated(data) != SUCCESS) {
! trace(TRACE_DEBUG_LEVEL,"Unallocated packet in the retry queue\n");
return;
}
***************
*** 176,194 ****
void AdvanceRetryHead() {
! while ((RetryHead != RetryTail) &&
! // this shouldn't be necessary. How is NextRetry.Ack true or
! // NextRetry.Valid false? (RetryHead != NextRetry) &&
! ((RetryList[RetryHead].Ack == TRUE) ||
! (RetryList[RetryHead].Valid == FALSE))) {
!
! if (RetryHead == NextRetry) {
! DisplayStr("RetryHead passing NextRetry\n");
! }
! RetryHead = (RetryHead == (MAX_RETRY_PACKETS - 1)) ? 0 : RetryHead + 1;
!
! }
TestQueueValidity();
}
!
--- 170,188 ----
void AdvanceRetryHead() {
! while ((RetryHead != RetryTail) &&
! // this shouldn't be necessary. How is NextRetry.Ack true or
! // NextRetry.Valid false? (RetryHead != NextRetry) &&
! ((RetryList[RetryHead].Ack == TRUE) ||
! (RetryList[RetryHead].Valid == FALSE))) {
!
! if (RetryHead == NextRetry) {
! trace(TRACE_DEBUG_LEVEL,"RetryHead passing NextRetry\n");
! }
! RetryHead = (RetryHead == (MAX_RETRY_PACKETS - 1)) ? 0 : RetryHead + 1;
!
! }
TestQueueValidity();
}
!
***************
*** 200,204 ****
ind = GetRetryIndex(dataPtr);
if (ind == -1) {
! DisplayStr("Could not find bufferd packet\n");
return; // entry is not in the queue;
}
--- 194,198 ----
ind = GetRetryIndex(dataPtr);
if (ind == -1) {
! trace(TRACE_DEBUG_LEVEL,"Could not find bufferd packet\n");
return; // entry is not in the queue;
}
***************
*** 238,244 ****
signal NetworkPacket.SendDone[headerPtr->channel](dataPtr);
}
! DisplayStr("Send Queue Full - dropping oldest entry\n");
#endif
! DisplayStr("Send Queue Full\n");
return FAIL;
} /* else */
--- 232,238 ----
signal NetworkPacket.SendDone[headerPtr->channel](dataPtr);
}
! trace(TRACE_DEBUG_LEVEL,"Send Queue Full - dropping oldest entry\n");
#endif
! trace(TRACE_DEBUG_LEVEL,"Send Queue Full\n");
return FAIL;
} /* else */
***************
*** 272,276 ****
if (ind == RetryTail) {
! DisplayStr("Cannot find message to re-queue\n");
return FAIL;
}
--- 266,270 ----
if (ind == RetryTail) {
! trace(TRACE_DEBUG_LEVEL,"Cannot find message to re-queue\n");
return FAIL;
}
***************
*** 294,298 ****
return SUCCESS;
} else {
! DisplayStr("Retry queue full\n");
return FAIL;
}
--- 288,292 ----
return SUCCESS;
} else {
! trace(TRACE_DEBUG_LEVEL,"Retry queue full\n");
return FAIL;
}
***************
*** 320,328 ****
NextRetry = (NextRetry == (MAX_RETRY_PACKETS - 1)) ? 0 : NextRetry + 1;
AdvanceRetryHead();
! {
! char str[80];
! sprintf(str, "Invalid Dest %05X\n", packet->DestID);
! DisplayStr(str);
! }
#if 0 // remove for hard-wired
--- 314,319 ----
NextRetry = (NextRetry == (MAX_RETRY_PACKETS - 1)) ? 0 : NextRetry + 1;
AdvanceRetryHead();
!
! trace(TRACE_DEBUG_LEVEL,"Invalid Dest %05X\n", packet->DestID);
#if 0 // remove for hard-wired
***************
*** 440,444 ****
if ((ind != -1) && (RetryList[ind].Valid == TRUE) &&
(RetryList[ind].Ack == FALSE)) {
! DisplayStr("Releasing a valid buffer in the retry queue\n");
RetryList[ind].Valid = FALSE;
AdvanceRetryHead();
--- 431,435 ----
if ((ind != -1) && (RetryList[ind].Valid == TRUE) &&
(RetryList[ind].Ack == FALSE)) {
! trace(TRACE_DEBUG_LEVEL,"Releasing a valid buffer in the retry queue\n");
RetryList[ind].Valid = FALSE;
AdvanceRetryHead();
***************
*** 448,452 ****
return SUCCESS;
} else {
! DisplayStr("Releasing unallocated buffer\n");
return FAIL;
}
--- 439,443 ----
return SUCCESS;
} else {
! trace(TRACE_DEBUG_LEVEL,"Releasing unallocated buffer\n");
return FAIL;
}
***************
*** 534,538 ****
if (call NetworkTopology.NextHandle2NodeID(Connection_Handle,
&NextNodeID) == FAIL) {
! DisplayStr("Invalid Receive packet\n");
} else {
// add an entry with a very large hop count
--- 525,529 ----
if (call NetworkTopology.NextHandle2NodeID(Connection_Handle,
&NextNodeID) == FAIL) {
! trace(TRACE_DEBUG_LEVEL,"Invalid Receive packet\n");
} else {
// add an entry with a very large hop count
Index: NetworkHardwiredC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/NetworkHardwiredC.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NetworkHardwiredC.nc 29 Jun 2004 14:56:14 -0000 1.1
--- NetworkHardwiredC.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 1,33 ****
! /*
! * Copyright (c) 2004, Intel Corporation
! * All rights reserved.
*
! * Redistribution and use in source and binary forms, with or without
! * modification, are permitted provided that the following conditions are met:
*
! * Redistributions of source code must retain the above copyright notice,
! * this list of conditions and the following disclaimer.
*
! * Redistributions in binary form must reproduce the above copyright notice,
! * this list of conditions and the following disclaimer in the documentation
! * and/or other materials provided with the distribution.
*
- * Neither the name of the Intel Corporation nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
*/
configuration NetworkHardwiredC
{
--- 1,41 ----
! /* tab:4
! * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
! * downloading, copying, installing or using the software you agree to
! * this license. If you do not agree to this license, do not download,
! * install, copy or use the software.
*
! * Intel Open Source License
*
! * Copyright (c) 2002 Intel Corporation
! * All rights reserved.
! * Redistribution and use in source and binary forms, with or without
! * modification, are permitted provided that the following conditions are
! * met:
*
! * Redistributions of source code must retain the above copyright
! * notice, this list of conditions and the following disclaimer.
! * Redistributions in binary form must reproduce the above copyright
! * notice, this list of conditions and the following disclaimer in the
! * documentation and/or other materials provided with the distribution.
! * Neither the name of the Intel Corporation nor the names of its
! * contributors may be used to endorse or promote products derived from
! * this software without specific prior written permission.
! *
! * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
! * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
! * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
! * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
! * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
! * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
! * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
! * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
! * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
! * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
! * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
+ includes StatsTypes;
configuration NetworkHardwiredC
{
***************
*** 52,55 ****
--- 60,64 ----
NetworkMonitorC,
SignalStrengthC,
+ StatsLoggerM,
BTBufferM,
MemoryM,
***************
*** 92,98 ****
--- 101,110 ----
TreeRoutingM.NetworkDiscoveryActive -> ScatternetHardwiredM;
TreeRoutingM.LowPower -> LowPowerC;
+ TreeRoutingM.StatsLogger -> StatsLoggerM;
NetworkPropertiesM.NetworkTopology -> NetworkTopologyM.NetworkTopology;
NetworkPropertiesM.NetworkPacket -> NetworkLinkQueuesM.NetworkPacket[4];
+ NetworkPropertiesM.StatsLogger -> StatsLoggerM;
+
NetworkRelayM.NetworkPacket -> NetworkLinkQueuesM.RelayPacket;
***************
*** 102,107 ****
--- 114,121 ----
NetworkLinkQueuesM.Timer -> TimerC.Timer[unique("Timer")];
NetworkLinkQueuesM.NetworkTopology -> NetworkTopologyM;
+ NetworkLinkQueuesM.StatsLogger -> StatsLoggerM;
NetworkLinkQueuesM.InvalidDest -> TreeRoutingM;
+ NetworkLinkQueuesM.Memory -> MemoryM;
BTBufferM.Memory -> MemoryM;
***************
*** 117,119 ****
--- 131,137 ----
WDTControlM.Timer -> TimerC.Timer[unique("Timer")];
+ StatsLoggerM.Timer -> TimerC.Timer[unique("Timer")];
+ StatsLoggerM.Memory -> MemoryM;
+
+
}
Index: NetworkLinkQueuesM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/NetworkLinkQueuesM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** NetworkLinkQueuesM.nc 4 Apr 2005 17:39:36 -0000 1.2
--- NetworkLinkQueuesM.nc 6 Sep 2005 08:27:59 -0000 1.3
***************
*** 48,51 ****
--- 48,52 ----
+ includes StatsTypes;
module NetworkLinkQueuesM
{
***************
*** 63,66 ****
--- 64,69 ----
interface HCILinkControl;
event result_t InvalidDest(uint32 Dest);
+ interface StatsLogger;
+ interface Memory;
}
}
***************
*** 72,81 ****
#define NEXT_BUFFER(ent, max) (((ent) >= ((max) - 1)) ? 0 : ((ent) + 1))
! //#define DEBUG_LINK_QUEUE
! #ifdef DEBUG_LINK_QUEUE
! void DisplayStr(char *str) __attribute__ ((C, spontaneous));
! #else
! #define DisplayStr(str)
! #endif // DEBUG_LINK_QUEUE
#define INVALID_HANDLE 0xFFFF
--- 75,80 ----
#define NEXT_BUFFER(ent, max) (((ent) >= ((max) - 1)) ? 0 : ((ent) + 1))
! #define TRACE_DEBUG_LEVEL 0ULL
! //#define TRACE_DEBUG_LEVEL DBG_USR1
#define INVALID_HANDLE 0xFFFF
***************
*** 94,99 ****
--- 93,104 ----
#define MAX_RETRY_PACKETS 40 // arbitrary
+ #define MIN_RETRY_PACKETS 2
+ #if 0 // Switch to BRAM
tRetryPacket RetryList[MAX_RETRY_PACKETS];
+ #else
+ tRetryPacket *RetryList;
+ #endif
+ uint8 MaxRetryPackets;
uint8 NumRetryEntries; // Number of outstanding packets
uint8 NextFreeEntry; // Candidate for the next retry list to use
***************
*** 130,133 ****
--- 135,139 ----
bool TimerRunning;
bool WaitToSend; // Whether it is OK to send a packet
+ uint8 OutstandingPackets; // Num packets in lower layer
***************
*** 173,186 ****
uint8 i, retval;
! for (i = 0; i < MAX_RETRY_PACKETS; i++) {
if (RetryList[NextFreeEntry].Valid == FALSE) {
retval = NextFreeEntry;
! NextFreeEntry = NEXT_BUFFER(NextFreeEntry, MAX_RETRY_PACKETS);
return retval;
}
! NextFreeEntry = NEXT_BUFFER(NextFreeEntry, MAX_RETRY_PACKETS);
}
! return MAX_RETRY_PACKETS;
}
--- 179,192 ----
uint8 i, retval;
! for (i = 0; i < MaxRetryPackets; i++) {
if (RetryList[NextFreeEntry].Valid == FALSE) {
retval = NextFreeEntry;
! NextFreeEntry = NEXT_BUFFER(NextFreeEntry, MaxRetryPackets);
return retval;
}
! NextFreeEntry = NEXT_BUFFER(NextFreeEntry, MaxRetryPackets);
}
! return MaxRetryPackets;
}
***************
*** 243,258 ****
if ((queue = GetLinkQueue(DestID)) == NULL) {
! { char str[80];
! sprintf(str, "Failed packet to dest %05X\r\n", DestID);
! DisplayStr(str);
! }
! return FAIL;
}
! if ((ind = GetFreeRetryListIndex()) == MAX_RETRY_PACKETS) {
! { char str[80];
! sprintf(str, "Retry Queue full\r\n");
! DisplayStr(str);
! }
return FAIL;
}
--- 249,258 ----
if ((queue = GetLinkQueue(DestID)) == NULL) {
! trace(TRACE_DEBUG_LEVEL,"Failed packet to dest %05X\r\n", DestID);
! return FAIL;
}
! if ((ind = GetFreeRetryListIndex()) == MaxRetryPackets) {
! trace(TRACE_DEBUG_LEVEL,"Retry Queue full\r\n");
return FAIL;
}
***************
*** 270,281 ****
packet->Queued = FALSE;
packet->RetryAttempt = 0;
! {
! char str[80];
! int size;
! size = queue->Head - queue->Tail;
! size = (queue->Head < queue->Tail) ? size + MAX_PACKET_PER_LINK : size;
! sprintf(str, "Message %d for %05X channel %d id %d\n", size, DestID, ((tiMoteHeader *)Data)->channel, *((uint32 *)((uint32) Data + sizeof(tiMoteHeader))));
! DisplayStr(str);
! }
if (WaitToSend == TRUE) return SUCCESS;
--- 270,279 ----
packet->Queued = FALSE;
packet->RetryAttempt = 0;
! {
! int size;
! size = queue->Head - queue->Tail;
! size = (queue->Head < queue->Tail) ? size + MAX_PACKET_PER_LINK : size;
! trace(TRACE_DEBUG_LEVEL,"Message %d for %05X channel %d id %d\n", size, DestID, ((tiMoteHeader *)Data)->channel, *((uint32 *)((uint32) Data + sizeof(tiMoteHeader))));
! }
if (WaitToSend == TRUE) return SUCCESS;
***************
*** 286,289 ****
--- 284,293 ----
== SUCCESS)){
packet->Queued = TRUE;
+ call StatsLogger.BumpCounter(NUM_TOTAL_SEND, 1);
+ if (OutstandingPackets == 0) {
+ // assume Tx is On for sake of logging
+ call StatsLogger.StartTimer(MSEC_MOTE_TX);
+ }
+ OutstandingPackets++;
} else {
StartTimer();
***************
*** 337,340 ****
--- 341,350 ----
LastQueuedLink = NEXT_BUFFER(LastQueuedLink, NumLinks);
packet->Queued = TRUE;
+ call StatsLogger.BumpCounter(NUM_TOTAL_SEND, 1);
+ if (OutstandingPackets == 0) {
+ // assume Tx is On for sake of logging
+ call StatsLogger.StartTimer(MSEC_MOTE_TX);
+ }
+ OutstandingPackets++;
return SUCCESS;
} else {
***************
*** 371,376 ****
}
}
! sprintf(str, "%s \n", str);
! DisplayStr(str);
}
--- 381,385 ----
}
}
! trace(TRACE_DEBUG_LEVEL,"%s \n", str);
}
***************
*** 405,412 ****
} else {
! DisplayStr("Error - Trying to free a resend queue OOO\n");
}
}
! DisplayStr("Error - Could not find message to de-queue\n");
}
--- 414,421 ----
} else {
! trace(TRACE_DEBUG_LEVEL,"Error - Trying to free a resend queue OOO\n");
}
}
! trace(TRACE_DEBUG_LEVEL,"Error - Could not find message to de-queue\n");
}
***************
*** 420,423 ****
--- 429,449 ----
call BTBuffer.Initialize();
+ // LN : Allocate space for queues from BRAM, running out of IRAM
+ RetryList = (tRetryPacket *) call Memory.alloc(MAX_RETRY_PACKETS * sizeof(tRetryPacket));
+ MaxRetryPackets = MAX_RETRY_PACKETS;
+ if (RetryList == NULL) {
+ TM_SetPio(4);
+ TM_SetPio(5);
+ TM_SetPio(6);
+
+ // Try minimal amount
+ RetryList = (tRetryPacket *) call Memory.alloc(MIN_RETRY_PACKETS * sizeof(tRetryPacket));
+ MaxRetryPackets = MIN_RETRY_PACKETS;
+ if (RetryList == NULL) {
+ // Wait, can't do anything anyway
+ while(1);
+ }
+ }
+
NumRetryEntries = 0;
NumLinks = 0;
***************
*** 425,428 ****
--- 451,455 ----
LastQueuedLink = 0;
PacketCount = 0;
+ OutstandingPackets = 0;
TimerRunning = FALSE;
***************
*** 585,588 ****
--- 612,621 ----
dataPtr = (char *) ((uint32) headerPtr + sizeof(tiMoteHeader));
+ OutstandingPackets--;
+ if (OutstandingPackets == 0) {
+ // Done sending packets, stop TxOn timer
+ call StatsLogger.StopTimerUpdateCounter(MSEC_MOTE_TX);
+ }
+
if (Acknowledge == SUCCESS) {
***************
*** 592,605 ****
}
- {
- char str[80];
- sprintf(str, "Send fail dest = %05X\n", headerPtr->dest);
- DisplayStr(str);
- }
// otherwise requeue message and clear out invalid entries from retry queue
if ((queue = GetHandleQueue(Connection_Handle)) == NULL) {
! DisplayStr("Error - Can't find link queue for handle in SendDone\n");
return FAIL;
}
--- 625,635 ----
}
+
+ trace(TRACE_DEBUG_LEVEL,"Send fail dest = %05X\n", headerPtr->dest);
// otherwise requeue message and clear out invalid entries from retry queue
if ((queue = GetHandleQueue(Connection_Handle)) == NULL) {
! trace(TRACE_DEBUG_LEVEL,"Error - Can't find link queue for handle in SendDone\n");
return FAIL;
}
***************
*** 608,612 ****
if ((uint32) packet->Data != TransactionID) {
! DisplayStr("Error - Wrong data packet returned to SendDone\n");
ReleaseQueueEntry(queue);
SignalSendDone(headerPtr, dataPtr);
--- 638,642 ----
if ((uint32) packet->Data != TransactionID) {
! trace(TRACE_DEBUG_LEVEL,"Error - Wrong data packet returned to SendDone\n");
ReleaseQueueEntry(queue);
SignalSendDone(headerPtr, dataPtr);
***************
*** 648,651 ****
--- 678,683 ----
uint32 Source;
+ call StatsLogger.BumpCounter(NUM_TOTAL_RECV, 1);
+
headerPtr = (tiMoteHeader *) Data;
***************
*** 657,666 ****
Source = headerPtr->source;
if ((Source > 0x90000) || ((Source < 0x85000) && (Source > 256))) {
! {
! char str[80];
! sprintf(str, "Dropping packet with bad source %0X\r\n", Source);
! DisplayStr(str);
! }
! return SUCCESS;
}
--- 689,694 ----
Source = headerPtr->source;
if ((Source > 0x90000) || ((Source < 0x85000) && (Source > 256))) {
! trace(TRACE_DEBUG_LEVEL,"Dropping packet with bad source %0X\r\n", Source);
! return SUCCESS;
}
***************
*** 669,678 ****
*/
if (headerPtr->channel > 255) { // arbitrary boundary
! {
! char str[80];
! sprintf(str, "Dropping packet with bad channel %d\r\n", headerPtr->channel);
! DisplayStr(str);
! }
! return SUCCESS;
}
--- 697,702 ----
*/
if (headerPtr->channel > 255) { // arbitrary boundary
! trace(TRACE_DEBUG_LEVEL,"Dropping packet with bad channel %d\r\n", headerPtr->channel);
! return SUCCESS;
}
***************
*** 686,690 ****
if (call NetworkTopology.NextHandle2NodeID(Connection_Handle,
&NextNodeID) == FAIL) {
! DisplayStr("Invalid Receive packet\n");
} else {
// add an entry with a very large hop count
--- 710,714 ----
if (call NetworkTopology.NextHandle2NodeID(Connection_Handle,
&NextNodeID) == FAIL) {
! trace(TRACE_DEBUG_LEVEL,"Invalid Receive packet\n");
} else {
// add an entry with a very large hop count
Index: NetworkManagerM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/NetworkManagerM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NetworkManagerM.nc 29 Jun 2004 14:56:14 -0000 1.1
--- NetworkManagerM.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 43,46 ****
--- 43,47 ----
command result_t DisplayMessage(char *str);
command result_t NetworkWriteScanEnable(uint32 state);
+ command result_t NetworkResetNodes(uint32 ResetDelayMS);
}
***************
*** 55,60 ****
interface LowPower;
! // interface Timer;
interface HCIBaseband;
}
}
--- 56,63 ----
interface LowPower;
! interface Timer;
interface HCIBaseband;
+ interface StatsLogger;
+ interface WDTControl;
}
}
***************
*** 62,72 ****
implementation {
! //#define NM_DEBUG
!
! #ifdef NM_DEBUG
! void DisplayStr(char *str) __attribute__ ((C, spontaneous));
! #else
! #define DisplayStr(str)
! #endif
// Network management messages
--- 65,69 ----
implementation {
! #define TRACE_DEBUG_LEVEL 0ULL
// Network management messages
***************
*** 80,84 ****
NM_EXIT_LOW_POWER,
NM_EXIT_LOW_POWER_DONE,
! NM_WRITE_SCAN_ENABLE
};
--- 77,82 ----
NM_EXIT_LOW_POWER,
NM_EXIT_LOW_POWER_DONE,
! NM_WRITE_SCAN_ENABLE,
! NM_NETWORK_RESET_NODES
};
***************
*** 88,91 ****
--- 86,90 ----
uint32 LowPowerSleepTime;
uint32 ScanState; // current state of the write scan enable
+ uint32 ResetDelay;
***************
*** 103,107 ****
char DisplayString[80];
!
void PassDownDisplayMessage() {
uint32 *t;
--- 102,106 ----
char DisplayString[80];
!
void PassDownDisplayMessage() {
uint32 *t;
***************
*** 151,155 ****
}
} else { // this is the root node
! signal DisplayMessageDone();
}
--- 150,154 ----
}
} else { // this is the root node
! // signal DisplayMessageDone();
}
***************
*** 163,167 ****
if (NumChildren == 0) { // this is a leaf node
! DisplayStr(DisplayString);
post SendDisplayMessageDone();
} else {
--- 162,166 ----
if (NumChildren == 0) { // this is a leaf node
! trace(TRACE_DEBUG_LEVEL,"%s",DisplayString);
post SendDisplayMessageDone();
} else {
***************
*** 184,188 ****
if (NumChildren == 0) {
! DisplayStr(DisplayString);
post SendDisplayMessageDone();
}
--- 183,187 ----
if (NumChildren == 0) {
! trace(TRACE_DEBUG_LEVEL,"%s",DisplayString);
post SendDisplayMessageDone();
}
***************
*** 244,247 ****
--- 243,282 ----
}
+ void PassDownNetworkResetNodes() {
+ uint32 *t;
+ char *buffer;
+ int i;
+
+ for (i = 0; i < NumChildren; i++) {
+ // Need to add retry on failure
+ if ((buffer = call NetworkPacket.AllocateBuffer(8)) == NULL) return;
+ t = (uint32 *) buffer;
+ t[0] = NM_NETWORK_RESET_NODES;
+ t[1] = ResetDelay;
+
+ if (call NetworkPacket.Send(ChildList[i], buffer, 8) == FAIL) {
+ call NetworkPacket.ReleaseBuffer(buffer);
+ // need to add retry on failure
+ }
+ }
+ }
+
+ task void DoNetworkResetNodes() {
+
+ call NetworkTopology.GetChildren(&NumChildren, &(ChildList[0]));
+
+ if (NumChildren != 0) { // have children
+ PassDownNetworkResetNodes();
+ }
+ call Timer.stop(); // just in case
+ call Timer.start(TIMER_ONE_SHOT, ResetDelay);
+ }
+
+ command result_t NetworkResetNodes(uint32 ResetDelayMS) {
+ ResetDelay = ResetDelayMS;
+ post DoNetworkResetNodes();
+ return SUCCESS;
+ }
+
/*
* End of Disable scan routines
***************
*** 321,329 ****
// manager
post SendInitLowPowerDone();
! {
! char str[80];
! sprintf(str, "Initializing Low Power min = %d, max = %d\r\n", min, max);
! DisplayStr(str);
! }
call LowPower.init(min, max);
} else {
--- 356,361 ----
// manager
post SendInitLowPowerDone();
!
! trace(TRACE_DEBUG_LEVEL,"Initializing Low Power min = %d, max = %d\r\n", min, max);
call LowPower.init(min, max);
} else {
***************
*** 346,356 ****
if (NumChildren == 0) {
! post SendInitLowPowerDone();
! {
! char str[80];
! sprintf(str, "Initializing Low Power min = %d, max = %d\r\n", min, max);
! DisplayStr(str);
! }
! call LowPower.init(min, max);
}
}
--- 378,384 ----
if (NumChildren == 0) {
! post SendInitLowPowerDone();
! trace(TRACE_DEBUG_LEVEL,"Initializing Low Power min = %d, max = %d\r\n", min, max);
! call LowPower.init(min, max);
}
}
***************
*** 429,433 ****
// manager
post SendEnterLowPowerDone();
! DisplayStr("Entering Low Power\r\n");
call LowPower.EnterLowPower(NULL, 0);
if (LowPowerSleepTime != 0) {
--- 457,461 ----
// manager
post SendEnterLowPowerDone();
! trace(TRACE_DEBUG_LEVEL,"Entering Low Power\r\n");
call LowPower.EnterLowPower(NULL, 0);
if (LowPowerSleepTime != 0) {
***************
*** 444,448 ****
uint8 tmp;
! DisplayStr("Child done with Entering Low Power\r\n");
i = 0;
while (i < NumChildren) {
--- 472,476 ----
uint8 tmp;
! trace(TRACE_DEBUG_LEVEL,"Child done with Entering Low Power\r\n");
i = 0;
while (i < NumChildren) {
***************
*** 456,460 ****
if (NumChildren == 0) {
post SendEnterLowPowerDone();
! DisplayStr("Entering Low Power\r\n");
call NetworkTopology.GetChildren(&NumChildren, &(ChildList[0]));
tmp = NumChildren;
--- 484,488 ----
if (NumChildren == 0) {
post SendEnterLowPowerDone();
! trace(TRACE_DEBUG_LEVEL,"Entering Low Power\r\n");
call NetworkTopology.GetChildren(&NumChildren, &(ChildList[0]));
tmp = NumChildren;
***************
*** 509,517 ****
if (call NetworkPacket.Send(ChildList[i], buffer, 4) == FAIL) {
! DisplayStr("Manager - pass down send fails\r\n");
call NetworkPacket.ReleaseBuffer(buffer);
// need to add retry on failure
} else {
! DisplayStr("Exit Low Power packet sent\r\n");
}
}
--- 537,545 ----
if (call NetworkPacket.Send(ChildList[i], buffer, 4) == FAIL) {
! trace(TRACE_DEBUG_LEVEL,"Manager - pass down send fails\r\n");
call NetworkPacket.ReleaseBuffer(buffer);
// need to add retry on failure
} else {
! trace(TRACE_DEBUG_LEVEL,"Exit Low Power packet sent\r\n");
}
}
***************
*** 563,567 ****
// manager
post SendExitLowPowerDone();
! DisplayStr("Exiting Low Power\r\n");
} else {
PassDownExitLowPower();
--- 591,595 ----
// manager
post SendExitLowPowerDone();
! trace(TRACE_DEBUG_LEVEL,"Exiting Low Power\r\n");
} else {
PassDownExitLowPower();
***************
*** 589,593 ****
command result_t NetworkLowPower.NetworkExitLowPower() {
! DisplayStr("Manager - exit low power\r\n");
post DoExitLowPower();
--- 617,621 ----
command result_t NetworkLowPower.NetworkExitLowPower() {
! trace(TRACE_DEBUG_LEVEL,"Manager - exit low power\r\n");
post DoExitLowPower();
***************
*** 608,611 ****
--- 636,640 ----
event result_t NetworkPacket.SendDone(char *data) {
call NetworkPacket.ReleaseBuffer ( data );
+ call StatsLogger.BumpCounter(NUM_PS_SEND, 1);
return SUCCESS;
}
***************
*** 620,623 ****
--- 649,654 ----
t = (uint32 *) (Data);
+ call StatsLogger.BumpCounter(NUM_PS_RECV, 1);
+
switch (t[0]) {
case NM_DISPLAY_MESSAGE:
***************
*** 651,660 ****
case NM_EXIT_LOW_POWER:
! DisplayStr("Receive Exit Low Power packet\r\n");
post DoExitLowPower();
break;
case NM_EXIT_LOW_POWER_DONE:
! DisplayStr("Receive Exit Low Power Done packet\r\n");
DoExitLowPowerDone(Source);
break;
--- 682,691 ----
case NM_EXIT_LOW_POWER:
! trace(TRACE_DEBUG_LEVEL,"Receive Exit Low Power packet\r\n");
post DoExitLowPower();
break;
case NM_EXIT_LOW_POWER_DONE:
! trace(TRACE_DEBUG_LEVEL,"Receive Exit Low Power Done packet\r\n");
DoExitLowPowerDone(Source);
break;
***************
*** 665,668 ****
--- 696,704 ----
break;
+ case NM_NETWORK_RESET_NODES:
+ ResetDelay = t[1];
+ post DoNetworkResetNodes();
+ break;
+
default:
}
***************
*** 688,692 ****
event result_t LowPower.EnterLowPowerComplete () {
! DisplayStr("Entering deep sleep\r\n");
call LowPower.EnterDeepSleep();
return SUCCESS;
--- 724,728 ----
event result_t LowPower.EnterLowPowerComplete () {
! trace(TRACE_DEBUG_LEVEL,"Entering deep sleep\r\n");
call LowPower.EnterDeepSleep();
return SUCCESS;
***************
*** 717,729 ****
- #if 0
event result_t Timer.fired() {
! call LowPower.ExitDeepSleep();
! call LowPower.ExitLowPower();
!
return SUCCESS;
}
- #endif
--- 753,761 ----
event result_t Timer.fired() {
! call WDTControl.AllowForceReset();
return SUCCESS;
}
Index: NetworkMonitorC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/NetworkMonitorC.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** NetworkMonitorC.nc 16 Aug 2004 18:14:06 -0000 1.2
--- NetworkMonitorC.nc 6 Sep 2005 08:27:59 -0000 1.3
***************
*** 30,41 ****
*/
! #define DISPLAY 0
configuration NetworkMonitorC
{
provides {
interface StdControl as Control;
! command result_t Display(char *str);
interface NetworkLowPower;
command result_t NetworkWriteScanEnable(uint32 state);
command result_t SendTraceRoute();
}
--- 30,42 ----
*/
! includes StatsTypes;
configuration NetworkMonitorC
{
provides {
interface StdControl as Control;
!
interface NetworkLowPower;
command result_t NetworkWriteScanEnable(uint32 state);
+ command result_t NetworkResetNodes(uint32 ResetDelayMS);
command result_t SendTraceRoute();
}
***************
*** 51,75 ****
{
components NetworkMonitorM,
! NetworkTopologyM,
! BTLowerLayersM,
! LowPowerC,
! #if DISPLAY
! UARTBufferC,
! #endif
! NetworkManagerM;
! // TimerC;
Control = NetworkMonitorM;
- Display = NetworkMonitorM;
NetworkProperty = NetworkMonitorM;
NetworkLowPower = NetworkManagerM;
SendTraceRoute = NetworkMonitorM;
! #if DISPLAY
! NetworkMonitorM.UARTControl -> UARTBufferC;
! NetworkMonitorM.ReceiveData -> UARTBufferC;
! NetworkMonitorM.SendVarLenPacket -> UARTBufferC;
! #endif
!
NetworkMonitorM.NetworkPacket = NetworkMonitorPacket;
--- 52,77 ----
{
components NetworkMonitorM,
! NetworkTopologyM,
! BTLowerLayersM,
! LowPowerC,
! BluSHC,
! StatsLoggerM,
! NetworkManagerM,
! WDTControlM,
! TimerC;
Control = NetworkMonitorM;
NetworkProperty = NetworkMonitorM;
NetworkLowPower = NetworkManagerM;
SendTraceRoute = NetworkMonitorM;
+ NetworkResetNodes = NetworkManagerM.NetworkResetNodes;
! BluSHC.BluSH_AppI[unique("BluSH")] -> NetworkMonitorM.app_tracert;
! BluSHC.BluSH_AppI[unique("BluSH")] -> NetworkMonitorM.app_dump;
! BluSHC.BluSH_AppI[unique("BluSH")] -> NetworkMonitorM.app_getpower;
! BluSHC.BluSH_AppI[unique("BluSH")] -> NetworkMonitorM.app_lowpowerON;
! BluSHC.BluSH_AppI[unique("BluSH")] -> NetworkMonitorM.app_lowpowerOFF;
! BluSHC.BluSH_AppI[unique("BluSH")] -> NetworkMonitorM.app_resetnodes;
!
NetworkMonitorM.NetworkPacket = NetworkMonitorPacket;
***************
*** 80,85 ****
NetworkMonitorM.HCIBaseband -> BTLowerLayersM;
! NetworkMonitorM.DisplayMessage -> NetworkManagerM;
! NetworkManagerM.DisplayMessageDone -> NetworkMonitorM;
NetworkManagerM.NetworkPacket = NetworkManagerPacket;
--- 82,88 ----
NetworkMonitorM.HCIBaseband -> BTLowerLayersM;
! NetworkMonitorM.StatsLogger -> StatsLoggerM;
!
! NetworkManagerM.StatsLogger -> StatsLoggerM;
NetworkManagerM.NetworkPacket = NetworkManagerPacket;
***************
*** 93,99 ****
// NetworkManagerM.NetworkExitLowPowerDone -> NetworkMonitorM;
NetworkMonitorM.NetworkLowPower -> NetworkManagerM;
! NetworkMonitorM.NetworkWriteScanEnable -> NetworkManagerM;
NetworkManagerM.LowPower -> LowPowerC;
NetworkManagerM.HCIBaseband -> BTLowerLayersM;
! // NetworkManagerM.Timer -> TimerC.Timer[unique("Timer")];
}
--- 96,106 ----
// NetworkManagerM.NetworkExitLowPowerDone -> NetworkMonitorM;
NetworkMonitorM.NetworkLowPower -> NetworkManagerM;
! NetworkMonitorM.NetworkWriteScanEnable -> NetworkManagerM.NetworkWriteScanEnable;
! NetworkMonitorM.NetworkResetNodes -> NetworkManagerM.NetworkResetNodes;
!
NetworkManagerM.LowPower -> LowPowerC;
NetworkManagerM.HCIBaseband -> BTLowerLayersM;
! NetworkManagerM.Timer -> TimerC.Timer[unique("Timer")];
! NetworkManagerM.WDTControl -> WDTControlM;
!
}
Index: NetworkMonitorM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/NetworkMonitorM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** NetworkMonitorM.nc 16 Aug 2004 18:14:06 -0000 1.2
--- NetworkMonitorM.nc 6 Sep 2005 08:27:59 -0000 1.3
***************
*** 1,1099 ****
! /*
! * Copyright (c) 2004, Intel Corporation
! * All rights reserved.
! *
! * Redistribution and use in source and binary forms, with or without
! * modification, are permitted provided that the following conditions are met:
! *
! * Redistributions of source code must retain the above copyright notice,
! * this list of conditions and the following disclaimer.
! *
[...2151 lines suppressed...]
! * Start of NetworkManager interface.
! */
!
!
! event result_t NetworkLowPower.NetworkInitLowPowerDone() { return SUCCESS;}
! event result_t NetworkLowPower.NetworkEnterLowPowerDone() { return SUCCESS;}
! event result_t NetworkLowPower.NetworkExitLowPowerDone() { return SUCCESS;}
!
! /*
! * End of NetworkManager interface.
! */
!
! command result_t SendTraceRoute() {
! if (!TracePending) {
! TracePending = TRUE;
! post DoTraceRoute();
! }
! }
!
! }
Index: NetworkPageM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/NetworkPageM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NetworkPageM.nc 29 Jun 2004 14:56:14 -0000 1.1
--- NetworkPageM.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 29,33 ****
* POSSIBILITY OF SUCH DAMAGE.
*/
-
/*
* The Network Page interface abstracts the Bluetooth device paging mechanism.
--- 29,32 ----
***************
*** 56,68 ****
implementation
{
- //#define PAGE_DEBUG
#define INVALID_HANDLE 0xFFFF
! #ifdef PAGE_DEBUG
! void DisplayStr(char *str) __attribute__ ((C, spontaneous));
! #else
! #define DisplayStr(str)
! #endif
!
/*
--- 55,61 ----
implementation
{
#define INVALID_HANDLE 0xFFFF
! #define TRACE_DEBUG_LEVEL 0ULL
/*
***************
*** 117,121 ****
tConnectionParameters *NextPtr; // pointer to next PageList entry
! DisplayStr("Add Page\n");
for (i = PageListHead; i != PageListTail;) {
if (PageList[i].DestID == NodeID) {
--- 110,114 ----
tConnectionParameters *NextPtr; // pointer to next PageList entry
! trace(TRACE_DEBUG_LEVEL,"Add Page\n");
for (i = PageListHead; i != PageListTail;) {
if (PageList[i].DestID == NodeID) {
***************
*** 191,201 ****
if (ptr->RetryCount < MAX_PAGE_RETRY) {
!
! {
! char str[80];
! sprintf(str, "Paging - %01X%02X%02X\n", ptr->BD_ADDR.byte[2], ptr->BD_ADDR.byte[1], ptr->BD_ADDR.byte[0]);
! DisplayStr(str);
! }
! // allow all packet types
call HCILinkControl.Create_Connection( ptr->BD_ADDR,
(PACKET_TYPE_DM1 | PACKET_TYPE_DH1 | PACKET_TYPE_DM3 |
--- 184,190 ----
if (ptr->RetryCount < MAX_PAGE_RETRY) {
!
! trace(TRACE_DEBUG_LEVEL,"Paging - %01X%02X%02X\n", ptr->BD_ADDR.byte[2], ptr->BD_ADDR.byte[1], ptr->BD_ADDR.byte[0]);
! // allow all packet types
call HCILinkControl.Create_Connection( ptr->BD_ADDR,
(PACKET_TYPE_DM1 | PACKET_TYPE_DH1 | PACKET_TYPE_DM3 |
***************
*** 208,218 ****
} else {
!
! {
! char str[80];
! sprintf(str, "Page Connections %02X%02X%02X%02X%02X%02X %c %c %05X\n", ptr->BD_ADDR.byte[5], ptr->BD_ADDR.byte[4], ptr->BD_ADDR.byte[3], ptr->BD_ADDR.byte[2], ptr->BD_ADDR.byte[1], ptr->BD_ADDR.byte[0], (ptr->PagePending == TRUE) ? 'T' : 'F' , (ptr->PageDone == TRUE) ? 'T' : 'F', ptr->DestID );
! DisplayStr(str);
! }
! signal NetworkPage.PageComplete( ptr->DestID, INVALID_HANDLE);
ptr->PageDone = TRUE; // exceeded the retry limit
RemoveFinishedPages();
--- 197,203 ----
} else {
!
! trace(TRACE_DEBUG_LEVEL,"Page Connections %02X%02X%02X%02X%02X%02X %c %c %05X\n", ptr->BD_ADDR.byte[5], ptr->BD_ADDR.byte[4], ptr->BD_ADDR.byte[3], ptr->BD_ADDR.byte[2], ptr->BD_ADDR.byte[1], ptr->BD_ADDR.byte[0], (ptr->PagePending == TRUE) ? 'T' : 'F' , (ptr->PageDone == TRUE) ? 'T' : 'F', ptr->DestID );
! signal NetworkPage.PageComplete( ptr->DestID, INVALID_HANDLE);
ptr->PageDone = TRUE; // exceeded the retry limit
RemoveFinishedPages();
***************
*** 385,393 ****
PageList[i].PagePending = FALSE;
PageList[i].RetryCount++;
! {
! char str[80];
! sprintf(str, "Page failed - 0x%0X\n", Status);
! DisplayStr(str);
! }
PostPageConnections();
return SUCCESS;
--- 370,375 ----
PageList[i].PagePending = FALSE;
PageList[i].RetryCount++;
!
! trace(TRACE_DEBUG_LEVEL,"Page failed - 0x%0X\n", Status);
PostPageConnections();
return SUCCESS;
Index: NetworkPropertiesM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/NetworkPropertiesM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NetworkPropertiesM.nc 29 Jun 2004 14:56:14 -0000 1.1
--- NetworkPropertiesM.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 29,33 ****
* POSSIBILITY OF SUCH DAMAGE.
*/
-
/*
* This component manages the network properties.
--- 29,32 ----
***************
*** 44,47 ****
--- 43,47 ----
interface NetworkPacket;
interface NetworkTopology;
+ interface StatsLogger;
}
}
***************
*** 135,138 ****
--- 135,140 ----
uint32 Command;
+ call StatsLogger.BumpCounter(NUM_NP_RECV, 1);
+
Command = *((uint32 *) (Data));
switch (Command) {
***************
*** 154,157 ****
--- 156,160 ----
event result_t NetworkPacket.SendDone (char *data) {
call NetworkPacket.ReleaseBuffer ( data );
+ call StatsLogger.BumpCounter(NUM_NP_SEND, 1);
return SUCCESS;
Index: NetworkRelayM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/NetworkRelayM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** NetworkRelayM.nc 16 Aug 2004 18:14:06 -0000 1.2
--- NetworkRelayM.nc 6 Sep 2005 08:27:59 -0000 1.3
***************
*** 29,33 ****
* POSSIBILITY OF SUCH DAMAGE.
*/
-
/*
* This module manages network traffic not intended for this node.
--- 29,32 ----
***************
*** 52,65 ****
implementation
{
! //#define RELAY_DEBUG
!
! #ifdef RELAY_DEBUG
! void DisplayStr(char *str) __attribute__ ((C, spontaneous));
! #else
! #define DisplayStr(str)
! #endif
task void SendQueuedBuffers();
! #define MAX_RELAY_BUFFERS 80
typedef struct tRelayBuffer {
--- 51,58 ----
implementation
{
! #define TRACE_DEBUG_LEVEL 0ULL
task void SendQueuedBuffers();
! #define MAX_RELAY_BUFFERS 50
typedef struct tRelayBuffer {
***************
*** 133,141 ****
if (call NetworkPacket.Send(HeaderPtr->dest, Data, Length) != SUCCESS) {
call NetworkPacket.ReleaseBuffer(Data);
! {
! char str[80];
! sprintf(str, "Relay send to %05X failed, dropping packet\n\r", HeaderPtr->dest);
! DisplayStr(str);
! }
}
RelayBuffer[i].data = NULL;
--- 126,131 ----
if (call NetworkPacket.Send(HeaderPtr->dest, Data, Length) != SUCCESS) {
call NetworkPacket.ReleaseBuffer(Data);
!
! trace(TRACE_DEBUG_LEVEL,"Relay send to %05X failed, dropping packet\n\r", HeaderPtr->dest);
}
RelayBuffer[i].data = NULL;
***************
*** 157,165 ****
// ran out of buffers
post SendQueuedBuffers();
! {
! char str[80];
! sprintf(str, "Relay Buffers full, dropping packet from %05X\n\r", Source);
! DisplayStr(str);
! }
return FAIL;
}
--- 147,151 ----
// ran out of buffers
post SendQueuedBuffers();
! trace(TRACE_DEBUG_LEVEL, "Relay Buffers full, dropping packet from %05X\n\r", Source);
return FAIL;
}
***************
*** 167,176 ****
buffer = call NetworkPacket.AllocateBuffer(Length);
if (buffer == NULL ) {
! {
! char str[80];
! sprintf(str, "Relay out of memory, dropping packet from %05X\n\r", Source);
! DisplayStr(str);
! }
! return FAIL;
}
--- 153,158 ----
buffer = call NetworkPacket.AllocateBuffer(Length);
if (buffer == NULL ) {
! trace(TRACE_DEBUG_LEVEL, "Relay out of memory, dropping packet from %05X\n\r", Source);
! return FAIL;
}
Index: NetworkTopologyM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/NetworkTopologyM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NetworkTopologyM.nc 29 Jun 2004 14:56:14 -0000 1.1
--- NetworkTopologyM.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 29,33 ****
* POSSIBILITY OF SUCH DAMAGE.
*/
-
/*
* This module maintains the routing table structure and the set of
--- 29,32 ----
***************
*** 47,56 ****
! //#define NT_DEBUG
! #ifdef NT_DEBUG
! void DisplayStr(char *str) __attribute__ ((C, spontaneous));
! #else
! #define DisplayStr(str)
! #endif
// Bitmask values for the ConnectionProperties field of the ActiveConnection
--- 46,50 ----
! #define TRACE_DEBUG_LEVEL 0ULL
// Bitmask values for the ConnectionProperties field of the ActiveConnection
***************
*** 358,362 ****
if (RTArray[i].Connection == *ptr) {
#ifdef NT_DEBUG
! sprintf(str, "%s, %0X", str, RTArray[i].Destination & 0xFFFFF);
#endif // NT_DEBUG
if (i < (NumRTEntries - 1)) {
--- 352,356 ----
if (RTArray[i].Connection == *ptr) {
#ifdef NT_DEBUG
! trace(TRACE_DEBUG_LEVEL, "%s, %0X", str, RTArray[i].Destination & 0xFFFFF);
#endif // NT_DEBUG
if (i < (NumRTEntries - 1)) {
***************
*** 372,378 ****
}
}
- #ifdef NT_DEBUG
- DisplayStr(str);
- #endif // NT_DEBUG
// Remove the ActiveConnection entry if forced or if it was a discoverd link
--- 366,369 ----
***************
*** 736,746 ****
! #ifdef NT_DEBUG
! {
! char str[80];
! sprintf(str, "Update route to %05X through %05X\n", Dest & 0xFFFFF, Next & 0xFFFFF);
! DisplayStr(str);
! }
! #endif // NT_DEBUG
RTArray[i].Connection = ConnectionPtr;
RTArray[i].Hops = Hops;
--- 727,732 ----
! trace(TRACE_DEBUG_LEVEL, "Update route to %05X through %05X\n", Dest & 0xFFFFF, Next & 0xFFFFF);
!
RTArray[i].Connection = ConnectionPtr;
RTArray[i].Hops = Hops;
***************
*** 756,766 ****
if (NumRTEntries < MAX_NUM_ROUTING_TABLE) {
! #ifdef NT_DEBUG
! {
! char str[80];
! sprintf(str, "Add new route to %05X through %05X\n", Dest & 0xFFFFF, Next & 0xFFFFF);
! DisplayStr(str);
! }
! #endif // NT_DEBUG
RTArray[NumRTEntries].Destination = Dest;
RTArray[NumRTEntries].Connection = ConnectionPtr;
--- 742,746 ----
if (NumRTEntries < MAX_NUM_ROUTING_TABLE) {
! trace(TRACE_DEBUG_LEVEL,"Add new route to %05X through %05X\n", Dest & 0xFFFFF, Next & 0xFFFFF);
RTArray[NumRTEntries].Destination = Dest;
RTArray[NumRTEntries].Connection = ConnectionPtr;
***************
*** 780,791 ****
command result_t NetworkTopology.RemoveRoute(uint32 Dest) {
int i;
!
! #ifdef NT_DEBUG
! {
! char str[80];
! sprintf(str, "Remove route to %0X\n", Dest & 0xFFFFF);
! DisplayStr(str);
! }
! #endif // NT_DEBUG
for (i = 0; i < NumRTEntries; i++) {
if (RTArray[i].Destination == Dest) {
--- 760,766 ----
command result_t NetworkTopology.RemoveRoute(uint32 Dest) {
int i;
!
! trace(TRACE_DEBUG_LEVEL,"Remove route to %0X\n", Dest & 0xFFFFF);
!
for (i = 0; i < NumRTEntries; i++) {
if (RTArray[i].Destination == Dest) {
Index: SensorC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/SensorC.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SensorC.nc 29 Jun 2004 14:56:14 -0000 1.1
--- SensorC.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 29,33 ****
* POSSIBILITY OF SUCH DAMAGE.
*/
-
configuration SensorC {
provides interface Sensor;
--- 29,32 ----
***************
*** 35,42 ****
}
implementation {
! components SensorM, HPLDMAUartC, MemoryM;
Sensor = SensorM;
StdControl = SensorM;
! SensorM.HPLDMAUart -> HPLDMAUartC;
SensorM.Memory -> MemoryM;
}
--- 34,43 ----
}
implementation {
! components SensorM, HPLDMAUartC, MemoryM, StatsLoggerM;
Sensor = SensorM;
StdControl = SensorM;
! SensorM.HPLUART -> HPLDMAUartC;
! SensorM.HPLDMA -> HPLDMAUartC;
SensorM.Memory -> MemoryM;
+ SensorM.StatsLogger -> StatsLoggerM;
}
Index: SensorM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/SensorM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SensorM.nc 29 Jun 2004 14:56:14 -0000 1.1
--- SensorM.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 29,33 ****
* POSSIBILITY OF SUCH DAMAGE.
*/
-
#define BAUD_115200 eTM_B115200
#define BAUD_230400 eTM_B230400
--- 29,32 ----
***************
*** 42,47 ****
}
uses {
! interface HPLDMAUart;
interface Memory;
}
}
--- 41,48 ----
}
uses {
! interface HPLUART;
! interface HPLDMA;
interface Memory;
+ interface StatsLogger;
}
}
***************
*** 64,70 ****
command result_t StdControl.init() {
clkDiv = BAUD_460800;
TurnedOnBoard = false;
AcquiringSamples = false;
! call HPLDMAUart.init(clkDiv);
/*
--- 65,73 ----
command result_t StdControl.init() {
clkDiv = BAUD_460800;
+ //clkDiv = BAUD_115200;
TurnedOnBoard = false;
AcquiringSamples = false;
! call HPLUART.setRate(clkDiv);
! call HPLUART.init();
/*
***************
*** 98,101 ****
--- 101,105 ----
TM_SetPio(3);
TurnedOnBoard = true;
+ call StatsLogger.StartTimer(MSEC_SENSOR_BOARD_ON);
return SUCCESS;
}
***************
*** 107,110 ****
--- 111,115 ----
TM_SetPio(7);
AcquiringSamples=false;
+ call StatsLogger.StopTimerUpdateCounter(MSEC_SENSOR_BOARD_ON);
return SUCCESS;
}
***************
*** 180,183 ****
--- 185,189 ----
+ #if 0
//allocate the buffer to be used by the UART and start collecting
if(!UARTBuffer){
***************
*** 191,196 ****
}
}
!
! call HPLDMAUart.start(RxBuffer, BufferSize);
TM_ResetPio(7);
--- 197,213 ----
}
}
! #endif
! //something is wrong and the UART is not empty
! if(TM_MainUartReg->lineStatus & TM_UART_RX_READY_MASK){
! TM_SetPioAsOutput(4);
! TM_SetPioAsOutput(5);
! TM_SetPioAsOutput(6);
! TM_SetPio(4);
! TM_ResetPio(5);
! TM_SetPio(6);
! while(1);
! }
!
! call HPLDMA.DMAGet(RxBuffer, rxBytesTotal);
TM_ResetPio(7);
***************
*** 211,234 ****
return SUCCESS;
}
!
! event uint8 *HPLDMAUart.get(uint8 *data, uint16 NumBytes) {
if(AcquiringSamples){
rxBytesCurrent+=NumBytes;
! if(rxBytesCurrent >=rxBytesTotal)
! {
! TM_SetPio(7);
! AcquiringSamples = false;
! signal Sensor.SamplesAcquired(CurrentSensor, RxBuffer, numSamples);
! return UARTBuffer;
! }
! return (RxBuffer+rxBytesCurrent);
}
! return UARTBuffer;
}
! event result_t HPLDMAUart.putDone(uint8 *data) {
!
return SUCCESS;
! }
}
--- 228,270 ----
return SUCCESS;
}
! task void SignalSamplesAcquired(){
! // signal Sensor.SamplesAcquired(CurrentSensor, RxBuffer, rxBytesCurrent/bytesPerSample);
! signal Sensor.SamplesAcquired(CurrentSensor, RxBuffer, numSamples);
! return;
! }
!
! async event uint8 *HPLDMA.DMAGetDone(uint8 *data, uint16 NumBytes) {
if(AcquiringSamples){
+ if(NumBytes!=rxBytesTotal){
+ TM_SetPioAsOutput(4);
+ TM_SetPioAsOutput(5);
+ TM_SetPioAsOutput(6);
+
+ TM_ResetPio(4);
+ TM_ResetPio(5);
+ TM_SetPio(6);
+ while(1);
+ }
rxBytesCurrent+=NumBytes;
! TM_SetPio(7);
! AcquiringSamples = false;
! //signal Sensor.SamplesAcquired(CurrentSensor, RxBuffer, numSamples);
! post SignalSamplesAcquired();
! //return UARTBuffer;
}
! return NULL;
}
! async event result_t HPLDMA.DMAPutDone(uint8 *data) {
return SUCCESS;
! }
!
! async event result_t HPLUART.get(uint8 data){
! return SUCCESS;
! }
!
! async event result_t HPLUART.putDone(){
! return SUCCESS;
! }
}
Index: SignalStrengthM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/SignalStrengthM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SignalStrengthM.nc 29 Jun 2004 14:56:14 -0000 1.1
--- SignalStrengthM.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 29,33 ****
* POSSIBILITY OF SUCH DAMAGE.
*/
-
module SignalStrengthM {
--- 29,32 ----
***************
*** 49,58 ****
implementation
{
! //#define SIGNAL_STRENGTH_DEBUG
! #ifdef SIGNAL_STRENGTH_DEBUG
! void DisplayStr(char *str) __attribute__ ((C, spontaneous));
! #else
! #define DisplayStr(str)
! #endif
#define MAX_NEIGHBORS 16
--- 48,52 ----
implementation
{
! #define TRACE_DEBUG_LEVEL 0ULL
#define MAX_NEIGHBORS 16
***************
*** 93,102 ****
&NumNeighbors,
&(Neighbors[0]));
! {
! char str[80];
! sprintf(str, "Collecting %d transmit powers for %05X\n\r", NumNeighbors, Neighbors[0]);
! DisplayStr(str);
! }
!
if (NumNeighbors > 0) {
if (call NetworkTopology.GetNextConnection(Neighbors[--NumNeighbors],
--- 87,92 ----
&NumNeighbors,
&(Neighbors[0]));
! trace(TRACE_DEBUG_LEVEL,"Collecting %d transmit powers for %05X\n\r", NumNeighbors, Neighbors[0]);
!
if (NumNeighbors > 0) {
if (call NetworkTopology.GetNextConnection(Neighbors[--NumNeighbors],
***************
*** 118,127 ****
&NumNeighbors,
&(Neighbors[0]));
! {
! char str[80];
! sprintf(str, "Collecting %d signal strengths for %05X\n\r", NumNeighbors, Neighbors[0]);
! DisplayStr(str);
! }
!
if (NumNeighbors > 0) {
if (call NetworkTopology.GetNextConnection(Neighbors[--NumNeighbors],
--- 108,113 ----
&NumNeighbors,
&(Neighbors[0]));
! trace(TRACE_DEBUG_LEVEL,"Collecting %d signal strengths for %05X\n\r", NumNeighbors, Neighbors[0]);
!
if (NumNeighbors > 0) {
if (call NetworkTopology.GetNextConnection(Neighbors[--NumNeighbors],
***************
*** 148,156 ****
int8_t RSSI) {
! {
! char str[80];
! sprintf(str, "Read RSSI complete status %d, Handle %d, signal strength %d\n\r", Status, Handle, RSSI);
! DisplayStr(str);
! }
if (Status == 0) {
call NetworkTopology.SetRSSI(Handle, RSSI);
--- 134,139 ----
int8_t RSSI) {
! trace(TRACE_DEBUG_LEVEL, "Read RSSI complete status %d, Handle %d, signal strength %d\n\r", Status, Handle, RSSI);
!
if (Status == 0) {
call NetworkTopology.SetRSSI(Handle, RSSI);
***************
*** 202,211 ****
tHandle Connection_Handle,
int8_t Transmit_Power_Level) {
! {
! char str[80];
! sprintf(str, "Read transmit power status %d, Handle %d, power %d\n\r", Status, Connection_Handle, Transmit_Power_Level);
! DisplayStr(str);
! }
! if (Status == 0) {
call NetworkTopology.SetTransmitPower( Connection_Handle,
Transmit_Power_Level);
--- 185,190 ----
tHandle Connection_Handle,
int8_t Transmit_Power_Level) {
! trace(TRACE_DEBUG_LEVEL,"Read transmit power status %d, Handle %d, power %d\n\r", Status, Connection_Handle, Transmit_Power_Level);
! if (Status == 0) {
call NetworkTopology.SetTransmitPower( Connection_Handle,
Transmit_Power_Level);
Index: TempHum.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/TempHum.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** TempHum.nc 29 Jun 2004 14:56:14 -0000 1.1
--- TempHum.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 1,52 ****
! /*
! * Copyright (c) 2004, Intel Corporation
! * All rights reserved.
! *
! * Redistribution and use in source and binary forms, with or without
! * modification, are permitted provided that the following conditions are met:
! *
! * Redistributions of source code must retain the above copyright notice,
! * this list of conditions and the following disclaimer.
! *
! * Redistributions in binary form must reproduce the above copyright notice,
! * this list of conditions and the following disclaimer in the documentation
! * and/or other materials provided with the distribution.
! *
! * Neither the name of the Intel Corporation nor the names of its contributors
! * may be used to endorse or promote products derived from this software
! * without specific prior written permission.
! *
! * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
! * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
! * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
! * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
! * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
! * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
! * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
! * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! * POSSIBILITY OF SUCH DAMAGE.
! */
!
! configuration TempHum {
! provides {
! interface StdControl;
! interface ADC as TempSensor;
! interface ADC as HumSensor;
! interface ADCError as TempError;
! interface ADCError as HumError;
! }
! }
! implementation {
! components TempHumM, TimerC;
! StdControl = TempHumM.StdControl;
! TempSensor = TempHumM.TempSensor;
! HumSensor = TempHumM.HumSensor;
! TempError = TempHumM.TempError;
! HumError = TempHumM.HumError;
!
! TempHumM.TimerControl -> TimerC;
! TempHumM.Timer -> TimerC.Timer[unique("Timer")];
! }
!
--- 1,88 ----
! /* tab:4
! *
! *
! * "Copyright (c) 2000-2002 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."
! *
! */
! /* tab:4
! * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
! * downloading, copying, installing or using the software you agree to
! * this license. If you do not agree to this license, do not download,
! * install, copy or use the software.
! *
! * Intel Open Source License
! *
! * Copyright (c) 2002 Intel Corporation
! * All rights reserved.
! * Redistribution and use in source and binary forms, with or without
! * modification, are permitted provided that the following conditions are
! * met:
! *
! * Redistributions of source code must retain the above copyright
! * notice, this list of conditions and the following disclaimer.
! * Redistributions in binary form must reproduce the above copyright
! * notice, this list of conditions and the following disclaimer in the
! * documentation and/or other materials provided with the distribution.
! * Neither the name of the Intel Corporation nor the names of its
! * contributors may be used to endorse or promote products derived from
! * this software without specific prior written permission.
! *
! * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
! * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
! * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
! * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
! * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
! * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
! * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
! * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
! * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
! * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
! * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! *
! *
! */
! /*
! *
! * Authors: Mohammad Rahmim, Joe Polastre
! *
! * $Id$
! */
!
! configuration TempHum {
! provides {
! interface StdControl;
! interface ADC as TempSensor;
! interface ADC as HumSensor;
! // interface ADCError as TempError;
! // interface ADCError as HumError;
! }
! }
! implementation {
! components TempHumM, TimerC;
! StdControl = TempHumM.StdControl;
! TempSensor = TempHumM.TempSensor;
! HumSensor = TempHumM.HumSensor;
! // TempError = TempHumM.TempError;
! // HumError = TempHumM.HumError;
!
! TempHumM.TimerControl -> TimerC;
! TempHumM.Timer -> TimerC.Timer[unique("Timer")];
! }
!
Index: TempHumM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/TempHumM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** TempHumM.nc 29 Jun 2004 14:56:14 -0000 1.1
--- TempHumM.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 1,470 ****
! /*
! * Copyright (c) 2004, Intel Corporation
! * All rights reserved.
! *
! * Redistribution and use in source and binary forms, with or without
! * modification, are permitted provided that the following conditions are met:
! *
! * Redistributions of source code must retain the above copyright notice,
! * this list of conditions and the following disclaimer.
! *
! * Redistributions in binary form must reproduce the above copyright notice,
! * this list of conditions and the following disclaimer in the documentation
! * and/or other materials provided with the distribution.
! *
! * Neither the name of the Intel Corporation nor the names of its contributors
! * may be used to endorse or promote products derived from this software
! * without specific prior written permission.
! *
! * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
! * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
! * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
! * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
! * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
! * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
! * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
! * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! * POSSIBILITY OF SUCH DAMAGE.
! */
!
! module TempHumM {
! provides {
! interface StdControl;
! interface ADC as TempSensor;
! interface ADC as HumSensor;
! interface ADCError as HumError;
! interface ADCError as TempError;
! }
! uses {
! interface Leds;
! interface Timer;
! interface StdControl as TimerControl;
! }
!
! }
! implementation {
!
!
! //states
! enum {READY=0, TEMP_MEASUREMENT=1, HUM_MEASUREMENT=2, POWER_OFF};
!
! char state;
! uint8_t timeout;
! uint8_t errornum;
! uint16_t data;
!
! bool humerror,temperror;
!
! void HUMIDITY_MAKE_DATA_OUTPUT(){ TOSH_MAKE_I2C_BUS1_SDA_OUTPUT();}
! void HUMIDITY_MAKE_DATA_INPUT() { TOSH_MAKE_I2C_BUS1_SDA_INPUT(); }
!
! void HUMIDITY_SET_DATA() { TOSH_SET_I2C_BUS1_SDA_PIN(); }
! void HUMIDITY_CLEAR_DATA() { TOSH_CLR_I2C_BUS1_SDA_PIN(); }
! char HUMIDITY_GET_DATA() { return TOSH_READ_I2C_BUS1_SDA_PIN(); }
!
! void HUMIDITY_MAKE_CLOCK_OUTPUT() { TOSH_MAKE_I2C_BUS1_SCL_OUTPUT(); }
! void HUMIDITY_MAKE_CLOCK_INPUT() { TOSH_MAKE_I2C_BUS1_SCL_INPUT(); }
! void HUMIDITY_SET_CLOCK() { TOSH_SET_I2C_BUS1_SCL_PIN(); }
! void HUMIDITY_CLEAR_CLOCK() { TOSH_CLR_I2C_BUS1_SCL_PIN(); }
!
! void TOSH_wait_250ns()
! {
! int i;
! for( i=0;i<2; i++)
! {
! asm volatile ("nop" ::);
! }
! }
!
! char calc_crc(char current, char in) {
! return crctable[current ^ in];
! }
!
! task void signalHumError() {
! signal HumError.error(errornum);
! }
!
! task void signalTempError() {
! signal TempError.error(errornum);
! }
!
! static inline void ack()
! {
! HUMIDITY_MAKE_DATA_OUTPUT();
! HUMIDITY_CLEAR_DATA();
! TOSH_wait_250ns();
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! HUMIDITY_CLEAR_CLOCK();
! HUMIDITY_MAKE_DATA_INPUT();
! HUMIDITY_SET_DATA();
! }
!
! static inline void initseq()
! {
! HUMIDITY_MAKE_DATA_OUTPUT();
! HUMIDITY_SET_DATA();
! HUMIDITY_CLEAR_CLOCK();
! TOSH_wait_250ns();
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! HUMIDITY_CLEAR_DATA();
! TOSH_wait_250ns();
! HUMIDITY_CLEAR_CLOCK();
! TOSH_wait_250ns();
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! HUMIDITY_SET_DATA();
! TOSH_wait_250ns();
! HUMIDITY_CLEAR_CLOCK();
! }
!
! static inline void reset()
! {
! int i;
! HUMIDITY_MAKE_DATA_OUTPUT();
! HUMIDITY_SET_DATA();
! HUMIDITY_CLEAR_CLOCK();
! for (i=0;i<9;i++) {
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! HUMIDITY_CLEAR_CLOCK();
! }
! }
!
! static inline char processCommand(int cmd)
! {
! int i;
! int CMD = cmd;
! cmd &= 0x1f;
! //HUMIDITY_INT_DISABLE();
! reset();
! initseq(); //sending the init sequence
! for(i=0;i<8;i++)
! {
! if(cmd & 0x80)
! HUMIDITY_SET_DATA();
! else
! HUMIDITY_CLEAR_DATA();
! cmd = cmd << 1 ;
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! TOSH_wait_250ns();
! HUMIDITY_CLEAR_CLOCK();
! }
! HUMIDITY_MAKE_DATA_INPUT();
! HUMIDITY_SET_DATA();
! TOSH_wait_250ns();
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! if(HUMIDITY_GET_DATA())
! {
! reset();
! errornum = 2;
! if ((CMD == TOSH_HUMIDITY_ADDR) && (humerror == TRUE))
! post signalHumError();
! else if ((CMD == TOSH_HUMIDTEMP_ADDR) && (temperror == TRUE))
! post signalTempError();
! return 0;
! }
! TOSH_wait_250ns();
! HUMIDITY_CLEAR_CLOCK();
! if((CMD == TOSH_HUMIDITY_ADDR) || (CMD == TOSH_HUMIDTEMP_ADDR) )
! {
! if ((CMD == TOSH_HUMIDITY_ADDR) && (humerror == TRUE))
! {
! timeout = 0;
! call Timer.start(TIMER_REPEAT, HUMIDITY_TIMEOUT_MS);
! }
! else if ((CMD == TOSH_HUMIDTEMP_ADDR) && (temperror == TRUE))
! {
! timeout = 0;
! call Timer.start(TIMER_REPEAT, HUMIDITY_TIMEOUT_MS);
! }
! TOSH_wait_250ns();
! TM_SetPio(5);
! TM_EnablePIOInt();
! //HUMIDITY_INT_ENABLE();
! }
! return 1;
! }
!
! extern void TM_PIOIsr_ISR() __attribute__ ((C, spontaneous));
!
! command result_t StdControl.init() {
! humerror = FALSE;
! temperror = FALSE;
! state = POWER_OFF;
! TM_RegisterInterrupt(eTM_PIO, (tIntFunc) TM_PIOIsr_ISR, eTM_ProLow);
! return call TimerControl.init();
! }
!
! command result_t StdControl.start() {
! state=READY;
! TM_SetPioAsOutput(5);
! TM_SetPioAsOutput(6);
!
! HUMIDITY_CLEAR_CLOCK();
! HUMIDITY_MAKE_CLOCK_OUTPUT();
! HUMIDITY_SET_DATA();
! HUMIDITY_MAKE_DATA_INPUT();
! //HUMIDITY_INT_DISABLE();
! reset();
! processCommand(TOSH_HUMIDITY_RESET);
! return SUCCESS;
! }
!
! command result_t StdControl.stop() {
! state = POWER_OFF;
! HUMIDITY_CLEAR_CLOCK();
! HUMIDITY_MAKE_CLOCK_INPUT();
! HUMIDITY_MAKE_DATA_INPUT();
! HUMIDITY_CLEAR_DATA();
! TM_DisablePIOInt();
! return SUCCESS;
! }
!
! default event result_t TempSensor.dataReady(uint16_t tempData)
! {
! return SUCCESS;
! }
!
!
! default event result_t HumSensor.dataReady(uint16_t humData)
! {
! return SUCCESS;
! }
!
!
! task void readSensor()
! {
! char i;
! char CRC=0;
! uint32_t temp, humidity;
! data=0;
!
!
! //call Timer.stop();
!
! for(i=0;i<8;i++)
! {
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! data |= HUMIDITY_GET_DATA();
! data = data << 1;
! HUMIDITY_CLEAR_CLOCK();
! }
! ack();
! for(i=0;i<8;i++)
! {
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! data |= HUMIDITY_GET_DATA();
! //the last byte of data should not be shifted
! if(i!=7)
! data = data << 1;
! HUMIDITY_CLEAR_CLOCK();
! }
! ack();
! for(i=0;i<8;i++){
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! CRC |= HUMIDITY_GET_DATA();
! if(i!=7)CRC = CRC << 1;
! HUMIDITY_CLEAR_CLOCK();
! }
! // nack with high as it should be for the CRC ack
! HUMIDITY_MAKE_DATA_OUTPUT();
! HUMIDITY_SET_DATA();
! TOSH_wait_250ns();
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! HUMIDITY_CLEAR_CLOCK();
!
! /**********
! * initial implementation of CRC calculation
! * commented out for now
! {
! int i;
! char crc = 0;
! char reverse_crc = 0;
!
! // check CRC
! crc = calc_crc(crc,TOSH_HUMIDTEM_ADDR);
! crc = calc_crc(crc,data[0]);
! crc = calc_crc(crc,data[1]);
!
! // reverse the crc bits
! for (i=0; i<8; i++)
! reverse_crc = reverse_crc + (((crc >> i) & 0x01) << (7-i));
!
! // is the crc correct?
! if ((reverse_crc == data[2]) || (crc == data[2])) {
! }
! }
! **/
!
!
! if(state==TEMP_MEASUREMENT){
! // let the PC do the calculation *****
!
! //temp=data;
! //t= (((ftemp) )*0.98-3840)/100;
! //temp= (int16_t) t;
! //if(temp > 100 ) temp=100;
! //if(temp < -40 ) temp=-40;
! temp = (((data>>1) *18) -39280)/1000;
! //signal TempSensor.dataReady( (int16_t)temp);
! signal TempSensor.dataReady((uint16_t)(temp & 0xFF));
! //signal TempSensor.dataReady( 13262);
!
! //signal TempSensor.dataReady(data);
! }
! else if(state==HUM_MEASUREMENT) {
! /* let the PC do the calculation *****
! hum=data;
! h= 0.0405 * (float) (hum) - 4 - (float)(hum) * (float)(hum)*0.0000028;
! h= (t-25) * (0.01 + 0.00128 * hum) + h;
! hum= (int16_t) h;
! if(hum > 100 ) hum=100;
! if(hum < 0 ) hum=0;
! signal HumSensor.dataReady(hum);
! ****/
! humidity = (((data>>1) * (data >>1)) * -28)/10000000;
! humidity += ((data>>1) * 405)/10000;
! humidity -=4;
! // if(humidity > 99)
! // humidity = 99;
! // humidity = data;
! // signal HumSensor.dataReady((uint16_t)(humidity & 0xFF));
! signal HumSensor.dataReady((uint16_t)(humidity));
! }
! state=READY;
! }
!
!
! //#ifndef PLATFORM_PC
! #if 0
! TOSH_SIGNAL(HUMIDITY_INTERRUPT)
! {
! HUMIDITY_INT_DISABLE();
! post readSensor();
! return;
! }
! #endif
!
! //if we get the GPIO interrupt and it's the correct pin, post readSensor();
!
! void TM_PIO_InterruptHdl() __attribute__ ((C, spontaneous))
! {
! TM_DisablePIOInt();
! if( TM_ReadPio(1) == 0)
! {
! //only disable it if we get the one we want...
! //it seems like there's some stale state or somethin
! TM_ResetPio(5);
! post readSensor();
! }
! else
! {
! TM_EnablePIOInt();
! }
! TM_ClearPioInterrupt();
! }
!
! // no such thing
! command result_t TempSensor.getContinuousData() {
! return FAIL;
! }
!
! // no such thing
! command result_t HumSensor.getContinuousData() {
! return FAIL;
! }
!
! command result_t TempSensor.getData()
! {
! if(state!= READY ){
! reset();
! }
! state=TEMP_MEASUREMENT;
! processCommand(TOSH_HUMIDTEMP_ADDR);
! return SUCCESS;
! }
!
! command result_t HumSensor.getData()
! {
! if(state!= READY ){
! reset();
! }
! state=HUM_MEASUREMENT;
! processCommand(TOSH_HUMIDITY_ADDR);
! return SUCCESS;
! }
!
!
! command result_t HumError.enable() {
! if (humerror == FALSE) {
! //atomic humerror = TRUE;
! humerror = TRUE;
! return SUCCESS;
! }
! return FAIL;
! }
!
! command result_t TempError.enable() {
! if (temperror == FALSE) {
! //atomic temperror = TRUE;
! temperror = TRUE;
! return SUCCESS;
! }
! return FAIL;
! }
!
! command result_t HumError.disable() {
! if (humerror == TRUE) {
! //atomic humerror = FALSE;
! humerror = FALSE;
! return SUCCESS;
! }
! return FAIL;
! }
!
! command result_t TempError.disable() {
! if (temperror == TRUE) {
! // atomic temperror = FALSE;
! temperror = FALSE;
! return SUCCESS;
! }
! return FAIL;
! }
!
! event result_t Timer.fired() {
! timeout++;
! if (timeout > HUMIDITY_TIMEOUT_TRIES) {
! if ((state == HUM_MEASUREMENT) && (humerror == TRUE)) {
! call Timer.stop();
! //HUMIDITY_INT_DISABLE();
! state = READY;
! errornum = 1;
! post signalHumError();
! }
! else if ((state == TEMP_MEASUREMENT) && (temperror == TRUE)) {
! call Timer.stop();
! //HUMIDITY_INT_DISABLE();
! state = READY;
! errornum = 1;
! post signalTempError();
! }
! }
! return SUCCESS;
! }
!
!
! default event result_t HumError.error(uint8_t token) { return SUCCESS; }
!
! default event result_t TempError.error(uint8_t token) { return SUCCESS; }
!
! }
--- 1,508 ----
! /* tab:4
! **
! *
! * "Copyright (c) 2000-2002 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."
! *
! */
! /* tab:4
! * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
! * downloading, copying, installing or using the software you agree to
! * this license. If you do not agree to this license, do not download,
! * install, copy or use the software.
! *
! * Intel Open Source License
! *
! * Copyright (c) 2002 Intel Corporation
! * All rights reserved.
! * Redistribution and use in source and binary forms, with or without
! * modification, are permitted provided that the following conditions are
! * met:
! *
! * Redistributions of source code must retain the above copyright
! * notice, this list of conditions and the following disclaimer.
! * Redistributions in binary form must reproduce the above copyright
! * notice, this list of conditions and the following disclaimer in the
! * documentation and/or other materials provided with the distribution.
! * Neither the name of the Intel Corporation nor the names of its
! * contributors may be used to endorse or promote products derived from
! * this software without specific prior written permission.
! *
! * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
! * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
! * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
! * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
! * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
! * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
! * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
! * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
! * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
! * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
! * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! *
! *
! */
! /*
! *
! * Authors: Mohammad Rahmim, Joe Polastre
! *
! * $Id$
! */
!
! module TempHumM {
! provides {
! interface StdControl;
! interface ADC as TempSensor;
! interface ADC as HumSensor;
! // interface ADCError as HumError;
! // interface ADCError as TempError;
! }
! uses {
! interface Leds;
! interface Timer;
! interface StdControl as TimerControl;
! }
!
! }
! implementation {
!
!
! #include "sensorboard.h"
!
! //states
! enum {READY=0, TEMP_MEASUREMENT=1, HUM_MEASUREMENT=2, POWER_OFF};
!
! char state;
! uint8_t timeout;
! uint8_t errornum;
! uint16_t data;
!
! bool humerror,temperror;
!
! void HUMIDITY_MAKE_DATA_OUTPUT(){ TOSH_MAKE_I2C_BUS1_SDA_OUTPUT();}
! void HUMIDITY_MAKE_DATA_INPUT() { TOSH_MAKE_I2C_BUS1_SDA_INPUT(); }
!
! void HUMIDITY_SET_DATA() { TOSH_SET_I2C_BUS1_SDA_PIN(); }
! void HUMIDITY_CLEAR_DATA() { TOSH_CLR_I2C_BUS1_SDA_PIN(); }
! char HUMIDITY_GET_DATA() { return TOSH_READ_I2C_BUS1_SDA_PIN(); }
!
! void HUMIDITY_MAKE_CLOCK_OUTPUT() { TOSH_MAKE_I2C_BUS1_SCL_OUTPUT(); }
! void HUMIDITY_MAKE_CLOCK_INPUT() { TOSH_MAKE_I2C_BUS1_SCL_INPUT(); }
! void HUMIDITY_SET_CLOCK() { TOSH_SET_I2C_BUS1_SCL_PIN(); }
! void HUMIDITY_CLEAR_CLOCK() { TOSH_CLR_I2C_BUS1_SCL_PIN(); }
!
! void TOSH_wait_250ns()
! {
! int i;
! for( i=0;i<2; i++)
! {
! asm volatile ("nop" ::);
! }
! }
!
! char calc_crc(char current, char in) {
! return crctable[current ^ in];
! }
!
! /* task void signalHumError() {
! signal HumError.error(errornum);
! }
!
! task void signalTempError() {
! signal TempError.error(errornum);
! }*/
!
! static inline void ack()
! {
! HUMIDITY_MAKE_DATA_OUTPUT();
! HUMIDITY_CLEAR_DATA();
! TOSH_wait_250ns();
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! HUMIDITY_CLEAR_CLOCK();
! HUMIDITY_MAKE_DATA_INPUT();
! HUMIDITY_SET_DATA();
! }
!
! static inline void initseq()
! {
! HUMIDITY_MAKE_DATA_OUTPUT();
! HUMIDITY_SET_DATA();
! HUMIDITY_CLEAR_CLOCK();
! TOSH_wait_250ns();
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! HUMIDITY_CLEAR_DATA();
! TOSH_wait_250ns();
! HUMIDITY_CLEAR_CLOCK();
! TOSH_wait_250ns();
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! HUMIDITY_SET_DATA();
! TOSH_wait_250ns();
! HUMIDITY_CLEAR_CLOCK();
! }
!
! static inline void reset()
! {
! int i;
! HUMIDITY_MAKE_DATA_OUTPUT();
! HUMIDITY_SET_DATA();
! HUMIDITY_CLEAR_CLOCK();
! for (i=0;i<9;i++) {
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! HUMIDITY_CLEAR_CLOCK();
! }
! }
!
! static inline char processCommand(int cmd)
! {
! int i;
! int CMD = cmd;
! cmd &= 0x1f;
! //HUMIDITY_INT_DISABLE();
! reset();
! initseq(); //sending the init sequence
! for(i=0;i<8;i++)
! {
! if(cmd & 0x80)
! HUMIDITY_SET_DATA();
! else
! HUMIDITY_CLEAR_DATA();
! cmd = cmd << 1 ;
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! TOSH_wait_250ns();
! HUMIDITY_CLEAR_CLOCK();
! }
! HUMIDITY_MAKE_DATA_INPUT();
! HUMIDITY_SET_DATA();
! TOSH_wait_250ns();
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! if(HUMIDITY_GET_DATA())
! {
! reset();
! errornum = 2;
! /* if ((CMD == TOSH_HUMIDITY_ADDR) && (humerror == TRUE))
! post signalHumError();
! else if ((CMD == TOSH_HUMIDTEMP_ADDR) && (temperror == TRUE))
! post signalTempError();*/
! return 0;
! }
! TOSH_wait_250ns();
! HUMIDITY_CLEAR_CLOCK();
! if((CMD == TOSH_HUMIDITY_ADDR) || (CMD == TOSH_HUMIDTEMP_ADDR) )
! {
! if ((CMD == TOSH_HUMIDITY_ADDR) && (humerror == TRUE))
! {
! timeout = 0;
! call Timer.start(TIMER_REPEAT, HUMIDITY_TIMEOUT_MS);
! }
! else if ((CMD == TOSH_HUMIDTEMP_ADDR) && (temperror == TRUE))
! {
! timeout = 0;
! call Timer.start(TIMER_REPEAT, HUMIDITY_TIMEOUT_MS);
! }
! TOSH_wait_250ns();
! TM_SetPio(5);
! TM_EnablePIOInt();
! //HUMIDITY_INT_ENABLE();
! }
! return 1;
! }
!
! extern void TM_PIOIsr_ISR() __attribute__ ((C, spontaneous));
!
! command result_t StdControl.init() {
! humerror = FALSE;
! temperror = FALSE;
! state = POWER_OFF;
! TM_RegisterInterrupt(eTM_PIO, (tIntFunc) TM_PIOIsr_ISR, eTM_ProLow);
! return call TimerControl.init();
! }
!
! command result_t StdControl.start() {
! state=READY;
! TM_SetPioAsOutput(5);
! TM_SetPioAsOutput(6);
!
! HUMIDITY_CLEAR_CLOCK();
! HUMIDITY_MAKE_CLOCK_OUTPUT();
! HUMIDITY_SET_DATA();
! HUMIDITY_MAKE_DATA_INPUT();
! //HUMIDITY_INT_DISABLE();
! reset();
! processCommand(TOSH_HUMIDITY_RESET);
! return SUCCESS;
! }
!
! command result_t StdControl.stop() {
! state = POWER_OFF;
! HUMIDITY_CLEAR_CLOCK();
! HUMIDITY_MAKE_CLOCK_INPUT();
! HUMIDITY_MAKE_DATA_INPUT();
! HUMIDITY_CLEAR_DATA();
! TM_DisablePIOInt();
! return SUCCESS;
! }
!
! default async event result_t TempSensor.dataReady(uint16_t tempData)
! {
! return SUCCESS;
! }
!
!
! default async event result_t HumSensor.dataReady(uint16_t humData)
! {
! return SUCCESS;
! }
!
!
! task void readSensor()
! {
! char i;
! char CRC=0;
! uint32_t temp, humidity;
! data=0;
!
!
! //call Timer.stop();
!
! for(i=0;i<8;i++)
! {
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! data |= HUMIDITY_GET_DATA();
! data = data << 1;
! HUMIDITY_CLEAR_CLOCK();
! }
! ack();
! for(i=0;i<8;i++)
! {
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! data |= HUMIDITY_GET_DATA();
! //the last byte of data should not be shifted
! if(i!=7)
! data = data << 1;
! HUMIDITY_CLEAR_CLOCK();
! }
! ack();
! for(i=0;i<8;i++){
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! CRC |= HUMIDITY_GET_DATA();
! if(i!=7)CRC = CRC << 1;
! HUMIDITY_CLEAR_CLOCK();
! }
! // nack with high as it should be for the CRC ack
! HUMIDITY_MAKE_DATA_OUTPUT();
! HUMIDITY_SET_DATA();
! TOSH_wait_250ns();
! HUMIDITY_SET_CLOCK();
! TOSH_wait_250ns();
! HUMIDITY_CLEAR_CLOCK();
!
! /**********
! * initial implementation of CRC calculation
! * commented out for now
! {
! int i;
! char crc = 0;
! char reverse_crc = 0;
!
! // check CRC
! crc = calc_crc(crc,TOSH_HUMIDTEM_ADDR);
! crc = calc_crc(crc,data[0]);
! crc = calc_crc(crc,data[1]);
!
! // reverse the crc bits
! for (i=0; i<8; i++)
! reverse_crc = reverse_crc + (((crc >> i) & 0x01) << (7-i));
!
! // is the crc correct?
! if ((reverse_crc == data[2]) || (crc == data[2])) {
! }
! }
! **/
!
!
! if(state==TEMP_MEASUREMENT){
! // let the PC do the calculation *****
!
! //temp=data;
! //t= (((ftemp) )*0.98-3840)/100;
! //temp= (int16_t) t;
! //if(temp > 100 ) temp=100;
! //if(temp < -40 ) temp=-40;
! temp = (((data>>1) *18) -39280)/1000;
! //signal TempSensor.dataReady( (int16_t)temp);
! signal TempSensor.dataReady((uint16_t)(temp & 0xFF));
! //signal TempSensor.dataReady( 13262);
!
! //signal TempSensor.dataReady(data);
! }
! else if(state==HUM_MEASUREMENT) {
! /* let the PC do the calculation *****
! hum=data;
! h= 0.0405 * (float) (hum) - 4 - (float)(hum) * (float)(hum)*0.0000028;
! h= (t-25) * (0.01 + 0.00128 * hum) + h;
! hum= (int16_t) h;
! if(hum > 100 ) hum=100;
! if(hum < 0 ) hum=0;
! signal HumSensor.dataReady(hum);
! ****/
! humidity = (((data>>1) * (data >>1)) * -28)/10000000;
! humidity += ((data>>1) * 405)/10000;
! humidity -=4;
! // if(humidity > 99)
! // humidity = 99;
! // humidity = data;
! // signal HumSensor.dataReady((uint16_t)(humidity & 0xFF));
! signal HumSensor.dataReady((uint16_t)(humidity));
! }
! state=READY;
! }
!
!
! //#ifndef PLATFORM_PC
! #if 0
! TOSH_SIGNAL(HUMIDITY_INTERRUPT)
! {
! HUMIDITY_INT_DISABLE();
! post readSensor();
! return;
! }
! #endif
!
! //if we get the GPIO interrupt and it's the correct pin, post readSensor();
!
! void TM_PIO_InterruptHdl() __attribute__ ((C, spontaneous))
! {
! TM_DisablePIOInt();
! if( TM_ReadPio(1) == 0)
! {
! //only disable it if we get the one we want...
! //it seems like there's some stale state or somethin
! TM_ResetPio(5);
! post readSensor();
! }
! else
! {
! TM_EnablePIOInt();
! }
! TM_ClearPioInterrupt();
! }
!
! // no such thing
! async command result_t TempSensor.getContinuousData() {
! return FAIL;
! }
!
! // no such thing
! async command result_t HumSensor.getContinuousData() {
! return FAIL;
! }
!
! async command result_t TempSensor.getData()
! {
! if(state!= READY ){
! reset();
! }
! state=TEMP_MEASUREMENT;
! processCommand(TOSH_HUMIDTEMP_ADDR);
! return SUCCESS;
! }
!
! async command result_t HumSensor.getData()
! {
! if(state!= READY ){
! reset();
! }
! state=HUM_MEASUREMENT;
! processCommand(TOSH_HUMIDITY_ADDR);
! return SUCCESS;
! }
!
!
! /* command result_t HumError.enable() {
! if (humerror == FALSE) {
! //atomic humerror = TRUE;
! humerror = TRUE;
! return SUCCESS;
! }
! return FAIL;
! }
!
! command result_t TempError.enable() {
! if (temperror == FALSE) {
! //atomic temperror = TRUE;
! temperror = TRUE;
! return SUCCESS;
! }
! return FAIL;
! }
!
! command result_t HumError.disable() {
! if (humerror == TRUE) {
! //atomic humerror = FALSE;
! humerror = FALSE;
! return SUCCESS;
! }
! return FAIL;
! }
!
! command result_t TempError.disable() {
! if (temperror == TRUE) {
! // atomic temperror = FALSE;
! temperror = FALSE;
! return SUCCESS;
! }
! return FAIL;
! }*/
!
! event result_t Timer.fired() {
! timeout++;
! if (timeout > HUMIDITY_TIMEOUT_TRIES) {
! if ((state == HUM_MEASUREMENT) && (humerror == TRUE)) {
! call Timer.stop();
! //HUMIDITY_INT_DISABLE();
! state = READY;
! errornum = 1;
! // post signalHumError();
! }
! else if ((state == TEMP_MEASUREMENT) && (temperror == TRUE)) {
! call Timer.stop();
! //HUMIDITY_INT_DISABLE();
! state = READY;
! errornum = 1;
! // post signalTempError();
! }
! }
! return SUCCESS;
! }
!
!
! /* default event result_t HumError.error(uint8_t token) { return SUCCESS; }
!
! default event result_t TempError.error(uint8_t token) { return SUCCESS; }*/
!
! }
Index: TimerM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/TimerM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** TimerM.nc 16 Aug 2004 18:14:06 -0000 1.1
--- TimerM.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 46,51 ****
provides interface StdControl;
uses {
! interface Leds;
! interface Clock;
interface PowerManagement;
}
--- 46,50 ----
provides interface StdControl;
uses {
! interface Clock;
interface PowerManagement;
}
***************
*** 53,59 ****
implementation {
uint32_t mState; // each bit represent a timer state
uint8_t setIntervalFlag;
! uint8_t mScale, mInterval;
int8_t queue_head;
int8_t queue_tail;
--- 52,64 ----
implementation {
+
+ #include "./NewTimer.h"
+
+
uint32_t mState; // each bit represent a timer state
uint8_t setIntervalFlag;
! uint8_t mScale;
! uint32_t mInterval;
! uint8_t mInit=FALSE;
int8_t queue_head;
int8_t queue_tail;
***************
*** 68,73 ****
enum {
! maxTimerInterval = 230
! };
command result_t StdControl.init() {
mState=0;
--- 73,83 ----
enum {
! #ifdef USE_NEW_TIMER
! maxTimerInterval = 2047 //65536/32 - 1
! #else
! maxTimerInterval = 230
! #endif
!
! };
command result_t StdControl.init() {
mState=0;
***************
*** 78,81 ****
--- 88,92 ----
mInterval = maxTimerInterval;
return call Clock.setRate(mInterval, mScale) ;
+ //return call Clock.setRate(0, mScale) ;
}
***************
*** 85,91 ****
--- 96,104 ----
command result_t StdControl.stop() {
+ #if 0
mState=0;
mInterval = maxTimerInterval;
setIntervalFlag = 0;
+ #endif
return SUCCESS;
}
***************
*** 93,97 ****
command result_t Timer.start[uint8_t id](char type,
uint32_t interval) {
! uint8_t diff;
if (id >= NUM_TIMERS) return FAIL;
if (type>1) return FAIL;
--- 106,110 ----
command result_t Timer.start[uint8_t id](char type,
uint32_t interval) {
! uint32_t diff;
if (id >= NUM_TIMERS) return FAIL;
if (type>1) return FAIL;
***************
*** 104,108 ****
mTimerList[id].ticksLeft = interval;
mState|=(0x1<<id);
! if (interval < mInterval) {
mInterval=interval;
call Clock.setInterval(mInterval);
--- 117,121 ----
mTimerList[id].ticksLeft = interval;
mState|=(0x1<<id);
! if (interval <= mInterval) {
mInterval=interval;
call Clock.setInterval(mInterval);
***************
*** 110,119 ****
call PowerManagement.adjustPower();
}
! }
return SUCCESS;
}
static void adjustInterval() {
! uint8_t i, val = maxTimerInterval;
if ( mState) {
for (i=0;i<NUM_TIMERS;i++) {
--- 123,140 ----
call PowerManagement.adjustPower();
}
! else if (!mInit){
! mInterval=maxTimerInterval;
! call Clock.setInterval(mInterval);
! setIntervalFlag = 0;
! call PowerManagement.adjustPower();
! }
! mInit=TRUE;
! }
return SUCCESS;
}
static void adjustInterval() {
! uint8_t i;
! uint32_t val = maxTimerInterval;
if ( mState) {
for (i=0;i<NUM_TIMERS;i++) {
Index: TreeRoutingM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/TreeRoutingM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TreeRoutingM.nc 16 Aug 2004 18:14:06 -0000 1.2
--- TreeRoutingM.nc 6 Sep 2005 08:27:59 -0000 1.3
***************
*** 1,34 ****
/*
- * Copyright (c) 2004, Intel Corporation
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * Neither the name of the Intel Corporation nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
- /*
* This component recursively sends route requests and the corresponding replies
* to maintain a tree routing table. A route broadcast is generated under
--- 1,3 ----
***************
*** 76,79 ****
--- 45,49 ----
interface NetworkTopology;
interface LowPower;
+ interface StatsLogger;
command result_t NetworkDiscoveryActive(bool DiscoveryActive);
***************
*** 86,96 ****
{
! //#define TREE_ROUTING_DEBUG
!
! #ifdef TREE_ROUTING_DEBUG
! void DisplayStr(char *str) __attribute__ ((C, spontaneous));
! #else
! #define DisplayStr(str)
! #endif
enum {ROUTING_QUERY_ADJACENT_NODES = 1,
--- 56,60 ----
{
! #define TRACE_DEBUG_LEVEL DBG_USR2
enum {ROUTING_QUERY_ADJACENT_NODES = 1,
***************
*** 99,104 ****
--- 63,78 ----
ROUTING_INVALIDATE_ROUTE};
+ //#define ROUTE_BEACON_INTERVAL 120000 // 12s period for sending route requests
+ //#define LOW_POWER_BEACON_INTERVAL 300000 // in low power, period = 60 seconds
+
+ #if 0 // LN : slower beacons & resets
#define ROUTE_BEACON_INTERVAL 12000 // 12s period for sending route requests
#define LOW_POWER_BEACON_INTERVAL 60000 // in low power, period = 60 seconds
+ #else
+ #define ROUTE_BEACON_INTERVAL 60000 // 12s period for sending route requests
+ #define LOW_POWER_BEACON_INTERVAL 120000 // in low power, period = 60 seconds
+
+ #endif
+
#define MAX_CONNECTIONS 12
#define MAX_QUEUED_MESSAGES 10
***************
*** 349,358 ****
InvalidateRoute(OtherNodeID, INVALID_NODE);
- {
- char str[80];
- sprintf(str, "Removing route to %05X\n\r", OtherNodeID);
- DisplayStr(str);
- }
return (call NetworkTopology.RemoveRoute(OtherNodeID));
}
--- 323,329 ----
InvalidateRoute(OtherNodeID, INVALID_NODE);
+
+ trace(TRACE_DEBUG_LEVEL,"Removing route to %05X\n\r", OtherNodeID);
return (call NetworkTopology.RemoveRoute(OtherNodeID));
}
***************
*** 367,370 ****
--- 338,342 ----
call NetworkPacket.ReleaseBuffer( data );
+ call StatsLogger.BumpCounter(NUM_ROUTING_SEND, 1);
return SUCCESS;
***************
*** 427,430 ****
--- 399,404 ----
tRoutingMessage *Message;
+ call StatsLogger.BumpCounter(NUM_ROUTING_RECV, 1);
+
TimeSinceLastMessage = 0; // reset counter for any received message
***************
*** 454,474 ****
break;
! case ROUTING_INVALIDATE_ROUTE:
! {
! char str[80];
! sprintf(str, "Got invalidate route from %05X for %05X\n\r", Source, t[1]);
! DisplayStr(str);
! }
if (call NetworkTopology.GetNextConnection(t[1], &RTNextNode, NULL)
== SUCCESS) {
if (RTNextNode == Source) {
! // the route through Source to t[1] is invalid
! {
! char str[80];
! sprintf(str, "Removing route to %05X\n\r", t[1]);
! DisplayStr(str);
! }
! call NetworkTopology.RemoveRoute(t[1]);
! InvalidateRoute(t[1], Source);
}
}
--- 428,441 ----
break;
! case ROUTING_INVALIDATE_ROUTE:
! trace(TRACE_DEBUG_LEVEL,"Got invalidate route from %05X for %05X\n\r", Source, t[1]);
!
if (call NetworkTopology.GetNextConnection(t[1], &RTNextNode, NULL)
== SUCCESS) {
if (RTNextNode == Source) {
! // the route through Source to t[1] is invalid
! trace(TRACE_DEBUG_LEVEL,"Removing route to %05X\n\r", t[1]);
! call NetworkTopology.RemoveRoute(t[1]);
! InvalidateRoute(t[1], Source);
}
}
***************
*** 555,563 ****
TimeSinceLastMessage = 0;
} else {
! {
! char str[80];
! sprintf(str, "Tree Routing : Resetting\n\r");
! DisplayStr(str);
! }
call WDTControl.AllowForceReset();
}
--- 522,527 ----
TimeSinceLastMessage = 0;
} else {
! trace(TRACE_DEBUG_LEVEL,"Tree Routing : Resetting\n\r");
!
call WDTControl.AllowForceReset();
}
Index: UARTBufferM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/UARTBufferM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** UARTBufferM.nc 16 Aug 2004 18:14:06 -0000 1.2
--- UARTBufferM.nc 6 Sep 2005 08:27:59 -0000 1.3
***************
*** 1,31 ****
! /*
! * Copyright (c) 2004, Intel Corporation
! * All rights reserved.
*
! * Redistribution and use in source and binary forms, with or without
! * modification, are permitted provided that the following conditions are met:
*
! * Redistributions of source code must retain the above copyright notice,
! * this list of conditions and the following disclaimer.
*
! * Redistributions in binary form must reproduce the above copyright notice,
! * this list of conditions and the following disclaimer in the documentation
! * and/or other materials provided with the distribution.
*
- * Neither the name of the Intel Corporation nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
*/
--- 1,38 ----
! /* tab:4
! * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
! * downloading, copying, installing or using the software you agree to
! * this license. If you do not agree to this license, do not download,
! * install, copy or use the software.
*
! * Intel Open Source License
*
! * Copyright (c) 2002 Intel Corporation
! * All rights reserved.
! * Redistribution and use in source and binary forms, with or without
! * modification, are permitted provided that the following conditions are
! * met:
*
! * Redistributions of source code must retain the above copyright
! * notice, this list of conditions and the following disclaimer.
! * Redistributions in binary form must reproduce the above copyright
! * notice, this list of conditions and the following disclaimer in the
! * documentation and/or other materials provided with the distribution.
! * Neither the name of the Intel Corporation nor the names of its
! * contributors may be used to endorse or promote products derived from
! * this software without specific prior written permission.
! *
! * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
! * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
! * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
! * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
! * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
! * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
! * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
! * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
! * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
! * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
! * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
***************
*** 69,76 ****
command result_t Control.init() {
atomic {
! Head = 0;
! Tail = 0;
! BytePending = FALSE;
}
--- 76,83 ----
command result_t Control.init() {
+ Head = 0;
+ Tail = 0;
atomic {
! BytePending = FALSE;
}
***************
*** 93,99 ****
result_t SendNextByte() {
! bool busy, done;
! char c;
!
atomic {
busy = (BytePending == TRUE);
--- 100,104 ----
result_t SendNextByte() {
! bool busy;
atomic {
busy = (BytePending == TRUE);
***************
*** 103,115 ****
}
! atomic done = (Head == Tail); // buffer is empty
! if (done) return SUCCESS; // buffer is empty
atomic {
BytePending = TRUE;
- c = Buffer[Tail];
}
! call ByteComm.txByte(c);
// if (call ByteComm.txByte(Buffer[Tail]) == FAIL) {
// // UART not enabled
--- 108,118 ----
}
! if (Head == Tail) return SUCCESS; // buffer is empty
atomic {
BytePending = TRUE;
}
! call ByteComm.txByte(Buffer[Tail]);
// if (call ByteComm.txByte(Buffer[Tail]) == FAIL) {
// // UART not enabled
***************
*** 130,142 ****
// see if there's enough room for this packet
! atomic size = (Head < Tail) ? Head + BUFFER_SIZE - Tail : Head - Tail;
if (size + length >= BUFFER_SIZE) return FAIL; // not enough room
// copy incoming bytes to the buffer
! atomic {
! for (i = 0; i < length; i++) {
! Buffer[Head] = data[i];
! Head = NEXT_BUFFER(Head, BUFFER_SIZE);
! }
}
--- 133,143 ----
// see if there's enough room for this packet
! size = (Head < Tail) ? Head + BUFFER_SIZE - Tail : Head - Tail;
if (size + length >= BUFFER_SIZE) return FAIL; // not enough room
// copy incoming bytes to the buffer
! for (i = 0; i < length; i++) {
! Buffer[Head] = data[i];
! Head = NEXT_BUFFER(Head, BUFFER_SIZE);
}
***************
*** 165,176 ****
async event result_t ByteComm.txByteReady(bool success) {
- bool done;
atomic {
BytePending = FALSE;
}
! atomic done = (Head == Tail);
! if (done) return SUCCESS;
! atomic Tail = NEXT_BUFFER(Tail, BUFFER_SIZE);
SendNextByte();
--- 166,175 ----
async event result_t ByteComm.txByteReady(bool success) {
atomic {
BytePending = FALSE;
}
! if (Head == Tail) return SUCCESS;
! Tail = NEXT_BUFFER(Tail, BUFFER_SIZE);
SendNextByte();
Index: WDTControlM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote/WDTControlM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** WDTControlM.nc 29 Jun 2004 14:56:14 -0000 1.1
--- WDTControlM.nc 6 Sep 2005 08:27:59 -0000 1.2
***************
*** 29,33 ****
* POSSIBILITY OF SUCH DAMAGE.
*/
-
/*
* This module manages the WatchDogTimer .
--- 29,32 ----
***************
*** 54,63 ****
int ForceReset;
! //#define WD_DEBUG
! #ifdef WD_DEBUG
! void DisplayStr(char *str) __attribute__ ((C, spontaneous));
! #else
! #define DisplayStr(str)
! #endif
bool TaskFlag; // Whether the task context has been entered since the last
--- 53,57 ----
int ForceReset;
! #define TRACE_DEBUG_LEVEL 0ULL
bool TaskFlag; // Whether the task context has been entered since the last
***************
*** 86,89 ****
--- 80,84 ----
command result_t StdControl.start() {
+ TM_SetWdTmrEnable();
//debugging - VEH
#if 0
***************
*** 118,122 ****
if (TaskFlag == FALSE) {
! DisplayStr("Task context skipped for 1 sec\n");
}
TaskFlag = FALSE;
--- 113,117 ----
if (TaskFlag == FALSE) {
! trace(TRACE_DEBUG_LEVEL,"Task context skipped for 1 sec\n");
}
TaskFlag = FALSE;
- Previous message: [Tinyos-beta-commits]
CVS: tinyos-1.x/beta/platform/imote/zeevo1.2/ChipBase/Common
Config.h, 1.1, 1.2 ZvDynamicScript.sp, 1.1, 1.2
- Next message: [Tinyos-beta-commits] CVS: tinyos-1.x/beta/platform/pxa27x
PXA27XHPLDMAM.nc, 1.1, 1.2 PXA27XHPLDMA.nc, 1.1,
1.2 PXA27XDMAM.nc, 1.2, 1.3 PXA27XDMAChannel.nc, 1.2, 1.3
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-beta-commits
mailing list