2010-02-26 23:44:39 +01:00
|
|
|
#include <mc1322x.h>
|
|
|
|
#include <board.h>
|
2010-03-03 19:39:14 +01:00
|
|
|
#include <stdio.h>
|
2009-04-01 23:57:02 +02:00
|
|
|
|
2010-02-26 23:44:39 +01:00
|
|
|
#include "tests.h"
|
|
|
|
#include "config.h"
|
2009-04-02 20:54:02 +02:00
|
|
|
|
|
|
|
#define DELAY 400000
|
|
|
|
#define DATA 0x00401000;
|
|
|
|
|
2009-04-08 00:19:00 +02:00
|
|
|
uint32_t ackBox[10];
|
|
|
|
|
2009-04-14 00:19:13 +02:00
|
|
|
#define MAX_PAYLOAD 128
|
|
|
|
volatile uint8_t data[MAX_PAYLOAD];
|
|
|
|
/* maca_rxlen is very important */
|
2009-04-08 00:19:00 +02:00
|
|
|
#define command_xcvr_rx() \
|
|
|
|
do { \
|
2009-04-14 00:19:13 +02:00
|
|
|
maca_txlen = ((0xff)<<16); \
|
2009-04-08 00:19:00 +02:00
|
|
|
maca_dmatx = (uint32_t)&ackBox; \
|
2010-02-26 23:44:39 +01:00
|
|
|
maca_dmarx = (uint32_t)data; \
|
2009-04-08 00:19:00 +02:00
|
|
|
maca_tmren = (maca_cpl_clk | maca_soft_clk); \
|
|
|
|
maca_control = (control_prm | control_asap | control_seq_rx); \
|
2010-02-26 23:44:39 +01:00
|
|
|
}while(0)
|
2009-04-08 00:19:00 +02:00
|
|
|
|
2009-06-22 18:35:39 +02:00
|
|
|
#define LED LED_GREEN
|
|
|
|
|
2010-02-26 23:44:39 +01:00
|
|
|
#define led_on() do { led = 1; *GPIO_DATA0 = LED; } while(0);
|
|
|
|
#define led_off() do { led = 0; *GPIO_DATA0 = 0x00000000; } while(0);
|
2009-04-13 21:54:10 +02:00
|
|
|
|
2010-02-26 23:44:39 +01:00
|
|
|
volatile uint8_t led;
|
2009-04-13 21:54:10 +02:00
|
|
|
void toggle_led(void) {
|
|
|
|
if(0 == led) {
|
|
|
|
led_on();
|
|
|
|
led = 1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
led_off();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-01 23:57:02 +02:00
|
|
|
void main(void) {
|
2009-04-02 20:54:02 +02:00
|
|
|
volatile uint32_t i;
|
2009-04-08 00:19:00 +02:00
|
|
|
uint16_t status;
|
2009-04-02 20:54:02 +02:00
|
|
|
|
2010-02-26 23:44:39 +01:00
|
|
|
*GPIO_PAD_DIR0 = LED;
|
2009-04-13 21:54:10 +02:00
|
|
|
led_on();
|
|
|
|
|
2010-02-26 23:44:39 +01:00
|
|
|
uart_init(INC,MOD);
|
2009-04-01 23:57:02 +02:00
|
|
|
|
2009-04-08 00:19:00 +02:00
|
|
|
reset_maca();
|
2009-04-08 00:52:12 +02:00
|
|
|
radio_init();
|
2009-04-11 23:17:37 +02:00
|
|
|
flyback_init();
|
|
|
|
vreg_init();
|
2009-04-03 00:05:13 +02:00
|
|
|
init_phy();
|
|
|
|
|
2010-03-01 19:01:51 +01:00
|
|
|
/* trim the reference osc. to 24MHz */
|
|
|
|
pack_XTAL_CNTL(CTUNE_4PF, CTUNE, FTUNE, IBIAS);
|
|
|
|
|
2009-04-13 20:11:18 +02:00
|
|
|
set_power(0x0f); /* 0dbm */
|
2009-08-04 16:54:23 +02:00
|
|
|
set_channel(0); /* channel 11 */
|
2009-04-08 00:19:00 +02:00
|
|
|
|
2010-02-26 23:44:39 +01:00
|
|
|
*MACA_CONTROL = SMAC_MACA_CNTL_INIT_STATE;
|
2009-04-03 00:05:13 +02:00
|
|
|
for(i=0; i<DELAY; i++) { continue; }
|
2009-04-02 20:54:02 +02:00
|
|
|
|
2010-02-26 23:44:39 +01:00
|
|
|
*MACA_DMARX = (uint32_t)data; /* put data somewhere */
|
|
|
|
*MACA_PREAMBLE = 0;
|
2009-04-08 00:19:00 +02:00
|
|
|
|
|
|
|
command_xcvr_rx();
|
2009-04-02 20:54:02 +02:00
|
|
|
|
|
|
|
while(1) {
|
2009-04-13 21:54:10 +02:00
|
|
|
|
|
|
|
if(_is_action_complete_interrupt(maca_irq)) {
|
|
|
|
maca_clrirq = maca_irq;
|
|
|
|
|
2010-02-26 23:44:39 +01:00
|
|
|
status = *MACA_STATUS & 0x0000ffff;
|
2009-04-13 21:54:10 +02:00
|
|
|
switch(status)
|
|
|
|
{
|
|
|
|
case(cc_aborted):
|
|
|
|
{
|
2010-03-03 19:39:14 +01:00
|
|
|
printf("aborted\n\r");
|
2009-04-13 21:54:10 +02:00
|
|
|
ResumeMACASync();
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
case(cc_not_completed):
|
|
|
|
{
|
2010-03-03 19:39:14 +01:00
|
|
|
printf("not completed\n\r");
|
2009-04-13 21:54:10 +02:00
|
|
|
ResumeMACASync();
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
case(cc_timeout):
|
|
|
|
{
|
2010-03-03 19:39:14 +01:00
|
|
|
printf("timeout\n\r");
|
2009-04-13 21:54:10 +02:00
|
|
|
ResumeMACASync();
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
case(cc_no_ack):
|
|
|
|
{
|
2010-03-03 19:39:14 +01:00
|
|
|
printf("no ack\n\r");
|
2009-04-13 21:54:10 +02:00
|
|
|
ResumeMACASync();
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
case(cc_ext_timeout):
|
|
|
|
{
|
2010-03-03 19:39:14 +01:00
|
|
|
printf("ext timeout\n\r");
|
2009-04-13 21:54:10 +02:00
|
|
|
ResumeMACASync();
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
case(cc_ext_pnd_timeout):
|
|
|
|
{
|
2010-03-03 19:39:14 +01:00
|
|
|
printf("ext pnd timeout\n\r");
|
2009-04-13 21:54:10 +02:00
|
|
|
ResumeMACASync();
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
case(cc_success):
|
|
|
|
{
|
2010-03-03 19:39:14 +01:00
|
|
|
// printf("success\n\r");
|
|
|
|
|
|
|
|
printf("rftest-rx --- maca_getrxlvl: 0x%02x timestamp: 0x%08x\n\r", maca_getrxlvl, maca_timestamp);
|
|
|
|
printf(" data: 0x%08x ", (uint32_t)data);
|
2010-02-26 23:44:39 +01:00
|
|
|
for(i=0; i<=(*MACA_GETRXLVL-4); i++) { /* fcs+somethingelse is not transferred by DMA */
|
2010-03-03 19:39:14 +01:00
|
|
|
printf("%02x ", data[i]);
|
2009-04-14 00:19:13 +02:00
|
|
|
}
|
2010-03-03 19:39:14 +01:00
|
|
|
printf("\n\r");
|
2009-04-13 21:54:10 +02:00
|
|
|
|
|
|
|
toggle_led();
|
|
|
|
|
2009-04-16 23:59:00 +02:00
|
|
|
ResumeMACASync();
|
|
|
|
|
2009-04-13 21:54:10 +02:00
|
|
|
command_xcvr_rx();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2010-03-03 19:39:14 +01:00
|
|
|
printf("status: %04x\n\r",status);
|
2009-04-13 21:54:10 +02:00
|
|
|
ResumeMACASync();
|
|
|
|
command_xcvr_rx();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (_is_filter_failed_interrupt(maca_irq)) {
|
2010-03-03 19:39:14 +01:00
|
|
|
printf("filter failed\n\r");
|
2009-04-13 21:54:10 +02:00
|
|
|
ResumeMACASync();
|
|
|
|
command_xcvr_rx();
|
2009-04-16 23:59:00 +02:00
|
|
|
} else if (_is_checksum_failed_interrupt(maca_irq)) {
|
2010-03-03 19:39:14 +01:00
|
|
|
printf("crc failed\n\r");
|
2009-04-16 23:59:00 +02:00
|
|
|
ResumeMACASync();
|
|
|
|
command_xcvr_rx();
|
2009-04-13 21:54:10 +02:00
|
|
|
}
|
|
|
|
|
2009-04-02 20:54:02 +02:00
|
|
|
|
2009-04-01 23:57:02 +02:00
|
|
|
};
|
|
|
|
}
|