1 /*********************************************************************
2 * SEGGER Microcontroller GmbH *
3 * The Embedded Experts *
4 **********************************************************************
5 * *
6 * (c) 1995 - 2019 SEGGER Microcontroller GmbH *
7 * *
8 * www.segger.com Support: [email protected] *
9 * *
10 **********************************************************************
11 * *
12 * SEGGER RTT * Real Time Transfer for embedded targets *
13 * *
14 **********************************************************************
15 * *
16 * All rights reserved. *
17 * *
18 * SEGGER strongly recommends to not make any changes *
19 * to or modify the source code of this software in order to stay *
20 * compatible with the RTT protocol and J-Link. *
21 * *
22 * Redistribution and use in source and binary forms, with or *
23 * without modification, are permitted provided that the following *
24 * condition is met: *
25 * *
26 * o Redistributions of source code must retain the above copyright *
27 * notice, this condition and the following disclaimer. *
28 * *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
30 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
31 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
32 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
33 * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
34 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
36 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
37 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
38 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
40 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
41 * DAMAGE. *
42 * *
43 **********************************************************************
44 ---------------------------END-OF-HEADER------------------------------
45 File : SEGGER_RTT_Syscalls_GCC.c
46 Purpose : Low-level functions for using printf() via RTT in GCC.
47 To use RTT for printf output, include this file in your
48 application.
49 Revision: $Rev: 24316 $
50 ----------------------------------------------------------------------
51 */
52 #if (defined __GNUC__) && !(defined __SES_ARM) && !(defined __CROSSWORKS_ARM) && !(defined __ARMCC_VERSION) && !(defined __CC_ARM)
53
54 #include "btstack_config.h"
55 #ifdef ENABLE_SEGGER_RTT
56
57 #include <reent.h> // required for _write_r
58 #include "SEGGER_RTT.h"
59
60
61 /*********************************************************************
62 *
63 * Types
64 *
65 **********************************************************************
66 */
67 //
68 // If necessary define the _reent struct
69 // to match the one passed by the used standard library.
70 //
71 struct _reent;
72
73 /*********************************************************************
74 *
75 * Function prototypes
76 *
77 **********************************************************************
78 */
79 _ssize_t _write (int file, const void *ptr, size_t len);
80 _ssize_t _write_r(struct _reent *r, int file, const void *ptr, size_t len);
81
82 /*********************************************************************
83 *
84 * Global functions
85 *
86 **********************************************************************
87 */
88
89 /*********************************************************************
90 *
91 * _write()
92 *
93 * Function description
94 * Low-level write function.
95 * libc subroutines will use this system routine for output to all files,
96 * including stdout.
97 * Write data via RTT.
98 */
_write(int file,const void * ptr,size_t len)99 _ssize_t __attribute__((weak)) _write(int file, const void *ptr, size_t len) {
100 (void) file; /* Not used, avoid warning */
101 SEGGER_RTT_Write(0, ptr, len);
102 return len;
103 }
104
105 /*********************************************************************
106 *
107 * _write_r()
108 *
109 * Function description
110 * Low-level reentrant write function.
111 * libc subroutines will use this system routine for output to all files,
112 * including stdout.
113 * Write data via RTT.
114 */
_write_r(struct _reent * r,int file,const void * ptr,size_t len)115 _ssize_t __attribute__((weak)) _write_r(struct _reent *r, int file, const void *ptr, size_t len) {
116 (void) file; /* Not used, avoid warning */
117 (void) r; /* Not used, avoid warning */
118 SEGGER_RTT_Write(0, ptr, len);
119 return len;
120 }
121
122 #endif
123 #endif
124 /****** End Of File *************************************************/
125