2010-03-03 23:48:29 +00:00
|
|
|
#include <mc1322x.h>
|
|
|
|
#include <board.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "tests.h"
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
/* This program communicates with itself and determines the packet */
|
|
|
|
/* error rate (PER) under a variety of powers and packet sizes */
|
|
|
|
/* Each test the packets are sent and received as fast as possible */
|
|
|
|
|
|
|
|
/* The program first scans on channel 11 and attempts to open a test */
|
|
|
|
/* session with a node. After opening a session, the nodes begin the */
|
|
|
|
/* test sequence */
|
|
|
|
|
|
|
|
#define DEBUG_MACA 1
|
|
|
|
|
2010-03-04 23:52:42 +00:00
|
|
|
/* how long to wait between session requests */
|
2010-03-06 23:48:13 +00:00
|
|
|
#define SESSION_REQ_TIMEOUT 10000 /* phony seconds */
|
2010-03-03 23:48:29 +00:00
|
|
|
|
|
|
|
enum STATES {
|
|
|
|
SCANNING,
|
|
|
|
MAX_STATE
|
|
|
|
};
|
|
|
|
|
2010-03-04 23:52:42 +00:00
|
|
|
typedef uint32_t ptype_t;
|
2010-03-03 23:48:29 +00:00
|
|
|
enum PACKET_TYPE {
|
2010-03-04 23:52:42 +00:00
|
|
|
PACKET_SESS_REQ,
|
2010-03-03 23:48:29 +00:00
|
|
|
MAX_PACKET_TYPE
|
|
|
|
};
|
2010-03-04 23:52:42 +00:00
|
|
|
/* get protocol level packet type */
|
|
|
|
/* this is not 802.15.4 packet type */
|
|
|
|
ptype_t get_packet_type(packet_t *p) {
|
|
|
|
return MAX_PACKET_TYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef uint32_t session_id_t;
|
|
|
|
|
|
|
|
/* phony get_time */
|
|
|
|
uint32_t get_time(void) {
|
|
|
|
static volatile int32_t cur_time = 0;
|
|
|
|
cur_time++;
|
|
|
|
return cur_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define random_short_addr() (*MACA_RANDOM & ones(sizeof(short_addr_t)*8))
|
|
|
|
|
|
|
|
void build_session_req(volatile packet_t *p) {
|
2010-03-06 23:48:13 +00:00
|
|
|
p->length = 16;
|
2010-03-04 23:52:42 +00:00
|
|
|
p->data[0] = 0xff;
|
|
|
|
p->data[1] = 0x01;
|
|
|
|
p->data[2] = 0x23;
|
|
|
|
p->data[3] = 0x45;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void session_req(short_addr_t addr) {
|
|
|
|
static volatile int time = 0;
|
|
|
|
volatile packet_t *p;
|
|
|
|
|
2010-03-06 22:58:49 +00:00
|
|
|
if((get_time() - time) > SESSION_REQ_TIMEOUT) {
|
|
|
|
time = get_time();
|
|
|
|
if((p = get_free_packet())) {
|
|
|
|
build_session_req(p);
|
|
|
|
tx_packet(p);
|
|
|
|
}
|
2010-03-05 22:06:08 +00:00
|
|
|
}
|
2010-03-04 23:52:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-03-03 23:48:29 +00:00
|
|
|
|
2010-03-06 22:58:49 +00:00
|
|
|
void print_packet(packet_t *p) {
|
2010-03-07 00:14:55 +00:00
|
|
|
volatile uint8_t i,j,k;
|
|
|
|
#define PER_ROW 16
|
2010-03-06 22:58:49 +00:00
|
|
|
if(p) {
|
2010-03-07 00:14:55 +00:00
|
|
|
printf("len 0x%02x\n\r",p->length);
|
|
|
|
for(j=0, k=0; j < ((p->length)%PER_ROW)-1; j++) {
|
|
|
|
for(i=0; i < PER_ROW; i++, k++) {
|
|
|
|
if(k>=p->length) { break; }
|
|
|
|
printf("%02x ",p->data[j*PER_ROW+i]);
|
2010-03-06 22:58:49 +00:00
|
|
|
}
|
|
|
|
printf("\n\r");
|
|
|
|
}
|
2010-03-07 00:14:55 +00:00
|
|
|
printf("\n\r");
|
2010-03-06 22:58:49 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2010-03-04 23:52:42 +00:00
|
|
|
session_id_t open_session(short_addr_t addr) { return 0; }
|
2010-03-03 23:48:29 +00:00
|
|
|
|
|
|
|
void main(void) {
|
|
|
|
uint32_t state;
|
2010-03-04 23:52:42 +00:00
|
|
|
volatile packet_t *p;
|
|
|
|
session_id_t sesid;
|
|
|
|
ptype_t type;
|
|
|
|
short_addr_t addr, my_addr;
|
|
|
|
|
2010-03-03 23:48:29 +00:00
|
|
|
uart_init(INC,MOD);
|
|
|
|
|
|
|
|
print_welcome("Packet error test");
|
|
|
|
|
|
|
|
/* standard radio initialization */
|
|
|
|
reset_maca();
|
|
|
|
radio_init();
|
|
|
|
vreg_init();
|
|
|
|
flyback_init();
|
|
|
|
init_phy();
|
2010-03-04 23:52:42 +00:00
|
|
|
free_all_packets();
|
|
|
|
|
2010-03-03 23:48:29 +00:00
|
|
|
/* trim the reference osc. to 24MHz */
|
|
|
|
pack_XTAL_CNTL(CTUNE_4PF, CTUNE, FTUNE, IBIAS);
|
|
|
|
|
|
|
|
set_power(0x0f); /* 0dbm */
|
|
|
|
set_channel(0); /* channel 11 */
|
|
|
|
|
2010-03-04 23:52:42 +00:00
|
|
|
enable_irq(MACA);
|
|
|
|
|
2010-03-03 23:48:29 +00:00
|
|
|
/* initial radio command */
|
|
|
|
/* nop, promiscuous, no cca */
|
|
|
|
*MACA_CONTROL = (1 << PRM) | (NO_CCA << MODE);
|
|
|
|
|
2010-03-04 23:52:42 +00:00
|
|
|
/* generate a random short address */
|
|
|
|
my_addr = random_short_addr();
|
|
|
|
|
2010-03-06 00:25:38 +00:00
|
|
|
/* sets up tx_on, should be a board specific item */
|
|
|
|
*GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2));
|
|
|
|
*GPIO_PAD_DIR0 = *GPIO_PAD_DIR0 | (1<<(44-32));
|
|
|
|
|
2010-03-03 23:48:29 +00:00
|
|
|
state = SCANNING;
|
|
|
|
while(1) {
|
2010-03-04 23:52:42 +00:00
|
|
|
|
2010-03-03 23:48:29 +00:00
|
|
|
switch(state) {
|
|
|
|
case SCANNING:
|
2010-03-04 23:52:42 +00:00
|
|
|
if((p = rx_packet())) {
|
|
|
|
/* extract what we need and free the packet */
|
2010-03-06 22:58:49 +00:00
|
|
|
printf("Recv: ");
|
|
|
|
print_packet(p);
|
2010-03-04 23:52:42 +00:00
|
|
|
type = get_packet_type(p);
|
|
|
|
addr = p->addr;
|
|
|
|
free_packet(p);
|
|
|
|
/* pick a new address if someone else is using ours */
|
|
|
|
if(addr == my_addr) {
|
|
|
|
my_addr = random_short_addr();
|
|
|
|
printf("DUP addr received, changing to new addr 0x%x02\n\r",my_addr);
|
|
|
|
}
|
2010-03-03 23:48:29 +00:00
|
|
|
/* if we have a packet */
|
2010-03-04 23:52:42 +00:00
|
|
|
/* check if it's a session request beacon */
|
|
|
|
if(type == PACKET_SESS_REQ) {
|
2010-03-03 23:48:29 +00:00
|
|
|
/* try to start a session */
|
2010-03-04 23:52:42 +00:00
|
|
|
sesid = open_session(p->addr);
|
2010-03-03 23:48:29 +00:00
|
|
|
}
|
2010-03-04 23:52:42 +00:00
|
|
|
} else {
|
2010-03-06 23:48:13 +00:00
|
|
|
// session_req(my_addr);
|
2010-03-03 23:48:29 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|