Elijah Stanger-Jones / mbed-dev
Committer:
saloutos
Date:
Thu Nov 26 04:08:56 2020 +0000
Revision:
0:083111ae2a11
first commit of leaned mbed dev lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
saloutos 0:083111ae2a11 1 /* mbed Microcontroller Library
saloutos 0:083111ae2a11 2 * Copyright (c) 2006-2013 ARM Limited
saloutos 0:083111ae2a11 3 *
saloutos 0:083111ae2a11 4 * Licensed under the Apache License, Version 2.0 (the "License");
saloutos 0:083111ae2a11 5 * you may not use this file except in compliance with the License.
saloutos 0:083111ae2a11 6 * You may obtain a copy of the License at
saloutos 0:083111ae2a11 7 *
saloutos 0:083111ae2a11 8 * http://www.apache.org/licenses/LICENSE-2.0
saloutos 0:083111ae2a11 9 *
saloutos 0:083111ae2a11 10 * Unless required by applicable law or agreed to in writing, software
saloutos 0:083111ae2a11 11 * distributed under the License is distributed on an "AS IS" BASIS,
saloutos 0:083111ae2a11 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
saloutos 0:083111ae2a11 13 * See the License for the specific language governing permissions and
saloutos 0:083111ae2a11 14 * limitations under the License.
saloutos 0:083111ae2a11 15 */
saloutos 0:083111ae2a11 16
saloutos 0:083111ae2a11 17 // This implementation of the wait functions will be compiled only
saloutos 0:083111ae2a11 18 // if the RTOS is present.
saloutos 0:083111ae2a11 19 #ifdef MBED_CONF_RTOS_PRESENT
saloutos 0:083111ae2a11 20
saloutos 0:083111ae2a11 21 #include "platform/mbed_wait_api.h"
saloutos 0:083111ae2a11 22 #include "hal/us_ticker_api.h"
saloutos 0:083111ae2a11 23 #include "rtos/rtos.h"
saloutos 0:083111ae2a11 24 #include "platform/mbed_critical.h"
saloutos 0:083111ae2a11 25 #include "platform/mbed_sleep.h"
saloutos 0:083111ae2a11 26
saloutos 0:083111ae2a11 27 void wait(float s) {
saloutos 0:083111ae2a11 28 wait_us(s * 1000000.0f);
saloutos 0:083111ae2a11 29 }
saloutos 0:083111ae2a11 30
saloutos 0:083111ae2a11 31 void wait_ms(int ms) {
saloutos 0:083111ae2a11 32 wait_us(ms * 1000);
saloutos 0:083111ae2a11 33 }
saloutos 0:083111ae2a11 34
saloutos 0:083111ae2a11 35 void wait_us(int us) {
saloutos 0:083111ae2a11 36 const ticker_data_t *const ticker = get_us_ticker_data();
saloutos 0:083111ae2a11 37
saloutos 0:083111ae2a11 38 uint32_t start = ticker_read(ticker);
saloutos 0:083111ae2a11 39 // Use the RTOS to wait for millisecond delays if possible
saloutos 0:083111ae2a11 40 int ms = us / 1000;
saloutos 0:083111ae2a11 41 if ((ms > 0) && core_util_are_interrupts_enabled()) {
saloutos 0:083111ae2a11 42 sleep_manager_lock_deep_sleep();
saloutos 0:083111ae2a11 43 Thread::wait((uint32_t)ms);
saloutos 0:083111ae2a11 44 sleep_manager_unlock_deep_sleep();
saloutos 0:083111ae2a11 45 }
saloutos 0:083111ae2a11 46 // Use busy waiting for sub-millisecond delays, or for the whole
saloutos 0:083111ae2a11 47 // interval if interrupts are not enabled
saloutos 0:083111ae2a11 48 while ((ticker_read(ticker) - start) < (uint32_t)us);
saloutos 0:083111ae2a11 49 }
saloutos 0:083111ae2a11 50
saloutos 0:083111ae2a11 51 #endif // #if MBED_CONF_RTOS_PRESENT
saloutos 0:083111ae2a11 52