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