fix nrf51822 i2c & spi conflict
Dependencies: BLE_API eMPL_MPU6050 nRF51822
Fork of Seeed_Tiny_BLE_Flash by
mbed-src/api/FileHandle.h@5:b8c02645e6af, 2015-11-17 (annotated)
- Committer:
- yihui
- Date:
- Tue Nov 17 07:48:56 2015 +0000
- Revision:
- 5:b8c02645e6af
fix i2c & spi conflict
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yihui | 5:b8c02645e6af | 1 | /* mbed Microcontroller Library |
yihui | 5:b8c02645e6af | 2 | * Copyright (c) 2006-2013 ARM Limited |
yihui | 5:b8c02645e6af | 3 | * |
yihui | 5:b8c02645e6af | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
yihui | 5:b8c02645e6af | 5 | * you may not use this file except in compliance with the License. |
yihui | 5:b8c02645e6af | 6 | * You may obtain a copy of the License at |
yihui | 5:b8c02645e6af | 7 | * |
yihui | 5:b8c02645e6af | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
yihui | 5:b8c02645e6af | 9 | * |
yihui | 5:b8c02645e6af | 10 | * Unless required by applicable law or agreed to in writing, software |
yihui | 5:b8c02645e6af | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
yihui | 5:b8c02645e6af | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
yihui | 5:b8c02645e6af | 13 | * See the License for the specific language governing permissions and |
yihui | 5:b8c02645e6af | 14 | * limitations under the License. |
yihui | 5:b8c02645e6af | 15 | */ |
yihui | 5:b8c02645e6af | 16 | #ifndef MBED_FILEHANDLE_H |
yihui | 5:b8c02645e6af | 17 | #define MBED_FILEHANDLE_H |
yihui | 5:b8c02645e6af | 18 | |
yihui | 5:b8c02645e6af | 19 | typedef int FILEHANDLE; |
yihui | 5:b8c02645e6af | 20 | |
yihui | 5:b8c02645e6af | 21 | #include <stdio.h> |
yihui | 5:b8c02645e6af | 22 | |
yihui | 5:b8c02645e6af | 23 | #if defined(__ARMCC_VERSION) || defined(__ICCARM__) |
yihui | 5:b8c02645e6af | 24 | typedef int ssize_t; |
yihui | 5:b8c02645e6af | 25 | typedef long off_t; |
yihui | 5:b8c02645e6af | 26 | |
yihui | 5:b8c02645e6af | 27 | #else |
yihui | 5:b8c02645e6af | 28 | # include <sys/types.h> |
yihui | 5:b8c02645e6af | 29 | #endif |
yihui | 5:b8c02645e6af | 30 | |
yihui | 5:b8c02645e6af | 31 | namespace mbed { |
yihui | 5:b8c02645e6af | 32 | |
yihui | 5:b8c02645e6af | 33 | /** An OO equivalent of the internal FILEHANDLE variable |
yihui | 5:b8c02645e6af | 34 | * and associated _sys_* functions. |
yihui | 5:b8c02645e6af | 35 | * |
yihui | 5:b8c02645e6af | 36 | * FileHandle is an abstract class, needing at least sys_write and |
yihui | 5:b8c02645e6af | 37 | * sys_read to be implmented for a simple interactive device. |
yihui | 5:b8c02645e6af | 38 | * |
yihui | 5:b8c02645e6af | 39 | * No one ever directly tals to/instanciates a FileHandle - it gets |
yihui | 5:b8c02645e6af | 40 | * created by FileSystem, and wrapped up by stdio. |
yihui | 5:b8c02645e6af | 41 | */ |
yihui | 5:b8c02645e6af | 42 | class FileHandle { |
yihui | 5:b8c02645e6af | 43 | |
yihui | 5:b8c02645e6af | 44 | public: |
yihui | 5:b8c02645e6af | 45 | /** Write the contents of a buffer to the file |
yihui | 5:b8c02645e6af | 46 | * |
yihui | 5:b8c02645e6af | 47 | * @param buffer the buffer to write from |
yihui | 5:b8c02645e6af | 48 | * @param length the number of characters to write |
yihui | 5:b8c02645e6af | 49 | * |
yihui | 5:b8c02645e6af | 50 | * @returns |
yihui | 5:b8c02645e6af | 51 | * The number of characters written (possibly 0) on success, -1 on error. |
yihui | 5:b8c02645e6af | 52 | */ |
yihui | 5:b8c02645e6af | 53 | virtual ssize_t write(const void* buffer, size_t length) = 0; |
yihui | 5:b8c02645e6af | 54 | |
yihui | 5:b8c02645e6af | 55 | /** Close the file |
yihui | 5:b8c02645e6af | 56 | * |
yihui | 5:b8c02645e6af | 57 | * @returns |
yihui | 5:b8c02645e6af | 58 | * Zero on success, -1 on error. |
yihui | 5:b8c02645e6af | 59 | */ |
yihui | 5:b8c02645e6af | 60 | virtual int close() = 0; |
yihui | 5:b8c02645e6af | 61 | |
yihui | 5:b8c02645e6af | 62 | /** Function read |
yihui | 5:b8c02645e6af | 63 | * Reads the contents of the file into a buffer |
yihui | 5:b8c02645e6af | 64 | * |
yihui | 5:b8c02645e6af | 65 | * @param buffer the buffer to read in to |
yihui | 5:b8c02645e6af | 66 | * @param length the number of characters to read |
yihui | 5:b8c02645e6af | 67 | * |
yihui | 5:b8c02645e6af | 68 | * @returns |
yihui | 5:b8c02645e6af | 69 | * The number of characters read (zero at end of file) on success, -1 on error. |
yihui | 5:b8c02645e6af | 70 | */ |
yihui | 5:b8c02645e6af | 71 | virtual ssize_t read(void* buffer, size_t length) = 0; |
yihui | 5:b8c02645e6af | 72 | |
yihui | 5:b8c02645e6af | 73 | /** Check if the handle is for a interactive terminal device. |
yihui | 5:b8c02645e6af | 74 | * If so, line buffered behaviour is used by default |
yihui | 5:b8c02645e6af | 75 | * |
yihui | 5:b8c02645e6af | 76 | * @returns |
yihui | 5:b8c02645e6af | 77 | * 1 if it is a terminal, |
yihui | 5:b8c02645e6af | 78 | * 0 otherwise |
yihui | 5:b8c02645e6af | 79 | */ |
yihui | 5:b8c02645e6af | 80 | virtual int isatty() = 0; |
yihui | 5:b8c02645e6af | 81 | |
yihui | 5:b8c02645e6af | 82 | /** Move the file position to a given offset from a given location. |
yihui | 5:b8c02645e6af | 83 | * |
yihui | 5:b8c02645e6af | 84 | * @param offset The offset from whence to move to |
yihui | 5:b8c02645e6af | 85 | * @param whence SEEK_SET for the start of the file, SEEK_CUR for the |
yihui | 5:b8c02645e6af | 86 | * current file position, or SEEK_END for the end of the file. |
yihui | 5:b8c02645e6af | 87 | * |
yihui | 5:b8c02645e6af | 88 | * @returns |
yihui | 5:b8c02645e6af | 89 | * new file position on success, |
yihui | 5:b8c02645e6af | 90 | * -1 on failure or unsupported |
yihui | 5:b8c02645e6af | 91 | */ |
yihui | 5:b8c02645e6af | 92 | virtual off_t lseek(off_t offset, int whence) = 0; |
yihui | 5:b8c02645e6af | 93 | |
yihui | 5:b8c02645e6af | 94 | /** Flush any buffers associated with the FileHandle, ensuring it |
yihui | 5:b8c02645e6af | 95 | * is up to date on disk |
yihui | 5:b8c02645e6af | 96 | * |
yihui | 5:b8c02645e6af | 97 | * @returns |
yihui | 5:b8c02645e6af | 98 | * 0 on success or un-needed, |
yihui | 5:b8c02645e6af | 99 | * -1 on error |
yihui | 5:b8c02645e6af | 100 | */ |
yihui | 5:b8c02645e6af | 101 | virtual int fsync() = 0; |
yihui | 5:b8c02645e6af | 102 | |
yihui | 5:b8c02645e6af | 103 | virtual off_t flen() { |
yihui | 5:b8c02645e6af | 104 | /* remember our current position */ |
yihui | 5:b8c02645e6af | 105 | off_t pos = lseek(0, SEEK_CUR); |
yihui | 5:b8c02645e6af | 106 | if(pos == -1) return -1; |
yihui | 5:b8c02645e6af | 107 | /* seek to the end to get the file length */ |
yihui | 5:b8c02645e6af | 108 | off_t res = lseek(0, SEEK_END); |
yihui | 5:b8c02645e6af | 109 | /* return to our old position */ |
yihui | 5:b8c02645e6af | 110 | lseek(pos, SEEK_SET); |
yihui | 5:b8c02645e6af | 111 | return res; |
yihui | 5:b8c02645e6af | 112 | } |
yihui | 5:b8c02645e6af | 113 | |
yihui | 5:b8c02645e6af | 114 | virtual ~FileHandle(); |
yihui | 5:b8c02645e6af | 115 | }; |
yihui | 5:b8c02645e6af | 116 | |
yihui | 5:b8c02645e6af | 117 | } // namespace mbed |
yihui | 5:b8c02645e6af | 118 | |
yihui | 5:b8c02645e6af | 119 | #endif |