Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: SPIne CH_Communicatuin_Test CH_Communicatuin_Test2 MCP_SPIne ... more
Fork of mbed-dev-f303 by
mbed_retarget.h
00001 /* 00002 * mbed Microcontroller Library 00003 * Copyright (c) 2006-2016 ARM Limited 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 */ 00018 00019 #ifndef RETARGET_H 00020 #define RETARGET_H 00021 00022 #if __cplusplus 00023 #include <cstdio> 00024 #endif //__cplusplus 00025 #include <stdint.h> 00026 #include <stddef.h> 00027 00028 /* We can get the following standard types from sys/types for gcc, but we 00029 * need to define the types ourselves for the other compilers that normally 00030 * target embedded systems */ 00031 #if defined(__ARMCC_VERSION) || defined(__ICCARM__) 00032 typedef signed int ssize_t; ///< Signed size type, usually encodes negative errors 00033 typedef signed long off_t; ///< Offset in a data stream 00034 typedef unsigned int mode_t; ///< Mode for opening files 00035 typedef unsigned int dev_t; ///< Device ID type 00036 typedef unsigned long ino_t; ///< File serial number 00037 typedef unsigned int nlink_t; ///< Number of links to a file 00038 typedef unsigned int uid_t; ///< User ID 00039 typedef unsigned int gid_t; ///< Group ID 00040 00041 #define O_RDONLY 0 ///< Open for reading 00042 #define O_WRONLY 1 ///< Open for writing 00043 #define O_RDWR 2 ///< Open for reading and writing 00044 #define O_CREAT 0x0200 ///< Create file if it does not exist 00045 #define O_TRUNC 0x0400 ///< Truncate file to zero length 00046 #define O_EXCL 0x0800 ///< Fail if file exists 00047 #define O_APPEND 0x0008 ///< Set file offset to end of file prior to each write 00048 00049 #define NAME_MAX 255 ///< Maximum size of a name in a file path 00050 00051 #include <time.h> 00052 00053 #else 00054 00055 #include <sys/fcntl.h> 00056 #include <sys/types.h> 00057 #include <sys/syslimits.h> 00058 00059 #endif 00060 00061 00062 /* DIR declarations must also be here */ 00063 #if __cplusplus 00064 namespace mbed { 00065 class FileHandle; 00066 class DirHandle; 00067 std::FILE *mbed_fdopen(FileHandle *fh, const char *mode); 00068 } 00069 typedef mbed::DirHandle DIR; 00070 #else 00071 typedef struct Dir DIR; 00072 #endif 00073 00074 #if __cplusplus 00075 extern "C" { 00076 #endif 00077 DIR *opendir(const char*); 00078 struct dirent *readdir(DIR *); 00079 int closedir(DIR*); 00080 void rewinddir(DIR*); 00081 long telldir(DIR*); 00082 void seekdir(DIR*, long); 00083 int mkdir(const char *name, mode_t n); 00084 #if __cplusplus 00085 }; 00086 #endif 00087 00088 00089 #if defined(__ARMCC_VERSION) || defined(__ICCARM__) 00090 /* The intent of this section is to unify the errno error values to match 00091 * the POSIX definitions for the GCC_ARM, ARMCC and IAR compilers. This is 00092 * necessary because the ARMCC/IAR errno.h, or sys/stat.h are missing some 00093 * symbol definitions used by the POSIX filesystem API to return errno codes. 00094 * Note also that ARMCC errno.h defines some symbol values differently from 00095 * the GCC_ARM/IAR/standard POSIX definitions. The definitions guard against 00096 * this and future changes by changing the symbol definition as shown below. 00097 */ 00098 #undef EPERM 00099 #define EPERM 1 /* Operation not permitted */ 00100 #undef ENOENT 00101 #define ENOENT 2 /* No such file or directory */ 00102 #undef ESRCH 00103 #define ESRCH 3 /* No such process */ 00104 #undef EINTR 00105 #define EINTR 4 /* Interrupted system call */ 00106 #undef EIO 00107 #define EIO 5 /* I/O error */ 00108 #undef ENXIO 00109 #define ENXIO 6 /* No such device or address */ 00110 #undef E2BIG 00111 #define E2BIG 7 /* Argument list too long */ 00112 #undef ENOEXEC 00113 #define ENOEXEC 8 /* Exec format error */ 00114 #undef EBADF 00115 #define EBADF 9 /* Bad file number */ 00116 #undef ECHILD 00117 #define ECHILD 10 /* No child processes */ 00118 #undef EAGAIN 00119 #define EAGAIN 11 /* Try again */ 00120 #undef ENOMEM 00121 #define ENOMEM 12 /* Out of memory */ 00122 #undef EACCES 00123 #define EACCES 13 /* Permission denied */ 00124 #undef EFAULT 00125 #define EFAULT 14 /* Bad address */ 00126 #undef ENOTBLK 00127 #define ENOTBLK 15 /* Block device required */ 00128 #undef EBUSY 00129 #define EBUSY 16 /* Device or resource busy */ 00130 #undef EEXIST 00131 #define EEXIST 17 /* File exists */ 00132 #undef EXDEV 00133 #define EXDEV 18 /* Cross-device link */ 00134 #undef ENODEV 00135 #define ENODEV 19 /* No such device */ 00136 #undef ENOTDIR 00137 #define ENOTDIR 20 /* Not a directory */ 00138 #undef EISDIR 00139 #define EISDIR 21 /* Is a directory */ 00140 #undef EINVAL 00141 #define EINVAL 22 /* Invalid argument */ 00142 #undef ENFILE 00143 #define ENFILE 23 /* File table overflow */ 00144 #undef EMFILE 00145 #define EMFILE 24 /* Too many open files */ 00146 #undef ENOTTY 00147 #define ENOTTY 25 /* Not a typewriter */ 00148 #undef ETXTBSY 00149 #define ETXTBSY 26 /* Text file busy */ 00150 #undef EFBIG 00151 #define EFBIG 27 /* File too large */ 00152 #undef ENOSPC 00153 #define ENOSPC 28 /* No space left on device */ 00154 #undef ESPIPE 00155 #define ESPIPE 29 /* Illegal seek */ 00156 #undef EROFS 00157 #define EROFS 30 /* Read-only file system */ 00158 #undef EMLINK 00159 #define EMLINK 31 /* Too many links */ 00160 #undef EPIPE 00161 #define EPIPE 32 /* Broken pipe */ 00162 #undef EDOM 00163 #define EDOM 33 /* Math argument out of domain of func */ 00164 #undef ERANGE 00165 #define ERANGE 34 /* Math result not representable */ 00166 #undef EDEADLK 00167 #define EDEADLK 35 /* Resource deadlock would occur */ 00168 #undef ENAMETOOLONG 00169 #define ENAMETOOLONG 36 /* File name too long */ 00170 #undef ENOLCK 00171 #define ENOLCK 37 /* No record locks available */ 00172 #undef ENOSYS 00173 #define ENOSYS 38 /* Function not implemented */ 00174 #undef ENOTEMPTY 00175 #define ENOTEMPTY 39 /* Directory not empty */ 00176 #undef ELOOP 00177 #define ELOOP 40 /* Too many symbolic links encountered */ 00178 #undef EWOULDBLOCK 00179 #define EWOULDBLOCK EAGAIN /* Operation would block */ 00180 #undef ENOMSG 00181 #define ENOMSG 42 /* No message of desired type */ 00182 #undef EIDRM 00183 #define EIDRM 43 /* Identifier removed */ 00184 #undef ECHRNG 00185 #define ECHRNG 44 /* Channel number out of range */ 00186 #undef EL2NSYNC 00187 #define EL2NSYNC 45 /* Level 2 not synchronized */ 00188 #undef EL3HLT 00189 #define EL3HLT 46 /* Level 3 halted */ 00190 #undef EL3RST 00191 #define EL3RST 47 /* Level 3 reset */ 00192 #undef ELNRNG 00193 #define ELNRNG 48 /* Link number out of range */ 00194 #undef EUNATCH 00195 #define EUNATCH 49 /* Protocol driver not attached */ 00196 #undef ENOCSI 00197 #define ENOCSI 50 /* No CSI structure available */ 00198 #undef EL2HLT 00199 #define EL2HLT 51 /* Level 2 halted */ 00200 #undef EBADE 00201 #define EBADE 52 /* Invalid exchange */ 00202 #undef EBADR 00203 #define EBADR 53 /* Invalid request descriptor */ 00204 #undef EXFULL 00205 #define EXFULL 54 /* Exchange full */ 00206 #undef ENOANO 00207 #define ENOANO 55 /* No anode */ 00208 #undef EBADRQC 00209 #define EBADRQC 56 /* Invalid request code */ 00210 #undef EBADSLT 00211 #define EBADSLT 57 /* Invalid slot */ 00212 #undef EDEADLOCK 00213 #define EDEADLOCK EDEADLK /* Resource deadlock would occur */ 00214 #undef EBFONT 00215 #define EBFONT 59 /* Bad font file format */ 00216 #undef ENOSTR 00217 #define ENOSTR 60 /* Device not a stream */ 00218 #undef ENODATA 00219 #define ENODATA 61 /* No data available */ 00220 #undef ETIME 00221 #define ETIME 62 /* Timer expired */ 00222 #undef ENOSR 00223 #define ENOSR 63 /* Out of streams resources */ 00224 #undef ENONET 00225 #define ENONET 64 /* Machine is not on the network */ 00226 #undef ENOPKG 00227 #define ENOPKG 65 /* Package not installed */ 00228 #undef EREMOTE 00229 #define EREMOTE 66 /* Object is remote */ 00230 #undef ENOLINK 00231 #define ENOLINK 67 /* Link has been severed */ 00232 #undef EADV 00233 #define EADV 68 /* Advertise error */ 00234 #undef ESRMNT 00235 #define ESRMNT 69 /* Srmount error */ 00236 #undef ECOMM 00237 #define ECOMM 70 /* Communication error on send */ 00238 #undef EPROTO 00239 #define EPROTO 71 /* Protocol error */ 00240 #undef EMULTIHOP 00241 #define EMULTIHOP 72 /* Multihop attempted */ 00242 #undef EDOTDOT 00243 #define EDOTDOT 73 /* RFS specific error */ 00244 #undef EBADMSG 00245 #define EBADMSG 74 /* Not a data message */ 00246 #undef EOVERFLOW 00247 #define EOVERFLOW 75 /* Value too large for defined data type */ 00248 #undef ENOTUNIQ 00249 #define ENOTUNIQ 76 /* Name not unique on network */ 00250 #undef EBADFD 00251 #define EBADFD 77 /* File descriptor in bad state */ 00252 #undef EREMCHG 00253 #define EREMCHG 78 /* Remote address changed */ 00254 #undef ELIBACC 00255 #define ELIBACC 79 /* Can not access a needed shared library */ 00256 #undef ELIBBAD 00257 #define ELIBBAD 80 /* Accessing a corrupted shared library */ 00258 #undef ELIBSCN 00259 #define ELIBSCN 81 /* .lib section in a.out corrupted */ 00260 #undef ELIBMAX 00261 #define ELIBMAX 82 /* Attempting to link in too many shared libraries */ 00262 #undef ELIBEXEC 00263 #define ELIBEXEC 83 /* Cannot exec a shared library directly */ 00264 #undef EILSEQ 00265 #define EILSEQ 84 /* Illegal byte sequence */ 00266 #undef ERESTART 00267 #define ERESTART 85 /* Interrupted system call should be restarted */ 00268 #undef ESTRPIPE 00269 #define ESTRPIPE 86 /* Streams pipe error */ 00270 #undef EUSERS 00271 #define EUSERS 87 /* Too many users */ 00272 #undef ENOTSOCK 00273 #define ENOTSOCK 88 /* Socket operation on non-socket */ 00274 #undef EDESTADDRREQ 00275 #define EDESTADDRREQ 89 /* Destination address required */ 00276 #undef EMSGSIZE 00277 #define EMSGSIZE 90 /* Message too long */ 00278 #undef EPROTOTYPE 00279 #define EPROTOTYPE 91 /* Protocol wrong type for socket */ 00280 #undef ENOPROTOOPT 00281 #define ENOPROTOOPT 92 /* Protocol not available */ 00282 #undef EPROTONOSUPPORT 00283 #define EPROTONOSUPPORT 93 /* Protocol not supported */ 00284 #undef ESOCKTNOSUPPORT 00285 #define ESOCKTNOSUPPORT 94 /* Socket type not supported */ 00286 #undef EOPNOTSUPP 00287 #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ 00288 #undef EPFNOSUPPORT 00289 #define EPFNOSUPPORT 96 /* Protocol family not supported */ 00290 #undef EAFNOSUPPORT 00291 #define EAFNOSUPPORT 97 /* Address family not supported by protocol */ 00292 #undef EADDRINUSE 00293 #define EADDRINUSE 98 /* Address already in use */ 00294 #undef EADDRNOTAVAIL 00295 #define EADDRNOTAVAIL 99 /* Cannot assign requested address */ 00296 #undef ENETDOWN 00297 #define ENETDOWN 100 /* Network is down */ 00298 #undef ENETUNREACH 00299 #define ENETUNREACH 101 /* Network is unreachable */ 00300 #undef ENETRESET 00301 #define ENETRESET 102 /* Network dropped connection because of reset */ 00302 #undef ECONNABORTED 00303 #define ECONNABORTED 103 /* Software caused connection abort */ 00304 #undef ECONNRESET 00305 #define ECONNRESET 104 /* Connection reset by peer */ 00306 #undef ENOBUFS 00307 #define ENOBUFS 105 /* No buffer space available */ 00308 #undef EISCONN 00309 #define EISCONN 106 /* Transport endpoint is already connected */ 00310 #undef ENOTCONN 00311 #define ENOTCONN 107 /* Transport endpoint is not connected */ 00312 #undef ESHUTDOWN 00313 #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ 00314 #undef ETOOMANYREFS 00315 #define ETOOMANYREFS 109 /* Too many references: cannot splice */ 00316 #undef ETIMEDOUT 00317 #define ETIMEDOUT 110 /* Connection timed out */ 00318 #undef ECONNREFUSED 00319 #define ECONNREFUSED 111 /* Connection refused */ 00320 #undef EHOSTDOWN 00321 #define EHOSTDOWN 112 /* Host is down */ 00322 #undef EHOSTUNREACH 00323 #define EHOSTUNREACH 113 /* No route to host */ 00324 #undef EALREADY 00325 #define EALREADY 114 /* Operation already in progress */ 00326 #undef EINPROGRESS 00327 #define EINPROGRESS 115 /* Operation now in progress */ 00328 #undef ESTALE 00329 #define ESTALE 116 /* Stale NFS file handle */ 00330 #undef EUCLEAN 00331 #define EUCLEAN 117 /* Structure needs cleaning */ 00332 #undef ENOTNAM 00333 #define ENOTNAM 118 /* Not a XENIX named type file */ 00334 #undef ENAVAIL 00335 #define ENAVAIL 119 /* No XENIX semaphores available */ 00336 #undef EISNAM 00337 #define EISNAM 120 /* Is a named type file */ 00338 #undef EREMOTEIO 00339 #define EREMOTEIO 121 /* Remote I/O error */ 00340 #undef EDQUOT 00341 #define EDQUOT 122 /* Quota exceeded */ 00342 #undef ENOMEDIUM 00343 #define ENOMEDIUM 123 /* No medium found */ 00344 #undef EMEDIUMTYPE 00345 #define EMEDIUMTYPE 124 /* Wrong medium type */ 00346 #undef ECANCELED 00347 #define ECANCELED 125 /* Operation Canceled */ 00348 #undef ENOKEY 00349 #define ENOKEY 126 /* Required key not available */ 00350 #undef EKEYEXPIRED 00351 #define EKEYEXPIRED 127 /* Key has expired */ 00352 #undef EKEYREVOKED 00353 #define EKEYREVOKED 128 /* Key has been revoked */ 00354 #undef EKEYREJECTED 00355 #define EKEYREJECTED 129 /* Key was rejected by service */ 00356 #undef EOWNERDEAD 00357 #define EOWNERDEAD 130 /* Owner died */ 00358 #undef ENOTRECOVERABLE 00359 #define ENOTRECOVERABLE 131 /* State not recoverable */ 00360 #endif 00361 00362 #if defined(__ARMCC_VERSION) || defined(__ICCARM__) 00363 /* Missing stat.h defines. 00364 * The following are sys/stat.h definitions not currently present in the ARMCC 00365 * errno.h. Note, ARMCC errno.h defines some symbol values differing from 00366 * GCC_ARM/IAR/standard POSIX definitions. Guard against this and future 00367 * changes by changing the symbol definition for filesystem use. 00368 */ 00369 #define _IFMT 0170000 //< type of file 00370 #define _IFSOCK 0140000 //< socket 00371 #define _IFLNK 0120000 //< symbolic link 00372 #define _IFREG 0100000 //< regular 00373 #define _IFBLK 0060000 //< block special 00374 #define _IFDIR 0040000 //< directory 00375 #define _IFCHR 0020000 //< character special 00376 #define _IFIFO 0010000 //< fifo special 00377 00378 #define S_IFMT _IFMT //< type of file 00379 #define S_IFSOCK _IFSOCK //< socket 00380 #define S_IFLNK _IFLNK //< symbolic link 00381 #define S_IFREG _IFREG //< regular 00382 #define S_IFBLK _IFBLK //< block special 00383 #define S_IFDIR _IFDIR //< directory 00384 #define S_IFCHR _IFCHR //< character special 00385 #define S_IFIFO _IFIFO //< fifo special 00386 00387 #define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) 00388 #define S_IRUSR 0000400 ///< read permission, owner 00389 #define S_IWUSR 0000200 ///< write permission, owner 00390 #define S_IXUSR 0000100 ///< execute/search permission, owner 00391 #define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) 00392 #define S_IRGRP 0000040 ///< read permission, group 00393 #define S_IWGRP 0000020 ///< write permission, grougroup 00394 #define S_IXGRP 0000010 ///< execute/search permission, group 00395 #define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) 00396 #define S_IROTH 0000004 ///< read permission, other 00397 #define S_IWOTH 0000002 ///< write permission, other 00398 #define S_IXOTH 0000001 ///< execute/search permission, other 00399 00400 /* Refer to sys/stat standard 00401 * Note: Not all fields may be supported by the underlying filesystem 00402 */ 00403 struct stat { 00404 dev_t st_dev; ///< Device ID containing file 00405 ino_t st_ino; ///< File serial number 00406 mode_t st_mode; ///< Mode of file 00407 nlink_t st_nlink; ///< Number of links to file 00408 00409 uid_t st_uid; ///< User ID 00410 gid_t st_gid; ///< Group ID 00411 00412 off_t st_size; ///< Size of file in bytes 00413 00414 time_t st_atime; ///< Time of last access 00415 time_t st_mtime; ///< Time of last data modification 00416 time_t st_ctime; ///< Time of last status change 00417 }; 00418 00419 #endif /* defined(__ARMCC_VERSION) || defined(__ICCARM__) */ 00420 00421 00422 /* The following are dirent.h definitions are declared here to garuntee 00423 * consistency where structure may be different with different toolchains 00424 */ 00425 struct dirent { 00426 char d_name[NAME_MAX+1]; ///< Name of file 00427 uint8_t d_type; ///< Type of file 00428 }; 00429 00430 enum { 00431 DT_UNKNOWN, ///< The file type could not be determined. 00432 DT_FIFO, ///< This is a named pipe (FIFO). 00433 DT_CHR, ///< This is a character device. 00434 DT_DIR, ///< This is a directory. 00435 DT_BLK, ///< This is a block device. 00436 DT_REG, ///< This is a regular file. 00437 DT_LNK, ///< This is a symbolic link. 00438 DT_SOCK, ///< This is a UNIX domain socket. 00439 }; 00440 00441 #endif /* RETARGET_H */
Generated on Tue Jul 12 2022 19:39:49 by
