summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
222456d)
This reverts commit
222456d4edba28dede43232231fee62df2a45880.
I could reproduce the problem which lead me to activate hw packet
handling with activated hw packet handling, so the old solution is
better.
===================================================================
--- clib/rf_asksin.c (revision 373)
+++ clib/rf_asksin.c (working copy)
===================================================================
--- clib/rf_asksin.c (revision 373)
+++ clib/rf_asksin.c (working copy)
+ #include "rf_asksin.h"
+
++//we receive a new byte approximately every 8 ms...
++#define RX_TIMEOUT_MS 10
++
uint8_t asksin_on = 0;
-const uint8_t PROGMEM ASKSIN_CFG[50] = {
uint8_t asksin_on = 0;
-const uint8_t PROGMEM ASKSIN_CFG[50] = {
0x02, 0x2e,
0x03, 0x0d,
0x04, 0xE9,
0x02, 0x2e,
0x03, 0x0d,
0x04, 0xE9,
+ 0x05, 0xCA,
+- 0x07, 0x0C,
++ 0x07, 0x04,
+ 0x0B, 0x06,
+ 0x0D, 0x21,
+ 0x0E, 0x65,
+@@ -26,18 +29,22 @@
0x11, 0x93,
0x12, 0x03,
0x15, 0x34,
- 0x17, 0x30, // always go into IDLE
0x11, 0x93,
0x12, 0x03,
0x15, 0x34,
- 0x17, 0x30, // always go into IDLE
-+ 0x17, 0x33, // go into RX after TX, CCA; ELV uses 0x03
++ 0x17, 0x3F, // always go into RX, CCA; ELV uses 0x03
0x18, 0x18,
0x19, 0x16,
0x1B, 0x43,
0x18, 0x18,
0x19, 0x16,
0x1B, 0x43,
++static inline uint8_t read_cc1100_rxbytes(void);
+static void rf_asksin_reset_rx(void);
+
void
rf_asksin_init(void)
{
+static void rf_asksin_reset_rx(void);
+
void
rf_asksin_init(void)
{
my_delay_us(100);
// load configuration
my_delay_us(100);
// load configuration
++// Workaround for CC1101 Errata 3
++static inline uint8_t
++read_cc1100_rxbytes(void)
++{
++ uint8_t rxbytes, rxbytes2;
++
++ rxbytes = cc1100_readReg(CC1100_RXBYTES);
++ while((rxbytes2 = cc1100_readReg(CC1100_RXBYTES)) != rxbytes)
++ rxbytes = rxbytes2;
++
++ return rxbytes;
++}
++
+static void
+rf_asksin_reset_rx(void)
+{
+ ccStrobe( CC1100_SFRX );
+ ccStrobe( CC1100_SIDLE );
+ ccStrobe( CC1100_SNOP );
+static 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)
{
+ ccStrobe( CC1100_SRX );
+}
+
void
rf_asksin_task(void)
{
+@@ -77,18 +108,57 @@
+ uint8_t dec[MAX_ASKSIN_MSG];
+ uint8_t rssi;
+ uint8_t l;
++ uint8_t rxfifo_cnt;
++ uint16_t timeout;
- // see if a CRC OK pkt has been arrived
- if (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
--
+ 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;
++
++ // We must not read the last byte from the RX fifo while RX is in progress (Errata 1)
++ while ((rxfifo_cnt == 1) && (cc1100_readReg(CC1100_PKTSTATUS) & (1 << 3))) {
++ my_delay_ms(1);
++ rxfifo_cnt = read_cc1100_rxbytes() & 0x7f;
++ }
++
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;
- if (enc[0]>=MAX_ASKSIN_MSG)
- enc[0] = MAX_ASKSIN_MSG-1;
+ rf_asksin_reset_rx();
+ return;
+ }
+ rf_asksin_reset_rx();
+ return;
+ }
++
++ if ((enc[0] + 2) > rxfifo_cnt) {
++ timeout = RX_TIMEOUT_MS * ((enc[0] + 2) - rxfifo_cnt);
++ while (timeout-- && ((enc[0] + 2) > rxfifo_cnt)) { // Wait for more data
++ my_delay_ms(1);
++ rxfifo_cnt = read_cc1100_rxbytes();
++
++ if (rxfifo_cnt & 0x80) { // Overflow
++ rf_asksin_reset_rx();
++ return;
++ }
++
++ rxfifo_cnt &= 0x7f;
++ }
++
++ if (!timeout) {
++ // Not enough data received, out of sync?
++ rf_asksin_reset_rx();
++ return;
++ }
++ }
+
CC1100_ASSERT;
cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
+
CC1100_ASSERT;
cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
}
rssi = cc1100_sendbyte( 0 );
-
}
rssi = cc1100_sendbyte( 0 );
-
-+ l = cc1100_sendbyte( 0 );
+
CC1100_DEASSERT;
- ccStrobe( CC1100_SFRX );
- ccStrobe( CC1100_SIDLE );
- ccStrobe( CC1100_SNOP );
+
CC1100_DEASSERT;
- ccStrobe( CC1100_SFRX );
- ccStrobe( CC1100_SIDLE );
- ccStrobe( CC1100_SNOP );
- ccStrobe( CC1100_SRX );
+- 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[1] = (~enc[1]) ^ 0x89;
+
+@@ -113,7 +188,6 @@
dec[l] = enc[l] ^ dec[2];
dec[l] = enc[l] ^ dec[2];
if (tx_report & REP_BINTIME) {
DC('a');
if (tx_report & REP_BINTIME) {
DC('a');
my_delay_ms(3); // 3ms: Found by trial and error
}
my_delay_ms(3); // 3ms: Found by trial and error
}
enc[0] = dec[0];
enc[1] = (~dec[1]) ^ 0x89;
enc[0] = dec[0];
enc[1] = (~dec[1]) ^ 0x89;
enc[l] = dec[l] ^ dec[2];
enc[l] = dec[l] ^ dec[2];
// send
CC1100_ASSERT;
cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
// send
CC1100_ASSERT;
cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);