max32630fthr quad spi , unexpected spi behavior

Committer:
boonshen
Date:
Tue Mar 13 21:12:00 2018 +0000
Revision:
0:a35c40f49345
MAX32630FTHR QuadSPI test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
boonshen 0:a35c40f49345 1 /* mbed Microcontroller Library
boonshen 0:a35c40f49345 2 * Copyright (c) 2006-2013 ARM Limited
boonshen 0:a35c40f49345 3 *
boonshen 0:a35c40f49345 4 * Licensed under the Apache License, Version 2.0 (the "License");
boonshen 0:a35c40f49345 5 * you may not use this file except in compliance with the License.
boonshen 0:a35c40f49345 6 * You may obtain a copy of the License at
boonshen 0:a35c40f49345 7 *
boonshen 0:a35c40f49345 8 * http://www.apache.org/licenses/LICENSE-2.0
boonshen 0:a35c40f49345 9 *
boonshen 0:a35c40f49345 10 * Unless required by applicable law or agreed to in writing, software
boonshen 0:a35c40f49345 11 * distributed under the License is distributed on an "AS IS" BASIS,
boonshen 0:a35c40f49345 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
boonshen 0:a35c40f49345 13 * See the License for the specific language governing permissions and
boonshen 0:a35c40f49345 14 * limitations under the License.
boonshen 0:a35c40f49345 15 */
boonshen 0:a35c40f49345 16 #include "drivers/Timer.h"
boonshen 0:a35c40f49345 17 #include "hal/ticker_api.h"
boonshen 0:a35c40f49345 18 #include "hal/us_ticker_api.h"
boonshen 0:a35c40f49345 19 #include "platform/mbed_critical.h"
boonshen 0:a35c40f49345 20 #include "hal/lp_ticker_api.h"
boonshen 0:a35c40f49345 21
boonshen 0:a35c40f49345 22 namespace mbed {
boonshen 0:a35c40f49345 23
boonshen 0:a35c40f49345 24 Timer::Timer() : _running(), _start(), _time(), _ticker_data(get_us_ticker_data()), _lock_deepsleep(true) {
boonshen 0:a35c40f49345 25 reset();
boonshen 0:a35c40f49345 26 }
boonshen 0:a35c40f49345 27
boonshen 0:a35c40f49345 28 Timer::Timer(const ticker_data_t *data) : _running(), _start(), _time(), _ticker_data(data), _lock_deepsleep(true) {
boonshen 0:a35c40f49345 29 reset();
boonshen 0:a35c40f49345 30 #if DEVICE_LOWPOWERTIMER
boonshen 0:a35c40f49345 31 _lock_deepsleep = (data != get_lp_ticker_data());
boonshen 0:a35c40f49345 32 #endif
boonshen 0:a35c40f49345 33 }
boonshen 0:a35c40f49345 34
boonshen 0:a35c40f49345 35 Timer::~Timer() {
boonshen 0:a35c40f49345 36 core_util_critical_section_enter();
boonshen 0:a35c40f49345 37 if (_running) {
boonshen 0:a35c40f49345 38 if(_lock_deepsleep) {
boonshen 0:a35c40f49345 39 sleep_manager_unlock_deep_sleep();
boonshen 0:a35c40f49345 40 }
boonshen 0:a35c40f49345 41 }
boonshen 0:a35c40f49345 42 _running = 0;
boonshen 0:a35c40f49345 43 core_util_critical_section_exit();
boonshen 0:a35c40f49345 44 }
boonshen 0:a35c40f49345 45
boonshen 0:a35c40f49345 46 void Timer::start() {
boonshen 0:a35c40f49345 47 core_util_critical_section_enter();
boonshen 0:a35c40f49345 48 if (!_running) {
boonshen 0:a35c40f49345 49 if(_lock_deepsleep) {
boonshen 0:a35c40f49345 50 sleep_manager_lock_deep_sleep();
boonshen 0:a35c40f49345 51 }
boonshen 0:a35c40f49345 52 _start = ticker_read_us(_ticker_data);
boonshen 0:a35c40f49345 53 _running = 1;
boonshen 0:a35c40f49345 54 }
boonshen 0:a35c40f49345 55 core_util_critical_section_exit();
boonshen 0:a35c40f49345 56 }
boonshen 0:a35c40f49345 57
boonshen 0:a35c40f49345 58 void Timer::stop() {
boonshen 0:a35c40f49345 59 core_util_critical_section_enter();
boonshen 0:a35c40f49345 60 _time += slicetime();
boonshen 0:a35c40f49345 61 if (_running) {
boonshen 0:a35c40f49345 62 if(_lock_deepsleep) {
boonshen 0:a35c40f49345 63 sleep_manager_unlock_deep_sleep();
boonshen 0:a35c40f49345 64 }
boonshen 0:a35c40f49345 65 }
boonshen 0:a35c40f49345 66 _running = 0;
boonshen 0:a35c40f49345 67 core_util_critical_section_exit();
boonshen 0:a35c40f49345 68 }
boonshen 0:a35c40f49345 69
boonshen 0:a35c40f49345 70 int Timer::read_us() {
boonshen 0:a35c40f49345 71 return read_high_resolution_us();
boonshen 0:a35c40f49345 72 }
boonshen 0:a35c40f49345 73
boonshen 0:a35c40f49345 74 float Timer::read() {
boonshen 0:a35c40f49345 75 return (float)read_us() / 1000000.0f;
boonshen 0:a35c40f49345 76 }
boonshen 0:a35c40f49345 77
boonshen 0:a35c40f49345 78 int Timer::read_ms() {
boonshen 0:a35c40f49345 79 return read_high_resolution_us() / 1000;
boonshen 0:a35c40f49345 80 }
boonshen 0:a35c40f49345 81
boonshen 0:a35c40f49345 82 us_timestamp_t Timer::read_high_resolution_us() {
boonshen 0:a35c40f49345 83 core_util_critical_section_enter();
boonshen 0:a35c40f49345 84 us_timestamp_t time = _time + slicetime();
boonshen 0:a35c40f49345 85 core_util_critical_section_exit();
boonshen 0:a35c40f49345 86 return time;
boonshen 0:a35c40f49345 87 }
boonshen 0:a35c40f49345 88
boonshen 0:a35c40f49345 89 us_timestamp_t Timer::slicetime() {
boonshen 0:a35c40f49345 90 us_timestamp_t ret = 0;
boonshen 0:a35c40f49345 91 core_util_critical_section_enter();
boonshen 0:a35c40f49345 92 if (_running) {
boonshen 0:a35c40f49345 93 ret = ticker_read_us(_ticker_data) - _start;
boonshen 0:a35c40f49345 94 }
boonshen 0:a35c40f49345 95 core_util_critical_section_exit();
boonshen 0:a35c40f49345 96 return ret;
boonshen 0:a35c40f49345 97 }
boonshen 0:a35c40f49345 98
boonshen 0:a35c40f49345 99 void Timer::reset() {
boonshen 0:a35c40f49345 100 core_util_critical_section_enter();
boonshen 0:a35c40f49345 101 _start = ticker_read_us(_ticker_data);
boonshen 0:a35c40f49345 102 _time = 0;
boonshen 0:a35c40f49345 103 core_util_critical_section_exit();
boonshen 0:a35c40f49345 104 }
boonshen 0:a35c40f49345 105
boonshen 0:a35c40f49345 106 Timer::operator float() {
boonshen 0:a35c40f49345 107 return read();
boonshen 0:a35c40f49345 108 }
boonshen 0:a35c40f49345 109
boonshen 0:a35c40f49345 110 } // namespace mbed