Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bryantaylor 0:eafc3fd41f75 1 /* mbed Microcontroller Library
bryantaylor 0:eafc3fd41f75 2 * Copyright (c) 2006-2013 ARM Limited
bryantaylor 0:eafc3fd41f75 3 *
bryantaylor 0:eafc3fd41f75 4 * Licensed under the Apache License, Version 2.0 (the "License");
bryantaylor 0:eafc3fd41f75 5 * you may not use this file except in compliance with the License.
bryantaylor 0:eafc3fd41f75 6 * You may obtain a copy of the License at
bryantaylor 0:eafc3fd41f75 7 *
bryantaylor 0:eafc3fd41f75 8 * http://www.apache.org/licenses/LICENSE-2.0
bryantaylor 0:eafc3fd41f75 9 *
bryantaylor 0:eafc3fd41f75 10 * Unless required by applicable law or agreed to in writing, software
bryantaylor 0:eafc3fd41f75 11 * distributed under the License is distributed on an "AS IS" BASIS,
bryantaylor 0:eafc3fd41f75 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
bryantaylor 0:eafc3fd41f75 13 * See the License for the specific language governing permissions and
bryantaylor 0:eafc3fd41f75 14 * limitations under the License.
bryantaylor 0:eafc3fd41f75 15 */
bryantaylor 0:eafc3fd41f75 16 #include "FileBase.h"
bryantaylor 0:eafc3fd41f75 17
bryantaylor 0:eafc3fd41f75 18 namespace mbed {
bryantaylor 0:eafc3fd41f75 19
bryantaylor 0:eafc3fd41f75 20 FileBase *FileBase::_head = NULL;
bryantaylor 0:eafc3fd41f75 21 SingletonPtr<PlatformMutex> FileBase::_mutex;
bryantaylor 0:eafc3fd41f75 22
bryantaylor 0:eafc3fd41f75 23 FileBase::FileBase(const char *name, PathType t) : _next(NULL),
bryantaylor 0:eafc3fd41f75 24 _name(name),
bryantaylor 0:eafc3fd41f75 25 _path_type(t) {
bryantaylor 0:eafc3fd41f75 26 _mutex->lock();
bryantaylor 0:eafc3fd41f75 27 if (name != NULL) {
bryantaylor 0:eafc3fd41f75 28 // put this object at head of the list
bryantaylor 0:eafc3fd41f75 29 _next = _head;
bryantaylor 0:eafc3fd41f75 30 _head = this;
bryantaylor 0:eafc3fd41f75 31 } else {
bryantaylor 0:eafc3fd41f75 32 _next = NULL;
bryantaylor 0:eafc3fd41f75 33 }
bryantaylor 0:eafc3fd41f75 34 _mutex->unlock();
bryantaylor 0:eafc3fd41f75 35 }
bryantaylor 0:eafc3fd41f75 36
bryantaylor 0:eafc3fd41f75 37 FileBase::~FileBase() {
bryantaylor 0:eafc3fd41f75 38 _mutex->lock();
bryantaylor 0:eafc3fd41f75 39 if (_name != NULL) {
bryantaylor 0:eafc3fd41f75 40 // remove this object from the list
bryantaylor 0:eafc3fd41f75 41 if (_head == this) { // first in the list, so just drop me
bryantaylor 0:eafc3fd41f75 42 _head = _next;
bryantaylor 0:eafc3fd41f75 43 } else { // find the object before me, then drop me
bryantaylor 0:eafc3fd41f75 44 FileBase *p = _head;
bryantaylor 0:eafc3fd41f75 45 while (p->_next != this) {
bryantaylor 0:eafc3fd41f75 46 p = p->_next;
bryantaylor 0:eafc3fd41f75 47 }
bryantaylor 0:eafc3fd41f75 48 p->_next = _next;
bryantaylor 0:eafc3fd41f75 49 }
bryantaylor 0:eafc3fd41f75 50 }
bryantaylor 0:eafc3fd41f75 51 _mutex->unlock();
bryantaylor 0:eafc3fd41f75 52 }
bryantaylor 0:eafc3fd41f75 53
bryantaylor 0:eafc3fd41f75 54 FileBase *FileBase::lookup(const char *name, unsigned int len) {
bryantaylor 0:eafc3fd41f75 55 _mutex->lock();
bryantaylor 0:eafc3fd41f75 56 FileBase *p = _head;
bryantaylor 0:eafc3fd41f75 57 while (p != NULL) {
bryantaylor 0:eafc3fd41f75 58 /* Check that p->_name matches name and is the correct length */
bryantaylor 0:eafc3fd41f75 59 if (p->_name != NULL && std::strncmp(p->_name, name, len) == 0 && std::strlen(p->_name) == len) {
bryantaylor 0:eafc3fd41f75 60 _mutex->unlock();
bryantaylor 0:eafc3fd41f75 61 return p;
bryantaylor 0:eafc3fd41f75 62 }
bryantaylor 0:eafc3fd41f75 63 p = p->_next;
bryantaylor 0:eafc3fd41f75 64 }
bryantaylor 0:eafc3fd41f75 65 _mutex->unlock();
bryantaylor 0:eafc3fd41f75 66 return NULL;
bryantaylor 0:eafc3fd41f75 67 }
bryantaylor 0:eafc3fd41f75 68
bryantaylor 0:eafc3fd41f75 69 FileBase *FileBase::get(int n) {
bryantaylor 0:eafc3fd41f75 70 _mutex->lock();
bryantaylor 0:eafc3fd41f75 71 FileBase *p = _head;
bryantaylor 0:eafc3fd41f75 72 int m = 0;
bryantaylor 0:eafc3fd41f75 73 while (p != NULL) {
bryantaylor 0:eafc3fd41f75 74 if (m == n) {
bryantaylor 0:eafc3fd41f75 75 _mutex->unlock();
bryantaylor 0:eafc3fd41f75 76 return p;
bryantaylor 0:eafc3fd41f75 77 }
bryantaylor 0:eafc3fd41f75 78
bryantaylor 0:eafc3fd41f75 79 m++;
bryantaylor 0:eafc3fd41f75 80 p = p->_next;
bryantaylor 0:eafc3fd41f75 81 }
bryantaylor 0:eafc3fd41f75 82 _mutex->unlock();
bryantaylor 0:eafc3fd41f75 83 return NULL;
bryantaylor 0:eafc3fd41f75 84 }
bryantaylor 0:eafc3fd41f75 85
bryantaylor 0:eafc3fd41f75 86 const char* FileBase::getName(void) {
bryantaylor 0:eafc3fd41f75 87 // Constant read so no lock needed
bryantaylor 0:eafc3fd41f75 88 return _name;
bryantaylor 0:eafc3fd41f75 89 }
bryantaylor 0:eafc3fd41f75 90
bryantaylor 0:eafc3fd41f75 91 PathType FileBase::getPathType(void) {
bryantaylor 0:eafc3fd41f75 92 // Constant read so no lock needed
bryantaylor 0:eafc3fd41f75 93 return _path_type;
bryantaylor 0:eafc3fd41f75 94 }
bryantaylor 0:eafc3fd41f75 95
bryantaylor 0:eafc3fd41f75 96 } // namespace mbed
bryantaylor 0:eafc3fd41f75 97