1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-11-04 23:49:42 +02:00

tools/: moved function to set transmit power from atrf-txrx to libatrf

- atrf-txrx/atrf-txrx.c (tx_pwr_230, tx_pwr_231, set_power): moved to
  lib/misctxrx.c
- include/misctxrx.h, lib/misctxr.c (set_power_step, set_power_dBm):
  separated dBm to index conversion from the actual operation
- atrf-txrx/atrf-txrx.c (main): use new set_power_dBm instead of old
  set_power
This commit is contained in:
Werner Almesberger 2011-04-12 16:37:05 -03:00
parent 8f7e5cdefe
commit 8934c062a9
3 changed files with 83 additions and 66 deletions

View File

@ -63,22 +63,6 @@ enum rx_res {
};
static double tx_pwr_230[] = {
3.0, 2.6, 2.1, 1.6,
1.1, 0.5, -0.2, -1.2,
-2.2, -3.2, -4.2, -5.2,
-7.2, -9.2, -12.2, -17.2
};
static double tx_pwr_231[] = {
3.0, 2.8, 2.3, 1.8,
1.3, 0.7, 0.0, -1,
-2, -3, -4, -5,
-7, -9, -12, -17
};
static volatile int run = 1;
@ -146,47 +130,6 @@ static void set_rate(struct atrf_dsc *dsc, uint8_t rate)
}
static void set_power(struct atrf_dsc *dsc, double power, int crc)
{
const double *tx_pwr;
int n;
uint8_t tmp;
switch (atrf_identify(dsc)) {
case artf_at86rf230:
tx_pwr = tx_pwr_230;
break;
case artf_at86rf231:
tx_pwr = tx_pwr_231;
break;
default:
abort();
}
for (n = 0; n != sizeof(tx_pwr_230)/sizeof(*tx_pwr_230)-1; n++)
if (tx_pwr[n] <= power)
break;
if (fabs(tx_pwr[n]-power) > 0.01)
fprintf(stderr, "TX power %.1f dBm\n", tx_pwr[n]);
switch (atrf_identify(dsc)) {
case artf_at86rf230:
atrf_reg_write(dsc, REG_PHY_TX_PWR,
(crc ? TX_AUTO_CRC_ON_230 : 0) | n);
break;
case artf_at86rf231:
tmp = atrf_reg_read(dsc, REG_PHY_TX_PWR);
tmp = (tmp & ~TX_PWR_MASK) | n;
atrf_reg_write(dsc, REG_PHY_TX_PWR, tmp);
atrf_reg_write(dsc, REG_TRX_CTRL_1,
crc ? TX_AUTO_CRC_ON : 0);
break;
default:
abort();
}
}
static void receive_message(struct atrf_dsc *dsc)
{
uint8_t buf[MAX_PSDU+1]; /* PSDU+LQI */
@ -642,15 +585,15 @@ int main(int argc, char *const *argv)
receive(dsc, pcap_file);
break;
case mode_per:
set_power(dsc, power, 0);
set_power_dBm(dsc, power, 0);
transmit_pattern(dsc, pause_s, 0);
break;
case mode_ping:
set_power(dsc, power, 1);
set_power_dBm(dsc, power, 1);
ping(dsc, pause_s, 0);
break;
case mode_cont_tx:
set_power(dsc, power, 0);
set_power_dBm(dsc, power, 0);
status = test_mode(dsc, cont_tx, NULL);
break;
default:
@ -679,25 +622,25 @@ int main(int argc, char *const *argv)
set_rate(dsc, rate);
switch (mode) {
case mode_msg:
set_power(dsc, power, 1);
set_power_dBm(dsc, power, 1);
transmit(dsc, argv[optind], times);
break;
case mode_per:
times = strtoul(argv[optind+1], &end, 0);
if (*end)
usage(*argv);
set_power(dsc, power, 0);
set_power_dBm(dsc, power, 0);
transmit_pattern(dsc, pause_s, times);
break;
case mode_ping:
pause_s = strtof(argv[optind], &end);
if (*end)
usage(*argv);
set_power(dsc, power, 1);
set_power_dBm(dsc, power, 1);
ping(dsc, pause_s, 1);
break;
case mode_cont_tx:
set_power(dsc, power, 0);
set_power_dBm(dsc, power, 0);
status = test_mode(dsc, cont_tx, argv[optind]);
break;
default:

View File

@ -1,8 +1,8 @@
/*
* include/misctxrx.h - Miscellaenous transceiver helper functions
*
* Written 2010 by Werner Almesberger
* Copyright 2010 Werner Almesberger
* 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
@ -21,4 +21,7 @@
uint8_t wait_for_interrupt(struct atrf_dsc *dsc, uint8_t wait_for,
uint8_t ignore, int sleep_us, int timeout);
void set_power_step(struct atrf_dsc *dsc, int power, int crc);
void set_power_dBm(struct atrf_dsc *dsc, double power, int crc);
#endif /* !MISCTXRX_H */

View File

@ -16,12 +16,16 @@
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <math.h>
#include "at86rf230.h"
#include "atrf.h"
#include "misctxrx.h"
/* ----- Interrupts -------------------------------------------------------- */
static volatile int run = 1;
@ -85,3 +89,70 @@ out:
raise(SIGINT);
return irq;
}
/* ----- Transmit power ---------------------------------------------------- */
static double tx_pwr_230[] = {
3.0, 2.6, 2.1, 1.6,
1.1, 0.5, -0.2, -1.2,
-2.2, -3.2, -4.2, -5.2,
-7.2, -9.2, -12.2, -17.2
};
static double tx_pwr_231[] = {
3.0, 2.8, 2.3, 1.8,
1.3, 0.7, 0.0, -1,
-2, -3, -4, -5,
-7, -9, -12, -17
};
void set_power_step(struct atrf_dsc *dsc, int power, int crc)
{
uint8_t tmp;
switch (atrf_identify(dsc)) {
case artf_at86rf230:
atrf_reg_write(dsc, REG_PHY_TX_PWR,
(crc ? TX_AUTO_CRC_ON_230 : 0) | power);
break;
case artf_at86rf231:
tmp = atrf_reg_read(dsc, REG_PHY_TX_PWR);
tmp = (tmp & ~TX_PWR_MASK) | power;
atrf_reg_write(dsc, REG_PHY_TX_PWR, tmp);
atrf_reg_write(dsc, REG_TRX_CTRL_1,
crc ? TX_AUTO_CRC_ON : 0);
break;
default:
abort();
}
}
void set_power_dBm(struct atrf_dsc *dsc, double power, int crc)
{
const double *tx_pwr;
int n;
switch (atrf_identify(dsc)) {
case artf_at86rf230:
tx_pwr = tx_pwr_230;
break;
case artf_at86rf231:
tx_pwr = tx_pwr_231;
break;
default:
abort();
}
for (n = 0; n != sizeof(tx_pwr_230)/sizeof(*tx_pwr_230)-1; n++)
if (tx_pwr[n] <= power)
break;
if (fabs(tx_pwr[n]-power) > 0.01)
fprintf(stderr, "TX power %.1f dBm\n", tx_pwr[n]);
set_power_step(dsc, n, crc);
}