-
Notifications
You must be signed in to change notification settings - Fork 0
/
Retarget.c
169 lines (136 loc) · 4.16 KB
/
Retarget.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*----------------------------------------------------------------------------
* R T L - F l a s h F i l e S y s t e m
*----------------------------------------------------------------------------
* Name: RETARGET.C
* Purpose: Retarget low level functions
* Rev.: V3.20
*----------------------------------------------------------------------------
* This code is part of the RealView Run-Time Library.
* Copyright (c) 2004-2008 KEIL - An ARM Company. All rights reserved.
*---------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <rt_misc.h>
#include <rt_sys.h>
#include <File_Config.h>
#pragma import(__use_no_semihosting_swi)
/* The following macro definitions may be used to translate this file:
STDIO - use standard Input/Output device
(default is NOT used)
*/
/* Standard IO device handles. */
#define STDIN 0x8001
#define STDOUT 0x8002
#define STDERR 0x8003
/* Standard IO device name defines. */
const char __stdin_name[] = "STDIN";
const char __stdout_name[] = "STDOUT";
const char __stderr_name[] = "STDERR";
struct __FILE { int handle; /* Add whatever you need here */ };
#ifdef STDIO
extern int sendchar (int ch);
extern int getkey (void);
#endif
/*--------------------------- _ttywrch --------------------------------------*/
void _ttywrch (int ch) {
#ifdef STDIO
sendchar(ch);
#endif
}
/*--------------------------- _sys_open -------------------------------------*/
FILEHANDLE _sys_open (const char *name, int openmode) {
/* Register standard Input Output devices. */
if (strcmp(name, "STDIN") == 0) {
return (STDIN);
}
if (strcmp(name, "STDOUT") == 0) {
return (STDOUT);
}
if (strcmp(name, "STDERR") == 0) {
return (STDERR);
}
return (__fopen (name, openmode));
}
/*--------------------------- _sys_close ------------------------------------*/
int _sys_close (FILEHANDLE fh) {
if (fh > 0x8000) {
return (0);
}
return (__fclose (fh));
}
/*--------------------------- _sys_write ------------------------------------*/
int _sys_write (FILEHANDLE fh, const U8 *buf, U32 len, int mode) {
#ifdef STDIO
if (fh == STDOUT) {
/* Standard Output device. */
for ( ; len; len--) {
sendchar (*buf++);
}
return (0);
}
#endif
if (fh > 0x8000) {
return (-1);
}
return (__write (fh, buf, len));
}
/*--------------------------- _sys_read -------------------------------------*/
int _sys_read (FILEHANDLE fh, U8 *buf, U32 len, int mode) {
#ifdef STDIO
if (fh == STDIN) {
/* Standard Input device. */
for ( ; len; len--) {
*buf++ = getkey ();
}
return (0);
}
#endif
if (fh > 0x8000) {
return (-1);
}
return (__read (fh, buf, len));
}
/*--------------------------- _sys_istty ------------------------------------*/
int _sys_istty (FILEHANDLE fh) {
if (fh > 0x8000) {
return (1);
}
return (0);
}
/*--------------------------- _sys_seek -------------------------------------*/
int _sys_seek (FILEHANDLE fh, long pos) {
if (fh > 0x8000) {
return (-1);
}
return (__setfpos (fh, pos));
}
/*--------------------------- _sys_ensure -----------------------------------*/
int _sys_ensure (FILEHANDLE fh) {
if (fh > 0x8000) {
return (-1);
}
return (__flushbuf (fh));
}
/*--------------------------- _sys_flen -------------------------------------*/
long _sys_flen (FILEHANDLE fh) {
if (fh > 0x8000) {
return (0);
}
return (__get_flen (fh));
}
/*--------------------------- _sys_tmpnam -----------------------------------*/
int _sys_tmpnam (char *name, int sig, unsigned maxlen) {
return (1);
}
/*--------------------------- _sys_command_string ---------------------------*/
char *_sys_command_string (char *cmd, int len) {
return (cmd);
}
/*--------------------------- _sys_exit -------------------------------------*/
void _sys_exit (int return_code) {
/* Endless loop. */
// while (1);
}
/*----------------------------------------------------------------------------
* end of file
*---------------------------------------------------------------------------*/