Add RADIOSTATS

This commit is contained in:
dak664 2010-02-12 16:41:02 +00:00
parent eb2ac1a154
commit a6ab27402a
2 changed files with 76 additions and 16 deletions

View file

@ -36,7 +36,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Id: radio.c,v 1.3 2009/07/05 18:50:44 dak664 Exp $
* $Id: radio.c,v 1.4 2010/02/12 16:41:02 dak664 Exp $
*/
/**
@ -112,6 +112,14 @@ static radio_rx_callback rx_frame_callback;
static uint8_t rssi_val;
static uint8_t rx_mode;
uint8_t rxMode = RX_AACK_ON;
/* See clock.c and httpd-cgi.c for RADIOSTATS code */
#define RADIOSTATS 0
#if RADIOSTATS
uint8_t RF230_radio_on, RF230_rsigsi;
uint16_t RF230_sendpackets,RF230_receivepackets,RF230_sendfail,RF230_receivefail;
#endif
static hal_rx_frame_t rx_frame;
static parsed_frame_t parsed_frame;
@ -184,9 +192,12 @@ radio_init(bool cal_rc_osc,
else {
if (hal_register_read(RG_MAN_ID_0) != SUPPORTED_MANUFACTURER_ID)
init_status = RADIO_UNSUPPORTED_DEVICE;
else
hal_register_write(RG_IRQ_MASK, RF230_SUPPORTED_INTERRUPT_MASK);
else
hal_register_write(RG_IRQ_MASK, RF230_SUPPORTED_INTERRUPT_MASK);
}
#if RADIOSTATS
RF230_radio_on = 1;
#endif
}
/* set callbacks for events. Save user's rx_event, which we will */
@ -246,6 +257,10 @@ radio_trx_end_event(uint32_t const isr_timestamp)
}
if (rx_mode){
/* radio has received frame, store it away */
#if RADIOSTATS
RF230_rssi=rssi_val;
RF230_receivepackets++;
#endif
parsed_frame.time = isr_timestamp;
parsed_frame.rssi = rssi_val;
@ -271,12 +286,18 @@ radio_trx_end_event(uint32_t const isr_timestamp)
case TRAC_NO_ACK:
case TRAC_CHANNEL_ACCESS_FAILURE:
event.event = MAC_EVENT_NACK;
#if RADIOSTATS
RF230_sendfail++;
#endif
break;
case TRAC_SUCCESS_WAIT_FOR_ACK:
/* should only happen in RX mode */
case TRAC_INVALID:
/* should never happen here */
default:
#if RADIOSTATS
RF230_sendfail++;
#endif
break;
}
if (event.event)
@ -893,6 +914,9 @@ radio_enter_sleep_mode(void)
/* Enter Sleep. */
hal_set_slptr_high();
enter_sleep_status = RADIO_SUCCESS;
#if RADIOSTATS
RF230_radio_on = 0;
#endif
}
return enter_sleep_status;
@ -921,6 +945,9 @@ radio_leave_sleep_mode(void)
/* Ensure that the radio transceiver is in the TRX_OFF state. */
if (radio_get_trx_state() == TRX_OFF){
leave_sleep_status = RADIO_SUCCESS;
#if RADIOSTATS
RF230_radio_on = 1;
#endif
}
return leave_sleep_status;
@ -990,12 +1017,18 @@ radio_send_data(uint8_t data_length, uint8_t *data)
{
/*Check function parameters and current state.*/
if (data_length > RF230_MAX_TX_FRAME_LENGTH){
#if RADIOSTATS
RF230_sendfail++;
#endif
return RADIO_INVALID_ARGUMENT;
}
/* If we are busy, return */
if ((radio_get_trx_state() == BUSY_TX) || (radio_get_trx_state() == BUSY_TX_ARET) )
{
#if RADIOSTATS
RF230_sendfail++;
#endif
return RADIO_WRONG_STATE;
}
@ -1008,7 +1041,9 @@ radio_send_data(uint8_t data_length, uint8_t *data)
hal_set_slptr_low();
hal_frame_write(data, data_length); /* Then write data to the frame buffer. */
#if RADIOSTATS
RF230_sendpackets++;
#endif
return RADIO_SUCCESS;
}

View file

@ -27,7 +27,7 @@
* SUCH DAMAGE.
*
*
* $Id: rf230bb.c,v 1.1 2009/07/08 16:17:07 dak664 Exp $
* $Id: rf230bb.c,v 1.2 2010/02/12 16:41:02 dak664 Exp $
*/
/**
@ -84,6 +84,13 @@
#define WITH_SEND_CCA 0
/* See clock.c and httpd-cgi.c for RADIOSTATS code */
uint8_t RF230_radio_on;
#define RADIOSTATS 0
#if RADIOSTATS
uint8_t RF230_rsigsi;
uint16_t RF230_sendpackets,RF230_receivepackets,RF230_sendfail,RF230_receivefail;
#endif
#if RF230_CONF_TIMESTAMPS
#include "net/rime/timesynch.h"
@ -172,8 +179,6 @@ static void (* receiver_callback)(const struct radio_driver *);
//signed char rf230_last_rssi;
//uint8_t rf230_last_correlation;
static uint8_t receive_on;
//static uint8_t rssi_val;
uint8_t rx_mode;
/* Radio stuff in network byte order. */
@ -396,7 +401,7 @@ on(void)
{
ENERGEST_ON(ENERGEST_TYPE_LISTEN);
PRINTF("rf230 internal on\n");
receive_on = 1;
RF230_radio_on = 1;
hal_set_slptr_low();
//radio_is_waking=1;//can test this before tx instead of delaying
@ -410,7 +415,7 @@ static void
off(void)
{
PRINTF("rf230 internal off\n");
receive_on = 0;
RF230_radio_on = 0;
/* Wait for transmission to end before turning radio off. */
rf230_waitidle();
@ -450,7 +455,7 @@ rf230_off(void)
{
// PRINTF("rf230_off\n");
/* Don't do anything if we are already turned off. */
if(receive_on == 0) {
if(RF230_radio_on == 0) {
return 1;
}
@ -469,7 +474,7 @@ int
rf230_on(void)
{
//PRINTF("rf230_on\n");
if(receive_on) {
if(RF230_radio_on) {
return 1;
}
if(locked) {
@ -665,6 +670,9 @@ bomb
rxframe.length=0;
// framep+=len-AUX_LEN+2;
#if RADIOSTATS
RF230_receivepackets++;
#endif
#if RF230_CONF_CHECKSUM
bomb
@ -706,7 +714,9 @@ bomb
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (const rimeaddr_t *)src_reversed);
*/
#if RADIOSTATS
RF230_rsigsi=hal_subregister_read( SR_RSSI );
#endif
packetbuf_set_attr(PACKETBUF_ATTR_RSSI, hal_subregister_read( SR_RSSI ));
packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, rxframe.lqi);
@ -725,7 +735,12 @@ bomb
#endif /* RF230_CONF_TIMESTAMPS */
} else {
PRINTF("rf230: Bad CRC\n");
PRINTF("rf230: Bad CRC\n");
#if RADIOSTATS
RF230_receivefail++;
#endif
RIMESTATS_ADD(badcrc);
len = AUX_LEN;
}
@ -775,7 +790,7 @@ rf230_rssi(void)
int radio_was_off = 0;
/*The RSSI measurement should only be done in RX_ON or BUSY_RX.*/
if(!receive_on) {
if(!RF230_radio_on) {
radio_was_off = 1;
rf230_on();
}
@ -800,6 +815,10 @@ rf230_send(const void *payload, unsigned short payload_len)
uint16_t checksum;
#endif /* RF230_CONF_CHECKSUM */
#if RADIOSTATS
RF230_sendpackets++;
#endif
GET_LOCK();
if(packetbuf_attr(PACKETBUF_ATTR_RADIO_TXPOWER) > 0) {
@ -816,6 +835,9 @@ rf230_send(const void *payload, unsigned short payload_len)
total_len = payload_len + AUX_LEN;
/*Check function parameters and current state.*/
if (total_len > RF230_MAX_TX_FRAME_LENGTH){
#if RADIOSTATS
RF230_sendfail++;
#endif
return -1;
}
pbuf=&buffer[0];
@ -874,7 +896,7 @@ rf230_send(const void *payload, unsigned short payload_len)
rtimer_clock_t txtime = timesynch_time();
#endif /* RF230_CONF_TIMESTAMPS */
if(receive_on) {
if(RF230_radio_on) {
ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
}
ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
@ -897,7 +919,7 @@ rf230_send(const void *payload, unsigned short payload_len)
ENERGEST_OFF_LEVEL(ENERGEST_TYPE_TRANSMIT,rf230_get_txpower());
#endif
ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
if(receive_on) {
if(RF230_radio_on) {
ENERGEST_ON(ENERGEST_TYPE_LISTEN);
}
@ -910,6 +932,9 @@ rf230_send(const void *payload, unsigned short payload_len)
transmitted because of other channel activity. */
RIMESTATS_ADD(contentiondrop);
PRINTF("rf230: do_send() transmission never started\n");
#if RADIOSTATS
RF230_sendfail++;
#endif
RELEASE_LOCK();
return -3; /* Transmission never started! */
}/*---------------------------------------------------------------------------*/