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