From: Michael Gernoth Date: Thu, 20 Jun 2013 08:43:30 +0000 (+0200) Subject: add WIP culfw patches to fix asksin problems with lost packets X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/fhem-stuff/commitdiff_plain/b2720844ad3ca5ae4d2b92d6d76650756f41ace0 add WIP culfw patches to fix asksin problems with lost packets --- diff --git a/culfw/culfw-asksin-fix.diff b/culfw/culfw-asksin-fix.diff new file mode 100644 index 0000000..e63b87f --- /dev/null +++ b/culfw/culfw-asksin-fix.diff @@ -0,0 +1,160 @@ +Index: clib/rf_asksin.c +=================================================================== +--- clib/rf_asksin.c (revision 373) ++++ clib/rf_asksin.c (working copy) +@@ -11,7 +11,7 @@ + + uint8_t asksin_on = 0; + +-const uint8_t PROGMEM ASKSIN_CFG[50] = { ++const uint8_t PROGMEM ASKSIN_CFG[] = { + 0x00, 0x07, + 0x02, 0x2e, + 0x03, 0x0d, +@@ -26,16 +26,18 @@ + 0x11, 0x93, + 0x12, 0x03, + 0x15, 0x34, +- 0x17, 0x30, // always go into IDLE ++ 0x17, 0x3F, // always go into RX, CCA, ELV uses 0x03 + 0x18, 0x18, + 0x19, 0x16, + 0x1B, 0x43, + 0x21, 0x56, + 0x25, 0x00, + 0x26, 0x11, ++ 0x29, 0x59, ++ 0x2c, 0x81, + 0x2D, 0x35, + 0x3e, 0xc3, +- 0xff ++ 0xff, 0xff + }; + + void +@@ -56,7 +58,7 @@ + my_delay_us(100); + + // load configuration +- for (uint8_t i = 0; i<50; i += 2) { ++ for (uint8_t i = 0; i < sizeof(ASKSIN_CFG); i += 2) { + + if (pgm_read_byte( &ASKSIN_CFG[i] )>0x40) + break; +@@ -67,7 +69,9 @@ + + ccStrobe( CC1100_SCAL ); + +- my_delay_ms(1); ++ my_delay_ms(4); ++ ++ ccRX(); + } + + void +@@ -97,14 +101,10 @@ + } + + rssi = cc1100_sendbyte( 0 ); ++ /* LQI = */ cc1100_sendbyte( 0 ); + + CC1100_DEASSERT; + +- ccStrobe( CC1100_SFRX ); +- ccStrobe( CC1100_SIDLE ); +- ccStrobe( CC1100_SNOP ); +- ccStrobe( CC1100_SRX ); +- + dec[0] = enc[0]; + dec[1] = (~enc[1]) ^ 0x89; + +@@ -113,7 +113,6 @@ + + dec[l] = enc[l] ^ dec[2]; + +- + if (tx_report & REP_BINTIME) { + + DC('a'); +@@ -133,24 +132,14 @@ + } + + return; +- + } +- +- +- switch (cc1100_readReg( CC1100_MARCSTATE )) { +- +- // RX_OVERFLOW +- case 17: +- // IDLE +- case 1: +- ccStrobe( CC1100_SFRX ); +- ccStrobe( CC1100_SIDLE ); +- ccStrobe( CC1100_SNOP ); +- ccStrobe( CC1100_SRX ); +- 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 @@ + my_delay_ms(3); // 3ms: Found by trial and error + } + +- ccStrobe(CC1100_SIDLE); +- ccStrobe(CC1100_SFRX ); +- ccStrobe(CC1100_SFTX ); +- +- if (dec[2] & (1 << 4)) { //BURST-bit set? +- ccStrobe(CC1100_STX ); //We need to send a burst +- +- //According to ELV, devices get activated every 300ms, so send burst for 360ms +- for(l = 0; l < 3; l++) +- my_delay_ms(120); //arg is uint_8, so loop +- } +- + // "crypt" +- + enc[0] = dec[0]; + enc[1] = (~dec[1]) ^ 0x89; + +@@ -195,6 +171,13 @@ + + enc[l] = dec[l] ^ dec[2]; + ++ ccTX(); ++ if (dec[2] & (1 << 4)) { // BURST-bit set? ++ // According to ELV, devices get activated every 300ms, so send burst for 360ms ++ for(l = 0; l < 3; l++) ++ my_delay_ms(120); // arg is uint_8, so loop ++ } ++ + // send + CC1100_ASSERT; + cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO); +@@ -205,12 +188,10 @@ + + CC1100_DEASSERT; + +- ccStrobe( CC1100_SFRX ); +- ccStrobe( CC1100_STX ); ++ // wait for TX to finish ++ while(cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TX) ++ ; + +- while( cc1100_readReg( CC1100_MARCSTATE ) != 1 ) +- my_delay_ms(5); +- + if(asksin_on) { + ccRX(); + } else { diff --git a/culfw/culfw-cc1100-fix.diff b/culfw/culfw-cc1100-fix.diff new file mode 100644 index 0000000..097b483 --- /dev/null +++ b/culfw/culfw-cc1100-fix.diff @@ -0,0 +1,38 @@ +Index: clib/cc1100.c +=================================================================== +--- clib/cc1100.c (revision 373) ++++ clib/cc1100.c (working copy) +@@ -266,26 +266,25 @@ + void + ccTX(void) + { +- uint8_t cnt = 0xff; + EIMSK &= ~_BV(CC1100_INT); + + // Going from RX to TX does not work if there was a reception less than 0.5 + // sec ago. Due to CCA? Using IDLE helps to shorten this period(?) +- ccStrobe(CC1100_SIDLE); +- while(cnt-- && (ccStrobe( CC1100_STX ) & 0x70) != 2) +- my_delay_us(10); ++ ++ while (cc1100_readReg(CC1100_MARCSTATE) != MARCSTATE_TX) { ++ ccStrobe(CC1100_STX); ++ } + } + + //-------------------------------------------------------------------- + void + ccRX(void) + { +- uint8_t cnt = 0xff; ++ while (cc1100_readReg(CC1100_MARCSTATE) != MARCSTATE_RX) { ++ ccStrobe(CC1100_SRX); ++ } + +- while(cnt-- && (ccStrobe( CC1100_SRX ) & 0x70) != 1) +- my_delay_us(10); + EIMSK |= _BV(CC1100_INT); +- + } + +