]> 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 c2d7101d3273f3f4b17c82db40fd8cb530ad3b17..168ad477b42dfdda427084da0dcdcbcf1be4ce5f 100644 (file)
@@ -2,21 +2,23 @@ Index: clib/rf_asksin.c
 ===================================================================
 --- 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,18 @@
+      0x04, 0xE9,
+@@ -26,18 +26,21 @@
       0x11, 0x93,
       0x12, 0x03,
       0x15, 0x34,
 -     0x17, 0x30, // always go into IDLE
-+     0x17, 0x3F, // always go into RX, CCA, ELV uses 0x03
++     0x17, 0x33, // go into RX after TX, CCA; ELV uses 0x03
       0x18, 0x18,
       0x19, 0x16,
       0x1B, 0x43,
@@ -26,22 +28,29 @@ Index: clib/rf_asksin.c
 +     0x29, 0x59,
 +     0x2c, 0x81,
       0x2D, 0x35,
-      0x3e, 0xc3,
+-     0x3e, 0xc3,
 -     0xff
-+     0xff, 0xff
++     0x3e, 0xc3
  };
  
++static void rf_asksin_reset_rx(void);
++
  void
-@@ -56,7 +58,7 @@
+ rf_asksin_init(void)
+ {
+@@ -56,20 +59,27 @@
    my_delay_us(100);
  
    // load configuration
 -  for (uint8_t i = 0; i<50; i += 2) {
+-       
+-    if (pgm_read_byte( &ASKSIN_CFG[i] )>0x40)
+-      break;
+-
 +  for (uint8_t i = 0; i < sizeof(ASKSIN_CFG); i += 2) {
-        
-     if (pgm_read_byte( &ASKSIN_CFG[i] )>0x40)
-       break;
-@@ -67,7 +69,9 @@
+     cc1100_writeReg( pgm_read_byte(&ASKSIN_CFG[i]),
+                      pgm_read_byte(&ASKSIN_CFG[i+1]) );
+   }
    
    ccStrobe( CC1100_SCAL );
  
@@ -51,24 +60,53 @@ Index: clib/rf_asksin.c
 +  ccRX();
  }
  
++static void
++rf_asksin_reset_rx(void)
++{
++  ccStrobe( CC1100_SFRX  );
++  ccStrobe( CC1100_SIDLE );
++  ccStrobe( CC1100_SNOP  );
++  ccStrobe( CC1100_SRX   );
++}
++
  void
-@@ -97,14 +101,10 @@
+ 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 )) {
+-
+     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) {
++      // 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 );
-+    /* LQI = */ cc1100_sendbyte( 0 );
-     
+-    
++    l = cc1100_sendbyte( 0 );
++
      CC1100_DEASSERT;
  
 -    ccStrobe( CC1100_SFRX  );
 -    ccStrobe( CC1100_SIDLE );
 -    ccStrobe( CC1100_SNOP  );
--    ccStrobe( CC1100_SRX   );
--
+     ccStrobe( CC1100_SRX   );
      dec[0] = enc[0];
-     dec[1] = (~enc[1]) ^ 0x89;
-     
-@@ -113,7 +113,6 @@
+@@ -113,7 +123,6 @@
      
      dec[l] = enc[l] ^ dec[2];
      
@@ -76,11 +114,22 @@ Index: clib/rf_asksin.c
      if (tx_report & REP_BINTIME) {
        
        DC('a');
-@@ -133,24 +132,14 @@
+@@ -131,26 +140,17 @@
+       
+       DNL();
      }
++  }
  
-     return;
+-    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;
    }
 -       
 -       
@@ -97,17 +146,11 @@ Index: clib/rf_asksin.c
 -    break;
 -       
 -  }
-+  if (cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_RXFIFO_OVERFLOW) {
-+      ccStrobe( CC1100_SFRX  );
-+      ccStrobe( CC1100_SIDLE );
-+      ccStrobe( CC1100_SNOP  );
-+      ccStrobe( CC1100_SRX   );
-+  }
+-
  }
  
  void
-@@ -173,20 +162,7 @@
+@@ -173,20 +173,7 @@
      my_delay_ms(3);             // 3ms: Found by trial and error
    }
  
@@ -128,7 +171,7 @@ Index: clib/rf_asksin.c
    enc[0] = dec[0];
    enc[1] = (~dec[1]) ^ 0x89;
  
-@@ -195,6 +171,15 @@
+@@ -195,6 +182,15 @@
    
    enc[l] = dec[l] ^ dec[2];
  
@@ -144,7 +187,7 @@ Index: clib/rf_asksin.c
    // send
    CC1100_ASSERT;
    cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
-@@ -205,12 +190,10 @@
+@@ -205,12 +201,17 @@
  
    CC1100_DEASSERT;
  
@@ -153,6 +196,13 @@ Index: clib/rf_asksin.c
 +  // wait for TX to finish
 +  while(cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TX)
 +    ;
++
++  if (cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TXFIFO_UNDERFLOW) {
++      ccStrobe( CC1100_SFTX  );
++      ccStrobe( CC1100_SIDLE );
++      ccStrobe( CC1100_SNOP  );
++      ccStrobe( CC1100_SRX   );
++  }
    
 -  while( cc1100_readReg( CC1100_MARCSTATE ) != 1 )
 -    my_delay_ms(5);
Impressum, Datenschutz