test

Committer:
elijahsj
Date:
Mon Nov 09 00:33:19 2020 -0500
Revision:
2:4364577b5ad8
Parent:
1:8a094db1347f
copied mbed library

Who changed what in which revision?

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