BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:fbdae7e6d805 1 /*
borlanic 0:fbdae7e6d805 2 * mbed Microcontroller Library
borlanic 0:fbdae7e6d805 3 * Copyright (c) 2006-2016 ARM Limited
borlanic 0:fbdae7e6d805 4 *
borlanic 0:fbdae7e6d805 5 * Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:fbdae7e6d805 6 * you may not use this file except in compliance with the License.
borlanic 0:fbdae7e6d805 7 * You may obtain a copy of the License at
borlanic 0:fbdae7e6d805 8 *
borlanic 0:fbdae7e6d805 9 * http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:fbdae7e6d805 10 *
borlanic 0:fbdae7e6d805 11 * Unless required by applicable law or agreed to in writing, software
borlanic 0:fbdae7e6d805 12 * distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:fbdae7e6d805 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:fbdae7e6d805 14 * See the License for the specific language governing permissions and
borlanic 0:fbdae7e6d805 15 * limitations under the License.
borlanic 0:fbdae7e6d805 16 *
borlanic 0:fbdae7e6d805 17 */
borlanic 0:fbdae7e6d805 18
borlanic 0:fbdae7e6d805 19 #ifndef RETARGET_H
borlanic 0:fbdae7e6d805 20 #define RETARGET_H
borlanic 0:fbdae7e6d805 21
borlanic 0:fbdae7e6d805 22 #if __cplusplus
borlanic 0:fbdae7e6d805 23 #include <cstdio>
borlanic 0:fbdae7e6d805 24 #else
borlanic 0:fbdae7e6d805 25 #include <stdio.h>
borlanic 0:fbdae7e6d805 26 #endif //__cplusplus
borlanic 0:fbdae7e6d805 27 #include <stdint.h>
borlanic 0:fbdae7e6d805 28 #include <stddef.h>
borlanic 0:fbdae7e6d805 29
borlanic 0:fbdae7e6d805 30 /* We can get the following standard types from sys/types for gcc, but we
borlanic 0:fbdae7e6d805 31 * need to define the types ourselves for the other compilers that normally
borlanic 0:fbdae7e6d805 32 * target embedded systems */
borlanic 0:fbdae7e6d805 33 typedef signed int ssize_t; ///< Signed size type, usually encodes negative errors
borlanic 0:fbdae7e6d805 34 typedef signed long off_t; ///< Offset in a data stream
borlanic 0:fbdae7e6d805 35 typedef unsigned int nfds_t; ///< Number of file descriptors
borlanic 0:fbdae7e6d805 36 typedef unsigned long long fsblkcnt_t; ///< Count of file system blocks
borlanic 0:fbdae7e6d805 37 #if defined(__ARMCC_VERSION) || !defined(__GNUC__)
borlanic 0:fbdae7e6d805 38 typedef unsigned int mode_t; ///< Mode for opening files
borlanic 0:fbdae7e6d805 39 typedef unsigned int dev_t; ///< Device ID type
borlanic 0:fbdae7e6d805 40 typedef unsigned long ino_t; ///< File serial number
borlanic 0:fbdae7e6d805 41 typedef unsigned int nlink_t; ///< Number of links to a file
borlanic 0:fbdae7e6d805 42 typedef unsigned int uid_t; ///< User ID
borlanic 0:fbdae7e6d805 43 typedef unsigned int gid_t; ///< Group ID
borlanic 0:fbdae7e6d805 44 #endif
borlanic 0:fbdae7e6d805 45
borlanic 0:fbdae7e6d805 46 #define O_RDONLY 0 ///< Open for reading
borlanic 0:fbdae7e6d805 47 #define O_WRONLY 1 ///< Open for writing
borlanic 0:fbdae7e6d805 48 #define O_RDWR 2 ///< Open for reading and writing
borlanic 0:fbdae7e6d805 49 #define O_CREAT 0x0200 ///< Create file if it does not exist
borlanic 0:fbdae7e6d805 50 #define O_TRUNC 0x0400 ///< Truncate file to zero length
borlanic 0:fbdae7e6d805 51 #define O_EXCL 0x0800 ///< Fail if file exists
borlanic 0:fbdae7e6d805 52 #define O_APPEND 0x0008 ///< Set file offset to end of file prior to each write
borlanic 0:fbdae7e6d805 53 #define O_BINARY 0x8000 ///< Open file in binary mode
borlanic 0:fbdae7e6d805 54
borlanic 0:fbdae7e6d805 55 #define NAME_MAX 255 ///< Maximum size of a name in a file path
borlanic 0:fbdae7e6d805 56
borlanic 0:fbdae7e6d805 57 #define STDIN_FILENO 0
borlanic 0:fbdae7e6d805 58 #define STDOUT_FILENO 1
borlanic 0:fbdae7e6d805 59 #define STDERR_FILENO 2
borlanic 0:fbdae7e6d805 60
borlanic 0:fbdae7e6d805 61 #include <time.h>
borlanic 0:fbdae7e6d805 62
borlanic 0:fbdae7e6d805 63 /** \addtogroup platform */
borlanic 0:fbdae7e6d805 64 /** @{*/
borlanic 0:fbdae7e6d805 65 /**
borlanic 0:fbdae7e6d805 66 * \defgroup platform_retarget Retarget functions
borlanic 0:fbdae7e6d805 67 * @{
borlanic 0:fbdae7e6d805 68 */
borlanic 0:fbdae7e6d805 69
borlanic 0:fbdae7e6d805 70 /* DIR declarations must also be here */
borlanic 0:fbdae7e6d805 71 #if __cplusplus
borlanic 0:fbdae7e6d805 72 namespace mbed {
borlanic 0:fbdae7e6d805 73
borlanic 0:fbdae7e6d805 74 class FileHandle;
borlanic 0:fbdae7e6d805 75 class DirHandle;
borlanic 0:fbdae7e6d805 76
borlanic 0:fbdae7e6d805 77 /** Targets may implement this to change stdin, stdout, stderr.
borlanic 0:fbdae7e6d805 78 *
borlanic 0:fbdae7e6d805 79 * If the application hasn't provided mbed_override_console, this is called
borlanic 0:fbdae7e6d805 80 * to give the target a chance to specify a FileHandle for the console.
borlanic 0:fbdae7e6d805 81 *
borlanic 0:fbdae7e6d805 82 * If this is not provided or returns NULL, the console will be:
borlanic 0:fbdae7e6d805 83 * - UARTSerial if configuration option "platform.stdio-buffered-serial" is
borlanic 0:fbdae7e6d805 84 * true and the target has DEVICE_SERIAL;
borlanic 0:fbdae7e6d805 85 * - Raw HAL serial via serial_getc and serial_putc if
borlanic 0:fbdae7e6d805 86 * "platform.stdio-buffered-serial" is false and the target has DEVICE_SERIAL;
borlanic 0:fbdae7e6d805 87 * - stdout/stderr will be a sink and stdin will input a stream of 0s if the
borlanic 0:fbdae7e6d805 88 * target does not have DEVICE_SERIAL.
borlanic 0:fbdae7e6d805 89 *
borlanic 0:fbdae7e6d805 90 * @param fd file descriptor - STDIN_FILENO, STDOUT_FILENO or STDERR_FILENO
borlanic 0:fbdae7e6d805 91 * @return pointer to FileHandle to override normal stream otherwise NULL
borlanic 0:fbdae7e6d805 92 */
borlanic 0:fbdae7e6d805 93 FileHandle* mbed_target_override_console(int fd);
borlanic 0:fbdae7e6d805 94
borlanic 0:fbdae7e6d805 95 /** Applications may implement this to change stdin, stdout, stderr.
borlanic 0:fbdae7e6d805 96 *
borlanic 0:fbdae7e6d805 97 * This hook gives the application a chance to specify a custom FileHandle
borlanic 0:fbdae7e6d805 98 * for the console.
borlanic 0:fbdae7e6d805 99 *
borlanic 0:fbdae7e6d805 100 * If this is not provided or returns NULL, the console will be specified
borlanic 0:fbdae7e6d805 101 * by mbed_target_override_console, else will default to serial - see
borlanic 0:fbdae7e6d805 102 * mbed_target_override_console for more details.
borlanic 0:fbdae7e6d805 103 *
borlanic 0:fbdae7e6d805 104 * Example:
borlanic 0:fbdae7e6d805 105 * @code
borlanic 0:fbdae7e6d805 106 * FileHandle* mbed::mbed_override_console(int) {
borlanic 0:fbdae7e6d805 107 * static UARTSerial my_serial(D0, D1);
borlanic 0:fbdae7e6d805 108 * return &my_serial;
borlanic 0:fbdae7e6d805 109 * }
borlanic 0:fbdae7e6d805 110 * @endcode
borlanic 0:fbdae7e6d805 111
borlanic 0:fbdae7e6d805 112 * @param fd file descriptor - STDIN_FILENO, STDOUT_FILENO or STDERR_FILENO
borlanic 0:fbdae7e6d805 113 * @return pointer to FileHandle to override normal stream otherwise NULL
borlanic 0:fbdae7e6d805 114 */
borlanic 0:fbdae7e6d805 115 FileHandle* mbed_override_console(int fd);
borlanic 0:fbdae7e6d805 116
borlanic 0:fbdae7e6d805 117 }
borlanic 0:fbdae7e6d805 118
borlanic 0:fbdae7e6d805 119 typedef mbed::DirHandle DIR;
borlanic 0:fbdae7e6d805 120 #else
borlanic 0:fbdae7e6d805 121 typedef struct Dir DIR;
borlanic 0:fbdae7e6d805 122 #endif
borlanic 0:fbdae7e6d805 123
borlanic 0:fbdae7e6d805 124 /* The intent of this section is to unify the errno error values to match
borlanic 0:fbdae7e6d805 125 * the POSIX definitions for the GCC_ARM, ARMCC and IAR compilers. This is
borlanic 0:fbdae7e6d805 126 * necessary because the ARMCC/IAR errno.h, or sys/stat.h are missing some
borlanic 0:fbdae7e6d805 127 * symbol definitions used by the POSIX filesystem API to return errno codes.
borlanic 0:fbdae7e6d805 128 * Note also that ARMCC errno.h defines some symbol values differently from
borlanic 0:fbdae7e6d805 129 * the GCC_ARM/IAR/standard POSIX definitions. The definitions guard against
borlanic 0:fbdae7e6d805 130 * this and future changes by changing the symbol definition as shown below.
borlanic 0:fbdae7e6d805 131 */
borlanic 0:fbdae7e6d805 132 #undef EPERM
borlanic 0:fbdae7e6d805 133 #define EPERM 1 /* Operation not permitted */
borlanic 0:fbdae7e6d805 134 #undef ENOENT
borlanic 0:fbdae7e6d805 135 #define ENOENT 2 /* No such file or directory */
borlanic 0:fbdae7e6d805 136 #undef ESRCH
borlanic 0:fbdae7e6d805 137 #define ESRCH 3 /* No such process */
borlanic 0:fbdae7e6d805 138 #undef EINTR
borlanic 0:fbdae7e6d805 139 #define EINTR 4 /* Interrupted system call */
borlanic 0:fbdae7e6d805 140 #undef EIO
borlanic 0:fbdae7e6d805 141 #define EIO 5 /* I/O error */
borlanic 0:fbdae7e6d805 142 #undef ENXIO
borlanic 0:fbdae7e6d805 143 #define ENXIO 6 /* No such device or address */
borlanic 0:fbdae7e6d805 144 #undef E2BIG
borlanic 0:fbdae7e6d805 145 #define E2BIG 7 /* Argument list too long */
borlanic 0:fbdae7e6d805 146 #undef ENOEXEC
borlanic 0:fbdae7e6d805 147 #define ENOEXEC 8 /* Exec format error */
borlanic 0:fbdae7e6d805 148 #undef EBADF
borlanic 0:fbdae7e6d805 149 #define EBADF 9 /* Bad file number */
borlanic 0:fbdae7e6d805 150 #undef ECHILD
borlanic 0:fbdae7e6d805 151 #define ECHILD 10 /* No child processes */
borlanic 0:fbdae7e6d805 152 #undef EAGAIN
borlanic 0:fbdae7e6d805 153 #define EAGAIN 11 /* Try again */
borlanic 0:fbdae7e6d805 154 #undef ENOMEM
borlanic 0:fbdae7e6d805 155 #define ENOMEM 12 /* Out of memory */
borlanic 0:fbdae7e6d805 156 #undef EACCES
borlanic 0:fbdae7e6d805 157 #define EACCES 13 /* Permission denied */
borlanic 0:fbdae7e6d805 158 #undef EFAULT
borlanic 0:fbdae7e6d805 159 #define EFAULT 14 /* Bad address */
borlanic 0:fbdae7e6d805 160 #undef ENOTBLK
borlanic 0:fbdae7e6d805 161 #define ENOTBLK 15 /* Block device required */
borlanic 0:fbdae7e6d805 162 #undef EBUSY
borlanic 0:fbdae7e6d805 163 #define EBUSY 16 /* Device or resource busy */
borlanic 0:fbdae7e6d805 164 #undef EEXIST
borlanic 0:fbdae7e6d805 165 #define EEXIST 17 /* File exists */
borlanic 0:fbdae7e6d805 166 #undef EXDEV
borlanic 0:fbdae7e6d805 167 #define EXDEV 18 /* Cross-device link */
borlanic 0:fbdae7e6d805 168 #undef ENODEV
borlanic 0:fbdae7e6d805 169 #define ENODEV 19 /* No such device */
borlanic 0:fbdae7e6d805 170 #undef ENOTDIR
borlanic 0:fbdae7e6d805 171 #define ENOTDIR 20 /* Not a directory */
borlanic 0:fbdae7e6d805 172 #undef EISDIR
borlanic 0:fbdae7e6d805 173 #define EISDIR 21 /* Is a directory */
borlanic 0:fbdae7e6d805 174 #undef EINVAL
borlanic 0:fbdae7e6d805 175 #define EINVAL 22 /* Invalid argument */
borlanic 0:fbdae7e6d805 176 #undef ENFILE
borlanic 0:fbdae7e6d805 177 #define ENFILE 23 /* File table overflow */
borlanic 0:fbdae7e6d805 178 #undef EMFILE
borlanic 0:fbdae7e6d805 179 #define EMFILE 24 /* Too many open files */
borlanic 0:fbdae7e6d805 180 #undef ENOTTY
borlanic 0:fbdae7e6d805 181 #define ENOTTY 25 /* Not a typewriter */
borlanic 0:fbdae7e6d805 182 #undef ETXTBSY
borlanic 0:fbdae7e6d805 183 #define ETXTBSY 26 /* Text file busy */
borlanic 0:fbdae7e6d805 184 #undef EFBIG
borlanic 0:fbdae7e6d805 185 #define EFBIG 27 /* File too large */
borlanic 0:fbdae7e6d805 186 #undef ENOSPC
borlanic 0:fbdae7e6d805 187 #define ENOSPC 28 /* No space left on device */
borlanic 0:fbdae7e6d805 188 #undef ESPIPE
borlanic 0:fbdae7e6d805 189 #define ESPIPE 29 /* Illegal seek */
borlanic 0:fbdae7e6d805 190 #undef EROFS
borlanic 0:fbdae7e6d805 191 #define EROFS 30 /* Read-only file system */
borlanic 0:fbdae7e6d805 192 #undef EMLINK
borlanic 0:fbdae7e6d805 193 #define EMLINK 31 /* Too many links */
borlanic 0:fbdae7e6d805 194 #undef EPIPE
borlanic 0:fbdae7e6d805 195 #define EPIPE 32 /* Broken pipe */
borlanic 0:fbdae7e6d805 196 #undef EDOM
borlanic 0:fbdae7e6d805 197 #define EDOM 33 /* Math argument out of domain of func */
borlanic 0:fbdae7e6d805 198 #undef ERANGE
borlanic 0:fbdae7e6d805 199 #define ERANGE 34 /* Math result not representable */
borlanic 0:fbdae7e6d805 200 #undef EDEADLK
borlanic 0:fbdae7e6d805 201 #define EDEADLK 35 /* Resource deadlock would occur */
borlanic 0:fbdae7e6d805 202 #undef ENAMETOOLONG
borlanic 0:fbdae7e6d805 203 #define ENAMETOOLONG 36 /* File name too long */
borlanic 0:fbdae7e6d805 204 #undef ENOLCK
borlanic 0:fbdae7e6d805 205 #define ENOLCK 37 /* No record locks available */
borlanic 0:fbdae7e6d805 206 #undef ENOSYS
borlanic 0:fbdae7e6d805 207 #define ENOSYS 38 /* Function not implemented */
borlanic 0:fbdae7e6d805 208 #undef ENOTEMPTY
borlanic 0:fbdae7e6d805 209 #define ENOTEMPTY 39 /* Directory not empty */
borlanic 0:fbdae7e6d805 210 #undef ELOOP
borlanic 0:fbdae7e6d805 211 #define ELOOP 40 /* Too many symbolic links encountered */
borlanic 0:fbdae7e6d805 212 #undef EWOULDBLOCK
borlanic 0:fbdae7e6d805 213 #define EWOULDBLOCK EAGAIN /* Operation would block */
borlanic 0:fbdae7e6d805 214 #undef ENOMSG
borlanic 0:fbdae7e6d805 215 #define ENOMSG 42 /* No message of desired type */
borlanic 0:fbdae7e6d805 216 #undef EIDRM
borlanic 0:fbdae7e6d805 217 #define EIDRM 43 /* Identifier removed */
borlanic 0:fbdae7e6d805 218 #undef ECHRNG
borlanic 0:fbdae7e6d805 219 #define ECHRNG 44 /* Channel number out of range */
borlanic 0:fbdae7e6d805 220 #undef EL2NSYNC
borlanic 0:fbdae7e6d805 221 #define EL2NSYNC 45 /* Level 2 not synchronized */
borlanic 0:fbdae7e6d805 222 #undef EL3HLT
borlanic 0:fbdae7e6d805 223 #define EL3HLT 46 /* Level 3 halted */
borlanic 0:fbdae7e6d805 224 #undef EL3RST
borlanic 0:fbdae7e6d805 225 #define EL3RST 47 /* Level 3 reset */
borlanic 0:fbdae7e6d805 226 #undef ELNRNG
borlanic 0:fbdae7e6d805 227 #define ELNRNG 48 /* Link number out of range */
borlanic 0:fbdae7e6d805 228 #undef EUNATCH
borlanic 0:fbdae7e6d805 229 #define EUNATCH 49 /* Protocol driver not attached */
borlanic 0:fbdae7e6d805 230 #undef ENOCSI
borlanic 0:fbdae7e6d805 231 #define ENOCSI 50 /* No CSI structure available */
borlanic 0:fbdae7e6d805 232 #undef EL2HLT
borlanic 0:fbdae7e6d805 233 #define EL2HLT 51 /* Level 2 halted */
borlanic 0:fbdae7e6d805 234 #undef EBADE
borlanic 0:fbdae7e6d805 235 #define EBADE 52 /* Invalid exchange */
borlanic 0:fbdae7e6d805 236 #undef EBADR
borlanic 0:fbdae7e6d805 237 #define EBADR 53 /* Invalid request descriptor */
borlanic 0:fbdae7e6d805 238 #undef EXFULL
borlanic 0:fbdae7e6d805 239 #define EXFULL 54 /* Exchange full */
borlanic 0:fbdae7e6d805 240 #undef ENOANO
borlanic 0:fbdae7e6d805 241 #define ENOANO 55 /* No anode */
borlanic 0:fbdae7e6d805 242 #undef EBADRQC
borlanic 0:fbdae7e6d805 243 #define EBADRQC 56 /* Invalid request code */
borlanic 0:fbdae7e6d805 244 #undef EBADSLT
borlanic 0:fbdae7e6d805 245 #define EBADSLT 57 /* Invalid slot */
borlanic 0:fbdae7e6d805 246 #undef EDEADLOCK
borlanic 0:fbdae7e6d805 247 #define EDEADLOCK EDEADLK /* Resource deadlock would occur */
borlanic 0:fbdae7e6d805 248 #undef EBFONT
borlanic 0:fbdae7e6d805 249 #define EBFONT 59 /* Bad font file format */
borlanic 0:fbdae7e6d805 250 #undef ENOSTR
borlanic 0:fbdae7e6d805 251 #define ENOSTR 60 /* Device not a stream */
borlanic 0:fbdae7e6d805 252 #undef ENODATA
borlanic 0:fbdae7e6d805 253 #define ENODATA 61 /* No data available */
borlanic 0:fbdae7e6d805 254 #undef ETIME
borlanic 0:fbdae7e6d805 255 #define ETIME 62 /* Timer expired */
borlanic 0:fbdae7e6d805 256 #undef ENOSR
borlanic 0:fbdae7e6d805 257 #define ENOSR 63 /* Out of streams resources */
borlanic 0:fbdae7e6d805 258 #undef ENONET
borlanic 0:fbdae7e6d805 259 #define ENONET 64 /* Machine is not on the network */
borlanic 0:fbdae7e6d805 260 #undef ENOPKG
borlanic 0:fbdae7e6d805 261 #define ENOPKG 65 /* Package not installed */
borlanic 0:fbdae7e6d805 262 #undef EREMOTE
borlanic 0:fbdae7e6d805 263 #define EREMOTE 66 /* Object is remote */
borlanic 0:fbdae7e6d805 264 #undef ENOLINK
borlanic 0:fbdae7e6d805 265 #define ENOLINK 67 /* Link has been severed */
borlanic 0:fbdae7e6d805 266 #undef EADV
borlanic 0:fbdae7e6d805 267 #define EADV 68 /* Advertise error */
borlanic 0:fbdae7e6d805 268 #undef ESRMNT
borlanic 0:fbdae7e6d805 269 #define ESRMNT 69 /* Srmount error */
borlanic 0:fbdae7e6d805 270 #undef ECOMM
borlanic 0:fbdae7e6d805 271 #define ECOMM 70 /* Communication error on send */
borlanic 0:fbdae7e6d805 272 #undef EPROTO
borlanic 0:fbdae7e6d805 273 #define EPROTO 71 /* Protocol error */
borlanic 0:fbdae7e6d805 274 #undef EMULTIHOP
borlanic 0:fbdae7e6d805 275 #define EMULTIHOP 72 /* Multihop attempted */
borlanic 0:fbdae7e6d805 276 #undef EDOTDOT
borlanic 0:fbdae7e6d805 277 #define EDOTDOT 73 /* RFS specific error */
borlanic 0:fbdae7e6d805 278 #undef EBADMSG
borlanic 0:fbdae7e6d805 279 #define EBADMSG 74 /* Not a data message */
borlanic 0:fbdae7e6d805 280 #undef EOVERFLOW
borlanic 0:fbdae7e6d805 281 #define EOVERFLOW 75 /* Value too large for defined data type */
borlanic 0:fbdae7e6d805 282 #undef ENOTUNIQ
borlanic 0:fbdae7e6d805 283 #define ENOTUNIQ 76 /* Name not unique on network */
borlanic 0:fbdae7e6d805 284 #undef EBADFD
borlanic 0:fbdae7e6d805 285 #define EBADFD 77 /* File descriptor in bad state */
borlanic 0:fbdae7e6d805 286 #undef EREMCHG
borlanic 0:fbdae7e6d805 287 #define EREMCHG 78 /* Remote address changed */
borlanic 0:fbdae7e6d805 288 #undef ELIBACC
borlanic 0:fbdae7e6d805 289 #define ELIBACC 79 /* Can not access a needed shared library */
borlanic 0:fbdae7e6d805 290 #undef ELIBBAD
borlanic 0:fbdae7e6d805 291 #define ELIBBAD 80 /* Accessing a corrupted shared library */
borlanic 0:fbdae7e6d805 292 #undef ELIBSCN
borlanic 0:fbdae7e6d805 293 #define ELIBSCN 81 /* .lib section in a.out corrupted */
borlanic 0:fbdae7e6d805 294 #undef ELIBMAX
borlanic 0:fbdae7e6d805 295 #define ELIBMAX 82 /* Attempting to link in too many shared libraries */
borlanic 0:fbdae7e6d805 296 #undef ELIBEXEC
borlanic 0:fbdae7e6d805 297 #define ELIBEXEC 83 /* Cannot exec a shared library directly */
borlanic 0:fbdae7e6d805 298 #undef EILSEQ
borlanic 0:fbdae7e6d805 299 #define EILSEQ 84 /* Illegal byte sequence */
borlanic 0:fbdae7e6d805 300 #undef ERESTART
borlanic 0:fbdae7e6d805 301 #define ERESTART 85 /* Interrupted system call should be restarted */
borlanic 0:fbdae7e6d805 302 #undef ESTRPIPE
borlanic 0:fbdae7e6d805 303 #define ESTRPIPE 86 /* Streams pipe error */
borlanic 0:fbdae7e6d805 304 #undef EUSERS
borlanic 0:fbdae7e6d805 305 #define EUSERS 87 /* Too many users */
borlanic 0:fbdae7e6d805 306 #undef ENOTSOCK
borlanic 0:fbdae7e6d805 307 #define ENOTSOCK 88 /* Socket operation on non-socket */
borlanic 0:fbdae7e6d805 308 #undef EDESTADDRREQ
borlanic 0:fbdae7e6d805 309 #define EDESTADDRREQ 89 /* Destination address required */
borlanic 0:fbdae7e6d805 310 #undef EMSGSIZE
borlanic 0:fbdae7e6d805 311 #define EMSGSIZE 90 /* Message too long */
borlanic 0:fbdae7e6d805 312 #undef EPROTOTYPE
borlanic 0:fbdae7e6d805 313 #define EPROTOTYPE 91 /* Protocol wrong type for socket */
borlanic 0:fbdae7e6d805 314 #undef ENOPROTOOPT
borlanic 0:fbdae7e6d805 315 #define ENOPROTOOPT 92 /* Protocol not available */
borlanic 0:fbdae7e6d805 316 #undef EPROTONOSUPPORT
borlanic 0:fbdae7e6d805 317 #define EPROTONOSUPPORT 93 /* Protocol not supported */
borlanic 0:fbdae7e6d805 318 #undef ESOCKTNOSUPPORT
borlanic 0:fbdae7e6d805 319 #define ESOCKTNOSUPPORT 94 /* Socket type not supported */
borlanic 0:fbdae7e6d805 320 #undef EOPNOTSUPP
borlanic 0:fbdae7e6d805 321 #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
borlanic 0:fbdae7e6d805 322 #undef EPFNOSUPPORT
borlanic 0:fbdae7e6d805 323 #define EPFNOSUPPORT 96 /* Protocol family not supported */
borlanic 0:fbdae7e6d805 324 #undef EAFNOSUPPORT
borlanic 0:fbdae7e6d805 325 #define EAFNOSUPPORT 97 /* Address family not supported by protocol */
borlanic 0:fbdae7e6d805 326 #undef EADDRINUSE
borlanic 0:fbdae7e6d805 327 #define EADDRINUSE 98 /* Address already in use */
borlanic 0:fbdae7e6d805 328 #undef EADDRNOTAVAIL
borlanic 0:fbdae7e6d805 329 #define EADDRNOTAVAIL 99 /* Cannot assign requested address */
borlanic 0:fbdae7e6d805 330 #undef ENETDOWN
borlanic 0:fbdae7e6d805 331 #define ENETDOWN 100 /* Network is down */
borlanic 0:fbdae7e6d805 332 #undef ENETUNREACH
borlanic 0:fbdae7e6d805 333 #define ENETUNREACH 101 /* Network is unreachable */
borlanic 0:fbdae7e6d805 334 #undef ENETRESET
borlanic 0:fbdae7e6d805 335 #define ENETRESET 102 /* Network dropped connection because of reset */
borlanic 0:fbdae7e6d805 336 #undef ECONNABORTED
borlanic 0:fbdae7e6d805 337 #define ECONNABORTED 103 /* Software caused connection abort */
borlanic 0:fbdae7e6d805 338 #undef ECONNRESET
borlanic 0:fbdae7e6d805 339 #define ECONNRESET 104 /* Connection reset by peer */
borlanic 0:fbdae7e6d805 340 #undef ENOBUFS
borlanic 0:fbdae7e6d805 341 #define ENOBUFS 105 /* No buffer space available */
borlanic 0:fbdae7e6d805 342 #undef EISCONN
borlanic 0:fbdae7e6d805 343 #define EISCONN 106 /* Transport endpoint is already connected */
borlanic 0:fbdae7e6d805 344 #undef ENOTCONN
borlanic 0:fbdae7e6d805 345 #define ENOTCONN 107 /* Transport endpoint is not connected */
borlanic 0:fbdae7e6d805 346 #undef ESHUTDOWN
borlanic 0:fbdae7e6d805 347 #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
borlanic 0:fbdae7e6d805 348 #undef ETOOMANYREFS
borlanic 0:fbdae7e6d805 349 #define ETOOMANYREFS 109 /* Too many references: cannot splice */
borlanic 0:fbdae7e6d805 350 #undef ETIMEDOUT
borlanic 0:fbdae7e6d805 351 #define ETIMEDOUT 110 /* Connection timed out */
borlanic 0:fbdae7e6d805 352 #undef ECONNREFUSED
borlanic 0:fbdae7e6d805 353 #define ECONNREFUSED 111 /* Connection refused */
borlanic 0:fbdae7e6d805 354 #undef EHOSTDOWN
borlanic 0:fbdae7e6d805 355 #define EHOSTDOWN 112 /* Host is down */
borlanic 0:fbdae7e6d805 356 #undef EHOSTUNREACH
borlanic 0:fbdae7e6d805 357 #define EHOSTUNREACH 113 /* No route to host */
borlanic 0:fbdae7e6d805 358 #undef EALREADY
borlanic 0:fbdae7e6d805 359 #define EALREADY 114 /* Operation already in progress */
borlanic 0:fbdae7e6d805 360 #undef EINPROGRESS
borlanic 0:fbdae7e6d805 361 #define EINPROGRESS 115 /* Operation now in progress */
borlanic 0:fbdae7e6d805 362 #undef ESTALE
borlanic 0:fbdae7e6d805 363 #define ESTALE 116 /* Stale NFS file handle */
borlanic 0:fbdae7e6d805 364 #undef EUCLEAN
borlanic 0:fbdae7e6d805 365 #define EUCLEAN 117 /* Structure needs cleaning */
borlanic 0:fbdae7e6d805 366 #undef ENOTNAM
borlanic 0:fbdae7e6d805 367 #define ENOTNAM 118 /* Not a XENIX named type file */
borlanic 0:fbdae7e6d805 368 #undef ENAVAIL
borlanic 0:fbdae7e6d805 369 #define ENAVAIL 119 /* No XENIX semaphores available */
borlanic 0:fbdae7e6d805 370 #undef EISNAM
borlanic 0:fbdae7e6d805 371 #define EISNAM 120 /* Is a named type file */
borlanic 0:fbdae7e6d805 372 #undef EREMOTEIO
borlanic 0:fbdae7e6d805 373 #define EREMOTEIO 121 /* Remote I/O error */
borlanic 0:fbdae7e6d805 374 #undef EDQUOT
borlanic 0:fbdae7e6d805 375 #define EDQUOT 122 /* Quota exceeded */
borlanic 0:fbdae7e6d805 376 #undef ENOMEDIUM
borlanic 0:fbdae7e6d805 377 #define ENOMEDIUM 123 /* No medium found */
borlanic 0:fbdae7e6d805 378 #undef EMEDIUMTYPE
borlanic 0:fbdae7e6d805 379 #define EMEDIUMTYPE 124 /* Wrong medium type */
borlanic 0:fbdae7e6d805 380 #undef ECANCELED
borlanic 0:fbdae7e6d805 381 #define ECANCELED 125 /* Operation Canceled */
borlanic 0:fbdae7e6d805 382 #undef ENOKEY
borlanic 0:fbdae7e6d805 383 #define ENOKEY 126 /* Required key not available */
borlanic 0:fbdae7e6d805 384 #undef EKEYEXPIRED
borlanic 0:fbdae7e6d805 385 #define EKEYEXPIRED 127 /* Key has expired */
borlanic 0:fbdae7e6d805 386 #undef EKEYREVOKED
borlanic 0:fbdae7e6d805 387 #define EKEYREVOKED 128 /* Key has been revoked */
borlanic 0:fbdae7e6d805 388 #undef EKEYREJECTED
borlanic 0:fbdae7e6d805 389 #define EKEYREJECTED 129 /* Key was rejected by service */
borlanic 0:fbdae7e6d805 390 #undef EOWNERDEAD
borlanic 0:fbdae7e6d805 391 #define EOWNERDEAD 130 /* Owner died */
borlanic 0:fbdae7e6d805 392 #undef ENOTRECOVERABLE
borlanic 0:fbdae7e6d805 393 #define ENOTRECOVERABLE 131 /* State not recoverable */
borlanic 0:fbdae7e6d805 394
borlanic 0:fbdae7e6d805 395 /* Missing stat.h defines.
borlanic 0:fbdae7e6d805 396 * The following are sys/stat.h definitions not currently present in the ARMCC
borlanic 0:fbdae7e6d805 397 * errno.h. Note, ARMCC errno.h defines some symbol values differing from
borlanic 0:fbdae7e6d805 398 * GCC_ARM/IAR/standard POSIX definitions. Guard against this and future
borlanic 0:fbdae7e6d805 399 * changes by changing the symbol definition for filesystem use.
borlanic 0:fbdae7e6d805 400 */
borlanic 0:fbdae7e6d805 401 #define _IFMT 0170000 //< type of file
borlanic 0:fbdae7e6d805 402 #define _IFSOCK 0140000 //< socket
borlanic 0:fbdae7e6d805 403 #define _IFLNK 0120000 //< symbolic link
borlanic 0:fbdae7e6d805 404 #define _IFREG 0100000 //< regular
borlanic 0:fbdae7e6d805 405 #define _IFBLK 0060000 //< block special
borlanic 0:fbdae7e6d805 406 #define _IFDIR 0040000 //< directory
borlanic 0:fbdae7e6d805 407 #define _IFCHR 0020000 //< character special
borlanic 0:fbdae7e6d805 408 #define _IFIFO 0010000 //< fifo special
borlanic 0:fbdae7e6d805 409
borlanic 0:fbdae7e6d805 410 #define S_IFMT _IFMT //< type of file
borlanic 0:fbdae7e6d805 411 #define S_IFSOCK _IFSOCK //< socket
borlanic 0:fbdae7e6d805 412 #define S_IFLNK _IFLNK //< symbolic link
borlanic 0:fbdae7e6d805 413 #define S_IFREG _IFREG //< regular
borlanic 0:fbdae7e6d805 414 #define S_IFBLK _IFBLK //< block special
borlanic 0:fbdae7e6d805 415 #define S_IFDIR _IFDIR //< directory
borlanic 0:fbdae7e6d805 416 #define S_IFCHR _IFCHR //< character special
borlanic 0:fbdae7e6d805 417 #define S_IFIFO _IFIFO //< fifo special
borlanic 0:fbdae7e6d805 418
borlanic 0:fbdae7e6d805 419 #define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
borlanic 0:fbdae7e6d805 420 #define S_IRUSR 0000400 ///< read permission, owner
borlanic 0:fbdae7e6d805 421 #define S_IWUSR 0000200 ///< write permission, owner
borlanic 0:fbdae7e6d805 422 #define S_IXUSR 0000100 ///< execute/search permission, owner
borlanic 0:fbdae7e6d805 423 #define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
borlanic 0:fbdae7e6d805 424 #define S_IRGRP 0000040 ///< read permission, group
borlanic 0:fbdae7e6d805 425 #define S_IWGRP 0000020 ///< write permission, group
borlanic 0:fbdae7e6d805 426 #define S_IXGRP 0000010 ///< execute/search permission, group
borlanic 0:fbdae7e6d805 427 #define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
borlanic 0:fbdae7e6d805 428 #define S_IROTH 0000004 ///< read permission, other
borlanic 0:fbdae7e6d805 429 #define S_IWOTH 0000002 ///< write permission, other
borlanic 0:fbdae7e6d805 430 #define S_IXOTH 0000001 ///< execute/search permission, other
borlanic 0:fbdae7e6d805 431
borlanic 0:fbdae7e6d805 432 /* Refer to sys/stat standard
borlanic 0:fbdae7e6d805 433 * Note: Not all fields may be supported by the underlying filesystem
borlanic 0:fbdae7e6d805 434 */
borlanic 0:fbdae7e6d805 435 struct stat {
borlanic 0:fbdae7e6d805 436 dev_t st_dev; ///< Device ID containing file
borlanic 0:fbdae7e6d805 437 ino_t st_ino; ///< File serial number
borlanic 0:fbdae7e6d805 438 mode_t st_mode; ///< Mode of file
borlanic 0:fbdae7e6d805 439 nlink_t st_nlink; ///< Number of links to file
borlanic 0:fbdae7e6d805 440
borlanic 0:fbdae7e6d805 441 uid_t st_uid; ///< User ID
borlanic 0:fbdae7e6d805 442 gid_t st_gid; ///< Group ID
borlanic 0:fbdae7e6d805 443
borlanic 0:fbdae7e6d805 444 off_t st_size; ///< Size of file in bytes
borlanic 0:fbdae7e6d805 445
borlanic 0:fbdae7e6d805 446 time_t st_atime; ///< Time of last access
borlanic 0:fbdae7e6d805 447 time_t st_mtime; ///< Time of last data modification
borlanic 0:fbdae7e6d805 448 time_t st_ctime; ///< Time of last status change
borlanic 0:fbdae7e6d805 449 };
borlanic 0:fbdae7e6d805 450
borlanic 0:fbdae7e6d805 451 struct statvfs {
borlanic 0:fbdae7e6d805 452 unsigned long f_bsize; ///< Filesystem block size
borlanic 0:fbdae7e6d805 453 unsigned long f_frsize; ///< Fragment size (block size)
borlanic 0:fbdae7e6d805 454
borlanic 0:fbdae7e6d805 455 fsblkcnt_t f_blocks; ///< Number of blocks
borlanic 0:fbdae7e6d805 456 fsblkcnt_t f_bfree; ///< Number of free blocks
borlanic 0:fbdae7e6d805 457 fsblkcnt_t f_bavail; ///< Number of free blocks for unprivileged users
borlanic 0:fbdae7e6d805 458
borlanic 0:fbdae7e6d805 459 unsigned long f_fsid; ///< Filesystem ID
borlanic 0:fbdae7e6d805 460
borlanic 0:fbdae7e6d805 461 unsigned long f_namemax; ///< Maximum filename length
borlanic 0:fbdae7e6d805 462 };
borlanic 0:fbdae7e6d805 463
borlanic 0:fbdae7e6d805 464 /* The following are dirent.h definitions are declared here to guarantee
borlanic 0:fbdae7e6d805 465 * consistency where structure may be different with different toolchains
borlanic 0:fbdae7e6d805 466 */
borlanic 0:fbdae7e6d805 467 struct dirent {
borlanic 0:fbdae7e6d805 468 char d_name[NAME_MAX+1]; ///< Name of file
borlanic 0:fbdae7e6d805 469 uint8_t d_type; ///< Type of file
borlanic 0:fbdae7e6d805 470 };
borlanic 0:fbdae7e6d805 471
borlanic 0:fbdae7e6d805 472 enum {
borlanic 0:fbdae7e6d805 473 DT_UNKNOWN, ///< The file type could not be determined.
borlanic 0:fbdae7e6d805 474 DT_FIFO, ///< This is a named pipe (FIFO).
borlanic 0:fbdae7e6d805 475 DT_CHR, ///< This is a character device.
borlanic 0:fbdae7e6d805 476 DT_DIR, ///< This is a directory.
borlanic 0:fbdae7e6d805 477 DT_BLK, ///< This is a block device.
borlanic 0:fbdae7e6d805 478 DT_REG, ///< This is a regular file.
borlanic 0:fbdae7e6d805 479 DT_LNK, ///< This is a symbolic link.
borlanic 0:fbdae7e6d805 480 DT_SOCK, ///< This is a UNIX domain socket.
borlanic 0:fbdae7e6d805 481 };
borlanic 0:fbdae7e6d805 482
borlanic 0:fbdae7e6d805 483 struct pollfd {
borlanic 0:fbdae7e6d805 484 int fd;
borlanic 0:fbdae7e6d805 485 short events;
borlanic 0:fbdae7e6d805 486 short revents;
borlanic 0:fbdae7e6d805 487 };
borlanic 0:fbdae7e6d805 488
borlanic 0:fbdae7e6d805 489 /* POSIX-compatible I/O functions */
borlanic 0:fbdae7e6d805 490 #if __cplusplus
borlanic 0:fbdae7e6d805 491 extern "C" {
borlanic 0:fbdae7e6d805 492 #endif
borlanic 0:fbdae7e6d805 493 int open(const char *path, int oflag, ...);
borlanic 0:fbdae7e6d805 494 #ifndef __IAR_SYSTEMS_ICC__ /* IAR provides fdopen itself */
borlanic 0:fbdae7e6d805 495 #if __cplusplus
borlanic 0:fbdae7e6d805 496 std::FILE* fdopen(int fildes, const char *mode);
borlanic 0:fbdae7e6d805 497 #else
borlanic 0:fbdae7e6d805 498 FILE* fdopen(int fildes, const char *mode);
borlanic 0:fbdae7e6d805 499 #endif
borlanic 0:fbdae7e6d805 500 #endif
borlanic 0:fbdae7e6d805 501 ssize_t write(int fildes, const void *buf, size_t nbyte);
borlanic 0:fbdae7e6d805 502 ssize_t read(int fildes, void *buf, size_t nbyte);
borlanic 0:fbdae7e6d805 503 off_t lseek(int fildes, off_t offset, int whence);
borlanic 0:fbdae7e6d805 504 int isatty(int fildes);
borlanic 0:fbdae7e6d805 505 int fsync(int fildes);
borlanic 0:fbdae7e6d805 506 int fstat(int fh, struct stat *st);
borlanic 0:fbdae7e6d805 507 int poll(struct pollfd fds[], nfds_t nfds, int timeout);
borlanic 0:fbdae7e6d805 508 int close(int fildes);
borlanic 0:fbdae7e6d805 509 int stat(const char *path, struct stat *st);
borlanic 0:fbdae7e6d805 510 int statvfs(const char *path, struct statvfs *buf);
borlanic 0:fbdae7e6d805 511 DIR *opendir(const char*);
borlanic 0:fbdae7e6d805 512 struct dirent *readdir(DIR *);
borlanic 0:fbdae7e6d805 513 int closedir(DIR*);
borlanic 0:fbdae7e6d805 514 void rewinddir(DIR*);
borlanic 0:fbdae7e6d805 515 long telldir(DIR*);
borlanic 0:fbdae7e6d805 516 void seekdir(DIR*, long);
borlanic 0:fbdae7e6d805 517 int mkdir(const char *name, mode_t n);
borlanic 0:fbdae7e6d805 518 #if __cplusplus
borlanic 0:fbdae7e6d805 519 }; // extern "C"
borlanic 0:fbdae7e6d805 520
borlanic 0:fbdae7e6d805 521 namespace mbed {
borlanic 0:fbdae7e6d805 522
borlanic 0:fbdae7e6d805 523 /** This call is an analogue to POSIX fdopen().
borlanic 0:fbdae7e6d805 524 *
borlanic 0:fbdae7e6d805 525 * It associates a C stream to an already-opened FileHandle, to allow you to
borlanic 0:fbdae7e6d805 526 * use C printf/scanf/fwrite etc. The provided FileHandle must remain open -
borlanic 0:fbdae7e6d805 527 * it will be closed by the C library when fclose(FILE) is called.
borlanic 0:fbdae7e6d805 528 *
borlanic 0:fbdae7e6d805 529 * The net effect is fdopen(bind_to_fd(fh), mode), with error handling.
borlanic 0:fbdae7e6d805 530 *
borlanic 0:fbdae7e6d805 531 * @param fh a pointer to an opened FileHandle
borlanic 0:fbdae7e6d805 532 * @param mode operation upon the file descriptor, e.g., "w+"
borlanic 0:fbdae7e6d805 533 *
borlanic 0:fbdae7e6d805 534 * @returns a pointer to FILE
borlanic 0:fbdae7e6d805 535 */
borlanic 0:fbdae7e6d805 536 std::FILE* fdopen(mbed::FileHandle *fh, const char *mode);
borlanic 0:fbdae7e6d805 537
borlanic 0:fbdae7e6d805 538 /** Bind an mbed FileHandle to a POSIX file descriptor
borlanic 0:fbdae7e6d805 539 *
borlanic 0:fbdae7e6d805 540 * This is similar to fdopen, but only operating at the POSIX layer - it
borlanic 0:fbdae7e6d805 541 * associates a POSIX integer file descriptor with a FileHandle, to allow you
borlanic 0:fbdae7e6d805 542 * to use POSIX read/write calls etc. The provided FileHandle must remain open -
borlanic 0:fbdae7e6d805 543 * it will be closed when close(int) is called.
borlanic 0:fbdae7e6d805 544 *
borlanic 0:fbdae7e6d805 545 * @param fh a pointer to an opened FileHandle
borlanic 0:fbdae7e6d805 546 *
borlanic 0:fbdae7e6d805 547 * @return an integer file descriptor, or negative if no descriptors available
borlanic 0:fbdae7e6d805 548 */
borlanic 0:fbdae7e6d805 549 int bind_to_fd(mbed::FileHandle *fh);
borlanic 0:fbdae7e6d805 550
borlanic 0:fbdae7e6d805 551 } // namespace mbed
borlanic 0:fbdae7e6d805 552
borlanic 0:fbdae7e6d805 553 #endif // __cplusplus
borlanic 0:fbdae7e6d805 554
borlanic 0:fbdae7e6d805 555 /**@}*/
borlanic 0:fbdae7e6d805 556
borlanic 0:fbdae7e6d805 557 /**@}*/
borlanic 0:fbdae7e6d805 558
borlanic 0:fbdae7e6d805 559 #endif /* RETARGET_H */