mbed os with nrf51 internal bandgap enabled to read battery level

Dependents:   BLE_file_test BLE_Blink ExternalEncoder

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 /* mbed Microcontroller Library
elessair 0:f269e3021894 2 * Copyright (c) 2006-2013 ARM Limited
elessair 0:f269e3021894 3 *
elessair 0:f269e3021894 4 * Licensed under the Apache License, Version 2.0 (the "License");
elessair 0:f269e3021894 5 * you may not use this file except in compliance with the License.
elessair 0:f269e3021894 6 * You may obtain a copy of the License at
elessair 0:f269e3021894 7 *
elessair 0:f269e3021894 8 * http://www.apache.org/licenses/LICENSE-2.0
elessair 0:f269e3021894 9 *
elessair 0:f269e3021894 10 * Unless required by applicable law or agreed to in writing, software
elessair 0:f269e3021894 11 * distributed under the License is distributed on an "AS IS" BASIS,
elessair 0:f269e3021894 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
elessair 0:f269e3021894 13 * See the License for the specific language governing permissions and
elessair 0:f269e3021894 14 * limitations under the License.
elessair 0:f269e3021894 15 */
elessair 0:f269e3021894 16 #ifndef MBED_DIRHANDLE_H
elessair 0:f269e3021894 17 #define MBED_DIRHANDLE_H
elessair 0:f269e3021894 18
elessair 0:f269e3021894 19 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
elessair 0:f269e3021894 20 # define NAME_MAX 255
elessair 0:f269e3021894 21 typedef int mode_t;
elessair 0:f269e3021894 22
elessair 0:f269e3021894 23 #else
elessair 0:f269e3021894 24 # include <sys/syslimits.h>
elessair 0:f269e3021894 25 #endif
elessair 0:f269e3021894 26
elessair 0:f269e3021894 27 #include "FileHandle.h"
elessair 0:f269e3021894 28
elessair 0:f269e3021894 29 struct dirent {
elessair 0:f269e3021894 30 char d_name[NAME_MAX+1];
elessair 0:f269e3021894 31 };
elessair 0:f269e3021894 32
elessair 0:f269e3021894 33 namespace mbed {
elessair 0:f269e3021894 34 /** \addtogroup drivers */
elessair 0:f269e3021894 35 /** @{*/
elessair 0:f269e3021894 36
elessair 0:f269e3021894 37 /** Represents a directory stream. Objects of this type are returned
elessair 0:f269e3021894 38 * by a FileSystemLike's opendir method. Implementations must define
elessair 0:f269e3021894 39 * at least closedir, readdir and rewinddir.
elessair 0:f269e3021894 40 *
elessair 0:f269e3021894 41 * If a FileSystemLike class defines the opendir method, then the
elessair 0:f269e3021894 42 * directories of an object of that type can be accessed by
elessair 0:f269e3021894 43 * DIR *d = opendir("/example/directory") (or opendir("/example")
elessair 0:f269e3021894 44 * to open the root of the filesystem), and then using readdir(d) etc.
elessair 0:f269e3021894 45 *
elessair 0:f269e3021894 46 * The root directory is considered to contain all FileLike and
elessair 0:f269e3021894 47 * FileSystemLike objects, so the DIR* returned by opendir("/") will
elessair 0:f269e3021894 48 * reflect this.
elessair 0:f269e3021894 49 *
elessair 0:f269e3021894 50 * @Note Synchronization level: Set by subclass
elessair 0:f269e3021894 51 */
elessair 0:f269e3021894 52 class DirHandle {
elessair 0:f269e3021894 53
elessair 0:f269e3021894 54 public:
elessair 0:f269e3021894 55 /** Closes the directory.
elessair 0:f269e3021894 56 *
elessair 0:f269e3021894 57 * @returns
elessair 0:f269e3021894 58 * 0 on success,
elessair 0:f269e3021894 59 * -1 on error.
elessair 0:f269e3021894 60 */
elessair 0:f269e3021894 61 virtual int closedir()=0;
elessair 0:f269e3021894 62
elessair 0:f269e3021894 63 /** Return the directory entry at the current position, and
elessair 0:f269e3021894 64 * advances the position to the next entry.
elessair 0:f269e3021894 65 *
elessair 0:f269e3021894 66 * @returns
elessair 0:f269e3021894 67 * A pointer to a dirent structure representing the
elessair 0:f269e3021894 68 * directory entry at the current position, or NULL on reaching
elessair 0:f269e3021894 69 * end of directory or error.
elessair 0:f269e3021894 70 */
elessair 0:f269e3021894 71 virtual struct dirent *readdir()=0;
elessair 0:f269e3021894 72
elessair 0:f269e3021894 73 /** Resets the position to the beginning of the directory.
elessair 0:f269e3021894 74 */
elessair 0:f269e3021894 75 virtual void rewinddir()=0;
elessair 0:f269e3021894 76
elessair 0:f269e3021894 77 /** Returns the current position of the DirHandle.
elessair 0:f269e3021894 78 *
elessair 0:f269e3021894 79 * @returns
elessair 0:f269e3021894 80 * the current position,
elessair 0:f269e3021894 81 * -1 on error.
elessair 0:f269e3021894 82 */
elessair 0:f269e3021894 83 virtual off_t telldir() { return -1; }
elessair 0:f269e3021894 84
elessair 0:f269e3021894 85 /** Sets the position of the DirHandle.
elessair 0:f269e3021894 86 *
elessair 0:f269e3021894 87 * @param location The location to seek to. Must be a value returned by telldir.
elessair 0:f269e3021894 88 */
elessair 0:f269e3021894 89 virtual void seekdir(off_t location) { (void)location;}
elessair 0:f269e3021894 90
elessair 0:f269e3021894 91 virtual ~DirHandle() {}
elessair 0:f269e3021894 92
elessair 0:f269e3021894 93 protected:
elessair 0:f269e3021894 94
elessair 0:f269e3021894 95 /** Acquire exclusive access to this object.
elessair 0:f269e3021894 96 */
elessair 0:f269e3021894 97 virtual void lock() {
elessair 0:f269e3021894 98 // Stub
elessair 0:f269e3021894 99 }
elessair 0:f269e3021894 100
elessair 0:f269e3021894 101 /** Release exclusive access to this object.
elessair 0:f269e3021894 102 */
elessair 0:f269e3021894 103 virtual void unlock() {
elessair 0:f269e3021894 104 // Stub
elessair 0:f269e3021894 105 }
elessair 0:f269e3021894 106 };
elessair 0:f269e3021894 107
elessair 0:f269e3021894 108 } // namespace mbed
elessair 0:f269e3021894 109
elessair 0:f269e3021894 110 typedef mbed::DirHandle DIR;
elessair 0:f269e3021894 111
elessair 0:f269e3021894 112 extern "C" {
elessair 0:f269e3021894 113 DIR *opendir(const char*);
elessair 0:f269e3021894 114 struct dirent *readdir(DIR *);
elessair 0:f269e3021894 115 int closedir(DIR*);
elessair 0:f269e3021894 116 void rewinddir(DIR*);
elessair 0:f269e3021894 117 long telldir(DIR*);
elessair 0:f269e3021894 118 void seekdir(DIR*, long);
elessair 0:f269e3021894 119 int mkdir(const char *name, mode_t n);
elessair 0:f269e3021894 120 };
elessair 0:f269e3021894 121
elessair 0:f269e3021894 122 #endif /* MBED_DIRHANDLE_H */
elessair 0:f269e3021894 123
elessair 0:f269e3021894 124 /** @}*/