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 "hal/rtc_api.h"
switches 0:5c4d7b2438d3 17
switches 0:5c4d7b2438d3 18 #include <time.h>
switches 0:5c4d7b2438d3 19 #include "platform/critical.h"
switches 0:5c4d7b2438d3 20 #include "platform/rtc_time.h"
switches 0:5c4d7b2438d3 21 #include "hal/us_ticker_api.h"
switches 0:5c4d7b2438d3 22 #include "platform/SingletonPtr.h"
switches 0:5c4d7b2438d3 23 #include "platform/PlatformMutex.h"
switches 0:5c4d7b2438d3 24
switches 0:5c4d7b2438d3 25 static SingletonPtr<PlatformMutex> _mutex;
switches 0:5c4d7b2438d3 26
switches 0:5c4d7b2438d3 27 #if DEVICE_RTC
switches 0:5c4d7b2438d3 28 static void (*_rtc_init)(void) = rtc_init;
switches 0:5c4d7b2438d3 29 static int (*_rtc_isenabled)(void) = rtc_isenabled;
switches 0:5c4d7b2438d3 30 static time_t (*_rtc_read)(void) = rtc_read;
switches 0:5c4d7b2438d3 31 static void (*_rtc_write)(time_t t) = rtc_write;
switches 0:5c4d7b2438d3 32 #else
switches 0:5c4d7b2438d3 33 static void (*_rtc_init)(void) = NULL;
switches 0:5c4d7b2438d3 34 static int (*_rtc_isenabled)(void) = NULL;
switches 0:5c4d7b2438d3 35 static time_t (*_rtc_read)(void) = NULL;
switches 0:5c4d7b2438d3 36 static void (*_rtc_write)(time_t t) = NULL;
switches 0:5c4d7b2438d3 37 #endif
switches 0:5c4d7b2438d3 38
switches 0:5c4d7b2438d3 39 #ifdef __cplusplus
switches 0:5c4d7b2438d3 40 extern "C" {
switches 0:5c4d7b2438d3 41 #endif
switches 0:5c4d7b2438d3 42 #if defined (__ICCARM__)
switches 0:5c4d7b2438d3 43 time_t __time32(time_t *timer)
switches 0:5c4d7b2438d3 44 #else
switches 0:5c4d7b2438d3 45 time_t time(time_t *timer)
switches 0:5c4d7b2438d3 46 #endif
switches 0:5c4d7b2438d3 47
switches 0:5c4d7b2438d3 48 {
switches 0:5c4d7b2438d3 49 _mutex->lock();
switches 0:5c4d7b2438d3 50 if (_rtc_isenabled != NULL) {
switches 0:5c4d7b2438d3 51 if (!(_rtc_isenabled())) {
switches 0:5c4d7b2438d3 52 set_time(0);
switches 0:5c4d7b2438d3 53 }
switches 0:5c4d7b2438d3 54 }
switches 0:5c4d7b2438d3 55
switches 0:5c4d7b2438d3 56 time_t t = 0;
switches 0:5c4d7b2438d3 57 if (_rtc_read != NULL) {
switches 0:5c4d7b2438d3 58 t = _rtc_read();
switches 0:5c4d7b2438d3 59 }
switches 0:5c4d7b2438d3 60
switches 0:5c4d7b2438d3 61 if (timer != NULL) {
switches 0:5c4d7b2438d3 62 *timer = t;
switches 0:5c4d7b2438d3 63 }
switches 0:5c4d7b2438d3 64 _mutex->unlock();
switches 0:5c4d7b2438d3 65 return t;
switches 0:5c4d7b2438d3 66 }
switches 0:5c4d7b2438d3 67
switches 0:5c4d7b2438d3 68 void set_time(time_t t) {
switches 0:5c4d7b2438d3 69 _mutex->lock();
switches 0:5c4d7b2438d3 70 if (_rtc_init != NULL) {
switches 0:5c4d7b2438d3 71 _rtc_init();
switches 0:5c4d7b2438d3 72 }
switches 0:5c4d7b2438d3 73 if (_rtc_write != NULL) {
switches 0:5c4d7b2438d3 74 _rtc_write(t);
switches 0:5c4d7b2438d3 75 }
switches 0:5c4d7b2438d3 76 _mutex->unlock();
switches 0:5c4d7b2438d3 77 }
switches 0:5c4d7b2438d3 78
switches 0:5c4d7b2438d3 79 clock_t clock() {
switches 0:5c4d7b2438d3 80 _mutex->lock();
switches 0:5c4d7b2438d3 81 clock_t t = us_ticker_read();
switches 0:5c4d7b2438d3 82 t /= 1000000 / CLOCKS_PER_SEC; // convert to processor time
switches 0:5c4d7b2438d3 83 _mutex->unlock();
switches 0:5c4d7b2438d3 84 return t;
switches 0:5c4d7b2438d3 85 }
switches 0:5c4d7b2438d3 86
switches 0:5c4d7b2438d3 87 void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void)) {
switches 0:5c4d7b2438d3 88 _mutex->lock();
switches 0:5c4d7b2438d3 89 _rtc_read = read_rtc;
switches 0:5c4d7b2438d3 90 _rtc_write = write_rtc;
switches 0:5c4d7b2438d3 91 _rtc_init = init_rtc;
switches 0:5c4d7b2438d3 92 _rtc_isenabled = isenabled_rtc;
switches 0:5c4d7b2438d3 93 _mutex->unlock();
switches 0:5c4d7b2438d3 94 }
switches 0:5c4d7b2438d3 95
switches 0:5c4d7b2438d3 96
switches 0:5c4d7b2438d3 97
switches 0:5c4d7b2438d3 98 #ifdef __cplusplus
switches 0:5c4d7b2438d3 99 }
switches 0:5c4d7b2438d3 100 #endif