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 * Implementation for the mbed library
switches 0:5c4d7b2438d3 3 * https://github.com/mbedmicro/mbed
switches 0:5c4d7b2438d3 4 *
switches 0:5c4d7b2438d3 5 * Copyright (c) 2016 Christopher Haster
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 #include "equeue/equeue_platform.h"
switches 0:5c4d7b2438d3 20
switches 0:5c4d7b2438d3 21 #if defined(EQUEUE_PLATFORM_MBED)
switches 0:5c4d7b2438d3 22
switches 0:5c4d7b2438d3 23 #include <stdbool.h>
switches 0:5c4d7b2438d3 24 #include "mbed.h"
switches 0:5c4d7b2438d3 25
switches 0:5c4d7b2438d3 26
switches 0:5c4d7b2438d3 27 // Ticker operations
switches 0:5c4d7b2438d3 28 static bool equeue_tick_inited = false;
switches 0:5c4d7b2438d3 29 static unsigned equeue_minutes = 0;
switches 0:5c4d7b2438d3 30 static unsigned equeue_timer[
switches 0:5c4d7b2438d3 31 (sizeof(Timer)+sizeof(unsigned)-1)/sizeof(unsigned)];
switches 0:5c4d7b2438d3 32 static unsigned equeue_ticker[
switches 0:5c4d7b2438d3 33 (sizeof(Ticker)+sizeof(unsigned)-1)/sizeof(unsigned)];
switches 0:5c4d7b2438d3 34
switches 0:5c4d7b2438d3 35 static void equeue_tick_update() {
switches 0:5c4d7b2438d3 36 reinterpret_cast<Timer*>(equeue_timer)->reset();
switches 0:5c4d7b2438d3 37 equeue_minutes += 1;
switches 0:5c4d7b2438d3 38 }
switches 0:5c4d7b2438d3 39
switches 0:5c4d7b2438d3 40 static void equeue_tick_init() {
switches 0:5c4d7b2438d3 41 MBED_STATIC_ASSERT(sizeof(equeue_timer) >= sizeof(Timer),
switches 0:5c4d7b2438d3 42 "The equeue_timer buffer must fit the class Timer");
switches 0:5c4d7b2438d3 43 MBED_STATIC_ASSERT(sizeof(equeue_ticker) >= sizeof(Ticker),
switches 0:5c4d7b2438d3 44 "The equeue_ticker buffer must fit the class Ticker");
switches 0:5c4d7b2438d3 45 new (equeue_timer) Timer;
switches 0:5c4d7b2438d3 46 new (equeue_ticker) Ticker;
switches 0:5c4d7b2438d3 47
switches 0:5c4d7b2438d3 48 equeue_minutes = 0;
switches 0:5c4d7b2438d3 49 reinterpret_cast<Timer*>(equeue_timer)->start();
switches 0:5c4d7b2438d3 50 reinterpret_cast<Ticker*>(equeue_ticker)
switches 0:5c4d7b2438d3 51 ->attach_us(equeue_tick_update, (1 << 16)*1000);
switches 0:5c4d7b2438d3 52
switches 0:5c4d7b2438d3 53 equeue_tick_inited = true;
switches 0:5c4d7b2438d3 54 }
switches 0:5c4d7b2438d3 55
switches 0:5c4d7b2438d3 56 unsigned equeue_tick() {
switches 0:5c4d7b2438d3 57 if (!equeue_tick_inited) {
switches 0:5c4d7b2438d3 58 equeue_tick_init();
switches 0:5c4d7b2438d3 59 }
switches 0:5c4d7b2438d3 60
switches 0:5c4d7b2438d3 61 unsigned equeue_ms = reinterpret_cast<Timer*>(equeue_timer)->read_ms();
switches 0:5c4d7b2438d3 62 return (equeue_minutes << 16) + equeue_ms;
switches 0:5c4d7b2438d3 63 }
switches 0:5c4d7b2438d3 64
switches 0:5c4d7b2438d3 65
switches 0:5c4d7b2438d3 66 // Mutex operations
switches 0:5c4d7b2438d3 67 int equeue_mutex_create(equeue_mutex_t *m) { return 0; }
switches 0:5c4d7b2438d3 68 void equeue_mutex_destroy(equeue_mutex_t *m) { }
switches 0:5c4d7b2438d3 69
switches 0:5c4d7b2438d3 70 void equeue_mutex_lock(equeue_mutex_t *m) {
switches 0:5c4d7b2438d3 71 core_util_critical_section_enter();
switches 0:5c4d7b2438d3 72 }
switches 0:5c4d7b2438d3 73
switches 0:5c4d7b2438d3 74 void equeue_mutex_unlock(equeue_mutex_t *m) {
switches 0:5c4d7b2438d3 75 core_util_critical_section_exit();
switches 0:5c4d7b2438d3 76 }
switches 0:5c4d7b2438d3 77
switches 0:5c4d7b2438d3 78
switches 0:5c4d7b2438d3 79 // Semaphore operations
switches 0:5c4d7b2438d3 80 #ifdef MBED_CONF_RTOS_PRESENT
switches 0:5c4d7b2438d3 81
switches 0:5c4d7b2438d3 82 int equeue_sema_create(equeue_sema_t *s) {
switches 0:5c4d7b2438d3 83 MBED_STATIC_ASSERT(sizeof(equeue_sema_t) >= sizeof(Semaphore),
switches 0:5c4d7b2438d3 84 "The equeue_sema_t must fit the class Semaphore");
switches 0:5c4d7b2438d3 85 new (s) Semaphore(0);
switches 0:5c4d7b2438d3 86 return 0;
switches 0:5c4d7b2438d3 87 }
switches 0:5c4d7b2438d3 88
switches 0:5c4d7b2438d3 89 void equeue_sema_destroy(equeue_sema_t *s) {
switches 0:5c4d7b2438d3 90 reinterpret_cast<Semaphore*>(s)->~Semaphore();
switches 0:5c4d7b2438d3 91 }
switches 0:5c4d7b2438d3 92
switches 0:5c4d7b2438d3 93 void equeue_sema_signal(equeue_sema_t *s) {
switches 0:5c4d7b2438d3 94 reinterpret_cast<Semaphore*>(s)->release();
switches 0:5c4d7b2438d3 95 }
switches 0:5c4d7b2438d3 96
switches 0:5c4d7b2438d3 97 bool equeue_sema_wait(equeue_sema_t *s, int ms) {
switches 0:5c4d7b2438d3 98 if (ms < 0) {
switches 0:5c4d7b2438d3 99 ms = osWaitForever;
switches 0:5c4d7b2438d3 100 }
switches 0:5c4d7b2438d3 101
switches 0:5c4d7b2438d3 102 return (reinterpret_cast<Semaphore*>(s)->wait(ms) > 0);
switches 0:5c4d7b2438d3 103 }
switches 0:5c4d7b2438d3 104
switches 0:5c4d7b2438d3 105 #else
switches 0:5c4d7b2438d3 106
switches 0:5c4d7b2438d3 107 // Semaphore operations
switches 0:5c4d7b2438d3 108 int equeue_sema_create(equeue_sema_t *s) {
switches 0:5c4d7b2438d3 109 *s = false;
switches 0:5c4d7b2438d3 110 return 0;
switches 0:5c4d7b2438d3 111 }
switches 0:5c4d7b2438d3 112
switches 0:5c4d7b2438d3 113 void equeue_sema_destroy(equeue_sema_t *s) {
switches 0:5c4d7b2438d3 114 }
switches 0:5c4d7b2438d3 115
switches 0:5c4d7b2438d3 116 void equeue_sema_signal(equeue_sema_t *s) {
switches 0:5c4d7b2438d3 117 *s = 1;
switches 0:5c4d7b2438d3 118 }
switches 0:5c4d7b2438d3 119
switches 0:5c4d7b2438d3 120 static void equeue_sema_timeout(equeue_sema_t *s) {
switches 0:5c4d7b2438d3 121 *s = -1;
switches 0:5c4d7b2438d3 122 }
switches 0:5c4d7b2438d3 123
switches 0:5c4d7b2438d3 124 bool equeue_sema_wait(equeue_sema_t *s, int ms) {
switches 0:5c4d7b2438d3 125 int signal = 0;
switches 0:5c4d7b2438d3 126 Timeout timeout;
switches 0:5c4d7b2438d3 127 timeout.attach_us(s, equeue_sema_timeout, ms*1000);
switches 0:5c4d7b2438d3 128
switches 0:5c4d7b2438d3 129 core_util_critical_section_enter();
switches 0:5c4d7b2438d3 130 while (!*s) {
switches 0:5c4d7b2438d3 131 sleep();
switches 0:5c4d7b2438d3 132 core_util_critical_section_exit();
switches 0:5c4d7b2438d3 133 core_util_critical_section_enter();
switches 0:5c4d7b2438d3 134 }
switches 0:5c4d7b2438d3 135
switches 0:5c4d7b2438d3 136 signal = *s;
switches 0:5c4d7b2438d3 137 *s = false;
switches 0:5c4d7b2438d3 138 core_util_critical_section_exit();
switches 0:5c4d7b2438d3 139
switches 0:5c4d7b2438d3 140 return (signal > 0);
switches 0:5c4d7b2438d3 141 }
switches 0:5c4d7b2438d3 142
switches 0:5c4d7b2438d3 143 #endif
switches 0:5c4d7b2438d3 144
switches 0:5c4d7b2438d3 145 #endif