Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
write.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
20void write_u16_be(uint8_t *ptr, size_t offset, uint16_t value)
21{
22 ptr[offset + 0] = (uint8_t) (value >> 8);
23 ptr[offset + 1] = (uint8_t) (value >> 0);
24}
25
26void write_u32_be(uint8_t *ptr, size_t offset, uint32_t value)
27{
28 ptr[offset + 0] = (uint8_t) (value >> 24);
29 ptr[offset + 1] = (uint8_t) (value >> 16);
30 ptr[offset + 2] = (uint8_t) (value >> 8);
31 ptr[offset + 3] = (uint8_t) (value >> 0);
32}
33
34void write_u64_be(uint8_t *ptr, size_t offset, uint64_t value)
35{
36 ptr[offset + 0] = (uint8_t) (value >> 56);
37 ptr[offset + 1] = (uint8_t) (value >> 48);
38 ptr[offset + 2] = (uint8_t) (value >> 40);
39 ptr[offset + 3] = (uint8_t) (value >> 32);
40 ptr[offset + 4] = (uint8_t) (value >> 24);
41 ptr[offset + 5] = (uint8_t) (value >> 16);
42 ptr[offset + 6] = (uint8_t) (value >> 8);
43 ptr[offset + 7] = (uint8_t) (value >> 0);
44}
45
46void write_u16_le(uint8_t *ptr, size_t offset, uint16_t value)
47{
48 ptr[offset + 0] = (uint8_t) (value >> 0);
49 ptr[offset + 1] = (uint8_t) (value >> 8);
50}
51
52void write_u32_le(uint8_t *ptr, size_t offset, uint32_t value)
53{
54 ptr[offset + 0] = (uint8_t) (value >> 0);
55 ptr[offset + 1] = (uint8_t) (value >> 8);
56 ptr[offset + 2] = (uint8_t) (value >> 16);
57 ptr[offset + 3] = (uint8_t) (value >> 24);
58}
59
60void write_u64_le(uint8_t *ptr, size_t offset, uint64_t value)
61{
62 ptr[offset + 0] = (uint8_t) (value >> 0);
63 ptr[offset + 1] = (uint8_t) (value >> 8);
64 ptr[offset + 2] = (uint8_t) (value >> 16);
65 ptr[offset + 3] = (uint8_t) (value >> 24);
66 ptr[offset + 4] = (uint8_t) (value >> 32);
67 ptr[offset + 5] = (uint8_t) (value >> 40);
68 ptr[offset + 6] = (uint8_t) (value >> 48);
69 ptr[offset + 7] = (uint8_t) (value >> 56);
70}
unsigned short uint16_t
Definition usbd_conf.h:54
unsigned char uint8_t
Definition usbd_conf.h:53
void write_u16_le(uint8_t *ptr, size_t offset, uint16_t value)
Definition write.c:46
void write_u32_be(uint8_t *ptr, size_t offset, uint32_t value)
Definition write.c:26
void write_u16_be(uint8_t *ptr, size_t offset, uint16_t value)
Definition write.c:20
void write_u64_be(uint8_t *ptr, size_t offset, uint64_t value)
Definition write.c:34
void write_u64_le(uint8_t *ptr, size_t offset, uint64_t value)
Definition write.c:60
void write_u32_le(uint8_t *ptr, size_t offset, uint32_t value)
Definition write.c:52