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 #include "drivers/FileSystemLike.h"
switches 0:5c4d7b2438d3 17
switches 0:5c4d7b2438d3 18 namespace mbed {
switches 0:5c4d7b2438d3 19
switches 0:5c4d7b2438d3 20 class BaseDirHandle : public DirHandle {
switches 0:5c4d7b2438d3 21 public:
switches 0:5c4d7b2438d3 22 /*
switches 0:5c4d7b2438d3 23 We keep track of our current location as the n'th object in the
switches 0:5c4d7b2438d3 24 FileSystemLike list. Using a Base* instead would cause problems if that
switches 0:5c4d7b2438d3 25 object were to be destroyed between readdirs.
switches 0:5c4d7b2438d3 26 Using this method does mean though that destroying/creating objects can
switches 0:5c4d7b2438d3 27 give unusual results from readdir.
switches 0:5c4d7b2438d3 28 */
switches 0:5c4d7b2438d3 29 off_t n;
switches 0:5c4d7b2438d3 30 struct dirent cur_entry;
switches 0:5c4d7b2438d3 31
switches 0:5c4d7b2438d3 32 BaseDirHandle() : n(0), cur_entry() {
switches 0:5c4d7b2438d3 33 }
switches 0:5c4d7b2438d3 34
switches 0:5c4d7b2438d3 35 virtual int closedir() {
switches 0:5c4d7b2438d3 36 // No lock can be used in destructor
switches 0:5c4d7b2438d3 37 delete this;
switches 0:5c4d7b2438d3 38 return 0;
switches 0:5c4d7b2438d3 39 }
switches 0:5c4d7b2438d3 40
switches 0:5c4d7b2438d3 41 virtual struct dirent *readdir() {
switches 0:5c4d7b2438d3 42 lock();
switches 0:5c4d7b2438d3 43 FileBase *ptr = FileBase::get(n);
switches 0:5c4d7b2438d3 44 if (ptr == NULL) {
switches 0:5c4d7b2438d3 45 unlock();
switches 0:5c4d7b2438d3 46 return NULL;
switches 0:5c4d7b2438d3 47 }
switches 0:5c4d7b2438d3 48
switches 0:5c4d7b2438d3 49 /* Increment n, so next readdir gets the next item */
switches 0:5c4d7b2438d3 50 n++;
switches 0:5c4d7b2438d3 51
switches 0:5c4d7b2438d3 52 /* Setup cur entry and return a pointer to it */
switches 0:5c4d7b2438d3 53 std::strncpy(cur_entry.d_name, ptr->getName(), NAME_MAX);
switches 0:5c4d7b2438d3 54 unlock();
switches 0:5c4d7b2438d3 55 return &cur_entry;
switches 0:5c4d7b2438d3 56 }
switches 0:5c4d7b2438d3 57
switches 0:5c4d7b2438d3 58 virtual off_t telldir() {
switches 0:5c4d7b2438d3 59 lock();
switches 0:5c4d7b2438d3 60 off_t offset = n;
switches 0:5c4d7b2438d3 61 unlock();
switches 0:5c4d7b2438d3 62 return offset;
switches 0:5c4d7b2438d3 63 }
switches 0:5c4d7b2438d3 64
switches 0:5c4d7b2438d3 65 virtual void seekdir(off_t offset) {
switches 0:5c4d7b2438d3 66 lock();
switches 0:5c4d7b2438d3 67 n = offset;
switches 0:5c4d7b2438d3 68 unlock();
switches 0:5c4d7b2438d3 69 }
switches 0:5c4d7b2438d3 70
switches 0:5c4d7b2438d3 71 virtual void rewinddir() {
switches 0:5c4d7b2438d3 72 lock();
switches 0:5c4d7b2438d3 73 n = 0;
switches 0:5c4d7b2438d3 74 unlock();
switches 0:5c4d7b2438d3 75 }
switches 0:5c4d7b2438d3 76
switches 0:5c4d7b2438d3 77 protected:
switches 0:5c4d7b2438d3 78 PlatformMutex _mutex;
switches 0:5c4d7b2438d3 79
switches 0:5c4d7b2438d3 80 virtual void lock() {
switches 0:5c4d7b2438d3 81 _mutex.lock();
switches 0:5c4d7b2438d3 82 }
switches 0:5c4d7b2438d3 83
switches 0:5c4d7b2438d3 84 virtual void unlock() {
switches 0:5c4d7b2438d3 85 _mutex.unlock();
switches 0:5c4d7b2438d3 86 }
switches 0:5c4d7b2438d3 87 };
switches 0:5c4d7b2438d3 88
switches 0:5c4d7b2438d3 89 FileSystemLike::FileSystemLike(const char *name) : FileBase(name, FileSystemPathType) {
switches 0:5c4d7b2438d3 90
switches 0:5c4d7b2438d3 91 }
switches 0:5c4d7b2438d3 92
switches 0:5c4d7b2438d3 93 FileSystemLike::~FileSystemLike() {
switches 0:5c4d7b2438d3 94
switches 0:5c4d7b2438d3 95 }
switches 0:5c4d7b2438d3 96
switches 0:5c4d7b2438d3 97 DirHandle *FileSystemLike::opendir() {
switches 0:5c4d7b2438d3 98 return new BaseDirHandle();
switches 0:5c4d7b2438d3 99 }
switches 0:5c4d7b2438d3 100
switches 0:5c4d7b2438d3 101 } // namespace mbed