The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
Kojto
Date:
Wed Jul 19 16:46:19 2017 +0100
Revision:
147:a97add6d7e64
Parent:
145:64910690c574
Child:
152:235179ab3f27
Release 147 of the mbed library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 138:093f2bd7b9eb 1 /*
<> 138:093f2bd7b9eb 2 * mbed Microcontroller Library
<> 138:093f2bd7b9eb 3 * Copyright (c) 2006-2016 ARM Limited
<> 138:093f2bd7b9eb 4 *
<> 138:093f2bd7b9eb 5 * Licensed under the Apache License, Version 2.0 (the "License");
<> 138:093f2bd7b9eb 6 * you may not use this file except in compliance with the License.
<> 138:093f2bd7b9eb 7 * You may obtain a copy of the License at
<> 138:093f2bd7b9eb 8 *
<> 138:093f2bd7b9eb 9 * http://www.apache.org/licenses/LICENSE-2.0
<> 138:093f2bd7b9eb 10 *
<> 138:093f2bd7b9eb 11 * Unless required by applicable law or agreed to in writing, software
<> 138:093f2bd7b9eb 12 * distributed under the License is distributed on an "AS IS" BASIS,
<> 138:093f2bd7b9eb 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 138:093f2bd7b9eb 14 * See the License for the specific language governing permissions and
<> 138:093f2bd7b9eb 15 * limitations under the License.
<> 138:093f2bd7b9eb 16 *
<> 138:093f2bd7b9eb 17 */
<> 138:093f2bd7b9eb 18
<> 138:093f2bd7b9eb 19 #ifndef RETARGET_H
<> 138:093f2bd7b9eb 20 #define RETARGET_H
<> 138:093f2bd7b9eb 21
AnnaBridge 145:64910690c574 22 #if __cplusplus
AnnaBridge 145:64910690c574 23 #include <cstdio>
AnnaBridge 145:64910690c574 24 #endif //__cplusplus
<> 138:093f2bd7b9eb 25 #include <stdint.h>
<> 138:093f2bd7b9eb 26 #include <stddef.h>
<> 138:093f2bd7b9eb 27
<> 138:093f2bd7b9eb 28 /* We can get the following standard types from sys/types for gcc, but we
<> 138:093f2bd7b9eb 29 * need to define the types ourselves for the other compilers that normally
<> 138:093f2bd7b9eb 30 * target embedded systems */
<> 138:093f2bd7b9eb 31 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
<> 138:093f2bd7b9eb 32 typedef int ssize_t; ///< Signed size type, usually encodes negative errors
<> 138:093f2bd7b9eb 33 typedef long off_t; ///< Offset in a data stream
<> 138:093f2bd7b9eb 34 typedef int mode_t; ///< Mode for opening files
<> 138:093f2bd7b9eb 35
<> 138:093f2bd7b9eb 36 #define O_RDONLY 0
<> 138:093f2bd7b9eb 37 #define O_WRONLY 1
<> 138:093f2bd7b9eb 38 #define O_RDWR 2
<> 138:093f2bd7b9eb 39 #define O_CREAT 0x0200
<> 138:093f2bd7b9eb 40 #define O_TRUNC 0x0400
<> 138:093f2bd7b9eb 41 #define O_APPEND 0x0008
<> 138:093f2bd7b9eb 42
<> 138:093f2bd7b9eb 43 #define NAME_MAX 255 ///< Maximum size of a name in a file path
<> 138:093f2bd7b9eb 44
<> 138:093f2bd7b9eb 45 #else
<> 138:093f2bd7b9eb 46 #include <sys/fcntl.h>
<> 138:093f2bd7b9eb 47 #include <sys/types.h>
<> 138:093f2bd7b9eb 48 #include <sys/syslimits.h>
<> 138:093f2bd7b9eb 49 #endif
<> 138:093f2bd7b9eb 50
<> 138:093f2bd7b9eb 51
<> 138:093f2bd7b9eb 52 /* DIR declarations must also be here */
<> 138:093f2bd7b9eb 53 #if __cplusplus
AnnaBridge 145:64910690c574 54 namespace mbed {
AnnaBridge 145:64910690c574 55 class FileHandle;
AnnaBridge 145:64910690c574 56 class DirHandle;
AnnaBridge 145:64910690c574 57 std::FILE *mbed_fdopen(FileHandle *fh, const char *mode);
AnnaBridge 145:64910690c574 58 }
AnnaBridge 145:64910690c574 59 typedef mbed::DirHandle DIR;
<> 139:856d2700e60b 60 #else
<> 139:856d2700e60b 61 typedef struct Dir DIR;
<> 139:856d2700e60b 62 #endif
<> 138:093f2bd7b9eb 63
<> 139:856d2700e60b 64 #if __cplusplus
<> 138:093f2bd7b9eb 65 extern "C" {
<> 139:856d2700e60b 66 #endif
<> 138:093f2bd7b9eb 67 DIR *opendir(const char*);
<> 138:093f2bd7b9eb 68 struct dirent *readdir(DIR *);
<> 138:093f2bd7b9eb 69 int closedir(DIR*);
<> 138:093f2bd7b9eb 70 void rewinddir(DIR*);
<> 138:093f2bd7b9eb 71 long telldir(DIR*);
<> 138:093f2bd7b9eb 72 void seekdir(DIR*, long);
<> 138:093f2bd7b9eb 73 int mkdir(const char *name, mode_t n);
<> 139:856d2700e60b 74 #if __cplusplus
<> 138:093f2bd7b9eb 75 };
<> 138:093f2bd7b9eb 76 #endif
<> 138:093f2bd7b9eb 77
<> 138:093f2bd7b9eb 78
<> 138:093f2bd7b9eb 79 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
<> 138:093f2bd7b9eb 80 /* The intent of this section is to unify the errno error values to match
<> 138:093f2bd7b9eb 81 * the POSIX definitions for the GCC_ARM, ARMCC and IAR compilers. This is
<> 138:093f2bd7b9eb 82 * necessary because the ARMCC/IAR errno.h, or sys/stat.h are missing some
<> 138:093f2bd7b9eb 83 * symbol definitions used by the POSIX filesystem API to return errno codes.
<> 138:093f2bd7b9eb 84 * Note also that ARMCC errno.h defines some symbol values differently from
<> 138:093f2bd7b9eb 85 * the GCC_ARM/IAR/standard POSIX definitions. The definitions guard against
<> 138:093f2bd7b9eb 86 * this and future changes by changing the symbol definition as shown below. */
<> 138:093f2bd7b9eb 87 #undef ENOENT
<> 138:093f2bd7b9eb 88 #define ENOENT 2 /* No such file or directory. */
<> 138:093f2bd7b9eb 89
<> 138:093f2bd7b9eb 90 #undef EIO
<> 138:093f2bd7b9eb 91 #define EIO 5 /* I/O error */
<> 138:093f2bd7b9eb 92
<> 138:093f2bd7b9eb 93 #undef ENXIO
<> 138:093f2bd7b9eb 94 #define ENXIO 6 /* No such device or address */
<> 138:093f2bd7b9eb 95
<> 138:093f2bd7b9eb 96 #undef ENOEXEC
<> 138:093f2bd7b9eb 97 #define ENOEXEC 8 /* Exec format error */
<> 138:093f2bd7b9eb 98
<> 138:093f2bd7b9eb 99 #undef EBADF
<> 138:093f2bd7b9eb 100 #define EBADF 9 /* Bad file number */
<> 138:093f2bd7b9eb 101
AnnaBridge 145:64910690c574 102 #undef EAGAIN
AnnaBridge 145:64910690c574 103 #define EAGAIN 11 /* Resource unavailable, try again */
AnnaBridge 145:64910690c574 104
AnnaBridge 145:64910690c574 105 #undef EWOULDBLOCK
AnnaBridge 145:64910690c574 106 #define EWOULDBLOCK EAGAIN /* Operation would block */
AnnaBridge 145:64910690c574 107
<> 138:093f2bd7b9eb 108 #undef ENOMEM
<> 138:093f2bd7b9eb 109 #define ENOMEM 12 /* Not enough space */
<> 138:093f2bd7b9eb 110
<> 138:093f2bd7b9eb 111 #undef EACCES
<> 138:093f2bd7b9eb 112 #define EACCES 13 /* Permission denied */
<> 138:093f2bd7b9eb 113
<> 138:093f2bd7b9eb 114 #undef EFAULT
<> 138:093f2bd7b9eb 115 #define EFAULT 14 /* Bad address */
<> 138:093f2bd7b9eb 116
<> 138:093f2bd7b9eb 117 #undef EEXIST
<> 138:093f2bd7b9eb 118 #define EEXIST 17 /* File exists */
<> 138:093f2bd7b9eb 119
AnnaBridge 145:64910690c574 120 #undef EXDEV
AnnaBridge 145:64910690c574 121 #define EXDEV 18 /* Cross-device link */
AnnaBridge 145:64910690c574 122
<> 138:093f2bd7b9eb 123 #undef EINVAL
<> 138:093f2bd7b9eb 124 #define EINVAL 22 /* Invalid argument */
<> 138:093f2bd7b9eb 125
<> 138:093f2bd7b9eb 126 #undef ENFILE
<> 138:093f2bd7b9eb 127 #define ENFILE 23 /* Too many open files in system */
<> 138:093f2bd7b9eb 128
<> 138:093f2bd7b9eb 129 #undef EMFILE
<> 138:093f2bd7b9eb 130 #define EMFILE 24 /* File descriptor value too large */
<> 138:093f2bd7b9eb 131
AnnaBridge 145:64910690c574 132 #undef ESPIPE
AnnaBridge 145:64910690c574 133 #define ESPIPE 29 /* Invalid seek */
AnnaBridge 145:64910690c574 134
<> 138:093f2bd7b9eb 135 #undef ENOSYS
<> 138:093f2bd7b9eb 136 #define ENOSYS 38 /* Function not implemented */
<> 138:093f2bd7b9eb 137
AnnaBridge 145:64910690c574 138 #undef EOVERFLOW
AnnaBridge 145:64910690c574 139 #define EOVERFLOW 75 /* Value too large to be stored in data type */
AnnaBridge 145:64910690c574 140
<> 138:093f2bd7b9eb 141 /* Missing stat.h defines.
<> 138:093f2bd7b9eb 142 * The following are sys/stat.h definitions not currently present in the ARMCC
<> 138:093f2bd7b9eb 143 * errno.h. Note, ARMCC errno.h defines some symbol values differing from
<> 138:093f2bd7b9eb 144 * GCC_ARM/IAR/standard POSIX definitions. Guard against this and future
<> 138:093f2bd7b9eb 145 * changes by changing the symbol definition for filesystem use. */
<> 138:093f2bd7b9eb 146 #define _IFDIR 0040000 /* directory */
<> 138:093f2bd7b9eb 147 #define _IFREG 0100000 /* regular */
<> 138:093f2bd7b9eb 148
<> 138:093f2bd7b9eb 149 #define S_IFDIR _IFDIR
<> 138:093f2bd7b9eb 150 #define S_IFREG _IFREG
<> 138:093f2bd7b9eb 151
<> 138:093f2bd7b9eb 152 #define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
<> 138:093f2bd7b9eb 153 #define S_IRUSR 0000400 /* read permission, owner */
<> 138:093f2bd7b9eb 154 #define S_IWUSR 0000200 /* write permission, owner */
<> 138:093f2bd7b9eb 155 #define S_IXUSR 0000100/* execute/search permission, owner */
<> 138:093f2bd7b9eb 156 #define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
<> 138:093f2bd7b9eb 157 #define S_IRGRP 0000040 /* read permission, group */
<> 138:093f2bd7b9eb 158 #define S_IWGRP 0000020 /* write permission, grougroup */
<> 138:093f2bd7b9eb 159 #define S_IXGRP 0000010/* execute/search permission, group */
<> 138:093f2bd7b9eb 160 #define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
<> 138:093f2bd7b9eb 161 #define S_IROTH 0000004 /* read permission, other */
<> 138:093f2bd7b9eb 162 #define S_IWOTH 0000002 /* write permission, other */
<> 138:093f2bd7b9eb 163 #define S_IXOTH 0000001/* execute/search permission, other */
<> 138:093f2bd7b9eb 164
<> 138:093f2bd7b9eb 165 #endif /* defined(__ARMCC_VERSION) || defined(__ICCARM__) */
<> 138:093f2bd7b9eb 166
<> 138:093f2bd7b9eb 167
<> 138:093f2bd7b9eb 168 /* The following are dirent.h definitions are declared here to garuntee
<> 138:093f2bd7b9eb 169 * consistency where structure may be different with different toolchains */
<> 138:093f2bd7b9eb 170 struct dirent {
<> 138:093f2bd7b9eb 171 char d_name[NAME_MAX+1];
<> 138:093f2bd7b9eb 172 uint8_t d_type;
<> 138:093f2bd7b9eb 173 };
<> 138:093f2bd7b9eb 174
<> 138:093f2bd7b9eb 175 enum {
<> 138:093f2bd7b9eb 176 DT_UNKNOWN, // The file type could not be determined.
<> 138:093f2bd7b9eb 177 DT_FIFO, // This is a named pipe (FIFO).
<> 138:093f2bd7b9eb 178 DT_CHR, // This is a character device.
<> 138:093f2bd7b9eb 179 DT_DIR, // This is a directory.
<> 138:093f2bd7b9eb 180 DT_BLK, // This is a block device.
<> 138:093f2bd7b9eb 181 DT_REG, // This is a regular file.
<> 138:093f2bd7b9eb 182 DT_LNK, // This is a symbolic link.
<> 138:093f2bd7b9eb 183 DT_SOCK, // This is a UNIX domain socket.
<> 138:093f2bd7b9eb 184 };
<> 138:093f2bd7b9eb 185
<> 138:093f2bd7b9eb 186 #endif /* RETARGET_H */