| [1] | 1 | /*********************************************************************
|
|---|
| 2 | * SEGGER Microcontroller GmbH *
|
|---|
| 3 | * The Embedded Experts *
|
|---|
| 4 | **********************************************************************
|
|---|
| 5 | * *
|
|---|
| 6 | * (c) 2014 - 2020 SEGGER Microcontroller GmbH *
|
|---|
| 7 | * *
|
|---|
| 8 | * www.segger.com Support: support@segger.com *
|
|---|
| 9 | * *
|
|---|
| 10 | **********************************************************************
|
|---|
| 11 | * *
|
|---|
| 12 | * All rights reserved. *
|
|---|
| 13 | * *
|
|---|
| 14 | * Redistribution and use in source and binary forms, with or *
|
|---|
| 15 | * without modification, are permitted provided that the following *
|
|---|
| 16 | * conditions are met: *
|
|---|
| 17 | * *
|
|---|
| 18 | * - Redistributions of source code must retain the above copyright *
|
|---|
| 19 | * notice, this list of conditions and the following disclaimer. *
|
|---|
| 20 | * *
|
|---|
| 21 | * - Neither the name of SEGGER Microcontroller GmbH *
|
|---|
| 22 | * nor the names of its contributors may be used to endorse or *
|
|---|
| 23 | * promote products derived from this software without specific *
|
|---|
| 24 | * prior written permission. *
|
|---|
| 25 | * *
|
|---|
| 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
|
|---|
| 27 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
|
|---|
| 28 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
|
|---|
| 29 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
|
|---|
| 30 | * DISCLAIMED. *
|
|---|
| 31 | * IN NO EVENT SHALL SEGGER Microcontroller GmbH BE LIABLE FOR *
|
|---|
| 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
|
|---|
| 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
|
|---|
| 34 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
|
|---|
| 35 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
|---|
| 36 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
|
|---|
| 37 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
|
|---|
| 38 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
|
|---|
| 39 | * DAMAGE. *
|
|---|
| 40 | * *
|
|---|
| 41 | **********************************************************************
|
|---|
| 42 | -------- END-OF-HEADER ---------------------------------------------
|
|---|
| 43 | File : SEGGER_RTT_Syscalls_SES.c
|
|---|
| 44 | Purpose : Reimplementation of printf, puts and
|
|---|
| 45 | implementation of __putchar and __getchar using RTT in SES.
|
|---|
| 46 | To use RTT for printf output, include this file in your
|
|---|
| 47 | application.
|
|---|
| 48 | ----------------------------------------------------------------------
|
|---|
| 49 | */
|
|---|
| 50 | #include "SEGGER_RTT.h"
|
|---|
| 51 | #include "__libc.h"
|
|---|
| 52 | #include <stdarg.h>
|
|---|
| 53 | #include <stdio.h>
|
|---|
| 54 |
|
|---|
| 55 | int printf(const char *fmt,...) {
|
|---|
| 56 | char buffer[128];
|
|---|
| 57 | va_list args;
|
|---|
| 58 | va_start (args, fmt);
|
|---|
| 59 | int n = vsnprintf(buffer, sizeof(buffer), fmt, args);
|
|---|
| 60 | SEGGER_RTT_Write(0, buffer, n);
|
|---|
| 61 | va_end(args);
|
|---|
| 62 | return n;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | int puts(const char *s) {
|
|---|
| 66 | return SEGGER_RTT_WriteString(0, s);
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | int __putchar(int x, __printf_tag_ptr ctx) {
|
|---|
| 70 | (void)ctx;
|
|---|
| 71 | SEGGER_RTT_Write(0, (char *)&x, 1);
|
|---|
| 72 | return x;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | int __getchar() {
|
|---|
| 76 | return SEGGER_RTT_WaitKey();
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | /****** End Of File *************************************************/
|
|---|