MyLibs 1.0
Расширенные библиотеки для STM32
Loading...
Searching...
No Matches
SEGGER_RTT_Syscalls_KEIL.c
1/*********************************************************************
2* SEGGER Microcontroller GmbH *
3* The Embedded Experts *
4**********************************************************************
5* *
6* (c) 1995 - 2021 SEGGER Microcontroller GmbH *
7* *
8* www.segger.com Support: support@segger.com *
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* *
45* RTT version: 7.54 *
46* *
47**********************************************************************
48
49---------------------------END-OF-HEADER------------------------------
50File : RTT_Syscalls_KEIL.c
51Purpose : Retargeting module for KEIL MDK-CM3.
52 Low-level functions for using printf() via RTT
53Revision: $Rev: 24316 $
54Notes : (1) https://wiki.segger.com/Keil_MDK-ARM#RTT_in_uVision
55----------------------------------------------------------------------
56*/
57#if (defined __CC_ARM) || (defined __ARMCC_VERSION)
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62#include <rt_sys.h>
63#include <rt_misc.h>
64
65#include "SEGGER_RTT.h"
66/*********************************************************************
67*
68* #pragmas
69*
70**********************************************************************
71*/
72#if __ARMCC_VERSION < 6000000
73#pragma import(__use_no_semihosting)
74#endif
75
76#ifdef _MICROLIB
77 #pragma import(__use_full_stdio)
78#endif
79
80/*********************************************************************
81*
82* Defines non-configurable
83*
84**********************************************************************
85*/
86
87/* Standard IO device handles - arbitrary, but any real file system handles must be
88 less than 0x8000. */
89#define STDIN 0x8001 // Standard Input Stream
90#define STDOUT 0x8002 // Standard Output Stream
91#define STDERR 0x8003 // Standard Error Stream
92
93/*********************************************************************
94*
95* Public const
96*
97**********************************************************************
98*/
99#if __ARMCC_VERSION < 5000000
100//const char __stdin_name[] = "STDIN";
101const char __stdout_name[] = "STDOUT";
102const char __stderr_name[] = "STDERR";
103#endif
104
105/*********************************************************************
106*
107* Public code
108*
109**********************************************************************
110*/
111
112/*********************************************************************
113*
114* _ttywrch
115*
116* Function description:
117* Outputs a character to the console
118*
119* Parameters:
120* c - character to output
121*
122*/
123void _ttywrch(int c) {
124 fputc(c, stdout); // stdout
125 fflush(stdout);
126}
127
128/*********************************************************************
129*
130* _sys_open
131*
132* Function description:
133* Opens the device/file in order to do read/write operations
134*
135* Parameters:
136* sName - sName of the device/file to open
137* OpenMode - This parameter is currently ignored
138*
139* Return value:
140* != 0 - Handle to the object to open, otherwise
141* == 0 -"device" is not handled by this module
142*
143*/
144FILEHANDLE _sys_open(const char * sName, int OpenMode) {
145 (void)OpenMode;
146 // Register standard Input Output devices.
147 if (strcmp(sName, __stdout_name) == 0) {
148 return (STDOUT);
149 } else if (strcmp(sName, __stderr_name) == 0) {
150 return (STDERR);
151 } else
152 return (0); // Not implemented
153}
154
155/*********************************************************************
156*
157* _sys_close
158*
159* Function description:
160* Closes the handle to the open device/file
161*
162* Parameters:
163* hFile - Handle to a file opened via _sys_open
164*
165* Return value:
166* 0 - device/file closed
167*
168*/
169int _sys_close(FILEHANDLE hFile) {
170 (void)hFile;
171 return 0; // Not implemented
172}
173
174/*********************************************************************
175*
176* _sys_write
177*
178* Function description:
179* Writes the data to an open handle.
180* Currently this function only outputs data to the console
181*
182* Parameters:
183* hFile - Handle to a file opened via _sys_open
184* pBuffer - Pointer to the data that shall be written
185* NumBytes - Number of bytes to write
186* Mode - The Mode that shall be used
187*
188* Return value:
189* Number of bytes *not* written to the file/device
190*
191*/
192int _sys_write(FILEHANDLE hFile, const unsigned char * pBuffer, unsigned NumBytes, int Mode) {
193 int r = 0;
194
195 (void)Mode;
196 if (hFile == STDOUT) {
197 SEGGER_RTT_Write(0, (const char*)pBuffer, NumBytes);
198 return 0;
199 }
200 return r;
201}
202
203/*********************************************************************
204*
205* _sys_read
206*
207* Function description:
208* Reads data from an open handle.
209* Currently this modules does nothing.
210*
211* Parameters:
212* hFile - Handle to a file opened via _sys_open
213* pBuffer - Pointer to buffer to store the read data
214* NumBytes - Number of bytes to read
215* Mode - The Mode that shall be used
216*
217* Return value:
218* Number of bytes read from the file/device
219*
220*/
221int _sys_read(FILEHANDLE hFile, unsigned char * pBuffer, unsigned NumBytes, int Mode) {
222 (void)hFile;
223 (void)pBuffer;
224 (void)NumBytes;
225 (void)Mode;
226 return (0); // Not implemented
227}
228
229/*********************************************************************
230*
231* _sys_istty
232*
233* Function description:
234* This function shall return whether the opened file
235* is a console device or not.
236*
237* Parameters:
238* hFile - Handle to a file opened via _sys_open
239*
240* Return value:
241* 1 - Device is a console
242* 0 - Device is not a console
243*
244*/
245int _sys_istty(FILEHANDLE hFile) {
246 if (hFile > 0x8000) {
247 return (1);
248 }
249 return (0); // Not implemented
250}
251
252/*********************************************************************
253*
254* _sys_seek
255*
256* Function description:
257* Seeks via the file to a specific position
258*
259* Parameters:
260* hFile - Handle to a file opened via _sys_open
261* Pos -
262*
263* Return value:
264* int -
265*
266*/
267int _sys_seek(FILEHANDLE hFile, long Pos) {
268 (void)hFile;
269 (void)Pos;
270 return (0); // Not implemented
271}
272
273/*********************************************************************
274*
275* _sys_ensure
276*
277* Function description:
278*
279*
280* Parameters:
281* hFile - Handle to a file opened via _sys_open
282*
283* Return value:
284* int -
285*
286*/
287int _sys_ensure(FILEHANDLE hFile) {
288 (void)hFile;
289 return (-1); // Not implemented
290}
291
292/*********************************************************************
293*
294* _sys_flen
295*
296* Function description:
297* Returns the length of the opened file handle
298*
299* Parameters:
300* hFile - Handle to a file opened via _sys_open
301*
302* Return value:
303* Length of the file
304*
305*/
306long _sys_flen(FILEHANDLE hFile) {
307 (void)hFile;
308 return (0); // Not implemented
309}
310
311/*********************************************************************
312*
313* _sys_tmpnam
314*
315* Function description:
316* This function converts the file number fileno for a temporary
317* file to a unique filename, for example, tmp0001.
318*
319* Parameters:
320* pBuffer - Pointer to a buffer to store the name
321* FileNum - file number to convert
322* MaxLen - Size of the buffer
323*
324* Return value:
325* 1 - Error
326* 0 - Success
327*
328*/
329int _sys_tmpnam2(char * pBuffer, int FileNum, unsigned MaxLen) {
330 (void)pBuffer;
331 (void)FileNum;
332 (void)MaxLen;
333 return (1); // Not implemented
334}
335
336/*********************************************************************
337*
338* _sys_command_string
339*
340* Function description:
341* This function shall execute a system command.
342*
343* Parameters:
344* cmd - Pointer to the command string
345* len - Length of the string
346*
347* Return value:
348* == NULL - Command was not successfully executed
349* == sCmd - Command was passed successfully
350*
351*/
352char * _sys_command_string(char * cmd, int len) {
353 (void)len;
354 return cmd; // Not implemented
355}
356
357/*********************************************************************
358*
359* _sys_exit
360*
361* Function description:
362* This function is called when the application returns from main
363*
364* Parameters:
365* ReturnCode - Return code from the main function
366*
367*
368*/
369void _sys_exit(int ReturnCode) {
370 (void)ReturnCode;
371 while (1); // Not implemented
372}
373
374#if __ARMCC_VERSION >= 5000000
375/*********************************************************************
376*
377* stdout_putchar
378*
379* Function description:
380* Put a character to the stdout
381*
382* Parameters:
383* ch - Character to output
384*
385*
386*/
387int stdout_putchar(int ch) {
388 (void)ch;
389 return ch; // Not implemented
390}
391#endif
392
393#endif
394/*************************** End of file ****************************/