Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions RTT/SEGGER_RTT.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ Additional information:

#include "SEGGER_RTT.h"

#include <string.h> // for memcpy

/*********************************************************************
*
* Configuration, default values
Expand Down Expand Up @@ -158,6 +156,7 @@ Additional information:
#ifdef MEMCPY
#define SEGGER_RTT_MEMCPY(pDest, pSrc, NumBytes) MEMCPY((pDest), (pSrc), (NumBytes))
#else
#include <string.h> // for memcpy
#define SEGGER_RTT_MEMCPY(pDest, pSrc, NumBytes) memcpy((pDest), (pSrc), (NumBytes))
#endif
#endif
Expand Down Expand Up @@ -951,15 +950,15 @@ unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pBuffer, u
if (RdOff <= WrOff) { // Case 1), 2) or 3)
Avail = pRing->SizeOfBuffer - WrOff - 1u; // Space until wrap-around (assume 1 byte not usable for case that RdOff == 0)
if (Avail >= NumBytes) { // Case 1)?
memcpy((void*)pDst, pData, NumBytes);
SEGGER_RTT_MEMCPY((void*)pDst, pData, NumBytes);
RTT__DMB(); // Force data write to be complete before writing the <WrOff>, in case CPU is allowed to change the order of memory accesses
pRing->WrOff = WrOff + NumBytes;
return 1;
}
Avail += RdOff; // Space incl. wrap-around
if (Avail >= NumBytes) { // Case 2? => If not, we have case 3) (does not fit)
Rem = pRing->SizeOfBuffer - WrOff; // Space until end of buffer
memcpy((void*)pDst, pData, Rem); // Copy 1st chunk
SEGGER_RTT_MEMCPY((void*)pDst, pData, Rem); // Copy 1st chunk
NumBytes -= Rem;
//
// Special case: First check that assumed RdOff == 0 calculated that last element before wrap-around could not be used
Expand All @@ -969,7 +968,7 @@ unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pBuffer, u
//
if (NumBytes) {
pDst = pRing->pBuffer + SEGGER_RTT_UNCACHED_OFF;
memcpy((void*)pDst, pData + Rem, NumBytes);
SEGGER_RTT_MEMCPY((void*)pDst, pData + Rem, NumBytes);
}
RTT__DMB(); // Force data write to be complete before writing the <WrOff>, in case CPU is allowed to change the order of memory accesses
pRing->WrOff = NumBytes;
Expand All @@ -978,7 +977,7 @@ unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pBuffer, u
} else { // Potential case 4)
Avail = RdOff - WrOff - 1u;
if (Avail >= NumBytes) { // Case 4)? => If not, we have case 5) (does not fit)
memcpy((void*)pDst, pData, NumBytes);
SEGGER_RTT_MEMCPY((void*)pDst, pData, NumBytes);
RTT__DMB(); // Force data write to be complete before writing the <WrOff>, in case CPU is allowed to change the order of memory accesses
pRing->WrOff = WrOff + NumBytes;
return 1;
Expand Down
14 changes: 12 additions & 2 deletions RTT/SEGGER_RTT.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ Revision: $Rev: 25842 $
#endif

#ifndef SEGGER_RTT_ASM // defined when SEGGER_RTT.h is included from assembly file
#include <stdlib.h>
#include <stdarg.h>
#include <stdint.h>

Expand All @@ -310,6 +309,17 @@ Revision: $Rev: 25842 $
#define SEGGER_RTT__CB_SIZE (16 + 4 + 4 + (SEGGER_RTT_MAX_NUM_UP_BUFFERS * 24) + (SEGGER_RTT_MAX_NUM_DOWN_BUFFERS * 24))
#define SEGGER_RTT__CB_PADDING (SEGGER_RTT__ROUND_UP_2_CACHE_LINE_SIZE(SEGGER_RTT__CB_SIZE) - SEGGER_RTT__CB_SIZE)

#if defined(__GNUC__) || defined(__clang__)
// https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Function-Attributes.html
# ifdef __MINGW_PRINTF_FORMAT
# define SEGGER_RTT_PRINTF_FORMAT(STRING_INDEX, FIRST_TO_CHECK) __attribute__ ((format (__MINGW_PRINTF_FORMAT, STRING_INDEX, FIRST_TO_CHECK)))
# else
# define SEGGER_RTT_PRINTF_FORMAT(STRING_INDEX, FIRST_TO_CHECK) __attribute__ ((format (printf, STRING_INDEX, FIRST_TO_CHECK)))
# endif // __MINGW_PRINTF_FORMAT
#else
# define SEGGER_RTT_PRINTF_FORMAT(STRING_INDEX, FIRST_TO_CHECK)
#endif

/*********************************************************************
*
* Types
Expand Down Expand Up @@ -440,7 +450,7 @@ int SEGGER_RTT_TerminalOut (unsigned char TerminalId, const char* s);
*
**********************************************************************
*/
int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);
int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...) SEGGER_RTT_PRINTF_FORMAT(2, 3);
int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);

#ifdef __cplusplus
Expand Down