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
switches 0:5c4d7b2438d3 2 /** \addtogroup platform */
switches 0:5c4d7b2438d3 3 /** @{*/
switches 0:5c4d7b2438d3 4 /* mbed Microcontroller Library
switches 0:5c4d7b2438d3 5 * Copyright (c) 2006-2013 ARM Limited
switches 0:5c4d7b2438d3 6 *
switches 0:5c4d7b2438d3 7 * Licensed under the Apache License, Version 2.0 (the "License");
switches 0:5c4d7b2438d3 8 * you may not use this file except in compliance with the License.
switches 0:5c4d7b2438d3 9 * You may obtain a copy of the License at
switches 0:5c4d7b2438d3 10 *
switches 0:5c4d7b2438d3 11 * http://www.apache.org/licenses/LICENSE-2.0
switches 0:5c4d7b2438d3 12 *
switches 0:5c4d7b2438d3 13 * Unless required by applicable law or agreed to in writing, software
switches 0:5c4d7b2438d3 14 * distributed under the License is distributed on an "AS IS" BASIS,
switches 0:5c4d7b2438d3 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
switches 0:5c4d7b2438d3 16 * See the License for the specific language governing permissions and
switches 0:5c4d7b2438d3 17 * limitations under the License.
switches 0:5c4d7b2438d3 18 */
switches 0:5c4d7b2438d3 19 #ifndef SINGLETONPTR_H
switches 0:5c4d7b2438d3 20 #define SINGLETONPTR_H
switches 0:5c4d7b2438d3 21
switches 0:5c4d7b2438d3 22 #include <stdint.h>
switches 0:5c4d7b2438d3 23 #include <new>
switches 0:5c4d7b2438d3 24 #include "platform/mbed_assert.h"
switches 0:5c4d7b2438d3 25 #ifdef MBED_CONF_RTOS_PRESENT
switches 0:5c4d7b2438d3 26 #include "cmsis_os.h"
switches 0:5c4d7b2438d3 27 #endif
switches 0:5c4d7b2438d3 28
switches 0:5c4d7b2438d3 29 #ifdef MBED_CONF_RTOS_PRESENT
switches 0:5c4d7b2438d3 30 extern osMutexId singleton_mutex_id;
switches 0:5c4d7b2438d3 31 #endif
switches 0:5c4d7b2438d3 32
switches 0:5c4d7b2438d3 33 /** Lock the singleton mutex
switches 0:5c4d7b2438d3 34 *
switches 0:5c4d7b2438d3 35 * This function is typically used to provide
switches 0:5c4d7b2438d3 36 * exclusive access when initializing a
switches 0:5c4d7b2438d3 37 * global object.
switches 0:5c4d7b2438d3 38 */
switches 0:5c4d7b2438d3 39 inline static void singleton_lock(void)
switches 0:5c4d7b2438d3 40 {
switches 0:5c4d7b2438d3 41 #ifdef MBED_CONF_RTOS_PRESENT
switches 0:5c4d7b2438d3 42 osMutexWait(singleton_mutex_id, osWaitForever);
switches 0:5c4d7b2438d3 43 #endif
switches 0:5c4d7b2438d3 44 }
switches 0:5c4d7b2438d3 45
switches 0:5c4d7b2438d3 46 /** Unlock the singleton mutex
switches 0:5c4d7b2438d3 47 *
switches 0:5c4d7b2438d3 48 * This function is typically used to provide
switches 0:5c4d7b2438d3 49 * exclusive access when initializing a
switches 0:5c4d7b2438d3 50 * global object.
switches 0:5c4d7b2438d3 51 */
switches 0:5c4d7b2438d3 52 inline static void singleton_unlock(void)
switches 0:5c4d7b2438d3 53 {
switches 0:5c4d7b2438d3 54 #ifdef MBED_CONF_RTOS_PRESENT
switches 0:5c4d7b2438d3 55 osMutexRelease (singleton_mutex_id);
switches 0:5c4d7b2438d3 56 #endif
switches 0:5c4d7b2438d3 57 }
switches 0:5c4d7b2438d3 58
switches 0:5c4d7b2438d3 59 /** Utility class for creating an using a singleton
switches 0:5c4d7b2438d3 60 *
switches 0:5c4d7b2438d3 61 * @Note Synchronization level: Thread safe
switches 0:5c4d7b2438d3 62 *
switches 0:5c4d7b2438d3 63 * @Note: This class must only be used in a static context -
switches 0:5c4d7b2438d3 64 * this class must never be allocated or created on the
switches 0:5c4d7b2438d3 65 * stack.
switches 0:5c4d7b2438d3 66 *
switches 0:5c4d7b2438d3 67 * @Note: This class is lazily initialized on first use.
switches 0:5c4d7b2438d3 68 * This class is a POD type so if it is not used it will
switches 0:5c4d7b2438d3 69 * be garbage collected.
switches 0:5c4d7b2438d3 70 */
switches 0:5c4d7b2438d3 71 template <class T>
switches 0:5c4d7b2438d3 72 struct SingletonPtr {
switches 0:5c4d7b2438d3 73
switches 0:5c4d7b2438d3 74 /** Get a pointer to the underlying singleton
switches 0:5c4d7b2438d3 75 *
switches 0:5c4d7b2438d3 76 * @returns
switches 0:5c4d7b2438d3 77 * A pointer to the singleton
switches 0:5c4d7b2438d3 78 */
switches 0:5c4d7b2438d3 79 T* get() {
switches 0:5c4d7b2438d3 80 if (NULL == _ptr) {
switches 0:5c4d7b2438d3 81 singleton_lock();
switches 0:5c4d7b2438d3 82 if (NULL == _ptr) {
switches 0:5c4d7b2438d3 83 _ptr = new (_data) T();
switches 0:5c4d7b2438d3 84 }
switches 0:5c4d7b2438d3 85 singleton_unlock();
switches 0:5c4d7b2438d3 86 }
switches 0:5c4d7b2438d3 87 // _ptr was not zero initialized or was
switches 0:5c4d7b2438d3 88 // corrupted if this assert is hit
switches 0:5c4d7b2438d3 89 MBED_ASSERT(_ptr == (T *)&_data);
switches 0:5c4d7b2438d3 90 return _ptr;
switches 0:5c4d7b2438d3 91 }
switches 0:5c4d7b2438d3 92
switches 0:5c4d7b2438d3 93 /** Get a pointer to the underlying singleton
switches 0:5c4d7b2438d3 94 *
switches 0:5c4d7b2438d3 95 * @returns
switches 0:5c4d7b2438d3 96 * A pointer to the singleton
switches 0:5c4d7b2438d3 97 */
switches 0:5c4d7b2438d3 98 T* operator->() {
switches 0:5c4d7b2438d3 99 return get();
switches 0:5c4d7b2438d3 100 }
switches 0:5c4d7b2438d3 101
switches 0:5c4d7b2438d3 102 // This is zero initialized when in global scope
switches 0:5c4d7b2438d3 103 T *_ptr;
switches 0:5c4d7b2438d3 104 // Force data to be 4 byte aligned
switches 0:5c4d7b2438d3 105 uint32_t _data[(sizeof(T) + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
switches 0:5c4d7b2438d3 106 };
switches 0:5c4d7b2438d3 107
switches 0:5c4d7b2438d3 108 #endif
switches 0:5c4d7b2438d3 109
switches 0:5c4d7b2438d3 110 /** @}*/