Development mbed library for MAX32630FTHR
Dependents: blinky_max32630fthr
drivers/FileBase.cpp@3:1198227e6421, 2016-12-16 (annotated)
- 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?
User | Revision | Line number | New 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/FileBase.h" |
switches | 0:5c4d7b2438d3 | 17 | |
switches | 0:5c4d7b2438d3 | 18 | namespace mbed { |
switches | 0:5c4d7b2438d3 | 19 | |
switches | 0:5c4d7b2438d3 | 20 | FileBase *FileBase::_head = NULL; |
switches | 0:5c4d7b2438d3 | 21 | SingletonPtr<PlatformMutex> FileBase::_mutex; |
switches | 0:5c4d7b2438d3 | 22 | |
switches | 0:5c4d7b2438d3 | 23 | FileBase::FileBase(const char *name, PathType t) : _next(NULL), |
switches | 0:5c4d7b2438d3 | 24 | _name(name), |
switches | 0:5c4d7b2438d3 | 25 | _path_type(t) { |
switches | 0:5c4d7b2438d3 | 26 | _mutex->lock(); |
switches | 0:5c4d7b2438d3 | 27 | if (name != NULL) { |
switches | 0:5c4d7b2438d3 | 28 | // put this object at head of the list |
switches | 0:5c4d7b2438d3 | 29 | _next = _head; |
switches | 0:5c4d7b2438d3 | 30 | _head = this; |
switches | 0:5c4d7b2438d3 | 31 | } else { |
switches | 0:5c4d7b2438d3 | 32 | _next = NULL; |
switches | 0:5c4d7b2438d3 | 33 | } |
switches | 0:5c4d7b2438d3 | 34 | _mutex->unlock(); |
switches | 0:5c4d7b2438d3 | 35 | } |
switches | 0:5c4d7b2438d3 | 36 | |
switches | 0:5c4d7b2438d3 | 37 | FileBase::~FileBase() { |
switches | 0:5c4d7b2438d3 | 38 | _mutex->lock(); |
switches | 0:5c4d7b2438d3 | 39 | if (_name != NULL) { |
switches | 0:5c4d7b2438d3 | 40 | // remove this object from the list |
switches | 0:5c4d7b2438d3 | 41 | if (_head == this) { // first in the list, so just drop me |
switches | 0:5c4d7b2438d3 | 42 | _head = _next; |
switches | 0:5c4d7b2438d3 | 43 | } else { // find the object before me, then drop me |
switches | 0:5c4d7b2438d3 | 44 | FileBase *p = _head; |
switches | 0:5c4d7b2438d3 | 45 | while (p->_next != this) { |
switches | 0:5c4d7b2438d3 | 46 | p = p->_next; |
switches | 0:5c4d7b2438d3 | 47 | } |
switches | 0:5c4d7b2438d3 | 48 | p->_next = _next; |
switches | 0:5c4d7b2438d3 | 49 | } |
switches | 0:5c4d7b2438d3 | 50 | } |
switches | 0:5c4d7b2438d3 | 51 | _mutex->unlock(); |
switches | 0:5c4d7b2438d3 | 52 | } |
switches | 0:5c4d7b2438d3 | 53 | |
switches | 0:5c4d7b2438d3 | 54 | FileBase *FileBase::lookup(const char *name, unsigned int len) { |
switches | 0:5c4d7b2438d3 | 55 | _mutex->lock(); |
switches | 0:5c4d7b2438d3 | 56 | FileBase *p = _head; |
switches | 0:5c4d7b2438d3 | 57 | while (p != NULL) { |
switches | 0:5c4d7b2438d3 | 58 | /* Check that p->_name matches name and is the correct length */ |
switches | 0:5c4d7b2438d3 | 59 | if (p->_name != NULL && std::strncmp(p->_name, name, len) == 0 && std::strlen(p->_name) == len) { |
switches | 0:5c4d7b2438d3 | 60 | _mutex->unlock(); |
switches | 0:5c4d7b2438d3 | 61 | return p; |
switches | 0:5c4d7b2438d3 | 62 | } |
switches | 0:5c4d7b2438d3 | 63 | p = p->_next; |
switches | 0:5c4d7b2438d3 | 64 | } |
switches | 0:5c4d7b2438d3 | 65 | _mutex->unlock(); |
switches | 0:5c4d7b2438d3 | 66 | return NULL; |
switches | 0:5c4d7b2438d3 | 67 | } |
switches | 0:5c4d7b2438d3 | 68 | |
switches | 0:5c4d7b2438d3 | 69 | FileBase *FileBase::get(int n) { |
switches | 0:5c4d7b2438d3 | 70 | _mutex->lock(); |
switches | 0:5c4d7b2438d3 | 71 | FileBase *p = _head; |
switches | 0:5c4d7b2438d3 | 72 | int m = 0; |
switches | 0:5c4d7b2438d3 | 73 | while (p != NULL) { |
switches | 0:5c4d7b2438d3 | 74 | if (m == n) { |
switches | 0:5c4d7b2438d3 | 75 | _mutex->unlock(); |
switches | 0:5c4d7b2438d3 | 76 | return p; |
switches | 0:5c4d7b2438d3 | 77 | } |
switches | 0:5c4d7b2438d3 | 78 | |
switches | 0:5c4d7b2438d3 | 79 | m++; |
switches | 0:5c4d7b2438d3 | 80 | p = p->_next; |
switches | 0:5c4d7b2438d3 | 81 | } |
switches | 0:5c4d7b2438d3 | 82 | _mutex->unlock(); |
switches | 0:5c4d7b2438d3 | 83 | return NULL; |
switches | 0:5c4d7b2438d3 | 84 | } |
switches | 0:5c4d7b2438d3 | 85 | |
switches | 0:5c4d7b2438d3 | 86 | const char* FileBase::getName(void) { |
switches | 0:5c4d7b2438d3 | 87 | // Constant read so no lock needed |
switches | 0:5c4d7b2438d3 | 88 | return _name; |
switches | 0:5c4d7b2438d3 | 89 | } |
switches | 0:5c4d7b2438d3 | 90 | |
switches | 0:5c4d7b2438d3 | 91 | PathType FileBase::getPathType(void) { |
switches | 0:5c4d7b2438d3 | 92 | // Constant read so no lock needed |
switches | 0:5c4d7b2438d3 | 93 | return _path_type; |
switches | 0:5c4d7b2438d3 | 94 | } |
switches | 0:5c4d7b2438d3 | 95 | |
switches | 0:5c4d7b2438d3 | 96 | } // namespace mbed |
switches | 0:5c4d7b2438d3 | 97 |