fft

Dependencies:   BSP_DISCO_F746NG SDFileSystem_Warning_Fixed

Committer:
aria19970520
Date:
Fri Mar 06 06:52:14 2020 +0000
Revision:
3:6f7e05dd8d15
Parent:
0:3e46577dc273
fft

Who changed what in which revision?

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