Skip to content

Commit e0a74a7

Browse files
authored
flexray: add second keyslot to config (#289)
Add a second keyslot to the FlexrayNodeParameters, bump the structure version and ensure that we are backward compatible on a network protocol level and on API / abi level. Fix some UB in the yaml parser which used uninitialized objects on the stack. --------- Signed-off-by: Marius Börschig <marius.boerschig@vector.com>
1 parent 299d068 commit e0a74a7

15 files changed

Lines changed: 92 additions & 44 deletions

SilKit/include/silkit/capi/Flexray.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,6 @@ struct SilKit_FlexrayNodeParameters
216216
//! Maximum permissible rate correction value (range 3-3846 MicroTicks).
217217
SilKit_FlexrayMicroTick pRateCorrectionOut;
218218

219-
////! Not used by network simulator
220-
// pSecondKeySlotID
221-
222-
////! Not used by network simulator
223-
// pTwoKeySlotMode
224-
225219
//! Channel used by the node to send a wakeup pattern (values FlexrayChannel::A, FlexrayChannel::B).
226220
SilKit_FlexrayChannel pWakeupChannel;
227221

@@ -242,6 +236,15 @@ struct SilKit_FlexrayNodeParameters
242236

243237
//! Number of samples per MicroTick (values 1 or 2).
244238
uint8_t pSamplesPerMicrotick;
239+
240+
// ----------------------------------------------------------------------
241+
// Parameters according to B.3.2.1 (added in SIL Kit 5.0.3)
242+
243+
//! Second Key Slot ID of the key slot (range 0-1023, value 0 means that there is no key slot).
244+
uint16_t pSecondKeySlotId;
245+
246+
//! Second Key slot is used for startup with a single cold start node (range 0, 1).
247+
uint8_t pTwoKeySlotMode;
245248
};
246249
typedef struct SilKit_FlexrayNodeParameters SilKit_FlexrayNodeParameters;
247250

SilKit/include/silkit/capi/InterfaceIdentifiers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ typedef struct
137137
#define SilKit_FlexrayWakeupEvent_VERSION 1
138138
#define SilKit_FlexrayControllerConfig_VERSION 1
139139
#define SilKit_FlexrayClusterParameters_VERSION 1
140-
#define SilKit_FlexrayNodeParameters_VERSION 1
140+
#define SilKit_FlexrayNodeParameters_VERSION 2
141141
#define SilKit_FlexrayHostCommand_VERSION 1
142142
#define SilKit_FlexrayHeader_VERSION 1
143143
#define SilKit_FlexrayFrame_VERSION 1

SilKit/include/silkit/detail/impl/HourglassConversions.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ inline void assignCxxToC(const SilKit::Services::Flexray::FlexrayNodeParameters&
221221
cOut.pWakeupPattern = cxxIn.pWakeupPattern;
222222
cOut.pdMicrotick = static_cast<SilKit_FlexrayClockPeriod>(cxxIn.pdMicrotick);
223223
cOut.pSamplesPerMicrotick = cxxIn.pSamplesPerMicrotick;
224+
cOut.pTwoKeySlotMode = cxxIn.pTwoKeySlotMode;
225+
cOut.pSecondKeySlotId = cxxIn.pSecondKeySlotId;
224226
}
225227

226228
inline void assignCxxToC(const SilKit::Services::Flexray::FlexrayTxBufferConfig& cxxIn,
@@ -651,6 +653,8 @@ inline void assignCToCxx(const SilKit_FlexrayNodeParameters* cIn,
651653
cxxOut.pWakeupPattern = cIn->pWakeupPattern;
652654
cxxOut.pdMicrotick = (SilKit::Services::Flexray::FlexrayClockPeriod)cIn->pdMicrotick;
653655
cxxOut.pSamplesPerMicrotick = cIn->pSamplesPerMicrotick;
656+
cxxOut.pTwoKeySlotMode = cIn->pTwoKeySlotMode;
657+
cxxOut.pSecondKeySlotId = cIn->pSecondKeySlotId;
654658
}
655659

656660
// -----------------------------------

SilKit/include/silkit/detail/impl/services/flexray/FlexrayController.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ void CxxToC(const SilKit::Services::Flexray::FlexrayNodeParameters& cxxFlexrayNo
567567
cFlexrayNodeParameters.pWakeupPattern = cxxFlexrayNodeParameters.pWakeupPattern;
568568
cFlexrayNodeParameters.pdMicrotick = static_cast<SilKit_FlexrayClockPeriod>(cxxFlexrayNodeParameters.pdMicrotick);
569569
cFlexrayNodeParameters.pSamplesPerMicrotick = cxxFlexrayNodeParameters.pSamplesPerMicrotick;
570+
cFlexrayNodeParameters.pTwoKeySlotMode = cxxFlexrayNodeParameters.pTwoKeySlotMode;
571+
cFlexrayNodeParameters.pSecondKeySlotId = cxxFlexrayNodeParameters.pSecondKeySlotId;
570572
}
571573

572574
void CxxToC(const SilKit::Services::Flexray::FlexrayTxBufferConfig& cxxFlexrayTxBufferConfig,

SilKit/include/silkit/services/flexray/FlexrayDatatypes.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,6 @@ struct FlexrayNodeParameters
211211

212212
//! Maximum permissible rate correction value (range 3-3846 MicroTicks).
213213
FlexrayMicroTick pRateCorrectionOut;
214-
215-
////! Not used by network simulator
216-
//pSecondKeySlotID
217-
218-
////! Not used by network simulator
219-
//pTwoKeySlotMode
220-
221214
//! Channel used by the node to send a wakeup pattern (values FlexrayChannel::A, FlexrayChannel::B).
222215
FlexrayChannel pWakeupChannel;
223216

@@ -238,6 +231,15 @@ struct FlexrayNodeParameters
238231

239232
//! Number of samples per MicroTick (values 1 or 2).
240233
uint8_t pSamplesPerMicrotick;
234+
235+
// ----------------------------------------------------------------------
236+
// Parameters according to B.3.2.1 (added in SIL Kit 5.0.3)
237+
238+
//! Second Key Slot ID of the key slot (range 0-1023, value 0 means that there is no key slot).
239+
uint16_t pSecondKeySlotId;
240+
241+
//! Second Key slot is used for startup with a single cold start node (range 0, 1).
242+
uint8_t pTwoKeySlotMode;
241243
};
242244

243245
//! Transmission mode for FlexRay Tx-Buffer
@@ -537,7 +539,9 @@ inline bool operator==(const FlexrayNodeParameters& lhs, const FlexrayNodeParame
537539
&& lhs.pOffsetCorrectionStart == rhs.pOffsetCorrectionStart
538540
&& lhs.pRateCorrectionOut == rhs.pRateCorrectionOut && lhs.pWakeupChannel == rhs.pWakeupChannel
539541
&& lhs.pWakeupPattern == rhs.pWakeupPattern && lhs.pdMicrotick == rhs.pdMicrotick
540-
&& lhs.pSamplesPerMicrotick == rhs.pSamplesPerMicrotick;
542+
&& lhs.pSamplesPerMicrotick == rhs.pSamplesPerMicrotick && lhs.pSecondKeySlotId == rhs.pSecondKeySlotId
543+
&& lhs.pTwoKeySlotMode == rhs.pTwoKeySlotMode
544+
;
541545
}
542546

543547
inline bool operator==(const FlexrayTxBufferConfig& lhs, const FlexrayTxBufferConfig& rhs)

SilKit/source/capi/CapiFlexray.cpp

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,40 @@ void assign(SilKit::Services::Flexray::FlexrayClusterParameters& cppClusterParam
5454
void assign(SilKit::Services::Flexray::FlexrayNodeParameters& cppNodeParameters,
5555
const SilKit_FlexrayNodeParameters* nodeParameters)
5656
{
57-
cppNodeParameters.pAllowHaltDueToClock = nodeParameters->pAllowHaltDueToClock;
58-
cppNodeParameters.pAllowPassiveToActive = nodeParameters->pAllowPassiveToActive;
59-
cppNodeParameters.pChannels = (SilKit::Services::Flexray::FlexrayChannel)nodeParameters->pChannels;
60-
cppNodeParameters.pClusterDriftDamping = nodeParameters->pClusterDriftDamping;
61-
cppNodeParameters.pdAcceptedStartupRange = nodeParameters->pdAcceptedStartupRange;
62-
cppNodeParameters.pdListenTimeout = nodeParameters->pdListenTimeout;
63-
cppNodeParameters.pKeySlotId = nodeParameters->pKeySlotId;
64-
cppNodeParameters.pKeySlotOnlyEnabled = nodeParameters->pKeySlotOnlyEnabled;
65-
cppNodeParameters.pKeySlotUsedForStartup = nodeParameters->pKeySlotUsedForStartup;
66-
cppNodeParameters.pKeySlotUsedForSync = nodeParameters->pKeySlotUsedForSync;
67-
cppNodeParameters.pLatestTx = nodeParameters->pLatestTx;
68-
cppNodeParameters.pMacroInitialOffsetA = nodeParameters->pMacroInitialOffsetA;
69-
cppNodeParameters.pMacroInitialOffsetB = nodeParameters->pMacroInitialOffsetB;
70-
cppNodeParameters.pMicroInitialOffsetA = nodeParameters->pMicroInitialOffsetA;
71-
cppNodeParameters.pMicroInitialOffsetB = nodeParameters->pMicroInitialOffsetB;
72-
cppNodeParameters.pMicroPerCycle = nodeParameters->pMicroPerCycle;
73-
cppNodeParameters.pOffsetCorrectionOut = nodeParameters->pOffsetCorrectionOut;
74-
cppNodeParameters.pOffsetCorrectionStart = nodeParameters->pOffsetCorrectionStart;
75-
cppNodeParameters.pRateCorrectionOut = nodeParameters->pRateCorrectionOut;
76-
cppNodeParameters.pWakeupChannel = (SilKit::Services::Flexray::FlexrayChannel)nodeParameters->pWakeupChannel;
77-
cppNodeParameters.pWakeupPattern = nodeParameters->pWakeupPattern;
78-
cppNodeParameters.pdMicrotick = (SilKit::Services::Flexray::FlexrayClockPeriod)nodeParameters->pdMicrotick;
79-
cppNodeParameters.pSamplesPerMicrotick = nodeParameters->pSamplesPerMicrotick;
57+
const auto inputVersion = SK_ID_GET_VERSION(SilKit_Struct_GetId(*nodeParameters));
58+
59+
if (inputVersion == 1 || inputVersion == 2)
60+
{
61+
cppNodeParameters.pAllowHaltDueToClock = nodeParameters->pAllowHaltDueToClock;
62+
cppNodeParameters.pAllowPassiveToActive = nodeParameters->pAllowPassiveToActive;
63+
cppNodeParameters.pChannels = (SilKit::Services::Flexray::FlexrayChannel)nodeParameters->pChannels;
64+
cppNodeParameters.pClusterDriftDamping = nodeParameters->pClusterDriftDamping;
65+
cppNodeParameters.pdAcceptedStartupRange = nodeParameters->pdAcceptedStartupRange;
66+
cppNodeParameters.pdListenTimeout = nodeParameters->pdListenTimeout;
67+
cppNodeParameters.pKeySlotId = nodeParameters->pKeySlotId;
68+
cppNodeParameters.pKeySlotOnlyEnabled = nodeParameters->pKeySlotOnlyEnabled;
69+
cppNodeParameters.pKeySlotUsedForStartup = nodeParameters->pKeySlotUsedForStartup;
70+
cppNodeParameters.pKeySlotUsedForSync = nodeParameters->pKeySlotUsedForSync;
71+
cppNodeParameters.pLatestTx = nodeParameters->pLatestTx;
72+
cppNodeParameters.pMacroInitialOffsetA = nodeParameters->pMacroInitialOffsetA;
73+
cppNodeParameters.pMacroInitialOffsetB = nodeParameters->pMacroInitialOffsetB;
74+
cppNodeParameters.pMicroInitialOffsetA = nodeParameters->pMicroInitialOffsetA;
75+
cppNodeParameters.pMicroInitialOffsetB = nodeParameters->pMicroInitialOffsetB;
76+
cppNodeParameters.pMicroPerCycle = nodeParameters->pMicroPerCycle;
77+
cppNodeParameters.pOffsetCorrectionOut = nodeParameters->pOffsetCorrectionOut;
78+
cppNodeParameters.pOffsetCorrectionStart = nodeParameters->pOffsetCorrectionStart;
79+
cppNodeParameters.pRateCorrectionOut = nodeParameters->pRateCorrectionOut;
80+
cppNodeParameters.pWakeupChannel = (SilKit::Services::Flexray::FlexrayChannel)nodeParameters->pWakeupChannel;
81+
cppNodeParameters.pWakeupPattern = nodeParameters->pWakeupPattern;
82+
cppNodeParameters.pdMicrotick = (SilKit::Services::Flexray::FlexrayClockPeriod)nodeParameters->pdMicrotick;
83+
cppNodeParameters.pSamplesPerMicrotick = nodeParameters->pSamplesPerMicrotick;
84+
}
85+
86+
if (inputVersion == 2)
87+
{
88+
cppNodeParameters.pTwoKeySlotMode = nodeParameters->pTwoKeySlotMode;
89+
cppNodeParameters.pSecondKeySlotId = nodeParameters->pSecondKeySlotId;
90+
}
8091
}
8192

8293
void assign(SilKit::Services::Flexray::FlexrayControllerConfig& cppConfig, const SilKit_FlexrayControllerConfig* config)

SilKit/source/config/ParticipantConfiguration_Full.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@
116116
"pWakeupPattern": 33,
117117
"pdAcceptedStartupRange": 212,
118118
"pdListenTimeout": 400162,
119-
"pdMicrotick": "25ns"
119+
"pdMicrotick": "25ns",
120+
"pSecondKeySlotId": 1337,
121+
"pTwoKeySlotMode": 1
120122
},
121123
"TxBufferConfigurations": [
122124
{

SilKit/source/config/ParticipantConfiguration_Full.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,14 @@ FlexrayControllers:
8989
pOffsetCorrectionStart: 3632
9090
pRateCorrectionOut: 81
9191
pSamplesPerMicrotick: 2
92+
pSecondKeySlotId: 1337
93+
pTwoKeySlotMode: 1
9294
pWakeupChannel: A
9395
pWakeupPattern: 33
9496
pdAcceptedStartupRange: 212
9597
pdListenTimeout: 400162
9698
pdMicrotick: 25ns
99+
97100
TxBufferConfigurations:
98101
- channels: A
99102
headerCrc: 0

SilKit/source/config/YamlParser.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ auto Deserialize(const std::string& input) -> T
4949
auto root = tree.crootref();
5050

5151
R reader{parser, root};
52-
T result;
52+
T result{};
5353
reader.Read(result);
5454
return result;
5555
}

SilKit/source/config/YamlReader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ void YamlReader::Read(SilKit::Services::Flexray::FlexrayNodeParameters& obj)
9797
ReadKeyValue(obj.pWakeupChannel, "pWakeupChannel");
9898
ReadKeyValue(obj.pdMicrotick, "pdMicrotick");
9999
ReadKeyValue(obj.pChannels, "pChannels");
100+
OptionalRead(obj.pSecondKeySlotId, "pSecondKeySlotId");
101+
OptionalRead(obj.pTwoKeySlotMode, "pTwoKeySlotMode");
100102
}
101103

102104
void YamlReader::Read(SilKit::Services::Flexray::FlexrayTxBufferConfig& obj)

0 commit comments

Comments
 (0)