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