summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@mur.at>2015-03-03 05:15:57 +0100
committerChristian Pointner <equinox@mur.at>2015-03-03 05:15:57 +0100
commit6cc790e4fba215cdb236fee0e7b2afb0207ab32c (patch)
tree5147fcfc6f0a1c7ff64d7dfd270867db2d0b8148
parentadded manual dump for nomalized register access (diff)
hhd70: added simple task handling
implemented very basic receive task
-rw-r--r--software/hhd70dongle/hhd70dongle.c103
1 files changed, 94 insertions, 9 deletions
diff --git a/software/hhd70dongle/hhd70dongle.c b/software/hhd70dongle/hhd70dongle.c
index d1fb2db..44a2c30 100644
--- a/software/hhd70dongle/hhd70dongle.c
+++ b/software/hhd70dongle/hhd70dongle.c
@@ -47,6 +47,23 @@
#define DEFAULT_FREQ 437525000
int32_t current_freq_hz = DEFAULT_FREQ;
+
+typedef enum { none, receive, send, beacon } task_t;
+task_t current_task = none;
+task_t last_task = none;
+
+static char* task_to_string(cc1101_state_t state)
+{
+ switch(state) {
+ case none: return "none";
+ case receive: return "receiving";
+ case send: return "sending";
+ case beacon: return "beacon";
+ default: return "unknown";
+ }
+}
+
+
static void reset_hhd70(void)
{
printf("soft resetting HHD70.\r\n");
@@ -165,6 +182,8 @@ static void dump_register_normalized(void)
printf("RCCTRL1: 0x%02X\r\n", cc1101_get_rcctrl1_status());
}
+
+
static void handle_cmd(uint8_t cmd)
{
switch(cmd) {
@@ -173,8 +192,8 @@ static void handle_cmd(uint8_t cmd)
case 't': led_toggle(); printf("led TOGGLE\r\n"); break;
case '!': cc1101_soft_reset(); reset2bootloader(); break;
- case 'r': reset_hhd70(); break;
- case 'i': reinit_hhd70(); break;
+ case 'r': reset_hhd70(); current_task = none; break;
+ case 'i': reinit_hhd70(); current_task = none; break;
case 'F': current_freq_hz = DEFAULT_FREQ; update_current_freq(); break;
case '#': current_freq_hz+=100000; update_current_freq(); break;
@@ -184,13 +203,13 @@ 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': powerdown_hhd70(); break;
- case 'I': cc1101_idle(); print_status(); break;
- case 'O': osc_off_hhd70(); break;
- case 'C': cc1101_calibrate(); print_status(); break;
- case 'X': cc1101_fasttxon(); print_status(); break;
- case 'R': cc1101_rx(); print_status(); break;
- case 'T': cc1101_tx(); print_status(); break;
+ case 'P': powerdown_hhd70(); current_task = none; break;
+ case 'I': cc1101_idle(); print_status(); current_task = none; break;
+ case 'O': osc_off_hhd70(); current_task = none; break;
+ case 'C': cc1101_calibrate(); print_status(); current_task = none; break;
+ case 'X': cc1101_fasttxon(); print_status(); current_task = none; break;
+ case 'R': cc1101_rx(); print_status(); current_task = receive; break;
+ case 'T': cc1101_tx(); print_status(); current_task = send; break;
case 'f': print_actual_freq(); break;
case 's': print_status(); break;
@@ -201,6 +220,71 @@ static void handle_cmd(uint8_t cmd)
}
}
+uint8_t tempdata[255];
+
+static void do_receive_task(uint8_t first)
+{
+ static uint8_t pos = 0;
+ if(first) pos = 0;
+
+ cc1101_state_t s = cc1101_get_state();
+ switch(s) {
+ case fs_wakeup:
+ case calibrate:
+ case settling:
+ case rx:
+ case txrx_settling: break;
+ case rxfifo_overflow: {
+ printf("%sRX-Fifo overflow! - resetting fifo...\r\n", pos ? "\r\n": "");
+ cc1101_reset_rx_fifo();
+ pos = 0;
+ break;
+ }
+ default: {
+ printf("%sleaving receive task: invalid state '%s'\r\n", pos ? "\r\n": "", cc1101_state_to_string(s));
+ current_task = none;
+ return;
+ }
+ }
+
+ uint8_t r = cc1101_read_rxfifo(tempdata, 255);
+ if(r) {
+ uint8_t i;
+ for(i=0; i<r; ++i) {
+ pos++;
+ printf("%02X%s", tempdata[i], (pos==8) ? " " : " ");
+ if(pos >= 16) {
+ pos = 0;
+ printf("\r\n");
+ }
+ }
+ }
+}
+
+static void do_send_task(uint8_t first)
+{
+}
+
+static void do_beacon_task(uint8_t first)
+{
+}
+
+static void handle_task(void)
+{
+ uint8_t first = 0;
+ if(current_task != last_task) {
+ printf("switching to task: %s\r\n", task_to_string(current_task));
+ last_task = current_task;
+ first = 1;
+ }
+ switch(current_task) {
+ case receive: do_receive_task(first); return;
+ case send: do_send_task(first); return;
+ case beacon: do_beacon_task(first); return;
+ case none: return;
+ }
+}
+
int main(void)
{
MCUSR &= ~(1 << WDRF);
@@ -222,6 +306,7 @@ int main(void)
}
BytesReceived--;
}
+ handle_task();
usbio_task();
}