contiki/tests/rftest-tx.c

165 lines
3.1 KiB
C
Raw Normal View History

2010-02-26 23:27:58 +00:00
#include <mc1322x.h>
#include <board.h>
2010-03-02 22:52:31 +00:00
#include <stdio.h>
2009-04-02 18:54:02 +00:00
2010-02-26 23:27:58 +00:00
#include "tests.h"
#include "config.h"
2009-04-02 18:54:02 +00:00
2009-05-21 00:12:39 +00:00
#define DELAY 100000
2010-03-02 23:23:23 +00:00
#define DATA 0x00401000
#define DEBUG_MACA 1
2009-04-02 18:54:02 +00:00
2009-04-13 22:19:13 +00:00
uint32_t ackBox[10];
#define command_xcvr_rx() \
do { \
maca_txlen = (uint32_t)1<<16; \
maca_dmatx = (uint32_t)&ackBox; \
maca_dmarx = DATA; \
maca_tmren = (maca_cpl_clk | maca_soft_clk); \
maca_control = (control_prm | control_asap | control_seq_rx); \
2010-02-26 23:27:58 +00:00
}while(0)
2009-04-13 22:19:13 +00:00
2009-05-21 00:12:39 +00:00
#define PAYLOAD_LEN 16 /* not including the extra 4 bytes for len+fcs+somethingelse */
2009-04-13 22:19:13 +00:00
/* maca dmatx needs extra 4 bytes for checksum */
/* needs + 4 bytes for len(1 byte) + fcs(2 bytes) + somethingelse */
#define command_xcvr_tx() \
do { \
2010-02-26 23:27:58 +00:00
maca_txlen = (uint32_t)(PAYLOAD_LEN+4); \
2009-04-13 22:19:13 +00:00
maca_dmatx = (uint32_t)DATA; \
maca_dmarx = (uint32_t)&ackBox; \
maca_control = (control_prm | control_mode_no_cca | \
control_asap | control_seq_tx); \
2010-02-26 23:27:58 +00:00
}while(0)
2009-04-13 22:19:13 +00:00
volatile uint8_t *data;
uint8_t count=0;
void fill_data(void) {
uint8_t i;
for(i=0; i<PAYLOAD_LEN; i++) {
data[i] = count++;
}
}
2009-04-02 18:54:02 +00:00
void main(void) {
volatile uint32_t i;
2009-04-13 22:19:13 +00:00
uint16_t status;
2009-04-02 18:54:02 +00:00
2010-02-26 23:27:58 +00:00
*GPIO_PAD_DIR0 = LED;
2009-04-13 22:19:13 +00:00
led_on();
2010-02-26 23:27:58 +00:00
uart_init(INC,MOD);
2009-04-13 22:19:13 +00:00
reset_maca();
radio_init();
vreg_init();
flyback_init();
init_phy();
2010-03-01 18:01:51 +00:00
/* trim the reference osc. to 24MHz */
pack_XTAL_CNTL(CTUNE_4PF, CTUNE, FTUNE, IBIAS);
2009-04-13 22:19:13 +00:00
set_power(0x0f); /* 0dbm */
set_channel(0); /* channel 11 */
2009-04-13 22:19:13 +00:00
*MACA_CONTROL = (1 << PRM) | (NO_CCA << MODE);
for(i=0; i<DELAY; i++) { continue; }
data = (void *)DATA;
2010-02-26 23:27:58 +00:00
*MACA_DMARX = DATA; /* put data somewhere */
*MACA_PREAMBLE = 0;
2010-02-26 23:27:58 +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));
2009-05-21 00:12:39 +00:00
2009-04-13 22:19:13 +00:00
fill_data();
command_xcvr_tx();
2009-04-02 18:54:02 +00:00
while(1) {
2009-04-13 22:19:13 +00:00
if(_is_action_complete_interrupt(maca_irq)) {
maca_clrirq = maca_irq;
2010-02-26 23:27:58 +00:00
status = *MACA_STATUS & 0x0000ffff;
2009-04-13 22:19:13 +00:00
switch(status)
{
case(cc_aborted):
{
2010-03-02 22:52:31 +00:00
printf("aborted\n\r");
2009-04-13 22:19:13 +00:00
ResumeMACASync();
break;
}
2009-04-13 22:19:13 +00:00
case(cc_not_completed):
{
2010-03-02 22:52:31 +00:00
printf("not completed\n\r");
2009-04-13 22:19:13 +00:00
ResumeMACASync();
break;
}
case(cc_timeout):
{
2010-03-02 22:52:31 +00:00
printf("timeout\n\r");
2009-04-13 22:19:13 +00:00
ResumeMACASync();
break;
}
case(cc_no_ack):
{
2010-03-02 22:52:31 +00:00
printf("no ack\n\r");
2009-04-13 22:19:13 +00:00
ResumeMACASync();
break;
}
case(cc_ext_timeout):
{
2010-03-02 22:52:31 +00:00
printf("ext timeout\n\r");
2009-04-13 22:19:13 +00:00
ResumeMACASync();
break;
}
case(cc_ext_pnd_timeout):
{
2010-03-02 22:52:31 +00:00
printf("ext pnd timeout\n\r");
2009-04-13 22:19:13 +00:00
ResumeMACASync();
break;
}
case(cc_success):
{
2010-03-02 22:52:31 +00:00
// printf("success\n\r");
2009-04-13 22:19:13 +00:00
2010-03-02 22:52:31 +00:00
printf("rftest-tx --- payload len+crc: 0x%02x timestamp: 0x%08x\n\r", PAYLOAD_LEN+4, maca_timestamp);
printf(" data: ");
2009-04-13 22:19:13 +00:00
for(i=0; i<PAYLOAD_LEN; i++) {
2010-03-02 22:52:31 +00:00
printf("%02x ",data[i]);
2009-04-13 22:19:13 +00:00
}
2010-03-02 22:52:31 +00:00
printf("\n\r");
2009-04-13 22:19:13 +00:00
toggle_led();
2009-04-13 22:19:13 +00:00
fill_data();
command_xcvr_tx();
break;
}
default:
{
2010-03-03 18:39:22 +00:00
printf("status: 0x%04x",status);
2009-04-13 22:19:13 +00:00
ResumeMACASync();
}
}
} else if (_is_filter_failed_interrupt(maca_irq)) {
2010-03-02 22:52:31 +00:00
printf("filter failed\n\r");
2009-04-13 22:19:13 +00:00
ResumeMACASync();
}
2009-04-02 18:54:02 +00:00
for(i=0; i<DELAY; i++) { continue; }
2009-04-13 22:19:13 +00:00
2009-04-02 18:54:02 +00:00
};
}