1111
1212#if MEMFAULT_COMPACT_LOG_ENABLE
1313
14- #include "memfault/core/compiler .h"
15- #include "memfault/core/debug_log .h"
16- #include "memfault/core/compact_log_helpers .h"
17- #include "memfault/core/compact_log_serializer .h"
18- #include "memfault/util/cbor.h"
14+ #include "memfault/core/compact_log_helpers .h"
15+ #include "memfault/core/compact_log_serializer .h"
16+ #include "memfault/core/compiler .h"
17+ #include "memfault/core/debug_log .h"
18+ #include "memfault/util/cbor.h"
1919
2020//! Compact logs are placed in a linker section named "log_fmt". This is a symbol exposed by the
2121//! linker which points to the start of the section
@@ -24,16 +24,15 @@ extern uint32_t __start_log_fmt;
2424//! Note: We don't read this in the firmware but it is used during the decode
2525//! process to sanity check the section is being laid out as we would expect.
2626MEMFAULT_PUT_IN_SECTION (".log_fmt_hdr" )
27- MEMFAULT_NO_ALLOC
28- const sMemfaultLogFmtElfSectionHeader g_memfault_log_fmt_elf_section_hdr = {
27+ MEMFAULT_NO_ALLOC const sMemfaultLogFmtElfSectionHeader g_memfault_log_fmt_elf_section_hdr = {
2928 .magic = 0x66474f4c , /* LOGf */
3029 .version = 1 ,
3130};
3231
3332bool memfault_vlog_compact_serialize (sMemfaultCborEncoder * encoder , uint32_t log_id ,
3433 uint32_t compressed_fmt , va_list args ) {
3534 const uint32_t bits_per_arg = 2 ;
36- const uint32_t bits_per_arg_mask = (1 << bits_per_arg ) - 1 ;
35+ const uint32_t bits_per_arg_mask = (1 << bits_per_arg ) - 1 ;
3736
3837 const size_t num_args = (31UL - MEMFAULT_CLZ (compressed_fmt )) / bits_per_arg ;
3938
@@ -54,11 +53,10 @@ bool memfault_vlog_compact_serialize(sMemfaultCborEncoder *encoder, uint32_t log
5453 // the promotion type of a given va_arg is encoded within two bits of the
5554 // compressed_fmt field.
5655 const uint32_t type =
57- (compressed_fmt >> ((num_args - i - 1 ) * bits_per_arg )) & bits_per_arg_mask ;
56+ (compressed_fmt >> ((num_args - i - 1 ) * bits_per_arg )) & bits_per_arg_mask ;
5857
5958 bool success = false;
6059 switch (type ) {
61-
6260 case MEMFAULT_LOG_ARG_PROMOTED_TO_INT32 : {
6361 int32_t val = va_arg (args , int32_t );
6462 success = memfault_cbor_encode_signed_integer (encoder , val );
@@ -70,7 +68,7 @@ bool memfault_vlog_compact_serialize(sMemfaultCborEncoder *encoder, uint32_t log
7068 // by packing the cbor encoded int in an array.
7169 uint64_t val = va_arg (args , uint64_t );
7270 success = memfault_cbor_encode_array_begin (encoder , 1 ) &&
73- memfault_cbor_encode_long_signed_integer (encoder , (int64_t )val );
71+ memfault_cbor_encode_long_signed_integer (encoder , (int64_t )val );
7472 break ;
7573 }
7674
@@ -91,7 +89,8 @@ bool memfault_vlog_compact_serialize(sMemfaultCborEncoder *encoder, uint32_t log
9189 //
9290 // But parsing as a double is more portable and get's optimized away by compilers
9391 // like GCC anyway: https://godbolt.org/z/mVAS7D
94- MEMFAULT_STATIC_ASSERT (sizeof (uint64_t ) == sizeof (double ), "double does not fit in uint64_t" );
92+ MEMFAULT_STATIC_ASSERT (sizeof (uint64_t ) == sizeof (double ),
93+ "double does not fit in uint64_t" );
9594
9695 // Note: We use memcpy to properly type-pun / avoid strict-aliasing violation:
9796 // https://mflt.io/strict-aliasing-type-punning
@@ -103,14 +102,13 @@ bool memfault_vlog_compact_serialize(sMemfaultCborEncoder *encoder, uint32_t log
103102 }
104103
105104 case MEMFAULT_LOG_ARG_PROMOTED_TO_STR : {
106- const char * str = va_arg (args , const char * );
105+ const char * str = va_arg (args , const char * );
107106 success = memfault_cbor_encode_string (encoder , str != NULL ? str : "(null)" );
108107 break ;
109108 }
110109
111110 default :
112111 break ;
113-
114112 }
115113
116114 if (!success ) {
@@ -122,7 +120,7 @@ bool memfault_vlog_compact_serialize(sMemfaultCborEncoder *encoder, uint32_t log
122120}
123121
124122bool memfault_log_compact_serialize (sMemfaultCborEncoder * encoder , uint32_t log_id ,
125- uint32_t compressed_fmt , ...) {
123+ uint32_t compressed_fmt , ...) {
126124 va_list args ;
127125 va_start (args , compressed_fmt );
128126 const bool success = memfault_vlog_compact_serialize (encoder , log_id , compressed_fmt , args );
0 commit comments