board.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2018, hathach (tinyusb.org)
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. *
  24. */
  25. #include "board.h"
  26. #if defined(__MSP430__)
  27. #define sys_write write
  28. #define sys_read read
  29. #else
  30. #define sys_write _write
  31. #define sys_read _read
  32. #endif
  33. //--------------------------------------------------------------------+
  34. // newlib read()/write() retarget
  35. //--------------------------------------------------------------------+
  36. #if defined(LOGGER_RTT)
  37. // Logging with RTT
  38. // If using SES IDE, use the Syscalls/SEGGER_RTT_Syscalls_SES.c instead
  39. #if !(defined __SES_ARM) && !(defined __SES_RISCV) && !(defined __CROSSWORKS_ARM)
  40. #include "SEGGER_RTT.h"
  41. TU_ATTR_USED int sys_write (int fhdl, const void *buf, size_t count)
  42. {
  43. (void) fhdl;
  44. SEGGER_RTT_Write(0, (char*) buf, (int) count);
  45. return count;
  46. }
  47. TU_ATTR_USED int sys_read (int fhdl, char *buf, size_t count)
  48. {
  49. (void) fhdl;
  50. return SEGGER_RTT_Read(0, buf, count);
  51. }
  52. #endif
  53. #elif defined(LOGGER_SWO)
  54. // Logging with SWO for ARM Cortex
  55. #include "board_mcu.h"
  56. TU_ATTR_USED int sys_write (int fhdl, const void *buf, size_t count)
  57. {
  58. (void) fhdl;
  59. uint8_t const* buf8 = (uint8_t const*) buf;
  60. for(size_t i=0; i<count; i++)
  61. {
  62. ITM_SendChar(buf8[i]);
  63. }
  64. return count;
  65. }
  66. TU_ATTR_USED int sys_read (int fhdl, char *buf, size_t count)
  67. {
  68. (void) fhdl;
  69. return 0;
  70. }
  71. #else
  72. // Default logging with on-board UART
  73. TU_ATTR_USED int sys_write (int fhdl, const void *buf, size_t count)
  74. {
  75. (void) fhdl;
  76. return board_uart_write(buf, count);
  77. }
  78. TU_ATTR_USED int sys_read (int fhdl, char *buf, size_t count)
  79. {
  80. (void) fhdl;
  81. return board_uart_read((uint8_t*) buf, count);
  82. }
  83. #endif