1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-12-26 07:49:54 +02:00

libatrf: further modularized transmit power setting and exported conversion

- lib/misctxrx.c (tx_pwr_230, tx_pwr_231): declare tables as "const"
- lib/misctxrx.c (POWER_TABLE_SIZE, set_power_dBm): don't open-code the
  table size calculation
- lib/misctxrx.c (tx_power_table, set_power_dBm): moved transmit power
  table selection out of set_power_dBm
- include/misctxrx.h (tx_power_dBm2step, tx_power_step2dBm),
  lib/misctxrx.c (tx_power_dBm2step, tx_power_step2dBm, set_power_dBm):
  moved conversion functions out of set_power_dBm and made them globally
  available
This commit is contained in:
Werner Almesberger 2011-04-12 18:41:03 -03:00
parent 8934c062a9
commit 1618868f9f
2 changed files with 45 additions and 14 deletions

View File

@ -21,6 +21,9 @@
uint8_t wait_for_interrupt(struct atrf_dsc *dsc, uint8_t wait_for,
uint8_t ignore, int sleep_us, int timeout);
int tx_power_dBm2step(struct atrf_dsc *dsc, double power);
double tx_power_step2dBm(struct atrf_dsc *dsc, int step);
void set_power_step(struct atrf_dsc *dsc, int power, int crc);
void set_power_dBm(struct atrf_dsc *dsc, double power, int crc);

View File

@ -94,7 +94,7 @@ out:
/* ----- Transmit power ---------------------------------------------------- */
static double tx_pwr_230[] = {
static const 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,
@ -102,7 +102,7 @@ static double tx_pwr_230[] = {
};
static double tx_pwr_231[] = {
static const double tx_pwr_231[] = {
3.0, 2.8, 2.3, 1.8,
1.3, 0.7, 0.0, -1,
-2, -3, -4, -5,
@ -110,6 +110,9 @@ static double tx_pwr_231[] = {
};
#define POWER_TABLE_SIZE (sizeof(tx_pwr_230)/sizeof(*tx_pwr_230))
void set_power_step(struct atrf_dsc *dsc, int power, int crc)
{
uint8_t tmp;
@ -132,27 +135,52 @@ void set_power_step(struct atrf_dsc *dsc, int power, int crc)
}
void set_power_dBm(struct atrf_dsc *dsc, double power, int crc)
static const double *tx_power_table(struct atrf_dsc *dsc)
{
const double *tx_pwr;
int n;
switch (atrf_identify(dsc)) {
case artf_at86rf230:
tx_pwr = tx_pwr_230;
break;
return tx_pwr_230;
case artf_at86rf231:
tx_pwr = tx_pwr_231;
return tx_pwr_231;
break;
default:
abort();
}
}
for (n = 0; n != sizeof(tx_pwr_230)/sizeof(*tx_pwr_230)-1; n++)
int tx_power_dBm2step(struct atrf_dsc *dsc, double power)
{
const double *tx_pwr = tx_power_table(dsc);
int n;
for (n = 0; n != POWER_TABLE_SIZE-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);
return n;
}
double tx_power_step2dBm(struct atrf_dsc *dsc, int step)
{
const double *tx_pwr = tx_power_table(dsc);
if (step < 0 || step > POWER_TABLE_SIZE)
abort();
return tx_pwr[step];
}
void set_power_dBm(struct atrf_dsc *dsc, double power, int crc)
{
int step;
double got;
step = tx_power_dBm2step(dsc, power);
got = tx_power_step2dBm(dsc, step);
if (fabs(got-power) > 0.01)
fprintf(stderr, "TX power %.1f dBm\n", got);
set_power_step(dsc, step, crc);
}