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 events */
switches 0:5c4d7b2438d3 3 /** @{*/
switches 0:5c4d7b2438d3 4 /*
switches 0:5c4d7b2438d3 5 * System specific implementation
switches 0:5c4d7b2438d3 6 *
switches 0:5c4d7b2438d3 7 * Copyright (c) 2016 Christopher Haster
switches 0:5c4d7b2438d3 8 *
switches 0:5c4d7b2438d3 9 * Licensed under the Apache License, Version 2.0 (the "License");
switches 0:5c4d7b2438d3 10 * you may not use this file except in compliance with the License.
switches 0:5c4d7b2438d3 11 * You may obtain a copy of the License at
switches 0:5c4d7b2438d3 12 *
switches 0:5c4d7b2438d3 13 * http://www.apache.org/licenses/LICENSE-2.0
switches 0:5c4d7b2438d3 14 *
switches 0:5c4d7b2438d3 15 * Unless required by applicable law or agreed to in writing, software
switches 0:5c4d7b2438d3 16 * distributed under the License is distributed on an "AS IS" BASIS,
switches 0:5c4d7b2438d3 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
switches 0:5c4d7b2438d3 18 * See the License for the specific language governing permissions and
switches 0:5c4d7b2438d3 19 * limitations under the License.
switches 0:5c4d7b2438d3 20 */
switches 0:5c4d7b2438d3 21 #ifndef EQUEUE_PLATFORM_H
switches 0:5c4d7b2438d3 22 #define EQUEUE_PLATFORM_H
switches 0:5c4d7b2438d3 23
switches 0:5c4d7b2438d3 24 #ifdef __cplusplus
switches 0:5c4d7b2438d3 25 extern "C" {
switches 0:5c4d7b2438d3 26 #endif
switches 0:5c4d7b2438d3 27
switches 0:5c4d7b2438d3 28 #include <stdbool.h>
switches 0:5c4d7b2438d3 29
switches 0:5c4d7b2438d3 30 // Currently supported platforms
switches 0:5c4d7b2438d3 31 //
switches 0:5c4d7b2438d3 32 // Uncomment to select a supported platform or reimplement this file
switches 0:5c4d7b2438d3 33 // for a specific target.
switches 0:5c4d7b2438d3 34 //#define EQUEUE_PLATFORM_POSIX
switches 0:5c4d7b2438d3 35 //#define EQUEUE_PLATFORM_MBED
switches 0:5c4d7b2438d3 36
switches 0:5c4d7b2438d3 37 // Try to infer a platform if none was manually selected
switches 0:5c4d7b2438d3 38 #if !defined(EQUEUE_PLATFORM_POSIX) \
switches 0:5c4d7b2438d3 39 && !defined(EQUEUE_PLATFORM_MBED)
switches 0:5c4d7b2438d3 40 #if defined(__unix__)
switches 0:5c4d7b2438d3 41 #define EQUEUE_PLATFORM_POSIX
switches 0:5c4d7b2438d3 42 #elif defined(__MBED__)
switches 0:5c4d7b2438d3 43 #define EQUEUE_PLATFORM_MBED
switches 0:5c4d7b2438d3 44 #else
switches 0:5c4d7b2438d3 45 #warning "Unknown platform! Please update equeue_platform.h"
switches 0:5c4d7b2438d3 46 #endif
switches 0:5c4d7b2438d3 47 #endif
switches 0:5c4d7b2438d3 48
switches 0:5c4d7b2438d3 49 // Platform includes
switches 0:5c4d7b2438d3 50 #if defined(EQUEUE_PLATFORM_POSIX)
switches 0:5c4d7b2438d3 51 #include <pthread.h>
switches 0:5c4d7b2438d3 52 #endif
switches 0:5c4d7b2438d3 53
switches 0:5c4d7b2438d3 54
switches 0:5c4d7b2438d3 55 // Platform millisecond counter
switches 0:5c4d7b2438d3 56 //
switches 0:5c4d7b2438d3 57 // Return a tick that represents the number of milliseconds that have passed
switches 0:5c4d7b2438d3 58 // since an arbitrary point in time. The granularity does not need to be at
switches 0:5c4d7b2438d3 59 // the millisecond level, however the accuracy of the equeue library is
switches 0:5c4d7b2438d3 60 // limited by the accuracy of this tick.
switches 0:5c4d7b2438d3 61 //
switches 0:5c4d7b2438d3 62 // Must intentionally overflow to 0 after 2^32-1
switches 0:5c4d7b2438d3 63 unsigned equeue_tick(void);
switches 0:5c4d7b2438d3 64
switches 0:5c4d7b2438d3 65
switches 0:5c4d7b2438d3 66 // Platform mutex type
switches 0:5c4d7b2438d3 67 //
switches 0:5c4d7b2438d3 68 // The equeue library requires at minimum a non-recursive mutex that is
switches 0:5c4d7b2438d3 69 // safe in interrupt contexts. The mutex section is help for a bounded
switches 0:5c4d7b2438d3 70 // amount of time, so simply disabling interrupts is acceptable
switches 0:5c4d7b2438d3 71 //
switches 0:5c4d7b2438d3 72 // If irq safety is not required, a regular blocking mutex can be used.
switches 0:5c4d7b2438d3 73 #if defined(EQUEUE_PLATFORM_POSIX)
switches 0:5c4d7b2438d3 74 typedef pthread_mutex_t equeue_mutex_t;
switches 0:5c4d7b2438d3 75 #elif defined(EQUEUE_PLATFORM_WINDOWS)
switches 0:5c4d7b2438d3 76 typedef CRITICAL_SECTION equeue_mutex_t;
switches 0:5c4d7b2438d3 77 #elif defined(EQUEUE_PLATFORM_MBED)
switches 0:5c4d7b2438d3 78 typedef unsigned equeue_mutex_t;
switches 0:5c4d7b2438d3 79 #elif defined(EQUEUE_PLATFORM_FREERTOS)
switches 0:5c4d7b2438d3 80 typedef UBaseType_t equeue_mutex_t;
switches 0:5c4d7b2438d3 81 #endif
switches 0:5c4d7b2438d3 82
switches 0:5c4d7b2438d3 83 // Platform mutex operations
switches 0:5c4d7b2438d3 84 //
switches 0:5c4d7b2438d3 85 // The equeue_mutex_create and equeue_mutex_destroy manage the lifetime
switches 0:5c4d7b2438d3 86 // of the mutex. On error, equeue_mutex_create should return a negative
switches 0:5c4d7b2438d3 87 // error code.
switches 0:5c4d7b2438d3 88 //
switches 0:5c4d7b2438d3 89 // The equeue_mutex_lock and equeue_mutex_unlock lock and unlock the
switches 0:5c4d7b2438d3 90 // underlying mutex.
switches 0:5c4d7b2438d3 91 int equeue_mutex_create(equeue_mutex_t *mutex);
switches 0:5c4d7b2438d3 92 void equeue_mutex_destroy(equeue_mutex_t *mutex);
switches 0:5c4d7b2438d3 93 void equeue_mutex_lock(equeue_mutex_t *mutex);
switches 0:5c4d7b2438d3 94 void equeue_mutex_unlock(equeue_mutex_t *mutex);
switches 0:5c4d7b2438d3 95
switches 0:5c4d7b2438d3 96
switches 0:5c4d7b2438d3 97 // Platform semaphore type
switches 0:5c4d7b2438d3 98 //
switches 0:5c4d7b2438d3 99 // The equeue library requires a binary semaphore type that can be safely
switches 0:5c4d7b2438d3 100 // signaled from interrupt contexts and from inside a equeue_mutex section.
switches 0:5c4d7b2438d3 101 //
switches 0:5c4d7b2438d3 102 // The equeue_signal_wait is relied upon by the equeue library to sleep the
switches 0:5c4d7b2438d3 103 // processor between events. Spurious wakeups have no negative-effects.
switches 0:5c4d7b2438d3 104 //
switches 0:5c4d7b2438d3 105 // A counting semaphore will also work, however may cause the event queue
switches 0:5c4d7b2438d3 106 // dispatch loop to run unnecessarily. For that matter, equeue_signal_wait
switches 0:5c4d7b2438d3 107 // may even be implemented as a single return statement.
switches 0:5c4d7b2438d3 108 #if defined(EQUEUE_PLATFORM_POSIX)
switches 0:5c4d7b2438d3 109 typedef struct equeue_sema {
switches 0:5c4d7b2438d3 110 pthread_mutex_t mutex;
switches 0:5c4d7b2438d3 111 pthread_cond_t cond;
switches 0:5c4d7b2438d3 112 bool signal;
switches 0:5c4d7b2438d3 113 } equeue_sema_t;
switches 0:5c4d7b2438d3 114 #elif defined(EQUEUE_PLATFORM_MBED) && defined(MBED_CONF_RTOS_PRESENT)
switches 0:5c4d7b2438d3 115 typedef unsigned equeue_sema_t[8];
switches 0:5c4d7b2438d3 116 #elif defined(EQUEUE_PLATFORM_MBED)
switches 0:5c4d7b2438d3 117 typedef volatile int equeue_sema_t;
switches 0:5c4d7b2438d3 118 #endif
switches 0:5c4d7b2438d3 119
switches 0:5c4d7b2438d3 120 // Platform semaphore operations
switches 0:5c4d7b2438d3 121 //
switches 0:5c4d7b2438d3 122 // The equeue_sema_create and equeue_sema_destroy manage the lifetime
switches 0:5c4d7b2438d3 123 // of the semaphore. On error, equeue_sema_create should return a negative
switches 0:5c4d7b2438d3 124 // error code.
switches 0:5c4d7b2438d3 125 //
switches 0:5c4d7b2438d3 126 // The equeue_sema_signal marks a semaphore as signalled such that the next
switches 0:5c4d7b2438d3 127 // equeue_sema_wait will return true.
switches 0:5c4d7b2438d3 128 //
switches 0:5c4d7b2438d3 129 // The equeue_sema_wait waits for a semaphore to be signalled or returns
switches 0:5c4d7b2438d3 130 // immediately if equeue_sema_signal had been called since the last
switches 0:5c4d7b2438d3 131 // equeue_sema_wait. The equeue_sema_wait returns true if it detected that
switches 0:5c4d7b2438d3 132 // equeue_sema_signal had been called.
switches 0:5c4d7b2438d3 133 int equeue_sema_create(equeue_sema_t *sema);
switches 0:5c4d7b2438d3 134 void equeue_sema_destroy(equeue_sema_t *sema);
switches 0:5c4d7b2438d3 135 void equeue_sema_signal(equeue_sema_t *sema);
switches 0:5c4d7b2438d3 136 bool equeue_sema_wait(equeue_sema_t *sema, int ms);
switches 0:5c4d7b2438d3 137
switches 0:5c4d7b2438d3 138
switches 0:5c4d7b2438d3 139 #ifdef __cplusplus
switches 0:5c4d7b2438d3 140 }
switches 0:5c4d7b2438d3 141 #endif
switches 0:5c4d7b2438d3 142
switches 0:5c4d7b2438d3 143 #endif
switches 0:5c4d7b2438d3 144
switches 0:5c4d7b2438d3 145 /** @}*/