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 #include "Stream.h"
MikamiUitOpen 0:3e46577dc273 17
MikamiUitOpen 0:3e46577dc273 18 namespace mbed {
MikamiUitOpen 0:3e46577dc273 19
MikamiUitOpen 0:3e46577dc273 20 Stream::Stream(const char *name) : FileLike(name), _file(NULL) {
MikamiUitOpen 0:3e46577dc273 21 /* open ourselves */
MikamiUitOpen 0:3e46577dc273 22 char buf[12]; /* :0x12345678 + null byte */
MikamiUitOpen 0:3e46577dc273 23 std::sprintf(buf, ":%p", this);
MikamiUitOpen 0:3e46577dc273 24 _file = std::fopen(buf, "w+");
MikamiUitOpen 0:3e46577dc273 25 mbed_set_unbuffered_stream(_file);
MikamiUitOpen 0:3e46577dc273 26 }
MikamiUitOpen 0:3e46577dc273 27
MikamiUitOpen 0:3e46577dc273 28 Stream::~Stream() {
MikamiUitOpen 0:3e46577dc273 29 fclose(_file);
MikamiUitOpen 0:3e46577dc273 30 }
MikamiUitOpen 0:3e46577dc273 31
MikamiUitOpen 0:3e46577dc273 32 int Stream::putc(int c) {
MikamiUitOpen 0:3e46577dc273 33 fflush(_file);
MikamiUitOpen 0:3e46577dc273 34 return std::fputc(c, _file);
MikamiUitOpen 0:3e46577dc273 35 }
MikamiUitOpen 0:3e46577dc273 36 int Stream::puts(const char *s) {
MikamiUitOpen 0:3e46577dc273 37 fflush(_file);
MikamiUitOpen 0:3e46577dc273 38 return std::fputs(s, _file);
MikamiUitOpen 0:3e46577dc273 39 }
MikamiUitOpen 0:3e46577dc273 40 int Stream::getc() {
MikamiUitOpen 0:3e46577dc273 41 fflush(_file);
MikamiUitOpen 0:3e46577dc273 42 return mbed_getc(_file);
MikamiUitOpen 0:3e46577dc273 43 }
MikamiUitOpen 0:3e46577dc273 44 char* Stream::gets(char *s, int size) {
MikamiUitOpen 0:3e46577dc273 45 fflush(_file);
MikamiUitOpen 0:3e46577dc273 46 return mbed_gets(s,size,_file);
MikamiUitOpen 0:3e46577dc273 47 }
MikamiUitOpen 0:3e46577dc273 48
MikamiUitOpen 0:3e46577dc273 49 int Stream::close() {
MikamiUitOpen 0:3e46577dc273 50 return 0;
MikamiUitOpen 0:3e46577dc273 51 }
MikamiUitOpen 0:3e46577dc273 52
MikamiUitOpen 0:3e46577dc273 53 ssize_t Stream::write(const void* buffer, size_t length) {
MikamiUitOpen 0:3e46577dc273 54 const char* ptr = (const char*)buffer;
MikamiUitOpen 0:3e46577dc273 55 const char* end = ptr + length;
MikamiUitOpen 0:3e46577dc273 56 while (ptr != end) {
MikamiUitOpen 0:3e46577dc273 57 if (_putc(*ptr++) == EOF) {
MikamiUitOpen 0:3e46577dc273 58 break;
MikamiUitOpen 0:3e46577dc273 59 }
MikamiUitOpen 0:3e46577dc273 60 }
MikamiUitOpen 0:3e46577dc273 61 return ptr - (const char*)buffer;
MikamiUitOpen 0:3e46577dc273 62 }
MikamiUitOpen 0:3e46577dc273 63
MikamiUitOpen 0:3e46577dc273 64 ssize_t Stream::read(void* buffer, size_t length) {
MikamiUitOpen 0:3e46577dc273 65 char* ptr = (char*)buffer;
MikamiUitOpen 0:3e46577dc273 66 char* end = ptr + length;
MikamiUitOpen 0:3e46577dc273 67 while (ptr != end) {
MikamiUitOpen 0:3e46577dc273 68 int c = _getc();
MikamiUitOpen 0:3e46577dc273 69 if (c==EOF) break;
MikamiUitOpen 0:3e46577dc273 70 *ptr++ = c;
MikamiUitOpen 0:3e46577dc273 71 }
MikamiUitOpen 0:3e46577dc273 72 return ptr - (const char*)buffer;
MikamiUitOpen 0:3e46577dc273 73 }
MikamiUitOpen 0:3e46577dc273 74
MikamiUitOpen 0:3e46577dc273 75 off_t Stream::lseek(off_t offset, int whence) {
MikamiUitOpen 0:3e46577dc273 76 return 0;
MikamiUitOpen 0:3e46577dc273 77 }
MikamiUitOpen 0:3e46577dc273 78
MikamiUitOpen 0:3e46577dc273 79 int Stream::isatty() {
MikamiUitOpen 0:3e46577dc273 80 return 0;
MikamiUitOpen 0:3e46577dc273 81 }
MikamiUitOpen 0:3e46577dc273 82
MikamiUitOpen 0:3e46577dc273 83 int Stream::fsync() {
MikamiUitOpen 0:3e46577dc273 84 return 0;
MikamiUitOpen 0:3e46577dc273 85 }
MikamiUitOpen 0:3e46577dc273 86
MikamiUitOpen 0:3e46577dc273 87 off_t Stream::flen() {
MikamiUitOpen 0:3e46577dc273 88 return 0;
MikamiUitOpen 0:3e46577dc273 89 }
MikamiUitOpen 0:3e46577dc273 90
MikamiUitOpen 0:3e46577dc273 91 int Stream::printf(const char* format, ...) {
MikamiUitOpen 0:3e46577dc273 92 std::va_list arg;
MikamiUitOpen 0:3e46577dc273 93 va_start(arg, format);
MikamiUitOpen 0:3e46577dc273 94 fflush(_file);
MikamiUitOpen 0:3e46577dc273 95 int r = vfprintf(_file, format, arg);
MikamiUitOpen 0:3e46577dc273 96 va_end(arg);
MikamiUitOpen 0:3e46577dc273 97 return r;
MikamiUitOpen 0:3e46577dc273 98 }
MikamiUitOpen 0:3e46577dc273 99
MikamiUitOpen 0:3e46577dc273 100 int Stream::scanf(const char* format, ...) {
MikamiUitOpen 0:3e46577dc273 101 std::va_list arg;
MikamiUitOpen 0:3e46577dc273 102 va_start(arg, format);
MikamiUitOpen 0:3e46577dc273 103 fflush(_file);
MikamiUitOpen 0:3e46577dc273 104 int r = vfscanf(_file, format, arg);
MikamiUitOpen 0:3e46577dc273 105 va_end(arg);
MikamiUitOpen 0:3e46577dc273 106 return r;
MikamiUitOpen 0:3e46577dc273 107 }
MikamiUitOpen 0:3e46577dc273 108
MikamiUitOpen 0:3e46577dc273 109 int Stream::vprintf(const char* format, std::va_list args) {
MikamiUitOpen 0:3e46577dc273 110 fflush(_file);
MikamiUitOpen 0:3e46577dc273 111 int r = vfprintf(_file, format, args);
MikamiUitOpen 0:3e46577dc273 112 return r;
MikamiUitOpen 0:3e46577dc273 113 }
MikamiUitOpen 0:3e46577dc273 114
MikamiUitOpen 0:3e46577dc273 115 int Stream::vscanf(const char* format, std::va_list args) {
MikamiUitOpen 0:3e46577dc273 116 fflush(_file);
MikamiUitOpen 0:3e46577dc273 117 int r = vfscanf(_file, format, args);
MikamiUitOpen 0:3e46577dc273 118 return r;
MikamiUitOpen 0:3e46577dc273 119 }
MikamiUitOpen 0:3e46577dc273 120
MikamiUitOpen 0:3e46577dc273 121 } // namespace mbed