===================================================================
--- clib/rf_asksin.c (revision 373)
+++ clib/rf_asksin.c (working copy)
-@@ -11,7 +11,7 @@
+@@ -11,8 +11,8 @@
uint8_t asksin_on = 0;
-const uint8_t PROGMEM ASKSIN_CFG[50] = {
+- 0x00, 0x07,
+const uint8_t PROGMEM ASKSIN_CFG[] = {
- 0x00, 0x07,
++ 0x00, 0x01,
0x02, 0x2e,
0x03, 0x0d,
-@@ -26,16 +26,17 @@
+ 0x04, 0xE9,
+@@ -26,18 +26,21 @@
0x11, 0x93,
0x12, 0x03,
0x15, 0x34,
- 0x17, 0x30, // always go into IDLE
-+ 0x17, 0x3F, // always go into RX after TX, CCA, ELV uses 0x03
++ 0x17, 0x33, // go into RX after TX, CCA; ELV uses 0x03
0x18, 0x18,
0x19, 0x16,
0x1B, 0x43,
+ 0x3e, 0xc3
};
++static void rf_asksin_reset_rx(void);
++
void
-@@ -56,18 +57,16 @@
+ rf_asksin_init(void)
+ {
+@@ -56,20 +59,27 @@
my_delay_us(100);
// load configuration
+ ccRX();
}
++static void
++rf_asksin_reset_rx(void)
++{
++ ccStrobe( CC1100_SFRX );
++ ccStrobe( CC1100_SIDLE );
++ ccStrobe( CC1100_SNOP );
++ ccStrobe( CC1100_SRX );
++}
++
void
-@@ -77,80 +76,74 @@
- uint8_t dec[MAX_ASKSIN_MSG];
- uint8_t rssi;
- uint8_t l;
-+ uint8_t rxfifo_cnt;
-
- if(!asksin_on)
- return;
+ rf_asksin_task(void)
+ {
+@@ -83,12 +93,14 @@
// see if a CRC OK pkt has been arrived
if (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
-+ while((rxfifo_cnt = cc1100_readReg(CC1100_RXBYTES)) != 0x00) {
-+ if (rxfifo_cnt & 0x80) // Overflow
-+ break;
-
-- enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
-+ enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
+-
+ enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
- if (enc[0]>=MAX_ASKSIN_MSG)
- enc[0] = MAX_ASKSIN_MSG-1;
-
-- CC1100_ASSERT;
-- cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
--
-- for (uint8_t i=0; i<enc[0]; i++) {
-- enc[i+1] = cc1100_sendbyte( 0 );
-- }
--
-- rssi = cc1100_sendbyte( 0 );
++ if (enc[0] >= MAX_ASKSIN_MSG) {
++ // Something went horribly wrong, out of sync?
++ rf_asksin_reset_rx();
++ return;
++ }
++
+ CC1100_ASSERT;
+ cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
+
+@@ -97,12 +109,10 @@
+ }
+
+ rssi = cc1100_sendbyte( 0 );
-
-- CC1100_DEASSERT;
-+ if (enc[0]>=MAX_ASKSIN_MSG)
-+ enc[0] = MAX_ASKSIN_MSG-1;
-+
-+ CC1100_ASSERT;
-+ cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
-+
-+ for (uint8_t i=0; i<enc[0]; i++) {
-+ enc[i+1] = cc1100_sendbyte( 0 );
-+ }
-+
-+ rssi = cc1100_sendbyte( 0 );
-+ /* LQI = */ cc1100_sendbyte( 0 );
++ l = cc1100_sendbyte( 0 );
++
+ CC1100_DEASSERT;
- ccStrobe( CC1100_SFRX );
- ccStrobe( CC1100_SIDLE );
- ccStrobe( CC1100_SNOP );
-- ccStrobe( CC1100_SRX );
-+ CC1100_DEASSERT;
+ ccStrobe( CC1100_SRX );
-- dec[0] = enc[0];
-- dec[1] = (~enc[1]) ^ 0x89;
--
-- for (l = 2; l < dec[0]; l++)
-- dec[l] = (enc[l-1] + 0xdc) ^ enc[l];
--
-- dec[l] = enc[l] ^ dec[2];
+ dec[0] = enc[0];
+@@ -113,7 +123,6 @@
+
+ dec[l] = enc[l] ^ dec[2];
+
-
--
-- if (tx_report & REP_BINTIME) {
-+ while(cc1100_readReg(CC1100_RXBYTES) & 0x7f)
-+ cc1100_readReg( CC1100_RXFIFO );
-+
-+ dec[0] = enc[0];
-+ dec[1] = (~enc[1]) ^ 0x89;
-
-- DC('a');
-- for (uint8_t i=0; i<=dec[0]; i++)
-- DC( dec[i] );
--
-- } else {
-- DC('A');
-+ for (l = 2; l < dec[0]; l++)
-+ dec[l] = (enc[l-1] + 0xdc) ^ enc[l];
+ if (tx_report & REP_BINTIME) {
-- for (uint8_t i=0; i<=dec[0]; i++)
-- DH2( dec[i] );
-+ dec[l] = enc[l] ^ dec[2];
+ DC('a');
+@@ -131,26 +140,17 @@
-- if (tx_report & REP_RSSI)
-- DH2(rssi);
--
-- DNL();
-+ if (tx_report & REP_BINTIME) {
-+
-+ DC('a');
-+ for (uint8_t i=0; i<=dec[0]; i++)
-+ DC( dec[i] );
-+
-+ } else {
-+ DC('A');
-+
-+ for (uint8_t i=0; i<=dec[0]; i++)
-+ DH2( dec[i] );
-+
-+ if (tx_report & REP_RSSI)
-+ DH2(rssi);
-+
-+ DNL();
-+ }
+ DNL();
}
--
++ }
+
- return;
-
++ switch(cc1100_readReg( CC1100_MARCSTATE )) {
++ case MARCSTATE_RXFIFO_OVERFLOW:
++ ccStrobe( CC1100_SFRX );
++ case MARCSTATE_IDLE:
++ ccStrobe( CC1100_SIDLE );
++ ccStrobe( CC1100_SNOP );
++ ccStrobe( CC1100_SRX );
++ break;
}
-
-
- break;
-
- }
-
-+ switch(cc1100_readReg( CC1100_MARCSTATE )) {
-+ case MARCSTATE_RXFIFO_OVERFLOW:
-+ ccStrobe( CC1100_SFRX );
-+ case MARCSTATE_IDLE:
-+ ccStrobe( CC1100_SIDLE );
-+ ccStrobe( CC1100_SNOP );
-+ ccStrobe( CC1100_SRX );
-+ break;
-+ }
+-
}
void
-@@ -173,20 +166,7 @@
+@@ -173,20 +173,7 @@
my_delay_ms(3); // 3ms: Found by trial and error
}
enc[0] = dec[0];
enc[1] = (~dec[1]) ^ 0x89;
-@@ -195,6 +175,15 @@
+@@ -195,6 +182,15 @@
enc[l] = dec[l] ^ dec[2];
// send
CC1100_ASSERT;
cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
-@@ -205,12 +194,17 @@
+@@ -205,12 +201,17 @@
CC1100_DEASSERT;