retarget.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. #if !defined(NRF_LOG_USES_RTT) || NRF_LOG_USES_RTT != 1
  13. #if !defined(HAS_SIMPLE_UART_RETARGET)
  14. #include <stdio.h>
  15. #include <stdint.h>
  16. #include "app_uart.h"
  17. #include "nordic_common.h"
  18. #include "nrf_error.h"
  19. #if !defined(__ICCARM__)
  20. struct __FILE
  21. {
  22. int handle;
  23. };
  24. #endif
  25. FILE __stdout;
  26. FILE __stdin;
  27. #if defined(__CC_ARM) || defined(__ICCARM__)
  28. int fgetc(FILE * p_file)
  29. {
  30. uint8_t input;
  31. while (app_uart_get(&input) == NRF_ERROR_NOT_FOUND)
  32. {
  33. // No implementation needed.
  34. }
  35. return input;
  36. }
  37. int fputc(int ch, FILE * p_file)
  38. {
  39. UNUSED_PARAMETER(p_file);
  40. UNUSED_VARIABLE(app_uart_put((uint8_t)ch));
  41. return ch;
  42. }
  43. #elif defined(__GNUC__)
  44. int _write(int file, const char * p_char, int len)
  45. {
  46. int i;
  47. UNUSED_PARAMETER(file);
  48. for (i = 0; i < len; i++)
  49. {
  50. UNUSED_VARIABLE(app_uart_put(*p_char++));
  51. }
  52. return len;
  53. }
  54. int _read(int file, char * p_char, int len)
  55. {
  56. UNUSED_PARAMETER(file);
  57. while (app_uart_get((uint8_t *)p_char) == NRF_ERROR_NOT_FOUND)
  58. {
  59. // No implementation needed.
  60. }
  61. return 1;
  62. }
  63. #endif
  64. #if defined(__ICCARM__)
  65. __ATTRIBUTES size_t __write(int file, const unsigned char * p_char, size_t len)
  66. {
  67. int i;
  68. UNUSED_PARAMETER(file);
  69. for (i = 0; i < len; i++)
  70. {
  71. UNUSED_VARIABLE(app_uart_put(*p_char++));
  72. }
  73. return len;
  74. }
  75. #endif
  76. #endif // !defined(HAS_SIMPLE_UART_RETARGET)
  77. #endif // NRF_LOG_USES_RTT != 1