Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segger RTT: support CONFIG_SEGGER_RTT_INIT_MODE and optimizations #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion Config/SEGGER_RTT_Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Revision: $Rev: 24316 $
#define SEGGER_RTT_SECTION ".dtcm_data"
#elif defined(CONFIG_SEGGER_RTT_SECTION_CCM)
#define SEGGER_RTT_SECTION ".ccm_data"
#elif defined(CONFIG_SEGGER_RTT_SECTION_CUSTOM)
#elif defined(CONFIG_SEGGER_RTT_SECTION_CUSTOM) || defined(CONFIG_SEGGER_RTT_SECTION_CUSTOM_DTS_REGION)
henrikbrixandersen marked this conversation as resolved.
Show resolved Hide resolved
#define SEGGER_RTT_SECTION CONFIG_SEGGER_RTT_SECTION_CUSTOM_NAME
#endif

Expand Down
44 changes: 41 additions & 3 deletions SEGGER/SEGGER_RTT.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ Additional information:
**********************************************************************
*/

static unsigned char _aTerminalId[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
static const unsigned char _aTerminalId[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

static const char _aInitStr[] = "\0\0\0\0\0\0TTR REGGES"; // Init complete ID string to make sure that things also work if RTT is linked to a no-init memory area

/*********************************************************************
*
Expand Down Expand Up @@ -309,15 +311,14 @@ static unsigned char _ActiveTerminal;
volatile SEGGER_RTT_CB* pRTTCBInit; \
pRTTCBInit = (volatile SEGGER_RTT_CB*)((char*)&_SEGGER_RTT + SEGGER_RTT_UNCACHED_OFF); \
do { \
if (pRTTCBInit->acID[0] == '\0') { \
if (pRTTCBInit->acID[0] != 'S') { \
_DoInit(); \
} \
} while (0); \
}

static void _DoInit(void) {
volatile SEGGER_RTT_CB* p; // Volatile to make sure that compiler cannot change the order of accesses to the control block
static const char _aInitStr[] = "\0\0\0\0\0\0TTR REGGES"; // Init complete ID string to make sure that things also work if RTT is linked to a no-init memory area
unsigned i;
//
// Initialize control block
Expand Down Expand Up @@ -1892,6 +1893,28 @@ int SEGGER_RTT_SetFlagsDownBuffer(unsigned BufferIndex, unsigned Flags) {
return r;
}

#if defined(CONFIG_SEGGER_RTT_INIT_MODE_STRONG_CHECK)
henrikbrixandersen marked this conversation as resolved.
Show resolved Hide resolved
static void SEGGER_RTT_StrongCheckInit(void) {
volatile SEGGER_RTT_CB* p;
p = (volatile SEGGER_RTT_CB*)((char*)&_SEGGER_RTT + SEGGER_RTT_UNCACHED_OFF);
unsigned i;
int DoInit = 0;

RTT__DMB(); // Force order of memory accesses for cores that may perform out-of-order memory accesses
for (i = 0; i < sizeof(_aInitStr) - 1; ++i) {
if (p->acID[i] != _aInitStr[sizeof(_aInitStr) - 2 - i]) { // Skip terminating \0 at the end of the array
DoInit = 1;
break;
}
}
RTT__DMB(); // Force order of memory accesses for cores that may perform out-of-order memory accesses

if (DoInit) {
_DoInit();
}
}
#endif

/*********************************************************************
*
* SEGGER_RTT_Init
Expand All @@ -1902,7 +1925,22 @@ int SEGGER_RTT_SetFlagsDownBuffer(unsigned BufferIndex, unsigned Flags) {
*
*/
void SEGGER_RTT_Init (void) {
/*
* The standard Segger code calls only _DoInit() here. This happens,
* for example, in a bootloader or in stand-alone applications.
* For applications started by a bootloader, Segger recommends not
* calling this function, as all the recommended APIs use INIT().
* Unfortunately Zephyr log backend uses SEGGER_RTT_WriteSkipNoLock()
* that doesn't call INIT(), so the additional two following variants
* have been added here for a safe API usage.
*/
#if defined(CONFIG_SEGGER_RTT_INIT_MODE_STRONG_CHECK)
SEGGER_RTT_StrongCheckInit();
#elif defined(CONFIG_SEGGER_RTT_INIT_MODE_WEAK_CHECK)
henrikbrixandersen marked this conversation as resolved.
Show resolved Hide resolved
INIT();
#else
_DoInit();
#endif
}

/*********************************************************************
Expand Down