debug_log.cc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. ==============================================================================*/
  12. // Reference implementation of the DebugLog() function that's required for a
  13. // platform to support the TensorFlow Lite for Microcontrollers library. This is
  14. // the only function that's absolutely required to be available on a target
  15. // device, since it's used for communicating test results back to the host so
  16. // that we can verify the implementation is working correctly.
  17. // It's designed to be as easy as possible to supply an implementation though.
  18. // On platforms that have a POSIX stack or C library, it can be written as a
  19. // single call to `fprintf(stderr, "%s", s)` to output a string to the error
  20. // stream of the console, but if there's no OS or C library available, there's
  21. // almost always an equivalent way to write out a string to some serial
  22. // interface that can be used instead. For example on Arm M-series MCUs, calling
  23. // the `bkpt #0xAB` assembler instruction will output the string in r1 to
  24. // whatever debug serial connection is available. If you're running mbed, you
  25. // can do the same by creating `Serial pc(USBTX, USBRX)` and then calling
  26. // `pc.printf("%s", s)`.
  27. // To add an equivalent function for your own platform, create your own
  28. // implementation file, and place it in a subfolder with named after the OS
  29. // you're targeting. For example, see the Cortex M bare metal version in
  30. // tensorflow/lite/micro/bluepill/debug_log.cc or the mbed one on
  31. // tensorflow/lite/micro/mbed/debug_log.cc.
  32. #include "tensorflow/lite/micro/debug_log.h"
  33. #include <rtthread.h>
  34. #include <rtdevice.h>
  35. #include <board.h>
  36. extern "C" void DebugLog(const char* s) { rt_kprintf("%s", s); }