summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Daniel <cd@maintech.de>2012-03-06 15:29:33 +0100
committerChristian Daniel <cd@maintech.de>2012-03-06 15:29:33 +0100
commit4683c1c21a32604f4e24cc6596f8736f63b8f251 (patch)
tree5003beadc8f889f87e45e918bf432f5d85e90626
parent7abdbca85c634752a024675a128014464edc1c40 (diff)
tuner_e4k: add manual i/q correction
-rw-r--r--firmware/include/tuner_e4k.h2
-rw-r--r--firmware/sdr-test-project/main.c23
-rw-r--r--firmware/src/tuner_e4k.c25
3 files changed, 50 insertions, 0 deletions
diff --git a/firmware/include/tuner_e4k.h b/firmware/include/tuner_e4k.h
index 26b9eaf..3e5e498 100644
--- a/firmware/include/tuner_e4k.h
+++ b/firmware/include/tuner_e4k.h
@@ -207,6 +207,8 @@ int sam3u_e4k_init(struct e4k_state *e4k, void *i2c, uint8_t slave_addr);
void sam3u_e4k_power(struct e4k_state *e4k, int on);
void sam3u_e4k_stby(struct e4k_state *e4k, int on);
+
+int e4k_manual_dc_offset(struct e4k_state *e4k, int8_t iofs, int8_t irange, int8_t qofs, int8_t qrange);
int e4k_dc_offset_calibrate(struct e4k_state *e4k);
int e4k_dc_offset_gen_table(struct e4k_state *e4k);
diff --git a/firmware/sdr-test-project/main.c b/firmware/sdr-test-project/main.c
index e46ea03..326b5a7 100644
--- a/firmware/sdr-test-project/main.c
+++ b/firmware/sdr-test-project/main.c
@@ -313,6 +313,27 @@ static int cmd_tuner_commonmode(struct cmd_state *cs, enum cmd_op op,
return 0;
}
+static int cmd_tuner_iqofs(struct cmd_state *cs, enum cmd_op op,
+ const char *cmd, int argc, char ** argv)
+{
+ int iofs;
+ int qofs;
+ int irange;
+ int qrange;
+
+ if(op != CMD_OP_SET)
+ return -EINVAL;
+ if(argc < 4)
+ return -EINVAL;
+
+ iofs = strtol(argv[0], NULL, 10);
+ qofs = strtol(argv[1], NULL, 10);
+ irange = strtol(argv[2], NULL, 10);
+ qrange = strtol(argv[3], NULL, 10);
+
+ return e4k_manual_dc_offset(&e4k, iofs, irange, qofs, qrange);
+}
+
static struct cmd cmds[] = {
{ "tuner.init", CMD_OP_EXEC, cmd_tuner_init,
"Initialize the tuner" },
@@ -332,6 +353,8 @@ static struct cmd cmds[] = {
"Generate DC offset table" },
{ "tuner.commonmode", CMD_OP_SET, cmd_tuner_commonmode,
"Switch common mode voltage" },
+ { "tuner.iqofs", CMD_OP_SET, cmd_tuner_iqofs,
+ "Manually set I/Q offset and correction range" },
{ "si570.freq", CMD_OP_SET|CMD_OP_GET, cmd_si570_freq,
"Change the SI570 clock frequency" },
diff --git a/firmware/src/tuner_e4k.c b/firmware/src/tuner_e4k.c
index ddbecbe..dfd9640 100644
--- a/firmware/src/tuner_e4k.c
+++ b/firmware/src/tuner_e4k.c
@@ -727,6 +727,31 @@ int e4k_commonmode_set(struct e4k_state *e4k, int8_t value)
/***********************************************************************
* DC Offset */
+int e4k_manual_dc_offset(struct e4k_state *e4k, int8_t iofs, int8_t irange, int8_t qofs, int8_t qrange)
+{
+ int res;
+
+ if((iofs < 0x00) || (iofs > 0x3f))
+ return -EINVAL;
+ if((irange < 0x00) || (irange > 0x03))
+ return -EINVAL;
+ if((qofs < 0x00) || (qofs > 0x3f))
+ return -EINVAL;
+ if((qrange < 0x00) || (qrange > 0x03))
+ return -EINVAL;
+
+ res = e4k_reg_set_mask(e4k, E4K_REG_DC2, 0x3f, iofs);
+ if(res < 0)
+ return res;
+
+ res = e4k_reg_set_mask(e4k, E4K_REG_DC3, 0x3f, qofs);
+ if(res < 0)
+ return res;
+
+ res = e4k_reg_set_mask(e4k, E4K_REG_DC4, 0x33, (qrange << 4) | irange);
+ return res;
+}
+
/*! \brief Perform a DC offset calibration right now
* \param[e4k] handle to the tuner chip
*/