xref: /btstack/3rd-party/segger-rtt/SEGGER_RTT_Syscalls_GCC.c (revision 225f4ba4fe806afeda1ee8519bb5f4a8ce540af2)
1 /*********************************************************************
2 *               SEGGER MICROCONTROLLER GmbH & Co. KG                 *
3 *       Solutions for real time microcontroller applications         *
4 **********************************************************************
5 *                                                                    *
6 *       (c) 2014 - 2016  SEGGER Microcontroller GmbH & Co. KG        *
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 * conditions are met:                                                *
25 *                                                                    *
26 * o Redistributions of source code must retain the above copyright   *
27 *   notice, this list of conditions and the following disclaimer.    *
28 *                                                                    *
29 * o Redistributions in binary form must reproduce the above          *
30 *   copyright notice, this list of conditions and the following      *
31 *   disclaimer in the documentation and/or other materials provided  *
32 *   with the distribution.                                           *
33 *                                                                    *
34 * o Neither the name of SEGGER Microcontroller GmbH & Co. KG         *
35 *   nor the names of its contributors may be used to endorse or      *
36 *   promote products derived from this software without specific     *
37 *   prior written permission.                                        *
38 *                                                                    *
39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
40 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
41 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
43 * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
44 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
45 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
46 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
47 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
48 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
50 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
51 * DAMAGE.                                                            *
52 *                                                                    *
53 **********************************************************************
54 ---------------------------END-OF-HEADER------------------------------
55 File    : SEGGER_RTT_Syscalls_GCC.c
56 Purpose : Low-level functions for using printf() via RTT in GCC.
57           To use RTT for printf output, include this file in your
58           application.
59 Revision: $Rev: 4351 $
60 ----------------------------------------------------------------------
61 */
62 
63 #include "btstack_config.h"
64 
65 #ifdef ENABLE_SEGGER_RTT
66 
67 #if (defined __GNUC__) && !(defined __SES_ARM) && !(defined __CROSSWORKS_ARM)
68 
69 #include <reent.h>  // required for _write_r
70 #include "SEGGER_RTT.h"
71 
72 /*********************************************************************
73 *
74 *       Types
75 *
76 **********************************************************************
77 */
78 //
79 // If necessary define the _reent struct
80 // to match the one passed by the used standard library.
81 //
82 struct _reent;
83 
84 /*********************************************************************
85 *
86 *       Function prototypes
87 *
88 **********************************************************************
89 */
90 int _write(int file, char *ptr, int len);
91 _ssize_t _write_r(struct _reent *r, int file, const void *ptr, size_t len);
92 
93 /*********************************************************************
94 *
95 *       Global functions
96 *
97 **********************************************************************
98 */
99 
100 /*********************************************************************
101 *
102 *       _write()
103 *
104 * Function description
105 *   Low-level write function.
106 *   libc subroutines will use this system routine for output to all files,
107 *   including stdout.
108 *   Write data via RTT.
109 */
110 int _write(int file, char *ptr, int len) {
111   (void) file;  /* Not used, avoid warning */
112   SEGGER_RTT_Write(0, ptr, len);
113   return len;
114 }
115 
116 /*********************************************************************
117 *
118 *       _write_r()
119 *
120 * Function description
121 *   Low-level reentrant write function.
122 *   libc subroutines will use this system routine for output to all files,
123 *   including stdout.
124 *   Write data via RTT.
125 */
126 _ssize_t _write_r(struct _reent *r, int file, const void *ptr, size_t len) {
127   (void) file;  /* Not used, avoid warning */
128   (void) r;     /* Not used, avoid warning */
129   SEGGER_RTT_Write(0, ptr, len);
130   return len;
131 }
132 
133 #endif
134 
135 #endif
136 /****** End Of File *************************************************/
137