µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
trace-segger-rtt.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2016-2025 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
9 * be obtained from https://opensource.org/licenses/mit.
10 */
11
12#if defined(__clang__)
13#pragma clang diagnostic ignored "-Wempty-translation-unit"
14#endif
15
16// ----------------------------------------------------------------------------
17
18#if defined(__ARM_EABI__)
19
20// ----------------------------------------------------------------------------
21
22#if defined(TRACE)
23
24#if defined(OS_USE_OS_APP_CONFIG_H)
25#include <cmsis-plus/os-app-config.h>
26#endif
27
28#if defined(OS_USE_TRACE_SEGGER_RTT)
29
30#include <cmsis-plus/rtos/os.h>
32
33#include <cmsis_device.h>
34
35#include "SEGGER_RTT.h"
36
37// ----------------------------------------------------------------------------
38
39namespace os
40{
41 namespace trace
42 {
43 // --------------------------------------------------------------------
44
45 void
46 initialize (void)
47 {
48 SEGGER_RTT_Init ();
49
50 // Clear the SLEEPDEEP.
51 // This does not guarantee that the WFI will not prevent
52 // the J-Link to read the RTT buffer, but it is the best it
53 // can be done at this level.
54#if defined(__GNUC__)
55#pragma GCC diagnostic push
56#if defined(__clang__)
57#else
58#pragma GCC diagnostic ignored "-Wold-style-cast"
59#endif
60#endif
61 SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
62#if defined(__GNUC__)
63#pragma GCC diagnostic pop
64#endif
65 }
66
67 // --------------------------------------------------------------------
68
69 ssize_t
70 write (const void* buf, std::size_t nbyte)
71 {
72 if (buf == nullptr || nbyte == 0)
73 {
74 return 0;
75 }
76
77 if (nbyte > BUFFER_SIZE_UP)
78 {
79 return 0;
80 }
81
82 ssize_t ret;
83
84 // SEGGER provides a `SEGGER_RTT_Write()` which implements locking
85 // with its own `SEGGER_RTT_MAX_INTERRUPT_PRIORITY`.
86 // For consistency with µOS++ interrupt handling, a µOS++ critical
87 // section is preferred.
88 rtos::interrupts::critical_section ics;
89 ret = static_cast<ssize_t> (SEGGER_RTT_WriteNoLock (0, buf, nbyte));
90
91 return ret;
92 }
93
94 void
95 flush (void)
96 {
97 // Busy wait until all data is sent.
98 // The buffer is empty when WrOff == RdOff.
99 while (_SEGGER_RTT.aUp[0].WrOff != _SEGGER_RTT.aUp[0].RdOff)
100 {
101 __NOP ();
102 }
103 }
104
105 } /* namespace trace */
106} /* namespace os */
107
108#endif /* defined(OS_USE_TRACE_SEGGER_RTT) */
109#endif /* defined(TRACE) */
110
111// ----------------------------------------------------------------------------
112
113#endif /* defined(__ARM_EABI__) */
void initialize(void)
Definition trace.cpp:37
ssize_t write(const void *buf, std::size_t nbyte)
Write the given number of bytes to the trace output channel.
Definition trace.cpp:46
void flush(void)
Flush the output.
Definition trace.cpp:52
System namespace.
Single file µOS++ RTOS definitions.