mbed-os for GR-LYCHEE
Dependents: mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more
platform/mbed_wait_api_rtos.cpp@0:f782d9c66c49, 2018-02-02 (annotated)
- Committer:
- dkato
- Date:
- Fri Feb 02 05:42:23 2018 +0000
- Revision:
- 0:f782d9c66c49
mbed-os for GR-LYCHEE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dkato | 0:f782d9c66c49 | 1 | /* mbed Microcontroller Library |
dkato | 0:f782d9c66c49 | 2 | * Copyright (c) 2006-2013 ARM Limited |
dkato | 0:f782d9c66c49 | 3 | * |
dkato | 0:f782d9c66c49 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
dkato | 0:f782d9c66c49 | 5 | * you may not use this file except in compliance with the License. |
dkato | 0:f782d9c66c49 | 6 | * You may obtain a copy of the License at |
dkato | 0:f782d9c66c49 | 7 | * |
dkato | 0:f782d9c66c49 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
dkato | 0:f782d9c66c49 | 9 | * |
dkato | 0:f782d9c66c49 | 10 | * Unless required by applicable law or agreed to in writing, software |
dkato | 0:f782d9c66c49 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
dkato | 0:f782d9c66c49 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
dkato | 0:f782d9c66c49 | 13 | * See the License for the specific language governing permissions and |
dkato | 0:f782d9c66c49 | 14 | * limitations under the License. |
dkato | 0:f782d9c66c49 | 15 | */ |
dkato | 0:f782d9c66c49 | 16 | |
dkato | 0:f782d9c66c49 | 17 | // This implementation of the wait functions will be compiled only |
dkato | 0:f782d9c66c49 | 18 | // if the RTOS is present. |
dkato | 0:f782d9c66c49 | 19 | #ifdef MBED_CONF_RTOS_PRESENT |
dkato | 0:f782d9c66c49 | 20 | |
dkato | 0:f782d9c66c49 | 21 | #include "platform/mbed_wait_api.h" |
dkato | 0:f782d9c66c49 | 22 | #include "hal/us_ticker_api.h" |
dkato | 0:f782d9c66c49 | 23 | #include "rtos/rtos.h" |
dkato | 0:f782d9c66c49 | 24 | #include "platform/mbed_critical.h" |
dkato | 0:f782d9c66c49 | 25 | |
dkato | 0:f782d9c66c49 | 26 | void wait(float s) { |
dkato | 0:f782d9c66c49 | 27 | wait_us(s * 1000000.0f); |
dkato | 0:f782d9c66c49 | 28 | } |
dkato | 0:f782d9c66c49 | 29 | |
dkato | 0:f782d9c66c49 | 30 | void wait_ms(int ms) { |
dkato | 0:f782d9c66c49 | 31 | wait_us(ms * 1000); |
dkato | 0:f782d9c66c49 | 32 | } |
dkato | 0:f782d9c66c49 | 33 | |
dkato | 0:f782d9c66c49 | 34 | void wait_us(int us) { |
dkato | 0:f782d9c66c49 | 35 | uint32_t start = us_ticker_read(); |
dkato | 0:f782d9c66c49 | 36 | // Use the RTOS to wait for millisecond delays if possible |
dkato | 0:f782d9c66c49 | 37 | int ms = us / 1000; |
dkato | 0:f782d9c66c49 | 38 | if ((ms > 0) && core_util_are_interrupts_enabled()) { |
dkato | 0:f782d9c66c49 | 39 | Thread::wait((uint32_t)ms); |
dkato | 0:f782d9c66c49 | 40 | } |
dkato | 0:f782d9c66c49 | 41 | // Use busy waiting for sub-millisecond delays, or for the whole |
dkato | 0:f782d9c66c49 | 42 | // interval if interrupts are not enabled |
dkato | 0:f782d9c66c49 | 43 | while ((us_ticker_read() - start) < (uint32_t)us); |
dkato | 0:f782d9c66c49 | 44 | } |
dkato | 0:f782d9c66c49 | 45 | |
dkato | 0:f782d9c66c49 | 46 | #endif // #if MBED_CONF_RTOS_PRESENT |
dkato | 0:f782d9c66c49 | 47 |