Skip to content

Commit 46f94c9

Browse files
authored
Compile without (u)int64 and with 16-bit (u)int, solving #607 and #608 (#609)
* Allow complete (u)int64_t disable (#607). Allow compilation with 16 bit integer width (#608). * Another trice64 occurrence made conditional. #607 * Explicit casts and library include outside extern C (#610). * Make TRICE_CYCLE a native uint_fast32_t, following hint by @rokath in #609
1 parent 8c0394b commit 46f94c9

18 files changed

+409
-388
lines changed

src/cobsDecode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
//! @return Number of bytes successfully decoded.
1111
//! @note Stops decoding if delimiter byte is found. Code taken from Wikipedia and slightly modified.
1212
size_t COBSDecode(void* __restrict out, const void* __restrict in, size_t length) {
13-
uint8_t* data = out;
14-
const uint8_t* buffer = in;
13+
uint8_t* data = (uint8_t*) out;
14+
const uint8_t* buffer = (const uint8_t*) in;
1515
const uint8_t* byte = buffer; // Encoded input byte pointer
1616
uint8_t* decode = data; // Decoded output byte pointer
1717

src/tcobsv1Encode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@
7878
//! \param output destination
7979
//! \retval length of encoded data in output
8080
int TCOBSEncode(void* __restrict output, const void* __restrict input, size_t length) {
81-
uint8_t* o = output; // write pointer
82-
uint8_t* out = output;
83-
uint8_t const* i = input; // read pointer
81+
uint8_t* o = (uint8_t*) output; // write pointer
82+
uint8_t* out = (uint8_t*) output;
83+
uint8_t const* i = (uint8_t const*) input; // read pointer
8484
uint8_t const* limit = (uint8_t*)input + length; // read limit
8585
uint8_t zeroCount = 0; // counts zero bytes 1-3 for Z1-Z3
8686
uint8_t fullCount = 0; // counts 0xFF bytes 1-4 for FF and F2-F4

src/trice.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ int triceCommandFlag = 0; // updated
244244
#if TRICE_CYCLE_COUNTER == 1
245245

246246
//! TriceCycle is increased and transmitted with each trice message, if enabled.
247-
uint8_t TriceCycle = 0xc0;
247+
uint_fast32_t TriceCycle = 0xc0;
248248

249249
#endif
250250

@@ -1022,6 +1022,7 @@ void TRice32B(int tid, char const* fmt, void* buf, uint32_t n) {
10221022
TRICE32_B(ID(tid), fmt, buf, n);
10231023
}
10241024

1025+
#if (TRICE_64_BIT_SUPPORT == 1)
10251026
void trice64B(int tid, char const* fmt, void* buf, uint32_t n) {
10261027
TRICE64_B(id(tid), fmt, buf, n);
10271028
}
@@ -1033,6 +1034,7 @@ void Trice64B(int tid, char const* fmt, void* buf, uint32_t n) {
10331034
void TRice64B(int tid, char const* fmt, void* buf, uint32_t n) {
10341035
TRICE64_B(ID(tid), fmt, buf, n);
10351036
}
1037+
#endif // (TRICE_64_BIT_SUPPORT == 1)
10361038

10371039
void trice8F(int tid, char const* fmt, void* buf, uint32_t n) {
10381040
TRICE8_F(id(tid), fmt, buf, n);
@@ -1070,6 +1072,7 @@ void TRice32F(int tid, char const* fmt, void* buf, uint32_t n) {
10701072
TRICE32_F(ID(tid), fmt, buf, n);
10711073
}
10721074

1075+
#if (TRICE_64_BIT_SUPPORT == 1)
10731076
void trice64F(int tid, char const* fmt, void* buf, uint32_t n) {
10741077
TRICE64_F(id(tid), fmt, buf, n);
10751078
}
@@ -1081,6 +1084,7 @@ void Trice64F(int tid, char const* fmt, void* buf, uint32_t n) {
10811084
void TRice64F(int tid, char const* fmt, void* buf, uint32_t n) {
10821085
TRICE64_F(ID(tid), fmt, buf, n);
10831086
}
1087+
#endif // (TRICE_64_BIT_SUPPORT == 1)
10841088

10851089
#endif // #ifdef TRICE_N
10861090

src/trice.h

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#ifndef TRICE_H_
66
#define TRICE_H_
77

8+
#include <stdint.h>
9+
#include <string.h>
10+
811
#ifdef __cplusplus
912
extern "C" {
1013
#endif
@@ -50,44 +53,42 @@ extern "C" {
5053
// lint -emacro( 717, DCOPY, SCOPY )
5154
// lint -emacro( 732, DCOPY )
5255

53-
// helper macros (the numbers are 32-bit random values)
56+
// helper macros (the numbers are 16-bit random values)
5457

5558
//! TRICE_SINGLE_PACK_MODE is the recommended TRICE_DEFERRED_TRANSFER_MODE. It packs each trice in a separate TCOBS package with a following 0-delimiter byte.
5659
//! Single trices need a bit more transfer data. In case of a data disruption, only a single trice messages can get lost.
57-
#define TRICE_SINGLE_PACK_MODE 787345706U
60+
#define TRICE_SINGLE_PACK_MODE 5706U
5861

5962
//! TRICE_MULTI_PACK_MODE packs all trices of a buffer in a single TCOBS package and a following 0-delimiter byte.
6063
//! Grouped trices need a bit less transfer data. In case of a data disruption, multiple trice messages can get lost.
6164
//! Olny relevant when TRICE_DOUBLE_BUFFER is selected
62-
#define TRICE_MULTI_PACK_MODE 3987862482U
65+
#define TRICE_MULTI_PACK_MODE 2482U
6366

6467
//! With TRICE_BUFFER == TRICE_STACK_BUFFER the internal macro TRICE_PUT writes to the stack.
6568
//! This is direct logging. This reduces memory needs if only one stack is used.
66-
#define TRICE_STACK_BUFFER 2645382063U
69+
#define TRICE_STACK_BUFFER 2063U
6770

6871
//! With TRICE_BUFFER == TRICE_STATIC_BUFFER the internal macro TRICE_PUT writes to a static buffer.
6972
//! This reduces memory needs if many stacks are used.
70-
#define TRICE_STATIC_BUFFER 1763551404U
73+
#define TRICE_STATIC_BUFFER 1404U
7174

7275
//! With TRICE_BUFFER == TRICE_DOUBLE_BUFFER the internal macro TRICE_PUT writes to a double buffer half.
7376
//! This is deferred logging using more space but the TRICE macros are executed faster.
74-
#define TRICE_DOUBLE_BUFFER 1950870368U
77+
#define TRICE_DOUBLE_BUFFER 368U
7578

7679
//! With TRICE_BUFFER == TRICE_RING_BUFFER the internal macro TRICE_PUT writes to a ring buffer segment.
7780
//! This is deferred logging using less space but the TRICE macros are executed a bit slower.
78-
#define TRICE_RING_BUFFER 2237719049U
81+
#define TRICE_RING_BUFFER 9049U
7982

8083
//! TRICE_FRAMING_TCOBS is recommended for trice transfer over UART.
81-
#define TRICE_FRAMING_TCOBS 3745917584U
84+
#define TRICE_FRAMING_TCOBS 7584U
8285

8386
//! TRICE_FRAMING_COBS is recommended for encrypted trices.
84-
#define TRICE_FRAMING_COBS 2953804234U
87+
#define TRICE_FRAMING_COBS 4234U
8588

8689
//! TRICE_FRAMING_NONE is recommended for RTT in direct mode. One trice costs about 100 clocks and is completely done.
87-
#define TRICE_FRAMING_NONE 1431860787U
90+
#define TRICE_FRAMING_NONE 787U
8891

89-
#include <stdint.h>
90-
#include <string.h>
9192
#include "triceConfig.h" // Project specific settings are overwriting the default settings.
9293
#include "triceDefaultConfig.h" // default settings
9394

@@ -141,6 +142,7 @@ TRICE_INLINE uint32_t aFloat(float f) {
141142
return pun.to;
142143
}
143144

145+
#if (TRICE_64_BIT_SUPPORT == 1)
144146
// aDouble returns passed double value x as bit pattern in a uint64_t type.
145147
TRICE_INLINE uint64_t aDouble(double x) {
146148
union {
@@ -150,6 +152,7 @@ TRICE_INLINE uint64_t aDouble(double x) {
150152
t_aDouble.d = x;
151153
return t_aDouble.u;
152154
}
155+
#endif // #if (TRICE_64_BIT_SUPPORT == 1)
153156

154157
// Just in case you are receiving Trice messages containing uint32_t values to be interpreted as float:
155158
//
@@ -208,7 +211,7 @@ extern uint32_t* triceSingleBufferStartWritePosition;
208211
extern unsigned TricesCountRingBuffer;
209212
extern char triceCommandBuffer[];
210213
extern int triceCommandFlag;
211-
extern uint8_t TriceCycle;
214+
extern uint_fast32_t TriceCycle;
212215
extern unsigned RTT0_writeDepthMax;
213216
extern unsigned TriceErrorCount;
214217

@@ -276,11 +279,11 @@ extern uint32_t* TriceBufferWritePosition;
276279

277280
#if TRICE_CYCLE_COUNTER == 1
278281

279-
#define TRICE_CYCLE TriceCycle++ //!< TRICE_CYCLE is the trice cycle counter as 8 bit count 0-255.
282+
#define TRICE_CYCLE (TriceCycle++ & 0xFF) //!< TRICE_CYCLE is the trice cycle counter as 8 bit count 0-255.
280283

281284
#else // #if TRICE_CYCLE_COUNTER == 1
282285

283-
#define TRICE_CYCLE 0xC0 //!< TRICE_CYCLE is no trice cycle counter, just a static value.
286+
#define TRICE_CYCLE ((uint_fast32_t) 0xC0) //!< TRICE_CYCLE is no trice cycle counter, just a static value.
284287

285288
#endif // #else // #if TRICE_CYCLE_COUNTER == 1
286289

@@ -321,7 +324,9 @@ extern uint32_t* TriceBufferWritePosition;
321324
#include "trice8.h"
322325
#include "trice16.h"
323326
#include "trice32.h"
327+
#if (TRICE_64_BIT_SUPPORT == 1)
324328
#include "trice64.h"
329+
#endif // (TRICE_64_BIT_SUPPORT == 1)
325330

326331
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
327332
// Endian dependent macros and code:
@@ -383,7 +388,9 @@ extern uint32_t* TriceBufferWritePosition;
383388
#include "trice8McuOrder.h"
384389
#include "trice16McuOrder.h"
385390
#include "trice32McuOrder.h"
391+
#if (TRICE_64_BIT_SUPPORT == 1)
386392
#include "trice64McuOrder.h"
393+
#endif // (TRICE_64_BIT_SUPPORT == 1)
387394

388395
#else // #if TRICE_TRANSFER_ORDER_IS_BIG_ENDIAN == TRICE_MCU_IS_BIG_ENDIAN
389396

@@ -392,7 +399,9 @@ extern uint32_t* TriceBufferWritePosition;
392399
#include "trice8McuReverse.h"
393400
#include "trice16McuReverse.h"
394401
#include "trice32McuReverse.h"
402+
#if (TRICE_64_BIT_SUPPORT == 1)
395403
#include "trice64McuReverse.h"
404+
#endif // (TRICE_64_BIT_SUPPORT == 1)
396405

397406
#endif // #else // #if TRICE_TRANSFER_ORDER_IS_BIG_ENDIAN == TRICE_MCU_IS_BIG_ENDIAN
398407

0 commit comments

Comments
 (0)