change some io settings for TWR-K22F-120M

Dependents:   twr_helloworld

Committer:
Jasper_lee
Date:
Tue Dec 23 03:35:08 2014 +0000
Revision:
0:b16d94660a33
change some io setting used in TWR-K22F120M

Who changed what in which revision?

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