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_LOCALFILESYSTEM_H
Jasper_lee 0:b16d94660a33 17 #define MBED_LOCALFILESYSTEM_H
Jasper_lee 0:b16d94660a33 18
Jasper_lee 0:b16d94660a33 19 #include "platform.h"
Jasper_lee 0:b16d94660a33 20
Jasper_lee 0:b16d94660a33 21 #if DEVICE_LOCALFILESYSTEM
Jasper_lee 0:b16d94660a33 22
Jasper_lee 0:b16d94660a33 23 #include "FileSystemLike.h"
Jasper_lee 0:b16d94660a33 24
Jasper_lee 0:b16d94660a33 25 namespace mbed {
Jasper_lee 0:b16d94660a33 26
Jasper_lee 0:b16d94660a33 27 FILEHANDLE local_file_open(const char* name, int flags);
Jasper_lee 0:b16d94660a33 28
Jasper_lee 0:b16d94660a33 29 class LocalFileHandle : public FileHandle {
Jasper_lee 0:b16d94660a33 30
Jasper_lee 0:b16d94660a33 31 public:
Jasper_lee 0:b16d94660a33 32 LocalFileHandle(FILEHANDLE fh);
Jasper_lee 0:b16d94660a33 33
Jasper_lee 0:b16d94660a33 34 virtual int close();
Jasper_lee 0:b16d94660a33 35
Jasper_lee 0:b16d94660a33 36 virtual ssize_t write(const void *buffer, size_t length);
Jasper_lee 0:b16d94660a33 37
Jasper_lee 0:b16d94660a33 38 virtual ssize_t read(void *buffer, size_t length);
Jasper_lee 0:b16d94660a33 39
Jasper_lee 0:b16d94660a33 40 virtual int isatty();
Jasper_lee 0:b16d94660a33 41
Jasper_lee 0:b16d94660a33 42 virtual off_t lseek(off_t position, int whence);
Jasper_lee 0:b16d94660a33 43
Jasper_lee 0:b16d94660a33 44 virtual int fsync();
Jasper_lee 0:b16d94660a33 45
Jasper_lee 0:b16d94660a33 46 virtual off_t flen();
Jasper_lee 0:b16d94660a33 47
Jasper_lee 0:b16d94660a33 48 protected:
Jasper_lee 0:b16d94660a33 49 FILEHANDLE _fh;
Jasper_lee 0:b16d94660a33 50 int pos;
Jasper_lee 0:b16d94660a33 51 };
Jasper_lee 0:b16d94660a33 52
Jasper_lee 0:b16d94660a33 53 /** A filesystem for accessing the local mbed Microcontroller USB disk drive
Jasper_lee 0:b16d94660a33 54 *
Jasper_lee 0:b16d94660a33 55 * This allows programs to read and write files on the same disk drive that is used to program the
Jasper_lee 0:b16d94660a33 56 * mbed Microcontroller. Once created, the standard C file access functions are used to open,
Jasper_lee 0:b16d94660a33 57 * read and write files.
Jasper_lee 0:b16d94660a33 58 *
Jasper_lee 0:b16d94660a33 59 * Example:
Jasper_lee 0:b16d94660a33 60 * @code
Jasper_lee 0:b16d94660a33 61 * #include "mbed.h"
Jasper_lee 0:b16d94660a33 62 *
Jasper_lee 0:b16d94660a33 63 * LocalFileSystem local("local"); // Create the local filesystem under the name "local"
Jasper_lee 0:b16d94660a33 64 *
Jasper_lee 0:b16d94660a33 65 * int main() {
Jasper_lee 0:b16d94660a33 66 * FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
Jasper_lee 0:b16d94660a33 67 * fprintf(fp, "Hello World!");
Jasper_lee 0:b16d94660a33 68 * fclose(fp);
Jasper_lee 0:b16d94660a33 69 * remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
Jasper_lee 0:b16d94660a33 70 *
Jasper_lee 0:b16d94660a33 71 * DIR *d = opendir("/local"); // Opens the root directory of the local file system
Jasper_lee 0:b16d94660a33 72 * struct dirent *p;
Jasper_lee 0:b16d94660a33 73 * while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system
Jasper_lee 0:b16d94660a33 74 * printf("%s\n", p->d_name); // to stdout.
Jasper_lee 0:b16d94660a33 75 * }
Jasper_lee 0:b16d94660a33 76 * closedir(d);
Jasper_lee 0:b16d94660a33 77 * }
Jasper_lee 0:b16d94660a33 78 * @endcode
Jasper_lee 0:b16d94660a33 79 *
Jasper_lee 0:b16d94660a33 80 * @note
Jasper_lee 0:b16d94660a33 81 * If the microcontroller program makes an access to the local drive, it will be marked as "removed"
Jasper_lee 0:b16d94660a33 82 * on the Host computer. This means it is no longer accessible from the Host Computer.
Jasper_lee 0:b16d94660a33 83 *
Jasper_lee 0:b16d94660a33 84 * The drive will only re-appear when the microcontroller program exists. Note that if the program does
Jasper_lee 0:b16d94660a33 85 * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!
Jasper_lee 0:b16d94660a33 86 */
Jasper_lee 0:b16d94660a33 87 class LocalFileSystem : public FileSystemLike {
Jasper_lee 0:b16d94660a33 88
Jasper_lee 0:b16d94660a33 89 public:
Jasper_lee 0:b16d94660a33 90 LocalFileSystem(const char* n) : FileSystemLike(n) {
Jasper_lee 0:b16d94660a33 91
Jasper_lee 0:b16d94660a33 92 }
Jasper_lee 0:b16d94660a33 93
Jasper_lee 0:b16d94660a33 94 virtual FileHandle *open(const char* name, int flags);
Jasper_lee 0:b16d94660a33 95 virtual int remove(const char *filename);
Jasper_lee 0:b16d94660a33 96 virtual DirHandle *opendir(const char *name);
Jasper_lee 0:b16d94660a33 97 };
Jasper_lee 0:b16d94660a33 98
Jasper_lee 0:b16d94660a33 99 } // namespace mbed
Jasper_lee 0:b16d94660a33 100
Jasper_lee 0:b16d94660a33 101 #endif
Jasper_lee 0:b16d94660a33 102
Jasper_lee 0:b16d94660a33 103 #endif