Skip to content
This repository was archived by the owner on Jun 23, 2024. It is now read-only.

Commit 824dbee

Browse files
committed
libtf: Allow outside code to override the default log handler.
1 parent 9bbf7a7 commit 824dbee

File tree

5 files changed

+7
-18
lines changed

5 files changed

+7
-18
lines changed

libtf.cc

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,9 @@
1414
#define LIBTF_MAX_OPS 80
1515

1616
extern "C" {
17-
// These are set by openmv py_tf.c code to redirect printing to an error message buffer...
18-
char *py_tf_putchar_buffer = NULL;
19-
size_t py_tf_putchar_buffer_index = 0;
20-
size_t py_tf_putchar_buffer_len = 0;
21-
22-
static void libtf_debug_log(const char *s) {
23-
for (size_t i = 0, j = strlen(s); i < j; i++) {
24-
if (py_tf_putchar_buffer_len) {
25-
py_tf_putchar_buffer[py_tf_putchar_buffer_index++] = s[i];
26-
py_tf_putchar_buffer_len--;
27-
} else {
28-
putchar(s[i]);
29-
}
30-
}
17+
// Default log handler.
18+
__attribute__((weak)) void libtf_log_handler(const char *s) {
19+
printf(s);
3120
}
3221

3322
static int libtf_align_tensor_arena(unsigned char **tensor_arena, size_t *tensor_arena_size) {
@@ -243,7 +232,7 @@ extern "C" {
243232
unsigned char *tensor_arena, size_t tensor_arena_size,
244233
libtf_parameters_t *params,
245234
libtf_resolver_init_t libtf_resolver_init) {
246-
RegisterDebugLogCallback(libtf_debug_log);
235+
RegisterDebugLogCallback(libtf_log_handler);
247236

248237
tflite::MicroErrorReporter micro_error_reporter;
249238
tflite::ErrorReporter *error_reporter = &micro_error_reporter;
@@ -410,7 +399,7 @@ extern "C" {
410399
libtf_output_data_callback_t output_callback,
411400
void *output_callback_data,
412401
libtf_resolver_init_t libtf_resolver_init) {
413-
RegisterDebugLogCallback(libtf_debug_log);
402+
RegisterDebugLogCallback(libtf_log_handler);
414403

415404
tflite::MicroErrorReporter micro_error_reporter;
416405
tflite::ErrorReporter *error_reporter = &micro_error_reporter;
@@ -486,7 +475,7 @@ extern "C" {
486475
}
487476

488477
int libtf_initialize_micro_features() {
489-
RegisterDebugLogCallback(libtf_debug_log);
478+
RegisterDebugLogCallback(libtf_log_handler);
490479

491480
tflite::MicroErrorReporter micro_error_reporter;
492481
tflite::ErrorReporter *error_reporter = &micro_error_reporter;
@@ -500,7 +489,7 @@ extern "C" {
500489

501490
int libtf_generate_micro_features(const int16_t *input, int input_size,
502491
int output_size, int8_t *output, size_t *num_samples_read) {
503-
RegisterDebugLogCallback(libtf_debug_log);
492+
RegisterDebugLogCallback(libtf_log_handler);
504493

505494
tflite::MicroErrorReporter micro_error_reporter;
506495
tflite::ErrorReporter *error_reporter = &micro_error_reporter;

libtf/cortex-m0plus/libtf.a

-638 Bytes
Binary file not shown.

libtf/cortex-m4/libtf.a

-634 Bytes
Binary file not shown.

libtf/cortex-m55/libtf.a

-638 Bytes
Binary file not shown.

libtf/cortex-m7/libtf.a

-638 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)