LPC11U35 ADC Tick & USBSerial

Dependencies:   mbed

Dependents:   SmallDoseMeter_SingleCH_AE_lpc11u35_V1_00

Committer:
H_Tsunemoto
Date:
Mon Feb 19 09:09:52 2018 +0000
Revision:
1:b1a3be5f48ab
Parent:
0:871ab6846b18
test

Who changed what in which revision?

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