10
10
// ----------------------------------------------------------------------------
11
11
12
12
#include <modm/platform/device.hpp>
13
+ #include <modm/processing/fiber.hpp>
13
14
#include "itm.hpp"
14
15
15
16
%% if options["buffer.tx"]
@@ -74,14 +75,18 @@ Itm::enable(uint8_t prescaler)
74
75
void
75
76
Itm::writeBlocking(uint8_t data)
76
77
{
77
- while(not write(data)) ;
78
+ modm::this_fiber::poll([&]{ return write(data); }) ;
78
79
}
79
80
80
81
void
81
82
Itm::flushWriteBuffer()
82
83
{
83
84
%% if options["buffer.tx"]
84
- while(!isWriteFinished()) update();
85
+ while(!isWriteFinished())
86
+ {
87
+ update();
88
+ modm::this_fiber::yield();
89
+ }
85
90
%% else
86
91
return;
87
92
%% endif
91
96
Itm::write(uint8_t data)
92
97
{
93
98
%% if options["buffer.tx"]
99
+ update();
94
100
if (txBuffer.push(data)) return true;
95
101
update();
96
102
return txBuffer.push(data);
@@ -109,16 +115,6 @@ Itm::write(const uint8_t *data, std::size_t length)
109
115
return sent;
110
116
}
111
117
112
- bool
113
- Itm::isWriteFinished()
114
- {
115
- %% if options["buffer.tx"]
116
- return txBuffer.isEmpty();
117
- %% else
118
- return true;
119
- %% endif
120
- }
121
-
122
118
std::size_t
123
119
Itm::discardTransmitBuffer()
124
120
{
@@ -138,6 +134,16 @@ Itm::discardTransmitBuffer()
138
134
#undef PORT
139
135
%% endif
140
136
137
+ bool
138
+ Itm::isWriteFinished()
139
+ {
140
+ %% if options["buffer.tx"]
141
+ return txBuffer.isEmpty() and ITM->PORT[0].u32 != 0;
142
+ %% else
143
+ return ITM->PORT[0].u32 != 0;
144
+ %% endif
145
+ }
146
+
141
147
bool
142
148
Itm::write_itm(uint32_t data, uint8_t size)
143
149
{
0 commit comments