|
|
@@ -33,11 +33,13 @@
|
|
|
#include <rt_sys.h>
|
|
|
#else
|
|
|
#define GCCCOMPILER
|
|
|
+#if !defined(__ICCARM__)
|
|
|
struct __FILE {int handle;};
|
|
|
FILE __stdout;
|
|
|
FILE __stdin;
|
|
|
FILE __stderr;
|
|
|
#endif
|
|
|
+#endif
|
|
|
|
|
|
#include "ARMCM0.h"
|
|
|
|
|
|
@@ -90,8 +92,12 @@ void SystemInit (void)
|
|
|
#if 1
|
|
|
int stdout_putchar(char txchar)
|
|
|
{
|
|
|
- SERIAL_DATA = txchar;
|
|
|
- return(txchar);
|
|
|
+#if defined(__ICCARM__)
|
|
|
+ putchar(txchar);
|
|
|
+#else
|
|
|
+ SERIAL_DATA = txchar;
|
|
|
+#endif
|
|
|
+ return(txchar);
|
|
|
}
|
|
|
|
|
|
int stderr_putchar(char txchar)
|
|
|
@@ -112,21 +118,22 @@ __asm(".global __ARM_use_no_argv\n\t");
|
|
|
#endif
|
|
|
|
|
|
|
|
|
+#if !defined(__ICCARM__)
|
|
|
/**
|
|
|
Writes the character specified by c (converted to an unsigned char) to
|
|
|
the output stream pointed to by stream, at the position indicated by the
|
|
|
associated file position indicator (if defined), and advances the
|
|
|
indicator appropriately. If the file position indicator is not defined,
|
|
|
the character is appended to the output stream.
|
|
|
-
|
|
|
+
|
|
|
\param[in] c Character
|
|
|
\param[in] stream Stream handle
|
|
|
-
|
|
|
+
|
|
|
\return The character written. If a write error occurs, the error
|
|
|
indicator is set and fputc returns EOF.
|
|
|
*/
|
|
|
__attribute__((weak))
|
|
|
-int fputc (int c, FILE * stream)
|
|
|
+int fputc (int c, FILE * stream)
|
|
|
{
|
|
|
if (stream == &__stdout) {
|
|
|
return (stdout_putchar(c));
|
|
|
@@ -138,6 +145,7 @@ int fputc (int c, FILE * stream)
|
|
|
|
|
|
return (-1);
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
#ifndef GCCCOMPILER
|
|
|
/* IO device file handles. */
|
|
|
@@ -154,17 +162,17 @@ const char __stderr_name[] = ":STDERR";
|
|
|
#define RTE_Compiler_IO_STDERR 1
|
|
|
/**
|
|
|
Defined in rt_sys.h, this function opens a file.
|
|
|
-
|
|
|
+
|
|
|
The _sys_open() function is required by fopen() and freopen(). These
|
|
|
functions in turn are required if any file input/output function is to
|
|
|
be used.
|
|
|
The openmode parameter is a bitmap whose bits mostly correspond directly to
|
|
|
the ISO mode specification. Target-dependent extensions are possible, but
|
|
|
freopen() must also be extended.
|
|
|
-
|
|
|
+
|
|
|
\param[in] name File name
|
|
|
\param[in] openmode Mode specification bitmap
|
|
|
-
|
|
|
+
|
|
|
\return The return value is ?1 if an error occurs.
|
|
|
*/
|
|
|
#ifdef RETARGET_SYS
|
|
|
@@ -173,11 +181,11 @@ FILEHANDLE _sys_open (const char *name, int openmode) {
|
|
|
#if (!defined(RTE_Compiler_IO_File))
|
|
|
(void)openmode;
|
|
|
#endif
|
|
|
-
|
|
|
+
|
|
|
if (name == NULL) {
|
|
|
return (-1);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (name[0] == ':') {
|
|
|
if (strcmp(name, ":STDIN") == 0) {
|
|
|
return (FH_STDIN);
|
|
|
@@ -190,7 +198,7 @@ FILEHANDLE _sys_open (const char *name, int openmode) {
|
|
|
}
|
|
|
return (-1);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
#ifdef RTE_Compiler_IO_File
|
|
|
#ifdef RTE_Compiler_IO_File_FS
|
|
|
return (__sys_open(name, openmode));
|
|
|
@@ -200,23 +208,23 @@ FILEHANDLE _sys_open (const char *name, int openmode) {
|
|
|
#endif
|
|
|
}
|
|
|
#endif
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
Defined in rt_sys.h, this function closes a file previously opened
|
|
|
with _sys_open().
|
|
|
-
|
|
|
+
|
|
|
This function must be defined if any input/output function is to be used.
|
|
|
-
|
|
|
+
|
|
|
\param[in] fh File handle
|
|
|
-
|
|
|
+
|
|
|
\return The return value is 0 if successful. A nonzero value indicates
|
|
|
an error.
|
|
|
*/
|
|
|
#ifdef RETARGET_SYS
|
|
|
__attribute__((weak))
|
|
|
int _sys_close (FILEHANDLE fh) {
|
|
|
-
|
|
|
+
|
|
|
switch (fh) {
|
|
|
case FH_STDIN:
|
|
|
return (0);
|
|
|
@@ -225,7 +233,7 @@ int _sys_close (FILEHANDLE fh) {
|
|
|
case FH_STDERR:
|
|
|
return (0);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
#ifdef RTE_Compiler_IO_File
|
|
|
#ifdef RTE_Compiler_IO_File_FS
|
|
|
return (__sys_close(fh));
|
|
|
@@ -235,20 +243,20 @@ int _sys_close (FILEHANDLE fh) {
|
|
|
#endif
|
|
|
}
|
|
|
#endif
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
Defined in rt_sys.h, this function writes the contents of a buffer to a file
|
|
|
previously opened with _sys_open().
|
|
|
-
|
|
|
+
|
|
|
\note The mode parameter is here for historical reasons. It contains
|
|
|
nothing useful and must be ignored.
|
|
|
-
|
|
|
+
|
|
|
\param[in] fh File handle
|
|
|
\param[in] buf Data buffer
|
|
|
\param[in] len Data length
|
|
|
\param[in] mode Ignore this parameter
|
|
|
-
|
|
|
+
|
|
|
\return The return value is either:
|
|
|
- a positive number representing the number of characters not
|
|
|
written (so any nonzero return value denotes a failure of
|
|
|
@@ -265,7 +273,7 @@ int _sys_write (FILEHANDLE fh, const uint8_t *buf, uint32_t len, int mode) {
|
|
|
(void)len;
|
|
|
#endif
|
|
|
(void)mode;
|
|
|
-
|
|
|
+
|
|
|
switch (fh) {
|
|
|
case FH_STDIN:
|
|
|
return (-1);
|
|
|
@@ -288,7 +296,7 @@ int _sys_write (FILEHANDLE fh, const uint8_t *buf, uint32_t len, int mode) {
|
|
|
#endif
|
|
|
return (0);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
#ifdef RTE_Compiler_IO_File
|
|
|
#ifdef RTE_Compiler_IO_File_FS
|
|
|
return (__sys_write(fh, buf, len));
|
|
|
@@ -298,11 +306,11 @@ int _sys_write (FILEHANDLE fh, const uint8_t *buf, uint32_t len, int mode) {
|
|
|
#endif
|
|
|
}
|
|
|
#endif
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
Defined in rt_sys.h, this function reads the contents of a file into a buffer.
|
|
|
-
|
|
|
+
|
|
|
Reading up to and including the last byte of data does not turn on the EOF
|
|
|
indicator. The EOF indicator is only reached when an attempt is made to read
|
|
|
beyond the last byte of data. The target-independent code is capable of
|
|
|
@@ -311,15 +319,15 @@ int _sys_write (FILEHANDLE fh, const uint8_t *buf, uint32_t len, int mode) {
|
|
|
of data that precede the EOF
|
|
|
- the EOF indicator being returned on its own after the remaining bytes of
|
|
|
data have been returned in a previous read.
|
|
|
-
|
|
|
+
|
|
|
\note The mode parameter is here for historical reasons. It contains
|
|
|
nothing useful and must be ignored.
|
|
|
-
|
|
|
+
|
|
|
\param[in] fh File handle
|
|
|
\param[in] buf Data buffer
|
|
|
\param[in] len Data length
|
|
|
\param[in] mode Ignore this parameter
|
|
|
-
|
|
|
+
|
|
|
\return The return value is one of the following:
|
|
|
- The number of bytes not read (that is, len - result number of
|
|
|
bytes were read).
|
|
|
@@ -337,7 +345,7 @@ int _sys_read (FILEHANDLE fh, uint8_t *buf, uint32_t len, int mode) {
|
|
|
(void)len;
|
|
|
#endif
|
|
|
(void)mode;
|
|
|
-
|
|
|
+
|
|
|
switch (fh) {
|
|
|
case FH_STDIN:
|
|
|
#ifdef RTE_Compiler_IO_STDIN
|
|
|
@@ -359,7 +367,7 @@ int _sys_read (FILEHANDLE fh, uint8_t *buf, uint32_t len, int mode) {
|
|
|
case FH_STDERR:
|
|
|
return (-1);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
#ifdef RTE_Compiler_IO_File
|
|
|
#ifdef RTE_Compiler_IO_File_FS
|
|
|
return (__sys_read(fh, buf, len));
|
|
|
@@ -369,21 +377,21 @@ int _sys_read (FILEHANDLE fh, uint8_t *buf, uint32_t len, int mode) {
|
|
|
#endif
|
|
|
}
|
|
|
#endif
|
|
|
-
|
|
|
-
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
Defined in rt_sys.h, this function determines if a file handle identifies
|
|
|
a terminal.
|
|
|
-
|
|
|
+
|
|
|
When a file is connected to a terminal device, this function is used to
|
|
|
provide unbuffered behavior by default (in the absence of a call to
|
|
|
set(v)buf) and to prohibit seeking.
|
|
|
-
|
|
|
+
|
|
|
\param[in] fh File handle
|
|
|
-
|
|
|
+
|
|
|
\return The return value is one of the following values:
|
|
|
- 0: There is no interactive device.
|
|
|
- 1: There is an interactive device.
|
|
|
@@ -392,7 +400,7 @@ int _sys_read (FILEHANDLE fh, uint8_t *buf, uint32_t len, int mode) {
|
|
|
#ifdef RETARGET_SYS
|
|
|
__attribute__((weak))
|
|
|
int _sys_istty (FILEHANDLE fh) {
|
|
|
-
|
|
|
+
|
|
|
switch (fh) {
|
|
|
case FH_STDIN:
|
|
|
return (1);
|
|
|
@@ -401,22 +409,22 @@ int _sys_istty (FILEHANDLE fh) {
|
|
|
case FH_STDERR:
|
|
|
return (1);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return (0);
|
|
|
}
|
|
|
#endif
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
Defined in rt_sys.h, this function puts the file pointer at offset pos from
|
|
|
the beginning of the file.
|
|
|
-
|
|
|
+
|
|
|
This function sets the current read or write position to the new location pos
|
|
|
relative to the start of the current file fh.
|
|
|
-
|
|
|
+
|
|
|
\param[in] fh File handle
|
|
|
\param[in] pos File pointer offset
|
|
|
-
|
|
|
+
|
|
|
\return The result is:
|
|
|
- non-negative if no error occurs
|
|
|
- negative if an error occurs
|
|
|
@@ -427,7 +435,7 @@ int _sys_seek (FILEHANDLE fh, long pos) {
|
|
|
#if (!defined(RTE_Compiler_IO_File))
|
|
|
(void)pos;
|
|
|
#endif
|
|
|
-
|
|
|
+
|
|
|
switch (fh) {
|
|
|
case FH_STDIN:
|
|
|
return (-1);
|
|
|
@@ -436,7 +444,7 @@ int _sys_seek (FILEHANDLE fh, long pos) {
|
|
|
case FH_STDERR:
|
|
|
return (-1);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
#ifdef RTE_Compiler_IO_File
|
|
|
#ifdef RTE_Compiler_IO_File_FS
|
|
|
return (__sys_seek(fh, (uint32_t)pos));
|
|
|
@@ -446,27 +454,27 @@ int _sys_seek (FILEHANDLE fh, long pos) {
|
|
|
#endif
|
|
|
}
|
|
|
#endif
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
Defined in rt_sys.h, this function returns the current length of a file.
|
|
|
-
|
|
|
+
|
|
|
This function is used by _sys_seek() to convert an offset relative to the
|
|
|
end of a file into an offset relative to the beginning of the file.
|
|
|
You do not have to define _sys_flen() if you do not intend to use fseek().
|
|
|
If you retarget at system _sys_*() level, you must supply _sys_flen(),
|
|
|
even if the underlying system directly supports seeking relative to the
|
|
|
end of a file.
|
|
|
-
|
|
|
+
|
|
|
\param[in] fh File handle
|
|
|
-
|
|
|
+
|
|
|
\return This function returns the current length of the file fh,
|
|
|
or a negative error indicator.
|
|
|
*/
|
|
|
#ifdef RETARGET_SYS
|
|
|
__attribute__((weak))
|
|
|
long _sys_flen (FILEHANDLE fh) {
|
|
|
-
|
|
|
+
|
|
|
switch (fh) {
|
|
|
case FH_STDIN:
|
|
|
return (0);
|
|
|
@@ -475,7 +483,7 @@ long _sys_flen (FILEHANDLE fh) {
|
|
|
case FH_STDERR:
|
|
|
return (0);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
#ifdef RTE_Compiler_IO_File
|
|
|
#ifdef RTE_Compiler_IO_File_FS
|
|
|
return (__sys_flen(fh));
|
|
|
@@ -493,7 +501,7 @@ int _write(int file,
|
|
|
{
|
|
|
int i;
|
|
|
(void)file;
|
|
|
-
|
|
|
+
|
|
|
for(i=0; i < len;i++)
|
|
|
{
|
|
|
stdout_putchar(*ptr++);
|
|
|
@@ -502,7 +510,7 @@ int _write(int file,
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
-
|
|
|
+
|
|
|
#define log_str(...) \
|
|
|
do { \
|
|
|
const char *pchSrc = __VA_ARGS__; \
|
|
|
@@ -532,13 +540,13 @@ void _sys_exit(int n)
|
|
|
stdout_putchar(4);
|
|
|
while(1);
|
|
|
}
|
|
|
-#endif
|
|
|
+#endif
|
|
|
|
|
|
extern void ttywrch (int ch);
|
|
|
__attribute__((weak))
|
|
|
-void _ttywrch (int ch)
|
|
|
+void _ttywrch (int ch)
|
|
|
{
|
|
|
ttywrch(ch);
|
|
|
}
|
|
|
|
|
|
-#endif
|
|
|
+#endif
|