customized mbed library sources for nrf51822

Dependents:   Grove_Node Potentiometer BLE_Beacon I2C_Scanner

Committer:
yihui
Date:
Tue Nov 04 07:38:53 2014 +0000
Revision:
0:700cadd8b708
customized mbed-src library for nrf51822

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 0:700cadd8b708 1 /* mbed Microcontroller Library
yihui 0:700cadd8b708 2 * Copyright (c) 2006-2013 ARM Limited
yihui 0:700cadd8b708 3 *
yihui 0:700cadd8b708 4 * Licensed under the Apache License, Version 2.0 (the "License");
yihui 0:700cadd8b708 5 * you may not use this file except in compliance with the License.
yihui 0:700cadd8b708 6 * You may obtain a copy of the License at
yihui 0:700cadd8b708 7 *
yihui 0:700cadd8b708 8 * http://www.apache.org/licenses/LICENSE-2.0
yihui 0:700cadd8b708 9 *
yihui 0:700cadd8b708 10 * Unless required by applicable law or agreed to in writing, software
yihui 0:700cadd8b708 11 * distributed under the License is distributed on an "AS IS" BASIS,
yihui 0:700cadd8b708 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
yihui 0:700cadd8b708 13 * See the License for the specific language governing permissions and
yihui 0:700cadd8b708 14 * limitations under the License.
yihui 0:700cadd8b708 15 */
yihui 0:700cadd8b708 16 #ifndef MBED_LOCALFILESYSTEM_H
yihui 0:700cadd8b708 17 #define MBED_LOCALFILESYSTEM_H
yihui 0:700cadd8b708 18
yihui 0:700cadd8b708 19 #include "platform.h"
yihui 0:700cadd8b708 20
yihui 0:700cadd8b708 21 #if DEVICE_LOCALFILESYSTEM
yihui 0:700cadd8b708 22
yihui 0:700cadd8b708 23 #include "FileSystemLike.h"
yihui 0:700cadd8b708 24
yihui 0:700cadd8b708 25 namespace mbed {
yihui 0:700cadd8b708 26
yihui 0:700cadd8b708 27 FILEHANDLE local_file_open(const char* name, int flags);
yihui 0:700cadd8b708 28
yihui 0:700cadd8b708 29 class LocalFileHandle : public FileHandle {
yihui 0:700cadd8b708 30
yihui 0:700cadd8b708 31 public:
yihui 0:700cadd8b708 32 LocalFileHandle(FILEHANDLE fh);
yihui 0:700cadd8b708 33
yihui 0:700cadd8b708 34 virtual int close();
yihui 0:700cadd8b708 35
yihui 0:700cadd8b708 36 virtual ssize_t write(const void *buffer, size_t length);
yihui 0:700cadd8b708 37
yihui 0:700cadd8b708 38 virtual ssize_t read(void *buffer, size_t length);
yihui 0:700cadd8b708 39
yihui 0:700cadd8b708 40 virtual int isatty();
yihui 0:700cadd8b708 41
yihui 0:700cadd8b708 42 virtual off_t lseek(off_t position, int whence);
yihui 0:700cadd8b708 43
yihui 0:700cadd8b708 44 virtual int fsync();
yihui 0:700cadd8b708 45
yihui 0:700cadd8b708 46 virtual off_t flen();
yihui 0:700cadd8b708 47
yihui 0:700cadd8b708 48 protected:
yihui 0:700cadd8b708 49 FILEHANDLE _fh;
yihui 0:700cadd8b708 50 int pos;
yihui 0:700cadd8b708 51 };
yihui 0:700cadd8b708 52
yihui 0:700cadd8b708 53 /** A filesystem for accessing the local mbed Microcontroller USB disk drive
yihui 0:700cadd8b708 54 *
yihui 0:700cadd8b708 55 * This allows programs to read and write files on the same disk drive that is used to program the
yihui 0:700cadd8b708 56 * mbed Microcontroller. Once created, the standard C file access functions are used to open,
yihui 0:700cadd8b708 57 * read and write files.
yihui 0:700cadd8b708 58 *
yihui 0:700cadd8b708 59 * Example:
yihui 0:700cadd8b708 60 * @code
yihui 0:700cadd8b708 61 * #include "mbed.h"
yihui 0:700cadd8b708 62 *
yihui 0:700cadd8b708 63 * LocalFileSystem local("local"); // Create the local filesystem under the name "local"
yihui 0:700cadd8b708 64 *
yihui 0:700cadd8b708 65 * int main() {
yihui 0:700cadd8b708 66 * FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
yihui 0:700cadd8b708 67 * fprintf(fp, "Hello World!");
yihui 0:700cadd8b708 68 * fclose(fp);
yihui 0:700cadd8b708 69 * remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
yihui 0:700cadd8b708 70 *
yihui 0:700cadd8b708 71 * DIR *d = opendir("/local"); // Opens the root directory of the local file system
yihui 0:700cadd8b708 72 * struct dirent *p;
yihui 0:700cadd8b708 73 * while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system
yihui 0:700cadd8b708 74 * printf("%s\n", p->d_name); // to stdout.
yihui 0:700cadd8b708 75 * }
yihui 0:700cadd8b708 76 * closedir(d);
yihui 0:700cadd8b708 77 * }
yihui 0:700cadd8b708 78 * @endcode
yihui 0:700cadd8b708 79 *
yihui 0:700cadd8b708 80 * @note
yihui 0:700cadd8b708 81 * If the microcontroller program makes an access to the local drive, it will be marked as "removed"
yihui 0:700cadd8b708 82 * on the Host computer. This means it is no longer accessible from the Host Computer.
yihui 0:700cadd8b708 83 *
yihui 0:700cadd8b708 84 * The drive will only re-appear when the microcontroller program exists. Note that if the program does
yihui 0:700cadd8b708 85 * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!
yihui 0:700cadd8b708 86 */
yihui 0:700cadd8b708 87 class LocalFileSystem : public FileSystemLike {
yihui 0:700cadd8b708 88
yihui 0:700cadd8b708 89 public:
yihui 0:700cadd8b708 90 LocalFileSystem(const char* n) : FileSystemLike(n) {
yihui 0:700cadd8b708 91
yihui 0:700cadd8b708 92 }
yihui 0:700cadd8b708 93
yihui 0:700cadd8b708 94 virtual FileHandle *open(const char* name, int flags);
yihui 0:700cadd8b708 95 virtual int remove(const char *filename);
yihui 0:700cadd8b708 96 virtual DirHandle *opendir(const char *name);
yihui 0:700cadd8b708 97 };
yihui 0:700cadd8b708 98
yihui 0:700cadd8b708 99 } // namespace mbed
yihui 0:700cadd8b708 100
yihui 0:700cadd8b708 101 #endif
yihui 0:700cadd8b708 102
yihui 0:700cadd8b708 103 #endif