1
|
#include <unistd.h>
|
2
|
#include <stdio.h>
|
3
|
#include <stdlib.h>
|
4
|
#include <stdint.h>
|
5
|
|
6
|
class CMyI2c
|
7
|
{
|
8
|
public:
|
9
|
int data;
|
10
|
|
11
|
CMyI2c()
|
12
|
{
|
13
|
data=0;
|
14
|
}
|
15
|
void setData(int i)
|
16
|
{
|
17
|
data=i;
|
18
|
}
|
19
|
void showData()
|
20
|
{
|
21
|
printf("Data: %d\n", data);
|
22
|
}
|
23
|
};
|
24
|
|
25
|
struct SEeprom
|
26
|
{
|
27
|
int info;
|
28
|
};
|
29
|
|
30
|
// template <typename S, CMyI2c& i2c>
|
31
|
template <typename S, class C>
|
32
|
class CTemp//: public virtual CMyI2c
|
33
|
{
|
34
|
//virtual CMyI2c myI2c;
|
35
|
//CMyI2c &myI2c;
|
36
|
C& m_ref;
|
37
|
|
38
|
public:
|
39
|
//CTemp()
|
40
|
// ( CMyI2c &v_i2c )
|
41
|
// :v_i2c
|
42
|
//CTemp( CMyI2c &v_i2c )
|
43
|
// :myI2c(v_i2c)
|
44
|
CTemp( C& ref )
|
45
|
:m_ref(ref)
|
46
|
{
|
47
|
|
48
|
}
|
49
|
void showData()
|
50
|
{
|
51
|
m_ref.myI2c.showData();
|
52
|
printf("EEPROM-Info: %d\n", m_ref.m_eeprom.info );
|
53
|
}
|
54
|
|
55
|
};
|
56
|
|
57
|
// template <typename S, CMyI2c& i2c>
|
58
|
template <typename TSEeprom_, class TCPlatform>
|
59
|
class CApp: public TCPlatform
|
60
|
{
|
61
|
//virtual CMyI2c myI2c;
|
62
|
//CMyI2c &myI2c;
|
63
|
//C& m_ref;
|
64
|
|
65
|
public:
|
66
|
//CTemp()
|
67
|
// ( CMyI2c &v_i2c )
|
68
|
// :v_i2c
|
69
|
//CTemp( CMyI2c &v_i2c )
|
70
|
// :myI2c(v_i2c)
|
71
|
CApp( )
|
72
|
{
|
73
|
|
74
|
}
|
75
|
void showData()
|
76
|
{
|
77
|
this->myI2c.showData();
|
78
|
printf("EEPROM-Info: %d\n", this->m_eeprom.info );
|
79
|
}
|
80
|
};
|
81
|
|
82
|
CMyI2c xmyI2c;
|
83
|
|
84
|
class CPlain
|
85
|
{
|
86
|
friend class CTemp<SEeprom, CPlain>;
|
87
|
protected:
|
88
|
SEeprom m_eeprom;
|
89
|
public:
|
90
|
|
91
|
CMyI2c myI2c;
|
92
|
//CTemp<SEeprom, &xmyI2c> temp;
|
93
|
//CTemp<SEeprom, myI2c> temp;
|
94
|
CTemp<SEeprom, CPlain> temp;
|
95
|
|
96
|
CPlain()
|
97
|
//:temp(myI2c)
|
98
|
:temp(*this)
|
99
|
{
|
100
|
|
101
|
}
|
102
|
void setInfo( int info)
|
103
|
{
|
104
|
m_eeprom.info=info;
|
105
|
//asm("foooo\n");
|
106
|
}
|
107
|
//template <class MC1>
|
108
|
void templated(int i1);
|
109
|
};
|
110
|
|
111
|
//template <class MC1>
|
112
|
//template <typename MC1>
|
113
|
//template <class MC1>
|
114
|
//void MC1::templated(int i1)
|
115
|
void CPlain::templated(int i1)
|
116
|
{
|
117
|
printf("Templated: %d\n", i1);
|
118
|
};
|
119
|
|
120
|
|
121
|
|
122
|
struct SRegEntry
|
123
|
{
|
124
|
int addr;
|
125
|
int bitStart;
|
126
|
int bitSize;
|
127
|
// const char *name;
|
128
|
// enum entries;
|
129
|
};
|
130
|
|
131
|
enum ESettings: unsigned int;
|
132
|
|
133
|
|
134
|
typedef const char* SSettingDesctriptorTexts[6];
|
135
|
struct SSettingDesctriptor
|
136
|
{
|
137
|
const SRegEntry ®Entry;
|
138
|
const char *descText;
|
139
|
SSettingDesctriptorTexts valueTexts;
|
140
|
};
|
141
|
|
142
|
#define MAX_VALUE_TEXTS 6
|
143
|
typedef SSettingDesctriptor SSettingDesctriptors[ ];
|
144
|
typedef const char** SSettingDesctriptorsI[ MAX_VALUE_TEXTS ];
|
145
|
|
146
|
template<typename T>
|
147
|
class CRegConfig
|
148
|
{
|
149
|
private:
|
150
|
T* m_conf;
|
151
|
//SSettingDesctriptor *m_descriptors;
|
152
|
//SRegEntry *m_bitFieldDescriptors;
|
153
|
|
154
|
public:
|
155
|
CRegConfig( int size )
|
156
|
//, SRegEntry *bitFieldDescriptors)
|
157
|
//:m_bitFieldDescriptors(bitFieldDescriptors)
|
158
|
{
|
159
|
m_conf=new uint8_t[size];
|
160
|
}
|
161
|
~CRegConfig()
|
162
|
{
|
163
|
delete[] m_conf;
|
164
|
}
|
165
|
T* data()
|
166
|
{
|
167
|
return( m_conf );
|
168
|
}
|
169
|
void setSetting( const SRegEntry& regEntry, int value )
|
170
|
{
|
171
|
m_conf[ regEntry.addr ]=
|
172
|
setBitFields(
|
173
|
m_conf[ regEntry.addr ],
|
174
|
regEntry.bitStart,
|
175
|
regEntry.bitSize,
|
176
|
value
|
177
|
);
|
178
|
}
|
179
|
T plainSetting( const SRegEntry& regEntry, int value )
|
180
|
{
|
181
|
return(
|
182
|
setBitFields(
|
183
|
regEntry.bitStart,
|
184
|
regEntry.bitSize,
|
185
|
value
|
186
|
) );
|
187
|
}
|
188
|
T getConfig( const SRegEntry& regEntry )
|
189
|
{
|
190
|
return( getBitFields(
|
191
|
m_conf[ regEntry.addr ],
|
192
|
regEntry.bitStart,
|
193
|
regEntry.bitSize
|
194
|
)
|
195
|
);
|
196
|
}
|
197
|
static T setBitFields( T org, T bitPos, T bitSize, T value)
|
198
|
{
|
199
|
T mask=(((T)-1)>>( (sizeof(T)*8) - bitSize)) << bitPos;
|
200
|
return ( ( org & (~mask)) | ( (value << bitPos) & mask ) );
|
201
|
}
|
202
|
static constexpr T setBitFields( const T bitPos, const T bitSize, const T value)
|
203
|
{
|
204
|
return ( value << bitPos );
|
205
|
}
|
206
|
static T getBitFields( T org, T bitPos, T bitSize)
|
207
|
{
|
208
|
T mask=(((T)-1)>>( (sizeof(T)*8) - bitSize)) << bitPos;
|
209
|
return( ( org & mask) >> bitPos );
|
210
|
}
|
211
|
|
212
|
void dumpConfig( SSettingDesctriptor *descriptors, int count )
|
213
|
{
|
214
|
printf("Dumping config:\n");
|
215
|
for(int i1=0; i1<count; i1++)
|
216
|
{
|
217
|
T value=getConfig( descriptors[i1].regEntry );
|
218
|
const char* desc=nullptr;
|
219
|
if( value < MAX_VALUE_TEXTS )
|
220
|
{
|
221
|
desc=descriptors[i1].valueTexts[value];
|
222
|
}
|
223
|
|
224
|
printf(" %s: %d %s\n", descriptors[i1].descText
|
225
|
, value
|
226
|
, desc?desc:"?" );
|
227
|
}
|
228
|
};
|
229
|
};
|
230
|
|
231
|
enum ERegs
|
232
|
{
|
233
|
RegFifo = 0x0,
|
234
|
RegOpMode = 0x1,
|
235
|
RegDataModul = 0x2,
|
236
|
RegBitRateMsb = 0x3,
|
237
|
RegBitRateLsb = 0x4,
|
238
|
RegFdevMsb = 0x5,
|
239
|
RegFdevLsb = 0x6,
|
240
|
RegFrfMsb = 0x7,
|
241
|
RegFrfMid = 0x8,
|
242
|
RegFrfLsb = 0x9,
|
243
|
RegOsc1 = 0xA,
|
244
|
RegAfcCtrl = 0xB,
|
245
|
RegListen1 = 0xD,
|
246
|
RegListen2 = 0xE,
|
247
|
RegListen3 = 0xF,
|
248
|
RegVersion = 0x10,
|
249
|
RegPaLevel = 0x11,
|
250
|
RegPaRamp = 0x12,
|
251
|
RegOcp = 0x13,
|
252
|
RegLna = 0x18,
|
253
|
RegRxBw = 0x19,
|
254
|
RegAfcBw = 0x1A,
|
255
|
RegOokPeak = 0x1B,
|
256
|
RegOokAvg = 0x1C,
|
257
|
RegOokFix = 0x1D,
|
258
|
RegAfcFei = 0x1E,
|
259
|
RegAfcMsb = 0x1F,
|
260
|
RegAfcLsb = 0x20,
|
261
|
RegFeiMsb = 0x21,
|
262
|
RegFeiLsb = 0x22,
|
263
|
RegRssiConfig = 0x23,
|
264
|
RegRssiValue = 0x24,
|
265
|
RegDioMapping1 = 0x25,
|
266
|
RegDioMapping2 = 0x26,
|
267
|
RegIrqFlags1 = 0x27,
|
268
|
RegIrqFlags2 = 0x28,
|
269
|
RegRssiThresh = 0x29,
|
270
|
RegRxTimeout1 = 0x2A,
|
271
|
RegRxTimeout2 = 0x2B,
|
272
|
RegPreambleMsb = 0x2C,
|
273
|
RegPreambleLsb = 0x2D,
|
274
|
RegSyncConfig = 0x2E,
|
275
|
RegSyncValue1 = 0x2F,
|
276
|
RegSyncValue2 = 0x30,
|
277
|
RegSyncValue3 = 0x31,
|
278
|
RegSyncValue4 = 0x32,
|
279
|
RegSyncValue5 = 0x33,
|
280
|
RegSyncValue6 = 0x34,
|
281
|
RegSyncValue7 = 0x35,
|
282
|
RegSyncValue8 = 0x36,
|
283
|
RegPacketConfig1 = 0x37,
|
284
|
RegPayloadLength = 0x38,
|
285
|
RegNodeAdrs = 0x39,
|
286
|
RegBroadcastAdrs = 0x3A,
|
287
|
RegAutoModes = 0x3B,
|
288
|
RegFifoThresh = 0x3C,
|
289
|
RegPacketConfig2 = 0x3D,
|
290
|
RegAesKey1 = 0x3E,
|
291
|
RegAesKey2 = 0x3F,
|
292
|
RegAesKey3 = 0x40,
|
293
|
RegAesKey4 = 0x41,
|
294
|
RegAesKey5 = 0x42,
|
295
|
RegAesKey6 = 0x43,
|
296
|
RegAesKey7 = 0x44,
|
297
|
RegAesKey8 = 0x45,
|
298
|
RegAesKey9 = 0x46,
|
299
|
RegAesKey10 = 0x47,
|
300
|
RegAesKey11 = 0x48,
|
301
|
RegAesKey12 = 0x49,
|
302
|
RegAesKey13 = 0x4A,
|
303
|
RegAesKey14 = 0x4B,
|
304
|
RegAesKey15 = 0x4C,
|
305
|
RegAesKey16 = 0x4D,
|
306
|
RegTemp1 = 0x4E,
|
307
|
RegTemp2 = 0x4F,
|
308
|
RegTestLna = 0x58,
|
309
|
RegTestPa1 = 0x5A,
|
310
|
RegTestPa2 = 0x5C,
|
311
|
RegTestDagc = 0x6F,
|
312
|
RegTestAfc = 0x71,
|
313
|
};
|
314
|
|
315
|
|
316
|
SRegEntry RESequencerOff { RegOpMode, 7, 1 };
|
317
|
namespace ESequencerOff {
|
318
|
enum ESequencerOff: int {
|
319
|
SequencerOn= 0x0,
|
320
|
SequencerOff= 0x1,
|
321
|
};
|
322
|
}
|
323
|
|
324
|
SRegEntry REListenOn { RegOpMode, 6, 1 };
|
325
|
namespace EListenOn {
|
326
|
enum EListenOn: int {
|
327
|
ListenOn= 0x1,
|
328
|
ListenOff= 0x0,
|
329
|
};
|
330
|
}
|
331
|
|
332
|
SRegEntry REListenAbort { RegOpMode, 5, 1 };
|
333
|
|
334
|
SRegEntry REMode { RegOpMode, 2, 3 };
|
335
|
namespace EMode
|
336
|
{
|
337
|
enum EMode: int {
|
338
|
Sleep =0x0,
|
339
|
Standby =0x1,
|
340
|
FrequencySynth =2,
|
341
|
Transmit =3,
|
342
|
Receive =4
|
343
|
};
|
344
|
}
|
345
|
|
346
|
SRegEntry REDataMode { RegDataModul, 5, 2 };
|
347
|
namespace EDataMode
|
348
|
{
|
349
|
enum EDataMode: int {
|
350
|
PacketMode =0,
|
351
|
Reserved =1,
|
352
|
ContinuousWithBitSynchronizer =2,
|
353
|
ContinuousWithoutBitSynchronizer =3,
|
354
|
};
|
355
|
}
|
356
|
|
357
|
SRegEntry REModulationType { RegDataModul, 3, 2 };
|
358
|
namespace EModulationType
|
359
|
{
|
360
|
enum EModulationType: int {
|
361
|
FSK=0,
|
362
|
OOK=1,
|
363
|
};
|
364
|
}
|
365
|
|
366
|
SRegEntry REModulationShaping{ RegDataModul, 0, 2 };
|
367
|
namespace EModulationShaping
|
368
|
{
|
369
|
enum EModulationShaping: int {
|
370
|
None=0,
|
371
|
Gaussian_BT_1_0=1,
|
372
|
Gaussian_BT_0_5=2,
|
373
|
Gaussian_BT_0_3=3,
|
374
|
};
|
375
|
}
|
376
|
|
377
|
SRegEntry REBitRateMsb{ RegBitRateMsb, 0, 8 };
|
378
|
SRegEntry REBitRateLsb{ RegBitRateLsb, 0, 8 };
|
379
|
SRegEntry REFdevMsb{ RegFdevMsb, 0, 8 };
|
380
|
SRegEntry REFdevLsb{ RegFdevLsb, 0, 8 };
|
381
|
SRegEntry REFrfMsb{ RegFrfMsb, 0, 8 };
|
382
|
SRegEntry REFrfMid{ RegFrfMid, 0, 8 };
|
383
|
SRegEntry REFrfLsb{ RegFrfLsb, 0, 8 };
|
384
|
|
385
|
SRegEntry RERcCalStart{ RegOsc1, 7, 1};
|
386
|
SRegEntry RERcCalDone{ RegOsc1, 6, 1};
|
387
|
namespace ERcCalDone
|
388
|
{
|
389
|
enum ERcCalDone: int {
|
390
|
Progress=0,
|
391
|
Done=1,
|
392
|
};
|
393
|
}
|
394
|
|
395
|
SRegEntry REAfcLowBetaOn{ RegAfcCtrl, 5, 1};
|
396
|
namespace EAfcLowBetaOn
|
397
|
{
|
398
|
enum EAfcLowBetaOn: int {
|
399
|
Standard,
|
400
|
Improved,
|
401
|
};
|
402
|
}
|
403
|
|
404
|
SRegEntry REListenResolIdle{ RegListen1, 6, 2};
|
405
|
SRegEntry REListenResolRx{ RegListen1, 4, 2};
|
406
|
SRegEntry REListenCriteria{ RegListen1, 3, 1};
|
407
|
SRegEntry REListenEnd{ RegListen1, 1, 2};
|
408
|
|
409
|
SRegEntry REListenCoefIdle{ RegListen2, 0, 8};
|
410
|
SRegEntry REListenCoefRx{ RegListen3, 0, 8};
|
411
|
|
412
|
SRegEntry REVersion{ RegVersion, 0, 8};
|
413
|
|
414
|
SRegEntry REPa0On{ RegPaLevel, 7, 1};
|
415
|
SRegEntry REPa1On{ RegPaLevel, 6, 1};
|
416
|
SRegEntry REPa2On{ RegPaLevel, 5, 1};
|
417
|
SRegEntry REOutputPower{ RegPaLevel, 0, 5};
|
418
|
|
419
|
SRegEntry REPaRamp{ RegPaRamp, 0, 4};
|
420
|
|
421
|
SRegEntry REOcpOn{ RegOcp, 4, 1};
|
422
|
SRegEntry REOcpTrim{ RegOcp, 0, 4};
|
423
|
|
424
|
SRegEntry RELnaZin{ RegLna, 7, 1};
|
425
|
SRegEntry RELnaCurrentGain{ RegLna, 3, 3};
|
426
|
SRegEntry RELnaGainSelect{ RegLna, 0, 3};
|
427
|
|
428
|
SRegEntry REDccFreq{ RegRxBw, 5, 3};
|
429
|
SRegEntry RERxBwMant{ RegRxBw, 4, 2};
|
430
|
SRegEntry RERxBwExp{ RegRxBw, 0, 3};
|
431
|
|
432
|
SRegEntry REDccFreqAfc{ RegAfcBw, 5, 3};
|
433
|
SRegEntry RERxBwMantAfc{ RegAfcBw, 3, 2};
|
434
|
SRegEntry RERxBwExpAfc{ RegAfcBw, 0, 3};
|
435
|
|
436
|
SRegEntry REOokThreshType{ RegOokPeak, 6, 7};
|
437
|
SRegEntry REOokPeakTheshStep{ RegOokPeak, 3, 3};
|
438
|
SRegEntry REOokPeakTheshDec{ RegOokPeak, 0, 3};
|
439
|
|
440
|
SRegEntry REOokAverageThreshFilt{ RegOokAvg, 6, 2};
|
441
|
|
442
|
SRegEntry REOokFixedThresh{ RegOokFix, 0, 8};
|
443
|
|
444
|
SRegEntry REFeiDone{ RegAfcFei, 6, 1};
|
445
|
SRegEntry REFeiStart{ RegAfcFei, 5, 1};
|
446
|
SRegEntry REAfcDone{ RegAfcFei, 4, 1};
|
447
|
SRegEntry REAfcAutclearOn{ RegAfcFei, 3, 1};
|
448
|
SRegEntry REAfcAutoOn{ RegAfcFei, 2, 1};
|
449
|
SRegEntry REAfcClear{ RegAfcFei, 1, 1};
|
450
|
SRegEntry REAfcStart{ RegAfcFei, 0, 1};
|
451
|
|
452
|
SRegEntry REAfcValueMsb{ RegAfcMsb, 0, 8};
|
453
|
SRegEntry REAfcValueLsb{ RegAfcLsb, 0, 8};
|
454
|
SRegEntry REFeiValueMsb{ RegFeiMsb, 0, 8};
|
455
|
SRegEntry REFeiValueLsb{ RegFeiLsb, 0, 8};
|
456
|
|
457
|
SRegEntry RERssiDone{ RegRssiConfig, 1, 1};
|
458
|
SRegEntry RERssiStart{ RegRssiConfig, 0, 1};
|
459
|
|
460
|
SRegEntry RERssiValue{ RegRssiValue, 0, 8};
|
461
|
|
462
|
SRegEntry REDio0Mapping{ RegDioMapping1, 6, 2};
|
463
|
SRegEntry REDio1Mapping{ RegDioMapping1, 4, 2};
|
464
|
SRegEntry REDio2Mapping{ RegDioMapping1, 2, 2};
|
465
|
SRegEntry REDio3Mapping{ RegDioMapping1, 0, 2};
|
466
|
|
467
|
SRegEntry REDio5Mapping{ RegDioMapping2, 4, 2};
|
468
|
SRegEntry REClkOut{ RegDioMapping2, 0, 3};
|
469
|
|
470
|
SRegEntry REModeReady{ RegIrqFlags1, 7, 1};
|
471
|
SRegEntry RERxReady{ RegIrqFlags1, 6, 1};
|
472
|
SRegEntry RETxReady{ RegIrqFlags1, 5, 1};
|
473
|
SRegEntry REPllLock{ RegIrqFlags1, 4, 1};
|
474
|
SRegEntry RERssi{ RegIrqFlags1, 3, 1};
|
475
|
SRegEntry RETimeout{ RegIrqFlags1, 2, 1};
|
476
|
SRegEntry REAutoMode{ RegIrqFlags1, 1, 1};
|
477
|
SRegEntry RESyncAddressMatch{ RegIrqFlags1, 0, 1};
|
478
|
|
479
|
SRegEntry REFifoFull{ RegIrqFlags2, 7, 1};
|
480
|
SRegEntry REFifoNotEmpty{ RegIrqFlags2, 6, 1};
|
481
|
SRegEntry REFifoLevel{ RegIrqFlags2, 5, 1};
|
482
|
SRegEntry REFifoOverrun{ RegIrqFlags2, 4, 1};
|
483
|
SRegEntry REPacketSent{ RegIrqFlags2, 3, 1};
|
484
|
SRegEntry REPayloadReady{ RegIrqFlags2, 2, 1};
|
485
|
SRegEntry RECrcOk{ RegIrqFlags2, 1, 1};
|
486
|
|
487
|
SRegEntry RERssiThreshold{ RegRssiThresh, 0, 8};
|
488
|
SRegEntry RETimeoutRxStart{ RegRxTimeout1, 0, 8};
|
489
|
SRegEntry RETimeoutRssiThresh{ RegRxTimeout2, 0, 8};
|
490
|
SRegEntry REPreambleSizeMsb{ RegPreambleMsb, 0, 8};
|
491
|
SRegEntry REPreambleSizeLsb{ RegPreambleLsb, 0, 8};
|
492
|
|
493
|
SRegEntry RESyncOn{ RegSyncConfig, 7, 1};
|
494
|
SRegEntry REFifoFillCondition{ RegSyncConfig, 6, 1};
|
495
|
SRegEntry RESyncSize{ RegSyncConfig, 3, 3};
|
496
|
SRegEntry RESyncTol{ RegSyncConfig, 0, 3};
|
497
|
SRegEntry RESyncValue1{ RegSyncValue1, 0, 8};
|
498
|
SRegEntry RESyncValue2{ RegSyncValue2, 0, 8};
|
499
|
SRegEntry RESyncValue3{ RegSyncValue3, 0, 8};
|
500
|
SRegEntry RESyncValue4{ RegSyncValue4, 0, 8};
|
501
|
SRegEntry RESyncValue5{ RegSyncValue5, 0, 8};
|
502
|
SRegEntry RESyncValue6{ RegSyncValue6, 0, 8};
|
503
|
SRegEntry RESyncValue7{ RegSyncValue7, 0, 8};
|
504
|
SRegEntry RESyncValue8{ RegSyncValue8, 0, 8};
|
505
|
|
506
|
SRegEntry REPacketFormat{ RegPacketConfig1, 7, 1};
|
507
|
SRegEntry REDcFree{ RegPacketConfig1, 5, 2};
|
508
|
SRegEntry RECrcOn{ RegPacketConfig1, 4, 1};
|
509
|
SRegEntry RECrcAutoClearOff{ RegPacketConfig1, 3, 1};
|
510
|
SRegEntry REAddressFiltering{ RegPacketConfig1, 1, 2};
|
511
|
|
512
|
SRegEntry REPayloadLength{ RegPayloadLength, 0, 8};
|
513
|
SRegEntry RENodeAddress{ RegNodeAdrs, 0, 8};
|
514
|
SRegEntry REBroadcastAddress{ RegBroadcastAdrs, 0, 8};
|
515
|
|
516
|
SRegEntry REEnterCondition{ RegAutoModes, 5, 3};
|
517
|
SRegEntry REExitCondition{ RegAutoModes, 2, 3};
|
518
|
SRegEntry REIntermediateMode{ RegAutoModes, 0, 2};
|
519
|
|
520
|
SRegEntry RETxStartCondition{ RegFifoThresh, 0, 7};
|
521
|
SRegEntry REFifoThreshold{ RegFifoThresh, 7, 1};
|
522
|
SRegEntry REInterPacketRxDelay{ RegPacketConfig2, 4, 4};
|
523
|
SRegEntry RERestartRx{ RegPacketConfig2, 2, 1};
|
524
|
SRegEntry REAutoRxRestartOn{ RegPacketConfig2, 1, 1};
|
525
|
SRegEntry REAesOn{ RegPacketConfig2, 0, 1};
|
526
|
|
527
|
SRegEntry REAesKey1{ RegAesKey1, 0, 8};
|
528
|
SRegEntry REAesKey2{ RegAesKey2, 0, 8};
|
529
|
SRegEntry REAesKey3{ RegAesKey3, 0, 8};
|
530
|
SRegEntry REAesKey4{ RegAesKey4, 0, 8};
|
531
|
SRegEntry REAesKey5{ RegAesKey5, 0, 8};
|
532
|
SRegEntry REAesKey6{ RegAesKey6, 0, 8};
|
533
|
SRegEntry REAesKey7{ RegAesKey7, 0, 8};
|
534
|
SRegEntry REAesKey8{ RegAesKey8, 0, 8};
|
535
|
SRegEntry REAesKey9{ RegAesKey9, 0, 8};
|
536
|
SRegEntry REAesKey10{ RegAesKey10, 0, 8};
|
537
|
SRegEntry REAesKey11{ RegAesKey11, 0, 8};
|
538
|
SRegEntry REAesKey12{ RegAesKey12, 0, 8};
|
539
|
SRegEntry REAesKey13{ RegAesKey13, 0, 8};
|
540
|
SRegEntry REAesKey14{ RegAesKey14, 0, 8};
|
541
|
SRegEntry REAesKey15{ RegAesKey15, 0, 8};
|
542
|
SRegEntry REAesKey16{ RegAesKey16, 0, 8};
|
543
|
|
544
|
SRegEntry RETempMeasStart{ RegTemp1, 3, 1};
|
545
|
SRegEntry RETempMeasRunning{ RegTemp1, 2, 1};
|
546
|
SRegEntry RETempValue{ RegTemp2, 0, 8};
|
547
|
|
548
|
SRegEntry RESensitivityBoost{ RegTestLna, 0, 8};
|
549
|
SRegEntry REPa13dBm1{ RegTestPa1, 0, 8};
|
550
|
SRegEntry REPa13dBm2{ RegTestPa2, 0, 8};
|
551
|
SRegEntry REContinuousDagc{ RegTestDagc, 0, 8};
|
552
|
SRegEntry RELowBetaAfcOffset{ RegTestAfc, 0, 8};
|
553
|
|
554
|
SSettingDesctriptors descriptors=
|
555
|
{
|
556
|
//------ RegOpMode
|
557
|
{ RESequencerOff, "Sequencer Off", {
|
558
|
[ESequencerOff::SequencerOn]="Sequencer on",
|
559
|
[ESequencerOff::SequencerOff]="Sequencer Off" } },
|
560
|
{ REListenOn, "Listening On", {
|
561
|
[EListenOn::ListenOff]="Listen Off",
|
562
|
[EListenOn::ListenOn]="Listen On" } },
|
563
|
{ REListenAbort, "Abort Listening", {
|
564
|
"Always reads zero" } },
|
565
|
{ REMode, "Operating mode", {
|
566
|
[EMode::Sleep]="Sleep",
|
567
|
[EMode::Standby]="Standby",
|
568
|
[EMode::FrequencySynth]="Frequency Synthesizer mode",
|
569
|
[EMode::Transmit]="Transmitter mode",
|
570
|
[EMode::Receive]="Receiver mode" } },
|
571
|
|
572
|
//------ RegDataModul
|
573
|
{ REDataMode, "Data processing mode", {
|
574
|
[EDataMode::PacketMode]="Packet mode",
|
575
|
[EDataMode::Reserved]="reserved",
|
576
|
[EDataMode::ContinuousWithBitSynchronizer]="continuous with bit synchronizer",
|
577
|
[EDataMode::ContinuousWithoutBitSynchronizer]="continuous without bit synchronizer" } },
|
578
|
{ REModulationType, "Modulation scheme", {
|
579
|
[EModulationType::FSK]="FSK",
|
580
|
[EModulationType::OOK]="OOK" } },
|
581
|
{ REModulationShaping, "Datashaping", {
|
582
|
[EModulationShaping::None]="no shaping",
|
583
|
[EModulationShaping::Gaussian_BT_1_0]="Gaussian filter, BT=1.0",
|
584
|
[EModulationShaping::Gaussian_BT_0_5]="Gaussian filter, BT=0.5",
|
585
|
[EModulationShaping::Gaussian_BT_0_3]="Gaussian filter, BT=0.3" } },
|
586
|
|
587
|
//------ RegBitRateMsb, RegBitRateLsb, RegFdevMsb, RegFdevLsb, RegFrfMsb, RegFrfMid, RegFrfLsb
|
588
|
{ REBitRateMsb, "Bitrate MSB", {
|
589
|
} },
|
590
|
{ REBitRateLsb, "Bitrate LSB", {
|
591
|
} },
|
592
|
{ REFdevMsb, "frequency deviation MSB", {
|
593
|
} },
|
594
|
{ REFdevLsb, "frequency deviation LSB", {
|
595
|
} },
|
596
|
{ REFrfMsb, "RF carrier frequency MSB", {
|
597
|
} },
|
598
|
{ REFrfMid, "RF carrier frequency Mid", {
|
599
|
} },
|
600
|
{ REFrfLsb, "RF carrier frequency LSB", {
|
601
|
} },
|
602
|
|
603
|
//------ RegOsc1
|
604
|
{ RERcCalStart, "Triggers the calibration of the RC oscillator when set", {
|
605
|
"Write only",
|
606
|
} },
|
607
|
{ RERcCalDone, "Calibration done", {
|
608
|
[ERcCalDone::Progress]="RC calibration in progress",
|
609
|
[ERcCalDone::Done]="RC calibration is over",
|
610
|
} },
|
611
|
|
612
|
//------ RegAfcCtrl
|
613
|
{ REAfcLowBetaOn, "Improved AFC routine for signals with modulation index lower than 2", {
|
614
|
[EAfcLowBetaOn::Standard]="Standard AFC routine",
|
615
|
[EAfcLowBetaOn::Improved]="Improved AFC routine",
|
616
|
} },
|
617
|
|
618
|
//------ RegListenMode
|
619
|
{ REListenResolIdle, "Resolution of listen mode idle time", {
|
620
|
"reserved",
|
621
|
"64µs",
|
622
|
"4.4ms",
|
623
|
"262ms"
|
624
|
} },
|
625
|
{ REListenResolRx, "Resolution of listen mode Rx time", {
|
626
|
"reserved",
|
627
|
"64µs",
|
628
|
"4.4ms",
|
629
|
"262ms"
|
630
|
} },
|
631
|
{ REListenCriteria, "Criteria for packet acceptance in Listen mode", {
|
632
|
"signal strength is above RssiThreshold",
|
633
|
"signal strength is above RssiThreshold and SyncAddress matched"
|
634
|
} },
|
635
|
{ REListenEnd, "Action taken after acceptance of packet in listen mode", {
|
636
|
"chip stays in Rx mode",
|
637
|
"mode defined by 'Mode'",
|
638
|
"Listen mode resumes in idle state",
|
639
|
"reserved",
|
640
|
} },
|
641
|
|
642
|
//------ RegListen2, RegListen3
|
643
|
{ REListenCoefIdle, "Duration of the idle phase in listen mode", { } },
|
644
|
{ REListenCoefRx, "Duration of the Rx phase in listen mode", { } },
|
645
|
|
646
|
//------ RegVersion
|
647
|
{ REVersion, "Version code of the chip", { } },
|
648
|
|
649
|
//------ RegPaLevel
|
650
|
{ REPa0On, "Enable PA0, connected to RFIO and LNA", { } },
|
651
|
{ REPa1On, "Enable PA1, on PA_BOOST pin", { } },
|
652
|
{ REPa2On, "Enable PA2, on PA_BOOST pin", { } },
|
653
|
{ REOutputPower, "Output power setting, with 1dB steps", { } },
|
654
|
|
655
|
//------ RegPaRamp
|
656
|
{ REPaRamp, "Rise/Fall time of ramp up/down in FSK", { } },
|
657
|
|
658
|
//------ RegOcp
|
659
|
{ REOcpOn, "Enables overload current protection for the PA", { } },
|
660
|
{ REOcpTrim, "Trimming of Ocp current", { } },
|
661
|
|
662
|
//------ RegLna
|
663
|
{ RELnaZin, "LNAs input impedance", { } },
|
664
|
{ RELnaCurrentGain, "Current LNA gain", { } },
|
665
|
{ RELnaGainSelect, "LNA gain setting", { } },
|
666
|
|
667
|
//------ RegRxBw
|
668
|
{ REDccFreq, "Cut-off frequency of the DC offset canceller", { } },
|
669
|
{ RERxBwMant, "Channel filter bandwidth control", { } },
|
670
|
{ RERxBwExp, "Channel filter bandwith control", { } },
|
671
|
|
672
|
//------ RegAfcBw
|
673
|
{ REDccFreqAfc, "DccFreq parameter used during the AFC", { } },
|
674
|
{ RERxBwMantAfc, "RxBwMant parameter used during the AFC", { } },
|
675
|
{ RERxBwExpAfc, "RxBwExp parameter used during the AFC", { } },
|
676
|
|
677
|
|
678
|
//------ RegOokPeak
|
679
|
{ REOokThreshType, "Selects type of threshold in the OOK data slicer", { } },
|
680
|
{ REOokPeakTheshStep, "Size of each decrement of the RSSI threshold in the OOK demodulator", { } },
|
681
|
{ REOokPeakTheshDec, "Period of decrement of the RSSI threshold in the OOK demodulator", { } },
|
682
|
|
683
|
//------ RegOokAvg, RegOokFix
|
684
|
{ REOokAverageThreshFilt, "Filter coefficients in average mode of the OOK demodulator", { } },
|
685
|
{ REOokFixedThresh, "Fixed threshold value (in dB) in the OOK demodulator", { } },
|
686
|
|
687
|
//------ RegOokAvg
|
688
|
{ REFeiDone, "FEI done", { } },
|
689
|
{ REFeiStart, "write only", { } },
|
690
|
{ REAfcDone, "AFC done", { } },
|
691
|
{ REAfcAutclearOn, "Only valid if AfcAutoOn is set", { } },
|
692
|
{ REAfcAutoOn, "AFC auto on", { } },
|
693
|
{ REAfcClear, "AFC auto clear", { } },
|
694
|
{ REAfcStart, "AFC Start; always 0", { } },
|
695
|
|
696
|
//------ RegAfcMsb, RegAfcLsb, RegFeiMsb, RegFeiLsb
|
697
|
{ REAfcValueMsb, "MSB of the AfcValue, 2’s complement format", { } },
|
698
|
{ REAfcValueLsb, "LSB of the AfcValue, 2’s complement format", { } },
|
699
|
{ REFeiValueMsb, "MSB of the measured frequency offset, 2’s complement", { } },
|
700
|
{ REFeiValueLsb, "LSB of the measured frequency offset, 2’s complement", { } },
|
701
|
|
702
|
//------ RegRssiConfig
|
703
|
{ RERssiDone, "Rssi done", { } },
|
704
|
{ RERssiStart, "Trigger a RSSI measurement when set. Always reads 0", { } },
|
705
|
|
706
|
//------ RegRssiValue
|
707
|
{ RERssiValue, "Absolute value of the RSSI in dBm, 0.5dB steps.", { } },
|
708
|
|
709
|
//------ RegDioMapping1
|
710
|
{ REDio0Mapping, "Mapping of pins DIO0", { } },
|
711
|
{ REDio1Mapping, "Mapping of pins DIO1", { } },
|
712
|
{ REDio2Mapping, "Mapping of pins DIO2", { } },
|
713
|
{ REDio3Mapping, "Mapping of pins DIO3", { } },
|
714
|
{ REDio5Mapping, "Mapping of pins DIO5", { } },
|
715
|
|
716
|
//------ RegDioMapping2
|
717
|
{ REClkOut, "Selects CLKOUT frequency", { } },
|
718
|
|
719
|
//------ RegIrqFlags1
|
720
|
{ REModeReady, "Set when the operation mode requested in Mode, is ready", { } },
|
721
|
{ RERxReady, "Set in Rx mode, after RSSI, AGC and AFC", { } },
|
722
|
{ RETxReady, "Set in Tx mode, after PA ramp-up", { } },
|
723
|
{ REPllLock, "Set (in FS, Rx or Tx) when the PLL is locked", { } },
|
724
|
{ RERssi, "Set in Rx when the RssiValue exceeds RssiThreshold", { } },
|
725
|
{ RETimeout, "Set when a timeout occurs", { } },
|
726
|
{ REAutoMode, "Set when entering Intermediate mode", { } },
|
727
|
{ RESyncAddressMatch, "Set when Sync and Address (if enabled) are detected", { } },
|
728
|
|
729
|
//------ RegIrqFlags2
|
730
|
{ REFifoFull, "Set when FIFO is full", { } },
|
731
|
{ REFifoNotEmpty, "Set when FIFO contains at least one byte", { } },
|
732
|
{ REFifoLevel, "Set when the number of bytes in the FIFO strictly exceeds FifoThreshold", { } },
|
733
|
{ REFifoOverrun, "Set when FIFO overrun occurs", { } },
|
734
|
{ REPacketSent, "Set in Tx when the complete packet has been sent", { } },
|
735
|
{ REPayloadReady, "Set in Rx when the payload is ready", { } },
|
736
|
{ RECrcOk, "Set in Rx when the CRC of the payload is Ok", { } },
|
737
|
|
738
|
//------ RegRssiThresh, RegRxTimeout1, RegRxTimeout2, RegPreambleMsb, RegPreambleLsb
|
739
|
{ RERssiThreshold, "RSSI trigger level for Rssi interrup", { } },
|
740
|
{ RETimeoutRxStart, "Timeout interrupt is generated (Start)", { } },
|
741
|
{ RETimeoutRssiThresh, "Timeout interrupt is generated (Threshold)", { } },
|
742
|
{ REPreambleSizeMsb, "Size of the preamble to be sent (MSB)", { } },
|
743
|
{ REPreambleSizeLsb, "Size of the preamble to be sent (LSB)", { } },
|
744
|
|
745
|
//------ RegSyncConfig
|
746
|
{ RESyncOn, "Enables the Sync word generation and detection", { } },
|
747
|
{ REFifoFillCondition, "FIFO filling condition", { } },
|
748
|
{ RESyncSize, "Size of the Sync word", { } },
|
749
|
{ RESyncTol, "Number of tolerated bit errors in Sync word", { } },
|
750
|
|
751
|
//------ RegSyncValue1...RegSyncValue8
|
752
|
{ RESyncValue1, "1st byte of Sync word", { } },
|
753
|
{ RESyncValue2, "2st byte of Sync word", { } },
|
754
|
{ RESyncValue3, "3st byte of Sync word", { } },
|
755
|
{ RESyncValue4, "4st byte of Sync word", { } },
|
756
|
{ RESyncValue5, "5st byte of Sync word", { } },
|
757
|
{ RESyncValue6, "6st byte of Sync word", { } },
|
758
|
{ RESyncValue7, "7st byte of Sync word", { } },
|
759
|
{ RESyncValue8, "8st byte of Sync word", { } },
|
760
|
|
761
|
//------ RegPacketConfig1
|
762
|
{ REPacketFormat, "Defines the packet format used", { } },
|
763
|
{ REDcFree, "Defines DC-free encoding/decoding performed", { } },
|
764
|
{ RECrcOn, "Enables CRC calculation/check", { } },
|
765
|
{ RECrcAutoClearOff, "Defines the behavior of the packet handler when CRC check fails", { } },
|
766
|
{ REAddressFiltering, "Defines address based filtering in Rx", { } },
|
767
|
|
768
|
//------ RegPayloadLength, RegNodeAdrs, RegBroadcastAdrs
|
769
|
{ REPayloadLength, "payload length/max length in packet mode for RX", { } },
|
770
|
{ RENodeAddress, "Node address used in address filtering", { } },
|
771
|
{ REBroadcastAddress, "Broadcast address used in address filtering", { } },
|
772
|
|
773
|
//------ RegAutoModes
|
774
|
{ REEnterCondition, "Interrupt condition for entering the intermediate mode", { } },
|
775
|
{ REExitCondition, "Interrupt condition for exiting the intermediate mode", { } },
|
776
|
{ REIntermediateMode, "Intermediate mode", { } },
|
777
|
|
778
|
//------ RegFifoThresh
|
779
|
{ RETxStartCondition, "Defines the condition to start packet transmission", { } },
|
780
|
{ REFifoThreshold, "Used to trigger FifoLevel interrup", { } },
|
781
|
|
782
|
//------ RegPacketConfig2
|
783
|
{ REInterPacketRxDelay, "After PayloadReady occurred, defines the delay between FIFO empty and the start of a new RSSI phase for next packet", { } },
|
784
|
{ RERestartRx, "Forces the Receiver in WAIT mode, in Continuous Rx mode", { } },
|
785
|
{ REAutoRxRestartOn, "Enables automatic Rx restart after packet has been completely read from FIFO", { } },
|
786
|
{ REAesOn, "Enable the AES encryption/decryption", { } },
|
787
|
|
788
|
//------ RegAesKey1 ... RegAesKey16
|
789
|
{ REAesKey1, "1st byte of cipher key", { } },
|
790
|
{ REAesKey2, "2nd byte of cipher key", { } },
|
791
|
{ REAesKey3, "3rd byte of cipher key", { } },
|
792
|
{ REAesKey4, "4th byte of cipher key", { } },
|
793
|
{ REAesKey5, "5th byte of cipher key", { } },
|
794
|
{ REAesKey6, "6th byte of cipher key", { } },
|
795
|
{ REAesKey7, "7th byte of cipher key", { } },
|
796
|
{ REAesKey8, "8th byte of cipher key", { } },
|
797
|
{ REAesKey9, "9th byte of cipher key", { } },
|
798
|
{ REAesKey10, "10th byte of cipher key", { } },
|
799
|
{ REAesKey11, "11th byte of cipher key", { } },
|
800
|
{ REAesKey12, "12th byte of cipher key", { } },
|
801
|
{ REAesKey13, "13th byte of cipher key", { } },
|
802
|
{ REAesKey14, "14th byte of cipher key", { } },
|
803
|
{ REAesKey15, "15th byte of cipher key", { } },
|
804
|
{ REAesKey16, "16th byte of cipher key", { } },
|
805
|
|
806
|
{ RETempMeasStart, "Triggers the temperature measurement when set", { } },
|
807
|
{ RETempMeasRunning, "Set to 1 while the temperature measurement is running", { } },
|
808
|
{ RETempValue, "Measured temperature", { } },
|
809
|
|
810
|
//------ RegTemp1
|
811
|
{ RETempMeasStart, "Triggers the temperature measurement when set", { } },
|
812
|
{ RETempMeasRunning, "Set to 1 while the temperature measurement is running", { } },
|
813
|
{ RETempValue, "Measured temperature", { } },
|
814
|
|
815
|
//------ Test registers
|
816
|
{ RESensitivityBoost, "High sensitivity(0x2D) or normal sensitivity mode(0x1B)", { } },
|
817
|
{ REPa13dBm1, "Set to 0x5D for +13 dBm operation", { } },
|
818
|
{ REPa13dBm2, "Set to 0x7C for +13 dBm operation", { } },
|
819
|
{ REContinuousDagc, "Fading Margin Improvement", { } },
|
820
|
{ RELowBetaAfcOffset, "AFC offset set for low modulation index systems, used if AfcLowBetaOn=1", { } },
|
821
|
};
|
822
|
|
823
|
int main(int argc, const char *argv[])
|
824
|
{
|
825
|
CPlain p;
|
826
|
CRegConfig <uint8_t> conf(0x100);
|
827
|
//, regEntries);
|
828
|
|
829
|
SSettingDesctriptor *d=descriptors;
|
830
|
|
831
|
conf.setSetting( RESequencerOff, 1);
|
832
|
|
833
|
// /* 0x01 */ { REG_OPMODE, RF_OPMODE_SEQUENCER_ON | RF_OPMODE_LISTEN_OFF | RF_OPMODE_STANDBY },
|
834
|
|
835
|
conf.data()[ RegOpMode ] = conf.plainSetting( RESequencerOff, ESequencerOff::SequencerOn)
|
836
|
| conf.plainSetting( REListenOn, EListenOn::ListenOff)
|
837
|
| conf.plainSetting( REMode, EMode::Standby);
|
838
|
|
839
|
//conf.setDescriptors( descriptors );
|
840
|
conf.dumpConfig( descriptors, sizeof(descriptors)/sizeof(descriptors[0]) );
|
841
|
|
842
|
p.myI2c.setData(10);
|
843
|
p.setInfo( 0x100 );
|
844
|
|
845
|
p.temp.showData();
|
846
|
|
847
|
printf( "Size: %d\n", sizeof( CPlain::temp ) );
|
848
|
|
849
|
CApp<SEeprom, CPlain> p2;
|
850
|
p2.myI2c.setData( 666 );
|
851
|
p2.showData();
|
852
|
printf( "Size p2: %d\n", sizeof( p2 ) );
|
853
|
printf( "Size plain: %d\n", sizeof( CPlain ) );
|
854
|
return(0);
|
855
|
}
|
856
|
|