forked from gioblu/PJON
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timing.h
212 lines (191 loc) · 5.72 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
/* PJON AnalogSampling strategy Transmission Timing table
Copyright 2018, Giovanni Blu Mitolo All rights reserved.
__________________________________________________________
| MODE 1 | Transmission speed 1024Bb - 128B/s |
| ADC prescale 128 | |
|-------------------|--------------------------------------|
| MODE 2 | Transmission speed 1361Bb - 170B/s |
| ADC prescale 128 | |
|-------------------|--------------------------------------|
| MODE 3 | Transmission speed 3773Bb - 471B/s |
| ADC prescale 32 | |
|-------------------|--------------------------------------|
| MODE 4 | Transmission speed 5547Bb - 639B/s |
| ADC prescale 16 | |
|-------------------|--------------------------------------|
| MODE 5 | Transmission speed 12658Bb - 1582B/s |
| ADC prescale 8 | Caution, ADC clocked faster than |
| | manifacturer raccomends as maximum |
| | ADC sample rate (prescale 16) |
|___________________|______________________________________|
All benchmarks are obtained with NetworkAnalysis and SpeedTest examples. */
#pragma once
#if defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) || \
defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
#if AS_MODE == 1
#if F_CPU == 16000000L
#define AS_BIT_WIDTH 750
#define AS_BIT_SPACER 1050
#define AS_READ_DELAY 0
#endif
#elif AS_MODE == 2
#if F_CPU == 16000000L
#define AS_BIT_WIDTH 572
#define AS_BIT_SPACER 728
#define AS_READ_DELAY 0
#endif
#elif AS_MODE == 3
#ifndef AS_PRESCALE
#define AS_PRESCALE 32
#endif
#if F_CPU == 16000000L
#define AS_BIT_WIDTH 188
#define AS_BIT_SPACER 428
#define AS_READ_DELAY 0
#endif
#elif AS_MODE == 4
#ifndef AS_PRESCALE
#define AS_PRESCALE 16
#endif
#if F_CPU == 16000000L
#define AS_BIT_WIDTH 128
#define AS_BIT_SPACER 290
#define AS_READ_DELAY 0
#endif
#elif AS_MODE == 5
#ifndef AS_PRESCALE
#define AS_PRESCALE 8
#endif
#if F_CPU == 16000000L
#define AS_BIT_WIDTH 56
#define AS_BIT_SPACER 128
#define AS_READ_DELAY 16
#endif
#endif
#endif
/* ATmega1280/2560 - Arduino Mega/Mega-nano ------------------------------- */
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#if AS_MODE == 1
#if F_CPU == 16000000L
/* Standard timing is applied below */
#endif
#elif AS_MODE == 2
#if F_CPU == 16000000L
/* Standard timing is applied below */
#endif
#elif AS_MODE == 3
#ifndef AS_PRESCALE
#define AS_PRESCALE 32
#endif
#if F_CPU == 16000000L
/* Standard timing is applied below */
#endif
#elif AS_MODE == 4
#ifndef AS_PRESCALE
#define AS_PRESCALE 16
#endif
#if F_CPU == 16000000L
/* Standard timing is applied below */
#endif
#elif AS_MODE == 5
#ifndef AS_PRESCALE
#define AS_PRESCALE 8
#endif
#if F_CPU == 16000000L
/* TODO - define dedicated timing */
#endif
#endif
#endif
/* ATmega16/32U4 - Arduino Leonardo/Micro --------------------------------- */
#if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)
#if AS_MODE == 1
/* TODO - define dedicated timing */
#endif
#endif
/* NodeMCU, generic ESP8266 ----------------------------------------------- */
#if defined(ESP8266)
#if AS_MODE == 1
#if F_CPU == 80000000L
/* TODO - define dedicated timing */
#endif
#endif
#endif
/* Fallback to standard timing if not previously defined: */
#if AS_MODE == 1
#ifndef AS_BIT_WIDTH
#define AS_BIT_WIDTH 750
#endif
#ifndef AS_BIT_SPACER
#define AS_BIT_SPACER 1050
#endif
#ifndef AS_READ_DELAY
#define AS_READ_DELAY 0
#endif
#elif AS_MODE == 2
#ifndef AS_BIT_WIDTH
#define AS_BIT_WIDTH 572
#endif
#ifndef AS_BIT_SPACER
#define AS_BIT_SPACER 728
#endif
#ifndef AS_READ_DELAY
#define AS_READ_DELAY 0
#endif
#elif AS_MODE == 3
#ifndef AS_BIT_WIDTH
#define AS_BIT_WIDTH 188
#endif
#ifndef AS_BIT_SPACER
#define AS_BIT_SPACER 428
#endif
#ifndef AS_READ_DELAY
#define AS_READ_DELAY 0
#endif
#elif AS_MODE == 4
#ifndef AS_BIT_WIDTH
#define AS_BIT_WIDTH 128
#endif
#ifndef AS_BIT_SPACER
#define AS_BIT_SPACER 290
#endif
#ifndef AS_READ_DELAY
#define AS_READ_DELAY 0
#endif
#elif AS_MODE == 5
#ifndef AS_BIT_WIDTH
#define AS_BIT_WIDTH 56
#endif
#ifndef AS_BIT_SPACER
#define AS_BIT_SPACER 128
#endif
#ifndef AS_READ_DELAY
#define AS_READ_DELAY 16
#endif
#endif
/* Synchronous acknowledgement response timeout. (15 milliseconds default).
If (latency + CRC computation) > AS_RESPONSE_TIMEOUT synchronous
acknowledgement reliability could be affected or disrupted higher
AS_RESPONSE_TIMEOUT if necessary. */
#ifndef AS_RESPONSE_TIMEOUT
#define AS_RESPONSE_TIMEOUT 15000
#endif
/* Maximum initial delay in milliseconds: */
#ifndef AS_INITIAL_DELAY
#define AS_INITIAL_DELAY 1000
#endif
/* Maximum delay in case of collision in microseconds: */
#ifndef AS_COLLISION_DELAY
#define AS_COLLISION_DELAY 64
#endif
/* Maximum transmission attempts */
#ifndef AS_MAX_ATTEMPTS
#define AS_MAX_ATTEMPTS 10
#endif
/* Back-off exponential degree */
#ifndef AS_BACK_OFF_DEGREE
#define AS_BACK_OFF_DEGREE 5
#endif
/* Threshold decrease interval (10 millis) */
#ifndef AS_THRESHOLD_DECREASE_INTERVAL
#define AS_THRESHOLD_DECREASE_INTERVAL 10000
#endif