Skip to content

Commit

Permalink
format code initial
Browse files Browse the repository at this point in the history
  • Loading branch information
lilian committed Aug 28, 2024
1 parent 272eb16 commit a07de06
Show file tree
Hide file tree
Showing 30 changed files with 10,018 additions and 7,298 deletions.
2,341 changes: 1,300 additions & 1,041 deletions src/SEGGER_RTT.c

Large diffs are not rendered by default.

745 changes: 408 additions & 337 deletions src/SEGGER_RTT.h

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/_unused/_TriceUnsused.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ static void singleTriceDirectOut( uint32_t* tb, size_t tLen ){
if( triceID <= 0 ){ // on data error
break; // ignore following data
}
#if TRICE_DEFERRED_TRANSFER_MODE == TRICE_SINGLE_PACK_MODE
#if TRICE_DEFERRED_TRANSFER_MODE == TRICE_SINGLE_PACK_MODE
encLen += TriceEncode( enc+encLen, triceStart, triceLen );
#endif
#endif
}
#if TRICE_DEFERRED_SEGGER_RTT_8BIT_WRITE == 1
#if TRICE_DEFERRED_SEGGER_RTT_8BIT_WRITE == 1
TriceWriteDeviceRtt0( enc, encLen );
#endif
#endif
}

#if TRICE_DEFERRED_SEGGER_RTT_8BIT_WRITE == 1
Expand All @@ -86,9 +86,9 @@ void TriceOutRtt0( uint32_t* tb, size_t tLen ){
if( triceID <= 0 ){ // on data error
break; // ignore following data
}
#if TRICE_DEFERRED_TRANSFER_MODE == TRICE_SINGLE_PACK_MODE
#if TRICE_DEFERRED_TRANSFER_MODE == TRICE_SINGLE_PACK_MODE
encLen += TriceEncode( enc+encLen, triceStart, triceLen );
#endif
#endif
}
TriceWriteDeviceRtt0( enc, encLen ); //lint !e534
}
Expand Down
6 changes: 2 additions & 4 deletions src/_unused/_unused_triceModbusBuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ size_t TriceModbusOnlyFetch( int index, uint8_t* tBuf );
//
///////////////////////////////////////////////////////////////////////////////


#ifdef TRICE_LOG_OVER_MODBUS_FUNC24_ALSO
#error
#if TRICE_MODBUS_BUFFER_SIZE < 2*(TRICE_SINGLE_MAX_SIZE+TRICE_DATA_OFFSET)
#if TRICE_MODBUS_BUFFER_SIZE < 2 * (TRICE_SINGLE_MAX_SIZE + TRICE_DATA_OFFSET)
#error
#endif

Expand All @@ -64,7 +63,7 @@ static uint32_t* triceModbusBufferWritePosition = triceModbusBufferHeap; //!< Tr
static uint32_t* triceModbusBufferWriteLimit = &triceModbusBufferHeap[TRICE_MODBUS_BUFFER_SIZE>>2]; //!< triceModbusBufferWriteLimit is the triceBuffer written limit.

// TRICE_MODBUS_FIFO_MAX_DEPTH is the max possible count of values the triceFifo can hold.
#define TRICE_MODBUS_FIFO_MAX_DEPTH (TRICE_MODBUS_FIFO_ELEMENTS-1)
#define TRICE_MODBUS_FIFO_MAX_DEPTH (TRICE_MODBUS_FIFO_ELEMENTS - 1)

//! triceModbusFifo holds up to TRICE_MODBUS_FIFO_MAX_DEPTH uint32_t* values.
static uint32_t* triceModbusFifo[TRICE_MODBUS_FIFO_ELEMENTS];
Expand Down Expand Up @@ -170,7 +169,6 @@ void TriceNonBlockingWriteModbusBuffer( uint8_t const * buf, unsigned len ){
TriceModbusFifoPush(dest + ((len+3)>>2) );
}


#if TRICE_CYCLE_COUNTER == 0
#error TRICE_CYCLE_COUNTER is needed for TRICE_LOG_OVER_MODBUS_FUNC24
#endif
Expand Down
13 changes: 8 additions & 5 deletions src/cobs.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
//! \file cobs.h
//! \author Thomas.Hoehenleitner [at] seerose.net


#ifndef COBS_H_
#define COBS_H_

#include <stddef.h> //lint !e537 !e451 Warning 537: Repeated include file, Warning 451: Header file repeatedly included but does not have a standard
#include <stdint.h> //lint !e537 !e451 Warning 537: Repeated include file, Warning 451: Header file repeatedly included but does not have a standard

//! If your compiler uses a pre-C99 C dialect and does not know The "__restrict" keyword, you can define it in the project settings.
size_t COBSEncode(void * __restrict out, const void * __restrict in, size_t length);
//! If your compiler uses a pre-C99 C dialect and does not know The "__restrict"
//! keyword, you can define it in the project settings.
size_t COBSEncode(void *__restrict out, const void *__restrict in,
size_t length);

//! If your compiler uses a pre-C99 C dialect and does not know The "__restrict" keyword, you can define it in the project settings.
size_t COBSDecode(void * __restrict out, const void * __restrict in, size_t length);
//! If your compiler uses a pre-C99 C dialect and does not know The "__restrict"
//! keyword, you can define it in the project settings.
size_t COBSDecode(void *__restrict out, const void *__restrict in,
size_t length);

#endif
42 changes: 22 additions & 20 deletions src/cobsDecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@
//! @param length Number of bytes to decode.
//! @param out Pointer to decoded output data.
//! @return Number of bytes successfully decoded.
//! @note Stops decoding if delimiter byte is found. Code taken from Wikipedia and slightly modyfied.
size_t COBSDecode(void * __restrict out, const void * __restrict in, size_t length ) {
uint8_t* data = out;
const uint8_t * buffer = in;
const uint8_t *byte = buffer; // Encoded input byte pointer
uint8_t *decode = (uint8_t *)data; // Decoded output byte pointer
//! @note Stops decoding if delimiter byte is found. Code taken from Wikipedia
//! and slightly modyfied.
size_t COBSDecode(void *__restrict out, const void *__restrict in,
size_t length) {
uint8_t *data = out;
const uint8_t *buffer = in;
const uint8_t *byte = buffer; // Encoded input byte pointer
uint8_t *decode = (uint8_t *)data; // Decoded output byte pointer

for (uint8_t code = 0xff, block = 0; byte < buffer + length; --block) {
if (block) { // Decode block byte
*decode++ = *byte++;
} else {
if (code != 0xff) { // Encoded zero, write it
*decode++ = 0;
}
block = code = *byte++; // Next block length
if (!code) { // Delimiter code found
break;
}
}
}
return (size_t)(decode - data);
for (uint8_t code = 0xff, block = 0; byte < buffer + length; --block) {
if (block) { // Decode block byte
*decode++ = *byte++;
} else {
if (code != 0xff) { // Encoded zero, write it
*decode++ = 0;
}
block = code = *byte++; // Next block length
if (!code) { // Delimiter code found
break;
}
}
}
return (size_t)(decode - data);
}
40 changes: 21 additions & 19 deletions src/cobsEncode.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@
//! @param length Number of bytes to encode.
//! @param out Pointer to encoded output buffer.
//! @return Encoded buffer length in bytes.
//! @note Does not output delimiter byte. Code taken from Wikipedia and slightly adapted.
size_t COBSEncode( void * __restrict out, const void * __restrict in, size_t length) {
uint8_t * buffer = out;
uint8_t *encode = buffer; // Encoded byte pointer
uint8_t *codep = encode++; // Output code pointer
uint8_t code = 1; // Code value
//! @note Does not output delimiter byte. Code taken from Wikipedia and slightly
//! adapted.
size_t COBSEncode(void *__restrict out, const void *__restrict in,
size_t length) {
uint8_t *buffer = out;
uint8_t *encode = buffer; // Encoded byte pointer
uint8_t *codep = encode++; // Output code pointer
uint8_t code = 1; // Code value

for (const uint8_t *byte = (const uint8_t *)in; length--; ++byte) {
if (*byte) { // Byte not zero, write it
*encode++ = *byte, ++code;
}
if (!*byte || code == 0xff) { // Input is zero or block completed, restart
*codep = code, code = 1, codep = encode;
if (!*byte || length) {
++encode;
}
}
}
*codep = code; // Write final code value
return (size_t)(encode - buffer);
for (const uint8_t *byte = (const uint8_t *)in; length--; ++byte) {
if (*byte) { // Byte not zero, write it
*encode++ = *byte, ++code;
}
if (!*byte || code == 0xff) { // Input is zero or block completed, restart
*codep = code, code = 1, codep = encode;
if (!*byte || length) {
++encode;
}
}
}
*codep = code; // Write final code value
return (size_t)(encode - buffer);
}
56 changes: 34 additions & 22 deletions src/tcobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,40 @@ extern "C" {

#include <stddef.h>

//! TCOBSEncode stuffs "length" bytes of data beginning at the location pointed to by "input" and writes the output to the
//! location pointed to by "output". Returns the number of bytes written to "output" or a negative value in error case.
//! A 0-delimiter is NOT added as last byte allowing concatenating TCOBS encoded buffers to one bigger buffer before the
//! 00-byte delimiting. Buffer overlapping is allowed, when input lays inside output with a sufficient offset. The offset
//! should be >= next large whole number of length/31. because in the worst case for each 31 bytes an additional sigil byte
//! is inserted. The provided output buffer size should be >= length + next large whole number of length/31. This is a
//! responsibility of the caller and not checked for efficiency.
//! If your compiler uses a pre-C99 C dialect and does not know The "__restrict" keyword, you can define it in the project settings.
int TCOBSEncode( void * __restrict output, const void * __restrict input, size_t length);

//! TCOBSDecode decodes data ending at the location pointed to by "input" backwards (starting with the last byte)
//! and writes the output also backwards to the location pointed to by "output" with a maximum size of max.
//! Returns the number of bytes written to "output". Only max bytes are written. If the returned value is
//! > max, this is an error "output buffer too small". In case of an error, a negative value is returned.
//! THIS IS **IMPORTANT**: The decoded data start at output+max-returned, because output is filled from the end.
//! Buffer overlapping is partially possible if output limit is _behind_ input limit with sufficient distance,
//! but data can get much longer.
//! If your compiler uses a pre-C99 C dialect and does not know The "__restrict" keyword, you can define it in the project settings.
int TCOBSDecode( void * __restrict output, size_t max, const void * __restrict input, size_t length );

#define OUT_BUFFER_TOO_SMALL -1000000 //!< OUT_BUFFER_TOO_SMALL is TCOBSDecode return error code.
#define INPUT_DATA_CORRUPTED -2000000 //!< INPUT_DATA_CORRUPTED is TCOBSDecode return error code.
//! TCOBSEncode stuffs "length" bytes of data beginning at the location pointed
//! to by "input" and writes the output to the location pointed to by "output".
//! Returns the number of bytes written to "output" or a negative value in error
//! case. A 0-delimiter is NOT added as last byte allowing concatenating TCOBS
//! encoded buffers to one bigger buffer before the 00-byte delimiting. Buffer
//! overlapping is allowed, when input lays inside output with a sufficient
//! offset. The offset should be >= next large whole number of length/31.
//! because in the worst case for each 31 bytes an additional sigil byte is
//! inserted. The provided output buffer size should be >= length + next large
//! whole number of length/31. This is a responsibility of the caller and not
//! checked for efficiency. If your compiler uses a pre-C99 C dialect and does
//! not know The "__restrict" keyword, you can define it in the project
//! settings.
int TCOBSEncode(void *__restrict output, const void *__restrict input,
size_t length);

//! TCOBSDecode decodes data ending at the location pointed to by "input"
//! backwards (starting with the last byte) and writes the output also backwards
//! to the location pointed to by "output" with a maximum size of max. Returns
//! the number of bytes written to "output". Only max bytes are written. If the
//! returned value is > max, this is an error "output buffer too small". In case
//! of an error, a negative value is returned. THIS IS **IMPORTANT**: The
//! decoded data start at output+max-returned, because output is filled from the
//! end. Buffer overlapping is partially possible if output limit is _behind_
//! input limit with sufficient distance, but data can get much longer. If your
//! compiler uses a pre-C99 C dialect and does not know The "__restrict"
//! keyword, you can define it in the project settings.
int TCOBSDecode(void *__restrict output, size_t max,
const void *__restrict input, size_t length);

#define OUT_BUFFER_TOO_SMALL \
-1000000 //!< OUT_BUFFER_TOO_SMALL is TCOBSDecode return error code.
#define INPUT_DATA_CORRUPTED \
-2000000 //!< INPUT_DATA_CORRUPTED is TCOBSDecode return error code.

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit a07de06

Please sign in to comment.