SEGGER_RTT_SES.c 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*********************************************************************
  2. * SEGGER MICROCONTROLLER GmbH & Co. KG *
  3. * Solutions for real time microcontroller applications *
  4. **********************************************************************
  5. * *
  6. * (c) 2014 - 2015 SEGGER Microcontroller GmbH & Co. KG *
  7. * *
  8. * www.segger.com Support: support@segger.com *
  9. * *
  10. **********************************************************************
  11. * *
  12. * All rights reserved. *
  13. * *
  14. * * This software may in its unmodified form be freely redistributed *
  15. * in source form. *
  16. * * The source code may be modified, provided the source code *
  17. * retains the above copyright notice, this list of conditions and *
  18. * the following disclaimer. *
  19. * * Modified versions of this software in source or linkable form *
  20. * may not be distributed without prior consent of SEGGER. *
  21. * * This software may only be used for communication with SEGGER *
  22. * J-Link debug probes. *
  23. * *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
  25. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
  26. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
  27. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
  28. * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
  29. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
  31. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
  32. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
  33. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
  34. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
  35. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
  36. * DAMAGE. *
  37. * *
  38. **********************************************************************
  39. -------- END-OF-HEADER ---------------------------------------------
  40. File : SEGGER_RTT_Syscalls_SES.c
  41. Purpose : Reimplementation of printf, puts and
  42. implementation of __putchar and __getchar using RTT in SES.
  43. To use RTT for printf output, include this file in your
  44. application.
  45. ----------------------------------------------------------------------
  46. */
  47. #include "SEGGER_RTT.h"
  48. #include "__libc.h"
  49. #include <stdarg.h>
  50. #include <stdio.h>
  51. int printf(const char *fmt,...) {
  52. char buffer[512];
  53. va_list args;
  54. va_start (args, fmt);
  55. int n = vsnprintf(buffer, sizeof(buffer), fmt, args);
  56. SEGGER_RTT_Write(0, buffer, n);
  57. va_end(args);
  58. return n;
  59. }
  60. int puts(const char *s) {
  61. return SEGGER_RTT_WriteString(0, s);
  62. }
  63. int __putchar(int x, __printf_tag_ptr ctx) {
  64. (void)ctx;
  65. SEGGER_RTT_Write(0, (char *)&x, 1);
  66. return x;
  67. }
  68. int __getchar() {
  69. return SEGGER_RTT_WaitKey();
  70. }
  71. /****** End Of File *************************************************/