From: Michael Gernoth Date: Fri, 21 Jun 2013 09:18:12 +0000 (+0200) Subject: handle errata 1, add timeouts in rx X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/fhem-stuff/commitdiff_plain/b74270d7ccee16d14bfd0ec2ce4fbcf897f51698?ds=sidebyside handle errata 1, add timeouts in rx --- diff --git a/culfw/culfw-asksin-fix.diff b/culfw/culfw-asksin-fix.diff index 795ff41..bbe630f 100644 --- a/culfw/culfw-asksin-fix.diff +++ b/culfw/culfw-asksin-fix.diff @@ -19,7 +19,7 @@ Index: clib/rf_asksin.c 0x0B, 0x06, 0x0D, 0x21, 0x0E, 0x65, -@@ -26,18 +26,21 @@ +@@ -26,18 +26,22 @@ 0x11, 0x93, 0x12, 0x03, 0x15, 0x34, @@ -39,12 +39,13 @@ Index: clib/rf_asksin.c + 0x3e, 0xc3 }; -+static inline uint8_t read_cc1100_rxbytes(); ++static inline uint8_t read_cc1100_rxbytes(void); ++static inline void rf_asksin_reset_rx(void); + void rf_asksin_init(void) { -@@ -56,20 +59,30 @@ +@@ -56,20 +60,44 @@ my_delay_us(100); // load configuration @@ -67,7 +68,8 @@ Index: clib/rf_asksin.c } +// Workaround for CC1101 Errata 3 -+static inline uint8_t read_cc1100_rxbytes() ++static inline uint8_t ++read_cc1100_rxbytes(void) +{ + uint8_t rxbytes, rxbytes2; + @@ -77,11 +79,24 @@ Index: clib/rf_asksin.c + + return rxbytes; +} ++ ++static inline void ++rf_asksin_reset_rx(void) ++{ ++ ccStrobe( CC1100_SFRX ); ++ ccStrobe( CC1100_SIDLE ); ++ ccStrobe( CC1100_SNOP ); ++ ++ while (read_cc1100_rxbytes() & 0x7f) ++ cc1100_readReg(CC1100_RXFIFO); ++ ++ ccStrobe( CC1100_SRX ); ++} + void rf_asksin_task(void) { -@@ -77,18 +90,30 @@ +@@ -77,18 +105,41 @@ uint8_t dec[MAX_ASKSIN_MSG]; uint8_t rssi; uint8_t l; @@ -102,25 +117,37 @@ Index: clib/rf_asksin.c + rxfifo_cnt &= 0x7f; + enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len ++ rxfifo_cnt--; - if (enc[0]>=MAX_ASKSIN_MSG) - enc[0] = MAX_ASKSIN_MSG-1; +- if (enc[0]>=MAX_ASKSIN_MSG) +- enc[0] = MAX_ASKSIN_MSG-1; - ++ if (enc[0] >= MAX_ASKSIN_MSG) { ++ // Something went horribly wrong, out of sync? ++ rf_asksin_reset_rx(); ++ return; ++ } + -+ while ((enc[0] + 2) < (rxfifo_cnt - 1)) { // Wait for more data ++ l = 50; ++ while (l-- && ((enc[0] + 2) < rxfifo_cnt)) { // Wait for more data + my_delay_ms(1); -+ rxfifo_cnt = (read_cc1100_rxbytes() & 0x7f) + 1; ++ rxfifo_cnt = (read_cc1100_rxbytes() & 0x7f); ++ } ++ ++ if (!l) { ++ // Not enough data received, out of sync? ++ rf_asksin_reset_rx(); ++ return; + } + CC1100_ASSERT; cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO ); -@@ -97,13 +122,12 @@ +@@ -97,14 +148,19 @@ } rssi = cc1100_sendbyte( 0 ); - -+ l = cc1100_sendbyte( 0 ); + CC1100_DEASSERT; @@ -128,12 +155,20 @@ Index: clib/rf_asksin.c - ccStrobe( CC1100_SIDLE ); - ccStrobe( CC1100_SNOP ); - ccStrobe( CC1100_SRX ); ++ // We must not read the last byte from the RX fifo while RX is in progress (Errata 1) ++ while (((read_cc1100_rxbytes() & 0x7f) == 1) && (cc1100_readReg(CC1100_PKTSTATUS) & (1 << 3))) { ++ my_delay_ms(1); ++ } + ++ l = cc1100_readReg(CC1100_RXFIFO); ++ + if (!(l & 0x80)) // CRC not ok + continue; - ++ dec[0] = enc[0]; dec[1] = (~enc[1]) ^ 0x89; -@@ -113,7 +137,6 @@ + +@@ -113,7 +169,6 @@ dec[l] = enc[l] ^ dec[2]; @@ -141,7 +176,7 @@ Index: clib/rf_asksin.c if (tx_report & REP_BINTIME) { DC('a'); -@@ -131,26 +154,17 @@ +@@ -131,26 +186,17 @@ DNL(); } @@ -177,7 +212,7 @@ Index: clib/rf_asksin.c } void -@@ -173,20 +187,7 @@ +@@ -173,20 +219,7 @@ my_delay_ms(3); // 3ms: Found by trial and error } @@ -198,7 +233,7 @@ Index: clib/rf_asksin.c enc[0] = dec[0]; enc[1] = (~dec[1]) ^ 0x89; -@@ -195,6 +196,15 @@ +@@ -195,6 +228,15 @@ enc[l] = dec[l] ^ dec[2]; @@ -214,7 +249,7 @@ Index: clib/rf_asksin.c // send CC1100_ASSERT; cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO); -@@ -205,12 +215,17 @@ +@@ -205,12 +247,17 @@ CC1100_DEASSERT;