- Replaced TR1001 statistics with rimestats
- Fixed typo in constant name - Changed all occurences of u8_t and u16_t to uint8_t and uint16_t
This commit is contained in:
parent
6e657ad3d8
commit
8db3671d65
3 changed files with 56 additions and 289 deletions
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* @(#)$Id: tr1001-gcr.c,v 1.12 2007/11/28 21:28:03 nifi Exp $
|
* @(#)$Id: tr1001-gcr.c,v 1.13 2008/07/08 12:27:22 nifi Exp $
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* \addtogroup esb
|
* \addtogroup esb
|
||||||
|
@ -56,27 +56,19 @@
|
||||||
#include "dev/radio-sensor.h"
|
#include "dev/radio-sensor.h"
|
||||||
#include "lib/gcr.h"
|
#include "lib/gcr.h"
|
||||||
#include "lib/crc16.h"
|
#include "lib/crc16.h"
|
||||||
|
#include "net/rime/rimestats.h"
|
||||||
|
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define RXSTATE_READY 0
|
#define RXSTATE_READY 0
|
||||||
#define RXSTATE_RECEVING 1
|
#define RXSTATE_RECEIVING 1
|
||||||
#define RXSTATE_FULL 2
|
#define RXSTATE_FULL 2
|
||||||
|
|
||||||
#define SYNCH1 0x3c
|
#define SYNCH1 0x3c
|
||||||
#define SYNCH2 0x03
|
#define SYNCH2 0x03
|
||||||
|
|
||||||
#if TR1001_STATISTICS
|
|
||||||
static unsigned short sstrength_dropped,
|
|
||||||
sstrength_max, sstrength_min, tmp_sstrength_max, tmp_sstrength_min;
|
|
||||||
/* The number of dropped packets */
|
|
||||||
static unsigned short packets_err;
|
|
||||||
/* The number of accepted packets */
|
|
||||||
static unsigned short packets_ok;
|
|
||||||
#endif /* TR1001_STATISTICS */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The buffer which holds incoming data.
|
* The buffer which holds incoming data.
|
||||||
*/
|
*/
|
||||||
|
@ -93,15 +85,13 @@ static unsigned short tr1001_rxlen = 0;
|
||||||
*/
|
*/
|
||||||
volatile unsigned char tr1001_rxstate = RXSTATE_READY;
|
volatile unsigned char tr1001_rxstate = RXSTATE_READY;
|
||||||
|
|
||||||
static u8_t radio_active;
|
static uint16_t rxcrc, rxcrctmp;
|
||||||
|
|
||||||
static u16_t rxcrc, rxcrctmp;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The structure of the packet header.
|
* The structure of the packet header.
|
||||||
*/
|
*/
|
||||||
struct tr1001_hdr {
|
struct tr1001_hdr {
|
||||||
u8_t len[2]; /**< The 16-bit length of the packet in network byte
|
uint8_t len[2]; /**< The 16-bit length of the packet in network byte
|
||||||
order. */
|
order. */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -112,7 +102,7 @@ struct tr1001_hdr {
|
||||||
|
|
||||||
#define OFF 0
|
#define OFF 0
|
||||||
#define ON 1
|
#define ON 1
|
||||||
static u8_t onoroff = OFF;
|
static uint8_t onoroff = OFF;
|
||||||
|
|
||||||
#define NUM_SYNCHBYTES 4
|
#define NUM_SYNCHBYTES 4
|
||||||
|
|
||||||
|
@ -160,23 +150,6 @@ const struct radio_driver tr1001_driver = {
|
||||||
tr1001_off
|
tr1001_off
|
||||||
};
|
};
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#if TR1001_STATISTICS
|
|
||||||
#define PACKET_DROPPED() do { \
|
|
||||||
if(packets_err < ~0) {\
|
|
||||||
packets_err++;\
|
|
||||||
}\
|
|
||||||
sstrength_dropped = (tmp_count ? ((tmp_sstrength / tmp_count) << 2) : 0);\
|
|
||||||
} while(0)
|
|
||||||
#define PACKET_ACCEPTED() do {\
|
|
||||||
if(packets_ok < ~0) {\
|
|
||||||
packets_ok++;\
|
|
||||||
}\
|
|
||||||
} while(0);
|
|
||||||
#else
|
|
||||||
#define PACKET_DROPPED()
|
|
||||||
#define PACKET_ACCEPTED()
|
|
||||||
#endif /* TR1001_STATISTICS */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/*
|
/*
|
||||||
* Turn on data transmission in On-Off-Keyed mode.
|
* Turn on data transmission in On-Off-Keyed mode.
|
||||||
|
@ -297,25 +270,6 @@ send(unsigned char b)
|
||||||
*
|
*
|
||||||
* \param b The byte to be sent.
|
* \param b The byte to be sent.
|
||||||
*/
|
*/
|
||||||
/* static void */
|
|
||||||
/* send2(unsigned char b) */
|
|
||||||
/* { */
|
|
||||||
/* u16_t m; */
|
|
||||||
/* m = me_encode(b); */
|
|
||||||
/* send(m >> 8); */
|
|
||||||
/* send(m & 0xff); */
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
/* static u16_t */
|
|
||||||
/* send2_crc16(unsigned char b, u16_t crcacc) */
|
|
||||||
/* { */
|
|
||||||
/* u16_t m; */
|
|
||||||
/* m = me_encode(b); */
|
|
||||||
/* send(m >> 8); */
|
|
||||||
/* send(m & 0xff); */
|
|
||||||
/* return crc16_add(b, crcacc); */
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sendx(unsigned char b)
|
sendx(unsigned char b)
|
||||||
{
|
{
|
||||||
|
@ -328,8 +282,8 @@ sendx(unsigned char b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static u16_t
|
static uint16_t
|
||||||
sendx_crc16(unsigned char b, u16_t crcacc)
|
sendx_crc16(unsigned char b, uint16_t crcacc)
|
||||||
{
|
{
|
||||||
gcr_encode(b);
|
gcr_encode(b);
|
||||||
GCRLOG("(%02x)", b);
|
GCRLOG("(%02x)", b);
|
||||||
|
@ -341,7 +295,6 @@ sendx_crc16(unsigned char b, u16_t crcacc)
|
||||||
return crcacc;
|
return crcacc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
tr1001_set_txpower(unsigned char p)
|
tr1001_set_txpower(unsigned char p)
|
||||||
|
@ -380,16 +333,10 @@ tr1001_set_receiver(void (* recv)(const struct radio_driver *))
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
tr1001_init()
|
tr1001_init(void)
|
||||||
{
|
{
|
||||||
PT_INIT(&rxhandler_pt);
|
PT_INIT(&rxhandler_pt);
|
||||||
|
|
||||||
#if TR1001_STATISTICS
|
|
||||||
packets_ok = packets_err = 0;
|
|
||||||
sstrength_dropped = 0;
|
|
||||||
sstrength_min = 0xFFFF;
|
|
||||||
sstrength_max = 0;
|
|
||||||
#endif /* TR1001_STATISTICS */
|
|
||||||
onoroff = OFF;
|
onoroff = OFF;
|
||||||
|
|
||||||
UCTL0 = CHAR; /* 8-bit character */
|
UCTL0 = CHAR; /* 8-bit character */
|
||||||
|
@ -444,16 +391,10 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
|
|
||||||
timer_restart(&rxtimer);
|
timer_restart(&rxtimer);
|
||||||
|
|
||||||
if(tr1001_rxstate == RXSTATE_RECEVING) {
|
if(tr1001_rxstate == RXSTATE_RECEIVING) {
|
||||||
unsigned short signal = radio_sensor.value(0);;
|
unsigned short signal = radio_sensor.value(0);
|
||||||
tmp_sstrength += (signal >> 2);
|
tmp_sstrength += (signal >> 2);
|
||||||
tmp_count++;
|
tmp_count++;
|
||||||
if(signal < tmp_sstrength_min) {
|
|
||||||
tmp_sstrength_min = signal;
|
|
||||||
}
|
|
||||||
if(signal > tmp_sstrength_max) {
|
|
||||||
tmp_sstrength_max = signal;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PT_BEGIN(&rxhandler_pt);
|
PT_BEGIN(&rxhandler_pt);
|
||||||
|
@ -466,7 +407,7 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
/* Wait until we receive the first syncronization byte. */
|
/* Wait until we receive the first syncronization byte. */
|
||||||
PT_WAIT_UNTIL(&rxhandler_pt, incoming_byte == SYNCH1);
|
PT_WAIT_UNTIL(&rxhandler_pt, incoming_byte == SYNCH1);
|
||||||
|
|
||||||
tr1001_rxstate = RXSTATE_RECEVING;
|
tr1001_rxstate = RXSTATE_RECEIVING;
|
||||||
|
|
||||||
/* Read all incoming syncronization bytes. */
|
/* Read all incoming syncronization bytes. */
|
||||||
PT_WAIT_WHILE(&rxhandler_pt, incoming_byte == SYNCH1);
|
PT_WAIT_WHILE(&rxhandler_pt, incoming_byte == SYNCH1);
|
||||||
|
@ -480,8 +421,6 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
/* Start signal strength measurement */
|
/* Start signal strength measurement */
|
||||||
tmp_sstrength = 0;
|
tmp_sstrength = 0;
|
||||||
tmp_count = 0;
|
tmp_count = 0;
|
||||||
tmp_sstrength_max = 0;
|
|
||||||
tmp_sstrength_min = 0xFFFF;
|
|
||||||
|
|
||||||
/* Reset the CRC. */
|
/* Reset the CRC. */
|
||||||
rxcrc = 0xffff;
|
rxcrc = 0xffff;
|
||||||
|
@ -503,7 +442,7 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
if(!gcr_valid()) {
|
if(!gcr_valid()) {
|
||||||
beep_beep(1000);
|
beep_beep(1000);
|
||||||
LOG("Incorrect GCR in header at byte %d/1 %x\n", tmppos, incoming_byte);
|
LOG("Incorrect GCR in header at byte %d/1 %x\n", tmppos, incoming_byte);
|
||||||
PACKET_DROPPED();
|
RIMESTATS_ADD(badsynch);
|
||||||
PT_RESTART(&rxhandler_pt);
|
PT_RESTART(&rxhandler_pt);
|
||||||
}
|
}
|
||||||
} while(!gcr_get_decoded(&rxtmp));
|
} while(!gcr_get_decoded(&rxtmp));
|
||||||
|
@ -521,7 +460,7 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
/* If the length is longer than we can handle, we'll start from
|
/* If the length is longer than we can handle, we'll start from
|
||||||
the beginning. */
|
the beginning. */
|
||||||
if(tmppos + tr1001_rxlen > sizeof(tr1001_rxbuf)) {
|
if(tmppos + tr1001_rxlen > sizeof(tr1001_rxbuf)) {
|
||||||
PACKET_DROPPED();
|
RIMESTATS_ADD(toolong);
|
||||||
PT_RESTART(&rxhandler_pt);
|
PT_RESTART(&rxhandler_pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -540,7 +479,7 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
beep_beep(1000);
|
beep_beep(1000);
|
||||||
LOG("Incorrect GCR 0x%02x at byte %d/1\n", incoming_byte,
|
LOG("Incorrect GCR 0x%02x at byte %d/1\n", incoming_byte,
|
||||||
tmppos - TR1001_HDRLEN);
|
tmppos - TR1001_HDRLEN);
|
||||||
PACKET_DROPPED();
|
RIMESTATS_ADD(badsynch);
|
||||||
PT_RESTART(&rxhandler_pt);
|
PT_RESTART(&rxhandler_pt);
|
||||||
}
|
}
|
||||||
} while(!gcr_get_decoded(&rxtmp));
|
} while(!gcr_get_decoded(&rxtmp));
|
||||||
|
@ -561,7 +500,7 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
gcr_decode(incoming_byte);
|
gcr_decode(incoming_byte);
|
||||||
if(!gcr_valid()) {
|
if(!gcr_valid()) {
|
||||||
beep_beep(1000);
|
beep_beep(1000);
|
||||||
PACKET_DROPPED();
|
RIMESTATS_ADD(badsynch);
|
||||||
PT_RESTART(&rxhandler_pt);
|
PT_RESTART(&rxhandler_pt);
|
||||||
}
|
}
|
||||||
} while(!gcr_get_decoded(&rxtmp));
|
} while(!gcr_get_decoded(&rxtmp));
|
||||||
|
@ -575,7 +514,7 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
/* A full packet has been received and the CRC checks out. We'll
|
/* A full packet has been received and the CRC checks out. We'll
|
||||||
request the driver to take care of the incoming data. */
|
request the driver to take care of the incoming data. */
|
||||||
|
|
||||||
PACKET_ACCEPTED();
|
RIMESTATS_ADD(llrx);
|
||||||
process_poll(&tr1001_process);
|
process_poll(&tr1001_process);
|
||||||
|
|
||||||
/* We'll set the receive state flag to signal that a full frame
|
/* We'll set the receive state flag to signal that a full frame
|
||||||
|
@ -587,7 +526,7 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
} else {
|
} else {
|
||||||
LOG("Incorrect CRC\n");
|
LOG("Incorrect CRC\n");
|
||||||
beep_beep(1000);
|
beep_beep(1000);
|
||||||
PACKET_DROPPED();
|
RIMESTATS_ADD(badcrc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PT_END(&rxhandler_pt);
|
PT_END(&rxhandler_pt);
|
||||||
|
@ -612,7 +551,7 @@ prepare_transmission(int synchbytes)
|
||||||
we wait until the reception has been completed. Reception is done
|
we wait until the reception has been completed. Reception is done
|
||||||
with interrupts so it is OK for us to wait in a while() loop. */
|
with interrupts so it is OK for us to wait in a while() loop. */
|
||||||
|
|
||||||
while(tr1001_rxstate == RXSTATE_RECEVING &&
|
while(tr1001_rxstate == RXSTATE_RECEIVING &&
|
||||||
!timer_expired(&rxtimer)) {
|
!timer_expired(&rxtimer)) {
|
||||||
/* Delay the transmission for a short random duration. */
|
/* Delay the transmission for a short random duration. */
|
||||||
clock_delay(random_rand() & 0x7ff);
|
clock_delay(random_rand() & 0x7ff);
|
||||||
|
@ -649,7 +588,7 @@ int
|
||||||
tr1001_send(const void *packet, unsigned short len)
|
tr1001_send(const void *packet, unsigned short len)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
u16_t crc16;
|
uint16_t crc16;
|
||||||
|
|
||||||
LOG("tr1001_send: sending %d bytes\n", len);
|
LOG("tr1001_send: sending %d bytes\n", len);
|
||||||
|
|
||||||
|
@ -658,8 +597,6 @@ tr1001_send(const void *packet, unsigned short len)
|
||||||
/* Prepare the transmission. */
|
/* Prepare the transmission. */
|
||||||
prepare_transmission(NUM_SYNCHBYTES);
|
prepare_transmission(NUM_SYNCHBYTES);
|
||||||
|
|
||||||
radio_active = 1;
|
|
||||||
|
|
||||||
crc16 = 0xffff;
|
crc16 = 0xffff;
|
||||||
|
|
||||||
gcr_init();
|
gcr_init();
|
||||||
|
@ -672,7 +609,7 @@ tr1001_send(const void *packet, unsigned short len)
|
||||||
|
|
||||||
/* Send packet data. */
|
/* Send packet data. */
|
||||||
for(i = 0; i < len; ++i) {
|
for(i = 0; i < len; ++i) {
|
||||||
crc16 = sendx_crc16(((u8_t *)packet)[i], crc16);
|
crc16 = sendx_crc16(((uint8_t *)packet)[i], crc16);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send CRC */
|
/* Send CRC */
|
||||||
|
@ -702,6 +639,7 @@ tr1001_send(const void *packet, unsigned short len)
|
||||||
}
|
}
|
||||||
|
|
||||||
ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
|
ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
|
||||||
|
RIMESTATS_ADD(lltx);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -726,8 +664,6 @@ tr1001_read(void *buf, unsigned short bufsize)
|
||||||
/* header + content + CRC */
|
/* header + content + CRC */
|
||||||
/* sstrength = (tmp_sstrength / (TR1001_HDRLEN + tr1001_rxlen + 2)) << 1; */
|
/* sstrength = (tmp_sstrength / (TR1001_HDRLEN + tr1001_rxlen + 2)) << 1; */
|
||||||
sstrength = (tmp_count ? ((tmp_sstrength / tmp_count) << 2) : 0);
|
sstrength = (tmp_count ? ((tmp_sstrength / tmp_count) << 2) : 0);
|
||||||
sstrength_max = tmp_sstrength_max;
|
|
||||||
sstrength_min = tmp_sstrength_min;
|
|
||||||
|
|
||||||
rxclear();
|
rxclear();
|
||||||
|
|
||||||
|
@ -753,7 +689,7 @@ PROCESS_THREAD(tr1001_process, ev, data)
|
||||||
LOG("tr1001 has no receive function\n");
|
LOG("tr1001 has no receive function\n");
|
||||||
|
|
||||||
/* Perform a dummy read to drop the message. */
|
/* Perform a dummy read to drop the message. */
|
||||||
tr1001_read((u8_t *) &data, 0);
|
tr1001_read((uint8_t *)&data, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -792,59 +728,6 @@ tr1001_sstrength(void)
|
||||||
{
|
{
|
||||||
return sstrength;
|
return sstrength;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#if TR1001_STATISTICS
|
|
||||||
unsigned short
|
|
||||||
tr1001_packets_ok(void)
|
|
||||||
{
|
|
||||||
return packets_ok;
|
|
||||||
}
|
|
||||||
#endif /* TR1001_STATISTICS */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#if TR1001_STATISTICS
|
|
||||||
unsigned short
|
|
||||||
tr1001_packets_dropped(void)
|
|
||||||
{
|
|
||||||
return packets_err;
|
|
||||||
}
|
|
||||||
#endif /* TR1001_STATISTICS */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#if TR1001_STATISTICS
|
|
||||||
void
|
|
||||||
tr1001_clear_packets(void)
|
|
||||||
{
|
|
||||||
packets_ok = packets_err = 0;
|
|
||||||
}
|
|
||||||
#endif /* TR1001_STATISTICS */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#if TR1001_STATISTICS
|
|
||||||
unsigned short
|
|
||||||
tr1001_sstrength_value(unsigned int type)
|
|
||||||
{
|
|
||||||
switch(type) {
|
|
||||||
case TR1001_SSTRENGTH_DROPPED:
|
|
||||||
return sstrength_dropped;
|
|
||||||
case TR1001_SSTRENGTH_MAX:
|
|
||||||
return sstrength_max;
|
|
||||||
case TR1001_SSTRENGTH_MIN:
|
|
||||||
return sstrength_min < sstrength_max ? sstrength_min : 0;
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* TR1001_STATISTICS */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
unsigned char
|
|
||||||
tr1001_active(void)
|
|
||||||
{
|
|
||||||
return radio_active;
|
|
||||||
}
|
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
void
|
|
||||||
tr1001_clear_active(void)
|
|
||||||
{
|
|
||||||
radio_active = 0;
|
|
||||||
}
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
/** @} */
|
/** @} */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* @(#)$Id: tr1001.c,v 1.9 2007/11/28 21:28:03 nifi Exp $
|
* @(#)$Id: tr1001.c,v 1.10 2008/07/08 12:27:22 nifi Exp $
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* \addtogroup esb
|
* \addtogroup esb
|
||||||
|
@ -56,28 +56,19 @@
|
||||||
#include "dev/radio-sensor.h"
|
#include "dev/radio-sensor.h"
|
||||||
#include "lib/me.h"
|
#include "lib/me.h"
|
||||||
#include "lib/crc16.h"
|
#include "lib/crc16.h"
|
||||||
|
#include "net/rime/rimestats.h"
|
||||||
|
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define RXSTATE_READY 0
|
#define RXSTATE_READY 0
|
||||||
#define RXSTATE_RECEVING 1
|
#define RXSTATE_RECEIVING 1
|
||||||
#define RXSTATE_FULL 2
|
#define RXSTATE_FULL 2
|
||||||
|
|
||||||
#define SYNCH1 0x3c
|
#define SYNCH1 0x3c
|
||||||
#define SYNCH2 0x03
|
#define SYNCH2 0x03
|
||||||
|
|
||||||
#if TR1001_STATISTICS
|
|
||||||
static unsigned short sstrength_dropped,
|
|
||||||
sstrength_max, sstrength_min, tmp_sstrength_max, tmp_sstrength_min;
|
|
||||||
/* The number of dropped packets */
|
|
||||||
static unsigned short packets_err;
|
|
||||||
/* The number of accepted packets */
|
|
||||||
static unsigned short packets_ok;
|
|
||||||
#endif /* TR1001_STATISTICS */
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The buffer which holds incoming data.
|
* The buffer which holds incoming data.
|
||||||
*/
|
*/
|
||||||
|
@ -94,15 +85,13 @@ static unsigned short tr1001_rxlen = 0;
|
||||||
*/
|
*/
|
||||||
volatile unsigned char tr1001_rxstate = RXSTATE_READY;
|
volatile unsigned char tr1001_rxstate = RXSTATE_READY;
|
||||||
|
|
||||||
static u8_t radio_active;
|
static uint16_t rxcrc, rxcrctmp;
|
||||||
|
|
||||||
static u16_t rxcrc, rxcrctmp;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The structure of the packet header.
|
* The structure of the packet header.
|
||||||
*/
|
*/
|
||||||
struct tr1001_hdr {
|
struct tr1001_hdr {
|
||||||
u8_t len[2]; /**< The 16-bit length of the packet in network byte
|
uint8_t len[2]; /**< The 16-bit length of the packet in network byte
|
||||||
order. */
|
order. */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -113,7 +102,7 @@ struct tr1001_hdr {
|
||||||
|
|
||||||
#define OFF 0
|
#define OFF 0
|
||||||
#define ON 1
|
#define ON 1
|
||||||
static u8_t onoroff = OFF;
|
static uint8_t onoroff = OFF;
|
||||||
|
|
||||||
#define NUM_SYNCHBYTES 4
|
#define NUM_SYNCHBYTES 4
|
||||||
|
|
||||||
|
@ -158,23 +147,6 @@ const struct radio_driver tr1001_driver = {
|
||||||
tr1001_off
|
tr1001_off
|
||||||
};
|
};
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#if TR1001_STATISTICS
|
|
||||||
#define PACKET_DROPPED() do { \
|
|
||||||
if(packets_err < ~0) {\
|
|
||||||
packets_err++;\
|
|
||||||
}\
|
|
||||||
sstrength_dropped = (tmp_count ? ((tmp_sstrength / tmp_count) << 2) : 0);\
|
|
||||||
} while(0)
|
|
||||||
#define PACKET_ACCEPTED() do {\
|
|
||||||
if(packets_ok < ~0) {\
|
|
||||||
packets_ok++;\
|
|
||||||
}\
|
|
||||||
} while(0);
|
|
||||||
#else
|
|
||||||
#define PACKET_DROPPED()
|
|
||||||
#define PACKET_ACCEPTED()
|
|
||||||
#endif /* TR1001_STATISTICS */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/*
|
/*
|
||||||
* Turn on data transmission in On-Off-Keyed mode.
|
* Turn on data transmission in On-Off-Keyed mode.
|
||||||
|
@ -298,15 +270,15 @@ send(unsigned char b)
|
||||||
static void
|
static void
|
||||||
send2(unsigned char b)
|
send2(unsigned char b)
|
||||||
{
|
{
|
||||||
u16_t m;
|
uint16_t m;
|
||||||
m = me_encode(b);
|
m = me_encode(b);
|
||||||
send(m >> 8);
|
send(m >> 8);
|
||||||
send(m & 0xff);
|
send(m & 0xff);
|
||||||
}
|
}
|
||||||
static u16_t
|
static uint16_t
|
||||||
send2_crc16(unsigned char b, u16_t crcacc)
|
send2_crc16(unsigned char b, uint16_t crcacc)
|
||||||
{
|
{
|
||||||
u16_t m;
|
uint16_t m;
|
||||||
m = me_encode(b);
|
m = me_encode(b);
|
||||||
send(m >> 8);
|
send(m >> 8);
|
||||||
send(m & 0xff);
|
send(m & 0xff);
|
||||||
|
@ -355,12 +327,6 @@ tr1001_init(void)
|
||||||
|
|
||||||
PT_INIT(&rxhandler_pt);
|
PT_INIT(&rxhandler_pt);
|
||||||
|
|
||||||
#if TR1001_STATISTICS
|
|
||||||
packets_ok = packets_err = 0;
|
|
||||||
sstrength_dropped = 0;
|
|
||||||
sstrength_min = 0xFFFF;
|
|
||||||
sstrength_max = 0;
|
|
||||||
#endif /* TR1001_STATISTICS */
|
|
||||||
onoroff = OFF;
|
onoroff = OFF;
|
||||||
|
|
||||||
UCTL0 = CHAR; /* 8-bit character */
|
UCTL0 = CHAR; /* 8-bit character */
|
||||||
|
@ -415,16 +381,10 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
|
|
||||||
timer_restart(&rxtimer);
|
timer_restart(&rxtimer);
|
||||||
|
|
||||||
if(tr1001_rxstate == RXSTATE_RECEVING) {
|
if(tr1001_rxstate == RXSTATE_RECEIVING) {
|
||||||
unsigned short signal = radio_sensor.value(0);
|
unsigned short signal = radio_sensor.value(0);
|
||||||
tmp_sstrength += (signal >> 2);
|
tmp_sstrength += (signal >> 2);
|
||||||
tmp_count++;
|
tmp_count++;
|
||||||
if(signal < tmp_sstrength_min) {
|
|
||||||
tmp_sstrength_min = signal;
|
|
||||||
}
|
|
||||||
if(signal > tmp_sstrength_max) {
|
|
||||||
tmp_sstrength_max = signal;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PT_BEGIN(&rxhandler_pt);
|
PT_BEGIN(&rxhandler_pt);
|
||||||
|
@ -437,7 +397,7 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
/* Wait until we receive the first syncronization byte. */
|
/* Wait until we receive the first syncronization byte. */
|
||||||
PT_WAIT_UNTIL(&rxhandler_pt, incoming_byte == SYNCH1);
|
PT_WAIT_UNTIL(&rxhandler_pt, incoming_byte == SYNCH1);
|
||||||
|
|
||||||
tr1001_rxstate = RXSTATE_RECEVING;
|
tr1001_rxstate = RXSTATE_RECEIVING;
|
||||||
|
|
||||||
/* Read all incoming syncronization bytes. */
|
/* Read all incoming syncronization bytes. */
|
||||||
PT_WAIT_WHILE(&rxhandler_pt, incoming_byte == SYNCH1);
|
PT_WAIT_WHILE(&rxhandler_pt, incoming_byte == SYNCH1);
|
||||||
|
@ -451,8 +411,6 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
/* Start signal strength measurement */
|
/* Start signal strength measurement */
|
||||||
tmp_sstrength = 0;
|
tmp_sstrength = 0;
|
||||||
tmp_count = 0;
|
tmp_count = 0;
|
||||||
tmp_sstrength_max = 0;
|
|
||||||
tmp_sstrength_min = 0xFFFF;
|
|
||||||
|
|
||||||
/* Reset the CRC. */
|
/* Reset the CRC. */
|
||||||
rxcrc = 0xffff;
|
rxcrc = 0xffff;
|
||||||
|
@ -464,11 +422,11 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
PT_YIELD(&rxhandler_pt);
|
PT_YIELD(&rxhandler_pt);
|
||||||
|
|
||||||
/* If the incoming byte isn't a valid Manchester encoded byte,
|
/* If the incoming byte isn't a valid Manchester encoded byte,
|
||||||
we start again from the beinning. */
|
we start again from the beginning. */
|
||||||
if(!me_valid(incoming_byte)) {
|
if(!me_valid(incoming_byte)) {
|
||||||
beep_beep(1000);
|
beep_beep(1000);
|
||||||
LOG("Incorrect manchester in header at byte %d/1\n", tmppos);
|
LOG("Incorrect manchester in header at byte %d/1\n", tmppos);
|
||||||
PACKET_DROPPED();
|
RIMESTATS_ADD(badsynch);
|
||||||
PT_RESTART(&rxhandler_pt);
|
PT_RESTART(&rxhandler_pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,7 +438,7 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
if(!me_valid(incoming_byte)) {
|
if(!me_valid(incoming_byte)) {
|
||||||
beep_beep(1000);
|
beep_beep(1000);
|
||||||
LOG("Incorrect manchester in header at byte %d/2\n", tmppos);
|
LOG("Incorrect manchester in header at byte %d/2\n", tmppos);
|
||||||
PACKET_DROPPED();
|
RIMESTATS_ADD(badsynch);
|
||||||
PT_RESTART(&rxhandler_pt);
|
PT_RESTART(&rxhandler_pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,7 +460,7 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
/* If the length is longer than we can handle, we'll start from
|
/* If the length is longer than we can handle, we'll start from
|
||||||
the beginning. */
|
the beginning. */
|
||||||
if(tmppos + tr1001_rxlen > sizeof(tr1001_rxbuf)) {
|
if(tmppos + tr1001_rxlen > sizeof(tr1001_rxbuf)) {
|
||||||
PACKET_DROPPED();
|
RIMESTATS_ADD(toolong);
|
||||||
PT_RESTART(&rxhandler_pt);
|
PT_RESTART(&rxhandler_pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -514,7 +472,7 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
LOG("Incorrect manchester 0x%02x at byte %d/1\n", incoming_byte,
|
LOG("Incorrect manchester 0x%02x at byte %d/1\n", incoming_byte,
|
||||||
tmppos - TR1001_HDRLEN);
|
tmppos - TR1001_HDRLEN);
|
||||||
beep_beep(1000);
|
beep_beep(1000);
|
||||||
PACKET_DROPPED();
|
RIMESTATS_ADD(badsynch);
|
||||||
PT_RESTART(&rxhandler_pt);
|
PT_RESTART(&rxhandler_pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -525,7 +483,7 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
if(!me_valid(incoming_byte)) {
|
if(!me_valid(incoming_byte)) {
|
||||||
LOG("Incorrect manchester at byte %d/2\n", tmppos - TR1001_HDRLEN);
|
LOG("Incorrect manchester at byte %d/2\n", tmppos - TR1001_HDRLEN);
|
||||||
beep_beep(1000);
|
beep_beep(1000);
|
||||||
PACKET_DROPPED();
|
RIMESTATS_ADD(badsynch);
|
||||||
PT_RESTART(&rxhandler_pt);
|
PT_RESTART(&rxhandler_pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,7 +499,7 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
|
|
||||||
if(!me_valid(incoming_byte)) {
|
if(!me_valid(incoming_byte)) {
|
||||||
beep_beep(1000);
|
beep_beep(1000);
|
||||||
PACKET_DROPPED();
|
RIMESTATS_ADD(badsynch);
|
||||||
PT_RESTART(&rxhandler_pt);
|
PT_RESTART(&rxhandler_pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,7 +510,7 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
/* A full packet has been received and the CRC checks out. We'll
|
/* A full packet has been received and the CRC checks out. We'll
|
||||||
request the driver to take care of the incoming data. */
|
request the driver to take care of the incoming data. */
|
||||||
|
|
||||||
PACKET_ACCEPTED();
|
RIMESTATS_ADD(llrx);
|
||||||
process_poll(&tr1001_process);
|
process_poll(&tr1001_process);
|
||||||
|
|
||||||
/* We'll set the receive state flag to signal that a full frame
|
/* We'll set the receive state flag to signal that a full frame
|
||||||
|
@ -564,7 +522,7 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
|
||||||
} else {
|
} else {
|
||||||
LOG("Incorrect CRC");
|
LOG("Incorrect CRC");
|
||||||
beep_beep(1000);
|
beep_beep(1000);
|
||||||
PACKET_DROPPED();
|
RIMESTATS_ADD(badcrc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PT_END(&rxhandler_pt);
|
PT_END(&rxhandler_pt);
|
||||||
|
@ -589,7 +547,7 @@ prepare_transmission(int synchbytes)
|
||||||
we wait until the reception has been completed. Reception is done
|
we wait until the reception has been completed. Reception is done
|
||||||
with interrupts so it is OK for us to wait in a while() loop. */
|
with interrupts so it is OK for us to wait in a while() loop. */
|
||||||
|
|
||||||
while(tr1001_rxstate == RXSTATE_RECEVING &&
|
while(tr1001_rxstate == RXSTATE_RECEIVING &&
|
||||||
!timer_expired(&rxtimer)) {
|
!timer_expired(&rxtimer)) {
|
||||||
/* Delay the transmission for a short random duration. */
|
/* Delay the transmission for a short random duration. */
|
||||||
clock_delay(random_rand() & 0x7ff);
|
clock_delay(random_rand() & 0x7ff);
|
||||||
|
@ -623,10 +581,10 @@ prepare_transmission(int synchbytes)
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int
|
int
|
||||||
tr1001_send(const u8_t *packet, u16_t len)
|
tr1001_send(const uint8_t *packet, uint16_t len)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
u16_t crc16;
|
uint16_t crc16;
|
||||||
|
|
||||||
LOG("tr1001_send: sending %d bytes\n", len);
|
LOG("tr1001_send: sending %d bytes\n", len);
|
||||||
|
|
||||||
|
@ -635,8 +593,6 @@ tr1001_send(const u8_t *packet, u16_t len)
|
||||||
/* Prepare the transmission. */
|
/* Prepare the transmission. */
|
||||||
prepare_transmission(NUM_SYNCHBYTES);
|
prepare_transmission(NUM_SYNCHBYTES);
|
||||||
|
|
||||||
radio_active = 1;
|
|
||||||
|
|
||||||
crc16 = 0xffff;
|
crc16 = 0xffff;
|
||||||
|
|
||||||
/* Send packet header. */
|
/* Send packet header. */
|
||||||
|
@ -668,12 +624,13 @@ tr1001_send(const u8_t *packet, u16_t len)
|
||||||
}
|
}
|
||||||
|
|
||||||
ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
|
ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
|
||||||
|
RIMESTATS_ADD(lltx);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
u16_t
|
uint16_t
|
||||||
tr1001_read(u8_t *buf, u16_t bufsize)
|
tr1001_read(uint8_t *buf, uint16_t bufsize)
|
||||||
{
|
{
|
||||||
unsigned short tmplen;
|
unsigned short tmplen;
|
||||||
|
|
||||||
|
@ -694,8 +651,6 @@ tr1001_read(u8_t *buf, u16_t bufsize)
|
||||||
|
|
||||||
/* header + content + CRC */
|
/* header + content + CRC */
|
||||||
sstrength = (tmp_count ? ((tmp_sstrength / tmp_count) << 2) : 0);
|
sstrength = (tmp_count ? ((tmp_sstrength / tmp_count) << 2) : 0);
|
||||||
sstrength_max = tmp_sstrength_max;
|
|
||||||
sstrength_min = tmp_sstrength_min;
|
|
||||||
|
|
||||||
rxclear();
|
rxclear();
|
||||||
|
|
||||||
|
@ -761,58 +716,5 @@ tr1001_sstrength(void)
|
||||||
return sstrength;
|
return sstrength;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
#if TR1001_STATISTICS
|
|
||||||
unsigned short
|
|
||||||
tr1001_packets_ok(void)
|
|
||||||
{
|
|
||||||
return packets_ok;
|
|
||||||
}
|
|
||||||
#endif /* TR1001_STATISTICS */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#if TR1001_STATISTICS
|
|
||||||
unsigned short
|
|
||||||
tr1001_packets_dropped(void)
|
|
||||||
{
|
|
||||||
return packets_err;
|
|
||||||
}
|
|
||||||
#endif /* TR1001_STATISTICS */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#if TR1001_STATISTICS
|
|
||||||
void
|
|
||||||
tr1001_clear_packets(void)
|
|
||||||
{
|
|
||||||
packets_ok = packets_err = 0;
|
|
||||||
}
|
|
||||||
#endif /* TR1001_STATISTICS */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#if TR1001_STATISTICS
|
|
||||||
unsigned short
|
|
||||||
tr1001_sstrength_value(unsigned int type)
|
|
||||||
{
|
|
||||||
switch(type) {
|
|
||||||
case TR1001_SSTRENGTH_DROPPED:
|
|
||||||
return sstrength_dropped;
|
|
||||||
case TR1001_SSTRENGTH_MAX:
|
|
||||||
return sstrength_max;
|
|
||||||
case TR1001_SSTRENGTH_MIN:
|
|
||||||
return sstrength_min < sstrength_max ? sstrength_min : 0;
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* TR1001_STATISTICS */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
unsigned char
|
|
||||||
tr1001_active(void)
|
|
||||||
{
|
|
||||||
return radio_active;
|
|
||||||
}
|
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
void
|
|
||||||
tr1001_clear_active(void)
|
|
||||||
{
|
|
||||||
radio_active = 0;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/** @} */
|
/** @} */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* @(#)$Id: tr1001.h,v 1.6 2007/11/19 09:50:54 adamdunkels Exp $
|
* @(#)$Id: tr1001.h,v 1.7 2008/07/08 12:27:22 nifi Exp $
|
||||||
*/
|
*/
|
||||||
#ifndef __TR1001_H__
|
#ifndef __TR1001_H__
|
||||||
#define __TR1001_H__
|
#define __TR1001_H__
|
||||||
|
@ -140,22 +140,4 @@ extern volatile unsigned char tr1001_rxstate;
|
||||||
*/
|
*/
|
||||||
unsigned short tr1001_sstrength(void);
|
unsigned short tr1001_sstrength(void);
|
||||||
|
|
||||||
#ifdef TR1001_CONF_STATISTICS
|
|
||||||
#define TR1001_STATISTICS TR1001_CONF_STATISTICS
|
|
||||||
#else
|
|
||||||
#define TR1001_STATISTICS 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if TR1001_STATISTICS
|
|
||||||
#define TR1001_SSTRENGTH_DROPPED 1
|
|
||||||
#define TR1001_SSTRENGTH_MAX 2
|
|
||||||
#define TR1001_SSTRENGTH_MIN 3
|
|
||||||
unsigned short tr1001_packets_ok(void);
|
|
||||||
unsigned short tr1001_packets_dropped(void);
|
|
||||||
void tr1001_clear_packets(void);
|
|
||||||
unsigned short tr1001_sstrength_value(unsigned int type);
|
|
||||||
unsigned char tr1001_active(void);
|
|
||||||
void tr1001_clear_active(void);
|
|
||||||
#endif /* TR1001_STATISTICS */
|
|
||||||
|
|
||||||
#endif /* __TR1001_H__ */
|
#endif /* __TR1001_H__ */
|
||||||
|
|
Loading…
Reference in a new issue