Skip to content

Commit cf98fe6

Browse files
committed
[ot-rfsim] clean up usage of global vars/externs (#769)
The usage of global vars and 'extern' in the RFSIM platform was hard to disentangle. This fixes the issue by placing all 'extern' references in the header file along with comments as to what these variables do. This way, all the relevant sources have access to these global vars.
1 parent f478cdd commit cf98fe6

6 files changed

Lines changed: 18 additions & 16 deletions

File tree

ot-rfsim/src/event-sim.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737
#include "event-sim.h"
3838
#include "platform-rfsim.h"
3939

40-
// socket communication parameters for events
41-
extern int gSockFd;
42-
extern struct Event gLastRecvEvent;
43-
4440
struct Event gLastSentEvent;
4541

4642
void otSimSendSleepEvent(void)

ot-rfsim/src/misc.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2024, The OpenThread Authors.
2+
* Copyright (c) 2016-2026, The OpenThread Authors.
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -37,8 +37,7 @@
3737

3838
#include "common/logging.hpp"
3939

40-
extern jmp_buf gResetJump;
41-
extern struct Event gLastSentEvent, gLastRecvEvent;
40+
extern jmp_buf gResetJump;
4241

4342
otPlatResetReason gPlatResetReason = OT_PLAT_RESET_REASON_POWER_ON;
4443
bool gPlatformPseudoResetWasRequested;

ot-rfsim/src/platform-rfsim.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,9 @@
5757

5858
static const otIp6Address kUnspecifiedIp6Address = {.mFields = {.m32 = {0, 0, 0, 0}}};
5959

60-
extern int gSockFd;
61-
6260
void platformRfsimInit(void)
6361
{
64-
// No actions currently.
62+
// No actions currently. Global structs are automatically zero-initialized.
6563
}
6664

6765
void platformExit(int exitCode)

ot-rfsim/src/platform-rfsim.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2024, The OpenThread Authors.
2+
* Copyright (c) 2016-2026, The OpenThread Authors.
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -67,21 +67,29 @@
6767

6868
/**
6969
* Unique node ID.
70-
*
7170
*/
7271
extern uint32_t gNodeId;
7372

7473
/**
75-
* MsgId of last received event from simulator, or 0 if no MsgId yet received.
74+
* Last received event from simulator.
75+
*/
76+
extern struct Event gLastRecvEvent;
77+
78+
/**
79+
* Last (attempted and/or succeeded) sent event to simulator.
7680
*/
77-
extern uint64_t gLastMsgId;
81+
extern struct Event gLastSentEvent;
7882

7983
/**
8084
* State of requested termination of this node process.
81-
*
8285
*/
8386
extern volatile bool gTerminate;
8487

88+
/**
89+
* Unix socket file descriptor for communication with simulator.
90+
*/
91+
extern int gSockFd;
92+
8593
/**
8694
* initializes the alarm/time service used by OpenThread.
8795
*

ot-rfsim/src/system.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ void otSysProcessDrivers(otInstance *aInstance)
156156
is_new_event = true;
157157
}
158158

159+
// Sleep if nothing more to do
159160
if (!is_new_event && !otTaskletsArePending(aInstance) && platformAlarmGetNext() > 0 &&
160161
(!platformRadioIsTransmitPending() || platformRadioIsBusy()) && !platformUartHasPendingData())
161162
{

radiomodel/radionode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (rn *RadioNode) SetChannel(ch ChannelId) {
8989
}
9090

9191
// SetTxDone moves the physical radio state, if currently Tx, to Rx. The RadioSubState is not altered, as
92-
// the expectation is that the node will report its state/substate soon after using an EventTypeRadioState
92+
// the expectation is that the node will report its state/substate soon after: with an EventTypeRadioState
9393
// event. Setting the RadioState to RadioRx here will enable frame dispatching to the node again, which is
9494
// not done while the radio is in RadioTx state. The RFSIM simulated radio further determines (based on its
9595
// substate) whether the node will be able to receive the frame dispatched to it.

0 commit comments

Comments
 (0)