Ignore:
Timestamp:
Jul 13, 2020, 8:07:55 PM (4 years ago)
Author:
coas-nagasima
Message:

ntshellアプリはnewlibを使うよう変更し、syscallの実装部分と区別がつくよう更新。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/asp3_dcre/mbed/platform/mbed_retarget.h

    r439 r442  
     1/*
     2 * mbed Microcontroller Library
     3 * Copyright (c) 2006-2016 ARM Limited
     4 * SPDX-License-Identifier: Apache-2.0
     5 *
     6 * Licensed under the Apache License, Version 2.0 (the "License");
     7 * you may not use this file except in compliance with the License.
     8 * You may obtain a copy of the License at
     9 *
     10 *     http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 *
     18 */
     19
    120#ifndef RETARGET_H
    221#define RETARGET_H
     
    726#include <stdio.h>
    827#endif //__cplusplus
    9 
    10 #include <errno.h>
    11 #include <dirent.h>
    12 #include <fcntl.h>
    13 #include <sys/ioctl.h>
     28#include <stdint.h>
     29#include <stddef.h>
    1430#include <sys/types.h>
    1531#include <sys/stat.h>
    16 #include <sys/statvfs.h>
    17 #include <unistd.h>
    18 
    19 #ifdef __cplusplus
    20 namespace mbed {
    21 
    22 class FileHandle;
    23 class DirHandle;
    24 
    25 std::FILE *fdopen(FileHandle *fh, const char *mode);
    26 
    27 }
     32
     33/* Include logic for errno so we can get errno defined but not bring in error_t,
     34 * including errno here prevents an include later, which would redefine our
     35 * error codes
     36 */
     37#ifndef __error_t_defined
     38#define __error_t_defined 1
     39#include <errno.h>
     40#undef __error_t_defined
     41#else
     42#include <errno.h>
    2843#endif
    2944
     45/* We can get the following standard types from sys/types for gcc, but we
     46 * need to define the types ourselves for the other compilers that normally
     47 * target embedded systems */
     48typedef signed   int  ssize_t;  ///< Signed size type, usually encodes negative errors
     49typedef unsigned int  nfds_t;   ///< Number of file descriptors
     50typedef unsigned long long fsblkcnt_t;  ///< Count of file system blocks
     51#if defined(__ARMCC_VERSION) || !defined(__GNUC__)
     52typedef unsigned int  mode_t;   ///< Mode for opening files
     53typedef unsigned int  dev_t;    ///< Device ID type
     54typedef unsigned long ino_t;    ///< File serial number
     55typedef unsigned int  nlink_t;  ///< Number of links to a file
     56typedef unsigned int  uid_t;    ///< User ID
     57typedef unsigned int  gid_t;    ///< Group ID
     58#endif
     59
     60/* Flags for open() and fcntl(GETFL/SETFL)
     61 * At present, fcntl only supports reading and writing O_NONBLOCK
     62 */
     63#define O_RDONLY 0        ///< Open for reading
     64#define O_WRONLY 1        ///< Open for writing
     65#define O_RDWR   2        ///< Open for reading and writing
     66#define O_NONBLOCK 04000  ///< Non-blocking mode
     67#define O_APPEND   02000  ///< Set file offset to end of file prior to each write
     68#define O_CREAT    0100   ///< Create file if it does not exist
     69#define O_TRUNC    01000  ///< Truncate file to zero length
     70#define O_EXCL     0200   ///< Fail if file exists
     71#define O_BINARY   0      ///< Open file in binary mode
     72
     73#define O_ASYNC    020000
     74
     75#define O_ACCMODE   (O_RDONLY|O_WRONLY|O_RDWR)
     76
     77#define NAME_MAX 255    ///< Maximum size of a name in a file path
     78
     79#define STDIN_FILENO  0
     80#define STDOUT_FILENO 1
     81#define STDERR_FILENO 2
     82
     83#include <time.h>
     84
     85/** \addtogroup platform */
     86/** @{*/
     87/**
     88 * \defgroup platform_retarget Retarget functions
     89 * @{
     90 */
     91typedef struct Dir DIR;
     92
     93
     94/* The intent of this section is to unify the errno error values to match
     95 * the POSIX definitions for the GCC_ARM, ARMCC and IAR compilers. This is
     96 * necessary because the ARMCC/IAR errno.h, or sys/stat.h are missing some
     97 * symbol definitions used by the POSIX filesystem API to return errno codes.
     98 * Note also that ARMCC errno.h defines some symbol values differently from
     99 * the GCC_ARM/IAR/standard POSIX definitions. The definitions guard against
     100 * this and future changes by changing the symbol definition as shown below.
     101 */
     102#undef  EPERM
     103#define EPERM           1       /* Operation not permitted */
     104#undef  ENOENT
     105#define ENOENT          2       /* No such file or directory */
     106#undef  ESRCH
     107#define ESRCH           3       /* No such process */
     108#undef  EINTR
     109#define EINTR           4       /* Interrupted system call */
     110#undef  EIO
     111#define EIO             5       /* I/O error */
     112#undef  ENXIO
     113#define ENXIO           6       /* No such device or address */
     114#undef  E2BIG
     115#define E2BIG           7       /* Argument list too long */
     116#undef  ENOEXEC
     117#define ENOEXEC         8       /* Exec format error */
     118#undef  EBADF
     119#define EBADF           9       /* Bad file number */
     120#undef  ECHILD
     121#define ECHILD          10      /* No child processes */
     122#undef  EAGAIN
     123#define EAGAIN          11      /* Try again */
     124#undef  ENOMEM
     125#define ENOMEM          12      /* Out of memory */
     126#undef  EACCES
     127#define EACCES          13      /* Permission denied */
     128#undef  EFAULT
     129#define EFAULT          14      /* Bad address */
     130#undef  ENOTBLK
     131#define ENOTBLK         15      /* Block device required */
     132#undef  EBUSY
     133#define EBUSY           16      /* Device or resource busy */
     134#undef  EEXIST
     135#define EEXIST          17      /* File exists */
     136#undef  EXDEV
     137#define EXDEV           18      /* Cross-device link */
     138#undef  ENODEV
     139#define ENODEV          19      /* No such device */
     140#undef  ENOTDIR
     141#define ENOTDIR         20      /* Not a directory */
     142#undef  EISDIR
     143#define EISDIR          21      /* Is a directory */
     144#undef  EINVAL
     145#define EINVAL          22      /* Invalid argument */
     146#undef  ENFILE
     147#define ENFILE          23      /* File table overflow */
     148#undef  EMFILE
     149#define EMFILE          24      /* Too many open files */
     150#undef  ENOTTY
     151#define ENOTTY          25      /* Not a typewriter */
     152#undef  ETXTBSY
     153#define ETXTBSY         26      /* Text file busy */
     154#undef  EFBIG
     155#define EFBIG           27      /* File too large */
     156#undef  ENOSPC
     157#define ENOSPC          28      /* No space left on device */
     158#undef  ESPIPE
     159#define ESPIPE          29      /* Illegal seek */
     160#undef  EROFS
     161#define EROFS           30      /* Read-only file system */
     162#undef  EMLINK
     163#define EMLINK          31      /* Too many links */
     164#undef  EPIPE
     165#define EPIPE           32      /* Broken pipe */
     166#undef  EDOM
     167#define EDOM            33      /* Math argument out of domain of func */
     168#undef  ERANGE
     169#define ERANGE          34      /* Math result not representable */
     170#undef  EDEADLK
     171#define EDEADLK         35      /* Resource deadlock would occur */
     172#undef  ENAMETOOLONG
     173#define ENAMETOOLONG    36      /* File name too long */
     174#undef  ENOLCK
     175#define ENOLCK          37      /* No record locks available */
     176#undef  ENOSYS
     177#define ENOSYS          38      /* Function not implemented */
     178#undef  ENOTEMPTY
     179#define ENOTEMPTY       39      /* Directory not empty */
     180#undef  ELOOP
     181#define ELOOP           40      /* Too many symbolic links encountered */
     182#undef  EWOULDBLOCK
     183#define EWOULDBLOCK     EAGAIN  /* Operation would block */
     184#undef  ENOMSG
     185#define ENOMSG          42      /* No message of desired type */
     186#undef  EIDRM
     187#define EIDRM           43      /* Identifier removed */
     188#undef  ECHRNG
     189#define ECHRNG          44      /* Channel number out of range */
     190#undef  EL2NSYNC
     191#define EL2NSYNC        45      /* Level 2 not synchronized */
     192#undef  EL3HLT
     193#define EL3HLT          46      /* Level 3 halted */
     194#undef  EL3RST
     195#define EL3RST          47      /* Level 3 reset */
     196#undef  ELNRNG
     197#define ELNRNG          48      /* Link number out of range */
     198#undef  EUNATCH
     199#define EUNATCH         49      /* Protocol driver not attached */
     200#undef  ENOCSI
     201#define ENOCSI          50      /* No CSI structure available */
     202#undef  EL2HLT
     203#define EL2HLT          51      /* Level 2 halted */
     204#undef  EBADE
     205#define EBADE           52      /* Invalid exchange */
     206#undef  EBADR
     207#define EBADR           53      /* Invalid request descriptor */
     208#undef  EXFULL
     209#define EXFULL          54      /* Exchange full */
     210#undef  ENOANO
     211#define ENOANO          55      /* No anode */
     212#undef  EBADRQC
     213#define EBADRQC         56      /* Invalid request code */
     214#undef  EBADSLT
     215#define EBADSLT         57      /* Invalid slot */
     216#undef  EDEADLOCK
     217#define EDEADLOCK       EDEADLK /* Resource deadlock would occur */
     218#undef  EBFONT
     219#define EBFONT          59      /* Bad font file format */
     220#undef  ENOSTR
     221#define ENOSTR          60      /* Device not a stream */
     222#undef  ENODATA
     223#define ENODATA         61      /* No data available */
     224#undef  ETIME
     225#define ETIME           62      /* Timer expired */
     226#undef  ENOSR
     227#define ENOSR           63      /* Out of streams resources */
     228#undef  ENONET
     229#define ENONET          64      /* Machine is not on the network */
     230#undef  ENOPKG
     231#define ENOPKG          65      /* Package not installed */
     232#undef  EREMOTE
     233#define EREMOTE         66      /* Object is remote */
     234#undef  ENOLINK
     235#define ENOLINK         67      /* Link has been severed */
     236#undef  EADV
     237#define EADV            68      /* Advertise error */
     238#undef  ESRMNT
     239#define ESRMNT          69      /* Srmount error */
     240#undef  ECOMM
     241#define ECOMM           70      /* Communication error on send */
     242#undef  EPROTO
     243#define EPROTO          71      /* Protocol error */
     244#undef  EMULTIHOP
     245#define EMULTIHOP       72      /* Multihop attempted */
     246#undef  EDOTDOT
     247#define EDOTDOT         73      /* RFS specific error */
     248#undef  EBADMSG
     249#define EBADMSG         74      /* Not a data message */
     250#undef  EOVERFLOW
     251#define EOVERFLOW       75      /* Value too large for defined data type */
     252#undef  ENOTUNIQ
     253#define ENOTUNIQ        76      /* Name not unique on network */
     254#undef  EBADFD
     255#define EBADFD          77      /* File descriptor in bad state */
     256#undef  EREMCHG
     257#define EREMCHG         78      /* Remote address changed */
     258#undef  ELIBACC
     259#define ELIBACC         79      /* Can not access a needed shared library */
     260#undef  ELIBBAD
     261#define ELIBBAD         80      /* Accessing a corrupted shared library */
     262#undef  ELIBSCN
     263#define ELIBSCN         81      /* .lib section in a.out corrupted */
     264#undef  ELIBMAX
     265#define ELIBMAX         82      /* Attempting to link in too many shared libraries */
     266#undef  ELIBEXEC
     267#define ELIBEXEC        83      /* Cannot exec a shared library directly */
     268#undef  EILSEQ
     269#define EILSEQ          84      /* Illegal byte sequence */
     270#undef  ERESTART
     271#define ERESTART        85      /* Interrupted system call should be restarted */
     272#undef  ESTRPIPE
     273#define ESTRPIPE        86      /* Streams pipe error */
     274#undef  EUSERS
     275#define EUSERS          87      /* Too many users */
     276#undef  ENOTSOCK
     277#define ENOTSOCK        88      /* Socket operation on non-socket */
     278#undef  EDESTADDRREQ
     279#define EDESTADDRREQ    89      /* Destination address required */
     280#undef  EMSGSIZE
     281#define EMSGSIZE        90      /* Message too long */
     282#undef  EPROTOTYPE
     283#define EPROTOTYPE      91      /* Protocol wrong type for socket */
     284#undef  ENOPROTOOPT
     285#define ENOPROTOOPT     92      /* Protocol not available */
     286#undef  EPROTONOSUPPORT
     287#define EPROTONOSUPPORT 93      /* Protocol not supported */
     288#undef  ESOCKTNOSUPPORT
     289#define ESOCKTNOSUPPORT 94      /* Socket type not supported */
     290#undef  EOPNOTSUPP
     291#define EOPNOTSUPP      95      /* Operation not supported on transport endpoint */
     292#undef  EPFNOSUPPORT
     293#define EPFNOSUPPORT    96      /* Protocol family not supported */
     294#undef  EAFNOSUPPORT
     295#define EAFNOSUPPORT    97      /* Address family not supported by protocol */
     296#undef  EADDRINUSE
     297#define EADDRINUSE      98      /* Address already in use */
     298#undef  EADDRNOTAVAIL
     299#define EADDRNOTAVAIL   99      /* Cannot assign requested address */
     300#undef  ENETDOWN
     301#define ENETDOWN        100     /* Network is down */
     302#undef  ENETUNREACH
     303#define ENETUNREACH     101     /* Network is unreachable */
     304#undef  ENETRESET
     305#define ENETRESET       102     /* Network dropped connection because of reset */
     306#undef  ECONNABORTED
     307#define ECONNABORTED    103     /* Software caused connection abort */
     308#undef  ECONNRESET
     309#define ECONNRESET      104     /* Connection reset by peer */
     310#undef  ENOBUFS
     311#define ENOBUFS         105     /* No buffer space available */
     312#undef  EISCONN
     313#define EISCONN         106     /* Transport endpoint is already connected */
     314#undef  ENOTCONN
     315#define ENOTCONN        107     /* Transport endpoint is not connected */
     316#undef  ESHUTDOWN
     317#define ESHUTDOWN       108     /* Cannot send after transport endpoint shutdown */
     318#undef  ETOOMANYREFS
     319#define ETOOMANYREFS    109     /* Too many references: cannot splice */
     320#undef  ETIMEDOUT
     321#define ETIMEDOUT       110     /* Connection timed out */
     322#undef  ECONNREFUSED
     323#define ECONNREFUSED    111     /* Connection refused */
     324#undef  EHOSTDOWN
     325#define EHOSTDOWN       112     /* Host is down */
     326#undef  EHOSTUNREACH
     327#define EHOSTUNREACH    113     /* No route to host */
     328#undef  EALREADY
     329#define EALREADY        114     /* Operation already in progress */
     330#undef  EINPROGRESS
     331#define EINPROGRESS     115     /* Operation now in progress */
     332#undef  ESTALE
     333#define ESTALE          116     /* Stale NFS file handle */
     334#undef  EUCLEAN
     335#define EUCLEAN         117     /* Structure needs cleaning */
     336#undef  ENOTNAM
     337#define ENOTNAM         118     /* Not a XENIX named type file */
     338#undef  ENAVAIL
     339#define ENAVAIL         119     /* No XENIX semaphores available */
     340#undef  EISNAM
     341#define EISNAM          120     /* Is a named type file */
     342#undef  EREMOTEIO
     343#define EREMOTEIO       121     /* Remote I/O error */
     344#undef  EDQUOT
     345#define EDQUOT          122     /* Quota exceeded */
     346#undef  ENOMEDIUM
     347#define ENOMEDIUM       123     /* No medium found */
     348#undef  EMEDIUMTYPE
     349#define EMEDIUMTYPE     124     /* Wrong medium type */
     350#undef  ECANCELED
     351#define ECANCELED       125     /* Operation Canceled */
     352#undef  ENOKEY
     353#define ENOKEY          126     /* Required key not available */
     354#undef  EKEYEXPIRED
     355#define EKEYEXPIRED     127     /* Key has expired */
     356#undef  EKEYREVOKED
     357#define EKEYREVOKED     128     /* Key has been revoked */
     358#undef  EKEYREJECTED
     359#define EKEYREJECTED    129     /* Key was rejected by service */
     360#undef  EOWNERDEAD
     361#define EOWNERDEAD      130     /* Owner died */
     362#undef  ENOTRECOVERABLE
     363#define ENOTRECOVERABLE 131     /* State not recoverable */
     364
     365struct statvfs {
     366    unsigned long  f_bsize;    ///< Filesystem block size
     367    unsigned long  f_frsize;   ///< Fragment size (block size)
     368
     369    fsblkcnt_t     f_blocks;   ///< Number of blocks
     370    fsblkcnt_t     f_bfree;    ///< Number of free blocks
     371    fsblkcnt_t     f_bavail;   ///< Number of free blocks for unprivileged users
     372
     373    unsigned long  f_fsid;     ///< Filesystem ID
     374
     375    unsigned long  f_namemax;  ///< Maximum filename length
     376};
     377
     378/* The following are dirent.h definitions are declared here to guarantee
     379 * consistency where structure may be different with different toolchains
     380 */
     381struct dirent {
     382        ino_t d_ino;
     383        off_t d_off;
     384        unsigned short d_reclen;
     385        unsigned char d_type;
     386        char d_name[256];
     387};
     388
     389enum {
     390        DT_UNKNOWN = 0,  ///< The file type could not be determined.
     391        DT_FIFO = 1,     ///< This is a named pipe (FIFO).
     392        DT_CHR = 2,      ///< This is a character device.
     393        DT_DIR = 4,      ///< This is a directory.
     394        DT_BLK = 6,      ///< This is a block device.
     395        DT_REG = 8,      ///< This is a regular file.
     396        DT_LNK = 10,     ///< This is a symbolic link.
     397        DT_SOCK = 12,    ///< This is a UNIX domain socket.
     398};
     399
     400/* fcntl.h defines */
     401#define F_GETFL 3
     402#define F_SETFL 4
     403#define F_SETOWN 8
     404
     405struct pollfd {
     406    int fd;
     407    short events;
     408    short revents;
     409};
     410
     411/* termios.h */
     412typedef unsigned char cc_t;
     413typedef unsigned int speed_t;
     414typedef unsigned int tcflag_t;
     415
     416#define NCCS 32
     417
     418struct termios {
     419        tcflag_t c_iflag;
     420        tcflag_t c_oflag;
     421        tcflag_t c_cflag;
     422        tcflag_t c_lflag;
     423        cc_t c_line;
     424        cc_t c_cc[NCCS];
     425        speed_t __c_ispeed;
     426        speed_t __c_ospeed;
     427};
     428
     429#define ICANON 0000002
     430#define ECHO   0000010
     431
     432#define TCSAFLUSH 2
     433
     434#define DebugBreak()    asm("bkpt #0")
     435
     436/* POSIX-compatible I/O functions */
     437#if __cplusplus
     438extern "C" {
     439#endif
     440        int open(const char *path, int oflag, ...);
     441#ifndef __IAR_SYSTEMS_ICC__ /* IAR provides fdopen itself */
     442#if __cplusplus
     443        std::FILE *fdopen(int fildes, const char *mode);
     444#else
     445        FILE *fdopen(int fildes, const char *mode);
     446#endif
     447#endif
     448        ssize_t write(int fildes, const void *buf, size_t nbyte);
     449        ssize_t read(int fildes, void *buf, size_t nbyte);
     450        off_t lseek(int fildes, off_t offset, int whence);
     451        int isatty(int fildes);
     452        int fsync(int fildes);
     453        int fstat(int fildes, struct stat *st);
     454        int fcntl(int fildes, int cmd, ...);
     455        int poll(struct pollfd fds[], nfds_t nfds, int timeout);
     456        int close(int fildes);
     457        int stat(const char *path, struct stat *st);
     458        int statvfs(const char *path, struct statvfs *buf);
     459        DIR *opendir(const char *);
     460        struct dirent *readdir(DIR *);
     461        int closedir(DIR *);
     462        void rewinddir(DIR *);
     463        long telldir(DIR *);
     464        void seekdir(DIR *, long);
     465        int mkdir(const char *name, mode_t n);
     466
     467#if __cplusplus
     468}; // extern "C"
     469#endif // __cplusplus
     470
    30471#endif //RETARGET_H
Note: See TracChangeset for help on using the changeset viewer.