1 // Copyright 2020 The Pigweed Authors
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
7 // https://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
18 #include "pw_bytes/array.h"
19 #include "pw_log/log.h"
20 #include "pw_preprocessor/compiler.h"
21 #include "pw_status/status.h"
26 constexpr auto kArray = pw::bytes::Array<
27 0x0a, 0x14, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00,
28 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x96, 0x00,
29 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x12, 0x08,
30 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01>();
33 PW_NO_INLINE pw::Status Read(size_t offset,
35 std::span<const std::byte>* out) {
36 if (offset + size >= std::size(kArray)) {
37 return pw::Status::OutOfRange();
40 *out = std::span<const std::byte>(std::data(kArray) + offset, size);
41 return pw::OkStatus();
46 size_t volatile* unoptimizable;
49 std::span<const std::byte> data;
50 pw::Status status = Read(*unoptimizable, *unoptimizable, &data);
55 PW_LOG_INFO("Read %u bytes", static_cast<unsigned>(data.size()));