µ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++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2016-2023 Liviu Ionescu. All rights reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose is hereby granted, under the terms of the MIT license.
8 *
9 * If a copy of the license was not distributed with this file, it can
10 * be obtained from https://opensource.org/licenses/mit/.
11 */
12
13#if defined(__clang__)
14#pragma clang diagnostic ignored "-Wempty-translation-unit"
15#endif
16
17// ----------------------------------------------------------------------------
18
19#if defined(__ARM_EABI__)
20
21// ----------------------------------------------------------------------------
22
23#if defined(TRACE)
24
25#if defined(OS_USE_OS_APP_CONFIG_H)
26#include <cmsis-plus/os-app-config.h>
27#endif
28
29#if defined(OS_USE_TRACE_SEGGER_RTT)
30
31#include <cmsis-plus/rtos/os.h>
33
34#include <cmsis_device.h>
35
36#include "SEGGER_RTT.h"
37
38// ----------------------------------------------------------------------------
39
40namespace os
41{
42 namespace trace
43 {
44 // --------------------------------------------------------------------
45
46 void
47 initialize (void)
48 {
49 SEGGER_RTT_Init ();
50
51 // Clear the SLEEPDEEP.
52 // This does not guarantee that the WFI will not prevent
53 // the J-Link to read the RTT buffer, but it is the best it
54 // can be done at this level.
55 SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
56 }
57
58 // --------------------------------------------------------------------
59
60 ssize_t
61 write (const void* buf, std::size_t nbyte)
62 {
63 if (buf == nullptr || nbyte == 0)
64 {
65 return 0;
66 }
67
68 if (nbyte > BUFFER_SIZE_UP)
69 {
70 return 0;
71 }
72
73 ssize_t ret;
74
75 rtos::interrupts::critical_section ics;
76 ret = (ssize_t) SEGGER_RTT_WriteNoLock (0, buf, nbyte);
77
78 return ret;
79 }
80
81 void
82 flush (void)
83 {
84 while (_SEGGER_RTT.aUp[0].WrOff != _SEGGER_RTT.aUp[0].RdOff)
85 {
86 __NOP ();
87 }
88 }
89
90 } /* namespace trace */
91} /* namespace os */
92
93#endif /* defined(OS_USE_TRACE_SEGGER_RTT) */
94#endif /* defined(TRACE) */
95
96// ----------------------------------------------------------------------------
97
98#endif /* defined(__ARM_EABI__) */
void initialize(void)
Definition trace.cpp:38
ssize_t write(const void *buf, std::size_t nbyte)
Write the given number of bytes to the trace output channel.
Definition trace.cpp:47
void flush(void)
Flush the output.
Definition trace.cpp:53
System namespace.
Single file µOS++ RTOS definitions.