mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
pmcorreia
Date:
Tue Oct 09 14:42:37 2018 +0000
Revision:
187:fa51feb62426
Parent:
186:707f6e361f3e
Updated version to work with F446RE

Who changed what in which revision?

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