Skip to content

Commit 9c1f3a4

Browse files
Daniel Jaecklemluis1
authored andcommitted
Fixed RU864 Class B ping-slot frequency.
Updated Class B ping-slot handling in order to have different frequency value from beacon.
1 parent 657c507 commit 9c1f3a4

22 files changed

+184
-28
lines changed

src/mac/LoRaMacClassB.c

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -223,63 +223,74 @@ static void ComputePingOffset( uint64_t beaconTime, uint32_t address, uint16_t p
223223
*
224224
* \param [IN] channel The channel according to the channel plan.
225225
*
226+
* \param [IN] isBeacon Set to true, if the function shall
227+
* calculate the frequency for a beacon.
228+
*
226229
* \retval The downlink frequency
227230
*/
228-
static uint32_t CalcDownlinkFrequency( uint8_t channel )
231+
static uint32_t CalcDownlinkFrequency( uint8_t channel, bool isBeacon )
229232
{
230233
GetPhyParams_t getPhy;
231234
PhyParam_t phyParam;
232-
uint32_t frequency = 0;
233-
uint32_t stepwidth = 0;
234235

235-
getPhy.Attribute = PHY_BEACON_CHANNEL_FREQ;
236-
phyParam = RegionGetPhyParam( *Ctx.LoRaMacClassBParams.LoRaMacRegion, &getPhy );
237-
frequency = phyParam.Value;
236+
getPhy.Attribute = PHY_PING_SLOT_CHANNEL_FREQ;
238237

239-
getPhy.Attribute = PHY_BEACON_CHANNEL_STEPWIDTH;
238+
if( isBeacon == true )
239+
{
240+
getPhy.Attribute = PHY_BEACON_CHANNEL_FREQ;
241+
}
242+
getPhy.Channel = channel;
240243
phyParam = RegionGetPhyParam( *Ctx.LoRaMacClassBParams.LoRaMacRegion, &getPhy );
241-
stepwidth = phyParam.Value;
242244

243-
// Calculate the frequency
244-
return frequency + ( channel * stepwidth );
245+
return phyParam.Value;
245246
}
246247

247248
/*!
248249
* \brief Calculates the downlink channel for the beacon and for
249250
* ping slot downlinks.
250251
*
251-
* \param [IN] devAddr The address of the device
252+
* \param [IN] devAddr The address of the device. Assign 0 if its a beacon.
252253
*
253254
* \param [IN] beaconTime The beacon time of the beacon.
254255
*
255-
* \param [IN] beaconInterval The beacon interval
256+
* \param [IN] beaconInterval The beacon interval.
257+
*
258+
* \param [IN] isBeacon Set to true, if the function shall
259+
* calculate the frequency for a beacon.
256260
*
257261
* \retval The downlink channel
258262
*/
259-
static uint32_t CalcDownlinkChannelAndFrequency( uint32_t devAddr, TimerTime_t beaconTime, TimerTime_t beaconInterval )
263+
static uint32_t CalcDownlinkChannelAndFrequency( uint32_t devAddr, TimerTime_t beaconTime,
264+
TimerTime_t beaconInterval, bool isBeacon )
260265
{
261266
GetPhyParams_t getPhy;
262267
PhyParam_t phyParam;
263268
uint32_t channel = 0;
264269
uint8_t nbChannels = 0;
265-
uint32_t frequency = 0;
266270

267-
getPhy.Attribute = PHY_BEACON_NB_CHANNELS;
271+
// Default initialization - ping slot channels
272+
getPhy.Attribute = PHY_PING_SLOT_NB_CHANNELS;
273+
274+
if( isBeacon == true )
275+
{
276+
// Beacon channels
277+
getPhy.Attribute = PHY_BEACON_NB_CHANNELS;
278+
}
268279
phyParam = RegionGetPhyParam( *Ctx.LoRaMacClassBParams.LoRaMacRegion, &getPhy );
269-
nbChannels = (uint8_t) phyParam.Value;
280+
nbChannels = ( uint8_t ) phyParam.Value;
270281

282+
// nbChannels is > 1, when the channel plan requires more than one possible channel
283+
// defined by the calculation below.
271284
if( nbChannels > 1 )
272285
{
273286
// Calculate the channel for the next downlink
274287
channel = devAddr + ( beaconTime / ( beaconInterval / 1000 ) );
275288
channel = channel % nbChannels;
276289
}
277290

278-
// Calculate the frequency for the next downlink
279-
frequency = CalcDownlinkFrequency( channel );
280-
281-
// Calculate the frequency for the next downlink
282-
return frequency;
291+
// Calculate the frequency for the next downlink. This holds
292+
// for beacons and ping slots.
293+
return CalcDownlinkFrequency( channel, isBeacon );
283294
}
284295

285296
/*!
@@ -302,13 +313,13 @@ static void RxBeaconSetup( TimerTime_t rxTime, bool activateDefaultChannel )
302313
{
303314
// This is the default frequency in case we don't know when the next
304315
// beacon will be transmitted. We select channel 0 as default.
305-
frequency = CalcDownlinkFrequency( 0 );
316+
frequency = CalcDownlinkFrequency( 0, true );
306317
}
307318
else
308319
{
309320
// This is the frequency according to the channel plan
310321
frequency = CalcDownlinkChannelAndFrequency( 0, Ctx.BeaconCtx.BeaconTime.Seconds + ( CLASSB_BEACON_INTERVAL / 1000 ),
311-
CLASSB_BEACON_INTERVAL );
322+
CLASSB_BEACON_INTERVAL, true );
312323
}
313324

314325
if( Ctx.NvmCtx->BeaconCtx.Ctrl.CustomFreq == 1 )
@@ -321,7 +332,7 @@ static void RxBeaconSetup( TimerTime_t rxTime, bool activateDefaultChannel )
321332
{
322333
// Set the frequency which was provided by BeaconTimingAns MAC command
323334
Ctx.BeaconCtx.Ctrl.BeaconChannelSet = 0;
324-
frequency = CalcDownlinkFrequency( Ctx.BeaconCtx.BeaconTimingChannel );
335+
frequency = CalcDownlinkFrequency( Ctx.BeaconCtx.BeaconTimingChannel, true );
325336
}
326337

327338
if( ( Ctx.BeaconCtx.Ctrl.BeaconAcquired == 1 ) || ( Ctx.BeaconCtx.Ctrl.AcquisitionPending == 1 ) )
@@ -1021,7 +1032,8 @@ static void LoRaMacClassBProcessPingSlot( void )
10211032
if( Ctx.NvmCtx->PingSlotCtx.Ctrl.CustomFreq == 0 )
10221033
{
10231034
// Restore floor plan
1024-
frequency = CalcDownlinkChannelAndFrequency( *Ctx.LoRaMacClassBParams.LoRaMacDevAddr, Ctx.BeaconCtx.BeaconTime.Seconds, CLASSB_BEACON_INTERVAL );
1035+
frequency = CalcDownlinkChannelAndFrequency( *Ctx.LoRaMacClassBParams.LoRaMacDevAddr, Ctx.BeaconCtx.BeaconTime.Seconds,
1036+
CLASSB_BEACON_INTERVAL, false );
10251037
}
10261038

10271039
// Open the ping slot window only, if there is no multicast ping slot
@@ -1178,7 +1190,8 @@ static void LoRaMacClassBProcessMulticastSlot( void )
11781190
if( frequency == 0 )
11791191
{
11801192
// Restore floor plan
1181-
frequency = CalcDownlinkChannelAndFrequency( Ctx.PingSlotCtx.NextMulticastChannel->ChannelParams.Address, Ctx.BeaconCtx.BeaconTime.Seconds, CLASSB_BEACON_INTERVAL );
1193+
frequency = CalcDownlinkChannelAndFrequency( Ctx.PingSlotCtx.NextMulticastChannel->ChannelParams.Address,
1194+
Ctx.BeaconCtx.BeaconTime.Seconds, CLASSB_BEACON_INTERVAL, false );
11821195
}
11831196

11841197
Ctx.MulticastSlotState = PINGSLOT_STATE_RX;

src/mac/region/Region.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,10 +808,18 @@ typedef enum ePhyAttribute
808808
* The number of channels for the beacon reception.
809809
*/
810810
PHY_BEACON_NB_CHANNELS,
811+
/*!
812+
* Ping slot channel frequency.
813+
*/
814+
PHY_PING_SLOT_CHANNEL_FREQ,
811815
/*!
812816
* The datarate of a ping slot channel.
813817
*/
814818
PHY_PING_SLOT_CHANNEL_DR,
819+
/*
820+
* The number of channels for the ping slot reception.
821+
*/
822+
PHY_PING_SLOT_NB_CHANNELS,
815823
/*!
816824
* The equivalent spreading factor value from datarate
817825
*/
@@ -933,6 +941,12 @@ typedef struct sGetPhyParams
933941
* PHY_MIN_RX_DR, PHY_MAX_PAYLOAD.
934942
*/
935943
uint8_t DownlinkDwellTime;
944+
/*!
945+
* Specification of the downlink channel. Used in Class B only.
946+
* The parameter is needed for the following queries:
947+
* PHY_BEACON_CHANNEL_FREQ, PHY_PING_SLOT_CHANNEL_FREQ
948+
*/
949+
uint8_t Channel;
936950
}GetPhyParams_t;
937951

938952
/*!

src/mac/region/RegionAS923.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ PhyParam_t RegionAS923GetPhyParam( GetPhyParams_t* getPhy )
327327
phyParam.Value = AS923_BEACON_CHANNEL_DR;
328328
break;
329329
}
330+
case PHY_PING_SLOT_CHANNEL_FREQ:
331+
{
332+
phyParam.Value = AS923_PING_SLOT_CHANNEL_FREQ;
333+
break;
334+
}
330335
case PHY_PING_SLOT_CHANNEL_DR:
331336
{
332337
phyParam.Value = AS923_PING_SLOT_CHANNEL_DR;
@@ -335,6 +340,7 @@ PhyParam_t RegionAS923GetPhyParam( GetPhyParams_t* getPhy )
335340
case PHY_SF_FROM_DR:
336341
{
337342
phyParam.Value = DataratesAS923[getPhy->Datarate];
343+
break;
338344
}
339345
default:
340346
{

src/mac/region/RegionAS923.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ extern "C"
217217
*/
218218
#define AS923_BEACON_CHANNEL_FREQ 923400000
219219

220+
/*!
221+
* Ping slot channel frequency
222+
*/
223+
#define AS923_PING_SLOT_CHANNEL_FREQ 923400000
224+
220225
/*!
221226
* Payload size of a beacon frame
222227
*/

src/mac/region/RegionAU915.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ PhyParam_t RegionAU915GetPhyParam( GetPhyParams_t* getPhy )
324324
}
325325
case PHY_BEACON_CHANNEL_FREQ:
326326
{
327-
phyParam.Value = AU915_BEACON_CHANNEL_FREQ;
327+
phyParam.Value = AU915_BEACON_CHANNEL_FREQ + ( getPhy->Channel * AU915_BEACON_CHANNEL_STEPWIDTH );
328328
break;
329329
}
330330
case PHY_BEACON_FORMAT:
@@ -349,6 +349,11 @@ PhyParam_t RegionAU915GetPhyParam( GetPhyParams_t* getPhy )
349349
phyParam.Value = AU915_BEACON_NB_CHANNELS;
350350
break;
351351
}
352+
case PHY_PING_SLOT_CHANNEL_FREQ:
353+
{
354+
phyParam.Value = AU915_PING_SLOT_CHANNEL_FREQ + ( getPhy->Channel * AU915_BEACON_CHANNEL_STEPWIDTH );
355+
break;
356+
}
352357
case PHY_PING_SLOT_CHANNEL_DR:
353358
{
354359
phyParam.Value = AU915_PING_SLOT_CHANNEL_DR;
@@ -357,6 +362,7 @@ PhyParam_t RegionAU915GetPhyParam( GetPhyParams_t* getPhy )
357362
case PHY_SF_FROM_DR:
358363
{
359364
phyParam.Value = DataratesAU915[getPhy->Datarate];
365+
break;
360366
}
361367
default:
362368
{

src/mac/region/RegionAU915.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ extern "C"
208208
*/
209209
#define AU915_BEACON_CHANNEL_STEPWIDTH 600000
210210

211+
/*!
212+
* Ping slot channel frequency
213+
*/
214+
#define AU915_PING_SLOT_CHANNEL_FREQ 923300000
215+
211216
/*!
212217
* Number of possible beacon channels
213218
*/

src/mac/region/RegionCN470.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ PhyParam_t RegionCN470GetPhyParam( GetPhyParams_t* getPhy )
278278
phyParam.fValue = CN470_DEFAULT_ANTENNA_GAIN;
279279
break;
280280
}
281+
case PHY_BEACON_CHANNEL_FREQ:
282+
{
283+
phyParam.Value = CN470_BEACON_CHANNEL_FREQ;
284+
break;
285+
}
281286
case PHY_BEACON_FORMAT:
282287
{
283288
phyParam.BeaconFormat.BeaconSize = CN470_BEACON_SIZE;
@@ -300,6 +305,11 @@ PhyParam_t RegionCN470GetPhyParam( GetPhyParams_t* getPhy )
300305
phyParam.Value = CN470_BEACON_NB_CHANNELS;
301306
break;
302307
}
308+
case PHY_PING_SLOT_CHANNEL_FREQ:
309+
{
310+
phyParam.Value = CN470_PING_SLOT_CHANNEL_FREQ;
311+
break;
312+
}
303313
case PHY_PING_SLOT_CHANNEL_DR:
304314
{
305315
phyParam.Value = CN470_PING_SLOT_CHANNEL_DR;
@@ -308,6 +318,7 @@ PhyParam_t RegionCN470GetPhyParam( GetPhyParams_t* getPhy )
308318
case PHY_SF_FROM_DR:
309319
{
310320
phyParam.Value = DataratesCN470[getPhy->Datarate];
321+
break;
311322
}
312323
default:
313324
{

src/mac/region/RegionCN470.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ extern "C"
192192
*/
193193
#define CN470_BEACON_CHANNEL_STEPWIDTH 200000
194194

195+
/*!
196+
* Ping slot channel frequency
197+
*/
198+
#define CN470_PING_SLOT_CHANNEL_FREQ 508300000
199+
195200
/*!
196201
* Number of possible beacon channels
197202
*/

src/mac/region/RegionCN779.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ PhyParam_t RegionCN779GetPhyParam( GetPhyParams_t* getPhy )
295295
phyParam.Value = CN779_BEACON_CHANNEL_DR;
296296
break;
297297
}
298+
case PHY_PING_SLOT_CHANNEL_FREQ:
299+
{
300+
phyParam.Value = CN779_PING_SLOT_CHANNEL_FREQ;
301+
break;
302+
}
298303
case PHY_PING_SLOT_CHANNEL_DR:
299304
{
300305
phyParam.Value = CN779_PING_SLOT_CHANNEL_DR;
@@ -303,6 +308,7 @@ PhyParam_t RegionCN779GetPhyParam( GetPhyParams_t* getPhy )
303308
case PHY_SF_FROM_DR:
304309
{
305310
phyParam.Value = DataratesCN779[getPhy->Datarate];
311+
break;
306312
}
307313
default:
308314
{

src/mac/region/RegionCN779.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ extern "C"
204204
*/
205205
#define CN779_BEACON_CHANNEL_FREQ 785000000
206206

207+
/*!
208+
* Ping slot channel frequency
209+
*/
210+
#define CN779_PING_SLOT_CHANNEL_FREQ 785000000
211+
207212
/*!
208213
* Payload size of a beacon frame
209214
*/

0 commit comments

Comments
 (0)