]> git.zerfleddert.de Git - fhem-stuff/blobdiff - culfw/culfw-asksin-fix.diff
go back to hardware packet handling
[fhem-stuff] / culfw / culfw-asksin-fix.diff
index 795ff4107d6f6ac13c7e4ae7afe868d45aab6d8c..168ad477b42dfdda427084da0dcdcbcf1be4ce5f 100644 (file)
@@ -2,7 +2,7 @@ Index: clib/rf_asksin.c
 ===================================================================
 --- clib/rf_asksin.c   (revision 373)
 +++ clib/rf_asksin.c   (working copy)
-@@ -11,13 +11,13 @@
+@@ -11,8 +11,8 @@
  
  uint8_t asksin_on = 0;
  
@@ -13,18 +13,12 @@ Index: clib/rf_asksin.c
       0x02, 0x2e,
       0x03, 0x0d,
       0x04, 0xE9,
-      0x05, 0xCA,
--     0x07, 0x0C,
-+     0x07, 0x04,
-      0x0B, 0x06,
-      0x0D, 0x21,
-      0x0E, 0x65,
 @@ -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,
@@ -39,12 +33,12 @@ Index: clib/rf_asksin.c
 +     0x3e, 0xc3
  };
  
-+static inline uint8_t read_cc1100_rxbytes();
++static void rf_asksin_reset_rx(void);
 +
  void
  rf_asksin_init(void)
  {
-@@ -56,20 +59,30 @@
+@@ -56,20 +59,27 @@
    my_delay_us(100);
  
    // load configuration
@@ -66,56 +60,38 @@ Index: clib/rf_asksin.c
 +  ccRX();
  }
  
-+// Workaround for CC1101 Errata 3
-+static inline uint8_t read_cc1100_rxbytes()
++static void
++rf_asksin_reset_rx(void)
 +{
-+  uint8_t rxbytes, rxbytes2;
-+  
-+  rxbytes = cc1100_readReg(CC1100_RXBYTES);
-+  while((rxbytes2 = cc1100_readReg(CC1100_RXBYTES)) != rxbytes)
-+    rxbytes = rxbytes2;
-+
-+  return rxbytes;
++  ccStrobe( CC1100_SFRX  );
++  ccStrobe( CC1100_SIDLE );
++  ccStrobe( CC1100_SNOP  );
++  ccStrobe( CC1100_SRX   );
 +}
 +
  void
  rf_asksin_task(void)
  {
-@@ -77,18 +90,30 @@
-   uint8_t dec[MAX_ASKSIN_MSG];
-   uint8_t rssi;
-   uint8_t l;
-+  uint8_t rxfifo_cnt;
-   if(!asksin_on)
-     return;
--  // see if a CRC OK pkt has been arrived
--  if (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
-+  // see if there is data to be read
-+  while (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
-+    rxfifo_cnt = read_cc1100_rxbytes();
-+    if (rxfifo_cnt & 0x80) // Overflow
-+      break;
-+
-+    rxfifo_cnt &= 0x7f;
-+
+@@ -83,12 +93,14 @@
+   // see if a CRC OK pkt has been arrived
+   if (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
+-
      enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
  
-     if (enc[0]>=MAX_ASKSIN_MSG)
-          enc[0] = MAX_ASKSIN_MSG-1;
+-    if (enc[0]>=MAX_ASKSIN_MSG)
+-         enc[0] = MAX_ASKSIN_MSG-1;
 -    
-+
-+    while ((enc[0] + 2) < (rxfifo_cnt - 1)) { // Wait for more data
-+      my_delay_ms(1);
-+      rxfifo_cnt = (read_cc1100_rxbytes() & 0x7f) + 1;
++    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,13 +122,12 @@
+@@ -97,12 +109,10 @@
      }
      
      rssi = cc1100_sendbyte( 0 );
@@ -127,13 +103,10 @@ Index: clib/rf_asksin.c
 -    ccStrobe( CC1100_SFRX  );
 -    ccStrobe( CC1100_SIDLE );
 -    ccStrobe( CC1100_SNOP  );
--    ccStrobe( CC1100_SRX   );
-+    if (!(l & 0x80)) // CRC not ok
-+      continue;
+     ccStrobe( CC1100_SRX   );
  
      dec[0] = enc[0];
-     dec[1] = (~enc[1]) ^ 0x89;
-@@ -113,7 +137,6 @@
+@@ -113,7 +123,6 @@
      
      dec[l] = enc[l] ^ dec[2];
      
@@ -141,7 +114,7 @@ Index: clib/rf_asksin.c
      if (tx_report & REP_BINTIME) {
        
        DC('a');
-@@ -131,26 +154,17 @@
+@@ -131,26 +140,17 @@
        
        DNL();
      }
@@ -177,7 +150,7 @@ Index: clib/rf_asksin.c
  }
  
  void
-@@ -173,20 +187,7 @@
+@@ -173,20 +173,7 @@
      my_delay_ms(3);             // 3ms: Found by trial and error
    }
  
@@ -198,7 +171,7 @@ Index: clib/rf_asksin.c
    enc[0] = dec[0];
    enc[1] = (~dec[1]) ^ 0x89;
  
-@@ -195,6 +196,15 @@
+@@ -195,6 +182,15 @@
    
    enc[l] = dec[l] ^ dec[2];
  
@@ -214,7 +187,7 @@ Index: clib/rf_asksin.c
    // send
    CC1100_ASSERT;
    cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
-@@ -205,12 +215,17 @@
+@@ -205,12 +201,17 @@
  
    CC1100_DEASSERT;
  
Impressum, Datenschutz