SerialWireOutput.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* mbed Microcontroller Library
  2. * Copyright (c) 2017 ARM Limited
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #if defined(DEVICE_ITM)
  17. #include "hal/itm_api.h"
  18. #include "platform/FileHandle.h"
  19. namespace mbed {
  20. class SerialWireOutput : public FileHandle {
  21. public:
  22. SerialWireOutput(void)
  23. {
  24. /* Initialize ITM using internal init function. */
  25. mbed_itm_init();
  26. }
  27. virtual ssize_t write(const void *buffer, size_t size)
  28. {
  29. mbed_itm_send_block(ITM_PORT_SWO, buffer, size);
  30. return size;
  31. }
  32. virtual ssize_t read(void *buffer, size_t size)
  33. {
  34. /* Reading is not supported by this file handle */
  35. return -EBADF;
  36. }
  37. virtual off_t seek(off_t offset, int whence = SEEK_SET)
  38. {
  39. /* Seeking is not support by this file handler */
  40. return -ESPIPE;
  41. }
  42. virtual off_t size()
  43. {
  44. /* Size is not defined for this file handle */
  45. return -EINVAL;
  46. }
  47. virtual int isatty()
  48. {
  49. /* File handle is used for terminal output */
  50. return true;
  51. }
  52. virtual int close()
  53. {
  54. return 0;
  55. }
  56. };
  57. } // namespace mbed
  58. #endif