Describes predefine macros for mbed online compiler (armcc)

Committer:
MACRUM
Date:
Thu Mar 16 21:58:09 2017 +0900
Revision:
6:40e873bbc5f7
Add licence header info

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 6:40e873bbc5f7 1 /* mbed Microcontroller Library
MACRUM 6:40e873bbc5f7 2 * Copyright (c) 2006-2013 ARM Limited
MACRUM 6:40e873bbc5f7 3 *
MACRUM 6:40e873bbc5f7 4 * Licensed under the Apache License, Version 2.0 (the "License");
MACRUM 6:40e873bbc5f7 5 * you may not use this file except in compliance with the License.
MACRUM 6:40e873bbc5f7 6 * You may obtain a copy of the License at
MACRUM 6:40e873bbc5f7 7 *
MACRUM 6:40e873bbc5f7 8 * http://www.apache.org/licenses/LICENSE-2.0
MACRUM 6:40e873bbc5f7 9 *
MACRUM 6:40e873bbc5f7 10 * Unless required by applicable law or agreed to in writing, software
MACRUM 6:40e873bbc5f7 11 * distributed under the License is distributed on an "AS IS" BASIS,
MACRUM 6:40e873bbc5f7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MACRUM 6:40e873bbc5f7 13 * See the License for the specific language governing permissions and
MACRUM 6:40e873bbc5f7 14 * limitations under the License.
MACRUM 6:40e873bbc5f7 15 */
MACRUM 6:40e873bbc5f7 16 #ifndef MBED_FILEHANDLE_H
MACRUM 6:40e873bbc5f7 17 #define MBED_FILEHANDLE_H
MACRUM 6:40e873bbc5f7 18
MACRUM 6:40e873bbc5f7 19 typedef int FILEHANDLE;
MACRUM 6:40e873bbc5f7 20
MACRUM 6:40e873bbc5f7 21 #include <stdio.h>
MACRUM 6:40e873bbc5f7 22 #include "platform/platform.h"
MACRUM 6:40e873bbc5f7 23
MACRUM 6:40e873bbc5f7 24 namespace mbed {
MACRUM 6:40e873bbc5f7 25 /** \addtogroup drivers */
MACRUM 6:40e873bbc5f7 26 /** @{*/
MACRUM 6:40e873bbc5f7 27
MACRUM 6:40e873bbc5f7 28 /** An OO equivalent of the internal FILEHANDLE variable
MACRUM 6:40e873bbc5f7 29 * and associated _sys_* functions.
MACRUM 6:40e873bbc5f7 30 *
MACRUM 6:40e873bbc5f7 31 * FileHandle is an abstract class, needing at least sys_write and
MACRUM 6:40e873bbc5f7 32 * sys_read to be implmented for a simple interactive device.
MACRUM 6:40e873bbc5f7 33 *
MACRUM 6:40e873bbc5f7 34 * No one ever directly tals to/instanciates a FileHandle - it gets
MACRUM 6:40e873bbc5f7 35 * created by FileSystem, and wrapped up by stdio.
MACRUM 6:40e873bbc5f7 36 *
MACRUM 6:40e873bbc5f7 37 * @Note Synchronization level: Set by subclass
MACRUM 6:40e873bbc5f7 38 */
MACRUM 6:40e873bbc5f7 39 class FileHandle {
MACRUM 6:40e873bbc5f7 40
MACRUM 6:40e873bbc5f7 41 public:
MACRUM 6:40e873bbc5f7 42 MBED_DEPRECATED_SINCE("mbed-os-5.4",
MACRUM 6:40e873bbc5f7 43 "The mbed 2 filesystem classes have been superseeded by the FileSystem api, "
MACRUM 6:40e873bbc5f7 44 "Replaced by File")
MACRUM 6:40e873bbc5f7 45 FileHandle() {}
MACRUM 6:40e873bbc5f7 46
MACRUM 6:40e873bbc5f7 47 /** Write the contents of a buffer to the file
MACRUM 6:40e873bbc5f7 48 *
MACRUM 6:40e873bbc5f7 49 * @param buffer the buffer to write from
MACRUM 6:40e873bbc5f7 50 * @param length the number of characters to write
MACRUM 6:40e873bbc5f7 51 *
MACRUM 6:40e873bbc5f7 52 * @returns
MACRUM 6:40e873bbc5f7 53 * The number of characters written (possibly 0) on success, -1 on error.
MACRUM 6:40e873bbc5f7 54 */
MACRUM 6:40e873bbc5f7 55 virtual ssize_t write(const void* buffer, size_t length) = 0;
MACRUM 6:40e873bbc5f7 56
MACRUM 6:40e873bbc5f7 57 /** Close the file
MACRUM 6:40e873bbc5f7 58 *
MACRUM 6:40e873bbc5f7 59 * @returns
MACRUM 6:40e873bbc5f7 60 * Zero on success, -1 on error.
MACRUM 6:40e873bbc5f7 61 */
MACRUM 6:40e873bbc5f7 62 virtual int close() = 0;
MACRUM 6:40e873bbc5f7 63
MACRUM 6:40e873bbc5f7 64 /** Function read
MACRUM 6:40e873bbc5f7 65 * Reads the contents of the file into a buffer
MACRUM 6:40e873bbc5f7 66 *
MACRUM 6:40e873bbc5f7 67 * @param buffer the buffer to read in to
MACRUM 6:40e873bbc5f7 68 * @param length the number of characters to read
MACRUM 6:40e873bbc5f7 69 *
MACRUM 6:40e873bbc5f7 70 * @returns
MACRUM 6:40e873bbc5f7 71 * The number of characters read (zero at end of file) on success, -1 on error.
MACRUM 6:40e873bbc5f7 72 */
MACRUM 6:40e873bbc5f7 73 virtual ssize_t read(void* buffer, size_t length) = 0;
MACRUM 6:40e873bbc5f7 74
MACRUM 6:40e873bbc5f7 75 /** Check if the handle is for a interactive terminal device.
MACRUM 6:40e873bbc5f7 76 * If so, line buffered behaviour is used by default
MACRUM 6:40e873bbc5f7 77 *
MACRUM 6:40e873bbc5f7 78 * @returns
MACRUM 6:40e873bbc5f7 79 * 1 if it is a terminal,
MACRUM 6:40e873bbc5f7 80 * 0 otherwise
MACRUM 6:40e873bbc5f7 81 */
MACRUM 6:40e873bbc5f7 82 virtual int isatty() = 0;
MACRUM 6:40e873bbc5f7 83
MACRUM 6:40e873bbc5f7 84 /** Move the file position to a given offset from a given location.
MACRUM 6:40e873bbc5f7 85 *
MACRUM 6:40e873bbc5f7 86 * @param offset The offset from whence to move to
MACRUM 6:40e873bbc5f7 87 * @param whence SEEK_SET for the start of the file, SEEK_CUR for the
MACRUM 6:40e873bbc5f7 88 * current file position, or SEEK_END for the end of the file.
MACRUM 6:40e873bbc5f7 89 *
MACRUM 6:40e873bbc5f7 90 * @returns
MACRUM 6:40e873bbc5f7 91 * new file position on success,
MACRUM 6:40e873bbc5f7 92 * -1 on failure or unsupported
MACRUM 6:40e873bbc5f7 93 */
MACRUM 6:40e873bbc5f7 94 virtual off_t lseek(off_t offset, int whence) = 0;
MACRUM 6:40e873bbc5f7 95
MACRUM 6:40e873bbc5f7 96 /** Flush any buffers associated with the FileHandle, ensuring it
MACRUM 6:40e873bbc5f7 97 * is up to date on disk
MACRUM 6:40e873bbc5f7 98 *
MACRUM 6:40e873bbc5f7 99 * @returns
MACRUM 6:40e873bbc5f7 100 * 0 on success or un-needed,
MACRUM 6:40e873bbc5f7 101 * -1 on error
MACRUM 6:40e873bbc5f7 102 */
MACRUM 6:40e873bbc5f7 103 virtual int fsync() = 0;
MACRUM 6:40e873bbc5f7 104
MACRUM 6:40e873bbc5f7 105 virtual off_t flen() {
MACRUM 6:40e873bbc5f7 106 lock();
MACRUM 6:40e873bbc5f7 107 /* remember our current position */
MACRUM 6:40e873bbc5f7 108 off_t pos = lseek(0, SEEK_CUR);
MACRUM 6:40e873bbc5f7 109 if(pos == -1) {
MACRUM 6:40e873bbc5f7 110 unlock();
MACRUM 6:40e873bbc5f7 111 return -1;
MACRUM 6:40e873bbc5f7 112 }
MACRUM 6:40e873bbc5f7 113 /* seek to the end to get the file length */
MACRUM 6:40e873bbc5f7 114 off_t res = lseek(0, SEEK_END);
MACRUM 6:40e873bbc5f7 115 /* return to our old position */
MACRUM 6:40e873bbc5f7 116 lseek(pos, SEEK_SET);
MACRUM 6:40e873bbc5f7 117 unlock();
MACRUM 6:40e873bbc5f7 118 return res;
MACRUM 6:40e873bbc5f7 119 }
MACRUM 6:40e873bbc5f7 120
MACRUM 6:40e873bbc5f7 121 virtual ~FileHandle() {};
MACRUM 6:40e873bbc5f7 122
MACRUM 6:40e873bbc5f7 123 protected:
MACRUM 6:40e873bbc5f7 124
MACRUM 6:40e873bbc5f7 125 /** Acquire exclusive access to this object.
MACRUM 6:40e873bbc5f7 126 */
MACRUM 6:40e873bbc5f7 127 virtual void lock() {
MACRUM 6:40e873bbc5f7 128 // Stub
MACRUM 6:40e873bbc5f7 129 }
MACRUM 6:40e873bbc5f7 130
MACRUM 6:40e873bbc5f7 131 /** Release exclusive access to this object.
MACRUM 6:40e873bbc5f7 132 */
MACRUM 6:40e873bbc5f7 133 virtual void unlock() {
MACRUM 6:40e873bbc5f7 134 // Stub
MACRUM 6:40e873bbc5f7 135 }
MACRUM 6:40e873bbc5f7 136 };
MACRUM 6:40e873bbc5f7 137
MACRUM 6:40e873bbc5f7 138 } // namespace mbed
MACRUM 6:40e873bbc5f7 139
MACRUM 6:40e873bbc5f7 140 #endif
MACRUM 6:40e873bbc5f7 141
MACRUM 6:40e873bbc5f7 142 /** @}*/