Skip to content

Commit 20f28e7

Browse files
Replace unaligned_type::at_address with construction via unaligned_type and unaligned_type_ext
1 parent e179f8c commit 20f28e7

File tree

12 files changed

+43
-127
lines changed

12 files changed

+43
-127
lines changed

executables/unitTest/common/include/util/EcuIdList.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ class EcuIdList
5353

5454
uint16_t getSize() const
5555
{
56-
return (fBufferLength == 0U) ? 0U
57-
: static_cast<uint16_t>(etl::be_uint16_t::at_address(fpData));
56+
return (fBufferLength == 0U) ? 0U : static_cast<uint16_t>(etl::be_uint16_t(fpData));
5857
}
5958

6059
bool empty() const { return (getSize() == 0U); }

executables/unitTest/common/src/util/EcuIdList.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ EcuIdList::init(uint8_t* const pData, uint16_t const length, bool const initiali
5656
fBufferLength = length;
5757
if (!initializeWithData)
5858
{
59-
etl::be_uint16_t::at_address(fpData) = 0U; // set current length to 0
59+
etl::be_uint16_ext_t{fpData} = 0U; // set current length to 0
6060
}
6161
return ECU_LIST_OK;
6262
}
@@ -72,8 +72,8 @@ EcuId EcuIdList::pop_back()
7272
{
7373
uint16_t const size = getSize();
7474
estd_assert(size > 0U);
75-
uint16_t const newSize = static_cast<uint16_t>(size - 1U);
76-
etl::be_uint16_t::at_address(fpData) = newSize;
75+
uint16_t const newSize = static_cast<uint16_t>(size - 1U);
76+
etl::be_uint16_ext_t{fpData} = newSize;
7777
return fpData[static_cast<uint16_t>(2U + static_cast<uint16_t>(size - 1U))];
7878
}
7979

@@ -88,8 +88,8 @@ EcuIdList::ErrorCode EcuIdList::getNextEcuId(EcuId& ecuId)
8888

8989
--size;
9090

91-
uint16_t const newSize = size;
92-
etl::be_uint16_t::at_address(fpData) = newSize;
91+
uint16_t const newSize = size;
92+
etl::be_uint16_ext_t{fpData} = newSize;
9393
return ECU_LIST_OK;
9494
}
9595

@@ -105,7 +105,7 @@ EcuIdList::ErrorCode EcuIdList::push_back(EcuId const ecuId)
105105
return ECU_LIST_ERROR;
106106
}
107107
++size;
108-
etl::be_uint16_t::at_address(fpData) = size;
108+
etl::be_uint16_ext_t{fpData} = size;
109109
fpData[static_cast<uint16_t>(1U + size)] = ecuId;
110110
return ECU_LIST_OK;
111111
}
@@ -140,7 +140,7 @@ bool EcuIdList::contains(EcuId const ecuId) const
140140
{
141141
return false;
142142
}
143-
uint16_t const size = etl::be_uint16_t::at_address(fpData);
143+
uint16_t const size = etl::be_uint16_t{fpData};
144144
for (uint16_t i = 0U; i < size; ++i)
145145
{
146146
if (fpData[static_cast<uint16_t>(2U + i)] == ecuId)
@@ -157,7 +157,7 @@ void EcuIdList::remove(EcuId const ecuId)
157157
{
158158
return;
159159
}
160-
uint16_t size = etl::be_uint16_t::at_address(fpData);
160+
uint16_t size = etl::be_uint16_t{fpData};
161161
bool found = false;
162162
uint8_t idx = 0U;
163163
for (uint16_t i = 0U; i < size; ++i)
@@ -173,15 +173,15 @@ void EcuIdList::remove(EcuId const ecuId)
173173
{
174174
fpData[static_cast<uint8_t>(2U + idx)] = fpData[static_cast<uint16_t>(2U + (size - 1U))];
175175
--size;
176-
etl::be_uint16_t::at_address(fpData) = size;
176+
etl::be_uint16_ext_t{fpData} = size;
177177
}
178178
}
179179

180180
EcuIdList::ErrorCode EcuIdList::resetSize(uint16_t const size)
181181
{
182182
if ((fBufferLength - 2U) >= size)
183183
{
184-
etl::be_uint16_t::at_address(fpData) = size;
184+
etl::be_uint16_ext_t{fpData} = size;
185185
return ECU_LIST_OK;
186186
}
187187
return ECU_LIST_ERROR;

libs/3rdparty/etl/include/etl/unaligned_type.h

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -574,86 +574,6 @@ namespace etl
574574

575575
return value;
576576
}
577-
578-
//*******************************************
579-
/// at_address
580-
///\brief Helps to reinterprete memory as unaligned_type. Overload for write access.
581-
///\param address Pointer to memory to be reinterpreted.
582-
///\return Reference to unaligned_type object at location specified by address
583-
//*******************************************
584-
static unaligned_type<T, Endian_>& at_address(void* address)
585-
{
586-
return *reinterpret_cast<unaligned_type<T, Endian_>*>(address);
587-
}
588-
589-
//*******************************************
590-
/// at_address
591-
///\brief Helps to reinterprete memory as unaligned_type. Overload for read only access to const memory.
592-
///\param address Pointer to memory to be reinterpreted.
593-
///\return Reference to unaligned_type object at location specified by address
594-
//*******************************************
595-
static const unaligned_type<T, Endian_>& at_address(const void* address)
596-
{
597-
return *reinterpret_cast<const unaligned_type<T, Endian_>*>(address);
598-
}
599-
600-
//*******************************************
601-
/// at_address
602-
///\brief Helps to reinterprete memory as unaligned_type. Overload for write access.
603-
///\param address Pointer to memory to be reinterpreted.
604-
///\param buffer_size Size in bytes for run time size check
605-
///\return Reference to unaligned_type object at location specified by address
606-
//*******************************************
607-
static unaligned_type<T, Endian_>& at_address(void* address, size_t buffer_size)
608-
{
609-
ETL_ASSERT(sizeof(T) <= buffer_size, ETL_ERROR(etl::unaligned_type_buffer_size));
610-
611-
return *reinterpret_cast<unaligned_type<T, Endian_>*>(address);
612-
}
613-
614-
//*******************************************
615-
/// at_address
616-
///\brief Helps to reinterprete memory as unaligned_type. Overload for read only access to const memory.
617-
///\param address Pointer to memory to be reinterpreted.
618-
///\param buffer_size Size in bytes for runtime size check
619-
///\return Reference to unaligned_type object at location specified by address
620-
//*******************************************
621-
static const unaligned_type<T, Endian_>& at_address(const void* address, size_t buffer_size)
622-
{
623-
ETL_ASSERT(sizeof(T) <= buffer_size, ETL_ERROR(etl::unaligned_type_buffer_size));
624-
625-
return *reinterpret_cast<const unaligned_type<T, Endian_>*>(address);
626-
}
627-
628-
//*******************************************
629-
/// at_address
630-
///\brief Helps to reinterprete memory as unaligned_type. Overload for write access.
631-
///\tparam BufferSize Size in bytes for compile time size check
632-
///\param address Pointer to memory to be reinterpreted.
633-
///\return Reference to unaligned_type object at location specified by address
634-
//*******************************************
635-
template <size_t BufferSize>
636-
static unaligned_type<T, Endian_>& at_address(void* address)
637-
{
638-
ETL_STATIC_ASSERT(sizeof(T) <= BufferSize, "Buffer size to small for type");
639-
640-
return *reinterpret_cast<unaligned_type<T, Endian_>*>(address);
641-
}
642-
643-
//*******************************************
644-
/// at_address
645-
///\brief Helps to reinterprete memory as unaligned_type. Overload for read only access to const memory.
646-
///\tparam BufferSize Size in bytes for compile time size check
647-
///\param address Pointer to memory to be reinterpreted.
648-
///\return Reference to unaligned_type object at location specified by address
649-
//*******************************************
650-
template <size_t BufferSize>
651-
static const unaligned_type<T, Endian_>& at_address(const void* address)
652-
{
653-
ETL_STATIC_ASSERT(sizeof(T) <= BufferSize, "Buffer size to small for type");
654-
655-
return *reinterpret_cast<const unaligned_type<T, Endian_>*>(address);
656-
}
657577
}; ETL_END_PACKED
658578

659579
template <typename T, int Endian_>

libs/bsw/docan/include/docan/datalink/DoCanFrameCodec.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@ CodecResult DoCanFrameCodec<DataLinkLayer>::decodeFirstFrame(
275275
if (checkFrameSize(payload, 3U, _config._firstFrameSize))
276276
{
277277
size_t const offset = _config._offset;
278-
messageSize
279-
= static_cast<MessageSizeType>(etl::be_uint16_t::at_address(&payload[offset]) & 0xFFFU);
278+
messageSize = static_cast<MessageSizeType>(etl::be_uint16_t(&payload[offset]) & 0xFFFU);
280279
uint8_t dataStart = 2U;
281280
consecutiveFrameDataSize = static_cast<FrameSizeType>(payload.size())
282281
- (static_cast<FrameSizeType>(offset) + 1U);
@@ -287,7 +286,7 @@ CodecResult DoCanFrameCodec<DataLinkLayer>::decodeFirstFrame(
287286
return CodecResult::INVALID_FRAME_SIZE;
288287
}
289288
// Escape sequence, aka message size > 4095 up to uint32_t
290-
uint32_t const escapedMessageSize = etl::be_uint32_t::at_address(&payload[offset + 2U]);
289+
uint32_t const escapedMessageSize = etl::be_uint32_t(&payload[offset + 2U]);
291290

292291
if ((escapedMessageSize <= ESCAPED_SEQ_MESSAGE_SIZE)
293292
|| (escapedMessageSize > ::etl::numeric_limits<MessageSizeType>::max()))
@@ -449,13 +448,13 @@ CodecResult DoCanFrameCodec<DataLinkLayer>::encodeDataFrame(
449448

450449
if (pendingMessageSize <= ESCAPED_SEQ_MESSAGE_SIZE)
451450
{
452-
etl::be_uint16_t::at_address(&payload[offset]) = pendingMessageSize & 0xFFFU;
451+
etl::be_uint16_ext_t{&payload[offset]} = pendingMessageSize & 0xFFFU;
453452
}
454453
else
455454
{
456-
payload[offset] = 0U;
457-
payload[offset + 1U] = 0U;
458-
etl::be_uint32_t::at_address(&payload[offset + 2U]) = pendingMessageSize;
455+
payload[offset] = 0U;
456+
payload[offset + 1U] = 0U;
457+
etl::be_uint32_ext_t{&payload[offset + 2U]} = pendingMessageSize;
459458

460459
destOffset += 4U;
461460
consumedDataSize -= 4U;

libs/bsw/io/examples/MemoryQueueExample.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ bool forwardCanFrame(::io::IWriter& writer)
5959
return false;
6060
}
6161
// The big endian 32bit id comes first in the serialization.
62-
auto& id = etl::be_uint32_t::at_address(data.data());
63-
data.advance(sizeof(id));
62+
etl::be_uint32_ext_t id{data.data()};
63+
data.advance(id.size());
6464
// We pass the slice data to the frame so that readCanFrame can read the data directly from
6565
// the hardware to the allocated memory.
6666
CanFrame frame;
@@ -121,7 +121,7 @@ bool forwardCanFrame(::io::IWriter& writer)
121121
return false;
122122
}
123123
// The big endian 32bit id comes first in the serialization.
124-
etl::be_uint32_t::at_address(data.data()) = rxFrame.id;
124+
etl::be_uint32_ext_t{data.data()} = rxFrame.id;
125125
data.advance(sizeof(etl::be_uint32_t));
126126
// Copy payload to allocated data.
127127
::etl::copy(rxFrame.data, data);
@@ -149,7 +149,7 @@ bool receiveCanFrame(CanFrame& frame, ::io::IReader& reader)
149149
return false;
150150
}
151151
// Copy data to frame. We expect a big endian 32bit id followed by the actual data.
152-
frame.id = etl::be_uint32_t::at_address(data.data());
152+
frame.id = etl::be_uint32_t(data.data());
153153
data.advance(sizeof(etl::be_uint32_t));
154154
::etl::copy(data, frame.data);
155155
frame.data = frame.data.first(data.size());
@@ -263,7 +263,7 @@ TEST(MemoryQueueExample, non_virtual_interface)
263263
{
264264
auto d = srcWriter.allocate(4);
265265
ASSERT_EQ(4, d.size());
266-
::etl::be_uint32_t::at_address(d.data()) = 0x1234;
266+
::etl::be_uint32_ext_t{d.data()} = 0x1234;
267267
srcWriter.commit();
268268
}
269269

@@ -272,7 +272,7 @@ TEST(MemoryQueueExample, non_virtual_interface)
272272
{
273273
auto d = dstReader.peek();
274274
ASSERT_EQ(4, d.size());
275-
ASSERT_EQ(0x1234, ::etl::be_uint32_t::at_address(d.data()));
275+
ASSERT_EQ(0x1234, ::etl::be_uint32_t(d.data()));
276276
}
277277
// EXAMPLE_END WriterReader2
278278
}
@@ -327,7 +327,7 @@ TEST(MemoryQueueExample, virtual_interface)
327327
{
328328
auto d = srcWriter.allocate(4);
329329
ASSERT_EQ(4, d.size());
330-
::etl::be_uint32_t::at_address(d.data()) = 0x1234;
330+
::etl::be_uint32_ext_t{d.data()} = 0x1234;
331331
srcWriter.commit();
332332
}
333333

@@ -336,7 +336,7 @@ TEST(MemoryQueueExample, virtual_interface)
336336
{
337337
auto d = dstReader.peek();
338338
ASSERT_EQ(4, d.size());
339-
ASSERT_EQ(0x1234, ::etl::be_uint32_t::at_address(d.data()));
339+
ASSERT_EQ(0x1234, ::etl::be_uint32_t(d.data()));
340340
}
341341
// EXAMPLE_END IWriterIReader2
342342
}

libs/bsw/io/include/io/MemoryQueue.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ void MemoryQueue<CAPACITY, MAX_ELEMENT_SIZE, SIZE_TYPE>::Writer::commit()
264264
size_t writeIndex = _txData.sent.load();
265265
size_t const index = writeIndex % CAPACITY;
266266
SIZE_TYPE const size = static_cast<SIZE_TYPE>(_txData.allocated);
267-
::etl::unaligned_type<SIZE_TYPE, etl::endian::big>::at_address(&_txData.data[index])
268-
= static_cast<SIZE_TYPE>(size);
267+
::etl::unaligned_type_ext<SIZE_TYPE, etl::endian::big>{&_txData.data[index]}
268+
= static_cast<SIZE_TYPE>(size);
269269

270270
writeIndex = advanceIndex(writeIndex, size);
271271
_txData.allocated = 0U;
@@ -325,7 +325,7 @@ inline ::etl::span<uint8_t> MemoryQueue<CAPACITY, MAX_ELEMENT_SIZE, SIZE_TYPE>::
325325
}
326326
size_t const index = _rxData.received.load() % CAPACITY;
327327
SIZE_TYPE const size
328-
= ::etl::unaligned_type<SIZE_TYPE, ::etl::endian::big>::at_address(&_txData.data[index]);
328+
= ::etl::unaligned_type<SIZE_TYPE, ::etl::endian::big>(&_txData.data[index]);
329329
return ::etl::span<uint8_t>(&_txData.data[index + sizeof(SIZE_TYPE)], size);
330330
}
331331

@@ -339,7 +339,7 @@ void MemoryQueue<CAPACITY, MAX_ELEMENT_SIZE, SIZE_TYPE>::Reader::release() const
339339
size_t readIndex = _rxData.received.load();
340340
size_t const index = readIndex % CAPACITY;
341341
SIZE_TYPE const size
342-
= ::etl::unaligned_type<SIZE_TYPE, ::etl::endian::big>::at_address(&_txData.data[index]);
342+
= ::etl::unaligned_type<SIZE_TYPE, ::etl::endian::big>(&_txData.data[index]);
343343
readIndex = advanceIndex(readIndex, size);
344344
// Store readIndex last to ensure data consistency.
345345
_rxData.received.store(readIndex);

libs/bsw/io/test/src/io/MemoryQueueTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ allocate(typename Queue::Writer& s, uint8_t const bus, uint32_t const id, size_t
7373
::etl::span<uint8_t> memory = s.allocate(sizeof(uint8_t) + sizeof(uint32_t) + size);
7474
if (memory.size() >= 5)
7575
{
76-
memory[0] = bus;
77-
etl::be_uint32_t::at_address(&memory[1]) = id;
76+
memory[0] = bus;
77+
etl::be_uint32_ext_t{&memory[1]} = id;
7878
memory.advance(sizeof(bus) + sizeof(id));
7979
}
8080
return memory;
@@ -87,7 +87,7 @@ Pdu poll(typename Queue::Reader& r)
8787
if (s.size() >= 5)
8888
{
8989
uint8_t const bus = s[0];
90-
uint32_t const id = ::etl::be_uint32_t::at_address(&s[1]);
90+
uint32_t const id = ::etl::be_uint32_t(&s[1]);
9191
return Pdu(bus, id, s.subspan(sizeof(bus) + sizeof(id)));
9292
}
9393
return Pdu(0xFFU, 0xFFFFFFFFU, {});

libs/bsw/uds/src/uds/jobs/ReadIdentifierFromNvStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void ReadIdentifierFromNvStorage::onLengthNvReadJobFinished(
131131
return;
132132
}
133133

134-
_length = ::etl::be_uint32_t::at_address(_lengthBuffer);
134+
_length = ::etl::be_uint32_t(_lengthBuffer);
135135

136136
if (_posResponse->getMaximumLength() < _length)
137137
{

libs/bsw/uds/src/uds/jobs/WriteIdentifierToNvStorage.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ DiagReturnCode::Type WriteIdentifierToNvStorage::process(
122122

123123
if (_variableLength)
124124
{
125-
_length = requestLength;
126-
_pRequestData = request;
127-
::etl::be_uint32_t::at_address(_lengthBuff) = requestLength;
125+
_length = requestLength;
126+
_pRequestData = request;
127+
::etl::be_uint32_ext_t{_lengthBuff} = requestLength;
128128
if (!_ieepromHelper.write(
129129
_nvLengthItem, &_lengthBuff[0U], sizeof(_lengthBuff), _nvLengthWriteJobfinished))
130130
{

libs/bsw/uds/src/uds/services/communicationcontrol/CommunicationControl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ DiagReturnCode::Type CommunicationControl::process(
231231
{
232232
if (static_cast<uint8_t>(NORMAL_COMMUNICATION_MESSAGES) == communicationTypeLo)
233233
{
234-
rcvNode = ::etl::be_uint16_t::at_address(&request[2]);
234+
rcvNode = ::etl::be_uint16_t(&request[2]);
235235
if (0U == fSubNodeIdDisabledTx)
236236
{
237237
if (notifySubListeners(
@@ -267,7 +267,7 @@ DiagReturnCode::Type CommunicationControl::process(
267267
{
268268
if (static_cast<uint8_t>(NORMAL_COMMUNICATION_MESSAGES) == communicationTypeLo)
269269
{
270-
rcvNode = ::etl::be_uint16_t::at_address(&request[2]);
270+
rcvNode = ::etl::be_uint16_t(&request[2]);
271271
if (rcvNode == fSubNodeIdDisabledTx)
272272
{
273273
if (notifySubListeners(

0 commit comments

Comments
 (0)