Statistics
| Branch: | Tag: | Revision:

mongoose / examples / nRF52 / http / rtt / Syscalls / RTT_Syscalls_KEIL.c @ eaef5bd1

History | View | Annotate | Download (8.12 KB)

1
/* clang-format off */
2
/*********************************************************************
3
*               SEGGER MICROCONTROLLER GmbH & Co KG                  *
4
*       Solutions for real time microcontroller applications         *
5
**********************************************************************
6
*                                                                    *
7
*       (c) 2014  SEGGER Microcontroller GmbH & Co KG                *
8
*                                                                    *
9
*       www.segger.com     Support: support@segger.com               *
10
*                                                                    *
11
**********************************************************************
12

13
----------------------------------------------------------------------
14
File    : RTT_Syscalls_KEIL.c
15
Purpose : Retargeting module for KEIL MDK-CM3.
16
          Low-level functions for using printf() via RTT
17
--------- END-OF-HEADER --------------------------------------------*/
18

    
19
#include <stdio.h>
20
#include <stdlib.h>
21
#include <string.h>
22
#include <rt_sys.h>
23
#include <rt_misc.h>
24

    
25
#include "SEGGER_RTT.h"
26
/*********************************************************************
27
*
28
*       #pragmas
29
*
30
**********************************************************************
31
*/
32
#pragma import(__use_no_semihosting)
33

    
34
#ifdef _MICROLIB
35
  #pragma import(__use_full_stdio)
36
#endif
37

    
38
/*********************************************************************
39
*
40
*       Defines non-configurable
41
*
42
**********************************************************************
43
*/
44

    
45
/* Standard IO device handles - arbitrary, but any real file system handles must be
46
   less than 0x8000. */
47
#define STDIN             0x8001    // Standard Input Stream
48
#define STDOUT            0x8002    // Standard Output Stream
49
#define STDERR            0x8003    // Standard Error Stream
50

    
51
/*********************************************************************
52
*
53
*       Public const
54
*
55
**********************************************************************
56
*/
57
const char __stdin_name[]  = "STDIN";
58
const char __stdout_name[] = "STDOUT";
59
const char __stderr_name[] = "STDERR";
60

    
61
/*********************************************************************
62
*
63
*       Public code
64
*
65
**********************************************************************
66
*/
67

    
68
/*********************************************************************
69
*
70
*       _ttywrch
71
*
72
*  Function description:
73
*    Outputs a character to the console
74
*
75
*  Parameters:
76
*    c    - character to output
77
*  
78
*/
79
void _ttywrch(int c) {
80
  fputc(c, stdout); // stdout
81
  fflush(stdout);
82
}
83

    
84
/*********************************************************************
85
*
86
*       _sys_open
87
*
88
*  Function description:
89
*    Opens the device/file in order to do read/write operations
90
*
91
*  Parameters:
92
*    sName        - sName of the device/file to open
93
*    OpenMode    - This parameter is currently ignored
94
*  
95
*  Return value:
96
*    != 0     - Handle to the object to open, otherwise 
97
*    == 0     -"device" is not handled by this module
98
*
99
*/
100
FILEHANDLE _sys_open(const char * sName, int OpenMode) {
101
  // Register standard Input Output devices.
102
  if (strcmp(sName, __stdout_name) == 0) {
103
    return (STDOUT);
104
  } else if (strcmp(sName, __stderr_name) == 0) {
105
    return (STDERR);
106
  } else
107
  return (0);  // Not implemented
108
}
109

    
110
/*********************************************************************
111
*
112
*       _sys_close
113
*
114
*  Function description:
115
*    Closes the handle to the open device/file
116
*
117
*  Parameters:
118
*    hFile    - Handle to a file opened via _sys_open
119
*  
120
*  Return value:
121
*    0     - device/file closed
122
*
123
*/
124
int _sys_close(FILEHANDLE hFile) {
125
  return 0;  // Not implemented
126
}
127

    
128
/*********************************************************************
129
*
130
*       _sys_write
131
*
132
*  Function description:
133
*    Writes the data to an open handle.
134
*    Currently this function only outputs data to the console
135
*
136
*  Parameters:
137
*    hFile    - Handle to a file opened via _sys_open
138
*    pBuffer  - Pointer to the data that shall be written
139
*    NumBytes      - Number of bytes to write
140
*    Mode     - The Mode that shall be used
141
*  
142
*  Return value:
143
*    Number of bytes *not* written to the file/device
144
*
145
*/
146
int _sys_write(FILEHANDLE hFile, const unsigned char * pBuffer, unsigned NumBytes, int Mode) {
147
  int r = 0;
148

    
149
  if (hFile == STDOUT) {
150
    return NumBytes - SEGGER_RTT_Write(0, (const char*)pBuffer, NumBytes);
151
  }
152
  return r;
153
}
154

    
155
/*********************************************************************
156
*
157
*       _sys_read
158
*
159
*  Function description:
160
*    Reads data from an open handle.
161
*    Currently this modules does nothing.
162
*
163
*  Parameters:
164
*    hFile    - Handle to a file opened via _sys_open
165
*    pBuffer  - Pointer to buffer to store the read data
166
*    NumBytes      - Number of bytes to read
167
*    Mode     - The Mode that shall be used
168
*  
169
*  Return value:
170
*    Number of bytes read from the file/device
171
*
172
*/
173
int _sys_read(FILEHANDLE hFile, unsigned char * pBuffer, unsigned NumBytes, int Mode) {
174
  return (0);  // Not implemented
175
}
176

    
177
/*********************************************************************
178
*
179
*       _sys_istty
180
*
181
*  Function description:
182
*    This function shall return whether the opened file 
183
*    is a console device or not.
184
*
185
*  Parameters:
186
*    hFile    - Handle to a file opened via _sys_open
187
*  
188
*  Return value:
189
*    1       - Device is     a console
190
*    0       - Device is not a console
191
*
192
*/
193
int _sys_istty(FILEHANDLE hFile) {
194
  if (hFile > 0x8000) {
195
    return (1);
196
  }
197
  return (0);  // Not implemented
198
}
199

    
200
/*********************************************************************
201
*
202
*       _sys_seek
203
*
204
*  Function description:
205
*    Seeks via the file to a specific position
206
*
207
*  Parameters:
208
*    hFile  - Handle to a file opened via _sys_open
209
*    Pos    - 
210
*  
211
*  Return value:
212
*    int       - 
213
*
214
*/
215
int _sys_seek(FILEHANDLE hFile, long Pos) {
216
  return (0);  // Not implemented
217
}
218

    
219
/*********************************************************************
220
*
221
*       _sys_ensure
222
*
223
*  Function description:
224
*    
225
*
226
*  Parameters:
227
*    hFile    - Handle to a file opened via _sys_open
228
*  
229
*  Return value:
230
*    int       - 
231
*
232
*/
233
int _sys_ensure(FILEHANDLE hFile) {
234
  return (-1);  // Not implemented
235
}
236

    
237
/*********************************************************************
238
*
239
*       _sys_flen
240
*
241
*  Function description:
242
*    Returns the length of the opened file handle
243
*
244
*  Parameters:
245
*    hFile    - Handle to a file opened via _sys_open
246
*  
247
*  Return value:
248
*    Length of the file
249
*
250
*/
251
long _sys_flen(FILEHANDLE hFile) {
252
  return (0);  // Not implemented
253
}
254

    
255
/*********************************************************************
256
*
257
*       _sys_tmpnam
258
*
259
*  Function description:
260
*    This function converts the file number fileno for a temporary 
261
*    file to a unique filename, for example, tmp0001.
262
*
263
*  Parameters:
264
*    pBuffer    - Pointer to a buffer to store the name
265
*    FileNum    - file number to convert
266
*    MaxLen     - Size of the buffer
267
*  
268
*  Return value:
269
*     1 - Error
270
*     0 - Success  
271
*
272
*/
273
int _sys_tmpnam(char * pBuffer, int FileNum, unsigned MaxLen) {
274
  return (1);  // Not implemented
275
}
276

    
277
/*********************************************************************
278
*
279
*       _sys_command_string
280
*
281
*  Function description:
282
*    This function shall execute a system command.
283
*
284
*  Parameters:
285
*    cmd    - Pointer to the command string
286
*    len    - Length of the string
287
*  
288
*  Return value:
289
*    == NULL - Command was not successfully executed
290
*    == sCmd - Command was passed successfully
291
*
292
*/
293
char * _sys_command_string(char * cmd, int len) {
294
  return cmd;  // Not implemented
295
}
296

    
297
/*********************************************************************
298
*
299
*       _sys_exit
300
*
301
*  Function description:
302
*    This function is called when the application returns from main
303
*
304
*  Parameters:
305
*    ReturnCode    - Return code from the main function
306
*  
307
*
308
*/
309
void _sys_exit(int ReturnCode) {
310
  while (1);  // Not implemented
311
}