[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/byte_radio manchester.h,
NONE, 1.1.2.1 UartPhyC.nc, NONE, 1.1.2.1 LinkLayerP.nc,
1.1.2.1, 1.1.2.2 PacketSerializerP.nc, 1.1.2.5, 1.1.2.6
Philipp Huppertz
phihup at users.sourceforge.net
Wed Jun 7 12:54:55 PDT 2006
Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/byte_radio
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv11812/tos/lib/byte_radio
Modified Files:
Tag: tinyos-2_0_devel-BRANCH
LinkLayerP.nc PacketSerializerP.nc
Added Files:
Tag: tinyos-2_0_devel-BRANCH
manchester.h UartPhyC.nc
Log Message:
- should compile again...
--- NEW FILE: manchester.h ---
/* -*- mode:c++; indent-tabs-mode: nil -*-
* Copyright (c) 2006, Technische Universitaet Berlin
* 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 Technische Universitaet Berlin 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.
*
* - Description ---------------------------------------------------------
* provide functions to encode/decode a manchester stream
* - Revision -------------------------------------------------------------
* $Revision: 1.1.2.1 $
* $Date: 2006/06/07 19:54:53 $
* @author Andreas Koepke <koepke at tkn.tu-berlin.de>
* ========================================================================
*/
const uint8_t nibbleToManchesterByte[] = {
0x55,
0x56,
0x59,
0x5a,
0x65,
0x66,
0x69,
0x6a,
0x95,
0x96,
0x99,
0x9a,
0xa5,
0xa6,
0xa9,
0xaa
};
const uint8_t manchesterByteToNibble[] = {
0x0,
0x1,
0xff,
0xff,
0x2,
0x3,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0x4,
0x5,
0xff,
0xff,
0x6,
0x7,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0x8,
0x9,
0xff,
0xff,
0xa,
0xb,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xff,
0xc,
0xd,
0xff,
0xff,
0xe,
0xf
};
uint8_t manchesterEncodeNibble(uint8_t nib)
{
return nibbleToManchesterByte[nib];
}
uint8_t manchesterDecodeByte(uint8_t b)
{
uint8_t dec;
if(b < 0x55) {
dec = 0xff;
}
else if(b > 0xaa) {
dec = 0xff;
}
else {
dec = manchesterByteToNibble[b - 0x55];
}
return dec;
}
--- NEW FILE: UartPhyC.nc ---
/*
* Copyright (c) 2006, Technische Universitaet Berlin
* 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 Technische Universitaet Berlin 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.
*
* - Description ---------------------------------------------------------
*
* - Revision -------------------------------------------------------------
* $Revision: 1.1.2.1 $
* $Date: 2006/06/07 19:54:53 $
* @author: Philipp Huppertz <huppertz at tkn.tu-berlin.de>
* ========================================================================
*/
/**
* UartPhyC
*
* @author Philipp Huppertz <huppertz at tkn.tu-berlin.de>
*/
configuration UartPhyC
{
provides{
interface Init;
interface PhyPacketTx;
interface RadioByteComm as SerializerRadioByteComm;
interface PhyPacketRx;
interface UartPhyControl;
}
uses {
interface RadioByteComm;
}
}
implementation
{
components
new Alarm32khzC() as RxByteTimer,
UartPhyP;
Init = UartPhyP;
PhyPacketRx = UartPhyP;
SerializerRadioByteComm = UartPhyP;
RadioByteComm = UartPhyP;
PhyPacketTx = UartPhyP;
UartPhyControl = UartPhyP;
UartPhyP.RxByteTimer -> RxByteTimer;
}
Index: LinkLayerP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/byte_radio/Attic/LinkLayerP.nc,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** LinkLayerP.nc 31 May 2006 13:53:02 -0000 1.1.2.1
--- LinkLayerP.nc 7 Jun 2006 19:54:53 -0000 1.1.2.2
***************
*** 80,83 ****
--- 80,84 ----
/* state vars */
error_t splitStateError; // state of SplitControl interfaces
+ bool recvBlock; // blocks an incoming packet if the rxBuffer is in use
// #define LLCM_DEBUG
***************
*** 100,103 ****
--- 101,105 ----
seqNo = 0;
splitStateError = EOFF;
+ recvBlock = FALSE;
}
return SUCCESS;
***************
*** 208,224 ****
void *payload;
uint8_t len;
atomic {
len = call Packet.payloadLength(rxBufPtr);
payload = call Packet.getPayload(rxBufPtr, &len);
! signal Receive.receive(rxBufPtr, payload , len);
}
}
async event message_t* ReceiveLower.receiveDone(message_t* msg) {
atomic {
! rxBufPtr = msg;
! }
! post ReceiveTask();
! return &rxBuf;
}
--- 210,239 ----
void *payload;
uint8_t len;
+ message_t* tmpMsgPtr;
atomic {
len = call Packet.payloadLength(rxBufPtr);
payload = call Packet.getPayload(rxBufPtr, &len);
! tmpMsgPtr = rxBufPtr;
! }
! tmpMsgPtr = signal Receive.receive(tmpMsgPtr, payload , len);
! atomic {
! rxBufPtr = tmpMsgPtr;
! recvBlock = FALSE;
}
}
async event message_t* ReceiveLower.receiveDone(message_t* msg) {
+ message_t* msgPtr;
atomic {
! if (recvBlock) {
! msgPtr = msg;
! } else {
! recvBlock = TRUE;
! msgPtr = rxBufPtr;
! rxBufPtr = msg;
! post ReceiveTask();
! }
! }
! return msgPtr;
}
***************
*** 255,263 ****
return FALSE;
}
-
-
-
-
-
}
--- 270,273 ----
Index: PacketSerializerP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/byte_radio/Attic/PacketSerializerP.nc,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -C2 -d -r1.1.2.5 -r1.1.2.6
*** PacketSerializerP.nc 31 May 2006 13:53:03 -0000 1.1.2.5
--- PacketSerializerP.nc 7 Jun 2006 19:54:53 -0000 1.1.2.6
***************
*** 1,3 ****
! /*
* Copyright (c) 2004, Technische Universitaet Berlin
* All rights reserved.
--- 1,3 ----
! /* -*- mode:c++; indent-tabs-mode: nil -*-
* Copyright (c) 2004, Technische Universitaet Berlin
* All rights reserved.
***************
*** 60,77 ****
implementation {
/* Module Global Variables */
- typedef enum {
- STATE_CRC1,
- STATE_CRC2,
- STATE_CRC_DONE,
- } crcState_t;
! message_t *txBufPtr; // pointer to tx buffer
! message_t *rxBufPtr; // pointer to rx buffer
message_t rxMsg; // rx message buffer
- uint16_t pSize;
- uint16_t byteCnt; // index into current datapacket
uint16_t crc; // CRC value of either the current incoming or outgoing packet
! crcState_t crcState; // CRC state
!
/* Local Function Declarations */
void TransmitNextByte();
--- 60,70 ----
implementation {
/* Module Global Variables */
! message_t *txBufPtr; // pointer to tx buffer
! message_t *rxBufPtr; // pointer to rx buffer
message_t rxMsg; // rx message buffer
uint16_t crc; // CRC value of either the current incoming or outgoing packet
! uint8_t byteCnt; // index into current datapacket
!
/* Local Function Declarations */
void TransmitNextByte();
***************
*** 86,90 ****
rxBufPtr = &rxMsg;
byteCnt = 0;
- pSize = 0;
}
return SUCCESS;
--- 79,82 ----
***************
*** 119,147 ****
void TransmitNextByte() {
- crcState_t state;
message_radio_header_t* header = getHeader((message_t*) txBufPtr);
if (byteCnt < header->length + sizeof(message_header_t) ) { // send (data + header), compute crc
- atomic {
- crcState = STATE_CRC1;
crc = crcByte(crc, ((uint8_t *)(txBufPtr))[byteCnt]);
! }
! call RadioByteComm.txByte(((uint8_t *)(txBufPtr))[byteCnt++]);
! } else { // send crc
! atomic state = crcState;
! switch(state) {
! case STATE_CRC1:
! atomic crcState = STATE_CRC2;
! call RadioByteComm.txByte((uint8_t)(crc >> 8));
! break;
! case STATE_CRC2:
! atomic crcState = STATE_CRC_DONE;
! call RadioByteComm.txByte((uint8_t)(crc));
! break;
! case STATE_CRC_DONE:
call PhyPacketTx.sendFooter();
- break;
- default:
- break;
- }
}
}
--- 111,126 ----
void TransmitNextByte() {
message_radio_header_t* header = getHeader((message_t*) txBufPtr);
if (byteCnt < header->length + sizeof(message_header_t) ) { // send (data + header), compute crc
crc = crcByte(crc, ((uint8_t *)(txBufPtr))[byteCnt]);
! call RadioByteComm.txByte(((uint8_t *)(txBufPtr))[byteCnt++]);
! } else if (byteCnt == (header->length + sizeof(message_header_t))) {
! ++byteCnt;
! call RadioByteComm.txByte((uint8_t)crc);
! } else if (byteCnt == (header->length + sizeof(message_header_t)+1)) {
! ++byteCnt;
! call RadioByteComm.txByte((uint8_t)(crc >> 8));
! } else { // (byteCnt > (header->length + sizeof(message_header_t)+1))
call PhyPacketTx.sendFooter();
}
}
***************
*** 151,158 ****
}
! /* Radio Receive */
async event void PhyPacketRx.recvHeaderDone(error_t error) {
! if (error == SUCCESS) {
byteCnt = (sizeof(message_header_t) - sizeof(message_radio_header_t));
getHeader(rxBufPtr)->length = sizeof(message_radio_header_t);
signal PhyReceive.receiveDetected();
--- 130,138 ----
}
! /* Radio Receive */
async event void PhyPacketRx.recvHeaderDone(error_t error) {
! if(error == SUCCESS) {
byteCnt = (sizeof(message_header_t) - sizeof(message_radio_header_t));
+ crc = 0;
getHeader(rxBufPtr)->length = sizeof(message_radio_header_t);
signal PhyReceive.receiveDetected();
***************
*** 167,170 ****
--- 147,153 ----
async event void PhyPacketRx.recvFooterDone(error_t error) {
message_radio_header_t* header = getHeader((message_t*)(rxBufPtr));
+ message_radio_footer_t* footer = getFooter((message_t*)rxBufPtr);
+ // we care about wrong crc in this layer
+ if (footer->crc == 0) error = FAIL;
rxBufPtr = signal PhyReceive.receiveDone((message_t*)rxBufPtr, ((message_t*)rxBufPtr)->data, header->length, error);
}
***************
*** 172,185 ****
/* Receive the next Byte from the USART */
void ReceiveNextByte(uint8_t data) {
((uint8_t *)(rxBufPtr))[byteCnt++] = data;
! pSize = getHeader(rxBufPtr)->length + sizeof(message_radio_header_t);
! if ( byteCnt < pSize ) {
crc = crcByte(crc, data);
if (getHeader(rxBufPtr)->length > TOSH_DATA_LENGTH) {
! getHeader(rxBufPtr)->length = TOSH_DATA_LENGTH; // this packet is surely corrupt
}
! } else if ( byteCnt == (getHeader(rxBufPtr)->length + sizeof(message_radio_header_t) + sizeof(message_radio_footer_t)) ) {
! message_radio_footer_t* footer = getFooter((message_t*)rxBufPtr);
! // we don't care about wrong crc in this layer
footer->crc = (footer->crc == crc);
call PhyPacketRx.recvFooter();
--- 155,171 ----
/* Receive the next Byte from the USART */
void ReceiveNextByte(uint8_t data) {
+ message_radio_footer_t* footer = getFooter((message_t*)rxBufPtr);
((uint8_t *)(rxBufPtr))[byteCnt++] = data;
! if ( byteCnt < getHeader(rxBufPtr)->length + sizeof(message_radio_header_t) ) {
crc = crcByte(crc, data);
if (getHeader(rxBufPtr)->length > TOSH_DATA_LENGTH) {
! // this packet is surely corrupt, so whatever...
! footer->crc = 0;
! call PhyPacketRx.recvFooter();
}
! } else if (byteCnt == (getHeader(rxBufPtr)->length + sizeof(message_radio_header_t))) {
! crc = crcByte(crc, data);
! byteCnt = offsetof(message_t, footer) + offsetof(message_radio_footer_t, crc);
! } else if (byteCnt == (offsetof(message_t, footer) + sizeof(message_radio_footer_t))) {
footer->crc = (footer->crc == crc);
call PhyPacketRx.recvFooter();
More information about the Tinyos-2-commits
mailing list