Fork of mbed for KL05Z based smart sensor which has no crystal on the board, so MCG FEI mode is required.

Dependents:   smart-sensor-KL05Z-debug

Fork of mbed-src by Ermanno Brusadin

Committer:
r14793
Date:
Mon Jan 29 15:38:37 2018 +0000
Revision:
1:da408b460382
Parent:
0:0a673c671a56
changed KL05 MCG mode to FEI for smart sensor boards (no crystal)

Who changed what in which revision?

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