forked from gioblu/PJON
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timing.h
391 lines (354 loc) · 11 KB
/
Timing.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
/* PJON SoftwareBitBang strategy Transmission Timing table
Copyright 2010-2021, Giovanni Blu Mitolo All rights reserved.
Often timing in two different machines do not match, code execution
time can variate and time measurements are not perfectly equal.
Consider that durations defined below may differ from what is specified in
PJDL v5.0. This is done to accomodate machine's inner workings and
effectively produce the specified timing.
Arduino Duemilanove/UNO/Nano is used as timing master, or the machine used
to test all new supported MCUs.
Benchmarks can be executed using NetworkAnalysis and SpeedTest examples.
MODE 1: 1.97kB/s - 15808Bd
MODE 2: 2.21kB/s - 17696Bd
MODE 3: 3.10kB/s - 24844Bd
MODE 4: 3.34kB/s - 26755Bd
Use the same pin number on all connected devices to achieve maximum
timing efficiency, not all different pin combinations work nominally
because of execution timing discrepancies between physical pins. */
#pragma once
/* ATmega88/168/328 - Arduino Duemilanove, Uno, Nano, Mini, Pro, Pro mini */
#if defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) || \
defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
#if SWBB_MODE == 1
#if F_CPU == 16000000L
/* Working on pin: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, A0, A1 */
#define SWBB_BIT_WIDTH 40
#define SWBB_BIT_SPACER 112
#define SWBB_ACCEPTANCE 56
#define SWBB_READ_DELAY 4
#endif
#endif
#if SWBB_MODE == 2
#if F_CPU == 16000000L
/* Working on pin: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, A0, A1 */
#define SWBB_BIT_WIDTH 36
#define SWBB_BIT_SPACER 88
#define SWBB_ACCEPTANCE 56
#define SWBB_READ_DELAY 4
#endif
#endif
#if SWBB_MODE == 3
#if F_CPU == 16000000L
/* Working on pin: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, A0, A1 */
#define SWBB_BIT_WIDTH 24
#define SWBB_BIT_SPACER 66
#define SWBB_ACCEPTANCE 30
#define SWBB_READ_DELAY 8
#endif
#endif
#if SWBB_MODE == 4
#if F_CPU == 16000000L
/* Working on pin: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, A0, A1 */
#define SWBB_BIT_WIDTH 22
#define SWBB_BIT_SPACER 61
#define SWBB_ACCEPTANCE 30
#define SWBB_READ_DELAY 7
#endif
#endif
#endif
/* ATmega328PB ------------------------------------------------------------ */
#if defined(__AVR_ATmega328PB__)
#if SWBB_MODE == 1
#if F_CPU == 16000000L
/* Working on pin: 10 */
#define SWBB_BIT_WIDTH 37
#define SWBB_BIT_SPACER 110
#define SWBB_ACCEPTANCE 56
#define SWBB_READ_DELAY 4
#endif
#endif
#if SWBB_MODE == 2
#if F_CPU == 16000000L
/* Working on pin: 10 */
#define SWBB_BIT_WIDTH 33
#define SWBB_BIT_SPACER 88
#define SWBB_ACCEPTANCE 56
#define SWBB_READ_DELAY 8
#endif
#endif
#endif
/* ATmega16/32U4 - Arduino Leonardo/Micro --------------------------------- */
#if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)
#if SWBB_MODE == 1
/* Working on pin: 2, 4, 8, 12
Fallback to default timing */
#define SWBB_BIT_WIDTH 40
#define SWBB_BIT_SPACER 112
#define SWBB_ACCEPTANCE 56
#define SWBB_READ_DELAY 8
#endif
#if SWBB_MODE == 2
/* Working on pin: 2, 4, 8, 12
Fallback to default timing */
#define SWBB_BIT_WIDTH 36
#define SWBB_BIT_SPACER 88
#define SWBB_ACCEPTANCE 56
#define SWBB_READ_DELAY 12
#endif
#endif
/* ATmega1280/2560 - Arduino Mega/Mega-nano ------------------------------- */
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#if SWBB_MODE == 1
/* Working on pin: 3, 4, 7, 8, 9, 10, 12 */
#define SWBB_BIT_WIDTH 38
#define SWBB_BIT_SPACER 110
#define SWBB_ACCEPTANCE 62
#define SWBB_READ_DELAY 11
#endif
#if SWBB_MODE == 2
/* Working on pin: 3, 4, 7, 8, 9, 10, 12 */
#define SWBB_BIT_WIDTH 34
#define SWBB_BIT_SPACER 86
#define SWBB_ACCEPTANCE 58
#define SWBB_READ_DELAY 10
#endif
#endif
/* ATtiny45/85 ------------------------------------------------------------ */
#if defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
#if SWBB_MODE == 1
#if F_CPU == 16000000L
/* Working on pin: 1, 2
Fallback to default */
#define SWBB_BIT_WIDTH 40
#define SWBB_BIT_SPACER 112
#define SWBB_ACCEPTANCE 56
#define SWBB_READ_DELAY 4
#endif
#endif
#if SWBB_MODE == 2
#if F_CPU == 16000000L
/* Working on pin: 1, 2
Fallback to default */
#define SWBB_BIT_WIDTH 36
#define SWBB_BIT_SPACER 88
#define SWBB_ACCEPTANCE 56
#define SWBB_READ_DELAY 4
#endif
#endif
#endif
/* ATtiny44/84/44A/84A ---------------------------------------------------- */
#if defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || \
defined(__AVR_ATtiny84A__) || defined(__AVR_ATtiny84A__)
#if SWBB_MODE == 1
#if F_CPU == 16000000L
/* Working on pin: 0, 1, 2, 3, 4
Fallback to default */
#define SWBB_BIT_WIDTH 40
#define SWBB_BIT_SPACER 112
#define SWBB_ACCEPTANCE 56
#define SWBB_READ_DELAY 4
#endif
#endif
#if SWBB_MODE == 2
#if F_CPU == 16000000L
/* Working on pin: 0, 1, 2, 3, 4
Fallback to default */
#define SWBB_BIT_WIDTH 36
#define SWBB_BIT_SPACER 88
#define SWBB_ACCEPTANCE 56
#define SWBB_READ_DELAY 4
#endif
#endif
#endif
/* Arduino Zero ----------------------------------------------------------- */
#if defined(ARDUINO_SAMD_ZERO)
#if SWBB_MODE == 1
/* Added by Esben Soeltoft - 03/09/2016
Updated by Giovanni Blu Mitolo - 31/05/2019
Working on pin: D0, D1, D3, A0, A1 */
#define SWBB_BIT_WIDTH 43
#define SWBB_BIT_SPACER 115
#define SWBB_ACCEPTANCE 40
#define SWBB_READ_DELAY -4
#endif
#endif
/* NodeMCU, generic ESP8266 ----------------------------------------------- */
#if defined(ESP8266)
#if SWBB_MODE == 1
/* Added by github user 240974a - 09/03/2016
Added full support to MODE 1 (80 and 160MHz) - 12/06/2018 */
#if (F_CPU == 80000000L) || (F_CPU == 160000000L)
/* Working on pin: D1 or GPIO 5 */
#define SWBB_BIT_WIDTH 44
#define SWBB_BIT_SPACER 112
#define SWBB_ACCEPTANCE 56
#define SWBB_READ_DELAY -6
#endif
#endif
#endif
/* Heltech WiFi LoRa ESP32, generic ESP32 --------------------------------- */
#if defined(ESP32)
#if SWBB_MODE == 1
/* Added full support to MODE 1 - 28/06/2018
Working on pin: 12 and 25 */
#define SWBB_BIT_WIDTH 44
#define SWBB_BIT_SPACER 112
#define SWBB_ACCEPTANCE 56
#define SWBB_READ_DELAY -2
#endif
#endif
/* MK20DX256 - Teensy ----------------------------------------------------- */
#if defined(__MK20DX256__)
#if SWBB_MODE == 1
/* Added by github user SticilFace - 25/04/2016 */
#if F_CPU == 96000000L
#define SWBB_BIT_WIDTH 46
#define SWBB_BIT_SPACER 112
#define SWBB_ACCEPTANCE 40
#define SWBB_READ_DELAY -10
#endif
#endif
#endif
/* STM32F1 ---------------------------------------------------------------- */
/* @jcallano 09-jul-2020 tested with pin PB15, PB14, PB13, PB12, PB11, PB10,
PB9, PB8, PB7, PB6, PB4, PB3, PA15, PA10. 5v tolerant pins on bluepill */
#if defined(__STM32F1__)
#if SWBB_MODE == 1
#if F_CPU == 72000000L
#define SWBB_BIT_WIDTH 43
#define SWBB_BIT_SPACER 115
#define SWBB_ACCEPTANCE 60
#define SWBB_READ_DELAY 3
#endif
#endif
#if SWBB_MODE == 2
#if F_CPU == 72000000L
#define SWBB_BIT_WIDTH 39
#define SWBB_BIT_SPACER 91
#define SWBB_ACCEPTANCE 47
#define SWBB_READ_DELAY 3
#endif
#endif
#if SWBB_MODE == 3
#if F_CPU == 72000000L
#define SWBB_BIT_WIDTH 27.5
#define SWBB_BIT_SPACER 69.5
#define SWBB_ACCEPTANCE 33
#define SWBB_READ_DELAY -5
#endif
#endif
#if SWBB_MODE == 4
#if F_CPU == 72000000L
#define SWBB_BIT_WIDTH 25
#define SWBB_BIT_SPACER 59
#define SWBB_ACCEPTANCE 30 //
#define SWBB_READ_DELAY 4
#endif
#endif
#endif
/* Avoid error if any previous defined ------------------------------------ */
#if SWBB_MODE == 1
#ifndef SWBB_BIT_WIDTH
#define SWBB_BIT_WIDTH 40
#endif
#ifndef SWBB_BIT_SPACER
#define SWBB_BIT_SPACER 112
#endif
#ifndef SWBB_ACCEPTANCE
#define SWBB_ACCEPTANCE 56
#endif
#ifndef SWBB_READ_DELAY
#define SWBB_READ_DELAY 4
#endif
#ifndef SWBB_LATENCY
#define SWBB_LATENCY 13
#endif
#endif
#if SWBB_MODE == 2
#ifndef SWBB_BIT_WIDTH
#define SWBB_BIT_WIDTH 36
#endif
#ifndef SWBB_BIT_SPACER
#define SWBB_BIT_SPACER 88
#endif
#ifndef SWBB_ACCEPTANCE
#define SWBB_ACCEPTANCE 56
#endif
#ifndef SWBB_READ_DELAY
#define SWBB_READ_DELAY 4
#endif
#ifndef SWBB_LATENCY
#define SWBB_LATENCY 10
#endif
#endif
#if SWBB_MODE == 3
#ifndef SWBB_BIT_WIDTH
#define SWBB_BIT_WIDTH 24
#endif
#ifndef SWBB_BIT_SPACER
#define SWBB_BIT_SPACER 66
#endif
#ifndef SWBB_ACCEPTANCE
#define SWBB_ACCEPTANCE 30
#endif
#ifndef SWBB_READ_DELAY
#define SWBB_READ_DELAY 8
#endif
#ifndef SWBB_LATENCY
#define SWBB_LATENCY 8
#endif
#endif
#if SWBB_MODE == 4
#ifndef SWBB_BIT_WIDTH
#define SWBB_BIT_WIDTH 22
#endif
#ifndef SWBB_BIT_SPACER
#define SWBB_BIT_SPACER 61
#endif
#ifndef SWBB_ACCEPTANCE
#define SWBB_ACCEPTANCE 30
#endif
#ifndef SWBB_READ_DELAY
#define SWBB_READ_DELAY 7
#endif
#ifndef SWBB_LATENCY
#define SWBB_LATENCY 5
#endif
#endif
/* Frame preamble length (by default set to 1 x SWBB_BIT_SPACER)
Maximum allowed value is 100 or a preamble of 100 x SWBB_BIT_SPACER
When devices execute other tasks frames may be lost unheard. The preamble
can be used to avoid transmission failure. To avoid retransmissions the
preamble length should be slightly longer than the task's duration. */
#ifndef SWBB_PREAMBLE
#define SWBB_PREAMBLE 1
#endif
/* Maximum frame preamble length (by default set to 1 x SWBB_BIT_SPACER)
Maximum allowed value is 100 or a preamble of 100 x SWBB_BIT_SPACER
To have full interoperability set SWBB_MAX_PREAMBLE = 100 */
#ifndef SWBB_MAX_PREAMBLE
#define SWBB_MAX_PREAMBLE 1
#endif
/* Synchronous acknowledgement response offset.
If (latency + CRC computation) > (SWBB_RESPONSE_OFFSET * length)
synchronous acknowledgement reliability could be affected or disrupted
set a higher SWBB_RESPONSE_OFFSET if necessary. */
#ifndef SWBB_RESPONSE_OFFSET
#define SWBB_RESPONSE_OFFSET 20
#endif
/* Maximum initial delay in milliseconds: */
#ifndef SWBB_INITIAL_DELAY
#define SWBB_INITIAL_DELAY 1000
#endif
/* Maximum delay in case of collision in microseconds: */
#ifndef SWBB_COLLISION_DELAY
#define SWBB_COLLISION_DELAY 16
#endif
/* Maximum transmission attempts */
#ifndef SWBB_MAX_ATTEMPTS
#define SWBB_MAX_ATTEMPTS 20
#endif
/* Back-off exponential degree */
#ifndef SWBB_BACK_OFF_DEGREE
#define SWBB_BACK_OFF_DEGREE 4
#endif