Skip to content

Commit c8d213a

Browse files
oyvindronningstadnordicjm
authored andcommitted
zcbor: Copy source and header files
from zcbor 0.8.1 Signed-off-by: Øyvind Rønningstad <[email protected]>
1 parent f09e205 commit c8d213a

File tree

8 files changed

+43
-27
lines changed

8 files changed

+43
-27
lines changed

boot/zcbor/include/zcbor_common.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file has been copied from the zcbor library.
3-
* Commit zcbor 0.8.0
3+
* Commit zcbor 0.8.1
44
*/
55

66
/*
@@ -22,6 +22,23 @@
2222
extern "C" {
2323
#endif
2424

25+
#define ZCBOR_STRINGIFY_PRE(x) #x
26+
#define ZCBOR_STRINGIFY(s) ZCBOR_STRINGIFY_PRE(s)
27+
28+
#define ZCBOR_VERSION_MAJOR 0
29+
#define ZCBOR_VERSION_MINOR 8
30+
#define ZCBOR_VERSION_BUGFIX 1
31+
32+
/** The version string with dots and not prefix. */
33+
#define ZCBOR_VERSION_STR ZCBOR_STRINGIFY(ZCBOR_VERSION_MAJOR) \
34+
"." ZCBOR_STRINGIFY(ZCBOR_VERSION_MINOR) \
35+
"." ZCBOR_STRINGIFY(ZCBOR_VERSION_BUGFIX)
36+
37+
/** Monotonically increasing integer representing the version. */
38+
#define ZCBOR_VERSION ((ZCBOR_VERSION_MAJOR << 24) \
39+
+ (ZCBOR_VERSION_MINOR << 16) \
40+
+ (ZCBOR_VERSION_BUGFIX << 8))
41+
2542
/** Convenience type that allows pointing to strings directly inside the payload
2643
* without the need to copy out.
2744
*/
@@ -488,6 +505,8 @@ static inline size_t zcbor_flags_to_states(size_t num_flags)
488505
#define ZCBOR_FLAG_STATES(n_flags) 0
489506
#endif
490507

508+
size_t strnlen(const char *, size_t);
509+
491510
#ifdef __cplusplus
492511
}
493512
#endif

boot/zcbor/include/zcbor_decode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file has been copied from the zcbor library.
3-
* Commit zcbor 0.8.0
3+
* Commit zcbor 0.8.1
44
*/
55

66
/*

boot/zcbor/include/zcbor_encode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file has been copied from the zcbor library.
3-
* Commit zcbor 0.8.0
3+
* Commit zcbor 0.8.1
44
*/
55

66
/*

boot/zcbor/include/zcbor_print.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file has been copied from the zcbor library.
3-
* Commit zcbor 0.8.0
3+
* Commit zcbor 0.8.1
44
*/
55

66
/*
@@ -93,23 +93,27 @@ static void zcbor_print_compare_lines(const uint8_t *str1, const uint8_t *str2,
9393
__attribute__((used))
9494
static void zcbor_print_compare_strings(const uint8_t *str1, const uint8_t *str2, size_t size)
9595
{
96-
for (size_t i = 0; i <= size / 16; i++) {
97-
zcbor_do_print("line %zu (char %zu)\r\n", i, i*16);
98-
zcbor_print_compare_lines(&str1[i*16], &str2[i*16],
99-
MIN(16, (size - i*16)));
96+
const size_t col_width = 16;
97+
98+
for (size_t i = 0; i <= size / col_width; i++) {
99+
zcbor_do_print("line %zu (char %zu)\r\n", i, i*col_width);
100+
zcbor_print_compare_lines(&str1[i*col_width], &str2[i*col_width],
101+
MIN(col_width, (size - i*col_width)));
100102
}
101103
zcbor_do_print("\r\n");
102104
}
103105

104106
__attribute__((used))
105107
static void zcbor_print_compare_strings_diff(const uint8_t *str1, const uint8_t *str2, size_t size)
106108
{
109+
const size_t col_width = 16;
107110
bool printed = false;
108-
for (size_t i = 0; i <= size / 16; i++) {
109-
if (memcmp(&str1[i*16], &str2[i*16], MIN(16, (size - i*16))) != 0) {
110-
zcbor_do_print("line %zu (char %zu)\r\n", i, i*16);
111-
zcbor_print_compare_lines(&str1[i*16], &str2[i*16],
112-
MIN(16, (size - i*16)));
111+
112+
for (size_t i = 0; i <= size / col_width; i++) {
113+
if (memcmp(&str1[i*col_width], &str2[i*col_width], MIN(col_width, (size - i*col_width))) != 0) {
114+
zcbor_do_print("line %zu (char %zu)\r\n", i, i*col_width);
115+
zcbor_print_compare_lines(&str1[i*col_width], &str2[i*col_width],
116+
MIN(col_width, (size - i*col_width)));
113117
printed = true;
114118
}
115119
}

boot/zcbor/include/zcbor_tags.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file has been copied from the zcbor library.
3-
* Commit zcbor 0.8.0
3+
* Commit zcbor 0.8.1
44
*/
55

66
/*

boot/zcbor/src/zcbor_common.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file has been copied from the zcbor library.
3-
* Commit zcbor 0.8.0
3+
* Commit zcbor 0.8.1
44
*/
55

66
/*
@@ -355,30 +355,23 @@ float zcbor_float16_to_32(uint16_t input)
355355
: (expo + (F32_BIAS - F16_BIAS));
356356
uint32_t value32 = (sign << F32_SIGN_OFFS) | (new_expo << F32_EXPO_OFFS)
357357
| (mantissa << (F32_EXPO_OFFS - F16_EXPO_OFFS));
358-
float result;
359-
360-
memcpy(&result, &value32, sizeof(result));
361-
return result;
358+
return *(float *)&value32;
362359
}
363360
}
364361

365362

366363
uint16_t zcbor_float32_to_16(float input)
367364
{
368-
uint32_t value32;
369-
370-
memcpy(&value32, &input, sizeof(value32));
365+
uint32_t value32 = *(uint32_t *)&input;
371366

372367
uint32_t sign = value32 >> F32_SIGN_OFFS;
373368
uint32_t expo = (value32 >> F32_EXPO_OFFS) & F32_EXPO_MSK;
374369
uint32_t mantissa = value32 & F32_MANTISSA_MSK;
375370

376371
uint16_t value16 = (uint16_t)(sign << F16_SIGN_OFFS);
377372

378-
uint32_t abs_value32 = value32 & ~(1 << F32_SIGN_OFFS);
379373
float abs_input;
380-
381-
memcpy(&abs_input, &abs_value32, sizeof(abs_input));
374+
*(uint32_t *)&abs_input = value32 & ~(1 << F32_SIGN_OFFS);
382375

383376
if (abs_input <= (F16_MIN / 2)) {
384377
/* 0 or too small for float16. Round down to 0. value16 is already correct. */

boot/zcbor/src/zcbor_decode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file has been copied from the zcbor library.
3-
* Commit zcbor 0.8.0
3+
* Commit zcbor 0.8.1
44
*/
55

66
/*

boot/zcbor/src/zcbor_encode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* This file has been copied from the zcbor library.
3-
* Commit zcbor 0.8.0
3+
* Commit zcbor 0.8.1
44
*/
55

66
/*

0 commit comments

Comments
 (0)