Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sat Jun 03 00:22:44 2017 +0000
Revision:
46:b156ef445742
Parent:
18:6a4db94011d3
Final code for internal battlebot competition.

Who changed what in which revision?

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