summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@mur.at>2015-02-17 15:08:29 (GMT)
committerChristian Pointner <equinox@mur.at>2015-02-17 15:08:29 (GMT)
commit44dda8f30750d0cb2915e9cfadec4798caf88e0c (patch)
tree76b56ffcc1d43a828778795f6d14862572626a45
parenta40b7dcbd420f8c02ec3e6be341001c57a9610d7 (diff)
hhd70: reading state works now
-rw-r--r--software/avr.lib/cc1101.c56
-rw-r--r--software/avr.lib/cc1101.h5
-rw-r--r--software/avr.lib/cc1101_defines.h26
-rw-r--r--software/hhd70dongle/hhd70dongle.c11
4 files changed, 94 insertions, 4 deletions
diff --git a/software/avr.lib/cc1101.c b/software/avr.lib/cc1101.c
index 833adff..e846551 100644
--- a/software/avr.lib/cc1101.c
+++ b/software/avr.lib/cc1101.c
@@ -123,6 +123,62 @@ void cc1101_idle(void)
cc1101_spi_strobe_command(CC1101_CMD_SIDLE);
}
+char* cc1101_state_to_string(cc1101_state_t state)
+{
+ switch(state) {
+ case sleep: return "sleep";
+ case idle: return "idle";
+ case xoff: return "xoff";
+ case mancal: return "mancal";
+ case fs_wakeup: return "fs_wakeup";
+ case calibrate: return "calibrate";
+ case settling: return "settling";
+ case rx: return "rx";
+ case txrx_settling: return "txrx_settling";
+ case rxfifo_overflow: return "rxfifo_overflow";
+ case fstxon: return "fstxon";
+ case tx: return "tx";
+ case rxtx_settling: return "rxtx_settling";
+ case txfifo_underflow: return "txfifo_underflow";
+ default: return "unknown";
+ }
+}
+
+static cc1101_state_t cc1101_marcstate_to_state(uint8_t marcstate)
+{
+ switch(marcstate) {
+ case CC1101_MARCSTATE_SLEEP: return sleep;
+ case CC1101_MARCSTATE_IDLE: return idle;
+ case CC1101_MARCSTATE_XOFF: return xoff;
+ case CC1101_MARCSTATE_VCOON_MC:
+ case CC1101_MARCSTATE_REGON_MC:
+ case CC1101_MARCSTATE_MANCAL: return mancal;
+ case CC1101_MARCSTATE_VCOON:
+ case CC1101_MARCSTATE_REGON: return fs_wakeup;
+ case CC1101_MARCSTATE_STARTCAL: return calibrate;
+ case CC1101_MARCSTATE_BWBOOST:
+ case CC1101_MARCSTATE_FS_LOCK:
+ case CC1101_MARCSTATE_IFADCON: return settling;
+ case CC1101_MARCSTATE_ENDCAL: return calibrate;
+ case CC1101_MARCSTATE_RX:
+ case CC1101_MARCSTATE_RX_END:
+ case CC1101_MARCSTATE_RX_RST: return rx;
+ case CC1101_MARCSTATE_TXRX_SWITCH: return txrx_settling;
+ case CC1101_MARCSTATE_RXFIFO_OVERFLOW: return rxfifo_overflow;
+ case CC1101_MARCSTATE_FSTXON: return fstxon;
+ case CC1101_MARCSTATE_TX:
+ case CC1101_MARCSTATE_TX_END: return tx;
+ case CC1101_MARCSTATE_RXTX_SWITCH: return rxtx_settling;
+ case CC1101_MARCSTATE_TXFIFO_UNDERFLOW: return txfifo_underflow;
+ default: return unknown;
+ }
+}
+
+cc1101_state_t cc1101_get_state(void)
+{
+ return cc1101_marcstate_to_state(cc1101_spi_read_register(CC1101_REG_RO_MARCSTATE));
+}
+
void cc1101_set_freq_hz(uint32_t hz)
{
uint32_t freq = (uint32_t)((float)hz / drv.freq_corr);
diff --git a/software/avr.lib/cc1101.h b/software/avr.lib/cc1101.h
index 6e9e657..6f2ec4c 100644
--- a/software/avr.lib/cc1101.h
+++ b/software/avr.lib/cc1101.h
@@ -23,6 +23,10 @@
#ifndef SPREADAVR_cc1101_h_INCLUDED
#define SPREADAVR_cc1101_h_INCLUDED
+typedef enum { unknown, sleep, idle, xoff, mancal, fs_wakeup, calibrate, settling, rx, txrx_settling,
+ rxfifo_overflow, fstxon, tx, rxtx_settling, txfifo_underflow } cc1101_state_t;
+char* cc1101_state_to_string(cc1101_state_t);
+
#define CC1101_FREQ_CORR(xtal) ((float)(xtal/65536.0))
typedef struct {
@@ -41,6 +45,7 @@ void cc1101_soft_reset(void);
void cc1101_powerdown(void);
void cc1101_idle(void);
+cc1101_state_t cc1101_get_state(void);
void cc1101_set_freq_hz(uint32_t hz);
uint32_t cc1101_get_freq_hz(void);
diff --git a/software/avr.lib/cc1101_defines.h b/software/avr.lib/cc1101_defines.h
index 51ba6ea..a257e75 100644
--- a/software/avr.lib/cc1101_defines.h
+++ b/software/avr.lib/cc1101_defines.h
@@ -140,7 +140,31 @@
#define CC1101_STATUS_TXFIFO_OVERFLOW(x) ((x & 0b01110000) == 0b01110000)
#define CC1101_STATUS_FIFO_BYTES_AVAILABLE(x) (x & 0b00001111)
-
#define CC1101_FIFO_MAX_LEN 64
+
+#define CC1101_MARCSTATE_SLEEP 0x00
+#define CC1101_MARCSTATE_IDLE 0x01
+#define CC1101_MARCSTATE_XOFF 0x02
+#define CC1101_MARCSTATE_VCOON_MC 0x03
+#define CC1101_MARCSTATE_REGON_MC 0x04
+#define CC1101_MARCSTATE_MANCAL 0x05
+#define CC1101_MARCSTATE_VCOON 0x06
+#define CC1101_MARCSTATE_REGON 0x07
+#define CC1101_MARCSTATE_STARTCAL 0x08
+#define CC1101_MARCSTATE_BWBOOST 0x09
+#define CC1101_MARCSTATE_FS_LOCK 0x0A
+#define CC1101_MARCSTATE_IFADCON 0x0B
+#define CC1101_MARCSTATE_ENDCAL 0x0C
+#define CC1101_MARCSTATE_RX 0x0D
+#define CC1101_MARCSTATE_RX_END 0x0E
+#define CC1101_MARCSTATE_RX_RST 0x0F
+#define CC1101_MARCSTATE_TXRX_SWITCH 0x10
+#define CC1101_MARCSTATE_RXFIFO_OVERFLOW 0x11
+#define CC1101_MARCSTATE_FSTXON 0x12
+#define CC1101_MARCSTATE_TX 0x13
+#define CC1101_MARCSTATE_TX_END 0x14
+#define CC1101_MARCSTATE_RXTX_SWITCH 0x15
+#define CC1101_MARCSTATE_TXFIFO_UNDERFLOW 0x16
+
#endif
diff --git a/software/hhd70dongle/hhd70dongle.c b/software/hhd70dongle/hhd70dongle.c
index 482be70..35d2d38 100644
--- a/software/hhd70dongle/hhd70dongle.c
+++ b/software/hhd70dongle/hhd70dongle.c
@@ -59,6 +59,12 @@ static void reinit_hhd70(void)
cc1101_reg_init();
}
+static void powerdown_hhd70(void)
+{
+ printf("sending CC1101 to sleep.\r\n");
+ cc1101_powerdown();
+}
+
static uint32_t print_actual_freq(void)
{
uint32_t f = cc1101_get_freq_hz();
@@ -87,8 +93,7 @@ static void update_current_freq(void)
static void print_status(void)
{
- printf("HHD70 status:\r\n");
- printf(" to be implemented...\r\n");
+ printf("current state: %s\r\n", cc1101_state_to_string(cc1101_get_state()));
}
static void handle_cmd(uint8_t cmd)
@@ -110,7 +115,7 @@ static void handle_cmd(uint8_t cmd)
case '-': current_freq_hz-=10000; update_current_freq(); break;
case '_': current_freq_hz-=100000; update_current_freq(); break;
- case 'P': cc1101_powerdown(); print_status(); break;
+ case 'P': powerdown_hhd70(); break;
case 'I': cc1101_idle(); print_status(); break;
case 'f': print_actual_freq(); break;