Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

Who changed what in which revision?

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