Browse Source

Further testing

Thomas Buck 8 years ago
parent
commit
698d5ee16c
4 changed files with 240 additions and 58 deletions
  1. 3
    1
      include/main.h
  2. 15
    1
      src/main.c
  3. 218
    54
      src/rx.c
  4. 4
    2
      src/spi.c

+ 3
- 1
include/main.h View File

9
 
9
 
10
 #include "serial.h"
10
 #include "serial.h"
11
 
11
 
12
-#define DEBUG_UART_MENU
12
+//#define DEBUG_UART_MENU
13
 
13
 
14
 #define debugWrite(x) serialWriteString(0, x);
14
 #define debugWrite(x) serialWriteString(0, x);
15
 #define debugHex(x) serialWriteHex(0, x);
15
 #define debugHex(x) serialWriteHex(0, x);
16
 
16
 
17
+#ifdef DEBUG_UART_MENU
17
 void uartMenu(void);
18
 void uartMenu(void);
19
+#endif
18
 
20
 
19
 #else // DEBUG
21
 #else // DEBUG
20
 
22
 

+ 15
- 1
src/main.c View File

2
  * main() method
2
  * main() method
3
  */
3
  */
4
 
4
 
5
+#ifndef DEBUG
6
+// Only use without Arduino Bootloader!
7
+#define ENABLE_WATCHDOG
8
+#endif
9
+
5
 #include <avr/interrupt.h>
10
 #include <avr/interrupt.h>
6
 #include <avr/wdt.h>
11
 #include <avr/wdt.h>
7
 
12
 
11
 #include "rx.h"
16
 #include "rx.h"
12
 #include "main.h"
17
 #include "main.h"
13
 
18
 
19
+#ifdef ENABLE_WATCHDOG
14
 void watchdogBoot(void) __attribute__((naked)) __attribute__((section(".init3")));
20
 void watchdogBoot(void) __attribute__((naked)) __attribute__((section(".init3")));
15
 void watchdogBoot(void) {
21
 void watchdogBoot(void) {
16
     MCUSR = 0;
22
     MCUSR = 0;
17
     wdt_disable();
23
     wdt_disable();
18
 }
24
 }
25
+#endif
19
 
26
 
20
 #ifdef DEBUG_UART_MENU
27
 #ifdef DEBUG_UART_MENU
21
 void uartMenu(void) {
28
 void uartMenu(void) {
34
         debugWrite("s\n");
41
         debugWrite("s\n");
35
         break;
42
         break;
36
 
43
 
44
+#ifdef ENABLE_WATCHDOG
37
     case 'q': case 'Q':
45
     case 'q': case 'Q':
38
         debugWrite("Resetting...\n\n");
46
         debugWrite("Resetting...\n\n");
39
-        wdt_enable(WDTO_15MS);
47
+        wdt_enable(WDTO_2S);
40
         for (;;) { }
48
         for (;;) { }
41
         break;
49
         break;
50
+#endif
42
 
51
 
43
     default:
52
     default:
44
         debugWrite("Unknown command: '");
53
         debugWrite("Unknown command: '");
49
         debugWrite("Available commands:\n");
58
         debugWrite("Available commands:\n");
50
         debugWrite("  h - Help\n");
59
         debugWrite("  h - Help\n");
51
         debugWrite("  t - Time\n");
60
         debugWrite("  t - Time\n");
61
+#ifdef ENABLE_WATCHDOG
52
         debugWrite("  q - Reset\n");
62
         debugWrite("  q - Reset\n");
63
+#endif
53
         break;
64
         break;
54
     }
65
     }
55
 }
66
 }
64
 #endif
75
 #endif
65
 
76
 
66
     sei(); // Enable interrupts (required for timer)
77
     sei(); // Enable interrupts (required for timer)
78
+
79
+#ifdef ENABLE_WATCHDOG
67
     //wdt_enable(WDTO_250MS); // Trigger Watchdog after 250ms
80
     //wdt_enable(WDTO_250MS); // Trigger Watchdog after 250ms
68
     wdt_enable(WDTO_2S); // Trigger Watchdog after 2s
81
     wdt_enable(WDTO_2S); // Trigger Watchdog after 2s
82
+#endif
69
 
83
 
70
     //debugWrite("RX reset.\n");
84
     //debugWrite("RX reset.\n");
71
 
85
 

+ 218
- 54
src/rx.c View File

3
  */
3
  */
4
 
4
 
5
 #ifdef DEBUG
5
 #ifdef DEBUG
6
+
6
 //#define DEBUG_TEST_PART_VERSION
7
 //#define DEBUG_TEST_PART_VERSION
7
 //#define DEBUG_EEPROM_DATA_READ
8
 //#define DEBUG_EEPROM_DATA_READ
9
+//#define DEBUG_EEPROM_DATA_WRITE
8
 //#define DEBUG_MISSING_PACKETS
10
 //#define DEBUG_MISSING_PACKETS
9
 //#define DEBUG_PACKET_DUMP
11
 //#define DEBUG_PACKET_DUMP
10
 //#define DEBUG_PACKET_DUMP_TUNE
12
 //#define DEBUG_PACKET_DUMP_TUNE
12
 //#define DEBUG_PACKET_DUMP_LIST
14
 //#define DEBUG_PACKET_DUMP_LIST
13
 //#define DEBUG_PPM_VALUES
15
 //#define DEBUG_PPM_VALUES
14
 //#define DEBUG_ERROR_MESSAGES
16
 //#define DEBUG_ERROR_MESSAGES
15
-#define DEBUG_PACKET_DOT
17
+//#define DEBUG_MESSAGES
18
+//#define DEBUG_HOP_DATA
19
+
20
+#define DEBUG_SINGLE_CHARACTER_MESSAGES
21
+
22
+#define ALWAYS_PERFORM_BINDING
23
+
16
 #endif
24
 #endif
17
 
25
 
18
 #include <stdint.h>
26
 #include <stdint.h>
29
 #include "main.h"
37
 #include "main.h"
30
 
38
 
31
 #define CHANNELS 8
39
 #define CHANNELS 8
32
-#define PPM_MIN 1000
33
-#define PPM_MAX 2000
34
 #define HOP_DATA_LENGTH 60
40
 #define HOP_DATA_LENGTH 60
35
 #define EEPROM_BASE_ADDRESS 100
41
 #define EEPROM_BASE_ADDRESS 100
36
-#define MISSING_PACKET_DELAY 9
42
+#define MISSING_PACKET_DELAY 10 // was 9 originally
37
 #define SEEK_CHANNEL_SKIP   13
43
 #define SEEK_CHANNEL_SKIP   13
38
 #define MAX_MISSING_PACKET 20
44
 #define MAX_MISSING_PACKET 20
39
 #define FAILSAFE_MISSING_PACKET 170
45
 #define FAILSAFE_MISSING_PACKET 170
40
 
46
 
41
-//#define FAILSAFE_INVALID_VALUE 850
47
+#define FAILSAFE_INVALID_VALUE 850
42
 #define FAILSAFE_INVALID_VALUE_MINIMUM 900
48
 #define FAILSAFE_INVALID_VALUE_MINIMUM 900
43
 #define FAILSAFE_INVALID_VALUE_MAXIMUM 2100
49
 #define FAILSAFE_INVALID_VALUE_MAXIMUM 2100
44
 
50
 
46
 #define RSSI_OFFSET 71
52
 #define RSSI_OFFSET 71
47
 #define RSSI_MIN -103
53
 #define RSSI_MIN -103
48
 #define RSSI_MAX -96
54
 #define RSSI_MAX -96
55
+#define PPM_MIN 1000
56
+#define PPM_MAX 2000
49
 
57
 
50
 #define PPM_SCALE 2 / 3
58
 #define PPM_SCALE 2 / 3
51
 
59
 
59
 #define FREQ_SCAN_START_1 0x76
67
 #define FREQ_SCAN_START_1 0x76
60
 #define FREQ_SCAN_START_0 0x00
68
 #define FREQ_SCAN_START_0 0x00
61
 
69
 
62
-uint8_t ccData[27];
70
+uint8_t ccData[100]; // was 27, led to buffer overruns?!
63
 uint8_t ccLen;
71
 uint8_t ccLen;
64
 uint8_t packet = 0;
72
 uint8_t packet = 0;
65
 uint8_t channr = 0;
73
 uint8_t channr = 0;
69
 uint8_t txid[2];
77
 uint8_t txid[2];
70
 uint8_t counter = 0;
78
 uint8_t counter = 0;
71
 uint8_t failed = 0;
79
 uint8_t failed = 0;
72
-uint8_t frequencyOffsetHack = 0;
80
+uint16_t frequencyOffsetHack = 0;
73
 uint16_t c[CHANNELS];
81
 uint16_t c[CHANNELS];
74
 
82
 
75
 #ifdef FREQUENCY_SCAN
83
 #ifdef FREQUENCY_SCAN
92
 static void tuning(void);
100
 static void tuning(void);
93
 static void performBind(void);
101
 static void performBind(void);
94
 static void nextChannel(uint8_t skip);
102
 static void nextChannel(uint8_t skip);
95
-static void readBindingData(void);
96
 static void writeBindingData(void);
103
 static void writeBindingData(void);
97
 
104
 
105
+#ifndef ALWAYS_PERFORM_BINDING
106
+static void readBindingData(void);
107
+#endif
108
+
98
 void rxInit(void) {
109
 void rxInit(void) {
99
     GDO_dir;
110
     GDO_dir;
100
 
111
 
112
+#ifdef DEBUG_MESSAGES
101
     debugWrite("RX: initializing\n");
113
     debugWrite("RX: initializing\n");
114
+#endif
102
 
115
 
103
     initialize(1); // binding
116
     initialize(1); // binding
104
 
117
 
118
+#ifdef DEBUG_MESSAGES
105
     debugWrite("RX: binding\n");
119
     debugWrite("RX: binding\n");
120
+#endif
106
 
121
 
107
     binding();
122
     binding();
108
 
123
 
124
+#ifdef DEBUG_MESSAGES
109
     debugWrite("RX: receiving\n");
125
     debugWrite("RX: receiving\n");
126
+#endif
110
 
127
 
111
     initialize(0); // data
128
     initialize(0); // data
112
     cc2500WriteReg(CC2500_0A_CHANNR, hopData[channr]);// 0A - hop
129
     cc2500WriteReg(CC2500_0A_CHANNR, hopData[channr]);// 0A - hop
165
     //cc2500WriteReg(CC2500_03_FIFOTHR,  0x0F); // 0x07?
182
     //cc2500WriteReg(CC2500_03_FIFOTHR,  0x0F); // 0x07?
166
 
183
 
167
     cc2500WriteReg(CC2500_09_ADDR, bind ? 0x03 : txid[0]);
184
     cc2500WriteReg(CC2500_09_ADDR, bind ? 0x03 : txid[0]);
168
-    //cc2500WriteReg(CC2500_09_ADDR, bind ? 0x00 : txid[0]);
169
 
185
 
186
+#ifdef DEBUG_MESSAGES
170
     debugWrite("CC2500: Entering IDLE mode...\n");
187
     debugWrite("CC2500: Entering IDLE mode...\n");
188
+#endif
171
 
189
 
172
     cc2500Strobe(CC2500_SIDLE); // Go to idle...
190
     cc2500Strobe(CC2500_SIDLE); // Go to idle...
173
 
191
 
196
 }
214
 }
197
 
215
 
198
 static void binding(void) {
216
 static void binding(void) {
217
+#ifndef ALWAYS_PERFORM_BINDING
199
     readBindingData();
218
     readBindingData();
200
     if ((txid[0] != 0xff) || (txid[1] != 0xff)) {
219
     if ((txid[0] != 0xff) || (txid[1] != 0xff)) {
201
         // valid binding data found
220
         // valid binding data found
202
         debugWrite("RX: found data in EEPROM!\n");
221
         debugWrite("RX: found data in EEPROM!\n");
203
         return;
222
         return;
204
     }
223
     }
224
+#endif
205
 
225
 
226
+#ifdef DEBUG_MESSAGES
206
     debugWrite("RX: no stored data, tuning...\n");
227
     debugWrite("RX: no stored data, tuning...\n");
228
+#endif
207
 
229
 
208
     // No valid txid, forcing bind
230
     // No valid txid, forcing bind
209
     tuning();
231
     tuning();
212
     cc2500WriteReg(CC2500_0C_FSCTRL0, frequencyOffsetHack);
234
     cc2500WriteReg(CC2500_0C_FSCTRL0, frequencyOffsetHack);
213
     eeprom_write_byte(EEPROM_BASE_ADDRESS + 101, frequencyOffsetHack);
235
     eeprom_write_byte(EEPROM_BASE_ADDRESS + 101, frequencyOffsetHack);
214
 
236
 
237
+#ifdef DEBUG_EEPROM_DATA_WRITE
238
+    debugWrite("RX: Write EEPROM Frequency Offset Hack: ");
239
+    serialWriteUnsigned8(0, frequencyOffsetHack);
240
+    debugWrite("\n");
241
+#endif
242
+
243
+#ifdef DEBUG_MESSAGES
215
     debugWrite("RX: tuned, binding...\n");
244
     debugWrite("RX: tuned, binding...\n");
245
+#endif
216
 
246
 
217
     performBind();
247
     performBind();
218
 }
248
 }
223
     uint16_t frequencyOffsetTimer = 0;
253
     uint16_t frequencyOffsetTimer = 0;
224
     while (1) {
254
     while (1) {
225
         frequencyOffsetTimer++;
255
         frequencyOffsetTimer++;
226
-        if (frequencyOffsetTimer > 3000) {
227
-            frequencyOffsetTimer = 0;
228
-            cc2500WriteReg(CC2500_0C_FSCTRL0, frequencyOffsetHack);
229
-            if (frequencyOffsetHack <= 250) {
230
-                frequencyOffsetHack += 5;
231
-            } else {
232
-                frequencyOffsetHack = 0;
256
+        if (frequencyOffsetHack >= 250) {
257
+            frequencyOffsetHack = 0;
233
 
258
 
234
 #ifdef FREQUENCY_SCAN
259
 #ifdef FREQUENCY_SCAN
235
-                if (freq0 < 255) {
236
-                    freq0++;
260
+            if (freq0 < 255) {
261
+                freq0++;
262
+            } else {
263
+                freq0 = 0;
264
+                if (freq1 < 255) {
265
+                    freq1++;
237
                 } else {
266
                 } else {
238
-                    freq0 = 0;
239
-                    if (freq1 < 255) {
240
-                        freq1++;
267
+                    freq1 = 0;
268
+                    if (freq2 < 255) {
269
+                        freq2++;
241
                     } else {
270
                     } else {
242
-                        freq1 = 0;
243
-                        if (freq2 < 255) {
244
-                            freq2++;
245
-                        } else {
246
-                            freq2 = 0;
247
-                        }
271
+                        freq2 = 0;
248
                     }
272
                     }
249
                 }
273
                 }
274
+            }
250
 
275
 
251
-                debugWrite("0x");
252
-                debugHex(freq2);
253
-                debugHex(freq1);
254
-                debugHex(freq0);
255
-                debugWrite("\n");
276
+            debugWrite("0x");
277
+            debugHex(freq2);
278
+            debugHex(freq1);
279
+            debugHex(freq0);
280
+            debugWrite("\n");
256
 
281
 
257
-                cc2500WriteReg(CC2500_0D_FREQ2, freq2);
258
-                cc2500WriteReg(CC2500_0E_FREQ1, freq1);
259
-                cc2500WriteReg(CC2500_0F_FREQ0, freq0);
282
+            cc2500WriteReg(CC2500_0D_FREQ2, freq2);
283
+            cc2500WriteReg(CC2500_0E_FREQ1, freq1);
284
+            cc2500WriteReg(CC2500_0F_FREQ0, freq0);
260
 #endif
285
 #endif
261
-            }
286
+
287
+        }
288
+
289
+        if (frequencyOffsetTimer > 3000) {
290
+            frequencyOffsetTimer = 0;
291
+            cc2500WriteReg(CC2500_0C_FSCTRL0, frequencyOffsetHack);
292
+            frequencyOffsetHack += 10;
262
             //cc2500Strobe(CC2500_SRX); // enter in rx mode
293
             //cc2500Strobe(CC2500_SRX); // enter in rx mode
263
         }
294
         }
264
 
295
 
273
                 debugWrite("):\n");
304
                 debugWrite("):\n");
274
                 for (uint8_t i = 0; i < ccLen; i++) {
305
                 for (uint8_t i = 0; i < ccLen; i++) {
275
                     debugWrite("0x")
306
                     debugWrite("0x")
276
-                    serialWriteHex(0, ccData[i]);
307
+                    debugHex(ccData[i]);
277
                     if (i < (ccLen - 1)) {
308
                     if (i < (ccLen - 1)) {
278
                         debugWrite(" ");
309
                         debugWrite(" ");
279
                     } else {
310
                     } else {
282
                 }
313
                 }
283
 #endif
314
 #endif
284
 
315
 
285
-                if ((ccData[ccLen - 1] & 0x80)
316
+                if ((ccData[ccLen - 1] & CC2500_LQI_CRC_OK_BM)
286
                         && (ccData[2] == 0x01)
317
                         && (ccData[2] == 0x01)
287
                         && (ccData[5] == 0x00)) {
318
                         && (ccData[5] == 0x00)) {
319
+#ifdef DEBUG_MESSAGES
320
+                    debugWrite("RX: Tune: finished at: ");
321
+                    serialWriteUnsigned8(0, frequencyOffsetHack);
322
+                    debugWrite("!\n");
323
+#endif
324
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
325
+                    serialWrite(0, 't');
326
+#endif
288
                     break;
327
                     break;
328
+                } else {
329
+#ifdef DEBUG_ERROR_MESSAGES
330
+                    if (!(ccData[ccLen - 1] & CC2500_LQI_CRC_OK_BM)) {
331
+                        debugWrite("RX: Tune: invalid CRC!\n");
332
+                    }
333
+                    if (ccData[2] != 0x01) {
334
+                        debugWrite("RX: Tune: invalid data[2]: ");
335
+                        serialWriteUnsigned8(0, ccData[2]);
336
+                        debugWrite(" != ");
337
+                        serialWriteUnsigned8(0, 0x01);
338
+                        debugWrite("\n");
339
+                    }
340
+                    if (ccData[5] != 0x00) {
341
+                        debugWrite("RX: Tune: invalid data[5]: ");
342
+                        serialWriteUnsigned8(0, ccData[5]);
343
+                        debugWrite(" != ");
344
+                        serialWriteUnsigned8(0, 0x00);
345
+                        debugWrite("\n");
346
+                    }
347
+#endif
348
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
349
+                    serialWrite(0, 'u');
350
+#endif
289
                 }
351
                 }
290
             }
352
             }
291
         }
353
         }
313
                 debugWrite("):\n");
375
                 debugWrite("):\n");
314
                 for (uint8_t i = 0; i < ccLen; i++) {
376
                 for (uint8_t i = 0; i < ccLen; i++) {
315
                     debugWrite("0x")
377
                     debugWrite("0x")
316
-                    serialWriteHex(0, ccData[i]);
378
+                    debugHex(ccData[i]);
317
                     if (i < (ccLen - 1)) {
379
                     if (i < (ccLen - 1)) {
318
                         debugWrite(" ");
380
                         debugWrite(" ");
319
                     } else {
381
                     } else {
322
                 }
384
                 }
323
 #endif
385
 #endif
324
 
386
 
325
-                if ((ccData[ccLen - 1] & 0x80)
387
+                if ((ccData[ccLen - 1] & CC2500_LQI_CRC_OK_BM)
326
                         && (ccData[2] == 0x01)
388
                         && (ccData[2] == 0x01)
327
                         && (ccData[5] == 0x00)) {
389
                         && (ccData[5] == 0x00)) {
328
                     txid[0] = ccData[3];
390
                     txid[0] = ccData[3];
329
                     txid[1] = ccData[4];
391
                     txid[1] = ccData[4];
392
+#ifdef DEBUG_MESSAGES
393
+                    debugWrite("RX: Bind: got txid: 0x");
394
+                    debugHex(txid[0]);
395
+                    debugWrite(" 0x");
396
+                    debugHex(txid[1]);
397
+                    debugWrite("\n");
398
+#endif
399
+#ifdef DEBUG_HOP_DATA
400
+                    debugWrite("RX: Bind: got hop list:\n");
401
+#endif
330
                     for (uint8_t n = 0; n < 5; n++) {
402
                     for (uint8_t n = 0; n < 5; n++) {
331
                         hopData[ccData[5] + n] = ccData[6 + n];
403
                         hopData[ccData[5] + n] = ccData[6 + n];
404
+#ifdef DEBUG_HOP_DATA
405
+                        serialWriteUnsigned8(0, ccData[5] + n);
406
+                        debugWrite(": ");
407
+                        serialWriteUnsigned8(0, ccData[6 + n]);
408
+                        debugWrite("\n");
409
+#endif
332
                     }
410
                     }
411
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
412
+                    serialWrite(0, 'b');
413
+#endif
333
                     break;
414
                     break;
415
+                } else {
416
+#ifdef DEBUG_ERROR_MESSAGES
417
+                    if (!(ccData[ccLen - 1] & CC2500_LQI_CRC_OK_BM)) {
418
+                        debugWrite("RX: Bind: invalid CRC!\n");
419
+                    }
420
+                    if (ccData[2] != 0x01) {
421
+                        debugWrite("RX: Bind: invalid data[2]: ");
422
+                        serialWriteUnsigned8(0, ccData[2]);
423
+                        debugWrite(" != ");
424
+                        serialWriteUnsigned8(0, 0x01);
425
+                        debugWrite("\n");
426
+                    }
427
+                    if (ccData[5] != 0x00) {
428
+                        debugWrite("RX: Bind: invalid data[5]: ");
429
+                        serialWriteUnsigned8(0, ccData[5]);
430
+                        debugWrite(" != ");
431
+                        serialWriteUnsigned8(0, 0x00);
432
+                        debugWrite("\n");
433
+                    }
434
+#endif
435
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
436
+                    serialWrite(0, 'c');
437
+#endif
334
                 }
438
                 }
335
             }
439
             }
336
         }
440
         }
342
 #endif
446
 #endif
343
     }
447
     }
344
 
448
 
449
+#ifdef DEBUG_MESSAGES
345
     debugWrite("RX: got hop data, reading list...\n");
450
     debugWrite("RX: got hop data, reading list...\n");
451
+#endif
346
 
452
 
347
     listLength = 0;
453
     listLength = 0;
348
     uint8_t eol = 0;
454
     uint8_t eol = 0;
359
                     debugWrite("):\n");
465
                     debugWrite("):\n");
360
                     for (uint8_t i = 0; i < ccLen; i++) {
466
                     for (uint8_t i = 0; i < ccLen; i++) {
361
                         debugWrite("0x")
467
                         debugWrite("0x")
362
-                        serialWriteHex(0, ccData[i]);
468
+                        debugHex(ccData[i]);
363
                         if (i < (ccLen - 1)) {
469
                         if (i < (ccLen - 1)) {
364
                             debugWrite(" ");
470
                             debugWrite(" ");
365
                         } else {
471
                         } else {
368
                     }
474
                     }
369
 #endif
475
 #endif
370
 
476
 
371
-                    if ((ccData[ccLen - 1] & 0x80)
477
+                    if ((ccData[ccLen - 1] & CC2500_LQI_CRC_OK_BM)
372
                             && (ccData[2] == 0x01)
478
                             && (ccData[2] == 0x01)
373
                             && (ccData[3] == txid[0])
479
                             && (ccData[3] == txid[0])
374
                             && (ccData[4] == txid[1])
480
                             && (ccData[4] == txid[1])
382
                             }
488
                             }
383
                             hopData[ccData[5] + n] = ccData[6 + n];
489
                             hopData[ccData[5] + n] = ccData[6 + n];
384
                         }
490
                         }
491
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
492
+                        serialWrite(0, 'l');
493
+#endif
385
                         break;
494
                         break;
495
+                    } else {
496
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
497
+                        serialWrite(0, 'm');
498
+#endif
386
                     }
499
                     }
387
                 }
500
                 }
388
             }
501
             }
399
         }
512
         }
400
     }
513
     }
401
 
514
 
515
+#ifdef DEBUG_MESSAGES
402
     debugWrite("RX: binding finished!\n");
516
     debugWrite("RX: binding finished!\n");
517
+#endif
403
 
518
 
404
     writeBindingData();
519
     writeBindingData();
405
     cc2500Strobe(CC2500_SIDLE); // Back to idle
520
     cc2500Strobe(CC2500_SIDLE); // Back to idle
415
     cc2500WriteReg(CC2500_23_FSCAL3, 0x89);
530
     cc2500WriteReg(CC2500_23_FSCAL3, 0x89);
416
 }
531
 }
417
 
532
 
533
+#ifndef ALWAYS_PERFORM_BINDING
418
 static void readBindingData() {
534
 static void readBindingData() {
419
 #ifdef DEBUG_EEPROM_DATA_READ
535
 #ifdef DEBUG_EEPROM_DATA_READ
420
-    debugWrite("RX: EEPROM TXID: ");
536
+    debugWrite("RX: Read EEPROM TXID: ");
421
 #endif
537
 #endif
422
     for (uint8_t i = 0; i < 2; i++) {
538
     for (uint8_t i = 0; i < 2; i++) {
423
         txid[i] = eeprom_read_byte(EEPROM_BASE_ADDRESS + i);
539
         txid[i] = eeprom_read_byte(EEPROM_BASE_ADDRESS + i);
424
 #ifdef DEBUG_EEPROM_DATA_READ
540
 #ifdef DEBUG_EEPROM_DATA_READ
425
         debugWrite("0x")
541
         debugWrite("0x")
426
-        serialWriteHex(0, txid[i]);
542
+        debugHex(txid[i]);
427
         debugWrite(" ");
543
         debugWrite(" ");
428
 #endif
544
 #endif
429
     }
545
     }
432
 #endif
548
 #endif
433
 
549
 
434
 #ifdef DEBUG_EEPROM_DATA_READ
550
 #ifdef DEBUG_EEPROM_DATA_READ
435
-    debugWrite("RX: EEPROM Hop Data (");
551
+    debugWrite("RX: Read EEPROM Hop Data (");
436
     serialWriteUnsigned8(0, HOP_DATA_LENGTH);
552
     serialWriteUnsigned8(0, HOP_DATA_LENGTH);
437
     debugWrite(")\n");
553
     debugWrite(")\n");
438
 #endif
554
 #endif
440
         hopData[i] = eeprom_read_byte(EEPROM_BASE_ADDRESS + 10 + i);
556
         hopData[i] = eeprom_read_byte(EEPROM_BASE_ADDRESS + 10 + i);
441
 #ifdef DEBUG_EEPROM_DATA_READ
557
 #ifdef DEBUG_EEPROM_DATA_READ
442
         debugWrite("0x")
558
         debugWrite("0x")
443
-        serialWriteHex(0, hopData[i]);
559
+        debugHex(hopData[i]);
444
         debugWrite(" ");
560
         debugWrite(" ");
445
 #endif
561
 #endif
446
     }
562
     }
452
     frequencyOffsetHack = eeprom_read_byte(EEPROM_BASE_ADDRESS + 101);
568
     frequencyOffsetHack = eeprom_read_byte(EEPROM_BASE_ADDRESS + 101);
453
 
569
 
454
 #ifdef DEBUG_EEPROM_DATA_READ
570
 #ifdef DEBUG_EEPROM_DATA_READ
455
-    debugWrite("RX: EEPROM List Length: ");
571
+    debugWrite("RX: Read EEPROM List Length: ");
456
     serialWriteUnsigned8(0, listLength);
572
     serialWriteUnsigned8(0, listLength);
457
-    debugWrite("\nRX: EEPROM Frequency Offset Hack: ");
573
+    debugWrite("\nRX: Read EEPROM Frequency Offset Hack: ");
458
     serialWriteUnsigned8(0, frequencyOffsetHack);
574
     serialWriteUnsigned8(0, frequencyOffsetHack);
459
     debugWrite("\n");
575
     debugWrite("\n");
460
 #endif
576
 #endif
461
 }
577
 }
578
+#endif
462
 
579
 
463
 static void writeBindingData() {
580
 static void writeBindingData() {
581
+#ifdef DEBUG_EEPROM_DATA_WRITE
582
+    debugWrite("RX: Write EEPROM TXID: ");
583
+#endif
464
     for (uint8_t i = 0; i < 2; i++) {
584
     for (uint8_t i = 0; i < 2; i++) {
465
         eeprom_write_byte(EEPROM_BASE_ADDRESS + i, txid[i]);
585
         eeprom_write_byte(EEPROM_BASE_ADDRESS + i, txid[i]);
586
+#ifdef DEBUG_EEPROM_DATA_WRITE
587
+        debugWrite("0x")
588
+        debugHex(txid[i]);
589
+        debugWrite(" ");
590
+#endif
466
     }
591
     }
592
+#ifdef DEBUG_EEPROM_DATA_WRITE
593
+    debugWrite("\n");
594
+#endif
467
 
595
 
596
+#ifdef DEBUG_EEPROM_DATA_WRITE
597
+    debugWrite("RX: Write EEPROM Hop Data (");
598
+    serialWriteUnsigned8(0, HOP_DATA_LENGTH);
599
+    debugWrite(")\n");
600
+#endif
468
     for (uint8_t i = 0; i < HOP_DATA_LENGTH; i++) {
601
     for (uint8_t i = 0; i < HOP_DATA_LENGTH; i++) {
469
         eeprom_write_byte(EEPROM_BASE_ADDRESS + 10 + i, hopData[i]);
602
         eeprom_write_byte(EEPROM_BASE_ADDRESS + 10 + i, hopData[i]);
603
+#ifdef DEBUG_EEPROM_DATA_WRITE
604
+        debugWrite("0x")
605
+        debugHex(hopData[i]);
606
+        debugWrite(" ");
607
+#endif
470
     }
608
     }
609
+#ifdef DEBUG_EEPROM_DATA_WRITE
610
+    debugWrite("\n");
611
+#endif
471
 
612
 
472
     eeprom_write_byte(EEPROM_BASE_ADDRESS + 100, listLength);
613
     eeprom_write_byte(EEPROM_BASE_ADDRESS + 100, listLength);
614
+#ifdef DEBUG_EEPROM_DATA_WRITE
615
+    debugWrite("RX: Write EEPROM List Length: ");
616
+    serialWriteUnsigned8(0, listLength);
617
+    debugWrite("\n");
618
+#endif
473
 }
619
 }
474
 
620
 
475
 void rxReceivePacket() {
621
 void rxReceivePacket() {
476
     time_t time = timerGet();
622
     time_t time = timerGet();
477
 
623
 
478
-#ifdef DEBUG_MISSING_PACKETS
624
+#if defined(DEBUG_MISSING_PACKETS) || defined(DEBUG_SINGLE_CHARACTER_MESSAGES)
479
     static uint8_t packetMissingNotification = 0;
625
     static uint8_t packetMissingNotification = 0;
480
 #endif
626
 #endif
481
 
627
 
485
     }
631
     }
486
 
632
 
487
     while (1) {
633
     while (1) {
488
-        if ((timerGet() - time) > MISSING_PACKET_DELAY) {
634
+        if ((timerGet() - time) >= MISSING_PACKET_DELAY) {
489
             missingPackets++;
635
             missingPackets++;
490
             cc2500Strobe(CC2500_SIDLE);
636
             cc2500Strobe(CC2500_SIDLE);
491
             if (missingPackets > MAX_MISSING_PACKET) {
637
             if (missingPackets > MAX_MISSING_PACKET) {
499
                         packetMissingNotification = 1;
645
                         packetMissingNotification = 1;
500
                     }
646
                     }
501
 #endif
647
 #endif
648
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
649
+                    if (packetMissingNotification < 1) {
650
+                        serialWrite(0, '1');
651
+                        packetMissingNotification = 1;
652
+                    }
653
+#endif
502
                 }
654
                 }
503
 
655
 
504
                 if (counter == (MAX_MISSING_PACKET << 2)) {
656
                 if (counter == (MAX_MISSING_PACKET << 2)) {
508
                         packetMissingNotification = 2;
660
                         packetMissingNotification = 2;
509
                     }
661
                     }
510
 #endif
662
 #endif
663
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
664
+                    if (packetMissingNotification < 2) {
665
+                        serialWrite(0, '2');
666
+                        packetMissingNotification = 2;
667
+                    }
668
+#endif
511
                     counter = 0;
669
                     counter = 0;
512
                 }
670
                 }
513
             } else {
671
             } else {
536
                     debugWrite("):\n");
694
                     debugWrite("):\n");
537
                     for (uint8_t i = 0; i < ccLen; i++) {
695
                     for (uint8_t i = 0; i < ccLen; i++) {
538
                         debugWrite("0x")
696
                         debugWrite("0x")
539
-                        serialWriteHex(0, ccData[i]);
697
+                        debugHex(ccData[i]);
540
                         if (i < (ccLen - 1)) {
698
                         if (i < (ccLen - 1)) {
541
                             debugWrite(" ");
699
                             debugWrite(" ");
542
                         } else {
700
                         } else {
549
                     if ((ccData[0] == FRSKY_PACKET_LENGTH) // Correct length
707
                     if ((ccData[0] == FRSKY_PACKET_LENGTH) // Correct length
550
                             && (ccData[1] == txid[0]) // Correct txid
708
                             && (ccData[1] == txid[0]) // Correct txid
551
                             && (ccData[2] == txid[1])) {
709
                             && (ccData[2] == txid[1])) {
552
-#ifdef DEBUG_MISSING_PACKETS
710
+#if defined(DEBUG_MISSING_PACKETS) || defined(DEBUG_SINGLE_CHARACTER_MESSAGES)
553
                         packetMissingNotification = 0;
711
                         packetMissingNotification = 0;
554
 #endif
712
 #endif
555
 
713
 
593
                             debugWrite("\n");
751
                             debugWrite("\n");
594
                         }
752
                         }
595
 #endif
753
 #endif
754
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
755
+                        serialWrite(0, 'r');
756
+#endif
596
                     }
757
                     }
597
                 } else {
758
                 } else {
598
 #ifdef DEBUG_ERROR_MESSAGES
759
 #ifdef DEBUG_ERROR_MESSAGES
599
                     debugWrite("RX: invalid CRC!\n");
760
                     debugWrite("RX: invalid CRC!\n");
600
 #endif
761
 #endif
762
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
763
+                    serialWrite(0, 'q');
764
+#endif
601
                 }
765
                 }
602
             }
766
             }
603
         }
767
         }
657
         }
821
         }
658
 #endif
822
 #endif
659
 
823
 
660
-#ifdef DEBUG_PACKET_DOT
661
-        serialWrite(0, '.');
824
+#ifdef DEBUG_SINGLE_CHARACTER_MESSAGES
825
+        serialWrite(0, 'p');
662
 #endif
826
 #endif
663
 
827
 
664
         cppmCopy(ppmBuffer);
828
         cppmCopy(ppmBuffer);

+ 4
- 2
src/spi.c View File

2
  * Bit-Banged SPI routines
2
  * Bit-Banged SPI routines
3
  */
3
  */
4
 
4
 
5
+//#define DEBUG_SLOW_SPI_TRAFFIC
6
+
5
 #include "spi.h"
7
 #include "spi.h"
6
 
8
 
7
 void spiInit(void) {
9
 void spiInit(void) {
37
         SCK_on;
39
         SCK_on;
38
         NOP();
40
         NOP();
39
 
41
 
40
-#ifdef DEBUG
42
+#ifdef DEBUG_SLOW_SPI_TRAFFIC
41
         NOP();
43
         NOP();
42
         NOP();
44
         NOP();
43
         NOP();
45
         NOP();
47
         SCK_off;
49
         SCK_off;
48
         NOP();
50
         NOP();
49
 
51
 
50
-#ifdef DEBUG
52
+#ifdef DEBUG_SLOW_SPI_TRAFFIC
51
         NOP();
53
         NOP();
52
         NOP();
54
         NOP();
53
         NOP();
55
         NOP();

Loading…
Cancel
Save