Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed-os/platform/mbed_wait_api_rtos.cpp@4:75df35ef4fb6, 2018-03-30 (annotated)
- Committer:
- borlanic
- Date:
- Fri Mar 30 14:07:05 2018 +0000
- Revision:
- 4:75df35ef4fb6
- Parent:
- 0:380207fcb5c1
commentar
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| borlanic | 0:380207fcb5c1 | 1 | /* mbed Microcontroller Library |
| borlanic | 0:380207fcb5c1 | 2 | * Copyright (c) 2006-2013 ARM Limited |
| borlanic | 0:380207fcb5c1 | 3 | * |
| borlanic | 0:380207fcb5c1 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| borlanic | 0:380207fcb5c1 | 5 | * you may not use this file except in compliance with the License. |
| borlanic | 0:380207fcb5c1 | 6 | * You may obtain a copy of the License at |
| borlanic | 0:380207fcb5c1 | 7 | * |
| borlanic | 0:380207fcb5c1 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| borlanic | 0:380207fcb5c1 | 9 | * |
| borlanic | 0:380207fcb5c1 | 10 | * Unless required by applicable law or agreed to in writing, software |
| borlanic | 0:380207fcb5c1 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| borlanic | 0:380207fcb5c1 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| borlanic | 0:380207fcb5c1 | 13 | * See the License for the specific language governing permissions and |
| borlanic | 0:380207fcb5c1 | 14 | * limitations under the License. |
| borlanic | 0:380207fcb5c1 | 15 | */ |
| borlanic | 0:380207fcb5c1 | 16 | |
| borlanic | 0:380207fcb5c1 | 17 | // This implementation of the wait functions will be compiled only |
| borlanic | 0:380207fcb5c1 | 18 | // if the RTOS is present. |
| borlanic | 0:380207fcb5c1 | 19 | #ifdef MBED_CONF_RTOS_PRESENT |
| borlanic | 0:380207fcb5c1 | 20 | |
| borlanic | 0:380207fcb5c1 | 21 | #include "platform/mbed_wait_api.h" |
| borlanic | 0:380207fcb5c1 | 22 | #include "hal/us_ticker_api.h" |
| borlanic | 0:380207fcb5c1 | 23 | #include "rtos/rtos.h" |
| borlanic | 0:380207fcb5c1 | 24 | #include "platform/mbed_critical.h" |
| borlanic | 0:380207fcb5c1 | 25 | #include "platform/mbed_power_mgmt.h" |
| borlanic | 0:380207fcb5c1 | 26 | |
| borlanic | 0:380207fcb5c1 | 27 | void wait(float s) { |
| borlanic | 0:380207fcb5c1 | 28 | wait_us(s * 1000000.0f); |
| borlanic | 0:380207fcb5c1 | 29 | } |
| borlanic | 0:380207fcb5c1 | 30 | |
| borlanic | 0:380207fcb5c1 | 31 | void wait_ms(int ms) { |
| borlanic | 0:380207fcb5c1 | 32 | wait_us(ms * 1000); |
| borlanic | 0:380207fcb5c1 | 33 | } |
| borlanic | 0:380207fcb5c1 | 34 | |
| borlanic | 0:380207fcb5c1 | 35 | void wait_us(int us) { |
| borlanic | 0:380207fcb5c1 | 36 | const ticker_data_t *const ticker = get_us_ticker_data(); |
| borlanic | 0:380207fcb5c1 | 37 | |
| borlanic | 0:380207fcb5c1 | 38 | uint32_t start = ticker_read(ticker); |
| borlanic | 0:380207fcb5c1 | 39 | // Use the RTOS to wait for millisecond delays if possible |
| borlanic | 0:380207fcb5c1 | 40 | int ms = us / 1000; |
| borlanic | 0:380207fcb5c1 | 41 | if ((ms > 0) && core_util_are_interrupts_enabled()) { |
| borlanic | 0:380207fcb5c1 | 42 | sleep_manager_lock_deep_sleep(); |
| borlanic | 0:380207fcb5c1 | 43 | Thread::wait((uint32_t)ms); |
| borlanic | 0:380207fcb5c1 | 44 | sleep_manager_unlock_deep_sleep(); |
| borlanic | 0:380207fcb5c1 | 45 | } |
| borlanic | 0:380207fcb5c1 | 46 | // Use busy waiting for sub-millisecond delays, or for the whole |
| borlanic | 0:380207fcb5c1 | 47 | // interval if interrupts are not enabled |
| borlanic | 0:380207fcb5c1 | 48 | while ((ticker_read(ticker) - start) < (uint32_t)us); |
| borlanic | 0:380207fcb5c1 | 49 | } |
| borlanic | 0:380207fcb5c1 | 50 | |
| borlanic | 0:380207fcb5c1 | 51 | #endif // #if MBED_CONF_RTOS_PRESENT |
| borlanic | 0:380207fcb5c1 | 52 |