Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
read.c
Go to the documentation of this file.
1/*****************************************************************************
2 * (c) 2020 Ledger SAS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#include <stdint.h> // uint*_t
18#include <stddef.h> // size_t
19
20uint16_t read_u16_be(const uint8_t *ptr, size_t offset)
21{
22 return (uint16_t) ptr[offset + 0] << 8 | //
23 (uint16_t) ptr[offset + 1] << 0;
24}
25
26uint32_t read_u32_be(const uint8_t *ptr, size_t offset)
27{
28 return (uint32_t) ptr[offset + 0] << 24 | //
29 (uint32_t) ptr[offset + 1] << 16 | //
30 (uint32_t) ptr[offset + 2] << 8 | //
31 (uint32_t) ptr[offset + 3] << 0;
32}
33
34uint64_t read_u64_be(const uint8_t *ptr, size_t offset)
35{
36 return (uint64_t) ptr[offset + 0] << 56 | //
37 (uint64_t) ptr[offset + 1] << 48 | //
38 (uint64_t) ptr[offset + 2] << 40 | //
39 (uint64_t) ptr[offset + 3] << 32 | //
40 (uint64_t) ptr[offset + 4] << 24 | //
41 (uint64_t) ptr[offset + 5] << 16 | //
42 (uint64_t) ptr[offset + 6] << 8 | //
43 (uint64_t) ptr[offset + 7] << 0;
44}
45
46uint16_t read_u16_le(const uint8_t *ptr, size_t offset)
47{
48 return (uint16_t) ptr[offset + 0] << 0 | //
49 (uint16_t) ptr[offset + 1] << 8;
50}
51
52uint32_t read_u32_le(const uint8_t *ptr, size_t offset)
53{
54 return (uint32_t) ptr[offset + 0] << 0 | //
55 (uint32_t) ptr[offset + 1] << 8 | //
56 (uint32_t) ptr[offset + 2] << 16 | //
57 (uint32_t) ptr[offset + 3] << 24;
58}
59
60uint64_t read_u64_le(const uint8_t *ptr, size_t offset)
61{
62 return (uint64_t) ptr[offset + 0] << 0 | //
63 (uint64_t) ptr[offset + 1] << 8 | //
64 (uint64_t) ptr[offset + 2] << 16 | //
65 (uint64_t) ptr[offset + 3] << 24 | //
66 (uint64_t) ptr[offset + 4] << 32 | //
67 (uint64_t) ptr[offset + 5] << 40 | //
68 (uint64_t) ptr[offset + 6] << 48 | //
69 (uint64_t) ptr[offset + 7] << 56;
70}
uint32_t read_u32_le(const uint8_t *ptr, size_t offset)
Definition read.c:52
uint64_t read_u64_le(const uint8_t *ptr, size_t offset)
Definition read.c:60
uint16_t read_u16_le(const uint8_t *ptr, size_t offset)
Definition read.c:46
uint32_t read_u32_be(const uint8_t *ptr, size_t offset)
Definition read.c:26
uint64_t read_u64_be(const uint8_t *ptr, size_t offset)
Definition read.c:34
uint16_t read_u16_be(const uint8_t *ptr, size_t offset)
Definition read.c:20
unsigned short uint16_t
Definition usbd_conf.h:54
unsigned char uint8_t
Definition usbd_conf.h:53