mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-11-05 04:20:37 +02:00
tools/: moved constant wave test mode code to libatrf (for sharing)
- lib/Makefile (OBJS), include/cwtest.h (cw_test_begin, cw_test_end), lib/cwtest.c (enter_test_mode_230, enter_test_mode_231, cw_test_begin, cw_test_end): moved constant wave test mode setup over from atrf-txrx.c - atrf-txrx/atrf-txrx.c (transmit_pattern): use functions from cwtest.o
This commit is contained in:
parent
fc1ad9fffd
commit
4b07e5c894
@ -24,6 +24,7 @@
|
||||
#include "at86rf230.h"
|
||||
#include "atrf.h"
|
||||
#include "misctxrx.h"
|
||||
#include "cwtest.h"
|
||||
|
||||
#include "pcap.h"
|
||||
|
||||
@ -341,74 +342,6 @@ static void transmit(struct atrf_dsc *dsc, const char *msg, int times)
|
||||
}
|
||||
|
||||
|
||||
static void enter_test_mode_230(struct atrf_dsc *dsc, uint8_t cont_tx)
|
||||
{
|
||||
atrf_buf_write(dsc, "", 1);
|
||||
atrf_reg_write(dsc, REG_CONT_TX_0, CONT_TX_MAGIC);
|
||||
atrf_reg_write(dsc, REG_CONT_TX_1, cont_tx);
|
||||
|
||||
if (!atrf_test_mode(dsc)) {
|
||||
atrf_reset_rf(dsc);
|
||||
fprintf(stderr, "device does not support test mode\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
|
||||
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START);
|
||||
}
|
||||
|
||||
|
||||
static void enter_test_mode_231(struct atrf_dsc *dsc, uint8_t cont_tx)
|
||||
{
|
||||
uint8_t buf[127];
|
||||
uint8_t status;
|
||||
|
||||
switch (cont_tx) {
|
||||
case CONT_TX_M2M:
|
||||
fprintf(stderr,
|
||||
"-2 MHz mode is not supported by the AT86RF231\n");
|
||||
atrf_close(dsc);
|
||||
exit(1);
|
||||
case CONT_TX_M500K:
|
||||
memset(buf, 0, sizeof(buf));
|
||||
break;
|
||||
case CONT_TX_P500K:
|
||||
memset(buf, 0xff, sizeof(buf));
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
||||
atrf_reg_write(dsc, REG_IRQ_MASK, IRQ_PLL_LOCK); /* 2 */
|
||||
atrf_reg_write(dsc, REG_TRX_CTRL_1, 0); /* 3 */
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_FORCE_TRX_OFF); /* 4 */
|
||||
/* deleted step 5 - we don't need to enable CLKM */
|
||||
|
||||
status = atrf_reg_read(dsc, REG_TRX_STATUS) & TRX_STATUS_MASK; /* 8 */
|
||||
if (status != TRX_STATUS_TRX_OFF) {
|
||||
fprintf(stderr, "expected status 0x%02x, got 0x%02x\n",
|
||||
TRX_STATUS_TRX_OFF, status);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
atrf_reg_write(dsc, REG_CONT_TX_0, CONT_TX_MAGIC); /* 9 */
|
||||
atrf_reg_write(dsc, REG_TRX_CTRL_2, OQPSK_DATA_RATE_2000); /*10 */
|
||||
atrf_reg_write(dsc, REG_RX_CTRL, 0xa7); /*11 */
|
||||
|
||||
atrf_buf_write(dsc, buf, sizeof(buf)); /*12 */
|
||||
|
||||
atrf_reg_write(dsc, REG_PART_NUM, 0x54); /*13 */
|
||||
atrf_reg_write(dsc, REG_PART_NUM, 0x46); /*14 */
|
||||
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON); /*15 */
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 0); /*16 */
|
||||
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START); /*17 */
|
||||
}
|
||||
|
||||
|
||||
static void transmit_pattern(struct atrf_dsc *dsc, double pause_s, int times)
|
||||
{
|
||||
uint8_t buf[MAX_PSDU];
|
||||
@ -534,16 +467,7 @@ static int test_mode(struct atrf_dsc *dsc, uint8_t cont_tx, const char *cmd)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
switch (atrf_identify(dsc)) {
|
||||
case artf_at86rf230:
|
||||
enter_test_mode_230(dsc, cont_tx);
|
||||
break;
|
||||
case artf_at86rf231:
|
||||
enter_test_mode_231(dsc, cont_tx);
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
cw_test_begin(dsc, cont_tx);
|
||||
|
||||
if (cmd)
|
||||
status = system(cmd);
|
||||
@ -552,10 +476,7 @@ static int test_mode(struct atrf_dsc *dsc, uint8_t cont_tx, const char *cmd)
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
if (atrf_identify(dsc) == artf_at86rf231)
|
||||
atrf_reg_write(dsc, REG_PART_NUM, 0);
|
||||
|
||||
atrf_reset_rf(dsc);
|
||||
cw_test_end(dsc);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
25
tools/include/cwtest.h
Normal file
25
tools/include/cwtest.h
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* include/cwtest.h - AT86RF230/231 constant wave test mode
|
||||
*
|
||||
* Written 2011 by Werner Almesberger
|
||||
* Copyright 2011 Werner Almesberger
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef CWTEST_H
|
||||
#define CWTEST_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "atrf.h"
|
||||
|
||||
|
||||
void cw_test_begin(struct atrf_dsc *dsc, uint8_t cont_tx);
|
||||
void cw_test_end(struct atrf_dsc *dsc);
|
||||
|
||||
#endif /* !CW_TEST_H */
|
@ -19,7 +19,7 @@ OBJS_host = atusb.o usbopen.o
|
||||
OBJS_ben_jlime = atben.o
|
||||
OBJS_ben_openwrt = atben.o
|
||||
|
||||
OBJS = atrf.o misctxrx.o $(OBJS_$(TARGET))
|
||||
OBJS = atrf.o misctxrx.o cwtest.o $(OBJS_$(TARGET))
|
||||
|
||||
.PHONY: all clean spotless
|
||||
|
||||
|
115
tools/lib/cwtest.c
Normal file
115
tools/lib/cwtest.c
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* lib/cwtest.c - Set up AT86RF230/231 constant wave test mode
|
||||
*
|
||||
* Written 2010-2011 by Werner Almesberger
|
||||
* Copyright 2010-2011 Werner Almesberger
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "at86rf230.h"
|
||||
#include "atrf.h"
|
||||
#include "misctxrx.h"
|
||||
|
||||
#include "cwtest.h"
|
||||
|
||||
|
||||
static void enter_test_mode_230(struct atrf_dsc *dsc, uint8_t cont_tx)
|
||||
{
|
||||
atrf_buf_write(dsc, "", 1);
|
||||
atrf_reg_write(dsc, REG_CONT_TX_0, CONT_TX_MAGIC);
|
||||
atrf_reg_write(dsc, REG_CONT_TX_1, cont_tx);
|
||||
|
||||
if (!atrf_test_mode(dsc)) {
|
||||
atrf_reset_rf(dsc);
|
||||
fprintf(stderr, "device does not support test mode\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
|
||||
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START);
|
||||
}
|
||||
|
||||
|
||||
static void enter_test_mode_231(struct atrf_dsc *dsc, uint8_t cont_tx)
|
||||
{
|
||||
uint8_t buf[127];
|
||||
uint8_t status;
|
||||
|
||||
switch (cont_tx) {
|
||||
case CONT_TX_M2M:
|
||||
fprintf(stderr,
|
||||
"-2 MHz mode is not supported by the AT86RF231\n");
|
||||
atrf_close(dsc);
|
||||
exit(1);
|
||||
case CONT_TX_M500K:
|
||||
memset(buf, 0, sizeof(buf));
|
||||
break;
|
||||
case CONT_TX_P500K:
|
||||
memset(buf, 0xff, sizeof(buf));
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
||||
atrf_reg_write(dsc, REG_IRQ_MASK, IRQ_PLL_LOCK); /* 2 */
|
||||
atrf_reg_write(dsc, REG_TRX_CTRL_1, 0); /* 3 */
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_FORCE_TRX_OFF); /* 4 */
|
||||
/* deleted step 5 - we don't need to enable CLKM */
|
||||
|
||||
status = atrf_reg_read(dsc, REG_TRX_STATUS) & TRX_STATUS_MASK; /* 8 */
|
||||
if (status != TRX_STATUS_TRX_OFF) {
|
||||
fprintf(stderr, "expected status 0x%02x, got 0x%02x\n",
|
||||
TRX_STATUS_TRX_OFF, status);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
atrf_reg_write(dsc, REG_CONT_TX_0, CONT_TX_MAGIC); /* 9 */
|
||||
atrf_reg_write(dsc, REG_TRX_CTRL_2, OQPSK_DATA_RATE_2000); /*10 */
|
||||
atrf_reg_write(dsc, REG_RX_CTRL, 0xa7); /*11 */
|
||||
|
||||
atrf_buf_write(dsc, buf, sizeof(buf)); /*12 */
|
||||
|
||||
atrf_reg_write(dsc, REG_PART_NUM, 0x54); /*13 */
|
||||
atrf_reg_write(dsc, REG_PART_NUM, 0x46); /*14 */
|
||||
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON); /*15 */
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 0); /*16 */
|
||||
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START); /*17 */
|
||||
}
|
||||
|
||||
|
||||
void cw_test_begin(struct atrf_dsc *dsc, uint8_t cont_tx)
|
||||
{
|
||||
switch (atrf_identify(dsc)) {
|
||||
case artf_at86rf230:
|
||||
enter_test_mode_230(dsc, cont_tx);
|
||||
break;
|
||||
case artf_at86rf231:
|
||||
enter_test_mode_231(dsc, cont_tx);
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cw_test_end(struct atrf_dsc *dsc)
|
||||
{
|
||||
if (atrf_identify(dsc) == artf_at86rf231)
|
||||
atrf_reg_write(dsc, REG_PART_NUM, 0);
|
||||
|
||||
atrf_reset_rf(dsc);
|
||||
}
|
Loading…
Reference in New Issue
Block a user