Final version.

Dependencies:   F746_GUI F746_SAI_IO UIT_FFT_Real

Fork of F746_Spectrogram by 不韋 呂

Committer:
MikamiUitOpen
Date:
Sun Oct 02 10:51:10 2016 +0000
Revision:
4:c1beacfc42c7
5

Who changed what in which revision?

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