Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mbed_retarget.h Source File

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 #include <stdint.h>
00023 #include <stddef.h>
00024 
00025 /* We can get the following standard types from sys/types for gcc, but we
00026  * need to define the types ourselves for the other compilers that normally
00027  * target embedded systems */
00028 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
00029 typedef int ssize_t;    ///< Signed size type, usually encodes negative errors
00030 typedef long off_t;     ///< Offset in a data stream
00031 typedef int mode_t;     ///< Mode for opening files
00032 
00033 #define O_RDONLY 0
00034 #define O_WRONLY 1
00035 #define O_RDWR   2
00036 #define O_CREAT  0x0200
00037 #define O_TRUNC  0x0400
00038 #define O_APPEND 0x0008
00039 
00040 #define NAME_MAX 255    ///< Maximum size of a name in a file path
00041 
00042 #else
00043 #include <sys/fcntl.h>
00044 #include <sys/types.h>
00045 #include <sys/syslimits.h>
00046 #endif
00047 
00048 
00049 /* DIR declarations must also be here */
00050 #if __cplusplus
00051 namespace mbed { class Dir; }
00052 typedef mbed::Dir DIR;
00053 #else
00054 typedef struct Dir DIR;
00055 #endif
00056 
00057 #if __cplusplus
00058 extern "C" {
00059 #endif
00060     DIR *opendir(const char*);
00061     struct dirent *readdir(DIR *);
00062     int closedir(DIR*);
00063     void rewinddir(DIR*);
00064     long telldir(DIR*);
00065     void seekdir(DIR*, long);
00066     int mkdir(const char *name, mode_t n);
00067 #if __cplusplus
00068 };
00069 #endif
00070 
00071 
00072 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
00073 /* The intent of this section is to unify the errno error values to match
00074  * the POSIX definitions for the GCC_ARM, ARMCC and IAR compilers. This is
00075  * necessary because the ARMCC/IAR errno.h, or sys/stat.h are missing some
00076  * symbol definitions used by the POSIX filesystem API to return errno codes.
00077  * Note also that ARMCC errno.h defines some symbol values differently from
00078  * the GCC_ARM/IAR/standard POSIX definitions. The definitions guard against
00079  * this and future changes by changing the symbol definition as shown below. */
00080 #ifdef ENOENT
00081 #undef ENOENT
00082 #endif
00083 #define ENOENT      2       /* No such file or directory. */
00084 
00085 #ifdef EIO
00086 #undef EIO
00087 #endif
00088 #define EIO         5       /* I/O error */
00089 
00090 #ifdef ENXIO
00091 #undef ENXIO
00092 #endif
00093 #define ENXIO       6       /* No such device or address */
00094 
00095 #ifdef ENOEXEC
00096 #undef ENOEXEC
00097 #endif
00098 #define ENOEXEC     8       /* Exec format error */
00099 
00100 #ifdef EBADF
00101 #undef EBADF
00102 #endif
00103 #define EBADF       9       /* Bad file number */
00104 
00105 #ifdef ENOMEM
00106 #undef ENOMEM
00107 #endif
00108 #define ENOMEM      12      /* Not enough space */
00109 
00110 #ifdef EACCES
00111 #undef EACCES
00112 #endif
00113 #define EACCES      13      /* Permission denied */
00114 
00115 #ifdef EFAULT
00116 #undef EFAULT
00117 #endif
00118 #define EFAULT      14      /* Bad address */
00119 
00120 #ifdef EEXIST
00121 #undef EEXIST
00122 #endif
00123 #define EEXIST      17      /* File exists */
00124 
00125 #ifdef EINVAL
00126 #undef EINVAL
00127 #endif
00128 #define EINVAL      22      /* Invalid argument */
00129 
00130 #ifdef ENFILE
00131 #undef ENFILE
00132 #endif
00133 #define ENFILE      23      /* Too many open files in system */
00134 
00135 #ifdef EMFILE
00136 #undef EMFILE
00137 #endif
00138 #define EMFILE      24      /* File descriptor value too large */
00139 
00140 #ifdef ENOSYS
00141 #undef ENOSYS
00142 #endif
00143 #define ENOSYS      38      /* Function not implemented */
00144 
00145 /* Missing stat.h defines.
00146  * The following are sys/stat.h definitions not currently present in the ARMCC
00147  * errno.h. Note, ARMCC errno.h defines some symbol values differing from
00148  * GCC_ARM/IAR/standard POSIX definitions. Guard against this and future
00149  * changes by changing the symbol definition for filesystem use. */
00150 #define     _IFDIR  0040000 /* directory */
00151 #define     _IFREG  0100000 /* regular */
00152 
00153 #define S_IFDIR     _IFDIR
00154 #define S_IFREG     _IFREG
00155 
00156 #define S_IRWXU     (S_IRUSR | S_IWUSR | S_IXUSR)
00157 #define     S_IRUSR 0000400 /* read permission, owner */
00158 #define     S_IWUSR 0000200 /* write permission, owner */
00159 #define     S_IXUSR 0000100/* execute/search permission, owner */
00160 #define S_IRWXG     (S_IRGRP | S_IWGRP | S_IXGRP)
00161 #define     S_IRGRP 0000040 /* read permission, group */
00162 #define     S_IWGRP 0000020 /* write permission, grougroup */
00163 #define     S_IXGRP 0000010/* execute/search permission, group */
00164 #define S_IRWXO     (S_IROTH | S_IWOTH | S_IXOTH)
00165 #define     S_IROTH 0000004 /* read permission, other */
00166 #define     S_IWOTH 0000002 /* write permission, other */
00167 #define     S_IXOTH 0000001/* execute/search permission, other */
00168 
00169 #endif /* defined(__ARMCC_VERSION) || defined(__ICCARM__) */
00170 
00171 
00172 /* The following are dirent.h definitions are declared here to garuntee
00173  * consistency where structure may be different with different toolchains */
00174 struct dirent {
00175     char d_name[NAME_MAX+1];
00176     uint8_t d_type;
00177 };
00178 
00179 enum {
00180     DT_UNKNOWN, // The file type could not be determined.
00181     DT_FIFO,    // This is a named pipe (FIFO).
00182     DT_CHR,     // This is a character device.
00183     DT_DIR,     // This is a directory.
00184     DT_BLK,     // This is a block device.
00185     DT_REG,     // This is a regular file.
00186     DT_LNK,     // This is a symbolic link.
00187     DT_SOCK,    // This is a UNIX domain socket.
00188 };
00189 
00190 
00191 #endif /* RETARGET_H */