BA / SerialCom

Fork of OmniWheels by Gustav Atmel

Committer:
gustavatmel
Date:
Tue May 01 15:55:34 2018 +0000
Revision:
2:798925c9e4a8
Parent:
1:9c5af431a1f1
bluetooth

Who changed what in which revision?

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