Commit 09bd1e8d authored by Tristan Gingold's avatar Tristan Gingold

Add a function to get ocxo current

parent ead60be5
......@@ -377,6 +377,20 @@ int libwr2rf_enable_check_ocxo(struct libwr2rf_dev *dev)
return warmup_time - v;
}
/* Read ocxo current sensor, return the current in mA. */
int libwr2rf_get_ocxo_current_ma(struct libwr2rf_dev *dev)
{
unsigned addr = WR2RF_VME_REGS_INIT + WR2RF_INIT_REGS_XADC;
unsigned val = libwr2rf_read16(dev, addr + (0x12 << 1));
/* See EDA-04387-V2 Sheet 24 (p43) Power for OCXO */
/* V= 40 * 0.05 Ohm * ocxo_cur */
double v = (val >> 4) / 4096.0;
return (v / 2.0) * 1000;
}
int libwr2rf_check_link_time(struct libwr2rf_dev *dev)
{
unsigned status;
......
......@@ -3,6 +3,9 @@
#include "io.h"
/* For ocxo */
int libwr2rf_get_ocxo_current_ma(struct libwr2rf_dev *dev);
/* For the main pll (ltc6950). */
void libwr2rf_pll_spi_init(struct libwr2rf_dev *dev);
uint8_t libwr2rf_pll_read(struct libwr2rf_dev *dev, unsigned reg);
......
......@@ -1329,6 +1329,8 @@ ocxo (struct libwr2rf_dev *dev, int argc, char **argv)
printf ("ocxo status: 0x%04x\n", v);
v = libwr2rf_read16(dev, WR2RF_VME_REGS_INIT + WR2RF_INIT_REGS_OCXO_UPTIME);
printf ("ocxo uptime: 0x%04x (%u)\n", v, v);
v = libwr2rf_get_ocxo_current_ma(dev);
printf ("ocxo current: %u mA\n", v);
}
else if (argc == 2 && strcmp (argv[1], "off") == 0) {
libwr2rf_write16(dev, WR2RF_VME_REGS_INIT + WR2RF_INIT_REGS_OCXO_CTRL, 0);
......@@ -1345,7 +1347,7 @@ ocxo (struct libwr2rf_dev *dev, int argc, char **argv)
#define XADC_FLAG_TEMP 1 /* Value is a temperature */
#define XADC_FLAG_POWR 2 /* Value is a voltage (unipolar) */
#define XADC_FLAG_OCXO_SENSE 3 /* ocxo current */
struct xadc_regs_desc {
const char *name;
unsigned flag;
......@@ -1375,14 +1377,14 @@ static const struct xadc_regs_desc xadc_regs[] =
{ NULL, 0},
/* 0x10 */
{ "vaux0", 0},
{ "vaux1", 0},
{ "vaux2", 0},
{ "vaux3", 0},
{ "vaux4", 0},
{ "vaux5", 0},
{ "vaux6", 0},
{ "vaux7", 0},
{ NULL, 0},
{ NULL, 0},
{ "vaux2", XADC_FLAG_OCXO_SENSE},
{ NULL, 0},
{ NULL, 0},
{ NULL, 0},
{ NULL, 0},
{ NULL, 0},
/* 0x18 */
{ NULL, 0},
......@@ -1498,6 +1500,15 @@ xadc_dump (struct libwr2rf_dev *dev, int argc, char **argv)
/* See ug480 eq 2-7 p 26 */
printf (" %1.02f V", (val >> 4) / 4096.0 * 3.0);
break;
case XADC_FLAG_OCXO_SENSE:
/* See EDA-04387-V2 Sheet 24 (p43) Power for OCXO */
/* V= 40 * 0.05 Ohm * ocxo_cur */
{
double v = (val >> 4) / 4096.0;
double a = v / 2.0;
printf (" %1.03f V -> %1.03f A", v, a);
}
break;
default:
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment