Skip to content

Commit e0cbc49

Browse files
committed
[tfkernel] remove test_over_serial in system_setup
1 parent 65f98cb commit e0cbc49

File tree

2 files changed

+4
-122
lines changed

2 files changed

+4
-122
lines changed

src/tensorflow/lite/micro/system_setup.cpp

Lines changed: 4 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,22 @@ limitations under the License.
2020
#include "tensorflow/lite/micro/debug_log.h"
2121

2222
#if defined(ARDUINO) && !defined(ARDUINO_ARDUINO_NANO33BLE)
23-
#define ARDUINO_EXCLUDE_CODE
23+
//#define ARDUINO_EXCLUDE_CODE
2424
#endif // defined(ARDUINO) && !defined(ARDUINO_ARDUINO_NANO33BLE)
2525

2626
#ifndef ARDUINO_EXCLUDE_CODE
2727

2828
#include "Arduino.h"
2929

30-
// The Arduino DUE uses a different object for the default serial port shown in
31-
// the monitor than most other models, so make sure we pick the right one. See
32-
// https://github.com/arduino/Arduino/issues/3088#issuecomment-406655244
33-
#if defined(__SAM3X8E__)
34-
#define DEBUG_SERIAL_OBJECT (SerialUSB)
35-
#else
3630
#define DEBUG_SERIAL_OBJECT (Serial)
37-
#endif
38-
39-
extern "C" void DebugLog(const char* s) { DEBUG_SERIAL_OBJECT.print(s); }
4031

4132
namespace tflite {
4233

43-
constexpr ulong kSerialMaxInitWait = 4000; // milliseconds
34+
constexpr unsigned long kSerialMaxInitWait = 4000; // milliseconds
4435

4536
void InitializeTarget() {
46-
DEBUG_SERIAL_OBJECT.begin(9600);
47-
ulong start_time = millis();
37+
DEBUG_SERIAL_OBJECT.begin();
38+
unsigned long start_time = millis();
4839
while (!DEBUG_SERIAL_OBJECT) {
4940
// allow for Arduino IDE Serial Monitor synchronization
5041
if (millis() - start_time > kSerialMaxInitWait) {
@@ -55,84 +46,4 @@ void InitializeTarget() {
5546

5647
} // namespace tflite
5748

58-
namespace test_over_serial {
59-
60-
// Change baud rate on default serial port
61-
void SerialChangeBaudRate(const int baud) {
62-
DEBUG_SERIAL_OBJECT.begin(baud);
63-
ulong start_time = millis();
64-
while (!DEBUG_SERIAL_OBJECT) {
65-
// allow for Arduino IDE Serial Monitor synchronization
66-
if (millis() - start_time > tflite::kSerialMaxInitWait) {
67-
break;
68-
}
69-
}
70-
}
71-
72-
class _RingBuffer : public RingBufferN<kSerialMaxInputLength + 1> {
73-
public:
74-
bool need_reset = false;
75-
};
76-
77-
static _RingBuffer _ring_buffer;
78-
79-
// SerialReadLine
80-
// Read a set of ASCII characters from the default
81-
// serial port. Data is read up to the first newline ('\\n') character.
82-
// This function uses an internal buffer which is automatically reset.
83-
// The buffer will not contain the newline character.
84-
// The buffer will be zero ('\\0') terminated.
85-
// The <timeout> value is in milliseconds. Any negative value means that
86-
// the wait for data will be forever.
87-
// Returns std::pair<size_t, char*>.
88-
// The first pair element is the number of characters in buffer not including
89-
// the newline character or zero terminator.
90-
// Returns {0, NULL} if the timeout occurs.
91-
std::pair<size_t, char*> SerialReadLine(int timeout) {
92-
if (_ring_buffer.need_reset) {
93-
_ring_buffer.need_reset = false;
94-
_ring_buffer.clear();
95-
}
96-
97-
ulong start_time = millis();
98-
99-
while (true) {
100-
int value = DEBUG_SERIAL_OBJECT.read();
101-
if (value >= 0) {
102-
if (value == '\n') {
103-
// read a newline character
104-
_ring_buffer.store_char('\0');
105-
_ring_buffer.need_reset = true;
106-
break;
107-
} else {
108-
// read other character
109-
_ring_buffer.store_char(value);
110-
if (_ring_buffer.availableForStore() == 1) {
111-
// buffer is full
112-
_ring_buffer.store_char('\0');
113-
_ring_buffer.need_reset = true;
114-
break;
115-
}
116-
}
117-
}
118-
if (timeout < 0) {
119-
// wait forever
120-
continue;
121-
} else if (millis() - start_time >= static_cast<ulong>(timeout)) {
122-
// timeout
123-
return std::make_pair(0UL, reinterpret_cast<char*>(NULL));
124-
}
125-
}
126-
127-
return std::make_pair(static_cast<size_t>(_ring_buffer.available() - 1),
128-
reinterpret_cast<char*>(_ring_buffer._aucBuffer));
129-
}
130-
131-
// SerialWrite
132-
// Write the ASCII characters in <buffer> to the default serial port.
133-
// The <buffer> must be zero terminated.
134-
void SerialWrite(const char* buffer) { DEBUG_SERIAL_OBJECT.print(buffer); }
135-
136-
} // namespace test_over_serial
137-
13849
#endif // ARDUINO_EXCLUDE_CODE

src/tensorflow/lite/micro/system_setup.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,4 @@ void InitializeTarget();
2727

2828
} // namespace tflite
2929

30-
namespace test_over_serial {
31-
32-
// computed for Arduino Nano 33 BLE Sense
33-
constexpr size_t kSerialMaxInputLength = (64);
34-
35-
// Change baud rate on default serial port
36-
void SerialChangeBaudRate(const int baud);
37-
38-
// SerialReadLine
39-
// Read a set of ASCII characters from the default
40-
// serial port. Data is read up to the first newline ('\\n') character.
41-
// This function uses an internal buffer which is automatically reset.
42-
// The buffer will not contain the newline character.
43-
// The buffer will be zero ('\\0') terminated.
44-
// The <timeout> value is in milliseconds. Any negative value means that
45-
// the wait for data will be forever.
46-
// Returns std::pair<size_t, char*>.
47-
// The first pair element is the number of characters in buffer not including
48-
// the newline character or zero terminator.
49-
// Returns {0, NULL} if the timeout occurs.
50-
std::pair<size_t, char*> SerialReadLine(int timeout);
51-
52-
// SerialWrite
53-
// Write the ASCII characters in <buffer> to the default serial port.
54-
// The <buffer> must be zero terminated.
55-
void SerialWrite(const char* buffer);
56-
57-
} // namespace test_over_serial
58-
5930
#endif // TENSORFLOW_LITE_MICRO_SYSTEM_SETUP_H_

0 commit comments

Comments
 (0)